@appium/base-driver 8.5.2 → 8.5.5
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/build/lib/basedriver/capabilities.d.ts.map +1 -1
- package/build/lib/basedriver/capabilities.js +1 -1
- package/build/lib/basedriver/commands/event.js +1 -1
- package/build/lib/basedriver/commands/find.d.ts.map +1 -1
- package/build/lib/basedriver/commands/find.js +1 -1
- package/build/lib/basedriver/commands/index.js +1 -1
- package/build/lib/basedriver/commands/log.d.ts.map +1 -1
- package/build/lib/basedriver/commands/log.js +1 -1
- package/build/lib/basedriver/commands/session.js +1 -1
- package/build/lib/basedriver/commands/settings.d.ts.map +1 -1
- package/build/lib/basedriver/commands/settings.js +1 -1
- package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
- package/build/lib/basedriver/commands/timeout.js +1 -1
- package/build/lib/basedriver/core.d.ts +120 -139
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +1 -49
- package/build/lib/basedriver/desired-caps.d.ts +5 -2
- package/build/lib/basedriver/desired-caps.d.ts.map +1 -1
- package/build/lib/basedriver/desired-caps.js +14 -18
- package/build/lib/basedriver/device-settings.d.ts +9 -9
- package/build/lib/basedriver/device-settings.d.ts.map +1 -1
- package/build/lib/basedriver/device-settings.js +4 -4
- package/build/lib/basedriver/driver.d.ts +43 -38
- package/build/lib/basedriver/driver.d.ts.map +1 -1
- package/build/lib/basedriver/driver.js +58 -11
- package/build/lib/basedriver/helpers.d.ts +8 -3
- package/build/lib/basedriver/helpers.d.ts.map +1 -1
- package/build/lib/basedriver/helpers.js +4 -6
- package/build/lib/basedriver/logger.d.ts +1 -1
- package/build/lib/basedriver/logger.d.ts.map +1 -1
- package/build/lib/basedriver/logger.js +1 -1
- package/build/lib/constants.js +1 -1
- package/build/lib/express/crash.d.ts.map +1 -1
- package/build/lib/express/crash.js +1 -1
- package/build/lib/express/express-logging.d.ts.map +1 -1
- package/build/lib/express/express-logging.js +1 -1
- package/build/lib/express/idempotency.js +1 -1
- package/build/lib/express/logger.d.ts +1 -1
- package/build/lib/express/logger.d.ts.map +1 -1
- package/build/lib/express/logger.js +1 -1
- package/build/lib/express/middleware.d.ts.map +1 -1
- package/build/lib/express/middleware.js +1 -1
- package/build/lib/express/server.d.ts +21 -0
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +4 -9
- package/build/lib/express/static.d.ts.map +1 -1
- package/build/lib/express/static.js +2 -2
- package/build/lib/express/websocket.d.ts +14 -11
- package/build/lib/express/websocket.d.ts.map +1 -1
- package/build/lib/express/websocket.js +2 -2
- package/build/lib/helpers/capabilities.d.ts.map +1 -1
- package/build/lib/helpers/capabilities.js +1 -1
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.js +7 -1
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.js +2 -2
- package/build/lib/jsonwp-proxy/proxy.d.ts +30 -5
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +20 -4
- package/build/lib/jsonwp-status/status.d.ts.map +1 -1
- package/build/lib/jsonwp-status/status.js +2 -2
- package/build/lib/protocol/errors.d.ts +17 -8
- package/build/lib/protocol/errors.d.ts.map +1 -1
- package/build/lib/protocol/errors.js +9 -5
- package/build/lib/protocol/helpers.js +1 -1
- package/build/lib/protocol/index.js +1 -1
- package/build/lib/protocol/protocol.d.ts.map +1 -1
- package/build/lib/protocol/protocol.js +1 -1
- package/build/lib/protocol/routes.d.ts +17 -3
- package/build/lib/protocol/routes.d.ts.map +1 -1
- package/build/lib/protocol/routes.js +1 -1
- package/build/lib/protocol/validators.js +1 -1
- package/build/test/basedriver/driver-e2e-tests.js +1 -1
- package/build/test/basedriver/driver-tests.js +1 -1
- package/build/test/basedriver/index.js +1 -1
- package/build/test/e2e/basedriver/driver.e2e.spec.js +1 -1
- package/build/test/e2e/basedriver/helpers.e2e.spec.js +1 -1
- package/build/test/e2e/basedriver/websockets.e2e.spec.js +1 -1
- package/build/test/e2e/express/server.e2e.spec.js +1 -1
- package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +1 -1
- package/build/test/e2e/protocol/fake-driver.js +1 -1
- package/build/test/e2e/protocol/helpers.js +1 -1
- package/build/test/e2e/protocol/protocol.e2e.spec.js +13 -13
- package/build/test/helpers.js +1 -1
- package/build/test/unit/basedriver/capabilities.spec.js +12 -12
- package/build/test/unit/basedriver/capability.spec.js +15 -15
- package/build/test/unit/basedriver/commands/event.spec.js +1 -1
- package/build/test/unit/basedriver/commands/log.spec.js +1 -1
- package/build/test/unit/basedriver/device-settings.spec.js +1 -1
- package/build/test/unit/basedriver/driver.spec.js +1 -1
- package/build/test/unit/basedriver/helpers.spec.js +33 -33
- package/build/test/unit/basedriver/timeout.spec.js +1 -1
- package/build/test/unit/express/server.spec.js +1 -1
- package/build/test/unit/express/static.spec.js +2 -2
- package/build/test/unit/jsonwp-proxy/mock-request.js +1 -1
- package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +1 -1
- package/build/test/unit/jsonwp-proxy/proxy.spec.js +2 -2
- package/build/test/unit/jsonwp-proxy/url.spec.js +1 -1
- package/build/test/unit/jsonwp-status/status.spec.js +1 -1
- package/build/test/unit/protocol/errors.spec.js +1 -1
- package/build/test/unit/protocol/routes.spec.js +1 -1
- package/build/test/unit/protocol/validator.spec.js +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/basedriver/capabilities.js +95 -47
- package/lib/basedriver/commands/event.js +4 -4
- package/lib/basedriver/commands/find.js +12 -26
- package/lib/basedriver/commands/index.js +7 -7
- package/lib/basedriver/commands/log.js +5 -7
- package/lib/basedriver/commands/session.js +3 -3
- package/lib/basedriver/commands/settings.js +3 -5
- package/lib/basedriver/commands/timeout.js +18 -23
- package/lib/basedriver/core.js +150 -229
- package/lib/basedriver/desired-caps.js +30 -29
- package/lib/basedriver/device-settings.js +21 -20
- package/lib/basedriver/driver.js +131 -96
- package/lib/basedriver/helpers.js +124 -81
- package/lib/basedriver/logger.js +1 -1
- package/lib/constants.js +2 -6
- package/lib/express/crash.js +4 -6
- package/lib/express/express-logging.js +26 -24
- package/lib/express/idempotency.js +16 -16
- package/lib/express/logger.js +1 -1
- package/lib/express/middleware.js +49 -33
- package/lib/express/server.js +68 -44
- package/lib/express/static.js +11 -12
- package/lib/express/websocket.js +26 -16
- package/lib/helpers/capabilities.js +11 -16
- package/lib/index.js +50 -33
- package/lib/jsonwp-proxy/protocol-converter.js +85 -69
- package/lib/jsonwp-proxy/proxy.js +116 -53
- package/lib/jsonwp-status/status.js +36 -29
- package/lib/protocol/errors.js +469 -292
- package/lib/protocol/helpers.js +5 -8
- package/lib/protocol/index.js +22 -15
- package/lib/protocol/protocol.js +103 -55
- package/lib/protocol/routes.js +430 -273
- package/lib/protocol/validators.js +5 -5
- package/package.json +9 -11
- package/test/basedriver/driver-e2e-tests.js +92 -66
- package/test/basedriver/driver-tests.js +90 -33
- package/test/basedriver/index.js +1 -1
package/lib/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
1
|
import B from 'bluebird';
|
|
4
2
|
|
|
5
3
|
B.config({
|
|
@@ -7,62 +5,81 @@ B.config({
|
|
|
7
5
|
});
|
|
8
6
|
|
|
9
7
|
// BaseDriver exports
|
|
10
|
-
import {
|
|
11
|
-
export {
|
|
12
|
-
import {
|
|
8
|
+
import {BaseDriver} from './basedriver/driver';
|
|
9
|
+
export {DriverCore} from './basedriver/core';
|
|
10
|
+
import {DeviceSettings} from './basedriver/device-settings';
|
|
13
11
|
|
|
14
|
-
export {
|
|
12
|
+
export {BaseDriver, DeviceSettings};
|
|
15
13
|
export default BaseDriver;
|
|
16
14
|
|
|
17
|
-
|
|
18
15
|
// MJSONWP exports
|
|
19
16
|
import * as protocol from './protocol';
|
|
20
|
-
import {
|
|
21
|
-
DEFAULT_BASE_PATH, PROTOCOLS
|
|
22
|
-
} from './constants';
|
|
17
|
+
import {DEFAULT_BASE_PATH, PROTOCOLS} from './constants';
|
|
23
18
|
|
|
24
19
|
const {
|
|
25
|
-
routeConfiguringFunction,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
routeConfiguringFunction,
|
|
21
|
+
errors,
|
|
22
|
+
isErrorType,
|
|
23
|
+
errorFromMJSONWPStatusCode,
|
|
24
|
+
errorFromW3CJsonCode,
|
|
25
|
+
ALL_COMMANDS,
|
|
26
|
+
METHOD_MAP,
|
|
27
|
+
routeToCommandName,
|
|
28
|
+
NO_SESSION_ID_COMMANDS,
|
|
29
|
+
isSessionCommand,
|
|
30
|
+
determineProtocol,
|
|
31
|
+
CREATE_SESSION_COMMAND,
|
|
32
|
+
DELETE_SESSION_COMMAND,
|
|
33
|
+
GET_STATUS_COMMAND,
|
|
30
34
|
} = protocol;
|
|
31
35
|
|
|
32
36
|
export {
|
|
33
|
-
routeConfiguringFunction,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
routeConfiguringFunction,
|
|
38
|
+
errors,
|
|
39
|
+
isErrorType,
|
|
40
|
+
PROTOCOLS,
|
|
41
|
+
errorFromMJSONWPStatusCode,
|
|
42
|
+
errorFromW3CJsonCode,
|
|
43
|
+
determineProtocol,
|
|
44
|
+
errorFromMJSONWPStatusCode as errorFromCode,
|
|
45
|
+
ALL_COMMANDS,
|
|
46
|
+
METHOD_MAP,
|
|
47
|
+
routeToCommandName,
|
|
48
|
+
NO_SESSION_ID_COMMANDS,
|
|
49
|
+
isSessionCommand,
|
|
50
|
+
DEFAULT_BASE_PATH,
|
|
51
|
+
CREATE_SESSION_COMMAND,
|
|
52
|
+
DELETE_SESSION_COMMAND,
|
|
53
|
+
GET_STATUS_COMMAND,
|
|
39
54
|
};
|
|
40
55
|
|
|
41
56
|
// Express exports
|
|
42
57
|
import * as staticIndex from './express/static';
|
|
43
|
-
const {
|
|
44
|
-
export {
|
|
58
|
+
const {STATIC_DIR} = staticIndex;
|
|
59
|
+
export {STATIC_DIR};
|
|
45
60
|
|
|
46
61
|
import * as serverIndex from './express/server';
|
|
47
|
-
const {
|
|
48
|
-
export {
|
|
62
|
+
const {server, normalizeBasePath} = serverIndex;
|
|
63
|
+
export {server, normalizeBasePath};
|
|
49
64
|
|
|
50
65
|
// jsonwp-proxy exports
|
|
51
66
|
import * as proxyIndex from './jsonwp-proxy/proxy';
|
|
52
|
-
const {
|
|
53
|
-
export {
|
|
67
|
+
const {JWProxy} = proxyIndex;
|
|
68
|
+
export {JWProxy};
|
|
54
69
|
|
|
55
70
|
// jsonwp-status exports
|
|
56
71
|
import * as statusIndex from './jsonwp-status/status';
|
|
57
|
-
const {
|
|
58
|
-
export {
|
|
72
|
+
const {codes: statusCodes, getSummaryByCode} = statusIndex;
|
|
73
|
+
export {statusCodes, getSummaryByCode};
|
|
59
74
|
|
|
60
75
|
// W3C capabilities parser
|
|
61
76
|
import * as caps from './basedriver/capabilities';
|
|
62
|
-
const {
|
|
63
|
-
export {
|
|
77
|
+
const {processCapabilities, isStandardCap, validateCaps} = caps;
|
|
78
|
+
export {processCapabilities, isStandardCap, validateCaps};
|
|
64
79
|
|
|
65
80
|
// Web socket helpers
|
|
66
81
|
import * as ws from './express/websocket';
|
|
67
|
-
const {
|
|
68
|
-
export {
|
|
82
|
+
const {DEFAULT_WS_PATHNAME_PREFIX} = ws;
|
|
83
|
+
export {DEFAULT_WS_PATHNAME_PREFIX};
|
|
84
|
+
|
|
85
|
+
export {PREFIXED_APPIUM_OPTS_CAP} from './basedriver/capabilities';
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY, PROTOCOLS
|
|
6
|
-
} from '../constants';
|
|
2
|
+
import {logger, util} from '@appium/support';
|
|
3
|
+
import {duplicateKeys} from '../basedriver/helpers';
|
|
4
|
+
import {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY, PROTOCOLS} from '../constants';
|
|
7
5
|
|
|
8
6
|
export const COMMAND_URLS_CONFLICTS = [
|
|
9
7
|
{
|
|
10
8
|
commandNames: ['execute', 'executeAsync'],
|
|
11
|
-
jsonwpConverter: (url) =>
|
|
12
|
-
url.includes('async') ? '/execute_async' : '/execute'),
|
|
13
|
-
w3cConverter: (url) =>
|
|
14
|
-
url.includes('async') ? '/execute/async' : '/execute/sync'),
|
|
9
|
+
jsonwpConverter: (url) =>
|
|
10
|
+
url.replace(/\/execute.*/, url.includes('async') ? '/execute_async' : '/execute'),
|
|
11
|
+
w3cConverter: (url) =>
|
|
12
|
+
url.replace(/\/execute.*/, url.includes('async') ? '/execute/async' : '/execute/sync'),
|
|
15
13
|
},
|
|
16
14
|
{
|
|
17
15
|
commandNames: ['getElementScreenshot'],
|
|
18
|
-
jsonwpConverter: (url) => url.replace(/\/element\/([^/]+)\/screenshot$/,
|
|
19
|
-
|
|
20
|
-
w3cConverter: (url) => url.replace(/\/screenshot\/([^/]+)/,
|
|
21
|
-
'/element/$1/screenshot'),
|
|
16
|
+
jsonwpConverter: (url) => url.replace(/\/element\/([^/]+)\/screenshot$/, '/screenshot/$1'),
|
|
17
|
+
w3cConverter: (url) => url.replace(/\/screenshot\/([^/]+)/, '/element/$1/screenshot'),
|
|
22
18
|
},
|
|
23
19
|
{
|
|
24
20
|
commandNames: ['getWindowHandles', 'getWindowHandle'],
|
|
25
|
-
jsonwpConverter
|
|
21
|
+
jsonwpConverter(url) {
|
|
26
22
|
return /\/window$/.test(url)
|
|
27
23
|
? url.replace(/\/window$/, '/window_handle')
|
|
28
24
|
: url.replace(/\/window\/handle(s?)$/, '/window_handle$1');
|
|
29
25
|
},
|
|
30
|
-
w3cConverter
|
|
26
|
+
w3cConverter(url) {
|
|
31
27
|
return /\/window_handle$/.test(url)
|
|
32
28
|
? url.replace(/\/window_handle$/, '/window')
|
|
33
29
|
: url.replace(/\/window_handles$/, '/window/handles');
|
|
@@ -40,29 +36,28 @@ export const COMMAND_URLS_CONFLICTS = [
|
|
|
40
36
|
const jsonwpUrl = w3cUrl.replace(w3cPropertyRegex, '/element/$1/attribute/$2');
|
|
41
37
|
return jsonwpUrl;
|
|
42
38
|
},
|
|
43
|
-
w3cConverter: (jsonwpUrl) => jsonwpUrl // Don't convert JSONWP URL to W3C. W3C accepts /attribute and /property
|
|
44
|
-
}
|
|
39
|
+
w3cConverter: (jsonwpUrl) => jsonwpUrl, // Don't convert JSONWP URL to W3C. W3C accepts /attribute and /property
|
|
40
|
+
},
|
|
45
41
|
];
|
|
46
42
|
const {MJSONWP, W3C} = PROTOCOLS;
|
|
47
43
|
const DEFAULT_LOG = logger.getLogger('Protocol Converter');
|
|
48
44
|
|
|
49
|
-
|
|
50
45
|
class ProtocolConverter {
|
|
51
|
-
constructor
|
|
46
|
+
constructor(proxyFunc, log = null) {
|
|
52
47
|
this.proxyFunc = proxyFunc;
|
|
53
48
|
this._downstreamProtocol = null;
|
|
54
49
|
this._log = log;
|
|
55
50
|
}
|
|
56
51
|
|
|
57
|
-
get log
|
|
52
|
+
get log() {
|
|
58
53
|
return this._log ?? DEFAULT_LOG;
|
|
59
54
|
}
|
|
60
55
|
|
|
61
|
-
set downstreamProtocol
|
|
56
|
+
set downstreamProtocol(value) {
|
|
62
57
|
this._downstreamProtocol = value;
|
|
63
58
|
}
|
|
64
59
|
|
|
65
|
-
get downstreamProtocol
|
|
60
|
+
get downstreamProtocol() {
|
|
66
61
|
return this._downstreamProtocol;
|
|
67
62
|
}
|
|
68
63
|
|
|
@@ -74,25 +69,29 @@ class ProtocolConverter {
|
|
|
74
69
|
* @param {Object} body Request body
|
|
75
70
|
* @return {Array} Array of W3C + MJSONWP compatible timeout objects
|
|
76
71
|
*/
|
|
77
|
-
getTimeoutRequestObjects
|
|
72
|
+
getTimeoutRequestObjects(body) {
|
|
78
73
|
if (this.downstreamProtocol === W3C && _.has(body, 'ms') && _.has(body, 'type')) {
|
|
79
|
-
const typeToW3C = (x) => x === 'page load' ? 'pageLoad' : x;
|
|
80
|
-
return [
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
const typeToW3C = (x) => (x === 'page load' ? 'pageLoad' : x);
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
[typeToW3C(body.type)]: body.ms,
|
|
78
|
+
},
|
|
79
|
+
];
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
if (this.downstreamProtocol === MJSONWP && (!_.has(body, 'ms') || !_.has(body, 'type'))) {
|
|
86
|
-
const typeToJSONWP = (x) => x === 'pageLoad' ? 'page load' : x;
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
const typeToJSONWP = (x) => (x === 'pageLoad' ? 'page load' : x);
|
|
84
|
+
return (
|
|
85
|
+
_.toPairs(body)
|
|
86
|
+
// Only transform the entry if ms value is a valid positive float number
|
|
87
|
+
.filter((pair) => /^\d+(?:[.,]\d*?)?$/.test(`${pair[1]}`))
|
|
88
|
+
.map(function (pair) {
|
|
89
|
+
return {
|
|
90
|
+
type: typeToJSONWP(pair[0]),
|
|
91
|
+
ms: pair[1],
|
|
92
|
+
};
|
|
93
|
+
})
|
|
94
|
+
);
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
return [body];
|
|
@@ -104,11 +103,15 @@ class ProtocolConverter {
|
|
|
104
103
|
* @param {String} method Endpoint method
|
|
105
104
|
* @param {Object} body Request body
|
|
106
105
|
*/
|
|
107
|
-
async proxySetTimeouts
|
|
106
|
+
async proxySetTimeouts(url, method, body) {
|
|
108
107
|
let response, resBody;
|
|
109
108
|
|
|
110
109
|
const timeoutRequestObjects = this.getTimeoutRequestObjects(body);
|
|
111
|
-
this.log.debug(
|
|
110
|
+
this.log.debug(
|
|
111
|
+
`Will send the following request bodies to /timeouts: ${JSON.stringify(
|
|
112
|
+
timeoutRequestObjects
|
|
113
|
+
)}`
|
|
114
|
+
);
|
|
112
115
|
for (const timeoutObj of timeoutRequestObjects) {
|
|
113
116
|
[response, resBody] = await this.proxyFunc(url, method, timeoutObj);
|
|
114
117
|
|
|
@@ -127,7 +130,7 @@ class ProtocolConverter {
|
|
|
127
130
|
return [response, resBody];
|
|
128
131
|
}
|
|
129
132
|
|
|
130
|
-
async proxySetWindow
|
|
133
|
+
async proxySetWindow(url, method, body) {
|
|
131
134
|
const bodyObj = util.safeJsonParse(body);
|
|
132
135
|
if (_.isPlainObject(bodyObj)) {
|
|
133
136
|
if (this.downstreamProtocol === W3C && _.has(bodyObj, 'name') && !_.has(bodyObj, 'handle')) {
|
|
@@ -137,7 +140,11 @@ class ProtocolConverter {
|
|
|
137
140
|
handle: bodyObj.name,
|
|
138
141
|
});
|
|
139
142
|
}
|
|
140
|
-
if (
|
|
143
|
+
if (
|
|
144
|
+
this.downstreamProtocol === MJSONWP &&
|
|
145
|
+
_.has(bodyObj, 'handle') &&
|
|
146
|
+
!_.has(bodyObj, 'name')
|
|
147
|
+
) {
|
|
141
148
|
this.log.debug(`Copied 'handle' value '${bodyObj.handle}' to 'name' as per JSONWP spec`);
|
|
142
149
|
return await this.proxyFunc(url, method, {
|
|
143
150
|
...bodyObj,
|
|
@@ -149,48 +156,54 @@ class ProtocolConverter {
|
|
|
149
156
|
return await this.proxyFunc(url, method, body);
|
|
150
157
|
}
|
|
151
158
|
|
|
152
|
-
async proxySetValue
|
|
159
|
+
async proxySetValue(url, method, body) {
|
|
153
160
|
const bodyObj = util.safeJsonParse(body);
|
|
154
161
|
if (_.isPlainObject(bodyObj) && (util.hasValue(bodyObj.text) || util.hasValue(bodyObj.value))) {
|
|
155
162
|
let {text, value} = bodyObj;
|
|
156
163
|
if (util.hasValue(text) && !util.hasValue(value)) {
|
|
157
|
-
value = _.isString(text)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
164
|
+
value = _.isString(text) ? [...text] : _.isArray(text) ? text : [];
|
|
165
|
+
this.log.debug(
|
|
166
|
+
`Added 'value' property ${JSON.stringify(value)} to 'setValue' request body`
|
|
167
|
+
);
|
|
161
168
|
} else if (!util.hasValue(text) && util.hasValue(value)) {
|
|
162
|
-
text = _.isArray(value)
|
|
163
|
-
? value.join('')
|
|
164
|
-
: (_.isString(value) ? value : '');
|
|
169
|
+
text = _.isArray(value) ? value.join('') : _.isString(value) ? value : '';
|
|
165
170
|
this.log.debug(`Added 'text' property ${JSON.stringify(text)} to 'setValue' request body`);
|
|
166
171
|
}
|
|
167
|
-
return await this.proxyFunc(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
return await this.proxyFunc(
|
|
173
|
+
url,
|
|
174
|
+
method,
|
|
175
|
+
Object.assign({}, bodyObj, {
|
|
176
|
+
text,
|
|
177
|
+
value,
|
|
178
|
+
})
|
|
179
|
+
);
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
return await this.proxyFunc(url, method, body);
|
|
174
183
|
}
|
|
175
184
|
|
|
176
|
-
async proxySetFrame
|
|
185
|
+
async proxySetFrame(url, method, body) {
|
|
177
186
|
const bodyObj = util.safeJsonParse(body);
|
|
178
187
|
return _.has(bodyObj, 'id') && _.isPlainObject(bodyObj.id)
|
|
179
188
|
? await this.proxyFunc(url, method, {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
...bodyObj,
|
|
190
|
+
id: duplicateKeys(bodyObj.id, MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY),
|
|
191
|
+
})
|
|
183
192
|
: await this.proxyFunc(url, method, body);
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
async proxyPerformActions
|
|
195
|
+
async proxyPerformActions(url, method, body) {
|
|
187
196
|
const bodyObj = util.safeJsonParse(body);
|
|
188
197
|
return _.isPlainObject(bodyObj)
|
|
189
|
-
? await this.proxyFunc(
|
|
198
|
+
? await this.proxyFunc(
|
|
199
|
+
url,
|
|
200
|
+
method,
|
|
201
|
+
duplicateKeys(bodyObj, MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY)
|
|
202
|
+
)
|
|
190
203
|
: await this.proxyFunc(url, method, body);
|
|
191
204
|
}
|
|
192
205
|
|
|
193
|
-
async proxyReleaseActions
|
|
206
|
+
async proxyReleaseActions(url, method) {
|
|
194
207
|
return await this.proxyFunc(url, method);
|
|
195
208
|
}
|
|
196
209
|
|
|
@@ -204,7 +217,7 @@ class ProtocolConverter {
|
|
|
204
217
|
* @param {?string|object} body
|
|
205
218
|
* @returns The proxyfying result as [response, responseBody] tuple
|
|
206
219
|
*/
|
|
207
|
-
async convertAndProxy
|
|
220
|
+
async convertAndProxy(commandName, url, method, body) {
|
|
208
221
|
if (!this.downstreamProtocol) {
|
|
209
222
|
return await this.proxyFunc(url, method, body);
|
|
210
223
|
}
|
|
@@ -220,7 +233,7 @@ class ProtocolConverter {
|
|
|
220
233
|
case 'performActions':
|
|
221
234
|
return await this.proxyPerformActions(url, method, body);
|
|
222
235
|
case 'releaseActions':
|
|
223
|
-
return await this.proxyReleaseActions(url, method
|
|
236
|
+
return await this.proxyReleaseActions(url, method);
|
|
224
237
|
case 'setFrame':
|
|
225
238
|
return await this.proxySetFrame(url, method, body);
|
|
226
239
|
default:
|
|
@@ -233,16 +246,19 @@ class ProtocolConverter {
|
|
|
233
246
|
continue;
|
|
234
247
|
}
|
|
235
248
|
|
|
236
|
-
const rewrittenUrl =
|
|
237
|
-
? jsonwpConverter(url)
|
|
238
|
-
: w3cConverter(url);
|
|
249
|
+
const rewrittenUrl =
|
|
250
|
+
this.downstreamProtocol === MJSONWP ? jsonwpConverter(url) : w3cConverter(url);
|
|
239
251
|
if (rewrittenUrl === url) {
|
|
240
|
-
this.log.debug(
|
|
241
|
-
`
|
|
252
|
+
this.log.debug(
|
|
253
|
+
`Did not know how to rewrite the original URL '${url}' ` +
|
|
254
|
+
`for ${this.downstreamProtocol} protocol`
|
|
255
|
+
);
|
|
242
256
|
break;
|
|
243
257
|
}
|
|
244
|
-
this.log.info(
|
|
245
|
-
`
|
|
258
|
+
this.log.info(
|
|
259
|
+
`Rewrote the original URL '${url}' to '${rewrittenUrl}' ` +
|
|
260
|
+
`for ${this.downstreamProtocol} protocol`
|
|
261
|
+
);
|
|
246
262
|
return await this.proxyFunc(rewrittenUrl, method, body);
|
|
247
263
|
}
|
|
248
264
|
|