Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@itentialopensource/adapter-utils

Package Overview
Dependencies
Maintainers
3
Versions
215
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@itentialopensource/adapter-utils - npm Package Compare versions

Comparing version 4.44.6 to 4.44.7

10

CHANGELOG.md
## 4.44.7 [08-29-2021]
* changes to fix async issues in getEntitiesSchema
Closes ADAPT-880
See merge request itentialopensource/adapter-utils!220
---
## 4.44.6 [08-26-2021]

@@ -3,0 +13,0 @@

105

lib/dbUtil.js

@@ -633,7 +633,7 @@ /* Required libraries. */

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -644,2 +644,7 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// work with the provided database

@@ -712,7 +717,7 @@ return MongoClient.connect(usedburl, usedbopt, (error, db) => {

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -723,2 +728,7 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// work with the provided database

@@ -816,7 +826,7 @@ return MongoClient.connect(usedburl, usedbopt, (error, db) => {

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -827,2 +837,7 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// work with the provided database

@@ -891,7 +906,7 @@ return MongoClient.connect(usedburl, usedbopt, (error, db) => {

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -902,2 +917,7 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// work with the provided database

@@ -966,7 +986,7 @@ return MongoClient.connect(usedburl, usedbopt, (error, db) => {

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -977,2 +997,7 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// work with the provided database

@@ -1054,7 +1079,7 @@ return MongoClient.connect(usedburl, usedbopt, (error, db) => {

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -1065,2 +1090,7 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// work with the provided database

@@ -1157,7 +1187,7 @@ return MongoClient.connect(usedburl, usedbopt, (error, db) => {

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -1168,2 +1198,7 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// work with the provided database

@@ -1274,7 +1309,7 @@ return MongoClient.connect(usedburl, usedbopt, (error, db) => {

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -1285,5 +1320,10 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// work with the provided database
return MongoClient.connect(usedburl, usedbopt, async (error, db) => {
if (error) {
return MongoClient.connect(usedburl, usedbopt, (error, db) => {
if (error || !db) {
// no Database connection available

@@ -1364,7 +1404,7 @@ log.warn(`${origin}: Error connecting to Mongo ${error}`);

// if we were passed in dbInfo, verify it contains all the pieces we want
if (dbInfo && (!dbInfo.dburl || !dbInfo.dboptions || !dbInfo.database)) {
log.warn(`${origin}: Improper dbInfo provided should have dburl, dboptions and database! Using default database`);
if (!dbInfo || !dbInfo.dburl || !dbInfo.database) {
log.warn(`${origin}: Improper dbInfo provided should have dburl and database! Using default database`);
}
// if we were passed in dbInfo, that should supercede the default database
if (dbInfo && dbInfo.dburl && !dbInfo.dboptions && dbInfo.database) {
if (dbInfo && dbInfo.dburl && dbInfo.database) {
usedburl = dbInfo.dburl;

@@ -1375,2 +1415,7 @@ usedbopt = dbInfo.dboptions;

if (!usedburl || !usedb) {
log.warn(`${origin}: Did not find database to connect to`);
return callback(`${origin}: Did not find database to connect to`, null);
}
// connect to the provided database

@@ -1388,3 +1433,3 @@ return MongoClient.connect(usedburl, usedbopt, (error, db) => {

db.close();
MongoClient.close();
if (err) {

@@ -1391,0 +1436,0 @@ log.warn(`${origin}: Failed to modified data in database ${err}`);

@@ -391,3 +391,3 @@ /* @copyright Itential, LLC 2018-9 */

*/
getEntitySchemaFromDB(dbObj, entityName, actionName, dbUtils) {
getEntitySchemaFromDB(dbObj, entityName, actionName, dbUtils, callback) {
const origin = `${this.myid}-propertyUtil-getEntitySchemaFromDB`;

@@ -410,3 +410,3 @@ log.trace(origin);

errorObj.error = [`${origin}: Entity is required to get entity schema for action`];
return errorObj;
return callback(null, errorObj);
}

@@ -418,3 +418,3 @@ if (!actionName || typeof actionName !== 'string') {

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -424,3 +424,3 @@ log.error(`${origin}: Action is required to get entity schema for action`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -446,3 +446,3 @@

errorObj.error = [`${origin}: Database Error: ${dbError}`];
return errorObj;
return callback(null, errorObj);
}

@@ -455,7 +455,7 @@ if (!dbResult) {

errorObj.error = [`${origin}: Entity was not found in the database`];
return errorObj;
return callback(null, errorObj);
}
// Read the action from the entity object
const entityActions = dbResult;
const entityActions = dbResult[0];

@@ -468,3 +468,3 @@ // handle possible errors in the action file

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -474,3 +474,3 @@ log.error(`${origin}: Invalid entity action file, please verify file: ${entityName}`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -482,3 +482,3 @@ if (!entityActions.actions || !Array.isArray(entityActions.actions)) {

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -488,3 +488,3 @@ log.error(`${origin}: Invalid action file syntax ${entityName} - must contain an array of actions`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -507,3 +507,3 @@

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -513,3 +513,3 @@ log.error(`${origin}: Entity ${entityName} - action file missing action: ${actionName}`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -523,3 +523,3 @@

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -529,3 +529,3 @@ log.error(`${origin}: Entity ${entityName} action ${actionName} - missing protocol`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -537,3 +537,3 @@ if (!actionInfo.method) {

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -543,3 +543,3 @@ log.error(`${origin}: Entity ${entityName} action ${actionName} - missing method`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -551,3 +551,3 @@ if (!actionInfo.entitypath) {

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -557,3 +557,3 @@ log.error(`${origin}: Entity ${entityName} action ${actionName} - missing entity path`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -565,3 +565,3 @@ if (!actionInfo.schema && (!actionInfo.requestSchema || !actionInfo.responseSchema)) {

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -571,3 +571,3 @@ log.error(`${origin}: Entity ${entityName} action ${actionName} - missing schema`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -593,3 +593,3 @@

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -599,3 +599,3 @@ log.error(`${origin}: Invalid schema file syntax ${reqSchemaName} - must contain an array of schemas`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -622,3 +622,3 @@

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -628,3 +628,3 @@ log.error(`${origin}: Could not find file - ${reqSchemaName}`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -638,3 +638,3 @@

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -644,3 +644,3 @@ log.error(`${origin}: Could not find file - ${respSchemaName}`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -654,3 +654,3 @@

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -660,3 +660,3 @@ log.error(`${origin}: Invalid entity request schema, please verify file: ${reqSchemaInfo}`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -668,3 +668,3 @@ if (typeof respSchemaInfo !== 'object') {

// log (if not system entity) and throw the error
// log (if not system entity) and return the error
if (entityName !== '.system') {

@@ -674,3 +674,3 @@ log.error(`${origin}: Invalid entity response schema, please verify file: ${respSchemaInfo}`);

}
return errorObj;
return callback(null, errorObj);
}

@@ -775,3 +775,3 @@

// parse the mockdata file to store it as an object
mockResponse.response = JSON.parse(mockResp);
mockResponse.response = mockResp;
} catch (excep) {

@@ -796,3 +796,3 @@ log.warn(`${origin}: Could not parse file - ${mockFileName}`);

// return the entity schema
return entitySchema;
return callback(entitySchema, null);
});

@@ -805,3 +805,4 @@ } catch (e) {

// return the error message
return errorObj;
log.info(`unable to get adapter config from database: ${e}`);
return callback(null, errorObj);
}

@@ -819,6 +820,5 @@ }

*/
getEntitySchema(entityName, actionName, dbUtils) {
getEntitySchema(entityName, actionName, dbUtils, callback) {
const origin = `${this.myid}-propertyUtil-getEntitySchema`;
log.trace(origin);
let gotSchema = null;

@@ -828,49 +828,44 @@ // need to try to get the entity schema from the adapter database

// call to get the adapter schema from the database
gotSchema = this.getEntitySchemaFromDB(null, entityName, actionName, dbUtils);
return this.getEntitySchemaFromDB(null, entityName, actionName, dbUtils, (dbresp, dberror) => {
// if we got an error back - just means db config not in place
if (dberror || !dbresp || (dbresp && Object.keys(dbresp).length === 0)) {
log.debug('unable to get adapter config from adapter database');
// if we got an error back - just means db config not in place
if (gotSchema && gotSchema.isError) {
log.debug('unable to get adapter config from adapter database');
gotSchema = null;
}
} catch (exaddb) {
log.debug('unable to get adapter config from adapter database');
}
// Temporarily hardcode the adapter properties
const iapDB = {
dburl: 'mongodb://127.0.0.1:27017',
dboptions: {},
database: 'pronghorn'
};
if (gotSchema) {
return gotSchema;
}
// need to try to get the entity schema from the iap database
return this.getEntitySchemaFromDB(iapDB, entityName, actionName, dbUtils, (iapdbresp, iapdberror) => {
// if we got an error back - just means db config not in place
if (iapdberror || !iapdbresp || (iapdbresp && Object.keys(iapdbresp).length === 0)) {
log.debug('unable to get adapter config from iap database');
// need to try to get the entity schema from the iap database
try {
// call to get the adapter schema from the database
const iapDB = {
dburl: '',
dboptions: '',
database: ''
};
gotSchema = this.getEntitySchemaFromDB(iapDB, entityName, actionName, dbUtils);
// need to try to get the entity schema from the filesystem
log.debug('returning adapter config from file system');
try {
return callback(this.getEntitySchemaFromFS(entityName, actionName), null);
} catch (exc) {
log.error('Exception caught on File System');
return callback(null, exc);
}
}
// if we got an error back - just means db config not in place
if (gotSchema && gotSchema.isError) {
log.debug('unable to get adapter config from adapter database');
gotSchema = null;
}
// return the iap db config
log.debug(`returning adapter config from iap database ${iapdbresp}`);
return callback(iapdbresp, null);
});
}
// return the adapter db config
log.debug(`returning adapter config from adapter database ${dbresp}`);
return callback(dbresp, null);
});
} catch (exaddb) {
log.debug('unable to get adapter config from iap database');
log.debug(`unable to get adapter config: ${exaddb}`);
return callback(null, exaddb);
}
if (gotSchema) {
return gotSchema;
}
// need to get the entity schema from the file system
try {
gotSchema = this.getEntitySchemaFromFS(entityName, actionName);
} catch (exfs) {
log.debug('unable to get adapter config from file system');
throw exfs;
}
return gotSchema;
}

@@ -877,0 +872,0 @@

@@ -580,27 +580,55 @@ /* @copyright Itential, LLC 2018 */

// Get the entity schema from the file system
const entitySchema = this.propUtil.getEntitySchema(entity, action, this.dbUtil);
return this.propUtil.getEntitySchema(entity, action, this.dbUtil, (entitySchema, entityError) => {
// verify protocol for call
if (entityError) {
const errorObj = this.transUtil.checkAndReturn(entityError, origin, 'Issue identifiying request');
return callback(null, errorObj);
}
// verify protocol for call
if (!Object.hasOwnProperty.call(entitySchema, 'protocol')) {
const errorObj = this.formatErrorObject(this.myid, meth, 'Missing Data', ['action protocol'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
// verify protocol for call
if (!Object.hasOwnProperty.call(entitySchema, 'protocol')) {
const errorObj = this.formatErrorObject(this.myid, meth, 'Missing Data', ['action protocol'], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
}
// Determine the Protocol so the appropriate handler can be called
if (entitySchema.protocol.toUpperCase() === 'REST') {
return this.restHandler.genericRestRequest(entity, action, entitySchema, requestObj, translate, (result, error) => {
const overallDiff = process.hrtime(overallTime);
const overallEnd = `${Math.round(((overallDiff[0] * NS_PER_SEC) + overallDiff[1]) / 1000000)}ms`;
if (error) {
const newError = error;
if (!newError.metrics) {
newError.metrics = {};
// Determine the Protocol so the appropriate handler can be called
if (entitySchema.protocol.toUpperCase() === 'REST') {
return this.restHandler.genericRestRequest(entity, action, entitySchema, requestObj, translate, (result, error) => {
const overallDiff = process.hrtime(overallTime);
const overallEnd = `${Math.round(((overallDiff[0] * NS_PER_SEC) + overallDiff[1]) / 1000000)}ms`;
if (error) {
const newError = error;
if (!newError.metrics) {
newError.metrics = {};
}
newError.metrics.capabilityTime = overallEnd;
// console.log(newError); //can't test b/c no errors built into tests rn.
// will call from adapterFunction.ejs only eventually since it will have all metrics here + the 2 missing ones.
if (this.saveMetric) {
dbCalls('metrics', entity, action, newError.metrics, (saved) => {
if (saved) {
log.info(`${origin}: Metrics Saved`);
}
});
}
return callback(null, newError);
}
newError.metrics.capabilityTime = overallEnd;
// console.log(newError); //can't test b/c no errors built into tests rn.
let newRes = result;
if (!newRes) {
newRes = {
metrics: {
}
};
} else if (!newRes.metrics) {
newRes.metrics = {};
}
newRes.metrics.capabilityTime = overallEnd;
// overallEnd is from start of identifyRequest to right before dbCalls is called (error or good).
// will call from adapterFunction.ejs only eventually since it will have all metrics here + the 2 missing ones.
if (this.saveMetric) {
dbCalls('metrics', entity, action, newError.metrics, (saved) => {
dbCalls('metrics', entity, action, newRes.metrics, (saved) => {
if (saved) {

@@ -611,33 +639,11 @@ log.info(`${origin}: Metrics Saved`);

}
return callback(null, newError);
}
return callback(newRes);
});
}
let newRes = result;
if (!newRes) {
newRes = {
metrics: {
}
};
} else if (!newRes.metrics) {
newRes.metrics = {};
}
newRes.metrics.capabilityTime = overallEnd;
// overallEnd is from start of identifyRequest to right before dbCalls is called (error or good).
// will call from adapterFunction.ejs only eventually since it will have all metrics here + the 2 missing ones.
if (this.saveMetric) {
dbCalls('metrics', entity, action, newRes.metrics, (saved) => {
if (saved) {
log.info(`${origin}: Metrics Saved`);
}
});
}
return callback(newRes);
});
}
// Unsupported protocols
const errorObj = this.formatErrorObject(this.myid, meth, 'Unsupported Protocol', [entitySchema.protocol], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
// Unsupported protocols
const errorObj = this.formatErrorObject(this.myid, meth, 'Unsupported Protocol', [entitySchema.protocol], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
});
} catch (e) {

@@ -669,35 +675,55 @@ // handle any exception

try {
let healthSchema = null;
let prot = this.props.healthcheck.protocol;
try {
// Get the health schema from the file system
healthSchema = this.propUtil.getEntitySchema('.system', 'healthcheck', this.dbUtil);
log.debug(`${origin}: Using action and schema for healthcheck information`);
} catch (ex) {
// Healthcheck schema is not required (could be defined in
// properties so ignore the exception!!!
log.debug(`${origin}: Using adapter properties for healthcheck information`);
}
// Get the entity schema from the file system
return this.propUtil.getEntitySchema('.system', 'healthcheck', this.dbUtil, (healthSchema, healthError) => {
if (healthError || !healthSchema || Object.keys(healthSchema).length === 0) {
log.debug(`${origin}: Using adapter properties for healthcheck information`);
} else {
log.debug(`${origin}: Using action and schema for healthcheck information`);
}
if (healthSchema && healthSchema.protocol) {
prot = healthSchema.protocol;
}
if (healthSchema && healthSchema.protocol) {
prot = healthSchema.protocol;
}
// Determine the Protocol so the appropriate handler can be called
if (prot.toUpperCase() === 'REST') {
return this.restHandler.healthcheckRest(healthSchema, requestObj, (result, error) => {
const overallDiff = process.hrtime(overallTime);
const overallEnd = `${Math.round(((overallDiff[0] * NS_PER_SEC) + overallDiff[1]) / 1000000)}ms`;
if (error) {
const newError = error;
if (!newError.metrics) {
newError.metrics = {};
// Determine the Protocol so the appropriate handler can be called
if (prot.toUpperCase() === 'REST') {
return this.restHandler.healthcheckRest(healthSchema, requestObj, (result, error) => {
const overallDiff = process.hrtime(overallTime);
const overallEnd = `${Math.round(((overallDiff[0] * NS_PER_SEC) + overallDiff[1]) / 1000000)}ms`;
if (error) {
const newError = error;
if (!newError.metrics) {
newError.metrics = {};
}
newError.metrics.capabilityTime = overallEnd;
// console.log(newError); //can't test b/c no errors built into tests rn.
// will call from adapterFunction.ejs only eventually since it will have all metrics here + the 2 missing ones.
if (this.saveMetric) {
dbCalls('metrics', '.system', 'healthcheck', newError.metrics, (saved) => {
if (saved) {
log.info(`${origin}: Metrics Saved`);
}
});
}
return callback(null, newError);
}
newError.metrics.capabilityTime = overallEnd;
// console.log(newError); //can't test b/c no errors built into tests rn.
let newRes = result;
if (!newRes) {
newRes = {
metrics: {
}
};
} else if (!newRes.metrics) {
newRes.metrics = {};
}
newRes.metrics.capabilityTime = overallEnd;
// overallEnd is from start of identifyRequest to right before dbCalls is called (error or good).
// will call from adapterFunction.ejs only eventually since it will have all metrics here + the 2 missing ones.
if (this.saveMetric) {
dbCalls('metrics', '.system', 'healthcheck', newError.metrics, (saved) => {
dbCalls('metrics', '.system', 'healthcheck', newRes.metrics, (saved) => {
if (saved) {

@@ -708,33 +734,11 @@ log.info(`${origin}: Metrics Saved`);

}
return callback(null, newError);
}
return callback(newRes);
});
}
let newRes = result;
if (!newRes) {
newRes = {
metrics: {
}
};
} else if (!newRes.metrics) {
newRes.metrics = {};
}
newRes.metrics.capabilityTime = overallEnd;
// overallEnd is from start of identifyRequest to right before dbCalls is called (error or good).
// will call from adapterFunction.ejs only eventually since it will have all metrics here + the 2 missing ones.
if (this.saveMetric) {
dbCalls('metrics', '.system', 'healthcheck', newRes.metrics, (saved) => {
if (saved) {
log.info(`${origin}: Metrics Saved`);
}
});
}
return callback(newRes);
});
}
// Unsupported protocols
const errorObj = this.formatErrorObject(this.myid, meth, 'Unsupported Protocol', [prot], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
// Unsupported protocols
const errorObj = this.formatErrorObject(this.myid, meth, 'Unsupported Protocol', [prot], null, null, null);
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
return callback(null, errorObj);
});
} catch (e) {

@@ -741,0 +745,0 @@ // handle any exception

{
"name": "@itentialopensource/adapter-utils",
"version": "4.44.6",
"version": "4.44.7",
"description": "Itential Adapter Utility Libraries",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc