@zaiusinc/app-forms-schema
Advanced tools
Comparing version
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -0,1 +1,2 @@ | ||
import Ajv from 'ajv'; | ||
import { AnyElement, Schema } from '../index'; | ||
@@ -5,3 +6,3 @@ import { Section } from '../Section'; | ||
export declare function validateFormDefinition(form: Schema.Form): Promise<string[]>; | ||
export declare function validateSection(section: Section | ZedSection, path: string, ajv: any): Promise<string[]>; | ||
export declare function validateElementDefinition(element: AnyElement, path: string, ajv: any): Promise<string[]>; | ||
export declare function validateSection(section: Section | ZedSection, path: string, ajv: Ajv): Promise<string[]>; | ||
export declare function validateElementDefinition(element: AnyElement, path: string, ajv: Ajv): Promise<string[]>; |
@@ -65,5 +65,10 @@ "use strict"; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -84,3 +89,3 @@ var __values = (this && this.__values) || function(o) { | ||
exports.validateElementDefinition = exports.validateSection = exports.validateFormDefinition = void 0; | ||
var Ajv = require("ajv"); | ||
var ajv_1 = require("ajv"); | ||
var index_1 = require("../index"); | ||
@@ -91,27 +96,29 @@ var formSchema = require("../schema/Form.schema.json"); | ||
function validateFormDefinition(form) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var errors, ajv, i, section, _a, _b, _c, j, element, _d, _e, _f, dataKeys_1, unvalidatedDataRefs_2, unvalidatedDataRefs_1, unvalidatedDataRefs_1_1, ref; | ||
var e_1, _g; | ||
return __generator(this, function (_h) { | ||
switch (_h.label) { | ||
var errors, ajv, i, section, _b, _c, _d, _e, j, element, _f, _g, _h, _j, dataKeys_1, unvalidatedDataRefs_2, unvalidatedDataRefs_1, unvalidatedDataRefs_1_1, ref; | ||
var e_1, _k; | ||
return __generator(this, function (_l) { | ||
switch (_l.label) { | ||
case 0: | ||
errors = []; | ||
ajv = new Ajv({ allErrors: true }); | ||
ajv = new ajv_1.default({ allErrors: true }); | ||
if (!ajv.validate(formRootSchema, form)) { | ||
ajv.errors.forEach(function (e) { return errors.push(formatAjvError(e)); }); | ||
((_a = ajv.errors) !== null && _a !== void 0 ? _a : []).forEach(function (e) { return errors.push(formatAjvError(e)); }); | ||
} | ||
if (!Array.isArray(form.sections)) return [3 /*break*/, 7]; | ||
i = 0; | ||
_h.label = 1; | ||
_l.label = 1; | ||
case 1: | ||
if (!(i < form.sections.length)) return [3 /*break*/, 7]; | ||
section = form.sections[i]; | ||
_b = (_a = errors.push).apply; | ||
_c = [errors]; | ||
return [4 /*yield*/, validateSection(section, "sections[" + i + "]", ajv)]; | ||
_c = (_b = errors.push).apply; | ||
_d = [errors]; | ||
_e = [[]]; | ||
return [4 /*yield*/, validateSection(section, "sections[".concat(i, "]"), ajv)]; | ||
case 2: | ||
_b.apply(_a, _c.concat([__spread.apply(void 0, [_h.sent()])])); | ||
_c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [_l.sent()]), false]))])); | ||
if (!(isFormSection(section) && Object.keys(section).length > 0 && Array.isArray(section.elements))) return [3 /*break*/, 6]; | ||
j = 0; | ||
_h.label = 3; | ||
_l.label = 3; | ||
case 3: | ||
@@ -121,8 +128,9 @@ if (!(j < section.elements.length)) return [3 /*break*/, 6]; | ||
if (!(Object.keys(element).length > 0)) return [3 /*break*/, 5]; | ||
_e = (_d = errors.push).apply; | ||
_f = [errors]; | ||
return [4 /*yield*/, validateElementDefinition(element, "sections[" + i + "].elements[" + j + "]", ajv)]; | ||
_g = (_f = errors.push).apply; | ||
_h = [errors]; | ||
_j = [[]]; | ||
return [4 /*yield*/, validateElementDefinition(element, "sections[".concat(i, "].elements[").concat(j, "]"), ajv)]; | ||
case 4: | ||
_e.apply(_d, _f.concat([__spread.apply(void 0, [(_h.sent())])])); | ||
_h.label = 5; | ||
_g.apply(_f, _h.concat([__spreadArray.apply(void 0, _j.concat([__read.apply(void 0, [(_l.sent())]), false]))])); | ||
_l.label = 5; | ||
case 5: | ||
@@ -142,6 +150,6 @@ j++; | ||
var addSectionDataKey = function (key) { | ||
var dataKey = section.key + "." + key; | ||
var dataKey = "".concat(section.key, ".").concat(key); | ||
dataKeys_1.add(dataKey); | ||
if (sectionDataKeys.has(dataKey)) { | ||
errors.push("data key " + dataKey + " is defined more than once"); | ||
errors.push("data key ".concat(dataKey, " is defined more than once")); | ||
} | ||
@@ -168,3 +176,3 @@ else { | ||
} | ||
unvalidatedDataRefs_2.push.apply(unvalidatedDataRefs_2, __spread(eachMustacheRef(section, "sections[" + sectionIndex + "]"))); | ||
unvalidatedDataRefs_2.push.apply(unvalidatedDataRefs_2, __spreadArray([], __read(eachMustacheRef(section, "sections[".concat(sectionIndex, "]"))), false)); | ||
var i = 0; | ||
@@ -178,3 +186,3 @@ try { | ||
// verify all mustache references are valid (and fully qualified) | ||
unvalidatedDataRefs_2.push.apply(unvalidatedDataRefs_2, __spread(eachMustacheRef(element, "sections[" + sectionIndex + "].elements[" + i + "]"))); | ||
unvalidatedDataRefs_2.push.apply(unvalidatedDataRefs_2, __spreadArray([], __read(eachMustacheRef(element, "sections[".concat(sectionIndex, "].elements[").concat(i, "]"))), false)); | ||
i++; | ||
@@ -193,3 +201,3 @@ } | ||
// verify all key references in predicates are valid | ||
for (var _h = __values(traverseForm(section, "sections[" + sectionIndex + "]")), _j = _h.next(); !_j.done; _j = _h.next()) { | ||
for (var _h = __values(traverseForm(section, "sections[".concat(sectionIndex, "]"))), _j = _h.next(); !_j.done; _j = _h.next()) { | ||
var ref = _j.value; | ||
@@ -202,3 +210,3 @@ if (isDataRef(ref)) { | ||
else { | ||
errors.push.apply(errors, __spread(validateRegex(ref))); | ||
errors.push.apply(errors, __spreadArray([], __read(validateRegex(ref)), false)); | ||
} | ||
@@ -219,3 +227,3 @@ } | ||
if (!dataKeys_1.has(ref.key)) { | ||
errors.push(ref.path + " references undefined data key '" + ref.key + "'"); | ||
errors.push("".concat(ref.path, " references undefined data key '").concat(ref.key, "'")); | ||
} | ||
@@ -227,3 +235,3 @@ } | ||
try { | ||
if (unvalidatedDataRefs_1_1 && !unvalidatedDataRefs_1_1.done && (_g = unvalidatedDataRefs_1.return)) _g.call(unvalidatedDataRefs_1); | ||
if (unvalidatedDataRefs_1_1 && !unvalidatedDataRefs_1_1.done && (_k = unvalidatedDataRefs_1.return)) _k.call(unvalidatedDataRefs_1); | ||
} | ||
@@ -272,5 +280,6 @@ finally { if (e_1) throw e_1.error; } | ||
function validateElementDefinition(element, path, ajv) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var errors, type, elementSchema; | ||
return __generator(this, function (_a) { | ||
return __generator(this, function (_b) { | ||
errors = []; | ||
@@ -281,7 +290,7 @@ type = ELEMENT_TYPE_MAPPING[element.type]; | ||
if (!ajv.validate(elementSchema, element)) { | ||
ajv.errors.forEach(function (e) { return errors.push(formatAjvError(e, path)); }); | ||
((_a = ajv.errors) !== null && _a !== void 0 ? _a : []).forEach(function (e) { return errors.push(formatAjvError(e, path)); }); | ||
} | ||
} | ||
else { | ||
errors.push(path + ".type must be equal to one of the allowed values"); | ||
errors.push("".concat(path, ".type must be equal to one of the allowed values")); | ||
} | ||
@@ -294,7 +303,9 @@ return [2 /*return*/, errors]; | ||
function formatAjvError(e, basePath) { | ||
var adjustedDataPath = e.dataPath.length > 0 ? e.dataPath.substring(1).replace(/\['([^']+)']/, '.$1') + ' ' : ''; | ||
var _a, _b; | ||
var adjustedDataPath = e.instancePath.length > 0 ? | ||
e.instancePath.substring(1).replace(/\['([^']+)']/, '.$1') + ' ' : ''; | ||
if (basePath) { | ||
adjustedDataPath = adjustedDataPath.length > 0 ? basePath + "." + adjustedDataPath : basePath + ' '; | ||
adjustedDataPath = adjustedDataPath.length > 0 ? "".concat(basePath, ".").concat(adjustedDataPath) : basePath + ' '; | ||
} | ||
return "" + adjustedDataPath + e.message.replace(/\bshould\b/, 'must'); | ||
return "".concat(adjustedDataPath).concat((_b = (_a = e.message) === null || _a === void 0 ? void 0 : _a.replace(/\bshould\b/, 'must')) !== null && _b !== void 0 ? _b : ''); | ||
} | ||
@@ -312,3 +323,3 @@ function traverseForm(item, path) { | ||
if (!(i < item.length)) return [3 /*break*/, 4]; | ||
return [5 /*yield**/, __values(traverseForm(item[i], path + "[" + i + "]"))]; | ||
return [5 /*yield**/, __values(traverseForm(item[i], "".concat(path, "[").concat(i, "]")))]; | ||
case 2: | ||
@@ -341,3 +352,3 @@ _d.sent(); | ||
return [3 /*break*/, 12]; | ||
case 10: return [5 /*yield**/, __values(traverseForm(val, path + "." + key))]; | ||
case 10: return [5 /*yield**/, __values(traverseForm(val, "".concat(path, ".").concat(key)))]; | ||
case 11: | ||
@@ -383,3 +394,3 @@ _d.sent(); | ||
if (!m) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, { path: path + "." + prop, key: m[1] }]; | ||
return [4 /*yield*/, { path: "".concat(path, ".").concat(prop), key: m[1] }]; | ||
case 3: | ||
@@ -410,3 +421,3 @@ _d.sent(); | ||
function qualifyKey(section, key) { | ||
return key.startsWith(section.key + '.') ? key : section.key + "." + key; | ||
return key.startsWith(section.key + '.') ? key : "".concat(section.key, ".").concat(key); | ||
} | ||
@@ -433,7 +444,7 @@ function isDataRef(ref) { | ||
catch (e) { | ||
errors.push("Invalid regex at " + regexRef.path + ".regex"); | ||
errors.push("Invalid regex at ".concat(regexRef.path, ".regex")); | ||
} | ||
if (regexRef.flags) { | ||
if (!new RegExp('/^[gimsuy]*$/').test(regexRef.flags)) { | ||
errors.push("Invalid regex flags at " + regexRef.path + ".flags"); | ||
errors.push("Invalid regex flags at ".concat(regexRef.path, ".flags")); | ||
} | ||
@@ -440,0 +451,0 @@ } |
@@ -82,3 +82,4 @@ "use strict"; | ||
regex: '/^[a-z0-9]{13,}/i', | ||
message: 'Your API secret does not appear to be valid. It can be found on your MonkeyMailer admin page under Integrations > API.' | ||
message: 'Your API secret does not appear to be valid. ' + | ||
'It can be found on your MonkeyMailer admin page under Integrations > API.' | ||
} | ||
@@ -104,3 +105,3 @@ ] | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(validForm)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(validForm)]; | ||
case 1: | ||
@@ -128,3 +129,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([]); | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(validForm)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(validForm)]; | ||
case 1: | ||
@@ -160,3 +161,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([]); | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(invalidForm)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(invalidForm)]; | ||
case 1: | ||
@@ -204,3 +205,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([ | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(form)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(form)]; | ||
case 1: | ||
@@ -244,3 +245,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([ | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(invalidForm)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(invalidForm)]; | ||
case 1: | ||
@@ -296,3 +297,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([]); | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(form)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(form)]; | ||
case 1: | ||
@@ -320,3 +321,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([ | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(form)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(form)]; | ||
case 1: | ||
@@ -344,3 +345,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([ | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(form)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(form)]; | ||
case 1: | ||
@@ -371,3 +372,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([ | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(form)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(form)]; | ||
case 1: | ||
@@ -425,3 +426,3 @@ _a.apply(void 0, [_b.sent()]).toEqual([ | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(invalidForm)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(invalidForm)]; | ||
case 1: | ||
@@ -467,8 +468,9 @@ _a.apply(void 0, [_b.sent()]).toEqual([ | ||
_a = expect; | ||
return [4 /*yield*/, validateForm_1.validateFormDefinition(invalidForm)]; | ||
return [4 /*yield*/, (0, validateForm_1.validateFormDefinition)(invalidForm)]; | ||
case 1: | ||
_a.apply(void 0, [_b.sent()]).toEqual([ | ||
'sections[0] must NOT have additional properties', | ||
"sections[0] must have required property 'key'", | ||
"sections[0] must have required property 'mode'" | ||
"sections[0] must have required property 'label'", | ||
"sections[0] must have required property 'mode'", | ||
'sections[0] must NOT have additional properties' | ||
]); | ||
@@ -475,0 +477,0 @@ return [2 /*return*/]; |
{ | ||
"name": "@zaiusinc/app-forms-schema", | ||
"version": "0.4.1", | ||
"version": "1.0.0", | ||
"license": "Apache-2.0", | ||
@@ -18,5 +18,8 @@ "licenses": [ | ||
"types": "dist/index.d.ts", | ||
"engines": { | ||
"node": ">=18.0" | ||
}, | ||
"scripts": { | ||
"build": "yarn update-schema && tsc && cp ./src/schema/Form.schema.json ./dist/", | ||
"lint": "tslint --project .", | ||
"lint": "npx eslint 'src/**/*.ts'", | ||
"prettier": "prettier --write 'src/**/*.ts'", | ||
@@ -27,16 +30,27 @@ "test": "jest", | ||
"dependencies": { | ||
"ajv": "^6.10.0" | ||
"ajv": "^8.11.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.11", | ||
"@zaiusinc/tslint-presets": "^1.0.1", | ||
"jest": "^24.5.0", | ||
"prettier": "^2.0.4", | ||
"ts-jest": "^24.0.0", | ||
"tslint": "^5.20.0", | ||
"typedoc": "^0.14.2", | ||
"typescript": "^3.9.5", | ||
"typescript-json-schema": "^0.42.0" | ||
"@types/jest": "^28.1.8", | ||
"@typescript-eslint/parser": "^5.37.0", | ||
"@typescript-eslint/eslint-plugin": "^5.35.1", | ||
"@typescript-eslint/eslint-plugin-tslint": "^5.35.1", | ||
"@zaiusinc/eslint-config-presets": "^1.0.0", | ||
"eslint": "^8.0.1", | ||
"eslint-config-standard-with-typescript": "^22.0.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jsdoc": "^39.3.6", | ||
"eslint-plugin-n": "^15.0.0", | ||
"eslint-plugin-prefer-arrow": "^1.2.3", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"eslint-plugin-react": "^7.31.1", | ||
"jest": "^28.1.3", | ||
"prettier": "^2.7.1", | ||
"ts-jest": "^28.0.8", | ||
"tslint": "^5.14.0", | ||
"typedoc": "^0.23.11", | ||
"typescript": "^4.7.4", | ||
"typescript-json-schema": "^0.54.0" | ||
}, | ||
"publishConfig": {} | ||
} |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable @typescript-eslint/no-shadow */ | ||
import {Evaluation} from '../evaluations'; | ||
@@ -2,0 +3,0 @@ import {Button, LinkButton, OAuthImageButton} from './'; |
@@ -43,3 +43,4 @@ import 'jest'; | ||
message: | ||
'Your API secret does not appear to be valid. It can be found on your MonkeyMailer admin page under Integrations > API.' | ||
'Your API secret does not appear to be valid. ' + | ||
'It can be found on your MonkeyMailer admin page under Integrations > API.' | ||
} | ||
@@ -342,5 +343,6 @@ ] | ||
expect(await validateFormDefinition(invalidForm as any)).toEqual([ | ||
'sections[0] must NOT have additional properties', | ||
"sections[0] must have required property 'key'", | ||
"sections[0] must have required property 'mode'" | ||
"sections[0] must have required property 'label'", | ||
"sections[0] must have required property 'mode'", | ||
'sections[0] must NOT have additional properties' | ||
]); | ||
@@ -347,0 +349,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import * as Ajv from 'ajv'; | ||
import Ajv from 'ajv'; | ||
import {ErrorObject} from 'ajv'; | ||
@@ -38,3 +38,3 @@ import {Comparator, FieldValidation, Predicate, RegexComparator} from '../evaluations'; | ||
if (!ajv.validate(formRootSchema, form)) { | ||
ajv.errors!.forEach((e) => errors.push(formatAjvError(e))); | ||
(ajv.errors ?? []).forEach((e) => errors.push(formatAjvError(e))); | ||
} | ||
@@ -136,3 +136,3 @@ if (Array.isArray(form.sections)) { | ||
export async function validateSection(section: Section | ZedSection, path: string, ajv: any): Promise<string[]> { | ||
export async function validateSection(section: Section | ZedSection, path: string, ajv: Ajv): Promise<string[]> { | ||
const type = isFormSection(section) ? 'Section' : 'ZedSection'; | ||
@@ -143,3 +143,2 @@ // reconfigure the schema to only validate the section | ||
definitions: formSchema.definitions, | ||
// @ts-ignore | ||
...formSchema.definitions[type] | ||
@@ -150,3 +149,3 @@ }, section); | ||
export async function validateElementDefinition(element: AnyElement, path: string, ajv: any): Promise<string[]> { | ||
export async function validateElementDefinition(element: AnyElement, path: string, ajv: Ajv): Promise<string[]> { | ||
const errors: string[] = []; | ||
@@ -159,7 +158,6 @@ const type = ELEMENT_TYPE_MAPPING[element.type]; | ||
definitions: formSchema.definitions, | ||
// @ts-ignore | ||
...formSchema.definitions[type] | ||
...formSchema.definitions[type as keyof typeof formSchema.definitions] | ||
}; | ||
if (!ajv.validate(elementSchema, element)) { | ||
ajv.errors!.forEach((e: ErrorObject) => errors.push(formatAjvError(e, path))); | ||
(ajv.errors ?? []).forEach((e: ErrorObject) => errors.push(formatAjvError(e, path))); | ||
} | ||
@@ -173,7 +171,8 @@ } else { | ||
function formatAjvError(e: ErrorObject, basePath?: string): string { | ||
let adjustedDataPath = e.dataPath.length > 0 ? e.dataPath.substring(1).replace(/\['([^']+)']/, '.$1') + ' ' : ''; | ||
let adjustedDataPath = e.instancePath.length > 0 ? | ||
e.instancePath.substring(1).replace(/\['([^']+)']/, '.$1') + ' ' : ''; | ||
if (basePath) { | ||
adjustedDataPath = adjustedDataPath.length > 0 ? `${basePath}.${adjustedDataPath}` : basePath + ' '; | ||
} | ||
return `${adjustedDataPath}${e.message!.replace(/\bshould\b/, 'must')}`; | ||
return `${adjustedDataPath}${e.message?.replace(/\bshould\b/, 'must') ?? ''}`; | ||
} | ||
@@ -180,0 +179,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
406739
0.84%10233
0.43%1
-50%20
122.22%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated