import {z} from 'zod' export type GetApiBaseUrlV1CentersCenterIdInvoicesArgs = {'center-id': string, date?: string | undefined, search_type?: number | undefined, search_value?: string | undefined}; export type GetApiBaseUrlV1CentersCenterIdInvoicesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiBaseUrlV1CentersCenterIdInvoicesResponse = z.object({todays_invoices: z.unknown(), invoices: z.array(z.object({name: z.string().optional(), items: z.string().optional(), sale_date: z.string().optional(), appointment_date: z.string().optional(), start_time: z.string().optional(), price: z.number().int().optional(), discount: z.number().int().optional(), redemptions: z.number().int().optional(), final_price: z.number().int().optional(), final_price_tax: z.number().int().optional(), taxes: z.number().int().optional(), rounding_adjustment: z.number().int().optional(), mobile_phone: z.string().optional(), email: z.unknown(), invoice_id: z.string().optional(), receive_email: z.boolean().optional(), SSG_amount: z.number().int().optional(), unassigned_tip: z.number().int().optional(), app_group_id: z.string().optional(), user_id: z.string().optional(), therapist_name: z.unknown(), end_time: z.unknown(), preferred_pronoun: z.unknown(), invoice_no: z.string().optional()})).optional()}); 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 }; /** * Retrieve open invoices * * GET /{base_url}/v1/centers/{center_id}/invoices */ export const getApiBaseUrlV1CentersCenterIdInvoices = async (args: GetApiBaseUrlV1CentersCenterIdInvoicesArgs, options?: GetApiBaseUrlV1CentersCenterIdInvoicesOptions) => { const {baseUrl = "https://api.zenoti.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.date != null) query.append("date", String(args.date)) if (args.search_type != null) query.append("search_type", String(args.search_type)) if (args.search_value != null) query.append("search_value", String(args.search_value)) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.base_url))}/v1/centers/${encodeURIComponent(String(args.center_id))}/invoices${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(getApiBaseUrlV1CentersCenterIdInvoicesResponse, await res.json()) };