@cnc-tools/storm 0.13.0 → 0.14.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.
Files changed (136) hide show
  1. package/dist/application.js +5 -1
  2. package/dist/bin/storm.js +6 -2
  3. package/dist/build-info.js +1 -1
  4. package/dist/chunks/{chunk-N7E6DAUE.js → chunk-27P2QSIM.js} +1 -1
  5. package/dist/chunks/{chunk-ZDJLKF2G.js → chunk-5ED3IDUJ.js} +7 -4
  6. package/dist/chunks/{chunk-6EQKA7LI.js → chunk-5TMHYH7G.js} +1 -1
  7. package/dist/chunks/{chunk-AX4EQZUS.js → chunk-BFLYGMG3.js} +12 -7
  8. package/dist/chunks/{chunk-LQKNI3EG.js → chunk-BRUIATTR.js} +6 -6
  9. package/dist/chunks/{chunk-DOFB2ACU.js → chunk-HOKDKP5A.js} +1 -1
  10. package/dist/chunks/{chunk-EGNP3S6C.js → chunk-IVRRGGCD.js} +60 -20
  11. package/dist/chunks/{chunk-RTILVSYQ.js → chunk-QBR5VHJ7.js} +1 -1
  12. package/dist/chunks/{chunk-YT5OROR7.js → chunk-RA4L2ACU.js} +12 -2
  13. package/dist/chunks/{chunk-YGS5VRQT.js → chunk-RKONDLPS.js} +8 -5
  14. package/dist/chunks/{chunk-IYM44FUX.js → chunk-UC6DULWY.js} +2 -2
  15. package/dist/chunks/{chunk-2NZXL6OH.js → chunk-XPCUINWS.js} +1 -1
  16. package/dist/chunks/{chunk-Q4TKRILH.js → chunk-YBPTMJUM.js} +98 -21
  17. package/dist/chunks/{chunk-5UMJNVKT.js → chunk-Z5OXOZD3.js} +125 -83
  18. package/dist/chunks/{chunk-X4WBJIOF.js → chunk-ZH5R7W4A.js} +1 -1
  19. package/dist/chunks/{live-app-QFHS54SX.js → live-app-FBVWUUMT.js} +7 -7
  20. package/dist/commands/exec/command.d.ts +2 -0
  21. package/dist/commands/exec/command.js +15 -41
  22. package/dist/commands/exec/define-run-command.d.ts +17 -10
  23. package/dist/commands/exec/define-run-command.js +48 -15
  24. package/dist/commands/exec/driver-plan.d.ts +24 -16
  25. package/dist/commands/exec/driver-plan.js +34 -15
  26. package/dist/commands/exec/driver-refusals.js +7 -6
  27. package/dist/commands/exec/exec-words.d.ts +1 -1
  28. package/dist/commands/exec/exec-words.js +8 -2
  29. package/dist/commands/exec/final-results.d.ts +39 -0
  30. package/dist/commands/exec/final-results.js +29 -0
  31. package/dist/commands/exec/metadata.js +1 -1
  32. package/dist/commands/exec/outcomes.d.ts +13 -3
  33. package/dist/commands/exec/outcomes.js +21 -4
  34. package/dist/commands/exec/plan-run.d.ts +11 -3
  35. package/dist/commands/exec/plan-run.js +3 -2
  36. package/dist/commands/exec/run-command.d.ts +1 -1
  37. package/dist/commands/exec/run-command.js +27 -5
  38. package/dist/commands/exec/test-plan.d.ts +2 -1
  39. package/dist/commands/exec/test-plan.js +13 -4
  40. package/dist/commands/exec/tests-summary.d.ts +2 -2
  41. package/dist/commands/exec/worker-chart.d.ts +1 -1
  42. package/dist/commands/playwright/command.d.ts +10 -7
  43. package/dist/commands/playwright/command.js +14 -14
  44. package/dist/commands/playwright/metadata.js +2 -2
  45. package/dist/commands/runs/list/command.js +6 -6
  46. package/dist/commands/runs/logs/command.js +6 -6
  47. package/dist/commands/runs/show/command.d.ts +2 -2
  48. package/dist/commands/runs/show/command.js +11 -11
  49. package/dist/commands/runs/show/outcomes.d.ts +1 -1
  50. package/dist/commands/snapshots/build/command.js +12 -12
  51. package/dist/commands/snapshots/list/command.js +9 -9
  52. package/dist/commands/vitest/command.d.ts +12 -8
  53. package/dist/commands/vitest/command.js +14 -14
  54. package/dist/commands/vitest/metadata.js +2 -2
  55. package/dist/config/resolve.d.ts +1 -1
  56. package/dist/config/resolve.js +2 -1
  57. package/dist/config/schema.d.ts +8 -0
  58. package/dist/config/schema.js +5 -4
  59. package/dist/extensions/playwright/driver.js +17 -10
  60. package/dist/extensions/testserver/commands/pool/create/command.js +4 -4
  61. package/dist/extensions/testserver/commands/pool/list/command.js +2 -2
  62. package/dist/extensions/testserver/definition.d.ts +1 -1
  63. package/dist/extensions/testserver/extension.d.ts +1 -1
  64. package/dist/extensions/testserver/options/rules.d.ts +3 -3
  65. package/dist/extensions/testserver/options/rules.js +5 -5
  66. package/dist/extensions/testserver/resource.d.ts +1 -1
  67. package/dist/extensions/testserver/vercel-cli/arguments.d.ts +10 -4
  68. package/dist/extensions/testserver/vercel-cli/arguments.js +17 -6
  69. package/dist/extensions/testserver/vercel-cli/environment.d.ts +12 -1
  70. package/dist/extensions/testserver/vercel-cli/environment.js +35 -5
  71. package/dist/extensions/testserver/vercel-cli/index.d.ts +1 -0
  72. package/dist/extensions/testserver/vercel-cli/index.js +1 -0
  73. package/dist/extensions/testserver/vercel-cli/invoker.d.ts +28 -13
  74. package/dist/extensions/testserver/vercel-cli/invoker.js +81 -67
  75. package/dist/extensions/testserver/vercel-cli/live/process-gateway.js +4 -10
  76. package/dist/extensions/testserver/vercel-cli/report.js +5 -2
  77. package/dist/extensions/testserver/vercel-cli/session-id.d.ts +8 -0
  78. package/dist/extensions/testserver/vercel-cli/session-id.js +17 -0
  79. package/dist/extensions/testserver/vitest/config.d.ts +2 -2
  80. package/dist/extensions/testserver/vitest/config.js +2 -2
  81. package/dist/extensions/testserver/vitest/container-scope.d.ts +25 -16
  82. package/dist/extensions/testserver/vitest/container-scope.js +32 -13
  83. package/dist/extensions/testserver/vitest/diagnostics.d.ts +14 -12
  84. package/dist/extensions/testserver/vitest/diagnostics.js +29 -21
  85. package/dist/extensions/testserver/vitest/fixtures.d.ts +14 -1
  86. package/dist/extensions/testserver/vitest/fixtures.js +41 -12
  87. package/dist/extensions/testserver/vitest/types.d.ts +16 -0
  88. package/dist/extensions/vitest/driver.js +28 -14
  89. package/dist/extensions/vitest/plan/gateways.d.ts +28 -5
  90. package/dist/extensions/vitest/plan/gateways.js +2 -2
  91. package/dist/extensions/vitest/plan/list-output.d.ts +5 -0
  92. package/dist/extensions/vitest/plan/list-output.js +23 -9
  93. package/dist/extensions/vitest/plan/live/list-gateway.d.ts +3 -2
  94. package/dist/extensions/vitest/plan/live/list-gateway.js +77 -64
  95. package/dist/extensions/vitest/plan/plan-over.d.ts +19 -7
  96. package/dist/extensions/vitest/plan/plan-over.js +18 -7
  97. package/dist/extensions/vitest/plan/plan.d.ts +14 -5
  98. package/dist/extensions/vitest/plan/plan.js +23 -9
  99. package/dist/extensions.d.ts +2 -2
  100. package/dist/run-directory/plan.d.ts +3 -2
  101. package/dist/run-directory/plan.js +6 -3
  102. package/dist/run-directory/run-record.d.ts +4 -3
  103. package/dist/runner/recipe.d.ts +5 -1
  104. package/dist/runner/sandboxed-command.d.ts +5 -3
  105. package/dist/runner/sandboxed-command.js +10 -4
  106. package/dist/sdk/extension/driver.d.ts +32 -6
  107. package/dist/sdk/extension/driver.js +12 -2
  108. package/dist/sdk/extension/index.d.ts +1 -1
  109. package/dist/sdk/extension/index.js +2 -1
  110. package/dist/sdk/extension/resource-definition.d.ts +6 -5
  111. package/dist/vendor/testserver-sdk/container/api-request.d.ts +2 -3
  112. package/dist/vendor/testserver-sdk/container/api-request.js +2 -3
  113. package/dist/vendor/testserver-sdk/container/container.d.ts +12 -2
  114. package/dist/vendor/testserver-sdk/container/container.js +10 -7
  115. package/dist/vendor/testserver-sdk/container/recorder.d.ts +29 -7
  116. package/dist/vendor/testserver-sdk/container/recorder.js +26 -14
  117. package/dist/vendor/testserver-sdk/index.d.ts +1 -1
  118. package/dist/vendor/testserver-sdk/index.js +1 -1
  119. package/dist/vendor/testserver-sdk/proxy/exchange.d.ts +24 -5
  120. package/dist/vendor/testserver-sdk/proxy/exchange.js +43 -25
  121. package/dist/vendor/testserver-sdk/proxy/faulted-exchange.js +15 -10
  122. package/dist/vendor/testserver-sdk/proxy/faults.d.ts +6 -5
  123. package/dist/vendor/testserver-sdk/proxy/proxy.d.ts +10 -1
  124. package/dist/vendor/testserver-sdk/proxy/proxy.js +5 -3
  125. package/dist/vendor/testserver-sdk/proxy/records.d.ts +17 -17
  126. package/dist/vendor/testserver-sdk/proxy/records.js +18 -17
  127. package/dist/vendor/testserver-sdk/records/body.d.ts +7 -9
  128. package/dist/vendor/testserver-sdk/records/body.js +10 -15
  129. package/dist/vendor/testserver-sdk/records/headers.d.ts +79 -0
  130. package/dist/vendor/testserver-sdk/records/headers.js +162 -0
  131. package/dist/vendor/testserver-sdk/records/index.d.ts +2 -1
  132. package/dist/vendor/testserver-sdk/records/index.js +4 -2
  133. package/dist/vendor/testserver-sdk/records/records.d.ts +19 -10
  134. package/package.json +5 -4
  135. package/skills/overview.md +5 -5
  136. package/skills/testserver-builds.md +0 -82
