ai-shit
This commit is contained in:
@@ -12,6 +12,15 @@ import type {
|
||||
TenantSnippet,
|
||||
TagResponse,
|
||||
} from './apiTypes';
|
||||
import type { AxiosInstance } from 'axios';
|
||||
|
||||
export const httpClient: Pick<AxiosInstance, 'get' | 'post' | 'patch' | 'delete' | 'defaults'> = {
|
||||
get: api.get.bind(api),
|
||||
post: api.post.bind(api),
|
||||
patch: api.patch.bind(api),
|
||||
delete: api.delete.bind(api),
|
||||
defaults: api.defaults,
|
||||
};
|
||||
|
||||
const normalizeNumber = (value: unknown): number | undefined => {
|
||||
const n = Number(value);
|
||||
@@ -158,6 +167,15 @@ export const performLogin = async (payload: Record<string, unknown>): Promise<un
|
||||
return data;
|
||||
};
|
||||
|
||||
export const refreshSession = async (): Promise<{ access_token?: string; tenant?: unknown }> => {
|
||||
const { data } = await api.post('/auth/refresh');
|
||||
return data as { access_token?: string; tenant?: unknown };
|
||||
};
|
||||
|
||||
export const logoutSession = async (): Promise<void> => {
|
||||
await api.post('/auth/logout');
|
||||
};
|
||||
|
||||
export const selectTenant = async (
|
||||
payload: { tenant_id: Identifier },
|
||||
selectionToken: string,
|
||||
@@ -247,6 +265,18 @@ export const listTenants = async (): Promise<TenantSnippet[]> => {
|
||||
return Array.isArray(data?.tenants) ? data.tenants : [];
|
||||
};
|
||||
|
||||
export const setAuthToken = (token?: string | null) => {
|
||||
if (token) {
|
||||
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
||||
} else {
|
||||
delete api.defaults.headers.common.Authorization;
|
||||
}
|
||||
};
|
||||
|
||||
export const clearAuthToken = () => {
|
||||
delete api.defaults.headers.common.Authorization;
|
||||
};
|
||||
|
||||
export type {
|
||||
DownloadLink,
|
||||
DocumentResponse,
|
||||
|
||||
Reference in New Issue
Block a user