@itentialopensource/adapter-utils 4.44.11 → 4.45.0

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
+ ## 4.45.0 [12-08-2021]
3
+
4
+ * changes for uriOptions and not encoding query params
5
+
6
+ Closes ADAPT-1866
7
+
8
+ See merge request itentialopensource/adapter-utils!227
9
+
10
+ ---
11
+
2
12
  ## 4.44.11 [10-25-2021]
3
13
 
4
14
  * change to the npm registry url
@@ -1760,6 +1760,20 @@ function buildTokenRequest(reqPath, reqBody, callProperties, callback) {
1760
1760
  }
1761
1761
  }
1762
1762
 
1763
+ // only add global options if there are global options to add
1764
+ if (globalRequest && globalRequest.uriOptions
1765
+ && Object.keys(globalRequest.uriOptions).length > 0) {
1766
+ const optionString = querystring.stringify(globalRequest.uriOptions);
1767
+
1768
+ // if no query paramters yet - start with ?
1769
+ if (options.path.indexOf('?') < 0) {
1770
+ options.path += `?${optionString}`;
1771
+ } else {
1772
+ // if already have query parameters, add on to end
1773
+ options.path += `&${optionString}`;
1774
+ }
1775
+ }
1776
+
1763
1777
  // remove the path vars from the reqBody
1764
1778
  const actReqBody = Object.assign({}, reqBody);
1765
1779
  if (actReqBody && actReqBody.uriPathVars) {
@@ -19,6 +19,7 @@ let basepathGl = null;
19
19
  let globalRequestGl = null;
20
20
  let returnRawGl = false;
21
21
  let encodePath = true;
22
+ let encodeUri = true;
22
23
 
23
24
  // INTERNAL FUNCTIONS
24
25
  /*
@@ -677,7 +678,23 @@ function buildRequestPath(entity, action, entitySchema, reqPath, uriPathVars, ur
677
678
  addquery = entitySchema.querykey;
678
679
  }
679
680
  if (systemQuery !== null) {
680
- addquery += querystring.stringify(systemQuery);
681
+ // if we are encoding - use querystring since it does it all!
682
+ if (encodeUri === true) {
683
+ addquery += querystring.stringify(systemQuery);
684
+ } else {
685
+ // if not encoding we need to build
686
+ const qkeys = Object.keys(systemQuery);
687
+
688
+ // add each query parameter and its value
689
+ for (let k = 0; k < qkeys.length; k += 1) {
690
+ // need to add separator for everything after the first one
691
+ if (k > 0) {
692
+ addquery += '&';
693
+ }
694
+ // adds key=value
695
+ addquery += `${qkeys[k]}=${systemQuery[qkeys[k]]}`;
696
+ }
697
+ }
681
698
  }
682
699
  }
683
700
 
@@ -988,6 +1005,8 @@ class RestHandler {
988
1005
  this.globalRequest = null;
989
1006
  this.encode = properties.encode_pathvars;
990
1007
  encodePath = this.encode;
1008
+ this.encodeQ = properties.encode_queryvars;
1009
+ encodeUri = this.encodeQ;
991
1010
 
992
1011
  // only need to set returnRaw if the property is true - defaults to false
993
1012
  if (properties.request && properties.request.return_raw) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "4.44.11",
3
+ "version": "4.45.0",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
6
  "preinstall": "node utils/setup.js",
@@ -51,6 +51,11 @@
51
51
  "description": "When true the path variables are encoded in the url",
52
52
  "default": true
53
53
  },
54
+ "encode_queryvars": {
55
+ "type": "boolean",
56
+ "description": "When true the query variables are encoded in the url",
57
+ "default": true
58
+ },
54
59
  "save_metric": {
55
60
  "type": [
56
61
  "boolean",