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
14 kB 474 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 GetFollowingUsersParams, 89 GetFollowingUsersResponse, 90 GetFollowersParams, 91 GetFollowersResponse, 92 GetFollowingCollectionsParams, 93 GetFollowingCollectionsResponse, 94 GetCollectionFollowersParams, 95 GetCollectionFollowersResponse, 96 GetFollowingCountParams, 97 GetFollowersCountParams, 98 GetFollowingCollectionsCountParams, 99 GetCollectionFollowersCountParams, 100 GetFollowCountResponse, 101 GetCollectionContributorsParams, 102 GetCollectionContributorsResponse, 103} from '@semble/types'; 104 105// Main API Client class using composition 106export class ApiClient { 107 private queryClient: QueryClient; 108 private cardClient: CardClient; 109 private collectionClient: CollectionClient; 110 private userClient: UserClient; 111 private feedClient: FeedClient; 112 private notificationClient: NotificationClient; 113 114 constructor( 115 private baseUrl: string, 116 accessToken?: string, 117 ) { 118 this.queryClient = new QueryClient(baseUrl, accessToken); 119 this.cardClient = new CardClient(baseUrl, accessToken); 120 this.collectionClient = new CollectionClient(baseUrl, accessToken); 121 this.userClient = new UserClient(baseUrl, accessToken); 122 this.feedClient = new FeedClient(baseUrl, accessToken); 123 this.notificationClient = new NotificationClient(baseUrl, accessToken); 124 } 125 126 // Query operations - delegate to QueryClient 127 async getUrlMetadata(url: string): Promise<GetUrlMetadataResponse> { 128 return this.queryClient.getUrlMetadata(url); 129 } 130 131 async getMyUrlCards( 132 params?: GetMyUrlCardsParams, 133 ): Promise<GetUrlCardsResponse> { 134 return this.queryClient.getMyUrlCards(params); 135 } 136 137 async getUrlCards(params: GetUrlCardsParams): Promise<GetUrlCardsResponse> { 138 return this.queryClient.getUserUrlCards(params); 139 } 140 141 async getUrlCardView(cardId: string): Promise<GetUrlCardViewResponse> { 142 return this.queryClient.getUrlCardView(cardId); 143 } 144 145 async getLibrariesForCard( 146 cardId: string, 147 ): Promise<GetLibrariesForCardResponse> { 148 return this.queryClient.getLibrariesForCard(cardId); 149 } 150 151 async getMyProfile(): Promise<GetProfileResponse> { 152 return this.queryClient.getMyProfile(); 153 } 154 155 async getProfile(params: GetProfileParams): Promise<GetProfileResponse> { 156 return this.queryClient.getUserProfile(params); 157 } 158 159 async getCollectionPage( 160 collectionId: string, 161 params?: GetCollectionPageParams, 162 ): Promise<GetCollectionPageResponse> { 163 return this.queryClient.getCollectionPage(collectionId, params); 164 } 165 166 async getCollectionPageByAtUri( 167 params: GetCollectionPageByAtUriParams, 168 ): Promise<GetCollectionPageResponse> { 169 return this.queryClient.getCollectionPageByAtUri(params); 170 } 171 172 async getMyCollections( 173 params?: GetMyCollectionsParams, 174 ): Promise<GetCollectionsResponse> { 175 return this.queryClient.getMyCollections(params); 176 } 177 178 async getCollections( 179 params: GetCollectionsParams, 180 ): Promise<GetCollectionsResponse> { 181 return this.queryClient.getUserCollections(params); 182 } 183 184 async getOpenCollectionsWithContributor( 185 params: GetOpenCollectionsWithContributorParams, 186 ): Promise<GetCollectionsResponse> { 187 return this.queryClient.getOpenCollectionsWithContributor(params); 188 } 189 190 async getUrlStatusForMyLibrary( 191 params: GetUrlStatusForMyLibraryParams, 192 ): Promise<GetUrlStatusForMyLibraryResponse> { 193 return this.queryClient.getUrlStatusForMyLibrary(params); 194 } 195 196 async getLibrariesForUrl( 197 params: GetLibrariesForUrlParams, 198 ): Promise<GetLibrariesForUrlResponse> { 199 return this.queryClient.getLibrariesForUrl(params); 200 } 201 202 async getNoteCardsForUrl( 203 params: GetNoteCardsForUrlParams, 204 ): Promise<GetNoteCardsForUrlResponse> { 205 return this.queryClient.getNoteCardsForUrl(params); 206 } 207 208 async getCollectionsForUrl( 209 params: GetCollectionsForUrlParams, 210 ): Promise<GetCollectionsForUrlResponse> { 211 return this.queryClient.getCollectionsForUrl(params); 212 } 213 214 async getSimilarUrlsForUrl( 215 params: GetSimilarUrlsForUrlParams, 216 ): Promise<GetSimilarUrlsForUrlResponse> { 217 return this.queryClient.getSimilarUrlsForUrl(params); 218 } 219 220 async semanticSearchUrls( 221 params: SemanticSearchUrlsParams, 222 ): Promise<SemanticSearchUrlsResponse> { 223 return this.queryClient.semanticSearchUrls(params); 224 } 225 226 async searchBskyPosts( 227 params: SearchBskyPostsForUrlParams, 228 ): Promise<SearchBskyPostsForUrlResponse> { 229 return this.queryClient.searchBskyPosts(params); 230 } 231 232 async searchAtProtoAccounts( 233 params: SearchAtProtoAccountsParams, 234 ): Promise<SearchAtProtoAccountsResponse> { 235 return this.queryClient.searchAtProtoAccounts(params); 236 } 237 238 async searchLeafletDocs( 239 params: SearchLeafletDocsForUrlParams, 240 ): Promise<SearchLeafletDocsForUrlResponse> { 241 return this.queryClient.searchLeafletDocs(params); 242 } 243 244 // Follow query operations - delegate to QueryClient 245 async getFollowingUsers( 246 params: GetFollowingUsersParams, 247 ): Promise<GetFollowingUsersResponse> { 248 return this.queryClient.getFollowingUsers(params); 249 } 250 251 async getFollowers( 252 params: GetFollowersParams, 253 ): Promise<GetFollowersResponse> { 254 return this.queryClient.getFollowers(params); 255 } 256 257 async getFollowingCollections( 258 params: GetFollowingCollectionsParams, 259 ): Promise<GetFollowingCollectionsResponse> { 260 return this.queryClient.getFollowingCollections(params); 261 } 262 263 async getCollectionFollowers( 264 params: GetCollectionFollowersParams, 265 ): Promise<GetCollectionFollowersResponse> { 266 return this.queryClient.getCollectionFollowers(params); 267 } 268 269 async getFollowingCount( 270 params: GetFollowingCountParams, 271 ): Promise<GetFollowCountResponse> { 272 return this.queryClient.getFollowingCount(params); 273 } 274 275 async getFollowersCount( 276 params: GetFollowersCountParams, 277 ): Promise<GetFollowCountResponse> { 278 return this.queryClient.getFollowersCount(params); 279 } 280 281 async getFollowingCollectionsCount( 282 params: GetFollowingCollectionsCountParams, 283 ): Promise<GetFollowCountResponse> { 284 return this.queryClient.getFollowingCollectionsCount(params); 285 } 286 287 async getCollectionFollowersCount( 288 params: GetCollectionFollowersCountParams, 289 ): Promise<GetFollowCountResponse> { 290 return this.queryClient.getCollectionFollowersCount(params); 291 } 292 293 async getCollectionContributors( 294 params: GetCollectionContributorsParams, 295 ): Promise<GetCollectionContributorsResponse> { 296 return this.queryClient.getCollectionContributors(params); 297 } 298 299 // Card operations - delegate to CardClient 300 async addUrlToLibrary( 301 request: AddUrlToLibraryRequest, 302 ): Promise<AddUrlToLibraryResponse> { 303 return this.cardClient.addUrlToLibrary(request); 304 } 305 306 async addCardToLibrary( 307 request: AddCardToLibraryRequest, 308 ): Promise<AddCardToLibraryResponse> { 309 return this.cardClient.addCardToLibrary(request); 310 } 311 312 async addCardToCollection( 313 request: AddCardToCollectionRequest, 314 ): Promise<AddCardToCollectionResponse> { 315 return this.cardClient.addCardToCollection(request); 316 } 317 318 async updateNoteCard( 319 request: UpdateNoteCardRequest, 320 ): Promise<UpdateNoteCardResponse> { 321 return this.cardClient.updateNoteCard(request); 322 } 323 324 async updateUrlCardAssociations( 325 request: UpdateUrlCardAssociationsRequest, 326 ): Promise<UpdateUrlCardAssociationsResponse> { 327 return this.cardClient.updateUrlCardAssociations(request); 328 } 329 330 async removeCardFromLibrary( 331 request: RemoveCardFromLibraryRequest, 332 ): Promise<RemoveCardFromLibraryResponse> { 333 return this.cardClient.removeCardFromLibrary(request); 334 } 335 336 async removeCardFromCollection( 337 request: RemoveCardFromCollectionRequest, 338 ): Promise<RemoveCardFromCollectionResponse> { 339 return this.cardClient.removeCardFromCollection(request); 340 } 341 342 // Collection operations - delegate to CollectionClient 343 async createCollection( 344 request: CreateCollectionRequest, 345 ): Promise<CreateCollectionResponse> { 346 return this.collectionClient.createCollection(request); 347 } 348 349 async updateCollection( 350 request: UpdateCollectionRequest, 351 ): Promise<UpdateCollectionResponse> { 352 return this.collectionClient.updateCollection(request); 353 } 354 355 async deleteCollection( 356 request: DeleteCollectionRequest, 357 ): Promise<DeleteCollectionResponse> { 358 return this.collectionClient.deleteCollection(request); 359 } 360 361 async searchCollections( 362 params?: SearchCollectionsParams, 363 ): Promise<GetCollectionsResponse> { 364 return this.collectionClient.searchCollections(params); 365 } 366 367 // User operations - delegate to UserClient 368 async loginWithAppPassword( 369 request: LoginWithAppPasswordRequest, 370 ): Promise<LoginWithAppPasswordResponse> { 371 return this.userClient.loginWithAppPassword(request); 372 } 373 374 async initiateOAuthSignIn( 375 request?: InitiateOAuthSignInRequest, 376 ): Promise<InitiateOAuthSignInResponse> { 377 return this.userClient.initiateOAuthSignIn(request); 378 } 379 380 async completeOAuthSignIn( 381 request: CompleteOAuthSignInRequest, 382 ): Promise<CompleteOAuthSignInResponse> { 383 return this.userClient.completeOAuthSignIn(request); 384 } 385 386 async refreshAccessToken( 387 request: RefreshAccessTokenRequest, 388 ): Promise<RefreshAccessTokenResponse> { 389 return this.userClient.refreshAccessToken(request); 390 } 391 392 async generateExtensionTokens( 393 request?: GenerateExtensionTokensRequest, 394 ): Promise<GenerateExtensionTokensResponse> { 395 return this.userClient.generateExtensionTokens(request); 396 } 397 398 async logout(): Promise<{ success: boolean; message: string }> { 399 return this.userClient.logout(); 400 } 401 402 async followTarget( 403 request: FollowTargetRequest, 404 ): Promise<FollowTargetResponse> { 405 return this.userClient.followTarget(request); 406 } 407 408 async unfollowTarget( 409 targetId: string, 410 targetType: 'USER' | 'COLLECTION', 411 ): Promise<void> { 412 return this.userClient.unfollowTarget(targetId, targetType); 413 } 414 415 // Feed operations - delegate to FeedClient 416 async getGlobalFeed( 417 params?: GetGlobalFeedParams, 418 ): Promise<GetGlobalFeedResponse> { 419 return this.feedClient.getGlobalFeed(params); 420 } 421 422 async getGemsActivityFeed( 423 params?: GetGemActivityFeedParams, 424 ): Promise<GetGlobalFeedResponse> { 425 return this.feedClient.getGemsActivityFeed(params); 426 } 427 428 async getFollowingFeed( 429 params?: GetFollowingFeedParams, 430 ): Promise<GetGlobalFeedResponse> { 431 return this.feedClient.getFollowingFeed(params); 432 } 433 434 // Notification operations - delegate to NotificationClient 435 async getMyNotifications( 436 params?: GetMyNotificationsParams, 437 ): Promise<GetMyNotificationsResponse> { 438 return this.notificationClient.getMyNotifications(params); 439 } 440 441 async getUnreadNotificationCount(): Promise<GetUnreadNotificationCountResponse> { 442 return this.notificationClient.getUnreadNotificationCount(); 443 } 444 445 async markNotificationsAsRead( 446 request: MarkNotificationsAsReadRequest, 447 ): Promise<MarkNotificationsAsReadResponse> { 448 return this.notificationClient.markNotificationsAsRead(request); 449 } 450 451 async markAllNotificationsAsRead(): Promise<MarkAllNotificationsAsReadResponse> { 452 return this.notificationClient.markAllNotificationsAsRead(); 453 } 454} 455 456// Re-export types for convenience 457export * from '@semble/types'; 458 459// Factory functions for different client types 460export const createApiClient = () => { 461 return new ApiClient( 462 process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000', 463 ); 464}; 465 466export const createServerApiClient = (accessToken?: string) => { 467 return new ApiClient( 468 process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000', 469 accessToken, 470 ); 471}; 472 473// Default client instance for backward compatibility 474export const apiClient = createApiClient();