@speedkit/cli 4.43.0-beta.1 → 4.43.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 (109) hide show
  1. package/CHANGELOG.md +9 -2
  2. package/README.md +12 -2
  3. package/dist/commands/onboarding.d.ts +3 -0
  4. package/dist/commands/onboarding.js +7 -1
  5. package/dist/models/files.d.ts +0 -1
  6. package/dist/models/files.js +0 -1
  7. package/dist/services/bundler/bundle-service-factory.d.ts +1 -6
  8. package/dist/services/bundler/bundle-service-factory.js +2 -9
  9. package/dist/services/bundler/bundle-service.d.ts +1 -10
  10. package/dist/services/bundler/bundle-service.js +1 -16
  11. package/dist/services/bundler/index.d.ts +0 -1
  12. package/dist/services/bundler/index.js +0 -1
  13. package/dist/services/cli/cli-environment.js +0 -1
  14. package/dist/services/cli/cli-settings.d.ts +0 -5
  15. package/dist/services/cli/cli-settings.js +0 -1
  16. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  17. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.d.ts +2 -2
  18. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.js +8 -7
  19. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.d.ts +2 -2
  20. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +11 -7
  21. package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +2 -2
  22. package/dist/services/deploy/checks/post-deploy/save-files-check.js +3 -2
  23. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
  24. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
  25. package/dist/services/deploy/deploy-service-factory.js +1 -3
  26. package/dist/services/deploy/deploy-service-model.d.ts +11 -1
  27. package/dist/services/deploy/deploy-service.d.ts +2 -0
  28. package/dist/services/deploy/deploy-service.js +26 -1
  29. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +1 -1
  30. package/dist/services/deploy/policy/deploy-policy-model.d.ts +1 -5
  31. package/dist/services/deploy/policy/deploy-policy-model.js +0 -4
  32. package/dist/services/deploy/spec/checks/post-deploy/refresh-deployment-job-check.spec.js +5 -12
  33. package/dist/services/deploy/spec/deploy-service.spec.js +64 -0
  34. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +0 -2
  35. package/dist/services/document-handler-runtime/document-handler-runtime-model.d.ts +0 -2
  36. package/dist/services/document-handler-runtime/document-handler-runtime-model.js +0 -2
  37. package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
  38. package/dist/services/document-handler-runtime/document-handler-server.js +20 -82
  39. package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +1 -1
  40. package/dist/services/integration-api/integration-api-factory.js +1 -1
  41. package/dist/services/integration-api/integration-api-model.d.ts +1 -2
  42. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -70
  43. package/dist/services/integration-api/struct/customer-config.d.ts +1 -19
  44. package/dist/services/integration-api/struct/customer-config.js +3 -11
  45. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
  46. package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -30
  47. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -24
  48. package/dist/services/onboarding/error/inject-installation-error.d.ts +6 -0
  49. package/dist/services/onboarding/error/inject-installation-error.js +11 -0
  50. package/dist/services/onboarding/error/inject-target-error.d.ts +6 -0
  51. package/dist/services/onboarding/error/inject-target-error.js +11 -0
  52. package/dist/services/onboarding/error/missing-customer-path-error.d.ts +1 -1
  53. package/dist/services/onboarding/error/missing-customer-path-error.js +2 -1
  54. package/dist/services/onboarding/fetch-events/customer-domain-document-response.d.ts +4 -14
  55. package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +6 -45
  56. package/dist/services/onboarding/fetch-events/document-rewrite.d.ts +19 -0
  57. package/dist/services/onboarding/fetch-events/document-rewrite.js +47 -0
  58. package/dist/services/onboarding/fetch-events/speed-kit-install-html.d.ts +5 -1
  59. package/dist/services/onboarding/fetch-events/speed-kit-install-html.js +7 -2
  60. package/dist/services/onboarding/html-rewrites.d.ts +3 -3
  61. package/dist/services/onboarding/html-rewrites.js +3 -3
  62. package/dist/services/onboarding/index.d.ts +1 -1
  63. package/dist/services/onboarding/index.js +1 -1
  64. package/dist/services/onboarding/inject/content-security-policy.d.ts +14 -0
  65. package/dist/services/onboarding/inject/content-security-policy.js +54 -0
  66. package/dist/services/onboarding/inject/deployed-installation.d.ts +15 -0
  67. package/dist/services/onboarding/inject/deployed-installation.js +32 -0
  68. package/dist/services/onboarding/inject/foreign-install-request.d.ts +27 -0
  69. package/dist/services/onboarding/inject/foreign-install-request.js +50 -0
  70. package/dist/services/onboarding/inject/inject-document-rewrite.d.ts +23 -0
  71. package/dist/services/onboarding/inject/inject-document-rewrite.js +52 -0
  72. package/dist/services/onboarding/inject/inject-service.d.ts +32 -0
  73. package/dist/services/onboarding/inject/inject-service.js +72 -0
  74. package/dist/services/onboarding/inject/injected-installation.d.ts +29 -0
  75. package/dist/services/onboarding/inject/injected-installation.js +37 -0
  76. package/dist/services/onboarding/onboarding-service-build-context.d.ts +15 -1
  77. package/dist/services/onboarding/onboarding-service-build-context.js +31 -2
  78. package/dist/services/onboarding/onboarding-service-factory.d.ts +23 -5
  79. package/dist/services/onboarding/onboarding-service-factory.js +87 -7
  80. package/dist/services/onboarding/spec/inject/content-security-policy.spec.d.ts +1 -0
  81. package/dist/services/onboarding/spec/inject/content-security-policy.spec.js +47 -0
  82. package/dist/services/onboarding/spec/inject/deployed-installation.spec.d.ts +1 -0
  83. package/dist/services/onboarding/spec/inject/deployed-installation.spec.js +49 -0
  84. package/dist/services/onboarding/spec/inject/foreign-install-request.spec.d.ts +1 -0
  85. package/dist/services/onboarding/spec/inject/foreign-install-request.spec.js +47 -0
  86. package/dist/services/onboarding/spec/inject/inject-document-rewrite.spec.d.ts +1 -0
  87. package/dist/services/onboarding/spec/inject/inject-document-rewrite.spec.js +66 -0
  88. package/dist/services/onboarding/spec/inject/injected-installation.spec.d.ts +1 -0
  89. package/dist/services/onboarding/spec/inject/injected-installation.spec.js +24 -0
  90. package/dist/services/onboarding/spec/onboarding-service-build-context.spec.d.ts +1 -0
  91. package/dist/services/onboarding/spec/onboarding-service-build-context.spec.js +22 -0
  92. package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +53 -2
  93. package/dist/services/onboarding/templates/install-speed-kit-html-template.js +3 -0
  94. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
  95. package/dist/services/query-builder/query-builder-factory.js +3 -3
  96. package/oclif.manifest.json +26 -3
  97. package/package.json +1 -2
  98. package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
  99. package/dist/services/bundler/error/packjockel-error.js +0 -3
  100. package/dist/services/bundler/packjockel-service.d.ts +0 -70
  101. package/dist/services/bundler/packjockel-service.js +0 -171
  102. package/dist/services/bundler/spec/packjockel-service.spec.js +0 -149
  103. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +0 -15
  104. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +0 -70
  105. package/dist/services/deploy/error/check-module-file-error.d.ts +0 -4
  106. package/dist/services/deploy/error/check-module-file-error.js +0 -4
  107. package/dist/services/deploy/error/post-deploy-deployment-detection-error.d.ts +0 -4
  108. package/dist/services/deploy/error/post-deploy-deployment-detection-error.js +0 -4
  109. /package/dist/services/{bundler/spec/packjockel-service.spec.d.ts → deploy/spec/deploy-service.spec.d.ts} +0 -0
