drapcode-utility 1.9.6 → 1.9.78
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.
- package/build/encryption/utility.d.ts +1 -2
- package/build/encryption/utility.js +4 -39
- package/build/format-fields/index.js +1 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +3 -1
- package/build/utils/check-error.js +7 -7
- package/build/utils/common-util.d.ts +78 -0
- package/build/utils/common-util.js +219 -0
- package/build/utils/date-util.js +0 -13
- package/build/utils/file-util.d.ts +7 -0
- package/build/utils/file-util.js +118 -0
- package/build/utils/prepare-query.d.ts +0 -148
- package/build/utils/prepare-query.js +1 -100
- package/build/utils/project-util.d.ts +1 -0
- package/build/utils/project-util.js +31 -49
- package/build/utils/{query-paser-new.js → query-parser-new.js} +24 -174
- package/build/utils/query-parser.d.ts +0 -12
- package/build/utils/query-parser.js +16 -280
- package/build/utils/query-utils.d.ts +20 -0
- package/build/utils/query-utils.js +254 -0
- package/build/utils/rest-client.d.ts +6 -0
- package/build/utils/rest-client.js +342 -0
- package/build/utils/util.d.ts +77 -3
- package/build/utils/util.js +511 -32
- package/package.json +10 -5
- /package/build/utils/{query-paser-new.d.ts → query-parser-new.d.ts} +0 -0
package/build/utils/util.js
CHANGED
|
@@ -10,6 +10,42 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
13
49
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
50
|
var t = {};
|
|
15
51
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -34,11 +70,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
34
70
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
35
71
|
};
|
|
36
72
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.replaceUnderscoreWithSlash = exports.replaceSlashWithUnderscore = exports.toggleConsoleLogs = exports.validateUrl = exports.validateData = exports.fillDefaultValues = exports.replaceValueFromSource = exports.
|
|
73
|
+
exports.average = exports.substraction = exports.addition = exports.validateNumbers = exports.checkAndConvertNumber = exports.evaluateCustomSentence = exports.strJoin = exports.markdownToHtml = exports.substr = exports.truncate = exports.titleCase = exports.trim = exports.slugify = exports.upperCase = exports.lowerCase = exports.capitalize = exports.replaceUnderscoreWithSlash = exports.replaceSlashWithUnderscore = exports.toggleConsoleLogs = exports.validateUrl = exports.validateData = exports.fillDefaultValues = exports.replaceValueFromSource = exports.processFieldsInclude = exports.removeMongoDbId = exports.replaceTransferObjectValueIntoExpression = exports.unflattenObject = exports.parseValueFromData = exports.parseJsonString = exports.replaceDataValueIntoExpression = exports.formatCustomCSSClasses = exports.validateAlphanumericString = exports.convertItemToArray = exports.arraysEqual = exports.checkAndCompareValue = exports.restructureData = exports.formatCollectionAndFieldName = exports.cleanCollectionAndFieldName = exports.stringToExpression = exports.expressionToString = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.dynamicSort = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = void 0;
|
|
74
|
+
exports.getAwsSignature = exports.replaceValuesFromRequestMapping = exports.replaceValuesFromObjArr = exports.checkFieldValueType = exports.getPrimaryFieldNameOfDataSource = exports.getFieldSchemaForDataSourcePrimaryId = exports.getMappingObjKey = exports.getItemDataForArrayFields = exports.getFileObjectList = exports.getFindQuery = exports.mergeObjects = exports.dateDifference = exports.formatDate = exports.evaluateJSLogic = exports.evaluateCurrency = exports.evaluateExpression = exports.divide = exports.multiply = void 0;
|
|
38
75
|
var drapcode_constant_1 = require("drapcode-constant");
|
|
39
76
|
var lodash_1 = __importDefault(require("lodash"));
|
|
77
|
+
var showdown_1 = __importDefault(require("showdown"));
|
|
40
78
|
var format_fields_1 = require("../format-fields");
|
|
41
79
|
var uuid_1 = require("uuid");
|
|
80
|
+
var voca_1 = __importDefault(require("voca"));
|
|
81
|
+
var numeral_1 = __importDefault(require("numeral"));
|
|
82
|
+
var mathjs_1 = __importDefault(require("mathjs"));
|
|
83
|
+
var moment_1 = __importDefault(require("moment"));
|
|
84
|
+
var mime_types_1 = __importDefault(require("mime-types"));
|
|
85
|
+
var uuid_2 = require("uuid");
|
|
86
|
+
var aws4_1 = require("aws4");
|
|
42
87
|
// TODO: Refactor
|
|
43
88
|
var derivedFieldExcludes = [
|
|
44
89
|
"formatType",
|
|
@@ -105,20 +150,13 @@ var isEmpty = function (obj) {
|
|
|
105
150
|
};
|
|
106
151
|
exports.isEmpty = isEmpty;
|
|
107
152
|
var isEmptyObject = function (object) {
|
|
108
|
-
return
|
|
153
|
+
return (0, exports.isEmpty)(object) && object.constructor === Object;
|
|
109
154
|
};
|
|
110
155
|
exports.isEmptyObject = isEmptyObject;
|
|
111
156
|
var isObject = function (item) {
|
|
112
157
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
113
158
|
};
|
|
114
159
|
exports.isObject = isObject;
|
|
115
|
-
var checkValidArray = function (object) {
|
|
116
|
-
return (object &&
|
|
117
|
-
object !== "null" &&
|
|
118
|
-
object !== undefined &&
|
|
119
|
-
Object.keys(object).length > 0);
|
|
120
|
-
};
|
|
121
|
-
exports.checkValidArray = checkValidArray;
|
|
122
160
|
var dynamicSort = function (property) {
|
|
123
161
|
return function (a, b) {
|
|
124
162
|
var result = 0;
|
|
@@ -146,22 +184,6 @@ var dynamicSort = function (property) {
|
|
|
146
184
|
};
|
|
147
185
|
};
|
|
148
186
|
exports.dynamicSort = dynamicSort;
|
|
149
|
-
var snakeCaseToTitleCase = function (str, checkForUnderscore) {
|
|
150
|
-
if (checkForUnderscore === void 0) { checkForUnderscore = false; }
|
|
151
|
-
if (!str)
|
|
152
|
-
return str;
|
|
153
|
-
if (typeof str === "string" && !checkForUnderscore) {
|
|
154
|
-
return str
|
|
155
|
-
.toLowerCase()
|
|
156
|
-
.split("_")
|
|
157
|
-
.map(function (word) {
|
|
158
|
-
return word.replace(word[0], word[0].toUpperCase());
|
|
159
|
-
})
|
|
160
|
-
.join(" ");
|
|
161
|
-
}
|
|
162
|
-
return str;
|
|
163
|
-
};
|
|
164
|
-
exports.snakeCaseToTitleCase = snakeCaseToTitleCase;
|
|
165
187
|
var validateEmail = function (email) {
|
|
166
188
|
if (!email) {
|
|
167
189
|
return false;
|
|
@@ -519,7 +541,7 @@ var removeMongoDbId = function (result) {
|
|
|
519
541
|
return result.map(moveUuidToTopLevel);
|
|
520
542
|
};
|
|
521
543
|
exports.removeMongoDbId = removeMongoDbId;
|
|
522
|
-
var
|
|
544
|
+
var processFieldsInclude = function (fieldsInclude) {
|
|
523
545
|
var result = fieldsInclude;
|
|
524
546
|
var refFieldsInclude = fieldsInclude.filter(function (field) {
|
|
525
547
|
return field.startsWith("RF::");
|
|
@@ -534,7 +556,7 @@ var processFieldsInlcude = function (fieldsInclude) {
|
|
|
534
556
|
result = __spreadArray(__spreadArray([], fieldsInclude, true), extraField, true);
|
|
535
557
|
return result;
|
|
536
558
|
};
|
|
537
|
-
exports.
|
|
559
|
+
exports.processFieldsInclude = processFieldsInclude;
|
|
538
560
|
var processReferenceFieldInclude = function (refFieldsInclude) {
|
|
539
561
|
var refFields = [];
|
|
540
562
|
refFieldsInclude.forEach(function (exField) {
|
|
@@ -556,12 +578,12 @@ var processDerivedFieldInclude = function (derivedFieldsInclude) {
|
|
|
556
578
|
if (arg.name === "expression") {
|
|
557
579
|
var needleList = (_a = arg.key
|
|
558
580
|
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
559
|
-
var tempFields = (0, exports.
|
|
581
|
+
var tempFields = (0, exports.processFieldsInclude)(needleList);
|
|
560
582
|
fields = __spreadArray(__spreadArray([], fields, true), tempFields, true);
|
|
561
583
|
}
|
|
562
584
|
else if (!derivedFieldExcludes.includes(arg.name)) {
|
|
563
585
|
var tempFields = Array.isArray(arg.key) ? arg.key : [arg.key];
|
|
564
|
-
tempFields = (0, exports.
|
|
586
|
+
tempFields = (0, exports.processFieldsInclude)(tempFields);
|
|
565
587
|
fields = __spreadArray(__spreadArray([], fields, true), tempFields, true);
|
|
566
588
|
}
|
|
567
589
|
});
|
|
@@ -681,9 +703,24 @@ var validateData = function (fields, data) {
|
|
|
681
703
|
break;
|
|
682
704
|
case "reference":
|
|
683
705
|
case "belongsTo":
|
|
684
|
-
if (
|
|
685
|
-
fieldValue.some(function (item) {
|
|
686
|
-
|
|
706
|
+
if (Array.isArray(fieldValue)) {
|
|
707
|
+
var invalid = fieldValue.some(function (item) {
|
|
708
|
+
if (typeof item === "string")
|
|
709
|
+
return false;
|
|
710
|
+
if (typeof item === "object" && typeof item.uuid === "string")
|
|
711
|
+
return false;
|
|
712
|
+
return true;
|
|
713
|
+
});
|
|
714
|
+
if (invalid) {
|
|
715
|
+
errors.push("".concat(fieldTitle, " must be an array of UUID strings or objects with a uuid"));
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
else {
|
|
719
|
+
if (!(typeof fieldValue === "string" ||
|
|
720
|
+
(typeof fieldValue === "object" &&
|
|
721
|
+
typeof (fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.uuid) === "string"))) {
|
|
722
|
+
errors.push("".concat(fieldTitle, " must be a UUID string or an object with a uuid"));
|
|
723
|
+
}
|
|
687
724
|
}
|
|
688
725
|
break;
|
|
689
726
|
case "createdAt":
|
|
@@ -806,3 +843,445 @@ var replaceUnderscoreWithSlash = function (value) {
|
|
|
806
843
|
return value && value.replace(/____/g, "/");
|
|
807
844
|
};
|
|
808
845
|
exports.replaceUnderscoreWithSlash = replaceUnderscoreWithSlash;
|
|
846
|
+
var capitalize = function (str, restToLower) {
|
|
847
|
+
return voca_1.default.capitalize(str, restToLower === "TRUE");
|
|
848
|
+
};
|
|
849
|
+
exports.capitalize = capitalize;
|
|
850
|
+
var lowerCase = function (subject) {
|
|
851
|
+
return voca_1.default.lowerCase(subject);
|
|
852
|
+
};
|
|
853
|
+
exports.lowerCase = lowerCase;
|
|
854
|
+
var upperCase = function (subject) {
|
|
855
|
+
return voca_1.default.upperCase(subject);
|
|
856
|
+
};
|
|
857
|
+
exports.upperCase = upperCase;
|
|
858
|
+
var slugify = function (subject) {
|
|
859
|
+
return voca_1.default.slugify(subject);
|
|
860
|
+
};
|
|
861
|
+
exports.slugify = slugify;
|
|
862
|
+
var trim = function (subject, whitespace, type) {
|
|
863
|
+
if (type === "LEFT") {
|
|
864
|
+
return voca_1.default.trimLeft(subject, whitespace);
|
|
865
|
+
}
|
|
866
|
+
else if (type === "RIGHT") {
|
|
867
|
+
return voca_1.default.trimRight(subject, whitespace);
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
return voca_1.default.trim(subject, whitespace);
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
exports.trim = trim;
|
|
874
|
+
var titleCase = function (subject, noSplitopt) {
|
|
875
|
+
return voca_1.default.titleCase(subject, [noSplitopt]);
|
|
876
|
+
};
|
|
877
|
+
exports.titleCase = titleCase;
|
|
878
|
+
var truncate = function (subject, length, endopt) {
|
|
879
|
+
return voca_1.default.truncate(subject, length, endopt);
|
|
880
|
+
};
|
|
881
|
+
exports.truncate = truncate;
|
|
882
|
+
var substr = function (subject, startLength, endLength) {
|
|
883
|
+
return voca_1.default.substr(subject, startLength, endLength);
|
|
884
|
+
};
|
|
885
|
+
exports.substr = substr;
|
|
886
|
+
var markdownToHtml = function (subject) {
|
|
887
|
+
var converter = new showdown_1.default.Converter({ tables: true });
|
|
888
|
+
var html = converter.makeHtml(subject);
|
|
889
|
+
return html;
|
|
890
|
+
};
|
|
891
|
+
exports.markdownToHtml = markdownToHtml;
|
|
892
|
+
var strJoin = function (dataArr, separator, startString, endString) {
|
|
893
|
+
separator = separator ? separator.replace(/##@@##@@##/g, " ") : " ";
|
|
894
|
+
dataArr = Array.isArray(dataArr) ? dataArr : [dataArr];
|
|
895
|
+
dataArr = dataArr.filter(Boolean);
|
|
896
|
+
return "".concat(startString ? startString.replace(/##@@##@@##/g, " ") + separator : "").concat(dataArr.join(separator)).concat(endString ? separator + endString.replace(/##@@##@@##/g, " ") : "");
|
|
897
|
+
};
|
|
898
|
+
exports.strJoin = strJoin;
|
|
899
|
+
var evaluateCustomSentence = function (expression, data, user, envConstants) {
|
|
900
|
+
expression = expression
|
|
901
|
+
? (0, exports.getSpecialCharectorReplacedExpression)(expression)
|
|
902
|
+
: " ";
|
|
903
|
+
return (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
|
|
904
|
+
};
|
|
905
|
+
exports.evaluateCustomSentence = evaluateCustomSentence;
|
|
906
|
+
var checkAndConvertNumber = function (number) {
|
|
907
|
+
return lodash_1.default.isNumber(number) ? number : Number(number);
|
|
908
|
+
};
|
|
909
|
+
exports.checkAndConvertNumber = checkAndConvertNumber;
|
|
910
|
+
var validateNumbers = function (numbers) {
|
|
911
|
+
return numbers.map(function (number) {
|
|
912
|
+
return (0, exports.checkAndConvertNumber)(number);
|
|
913
|
+
});
|
|
914
|
+
};
|
|
915
|
+
exports.validateNumbers = validateNumbers;
|
|
916
|
+
var addition = function (formatType, _a) {
|
|
917
|
+
var numbers = _a.numbers;
|
|
918
|
+
try {
|
|
919
|
+
if (!Array.isArray(numbers)) {
|
|
920
|
+
numbers = [numbers, 0];
|
|
921
|
+
}
|
|
922
|
+
numbers = numbers.map(function (number) { return (isNaN(number) ? 0 : number); });
|
|
923
|
+
var allNumbers = (0, exports.validateNumbers)(numbers);
|
|
924
|
+
return (0, numeral_1.default)(mathjs_1.default.add.apply(mathjs_1.default, allNumbers)).format(formatType ? formatType : "00.00");
|
|
925
|
+
}
|
|
926
|
+
catch (err) {
|
|
927
|
+
console.log("🚀 ~ file: util.js:89 ~ addition ~ error:", err);
|
|
928
|
+
return "";
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
exports.addition = addition;
|
|
932
|
+
var substraction = function (formatType, _a) {
|
|
933
|
+
var numbers1 = _a.numbers1, numbers2 = _a.numbers2;
|
|
934
|
+
try {
|
|
935
|
+
var actNumber1 = Array.isArray(numbers1)
|
|
936
|
+
? mathjs_1.default.add.apply(mathjs_1.default, numbers1) : numbers1;
|
|
937
|
+
var actNumber2 = Array.isArray(numbers2)
|
|
938
|
+
? mathjs_1.default.add.apply(mathjs_1.default, numbers2) : numbers2;
|
|
939
|
+
return (0, numeral_1.default)(mathjs_1.default.subtract(actNumber1, actNumber2)).format(formatType ? formatType : "00.00");
|
|
940
|
+
}
|
|
941
|
+
catch (err) {
|
|
942
|
+
console.log("🚀 ~ file: util.js:202 ~ substraction ~ error:", err);
|
|
943
|
+
return "";
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
exports.substraction = substraction;
|
|
947
|
+
var average = function (formatType, _a) {
|
|
948
|
+
var numbers = _a.numbers;
|
|
949
|
+
try {
|
|
950
|
+
if (!Array.isArray(numbers)) {
|
|
951
|
+
numbers = [numbers];
|
|
952
|
+
}
|
|
953
|
+
numbers = numbers.map(function (number) { return (isNaN(number) ? 0 : number); });
|
|
954
|
+
var allNumbers = (0, exports.validateNumbers)(numbers);
|
|
955
|
+
return (0, numeral_1.default)(mathjs_1.default.mean.apply(mathjs_1.default, allNumbers)).format(formatType ? formatType : "00.00");
|
|
956
|
+
}
|
|
957
|
+
catch (err) {
|
|
958
|
+
console.log("🚀 ~ file: util.js:98 ~ average ~ error:", err);
|
|
959
|
+
return "";
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
exports.average = average;
|
|
963
|
+
var multiply = function (formatType, _a) {
|
|
964
|
+
var numbers = _a.numbers;
|
|
965
|
+
try {
|
|
966
|
+
if (!Array.isArray(numbers)) {
|
|
967
|
+
numbers = [numbers, 1];
|
|
968
|
+
}
|
|
969
|
+
numbers = numbers.map(function (number) { return (isNaN(number) ? 1 : number); });
|
|
970
|
+
var allNumbers = (0, exports.validateNumbers)(numbers);
|
|
971
|
+
return (0, numeral_1.default)(mathjs_1.default.multiply.apply(mathjs_1.default, allNumbers)).format(formatType ? formatType : "00.00");
|
|
972
|
+
}
|
|
973
|
+
catch (err) {
|
|
974
|
+
console.log("🚀 ~ file: util.js:106 ~ multiply ~ error:", err);
|
|
975
|
+
return "";
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
exports.multiply = multiply;
|
|
979
|
+
var divide = function (formatType, _a) {
|
|
980
|
+
var number1 = _a.number1, number2 = _a.number2;
|
|
981
|
+
try {
|
|
982
|
+
var num1 = (0, exports.checkAndConvertNumber)(number1);
|
|
983
|
+
var num2 = (0, exports.checkAndConvertNumber)(number2);
|
|
984
|
+
return (0, numeral_1.default)(mathjs_1.default.divide(num1, num2)).format(formatType ? formatType : "00.00");
|
|
985
|
+
}
|
|
986
|
+
catch (err) {
|
|
987
|
+
console.log("🚀 ~ file: util.js:114 ~ divide ~ error:", err);
|
|
988
|
+
return "";
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
exports.divide = divide;
|
|
992
|
+
var evaluateExpression = function (expression, data, user, formatType, envConstants) {
|
|
993
|
+
expression = expression
|
|
994
|
+
? (0, exports.getSpecialCharectorReplacedExpression)(expression)
|
|
995
|
+
: " ";
|
|
996
|
+
var replacedExpression = (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
|
|
997
|
+
try {
|
|
998
|
+
return (0, numeral_1.default)(mathjs_1.default.evaluate(replacedExpression)).format(formatType ? formatType : "00.00");
|
|
999
|
+
}
|
|
1000
|
+
catch (err) {
|
|
1001
|
+
return "";
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
exports.evaluateExpression = evaluateExpression;
|
|
1005
|
+
var evaluateCurrency = function (formatType, subject, currency, position, maxFraction) {
|
|
1006
|
+
try {
|
|
1007
|
+
if (!subject)
|
|
1008
|
+
subject = 0;
|
|
1009
|
+
if (!maxFraction && maxFraction !== 0)
|
|
1010
|
+
maxFraction = 2;
|
|
1011
|
+
var multiplier = Math.pow(10, maxFraction || 0);
|
|
1012
|
+
var digit = Math.round(subject * multiplier) / multiplier;
|
|
1013
|
+
subject = new Intl.NumberFormat(formatType, {
|
|
1014
|
+
minimumFractionDigits: maxFraction,
|
|
1015
|
+
}).format(digit);
|
|
1016
|
+
switch (position) {
|
|
1017
|
+
case "FRONT":
|
|
1018
|
+
return "".concat(currency).concat(subject);
|
|
1019
|
+
case "FRONT_WITH_SPACE":
|
|
1020
|
+
return "".concat(currency, " ").concat(subject);
|
|
1021
|
+
case "BACK":
|
|
1022
|
+
return "".concat(subject).concat(currency);
|
|
1023
|
+
case "BACK_WITH_SPACE":
|
|
1024
|
+
return "".concat(subject, " ").concat(currency);
|
|
1025
|
+
default:
|
|
1026
|
+
return "";
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
catch (error) {
|
|
1030
|
+
return "";
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
exports.evaluateCurrency = evaluateCurrency;
|
|
1034
|
+
var evaluateJSLogic = function (expression, data, user, envConstants) {
|
|
1035
|
+
expression = expression
|
|
1036
|
+
? (0, exports.getSpecialCharectorReplacedExpression)(expression)
|
|
1037
|
+
: " ";
|
|
1038
|
+
var replacedExpression = (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
|
|
1039
|
+
try {
|
|
1040
|
+
var replacedExpressionFunction = new Function(replacedExpression.toString());
|
|
1041
|
+
return replacedExpressionFunction();
|
|
1042
|
+
}
|
|
1043
|
+
catch (err) {
|
|
1044
|
+
return "";
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
exports.evaluateJSLogic = evaluateJSLogic;
|
|
1048
|
+
var formatDate = function (formatType, datentime, timezone, unixType, offset) {
|
|
1049
|
+
if (offset === void 0) { offset = false; }
|
|
1050
|
+
var formatDateNTime = unixType && unixType === "SEC"
|
|
1051
|
+
? (0, moment_1.default)(datentime * 1000)
|
|
1052
|
+
: (0, moment_1.default)(datentime);
|
|
1053
|
+
if (offset) {
|
|
1054
|
+
formatDateNTime = formatDateNTime.utcOffset(timezone);
|
|
1055
|
+
}
|
|
1056
|
+
if (formatType === "FROM_NOW") {
|
|
1057
|
+
return datentime ? formatDateNTime.fromNow() : "";
|
|
1058
|
+
}
|
|
1059
|
+
return datentime ? formatDateNTime.format(formatType) : "";
|
|
1060
|
+
};
|
|
1061
|
+
exports.formatDate = formatDate;
|
|
1062
|
+
var dateDifference = function (formatType, datentime1, datentime2, timezone) {
|
|
1063
|
+
var result = "";
|
|
1064
|
+
var dateExist = !datentime1 || !datentime2;
|
|
1065
|
+
var firstDate = datentime1 === "CURRENT_DATE_TIME"
|
|
1066
|
+
? (0, moment_1.default)().utcOffset(timezone)
|
|
1067
|
+
: (0, moment_1.default)(datentime1).utcOffset(timezone);
|
|
1068
|
+
var secondDate = datentime2 === "CURRENT_DATE_TIME"
|
|
1069
|
+
? (0, moment_1.default)().utcOffset(timezone)
|
|
1070
|
+
: (0, moment_1.default)(datentime2).utcOffset(timezone);
|
|
1071
|
+
var patterns = formatType.split(",");
|
|
1072
|
+
patterns.forEach(function (format, i) {
|
|
1073
|
+
var diff = firstDate.diff(secondDate, format);
|
|
1074
|
+
if (diff < 0) {
|
|
1075
|
+
firstDate.subtract(diff, format);
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
secondDate.add(diff, format);
|
|
1079
|
+
}
|
|
1080
|
+
result =
|
|
1081
|
+
result +
|
|
1082
|
+
"".concat(Math.abs(dateExist ? 0 : diff), " ").concat(format.charAt(0).toUpperCase() + format.slice(1)).concat(i === patterns.length - 1 ? "" : ",", " ");
|
|
1083
|
+
});
|
|
1084
|
+
return result;
|
|
1085
|
+
};
|
|
1086
|
+
exports.dateDifference = dateDifference;
|
|
1087
|
+
var mergeObjects = function (arrayOfObjects, data, user, tenant, userSetting, subTenant, sessionValue, envConstants, sessionFormValue, dataTransferObject, localStorageValue, cookiesValue) {
|
|
1088
|
+
if (data === void 0) { data = null; }
|
|
1089
|
+
if (user === void 0) { user = null; }
|
|
1090
|
+
if (tenant === void 0) { tenant = null; }
|
|
1091
|
+
if (userSetting === void 0) { userSetting = null; }
|
|
1092
|
+
if (subTenant === void 0) { subTenant = null; }
|
|
1093
|
+
if (sessionValue === void 0) { sessionValue = null; }
|
|
1094
|
+
if (envConstants === void 0) { envConstants = null; }
|
|
1095
|
+
if (sessionFormValue === void 0) { sessionFormValue = null; }
|
|
1096
|
+
if (dataTransferObject === void 0) { dataTransferObject = {}; }
|
|
1097
|
+
if (localStorageValue === void 0) { localStorageValue = {}; }
|
|
1098
|
+
if (cookiesValue === void 0) { cookiesValue = {}; }
|
|
1099
|
+
var object = {};
|
|
1100
|
+
arrayOfObjects.map(function (x) {
|
|
1101
|
+
var value = x.value;
|
|
1102
|
+
value = (0, exports.replaceTransferObjectValueIntoExpression)(value, dataTransferObject);
|
|
1103
|
+
value =
|
|
1104
|
+
data ||
|
|
1105
|
+
user ||
|
|
1106
|
+
tenant ||
|
|
1107
|
+
sessionValue ||
|
|
1108
|
+
envConstants ||
|
|
1109
|
+
sessionFormValue ||
|
|
1110
|
+
localStorageValue ||
|
|
1111
|
+
cookiesValue ||
|
|
1112
|
+
userSetting ||
|
|
1113
|
+
subTenant
|
|
1114
|
+
? (0, exports.replaceDataValueIntoExpression)(value, data, user, tenant, userSetting, subTenant, sessionValue, envConstants, sessionFormValue, localStorageValue, cookiesValue)
|
|
1115
|
+
: value;
|
|
1116
|
+
object[x.key] = value;
|
|
1117
|
+
});
|
|
1118
|
+
console.log("object", object);
|
|
1119
|
+
return object;
|
|
1120
|
+
};
|
|
1121
|
+
exports.mergeObjects = mergeObjects;
|
|
1122
|
+
var getFindQuery = function (dataSourceType, item, customKey) {
|
|
1123
|
+
var _a, _b;
|
|
1124
|
+
if (customKey === void 0) { customKey = ""; }
|
|
1125
|
+
if (customKey) {
|
|
1126
|
+
return _a = {}, _a[customKey] = item[customKey], _a;
|
|
1127
|
+
}
|
|
1128
|
+
return _b = {}, _b[drapcode_constant_1.REST_API_PRIMAREY_KEY] = item[drapcode_constant_1.REST_API_PRIMAREY_KEY], _b;
|
|
1129
|
+
// switch (dataSourceType) {
|
|
1130
|
+
// default:
|
|
1131
|
+
// return {};
|
|
1132
|
+
// }
|
|
1133
|
+
};
|
|
1134
|
+
exports.getFindQuery = getFindQuery;
|
|
1135
|
+
var getFileObjectList = function (fileUrls, projectId) {
|
|
1136
|
+
var result = [];
|
|
1137
|
+
fileUrls.forEach(function (url) {
|
|
1138
|
+
var urlSplits = url.split("?")[0].split("/");
|
|
1139
|
+
var fileName = urlSplits[urlSplits.length - 1];
|
|
1140
|
+
var extension = fileName.substring(fileName.lastIndexOf("."));
|
|
1141
|
+
var mimetype = mime_types_1.default.lookup(extension) || "application/octet-stream";
|
|
1142
|
+
console.log(mimetype);
|
|
1143
|
+
var fileJson = {
|
|
1144
|
+
uuid: (0, uuid_2.v4)(),
|
|
1145
|
+
originalName: fileName,
|
|
1146
|
+
contentType: mime_types_1.default.contentType(mimetype) || "application/octet-stream",
|
|
1147
|
+
mimeType: mimetype,
|
|
1148
|
+
projectId: projectId,
|
|
1149
|
+
isExternalUrl: true,
|
|
1150
|
+
url: url,
|
|
1151
|
+
};
|
|
1152
|
+
result.push(fileJson);
|
|
1153
|
+
});
|
|
1154
|
+
return result;
|
|
1155
|
+
};
|
|
1156
|
+
exports.getFileObjectList = getFileObjectList;
|
|
1157
|
+
var getItemDataForArrayFields = function (item, dataSourceItemKey) {
|
|
1158
|
+
if (dataSourceItemKey.indexOf(".") != -1) {
|
|
1159
|
+
var parentKey = dataSourceItemKey.substring(0, dataSourceItemKey.lastIndexOf("."));
|
|
1160
|
+
var parenteItemData = lodash_1.default.get(item, parentKey);
|
|
1161
|
+
if (Array.isArray(parenteItemData)) {
|
|
1162
|
+
var lastLevelKey_1 = dataSourceItemKey.substring(dataSourceItemKey.lastIndexOf(".") + 1);
|
|
1163
|
+
var itemFieldData = parenteItemData.map(function (e) { return e[lastLevelKey_1]; });
|
|
1164
|
+
return itemFieldData;
|
|
1165
|
+
}
|
|
1166
|
+
else {
|
|
1167
|
+
var itemFieldData = lodash_1.default.get(item, dataSourceItemKey);
|
|
1168
|
+
return itemFieldData ? (0, exports.convertItemToArray)(itemFieldData) : [];
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
else {
|
|
1172
|
+
var itemFieldData = lodash_1.default.get(item, dataSourceItemKey);
|
|
1173
|
+
return itemFieldData ? (0, exports.convertItemToArray)(itemFieldData) : [];
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
exports.getItemDataForArrayFields = getItemDataForArrayFields;
|
|
1177
|
+
var getMappingObjKey = function (collectionMapping, fieldName) {
|
|
1178
|
+
if (collectionMapping === void 0) { collectionMapping = {}; }
|
|
1179
|
+
if (typeof collectionMapping[fieldName] === "object") {
|
|
1180
|
+
return collectionMapping[fieldName].dataSourceField;
|
|
1181
|
+
}
|
|
1182
|
+
else {
|
|
1183
|
+
return collectionMapping[fieldName];
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
exports.getMappingObjKey = getMappingObjKey;
|
|
1187
|
+
var getFieldSchemaForDataSourcePrimaryId = function (dataSourceType) {
|
|
1188
|
+
return getPrimaryFieldSchema("Data Source Rest API Primary Id", drapcode_constant_1.REST_API_PRIMAREY_KEY);
|
|
1189
|
+
};
|
|
1190
|
+
exports.getFieldSchemaForDataSourcePrimaryId = getFieldSchemaForDataSourcePrimaryId;
|
|
1191
|
+
var getPrimaryFieldNameOfDataSource = function (dataSourceType) {
|
|
1192
|
+
return drapcode_constant_1.REST_API_PRIMAREY_KEY;
|
|
1193
|
+
};
|
|
1194
|
+
exports.getPrimaryFieldNameOfDataSource = getPrimaryFieldNameOfDataSource;
|
|
1195
|
+
var getPrimaryFieldSchema = function (fieldTitle, fieldName) { return ({
|
|
1196
|
+
required: false,
|
|
1197
|
+
staticOptions: [],
|
|
1198
|
+
unique: true,
|
|
1199
|
+
isMultiSelect: false,
|
|
1200
|
+
isPluginField: false,
|
|
1201
|
+
fieldTitle: {
|
|
1202
|
+
en: fieldTitle,
|
|
1203
|
+
},
|
|
1204
|
+
type: "text",
|
|
1205
|
+
placeholder: {
|
|
1206
|
+
en: fieldTitle,
|
|
1207
|
+
},
|
|
1208
|
+
validation: {
|
|
1209
|
+
min: null,
|
|
1210
|
+
max: null,
|
|
1211
|
+
regex: "",
|
|
1212
|
+
allowedFileTypes: [],
|
|
1213
|
+
noAllowedFiles: 1,
|
|
1214
|
+
},
|
|
1215
|
+
refCollection: {
|
|
1216
|
+
collectionName: "",
|
|
1217
|
+
collectionField: "",
|
|
1218
|
+
displayType: "dropdown",
|
|
1219
|
+
parentCollectionField: "",
|
|
1220
|
+
isShowAsText: false,
|
|
1221
|
+
},
|
|
1222
|
+
extraFieldSetting: {
|
|
1223
|
+
dateDisplayType: "date",
|
|
1224
|
+
textareaDisplayType: "text-area",
|
|
1225
|
+
},
|
|
1226
|
+
fieldName: fieldName,
|
|
1227
|
+
}); };
|
|
1228
|
+
var checkFieldValueType = function (val) {
|
|
1229
|
+
return (val.startsWith(drapcode_constant_1.CURRENT_USER_LOWER) ||
|
|
1230
|
+
val.startsWith(drapcode_constant_1.CURRENT_SESSION) ||
|
|
1231
|
+
val.startsWith(drapcode_constant_1.SESSION_STORAGE) ||
|
|
1232
|
+
val.startsWith(drapcode_constant_1.LOCAL_STORAGE) ||
|
|
1233
|
+
val.startsWith(drapcode_constant_1.COOKIES) ||
|
|
1234
|
+
val.startsWith(drapcode_constant_1.FORM_DATA_SESSION) ||
|
|
1235
|
+
val.startsWith(drapcode_constant_1.ENVIRONMENT_VARIABLE) ||
|
|
1236
|
+
val.startsWith(drapcode_constant_1.PROJECT_CONSTANTS_PREFIX));
|
|
1237
|
+
};
|
|
1238
|
+
exports.checkFieldValueType = checkFieldValueType;
|
|
1239
|
+
var replaceValuesFromObjArr = function (dataArr, mappingArray) {
|
|
1240
|
+
return dataArr.map(function (data) {
|
|
1241
|
+
mappingArray.map(function (mapping) {
|
|
1242
|
+
var dataValue = data.value.replace(/{{(.*?)}}/g, "$1");
|
|
1243
|
+
var mappingValue = mapping[dataValue];
|
|
1244
|
+
if (mappingValue) {
|
|
1245
|
+
data.value = data.value.replace(data.value, mappingValue);
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
return data;
|
|
1249
|
+
});
|
|
1250
|
+
};
|
|
1251
|
+
exports.replaceValuesFromObjArr = replaceValuesFromObjArr;
|
|
1252
|
+
var replaceValuesFromRequestMapping = function (dataArr, mappingArray) {
|
|
1253
|
+
return dataArr.map(function (data) {
|
|
1254
|
+
mappingArray.forEach(function (mapping) {
|
|
1255
|
+
if (data.value.includes(mapping.value))
|
|
1256
|
+
data.value = data.value.replace(mapping.value, mapping.key);
|
|
1257
|
+
});
|
|
1258
|
+
return data;
|
|
1259
|
+
});
|
|
1260
|
+
};
|
|
1261
|
+
exports.replaceValuesFromRequestMapping = replaceValuesFromRequestMapping;
|
|
1262
|
+
var getAwsSignature = function (axiosConfig, awsSignPluginConfig) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1263
|
+
var response, method, headers, url, data, parsedUrl, payload, accessKeyId, secretAccessKey, region, service, signedRequest;
|
|
1264
|
+
return __generator(this, function (_a) {
|
|
1265
|
+
response = { error: "", data: {} };
|
|
1266
|
+
method = axiosConfig.method, headers = axiosConfig.headers, url = axiosConfig.url, data = axiosConfig.data;
|
|
1267
|
+
parsedUrl = new URL(url);
|
|
1268
|
+
payload = JSON.stringify(data);
|
|
1269
|
+
if (awsSignPluginConfig) {
|
|
1270
|
+
accessKeyId = awsSignPluginConfig.accessKeyId, secretAccessKey = awsSignPluginConfig.secretAccessKey, region = awsSignPluginConfig.region, service = awsSignPluginConfig.service;
|
|
1271
|
+
signedRequest = (0, aws4_1.sign)({
|
|
1272
|
+
method: method,
|
|
1273
|
+
service: service,
|
|
1274
|
+
region: region,
|
|
1275
|
+
host: parsedUrl.host,
|
|
1276
|
+
headers: headers,
|
|
1277
|
+
body: payload,
|
|
1278
|
+
}, { accessKeyId: accessKeyId, secretAccessKey: secretAccessKey });
|
|
1279
|
+
response.data = signedRequest;
|
|
1280
|
+
return [2 /*return*/, response];
|
|
1281
|
+
}
|
|
1282
|
+
else
|
|
1283
|
+
response.error = "AWS Signature Plugin is not installed.";
|
|
1284
|
+
return [2 /*return*/, response];
|
|
1285
|
+
});
|
|
1286
|
+
}); };
|
|
1287
|
+
exports.getAwsSignature = getAwsSignature;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.78",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"author": "Drapcode",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"devDependencies": {
|
|
22
|
+
"@types/aws4": "^1.11.6",
|
|
22
23
|
"@types/dompurify": "^3.0.5",
|
|
23
24
|
"@types/jsdom": "^21.1.7",
|
|
24
25
|
"@types/lodash": "^4.14.179",
|
|
@@ -31,23 +32,27 @@
|
|
|
31
32
|
"@aws-sdk/client-kms": "^3.540.0",
|
|
32
33
|
"@aws-sdk/client-s3": "^3.499.0",
|
|
33
34
|
"@aws-sdk/lib-storage": "^3.499.0",
|
|
34
|
-
"@types/cookie-session": "^2.0.41",
|
|
35
35
|
"@types/express": "^4.17.7",
|
|
36
36
|
"@types/gm": "^1.25.4",
|
|
37
|
+
"@types/numeral": "^2.0.5",
|
|
38
|
+
"@types/showdown": "^2.0.6",
|
|
37
39
|
"@types/voca": "^1.4.2",
|
|
40
|
+
"aws4": "^1.13.2",
|
|
38
41
|
"axios": "^1.1.2",
|
|
39
42
|
"dompurify": "^3.1.7",
|
|
40
|
-
"drapcode-constant": "^1.
|
|
43
|
+
"drapcode-constant": "^1.7.0",
|
|
41
44
|
"drapcode-logger": "^1.3.4",
|
|
42
|
-
"drapcode-redis": "^1.2.
|
|
45
|
+
"drapcode-redis": "^1.2.5",
|
|
43
46
|
"exiftool-vendored": "^28.2.1",
|
|
44
47
|
"express": "^4.17.1",
|
|
45
48
|
"gm": "^1.25.0",
|
|
46
49
|
"jsdom": "^25.0.1",
|
|
47
50
|
"lodash": "^4.17.21",
|
|
51
|
+
"mathjs": "^14.4.0",
|
|
48
52
|
"mime-types": "^2.1.35",
|
|
49
53
|
"moment": "^2.29.0",
|
|
50
|
-
"
|
|
54
|
+
"numeral": "^2.0.6",
|
|
55
|
+
"showdown": "^2.1.0",
|
|
51
56
|
"svgo": "^3.3.2",
|
|
52
57
|
"uuid": "^8.3.2",
|
|
53
58
|
"voca": "^1.4.0"
|
|
File without changes
|