drapcode-utility 2.7.3 → 2.7.4-sandbox.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/build/aws/aws-util.d.ts +6 -0
  2. package/build/aws/aws-util.d.ts.map +1 -0
  3. package/build/aws/aws-util.js +34 -0
  4. package/build/aws/aws-util.js.map +1 -0
  5. package/build/aws/encryption/KMS.d.ts +9 -0
  6. package/build/aws/encryption/KMS.d.ts.map +1 -0
  7. package/build/aws/encryption/KMS.js +65 -0
  8. package/build/aws/encryption/KMS.js.map +1 -0
  9. package/build/{encryption → aws/encryption}/crypt.d.ts +1 -0
  10. package/build/aws/encryption/crypt.d.ts.map +1 -0
  11. package/build/{encryption → aws/encryption}/crypt.js +25 -36
  12. package/build/aws/encryption/crypt.js.map +1 -0
  13. package/build/{encryption → aws/encryption}/file.d.ts +2 -1
  14. package/build/aws/encryption/file.d.ts.map +1 -0
  15. package/build/{encryption → aws/encryption}/file.js +2 -3
  16. package/build/aws/encryption/file.js.map +1 -0
  17. package/build/{encryption → aws/encryption}/index.d.ts +4 -3
  18. package/build/aws/encryption/index.d.ts.map +1 -0
  19. package/build/{encryption → aws/encryption}/index.js +41 -41
  20. package/build/aws/encryption/index.js.map +1 -0
  21. package/build/{encryption → aws/encryption}/utility.d.ts +1 -0
  22. package/build/aws/encryption/utility.d.ts.map +1 -0
  23. package/build/{encryption → aws/encryption}/utility.js +3 -2
  24. package/build/aws/encryption/utility.js.map +1 -0
  25. package/build/aws/model.d.ts +30 -0
  26. package/build/aws/model.d.ts.map +1 -0
  27. package/build/{encryption → aws}/model.js +1 -0
  28. package/build/aws/model.js.map +1 -0
  29. package/build/aws/s3-util.d.ts +36 -0
  30. package/build/aws/s3-util.d.ts.map +1 -0
  31. package/build/aws/s3-util.js +198 -0
  32. package/build/aws/s3-util.js.map +1 -0
  33. package/build/errors/app-error.d.ts +17 -4
  34. package/build/errors/app-error.d.ts.map +1 -0
  35. package/build/errors/app-error.js +184 -6
  36. package/build/errors/app-error.js.map +1 -0
  37. package/build/errors/async-handler.d.ts +3 -0
  38. package/build/errors/async-handler.d.ts.map +1 -0
  39. package/build/errors/async-handler.js +9 -0
  40. package/build/errors/async-handler.js.map +1 -0
  41. package/build/errors/axios-error.d.ts +2 -1
  42. package/build/errors/axios-error.d.ts.map +1 -0
  43. package/build/errors/axios-error.js +12 -8
  44. package/build/errors/axios-error.js.map +1 -0
  45. package/build/errors/bad-request-error.d.ts +2 -1
  46. package/build/errors/bad-request-error.d.ts.map +1 -0
  47. package/build/errors/bad-request-error.js +1 -0
  48. package/build/errors/bad-request-error.js.map +1 -0
  49. package/build/errors/custom-error.d.ts +1 -0
  50. package/build/errors/custom-error.d.ts.map +1 -0
  51. package/build/errors/custom-error.js +1 -0
  52. package/build/errors/custom-error.js.map +1 -0
  53. package/build/errors/error-classes.d.ts +23 -0
  54. package/build/errors/error-classes.d.ts.map +1 -0
  55. package/build/errors/error-classes.js +87 -0
  56. package/build/errors/error-classes.js.map +1 -0
  57. package/build/errors/error-codes.d.ts +47 -0
  58. package/build/errors/error-codes.d.ts.map +1 -0
  59. package/build/errors/error-codes.js +78 -0
  60. package/build/errors/error-codes.js.map +1 -0
  61. package/build/errors/error-obj.d.ts +10 -0
  62. package/build/errors/error-obj.d.ts.map +1 -0
  63. package/build/errors/error-obj.js +55 -0
  64. package/build/errors/error-obj.js.map +1 -0
  65. package/build/errors/get-error-details.d.ts +11 -0
  66. package/build/errors/get-error-details.d.ts.map +1 -0
  67. package/build/errors/get-error-details.js +28 -0
  68. package/build/errors/get-error-details.js.map +1 -0
  69. package/build/errors/not-found.d.ts +2 -1
  70. package/build/errors/not-found.d.ts.map +1 -0
  71. package/build/errors/not-found.js +3 -2
  72. package/build/errors/not-found.js.map +1 -0
  73. package/build/errors/wrap-error.d.ts +9 -0
  74. package/build/errors/wrap-error.d.ts.map +1 -0
  75. package/build/errors/wrap-error.js +17 -0
  76. package/build/errors/wrap-error.js.map +1 -0
  77. package/build/format-fields/index.d.ts +1 -0
  78. package/build/format-fields/index.d.ts.map +1 -0
  79. package/build/format-fields/index.js +13 -13
  80. package/build/format-fields/index.js.map +1 -0
  81. package/build/index.d.ts +25 -21
  82. package/build/index.d.ts.map +1 -0
  83. package/build/index.js +13 -7
  84. package/build/index.js.map +1 -0
  85. package/build/middlewares/redis/request-log.d.ts +1 -0
  86. package/build/middlewares/redis/request-log.d.ts.map +1 -0
  87. package/build/middlewares/redis/request-log.js +3 -2
  88. package/build/middlewares/redis/request-log.js.map +1 -0
  89. package/build/query/queryBuilder.d.ts +1 -0
  90. package/build/query/queryBuilder.d.ts.map +1 -0
  91. package/build/query/queryBuilder.js +66 -129
  92. package/build/query/queryBuilder.js.map +1 -0
  93. package/build/utils/check-error.d.ts +1 -0
  94. package/build/utils/check-error.d.ts.map +1 -0
  95. package/build/utils/check-error.js +14 -15
  96. package/build/utils/check-error.js.map +1 -0
  97. package/build/utils/common-util.d.ts +2 -1
  98. package/build/utils/common-util.d.ts.map +1 -0
  99. package/build/utils/common-util.js +46 -47
  100. package/build/utils/common-util.js.map +1 -0
  101. package/build/utils/date-util.d.ts +1 -0
  102. package/build/utils/date-util.d.ts.map +1 -0
  103. package/build/utils/date-util.js +59 -60
  104. package/build/utils/date-util.js.map +1 -0
  105. package/build/utils/file-util.d.ts +9 -0
  106. package/build/utils/file-util.d.ts.map +1 -0
  107. package/build/utils/file-util.js +120 -9
  108. package/build/utils/file-util.js.map +1 -0
  109. package/build/utils/prepare-query.d.ts +1 -0
  110. package/build/utils/prepare-query.d.ts.map +1 -0
  111. package/build/utils/prepare-query.js +15 -17
  112. package/build/utils/prepare-query.js.map +1 -0
  113. package/build/utils/project-util.d.ts +2 -1
  114. package/build/utils/project-util.d.ts.map +1 -0
  115. package/build/utils/project-util.js +45 -50
  116. package/build/utils/project-util.js.map +1 -0
  117. package/build/utils/query-parser.d.ts +1 -1
  118. package/build/utils/query-parser.d.ts.map +1 -0
  119. package/build/utils/query-parser.js +6 -568
  120. package/build/utils/query-parser.js.map +1 -0
  121. package/build/utils/query-utils.d.ts +1 -0
  122. package/build/utils/query-utils.d.ts.map +1 -0
  123. package/build/utils/query-utils.js +46 -50
  124. package/build/utils/query-utils.js.map +1 -0
  125. package/build/utils/rest-client.d.ts +1 -0
  126. package/build/utils/rest-client.d.ts.map +1 -0
  127. package/build/utils/rest-client.js +88 -122
  128. package/build/utils/rest-client.js.map +1 -0
  129. package/build/utils/token.d.ts +1 -0
  130. package/build/utils/token.d.ts.map +1 -0
  131. package/build/utils/token.js +4 -3
  132. package/build/utils/token.js.map +1 -0
  133. package/build/utils/util.d.ts +2 -1
  134. package/build/utils/util.d.ts.map +1 -0
  135. package/build/utils/util.js +340 -392
  136. package/build/utils/util.js.map +1 -0
  137. package/build/utils/uuid-generator.d.ts +1 -0
  138. package/build/utils/uuid-generator.d.ts.map +1 -0
  139. package/build/utils/uuid-generator.js +9 -8
  140. package/build/utils/uuid-generator.js.map +1 -0
  141. package/package.json +7 -6
  142. package/build/encryption/KMS.d.ts +0 -8
  143. package/build/encryption/KMS.js +0 -67
  144. package/build/encryption/model.d.ts +0 -17
  145. package/build/middlewares/error-logger.d.ts +0 -3
  146. package/build/middlewares/error-logger.js +0 -74
  147. package/build/utils/s3-util.d.ts +0 -36
  148. package/build/utils/s3-util.js +0 -275
@@ -36,8 +36,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- 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;
40
- exports.getArgsFromKey = exports.masking = exports.getLastUpdatedId = exports.getTotalRecords = exports.buildLimitOffsetClause = exports.buildOrderByClause = exports.buildWhereClause = exports.createMySqlConnection = 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;
39
+ exports.divide = 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.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;
40
+ exports.slugifyFileName = exports.getArgsFromKey = exports.masking = exports.getLastUpdatedId = exports.getTotalRecords = exports.buildLimitOffsetClause = exports.buildOrderByClause = exports.buildWhereClause = exports.createMySqlConnection = 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 = void 0;
41
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
42
+ /* eslint-disable @typescript-eslint/no-require-imports */
41
43
  const drapcode_constant_1 = require("drapcode-constant");
42
44
  const lodash_1 = __importDefault(require("lodash"));
43
45
  const showdown_1 = __importDefault(require("showdown"));
@@ -51,39 +53,40 @@ const mime_types_1 = __importDefault(require("mime-types"));
51
53
  const uuid_2 = require("uuid");
52
54
  const aws4_1 = require("aws4");
53
55
  const fs_1 = __importDefault(require("fs"));
54
- const mysql = require("mysql2/promise");
55
- exports.nonFindQuery = ["COUNT", "SUM", "AVG", "MIN", "MAX"];
56
+ const drapcode_logger_1 = require("drapcode-logger");
57
+ const mysql = require('mysql2/promise');
58
+ exports.nonFindQuery = ['COUNT', 'SUM', 'AVG', 'MIN', 'MAX'];
56
59
  // Constants
