drapcode-utility 2.5.5 → 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.
- package/build/utils/util.d.ts +2 -1
- package/build/utils/util.js +92 -22
- package/package.json +1 -1
package/build/utils/util.d.ts
CHANGED
|
@@ -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 {};
|
package/build/utils/util.js
CHANGED
|
@@ -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 (
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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) {
|
|
@@ -1010,7 +1009,7 @@ const evaluateExpression = function (expression, data, user, formatType, envCons
|
|
|
1010
1009
|
}
|
|
1011
1010
|
};
|
|
1012
1011
|
exports.evaluateExpression = evaluateExpression;
|
|
1013
|
-
const evaluateCurrency = function (formatType, subject, currency, position, maxFraction) {
|
|
1012
|
+
const evaluateCurrency = function (formatType, subject, currency, position, maxFraction, user = {}, tenant = {}) {
|
|
1014
1013
|
try {
|
|
1015
1014
|
if (!subject)
|
|
1016
1015
|
subject = 0;
|
|
@@ -1023,6 +1022,14 @@ const evaluateCurrency = function (formatType, subject, currency, position, maxF
|
|
|
1023
1022
|
}).format(digit);
|
|
1024
1023
|
if (currency === "NONE")
|
|
1025
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
|
+
}
|
|
1026
1033
|
switch (position) {
|
|
1027
1034
|
case "FRONT":
|
|
1028
1035
|
return `${currency}${subject}`;
|
|
@@ -1370,3 +1377,66 @@ const masking = (subject, visibleCharCount = 2, maskPosition = "END", maskCharac
|
|
|
1370
1377
|
}
|
|
1371
1378
|
};
|
|
1372
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;
|