import {z} from 'zod' export type GetApiV1GuestsGuestIdPrepaidcardsArgs = {guest_id: string}; export type GetApiV1GuestsGuestIdPrepaidcardsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1GuestsGuestIdPrepaidcardsResponse = z.object({guest_prepaid_cards: z.array(z.object({prepaid_card_user_id: z.string().optional(), prepaid_card_number: z.string().optional(), invoice: z.object({id: z.string().optional(), status: z.number().int().optional(), invoice_number: z.string().optional()}).optional(), center: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), purchase_details: z.object({date: z.string().optional(), price: z.object({currency_id: z.number().int().optional(), sales: z.number().int().optional(), tax: z.number().int().optional(), final: z.number().int().optional()}).optional()}).optional(), expiration_date: z.string().optional(), value: z.number().int().optional(), balance: z.number().int().optional(), is_closed: z.boolean().optional(), is_one_time_use: z.boolean().optional(), has_open_invoices: z.number().int().optional(), sale_receipt_no: z.unknown(), sale_invoice: z.unknown(), notes: z.string().optional()})).optional(), error: z.unknown()}); 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 all prepaid cards of a guest * * GET /v1/guests/{guest_id}/prepaidcards */ export const getApiV1GuestsGuestIdPrepaidcards = async (args: GetApiV1GuestsGuestIdPrepaidcardsArgs, options?: GetApiV1GuestsGuestIdPrepaidcardsOptions) => { const {baseUrl = "https://api.zenoti.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/guests/${encodeURIComponent(String(args.guest_id))}/prepaidcards${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(getApiV1GuestsGuestIdPrepaidcardsResponse, await res.json()) };