@speedkit/cli 4.43.0-beta.1 → 4.43.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 (86) hide show
  1. package/CHANGELOG.md +2 -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/services/bundler/bundle-service-factory.d.ts +1 -6
  6. package/dist/services/bundler/bundle-service-factory.js +2 -9
  7. package/dist/services/bundler/bundle-service.d.ts +1 -10
  8. package/dist/services/bundler/bundle-service.js +1 -16
  9. package/dist/services/bundler/index.d.ts +0 -1
  10. package/dist/services/bundler/index.js +0 -1
  11. package/dist/services/cli/cli-environment.js +0 -1
  12. package/dist/services/cli/cli-settings.d.ts +0 -5
  13. package/dist/services/cli/cli-settings.js +0 -1
  14. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  15. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
  16. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
  17. package/dist/services/deploy/deploy-service-factory.js +1 -1
  18. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +1 -1
  19. package/dist/services/document-handler-runtime/document-handler-runtime-model.d.ts +0 -2
  20. package/dist/services/document-handler-runtime/document-handler-runtime-model.js +0 -2
  21. package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
  22. package/dist/services/document-handler-runtime/document-handler-server.js +20 -82
  23. package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +1 -1
  24. package/dist/services/integration-api/integration-api-factory.js +1 -1
  25. package/dist/services/integration-api/integration-api-model.d.ts +1 -2
  26. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -70
  27. package/dist/services/integration-api/struct/customer-config.d.ts +1 -19
  28. package/dist/services/integration-api/struct/customer-config.js +3 -11
  29. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
  30. package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -30
  31. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -24
  32. package/dist/services/onboarding/error/inject-installation-error.d.ts +6 -0
  33. package/dist/services/onboarding/error/inject-installation-error.js +11 -0
  34. package/dist/services/onboarding/error/inject-target-error.d.ts +6 -0
  35. package/dist/services/onboarding/error/inject-target-error.js +11 -0
  36. package/dist/services/onboarding/error/missing-customer-path-error.d.ts +1 -1
  37. package/dist/services/onboarding/error/missing-customer-path-error.js +2 -1
  38. package/dist/services/onboarding/fetch-events/customer-domain-document-response.d.ts +4 -14
  39. package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +6 -45
  40. package/dist/services/onboarding/fetch-events/document-rewrite.d.ts +19 -0
  41. package/dist/services/onboarding/fetch-events/document-rewrite.js +47 -0
  42. package/dist/services/onboarding/fetch-events/speed-kit-install-html.d.ts +5 -1
  43. package/dist/services/onboarding/fetch-events/speed-kit-install-html.js +7 -2
  44. package/dist/services/onboarding/html-rewrites.d.ts +3 -3
  45. package/dist/services/onboarding/html-rewrites.js +3 -3
  46. package/dist/services/onboarding/index.d.ts +1 -1
  47. package/dist/services/onboarding/index.js +1 -1
  48. package/dist/services/onboarding/inject/content-security-policy.d.ts +14 -0
  49. package/dist/services/onboarding/inject/content-security-policy.js +54 -0
  50. package/dist/services/onboarding/inject/deployed-installation.d.ts +15 -0
  51. package/dist/services/onboarding/inject/deployed-installation.js +32 -0
  52. package/dist/services/onboarding/inject/foreign-install-request.d.ts +27 -0
  53. package/dist/services/onboarding/inject/foreign-install-request.js +50 -0
  54. package/dist/services/onboarding/inject/inject-document-rewrite.d.ts +23 -0
  55. package/dist/services/onboarding/inject/inject-document-rewrite.js +52 -0
  56. package/dist/services/onboarding/inject/inject-service.d.ts +32 -0
  57. package/dist/services/onboarding/inject/inject-service.js +72 -0
  58. package/dist/services/onboarding/inject/injected-installation.d.ts +29 -0
  59. package/dist/services/onboarding/inject/injected-installation.js +37 -0
  60. package/dist/services/onboarding/onboarding-service-build-context.d.ts +15 -1
  61. package/dist/services/onboarding/onboarding-service-build-context.js +31 -2
  62. package/dist/services/onboarding/onboarding-service-factory.d.ts +23 -5
  63. package/dist/services/onboarding/onboarding-service-factory.js +87 -7
  64. package/dist/services/onboarding/spec/inject/content-security-policy.spec.js +47 -0
  65. package/dist/services/onboarding/spec/inject/deployed-installation.spec.d.ts +1 -0
  66. package/dist/services/onboarding/spec/inject/deployed-installation.spec.js +49 -0
  67. package/dist/services/onboarding/spec/inject/foreign-install-request.spec.d.ts +1 -0
  68. package/dist/services/onboarding/spec/inject/foreign-install-request.spec.js +47 -0
  69. package/dist/services/onboarding/spec/inject/inject-document-rewrite.spec.d.ts +1 -0
  70. package/dist/services/onboarding/spec/inject/inject-document-rewrite.spec.js +66 -0
  71. package/dist/services/onboarding/spec/inject/injected-installation.spec.d.ts +1 -0
  72. package/dist/services/onboarding/spec/inject/injected-installation.spec.js +24 -0
  73. package/dist/services/onboarding/spec/onboarding-service-build-context.spec.d.ts +1 -0
  74. package/dist/services/onboarding/spec/onboarding-service-build-context.spec.js +22 -0
  75. package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +53 -2
  76. package/dist/services/onboarding/templates/install-speed-kit-html-template.js +3 -0
  77. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
  78. package/dist/services/query-builder/query-builder-factory.js +3 -3
  79. package/oclif.manifest.json +26 -3
  80. package/package.json +1 -2
  81. package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
  82. package/dist/services/bundler/error/packjockel-error.js +0 -3
  83. package/dist/services/bundler/packjockel-service.d.ts +0 -70
  84. package/dist/services/bundler/packjockel-service.js +0 -171
  85. package/dist/services/bundler/spec/packjockel-service.spec.js +0 -149
  86. /package/dist/services/{bundler/spec/packjockel-service.spec.d.ts → onboarding/spec/inject/content-security-policy.spec.d.ts} +0 -0
