export type GetApiApiClientsArgs = {page?: number | undefined, limit?: number | undefined, name?: string | undefined, active?: boolean | undefined}; export type GetApiApiClientsOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get all clients * * GET /api/clients */ export const getApiApiClients = async (args: GetApiApiClientsArgs, options: GetApiApiClientsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.name != null) query.append("name", String(args.name)) if (args.active != null) query.append("active", String(args.active)) if (apiKey !== undefined) headers.set("X-API-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/clients${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };