22
33const { JsonataTransform } = require ( '@elastic.io/component-commons-library' ) ;
44const request = require ( 'request-promise' ) ;
5- const { messages } = require ( 'elasticio-node' ) ;
65const xml2js = require ( 'xml2js-es6-promise' ) ;
76const uuidv1 = require ( 'uuid' ) . v1 ;
87
@@ -23,6 +22,11 @@ const methodsMap = {
2322 PUT : 'put' ,
2423} ;
2524
25+ module . exports . messages = {
26+ newMessageWithBody : ( body ) => ( { body, headers : { } } ) ,
27+ newEmptyMessage : ( ) => ( { body : { } , headers : { } } ) ,
28+ } ;
29+
2630const bodyEncodings = {
2731 FORM_DATA : 'form-data' ,
2832 RAW : 'raw' ,
@@ -228,7 +232,7 @@ module.exports.processMethod = async function (msg, cfg) {
228232 // Walk through chain of promises: https://stackoverflow.com/questions/30445543/execute-native-js-promise-in-series
229233 // eslint-disable-next-line no-restricted-syntax
230234 for ( const item of result . body ) {
231- const output = messages . newMessageWithBody ( {
235+ const output = module . exports . messages . newMessageWithBody ( {
232236 headers : result . headers ,
233237 body : item ,
234238 statusCode : result . statusCode ,
@@ -239,7 +243,7 @@ module.exports.processMethod = async function (msg, cfg) {
239243 await emitter . emit ( 'data' , output ) ;
240244 }
241245 } else {
242- const output = messages . newMessageWithBody ( result ) ;
246+ const output = module . exports . messages . newMessageWithBody ( result ) ;
243247 output . attachments = msg . attachments ;
244248 await emitter . emit ( 'data' , output ) ;
245249 }
@@ -371,7 +375,7 @@ module.exports.processMethod = async function (msg, cfg) {
371375 errorMessage : e . message ,
372376 errorStack : e . stack ,
373377 } ;
374- await emitter . emit ( 'data' , messages . newMessageWithBody ( output ) ) ;
378+ await emitter . emit ( 'data' , output ) ;
375379 await rateLimit ( emitter . logger , rateLimitDelay ) ;
376380 await emitter . emit ( 'end' ) ;
377381 } else {
0 commit comments