@speedkit/cli 4.50.4 → 4.51.0-beta.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 (71) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/services/bundler/bundle-service-factory.d.ts +3 -0
  3. package/dist/services/bundler/bundle-service-factory.js +5 -1
  4. package/dist/services/bundler/bundle-service.d.ts +10 -1
  5. package/dist/services/bundler/bundle-service.js +16 -1
  6. package/dist/services/bundler/error/packjockel-error.d.ts +3 -0
  7. package/dist/services/bundler/error/packjockel-error.js +3 -0
  8. package/dist/services/bundler/index.d.ts +1 -0
  9. package/dist/services/bundler/index.js +1 -0
  10. package/dist/services/bundler/packjockel-service.d.ts +112 -0
  11. package/dist/services/bundler/packjockel-service.js +202 -0
  12. package/dist/services/bundler/spec/packjockel-service.spec.d.ts +1 -0
  13. package/dist/services/bundler/spec/packjockel-service.spec.js +186 -0
  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 +2 -3
  16. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +2 -3
  17. package/dist/services/deploy/handler/customer-config-handler.d.ts +9 -0
  18. package/dist/services/deploy/handler/customer-config-handler.js +41 -6
  19. package/dist/services/deploy/interface/install.d.ts +7 -1
  20. package/dist/services/deploy/mr/live-state-check.js +21 -2
  21. package/dist/services/deploy/policy/auto-deploy-policy.js +2 -0
  22. package/dist/services/deploy/policy/deploy-policy-model.d.ts +4 -0
  23. package/dist/services/deploy/policy/deploy-policy-model.js +4 -0
  24. package/dist/services/deploy/policy/testing-deploy-policy.js +2 -0
  25. package/dist/services/deploy/spec/handler/customer-config-handler.spec.d.ts +1 -0
  26. package/dist/services/deploy/spec/handler/customer-config-handler.spec.js +98 -0
  27. package/dist/services/deploy/spec/mr/live-state-check.spec.js +45 -4
  28. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +2 -0
  29. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +3 -1
  30. package/dist/services/document-handler-runtime/document-handler-browser-mock.d.ts +13 -0
  31. package/dist/services/document-handler-runtime/document-handler-browser-mock.js +69 -0
  32. package/dist/services/document-handler-runtime/document-handler-server.d.ts +27 -0
  33. package/dist/services/document-handler-runtime/document-handler-server.js +112 -19
  34. package/dist/services/document-handler-runtime/spec/document-handler-browser-mock.spec.d.ts +1 -0
  35. package/dist/services/document-handler-runtime/spec/document-handler-browser-mock.spec.js +34 -0
  36. package/dist/services/integration-api/integration-api-model.d.ts +4 -1
  37. package/dist/services/integration-api/spec/customer-config-file.spec.d.ts +1 -0
  38. package/dist/services/integration-api/spec/customer-config-file.spec.js +56 -0
  39. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +68 -8
  40. package/dist/services/integration-api/struct/customer-config-file.d.ts +15 -0
  41. package/dist/services/integration-api/struct/customer-config-file.js +42 -0
  42. package/dist/services/integration-api/struct/customer-config.d.ts +55 -1
  43. package/dist/services/integration-api/struct/customer-config.js +70 -3
  44. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +11 -4
  45. package/dist/services/integration-api/struct/speed-kit-config-file.js +31 -10
  46. package/dist/services/onboarding/config-renderer/speed-kit-install-context.d.ts +2 -0
  47. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +29 -8
  48. package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +4 -25
  49. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +3 -1
  50. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +10 -2
  51. package/dist/services/onboarding/file-events/file-watcher.d.ts +3 -1
  52. package/dist/services/onboarding/file-events/file-watcher.js +9 -2
  53. package/dist/services/onboarding/html-charset.d.ts +28 -0
  54. package/dist/services/onboarding/html-charset.js +57 -0
  55. package/dist/services/onboarding/onboarding-model.d.ts +0 -1
  56. package/dist/services/onboarding/onboarding-model.js +0 -1
  57. package/dist/services/onboarding/onboarding-service-factory.js +12 -2
  58. package/dist/services/onboarding/spec/fetch-events/customer-domain-document-response.spec.d.ts +1 -0
  59. package/dist/services/onboarding/spec/fetch-events/customer-domain-document-response.spec.js +39 -0
  60. package/dist/services/onboarding/spec/file-events/file-watcher.spec.d.ts +1 -0
  61. package/dist/services/onboarding/spec/file-events/file-watcher.spec.js +67 -0
  62. package/dist/services/onboarding/spec/html-charset.spec.d.ts +1 -0
  63. package/dist/services/onboarding/spec/html-charset.spec.js +58 -0
  64. package/dist/services/onboarding/spec/virtual-orestes-app/index.spec.d.ts +1 -0
  65. package/dist/services/onboarding/spec/virtual-orestes-app/index.spec.js +19 -0
  66. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +5 -0
  67. package/dist/services/onboarding/virtual-orestes-app/index.js +3 -26
  68. package/dist/services/pull/pull-service.js +23 -5
  69. package/dist/services/query-builder/query-builder-factory.js +3 -3
  70. package/oclif.manifest.json +1 -1
  71. package/package.json +3 -2
