@itentialopensource/adapter-utils 4.44.11 → 4.45.3

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,42 @@
1
1
 
2
+ ## 4.45.3 [12-13-2021]
3
+
4
+ * move preinstall to postinstall
5
+
6
+ See merge request itentialopensource/adapter-utils!229
7
+
8
+ ---
9
+
10
+ ## 4.45.2 [12-09-2021]
11
+
12
+ * change for sending content-length with empty token body
13
+
14
+ Closes ADAPT-1889
15
+
16
+ See merge request itentialopensource/adapter-utils!228
17
+
18
+ ---
19
+
20
+ ## 4.45.1 [12-08-2021]
21
+
22
+ * Modified response handling on error to use the translator
23
+
24
+ Closes ADAPT-1876
25
+
26
+ See merge request itentialopensource/adapter-utils!225
27
+
28
+ ---
29
+
30
+ ## 4.45.0 [12-08-2021]
31
+
32
+ * changes for uriOptions and not encoding query params
33
+
34
+ Closes ADAPT-1866
35
+
36
+ See merge request itentialopensource/adapter-utils!227
37
+
38
+ ---
39
+
2
40
  ## 4.44.11 [10-25-2021]
3
41
 
4
42
  * 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) {
@@ -1917,7 +1931,7 @@ function buildTokenRequest(reqPath, reqBody, callProperties, callback) {
1917
1931
 
1918
1932
  // if there is a body, set the content length of the body and add it to
1919
1933
  // the header
1920
- if (Object.keys(tokenEntity).length > 0) {
1934
+ if (Object.keys(tokenEntity).length > 0 || tokenSchema.sendEmpty) {
1921
1935
  options.headers['Content-length'] = Buffer.byteLength(bodyString);
1922
1936
  }
1923
1937
 
@@ -187,6 +187,7 @@ class AdapterPropertyUtil {
187
187
  // get the path for the specific schema file
188
188
  const reqSchemaFile = path.join(this.baseDir, `/entities/${entityName}/${reqSchemaName}`);
189
189
  const respSchemaFile = path.join(this.baseDir, `/entities/${entityName}/${respSchemaName}`);
190
+ const errorSchemaFile = path.join(this.baseDir, '/entities/.system/errorSchema');
190
191
 
191
192
  // if the file does not exist - error
192
193
  if (!fs.existsSync(reqSchemaFile)) {
@@ -244,6 +245,16 @@ class AdapterPropertyUtil {
244
245
  throw new Error(JSON.stringify(errorObj));
245
246
  }
246
247
 
248
+ // if the error schema file exist - read it in
249
+ if (fs.existsSync(errorSchemaFile)) {
250
+ entitySchema.errorSchema = JSON.parse(fs.readFileSync(errorSchemaFile, 'utf-8'));
251
+
252
+ // if the error schema file is bad, warn about it but continue and use the global on!
253
+ if (entitySchema.errorSchema && typeof entitySchema.errorSchema !== 'object') {
254
+ log.warn(`${origin}: Invalid error schema, please verify file: ${errorSchemaFile}`);
255
+ }
256
+ }
257
+
247
258
  // Merge the information into the entity schema
248
259
  entitySchema.protocol = actionInfo.protocol;
249
260
  entitySchema.method = actionInfo.method;
@@ -51,7 +51,7 @@ function validateProperties(properties) {
51
51
 
52
52
  try {
53
53
  // get the path for the specific action file
54
- const propertyFile = path.join(__dirname, '/../propertiesSchema.json');
54
+ const propertyFile = path.join(__dirname, '/../schemas/propertiesSchema.json');
55
55
 
56
56
  // Read the action from the file system
57
57
  const propertySchema = JSON.parse(fs.readFileSync(propertyFile, 'utf-8'));
@@ -113,7 +113,7 @@ function walkThroughActionFiles(directory) {
113
113
 
114
114
  try {
115
115
  // Read the action schema from the file system
116
- const actionSchemaFile = path.join(__dirname, '/../actionSchema.json');
116
+ const actionSchemaFile = path.join(__dirname, '/../schemas/actionSchema.json');
117
117
  const actionSchema = JSON.parse(fs.readFileSync(actionSchemaFile, 'utf-8'));
118
118
  const entitydir = `${directory}/entities`;
119
119
 
@@ -9,6 +9,8 @@ const jsonQuery = require('json-query');
9
9
  const jsonxml = require('jsontoxml');
10
10
  const xml2js = require('xml2js');
11
11
 
12
+ const globalSchema = JSON.parse(require('fs').readFileSync(require('path').join(__dirname, '/../schemas/globalSchema.json')));
13
+
12
14
  let transUtilInst = null;
13
15
  let connectorInst = null;
14
16
 
@@ -19,6 +21,7 @@ let basepathGl = null;
19
21
  let globalRequestGl = null;
20
22
  let returnRawGl = false;
21
23
  let encodePath = true;
24
+ let encodeUri = true;
22
25
 
23
26
  // INTERNAL FUNCTIONS
24
27
  /*
@@ -178,7 +181,13 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
178
181
 
179
182
  // if the return error message was JSON then return the parsed object
180
183
  if (retError !== null) {
181
- retErrorObj.response = retError;
184
+ // if there is a local error schema in the entity use that one
185
+ if (Object.hasOwnProperty.call(entitySchema, 'errorSchema')) {
186
+ retErrorObj.response = transUtilInst.mapFromOutboundEntity(retError, entitySchema.errorSchema);
187
+ } else {
188
+ // if there is a no local error schema in the entity use that one
189
+ retErrorObj.response = transUtilInst.mapFromOutboundEntity(retError, globalSchema);
190
+ }
182
191
  }
183
192
 
184
193
  // return the error response
@@ -460,6 +469,9 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
460
469
  return callback(retObject);
461
470
  }
462
471
 
472
+ // Apply global schema
473
+ // retResponse = transUtilInst.mapFromOutboundEntity(retResponse, globalSchema);
474
+
463
475
  // added the translated response to the return Object
464
476
  retObject.response = transUtilInst.mapFromOutboundEntity(retResponse, entitySchema.responseSchema);
465
477
 
@@ -677,7 +689,23 @@ function buildRequestPath(entity, action, entitySchema, reqPath, uriPathVars, ur
677
689
  addquery = entitySchema.querykey;
678
690
  }
679
691
  if (systemQuery !== null) {
680
- addquery += querystring.stringify(systemQuery);
692
+ // if we are encoding - use querystring since it does it all!
693
+ if (encodeUri === true) {
694
+ addquery += querystring.stringify(systemQuery);
695
+ } else {
696
+ // if not encoding we need to build
697
+ const qkeys = Object.keys(systemQuery);
698
+
699
+ // add each query parameter and its value
700
+ for (let k = 0; k < qkeys.length; k += 1) {
701
+ // need to add separator for everything after the first one
702
+ if (k > 0) {
703
+ addquery += '&';
704
+ }
705
+ // adds key=value
706
+ addquery += `${qkeys[k]}=${systemQuery[qkeys[k]]}`;
707
+ }
708
+ }
681
709
  }
682
710
  }
683
711
 
@@ -988,6 +1016,8 @@ class RestHandler {
988
1016
  this.globalRequest = null;
989
1017
  this.encode = properties.encode_pathvars;
990
1018
  encodePath = this.encode;
1019
+ this.encodeQ = properties.encode_queryvars;
1020
+ encodeUri = this.encodeQ;
991
1021
 
992
1022
  // only need to set returnRaw if the property is true - defaults to false
993
1023
  if (properties.request && properties.request.return_raw) {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "4.44.11",
3
+ "version": "4.45.3",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
- "preinstall": "node utils/setup.js",
6
+ "postinstall": "node utils/setup.js",
7
7
  "lint": "eslint . --ext .json --ext .js",
8
8
  "lint:errors": "eslint --quiet . --ext .json --ext .js",
9
9
  "test:unit": "mocha test/unit/lib/requestHandlerTest.js --LOG=error && mocha test/unit/lib/restHandlerTest.js --LOG=error && mocha test/unit/lib/propertyUtilTest.js --LOG=error && mocha test/unit/lib/translatorUtilTest.js --LOG=error && mocha test/unit/lib/dbUtilTest.js --LOG=debug",
File without changes
@@ -0,0 +1,19 @@
1
+ {
2
+ "$id": "schema.json",
3
+ "type": "object",
4
+ "schema": "http://json-schema.org/draft-07/schema#",
5
+ "translate": true,
6
+ "dynamicfields": true,
7
+ "properties": {
8
+ "id": {
9
+ "type": "string",
10
+ "description": "Restricted for: special use within mongo",
11
+ "encrypt": {
12
+ "type": "AES",
13
+ "key": ""
14
+ },
15
+ "external_name": "$id"
16
+ }
17
+ },
18
+ "definitions": {}
19
+ }
@@ -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",