// SPDX-License-Identifier: MIT import { Client } from "@microsoft/microsoft-graph-client"; import { acquireResourceTokenFromLogin } from "../azure/index.ts"; type GraphClientOptions = { tenantId?: string; clientId?: string; }; type GraphApiToken = { accessToken: string; [key: string]: unknown; }; export async function getGraphClient({ tenantId, clientId }: GraphClientOptions): Promise<{ graphApiToken: GraphApiToken; client: any }> { const graphApiToken = await acquireResourceTokenFromLogin({ tenantId, clientId, resource: "graph", }) as GraphApiToken; const client = Client.init({ authProvider: (done) => { done(null, graphApiToken.accessToken); }, }); return { graphApiToken, client }; }