import {z} from 'zod' export type GetApiPricesArgs = {id?: unknown | undefined, product_id?: unknown | undefined, active?: unknown | undefined, description?: unknown | undefined, unit_amount?: unknown | undefined, currency?: unknown | undefined, type?: unknown | undefined, interval?: unknown | undefined, interval_count?: unknown | undefined, trial_period_days?: unknown | undefined, metadata?: 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 GetApiPricesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const prices = z.object({id: z.string(), product_id: z.string().optional(), active: z.boolean().optional(), description: z.string().optional(), unit_amount: z.number().int().optional(), currency: z.string().optional(), type: z.enum(["one_time", "recurring"]).optional(), interval: z.enum(["day", "week", "month", "year"]).optional(), interval_count: z.number().int().optional(), trial_period_days: z.number().int().optional(), metadata: z.unknown()}); export const getApiPricesResponse = z.array(prices); 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 /prices */ export const getApiPrices = async (args: GetApiPricesArgs, options?: GetApiPricesOptions) => { 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.product_id != null) query.append("product_id", String(args.product_id)) if (args.active != null) query.append("active", String(args.active)) if (args.description != null) query.append("description", String(args.description)) if (args.unit_amount != null) query.append("unit_amount", String(args.unit_amount)) if (args.currency != null) query.append("currency", String(args.currency)) if (args.type != null) query.append("type", String(args.type)) if (args.interval != null) query.append("interval", String(args.interval)) if (args.interval_count != null) query.append("interval_count", String(args.interval_count)) if (args.trial_period_days != null) query.append("trial_period_days", String(args.trial_period_days)) if (args.metadata != null) query.append("metadata", String(args.metadata)) 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(/\/+$/, '')}/prices${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(getApiPricesResponse, await res.json()) };