@speedkit/cli 4.48.0 → 4.50.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +8 -1
  3. package/dist/commands/onboarding.d.ts +2 -0
  4. package/dist/commands/onboarding.js +1 -0
  5. package/dist/services/browser-fetch/device-emulation.d.ts +16 -3
  6. package/dist/services/browser-fetch/device-emulation.js +32 -17
  7. package/dist/services/browser-fetch/spec/device-emulation.spec.js +20 -0
  8. package/dist/services/diff/diff-service-factory.js +1 -1
  9. package/dist/services/diff/spec/page-source.spec.js +1 -1
  10. package/dist/services/onboarding/browser/emulate-device.d.ts +13 -0
  11. package/dist/services/onboarding/browser/emulate-device.js +50 -0
  12. package/dist/services/onboarding/browser/launch-browser.js +7 -2
  13. package/dist/services/onboarding/onboarding-model.d.ts +27 -6
  14. package/dist/services/onboarding/onboarding-model.js +88 -15
  15. package/dist/services/onboarding/onboarding-service-build-context.d.ts +7 -0
  16. package/dist/services/onboarding/onboarding-service-build-context.js +12 -0
  17. package/dist/services/onboarding/onboarding-service-factory.d.ts +7 -0
  18. package/dist/services/onboarding/onboarding-service-factory.js +34 -1
  19. package/dist/services/onboarding/spec/onboarding-model.spec.js +93 -2
  20. package/dist/services/onboarding/spec/onboarding-service-build-context.spec.js +16 -1
  21. package/dist/services/origin-request/asset-variations.d.ts +24 -3
  22. package/dist/services/origin-request/asset-variations.js +51 -17
  23. package/dist/services/origin-request/origin-fetcher.d.ts +2 -2
  24. package/dist/services/origin-request/origin-fetcher.js +10 -4
  25. package/dist/services/origin-request/origin-request-service-factory.js +1 -1
  26. package/dist/services/origin-request/origin-request-service.d.ts +6 -2
  27. package/dist/services/origin-request/origin-request-service.js +32 -11
  28. package/dist/services/origin-request/runtime-config-source.d.ts +3 -1
  29. package/dist/services/origin-request/runtime-config-source.js +1 -0
  30. package/dist/services/origin-request/spec/asset-variations.spec.js +58 -0
  31. package/dist/services/origin-request/spec/origin-fetcher.spec.js +16 -1
  32. package/dist/services/origin-request/spec/origin-request-service.spec.js +27 -1
  33. package/dist/services/origin-request/spec/runtime-config-source.spec.d.ts +1 -0
  34. package/dist/services/origin-request/spec/runtime-config-source.spec.js +47 -0
  35. package/oclif.manifest.json +24 -1
  36. package/package.json +1 -1
@@ -27,6 +27,7 @@ function fetcher(cli, runtime) {
27
27
  config: runtime && {
28
28
  variations: runtime.speedKit.variations ?? {},
29
29
  authentications: runtime.speedKit.authentications ?? [],
30
+ originMap: runtime.speedKit.originMap ?? {},
30
31
  },
31
32
  });
32
33
  }
@@ -121,11 +122,25 @@ describe("OriginFetcher.fetch", () => {
121
122
  await fetcher(cli, runtime).fetch(url, "default");
122
123
  expect(received.authorization).to.equal(`Basic ${Buffer.from("shop:secret").toString("base64")}`);
123
124
  });
