A social knowledge tool for researchers built on ATProto
1import { BaseClient } from './BaseClient';
2import {
3 AddUrlToLibraryRequest,
4 AddUrlToLibraryResponse,
5 AddCardToLibraryRequest,
6 AddCardToLibraryResponse,
7 AddCardToCollectionRequest,
8 AddCardToCollectionResponse,
9 UpdateNoteCardRequest,
10 UpdateNoteCardResponse,
11 RemoveCardFromLibraryRequest,
12 RemoveCardFromLibraryResponse,
13 RemoveCardFromCollectionRequest,
14 RemoveCardFromCollectionResponse,
15} from '../types';
16
17export class CardClient extends BaseClient {
18 async addUrlToLibrary(
19 request: AddUrlToLibraryRequest,
20 ): Promise<AddUrlToLibraryResponse> {
21 return this.request<AddUrlToLibraryResponse>(
22 'POST',
23 '/api/cards/library/urls',
24 request,
25 );
26 }
27
28 async addCardToLibrary(
29 request: AddCardToLibraryRequest,
30 ): Promise<AddCardToLibraryResponse> {
31 return this.request<AddCardToLibraryResponse>(
32 'POST',
33 '/api/cards/library',
34 request,
35 );
36 }
37
38 async addCardToCollection(
39 request: AddCardToCollectionRequest,
40 ): Promise<AddCardToCollectionResponse> {
41 return this.request<AddCardToCollectionResponse>(
42 'POST',
43 '/api/cards/collections',
44 request,
45 );
46 }
47
48 async updateNoteCard(
49 request: UpdateNoteCardRequest,
50 ): Promise<UpdateNoteCardResponse> {
51 return this.request<UpdateNoteCardResponse>(
52 'PUT',
53 `/api/cards/${request.cardId}/note`,
54 {
55 note: request.note,
56 },
57 );
58 }
59
60 async removeCardFromLibrary(
61 request: RemoveCardFromLibraryRequest,
62 ): Promise<RemoveCardFromLibraryResponse> {
63 return this.request<RemoveCardFromLibraryResponse>(
64 'DELETE',
65 `/api/cards/${request.cardId}/library`,
66 );
67 }
68
69 async removeCardFromCollection(
70 request: RemoveCardFromCollectionRequest,
71 ): Promise<RemoveCardFromCollectionResponse> {
72 const collectionIdsParam = request.collectionIds.join(',');
73 return this.request<RemoveCardFromCollectionResponse>(
74 'DELETE',
75 `/api/cards/${request.cardId}/collections?collectionIds=${encodeURIComponent(collectionIdsParam)}`,
76 );
77 }
78}