mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 14:25:17 +00:00
Added a new setter and getter for preferredStyleSchemes to throw if type is not an eventTicket and moved PreferredStyleSchemes schemas
This commit is contained in:
@@ -316,6 +316,44 @@ export default class PKPass extends Bundle {
|
|||||||
return this[propsSymbol][this.type].backFields;
|
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.
|
* Allows setting a pass type.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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",
|
"Cannot set transitType because not compliant with Apple specifications. Refer to https://apple.co/3DHuAG4 for more - %s",
|
||||||
} as const;
|
} 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 = {
|
export const PASS_TYPE = {
|
||||||
INVALID:
|
INVALID:
|
||||||
"Cannot set type because not compliant with Apple specifications. Refer to https://apple.co/3aFpSfg for a list of valid props - %s",
|
"Cannot set type because not compliant with Apple specifications. Refer to https://apple.co/3aFpSfg for a list of valid props - %s",
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ export const TransitType = Joi.string().regex(
|
|||||||
/(PKTransitTypeAir|PKTransitTypeBoat|PKTransitTypeBus|PKTransitTypeGeneric|PKTransitTypeTrain)/,
|
/(PKTransitTypeAir|PKTransitTypeBoat|PKTransitTypeBus|PKTransitTypeGeneric|PKTransitTypeTrain)/,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export type PreferredStyleSchemes = ("posterEventTicket" | "eventTicket")[];
|
||||||
|
|
||||||
|
export const PreferredStyleSchemes = Joi.array().items(
|
||||||
|
"posterEventTicket",
|
||||||
|
"eventTicket",
|
||||||
|
) satisfies Joi.Schema<PreferredStyleSchemes>;
|
||||||
|
|
||||||
export interface PassFields {
|
export interface PassFields {
|
||||||
auxiliaryFields: FieldWithRow[];
|
auxiliaryFields: FieldWithRow[];
|
||||||
backFields: Field[];
|
backFields: Field[];
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { Barcode } from "./Barcode";
|
|||||||
import { Location } from "./Location";
|
import { Location } from "./Location";
|
||||||
import { Beacon } from "./Beacon";
|
import { Beacon } from "./Beacon";
|
||||||
import { NFC } from "./NFC";
|
import { NFC } from "./NFC";
|
||||||
import { PassFields, TransitType } from "./PassFields";
|
import { PassFields, PreferredStyleSchemes, TransitType } from "./PassFields";
|
||||||
import { Semantics } from "./Semantics";
|
import { Semantics } from "./Semantics";
|
||||||
import { CertificatesSchema } from "./Certificates";
|
import { CertificatesSchema } from "./Certificates";
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ export interface PassProps {
|
|||||||
* so on, are not necessary anymore for the new style,
|
* so on, are not necessary anymore for the new style,
|
||||||
* as semantics are preferred.
|
* as semantics are preferred.
|
||||||
*/
|
*/
|
||||||
preferredStyleSchemes?: ("posterEventTicket" | "eventTicket")[];
|
preferredStyleSchemes?: PreferredStyleSchemes;
|
||||||
};
|
};
|
||||||
coupon?: PassFields;
|
coupon?: PassFields;
|
||||||
generic?: PassFields;
|
generic?: PassFields;
|
||||||
@@ -158,9 +158,7 @@ export const PassKindsProps = Joi.object<PassKindsProps>({
|
|||||||
* so on, are not necessary anymore for the new style,
|
* so on, are not necessary anymore for the new style,
|
||||||
* as semantics are preferred.
|
* as semantics are preferred.
|
||||||
*/
|
*/
|
||||||
preferredStyleSchemes: Joi.array().items(
|
preferredStyleSchemes: PreferredStyleSchemes,
|
||||||
Joi.string().allow("posterEventTicket", "eventTicket"),
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
boardingPass: PassFields,
|
boardingPass: PassFields,
|
||||||
@@ -240,7 +238,7 @@ export const Template = Joi.object<Template>({
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function assertValidity<T>(
|
export function assertValidity<T>(
|
||||||
schema: Joi.ObjectSchema<T> | Joi.StringSchema,
|
schema: Joi.ObjectSchema<T> | Joi.StringSchema | Joi.Schema<T>,
|
||||||
data: T,
|
data: T,
|
||||||
customErrorMessage?: string,
|
customErrorMessage?: string,
|
||||||
): void {
|
): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user