recime-bot-runtime
Version:
This runtime is intended to run inside a micro-service container with platform specific integration and module interpreter.
40 lines (39 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var Ajv = require("ajv");
var config_1 = require("./config");
var platforms = ['facebook', 'telegram', 'twilio', 'wechat', 'slack', 'slack-command', 'sendbird', 'slack-event', "viber", 'telegram-callback', 'bot-framework'];
var SchemaValidator = /** @class */ (function () {
function SchemaValidator(schema) {
this.schema = schema;
}
SchemaValidator.findOne = function (data) {
return new Promise(function (resolve, reject) {
var validator = new SchemaValidator(config_1.Config.schema);
Promise.all(platforms.map(function (platform) {
return validator.validate(platform, data);
})).then(function (results) {
var index = results.indexOf(true);
if (results.indexOf(true) >= 0) {
resolve(platforms[index].replace(/-callback/, ""));
}
else {
resolve("web");
}
});
});
};
SchemaValidator.prototype.validate = function (platform, data) {
var _this = this;
return new Promise(function (resolve, reject) {
resolve(_this.validateSchema(_this.schema[platform], data));
});
};
SchemaValidator.prototype.validateSchema = function (schema, data) {
var ajv = new Ajv();
var validate = ajv.compile(schema);
return validate(data);
};
return SchemaValidator;
}());
exports.SchemaValidator = SchemaValidator;