@speedkit/cli 2.14.3 → 2.16.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 (113) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +5 -2
  3. package/dist/commands/generate-pop-config.js +6 -5
  4. package/dist/dummy.spec.js +4 -4
  5. package/dist/helpers/build-query-helper.js +49 -35
  6. package/dist/helpers/file-helper.d.ts +2 -8
  7. package/dist/helpers/file-helper.js +6 -41
  8. package/dist/helpers/get-parsed-config.js +7 -7
  9. package/dist/helpers/getChromePath.js +11 -7
  10. package/dist/helpers/isDirectory.js +1 -1
  11. package/dist/helpers/isFile.js +1 -1
  12. package/dist/helpers/normalize.d.ts +2 -0
  13. package/dist/helpers/normalize.js +14 -12
  14. package/dist/helpers/race.js +3 -1
  15. package/dist/helpers/scrape.js +3 -2
  16. package/dist/helpers/speedKitRuleToRegExp.js +2 -2
  17. package/dist/models/cli-parameters.d.ts +2 -2
  18. package/dist/models/cli-parameters.js +8 -2
  19. package/dist/models/files.js +13 -13
  20. package/dist/services/athena/athena-service-factory.d.ts +13 -0
  21. package/dist/services/athena/athena-service-factory.js +40 -0
  22. package/dist/services/athena/athena-service-model.d.ts +4 -0
  23. package/dist/services/athena/athena-service-model.js +7 -0
  24. package/dist/services/{athena-service.d.ts → athena/athena-service.d.ts} +4 -8
  25. package/dist/services/{athena-service.js → athena/athena-service.js} +12 -36
  26. package/dist/services/athena/error/fetch-credentials-error.d.ts +2 -0
  27. package/dist/services/athena/error/fetch-credentials-error.js +6 -0
  28. package/dist/services/athena/index.d.ts +4 -0
  29. package/dist/services/athena/index.js +7 -0
  30. package/dist/services/bundler/bundle-service-factory.d.ts +1 -1
  31. package/dist/services/bundler/bundle-service.d.ts +2 -2
  32. package/dist/services/bundler/bundle-service.js +29 -23
  33. package/dist/services/bundler/index.d.ts +2 -2
  34. package/dist/services/cli/cli-service.js +5 -5
  35. package/dist/services/cli/hooks.js +2 -2
  36. package/dist/services/cli/index.d.ts +3 -3
  37. package/dist/services/config-api/client.d.ts +1 -1
  38. package/dist/services/config-api/client.js +9 -7
  39. package/dist/services/config-api/config-api-service.js +20 -8
  40. package/dist/services/config-api/factory/config-api-service-factory.js +1 -1
  41. package/dist/services/config-api/interface/request-extension-interface.d.ts +2 -2
  42. package/dist/services/customer-config/customer-config-service-context.js +1 -1
  43. package/dist/services/customer-config/customer-config-service.d.ts +1 -0
  44. package/dist/services/customer-config/customer-config-service.js +68 -57
  45. package/dist/services/customer-config/index.d.ts +4 -4
  46. package/dist/services/deploy/builder/install-resource-builder.js +9 -7
  47. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +2 -2
  48. package/dist/services/deploy/checks/post-deploy/save-files-check.js +2 -2
  49. package/dist/services/deploy/deploy-service.js +7 -7
  50. package/dist/services/deploy/handler/customer-config-handler.js +12 -11
  51. package/dist/services/deploy/handler/install-resource-handler.js +14 -12
  52. package/dist/services/deploy/handler/install-resource-modifier/deleted-file-check.js +10 -10
  53. package/dist/services/deploy/handler/module-handler.js +9 -9
  54. package/dist/services/deploy/handler/module-modifier/deployment-detection-modifier.js +2 -2
  55. package/dist/services/deploy/handler/server-config-handler.js +4 -4
  56. package/dist/services/deploy/interface/install.d.ts +1 -1
  57. package/dist/services/document-handler-runtime/context/document-handler-runtime-context.js +37 -18
  58. package/dist/services/document-handler-runtime/document-handler-runtime-service.js +45 -35
  59. package/dist/services/document-handler-runtime/document-handler-server.js +56 -33
  60. package/dist/services/document-handler-runtime/error/handler/required-file-not-found-handler.js +1 -1
  61. package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +20 -16
  62. package/dist/services/document-handler-runtime/templates/abstract-template.d.ts +1 -1
  63. package/dist/services/document-handler-runtime/templates/abstract-template.js +1 -1
  64. package/dist/services/error-handling/abstract/abstract-async-error-handling-factory.js +1 -1
  65. package/dist/services/error-handling/abstract/abstract-async-error-handling-service.js +1 -1
  66. package/dist/services/error-handling/abstract/abstract-error-handling-factory.js +1 -1
  67. package/dist/services/error-handling/abstract/abstract-error-handling-service.js +1 -1
  68. package/dist/services/error-handling/error/handler/default-error-handler.d.ts +1 -1
  69. package/dist/services/error-handling/error/handler/default-error-handler.js +1 -1
  70. package/dist/services/error-handling/error-handling-service.js +2 -2
  71. package/dist/services/integration-api/context/integration-api-context.js +1 -1
  72. package/dist/services/integration-api/external/external-file-reader.js +1 -1
  73. package/dist/services/integration-api/factory/integration-api-service-factory.js +3 -3
  74. package/dist/services/integration-api/file-list.js +6 -4
  75. package/dist/services/integration-api/file-reader.js +17 -12
  76. package/dist/services/integration-api/handler/file-handler.d.ts +1 -1
  77. package/dist/services/integration-api/handler/file-handler.js +8 -4
  78. package/dist/services/integration-api/handler/install-resource-handler.js +21 -20
  79. package/dist/services/integration-api/handler/server-config-handler.js +1 -3
  80. package/dist/services/integration-api/integration-api-model.d.ts +2 -2
  81. package/dist/services/integration-api/integration-api-service.js +10 -7
  82. package/dist/services/integration-api/struct/customer-config.js +3 -2
  83. package/dist/services/integration-api/struct/file.js +4 -4
  84. package/dist/services/integration-api/struct/module-file.d.ts +1 -1
  85. package/dist/services/integration-api/struct/module-file.js +3 -1
  86. package/dist/services/integration-api/struct/server-config-file.d.ts +1 -1
  87. package/dist/services/integration-api/validator/customer-config-validator.js +13 -4
  88. package/dist/services/integration-api/validator/mandatory-files-validator.js +9 -5
  89. package/dist/services/integration-api/virtual/virtual-file-handler.js +1 -1
  90. package/dist/services/onboarding/dashboard/frontend-dist/assets/{index-87b53ed4.css → index-e3bd4f6e.css} +1 -1
  91. package/dist/services/onboarding/dashboard/frontend-dist/assets/{main-274b5625.js → main-215271c2.js} +3 -3
  92. package/dist/services/onboarding/dashboard/frontend-dist/index.html +2 -2
  93. package/dist/services/onboarding/dashboard/index.d.ts +2 -1
  94. package/dist/services/onboarding/dashboard/index.js +6 -5
  95. package/dist/services/onboarding/dashboard/request-diff-service.d.ts +4 -2
  96. package/dist/services/onboarding/dashboard/request-diff-service.js +23 -14
  97. package/dist/services/onboarding/fetch-events/speed-kit-asset-request.d.ts +1 -0
  98. package/dist/services/onboarding/fetch-events/speed-kit-asset-request.js +18 -1
  99. package/dist/services/onboarding/onboarding-service-factory.d.ts +0 -1
  100. package/dist/services/onboarding/onboarding-service-factory.js +9 -34
  101. package/dist/services/pop-config/index.d.ts +3 -0
  102. package/dist/services/pop-config/index.js +6 -0
  103. package/dist/services/pop-config/pop-config-factory.d.ts +4 -0
  104. package/dist/services/pop-config/pop-config-factory.js +12 -0
  105. package/dist/services/pop-config/pop-config-model.d.ts +6 -0
  106. package/dist/services/pop-config/pop-config-model.js +2 -0
  107. package/dist/services/pop-config/pop-config-service.d.ts +7 -0
  108. package/dist/services/pop-config/pop-config-service.js +39 -0
  109. package/dist/services/prewarm-service.js +22 -16
  110. package/oclif.manifest.json +1 -1
  111. package/package.json +2 -4
  112. package/dist/services/onboarding/dashboard/athena-service.d.ts +0 -11
  113. package/dist/services/onboarding/dashboard/athena-service.js +0 -75
