export type GetApiV2AccountsArgs = {page?: number | undefined, per_page?: number | undefined, order_by?: string | undefined, direction?: string | undefined, 'x-customer-api-key'?: string | undefined}; export type GetApiV2AccountsOptions = {baseUrl: string, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; /** * List accounts * * GET /v2/accounts */ export const getApiV2Accounts = async (args: GetApiV2AccountsArgs, options: GetApiV2AccountsOptions) => { const {baseUrl, fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.direction != null) query.append("direction", String(args.direction)) if (args['x-customer-api-key'] != null) headers.set("x-customer-api-key", String(args['x-customer-api-key'])) if (defaultValue !== undefined) headers.set("x-customer-api-key", defaultValue) const url = `${baseUrl.replace(/\/+$/, '')}/v2/accounts${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 };