mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 21:25:26 +00:00
Changed _validateType to validate also the schema;
Edited schemas to comply with boardingPass requirements and the others pass types
This commit is contained in:
8
index.js
8
index.js
@@ -208,8 +208,14 @@ class Pass {
|
|||||||
_validateType(passBuffer) {
|
_validateType(passBuffer) {
|
||||||
try {
|
try {
|
||||||
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
||||||
|
let index = this.passTypes.findIndex(passType => passFile.hasOwnProperty(passType));
|
||||||
|
|
||||||
return this.passTypes.some(passType => passFile.hasOwnProperty(passType));
|
if (index == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let type = this.passTypes[index];
|
||||||
|
return schema.isValid(passFile[type], schema.constants[(type === "boardingPass" ? "boarding" : "basic") + "Structure"]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
24
schema.js
24
schema.js
@@ -28,26 +28,36 @@ let field = Joi.object().keys({
|
|||||||
textAlignment: Joi.string().regex(/(PKTextAlignmentLeft|PKTextAlignmentCenter|PKTextAlignmentRight|PKTextAlignmentNatural)/, "graphic-alignment"),
|
textAlignment: Joi.string().regex(/(PKTextAlignmentLeft|PKTextAlignmentCenter|PKTextAlignmentRight|PKTextAlignmentNatural)/, "graphic-alignment"),
|
||||||
key: Joi.string().required(),
|
key: Joi.string().required(),
|
||||||
value: Joi.string().required()
|
value: Joi.string().required()
|
||||||
})
|
});
|
||||||
|
|
||||||
let structure = Joi.object().keys({
|
let struct = {
|
||||||
auxiliaryFields: Joi.array().items(field),
|
auxiliaryFields: Joi.array().items(field),
|
||||||
backFields: Joi.array().items(field),
|
backFields: Joi.array().items(field),
|
||||||
headerFields: Joi.array().items(field),
|
headerFields: Joi.array().items(field),
|
||||||
primaryFields: Joi.array().items(field),
|
primaryFields: Joi.array().items(field),
|
||||||
secondaryFields: Joi.array().items(field),
|
secondaryFields: Joi.array().items(field)
|
||||||
transitType: Joi.string().regex(/(PKTransitTypeAir|PKTransitTypeBoat|PKTransitTypeBus|PKTransitTypeGeneric|PKTransitTypeTrain)/)
|
};
|
||||||
});
|
|
||||||
|
let basicStructure = Joi.object().keys(struct);
|
||||||
|
let boardingStructure = Joi.object().keys(Object.assign({
|
||||||
|
transitType: Joi.string().regex(/(PKTransitTypeAir|PKTransitTypeBoat|PKTransitTypeBus|PKTransitTypeGeneric|PKTransitTypeTrain)/).required()
|
||||||
|
}, struct));
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
constants: {
|
constants: {
|
||||||
instance,
|
instance,
|
||||||
barcode,
|
barcode,
|
||||||
field,
|
field,
|
||||||
structure
|
basicStructure,
|
||||||
|
boardingStructure
|
||||||
},
|
},
|
||||||
isValid: (opts, schemaName) => {
|
isValid: (opts, schemaName, debug = false) => {
|
||||||
let validation = Joi.validate(opts, schemaName);
|
let validation = Joi.validate(opts, schemaName);
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
console.log(validation)
|
||||||
|
}
|
||||||
|
|
||||||
return !validation.error;
|
return !validation.error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user