This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

semble / src / webapp / features / cards / lib / dal.ts
3.0 kB 112 lines
1import { verifySessionOnClient } from '@/lib/auth/dal'; 2import { createSembleClient } from '@/services/apiClient'; 3import { cache } from 'react'; 4 5interface PageParams { 6 page?: number; 7 limit?: number; 8} 9 10export const getUrlMetadata = cache(async (url: string) => { 11 const client = createSembleClient(); 12 const response = await client.getUrlMetadata(url); 13 14 return response; 15}); 16 17export const getCardFromMyLibrary = cache(async (url: string) => { 18 const session = await verifySessionOnClient(); 19 if (!session) throw new Error('No session found'); 20 const client = createSembleClient(); 21 const response = await client.getUrlStatusForMyLibrary({ url: url }); 22 23 return response; 24}); 25 26export const getMyUrlCards = cache(async (params?: PageParams) => { 27 const session = await verifySessionOnClient(); 28 if (!session) throw new Error('No session found'); 29 const client = createSembleClient(); 30 const response = await client.getMyUrlCards({ 31 page: params?.page, 32 limit: params?.limit, 33 }); 34 35 return response; 36}); 37 38export const addUrlToLibrary = cache( 39 async ( 40 url: string, 41 { note, collectionIds }: { note?: string; collectionIds?: string[] }, 42 ) => { 43 const session = await verifySessionOnClient(); 44 if (!session) throw new Error('No session found'); 45 const client = createSembleClient(); 46 const response = await client.addUrlToLibrary({ 47 url: url, 48 note: note, 49 collectionIds: collectionIds, 50 }); 51 52 return response; 53 }, 54); 55 56export const getUrlCardView = cache(async (id: string) => { 57 const client = createSembleClient(); 58 const response = await client.getUrlCardView(id); 59 60 return response; 61}); 62 63export const getUrlCards = cache( 64 async (didOrHandle: string, params?: PageParams) => { 65 const client = createSembleClient(); 66 const response = await client.getUrlCards({ 67 identifier: didOrHandle, 68 page: params?.page, 69 limit: params?.limit, 70 }); 71 72 return response; 73 }, 74); 75 76export const removeCardFromCollection = cache( 77 async ({ 78 cardId, 79 collectionIds, 80 }: { 81 cardId: string; 82 collectionIds: string[]; 83 }) => { 84 const session = await verifySessionOnClient(); 85 if (!session) throw new Error('No session found'); 86 const client = createSembleClient(); 87 const response = await client.removeCardFromCollection({ 88 cardId, 89 collectionIds, 90 }); 91 92 return response; 93 }, 94); 95 96export const removeCardFromLibrary = cache(async (cardId: string) => { 97 const session = await verifySessionOnClient(); 98 if (!session) throw new Error('No session found'); 99 const client = createSembleClient(); 100 const response = await client.removeCardFromLibrary({ cardId }); 101 102 return response; 103}); 104 105export const getLibrariesForCard = cache(async (cardId: string) => { 106 const session = await verifySessionOnClient(); 107 if (!session) throw new Error('No session found'); 108 const client = createSembleClient(); 109 const response = await client.getLibrariesForCard(cardId); 110 111 return response; 112});