From e548d5796cfd8d7aded3b454c7fd258ae21c797a Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Mon, 20 Oct 2025 11:58:25 -0700 Subject: [PATCH] refactor: api client --- src/webapp/features/cards/lib/dal.ts | 4 +-- src/webapp/features/collections/lib/dal.ts | 4 +-- .../collections/lib/queries/useCollection.tsx | 4 +-- src/webapp/features/notes/lib/dal.ts | 4 +-- src/webapp/features/profile/lib/dal.ts | 4 +-- .../SembleLibrariesContainer.tsx | 3 +- .../SembleNotesContainer.tsx | 2 +- src/webapp/features/semble/lib/dal.ts | 4 +-- src/webapp/services/apiClient.ts | 30 +++++-------------- 9 files changed, 22 insertions(+), 37 deletions(-) diff --git a/src/webapp/features/cards/lib/dal.ts b/src/webapp/features/cards/lib/dal.ts index 5e6befa3..ba6f7a54 100644 --- a/src/webapp/features/cards/lib/dal.ts +++ b/src/webapp/features/cards/lib/dal.ts @@ -1,8 +1,8 @@ -import { createApiClient } from '@/services/apiClient'; +import { createSembleClient } from '@/services/apiClient'; import { cache } from 'react'; export const getUrlMetadata = cache(async (url: string) => { - const client = await createApiClient(); + const client = createSembleClient(); const response = await client.getUrlMetadata(url); return response; diff --git a/src/webapp/features/collections/lib/dal.ts b/src/webapp/features/collections/lib/dal.ts index baa14692..eb03a26f 100644 --- a/src/webapp/features/collections/lib/dal.ts +++ b/src/webapp/features/collections/lib/dal.ts @@ -1,4 +1,4 @@ -import { createApiClient } from '@/services/apiClient'; +import { createSembleClient } from '@/services/apiClient'; import { cache } from 'react'; interface PageParams { @@ -8,7 +8,7 @@ interface PageParams { export const getCollectionsForUrl = cache( async (url: string, params?: PageParams) => { - const client = await createApiClient(); + const client = createSembleClient(); const response = await client.getCollectionsForUrl({ url, page: params?.page, diff --git a/src/webapp/features/collections/lib/queries/useCollection.tsx b/src/webapp/features/collections/lib/queries/useCollection.tsx index 092bdc80..3464b2f4 100644 --- a/src/webapp/features/collections/lib/queries/useCollection.tsx +++ b/src/webapp/features/collections/lib/queries/useCollection.tsx @@ -1,4 +1,4 @@ -import { createApiClient } from '@/api-client/ApiClient'; +import { createSembleClient } from '@/services/apiClient'; import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; interface Props { @@ -8,7 +8,7 @@ interface Props { } export default function useCollection(props: Props) { - const apiClient = createApiClient(); + const apiClient = createSembleClient(); const limit = props.limit ?? 20; diff --git a/src/webapp/features/notes/lib/dal.ts b/src/webapp/features/notes/lib/dal.ts index 1f878305..2845dc8c 100644 --- a/src/webapp/features/notes/lib/dal.ts +++ b/src/webapp/features/notes/lib/dal.ts @@ -1,4 +1,4 @@ -import { createApiClient } from '@/services/apiClient'; +import { createSembleClient } from '@/services/apiClient'; import { cache } from 'react'; interface PageParams { @@ -8,7 +8,7 @@ interface PageParams { export const getNoteCardsForUrl = cache( async (url: string, params?: PageParams) => { - const client = await createApiClient(); + const client = createSembleClient(); const response = await client.getNoteCardsForUrl({ url, page: params?.page, diff --git a/src/webapp/features/profile/lib/dal.ts b/src/webapp/features/profile/lib/dal.ts index 8d6d4f1f..67678c4e 100644 --- a/src/webapp/features/profile/lib/dal.ts +++ b/src/webapp/features/profile/lib/dal.ts @@ -1,8 +1,8 @@ -import { createApiClient } from '@/services/apiClient'; +import { createSembleClient } from '@/services/apiClient'; import { cache } from 'react'; export const getProfile = cache(async (didOrHandle: string) => { - const client = await createApiClient(); + const client = createSembleClient(); const response = await client.getProfile({ identifier: didOrHandle, }); diff --git a/src/webapp/features/semble/containers/sembleLibrariesContainer/SembleLibrariesContainer.tsx b/src/webapp/features/semble/containers/sembleLibrariesContainer/SembleLibrariesContainer.tsx index dee47c5d..19101c1e 100644 --- a/src/webapp/features/semble/containers/sembleLibrariesContainer/SembleLibrariesContainer.tsx +++ b/src/webapp/features/semble/containers/sembleLibrariesContainer/SembleLibrariesContainer.tsx @@ -62,8 +62,7 @@ export default function SembleLibrariesContainer(props: Props) { lg: 3, }} > - <>{u.userId} - {/**/} + {/**/} ))} diff --git a/src/webapp/features/semble/containers/sembleNotesContainer/SembleNotesContainer.tsx b/src/webapp/features/semble/containers/sembleNotesContainer/SembleNotesContainer.tsx index ecf7ab6e..9bbefade 100644 --- a/src/webapp/features/semble/containers/sembleNotesContainer/SembleNotesContainer.tsx +++ b/src/webapp/features/semble/containers/sembleNotesContainer/SembleNotesContainer.tsx @@ -63,7 +63,7 @@ export default function SembleNotesContainer(props: Props) { > diff --git a/src/webapp/features/semble/lib/dal.ts b/src/webapp/features/semble/lib/dal.ts index ec110c1d..12d76781 100644 --- a/src/webapp/features/semble/lib/dal.ts +++ b/src/webapp/features/semble/lib/dal.ts @@ -1,4 +1,4 @@ -import { createApiClient } from '@/services/apiClient'; +import { createSembleClient } from '@/services/apiClient'; import { cache } from 'react'; interface PageParams { @@ -8,7 +8,7 @@ interface PageParams { export const getLibrariesForUrl = cache( async (url: string, params?: PageParams) => { - const client = await createApiClient(); + const client = createSembleClient(); const response = await client.getLibrariesForUrl({ url, page: params?.page, diff --git a/src/webapp/services/apiClient.ts b/src/webapp/services/apiClient.ts index 5b0bfce5..58b4c0e7 100644 --- a/src/webapp/services/apiClient.ts +++ b/src/webapp/services/apiClient.ts @@ -1,31 +1,17 @@ -import { ApiClient } from '@/api-client/ApiClient'; -import { - createClientTokenManager, - createServerTokenManager, -} from '@/services/auth'; +import { createApiClient, createServerApiClient } from '@/api-client/ApiClient'; -export const createServerSideApiClient = async () => { - const tokenManager = await createServerTokenManager(); - - return new ApiClient( - process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3000', - tokenManager, - ); +export const createServerSideSembleClient = () => { + return createServerApiClient(); }; -export const createClientSideApiClient = () => { - const tokenManager = createClientTokenManager(); - - return new ApiClient( - process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3000', - tokenManager, - ); +export const createClientSideSembleClient = () => { + return createApiClient(); }; -export const createApiClient = async () => { +export const createSembleClient = () => { if (typeof window === 'undefined') { - return await createServerSideApiClient(); + return createServerSideSembleClient(); } else { - return createClientSideApiClient(); + return createClientSideSembleClient(); } }; -- 2.51.2