@@ -6,8 +6,8 @@
6
6
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
8
  <title>Speedkit Devtools</title>
9
- <script type="module" crossorigin src="/assets/main-274b5625.js"></script>
10
- <link rel="stylesheet" href="/assets/index-87b53ed4.css">
9
+ <script type="module" crossorigin src="/assets/main-215271c2.js"></script>
10
+ <link rel="stylesheet" href="/assets/index-e3bd4f6e.css">
11
11
  </head>
12
12
 
13
13
  <body>
@@ -2,15 +2,16 @@ import { BaqendResponse } from "../browser/baqend-response";
2
2
  import { Protocol } from "devtools-protocol";
3
3
  import { ParamQueryBuilder } from "./param-query-builder";
4
4
  import CustomerConfig from "../../integration-api/struct/customer-config";
5
- import { AthenaService } from "./athena-service";
6
5
  import { RequestDiffService } from "./request-diff-service";
7
6
  import { Cache } from "../request-cache/cache";
7
+ import { AthenaService } from "../../athena";
8
8
  export declare class Dashboard {
9
9
  private customerConfig;
10
10
  private paramQueryBuilder;
11
11
  private athenaClient;
12
12
  private requestDiffService;
13
13
  private cache;
14
+ private athenaLastResult;
14
15
  constructor(customerConfig: CustomerConfig, paramQueryBuilder: ParamQueryBuilder, athenaClient: AthenaService, requestDiffService: RequestDiffService, cache: Cache);
15
16
  getResponse(request: Protocol.Network.Request): Promise<BaqendResponse>;
16
17
  }
