export type GetApiProductsArgs = {program_uid?: string | undefined}; export type GetApiProductsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * List Products * * GET /products */ export const getApiProducts = async (args: GetApiProductsArgs, options?: GetApiProductsOptions) => { const {baseUrl = "https://sandbox.newline53.com/api/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.program_uid != null) query.append("program_uid", String(args.program_uid)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/products${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 };