@speedkit/cli 2.95.0 → 3.0.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 (67) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +10 -7
  3. package/dist/commands/build-parameter-query.d.ts +0 -1
  4. package/dist/commands/build-parameter-query.js +9 -76
  5. package/dist/commands/build-prewarm-query.d.ts +0 -1
  6. package/dist/commands/build-prewarm-query.js +9 -48
  7. package/dist/commands/deploy.d.ts +3 -6
  8. package/dist/commands/deploy.js +3 -17
  9. package/dist/commands/onboarding.js +2 -2
  10. package/dist/helpers/array-helper.d.ts +1 -0
  11. package/dist/helpers/array-helper.js +9 -0
  12. package/dist/helpers/customer-config.d.ts +0 -1
  13. package/dist/helpers/customer-config.js +0 -2
  14. package/dist/models/cli-parameters.d.ts +7 -2
  15. package/dist/models/cli-parameters.js +12 -1
  16. package/dist/services/customer-config/customer-config-service-model.d.ts +0 -1
  17. package/dist/services/customer-config/customer-config-service.js +2 -8
  18. package/dist/services/customer-config/templates/config_customer.json.hbs +56 -0
  19. package/dist/services/deploy/context/deploy-context.d.ts +4 -2
  20. package/dist/services/deploy/context/deploy-context.js +28 -3
  21. package/dist/services/deploy/deploy-service-factory.js +2 -6
  22. package/dist/services/deploy/handler/customer-config-handler.d.ts +0 -1
  23. package/dist/services/deploy/handler/customer-config-handler.js +3 -8
  24. package/dist/services/deploy/handler/install-resource-handler.js +2 -2
  25. package/dist/services/deploy/handler/module-handler.js +2 -2
  26. package/dist/services/deploy/handler/server-config-handler.js +2 -2
  27. package/dist/services/diff/diff-service.d.ts +1 -1
  28. package/dist/services/diff/diff-service.js +1 -1
  29. package/dist/services/integration-api/error/invalid-config-format-error.d.ts +4 -0
  30. package/dist/services/integration-api/error/invalid-config-format-error.js +15 -0
  31. package/dist/services/integration-api/file-reader.d.ts +1 -0
  32. package/dist/services/integration-api/file-reader.js +4 -0
  33. package/dist/services/integration-api/handler/customer-config-handler.d.ts +2 -1
  34. package/dist/services/integration-api/handler/customer-config-handler.js +42 -25
  35. package/dist/services/integration-api/integration-api-factory.js +3 -3
  36. package/dist/services/integration-api/integration-api-model.d.ts +4 -2
  37. package/dist/services/integration-api/integration-api-model.js +6 -4
  38. package/dist/services/integration-api/spec/customer-config-validator.spec.js +1 -1
  39. package/dist/services/integration-api/spec/file-list.spec.js +2 -2
  40. package/dist/services/integration-api/spec/file-reader.spec.js +17 -3
  41. package/dist/services/integration-api/spec/integration-api-service.spec.js +15 -1
  42. package/dist/services/integration-api/struct/customer-config-file.d.ts +1 -0
  43. package/dist/services/integration-api/struct/customer-config-file.js +24 -12
  44. package/dist/services/integration-api/struct/customer-config.d.ts +5 -1
  45. package/dist/services/integration-api/validator/customer-config-validator.js +1 -1
  46. package/dist/services/onboarding/onboarding-model.d.ts +2 -1
  47. package/dist/services/onboarding/onboarding-model.js +4 -1
  48. package/dist/services/onboarding/onboarding-service-factory.js +1 -1
  49. package/dist/services/pull/pull-service.d.ts +1 -0
  50. package/dist/services/pull/pull-service.js +13 -0
  51. package/dist/services/query-builder/error/parse-config-speed-kit-error.d.ts +4 -0
  52. package/dist/services/query-builder/error/parse-config-speed-kit-error.js +11 -0
  53. package/dist/services/query-builder/query/parameter.d.ts +4 -0
  54. package/dist/services/query-builder/query/parameter.js +49 -0
  55. package/dist/services/query-builder/query/prewarm.d.ts +4 -0
  56. package/dist/services/query-builder/query/prewarm.js +23 -0
  57. package/dist/services/query-builder/query-builder-factory.d.ts +11 -0
  58. package/dist/services/query-builder/query-builder-factory.js +48 -0
  59. package/dist/services/query-builder/query-builder-model.d.ts +20 -0
  60. package/dist/services/query-builder/query-builder-model.js +8 -0
  61. package/dist/services/query-builder/query-builder-service.d.ts +10 -0
  62. package/dist/services/query-builder/query-builder-service.js +48 -0
  63. package/oclif.manifest.json +36 -16
  64. package/package.json +1 -1
  65. package/dist/services/customer-config/templates/config_customer.js.hbs +0 -62
  66. package/dist/services/deploy/handler/module-modifier/deployment-detection-modifier.d.ts +0 -9
  67. package/dist/services/deploy/handler/module-modifier/deployment-detection-modifier.js +0 -24
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParseConfigSpeedKitError = void 0;
4
+ const config_file_error_1 = require("../../error-handling/error/config-file-error");
5
+ class ParseConfigSpeedKitError extends config_file_error_1.ConfigFileError {
6
+ constructor(message) {
7
+ super(message);
8
+ this.suggestions = ["please check file config_SpeedKit"];
9
+ }
10
+ }
11
+ exports.ParseConfigSpeedKitError = ParseConfigSpeedKitError;
@@ -0,0 +1,4 @@
1
+ export declare class Parameter {
2
+ readonly query: string;
3
+ constructor(app: string, parameterFilter: string, whitelistedFilter: string, blacklistedFilter: string, parameterReplaceFilter: string);
4
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Parameter = void 0;
4
+ class Parameter {
5
+ query;
6
+ constructor(app, parameterFilter, whitelistedFilter, blacklistedFilter, parameterReplaceFilter) {
7
+ const nowMinusOneMonth = new Date(new Date().setMonth(new Date().getMonth() - 1, new Date().getDate()));
8
+ const monthString = `${nowMinusOneMonth.getMonth() + 1 < 10 ? "0" : ""}${nowMinusOneMonth.getMonth() + 1}`;
9
+ const dateString = `${nowMinusOneMonth.getDate() < 10 ? "0" : ""}${nowMinusOneMonth.getDate()}`;
10
+ const date = `${nowMinusOneMonth.getFullYear()}-${monthString}-${dateString}`;
11
+ this.query = `
12
+ with urlWithParams as (
13
+ select
14
+ url,
15
+ createdat,
16
+ split(url, '?')[1] as urlWithoutParams,
17
+ filter (
18
+ transform(
19
+ split(split(url, '?')[2], '&'),
20
+ (pair) -> split(pair, '=')[1]
21
+ ),
22
+ (key) -> ${parameterFilter}
23
+ ) as paramKeys
24
+ from live.rum.pi
25
+ where app = '${app}'
26
+ and date >= '${date}'
27
+ and cardinality(split(url, '?')) > 1
28
+ and (${whitelistedFilter})
29
+ and ${blacklistedFilter}
30
+ ), prepared as (
31
+ select count(*) as PIs,
32
+ count(distinct url) as urls,
33
+ count(distinct ${parameterReplaceFilter}) as cachedUrls,
34
+ count(distinct urlWithoutParams) as uniqueWithoutParam,
35
+ paramKeys,
36
+ element_at(array_distinct(max_by(url, MD5(to_utf8(to_iso8601(createdat))), 500)), 1) as example1,
37
+ element_at(array_distinct(max_by(url, MD5(to_utf8(to_iso8601(createdat))), 500)), 2) as example2,
38
+ element_at(array_distinct(max_by(url, MD5(to_utf8(to_iso8601(createdat))), 500)), 3) as example3
39
+ from urlWithParams
40
+ group by paramKeys
41
+ )
42
+
43
+ select paramKeys, cachedUrls - uniqueWithoutParam as potentialGain, cachedUrls, PIs, example1, example2, example3
44
+ from prepared
45
+ where cardinality(paramKeys) > 0
46
+ order by potentialGain desc, cachedUrls desc, PIs desc`;
47
+ }
48
+ }
49
+ exports.Parameter = Parameter;
@@ -0,0 +1,4 @@
1
+ export declare class Prewarm {
2
+ readonly query: string;
3
+ constructor(app: string, whitelistedFilter: string, blacklistedFilter: string, parameterReplaceFilter: string);
4
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Prewarm = void 0;
4
+ class Prewarm {
5
+ query;
6
+ constructor(app, whitelistedFilter, blacklistedFilter, parameterReplaceFilter) {
7
+ const now = new Date();
8
+ now.setDate(now.getDate() - 10);
9
+ const date = now.toISOString().split("T")[0];
10
+ this.query = `
11
+ select url
12
+ from (
13
+ select regexp_replace(regexp_replace(${parameterReplaceFilter}, '(^[^&?]*)&','$1?'), '\\?$','') as url
14
+ from live.rum.pi
15
+ where app = '${app}'
16
+ and date >= '${date}'
17
+ and ${whitelistedFilter}
18
+ and ${blacklistedFilter})
19
+ group by url
20
+ order by count(*) desc`;
21
+ }
22
+ }
23
+ exports.Prewarm = Prewarm;
@@ -0,0 +1,11 @@
1
+ import { QueryBuilderService } from "./query-builder-service";
2
+ import { QueryBuilderFactoryContext, QueryTpe } from "./query-builder-model";
3
+ import { UserCliConfig } from "../../helpers/cli-config";
4
+ export declare class QueryBuilderFactory {
5
+ private context;
6
+ private userConfig;
7
+ constructor(context: QueryBuilderFactoryContext, userConfig: UserCliConfig);
8
+ buildService(queryType: QueryTpe): Promise<QueryBuilderService>;
9
+ private getIntegrationFiles;
10
+ private getSpeedKitConfig;
11
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryBuilderFactory = void 0;
4
+ const query_builder_service_1 = require("./query-builder-service");
5
+ const integration_api_1 = require("../integration-api");
6
+ const files_1 = require("../../models/files");
7
+ const get_parsed_config_1 = require("../../helpers/get-parsed-config");
8
+ const cli_1 = require("../cli");
9
+ const safe_1 = require("../../helpers/safe");
10
+ const parse_config_speed_kit_error_1 = require("./error/parse-config-speed-kit-error");
11
+ class QueryBuilderFactory {
12
+ context;
13
+ userConfig;
14
+ constructor(context, userConfig) {
15
+ this.context = context;
16
+ this.userConfig = userConfig;
17
+ }
18
+ async buildService(queryType) {
19
+ const cli = new cli_1.CliServiceFactory().getService();
20
+ const files = await this.getIntegrationFiles();
21
+ const app = files.getCustomerConfig().config.app;
22
+ const speedKitConfigFile = files.getByName(files_1.INTEGRATION_FILES.CONFIG.SPEED_KIT);
23
+ const speedKitConfig = this.getSpeedKitConfig(speedKitConfigFile.getContent());
24
+ const serviceContext = {
25
+ app,
26
+ queryType,
27
+ isWindows: this.context.isWindows,
28
+ };
29
+ return new query_builder_service_1.QueryBuilderService(serviceContext, speedKitConfig, cli);
30
+ }
31
+ async getIntegrationFiles() {
32
+ const integrationApiContext = new integration_api_1.IntegrationApiContext(this.context.customerPath, this.context.configName, ["config_SpeedKit"]);
33
+ const integrationApi = new integration_api_1.IntegrationApiFactory(integrationApiContext, this.userConfig).buildService();
34
+ return await integrationApi.run();
35
+ }
36
+ // todo create a customService to exchange parseSpeedKitConfig()
37
+ // this service then can also be used in: deploy/checks/pre-deploy
38
+ getSpeedKitConfig(fileContentString) {
39
+ const result = (0, safe_1.safe)(() => {
40
+ return (0, get_parsed_config_1.parseSpeedKitConfig)(fileContentString);
41
+ });
42
+ if (result.success !== true) {
43
+ throw new parse_config_speed_kit_error_1.ParseConfigSpeedKitError(result.error);
44
+ }
45
+ return result.data;
46
+ }
47
+ }
48
+ exports.QueryBuilderFactory = QueryBuilderFactory;
@@ -0,0 +1,20 @@
1
+ export type QueryBuilderContext = {
2
+ isWindows?: boolean;
3
+ queryType: QueryTpe;
4
+ app: string;
5
+ };
6
+ export type QueryBuilderFactoryContext = {
7
+ readonly customerPath: string;
8
+ readonly configName: string;
9
+ readonly isWindows?: boolean;
10
+ };
11
+ export declare enum QueryTpe {
12
+ prewarm = "prewarm",
13
+ parameter = "parameter"
14
+ }
15
+ export type SpeedKitConfig = {
16
+ ruleSetConfig?: {
17
+ version?: string;
18
+ };
19
+ [key: string]: any;
20
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryTpe = void 0;
4
+ var QueryTpe;
5
+ (function (QueryTpe) {
6
+ QueryTpe["prewarm"] = "prewarm";
7
+ QueryTpe["parameter"] = "parameter";
8
+ })(QueryTpe || (exports.QueryTpe = QueryTpe = {}));
@@ -0,0 +1,10 @@
1
+ import { QueryBuilderContext, SpeedKitConfig } from "./query-builder-model";
2
+ import { CliServiceInterface } from "../cli";
3
+ export declare class QueryBuilderService {
4
+ private context;
5
+ private speedKitConfig;
6
+ private cli;
7
+ constructor(context: QueryBuilderContext, speedKitConfig: SpeedKitConfig, cli: CliServiceInterface);
8
+ run(): Promise<void>;
9
+ private buildQuery;
10
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryBuilderService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const get_parsed_config_1 = require("../../helpers/get-parsed-config");
6
+ const build_query_helper_1 = require("../../helpers/build-query-helper");
7
+ const clipboardy_cjs_1 = tslib_1.__importDefault(require("clipboardy-cjs"));
8
+ const query_builder_model_1 = require("./query-builder-model");
9
+ const prewarm_1 = require("./query/prewarm");
10
+ const parameter_1 = require("./query/parameter");
11
+ const cli_1 = require("../cli");
12
+ class QueryBuilderService {
13
+ context;
14
+ speedKitConfig;
15
+ cli;
16
+ constructor(context, speedKitConfig, cli) {
17
+ this.context = context;
18
+ this.speedKitConfig = speedKitConfig;
19
+ this.cli = cli;
20
+ }
21
+ async run() {
22
+ this.cli.startAction(`build ${this.context.queryType}-query`);
23
+ const parameters = (0, build_query_helper_1.getStrippedParameters)(this.speedKitConfig);
24
+ const parameterReplaceFilter = (0, build_query_helper_1.getParameterReplaceFilter)(parameters, (0, get_parsed_config_1.getSpeedKitConfigVersion)(this.speedKitConfig));
25
+ const whitelistedFilter = (0, build_query_helper_1.getWhitelistedFilter)(this.speedKitConfig);
26
+ const blacklistedFilter = (0, build_query_helper_1.getBlacklistedFilter)(this.speedKitConfig);
27
+ const skConfigVersion = (0, get_parsed_config_1.getSpeedKitConfigVersion)(this.speedKitConfig);
28
+ const parameterFilter = (0, build_query_helper_1.getParameterFilter)(parameters, skConfigVersion);
29
+ const result = this.buildQuery(this.context.app, parameterFilter, whitelistedFilter, blacklistedFilter, parameterReplaceFilter);
30
+ this.cli.endAction(cli_1.CliActionStatus.COMPLETED);
31
+ if (!this.context.isWindows) {
32
+ clipboardy_cjs_1.default.writeSync(result);
33
+ }
34
+ this.cli.write(this.cli.style.dim.italic(result));
35
+ if (!this.context.isWindows) {
36
+ this.cli.writeSuccess("Result has been copied to the clipboard 📋");
37
+ }
38
+ }
39
+ buildQuery(app, parameterFilter, whitelistedFilter, blacklistedFilter, parameterReplaceFilter) {
40
+ if (this.context.queryType === query_builder_model_1.QueryTpe.prewarm) {
41
+ return new prewarm_1.Prewarm(app, whitelistedFilter, blacklistedFilter, parameterReplaceFilter).query;
42
+ }
43
+ if (this.context.queryType === query_builder_model_1.QueryTpe.parameter) {
44
+ return new parameter_1.Parameter(app, parameterFilter, whitelistedFilter, blacklistedFilter, parameterReplaceFilter).query;
45
+ }
46
+ }
47
+ }
48
+ exports.QueryBuilderService = QueryBuilderService;
@@ -107,28 +107,41 @@
107
107
  "multiple": false,
108
108
  "type": "option"
109
109
  },
110
- "artifacts": {
111
- "char": "a",
112
- "description": "Whitelist of files to deploy",
113
- "name": "artifacts",
110
+ "useTestConfig": {
111
+ "char": "t",
112
+ "description": "Override app with configured testApp",
113
+ "name": "useTestConfig",
114
+ "allowNo": false,
115
+ "type": "boolean"
116
+ },
117
+ "domain": {
118
+ "char": "d",
119
+ "description": "Startup domain (optional)",
120
+ "name": "domain",
114
121
  "hasDynamicHelp": false,
115
122
  "multiple": false,
116
123
  "type": "option"
117
124
  },
118
- "dryRun": {
119
- "char": "d",
120
- "description": "Do not deploy changes",
121
- "name": "dryRun",
125
+ "local": {
126
+ "char": "l",
127
+ "description": "Run with local documentHandler",
128
+ "name": "local",
122
129
  "allowNo": false,
123
130
  "type": "boolean"
124
131
  },
125
- "slackToken": {
126
- "char": "t",
127
- "description": "Slack hook found on 1Pass",
128
- "name": "slackToken",
129
- "hasDynamicHelp": false,
130
- "multiple": false,
131
- "type": "option"
132
+ "verboseLevel": {
133
+ "char": "v",
134
+ "description": "Show all messages",
135
+ "name": "verboseLevel",
136
+ "allowNo": false,
137
+ "type": "boolean"
138
+ },
139
+ "ignoreContentSecurityPolicy": {
140
+ "char": "s",
141
+ "description": "Removes header/meta \"content-security-policy\" for origin-responses",
142
+ "name": "ignoreContentSecurityPolicy",
143
+ "allowNo": false,
144
+ "type": "boolean"
132
145
  }
133
146
  },
134
147
  "hasDynamicHelp": false,
@@ -458,6 +471,13 @@
458
471
  "multiple": false,
459
472
  "type": "option"
460
473
  },
474
+ "useTestConfig": {
475
+ "char": "t",
476
+ "description": "Override app with configured testApp",
477
+ "name": "useTestConfig",
478
+ "allowNo": false,
479
+ "type": "boolean"
480
+ },
461
481
  "domain": {
462
482
  "char": "d",
463
483
  "description": "Startup domain (optional)",
@@ -712,5 +732,5 @@
712
732
  ]
713
733
  }
714
734
  },
715
- "version": "2.95.0"
735
+ "version": "3.0.0"
716
736
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "2.95.0",
4
+ "version": "3.0.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"
@@ -1,62 +0,0 @@
1
- /**
2
- * Shop/Frontend system in use:
3
- {{#if isShopify}}
4
- * - Shopify
5
- {{else if isShopware}}
6
- * - Shopware
7
- {{else if isSalesforce}}
8
- * - Salesforce Commerce Cloud
9
- {{else if isOxid}}
10
- * - OXID eShop
11
- {{else if isPlentymarkets}}
12
- * - Plentymarkets
13
- {{else}}
14
- * - TODO: enter name of system in use
15
- {{/if}}
16
- */
17
-
18
- const shared = {
19
- app: "{{appName}}",
20
- domain: "{{production.host}}",
21
- origins: [
22
- "https://{{production.host}}",
23
- ],
24
- {{#if isShopify}}
25
- shopifyId: "{{shopifyId}}", // Shopify specific
26
- swPath: "/apps/speed-kit/sw.js", // Shopify specific
27
- {{else}}
28
- swPath: "/wrapper-sw.js",
29
- {{/if}}
30
- {{#if subRouteScope}}
31
- scope: "/{{subRouteScope}}/",
32
- {{else}}
33
- scope: "/",
34
- {{/if}}
35
- };
36
-
37
- module.exports = {
38
- test: {
39
- ...shared,
40
- app: process.env.TEST_APP,
41
- name: shared.app,
42
- forceInstall: true,
43
- },
44
- {{#if staging.host}}
45
- staging: {
46
- ...shared,
47
- name: "staging",
48
- domain: "{{staging.host}}",
49
- origins: [
50
- "https://{{staging.host}}",
51
- ],
52
- forceInstall: {{staging.forceInstall}}, // use when our setup is not present yet
53
- // bypassDeactivation: false, // comment out when SK deactivation should not be bypassed
54
- },
55
- {{/if}}
56
- production: {
57
- ...shared,
58
- name: "production",
59
- forceInstall: {{production.forceInstall}}, // use when our setup is not present yet
60
- // bypassDeactivation: false, // comment out when SK deactivation should not be bypassed
61
- },
62
- };
@@ -1,9 +0,0 @@
1
- import RuntimeModifier from "../../interface/runtime-modifier";
2
- import { ModuleInterface } from "../../../integration-api/integration-api-model";
3
- export default class DeploymentDetectionModifier implements RuntimeModifier {
4
- private readonly slackToken;
5
- constructor(slackToken?: string);
6
- canModify(file: ModuleInterface): boolean;
7
- modify(file: ModuleInterface): void;
8
- revert(file: ModuleInterface): void;
9
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const FILE = "deploymentDetection";
4
- const SLACK_TOKEN_PLACEHOLDER = "<1Password deployment token>";
5
- class DeploymentDetectionModifier {
6
- slackToken;
7
- constructor(slackToken) {
8
- this.slackToken = slackToken;
9
- }
10
- canModify(file) {
11
- return file.name === FILE;
12
- }
13
- modify(file) {
14
- if (this.slackToken) {
15
- file.setContent(file.getContent().replace(SLACK_TOKEN_PLACEHOLDER, this.slackToken));
16
- }
17
- }
18
- revert(file) {
19
- if (this.slackToken) {
20
- file.setContent(file.getContent().replace(this.slackToken, SLACK_TOKEN_PLACEHOLDER));
21
- }
22
- }
23
- }
24
- exports.default = DeploymentDetectionModifier;