import { QueryClient, CardClient, CollectionClient, UserClient, FeedClient, NotificationClient, } from './clients'; import type { // Request types AddUrlToLibraryRequest, AddCardToLibraryRequest, AddCardToCollectionRequest, UpdateNoteCardRequest, UpdateUrlCardAssociationsRequest, RemoveCardFromLibraryRequest, RemoveCardFromCollectionRequest, CreateCollectionRequest, UpdateCollectionRequest, DeleteCollectionRequest, LoginWithAppPasswordRequest, InitiateOAuthSignInRequest, CompleteOAuthSignInRequest, RefreshAccessTokenRequest, GenerateExtensionTokensRequest, GetMyUrlCardsParams, GetCollectionPageParams, GetCollectionPageByAtUriParams, GetMyCollectionsParams, GetGlobalFeedParams, GetFollowingFeedParams, // Response types AddUrlToLibraryResponse, AddCardToLibraryResponse, AddCardToCollectionResponse, UpdateNoteCardResponse, UpdateUrlCardAssociationsResponse, RemoveCardFromLibraryResponse, RemoveCardFromCollectionResponse, CreateCollectionResponse, UpdateCollectionResponse, DeleteCollectionResponse, LoginWithAppPasswordResponse, InitiateOAuthSignInResponse, CompleteOAuthSignInResponse, RefreshAccessTokenResponse, GenerateExtensionTokensResponse, GetUrlMetadataResponse, GetUrlCardViewResponse, GetLibrariesForCardResponse, GetCollectionPageResponse, GetGlobalFeedResponse, GetCollectionsResponse, GetCollectionsParams, GetUrlCardsParams, GetUrlCardsResponse, GetProfileResponse, GetProfileParams, GetUrlStatusForMyLibraryParams, GetUrlStatusForMyLibraryResponse, GetLibrariesForUrlParams, GetLibrariesForUrlResponse, GetNoteCardsForUrlParams, GetNoteCardsForUrlResponse, GetCollectionsForUrlParams, GetCollectionsForUrlResponse, GetSimilarUrlsForUrlParams, GetSimilarUrlsForUrlResponse, SemanticSearchUrlsParams, SemanticSearchUrlsResponse, SearchBskyPostsForUrlParams, SearchBskyPostsForUrlResponse, SearchAtProtoAccountsParams, SearchAtProtoAccountsResponse, SearchLeafletDocsForUrlParams, SearchLeafletDocsForUrlResponse, GetMyNotificationsParams, GetMyNotificationsResponse, GetUnreadNotificationCountResponse, MarkNotificationsAsReadRequest, MarkNotificationsAsReadResponse, MarkAllNotificationsAsReadResponse, GetGemActivityFeedParams, SearchCollectionsParams, GetOpenCollectionsWithContributorParams, FollowTargetRequest, FollowTargetResponse, GetFollowingUsersParams, GetFollowingUsersResponse, GetFollowersParams, GetFollowersResponse, GetFollowingCollectionsParams, GetFollowingCollectionsResponse, GetCollectionFollowersParams, GetCollectionFollowersResponse, GetFollowingCountParams, GetFollowersCountParams, GetFollowingCollectionsCountParams, GetCollectionFollowersCountParams, GetFollowCountResponse, GetCollectionContributorsParams, GetCollectionContributorsResponse, } from '@semble/types'; // Main API Client class using composition export class ApiClient { private queryClient: QueryClient; private cardClient: CardClient; private collectionClient: CollectionClient; private userClient: UserClient; private feedClient: FeedClient; private notificationClient: NotificationClient; constructor( private baseUrl: string, accessToken?: string, ) { this.queryClient = new QueryClient(baseUrl, accessToken); this.cardClient = new CardClient(baseUrl, accessToken); this.collectionClient = new CollectionClient(baseUrl, accessToken); this.userClient = new UserClient(baseUrl, accessToken); this.feedClient = new FeedClient(baseUrl, accessToken); this.notificationClient = new NotificationClient(baseUrl, accessToken); } // Query operations - delegate to QueryClient async getUrlMetadata(url: string): Promise { return this.queryClient.getUrlMetadata(url); } async getMyUrlCards( params?: GetMyUrlCardsParams, ): Promise { return this.queryClient.getMyUrlCards(params); } async getUrlCards(params: GetUrlCardsParams): Promise { return this.queryClient.getUserUrlCards(params); } async getUrlCardView(cardId: string): Promise { return this.queryClient.getUrlCardView(cardId); } async getLibrariesForCard( cardId: string, ): Promise { return this.queryClient.getLibrariesForCard(cardId); } async getMyProfile(): Promise { return this.queryClient.getMyProfile(); } async getProfile(params: GetProfileParams): Promise { return this.queryClient.getUserProfile(params); } async getCollectionPage( collectionId: string, params?: GetCollectionPageParams, ): Promise { return this.queryClient.getCollectionPage(collectionId, params); } async getCollectionPageByAtUri( params: GetCollectionPageByAtUriParams, ): Promise { return this.queryClient.getCollectionPageByAtUri(params); } async getMyCollections( params?: GetMyCollectionsParams, ): Promise { return this.queryClient.getMyCollections(params); } async getCollections( params: GetCollectionsParams, ): Promise { return this.queryClient.getUserCollections(params); } async getOpenCollectionsWithContributor( params: GetOpenCollectionsWithContributorParams, ): Promise { return this.queryClient.getOpenCollectionsWithContributor(params); } async getUrlStatusForMyLibrary( params: GetUrlStatusForMyLibraryParams, ): Promise { return this.queryClient.getUrlStatusForMyLibrary(params); } async getLibrariesForUrl( params: GetLibrariesForUrlParams, ): Promise { return this.queryClient.getLibrariesForUrl(params); } async getNoteCardsForUrl( params: GetNoteCardsForUrlParams, ): Promise { return this.queryClient.getNoteCardsForUrl(params); } async getCollectionsForUrl( params: GetCollectionsForUrlParams, ): Promise { return this.queryClient.getCollectionsForUrl(params); } async getSimilarUrlsForUrl( params: GetSimilarUrlsForUrlParams, ): Promise { return this.queryClient.getSimilarUrlsForUrl(params); } async semanticSearchUrls( params: SemanticSearchUrlsParams, ): Promise { return this.queryClient.semanticSearchUrls(params); } async searchBskyPosts( params: SearchBskyPostsForUrlParams, ): Promise { return this.queryClient.searchBskyPosts(params); } async searchAtProtoAccounts( params: SearchAtProtoAccountsParams, ): Promise { return this.queryClient.searchAtProtoAccounts(params); } async searchLeafletDocs( params: SearchLeafletDocsForUrlParams, ): Promise { return this.queryClient.searchLeafletDocs(params); } // Follow query operations - delegate to QueryClient async getFollowingUsers( params: GetFollowingUsersParams, ): Promise { return this.queryClient.getFollowingUsers(params); } async getFollowers( params: GetFollowersParams, ): Promise { return this.queryClient.getFollowers(params); } async getFollowingCollections( params: GetFollowingCollectionsParams, ): Promise { return this.queryClient.getFollowingCollections(params); } async getCollectionFollowers( params: GetCollectionFollowersParams, ): Promise { return this.queryClient.getCollectionFollowers(params); } async getFollowingCount( params: GetFollowingCountParams, ): Promise { return this.queryClient.getFollowingCount(params); } async getFollowersCount( params: GetFollowersCountParams, ): Promise { return this.queryClient.getFollowersCount(params); } async getFollowingCollectionsCount( params: GetFollowingCollectionsCountParams, ): Promise { return this.queryClient.getFollowingCollectionsCount(params); } async getCollectionFollowersCount( params: GetCollectionFollowersCountParams, ): Promise { return this.queryClient.getCollectionFollowersCount(params); } async getCollectionContributors( params: GetCollectionContributorsParams, ): Promise { return this.queryClient.getCollectionContributors(params); } // Card operations - delegate to CardClient async addUrlToLibrary( request: AddUrlToLibraryRequest, ): Promise { return this.cardClient.addUrlToLibrary(request); } async addCardToLibrary( request: AddCardToLibraryRequest, ): Promise { return this.cardClient.addCardToLibrary(request); } async addCardToCollection( request: AddCardToCollectionRequest, ): Promise { return this.cardClient.addCardToCollection(request); } async updateNoteCard( request: UpdateNoteCardRequest, ): Promise { return this.cardClient.updateNoteCard(request); } async updateUrlCardAssociations( request: UpdateUrlCardAssociationsRequest, ): Promise { return this.cardClient.updateUrlCardAssociations(request); } async removeCardFromLibrary( request: RemoveCardFromLibraryRequest, ): Promise { return this.cardClient.removeCardFromLibrary(request); } async removeCardFromCollection( request: RemoveCardFromCollectionRequest, ): Promise { return this.cardClient.removeCardFromCollection(request); } // Collection operations - delegate to CollectionClient async createCollection( request: CreateCollectionRequest, ): Promise { return this.collectionClient.createCollection(request); } async updateCollection( request: UpdateCollectionRequest, ): Promise { return this.collectionClient.updateCollection(request); } async deleteCollection( request: DeleteCollectionRequest, ): Promise { return this.collectionClient.deleteCollection(request); } async searchCollections( params?: SearchCollectionsParams, ): Promise { return this.collectionClient.searchCollections(params); } // User operations - delegate to UserClient async loginWithAppPassword( request: LoginWithAppPasswordRequest, ): Promise { return this.userClient.loginWithAppPassword(request); } async initiateOAuthSignIn( request?: InitiateOAuthSignInRequest, ): Promise { return this.userClient.initiateOAuthSignIn(request); } async completeOAuthSignIn( request: CompleteOAuthSignInRequest, ): Promise { return this.userClient.completeOAuthSignIn(request); } async refreshAccessToken( request: RefreshAccessTokenRequest, ): Promise { return this.userClient.refreshAccessToken(request); } async generateExtensionTokens( request?: GenerateExtensionTokensRequest, ): Promise { return this.userClient.generateExtensionTokens(request); } async logout(): Promise<{ success: boolean; message: string }> { return this.userClient.logout(); } async followTarget( request: FollowTargetRequest, ): Promise { return this.userClient.followTarget(request); } async unfollowTarget( targetId: string, targetType: 'USER' | 'COLLECTION', ): Promise { return this.userClient.unfollowTarget(targetId, targetType); } // Feed operations - delegate to FeedClient async getGlobalFeed( params?: GetGlobalFeedParams, ): Promise { return this.feedClient.getGlobalFeed(params); } async getGemsActivityFeed( params?: GetGemActivityFeedParams, ): Promise { return this.feedClient.getGemsActivityFeed(params); } async getFollowingFeed( params?: GetFollowingFeedParams, ): Promise { return this.feedClient.getFollowingFeed(params); } // Notification operations - delegate to NotificationClient async getMyNotifications( params?: GetMyNotificationsParams, ): Promise { return this.notificationClient.getMyNotifications(params); } async getUnreadNotificationCount(): Promise { return this.notificationClient.getUnreadNotificationCount(); } async markNotificationsAsRead( request: MarkNotificationsAsReadRequest, ): Promise { return this.notificationClient.markNotificationsAsRead(request); } async markAllNotificationsAsRead(): Promise { return this.notificationClient.markAllNotificationsAsRead(); } } // Re-export types for convenience export * from '@semble/types'; // Factory functions for different client types export const createApiClient = () => { return new ApiClient( process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000', ); }; export const createServerApiClient = (accessToken?: string) => { return new ApiClient( process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000', accessToken, ); }; // Default client instance for backward compatibility export const apiClient = createApiClient();