cloudelements-cehandler
Advanced tools
+6
-0
@@ -10,4 +10,10 @@ # Cloud Elements Executor | ||
| ## v0.5.30 <sub><sup>(2017-10-16)</sup></sub> | ||
| #### Highlights | ||
| * Enhanced our multipart upload framework to handle a ReadableStream or path to file | ||
| * Added configurable logging, which has disabled by default. It can be enabled by passing `{ "debug": true }` in the headers object | ||
| * Added additional logging and improved error handling for vendor-based SOAP requests | ||
| ## v0.5.29 <sub><sup>(2017-10-09)</sup></sub> | ||
| #### Highlights | ||
| * Update to better handle converting body to query parameters |
+2
-1
@@ -171,2 +171,3 @@ 'use strict'; | ||
| const executeNamedQuery = (context, output) => { | ||
| const logger = util.logger(output); | ||
| const scriptNamedValues = findNamedValues(context, output); | ||
@@ -181,3 +182,3 @@ const script = scriptNamedValues[0]; | ||
| withConnection(context, output, (conn, cb) => { | ||
| util.debug("in with conn", script, namedValues); | ||
| logger.debug("in with conn", script, namedValues); | ||
| conn.query(script, namedValues, cb); | ||
@@ -184,0 +185,0 @@ }, standardResponse(context, output)); |
+61
-19
@@ -12,2 +12,3 @@ 'use strict'; | ||
| const util = require('./util'); | ||
| const EventEmitter = require("events"); | ||
@@ -42,3 +43,3 @@ /** A request handler that handles all JSON and JSONP content. */ | ||
| const logger = util.logger(output); | ||
| /* Wrap the context to output request timing values. */ | ||
@@ -48,3 +49,3 @@ const outCtx = { | ||
| const end = new Date().getTime(); | ||
| util.debug("vendor success in", (end - start)); | ||
| logger.debug("vendor success in", (end - start)); | ||
| return context.succeed(o); | ||
@@ -54,3 +55,3 @@ }, | ||
| const end = new Date().getTime(); | ||
| util.debug("vendor fail in", (end - start)); | ||
| logger.debug("vendor fail in", (end - start)); | ||
| context.fail(e); | ||
@@ -60,3 +61,3 @@ }, | ||
| const end = new Date().getTime(); | ||
| util.debug("vendor done in", (end - start)); | ||
| logger.debug("vendor done in", (end - start)); | ||
| context.done(e, o); | ||
@@ -148,2 +149,23 @@ } | ||
| const logger = util.logger(output); | ||
| /* Wrap the context to output request timing values. */ | ||
| const outCtx = { | ||
| succeed: o => { | ||
| const end = new Date().getTime(); | ||
| logger.debug("vendor success in", (end - start)); | ||
| return context.succeed(o); | ||
| }, | ||
| fail: e => { | ||
| const end = new Date().getTime(); | ||
| logger.debug("vendor fail in", (end - start)); | ||
| context.fail(e); | ||
| }, | ||
| done: (e, o) => { | ||
| const end = new Date().getTime(); | ||
| logger.debug("vendor done in", (end - start)); | ||
| context.done(e, o); | ||
| } | ||
| }; | ||
| let start = null; | ||
| xml2js.parseString(output.body, (err, result) => { | ||
@@ -172,11 +194,13 @@ const envelope = result[soapEnvelope]; | ||
| headers: output.headers, | ||
| body: output.body, | ||
| body: output.body | ||
| }; | ||
| start = new Date().getTime(); | ||
| request[method](reqOptions, (err, res, body) => { | ||
| if (res.statusCode >= 200 && res.statusCode <= 207) { | ||
| if (err) { | ||
| outCtx.fail(util.failure(400, err)); | ||
| } else if (res.statusCode >= 200 && res.statusCode <= 207) { | ||
| const handler = responseHandler.getResponseHandler(res.headers, 'soap'); | ||
| handler(res, body, context, output); | ||
| handler(res, body, outCtx, output); | ||
| } else { | ||
| context.fail(util.failure(res.statusCode, err)); | ||
| outCtx.done(util.failure(res.statusCode, body, res.statusMessage), res); | ||
| } | ||
@@ -198,2 +222,3 @@ }); | ||
| const multipartRequestHandler = (context, output) => { | ||
| const logger = util.logger(output); | ||
| let url = output.url || `${output.protocol}//${output.hostname}${output.path}`; | ||
@@ -205,3 +230,3 @@ const start = new Date().getTime(); | ||
| const end = new Date().getTime(); | ||
| util.debug("vendor success in", (end - start)); | ||
| logger.debug("vendor success in", (end - start)); | ||
| return context.succeed(o); | ||
@@ -211,3 +236,3 @@ }, | ||
| const end = new Date().getTime(); | ||
| util.debug("vendor fail in", (end - start)); | ||
| logger.debug("vendor fail in", (end - start)); | ||
| context.fail(e); | ||
@@ -217,3 +242,3 @@ }, | ||
| const end = new Date().getTime(); | ||
| util.debug("vendor done in", (end - start)); | ||
| logger.debug("vendor done in", (end - start)); | ||
| context.done(e, o); | ||
@@ -232,14 +257,31 @@ } | ||
| if (vendorName) { | ||
| if (fs.existsSync(output.input.file)) { | ||
| var req = request(reqOpts, function(err, resp, body) { | ||
| let req, form; | ||
| if (output.input.file instanceof EventEmitter && (typeof output.input.file.read) === 'function') { | ||
| req = request(reqOpts, function(err, resp, body) { | ||
| if (err) { | ||
| outCtx.fail(err); | ||
| outCtx.fail(util.failure(400, err)); | ||
| } else if (resp.statusCode >= 200 && resp.statusCode <= 207) { | ||
| outCtx.succeed(resp); | ||
| } else { | ||
| outCtx.done(null, resp); | ||
| outCtx.done(util.failure(resp.statusCode, resp.body, resp.statusMessage), resp); | ||
| } | ||
| }); | ||
| var form = req.form(); | ||
| form.append(vendorName, fs.createReadStream(output.input.file)); | ||
| form = req.form(); | ||
| form.append(vendorName, output.input.file); | ||
| } else { | ||
| outCtx.fail(util.failure(400, "No file exists at: " + output.input.file)); | ||
| if (fs.existsSync(output.input.file)) { | ||
| req = request(reqOpts, function(err, resp, body) { | ||
| if (err) { | ||
| outCtx.fail(util.failure(400, err)); | ||
| } else if (resp.statusCode >= 200 && resp.statusCode <= 207) { | ||
| outCtx.succeed(resp); | ||
| } else { | ||
| outCtx.done(util.failure(resp.statusCode, resp.body, resp.statusMessage), resp); | ||
| } | ||
| }); | ||
| form = req.form(); | ||
| form.append(vendorName, fs.createReadStream(output.input.file)); | ||
| } else { | ||
| outCtx.fail(util.failure(400, "No file exists at: " + output.input.file)); | ||
| } | ||
| } | ||
@@ -246,0 +288,0 @@ } else { |
+10
-4
| 'use strict'; | ||
| const _ = require('lodash'); | ||
| const logger = require('winston'); | ||
| const debug = true; | ||
| logger.level = debug ? 'debug' : null; | ||
| exports.debug = logger.debug; | ||
| exports.logger = (event) => { | ||
| const winston = require('winston'); | ||
| const headers = event.original_input ? event.original_input.headers : event.headers; | ||
| const level = exports.notNull(headers) && exports.notNull(headers.debug) && headers.debug === true ? 'debug' : 'info'; | ||
| winston.level = level; | ||
| winston | ||
| .remove(winston.transports.Console) | ||
| .add(winston.transports.Console, { level: level }); | ||
| return winston; | ||
| }; | ||
@@ -10,0 +16,0 @@ /** Returns if something is not null. */ |
+7
-5
@@ -23,4 +23,6 @@ 'use strict'; | ||
| const elementHandler = (element) => (event, context) => { | ||
| util.debug('Received event:', JSON.stringify(event, null, 2)); | ||
| const logger = util.logger(event); | ||
| logger.debug('Received event:', JSON.stringify(event, null, 2)); | ||
| const verror = verifyElement(element); | ||
@@ -40,3 +42,3 @@ if (verror != null) { | ||
| const end = new Date().getTime(); | ||
| util.debug("success in", (end - start)); | ||
| logger.debug("success in", (end - start)); | ||
| return apiCtx.succeed(o); | ||
@@ -46,3 +48,3 @@ }, | ||
| const end = new Date().getTime(); | ||
| util.debug("fail in", (end - start)); | ||
| logger.debug("fail in", (end - start)); | ||
| apiCtx.fail(e); | ||
@@ -52,3 +54,3 @@ }, | ||
| const end = new Date().getTime(); | ||
| util.debug("done in", (end - start)); | ||
| logger.debug("done in", (end - start)); | ||
| apiCtx.done(e, o); | ||
@@ -667,3 +669,3 @@ } | ||
| // only update values that are given in the input | ||
| output.input = _.merge(_.cloneDeep(output.original_input), input); | ||
| output.input = _.merge(output.input, input); | ||
@@ -670,0 +672,0 @@ // Hydrate the the continuationToken |
+1
-1
| { | ||
| "name": "cloudelements-cehandler", | ||
| "version": "0.5.29", | ||
| "version": "0.5.30", | ||
| "description": "An independent execution function for elements", | ||
@@ -5,0 +5,0 @@ "main": "main", |
+3
-3
@@ -29,7 +29,7 @@ # Cloud Elements Executor | ||
| documentation) also apply to the request and response JavaScript objects | ||
| that are passed into/out of the functino. | ||
| that are passed into/out of the function. | ||
| ## How to Use | ||
| There are two major data that are required to use the Executor: | ||
| There are two major data that are required to use the Executor: | ||
@@ -39,3 +39,3 @@ 1. The Element descriptor. This is usually saved as JSON in a file named | ||
| to complete a request to a particular back-end vendor. | ||
| 2. The request data for actually making the API request. | ||
@@ -42,0 +42,0 @@ |
Explicitly Unlicensed Item
LicenseSomething was found which is explicitly marked as unlicensed.
AI-detected potential malware
Supply chain riskAI has identified this package as malware. This is a strong signal that the package may be malicious.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Explicitly Unlicensed Item
LicenseSomething was found which is explicitly marked as unlicensed.
AI-detected potential malware
Supply chain riskAI has identified this package as malware. This is a strong signal that the package may be malicious.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
90349
2.65%2367
2.2%3
-25%