@speedkit/cli 4.43.0-beta.1 → 4.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -2
- package/README.md +12 -2
- package/dist/commands/onboarding.d.ts +3 -0
- package/dist/commands/onboarding.js +7 -1
- package/dist/models/files.d.ts +0 -1
- package/dist/models/files.js +0 -1
- package/dist/services/bundler/bundle-service-factory.d.ts +1 -6
- package/dist/services/bundler/bundle-service-factory.js +2 -9
- package/dist/services/bundler/bundle-service.d.ts +1 -10
- package/dist/services/bundler/bundle-service.js +1 -16
- package/dist/services/bundler/index.d.ts +0 -1
- package/dist/services/bundler/index.js +0 -1
- package/dist/services/cli/cli-environment.js +0 -1
- package/dist/services/cli/cli-settings.d.ts +0 -5
- package/dist/services/cli/cli-settings.js +0 -1
- package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
- package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.d.ts +2 -2
- package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.js +8 -7
- package/dist/services/deploy/checks/post-deploy/revalidated-module-check.d.ts +2 -2
- package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +11 -7
- package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +2 -2
- package/dist/services/deploy/checks/post-deploy/save-files-check.js +3 -2
- package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
- package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
- package/dist/services/deploy/deploy-service-factory.js +1 -3
- package/dist/services/deploy/deploy-service-model.d.ts +11 -1
- package/dist/services/deploy/deploy-service.d.ts +2 -0
- package/dist/services/deploy/deploy-service.js +26 -1
- package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +1 -1
- package/dist/services/deploy/policy/deploy-policy-model.d.ts +1 -5
- package/dist/services/deploy/policy/deploy-policy-model.js +0 -4
- package/dist/services/deploy/spec/checks/post-deploy/refresh-deployment-job-check.spec.js +5 -12
- package/dist/services/deploy/spec/deploy-service.spec.js +64 -0
- package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +0 -2
- package/dist/services/document-handler-runtime/document-handler-runtime-model.d.ts +0 -2
- package/dist/services/document-handler-runtime/document-handler-runtime-model.js +0 -2
- package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
- package/dist/services/document-handler-runtime/document-handler-server.js +20 -82
- package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +1 -1
- package/dist/services/integration-api/integration-api-factory.js +1 -1
- package/dist/services/integration-api/integration-api-model.d.ts +1 -2
- package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -70
- package/dist/services/integration-api/struct/customer-config.d.ts +1 -19
- package/dist/services/integration-api/struct/customer-config.js +3 -11
- package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
- package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -30
- package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -24
- package/dist/services/onboarding/error/inject-installation-error.d.ts +6 -0
- package/dist/services/onboarding/error/inject-installation-error.js +11 -0
- package/dist/services/onboarding/error/inject-target-error.d.ts +6 -0
- package/dist/services/onboarding/error/inject-target-error.js +11 -0
- package/dist/services/onboarding/error/missing-customer-path-error.d.ts +1 -1
- package/dist/services/onboarding/error/missing-customer-path-error.js +2 -1
- package/dist/services/onboarding/fetch-events/customer-domain-document-response.d.ts +4 -14
- package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +6 -45
- package/dist/services/onboarding/fetch-events/document-rewrite.d.ts +19 -0
- package/dist/services/onboarding/fetch-events/document-rewrite.js +47 -0
- package/dist/services/onboarding/fetch-events/speed-kit-install-html.d.ts +5 -1
- package/dist/services/onboarding/fetch-events/speed-kit-install-html.js +7 -2
- package/dist/services/onboarding/html-rewrites.d.ts +3 -3
- package/dist/services/onboarding/html-rewrites.js +3 -3
- package/dist/services/onboarding/index.d.ts +1 -1
- package/dist/services/onboarding/index.js +1 -1
- package/dist/services/onboarding/inject/content-security-policy.d.ts +14 -0
- package/dist/services/onboarding/inject/content-security-policy.js +54 -0
- package/dist/services/onboarding/inject/deployed-installation.d.ts +15 -0
- package/dist/services/onboarding/inject/deployed-installation.js +32 -0
- package/dist/services/onboarding/inject/foreign-install-request.d.ts +27 -0
- package/dist/services/onboarding/inject/foreign-install-request.js +50 -0
- package/dist/services/onboarding/inject/inject-document-rewrite.d.ts +23 -0
- package/dist/services/onboarding/inject/inject-document-rewrite.js +52 -0
- package/dist/services/onboarding/inject/inject-service.d.ts +32 -0
- package/dist/services/onboarding/inject/inject-service.js +72 -0
- package/dist/services/onboarding/inject/injected-installation.d.ts +29 -0
- package/dist/services/onboarding/inject/injected-installation.js +37 -0
- package/dist/services/onboarding/onboarding-service-build-context.d.ts +15 -1
- package/dist/services/onboarding/onboarding-service-build-context.js +31 -2
- package/dist/services/onboarding/onboarding-service-factory.d.ts +23 -5
- package/dist/services/onboarding/onboarding-service-factory.js +87 -7
- package/dist/services/onboarding/spec/inject/content-security-policy.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/content-security-policy.spec.js +47 -0
- package/dist/services/onboarding/spec/inject/deployed-installation.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/deployed-installation.spec.js +49 -0
- package/dist/services/onboarding/spec/inject/foreign-install-request.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/foreign-install-request.spec.js +47 -0
- package/dist/services/onboarding/spec/inject/inject-document-rewrite.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/inject-document-rewrite.spec.js +66 -0
- package/dist/services/onboarding/spec/inject/injected-installation.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/inject/injected-installation.spec.js +24 -0
- package/dist/services/onboarding/spec/onboarding-service-build-context.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/onboarding-service-build-context.spec.js +22 -0
- package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +53 -2
- package/dist/services/onboarding/templates/install-speed-kit-html-template.js +3 -0
- package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
- package/dist/services/query-builder/query-builder-factory.js +3 -3
- package/oclif.manifest.json +26 -3
- package/package.json +1 -2
- package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
- package/dist/services/bundler/error/packjockel-error.js +0 -3
- package/dist/services/bundler/packjockel-service.d.ts +0 -70
- package/dist/services/bundler/packjockel-service.js +0 -171
- package/dist/services/bundler/spec/packjockel-service.spec.js +0 -149
- package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +0 -15
- package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +0 -70
- package/dist/services/deploy/error/check-module-file-error.d.ts +0 -4
- package/dist/services/deploy/error/check-module-file-error.js +0 -4
- package/dist/services/deploy/error/post-deploy-deployment-detection-error.d.ts +0 -4
- package/dist/services/deploy/error/post-deploy-deployment-detection-error.js +0 -4
- /package/dist/services/{bundler/spec/packjockel-service.spec.d.ts → deploy/spec/deploy-service.spec.d.ts} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { AbortResponse } from "../../browser/abort-response.js";
|
|
4
|
+
import { ForeignInstallRequest } from "../../inject/foreign-install-request.js";
|
|
5
|
+
const APP = "example.app.baqend.com";
|
|
6
|
+
function handler(testingId) {
|
|
7
|
+
const warnings = [];
|
|
8
|
+
const cli = {
|
|
9
|
+
writeWarning: (message) => warnings.push(message),
|
|
10
|
+
};
|
|
11
|
+
return { warnings, handler: new ForeignInstallRequest(APP, cli, testingId) };
|
|
12
|
+
}
|
|
13
|
+
function request(url) {
|
|
14
|
+
return { request: { url } };
|
|
15
|
+
}
|
|
16
|
+
describe("ForeignInstallRequest", () => {
|
|
17
|
+
it("has a pattern that the dispatcher matches against an install resource", () => {
|
|
18
|
+
const [{ urlPattern }] = handler().handler.patterns;
|
|
19
|
+
const expression = new RegExp(urlPattern);
|
|
20
|
+
expect(expression.test("https://other.app.baqend.com/v1/speedkit/install.js")).to.equal(true);
|
|
21
|
+
expect(expression.test("https://www.example.com/app.js")).to.equal(false);
|
|
22
|
+
});
|
|
23
|
+
it("lets the install resource of the injected app through", async () => {
|
|
24
|
+
const { handler: foreign, warnings } = handler();
|
|
25
|
+
const response = await foreign.handle(request(`https://${APP}/v1/speedkit/install.js?d=production`));
|
|
26
|
+
expect(response).to.equal(null);
|
|
27
|
+
expect(warnings).to.deep.equal([]);
|
|
28
|
+
});
|
|
29
|
+
it("blocks the install resource of another app, and says so once", async () => {
|
|
30
|
+
const { handler: foreign, warnings } = handler();
|
|
31
|
+
const url = "https://other.app.baqend.com/v1/speedkit/install.js";
|
|
32
|
+
const response = await foreign.handle(request(url));
|
|
33
|
+
await foreign.handle(request(url));
|
|
34
|
+
expect(response).to.be.instanceOf(AbortResponse);
|
|
35
|
+
expect(response.errorReason).to.equal("BlockedByClient");
|
|
36
|
+
expect(warnings).to.have.length(1);
|
|
37
|
+
expect(warnings[0]).to.contain(url);
|
|
38
|
+
});
|
|
39
|
+
it("blocks the live installation of the app while a testing installation is injected", async () => {
|
|
40
|
+
const { handler: foreign } = handler("abc-123");
|
|
41
|
+
expect(await foreign.handle(request(`https://${APP}/v1/speedkit/install.js`))).to.be.instanceOf(AbortResponse);
|
|
42
|
+
});
|
|
43
|
+
it("lets the testing installation through, also when the worker added the id again", async () => {
|
|
44
|
+
const { handler: foreign } = handler("abc-123");
|
|
45
|
+
expect(await foreign.handle(request(`https://${APP}/v1/speedkit/install.js?r=abc-123&r=abc-123`))).to.equal(null);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { InjectDocumentRewrite } from "../../inject/inject-document-rewrite.js";
|
|
4
|
+
import { InjectedInstallation } from "../../inject/injected-installation.js";
|
|
5
|
+
const APP = "https://example.app.baqend.com";
|
|
6
|
+
const INSTALL = `${APP}/v1/speedkit/install.js`;
|
|
7
|
+
function rewrite(removeContentSecurityPolicy = false, testingId) {
|
|
8
|
+
const warnings = [];
|
|
9
|
+
const cli = {
|
|
10
|
+
writeWarning: (message) => warnings.push(message),
|
|
11
|
+
};
|
|
12
|
+
const installation = new InjectedInstallation({ installPath: INSTALL, installParams: 'crossorigin="anonymous"' }, testingId);
|
|
13
|
+
return {
|
|
14
|
+
warnings,
|
|
15
|
+
rewrite: new InjectDocumentRewrite(installation, APP, removeContentSecurityPolicy, cli),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
describe("InjectDocumentRewrite", () => {
|
|
19
|
+
it("injects the install script into a document without Speed Kit", () => {
|
|
20
|
+
const html = rewrite().rewrite.html("<html><head></head></html>");
|
|
21
|
+
expect(html).to.contain(`src="${INSTALL}" crossorigin="anonymous"`);
|
|
22
|
+
});
|
|
23
|
+
it("replaces the live install script with the testing installation", () => {
|
|
24
|
+
const html = rewrite(false, "abc-123").rewrite.html(`<html><head><script src="${INSTALL}" async></script></head></html>`);
|
|
25
|
+
expect(html.match(/install\.js/g)).to.have.length(1);
|
|
26
|
+
expect(html).to.contain(`src="${INSTALL}?r=abc-123"`);
|
|
27
|
+
});
|
|
28
|
+
it("reuses the nonce of the origin for the install script", () => {
|
|
29
|
+
const html = rewrite().rewrite.html(`<html><head><script nonce="n0nce">1</script></head></html>`);
|
|
30
|
+
expect(html).to.contain(`<script nonce="n0nce" src="${INSTALL}"`);
|
|
31
|
+
});
|
|
32
|
+
it("amends the policy header and prints the change once", () => {
|
|
33
|
+
const { rewrite: documentRewrite, warnings } = rewrite();
|
|
34
|
+
const headers = [
|
|
35
|
+
{ name: "Content-Security-Policy", value: "script-src 'self'" },
|
|
36
|
+
{
|
|
37
|
+
name: "Content-Security-Policy-Report-Only",
|
|
38
|
+
value: "script-src 'self'",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
const first = documentRewrite.headers(headers);
|
|
42
|
+
documentRewrite.headers(headers);
|
|
43
|
+
expect(first).to.deep.equal([
|
|
44
|
+
{ name: "Content-Security-Policy", value: `script-src 'self' ${APP}` },
|
|
45
|
+
{
|
|
46
|
+
name: "Content-Security-Policy-Report-Only",
|
|
47
|
+
value: "script-src 'self'",
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
expect(warnings).to.have.length(1);
|
|
51
|
+
expect(warnings[0]).to.contain("script-src");
|
|
52
|
+
});
|
|
53
|
+
it("removes every policy with -s", () => {
|
|
54
|
+
const { rewrite: documentRewrite, warnings } = rewrite(true);
|
|
55
|
+
const headers = documentRewrite.headers([
|
|
56
|
+
{ name: "content-security-policy", value: "script-src 'self'" },
|
|
57
|
+
{ name: "content-type", value: "text/html" },
|
|
58
|
+
]);
|
|
59
|
+
const html = documentRewrite.html(`<html><head><meta http-equiv="Content-Security-Policy" content="script-src 'self'"></head></html>`);
|
|
60
|
+
expect(headers).to.deep.equal([
|
|
61
|
+
{ name: "content-type", value: "text/html" },
|
|
62
|
+
]);
|
|
63
|
+
expect(html).not.to.contain("Content-Security-Policy");
|
|
64
|
+
expect(warnings).to.deep.equal([]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { InjectedInstallation } from "../../inject/injected-installation.js";
|
|
4
|
+
const RESOURCE = {
|
|
5
|
+
installPath: "https://example.app.baqend.com/v1/speedkit/install.js",
|
|
6
|
+
installParams: 'async="" crossorigin="anonymous"',
|
|
7
|
+
};
|
|
8
|
+
describe("InjectedInstallation", () => {
|
|
9
|
+
it("injects the latest deployed installation without a testing id", () => {
|
|
10
|
+
const installation = new InjectedInstallation(RESOURCE);
|
|
11
|
+
expect(installation.installPath).to.equal(RESOURCE.installPath);
|
|
12
|
+
expect(installation.installParams).to.equal(RESOURCE.installParams);
|
|
13
|
+
expect(installation.installPage("/")).to.equal("/speed-kit-install.html?url=%2F&enableSpeedKit=1");
|
|
14
|
+
});
|
|
15
|
+
it("names the testing installation in the install resource and on the install page", () => {
|
|
16
|
+
const installation = new InjectedInstallation(RESOURCE, "abc-123");
|
|
17
|
+
expect(installation.installPath).to.equal(`${RESOURCE.installPath}?r=abc-123`);
|
|
18
|
+
expect(installation.installPage("/de/")).to.equal("/de/speed-kit-install.html?url=%2Fde%2F&enableSpeedKit=1&debugSpeedKit=abc-123");
|
|
19
|
+
});
|
|
20
|
+
it("appends to an install path that has a query", () => {
|
|
21
|
+
const installation = new InjectedInstallation({ ...RESOURCE, installPath: "/sk/install.js?v=2" }, "abc-123");
|
|
22
|
+
expect(installation.installPath).to.equal("/sk/install.js?v=2&r=abc-123");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { withInjectDefault } from "../onboarding-service-build-context.js";
|
|
4
|
+
describe("withInjectDefault", () => {
|
|
5
|
+
it("gives --inject at the end the latest installation", () => {
|
|
6
|
+
expect(withInjectDefault(["customers/shop", "--inject"])).to.deep.equal([
|
|
7
|
+
"customers/shop",
|
|
8
|
+
"--inject=latest",
|
|
9
|
+
]);
|
|
10
|
+
});
|
|
11
|
+
it("gives --inject before another flag the latest installation", () => {
|
|
12
|
+
expect(withInjectDefault(["customers/shop", "--inject", "--headless"])).to.deep.equal(["customers/shop", "--inject=latest", "--headless"]);
|
|
13
|
+
});
|
|
14
|
+
it("keeps the id that follows --inject", () => {
|
|
15
|
+
const argv = ["customers/shop", "--inject", "abc-123", "-p"];
|
|
16
|
+
expect(withInjectDefault(argv)).to.deep.equal(argv);
|
|
17
|
+
});
|
|
18
|
+
it("keeps --inject=<id>", () => {
|
|
19
|
+
const argv = ["customers/shop", "--inject=abc-123"];
|
|
20
|
+
expect(withInjectDefault(argv)).to.deep.equal(argv);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -5,6 +5,8 @@ import { tmpdir } from "node:os";
|
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { BrowseService } from "../browse/browse-service.js";
|
|
7
7
|
import { BrowseDomainError } from "../error/browse-domain-error.js";
|
|
8
|
+
import { InjectTargetError } from "../error/inject-target-error.js";
|
|
9
|
+
import { InjectService } from "../inject/inject-service.js";
|
|
8
10
|
import { MissingCustomerPathError } from "../error/missing-customer-path-error.js";
|
|
9
11
|
import { BrowserContext } from "../onboarding-model.js";
|
|
10
12
|
import { OnboardingServiceBuildContext, } from "../onboarding-service-build-context.js";
|
|
@@ -40,12 +42,18 @@ function buildContext(values = {}) {
|
|
|
40
42
|
debugPort: 9290,
|
|
41
43
|
browserFetch: false,
|
|
42
44
|
browse: false,
|
|
45
|
+
inject: false,
|
|
43
46
|
...values,
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
49
|
/** Records what browse mode would launch, instead of resolving extensions and Chrome. */
|
|
47
50
|
class RecordingFactory extends OnboardingServiceFactory {
|
|
48
51
|
launched;
|
|
52
|
+
installationRead;
|
|
53
|
+
async readDeployedInstallation(installPath, origin) {
|
|
54
|
+
this.installationRead = { installPath, origin };
|
|
55
|
+
return { swPath: "/deployed-sw.js", scope: "/" };
|
|
56
|
+
}
|
|
49
57
|
async prepareBrowser(domain, customerChromeFlags) {
|
|
50
58
|
this.launched = { domain, customerChromeFlags };
|
|
51
59
|
return {
|
|
@@ -60,7 +68,7 @@ class RecordingFactory extends OnboardingServiceFactory {
|
|
|
60
68
|
}
|
|
61
69
|
describe("OnboardingServiceFactory", () => {
|
|
62
70
|
describe("CUSTOMERPATH", () => {
|
|
63
|
-
it("is required without --browse", async () => {
|
|
71
|
+
it("is required without --browse and without --inject", async () => {
|
|
64
72
|
const factory = new OnboardingServiceFactory(buildContext());
|
|
65
73
|
const error = await factory.getService().catch((error_) => error_);
|
|
66
74
|
expect(error).to.be.instanceOf(MissingCustomerPathError);
|
|
@@ -81,7 +89,7 @@ describe("OnboardingServiceFactory", () => {
|
|
|
81
89
|
expect(factory.launched).to.equal(undefined);
|
|
82
90
|
});
|
|
83
91
|
});
|
|
84
|
-
describe("
|
|
92
|
+
describe("a mode that reads only config_customer.json", () => {
|
|
85
93
|
let customerPath;
|
|
86
94
|
before(() => {
|
|
87
95
|
customerPath = mkdtempSync(join(tmpdir(), "sk-browse-"));
|
|
@@ -114,6 +122,49 @@ describe("OnboardingServiceFactory", () => {
|
|
|
114
122
|
await factory.getService();
|
|
115
123
|
expect(factory.launched?.domain).to.equal("https://shop.example.com/");
|
|
116
124
|
});
|
|
125
|
+
it("builds the inject service under --inject, without any other config file", async () => {
|
|
126
|
+
const factory = new RecordingFactory(buildContext({ inject: true, testing: "abc-123", customerPath }));
|
|
127
|
+
const service = await factory.getService();
|
|
128
|
+
expect(service).to.be.instanceOf(InjectService);
|
|
129
|
+
expect(factory.launched).to.deep.equal({
|
|
130
|
+
domain: "https://www.example.com/",
|
|
131
|
+
customerChromeFlags: ["--lang=fr"],
|
|
132
|
+
});
|
|
133
|
+
expect(factory.installationRead).to.deep.equal({
|
|
134
|
+
installPath: "https://example-shop.app.baqend.com/v1/speedkit/install.js?d=production&r=abc-123",
|
|
135
|
+
origin: "https://www.example.com",
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe("inject mode without a CUSTOMERPATH", () => {
|
|
140
|
+
it("takes the app and the domain from the flags", async () => {
|
|
141
|
+
const factory = new RecordingFactory(buildContext({
|
|
142
|
+
inject: true,
|
|
143
|
+
app: "example-shop",
|
|
144
|
+
domain: "www.example.com",
|
|
145
|
+
}));
|
|
146
|
+
const service = await factory.getService();
|
|
147
|
+
expect(service).to.be.instanceOf(InjectService);
|
|
148
|
+
expect(factory.launched).to.deep.equal({
|
|
149
|
+
domain: "https://www.example.com/",
|
|
150
|
+
customerChromeFlags: undefined,
|
|
151
|
+
});
|
|
152
|
+
expect(factory.installationRead).to.deep.equal({
|
|
153
|
+
installPath: "https://example-shop.app.baqend.com/v1/speedkit/install.js",
|
|
154
|
+
origin: "https://www.example.com",
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
for (const [missing, values] of [
|
|
158
|
+
["app", { domain: "www.example.com" }],
|
|
159
|
+
["domain", { app: "example-shop" }],
|
|
160
|
+
]) {
|
|
161
|
+
it(`fails without ${missing === "app" ? "an app" : "a domain"}`, async () => {
|
|
162
|
+
const factory = new RecordingFactory(buildContext({ inject: true, ...values }));
|
|
163
|
+
const error = await factory.getService().catch((error_) => error_);
|
|
164
|
+
expect(error).to.be.instanceOf(InjectTargetError);
|
|
165
|
+
expect(factory.launched).to.equal(undefined);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
117
168
|
});
|
|
118
169
|
describe("buildBrowserContext", () => {
|
|
119
170
|
const inputs = {
|
|
@@ -192,6 +192,9 @@ aside.loader:not(.stop)::after {
|
|
|
192
192
|
step1.classList.add('error')
|
|
193
193
|
showError(new Error('unable to load script: {{{installPath}}}' ))
|
|
194
194
|
})
|
|
195
|
+
{{#if crossOrigin}}
|
|
196
|
+
installScript.crossOrigin = 'anonymous';
|
|
197
|
+
{{/if}}
|
|
195
198
|
installScript.setAttribute('src','{{{installPath}}}')
|
|
196
199
|
document.querySelector('head').appendChild(installScript)
|
|
197
200
|
|
|
@@ -5,11 +5,6 @@ export class InstallSpeedKitJsTemplate extends AbstractTemplate {
|
|
|
5
5
|
// Config
|
|
6
6
|
{{{config}}}
|
|
7
7
|
|
|
8
|
-
{{#if configPlugins}}
|
|
9
|
-
// The config writes SpeedKit.config, which packjockel exposes; the overrides below change it.
|
|
10
|
-
var speedKit = SpeedKit.config;
|
|
11
|
-
{{/if}}
|
|
12
|
-
|
|
13
8
|
// Reset potential split test parameters
|
|
14
9
|
speedKit.split = 1.0;
|
|
15
10
|
speedKit.splitTestId = 'debug';
|
|
@@ -22,7 +22,7 @@ export class QueryBuilderFactory {
|
|
|
22
22
|
const customerConfig = files.getCustomerConfig().config;
|
|
23
23
|
const app = customerConfig.app;
|
|
24
24
|
const origins = customerConfig.origins ?? [];
|
|
25
|
-
const speedKitConfig = await this.getSpeedKitConfig(
|
|
25
|
+
const speedKitConfig = await this.getSpeedKitConfig(app, origins[0], files.getSpeedKitConfig());
|
|
26
26
|
const serviceContext = {
|
|
27
27
|
app,
|
|
28
28
|
bySet: this.context.bySet,
|
|
@@ -72,8 +72,8 @@ export class QueryBuilderFactory {
|
|
|
72
72
|
const integrationApi = new IntegrationApiFactory(integrationApiContext).buildService();
|
|
73
73
|
return await integrationApi.run();
|
|
74
74
|
}
|
|
75
|
-
async getSpeedKitConfig(
|
|
76
|
-
const result = await safe(speedKitConfigFile.evaluate(
|
|
75
|
+
async getSpeedKitConfig(app, origin, speedKitConfigFile) {
|
|
76
|
+
const result = await safe(speedKitConfigFile.evaluate(app, origin));
|
|
77
77
|
if (result.success !== true) {
|
|
78
78
|
throw new ParseConfigSpeedKitError(result.error);
|
|
79
79
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -647,7 +647,7 @@
|
|
|
647
647
|
"aliases": [],
|
|
648
648
|
"args": {
|
|
649
649
|
"customerPath": {
|
|
650
|
-
"description": "The customer config path (optional with --browse)",
|
|
650
|
+
"description": "The customer config path (optional with --browse and --inject)",
|
|
651
651
|
"name": "customerPath",
|
|
652
652
|
"required": false
|
|
653
653
|
}
|
|
@@ -657,7 +657,9 @@
|
|
|
657
657
|
"$ sk onboarding <customerPath> -c <configName> -d <domain>",
|
|
658
658
|
"$ sk onboarding customers/decathlon.de -c production -d www.decathlon.de",
|
|
659
659
|
"$ sk onboarding --browse -d www.decathlon.de --headless --debugPort 9290",
|
|
660
|
-
"$ sk onboarding customers/decathlon.de --browse -p"
|
|
660
|
+
"$ sk onboarding customers/decathlon.de --browse -p",
|
|
661
|
+
"$ sk onboarding customers/decathlon.de --inject",
|
|
662
|
+
"$ sk onboarding customers/decathlon.de --inject <installationId>"
|
|
661
663
|
],
|
|
662
664
|
"flags": {
|
|
663
665
|
"configName": {
|
|
@@ -737,6 +739,27 @@
|
|
|
737
739
|
"allowNo": false,
|
|
738
740
|
"type": "boolean"
|
|
739
741
|
},
|
|
742
|
+
"inject": {
|
|
743
|
+
"description": "Inject a deployed Speed Kit installation into the site, for a customer that has not installed Speed Kit. Without a value it uses the latest deployed installation. With an id it uses that testing installation. Needs no local config: without a CUSTOMERPATH, pass --app and -d.",
|
|
744
|
+
"exclusive": [
|
|
745
|
+
"browse"
|
|
746
|
+
],
|
|
747
|
+
"name": "inject",
|
|
748
|
+
"hasDynamicHelp": false,
|
|
749
|
+
"helpValue": "[<installationId>]",
|
|
750
|
+
"multiple": false,
|
|
751
|
+
"type": "option"
|
|
752
|
+
},
|
|
753
|
+
"app": {
|
|
754
|
+
"dependsOn": [
|
|
755
|
+
"inject"
|
|
756
|
+
],
|
|
757
|
+
"description": "The app of the installation that --inject uses. Wins over the app of the customer config.",
|
|
758
|
+
"name": "app",
|
|
759
|
+
"hasDynamicHelp": false,
|
|
760
|
+
"multiple": false,
|
|
761
|
+
"type": "option"
|
|
762
|
+
},
|
|
740
763
|
"browserFetch": {
|
|
741
764
|
"description": "Fetch every origin document with a second headless Chrome instead of a direct request. Only needed when bot protection refuses the CLI outright — a refusal is otherwise detected and rerouted on its own.",
|
|
742
765
|
"name": "browserFetch",
|
|
@@ -1765,5 +1788,5 @@
|
|
|
1765
1788
|
]
|
|
1766
1789
|
}
|
|
1767
1790
|
},
|
|
1768
|
-
"version": "4.43.
|
|
1791
|
+
"version": "4.43.1"
|
|
1769
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.43.
|
|
4
|
+
"version": "4.43.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Baqend.com",
|
|
7
7
|
"email": "info@baqend.com"
|
|
@@ -110,7 +110,6 @@
|
|
|
110
110
|
"@oclif/plugin-help": "^6.2.45",
|
|
111
111
|
"@oclif/plugin-not-found": "^3.2.81",
|
|
112
112
|
"@oclif/plugin-warn-if-update-available": "^3.1.61",
|
|
113
|
-
"@speedkit/packjockel": "2.0.0-beta",
|
|
114
113
|
"@speedkit/rules": "^1.3.0-0",
|
|
115
114
|
"baqend": "^4.2.5",
|
|
116
115
|
"chalk": "^5.6.2",
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The packjockel binary to run.
|
|
3
|
-
*
|
|
4
|
-
* `@speedkit/packjockel` installs one package per platform, `@speedkit/packjockel-<platform>-<arch>`.
|
|
5
|
-
* The CLI runs its binary directly, not the `bin` script of the meta package, which would start a
|
|
6
|
-
* second node process for every bundle.
|
|
7
|
-
*
|
|
8
|
-
* @param configured the `PACKJOCKEL_PATH` setting; empty means the npm package, else the `PATH`
|
|
9
|
-
* @param resolve resolves a module path, for tests
|
|
10
|
-
*/
|
|
11
|
-
export declare function resolvePackjockelBinary(configured: string, resolve?: (request: string) => string): string;
|
|
12
|
-
/**
|
|
13
|
-
* The base path of the `speed-kit-config` imports for a pinned plugin release.
|
|
14
|
-
*
|
|
15
|
-
* @param configPluginsVersion a version such as `1.8.0`, or a channel such as `@release`;
|
|
16
|
-
* empty means the `release` channel
|
|
17
|
-
*/
|
|
18
|
-
export declare function speedKitConfigBasePath(configPluginsVersion?: string): string;
|
|
19
|
-
export interface PackjockelBundleRequest {
|
|
20
|
-
/** The entry points by file name, in output order. */
|
|
21
|
-
entryPoints: Record<string, string>;
|
|
22
|
-
basePaths?: Record<string, string>;
|
|
23
|
-
define?: Record<string, string>;
|
|
24
|
-
platform?: "browser" | "node";
|
|
25
|
-
target?: "es5" | "es6";
|
|
26
|
-
minify?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export interface PackjockelDocumentHandlerRequest {
|
|
29
|
-
documentHandler: string;
|
|
30
|
-
documentHandlerConfig: string;
|
|
31
|
-
speedKitConfig: string;
|
|
32
|
-
appName: string;
|
|
33
|
-
dynamicFetcher?: string;
|
|
34
|
-
dynamicFetcherConfig?: string;
|
|
35
|
-
customStyle?: string;
|
|
36
|
-
basePaths?: Record<string, string>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Bundles with the packjockel binary in embedded mode, so no packjockel server is needed.
|
|
40
|
-
*
|
|
41
|
-
* Every input goes to the binary as a file, because a document handler is too large for one
|
|
42
|
-
* command line argument.
|
|
43
|
-
*/
|
|
44
|
-
export declare class PackjockelService {
|
|
45
|
-
private readonly binaryPath;
|
|
46
|
-
/**
|
|
47
|
-
* @param binaryPath the packjockel binary, a path or a command on the `PATH`
|
|
48
|
-
*/
|
|
49
|
-
constructor(binaryPath: string);
|
|
50
|
-
/**
|
|
51
|
-
* Bundles the entry points in their order into one script. packjockel puts a script before them
|
|
52
|
-
* which exposes the `SpeedKit` global.
|
|
53
|
-
*
|
|
54
|
-
* @returns the bundled code
|
|
55
|
-
*/
|
|
56
|
-
bundle(request: PackjockelBundleRequest): Promise<string>;
|
|
57
|
-
/**
|
|
58
|
-
* Bundles a document handler with its config, the embedded Speed Kit config and the default `post`.
|
|
59
|
-
*
|
|
60
|
-
* @returns the code of one CommonJS module, which exports `post`
|
|
61
|
-
*/
|
|
62
|
-
bundleDocumentHandler(request: PackjockelDocumentHandlerRequest): Promise<string>;
|
|
63
|
-
/**
|
|
64
|
-
* Runs packjockel in a scratch directory, which is removed afterwards.
|
|
65
|
-
*
|
|
66
|
-
* @param buildArgs writes the inputs into the directory and returns the arguments that read them
|
|
67
|
-
*/
|
|
68
|
-
private run;
|
|
69
|
-
private execute;
|
|
70
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
import { PackjockelError } from "./error/packjockel-error.js";
|
|
8
|
-
const execFileAsync = promisify(execFile);
|
|
9
|
-
/** The binary on the `PATH`, when no npm package of packjockel is installed. */
|
|
10
|
-
const PACKJOCKEL_ON_PATH = "packjockel";
|
|
11
|
-
/**
|
|
12
|
-
* The packjockel binary to run.
|
|
13
|
-
*
|
|
14
|
-
* `@speedkit/packjockel` installs one package per platform, `@speedkit/packjockel-<platform>-<arch>`.
|
|
15
|
-
* The CLI runs its binary directly, not the `bin` script of the meta package, which would start a
|
|
16
|
-
* second node process for every bundle.
|
|
17
|
-
*
|
|
18
|
-
* @param configured the `PACKJOCKEL_PATH` setting; empty means the npm package, else the `PATH`
|
|
19
|
-
* @param resolve resolves a module path, for tests
|
|
20
|
-
*/
|
|
21
|
-
export function resolvePackjockelBinary(configured, resolve = createRequire(import.meta.url).resolve) {
|
|
22
|
-
if (configured) {
|
|
23
|
-
return configured;
|
|
24
|
-
}
|
|
25
|
-
const executable = process.platform === "win32" ? "packjockel.exe" : "packjockel";
|
|
26
|
-
try {
|
|
27
|
-
return resolve(`@speedkit/packjockel-${process.platform}-${process.arch}/bin/${executable}`);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return PACKJOCKEL_ON_PATH;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/** Where speed-kit-config publishes its plugins, one folder per version and channel. */
|
|
34
|
-
const SPEED_KIT_CONFIG_URL = "https://www.baqend.com/speed-kit-config/";
|
|
35
|
-
/** The channel the plugins in the `export` format are published to. */
|
|
36
|
-
const DEFAULT_CONFIG_PLUGINS_CHANNEL = "release";
|
|
37
|
-
/**
|
|
38
|
-
* The base path of the `speed-kit-config` imports for a pinned plugin release.
|
|
39
|
-
*
|
|
40
|
-
* @param configPluginsVersion a version such as `1.8.0`, or a channel such as `@release`;
|
|
41
|
-
* empty means the `release` channel
|
|
42
|
-
*/
|
|
43
|
-
export function speedKitConfigBasePath(configPluginsVersion) {
|
|
44
|
-
const folder = configPluginsVersion?.trim().replace(/^@/, "") ||
|
|
45
|
-
DEFAULT_CONFIG_PLUGINS_CHANNEL;
|
|
46
|
-
return `${SPEED_KIT_CONFIG_URL}${folder}/`;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Bundles with the packjockel binary in embedded mode, so no packjockel server is needed.
|
|
50
|
-
*
|
|
51
|
-
* Every input goes to the binary as a file, because a document handler is too large for one
|
|
52
|
-
* command line argument.
|
|
53
|
-
*/
|
|
54
|
-
export class PackjockelService {
|
|
55
|
-
binaryPath;
|
|
56
|
-
/**
|
|
57
|
-
* @param binaryPath the packjockel binary, a path or a command on the `PATH`
|
|
58
|
-
*/
|
|
59
|
-
constructor(binaryPath) {
|
|
60
|
-
this.binaryPath = binaryPath;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Bundles the entry points in their order into one script. packjockel puts a script before them
|
|
64
|
-
* which exposes the `SpeedKit` global.
|
|
65
|
-
*
|
|
66
|
-
* @returns the bundled code
|
|
67
|
-
*/
|
|
68
|
-
async bundle(request) {
|
|
69
|
-
return this.run(async (directory) => {
|
|
70
|
-
const args = [
|
|
71
|
-
"bundle",
|
|
72
|
-
"--bundle",
|
|
73
|
-
`--platform=${request.platform ?? "browser"}`,
|
|
74
|
-
`--target=${request.target ?? "es5"}`,
|
|
75
|
-
];
|
|
76
|
-
if (request.minify) {
|
|
77
|
-
args.push("--minify");
|
|
78
|
-
}
|
|
79
|
-
args.push(...keyValueFlags("--define", request.define));
|
|
80
|
-
for (const [name, code] of Object.entries(request.entryPoints)) {
|
|
81
|
-
args.push(await writeInput(directory, name, code));
|
|
82
|
-
}
|
|
83
|
-
return args;
|
|
84
|
-
}, request.basePaths);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Bundles a document handler with its config, the embedded Speed Kit config and the default `post`.
|
|
88
|
-
*
|
|
89
|
-
* @returns the code of one CommonJS module, which exports `post`
|
|
90
|
-
*/
|
|
91
|
-
async bundleDocumentHandler(request) {
|
|
92
|
-
return this.run(async (directory) => {
|
|
93
|
-
const args = [
|
|
94
|
-
"bundle",
|
|
95
|
-
"document-handler",
|
|
96
|
-
await writeInput(directory, "DocumentHandler.js", request.documentHandler),
|
|
97
|
-
`--document-handler-config=${await writeInput(directory, "documentHandlerConfig.js", request.documentHandlerConfig)}`,
|
|
98
|
-
`--speed-kit-config=${await writeInput(directory, "speedKitConfig.js", request.speedKitConfig)}`,
|
|
99
|
-
`--app-name=${request.appName}`,
|
|
100
|
-
];
|
|
101
|
-
const optional = {
|
|
102
|
-
"dynamic-fetcher": ["dynamicFetcher.js", request.dynamicFetcher],
|
|
103
|
-
"dynamic-fetcher-config": [
|
|
104
|
-
"dynamicFetcherConfig.js",
|
|
105
|
-
request.dynamicFetcherConfig,
|
|
106
|
-
],
|
|
107
|
-
"custom-style": ["customStyle.css", request.customStyle],
|
|
108
|
-
};
|
|
109
|
-
for (const [flag, [name, value]] of Object.entries(optional)) {
|
|
110
|
-
if (value) {
|
|
111
|
-
args.push(`--${flag}=${await writeInput(directory, name, value)}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return args;
|
|
115
|
-
}, request.basePaths);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Runs packjockel in a scratch directory, which is removed afterwards.
|
|
119
|
-
*
|
|
120
|
-
* @param buildArgs writes the inputs into the directory and returns the arguments that read them
|
|
121
|
-
*/
|
|
122
|
-
async run(buildArgs, basePaths = {}) {
|
|
123
|
-
const directory = await mkdtemp(join(tmpdir(), "sk-packjockel-"));
|
|
124
|
-
try {
|
|
125
|
-
const output = join(directory, "out.js");
|
|
126
|
-
const args = [
|
|
127
|
-
...(await buildArgs(directory)),
|
|
128
|
-
...keyValueFlags("--base-path", basePaths),
|
|
129
|
-
"--embedded",
|
|
130
|
-
`--output=${output}`,
|
|
131
|
-
];
|
|
132
|
-
await this.execute(args);
|
|
133
|
-
return await readFile(output, "utf8");
|
|
134
|
-
}
|
|
135
|
-
finally {
|
|
136
|
-
await rm(directory, { recursive: true, force: true });
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
async execute(args) {
|
|
140
|
-
try {
|
|
141
|
-
await execFileAsync(this.binaryPath, args, {
|
|
142
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
const failure = error;
|
|
147
|
-
if (failure.code === "ENOENT") {
|
|
148
|
-
throw new PackjockelError(`packjockel not found at "${this.binaryPath}". Install @speedkit/packjockel or set PACKJOCKEL_PATH to the packjockel binary.`);
|
|
149
|
-
}
|
|
150
|
-
throw new PackjockelError(`packjockel failed: ${withoutLogLines(failure.stderr) || failure.message}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
/** Writes one input into the scratch directory and returns the `file://` value that reads it. */
|
|
155
|
-
async function writeInput(directory, name, content) {
|
|
156
|
-
const path = join(directory, name);
|
|
157
|
-
await writeFile(path, content);
|
|
158
|
-
return `file://${path}`;
|
|
159
|
-
}
|
|
160
|
-
function keyValueFlags(flag, values = {}) {
|
|
161
|
-
return Object.entries(values).map(([key, value]) => `${flag}=${key}=${value}`);
|
|
162
|
-
}
|
|
163
|
-
/** packjockel and its cache log to stderr as well; the error is in the remaining lines. */
|
|
164
|
-
function withoutLogLines(stderr = "") {
|
|
165
|
-
return stderr
|
|
166
|
-
.split("\n")
|
|
167
|
-
.filter((line) => line.trim() &&
|
|
168
|
-
!line.startsWith("time=") &&
|
|
169
|
-
!/^\d{4}\/\d{2}\/\d{2} /.test(line))
|
|
170
|
-
.join("\n");
|
|
171
|
-
}
|