@itentialopensource/adapter-utils 5.3.0 → 5.3.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ ## 5.3.1 [11-17-2023]
3
+
4
+ * logic to convert object to array when specified
5
+
6
+ Closes ADAPT-2943
7
+
8
+ See merge request itentialopensource/adapter-utils!280
9
+
10
+ ---
11
+
2
12
  ## 5.3.0 [10-19-2023]
3
13
 
4
14
  * ADAPT-485: AWS Auth
@@ -25,6 +25,7 @@ let encodeUri = true;
25
25
  let stripEscapes = false;
26
26
  let returnResponseHeaders = true;
27
27
  let healthcheckHeaders = null;
28
+ let xmlArrayKeys = null;
28
29
  // INTERNAL FUNCTIONS
29
30
  /*
30
31
  * INTERNAL FUNCTION: Get the best match for the mock data response
@@ -105,6 +106,24 @@ function checkBodyData(uriPath, method, reqBdObj, mockresponses) {
105
106
  return specificResp;
106
107
  }
107
108
 
109
+ /*
110
+ * INTERNAL FUNCTION: recursively convert objects to array at keys specified in keys array
111
+ */
112
+ function setArrays(obj, keys) {
113
+ const currentObj = obj;
114
+ if (typeof currentObj === 'object') {
115
+ Object.keys(currentObj).forEach((key) => {
116
+ if (keys.includes(key)) {
117
+ if (!Array.isArray(currentObj[key])) {
118
+ currentObj[key] = [currentObj[key]];
119
+ }
120
+ }
121
+ // Recurse for nested keys
122
+ setArrays(currentObj[key], keys);
123
+ });
124
+ }
125
+ }
126
+
108
127
  /**
109
128
  * INTERNAL FUNCTION
110
129
  *
@@ -405,6 +424,10 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
405
424
  log.warn(`${origin}: Unable to parse xml to json ${error}`);
406
425
  return callback(retObject);
407
426
  }
427
+ // Logic to convert keys specified to array if object
428
+ if (xmlArrayKeys) {
429
+ setArrays(result, xmlArrayKeys);
430
+ }
408
431
  retObject.response = result;
409
432
  return callback(retObject);
410
433
  });
@@ -1063,6 +1086,10 @@ class RestHandler {
1063
1086
  if (properties.healthcheck && typeof properties.healthcheck.addlHeaders === 'object') {
1064
1087
  healthcheckHeaders = properties.healthcheck.addlHeaders;
1065
1088
  }
1089
+
1090
+ if (properties.xmlArrayKeys && typeof properties.xmlArrayKeys === 'object') {
1091
+ xmlArrayKeys = properties.xmlArrayKeys;
1092
+ }
1066
1093
  }
1067
1094
 
1068
1095
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "5.3.0",
3
+ "version": "5.3.1",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
6
  "postinstall": "node utils/setup.js",
Binary file