@speedkit/cli 4.44.0-beta.6 → 4.44.0-beta.7

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 (28) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/services/bundler/packjockel-service.d.ts +1 -1
  3. package/dist/services/bundler/packjockel-service.js +1 -1
  4. package/dist/services/bundler/spec/packjockel-service.spec.js +2 -2
  5. package/dist/services/deploy/handler/customer-config-handler.d.ts +9 -0
  6. package/dist/services/deploy/handler/customer-config-handler.js +40 -6
  7. package/dist/services/deploy/interface/install.d.ts +7 -1
  8. package/dist/services/deploy/mr/live-state-check.js +21 -2
  9. package/dist/services/deploy/policy/auto-deploy-policy.js +2 -0
  10. package/dist/services/deploy/policy/deploy-policy-model.d.ts +4 -0
  11. package/dist/services/deploy/policy/deploy-policy-model.js +4 -0
  12. package/dist/services/deploy/spec/handler/customer-config-handler.spec.d.ts +1 -0
  13. package/dist/services/deploy/spec/handler/customer-config-handler.spec.js +79 -0
  14. package/dist/services/deploy/spec/mr/live-state-check.spec.js +45 -4
  15. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +2 -0
  16. package/dist/services/document-handler-runtime/document-handler-server.js +1 -1
  17. package/dist/services/integration-api/integration-api-model.d.ts +2 -0
  18. package/dist/services/integration-api/spec/customer-config-file.spec.d.ts +1 -0
  19. package/dist/services/integration-api/spec/customer-config-file.spec.js +56 -0
  20. package/dist/services/integration-api/struct/customer-config-file.d.ts +15 -0
  21. package/dist/services/integration-api/struct/customer-config-file.js +42 -0
  22. package/dist/services/integration-api/struct/customer-config.d.ts +24 -3
  23. package/dist/services/integration-api/struct/customer-config.js +41 -4
  24. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +1 -1
  25. package/dist/services/integration-api/struct/speed-kit-config-file.js +2 -2
  26. package/dist/services/pull/pull-service.js +23 -5
  27. package/oclif.manifest.json +1 -1
  28. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [4.44.0-beta.7](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.44.0-beta.6...v4.44.0-beta.7) (2026-10-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **integration-api:** name the feature embeddedConfig like the installation stores it ([9a8504c](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/9a8504cf2801bf66dc84fdfaed1c87f128eea42e))
7
+
8
+
9
+ ### Features
10
+
11
+ * **deploy:** reset omitted features, and sync the version tags with the installation ([6f14f7f](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/6f14f7f2c4611469266f7671e939a0c603645204))
12
+ * **deploy:** sync the feature flags of config_customer.json with the installation ([1ef84b0](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/1ef84b0bb9cd35b26eed23a8227f696231ae0ea7))
13
+ * **integration-api:** name the RUM tag rumPluginsVersion like configPluginsVersion ([335cb60](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/335cb60140a2d97391999b35bfbec46304c6da6f))
14
+
1
15
  # [4.44.0-beta.6](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.44.0-beta.5...v4.44.0-beta.6) (2026-10-28)
2
16
 
3
17
 
@@ -6,7 +6,7 @@
6
6
  export interface AssetVersions {
7
7
  /** Speed Kit: snippet, service worker and dynamic fetcher */
8
8
  speedKitVersion?: string;
9
- rumPluginVersion?: string;
9
+ rumPluginsVersion?: string;
10
10
  /** predictive preloading */
11
11
  ppVersion?: string;
12
12
  configPluginsVersion?: string;
@@ -6,7 +6,7 @@ import { binaryPath } from "@speedkit/packjockel";
6
6
  import { PackjockelError } from "./error/packjockel-error.js";
7
7
  const VERSION_FLAGS = {
8
8
  speedKitVersion: "--speed-kit-version",
9
- rumPluginVersion: "--rum-plugin-version",
9
+ rumPluginsVersion: "--rum-plugin-version",
10
10
  ppVersion: "--pp-version",
11
11
  configPluginsVersion: "--config-plugins-version",
12
12
  documentHandlerVersion: "--document-handler-version",
@@ -60,7 +60,7 @@ describe("PackjockelService", () => {
60
60
  it("should bundle the entry points in their order", async () => {
61
61
  const bundle = await service.bundle({
62
62
  entryPoints: { "rum.js": "rum()", "config.js": "SpeedKit.config = {}" },
63
- versions: { configPluginsVersion: "@release", rumPluginVersion: "" },
63
+ versions: { configPluginsVersion: "@release", rumPluginsVersion: "" },
64
64
  define: { APP: '"shop"' },
65
65
  platform: "browser",
66
66
  });
@@ -151,7 +151,7 @@ describe("PackjockelService", () => {
151
151
  versions: {
152
152
  documentHandlerVersion: "1.8.0",
153
153
  speedKitVersion: "2.22.4",
154
- rumPluginVersion: "@release",
154
+ rumPluginsVersion: "@release",
155
155
  },
156
156
  });
157
157
  const { args, inputs } = await recorded();
@@ -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: DiffService, 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,40 @@ 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
+ this.cli.write(`will update ${label}:`, true);
96
+ for (const [name, value] of Object.entries(changed)) {
97
+ this.cli.code(`${name}: ${JSON.stringify(live?.[name] ?? null)} -> ${JSON.stringify(value)}`, true);
64
98
  }
65
- installResource.origins = file.config.origins;
66
- this.builder.merge(installResource);
99
+ const update = await this.policy.confirm(question, `Update ${label}?`, true);
100
+ return update ? changed : {};
67
101
  }
68
102
  async handleMissingRemoteInstallResource(config) {
69
103
  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
  }
@@ -46,6 +46,8 @@ export class AutoDeployPolicy {
46
46
  // The reviewed change itself.
47
47
  case DeployQuestion.UpdateFile:
48
48
  case DeployQuestion.UpdateOrigins:
49
+ case DeployQuestion.UpdateFeatures:
50
+ case DeployQuestion.UpdateVersions:
49
51
  case DeployQuestion.DeleteInstallResourceKey:
50
52
  case DeployQuestion.UploadModules:
51
53
  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. */
@@ -0,0 +1,79 @@
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 { DiffService } 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
+ const policy = {
23
+ confirm: async (question) => {
24
+ questions.push(question);
25
+ return true;
26
+ },
27
+ };
28
+ const cli = new Proxy({}, { get: () => () => undefined });
29
+ const builder = new InstallResourceBuilder(configApi);
30
+ let skipped = false;
31
+ const file = {
32
+ config: {
33
+ origins: [...ORIGINS],
34
+ features,
35
+ ...versions,
36
+ },
37
+ skipFile: () => (skipped = true),
38
+ shouldSkipFile: () => skipped,
39
+ };
40
+ const handler = new CustomerConfigHandler({}, configApi, "production", new DiffService({}), cli, builder, policy);
41
+ await handler.handle([file]);
42
+ await handler.upload([file]);
43
+ return { builder, questions };
44
+ }
45
+ describe("CustomerConfigHandler", () => {
46
+ it("uploads a changed feature although the origins are the same", async () => {
47
+ const { builder, questions } = await deploy({ embeddedConfig: true, enableSpeedKitConfigPlugins: null }, { embeddedConfig: false, suppressOriginNoStore: true });
48
+ expect(questions).to.deep.equal([DeployQuestion.UpdateFeatures]);
49
+ expect(builder.hasChanges()).to.equal(true);
50
+ // An omitted feature is null, so the deploy resets it.
51
+ expect(builder.getInstallResource().features).to.deep.equal({
52
+ embeddedConfig: true,
53
+ suppressOriginNoStore: null,
54
+ });
55
+ });
56
+ it("changes nothing while the installation has the features", async () => {
57
+ const { builder, questions } = await deploy({ embeddedConfig: true }, { embeddedConfig: true });
58
+ expect(questions).to.deep.equal([]);
59
+ expect(builder.hasChanges()).to.equal(false);
60
+ });
61
+ });
62
+ describe("CustomerConfigHandler version tags", () => {
63
+ it("stores a tag in its installation field, and resets an omitted one", async () => {
64
+ const { builder, questions } = await deploy({}, {}, { speedKitVersion: "2.22.4" }, { swVersion: "2.21.0", rumVersion: "@release" });
65
+ expect(questions).to.deep.equal([DeployQuestion.UpdateVersions]);
66
+ expect(builder.getInstallResource()).to.include({
67
+ swVersion: "2.22.4",
68
+ rumVersion: null,
69
+ });
70
+ });
71
+ });
72
+ describe("changedFields", () => {
73
+ it("resets a feature the config omits", () => {
74
+ expect(changedFields({ embeddedConfig: false, allowCaseSensitiveVariation: null }, { prefetchingOnDeploymentJob: true, allowCaseSensitiveVariation: null })).to.deep.equal({
75
+ embeddedConfig: false,
76
+ prefetchingOnDeploymentJob: null,
77
+ });
78
+ });
79
+ });
@@ -4,7 +4,7 @@ import { LiveState, LiveStateCheck } from "../../mr/live-state-check.js";
4
4
  import { DiffService } 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 DiffService({}));
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,
@@ -155,7 +155,7 @@ export class DocumentHandlerServer {
155
155
  ? this.findBrowserGlobalRead()
156
156
  : undefined;
157
157
  if (read) {
158
- this.cli.failAction("DOCUMENTHANDLER:BUILD", `embedded_config: the Speed Kit config reads "${read}" while it loads, so the server rejects it. Read it in a callback, or turn embedded_config off.`);
158
+ this.cli.failAction("DOCUMENTHANDLER:BUILD", `embeddedConfig: the Speed Kit config reads "${read}" while it loads, so the server rejects it. Read it in a callback, or turn embeddedConfig off.`);
159
159
  return;
160
160
  }
161
161
  this.cli.successAction("DOCUMENTHANDLER:BUILD");
@@ -95,6 +95,8 @@ export interface SpeedKitConfigInterface extends InstallResourceInterface {
95
95
  export interface CustomerConfigInterface extends ConfigFileInterface {
96
96
  config: CustomerConfig;
97
97
  updateOrigins(origins: string[]): void;
98
+ updateFeatures(live?: Record<string, unknown>): boolean;
99
+ updateVersions(live: Record<string, unknown>): boolean;
98
100
  readonly configName: string;
99
101
  }
100
102
  export interface VirtualFileRecipe {
@@ -0,0 +1,56 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { CustomerConfig, CustomerConfigFile, } from "../../integration-api/index.js";
4
+ function fileWith(production) {
5
+ const content = JSON.stringify({ production }, null, 2);
6
+ return new CustomerConfigFile("config_customer.json", "config_customer.json", content, CustomerConfig.createFrom(production, "production"), "production");
7
+ }
8
+ const BASE = {
9
+ app: "example-shop",
10
+ domain: "production",
11
+ origins: ["https://www.example.com"],
12
+ swPath: "/sw.js",
13
+ scope: "/",
14
+ };
15
+ describe("CustomerConfigFile.updateFeatures", () => {
16
+ it("takes over the features the installation sets", () => {
17
+ const file = fileWith({ ...BASE, features: { embeddedConfig: false } });
18
+ const changed = file.updateFeatures({
19
+ embeddedConfig: true,
20
+ prefetchingOnDeploymentJob: null,
21
+ });
22
+ expect(changed).to.equal(true);
23
+ expect(JSON.parse(file.getContent()).production.features).to.deep.equal({
24
+ embeddedConfig: true,
25
+ });
26
+ expect(file.config.features).to.deep.equal({ embeddedConfig: true });
27
+ });
28
+ it("drops the features when the installation sets none", () => {
29
+ const file = fileWith({ ...BASE, features: { embeddedConfig: true } });
30
+ expect(file.updateFeatures({ embeddedConfig: null })).to.equal(true);
31
+ expect(JSON.parse(file.getContent()).production).to.not.have.property("features");
32
+ });
33
+ it("leaves an equal file alone", () => {
34
+ const file = fileWith({ ...BASE, features: { embeddedConfig: true } });
35
+ const before = file.getContent();
36
+ expect(file.updateFeatures({ embeddedConfig: true })).to.equal(false);
37
+ expect(file.getContent()).to.equal(before);
38
+ });
39
+ });
40
+ describe("CustomerConfigFile.updateVersions", () => {
41
+ it("writes the tags of the installation and drops the ones at latest", () => {
42
+ const file = fileWith({ ...BASE, ppVersion: "1.2.0" });
43
+ const changed = file.updateVersions({
44
+ speedKitVersion: "2.22.4",
45
+ rumPluginsVersion: null,
46
+ ppVersion: null,
47
+ configPluginsVersion: null,
48
+ documentHandlerVersion: null,
49
+ });
50
+ const production = JSON.parse(file.getContent()).production;
51
+ expect(changed).to.equal(true);
52
+ expect(production.speedKitVersion).to.equal("2.22.4");
53
+ expect(production).to.not.have.property("ppVersion");
54
+ expect(file.config.speedKitVersion).to.equal("2.22.4");
55
+ });
56
+ });
@@ -1,4 +1,5 @@
1
1
  import { CustomerConfig, File, CustomerConfigInterface, FILE_TYPE } from "../integration-api-model.js";
2
+ import { VersionTag } from "./customer-config.js";
2
3
  export declare class CustomerConfigFile extends File implements CustomerConfigInterface {
3
4
  config: CustomerConfig;
4
5
  readonly configName: string;
@@ -7,5 +8,19 @@ export declare class CustomerConfigFile extends File implements CustomerConfigIn
7
8
  constructor(name: string, path: string, content: string, config: CustomerConfig, configName: string, testApp?: string);
8
9
  setContent(content: string): void;
9
10
  updateOrigins(origins: string[]): void;
11
+ /**
12
+ * Takes over the features the installation sets. The file then holds exactly these, and none
13
+ * when the installation sets none.
14
+ *
15
+ * @returns whether the features changed
16
+ */
17
+ updateFeatures(live?: Record<string, unknown>): boolean;
18
+ /**
19
+ * Takes over the version tags of the installation. A tag the installation leaves at `latest` is
20
+ * removed from the file.
21
+ *
22
+ * @returns whether a tag changed
23
+ */
24
+ updateVersions(live: Record<VersionTag, unknown>): boolean;
10
25
  private updateConfigByContent;
11
26
  }
@@ -2,6 +2,7 @@ import { CustomerConfig, File, FILE_TYPE, } from "../integration-api-model.js";
2
2
  import { safe } from "../../../helpers/safe.js";
3
3
  import CustomerConfigError from "../error/customer-config-error.js";
4
4
  import { isSame } from "../array-helper.js";
5
+ import { declaredFields, versionsOfConfig, } from "./customer-config.js";
5
6
  export class CustomerConfigFile extends File {
6
7
  config;
7
8
  configName;
@@ -28,6 +29,47 @@ export class CustomerConfigFile extends File {
28
29
  configContent[this.configName].origins = origins;
29
30
  this.setContent(JSON.stringify(configContent, null, 2));
30
31
  }
32
+ /**
33
+ * Takes over the features the installation sets. The file then holds exactly these, and none
34
+ * when the installation sets none.
35
+ *
36
+ * @returns whether the features changed
37
+ */
38
+ updateFeatures(live) {
39
+ const features = declaredFields(live);
40
+ if (JSON.stringify(declaredFields(this.config.features)) ===
41
+ JSON.stringify(features)) {
42
+ return false;
43
+ }
44
+ const configContent = JSON.parse(this.getContent());
45
+ if (Object.keys(features).length > 0) {
46
+ configContent[this.configName].features = features;
47
+ }
48
+ else {
49
+ delete configContent[this.configName].features;
50
+ }
51
+ this.setContent(JSON.stringify(configContent, null, 2));
52
+ return true;
53
+ }
54
+ /**
55
+ * Takes over the version tags of the installation. A tag the installation leaves at `latest` is
56
+ * removed from the file.
57
+ *
58
+ * @returns whether a tag changed
59
+ */
60
+ updateVersions(live) {
61
+ if (JSON.stringify(versionsOfConfig(this.config)) === JSON.stringify(live)) {
62
+ return false;
63
+ }
64
+ const configContent = JSON.parse(this.getContent());
65
+ const others = Object.entries(configContent[this.configName]).filter(([key]) => !(key in live));
66
+ configContent[this.configName] = {
67
+ ...Object.fromEntries(others),
68
+ ...declaredFields(live),
69
+ };
70
+ this.setContent(JSON.stringify(configContent, null, 2));
71
+ return true;
72
+ }
31
73
  updateConfigByContent() {
32
74
  const configsResult = safe(() => {
33
75
  return JSON.parse(this.getContent());
@@ -1,6 +1,7 @@
1
1
  import type { AssetVersions } from "../../bundler/index.js";
2
2
  /**
3
- * The installation features of a config. `null` leaves a feature at its default.
3
+ * The installation features of a config, under the field names the installation stores. `sk deploy` sends
4
+ * them and `sk pull` writes them back. An omitted feature is `null`, so a deploy resets it.
4
5
  */
5
6
  export interface CustomerFeatures {
6
7
  /**
@@ -10,9 +11,29 @@ export interface CustomerFeatures {
10
11
  */
11
12
  enableSpeedKitConfigPlugins?: boolean | null;
12
13
  /** The server embeds the config into the service worker as well. */
13
- embedded_config?: boolean | null;
14
+ embeddedConfig?: boolean | null;
14
15
  [feature: string]: unknown;
15
16
  }
17
+ /** The fields that are set, without the `null` ones. */
18
+ export declare function declaredFields(features?: Record<string, unknown> | null): Record<string, unknown>;
19
+ /**
20
+ * The fields whose value in `local` differs from `live`, with the value of `local`. A field that either
21
+ * side omits is `null`.
22
+ */
23
+ export declare function changedFields(local?: Record<string, unknown> | null, live?: Record<string, unknown> | null): Record<string, unknown>;
24
+ /** Each version tag of a config, with the field of the installation that stores it. */
25
+ export declare const VERSION_FIELDS: {
26
+ readonly speedKitVersion: "swVersion";
27
+ readonly rumPluginsVersion: "rumVersion";
28
+ readonly ppVersion: "ppVersion";
29
+ readonly configPluginsVersion: "configPluginsVersion";
30
+ readonly documentHandlerVersion: "documentHandlerVersion";
31
+ };
32
+ export type VersionTag = keyof typeof VERSION_FIELDS;
33
+ /** The version tags of a config. A blank or omitted tag is `null`, which means `latest`. */
34
+ export declare function versionsOfConfig(config?: Partial<Record<VersionTag, unknown>> | null): Record<VersionTag, unknown>;
35
+ /** The version tags an installation stores, under the names of the config. */
36
+ export declare function versionsOfInstall(install?: object | null): Record<VersionTag, unknown>;
16
37
  export interface CustomerConfigs {
17
38
  production: CustomerConfig;
18
39
  [configName: string]: CustomerConfig;
@@ -44,7 +65,7 @@ export declare class CustomerConfig {
44
65
  */
45
66
  readonly speedKitVersion?: string;
46
67
  /** The tag of RUM for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
47
- readonly rumPluginVersion?: string;
68
+ readonly rumPluginsVersion?: string;
48
69
  /** The tag of predictive preloading for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
49
70
  readonly ppVersion?: string;
50
71
  /** The tag of the speed-kit-config plugins for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
@@ -1,4 +1,41 @@
1
1
  import CustomerConfigError from "../error/customer-config-error.js";
2
+ /** The fields that are set, without the `null` ones. */
3
+ export function declaredFields(features) {
4
+ return Object.fromEntries(Object.entries(features ?? {}).filter(([, value]) => value !== null && value !== undefined));
5
+ }
6
+ /**
7
+ * The fields whose value in `local` differs from `live`, with the value of `local`. A field that either
8
+ * side omits is `null`.
9
+ */
10
+ export function changedFields(local, live) {
11
+ const names = new Set([
12
+ ...Object.keys(local ?? {}),
13
+ ...Object.keys(live ?? {}),
14
+ ]);
15
+ return Object.fromEntries([...names]
16
+ .map((name) => [name, local?.[name] ?? null])
17
+ .filter(([name, value]) => JSON.stringify(value) !== JSON.stringify(live?.[name] ?? null)));
18
+ }
19
+ /** Each version tag of a config, with the field of the installation that stores it. */
20
+ export const VERSION_FIELDS = {
21
+ speedKitVersion: "swVersion",
22
+ rumPluginsVersion: "rumVersion",
23
+ ppVersion: "ppVersion",
24
+ configPluginsVersion: "configPluginsVersion",
25
+ documentHandlerVersion: "documentHandlerVersion",
26
+ };
27
+ /** The version tags of a config. A blank or omitted tag is `null`, which means `latest`. */
28
+ export function versionsOfConfig(config) {
29
+ return Object.fromEntries(Object.keys(VERSION_FIELDS).map((tag) => [tag, config?.[tag] || null]));
30
+ }
31
+ /** The version tags an installation stores, under the names of the config. */
32
+ export function versionsOfInstall(install) {
33
+ const fields = (install ?? {});
34
+ return Object.fromEntries(Object.entries(VERSION_FIELDS).map(([tag, field]) => [
35
+ tag,
36
+ fields[field] || null,
37
+ ]));
38
+ }
2
39
  export class CustomerConfig {
3
40
  app;
4
41
  origins;
@@ -26,7 +63,7 @@ export class CustomerConfig {
26
63
  */
27
64
  speedKitVersion;
28
65
  /** The tag of RUM for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
29
- rumPluginVersion;
66
+ rumPluginsVersion;
30
67
  /** The tag of predictive preloading for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
31
68
  ppVersion;
32
69
  /** The tag of the speed-kit-config plugins for the `enableSpeedKitConfigPlugins` feature, see {@link speedKitVersion}. */
@@ -52,17 +89,17 @@ export class CustomerConfig {
52
89
  this.needsCustomerApproval = needsCustomerApproval;
53
90
  this.features = features;
54
91
  this.speedKitVersion = versions.speedKitVersion;
55
- this.rumPluginVersion = versions.rumPluginVersion;
92
+ this.rumPluginsVersion = versions.rumPluginsVersion;
56
93
  this.ppVersion = versions.ppVersion;
57
94
  this.configPluginsVersion = versions.configPluginsVersion;
58
95
  this.documentHandlerVersion = versions.documentHandlerVersion;
59
96
  }
60
97
  static createFrom(configFile, configName) {
61
- const { app, origins, domain, swPath, scope, appDomain, installPath, installParams, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, features, speedKitVersion, rumPluginVersion, ppVersion, configPluginsVersion, documentHandlerVersion, } = configFile;
98
+ const { app, origins, domain, swPath, scope, appDomain, installPath, installParams, name, forceInstall, chromeFlags, dependencies, needsCustomerApproval, features, speedKitVersion, rumPluginsVersion, ppVersion, configPluginsVersion, documentHandlerVersion, } = configFile;
62
99
  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 ||
63
100
  `https://${app}.app.baqend.com/v1/speedkit/install.js?d=${name || configName}`, installParams || 'async="" crossorigin="anonymous"', name, forceInstall || false, chromeFlags, dependencies || {}, needsCustomerApproval || false, features || {}, {
64
101
  speedKitVersion,
65
- rumPluginVersion,
102
+ rumPluginsVersion,
66
103
  ppVersion,
67
104
  configPluginsVersion,
68
105
  documentHandlerVersion,
@@ -65,5 +65,5 @@ export declare class VirtualSpeedKitConfigFile extends SpeedKitConfigFile implem
65
65
  }
66
66
  /** The customer has the `enableSpeedKitConfigPlugins` feature: packjockel bundles its config. */
67
67
  export declare function usesConfigPlugins(customer: SpeedKitConfigCustomer): boolean;
68
- /** The customer also has the `embedded_config` feature: the service worker embeds the config too. */
68
+ /** The customer also has the `embeddedConfig` feature: the service worker embeds the config too. */
69
69
  export declare function embedsConfigInServiceWorker(customer: SpeedKitConfigCustomer): boolean;
@@ -222,9 +222,9 @@ function safeFileContentWrapper(fileContent) {
222
222
  export function usesConfigPlugins(customer) {
223
223
  return customer.features?.enableSpeedKitConfigPlugins === true;
224
224
  }
225
- /** The customer also has the `embedded_config` feature: the service worker embeds the config too. */
225
+ /** The customer also has the `embeddedConfig` feature: the service worker embeds the config too. */
226
226
  export function embedsConfigInServiceWorker(customer) {
227
- return (usesConfigPlugins(customer) && customer.features?.embedded_config === true);
227
+ return (usesConfigPlugins(customer) && customer.features?.embeddedConfig === true);
228
228
  }
229
229
  async function bundle(bundler, content, customer) {
230
230
  if (!content) {
@@ -1,4 +1,4 @@
1
- import { InstallResourceFile, } from "../integration-api/index.js";
1
+ import { InstallResourceFile, versionsOfInstall, } from "../integration-api/index.js";
2
2
  import { InstallResourceToFileMapping } from "./index.js";
3
3
  import { safe } from "../../helpers/safe.js";
4
4
  import { execSync } from "node:child_process";
@@ -107,13 +107,31 @@ export class PullService {
107
107
  async handleConfigCustomer(installResource) {
108
108
  const customerConfigFile = this.fileList.getCustomerConfig();
109
109
  const config = customerConfigFile.config;
110
- if (JSON.stringify(installResource.origins.sort()) !==
111
- JSON.stringify(config.origins.sort())) {
110
+ const updatesOrigins = JSON.stringify(installResource.origins.sort()) !==
111
+ JSON.stringify(config.origins.sort());
112
+ if (updatesOrigins) {
112
113
  this.cli.writeWarning(`update: config_customer(origins)`);
113
114
  customerConfigFile.updateOrigins(installResource.origins);
115
+ }
116
+ else {
117
+ this.cli.writeSuccess("equal, skip: config_customer(origins)");
118
+ }
119
+ const updatesFeatures = customerConfigFile.updateFeatures(installResource.features);
120
+ if (updatesFeatures) {
121
+ this.cli.writeWarning(`update: config_customer(features)`);
122
+ }
123
+ else {
124
+ this.cli.writeSuccess("equal, skip: config_customer(features)");
125
+ }
126
+ const updatesVersions = customerConfigFile.updateVersions(versionsOfInstall(installResource));
127
+ if (updatesVersions) {
128
+ this.cli.writeWarning(`update: config_customer(versions)`);
129
+ }
130
+ else {
131
+ this.cli.writeSuccess("equal, skip: config_customer(versions)");
132
+ }
133
+ if (updatesOrigins || updatesFeatures || updatesVersions) {
114
134
  await customerConfigFile.updateFile();
115
- return;
116
135
  }
117
- this.cli.writeSuccess("equal, skip: config_customer(origins)");
118
136
  }
119
137
  }
@@ -1788,5 +1788,5 @@
1788
1788
  ]
1789
1789
  }
1790
1790
  },
1791
- "version": "4.44.0-beta.6"
1791
+ "version": "4.44.0-beta.7"
1792
1792
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "4.44.0-beta.6",
4
+ "version": "4.44.0-beta.7",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"