@appium/base-driver 10.0.0-beta.0 → 10.0.0-beta.1

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.
Files changed (92) hide show
  1. package/README.md +0 -8
  2. package/build/lib/basedriver/capabilities.d.ts.map +1 -1
  3. package/build/lib/basedriver/capabilities.js +2 -4
  4. package/build/lib/basedriver/capabilities.js.map +1 -1
  5. package/build/lib/basedriver/commands/timeout.js +7 -25
  6. package/build/lib/basedriver/commands/timeout.js.map +1 -1
  7. package/build/lib/basedriver/core.d.ts +0 -8
  8. package/build/lib/basedriver/core.d.ts.map +1 -1
  9. package/build/lib/basedriver/core.js +8 -18
  10. package/build/lib/basedriver/core.js.map +1 -1
  11. package/build/lib/basedriver/driver.js +2 -2
  12. package/build/lib/basedriver/driver.js.map +1 -1
  13. package/build/lib/basedriver/helpers.d.ts +9 -1
  14. package/build/lib/basedriver/helpers.d.ts.map +1 -1
  15. package/build/lib/basedriver/helpers.js +56 -142
  16. package/build/lib/basedriver/helpers.js.map +1 -1
  17. package/build/lib/basedriver/validation.d.ts +7 -0
  18. package/build/lib/basedriver/validation.d.ts.map +1 -0
  19. package/build/lib/basedriver/validation.js +130 -0
  20. package/build/lib/basedriver/validation.js.map +1 -0
  21. package/build/lib/express/middleware.d.ts +0 -6
  22. package/build/lib/express/middleware.d.ts.map +1 -1
  23. package/build/lib/express/middleware.js +28 -60
  24. package/build/lib/express/middleware.js.map +1 -1
  25. package/build/lib/express/server.d.ts.map +1 -1
  26. package/build/lib/express/server.js +0 -1
  27. package/build/lib/express/server.js.map +1 -1
  28. package/build/lib/helpers/capabilities.d.ts +13 -6
  29. package/build/lib/helpers/capabilities.d.ts.map +1 -1
  30. package/build/lib/helpers/capabilities.js +7 -0
  31. package/build/lib/helpers/capabilities.js.map +1 -1
  32. package/build/lib/index.d.ts +1 -0
  33. package/build/lib/index.d.ts.map +1 -1
  34. package/build/lib/index.js +3 -1
  35. package/build/lib/index.js.map +1 -1
  36. package/build/lib/jsonwp-proxy/proxy.d.ts +0 -8
  37. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
  38. package/build/lib/jsonwp-proxy/proxy.js +7 -38
  39. package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
  40. package/build/lib/protocol/errors.d.ts +171 -277
  41. package/build/lib/protocol/errors.d.ts.map +1 -1
  42. package/build/lib/protocol/errors.js +201 -421
  43. package/build/lib/protocol/errors.js.map +1 -1
  44. package/build/lib/protocol/helpers.d.ts +6 -6
  45. package/build/lib/protocol/helpers.d.ts.map +1 -1
  46. package/build/lib/protocol/helpers.js +11 -7
  47. package/build/lib/protocol/helpers.js.map +1 -1
  48. package/build/lib/protocol/index.d.ts +2 -1
  49. package/build/lib/protocol/index.d.ts.map +1 -1
  50. package/build/lib/protocol/index.js +2 -1
  51. package/build/lib/protocol/index.js.map +1 -1
  52. package/build/lib/protocol/protocol.d.ts +5 -0
  53. package/build/lib/protocol/protocol.d.ts.map +1 -1
  54. package/build/lib/protocol/protocol.js +23 -23
  55. package/build/lib/protocol/protocol.js.map +1 -1
  56. package/build/lib/protocol/routes.d.ts +14 -715
  57. package/build/lib/protocol/routes.d.ts.map +1 -1
  58. package/build/lib/protocol/routes.js +28 -487
  59. package/build/lib/protocol/routes.js.map +1 -1
  60. package/build/lib/protocol/validators.d.ts +4 -7
  61. package/build/lib/protocol/validators.d.ts.map +1 -1
  62. package/build/lib/protocol/validators.js +4 -21
  63. package/build/lib/protocol/validators.js.map +1 -1
  64. package/lib/basedriver/capabilities.ts +2 -4
  65. package/lib/basedriver/commands/timeout.ts +11 -34
  66. package/lib/basedriver/core.ts +10 -19
  67. package/lib/basedriver/driver.ts +3 -3
  68. package/lib/basedriver/helpers.js +61 -167
  69. package/lib/basedriver/validation.ts +145 -0
  70. package/lib/express/middleware.js +32 -70
  71. package/lib/express/server.js +0 -2
  72. package/lib/helpers/capabilities.js +9 -4
  73. package/lib/index.js +2 -0
  74. package/lib/jsonwp-proxy/proxy.js +8 -45
  75. package/lib/protocol/{errors.js → errors.ts} +322 -436
  76. package/lib/protocol/helpers.js +12 -8
  77. package/lib/protocol/index.js +8 -1
  78. package/lib/protocol/protocol.js +25 -23
  79. package/lib/protocol/routes.js +30 -497
  80. package/lib/protocol/validators.ts +19 -0
  81. package/package.json +10 -11
  82. package/build/lib/basedriver/desired-caps.d.ts +0 -5
  83. package/build/lib/basedriver/desired-caps.d.ts.map +0 -1
  84. package/build/lib/basedriver/desired-caps.js +0 -92
  85. package/build/lib/basedriver/desired-caps.js.map +0 -1
  86. package/lib/basedriver/README.md +0 -36
  87. package/lib/basedriver/desired-caps.js +0 -103
  88. package/lib/express/README.md +0 -59
  89. package/lib/jsonwp-proxy/README.md +0 -52
  90. package/lib/jsonwp-status/README.md +0 -20
  91. package/lib/protocol/README.md +0 -100
  92. package/lib/protocol/validators.js +0 -38
