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 / ApiClient.ts
12 kB 404 lines
1import { 2 QueryClient, 3 CardClient, 4 CollectionClient, 5 UserClient, 6 FeedClient, 7 NotificationClient, 8} from './clients'; 9import type { 10 // Request types 11 AddUrlToLibraryRequest, 12 AddCardToLibraryRequest, 13 AddCardToCollectionRequest, 14 UpdateNoteCardRequest, 15 UpdateUrlCardAssociationsRequest, 16 RemoveCardFromLibraryRequest, 17 RemoveCardFromCollectionRequest, 18 CreateCollectionRequest, 19 UpdateCollectionRequest, 20 DeleteCollectionRequest, 21 LoginWithAppPasswordRequest, 22 InitiateOAuthSignInRequest, 23 CompleteOAuthSignInRequest, 24 RefreshAccessTokenRequest, 25 GenerateExtensionTokensRequest, 26 GetMyUrlCardsParams, 27 GetCollectionPageParams, 28 GetCollectionPageByAtUriParams, 29 GetMyCollectionsParams, 30 GetGlobalFeedParams, 31 GetFollowingFeedParams, 32 // Response types 33 AddUrlToLibraryResponse, 34 AddCardToLibraryResponse, 35 AddCardToCollectionResponse, 36 UpdateNoteCardResponse, 37 UpdateUrlCardAssociationsResponse, 38 RemoveCardFromLibraryResponse, 39 RemoveCardFromCollectionResponse, 40 CreateCollectionResponse, 41 UpdateCollectionResponse, 42 DeleteCollectionResponse, 43 LoginWithAppPasswordResponse, 44 InitiateOAuthSignInResponse, 45 CompleteOAuthSignInResponse, 46 RefreshAccessTokenResponse, 47 GenerateExtensionTokensResponse, 48 GetUrlMetadataResponse, 49 GetUrlCardViewResponse, 50 GetLibrariesForCardResponse, 51 GetCollectionPageResponse, 52 GetGlobalFeedResponse, 53 GetCollectionsResponse, 54 GetCollectionsParams, 55 GetUrlCardsParams, 56 GetUrlCardsResponse, 57 GetProfileResponse, 58 GetProfileParams, 59 GetUrlStatusForMyLibraryParams, 60 GetUrlStatusForMyLibraryResponse, 61 GetLibrariesForUrlParams, 62 GetLibrariesForUrlResponse, 63 GetNoteCardsForUrlParams, 64 GetNoteCardsForUrlResponse, 65 GetCollectionsForUrlParams, 66 GetCollectionsForUrlResponse, 67 GetSimilarUrlsForUrlParams, 68 GetSimilarUrlsForUrlResponse, 69 SemanticSearchUrlsParams, 70 SemanticSearchUrlsResponse, 71 SearchBskyPostsForUrlParams, 72 SearchBskyPostsForUrlResponse, 73 SearchAtProtoAccountsParams, 74 SearchAtProtoAccountsResponse, 75 SearchLeafletDocsForUrlParams, 76 SearchLeafletDocsForUrlResponse, 77 GetMyNotificationsParams, 78 GetMyNotificationsResponse, 79 GetUnreadNotificationCountResponse, 80 MarkNotificationsAsReadRequest, 81 MarkNotificationsAsReadResponse, 82 MarkAllNotificationsAsReadResponse, 83 GetGemActivityFeedParams, 84 SearchCollectionsParams, 85 GetOpenCollectionsWithContributorParams, 86 FollowTargetRequest, 87 FollowTargetResponse, 88} from '@semble/types'; 89 90// Main API Client class using composition 91export class ApiClient { 92 private queryClient: QueryClient; 93 private cardClient: CardClient; 94 private collectionClient: CollectionClient; 95 private userClient: UserClient; 96 private feedClient: FeedClient; 97 private notificationClient: NotificationClient; 98 99 constructor( 100 private baseUrl: string, 101 accessToken?: string, 102 ) { 103 this.queryClient = new QueryClient(baseUrl, accessToken); 104 this.cardClient = new CardClient(baseUrl, accessToken); 105 this.collectionClient = new CollectionClient(baseUrl, accessToken); 106 this.userClient = new UserClient(baseUrl, accessToken); 107 this.feedClient = new FeedClient(baseUrl, accessToken); 108 this.notificationClient = new NotificationClient(baseUrl, accessToken); 109 } 110 111 // Query operations - delegate to QueryClient 112 async getUrlMetadata(url: string): Promise<GetUrlMetadataResponse> { 113 return this.queryClient.getUrlMetadata(url); 114 } 115 116 async getMyUrlCards( 117 params?: GetMyUrlCardsParams, 118 ): Promise<GetUrlCardsResponse> { 119 return this.queryClient.getMyUrlCards(params); 120 } 121 122 async getUrlCards(params: GetUrlCardsParams): Promise<GetUrlCardsResponse> { 123 return this.queryClient.getUserUrlCards(params); 124 } 125 126 async getUrlCardView(cardId: string): Promise<GetUrlCardViewResponse> { 127 return this.queryClient.getUrlCardView(cardId); 128 } 129 130 async getLibrariesForCard( 131 cardId: string, 132 ): Promise<GetLibrariesForCardResponse> { 133 return this.queryClient.getLibrariesForCard(cardId); 134 } 135 136 async getMyProfile(): Promise<GetProfileResponse> { 137 return this.queryClient.getMyProfile(); 138 } 139 140 async getProfile(params: GetProfileParams): Promise<GetProfileResponse> { 141 return this.queryClient.getUserProfile(params); 142 } 143 144 async getCollectionPage( 145 collectionId: string, 146 params?: GetCollectionPageParams, 147 ): Promise<GetCollectionPageResponse> { 148 return this.queryClient.getCollectionPage(collectionId, params); 149 } 150 151 async getCollectionPageByAtUri( 152 params: GetCollectionPageByAtUriParams, 153 ): Promise<GetCollectionPageResponse> { 154 return this.queryClient.getCollectionPageByAtUri(params); 155 } 156 157 async getMyCollections( 158 params?: GetMyCollectionsParams, 159 ): Promise<GetCollectionsResponse> { 160 return this.queryClient.getMyCollections(params); 161 } 162 163 async getCollections( 164 params: GetCollectionsParams, 165 ): Promise<GetCollectionsResponse> { 166 return this.queryClient.getUserCollections(params); 167 } 168 169 async getOpenCollectionsWithContributor( 170 params: GetOpenCollectionsWithContributorParams, 171 ): Promise<GetCollectionsResponse> { 172 return this.queryClient.getOpenCollectionsWithContributor(params); 173 } 174 175 async getUrlStatusForMyLibrary( 176 params: GetUrlStatusForMyLibraryParams, 177 ): Promise<GetUrlStatusForMyLibraryResponse> { 178 return this.queryClient.getUrlStatusForMyLibrary(params); 179 } 180 181 async getLibrariesForUrl( 182 params: GetLibrariesForUrlParams, 183 ): Promise<GetLibrariesForUrlResponse> { 184 return this.queryClient.getLibrariesForUrl(params); 185 } 186 187 async getNoteCardsForUrl( 188 params: GetNoteCardsForUrlParams, 189 ): Promise<GetNoteCardsForUrlResponse> { 190 return this.queryClient.getNoteCardsForUrl(params); 191 } 192 193 async getCollectionsForUrl( 194 params: GetCollectionsForUrlParams, 195 ): Promise<GetCollectionsForUrlResponse> { 196 return this.queryClient.getCollectionsForUrl(params); 197 } 198 199 async getSimilarUrlsForUrl( 200 params: GetSimilarUrlsForUrlParams, 201 ): Promise<GetSimilarUrlsForUrlResponse> { 202 return this.queryClient.getSimilarUrlsForUrl(params); 203 } 204 205 async semanticSearchUrls( 206 params: SemanticSearchUrlsParams, 207 ): Promise<SemanticSearchUrlsResponse> { 208 return this.queryClient.semanticSearchUrls(params); 209 } 210 211 async searchBskyPosts( 212 params: SearchBskyPostsForUrlParams, 213 ): Promise<SearchBskyPostsForUrlResponse> { 214 return this.queryClient.searchBskyPosts(params); 215 } 216 217 async searchAtProtoAccounts( 218 params: SearchAtProtoAccountsParams, 219 ): Promise<SearchAtProtoAccountsResponse> { 220 return this.queryClient.searchAtProtoAccounts(params); 221 } 222 223 async searchLeafletDocs( 224 params: SearchLeafletDocsForUrlParams, 225 ): Promise<SearchLeafletDocsForUrlResponse> { 226 return this.queryClient.searchLeafletDocs(params); 227 } 228 229 // Card operations - delegate to CardClient 230 async addUrlToLibrary( 231 request: AddUrlToLibraryRequest, 232 ): Promise<AddUrlToLibraryResponse> { 233 return this.cardClient.addUrlToLibrary(request); 234 } 235 236 async addCardToLibrary( 237 request: AddCardToLibraryRequest, 238 ): Promise<AddCardToLibraryResponse> { 239 return this.cardClient.addCardToLibrary(request); 240 } 241 242 async addCardToCollection( 243 request: AddCardToCollectionRequest, 244 ): Promise<AddCardToCollectionResponse> { 245 return this.cardClient.addCardToCollection(request); 246 } 247 248 async updateNoteCard( 249 request: UpdateNoteCardRequest, 250 ): Promise<UpdateNoteCardResponse> { 251 return this.cardClient.updateNoteCard(request); 252 } 253 254 async updateUrlCardAssociations( 255 request: UpdateUrlCardAssociationsRequest, 256 ): Promise<UpdateUrlCardAssociationsResponse> { 257 return this.cardClient.updateUrlCardAssociations(request); 258 } 259 260 async removeCardFromLibrary( 261 request: RemoveCardFromLibraryRequest, 262 ): Promise<RemoveCardFromLibraryResponse> { 263 return this.cardClient.removeCardFromLibrary(request); 264 } 265 266 async removeCardFromCollection( 267 request: RemoveCardFromCollectionRequest, 268 ): Promise<RemoveCardFromCollectionResponse> { 269 return this.cardClient.removeCardFromCollection(request); 270 } 271 272 // Collection operations - delegate to CollectionClient 273 async createCollection( 274 request: CreateCollectionRequest, 275 ): Promise<CreateCollectionResponse> { 276 return this.collectionClient.createCollection(request); 277 } 278 279 async updateCollection( 280 request: UpdateCollectionRequest, 281 ): Promise<UpdateCollectionResponse> { 282 return this.collectionClient.updateCollection(request); 283 } 284 285 async deleteCollection( 286 request: DeleteCollectionRequest, 287 ): Promise<DeleteCollectionResponse> { 288 return this.collectionClient.deleteCollection(request); 289 } 290 291 async searchCollections( 292 params?: SearchCollectionsParams, 293 ): Promise<GetCollectionsResponse> { 294 return this.collectionClient.searchCollections(params); 295 } 296 297 // User operations - delegate to UserClient 298 async loginWithAppPassword( 299 request: LoginWithAppPasswordRequest, 300 ): Promise<LoginWithAppPasswordResponse> { 301 return this.userClient.loginWithAppPassword(request); 302 } 303 304 async initiateOAuthSignIn( 305 request?: InitiateOAuthSignInRequest, 306 ): Promise<InitiateOAuthSignInResponse> { 307 return this.userClient.initiateOAuthSignIn(request); 308 } 309 310 async completeOAuthSignIn( 311 request: CompleteOAuthSignInRequest, 312 ): Promise<CompleteOAuthSignInResponse> { 313 return this.userClient.completeOAuthSignIn(request); 314 } 315 316 async refreshAccessToken( 317 request: RefreshAccessTokenRequest, 318 ): Promise<RefreshAccessTokenResponse> { 319 return this.userClient.refreshAccessToken(request); 320 } 321 322 async generateExtensionTokens( 323 request?: GenerateExtensionTokensRequest, 324 ): Promise<GenerateExtensionTokensResponse> { 325 return this.userClient.generateExtensionTokens(request); 326 } 327 328 async logout(): Promise<{ success: boolean; message: string }> { 329 return this.userClient.logout(); 330 } 331 332 async followTarget( 333 request: FollowTargetRequest, 334 ): Promise<FollowTargetResponse> { 335 return this.userClient.followTarget(request); 336 } 337 338 async unfollowTarget( 339 targetId: string, 340 targetType: 'USER' | 'COLLECTION', 341 ): Promise<void> { 342 return this.userClient.unfollowTarget(targetId, targetType); 343 } 344 345 // Feed operations - delegate to FeedClient 346 async getGlobalFeed( 347 params?: GetGlobalFeedParams, 348 ): Promise<GetGlobalFeedResponse> { 349 return this.feedClient.getGlobalFeed(params); 350 } 351 352 async getGemsActivityFeed( 353 params?: GetGemActivityFeedParams, 354 ): Promise<GetGlobalFeedResponse> { 355 return this.feedClient.getGemsActivityFeed(params); 356 } 357 358 async getFollowingFeed( 359 params?: GetFollowingFeedParams, 360 ): Promise<GetGlobalFeedResponse> { 361 return this.feedClient.getFollowingFeed(params); 362 } 363 364 // Notification operations - delegate to NotificationClient 365 async getMyNotifications( 366 params?: GetMyNotificationsParams, 367 ): Promise<GetMyNotificationsResponse> { 368 return this.notificationClient.getMyNotifications(params); 369 } 370 371 async getUnreadNotificationCount(): Promise<GetUnreadNotificationCountResponse> { 372 return this.notificationClient.getUnreadNotificationCount(); 373 } 374 375 async markNotificationsAsRead( 376 request: MarkNotificationsAsReadRequest, 377 ): Promise<MarkNotificationsAsReadResponse> { 378 return this.notificationClient.markNotificationsAsRead(request); 379 } 380 381 async markAllNotificationsAsRead(): Promise<MarkAllNotificationsAsReadResponse> { 382 return this.notificationClient.markAllNotificationsAsRead(); 383 } 384} 385 386// Re-export types for convenience 387export * from '@semble/types'; 388 389// Factory functions for different client types 390export const createApiClient = () => { 391 return new ApiClient( 392 process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000', 393 ); 394}; 395 396export const createServerApiClient = (accessToken?: string) => { 397 return new ApiClient( 398 process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000', 399 accessToken, 400 ); 401}; 402 403// Default client instance for backward compatibility 404export const apiClient = createApiClient();