Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import type { Did } from "@atcute/lexicons/syntax";import type { OAuthUserAgent } from "@atcute/oauth-browser-client";import { getOrCreateDelegatedSession } from "$lib/api/actAs";import { organizationRole, type OrganizationRole } from "$lib/api/organizations";import { addController, getScopePresets, listControllers, removeController} from "$lib/api/tranquil";
export interface OrganizationMember { did: Did; handle?: string; role: OrganizationRole; grantedAt: string;}
export const listOrganizationMembers = async ( controllerAgent: OAuthUserAgent, orgDid: Did): Promise<OrganizationMember[]> => { const orgAgent = await getOrCreateDelegatedSession(controllerAgent, orgDid); const controllers = await listControllers(orgAgent); return controllers .filter((controller) => controller.isActive) .map((controller) => ({ did: controller.did, handle: controller.handle, role: organizationRole(controller.grantedScopes), grantedAt: controller.grantedAt }));};
export const inviteOrganizationMembers = async ( controllerAgent: OAuthUserAgent, orgDid: Did, dids: readonly Did[]): Promise<void> => { const orgAgent = await getOrCreateDelegatedSession(controllerAgent, orgDid); const editor = (await getScopePresets(orgAgent)).find((preset) => preset.name === "editor"); if (!editor) throw new Error("The organization's PDS does not offer an editor role."); for (const did of dids) { await addController(orgAgent, { controllerDid: did, grantedScopes: editor.scopes }); }};
export const removeOrganizationMember = async ( controllerAgent: OAuthUserAgent, orgDid: Did, memberDid: Did): Promise<void> => { const orgAgent = await getOrCreateDelegatedSession(controllerAgent, orgDid); await removeController(orgAgent, memberDid);};