Update: Refactored commands into their own source files.
This commit is contained in:
36
src/cli/commands/shared.ts
Normal file
36
src/cli/commands/shared.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { minimatch } from "minimatch";
|
||||
|
||||
import { loadPublicConfig } from "../../index.ts";
|
||||
import { getGraphClient } from "../../graph/auth.ts";
|
||||
|
||||
type PermissionRow = {
|
||||
permissionValue?: string | null;
|
||||
permissionDisplayName?: string | null;
|
||||
};
|
||||
|
||||
type DisplayNameRow = {
|
||||
displayName?: string | null;
|
||||
};
|
||||
|
||||
export function filterByPermissionName<T extends PermissionRow>(rows: T[], pattern: string): T[] {
|
||||
return rows.filter((item) =>
|
||||
minimatch(item.permissionValue ?? "", pattern, { nocase: true })
|
||||
|| minimatch(item.permissionDisplayName ?? "", pattern, { nocase: true }),
|
||||
);
|
||||
}
|
||||
|
||||
export function filterByDisplayName<T extends DisplayNameRow>(rows: T[], pattern: string): T[] {
|
||||
return rows.filter((item) =>
|
||||
minimatch(item.displayName ?? "", pattern, { nocase: true }),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getGraphClientFromPublicConfig(): Promise<{ client: any }> {
|
||||
const config = await loadPublicConfig();
|
||||
return getGraphClient({
|
||||
tenantId: config.tenantId,
|
||||
clientId: config.clientId,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user