botpress
Version:
The world's first CMS for bots. Easily create, manage and extend chatbots.
51 lines (38 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateFlowSchema = undefined;
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const validateFlowSchema = exports.validateFlowSchema = flow => {
const errorPrefix = `[Flow] Invalid flow "${flow && flow.location}"`;
if (!flow || !_lodash2.default.isObjectLike(flow)) {
return 'Invalid JSON flow schema';
}
if (!flow.version || !_lodash2.default.isString(flow.version)) {
return `${errorPrefix}, expected valid version but found none`;
}
if (!flow.version.startsWith('0.')) {
return `${errorPrefix}, unsupported version of the schema "${flow.version}"`;
}
if (!_lodash2.default.isString(flow.startNode)) {
return `${errorPrefix}, expected valid 'startNode'`;
}
if (!_lodash2.default.isArray(flow.nodes)) {
return `${errorPrefix}, expected 'nodes' to be an array of nodes`;
}
if (!_lodash2.default.find(flow.nodes, { name: flow.startNode })) {
return `${errorPrefix}, expected 'startNode' to point to a valid node name`;
}
if (flow.catchAll && flow.catchAll.onEnter) {
return `${errorPrefix}, "catchAll" does not support "onEnter"`;
}
for (const node of flow.nodes) {
if (!_lodash2.default.isString(node.id) || node.id.length <= 3) {
return `${errorPrefix}, expected node ${node.id} (${node.name}) to have a valid id`;
}
}
};
//# sourceMappingURL=validator.js.map