@speedkit/cli 4.29.0 → 4.31.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.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/services/customer-config/customer-config-service-model.d.ts +6 -0
- package/dist/services/customer-config/customer-config-service-model.js +1 -0
- package/dist/services/customer-config/customer-config-service.d.ts +5 -0
- package/dist/services/customer-config/customer-config-service.js +15 -0
- package/dist/services/deploy/checks/activation/customer-approval-check.d.ts +21 -0
- package/dist/services/deploy/checks/activation/customer-approval-check.js +62 -0
- package/dist/services/deploy/checks/activation/customer-approval-check.spec.js +64 -0
- package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +9 -7
- package/dist/services/deploy/checks/pre-deploy/split-change-check.js +7 -6
- package/dist/services/deploy/deploy-service-factory.js +2 -1
- package/dist/services/deploy/handler/install-resource-handler.d.ts +7 -1
- package/dist/services/deploy/handler/install-resource-handler.js +40 -19
- package/dist/services/deploy/handler/testing-installation-links.d.ts +10 -0
- package/dist/services/deploy/handler/testing-installation-links.js +27 -0
- package/dist/services/deploy/handler/testing-installation-links.spec.d.ts +1 -0
- package/dist/services/deploy/handler/testing-installation-links.spec.js +43 -0
- package/dist/services/integration-api/file-list.d.ts +2 -1
- package/dist/services/integration-api/file-list.js +7 -1
- package/dist/services/integration-api/handler/install-resource-handler.js +10 -2
- package/dist/services/integration-api/integration-api-model.d.ts +8 -0
- package/dist/services/integration-api/integration-api-model.js +3 -0
- package/dist/services/integration-api/spec/config-plugin.spec.d.ts +1 -0
- package/dist/services/integration-api/spec/config-plugin.spec.js +188 -0
- package/dist/services/integration-api/spec/speed-kit-config-file.spec.d.ts +1 -0
- package/dist/{helpers/evaluate-speed-kit-config.spec.js → services/integration-api/spec/speed-kit-config-file.spec.js} +43 -12
- package/dist/services/integration-api/spec/speed-kit-config.spec.d.ts +1 -0
- package/dist/services/integration-api/spec/speed-kit-config.spec.js +108 -0
- package/dist/services/integration-api/struct/config-plugin.d.ts +41 -0
- package/dist/services/integration-api/struct/config-plugin.js +241 -0
- package/dist/services/integration-api/struct/customer-config.d.ts +7 -1
- package/dist/services/integration-api/struct/customer-config.js +10 -3
- package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +46 -0
- package/dist/services/integration-api/struct/speed-kit-config-file.js +223 -0
- package/dist/services/integration-api/struct/speed-kit-config.d.ts +84 -0
- package/dist/services/integration-api/struct/speed-kit-config.js +114 -0
- package/dist/services/integration-api/virtual/static-recipe.d.ts +1 -1
- package/dist/services/query-builder/queries/spec/golden-configs.d.ts +2 -0
- package/dist/services/query-builder/queries/spec/golden-configs.js +37 -0
- package/dist/services/query-builder/queries/spec/golden.spec.js +5 -4
- package/dist/services/query-builder/queries/spec/queries.spec.js +2 -1
- package/dist/services/query-builder/queries/spec/reported-bugs.spec.js +2 -1
- package/dist/services/query-builder/query-builder-factory.js +4 -8
- package/dist/services/query-builder/query-builder-service.js +4 -0
- package/dist/services/query-builder/query-builder-service.spec.js +2 -1
- package/dist/services/query-builder/rules/rule-model.d.ts +6 -2
- package/dist/services/query-builder/rules/rule-model.js +0 -2
- package/dist/services/query-builder/rules/rule-parser.d.ts +7 -8
- package/dist/services/query-builder/rules/rule-parser.js +41 -47
- package/dist/services/query-builder/rules/spec/rule-parser.spec.js +30 -32
- package/dist/services/query-builder/rules/spec/rule-reducer.spec.js +2 -1
- package/dist/services/query-builder/rules/spec/rule-relevance.spec.js +7 -3
- package/dist/services/query-builder/rules/spec/rule-to-sql.spec.js +3 -2
- package/dist/services/query-builder/rules/spec/strip-parameters.spec.js +5 -2
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/dist/helpers/evaluate-speed-kit-config.d.ts +0 -11
- package/dist/helpers/evaluate-speed-kit-config.js +0 -150
- /package/dist/{helpers/evaluate-speed-kit-config.spec.d.ts → services/deploy/checks/activation/customer-approval-check.spec.d.ts} +0 -0
- /package/dist/services/{deploy → integration-api}/error/evaluate-sk-config-error.d.ts +0 -0
- /package/dist/services/{deploy → integration-api}/error/evaluate-sk-config-error.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [4.31.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.30.0...v4.31.0) (2026-09-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **config-plugins:** apply configPlugins to config before evaluation ([78984ff](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/78984ff145c6cacc3280652e5975f3ef1676b550))
|
|
7
|
+
|
|
8
|
+
# [4.30.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.29.0...v4.30.0) (2026-09-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **deploy:** require customer approval before activating a rollout ([e87d217](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/e87d2170315a4d601597cfbc2c656a227569c184))
|
|
14
|
+
|
|
1
15
|
# [4.29.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.28.0...v4.29.0) (2026-09-17)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -51,6 +51,12 @@ export interface CustomerConfigSettings {
|
|
|
51
51
|
handleUsercentrics?: boolean;
|
|
52
52
|
isPOV?: boolean;
|
|
53
53
|
useDisabledSitesApproach?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Written to config_customer.json. Makes `sk deploy` ask whether the customer
|
|
56
|
+
* approved the change before it offers to activate an installation with a
|
|
57
|
+
* split greater than 0.
|
|
58
|
+
*/
|
|
59
|
+
needsCustomerApproval?: boolean;
|
|
54
60
|
shopSystemName?: string;
|
|
55
61
|
isShopify?: boolean;
|
|
56
62
|
isShopware?: boolean;
|
|
@@ -18,6 +18,11 @@ export declare class CustomerConfigService {
|
|
|
18
18
|
private getPathWithChangedDir;
|
|
19
19
|
private isDirNotEmpty;
|
|
20
20
|
private chooseNewOutputDirectoryName;
|
|
21
|
+
/**
|
|
22
|
+
* Japanese customers sign off every rollout themselves, so the approval flag
|
|
23
|
+
* is preselected for them. A `.jp` host is the signal we have at this point.
|
|
24
|
+
*/
|
|
25
|
+
private isJapaneseHost;
|
|
21
26
|
/** A pre-PoC config marks itself via splitTestId "pre_poc" in config_SpeedKit.js. */
|
|
22
27
|
private isPrePocConfig;
|
|
23
28
|
/** Parks every config_* file as *_pre-poc (suffix before the extension). */
|
|
@@ -58,6 +58,13 @@ export class CustomerConfigService {
|
|
|
58
58
|
});
|
|
59
59
|
return this.selectOutputDirectory(this.getPathWithChangedDir(directoryPath, newDirectoryName));
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Japanese customers sign off every rollout themselves, so the approval flag
|
|
63
|
+
* is preselected for them. A `.jp` host is the signal we have at this point.
|
|
64
|
+
*/
|
|
65
|
+
isJapaneseHost(host) {
|
|
66
|
+
return /\.jp$/i.test(host.trim().replace(/\/.*$/, ""));
|
|
67
|
+
}
|
|
61
68
|
/** A pre-PoC config marks itself via splitTestId "pre_poc" in config_SpeedKit.js. */
|
|
62
69
|
isPrePocConfig(directoryPath) {
|
|
63
70
|
const speedKitConfigPath = path.join(directoryPath, "config_SpeedKit.js");
|
|
@@ -270,12 +277,19 @@ export class CustomerConfigService {
|
|
|
270
277
|
}
|
|
271
278
|
this.cli.spacer();
|
|
272
279
|
}
|
|
280
|
+
// 6. Customer approval. Its own question rather than a feature toggle: it
|
|
281
|
+
// decides whether sk deploy may ever activate a rollout unattended, which
|
|
282
|
+
// is too easy to miss in a multi-select. The question is the same for every
|
|
283
|
+
// customer — only the default answer follows the domain.
|
|
284
|
+
const needsCustomerApproval = await this.cli.confirm("[Approval] Must the customer approve a change before it may be activated?", this.isJapaneseHost(productionHost));
|
|
285
|
+
this.cli.spacer();
|
|
273
286
|
// Pre-PoC: the tracking-only set uses no acceleration answers — stop asking here.
|
|
274
287
|
if (this.context.mode === "pre-poc") {
|
|
275
288
|
return {
|
|
276
289
|
appName: this.appName,
|
|
277
290
|
production,
|
|
278
291
|
staging,
|
|
292
|
+
needsCustomerApproval,
|
|
279
293
|
shopSystemName: selectedShopSystem === ShopSystem.OTHER
|
|
280
294
|
? undefined
|
|
281
295
|
: selectedShopSystem,
|
|
@@ -453,6 +467,7 @@ export class CustomerConfigService {
|
|
|
453
467
|
isPlentymarkets,
|
|
454
468
|
isPOV,
|
|
455
469
|
addDowntimeDetection,
|
|
470
|
+
needsCustomerApproval,
|
|
456
471
|
};
|
|
457
472
|
}
|
|
458
473
|
async logWarnings(configSettings) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CliServiceInterface } from "../../../cli/index.js";
|
|
2
|
+
import { CustomerConfig } from "../../../integration-api/index.js";
|
|
3
|
+
import Install from "../../interface/install.js";
|
|
4
|
+
/**
|
|
5
|
+
* Some customers reserve the go-live decision for themselves: nothing may reach
|
|
6
|
+
* their real users before they signed it off. `needsCustomerApproval` in
|
|
7
|
+
* config_customer.json marks such a customer, and this check asks for that
|
|
8
|
+
* sign-off before `sk deploy` offers to activate an installation that would
|
|
9
|
+
* serve a share of the traffic (split > 0 for at least one origin).
|
|
10
|
+
*/
|
|
11
|
+
export declare class CustomerApprovalCheck {
|
|
12
|
+
private cli;
|
|
13
|
+
private customer;
|
|
14
|
+
constructor(cli: CliServiceInterface, customer: CustomerConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Whether the installation may be offered for regular activation. `false`
|
|
17
|
+
* means the deploy is limited to a testing installation.
|
|
18
|
+
*/
|
|
19
|
+
isActivationApproved(install: Install): Promise<boolean>;
|
|
20
|
+
private getSplitsGreaterZero;
|
|
21
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { VirtualSpeedKitConfigFile, } from "../../../integration-api/index.js";
|
|
2
|
+
import { safe } from "../../../../helpers/safe.js";
|
|
3
|
+
/** The install resource key config_SpeedKit.js is stored under. */
|
|
4
|
+
const SPEED_KIT_CONFIG_KEY = "config";
|
|
5
|
+
/**
|
|
6
|
+
* Some customers reserve the go-live decision for themselves: nothing may reach
|
|
7
|
+
* their real users before they signed it off. `needsCustomerApproval` in
|
|
8
|
+
* config_customer.json marks such a customer, and this check asks for that
|
|
9
|
+
* sign-off before `sk deploy` offers to activate an installation that would
|
|
10
|
+
* serve a share of the traffic (split > 0 for at least one origin).
|
|
11
|
+
*/
|
|
12
|
+
export class CustomerApprovalCheck {
|
|
13
|
+
cli;
|
|
14
|
+
customer;
|
|
15
|
+
constructor(cli, customer) {
|
|
16
|
+
this.cli = cli;
|
|
17
|
+
this.customer = customer;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether the installation may be offered for regular activation. `false`
|
|
21
|
+
* means the deploy is limited to a testing installation.
|
|
22
|
+
*/
|
|
23
|
+
async isActivationApproved(install) {
|
|
24
|
+
if (!this.customer.needsCustomerApproval) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
const splits = await this.getSplitsGreaterZero(install);
|
|
28
|
+
// Nothing reaches real users — no approval needed.
|
|
29
|
+
if (splits.length === 0) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
this.cli.writeWarning("This customer approves every rollout themselves and the configuration " +
|
|
33
|
+
"to be activated has a split greater than 0:");
|
|
34
|
+
this.cli.table(splits, { origin: {}, split: {} });
|
|
35
|
+
return this.cli.confirm("Was this change approved by customer?", false);
|
|
36
|
+
}
|
|
37
|
+
async getSplitsGreaterZero(install) {
|
|
38
|
+
const speedKitConfig = install[SPEED_KIT_CONFIG_KEY];
|
|
39
|
+
// No Speed Kit config at all means nothing is accelerated.
|
|
40
|
+
if (!speedKitConfig) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
// The config to be activated, read the same way the local file is — one
|
|
44
|
+
// file, evaluated once per origin.
|
|
45
|
+
const configFile = await VirtualSpeedKitConfigFile.createRemote(speedKitConfig);
|
|
46
|
+
const splits = [];
|
|
47
|
+
for (const origin of this.customer.origins) {
|
|
48
|
+
const result = await safe(configFile.evaluate(this.customer.app, origin));
|
|
49
|
+
if (result.success === false) {
|
|
50
|
+
// An unreadable config is not proof that the split is 0, so keep the
|
|
51
|
+
// approval question rather than skipping it.
|
|
52
|
+
this.cli.writeError(`Unable to evaluate the split for ${origin}: ${result.error}`);
|
|
53
|
+
splits.push({ origin, split: "unknown" });
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (result.data.split > 0) {
|
|
57
|
+
splits.push({ origin, split: result.data.split });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return splits;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { CustomerApprovalCheck } from "./customer-approval-check.js";
|
|
4
|
+
import { CustomerConfig } from "../../../integration-api/index.js";
|
|
5
|
+
function customer(needsCustomerApproval) {
|
|
6
|
+
return CustomerConfig.createFrom({
|
|
7
|
+
app: "test-app",
|
|
8
|
+
origins: ["https://www.example.com", "https://www.example.de"],
|
|
9
|
+
swPath: "/sw.js",
|
|
10
|
+
scope: "/",
|
|
11
|
+
needsCustomerApproval,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function installWithSplit(split) {
|
|
15
|
+
return {
|
|
16
|
+
domain: "production",
|
|
17
|
+
config: `window.speedKit = { appName: APP, split: ${split} };`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Records every question asked and answers all of them with `answer`. */
|
|
21
|
+
function cliAsking(answer) {
|
|
22
|
+
const questions = [];
|
|
23
|
+
const cli = {
|
|
24
|
+
confirm: async (message) => {
|
|
25
|
+
questions.push(message);
|
|
26
|
+
return answer;
|
|
27
|
+
},
|
|
28
|
+
table: () => undefined,
|
|
29
|
+
writeWarning: () => undefined,
|
|
30
|
+
writeError: () => undefined,
|
|
31
|
+
};
|
|
32
|
+
return { cli, questions };
|
|
33
|
+
}
|
|
34
|
+
describe("CustomerApprovalCheck", () => {
|
|
35
|
+
it("approves without asking when the customer does not need to approve", async () => {
|
|
36
|
+
const { cli, questions } = cliAsking(false);
|
|
37
|
+
const approved = await new CustomerApprovalCheck(cli, customer(false)).isActivationApproved(installWithSplit("1"));
|
|
38
|
+
expect(approved).to.equal(true);
|
|
39
|
+
expect(questions).to.deep.equal([]);
|
|
40
|
+
});
|
|
41
|
+
it("approves without asking while no origin serves traffic", async () => {
|
|
42
|
+
const { cli, questions } = cliAsking(false);
|
|
43
|
+
const approved = await new CustomerApprovalCheck(cli, customer(true)).isActivationApproved(installWithSplit("0"));
|
|
44
|
+
expect(approved).to.equal(true);
|
|
45
|
+
expect(questions).to.deep.equal([]);
|
|
46
|
+
});
|
|
47
|
+
it("asks once a single origin has a split greater than 0", async () => {
|
|
48
|
+
const { cli, questions } = cliAsking(true);
|
|
49
|
+
const approved = await new CustomerApprovalCheck(cli, customer(true)).isActivationApproved(installWithSplit('window.location.hostname === "www.example.com" ? 0.5 : 0'));
|
|
50
|
+
expect(approved).to.equal(true);
|
|
51
|
+
expect(questions).to.deep.equal(["Was this change approved by customer?"]);
|
|
52
|
+
});
|
|
53
|
+
it("withholds the approval when the question is answered with no", async () => {
|
|
54
|
+
const { cli } = cliAsking(false);
|
|
55
|
+
const approved = await new CustomerApprovalCheck(cli, customer(true)).isActivationApproved(installWithSplit("0.1"));
|
|
56
|
+
expect(approved).to.equal(false);
|
|
57
|
+
});
|
|
58
|
+
it("asks when the split cannot be evaluated", async () => {
|
|
59
|
+
const { cli, questions } = cliAsking(false);
|
|
60
|
+
const approved = await new CustomerApprovalCheck(cli, customer(true)).isActivationApproved(installWithSplit("({}).missing.split"));
|
|
61
|
+
expect(approved).to.equal(false);
|
|
62
|
+
expect(questions).to.deep.equal(["Was this change approved by customer?"]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { VirtualSpeedKitConfigFile, } from "../../../integration-api/index.js";
|
|
1
2
|
import { INTEGRATION_FILES } from "../../../../models/files.js";
|
|
2
3
|
import { safe } from "../../../../helpers/safe.js";
|
|
3
|
-
import { evaluateLocalAndRemoteSpeedKit } from "../../../../helpers/evaluate-speed-kit-config.js";
|
|
4
4
|
export class DeviceDetectionChangedCheck {
|
|
5
5
|
cli;
|
|
6
6
|
fileList;
|
|
@@ -22,9 +22,7 @@ export class DeviceDetectionChangedCheck {
|
|
|
22
22
|
!this.isProduction ||
|
|
23
23
|
// do not check if speedKitConfigFile is not to be deployed
|
|
24
24
|
!this.fileList.hasFile(INTEGRATION_FILES.CONFIG.SPEED_KIT) ||
|
|
25
|
-
this.fileList
|
|
26
|
-
.getByName(INTEGRATION_FILES.CONFIG.SPEED_KIT)
|
|
27
|
-
.shouldSkipFile()) {
|
|
25
|
+
this.fileList.getSpeedKitConfig().shouldSkipFile()) {
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
30
28
|
const activeInstallResource = await this.getActiveInstallResource();
|
|
@@ -33,7 +31,7 @@ export class DeviceDetectionChangedCheck {
|
|
|
33
31
|
return;
|
|
34
32
|
}
|
|
35
33
|
this.cli.startAction("PRE:CHECK:DEVICE_DETECTION", "Checking for customDeviceDetection");
|
|
36
|
-
const speedKitConfigFile = this.fileList.
|
|
34
|
+
const speedKitConfigFile = this.fileList.getSpeedKitConfig();
|
|
37
35
|
const activeSpeedKitConfig = activeInstallResource[speedKitConfigFile.remoteKey];
|
|
38
36
|
const changesResponse = await safe(this.checkForChangedDeviceDetection(speedKitConfigFile, activeSpeedKitConfig));
|
|
39
37
|
if (changesResponse.success === false) {
|
|
@@ -42,7 +40,7 @@ export class DeviceDetectionChangedCheck {
|
|
|
42
40
|
return;
|
|
43
41
|
}
|
|
44
42
|
const changes = changesResponse.data.map((value) => {
|
|
45
|
-
return
|
|
43
|
+
return `${INTEGRATION_FILES.CONFIG.SPEED_KIT}.${value}`;
|
|
46
44
|
});
|
|
47
45
|
this.cli.successAction("PRE:CHECK:DEVICE_DETECTION");
|
|
48
46
|
if (changes.length === 0) {
|
|
@@ -55,8 +53,12 @@ export class DeviceDetectionChangedCheck {
|
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
async checkForChangedDeviceDetection(speedKitConfigFile, activeSpeedKitConfig) {
|
|
56
|
+
const remoteConfigFile = await VirtualSpeedKitConfigFile.createRemote(activeSpeedKitConfig);
|
|
57
|
+
const app = this.customerConfig.app;
|
|
58
|
+
const origin = this.customerConfig.origins[0];
|
|
58
59
|
const changes = [];
|
|
59
|
-
const
|
|
60
|
+
const localSpeedKit = await speedKitConfigFile.evaluate(app, origin);
|
|
61
|
+
const remoteSpeedKit = await remoteConfigFile.evaluate(app, origin);
|
|
60
62
|
if ((localSpeedKit.detectDevice && !remoteSpeedKit.detectDevice) ||
|
|
61
63
|
(!localSpeedKit.detectDevice && remoteSpeedKit.detectDevice)) {
|
|
62
64
|
changes.push("detectDevice");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { VirtualSpeedKitConfigFile, } from "../../../integration-api/index.js";
|
|
1
2
|
import { INTEGRATION_FILES } from "../../../../models/files.js";
|
|
2
3
|
import { safe } from "../../../../helpers/safe.js";
|
|
3
|
-
import { evaluateLocalAndRemoteSpeedKit } from "../../../../helpers/evaluate-speed-kit-config.js";
|
|
4
4
|
import ApplicationError from "../../../error-handling/error/application-error.js";
|
|
5
5
|
export class SplitChangeCheck {
|
|
6
6
|
cli;
|
|
@@ -23,9 +23,7 @@ export class SplitChangeCheck {
|
|
|
23
23
|
!this.isProduction ||
|
|
24
24
|
// do not check if speedKitConfigFile is not to be deployed
|
|
25
25
|
!this.fileList.hasFile(INTEGRATION_FILES.CONFIG.SPEED_KIT) ||
|
|
26
|
-
this.fileList
|
|
27
|
-
.getByName(INTEGRATION_FILES.CONFIG.SPEED_KIT)
|
|
28
|
-
.shouldSkipFile()) {
|
|
26
|
+
this.fileList.getSpeedKitConfig().shouldSkipFile()) {
|
|
29
27
|
return;
|
|
30
28
|
}
|
|
31
29
|
const activeInstallResource = await this.getActiveInstallResource();
|
|
@@ -34,7 +32,7 @@ export class SplitChangeCheck {
|
|
|
34
32
|
return;
|
|
35
33
|
}
|
|
36
34
|
this.cli.startAction("PRE:CHECK:SPLIT_CHANGE", "Checking Split Test ID");
|
|
37
|
-
const speedKitConfigFile = this.fileList.
|
|
35
|
+
const speedKitConfigFile = this.fileList.getSpeedKitConfig();
|
|
38
36
|
const activeSpeedKitConfig = activeInstallResource[speedKitConfigFile.remoteKey];
|
|
39
37
|
if (!activeSpeedKitConfig) {
|
|
40
38
|
throw new ApplicationError("RemoteSpeedKitConfig is empty");
|
|
@@ -58,9 +56,12 @@ export class SplitChangeCheck {
|
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
async checkSplitsForEachOrigin(speedKitConfigFile, activeSpeedKitConfig) {
|
|
59
|
+
const remoteConfigFile = await VirtualSpeedKitConfigFile.createRemote(activeSpeedKitConfig);
|
|
60
|
+
const app = this.customerConfig.app;
|
|
61
61
|
const changes = [];
|
|
62
62
|
for (const origin of this.customerConfig.origins) {
|
|
63
|
-
const
|
|
63
|
+
const localSpeedKit = await speedKitConfigFile.evaluate(app, origin);
|
|
64
|
+
const remoteSpeedKit = await remoteConfigFile.evaluate(app, origin);
|
|
64
65
|
// check for split change
|
|
65
66
|
if (localSpeedKit.split !== remoteSpeedKit.split) {
|
|
66
67
|
changes.push({
|
|
@@ -15,6 +15,7 @@ import { ConfigApiContext, ConfigApiServiceFactory, } from "../config-api/index.
|
|
|
15
15
|
import { DeprecatedDeploymentDetectionCheck } from "./checks/post-deploy/deprecated-deployment-detection-check.js";
|
|
16
16
|
import { DeviceDetectionChangedCheck } from "./checks/pre-deploy/device-detection-changed-check.js";
|
|
17
17
|
import { RefreshDeploymentJobCheck } from "./checks/post-deploy/refresh-deployment-job-check.js";
|
|
18
|
+
import { CustomerApprovalCheck } from "./checks/activation/customer-approval-check.js";
|
|
18
19
|
export default class DeployServiceFactory {
|
|
19
20
|
context;
|
|
20
21
|
cliConfig;
|
|
@@ -40,7 +41,7 @@ export default class DeployServiceFactory {
|
|
|
40
41
|
const deletedFilesChecker = new DeletedFileCheck(cliService, this.context.hasArtifacts());
|
|
41
42
|
this.service = new DeployService(files, [
|
|
42
43
|
new CustomerConfigHandler(customer, configApi, configName, diffService, cliService, installResourceBuilder),
|
|
43
|
-
new InstallResourceHandler(customer, configApi, configName, diffService, cliService, installResourceBuilder, deletedFilesChecker),
|
|
44
|
+
new InstallResourceHandler(customer, configApi, configName, diffService, cliService, installResourceBuilder, deletedFilesChecker, new CustomerApprovalCheck(cliService, customer)),
|
|
44
45
|
new ModuleHandler(configApi, diffService, cliService, []),
|
|
45
46
|
new ServerConfigHandler(configApi, diffService, cliService),
|
|
46
47
|
], cliService, [
|
|
@@ -5,6 +5,7 @@ import InstallResourceBuilder from "../builder/install-resource-builder.js";
|
|
|
5
5
|
import DeletedFileCheck from "./install-resource-modifier/deleted-file-check.js";
|
|
6
6
|
import { CustomerConfig, FILE_TYPE, InstallResourceInterface } from "../../integration-api/index.js";
|
|
7
7
|
import { ConfigApiService } from "../../config-api/index.js";
|
|
8
|
+
import { CustomerApprovalCheck } from "../checks/activation/customer-approval-check.js";
|
|
8
9
|
export default class InstallResourceHandler implements DeployHandlerInterface {
|
|
9
10
|
private readonly customer;
|
|
10
11
|
private readonly configApi;
|
|
@@ -13,10 +14,15 @@ export default class InstallResourceHandler implements DeployHandlerInterface {
|
|
|
13
14
|
private cli;
|
|
14
15
|
private builder;
|
|
15
16
|
private deletedFilesChecker;
|
|
16
|
-
|
|
17
|
+
private customerApprovalCheck;
|
|
18
|
+
constructor(customer: CustomerConfig, configApi: ConfigApiService, configName: string, diffService: DiffService, cli: CliService, builder: InstallResourceBuilder, deletedFilesChecker: DeletedFileCheck, customerApprovalCheck: CustomerApprovalCheck);
|
|
17
19
|
canHandle(type: FILE_TYPE): boolean;
|
|
18
20
|
handle(files: InstallResourceInterface[]): Promise<void>;
|
|
19
21
|
upload(files: InstallResourceInterface[]): Promise<void>;
|
|
22
|
+
private activate;
|
|
23
|
+
private activateAsTesting;
|
|
24
|
+
/** The origins with the debug parameter attached, ready to be clicked. */
|
|
25
|
+
private writeTestingInstallationLinks;
|
|
20
26
|
private processFile;
|
|
21
27
|
private confirm;
|
|
22
28
|
private getInstallResource;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FILE_TYPE, } from "../../integration-api/index.js";
|
|
2
|
-
import { copyToClipboard } from "../../../helpers/clipboard.js";
|
|
3
2
|
import { safe } from "../../../helpers/safe.js";
|
|
3
|
+
import { buildTestingInstallationLinks } from "./testing-installation-links.js";
|
|
4
4
|
export default class InstallResourceHandler {
|
|
5
5
|
customer;
|
|
6
6
|
configApi;
|
|
@@ -9,7 +9,8 @@ export default class InstallResourceHandler {
|
|
|
9
9
|
cli;
|
|
10
10
|
builder;
|
|
11
11
|
deletedFilesChecker;
|
|
12
|
-
|
|
12
|
+
customerApprovalCheck;
|
|
13
|
+
constructor(customer, configApi, configName, diffService, cli, builder, deletedFilesChecker, customerApprovalCheck) {
|
|
13
14
|
this.customer = customer;
|
|
14
15
|
this.configApi = configApi;
|
|
15
16
|
this.diffService = diffService;
|
|
@@ -17,6 +18,7 @@ export default class InstallResourceHandler {
|
|
|
17
18
|
this.cli = cli;
|
|
18
19
|
this.builder = builder;
|
|
19
20
|
this.deletedFilesChecker = deletedFilesChecker;
|
|
21
|
+
this.customerApprovalCheck = customerApprovalCheck;
|
|
20
22
|
}
|
|
21
23
|
canHandle(type) {
|
|
22
24
|
return type === FILE_TYPE.INSTALL_FILE;
|
|
@@ -57,25 +59,16 @@ export default class InstallResourceHandler {
|
|
|
57
59
|
throw updateResult.errorObj;
|
|
58
60
|
}
|
|
59
61
|
this.cli.successAction("DEPLOY:UPDATE:INSTALL_RESOURCE");
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.cli.failAction("DEPLOY:ACTIVATE:INSTALL_RESOURCE_TEST", activateTestingResult.error);
|
|
66
|
-
throw activateTestingResult.errorObj;
|
|
67
|
-
}
|
|
68
|
-
this.cli.successAction("DEPLOY:ACTIVATE:INSTALL_RESOURCE_TEST");
|
|
69
|
-
const debugParameter = `?debugSpeedKit=${install.id.split("/").pop()}`;
|
|
70
|
-
if (await copyToClipboard(debugParameter)) {
|
|
71
|
-
this.cli.writeSuccess("Query parameter to activate the testing installation has been copied to the clipboard 📋");
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
this.cli.writeSuccess(`Use the following parameter to active the testing installation in your browser: ${debugParameter}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
62
|
+
// Without the customer's approval the installation may only go live as a
|
|
63
|
+
// testing installation, so the regular activation is not even offered.
|
|
64
|
+
const approved = await this.customerApprovalCheck.isActivationApproved(install);
|
|
65
|
+
if (approved && (await this.cli.confirm("Activate new installation?"))) {
|
|
66
|
+
await this.activate(install);
|
|
77
67
|
return;
|
|
78
68
|
}
|
|
69
|
+
await this.activateAsTesting(install, approved);
|
|
70
|
+
}
|
|
71
|
+
async activate(install) {
|
|
79
72
|
this.cli.startAction("DEPLOY:ACTIVATE:INSTALL_RESOURCE", "activate installResource");
|
|
80
73
|
const activateResult = await safe(this.configApi.activateInstall(install));
|
|
81
74
|
if (activateResult.success === false) {
|
|
@@ -84,6 +77,34 @@ export default class InstallResourceHandler {
|
|
|
84
77
|
}
|
|
85
78
|
this.cli.successAction("DEPLOY:ACTIVATE:INSTALL_RESOURCE");
|
|
86
79
|
}
|
|
80
|
+
async activateAsTesting(install, wasActivationOffered) {
|
|
81
|
+
const question = wasActivationOffered
|
|
82
|
+
? "Activate as testing installation instead?"
|
|
83
|
+
: "Activate as testing installation?";
|
|
84
|
+
if (!(await this.cli.confirm(question))) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.cli.startAction("DEPLOY:ACTIVATE:INSTALL_RESOURCE_TEST", "activate testing installResource");
|
|
88
|
+
const activateTestingResult = await safe(this.configApi.activateInstallTesting(install));
|
|
89
|
+
if (activateTestingResult.success === false) {
|
|
90
|
+
this.cli.failAction("DEPLOY:ACTIVATE:INSTALL_RESOURCE_TEST", activateTestingResult.error);
|
|
91
|
+
throw activateTestingResult.errorObj;
|
|
92
|
+
}
|
|
93
|
+
this.cli.successAction("DEPLOY:ACTIVATE:INSTALL_RESOURCE_TEST");
|
|
94
|
+
this.writeTestingInstallationLinks(install);
|
|
95
|
+
}
|
|
96
|
+
/** The origins with the debug parameter attached, ready to be clicked. */
|
|
97
|
+
writeTestingInstallationLinks(install) {
|
|
98
|
+
const { links, hidden } = buildTestingInstallationLinks(this.customer.origins, install.id.split("/").pop());
|
|
99
|
+
this.cli.write("");
|
|
100
|
+
this.cli.write("Open the testing installation:");
|
|
101
|
+
for (const link of links) {
|
|
102
|
+
this.cli.write(` ${link}`);
|
|
103
|
+
}
|
|
104
|
+
if (hidden > 0) {
|
|
105
|
+
this.cli.comment(` … and ${hidden} more origin${hidden === 1 ? "" : "s"}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
87
108
|
async processFile(file, installResource) {
|
|
88
109
|
if (!installResource) {
|
|
89
110
|
await this.confirm(file, true);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** How many origins are listed before the rest is summarised as a count. */
|
|
2
|
+
export declare const MAX_LISTED_ORIGINS = 10;
|
|
3
|
+
/**
|
|
4
|
+
* The links that open a testing installation — one per origin, capped so a
|
|
5
|
+
* customer with dozens of origins does not bury the rest of the deploy output.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildTestingInstallationLinks(origins: string[], testInstallationId: string): {
|
|
8
|
+
links: string[];
|
|
9
|
+
hidden: number;
|
|
10
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { safe } from "../../../helpers/safe.js";
|
|
2
|
+
/** How many origins are listed before the rest is summarised as a count. */
|
|
3
|
+
export const MAX_LISTED_ORIGINS = 10;
|
|
4
|
+
/** The query parameter that switches a browser to a testing installation. */
|
|
5
|
+
const DEBUG_PARAMETER = "debugSpeedKit";
|
|
6
|
+
/**
|
|
7
|
+
* The links that open a testing installation — one per origin, capped so a
|
|
8
|
+
* customer with dozens of origins does not bury the rest of the deploy output.
|
|
9
|
+
*/
|
|
10
|
+
export function buildTestingInstallationLinks(origins, testInstallationId) {
|
|
11
|
+
const links = origins
|
|
12
|
+
.slice(0, MAX_LISTED_ORIGINS)
|
|
13
|
+
.map((origin) => buildLink(origin, testInstallationId));
|
|
14
|
+
return { links, hidden: Math.max(origins.length - MAX_LISTED_ORIGINS, 0) };
|
|
15
|
+
}
|
|
16
|
+
function buildLink(origin, testInstallationId) {
|
|
17
|
+
const parsed = safe(() => {
|
|
18
|
+
const url = new URL(origin);
|
|
19
|
+
url.searchParams.set(DEBUG_PARAMETER, testInstallationId);
|
|
20
|
+
return url.toString();
|
|
21
|
+
});
|
|
22
|
+
// An origin the URL parser rejects is still worth printing — the deploy has
|
|
23
|
+
// happened by now, and a slightly off link beats no link at all.
|
|
24
|
+
return parsed.success
|
|
25
|
+
? parsed.data
|
|
26
|
+
: `${origin}?${DEBUG_PARAMETER}=${testInstallationId}`;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { buildTestingInstallationLinks, MAX_LISTED_ORIGINS, } from "./testing-installation-links.js";
|
|
4
|
+
function origins(count) {
|
|
5
|
+
return Array.from({ length: count }, (_, i) => `https://shop-${i}.example.com`);
|
|
6
|
+
}
|
|
7
|
+
describe("buildTestingInstallationLinks", () => {
|
|
8
|
+
it("attaches the debug parameter to every origin", () => {
|
|
9
|
+
const { links, hidden } = buildTestingInstallationLinks(["https://www.example.com", "https://www.example.de"], "hJ3kP9qw");
|
|
10
|
+
expect(links).to.deep.equal([
|
|
11
|
+
"https://www.example.com/?debugSpeedKit=hJ3kP9qw",
|
|
12
|
+
"https://www.example.de/?debugSpeedKit=hJ3kP9qw",
|
|
13
|
+
]);
|
|
14
|
+
expect(hidden).to.equal(0);
|
|
15
|
+
});
|
|
16
|
+
it("keeps a port and an existing query on the origin", () => {
|
|
17
|
+
const { links } = buildTestingInstallationLinks(["https://staging.example.com:8443?preview=1"], "id");
|
|
18
|
+
expect(links).to.deep.equal([
|
|
19
|
+
"https://staging.example.com:8443/?preview=1&debugSpeedKit=id",
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
it("still builds a link for an origin the URL parser rejects", () => {
|
|
23
|
+
const { links } = buildTestingInstallationLinks(["www.example.com"], "id");
|
|
24
|
+
expect(links).to.deep.equal(["www.example.com?debugSpeedKit=id"]);
|
|
25
|
+
});
|
|
26
|
+
it("lists everything while the cap is not reached", () => {
|
|
27
|
+
const { links, hidden } = buildTestingInstallationLinks(origins(MAX_LISTED_ORIGINS), "id");
|
|
28
|
+
expect(links).to.have.lengthOf(MAX_LISTED_ORIGINS);
|
|
29
|
+
expect(hidden).to.equal(0);
|
|
30
|
+
});
|
|
31
|
+
it("caps the list and reports how many origins it left out", () => {
|
|
32
|
+
const { links, hidden } = buildTestingInstallationLinks(origins(MAX_LISTED_ORIGINS + 3), "id");
|
|
33
|
+
expect(links).to.have.lengthOf(MAX_LISTED_ORIGINS);
|
|
34
|
+
expect(links[0]).to.equal("https://shop-0.example.com/?debugSpeedKit=id");
|
|
35
|
+
expect(hidden).to.equal(3);
|
|
36
|
+
});
|
|
37
|
+
it("handles a config without origins", () => {
|
|
38
|
+
expect(buildTestingInstallationLinks([], "id")).to.deep.equal({
|
|
39
|
+
links: [],
|
|
40
|
+
hidden: 0,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomerConfigInterface, FILE_TYPE, FileInterface, FileListInterface, InstallResourceInterface, ModuleInterface, ServerConfigInterface, RoFile, VirtualFile } from "./integration-api-model.js";
|
|
1
|
+
import { CustomerConfigInterface, FILE_TYPE, FileInterface, FileListInterface, InstallResourceInterface, ModuleInterface, ServerConfigInterface, RoFile, VirtualFile, SpeedKitConfigInterface } from "./integration-api-model.js";
|
|
2
2
|
export default class FileList implements FileListInterface {
|
|
3
3
|
files: FileInterface[];
|
|
4
4
|
addFile(file: FileInterface): void;
|
|
@@ -7,6 +7,7 @@ export default class FileList implements FileListInterface {
|
|
|
7
7
|
getModules(): ModuleInterface[];
|
|
8
8
|
getServerConfig(): ServerConfigInterface;
|
|
9
9
|
getCustomerConfig(): CustomerConfigInterface;
|
|
10
|
+
getSpeedKitConfig(): SpeedKitConfigInterface;
|
|
10
11
|
getTypes(): FILE_TYPE[];
|
|
11
12
|
getByType<T>(type: FILE_TYPE): FileInterface[] | T[];
|
|
12
13
|
getByName<T>(name: string): T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomerConfigFile, InstallResourceFile, ServerConfigFile, ModuleFile, } from "./integration-api-model.js";
|
|
1
|
+
import { CustomerConfigFile, InstallResourceFile, ServerConfigFile, ModuleFile, SpeedKitConfigFile, } from "./integration-api-model.js";
|
|
2
2
|
export default class FileList {
|
|
3
3
|
files = [];
|
|
4
4
|
addFile(file) {
|
|
@@ -35,6 +35,12 @@ export default class FileList {
|
|
|
35
35
|
});
|
|
36
36
|
return configFiles.shift();
|
|
37
37
|
}
|
|
38
|
+
getSpeedKitConfig() {
|
|
39
|
+
const configFiles = this.files.filter((file) => {
|
|
40
|
+
return file instanceof SpeedKitConfigFile;
|
|
41
|
+
});
|
|
42
|
+
return configFiles.shift();
|
|
43
|
+
}
|
|
38
44
|
getTypes() {
|
|
39
45
|
const types = this.files
|
|
40
46
|
.map((file) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import FileHandler from "./file-handler.js";
|
|
2
|
-
import { InstallResourceFile, } from "../integration-api-model.js";
|
|
2
|
+
import { InstallResourceFile, SpeedKitConfigFile, } from "../integration-api-model.js";
|
|
3
3
|
import ApplicationError from "../../error-handling/error/application-error.js";
|
|
4
|
+
import { INTEGRATION_FILES } from "../../../models/files.js";
|
|
4
5
|
export default class InstallResourceHandler extends FileHandler {
|
|
5
6
|
allowedFiles = [
|
|
6
7
|
"config_SpeedKit",
|
|
@@ -29,7 +30,14 @@ export default class InstallResourceHandler extends FileHandler {
|
|
|
29
30
|
}
|
|
30
31
|
async handle(filePath) {
|
|
31
32
|
const fileName = this.getFileName(filePath);
|
|
32
|
-
|
|
33
|
+
const content = await this.getFileContent(fileName, filePath);
|
|
34
|
+
const remoteKey = this.getRemoteKey(fileName);
|
|
35
|
+
// config_SpeedKit is more than a file to upload: it is the config itself,
|
|
36
|
+
// and everything downstream reads it through its own struct.
|
|
37
|
+
if (fileName === INTEGRATION_FILES.CONFIG.SPEED_KIT) {
|
|
38
|
+
return new SpeedKitConfigFile(fileName, filePath, content, remoteKey);
|
|
39
|
+
}
|
|
40
|
+
return new InstallResourceFile(fileName, filePath, content, remoteKey);
|
|
33
41
|
}
|
|
34
42
|
getRemoteKey(fileName) {
|
|
35
43
|
if (!this.remoteKeyMapping[fileName]) {
|