@speedkit/cli 2.10.0 → 2.11.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +39 -58
  3. package/dist/commands/build-parameter-query.d.ts +4 -4
  4. package/dist/commands/build-parameter-query.js +38 -38
  5. package/dist/commands/build-prewarm-query.d.ts +4 -4
  6. package/dist/commands/build-prewarm-query.js +33 -34
  7. package/dist/commands/deploy.d.ts +4 -4
  8. package/dist/commands/deploy.js +14 -15
  9. package/dist/helpers/cli-config.d.ts +8 -7
  10. package/dist/helpers/cli-config.js +50 -44
  11. package/dist/services/cli/cli-service.d.ts +1 -1
  12. package/dist/services/deploy/context/deploy-context.d.ts +1 -4
  13. package/dist/services/deploy/context/deploy-context.js +6 -7
  14. package/dist/services/deploy/deploy-service-factory.d.ts +4 -5
  15. package/dist/services/deploy/deploy-service-factory.js +19 -18
  16. package/dist/services/integration-api/handler/customer-config-handler.d.ts +3 -3
  17. package/dist/services/integration-api/handler/customer-config-handler.js +20 -14
  18. package/dist/services/integration-api/struct/customer-config-file.d.ts +4 -3
  19. package/dist/services/integration-api/struct/customer-config-file.js +7 -5
  20. package/dist/services/onboarding/browser/abort-response.js +1 -1
  21. package/dist/services/onboarding/browser/baqend-response.d.ts +4 -4
  22. package/dist/services/onboarding/browser/baqend-response.js +33 -25
  23. package/dist/services/onboarding/browser/origin-response.d.ts +1 -1
  24. package/dist/services/onboarding/browser/origin-response.js +2 -3
  25. package/dist/services/onboarding/config-renderer/speed-kit-install-context.d.ts +4 -4
  26. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +44 -32
  27. package/dist/services/onboarding/dashboard/athena-service.d.ts +2 -2
  28. package/dist/services/onboarding/dashboard/athena-service.js +28 -23
  29. package/dist/services/onboarding/dashboard/index.d.ts +3 -3
  30. package/dist/services/onboarding/dashboard/index.js +48 -36
  31. package/dist/services/onboarding/dashboard/param-query-builder.d.ts +2 -2
  32. package/dist/services/onboarding/dashboard/param-query-builder.js +2 -2
  33. package/dist/services/onboarding/dashboard/request-diff-service.d.ts +1 -1
  34. package/dist/services/onboarding/dashboard/request-diff-service.js +32 -28
  35. package/dist/services/onboarding/fetch-event-handler.d.ts +6 -6
  36. package/dist/services/onboarding/fetch-event-handler.js +72 -62
  37. package/dist/services/onboarding/fetch-events/customer-domain-document-response.d.ts +8 -8
  38. package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +51 -49
  39. package/dist/services/onboarding/fetch-events/customer-service-worker-js.d.ts +3 -3
  40. package/dist/services/onboarding/fetch-events/customer-service-worker-js.js +6 -6
  41. package/dist/services/onboarding/fetch-events/dashboard-request.d.ts +2 -2
  42. package/dist/services/onboarding/fetch-events/dashboard-request.js +3 -3
  43. package/dist/services/onboarding/fetch-events/speed-kit-asset-request.d.ts +7 -7
  44. package/dist/services/onboarding/fetch-events/speed-kit-asset-request.js +76 -59
  45. package/dist/services/onboarding/fetch-events/speed-kit-install-html.d.ts +3 -3
  46. package/dist/services/onboarding/fetch-events/speed-kit-install-html.js +14 -14
  47. package/dist/services/onboarding/fetch-events/speed-kit-install-js.d.ts +6 -6
  48. package/dist/services/onboarding/fetch-events/speed-kit-install-js.js +12 -10
  49. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.d.ts +7 -7
  50. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.js +3 -3
  51. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +4 -4
  52. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +6 -4
  53. package/dist/services/onboarding/file-events/{fileWatcher.d.ts → file-watcher.d.ts} +9 -8
  54. package/dist/services/onboarding/file-events/{fileWatcher.js → file-watcher.js} +74 -56
  55. package/dist/services/onboarding/index.d.ts +3 -3
  56. package/dist/services/onboarding/onboarding-model.d.ts +36 -34
  57. package/dist/services/onboarding/onboarding-model.js +19 -19
  58. package/dist/services/onboarding/onboarding-service-factory.d.ts +6 -6
  59. package/dist/services/onboarding/onboarding-service-factory.js +80 -75
  60. package/dist/services/onboarding/onboarding-service.d.ts +7 -7
  61. package/dist/services/onboarding/onboarding-service.js +54 -48
  62. package/dist/services/onboarding/request-cache/cache.d.ts +3 -3
  63. package/dist/services/onboarding/request-cache/cache.js +7 -7
  64. package/dist/services/onboarding/server-config/index.js +2 -2
  65. package/dist/services/onboarding/todo-collector.d.ts +1 -1
  66. package/dist/services/onboarding/todo-collector.js +8 -6
  67. package/oclif.manifest.json +9 -9
  68. package/package.json +4 -3
