import {z} from 'zod' export type CreateApiV1EventSeriesEventSeriesIdBundlesArgs = {event_series_id: string, body: {access_code?: string | undefined, booking_fee?: number | undefined, description: string, name: string, price: number, product_ids?: ({[key: string]: {product_id?: string | undefined, quantity?: number | undefined}}) | undefined, status?: ('ADMIN_ONLY' | 'HIDDEN' | 'LOCKED' | 'SOLD_OUT' | 'ON_SALE' | 'UNAVAILABLE') | undefined, ticket_type_ids: {[key: string]: {ticket_type_id?: string | undefined, quantity?: number | undefined}}}}; export type CreateApiV1EventSeriesEventSeriesIdBundlesOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const bundle = z.object({object: z.string().optional(), id: z.string().optional(), access_code: z.string().nullable().optional(), booking_fee: z.number().int().optional(), description: z.string().optional(), group_id: z.string().nullable().optional(), name: z.string().optional(), price: z.number().int().optional(), products: z.array(z.object({id: z.string().optional(), quantity: z.number().int().optional()})).optional(), status: z.enum(["HIDDEN", "UNAVAILABLE", "ON_SALE", "SOLD_OUT"]).optional(), ticket_types: z.array(z.object({id: z.string().optional(), quantity: z.number().int().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 }; /** * Create a bundle * * POST /v1/event_series/{event_series_id}/bundles */ export const createApiV1EventSeriesEventSeriesIdBundles = async (args: CreateApiV1EventSeriesEventSeriesIdBundlesArgs, options?: CreateApiV1EventSeriesEventSeriesIdBundlesOptions) => { const {baseUrl = "https://api.tickettailor.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/event_series/${encodeURIComponent(String(args.event_series_id))}/bundles${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(bundle, await res.json()) };