125
+ it("sends the origin map's headers for a device variation, which carries none of its own", async () => {
126
+ const { cli } = stubCli();
127
+ const runtime = {
128
+ speedKit: {
129
+ originMap: {
130
+ [new URL(url).origin]: {
131
+ headers: { "x-vercel-protection-bypass": "token" },
132
+ },
133
+ },
134
+ },
135
+ };
136
+ await fetcher(cli, runtime).fetch(url, "default");
137
+ expect(received["x-vercel-protection-bypass"]).to.equal("token");
138
+ });
124
139
  it("refuses an undefined variation when strict, as the server does", () => {
125
140
  const { cli } = stubCli();
126
141
  const strict = new OriginFetcher({
127
142
  cli,
128
- config: { variations: {}, authentications: [] },
143
+ config: { variations: {}, authentications: [], originMap: {} },
129
144
  strict: true,
130
145
  });
131
146
  expect(() => strict.prepare(url, "b2b")).to.throw(/b2b not found/);
@@ -1,9 +1,35 @@
1
1
  import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
- import { OriginRequestService } from "../origin-request-service.js";
3
+ import { OriginRequestService, printable } from "../origin-request-service.js";
4
4
  describe("OriginRequestService", () => {
5
5
  it("reports that it sent nothing when the runtime config was not usable", async () => {
6
6
  const service = new OriginRequestService({ pageUrl: "https://shop.test/" }, {}, undefined);
7
7
  expect(await service.run()).to.equal(false);
8
8
  });
9
+ it("prints neither basic auth nor an origin map credential, but keeps plain headers", () => {
10
+ const headers = printable({
11
+ Authorization: "Basic dXNlcjpwYXNz",
12
+ "x-vercel-protection-bypass": "secret",
13
+ cookie: "session=1",
14
+ "cache-control": "no-cache",
15
+ "x-variant": "b2b",
16
+ }, {
17
+ appliedKeys: [],
18
+ resolutionPath: "named",
19
+ originMapHeaders: [
20
+ "x-vercel-protection-bypass",
21
+ "cookie",
22
+ "cache-control",
23
+ ],
24
+ url: "https://shop.test/",
25
+ headers: {},
26
+ });
27
+ expect(headers).to.deep.equal({
28
+ Authorization: "Basic <credentials from the runtime config>",
29
+ "x-vercel-protection-bypass": "<from the origin map>",
30
+ cookie: "<from the origin map>",
31
+ "cache-control": "no-cache",
32
+ "x-variant": "b2b",
33
+ });
34
+ });
9
35
  });
@@ -0,0 +1,47 @@
1
+ import { expect } from "chai";
2
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { afterEach, beforeEach, describe, it } from "mocha";
6
+ import { RuntimeConfigSource } from "../runtime-config-source.js";
7
+ const quietCli = {
8
+ writeError: () => undefined,
9
+ writeSuccess: () => undefined,
10
+ startAction: () => undefined,
11
+ successAction: () => undefined,
12
+ failAction: () => undefined,
13
+ };
14
+ // RuntimeConfigSource reads with node:fs/promises, so these run against a temp dir rather than memfs.
15
+ describe("RuntimeConfigSource", () => {
16
+ let dir;
17
+ beforeEach(async () => {
18
+ dir = await mkdtemp(join(tmpdir(), "runtime-config-"));
19
+ });
20
+ afterEach(() => rm(dir, { recursive: true, force: true }));
21
+ it("loads the origin map", async () => {
22
+ const file = join(dir, "runtime.json");
23
+ await writeFile(file, JSON.stringify({
24
+ speedKit: {
25
+ originMap: {
26
+ "www.example.com": {
27
+ origin: "backend.example.net",
28
+ overrideHostHeader: true,
29
+ },
30
+ },
31
+ },
32
+ }));
33
+ const config = await new RuntimeConfigSource({ cli: quietCli }).load(file);
34
+ expect(config.originMap).to.deep.equal({
35
+ "www.example.com": {
36
+ origin: "backend.example.net",
37
+ overrideHostHeader: true,
38
+ },
39
+ });
40
+ });
41
+ it("loads a config without an origin map as an empty one", async () => {
42
+ const file = join(dir, "runtime.json");
43
+ await writeFile(file, JSON.stringify({ speedKit: { variations: {} } }));
44
+ const config = await new RuntimeConfigSource({ cli: quietCli }).load(file);
45
+ expect(config.originMap).to.deep.equal({});
46
+ });
47
+ });
@@ -790,6 +790,7 @@
790
790
  "$ sk onboarding customers/decathlon.de -c production -d www.decathlon.de",
791
791
  "$ sk onboarding --browse -d www.decathlon.de --headless --debugPort 9290",
792
792
  "$ sk onboarding customers/decathlon.de --browse -p",
793
+ "$ sk onboarding customers/decathlon.de -p --device tablet",
793
794
  "$ sk onboarding customers/decathlon.de --inject",
794
795
  "$ sk onboarding customers/decathlon.de --inject <installationId>"
795
796
  ],
@@ -865,6 +866,28 @@
865
866
  "allowNo": false,
866
867
  "type": "boolean"
867
868
  },
869
+ "device": {
870
+ "description": "Emulate a device in every page and Service Worker: user agent, client hints, viewport, pointer and touch. Without it, Chrome runs as it launches.",
871
+ "name": "device",
872
+ "hasDynamicHelp": false,
873
+ "multiple": false,
874
+ "options": [
875
+ "mobile",
876
+ "tablet",
877
+ "desktop"
878
+ ],
879
+ "type": "option"
880
+ },
881
+ "mobile": {
882
+ "char": "m",
883
+ "description": "Same as --device mobile",
884
+ "exclusive": [
885
+ "device"
886
+ ],
887
+ "name": "mobile",
888
+ "allowNo": false,
889
+ "type": "boolean"
890
+ },
868
891
  "browse": {
869
892
  "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.",
870
893
  "name": "browse",
@@ -2090,5 +2113,5 @@
2090
2113
  ]
2091
2114
  }
2092
2115
  },
2093
- "version": "4.48.0"
2116
+ "version": "4.50.0"
2094
2117
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "4.48.0",
4
+ "version": "4.50.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"