mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Changed schema passing method to strings instead of constants;
Added schema name resolution function in schema.js and schemas list
This commit is contained in:
@@ -25,7 +25,7 @@ class FieldsContainer {
|
|||||||
fields = fields[0];
|
fields = fields[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
let validFields = fields.filter(f => typeof f === "object" && schema.isValid(f, schema.constants.field));
|
let validFields = fields.filter(f => typeof f === "object" && schema.isValid(f, "field"));
|
||||||
|
|
||||||
this.fields.push(...validFields);
|
this.fields.push(...validFields);
|
||||||
|
|
||||||
|
|||||||
17
index.js
17
index.js
@@ -239,7 +239,7 @@ class Pass {
|
|||||||
data = [data];
|
data = [data];
|
||||||
}
|
}
|
||||||
|
|
||||||
let valid = data.filter(d => schema.isValid(d, schema.constants[type+"Dict"]));
|
let valid = data.filter(d => schema.isValid(d, type+"Dict"));
|
||||||
this.props[type] = valid;
|
this.props[type] = valid;
|
||||||
|
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
@@ -302,10 +302,7 @@ class Pass {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// messageEncoding is required
|
return schema.isValid(b, "barcode");
|
||||||
// b.messageEncoding = b.messageEncoding || "iso-8859-1";
|
|
||||||
|
|
||||||
return schema.isValid(b, schema.constants.barcode);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.props["barcode"] = valid[0] || {};
|
this.props["barcode"] = valid[0] || {};
|
||||||
@@ -406,7 +403,7 @@ class Pass {
|
|||||||
data = data[0];
|
data = data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
let valid = data.filter(d => d instanceof Object && schema.isValid(d, schema.constants.nfcDict));
|
let valid = data.filter(d => d instanceof Object && schema.isValid(d, "nfcDict"));
|
||||||
|
|
||||||
this.props["nfc"] = valid;
|
this.props["nfc"] = valid;
|
||||||
|
|
||||||
@@ -435,7 +432,7 @@ class Pass {
|
|||||||
let type = passTypes[index];
|
let type = passTypes[index];
|
||||||
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
return schema.isValid(passFile[type], schema.constants.passDict);
|
return schema.isValid(passFile[type], "passDict");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -564,7 +561,7 @@ class Pass {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
_parseSettings(options) {
|
_parseSettings(options) {
|
||||||
if (!schema.isValid(options, schema.constants.instance)) {
|
if (!schema.isValid(options, "instance")) {
|
||||||
throw new Error(errors.REQS_NOT_MET);
|
throw new Error(errors.REQS_NOT_MET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,7 +571,7 @@ class Pass {
|
|||||||
|
|
||||||
this.model = path.resolve(options.model) + (!!options.model && !path.extname(options.model) ? ".pass" : "");
|
this.model = path.resolve(options.model) + (!!options.model && !path.extname(options.model) ? ".pass" : "");
|
||||||
|
|
||||||
const filteredOpts = schema.filter(options, schema.constants.supportedOptions);
|
const filteredOpts = schema.filter(options.overrides, "supportedOptions");
|
||||||
|
|
||||||
Object.assign(this.props, filteredOpts);
|
Object.assign(this.props, filteredOpts);
|
||||||
|
|
||||||
@@ -606,7 +603,7 @@ class Pass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set transitType(v) {
|
set transitType(v) {
|
||||||
if (schema.isValid(v, schema.constants.transitType)) {
|
if (schema.isValid(v, "transitType")) {
|
||||||
this._transitType = v;
|
this._transitType = v;
|
||||||
} else {
|
} else {
|
||||||
this._transitType = this._transitType || "";
|
this._transitType = this._transitType || "";
|
||||||
|
|||||||
38
schema.js
38
schema.js
@@ -2,7 +2,7 @@ const Joi = require("joi");
|
|||||||
const debug = require("debug")("Schema");
|
const debug = require("debug")("Schema");
|
||||||
|
|
||||||
let instance = Joi.object().keys({
|
let instance = Joi.object().keys({
|
||||||
model: Joi.string(),
|
model: Joi.string().required(),
|
||||||
certificates: Joi.object().keys({
|
certificates: Joi.object().keys({
|
||||||
wwdr: Joi.string().required(),
|
wwdr: Joi.string().required(),
|
||||||
signerCert: Joi.string().required(),
|
signerCert: Joi.string().required(),
|
||||||
@@ -94,8 +94,31 @@ let nfcDict = Joi.object().keys({
|
|||||||
encryptionPublicKey: Joi.string()
|
encryptionPublicKey: Joi.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let schemas = {
|
||||||
|
instance,
|
||||||
|
barcode,
|
||||||
|
field,
|
||||||
|
passDict,
|
||||||
|
beaconsDict,
|
||||||
|
locationsDict,
|
||||||
|
transitType,
|
||||||
|
nfcDict,
|
||||||
|
supportedOptions
|
||||||
|
};
|
||||||
|
|
||||||
|
let resolveSchemaName = (name) => {
|
||||||
|
return schemas[name] || "";
|
||||||
|
};
|
||||||
|
|
||||||
let isValid = (opts, schemaName) => {
|
let isValid = (opts, schemaName) => {
|
||||||
let validation = Joi.validate(opts, schemaName);
|
let resolvedSchema = resolveSchemaName(schemaName);
|
||||||
|
|
||||||
|
if (!resolvedSchema) {
|
||||||
|
debug(`validation failed due to missing or mispelled schema name`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let validation = Joi.validate(opts, resolvedSchema);
|
||||||
|
|
||||||
if (validation.error) {
|
if (validation.error) {
|
||||||
debug(`validation failed due to error: ${validation.error.message}`);
|
debug(`validation failed due to error: ${validation.error.message}`);
|
||||||
@@ -121,17 +144,6 @@ let filter = (opts, schemaName) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
constants: {
|
|
||||||
instance,
|
|
||||||
barcode,
|
|
||||||
field,
|
|
||||||
passDict,
|
|
||||||
beaconsDict,
|
|
||||||
locationsDict,
|
|
||||||
transitType,
|
|
||||||
nfcDict,
|
|
||||||
supportedOptions
|
|
||||||
},
|
|
||||||
isValid,
|
isValid,
|
||||||
filter
|
filter
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user