@speedkit/cli 4.49.0 → 4.50.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 CHANGED
@@ -1,3 +1,18 @@
1
+ ## [4.50.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.50.0...v4.50.1) (2026-10-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **onboarding:** drop the --device warning about device detection ([e7325a6](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/e7325a6bea67b5ba502a0cda5943b28048372411))
7
+
8
+ # [4.50.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.49.0...v4.50.0) (2026-10-27)
9
+
10
+
11
+ ### Features
12
+
13
+ * **origin-request:** apply the runtime config's origin map to origin fetches ([dfc6f63](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/dfc6f6340033cce1525e7c25a159e8b7654d492b))
14
+ * **origin-request:** hide origin map header values in the report ([65c161a](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/65c161a973d95e3559e46ae7b1c42b8dbd697a5e))
15
+
1
16
  # [4.49.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.48.0...v4.49.0) (2026-10-26)
2
17
 
3
18
 
@@ -145,7 +145,7 @@ export class DiffServiceFactory {
145
145
  async loadRuntimeConfig(log, app) {
146
146
  if (!app && !this.context.variationsFile) {
147
147
  log.writeWarning("no customer: the requests carry Speed Kit's device defaults only, no variations of an app");
148
- return { variations: {}, authentications: [] };
148
+ return { variations: {}, authentications: [], originMap: {} };
149
149
  }
150
150
  return new RuntimeConfigSource({
151
151
  cli: log,
@@ -29,7 +29,7 @@ function fetcher() {
29
29
  writeWarning: () => undefined,
30
30
  writeError: () => undefined,
31
31
  },
32
- config: { variations: {}, authentications: [] },
32
+ config: { variations: {}, authentications: [], originMap: {} },
33
33
  strict: true,
34
34
  });
35
35
  }
@@ -50,13 +50,6 @@ export declare class OnboardingServiceFactory {
50
50
  customerChromeFlags?: string[];
51
51
  }): BrowserContext;
52
52
  private getOnboardingService;
53
- /**
54
- * `--device` only changes what Speed Kit does if the config derives the device from the user
55
- * agent. `RequestContext.getDevice` short-circuits on a pinned `customDevice` and returns nothing
56
- * at all when `userAgentDetection` is off. In both cases no `bqvariation` is appended and the
57
- * emulated device silently gets desktop assets. Say so up front.
58
- */
59
- private warnAboutDeviceDetection;
60
53
  private prepareMessagehandler;
