@speedkit/cli 2.57.1 → 2.59.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [2.59.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.58.0...v2.59.0) (2024-10-08)
2
+
3
+
4
+ ### Features
5
+
6
+ * **prewarm:** handle rateLimiter on retry ([b744295](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/b7442959fded70807d7d0d6ae4e58cc4afa756f3))
7
+ * **prewarm:** increase rateLimit after successfull batch ([d112927](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/d11292731b0151a0e467b595630673f452bdf845))
8
+
9
+ # [2.58.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.57.1...v2.58.0) (2024-09-27)
10
+
11
+
12
+ ### Features
13
+
14
+ * throw error if response of local docHandler is empty ([61fa850](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/61fa850077b983f6038f672b73f76c9b553aa2d3))
15
+
1
16
  ## [2.57.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.57.0...v2.57.1) (2024-09-26)
2
17
 
3
18
 
package/README.md CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @speedkit/cli
21
21
  $ sk COMMAND
22
22
  running command...
23
23
  $ sk (--version)
24
- @speedkit/cli/2.57.1 linux-x64 node-v20.17.0
24
+ @speedkit/cli/2.59.0 linux-x64 node-v20.18.0
25
25
  $ sk --help [COMMAND]
26
26
  USAGE
27
27
  $ sk COMMAND
@@ -13,6 +13,8 @@ const files_1 = require("../../models/files");
13
13
  const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
14
14
  const request_1 = require("./server/request");
15
15
  const document_handler_response_1 = require("./server/document-handler-response");