@@ -1,10 +1,10 @@
1
- import { BaqendResponse } from "../browser/baqend-response";
2
1
  import { Protocol } from "devtools-protocol";
3
- import { ParamQueryBuilder } from "./param-query-builder";
4
2
  import CustomerConfig from "../../integration-api/struct/customer-config";
3
+ import { BaqendResponse } from "../browser/baqend-response";
4
+ import { Cache } from "../request-cache/cache";
5
5
  import { AthenaService } from "./athena-service";
6
+ import { ParamQueryBuilder } from "./param-query-builder";
6
7
  import { RequestDiffService } from "./request-diff-service";
7
- import { Cache } from "../request-cache/cache";
8
8
  export declare class Dashboard {
9
9
  private customerConfig;
10
10
  private paramQueryBuilder;
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Dashboard = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const baqend_response_1 = require("../browser/baqend-response");
6
- const fs_1 = require("fs");
7
- const path_1 = tslib_1.__importDefault(require("path"));
8
- const safe_1 = require("../../../helpers/safe");
9
5
  const json2csv_1 = tslib_1.__importDefault(require("json2csv"));
6
+ const node_fs_1 = require("node:fs");
7
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
8
+ const safe_1 = require("../../../helpers/safe");
9
+ const baqend_response_1 = require("../browser/baqend-response");
10
10
  class Dashboard {
11
11
  customerConfig;
12
12
  paramQueryBuilder;
@@ -22,57 +22,69 @@ class Dashboard {
22
22
  }
23
23
  async getResponse(request) {
24
24
  const url = new URL(request.url);
25
- if (url.pathname === '/') {
26
- const filePath = path_1.default.join(__dirname, './frontend-dist', 'index.html');
27
- const content = (0, fs_1.readFileSync)(filePath, { encoding: 'utf-8' });
25
+ if (url.pathname === "/") {
26
+ const filePath = node_path_1.default.join(__dirname, "./frontend-dist", "index.html");
27
+ const content = (0, node_fs_1.readFileSync)(filePath, { encoding: "utf8" });
28
28
  return new baqend_response_1.BaqendResponse(content);
29
29
  }
30
- if (url.pathname.startsWith('/assets/')) {
31
- const filePath = path_1.default.join(__dirname, './frontend-dist', url.pathname);
32
- const content = (0, fs_1.readFileSync)(filePath, { encoding: 'utf-8' });
33
- let contentType = 'application/javascript; charset=UTF-8';
34
- if (url.pathname.includes('.css')) {
35
- contentType = 'text/css';
30
+ if (url.pathname.startsWith("/assets/")) {
31
+ const filePath = node_path_1.default.join(__dirname, "./frontend-dist", url.pathname);
32
+ const content = (0, node_fs_1.readFileSync)(filePath, { encoding: "utf8" });
33
+ let contentType = "application/javascript; charset=UTF-8";
34
+ if (url.pathname.includes(".css")) {
35
+ contentType = "text/css";
36
36
  }
37
37
  return new baqend_response_1.BaqendResponse(content, contentType);
38
38
  }
39
- if (url.pathname.startsWith('/query/create')) {
40
- return new baqend_response_1.BaqendResponse(JSON.stringify({ query: this.paramQueryBuilder.getQuery() }), 'application/json; charset=UTF-8');
39
+ if (url.pathname.startsWith("/query/create")) {
40
+ return new baqend_response_1.BaqendResponse(JSON.stringify({ query: this.paramQueryBuilder.getQuery() }), "application/json; charset=UTF-8");
41
41
  }
42
- if (url.pathname.startsWith('/query/execute')) {
43
- const postData = request.postData;
42
+ if (url.pathname.startsWith("/query/execute")) {
43
+ const { postData } = request;
44
44
  const data = JSON.parse(postData);
45
45
  const response = await (0, safe_1.safe)(this.athenaClient.executeQuery(data.query));
46
46
  if (response.success === true) {
47
- return new baqend_response_1.BaqendResponse(JSON.stringify(response.data), 'application/json; charset=UTF-8');
47
+ return new baqend_response_1.BaqendResponse(JSON.stringify(response.data), "application/json; charset=UTF-8");
48
48
  }
49
- return new baqend_response_1.BaqendResponse(response.error, null, [{ name: 'x-error', value: response.error }], 500);
49
+ return new baqend_response_1.BaqendResponse(response.error, null, [{ name: "x-error", value: response.error }], 500);
50
50
  }
51
- if (url.pathname.startsWith('/query/download')) {
51
+ if (url.pathname.startsWith("/query/download")) {
52
52
  const result = this.athenaClient.getLastQueryResult();
53
53
  result.shift();
54
- const csv = json2csv_1.default.parse(result, { fields: ['params', 'potentialGain', 'cachedUrls', 'PIs', 'example1', 'example2', 'example3'] });
55
- return new baqend_response_1.BaqendResponse(csv, 'application/csv', [{
56
- name: 'Content-disposition',
57
- value: `attachment; filename=parameter-${this.customerConfig.app}.csv`
58
- }]);
54
+ const csv = json2csv_1.default.parse(result, {
55
+ fields: [
56
+ "params",
57
+ "potentialGain",
58
+ "cachedUrls",
59
+ "PIs",
60
+ "example1",
61
+ "example2",
62
+ "example3",
63
+ ],
64
+ });
65
+ return new baqend_response_1.BaqendResponse(csv, "application/csv", [
66
+ {
67
+ name: "Content-disposition",
68
+ value: `attachment; filename=parameter-${this.customerConfig.app}.csv`,
69
+ },
70
+ ]);
59
71
  }
60
- if (url.pathname.startsWith('/api/config')) {
61
- return new baqend_response_1.BaqendResponse(JSON.stringify(this.customerConfig), 'application/json; charset=UTF-8');
72
+ if (url.pathname.startsWith("/api/config")) {
73
+ return new baqend_response_1.BaqendResponse(JSON.stringify(this.customerConfig), "application/json; charset=UTF-8");
62
74
  }
63
- if (url.pathname.startsWith('/diff')) {
64
- const postData = request.postData;
75
+ if (url.pathname.startsWith("/diff")) {
76
+ const { postData } = request;
65
77
  const data = JSON.parse(postData);
66
- return await this.requestDiffService.postDiff(data.url, data.params);
78
+ return this.requestDiffService.postDiff(data.url, data.params);
67
79
  }
68
- if (url.pathname.startsWith('/cache/get')) {
80
+ if (url.pathname.startsWith("/cache/get")) {
69
81
  const response = [];
70
- Array.from(this.cache.getAll()).forEach(([url, baqendResponse]) => {
71
- response.push({ url, response: baqendResponse });
72
- });
73
- return new baqend_response_1.BaqendResponse(JSON.stringify(response), 'application/json; charset=UTF-8');
82
+ for (const [url, baqendResponse] of this.cache.getAll()) {
83
+ response.push({ response: baqendResponse, url });
84
+ }
85
+ return new baqend_response_1.BaqendResponse(JSON.stringify(response), "application/json; charset=UTF-8");
74
86
  }
75
- return new baqend_response_1.BaqendResponse('Not implemented');
87
+ return new baqend_response_1.BaqendResponse("Not implemented");
76
88
  }
77
89
  }
78
90
  exports.Dashboard = Dashboard;
@@ -1,5 +1,5 @@
1
- import { ConfigFileInterface } from '../../integration-api/integration-api-model';
2
- import CustomerConfig from '../../integration-api/struct/customer-config';
1
+ import { ConfigFileInterface } from "../../integration-api/integration-api-model";
2
+ import CustomerConfig from "../../integration-api/struct/customer-config";
3
3
  export declare class ParamQueryBuilder {
4
4
  private customerConfig;
5
5
  private speedKitConfigFile;
@@ -12,8 +12,8 @@ class ParamQueryBuilder {
12
12
  }
13
13
  buildParameterQuery(app, parameterFilter, whitelistedFilter, blacklistedFilter, parameterReplaceFilter) {
14
14
  const nowMinusOneMonth = new Date(new Date().setMonth(new Date().getMonth() - 1, new Date().getDate()));
15
- const monthString = `${nowMinusOneMonth.getMonth() + 1 < 10 ? '0' : ''}${nowMinusOneMonth.getMonth() + 1}`;
16
- const dateString = `${nowMinusOneMonth.getDate() < 10 ? '0' : ''}${nowMinusOneMonth.getDate()}`;
15
+ const monthString = `${nowMinusOneMonth.getMonth() + 1 < 10 ? "0" : ""}${nowMinusOneMonth.getMonth() + 1}`;
16
+ const dateString = `${nowMinusOneMonth.getDate() < 10 ? "0" : ""}${nowMinusOneMonth.getDate()}`;
17
17
  const date = `${nowMinusOneMonth.getFullYear()}-${monthString}-${dateString}`;
18
18
  return `
19
19
  with urlWithParams as (
@@ -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;
7
8
  private diffLocal;
8
9
  private doOriginVsContentDiff;
9
10
  private fetchHtml;
10
- private createUrlsForDiff;
11
11
  }
@@ -1,59 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RequestDiffService = void 0;
4
- const baqend_response_1 = require("../browser/baqend-response");
5
4
  const safe_1 = require("../../../helpers/safe");
5
+ const baqend_response_1 = require("../browser/baqend-response");
6
6
  class RequestDiffService {
7
7
  diffService;
8
8
  constructor(diffService) {
9
9
  this.diffService = diffService;
10
10
  }
11
11
  async postDiff(url, parametersString) {
12
- const params = parametersString.replace('[', '').replace(']', '').split((',')).map(param => {
12
+ const params = parametersString
13
+ .replace("[", "")
14
+ .replace("]", "")
15
+ .split(",")
16
+ .map((param) => {
13
17
  return param.trim();
14
18
  });
15
19
  const { urlWithParam, urlWithoutParam } = this.createUrlsForDiff(url, params);
16
20
  const result = await (0, safe_1.safe)(this.diffLocal(urlWithParam, urlWithoutParam));
17
21
  if (result.success === true) {
18
- return new baqend_response_1.BaqendResponse(JSON.stringify({ status: 'success', isIdentical: result.data }), 'application/json; charset=UTF-8');
22
+ return new baqend_response_1.BaqendResponse(JSON.stringify({ isIdentical: result.data, status: "success" }), "application/json; charset=UTF-8");
19
23
  }
20
- return new baqend_response_1.BaqendResponse(JSON.stringify({ status: 'error', error: result.error }), 'application/json; charset=UTF-8', null, 500);
21
- }
22
- async diffLocal(urlWithParam, urlWithoutParam) {
23
- const htmlWithParam = await this.fetchHtml(urlWithParam);
24
- const htmlWithoutParam = await this.fetchHtml(urlWithoutParam);
25
- const paramsFilePath = await this.diffService.writeContentToTemporalFile('params', htmlWithParam);
26
- const pureFilePath = await this.diffService.writeContentToTemporalFile('pure', htmlWithoutParam);
27
- return await this.diffService.executeDiff(paramsFilePath, pureFilePath);
28
- }
29
- async doOriginVsContentDiff(url, content) {
30
- const html = await this.fetchHtml(url);
31
- const origin = await this.diffService.writeContentToTemporalFile('origin', html);
32
- const local = await this.diffService.writeContentToTemporalFile('content', content);
33
- return await this.diffService.executeDiff(local, origin);
34
- }
35
- async fetchHtml(url) {
36
- const response = await fetch(url);
37
- return await response.text();
24
+ return new baqend_response_1.BaqendResponse(JSON.stringify({ error: result.error, status: "error" }), "application/json; charset=UTF-8", null, 500);
38
25
  }
39
26
  createUrlsForDiff(urlWithParam, params) {
40
27
  const url = new URL(urlWithParam);
41
- const search_params = url.searchParams;
28
+ const { searchParams } = url;
42
29
  for (const param of params) {
43
- search_params.delete(param);
30
+ searchParams.delete(param);
44
31
  }
45
- url.search = search_params.toString();
32
+ url.search = searchParams.toString();
46
33
  const urlWithoutParam = url.toString();
47
- console.log('With-----');
34
+ console.log("With-----");
48
35
  console.log(urlWithParam);
49
- console.log('Without-----');
36
+ console.log("Without-----");
50
37
  console.log(urlWithoutParam);
51
- console.log('-----');
38
+ console.log("-----");
52
39
  // TODO: Insert the content
53
40
  return {
54
41
  urlWithParam,
55
- urlWithoutParam
42
+ urlWithoutParam,
56
43
  };
57
44
  }
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
+ }
58
62
  }
59
63
  exports.RequestDiffService = RequestDiffService;
@@ -1,19 +1,19 @@
1
- import { FetchRequestPausedEventHandler } from "./onboarding-model";
2
- import { Protocol } from "puppeteer-core";
3
1
  import { CDPSession, Target } from "puppeteer";
2
+ import { Protocol } from "puppeteer-core";
4
3
  import { CliService } from "../cli";
5
- import CustomerConfig from "../integration-api/struct/customer-config";
6
4
  import ConfigApiService from "../config-api/config-api-service";
5
+ import CustomerConfig from "../integration-api/struct/customer-config";
6
+ import { FetchRequestPausedEventHandler } from "./onboarding-model";
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[];
13
14
  handleRequestFetchEvents(target: Target): Promise<void>;
15
+ sendDefaultAuthBehaviour(browserClient: CDPSession, requestId: string): Promise<void>;
14
16
  private canHandlePattern;
15
- private onFetchRequestPaused;
16
- getAuthPattern(): Protocol.Fetch.RequestPattern[];
17
17
  private onFetchAuthRequired;
18
- sendDefaultAuthBehaviour(browserClient: CDPSession, requestId: string): Promise<void>;
18
+ private onFetchRequestPaused;
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 abort_response_1 = require("./browser/abort-response");
6
+ const safe_1 = require("../../helpers/safe");
7
7
  const cli_1 = require("../cli");
8
8
  const login_error_1 = tslib_1.__importDefault(require("../config-api/error/login-error"));
9
- const safe_1 = require("../../helpers/safe");
9
+ const abort_response_1 = require("./browser/abort-response");
10
10
  class FetchEventHandler {
11
11
  browserFetchEvents;
12
12
  customerConfig;
@@ -18,23 +18,39 @@ 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
+ }
21
34
  async handleRequestFetchEvents(target) {
22
35
  const browserClient = await target.createCDPSession();
23
- await browserClient.send('Fetch.enable', {
36
+ await browserClient.send("Fetch.enable", {
24
37
  handleAuthRequests: true,
25
- //see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestPattern
26
- patterns: this.browserFetchEvents.flatMap(handler => {
27
- return handler.patterns;
28
- }).concat(this.getAuthPattern()),
38
+ // see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#type-RequestPattern
39
+ patterns: [
40
+ ...this.browserFetchEvents.flatMap((handler) => {
41
+ return handler.patterns;
42
+ }),
43
+ ...this.getAuthPattern(),
44
+ ],
29
45
  });
30
- browserClient.on('Fetch.authRequired', async (event) => {
46
+ browserClient.on("Fetch.authRequired", async (event) => {
31
47
  const response = await (0, safe_1.safe)(this.onFetchAuthRequired(event, browserClient));
32
48
  if (response.success === true) {
33
49
  return response.data;
34
50
  }
35
51
  this.cli.writeError(response.error);
36
52
  });
37
- browserClient.on('Fetch.requestPaused', async (event) => {
53
+ browserClient.on("Fetch.requestPaused", async (event) => {
38
54
  const response = await (0, safe_1.safe)(this.onFetchRequestPaused(event, browserClient));
39
55
  if (response.success === true) {
40
56
  return;
@@ -48,9 +64,17 @@ class FetchEventHandler {
48
64
  this.cli.writeError(JSON.stringify(response.errorObj));
49
65
  });
50
66
  }
67
+ async sendDefaultAuthBehaviour(browserClient, requestId) {
68
+ await browserClient.send("Fetch.continueWithAuth", {
69
+ authChallengeResponse: {
70
+ response: "Default",
71
+ },
72
+ requestId,
73
+ });
74
+ }
51
75
  canHandlePattern(fetchEventHandler, url, resourceType, requestStage) {
52
- return fetchEventHandler.patterns.some(pattern => {
53
- if (!(new RegExp(pattern.urlPattern).test(url))) {
76
+ return fetchEventHandler.patterns.some((pattern) => {
77
+ if (!new RegExp(pattern.urlPattern).test(url)) {
54
78
  return false;
55
79
  }
56
80
  if (pattern.requestStage !== requestStage) {
@@ -59,65 +83,30 @@ class FetchEventHandler {
59
83
  return !pattern.resourceType || pattern.resourceType === resourceType;
60
84
  });
61
85
  }
62
- async onFetchRequestPaused(event, browserClient) {
63
- const requestId = event.requestId;
64
- for (const fetchEvent of this.browserFetchEvents) {
65
- // check if current request could be handled
66
- if (!this.canHandlePattern(fetchEvent, event.request.url, event.resourceType, event.responseHeaders ? 'Response' : 'Request')) {
67
- continue;
68
- }
69
- const response = await fetchEvent.handle(event, browserClient);
70
- if (!response) {
71
- continue;
72
- }
73
- if (response instanceof abort_response_1.AbortResponse) {
74
- await browserClient.send('Fetch.failRequest', { requestId: requestId, errorReason: response.errorReason });
75
- return;
76
- }
77
- await browserClient.send('Fetch.fulfillRequest', {
78
- ...response,
79
- requestId,
80
- });
81
- return;
82
- }
83
- //see: https://chromedevtools.github.io/devtools-protocol/tot/Fetch#method-continueRequest
84
- await browserClient.send('Fetch.continueRequest', {
85
- requestId: requestId,
86
- });
87
- }
88
- getAuthPattern() {
89
- let result = [];
90
- for (const origin of this.customerConfig.origins) {
91
- const pattern = [
92
- {
93
- urlPattern: `${origin}*`,
94
- requestStage: "Request"
95
- }
96
- ];
97
- result.push(...pattern);
98
- }
99
- return result;
100
- }
101
86
  async onFetchAuthRequired(event, browserClient) {
102
87
  this.cli.writeWarning(`auth requested for ${event.request.url}`);
103
- if (!this.customerConfig.origins.some((origin) => { return event.request.url.includes(origin); }) || !this.client) {
88
+ if (!this.customerConfig.origins.some((origin) => {
89
+ return event.request.url.includes(origin);
90
+ }) ||
91
+ !this.client) {
104
92
  this.cli.writeWarning(`incorrect origin for auth request: -> ${this.customerConfig.origins.join("|")}`);
105
93
  return { response: "Default" };
106
94
  }
107
- this.cli.startAction('wait for credentials from server-config');
95
+ this.cli.startAction("wait for credentials from server-config");
108
96
  const serverConfigResponse = await (0, safe_1.safe)(this.client.getServerConfig());
109
97
  if (serverConfigResponse.success === true) {
110
98
  const config = JSON.parse(serverConfigResponse.data);
111
99
  const authUrlOrigin = new URL(event.request.url).origin;
112
100
  for (const auth of config.speedKit.authentications) {
113
- if (auth.uri.includes(authUrlOrigin) && auth.type === event.authChallenge.scheme) {
114
- await browserClient.send('Fetch.continueWithAuth', {
115
- requestId: event.requestId,
101
+ if (auth.uri.includes(authUrlOrigin) &&
102
+ auth.type === event.authChallenge.scheme) {
103
+ await browserClient.send("Fetch.continueWithAuth", {
116
104
  authChallengeResponse: {
105
+ password: auth.password,
117
106
  response: "ProvideCredentials",
118
107
  username: auth.user,
119
- password: auth.password
120
- }
108
+ },
109
+ requestId: event.requestId,
121
110
  });
122
111
  this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
123
112
  this.cli.writeSuccess(`auth provided for ${event.request.url}`);
@@ -143,12 +132,33 @@ class FetchEventHandler {
143
132
  this.cli.writeError(`error providing auth: ${JSON.stringify(serverConfigResponse.errorObj)}`);
144
133
  await this.sendDefaultAuthBehaviour(browserClient, event.requestId);
145
134
  }
146
- async sendDefaultAuthBehaviour(browserClient, requestId) {
147
- await browserClient.send('Fetch.continueWithAuth', {
148
- requestId,
149
- authChallengeResponse: {
150
- response: "Default"
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;
151
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", {
161
+ requestId,
152
162
  });
153
163
  }
154
164
  }
@@ -1,8 +1,8 @@
1
- import Protocol from 'devtools-protocol';
2
- import { FetchRequestPausedEventHandler } from "../onboarding-model";
3
- import CustomerConfig from "../../integration-api/struct/customer-config";
1
+ import Protocol from "devtools-protocol";
4
2
  import { CDPSession } from "puppeteer";
5
3
  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
- get patterns(): Protocol.Fetch.RequestPattern[];
15
14
  constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface);
15
+ get patterns(): Protocol.Fetch.RequestPattern[];
16
16
  handle(event: Protocol.Fetch.RequestPausedEvent, client: CDPSession): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | void>;
17
- private isValidHtmlContent;
18
- private isValidResponse;
19
- private isHtmlContentHeader;
20
17
  private getHtmlContent;
18
+ private isHtmlContentHeader;
21
19
  private isSpeedKitResponse;
22
- private rewriteInstallResource;
20
+ private isValidHtmlContent;
21
+ private isValidResponse;
23
22
  private rewriteHtmlToLocalConfig;
23
+ private rewriteInstallResource;
24
24
  }