drapcode-utility 2.5.4 → 2.5.6

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.
@@ -99,7 +99,7 @@ export declare const average: (formatType: string, { numbers }: any) => string;
99
99
  export declare const multiply: (formatType: string, { numbers }: any) => string;
100
100
  export declare const divide: (formatType: string, { number1, number2 }: any) => string;
101
101
  export declare const evaluateExpression: (expression: string, data: any, user: any, formatType: string, envConstants: any) => string;
102
- export declare const evaluateCurrency: (formatType: string, subject: number | string | any, currency: string, position: string, maxFraction: number) => string;
102
+ export declare const evaluateCurrency: (formatType: string, subject: number | string | any, currency: string, position: string, maxFraction: number, user?: any, tenant?: any) => string;
103
103
  export declare const evaluateJSLogic: (expression: string, data: any, user: any, envConstants: any) => any;
104
104
  export declare const formatDate: (formatType: string, datentime: any, timezone: string, unixType: any, offset?: boolean) => string;
105
105
  export declare const dateDifference: (formatType: string, datentime1: any, datentime2: any, timezone: string) => string;
@@ -180,4 +180,5 @@ export declare const getTotalRecords: (connection: any, sqlQuery: string, sqlPar
180
180
  */
181
181
  export declare const getLastUpdatedId: (connection: any, sqlParams: any[]) => Promise<number | null>;
182
182
  export declare const masking: (subject: string | number, visibleCharCount?: number | string, maskPosition?: "START" | "END" | "MIDDLE", maskCharacter?: string) => string;
183
+ export declare const getArgsFromKey: (key: any, field: any, loggedInUserData: any, projectConstant: any | undefined, envConstants: any, collectionConstant: any | undefined, browserStorageData: any) => string;
183
184
  export {};
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
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.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;
7
+ 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;
8
8
  const drapcode_constant_1 = require("drapcode-constant");
9
9
  const lodash_1 = __importDefault(require("lodash"));
10
10
  const showdown_1 = __importDefault(require("showdown"));
@@ -302,7 +302,18 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
302
302
  console.log("1 replaceDataValueIntoExpression");
303
303
  contentList?.forEach((prop) => {
304
304
  const needle = `{{${prop}}}`;
305
+ prop = voca_1.default.trim(prop);
305
306
  let dataOfItem = "";
307
+ const isDynamicField = [
308
+ "RF::",
309
+ "PC::",
310
+ "CC::",
311
+ "current_user_reference_field.",
312
+ "createdBy.",
313
+ "environment_variable.",
314
+ "current_session.",
315
+ "form_data_session.",
316
+ ].some((str) => prop.includes(str));
306
317
  if (prop.includes("current_user") && user) {
307
318
  prop = prop.replace("current_user.", "");
308
319
  if (Object.keys(user).length > 0) {
@@ -327,20 +338,6 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
327
338
  dataOfItem = (0, exports.parseValueFromData)(subTenant, prop);
328
339
  }
329
340
  }
330
- else if (prop.includes("current_session")) {
331
- prop = prop.replace("current_session.", "");
332
- if (Object.keys(sessionValue).length > 0) {
333
- //Session will contain multi level data
334
- dataOfItem = lodash_1.default.get(sessionValue, prop);
335
- }
336
- }
337
- else if (prop.includes("form_data_session")) {
338
- prop = prop.replace("form_data_session.", "");
339
- if (Object.keys(sessionFormValue).length > 0) {
340
- //Form Session will contain multi level data
341
- dataOfItem = lodash_1.default.get(sessionFormValue, prop);
342
- }
343
- }
344
341
  else if (prop.includes("SESSION_STORAGE")) {
345
342
  prop = prop.replace("SESSION_STORAGE.", "");
346
343
  if (Object.keys(sessionValue).length > 0) {
@@ -362,12 +359,14 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
362
359
  dataOfItem = lodash_1.default.get(cookiesValue, prop);
363
360
  }
364
361
  }
365
- else if (prop.includes("environment_variable")) {
366
- prop = prop.replace("environment_variable.", "");
367
- if (Object.keys(envConstants).length > 0) {
368
- const selectedConstant = envConstants.find((constant) => constant.name === prop);
369
- dataOfItem = selectedConstant ? selectedConstant.value : "";
370
- }
362
+ else if (isDynamicField) {
363
+ dataOfItem = (0, exports.getArgsFromKey)(prop, data, user, {}, envConstants, {}, {
364
+ sessionValue,
365
+ sessionFormValue,
366
+ sessionStorageData: sessionValue,
367
+ localStorageData: localStorageValue,
368
+ cookiesData: cookiesValue,
369
+ });
371
370
  }
372
371
  else {
373
372
  if (Object.keys(data).length > 0) {
@@ -408,19 +407,21 @@ const parseJsonString = (str) => {
408
407
  exports.parseJsonString = parseJsonString;
409
408
  const parseValueFromData = (data, fieldName) => {
410
409
  let value = "";
410
+ let valueIndex = "";
411
+ let valueIndexFieldName = "";
411
412
  if (fieldName && fieldName.includes(".")) {
412
413
  let fullNameParts = fieldName.split(".");
413
414
  let prefix = "";
414
- let stack = data || "";
415
+ let stack = data || {};
415
416
  for (let k = 0; k < fullNameParts.length; k++) {
416
417
  prefix = fullNameParts[k];
417
- if (Array.isArray(stack)) {
418
+ if (stack && Array.isArray(stack)) {
418
419
  stack[prefix] = stack.map((item) => {
419
420
  if (item[prefix])
420
421
  return item[prefix];
421
422
  });
422
423
  }
423
- if (stack && stack[prefix] === undefined) {
424
+ if (stack && !stack[prefix]) {
424
425
  stack[prefix] = "";
425
426
  }
426
427
  stack = stack[prefix];
@@ -430,14 +431,57 @@ const parseValueFromData = (data, fieldName) => {
430
431
  value = value.filter(() => true);
431
432
  }
432
433
  }
434
+ else if (fieldName && fieldName.includes("[")) {
435
+ //Todo: Need to Refactor
436
+ let fullNameParts = fieldName.split("[");
437
+ let prefix = "";
438
+ let stack = data || {};
439
+ for (let k = 0; k < fullNameParts.length - 1; k++) {
440
+ const cValue = fullNameParts[k];
441
+ const nValue = fullNameParts[k + 1];
442
+ prefix = cValue ? (!cValue.includes("]") ? cValue : "") : "";
443
+ valueIndex = nValue
444
+ ? nValue.includes("]")
445
+ ? nValue.split("]")[0]
446
+ : nValue
447
+ : "";
448
+ if (stack && Array.isArray(stack)) {
449
+ stack[prefix] = stack.map((item) => {
450
+ if (item[prefix])
451
+ return item[prefix];
452
+ });
453
+ }
454
+ if (stack && !stack[prefix]) {
455
+ stack[prefix] = "";
456
+ }
457
+ stack = valueIndex ? stack[prefix][valueIndex] : stack[prefix];
458
+ if (fieldName.includes("]:")) {
459
+ valueIndexFieldName = nValue.split("]:")[1];
460
+ if (valueIndexFieldName) {
461
+ stack = stack[valueIndexFieldName];
462
+ }
463
+ }
464
+ }
465
+ value = stack ? stack : "";
466
+ if (Array.isArray(value)) {
467
+ value = value.filter(() => true);
468
+ }
469
+ }
433
470
  else {
434
471
  value = data ? data[fieldName] : "";
435
472
  }
473
+ if (value && Array.isArray(value) && value.length === 1)
474
+ return value[0];
436
475
  if (value && Array.isArray(value) && typeof value[0] === "string") {
437
- return value.join(", ");
476
+ return value.join(",");
438
477
  }
439
- if (typeof value !== undefined && typeof value === "number") {
440
- return value.toString();
478
+ if (!value || value == "undefined" || value === "undefined") {
479
+ if (value === 0) {
480
+ value = "0";
481
+ }
482
+ else {
483
+ value = "";
484
+ }
441
485
  }
442
486
  return value;
443
487
  };
@@ -965,7 +1009,7 @@ const evaluateExpression = function (expression, data, user, formatType, envCons
965
1009
  }
966
1010
  };
967
1011
  exports.evaluateExpression = evaluateExpression;
968
- const evaluateCurrency = function (formatType, subject, currency, position, maxFraction) {
1012
+ const evaluateCurrency = function (formatType, subject, currency, position, maxFraction, user = {}, tenant = {}) {
969
1013
  try {
970
1014
  if (!subject)
971
1015
  subject = 0;
@@ -978,6 +1022,14 @@ const evaluateCurrency = function (formatType, subject, currency, position, maxF
978
1022
  }).format(digit);
979
1023
  if (currency === "NONE")
980
1024
  return `${subject}`;
1025
+ if (currency.startsWith("current_user.")) {
1026
+ currency = currency.replace("current_user.", "");
1027
+ currency = (0, exports.parseValueFromData)(user, currency);
1028
+ }
1029
+ else if (currency.startsWith("current_tenant.")) {
1030
+ currency = currency.replace("current_tenant.", "");
1031
+ currency = (0, exports.parseValueFromData)(tenant, currency);
1032
+ }
981
1033
  switch (position) {
982
1034
  case "FRONT":
983
1035
  return `${currency}${subject}`;
@@ -1325,3 +1377,66 @@ const masking = (subject, visibleCharCount = 2, maskPosition = "END", maskCharac
1325
1377
  }
1326
1378
  };
1327
1379
  exports.masking = masking;
1380
+ const getArgsFromKey = (key, field, loggedInUserData, projectConstant = {}, envConstants, collectionConstant = {}, browserStorageData) => {
1381
+ const { sessionValue, sessionFormValue, sessionStorageData, localStorageData, cookiesData, } = browserStorageData || {};
1382
+ let value = "";
1383
+ if (key.includes("current_user.")) {
1384
+ const userKey = key.split(".")[1];
1385
+ value = (0, exports.parseValueFromData)(loggedInUserData, userKey);
1386
+ }
1387
+ else if (key.includes("current_user_reference_field.")) {
1388
+ const [userRefFieldName, newKey] = key
1389
+ .replace("current_user_reference_field.", "")
1390
+ .split(".");
1391
+ const userRefField = loggedInUserData?.[userRefFieldName];
1392
+ value = userRefField ? userRefField[0]?.[newKey] : "";
1393
+ }
1394
+ else if (key.includes("createdBy.")) {
1395
+ const newKey = key.split(".")[1];
1396
+ const createdBy = field?.createdBy;
1397
+ value = createdBy[0]?.[newKey];
1398
+ }
1399
+ else if (key.includes("environment_variable.")) {
1400
+ const envConstantName = key.split("environment_variable.")[1];
1401
+ value = envConstants.find((constant) => constant.name === envConstantName).value;
1402
+ }
1403
+ else if (key.includes("RF::")) {
1404
+ const refName = key.replace("RF::", "");
1405
+ value = (0, exports.parseValueFromData)(field, refName);
1406
+ }
1407
+ else if (key.includes("PC::")) {
1408
+ const projectConstantName = key.split("PC::")[1];
1409
+ const projectConst = projectConstant.find((constant) => constant.name === projectConstantName);
1410
+ value = projectConst?.value;
1411
+ }
1412
+ else if (key.includes("CC::")) {
1413
+ const collectionConstantName = key.split("CC::")[1];
1414
+ const collectionConst = collectionConstant.find((constant) => constant.name === collectionConstantName);
1415
+ value = collectionConst?.value;
1416
+ }
1417
+ else if (key.includes("current_session.")) {
1418
+ const sessionKey = key.replace("current_session.", "");
1419
+ value = (0, exports.parseValueFromData)(sessionValue, sessionKey);
1420
+ }
1421
+ else if (key.includes("form_data_session.")) {
1422
+ const sessionKey = key.replace("form_data_session.", "");
1423
+ value = (0, exports.parseValueFromData)(sessionFormValue, sessionKey);
1424
+ }
1425
+ else if (key.includes("SESSION_STORAGE.")) {
1426
+ const sessionKey = key.replace("SESSION_STORAGE.", "");
1427
+ value = (0, exports.parseValueFromData)(sessionStorageData, sessionKey);
1428
+ }
1429
+ else if (key.includes("LOCAL_STORAGE.")) {
1430
+ const sessionKey = key.replace("LOCAL_STORAGE.", "");
1431
+ value = (0, exports.parseValueFromData)(localStorageData, sessionKey);
1432
+ }
1433
+ else if (key.includes("COOKIES.")) {
1434
+ const sessionKey = key.replace("COOKIES.", "");
1435
+ value = (0, exports.parseValueFromData)(cookiesData, sessionKey);
1436
+ }
1437
+ else {
1438
+ value = "";
1439
+ }
1440
+ return value;
1441
+ };
1442
+ exports.getArgsFromKey = getArgsFromKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "2.5.4",
3
+ "version": "2.5.6",
4
4
  "description": "DrapCode Utility",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -42,9 +42,9 @@
42
42
  "axios": "^1.1.2",
43
43
  "date-fns": "^4.1.0",
44
44
  "dompurify": "^3.1.7",
45
- "drapcode-constant": "^2.0.4",
46
- "drapcode-logger": "^1.3.5",
47
- "drapcode-redis": "^1.5.1",
45
+ "drapcode-constant": "^2.0.5",
46
+ "drapcode-logger": "^1.3.6",
47
+ "drapcode-redis": "^1.5.2",
48
48
  "exiftool-vendored": "^28.2.1",
49
49
  "express": "^4.17.1",
50
50
  "gm": "^1.25.0",