@speedkit/cli 2.13.0 → 2.14.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 (56) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -1
  3. package/dist/commands/document-handler.d.ts +1 -1
  4. package/dist/commands/document-handler.js +4 -4
  5. package/dist/commands/find-pops.d.ts +1 -1
  6. package/dist/commands/find-pops.js +21 -18
  7. package/dist/commands/login.d.ts +1 -1
  8. package/dist/commands/login.js +4 -4
  9. package/dist/commands/onboarding.d.ts +1 -1
  10. package/dist/commands/onboarding.js +12 -4
  11. package/dist/commands/param-diff.d.ts +2 -2
  12. package/dist/commands/param-diff.js +16 -16
  13. package/dist/commands/pop-prewarm.d.ts +2 -2
  14. package/dist/commands/pop-prewarm.js +20 -13
  15. package/dist/commands/prewarm.d.ts +2 -2
  16. package/dist/commands/prewarm.js +35 -19
  17. package/dist/commands/pull.d.ts +1 -1
  18. package/dist/commands/pull.js +2 -2
  19. package/dist/commands/wpt-launcher.d.ts +2 -2
  20. package/dist/commands/wpt-launcher.js +35 -19
  21. package/dist/helpers/CustomerConfig.d.ts +1 -1
  22. package/dist/helpers/CustomerConfig.js +36 -35
  23. package/dist/helpers/file-helper.js +6 -6
  24. package/dist/services/onboarding/browser/baqend-response.d.ts +3 -3
  25. package/dist/services/onboarding/browser/baqend-response.js +13 -12
  26. package/dist/services/onboarding/config-renderer/speed-kit-install-context.d.ts +4 -4
  27. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +38 -38
  28. package/dist/services/onboarding/dashboard/athena-service.d.ts +1 -1
  29. package/dist/services/onboarding/dashboard/athena-service.js +12 -12
  30. package/dist/services/onboarding/dashboard/index.d.ts +3 -3
  31. package/dist/services/onboarding/dashboard/index.js +14 -14
  32. package/dist/services/onboarding/dashboard/request-diff-service.d.ts +1 -1
  33. package/dist/services/onboarding/dashboard/request-diff-service.js +23 -23
  34. package/dist/services/onboarding/fetch-event-handler.d.ts +6 -6
  35. package/dist/services/onboarding/fetch-event-handler.js +52 -52
  36. package/dist/services/onboarding/fetch-events/customer-domain-document-response.d.ts +7 -7
  37. package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +43 -43
  38. package/dist/services/onboarding/fetch-events/customer-service-worker-js.d.ts +2 -2
  39. package/dist/services/onboarding/fetch-events/customer-service-worker-js.js +4 -4
  40. package/dist/services/onboarding/fetch-events/dashboard-request.d.ts +1 -1
  41. package/dist/services/onboarding/fetch-events/dashboard-request.js +2 -2
  42. package/dist/services/onboarding/fetch-events/speed-kit-asset-request.d.ts +7 -7
  43. package/dist/services/onboarding/fetch-events/speed-kit-asset-request.js +27 -27
  44. package/dist/services/onboarding/fetch-events/speed-kit-install-html.d.ts +2 -2
  45. package/dist/services/onboarding/fetch-events/speed-kit-install-html.js +12 -12
  46. package/dist/services/onboarding/file-events/file-watcher.d.ts +9 -9
  47. package/dist/services/onboarding/file-events/file-watcher.js +67 -67
  48. package/dist/services/onboarding/onboarding-service.d.ts +6 -6
  49. package/dist/services/onboarding/onboarding-service.js +38 -39
  50. package/dist/services/onboarding/request-cache/cache.d.ts +3 -3
  51. package/dist/services/onboarding/request-cache/cache.js +7 -7
  52. package/dist/services/onboarding/server-config/index.js +1 -1
  53. package/dist/services/onboarding/todo-collector.d.ts +1 -1
  54. package/dist/services/onboarding/todo-collector.js +3 -4
  55. package/oclif.manifest.json +1 -1
  56. package/package.json +1 -1
