From 2444d52cb2d0a7ffbbc451af935234cf74b7f69b Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 27 Jul 2019 00:40:54 +0200 Subject: [PATCH] Added personalization messages and schemas --- src/messages.ts | 6 ++++-- src/schema.ts | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/messages.ts b/src/messages.ts index e05d175..7b9ee75 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -8,7 +8,7 @@ const errors: MessageGroup = { CP_NO_CERTS: "Cannot initialize the pass creation: no valid certificates were passed.", PASSFILE_VALIDATION_FAILED: "Validation of pass type failed. Pass file is not a valid buffer or (more probably) does not respect the schema.\nRefer to https://apple.co/2Nvshvn to build a correct pass.", REQUIR_VALID_FAILED: "The options passed to Pass constructor does not meet the requirements.\nRefer to the documentation to compile them correctly.", - MODEL_UNINITIALIZED: "Provided model ( %s ) matched but unitialized or may not contain icon.\nRefer to https://apple.co/2IhJr0Q, https://apple.co/2Nvshvn and documentation to fill the model correctly.", + MODEL_UNINITIALIZED: "Provided model ( %s ) matched but unitialized or may not contain icon or a valid pass.json.\nRefer to https://apple.co/2IhJr0Q, https://apple.co/2Nvshvn and documentation to fill the model correctly.", MODEL_NOT_VALID: "A model must be provided in form of path (string) or object { 'fileName': Buffer } in order to continue.", MODELF_NOT_FOUND: "Model %s not found. Provide a valid one to continue.", MODELF_FILE_NOT_FOUND: "File %s not found.", @@ -27,7 +27,9 @@ const debugMessages: MessageGroup = { BRC_BW_FORMAT_UNSUPPORTED: "This format is not supported (by Apple) for backward support. Please choose another one.", BRC_NO_POOL: "Cannot set barcode: no barcodes found. Please set barcodes first. Barcode is for retrocompatibility only.", DATE_FORMAT_UNMATCH: "%s was not set due to incorrect date format.", - NFC_INVALID: "Unable to set NFC properties: data not compliant with schema." + NFC_INVALID: "Unable to set NFC properties: data not compliant with schema.", + PRS_INVALID: "Unable to parse Personalization.json. File is not a valid JSON. Error: %s", + PRS_REMOVED: "Personalization has been removed as it requires an NFC-enabled pass to work." }; /** diff --git a/src/schema.ts b/src/schema.ts index fd1d6a1..d8ec67d 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -418,6 +418,26 @@ const nfcDict = Joi.object().keys({ encryptionPublicKey: Joi.string() }); +// ************************************* // +// *** Personalizable Passes Schemas *** // +// ************************************* // + +export interface Personalization { + requiredPersonalizationFields: PRSField[]; + description: string; + termsAndConditions?: string; +} + +type PRSField = "PKPassPersonalizationFieldName" | "PKPassPersonalizationFieldPostalCode" | "PKPassPersonalizationFieldEmailAddress" | "PKPassPersonalizationFieldPhoneNumber"; + +const personalizationDict = Joi.object().keys({ + requiredPersonalizationFields: Joi.array() + .items("PKPassPersonalizationFieldName", "PKPassPersonalizationFieldPostalCode", "PKPassPersonalizationFieldEmailAddress", "PKPassPersonalizationFieldPhoneNumber") + .required(), + description: Joi.string().required(), + termsAndConditions: Joi.string(), +}); + // --------- UTILITIES ---------- // type Schemas = { @@ -433,7 +453,8 @@ const schemas: Schemas = { locationsDict, transitType, nfcDict, - supportedOptions + supportedOptions, + personalizationDict }; function resolveSchemaName(name: keyof Schemas) {