@@ -1,4 +1,4 @@
1
- import type { RecordedBody, RequestOutcome } from "../records/index.ts";
1
+ import type { RequestOutcome } from "../records/index.ts";
2
2
  /**
3
3
  * The response a `respond` or `replace` fault rule sends the client in place of Testserver's. The proxy adds no
4
4
  * error format of its own, so a fake error body must match the real service's error format.
@@ -79,10 +79,11 @@ export interface ProxyFault {
79
79
  */
80
80
  readonly upstream?: FaultUpstream;
81
81
  }
82
- /** Testserver's answer under a forwarding fault: `RequestOutcome`'s shape, plus the body, recorded as usual. */
83
- export type FaultUpstream = RequestOutcome & {
84
- readonly responseBody?: RecordedBody;
85
- };
82
+ /**
83
+ * Testserver's answer under a forwarding fault, recorded as usual: beside a `status`, its headers (Testserver's less
84
+ * hop-by-hop headers) and body.
85
+ */
86
+ export type FaultUpstream = RequestOutcome;
86
87
  /** A rule checked by `checkRule`, its method upper-cased, its template split and its response serialized once. */
87
88
  export type CheckedRule = {
88
89
  readonly method: string;
@@ -21,6 +21,14 @@ export interface ProxyOptions {
21
21
  * What it throws is dropped: it never touches the exchange.
22
22
  */
23
23
  readonly onRequest?: (record: ProxyRequestRecord) => void;
24
+ /**
25
+ * The headers whose values its records show as sent, in requests and responses, besides `DEFAULT_RECORD_HEADERS`
26
+ * (such as `content-type`), which it adds to: such as `["dpop"]`; names are compared without regard to case. Every
27
+ * other header's value reads `<redacted>` (`REDACTED_HEADER`),
28
+ * but `authorization` and `proxy-authorization`, which show their scheme, and `cookie` and `set-cookie`, which show
29
+ * each cookie's name; those four can't be listed. A record always holds each header's name. By default none beyond the defaults.
30
+ */
31
+ readonly recordHeaders?: readonly string[];
24
32
  }
25
33
  /** A running proxy: a local server that adds a container's test id for clients that can't. */
26
34
  export interface ContainerProxy {
@@ -86,7 +94,8 @@ export interface ContainerProxy {
86
94
  * Starts a proxy that forwards each request to the container's Testserver URL with its test id added, unless a
87
95
  * fault rule (`proxy.fault`) changes what the client gets for it. Method, path, query, headers and body pass
88
96
  * through, `host` becomes Testserver's, and bodies stream both ways undecoded, while the proxy keeps a decoded,
89
- * redacted copy of each for its record. A request Testserver can't be reached for gets a 502.
97
+ * redacted copy of each for its record. A request Testserver can't be reached for gets a 502. Throws a `TypeError`
98
+ * for a bad `recordHeaders`, before it listens.
90
99
  */
91
100
  export declare function startProxy(options: ProxyOptions): Promise<ContainerProxy>;
92
101
  /** Starts a proxy, runs `body` with it, and closes it however `body` finishes. */
@@ -1,6 +1,6 @@
1
1
  import { Agent, createServer, request as httpRequest, } from "node:http";
2
2
  import { Agent as HttpsAgent, request as httpsRequest } from "node:https";
3
- import { splitTarget } from "../records/index.js";
3
+ import { checkRecordHeaders, splitTarget } from "../records/index.js";
4
4
  import { systemClock, TEST_ID_HEADER } from "../testserver/index.js";
5
5
  import { Exchange, passThrough } from "./exchange.js";
6
6
  import { applyFault } from "./faulted-exchange.js";
@@ -10,9 +10,11 @@ import { upstreamHeaders } from "./records.js";
10
10
  * Starts a proxy that forwards each request to the container's Testserver URL with its test id added, unless a
11
11
  * fault rule (`proxy.fault`) changes what the client gets for it. Method, path, query, headers and body pass
12
12
  * through, `host` becomes Testserver's, and bodies stream both ways undecoded, while the proxy keeps a decoded,
13
- * redacted copy of each for its record. A request Testserver can't be reached for gets a 502.
13
+ * redacted copy of each for its record. A request Testserver can't be reached for gets a 502. Throws a `TypeError`
14
+ * for a bad `recordHeaders`, before it listens.
14
15
  */
15
16
  export async function startProxy(options) {
17
+ const recordHeaders = checkRecordHeaders(options.recordHeaders);
16
18
  const upstream = new URL(options.container.testserverUrl);
17
19
  const secure = upstream.protocol === "https:";
18
20
  if (!secure && upstream.protocol !== "http:") {
@@ -37,7 +39,7 @@ export async function startProxy(options) {
37
39
  }),
38
40
  agent,
39
41
  }, onAnswer);
40
- const deps = { now: () => systemClock.now(), send, onRequest: options.onRequest };
42
+ const deps = { now: () => systemClock.now(), send, onRequest: options.onRequest, recordHeaders };
41
43
  const server = createServer((request, response) => {
42
44
  // Matched once, as the headers arrive: a rule added later never applies to this request.
43
45
  const rule = faults.take(request.method ?? "GET", splitTarget(request.url ?? "/").path);
@@ -1,14 +1,14 @@
1
1
  import type { IncomingHttpHeaders } from "node:http";
2
- import { type RecordedBody, type RequestOutcome, type RequestRecordFields } from "../records/index.ts";
2
+ import { type RecordedBody, type RecordedHeaders, type RequestOutcome, type RequestRecordFields } from "../records/index.ts";
3
3
  import type { ProxyFault } from "./faults.ts";
4
- /** The header the `vercel` CLI sends with the same id on every request of one invocation. */
5
- export declare const SESSION_ID_HEADER = "x-vercel-cli-session-id";
6
4
  /**
7
5
  * The outcome of a proxy record whose exchange was still open when `proxy.requests` was read: no `status` or
8
- * `error`, no `responseBody`, and a `durationMs` that runs to the read.
6
+ * `error`, no `responseHeaders` or `responseBody`, and a `durationMs` that runs to the read.
9
7
  */
10
8
  export type OpenRequestOutcome = {
11
9
  readonly open: true;
10
+ readonly responseHeaders?: never;
11
+ readonly responseBody?: never;
12
12
  };
13
13
  /** How a proxied exchange stands: ended as `RequestOutcome` says, or still open. */
14
14
  export type ProxyRequestOutcome = RequestOutcome | OpenRequestOutcome;
@@ -18,13 +18,12 @@ export type ProxyRequestOutcome = RequestOutcome | OpenRequestOutcome;
18
18
  * as the client sent it, `startedAt` is the proxy clock's reading at its arrival, `durationMs` runs from its arrival
19
19
  * to the exchange's end (or, for an open record, to the read), a fault rule's delay included, and `error` without a
20
20
  * `status` means no answer reached the client. An `error` beside a `status` says the answer broke off, or, with a
21
- * `failure`, that it was Testserver's 503 for a stopped container (`answeredOutcome`). No token reaches a record
22
- * (`records/body.ts`).
21
+ * `failure`, that it was Testserver's 503 for a stopped container (`answeredOutcome`). `requestHeaders` are the
22
+ * client's as it sent them, before the proxy sets `host` and adds the test id; `responseHeaders` are those the client
23
+ * got with the answer, Testserver's or a fault rule's, less the hop-by-hop headers the proxy never forwards. No token
24
+ * reaches a record (`records/body.ts`, `records/headers.ts`).
23
25
  */
24
26
  export type ProxyRequestRecord = RequestRecordFields & {
25
- readonly userAgent?: string;
26
- /** The `vercel` CLI's `x-vercel-cli-session-id`, the same for every request of one invocation. */
27
- readonly sessionId?: string;
28
27
  /**
29
28
  * The fault rule the request matched, if any: its action, and what Testserver answered when the proxy forwarded
30
29
  * it. Then `status`, `error` and `responseBody` say what the client got.
@@ -33,25 +32,26 @@ export type ProxyRequestRecord = RequestRecordFields & {
33
32
  } & ProxyRequestOutcome;
34
33
  /** Whether `record`'s exchange was still open when it was read. */
35
34
  export declare function isOpenRecord(record: ProxyRequestRecord): record is ProxyRequestRecord & OpenRequestOutcome;
36
- /** The record of a request with `method`, `target` and `headers` whose exchange stands as `outcome`. */
35
+ /** The record of a request with `method`, `target` and `requestHeaders` whose exchange stands as `outcome`. */
37
36
  export declare function proxyRecord(request: {
38
37
  readonly method: string;
39
38
  readonly target: string;
40
- readonly headers: IncomingHttpHeaders;
39
+ readonly requestHeaders: RecordedHeaders;
41
40
  readonly startedAt: number;
42
41
  readonly durationMs: number;
43
42
  readonly outcome: ProxyRequestOutcome;
44
43
  readonly requestBody?: RecordedBody | undefined;
45
- readonly responseBody?: RecordedBody | undefined;
46
44
  readonly fault?: ProxyFault | undefined;
47
45
  }): ProxyRequestRecord;
48
46
  /**
49
- * How an exchange whose answer from Testserver, with `status` and `responseBody`, arrived whole ended: with `status`
50
- * alone, or, for Testserver's 503 for a stopped container (`httpFailure`), with its `container-stopped` failure and
51
- * that failure's description as `error`, since the container the request was for had stopped, as when Testserver
52
- * evicted it.
47
+ * How an exchange whose answer from Testserver, with `status`, `responseHeaders` and `responseBody`, arrived whole
48
+ * ended: with that answer alone, or, for Testserver's 503 for a stopped container (`httpFailure`), with its
49
+ * `container-stopped` failure and that failure's description as `error`, since the container the request was for had
50
+ * stopped, as when Testserver evicted it.
53
51
  */
54
- export declare function answeredOutcome(status: number, responseBody: RecordedBody | undefined): RequestOutcome;
52
+ export declare function answeredOutcome(status: number, responseHeaders: RecordedHeaders, responseBody: RecordedBody | undefined): RequestOutcome;
53
+ /** Node's `rawHeaders`, a flat list of names and values, as name and value pairs. */
54
+ export declare function rawHeaderPairs(raw: readonly string[]): [string, string][];
55
55
  /**
56
56
  * The headers to send upstream: the client's, less hop-by-hop headers, with `host` set to Testserver's and the
57
57
  * test id header set to `testId`, replacing any the client sent.
@@ -1,24 +1,17 @@
1
- import { headerText, splitTarget, } from "../records/index.js";
1
+ import { splitTarget, } from "../records/index.js";
2
2
  import { BODY_EXCERPT_CHARS, describeFailure, httpFailure } from "../testserver/index.js";
3
- /** The header the `vercel` CLI sends with the same id on every request of one invocation. */
4
- export const SESSION_ID_HEADER = "x-vercel-cli-session-id";
5
3
  /** Whether `record`'s exchange was still open when it was read. */
6
4
  export function isOpenRecord(record) {
7
5
  return "open" in record;
8
6
  }
9
- /** The record of a request with `method`, `target` and `headers` whose exchange stands as `outcome`. */
7
+ /** The record of a request with `method`, `target` and `requestHeaders` whose exchange stands as `outcome`. */
10
8
  export function proxyRecord(request) {
11
- const userAgent = headerText(request.headers["user-agent"]);
12
- const sessionId = headerText(request.headers[SESSION_ID_HEADER]);
13
9
  return {
14
10
  method: request.method,
15
11
  url: request.target,
16
12
  ...splitTarget(request.target),
17
- authorization: request.headers.authorization !== undefined,
18
- ...(userAgent === undefined ? {} : { userAgent }),
19
- ...(sessionId === undefined ? {} : { sessionId }),
13
+ requestHeaders: request.requestHeaders,
20
14
  ...(request.requestBody === undefined ? {} : { requestBody: request.requestBody }),
21
- ...(request.responseBody === undefined ? {} : { responseBody: request.responseBody }),
22
15
  ...(request.fault === undefined ? {} : { fault: request.fault }),
23
16
  startedAt: request.startedAt,
24
17
  durationMs: request.durationMs,
@@ -26,16 +19,17 @@ export function proxyRecord(request) {
26
19
  };
27
20
  }
28
21
  /**
29
- * How an exchange whose answer from Testserver, with `status` and `responseBody`, arrived whole ended: with `status`
30
- * alone, or, for Testserver's 503 for a stopped container (`httpFailure`), with its `container-stopped` failure and
31
- * that failure's description as `error`, since the container the request was for had stopped, as when Testserver
32
- * evicted it.
22
+ * How an exchange whose answer from Testserver, with `status`, `responseHeaders` and `responseBody`, arrived whole
23
+ * ended: with that answer alone, or, for Testserver's 503 for a stopped container (`httpFailure`), with its
24
+ * `container-stopped` failure and that failure's description as `error`, since the container the request was for had
25
+ * stopped, as when Testserver evicted it.
33
26
  */
34
- export function answeredOutcome(status, responseBody) {
27
+ export function answeredOutcome(status, responseHeaders, responseBody) {
28
+ const answer = { status, responseHeaders, ...(responseBody === undefined ? {} : { responseBody }) };
35
29
  if (status !== 503 || responseBody?.kind !== "text")
36
- return { status };
30
+ return answer;
37
31
  const failure = httpFailure(status, responseBody.text.slice(0, BODY_EXCERPT_CHARS));
38
- return failure.kind === "container-stopped" ? { status, error: describeFailure(failure), failure } : { status };
32
+ return failure.kind === "container-stopped" ? { ...answer, error: describeFailure(failure), failure } : answer;
39
33
  }
40
34
  /** Headers that describe one connection, not the message, so the proxy never forwards them. */
41
35
  const HOP_BY_HOP = new Set([
@@ -48,6 +42,13 @@ const HOP_BY_HOP = new Set([
48
42
  "trailer",
49
43
  "upgrade",
50
44
  ]);
45
+ /** Node's `rawHeaders`, a flat list of names and values, as name and value pairs. */
46
+ export function rawHeaderPairs(raw) {
47
+ const pairs = [];
48
+ for (let at = 0; at + 1 < raw.length; at += 2)
49
+ pairs.push([raw[at] ?? "", raw[at + 1] ?? ""]);
50
+ return pairs;
51
+ }
51
52
  /**
52
53
  * The headers to send upstream: the client's, less hop-by-hop headers, with `host` set to Testserver's and the
53
54
  * test id header set to `testId`, replacing any the client sent.
@@ -39,28 +39,28 @@ export declare class BodyCapture {
39
39
  #private;
40
40
  push(chunk: Uint8Array): void;
41
41
  /** The whole body, decoded by `headers`; `undefined` when it was empty. */
42
- complete(headers: IncomingHttpHeaders, bearer: string | undefined): RecordedBody | undefined;
42
+ complete(headers: IncomingHttpHeaders, credentials: string | undefined): RecordedBody | undefined;
43
43
  /** A body that broke off partway; `undefined` when none of it arrived. */
44
44
  incomplete(headers: IncomingHttpHeaders): RecordedBody | undefined;
45
45
  }
46
46
  /**
47
- * A request or response body as a record keeps it: decoded by `headers`, capped, and redacted with the request's own
48
- * bearer token. The body was `bytes` bytes long, and `kept` holds all of it unless it was over
47
+ * A request or response body as a record keeps it: decoded by `headers`, capped, and redacted with the credentials of
48
+ * the request's own `authorization` header. The body was `bytes` bytes long, and `kept` holds all of it unless it was over
49
49
  * `RECORDED_BODY_CAP_BYTES`, when it is ignored. `undefined` for an empty body. The proxy's `BodyCapture` and an API
50
50
  * request's whole body both come through here.
51
51
  */
52
- export declare function recordedBody(kept: Uint8Array, bytes: number, headers: IncomingHttpHeaders, bearer: string | undefined): RecordedBody | undefined;
52
+ export declare function recordedBody(kept: Uint8Array, bytes: number, headers: IncomingHttpHeaders, credentials: string | undefined): RecordedBody | undefined;
53
53
  /**
54
54
  * The record of a body of `bytes` bytes sent with `headers`. `raw` is the body as sent, or `undefined` when it was
55
55
  * over the cap. Decompresses gzip, deflate and br, then decodes by `content-type`.
56
56
  */
57
57
  export declare function decodeBody(raw: Uint8Array | undefined, bytes: number, headers: IncomingHttpHeaders): RecordedBody;
58
58
  /**
59
- * `body` with every token field's string value, directly or inside arrays, replaced by `<token>`, and `bearer`, the
60
- * request's own bearer token, replaced wherever it appears. An object under a token field is redacted like any
59
+ * `body` with every token field's string value, directly or inside arrays, replaced by `<token>`, and `credentials`,
60
+ * those of the request's own `authorization` header, whatever its scheme, replaced wherever they appear. An object under a token field is redacted like any
61
61
  * other. Expects a body from `decodeBody`, whose JSON nesting is bounded; `recordedBody` composes the two.
62
62
  */
63
- export declare function redactBody(body: RecordedBody, bearer: string | undefined): RecordedBody;
63
+ export declare function redactBody(body: RecordedBody, credentials: string | undefined): RecordedBody;
64
64
  /**
65
65
  * `value` with every token field's string value, directly or inside arrays, replaced by `<token>`, as a JSON body's
66
66
  * are in a record. An object under a token field is redacted like any other. For printing a value no record holds,
@@ -77,8 +77,6 @@ export declare function tokenSecrets(value: unknown): Set<string>;
77
77
  * another is replaced whole. An empty secret is skipped. A container's `redact` and the Vercel CLI invoker's use it.
78
78
  */
79
79
  export declare function redactSecrets(text: string, secrets: Iterable<string>): string;
80
- /** The bearer token in an `authorization` header, such as `Bearer abc`, or `undefined`. */
81
- export declare function bearerToken(authorization: string | undefined): string | undefined;
82
80
  /**
83
81
  * Parsed search params; a key given more than once maps to every value, in order. Collects into a `Map` so a key
84
82
  * such as `__proto__` becomes a plain own property.
@@ -35,8 +35,8 @@ export class BodyCapture {
35
35
  this.#chunks.push(chunk);
36
36
  }
37
37
  /** The whole body, decoded by `headers`; `undefined` when it was empty. */
38
- complete(headers, bearer) {
39
- return recordedBody(Buffer.concat(this.#chunks), this.#bytes, headers, bearer);
38
+ complete(headers, credentials) {
39
+ return recordedBody(Buffer.concat(this.#chunks), this.#bytes, headers, credentials);
40
40
  }
41
41
  /** A body that broke off partway; `undefined` when none of it arrived. */
42
42
  incomplete(headers) {
@@ -46,16 +46,16 @@ export class BodyCapture {
46
46
  }
47
47
  }
48
48
  /**
49
- * A request or response body as a record keeps it: decoded by `headers`, capped, and redacted with the request's own
50
- * bearer token. The body was `bytes` bytes long, and `kept` holds all of it unless it was over
49
+ * A request or response body as a record keeps it: decoded by `headers`, capped, and redacted with the credentials of
50
+ * the request's own `authorization` header. The body was `bytes` bytes long, and `kept` holds all of it unless it was over
51
51
  * `RECORDED_BODY_CAP_BYTES`, when it is ignored. `undefined` for an empty body. The proxy's `BodyCapture` and an API
52
52
  * request's whole body both come through here.
53
53
  */
54
- export function recordedBody(kept, bytes, headers, bearer) {
54
+ export function recordedBody(kept, bytes, headers, credentials) {
55
55
  if (bytes === 0)
56
56
  return undefined;
57
57
  const raw = bytes > RECORDED_BODY_CAP_BYTES ? undefined : kept;
58
- return redactBody(decodeBody(raw, bytes, headers), bearer);
58
+ return redactBody(decodeBody(raw, bytes, headers), credentials);
59
59
  }
60
60
  /**
61
61
  * The record of a body of `bytes` bytes sent with `headers`. `raw` is the body as sent, or `undefined` when it was
@@ -92,12 +92,12 @@ export function decodeBody(raw, bytes, headers) {
92
92
  return omitted("binary", bytes, headers);
93
93
  }
94
94
  /**
95
- * `body` with every token field's string value, directly or inside arrays, replaced by `<token>`, and `bearer`, the
96
- * request's own bearer token, replaced wherever it appears. An object under a token field is redacted like any
95
+ * `body` with every token field's string value, directly or inside arrays, replaced by `<token>`, and `credentials`,
96
+ * those of the request's own `authorization` header, whatever its scheme, replaced wherever they appear. An object under a token field is redacted like any
97
97
  * other. Expects a body from `decodeBody`, whose JSON nesting is bounded; `recordedBody` composes the two.
98
98
  */
99
- export function redactBody(body, bearer) {
100
- const scrub = (text) => (bearer === undefined ? text : redactSecrets(text, [bearer]));
99
+ export function redactBody(body, credentials) {
100
+ const scrub = (text) => (credentials === undefined ? text : redactSecrets(text, [credentials]));
101
101
  switch (body.kind) {
102
102
  case "json":
103
103
  return { kind: "json", value: redactValue(body.value, scrub) };
@@ -183,11 +183,6 @@ function redactFields(fields, scrub) {
183
183
  }
184
184
  return Object.fromEntries(redacted);
185
185
  }
186
- /** The bearer token in an `authorization` header, such as `Bearer abc`, or `undefined`. */
187
- export function bearerToken(authorization) {
188
- const match = /^\s*bearer\s+(\S+)\s*$/i.exec(authorization ?? "");
189
- return match?.[1];
190
- }
191
186
  /**
192
187
  * Parsed search params; a key given more than once maps to every value, in order. Collects into a `Map` so a key
193
188
  * such as `__proto__` becomes a plain own property.
@@ -0,0 +1,79 @@
1
+ /** An `authorization` header's value, split into its scheme and its credentials. */
2
+ export interface Authorization {
3
+ /** The scheme as sent, such as `Bearer` or `DPoP`; absent for a value that is one word. */
4
+ readonly scheme?: string;
5
+ /** Everything after the scheme, trimmed: the secret a record must not hold. */
6
+ readonly credentials: string;
7
+ }
8
+ /**
9
+ * An `authorization` header's value read as any scheme and its credentials: `DPoP abc` is the scheme `DPoP` and
10
+ * the credentials `abc`. A value with no scheme, one word such as `abc`, is all credentials. `undefined` for an
11
+ * absent or blank value.
12
+ */
13
+ export declare function parseAuthorization(value: string | undefined): Authorization | undefined;
14
+ /**
15
+ * The fewest characters a request's `authorization` credentials must have for a record to search for them and
16
+ * replace them in its bodies and shown headers, and for a container to learn them. A shorter value, such as `a`,
17
+ * would replace every `a` in the record, and no real token is that short. The `authorization` header itself always
18
+ * hides its credentials, whatever their length.
19
+ */
20
+ export declare const MIN_CREDENTIAL_CHARS = 8;
21
+ /**
22
+ * The secret a record replaces wherever it appears: the credentials of an `authorization` header's value, whatever
23
+ * its scheme, or `undefined` when there are none or they are shorter than `MIN_CREDENTIAL_CHARS`.
24
+ */
25
+ export declare function authorizationSecret(value: string | undefined): string | undefined;
26
+ /**
27
+ * What a record holds in place of the value of a header no rule shows, `DEFAULT_RECORD_HEADERS` doesn't hold, and no
28
+ * `recordHeaders` list names.
29
+ */
30
+ export declare const REDACTED_HEADER = "<redacted>";
31
+ /**
32
+ * A request's or an answer's headers as a record keeps them (`recordedHeaders`): names lowercased, in the order each
33
+ * name first came, each value hidden unless a rule, `DEFAULT_RECORD_HEADERS` or the record's `recordHeaders` list
34
+ * shows it. A shown header sent
35
+ * more than once is one string: its values joined with `, `, as HTTP combines a repeated field, but `cookie`, joined
36
+ * with `; ` as a client sends its cookies, and `set-cookie`, joined with a line feed, since a cookie's own value or
37
+ * attributes can hold `, ` but no header value holds a line break. Split `set-cookie` on `\n` to read each cookie. A
38
+ * hidden header reads `<redacted>` once, however many times it was sent.
39
+ */
40
+ export type RecordedHeaders = Readonly<Record<string, string>>;
41
+ /** Headers as `recordedHeaders` takes them: name and value pairs, a value given as a list once per value. */
42
+ export type HeaderEntries = Iterable<readonly [string, string | readonly string[] | undefined]>;
43
+ /** How `recordedHeaders` redacts: the request's own secret, and the headers whose values are shown as sent. */
44
+ export interface HeaderRedaction {
45
+ /** The request's `authorization` credentials (`authorizationSecret`), replaced in every shown value. */
46
+ readonly secret: string | undefined;
47
+ /** The lowercased names whose values are shown as sent (`checkRecordHeaders`). */
48
+ readonly shown: ReadonlySet<string>;
49
+ }
50
+ /**
51
+ * The headers every record shows as sent, whatever its `recordHeaders` list: standard HTTP headers that describe the
52
+ * message or the connection, never the user or a resource, and whose values never hold a credential or a code.
53
+ * `location` is not one, since a redirect can carry a code or a token in its query, nor is any header of one
54
+ * product or protocol, such as `www-authenticate` or `dpop`: a consumer lists those itself.
55
+ */
56
+ export declare const DEFAULT_RECORD_HEADERS: readonly string[];
57
+ /**
58
+ * `names`, a `recordHeaders` option, as the set `recordedHeaders` shows: `DEFAULT_RECORD_HEADERS` and each of
59
+ * `names`, lowercased. A list adds to the defaults; nothing turns them off. Throws a `TypeError`
60
+ * for a list that isn't an array, a name that isn't a valid header name, and `authorization`, `proxy-authorization`,
61
+ * `cookie` or `set-cookie`, whose values a record never shows whole.
62
+ */
63
+ export declare function checkRecordHeaders(names: readonly string[] | undefined): ReadonlySet<string>;
64
+ /**
65
+ * The canonical key of `names`, a `recordHeaders` option: the JSON of the names `checkRecordHeaders` shows, sorted,
66
+ * so two lists that show the same headers give the same key. `undefined`, `[]`, and `["Content-Type"]` do, since a
67
+ * list adds to the defaults, and so do `["X-Trace", "dpop"]` and `["dpop", "x-trace", "DPoP"]`. Throws
68
+ * `checkRecordHeaders`' `TypeError` for a list it refuses.
69
+ */
70
+ export declare function recordHeadersKey(names: readonly string[] | undefined): string;
71
+ /**
72
+ * `headers` as a record keeps them. Every value is hidden, reading `<redacted>`, unless a rule or `shown` shows it:
73
+ * `authorization` and `proxy-authorization` show their scheme and read `<token>` for the credentials, such as
74
+ * `DPoP <token>`, and a value with no scheme reads `<token>`; `cookie` and `set-cookie` show each cookie's name, and
75
+ * `set-cookie` its attributes, and read `<token>` for each value; and a header `shown` names is kept as sent, with
76
+ * `secret`, the request's own `authorization` credentials, replaced by `<token>` wherever it appears. A header's name
77
+ * is always recorded, so a test can tell it was sent.
78
+ */
79
+ export declare function recordedHeaders(headers: HeaderEntries, redaction: HeaderRedaction): RecordedHeaders;
@@ -0,0 +1,162 @@
1
+ import { validateHeaderName } from "node:http";
2
+ import { REDACTED, redactSecrets } from "./body.js";
3
+ /** An auth scheme is an HTTP token (RFC 9110, section 11.1). */
4
+ const SCHEME_AND_CREDENTIALS = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+)\s+(\S[\s\S]*)$/;
5
+ /**
6
+ * An `authorization` header's value read as any scheme and its credentials: `DPoP abc` is the scheme `DPoP` and
7
+ * the credentials `abc`. A value with no scheme, one word such as `abc`, is all credentials. `undefined` for an
8
+ * absent or blank value.
9
+ */
10
+ export function parseAuthorization(value) {
11
+ const trimmed = (value ?? "").trim();
12
+ if (trimmed === "")
13
+ return undefined;
14
+ const match = SCHEME_AND_CREDENTIALS.exec(trimmed);
15
+ const scheme = match?.[1];
16
+ const credentials = match?.[2];
17
+ if (scheme === undefined || credentials === undefined)
18
+ return { credentials: trimmed };
19
+ return { scheme, credentials };
20
+ }
21
+ /**
22
+ * The fewest characters a request's `authorization` credentials must have for a record to search for them and
23
+ * replace them in its bodies and shown headers, and for a container to learn them. A shorter value, such as `a`,
24
+ * would replace every `a` in the record, and no real token is that short. The `authorization` header itself always
25
+ * hides its credentials, whatever their length.
26
+ */
27
+ export const MIN_CREDENTIAL_CHARS = 8;
28
+ /**
29
+ * The secret a record replaces wherever it appears: the credentials of an `authorization` header's value, whatever
30
+ * its scheme, or `undefined` when there are none or they are shorter than `MIN_CREDENTIAL_CHARS`.
31
+ */
32
+ export function authorizationSecret(value) {
33
+ const credentials = parseAuthorization(value)?.credentials;
34
+ return credentials === undefined || credentials.length < MIN_CREDENTIAL_CHARS ? undefined : credentials;
35
+ }
36
+ /**
37
+ * What a record holds in place of the value of a header no rule shows, `DEFAULT_RECORD_HEADERS` doesn't hold, and no
38
+ * `recordHeaders` list names.
39
+ */
40
+ export const REDACTED_HEADER = "<redacted>";
41
+ /**
42
+ * The headers every record shows as sent, whatever its `recordHeaders` list: standard HTTP headers that describe the
43
+ * message or the connection, never the user or a resource, and whose values never hold a credential or a code.
44
+ * `location` is not one, since a redirect can carry a code or a token in its query, nor is any header of one
45
+ * product or protocol, such as `www-authenticate` or `dpop`: a consumer lists those itself.
46
+ */
47
+ export const DEFAULT_RECORD_HEADERS = [
48
+ "content-type",
49
+ "content-length",
50
+ "content-encoding",
51
+ "transfer-encoding",
52
+ "accept",
53
+ "accept-encoding",
54
+ "user-agent",
55
+ "date",
56
+ "cache-control",
57
+ "retry-after",
58
+ ];
59
+ /** Headers whose credentials are always hidden, their scheme shown. */
60
+ const AUTHORIZATION_HEADERS = new Set(["authorization", "proxy-authorization"]);
61
+ /** Headers whose cookie values are always hidden, their names (and `set-cookie`'s attributes) shown. */
62
+ const COOKIE_HEADERS = new Set(["cookie", "set-cookie"]);
63
+ /**
64
+ * `names`, a `recordHeaders` option, as the set `recordedHeaders` shows: `DEFAULT_RECORD_HEADERS` and each of
65
+ * `names`, lowercased. A list adds to the defaults; nothing turns them off. Throws a `TypeError`
66
+ * for a list that isn't an array, a name that isn't a valid header name, and `authorization`, `proxy-authorization`,
67
+ * `cookie` or `set-cookie`, whose values a record never shows whole.
68
+ */
69
+ export function checkRecordHeaders(names) {
70
+ const shown = new Set(DEFAULT_RECORD_HEADERS);
71
+ if (names === undefined)
72
+ return shown;
73
+ if (!Array.isArray(names))
74
+ throw new TypeError("recordHeaders must be an array of header names");
75
+ for (const name of names) {
76
+ if (typeof name !== "string")
77
+ throw new TypeError(`recordHeaders holds ${String(name)}, not a header name`);
78
+ try {
79
+ validateHeaderName(name);
80
+ }
81
+ catch {
82
+ throw new TypeError(`recordHeaders holds ${JSON.stringify(name)}, not a valid header name`);
83
+ }
84
+ const key = name.toLowerCase();
85
+ if (AUTHORIZATION_HEADERS.has(key) || COOKIE_HEADERS.has(key)) {
86
+ throw new TypeError(`recordHeaders can't name ${key}: a record always shows only its ${AUTHORIZATION_HEADERS.has(key) ? "scheme" : "cookie names"}`);
87
+ }
88
+ shown.add(key);
89
+ }
90
+ return shown;
91
+ }
92
+ /**
93
+ * The canonical key of `names`, a `recordHeaders` option: the JSON of the names `checkRecordHeaders` shows, sorted,
94
+ * so two lists that show the same headers give the same key. `undefined`, `[]`, and `["Content-Type"]` do, since a
95
+ * list adds to the defaults, and so do `["X-Trace", "dpop"]` and `["dpop", "x-trace", "DPoP"]`. Throws
96
+ * `checkRecordHeaders`' `TypeError` for a list it refuses.
97
+ */
98
+ export function recordHeadersKey(names) {
99
+ return JSON.stringify([...checkRecordHeaders(names)].toSorted());
100
+ }
101
+ /**
102
+ * `headers` as a record keeps them. Every value is hidden, reading `<redacted>`, unless a rule or `shown` shows it:
103
+ * `authorization` and `proxy-authorization` show their scheme and read `<token>` for the credentials, such as
104
+ * `DPoP <token>`, and a value with no scheme reads `<token>`; `cookie` and `set-cookie` show each cookie's name, and
105
+ * `set-cookie` its attributes, and read `<token>` for each value; and a header `shown` names is kept as sent, with
106
+ * `secret`, the request's own `authorization` credentials, replaced by `<token>` wherever it appears. A header's name
107
+ * is always recorded, so a test can tell it was sent.
108
+ */
109
+ export function recordedHeaders(headers, redaction) {
110
+ const collected = new Map();
111
+ for (const [name, value] of headers) {
112
+ if (value === undefined)
113
+ continue;
114
+ const key = name.toLowerCase();
115
+ const values = collected.get(key) ?? [];
116
+ values.push(...(typeof value === "string" ? [value] : value));
117
+ collected.set(key, values);
118
+ }
119
+ // Collected in a `Map`, so a header named such as `__proto__` becomes a plain own property.
120
+ return Object.fromEntries([...collected].map(([name, values]) => [name, recordedValue(name, values, redaction)]));
121
+ }
122
+ /** Every value of the header `name` as one string, shown or hidden by its rule. */
123
+ function recordedValue(name, values, redaction) {
124
+ if (AUTHORIZATION_HEADERS.has(name))
125
+ return values.map(redactAuthorization).join(", ");
126
+ if (name === "cookie")
127
+ return values.map(redactRequestCookies).join("; ");
128
+ if (name === "set-cookie")
129
+ return values.map(redactSetCookie).join("\n");
130
+ if (!redaction.shown.has(name))
131
+ return REDACTED_HEADER;
132
+ const { secret } = redaction;
133
+ return values.map((value) => (secret === undefined ? value : redactSecrets(value, [secret]))).join(", ");
134
+ }
135
+ /** An `authorization` value as its scheme and `<token>`, or `<token>` alone for a value with no scheme. */
136
+ function redactAuthorization(value) {
137
+ const parsed = parseAuthorization(value);
138
+ if (parsed === undefined)
139
+ return value;
140
+ return parsed.scheme === undefined ? REDACTED : `${parsed.scheme} ${REDACTED}`;
141
+ }
142
+ /** A `cookie` value with each cookie's value reading `<token>`. */
143
+ function redactRequestCookies(value) {
144
+ return parts(value).map(redactCookie).join("; ");
145
+ }
146
+ /** A `set-cookie` value with its cookie's value reading `<token>`, its attributes kept. */
147
+ function redactSetCookie(value) {
148
+ const [cookie, ...attributes] = value.split(";").map((each) => each.trim());
149
+ return [redactCookie(cookie ?? ""), ...attributes.filter((each) => each !== "")].join("; ");
150
+ }
151
+ /** The non-empty `;`-separated parts of `value`, trimmed. */
152
+ function parts(value) {
153
+ return value
154
+ .split(";")
155
+ .map((each) => each.trim())
156
+ .filter((each) => each !== "");
157
+ }
158
+ /** A `name=value` cookie as `name=<token>`; a cookie with no `=` reads `<token>`. */
159
+ function redactCookie(cookie) {
160
+ const equals = cookie.indexOf("=");
161
+ return equals === -1 ? REDACTED : `${cookie.slice(0, equals).trim()}=${REDACTED}`;
162
+ }
@@ -1,2 +1,3 @@
1
- export { bearerToken, BodyCapture, decodeBody, headerText, parseParams, RECORDED_BODY_CAP_BYTES, type RecordedBody, recordedBody, REDACTED, redactBody, redactSecrets, redactTokenFields, tokenSecrets, } from "./body.ts";
1
+ export { BodyCapture, decodeBody, headerText, parseParams, RECORDED_BODY_CAP_BYTES, type RecordedBody, recordedBody, REDACTED, redactBody, redactSecrets, redactTokenFields, tokenSecrets, } from "./body.ts";
2
+ export { type Authorization, authorizationSecret, checkRecordHeaders, DEFAULT_RECORD_HEADERS, type HeaderEntries, type HeaderRedaction, MIN_CREDENTIAL_CHARS, parseAuthorization, REDACTED_HEADER, type RecordedHeaders, recordedHeaders, recordHeadersKey, } from "./headers.ts";
2
3
  export { type ApiRequestRecord, type ExternalCallRecord, incomingHeaders, type RequestOutcome, type RequestRecordFields, splitTarget, } from "./records.ts";
@@ -1,4 +1,6 @@
1
1
  // The SDK's `records` module: how request records are kept, shared by the proxy's records and a container's API
2
- // requests. Bodies are decoded, capped and redacted here, and the fields every record holds are defined here.
3
- export { bearerToken, BodyCapture, decodeBody, headerText, parseParams, RECORDED_BODY_CAP_BYTES, recordedBody, REDACTED, redactBody, redactSecrets, redactTokenFields, tokenSecrets, } from "./body.js";
2
+ // requests. Bodies and headers are decoded, capped and redacted here, and the fields every record holds are defined
3
+ // here.
4
+ export { BodyCapture, decodeBody, headerText, parseParams, RECORDED_BODY_CAP_BYTES, recordedBody, REDACTED, redactBody, redactSecrets, redactTokenFields, tokenSecrets, } from "./body.js";
5
+ export { authorizationSecret, checkRecordHeaders, DEFAULT_RECORD_HEADERS, MIN_CREDENTIAL_CHARS, parseAuthorization, REDACTED_HEADER, recordedHeaders, recordHeadersKey, } from "./headers.js";
4
6
  export { incomingHeaders, splitTarget, } from "./records.js";