@@ -13,9 +13,18 @@ export default class CustomerConfigHandler implements DeployHandlerInterface {
13
13
  private cli;
14
14
  private builder;
15
15
  private policy;
16
+ /** The confirmed features that differ from the installation. */
17
+ private features;
18
+ /** The confirmed version tags that differ from the installation. */
19
+ private versions;
16
20
  constructor(customer: CustomerConfig, configApi: ConfigApiService, configName: string, diffService: DiffEngine, cli: CliServiceInterface, builder: InstallResourceBuilder, policy: DeployPolicyInterface);
17
21
  canHandle(type: FILE_TYPE): boolean;
18
22
  handle(files: CustomerConfigFile[]): Promise<void>;
19
23
  upload(files: CustomerConfigFile[]): Promise<void>;
24
+ /**
25
+ * The fields whose local value differs from the installation, once confirmed. A field that the
26
+ * config omits is `null`, so the diff shows its reset.
27
+ */
28
+ private confirmChanges;
20
29
  private handleMissingRemoteInstallResource;
21
30
  }
@@ -1,4 +1,4 @@
1
- import { FILE_TYPE, } from "../../integration-api/index.js";
1
+ import { changedFields, FILE_TYPE, VERSION_FIELDS, versionsOfConfig, versionsOfInstall, } from "../../integration-api/index.js";
2
2
  import chalk from "chalk";
3
3
  import { DeployQuestion } from "../policy/index.js";
4
4
  import { DeployAbortedError } from "../error/deploy-aborted-error.js";