@@ -0,0 +1,64 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import DeployService from "../deploy-service.js";
4
+ const fileList = {
5
+ filter: () => undefined,
6
+ getTypes: () => [],
7
+ getCustomerConfig: () => ({ config: { app: "app", name: "production" } }),
8
+ };
9
+ function recordingCli(warnings) {
10
+ return {
11
+ spacer: () => undefined,
12
+ write: () => undefined,
13
+ comment: () => undefined,
14
+ writeWarning: (message) => warnings.push(message),
15
+ };
16
+ }
17
+ function check(run) {
18
+ return { check: run };
19
+ }
20
+ function deploy(warnings, postDeployChecks) {
21
+ return new DeployService(fileList, [], recordingCli(warnings), [], postDeployChecks).run();
22
+ }
23
+ describe("DeployService", () => {
24
+ it("runs every post-deploy check and reports the failed ones after", async () => {
25
+ const warnings = [];
26
+ let laterCheckRan = false;
27
+ await deploy(warnings, [
28
+ check(async () => ({
29
+ success: false,
30
+ error: "Missing required jobs: HTML",
31
+ suggestions: ["create them", "or not"],
32
+ })),
33
+ check(async () => {
34
+ laterCheckRan = true;
35
+ return { success: true };
36
+ }),
37
+ ]);
38
+ expect(laterCheckRan).to.equal(true);
39
+ expect(warnings).to.deep.equal([
40
+ "1 post-deploy check(s) failed:",
41
+ "› Missing required jobs: HTML\n Try this:\n * create them\n * or not",
42
+ ]);
43
+ });
44
+ it("stays quiet when every post-deploy check passes", async () => {
45
+ const warnings = [];
46
+ await deploy(warnings, [check(async () => ({ success: true }))]);
47
+ expect(warnings).to.deep.equal([]);
48
+ });
49
+ it("lets an error thrown by a post-deploy check fail the deploy", async () => {
50
+ const failure = new Error("could not reach the app");
51
+ let laterCheckRan = false;
52
+ const error = await deploy([], [
53
+ check(async () => {
54
+ throw failure;
55
+ }),
56
+ check(async () => {
57
+ laterCheckRan = true;
58
+ return { success: true };
59
+ }),
60
+ ]).catch((e) => e);
61
+ expect(error).to.equal(failure);
62
+ expect(laterCheckRan).to.equal(false);
63
+ });
64
+ });
@@ -26,8 +26,6 @@ const NOT_IN_A_MERGE_REQUEST = [
26
26
  DeployQuestion.SplitChange,
27
27
  DeployQuestion.DeviceDetectionChange,
28
28
  DeployQuestion.SaveLocalFiles,
29
- DeployQuestion.DeleteDeprecatedJob,
30
- DeployQuestion.DeleteDeprecatedModule,
31
29
  ];
