askui 0.17.1 → 0.18.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 (46) hide show
  1. package/dist/cjs/core/model/custom-element-json.d.ts +32 -15
  2. package/dist/cjs/core/model/custom-element.d.ts +3 -2
  3. package/dist/cjs/core/model/custom-element.js +4 -2
  4. package/dist/cjs/core/reporting/step-reporter.js +15 -6
  5. package/dist/cjs/execution/dsl.d.ts +361 -96
  6. package/dist/cjs/execution/dsl.js +361 -96
  7. package/dist/cjs/execution/index.d.ts +1 -1
  8. package/dist/cjs/execution/inference-client.js +9 -4
  9. package/dist/cjs/execution/ui-control-client-dependency-builder.js +3 -3
  10. package/dist/cjs/execution/ui-control-client.d.ts +154 -13
  11. package/dist/cjs/execution/ui-control-client.js +219 -21
  12. package/dist/cjs/execution/ui-controller-client-interface.d.ts +2 -0
  13. package/dist/cjs/execution/ui-controller-client.d.ts +1 -0
  14. package/dist/cjs/execution/ui-controller-client.js +11 -1
  15. package/dist/cjs/execution/ui-controller-not-connected-error.d.ts +4 -0
  16. package/dist/cjs/execution/ui-controller-not-connected-error.js +12 -0
  17. package/dist/cjs/lib/interactive_cli/create-example-project.js +1 -1
  18. package/dist/cjs/main.d.ts +1 -1
  19. package/dist/cjs/utils/analytics/analytics.d.ts +2 -0
  20. package/dist/cjs/utils/analytics/analytics.js +5 -0
  21. package/dist/cjs/utils/http/custom-errors/index.js +1 -1
  22. package/dist/cjs/utils/http/http-client-got.js +46 -20
  23. package/dist/esm/core/model/custom-element-json.d.ts +32 -15
  24. package/dist/esm/core/model/custom-element.d.ts +3 -2
  25. package/dist/esm/core/model/custom-element.js +4 -2
  26. package/dist/esm/core/reporting/step-reporter.js +15 -6
  27. package/dist/esm/execution/dsl.d.ts +361 -96
  28. package/dist/esm/execution/dsl.js +361 -96
  29. package/dist/esm/execution/index.d.ts +1 -1
  30. package/dist/esm/execution/inference-client.js +9 -4
  31. package/dist/esm/execution/ui-control-client-dependency-builder.js +3 -3
  32. package/dist/esm/execution/ui-control-client.d.ts +154 -13
  33. package/dist/esm/execution/ui-control-client.js +216 -21
  34. package/dist/esm/execution/ui-controller-client-interface.d.ts +2 -0
  35. package/dist/esm/execution/ui-controller-client.d.ts +1 -0
  36. package/dist/esm/execution/ui-controller-client.js +11 -1
  37. package/dist/esm/execution/ui-controller-not-connected-error.d.ts +4 -0
  38. package/dist/esm/execution/ui-controller-not-connected-error.js +8 -0
  39. package/dist/esm/lib/interactive_cli/create-example-project.js +1 -1
  40. package/dist/esm/main.d.ts +1 -1
  41. package/dist/esm/utils/analytics/analytics.d.ts +2 -0
  42. package/dist/esm/utils/analytics/analytics.js +5 -0
  43. package/dist/esm/utils/http/custom-errors/index.js +1 -1
  44. package/dist/esm/utils/http/http-client-got.js +46 -20
  45. package/dist/example_projects_templates/typescript/.eslintrc.json-template +3 -2
  46. package/package.json +1 -1
@@ -12,6 +12,22 @@ import { CookieJar } from 'tough-cookie';
12
12
  import { logger } from '../../lib';
13
13
  import { Credentials } from './credentials';
14
14
  import { httpClientErrorHandler } from './custom-errors';
