This repository has no description
0

Configure Feed

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

semble / src / webapp / api-client / clients / UserClient.ts
2.7 kB 102 lines
1import { BaseClient } from './BaseClient'; 2import { 3 LoginWithAppPasswordRequest, 4 InitiateOAuthSignInRequest, 5 CompleteOAuthSignInRequest, 6 RefreshAccessTokenRequest, 7 GenerateExtensionTokensRequest, 8 LoginWithAppPasswordResponse, 9 InitiateOAuthSignInResponse, 10 CompleteOAuthSignInResponse, 11 RefreshAccessTokenResponse, 12 GenerateExtensionTokensResponse, 13 FollowTargetRequest, 14 FollowTargetResponse, 15} from '@semble/types'; 16 17export class UserClient extends BaseClient { 18 async loginWithAppPassword( 19 request: LoginWithAppPasswordRequest, 20 ): Promise<LoginWithAppPasswordResponse> { 21 return this.request<LoginWithAppPasswordResponse>( 22 'POST', 23 '/api/users/login/app-password', 24 request, 25 ); 26 } 27 28 async initiateOAuthSignIn( 29 request?: InitiateOAuthSignInRequest, 30 ): Promise<InitiateOAuthSignInResponse> { 31 const params = new URLSearchParams(); 32 if (request?.handle) { 33 params.set('handle', request.handle); 34 } 35 const queryString = params.toString(); 36 const endpoint = queryString 37 ? `/api/users/login?${queryString}` 38 : '/api/users/login'; 39 return this.request<InitiateOAuthSignInResponse>('GET', endpoint); 40 } 41 42 async completeOAuthSignIn( 43 request: CompleteOAuthSignInRequest, 44 ): Promise<CompleteOAuthSignInResponse> { 45 const params = new URLSearchParams({ 46 code: request.code, 47 state: request.state, 48 iss: request.iss, 49 }); 50 return this.request<CompleteOAuthSignInResponse>( 51 'GET', 52 `/api/users/oauth/callback?${params}`, 53 ); 54 } 55 56 async refreshAccessToken( 57 request: RefreshAccessTokenRequest, 58 ): Promise<RefreshAccessTokenResponse> { 59 return this.request<RefreshAccessTokenResponse>( 60 'POST', 61 '/api/users/oauth/refresh', 62 request, 63 ); 64 } 65 66 async generateExtensionTokens( 67 request?: GenerateExtensionTokensRequest, 68 ): Promise<GenerateExtensionTokensResponse> { 69 return this.request<GenerateExtensionTokensResponse>( 70 'GET', 71 '/api/users/extension/tokens', 72 ); 73 } 74 75 async logout(): Promise<{ success: boolean; message: string }> { 76 // With cookie-based auth, refreshToken is sent automatically via cookies 77 return this.request<{ success: boolean; message: string }>( 78 'POST', 79 '/api/users/logout', 80 ); 81 } 82 83 async followTarget( 84 request: FollowTargetRequest, 85 ): Promise<FollowTargetResponse> { 86 return this.request<FollowTargetResponse>( 87 'POST', 88 '/api/users/follows', 89 request, 90 ); 91 } 92 93 async unfollowTarget( 94 targetId: string, 95 targetType: 'USER' | 'COLLECTION', 96 ): Promise<void> { 97 return this.request<void>( 98 'DELETE', 99 `/api/users/follows/${targetId}/${targetType}`, 100 ); 101 } 102}