n8n
Version:
n8n Workflow Automation Tool
61 lines • 2.78 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_EXECUTIONS_GET_ALL_LIMIT = void 0;
exports.validateEntity = validateEntity;
exports.validateRecordNoXss = validateRecordNoXss;
const class_validator_1 = require("class-validator");
const bad_request_error_1 = require("./errors/response-errors/bad-request.error");
const no_xss_validator_1 = require("./validators/no-xss.validator");
async function validateEntity(entity) {
const errors = await (0, class_validator_1.validate)(entity);
const errorMessages = errors
.reduce((acc, cur) => {
if (!cur.constraints)
return acc;
acc.push(...Object.values(cur.constraints));
return acc;
}, [])
.join(' | ');
if (errorMessages) {
throw new bad_request_error_1.BadRequestError(errorMessages);
}
}
exports.DEFAULT_EXECUTIONS_GET_ALL_LIMIT = 20;
class StringWithNoXss {
constructor(value) {
this.value = value;
}
}
__decorate([
(0, no_xss_validator_1.NoXss)(),
__metadata("design:type", String)
], StringWithNoXss.prototype, "value", void 0);
async function validateRecordNoXss(record) {
const errors = [];
for (const [key, value] of Object.entries(record)) {
const stringWithNoXss = new StringWithNoXss(value);
const validationErrors = await (0, class_validator_1.validate)(stringWithNoXss);
if (validationErrors.length > 0) {
const error = new class_validator_1.ValidationError();
error.property = key;
error.constraints = validationErrors[0].constraints;
errors.push(error);
}
}
if (errors.length > 0) {
const errorMessages = errors
.map((error) => { var _a; return `${error.property}: ${Object.values((_a = error.constraints) !== null && _a !== void 0 ? _a : {}).join(', ')}`; })
.join(' | ');
throw new bad_request_error_1.BadRequestError(errorMessages);
}
}
//# sourceMappingURL=GenericHelpers.js.map
;