From 1e0b08af6a4b150e3e48e4d6747d015a94909ad1 Mon Sep 17 00:00:00 2001 From: alexandercerutti Date: Sat, 18 Aug 2018 16:31:20 +0200 Subject: [PATCH] Introduced support to primaryFields, secondaryFields, etc. --- index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5ca9482..d01850c 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,8 @@ const forge = require("node-forge"); const archiver = require("archiver"); const async = require("async"); const stream = require("stream"); -const schema = require("./schema.js"); +const schema = require("./schema"); +const fields = require("./fields"); const util = require("util"); @@ -18,6 +19,8 @@ class Pass { this.Certificates = {}; this.model = ""; this.l10n = {}; + + fields.areas.forEach(a => this[a] = new fields.FieldsArea()); } /** @@ -173,6 +176,8 @@ class Pass { } let type = passTypes[index]; + + this.type = type; return schema.isValid(passFile[type], schema.constants[(type === "boardingPass" ? "boarding" : "basic") + "Structure"]); } catch (e) { return false; @@ -296,6 +301,12 @@ class Pass { Object.assign(passFile, options); + fields.areas.forEach(area => { + if (this[area].fields.length) { + passFile[this.type][area].push(...this[area].fields); + } + }); + return Promise.resolve(Buffer.from(JSON.stringify(passFile))); }