callman-core 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scenario-runner/runScenario.d.ts.map +1 -1
- package/dist/scenario-runner/runScenario.js +8 -0
- package/dist/scenario-runner/runScenario.js.map +1 -1
- package/dist/scenario-runner/types.d.ts +1 -1
- package/dist/scenario-runner/types.d.ts.map +1 -1
- package/dist/script/executor.d.ts.map +1 -1
- package/dist/script/executor.js +267 -11
- package/dist/script/executor.js.map +1 -1
- package/dist/script/features/collectionVariables.d.ts +16 -0
- package/dist/script/features/collectionVariables.d.ts.map +1 -0
- package/dist/script/features/collectionVariables.js +83 -0
- package/dist/script/features/collectionVariables.js.map +1 -0
- package/dist/script/features/cryptojs.d.ts +8 -12
- package/dist/script/features/cryptojs.d.ts.map +1 -1
- package/dist/script/features/cryptojs.js +15 -99
- package/dist/script/features/cryptojs.js.map +1 -1
- package/dist/script/features/environment.d.ts +8 -1
- package/dist/script/features/environment.d.ts.map +1 -1
- package/dist/script/features/environment.js +25 -1
- package/dist/script/features/environment.js.map +1 -1
- package/dist/script/features/execution.d.ts +17 -0
- package/dist/script/features/execution.d.ts.map +1 -0
- package/dist/script/features/execution.js +60 -0
- package/dist/script/features/execution.js.map +1 -0
- package/dist/script/features/headerList.d.ts +44 -0
- package/dist/script/features/headerList.d.ts.map +1 -0
- package/dist/script/features/headerList.js +284 -0
- package/dist/script/features/headerList.js.map +1 -0
- package/dist/script/features/info.d.ts +10 -0
- package/dist/script/features/info.d.ts.map +1 -0
- package/dist/script/features/info.js +32 -0
- package/dist/script/features/info.js.map +1 -0
- package/dist/script/features/request.d.ts +3 -2
- package/dist/script/features/request.d.ts.map +1 -1
- package/dist/script/features/request.js +38 -29
- package/dist/script/features/request.js.map +1 -1
- package/dist/script/features/response.d.ts +7 -5
- package/dist/script/features/response.d.ts.map +1 -1
- package/dist/script/features/response.js +16 -8
- package/dist/script/features/response.js.map +1 -1
- package/dist/script/features/responseAssertions.d.ts +50 -0
- package/dist/script/features/responseAssertions.d.ts.map +1 -0
- package/dist/script/features/responseAssertions.js +293 -0
- package/dist/script/features/responseAssertions.js.map +1 -0
- package/dist/script/features/timers.d.ts +17 -0
- package/dist/script/features/timers.d.ts.map +1 -0
- package/dist/script/features/timers.js +152 -0
- package/dist/script/features/timers.js.map +1 -0
- package/dist/script/features/variables.d.ts +8 -1
- package/dist/script/features/variables.d.ts.map +1 -1
- package/dist/script/features/variables.js +57 -11
- package/dist/script/features/variables.js.map +1 -1
- package/dist/script/pmApi.d.ts +36 -0
- package/dist/script/pmApi.d.ts.map +1 -1
- package/dist/script/pmApi.js +170 -0
- package/dist/script/pmApi.js.map +1 -1
- package/dist/script/scope.d.ts +10 -0
- package/dist/script/scope.d.ts.map +1 -1
- package/dist/script/scope.js +13 -4
- package/dist/script/scope.js.map +1 -1
- package/dist/script/types.d.ts +51 -1
- package/dist/script/types.d.ts.map +1 -1
- package/dist/templating/generator-metadata.d.ts +1 -0
- package/dist/templating/generator-metadata.d.ts.map +1 -1
- package/dist/templating/generator-metadata.js +76 -0
- package/dist/templating/generator-metadata.js.map +1 -1
- package/dist/templating/postman-generators.d.ts +12 -0
- package/dist/templating/postman-generators.d.ts.map +1 -0
- package/dist/templating/postman-generators.js +577 -0
- package/dist/templating/postman-generators.js.map +1 -0
- package/dist/templating/template-engine.d.ts.map +1 -1
- package/dist/templating/template-engine.js +16 -0
- package/dist/templating/template-engine.js.map +1 -1
- package/dist/variables/resolver.d.ts.map +1 -1
- package/dist/variables/resolver.js +15 -0
- package/dist/variables/resolver.js.map +1 -1
- package/dist-cjs/scenario-runner/runScenario.js +8 -0
- package/dist-cjs/scenario-runner/runScenario.js.map +1 -1
- package/dist-cjs/script/executor.js +270 -11
- package/dist-cjs/script/executor.js.map +1 -1
- package/dist-cjs/script/features/collectionVariables.js +87 -0
- package/dist-cjs/script/features/collectionVariables.js.map +1 -0
- package/dist-cjs/script/features/cryptojs.js +18 -99
- package/dist-cjs/script/features/cryptojs.js.map +1 -1
- package/dist-cjs/script/features/environment.js +25 -1
- package/dist-cjs/script/features/environment.js.map +1 -1
- package/dist-cjs/script/features/execution.js +64 -0
- package/dist-cjs/script/features/execution.js.map +1 -0
- package/dist-cjs/script/features/headerList.js +289 -0
- package/dist-cjs/script/features/headerList.js.map +1 -0
- package/dist-cjs/script/features/info.js +36 -0
- package/dist-cjs/script/features/info.js.map +1 -0
- package/dist-cjs/script/features/request.js +38 -29
- package/dist-cjs/script/features/request.js.map +1 -1
- package/dist-cjs/script/features/response.js +16 -8
- package/dist-cjs/script/features/response.js.map +1 -1
- package/dist-cjs/script/features/responseAssertions.js +297 -0
- package/dist-cjs/script/features/responseAssertions.js.map +1 -0
- package/dist-cjs/script/features/timers.js +156 -0
- package/dist-cjs/script/features/timers.js.map +1 -0
- package/dist-cjs/script/features/variables.js +57 -11
- package/dist-cjs/script/features/variables.js.map +1 -1
- package/dist-cjs/script/pmApi.js +170 -0
- package/dist-cjs/script/pmApi.js.map +1 -1
- package/dist-cjs/script/scope.js +13 -4
- package/dist-cjs/script/scope.js.map +1 -1
- package/dist-cjs/templating/generator-metadata.js +77 -1
- package/dist-cjs/templating/generator-metadata.js.map +1 -1
- package/dist-cjs/templating/postman-generators.js +581 -0
- package/dist-cjs/templating/postman-generators.js.map +1 -0
- package/dist-cjs/templating/template-engine.js +16 -0
- package/dist-cjs/templating/template-engine.js.map +1 -1
- package/dist-cjs/variables/resolver.js +15 -0
- package/dist-cjs/variables/resolver.js.map +1 -1
- package/package.json +6 -2
|
@@ -1,102 +1,18 @@
|
|
|
1
|
-
// CryptoJS —
|
|
1
|
+
// CryptoJS — the real `crypto-js` package, surfaced unmodified so
|
|
2
|
+
// Postman scripts that lean on it ("CryptoJS.HmacSHA256(message, key)",
|
|
3
|
+
// "CryptoJS.AES.encrypt", "CryptoJS.SHA256", "CryptoJS.MD5",
|
|
4
|
+
// "CryptoJS.PBKDF2", "CryptoJS.enc.Hex/Base64/Utf8", "CryptoJS.lib.WordArray")
|
|
5
|
+
// run unmodified.
|
|
2
6
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// in
|
|
7
|
+
// Why we kept a hand-written stub for so long: the original Callman
|
|
8
|
+
// sandbox blocked `Buffer`, and the team wanted to control bundle
|
|
9
|
+
// size. The trade-off failed in practice — every other request-signing
|
|
10
|
+
// pattern in real Postman scripts uses HMAC-SHA256, which the stub
|
|
11
|
+
// could not provide, leading to "CryptoJS.HmacSHA256 is not a function"
|
|
12
|
+
// errors. Bundling the real ~150 KB library is the right call.
|
|
7
13
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// CryptoJS.enc.Base64.parse(base64String) → Uint8Array (decoder)
|
|
13
|
-
//
|
|
14
|
-
// HMAC / SHA / AES are intentionally out of scope.
|
|
15
|
-
const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
16
|
-
const toUint8Array = (input) => {
|
|
17
|
-
if (input instanceof Uint8Array) {
|
|
18
|
-
return input;
|
|
19
|
-
}
|
|
20
|
-
if (input instanceof ArrayBuffer) {
|
|
21
|
-
return new Uint8Array(input);
|
|
22
|
-
}
|
|
23
|
-
if (ArrayBuffer.isView(input)) {
|
|
24
|
-
const view = input;
|
|
25
|
-
return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
26
|
-
}
|
|
27
|
-
if (typeof input === "string") {
|
|
28
|
-
return new TextEncoder().encode(input);
|
|
29
|
-
}
|
|
30
|
-
return new Uint8Array(0);
|
|
31
|
-
};
|
|
32
|
-
// Portable base64 encoder: walks the Uint8Array in 3-byte chunks and emits
|
|
33
|
-
// four characters per chunk per RFC 4648. No reliance on Buffer or btoa,
|
|
34
|
-
// so it works in vm contexts where neither is exposed.
|
|
35
|
-
const encodeBase64 = (bytes) => {
|
|
36
|
-
let output = "";
|
|
37
|
-
const length = bytes.length;
|
|
38
|
-
for (let index = 0; index < length; index += 3) {
|
|
39
|
-
const b0 = bytes[index];
|
|
40
|
-
const b1 = index + 1 < length ? bytes[index + 1] : 0;
|
|
41
|
-
const b2 = index + 2 < length ? bytes[index + 2] : 0;
|
|
42
|
-
const triplet = (b0 << 16) | (b1 << 8) | b2;
|
|
43
|
-
output += BASE64_CHARS[(triplet >> 18) & 0x3f];
|
|
44
|
-
output += BASE64_CHARS[(triplet >> 12) & 0x3f];
|
|
45
|
-
output += index + 1 < length ? BASE64_CHARS[(triplet >> 6) & 0x3f] : "=";
|
|
46
|
-
output += index + 2 < length ? BASE64_CHARS[triplet & 0x3f] : "=";
|
|
47
|
-
}
|
|
48
|
-
return output;
|
|
49
|
-
};
|
|
50
|
-
// Inverse of encodeBase64. Accepts both standard base64 (`+`/`/`, padded)
|
|
51
|
-
// and base64url (`-`/`_`, unpadded) input — useful because callers
|
|
52
|
-
// frequently pass JWT payload segments which use the url-safe alphabet
|
|
53
|
-
// without padding. Throws on characters outside both alphabets so the
|
|
54
|
-
// caller fails fast on garbage input rather than silently producing junk
|
|
55
|
-
// bytes.
|
|
56
|
-
const decodeBase64 = (input) => {
|
|
57
|
-
// Normalize url-safe → standard and re-pad to a multiple of 4.
|
|
58
|
-
const normalized = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
59
|
-
const padding = (4 - (normalized.length % 4)) % 4;
|
|
60
|
-
const padded = normalized + "=".repeat(padding);
|
|
61
|
-
// Reject anything outside the standard alphabet (post-normalization).
|
|
62
|
-
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(padded)) {
|
|
63
|
-
throw new Error("CryptoJS.enc.Base64.parse: invalid base64 input");
|
|
64
|
-
}
|
|
65
|
-
const cleanLength = padded.replace(/=+$/g, "").length;
|
|
66
|
-
const byteLength = Math.floor((cleanLength * 3) / 4);
|
|
67
|
-
const out = new Uint8Array(byteLength);
|
|
68
|
-
let outIndex = 0;
|
|
69
|
-
for (let i = 0; i < padded.length; i += 4) {
|
|
70
|
-
const c1 = BASE64_CHARS.indexOf(padded[i]);
|
|
71
|
-
const c2 = BASE64_CHARS.indexOf(padded[i + 1]);
|
|
72
|
-
const c3 = padded[i + 2] === "=" ? -1 : BASE64_CHARS.indexOf(padded[i + 2]);
|
|
73
|
-
const c4 = padded[i + 3] === "=" ? -1 : BASE64_CHARS.indexOf(padded[i + 3]);
|
|
74
|
-
out[outIndex++] = (c1 << 2) | (c2 >> 4);
|
|
75
|
-
if (c3 >= 0)
|
|
76
|
-
out[outIndex++] = ((c2 & 0x0f) << 4) | (c3 >> 2);
|
|
77
|
-
if (c4 >= 0)
|
|
78
|
-
out[outIndex++] = ((c3 & 0x03) << 6) | c4;
|
|
79
|
-
}
|
|
80
|
-
return out;
|
|
81
|
-
};
|
|
82
|
-
export const createCryptoJsApi = () => {
|
|
83
|
-
const decoder = new TextDecoder();
|
|
84
|
-
return {
|
|
85
|
-
enc: {
|
|
86
|
-
Utf8: {
|
|
87
|
-
parse: (input) => toUint8Array(input),
|
|
88
|
-
stringify: (input) => decoder.decode(toUint8Array(input)),
|
|
89
|
-
},
|
|
90
|
-
Base64: {
|
|
91
|
-
stringify: (input) => encodeBase64(toUint8Array(input)),
|
|
92
|
-
parse: (input) => {
|
|
93
|
-
if (typeof input !== "string") {
|
|
94
|
-
throw new Error("CryptoJS.enc.Base64.parse: expected a string");
|
|
95
|
-
}
|
|
96
|
-
return decodeBase64(input);
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
};
|
|
14
|
+
// The pure-JS implementation does not touch Node's `Buffer`, so it
|
|
15
|
+
// runs inside the vm sandbox without any host shims.
|
|
16
|
+
import CryptoJS from "crypto-js";
|
|
17
|
+
export const createCryptoJsApi = () => CryptoJS;
|
|
102
18
|
//# sourceMappingURL=cryptojs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cryptojs.js","sourceRoot":"","sources":["../../../src/script/features/cryptojs.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"cryptojs.js","sourceRoot":"","sources":["../../../src/script/features/cryptojs.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,wEAAwE;AACxE,6DAA6D;AAC7D,+EAA+E;AAC/E,kBAAkB;AAClB,EAAE;AACF,oEAAoE;AACpE,kEAAkE;AAClE,uEAAuE;AACvE,mEAAmE;AACnE,wEAAwE;AACxE,+DAA+D;AAC/D,EAAE;AACF,mEAAmE;AACnE,qDAAqD;AAErD,OAAO,QAAQ,MAAM,WAAW,CAAC;AAUjC,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAgB,EAAE,CAAC,QAAQ,CAAC"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { ScriptVariableMutation } from "../types.js";
|
|
2
2
|
export interface EnvironmentApi {
|
|
3
3
|
values: Record<string, string>;
|
|
4
|
+
/** Read-only label of the scope (e.g. "Staging" for an env, or
|
|
5
|
+
* "Globals"). Defaults to the scope kind. */
|
|
6
|
+
name: string;
|
|
4
7
|
get: (key: string) => string | undefined;
|
|
5
8
|
set: (key: string, value: unknown) => void;
|
|
6
9
|
unset: (key: string) => void;
|
|
7
10
|
has: (key: string) => boolean;
|
|
11
|
+
clear: () => void;
|
|
8
12
|
toObject: () => Record<string, string>;
|
|
13
|
+
replaceIn: (template: unknown) => string;
|
|
9
14
|
}
|
|
10
|
-
export declare const buildEnvironmentApi: (initial: Record<string, string>, mutations: ScriptVariableMutation[] | null, scope: ScriptVariableMutation["scope"]
|
|
15
|
+
export declare const buildEnvironmentApi: (initial: Record<string, string>, mutations: ScriptVariableMutation[] | null, scope: ScriptVariableMutation["scope"], options?: {
|
|
16
|
+
nameOverride?: string;
|
|
17
|
+
}) => EnvironmentApi;
|
|
11
18
|
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/script/features/environment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/script/features/environment.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B;iDAC6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACzC,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAC9B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,SAAS,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,MAAM,CAAC;CAC1C;AASD,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,WAAW,sBAAsB,EAAE,GAAG,IAAI,EAC1C,OAAO,sBAAsB,CAAC,OAAO,CAAC,EACtC,UAAS;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,KACtC,cA+DF,CAAC"}
|
|
@@ -7,16 +7,25 @@
|
|
|
7
7
|
// - emitMutations=false: the API mutates the in-memory `values` record
|
|
8
8
|
// directly without producing a log. Used by callman-core's legacy
|
|
9
9
|
// `runScript` shim where EnvStore is the source of truth.
|
|
10
|
+
//
|
|
11
|
+
// Postman compatibility additions (Phase 1.3):
|
|
12
|
+
// - `.replaceIn(template)` — resolve `{{var}}` against THIS scope only.
|
|
13
|
+
// - `.clear()` — wipe all keys (emits one unset mutation per key when
|
|
14
|
+
// mutations are tracked, so the host can mirror the deletion).
|
|
15
|
+
// - `.name` — read-only string label of the active scope ("environment"
|
|
16
|
+
// or "global" by default; backend can override via `nameOverride`).
|
|
17
|
+
import { resolveTemplate } from "../../variables/resolver.js";
|
|
10
18
|
const coerceToString = (value) => {
|
|
11
19
|
if (value === undefined || value === null) {
|
|
12
20
|
return "";
|
|
13
21
|
}
|
|
14
22
|
return String(value);
|
|
15
23
|
};
|
|
16
|
-
export const buildEnvironmentApi = (initial, mutations, scope) => {
|
|
24
|
+
export const buildEnvironmentApi = (initial, mutations, scope, options = {}) => {
|
|
17
25
|
// Copy so the caller's record is never mutated in-place when the
|
|
18
26
|
// sandbox is configured to emit mutations.
|
|
19
27
|
const values = { ...initial };
|
|
28
|
+
const name = options.nameOverride ?? (scope === "global" ? "Globals" : "Environment");
|
|
20
29
|
const recordMutation = (mutation) => {
|
|
21
30
|
if (mutations) {
|
|
22
31
|
mutations.push(mutation);
|
|
@@ -24,6 +33,7 @@ export const buildEnvironmentApi = (initial, mutations, scope) => {
|
|
|
24
33
|
};
|
|
25
34
|
return {
|
|
26
35
|
values,
|
|
36
|
+
name,
|
|
27
37
|
get: (key) => values[String(key ?? "").trim()],
|
|
28
38
|
set: (key, value) => {
|
|
29
39
|
const normalizedKey = String(key ?? "").trim();
|
|
@@ -55,7 +65,21 @@ export const buildEnvironmentApi = (initial, mutations, scope) => {
|
|
|
55
65
|
const normalizedKey = String(key ?? "").trim();
|
|
56
66
|
return Boolean(normalizedKey) && normalizedKey in values;
|
|
57
67
|
},
|
|
68
|
+
clear: () => {
|
|
69
|
+
// Snapshot keys first so we emit one unset mutation per entry and
|
|
70
|
+
// don't fight the iteration order while deleting.
|
|
71
|
+
const keys = Object.keys(values);
|
|
72
|
+
for (const key of keys) {
|
|
73
|
+
delete values[key];
|
|
74
|
+
recordMutation({
|
|
75
|
+
scope,
|
|
76
|
+
type: "unset",
|
|
77
|
+
key,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
},
|
|
58
81
|
toObject: () => ({ ...values }),
|
|
82
|
+
replaceIn: (template) => resolveTemplate(coerceToString(template), { env: values }),
|
|
59
83
|
};
|
|
60
84
|
};
|
|
61
85
|
//# sourceMappingURL=environment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/script/features/environment.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,EAAE;AACF,uBAAuB;AACvB,sEAAsE;AACtE,2EAA2E;AAC3E,qDAAqD;AACrD,yEAAyE;AACzE,sEAAsE;AACtE,8DAA8D;
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/script/features/environment.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ScriptExecutionCapability, ScriptExecutionControl } from "../types.js";
|
|
2
|
+
export interface ExecutionLocation extends Array<string> {
|
|
3
|
+
/** The last segment in the location array (the current request). */
|
|
4
|
+
current: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ExecutionApi {
|
|
7
|
+
setNextRequest: (name: string | null | undefined) => void;
|
|
8
|
+
skipRequest: () => void;
|
|
9
|
+
location: ExecutionLocation;
|
|
10
|
+
}
|
|
11
|
+
export interface ExecutionFeature {
|
|
12
|
+
api: ExecutionApi;
|
|
13
|
+
/** Snapshot of any control flags the script set. */
|
|
14
|
+
getControl: () => ScriptExecutionControl;
|
|
15
|
+
}
|
|
16
|
+
export declare const buildExecutionFeature: (capability: ScriptExecutionCapability | undefined) => ExecutionFeature;
|
|
17
|
+
//# sourceMappingURL=execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../../src/script/features/execution.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,iBAAkB,SAAQ,KAAK,CAAC,MAAM,CAAC;IACtD,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;IAC1D,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,YAAY,CAAC;IAClB,oDAAoD;IACpD,UAAU,EAAE,MAAM,sBAAsB,CAAC;CAC1C;AAkBD,eAAO,MAAM,qBAAqB,GAChC,YAAY,yBAAyB,GAAG,SAAS,KAChD,gBA2BF,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// pm.execution — Postman's collection-runner control surface.
|
|
2
|
+
//
|
|
3
|
+
// pm.execution.setNextRequest(name | null)
|
|
4
|
+
// Tell the runner to jump to a named request after this one (or
|
|
5
|
+
// `null` to stop the branch). Has no effect outside a runner — the
|
|
6
|
+
// host is free to ignore the flag for ad-hoc Send.
|
|
7
|
+
//
|
|
8
|
+
// pm.execution.skipRequest()
|
|
9
|
+
// Only meaningful in a pre-request script. Sets a flag that causes
|
|
10
|
+
// the runner to skip the HTTP call entirely. The Tests script then
|
|
11
|
+
// does NOT run either.
|
|
12
|
+
//
|
|
13
|
+
// pm.execution.location / .location.current
|
|
14
|
+
// A path-like array of segment strings (e.g. ["Smoke",
|
|
15
|
+
// "Authentication", "Login"]) and the last segment as `.current`,
|
|
16
|
+
// so users can pivot behaviour by location.
|
|
17
|
+
//
|
|
18
|
+
// Why this lives separately from `pm.node`:
|
|
19
|
+
// pm.node was a Callman-specific scenario-flow accessor. pm.execution
|
|
20
|
+
// is the Postman-named surface. We expose both — pm.node stays for
|
|
21
|
+
// back-compat, pm.execution is preferred going forward.
|
|
22
|
+
const buildLocation = (segments) => {
|
|
23
|
+
const arr = Array.isArray(segments) ? [...segments] : [];
|
|
24
|
+
const current = arr.length > 0 ? arr[arr.length - 1] : "";
|
|
25
|
+
// Augment the array with a `.current` getter. Using
|
|
26
|
+
// Object.defineProperty keeps it non-enumerable so JSON.stringify
|
|
27
|
+
// still produces a plain array.
|
|
28
|
+
Object.defineProperty(arr, "current", {
|
|
29
|
+
configurable: true,
|
|
30
|
+
enumerable: false,
|
|
31
|
+
get: () => current,
|
|
32
|
+
});
|
|
33
|
+
return arr;
|
|
34
|
+
};
|
|
35
|
+
export const buildExecutionFeature = (capability) => {
|
|
36
|
+
const state = {
|
|
37
|
+
nextRequest: undefined,
|
|
38
|
+
skipRequested: false,
|
|
39
|
+
};
|
|
40
|
+
const location = buildLocation(capability?.location);
|
|
41
|
+
const api = {
|
|
42
|
+
setNextRequest: (name) => {
|
|
43
|
+
if (name === null || name === undefined) {
|
|
44
|
+
state.nextRequest = null;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const trimmed = String(name).trim();
|
|
48
|
+
state.nextRequest = trimmed.length > 0 ? trimmed : null;
|
|
49
|
+
},
|
|
50
|
+
skipRequest: () => {
|
|
51
|
+
state.skipRequested = true;
|
|
52
|
+
},
|
|
53
|
+
location,
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
api,
|
|
57
|
+
getControl: () => ({ ...state }),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../../src/script/features/execution.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,6CAA6C;AAC7C,oEAAoE;AACpE,uEAAuE;AACvE,uDAAuD;AACvD,EAAE;AACF,+BAA+B;AAC/B,uEAAuE;AACvE,uEAAuE;AACvE,2BAA2B;AAC3B,EAAE;AACF,8CAA8C;AAC9C,2DAA2D;AAC3D,sEAAsE;AACtE,gDAAgD;AAChD,EAAE;AACF,4CAA4C;AAC5C,wEAAwE;AACxE,qEAAqE;AACrE,0DAA0D;AAwB1D,MAAM,aAAa,GAAG,CACpB,QAA8B,EACX,EAAE;IACrB,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1D,oDAAoD;IACpD,kEAAkE;IAClE,gCAAgC;IAChC,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE;QACpC,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,KAAK;QACjB,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO;KACnB,CAAC,CAAC;IACH,OAAO,GAAwB,CAAC;AAClC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,UAAiD,EAC/B,EAAE;IACpB,MAAM,KAAK,GAA2B;QACpC,WAAW,EAAE,SAAS;QACtB,aAAa,EAAE,KAAK;KACrB,CAAC;IAEF,MAAM,QAAQ,GAAG,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAErD,MAAM,GAAG,GAAiB;QACxB,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE;YACvB,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACxC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;gBACzB,OAAO;YACT,CAAC;YACD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;YACpC,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1D,CAAC;QACD,WAAW,EAAE,GAAG,EAAE;YAChB,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;QAC7B,CAAC;QACD,QAAQ;KACT,CAAC;IAEF,OAAO;QACL,GAAG;QACH,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface HeaderEntry {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface HeaderListMethods {
|
|
7
|
+
/** Case-insensitive value lookup. Returns the first matching value, or
|
|
8
|
+
* `undefined` if no header with that name exists. */
|
|
9
|
+
get(name: string): string | undefined;
|
|
10
|
+
/** Case-insensitive presence check. */
|
|
11
|
+
has(name: string): boolean;
|
|
12
|
+
/** Entry at numeric index, or undefined if out of range. */
|
|
13
|
+
idx(index: number): HeaderEntry | undefined;
|
|
14
|
+
/** Append an entry (allows duplicate names — same as Postman). */
|
|
15
|
+
add(spec: HeaderEntry | Record<string, unknown>): void;
|
|
16
|
+
/** Replace entries with the same name (case-insensitive), or append if
|
|
17
|
+
* absent. Always leaves at most one entry with that name. */
|
|
18
|
+
upsert(spec: HeaderEntry | Record<string, unknown>): void;
|
|
19
|
+
/** Remove every entry whose name matches (case-insensitive). */
|
|
20
|
+
remove(name: string): void;
|
|
21
|
+
/** Snapshot of all entries as a fresh array. */
|
|
22
|
+
all(): HeaderEntry[];
|
|
23
|
+
/** Postman-compat alias for `all()`. */
|
|
24
|
+
toJSON(): HeaderEntry[];
|
|
25
|
+
/** Iterator over entries (Postman HeaderList is iterable). */
|
|
26
|
+
[Symbol.iterator](): IterableIterator<HeaderEntry>;
|
|
27
|
+
}
|
|
28
|
+
export type HeaderList = HeaderListMethods & Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Build a Proxy-wrapped HeaderList. Bracket access reads / writes as if the
|
|
31
|
+
* value were a plain `Record<string, string>` (case-sensitive, exact key
|
|
32
|
+
* match). The HeaderList methods (`get`, `has`, `add`, ...) are exposed
|
|
33
|
+
* directly on the wrapper.
|
|
34
|
+
*/
|
|
35
|
+
export declare const createHeaderList: (initial?: HeaderEntry[] | Record<string, string>, options?: {
|
|
36
|
+
readOnly?: boolean;
|
|
37
|
+
}) => HeaderList;
|
|
38
|
+
/**
|
|
39
|
+
* Best-effort extraction of the underlying entry list, used by the
|
|
40
|
+
* request-state serialiser. Falls back to `Object.entries` for back-compat
|
|
41
|
+
* with any external callers that still pass a plain record.
|
|
42
|
+
*/
|
|
43
|
+
export declare const headerListEntries: (value: HeaderList | Record<string, string>) => HeaderEntry[];
|
|
44
|
+
//# sourceMappingURL=headerList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headerList.d.ts","sourceRoot":"","sources":["../../../src/script/features/headerList.ts"],"names":[],"mappings":"AAkCA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC;yDACqD;IACrD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC,uCAAuC;IACvC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,4DAA4D;IAC5D,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IAC5C,kEAAkE;IAClE,GAAG,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACvD;iEAC6D;IAC7D,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1D,gEAAgE;IAChE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,gDAAgD;IAChD,GAAG,IAAI,WAAW,EAAE,CAAC;IACrB,wCAAwC;IACxC,MAAM,IAAI,WAAW,EAAE,CAAC;IACxB,8DAA8D;IAC9D,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACpD;AAED,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AA8KpE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAS,WAAW,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpD,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACnC,UAwFF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC5B,OAAO,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACzC,WAAW,EAab,CAAC"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// HeaderList — Postman-compatible header / query parameter wrapper.
|
|
2
|
+
//
|
|
3
|
+
// Background. Older callman-core releases exposed `pm.request.headers` and
|
|
4
|
+
// `pm.response.headers` as plain `Record<string, string>` objects. Many real
|
|
5
|
+
// Postman scripts assume a richer `HeaderList` shape:
|
|
6
|
+
//
|
|
7
|
+
// pm.request.headers.add({ key, value, description? })
|
|
8
|
+
// pm.request.headers.upsert({ key, value, description? })
|
|
9
|
+
// pm.request.headers.remove(name)
|
|
10
|
+
// pm.request.headers.has(name) // case-insensitive
|
|
11
|
+
// pm.request.headers.get(name) // case-insensitive
|
|
12
|
+
// pm.request.headers.idx(i) // entry at index
|
|
13
|
+
// pm.request.headers.all() // [{ key, value, description }]
|
|
14
|
+
// for (const h of pm.request.headers) ... // iterable
|
|
15
|
+
//
|
|
16
|
+
// The class below provides both shapes through a Proxy: existing scripts that
|
|
17
|
+
// rely on bracket access (`headers["X-Custom"]`, `Object.keys(headers)`,
|
|
18
|
+
// `Object.entries(headers)`) keep working bit-for-bit, while new scripts can
|
|
19
|
+
// call the Postman methods on the same object.
|
|
20
|
+
//
|
|
21
|
+
// Mutability:
|
|
22
|
+
// - Request headers are writable. `setHeader` / `add` / `upsert` mutate the
|
|
23
|
+
// internal list and the changes are observed by `toRequestState()` when
|
|
24
|
+
// the script completes.
|
|
25
|
+
// - Response headers are constructed read-only — `add` / `upsert` / `remove`
|
|
26
|
+
// throw to preserve the immutability of an already-received response.
|
|
27
|
+
//
|
|
28
|
+
// Case sensitivity rules:
|
|
29
|
+
// - Lookups via `.get()`, `.has()`, `.remove()`, `.upsert()` are
|
|
30
|
+
// case-INSENSITIVE. This matches Postman and is the HTTP semantic.
|
|
31
|
+
// - Bracket access (`headers["X-Custom"]`) is case-SENSITIVE for
|
|
32
|
+
// back-compat with older Callman scripts that depended on exact-case
|
|
33
|
+
// keys derived from the previous Record<string, string> shape.
|
|
34
|
+
const METHOD_KEYS = new Set([
|
|
35
|
+
"get",
|
|
36
|
+
"has",
|
|
37
|
+
"idx",
|
|
38
|
+
"add",
|
|
39
|
+
"upsert",
|
|
40
|
+
"remove",
|
|
41
|
+
"all",
|
|
42
|
+
"toJSON",
|
|
43
|
+
"isReadOnly",
|
|
44
|
+
]);
|
|
45
|
+
const normaliseSpec = (spec) => {
|
|
46
|
+
if (spec === null || typeof spec !== "object") {
|
|
47
|
+
throw new TypeError("HeaderList: expected { key, value, description? } object");
|
|
48
|
+
}
|
|
49
|
+
const key = String(spec.key ?? "").trim();
|
|
50
|
+
if (!key) {
|
|
51
|
+
throw new TypeError("HeaderList: header key must be a non-empty string");
|
|
52
|
+
}
|
|
53
|
+
const value = spec.value;
|
|
54
|
+
const description = spec.description;
|
|
55
|
+
return {
|
|
56
|
+
key,
|
|
57
|
+
value: value === undefined || value === null ? "" : String(value),
|
|
58
|
+
description: typeof description === "string" ? description : undefined,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const stringifyValue = (value) => value === undefined || value === null ? "" : String(value);
|
|
62
|
+
class HeaderListImpl {
|
|
63
|
+
entries = [];
|
|
64
|
+
readOnly;
|
|
65
|
+
constructor(initial, readOnly = false) {
|
|
66
|
+
for (const entry of initial) {
|
|
67
|
+
this.entries.push({ ...entry });
|
|
68
|
+
}
|
|
69
|
+
this.readOnly = readOnly;
|
|
70
|
+
}
|
|
71
|
+
guardWritable() {
|
|
72
|
+
if (this.readOnly) {
|
|
73
|
+
throw new Error("Cannot mutate response headers — they are read-only after the response is captured.");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
get(name) {
|
|
77
|
+
const target = String(name ?? "")
|
|
78
|
+
.trim()
|
|
79
|
+
.toLowerCase();
|
|
80
|
+
if (!target)
|
|
81
|
+
return undefined;
|
|
82
|
+
for (const entry of this.entries) {
|
|
83
|
+
if (entry.key.toLowerCase() === target) {
|
|
84
|
+
return entry.value;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
has(name) {
|
|
90
|
+
return this.get(name) !== undefined;
|
|
91
|
+
}
|
|
92
|
+
idx(index) {
|
|
93
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.entries.length) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
return { ...this.entries[index] };
|
|
97
|
+
}
|
|
98
|
+
add(spec) {
|
|
99
|
+
this.guardWritable();
|
|
100
|
+
this.entries.push(normaliseSpec(spec));
|
|
101
|
+
}
|
|
102
|
+
upsert(spec) {
|
|
103
|
+
this.guardWritable();
|
|
104
|
+
const next = normaliseSpec(spec);
|
|
105
|
+
const target = next.key.toLowerCase();
|
|
106
|
+
const replaceIndex = this.entries.findIndex((entry) => entry.key.toLowerCase() === target);
|
|
107
|
+
if (replaceIndex >= 0) {
|
|
108
|
+
this.entries[replaceIndex] = next;
|
|
109
|
+
// Drop any further duplicates so upsert leaves a single entry.
|
|
110
|
+
for (let i = this.entries.length - 1; i > replaceIndex; i -= 1) {
|
|
111
|
+
if (this.entries[i].key.toLowerCase() === target) {
|
|
112
|
+
this.entries.splice(i, 1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.entries.push(next);
|
|
118
|
+
}
|
|
119
|
+
remove(name) {
|
|
120
|
+
this.guardWritable();
|
|
121
|
+
const target = String(name ?? "")
|
|
122
|
+
.trim()
|
|
123
|
+
.toLowerCase();
|
|
124
|
+
if (!target)
|
|
125
|
+
return;
|
|
126
|
+
for (let i = this.entries.length - 1; i >= 0; i -= 1) {
|
|
127
|
+
if (this.entries[i].key.toLowerCase() === target) {
|
|
128
|
+
this.entries.splice(i, 1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
all() {
|
|
133
|
+
return this.entries.map((entry) => ({ ...entry }));
|
|
134
|
+
}
|
|
135
|
+
toJSON() {
|
|
136
|
+
return this.all();
|
|
137
|
+
}
|
|
138
|
+
*[Symbol.iterator]() {
|
|
139
|
+
for (const entry of this.entries) {
|
|
140
|
+
yield { ...entry };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// ── Internal hooks used by the Proxy wrapper ──────────────────────────
|
|
144
|
+
__rawEntries() {
|
|
145
|
+
return this.entries;
|
|
146
|
+
}
|
|
147
|
+
__setRaw(key, value) {
|
|
148
|
+
this.guardWritable();
|
|
149
|
+
const normalisedKey = String(key ?? "").trim();
|
|
150
|
+
if (!normalisedKey)
|
|
151
|
+
return;
|
|
152
|
+
// Bracket-assignment is treated as upsert with EXACT case so that
|
|
153
|
+
// Object.keys(headers) and headers[k] readbacks see the user's chosen
|
|
154
|
+
// case — matches the legacy Record<string, string> behaviour.
|
|
155
|
+
const stringValue = stringifyValue(value);
|
|
156
|
+
const existing = this.entries.findIndex((entry) => entry.key === normalisedKey);
|
|
157
|
+
if (existing >= 0) {
|
|
158
|
+
this.entries[existing].value = stringValue;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.entries.push({ key: normalisedKey, value: stringValue });
|
|
162
|
+
}
|
|
163
|
+
__deleteRaw(key) {
|
|
164
|
+
this.guardWritable();
|
|
165
|
+
const normalisedKey = String(key ?? "").trim();
|
|
166
|
+
if (!normalisedKey)
|
|
167
|
+
return false;
|
|
168
|
+
const idx = this.entries.findIndex((entry) => entry.key === normalisedKey);
|
|
169
|
+
if (idx >= 0) {
|
|
170
|
+
this.entries.splice(idx, 1);
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Build a Proxy-wrapped HeaderList. Bracket access reads / writes as if the
|
|
178
|
+
* value were a plain `Record<string, string>` (case-sensitive, exact key
|
|
179
|
+
* match). The HeaderList methods (`get`, `has`, `add`, ...) are exposed
|
|
180
|
+
* directly on the wrapper.
|
|
181
|
+
*/
|
|
182
|
+
export const createHeaderList = (initial = [], options = {}) => {
|
|
183
|
+
const entries = Array.isArray(initial)
|
|
184
|
+
? initial.map((entry) => ({ ...entry }))
|
|
185
|
+
: Object.entries(initial).map(([key, value]) => ({
|
|
186
|
+
key,
|
|
187
|
+
value: stringifyValue(value),
|
|
188
|
+
}));
|
|
189
|
+
const impl = new HeaderListImpl(entries, options.readOnly ?? false);
|
|
190
|
+
return new Proxy(impl, {
|
|
191
|
+
get(target, prop, receiver) {
|
|
192
|
+
// Hand back methods / iterator unchanged.
|
|
193
|
+
if (typeof prop === "symbol") {
|
|
194
|
+
return Reflect.get(target, prop, receiver);
|
|
195
|
+
}
|
|
196
|
+
if (METHOD_KEYS.has(prop) || prop in target) {
|
|
197
|
+
const value = Reflect.get(target, prop, receiver);
|
|
198
|
+
if (typeof value === "function") {
|
|
199
|
+
return value.bind(target);
|
|
200
|
+
}
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
// String prop → look up as a header name (case-sensitive bracket
|
|
204
|
+
// access for back-compat with the previous Record shape).
|
|
205
|
+
const raw = target.__rawEntries();
|
|
206
|
+
for (const entry of raw) {
|
|
207
|
+
if (entry.key === prop) {
|
|
208
|
+
return entry.value;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return undefined;
|
|
212
|
+
},
|
|
213
|
+
set(target, prop, value, receiver) {
|
|
214
|
+
if (typeof prop === "symbol" || METHOD_KEYS.has(prop)) {
|
|
215
|
+
return Reflect.set(target, prop, value, receiver);
|
|
216
|
+
}
|
|
217
|
+
target.__setRaw(prop, value);
|
|
218
|
+
return true;
|
|
219
|
+
},
|
|
220
|
+
has(target, prop) {
|
|
221
|
+
if (typeof prop === "symbol" || METHOD_KEYS.has(prop) || prop in target) {
|
|
222
|
+
return Reflect.has(target, prop);
|
|
223
|
+
}
|
|
224
|
+
const raw = target.__rawEntries();
|
|
225
|
+
return raw.some((entry) => entry.key === prop);
|
|
226
|
+
},
|
|
227
|
+
deleteProperty(target, prop) {
|
|
228
|
+
if (typeof prop === "symbol" || METHOD_KEYS.has(prop)) {
|
|
229
|
+
return Reflect.deleteProperty(target, prop);
|
|
230
|
+
}
|
|
231
|
+
return target.__deleteRaw(String(prop));
|
|
232
|
+
},
|
|
233
|
+
ownKeys(target) {
|
|
234
|
+
// Object.keys / Object.entries / for-in see only the header names.
|
|
235
|
+
// The HeaderList methods stay non-enumerable so they don't pollute
|
|
236
|
+
// serialisation.
|
|
237
|
+
const raw = target.__rawEntries();
|
|
238
|
+
const seen = new Set();
|
|
239
|
+
const keys = [];
|
|
240
|
+
for (const entry of raw) {
|
|
241
|
+
if (!seen.has(entry.key)) {
|
|
242
|
+
seen.add(entry.key);
|
|
243
|
+
keys.push(entry.key);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return keys;
|
|
247
|
+
},
|
|
248
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
249
|
+
if (typeof prop === "symbol") {
|
|
250
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
251
|
+
}
|
|
252
|
+
if (METHOD_KEYS.has(prop)) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
const raw = target.__rawEntries();
|
|
256
|
+
const found = raw.find((entry) => entry.key === prop);
|
|
257
|
+
if (found) {
|
|
258
|
+
return {
|
|
259
|
+
configurable: true,
|
|
260
|
+
enumerable: true,
|
|
261
|
+
writable: true,
|
|
262
|
+
value: found.value,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return undefined;
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Best-effort extraction of the underlying entry list, used by the
|
|
271
|
+
* request-state serialiser. Falls back to `Object.entries` for back-compat
|
|
272
|
+
* with any external callers that still pass a plain record.
|
|
273
|
+
*/
|
|
274
|
+
export const headerListEntries = (value) => {
|
|
275
|
+
if (value &&
|
|
276
|
+
typeof value.all === "function") {
|
|
277
|
+
return value.all();
|
|
278
|
+
}
|
|
279
|
+
return Object.entries(value).map(([key, raw]) => ({
|
|
280
|
+
key,
|
|
281
|
+
value: stringifyValue(raw),
|
|
282
|
+
}));
|
|
283
|
+
};
|
|
284
|
+
//# sourceMappingURL=headerList.js.map
|