@@ -13,6 +13,7 @@ class Dashboard {
13
13
  athenaClient;
14
14
  requestDiffService;
15
15
  cache;
16
+ athenaLastResult = null;
16
17
  constructor(customerConfig, paramQueryBuilder, athenaClient, requestDiffService, cache) {
17
18
  this.customerConfig = customerConfig;
18
19
  this.paramQueryBuilder = paramQueryBuilder;
@@ -42,18 +43,18 @@ class Dashboard {
42
43
  if (url.pathname.startsWith("/query/execute")) {
43
44
  const postData = request.postData;
44
45
  const data = JSON.parse(postData);
45
- const response = await (0, safe_1.safe)(this.athenaClient.executeQuery(data.query));
46
+ const response = await (0, safe_1.safe)(this.athenaClient.getResult(data.query, []));
46
47
  if (response.success === true) {
47
48
  return new baqend_response_1.BaqendResponse(JSON.stringify(response.data), "application/json; charset=UTF-8");
48
49
  }
49
50
  return new baqend_response_1.BaqendResponse(response.error, null, [{ name: "x-error", value: response.error }], 500);
50
51
  }
52
+ // @todo reImplement getLastResult
51
53
  if (url.pathname.startsWith("/query/download")) {
52
- const result = this.athenaClient.getLastQueryResult();
53
- result.shift();
54
+ const result = this.athenaLastResult;
54
55
  const csv = json2csv_1.default.parse(result, {
55
56
  fields: [
56
- "params",
57
+ "paramKeys",
57
58
  "potentialGain",
58
59
  "cachedUrls",
59
60
  "PIs",
@@ -75,7 +76,7 @@ class Dashboard {
75
76
  if (url.pathname.startsWith("/diff")) {
76
77
  const postData = request.postData;
77
78
  const data = JSON.parse(postData);
78
- return await this.requestDiffService.postDiff(data.url, data.params);
79
+ return await this.requestDiffService.postDiff(data.url, data.paramKeys);
79
80
  }
80
81
  if (url.pathname.startsWith("/cache/get")) {
81
82
  const response = [];
@@ -1,9 +1,11 @@
1
1
  import { DiffService } from "../../diff";
2
2
  import { BaqendResponse } from "../browser/baqend-response";
3
+ import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
3
4
  export declare class RequestDiffService {
4
5
  private diffService;
5
- constructor(diffService: DiffService);
6
- postDiff(url: string, parametersString: string): Promise<BaqendResponse>;
6
+ private documentHandlerRuntime;
7
+ constructor(diffService: DiffService, documentHandlerRuntime: DocumentHandlerServer);
8
+ postDiff(url: string, parametersString: string, autoCheck?: boolean): Promise<BaqendResponse>;
7
9
  private diffLocal;
8
10
  private doOriginVsContentDiff;
9
11
  private fetchHtml;
@@ -5,10 +5,12 @@ const baqend_response_1 = require("../browser/baqend-response");
5
5
  const safe_1 = require("../../../helpers/safe");
6
6
  class RequestDiffService {
7
7
  diffService;
8
- constructor(diffService) {
8
+ documentHandlerRuntime;
9
+ constructor(diffService, documentHandlerRuntime) {
9
10
  this.diffService = diffService;
11
+ this.documentHandlerRuntime = documentHandlerRuntime;
10
12
  }
11
- async postDiff(url, parametersString) {
13
+ async postDiff(url, parametersString, autoCheck = false) {
12
14
  const params = parametersString
13
15
  .replace("[", "")
14
16
  .replace("]", "")
@@ -17,17 +19,30 @@ class RequestDiffService {
17
19
  return param.trim();
18
20
  });
19
21
  const { urlWithParam, urlWithoutParam } = this.createUrlsForDiff(url, params);
20
- const result = await (0, safe_1.safe)(this.diffLocal(urlWithParam, urlWithoutParam));
22
+ const result = await (0, safe_1.safe)(this.diffLocal(urlWithParam, urlWithoutParam, autoCheck));
21
23
  if (result.success === true) {
22
- return new baqend_response_1.BaqendResponse(JSON.stringify({ status: "success", isIdentical: result.data }), "application/json; charset=UTF-8");
24
+ return new baqend_response_1.BaqendResponse(JSON.stringify({
25
+ status: "success",
26
+ isIdentical: result.data,
27
+ }), "application/json; charset=UTF-8");
23
28
  }
24
- return new baqend_response_1.BaqendResponse(JSON.stringify({ status: "error", error: result.error }), "application/json; charset=UTF-8", null, 500);
29
+ return new baqend_response_1.BaqendResponse(JSON.stringify({
30
+ status: "error",
31
+ error: result.error,
32
+ }), "application/json; charset=UTF-8", null, 500);
25
33
  }
26
- async diffLocal(urlWithParam, urlWithoutParam) {
34
+ async diffLocal(urlWithParam, urlWithoutParam, checkIsEqual = false) {
27
35
  const htmlWithParam = await this.fetchHtml(urlWithParam);
28
36
  const htmlWithoutParam = await this.fetchHtml(urlWithoutParam);
29
- const paramsFilePath = await this.diffService.writeContentToTemporalFile("params", htmlWithParam);
30
- const pureFilePath = await this.diffService.writeContentToTemporalFile("pure", htmlWithoutParam);
37
+ const replaceRegEx = /<meta[^>]*name="baqend:asset_url"[^>]*>/;
38
+ // <meta name="baqend:asset_url" content="https://www.kik.de/c/damen/damen-bekleidung-shirts-tops?page=7">
39
+ const transformedHtmlWithParam = (await this.documentHandlerRuntime.transform(htmlWithParam, "", urlWithParam, {})).replace(replaceRegEx, "");
40
+ const transformedHtmlWithoutParam = (await this.documentHandlerRuntime.transform(htmlWithoutParam, "", urlWithParam, {})).replace(replaceRegEx, "");
41
+ if (checkIsEqual) {
42
+ return this.diffService.isContentEqual(transformedHtmlWithParam, transformedHtmlWithoutParam);
43
+ }
44
+ const paramsFilePath = await this.diffService.writeContentToTemporalFile("params", transformedHtmlWithParam);
45
+ const pureFilePath = await this.diffService.writeContentToTemporalFile("pure", transformedHtmlWithoutParam);
31
46
  return await this.diffService.executeDiff(paramsFilePath, pureFilePath);
32
47
  }
33
48
  async doOriginVsContentDiff(url, content) {
@@ -48,12 +63,6 @@ class RequestDiffService {
48
63
  }
49
64
  url.search = search_params.toString();
50
65
  const urlWithoutParam = url.toString();
51
- console.log("With-----");
52
- console.log(urlWithParam);
53
- console.log("Without-----");
54
- console.log(urlWithoutParam);
55
- console.log("-----");
56
- // TODO: Insert the content
57
66
  return {
58
67
  urlWithParam,
59
68
  urlWithoutParam,
@@ -17,6 +17,7 @@ export declare class SpeedKitAssetRequest implements FetchRequestPausedEventHand
17
17
  get patterns(): Protocol.Fetch.RequestPattern[];
18
18
  constructor(customerConfig: CustomerConfig, documentHandler: DocumentHandlerServer, cache: Cache, cli: CliService, speedKitServerConfig?: SpeedKitServerConfig);
19
19
  handle(event: Protocol.Fetch.RequestPausedEvent): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | AbortResponse>;
20
+ private fetchAsset;
20
21
  private getCachedResponse;
21
22
  private buildCustomHeaders;
22
23
  private createResponseFromLocalDocumentHandler;
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SpeedKitAssetRequest = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const baqend_response_1 = require("../browser/baqend-response");
6
+ const https_1 = require("https");
7
+ const crypto_1 = tslib_1.__importDefault(require("crypto"));
8
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
9
+ const agent = new https_1.Agent({
10
+ rejectUnauthorized: false,
11
+ keepAlive: true,
12
+ secureOptions: crypto_1.default.constants.SSL_OP_LEGACY_SERVER_CONNECT,
13
+ });
5
14
  /**
6
15
  * Handles fetch requests for Speed Kit assets and returns customized responses.
7
16
  */
@@ -47,7 +56,7 @@ class SpeedKitAssetRequest {
47
56
  if (cachedResponse instanceof baqend_response_1.BaqendResponse) {
48
57
  return cachedResponse;
49
58
  }
50
- const response = await fetch(originUrl, this.prepareOriginRequest(variation, { headers: event.request.headers }));
59
+ const response = await this.fetchAsset(originUrl, variation, event);
51
60
  const customHeaders = this.buildCustomHeaders(originUrl);
52
61
  if (response.headers.get("Content-Type").includes("image") ||
53
62
  response.headers.get("Content-Type").includes("font")) {
@@ -80,6 +89,14 @@ class SpeedKitAssetRequest {
80
89
  return new baqend_response_1.BaqendResponse(message, null, customHeaders, 500);
81
90
  }
82
91
  }
92
+ fetchAsset(originUrl, variation, event) {
93
+ return (0, node_fetch_1.default)(originUrl, {
94
+ ...this.prepareOriginRequest(variation, {
95
+ headers: event.request.headers,
96
+ }),
97
+ agent,
98
+ });
99
+ }
83
100
  getCachedResponse(requestUrl) {
84
101
  const response = this.cache.getEntry(requestUrl);
85
102
  if (!(response instanceof baqend_response_1.BaqendResponse)) {
@@ -9,7 +9,6 @@ export declare class OnboardingServiceFactory {
9
9
  private buildInstallResource;
10
10
  private getAthenaClient;
11
11
  private getConfigApi;
12
- private getCredentials;
13
12
  private getFetchEventHandler;
14
13
  private getIntegrationFiles;
15
14
  private getUrlForTest;
@@ -2,10 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OnboardingServiceFactory = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const client_athena_1 = require("@aws-sdk/client-athena");
6
- const vm = tslib_1.__importStar(require("node:vm"));
7
5
  const safe_1 = require("../../helpers/safe");
8
6
  const files_1 = require("../../models/files");
7
+ const athena_1 = require("../athena");
9
8
  const bundler_1 = require("../bundler");
10
9
  const cli_1 = require("../cli");
11
10
  const config_api_context_1 = tslib_1.__importDefault(require("../config-api/context/config-api-context"));
@@ -20,7 +19,6 @@ const external_recipe_1 = require("../integration-api/virtual/external-recipe");
20
19
  const install_file_recipe_1 = require("./config-renderer/install-file-recipe");
21
20
  const speed_kit_install_context_1 = require("./config-renderer/speed-kit-install-context");
22
21
  const dashboard_1 = require("./dashboard");
23
- const athena_service_1 = require("./dashboard/athena-service");
24
22
  const param_query_builder_1 = require("./dashboard/param-query-builder");
25
23
  const request_diff_service_1 = require("./dashboard/request-diff-service");
26
24
  const fetch_event_handler_1 = require("./fetch-event-handler");
@@ -36,7 +34,6 @@ const file_watcher_1 = require("./file-events/file-watcher");
36
34
  const onboarding_model_1 = require("./onboarding-model");
37
35
  const onboarding_service_1 = require("./onboarding-service");
38
36
  const cache_1 = require("./request-cache/cache");
39
- const server_config_1 = require("./server-config");
40
37
  const install_speed_kit_html_template_1 = require("./templates/install-speed-kit-html-template");
41
38
  const install_speed_kit_js_template_1 = require("./templates/install-speed-kit-js-template");
42
39
  const todo_collector_1 = require("./todo-collector");
@@ -83,43 +80,22 @@ class OnboardingServiceFactory {
83
80
  cli.endAction(cli_1.CliActionStatus.FAILED);
84
81
  cli.writeError(result.error);
85
82
  }
86
- async getAthenaClient(cli) {
87
- const credentials = await this.getCredentials(cli);
88
- if (!credentials) {
89
- return;
83
+ async getAthenaClient() {
84
+ const athenaFactory = new athena_1.AthenaServiceFactory();
85
+ const result = await (0, safe_1.safe)(athenaFactory.getService());
86
+ if (result.success === true) {
87
+ return result.data;
90
88
  }
91
- const config = {
92
- credentials: {
93
- accessKeyId: credentials?.accessKeyId,
94
- secretAccessKey: credentials?.secretAccessKey,
95
- },
96
- region: "eu-central-1",
97
- };
98
- return new athena_service_1.AthenaService(new client_athena_1.Athena(config), cli);
99
89
  }
100
90
  getConfigApi(app) {
101
91
  const configApiContext = new config_api_context_1.default(app);
102
92
  return new config_api_service_factory_1.default(configApiContext).getService();
103
93
  }
104
- async getCredentials(cli) {
105
- cli.startAction("fetch athena credentials");
106
- const configApiContext = new config_api_context_1.default("onboarding");
107
- const configApi = new config_api_service_factory_1.default(configApiContext).getService();
108
- const credentialsResult = await (0, safe_1.safe)(configApi.getModule("credentials"));
109
- if (credentialsResult.success === true) {
110
- const context = { module: { exports: { AWS_ATHENA: {} } } };
111
- vm.runInNewContext(credentialsResult.data, context);
112
- cli.endAction(cli_1.CliActionStatus.COMPLETED);
113
- return context.module.exports.AWS_ATHENA;
114
- }
115
- cli.endAction(cli_1.CliActionStatus.FAILED);
116
- cli.writeError(credentialsResult.error);
117
- }
118
94
  async getFetchEventHandler(files, customerConfig, documentHandler, cache, cli, browserContext) {
119
95
  const configApi = this.getConfigApi(customerConfig.app);
120
96
  const paramQueryBuilder = new param_query_builder_1.ParamQueryBuilder(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CONFIG.SPEED_KIT));
121
97
  const DiffService = new diff_1.DiffServiceFactory(new diff_1.DiffContext(this.cliConfig.diffExec, this.cliConfig.diffExecTemplate)).getService();
122
- const requestDiffService = new request_diff_service_1.RequestDiffService(DiffService);
98
+ const requestDiffService = new request_diff_service_1.RequestDiffService(DiffService, documentHandler);
123
99
  const handlers = [
124
100
  new customer_domain_document_response_1.CustomerDomainDocumentResponse(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CONFIG.DYNAMIC_BLOCKS), files.getByName(files_1.INTEGRATION_FILES.CONFIG.DYNAMIC_STYLES)),
125
101
  new speed_kit_install_html_1.SpeedKitInstallHtml(customerConfig, browserContext, new install_speed_kit_html_template_1.InstallSpeedKitHtmlTemplate()),
@@ -128,10 +104,9 @@ class OnboardingServiceFactory {
128
104
  new speed_kit_service_worker_js_1.SpeedKitServiceWorkerJs(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CUSTOM.SW)),
129
105
  ];
130
106
  if (this.context.local) {
131
- const speedKitConfigLoader = new server_config_1.ServerConfig(cli, configApi);
132
- handlers.push(new speed_kit_asset_request_1.SpeedKitAssetRequest(customerConfig, documentHandler, cache, cli, await speedKitConfigLoader.getServerSpeedKitConfig()), new speed_kit_rum_pi_request_1.SpeedKitRumPiRequest(customerConfig, cache, cli));
107
+ handlers.push(new speed_kit_asset_request_1.SpeedKitAssetRequest(customerConfig, documentHandler, cache, cli), new speed_kit_rum_pi_request_1.SpeedKitRumPiRequest(customerConfig, cache, cli));
133
108
  }
134
- const athenaClient = await this.getAthenaClient(cli);
109
+ const athenaClient = await this.getAthenaClient();
135
110
  if (athenaClient) {
136
111
  handlers.push(new dashboard_request_1.DashboardRequest(new dashboard_1.Dashboard(customerConfig, paramQueryBuilder, athenaClient, requestDiffService, cache)));
137
112
  browserContext.startParameterDashboard = true;
@@ -0,0 +1,3 @@
1
+ export * from "./pop-config-service";
2
+ export * from "./pop-config-factory";
3
+ export * from "./pop-config-model";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./pop-config-service"), exports);
5
+ tslib_1.__exportStar(require("./pop-config-factory"), exports);
6
+ tslib_1.__exportStar(require("./pop-config-model"), exports);
@@ -0,0 +1,4 @@
1
+ import { PopConfigService } from "./pop-config-service";
2
+ export declare class PopConfigFactory {
3
+ getService(): Promise<PopConfigService>;
4
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PopConfigFactory = void 0;
4
+ const pop_config_service_1 = require("./pop-config-service");
5
+ const athena_1 = require("../athena");
6
+ class PopConfigFactory {
7
+ async getService() {
8
+ const athenaService = await new athena_1.AthenaServiceFactory().getService();
9
+ return new pop_config_service_1.PopConfigService(athenaService);
10
+ }
11
+ }
12
+ exports.PopConfigFactory = PopConfigFactory;
@@ -0,0 +1,6 @@
1
+ export type UsedPopsPerOrigin = {
2
+ hits: number;
3
+ origin: string;
4
+ pop: string;
5
+ region: string;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { UsedPopsPerOrigin } from "./";
2
+ import { AthenaService } from "../athena";
3
+ export declare class PopConfigService {
4
+ private athenaService;
5
+ constructor(athenaService: AthenaService);
6
+ getUsedPopsPerOrigin(app: string, useRum: boolean): Promise<UsedPopsPerOrigin[]>;
7
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PopConfigService = void 0;
4
+ class PopConfigService {
5
+ athenaService;
6
+ constructor(athenaService) {
7
+ this.athenaService = athenaService;
8
+ }
9
+ async getUsedPopsPerOrigin(app, useRum) {
10
+ const query = `
11
+ with data as (select *,
12
+ coalesce('https://' || url_extract_host(assetUrl) ||
13
+ regexp_extract(url_extract_path(assetUrl), '(?i)/([a-z]{2}([-/_][a-z]{2})*/)', 0),
14
+ 'Unknown') as originWithPrefix
15
+ from fastly.logs
16
+ where date between ? and ?
17
+ and app = ?
18
+ and ${useRum ? "ispibeacon" : "isassetrequest and isnavigaterequest"}
19
+ and client.bot is null
20
+ and origin not in ('Unknown', ''))
21
+
22
+ select region,
23
+ pop,
24
+ coalesce(originWithPrefix, origin) as origin,
25
+ count() as hits
26
+ from data
27
+ group by grouping sets (
28
+ (region, pop, origin),
29
+ (region, pop, origin, originWithPrefix)
30
+ )
31
+ having originWithPrefix is null or originWithPrefix <> 'Unknown'`;
32
+ const endDate = new Date();
33
+ const startDate = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate() - 7);
34
+ const start = startDate.toISOString().slice(0, 10);
35
+ const end = endDate.toISOString().slice(0, 10);
36
+ return await this.athenaService.getResult(query, [start, end, app], 12 * 60);
37
+ }
38
+ }
39
+ exports.PopConfigService = PopConfigService;
@@ -1,27 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
3
4
  const normalize_1 = require("../helpers/normalize");
4
- const fetch = require('node-fetch');
5
- const https = require('https');
6
- const agent = new https.Agent({
5
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
6
+ const https_1 = tslib_1.__importDefault(require("https"));
7
+ const agent = new https_1.default.Agent({
7
8
  rejectUnauthorized: false,
8
9
  keepAlive: true,
9
10
  });
10
11
  class PrewarmService {
11
12
  // eslint-disable-next-line max-params
12
13
  static async fetchURLByIp(ip, url, origin, variation, app, token) {
13
- if (variation && variation !== 'DEFAULT' && variation !== 'DESKTOP') {
14
- url = url + (url.includes('?') ? '&' : '?') + `bqvariation=${variation.toLowerCase()}`;
14
+ if (variation && variation !== "DEFAULT" && variation !== "DESKTOP") {
15
+ url =
16
+ url +
17
+ (url.includes("?") ? "&" : "?") +
18
+ `bqvariation=${variation.toLowerCase()}`;
15
19
  }
16
- url += (url.includes('?') ? '&' : '?') + `bqpass=1`;
17
- return fetch(`https://${ip}/v1/asset/${url}`, {
20
+ url += (url.includes("?") ? "&" : "?") + `bqpass=1`;
21
+ return (0, node_fetch_1.default)(`https://${ip}/v1/asset/${url}`, {
18
22
  agent,
19
- method: 'HEAD',
23
+ method: "HEAD",
20
24
  headers: {
21
25
  Host: `${app}.app.baqend.com`,
22
26
  Origin: origin,
23
27
  authorization: `BAT ${token}`,
24
- 'Accept-Encoding': 'gzip, deflate, br',
28
+ "Accept-Encoding": "gzip, deflate, br",
25
29
  },
26
30
  timeout: 10_000,
27
31
  });
@@ -29,17 +33,19 @@ class PrewarmService {
29
33
  // eslint-disable-next-line max-params
30
34
  static async fetchURL(url, origin, variation, app, token, sortParameters) {
31
35
  let normalizedUrl = (0, normalize_1.normalize)(url, sortParameters);
32
- if (variation && variation !== 'DEFAULT' && variation !== 'DESKTOP') {
33
- normalizedUrl += (normalizedUrl.includes('?') ? '&' : '?') + `bqvariation=${variation.toLowerCase()}`;
36
+ if (variation && variation !== "DEFAULT" && variation !== "DESKTOP") {
37
+ normalizedUrl +=
38
+ (normalizedUrl.includes("?") ? "&" : "?") +
39
+ `bqvariation=${variation.toLowerCase()}`;
34
40
  }
35
- normalizedUrl += (normalizedUrl.includes('?') ? '&' : '?') + `bqpass=1`;
36
- return fetch(`https://${app}.app.baqend.com/v1/asset/${normalizedUrl}`, {
41
+ normalizedUrl += (normalizedUrl.includes("?") ? "&" : "?") + `bqpass=1`;
42
+ return (0, node_fetch_1.default)(`https://${app}.app.baqend.com/v1/asset/${normalizedUrl}`, {
37
43
  agent,
38
- method: 'HEAD',
44
+ method: "HEAD",
39
45
  headers: {
40
46
  Origin: origin,
41
47
  authorization: `BAT ${token}`,
42
- 'Accept-Encoding': 'gzip, deflate, br',
48
+ "Accept-Encoding": "gzip, deflate, br",
43
49
  },
44
50
  timeout: 10_000,
45
51
  });
@@ -49,7 +55,7 @@ class PrewarmService {
49
55
  const n = arr.length;
50
56
  let i = 0;
51
57
  while (i < n) {
52
- chunks.push(arr.slice(i, i += len));
58
+ chunks.push(arr.slice(i, (i += len)));
53
59
  }
54
60
  return chunks;
55
61
  }
@@ -696,5 +696,5 @@
696
696
  ]
697
697
  }
698
698
  },
699
- "version": "2.14.3"
699
+ "version": "2.16.0"
700
700
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "2.14.3",
4
+ "version": "2.16.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"
@@ -115,8 +115,6 @@
115
115
  "chai": "^4.4",
116
116
  "copyfiles": "^2.4.1",
117
117
  "eslint": "^8.57",
118
- "eslint-config-oclif": "^5.1",
119
- "eslint-config-oclif-typescript": "^3.1",
120
118
  "eslint-config-prettier": "^9.1",
121
119
  "eslint-plugin-prettier": "^5.1",
122
120
  "globby": "^11",
@@ -138,7 +136,7 @@
138
136
  },
139
137
  "lint-staged": {
140
138
  "*.ts": [
141
- "eslint --fix"
139
+ "eslint --fix --quiet"
142
140
  ]
143
141
  }
144
142
  }
@@ -1,11 +0,0 @@
1
- import { Athena } from "@aws-sdk/client-athena";
2
- import { CliService } from "../../cli";
3
- export declare class AthenaService {
4
- private athena;
5
- private cli;
6
- private lastQueryResult;
7
- constructor(athena: Athena, cli: CliService);
8
- executeQuery(queryString: string): Promise<unknown[]>;
9
- private fetchResult;
10
- getLastQueryResult(): unknown[];
11
- }
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AthenaService = void 0;
4
- const tslib_1 = require("tslib");
5
- const util_1 = tslib_1.__importDefault(require("util"));
6
- const cli_1 = require("../../cli");
7
- const safe_1 = require("../../../helpers/safe");
8
- const sleep = util_1.default.promisify(setTimeout);
9
- class AthenaService {
10
- athena;
11
- cli;
12
- lastQueryResult = [];
13
- constructor(athena, cli) {
14
- this.athena = athena;
15
- this.cli = cli;
16
- }
17
- async executeQuery(queryString) {
18
- if (this.lastQueryResult.length > 0) {
19
- return this.lastQueryResult;
20
- }
21
- const params = {
22
- QueryString: queryString,
23
- QueryExecutionContext: {
24
- Database: "rum.pi",
25
- },
26
- };
27
- this.cli.startAction("[athena-query]: fetch result");
28
- const result = await (0, safe_1.safe)(this.fetchResult(params));
29
- if (result.success === true) {
30
- this.lastQueryResult = result.data;
31
- this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
32
- return result.data;
33
- }
34
- this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
35
- this.cli.writeError(result.error);
36
- }
37
- async fetchResult(params) {
38
- const request = await this.athena.startQueryExecution(params);
39
- let queryStatus = await this.athena.getQueryExecution({
40
- QueryExecutionId: request.QueryExecutionId,
41
- });
42
- while (queryStatus.QueryExecution.Status.State === "QUEUED" ||
43
- queryStatus.QueryExecution.Status.State === "RUNNING") {
44
- await sleep(2000);
45
- queryStatus = await this.athena.getQueryExecution({
46
- QueryExecutionId: request.QueryExecutionId,
47
- });
48
- }
49
- const queryParams = {
50
- QueryExecutionId: request.QueryExecutionId,
51
- // MaxResults: 10
52
- };
53
- const queryResult = await this.athena.getQueryResults(queryParams);
54
- // transform result and return it
55
- const dataArray = [];
56
- queryResult.ResultSet.Rows.forEach((recordRow) => {
57
- const object = {
58
- params: recordRow.Data[0].VarCharValue,
59
- potentialGain: recordRow.Data[1].VarCharValue,
60
- cachedUrls: recordRow.Data[2].VarCharValue,
61
- PIs: recordRow.Data[3].VarCharValue,
62
- example1: recordRow.Data[4].VarCharValue,
63
- example2: recordRow.Data[5].VarCharValue,
64
- example3: recordRow.Data[6].VarCharValue,
65
- };
66
- // into an array....
67
- dataArray.push(object);
68
- });
69
- return dataArray;
70
- }
71
- getLastQueryResult() {
72
- return this.lastQueryResult;
73
- }
74
- }
75
- exports.AthenaService = AthenaService;