@itentialopensource/adapter-utils 4.44.8 → 4.45.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 +50 -0
- package/lib/connectorRest.js +15 -1
- package/lib/dbUtil.js +409 -477
- package/lib/propertyUtil.js +13 -1
- package/lib/requestHandler.js +2 -2
- package/lib/restHandler.js +33 -3
- package/package.json +4 -4
- package/{actionSchema.json → schemas/actionSchema.json} +0 -0
- package/schemas/globalSchema.json +19 -0
- package/{propertiesSchema.json → schemas/propertiesSchema.json} +5 -0
package/lib/propertyUtil.js
CHANGED
|
@@ -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;
|
|
@@ -428,7 +439,8 @@ class AdapterPropertyUtil {
|
|
|
428
439
|
filter: {
|
|
429
440
|
id: this.myid,
|
|
430
441
|
entity: entityName
|
|
431
|
-
}
|
|
442
|
+
},
|
|
443
|
+
entity: entityName
|
|
432
444
|
};
|
|
433
445
|
|
|
434
446
|
// call to get the adapter schema from the database
|
package/lib/requestHandler.js
CHANGED
|
@@ -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
|
|
package/lib/restHandler.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -897,7 +925,7 @@ function buildPayload(entity, action, entitySchema, payload) {
|
|
|
897
925
|
}
|
|
898
926
|
}
|
|
899
927
|
} else {
|
|
900
|
-
log.warn(`${origin}: Payload and
|
|
928
|
+
log.warn(`${origin}: Payload and Global Payload can not be merged!`);
|
|
901
929
|
}
|
|
902
930
|
}
|
|
903
931
|
|
|
@@ -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,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itentialopensource/adapter-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.45.1",
|
|
4
4
|
"description": "Itential Adapter Utility Libraries",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"preinstall": "node utils/setup.js",
|
|
7
7
|
"lint": "eslint . --ext .json --ext .js",
|
|
8
8
|
"lint:errors": "eslint --quiet . --ext .json --ext .js",
|
|
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=
|
|
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",
|
|
10
10
|
"test:integration": "mocha test/integration/lib/requestHandlerTest.js --LOG=error && mocha test/integration/lib/restHandlerTest.js --LOG=error",
|
|
11
11
|
"test:cover": "nyc --reporter html --reporter text mocha --recursive --reporter dot test/*",
|
|
12
12
|
"test": "npm run test:unit && npm run test:integration",
|
|
13
|
-
"deploy": "npm publish --registry=
|
|
13
|
+
"deploy": "npm publish --registry=https://registry.npmjs.org --access=public",
|
|
14
14
|
"build": "npm run deploy"
|
|
15
15
|
},
|
|
16
16
|
"license": "Apache-2.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"eslint-plugin-json": "^3.0.0",
|
|
52
52
|
"mocha": "^9.0.1",
|
|
53
53
|
"nyc": "^15.1.0",
|
|
54
|
-
"strip-ansi": "^7.0.
|
|
54
|
+
"strip-ansi": "^7.0.1",
|
|
55
55
|
"strip-ansi-cli": "^3.0.1",
|
|
56
56
|
"testdouble": "^3.16.1",
|
|
57
57
|
"winston": "^3.3.3"
|
|
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",
|