@speedkit/cli 2.60.0 → 2.61.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,14 @@
1
+ # [2.61.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.60.0...v2.61.0) (2024-10-18)
2
+
3
+
4
+ ### Features
5
+
6
+ * **customer-config:** add predictive preload package as default load handler feature ([9196dee](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/9196dee51d601c486ff8fc71d8c2b9c43f24817d))
7
+ * **customer-config:** update predictive preload package usage ([598824e](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/598824e93e12b4e474a60ef26f4cc1c997a5c8d7))
8
+ * **diff:** exchange tryCatch with safeMethod ([2cf32bc](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/2cf32bc4a4686153e29e8211ff97b65dd27742c1))
9
+ * **diffing:** add custom diffEndpoint for integrationDevtools ([b5b9b9e](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/b5b9b9e9ccb8bc1244551eb95d619fce4614c189))
10
+ * **diffing:** diffing show error case if remote fetch failed ([6447d53](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/6447d5325057d59559f85833c4e1332460e85c92))
11
+
1
12
  # [2.60.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.59.0...v2.60.0) (2024-10-14)
2
13
 
3
14
 
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.60.0 linux-x64 node-v20.18.0
24
+ @speedkit/cli/2.61.0 linux-x64 node-v20.18.0
25
25
  $ sk --help [COMMAND]
26
26
  USAGE
27
27
  $ sk COMMAND
@@ -6,6 +6,8 @@ import { HistoryApiPlugin } from 'rum/HistoryApiPlugin';
6
6
  import { GAEcommerceTrackingPlugin } from 'rum/GAEcommerceTrackingPlugin';
7
7
  {{/if}}
8
8
 
9
+ import { PredictivePreloading } from 'predictive-preloading/predictivePreloading';
10
+
9
11
  !function() {
10
12
  if (window !== window.top) {
11
13
  return;
@@ -562,4 +564,8 @@ import { GAEcommerceTrackingPlugin } from 'rum/GAEcommerceTrackingPlugin';
562
564
  });
563
565
  }
564
566
  {{/if}}
567
+
568
+ new PredictivePreloading({
569
+ // TODO: configure according to the needs of the customer
570
+ });
565
571
  }();
