import {z} from 'zod' export type CreateApiV1EventSeriesEventSeriesIdOverridesArgs = {event_series_id: string, body: {max_sellable_tickets?: number | undefined, name: string, override_lines: {'{{id}}'?: ({price?: number | undefined, quantity?: number | undefined, status?: ('ON_SALE' | 'HIDDEN' | 'SOLD_OUT' | 'UNAVAILABLE' | 'ADMIN_ONLY') | undefined}) | undefined}}}; export type CreateApiV1EventSeriesEventSeriesIdOverridesOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const override = z.object({object: z.string().optional(), id: z.string().optional(), created_at: z.object({date: z.string().optional(), formatted: z.string().optional(), iso: z.string().optional(), time: z.string().optional(), timezone: z.string().optional(), unix: z.number().int().optional()}).optional(), max_sellable_tickets: z.number().int().nullable().optional(), name: z.string().optional(), override_lines: z.array(z.object({price: z.number().int().nullable().optional(), quantity: z.number().int().nullable().optional(), reference_type: z.enum(["ticket", "ticket_group"]).optional(), reference_id: z.string().optional(), status: z.enum(["ON_SALE", "SOLD_OUT", "UNAVAILABLE", "HIDDEN", "ADMIN_ONLY", "LOCKED"]).nullable().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 an override * * POST /v1/event_series/{event_series_id}/overrides */ export const createApiV1EventSeriesEventSeriesIdOverrides = async (args: CreateApiV1EventSeriesEventSeriesIdOverridesArgs, options?: CreateApiV1EventSeriesEventSeriesIdOverridesOptions) => { 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))}/overrides${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(override, await res.json()) };