This repository has no description
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
10interface SearchParams {
11 sortBy?: string;
12 sortOrder?: 'asc' | 'desc';
13 searchText?: string;
14}
15
16export const getCollectionsForUrl = cache(
17 async (url: string, params?: PageParams) => {
18 const client = createSembleClient();
19 const response = await client.getCollectionsForUrl({
20 url,
21 page: params?.page,
22 limit: params?.limit,
23 });
24
25 return response;
26 },
27);
28
29export const getCollections = cache(
30 async (didOrHandle: string, params?: PageParams) => {
31 const client = createSembleClient();
32 const response = await client.getCollections({
33 identifier: didOrHandle,
34 limit: params?.limit,
35 page: params?.page,
36 });
37
38 return response;
39 },
40);
41
42export const getMyCollections = cache(
43 async (params?: PageParams & SearchParams) => {
44 const session = await verifySessionOnClient();
45 if (!session) throw new Error('No session found');
46 const client = createSembleClient();
47 const response = await client.getMyCollections({
48 page: params?.page,
49 limit: params?.limit,
50 sortBy: params?.sortBy,
51 sortOrder: params?.sortOrder,
52 searchText: params?.searchText,
53 });
54
55 return response;
56 },
57);
58
59export const createCollection = cache(
60 async (newCollection: { name: string; description: string }) => {
61 const session = await verifySessionOnClient();
62 if (!session) throw new Error('No session found');
63 const client = createSembleClient();
64 const response = await client.createCollection(newCollection);
65
66 return response;
67 },
68);
69
70export const deleteCollection = cache(async (id: string) => {
71 const session = await verifySessionOnClient();
72 if (!session) throw new Error('No session found');
73 const client = createSembleClient();
74 const response = await client.deleteCollection({ collectionId: id });
75
76 return response;
77});
78
79export const updateCollection = cache(
80 async (collection: {
81 collectionId: string;
82 rkey: string;
83 name: string;
84 description?: string;
85 }) => {
86 const session = await verifySessionOnClient();
87 if (!session) throw new Error('No session found');
88 const client = createSembleClient();
89 const response = await client.updateCollection(collection);
90
91 return response;
92 },
93);
94
95export const getCollectionPageByAtUri = cache(
96 async ({
97 recordKey,
98 handle,
99 params,
100 }: {
101 recordKey: string;
102 handle: string;
103 params?: PageParams;
104 }) => {
105 const client = createSembleClient();
106 const response = await client.getCollectionPageByAtUri({
107 recordKey,
108 handle,
109 page: params?.page,
110 limit: params?.limit,
111 });
112
113 return response;
114 },
115);