15
+ function buildRetryLog(requestUrl, errorCode, statusCode, errorMessage, delayInMs, delayReason, attemptCount) {
16
+ const failureReasons = [];
17
+ if (statusCode !== undefined && statusCode >= 400) {
18
+ failureReasons.push(`status code ${statusCode}`);
19
+ }
20
+ if (errorCode !== undefined) {
21
+ failureReasons.push(`error code ${errorCode}`);
22
+ }
23
+ if (failureReasons.length === 0) {
24
+ failureReasons.push('unknown error');
25
+ }
26
+ const requestText = requestUrl ? `Request to ${requestUrl}` : 'Request';
27
+ return (`${requestText} failed with ${failureReasons.join(', ')}.`
28
+ + ` Retrying in ${delayInMs} ms... (based on ${delayReason}; attempt ${attemptCount})`
29
+ + `\nFull message:\n${errorMessage}`);
30
+ }
15
31
  export class HttpClientGot {
16
32
  constructor(token, customHeaders, cookies = {}, proxyAgents) {
17
33
  this.token = token;
@@ -27,33 +43,43 @@ export class HttpClientGot {
27
43
  buildGotExtendOptions(proxyAgents) {
28
44
  const gotExtendOptions = {
29
45
  retry: {
30
- calculateDelay: ({ attemptCount, retryOptions, error, computedValue, }) => {
46
+ calculateDelay: ({ attemptCount, retryOptions, error, retryAfter, }) => {
31
47
  var _a, _b, _c;
32
- if (attemptCount > retryOptions.limit
33
- || !this.shouldRetryOnError(error)) {
48
+ if (!this.shouldRetryOnError(error)) {
49
+ return 0;
50
+ }
51
+ if (attemptCount > retryOptions.limit) {
52
+ return 0;
53
+ }
54
+ const hasMethod = retryOptions.methods.includes(error.options.method);
55
+ const hasErrorCode = retryOptions.errorCodes.includes(error.code);
56
+ const hasStatusCode = error.response
57
+ && retryOptions.statusCodes.includes(error.response.statusCode);
58
+ if (!hasMethod || (!hasErrorCode && !hasStatusCode)) {
34
59
  return 0;
35
60
  }
36
- if (error.response !== undefined
37
- && error.response.headers['retry-after'] === undefined) {
38
- logger.debug(`Request to ${(_a = error.request) === null || _a === void 0 ? void 0 : _a.requestUrl} failed with status code ${(_b = error.response) === null || _b === void 0 ? void 0 : _b.statusCode}.\n${error.message}\nRetrying... (attempt ${attemptCount})`);
39
- return Math.min(1000 * Math.pow(2, (attemptCount - 1)) + Math.random() * 100, Number.MAX_SAFE_INTEGER);
61
+ if (error.response) {
62
+ if (retryAfter) {
63
+ if (retryOptions.maxRetryAfter === undefined
64
+ || retryAfter > retryOptions.maxRetryAfter) {
65
+ return 0;
66
+ }
67
+ logger.debug(buildRetryLog((_a = error.request) === null || _a === void 0 ? void 0 : _a.requestUrl, error.code, error.response.statusCode, error.message, retryAfter, 'retry-after header', attemptCount));
68
+ return retryAfter;
69
+ }
70
+ if (error.response.statusCode === 413) {
71
+ return 0;
72
+ }
40
73
  }
41
- logger.debug(`Request to ${(_c = error.request) === null || _c === void 0 ? void 0 : _c.requestUrl} failed.\n${error.message}\nRetrying... (attempt ${attemptCount})`);
42
- return computedValue;
74
+ const baseDelayInMs = 1000;
75
+ const noiseToPreventCollisions = Math.random() * 100;
76
+ const delayInMs = Math.min(Math.pow(2, (attemptCount - 1)) * baseDelayInMs + noiseToPreventCollisions, Number.MAX_SAFE_INTEGER);
77
+ logger.debug(buildRetryLog((_b = error.request) === null || _b === void 0 ? void 0 : _b.requestUrl, error.code, (_c = error.response) === null || _c === void 0 ? void 0 : _c.statusCode, error.message, delayInMs, 'retry-after header', attemptCount));
78
+ return delayInMs;
43
79
  },
44
- errorCodes: [
45
- 'ETIMEDOUT',
46
- 'ECONNRESET',
47
- 'EADDRINUSE',
48
- 'ECONNREFUSED',
49
- 'EPIPE',
50
- 'ENOTFOUND',
51
- 'ENETUNREACH',
52
- 'EAI_AGAIN',
53
- ],
54
80
  limit: 5,
81
+ maxRetryAfter: 10 * 60,
55
82
  methods: ['POST', 'GET', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'],
56
- statusCodes: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
57
83
  },
58
84
  };
59
85
  if (proxyAgents) {
@@ -12,9 +12,10 @@
12
12
  },
13
13
  "plugins": [
14
14
  "import",
15
- "askui"
15
+ "@askui/askui"
16
16
  ],
17
17
  "rules": {
18
- "askui/no-missing-askui-exec": "error"
18
+ "@askui/askui/no-missing-exec": "error",
19
+ "@askui/askui/expect": "error"
19
20
  }
20
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "askui",
3
- "version": "0.17.1",
3
+ "version": "0.18.1",
4
4
  "license": "MIT",
5
5
  "author": "askui GmbH <info@askui.com> (http://www.askui.com/)",
6
6
  "description": "Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on",