mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Fixed comments and links; Moved pass lower-level definition to index.js
This commit is contained in:
11
fields.js
11
fields.js
@@ -1,8 +1,8 @@
|
|||||||
const schema = require("./schema");
|
const schema = require("./schema");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass fields area to be used as pass lower level keys
|
* Class to represent lower-level keys pass fields
|
||||||
* @see https://apple.co/2wkUBd
|
* @see https://apple.co/2wkUBdh
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FieldsContainer {
|
class FieldsContainer {
|
||||||
@@ -17,7 +17,7 @@ class FieldsContainer {
|
|||||||
*
|
*
|
||||||
* @method push
|
* @method push
|
||||||
* @params {Object[]} fields - the fields to be checked and pushed
|
* @params {Object[]} fields - the fields to be checked and pushed
|
||||||
* @params {schema.constants.field} fields[].* - each key must be compliant with schema.constants.field structure
|
* @params {schema.field} fields[].* - each key must be compliant with schema.field structure
|
||||||
* @returns {Number} - the amount of pushed elements (for checks)
|
* @returns {Number} - the amount of pushed elements (for checks)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -68,7 +68,4 @@ class FieldsContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = FieldsContainer;
|
||||||
areas: ["primaryFields", "secondaryFields", "auxiliaryFields", "backFields", "headerFields"],
|
|
||||||
FieldsContainer
|
|
||||||
};
|
|
||||||
|
|||||||
24
index.js
24
index.js
@@ -9,8 +9,8 @@ const barcodeDebug = require("debug")("passkit:barcode");
|
|||||||
const genericDebug = require("debug")("passkit:generic");
|
const genericDebug = require("debug")("passkit:generic");
|
||||||
|
|
||||||
const schema = require("./schema");
|
const schema = require("./schema");
|
||||||
const { areas: fieldsName, FieldsContainer } = require("./fields");
|
|
||||||
const errors = require("./messages");
|
const errors = require("./messages");
|
||||||
|
const FieldsContainer = require("./fields");
|
||||||
|
|
||||||
const readdir = util.promisify(fs.readdir);
|
const readdir = util.promisify(fs.readdir);
|
||||||
const readFile = util.promisify(fs.readFile);
|
const readFile = util.promisify(fs.readFile);
|
||||||
@@ -24,7 +24,9 @@ class Pass {
|
|||||||
this._props = {};
|
this._props = {};
|
||||||
this.shouldOverwrite = !(this.options.hasOwnProperty("shouldOverwrite") && !this.options.shouldOverwrite);
|
this.shouldOverwrite = !(this.options.hasOwnProperty("shouldOverwrite") && !this.options.shouldOverwrite);
|
||||||
|
|
||||||
fieldsName.forEach(a => this[a] = new FieldsContainer());
|
this._fields = ["primaryFields", "secondaryFields", "auxiliaryFields", "backFields", "headerFields"];
|
||||||
|
|
||||||
|
this._fields.forEach(a => this[a] = new FieldsContainer());
|
||||||
this._transitType = "";
|
this._transitType = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ class Pass {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
// May have not used this catch but ENOENT error is not enough self-explanatory in the case of external usage
|
// May have not used this catch but ENOENT error is not enough self-explanatory in the case of external usage
|
||||||
if (err.code && err.code === "ENOENT") {
|
if (err.code && err.code === "ENOENT") {
|
||||||
throw new Error(errors.MODEL_NOT_FOUND.replace("%s", (this.model ? this.model+" " : "")));
|
throw new Error(errors.MODEL_NOT_FOUND.replace("%s", (this.model ? this.model + " " : "")));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
@@ -227,12 +229,12 @@ class Pass {
|
|||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "beacons" || type === "locations") {
|
if (type === "beacons" || type === "locations") {
|
||||||
if (!(data instanceof Array)) {
|
if (!(data instanceof Array)) {
|
||||||
data = [data];
|
data = [data];
|
||||||
}
|
}
|
||||||
|
|
||||||
let valid = data.filter(d => schema.isValid(d, type+"Dict"));
|
let valid = data.filter(d => schema.isValid(d, type + "Dict"));
|
||||||
|
|
||||||
this._props[type] = valid.length ? valid : undefined;
|
this._props[type] = valid.length ? valid : undefined;
|
||||||
|
|
||||||
@@ -281,8 +283,8 @@ class Pass {
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
length: 0,
|
length: 0,
|
||||||
autocomplete: () => {},
|
autocomplete: () => { },
|
||||||
backward: () => {}
|
backward: () => { }
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +296,7 @@ class Pass {
|
|||||||
|
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
length: 4,
|
length: 4,
|
||||||
autocomplete: () => {},
|
autocomplete: () => { },
|
||||||
backward: this.__barcodeChooseBackward.bind(this)
|
backward: this.__barcodeChooseBackward.bind(this)
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
@@ -553,7 +555,7 @@ class Pass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldsName.forEach(area => {
|
this._fields.forEach(area => {
|
||||||
if (this[area].fields.length) {
|
if (this[area].fields.length) {
|
||||||
if (this.shouldOverwrite) {
|
if (this.shouldOverwrite) {
|
||||||
passFile[this.type][area] = this[area].fields;
|
passFile[this.type][area] = this[area].fields;
|
||||||
@@ -652,7 +654,7 @@ class Pass {
|
|||||||
function parsePEM(element, passphrase) {
|
function parsePEM(element, passphrase) {
|
||||||
if (element.includes("PRIVATE KEY") && passphrase) {
|
if (element.includes("PRIVATE KEY") && passphrase) {
|
||||||
return forge.pki.decryptRsaPrivateKey(element, String(passphrase));
|
return forge.pki.decryptRsaPrivateKey(element, String(passphrase));
|
||||||
} else if (element.includes("CERTIFICATE")) {
|
} else if (element.includes("CERTIFICATE")) {
|
||||||
return forge.pki.certificateFromPem(element);
|
return forge.pki.certificateFromPem(element);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@@ -678,7 +680,7 @@ function isValidRGB(value) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rgb.slice(1,4).every(v => Math.abs(Number(v)) <= 255);
|
return rgb.slice(1, 4).every(v => Math.abs(Number(v)) <= 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user