passkit-generator
Advanced tools
Comparing version 1.6.4 to 1.6.5
@@ -7,2 +7,20 @@ # Changelog | ||
___ | ||
## 1.6.5 | ||
[ [#f29203149](/commit/f2920314947e8e45f00bcfb83be676261950d37a) ] | ||
Added support for logoText in supportedOptions (issues #21, #28) | ||
[ [#6451a3c37](/commit/6451a3c37866cbdd88b275a4bc3fdff46c3bd3c7) ] | ||
Fixed nfc methods which was accepting and registering an array instead of an object | ||
[ [#4ce889d65](/commit/4ce889d6558678f01a993dcbd3e60b568e787638) ] | ||
Adding support for native Dates (#32) | ||
[ [#0e46d855e](/commit/0e46d855e43c2fd736aee0e43c5c993fbc41a0b9) ] | ||
Fixing passes parallel generation (#31) | ||
___ | ||
## 1.6.4 | ||
@@ -9,0 +27,0 @@ |
{ | ||
"name": "passkit-generator", | ||
"version": "1.6.4", | ||
"version": "1.6.5", | ||
"description": "The easiest way to generate custom Apple Wallet passes in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -94,2 +94,10 @@ const Passkit = require(".."); | ||
it("A date as a Date object will apply changes", () => { | ||
pass.expiration(new Date(2020,5,1,0,0,0)); | ||
// this is made to avoid problems with winter and summer time: | ||
// we focus only on the date and time for the tests. | ||
let noTimeZoneDateTime = pass._props["expirationDate"].split("+")[0]; | ||
expect(noTimeZoneDateTime).toBe("2020-06-01T00:00:00"); | ||
}); | ||
it("An invalid date, will not apply changes", () => { | ||
@@ -129,2 +137,10 @@ pass.expiration("32/18/228317"); | ||
}); | ||
it("A date as a Date object will apply changes", () => { | ||
pass.relevance("relevantDate",new Date(2020,5,1,0,0,0)); | ||
// this is made to avoid problems with winter and summer time: | ||
// we focus only on the date and time for the tests. | ||
let noTimeZoneDateTime = pass._props["relevantDate"].split("+")[0]; | ||
expect(noTimeZoneDateTime).toBe("2020-06-01T00:00:00"); | ||
}); | ||
}); | ||
@@ -131,0 +147,0 @@ |
@@ -5,9 +5,2 @@ const schema = require("./schema"); | ||
/** | ||
* Pass fields must be unique (for key) in its scope. | ||
* Therefore we use a Set to keep them tracked. | ||
*/ | ||
const fieldsKeys = new Set(); | ||
/** | ||
* Class to represent lower-level keys pass fields | ||
@@ -17,5 +10,9 @@ * @see https://apple.co/2wkUBdh | ||
const poolSymbol = Symbol("pool"); | ||
class FieldsArray extends Array { | ||
constructor(...items) { | ||
super(...items); | ||
constructor(pool,...args) { | ||
super(...args); | ||
this[poolSymbol] = pool; | ||
} | ||
@@ -34,9 +31,9 @@ | ||
if (acc.some(e => e.key === current.key) || fieldsKeys.has(current.key)) { | ||
debug(`Field with key "${current.key}" discarded: fields must be unique in pass scope.`); | ||
} else { | ||
fieldsKeys.add(current.key); | ||
acc.push(current); | ||
} | ||
if (acc.some(e => e.key === current.key) || this[poolSymbol].has(current.key)) { | ||
debug(`Field with key "${key}" discarded: fields must be unique in pass scope.`); | ||
} | ||
this[poolSymbol].add(current.key) | ||
acc.push(current) | ||
return acc; | ||
@@ -54,4 +51,4 @@ }, []); | ||
pop() { | ||
const element = Array.prototype.pop.call(this); | ||
fieldsKeys.delete(element.key); | ||
const element = Array.prototype.pop.call(this); | ||
this[poolSymbol].delete(element.key) | ||
return element; | ||
@@ -67,3 +64,3 @@ } | ||
const removeList = this.slice(start, deleteCount+start); | ||
removeList.forEach(item => fieldsKeys.delete(item.key)); | ||
removeList.forEach(item => this[poolSymbol].delete(item.key)); | ||
@@ -76,8 +73,4 @@ return Array.prototype.splice.call(this, start, deleteCount, items); | ||
} | ||
static emptyUnique() { | ||
fieldsKeys.clear(); | ||
} | ||
} | ||
module.exports = FieldsArray; |
@@ -47,3 +47,8 @@ const fs = require("fs"); | ||
this._fields.forEach(a => this[a] = new FieldsArray()); | ||
this.fieldsKeys = new Set(); | ||
this._fields.forEach(name => { | ||
this[name] = new FieldsArray(this.fieldsKeys); | ||
}); | ||
this[transitType] = ""; | ||
@@ -217,4 +222,2 @@ | ||
FieldsArray.emptyUnique(); | ||
return archive.finalize().then(() => passStream); | ||
@@ -261,3 +264,3 @@ } catch (err) { | ||
expiration(date, format) { | ||
if (typeof date !== "string") { | ||
if (typeof date !== "string" && !(date instanceof Date)) { | ||
return this; | ||
@@ -330,2 +333,7 @@ } | ||
} else if (type === "relevantDate") { | ||
if (typeof data !== "string" && !(data instanceof Date)) { | ||
genericDebug(formatMessage("DATE_FORMAT_UNMATCH", "Relevant Date")); | ||
return this; | ||
} | ||
let dateParse = dateToW3CString(data, relevanceDateFormat); | ||
@@ -490,17 +498,14 @@ | ||
* @method nfc | ||
* @params {Array<Object>} data - the data to be pushed in the pass | ||
* @params {Object} data - the data to be pushed in the pass | ||
* @returns {this} | ||
*/ | ||
nfc(...data) { | ||
if (data.length === 1 && data[0] instanceof Array) { | ||
data = data[0]; | ||
nfc(data) { | ||
if (!(typeof data === "object" && !Array.isArray(data) && schema.isValid(data, "nfcDict"))) { | ||
genericDebug("Invalid NFC data provided"); | ||
return this; | ||
} | ||
let valid = data.filter(d => d instanceof Object && schema.isValid(d, "nfcDict")); | ||
this._props["nfc"] = data; | ||
if (valid.length) { | ||
this._props["nfc"] = valid; | ||
} | ||
return this; | ||
@@ -507,0 +512,0 @@ } |
@@ -30,3 +30,4 @@ const Joi = require("joi"); | ||
groupingIdentifier: Joi.string(), | ||
suppressStripShine: Joi.boolean() | ||
suppressStripShine: Joi.boolean(), | ||
logoText: Joi.string(), | ||
}).with("webServiceURL", "authenticationToken"); | ||
@@ -33,0 +34,0 @@ |
@@ -37,7 +37,7 @@ const moment = require("moment"); | ||
function dateToW3CString(date, format) { | ||
if (typeof date !== "string") { | ||
if (typeof date !== "string" && !(date instanceof Date)) { | ||
return ""; | ||
} | ||
const parsedDate = moment(date.replace(/\//g, "-"), format || ["MM-DD-YYYY hh:mm:ss", "DD-MM-YYYY hh:mm:ss"]).format(); | ||
const parsedDate = date instanceof Date ? moment(date).format() : moment(date.replace(/\//g, "-"), format || ["MM-DD-YYYY hh:mm:ss", "DD-MM-YYYY hh:mm:ss"]).format(); | ||
@@ -44,0 +44,0 @@ if (parsedDate === "Invalid date") { |
112697
1564
16