drapcode-utility 2.5.0 → 2.5.1-preview

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.
@@ -155,7 +155,7 @@ const callCurlRequest = async (setting, user = {}, tenant = {}, userSetting = {}
155
155
  return prepareReturnObject(result.data, result.status, result?.success || (result.status >= 200 && result.status < 300), result?.headers, result?.mysqlError);
156
156
  }
157
157
  else {
158
- result = await makeAxiosCall(projectId, methodType, url, headerValue, data, timeout, wrapJsonDataInArray, awsSignPluginConfig);
158
+ result = await makeAxiosCall(projectId, methodType, url, headerValue, data, timeout, wrapJsonDataInArray, awsSignPluginConfig, dtoExternalAPI);
159
159
  }
160
160
  drapcode_logger_1.logger.info(`result.headers: ${result?.headers}`, { label: projectId });
161
161
  if (!result) {
@@ -234,14 +234,19 @@ const prepareReturnObject = (data, status = 400, success = false, headers = {},
234
234
  };
235
235
  }
236
236
  };
237
- const makeAxiosCall = async (projectId, methodType, url, axiosConfig, data, timeout, wrapJsonDataInArray, awsSignPluginConfig) => {
237
+ const makeAxiosCall = async (projectId, methodType, url, axiosConfig, data, timeout, wrapJsonDataInArray, awsSignPluginConfig, dtoExternalAPI) => {
238
238
  axiosConfig = { url, method: methodType, ...axiosConfig };
239
239
  let result = "";
240
240
  const instance = axios_1.default.create();
241
241
  instance.defaults.timeout = timeout * 1000;
242
+ const { dtoBodyDataFrom } = dtoExternalAPI || {};
243
+ const isNoBodyData = !dtoBodyDataFrom || dtoBodyDataFrom === "noDynamicData";
244
+ console.log(`\n ==> isNoBodyData for projectID: ${projectId}:`, isNoBodyData);
242
245
  switch (methodType) {
243
246
  case "GET":
244
- axiosConfig["data"] = data ? data : {};
247
+ if (!isNoBodyData) {
248
+ axiosConfig["data"] = data ? data : {};
249
+ }
245
250
  break;
246
251
  case "POST":
247
252
  case "PUT":
@@ -408,19 +408,21 @@ const parseJsonString = (str) => {
408
408
  exports.parseJsonString = parseJsonString;
409
409
  const parseValueFromData = (data, fieldName) => {
410
410
  let value = "";
411
+ let valueIndex = "";
412
+ let valueIndexFieldName = "";
411
413
  if (fieldName && fieldName.includes(".")) {
412
414
  let fullNameParts = fieldName.split(".");
413
415
  let prefix = "";
414
- let stack = data || "";
416
+ let stack = data || {};
415
417
  for (let k = 0; k < fullNameParts.length; k++) {
416
418
  prefix = fullNameParts[k];
417
- if (Array.isArray(stack)) {
419
+ if (stack && Array.isArray(stack)) {
418
420
  stack[prefix] = stack.map((item) => {
419
421
  if (item[prefix])
420
422
  return item[prefix];
421
423
  });
422
424
  }
423
- if (stack && stack[prefix] === undefined) {
425
+ if (stack && !stack[prefix]) {
424
426
  stack[prefix] = "";
425
427
  }
426
428
  stack = stack[prefix];
@@ -430,14 +432,57 @@ const parseValueFromData = (data, fieldName) => {
430
432
  value = value.filter(() => true);
431
433
  }
432
434
  }
435
+ else if (fieldName && fieldName.includes("[")) {
436
+ //Todo: Need to Refactor
437
+ let fullNameParts = fieldName.split("[");
438
+ let prefix = "";
439
+ let stack = data || {};
440
+ for (let k = 0; k < fullNameParts.length - 1; k++) {
441
+ const cValue = fullNameParts[k];
442
+ const nValue = fullNameParts[k + 1];
443
+ prefix = cValue ? (!cValue.includes("]") ? cValue : "") : "";
444
+ valueIndex = nValue
445
+ ? nValue.includes("]")
446
+ ? nValue.split("]")[0]
447
+ : nValue
448
+ : "";
449
+ if (stack && Array.isArray(stack)) {
450
+ stack[prefix] = stack.map((item) => {
451
+ if (item[prefix])
452
+ return item[prefix];
453
+ });
454
+ }
455
+ if (stack && !stack[prefix]) {
456
+ stack[prefix] = "";
457
+ }
458
+ stack = valueIndex ? stack[prefix][valueIndex] : stack[prefix];
459
+ if (fieldName.includes("]:")) {
460
+ valueIndexFieldName = nValue.split("]:")[1];
461
+ if (valueIndexFieldName) {
462
+ stack = stack[valueIndexFieldName];
463
+ }
464
+ }
465
+ }
466
+ value = stack ? stack : "";
467
+ if (Array.isArray(value)) {
468
+ value = value.filter(() => true);
469
+ }
470
+ }
433
471
  else {
434
472
  value = data ? data[fieldName] : "";
435
473
  }
474
+ if (value && Array.isArray(value) && value.length === 1)
475
+ return value[0];
436
476
  if (value && Array.isArray(value) && typeof value[0] === "string") {
437
- return value.join(", ");
477
+ return value.join(",");
438
478
  }
439
- if (typeof value !== undefined && typeof value === "number") {
440
- return value.toString();
479
+ if (!value || value == "undefined" || value === "undefined") {
480
+ if (value === 0) {
481
+ value = "0";
482
+ }
483
+ else {
484
+ value = "";
485
+ }
441
486
  }
442
487
  return value;
443
488
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "2.5.0",
3
+ "version": "2.5.1-preview",
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.2",
46
- "drapcode-logger": "^1.3.5",
47
- "drapcode-redis": "^1.4.9",
45
+ "drapcode-constant": "^2.0.2-preview",
46
+ "drapcode-logger": "^1.3.5-preview",
47
+ "drapcode-redis": "^1.4.9-preview",
48
48
  "exiftool-vendored": "^28.2.1",
49
49
  "express": "^4.17.1",
50
50
  "gm": "^1.25.0",