@@ -7,17 +7,19 @@ import {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY} from '../constants';
7
7
  * so they have keys for both W3C and JSONWP protocols.
8
8
  * The argument value is NOT mutated
9
9
  *
10
- * @param {?Object} resValue The actual response value
11
- * @returns {?Object} Either modified value or the same one if
10
+ * @param {Object | undefined} resValue The actual response value
11
+ * @returns {Object | null} Either modified value or the same one if
12
12
  * nothing has been modified
13
13
  */
14
- function formatResponseValue(resValue) {
14
+ export function formatResponseValue(resValue) {
15
15
  if (_.isUndefined(resValue)) {
16
16
  // convert undefined to null
17
17
  return null;
18
18
  }
19
- // If the MJSONWP element key format (ELEMENT) was provided, add a duplicate key (element-6066-11e4-a52e-4f735466cecf)
20
- // If the W3C element key format (element-6066-11e4-a52e-4f735466cecf) was provided, add a duplicate key (ELEMENT)
19
+ // If the MJSONWP element key format (ELEMENT) was provided,
20
+ // add a duplicate key (element-6066-11e4-a52e-4f735466cecf)
21
+ // If the W3C element key format (element-6066-11e4-a52e-4f735466cecf)
22
+ // was provided, add a duplicate key (ELEMENT)
21
23
  return duplicateKeys(resValue, MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY);
22
24
  }
23
25
 
@@ -28,8 +30,10 @@ function formatResponseValue(resValue) {
28
30
  * @param {Object} responseBody
29
31
  * @returns {Object} The fixed response body
30
32
  */
31
- function formatStatus(responseBody) {
32
- return _.isPlainObject(responseBody) ? _.omit(responseBody, ['status']) : responseBody;
33
+ export function ensureW3cResponse(responseBody) {
34
+ return _.isPlainObject(responseBody)
35
+ ? _.omit(responseBody, ['status', 'sessionId'])
36
+ : responseBody;
33
37
  }
34
38
 
35
- export {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY, formatResponseValue, formatStatus};
39
+ export {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY};
@@ -12,7 +12,13 @@ import {
12
12
  validateExecuteMethodParams,
13
13
  } from './protocol';
14
14
  import {NO_SESSION_ID_COMMANDS, ALL_COMMANDS, METHOD_MAP, routeToCommandName} from './routes';
15
- import {errors, isErrorType, errorFromMJSONWPStatusCode, errorFromW3CJsonCode} from './errors';
15
+ import {
16
+ errors,
17
+ isErrorType,
18
+ errorFromMJSONWPStatusCode,
19
+ errorFromW3CJsonCode,
20
+ getResponseForW3CError,
21
+ } from './errors';
16
22
 
17
23
  export {
18
24
  routeConfiguringFunction,
@@ -34,4 +40,5 @@ export {
34
40
  GET_STATUS_COMMAND,
35
41
  LIST_DRIVER_COMMANDS_COMMAND,
36
42
  LIST_DRIVER_EXTENSIONS_COMMAND,
43
+ getResponseForW3CError,
37
44
  };
@@ -7,10 +7,11 @@ import {
7
7
  getResponseForW3CError,
8
8
  errorFromMJSONWPStatusCode,
9
9
  errorFromW3CJsonCode,
10
+ BadParametersError,
10
11
  } from './errors';
11
12
  import {METHOD_MAP, NO_SESSION_ID_COMMANDS} from './routes';
12
13
  import B from 'bluebird';
13
- import {formatResponseValue, formatStatus} from './helpers';
14
+ import {formatResponseValue, ensureW3cResponse} from './helpers';
14
15
  import {MAX_LOG_BODY_LENGTH, PROTOCOLS, DEFAULT_BASE_PATH} from '../constants';
15
16
  import {isW3cCaps} from '../helpers/capabilities';
16
17
  import log from '../basedriver/logger';
@@ -29,21 +30,32 @@ function determineProtocol(createSessionArgs) {
29
30
  return _.some(createSessionArgs, isW3cCaps) ? PROTOCOLS.W3C : PROTOCOLS.MJSONWP;
30
31
  }
31
32
 
33
+ /**
34
+ *
35
+ * @param {import('../basedriver/driver').BaseDriver} driver
36
+ * @param {string | null} [sessionId=null]
37
+ * @returns {keyof PROTOCOLS}
38
+ */
32
39
  function extractProtocol(driver, sessionId = null) {
33
- const dstDriver = _.isFunction(driver.driverForSession)
40
+ const dstDriver = _.isFunction(driver.driverForSession) && sessionId
34
41
  ? driver.driverForSession(sessionId)
35
42
  : driver;
36
43
  if (dstDriver === driver) {
37
44
  // Shortcircuit if the driver instance is not an umbrella driver
38
45
  // or it is Fake driver instance, where `driver.driverForSession`
39
46
  // always returns self instance
40
- return driver.protocol;
47
+ return driver.protocol ?? PROTOCOLS.W3C;
41
48
  }
42
49
 
43
50
  // Extract the protocol for the current session if the given driver is the umbrella one
44
51
  return dstDriver?.protocol ?? PROTOCOLS.W3C;
45
52
  }
46
53
 
54
+ /**
55
+ *
56
+ * @param {any} command
57
+ * @returns {boolean}
58
+ */
47
59
  function isSessionCommand(command) {
48
60
  return !_.includes(NO_SESSION_ID_COMMANDS, command);
49
61
  }
@@ -123,7 +135,7 @@ export function checkParams(paramSets, jsonObj, protocol) {
123
135
  if (paramSets.validate) {
124
136
  let message = paramSets.validate(jsonObj, protocol);
125
137
  if (message) {
126
- throw new errors.BadParametersError(message, jsonObj);
138
+ throw new errors.InvalidArgumentError(message);
127
139
  }
128
140
  }
129
141
  }
@@ -154,7 +166,7 @@ export function checkParams(paramSets, jsonObj, protocol) {
154
166
  return;
155
167
  }
156
168
  }
157
- throw new errors.BadParametersError(paramSets, receivedParams);
169
+ throw new BadParametersError(paramSets, receivedParams);
158
170
  }
159
171
 
160
172
  /*
@@ -287,9 +299,9 @@ function routeConfiguringFunction(driver) {
287
299
  }
288
300
 
289
301
  function buildHandler(app, method, path, spec, driver, isSessCmd) {
290
- let asyncHandler = async (req, res) => {
302
+ let asyncHandler = async (/** @type {import('express').Request} */ req, /** @type {import('express').Response} */ res) => {
291
303
  let jsonObj = req.body;
292
- let httpResBody = {};
304
+ let httpResBody = /** @type {any} */ ({});
293
305
  let httpStatus = 200;
294
306
  let newSessionId;
295
307
  let currentProtocol = extractProtocol(driver, req.params.sessionId);
@@ -489,24 +501,14 @@ function buildHandler(app, method, path, spec, driver, isSessCmd) {
489
501
 
490
502
  // decode the response, which is either a string or json
491
503
  if (_.isString(httpResBody)) {
492
- res.status(httpStatus).send(httpResBody);
504
+ res.status(httpStatus)
505
+ .setHeader('content-type', 'application/json; charset=utf-8')
506
+ .send(httpResBody);
493
507
  } else {
494
- if (newSessionId) {
495
- if (currentProtocol === PROTOCOLS.W3C) {
496
- httpResBody.value.sessionId = newSessionId;
497
- } else {
498
- httpResBody.sessionId = newSessionId;
499
- }
500
- } else {
501
- httpResBody.sessionId = req.params.sessionId || null;
508
+ if (newSessionId && currentProtocol === PROTOCOLS.W3C) {
509
+ httpResBody.value.sessionId = newSessionId;
502
510
  }
503
- // Don't include sessionId in W3C responses
504
- if (currentProtocol === PROTOCOLS.W3C) {
505
- delete httpResBody.sessionId;
506
- }
507
-
508
- httpResBody = formatStatus(httpResBody);
509
- res.status(httpStatus).json(httpResBody);
511
+ res.status(httpStatus).json(ensureW3cResponse(httpResBody));
510
512
  }
511
513
  };
512
514
  // add the method to the app