import type { ApiResponse } from '../types/api'; const BASE_URL = '/snp-connection/api'; let currentUserId: number = 1; export const setApiClientUserId = (userId: number) => { currentUserId = userId; }; const request = async (url: string, options: RequestInit = {}): Promise> => { const headers: Record = { 'Content-Type': 'application/json', 'X-User-Id': String(currentUserId), ...options.headers as Record, }; const response = await fetch(`${BASE_URL}${url}`, { ...options, headers, }); const data = await response.json() as ApiResponse; return data; }; export const get = (url: string): Promise> => { return request(url, { method: 'GET' }); }; export const post = (url: string, body?: unknown): Promise> => { return request(url, { method: 'POST', body: body ? JSON.stringify(body) : undefined, }); }; export const put = (url: string, body?: unknown): Promise> => { return request(url, { method: 'PUT', body: body ? JSON.stringify(body) : undefined, }); }; export const del = (url: string): Promise> => { return request(url, { method: 'DELETE' }); };