export type IcdCodes = Record; export type CreateApiApiV1OrderArgs = {body: IcdCodes}; export type CreateApiApiV1OrderOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create Order * * POST /api/v1/order */ export const createApiApiV1Order = async (args: CreateApiApiV1OrderArgs, options?: CreateApiApiV1OrderOptions) => { const {baseUrl = "https://api.truepill.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/order${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };