botium-core 1.14.10 → 1.15.3
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 +216 -115
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +215 -114
- 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 +2 -2
- 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.3";
|
|
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
|
};
|
|
@@ -3348,7 +3388,8 @@ class Convo$6 {
|
|
|
3348
3388
|
scriptingMemory,
|
|
3349
3389
|
botMsg,
|
|
3350
3390
|
transcript,
|
|
3351
|
-
transcriptStep
|
|
3391
|
+
transcriptStep,
|
|
3392
|
+
transcriptSteps
|
|
3352
3393
|
});
|
|
3353
3394
|
await this.scriptingEvents.onBotEnd({
|
|
3354
3395
|
convo: this,
|
|
@@ -3574,7 +3615,7 @@ class Convo$6 {
|
|
|
3574
3615
|
return tomatch;
|
|
3575
3616
|
}
|
|
3576
3617
|
_checkNormalizeText(container, str) {
|
|
3577
|
-
return normalizeText(str,
|
|
3618
|
+
return normalizeText(str, container.caps);
|
|
3578
3619
|
}
|
|
3579
3620
|
expandPartialConvos() {
|
|
3580
3621
|
const _getIncludeLogicHookNames = convoStep => {
|
|
@@ -7637,7 +7678,7 @@ var BaseContainer_1 = class BaseContainer {
|
|
|
7637
7678
|
try {
|
|
7638
7679
|
await executeHook$1(this.caps, hook, Object.assign({
|
|
7639
7680
|
container: this,
|
|
7640
|
-
|
|
7681
|
+
fetch
|
|
7641
7682
|
}, args));
|
|
7642
7683
|
} catch (err) {
|
|
7643
7684
|
debug$7(`_RunCustomHook ${name} finished with error: ${err.message || util__default["default"].inspect(err)}`);
|
|
@@ -7924,6 +7965,10 @@ const {
|
|
|
7924
7965
|
v4: uuidv4
|
|
7925
7966
|
} = uuid__default["default"];
|
|
7926
7967
|
const debug$4 = debug__default["default"]('botium-connector-simplerest');
|
|
7968
|
+
const {
|
|
7969
|
+
ProxyAgent,
|
|
7970
|
+
Agent
|
|
7971
|
+
} = undici__default["default"];
|
|
7927
7972
|
const {
|
|
7928
7973
|
startProxy
|
|
7929
7974
|
} = proxy;
|
|
@@ -8000,6 +8045,16 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8000
8045
|
}
|
|
8001
8046
|
}
|
|
8002
8047
|
Build() {
|
|
8048
|
+
const agentOptions = {
|
|
8049
|
+
connect: {
|
|
8050
|
+
rejectUnauthorized: !!this.caps[Capabilities.SIMPLEREST_STRICT_SSL] // Equivalent to strictSSL of request module
|
|
8051
|
+
}
|
|
8052
|
+
};
|
|
8053
|
+
if (this.caps[Capabilities.SIMPLEREST_PROXY_URL]) {
|
|
8054
|
+
this.dispatcher = new ProxyAgent(this.caps[Capabilities.SIMPLEREST_PROXY_URL], agentOptions);
|
|
8055
|
+
} else {
|
|
8056
|
+
this.dispatcher = new Agent(agentOptions);
|
|
8057
|
+
}
|
|
8003
8058
|
return this._buildInbound();
|
|
8004
8059
|
}
|
|
8005
8060
|
Start() {
|
|
@@ -8140,6 +8195,27 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8140
8195
|
Clean() {
|
|
8141
8196
|
return this._cleanInbound();
|
|
8142
8197
|
}
|
|
8198
|
+
_fetchify(requestOptions) {
|
|
8199
|
+
requestOptions.signal = AbortSignal.timeout(requestOptions.timeout);
|
|
8200
|
+
delete requestOptions.timeout;
|
|
8201
|
+
if (requestOptions.body && !lodash__default["default"].isString(requestOptions.body)) {
|
|
8202
|
+
requestOptions.body = JSON.stringify(requestOptions.body);
|
|
8203
|
+
if (!requestOptions.headers) requestOptions.headers = {};
|
|
8204
|
+
if (!requestOptions.headers['Content-Type'] && !requestOptions.headers['content-type']) {
|
|
8205
|
+
requestOptions.headers['Content-Type'] = 'application/json';
|
|
8206
|
+
}
|
|
8207
|
+
}
|
|
8208
|
+
if (requestOptions.form) {
|
|
8209
|
+
if (requestOptions.body) {
|
|
8210
|
+
debug$4('Request.form and request.body are mutually exclusive');
|
|
8211
|
+
}
|
|
8212
|
+
requestOptions.body = new URLSearchParams(requestOptions.form).toString();
|
|
8213
|
+
// it is set automatically by fetch
|
|
8214
|
+
// requestOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
|
8215
|
+
delete requestOptions.form;
|
|
8216
|
+
}
|
|
8217
|
+
return requestOptions;
|
|
8218
|
+
}
|
|
8143
8219
|
|
|
8144
8220
|
// Separated just for better module testing
|
|
8145
8221
|
async _processBodyAsync(body, headers, isFromUser, updateContext) {
|
|
@@ -8410,12 +8486,25 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8410
8486
|
msg.sourceData = msg.sourceData || {};
|
|
8411
8487
|
msg.sourceData.requestOptions = requestOptions;
|
|
8412
8488
|
this.waitProcessQueue = [];
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8489
|
+
try {
|
|
8490
|
+
fetch(requestOptions.uri, requestOptions).then(async bodyRaw => {
|
|
8491
|
+
let body;
|
|
8492
|
+
try {
|
|
8493
|
+
if (bodyRaw.headers.get('content-type').includes('application/json')) {
|
|
8494
|
+
try {
|
|
8495
|
+
body = await bodyRaw.json();
|
|
8496
|
+
} catch (err) {
|
|
8497
|
+
body = await bodyRaw.text();
|
|
8498
|
+
debug$4(`failed to parse body as text, using text instead: ${body}`);
|
|
8499
|
+
}
|
|
8500
|
+
} else {
|
|
8501
|
+
body = await bodyRaw.text();
|
|
8502
|
+
}
|
|
8503
|
+
} catch (err) {
|
|
8504
|
+
return reject(new Error(`cant parse body: ${err.message}`));
|
|
8505
|
+
}
|
|
8506
|
+
if (!bodyRaw.ok) {
|
|
8507
|
+
debug$4(`got error response: ${bodyRaw.status}/${bodyRaw.statusText}`);
|
|
8419
8508
|
if (debug$4.enabled && body) {
|
|
8420
8509
|
debug$4(Utils.shortenJsonString(body));
|
|
8421
8510
|
}
|
|
@@ -8423,38 +8512,42 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8423
8512
|
const jsonBody = Utils.toJsonWeak(body);
|
|
8424
8513
|
const errKey = Object.keys(jsonBody).find(k => k.startsWith('err') || k.startsWith('fail'));
|
|
8425
8514
|
if (errKey) {
|
|
8426
|
-
return reject(new BotiumError(`got error response: ${
|
|
8515
|
+
return reject(new BotiumError(`got error response: ${bodyRaw.status}/${bodyRaw.statusText} - ${jsonBody[errKey]}`, {
|
|
8427
8516
|
message: Utils.shortenJsonString(body)
|
|
8428
8517
|
}));
|
|
8429
8518
|
}
|
|
8430
8519
|
}
|
|
8431
|
-
return reject(new Error(`got error response: ${
|
|
8520
|
+
return reject(new Error(`got error response: ${bodyRaw.status}/${bodyRaw.statusText}`));
|
|
8432
8521
|
}
|
|
8433
8522
|
if (body) {
|
|
8434
|
-
debug$4(`got response code: ${
|
|
8435
|
-
this._storeCookiesFromResponse(
|
|
8436
|
-
|
|
8437
|
-
body =
|
|
8438
|
-
|
|
8523
|
+
debug$4(`got response code: ${bodyRaw.status}/${bodyRaw.statusText}, body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(bodyRaw.headers)}`);
|
|
8524
|
+
this._storeCookiesFromResponse(bodyRaw);
|
|
8525
|
+
this._parseResponseBody(body).then(parsedBody => {
|
|
8526
|
+
body = parsedBody;
|
|
8527
|
+
if (body) {
|
|
8528
|
+
this._processBodyAsync(body, bodyRaw.headers, isFromUser, updateContext).then(() => resolve(this)).then(() => this._emptyWaitProcessQueue());
|
|
8529
|
+
} else {
|
|
8530
|
+
debug$4('ignoring response body (no string and no JSON object)');
|
|
8531
|
+
resolve(this);
|
|
8532
|
+
this._emptyWaitProcessQueue();
|
|
8533
|
+
}
|
|
8534
|
+
}).catch(err => {
|
|
8439
8535
|
debug$4(`ignoring not JSON formatted response body: ${err.message}`);
|
|
8440
8536
|
resolve(this);
|
|
8441
8537
|
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
|
-
}
|
|
8538
|
+
});
|
|
8451
8539
|
} else {
|
|
8452
|
-
debug$4(`got response code: ${
|
|
8540
|
+
debug$4(`got response code: ${bodyRaw.status}/${bodyRaw.statusText}, empty body`);
|
|
8453
8541
|
resolve(this);
|
|
8454
8542
|
this._emptyWaitProcessQueue();
|
|
8455
8543
|
}
|
|
8456
|
-
}
|
|
8457
|
-
|
|
8544
|
+
}).catch(err => {
|
|
8545
|
+
// rest request failed: fetch failed - Cause code: ECONNREFUSED - Cause message: connect ECONNREFUSED 127.0.0.1:3006
|
|
8546
|
+
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 : ''}`));
|
|
8547
|
+
});
|
|
8548
|
+
} catch (err) {
|
|
8549
|
+
return reject(new Error(`rest request failed: ${err.message}`));
|
|
8550
|
+
}
|
|
8458
8551
|
}));
|
|
8459
8552
|
}
|
|
8460
8553
|
async _buildRequest(msg) {
|
|
@@ -8471,7 +8564,6 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8471
8564
|
const requestOptions = {
|
|
8472
8565
|
uri,
|
|
8473
8566
|
method: this._getCapValue(Capabilities.SIMPLEREST_VERB) || this._getCapValue(Capabilities.SIMPLEREST_METHOD),
|
|
8474
|
-
followAllRedirects: true,
|
|
8475
8567
|
timeout
|
|
8476
8568
|
};
|
|
8477
8569
|
if (this.caps[Capabilities.SIMPLEREST_HEADERS_TEMPLATE]) {
|
|
@@ -8482,7 +8574,14 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8482
8574
|
throw new Error(`composing headers from SIMPLEREST_HEADERS_TEMPLATE failed (${err.message})`);
|
|
8483
8575
|
}
|
|
8484
8576
|
}
|
|
8485
|
-
|
|
8577
|
+
// It is possible to mix json, and non-json request messages. So it can happen that both
|
|
8578
|
+
// SIMPLEREST_BODY_FROM_JSON and SIMPLEREST_BODY_TEMPLATE are set
|
|
8579
|
+
if (this.caps[Capabilities.SIMPLEREST_BODY_FROM_JSON] && msg.sourceData && Object.keys(msg.sourceData).length > 0) {
|
|
8580
|
+
requestOptions.body = msg.sourceData;
|
|
8581
|
+
requestOptions.json = true;
|
|
8582
|
+
if (!requestOptions.headers) requestOptions.headers = {};
|
|
8583
|
+
requestOptions.headers['Content-Type'] = 'application/json';
|
|
8584
|
+
} else if (this.caps[Capabilities.SIMPLEREST_BODY_TEMPLATE]) {
|
|
8486
8585
|
const bodyRaw = this._getCapValue(Capabilities.SIMPLEREST_BODY_RAW);
|
|
8487
8586
|
if (bodyRaw) {
|
|
8488
8587
|
this.view.msg.messageText = nonEncodedMessage;
|
|
@@ -8495,6 +8594,10 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8495
8594
|
if (requestOptions.json && (!requestOptions.body || Object.keys(requestOptions.body).length === 0)) {
|
|
8496
8595
|
debug$4(`warning: requestOptions.body content seems to be empty - ${requestOptions.body} - capability: "${this.caps[Capabilities.SIMPLEREST_BODY_TEMPLATE]}"`);
|
|
8497
8596
|
}
|
|
8597
|
+
if (!bodyRaw) {
|
|
8598
|
+
if (!requestOptions.headers) requestOptions.headers = {};
|
|
8599
|
+
requestOptions.headers['Content-Type'] = 'application/json';
|
|
8600
|
+
}
|
|
8498
8601
|
} catch (err) {
|
|
8499
8602
|
throw new Error(`composing body from SIMPLEREST_BODY_TEMPLATE failed (${err.message})`);
|
|
8500
8603
|
}
|
|
@@ -8528,56 +8631,53 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8528
8631
|
}
|
|
8529
8632
|
}
|
|
8530
8633
|
this._addRequestOptions(requestOptions);
|
|
8634
|
+
this._fetchify(requestOptions);
|
|
8531
8635
|
await executeHook(this.caps, this.requestHook, Object.assign({
|
|
8532
8636
|
requestOptions
|
|
8533
8637
|
}, this.view));
|
|
8534
8638
|
this._addRequestCookies(requestOptions);
|
|
8535
8639
|
return requestOptions;
|
|
8536
8640
|
}
|
|
8537
|
-
async _waitForUrlResponse(
|
|
8641
|
+
async _waitForUrlResponse(httpConfig, retries) {
|
|
8538
8642
|
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
8539
8643
|
let tries = 0;
|
|
8540
8644
|
while (true) {
|
|
8541
|
-
debug$4(`_waitForUrlResponse checking url ${
|
|
8645
|
+
debug$4(`_waitForUrlResponse checking url ${httpConfig.uri} before proceed`);
|
|
8542
8646
|
if (tries > retries) {
|
|
8543
8647
|
throw new Error(`Failed to ping bot after ${retries} retries`);
|
|
8544
8648
|
}
|
|
8545
8649
|
tries++;
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8554
|
-
|
|
8555
|
-
body
|
|
8556
|
-
});
|
|
8557
|
-
});
|
|
8558
|
-
}));
|
|
8650
|
+
let bodyRaw;
|
|
8651
|
+
let body;
|
|
8652
|
+
let err;
|
|
8653
|
+
try {
|
|
8654
|
+
bodyRaw = await this.bottleneck(() => fetch(httpConfig.uri, httpConfig));
|
|
8655
|
+
body = await (httpConfig.json ? bodyRaw.json() : bodyRaw.text());
|
|
8656
|
+
} catch (e) {
|
|
8657
|
+
err = e;
|
|
8658
|
+
}
|
|
8559
8659
|
if (err) {
|
|
8560
|
-
debug$4(`_waitForUrlResponse error on url check ${
|
|
8660
|
+
debug$4(`_waitForUrlResponse error on url check ${httpConfig.uri}: ${err}`);
|
|
8561
8661
|
if (tries <= retries) {
|
|
8562
|
-
await timeout(
|
|
8662
|
+
await timeout(httpConfig.timeout);
|
|
8563
8663
|
}
|
|
8564
|
-
} else if (
|
|
8565
|
-
debug$4(`_waitForUrlResponse on url check ${
|
|
8664
|
+
} else if (!bodyRaw.ok) {
|
|
8665
|
+
debug$4(`_waitForUrlResponse on url check ${httpConfig.uri} got error response: ${bodyRaw.status}/${bodyRaw.statusText}`);
|
|
8566
8666
|
if (debug$4.enabled && body) {
|
|
8567
8667
|
debug$4(Utils.shortenJsonString(body));
|
|
8568
8668
|
}
|
|
8569
8669
|
if (tries <= retries) {
|
|
8570
|
-
await timeout(
|
|
8670
|
+
await timeout(httpConfig.timeout);
|
|
8571
8671
|
}
|
|
8572
8672
|
} else {
|
|
8573
|
-
debug$4(`_waitForUrlResponse success on url check ${
|
|
8574
|
-
this._storeCookiesFromResponse(
|
|
8673
|
+
debug$4(`_waitForUrlResponse success on url check ${httpConfig.uri}: ${bodyRaw.status}/${bodyRaw.statusText}`);
|
|
8674
|
+
this._storeCookiesFromResponse(bodyRaw);
|
|
8575
8675
|
if (debug$4.enabled && body) {
|
|
8576
|
-
debug$4(`body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(
|
|
8676
|
+
debug$4(`body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(bodyRaw.headers)}`);
|
|
8577
8677
|
}
|
|
8578
8678
|
return {
|
|
8579
8679
|
body,
|
|
8580
|
-
headers:
|
|
8680
|
+
headers: bodyRaw.headers
|
|
8581
8681
|
};
|
|
8582
8682
|
}
|
|
8583
8683
|
}
|
|
@@ -8729,7 +8829,6 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8729
8829
|
const pollConfig = {
|
|
8730
8830
|
method: verb,
|
|
8731
8831
|
uri,
|
|
8732
|
-
followAllRedirects: true,
|
|
8733
8832
|
timeout
|
|
8734
8833
|
};
|
|
8735
8834
|
if (this.caps[Capabilities.SIMPLEREST_POLL_HEADERS]) {
|
|
@@ -8745,12 +8844,17 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8745
8844
|
try {
|
|
8746
8845
|
pollConfig.body = this._getMustachedCap(Capabilities.SIMPLEREST_POLL_BODY, !bodyRaw);
|
|
8747
8846
|
pollConfig.json = !bodyRaw;
|
|
8847
|
+
if (!bodyRaw) {
|
|
8848
|
+
if (!pollConfig.headers) pollConfig.headers = {};
|
|
8849
|
+
pollConfig.headers['Content-Type'] = 'application/json';
|
|
8850
|
+
}
|
|
8748
8851
|
} catch (err) {
|
|
8749
8852
|
debug$4(`_runPolling: composing body from SIMPLEREST_POLL_BODY failed (${err.message})`);
|
|
8750
8853
|
return;
|
|
8751
8854
|
}
|
|
8752
8855
|
}
|
|
8753
8856
|
this._addRequestOptions(pollConfig);
|
|
8857
|
+
this._fetchify(pollConfig);
|
|
8754
8858
|
try {
|
|
8755
8859
|
await executeHook(this.caps, this.pollRequestHook, Object.assign({
|
|
8756
8860
|
requestOptions: pollConfig
|
|
@@ -8760,34 +8864,34 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8760
8864
|
return;
|
|
8761
8865
|
}
|
|
8762
8866
|
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
|
-
}
|
|
8867
|
+
try {
|
|
8868
|
+
const bodyRaw = await fetch(pollConfig.uri, pollConfig);
|
|
8869
|
+
let body = await (pollConfig.json ? bodyRaw.json() : bodyRaw.text());
|
|
8870
|
+
if (!bodyRaw.ok) {
|
|
8871
|
+
debug$4(`_runPolling: got error response: ${bodyRaw.status}/${bodyRaw.statusText}, request: ${JSON.stringify(pollConfig)}`);
|
|
8872
|
+
if (debug$4.enabled && body) {
|
|
8873
|
+
debug$4(Utils.shortenJsonString(body));
|
|
8874
|
+
}
|
|
8875
|
+
} else if (body) {
|
|
8876
|
+
debug$4(`_runPolling: got response code: ${bodyRaw.status}/${bodyRaw.statusText}, body: ${Utils.shortenJsonString(body)}, headers: ${Utils.shortenJsonString(bodyRaw.headers)}`);
|
|
8877
|
+
this._storeCookiesFromResponse(bodyRaw);
|
|
8878
|
+
try {
|
|
8879
|
+
body = await this._parseResponseBody(body);
|
|
8880
|
+
} catch (err) {
|
|
8881
|
+
debug$4(`_runPolling: ignoring not JSON formatted response body: ${err.message}`);
|
|
8882
|
+
return;
|
|
8883
|
+
}
|
|
8884
|
+
if (body) {
|
|
8885
|
+
setTimeout(() => this._processBodyAsync(body, bodyRaw.headers, true, !!this.caps[Capabilities.SIMPLEREST_POLL_UPDATE_CONTEXT]), 0);
|
|
8786
8886
|
} else {
|
|
8787
|
-
debug$4(
|
|
8887
|
+
debug$4('_runPolling: ignoring response body (no string and no JSON object)');
|
|
8788
8888
|
}
|
|
8889
|
+
} else {
|
|
8890
|
+
debug$4(`_runPolling: got response code: ${bodyRaw.status}/${bodyRaw.statusText}, empty body`);
|
|
8789
8891
|
}
|
|
8790
|
-
})
|
|
8892
|
+
} catch (err) {
|
|
8893
|
+
debug$4(`_runPolling: rest request failed: ${err.message}, request: ${JSON.stringify(pollConfig)}`);
|
|
8894
|
+
}
|
|
8791
8895
|
}
|
|
8792
8896
|
}
|
|
8793
8897
|
async _startPolling() {
|
|
@@ -8810,7 +8914,6 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8810
8914
|
const httpConfig = {
|
|
8811
8915
|
method: verb,
|
|
8812
8916
|
uri,
|
|
8813
|
-
followAllRedirects: true,
|
|
8814
8917
|
timeout
|
|
8815
8918
|
};
|
|
8816
8919
|
if (this.caps[`${capPrefix}_HEADERS`]) {
|
|
@@ -8830,6 +8933,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8830
8933
|
}
|
|
8831
8934
|
}
|
|
8832
8935
|
this._addRequestOptions(httpConfig);
|
|
8936
|
+
this._fetchify(httpConfig);
|
|
8833
8937
|
await executeHook(this.caps, this.requestHooks[capPrefix], Object.assign({
|
|
8834
8938
|
requestOptions: httpConfig
|
|
8835
8939
|
}, this.view));
|
|
@@ -8840,9 +8944,8 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8840
8944
|
return response;
|
|
8841
8945
|
}
|
|
8842
8946
|
_addRequestOptions(httpConfig) {
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
httpConfig.proxy = this.caps[Capabilities.SIMPLEREST_PROXY_URL];
|
|
8947
|
+
if (this.dispatcher) {
|
|
8948
|
+
httpConfig.dispatcher = this.dispatcher;
|
|
8846
8949
|
}
|
|
8847
8950
|
if (this.caps[Capabilities.SIMPLEREST_EXTRA_OPTIONS]) {
|
|
8848
8951
|
lodash__default["default"].merge(httpConfig, this.caps[Capabilities.SIMPLEREST_EXTRA_OPTIONS]);
|
|
@@ -8856,23 +8959,21 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
|
|
|
8856
8959
|
if (!requestOptions.headers) {
|
|
8857
8960
|
requestOptions.headers = {};
|
|
8858
8961
|
}
|
|
8859
|
-
|
|
8962
|
+
if (this.cookies[url.host]) {
|
|
8963
|
+
requestOptions.headers.Cookie = requestOptions.headers.Cookie ? `${requestOptions.headers.Cookie}; ${this.cookies[url.host]}` : this.cookies[url.host];
|
|
8964
|
+
}
|
|
8860
8965
|
}
|
|
8861
8966
|
_storeCookiesFromResponse(response) {
|
|
8862
8967
|
if (!this.caps[Capabilities.SIMPLEREST_COOKIE_REPLICATION] || !response) {
|
|
8863
8968
|
return;
|
|
8864
8969
|
}
|
|
8865
|
-
const responseCookies = response.headers
|
|
8970
|
+
const responseCookies = response.headers.get('set-cookie');
|
|
8866
8971
|
if (!responseCookies) {
|
|
8867
8972
|
return;
|
|
8868
8973
|
}
|
|
8869
|
-
const host =
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
cookie = cookie ? `${cookie}; ${cookieString}` : cookieString;
|
|
8873
|
-
});
|
|
8874
|
-
if (cookie) {
|
|
8875
|
-
this.cookies[host] = cookie;
|
|
8974
|
+
const host = response?.url ? new URL(response.url).host : null;
|
|
8975
|
+
if (host) {
|
|
8976
|
+
this.cookies[host] = responseCookies;
|
|
8876
8977
|
}
|
|
8877
8978
|
}
|
|
8878
8979
|
};
|