@@ -0,0 +1,10 @@
1
+ import { DiffService } from "../../diff";
2
+ import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
3
+ import { Crawler } from "../virtual-orestes-app/crawler";
4
+ export declare class DiffAgainstCurrentPage {
5
+ private diffService;
6
+ private documentHandlerRuntime;
7
+ private crawler;
8
+ constructor(diffService: DiffService, documentHandlerRuntime: DocumentHandlerServer, crawler: Crawler);
9
+ postDiff(currentHtml: string, currentUrl: string, variant?: string, transform?: boolean): Promise<boolean>;
10
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiffAgainstCurrentPage = void 0;
4
+ class DiffAgainstCurrentPage {
5
+ diffService;
6
+ documentHandlerRuntime;
7
+ crawler;
8
+ constructor(diffService, documentHandlerRuntime, crawler) {
9
+ this.diffService = diffService;
10
+ this.documentHandlerRuntime = documentHandlerRuntime;
11
+ this.crawler = crawler;
12
+ }
13
+ async postDiff(currentHtml, currentUrl, variant = "DEFAULT", transform = false) {
14
+ const originResponse = await this.crawler.fetchRemote(currentUrl, variant.toUpperCase());
15
+ let originHtml = await originResponse?.text();
16
+ if (!originHtml) {
17
+ throw new Error("Could not fetch remote page");
18
+ }
19
+ if (transform) {
20
+ // todo check if the currentHTML is already transformed
21
+ const currentDocumentHandlerResponse = await this.documentHandlerRuntime.transform(currentHtml, variant, currentUrl, {});
22
+ currentHtml = currentDocumentHandlerResponse.body;
23
+ const originDocumentHandlerResponse = await this.documentHandlerRuntime.transform(originHtml, variant, currentUrl, {});
24
+ originHtml = originDocumentHandlerResponse.body;
25
+ }
26
+ const remoteFilePath = await this.diffService.writeContentToTemporalFile(`remote-${variant}`, originHtml);
27
+ const localFilePath = await this.diffService.writeContentToTemporalFile("current", currentHtml);
28
+ return await this.diffService.executeDiff(localFilePath, remoteFilePath);
29
+ }
30
+ }
31
+ exports.DiffAgainstCurrentPage = DiffAgainstCurrentPage;
@@ -5,14 +5,16 @@ import { CustomerConfig } from "../../integration-api";
5
5
  import { RequestDiffService } from "./request-diff-service";
6
6
  import { Cache } from "../request-cache/cache";
7
7
  import { AthenaService } from "../../athena";
8
+ import { DiffAgainstCurrentPage } from "./diff-against-current-page";
8
9
  export declare class Dashboard {
9
10
  private customerConfig;
10
11
  private parameterQueryBuilder;
11
12
  private athenaClient;
12
13
  private requestDiffService;
14
+ private currentPageDiff;
13
15
  private cache;
14
16
  private athenaLastResult;
15
- constructor(customerConfig: CustomerConfig, parameterQueryBuilder: ParameterQueryBuilder, athenaClient: AthenaService, requestDiffService: RequestDiffService, cache: Cache);
17
+ constructor(customerConfig: CustomerConfig, parameterQueryBuilder: ParameterQueryBuilder, athenaClient: AthenaService, requestDiffService: RequestDiffService, currentPageDiff: DiffAgainstCurrentPage, cache: Cache);
16
18
  getResponse(request: Protocol.Network.Request): Promise<BaqendResponse>;
17
19
  private createBaqendResponse;
18
20
  }
@@ -10,13 +10,15 @@ class Dashboard {
10
10
  parameterQueryBuilder;
11
11
  athenaClient;
12
12
  requestDiffService;
13
+ currentPageDiff;
13
14
  cache;
14
15
  athenaLastResult = null;
15
- constructor(customerConfig, parameterQueryBuilder, athenaClient, requestDiffService, cache) {
16
+ constructor(customerConfig, parameterQueryBuilder, athenaClient, requestDiffService, currentPageDiff, cache) {
16
17
  this.customerConfig = customerConfig;
17
18
  this.parameterQueryBuilder = parameterQueryBuilder;
18
19
  this.athenaClient = athenaClient;
19
20
  this.requestDiffService = requestDiffService;
21
+ this.currentPageDiff = currentPageDiff;
20
22
  this.cache = cache;
21
23
  }
22
24
  async getResponse(request) {
@@ -69,6 +71,19 @@ class Dashboard {
69
71
  const data = JSON.parse(postData);
70
72
  return this.requestDiffService.postDiff(requestOrigin, data.url, data.paramKeys, data.autoDiff);
71
73
  }
74
+ if (url.pathname.startsWith("/variant-diff")) {
75
+ const postData = request.postData;
76
+ const data = JSON.parse(postData);
77
+ const currentHtml = data.currentHtml;
78
+ const currentUrl = data.currentUrl;
79
+ const variant = data.variant || "DEFAULT";
80
+ const transform = data.transform || false;
81
+ const diffResult = await (0, safe_1.safe)(this.currentPageDiff.postDiff(currentHtml, currentUrl, variant, transform));
82
+ if (diffResult.success === true) {
83
+ return this.createBaqendResponse(requestOrigin, JSON.stringify({ success: true }), "application/json; charset=UTF-8", [], 200);
84
+ }
85
+ return this.createBaqendResponse(requestOrigin, JSON.stringify({ success: false, error: diffResult.error }), "application/json; charset=UTF-8", [], 500);
86
+ }
72
87
  if (url.pathname.startsWith("/cache/get")) {
73
88
  const response = [];
74
89
  for (const [url, baqendResponse] of this.cache.getAll()) {
@@ -40,6 +40,7 @@ const config_api_1 = require("../config-api");
40
40
  const fs = tslib_1.__importStar(require("node:fs"));
41
41
  const path = tslib_1.__importStar(require("node:path"));
42
42
  const static_recipe_1 = require("../integration-api/virtual/static-recipe");
43
+ const diff_against_current_page_1 = require("./dashboard/diff-against-current-page");
43
44
  class OnboardingServiceFactory {
44
45
  context;
45
46
  cliConfig;
@@ -113,6 +114,7 @@ class OnboardingServiceFactory {
113
114
  async getFetchEventHandler(files, customerConfig, documentHandler, cache, cli, browserContext, athenaClient) {
114
115
  const configApi = this.getConfigApi(customerConfig.app);
115
116
  const serverConfig = await this.getSpeedKitServerConfig(configApi, cli);
117
+ const crawler = new crawler_1.Crawler(cli, serverConfig);
116
118
  const parameterQueryBuilder = new parameter_query_builder_1.ParameterQueryBuilder(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CONFIG.SPEED_KIT));
117
119
  const DiffService = new diff_1.DiffServiceFactory(new diff_1.DiffContext(this.cliConfig.diffExec, this.cliConfig.diffExecTemplate)).getService();
118
120
  const requestDiffService = new request_diff_service_1.RequestDiffService(DiffService, documentHandler);
@@ -124,12 +126,11 @@ class OnboardingServiceFactory {
124
126
  new speed_kit_service_worker_js_1.SpeedKitServiceWorkerJs(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CUSTOM.SW)),
125
127
  ];
126
128
  if (this.context.local) {
127
- const crawler = new crawler_1.Crawler(cli, serverConfig);
128
129
  const orestesApp = new virtual_orestes_app_1.VirtualOrestesApp(customerConfig, crawler, documentHandler, cache, cli);
129
130
  handlers.push(new speed_kit_asset_request_1.SpeedKitAssetRequest(customerConfig, orestesApp), new speed_kit_rum_pi_request_1.SpeedKitRumPiRequest(customerConfig, cache, cli));
130
131
  }
131
132
  if (athenaClient) {
132
- handlers.push(new dashboard_request_1.DashboardRequest(new dashboard_1.Dashboard(customerConfig, parameterQueryBuilder, athenaClient, requestDiffService, cache)));
133
+ handlers.push(new dashboard_request_1.DashboardRequest(new dashboard_1.Dashboard(customerConfig, parameterQueryBuilder, athenaClient, requestDiffService, new diff_against_current_page_1.DiffAgainstCurrentPage(DiffService, documentHandler, crawler), cache)));
133
134
  }
134
135
  return new fetch_event_handler_1.FetchEventHandler(handlers, customerConfig, cli, configApi);
135
136
  }
@@ -712,5 +712,5 @@
712
712
  ]
713
713
  }
714
714
  },
715
- "version": "2.60.0"
715
+ "version": "2.61.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.60.0",
4
+ "version": "2.61.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"