import {z} from 'zod' export type GetApiStripeProductsArgs = {id?: unknown | undefined, name?: unknown | undefined, active?: unknown | undefined, default_price?: unknown | undefined, description?: unknown | undefined, created?: unknown | undefined, updated?: unknown | undefined, attrs?: unknown | 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 GetApiStripeProductsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const stripeProducts = z.object({id: z.string().optional(), name: z.string().optional(), active: z.boolean().optional(), default_price: z.string().optional(), description: z.string().optional(), created: z.string().optional(), updated: z.string().optional(), attrs: z.unknown()}); export const getApiStripeProductsResponse = z.array(stripeProducts); 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 /stripe_products */ export const getApiStripeProducts = async (args: GetApiStripeProductsArgs, options?: GetApiStripeProductsOptions) => { 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.name != null) query.append("name", String(args.name)) if (args.active != null) query.append("active", String(args.active)) if (args.default_price != null) query.append("default_price", String(args.default_price)) if (args.description != null) query.append("description", String(args.description)) if (args.created != null) query.append("created", String(args.created)) if (args.updated != null) query.append("updated", String(args.updated)) if (args.attrs != null) query.append("attrs", String(args.attrs)) 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(/\/+$/, '')}/stripe_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 validateResponse(getApiStripeProductsResponse, await res.json()) };