57
60
  const DERIVED_FIELD_EXCLUDES = [
58
- "formatType",
59
- "restToLower",
60
- "whitespace",
61
- "type",
62
- "noSplitopt",
63
- "length",
64
- "endopt",
65
- "startLength",
66
- "endLength",
67
- "startString",
68
- "endString",
69
- "separator",
70
- "expression",
71
- "unixType",
72
- "currency",
73
- "maxFraction",
74
- "position",
75
- "refField",
76
- "condition",
77
- "match",
78
- "refFieldType",
79
- "index",
80
- "positionOfRecords",
81
- "numberOfRecords",
82
- "elementToRender",
83
- "indexNum",
61
+ 'formatType',
62
+ 'restToLower',
63
+ 'whitespace',
64
+ 'type',
65
+ 'noSplitopt',
66
+ 'length',
67
+ 'endopt',
68
+ 'startLength',
69
+ 'endLength',
70
+ 'startString',
71
+ 'endString',
72
+ 'separator',
73
+ 'expression',
74
+ 'unixType',
75
+ 'currency',
76
+ 'maxFraction',
77
+ 'position',
78
+ 'refField',
79
+ 'condition',
80
+ 'match',
81
+ 'refFieldType',
82
+ 'index',
83
+ 'positionOfRecords',
84
+ 'numberOfRecords',
85
+ 'elementToRender',
86
+ 'indexNum',
84
87
  ];
