mirror of
https://github.com/papra-hq/papra.git
synced 2025-12-30 08:59:39 -06:00
31 lines
792 B
TypeScript
31 lines
792 B
TypeScript
import type { HttpClientOptions, ResponseType } from './http.client';
|
|
import { Platform } from 'react-native';
|
|
import { httpClient } from './http.client';
|
|
|
|
export type ApiClient = ReturnType<typeof createApiClient>;
|
|
|
|
export function createApiClient({
|
|
baseUrl,
|
|
getAuthCookie,
|
|
}: {
|
|
baseUrl: string;
|
|
getAuthCookie: () => string;
|
|
}) {
|
|
return async <T, R extends ResponseType = 'json'>({ path, ...rest}: { path: string } & Omit<HttpClientOptions<R>, 'url'>) => {
|
|
return httpClient<T, R>({
|
|
baseUrl,
|
|
url: path,
|
|
credentials: Platform.OS === 'web' ? 'include' : 'omit',
|
|
headers: {
|
|
...(Platform.OS === 'web'
|
|
? {}
|
|
: {
|
|
Cookie: getAuthCookie(),
|
|
}),
|
|
...rest.headers,
|
|
},
|
|
...rest,
|
|
});
|
|
};
|
|
}
|