elasticio-sailor-nodejs 3.0.0-sailor-proxy-dev20 → 3.0.0-sailor-proxy-dev22
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 +3 -0
- package/lib/proxy-client.js +8 -19
- package/lib/sailor.js +5 -3
- package/lib/settings.js +0 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/lib/proxy-client.js
CHANGED
|
@@ -399,6 +399,7 @@ class ProxyClient {
|
|
|
399
399
|
chunks.push(chunk);
|
|
400
400
|
});
|
|
401
401
|
getObjectStream.on('error', (err) => {
|
|
402
|
+
// TODO: handle error responses
|
|
402
403
|
logger.error(err, 'Error during fetching message body');
|
|
403
404
|
reject(err);
|
|
404
405
|
});
|
|
@@ -406,7 +407,7 @@ class ProxyClient {
|
|
|
406
407
|
logger.info('Message stream ended by server');
|
|
407
408
|
const buffer = Buffer.concat(chunks);
|
|
408
409
|
logger.info({ messageSize: buffer.length }, 'Received complete message from server');
|
|
409
|
-
resolve(
|
|
410
|
+
resolve(JSON.parse(buffer.toString()));
|
|
410
411
|
});
|
|
411
412
|
}));
|
|
412
413
|
|
|
@@ -610,11 +611,7 @@ class ProxyClient {
|
|
|
610
611
|
} else if (type === 'http-reply') {
|
|
611
612
|
protocolVersion = 1;
|
|
612
613
|
}
|
|
613
|
-
const preparedMetadata = {
|
|
614
|
-
...metadata,
|
|
615
|
-
messageId: metadata.messageId || uuid.v4()
|
|
616
|
-
};
|
|
617
|
-
delete preparedMetadata.reboundIteration;
|
|
614
|
+
const preparedMetadata = { ...metadata };
|
|
618
615
|
let preparedData = data;
|
|
619
616
|
if (preparedData && preparedData.headers) {
|
|
620
617
|
preparedData.headers = _.omitBy(
|
|
@@ -657,12 +654,6 @@ class ProxyClient {
|
|
|
657
654
|
}, 'Sending message to proxy');
|
|
658
655
|
log.trace({ data }, 'Message data to send to proxy');
|
|
659
656
|
const { preparedMetadata, preparedData } = this._prepareData(data, metadata, type, forceProtocolVersion);
|
|
660
|
-
if (preparedData && preparedData.length > this.settings.OUTGOING_MESSAGE_SIZE_LIMIT) {
|
|
661
|
-
const error = new Error(`Outgoing message size ${preparedData.length}` +
|
|
662
|
-
` exceeds limit of ${this.settings.OUTGOING_MESSAGE_SIZE_LIMIT}.`);
|
|
663
|
-
log.error(error);
|
|
664
|
-
throw error;
|
|
665
|
-
}
|
|
666
657
|
log.debug({ preparedMetadata, preparedDataSize: preparedData ? preparedData.length : null }, 'Prepared message for sending to proxy');
|
|
667
658
|
|
|
668
659
|
const queryParams = new URLSearchParams({
|
|
@@ -683,6 +674,7 @@ class ProxyClient {
|
|
|
683
674
|
postMessageStream.end();
|
|
684
675
|
|
|
685
676
|
postMessageStream.on('response', (headers) => {
|
|
677
|
+
// TODO: handle error responses
|
|
686
678
|
log.debug({ status: headers[HTTP2_HEADER_STATUS] }, 'Send message response');
|
|
687
679
|
if (headers[HTTP2_HEADER_STATUS] !== 200) {
|
|
688
680
|
log.error({ headers }, 'Failed to send message');
|
|
@@ -746,13 +738,12 @@ class ProxyClient {
|
|
|
746
738
|
if (Object.values(MESSAGE_PROCESSING_STATUS).indexOf(status) === -1) {
|
|
747
739
|
throw new Error(`Invalid message processing status: ${status}`);
|
|
748
740
|
}
|
|
749
|
-
const { messageId: incomingMessageId
|
|
750
|
-
log.debug({ incomingMessageId, status
|
|
741
|
+
const { messageId: incomingMessageId } = metadata;
|
|
742
|
+
log.debug({ incomingMessageId, status }, 'Finishing processing of message');
|
|
751
743
|
const queryParams = new URLSearchParams({
|
|
752
744
|
clientId: this.proxyClientId,
|
|
753
745
|
incomingMessageId,
|
|
754
|
-
status
|
|
755
|
-
...(typeof reboundIteration !== 'undefined' ? { reboundIteration } : {})
|
|
746
|
+
status
|
|
756
747
|
}).toString();
|
|
757
748
|
|
|
758
749
|
await this._proxyRequestWithRetries('Finish processing', () => new Promise((resolve, reject) => {
|
|
@@ -764,6 +755,7 @@ class ProxyClient {
|
|
|
764
755
|
postMessageStream.end();
|
|
765
756
|
|
|
766
757
|
postMessageStream.on('response', (headers) => {
|
|
758
|
+
// TODO: handle error responses
|
|
767
759
|
log.debug({ status: headers[HTTP2_HEADER_STATUS] }, 'Finish processing response event');
|
|
768
760
|
if (headers[HTTP2_HEADER_STATUS] !== 200) {
|
|
769
761
|
log.error({ headers }, 'Failed to finish processing message');
|
|
@@ -893,9 +885,6 @@ class ProxyClient {
|
|
|
893
885
|
if (parsedMessageMetadata.reply_to) {
|
|
894
886
|
result.reply_to = parsedMessageMetadata.reply_to;
|
|
895
887
|
}
|
|
896
|
-
if (parsedMessageMetadata.reboundIteration) {
|
|
897
|
-
result.reboundIteration = parsedMessageMetadata.reboundIteration;
|
|
898
|
-
}
|
|
899
888
|
log.debug({ result }, 'Extracted message metadata');
|
|
900
889
|
return result;
|
|
901
890
|
}
|
package/lib/sailor.js
CHANGED
|
@@ -243,7 +243,9 @@ class Sailor {
|
|
|
243
243
|
|
|
244
244
|
async function onData(data) {
|
|
245
245
|
const metadataToSend = _.clone(outgoingMetadata);
|
|
246
|
-
|
|
246
|
+
if (data.id) {
|
|
247
|
+
metadataToSend.messageId = data.id;
|
|
248
|
+
}
|
|
247
249
|
logger.trace({
|
|
248
250
|
messagesCount: that.messagesCount,
|
|
249
251
|
messageProcessingTime: Date.now() - timeStart
|
|
@@ -523,13 +525,11 @@ class Sailor {
|
|
|
523
525
|
const stepData = this.stepData;
|
|
524
526
|
|
|
525
527
|
log.debug('Trigger or action: %s', settings.FUNCTION);
|
|
526
|
-
const outgoingMessageId = uuid.v4();
|
|
527
528
|
const outgoingMetadata = {
|
|
528
529
|
...metadata,
|
|
529
530
|
...getAdditionalMetadataFromSettings(settings),
|
|
530
531
|
parentMessageId: metadata.messageId,
|
|
531
532
|
threadId: metadata.threadId,
|
|
532
|
-
messageId: outgoingMessageId,
|
|
533
533
|
execId: settings.EXEC_ID,
|
|
534
534
|
taskId: settings.FLOW_ID,
|
|
535
535
|
workspaceId: settings.WORKSPACE_ID,
|
|
@@ -540,6 +540,8 @@ class Sailor {
|
|
|
540
540
|
function: settings.FUNCTION,
|
|
541
541
|
start: new Date().getTime()
|
|
542
542
|
};
|
|
543
|
+
delete outgoingMetadata.messageId;
|
|
544
|
+
|
|
543
545
|
let module;
|
|
544
546
|
try {
|
|
545
547
|
module = await this.componentReader.loadTriggerOrAction(settings.FUNCTION);
|
package/lib/settings.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elasticio-sailor-nodejs",
|
|
3
3
|
"description": "The official elastic.io library for bootstrapping and executing for Node.js connectors",
|
|
4
|
-
"version": "3.0.0-sailor-proxy-
|
|
4
|
+
"version": "3.0.0-sailor-proxy-dev22",
|
|
5
5
|
"main": "run.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"debug": "3.1.0",
|
|
24
24
|
"elasticio-rest-node": "2.0.0",
|
|
25
25
|
"event-to-promise": "0.8.0",
|
|
26
|
-
"jsonwebtoken": "
|
|
27
|
-
"lodash": "4.
|
|
26
|
+
"jsonwebtoken": "9.0.3",
|
|
27
|
+
"lodash": "4.18.1",
|
|
28
28
|
"p-throttle": "2.1.0",
|
|
29
29
|
"q": "1.5.1",
|
|
30
30
|
"uuid": "3.0.1"
|