This repository has no description
8.3 kB
285 lines
1import {
2 QueryClient,
3 CardClient,
4 CollectionClient,
5 UserClient,
6 FeedClient,
7} from './clients';
8import type {
9 // Request types
10 AddUrlToLibraryRequest,
11 AddCardToLibraryRequest,
12 AddCardToCollectionRequest,
13 UpdateNoteCardRequest,
14 UpdateUrlCardAssociationsRequest,
15 RemoveCardFromLibraryRequest,
16 RemoveCardFromCollectionRequest,
17 CreateCollectionRequest,
18 UpdateCollectionRequest,
19 DeleteCollectionRequest,
20 LoginWithAppPasswordRequest,
21 InitiateOAuthSignInRequest,
22 CompleteOAuthSignInRequest,
23 RefreshAccessTokenRequest,
24 GenerateExtensionTokensRequest,
25 GetMyUrlCardsParams,
26 GetCollectionPageParams,
27 GetCollectionPageByAtUriParams,
28 GetMyCollectionsParams,
29 GetGlobalFeedParams,
30 // Response types
31 AddUrlToLibraryResponse,
32 AddCardToLibraryResponse,
33 AddCardToCollectionResponse,
34 UpdateNoteCardResponse,
35 UpdateUrlCardAssociationsResponse,
36 RemoveCardFromLibraryResponse,
37 RemoveCardFromCollectionResponse,
38 CreateCollectionResponse,
39 UpdateCollectionResponse,
40 DeleteCollectionResponse,
41 LoginWithAppPasswordResponse,
42 InitiateOAuthSignInResponse,
43 CompleteOAuthSignInResponse,
44 RefreshAccessTokenResponse,
45 GenerateExtensionTokensResponse,
46 GetUrlMetadataResponse,
47 GetUrlCardViewResponse,
48 GetLibrariesForCardResponse,
49 GetCollectionPageResponse,
50 GetGlobalFeedResponse,
51 GetCollectionsResponse,
52 GetCollectionsParams,
53 GetUrlCardsParams,
54 GetUrlCardsResponse,
55 GetProfileResponse,
56 GetProfileParams,
57 GetUrlStatusForMyLibraryParams,
58 GetUrlStatusForMyLibraryResponse,
59 GetLibrariesForUrlParams,
60 GetLibrariesForUrlResponse,
61 GetNoteCardsForUrlParams,
62 GetNoteCardsForUrlResponse,
63 GetCollectionsForUrlParams,
64 GetCollectionsForUrlResponse,
65} from '@semble/types';
66
67// Main API Client class using composition
68export class ApiClient {
69 private queryClient: QueryClient;
70 private cardClient: CardClient;
71 private collectionClient: CollectionClient;
72 private userClient: UserClient;
73 private feedClient: FeedClient;
74
75 constructor(private baseUrl: string) {
76 this.queryClient = new QueryClient(baseUrl);
77 this.cardClient = new CardClient(baseUrl);
78 this.collectionClient = new CollectionClient(baseUrl);
79 this.userClient = new UserClient(baseUrl);
80 this.feedClient = new FeedClient(baseUrl);
81 }
82
83 // Query operations - delegate to QueryClient
84 async getUrlMetadata(url: string): Promise<GetUrlMetadataResponse> {
85 return this.queryClient.getUrlMetadata(url);
86 }
87
88 async getMyUrlCards(
89 params?: GetMyUrlCardsParams,
90 ): Promise<GetUrlCardsResponse> {
91 return this.queryClient.getMyUrlCards(params);
92 }
93
94 async getUrlCards(params: GetUrlCardsParams): Promise<GetUrlCardsResponse> {
95 return this.queryClient.getUserUrlCards(params);
96 }
97
98 async getUrlCardView(cardId: string): Promise<GetUrlCardViewResponse> {
99 return this.queryClient.getUrlCardView(cardId);
100 }
101
102 async getLibrariesForCard(
103 cardId: string,
104 ): Promise<GetLibrariesForCardResponse> {
105 return this.queryClient.getLibrariesForCard(cardId);
106 }
107
108 async getMyProfile(): Promise<GetProfileResponse> {
109 return this.queryClient.getMyProfile();
110 }
111
112 async getProfile(params: GetProfileParams): Promise<GetProfileResponse> {
113 return this.queryClient.getUserProfile(params);
114 }
115
116 async getCollectionPage(
117 collectionId: string,
118 params?: GetCollectionPageParams,
119 ): Promise<GetCollectionPageResponse> {
120 return this.queryClient.getCollectionPage(collectionId, params);
121 }
122
123 async getCollectionPageByAtUri(
124 params: GetCollectionPageByAtUriParams,
125 ): Promise<GetCollectionPageResponse> {
126 return this.queryClient.getCollectionPageByAtUri(params);
127 }
128
129 async getMyCollections(
130 params?: GetMyCollectionsParams,
131 ): Promise<GetCollectionsResponse> {
132 return this.queryClient.getMyCollections(params);
133 }
134
135 async getCollections(
136 params: GetCollectionsParams,
137 ): Promise<GetCollectionsResponse> {
138 return this.queryClient.getUserCollections(params);
139 }
140
141 async getUrlStatusForMyLibrary(
142 params: GetUrlStatusForMyLibraryParams,
143 ): Promise<GetUrlStatusForMyLibraryResponse> {
144 return this.queryClient.getUrlStatusForMyLibrary(params);
145 }
146
147 async getLibrariesForUrl(
148 params: GetLibrariesForUrlParams,
149 ): Promise<GetLibrariesForUrlResponse> {
150 return this.queryClient.getLibrariesForUrl(params);
151 }
152
153 async getNoteCardsForUrl(
154 params: GetNoteCardsForUrlParams,
155 ): Promise<GetNoteCardsForUrlResponse> {
156 return this.queryClient.getNoteCardsForUrl(params);
157 }
158
159 async getCollectionsForUrl(
160 params: GetCollectionsForUrlParams,
161 ): Promise<GetCollectionsForUrlResponse> {
162 return this.queryClient.getCollectionsForUrl(params);
163 }
164
165 // Card operations - delegate to CardClient
166 async addUrlToLibrary(
167 request: AddUrlToLibraryRequest,
168 ): Promise<AddUrlToLibraryResponse> {
169 return this.cardClient.addUrlToLibrary(request);
170 }
171
172 async addCardToLibrary(
173 request: AddCardToLibraryRequest,
174 ): Promise<AddCardToLibraryResponse> {
175 return this.cardClient.addCardToLibrary(request);
176 }
177
178 async addCardToCollection(
179 request: AddCardToCollectionRequest,
180 ): Promise<AddCardToCollectionResponse> {
181 return this.cardClient.addCardToCollection(request);
182 }
183
184 async updateNoteCard(
185 request: UpdateNoteCardRequest,
186 ): Promise<UpdateNoteCardResponse> {
187 return this.cardClient.updateNoteCard(request);
188 }
189
190 async updateUrlCardAssociations(
191 request: UpdateUrlCardAssociationsRequest,
192 ): Promise<UpdateUrlCardAssociationsResponse> {
193 return this.cardClient.updateUrlCardAssociations(request);
194 }
195
196 async removeCardFromLibrary(
197 request: RemoveCardFromLibraryRequest,
198 ): Promise<RemoveCardFromLibraryResponse> {
199 return this.cardClient.removeCardFromLibrary(request);
200 }
201
202 async removeCardFromCollection(
203 request: RemoveCardFromCollectionRequest,
204 ): Promise<RemoveCardFromCollectionResponse> {
205 return this.cardClient.removeCardFromCollection(request);
206 }
207
208 // Collection operations - delegate to CollectionClient
209 async createCollection(
210 request: CreateCollectionRequest,
211 ): Promise<CreateCollectionResponse> {
212 return this.collectionClient.createCollection(request);
213 }
214
215 async updateCollection(
216 request: UpdateCollectionRequest,
217 ): Promise<UpdateCollectionResponse> {
218 return this.collectionClient.updateCollection(request);
219 }
220
221 async deleteCollection(
222 request: DeleteCollectionRequest,
223 ): Promise<DeleteCollectionResponse> {
224 return this.collectionClient.deleteCollection(request);
225 }
226
227 // User operations - delegate to UserClient
228 async loginWithAppPassword(
229 request: LoginWithAppPasswordRequest,
230 ): Promise<LoginWithAppPasswordResponse> {
231 return this.userClient.loginWithAppPassword(request);
232 }
233
234 async initiateOAuthSignIn(
235 request?: InitiateOAuthSignInRequest,
236 ): Promise<InitiateOAuthSignInResponse> {
237 return this.userClient.initiateOAuthSignIn(request);
238 }
239
240 async completeOAuthSignIn(
241 request: CompleteOAuthSignInRequest,
242 ): Promise<CompleteOAuthSignInResponse> {
243 return this.userClient.completeOAuthSignIn(request);
244 }
245
246 async refreshAccessToken(
247 request: RefreshAccessTokenRequest,
248 ): Promise<RefreshAccessTokenResponse> {
249 return this.userClient.refreshAccessToken(request);
250 }
251
252 async generateExtensionTokens(
253 request?: GenerateExtensionTokensRequest,
254 ): Promise<GenerateExtensionTokensResponse> {
255 return this.userClient.generateExtensionTokens(request);
256 }
257
258 async logout(): Promise<{ success: boolean; message: string }> {
259 return this.userClient.logout();
260 }
261
262 // Feed operations - delegate to FeedClient
263 async getGlobalFeed(
264 params?: GetGlobalFeedParams,
265 ): Promise<GetGlobalFeedResponse> {
266 return this.feedClient.getGlobalFeed(params);
267 }
268}
269
270// Re-export types for convenience
271export * from '@semble/types';
272
273// Factory functions for different client types
274export const createApiClient = () => {
275 return new ApiClient(
276 process.env.NEXT_PUBLIC_API_BASE_URL || 'http://127.0.0.1:3000',
277 );
278};
279
280export const createServerApiClient = () => {
281 return new ApiClient(process.env.API_BASE_URL || 'http://127.0.0.1:3000');
282};
283
284// Default client instance for backward compatibility
285export const apiClient = createApiClient();