badmfck-api-server 2.9.9 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,10 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.Validator = exports.ValidationReport = void 0;
|
7
|
+
const dns_1 = __importDefault(require("dns"));
|
4
8
|
var ValidationReport;
|
5
9
|
(function (ValidationReport) {
|
6
10
|
ValidationReport[ValidationReport["OK"] = 1] = "OK";
|
@@ -44,6 +48,15 @@ class Validator {
|
|
44
48
|
for (let i in structure) {
|
45
49
|
if (!(i in object))
|
46
50
|
errors.push("no field '" + i + "'");
|
51
|
+
if (typeof structure[i] === "number" && typeof object[i] === "string") {
|
52
|
+
let num = parseInt(object[i]);
|
53
|
+
if (object[i].includes(","))
|
54
|
+
num = parseFloat(object[i]);
|
55
|
+
if (isNaN(num))
|
56
|
+
errors.push("wrong value for field '" + i + "', expected number got " + object[i]);
|
57
|
+
else
|
58
|
+
object[i] = num;
|
59
|
+
}
|
47
60
|
if (typeof object[i] !== typeof structure[i])
|
48
61
|
errors.push("wrong datatype for field '" + i + "' expected " + typeof structure[i] + " got " + typeof object[i]);
|
49
62
|
if (typeof structure[i] === "object" || typeof structure[i] === "function") {
|
@@ -63,6 +76,24 @@ class Validator {
|
|
63
76
|
errors.push("wrong value for field '" + i + "', expected " + expected.join(", ") + " got: " + value);
|
64
77
|
}
|
65
78
|
}
|
79
|
+
if (typeof structure[i] === "string" && structure[i].includes("regex:")) {
|
80
|
+
const regex = structure[i].substring(6);
|
81
|
+
const reg = new RegExp(regex);
|
82
|
+
if (reg.test(object[i]) === false)
|
83
|
+
errors.push("wrong value for field '" + i + "', false mask for: " + object[i]);
|
84
|
+
}
|
85
|
+
if (typeof structure[i] === "string" && (structure[i] === "@" || structure[i] === "email")) {
|
86
|
+
const value = object[i].toString().toLowerCase().trim();
|
87
|
+
if (value.replaceAll(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,6}$/g, "").length !== 0)
|
88
|
+
errors.push("wrong value for field '" + i + "', expected email got: " + object[i]);
|
89
|
+
const domain = value.split("@")[1];
|
90
|
+
try {
|
91
|
+
await dns_1.default.promises.resolveMx(domain);
|
92
|
+
}
|
93
|
+
catch (e) {
|
94
|
+
return ["MX Domain is incorrect"];
|
95
|
+
}
|
96
|
+
}
|
66
97
|
if (typeof structure[i] === "number") {
|
67
98
|
if (isNaN(object[i]))
|
68
99
|
errors.push("wrong value for field '" + i + "', expected number got " + object[i]);
|