diff --git a/src/PKPass.ts b/src/PKPass.ts index 462fbf9..4f0d53c 100644 --- a/src/PKPass.ts +++ b/src/PKPass.ts @@ -316,6 +316,44 @@ export default class PKPass extends Bundle { return this[propsSymbol][this.type].backFields; } + /** + * Allows accessing to iOS 18 new Event Ticket + * property `preferredStyleSchemes`. + * + * @throws (automatically) if current type is not + * "eventTicket". + */ + + public get preferredStyleSchemes(): Schemas.PreferredStyleSchemes { + return this[propsSymbol]["eventTicket"].preferredStyleSchemes; + } + + /** + * Allows setting a preferredStyleSchemes property + * for a eventTicket. + * + * @throws if current type is not "eventTicket". + * @param value + */ + + public set preferredStyleSchemes(value: Schemas.PreferredStyleSchemes) { + Utils.assertUnfrozen(this); + + if (this.type !== "eventTicket") { + throw new TypeError( + Messages.PREFERRED_STYLE_SCHEMES.UNEXPECTED_PASS_TYPE, + ); + } + + Schemas.assertValidity( + Schemas.PreferredStyleSchemes, + value, + Messages.PREFERRED_STYLE_SCHEMES.INVALID, + ); + + this[propsSymbol]["eventTicket"].preferredStyleSchemes = value; + } + /** * Allows setting a pass type. * diff --git a/src/messages.ts b/src/messages.ts index dd8ca5d..3e48e6c 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -15,6 +15,13 @@ export const TRANSIT_TYPE = { "Cannot set transitType because not compliant with Apple specifications. Refer to https://apple.co/3DHuAG4 for more - %s", } as const; +export const PREFERRED_STYLE_SCHEMES = { + UNEXPECTED_PASS_TYPE: + "Cannot set preferredStyleSchemes on a pass with type different from eventTicket.", + INVALID: + "Cannot set preferredStyleSchemes because not compliant with Apple specifications - %s", +} as const; + export const PASS_TYPE = { INVALID: "Cannot set type because not compliant with Apple specifications. Refer to https://apple.co/3aFpSfg for a list of valid props - %s", diff --git a/src/schemas/PassFields.ts b/src/schemas/PassFields.ts index 41eef7d..58c3b1e 100644 --- a/src/schemas/PassFields.ts +++ b/src/schemas/PassFields.ts @@ -12,6 +12,13 @@ export const TransitType = Joi.string().regex( /(PKTransitTypeAir|PKTransitTypeBoat|PKTransitTypeBus|PKTransitTypeGeneric|PKTransitTypeTrain)/, ); +export type PreferredStyleSchemes = ("posterEventTicket" | "eventTicket")[]; + +export const PreferredStyleSchemes = Joi.array().items( + "posterEventTicket", + "eventTicket", +) satisfies Joi.Schema; + export interface PassFields { auxiliaryFields: FieldWithRow[]; backFields: Field[]; diff --git a/src/schemas/index.ts b/src/schemas/index.ts index fa85c2e..3fe25b7 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -15,7 +15,7 @@ import { Barcode } from "./Barcode"; import { Location } from "./Location"; import { Beacon } from "./Beacon"; import { NFC } from "./NFC"; -import { PassFields, TransitType } from "./PassFields"; +import { PassFields, PreferredStyleSchemes, TransitType } from "./PassFields"; import { Semantics } from "./Semantics"; import { CertificatesSchema } from "./Certificates"; @@ -75,7 +75,7 @@ export interface PassProps { * so on, are not necessary anymore for the new style, * as semantics are preferred. */ - preferredStyleSchemes?: ("posterEventTicket" | "eventTicket")[]; + preferredStyleSchemes?: PreferredStyleSchemes; }; coupon?: PassFields; generic?: PassFields; @@ -158,9 +158,7 @@ export const PassKindsProps = Joi.object({ * so on, are not necessary anymore for the new style, * as semantics are preferred. */ - preferredStyleSchemes: Joi.array().items( - Joi.string().allow("posterEventTicket", "eventTicket"), - ), + preferredStyleSchemes: PreferredStyleSchemes, }), ), boardingPass: PassFields, @@ -240,7 +238,7 @@ export const Template = Joi.object