From 9f924bbdcdad4e8e6e95ff733e822234df4689ae Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Thu, 27 Jun 2019 22:39:52 +0200 Subject: [PATCH] Added support for pass.json properties to be inserted in _props --- src/pass.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/pass.ts b/src/pass.ts index b7611ba..dcbb5df 100644 --- a/src/pass.ts +++ b/src/pass.ts @@ -61,6 +61,13 @@ export class Pass implements PassIndexSignature { this.l10nBundles = options.model.l10nBundle; this.bundle = { ...options.model.bundle }; + try { + // getting pass.json + this.passCore = JSON.parse(this.bundle["pass.json"].toString("utf8")); + } catch (err) { + throw new Error(formatMessage("PASSFILE_VALIDATION_FAILED")); + } + // Parsing the options and extracting only the valid ones. const validOverrides = schema.getValidated(options.overrides || {}, "supportedOptions") as schema.OverridesSupportedOptions; @@ -68,15 +75,22 @@ export class Pass implements PassIndexSignature { throw new Error(formatMessage("OVV_KEYS_BADFORMAT")) } - if (Object.keys(validOverrides).length) { - this._props = { ...validOverrides }; - } + this._props = [ + "barcodes", "barcode", + "expirationDate", "voided", + "beacons", "locations", + "relevantDate", "nfc" + ].reduce((acc, current) => { + if (!this.passCore[current]) { + return acc; + } - try { - // getting pass.json - this.passCore = JSON.parse(this.bundle["pass.json"].toString("utf8")); - } catch (err) { - throw new Error(formatMessage("PASSFILE_VALIDATION_FAILED")); + acc[current] = this.passCore[current]; + return acc; + }, {}); + + if (Object.keys(validOverrides).length) { + this._props = { ...this._props, ...validOverrides }; } this.type = Object.keys(this.passCore)