@speedkit/cli 4.36.2 → 4.38.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 +21 -0
- package/README.md +12 -5
- package/dist/commands/find-pops.js +2 -2
- package/dist/commands/generate-pop-config.js +9 -2
- package/dist/commands/login.js +0 -1
- package/dist/commands/onboarding.d.ts +2 -1
- package/dist/commands/onboarding.js +2 -0
- package/dist/helpers/origin-proxy.d.ts +2 -2
- package/dist/helpers/origin-proxy.js +24 -11
- package/dist/helpers/spec/origin-proxy.spec.js +85 -0
- package/dist/services/athena/athena-service-build-context.d.ts +8 -0
- package/dist/services/athena/athena-service-factory.d.ts +10 -0
- package/dist/services/athena/athena-service-factory.js +18 -2
- package/dist/services/athena/baqend-athena-service.d.ts +27 -0
- package/dist/services/athena/baqend-athena-service.js +69 -7
- package/dist/services/athena/error/baqend-query-error.d.ts +4 -0
- package/dist/services/athena/error/baqend-query-error.js +4 -0
- package/dist/services/athena/error/unreadable-response.d.ts +18 -0
- package/dist/services/athena/error/unreadable-response.js +29 -0
- package/dist/services/athena/index.d.ts +2 -0
- package/dist/services/athena/index.js +2 -0
- package/dist/services/athena/spec/baqend-athena-service.spec.js +84 -8
- package/dist/services/cli/cli-environment.d.ts +7 -0
- package/dist/services/cli/cli-environment.js +7 -0
- package/dist/services/config-api/client.js +3 -3
- package/dist/services/config-api/config-api-factory.d.ts +12 -1
- package/dist/services/config-api/config-api-factory.js +13 -3
- package/dist/services/config-api/ensure-login.d.ts +52 -0
- package/dist/services/config-api/ensure-login.js +93 -0
- package/dist/services/config-api/entity-manager-provider.d.ts +24 -2
- package/dist/services/config-api/entity-manager-provider.js +40 -6
- package/dist/services/config-api/error/login-error.d.ts +7 -1
- package/dist/services/config-api/error/login-error.js +13 -2
- package/dist/services/config-api/spec/ensure-login.spec.d.ts +1 -0
- package/dist/services/config-api/spec/ensure-login.spec.js +95 -0
- package/dist/services/deploy/deploy-service-build-context.d.ts +7 -0
- package/dist/services/deploy/deploy-service-factory.js +6 -1
- package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +1 -0
- package/dist/services/document-handler-runtime/factory/document-handler-runtime-service-factory.js +4 -2
- package/dist/services/onboarding/browse/browse-service.d.ts +18 -0
- package/dist/services/onboarding/browse/browse-service.js +61 -0
- package/dist/services/onboarding/browse/browse-url.d.ts +10 -0
- package/dist/services/onboarding/browse/browse-url.js +19 -0
- package/dist/services/onboarding/browser/executable/executable-validator.js +3 -1
- package/dist/services/onboarding/browser/extension/extension-downloader.js +2 -0
- package/dist/services/onboarding/browser/launch-browser.d.ts +9 -0
- package/dist/services/onboarding/browser/launch-browser.js +20 -0
- package/dist/services/onboarding/error/browse-domain-error.d.ts +6 -0
- package/dist/services/onboarding/error/browse-domain-error.js +11 -0
- package/dist/services/onboarding/error/missing-customer-path-error.d.ts +6 -0
- package/dist/services/onboarding/error/missing-customer-path-error.js +11 -0
- package/dist/services/onboarding/onboarding-service-build-context.d.ts +5 -1
- package/dist/services/onboarding/onboarding-service-build-context.js +15 -3
- package/dist/services/onboarding/onboarding-service-factory.d.ts +34 -1
- package/dist/services/onboarding/onboarding-service-factory.js +88 -24
- package/dist/services/onboarding/onboarding-service.d.ts +2 -0
- package/dist/services/onboarding/onboarding-service.js +5 -16
- package/dist/services/onboarding/spec/browse/browse-url.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/browse/browse-url.spec.js +28 -0
- package/dist/services/onboarding/spec/onboarding-service-factory.spec.d.ts +1 -0
- package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +155 -0
- package/dist/services/onboarding/spec/virtual-orestes-app/crawler.spec.js +34 -1
- package/dist/services/pop-config/pop-config-factory.js +1 -0
- package/dist/services/prewarm/auto-pre-warm-factory.js +11 -1
- package/dist/services/query-builder/query-builder-factory.js +4 -0
- package/oclif.manifest.json +12 -4
- package/package.json +1 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { after, before, describe, it } from "mocha";
|
|
3
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { BrowseService } from "../browse/browse-service.js";
|
|
7
|
+
import { BrowseDomainError } from "../error/browse-domain-error.js";
|
|
8
|
+
import { MissingCustomerPathError } from "../error/missing-customer-path-error.js";
|
|
9
|
+
import { BrowserContext } from "../onboarding-model.js";
|
|
10
|
+
import { OnboardingServiceBuildContext, } from "../onboarding-service-build-context.js";
|
|
11
|
+
import { OnboardingServiceFactory } from "../onboarding-service-factory.js";
|
|
12
|
+
const cli = new Proxy({}, {
|
|
13
|
+
get: (_target, property) => property === "nonInteractive" ? true : () => undefined,
|
|
14
|
+
});
|
|
15
|
+
function environment() {
|
|
16
|
+
// chromeUserProfilePath keeps BrowserContext off the filesystem.
|
|
17
|
+
return {
|
|
18
|
+
cli,
|
|
19
|
+
settings: {
|
|
20
|
+
chromePath: "/usr/bin/google-chrome",
|
|
21
|
+
chromeUserProfilePath: "/tmp/sk-test-profile",
|
|
22
|
+
chromeExtensionPaths: "/tmp/sk-test-devtools",
|
|
23
|
+
chromeFlags: ["--lang=de"],
|
|
24
|
+
testApp: "",
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function buildContext(values = {}) {
|
|
29
|
+
return new OnboardingServiceBuildContext({
|
|
30
|
+
environment: environment(),
|
|
31
|
+
customerPath: undefined,
|
|
32
|
+
configName: "production",
|
|
33
|
+
domain: undefined,
|
|
34
|
+
local: false,
|
|
35
|
+
ignoreContentSecurityPolicy: false,
|
|
36
|
+
cliPath: "/tmp",
|
|
37
|
+
verboseLevel: false,
|
|
38
|
+
useTestConfig: false,
|
|
39
|
+
debuggingPort: false,
|
|
40
|
+
headless: true,
|
|
41
|
+
debugPort: 9290,
|
|
42
|
+
browserFetch: false,
|
|
43
|
+
browse: false,
|
|
44
|
+
...values,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Records what browse mode would launch, instead of resolving extensions and Chrome. */
|
|
48
|
+
class RecordingFactory extends OnboardingServiceFactory {
|
|
49
|
+
launched;
|
|
50
|
+
async prepareBrowser(domain, customerChromeFlags) {
|
|
51
|
+
this.launched = { domain, customerChromeFlags };
|
|
52
|
+
return {
|
|
53
|
+
browserContext: this.buildBrowserContext({
|
|
54
|
+
domain,
|
|
55
|
+
browserVersionString: "Google Chrome 146.0.7680.165",
|
|
56
|
+
customerChromeFlags,
|
|
57
|
+
}),
|
|
58
|
+
browserExtensions: { paths: [], hasDevtoolsExtension: false },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
describe("OnboardingServiceFactory", () => {
|
|
63
|
+
describe("CUSTOMERPATH", () => {
|
|
64
|
+
it("is required without --browse", async () => {
|
|
65
|
+
const factory = new OnboardingServiceFactory(buildContext());
|
|
66
|
+
const error = await factory.getService().catch((error_) => error_);
|
|
67
|
+
expect(error).to.be.instanceOf(MissingCustomerPathError);
|
|
68
|
+
});
|
|
69
|
+
it("is optional with --browse", async () => {
|
|
70
|
+
const factory = new RecordingFactory(buildContext({ browse: true, domain: "www.example.com" }));
|
|
71
|
+
const service = await factory.getService();
|
|
72
|
+
expect(service).to.be.instanceOf(BrowseService);
|
|
73
|
+
expect(factory.launched).to.deep.equal({
|
|
74
|
+
domain: "https://www.example.com/",
|
|
75
|
+
customerChromeFlags: undefined,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
it("fails in browse mode without a domain and without a CUSTOMERPATH", async () => {
|
|
79
|
+
const factory = new RecordingFactory(buildContext({ browse: true }));
|
|
80
|
+
const error = await factory.getService().catch((error_) => error_);
|
|
81
|
+
expect(error).to.be.instanceOf(BrowseDomainError);
|
|
82
|
+
expect(factory.launched).to.equal(undefined);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("browse mode with a CUSTOMERPATH", () => {
|
|
86
|
+
let customerPath;
|
|
87
|
+
before(() => {
|
|
88
|
+
customerPath = mkdtempSync(join(tmpdir(), "sk-browse-"));
|
|
89
|
+
writeFileSync(join(customerPath, "config_customer.json"), JSON.stringify({
|
|
90
|
+
production: {
|
|
91
|
+
app: "example-shop",
|
|
92
|
+
domain: "www.example.com",
|
|
93
|
+
origins: ["https://www.example.com"],
|
|
94
|
+
swPath: "/sw.js",
|
|
95
|
+
scope: "/",
|
|
96
|
+
chromeFlags: ["--lang=fr"],
|
|
97
|
+
},
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
after(() => rmSync(customerPath, { recursive: true, force: true }));
|
|
101
|
+
it("opens the domain and passes the chromeFlags of config_customer.json", async () => {
|
|
102
|
+
const factory = new RecordingFactory(buildContext({ browse: true, customerPath }));
|
|
103
|
+
await factory.getService();
|
|
104
|
+
expect(factory.launched).to.deep.equal({
|
|
105
|
+
domain: "https://www.example.com/",
|
|
106
|
+
customerChromeFlags: ["--lang=fr"],
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
it("lets --domain win over config_customer.json", async () => {
|
|
110
|
+
const factory = new RecordingFactory(buildContext({
|
|
111
|
+
browse: true,
|
|
112
|
+
customerPath,
|
|
113
|
+
domain: "shop.example.com",
|
|
114
|
+
}));
|
|
115
|
+
await factory.getService();
|
|
116
|
+
expect(factory.launched?.domain).to.equal("https://shop.example.com/");
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe("buildBrowserContext", () => {
|
|
120
|
+
const inputs = {
|
|
121
|
+
domain: "https://www.example.com/",
|
|
122
|
+
browserVersionString: "Google Chrome 146.0.7680.165",
|
|
123
|
+
customerChromeFlags: ["--lang=fr"],
|
|
124
|
+
};
|
|
125
|
+
function launchOptions(values) {
|
|
126
|
+
return new OnboardingServiceFactory(buildContext(values))
|
|
127
|
+
.buildBrowserContext(inputs)
|
|
128
|
+
.getPuppeteerLaunchOptions();
|
|
129
|
+
}
|
|
130
|
+
for (const mode of [
|
|
131
|
+
{ headless: true, debuggingPort: false },
|
|
132
|
+
{ headless: false, debuggingPort: true },
|
|
133
|
+
{ headless: false, debuggingPort: false },
|
|
134
|
+
]) {
|
|
135
|
+
it(`launches the same Chrome in browse mode as in onboarding (${JSON.stringify(mode)})`, () => {
|
|
136
|
+
expect(launchOptions({ ...mode, browse: true })).to.deep.equal(launchOptions({ ...mode, browse: false }));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
it("keeps the extensions and a TCP debug port next to the pipe", () => {
|
|
140
|
+
const options = launchOptions({ browse: true, headless: true });
|
|
141
|
+
expect(options).to.include({ pipe: true, headless: true });
|
|
142
|
+
expect(options["enableExtensions"]).to.deep.equal([
|
|
143
|
+
"/tmp/sk-test-devtools",
|
|
144
|
+
]);
|
|
145
|
+
expect(options.args).to.include("--remote-debugging-port=9290");
|
|
146
|
+
expect(options.args).to.include("--lang=fr");
|
|
147
|
+
expect(options.args).to.include("--lang=de");
|
|
148
|
+
});
|
|
149
|
+
it("is a BrowserContext for the given domain", () => {
|
|
150
|
+
const browserContext = new OnboardingServiceFactory(buildContext({ browse: true })).buildBrowserContext(inputs);
|
|
151
|
+
expect(browserContext).to.be.instanceOf(BrowserContext);
|
|
152
|
+
expect(browserContext.domain).to.equal(inputs.domain);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -23,8 +23,13 @@ function stubCli() {
|
|
|
23
23
|
describe("Crawler.fetchRemote", () => {
|
|
24
24
|
let server;
|
|
25
25
|
let url;
|
|
26
|
+
/** Raw headers of the last request, exactly as they arrived on the wire. */
|
|
27
|
+
let received;
|
|
26
28
|
beforeEach(async () => {
|
|
27
|
-
server = http.createServer((
|
|
29
|
+
server = http.createServer((request, response) => {
|
|
30
|
+
received = request.headers;
|
|
31
|
+
response.end("origin");
|
|
32
|
+
});
|
|
28
33
|
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
29
34
|
url = `http://127.0.0.1:${server.address().port}/`;
|
|
30
35
|
});
|
|
@@ -46,4 +51,32 @@ describe("Crawler.fetchRemote", () => {
|
|
|
46
51
|
expect(await result.response.text()).to.equal("origin");
|
|
47
52
|
expect(warnings.join(" ")).to.contain("no variations available");
|
|
48
53
|
});
|
|
54
|
+
describe("a runtime config that sets Accept-Language to null", () => {
|
|
55
|
+
const withVariations = (variations) => ({ speedKit: { variations } });
|
|
56
|
+
it("sends no Accept-Language, not even the one fetch adds by default", async () => {
|
|
57
|
+
const { cli } = stubCli();
|
|
58
|
+
const serverConfig = withVariations({
|
|
59
|
+
"*": { headers: { "Accept-Language": null } },
|
|
60
|
+
});
|
|
61
|
+
await new Crawler(cli, serverConfig).fetchRemote(url, "mobile");
|
|
62
|
+
expect(received).to.not.have.property("accept-language");
|
|
63
|
+
expect(received).to.not.have.property("sec-fetch-mode");
|
|
64
|
+
expect(received["user-agent"]).to.contain("SpeedKit/1.0");
|
|
65
|
+
});
|
|
66
|
+
it("sends the value a concrete variation sets over the wildcard", async () => {
|
|
67
|
+
const { cli } = stubCli();
|
|
68
|
+
const serverConfig = withVariations({
|
|
69
|
+
"*": { headers: { "Accept-Language": null } },
|
|
70
|
+
mobile: { headers: { "Accept-Language": "en-GB" } },
|
|
71
|
+
});
|
|
72
|
+
await new Crawler(cli, serverConfig).fetchRemote(url, "mobile");
|
|
73
|
+
expect(received["accept-language"]).to.equal("en-GB");
|
|
74
|
+
});
|
|
75
|
+
it("keeps the server's base value when no config touches the header", async () => {
|
|
76
|
+
const { cli } = stubCli();
|
|
77
|
+
const serverConfig = withVariations({ "*": { headers: {} } });
|
|
78
|
+
await new Crawler(cli, serverConfig).fetchRemote(url, "DEFAULT");
|
|
79
|
+
expect(received["accept-language"]).to.equal("*");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
49
82
|
});
|
|
@@ -9,6 +9,7 @@ export class PopConfigFactory {
|
|
|
9
9
|
const athenaService = await new AthenaServiceFactory(new AthenaServiceBuildContext({
|
|
10
10
|
environment: this.context.environment,
|
|
11
11
|
app: this.context.app,
|
|
12
|
+
promptForLogin: true,
|
|
12
13
|
})).getService();
|
|
13
14
|
return new PopConfigService(athenaService);
|
|
14
15
|
}
|
|
@@ -2,6 +2,7 @@ import { QueryBuilderFactory } from "../query-builder/query-builder-factory.js";
|
|
|
2
2
|
import { PrewarmQueryServiceBuildContext } from "../query-builder/query-builder-service-build-context.js";
|
|
3
3
|
import { normalizeDevices } from "../query-builder/queries/device.js";
|
|
4
4
|
import { ConfigApiContext, ConfigApiServiceFactory, } from "../config-api/index.js";
|
|
5
|
+
import { ensureBaqendLogin } from "../config-api/ensure-login.js";
|
|
5
6
|
import { AssetApiClient } from "./assets/asset-api-client.js";
|
|
6
7
|
import { CsvReader } from "./csv-reader.js";
|
|
7
8
|
import { PreWarmService } from "./pre-warm-service.js";
|
|
@@ -25,6 +26,9 @@ export class AutoPreWarmFactory {
|
|
|
25
26
|
}
|
|
26
27
|
async getService() {
|
|
27
28
|
const cli = this.context.environment.cli;
|
|
29
|
+
// One session for the whole run: the query and the asset API that warms
|
|
30
|
+
// its result are the same app, so they share the environment's login.
|
|
31
|
+
const entityManagerProvider = this.context.environment.entityManagerProvider;
|
|
28
32
|
const queryService = await new QueryBuilderFactory(new PrewarmQueryServiceBuildContext({
|
|
29
33
|
environment: this.context.environment,
|
|
30
34
|
configName: this.context.configName,
|
|
@@ -46,8 +50,14 @@ export class AutoPreWarmFactory {
|
|
|
46
50
|
catalog: this.context.catalog,
|
|
47
51
|
})).buildService();
|
|
48
52
|
const app = queryService.app;
|
|
53
|
+
// Before the query runs, not after: warming the result needs a Baqend
|
|
54
|
+
// session whichever way the query itself was answered, and with AWS
|
|
55
|
+
// credentials the Athena path never asks for one. Building the query above
|
|
56
|
+
// is local, so nothing has been spent yet when this fails. On the Baqend
|
|
57
|
+
// path the session is already there and this costs nothing.
|
|
58
|
+
await ensureBaqendLogin(app, entityManagerProvider, cli);
|
|
49
59
|
const rows = await queryService.execute();
|
|
50
|
-
const configApi = new ConfigApiServiceFactory(new ConfigApiContext(app)).getService();
|
|
60
|
+
const configApi = new ConfigApiServiceFactory(new ConfigApiContext(app), entityManagerProvider).getService();
|
|
51
61
|
const entityManager = await configApi.client.getEntityManager();
|
|
52
62
|
const assetApiClient = new AssetApiClient(entityManager.token, app, this.context.sortParameters, cli);
|
|
53
63
|
const csvReader = new CsvReader();
|
|
@@ -54,6 +54,10 @@ export class QueryBuilderFactory {
|
|
|
54
54
|
app,
|
|
55
55
|
workgroup: this.context.workgroup,
|
|
56
56
|
catalog: this.context.catalog,
|
|
57
|
+
// the query is the command's whole job here, so a missing login
|
|
58
|
+
// is asked for up front rather than failing the run half way
|
|
59
|
+
// through
|
|
60
|
+
promptForLogin: true,
|
|
57
61
|
})).getService()
|
|
58
62
|
: undefined;
|
|
59
63
|
return new QueryBuilderService(serviceContext, parseRuleSets(speedKitConfig), cli, athenaService);
|
package/oclif.manifest.json
CHANGED
|
@@ -632,15 +632,17 @@
|
|
|
632
632
|
"aliases": [],
|
|
633
633
|
"args": {
|
|
634
634
|
"customerPath": {
|
|
635
|
-
"description": "The customer config path",
|
|
635
|
+
"description": "The customer config path (optional with --browse)",
|
|
636
636
|
"name": "customerPath",
|
|
637
|
-
"required":
|
|
637
|
+
"required": false
|
|
638
638
|
}
|
|
639
639
|
},
|
|
640
640
|
"description": "Start a local dev environment for building and testing the Speed Kit configuration",
|
|
641
641
|
"examples": [
|
|
642
642
|
"$ sk onboarding <customerPath> -c <configName> -d <domain>",
|
|
643
|
-
"$ sk onboarding customers/decathlon.de -c production -d www.decathlon.de"
|
|
643
|
+
"$ sk onboarding customers/decathlon.de -c production -d www.decathlon.de",
|
|
644
|
+
"$ sk onboarding --browse -d www.decathlon.de --headless --debugPort 9290",
|
|
645
|
+
"$ sk onboarding customers/decathlon.de --browse -p"
|
|
644
646
|
],
|
|
645
647
|
"flags": {
|
|
646
648
|
"configName": {
|
|
@@ -710,6 +712,12 @@
|
|
|
710
712
|
"allowNo": false,
|
|
711
713
|
"type": "boolean"
|
|
712
714
|
},
|
|
715
|
+
"browse": {
|
|
716
|
+
"description": "Open the live site in the onboarding Chrome, with its extensions, but without request interception or Speed Kit injection. Takes the domain from -d or from the customer config.",
|
|
717
|
+
"name": "browse",
|
|
718
|
+
"allowNo": false,
|
|
719
|
+
"type": "boolean"
|
|
720
|
+
},
|
|
713
721
|
"browserFetch": {
|
|
714
722
|
"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.",
|
|
715
723
|
"name": "browserFetch",
|
|
@@ -1738,5 +1746,5 @@
|
|
|
1738
1746
|
]
|
|
1739
1747
|
}
|
|
1740
1748
|
},
|
|
1741
|
-
"version": "4.
|
|
1749
|
+
"version": "4.38.0"
|
|
1742
1750
|
}
|