drapcode-utility 2.5.5 → 2.5.7

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.
@@ -330,15 +330,31 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
330
330
  values.push(fileData);
331
331
  });
332
332
  }
333
- const { mysqlDbHostUrl, mysqlDbUser, mysqlDbPassword, mysqlDbName, mysqlDbPort } = extDbSetting || {};
333
+ const { mysqlDbHostUrl, mysqlDbUser, mysqlDbPassword, mysqlDbName, mysqlDbPort, mysqlDbSslEnabled, mysqlDbSslCa, mysqlDbSslCert, mysqlDbSslKey } = extDbSetting || {};
334
334
  const mysqlDBConfig = {
335
335
  host: mysqlDbHostUrl,
336
336
  user: mysqlDbUser,
337
337
  password: mysqlDbPassword,
338
338
  database: mysqlDbName,
339
339
  port: mysqlDbPort,
340
+ sslEnabled: mysqlDbSslEnabled,
341
+ sslCa: '',
342
+ sslCert: '',
343
+ sslKey: ''
340
344
  };
345
+ if (mysqlDbSslEnabled) {
346
+ if (mysqlDbSslCa) {
347
+ mysqlDBConfig.sslCa = mysqlDbSslCa;
348
+ }
349
+ if (mysqlDbSslCert) {
350
+ mysqlDBConfig.sslCert = mysqlDbSslCert;
351
+ }
352
+ if (mysqlDbSslKey) {
353
+ mysqlDBConfig.sslKey = mysqlDbSslKey;
354
+ }
355
+ }
341
356
  console.log(`==> Final MySQL projectID: ${projectId} ~ data:>> `, data, " ~ query type :>> ", operation, " ~ finalSql:>> ", finalSql, " ~ values:>> ", values);
357
+ console.log("🚀 ~ makeMySqlCall ~ process.env.MYSQL_SSL_CERT_PATH:", process.env.MYSQL_SSL_CERT_PATH);
342
358
  const connection = await (0, util_1.createMySqlConnection)(mysqlDBConfig);
