// SPDX-License-Identifier: MIT type GraphResult> = { value?: T[]; }; export async function getServicePrincipal(client: any, appId: string): Promise | null> { const result = await client .api("/servicePrincipals") .filter(`appId eq '${appId}'`) .get() as GraphResult; return Array.isArray(result.value) && result.value.length > 0 ? result.value[0] : null; } export async function createSp(client: any, appId: string): Promise> { const sp = await client.api("/servicePrincipals").post({ appId, }) as Record; if (!sp || typeof sp.id !== "string") { throw new Error("Failed to create service principal"); } return sp; } export async function deleteSp(client: any, spId: string): Promise { await client.api(`/servicePrincipals/${spId}`).delete(); }