32
30
  function policy(approval) {
33
31
  return new AutoDeployPolicy("!42 a reviewed change", approval);
@@ -4,6 +4,4 @@ export declare const LOCAL_DYNAMIC_FETCHER = "custom_dynamicFetcher";
4
4
  export declare const LOCAL_DYNAMIC_FETCHER_CONFIG = "config_dynamicBlocks";
5
5
  export declare const LOCAL_STYLES = "config_dynamicStyles";
6
6
  export declare const LATEST_DYNAMIC_FETCHER_URL = "https://www.baqend.com/speed-kit/latest/dynamic-fetcher.js";
7
- /** Where the imports of the latest dynamic fetcher resolve. */
8
- export declare const DYNAMIC_FETCHER_BASE_PATH = "https://www.baqend.com/speed-kit/latest/";
9
7
  export declare const LOCAL_TRIGGERED_BY = "STREAM:QA";
@@ -4,8 +4,6 @@ export const LOCAL_DYNAMIC_FETCHER = "custom_dynamicFetcher";
4
4
  export const LOCAL_DYNAMIC_FETCHER_CONFIG = "config_dynamicBlocks";
5
5
  export const LOCAL_STYLES = "config_dynamicStyles";
6
6
  export const LATEST_DYNAMIC_FETCHER_URL = "https://www.baqend.com/speed-kit/latest/dynamic-fetcher.js";
7
- /** Where the imports of the latest dynamic fetcher resolve. */
8
- export const DYNAMIC_FETCHER_BASE_PATH = "https://www.baqend.com/speed-kit/latest/";
9
7
  // Local runs have no persistent cache, so an origin HTML is served straight to the developer and may
10
8
  // legitimately be older than the default five minutes. STREAM:QA relaxes the document handler's
11
9
  // Shopify staleness check to one hour, see ONE_HOUR_STALENESS_TRIGGERS in document-handler.
@@ -13,11 +13,6 @@ export declare class DocumentHandlerServer {
13
13
  private entityManager?;
14
14
  private documentHandlerCode;
15
15
  private documentHandlerConfigCode;
16
- /**
17
- * The packjockel bundle for a customer with the `configPlugins` feature: the handler, its config
18
- * and the Speed Kit config in one CommonJS module, which exports `post`.
19
- */
20
- private documentHandlerBundle?;
21
16
  private database;
22
17
  /** Sources of app modules already looked up; `null` marks a lookup that came back empty. */
23
18
  private readonly appModules;
@@ -27,23 +22,11 @@ export declare class DocumentHandlerServer {
27
22
  */
28
23
  constructor(customerConfig: CustomerConfig, files: FileListInterface, bundler: BundleService, cli: CliServiceInterface, workSpace: string, verboseLevel?: boolean, entityManager?: EntityManager);
29
24
  transform(contentType: string, html: string, variation: string, url: string, headers: Record<string, string>): Promise<DocumentHandlerResponse>;
30
- /** Runs the handler in the context, and returns the config, which calls its `post`. */
31
- private createScript;
32
- /** Loads the packjockel bundle like a CommonJS module, and calls the `post` it exports. */
33
- private createBundleScript;
34
- private getDocumentHandlerConfigPath;
35
25
  private getTransformFunctionWrapper;
36
26
  buildDocumentHandler(): Promise<void>;
37
- /**
38
- * Bundles the handler, its config and the Speed Kit config into one module, the way the server
39
- * deploys a customer with the `configPlugins` feature.
40
- */
41
- private bundleWithPackjockel;
42
27
  private deactivateReleaseAndDeploymentDetection;
43
28
  private getDocumentHandler;
44
29
  private getDynamicFetcher;
45
- /** The customer's own dynamic fetcher, or else the source of the latest one. */
46
- private getDynamicFetcherSource;
47
30
  private getDynamicFetcherConfig;
48
31
  private getStyles;
49
32
  private getDocumentHandlerConfig;
@@ -1,9 +1,7 @@
1
- import { DYNAMIC_FETCHER_BASE_PATH, LATEST_DYNAMIC_FETCHER_URL, LOCAL_DOCUMENT_HANDLER, LOCAL_DOCUMENT_HANDLER_CONFIG, LOCAL_DYNAMIC_FETCHER, LOCAL_DYNAMIC_FETCHER_CONFIG, LOCAL_STYLES, } from "./document-handler-runtime-model.js";
1
+ import { LATEST_DYNAMIC_FETCHER_URL, LOCAL_DOCUMENT_HANDLER, LOCAL_DOCUMENT_HANDLER_CONFIG, LOCAL_DYNAMIC_FETCHER, LOCAL_DYNAMIC_FETCHER_CONFIG, LOCAL_STYLES, } from "./document-handler-runtime-model.js";
2
2
  import RequiredFileNotFoundError from "./error/required-file-not-found-error.js";
3
3
  import DatabaseMock from "./templates/database-mock.js";
4
4
  import * as vm from "node:vm";
5
- import { speedKitConfigBasePath, } from "../bundler/index.js";
6
- import { usesConfigPlugins, } from "../integration-api/index.js";
7
5
  import { INTEGRATION_FILES } from "../../models/files.js";
8
6
  // documentHandlerDependencies
9
7
  import fetch from "node-fetch";
@@ -27,11 +25,6 @@ export class DocumentHandlerServer {
27
25
  entityManager;
28
26
  documentHandlerCode;
29
27
  documentHandlerConfigCode;
30
- /**
31
- * The packjockel bundle for a customer with the `configPlugins` feature: the handler, its config
32
- * and the Speed Kit config in one CommonJS module, which exports `post`.
33
- */
34
- documentHandlerBundle;
35
28
  database;
36
29
  /** Sources of app modules already looked up; `null` marks a lookup that came back empty. */
37
30
  appModules = new Map();
@@ -49,11 +42,7 @@ export class DocumentHandlerServer {
49
42
  this.entityManager = entityManager;
50
43
  }
51
44
  async transform(contentType, html, variation, url, headers) {
52
- const configPlugins = usesConfigPlugins(this.customerConfig);
53
- const built = configPlugins
54
- ? this.documentHandlerBundle
55
- : this.documentHandlerCode && this.documentHandlerConfigCode;
56
- if (!built) {
45
+ if (!this.documentHandlerCode || !this.documentHandlerConfigCode) {
57
46
  await this.buildDocumentHandler();
58
47
  }
59
48
  const skInternalRequest = new Request(url, html, variation, headers, {
@@ -68,21 +57,26 @@ export class DocumentHandlerServer {
68
57
  skInternalError: {},
69
58
  Abort: DocumentHandlerAbort,
70
59
  APP: this.customerConfig.app,
71
- // packjockel defines these in the bundle itself.
72
- ...(configPlugins
73
- ? {}
74
- : {
75
- DYNAMIC_FETCHER: await this.getDynamicFetcher(),
76
- DYNAMIC_FETCHER_CONFIG: await this.getDynamicFetcherConfig(),
77
- CUSTOM_STYLES: this.getStyles(),
78
- }),
60
+ DYNAMIC_FETCHER: await this.getDynamicFetcher(),
61
+ DYNAMIC_FETCHER_CONFIG: await this.getDynamicFetcherConfig(),
62
+ CUSTOM_STYLES: this.getStyles(),
79
63
  ...this.getContextVars(),
80
64
  ...this.createNodeVmContext(),
81
65
  skErrorContext: {},
82
66
  };
83
- const script = configPlugins
84
- ? this.createBundleScript()
85
- : this.createScript(vmContext);
67
+ const customDocumentHandlerFile = this.files.getByName(INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
68
+ if (customDocumentHandlerFile.path) {
69
+ vm.runInNewContext(this.documentHandlerCode, vmContext, {
70
+ filename: customDocumentHandlerFile.path,
71
+ displayErrors: true,
72
+ });
73
+ }
74
+ else {
75
+ vm.runInNewContext(this.documentHandlerCode, vmContext);
76
+ }
77
+ const script = new vm.Script(this.documentHandlerConfigCode + this.getTransformFunctionWrapper(), {
78
+ filename: this.files.getByName("config_documentHandler").path,
79
+ });
86
80
  const vmResponse = await safe(new Promise((resolve, reject) => {
87
81
  vmContext.skInternalResponse.resolve = resolve;
88
82
  // @ts-expect-error reject is unknown
@@ -98,66 +92,17 @@ export class DocumentHandlerServer {
98
92
  }
99
93
  throw new DocumentHandlerTransformError(vmResponse.errorObj);
100
94
  }
101
- /** Runs the handler in the context, and returns the config, which calls its `post`. */
102
- createScript(vmContext) {
103
- const customDocumentHandlerFile = this.files.getByName(INTEGRATION_FILES.CUSTOM.DOCUMENT_HANDLER);
104
- if (customDocumentHandlerFile.path) {
105
- vm.runInNewContext(this.documentHandlerCode, vmContext, {
106
- filename: customDocumentHandlerFile.path,
107
- displayErrors: true,
108
- });
109
- }
110
- else {
111
- vm.runInNewContext(this.documentHandlerCode, vmContext);
112
- }
113
- return new vm.Script(this.documentHandlerConfigCode + this.getTransformFunctionWrapper(), { filename: this.getDocumentHandlerConfigPath() });
114
- }
115
- /** Loads the packjockel bundle like a CommonJS module, and calls the `post` it exports. */
116
- createBundleScript() {
117
- return new vm.Script(`(function (module, exports) {\n${this.documentHandlerBundle}\n})(module, module.exports);\n\n` +
118
- `module.exports.post(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`, { filename: this.getDocumentHandlerConfigPath() });
119
- }
120
- getDocumentHandlerConfigPath() {
121
- return this.files.getByName("config_documentHandler")
122
- .path;
123
- }
124
95
  getTransformFunctionWrapper() {
125
96
  return `\n\npost(db, skInternalRequest, skInternalResponse).catch((error)=>reject(error));`;
126
97
  }
127
98
  async buildDocumentHandler() {
128
99
  this.cli.startAction("DOCUMENTHANDLER:BUILD", "rebuild documentHandler");
129
- if (usesConfigPlugins(this.customerConfig)) {
130
- this.documentHandlerBundle = await this.bundleWithPackjockel();
131
- this.cli.successAction("DOCUMENTHANDLER:BUILD");
132
- return;
133
- }
134
100
  this.documentHandlerCode = await this.bundleDocumentHandlerCode("custom_documentHandler.js", await this.getDocumentHandler());
135
101
  this.documentHandlerConfigCode = await this.bundleDocumentHandlerCode("config_documentHandler.js", this.deactivateReleaseAndDeploymentDetection());
136
102
  this.cli.successAction("DOCUMENTHANDLER:BUILD");
137
103
  }
138
- /**
139
- * Bundles the handler, its config and the Speed Kit config into one module, the way the server
140
- * deploys a customer with the `configPlugins` feature.
141
- */
142
- async bundleWithPackjockel() {
143
- return this.bundler.packjockel.bundleDocumentHandler({
144
- documentHandler: await this.getDocumentHandler(),
145
- documentHandlerConfig: this.deactivateReleaseAndDeploymentDetection(),
146
- speedKitConfig: this.files
147
- .getByName(INTEGRATION_FILES.CONFIG.SPEED_KIT)
148
- .getContent(),
149
- appName: this.customerConfig.app,
150
- dynamicFetcher: await this.getDynamicFetcherSource(),
151
- dynamicFetcherConfig: await this.getDynamicFetcherConfig(),
152
- customStyle: this.getStyles(),
153
- basePaths: {
154
- "speed-kit-config": speedKitConfigBasePath(this.customerConfig.configPluginsVersion),
155
- "dynamic-fetcher": DYNAMIC_FETCHER_BASE_PATH,
156
- },
157
- });
158
- }
159
104
  deactivateReleaseAndDeploymentDetection() {
160
- return this.getDocumentHandlerConfig().replace(/const documentHandler =|export default new /, (selected) => {
105
+ return this.getDocumentHandlerConfig().replace("const documentHandler =", (selected) => {
161
106
  return (`config["executeDeploymentDetection"] = false;config["executeReleaseDetection"] = false;\n` +
162
107
  selected);
163
108
  });
@@ -168,17 +113,10 @@ export class DocumentHandlerServer {
168
113
  .getContent();
169
114
  }
170
115
  async getDynamicFetcher() {
171
- if (!this.files.hasFile(LOCAL_DYNAMIC_FETCHER)) {
172
- return await this.bundleDynamicFetcher({ "dynamic-fetcher": DYNAMIC_FETCHER_BASE_PATH }, await this.getDynamicFetcherSource());
173
- }
174
- return this.getDynamicFetcherSource();
175
- }
176
- /** The customer's own dynamic fetcher, or else the source of the latest one. */
177
- async getDynamicFetcherSource() {
178
116
  // todo use fetchRemoteFile from integration api
179
117
  if (!this.files.hasFile(LOCAL_DYNAMIC_FETCHER)) {
180
118
  const response = await fetch(LATEST_DYNAMIC_FETCHER_URL);
181
- return await response.text();
119
+ return await this.bundleDynamicFetcher({ "dynamic-fetcher": "https://www.baqend.com/speed-kit/latest/" }, await response.text());
182
120
  }
183
121
  return this.files
184
122
  .getByName(INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
@@ -25,7 +25,7 @@ export default class DocumentHandlerRuntimeServiceFactory {
25
25
  const customerConfig = this.getCustomerConfig(files);
26
26
  const cliService = this.context.environment.cli;
27
27
  await this.installAdditionalDependencies(customerConfig, cliService);
28
- const bundler = new BundleServiceFactory(this.context.customerPath, this.context.environment.settings.packjockelPath).buildService();
28
+ const bundler = new BundleServiceFactory(this.context.customerPath).buildService();
29
29
  // the non-prompting lookup: the document handler runs with a session when
30
30
  // there is one and without when there is not, so it must not stop the
31
31
  // command at a login prompt to find out
@@ -30,7 +30,7 @@ export class IntegrationApiFactory {
30
30
  const virtualFileHandler = new VirtualFileHandler(cli);
31
31
  this.service = new IntegrationApiService(fileReader, virtualFileHandler, new MandatoryFilesValidator(), [
32
32
  new CustomerConfigHandler(fileReader, cli, new CustomerConfigValidator(), this.context.configName, this.context.environment.settings.testApp, this.context.useTestConfig ?? false),
33
- new InstallResourceHandler(fileReader, new BundleServiceFactory("./", this.context.environment.settings.packjockelPath).buildService()),
33
+ new InstallResourceHandler(fileReader, new BundleServiceFactory("./").buildService()),
34
34
  new ServerConfigHandler(fileReader),
35
35
  new ModuleHandler(fileReader),
36
36
  ], new FileWriter(fs, this.context.basePath), this.whitelist.length === 0);
@@ -13,7 +13,6 @@ export * from "./virtual/external-recipe.js";
13
13
  export * from "./virtual/static-recipe.js";
14
14
  export * from "./external/external-file-reader.js";
15
15
  import type { SpeedKitConfig } from "./struct/speed-kit-config.js";
16
- import type { SpeedKitConfigCustomer } from "./struct/speed-kit-config-file.js";
17
16
  import { CustomerConfig } from "./struct/customer-config.js";
18
17
  import { RoFile } from "./struct/ro-file.js";
19
18
  import { VirtualFile } from "./struct/virtual-file.js";
@@ -90,7 +89,7 @@ export interface InstallResourceInterface extends ConfigFileInterface, FileInter
90
89
  readonly remoteKey: string;
91
90
  }
92
91
  export interface SpeedKitConfigInterface extends InstallResourceInterface {
93
- evaluate(customer: SpeedKitConfigCustomer, origin: string): Promise<SpeedKitConfig>;
92
+ evaluate(app: string, origin: string): Promise<SpeedKitConfig>;
94
93
  }
95
94
  export interface CustomerConfigInterface extends ConfigFileInterface {
96
95
  config: CustomerConfig;
@@ -2,21 +2,8 @@ import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
3
  import { SpeedKitConfigFile, VirtualSpeedKitConfigFile } from "../index.js";
4
4
  import { INTEGRATION_FILES } from "../../../models/files.js";
5
- import { BundleService, BundleServiceFactory, } from "../../bundler/index.js";
5
+ import { BundleServiceFactory } from "../../bundler/index.js";
6
6
  const bundler = new BundleServiceFactory("./").buildService();
7
- const SHOP_DE = { app: "shop-de" };
8
- /** Answers every bundle request with one bundle and keeps the requests. */
9
- class FakePackjockel {
10
- bundled;
11
- requests = [];
12
- constructor(bundled) {
13
- this.bundled = bundled;
14
- }
15
- async bundle(request) {
16
- this.requests.push(request);
17
- return this.bundled;
18
- }
19
- }
20
7
  function configFile(source) {
21
8
  return new SpeedKitConfigFile({
22
9
  name: INTEGRATION_FILES.CONFIG.SPEED_KIT,
@@ -26,7 +13,7 @@ function configFile(source) {
26
13
  }, bundler);
27
14
  }
28
15
  function evaluate(source) {
29
- return configFile(source).evaluate(SHOP_DE, "https://www.shop.de");
16
+ return configFile(source).evaluate("shop-de", "https://www.shop.de");
30
17
  }
31
18
  /** What the config assigned, for the tests about the browser mock itself. */
32
19
  async function evaluateRaw(source) {
@@ -102,19 +89,19 @@ describe("SpeedKitConfigFile", () => {
102
89
  // builder and the pre-deploy checks both go through here.
103
90
  const file = configFile(`window.speedKit = { host: window.location.host };`);
104
91
  const [first, second] = await Promise.all([
105
- file.evaluate(SHOP_DE, "https://www.shop.de"),
106
- file.evaluate(SHOP_DE, "https://www.shop.de"),
92
+ file.evaluate("shop-de", "https://www.shop.de"),
93
+ file.evaluate("shop-de", "https://www.shop.de"),
107
94
  ]);
108
- const otherOrigin = await file.evaluate(SHOP_DE, "https://m.shop.de");
95
+ const otherOrigin = await file.evaluate("shop-de", "https://m.shop.de");
109
96
  expect(first).to.equal(second);
110
97
  expect(otherOrigin).to.not.equal(first);
111
98
  expect(otherOrigin.raw.host).to.equal("m.shop.de");
112
99
  });
113
100
  it("should forget what it read when the file changes", async () => {
114
101
  const file = configFile(`window.speedKit = { split: 0.1 };`);
115
- const before = await file.evaluate(SHOP_DE, "https://www.shop.de");
102
+ const before = await file.evaluate("shop-de", "https://www.shop.de");
116
103
  file.setContent(`window.speedKit = { split: 0.5 };`);
117
- const after = await file.evaluate(SHOP_DE, "https://www.shop.de");
104
+ const after = await file.evaluate("shop-de", "https://www.shop.de");
118
105
  expect(before.split).to.equal(0.1);
119
106
  expect(after.split).to.equal(0.5);
120
107
  });
@@ -122,57 +109,8 @@ describe("SpeedKitConfigFile", () => {
122
109
  const source = `window.speedKit = { split: 0.5, appName: APP };`;
123
110
  const remote = await VirtualSpeedKitConfigFile.createRemote(source, bundler);
124
111
  const local = await evaluate(source);
125
- const deployed = await remote.evaluate(SHOP_DE, "https://www.shop.de");
112
+ const deployed = await remote.evaluate("shop-de", "https://www.shop.de");
126
113
  expect(deployed).to.deep.equal(local);
127
114
  expect(remote.getContent()).to.equal(source);
128
115
  });
129
- describe("with the configPlugins feature", () => {
130
- const SOURCE = "window.speedKit = { split: 0.1 };";
131
- const EMBEDDED = {
132
- app: "shop-de",
133
- features: { configPlugins: true },
134
- configPluginsVersion: "@release",
135
- };
136
- function embeddedFile(bundled) {
137
- const packjockel = new FakePackjockel(bundled);
138
- const file = new SpeedKitConfigFile({
139
- name: INTEGRATION_FILES.CONFIG.SPEED_KIT,
140
- path: "config_SpeedKit.js",
141
- content: SOURCE,
142
- remoteKey: "config",
143
- }, new BundleService("./", packjockel));
144
- return { file, packjockel };
145
- }
146
- it("should bundle with packjockel and its plugins of the pinned release", async () => {
147
- const { file, packjockel } = embeddedFile(`SpeedKit.config = {};`);
148
- await file.evaluate(EMBEDDED, "https://www.shop.de");
149
- expect(packjockel.requests).to.have.length(1);
150
- expect(packjockel.requests[0]).to.deep.equal({
151
- entryPoints: { "config.js": SOURCE },
152
- basePaths: {
153
- "speed-kit-config": "https://www.baqend.com/speed-kit-config/release/",
154
- },
155
- define: { APP: '"shop-de"' },
156
- platform: "browser",
157
- });
158
- });
159
- it("should read SpeedKit.config and the plugins pushed without a guard", async () => {
160
- const { file } = embeddedFile(`SpeedKit.configPlugins.push({ name: "StripQueryParamPlugin" });
161
- SpeedKit.config = { split: 0.3, appName: "shop-de" };`);
162
- const config = await file.evaluate(EMBEDDED, "https://www.shop.de");
163
- expect(config.split).to.equal(0.3);
164
- expect(config.raw.appName).to.equal("shop-de");
165
- });
166
- it("should still read a config that assigns window.speedKit", async () => {
167
- const { file } = embeddedFile(`window.speedKit = { split: 0.7 };`);
168
- const config = await file.evaluate(EMBEDDED, "https://www.shop.de");
169
- expect(config.split).to.equal(0.7);
170
- });
171
- it("should not reuse a reading of the other bundler", async () => {
172
- const { file, packjockel } = embeddedFile(`SpeedKit.config = {};`);
173
- await file.evaluate(EMBEDDED, "https://www.shop.de");
174
- await file.evaluate({ app: "shop-de" }, "https://www.shop.de");
175
- expect(packjockel.requests).to.have.length(1);
176
- });
177
- });
178
116
  });
@@ -1,15 +1,3 @@
1
- /**
2
- * The installation features of a config. `null` leaves a feature at its default.
3
- */
4
- export interface CustomerFeatures {
5
- /**
6
- * packjockel bundles the config with the config plugins of its target and
7
- * embeds it into the document handler and the install script. The config
8
- * writes `SpeedKit.config`.
9
- */
10
- configPlugins?: boolean | null;
11
- [feature: string]: unknown;
12
- }
13
1
  export interface CustomerConfigs {
14
2
  production: CustomerConfig;
15
3
  [configName: string]: CustomerConfig;
@@ -33,12 +21,6 @@ export declare class CustomerConfig {
33
21
  * installation whose split is greater than 0 for any origin.
34
22
  */
35
23
  readonly needsCustomerApproval?: boolean;
36
- readonly features?: CustomerFeatures;
37
- /**
38
- * The speed-kit-config release the packjockel bundles import plugins from: a version such as
39
- * `1.8.0`, or a channel such as `@release`.
40
- */
41
- readonly configPluginsVersion?: string;
42
- constructor(app: string, origins: string[], domain: string, swPath: string, scope: string, appDomain?: string, installPath?: string, installParameters?: string, name?: string, forceInstall?: boolean, chromeFlags?: string[], dependencies?: Record<string, string>, needsCustomerApproval?: boolean, features?: CustomerFeatures, configPluginsVersion?: string);
24
+ constructor(app: string, origins: string[], domain: string, swPath: string, scope: string, appDomain?: string, installPath?: string, installParameters?: string, name?: string, forceInstall?: boolean, chromeFlags?: string[], dependencies?: Record<string, string>, needsCustomerApproval?: boolean);
43
25
  static createFrom(configFile: Partial<CustomerConfig>, configName?: string): CustomerConfig;
44
26
  }
@@ -18,13 +18,7 @@ export class CustomerConfig {
18
18
  * installation whose split is greater than 0 for any origin.
19
19
  */
20
20
  needsCustomerApproval;
21
- features;
22
- /**
23
- * The speed-kit-config release the packjockel bundles import plugins from: a version such as
24
- * `1.8.0`, or a channel such as `@release`.
25
- */
26
- configPluginsVersion;
27
- constructor(app, origins, domain, swPath, scope, appDomain, installPath, installParameters, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, features, configPluginsVersion) {
21
+ constructor(app, origins, domain, swPath, scope, appDomain, installPath, installParameters, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval) {
28
22
  this.app = app;
29
23
  this.origins = origins;
30
24
  this.domain = domain;
@@ -38,13 +32,11 @@ export class CustomerConfig {
38
32
  this.chromeFlags = chromeFlags;
39
33
  this.dependencies = dependencies;
40
34
  this.needsCustomerApproval = needsCustomerApproval;
41
- this.features = features;
42
- this.configPluginsVersion = configPluginsVersion;
43
35
  }
44
36
  static createFrom(configFile, configName) {
45
- const { app, origins, domain, swPath, scope, appDomain, installPath, installParams, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, features, configPluginsVersion, } = configFile;
37
+ const { app, origins, domain, swPath, scope, appDomain, installPath, installParams, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, } = configFile;
46
38
  return new CustomerConfig(new RequiredParameter("app", app).isString().getValue(), new RequiredParameter("origins", origins).isArray().getValue(), domain, new RequiredParameter("swPath", swPath).isString().getValue(), new RequiredParameter("scope", scope).isString().getValue(), appDomain || `${app}.app.baqend.com`, installPath ||
47
- `https://${app}.app.baqend.com/v1/speedkit/install.js?d=${name || configName}`, installParams || 'async="" crossorigin="anonymous"', name, forceInstall || false, chromeFlags, dependencies || {}, needsCustomerApproval || false, features || {}, configPluginsVersion);
39
+ `https://${app}.app.baqend.com/v1/speedkit/install.js?d=${name || configName}`, installParams || 'async="" crossorigin="anonymous"', name, forceInstall || false, chromeFlags, dependencies || {}, needsCustomerApproval || false);
48
40
  }
49
41
  }
50
42
  class RequiredParameter {
@@ -1,10 +1,7 @@
1
- import { type BundleService } from "../../bundler/index.js";
1
+ import type { BundleService } from "../../bundler/index.js";
2
2
  import type { SpeedKitConfigInterface, VirtualFileInterface, VirtualFileRecipe } from "../integration-api-model.js";
3
3
  import { InstallResourceFile } from "./install-resource-file.js";
4
4
  import { SpeedKitConfig } from "./speed-kit-config.js";
5
- import type { CustomerConfig } from "./customer-config.js";
6
- /** What of the customer config decides how a Speed Kit config is bundled and read. */
7
- export type SpeedKitConfigCustomer = Pick<CustomerConfig, "app" | "features" | "configPluginsVersion">;
8
5
  /** The name the config deployed to the app is read back under. */
9
6
  export declare const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
10
7
  /** The file a {@link SpeedKitConfigFile} stands for. */
@@ -26,7 +23,7 @@ export interface SpeedKitConfigFileInit {
26
23
  export declare class SpeedKitConfigFile extends InstallResourceFile implements SpeedKitConfigInterface {
27
24
  private readonly bundler;
28
25
  /**
29
- * One evaluation per app, origin and bundler. A config branches on
26
+ * One evaluation per app and origin. A config branches on
30
27
  * `window.location`, so the same file read for two origins is two different
31
28
  * configs — and bundling one is expensive enough not to repeat per caller.
32
29
  */
@@ -37,8 +34,8 @@ export declare class SpeedKitConfigFile extends InstallResourceFile implements S
37
34
  */
38
35
  constructor(file: SpeedKitConfigFileInit, bundler: BundleService);
39
36
  setContent(content: string): void;
40
- /** The config this file describes for one customer and origin. */
41
- evaluate(customer: SpeedKitConfigCustomer, origin: string): Promise<SpeedKitConfig>;
37
+ /** The config this file describes for one app and origin. */
38
+ evaluate(app: string, origin: string): Promise<SpeedKitConfig>;
42
39
  }
43
40
  /**
44
41
  * A SpeedKit config that has no file on disk behind it — the one deployed to
@@ -63,5 +60,3 @@ export declare class VirtualSpeedKitConfigFile extends SpeedKitConfigFile implem
63
60
  delete(): Promise<void>;
64
61
  onChange(): void;
65
62
  }
66
- /** The customer has the `configPlugins` feature: packjockel bundles its config. */
67
- export declare function usesConfigPlugins(customer: SpeedKitConfigCustomer): boolean;
@@ -1,10 +1,9 @@
1
1
  import * as vm from "node:vm";
2
- import { speedKitConfigBasePath, } from "../../bundler/index.js";
3
2
  import { EvaluateSkConfigError } from "../error/evaluate-sk-config-error.js";
4
3
  import ApplicationError from "../../error-handling/error/application-error.js";
5
4
  import { StaticRecipe } from "../virtual/static-recipe.js";
6
5
  import { InstallResourceFile } from "./install-resource-file.js";
7
- import { SpeedKitConfig, } from "./speed-kit-config.js";
6
+ import { SpeedKitConfig } from "./speed-kit-config.js";
8
7
  /** The name the config deployed to the app is read back under. */
9
8
  export const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
10
9
  /**
@@ -18,7 +17,7 @@ export const REMOTE_SPEED_KIT_CONFIG = "config_SpeedKit@remote";
18
17
  export class SpeedKitConfigFile extends InstallResourceFile {
19
18
  bundler;
20
19
  /**
21
- * One evaluation per app, origin and bundler. A config branches on
20
+ * One evaluation per app and origin. A config branches on
22
21
  * `window.location`, so the same file read for two origins is two different
23
22
  * configs — and bundling one is expensive enough not to repeat per caller.
24
23
  */
@@ -35,15 +34,14 @@ export class SpeedKitConfigFile extends InstallResourceFile {
35
34
  super.setContent(content);
36
35
  this.evaluations.clear();
37
36
  }
38
- /** The config this file describes for one customer and origin. */
39
- evaluate(customer, origin) {
40
- const { app } = customer;
41
- const key = `${app}|${origin}|${usesConfigPlugins(customer) ? "packjockel" : "esbuild"}`;
37
+ /** The config this file describes for one app and origin. */
38
+ evaluate(app, origin) {
39
+ const key = `${app}|${origin}`;
42
40
  const cached = this.evaluations.get(key);
43
41
  if (cached) {
44
42
  return cached;
45
43
  }
46
- const evaluation = bundle(this.bundler, this.getContent(), customer)
44
+ const evaluation = bundle(this.bundler, this.getContent(), app)
47
45
  .then((code) => evaluateSpeedKitConfig(app, origin, code, this.path))
48
46
  .catch((error) => {
49
47
  // A failure is not an answer: forget it, so the next caller — or the
@@ -97,8 +95,7 @@ export class VirtualSpeedKitConfigFile extends SpeedKitConfigFile {
97
95
  }
98
96
  /**
99
97
  * Run a bundled config against a browser mock and hand back what it assigned to
100
- * `SpeedKit.config`, or else to `window.speedKit`, together with the config
101
- * plugins it registered.
98
+ * `window.speedKit`, together with the config plugins it registered.
102
99
  *
103
100
  * @param app the app the config is evaluated for, exposed to it as `APP`
104
101
  * @param origin the origin the config is evaluated for, its `window.location`
@@ -116,7 +113,7 @@ function evaluateSpeedKitConfig(app, origin, code, filename) {
116
113
  if (browserContext.vmError !== null) {
117
114
  throw new EvaluateSkConfigError(`[${filename}] ${browserContext.vmError?.message}`);
118
115
  }
119
- return SpeedKitConfig.createFrom(browserContext.window.SpeedKit.config ?? browserContext.window.speedKit, registeredPlugins(browserContext));
116
+ return SpeedKitConfig.createFrom(browserContext.window.speedKit, registeredPlugins(browserContext));
120
117
  }
121
118
  /**
122
119
  * The plugins a config registered, read the way `ConfigController.getPlugins`
@@ -139,9 +136,7 @@ function buildBrowserMock(origin, app) {
139
136
  },
140
137
  customVariation: [],
141
138
  },
142
- // An embedded config pushes its plugins without creating the list, the
143
- // way packjockel hands it over.
144
- SpeedKit: { configPlugins: [] },
139
+ SpeedKit: {},
145
140
  serviceWorkerUrl: "",
146
141
  screen: { width: 0, height: 0 },
147
142
  devicePixelRatio: 1,
@@ -219,25 +214,10 @@ function safeFileContentWrapper(fileContent) {
219
214
  }
220
215
  `;
221
216
  }
222
- /** The customer has the `configPlugins` feature: packjockel bundles its config. */
223
- export function usesConfigPlugins(customer) {
224
- return customer.features?.configPlugins === true;
225
- }
226
- async function bundle(bundler, content, customer) {
217
+ async function bundle(bundler, content, app) {
227
218
  if (!content) {
228
219
  throw new ApplicationError("Content is empty");
229
220
  }
230
- const app = customer.app;
231
- if (usesConfigPlugins(customer)) {
232
- return bundler.packjockel.bundle({
233
- entryPoints: { "config.js": content },
234
- basePaths: {
235
- "speed-kit-config": speedKitConfigBasePath(customer.configPluginsVersion),
236
- },
237
- define: { APP: JSON.stringify(app) },
238
- platform: "browser",
239
- });
240
- }
241
221
  return bundler.bundle({
242
222
  basePaths: {
243
223
  "speed-kit-config": "https://www.baqend.com/speed-kit-config/latest/",