drapcode-utility 2.0.0 → 2.0.2
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/KMS.js +54 -102
- package/build/encryption/crypt.d.ts +4 -2
- package/build/encryption/crypt.js +76 -91
- package/build/encryption/file.d.ts +0 -2
- package/build/encryption/file.js +14 -130
- package/build/encryption/index.js +162 -334
- package/build/encryption/utility.js +7 -10
- package/build/errors/app-error.js +9 -27
- package/build/errors/axios-error.js +3 -3
- package/build/errors/bad-request-error.js +10 -28
- package/build/errors/custom-error.js +5 -23
- package/build/errors/not-found.js +9 -27
- package/build/format-fields/index.d.ts +0 -1
- package/build/format-fields/index.js +32 -65
- package/build/index.d.ts +1 -4
- package/build/index.js +1 -4
- package/build/middlewares/error-logger.d.ts +1 -1
- package/build/middlewares/error-logger.js +29 -29
- package/build/middlewares/redis/request-log.js +24 -74
- package/build/query/queryBuilder.d.ts +9 -0
- package/build/query/queryBuilder.js +567 -0
- package/build/utils/check-error.d.ts +15 -8
- package/build/utils/check-error.js +71 -160
- package/build/utils/common-util.d.ts +40 -39
- package/build/utils/common-util.js +60 -59
- package/build/utils/date-util.d.ts +28 -7
- package/build/utils/date-util.js +180 -127
- package/build/utils/file-util.d.ts +51 -6
- package/build/utils/file-util.js +36 -40
- package/build/utils/prepare-query.js +70 -43
- package/build/utils/project-util.d.ts +43 -5
- package/build/utils/project-util.js +176 -121
- package/build/utils/query-parser.d.ts +1 -1
- package/build/utils/query-parser.js +289 -342
- package/build/utils/query-utils.d.ts +2 -2
- package/build/utils/query-utils.js +103 -116
- package/build/utils/rest-client.js +236 -328
- package/build/utils/s3-util.js +238 -469
- package/build/utils/token.js +34 -81
- package/build/utils/util.d.ts +58 -13
- package/build/utils/util.js +424 -494
- package/build/utils/uuid-generator.d.ts +20 -1
- package/build/utils/uuid-generator.js +111 -47
- package/package.json +7 -5
- package/build/middlewares/interceptor-logger-new.d.ts +0 -2
- package/build/middlewares/interceptor-logger-new.js +0 -53
- package/build/middlewares/interceptor-logger.d.ts +0 -2
- package/build/middlewares/interceptor-logger.js +0 -52
- package/build/utils/query-parser-new.d.ts +0 -1
- package/build/utils/query-parser-new.js +0 -541
package/build/utils/util.js
CHANGED
|
@@ -1,91 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
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
|
-
};
|
|
49
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
-
var t = {};
|
|
51
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
-
t[p] = s[p];
|
|
53
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
-
t[p[i]] = s[p[i]];
|
|
57
|
-
}
|
|
58
|
-
return t;
|
|
59
|
-
};
|
|
60
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
61
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
62
|
-
if (ar || !(i in from)) {
|
|
63
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
64
|
-
ar[i] = from[i];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
68
|
-
};
|
|
69
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
70
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
71
4
|
};
|
|
72
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.
|
|
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 =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
6
|
+
exports.multiply = 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.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.dynamicSort = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = exports.nonFindQuery = void 0;
|
|
7
|
+
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 = void 0;
|
|
8
|
+
const drapcode_constant_1 = require("drapcode-constant");
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const showdown_1 = __importDefault(require("showdown"));
|
|
11
|
+
const format_fields_1 = require("../format-fields");
|
|
12
|
+
const uuid_1 = require("uuid");
|
|
13
|
+
const voca_1 = __importDefault(require("voca"));
|
|
14
|
+
const numeral_1 = __importDefault(require("numeral"));
|
|
15
|
+
const mathjs_1 = __importDefault(require("mathjs"));
|
|
16
|
+
const moment_1 = __importDefault(require("moment"));
|
|
17
|
+
const mime_types_1 = __importDefault(require("mime-types"));
|
|
18
|
+
const uuid_2 = require("uuid");
|
|
19
|
+
const aws4_1 = require("aws4");
|
|
20
|
+
exports.nonFindQuery = ["COUNT", "SUM", "AVG", "MIN", "MAX"];
|
|
21
|
+
// Constants
|
|
22
|
+
const DERIVED_FIELD_EXCLUDES = [
|
|
89
23
|
"formatType",
|
|
90
24
|
"restToLower",
|
|
91
25
|
"whitespace",
|
|
@@ -113,167 +47,210 @@ var derivedFieldExcludes = [
|
|
|
113
47
|
"elementToRender",
|
|
114
48
|
"indexNum",
|
|
115
49
|
];
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
50
|
+
const ENVIRONMENT_FIX_KEY = "environment_variable.";
|
|
51
|
+
const TENANT_FIX_KEY = "current_tenant.";
|
|
52
|
+
const PREFIXES = [
|
|
53
|
+
drapcode_constant_1.CURRENT_USER_LOWER,
|
|
54
|
+
drapcode_constant_1.CURRENT_SESSION,
|
|
55
|
+
drapcode_constant_1.SESSION_STORAGE,
|
|
56
|
+
drapcode_constant_1.LOCAL_STORAGE,
|
|
57
|
+
drapcode_constant_1.COOKIES,
|
|
58
|
+
drapcode_constant_1.FORM_DATA_SESSION,
|
|
59
|
+
drapcode_constant_1.ENVIRONMENT_VARIABLE,
|
|
60
|
+
drapcode_constant_1.PROJECT_CONSTANTS_PREFIX,
|
|
61
|
+
];
|
|
62
|
+
// State
|
|
63
|
+
const consoleState = {
|
|
64
|
+
isModified: false,
|
|
65
|
+
oldConsoleLog: null,
|
|
66
|
+
oldConsoleInfo: null,
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Validates a string for special characters and numbers
|
|
70
|
+
* @param str - The string to validate
|
|
71
|
+
* @returns Error message if invalid, false if valid
|
|
72
|
+
*/
|
|
73
|
+
const validateString = (str) => {
|
|
74
|
+
const specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
|
|
75
|
+
const isNumber = str.match(/\d+/g);
|
|
76
|
+
if (specialChar.test(str)) {
|
|
125
77
|
return "String should not contain special characters";
|
|
126
|
-
|
|
78
|
+
}
|
|
79
|
+
if (isNumber) {
|
|
127
80
|
return "String should not contain any number";
|
|
81
|
+
}
|
|
128
82
|
return false;
|
|
129
83
|
};
|
|
130
84
|
exports.validateString = validateString;
|
|
131
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Converts a string to camelCase
|
|
87
|
+
* @param str - The string to convert
|
|
88
|
+
* @returns The camelCase string
|
|
89
|
+
*/
|
|
90
|
+
const camelize = (str) => {
|
|
132
91
|
str = (0, exports.clearSpaceAndReformat)(str);
|
|
133
|
-
return str.replace(/(?:^\w|[A-Z]|\b\w)/g,
|
|
92
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
|
|
134
93
|
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
135
94
|
});
|
|
136
95
|
};
|
|
137
96
|
exports.camelize = camelize;
|
|
138
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Clears spaces and reformats a string
|
|
99
|
+
* @param text - The text to format
|
|
100
|
+
* @param separator - Optional separator to use
|
|
101
|
+
* @returns The formatted string
|
|
102
|
+
*/
|
|
103
|
+
const clearSpaceAndReformat = (text, separator) => {
|
|
139
104
|
if (!text) {
|
|
140
105
|
return "";
|
|
141
106
|
}
|
|
142
107
|
return text
|
|
143
108
|
.toString()
|
|
144
109
|
.toLowerCase()
|
|
145
|
-
.replace(/\s+/g, separator
|
|
110
|
+
.replace(/\s+/g, separator ?? "");
|
|
146
111
|
};
|
|
147
112
|
exports.clearSpaceAndReformat = clearSpaceAndReformat;
|
|
148
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Checks if an object is empty
|
|
115
|
+
* @param obj - The object to check
|
|
116
|
+
* @returns True if the object is empty
|
|
117
|
+
*/
|
|
118
|
+
const isEmpty = (obj) => {
|
|
149
119
|
return Object.keys(obj).length === 0;
|
|
150
120
|
};
|
|
151
121
|
exports.isEmpty = isEmpty;
|
|
152
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Checks if an object is empty and is a plain object
|
|
124
|
+
* @param object - The object to check
|
|
125
|
+
* @returns True if the object is empty and is a plain object
|
|
126
|
+
*/
|
|
127
|
+
const isEmptyObject = (object) => {
|
|
153
128
|
return (0, exports.isEmpty)(object) && object.constructor === Object;
|
|
154
129
|
};
|
|
155
130
|
exports.isEmptyObject = isEmptyObject;
|
|
156
|
-
|
|
157
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Checks if a value is an object
|
|
133
|
+
* @param item - The value to check
|
|
134
|
+
* @returns True if the value is an object
|
|
135
|
+
*/
|
|
136
|
+
const isObject = (item) => {
|
|
137
|
+
return item !== null && typeof item === "object" && !Array.isArray(item);
|
|
158
138
|
};
|
|
159
139
|
exports.isObject = isObject;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
? -1
|
|
175
|
-
: a[property].toLowerCase() > b[property].toLowerCase()
|
|
176
|
-
? 1
|
|
177
|
-
: 0;
|
|
178
|
-
}
|
|
140
|
+
/**
|
|
141
|
+
* Creates a dynamic sort function for an array
|
|
142
|
+
* @param property - The property to sort by
|
|
143
|
+
* @returns A sort function
|
|
144
|
+
*/
|
|
145
|
+
const dynamicSort = (property) => {
|
|
146
|
+
return (a, b) => {
|
|
147
|
+
const aValue = a[property];
|
|
148
|
+
const bValue = b[property];
|
|
149
|
+
if (!aValue ||
|
|
150
|
+
!bValue ||
|
|
151
|
+
aValue === "undefined" ||
|
|
152
|
+
bValue === "undefined") {
|
|
153
|
+
return 0;
|
|
179
154
|
}
|
|
180
|
-
|
|
181
|
-
|
|
155
|
+
if (typeof aValue === "number" || typeof bValue === "number") {
|
|
156
|
+
return aValue < bValue ? -1 : aValue > bValue ? 1 : 0;
|
|
182
157
|
}
|
|
183
|
-
|
|
158
|
+
const aStr = String(aValue).toLowerCase();
|
|
159
|
+
const bStr = String(bValue).toLowerCase();
|
|
160
|
+
return aStr < bStr ? -1 : aStr > bStr ? 1 : 0;
|
|
184
161
|
};
|
|
185
162
|
};
|
|
186
163
|
exports.dynamicSort = dynamicSort;
|
|
187
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Validates an email address
|
|
166
|
+
* @param email - The email to validate
|
|
167
|
+
* @returns True if the email is valid
|
|
168
|
+
*/
|
|
169
|
+
const validateEmail = (email) => {
|
|
188
170
|
if (!email) {
|
|
189
171
|
return false;
|
|
190
172
|
}
|
|
191
|
-
|
|
192
|
-
return
|
|
173
|
+
const regexCode = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/;
|
|
174
|
+
return regexCode.test(email);
|
|
193
175
|
};
|
|
194
176
|
exports.validateEmail = validateEmail;
|
|
195
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Validates a UUID string
|
|
179
|
+
* @param uuid - The UUID to validate
|
|
180
|
+
* @returns True if the UUID is valid
|
|
181
|
+
*/
|
|
182
|
+
const validateUuidString = (uuid) => {
|
|
196
183
|
if (!uuid)
|
|
197
184
|
return false;
|
|
198
|
-
|
|
199
|
-
return
|
|
185
|
+
const regexCode = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
|
|
186
|
+
return regexCode.test(uuid);
|
|
200
187
|
};
|
|
201
188
|
exports.validateUuidString = validateUuidString;
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
189
|
+
const expressionMap = {
|
|
190
|
+
" ": "##@@##@@##",
|
|
191
|
+
">": "##@@##@@@@",
|
|
192
|
+
"<": "@@@@##@@@@",
|
|
193
|
+
"\n": "U+000A",
|
|
194
|
+
'"': "U+0022",
|
|
195
|
+
"'": "U+0027",
|
|
196
|
+
};
|
|
197
|
+
// Helper to escape special regex characters
|
|
198
|
+
const escapeRegExp = (string) => {
|
|
199
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
200
|
+
};
|
|
201
|
+
// If you want to render HTML line breaks only (like in JSX innerHTML or a browser)
|
|
202
|
+
const getSpecialCharectorReplacedExpression = (expression) => {
|
|
203
|
+
return expressionToString(expression).replace(/\n/g, "<br/>");
|
|
208
204
|
};
|
|
209
205
|
exports.getSpecialCharectorReplacedExpression = getSpecialCharectorReplacedExpression;
|
|
210
|
-
|
|
211
|
-
return
|
|
212
|
-
.replace(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
.replace(/U\+0027/g, "'")
|
|
217
|
-
.replace(/U\+000A/g, "\n");
|
|
218
|
-
};
|
|
219
|
-
exports.expressionToString = expressionToString;
|
|
220
|
-
var stringToExpression = function (str) {
|
|
221
|
-
return str
|
|
222
|
-
.replace(/ /g, "##@@##@@##")
|
|
223
|
-
.replace(/>/g, "##@@##@@@@")
|
|
224
|
-
.replace(/</g, "@@@@##@@@@")
|
|
225
|
-
.replace(/\n/g, "U+000A")
|
|
226
|
-
.replace(/"/g, "U+0022")
|
|
227
|
-
.replace(/'/g, "U+0027");
|
|
228
|
-
};
|
|
229
|
-
exports.stringToExpression = stringToExpression;
|
|
230
|
-
var cleanCollectionAndFieldName = function (str) {
|
|
206
|
+
const expressionToString = (ex) => {
|
|
207
|
+
return Object.entries(expressionMap).reduce((acc, [char, token]) => {
|
|
208
|
+
return acc.replace(new RegExp(escapeRegExp(token), "g"), char);
|
|
209
|
+
}, ex);
|
|
210
|
+
};
|
|
211
|
+
const cleanCollectionAndFieldName = (str) => {
|
|
231
212
|
str = str.replace(/[^A-Za-z0-9\s_]/, "");
|
|
232
213
|
return str;
|
|
233
214
|
};
|
|
234
215
|
exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
|
|
235
|
-
|
|
236
|
-
|
|
216
|
+
const formatCollectionAndFieldName = (str) => {
|
|
217
|
+
let updateString = (0, exports.cleanCollectionAndFieldName)(str);
|
|
237
218
|
return (0, exports.clearSpaceAndReformat)(updateString.trim(), "_");
|
|
238
219
|
};
|
|
239
220
|
exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
|
|
240
|
-
|
|
241
|
-
if (
|
|
221
|
+
const restructureData = (data) => {
|
|
222
|
+
if (data == null)
|
|
242
223
|
return [];
|
|
243
|
-
var dataType = typeof data;
|
|
244
224
|
if (Array.isArray(data)) {
|
|
245
|
-
if (data.length)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
return data;
|
|
225
|
+
if (!data.length)
|
|
226
|
+
return [];
|
|
227
|
+
let firstEle = data[0];
|
|
228
|
+
if (typeof firstEle === "string" || typeof firstEle === "number") {
|
|
229
|
+
return data.map((el) => {
|
|
230
|
+
value: el;
|
|
231
|
+
});
|
|
255
232
|
}
|
|
256
|
-
return
|
|
233
|
+
return data;
|
|
257
234
|
}
|
|
258
235
|
else {
|
|
259
|
-
if (
|
|
236
|
+
if (typeof data === "string" || typeof data === "number") {
|
|
260
237
|
return [{ value: data }];
|
|
261
238
|
}
|
|
262
239
|
return [data];
|
|
263
240
|
}
|
|
264
241
|
};
|
|
265
242
|
exports.restructureData = restructureData;
|
|
266
|
-
|
|
243
|
+
const checkAndCompareValue = (input1, input2) => {
|
|
267
244
|
return Array.isArray(input2)
|
|
268
|
-
? (0, exports.arraysEqual)(input1, input2.map(
|
|
245
|
+
? (0, exports.arraysEqual)(input1, input2.map((key) => key.value))
|
|
269
246
|
: input1 === input2.value;
|
|
270
247
|
};
|
|
271
248
|
exports.checkAndCompareValue = checkAndCompareValue;
|
|
272
|
-
|
|
249
|
+
const arraysEqual = (array1, array2) => {
|
|
273
250
|
if (array1 instanceof Array && array2 instanceof Array) {
|
|
274
251
|
if (array1.length != array2.length)
|
|
275
252
|
return false;
|
|
276
|
-
for (
|
|
253
|
+
for (let i = 0; i < array1.length; i++ // assert each element equal
|
|
277
254
|
)
|
|
278
255
|
if (!(0, exports.arraysEqual)(array1[i], array2[i]))
|
|
279
256
|
return false;
|
|
@@ -284,47 +261,47 @@ var arraysEqual = function (array1, array2) {
|
|
|
284
261
|
}
|
|
285
262
|
};
|
|
286
263
|
exports.arraysEqual = arraysEqual;
|
|
287
|
-
|
|
264
|
+
const convertItemToArray = (itemValue) => {
|
|
288
265
|
if (Array.isArray(itemValue)) {
|
|
289
266
|
return itemValue;
|
|
290
267
|
}
|
|
291
268
|
return itemValue ? [itemValue] : [];
|
|
292
269
|
};
|
|
293
270
|
exports.convertItemToArray = convertItemToArray;
|
|
294
|
-
|
|
271
|
+
const validateAlphanumericString = (str) => {
|
|
295
272
|
if (/[^A-Za-z0-9\s_]/.test(str)) {
|
|
296
273
|
return "String should contain only numbers and letters";
|
|
297
274
|
}
|
|
298
275
|
return false;
|
|
299
276
|
};
|
|
300
277
|
exports.validateAlphanumericString = validateAlphanumericString;
|
|
301
|
-
|
|
278
|
+
const formatCustomCSSClasses = (customClasses) => {
|
|
302
279
|
if (!customClasses || !Array.isArray(customClasses)) {
|
|
303
280
|
return "";
|
|
304
281
|
}
|
|
305
|
-
|
|
306
|
-
customClasses.forEach(
|
|
282
|
+
let projectCustomCSSClassesData = "";
|
|
283
|
+
customClasses.forEach((element) => {
|
|
307
284
|
if (element.classProperty) {
|
|
308
|
-
|
|
309
|
-
|
|
285
|
+
const classWithProp = JSON.stringify(element.classProperty);
|
|
286
|
+
const unquotedClassWithProp = classWithProp
|
|
310
287
|
.replace(/"([^"]+)"/g, "$1")
|
|
311
288
|
.split(",")
|
|
312
289
|
.join(";");
|
|
313
|
-
projectCustomCSSClassesData +=
|
|
290
|
+
projectCustomCSSClassesData += `${element.class.startsWith(".") ? element.class : "." + element.class}${element.pseudoClass ? ":" + element.pseudoClass : ""}${unquotedClassWithProp} `;
|
|
314
291
|
}
|
|
315
292
|
});
|
|
316
293
|
return projectCustomCSSClassesData;
|
|
317
294
|
};
|
|
318
295
|
exports.formatCustomCSSClasses = formatCustomCSSClasses;
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
296
|
+
const replaceDataValueIntoExpression = (expression, data, user, tenant, userSetting, subTenant, sessionValue, envConstants, sessionFormValue, localStorageValue, cookiesValue) => {
|
|
297
|
+
const contentList = expression
|
|
298
|
+
.match(/{{(.*?)}}/g)
|
|
299
|
+
?.map((b) => b.replace(/{{(.*?)}}/g, "$1"));
|
|
323
300
|
console.log("1 replaceDataValueIntoExpression");
|
|
324
|
-
contentList
|
|
325
|
-
|
|
301
|
+
contentList?.forEach((prop) => {
|
|
302
|
+
const needle = `{{${prop}}}`;
|
|
326
303
|
console.log("needle :>> ", needle);
|
|
327
|
-
|
|
304
|
+
let dataOfItem = "";
|
|
328
305
|
if (prop.includes("current_user")) {
|
|
329
306
|
console.log("Current User");
|
|
330
307
|
prop = prop.replace("current_user.", "");
|
|
@@ -396,7 +373,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
396
373
|
console.log("Environment Variable");
|
|
397
374
|
prop = prop.replace("environment_variable.", "");
|
|
398
375
|
if (Object.keys(envConstants).length > 0) {
|
|
399
|
-
|
|
376
|
+
const selectedConstant = envConstants.find((constant) => constant.name === prop);
|
|
400
377
|
dataOfItem = selectedConstant ? selectedConstant.value : "";
|
|
401
378
|
}
|
|
402
379
|
}
|
|
@@ -415,12 +392,12 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
415
392
|
return expression;
|
|
416
393
|
};
|
|
417
394
|
exports.replaceDataValueIntoExpression = replaceDataValueIntoExpression;
|
|
418
|
-
|
|
419
|
-
|
|
395
|
+
const replaceValueInExpression = (needle, replacement, expression) => {
|
|
396
|
+
const match = new RegExp(needle, "ig");
|
|
420
397
|
replacement = replacement ? replacement : "";
|
|
421
398
|
return expression.replace(match, replacement);
|
|
422
399
|
};
|
|
423
|
-
|
|
400
|
+
const parseJsonString = (str) => {
|
|
424
401
|
try {
|
|
425
402
|
str = str
|
|
426
403
|
.replace(/\\n/g, "\\n")
|
|
@@ -442,28 +419,28 @@ var parseJsonString = function (str) {
|
|
|
442
419
|
}
|
|
443
420
|
};
|
|
444
421
|
exports.parseJsonString = parseJsonString;
|
|
445
|
-
|
|
446
|
-
|
|
422
|
+
const parseValueFromData = (data, fieldName) => {
|
|
423
|
+
let value = "";
|
|
447
424
|
if (fieldName && fieldName.includes(".")) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
for (
|
|
452
|
-
|
|
425
|
+
let fullNameParts = fieldName.split(".");
|
|
426
|
+
let prefix = "";
|
|
427
|
+
let stack = data || "";
|
|
428
|
+
for (let k = 0; k < fullNameParts.length; k++) {
|
|
429
|
+
prefix = fullNameParts[k];
|
|
453
430
|
if (Array.isArray(stack)) {
|
|
454
|
-
stack[
|
|
455
|
-
if (item[
|
|
456
|
-
return item[
|
|
431
|
+
stack[prefix] = stack.map((item) => {
|
|
432
|
+
if (item[prefix])
|
|
433
|
+
return item[prefix];
|
|
457
434
|
});
|
|
458
435
|
}
|
|
459
|
-
if (stack && stack[
|
|
460
|
-
stack[
|
|
436
|
+
if (stack && stack[prefix] === undefined) {
|
|
437
|
+
stack[prefix] = "";
|
|
461
438
|
}
|
|
462
|
-
stack = stack[
|
|
439
|
+
stack = stack[prefix];
|
|
463
440
|
}
|
|
464
441
|
value = stack ? stack : "";
|
|
465
442
|
if (Array.isArray(value)) {
|
|
466
|
-
value = value.filter(
|
|
443
|
+
value = value.filter(() => true);
|
|
467
444
|
}
|
|
468
445
|
}
|
|
469
446
|
else {
|
|
@@ -479,8 +456,8 @@ var parseValueFromData = function (data, fieldName) {
|
|
|
479
456
|
return value;
|
|
480
457
|
};
|
|
481
458
|
exports.parseValueFromData = parseValueFromData;
|
|
482
|
-
|
|
483
|
-
|
|
459
|
+
const unflattenObject = (obj) => {
|
|
460
|
+
let result = {}, temp, substrings, property, i;
|
|
484
461
|
for (property in obj) {
|
|
485
462
|
substrings = property.split(".");
|
|
486
463
|
temp = result;
|
|
@@ -500,14 +477,14 @@ var unflattenObject = function (obj) {
|
|
|
500
477
|
return result;
|
|
501
478
|
};
|
|
502
479
|
exports.unflattenObject = unflattenObject;
|
|
503
|
-
|
|
504
|
-
var _a;
|
|
480
|
+
const replaceTransferObjectValueIntoExpression = (expression, transferObject) => {
|
|
505
481
|
if (transferObject && Object.keys(transferObject).length > 0) {
|
|
506
|
-
|
|
507
|
-
.match(/{{(.*?)}}/g)
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
482
|
+
const contentList = expression
|
|
483
|
+
.match(/{{(.*?)}}/g)
|
|
484
|
+
?.map((b) => b.replace(/{{(.*?)}}/g, "$1"));
|
|
485
|
+
contentList?.forEach((prop) => {
|
|
486
|
+
const needle = `{{${prop}}}`;
|
|
487
|
+
let dataOfItem = "";
|
|
511
488
|
dataOfItem = transferObject[prop] ? transferObject[prop] : "";
|
|
512
489
|
expression = dataOfItem
|
|
513
490
|
? replaceValueInExpression(needle, dataOfItem, expression)
|
|
@@ -517,8 +494,8 @@ var replaceTransferObjectValueIntoExpression = function (expression, transferObj
|
|
|
517
494
|
return expression;
|
|
518
495
|
};
|
|
519
496
|
exports.replaceTransferObjectValueIntoExpression = replaceTransferObjectValueIntoExpression;
|
|
520
|
-
|
|
521
|
-
|
|
497
|
+
const removeMongoDbId = function (result) {
|
|
498
|
+
const removeIdRecursively = function (obj) {
|
|
522
499
|
if (Array.isArray(obj)) {
|
|
523
500
|
return obj.map(removeIdRecursively);
|
|
524
501
|
}
|
|
@@ -534,69 +511,65 @@ var removeMongoDbId = function (result) {
|
|
|
534
511
|
}
|
|
535
512
|
return obj;
|
|
536
513
|
};
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
return
|
|
514
|
+
const moveUuidToTopLevel = function (obj) {
|
|
515
|
+
const { uuid, ...rest } = obj;
|
|
516
|
+
return { uuid, ...removeIdRecursively(rest) };
|
|
540
517
|
};
|
|
541
518
|
return result.map(moveUuidToTopLevel);
|
|
542
519
|
};
|
|
543
520
|
exports.removeMongoDbId = removeMongoDbId;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
var refFields = processReferenceFieldInclude(refFieldsInclude);
|
|
554
|
-
var derivedFields = processDerivedFieldInclude(derivedFieldsInclude);
|
|
555
|
-
var extraField = __spreadArray(__spreadArray([], refFields, true), derivedFields, true).filter(function (value, index, array) { return array.indexOf(value) === index; });
|
|
556
|
-
result = __spreadArray(__spreadArray([], fieldsInclude, true), extraField, true);
|
|
521
|
+
const processFieldsInclude = (fieldsInclude) => {
|
|
522
|
+
let result = fieldsInclude;
|
|
523
|
+
const refFieldsInclude = fieldsInclude.filter((field) => field.startsWith("RF::"));
|
|
524
|
+
const derivedFieldsInclude = fieldsInclude.filter((field) => field.startsWith("DF::"));
|
|
525
|
+
fieldsInclude = fieldsInclude.filter((field) => !(field.startsWith("RF::") || field.startsWith("DF::")));
|
|
526
|
+
const refFields = processReferenceFieldInclude(refFieldsInclude);
|
|
527
|
+
const derivedFields = processDerivedFieldInclude(derivedFieldsInclude);
|
|
528
|
+
const extraField = [...refFields, ...derivedFields].filter((value, index, array) => array.indexOf(value) === index);
|
|
529
|
+
result = [...fieldsInclude, ...extraField];
|
|
557
530
|
return result;
|
|
558
531
|
};
|
|
559
532
|
exports.processFieldsInclude = processFieldsInclude;
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
refFieldsInclude.forEach(
|
|
563
|
-
|
|
533
|
+
const processReferenceFieldInclude = (refFieldsInclude) => {
|
|
534
|
+
let refFields = [];
|
|
535
|
+
refFieldsInclude.forEach((exField) => {
|
|
536
|
+
let field = exField.replace("RF::", "");
|
|
564
537
|
field = field.split(".")[0];
|
|
565
538
|
refFields.push(field);
|
|
566
539
|
});
|
|
567
540
|
return refFields;
|
|
568
541
|
};
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
derivedFieldsInclude.forEach(
|
|
572
|
-
|
|
542
|
+
const processDerivedFieldInclude = (derivedFieldsInclude) => {
|
|
543
|
+
let derivedFields = [];
|
|
544
|
+
derivedFieldsInclude.forEach((exField) => {
|
|
545
|
+
let derivedFieldStr = exField.replace("DF::", "");
|
|
573
546
|
derivedFieldStr = derivedFieldStr.replaceAll("*#*#", '"');
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
derivedFieldObj.args.forEach(
|
|
577
|
-
var _a;
|
|
547
|
+
const derivedFieldObj = JSON.parse(derivedFieldStr);
|
|
548
|
+
let fields = [];
|
|
549
|
+
derivedFieldObj.args.forEach((arg) => {
|
|
578
550
|
if (arg.name === "expression") {
|
|
579
|
-
|
|
580
|
-
.match(/{{(.*?)}}/g)
|
|
581
|
-
|
|
582
|
-
|
|
551
|
+
const needleList = arg.key
|
|
552
|
+
.match(/{{(.*?)}}/g)
|
|
553
|
+
?.map((b) => b.replace(/{{(.*?)}}/g, "$1"));
|
|
554
|
+
const tempFields = (0, exports.processFieldsInclude)(needleList);
|
|
555
|
+
fields = [...fields, ...tempFields];
|
|
583
556
|
}
|
|
584
|
-
else if (!
|
|
585
|
-
|
|
557
|
+
else if (!DERIVED_FIELD_EXCLUDES.includes(arg.name)) {
|
|
558
|
+
let tempFields = Array.isArray(arg.key) ? arg.key : [arg.key];
|
|
586
559
|
tempFields = (0, exports.processFieldsInclude)(tempFields);
|
|
587
|
-
fields =
|
|
560
|
+
fields = [...fields, ...tempFields];
|
|
588
561
|
}
|
|
589
562
|
});
|
|
590
|
-
derivedFields =
|
|
563
|
+
derivedFields = [...derivedFields, ...fields];
|
|
591
564
|
});
|
|
592
565
|
return derivedFields;
|
|
593
566
|
};
|
|
594
|
-
|
|
567
|
+
const replaceValueFromSource = (variableName, environment, tenant) => {
|
|
595
568
|
if (variableName && typeof variableName === "string") {
|
|
596
|
-
if (variableName.startsWith(
|
|
569
|
+
if (variableName.startsWith(ENVIRONMENT_FIX_KEY)) {
|
|
597
570
|
return replaceValueFromEnvironment(variableName, environment);
|
|
598
571
|
}
|
|
599
|
-
else if (variableName.startsWith(
|
|
572
|
+
else if (variableName.startsWith(TENANT_FIX_KEY)) {
|
|
600
573
|
return replaceValueFromTenant(variableName, tenant);
|
|
601
574
|
}
|
|
602
575
|
else {
|
|
@@ -608,41 +581,39 @@ var replaceValueFromSource = function (variableName, environment, tenant) {
|
|
|
608
581
|
}
|
|
609
582
|
};
|
|
610
583
|
exports.replaceValueFromSource = replaceValueFromSource;
|
|
611
|
-
|
|
584
|
+
const replaceValueFromEnvironment = (variableName, environment) => {
|
|
612
585
|
if (variableName &&
|
|
613
586
|
typeof variableName === "string" &&
|
|
614
|
-
variableName.startsWith(
|
|
587
|
+
variableName.startsWith(ENVIRONMENT_FIX_KEY) &&
|
|
615
588
|
environment &&
|
|
616
589
|
environment.constants) {
|
|
617
|
-
|
|
590
|
+
const envConstant = environment.constants.find((env) => env.name === variableName.replace(ENVIRONMENT_FIX_KEY, ""));
|
|
618
591
|
return envConstant.value;
|
|
619
592
|
}
|
|
620
593
|
else {
|
|
621
594
|
return variableName;
|
|
622
595
|
}
|
|
623
596
|
};
|
|
624
|
-
|
|
597
|
+
const replaceValueFromTenant = (variableName, tenant) => {
|
|
625
598
|
if (!tenant) {
|
|
626
599
|
return variableName;
|
|
627
600
|
}
|
|
628
|
-
variableName = variableName.replace(
|
|
601
|
+
variableName = variableName.replace(TENANT_FIX_KEY, "");
|
|
629
602
|
return lodash_1.default.get(tenant, variableName);
|
|
630
603
|
};
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
allFields.forEach(function (field) {
|
|
640
|
-
var fieldName = field.fieldName;
|
|
604
|
+
const fillDefaultValues = (collection, itemdata) => {
|
|
605
|
+
const filledItemData = { ...itemdata };
|
|
606
|
+
const fieldsToSkip = drapcode_constant_1.hiddenFormField;
|
|
607
|
+
const fieldTypesToSkip = [drapcode_constant_1.FieldTypes.boolean.id];
|
|
608
|
+
const allFields = collection.fields.filter((field) => !fieldsToSkip.includes(field.fieldName) &&
|
|
609
|
+
!fieldTypesToSkip.includes(field.type));
|
|
610
|
+
allFields.forEach((field) => {
|
|
611
|
+
const fieldName = field.fieldName;
|
|
641
612
|
if (!(fieldName in filledItemData) ||
|
|
642
613
|
filledItemData[fieldName] === "" ||
|
|
643
614
|
filledItemData[fieldName] === 0 ||
|
|
644
615
|
filledItemData[fieldName] === false) {
|
|
645
|
-
|
|
616
|
+
const formattedField = JSON.parse(JSON.stringify(field));
|
|
646
617
|
if (field.extraFieldSetting &&
|
|
647
618
|
"defaultValue" in formattedField.extraFieldSetting) {
|
|
648
619
|
filledItemData[fieldName] = assignFieldValue(formattedField, field, fieldName, filledItemData);
|
|
@@ -652,33 +623,30 @@ var fillDefaultValues = function (collection, itemdata) {
|
|
|
652
623
|
return filledItemData;
|
|
653
624
|
};
|
|
654
625
|
exports.fillDefaultValues = fillDefaultValues;
|
|
655
|
-
|
|
656
|
-
|
|
626
|
+
const assignFieldValue = (formattedField, field, fieldName, filledItemData) => {
|
|
627
|
+
let value = "";
|
|
657
628
|
value = formattedField.extraFieldSetting
|
|
658
629
|
? formattedField.extraFieldSetting.defaultValue
|
|
659
|
-
:
|
|
630
|
+
: filledItemData[fieldName];
|
|
660
631
|
value = (0, format_fields_1.getFormatFieldData)(value, field.type);
|
|
661
632
|
return value;
|
|
662
633
|
};
|
|
663
|
-
|
|
664
|
-
|
|
634
|
+
const validateData = (fields, data) => {
|
|
635
|
+
const errors = [];
|
|
665
636
|
fields
|
|
666
|
-
.filter(
|
|
667
|
-
.forEach(
|
|
668
|
-
|
|
669
|
-
if (fieldValue
|
|
670
|
-
fieldValue === undefined ||
|
|
671
|
-
typeof fieldValue === "undefined" ||
|
|
672
|
-
fieldValue.length <= 0) {
|
|
637
|
+
.filter((field) => field.encrypted === false)
|
|
638
|
+
.forEach((field) => {
|
|
639
|
+
let fieldValue = data[field.fieldName];
|
|
640
|
+
if (fieldValue == null || fieldValue.length <= 0) {
|
|
673
641
|
return;
|
|
674
642
|
}
|
|
675
|
-
|
|
643
|
+
const fieldTitle = field.fieldTitle.en || field.fieldTitle.get("en");
|
|
676
644
|
if (field.type === "file" && typeof fieldValue === "string") {
|
|
677
645
|
try {
|
|
678
646
|
fieldValue = JSON.parse(fieldValue);
|
|
679
647
|
}
|
|
680
648
|
catch (error) {
|
|
681
|
-
errors.push(
|
|
649
|
+
errors.push(`Error parsing ${fieldTitle}: ${error.message}`);
|
|
682
650
|
return;
|
|
683
651
|
}
|
|
684
652
|
}
|
|
@@ -687,24 +655,24 @@ var validateData = function (fields, data) {
|
|
|
687
655
|
if (typeof fieldValue !== "string" &&
|
|
688
656
|
typeof fieldValue !== "number" &&
|
|
689
657
|
Object.prototype.toString.call(fieldValue) !== "[object Date]") {
|
|
690
|
-
errors.push(
|
|
658
|
+
errors.push(`${fieldTitle} must be a string`);
|
|
691
659
|
}
|
|
692
660
|
break;
|
|
693
661
|
case "large_text":
|
|
694
662
|
case "color":
|
|
695
663
|
if (typeof fieldValue !== "string") {
|
|
696
|
-
errors.push(
|
|
664
|
+
errors.push(`${fieldTitle} must be a string`);
|
|
697
665
|
}
|
|
698
666
|
break;
|
|
699
667
|
case "uuid":
|
|
700
668
|
if (typeof fieldValue !== "string" || !(0, uuid_1.validate)(fieldValue)) {
|
|
701
|
-
errors.push(
|
|
669
|
+
errors.push(`${fieldTitle} must be a valid UUID string`);
|
|
702
670
|
}
|
|
703
671
|
break;
|
|
704
672
|
case "reference":
|
|
705
673
|
case "belongsTo":
|
|
706
674
|
if (Array.isArray(fieldValue)) {
|
|
707
|
-
|
|
675
|
+
const invalid = fieldValue.some((item) => {
|
|
708
676
|
if (typeof item === "string")
|
|
709
677
|
return false;
|
|
710
678
|
if (typeof item === "object" && typeof item.uuid === "string")
|
|
@@ -712,14 +680,14 @@ var validateData = function (fields, data) {
|
|
|
712
680
|
return true;
|
|
713
681
|
});
|
|
714
682
|
if (invalid) {
|
|
715
|
-
errors.push(
|
|
683
|
+
errors.push(`${fieldTitle} must be an array of UUID strings or objects with a uuid`);
|
|
716
684
|
}
|
|
717
685
|
}
|
|
718
686
|
else {
|
|
719
687
|
if (!(typeof fieldValue === "string" ||
|
|
720
688
|
(typeof fieldValue === "object" &&
|
|
721
|
-
typeof
|
|
722
|
-
errors.push(
|
|
689
|
+
typeof fieldValue?.uuid === "string"))) {
|
|
690
|
+
errors.push(`${fieldTitle} must be a UUID string or an object with a uuid`);
|
|
723
691
|
}
|
|
724
692
|
}
|
|
725
693
|
break;
|
|
@@ -727,27 +695,27 @@ var validateData = function (fields, data) {
|
|
|
727
695
|
case "updatedAt":
|
|
728
696
|
case "date":
|
|
729
697
|
if (fieldValue && isNaN(Date.parse(fieldValue))) {
|
|
730
|
-
errors.push(
|
|
698
|
+
errors.push(`${fieldTitle} must be a valid date`);
|
|
731
699
|
}
|
|
732
700
|
break;
|
|
733
701
|
case "boolean":
|
|
734
702
|
if (typeof fieldValue !== "boolean") {
|
|
735
|
-
errors.push(
|
|
703
|
+
errors.push(`${fieldTitle} must be a boolean`);
|
|
736
704
|
}
|
|
737
705
|
break;
|
|
738
706
|
case "email":
|
|
739
707
|
if (typeof fieldValue !== "string" ||
|
|
740
708
|
!/\S+@\S+\.\S+/.test(fieldValue)) {
|
|
741
|
-
errors.push(
|
|
709
|
+
errors.push(`${fieldTitle} must be a valid email address`);
|
|
742
710
|
break;
|
|
743
711
|
}
|
|
744
712
|
break;
|
|
745
713
|
case "tel":
|
|
746
|
-
|
|
747
|
-
|
|
714
|
+
const removedSpace = fieldValue.replace(/\s+/g, "");
|
|
715
|
+
const telPattern = /^\+?(\d{1,3})?[-]?(\(\d{1,4}\)|\d{1,4})[-]?(\d{1,4}[-]?\d{1,4}|\d{7,10})$/;
|
|
748
716
|
if (typeof removedSpace !== "string" ||
|
|
749
717
|
!telPattern.test(removedSpace)) {
|
|
750
|
-
errors.push(
|
|
718
|
+
errors.push(`${fieldTitle} must be a valid phone number`);
|
|
751
719
|
}
|
|
752
720
|
break;
|
|
753
721
|
case "static_option":
|
|
@@ -756,38 +724,36 @@ var validateData = function (fields, data) {
|
|
|
756
724
|
break;
|
|
757
725
|
}
|
|
758
726
|
else if (Array.isArray(fieldValue)) {
|
|
759
|
-
if (fieldValue.some(
|
|
760
|
-
errors.push(
|
|
727
|
+
if (fieldValue.some((item) => typeof item !== "string")) {
|
|
728
|
+
errors.push(`${fieldTitle} must be an array of strings`);
|
|
761
729
|
}
|
|
762
730
|
}
|
|
763
731
|
else {
|
|
764
|
-
errors.push(
|
|
732
|
+
errors.push(`${fieldTitle} must be a string or an array of strings`);
|
|
765
733
|
}
|
|
766
734
|
break;
|
|
767
735
|
case "url":
|
|
768
736
|
if (typeof fieldValue !== "string" || !(0, exports.validateUrl)(fieldValue)) {
|
|
769
|
-
errors.push(
|
|
737
|
+
errors.push(`${fieldTitle} must be a valid URL`);
|
|
770
738
|
}
|
|
771
739
|
break;
|
|
772
740
|
case "file":
|
|
773
741
|
if (Array.isArray(fieldValue)) {
|
|
774
|
-
if (fieldValue.some(
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
})) {
|
|
779
|
-
errors.push("".concat(fieldTitle, " must be an array of objects with 'key' property as string"));
|
|
742
|
+
if (fieldValue.some((item) => typeof item !== "object" ||
|
|
743
|
+
!item.key ||
|
|
744
|
+
typeof item.key !== "string")) {
|
|
745
|
+
errors.push(`${fieldTitle} must be an array of objects with 'key' property as string`);
|
|
780
746
|
}
|
|
781
747
|
}
|
|
782
748
|
else if (typeof fieldValue !== "object" ||
|
|
783
749
|
!fieldValue.key ||
|
|
784
750
|
typeof fieldValue.key !== "string") {
|
|
785
|
-
errors.push(
|
|
751
|
+
errors.push(`${fieldTitle} must be an object with 'key' property as string`);
|
|
786
752
|
}
|
|
787
753
|
break;
|
|
788
754
|
case "number":
|
|
789
755
|
if (isNaN(Number(fieldValue))) {
|
|
790
|
-
errors.push(
|
|
756
|
+
errors.push(`${fieldTitle} must be a valid number.`);
|
|
791
757
|
}
|
|
792
758
|
break;
|
|
793
759
|
default:
|
|
@@ -795,15 +761,15 @@ var validateData = function (fields, data) {
|
|
|
795
761
|
}
|
|
796
762
|
});
|
|
797
763
|
if (errors.length > 0) {
|
|
798
|
-
return { isValid: false, errors
|
|
764
|
+
return { isValid: false, errors };
|
|
799
765
|
}
|
|
800
766
|
else {
|
|
801
767
|
return { isValid: true, errors: [] };
|
|
802
768
|
}
|
|
803
769
|
};
|
|
804
770
|
exports.validateData = validateData;
|
|
805
|
-
|
|
806
|
-
|
|
771
|
+
const validateUrl = (url) => {
|
|
772
|
+
const pattern = new RegExp("^((ft|htt)ps?:\\/\\/)?" +
|
|
807
773
|
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" +
|
|
808
774
|
"((\\d{1,3}\\.){3}\\d{1,3}))" +
|
|
809
775
|
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" +
|
|
@@ -812,58 +778,58 @@ var validateUrl = function (url) {
|
|
|
812
778
|
return !!pattern.test(url);
|
|
813
779
|
};
|
|
814
780
|
exports.validateUrl = validateUrl;
|
|
815
|
-
|
|
816
|
-
if (enable &&
|
|
781
|
+
const toggleConsoleLogs = (enable) => {
|
|
782
|
+
if (enable && consoleState.isModified) {
|
|
817
783
|
console.log("==> Enabling console log|info...");
|
|
818
|
-
if (
|
|
819
|
-
console.log =
|
|
820
|
-
console.info =
|
|
821
|
-
|
|
822
|
-
console.log(
|
|
784
|
+
if (consoleState.oldConsoleLog && consoleState.oldConsoleInfo) {
|
|
785
|
+
console.log = consoleState.oldConsoleLog;
|
|
786
|
+
console.info = consoleState.oldConsoleInfo;
|
|
787
|
+
consoleState.isModified = false;
|
|
788
|
+
console.log(`==> Enabling Console log modified: ${consoleState.isModified}`);
|
|
823
789
|
}
|
|
824
790
|
}
|
|
825
|
-
else if (!enable && !
|
|
826
|
-
|
|
827
|
-
|
|
791
|
+
else if (!enable && !consoleState.isModified) {
|
|
792
|
+
consoleState.oldConsoleLog = console.log;
|
|
793
|
+
consoleState.oldConsoleInfo = console.info;
|
|
828
794
|
console.log("==> Disabling console log|info...");
|
|
829
795
|
console.log = function () { };
|
|
830
796
|
console.info = function () { };
|
|
831
|
-
|
|
832
|
-
console.log(
|
|
797
|
+
consoleState.isModified = true;
|
|
798
|
+
console.log(`==> Disabling Console log modified: ${consoleState.isModified}`);
|
|
833
799
|
}
|
|
834
800
|
};
|
|
835
801
|
exports.toggleConsoleLogs = toggleConsoleLogs;
|
|
836
802
|
// Utility function to replace '/' with '____'
|
|
837
|
-
|
|
838
|
-
return value && typeof value ===
|
|
839
|
-
? value.replace(/\//g,
|
|
803
|
+
const replaceSlashWithUnderscore = (value) => {
|
|
804
|
+
return value && typeof value === "string" && value.includes("/")
|
|
805
|
+
? value.replace(/\//g, "____")
|
|
840
806
|
: value;
|
|
841
807
|
};
|
|
842
808
|
exports.replaceSlashWithUnderscore = replaceSlashWithUnderscore;
|
|
843
809
|
// Utility function to replace '____' with '/'
|
|
844
|
-
|
|
845
|
-
return value && typeof value ===
|
|
846
|
-
? value.replace(/____/g,
|
|
810
|
+
const replaceUnderscoreWithSlash = (value) => {
|
|
811
|
+
return value && typeof value === "string" && value.includes("____")
|
|
812
|
+
? value.replace(/____/g, "/")
|
|
847
813
|
: value;
|
|
848
814
|
};
|
|
849
815
|
exports.replaceUnderscoreWithSlash = replaceUnderscoreWithSlash;
|
|
850
|
-
|
|
816
|
+
const capitalize = function (str, restToLower) {
|
|
851
817
|
return voca_1.default.capitalize(str, restToLower === "TRUE");
|
|
852
818
|
};
|
|
853
819
|
exports.capitalize = capitalize;
|
|
854
|
-
|
|
820
|
+
const lowerCase = function (subject) {
|
|
855
821
|
return voca_1.default.lowerCase(subject);
|
|
856
822
|
};
|
|
857
823
|
exports.lowerCase = lowerCase;
|
|
858
|
-
|
|
824
|
+
const upperCase = function (subject) {
|
|
859
825
|
return voca_1.default.upperCase(subject);
|
|
860
826
|
};
|
|
861
827
|
exports.upperCase = upperCase;
|
|
862
|
-
|
|
828
|
+
const slugify = function (subject) {
|
|
863
829
|
return voca_1.default.slugify(subject);
|
|
864
830
|
};
|
|
865
831
|
exports.slugify = slugify;
|
|
866
|
-
|
|
832
|
+
const trim = function (subject, whitespace, type) {
|
|
867
833
|
if (type === "LEFT") {
|
|
868
834
|
return voca_1.default.trimLeft(subject, whitespace);
|
|
869
835
|
}
|
|
@@ -875,57 +841,56 @@ var trim = function (subject, whitespace, type) {
|
|
|
875
841
|
}
|
|
876
842
|
};
|
|
877
843
|
exports.trim = trim;
|
|
878
|
-
|
|
844
|
+
const titleCase = function (subject, noSplitopt) {
|
|
879
845
|
return voca_1.default.titleCase(subject, [noSplitopt]);
|
|
880
846
|
};
|
|
881
847
|
exports.titleCase = titleCase;
|
|
882
|
-
|
|
848
|
+
const truncate = function (subject, length, endopt) {
|
|
883
849
|
return voca_1.default.truncate(subject, length, endopt);
|
|
884
850
|
};
|
|
885
851
|
exports.truncate = truncate;
|
|
886
|
-
|
|
852
|
+
const substr = function (subject, startLength, endLength) {
|
|
887
853
|
return voca_1.default.substr(subject, startLength, endLength);
|
|
888
854
|
};
|
|
889
855
|
exports.substr = substr;
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
856
|
+
const markdownToHtml = function (subject) {
|
|
857
|
+
const converter = new showdown_1.default.Converter({ tables: true });
|
|
858
|
+
const html = converter.makeHtml(subject);
|
|
893
859
|
return html;
|
|
894
860
|
};
|
|
895
861
|
exports.markdownToHtml = markdownToHtml;
|
|
896
|
-
|
|
862
|
+
const strJoin = function (dataArr, separator, startString, endString) {
|
|
897
863
|
separator = separator ? separator.replace(/##@@##@@##/g, " ") : " ";
|
|
898
864
|
dataArr = Array.isArray(dataArr) ? dataArr : [dataArr];
|
|
899
865
|
dataArr = dataArr.filter(Boolean);
|
|
900
|
-
return
|
|
866
|
+
return `${startString ? startString.replace(/##@@##@@##/g, " ") + separator : ""}${dataArr.join(separator)}${endString ? separator + endString.replace(/##@@##@@##/g, " ") : ""}`;
|
|
901
867
|
};
|
|
902
868
|
exports.strJoin = strJoin;
|
|
903
|
-
|
|
869
|
+
const evaluateCustomSentence = function (expression, data, user, envConstants) {
|
|
904
870
|
expression = expression
|
|
905
871
|
? (0, exports.getSpecialCharectorReplacedExpression)(expression)
|
|
906
872
|
: " ";
|
|
907
873
|
return (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
|
|
908
874
|
};
|
|
909
875
|
exports.evaluateCustomSentence = evaluateCustomSentence;
|
|
910
|
-
|
|
876
|
+
const checkAndConvertNumber = (number) => {
|
|
911
877
|
return lodash_1.default.isNumber(number) ? number : Number(number);
|
|
912
878
|
};
|
|
913
879
|
exports.checkAndConvertNumber = checkAndConvertNumber;
|
|
914
|
-
|
|
915
|
-
return numbers.map(
|
|
880
|
+
const validateNumbers = (numbers) => {
|
|
881
|
+
return numbers.map((number) => {
|
|
916
882
|
return (0, exports.checkAndConvertNumber)(number);
|
|
917
883
|
});
|
|
918
884
|
};
|
|
919
885
|
exports.validateNumbers = validateNumbers;
|
|
920
|
-
|
|
921
|
-
var numbers = _a.numbers;
|
|
886
|
+
const addition = function (formatType, { numbers }) {
|
|
922
887
|
try {
|
|
923
888
|
if (!Array.isArray(numbers)) {
|
|
924
889
|
numbers = [numbers, 0];
|
|
925
890
|
}
|
|
926
|
-
numbers = numbers.map(
|
|
927
|
-
|
|
928
|
-
return (0, numeral_1.default)(mathjs_1.default.add
|
|
891
|
+
numbers = numbers.map((number) => (isNaN(number) ? 0 : number));
|
|
892
|
+
const allNumbers = (0, exports.validateNumbers)(numbers);
|
|
893
|
+
return (0, numeral_1.default)(mathjs_1.default.add(...allNumbers)).format(formatType ? formatType : "00.00");
|
|
929
894
|
}
|
|
930
895
|
catch (err) {
|
|
931
896
|
console.log("🚀 ~ file: util.js:89 ~ addition ~ error:", err);
|
|
@@ -933,13 +898,14 @@ var addition = function (formatType, _a) {
|
|
|
933
898
|
}
|
|
934
899
|
};
|
|
935
900
|
exports.addition = addition;
|
|
936
|
-
|
|
937
|
-
var numbers1 = _a.numbers1, numbers2 = _a.numbers2;
|
|
901
|
+
const substraction = function (formatType, { numbers1, numbers2 }) {
|
|
938
902
|
try {
|
|
939
|
-
|
|
940
|
-
? mathjs_1.default.add
|
|
941
|
-
|
|
942
|
-
|
|
903
|
+
const actNumber1 = Array.isArray(numbers1)
|
|
904
|
+
? mathjs_1.default.add(...numbers1)
|
|
905
|
+
: numbers1;
|
|
906
|
+
const actNumber2 = Array.isArray(numbers2)
|
|
907
|
+
? mathjs_1.default.add(...numbers2)
|
|
908
|
+
: numbers2;
|
|
943
909
|
return (0, numeral_1.default)(mathjs_1.default.subtract(actNumber1, actNumber2)).format(formatType ? formatType : "00.00");
|
|
944
910
|
}
|
|
945
911
|
catch (err) {
|
|
@@ -948,15 +914,14 @@ var substraction = function (formatType, _a) {
|
|
|
948
914
|
}
|
|
949
915
|
};
|
|
950
916
|
exports.substraction = substraction;
|
|
951
|
-
|
|
952
|
-
var numbers = _a.numbers;
|
|
917
|
+
const average = function (formatType, { numbers }) {
|
|
953
918
|
try {
|
|
954
919
|
if (!Array.isArray(numbers)) {
|
|
955
920
|
numbers = [numbers];
|
|
956
921
|
}
|
|
957
|
-
numbers = numbers.map(
|
|
958
|
-
|
|
959
|
-
return (0, numeral_1.default)(mathjs_1.default.mean
|
|
922
|
+
numbers = numbers.map((number) => (isNaN(number) ? 0 : number));
|
|
923
|
+
const allNumbers = (0, exports.validateNumbers)(numbers);
|
|
924
|
+
return (0, numeral_1.default)(mathjs_1.default.mean(...allNumbers)).format(formatType ? formatType : "00.00");
|
|
960
925
|
}
|
|
961
926
|
catch (err) {
|
|
962
927
|
console.log("🚀 ~ file: util.js:98 ~ average ~ error:", err);
|
|
@@ -964,15 +929,14 @@ var average = function (formatType, _a) {
|
|
|
964
929
|
}
|
|
965
930
|
};
|
|
966
931
|
exports.average = average;
|
|
967
|
-
|
|
968
|
-
var numbers = _a.numbers;
|
|
932
|
+
const multiply = function (formatType, { numbers }) {
|
|
969
933
|
try {
|
|
970
934
|
if (!Array.isArray(numbers)) {
|
|
971
935
|
numbers = [numbers, 1];
|
|
972
936
|
}
|
|
973
|
-
numbers = numbers.map(
|
|
974
|
-
|
|
975
|
-
return (0, numeral_1.default)(mathjs_1.default.multiply
|
|
937
|
+
numbers = numbers.map((number) => (isNaN(number) ? 1 : number));
|
|
938
|
+
const allNumbers = (0, exports.validateNumbers)(numbers);
|
|
939
|
+
return (0, numeral_1.default)(mathjs_1.default.multiply(...allNumbers)).format(formatType ? formatType : "00.00");
|
|
976
940
|
}
|
|
977
941
|
catch (err) {
|
|
978
942
|
console.log("🚀 ~ file: util.js:106 ~ multiply ~ error:", err);
|
|
@@ -980,11 +944,10 @@ var multiply = function (formatType, _a) {
|
|
|
980
944
|
}
|
|
981
945
|
};
|
|
982
946
|
exports.multiply = multiply;
|
|
983
|
-
|
|
984
|
-
var number1 = _a.number1, number2 = _a.number2;
|
|
947
|
+
const divide = function (formatType, { number1, number2 }) {
|
|
985
948
|
try {
|
|
986
|
-
|
|
987
|
-
|
|
949
|
+
const num1 = (0, exports.checkAndConvertNumber)(number1);
|
|
950
|
+
const num2 = (0, exports.checkAndConvertNumber)(number2);
|
|
988
951
|
return (0, numeral_1.default)(mathjs_1.default.divide(num1, num2)).format(formatType ? formatType : "00.00");
|
|
989
952
|
}
|
|
990
953
|
catch (err) {
|
|
@@ -993,11 +956,11 @@ var divide = function (formatType, _a) {
|
|
|
993
956
|
}
|
|
994
957
|
};
|
|
995
958
|
exports.divide = divide;
|
|
996
|
-
|
|
959
|
+
const evaluateExpression = function (expression, data, user, formatType, envConstants) {
|
|
997
960
|
expression = expression
|
|
998
961
|
? (0, exports.getSpecialCharectorReplacedExpression)(expression)
|
|
999
962
|
: " ";
|
|
1000
|
-
|
|
963
|
+
const replacedExpression = (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
|
|
1001
964
|
try {
|
|
1002
965
|
return (0, numeral_1.default)(mathjs_1.default.evaluate(replacedExpression)).format(formatType ? formatType : "00.00");
|
|
1003
966
|
}
|
|
@@ -1006,26 +969,26 @@ var evaluateExpression = function (expression, data, user, formatType, envConsta
|
|
|
1006
969
|
}
|
|
1007
970
|
};
|
|
1008
971
|
exports.evaluateExpression = evaluateExpression;
|
|
1009
|
-
|
|
972
|
+
const evaluateCurrency = function (formatType, subject, currency, position, maxFraction) {
|
|
1010
973
|
try {
|
|
1011
974
|
if (!subject)
|
|
1012
975
|
subject = 0;
|
|
1013
976
|
if (!maxFraction && maxFraction !== 0)
|
|
1014
977
|
maxFraction = 2;
|
|
1015
|
-
|
|
1016
|
-
|
|
978
|
+
const multiplier = Math.pow(10, maxFraction || 0);
|
|
979
|
+
const digit = Math.round(subject * multiplier) / multiplier;
|
|
1017
980
|
subject = new Intl.NumberFormat(formatType, {
|
|
1018
981
|
minimumFractionDigits: maxFraction,
|
|
1019
982
|
}).format(digit);
|
|
1020
983
|
switch (position) {
|
|
1021
984
|
case "FRONT":
|
|
1022
|
-
return
|
|
985
|
+
return `${currency}${subject}`;
|
|
1023
986
|
case "FRONT_WITH_SPACE":
|
|
1024
|
-
return
|
|
987
|
+
return `${currency} ${subject}`;
|
|
1025
988
|
case "BACK":
|
|
1026
|
-
return
|
|
989
|
+
return `${subject}${currency}`;
|
|
1027
990
|
case "BACK_WITH_SPACE":
|
|
1028
|
-
return
|
|
991
|
+
return `${subject} ${currency}`;
|
|
1029
992
|
default:
|
|
1030
993
|
return "";
|
|
1031
994
|
}
|
|
@@ -1035,13 +998,13 @@ var evaluateCurrency = function (formatType, subject, currency, position, maxFra
|
|
|
1035
998
|
}
|
|
1036
999
|
};
|
|
1037
1000
|
exports.evaluateCurrency = evaluateCurrency;
|
|
1038
|
-
|
|
1001
|
+
const evaluateJSLogic = function (expression, data, user, envConstants) {
|
|
1039
1002
|
expression = expression
|
|
1040
1003
|
? (0, exports.getSpecialCharectorReplacedExpression)(expression)
|
|
1041
1004
|
: " ";
|
|
1042
|
-
|
|
1005
|
+
const replacedExpression = (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
|
|
1043
1006
|
try {
|
|
1044
|
-
|
|
1007
|
+
const replacedExpressionFunction = new Function(replacedExpression.toString());
|
|
1045
1008
|
return replacedExpressionFunction();
|
|
1046
1009
|
}
|
|
1047
1010
|
catch (err) {
|
|
@@ -1049,9 +1012,8 @@ var evaluateJSLogic = function (expression, data, user, envConstants) {
|
|
|
1049
1012
|
}
|
|
1050
1013
|
};
|
|
1051
1014
|
exports.evaluateJSLogic = evaluateJSLogic;
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
var formatDateNTime = unixType && unixType === "SEC"
|
|
1015
|
+
const formatDate = function (formatType, datentime, timezone, unixType, offset = false) {
|
|
1016
|
+
let formatDateNTime = unixType && unixType === "SEC"
|
|
1055
1017
|
? (0, moment_1.default)(datentime * 1000)
|
|
1056
1018
|
: (0, moment_1.default)(datentime);
|
|
1057
1019
|
if (offset) {
|
|
@@ -1063,18 +1025,18 @@ var formatDate = function (formatType, datentime, timezone, unixType, offset) {
|
|
|
1063
1025
|
return datentime ? formatDateNTime.format(formatType) : "";
|
|
1064
1026
|
};
|
|
1065
1027
|
exports.formatDate = formatDate;
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1028
|
+
const dateDifference = (formatType, datentime1, datentime2, timezone) => {
|
|
1029
|
+
let result = "";
|
|
1030
|
+
const dateExist = !datentime1 || !datentime2;
|
|
1031
|
+
const firstDate = datentime1 === "CURRENT_DATE_TIME"
|
|
1070
1032
|
? (0, moment_1.default)().utcOffset(timezone)
|
|
1071
1033
|
: (0, moment_1.default)(datentime1).utcOffset(timezone);
|
|
1072
|
-
|
|
1034
|
+
const secondDate = datentime2 === "CURRENT_DATE_TIME"
|
|
1073
1035
|
? (0, moment_1.default)().utcOffset(timezone)
|
|
1074
1036
|
: (0, moment_1.default)(datentime2).utcOffset(timezone);
|
|
1075
|
-
|
|
1076
|
-
patterns.forEach(
|
|
1077
|
-
|
|
1037
|
+
const patterns = formatType.split(",");
|
|
1038
|
+
patterns.forEach((format, i) => {
|
|
1039
|
+
const diff = firstDate.diff(secondDate, format);
|
|
1078
1040
|
if (diff < 0) {
|
|
1079
1041
|
firstDate.subtract(diff, format);
|
|
1080
1042
|
}
|
|
@@ -1083,26 +1045,15 @@ var dateDifference = function (formatType, datentime1, datentime2, timezone) {
|
|
|
1083
1045
|
}
|
|
1084
1046
|
result =
|
|
1085
1047
|
result +
|
|
1086
|
-
|
|
1048
|
+
`${Math.abs(dateExist ? 0 : diff)} ${format.charAt(0).toUpperCase() + format.slice(1)}${i === patterns.length - 1 ? "" : ","} `;
|
|
1087
1049
|
});
|
|
1088
1050
|
return result;
|
|
1089
1051
|
};
|
|
1090
1052
|
exports.dateDifference = dateDifference;
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
if (userSetting === void 0) { userSetting = null; }
|
|
1096
|
-
if (subTenant === void 0) { subTenant = null; }
|
|
1097
|
-
if (sessionValue === void 0) { sessionValue = null; }
|
|
1098
|
-
if (envConstants === void 0) { envConstants = null; }
|
|
1099
|
-
if (sessionFormValue === void 0) { sessionFormValue = null; }
|
|
1100
|
-
if (dataTransferObject === void 0) { dataTransferObject = {}; }
|
|
1101
|
-
if (localStorageValue === void 0) { localStorageValue = {}; }
|
|
1102
|
-
if (cookiesValue === void 0) { cookiesValue = {}; }
|
|
1103
|
-
var object = {};
|
|
1104
|
-
arrayOfObjects.map(function (x) {
|
|
1105
|
-
var value = x.value;
|
|
1053
|
+
const mergeObjects = (arrayOfObjects, data = null, user = null, tenant = null, userSetting = null, subTenant = null, sessionValue = null, envConstants = null, sessionFormValue = null, dataTransferObject = {}, localStorageValue = {}, cookiesValue = {}) => {
|
|
1054
|
+
let object = {};
|
|
1055
|
+
arrayOfObjects.map((x) => {
|
|
1056
|
+
let value = x.value;
|
|
1106
1057
|
value = (0, exports.replaceTransferObjectValueIntoExpression)(value, dataTransferObject);
|
|
1107
1058
|
value =
|
|
1108
1059
|
data ||
|
|
@@ -1123,63 +1074,56 @@ var mergeObjects = function (arrayOfObjects, data, user, tenant, userSetting, su
|
|
|
1123
1074
|
return object;
|
|
1124
1075
|
};
|
|
1125
1076
|
exports.mergeObjects = mergeObjects;
|
|
1126
|
-
|
|
1127
|
-
var _a, _b;
|
|
1128
|
-
if (customKey === void 0) { customKey = ""; }
|
|
1077
|
+
const getFindQuery = (item, customKey = "") => {
|
|
1129
1078
|
if (customKey) {
|
|
1130
|
-
return
|
|
1079
|
+
return { [customKey]: item[customKey] };
|
|
1131
1080
|
}
|
|
1132
|
-
return
|
|
1133
|
-
// switch (dataSourceType) {
|
|
1134
|
-
// default:
|
|
1135
|
-
// return {};
|
|
1136
|
-
// }
|
|
1081
|
+
return { [drapcode_constant_1.REST_API_PRIMAREY_KEY]: item[drapcode_constant_1.REST_API_PRIMAREY_KEY] };
|
|
1137
1082
|
};
|
|
1138
1083
|
exports.getFindQuery = getFindQuery;
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
fileUrls.forEach(
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1084
|
+
const getFileObjectList = (fileUrls, projectId) => {
|
|
1085
|
+
const result = [];
|
|
1086
|
+
fileUrls.forEach((url) => {
|
|
1087
|
+
const urlSplits = url.split("?")[0].split("/");
|
|
1088
|
+
let fileName = urlSplits[urlSplits.length - 1];
|
|
1089
|
+
const extension = fileName.substring(fileName.lastIndexOf("."));
|
|
1090
|
+
let mimetype = mime_types_1.default.lookup(extension) || "application/octet-stream";
|
|
1146
1091
|
console.log(mimetype);
|
|
1147
|
-
|
|
1092
|
+
const fileJson = {
|
|
1148
1093
|
uuid: (0, uuid_2.v4)(),
|
|
1149
1094
|
originalName: fileName,
|
|
1150
1095
|
contentType: mime_types_1.default.contentType(mimetype) || "application/octet-stream",
|
|
1151
1096
|
mimeType: mimetype,
|
|
1152
|
-
projectId
|
|
1097
|
+
projectId,
|
|
1153
1098
|
isExternalUrl: true,
|
|
1154
|
-
url
|
|
1099
|
+
url,
|
|
1155
1100
|
};
|
|
1156
1101
|
result.push(fileJson);
|
|
1157
1102
|
});
|
|
1158
1103
|
return result;
|
|
1159
1104
|
};
|
|
1160
1105
|
exports.getFileObjectList = getFileObjectList;
|
|
1161
|
-
|
|
1106
|
+
const getItemDataForArrayFields = (item, dataSourceItemKey) => {
|
|
1162
1107
|
if (dataSourceItemKey.indexOf(".") != -1) {
|
|
1163
|
-
|
|
1164
|
-
|
|
1108
|
+
const parentKey = dataSourceItemKey.substring(0, dataSourceItemKey.lastIndexOf("."));
|
|
1109
|
+
const parenteItemData = lodash_1.default.get(item, parentKey);
|
|
1165
1110
|
if (Array.isArray(parenteItemData)) {
|
|
1166
|
-
|
|
1167
|
-
|
|
1111
|
+
const lastLevelKey = dataSourceItemKey.substring(dataSourceItemKey.lastIndexOf(".") + 1);
|
|
1112
|
+
const itemFieldData = parenteItemData.map((e) => e[lastLevelKey]);
|
|
1168
1113
|
return itemFieldData;
|
|
1169
1114
|
}
|
|
1170
1115
|
else {
|
|
1171
|
-
|
|
1116
|
+
const itemFieldData = lodash_1.default.get(item, dataSourceItemKey);
|
|
1172
1117
|
return itemFieldData ? (0, exports.convertItemToArray)(itemFieldData) : [];
|
|
1173
1118
|
}
|
|
1174
1119
|
}
|
|
1175
1120
|
else {
|
|
1176
|
-
|
|
1121
|
+
const itemFieldData = lodash_1.default.get(item, dataSourceItemKey);
|
|
1177
1122
|
return itemFieldData ? (0, exports.convertItemToArray)(itemFieldData) : [];
|
|
1178
1123
|
}
|
|
1179
1124
|
};
|
|
1180
1125
|
exports.getItemDataForArrayFields = getItemDataForArrayFields;
|
|
1181
|
-
|
|
1182
|
-
if (collectionMapping === void 0) { collectionMapping = {}; }
|
|
1126
|
+
const getMappingObjKey = (collectionMapping = {}, fieldName) => {
|
|
1183
1127
|
if (typeof collectionMapping[fieldName] === "object") {
|
|
1184
1128
|
return collectionMapping[fieldName].dataSourceField;
|
|
1185
1129
|
}
|
|
@@ -1188,15 +1132,13 @@ var getMappingObjKey = function (collectionMapping, fieldName) {
|
|
|
1188
1132
|
}
|
|
1189
1133
|
};
|
|
1190
1134
|
exports.getMappingObjKey = getMappingObjKey;
|
|
1191
|
-
|
|
1135
|
+
const getFieldSchemaForDataSourcePrimaryId = () => {
|
|
1192
1136
|
return getPrimaryFieldSchema("Data Source Rest API Primary Id", drapcode_constant_1.REST_API_PRIMAREY_KEY);
|
|
1193
1137
|
};
|
|
1194
1138
|
exports.getFieldSchemaForDataSourcePrimaryId = getFieldSchemaForDataSourcePrimaryId;
|
|
1195
|
-
|
|
1196
|
-
return drapcode_constant_1.REST_API_PRIMAREY_KEY;
|
|
1197
|
-
};
|
|
1139
|
+
const getPrimaryFieldNameOfDataSource = () => drapcode_constant_1.REST_API_PRIMAREY_KEY;
|
|
1198
1140
|
exports.getPrimaryFieldNameOfDataSource = getPrimaryFieldNameOfDataSource;
|
|
1199
|
-
|
|
1141
|
+
const getPrimaryFieldSchema = (fieldTitle, fieldName) => ({
|
|
1200
1142
|
required: false,
|
|
1201
1143
|
staticOptions: [],
|
|
1202
1144
|
unique: true,
|
|
@@ -1228,23 +1170,14 @@ var getPrimaryFieldSchema = function (fieldTitle, fieldName) { return ({
|
|
|
1228
1170
|
textareaDisplayType: "text-area",
|
|
1229
1171
|
},
|
|
1230
1172
|
fieldName: fieldName,
|
|
1231
|
-
});
|
|
1232
|
-
|
|
1233
|
-
return (val.startsWith(drapcode_constant_1.CURRENT_USER_LOWER) ||
|
|
1234
|
-
val.startsWith(drapcode_constant_1.CURRENT_SESSION) ||
|
|
1235
|
-
val.startsWith(drapcode_constant_1.SESSION_STORAGE) ||
|
|
1236
|
-
val.startsWith(drapcode_constant_1.LOCAL_STORAGE) ||
|
|
1237
|
-
val.startsWith(drapcode_constant_1.COOKIES) ||
|
|
1238
|
-
val.startsWith(drapcode_constant_1.FORM_DATA_SESSION) ||
|
|
1239
|
-
val.startsWith(drapcode_constant_1.ENVIRONMENT_VARIABLE) ||
|
|
1240
|
-
val.startsWith(drapcode_constant_1.PROJECT_CONSTANTS_PREFIX));
|
|
1241
|
-
};
|
|
1173
|
+
});
|
|
1174
|
+
const checkFieldValueType = (val) => PREFIXES.some((prefix) => val.startsWith(prefix));
|
|
1242
1175
|
exports.checkFieldValueType = checkFieldValueType;
|
|
1243
|
-
|
|
1244
|
-
return dataArr.map(
|
|
1245
|
-
mappingArray.map(
|
|
1246
|
-
|
|
1247
|
-
|
|
1176
|
+
const replaceValuesFromObjArr = (dataArr, mappingArray) => {
|
|
1177
|
+
return dataArr.map((data) => {
|
|
1178
|
+
mappingArray.map((mapping) => {
|
|
1179
|
+
let dataValue = data.value.replace(/{{(.*?)}}/g, "$1");
|
|
1180
|
+
let mappingValue = mapping[dataValue];
|
|
1248
1181
|
if (mappingValue) {
|
|
1249
1182
|
data.value = data.value.replace(data.value, mappingValue);
|
|
1250
1183
|
}
|
|
@@ -1253,9 +1186,9 @@ var replaceValuesFromObjArr = function (dataArr, mappingArray) {
|
|
|
1253
1186
|
});
|
|
1254
1187
|
};
|
|
1255
1188
|
exports.replaceValuesFromObjArr = replaceValuesFromObjArr;
|
|
1256
|
-
|
|
1257
|
-
return dataArr.map(
|
|
1258
|
-
mappingArray.forEach(
|
|
1189
|
+
const replaceValuesFromRequestMapping = (dataArr, mappingArray) => {
|
|
1190
|
+
return dataArr.map((data) => {
|
|
1191
|
+
mappingArray.forEach((mapping) => {
|
|
1259
1192
|
if (data.value.includes(mapping.value))
|
|
1260
1193
|
data.value = data.value.replace(mapping.value, mapping.key);
|
|
1261
1194
|
});
|
|
@@ -1263,29 +1196,26 @@ var replaceValuesFromRequestMapping = function (dataArr, mappingArray) {
|
|
|
1263
1196
|
});
|
|
1264
1197
|
};
|
|
1265
1198
|
exports.replaceValuesFromRequestMapping = replaceValuesFromRequestMapping;
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
return [2 /*return*/, response];
|
|
1289
|
-
});
|
|
1290
|
-
}); };
|
|
1199
|
+
const getAwsSignature = async (axiosConfig, awsSignPluginConfig) => {
|
|
1200
|
+
const response = { error: "", data: {} };
|
|
1201
|
+
const { method, headers, url, data } = axiosConfig;
|
|
1202
|
+
const parsedUrl = new URL(url);
|
|
1203
|
+
if (awsSignPluginConfig) {
|
|
1204
|
+
const { accessKeyId, secretAccessKey, region, service } = awsSignPluginConfig;
|
|
1205
|
+
const signedRequest = (0, aws4_1.sign)({
|
|
1206
|
+
method,
|
|
1207
|
+
service,
|
|
1208
|
+
region,
|
|
1209
|
+
host: parsedUrl.host,
|
|
1210
|
+
headers,
|
|
1211
|
+
body: data,
|
|
1212
|
+
path: parsedUrl.pathname + parsedUrl.search,
|
|
1213
|
+
}, { accessKeyId, secretAccessKey });
|
|
1214
|
+
response.data = { ...signedRequest, url };
|
|
1215
|
+
return response;
|
|
1216
|
+
}
|
|
1217
|
+
else
|
|
1218
|
+
response.error = "AWS Signature Plugin is not installed.";
|
|
1219
|
+
return response;
|
|
1220
|
+
};
|
|
1291
1221
|
exports.getAwsSignature = getAwsSignature;
|