@speedkit/cli 2.62.1 → 2.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [2.63.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.62.1...v2.63.0) (2024-11-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * create dashboardEndpoint also without aws-credentials ([38ccbf9](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/38ccbf9d83b9d9fc3d37cbcbe3196e1509ffdaff))
7
+
8
+
9
+ ### Features
10
+
11
+ * **onboarding:** make documentHandler errors more verbose ([cfb7e44](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/cfb7e448491ae7469addfd2370167a303f381851))
12
+
1
13
  ## [2.62.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.62.0...v2.62.1) (2024-11-01)
2
14
 
3
15
 
package/README.md CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @speedkit/cli
21
21
  $ sk COMMAND
22
22
  running command...
23
23
  $ sk (--version)
24
- @speedkit/cli/2.62.1 linux-x64 node-v20.18.0
24
+ @speedkit/cli/2.63.0 linux-x64 node-v20.18.0
25
25
  $ sk --help [COMMAND]
26
26
  USAGE
27
27
  $ sk COMMAND
@@ -13,10 +13,14 @@ async function safeAsync(promise) {
13
13
  return { data, success: true };
14
14
  }
15
15
  catch (error) {
16
- if (error instanceof Error) {
16
+ if (error instanceof Error || isError(error)) {
17
17
  return { success: false, error: error.message, errorObj: error };
18
18
  }
19
- return { success: false, error: "Something went wrong", errorObj: error };
19
+ return {
20
+ success: false,
21
+ error: "Something went wrong: " + error?.message,
22
+ errorObj: error,
23
+ };
20
24
  }
21
25
  }
22
26
  function safeSync(function_) {
@@ -25,9 +29,18 @@ function safeSync(function_) {
25
29
  return { data, success: true };
26
30
  }
27
31
  catch (error) {
28
- if (error instanceof Error) {
32
+ if (error instanceof Error || isError(error)) {
29
33
  return { success: false, error: error.message, errorObj: error };
30
34
  }
31
35
  return { success: false, error: "Something went wrong", errorObj: error };
32
36
  }
33
37
  }
38
+ function isError(error) {
39
+ if (!("message" in error)) {
40
+ return false;
41
+ }
42
+ if (!("stack" in error)) {
43
+ return false;
44
+ }
45
+ return true;
46
+ }
@@ -6,7 +6,6 @@ const document_handler_runtime_context_1 = require("./context/document-handler-r
6
6
  const required_file_not_found_error_1 = tslib_1.__importDefault(require("./error/required-file-not-found-error"));
7
7
  const database_mock_1 = tslib_1.__importDefault(require("./templates/database-mock"));
8
8
  const vm = tslib_1.__importStar(require("node:vm"));
9
- const vm_error_1 = require("../onboarding/error/vm-error");
10
9
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
11
10
  const files_1 = require("../../models/files");
12
11
  // documentHandlerDependencies
@@ -15,6 +14,7 @@ const request_1 = require("./server/request");
15
14
  const document_handler_response_1 = require("./server/document-handler-response");
16
15
  const safe_1 = require("../../helpers/safe");
17
16
  const vm_empty_response_error_1 = require("../onboarding/error/vm-empty-response-error");
17
+ const document_handler_transform_error_1 = require("../onboarding/error/document-handler-transform-error");
18
18
  class DocumentHandlerServer {
19
19
  customerConfig;
20
20
  files;
@@ -50,6 +50,7 @@ class DocumentHandlerServer {
50
50
  CUSTOM_STYLES: this.getStyles(),
51
51
  ...this.getContextVars(),
52
52
  ...this.createNodeVmContext(),
53
+ skErrorContext: {},
53
54
  };
54
55
  const customDocumentHandlerFile = this.files.getByName(files_1.INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
55
56
  if (customDocumentHandlerFile.path) {
@@ -77,10 +78,10 @@ class DocumentHandlerServer {
77
78
  }
78
79
  return vmResponse.data;
79
80
  }
80
- throw new vm_error_1.VmError(vmResponse.error + JSON.stringify(vmResponse.errorObj));
81
+ throw new document_handler_transform_error_1.DocumentHandlerTransformError(vmResponse.errorObj);
81
82
  }
82
83
  getTransformFunctionWrapper() {
83
- return `\n\npost(db, skInternalRequest, skInternalResponse).catch((err)=>{reject(err);});`;
84
+ return `\n\npost(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`;
84
85
  }
85
86
  async buildDocumentHandler() {
86
87
  this.documentHandlerCode = await this.getDocumentHandler();
@@ -1,10 +1,12 @@
1
1
  import { DiffService } from "../../diff";
2
2
  import { DocumentHandlerServer } from "../../document-handler-runtime/document-handler-server";
3
3
  import { Crawler } from "../virtual-orestes-app/crawler";
4
+ import { CliService } from "../../cli";
4
5
  export declare class DiffAgainstCurrentPage {
5
6
  private diffService;
6
7
  private documentHandlerRuntime;
7
8
  private crawler;
8
- constructor(diffService: DiffService, documentHandlerRuntime: DocumentHandlerServer, crawler: Crawler);
9
+ private cli;
10
+ constructor(diffService: DiffService, documentHandlerRuntime: DocumentHandlerServer, crawler: Crawler, cli: CliService);
9
11
  postDiff(currentHtml: string, currentUrl: string, variant?: string, transform?: boolean): Promise<boolean>;
10
12
  }
@@ -1,21 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DiffAgainstCurrentPage = void 0;
4
+ const cli_1 = require("../../cli");
4
5
  class DiffAgainstCurrentPage {
5
6
  diffService;
6
7
  documentHandlerRuntime;
7
8
  crawler;
8
- constructor(diffService, documentHandlerRuntime, crawler) {
9
+ cli;
10
+ constructor(diffService, documentHandlerRuntime, crawler, cli) {
9
11
  this.diffService = diffService;
10
12
  this.documentHandlerRuntime = documentHandlerRuntime;
11
13
  this.crawler = crawler;
14
+ this.cli = cli;
12
15
  }
13
16
  async postDiff(currentHtml, currentUrl, variant = "DEFAULT", transform = false) {
17
+ this.cli.writeWarning(`received diff for url: ${currentUrl}`);
18
+ this.cli.startAction(`fetch remote`);
14
19
  const originResponse = await this.crawler.fetchRemote(currentUrl, variant.toUpperCase());
15
20
  let originHtml = await originResponse?.text();
16
21
  if (!originHtml) {
22
+ this.cli.endAction(cli_1.CliActionStatus.FAILED);
17
23
  throw new Error("Could not fetch remote page");
18
24
  }
25
+ this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
26
+ this.cli.startAction(`transform documents`);
19
27
  if (transform) {
20
28
  // todo check if the currentHTML is already transformed
21
29
  const currentDocumentHandlerResponse = await this.documentHandlerRuntime.transform(currentHtml, variant, currentUrl, {});
@@ -23,6 +31,7 @@ class DiffAgainstCurrentPage {
23
31
  const originDocumentHandlerResponse = await this.documentHandlerRuntime.transform(originHtml, variant, currentUrl, {});
24
32
  originHtml = originDocumentHandlerResponse.body;
25
33
  }
34
+ this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
26
35
  const remoteFilePath = await this.diffService.writeContentToTemporalFile(`remote-${variant}`, originHtml);
27
36
  const localFilePath = await this.diffService.writeContentToTemporalFile("current", currentHtml);
28
37
  return await this.diffService.executeDiff(localFilePath, remoteFilePath);
@@ -0,0 +1,3 @@
1
+ export declare class DocumentHandlerTransformError extends Error {
2
+ constructor(error: Error);
3
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentHandlerTransformError = void 0;
4
+ class DocumentHandlerTransformError extends Error {
5
+ constructor(error) {
6
+ super(error.message);
7
+ this.stack = error.stack;
8
+ this.cause = error.cause;
9
+ }
10
+ }
11
+ exports.DocumentHandlerTransformError = DocumentHandlerTransformError;
@@ -124,14 +124,12 @@ class OnboardingServiceFactory {
124
124
  new speed_kit_install_js_1.SpeedKitInstallJs(customerConfig, files.getByName(files_1.INTEGRATION_FILES.BUILD.INSTALL)),
125
125
  new customer_service_worker_js_1.CustomerServiceWorkerJs(customerConfig),
126
126
  new speed_kit_service_worker_js_1.SpeedKitServiceWorkerJs(customerConfig, files.getByName(files_1.INTEGRATION_FILES.CUSTOM.SW)),
127
+ new dashboard_request_1.DashboardRequest(new dashboard_1.Dashboard(customerConfig, parameterQueryBuilder, athenaClient, requestDiffService, new diff_against_current_page_1.DiffAgainstCurrentPage(DiffService, documentHandler, crawler, cli), cache)),
127
128
  ];
128
129
  if (this.context.local) {
129
130
  const orestesApp = new virtual_orestes_app_1.VirtualOrestesApp(customerConfig, crawler, documentHandler, cache, cli);
130
131
  handlers.push(new speed_kit_asset_request_1.SpeedKitAssetRequest(customerConfig, orestesApp), new speed_kit_rum_pi_request_1.SpeedKitRumPiRequest(customerConfig, cache, cli));
131
132
  }
132
- if (athenaClient) {
133
- handlers.push(new dashboard_request_1.DashboardRequest(new dashboard_1.Dashboard(customerConfig, parameterQueryBuilder, athenaClient, requestDiffService, new diff_against_current_page_1.DiffAgainstCurrentPage(DiffService, documentHandler, crawler), cache)));
134
- }
135
133
  return new fetch_event_handler_1.FetchEventHandler(handlers, customerConfig, cli, configApi);
136
134
  }
137
135
  async getSpeedKitServerConfig(configApi, cli) {
@@ -79,12 +79,10 @@ class VirtualOrestesApp {
79
79
  return baqendResponse;
80
80
  }
81
81
  returnErrorResponse(customResponse, customHeaders) {
82
- let message = `could not transform html - ${customResponse.error}`;
83
- if (customResponse.errorObj) {
84
- message = customResponse.errorObj.message;
85
- }
86
- this.cli.writeError(message);
87
- this.cli.writeError(JSON.stringify(customResponse.errorObj));
82
+ const message = `Could not transform html: - ${customResponse.error}`;
83
+ this.cli.writeError(`[VirtualOrestes]: ${message}`);
84
+ this.cli.comment(customResponse.errorObj.stack);
85
+ this.cli.writeWarning("Suggestion: check files: config_documentHandler.es6 | custom_documentHandler.js");
88
86
  customHeaders.push({ name: "x-error", value: message });
89
87
  return new baqend_response_1.BaqendResponse(message, null, customHeaders, 500);
90
88
  }
@@ -712,5 +712,5 @@
712
712
  ]
713
713
  }
714
714
  },
715
- "version": "2.62.1"
715
+ "version": "2.63.0"
716
716
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "2.62.1",
4
+ "version": "2.63.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"