botium-core 1.14.10 → 1.15.2
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/dist/botium-cjs.js +214 -114
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +213 -113
- package/dist/botium-es.js.map +1 -1
- package/package.json +4 -4
- package/samples/connectors/simplerest-async/jokebot.js +24 -18
- package/src/Capabilities.js +3 -0
- package/src/containers/BaseContainer.js +1 -2
- package/src/containers/plugins/SimpleRestContainer.js +158 -89
- package/src/scripting/Convo.js +1 -1
- package/src/scripting/helper.js +59 -22
- package/src/scripting/logichook/asserter/BaseTextAsserter.js +1 -2
- package/src/scripting/logichook/asserter/ButtonsAsserter.js +3 -4
- package/src/scripting/logichook/userinput/MediaInput.js +14 -17
- package/test/compiler/compilertxt.spec.js +18 -0
- package/test/compiler/convos/txt/convos_jsonmessage.convo.txt +10 -0
- package/test/connectors/simplerest.spec.js +290 -42
- package/test/hooks/customhooks.spec.js +3 -5
- package/test/scripting/helper.spec.js +21 -0
- package/test/scripting/scriptingProvider.spec.js +34 -0
package/dist/botium-cjs.js
CHANGED
|
@@ -31,10 +31,10 @@ var yaml = require('yaml');
|
|
|
31
31
|
var child_process = require('child_process');
|
|
32
32
|
var socket = require('socket.io-client');
|
|
33
33
|
var bottleneck = require('bottleneck');
|
|
34
|
-
var request = require('request');
|
|
35
34
|
var mustache = require('mustache');
|
|
36
35
|
var mimeTypes = require('mime-types');
|
|
37
36
|
var ioredis = require('ioredis');
|
|
37
|
+
var undici = require('undici');
|
|
38
38
|
var express = require('express');
|
|
39
39
|
var bodyParser = require('body-parser');
|
|
40
40
|
|
|
@@ -69,20 +69,20 @@ var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
|
|
|
69
69
|
var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
|
|
70
70
|
var socket__default = /*#__PURE__*/_interopDefaultLegacy(socket);
|
|
71
71
|
var bottleneck__default = /*#__PURE__*/_interopDefaultLegacy(bottleneck);
|
|
72
|
-
var request__default = /*#__PURE__*/_interopDefaultLegacy(request);
|
|
73
72
|
var mustache__default = /*#__PURE__*/_interopDefaultLegacy(mustache);
|
|
74
73
|
var mimeTypes__default = /*#__PURE__*/_interopDefaultLegacy(mimeTypes);
|
|
75
74
|
var ioredis__default = /*#__PURE__*/_interopDefaultLegacy(ioredis);
|
|
75
|
+
var undici__default = /*#__PURE__*/_interopDefaultLegacy(undici);
|
|
76
76
|
var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
|
|
77
77
|
var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
|
|
78
78
|
|
|
79
79
|
var name = "botium-core";
|
|
80
|
-
var version$1 = "1.
|
|
80
|
+
var version$1 = "1.15.2";
|
|
81
81
|
var description = "The Selenium for Chatbots";
|
|
82
82
|
var main = "index.js";
|
|
83
83
|
var module$1 = "dist/botium-es.js";
|
|
84
84
|
var engines = {
|
|
85
|
-
node: ">=
|
|
85
|
+
node: ">=18.17"
|
|
86
86
|
};
|
|
87
87
|
var scripts = {
|
|
88
88
|
postinstall: "node ./report.js",
|
|
@@ -131,7 +131,6 @@ var dependencies = {
|
|
|
131
131
|
"promise-retry": "^2.0.1",
|
|
132
132
|
"promise.allsettled": "^1.0.7",
|
|
133
133
|
randomatic: "^3.1.1",
|
|
134
|
-
request: "^2.88.2",
|
|
135
134
|
rimraf: "^5.0.5",
|
|
136
135
|
"sanitize-filename": "^1.6.3",
|
|
137
136
|
slugify: "^1.6.6",
|
|
@@ -141,6 +140,7 @@ var dependencies = {
|
|
|
141
140
|
"swagger-jsdoc": "^6.2.8",
|
|
142
141
|
"swagger-ui-express": "^5.0.0",
|
|
143
142
|
tinyglobby: "^0.2.10",
|
|
143
|
+
undici: "^6.21.0",
|
|
144
144
|
uuid: "^9.0.1",
|
|
145
145
|
"word-error-rate": "0.0.7",
|
|
146
146
|
"write-yaml": "^1.0.0",
|
|
@@ -164,7 +164,7 @@ var devDependencies = {
|
|
|
164
164
|
"eslint-plugin-promise": "^6.1.1",
|
|
165
165
|
"eslint-plugin-standard": "^4.1.0",
|
|
166
166
|
mocha: "^10.3.0",
|
|
167
|
-
nock: "^
|
|
167
|
+
nock: "^14.0.0-beta.19",
|
|
168
168
|
"npm-check-updates": "^16.14.15",
|
|
169
169
|
nyc: "^15.1.0",
|
|
170
170
|
rollup: "2.79.1",
|
|
@@ -267,6 +267,7 @@ var Capabilities = {
|
|
|
267
267
|
SIMPLEREST_HEADERS_TEMPLATE: 'SIMPLEREST_HEADERS_TEMPLATE',
|
|
268
268
|
SIMPLEREST_BODY_TEMPLATE: 'SIMPLEREST_BODY_TEMPLATE',
|
|
269
269
|
SIMPLEREST_BODY_RAW: 'SIMPLEREST_BODY_RAW',
|
|
270
|
+
SIMPLEREST_BODY_FROM_JSON: 'SIMPLEREST_BODY_FROM_JSON',
|
|
270
271
|
SIMPLEREST_START_HOOK: 'SIMPLEREST_START_HOOK',
|
|
271
272
|
SIMPLEREST_STOP_HOOK: 'SIMPLEREST_STOP_HOOK',
|
|
272
273
|
SIMPLEREST_REQUEST_HOOK: 'SIMPLEREST_REQUEST_HOOK',
|
|
@@ -344,6 +345,8 @@ var Capabilities = {
|
|
|
344
345
|
SCRIPTING_CSV_UTTERANCE_STARTROW_HEADER: 'SCRIPTING_CSV_UTTERANCE_STARTROW_HEADER',
|
|
345
346
|
SCRIPTING_CSV_UTTERANCE_STOP_ON_EMPTY: 'SCRIPTING_CSV_UTTERANCE_STOP_ON_EMPTY',
|
|
346
347
|
SCRIPTING_NORMALIZE_TEXT: 'SCRIPTING_NORMALIZE_TEXT',
|
|
348
|
+
SCRIPTING_NORMALIZE_TEXT_REMOVE_CHARACTERES: 'SCRIPTING_NORMALIZE_TEXT_REMOVE_CHARACTERES',
|
|
349
|
+
SCRIPTING_NORMALIZE_TEXT_REMOVE_REGEXP: 'SCRIPTING_NORMALIZE_TEXT_REMOVE_REGEXP',
|
|
347
350
|
SCRIPTING_ENABLE_MEMORY: 'SCRIPTING_ENABLE_MEMORY',
|
|
348
351
|
SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS: 'SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS',
|
|
349
352
|
SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS: 'SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS',
|
|
@@ -442,6 +445,7 @@ Capabilities.SIMPLEREST_VERB;
|
|
|
442
445
|
Capabilities.SIMPLEREST_HEADERS_TEMPLATE;
|
|
443
446
|
Capabilities.SIMPLEREST_BODY_TEMPLATE;
|
|
444
447
|
Capabilities.SIMPLEREST_BODY_RAW;
|
|
448
|
+
Capabilities.SIMPLEREST_BODY_FROM_JSON;
|
|
445
449
|
Capabilities.SIMPLEREST_START_HOOK;
|
|
446
450
|
Capabilities.SIMPLEREST_STOP_HOOK;
|
|
447
451
|
Capabilities.SIMPLEREST_REQUEST_HOOK;
|
|
@@ -514,6 +518,8 @@ Capabilities.SCRIPTING_CSV_UTTERANCE_STARTROW;
|
|
|
514
518
|
Capabilities.SCRIPTING_CSV_UTTERANCE_STARTROW_HEADER;
|
|
515
519
|
Capabilities.SCRIPTING_CSV_UTTERANCE_STOP_ON_EMPTY;
|
|
516
520
|
Capabilities.SCRIPTING_NORMALIZE_TEXT;
|
|
521
|
+
Capabilities.SCRIPTING_NORMALIZE_TEXT_REMOVE_CHARACTERES;
|
|
522
|
+
Capabilities.SCRIPTING_NORMALIZE_TEXT_REMOVE_REGEXP;
|
|
517
523
|
Capabilities.SCRIPTING_ENABLE_MEMORY;
|
|
518
524
|
Capabilities.SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS;
|
|
519
525
|
Capabilities.SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS;
|
|
@@ -1586,7 +1592,31 @@ const {
|
|
|
1586
1592
|
E_SCRIPTING_MEMORY_COLUMN_MODE: E_SCRIPTING_MEMORY_COLUMN_MODE$1
|
|
1587
1593
|
} = Enums;
|
|
1588
1594
|
const WHITE_SPACES_EXCEPT_SPACE_CHAR_AT_THE_END = /[\n\t\r]+$/;
|
|
1589
|
-
const normalizeText$1 = (str,
|
|
1595
|
+
const normalizeText$1 = (str, doCleanupOrCaps) => {
|
|
1596
|
+
// TODO testlog
|
|
1597
|
+
debug$m('yxc1', doCleanupOrCaps);
|
|
1598
|
+
let basic;
|
|
1599
|
+
let charactersRemove = false;
|
|
1600
|
+
let regexpRemove = false;
|
|
1601
|
+
if (lodash__default["default"].isBoolean(doCleanupOrCaps) || lodash__default["default"].isNil(doCleanupOrCaps)) {
|
|
1602
|
+
debug$m('Normalize text: backward compatibility mode. Use caps instead of boolean flag');
|
|
1603
|
+
basic = !!doCleanupOrCaps;
|
|
1604
|
+
} else {
|
|
1605
|
+
const caps = doCleanupOrCaps;
|
|
1606
|
+
basic = !!caps[Capabilities.SCRIPTING_NORMALIZE_TEXT];
|
|
1607
|
+
if (caps[Capabilities.SCRIPTING_NORMALIZE_TEXT_REMOVE_CHARACTERES]) {
|
|
1608
|
+
charactersRemove = caps[Capabilities.SCRIPTING_NORMALIZE_TEXT_REMOVE_CHARACTERES];
|
|
1609
|
+
if (lodash__default["default"].isString(charactersRemove)) {
|
|
1610
|
+
const splitted = charactersRemove.split(/(?<!\/),/).map(e => e.trim()).map(e => e.split('/,').join(',').split('//').join('/')).filter(c => c.length > 0);
|
|
1611
|
+
charactersRemove = splitted.length ? splitted : [charactersRemove];
|
|
1612
|
+
} else if (!lodash__default["default"].isArray(charactersRemove)) {
|
|
1613
|
+
charactersRemove = false;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
if (caps[Capabilities.SCRIPTING_NORMALIZE_TEXT_REMOVE_REGEXP]) {
|
|
1617
|
+
regexpRemove = new RegExp(caps[Capabilities.SCRIPTING_NORMALIZE_TEXT_REMOVE_REGEXP], 'ug');
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1590
1620
|
if (str && lodash__default["default"].isArray(str)) {
|
|
1591
1621
|
str = str.join(' ');
|
|
1592
1622
|
} else if (str && !lodash__default["default"].isString(str)) {
|
|
@@ -1596,21 +1626,31 @@ const normalizeText$1 = (str, doCleanup) => {
|
|
|
1596
1626
|
str = `${str}`;
|
|
1597
1627
|
}
|
|
1598
1628
|
}
|
|
1599
|
-
if (str
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1629
|
+
if (str) {
|
|
1630
|
+
if (basic) {
|
|
1631
|
+
// remove html tags
|
|
1632
|
+
str = str.replace(/<p[^>]*>/g, ' ');
|
|
1633
|
+
str = str.replace(/<\/p>/g, ' ');
|
|
1634
|
+
str = str.replace(/<br[^>]*>/g, ' ');
|
|
1635
|
+
str = str.replace(/<[^>]*>/g, '');
|
|
1636
|
+
/* eslint-disable no-control-regex */
|
|
1637
|
+
// remove not printable characters
|
|
1638
|
+
str = str.replace(/[\x00-\x1F\x7F]/g, ' ');
|
|
1639
|
+
/* eslint-enable no-control-regex */
|
|
1640
|
+
// replace html entities
|
|
1641
|
+
str = str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, '\'').replace(/"/g, '"');
|
|
1642
|
+
// replace two spaces with one
|
|
1643
|
+
str = str.replace(/\s+/g, ' ');
|
|
1644
|
+
str = str.split('\n').map(s => s.trim()).join('\n').trim();
|
|
1645
|
+
}
|
|
1646
|
+
if (charactersRemove) {
|
|
1647
|
+
for (const character of charactersRemove) {
|
|
1648
|
+
str = str.split(character).join('');
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
if (regexpRemove) {
|
|
1652
|
+
str = str.replace(regexpRemove, '');
|
|
1653
|
+
}
|
|
1614
1654
|
}
|
|
1615
1655
|
return str;
|
|
1616
1656
|
};
|
|
@@ -3574,7 +3614,7 @@ class Convo$6 {
|
|
|
3574
3614
|
return tomatch;
|
|
3575
3615
|
}
|
|
3576
3616
|
_checkNormalizeText(container, str) {
|
|
3577
|
-
return normalizeText(str,
|
|
3617
|
+
return normalizeText(str, container.caps);
|
|
3578
3618
|
}
|
|
3579
3619
|
expandPartialConvos() {
|
|
3580
3620
|
const _getIncludeLogicHookNames = convoStep => {
|
|
@@ -7637,7 +7677,7 @@ var BaseContainer_1 = class BaseContainer {
|
|
|
7637
7677
|
try {
|
|
7638
7678
|
await executeHook$1(this.caps, hook, Object.assign({
|
|
7639
7679
|
container: this,
|
|
7640
|
-
|
|
7680
|
+
fetch
|
|
7641
7681
|
}, args));
|
|
7642
7682
|
} catch (err) {
|
|
7643
7683
|
debug$7(`_RunCustomHook ${name} finished with error: ${err.message || util__default["default"].inspect(err)}`);
|
|
@@ -7924,6 +7964,10 @@ const {
|
|
|
7924
7964
|
v4: uuidv4
|
|
7925
7965
|
} = uuid__default["default"];
|
|
7926
7966
|
const debug$4 = debug__default["default"]('botium-connector-simplerest');
|
|
7967
|
+
const {
|
|
7968
|
+
ProxyAgent,
|
|
7969
|
+
Agent
|
|
7970
|
+
} = undici__default["default"];
|
|
7927
7971
|
const {
|
|
7928
7972
|
startProxy
|
|
7929
7973
|
} = proxy;
|
|
@@ -8000,6 +8044,16 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8000
8044
|
}
|
|
8001
8045
|
}
|
|
8002
8046
|
Build() {
|
|
8047
|
+
const agentOptions = {
|
|
8048
|
+
connect: {
|
|
8049
|
+
rejectUnauthorized: !!this.caps[Capabilities.SIMPLEREST_STRICT_SSL] // Equivalent to strictSSL of request module
|
|
8050
|
+
}
|
|
8051
|
+
};
|
|
8052
|
+
if (this.caps[Capabilities.SIMPLEREST_PROXY_URL]) {
|
|
8053
|
+
this.dispatcher = new ProxyAgent(this.caps[Capabilities.SIMPLEREST_PROXY_URL], agentOptions);
|
|
8054
|
+
} else {
|
|
8055
|
+
this.dispatcher = new Agent(agentOptions);
|
|
8056
|
+
}
|
|
8003
8057
|
return this._buildInbound();
|
|
8004
8058
|
}
|
|
8005
8059
|
Start() {
|
|
@@ -8140,6 +8194,27 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8140
8194
|
Clean() {
|
|
8141
8195
|
return this._cleanInbound();
|
|
8142
8196
|
}
|
|
8197
|
+
_fetchify(requestOptions) {
|
|
8198
|
+
requestOptions.signal = AbortSignal.timeout(requestOptions.timeout);
|
|
8199
|
+
delete requestOptions.timeout;
|
|
8200
|
+
if (requestOptions.body && !lodash__default["default"].isString(requestOptions.body)) {
|
|
8201
|
+
requestOptions.body = JSON.stringify(requestOptions.body);
|
|
8202
|
+
if (!requestOptions.headers) requestOptions.headers = {};
|
|
8203
|
+
if (!requestOptions.headers['Content-Type'] && !requestOptions.headers['content-type']) {
|
|
8204
|
+
requestOptions.headers['Content-Type'] = 'application/json';
|
|
8205
|
+
}
|
|
8206
|
+
}
|
|
8207
|
+
if (requestOptions.form) {
|
|
8208
|
+
if (requestOptions.body) {
|
|
8209
|
+
debug$4('Request.form and request.body are mutually exclusive');
|
|
8210
|
+
}
|
|
8211
|
+
requestOptions.body = new URLSearchParams(requestOptions.form).toString();
|
|
8212
|
+
// it is set automatically by fetch
|
|
8213
|
+
// requestOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
|
8214
|
+
delete requestOptions.form;
|
|
8215
|
+
}
|
|
8216
|
+
return requestOptions;
|
|
8217
|
+
}
|
|
8143
8218
|
|
|
8144
8219
|
// Separated just for better module testing
|
|
8145
8220
|
async _processBodyAsync(body, headers, isFromUser, updateContext) {
|
|
@@ -8410,12 +8485,25 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8410
8485
|
msg.sourceData = msg.sourceData || {};
|
|
8411
8486
|
msg.sourceData.requestOptions = requestOptions;
|
|
8412
8487
|
this.waitProcessQueue = [];
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8488
|
+
try {
|
|
8489
|
+
fetch(requestOptions.uri, requestOptions).then(async bodyRaw => {
|
|
8490
|
+
let body;
|
|
8491
|
+
try {
|
|
8492
|
+
if (bodyRaw.headers.get('content-type').includes('application/json')) {
|
|
8493
|
+
try {
|
|
8494
|
+
body = await bodyRaw.json();
|
|
8495
|
+
} catch (err) {
|
|
8496
|
+
body = await bodyRaw.text();
|
|
8497
|
+
debug$4(`failed to parse body as text, using text instead: ${body}`);
|
|
8498
|
+
}
|
|
8499
|
+
} else {
|
|
8500
|
+
body = await bodyRaw.text();
|
|
8501
|
+
}
|
|
8502
|
+
} catch (err) {
|
|
8503
|
+
return reject(new Error(`cant parse body: ${err.message}`));
|
|
8504
|
+
}
|
|
8505
|
+
if (!bodyRaw.ok) {
|
|
8506
|
+
debug$4(`got error response: ${bodyRaw.status}/${bodyRaw.statusText}`);
|
|
8419
8507
|
if (debug$4.enabled && body) {
|
|
8420
8508
|
debug$4(Utils.shortenJsonString(body));
|
|
8421
8509
|
}
|
|
@@ -8423,38 +8511,42 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8423
8511
|
const jsonBody = Utils.toJsonWeak(body);
|
|
8424
8512
|
const errKey = Object.keys(jsonBody).find(k => k.startsWith('err') || k.startsWith('fail'));
|
|
8425
8513
|
if (errKey) {
|
|
8426
|
-
return reject(new BotiumError(`got error response: ${
|
|
8514
|
+
return reject(new BotiumError(`got error response: ${bodyRaw.status}/${bodyRaw.statusText} - ${jsonBody[errKey]}`, {
|
|
8427
8515
|
message: Utils.shortenJsonString(body)
|
|
8428
8516
|
}));
|
|
8429
8517
|
}
|
|
8430
8518
|
}
|
|
8431
|
-
return reject(new Error(`got error response: ${
|
|
8519
|
+
return reject(new Error(`got error response: ${bodyRaw.status}/${bodyRaw.statusText}`));
|
|
8432
8520
|
}
|
|
8433
8521
|
if (body) {
|
|
8434
|
-
debug$4(`got response code: ${
|
|
8435
|
-
this._storeCookiesFromResponse(
|
|
8436
|
-
|
|
8437
|
-
body =
|
|
8438
|
-
|
|
8522
|
+
debug$4(`got response code: ${bodyRaw.status}/${bodyRaw.statusText}, body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(bodyRaw.headers)}`);
|
|
8523
|
+
this._storeCookiesFromResponse(bodyRaw);
|
|
8524
|
+
this._parseResponseBody(body).then(parsedBody => {
|
|
8525
|
+
body = parsedBody;
|
|
8526
|
+
if (body) {
|
|
8527
|
+
this._processBodyAsync(body, bodyRaw.headers, isFromUser, updateContext).then(() => resolve(this)).then(() => this._emptyWaitProcessQueue());
|
|
8528
|
+
} else {
|
|
8529
|
+
debug$4('ignoring response body (no string and no JSON object)');
|
|
8530
|
+
resolve(this);
|
|
8531
|
+
this._emptyWaitProcessQueue();
|
|
8532
|
+
}
|
|
8533
|
+
}).catch(err => {
|
|
8439
8534
|
debug$4(`ignoring not JSON formatted response body: ${err.message}`);
|
|
8440
8535
|
resolve(this);
|
|
8441
8536
|
this._emptyWaitProcessQueue();
|
|
8442
|
-
|
|
8443
|
-
}
|
|
8444
|
-
if (body) {
|
|
8445
|
-
this._processBodyAsync(body, response.headers, isFromUser, updateContext).then(() => resolve(this)).then(() => this._emptyWaitProcessQueue());
|
|
8446
|
-
} else {
|
|
8447
|
-
debug$4('ignoring response body (no string and no JSON object)');
|
|
8448
|
-
resolve(this);
|
|
8449
|
-
this._emptyWaitProcessQueue();
|
|
8450
|
-
}
|
|
8537
|
+
});
|
|
8451
8538
|
} else {
|
|
8452
|
-
debug$4(`got response code: ${
|
|
8539
|
+
debug$4(`got response code: ${bodyRaw.status}/${bodyRaw.statusText}, empty body`);
|
|
8453
8540
|
resolve(this);
|
|
8454
8541
|
this._emptyWaitProcessQueue();
|
|
8455
8542
|
}
|
|
8456
|
-
}
|
|
8457
|
-
|
|
8543
|
+
}).catch(err => {
|
|
8544
|
+
// rest request failed: fetch failed - Cause code: ECONNREFUSED - Cause message: connect ECONNREFUSED 127.0.0.1:3006
|
|
8545
|
+
return reject(new Error(`rest request failed: ${err.message}${err.cause && err.cause.code ? ' - Cause code: ' + err.cause.code : ''}${err.cause && err.cause.message ? ' - Cause message: ' + err.cause.message : ''}`));
|
|
8546
|
+
});
|
|
8547
|
+
} catch (err) {
|
|
8548
|
+
return reject(new Error(`rest request failed: ${err.message}`));
|
|
8549
|
+
}
|
|
8458
8550
|
}));
|
|
8459
8551
|
}
|
|
8460
8552
|
async _buildRequest(msg) {
|
|
@@ -8471,7 +8563,6 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8471
8563
|
const requestOptions = {
|
|
8472
8564
|
uri,
|
|
8473
8565
|
method: this._getCapValue(Capabilities.SIMPLEREST_VERB) || this._getCapValue(Capabilities.SIMPLEREST_METHOD),
|
|
8474
|
-
followAllRedirects: true,
|
|
8475
8566
|
timeout
|
|
8476
8567
|
};
|
|
8477
8568
|
if (this.caps[Capabilities.SIMPLEREST_HEADERS_TEMPLATE]) {
|
|
@@ -8482,7 +8573,14 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8482
8573
|
throw new Error(`composing headers from SIMPLEREST_HEADERS_TEMPLATE failed (${err.message})`);
|
|
8483
8574
|
}
|
|
8484
8575
|
}
|
|
8485
|
-
|
|
8576
|
+
// It is possible to mix json, and non-json request messages. So it can happen that both
|
|
8577
|
+
// SIMPLEREST_BODY_FROM_JSON and SIMPLEREST_BODY_TEMPLATE are set
|
|
8578
|
+
if (this.caps[Capabilities.SIMPLEREST_BODY_FROM_JSON] && msg.sourceData && Object.keys(msg.sourceData).length > 0) {
|
|
8579
|
+
requestOptions.body = msg.sourceData;
|
|
8580
|
+
requestOptions.json = true;
|
|
8581
|
+
if (!requestOptions.headers) requestOptions.headers = {};
|
|
8582
|
+
requestOptions.headers['Content-Type'] = 'application/json';
|
|
8583
|
+
} else if (this.caps[Capabilities.SIMPLEREST_BODY_TEMPLATE]) {
|
|
8486
8584
|
const bodyRaw = this._getCapValue(Capabilities.SIMPLEREST_BODY_RAW);
|
|
8487
8585
|
if (bodyRaw) {
|
|
8488
8586
|
this.view.msg.messageText = nonEncodedMessage;
|
|
@@ -8495,6 +8593,10 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8495
8593
|
if (requestOptions.json && (!requestOptions.body || Object.keys(requestOptions.body).length === 0)) {
|
|
8496
8594
|
debug$4(`warning: requestOptions.body content seems to be empty - ${requestOptions.body} - capability: "${this.caps[Capabilities.SIMPLEREST_BODY_TEMPLATE]}"`);
|
|
8497
8595
|
}
|
|
8596
|
+
if (!bodyRaw) {
|
|
8597
|
+
if (!requestOptions.headers) requestOptions.headers = {};
|
|
8598
|
+
requestOptions.headers['Content-Type'] = 'application/json';
|
|
8599
|
+
}
|
|
8498
8600
|
} catch (err) {
|
|
8499
8601
|
throw new Error(`composing body from SIMPLEREST_BODY_TEMPLATE failed (${err.message})`);
|
|
8500
8602
|
}
|
|
@@ -8528,56 +8630,53 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8528
8630
|
}
|
|
8529
8631
|
}
|
|
8530
8632
|
this._addRequestOptions(requestOptions);
|
|
8633
|
+
this._fetchify(requestOptions);
|
|
8531
8634
|
await executeHook(this.caps, this.requestHook, Object.assign({
|
|
8532
8635
|
requestOptions
|
|
8533
8636
|
}, this.view));
|
|
8534
8637
|
this._addRequestCookies(requestOptions);
|
|
8535
8638
|
return requestOptions;
|
|
8536
8639
|
}
|
|
8537
|
-
async _waitForUrlResponse(
|
|
8640
|
+
async _waitForUrlResponse(httpConfig, retries) {
|
|
8538
8641
|
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
8539
8642
|
let tries = 0;
|
|
8540
8643
|
while (true) {
|
|
8541
|
-
debug$4(`_waitForUrlResponse checking url ${
|
|
8644
|
+
debug$4(`_waitForUrlResponse checking url ${httpConfig.uri} before proceed`);
|
|
8542
8645
|
if (tries > retries) {
|
|
8543
8646
|
throw new Error(`Failed to ping bot after ${retries} retries`);
|
|
8544
8647
|
}
|
|
8545
8648
|
tries++;
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8554
|
-
|
|
8555
|
-
body
|
|
8556
|
-
});
|
|
8557
|
-
});
|
|
8558
|
-
}));
|
|
8649
|
+
let bodyRaw;
|
|
8650
|
+
let body;
|
|
8651
|
+
let err;
|
|
8652
|
+
try {
|
|
8653
|
+
bodyRaw = await this.bottleneck(() => fetch(httpConfig.uri, httpConfig));
|
|
8654
|
+
body = await (httpConfig.json ? bodyRaw.json() : bodyRaw.text());
|
|
8655
|
+
} catch (e) {
|
|
8656
|
+
err = e;
|
|
8657
|
+
}
|
|
8559
8658
|
if (err) {
|
|
8560
|
-
debug$4(`_waitForUrlResponse error on url check ${
|
|
8659
|
+
debug$4(`_waitForUrlResponse error on url check ${httpConfig.uri}: ${err}`);
|
|
8561
8660
|
if (tries <= retries) {
|
|
8562
|
-
await timeout(
|
|
8661
|
+
await timeout(httpConfig.timeout);
|
|
8563
8662
|
}
|
|
8564
|
-
} else if (
|
|
8565
|
-
debug$4(`_waitForUrlResponse on url check ${
|
|
8663
|
+
} else if (!bodyRaw.ok) {
|
|
8664
|
+
debug$4(`_waitForUrlResponse on url check ${httpConfig.uri} got error response: ${bodyRaw.status}/${bodyRaw.statusText}`);
|
|
8566
8665
|
if (debug$4.enabled && body) {
|
|
8567
8666
|
debug$4(Utils.shortenJsonString(body));
|
|
8568
8667
|
}
|
|
8569
8668
|
if (tries <= retries) {
|
|
8570
|
-
await timeout(
|
|
8669
|
+
await timeout(httpConfig.timeout);
|
|
8571
8670
|
}
|
|
8572
8671
|
} else {
|
|
8573
|
-
debug$4(`_waitForUrlResponse success on url check ${
|
|
8574
|
-
this._storeCookiesFromResponse(
|
|
8672
|
+
debug$4(`_waitForUrlResponse success on url check ${httpConfig.uri}: ${bodyRaw.status}/${bodyRaw.statusText}`);
|
|
8673
|
+
this._storeCookiesFromResponse(bodyRaw);
|
|
8575
8674
|
if (debug$4.enabled && body) {
|
|
8576
|
-
debug$4(`body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(
|
|
8675
|
+
debug$4(`body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(bodyRaw.headers)}`);
|
|
8577
8676
|
}
|
|
8578
8677
|
return {
|
|
8579
8678
|
body,
|
|
8580
|
-
headers:
|
|
8679
|
+
headers: bodyRaw.headers
|
|
8581
8680
|
};
|
|
8582
8681
|
}
|
|
8583
8682
|
}
|
|
@@ -8729,7 +8828,6 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8729
8828
|
const pollConfig = {
|
|
8730
8829
|
method: verb,
|
|
8731
8830
|
uri,
|
|
8732
|
-
followAllRedirects: true,
|
|
8733
8831
|
timeout
|
|
8734
8832
|
};
|
|
8735
8833
|
if (this.caps[Capabilities.SIMPLEREST_POLL_HEADERS]) {
|
|
@@ -8745,12 +8843,17 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8745
8843
|
try {
|
|
8746
8844
|
pollConfig.body = this._getMustachedCap(Capabilities.SIMPLEREST_POLL_BODY, !bodyRaw);
|
|
8747
8845
|
pollConfig.json = !bodyRaw;
|
|
8846
|
+
if (!bodyRaw) {
|
|
8847
|
+
if (!pollConfig.headers) pollConfig.headers = {};
|
|
8848
|
+
pollConfig.headers['Content-Type'] = 'application/json';
|
|
8849
|
+
}
|
|
8748
8850
|
} catch (err) {
|
|
8749
8851
|
debug$4(`_runPolling: composing body from SIMPLEREST_POLL_BODY failed (${err.message})`);
|
|
8750
8852
|
return;
|
|
8751
8853
|
}
|
|
8752
8854
|
}
|
|
8753
8855
|
this._addRequestOptions(pollConfig);
|
|
8856
|
+
this._fetchify(pollConfig);
|
|
8754
8857
|
try {
|
|
8755
8858
|
await executeHook(this.caps, this.pollRequestHook, Object.assign({
|
|
8756
8859
|
requestOptions: pollConfig
|
|
@@ -8760,34 +8863,34 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8760
8863
|
return;
|
|
8761
8864
|
}
|
|
8762
8865
|
this._addRequestCookies(pollConfig);
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
}
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
setTimeout(() => this._processBodyAsync(body, response.headers, true, !!this.caps[Capabilities.SIMPLEREST_POLL_UPDATE_CONTEXT]), 0);
|
|
8783
|
-
} else {
|
|
8784
|
-
debug$4('_runPolling: ignoring response body (no string and no JSON object)');
|
|
8785
|
-
}
|
|
8866
|
+
try {
|
|
8867
|
+
const bodyRaw = await fetch(pollConfig.uri, pollConfig);
|
|
8868
|
+
let body = await (pollConfig.json ? bodyRaw.json() : bodyRaw.text());
|
|
8869
|
+
if (!bodyRaw.ok) {
|
|
8870
|
+
debug$4(`_runPolling: got error response: ${bodyRaw.status}/${bodyRaw.statusText}, request: ${JSON.stringify(pollConfig)}`);
|
|
8871
|
+
if (debug$4.enabled && body) {
|
|
8872
|
+
debug$4(Utils.shortenJsonString(body));
|
|
8873
|
+
}
|
|
8874
|
+
} else if (body) {
|
|
8875
|
+
debug$4(`_runPolling: got response code: ${bodyRaw.status}/${bodyRaw.statusText}, body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(bodyRaw.headers)}`);
|
|
8876
|
+
this._storeCookiesFromResponse(bodyRaw);
|
|
8877
|
+
try {
|
|
8878
|
+
body = await this._parseResponseBody(body);
|
|
8879
|
+
} catch (err) {
|
|
8880
|
+
debug$4(`_runPolling: ignoring not JSON formatted response body: ${err.message}`);
|
|
8881
|
+
return;
|
|
8882
|
+
}
|
|
8883
|
+
if (body) {
|
|
8884
|
+
setTimeout(() => this._processBodyAsync(body, bodyRaw.headers, true, !!this.caps[Capabilities.SIMPLEREST_POLL_UPDATE_CONTEXT]), 0);
|
|
8786
8885
|
} else {
|
|
8787
|
-
debug$4(
|
|
8886
|
+
debug$4('_runPolling: ignoring response body (no string and no JSON object)');
|
|
8788
8887
|
}
|
|
8888
|
+
} else {
|
|
8889
|
+
debug$4(`_runPolling: got response code: ${bodyRaw.status}/${bodyRaw.statusText}, empty body`);
|
|
8789
8890
|
}
|
|
8790
|
-
})
|
|
8891
|
+
} catch (err) {
|
|
8892
|
+
debug$4(`_runPolling: rest request failed: ${err.message}, request: ${JSON.stringify(pollConfig)}`);
|
|
8893
|
+
}
|
|
8791
8894
|
}
|
|
8792
8895
|
}
|
|
8793
8896
|
async _startPolling() {
|
|
@@ -8810,7 +8913,6 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8810
8913
|
const httpConfig = {
|
|
8811
8914
|
method: verb,
|
|
8812
8915
|
uri,
|
|
8813
|
-
followAllRedirects: true,
|
|
8814
8916
|
timeout
|
|
8815
8917
|
};
|
|
8816
8918
|
if (this.caps[`${capPrefix}_HEADERS`]) {
|
|
@@ -8830,6 +8932,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8830
8932
|
}
|
|
8831
8933
|
}
|
|
8832
8934
|
this._addRequestOptions(httpConfig);
|
|
8935
|
+
this._fetchify(httpConfig);
|
|
8833
8936
|
await executeHook(this.caps, this.requestHooks[capPrefix], Object.assign({
|
|
8834
8937
|
requestOptions: httpConfig
|
|
8835
8938
|
}, this.view));
|
|
@@ -8840,9 +8943,8 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8840
8943
|
return response;
|
|
8841
8944
|
}
|
|
8842
8945
|
_addRequestOptions(httpConfig) {
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
httpConfig.proxy = this.caps[Capabilities.SIMPLEREST_PROXY_URL];
|
|
8946
|
+
if (this.dispatcher) {
|
|
8947
|
+
httpConfig.dispatcher = this.dispatcher;
|
|
8846
8948
|
}
|
|
8847
8949
|
if (this.caps[Capabilities.SIMPLEREST_EXTRA_OPTIONS]) {
|
|
8848
8950
|
lodash__default["default"].merge(httpConfig, this.caps[Capabilities.SIMPLEREST_EXTRA_OPTIONS]);
|
|
@@ -8856,23 +8958,21 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8856
8958
|
if (!requestOptions.headers) {
|
|
8857
8959
|
requestOptions.headers = {};
|
|
8858
8960
|
}
|
|
8859
|
-
|
|
8961
|
+
if (this.cookies[url.host]) {
|
|
8962
|
+
requestOptions.headers.Cookie = requestOptions.headers.Cookie ? `${requestOptions.headers.Cookie}; ${this.cookies[url.host]}` : this.cookies[url.host];
|
|
8963
|
+
}
|
|
8860
8964
|
}
|
|
8861
8965
|
_storeCookiesFromResponse(response) {
|
|
8862
8966
|
if (!this.caps[Capabilities.SIMPLEREST_COOKIE_REPLICATION] || !response) {
|
|
8863
8967
|
return;
|
|
8864
8968
|
}
|
|
8865
|
-
const responseCookies = response.headers
|
|
8969
|
+
const responseCookies = response.headers.get('set-cookie');
|
|
8866
8970
|
if (!responseCookies) {
|
|
8867
8971
|
return;
|
|
8868
8972
|
}
|
|
8869
|
-
const host =
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
cookie = cookie ? `${cookie}; ${cookieString}` : cookieString;
|
|
8873
|
-
});
|
|
8874
|
-
if (cookie) {
|
|
8875
|
-
this.cookies[host] = cookie;
|
|
8973
|
+
const host = response?.url ? new URL(response.url).host : null;
|
|
8974
|
+
if (host) {
|
|
8975
|
+
this.cookies[host] = responseCookies;
|
|
8876
8976
|
}
|
|
8877
8977
|
}
|
|
8878
8978
|
};
|