@@ -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/",
@@ -1,5 +1,3 @@
1
- import { speedKitConfigBasePath } from "../../bundler/index.js";
2
- import { usesConfigPlugins, } from "../../integration-api/index.js";
3
1
  import { INTEGRATION_FILES } from "../../../models/files.js";
4
2
  const IMPORT_PATHS = {
5
3
  rum: "https://www.baqend.com/rum/latest/",
@@ -21,10 +19,8 @@ export class SpeedKitInstallContext {
21
19
  this.skTemplate = skTemplate;
22
20
  }
23
21
  async getSpeedKitInstallJs() {
24
- const configPlugins = usesConfigPlugins(this.customerConfig);
25
22
  const configJs = this.skTemplate.render({
26
23
  config: this.getConfigSpeedKit(),
27
- configPlugins,
28
24
  forceInstall: this.customerConfig.forceInstall,
29
25
  installPath: this.customerConfig.installPath,
30
26
  installParams: this.customerConfig.installParams,
@@ -33,27 +29,15 @@ export class SpeedKitInstallContext {
33
29
  .getByName(INTEGRATION_FILES.CUSTOM.DYNAMIC_FETCHER)
34
30
  .getContent(),
35
31
  });
36
- const entryPoints = {
37
- "rum.js": this.prepareConfigLoadHandler(),
38
- "config.js": configJs,
39
- "loader.js": this.files
40
- .getByName(INTEGRATION_FILES.CUSTOM.LOADER)
41
- .getContent(),
42
- };
43
- if (configPlugins) {
44
- return this.bundler.packjockel.bundle({
45
- entryPoints,
46
- basePaths: {
47
- ...IMPORT_PATHS,
48
- "speed-kit-config": speedKitConfigBasePath(this.customerConfig.configPluginsVersion),
49
- },
50
- define: { APP: JSON.stringify(this.customerConfig.app) },
51
- platform: "browser",
52
- });
53
- }
54
32
  return this.bundler.bundle({
55
33
  basePaths: IMPORT_PATHS,
56
- entryPoints,
34
+ entryPoints: {
35
+ "rum.js": this.prepareConfigLoadHandler(),
36
+ "config.js": configJs,
37
+ "loader.js": this.files
38
+ .getByName(INTEGRATION_FILES.CUSTOM.LOADER)
39
+ .getContent(),
40
+ },
57
41
  logLevel: "error",
58
42
  minify: false,
59
43
  platform: "browser",
@@ -88,7 +72,7 @@ export class SpeedKitInstallContext {
88
72
  return config.replace(value, "100");
89
73
  });
90
74
  }
91
- return configString.replace(/(?:window\.speedKit|SpeedKit\.config)[^{]*=[^{]*{/, (configOpenTag) => {
75
+ return configString.replace(/window\.speedKit[^{]*=[^{]*{/, (configOpenTag) => {
92
76
  return configOpenTag + `\n delayRacedOrigin: 100,\n`;
93
77
  });
94
78
  }
@@ -0,0 +1,6 @@
1
+ import ApplicationError from "../../error-handling/error/application-error.js";
2
+ /** The server has no installation that `sk onboarding --inject` can inject. */
3
+ export declare class InjectInstallationError extends ApplicationError {
4
+ readonly code = "INJECT_INSTALLATION_ERROR";
5
+ constructor(installUrl: string, reason: string);
6
+ }
@@ -0,0 +1,11 @@
1
+ import ApplicationError from "../../error-handling/error/application-error.js";
2
+ /** The server has no installation that `sk onboarding --inject` can inject. */
3
+ export class InjectInstallationError extends ApplicationError {
4
+ code = "INJECT_INSTALLATION_ERROR";
5
+ constructor(installUrl, reason) {
6
+ super(`No installation to inject at ${installUrl}: ${reason}.`, [
7
+ "check the app, the domain and the installation id",
8
+ "without an id the app needs a live installation for this domain: pass `--inject <installationId>` for a testing installation",
9
+ ]);
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ import ApplicationError from "../../error-handling/error/application-error.js";
2
+ /** `sk onboarding --inject` has no app, or no domain, to find the installation with. */
3
+ export declare class InjectTargetError extends ApplicationError {
4
+ readonly code = "INJECT_TARGET_ERROR";
5
+ constructor(missing: "app" | "domain");
6
+ }
@@ -0,0 +1,11 @@
1
+ import ApplicationError from "../../error-handling/error/application-error.js";
2
+ /** `sk onboarding --inject` has no app, or no domain, to find the installation with. */
3
+ export class InjectTargetError extends ApplicationError {
4
+ code = "INJECT_TARGET_ERROR";
5
+ constructor(missing) {
6
+ super(`Inject mode needs ${missing === "app" ? "an app" : "a domain"}.`, [
7
+ "pass both, e.g. `sk onboarding --inject --app example-shop -d www.example.com`",
8
+ "or pass a CUSTOMERPATH whose config_customer.json names them",
9
+ ]);
10
+ }
11
+ }
@@ -1,5 +1,5 @@
1
1
  import ApplicationError from "../../error-handling/error/application-error.js";
2
- /** `sk onboarding` without `--browse` runs a customer config, so it needs its directory. */
2
+ /** `sk onboarding` without `--browse` and without `--inject` runs a customer config, so it needs its directory. */
3
3
  export declare class MissingCustomerPathError extends ApplicationError {
4
4
  readonly code = "MISSING_CUSTOMER_PATH";
5
5
  constructor();
@@ -1,11 +1,12 @@
1
1
  import ApplicationError from "../../error-handling/error/application-error.js";
2
- /** `sk onboarding` without `--browse` runs a customer config, so it needs its directory. */
2
+ /** `sk onboarding` without `--browse` and without `--inject` runs a customer config, so it needs its directory. */
3
3
  export class MissingCustomerPathError extends ApplicationError {
4
4
  code = "MISSING_CUSTOMER_PATH";
5
5
  constructor() {
6
6
  super("Missing CUSTOMERPATH: onboarding needs a customer config.", [
7
7
  "pass the customer directory, e.g. `sk onboarding customers/example-shop`",
8
8
  "or add --browse to open the live site without a config",
9
+ "or add --inject with --app and -d to inject a deployed installation",
9
10
  ]);
10
11
  }
11
12
  }
@@ -1,30 +1,20 @@
1
1
  import { Protocol } from "devtools-protocol";
2
2
  import { FetchRequestPausedEventHandler } from "../onboarding-model.js";
3
- import { CustomerConfig, ConfigFileInterface } from "../../integration-api/index.js";
3
+ import { CustomerConfig } from "../../integration-api/index.js";
4
4
  import { CDPSession } from "puppeteer";
5
+ import { DocumentRewrite } from "./document-rewrite.js";
5
6
  /**
6
7
  * Intercepts any request to the customersOrigin and equivalent requests to baqendAssetApi
7
8
  * @implements {FetchRequestPausedEventHandler}
8
9
  */
9
10
  export declare class CustomerDomainDocumentResponse implements FetchRequestPausedEventHandler {
10
11
  private customerConfig;
11
- private configDynamicBlock;
12
- private configDynamicStyles;
13
- private removeContentSecurityPolicy;
12
+ private rewrite;
14
13
  get patterns(): Protocol.Fetch.RequestPattern[];
15
- constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface, removeContentSecurityPolicy: boolean);
14
+ constructor(customerConfig: CustomerConfig, rewrite: DocumentRewrite);
16
15
  handle(event: Protocol.Fetch.RequestPausedEvent, client: CDPSession): Promise<Partial<Protocol.Fetch.FulfillRequestRequest> | null>;
17
16
  private isValidHtmlContent;
18
17
  private isValidResponse;
19
18
  private isHtmlContentHeader;
20
19
  private getHtmlContent;
21
- private isSpeedKitResponse;
22
- private rewriteHtmlToLocalConfig;
23
- /**
24
- * Removes content policy headers from the given array of headers.
25
- *
26
- * @param {Protocol.Fetch.HeaderEntry[]} headers - The array of header entries.
27
- * @returns {Protocol.Fetch.HeaderEntry[]} - The modified array of header entries with content policy headers removed.
28
- */
29
- private removeContentSecurityHeaderFromResponse;
30
20
  }
@@ -1,6 +1,5 @@
1
1
  import { META_CONTENT_TYPE_REGEX, } from "../onboarding-model.js";
2
2
  import { OriginResponse } from "../browser/origin-response.js";
3
- import { removeContentSecurityMetaTag, rewriteInstallResource, } from "../html-rewrites.js";
4
3
  import iconv from "iconv-lite";
5
4
  import Encoding from "encoding-japanese";
6
5
  import { UnsupportedEncodingError } from "../error/unsupported-encoding-error.js";
@@ -10,9 +9,7 @@ import { UnsupportedEncodingError } from "../error/unsupported-encoding-error.js
10
9
  */
11
10
  export class CustomerDomainDocumentResponse {
12
11
  customerConfig;
13
- configDynamicBlock;
14
- configDynamicStyles;
15
- removeContentSecurityPolicy;
12
+ rewrite;
16
13
  get patterns() {
17
14
  const result = [];
18
15
  for (const origin of this.customerConfig.origins) {
@@ -47,11 +44,9 @@ export class CustomerDomainDocumentResponse {
47
44
  }
48
45
  return result;
49
46
  }
50
- constructor(customerConfig, configDynamicBlock, configDynamicStyles, removeContentSecurityPolicy) {
47
+ constructor(customerConfig, rewrite) {
51
48
  this.customerConfig = customerConfig;
52
- this.configDynamicBlock = configDynamicBlock;
53
- this.configDynamicStyles = configDynamicStyles;
54
- this.removeContentSecurityPolicy = removeContentSecurityPolicy;
49
+ this.rewrite = rewrite;
55
50
  }
56
51
  async handle(event, client) {
57
52
  if (!this.isValidResponse(event)) {
@@ -60,22 +55,12 @@ export class CustomerDomainDocumentResponse {
60
55
  if (!this.isHtmlContentHeader(event.responseHeaders)) {
61
56
  return;
62
57
  }
63
- let text = await this.getHtmlContent(client, event);
58
+ const text = await this.getHtmlContent(client, event);
64
59
  if (!this.isValidHtmlContent(text)) {
65
60
  return;
66
61
  }
67
- const headers = this.removeContentSecurityPolicy
68
- ? this.removeContentSecurityHeaderFromResponse(event.responseHeaders)
69
- : event.responseHeaders;
70
- if (this.customerConfig.forceInstall) {
71
- text = rewriteInstallResource(text, this.customerConfig);
72
- }
73
- if (this.isSpeedKitResponse(text)) {
74
- text = this.rewriteHtmlToLocalConfig(text);
75
- }
76
- const content = this.removeContentSecurityPolicy
77
- ? removeContentSecurityMetaTag(text)
78
- : text;
62
+ const headers = this.rewrite.headers(event.responseHeaders);
63
+ const content = this.rewrite.html(text);
79
64
  // replace origin contentTypeCharset with utf-8 as this is what it's converted to now
80
65
  let detectedEncoding = "utf-8";
81
66
  for (const header of headers) {
@@ -138,28 +123,4 @@ export class CustomerDomainDocumentResponse {
138
123
  }
139
124
  return body;
140
125
  }
141
- isSpeedKitResponse(text) {
142
- return text.includes("speed-kit-dynamic");
143
- }
144
- rewriteHtmlToLocalConfig(html) {
145
- const DF_CONFIG_PATTERN = /(<script[^>]* id="speed-kit-df-config"[^>]*>)([\S\s]*?)(<\/script>)/g;
146
- const DF_STYLES_PATTERN = /(<style[^>]* id="speed-kit-df-styles"[^>]*>)(?:(?!<\/style>)[\S\s])*(<\/style>)/g;
147
- html = html.replaceAll(DF_CONFIG_PATTERN, (_, tag, body, end) => {
148
- const injectedConfig = body.match(/window\.dynamicBlockConfig\.appName\s=.*$/s) ?? [""];
149
- return `${tag}${this.configDynamicBlock.getContent()}${injectedConfig[0]}${end}`;
150
- });
151
- html = html.replaceAll(DF_STYLES_PATTERN, (_, tag, end) => `${tag}${this.configDynamicStyles.getContent()}${end}`);
152
- return html;
153
- }
154
- /**
155
- * Removes content policy headers from the given array of headers.
156
- *
157
- * @param {Protocol.Fetch.HeaderEntry[]} headers - The array of header entries.
158
- * @returns {Protocol.Fetch.HeaderEntry[]} - The modified array of header entries with content policy headers removed.
159
- */
160
- removeContentSecurityHeaderFromResponse(headers) {
161
- return headers.filter((header) => {
162
- return !header.name.toLowerCase().includes("content-security-policy");
163
- });
164
- }
165
126
  }
@@ -0,0 +1,19 @@
1
+ import { Protocol } from "devtools-protocol";
2
+ import { ConfigFileInterface, CustomerConfig } from "../../integration-api/index.js";
3
+ /** What onboarding changes in an HTML document of the origin before Chrome gets it. */
4
+ export interface DocumentRewrite {
5
+ headers(headers: Protocol.Fetch.HeaderEntry[]): Protocol.Fetch.HeaderEntry[];
6
+ html(html: string): string;
7
+ }
8
+ /** The rewrite of a local run: the document gets the config that is on disk. */
9
+ export declare class LocalDocumentRewrite implements DocumentRewrite {
10
+ private customerConfig;
11
+ private configDynamicBlock;
12
+ private configDynamicStyles;
13
+ private removeContentSecurityPolicy;
14
+ constructor(customerConfig: CustomerConfig, configDynamicBlock: ConfigFileInterface, configDynamicStyles: ConfigFileInterface, removeContentSecurityPolicy: boolean);
15
+ headers(headers: Protocol.Fetch.HeaderEntry[]): Protocol.Fetch.HeaderEntry[];
16
+ html(html: string): string;
17
+ private isSpeedKitResponse;
18
+ private rewriteHtmlToLocalConfig;
19
+ }
@@ -0,0 +1,47 @@
1
+ import { removeContentSecurityMetaTag, rewriteInstallResource, } from "../html-rewrites.js";
2
+ /** The rewrite of a local run: the document gets the config that is on disk. */
3
+ export class LocalDocumentRewrite {
4
+ customerConfig;
5
+ configDynamicBlock;
6
+ configDynamicStyles;
7
+ removeContentSecurityPolicy;
8
+ constructor(customerConfig, configDynamicBlock, configDynamicStyles, removeContentSecurityPolicy) {
9
+ this.customerConfig = customerConfig;
10
+ this.configDynamicBlock = configDynamicBlock;
11
+ this.configDynamicStyles = configDynamicStyles;
12
+ this.removeContentSecurityPolicy = removeContentSecurityPolicy;
13
+ }
14
+ headers(headers) {
15
+ if (!this.removeContentSecurityPolicy) {
16
+ return headers;
17
+ }
18
+ return headers.filter((header) => {
19
+ return !header.name.toLowerCase().includes("content-security-policy");
20
+ });
21
+ }
22
+ html(html) {
23
+ let text = html;
24
+ if (this.customerConfig.forceInstall) {
25
+ text = rewriteInstallResource(text, this.customerConfig);
26
+ }
27
+ if (this.isSpeedKitResponse(text)) {
28
+ text = this.rewriteHtmlToLocalConfig(text);
29
+ }
30
+ return this.removeContentSecurityPolicy
31
+ ? removeContentSecurityMetaTag(text)
32
+ : text;
33
+ }
34
+ isSpeedKitResponse(text) {
35
+ return text.includes("speed-kit-dynamic");
36
+ }
37
+ rewriteHtmlToLocalConfig(html) {
38
+ const DF_CONFIG_PATTERN = /(<script[^>]* id="speed-kit-df-config"[^>]*>)([\S\s]*?)(<\/script>)/g;
39
+ const DF_STYLES_PATTERN = /(<style[^>]* id="speed-kit-df-styles"[^>]*>)(?:(?!<\/style>)[\S\s])*(<\/style>)/g;
40
+ html = html.replaceAll(DF_CONFIG_PATTERN, (_, tag, body, end) => {
41
+ const injectedConfig = body.match(/window\.dynamicBlockConfig\.appName\s=.*$/s) ?? [""];
42
+ return `${tag}${this.configDynamicBlock.getContent()}${injectedConfig[0]}${end}`;
43
+ });
44
+ html = html.replaceAll(DF_STYLES_PATTERN, (_, tag, end) => `${tag}${this.configDynamicStyles.getContent()}${end}`);
45
+ return html;
46
+ }
47
+ }
@@ -9,7 +9,11 @@ export declare class SpeedKitInstallHtml implements FetchRequestPausedEventHandl
9
9
  private customerConfig;
10
10
  private browserContext;
11
11
  private speedKitInstallHtmlTemplate;
12
+ /** The install resource of `--inject`. It loads as the snippet of a customer does, with CORS. */
13
+ private injectedInstallPath?;
12
14
  get patterns(): Protocol.Fetch.RequestPattern[];
13
- constructor(customerConfig: CustomerConfig, browserContext: BrowserContext, speedKitInstallHtmlTemplate: InstallSpeedKitHtmlTemplate);
15
+ constructor(customerConfig: CustomerConfig, browserContext: BrowserContext, speedKitInstallHtmlTemplate: InstallSpeedKitHtmlTemplate,
16
+ /** The install resource of `--inject`. It loads as the snippet of a customer does, with CORS. */
17
+ injectedInstallPath?: string);
14
18
  handle(): Promise<Partial<Protocol.Fetch.FulfillRequestRequest>>;
15
19
  }