import {z} from 'zod' export type GetApiV1OrdersOrderIdArgs = {order_id: string}; export type GetApiV1OrdersOrderIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const issuedTicket = z.object({object: z.string(), id: z.string(), add_on_id: z.string().nullable().optional(), barcode: z.string(), barcode_url: z.string(), checked_in: z.string(), created_at: z.number().int(), custom_questions: z.array(z.object({question: z.string().optional(), answer: z.string().nullable().optional()})), description: z.string(), email: z.string().nullable(), event_id: z.string(), event_series_id: z.string(), group_ticket_barcode: z.string().nullable(), reference: z.string().nullable(), full_name: z.string().nullable(), first_name: z.string().nullable(), last_name: z.string().nullable(), listed_currency: z.object({base_multiplier: z.number().int().optional(), code: z.enum(["gbp", "usd", "eur", "sgd", "aud", "brl", "cad", "czk", "dkk", "hkd", "huf", "ils", "jpy", "myr", "mxn", "nok", "nzd", "php", "pln", "rub", "sek", "chf", "twd", "thb", "try"]).optional()}).nullable().optional(), listed_price: z.number().int().nullable().optional(), reservation: z.string().nullable(), status: z.enum(["valid", "voided"]), source: z.enum(["api", "dashboard_import"]).nullable(), ticket_type_id: z.string().nullable(), updated_at: z.number().int(), voided_at: z.number().int().nullable(), order_id: z.string().nullable(), qr_code_url: z.string()}); export const soldProduct = z.object({object: z.string(), id: z.string(), event_id: z.string().nullable(), fulfilment: z.enum(["none", "issued_ticket", "issued_membership", "issued_voucher"]), fulfilment_reference_id: z.string().nullable(), fulfilment_reference_name: z.string().nullable(), order_id: z.string(), product_id: z.string(), product_name: z.string(), sales_channel: z.enum(["event", "store"]), sales_channel_reference_name: z.string(), status: z.enum(["valid", "voided"]), store_id: z.number().int().nullable()}); export const paymentMethod = z.object({external_id: z.string().nullable(), id: z.string().nullable(), type: z.enum(["no_cost", "offline", "operator", "paypal", "stripe", "transfer"]), name: z.string().nullable(), instructions: z.string().nullable(), additional_stripe_payment_methods: z.array(z.string()), paypal_pay_later_enabled: z.string(), min_order_value: z.number().nullable(), max_order_value: z.number().nullable(), lead_time_before_event: z.number().int().nullable()}); export const order = z.object({object: z.string(), id: z.string(), buyer_details: z.object({address: z.object({address_1: z.string().nullable(), address_2: z.string().nullable(), address_3: z.string().nullable(), postal_code: z.string().nullable()}), custom_questions: z.array(z.object({question: z.string().optional(), answer: z.string().nullable().optional()})).optional(), email: z.string(), first_name: z.string(), last_name: z.string(), name: z.string(), phone: z.string().nullable()}), created_at: z.number().int(), currency: z.object({code: z.enum(["gbp", "usd", "eur", "sgd", "aud", "brl", "cad", "czk", "dkk", "hkd", "huf", "ils", "jpy", "myr", "mxn", "nok", "nzd", "php", "pln", "rub", "sek", "chf", "twd", "thb", "try"]), base_multiplier: z.number().int()}), event_summary: z.object({id: z.string().optional(), event_id: z.string().optional(), event_series_id: z.string().optional(), name: z.string().optional(), start_date: z.object({date: z.string(), formatted: z.string(), iso: z.string(), time: z.string(), timezone: z.string(), unix: z.number().int()}).optional(), end_date: z.object({date: z.string(), formatted: z.string(), iso: z.string(), time: z.string(), timezone: z.string(), unix: z.number().int()}).optional(), venue: z.object({country: z.string().nullable().optional(), name: z.string().nullable(), postal_code: z.string().nullable()}).optional()}).optional(), issued_tickets: z.array(issuedTicket).nullable(), sold_products: z.array(soldProduct).nullable(), line_items: z.array(z.object({object: z.string(), id: z.string(), booking_fee: z.number().int(), description: z.string(), item_id: z.string().nullable().optional(), quantity: z.number().int(), store_id: z.string().nullable().optional(), total: z.number().int(), type: z.enum(["ticket", "transaction_charge", "void", "tax", "gift_card", "donation"]), value: z.number().int()})), marketing_opt_in: z.string().nullable().optional(), meta_data: z.array(z.object({key: z.string().optional(), value: z.string().nullable().optional()})).optional(), notes: z.string().nullable().optional(), payment_method: paymentMethod, refund_amount: z.number().int(), refunded_voucher_id: z.number().int().nullable(), credited_out_amount: z.number().int().optional(), referral_tag: z.string().nullable(), status: z.enum(["completed", "pending", "cancelled"]), status_message: z.string().nullable(), subtotal: z.number().int(), tax: z.number().int(), tax_treatment: z.enum(["exclusive", "inclusive"]).optional(), total: z.number().int(), total_paid: z.number().int(), txn_id: z.string().nullable()}); 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 a single order * * GET /v1/orders/{order_id} */ export const getApiV1OrdersOrderId = async (args: GetApiV1OrdersOrderIdArgs, options?: GetApiV1OrdersOrderIdOptions) => { const {baseUrl = "https://api.tickettailor.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/orders/${encodeURIComponent(String(args.order_id))}${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(order, await res.json()) };