import {z} from 'zod' export type PydanticObjectId = string; export type PassSharingMethod = 'PKPassSharingMethodURL' | 'PKPassSharingMethodDisabled'; export type PassSharing = {method?: PassSharingMethod | undefined, url?: (string | null) | undefined, text?: (string | null) | undefined}; export type PassBeacon = {proximityUUID: string, major?: (number | null) | undefined, minor?: (number | null) | undefined, relevantText?: (string | null) | undefined}; export type PassLocation = {latitude?: number | undefined, longitude?: number | undefined, altitude?: number | undefined, distance?: (number | null) | undefined, relevantText?: (string | null) | undefined}; export type PassBarcodeFormat = 'PKBarcodeFormatPDF417' | 'PKBarcodeFormatQR' | 'PKBarcodeFormatAztec' | 'PKBarcodeFormatCode128'; export type PassBarcode = {format: PassBarcodeFormat, message: string, messageEncoding?: string | undefined, altText?: (string | null) | undefined, verifier?: (boolean | null) | undefined, disabled?: (boolean | null) | undefined}; export type PassTextAlignment = 'PKTextAlignmentLeft' | 'PKTextAlignmentCenter' | 'PKTextAlignmentRight' | 'PKTextAlignmentJustified' | 'PKTextAlignmentNatural'; export type PassDataDetectorType = 'PKDataDetectorTypePhoneNumber' | 'PKDataDetectorTypeLink' | 'PKDataDetectorTypeAddress' | 'PKDataDetectorTypeCalendarEvent'; export type PassDateStyle = 'PKDateStyleNone' | 'PKDateStyleShort' | 'PKDateStyleMedium' | 'PKDateStyleLong' | 'PKDateStyleFull'; export type PassNumberStyle = 'PKNumberStyleDecimal' | 'PKNumberStylePercent' | 'PKNumberStyleScientific' | 'PKNumberStyleSpellOut'; export type PassField = {key: string, label?: (string | null) | undefined, value: string | number | number | string, attributedValue?: (string | number | number | string | null) | undefined, changeMessage?: (string | null) | undefined, textAlignment?: (PassTextAlignment | null) | undefined, dataDetectorTypes?: (Array | null) | undefined, dateStyle?: (PassDateStyle | null) | undefined, timeStyle?: (PassDateStyle | null) | undefined, isRelative?: (boolean | null) | undefined, ignoresTimeZone?: (boolean | null) | undefined, numberStyle?: (PassNumberStyle | null) | undefined, currencyCode?: (string | null) | undefined, googleHideOnCard?: (boolean | null) | undefined, googleHideOnBack?: (boolean | null) | undefined, googleFieldType?: (string | null) | undefined, googleUri?: (string | null) | undefined, googleLabel?: (string | null) | undefined, googleValue?: (string | null) | undefined}; export type PassTransitType = 'PKTransitTypeAir' | 'PKTransitTypeTrain' | 'PKTransitTypeBus' | 'PKTransitTypeBoat' | 'PKTransitTypeGeneric'; export type PassInformation = {headerFields?: Array | undefined, primaryFields?: Array | undefined, secondaryFields?: Array | undefined, backFields?: Array | undefined, auxiliaryFields?: Array | undefined, transitType?: (PassTransitType | null) | undefined}; export type TemplatePass = {description?: (string | null) | undefined, suppressStripShine?: (boolean | null) | undefined, sharing?: (PassSharing | null) | undefined, appLaunchURL?: (string | null) | undefined, associatedApps?: Array<{[key: string]: unknown}> | undefined, associatedStoreIdentifiers?: Array | undefined, associatedPlayIdentifiers?: Array | undefined, beacons?: Array | undefined, locations?: Array | undefined, barcodes?: Array | undefined, barcode?: (PassBarcode | null) | undefined, labelColor?: (string | null) | undefined, backgroundColor?: (string | null) | undefined, foregroundColor?: (string | null) | undefined, logoText?: (string | null) | undefined, relevantDate?: (string | null) | undefined, expirationDate?: (string | null) | undefined, voided?: (boolean | null) | undefined, userInfo?: ({[key: string]: unknown} | null) | undefined, generic?: (PassInformation | null) | undefined, coupon?: (PassInformation | null) | undefined, storeCard?: (PassInformation | null) | undefined, eventTicket?: (PassInformation | null) | undefined, boardingPass?: (PassInformation | null) | undefined}; export type TemplatePlaceholderType = 'text' | 'email' | 'number' | 'date' | 'selection' | 'json'; export type TemplatePlaceholder = {name: string, type?: TemplatePlaceholderType | undefined, displayName?: (string | null) | undefined, defaultValue?: (string | null) | undefined, points?: (number | null) | undefined, options?: (string | null) | undefined, required?: (boolean | null) | undefined}; export type ImageObject = {key?: (string | null) | undefined, url?: (string | null) | undefined}; export type TemplateBranding = {titleText?: (string | null) | undefined, headerText?: (string | null) | undefined, bodyTextColor?: (string | null) | undefined, footerTextColor?: (string | null) | undefined, footerBackgroundColor?: (string | null) | undefined, footerImage?: (ImageObject | null) | undefined}; export type TemplatePaymentProvider = 'PayPalNVP' | 'Stripe' | 'PAYMILL'; export type TemplatePaymentSettings = {username?: (string | null) | undefined, password?: (string | null) | undefined, signature?: (string | null) | undefined, sandbox?: (boolean | null) | undefined, itemName?: (string | null) | undefined, publishableKey?: (string | null) | undefined, secretKey?: (string | null) | undefined, publicKey?: (string | null) | undefined, privateKey?: (string | null) | undefined}; export type TemplatePayment = {enabled?: (boolean | null) | undefined, price?: (number | null) | undefined, currency?: (string | null) | undefined, provider?: (TemplatePaymentProvider | null) | undefined, providerSettings?: (TemplatePaymentSettings | null) | undefined}; export type ReturningUserRestrictionType = 'user_decides' | 'show_existing' | 'create_new'; export type TemplateSharingMethod = 'pass' | 'url' | 'disabled'; export type TemplateRestrictions = {quantityRestriction?: (number | null) | undefined, redemptionRestriction?: (number | null) | undefined, passwordProtection?: (string | null) | undefined, sharingRestriction?: (boolean | null) | undefined, dateRestriction?: (string | null) | undefined, returningUserRestriction?: (ReturningUserRestrictionType | null) | undefined, passSharingMethod?: (TemplateSharingMethod | null) | undefined}; export type TemplateAction = {redeem?: (boolean | null) | undefined, reactivate?: (boolean | null) | undefined, updateFields?: Array | undefined}; export type TemplateTranslation = {baseLanguage?: string | undefined, strings?: {[key: string]: {[key: string]: string}} | undefined}; export type PassImageType = 'logo' | 'icon' | 'strip' | 'footer' | 'background' | 'thumbnail'; export type TemplateStripImageGenerator = 'stamp'; export type TemplateStripImage = {generator?: (TemplateStripImageGenerator | null) | undefined, placeholder?: (string | null) | undefined, stamps?: (number | null) | undefined, backgroundColor?: (string | null) | undefined, backgroundImage?: (ImageObject | null) | undefined, stampedColor?: (string | null) | undefined, stampedImage?: (ImageObject | null) | undefined, unstampedColor?: (string | null) | undefined, unstampedImage?: (ImageObject | null) | undefined}; export type UpdateTemplatePayload = {name: string, passType?: (string | null) | undefined, description?: (TemplatePass | null) | undefined, disablePush?: (boolean | null) | undefined, placeholders?: (Array | null) | undefined, branding?: (TemplateBranding | null) | undefined, payment?: (TemplatePayment | null) | undefined, restrictions?: (TemplateRestrictions | null) | undefined, actions?: (TemplateAction | null) | undefined, translations?: (TemplateTranslation | null) | undefined, allowPassImages?: (Array | null) | undefined, stripImage?: (TemplateStripImage | null) | undefined}; export type UpdateApiV2TemplatesTemplateIdArgs = {templateId: PydanticObjectId | string, authorization?: (string | null) | undefined, body: UpdateTemplatePayload}; export type UpdateApiV2TemplatesTemplateIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2TemplatesTemplateIdResponse = z.unknown(); 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 }; /** * Update Pass Template Information * * PUT /v2/templates/{templateId} */ export const updateApiV2TemplatesTemplateId = async (args: UpdateApiV2TemplatesTemplateIdArgs, options?: UpdateApiV2TemplatesTemplateIdOptions) => { const {baseUrl = "https://api.loyalty.dog", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.authorization != null) headers.set("authorization", String(args.authorization)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/templates/${encodeURIComponent(String(args.templateId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiV2TemplatesTemplateIdResponse, await res.json()) };