Our Personal Data Server from scratch!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at fix/small-bugs 78 lines 2.5 kB view raw
1import type { AccessToken, Did, EmailAddress, Handle, ScopeSet } from "./types/branded.ts"; 2import type { Session } from "./types/api.ts"; 3import type { 4 DelegationAuditEntry, 5 DelegationControlledAccount, 6 DelegationController, 7 DelegationScopePreset, 8 SsoLinkedAccount, 9} from "./types/api.ts"; 10import { api, ApiError } from "./api.ts"; 11import type { Result } from "./types/result.ts"; 12 13export interface AuthenticatedClient { 14 readonly token: AccessToken; 15 readonly session: Session; 16 17 getSsoLinkedAccounts(): Promise<{ accounts: SsoLinkedAccount[] }>; 18 19 listDelegationControllers(): Promise< 20 Result<{ controllers: DelegationController[] }, ApiError> 21 >; 22 listDelegationControlledAccounts(): Promise< 23 Result<{ accounts: DelegationControlledAccount[] }, ApiError> 24 >; 25 getDelegationScopePresets(): Promise< 26 Result<{ presets: DelegationScopePreset[] }, ApiError> 27 >; 28 addDelegationController( 29 controllerDid: Did, 30 grantedScopes: ScopeSet, 31 ): Promise<Result<{ success: boolean }, ApiError>>; 32 removeDelegationController( 33 controllerDid: Did, 34 ): Promise<Result<{ success: boolean }, ApiError>>; 35 createDelegatedAccount( 36 handle: Handle, 37 email?: EmailAddress, 38 controllerScopes?: ScopeSet, 39 ): Promise<Result<{ did: Did; handle: Handle }, ApiError>>; 40 getDelegationAuditLog( 41 limit: number, 42 offset: number, 43 ): Promise< 44 Result<{ entries: DelegationAuditEntry[]; total: number }, ApiError> 45 >; 46 47 exportBlobs(): Promise<Blob>; 48} 49 50export function createAuthenticatedClient( 51 session: Session, 52): AuthenticatedClient { 53 const token = session.accessJwt; 54 55 return { 56 token, 57 session, 58 59 getSsoLinkedAccounts: () => api.getSsoLinkedAccounts(token), 60 61 listDelegationControllers: () => api.listDelegationControllers(token), 62 listDelegationControlledAccounts: () => 63 api.listDelegationControlledAccounts(token), 64 getDelegationScopePresets: () => api.getDelegationScopePresets(), 65 addDelegationController: (controllerDid, grantedScopes) => 66 api.addDelegationController(token, controllerDid, grantedScopes), 67 removeDelegationController: (controllerDid) => 68 api.removeDelegationController(token, controllerDid), 69 createDelegatedAccount: (handle, email, controllerScopes) => 70 api.createDelegatedAccount(token, handle, email, controllerScopes), 71 getDelegationAuditLog: (limit, offset) => 72 api.getDelegationAuditLog(token, limit, offset), 73 74 exportBlobs: () => api.exportBlobs(token), 75 }; 76} 77 78export { ApiError };