16
+ const safe_1 = require("../../helpers/safe");
17
+ const vm_empty_response_error_1 = require("../onboarding/error/vm-empty-response-error");
16
18
  class DocumentHandlerServer {
17
19
  customerConfig;
18
20
  files;
@@ -62,23 +64,20 @@ class DocumentHandlerServer {
62
64
  const script = new vm.Script(this.documentHandlerConfigCode + this.getTransformFunctionWrapper(), {
63
65
  filename: this.files.getByName("config_documentHandler").path,
64
66
  });
65
- try {
66
- return await (async () => {
67
- return await new Promise((resolve, reject) => {
68
- vmContext.skInternalResponse.resolve = resolve;
69
- // @ts-expect-error reject is unknown
70
- vmContext.reject = reject;
71
- const context = vm.createContext(vmContext);
72
- script.runInContext(context, { displayErrors: true });
73
- });
74
- })();
75
- }
76
- catch (error) {
77
- if (error instanceof Error) {
78
- throw new vm_error_1.VmError(error.message);
67
+ const vmResponse = await (0, safe_1.safe)(new Promise((resolve, reject) => {
68
+ vmContext.skInternalResponse.resolve = resolve;
69
+ // @ts-expect-error reject is unknown
70
+ vmContext.reject = reject;
71
+ const context = vm.createContext(vmContext);
72
+ script.runInContext(context, { displayErrors: true });
73
+ }));
74
+ if (vmResponse.success === true) {
75
+ if (!vmResponse.data.body || vmResponse.data.body?.length === 0) {
76
+ throw new vm_empty_response_error_1.VmEmptyResponseError(`documentHandlerResponse is empty for url: ${url}`);
79
77
  }
80
- throw new vm_error_1.VmError(String(error) + JSON.stringify(error));
78
+ return vmResponse.data;
81
79
  }
80
+ throw new vm_error_1.VmError(vmResponse.error + JSON.stringify(vmResponse.errorObj));
82
81
  }
83
82
  getTransformFunctionWrapper() {
84
83
  return `\n\npost(db, skInternalRequest, skInternalResponse).catch((err)=>{reject(err);});`;
@@ -0,0 +1,5 @@
1
+ import ApplicationError from "../../error-handling/error/application-error";
2
+ export declare class VmEmptyResponseError extends ApplicationError {
3
+ readonly code = "VM_EMPTY_RESPONSE_ERROR";
4
+ readonly suggestions: string[];
5
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VmEmptyResponseError = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const application_error_1 = tslib_1.__importDefault(require("../../error-handling/error/application-error"));
6
+ class VmEmptyResponseError extends application_error_1.default {
7
+ code = "VM_EMPTY_RESPONSE_ERROR";
8
+ suggestions = [
9
+ "You may forgot to return html somewhere, check config_documentHandler!",
10
+ ];
11
+ }
12
+ exports.VmEmptyResponseError = VmEmptyResponseError;
@@ -4,10 +4,14 @@ export declare class AssetApiClient {
4
4
  private sortParameters;
5
5
  private agent;
6
6
  private rateLimit;
7
+ private lowestRateLimit;
8
+ private isRetry;
7
9
  constructor(authenticationToken: string, app: string, sortParameters: boolean);
8
10
  fetchURL(url: string, variation: string): Promise<Response>;
11
+ setIsRetry(): void;
9
12
  getRateLimit(): number;
10
13
  reduceMaxRequestsPerSecond(): void;
14
+ increaseMaxRequestsPerSecond(): void;
11
15
  private isValidUrl;
12
16
  private setRateLimit;
13
17
  }
@@ -16,7 +16,9 @@ class AssetApiClient {
16
16
  keepAlive: true,
17
17
  rejectUnauthorized: false,
18
18
  });
19
- rateLimit = __1.DEFAULT_MAX_REQUESTS_PER_SECOND;
19
+ rateLimit = __1.DEFAULT_REQUESTS_PER_SECOND;
20
+ lowestRateLimit = __1.DEFAULT_REQUESTS_PER_SECOND;
21
+ isRetry = false;
20
22
  constructor(authenticationToken, app, sortParameters) {
21
23
  this.authenticationToken = authenticationToken;
22
24
  this.app = app;
@@ -39,11 +41,23 @@ class AssetApiClient {
39
41
  method: "HEAD",
40
42
  });
41
43
  }
44
+ setIsRetry() {
45
+ this.isRetry = true;
46
+ this.rateLimit = this.lowestRateLimit;
47
+ }
42
48
  getRateLimit() {
43
49
  return this.rateLimit;
44
50
  }
45
51
  reduceMaxRequestsPerSecond() {
46
52
  this.setRateLimit(this.rateLimit * __1.RATE_LIMIT_MULTIPLICATOR);
53
+ if (this.rateLimit < this.lowestRateLimit) {
54
+ this.lowestRateLimit = this.rateLimit;
55
+ }
56
+ }
57
+ increaseMaxRequestsPerSecond() {
58
+ if (this.rateLimit + 1 <= __1.MAX_REQUESTS_PER_SECOND && !this.isRetry) {
59
+ this.setRateLimit(this.rateLimit + 1);
60
+ }
47
61
  }
48
62
  isValidUrl(url) {
49
63
  if (!node_url_1.URL.canParse(url)) {
@@ -28,7 +28,8 @@ export declare enum ItemStatus {
28
28
  export declare const MIN_TIME_TO_FETCH_BATCH = 1000;
29
29
  export declare const FETCH_TIMEOUT = 10000;
30
30
  export declare const TIMOUT_AFTER_DETECTED_RATE_LIMIT = 5000;
31
- export declare const DEFAULT_MAX_REQUESTS_PER_SECOND = 15;
31
+ export declare const DEFAULT_REQUESTS_PER_SECOND = 10;
32
+ export declare const MAX_REQUESTS_PER_SECOND = 20;
32
33
  export declare const RATE_LIMIT_MULTIPLICATOR = 0.8;
33
34
  export declare const RATE_LIMIT_CODES: string[];
34
35
  export declare const TIMING_HEADER_ERROR_CODE_SELECTOR: RegExp;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_VARIATION = exports.VARIATION_SEPARATOR = exports.PROGRESS_BAR_FORMAT = exports.TIMING_HEADER_KEY = exports.TIMING_HEADER_ERROR_CODE_SELECTOR = exports.RATE_LIMIT_CODES = exports.RATE_LIMIT_MULTIPLICATOR = exports.DEFAULT_MAX_REQUESTS_PER_SECOND = exports.TIMOUT_AFTER_DETECTED_RATE_LIMIT = exports.FETCH_TIMEOUT = exports.MIN_TIME_TO_FETCH_BATCH = exports.ItemStatus = exports.PreWarmContext = void 0;
3
+ exports.DEFAULT_VARIATION = exports.VARIATION_SEPARATOR = exports.PROGRESS_BAR_FORMAT = exports.TIMING_HEADER_KEY = exports.TIMING_HEADER_ERROR_CODE_SELECTOR = exports.RATE_LIMIT_CODES = exports.RATE_LIMIT_MULTIPLICATOR = exports.MAX_REQUESTS_PER_SECOND = exports.DEFAULT_REQUESTS_PER_SECOND = exports.TIMOUT_AFTER_DETECTED_RATE_LIMIT = exports.FETCH_TIMEOUT = exports.MIN_TIME_TO_FETCH_BATCH = exports.ItemStatus = exports.PreWarmContext = void 0;
4
4
  class PreWarmContext {
5
5
  app;
6
6
  path;
@@ -28,7 +28,8 @@ var ItemStatus;
28
28
  exports.MIN_TIME_TO_FETCH_BATCH = 1000;
29
29
  exports.FETCH_TIMEOUT = 10_000;
30
30
  exports.TIMOUT_AFTER_DETECTED_RATE_LIMIT = 5000;
31
- exports.DEFAULT_MAX_REQUESTS_PER_SECOND = 15;
31
+ exports.DEFAULT_REQUESTS_PER_SECOND = 10;
32
+ exports.MAX_REQUESTS_PER_SECOND = 20;
32
33
  exports.RATE_LIMIT_MULTIPLICATOR = 0.8;
33
34
  exports.RATE_LIMIT_CODES = ["308", "310", "316"];
34
35
  exports.TIMING_HEADER_ERROR_CODE_SELECTOR = /errorcode;desc=([^,]*),/;
@@ -63,6 +63,7 @@ class PreWarmService {
63
63
  .getByStatus(_1.ItemStatus.RETRY)
64
64
  .map((entry) => entry.url);
65
65
  const retryList = this.generateAssetRequestList(urlsToRetry);
66
+ this.assetClient.setIsRetry();
66
67
  await this.fetchUrls(retryList);
67
68
  await this.printSummary(retryList);
68
69
  }
@@ -152,7 +153,9 @@ class PreWarmService {
152
153
  if (retryCount > 0) {
153
154
  await this.sleep(_1.TIMOUT_AFTER_DETECTED_RATE_LIMIT);
154
155
  this.assetClient.reduceMaxRequestsPerSecond();
156
+ return;
155
157
  }
158
+ this.assetClient.increaseMaxRequestsPerSecond();
156
159
  }
157
160
  showMinimalStatusUpdate(batch, assetList) {
158
161
  if (!this.cli.quiet) {
@@ -712,5 +712,5 @@
712
712
  ]
713
713
  }
714
714
  },
715
- "version": "2.57.1"
715
+ "version": "2.59.0"
716
716
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "2.57.1",
4
+ "version": "2.59.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"