@@ -4,8 +4,8 @@ export declare class RequestDiffService {
4
4
  private diffService;
5
5
  constructor(diffService: DiffService);
6
6
  postDiff(url: string, parametersString: string): Promise<BaqendResponse>;
7
- private createUrlsForDiff;
8
7
  private diffLocal;
9
8
  private doOriginVsContentDiff;
10
9
  private fetchHtml;
10
+ private createUrlsForDiff;
11
11
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RequestDiffService = void 0;
4
- const safe_1 = require("../../../helpers/safe");
5
4
  const baqend_response_1 = require("../browser/baqend-response");
5
+ const safe_1 = require("../../../helpers/safe");
6
6
  class RequestDiffService {
7
7
  diffService;
8
8
  constructor(diffService) {
@@ -19,17 +19,34 @@ class RequestDiffService {
19
19
  const { urlWithParam, urlWithoutParam } = this.createUrlsForDiff(url, params);
20
20
  const result = await (0, safe_1.safe)(this.diffLocal(urlWithParam, urlWithoutParam));
21
21
  if (result.success === true) {
22
- return new baqend_response_1.BaqendResponse(JSON.stringify({ isIdentical: result.data, status: "success" }), "application/json; charset=UTF-8");
22
+ return new baqend_response_1.BaqendResponse(JSON.stringify({ status: "success", isIdentical: result.data }), "application/json; charset=UTF-8");
23
23
  }
24
- return new baqend_response_1.BaqendResponse(JSON.stringify({ error: result.error, status: "error" }), "application/json; charset=UTF-8", null, 500);
24
+ return new baqend_response_1.BaqendResponse(JSON.stringify({ status: "error", error: result.error }), "application/json; charset=UTF-8", null, 500);
25
+ }
26
+ async diffLocal(urlWithParam, urlWithoutParam) {
27
+ const htmlWithParam = await this.fetchHtml(urlWithParam);
28
+ const htmlWithoutParam = await this.fetchHtml(urlWithoutParam);
29
+ const paramsFilePath = await this.diffService.writeContentToTemporalFile("params", htmlWithParam);
30
+ const pureFilePath = await this.diffService.writeContentToTemporalFile("pure", htmlWithoutParam);
31
+ return await this.diffService.executeDiff(paramsFilePath, pureFilePath);
32
+ }
33
+ async doOriginVsContentDiff(url, content) {
34
+ const html = await this.fetchHtml(url);
35
+ const origin = await this.diffService.writeContentToTemporalFile("origin", html);
36
+ const local = await this.diffService.writeContentToTemporalFile("content", content);
37
+ return await this.diffService.executeDiff(local, origin);
38
+ }
39
+ async fetchHtml(url) {
40
+ const response = await fetch(url);
41
+ return await response.text();
25
42
  }
26
43
  createUrlsForDiff(urlWithParam, params) {
27
44
  const url = new URL(urlWithParam);
28
- const { searchParams } = url;
45
+ const search_params = url.searchParams;
29
46
  for (const param of params) {
30
- searchParams.delete(param);
47
+ search_params.delete(param);
31
48
  }
32
- url.search = searchParams.toString();
49
+ url.search = search_params.toString();
33
50
  const urlWithoutParam = url.toString();
34
51
  console.log("With-----");
35
52
  console.log(urlWithParam);
@@ -42,22 +59,5 @@ class RequestDiffService {
42
59
  urlWithoutParam,
43
60
  };
44
61
  }
45
- async diffLocal(urlWithParam, urlWithoutParam) {
46
- const htmlWithParam = await this.fetchHtml(urlWithParam);
47
- const htmlWithoutParam = await this.fetchHtml(urlWithoutParam);
48
- const paramsFilePath = await this.diffService.writeContentToTemporalFile("params", htmlWithParam);
49
- const pureFilePath = await this.diffService.writeContentToTemporalFile("pure", htmlWithoutParam);
50
- return this.diffService.executeDiff(paramsFilePath, pureFilePath);
51
- }
52
- async doOriginVsContentDiff(url, content) {
53
- const html = await this.fetchHtml(url);
54
- const origin = await this.diffService.writeContentToTemporalFile("origin", html);
55
- const local = await this.diffService.writeContentToTemporalFile("content", content);
56
- return this.diffService.executeDiff(local, origin);
57
- }
58
- async fetchHtml(url) {
59
- const response = await fetch(url);
60
- return response.text();
61
- }
62
62
  }
63
63
  exports.RequestDiffService = RequestDiffService;
@@ -1,19 +1,19 @@
1
- import { CDPSession, Target } from "puppeteer";
1
+ import { FetchRequestPausedEventHandler } from "./onboarding-model";
2
2
  import { Protocol } from "puppeteer-core";
3
+ import { CDPSession, Target } from "puppeteer";
3
4
  import { CliService } from "../cli";
4
- import ConfigApiService from "../config-api/config-api-service";
5
5
  import CustomerConfig from "../integration-api/struct/customer-config";
6
- import { FetchRequestPausedEventHandler } from "./onboarding-model";
6
+ import ConfigApiService from "../config-api/config-api-service";
7
7
  export declare class FetchEventHandler {
8
8
  private browserFetchEvents;
9
9
  private customerConfig;
10
10
  private cli;
11
11
  private client?;
12
12
  constructor(browserFetchEvents: FetchRequestPausedEventHandler[], customerConfig: CustomerConfig, cli: CliService, client?: ConfigApiService);
13
- getAuthPattern(): Protocol.Fetch.RequestPattern[];
14
13
  handleRequestFetchEvents(target: Target): Promise<void>;
15
- sendDefaultAuthBehaviour(browserClient: CDPSession, requestId: string): Promise<void>;
16
14
  private canHandlePattern;
17
- private onFetchAuthRequired;
18
15
  private onFetchRequestPaused;
16
+ getAuthPattern(): Protocol.Fetch.RequestPattern[];
17
+ private onFetchAuthRequired;
18
+ sendDefaultAuthBehaviour(browserClient: CDPSession, requestId: string): Promise<void>;
19
19
  }
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FetchEventHandler = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const puppeteer_core_1 = require("puppeteer-core");
6
- const safe_1 = require("../../helpers/safe");
6
+ const abort_response_1 = require("./browser/abort-response");
7
7
  const cli_1 = require("../cli");
8
8
  const login_error_1 = tslib_1.__importDefault(require("../config-api/error/login-error"));
9
- const abort_response_1 = require("./browser/abort-response");
9
+ const safe_1 = require("../../helpers/safe");
10
10
  class FetchEventHandler {
11
11
  browserFetchEvents;
12
12
  customerConfig;
@@ -18,24 +18,11 @@ class FetchEventHandler {
18
18
  this.cli = cli;
19
19
  this.client = client;
20
20
  }
21
- getAuthPattern() {
22
- const result = [];
23
- for (const origin of this.customerConfig.origins) {
24
- const pattern = [
25
- {
26
- requestStage: "Request",
27
- urlPattern: `${origin}*`,
28
- },
29
- ];
30
- result.push(...pattern);
31
- }
32
- return result;
33
- }
34
21
  async handleRequestFetchEvents(target) {
35
22
  const browserClient = await target.createCDPSession();
36
23
  await browserClient.send("Fetch.enable", {
37
24
  handleAuthRequests: true,
38
- // see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestPattern
25
+ //see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestPattern
39
26
  patterns: [
40
27
  ...this.browserFetchEvents.flatMap((handler) => {
41
28
  return handler.patterns;
@@ -64,14 +51,6 @@ class FetchEventHandler {
64
51
  this.cli.writeError(JSON.stringify(response.errorObj));
65
52
  });
66
53
  }
67
- async sendDefaultAuthBehaviour(browserClient, requestId) {
68
- await browserClient.send("Fetch.continueWithAuth", {
69
- authChallengeResponse: {
70
- response: "Default",
71
- },
72
- requestId,
73
- });
74
- }
75
54
  canHandlePattern(fetchEventHandler, url, resourceType, requestStage) {
76
55
  return fetchEventHandler.patterns.some((pattern) => {
77
56
  if (!new RegExp(pattern.urlPattern).test(url)) {
@@ -83,6 +62,48 @@ class FetchEventHandler {
83
62
  return !pattern.resourceType || pattern.resourceType === resourceType;
84
63
  });
85
64
  }
65
+ async onFetchRequestPaused(event, browserClient) {
66
+ const requestId = event.requestId;
67
+ for (const fetchEvent of this.browserFetchEvents) {
68
+ // check if current request could be handled
69
+ if (!this.canHandlePattern(fetchEvent, event.request.url, event.resourceType, event.responseHeaders ? "Response" : "Request")) {
70
+ continue;
71
+ }
72
+ const response = await fetchEvent.handle(event, browserClient);
73
+ if (!response) {
74
+ continue;
75
+ }
76
+ if (response instanceof abort_response_1.AbortResponse) {
77
+ await browserClient.send("Fetch.failRequest", {
78
+ requestId: requestId,
79
+ errorReason: response.errorReason,
80
+ });
81
+ return;
82
+ }
83
+ await browserClient.send("Fetch.fulfillRequest", {
84
+ ...response,
85
+ requestId,
86
+ });
87
+ return;
88
+ }
89
+ //see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueRequest
90
+ await browserClient.send("Fetch.continueRequest", {
91
+ requestId: requestId,
92
+ });
93
+ }
94
+ getAuthPattern() {
95
+ const result = [];
96
+ for (const origin of this.customerConfig.origins) {
97
+ const pattern = [
98
+ {
99
+ urlPattern: `${origin}*`,
100
+ requestStage: "Request",
101
+ },
102
+ ];
103
+ result.push(...pattern);
104
+ }
105
+ return result;
106
+ }
86
107
  async onFetchAuthRequired(event, browserClient) {
87
108
  this.cli.writeWarning(`auth requested for ${event.request.url}`);
88
109
  if (!this.customerConfig.origins.some((origin) => {
@@ -101,12 +122,12 @@ class FetchEventHandler {
101
122
  if (auth.uri.includes(authUrlOrigin) &&
102
123
  auth.type === event.authChallenge.scheme) {
103
124
  await browserClient.send("Fetch.continueWithAuth", {
125
+ requestId: event.requestId,
104
126
  authChallengeResponse: {
105
- password: auth.password,
106
127
  response: "ProvideCredentials",
107
128
  username: auth.user,
129
+ password: auth.password,
108
130
  },
109
- requestId: event.requestId,
110
131
  });
111
132
  this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
112
133
  this.cli.writeSuccess(`auth provided for ${event.request.url}`);
@@ -132,33 +153,12 @@ class FetchEventHandler {
132
153
  this.cli.writeError(`error providing auth: ${JSON.stringify(serverConfigResponse.errorObj)}`);
133
154
  await this.sendDefaultAuthBehaviour(browserClient, event.requestId);
134
155
  }
135
- async onFetchRequestPaused(event, browserClient) {
136
- const { request: { url: requestUrl }, requestId, resourceType, responseHeaders, } = event;
137
- for (const fetchEvent of this.browserFetchEvents) {
138
- // check if current request could be handled
139
- if (!this.canHandlePattern(fetchEvent, requestUrl, resourceType, responseHeaders ? "Response" : "Request")) {
140
- continue;
141
- }
142
- const response = await fetchEvent.handle(event, browserClient);
143
- if (!response) {
144
- continue;
145
- }
146
- if (response instanceof abort_response_1.AbortResponse) {
147
- await browserClient.send("Fetch.failRequest", {
148
- errorReason: response.errorReason,
149
- requestId,
150
- });
151
- return;
152
- }
153
- await browserClient.send("Fetch.fulfillRequest", {
154
- ...response,
155
- requestId,
156
- });
157
- return;
158
- }
159
- // see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueRequest
160
- await browserClient.send("Fetch.continueRequest", {
156
+ async sendDefaultAuthBehaviour(browserClient, requestId) {
157
+ await browserClient.send("Fetch.continueWithAuth", {
161
158
  requestId,
159
+ authChallengeResponse: {
160
+ response: "Default",
161
+ },
162
162
  });
163
163
  }
164
164
  }
@@ -1,8 +1,8 @@
1
1
  import Protocol from "devtools-protocol";
2
+ import { FetchRequestPausedEventHandler } from "../onboarding-model";
3
+ import CustomerConfig from "../../integration-api/struct/customer-config";
2
4
  import { CDPSession } from "puppeteer";
3
5
  import { ConfigFileInterface } from "../../integration-api/integration-api-model";
4
- import CustomerConfig from "../../integration-api/struct/customer-config";
5
- import { FetchRequestPausedEventHandler } from "../onboarding-model";
6
6
  /**
7
7
  * Intercepts any request to the customersOrigin and equivalent requests to baqendAssetApi
8
8
  * @implements {FetchRequestPausedEventHandler}
@@ -11,14 +11,14 @@ export declare class CustomerDomainDocumentResponse implements FetchRequestPause
11
11
  private customerConfig;
12
12
  private configDynamicBlock;
13
13
  private configDynamicStyles;
14
- constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface);
15
14
  get patterns(): Protocol.Fetch.RequestPattern[];
15
+ constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface);
16
16
  handle(event: Protocol.Fetch.RequestPausedEvent, client: CDPSession): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | void>;
17
- private getHtmlContent;
18
- private isHtmlContentHeader;
19
- private isSpeedKitResponse;
20
17
  private isValidHtmlContent;
21
18
  private isValidResponse;
22
- private rewriteHtmlToLocalConfig;
19
+ private isHtmlContentHeader;
20
+ private getHtmlContent;
21
+ private isSpeedKitResponse;
23
22
  private rewriteInstallResource;
23
+ private rewriteHtmlToLocalConfig;
24
24
  }
@@ -10,45 +10,45 @@ class CustomerDomainDocumentResponse {
10
10
  customerConfig;
11
11
  configDynamicBlock;
12
12
  configDynamicStyles;
13
- constructor(customerConfig, configDynamicBlock, configDynamicStyles) {
14
- this.customerConfig = customerConfig;
15
- this.configDynamicBlock = configDynamicBlock;
16
- this.configDynamicStyles = configDynamicStyles;
17
- }
18
13
  get patterns() {
19
14
  const result = [];
20
15
  for (const origin of this.customerConfig.origins) {
21
16
  const pattern = [
22
17
  {
23
- requestStage: "Response",
24
- resourceType: "Document",
25
18
  urlPattern: `${origin}*`,
19
+ resourceType: "Document",
20
+ requestStage: "Response",
26
21
  },
27
22
  {
28
- requestStage: "Response",
29
- resourceType: "Fetch",
30
23
  urlPattern: `${origin}*`,
24
+ resourceType: "Fetch",
25
+ requestStage: "Response",
31
26
  },
32
27
  {
33
- requestStage: "Response",
34
- resourceType: "XHR",
35
28
  urlPattern: `${origin}*`,
29
+ resourceType: "XHR",
30
+ requestStage: "Response",
36
31
  },
37
32
  {
38
- requestStage: "Response",
39
- resourceType: "Fetch",
40
33
  urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
34
+ resourceType: "Fetch",
35
+ requestStage: "Response",
41
36
  },
42
37
  {
43
- requestStage: "Response",
44
- resourceType: "XHR",
45
38
  urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
39
+ resourceType: "XHR",
40
+ requestStage: "Response",
46
41
  },
47
42
  ];
48
43
  result.push(...pattern);
49
44
  }
50
45
  return result;
51
46
  }
47
+ constructor(customerConfig, configDynamicBlock, configDynamicStyles) {
48
+ this.customerConfig = customerConfig;
49
+ this.configDynamicBlock = configDynamicBlock;
50
+ this.configDynamicStyles = configDynamicStyles;
51
+ }
52
52
  async handle(event, client) {
53
53
  if (!this.isValidResponse(event)) {
54
54
  return;
@@ -68,53 +68,53 @@ class CustomerDomainDocumentResponse {
68
68
  }
69
69
  return new origin_response_1.OriginResponse(text, event.responseHeaders, event.responseStatusCode);
70
70
  }
71
+ isValidHtmlContent(text) {
72
+ return text.includes("<html");
73
+ }
74
+ isValidResponse(event) {
75
+ return (event.responseHeaders &&
76
+ event.responseStatusCode &&
77
+ event.responseStatusCode > 199 &&
78
+ event.responseStatusCode < 300);
79
+ }
80
+ isHtmlContentHeader(responseHeaders) {
81
+ const contentType = responseHeaders.filter((headerRecord) => {
82
+ return headerRecord.name.toLowerCase() === "content-type";
83
+ })?.[0]?.["value"];
84
+ return contentType && contentType.includes("text/html");
85
+ }
71
86
  async getHtmlContent(client, event) {
72
- const contentType = event.responseHeaders.find((headerRecord) => {
87
+ const contentType = event.responseHeaders.filter((headerRecord) => {
73
88
  return headerRecord.name.toLowerCase() === "content-type";
74
- })?.value || "";
89
+ })?.[0]?.["value"] || "";
75
90
  const charset = contentType.split("charset=")?.[1];
76
- const { base64Encoded, body } = await client.send("Fetch.getResponseBody", {
91
+ const { body, base64Encoded } = await client.send("Fetch.getResponseBody", {
77
92
  requestId: event.requestId,
78
93
  });
79
94
  if (base64Encoded) {
80
95
  // todo get encodingHeader for target encoding
81
- return Buffer.from(body, "base64").toString(charset || "utf8");
96
+ return Buffer.from(body, "base64").toString(charset || "utf-8");
82
97
  }
83
98
  return body;
84
99
  }
85
- isHtmlContentHeader(responseHeaders) {
86
- const contentType = responseHeaders.find((headerRecord) => {
87
- return headerRecord.name.toLowerCase() === "content-type";
88
- })?.value;
89
- return contentType && contentType.includes("text/html");
90
- }
91
100
  isSpeedKitResponse(text) {
92
101
  return text.includes("speed-kit-dynamic");
93
102
  }
94
- isValidHtmlContent(text) {
95
- return text.includes("<html");
96
- }
97
- isValidResponse(event) {
98
- return (event.responseHeaders &&
99
- event.responseStatusCode &&
100
- event.responseStatusCode > 199 &&
101
- event.responseStatusCode < 300);
103
+ rewriteInstallResource(text) {
104
+ text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
105
+ return text.replace(/<\s*head\b[^>]*>/, (head) => {
106
+ return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
107
+ });
102
108
  }
103
109
  rewriteHtmlToLocalConfig(html) {
104
- const DF_CONFIG_PATTERN = /(<script[^>]* id="speed-kit-df-config"[^>]*>)([\S\s]*?)(<\/script>)/g;
105
- const DF_STYLES_PATTERN = /(<style[^>]* id="speed-kit-df-styles"[^>]*>)(?:(?!<\/style>)[\S\s])*(<\/style>)/g;
106
- html = html.replaceAll(DF_CONFIG_PATTERN, (_, tag, body, end) => {
110
+ const DF_CONFIG_PATTERN = /(<script[^>]* id="speed-kit-df-config"[^>]*>)([\s\S]*?)(<\/script>)/g;
111
+ const DF_STYLES_PATTERN = /(<style[^>]* id="speed-kit-df-styles"[^>]*>)(?:(?!<\/style>)[\s\S])*(<\/style>)/g;
112
+ html = html.replace(DF_CONFIG_PATTERN, (_, tag, body, end) => {
107
113
  const injectedConfig = body.match(/window\.dynamicBlockConfig\.appName\s=.*$/s) ?? [""];
108
114
  return `${tag}${this.configDynamicBlock.getContent()}${injectedConfig[0]}${end}`;
109
115
  });
110
- html = html.replaceAll(DF_STYLES_PATTERN, (_, tag, end) => `${tag}${this.configDynamicStyles.getContent()}${end}`);
116
+ html = html.replace(DF_STYLES_PATTERN, (_, tag, end) => `${tag}${this.configDynamicStyles.getContent()}${end}`);
111
117
  return html;
112
118
  }
113
- rewriteInstallResource(text) {
114
- text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
115
- return text.replace(/<\s*head\b[^>]*>/, (head) => {
116
- return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
117
- });
118
- }
119
119
  }
120
120
  exports.CustomerDomainDocumentResponse = CustomerDomainDocumentResponse;
@@ -1,6 +1,6 @@
1
1
  import Protocol from "devtools-protocol";
2
- import CustomerConfig from "../../integration-api/struct/customer-config";
3
2
  import { FetchRequestPausedEventHandler } from "../onboarding-model";
3
+ import CustomerConfig from "../../integration-api/struct/customer-config";
4
4
  /**
5
5
  * Intercepts request to /wrapper-sw.js
6
6
  *
@@ -8,7 +8,7 @@ import { FetchRequestPausedEventHandler } from "../onboarding-model";
8
8
  */
9
9
  export declare class CustomerServiceWorkerJs implements FetchRequestPausedEventHandler {
10
10
  private customerConfig;
11
- constructor(customerConfig: CustomerConfig);
12
11
  get patterns(): Protocol.Fetch.RequestPattern[];
12
+ constructor(customerConfig: CustomerConfig);
13
13
  handle(): Promise<Partial<Protocol.Fetch.FulfillRequestRequest>>;
14
14
  }
@@ -9,19 +9,19 @@ const baqend_response_1 = require("../browser/baqend-response");
9
9
  */
10
10
  class CustomerServiceWorkerJs {
11
11
  customerConfig;
12
- constructor(customerConfig) {
13
- this.customerConfig = customerConfig;
14
- }
15
12
  get patterns() {
16
13
  const result = [];
17
14
  for (const origin of this.customerConfig.origins) {
18
15
  result.push({
19
- requestStage: "Request",
20
16
  urlPattern: `${origin}${this.customerConfig.swPath}*`,
17
+ requestStage: "Request",
21
18
  });
22
19
  }
23
20
  return result;
24
21
  }
22
+ constructor(customerConfig) {
23
+ this.customerConfig = customerConfig;
24
+ }
25
25
  async handle() {
26
26
  const wrapperSwCode = `importScripts(\`https://${this.customerConfig.appDomain}/v1/speedkit/sw.js\${location.search}\`); // skonboarding`;
27
27
  return new baqend_response_1.BaqendResponse(wrapperSwCode, "text/javascript; charset=utf-8");
@@ -1,6 +1,6 @@
1
1
  import Protocol from "devtools-protocol";
2
- import { Dashboard } from "../dashboard";
3
2
  import { FetchRequestPausedEventHandler } from "../onboarding-model";
3
+ import { Dashboard } from "../dashboard";
4
4
  /**
5
5
  * The DashboardRequest class represents a request handler for the dashboard.
6
6
  * Handle all the requests on the secondTab(http://skonboarding.local)
@@ -11,12 +11,12 @@ class DashboardRequest {
11
11
  dashboard;
12
12
  patterns = [
13
13
  {
14
- requestStage: "Request",
15
14
  urlPattern: `http://skonboarding.local*`,
15
+ requestStage: "Request",
16
16
  },
17
17
  {
18
- requestStage: "Request",
19
18
  urlPattern: `https://skonboarding.local*`,
19
+ requestStage: "Request",
20
20
  },
21
21
  ];
22
22
  constructor(dashboard) {
@@ -1,10 +1,10 @@
1
1
  import Protocol from "devtools-protocol";
2
- import { CliService } from "../../cli";
3
- import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
2
+ import { FetchRequestPausedEventHandler, SpeedKitServerConfig } from "../onboarding-model";
4
3
  import CustomerConfig from "../../integration-api/struct/customer-config";
4
+ import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
5
5
  import { AbortResponse } from "../browser/abort-response";
6
- import { FetchRequestPausedEventHandler, SpeedKitServerConfig } from "../onboarding-model";
7
6
  import { Cache } from "../request-cache/cache";
7
+ import { CliService } from "../../cli";
8
8
  /**
9
9
  * Handles fetch requests for Speed Kit assets and returns customized responses.
10
10
  */
@@ -14,15 +14,15 @@ export declare class SpeedKitAssetRequest implements FetchRequestPausedEventHand
14
14
  private cache;
15
15
  private cli;
16
16
  private speedKitServerConfig?;
17
- constructor(customerConfig: CustomerConfig, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService, speedKitServerConfig?: SpeedKitServerConfig);
18
17
  get patterns(): Protocol.Fetch.RequestPattern[];
19
- handle(event: Protocol.Fetch.RequestPausedEvent): Promise<AbortResponse | Partial<Protocol.Fetch.FulfillRequestRequest>>;
18
+ constructor(customerConfig: CustomerConfig, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService, speedKitServerConfig?: SpeedKitServerConfig);
19
+ handle(event: Protocol.Fetch.RequestPausedEvent): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | AbortResponse>;
20
+ private getCachedResponse;
20
21
  private buildCustomHeaders;
21
22
  private createResponseFromLocalDocumentHandler;
22
23
  private getAssetUrl;
23
- private getCachedResponse;
24
24
  private isHtmlContentHeader;
25
25
  private isValidHtmlContent;
26
- private prepareOriginRequest;
27
26
  private rewriteInstallResource;
27
+ private prepareOriginRequest;
28
28
  }
@@ -11,32 +11,32 @@ class SpeedKitAssetRequest {
11
11
  cache;
12
12
  cli;
13
13
  speedKitServerConfig;
14
- constructor(customerConfig, documentHandler, cache, cli, speedKitServerConfig) {
15
- this.customerConfig = customerConfig;
16
- this.documentHandler = documentHandler;
17
- this.cache = cache;
18
- this.cli = cli;
19
- this.speedKitServerConfig = speedKitServerConfig;
20
- }
21
14
  get patterns() {
22
15
  const result = [];
23
16
  for (const origin of this.customerConfig.origins) {
24
17
  const pattern = [
25
18
  {
26
- requestStage: "Request",
27
- resourceType: "Fetch",
28
19
  urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
20
+ resourceType: "Fetch",
21
+ requestStage: "Request",
29
22
  },
30
23
  {
31
- requestStage: "Request",
32
- resourceType: "XHR",
33
24
  urlPattern: `https://${this.customerConfig.appDomain}/v1/asset/${origin}*`,
25
+ resourceType: "XHR",
26
+ requestStage: "Request",
34
27
  },
35
28
  ];
36
29
  result.push(...pattern);
37
30
  }
38
31
  return result;
39
32
  }
33
+ constructor(customerConfig, documentHandler, cache, cli, speedKitServerConfig) {
34
+ this.customerConfig = customerConfig;
35
+ this.documentHandler = documentHandler;
36
+ this.cache = cache;
37
+ this.cli = cli;
38
+ this.speedKitServerConfig = speedKitServerConfig;
39
+ }
40
40
  async handle(event) {
41
41
  const originUrl = this.getAssetUrl(event.request.url);
42
42
  const UrlObject = new URL(event.request.url);
@@ -80,6 +80,16 @@ class SpeedKitAssetRequest {
80
80
  return new baqend_response_1.BaqendResponse(message, null, customHeaders, 500);
81
81
  }
82
82
  }
83
+ getCachedResponse(requestUrl) {
84
+ const response = this.cache.getEntry(requestUrl);
85
+ if (!(response instanceof baqend_response_1.BaqendResponse)) {
86
+ return;
87
+ }
88
+ response.setHeader("x-cache", "POP, HIT");
89
+ response.setHeader("x-served-by", "cache-local");
90
+ response.setHeader("server-timing", "pop;desc=LOCAL;dur=1,cache;desc=CACHE,hotness;desc=1,proto;desc=h3");
91
+ return response;
92
+ }
83
93
  buildCustomHeaders(originUrl) {
84
94
  const time = new Date().toUTCString();
85
95
  const originDomain = new URL(originUrl).origin;
@@ -130,16 +140,6 @@ class SpeedKitAssetRequest {
130
140
  const cleanedUrl = url.toString();
131
141
  return cleanedUrl.split("app.baqend.com/v1/asset/")[1];
132
142
  }
133
- getCachedResponse(requestUrl) {
134
- const response = this.cache.getEntry(requestUrl);
135
- if (!(response instanceof baqend_response_1.BaqendResponse)) {
136
- return;
137
- }
138
- response.setHeader("x-cache", "POP, HIT");
139
- response.setHeader("x-served-by", "cache-local");
140
- response.setHeader("server-timing", "pop;desc=LOCAL;dur=1,cache;desc=CACHE,hotness;desc=1,proto;desc=h3");
141
- return response;
142
- }
143
143
  isHtmlContentHeader(responseHeaders) {
144
144
  return (responseHeaders.has("content-type") &&
145
145
  responseHeaders.get("content-type").includes("text/html"));
@@ -147,6 +147,12 @@ class SpeedKitAssetRequest {
147
147
  isValidHtmlContent(text) {
148
148
  return text.includes("<html");
149
149
  }
150
+ rewriteInstallResource(text) {
151
+ text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
152
+ return text.replace(/<\s*head\b[^>]*>/, (head) => {
153
+ return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
154
+ });
155
+ }
150
156
  prepareOriginRequest(variationParam, init) {
151
157
  if (!this.speedKitServerConfig || !variationParam) {
152
158
  return init;
@@ -159,11 +165,5 @@ class SpeedKitAssetRequest {
159
165
  init.headers = { ...init.headers, ...variationConfig.headers };
160
166
  return init;
161
167
  }
162
- rewriteInstallResource(text) {
163
- text = text.replace(/<script(?:.(?!<\/script>))*app\.baqend\.com\/v1\/speedkit\/install.js(?:.|(?!<\/script>))*<\/script>/, "");
164
- return text.replace(/<\s*head\b[^>]*>/, (head) => {
165
- return `${head}\n<script src="${this.customerConfig.installPath}" ${this.customerConfig.installParams}></script>`;
166
- });
167
- }
168
168
  }
169
169
  exports.SpeedKitAssetRequest = SpeedKitAssetRequest;
@@ -1,6 +1,6 @@
1
1
  import Protocol from "devtools-protocol";
2
- import CustomerConfig from "../../integration-api/struct/customer-config";
3
2
  import { BrowserContext, FetchRequestPausedEventHandler } from "../onboarding-model";
3
+ import CustomerConfig from "../../integration-api/struct/customer-config";
4
4
  import { InstallSpeedKitHtmlTemplate } from "../templates/install-speed-kit-html-template";
5
5
  /**
6
6
  * Represents a class that handles the installation of Speed Kit HTML.
@@ -9,7 +9,7 @@ export declare class SpeedKitInstallHtml implements FetchRequestPausedEventHandl
9
9
  private customerConfig;
10
10
  private browserContext;
11
11
  private speedKitInstallHtmlTemplate;
12
- constructor(customerConfig: CustomerConfig, browserContext: BrowserContext, speedKitInstallHtmlTemplate: InstallSpeedKitHtmlTemplate);
13
12
  get patterns(): Protocol.Fetch.RequestPattern[];
13
+ constructor(customerConfig: CustomerConfig, browserContext: BrowserContext, speedKitInstallHtmlTemplate: InstallSpeedKitHtmlTemplate);
14
14
  handle(): Promise<Partial<Protocol.Fetch.FulfillRequestRequest>>;
15
15
  }