@contrast/reporter
Advanced tools
Comparing version 1.17.0 to 1.18.0
@@ -66,3 +66,9 @@ "use strict"; | ||
await this.applicationSettings.get(); | ||
await this.effectiveConfig.put(); | ||
try { | ||
await this.effectiveConfig.put(); | ||
} | ||
catch (err) { | ||
// [1] for now just swallow any errors; the endpoint methods will log them. | ||
// we may need to uninstall in the future, depending on nature of the error. | ||
} | ||
setInterval(async () => { | ||
@@ -73,4 +79,3 @@ try { | ||
catch (err) { | ||
// [1] for now just swallow any errors; the endpoint methods will log them. | ||
// we may need to uninstall in the future, depending on nature of the error. | ||
// [1] | ||
} | ||
@@ -77,0 +82,0 @@ try { |
@@ -23,2 +23,3 @@ "use strict"; | ||
const hpagent_1 = require("hpagent"); | ||
const crypto_1 = require("crypto"); | ||
function base64Encode(str) { | ||
@@ -32,33 +33,69 @@ return Buffer.from(str).toString('base64'); | ||
exports.base64EncodeUnpadded = base64EncodeUnpadded; | ||
function httpsAgent(core) { | ||
if (core.config.api.proxy.enable) { | ||
return new hpagent_1.HttpsProxyAgent({ | ||
keepAlive: true, | ||
proxy: core.config.api.proxy.url | ||
}); | ||
} | ||
} | ||
const baseConfig = { | ||
validateStatus(status) { | ||
// by default axios considers 3xx responses to be errors. | ||
return status < 400; | ||
}, | ||
}; | ||
function addInterceptors(core, client) { | ||
const logger = core.logger.child({ name: 'contrast:http' }); | ||
const request = client.interceptors.request.use(function requestLogger(config) { | ||
// we assign a generated ID for each request to associate the response | ||
Reflect.set(config, 'id', (0, crypto_1.randomUUID)()); | ||
logger.trace({ | ||
id: Reflect.get(config, 'id'), | ||
data: config.data | ||
}, '%s %s', config.method?.toUpperCase(), config.url); | ||
return config; | ||
}, function requestErrorLogger(err) { | ||
logger.error({ | ||
err, | ||
id: err.config?.id | ||
}, err.config ? '%s %s' : 'An unknown error occured.', err.config?.method?.toUpperCase(), err.config?.url); | ||
return err; | ||
}); | ||
const response = client.interceptors.response.use(function responseLogger(response) { | ||
logger.trace({ | ||
id: Reflect.get(response.config, 'id'), | ||
data: response.data | ||
}, '%s %s:%s %s', response.config.method?.toUpperCase(), response.status, response.statusText, response.config.url); | ||
return response; | ||
}, function responseErrorLogger(err) { | ||
logger.error({ | ||
err, | ||
id: err.response?.config.id, | ||
}, err.response ? '%s %s:%s %s' : 'An unknown error occured.', err.response?.config.method?.toUpperCase(), err.response?.status, err.response?.statusText, err.response?.config.url); | ||
return err; | ||
}); | ||
return { request, response }; | ||
} | ||
function createNgClient(core) { | ||
const opts = { | ||
const client = axios_1.default.create({ | ||
...baseConfig, | ||
baseURL: new URL(`${core.config.api.url}`).href, | ||
headers: constructAuthHeaders(), | ||
httpsAgent: constructProxy(), | ||
}; | ||
return axios_1.default.create(opts); | ||
function constructAuthHeaders() { | ||
return [ | ||
['Authorization', `${core.config.api.user_name}:${core.config.api.service_key}`], | ||
['Application-Name', core.appInfo.name], | ||
['Application-Path', core.appInfo.appPath], | ||
['Server-Name', core.appInfo.serverName], | ||
['Server-Path', core.appInfo.app_dir], | ||
['Server-Type', `node.js ${core.appInfo.node_version}`], | ||
].reduce((acc, [key, value]) => Object.assign(acc, { [key]: base64Encode(value) }), { | ||
headers: { | ||
'API-Key': core.config.api.api_key, | ||
'Application-Language': 'Node', | ||
'Application-Name': base64Encode(core.appInfo.name), | ||
'Application-Path': base64Encode(core.appInfo.appPath), | ||
'Application-Version': core.appInfo.version, | ||
'Authorization': base64Encode(`${core.config.api.user_name}:${core.config.api.service_key}`), | ||
'Server-Name': base64Encode(core.appInfo.serverName), | ||
'Server-Path': base64Encode(core.appInfo.app_dir), | ||
'Server-Type': base64Encode(`node.js ${core.appInfo.node_version}`), | ||
'X-Contrast-Agent': `Node ${core.agentVersion}`, | ||
'X-Contrast-Header-Encoding': 'base64', | ||
'X-Contrast-Agent': `Node ${core.agentVersion}`, | ||
}); | ||
} | ||
function constructProxy() { | ||
if (!core.config.api.proxy.enable) | ||
return null; | ||
return new hpagent_1.HttpsProxyAgent({ | ||
keepAlive: true, | ||
proxy: core.config.api.proxy.url | ||
}); | ||
} | ||
}, | ||
httpsAgent: httpsAgent(core), | ||
}); | ||
addInterceptors(core, client); | ||
return client; | ||
} | ||
@@ -68,10 +105,11 @@ exports.createNgClient = createNgClient; | ||
const client = axios_1.default.create({ | ||
...baseConfig, | ||
baseURL: new URL(`${core.config.api.url}`).href, | ||
headers: { | ||
'API-Key': core.config.api.api_key, | ||
'Authorization': base64Encode(`${core.config.api.user_name}:${core.config.api.service_key}`), | ||
'API-Key': core.config.api.api_key, | ||
'User-Agent': `ContrastNodeAgent/${core.agentVersion}`, | ||
}, | ||
validateStatus: (status) => status < 400, | ||
}); | ||
addInterceptors(core, client); | ||
return client; | ||
@@ -78,0 +116,0 @@ } |
{ | ||
"name": "@contrast/reporter", | ||
"version": "1.17.0", | ||
"version": "1.18.0", | ||
"description": "Subscribes to agent messages and reports them", | ||
@@ -20,3 +20,3 @@ "license": "SEE LICENSE IN LICENSE", | ||
"dependencies": { | ||
"@contrast/common": "1.12.0", | ||
"@contrast/common": "1.13.0", | ||
"axios": "^0.27.2", | ||
@@ -23,0 +23,0 @@ "crc-32": "^1.2.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
199588
2797
+ Added@contrast/common@1.13.0(transitive)
- Removed@contrast/common@1.12.0(transitive)
Updated@contrast/common@1.13.0