@itentialopensource/adapter-utils 4.45.0 → 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 CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ ## 4.45.1 [12-08-2021]
3
+
4
+ * Modified response handling on error to use the translator
5
+
6
+ Closes ADAPT-1876
7
+
8
+ See merge request itentialopensource/adapter-utils!225
9
+
10
+ ---
11
+
2
12
  ## 4.45.0 [12-08-2021]
3
13
 
4
14
  * changes for uriOptions and not encoding query params
@@ -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
 
@@ -179,7 +181,13 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
179
181
 
180
182
  // if the return error message was JSON then return the parsed object
181
183
  if (retError !== null) {
182
- 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
+ }
183
191
  }
184
192
 
185
193
  // return the error response
@@ -461,6 +469,9 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
461
469
  return callback(retObject);
462
470
  }
463
471
 
472
+ // Apply global schema
473
+ // retResponse = transUtilInst.mapFromOutboundEntity(retResponse, globalSchema);
474
+
464
475
  // added the translated response to the return Object
465
476
  retObject.response = transUtilInst.mapFromOutboundEntity(retResponse, entitySchema.responseSchema);
466
477
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-utils",
3
- "version": "4.45.0",
3
+ "version": "4.45.1",
4
4
  "description": "Itential Adapter Utility Libraries",
5
5
  "scripts": {
6
6
  "preinstall": "node utils/setup.js",
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
+ }