Migrated to TypeScript.
This commit is contained in:
30
src/graph/sp.ts
Normal file
30
src/graph/sp.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
type GraphResult<T = Record<string, unknown>> = {
|
||||
value?: T[];
|
||||
};
|
||||
|
||||
export async function getServicePrincipal(client: any, appId: string): Promise<Record<string, unknown> | 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<Record<string, unknown>> {
|
||||
const sp = await client.api("/servicePrincipals").post({
|
||||
appId,
|
||||
}) as Record<string, unknown>;
|
||||
|
||||
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<void> {
|
||||
await client.api(`/servicePrincipals/${spId}`).delete();
|
||||
}
|
||||
Reference in New Issue
Block a user