85
- const ENVIRONMENT_FIX_KEY = "environment_variable.";
86
- const TENANT_FIX_KEY = "current_tenant.";
88
+ const ENVIRONMENT_FIX_KEY = 'environment_variable.';
89
+ const TENANT_FIX_KEY = 'current_tenant.';
87
90
  const PREFIXES = [
88
91
  drapcode_constant_1.CURRENT_USER_LOWER,
89
92
  drapcode_constant_1.CURRENT_SESSION,
@@ -94,25 +97,17 @@ const PREFIXES = [
94
97
  drapcode_constant_1.ENVIRONMENT_VARIABLE,
95
98
  drapcode_constant_1.PROJECT_CONSTANTS_PREFIX,
96
99
  ];
97
- // State
98
- const consoleState = {
99
- isModified: false,
100
- oldConsoleLog: null,
101
- oldConsoleInfo: null,
102
- };
103
100
  /**
104
101
  * Validates a string for special characters and numbers
105
102
  * @param str - The string to validate
106
103
  * @returns Error message if invalid, false if valid
107
104
  */
108
105
  const validateString = (str) => {
109
- const specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
110
- const isNumber = str.match(/\d+/g);
111
- if (specialChar.test(str)) {
112
- return "String should not contain special characters";
106
+ if (/[`!@#$%^&*()_+=[\]{};':"\\|,.<>/?~-]/.test(str)) {
107
+ return 'String should not contain special characters';
113
108
  }
114
- if (isNumber) {
115
- return "String should not contain any number";
109
+ if (/\d/.test(str)) {
110
+ return 'String should not contain numbers';
116
111
  }
117
112
  return false;
118
113
  };
@@ -137,12 +132,12 @@ exports.camelize = camelize;
137
132
  */
138
133
  const clearSpaceAndReformat = (text, separator) => {
139
134
  if (!text) {
140
- return "";
135
+ return '';
141
136
  }
142
137
  return text
143
138
  .toString()
144
139
  .toLowerCase()
145
- .replace(/\s+/g, separator ?? "");
140
+ .replace(/\s+/g, separator ?? '');
146
141
  };
147
142
  exports.clearSpaceAndReformat = clearSpaceAndReformat;
148
143
  /**
@@ -169,7 +164,7 @@ exports.isEmptyObject = isEmptyObject;
169
164
  * @returns True if the value is an object
170
165
  */
171
166
  const isObject = (item) => {
172
- return item !== null && typeof item === "object" && !Array.isArray(item);
167
+ return item !== null && typeof item === 'object' && !Array.isArray(item);
173
168
  };
174
169
  exports.isObject = isObject;
175
170
  /**
@@ -183,13 +178,13 @@ const dynamicSort = (property) => {
183
178
  const bValue = b[property];
184
179
  if (!aValue ||
185
180
  !bValue ||
186
- aValue === "undefined" ||
187
- bValue === "undefined" ||
188
- typeof aValue === "undefined" ||
189
- typeof bValue === "undefined") {
181
+ aValue === 'undefined' ||
182
+ bValue === 'undefined' ||
183
+ typeof aValue === 'undefined' ||
184
+ typeof bValue === 'undefined') {
190
185
  return 0;
191
186
  }
192
- if (typeof aValue === "number" || typeof bValue === "number") {
187
+ if (typeof aValue === 'number' || typeof bValue === 'number') {
193
188
  return aValue < bValue ? -1 : aValue > bValue ? 1 : 0;
194
189
  }
195
190
  const aStr = String(aValue).toLowerCase();
@@ -223,35 +218,35 @@ const validateUuidString = (uuid) => {
223
218
  };
224
219
  exports.validateUuidString = validateUuidString;
225
220
  const expressionMap = {
226
- " ": "##@@##@@##",
227
- ">": "##@@##@@@@",
228
- "<": "@@@@##@@@@",
229
- "\n": "U+000A",
230
- '"': "U+0022",
231
- "'": "U+0027",
221
+ ' ': '##@@##@@##',
222
+ '>': '##@@##@@@@',
223
+ '<': '@@@@##@@@@',
224
+ '\n': 'U+000A',
225
+ '"': 'U+0022',
226
+ "'": 'U+0027',
232
227
  };
233
228
  // Helper to escape special regex characters
234
229
  const escapeRegExp = (string) => {
235
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
230
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
236
231
  };
237
232
  // If you want to render HTML line breaks only (like in JSX innerHTML or a browser)
238
233
  const getSpecialCharectorReplacedExpression = (expression) => {
239
- return expressionToString(expression).replace(/\n/g, "<br/>");
234
+ return expressionToString(expression).replace(/\n/g, '<br/>');
240
235
  };
241
236
  exports.getSpecialCharectorReplacedExpression = getSpecialCharectorReplacedExpression;
242
237
  const expressionToString = (ex) => {
243
238
  return Object.entries(expressionMap).reduce((acc, [char, token]) => {
244
- return acc.replace(new RegExp(escapeRegExp(token), "g"), char);
239
+ return acc.replace(new RegExp(escapeRegExp(token), 'g'), char);
245
240
  }, ex);
246
241
  };
247
242
  const cleanCollectionAndFieldName = (str) => {
248
- str = str.replace(/[^A-Za-z0-9\s_]/, "");
243
+ str = str.replace(/[^A-Za-z0-9\s_]/, '');
249
244
  return str;
250
245
  };
251
246
  exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
252
247
  const formatCollectionAndFieldName = (str) => {
253
- let updateString = (0, exports.cleanCollectionAndFieldName)(str);
254
- return (0, exports.clearSpaceAndReformat)(updateString.trim(), "_");
248
+ const updateString = (0, exports.cleanCollectionAndFieldName)(str);
249
+ return (0, exports.clearSpaceAndReformat)(updateString.trim(), '_');
255
250
  };
256
251
  exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
257
252
  const restructureData = (data) => {
@@ -260,16 +255,14 @@ const restructureData = (data) => {
260
255
  if (Array.isArray(data)) {
261
256
  if (!data.length)
262
257
  return [];
263
- let firstEle = data[0];
264
- if (typeof firstEle === "string" || typeof firstEle === "number") {
265
- return data.map((el) => {
266
- value: el;
267
- });
258
+ const firstEle = data[0];
259
+ if (typeof firstEle === 'string' || typeof firstEle === 'number') {
260
+ return data.map((el) => el);
268
261
  }
269
262
  return data;
270
263
  }
271
264
  else {
272
- if (typeof data === "string" || typeof data === "number") {
265
+ if (typeof data === 'string' || typeof data === 'number') {
273
266
  return [{ value: data }];
274
267
  }
275
268
  return [data];
@@ -306,88 +299,85 @@ const convertItemToArray = (itemValue) => {
306
299
  exports.convertItemToArray = convertItemToArray;
307
300
  const validateAlphanumericString = (str) => {
308
301
  if (/[^A-Za-z0-9\s_]/.test(str)) {
309
- return "String should contain only numbers and letters";
302
+ return 'String should contain only numbers and letters';
310
303
  }
311
304
  return false;
312
305
  };
313
306
  exports.validateAlphanumericString = validateAlphanumericString;
314
307
  const formatCustomCSSClasses = (customClasses) => {
315
308
  if (!customClasses || !Array.isArray(customClasses)) {
316
- return "";
309
+ return '';
317
310
  }
318
- let projectCustomCSSClassesData = "";
311
+ let projectCustomCSSClassesData = '';
319
312
  customClasses.forEach((element) => {
320
313
  if (element.classProperty) {
321
314
  const classWithProp = JSON.stringify(element.classProperty);
322
315
  const unquotedClassWithProp = classWithProp
323
- .replace(/"([^"]+)"/g, "$1")
324
- .split(",")
325
- .join(";");
326
- projectCustomCSSClassesData += `${element.class.startsWith(".") ? element.class : "." + element.class}${element.pseudoClass ? ":" + element.pseudoClass : ""}${unquotedClassWithProp} `;
316
+ .replace(/"([^"]+)"/g, '$1')
317
+ .split(',')
318
+ .join(';');
319
+ projectCustomCSSClassesData += `${element.class.startsWith('.') ? element.class : '.' + element.class}${element.pseudoClass ? ':' + element.pseudoClass : ''}${unquotedClassWithProp} `;
327
320
  }
328
321
  });
329
322
  return projectCustomCSSClassesData;
330
323
  };
331
324
  exports.formatCustomCSSClasses = formatCustomCSSClasses;
332
325
  const replaceDataValueIntoExpression = (expression, data, user, tenant, userSetting, subTenant, sessionValue, envConstants, sessionFormValue, localStorageValue, cookiesValue) => {
333
- const contentList = expression
334
- .match(/{{(.*?)}}/g)
335
- ?.map((b) => b.replace(/{{(.*?)}}/g, "$1"));
336
- console.log("1 replaceDataValueIntoExpression");
326
+ const contentList = expression.match(/{{(.*?)}}/g)?.map((b) => b.replace(/{{(.*?)}}/g, '$1'));
337
327
  contentList?.forEach((prop) => {
338
328
  const needle = `{{${prop}}}`;
339
329
  prop = voca_1.default.trim(prop);
340
- let dataOfItem = "";
330
+ let dataOfItem = '';
341
331
  const isDynamicField = [
342
- "RF::",
343
- "PC::",
344
- "CC::",
345
- "current_user_reference_field.",
346
- "createdBy.",
347
- "environment_variable.",
348
- "current_session.",
349
- "form_data_session.",
332
+ 'RF::',
333
+ 'PC::',
334
+ 'CC::',
335
+ 'current_user_reference_field.',
336
+ 'createdBy.',
337
+ 'environment_variable.',
338
+ 'current_session.',
339
+ 'form_data_session.',
350
340
  ].some((str) => prop.includes(str));
351
- if (prop.includes("current_user") && user) {
352
- prop = prop.replace("current_user.", "");
341
+ if (prop.includes('current_user') && user) {
342
+ prop = prop.replace('current_user.', '');
353
343
  if (Object.keys(user).length > 0) {
354
344
  dataOfItem = (0, exports.parseValueFromData)(user, prop);
355
345
  }
356
346
  }
357
- else if (prop.includes("current_tenant") && tenant) {
358
- prop = prop.replace("current_tenant.", "");
347
+ else if (prop.includes('current_tenant') && tenant) {
348
+ prop = prop.replace('current_tenant.', '');
359
349
  if (Object.keys(tenant).length > 0) {
360
350
  dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
361
351
  }
362
352
  }
363
- else if (prop.includes("current_settings") && userSetting) {
364
- prop = prop.replace("current_settings.", "");
353
+ else if (prop.includes('current_settings') && userSetting) {
354
+ prop = prop.replace('current_settings.', '');
365
355
  if (Object.keys(userSetting).length > 0) {
366
356
  dataOfItem = (0, exports.parseValueFromData)(userSetting, prop);
367
357
  }
368
358
  }
369
- else if (prop.includes("current_sub_tenant") && subTenant) {
370
- prop = prop.replace("current_sub_tenant.", "");
359
+ else if (prop.includes('current_sub_tenant') && subTenant) {
360
+ prop = prop.replace('current_sub_tenant.', '');
371
361
  if (Object.keys(userSetting).length > 0) {
372
362
  dataOfItem = (0, exports.parseValueFromData)(subTenant, prop);
373
363
  }
374
364
  }
375
- else if (prop.includes("SESSION_STORAGE")) {
376
- prop = prop.replace("SESSION_STORAGE.", "");
365
+ else if (prop.includes('SESSION_STORAGE')) {
366
+ prop = prop.replace('SESSION_STORAGE.', '');
377
367
  if (Object.keys(sessionValue).length > 0) {
378
368
  //Session will contain multi level data
379
369
  dataOfItem = lodash_1.default.get(sessionValue, prop);
380
370
  }
381
371
  }
382
- else if (prop.includes("LOCAL_STORAGE")) {
383
- prop = prop.replace("LOCAL_STORAGE.", "");
372
+ else if (prop.includes('LOCAL_STORAGE')) {
373
+ prop = prop.replace('LOCAL_STORAGE.', '');
384
374
  if (Object.keys(localStorageValue).length > 0) {
385
375
  //Session will contain multi level data
386
376
  dataOfItem = lodash_1.default.get(localStorageValue, prop);
387
377
  }
388
378
  }
389
- else if (prop.includes("COOKIES")) {
390
- prop = prop.replace("COOKIES.", "");
379
+ else if (prop.includes('COOKIES')) {
380
+ prop = prop.replace('COOKIES.', '');
391
381
  if (Object.keys(cookiesValue).length > 0) {
392
382
  //Session will contain multi level data
393
383
  dataOfItem = lodash_1.default.get(cookiesValue, prop);
@@ -405,6 +395,8 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
405
395
  else {
406
396
  if (Object.keys(data).length > 0) {
407
397
  dataOfItem = (0, exports.parseValueFromData)(data, prop);
398
+ //TODO: Need better way
399
+ delete data[prop];
408
400
  }
409
401
  }
410
402
  expression = replaceValueInExpression(needle, dataOfItem, expression);
@@ -413,39 +405,39 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
413
405
  };
414
406
  exports.replaceDataValueIntoExpression = replaceDataValueIntoExpression;
415
407
  const replaceValueInExpression = (needle, replacement, expression) => {
416
- const match = new RegExp(needle, "ig");
417
- replacement = replacement ? replacement : "";
408
+ const match = new RegExp(needle, 'ig');
409
+ replacement = replacement ? replacement : '';
418
410
  return expression.replace(match, replacement);
419
411
  };
420
412
  const parseJsonString = (str) => {
421
413
  try {
422
414
  str = str
423
- .replace(/\\n/g, "\\n")
415
+ .replace(/\\n/g, '\\n')
424
416
  .replace(/\\'/g, "\\'")
425
417
  .replace(/\\"/g, '\\"')
426
- .replace(/\\&/g, "\\&")
427
- .replace(/\\r/g, "\\r")
428
- .replace(/\\t/g, "\\t")
429
- .replace(/\\b/g, "\\b")
430
- .replace(/\\f/g, "\\f");
418
+ .replace(/\\&/g, '\\&')
419
+ .replace(/\\r/g, '\\r')
420
+ .replace(/\\t/g, '\\t')
421
+ .replace(/\\b/g, '\\b')
422
+ .replace(/\\f/g, '\\f');
431
423
  // Remove non-printable and other non-valid JSON characters
432
424
  // eslint-disable-next-line no-control-regex
433
- str = str.replace(/[\u0000-\u0019]+/g, "");
425
+ str = str.replace(/[\u0000-\u0019]+/g, '');
434
426
  return JSON.parse(str);
435
427
  }
436
428
  catch (e) {
437
- console.error("Error: ", e);
429
+ drapcode_logger_1.logger.error(e);
438
430
  return {};
439
431
  }
440
432
  };
441
433
  exports.parseJsonString = parseJsonString;
442
434
  const parseValueFromData = (data, fieldName) => {
443
- let value = "";
444
- let valueIndex = "";
445
- let valueIndexFieldName = "";
446
- if (fieldName && fieldName.includes(".")) {
447
- let fullNameParts = fieldName.split(".");
448
- let prefix = "";
435
+ let value = '';
436
+ let valueIndex = '';
437
+ let valueIndexFieldName = '';
438
+ if (fieldName && fieldName.includes('.')) {
439
+ const fullNameParts = fieldName.split('.');
440
+ let prefix = '';
449
441
  let stack = data || {};
450
442
  for (let k = 0; k < fullNameParts.length; k++) {
451
443
  prefix = fullNameParts[k];
@@ -456,29 +448,25 @@ const parseValueFromData = (data, fieldName) => {
456
448
  });
457
449
  }
458
450
  if (stack && !stack[prefix]) {
459
- stack[prefix] = "";
451
+ stack[prefix] = '';
460
452
  }
461
453
  stack = stack[prefix];
462
454
  }
463
- value = stack ? stack : "";
455
+ value = stack ? stack : '';
464
456
  if (Array.isArray(value)) {
465
457
  value = value.filter(() => true);
466
458
  }
467
459
  }
468
- else if (fieldName && fieldName.includes("[")) {
460
+ else if (fieldName && fieldName.includes('[')) {
469
461
  //Todo: Need to Refactor
470
- let fullNameParts = fieldName.split("[");
471
- let prefix = "";
462
+ const fullNameParts = fieldName.split('[');
463
+ let prefix = '';
472
464
  let stack = data || {};
473
465
  for (let k = 0; k < fullNameParts.length - 1; k++) {
474
466
  const cValue = fullNameParts[k];
475
467
  const nValue = fullNameParts[k + 1];
476
- prefix = cValue ? (!cValue.includes("]") ? cValue : "") : "";
477
- valueIndex = nValue
478
- ? nValue.includes("]")
479
- ? nValue.split("]")[0]
480
- : nValue
481
- : "";
468
+ prefix = cValue ? (!cValue.includes(']') ? cValue : '') : '';
469
+ valueIndex = nValue ? (nValue.includes(']') ? nValue.split(']')[0] : nValue) : '';
482
470
  if (stack && Array.isArray(stack)) {
483
471
  stack[prefix] = stack.map((item) => {
484
472
  if (item[prefix])
@@ -486,44 +474,45 @@ const parseValueFromData = (data, fieldName) => {
486
474
  });
487
475
  }
488
476
  if (stack && !stack[prefix]) {
489
- stack[prefix] = "";
477
+ stack[prefix] = '';
490
478
  }
491
479
  stack = valueIndex ? stack[prefix][valueIndex] : stack[prefix];
492
- if (fieldName.includes("]:")) {
493
- valueIndexFieldName = nValue.split("]:")[1];
480
+ if (fieldName.includes(']:')) {
481
+ valueIndexFieldName = nValue.split(']:')[1];
494
482
  if (valueIndexFieldName) {
495
483
  stack = stack[valueIndexFieldName];
496
484
  }
497
485
  }
498
486
  }
499
- value = stack ? stack : "";
487
+ value = stack ? stack : '';
500
488
  if (Array.isArray(value)) {
501
489
  value = value.filter(() => true);
502
490
  }
503
491
  }
504
492
  else {
505
- value = data ? data[fieldName] : "";
493
+ value = data ? data[fieldName] : '';
506
494
  }
507
495
  if (value && Array.isArray(value) && value.length === 1)
508
496
  return value[0];
509
- if (value && Array.isArray(value) && typeof value[0] === "string") {
510
- return value.join(",");
497
+ if (value && Array.isArray(value) && typeof value[0] === 'string') {
498
+ return value.join(',');
511
499
  }
512
- if (!value || value == "undefined" || value === "undefined") {
500
+ if (!value || value == 'undefined' || value === 'undefined') {
513
501
  if (value === 0) {
514
- value = "0";
502
+ value = '0';
515
503
  }
516
504
  else {
517
- value = "";
505
+ value = '';
518
506
  }
519
507
  }
520
508
  return value;
521
509
  };
522
510
  exports.parseValueFromData = parseValueFromData;
523
511
  const unflattenObject = (obj) => {
524
- let result = {}, temp, substrings, property, i;
512
+ const result = {};
513
+ let temp, substrings, property, i;
525
514
  for (property in obj) {
526
- substrings = property.split(".");
515
+ substrings = property.split('.');
527
516
  temp = result;
528
517
  for (i = 0; i < substrings.length - 1; i++) {
529
518
  if (!(substrings[i] in temp)) {
@@ -543,13 +532,11 @@ const unflattenObject = (obj) => {
543
532
  exports.unflattenObject = unflattenObject;
544
533
  const replaceTransferObjectValueIntoExpression = (expression, transferObject) => {
545
534
  if (transferObject && Object.keys(transferObject).length > 0) {
546
- const contentList = expression
547
- .match(/{{(.*?)}}/g)
548
- ?.map((b) => b.replace(/{{(.*?)}}/g, "$1"));
535
+ const contentList = expression.match(/{{(.*?)}}/g)?.map((b) => b.replace(/{{(.*?)}}/g, '$1'));
549
536
  contentList?.forEach((prop) => {
550
537
  const needle = `{{${prop}}}`;
551
- let dataOfItem = "";
552
- dataOfItem = transferObject[prop] ? transferObject[prop] : "";
538
+ let dataOfItem = '';
539
+ dataOfItem = transferObject[prop] ? transferObject[prop] : '';
553
540
  expression = dataOfItem
554
541
  ? replaceValueInExpression(needle, dataOfItem, expression)
555
542
  : expression;
@@ -563,9 +550,9 @@ const removeMongoDbId = function (result) {
563
550
  if (Array.isArray(obj)) {
564
551
  return obj.map(removeIdRecursively);
565
552
  }
566
- if (typeof obj === "object" && obj !== null) {
567
- for (var key in obj) {
568
- if (key === "_id") {
553
+ if (typeof obj === 'object' && obj !== null) {
554
+ for (const key in obj) {
555
+ if (key === '_id') {
569
556
  delete obj[key];
570
557
  }
571
558
  else {
@@ -584,9 +571,9 @@ const removeMongoDbId = function (result) {
584
571
  exports.removeMongoDbId = removeMongoDbId;
585
572
  const processFieldsInclude = (fieldsInclude) => {
586
573
  let result = fieldsInclude;
587
- const refFieldsInclude = fieldsInclude.filter((field) => field.startsWith("RF::"));
588
- const derivedFieldsInclude = fieldsInclude.filter((field) => field.startsWith("DF::"));
589
- fieldsInclude = fieldsInclude.filter((field) => !(field.startsWith("RF::") || field.startsWith("DF::")));
574
+ const refFieldsInclude = fieldsInclude.filter((field) => field.startsWith('RF::'));
575
+ const derivedFieldsInclude = fieldsInclude.filter((field) => field.startsWith('DF::'));
576
+ fieldsInclude = fieldsInclude.filter((field) => !(field.startsWith('RF::') || field.startsWith('DF::')));
590
577
  const refFields = processReferenceFieldInclude(refFieldsInclude);
591
578
  const derivedFields = processDerivedFieldInclude(derivedFieldsInclude);
592
579
  const extraField = [...refFields, ...derivedFields].filter((value, index, array) => array.indexOf(value) === index);
@@ -595,10 +582,10 @@ const processFieldsInclude = (fieldsInclude) => {
595
582
  };
596
583
  exports.processFieldsInclude = processFieldsInclude;
597
584
  const processReferenceFieldInclude = (refFieldsInclude) => {
598
- let refFields = [];
585
+ const refFields = [];
599
586
  refFieldsInclude.forEach((exField) => {
600
- let field = exField.replace("RF::", "");
601
- field = field.split(".")[0];
587
+ let field = exField.replace('RF::', '');
588
+ field = field.split('.')[0];
602
589
  refFields.push(field);
603
590
  });
604
591
  return refFields;
@@ -606,15 +593,15 @@ const processReferenceFieldInclude = (refFieldsInclude) => {
606
593
  const processDerivedFieldInclude = (derivedFieldsInclude) => {
607
594
  let derivedFields = [];
608
595
  derivedFieldsInclude.forEach((exField) => {
609
- let derivedFieldStr = exField.replace("DF::", "");
610
- derivedFieldStr = derivedFieldStr.replaceAll("*#*#", '"');
596
+ let derivedFieldStr = exField.replace('DF::', '');
597
+ derivedFieldStr = derivedFieldStr.replaceAll('*#*#', '"');
611
598
  const derivedFieldObj = JSON.parse(derivedFieldStr);
612
599
  let fields = [];
613
600
  derivedFieldObj.args.forEach((arg) => {
614
- if (arg.name === "expression") {
601
+ if (arg.name === 'expression') {
615
602
  const needleList = arg.key
616
603
  .match(/{{(.*?)}}/g)
617
- ?.map((b) => b.replace(/{{(.*?)}}/g, "$1"));
604
+ ?.map((b) => b.replace(/{{(.*?)}}/g, '$1'));
618
605
  const tempFields = (0, exports.processFieldsInclude)(needleList);
619
606
  fields = [...fields, ...tempFields];
620
607
  }
@@ -629,7 +616,7 @@ const processDerivedFieldInclude = (derivedFieldsInclude) => {
629
616
  return derivedFields;
630
617
  };
631
618
  const replaceValueFromSource = (variableName, environment, tenant) => {
632
- if (variableName && typeof variableName === "string") {
619
+ if (variableName && typeof variableName === 'string') {
633
620
  if (variableName.startsWith(ENVIRONMENT_FIX_KEY)) {
634
621
  return replaceValueFromEnvironment(variableName, environment);
635
622
  }
@@ -647,11 +634,11 @@ const replaceValueFromSource = (variableName, environment, tenant) => {
647
634
  exports.replaceValueFromSource = replaceValueFromSource;
648
635
  const replaceValueFromEnvironment = (variableName, environment) => {
649
636
  if (variableName &&
650
- typeof variableName === "string" &&
637
+ typeof variableName === 'string' &&
651
638
  variableName.startsWith(ENVIRONMENT_FIX_KEY) &&
652
639
  environment &&
653
640
  environment.constants) {
654
- const envConstant = environment.constants.find((env) => env.name === variableName.replace(ENVIRONMENT_FIX_KEY, ""));
641
+ const envConstant = environment.constants.find((env) => env.name === variableName.replace(ENVIRONMENT_FIX_KEY, ''));
655
642
  return envConstant.value;
656
643
  }
657
644
  else {
@@ -662,7 +649,7 @@ const replaceValueFromTenant = (variableName, tenant) => {
662
649
  if (!tenant) {
663
650
  return variableName;
664
651
  }
665
- variableName = variableName.replace(TENANT_FIX_KEY, "");
652
+ variableName = variableName.replace(TENANT_FIX_KEY, '');
666
653
  return lodash_1.default.get(tenant, variableName);
667
654
  };
668
655
  const fillDefaultValues = (collection, itemdata) => {
@@ -677,20 +664,18 @@ const fillDefaultValues = (collection, itemdata) => {
677
664
  const isBooleanField = field.type === drapcode_constant_1.FieldTypes.boolean.id;
678
665
  const isInvalidBoolean = isBooleanField && ![true, false].includes(currentValue);
679
666
  if (!(fieldName in filledItemData) ||
680
- currentValue === "" ||
667
+ currentValue === '' ||
681
668
  currentValue === 0 ||
682
669
  (!isBooleanField && currentValue === false) ||
683
670
  isEmptyArray ||
684
671
  isInvalidBoolean) {
685
672
  const formattedField = JSON.parse(JSON.stringify(field));
686
- if (field.type === "static_option") {
673
+ if (field.type === 'static_option') {
687
674
  if (formattedField.extraFieldSetting?.staticDefaultValue?.length > 0) {
688
- filledItemData[fieldName] =
689
- formattedField.extraFieldSetting.staticDefaultValue[0];
675
+ filledItemData[fieldName] = formattedField.extraFieldSetting.staticDefaultValue[0];
690
676
  }
691
677
  }
692
- else if (field.extraFieldSetting &&
693
- "defaultValue" in formattedField.extraFieldSetting) {
678
+ else if (field.extraFieldSetting && 'defaultValue' in formattedField.extraFieldSetting) {
694
679
  filledItemData[fieldName] = assignFieldValue(formattedField, field, fieldName, filledItemData);
695
680
  }
696
681
  }
@@ -699,13 +684,11 @@ const fillDefaultValues = (collection, itemdata) => {
699
684
  };
700
685
  exports.fillDefaultValues = fillDefaultValues;
701
686
  const assignFieldValue = (formattedField, field, fieldName, filledItemData) => {
702
- let value = "";
687
+ let value = '';
703
688
  value = formattedField.extraFieldSetting
704
689
  ? formattedField.extraFieldSetting.defaultValue
705
690
  : filledItemData[fieldName];
706
- console.log("\n +==+ value 1:", value);
707
691
  value = (0, format_fields_1.getFormatFieldData)(value, field.type);
708
- console.log("\n +==+ value 2:", value);
709
692
  return value;
710
693
  };
711
694
  const validateData = (fields, data) => {
@@ -717,8 +700,8 @@ const validateData = (fields, data) => {
717
700
  if (fieldValue == null || fieldValue.length <= 0) {
718
701
  return;
719
702
  }
720
- const fieldTitle = field.fieldTitle.en || field.fieldTitle.get("en");
721
- if (field.type === "file" && typeof fieldValue === "string") {
703
+ const fieldTitle = field.fieldTitle.en || field.fieldTitle.get('en');
704
+ if (field.type === 'file' && typeof fieldValue === 'string') {
722
705
  try {
723
706
  fieldValue = JSON.parse(fieldValue);
724
707
  }
@@ -728,31 +711,31 @@ const validateData = (fields, data) => {
728
711
  }
729
712
  }
730
713
  switch (field.type) {
731
- case "text":
732
- if (typeof fieldValue !== "string" &&
733
- typeof fieldValue !== "number" &&
734
- Object.prototype.toString.call(fieldValue) !== "[object Date]") {
714
+ case 'text':
715
+ if (typeof fieldValue !== 'string' &&
716
+ typeof fieldValue !== 'number' &&
717
+ Object.prototype.toString.call(fieldValue) !== '[object Date]') {
735
718
  errors.push(`${fieldTitle} must be a string`);
736
719
  }
737
720
  break;
738
- case "large_text":
739
- case "color":
740
- if (typeof fieldValue !== "string") {
721
+ case 'large_text':
722
+ case 'color':
723
+ if (typeof fieldValue !== 'string') {
741
724
  errors.push(`${fieldTitle} must be a string`);
742
725
  }
743
726
  break;
744
- case "uuid":
745
- if (typeof fieldValue !== "string" || !(0, uuid_1.validate)(fieldValue)) {
727
+ case 'uuid':
728
+ if (typeof fieldValue !== 'string' || !(0, uuid_1.validate)(fieldValue)) {
746
729
  errors.push(`${fieldTitle} must be a valid UUID string`);
747
730
  }
748
731
  break;
749
- case "reference":
750
- case "belongsTo":
732
+ case 'reference':
733
+ case 'belongsTo':
751
734
  if (Array.isArray(fieldValue)) {
752
735
  const invalid = fieldValue.some((item) => {
753
- if (typeof item === "string")
736
+ if (typeof item === 'string')
754
737
  return false;
755
- if (typeof item === "object" && typeof item.uuid === "string")
738
+ if (typeof item === 'object' && typeof item.uuid === 'string')
756
739
  return false;
757
740
  return true;
758
741
  });
@@ -761,47 +744,46 @@ const validateData = (fields, data) => {
761
744
  }
762
745
  }
763
746
  else {
764
- if (!(typeof fieldValue === "string" ||
765
- (typeof fieldValue === "object" &&
766
- typeof fieldValue?.uuid === "string"))) {
747
+ if (!(typeof fieldValue === 'string' ||
748
+ (typeof fieldValue === 'object' && typeof fieldValue?.uuid === 'string'))) {
767
749
  errors.push(`${fieldTitle} must be a UUID string or an object with a uuid`);
768
750
  }
769
751
  }
770
752
  break;
771
- case "createdAt":
772
- case "updatedAt":
773
- case "date":
753
+ case 'createdAt':
754
+ case 'updatedAt':
755
+ case 'date':
774
756
  if (fieldValue && isNaN(Date.parse(fieldValue))) {
775
757
  errors.push(`${fieldTitle} must be a valid date`);
776
758
  }
777
759
  break;
778
- case "boolean":
779
- if (typeof fieldValue !== "boolean") {
760
+ case 'boolean':
761
+ if (typeof fieldValue !== 'boolean') {
780
762
  errors.push(`${fieldTitle} must be a boolean`);
781
763
  }
782
764
  break;
783
- case "email":
784
- if (typeof fieldValue !== "string" ||
785
- !/\S+@\S+\.\S+/.test(fieldValue)) {
765
+ case 'email':
766
+ if (typeof fieldValue !== 'string' || !/\S+@\S+\.\S+/.test(fieldValue)) {
786
767
  errors.push(`${fieldTitle} must be a valid email address`);
787
768
  break;
788
769
  }
789
770
  break;
790
- case "tel":
791
- const removedSpace = fieldValue.replace(/\s+/g, "");
792
- const telPattern = /^\+?(\d{1,3})?[-]?(\(\d{1,4}\)|\d{1,4})[-]?(\d{1,4}[-]?\d{1,4}|\d{7,10})$/;
793
- if (typeof removedSpace !== "string" ||
794
- !telPattern.test(removedSpace)) {
795
- errors.push(`${fieldTitle} must be a valid phone number`);
771
+ case 'tel':
772
+ {
773
+ const removedSpace = fieldValue.replace(/\s+/g, '');
774
+ const telPattern = /^\+?(\d{1,3})?[-]?(\(\d{1,4}\)|\d{1,4})[-]?(\d{1,4}[-]?\d{1,4}|\d{7,10})$/;
775
+ if (typeof removedSpace !== 'string' || !telPattern.test(removedSpace)) {
776
+ errors.push(`${fieldTitle} must be a valid phone number`);
777
+ }
796
778
  }
797
779
  break;
798
- case "static_option":
799
- case "dynamic_option":
800
- if (typeof fieldValue === "string") {
780
+ case 'static_option':
781
+ case 'dynamic_option':
782
+ if (typeof fieldValue === 'string') {
801
783
  break;
802
784
  }
803
785
  else if (Array.isArray(fieldValue)) {
804
- if (fieldValue.some((item) => typeof item !== "string")) {
786
+ if (fieldValue.some((item) => typeof item !== 'string')) {
805
787
  errors.push(`${fieldTitle} must be an array of strings`);
806
788
  }
807
789
  }
@@ -809,26 +791,24 @@ const validateData = (fields, data) => {
809
791
  errors.push(`${fieldTitle} must be a string or an array of strings`);
810
792
  }
811
793
  break;
812
- case "url":
813
- if (typeof fieldValue !== "string" || !(0, exports.validateUrl)(fieldValue)) {
794
+ case 'url':
795
+ if (typeof fieldValue !== 'string' || !(0, exports.validateUrl)(fieldValue)) {
814
796
  errors.push(`${fieldTitle} must be a valid URL`);
815
797
  }
816
798
  break;
817
- case "file":
799
+ case 'file':
818
800
  if (Array.isArray(fieldValue)) {
819
- if (fieldValue.some((item) => typeof item !== "object" ||
820
- !item.key ||
821
- typeof item.key !== "string")) {
801
+ if (fieldValue.some((item) => typeof item !== 'object' || !item.key || typeof item.key !== 'string')) {
822
802
  errors.push(`${fieldTitle} must be an array of objects with 'key' property as string`);
823
803
  }
824
804
  }
825
- else if (typeof fieldValue !== "object" ||
805
+ else if (typeof fieldValue !== 'object' ||
826
806
  !fieldValue.key ||
827
- typeof fieldValue.key !== "string") {
807
+ typeof fieldValue.key !== 'string') {
828
808
  errors.push(`${fieldTitle} must be an object with 'key' property as string`);
829
809
  }
830
810
  break;
831
- case "number":
811
+ case 'number':
832
812
  if (isNaN(Number(fieldValue))) {
833
813
  errors.push(`${fieldTitle} must be a valid number.`);
834
814
  }
@@ -846,52 +826,31 @@ const validateData = (fields, data) => {
846
826
  };
847
827
  exports.validateData = validateData;
848
828
  const validateUrl = (url) => {
849
- const pattern = new RegExp("^((ft|htt)ps?:\\/\\/)?" +
850
- "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" +
851
- "((\\d{1,3}\\.){3}\\d{1,3}))" +
852
- "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" +
853
- "(\\?[;&a-z\\d%_.~+=-]*)?" +
854
- "(\\#[-a-z\\d_]*)?$", "i");
829
+ const pattern = new RegExp('^((ft|htt)ps?:\\/\\/)?' +
830
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
831
+ '((\\d{1,3}\\.){3}\\d{1,3}))' +
832
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
833
+ '(\\?[;&a-z\\d%_.~+=-]*)?' +
834
+ '(\\#[-a-z\\d_]*)?$', 'i');
855
835
  return !!pattern.test(url);
856
836
  };
857
837
  exports.validateUrl = validateUrl;
858
- const toggleConsoleLogs = (enable) => {
859
- if (enable && consoleState.isModified) {
860
- console.log("==> Enabling console log|info...");
861
- if (consoleState.oldConsoleLog && consoleState.oldConsoleInfo) {
862
- console.log = consoleState.oldConsoleLog;
863
- console.info = consoleState.oldConsoleInfo;
864
- consoleState.isModified = false;
865
- console.log(`==> Enabling Console log modified: ${consoleState.isModified}`);
866
- }
867
- }
868
- else if (!enable && !consoleState.isModified) {
869
- consoleState.oldConsoleLog = console.log;
870
- consoleState.oldConsoleInfo = console.info;
871
- console.log("==> Disabling console log|info...");
872
- console.log = function () { };
873
- console.info = function () { };
874
- consoleState.isModified = true;
875
- console.log(`==> Disabling Console log modified: ${consoleState.isModified}`);
876
- }
877
- };
878
- exports.toggleConsoleLogs = toggleConsoleLogs;
879
838
  // Utility function to replace '/' with '____'
880
839
  const replaceSlashWithUnderscore = (value) => {
881
- return value && typeof value === "string" && value.includes("/")
882
- ? value.replace(/\//g, "____")
840
+ return value && typeof value === 'string' && value.includes('/')
841
+ ? value.replace(/\//g, '____')
883
842
  : value;
884
843
  };
885
844
  exports.replaceSlashWithUnderscore = replaceSlashWithUnderscore;
886
845
  // Utility function to replace '____' with '/'
887
846
  const replaceUnderscoreWithSlash = (value) => {
888
- return value && typeof value === "string" && value.includes("____")
889
- ? value.replace(/____/g, "/")
847
+ return value && typeof value === 'string' && value.includes('____')
848
+ ? value.replace(/____/g, '/')
890
849
  : value;
891
850
  };
892
851
  exports.replaceUnderscoreWithSlash = replaceUnderscoreWithSlash;
893
852
  const capitalize = function (str, restToLower) {
894
- return voca_1.default.capitalize(str, restToLower === "TRUE");
853
+ return voca_1.default.capitalize(str, restToLower === 'TRUE');
895
854
  };
896
855
  exports.capitalize = capitalize;
897
856
  const lowerCase = function (subject) {
@@ -907,10 +866,10 @@ const slugify = function (subject) {
907
866
  };
908
867
  exports.slugify = slugify;
909
868
  const trim = function (subject, whitespace, type) {
910
- if (type === "LEFT") {
869
+ if (type === 'LEFT') {
911
870
  return voca_1.default.trimLeft(subject, whitespace);
912
871
  }
913
- else if (type === "RIGHT") {
872
+ else if (type === 'RIGHT') {
914
873
  return voca_1.default.trimRight(subject, whitespace);
915
874
  }
916
875
  else {
@@ -937,16 +896,14 @@ const markdownToHtml = function (subject) {
937
896
  };
938
897
  exports.markdownToHtml = markdownToHtml;
939
898
  const strJoin = function (dataArr, separator, startString, endString) {
940
- separator = separator ? separator.replace(/##@@##@@##/g, " ") : " ";
899
+ separator = separator ? separator.replace(/##@@##@@##/g, ' ') : ' ';
941
900
  dataArr = Array.isArray(dataArr) ? dataArr : [dataArr];
942
901
  dataArr = dataArr.filter(Boolean);
943
- return `${startString ? startString.replace(/##@@##@@##/g, " ") + separator : ""}${dataArr.join(separator)}${endString ? separator + endString.replace(/##@@##@@##/g, " ") : ""}`;
902
+ return `${startString ? startString.replace(/##@@##@@##/g, ' ') + separator : ''}${dataArr.join(separator)}${endString ? separator + endString.replace(/##@@##@@##/g, ' ') : ''}`;
944
903
  };
945
904
  exports.strJoin = strJoin;
946
905
  const evaluateCustomSentence = function (expression, data, user, envConstants) {
947
- expression = expression
948
- ? (0, exports.getSpecialCharectorReplacedExpression)(expression)
949
- : " ";
906
+ expression = expression ? (0, exports.getSpecialCharectorReplacedExpression)(expression) : ' ';
950
907
  return (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
951
908
  };
952
909
  exports.evaluateCustomSentence = evaluateCustomSentence;
@@ -967,27 +924,23 @@ const addition = function (formatType, { numbers }) {
967
924
  }
968
925
  numbers = numbers.map((number) => (isNaN(number) ? 0 : number));
969
926
  const allNumbers = (0, exports.validateNumbers)(numbers);
970
- return (0, numeral_1.default)(math.sum(allNumbers)).format(formatType ? formatType : "00.00");
927
+ return (0, numeral_1.default)(math.sum(allNumbers)).format(formatType ? formatType : '00.00');
971
928
  }
972
929
  catch (err) {
973
- console.log("🚀 ~ file: util.js:89 ~ addition ~ error:", err);
974
- return "";
930
+ drapcode_logger_1.logger.error(`🚀 ~ file: util.js:89 ~ addition ~ error: ${err}`);
931
+ return '';
975
932
  }
976
933
  };
977
934
  exports.addition = addition;
978
935
  const substraction = function (formatType, { numbers1, numbers2 }) {
979
936
  try {
980
- const actNumber1 = Array.isArray(numbers1)
981
- ? math.sum(...numbers1)
982
- : numbers1;
983
- const actNumber2 = Array.isArray(numbers2)
984
- ? math.sum(...numbers2)
985
- : numbers2;
986
- return (0, numeral_1.default)(math.subtract(actNumber1, actNumber2)).format(formatType ? formatType : "00.00");
937
+ const actNumber1 = Array.isArray(numbers1) ? math.sum(...numbers1) : numbers1;
938
+ const actNumber2 = Array.isArray(numbers2) ? math.sum(...numbers2) : numbers2;
939
+ return (0, numeral_1.default)(math.subtract(actNumber1, actNumber2)).format(formatType ? formatType : '00.00');
987
940
  }
988
941
  catch (err) {
989
- console.log("🚀 ~ file: util.js:202 ~ substraction ~ error:", err);
990
- return "";
942
+ drapcode_logger_1.logger.error(`🚀 ~ file: util.js:202 ~ substraction ~ error: ${err}`);
943
+ return '';
991
944
  }
992
945
  };
993
946
  exports.substraction = substraction;
@@ -998,11 +951,11 @@ const average = function (formatType, { numbers }) {
998
951
  }
999
952
  numbers = numbers.map((number) => (isNaN(number) ? 0 : number));
1000
953
  const allNumbers = (0, exports.validateNumbers)(numbers);
1001
- return (0, numeral_1.default)(math.mean(...allNumbers)).format(formatType ? formatType : "00.00");
954
+ return (0, numeral_1.default)(math.mean(...allNumbers)).format(formatType ? formatType : '00.00');
1002
955
  }
1003
956
  catch (err) {
1004
- console.log("🚀 ~ file: util.js:98 ~ average ~ error:", err);
1005
- return "";
957
+ drapcode_logger_1.logger.error(`🚀 ~ file: util.js:98 ~ average ~ error: ${err}`);
958
+ return '';
1006
959
  }
1007
960
  };
1008
961
  exports.average = average;
@@ -1013,11 +966,11 @@ const multiply = function (formatType, { numbers }) {
1013
966
  }
1014
967
  numbers = numbers.map((number) => (isNaN(number) ? 1 : number));
1015
968
  const allNumbers = (0, exports.validateNumbers)(numbers);
1016
- return (0, numeral_1.default)(math.prod(...allNumbers)).format(formatType ? formatType : "00.00");
969
+ return (0, numeral_1.default)(math.prod(...allNumbers)).format(formatType ? formatType : '00.00');
1017
970
  }
1018
971
  catch (err) {
1019
- console.log("🚀 ~ file: util.js:106 ~ multiply ~ error:", err);
1020
- return "";
972
+ drapcode_logger_1.logger.error(`🚀 ~ file: util.js:106 ~ multiply ~ error: ${err}`);
973
+ return '';
1021
974
  }
1022
975
  };
1023
976
  exports.multiply = multiply;
@@ -1025,24 +978,23 @@ const divide = function (formatType, { number1, number2 }) {
1025
978
  try {
1026
979
  const num1 = (0, exports.checkAndConvertNumber)(number1);
1027
980
  const num2 = (0, exports.checkAndConvertNumber)(number2);
1028
- return (0, numeral_1.default)(math.divide(num1, num2)).format(formatType ? formatType : "00.00");
981
+ return (0, numeral_1.default)(math.divide(num1, num2)).format(formatType ? formatType : '00.00');
1029
982
  }
1030
983
  catch (err) {
1031
- console.log("🚀 ~ file: util.js:114 ~ divide ~ error:", err);
1032
- return "";
984
+ drapcode_logger_1.logger.error(`🚀 ~ file: util.js:114 ~ divide ~ error: ${err}`);
985
+ return '';
1033
986
  }
1034
987
  };
1035
988
  exports.divide = divide;
1036
989
  const evaluateExpression = function (expression, data, user, formatType, envConstants) {
1037
- expression = expression
1038
- ? (0, exports.getSpecialCharectorReplacedExpression)(expression)
1039
- : " ";
990
+ expression = expression ? (0, exports.getSpecialCharectorReplacedExpression)(expression) : ' ';
1040
991
  const replacedExpression = (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
1041
992
  try {
1042
- return (0, numeral_1.default)(math.evaluate(replacedExpression)).format(formatType ? formatType : "00.00");
993
+ return (0, numeral_1.default)(math.evaluate(replacedExpression)).format(formatType ? formatType : '00.00');
1043
994
  }
1044
995
  catch (err) {
1045
- return "";
996
+ drapcode_logger_1.logger.error(err);
997
+ return '';
1046
998
  }
1047
999
  };
1048
1000
  exports.evaluateExpression = evaluateExpression;
@@ -1057,74 +1009,71 @@ const evaluateCurrency = function (formatType, subject, currency, position, maxF
1057
1009
  subject = new Intl.NumberFormat(formatType, {
1058
1010
  minimumFractionDigits: maxFraction,
1059
1011
  }).format(digit);
1060
- if (currency === "NONE")
1012
+ if (currency === 'NONE')
1061
1013
  return `${subject}`;
1062
- if (currency.startsWith("current_user.")) {
1063
- currency = currency.replace("current_user.", "");
1014
+ if (currency.startsWith('current_user.')) {
1015
+ currency = currency.replace('current_user.', '');
1064
1016
  currency = (0, exports.parseValueFromData)(user, currency);
1065
1017
  }
1066
- else if (currency.startsWith("current_tenant.")) {
1067
- currency = currency.replace("current_tenant.", "");
1018
+ else if (currency.startsWith('current_tenant.')) {
1019
+ currency = currency.replace('current_tenant.', '');
1068
1020
  currency = (0, exports.parseValueFromData)(tenant, currency);
1069
1021
  }
1070
1022
  switch (position) {
1071
- case "FRONT":
1023
+ case 'FRONT':
1072
1024
  return `${currency}${subject}`;
1073
- case "FRONT_WITH_SPACE":
1025
+ case 'FRONT_WITH_SPACE':
1074
1026
  return `${currency} ${subject}`;
1075
- case "BACK":
1027
+ case 'BACK':
1076
1028
  return `${subject}${currency}`;
1077
- case "BACK_WITH_SPACE":
1029
+ case 'BACK_WITH_SPACE':
1078
1030
  return `${subject} ${currency}`;
1079
1031
  default:
1080
- return "";
1032
+ return '';
1081
1033
  }
1082
1034
  }
1083
1035
  catch (error) {
1084
- console.log("error", error);
1085
- return "";
1036
+ drapcode_logger_1.logger.error(error);
1037
+ return '';
1086
1038
  }
1087
1039
  };
1088
1040
  exports.evaluateCurrency = evaluateCurrency;
1089
1041
  const evaluateJSLogic = function (expression, data, user, envConstants) {
1090
- expression = expression
1091
- ? (0, exports.getSpecialCharectorReplacedExpression)(expression)
1092
- : " ";
1042
+ expression = expression ? (0, exports.getSpecialCharectorReplacedExpression)(expression) : ' ';
1093
1043
  // Changing <br/> to /n for js code
1094
- expression = expression.replace(/<br\s*\/?>/g, "\n");
1044
+ expression = expression.replace(/<br\s*\/?>/g, '\n');
1095
1045
  const replacedExpression = (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
1096
1046
  try {
1097
1047
  const replacedExpressionFunction = new Function(replacedExpression.toString());
1098
1048
  return replacedExpressionFunction();
1099
1049
  }
1100
1050
  catch (err) {
1101
- return "";
1051
+ drapcode_logger_1.logger.error(err);
1052
+ return '';
1102
1053
  }
1103
1054
  };
1104
1055
  exports.evaluateJSLogic = evaluateJSLogic;
1105
1056
  const formatDate = function (formatType, datentime, timezone, unixType, offset = false) {
1106
- let formatDateNTime = unixType && unixType === "SEC"
1107
- ? moment_1.default.utc(datentime * 1000)
1108
- : moment_1.default.utc(datentime);
1057
+ let formatDateNTime = unixType && unixType === 'SEC' ? moment_1.default.utc(datentime * 1000) : moment_1.default.utc(datentime);
1109
1058
  if (offset) {
1110
1059
  formatDateNTime = formatDateNTime.utcOffset(timezone);
1111
1060
  }
1112
- if (formatType === "FROM_NOW") {
1113
- return datentime ? formatDateNTime.fromNow() : "";
1061
+ if (formatType === 'FROM_NOW') {
1062
+ return datentime ? formatDateNTime.fromNow() : '';
1114
1063
  }
1115
- return datentime ? formatDateNTime.format(formatType) : "";
1064
+ return datentime ? formatDateNTime.format(formatType) : '';
1116
1065
  };
1117
1066
  exports.formatDate = formatDate;
1118
1067
  const dateDifference = (formatType, datentime1, datentime2, timezone, dateFormat) => {
1119
- let result = "";
1068
+ let result = '';
1120
1069
  const dateExist = !datentime1 || !datentime2;
1121
- const firstDate = datentime1 === "CURRENT_DATE_TIME"
1070
+ const firstDate = datentime1 === 'CURRENT_DATE_TIME'
1122
1071
  ? (0, moment_1.default)().utcOffset(timezone)
1123
1072
  : (0, moment_1.default)(datentime1, dateFormat).utcOffset(timezone);
1124
- const secondDate = datentime2 === "CURRENT_DATE_TIME"
1073
+ const secondDate = datentime2 === 'CURRENT_DATE_TIME'
1125
1074
  ? (0, moment_1.default)().utcOffset(timezone)
1126
1075
  : (0, moment_1.default)(datentime2, dateFormat).utcOffset(timezone);
1127
- const patterns = formatType.split(",");
1076
+ const patterns = formatType.split(',');
1128
1077
  patterns.forEach((format, i) => {
1129
1078
  const diff = firstDate.diff(secondDate, format);
1130
1079
  if (diff < 0) {
@@ -1135,13 +1084,13 @@ const dateDifference = (formatType, datentime1, datentime2, timezone, dateFormat
1135
1084
  }
1136
1085
  result =
1137
1086
  result +
1138
- `${Math.abs(dateExist ? 0 : diff)} ${format.charAt(0).toUpperCase() + format.slice(1)}${i === patterns.length - 1 ? "" : ","} `;
1087
+ `${Math.abs(dateExist ? 0 : diff)} ${format.charAt(0).toUpperCase() + format.slice(1)}${i === patterns.length - 1 ? '' : ','} `;
1139
1088
  });
1140
1089
  return result;
1141
1090
  };
1142
1091
  exports.dateDifference = dateDifference;
1143
1092
  const mergeObjects = (arrayOfObjects, data = null, user = null, tenant = null, userSetting = null, subTenant = null, sessionValue = null, envConstants = null, sessionFormValue = null, dataTransferObject = {}, localStorageValue = {}, cookiesValue = {}) => {
1144
- let object = {};
1093
+ const object = {};
1145
1094
  arrayOfObjects.map((x) => {
1146
1095
  let value = x.value;
1147
1096
  value = (0, exports.replaceTransferObjectValueIntoExpression)(value, dataTransferObject);
@@ -1160,11 +1109,10 @@ const mergeObjects = (arrayOfObjects, data = null, user = null, tenant = null, u
1160
1109
  : value;
1161
1110
  object[x.key] = value;
1162
1111
  });
1163
- console.log("object", object);
1164
1112
  return object;
1165
1113
  };
1166
1114
  exports.mergeObjects = mergeObjects;
1167
- const getFindQuery = (item, customKey = "") => {
1115
+ const getFindQuery = (item, customKey = '') => {
1168
1116
  if (customKey) {
1169
1117
  return { [customKey]: item[customKey] };
1170
1118
  }
@@ -1174,15 +1122,14 @@ exports.getFindQuery = getFindQuery;
1174
1122
  const getFileObjectList = (fileUrls, projectId) => {
1175
1123
  const result = [];
1176
1124
  fileUrls.forEach((url) => {
1177
- const urlSplits = url.split("?")[0].split("/");
1178
- let fileName = urlSplits[urlSplits.length - 1];
1179
- const extension = fileName.substring(fileName.lastIndexOf("."));
1180
- let mimetype = mime_types_1.default.lookup(extension) || "application/octet-stream";
1181
- console.log(mimetype);
1125
+ const urlSplits = url.split('?')[0].split('/');
1126
+ const fileName = urlSplits[urlSplits.length - 1];
1127
+ const extension = fileName.substring(fileName.lastIndexOf('.'));
1128
+ const mimetype = mime_types_1.default.lookup(extension) || 'application/octet-stream';
1182
1129
  const fileJson = {
1183
1130
  uuid: (0, uuid_2.v4)(),
1184
1131
  originalName: fileName,
1185
- contentType: mime_types_1.default.contentType(mimetype) || "application/octet-stream",
1132
+ contentType: mime_types_1.default.contentType(mimetype) || 'application/octet-stream',
1186
1133
  mimeType: mimetype,
1187
1134
  projectId,
1188
1135
  isExternalUrl: true,
@@ -1194,11 +1141,11 @@ const getFileObjectList = (fileUrls, projectId) => {
1194
1141
  };
1195
1142
  exports.getFileObjectList = getFileObjectList;
1196
1143
  const getItemDataForArrayFields = (item, dataSourceItemKey) => {
1197
- if (dataSourceItemKey.indexOf(".") != -1) {
1198
- const parentKey = dataSourceItemKey.substring(0, dataSourceItemKey.lastIndexOf("."));
1144
+ if (dataSourceItemKey.indexOf('.') != -1) {
1145
+ const parentKey = dataSourceItemKey.substring(0, dataSourceItemKey.lastIndexOf('.'));
1199
1146
  const parenteItemData = lodash_1.default.get(item, parentKey);
1200
1147
  if (Array.isArray(parenteItemData)) {
1201
- const lastLevelKey = dataSourceItemKey.substring(dataSourceItemKey.lastIndexOf(".") + 1);
1148
+ const lastLevelKey = dataSourceItemKey.substring(dataSourceItemKey.lastIndexOf('.') + 1);
1202
1149
  const itemFieldData = parenteItemData.map((e) => e[lastLevelKey]);
1203
1150
  return itemFieldData;
1204
1151
  }
@@ -1214,7 +1161,7 @@ const getItemDataForArrayFields = (item, dataSourceItemKey) => {
1214
1161
  };
1215
1162
  exports.getItemDataForArrayFields = getItemDataForArrayFields;
1216
1163
  const getMappingObjKey = (collectionMapping = {}, fieldName) => {
1217
- if (typeof collectionMapping[fieldName] === "object") {
1164
+ if (typeof collectionMapping[fieldName] === 'object') {
1218
1165
  return collectionMapping[fieldName].dataSourceField;
1219
1166
  }
1220
1167
  else {
@@ -1223,7 +1170,7 @@ const getMappingObjKey = (collectionMapping = {}, fieldName) => {
1223
1170
  };
1224
1171
  exports.getMappingObjKey = getMappingObjKey;
1225
1172
  const getFieldSchemaForDataSourcePrimaryId = () => {
1226
- return getPrimaryFieldSchema("Data Source Rest API Primary Id", drapcode_constant_1.REST_API_PRIMAREY_KEY);
1173
+ return getPrimaryFieldSchema('Data Source Rest API Primary Id', drapcode_constant_1.REST_API_PRIMAREY_KEY);
1227
1174
  };
1228
1175
  exports.getFieldSchemaForDataSourcePrimaryId = getFieldSchemaForDataSourcePrimaryId;
1229
1176
  const getPrimaryFieldNameOfDataSource = () => drapcode_constant_1.REST_API_PRIMAREY_KEY;
@@ -1237,27 +1184,27 @@ const getPrimaryFieldSchema = (fieldTitle, fieldName) => ({
1237
1184
  fieldTitle: {
1238
1185
  en: fieldTitle,
1239
1186
  },
1240
- type: "text",
1187
+ type: 'text',
1241
1188
  placeholder: {
1242
1189
  en: fieldTitle,
1243
1190
  },
1244
1191
  validation: {
1245
1192
  min: null,
1246
1193
  max: null,
1247
- regex: "",
1194
+ regex: '',
1248
1195
  allowedFileTypes: [],
1249
1196
  noAllowedFiles: 1,
1250
1197
  },
1251
1198
  refCollection: {
1252
- collectionName: "",
1253
- collectionField: "",
1254
- displayType: "dropdown",
1255
- parentCollectionField: "",
1199
+ collectionName: '',
1200
+ collectionField: '',
1201
+ displayType: 'dropdown',
1202
+ parentCollectionField: '',
1256
1203
  isShowAsText: false,
1257
1204
  },
1258
1205
  extraFieldSetting: {
1259
- dateDisplayType: "date",
1260
- textareaDisplayType: "text-area",
1206
+ dateDisplayType: 'date',
1207
+ textareaDisplayType: 'text-area',
1261
1208
  },
1262
1209
  fieldName: fieldName,
1263
1210
  });
@@ -1266,8 +1213,8 @@ exports.checkFieldValueType = checkFieldValueType;
1266
1213
  const replaceValuesFromObjArr = (dataArr, mappingArray) => {
1267
1214
  return dataArr.map((data) => {
1268
1215
  mappingArray.map((mapping) => {
1269
- let dataValue = data.value.replace(/{{(.*?)}}/g, "$1");
1270
- let mappingValue = mapping[dataValue];
1216
+ const dataValue = data.value.replace(/{{(.*?)}}/g, '$1');
1217
+ const mappingValue = mapping[dataValue];
1271
1218
  if (mappingValue) {
1272
1219
  data.value = data.value.replace(data.value, mappingValue);
1273
1220
  }
@@ -1287,7 +1234,7 @@ const replaceValuesFromRequestMapping = (dataArr, mappingArray) => {
1287
1234
  };
1288
1235
  exports.replaceValuesFromRequestMapping = replaceValuesFromRequestMapping;
1289
1236
  const getAwsSignature = async (axiosConfig, awsSignPluginConfig) => {
1290
- const response = { error: "", data: {} };
1237
+ const response = { error: '', data: {} };
1291
1238
  const { method, headers, url, data } = axiosConfig;
1292
1239
  const parsedUrl = new URL(url);
1293
1240
  if (awsSignPluginConfig) {
@@ -1305,7 +1252,7 @@ const getAwsSignature = async (axiosConfig, awsSignPluginConfig) => {
1305
1252
  return response;
1306
1253
  }
1307
1254
  else
1308
- response.error = "AWS Signature Plugin is not installed.";
1255
+ response.error = 'AWS Signature Plugin is not installed.';
1309
1256
  return response;
1310
1257
  };
1311
1258
  exports.getAwsSignature = getAwsSignature;
@@ -1314,11 +1261,8 @@ exports.getAwsSignature = getAwsSignature;
1314
1261
  */
1315
1262
  const createMySqlConnection = async (config) => {
1316
1263
  try {
1317
- const { host, user, password, database, port, sslEnabled, sslCa, sslCert, sslKey, } = config || {};
1318
- console.log("🚀 ~ createMySqlConnection ~ sslEnabled:", sslEnabled);
1319
- console.log("🚀 ~ createMySqlConnection ~ process.env.MYSQL_SSL_CERT_PATH:", process.env.MYSQL_SSL_CERT_PATH);
1320
- const sslCertsPath = process.env.MYSQL_SSL_CERT_PATH || "./";
1321
- console.log("🚀 ~ createMySqlConnection ~ sslCertsPath:", sslCertsPath);
1264
+ const { host, user, password, database, port, sslEnabled, sslCa, sslCert, sslKey } = config || {};
1265
+ const sslCertsPath = process.env.MYSQL_SSL_CERT_PATH || './';
1322
1266
  let connection = null;
1323
1267
  if (sslEnabled) {
1324
1268
  const connectionOptions = {
@@ -1349,12 +1293,12 @@ const createMySqlConnection = async (config) => {
1349
1293
  port,
1350
1294
  });
1351
1295
  }
1352
- const [rows] = await connection.execute("select ?+? as sum", [2, 2]);
1353
- console.log("==> MySQL createMySqlConnection ~ Testing connection...", rows);
1296
+ const [rows] = await connection.execute('select ?+? as sum', [2, 2]);
1297
+ drapcode_logger_1.logger.info(rows, '==> MySQL createMySqlConnection ~ Testing connection...');
1354
1298
  return connection;
1355
1299
  }
1356
1300
  catch (error) {
1357
- console.error("==> MySQL createMySqlConnection ~ error:", error);
1301
+ drapcode_logger_1.logger.error(`==> MySQL createMySqlConnection ~ error: ${error}`);
1358
1302
  throw error;
1359
1303
  }
1360
1304
  };
@@ -1364,12 +1308,12 @@ exports.createMySqlConnection = createMySqlConnection;
1364
1308
  */
1365
1309
  const buildWhereClause = (searchQuery) => {
1366
1310
  if (!searchQuery)
1367
- return "";
1368
- const params = searchQuery.split("&").map((pair) => {
1369
- const [key, value] = pair.split("=");
1311
+ return '';
1312
+ const params = searchQuery.split('&').map((pair) => {
1313
+ const [key, value] = pair.split('=');
1370
1314
  return `${decodeURIComponent(key)}="${decodeURIComponent(value)}"`;
1371
1315
  });
1372
- return params.length ? ` WHERE ${params.join(" AND ")}` : "";
1316
+ return params.length ? ` WHERE ${params.join(' AND ')}` : '';
1373
1317
  };
1374
1318
  exports.buildWhereClause = buildWhereClause;
1375
1319
  /**
@@ -1377,10 +1321,10 @@ exports.buildWhereClause = buildWhereClause;
1377
1321
  */
1378
1322
  const buildOrderByClause = (sqlSort) => {
1379
1323
  if (sqlSort?.column && sqlSort?.order) {
1380
- const order = sqlSort.order.toUpperCase() === "DESC" ? "DESC" : "ASC";
1324
+ const order = sqlSort.order.toUpperCase() === 'DESC' ? 'DESC' : 'ASC';
1381
1325
  return ` ORDER BY \`${sqlSort.column}\` ${order}`;
1382
1326
  }
1383
- return "";
1327
+ return '';
1384
1328
  };
1385
1329
  exports.buildOrderByClause = buildOrderByClause;
1386
1330
  /**
@@ -1393,7 +1337,7 @@ const buildLimitOffsetClause = (sqlPagination, values) => {
1393
1337
  values.push(parseInt(sqlPagination.limit), parseInt(sqlPagination.offset));
1394
1338
  return ` LIMIT ${limit} OFFSET ${offset}`;
1395
1339
  }
1396
- return "";
1340
+ return '';
1397
1341
  };
1398
1342
  exports.buildLimitOffsetClause = buildLimitOffsetClause;
1399
1343
  /**
@@ -1414,95 +1358,99 @@ const getLastUpdatedId = async (connection, sqlParams) => {
1414
1358
  return lastUpdatedIdRows[0]?.lastId ?? null;
1415
1359
  };
1416
1360
  exports.getLastUpdatedId = getLastUpdatedId;
1417
- const masking = (subject, visibleCharCount = 2, maskPosition = "END", maskCharacter = "*") => {
1361
+ const masking = (subject, visibleCharCount = 2, maskPosition = 'END', maskCharacter = '*') => {
1418
1362
  if (subject === null || subject === undefined)
1419
- return "";
1363
+ return '';
1420
1364
  if (subject === 0)
1421
- return "0";
1365
+ return '0';
1422
1366
  const str = String(subject);
1423
1367
  const visibleCount = parseInt(visibleCharCount, 10);
1424
1368
  if (isNaN(visibleCount) || visibleCount <= 0)
1425
1369
  return str;
1426
- const maskChar = maskCharacter || "*";
1370
+ const maskChar = maskCharacter || '*';
1427
1371
  const length = str.length;
1428
1372
  if (visibleCount >= length)
1429
1373
  return str;
1430
1374
  const maskedPart = maskChar.repeat(length - visibleCount);
1431
- if (maskPosition === "START") {
1375
+ if (maskPosition === 'START') {
1432
1376
  return str.slice(0, visibleCount) + maskedPart;
1433
1377
  }
1434
- else if (maskPosition === "END") {
1378
+ else if (maskPosition === 'END') {
1435
1379
  return maskedPart + str.slice(-visibleCount);
1436
1380
  }
1437
1381
  else {
1438
1382
  const start = Math.floor((length - visibleCount) / 2);
1439
1383
  const end = start + visibleCount;
1440
- return (str.slice(0, start) +
1441
- maskChar.repeat(length - visibleCount) +
1442
- str.slice(end));
1384
+ return str.slice(0, start) + maskChar.repeat(length - visibleCount) + str.slice(end);
1443
1385
  }
1444
1386
  };
1445
1387
  exports.masking = masking;
1446
1388
  const getArgsFromKey = (key, field, loggedInUserData, projectConstant = {}, envConstants, collectionConstant = {}, browserStorageData) => {
1447
- const { sessionValue, sessionFormValue, sessionStorageData, localStorageData, cookiesData, } = browserStorageData || {};
1448
- let value = "";
1449
- if (key.includes("current_user.")) {
1450
- const userKey = key.split(".")[1];
1389
+ const { sessionValue, sessionFormValue, sessionStorageData, localStorageData, cookiesData } = browserStorageData || {};
1390
+ let value = '';
1391
+ if (key.includes('current_user.')) {
1392
+ const userKey = key.split('.')[1];
1451
1393
  value = (0, exports.parseValueFromData)(loggedInUserData, userKey);
1452
1394
  }
1453
- else if (key.includes("current_user_reference_field.")) {
1454
- const [userRefFieldName, newKey] = key
1455
- .replace("current_user_reference_field.", "")
1456
- .split(".");
1395
+ else if (key.includes('current_user_reference_field.')) {
1396
+ const [userRefFieldName, newKey] = key.replace('current_user_reference_field.', '').split('.');
1457
1397
  const userRefField = loggedInUserData?.[userRefFieldName];
1458
- value = userRefField ? userRefField[0]?.[newKey] : "";
1398
+ value = userRefField ? userRefField[0]?.[newKey] : '';
1459
1399
  }
1460
- else if (key.includes("createdBy.")) {
1461
- const newKey = key.split(".")[1];
1400
+ else if (key.includes('createdBy.')) {
1401
+ const newKey = key.split('.')[1];
1462
1402
  const createdBy = field?.createdBy;
1463
1403
  value = createdBy[0]?.[newKey];
1464
1404
  }
1465
- else if (key.includes("environment_variable.")) {
1466
- const envConstantName = key.split("environment_variable.")[1];
1405
+ else if (key.includes('environment_variable.')) {
1406
+ const envConstantName = key.split('environment_variable.')[1];
1467
1407
  value = envConstants.find((constant) => constant.name === envConstantName).value;
1468
1408
  }
1469
- else if (key.includes("RF::")) {
1470
- const refName = key.replace("RF::", "");
1409
+ else if (key.includes('RF::')) {
1410
+ const refName = key.replace('RF::', '');
1471
1411
  value = (0, exports.parseValueFromData)(field, refName);
1472
1412
  }
1473
- else if (key.includes("PC::")) {
1474
- const projectConstantName = key.split("PC::")[1];
1413
+ else if (key.includes('PC::')) {
1414
+ const projectConstantName = key.split('PC::')[1];
1475
1415
  const projectConst = projectConstant.find((constant) => constant.name === projectConstantName);
1476
1416
  value = projectConst?.value;
1477
1417
  }
1478
- else if (key.includes("CC::")) {
1479
- const collectionConstantName = key.split("CC::")[1];
1418
+ else if (key.includes('CC::')) {
1419
+ const collectionConstantName = key.split('CC::')[1];
1480
1420
  const collectionConst = collectionConstant.find((constant) => constant.name === collectionConstantName);
1481
1421
  value = collectionConst?.value;
1482
1422
  }
1483
- else if (key.includes("current_session.")) {
1484
- const sessionKey = key.replace("current_session.", "");
1423
+ else if (key.includes('current_session.')) {
1424
+ const sessionKey = key.replace('current_session.', '');
1485
1425
  value = (0, exports.parseValueFromData)(sessionValue, sessionKey);
1486
1426
  }
1487
- else if (key.includes("form_data_session.")) {
1488
- const sessionKey = key.replace("form_data_session.", "");
1427
+ else if (key.includes('form_data_session.')) {
1428
+ const sessionKey = key.replace('form_data_session.', '');
1489
1429
  value = (0, exports.parseValueFromData)(sessionFormValue, sessionKey);
1490
1430
  }
1491
- else if (key.includes("SESSION_STORAGE.")) {
1492
- const sessionKey = key.replace("SESSION_STORAGE.", "");
1431
+ else if (key.includes('SESSION_STORAGE.')) {
1432
+ const sessionKey = key.replace('SESSION_STORAGE.', '');
1493
1433
  value = (0, exports.parseValueFromData)(sessionStorageData, sessionKey);
1494
1434
  }
1495
- else if (key.includes("LOCAL_STORAGE.")) {
1496
- const sessionKey = key.replace("LOCAL_STORAGE.", "");
1435
+ else if (key.includes('LOCAL_STORAGE.')) {
1436
+ const sessionKey = key.replace('LOCAL_STORAGE.', '');
1497
1437
  value = (0, exports.parseValueFromData)(localStorageData, sessionKey);
1498
1438
  }
1499
- else if (key.includes("COOKIES.")) {
1500
- const sessionKey = key.replace("COOKIES.", "");
1439
+ else if (key.includes('COOKIES.')) {
1440
+ const sessionKey = key.replace('COOKIES.', '');
1501
1441
  value = (0, exports.parseValueFromData)(cookiesData, sessionKey);
1502
1442
  }
1503
1443
  else {
1504
- value = "";
1444
+ value = '';
1505
1445
  }
1506
1446
  return value;
1507
1447
  };
1508
1448
  exports.getArgsFromKey = getArgsFromKey;
1449
+ const slugifyFileName = (fileName) => {
1450
+ return fileName
1451
+ .replace(/\s+/g, '_') // Replace spaces with underscores
1452
+ .replace(/[^a-zA-Z0-9._]/g, '') // Remove anything that's not a letter, number, dot, or underscore
1453
+ .toLowerCase(); // Convert to lowercase
1454
+ };
1455
+ exports.slugifyFileName = slugifyFileName;
1456
+ //# sourceMappingURL=util.js.map