mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 14:25:17 +00:00
Added Barcode(s) correctness check with backward and forward compatibility check;
Added constants in schema.js to keep all the schemas against which validate; Added schema for barcodes; Renamed "settingSchema" in "schema"; Renamed schemas "validate" function in "isValid"; Edited "isValid" fn to accept both the schema and the object; Added more error-catching conditions;
This commit is contained in:
61
schema.js
61
schema.js
@@ -1,39 +1,38 @@
|
||||
const Joi = require("joi");
|
||||
|
||||
const schema = Joi.object().keys({
|
||||
modelDir: Joi.string(),
|
||||
modelName: Joi.string(),
|
||||
certificates: Joi.object().keys({
|
||||
dir: Joi.string(),
|
||||
wwdr: Joi.string(),
|
||||
signerCert: Joi.string(),
|
||||
signerKey: Joi.object().keys({
|
||||
keyFile: Joi.string(),
|
||||
passphrase: Joi.string(),
|
||||
})
|
||||
const CONSTANTS = {
|
||||
instance: Joi.object().keys({
|
||||
modelDir: Joi.string().required(),
|
||||
modelName: Joi.string(),
|
||||
certificates: Joi.object().keys({
|
||||
dir: Joi.string().required(),
|
||||
wwdr: Joi.string().required(),
|
||||
signerCert: Joi.string().required(),
|
||||
signerKey: Joi.object().keys({
|
||||
keyFile: Joi.string().required(),
|
||||
passphrase: Joi.string().required(),
|
||||
}).required()
|
||||
}).required(),
|
||||
handlers: Joi.object().keys({
|
||||
barcode: Joi.func(),
|
||||
serialNumber: Joi.func()
|
||||
}),
|
||||
overrides: Joi.object()
|
||||
}),
|
||||
handlers: Joi.object().keys({
|
||||
barcode: Joi.func(),
|
||||
serialNumber: Joi.func()
|
||||
}),
|
||||
overrides: Joi.object()
|
||||
});
|
||||
|
||||
const requiredSchema = schema.requiredKeys(
|
||||
"",
|
||||
"modelDir",
|
||||
"certificates",
|
||||
"certificates.dir",
|
||||
"certificates.wwdr",
|
||||
"certificates.signerCert",
|
||||
"certificates.signerKey",
|
||||
"certificates.signerKey.keyFile",
|
||||
"certificates.signerKey.passphrase"
|
||||
);
|
||||
barcode: Joi.object().keys({
|
||||
altText: Joi.string(),
|
||||
messageEncoding: Joi.string(),
|
||||
format: Joi.string().required().regex(/(PKBarcodeFormatQR|PKBarcodeFormatPDF417|PKBarcodeFormatAztec|PKBarcodeFormatCode128)/, "barcodeType"),
|
||||
message: Joi.string().required()
|
||||
}),
|
||||
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validate: (opts) => {
|
||||
let validation = Joi.validate(opts, requiredSchema);
|
||||
CONSTANTS,
|
||||
isValid: (opts, schemaName) => {
|
||||
let validation = Joi.validate(opts, schemaName);
|
||||
return !validation.error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user