import {z} from 'zod' export type GetApiAccountsAccountIdReservesArgs = {'Api-Version-Date'?: string | undefined, account_id: string}; export type GetApiAccountsAccountIdReservesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const accountReserveType = z.object({amount: z.string(), hold_period_days: z.number().int().nullable(), percentage: z.number().nullable(), type: z.enum(["regular", "bnpl", "sequra", "fraud_hold", "preshipment_hold"])}); export const accountReserveUnlockType = z.object({amount: z.string(), type: z.enum(["regular", "bnpl", "sequra", "fraud_hold", "preshipment_hold"])}); export const accountReserveUnlock = z.object({amount: z.string(), by_type: z.array(accountReserveUnlockType), date: z.string()}); export const accountReserve = z.object({amount: z.string(), by_type: z.array(accountReserveType), currency: z.string(), unlocks_by_date: z.array(accountReserveUnlock)}); export const getApiAccountsAccountIdReservesResponse = z.object({data: z.array(accountReserve)}); 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 }; /** * List Account Reserves * * GET /accounts/{account_id}/reserves */ export const getApiAccountsAccountIdReserves = async (args: GetApiAccountsAccountIdReservesArgs, options?: GetApiAccountsAccountIdReservesOptions) => { const {baseUrl = "https://api.whop.com/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Api-Version-Date'] != null) headers.set("Api-Version-Date", String(args['Api-Version-Date'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.account_id))}/reserves${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(getApiAccountsAccountIdReservesResponse, await res.json()) };