34 lines
1019 B
TypeScript
34 lines
1019 B
TypeScript
// SPDX-License-Identifier: MIT
|
|
|
|
import { minimatch } from "minimatch";
|
|
|
|
import { loadConfig } 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 loadConfig("public-config");
|
|
return getGraphClient(config.tenantId, config.clientId);
|
|
}
|