343
359
  try {
344
360
  const [rows] = await connection.execute(finalSql, values);
@@ -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"));
@@ -17,6 +17,7 @@ const moment_1 = __importDefault(require("moment"));
17
17
  const mime_types_1 = __importDefault(require("mime-types"));
18
18
  const uuid_2 = require("uuid");
19
19
  const aws4_1 = require("aws4");
20
+ const fs_1 = __importDefault(require("fs"));
20
21
  const mysql = require("mysql2/promise");
21
22
  exports.nonFindQuery = ["COUNT", "SUM", "AVG", "MIN", "MAX"];
22
23
  // Constants
@@ -302,7 +303,18 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
302
303
  console.log("1 replaceDataValueIntoExpression");
303
304
  contentList?.forEach((prop) => {
304
305
  const needle = `{{${prop}}}`;
306
+ prop = voca_1.default.trim(prop);
305
307
  let dataOfItem = "";
308
+ const isDynamicField = [
309
+ "RF::",
310
+ "PC::",
311
+ "CC::",
312
+ "current_user_reference_field.",
313
+ "createdBy.",
314
+ "environment_variable.",
315
+ "current_session.",
316
+ "form_data_session.",
317
+ ].some((str) => prop.includes(str));
306
318
  if (prop.includes("current_user") && user) {
307
319
  prop = prop.replace("current_user.", "");
308
320
  if (Object.keys(user).length > 0) {
@@ -327,20 +339,6 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
327
339
  dataOfItem = (0, exports.parseValueFromData)(subTenant, prop);
328
340
  }
329
341
  }
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
342
  else if (prop.includes("SESSION_STORAGE")) {
345
343
  prop = prop.replace("SESSION_STORAGE.", "");
346
344
  if (Object.keys(sessionValue).length > 0) {
@@ -362,12 +360,14 @@ const replaceDataValueIntoExpression = (expression, data, user, tenant, userSett
362
360
  dataOfItem = lodash_1.default.get(cookiesValue, prop);
363
361
  }
364
362
  }
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
- }
363
+ else if (isDynamicField) {
364
+ dataOfItem = (0, exports.getArgsFromKey)(prop, data, user, {}, envConstants, {}, {
365
+ sessionValue,
366
+ sessionFormValue,
367
+ sessionStorageData: sessionValue,
368
+ localStorageData: localStorageValue,
369
+ cookiesData: cookiesValue,
370
+ });
371
371
  }
372
372
  else {
373
373
  if (Object.keys(data).length > 0) {
@@ -1010,7 +1010,7 @@ const evaluateExpression = function (expression, data, user, formatType, envCons
1010
1010
  }
1011
1011
  };
1012
1012
  exports.evaluateExpression = evaluateExpression;
1013
- const evaluateCurrency = function (formatType, subject, currency, position, maxFraction) {
1013
+ const evaluateCurrency = function (formatType, subject, currency, position, maxFraction, user = {}, tenant = {}) {
1014
1014
  try {
1015
1015
  if (!subject)
1016
1016
  subject = 0;
@@ -1023,6 +1023,14 @@ const evaluateCurrency = function (formatType, subject, currency, position, maxF
1023
1023
  }).format(digit);
1024
1024
  if (currency === "NONE")
1025
1025
  return `${subject}`;
1026
+ if (currency.startsWith("current_user.")) {
1027
+ currency = currency.replace("current_user.", "");
1028
+ currency = (0, exports.parseValueFromData)(user, currency);
1029
+ }
1030
+ else if (currency.startsWith("current_tenant.")) {
1031
+ currency = currency.replace("current_tenant.", "");
1032
+ currency = (0, exports.parseValueFromData)(tenant, currency);
1033
+ }
1026
1034
  switch (position) {
1027
1035
  case "FRONT":
1028
1036
  return `${currency}${subject}`;
@@ -1268,14 +1276,41 @@ exports.getAwsSignature = getAwsSignature;
1268
1276
  */
1269
1277
  const createMySqlConnection = async (config) => {
1270
1278
  try {
1271
- const { host, user, password, database, port } = config || {};
1272
- const connection = await mysql.createConnection({
1273
- host: host,
1274
- user: user,
1275
- password: password,
1276
- database: database,
1277
- port: port,
1278
- });
1279
+ const { host, user, password, database, port, sslEnabled, sslCa, sslCert, sslKey } = config || {};
1280
+ console.log("🚀 ~ createMySqlConnection ~ sslEnabled:", sslEnabled);
1281
+ console.log("🚀 ~ createMySqlConnection ~ process.env.MYSQL_SSL_CERT_PATH:", process.env.MYSQL_SSL_CERT_PATH);
1282
+ const sslCertsPath = process.env.MYSQL_SSL_CERT_PATH || './';
1283
+ console.log("🚀 ~ createMySqlConnection ~ sslCertsPath:", sslCertsPath);
1284
+ let connection = null;
1285
+ if (sslEnabled) {
1286
+ const connectionOptions = {
1287
+ host,
1288
+ user,
1289
+ password,
1290
+ database,
1291
+ port,
1292
+ ssl: {}
1293
+ };
1294
+ if (sslCa) {
1295
+ connectionOptions.ssl.ca = fs_1.default.readFileSync(`${sslCertsPath}${sslCa}`);
1296
+ }
1297
+ if (sslCert) {
1298
+ connectionOptions.ssl.cert = fs_1.default.readFileSync(`${sslCertsPath}${sslCert}`);
1299
+ }
1300
+ if (sslKey) {
1301
+ connectionOptions.ssl.key = fs_1.default.readFileSync(`${sslCertsPath}${sslKey}`);
1302
+ }
1303
+ connection = await mysql.createConnection(connectionOptions);
1304
+ }
1305
+ else {
1306
+ connection = await mysql.createConnection({
1307
+ host,
1308
+ user,
1309
+ password,
1310
+ database,
1311
+ port,
1312
+ });
1313
+ }
1279
1314
  const [rows] = await connection.execute("select ?+? as sum", [2, 2]);
1280
1315
  console.log("==> MySQL createMySqlConnection ~ Testing connection...", rows);
1281
1316
  return connection;
@@ -1370,3 +1405,66 @@ const masking = (subject, visibleCharCount = 2, maskPosition = "END", maskCharac
1370
1405
  }
1371
1406
  };
1372
1407
  exports.masking = masking;
1408
+ const getArgsFromKey = (key, field, loggedInUserData, projectConstant = {}, envConstants, collectionConstant = {}, browserStorageData) => {
1409
+ const { sessionValue, sessionFormValue, sessionStorageData, localStorageData, cookiesData, } = browserStorageData || {};
1410
+ let value = "";
1411
+ if (key.includes("current_user.")) {
1412
+ const userKey = key.split(".")[1];
1413
+ value = (0, exports.parseValueFromData)(loggedInUserData, userKey);
1414
+ }
1415
+ else if (key.includes("current_user_reference_field.")) {
1416
+ const [userRefFieldName, newKey] = key
1417
+ .replace("current_user_reference_field.", "")
1418
+ .split(".");
1419
+ const userRefField = loggedInUserData?.[userRefFieldName];
1420
+ value = userRefField ? userRefField[0]?.[newKey] : "";
1421
+ }
1422
+ else if (key.includes("createdBy.")) {
1423
+ const newKey = key.split(".")[1];
1424
+ const createdBy = field?.createdBy;
1425
+ value = createdBy[0]?.[newKey];
1426
+ }
1427
+ else if (key.includes("environment_variable.")) {
1428
+ const envConstantName = key.split("environment_variable.")[1];
1429
+ value = envConstants.find((constant) => constant.name === envConstantName).value;
1430
+ }
1431
+ else if (key.includes("RF::")) {
1432
+ const refName = key.replace("RF::", "");
1433
+ value = (0, exports.parseValueFromData)(field, refName);
1434
+ }
1435
+ else if (key.includes("PC::")) {
1436
+ const projectConstantName = key.split("PC::")[1];
1437
+ const projectConst = projectConstant.find((constant) => constant.name === projectConstantName);
1438
+ value = projectConst?.value;
1439
+ }
1440
+ else if (key.includes("CC::")) {
1441
+ const collectionConstantName = key.split("CC::")[1];
1442
+ const collectionConst = collectionConstant.find((constant) => constant.name === collectionConstantName);
1443
+ value = collectionConst?.value;
1444
+ }
1445
+ else if (key.includes("current_session.")) {
1446
+ const sessionKey = key.replace("current_session.", "");
1447
+ value = (0, exports.parseValueFromData)(sessionValue, sessionKey);
1448
+ }
1449
+ else if (key.includes("form_data_session.")) {
1450
+ const sessionKey = key.replace("form_data_session.", "");
1451
+ value = (0, exports.parseValueFromData)(sessionFormValue, sessionKey);
1452
+ }
1453
+ else if (key.includes("SESSION_STORAGE.")) {
1454
+ const sessionKey = key.replace("SESSION_STORAGE.", "");
1455
+ value = (0, exports.parseValueFromData)(sessionStorageData, sessionKey);
1456
+ }
1457
+ else if (key.includes("LOCAL_STORAGE.")) {
1458
+ const sessionKey = key.replace("LOCAL_STORAGE.", "");
1459
+ value = (0, exports.parseValueFromData)(localStorageData, sessionKey);
1460
+ }
1461
+ else if (key.includes("COOKIES.")) {
1462
+ const sessionKey = key.replace("COOKIES.", "");
1463
+ value = (0, exports.parseValueFromData)(cookiesData, sessionKey);
1464
+ }
1465
+ else {
1466
+ value = "";
1467
+ }
1468
+ return value;
1469
+ };
1470
+ exports.getArgsFromKey = getArgsFromKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "2.5.5",
3
+ "version": "2.5.7",
4
4
  "description": "DrapCode Utility",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",