import {z} from 'zod' export type GetApiOcapiV1SitesSiteIdThirdPartyMemberSchemesArgs = {siteId: string, 'Connect-Region-Code'?: string | undefined}; export type GetApiOcapiV1SitesSiteIdThirdPartyMemberSchemesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const ocapiV1Translation = z.object({languageTag: z.string().min(1), text: z.string().min(1)}); export const ocapiV1Translatable = z.object({text: z.string().min(1), translations: z.array(ocapiV1Translation)}); export const ocapiV1SalesMasterDataThirdPartyMemberTicketSchemesThirdPartyMemberSchemeCardNumberFormat = z.object({partialFormat: z.string().nullable().optional(), fullFormat: z.string().nullable().optional(), prefixLength: z.number().int().optional()}); export const ocapiV1Quantity = z.object({isUnlimited: z.boolean(), value: z.number().int().nullable().optional()}); export const ocapiV1SalesMasterDataThirdPartyMemberTicketSchemesThirdPartyMemberScheme = z.object({id: z.string().min(1), name: ocapiV1Translatable, cardNumberFormat: ocapiV1SalesMasterDataThirdPartyMemberTicketSchemesThirdPartyMemberSchemeCardNumberFormat, seatLimitPerCard: ocapiV1Quantity}); export const ocapiV1SalesMasterDataThirdPartyMemberTicketSchemesThirdPartyMemberSchemeListDetails = z.object({thirdPartyMemberSchemes: z.array(ocapiV1SalesMasterDataThirdPartyMemberTicketSchemesThirdPartyMemberScheme)}); 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 }; /** * Gets the list of third party member scheme entities for a specified site * * GET /ocapi/v1/sites/{siteId}/third-party-member-schemes */ export const getApiOcapiV1SitesSiteIdThirdPartyMemberSchemes = async (args: GetApiOcapiV1SitesSiteIdThirdPartyMemberSchemesArgs, options: GetApiOcapiV1SitesSiteIdThirdPartyMemberSchemesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Connect-Region-Code'] != null) headers.set("Connect-Region-Code", String(args['Connect-Region-Code'])) const url = `${baseUrl.replace(/\/+$/, '')}/ocapi/v1/sites/${encodeURIComponent(String(args.siteId))}/third-party-member-schemes${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(ocapiV1SalesMasterDataThirdPartyMemberTicketSchemesThirdPartyMemberSchemeListDetails, await res.json()) };