@speedkit/cli 2.24.0 → 2.25.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,12 @@
1
+ # [2.25.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.24.0...v2.25.0) (2024-04-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * **onboarding:** add a flagInput to optin for ignoring the contentPolicy ([760764d](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/760764d6c1826b46f8e8d0164f2ada0d0ae71fd4))
7
+ * **onboarding:** remove content-policy-header ([c0ee577](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/c0ee577416ebbac6314463a93528cb5ccb68f3b2))
8
+ * **onboarding:** remove unnecessary unpacking ([5f16138](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/5f161387536201b46c1270eb2cab4d10e3f3cffa))
9
+
1
10
  # [2.24.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.23.2...v2.24.0) (2024-04-17)
2
11
 
3
12
 
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.24.0 linux-x64 node-v20.12.2
24
+ @speedkit/cli/2.25.0 linux-x64 node-v20.12.2
25
25
  $ sk --help [COMMAND]
26
26
  USAGE
27
27
  $ sk COMMAND
@@ -364,15 +364,16 @@ Start a local dev environment for building and testing the Speed Kit configurati
364
364
 
365
365
  ```
366
366
  USAGE
367
- $ sk onboarding CUSTOMERPATH [-c <value>] [-l] [-v]
367
+ $ sk onboarding CUSTOMERPATH [-c <value>] [-l] [-v] [-s]
368
368
 
369
369
  ARGUMENTS
370
370
  CUSTOMERPATH The customer config path
371
371
 
372
372
  FLAGS
373
- -c, --configName=<value> [default: production] The costumer config name
374
- -l, --local Run with local documentHandler
375
- -v, --verboseLevel Show all messages
373
+ -c, --configName=<value> [default: production] The costumer config name
374
+ -l, --local Run with local documentHandler
375
+ -s, --ignoreContentSecurityPolicy Removes header/meta "content-security-policy" for origin-responses
376
+ -v, --verboseLevel Show all messages
376
377
 
377
378
  DESCRIPTION
378
379
  Start a local dev environment for building and testing the Speed Kit configuration
@@ -1,11 +1,9 @@
1
1
  import { Command } from "@oclif/core";
2
2
  export default class Onboarding extends Command {
3
3
  static description: string;
4
- static flags: {
5
- local: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
6
- verboseLevel: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
- configName: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
8
- };
4
+ static flags: import("@oclif/core/lib/interfaces/parser").FlagInput<{
5
+ [flag: string]: any;
6
+ }>;
9
7
  static args: {
10
8
  customerPath: import("@oclif/core/lib/interfaces").Arg<string, {
11
9
  exists?: boolean;
@@ -6,27 +6,15 @@ const onboarding_1 = require("../services/onboarding");
6
6
  const cli_config_1 = require("../helpers/cli-config");
7
7
  class Onboarding extends core_1.Command {
8
8
  static description = "Start a local dev environment for building and testing the Speed Kit configuration";
9
- static flags = {
10
- ...cli_parameters_1.CLI_CONFIG_NAME,
11
- local: core_1.Flags.boolean({
12
- char: "l",
13
- default: false,
14
- description: "Run with local documentHandler",
15
- }),
16
- verboseLevel: core_1.Flags.boolean({
17
- char: "v",
18
- default: false,
19
- description: "Show all messages",
20
- }),
21
- };
9
+ static flags = onboarding_1.OnboardingContext.flags;
22
10
  static args = cli_parameters_1.CLI_CUSTOMER_CONFIG;
23
11
  static examples = [
24
12
  `$ sk onboarding <${cli_parameters_1.CLIParameters.CustomerPath}> -${cli_parameters_1.CLIParametersChar.ConfigName} <${cli_parameters_1.CLIParameters.ConfigName}>`,
25
13
  `$ sk onboarding ${cli_parameters_1.CLIParametersExample.CustomerPath} -${cli_parameters_1.CLIParametersChar.ConfigName} ${cli_parameters_1.CLIParametersExample.ConfigName}`,
26
14
  ];
27
15
  async run() {
28
- const { args: { customerPath }, flags: { configName, local, verboseLevel }, } = await this.parse(Onboarding);
29
- const service = await new onboarding_1.OnboardingServiceFactory(new onboarding_1.OnboardingContext(customerPath, configName, local, verboseLevel), new cli_config_1.CliConfig(this.config).load()).getService();
16
+ const { args: { customerPath }, flags: { configName, local, verboseLevel, ignoreContentSecurityPolicy }, } = await this.parse(Onboarding);
17
+ const service = await new onboarding_1.OnboardingServiceFactory(new onboarding_1.OnboardingContext(customerPath, configName, local, verboseLevel, ignoreContentSecurityPolicy), new cli_config_1.CliConfig(this.config).load()).getService();
30
18
  await service.run();
31
19
  }
32
20
  }
@@ -11,8 +11,9 @@ export declare class CustomerDomainDocumentResponse implements FetchRequestPause
11
11
  private customerConfig;
12
12
  private configDynamicBlock;
13
13
  private configDynamicStyles;
14
+ private removeContentSecurityPolicy;
14
15
  get patterns(): Protocol.Fetch.RequestPattern[];
15
- constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface);
16
+ constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface, removeContentSecurityPolicy: boolean);
16
17
  handle(event: Protocol.Fetch.RequestPausedEvent, client: CDPSession): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | void>;
17
18
  private isValidHtmlContent;
18
19
  private isValidResponse;
@@ -21,4 +22,18 @@ export declare class CustomerDomainDocumentResponse implements FetchRequestPause
21
22
  private isSpeedKitResponse;
22
23
  private rewriteInstallResource;
23
24
  private rewriteHtmlToLocalConfig;
25
+ /**
26
+ * Removes content policy headers from the given array of headers.
27
+ *
28
+ * @param {Protocol.Fetch.HeaderEntry[]} headers - The array of header entries.
29
+ * @returns {Protocol.Fetch.HeaderEntry[]} - The modified array of header entries with content policy headers removed.
30
+ */
31
+ private removeContentSecurityHeaderFromResponse;
32
+ /**
33
+ * Removes the content security meta tag from the provided HTML content.
34
+ *
35
+ * @param {string} htmlContent - The HTML content from which to remove the meta tag.
36
+ * @returns {string} - The HTML content without the content security meta tag.
37
+ */
38
+ private removeContentSecurityMetaTag;
24
39
  }
@@ -10,6 +10,7 @@ class CustomerDomainDocumentResponse {
10
10
  customerConfig;
11
11
  configDynamicBlock;
12
12
  configDynamicStyles;
13
+ removeContentSecurityPolicy;
13
14
  get patterns() {
14
15
  const result = [];
15
16
  for (const origin of this.customerConfig.origins) {
@@ -44,10 +45,11 @@ class CustomerDomainDocumentResponse {
44
45
  }
45
46
  return result;
46
47
  }
47
- constructor(customerConfig, configDynamicBlock, configDynamicStyles) {
48
+ constructor(customerConfig, configDynamicBlock, configDynamicStyles, removeContentSecurityPolicy) {
48
49
  this.customerConfig = customerConfig;
49
50
  this.configDynamicBlock = configDynamicBlock;
50
51
  this.configDynamicStyles = configDynamicStyles;
52
+ this.removeContentSecurityPolicy = removeContentSecurityPolicy;
51
53
  }
52
54
  async handle(event, client) {
53
55
  if (!this.isValidResponse(event)) {
@@ -66,7 +68,13 @@ class CustomerDomainDocumentResponse {
66
68
  if (this.isSpeedKitResponse(text)) {
67
69
  text = this.rewriteHtmlToLocalConfig(text);
68
70
  }
69
- return new origin_response_1.OriginResponse(text, event.responseHeaders, event.responseStatusCode);
71
+ const headers = this.removeContentSecurityPolicy
72
+ ? this.removeContentSecurityHeaderFromResponse(event.responseHeaders)
73
+ : event.responseHeaders;
74
+ const content = this.removeContentSecurityPolicy
75
+ ? this.removeContentSecurityMetaTag(text)
76
+ : text;
77
+ return new origin_response_1.OriginResponse(content, headers, event.responseStatusCode);
70
78
  }
71
79
  isValidHtmlContent(text) {
72
80
  return text.includes("<html");
@@ -116,5 +124,25 @@ class CustomerDomainDocumentResponse {
116
124
  html = html.replaceAll(DF_STYLES_PATTERN, (_, tag, end) => `${tag}${this.configDynamicStyles.getContent()}${end}`);
117
125
  return html;
118
126
  }
127
+ /**
128
+ * Removes content policy headers from the given array of headers.
129
+ *
130
+ * @param {Protocol.Fetch.HeaderEntry[]} headers - The array of header entries.
131
+ * @returns {Protocol.Fetch.HeaderEntry[]} - The modified array of header entries with content policy headers removed.
132
+ */
133
+ removeContentSecurityHeaderFromResponse(headers) {
134
+ return headers.filter((header) => {
135
+ return !header.name.toLowerCase().includes("content-security-policy");
136
+ });
137
+ }
138
+ /**
139
+ * Removes the content security meta tag from the provided HTML content.
140
+ *
141
+ * @param {string} htmlContent - The HTML content from which to remove the meta tag.
142
+ * @returns {string} - The HTML content without the content security meta tag.
143
+ */
144
+ removeContentSecurityMetaTag(htmlContent) {
145
+ return htmlContent.replace(/<meta[^>]*http-equiv=["']content-security-policy[^>]*>/is, "");
146
+ }
119
147
  }
120
148
  exports.CustomerDomainDocumentResponse = CustomerDomainDocumentResponse;
@@ -2,6 +2,7 @@ import { CDPSession } from "puppeteer";
2
2
  import { Protocol } from "puppeteer-core";
3
3
  import { UserCliConfig } from "../../helpers/cli-config";
4
4
  import { AbortResponse } from "./browser/abort-response";
5
+ import { FlagInput } from "@oclif/core/lib/interfaces/parser";
5
6
  export declare class BrowserContext {
6
7
  readonly domain: string;
7
8
  readonly chromeFlags?: string[];
@@ -20,17 +21,14 @@ export declare class OnboardingContext {
20
21
  readonly configName: string;
21
22
  readonly local: boolean;
22
23
  readonly verboseLevel?: boolean;
24
+ readonly ignoreContentSecurityPolicy: boolean;
25
+ static flags: FlagInput;
23
26
  readonly DEFAULT_DF_PATH = "https://www.baqend.com/speed-kit/latest/dynamic-fetcher.js";
24
27
  readonly DEFAULT_DOCUMENT_HANDLER_PATH = "https://www.baqend.com/speed-kit-handler/latest/DocumentHandler.js";
25
28
  readonly DEFAULT_SNIPPET_PATH = "https://www.baqend.com/speed-kit/latest/snippet.js";
26
29
  readonly DEFAULT_SW_PATH = "https://www.baqend.com/speed-kit/latest/sw.js";
27
- constructor(customerPath: string, configName: string, local: boolean, verboseLevel?: boolean);
30
+ constructor(customerPath: string, configName: string, local: boolean, verboseLevel?: boolean, ignoreContentSecurityPolicy?: boolean);
28
31
  }
29
- export type awsCredentials = {
30
- accessKeyId: string;
31
- region: string;
32
- secretAccessKey: string;
33
- };
34
32
  export type SpeedKitServerConfigAuthentication = {
35
33
  password: string;
36
34
  type: "basic";
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OnboardingContext = exports.BrowserContext = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ const cli_parameters_1 = require("../../models/cli-parameters");
4
6
  const DEFAULT_BROWSER_ARGS = [
5
7
  "--enable-features=NetworkService",
6
8
  "--no-first-run",
@@ -40,15 +42,35 @@ class OnboardingContext {
40
42
  configName;
41
43
  local;
42
44
  verboseLevel;
45
+ ignoreContentSecurityPolicy;
46
+ static flags = {
47
+ ...cli_parameters_1.CLI_CONFIG_NAME,
48
+ local: core_1.Flags.boolean({
49
+ char: "l",
50
+ default: false,
51
+ description: "Run with local documentHandler",
52
+ }),
53
+ verboseLevel: core_1.Flags.boolean({
54
+ char: "v",
55
+ default: false,
56
+ description: "Show all messages",
57
+ }),
58
+ ignoreContentSecurityPolicy: core_1.Flags.boolean({
59
+ char: "s",
60
+ default: false,
61
+ description: `Removes header/meta "content-security-policy" for origin-responses`,
62
+ }),
63
+ };
43
64
  DEFAULT_DF_PATH = "https://www.baqend.com/speed-kit/latest/dynamic-fetcher.js";
44
65
  DEFAULT_DOCUMENT_HANDLER_PATH = "https://www.baqend.com/speed-kit-handler/latest/DocumentHandler.js";
45
66
  DEFAULT_SNIPPET_PATH = "https://www.baqend.com/speed-kit/latest/snippet.js";
46
67
  DEFAULT_SW_PATH = "https://www.baqend.com/speed-kit/latest/sw.js";
47
- constructor(customerPath, configName, local, verboseLevel) {
68
+ constructor(customerPath, configName, local, verboseLevel, ignoreContentSecurityPolicy = false) {
48
69
  this.customerPath = customerPath;
49
70
  this.configName = configName;
50
71
  this.local = local;
51
72
  this.verboseLevel = verboseLevel;
73
+ this.ignoreContentSecurityPolicy = ignoreContentSecurityPolicy;
52
74
  }
53
75
  }
54
76
  exports.OnboardingContext = OnboardingContext;
@@ -97,7 +97,7 @@ class OnboardingServiceFactory {
97
97
  const DiffService = new diff_1.DiffServiceFactory(new diff_1.DiffContext(this.cliConfig.diffExec, this.cliConfig.diffExecTemplate)).getService();
98
98
  const requestDiffService = new request_diff_service_1.RequestDiffService(DiffService, documentHandler);
99
99
  const handlers = [
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)),
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), this.context.ignoreContentSecurityPolicy),
101
101
  new speed_kit_install_html_1.SpeedKitInstallHtml(customerConfig, browserContext, new install_speed_kit_html_template_1.InstallSpeedKitHtmlTemplate()),
102
102
  new speed_kit_install_js_1.SpeedKitInstallJs(customerConfig, files.getByName(files_1.INTEGRATION_FILES.BUILD.INSTALL)),
103
103
  new customer_service_worker_js_1.CustomerServiceWorkerJs(customerConfig),
@@ -459,6 +459,13 @@
459
459
  "name": "verboseLevel",
460
460
  "allowNo": false,
461
461
  "type": "boolean"
462
+ },
463
+ "ignoreContentSecurityPolicy": {
464
+ "char": "s",
465
+ "description": "Removes header/meta \"content-security-policy\" for origin-responses",
466
+ "name": "ignoreContentSecurityPolicy",
467
+ "allowNo": false,
468
+ "type": "boolean"
462
469
  }
463
470
  },
464
471
  "hasDynamicHelp": false,
@@ -660,5 +667,5 @@
660
667
  ]
661
668
  }
662
669
  },
663
- "version": "2.24.0"
670
+ "version": "2.25.0"
664
671
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "2.24.0",
4
+ "version": "2.25.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"