@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
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
3
4
  const core_1 = require("@oclif/core");
4
5
  const core_2 = require("@oclif/core");
6
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
5
7
  const cli_parameters_1 = require("../models/cli-parameters");
6
8
  const logging_helper_1 = require("../helpers/logging-helper");
7
- const fetch = require('node-fetch');
8
9
  class WptLauncher extends core_1.Command {
9
- static description = 'Analyze the performance impact that Speed Kit has compared to the original version.';
10
+ static description = "Analyze the performance impact that Speed Kit has compared to the original version.";
10
11
  static args = {
11
12
  [cli_parameters_1.CLIParameters.Urls]: core_1.Args.string({
12
13
  name: cli_parameters_1.CLIParameters.Urls, // name of arg to show in help and reference with args[name]
@@ -18,17 +19,26 @@ class WptLauncher extends core_1.Command {
18
19
  }),
19
20
  };
20
21
  static flags = {
21
- [cli_parameters_1.CLIParameters.Cookies]: core_1.Flags.string({ default: '', char: cli_parameters_1.CLIParametersChar.Cookies }),
22
- [cli_parameters_1.CLIParameters.Mobile]: core_1.Flags.string({ default: 'no', char: cli_parameters_1.CLIParametersChar.Mobile }),
23
- [cli_parameters_1.CLIParameters.Group]: core_1.Flags.string({ default: 'A', char: cli_parameters_1.CLIParametersChar.Group }),
22
+ [cli_parameters_1.CLIParameters.Cookies]: core_1.Flags.string({
23
+ default: "",
24
+ char: cli_parameters_1.CLIParametersChar.Cookies,
25
+ }),
26
+ [cli_parameters_1.CLIParameters.Mobile]: core_1.Flags.string({
27
+ default: "no",
28
+ char: cli_parameters_1.CLIParametersChar.Mobile,
29
+ }),
30
+ [cli_parameters_1.CLIParameters.Group]: core_1.Flags.string({
31
+ default: "A",
32
+ char: cli_parameters_1.CLIParametersChar.Group,
33
+ }),
24
34
  };
25
35
  static examples = [
26
36
  `$ sk wpt-launcher <${cli_parameters_1.CLIParameters.Urls}> <${cli_parameters_1.CLIParameters.TestId}> -${cli_parameters_1.CLIParametersChar.Group} <${cli_parameters_1.CLIParameters.Group}> -${cli_parameters_1.CLIParametersChar.Mobile} <${cli_parameters_1.CLIParameters.Mobile}> -${cli_parameters_1.CLIParametersChar.Cookies} <${cli_parameters_1.CLIParameters.Cookies}>`,
27
37
  `$ sk wpt-launcher ${cli_parameters_1.CLIParametersExample.Urls} ${cli_parameters_1.CLIParametersExample.TestId} -${cli_parameters_1.CLIParametersChar.Group} ${cli_parameters_1.CLIParametersExample.Group} -${cli_parameters_1.CLIParametersChar.Mobile} ${cli_parameters_1.CLIParametersExample.Mobile} -${cli_parameters_1.CLIParametersChar.Cookies} ${cli_parameters_1.CLIParametersExample.Cookies}`,
28
38
  ];
29
- static localhostUrl = 'http://localhost:8888/orange.html';
39
+ static localhostUrl = "http://localhost:8888/orange.html";
30
40
  async run() {
31
- const { args: { urls, testId }, flags: { group, mobile, cookies } } = await this.parse(WptLauncher);
41
+ const { args: { urls, testId }, flags: { group, mobile, cookies }, } = await this.parse(WptLauncher);
32
42
  const resourceOrigin = this.getResourceOrigin(this.allResourceUrls(urls));
33
43
  let script = `setViewportSize ${this.getViewPortSize(this.isMobile(mobile))}
34
44
  navigate ${resourceOrigin}/wrapper-sw.js
@@ -36,43 +46,49 @@ class WptLauncher extends core_1.Command {
36
46
  exec localStorage.setItem('baqend-speedkit-ab-test-info', encodeURIComponent(JSON.stringify({group:${group},testId:${testId})));
37
47
  navigate ${resourceOrigin}
38
48
  navigate ${WptLauncher.localhostUrl}`;
39
- this.allResourceUrls(urls).forEach(url => {
49
+ this.allResourceUrls(urls).forEach((url) => {
40
50
  script += `\n navigate ${url}`;
41
51
  });
42
- const postscript = await this.postScript(script);
52
+ const postscript = (await this.postScript(script));
43
53
  const currentTestIdUrl = `http://wpt.baqend.com/results.php?test=${postscript.wptTestId}`;
44
54
  if (!currentTestIdUrl) {
45
- (0, logging_helper_1.logError)('Getting testId failed, ' + currentTestIdUrl);
55
+ (0, logging_helper_1.logError)("Getting testId failed, " + currentTestIdUrl);
46
56
  core_2.ux.exit(1);
47
57
  }
48
- this.log('testUrl: ', currentTestIdUrl);
58
+ this.log("testUrl: ", currentTestIdUrl);
49
59
  core_2.ux.exit(0);
50
60
  }
51
61
  // ---------------------- services----------------
52
62
  isMobile(mobile) {
53
- return mobile === 'y' || mobile === 'Y' || mobile === 'yes' || mobile === 'Yes' || mobile === 'YES';
63
+ return (mobile === "y" ||
64
+ mobile === "Y" ||
65
+ mobile === "yes" ||
66
+ mobile === "Yes" ||
67
+ mobile === "YES");
54
68
  }
55
69
  getViewPortSize(isMobile) {
56
70
  if (isMobile) {
57
- return '375 667'; // mobile
71
+ return "375 667"; // mobile
58
72
  }
59
- return '1500 1300'; // desktop
73
+ return "1500 1300"; // desktop
60
74
  }
61
75
  allResourceUrls(urls) {
62
- const urlsArr = urls.split(',');
76
+ const urlsArr = urls.split(",");
63
77
  if (urlsArr.length > 0) {
64
78
  return urlsArr;
65
79
  }
66
- // eslint-disable-next-line unicorn/error-message
67
- throw new Error('urls must not be null');
80
+ throw new Error("urls must not be null");
68
81
  }
69
82
  getResourceOrigin(urlsArr) {
70
83
  return new URL(urlsArr[0]).origin;
71
84
  }
72
85
  // ---------------- wpt launcher --------------------------
73
86
  async postScript(script) {
74
- const urlPath = 'https://makefast.app.baqend.com/v1/code/testAPI';
75
- const res = await fetch(urlPath, { body: JSON.stringify({ script }), method: 'POST' });
87
+ const urlPath = "https://makefast.app.baqend.com/v1/code/testAPI";
88
+ const res = await (0, node_fetch_1.default)(urlPath, {
89
+ body: JSON.stringify({ script }),
90
+ method: "POST",
91
+ });
76
92
  return res.json();
77
93
  }
78
94
  }
@@ -1,4 +1,4 @@
1
- import { InstallConfigs } from '../models/install';
1
+ import { InstallConfigs } from "../models/install";
2
2
  export declare const SPEED_KIT_INSTALL_PATH: string;
3
3
  export declare const INSTALLATION_PROPERTIES: InstallConfigs<string>;
4
4
  type Params = {
@@ -6,17 +6,17 @@ const path_1 = tslib_1.__importDefault(require("path"));
6
6
  const isFile_1 = require("./isFile");
7
7
  const promises_1 = require("fs/promises");
8
8
  const logging_helper_1 = require("./logging-helper");
9
- exports.SPEED_KIT_INSTALL_PATH = '/speed-kit-install.js';
10
- const CUSTOMER_CONFIG_BASENAME = 'config_customer.js';
11
- const SK_CONFIG = 'config_SpeedKit.js';
12
- const RUM_CONFIG = 'config_loadHandler.js';
13
- const DF_CONFIG = 'config_dynamicBlocks.js';
14
- const DF_STYLES_BASENAME = 'config_dynamicStyles.css';
15
- const DOCUMENT_HANDLER_CONFIG = 'config_documentHandler.js';
16
- const CUSTOM_LOADER = 'custom_loader.js';
17
- const CUSTOM_SERVICE_WORKER = 'custom_sw.js';
18
- const CUSTOM_DOCUMENT_HANDLER = 'custom_documentHandler.js';
19
- const CUSTOM_DYNAMIC_FETCHER = 'custom_dynamicFetcher.js';
9
+ exports.SPEED_KIT_INSTALL_PATH = "/speed-kit-install.js";
10
+ const CUSTOMER_CONFIG_BASENAME = "config_customer.js";
11
+ const SK_CONFIG = "config_SpeedKit.js";
12
+ const RUM_CONFIG = "config_loadHandler.js";
13
+ const DF_CONFIG = "config_dynamicBlocks.js";
14
+ const DF_STYLES_BASENAME = "config_dynamicStyles.css";
15
+ const DOCUMENT_HANDLER_CONFIG = "config_documentHandler.js";
16
+ const CUSTOM_LOADER = "custom_loader.js";
17
+ const CUSTOM_SERVICE_WORKER = "custom_sw.js";
18
+ const CUSTOM_DOCUMENT_HANDLER = "custom_documentHandler.js";
19
+ const CUSTOM_DYNAMIC_FETCHER = "custom_dynamicFetcher.js";
20
20
  exports.INSTALLATION_PROPERTIES = {
21
21
  config: SK_CONFIG,
22
22
  custom: RUM_CONFIG,
@@ -38,16 +38,16 @@ function optional(check, params, name, defaultValue = null) {
38
38
  if (check(params[name])) {
39
39
  return params[name];
40
40
  }
41
- if (typeof params[name] === 'undefined' || params[name] === null) {
41
+ if (typeof params[name] === "undefined" || params[name] === null) {
42
42
  return defaultValue;
43
43
  }
44
44
  throw new TypeError(`Property "${name}" must be a ${check.name.substring(2)}.`);
45
45
  }
46
46
  function isString(value) {
47
- return typeof value === 'string';
47
+ return typeof value === "string";
48
48
  }
49
49
  function isBoolean(value) {
50
- return typeof value === 'boolean';
50
+ return typeof value === "boolean";
51
51
  }
52
52
  class CustomerConfig {
53
53
  name;
@@ -79,6 +79,7 @@ class CustomerConfig {
79
79
  if (!mainConfig) {
80
80
  throw new Error(`Could not find customer config file "${CUSTOMER_CONFIG_BASENAME}".`);
81
81
  }
82
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
82
83
  return require(mainConfig.filePath);
83
84
  }
84
85
  static async loadCustomer(dir, configName) {
@@ -88,37 +89,37 @@ class CustomerConfig {
88
89
  params = customerConfig[configName];
89
90
  }
90
91
  else {
91
- (0, logging_helper_1.logWarning)('Use legacy customer config loading format.');
92
- (0, logging_helper_1.logWarning)('Make sure to export the different app configs under their config names like:');
93
- (0, logging_helper_1.logWarning)('module.exports = { production, staging }');
92
+ (0, logging_helper_1.logWarning)("Use legacy customer config loading format.");
93
+ (0, logging_helper_1.logWarning)("Make sure to export the different app configs under their config names like:");
94
+ (0, logging_helper_1.logWarning)("module.exports = { production, staging }");
94
95
  params = customerConfig;
95
96
  }
96
97
  const configs = {};
97
98
  for (const [key, path] of Object.entries(exports.INSTALLATION_PROPERTIES)) {
98
- configs[key] = await ConfigFile.loadFile(dir, path, path.replace('.js', '.es6'));
99
+ configs[key] = await ConfigFile.loadFile(dir, path, path.replace(".js", ".es6"));
99
100
  }
100
101
  // Parse config
101
102
  return new CustomerConfig({ name: configName, ...params }, {
102
103
  ...configs,
103
- popConfig: await ConfigFile.loadFile(dir, 'config_pops.js'),
104
- globalWhitelist: await ConfigFile.loadFile(dir, '../../rules/global-whitelist.js'),
105
- globalBlacklist: await ConfigFile.loadFile(dir, '../../rules/global-blacklist.js'),
104
+ popConfig: await ConfigFile.loadFile(dir, "config_pops.js"),
105
+ globalWhitelist: await ConfigFile.loadFile(dir, "../../rules/global-whitelist.js"),
106
+ globalBlacklist: await ConfigFile.loadFile(dir, "../../rules/global-blacklist.js"),
106
107
  });
107
108
  }
108
109
  constructor(params, configFiles) {
109
- this.domain = required(isString, params, 'domain');
110
- this.name = optional(isString, params, 'name');
111
- this.swPath = optional(isString, params, 'swPath', '/wrapper-sw.js');
112
- this.app = optional(isString, params, 'app');
113
- this.appDomain = optional(isString, params, 'appDomain', '*.app.baqend.com');
114
- this.chromeFlags = optional(Array.isArray, params, 'chromeFlags', []);
115
- this.installPath = optional(isString, params, 'installPath', exports.SPEED_KIT_INSTALL_PATH);
116
- const scope = optional(isString, params, 'scope', '/');
117
- this.scope = scope + (scope.endsWith('/') ? '' : '/');
118
- this.origins = optional(Array.isArray, params, 'origins', []);
119
- this.installParams = optional(isString, params, 'installParams', 'async crossorigin="anonymous"');
120
- this.forceInstall = optional(isBoolean, params, 'forceInstall', false);
121
- this.bypassDeactivation = optional(isBoolean, params, 'bypassDeactivation', true);
110
+ this.domain = required(isString, params, "domain");
111
+ this.name = optional(isString, params, "name");
112
+ this.swPath = optional(isString, params, "swPath", "/wrapper-sw.js");
113
+ this.app = optional(isString, params, "app");
114
+ this.appDomain = optional(isString, params, "appDomain", "*.app.baqend.com");
115
+ this.chromeFlags = optional(Array.isArray, params, "chromeFlags", []);
116
+ this.installPath = optional(isString, params, "installPath", exports.SPEED_KIT_INSTALL_PATH);
117
+ const scope = optional(isString, params, "scope", "/");
118
+ this.scope = scope + (scope.endsWith("/") ? "" : "/");
119
+ this.origins = optional(Array.isArray, params, "origins", []);
120
+ this.installParams = optional(isString, params, "installParams", 'async crossorigin="anonymous"');
121
+ this.forceInstall = optional(isBoolean, params, "forceInstall", false);
122
+ this.bypassDeactivation = optional(isBoolean, params, "bypassDeactivation", true);
122
123
  // Assign Config Files
123
124
  Object.assign(this, configFiles);
124
125
  }
@@ -144,7 +145,7 @@ class ConfigFile {
144
145
  this.name = name;
145
146
  }
146
147
  async readContent() {
147
- return (0, promises_1.readFile)(this.filePath, 'utf-8');
148
+ return (0, promises_1.readFile)(this.filePath, "utf-8");
148
149
  }
149
150
  }
150
151
  exports.ConfigFile = ConfigFile;
@@ -11,19 +11,19 @@ const CustomerConfig_1 = require("./CustomerConfig");
11
11
  const logging_helper_1 = require("./logging-helper");
12
12
  async function createTemporalDir() {
13
13
  try {
14
- return fs.mkdtemp(path.join(os.tmpdir(), 'speed-kit-cli-'));
14
+ return fs.mkdtemp(path.join(os.tmpdir(), "speed-kit-cli-"));
15
15
  }
16
16
  catch (error) {
17
- console.error('Error creating temp folder', error);
17
+ console.error("Error creating temp folder", error);
18
18
  return null;
19
19
  }
20
20
  }
21
21
  exports.createTemporalDir = createTemporalDir;
22
22
  async function createEmptyFile() {
23
23
  const tempDir = await createTemporalDir();
24
- const filePath = path.join(tempDir, '/empty_FilePath.js');
24
+ const filePath = path.join(tempDir, "/empty_FilePath.js");
25
25
  const writeFilePromise = new Promise((resolve, reject) => {
26
- fs.writeFile(filePath, 'No file was found', err => {
26
+ fs.writeFile(filePath, "No file was found", (err) => {
27
27
  if (err) {
28
28
  return reject(err);
29
29
  }
@@ -35,7 +35,7 @@ async function createEmptyFile() {
35
35
  }
36
36
  exports.createEmptyFile = createEmptyFile;
37
37
  function trimFileExtension(str) {
38
- return str.replace('.js', '').replace('.es6', '');
38
+ return str.replace(".js", "").replace(".es6", "");
39
39
  }
40
40
  exports.trimFileExtension = trimFileExtension;
41
41
  async function readLocalFile(basePath, fileName) {
@@ -52,7 +52,7 @@ exports.readLocalFile = readLocalFile;
52
52
  * Returns the local path to the sk-onboarding project.
53
53
  */
54
54
  function getLocalPath(path) {
55
- const fullCustomerPath = path_1.default.resolve(path, '');
55
+ const fullCustomerPath = path_1.default.resolve(path, "");
56
56
  // Check if path is a valid path or not
57
57
  if (!fs.existsSync(fullCustomerPath)) {
58
58
  (0, logging_helper_1.logError)(`The given path: ${fullCustomerPath} is not a valid path`);
@@ -1,12 +1,12 @@
1
1
  import Protocol from "devtools-protocol";
2
2
  export declare class BaqendResponse implements Partial<Protocol.Fetch.FulfillRequestRequest> {
3
- readonly body: string;
4
3
  readonly requestId?: string;
5
4
  readonly responseCode: number;
5
+ readonly body: string;
6
6
  responseHeaders: Protocol.Fetch.HeaderEntry[];
7
- private contentLength;
8
7
  private contentType;
8
+ private contentLength;
9
9
  constructor(body: string, contentType?: string, headers?: Protocol.Fetch.HeaderEntry[], status?: number);
10
- protected addCustomHeaders(headers?: Protocol.Fetch.HeaderEntry[]): Protocol.Fetch.HeaderEntry[];
11
10
  setHeader(name: string, value: string): void;
11
+ protected addCustomHeaders(headers?: Protocol.Fetch.HeaderEntry[]): Protocol.Fetch.HeaderEntry[];
12
12
  }
@@ -8,12 +8,12 @@ const DEFAULT_HEADERS = [
8
8
  const DEFAULT_CONTENT_TYPE = "text/html; charset=utf-8";
9
9
  const DEFAULT_STATUS = 200;
10
10
  class BaqendResponse {
11
- body;
12
11
  requestId;
13
12
  responseCode;
13
+ body;
14
14
  responseHeaders;
15
- contentLength;
16
15
  contentType;
16
+ contentLength;
17
17
  constructor(body, contentType, headers, status) {
18
18
  this.responseCode = status || DEFAULT_STATUS;
19
19
  this.contentType = contentType || DEFAULT_CONTENT_TYPE;
@@ -24,6 +24,15 @@ class BaqendResponse {
24
24
  this.contentLength = body.length;
25
25
  this.body = Buffer.from(body).toString("base64");
26
26
  }
27
+ setHeader(name, value) {
28
+ for (const header of this.responseHeaders) {
29
+ if (header.name === name) {
30
+ header.value = value;
31
+ return;
32
+ }
33
+ }
34
+ this.responseHeaders.push({ name, value });
35
+ }
27
36
  addCustomHeaders(headers) {
28
37
  if (!headers?.find((o) => o.name === "Cache-Control")) {
29
38
  headers.push({
@@ -44,17 +53,9 @@ class BaqendResponse {
44
53
  if (!headers?.find((o) => o.name === "Content-Type")) {
45
54
  headers.push({ name: "Content-Type", value: String(this.contentType) });
46
55
  }
47
- headers.push({ name: "via", value: "sk-onboarding" }, { name: "Service-Worker-Allowed", value: "/" });
56
+ headers.push({ name: "via", value: "sk-onboarding" });
57
+ headers.push({ name: "Service-Worker-Allowed", value: "/" });
48
58
  return headers;
49
59
  }
50
- setHeader(name, value) {
51
- for (const header of this.responseHeaders) {
52
- if (header.name === name) {
53
- header.value = value;
54
- return;
55
- }
56
- }
57
- this.responseHeaders.push({ name, value });
58
- }
59
60
  }
60
61
  exports.BaqendResponse = BaqendResponse;
@@ -1,7 +1,7 @@
1
+ import { InstallSpeedKitJsTemplate } from "../templates/install-speed-kit-js-template";
2
+ import CustomerConfig from "../../integration-api/struct/customer-config";
1
3
  import { BundleService } from "../../bundler";
2
4
  import { FileListInterface } from "../../integration-api/integration-api-model";
3
- import CustomerConfig from "../../integration-api/struct/customer-config";
4
- import { InstallSpeedKitJsTemplate } from "../templates/install-speed-kit-js-template";
5
5
  export declare class SpeedKitInstallContext {
6
6
  private customerConfig;
7
7
  private configName;
@@ -10,6 +10,8 @@ export declare class SpeedKitInstallContext {
10
10
  private skTemplate;
11
11
  private isLocalRuntime;
12
12
  constructor(customerConfig: CustomerConfig, configName: string, files: FileListInterface, bundler: BundleService, skTemplate: InstallSpeedKitJsTemplate, isLocalRuntime?: boolean);
13
+ getSpeedKitInstallJs(): Promise<string>;
14
+ private getConfigSpeedKit;
13
15
  /**
14
16
  * Fetches and returns the latest dynamic fetcher from the code repository. If a new version is available online it is
15
17
  * downloaded and cached, otherwise the fetcher id returned from cache. The resulting module gets minified afterwards.
@@ -17,6 +19,4 @@ export declare class SpeedKitInstallContext {
17
19
  * @returns {Promise<string>} a Promise which resolves to the latest dynamic fetcher
18
20
  */
19
21
  bundleDynamicFetcher(): Promise<string>;
20
- private getConfigSpeedKit;
21
- getSpeedKitInstallJs(): Promise<string>;
22
22
  }
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SpeedKitInstallContext = void 0;
4
4
  const files_1 = require("../../../models/files");
5
5
  const IMPORT_PATHS = {
6
- "predictive-preloading": "https://www.baqend.com/speed-kit-predictive-preloading/latest/",
7
6
  rum: "https://www.baqend.com/rum/latest/",
8
7
  "speed-kit": "https://www.baqend.com/speed-kit/latest/",
8
+ "predictive-preloading": "https://www.baqend.com/speed-kit-predictive-preloading/latest/",
9
9
  };
10
10
  class SpeedKitInstallContext {
11
11
  customerConfig;
@@ -22,24 +22,32 @@ class SpeedKitInstallContext {
22
22
  this.skTemplate = skTemplate;
23
23
  this.isLocalRuntime = isLocalRuntime;
24
24
  }
25
- /**
26
- * Fetches and returns the latest dynamic fetcher from the code repository. If a new version is available online it is
27
- * downloaded and cached, otherwise the fetcher id returned from cache. The resulting module gets minified afterwards.
28
- *
29
- * @returns {Promise<string>} a Promise which resolves to the latest dynamic fetcher
30
- */
31
- async bundleDynamicFetcher() {
25
+ async getSpeedKitInstallJs() {
26
+ const configJs = this.skTemplate.render({
27
+ config: this.getConfigSpeedKit(),
28
+ forceInstall: this.customerConfig.forceInstall,
29
+ installPath: this.customerConfig.installPath,
30
+ installParams: this.customerConfig.installParams,
31
+ domain: this.customerConfig.domain,
32
+ df: this.files
33
+ .getByName(files_1.INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
34
+ .getContent(),
35
+ });
32
36
  return this.bundler.bundle({
33
- basePaths: {},
37
+ basePaths: IMPORT_PATHS,
34
38
  entryPoints: {
35
- "dynamicFetcher.js": this.files
36
- .getByName(files_1.INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
39
+ "rum.js": this.files
40
+ .getByName(files_1.INTEGRATION_FILES.CONFIG.LOAD_HANDLER)
41
+ .getContent(),
42
+ "config.js": configJs,
43
+ "loader.js": this.files
44
+ .getByName(files_1.INTEGRATION_FILES.CUSTOM.LOADER)
37
45
  .getContent(),
38
46
  },
39
- logLevel: "verbose",
40
- minify: false,
41
- platform: "browser",
42
- target: "es6",
47
+ logLevel: "error",
48
+ define: {
49
+ APP: JSON.stringify(this.customerConfig.app),
50
+ },
43
51
  });
44
52
  }
45
53
  getConfigSpeedKit() {
@@ -50,7 +58,7 @@ class SpeedKitInstallContext {
50
58
  return configString;
51
59
  }
52
60
  if (configString.includes("delayRacedOrigin")) {
53
- return configString.replace(/delayRacedOrigin:[^\d,|](\d*)[^,]*,/, (config, value) => {
61
+ return configString.replace(/delayRacedOrigin:[^,|\d](\d*)[^,]*,/, (config, value) => {
54
62
  return config.replace(value, "100");
55
63
  });
56
64
  }
@@ -58,32 +66,24 @@ class SpeedKitInstallContext {
58
66
  return configOpenTag + `\n delayRacedOrigin: 100,\n`;
59
67
  });
60
68
  }
61
- async getSpeedKitInstallJs() {
62
- const configJs = this.skTemplate.render({
63
- config: this.getConfigSpeedKit(),
64
- forceInstall: this.customerConfig.forceInstall,
65
- installPath: this.customerConfig.installPath,
66
- installParams: this.customerConfig.installParams,
67
- domain: this.customerConfig.domain,
68
- df: this.files
69
- .getByName(files_1.INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
70
- .getContent(),
71
- });
69
+ /**
70
+ * Fetches and returns the latest dynamic fetcher from the code repository. If a new version is available online it is
71
+ * downloaded and cached, otherwise the fetcher id returned from cache. The resulting module gets minified afterwards.
72
+ *
73
+ * @returns {Promise<string>} a Promise which resolves to the latest dynamic fetcher
74
+ */
75
+ async bundleDynamicFetcher() {
72
76
  return this.bundler.bundle({
73
- basePaths: IMPORT_PATHS,
74
- define: {
75
- APP: JSON.stringify(this.customerConfig.app),
76
- },
77
+ basePaths: {},
77
78
  entryPoints: {
78
- "config.js": configJs,
79
- "loader.js": this.files
80
- .getByName(files_1.INTEGRATION_FILES.CUSTOM.LOADER)
81
- .getContent(),
82
- "rum.js": this.files
83
- .getByName(files_1.INTEGRATION_FILES.CONFIG.LOAD_HANDLER)
79
+ "dynamicFetcher.js": this.files
80
+ .getByName(files_1.INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
84
81
  .getContent(),
85
82
  },
86
- logLevel: "error",
83
+ target: "es6",
84
+ logLevel: "verbose",
85
+ minify: false,
86
+ platform: "browser",
87
87
  });
88
88
  }
89
89
  }
@@ -6,6 +6,6 @@ export declare class AthenaService {
6
6
  private lastQueryResult;
7
7
  constructor(athena: Athena, cli: CliService);
8
8
  executeQuery(queryString: string): Promise<unknown[]>;
9
- getLastQueryResult(): unknown[];
10
9
  private fetchResult;
10
+ getLastQueryResult(): unknown[];
11
11
  }
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AthenaService = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const node_util_1 = tslib_1.__importDefault(require("node:util"));
6
- const safe_1 = require("../../../helpers/safe");
5
+ const util_1 = tslib_1.__importDefault(require("util"));
7
6
  const cli_1 = require("../../cli");
8
- const sleep = node_util_1.default.promisify(setTimeout);
7
+ const safe_1 = require("../../../helpers/safe");
8
+ const sleep = util_1.default.promisify(setTimeout);
9
9
  class AthenaService {
10
10
  athena;
11
11
  cli;
@@ -19,10 +19,10 @@ class AthenaService {
19
19
  return this.lastQueryResult;
20
20
  }
21
21
  const params = {
22
+ QueryString: queryString,
22
23
  QueryExecutionContext: {
23
24
  Database: "rum.pi",
24
25
  },
25
- QueryString: queryString,
26
26
  };
27
27
  this.cli.startAction("[athena-query]: fetch result");
28
28
  const result = await (0, safe_1.safe)(this.fetchResult(params));
@@ -34,9 +34,6 @@ class AthenaService {
34
34
  this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
35
35
  this.cli.writeError(result.error);
36
36
  }
37
- getLastQueryResult() {
38
- return this.lastQueryResult;
39
- }
40
37
  async fetchResult(params) {
41
38
  const request = await this.athena.startQueryExecution(params);
42
39
  let queryStatus = await this.athena.getQueryExecution({
@@ -56,20 +53,23 @@ class AthenaService {
56
53
  const queryResult = await this.athena.getQueryResults(queryParams);
57
54
  // transform result and return it
58
55
  const dataArray = [];
59
- for (const recordRow of queryResult.ResultSet.Rows) {
56
+ queryResult.ResultSet.Rows.forEach((recordRow) => {
60
57
  const object = {
61
- PIs: recordRow.Data[3].VarCharValue,
58
+ params: recordRow.Data[0].VarCharValue,
59
+ potentialGain: recordRow.Data[1].VarCharValue,
62
60
  cachedUrls: recordRow.Data[2].VarCharValue,
61
+ PIs: recordRow.Data[3].VarCharValue,
63
62
  example1: recordRow.Data[4].VarCharValue,
64
63
  example2: recordRow.Data[5].VarCharValue,
65
64
  example3: recordRow.Data[6].VarCharValue,
66
- params: recordRow.Data[0].VarCharValue,
67
- potentialGain: recordRow.Data[1].VarCharValue,
68
65
  };
69
66
  // into an array....
70
67
  dataArray.push(object);
71
- }
68
+ });
72
69
  return dataArray;
73
70
  }
71
+ getLastQueryResult() {
72
+ return this.lastQueryResult;
73
+ }
74
74
  }
75
75
  exports.AthenaService = AthenaService;
@@ -1,10 +1,10 @@
1
+ import { BaqendResponse } from "../browser/baqend-response";
1
2
  import { Protocol } from "devtools-protocol";
3
+ import { ParamQueryBuilder } from "./param-query-builder";
2
4
  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";
7
6
  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 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
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
+ const json2csv_1 = tslib_1.__importDefault(require("json2csv"));
10
10
  class Dashboard {
11
11
  customerConfig;
12
12
  paramQueryBuilder;
@@ -23,13 +23,13 @@ class Dashboard {
23
23
  async getResponse(request) {
24
24
  const url = new URL(request.url);
25
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" });
26
+ const filePath = path_1.default.join(__dirname, "./frontend-dist", "index.html");
27
+ const content = (0, fs_1.readFileSync)(filePath, { encoding: "utf-8" });
28
28
  return new baqend_response_1.BaqendResponse(content);
29
29
  }
30
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" });
31
+ const filePath = path_1.default.join(__dirname, "./frontend-dist", url.pathname);
32
+ const content = (0, fs_1.readFileSync)(filePath, { encoding: "utf-8" });
33
33
  let contentType = "application/javascript; charset=UTF-8";
34
34
  if (url.pathname.includes(".css")) {
35
35
  contentType = "text/css";
@@ -40,7 +40,7 @@ class Dashboard {
40
40
  return new baqend_response_1.BaqendResponse(JSON.stringify({ query: this.paramQueryBuilder.getQuery() }), "application/json; charset=UTF-8");
41
41
  }
42
42
  if (url.pathname.startsWith("/query/execute")) {
43
- const { postData } = request;
43
+ const postData = request.postData;
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) {
@@ -73,15 +73,15 @@ class Dashboard {
73
73
  return new baqend_response_1.BaqendResponse(JSON.stringify(this.customerConfig), "application/json; charset=UTF-8");
74
74
  }
75
75
  if (url.pathname.startsWith("/diff")) {
76
- const { postData } = request;
76
+ const postData = request.postData;
77
77
  const data = JSON.parse(postData);
78
- return this.requestDiffService.postDiff(data.url, data.params);
78
+ return await this.requestDiffService.postDiff(data.url, data.params);
79
79
  }
80
80
  if (url.pathname.startsWith("/cache/get")) {
81
81
  const response = [];
82
- for (const [url, baqendResponse] of this.cache.getAll()) {
83
- response.push({ response: baqendResponse, url });
84
- }
82
+ Array.from(this.cache.getAll()).forEach(([url, baqendResponse]) => {
83
+ response.push({ url, response: baqendResponse });
84
+ });
85
85
  return new baqend_response_1.BaqendResponse(JSON.stringify(response), "application/json; charset=UTF-8");
86
86
  }
87
87
  return new baqend_response_1.BaqendResponse("Not implemented");