import {z} from 'zod' export type GetApiTransactionsArgs = {scheduled?: boolean | undefined, from?: string | undefined, to?: string | undefined, deposited_gt?: string | undefined, deposited_lt?: string | undefined, created_gt?: string | undefined, created_lt?: string | undefined, type?: string | undefined, limit?: number | undefined, offset?: number | undefined, brand?: string | undefined, location_ids?: string | undefined, rental_ids?: string | undefined, sort_by?: string | undefined, sort_dir?: string | undefined, payment_source?: string | undefined, status?: string | undefined, processor_settlement_id?: string | undefined, payment_processor_ids?: string | undefined, actual_deposited_gt?: string | undefined, actual_deposited_lt?: string | undefined, 'csv-token'?: string | undefined, csv?: boolean | undefined, simple?: boolean | undefined, include_failed?: boolean | undefined, include_incomplete?: boolean | undefined}; export type GetApiTransactionsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dBInterfaceMap = z.unknown(); export const paymentProcessorName = z.string(); export const paymentProcessor = z.object({country: z.string().optional(), external_processor: z.string().optional(), external_processor_id: z.string().optional(), name: paymentProcessorName.optional()}); export const transaction: z.ZodType = z.object({actual_deposit_date: z.string().optional(), adjustment: z.number().int().optional(), amount: z.number().int().optional(), auto_deposit: z.boolean().optional(), available: z.string().optional(), booking_id: z.number().int().optional(), brand: z.string().optional(), can_delete: z.boolean().optional(), can_finance_sync: z.boolean().optional(), can_refund: z.boolean().optional(), can_retry: z.boolean().optional(), can_reverse_transfer: z.boolean().optional(), can_sync: z.boolean().optional(), can_transfer: z.boolean().optional(), cc_fee: z.number().int().optional(), charged: z.string().optional(), created: z.string().optional(), created_by_id: z.number().int().optional(), deposit_date: z.string().optional(), description: z.string().optional(), display_charge_type: z.string().optional(), display_payment_processor_name: z.string().optional(), display_type: z.string().optional(), dispute_reason: z.string().nullable().optional(), dispute_status: z.string().nullable().optional(), disputed: z.boolean().optional(), expected_deposit_date: z.string().optional(), failed: z.boolean().optional(), fraudulent: z.boolean().optional(), fx_fee: z.number().int().optional(), id: z.number().int().optional(), is_refund: z.boolean().optional(), last_four: z.string().optional(), original_charge_id: z.lazy(() => transaction.optional()), our_fee: z.number().int().optional(), outdoorsy_fee: z.number().int().optional(), owner_federal_withholding_tax: z.number().int().optional(), owner_fee: z.number().int().optional(), owner_integrations_fee: z.number().int().nullable().optional(), owner_quebec_sales_tax: z.number().int().optional(), paid: z.boolean().optional(), payment_meta: dBInterfaceMap.optional(), payment_processor: paymentProcessor.optional(), payment_source: z.string().optional(), processor_settlement_id: z.string().nullable().optional(), recipient_id: z.number().int().optional(), refund_source: z.string().optional(), refunded: z.number().int().optional(), refunded_cc_fee: z.number().int().optional(), refunded_fee: z.number().int().optional(), refunded_fx_fee: z.number().int().optional(), refunded_outdoorsy_fee: z.number().int().optional(), refunded_owner_federal_withholding_tax: z.number().int().optional(), refunded_owner_fee: z.number().int().optional(), refunded_owner_integrations_fee: z.number().int().nullable().optional(), refunded_owner_quebec_sales_tax: z.number().int().optional(), refunded_service_fee: z.number().int().optional(), retry_payout_id: z.lazy(() => transaction.optional()), sales_tax: z.number().int().optional(), service_fee: z.number().int().optional(), status: z.string().optional(), stripe_fee: z.number().int().optional(), stripe_fee_refund: z.number().int().optional(), stripe_id: z.string().optional(), transfer: z.lazy(() => transaction.optional()), type: z.string().optional()}); export const getApiTransactionsResponse = z.array(transaction); 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 }; /** * Global read many transactions, across all bookings. * * GET /transactions * * Also accepts auth: API-Key */ export const getApiTransactions = async (args: GetApiTransactionsArgs, options: GetApiTransactionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.scheduled != null) query.append("scheduled", String(args.scheduled)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.deposited_gt != null) query.append("deposited_gt", String(args.deposited_gt)) if (args.deposited_lt != null) query.append("deposited_lt", String(args.deposited_lt)) if (args.created_gt != null) query.append("created_gt", String(args.created_gt)) if (args.created_lt != null) query.append("created_lt", String(args.created_lt)) if (args.type != null) query.append("type", String(args.type)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.brand != null) query.append("brand", String(args.brand)) if (args.location_ids != null) query.append("location_ids", String(args.location_ids)) if (args.rental_ids != null) query.append("rental_ids", String(args.rental_ids)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_dir != null) query.append("sort_dir", String(args.sort_dir)) if (args.payment_source != null) query.append("payment_source", String(args.payment_source)) if (args.status != null) query.append("status", String(args.status)) if (args.processor_settlement_id != null) query.append("processor_settlement_id", String(args.processor_settlement_id)) if (args.payment_processor_ids != null) query.append("payment_processor_ids", String(args.payment_processor_ids)) if (args.actual_deposited_gt != null) query.append("actual_deposited_gt", String(args.actual_deposited_gt)) if (args.actual_deposited_lt != null) query.append("actual_deposited_lt", String(args.actual_deposited_lt)) if (args['csv-token'] != null) query.append("csv-token", String(args['csv-token'])) if (args.csv != null) query.append("csv", String(args.csv)) if (args.simple != null) query.append("simple", String(args.simple)) if (args.include_failed != null) query.append("include_failed", String(args.include_failed)) if (args.include_incomplete != null) query.append("include_incomplete", String(args.include_incomplete)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/transactions${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(getApiTransactionsResponse, await res.json()) };