import {z} from 'zod' export type GetApiAccountArgs = {id?: string | undefined, created_at?: unknown | undefined, stripe_account_id?: unknown | undefined, capabilities?: unknown | undefined, details_submitted?: unknown | undefined, email?: unknown | undefined, payouts_enabled?: unknown | undefined, type?: unknown | undefined, charges_enabled?: unknown | undefined, requirements?: unknown | undefined, organization_id?: string | undefined, select?: string | undefined, order?: string | undefined, Range?: string | undefined, 'Range-Unit'?: string | undefined, offset?: string | undefined, limit?: string | undefined, Prefer?: 'count=none' | undefined}; export type GetApiAccountOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const account = z.object({id: z.string(), created_at: z.string(), stripe_account_id: z.string().optional(), capabilities: z.unknown(), details_submitted: z.boolean(), email: z.string(), payouts_enabled: z.boolean(), type: z.enum(["standard", "express", "custom"]), charges_enabled: z.boolean(), requirements: z.array(z.string()).optional(), organization_id: z.string()}); export const getApiAccountResponse = z.array(account); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * GET /account */ export const getApiAccount = async (args: GetApiAccountArgs, options?: GetApiAccountOptions) => { const {baseUrl = "https://vnaabuozknwgxuvnfwjo.supabase.co:443", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args.created_at != null) query.append("created_at", String(args.created_at)) if (args.stripe_account_id != null) query.append("stripe_account_id", String(args.stripe_account_id)) if (args.capabilities != null) query.append("capabilities", String(args.capabilities)) if (args.details_submitted != null) query.append("details_submitted", String(args.details_submitted)) if (args.email != null) query.append("email", String(args.email)) if (args.payouts_enabled != null) query.append("payouts_enabled", String(args.payouts_enabled)) if (args.type != null) query.append("type", String(args.type)) if (args.charges_enabled != null) query.append("charges_enabled", String(args.charges_enabled)) if (args.requirements != null) query.append("requirements", String(args.requirements)) if (args.organization_id != null) query.append("organization_id", String(args.organization_id)) if (args.select != null) query.append("select", String(args.select)) if (args.order != null) query.append("order", String(args.order)) if (args.Range != null) headers.set("Range", String(args.Range)) if (args['Range-Unit'] != null) headers.set("Range-Unit", String(args['Range-Unit'])) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.Prefer != null) headers.set("Prefer", String(args.Prefer)) const url = `${baseUrl.replace(/\/+$/, '')}/account${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 validateResponse(getApiAccountResponse, await res.json()) };