This commit is contained in:
2025-11-22 18:19:55 +01:00
parent d3c76bc303
commit 014f489857
7 changed files with 124 additions and 141 deletions
+30
View File
@@ -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,
+1
View File
@@ -25,6 +25,7 @@ export interface AssetResponse {
mime_type: string;
metadata: Record<string, unknown>;
download?: DownloadLink | null;
[key: string]: unknown;
}
export interface DocumentVersionResponse {