@@ -10,6 +10,10 @@ export default class CustomerConfigHandler {
10
10
  cli;
11
11
  builder;
12
12
  policy;
13
+ /** The confirmed features that differ from the installation. */
14
+ features = {};
15
+ /** The confirmed version tags that differ from the installation. */
16
+ versions = {};
13
17
  constructor(customer, configApi, configName, diffService, cli, builder, policy) {
14
18
  this.customer = customer;
15
19
  this.configApi = configApi;
@@ -26,6 +30,8 @@ export default class CustomerConfigHandler {
26
30
  const installResource = await this.configApi.getActiveInstall(this.configName);
27
31
  const file = files[0];
28
32
  const config = file.config;
33
+ this.features = await this.confirmChanges(DeployQuestion.UpdateFeatures, "features", config.features, installResource?.features);
34
+ this.versions = await this.confirmChanges(DeployQuestion.UpdateVersions, "version tags", versionsOfConfig(config), versionsOfInstall(installResource));
29
35
  if (!installResource) {
30
36
  await this.handleMissingRemoteInstallResource(config);
31
37
  this.cli.write("with origins:", true);
@@ -58,12 +64,41 @@ export default class CustomerConfigHandler {
58
64
  async upload(files) {
59
65
  const file = files[0];
60
66
  const installResource = await this.builder.init(this.configName);
61
- if (file.shouldSkipFile()) {
62
- // if installResource already exists its possible to skip the origin update
63
- return;
67
+ const updatesFeatures = Object.keys(this.features).length > 0;
68
+ const updatesVersions = Object.keys(this.versions).length > 0;
69
+ if (updatesFeatures) {
70
+ installResource.features = {
71
+ ...installResource.features,
72
+ ...this.features,
73
+ };
74
+ }
75
+ for (const [tag, value] of Object.entries(this.versions)) {
76
+ installResource[VERSION_FIELDS[tag]] = value;
77
+ }
78
+ // if installResource already exists its possible to skip the origin update
79
+ if (!file.shouldSkipFile()) {
80
+ installResource.origins = file.config.origins;
81
+ }
82
+ if (updatesFeatures || updatesVersions || !file.shouldSkipFile()) {
83
+ this.builder.merge(installResource);
84
+ }
85
+ }
86
+ /**
87
+ * The fields whose local value differs from the installation, once confirmed. A field that the
88
+ * config omits is `null`, so the diff shows its reset.
89
+ */
90
+ async confirmChanges(question, label, local, live) {
91
+ const changed = changedFields(local, live);
92
+ if (Object.keys(changed).length === 0) {
93
+ return {};
94
+ }
95
+ // Unbuffered, so the diff shows before the question.
96
+ this.cli.write(`will update ${label}:`);
97
+ for (const [name, value] of Object.entries(changed)) {
98
+ this.cli.code(`${name}: ${JSON.stringify(live?.[name] ?? null)} -> ${JSON.stringify(value)}`);
64
99
  }
65
- installResource.origins = file.config.origins;
66
- this.builder.merge(installResource);
100
+ const update = await this.policy.confirm(question, `Update ${label}?`, true);
101
+ return update ? changed : {};
67
102
  }
68
103
  async handleMissingRemoteInstallResource(config) {
69
104
  const configName = config?.name || this.configName;
@@ -6,9 +6,15 @@ export default interface Install extends Partial<InstallConfigs<string>> {
6
6
  createdAt?: Date;
7
7
  updatedAt?: Date;
8
8
  status?: string;
9
- swVersion?: string;
9
+ swVersion?: string | null;
10
+ rumVersion?: string | null;
11
+ ppVersion?: string | null;
12
+ configPluginsVersion?: string | null;
13
+ documentHandlerVersion?: string | null;
10
14
  domain: string;
11
15
  configVersion?: number;
12
16
  description?: string;
13
17
  origins?: string[];
18
+ /** The feature flags, under the field names the installation stores. */
19
+ features?: Record<string, unknown>;
14
20
  }
@@ -1,3 +1,4 @@
1
+ import { changedFields, versionsOfConfig, versionsOfInstall, } from "../../integration-api/index.js";
1
2
  import { InstallResourceToFileMapping } from "../../pull/index.js";
2
3
  /** How the live installation relates to the merge request. */
3
4
  export var LiveState;
@@ -13,6 +14,10 @@ export var LiveState;
13
14
  })(LiveState || (LiveState = {}));
14
15
  /** The origins are one file of the comparison, under the name of their file. */
15
16
  const ORIGINS = "config_customer(origins)";
17
+ /** The features are one file of the comparison, under the name of their file. */
18
+ const FEATURES = "config_customer(features)";
19
+ /** The version tags are one file of the comparison, under the name of their file. */
20
+ const VERSIONS = "config_customer(versions)";
16
21
  /**
17
22
  * Compares the live installation with the state before the merge request.
18
23
  *
@@ -57,6 +62,12 @@ export class LiveStateCheck {
57
62
  JSON.stringify([...right.origins].sort())) {
58
63
  differences.push(ORIGINS);
59
64
  }
65
+ if (Object.keys(changedFields(left.features, right.features)).length) {
66
+ differences.push(FEATURES);
67
+ }
68
+ if (Object.keys(changedFields(left.versions, right.versions)).length) {
69
+ differences.push(VERSIONS);
70
+ }
60
71
  return differences;
61
72
  }
62
73
  stateOfFiles(files) {
@@ -66,9 +77,12 @@ export class LiveStateCheck {
66
77
  contents[file.remoteKey] = file.getContent();
67
78
  }
68
79
  }
80
+ const config = files.getCustomerConfig()?.config;
69
81
  return {
70
82
  contents,
71
- origins: files.getCustomerConfig()?.config?.origins ?? [],
83
+ origins: config?.origins ?? [],
84
+ features: config?.features ?? {},
85
+ versions: versionsOfConfig(config),
72
86
  };
73
87
  }
74
88
  stateOfInstall(install) {
@@ -76,6 +90,11 @@ export class LiveStateCheck {
76
90
  for (const key of Object.keys(InstallResourceToFileMapping)) {
77
91
  contents[key] = install[key] ?? "";
78
92
  }
79
- return { contents, origins: install.origins ?? [] };
93
+ return {
94
+ contents,
95
+ origins: install.origins ?? [],
96
+ features: install.features ?? {},
97
+ versions: versionsOfInstall(install),
98
+ };
80
99
  }
81
100
  }
@@ -53,6 +53,8 @@ export class AutoDeployPolicy {
53
53
  // The reviewed change itself.
54
54
  case DeployQuestion.UpdateFile:
55
55
  case DeployQuestion.UpdateOrigins:
56
+ case DeployQuestion.UpdateFeatures:
57
+ case DeployQuestion.UpdateVersions:
56
58
  case DeployQuestion.DeleteInstallResourceKey:
57
59
  case DeployQuestion.UploadModules:
58
60
  case DeployQuestion.UploadServerConfig: {
@@ -9,6 +9,10 @@ export declare enum DeployQuestion {
9
9
  UpdateFile = "updateFile",
10
10
  /** Take over the local origins into the installation. */
11
11
  UpdateOrigins = "updateOrigins",
12
+ /** Take over the local feature flags into the installation. */
13
+ UpdateFeatures = "updateFeatures",
14
+ /** Take over the local version tags into the installation. */
15
+ UpdateVersions = "updateVersions",
12
16
  /** Create a configuration that does not exist in the app yet. */
13
17
  CreateConfig = "createConfig",
14
18
  /** Drop a resource whose local file is gone. */
@@ -10,6 +10,10 @@ export var DeployQuestion;
10
10
  DeployQuestion["UpdateFile"] = "updateFile";
11
11
  /** Take over the local origins into the installation. */
12
12
  DeployQuestion["UpdateOrigins"] = "updateOrigins";
13
+ /** Take over the local feature flags into the installation. */
14
+ DeployQuestion["UpdateFeatures"] = "updateFeatures";
15
+ /** Take over the local version tags into the installation. */
16
+ DeployQuestion["UpdateVersions"] = "updateVersions";
13
17
  /** Create a configuration that does not exist in the app yet. */
14
18
  DeployQuestion["CreateConfig"] = "createConfig";
15
19
  /** Drop a resource whose local file is gone. */
@@ -18,6 +18,8 @@ export class TestingDeployPolicy {
18
18
  // The content of the new installation.
19
19
  case DeployQuestion.UpdateFile:
20
20
  case DeployQuestion.UpdateOrigins:
21
+ case DeployQuestion.UpdateFeatures:
22
+ case DeployQuestion.UpdateVersions:
21
23
  case DeployQuestion.CreateConfig:
22
24
  case DeployQuestion.DeleteInstallResourceKey:
23
25
  case DeployQuestion.UploadInstallResource:
@@ -0,0 +1,98 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import CustomerConfigHandler from "../../handler/customer-config-handler.js";
4
+ import InstallResourceBuilder from "../../builder/install-resource-builder.js";
5
+ import { DiffEngine, NoDiffSink } from "../../../diff/index.js";
6
+ import { changedFields, } from "../../../integration-api/index.js";
7
+ import { DeployQuestion } from "../../policy/index.js";
8
+ const ORIGINS = ["https://www.example.com"];
9
+ /** A deploy of `features` against a live installation with the same origins. */
10
+ async function deploy(features, live, versions = {}, liveVersions = {}) {
11
+ const install = {
12
+ domain: "production",
13
+ configVersion: 1,
14
+ origins: [...ORIGINS],
15
+ features: live,
16
+ ...liveVersions,
17
+ };
18
+ const configApi = {
19
+ getActiveInstall: async () => structuredClone(install),
20
+ };
21
+ const questions = [];
22
+ /** The console output and the questions, in their order. */
23
+ const output = [];
24
+ const policy = {
25
+ confirm: async (question) => {
26
+ questions.push(question);
27
+ output.push(`? ${question}`);
28
+ return true;
29
+ },
30
+ };
31
+ const cli = new Proxy({}, {
32
+ get: (_, method) => (message, buffered = false) => output.push(`${method}${buffered ? " (buffered)" : ""}: ${message}`),
33
+ });
34
+ const builder = new InstallResourceBuilder(configApi);
35
+ let skipped = false;
36
+ const file = {
37
+ config: {
38
+ origins: [...ORIGINS],
39
+ features,
40
+ ...versions,
41
+ },
42
+ skipFile: () => (skipped = true),
43
+ shouldSkipFile: () => skipped,
44
+ };
45
+ const handler = new CustomerConfigHandler({}, configApi, "production", new DiffEngine({ sink: new NoDiffSink() }), cli, builder, policy);
46
+ await handler.handle([file]);
47
+ await handler.upload([file]);
48
+ return { builder, questions, output };
49
+ }
50
+ describe("CustomerConfigHandler", () => {
51
+ it("uploads a changed feature although the origins are the same", async () => {
52
+ const { builder, questions } = await deploy({ embeddedConfig: true, enableSpeedKitConfigPlugins: null }, { embeddedConfig: false, suppressOriginNoStore: true });
53
+ expect(questions).to.deep.equal([DeployQuestion.UpdateFeatures]);
54
+ expect(builder.hasChanges()).to.equal(true);
55
+ // An omitted feature is null, so the deploy resets it.
56
+ expect(builder.getInstallResource().features).to.deep.equal({
57
+ embeddedConfig: true,
58
+ suppressOriginNoStore: null,
59
+ });
60
+ });
61
+ it("changes nothing while the installation has the features", async () => {
62
+ const { builder, questions } = await deploy({ embeddedConfig: true }, { embeddedConfig: true });
63
+ expect(questions).to.deep.equal([]);
64
+ expect(builder.hasChanges()).to.equal(false);
65
+ });
66
+ });
67
+ describe("CustomerConfigHandler version tags", () => {
68
+ it("stores a tag in its installation field, and resets an omitted one", async () => {
69
+ const { builder, questions } = await deploy({}, {}, { speedKitVersion: "2.22.4" }, { swVersion: "2.21.0", rumVersion: "@release" });
70
+ expect(questions).to.deep.equal([DeployQuestion.UpdateVersions]);
71
+ expect(builder.getInstallResource()).to.include({
72
+ swVersion: "2.22.4",
73
+ rumVersion: null,
74
+ });
75
+ });
76
+ });
77
+ describe("CustomerConfigHandler diff", () => {
78
+ it("shows the diff of the features and the version tags before each question", async () => {
79
+ const { output } = await deploy({ embeddedConfig: true }, { suppressOriginNoStore: true }, { speedKitVersion: "2.22.4" }, { swVersion: "2.21.0" });
80
+ expect(output.slice(0, 7)).to.deep.equal([
81
+ "write: will update features:",
82
+ "code: embeddedConfig: null -> true",
83
+ "code: suppressOriginNoStore: true -> null",
84
+ `? ${DeployQuestion.UpdateFeatures}`,
85
+ "write: will update version tags:",
86
+ 'code: speedKitVersion: "2.21.0" -> "2.22.4"',
87
+ `? ${DeployQuestion.UpdateVersions}`,
88
+ ]);
89
+ });
90
+ });
91
+ describe("changedFields", () => {
92
+ it("resets a feature the config omits", () => {
93
+ expect(changedFields({ embeddedConfig: false, allowCaseSensitiveVariation: null }, { prefetchingOnDeploymentJob: true, allowCaseSensitiveVariation: null })).to.deep.equal({
94
+ embeddedConfig: false,
95
+ prefetchingOnDeploymentJob: null,
96
+ });
97
+ });
98
+ });
@@ -4,7 +4,7 @@ import { LiveState, LiveStateCheck } from "../../mr/live-state-check.js";
4
4
  import { DiffEngine, NoDiffSink } from "../../../diff/index.js";
5
5
  const ORIGINS = ["https://www.example.com"];
6
6
  /** A configuration of the install resource files it holds. */
7
- function configuration(files, origins = ORIGINS) {
7
+ function configuration(files, origins = ORIGINS, features) {
8
8
  const resources = Object.entries(files).map(([remoteKey, content]) => ({
9
9
  remoteKey,
10
10
  name: remoteKey,
@@ -13,11 +13,11 @@ function configuration(files, origins = ORIGINS) {
13
13
  }));
14
14
  return {
15
15
  getInstallResources: () => resources,
16
- getCustomerConfig: () => ({ config: { origins } }),
16
+ getCustomerConfig: () => ({ config: { origins, features } }),
17
17
  };
18
18
  }
19
- function installOf(files, origins = ORIGINS) {
20
- return { domain: "production", origins, ...files };
19
+ function installOf(files, origins = ORIGINS, features) {
20
+ return { domain: "production", origins, features, ...files };
21
21
  }
22
22
  const check = new LiveStateCheck(new DiffEngine({ sink: new NoDiffSink() }));
23
23
  describe("LiveStateCheck", () => {
@@ -71,4 +71,45 @@ describe("LiveStateCheck", () => {
71
71
  const result = check.compare(base, base, null);
72
72
  expect(result.state).to.equal(LiveState.Missing);
73
73
  });
74
+ it("deploys a merge request that only turns on a feature", () => {
75
+ const base = configuration({ config: "same" }, ORIGINS, {
76
+ embeddedConfig: false,
77
+ });
78
+ const local = configuration({ config: "same" }, ORIGINS, {
79
+ embeddedConfig: true,
80
+ });
81
+ const live = installOf({ config: "same" }, ORIGINS, {
82
+ embeddedConfig: false,
83
+ });
84
+ expect(check.isUnchanged(base, local)).to.equal(false);
85
+ expect(check.compare(base, local, live).state).to.equal(LiveState.Reviewed);
86
+ });
87
+ it("names the features when live changed one", () => {
88
+ const features = { embeddedConfig: false };
89
+ const base = configuration({ config: "same" }, ORIGINS, features);
90
+ const local = configuration({ config: "after" }, ORIGINS, features);
91
+ const result = check.compare(base, local, installOf({ config: "same" }, ORIGINS, { embeddedConfig: true }));
92
+ expect(result.state).to.equal(LiveState.Drifted);
93
+ expect(result.driftedFiles).to.deep.equal(["config_customer(features)"]);
94
+ });
95
+ it("calls a feature that only live sets drift, because the deploy resets it", () => {
96
+ const base = configuration({ config: "before" });
97
+ const local = configuration({ config: "after" });
98
+ const result = check.compare(base, local, installOf({ config: "before" }, ORIGINS, {
99
+ suppressOriginNoStore: true,
100
+ embeddedConfig: null,
101
+ }));
102
+ expect(result.state).to.equal(LiveState.Drifted);
103
+ expect(result.driftedFiles).to.deep.equal(["config_customer(features)"]);
104
+ });
105
+ it("names the version tags when live pins another build", () => {
106
+ const base = configuration({ config: "before" });
107
+ const local = configuration({ config: "after" });
108
+ const result = check.compare(base, local, {
109
+ ...installOf({ config: "before" }),
110
+ swVersion: "2.21.0",
111
+ });
112
+ expect(result.state).to.equal(LiveState.Drifted);
113
+ expect(result.driftedFiles).to.deep.equal(["config_customer(versions)"]);
114
+ });
74
115
  });
@@ -5,6 +5,8 @@ import { DeployQuestion } from "../../policy/deploy-policy-model.js";
5
5
  const REVIEWED = [
6
6
  DeployQuestion.UpdateFile,
7
7
  DeployQuestion.UpdateOrigins,
8
+ DeployQuestion.UpdateFeatures,
9
+ DeployQuestion.UpdateVersions,
8
10
  DeployQuestion.DeleteInstallResourceKey,
9
11
  DeployQuestion.UploadInstallResource,
10
12
  DeployQuestion.UploadModules,
@@ -15,6 +15,8 @@ describe("TestingDeployPolicy", () => {
15
15
  for (const question of [
16
16
  DeployQuestion.UpdateFile,
17
17
  DeployQuestion.UpdateOrigins,
18
+ DeployQuestion.UpdateFeatures,
19
+ DeployQuestion.UpdateVersions,
18
20
  DeployQuestion.CreateConfig,
19
21
  DeployQuestion.DeleteInstallResourceKey,
20
22
  DeployQuestion.UploadInstallResource,
@@ -37,7 +39,7 @@ describe("TestingDeployPolicy", () => {
37
39
  }
38
40
  it("answers every question of the deploy, so a new one needs a decision here", () => {
39
41
  // Fails when DeployQuestion grows: decide then whether a testing deploy may answer yes.
40
- expect(Object.values(DeployQuestion)).to.have.length(14);
42
+ expect(Object.values(DeployQuestion)).to.have.length(16);
41
43
  });
42
44
  it("gives the description, and nothing for another open question", async () => {
43
45
  expect(await policy.text(DeployQuestion.Description)).to.equal("branch feature/x");
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The browser mock that the server passes to a document handler, as in
3
+ * `orestes-node/helper/browserMock.js`. The embedded Speed Kit config runs in
4
+ * it, so a read such as `location.hostname` in `getCurrentHostConfig()` works.
5
+ * `location` points at the app domain, and `window` and `top` are the mock
6
+ * itself. It has no timers and no event listeners, like the server's mock.
7
+ *
8
+ * @param app the app whose domain `location` points to
9
+ * @returns the browser globals by name
10
+ */
11
+ export declare function createBrowserGlobals(app: string): Record<string, unknown>;
12
+ /** The browser global that `error` reports as not defined, or undefined for any other error. */
13
+ export declare function missingBrowserGlobal(error: unknown): string | undefined;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The browser mock that the server passes to a document handler, as in
3
+ * `orestes-node/helper/browserMock.js`. The embedded Speed Kit config runs in
4
+ * it, so a read such as `location.hostname` in `getCurrentHostConfig()` works.
5
+ * `location` points at the app domain, and `window` and `top` are the mock
6
+ * itself. It has no timers and no event listeners, like the server's mock.
7
+ *
8
+ * @param app the app whose domain `location` points to
9
+ * @returns the browser globals by name
10
+ */
11
+ export function createBrowserGlobals(app) {
12
+ const url = new URL(`https://${app}.app.baqend.com/`);
13
+ const location = {
14
+ href: url.href,
15
+ origin: url.origin,
16
+ protocol: url.protocol,
17
+ host: url.host,
18
+ hostname: url.hostname,
19
+ port: url.port,
20
+ pathname: url.pathname,
21
+ search: url.search,
22
+ hash: url.hash,
23
+ toString: () => url.href,
24
+ };
25
+ const noop = () => {
26
+ /* empty */
27
+ };
28
+ const document = {
29
+ cookie: "",
30
+ referrer: "",
31
+ getElementById: () => null,
32
+ querySelector: () => null,
33
+ querySelectorAll: () => [],
34
+ createElement: noop,
35
+ };
36
+ document.head = document;
37
+ document.body = document;
38
+ const browserGlobals = {
39
+ location,
40
+ APP: app,
41
+ speedKit: {
42
+ split: undefined,
43
+ splitTestId: undefined,
44
+ detectDevice: noop,
45
+ customVariation: [],
46
+ },
47
+ serviceWorkerUrl: "",
48
+ screen: { width: 0, height: 0 },
49
+ devicePixelRatio: 1,
50
+ navigator: {
51
+ userAgent: "",
52
+ connection: {},
53
+ cookieEnabled: false,
54
+ languages: [],
55
+ online: true,
56
+ },
57
+ document,
58
+ localStorage: { getItem: noop, setItem: noop },
59
+ };
60
+ browserGlobals.window = browserGlobals;
61
+ browserGlobals.top = browserGlobals;
62
+ return browserGlobals;
63
+ }
64
+ const BROWSER_GLOBALS = Object.keys(createBrowserGlobals("local"));
65
+ /** The browser global that `error` reports as not defined, or undefined for any other error. */
66
+ export function missingBrowserGlobal(error) {
67
+ const name = /^(\S+) is not defined$/.exec(error?.message ?? "")?.[1];
68
+ return name && BROWSER_GLOBALS.includes(name) ? name : undefined;
69
+ }
@@ -13,6 +13,11 @@ 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 `enableSpeedKitConfigPlugins` feature: the handler, its config
18
+ * and the Speed Kit config in one CommonJS module, which exports `post`.
19
+ */
20
+ private documentHandlerBundle?;
16
21
  private database;
17
22
  /** Sources of app modules already looked up; `null` marks a lookup that came back empty. */
18
23
  private readonly appModules;
@@ -22,11 +27,33 @@ export declare class DocumentHandlerServer {
22
27
  */
23
28
  constructor(customerConfig: CustomerConfig, files: FileListInterface, bundler: BundleService, cli: CliServiceInterface, workSpace: string, verboseLevel?: boolean, entityManager?: EntityManager);
24
29
  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
+ /**
33
+ * Loads the packjockel bundle like a CommonJS module, and calls the `post` it exports. The browser mock
34
+ * shadows the globals of the bundle, as on the server.
35
+ */
36
+ private createBundleScript;
37
+ /**
38
+ * Loads the bundle once without the browser mock. The service worker embeds the config without a browser
39
+ * around it, so the server's proof rejects a config that reads a browser global while it loads.
40
+ *
41
+ * @returns the browser global the config reads, or undefined
42
+ */
43
+ private findBrowserGlobalRead;
44
+ private getDocumentHandlerConfigPath;
25
45
  private getTransformFunctionWrapper;
26
46
  buildDocumentHandler(): Promise<void>;
47
+ /**
48
+ * Bundles the handler, its config and the Speed Kit config into one module, the way the server
49
+ * deploys a customer with the `enableSpeedKitConfigPlugins` feature.
50
+ */
51
+ private bundleWithPackjockel;
27
52
  private deactivateReleaseAndDeploymentDetection;
28
53
  private getDocumentHandler;
29
54
  private getDynamicFetcher;
55
+ /** The customer's own dynamic fetcher, or else the source of the latest one. */
56
+ private getDynamicFetcherSource;
30
57
  private getDynamicFetcherConfig;
31
58
  private getStyles;
32
59
  private getDocumentHandlerConfig;