61
54
  /**
62
55
  * The app token for the devtools extension, or `null` when nobody is logged
@@ -240,9 +240,6 @@ export class OnboardingServiceFactory {
240
240
  const speedKitInstallContext = new SpeedKitInstallContext(customerConfig, this.context.configName, files, bundler, skTemplate);
241
241
  await this.buildInstallResource(speedKitInstallContext, files, cli);
242
242
  const { browserContext, browserExtensions } = await this.prepareBrowser(domainToStart, customerConfig.chromeFlags);
243
- if (this.context.device) {
244
- await this.warnAboutDeviceDetection(files, customerConfig, domainToStart);
245
- }
246
243
  const fileWatcher = new FileWatcher(cli, customerConfig, files, documentHandler, browserContext, cache);
247
244
  const athenaClient = (await this.getAthenaClient(customerConfig.app)) || null;
248
245
  const messageHandler = await this.prepareMessagehandler(athenaClient, files, customerConfig);
@@ -251,32 +248,6 @@ export class OnboardingServiceFactory {
251
248
  const extensionBridge = new ExtensionBridge(cli, browserExtensions.hasDevtoolsExtension);
252
249
  return new OnboardingService(browserContext, customerConfig, fetchHandler, fileWatcher, cli, messageHandler, extensionBridge, speedKitServiceWorkerJs, browserFetch);
253
250
  }
254
- /**
255
- * `--device` only changes what Speed Kit does if the config derives the device from the user
256
- * agent. `RequestContext.getDevice` short-circuits on a pinned `customDevice` and returns nothing
257
- * at all when `userAgentDetection` is off. In both cases no `bqvariation` is appended and the
258
- * emulated device silently gets desktop assets. Say so up front.
259
- */
260
- async warnAboutDeviceDetection(files, customerConfig, domain) {
261
- const cli = this.context.environment.cli;
262
- const speedKitConfig = files.getSpeedKitConfig();
263
- if (!speedKitConfig) {
264
- return;
265
- }
266
- const config = await safe(speedKitConfig.evaluate(customerConfig.app, new URL(domain).origin));
267
- if (config.success !== true) {
268
- cli.writeWarning(`Could not check the Speed Kit config for device detection: ${config.error}`);
269
- return;
270
- }
271
- // `raw` for the pin: `SSRPlugin` wraps `detectDevice` in `effective` for every config.
272
- const { raw, effective } = config.data;
273
- if (!effective.userAgentDetection && this.context.device !== "desktop") {
274
- cli.writeWarning(`userAgentDetection is off in the Speed Kit config — Speed Kit resolves the desktop variation regardless of --device ${this.context.device}.`);
275
- }
276
- if (raw.customDevice || raw.detectDevice) {
277
- cli.writeWarning("The Speed Kit config pins the device via customDevice/detectDevice, which takes precedence over the emulated user agent.");
278
- }
279
- }
280
251
  async prepareMessagehandler(athenaClient, files, customerConfig) {
281
252
  const messageHandler = new DevtoolsExtensionApi();
282
253
  messageHandler.addMessage({
@@ -5,8 +5,8 @@
5
5
  * Mirrors two pieces of server behaviour:
6
6
  * - `AssetVariations.getVariations()` — which variation configs apply and in which order
7
7
  * (orestes: `orestes-common/.../typesystem/AssetVariations.kt`)
8
- * - `AssetClient.newRequest()` / `createRequest()` — base headers, last-writer-wins merging,
9
- * urlPrefix and queryParams (orestes: `orestes-server/.../asset/AssetClient.kt`)
8
+ * - `AssetClient.newRequest()` / `createRequest()` — the origin map, base headers,
9
+ * last-writer-wins merging, urlPrefix and queryParams (orestes: `orestes-server/.../asset/AssetClient.kt`)
10
10
  *
11
11
  * Keep this file free of I/O so the resolution stays unit-testable.
12
12
  */
@@ -21,11 +21,25 @@ export interface AssetVariation {
21
21
  matchedKey?: string;
22
22
  }
23
23
  export type AssetVariationMap = Record<string, AssetVariation>;
24
+ /** An entry of the runtime config's `speedKit.originMap`, keyed by origin or by host. */
25
+ export interface OriginMapEntry {
26
+ /** Replaces the host, or the scheme and the host when it carries a scheme. */
27
+ origin?: string | null;
28
+ /** Keeps the original Host header after `origin` rewrote the url. */
29
+ overrideHostHeader?: boolean;
30
+ /** Sent with every request to this origin; the base and variation headers win on a conflict. */
31
+ headers?: Record<string, string>;
32
+ }
33
+ export type OriginMap = Record<string, OriginMapEntry>;
24
34
  export interface ResolvedRequest {
25
35
  /** Keys of the applied configs, in the order the server applies them. */
26
36
  appliedKeys: string[];
27
37
  /** `template` when a regex entry matched, otherwise `named`. */
28
38
  resolutionPath: "template" | "named";
39
+ /** The origin map key that applied, if any. */
40
+ originMapKey?: string;
41
+ /** Lower-case names of the headers whose sent value comes from the origin map. */
42
+ originMapHeaders?: string[];
29
43
  url: string;
30
44
  headers: Record<string, string>;
31
45
  }
@@ -43,7 +57,14 @@ export declare class UndefinedVariationError extends Error {
43
57
  * `[wildcard, template]` and skips the device defaults; otherwise `[default, wildcard, named]`.
44
58
  */
45
59
  export declare function getVariations(custom: AssetVariationMap, variationType?: string): AssetVariation[];
60
+ /** What a request is resolved against besides the variations. */
61
+ export interface ResolveOptions {
62
+ /** A Host header for every request, as `--host` sends it. */
63
+ hostOverride?: string;
64
+ /** The runtime config's `speedKit.originMap`. */
65
+ originMap?: OriginMap;
66
+ }
46
67
  /** Resolves a variation into the concrete request the server would send. */
47
- export declare function resolveRequest(custom: AssetVariationMap, url: string, variationType?: string, hostOverride?: string): ResolvedRequest;
68
+ export declare function resolveRequest(custom: AssetVariationMap, url: string, variationType?: string, { hostOverride, originMap }?: ResolveOptions): ResolvedRequest;
48
69
  /** Renders the resolved request as a curl command, for pasting into a bug report. */
49
70
  export declare function toCurl(url: string, headers: Record<string, string>): string;
@@ -5,8 +5,8 @@
5
5
  * Mirrors two pieces of server behaviour:
6
6
  * - `AssetVariations.getVariations()` — which variation configs apply and in which order
7
7
  * (orestes: `orestes-common/.../typesystem/AssetVariations.kt`)
8
- * - `AssetClient.newRequest()` / `createRequest()` — base headers, last-writer-wins merging,
9
- * urlPrefix and queryParams (orestes: `orestes-server/.../asset/AssetClient.kt`)
8
+ * - `AssetClient.newRequest()` / `createRequest()` — the origin map, base headers,
9
+ * last-writer-wins merging, urlPrefix and queryParams (orestes: `orestes-server/.../asset/AssetClient.kt`)
10
10
  *
11
11
  * Keep this file free of I/O so the resolution stays unit-testable.
12
12
  */
@@ -121,19 +121,40 @@ function buildUrl(url, chain) {
121
121
  return result;
122
122
  }
123
123
  /**
124
- * Base headers from AssetClient.newRequest, then each config's headers with the last writer
125
- * winning. A `null` value removes the header, which is how a config drops Accept-Language.
124
+ * The origin map entry for a url. Like AssetClient.createRequest, it tries `scheme://host` first
125
+ * and the host alone second.
126
126
  */
127
- function buildHeaders(chain, hostOverride) {
128
- const headers = new Map([
129
- [
130
- "accept",
131
- "text/html, application/xhtml+xml, application/xml;q=0.9, image/avif, image/webp, */*;q=0.8",
132
- ],
133
- ["accept-encoding", "gzip"],
134
- ["accept-language", "*"],
135
- ["user-agent", DEFAULT_USER_AGENT],
136
- ]);
127
+ function findOriginMapEntry(originMap, url) {
128
+ for (const key of [url.origin, url.host]) {
129
+ if (originMap[key])
130
+ return [key, originMap[key]];
131
+ }
132
+ return undefined;
133
+ }
134
+ /** URIs.cloneWithOrigin: `origin` replaces the host, plus the scheme when it names one. */
135
+ function withOrigin(url, origin) {
136
+ const target = new URL(origin.includes("://") ? origin : `${url.protocol}//${origin}`);
137
+ const result = new URL(url);
138
+ result.protocol = target.protocol;
139
+ result.host = target.host;
140
+ return result.toString();
141
+ }
142
+ /**
143
+ * The origin map's headers and Host first, because createRequest sets them before newRequest
144
+ * adds the rest. Then the base headers, then each config's headers, the last writer winning. A
145
+ * `null` value removes the header, which is how a config drops Accept-Language.
146
+ */
147
+ function buildHeaders(chain, hostOverride, originEntry, originalHost) {
148
+ const headers = new Map();
149
+ for (const [key, value] of Object.entries(originEntry?.headers ?? {})) {
150
+ headers.set(key.toLowerCase(), String(value));
151
+ }
152
+ if (originalHost)
153
+ headers.set("host", originalHost);
154
+ headers.set("accept", "text/html, application/xhtml+xml, application/xml;q=0.9, image/avif, image/webp, */*;q=0.8");
155
+ headers.set("accept-encoding", "gzip");
156
+ headers.set("accept-language", "*");
157
+ headers.set("user-agent", DEFAULT_USER_AGENT);
137
158
  for (const config of chain) {
138
159
  for (const [key, value] of Object.entries(config.headers ?? {})) {
139
160
  if (value === null)
@@ -147,16 +168,29 @@ function buildHeaders(chain, hostOverride) {
147
168
  return Object.fromEntries(headers);
148
169
  }
149
170
  /** Resolves a variation into the concrete request the server would send. */
150
- export function resolveRequest(custom, url, variationType, hostOverride) {
171
+ export function resolveRequest(custom, url, variationType, { hostOverride, originMap = {} } = {}) {
151
172
  const chain = getVariations(custom, variationType);
173
+ const parsed = new URL(url);
174
+ const [originMapKey, originEntry] = findOriginMapEntry(originMap, parsed) ?? [];
175
+ const requestUrl = originEntry?.origin
176
+ ? withOrigin(parsed, originEntry.origin)
177
+ : url;
178
+ const originalHost = originEntry?.origin && originEntry.overrideHostHeader
179
+ ? parsed.hostname
180
+ : undefined;
152
181
  const isTemplate = chain.some((config) => config.matchedKey !== WILD_CARD &&
153
182
  !DEVICE_DEFAULTS[config.matchedKey ?? ""]) &&
154
183
  !chain.some((config) => config.matchedKey?.startsWith("device-default:"));
184
+ const headers = buildHeaders(chain, hostOverride, originEntry, originalHost);
185
+ const originMapHeaders = Object.entries(originEntry?.headers ?? {})
186
+ .filter(([key, value]) => headers[key.toLowerCase()] === String(value))
187
+ .map(([key]) => key.toLowerCase());
155
188
  return {
156
189
  appliedKeys: chain.map((config) => config.matchedKey ?? "?"),
157
190
  resolutionPath: isTemplate ? "template" : "named",
158
- url: buildUrl(url, chain),
159
- headers: buildHeaders(chain, hostOverride),
191
+ ...(originMapKey ? { originMapKey, originMapHeaders } : {}),
192
+ url: buildUrl(requestUrl, chain),
193
+ headers,
160
194
  };
161
195
  }
162
196
  /** Renders the resolved request as a curl command, for pasting into a bug report. */
@@ -27,8 +27,8 @@ export interface PreparedOriginRequest {
27
27
  * dashboard diffs, `sk origin-request` and `sk diff` all fetch through it.
28
28
  *
29
29
  * The resolution itself is `resolveRequest`: the base headers, the wildcard-then-variation order,
30
- * the regex templates with their `${group}` substitution, and the query params. On top of it
31
- * comes origin basic auth, which no variation carries.
30
+ * the regex templates with their `${group}` substitution, the query params and the origin map.
31
+ * On top of it comes origin basic auth, which no variation carries.
32
32
  */
33
33
  export declare class OriginFetcher {
34
34
  private readonly deps;
@@ -8,8 +8,8 @@ import { resolveRequest, UndefinedVariationError, } from "./asset-variations.js"
8
8
  * dashboard diffs, `sk origin-request` and `sk diff` all fetch through it.
9
9
  *
10
10
  * The resolution itself is `resolveRequest`: the base headers, the wildcard-then-variation order,
11
- * the regex templates with their `${group}` substitution, and the query params. On top of it
12
- * comes origin basic auth, which no variation carries.
11
+ * the regex templates with their `${group}` substitution, the query params and the origin map.
12
+ * On top of it comes origin basic auth, which no variation carries.
13
13
  */
14
14
  export class OriginFetcher {
15
15
  deps;
@@ -56,7 +56,10 @@ export class OriginFetcher {
56
56
  }
57
57
  resolve(variations, originUrl, variation) {
58
58
  try {
59
- return resolveRequest(variations, originUrl, variation, this.deps.host);
59
+ return resolveRequest(variations, originUrl, variation, {
60
+ hostOverride: this.deps.host,
61
+ originMap: this.deps.config?.originMap,
62
+ });
60
63
  }
61
64
  catch (error) {
62
65
  // Only a custom variation reaches this branch: a device variation (default, mobile, tablet)
@@ -72,7 +75,10 @@ export class OriginFetcher {
72
75
  ? `defined are: ${defined.join(", ")}. `
73
76
  : "it defines no variations at all. ") +
74
77
  "Falling back to the base headers.");
75
- return resolveRequest({}, originUrl, undefined, this.deps.host);
78
+ return resolveRequest({}, originUrl, undefined, {
79
+ hostOverride: this.deps.host,
80
+ originMap: this.deps.config?.originMap,
81
+ });
76
82
  }
77
83
  }
78
84
  authorization(originUrl) {
@@ -48,7 +48,7 @@ export class OriginRequestServiceFactory {
48
48
  if (!this.context.json) {
49
49
  cli.writeWarning("no customer: the request carries Speed Kit's device defaults only, no variation of an app");
50
50
  }
51
- return { variations: {}, authentications: [] };
51
+ return { variations: {}, authentications: [], originMap: {} };
52
52
  }
53
53
  return new RuntimeConfigSource({
54
54
  cli,
@@ -1,6 +1,12 @@
1
1
  import { CliServiceInterface } from "../cli/index.js";
2
2
  import { OriginRequestOptions } from "./origin-request-service-build-context.js";
3
3
  import { OriginFetcher } from "./origin-fetcher.js";
4
+ import { ResolvedRequest } from "./asset-variations.js";
5
+ /**
6
+ * The headers as reported. Origin basic auth and the origin map's headers are sent, but their
7
+ * values are not printed: the runtime config stores credentials there, such as a bypass token.
8
+ */
9
+ export declare function printable(headers: Record<string, string>, { originMapHeaders }: ResolvedRequest): Record<string, string>;
4
10
  /**
5
11
  * Fetches a page from origin with exactly the headers Speed Kit's server would send for a cache
6
12
  * variation, then reports what the origin answered.
@@ -10,8 +16,6 @@ import { OriginFetcher } from "./origin-fetcher.js";
10
16
  * deployed runtime config, so the simulation follows production rather than a local file.
11
17
  *
12
18
  * Known deviations from the server, all deliberate:
13
- * - The origin map (origin rewriting plus its extra headers) lives outside the runtime config;
14
- * use `--host` for the Host part.
15
19
  * - Revalidation headers (If-None-Match, If-Modified-Since) apply only when refreshing a cached
16
20
  * entry, so they are out of scope.
17
21
  * - Header order and the HTTP version come from undici, not Jetty.
@@ -1,14 +1,34 @@
1
1
  import { writeFile } from "node:fs/promises";
2
2
  import { originFetch } from "../../helpers/origin-proxy.js";
3
3
  import { DEFAULT_TYPE, toCurl } from "./asset-variations.js";
4
- /** The headers as reported: origin basic auth is sent, but its credentials are not printed. */
5
- function printable(headers) {
6
- return headers["Authorization"]
7
- ? {
8
- ...headers,
9
- Authorization: "Basic <credentials from the runtime config>",
10
- }
11
- : headers;
4
+ /** Standard request headers that carry no credentials, so an origin map value stays visible. */
5
+ const PLAIN_HEADERS = new Set([
6
+ "accept",
7
+ "accept-encoding",
8
+ "accept-language",
9
+ "cache-control",
10
+ "host",
11
+ "origin",
12
+ "pragma",
13
+ "referer",
14
+ "user-agent",
15
+ "x-forwarded-for",
16
+ "x-forwarded-host",
17
+ "x-forwarded-proto",
18
+ ]);
19
+ /**
20
+ * The headers as reported. Origin basic auth and the origin map's headers are sent, but their
21
+ * values are not printed: the runtime config stores credentials there, such as a bypass token.
22
+ */
23
+ export function printable(headers, { originMapHeaders = [] }) {
24
+ const result = { ...headers };
25
+ if (result["Authorization"])
26
+ result["Authorization"] = "Basic <credentials from the runtime config>";
27
+ for (const key of originMapHeaders) {
28
+ if (!PLAIN_HEADERS.has(key))
29
+ result[key] = "<from the origin map>";
30
+ }
31
+ return result;
12
32
  }
13
33
  /**
14
34
  * Fetches a page from origin with exactly the headers Speed Kit's server would send for a cache
@@ -19,8 +39,6 @@ function printable(headers) {
19
39
  * deployed runtime config, so the simulation follows production rather than a local file.
20
40
  *
21
41
  * Known deviations from the server, all deliberate:
22
- * - The origin map (origin rewriting plus its extra headers) lives outside the runtime config;
23
- * use `--host` for the Host part.
24
42
  * - Revalidation headers (If-None-Match, If-Modified-Since) apply only when refreshing a cached
25
43
  * entry, so they are out of scope.
26
44
  * - Header order and the HTTP version come from undici, not Jetty.
@@ -44,7 +62,7 @@ export class OriginRequestService {
44
62
  return false;
45
63
  const variation = this.context.variation ?? DEFAULT_TYPE;
46
64
  const { url, init, resolved } = this.fetcher.prepare(this.context.pageUrl, this.context.variation);
47
- const headers = printable(init.headers);
65
+ const headers = printable(init.headers, resolved);
48
66
  const response = await originFetch(url, { ...init, redirect: "manual" });
49
67
  const body = await response.text();
50
68
  const setCookies = response.headers.getSetCookie?.() ?? [];
@@ -55,6 +73,7 @@ export class OriginRequestService {
55
73
  variation,
56
74
  resolutionPath: resolved.resolutionPath,
57
75
  appliedConfigs: resolved.appliedKeys,
76
+ originMapKey: resolved.originMapKey ?? null,
58
77
  requestUrl: url,
59
78
  requestHeaders: headers,
60
79
  status: response.status,
@@ -70,6 +89,8 @@ export class OriginRequestService {
70
89
  report(variation, resolved, headers, response, setCookies, body) {
71
90
  this.cli.write(`variation ${variation}`);
72
91
  this.cli.write(`resolution ${resolved.resolutionPath} → applied: ${resolved.appliedKeys.join(" then ")}`);
92
+ if (resolved.originMapKey)
93
+ this.cli.write(`origin map ${resolved.originMapKey}`);
73
94
  this.cli.write(`request url ${resolved.url}`);
74
95
  this.cli.write("request headers");
75
96
  for (const [key, value] of Object.entries(headers))
@@ -1,6 +1,6 @@
1
1
  import { CliServiceInterface } from "../cli/index.js";
2
2
  import { ConfigApiService } from "../config-api/index.js";
3
- import { AssetVariationMap } from "./asset-variations.js";
3
+ import { AssetVariationMap, OriginMap } from "./asset-variations.js";
4
4
  /** Origin basic auth of the runtime config, `speedKit.authentications`. */
5
5
  export interface OriginAuthentication {
6
6
  readonly type: string;
@@ -12,6 +12,8 @@ export interface OriginAuthentication {
12
12
  export interface OriginRequestConfig {
13
13
  readonly variations: AssetVariationMap;
14
14
  readonly authentications: readonly OriginAuthentication[];
15
+ /** `speedKit.originMap`: per origin, a rewrite target and extra headers. */
16
+ readonly originMap: OriginMap;
15
17
  }
16
18
  /** What loading the runtime config reports through. */
17
19
  export type RuntimeConfigLog = Pick<CliServiceInterface, "writeError" | "writeSuccess" | "startAction" | "successAction" | "failAction">;
@@ -21,6 +21,7 @@ export class RuntimeConfigSource {
21
21
  const config = {
22
22
  variations: speedKit.variations ?? {},
23
23
  authentications: speedKit.authentications ?? [],
24
+ originMap: speedKit.originMap ?? {},
24
25
  };
25
26
  const names = Object.keys(config.variations);
26
27
  if (names.length > 0) {
@@ -81,4 +81,62 @@ describe("asset variations", () => {
81
81
  it("reports an unknown variation instead of guessing", () => {
82
82
  expect(() => getVariations({}, "b2b-unknown")).to.throw(UndefinedVariationError);
83
83
  });
84
+ describe("origin map", () => {
85
+ it("sends an entry's headers, but lets the base and variation headers win", () => {
86
+ const { headers, originMapKey, originMapHeaders } = resolveRequest({ "*": { headers: { cookie: "from-variation" } } }, "https://www.example.com/plp", undefined, {
87
+ originMap: {
88
+ "www.example.com": {
89
+ headers: {
90
+ "X-Bypass": "token",
91
+ cookie: "from-origin-map",
92
+ "accept-language": "de",
93
+ },
94
+ },
95
+ },
96
+ });
97
+ expect(originMapKey).to.equal("www.example.com");
98
+ expect(headers["x-bypass"]).to.equal("token");
99
+ expect(headers.cookie).to.equal("from-variation");
100
+ expect(headers["accept-language"]).to.equal("*");
101
+ expect(originMapHeaders).to.deep.equal(["x-bypass"]);
102
+ });
103
+ it("prefers the entry for scheme and host over the one for the host alone", () => {
104
+ const { headers, originMapKey } = resolveRequest({}, "https://www.example.com/plp", undefined, {
105
+ originMap: {
106
+ "www.example.com": { headers: { "x-entry": "host" } },
107
+ "https://www.example.com": { headers: { "x-entry": "origin" } },
108
+ },
109
+ });
110
+ expect(originMapKey).to.equal("https://www.example.com");
111
+ expect(headers["x-entry"]).to.equal("origin");
112
+ });
113
+ it("rewrites the host, keeps path and query, and keeps the Host header on request", () => {
114
+ const { url, headers } = resolveRequest({ "*": { queryParams: ["sk=1"] } }, "https://www.example.com/plp?page=2", undefined, {
115
+ originMap: {
116
+ "www.example.com": {
117
+ origin: "backend.example.net:8443",
118
+ overrideHostHeader: true,
119
+ },
120
+ },
121
+ });
122
+ expect(url).to.equal("https://backend.example.net:8443/plp?page=2&sk=1");
123
+ expect(headers.host).to.equal("www.example.com");
124
+ });
125
+ it("takes the scheme from an origin that names one, and sends its own Host otherwise", () => {
126
+ const { url, headers } = resolveRequest({}, "https://www.example.com/plp", undefined, {
127
+ originMap: {
128
+ "www.example.com": { origin: "http://backend.example.net" },
129
+ },
130
+ });
131
+ expect(url).to.equal("http://backend.example.net/plp");
132
+ expect(headers.host).to.equal(undefined);
133
+ });
134
+ it("leaves a url without an entry untouched", () => {
135
+ const { url, originMapKey } = resolveRequest({}, "https://www.example.com/plp", undefined, {
136
+ originMap: { "shop.example.org": { origin: "backend.example.net" } },
137
+ });
138
+ expect(url).to.equal("https://www.example.com/plp");
139
+ expect(originMapKey).to.equal(undefined);
140
+ });
141
+ });
84
142
  });
@@ -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
+ });
@@ -1495,149 +1495,6 @@
1495
1495
  "setup.js"
1496
1496
  ]
1497
1497
  },
1498
- "extension:add": {
1499
- "aliases": [],
1500
- "args": {
1501
- "ref": {
1502
- "description": "Chrome Web Store link or extension id",
1503
- "name": "ref",
1504
- "required": false
1505
- }
1506
- },
1507
- "description": "Install a Chrome extension into the onboarding browser by Web Store link or id",
1508
- "examples": [
1509
- "$ sk extension add fmkadmapgofadopljbjfkapdkoienihi",
1510
- "$ sk extension add https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi",
1511
- "$ sk extension add"
1512
- ],
1513
- "flags": {},
1514
- "hasDynamicHelp": false,
1515
- "hiddenAliases": [],
1516
- "id": "extension:add",
1517
- "pluginAlias": "@speedkit/cli",
1518
- "pluginName": "@speedkit/cli",
1519
- "pluginType": "core",
1520
- "strict": true,
1521
- "enableJsonFlag": false,
1522
- "isESM": true,
1523
- "relativePath": [
1524
- "dist",
1525
- "commands",
1526
- "extension",
1527
- "add.js"
1528
- ]
1529
- },
1530
- "extension:devtools": {
1531
- "aliases": [],
1532
- "args": {},
1533
- "description": "Install the integration-devtools extension for the onboarding browser, or update it to the latest release",
1534
- "examples": [
1535
- "$ sk extension devtools",
1536
- "$ sk extension devtools --force"
1537
- ],
1538
- "flags": {
1539
- "force": {
1540
- "description": "reinstall the latest release even when it is up to date",
1541
- "name": "force",
1542
- "allowNo": false,
1543
- "type": "boolean"
1544
- }
1545
- },
1546
- "hasDynamicHelp": false,
1547
- "hiddenAliases": [],
1548
- "id": "extension:devtools",
1549
- "pluginAlias": "@speedkit/cli",
1550
- "pluginName": "@speedkit/cli",
1551
- "pluginType": "core",
1552
- "strict": true,
1553
- "enableJsonFlag": false,
1554
- "isESM": true,
1555
- "relativePath": [
1556
- "dist",
1557
- "commands",
1558
- "extension",
1559
- "devtools.js"
1560
- ]
1561
- },
1562
- "extension:list": {
1563
- "aliases": [],
1564
- "args": {},
1565
- "description": "List Chrome extensions managed by the setup wizard",
1566
- "examples": [
1567
- "$ sk extension list"
1568
- ],
1569
- "flags": {},
1570
- "hasDynamicHelp": false,
1571
- "hiddenAliases": [],
1572
- "id": "extension:list",
1573
- "pluginAlias": "@speedkit/cli",
1574
- "pluginName": "@speedkit/cli",
1575
- "pluginType": "core",
1576
- "strict": true,
1577
- "enableJsonFlag": false,
1578
- "isESM": true,
1579
- "relativePath": [
1580
- "dist",
1581
- "commands",
1582
- "extension",
1583
- "list.js"
1584
- ]
1585
- },
1586
- "extension:remove": {
1587
- "aliases": [],
1588
- "args": {
1589
- "ref": {
1590
- "description": "Chrome Web Store link or extension id",
1591
- "name": "ref",
1592
- "required": false
1593
- }
1594
- },
1595
- "description": "Remove a managed Chrome extension",
1596
- "examples": [
1597
- "$ sk extension remove",
1598
- "$ sk extension remove <id>"
1599
- ],
1600
- "flags": {},
1601
- "hasDynamicHelp": false,
1602
- "hiddenAliases": [],
1603
- "id": "extension:remove",
1604
- "pluginAlias": "@speedkit/cli",
1605
- "pluginName": "@speedkit/cli",
1606
- "pluginType": "core",
1607
- "strict": true,
1608
- "enableJsonFlag": false,
1609
- "isESM": true,
1610
- "relativePath": [
1611
- "dist",
1612
- "commands",
1613
- "extension",
1614
- "remove.js"
1615
- ]
1616
- },
1617
- "extension:update": {
1618
- "aliases": [],
1619
- "args": {},
1620
- "description": "Check managed Chrome extensions for updates and install them",
1621
- "examples": [
1622
- "$ sk extension update"
1623
- ],
1624
- "flags": {},
1625
- "hasDynamicHelp": false,
1626
- "hiddenAliases": [],
1627
- "id": "extension:update",
1628
- "pluginAlias": "@speedkit/cli",
1629
- "pluginName": "@speedkit/cli",
1630
- "pluginType": "core",
1631
- "strict": true,
1632
- "enableJsonFlag": false,
1633
- "isESM": true,
1634
- "relativePath": [
1635
- "dist",
1636
- "commands",
1637
- "extension",
1638
- "update.js"
1639
- ]
1640
- },
1641
1498
  "query:parameter": {
1642
1499
  "aliases": [
1643
1500
  "build-parameter-query"
@@ -1949,6 +1806,149 @@
1949
1806
  "prewarm.js"
1950
1807
  ]
1951
1808
  },
1809
+ "extension:add": {
1810
+ "aliases": [],
1811
+ "args": {
1812
+ "ref": {
1813
+ "description": "Chrome Web Store link or extension id",
1814
+ "name": "ref",
1815
+ "required": false
1816
+ }
1817
+ },
1818
+ "description": "Install a Chrome extension into the onboarding browser by Web Store link or id",
1819
+ "examples": [
1820
+ "$ sk extension add fmkadmapgofadopljbjfkapdkoienihi",
1821
+ "$ sk extension add https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi",
1822
+ "$ sk extension add"
1823
+ ],
1824
+ "flags": {},
1825
+ "hasDynamicHelp": false,
1826
+ "hiddenAliases": [],
1827
+ "id": "extension:add",
1828
+ "pluginAlias": "@speedkit/cli",
1829
+ "pluginName": "@speedkit/cli",
1830
+ "pluginType": "core",
1831
+ "strict": true,
1832
+ "enableJsonFlag": false,
1833
+ "isESM": true,
1834
+ "relativePath": [
1835
+ "dist",
1836
+ "commands",
1837
+ "extension",
1838
+ "add.js"
1839
+ ]
1840
+ },
1841
+ "extension:devtools": {
1842
+ "aliases": [],
1843
+ "args": {},
1844
+ "description": "Install the integration-devtools extension for the onboarding browser, or update it to the latest release",
1845
+ "examples": [
1846
+ "$ sk extension devtools",
1847
+ "$ sk extension devtools --force"
1848
+ ],
1849
+ "flags": {
1850
+ "force": {
1851
+ "description": "reinstall the latest release even when it is up to date",
1852
+ "name": "force",
1853
+ "allowNo": false,
1854
+ "type": "boolean"
1855
+ }
1856
+ },
1857
+ "hasDynamicHelp": false,
1858
+ "hiddenAliases": [],
1859
+ "id": "extension:devtools",
1860
+ "pluginAlias": "@speedkit/cli",
1861
+ "pluginName": "@speedkit/cli",
1862
+ "pluginType": "core",
1863
+ "strict": true,
1864
+ "enableJsonFlag": false,
1865
+ "isESM": true,
1866
+ "relativePath": [
1867
+ "dist",
1868
+ "commands",
1869
+ "extension",
1870
+ "devtools.js"
1871
+ ]
1872
+ },
1873
+ "extension:list": {
1874
+ "aliases": [],
1875
+ "args": {},
1876
+ "description": "List Chrome extensions managed by the setup wizard",
1877
+ "examples": [
1878
+ "$ sk extension list"
1879
+ ],
1880
+ "flags": {},
1881
+ "hasDynamicHelp": false,
1882
+ "hiddenAliases": [],
1883
+ "id": "extension:list",
1884
+ "pluginAlias": "@speedkit/cli",
1885
+ "pluginName": "@speedkit/cli",
1886
+ "pluginType": "core",
1887
+ "strict": true,
1888
+ "enableJsonFlag": false,
1889
+ "isESM": true,
1890
+ "relativePath": [
1891
+ "dist",
1892
+ "commands",
1893
+ "extension",
1894
+ "list.js"
1895
+ ]
1896
+ },
1897
+ "extension:remove": {
1898
+ "aliases": [],
1899
+ "args": {
1900
+ "ref": {
1901
+ "description": "Chrome Web Store link or extension id",
1902
+ "name": "ref",
1903
+ "required": false
1904
+ }
1905
+ },
1906
+ "description": "Remove a managed Chrome extension",
1907
+ "examples": [
1908
+ "$ sk extension remove",
1909
+ "$ sk extension remove <id>"
1910
+ ],
1911
+ "flags": {},
1912
+ "hasDynamicHelp": false,
1913
+ "hiddenAliases": [],
1914
+ "id": "extension:remove",
1915
+ "pluginAlias": "@speedkit/cli",
1916
+ "pluginName": "@speedkit/cli",
1917
+ "pluginType": "core",
1918
+ "strict": true,
1919
+ "enableJsonFlag": false,
1920
+ "isESM": true,
1921
+ "relativePath": [
1922
+ "dist",
1923
+ "commands",
1924
+ "extension",
1925
+ "remove.js"
1926
+ ]
1927
+ },
1928
+ "extension:update": {
1929
+ "aliases": [],
1930
+ "args": {},
1931
+ "description": "Check managed Chrome extensions for updates and install them",
1932
+ "examples": [
1933
+ "$ sk extension update"
1934
+ ],
1935
+ "flags": {},
1936
+ "hasDynamicHelp": false,
1937
+ "hiddenAliases": [],
1938
+ "id": "extension:update",
1939
+ "pluginAlias": "@speedkit/cli",
1940
+ "pluginName": "@speedkit/cli",
1941
+ "pluginType": "core",
1942
+ "strict": true,
1943
+ "enableJsonFlag": false,
1944
+ "isESM": true,
1945
+ "relativePath": [
1946
+ "dist",
1947
+ "commands",
1948
+ "extension",
1949
+ "update.js"
1950
+ ]
1951
+ },
1952
1952
  "revalidate:jobs": {
1953
1953
  "aliases": [],
1954
1954
  "args": {
@@ -2113,5 +2113,5 @@
2113
2113
  ]
2114
2114
  }
2115
2115
  },
2116
- "version": "4.49.0"
2116
+ "version": "4.50.1"
2117
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.49.0",
4
+ "version": "4.50.1",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"