import {z} from 'zod' export type GetApiAmsClientIDEventEventIdTicketsArgs = {TicketId?: number | undefined, EventId: number, DateCreated?: string | undefined, Name?: string | undefined, Quantity?: number | undefined, ChargeForEvent?: boolean | undefined, Active?: boolean | undefined, Required?: boolean | undefined, Type?: string | undefined, Description?: string | undefined, Category?: number | undefined, UseInventory?: boolean | undefined, Available?: string | undefined, SKU?: string | undefined, GLCode?: string | undefined, QBClass?: string | undefined, UnitPrice?: number | undefined, Prices?: string | undefined, ExcludeFromEvent?: boolean | undefined, PromoCodeIds?: string | undefined, IsForCopy?: boolean | undefined, IsForReuse?: boolean | undefined, IsLinked?: boolean | undefined, EventTicketLinkId?: number | undefined, TaxLocationID?: number | undefined, IsFreestoneProduct?: boolean | undefined, FreestoneProductTypeId?: number | undefined, FreestoneCourseTypeId?: number | undefined, IsFreestoneProductSynced?: boolean | undefined, UsingRedis?: boolean | undefined, AppInitTime?: string | undefined, ServerID?: string | undefined, ClientID: number, ResponseStatus?: string | undefined, BypassCache?: boolean | undefined, DateCached?: string | undefined, Device?: string | undefined}; export type GetApiAmsClientIDEventEventIdTicketsOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const productPrice = z.object({Id: z.number().int().optional(), Name: z.string().optional(), Price: z.number().optional()}); export const dictionaryStringString = z.record(z.string(), z.string()); export const responseError = z.object({ErrorCode: z.string().optional(), FieldName: z.string().optional(), Message: z.string().optional(), Meta: dictionaryStringString.optional()}); export const responseStatus = z.object({ErrorCode: z.string().optional(), Message: z.string().optional(), StackTrace: z.string().optional(), Errors: z.array(responseError).optional(), Meta: dictionaryStringString.optional()}); export const eventTickets = z.object({TicketId: z.number().int().optional(), EventId: z.number().int().optional(), DateCreated: z.string().optional(), Name: z.string().optional(), Quantity: z.number().int().optional(), ChargeForEvent: z.boolean().optional(), Active: z.boolean().optional(), Required: z.boolean().optional(), Type: z.string().optional(), Description: z.string().optional(), Category: z.number().int().optional(), UseInventory: z.boolean().optional(), Available: z.string().optional(), SKU: z.string().optional(), GLCode: z.string().optional(), QBClass: z.string().optional(), UnitPrice: z.number().optional(), Prices: z.array(productPrice).optional(), ExcludeFromEvent: z.boolean().optional(), PromoCodeIds: z.array(z.number().int()).optional(), IsForCopy: z.boolean().optional(), IsForReuse: z.boolean().optional(), IsLinked: z.boolean().optional(), EventTicketLinkId: z.number().int().optional(), TaxLocationID: z.number().int().optional(), IsFreestoneProduct: z.boolean().optional(), FreestoneProductTypeId: z.number().int().optional(), FreestoneCourseTypeId: z.number().int().optional(), IsFreestoneProductSynced: z.boolean().optional(), UsingRedis: z.boolean().optional(), AppInitTime: z.string().optional(), ServerID: z.string().optional(), ClientID: z.number().int().optional(), ResponseStatus: responseStatus.optional(), BypassCache: z.boolean().optional(), DateCached: z.string().optional(), Device: z.string().optional()}); export const eventTicketsResponse = z.object({Tickets: z.array(eventTickets).optional(), RestrictAvailableTypes: z.boolean().optional(), TicketId: z.number().int().optional(), EventId: z.number().int().optional(), DateCreated: z.string().optional(), Name: z.string().optional(), Quantity: z.number().int().optional(), ChargeForEvent: z.boolean().optional(), Active: z.boolean().optional(), Required: z.boolean().optional(), Type: z.string().optional(), Description: z.string().optional(), Category: z.number().int().optional(), UseInventory: z.boolean().optional(), Available: z.string().optional(), SKU: z.string().optional(), GLCode: z.string().optional(), QBClass: z.string().optional(), UnitPrice: z.number().optional(), Prices: z.array(productPrice).optional(), ExcludeFromEvent: z.boolean().optional(), PromoCodeIds: z.array(z.number().int()).optional(), IsForCopy: z.boolean().optional(), IsForReuse: z.boolean().optional(), IsLinked: z.boolean().optional(), EventTicketLinkId: z.number().int().optional(), TaxLocationID: z.number().int().optional(), IsFreestoneProduct: z.boolean().optional(), FreestoneProductTypeId: z.number().int().optional(), FreestoneCourseTypeId: z.number().int().optional(), IsFreestoneProductSynced: z.boolean().optional(), UsingRedis: z.boolean().optional(), AppInitTime: z.string().optional(), ServerID: z.string().optional(), ClientID: z.number().int().optional(), ResponseStatus: responseStatus.optional(), BypassCache: z.boolean().optional(), DateCached: z.string().optional(), Device: z.string().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 }; /** * Return a list of tickets linked to an event. * * GET /Ams/{ClientID}/Event/{EventId}/Tickets */ export const getApiAmsClientIDEventEventIdTickets = async (args: GetApiAmsClientIDEventEventIdTicketsArgs, options?: GetApiAmsClientIDEventEventIdTicketsOptions) => { const {baseUrl = "https://ws.yourmembership.com", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.TicketId != null) query.append("TicketId", String(args.TicketId)) if (args.DateCreated != null) query.append("DateCreated", String(args.DateCreated)) if (args.Name != null) query.append("Name", String(args.Name)) if (args.Quantity != null) query.append("Quantity", String(args.Quantity)) if (args.ChargeForEvent != null) query.append("ChargeForEvent", String(args.ChargeForEvent)) if (args.Active != null) query.append("Active", String(args.Active)) if (args.Required != null) query.append("Required", String(args.Required)) if (args.Type != null) query.append("Type", String(args.Type)) if (args.Description != null) query.append("Description", String(args.Description)) if (args.Category != null) query.append("Category", String(args.Category)) if (args.UseInventory != null) query.append("UseInventory", String(args.UseInventory)) if (args.Available != null) query.append("Available", String(args.Available)) if (args.SKU != null) query.append("SKU", String(args.SKU)) if (args.GLCode != null) query.append("GLCode", String(args.GLCode)) if (args.QBClass != null) query.append("QBClass", String(args.QBClass)) if (args.UnitPrice != null) query.append("UnitPrice", String(args.UnitPrice)) if (args.Prices != null) query.append("Prices", String(args.Prices)) if (args.ExcludeFromEvent != null) query.append("ExcludeFromEvent", String(args.ExcludeFromEvent)) if (args.PromoCodeIds != null) query.append("PromoCodeIds", String(args.PromoCodeIds)) if (args.IsForCopy != null) query.append("IsForCopy", String(args.IsForCopy)) if (args.IsForReuse != null) query.append("IsForReuse", String(args.IsForReuse)) if (args.IsLinked != null) query.append("IsLinked", String(args.IsLinked)) if (args.EventTicketLinkId != null) query.append("EventTicketLinkId", String(args.EventTicketLinkId)) if (args.TaxLocationID != null) query.append("TaxLocationID", String(args.TaxLocationID)) if (args.IsFreestoneProduct != null) query.append("IsFreestoneProduct", String(args.IsFreestoneProduct)) if (args.FreestoneProductTypeId != null) query.append("FreestoneProductTypeId", String(args.FreestoneProductTypeId)) if (args.FreestoneCourseTypeId != null) query.append("FreestoneCourseTypeId", String(args.FreestoneCourseTypeId)) if (args.IsFreestoneProductSynced != null) query.append("IsFreestoneProductSynced", String(args.IsFreestoneProductSynced)) if (args.UsingRedis != null) query.append("UsingRedis", String(args.UsingRedis)) if (args.AppInitTime != null) query.append("AppInitTime", String(args.AppInitTime)) if (args.ServerID != null) query.append("ServerID", String(args.ServerID)) if (args.ResponseStatus != null) query.append("ResponseStatus", String(args.ResponseStatus)) if (args.BypassCache != null) query.append("BypassCache", String(args.BypassCache)) if (args.DateCached != null) query.append("DateCached", String(args.DateCached)) if (args.Device != null) query.append("Device", String(args.Device)) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/Ams/${encodeURIComponent(String(args.ClientID))}/Event/${encodeURIComponent(String(args.EventId))}/Tickets${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(eventTicketsResponse, await res.json()) };