@tembo-io/sdk 0.18.0 → 0.19.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/api.md +3 -2
- package/dist/cjs/api-promise.d.ts.map +1 -1
- package/dist/cjs/api-promise.js +17 -6
- package/dist/cjs/api-promise.js.map +1 -1
- package/dist/cjs/client.d.ts +23 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +257 -12
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/internal/detect-platform.d.ts.map +1 -1
- package/dist/cjs/internal/detect-platform.js +44 -21
- package/dist/cjs/internal/detect-platform.js.map +1 -1
- package/dist/cjs/internal/utils/body.d.ts +40 -0
- package/dist/cjs/internal/utils/body.d.ts.map +1 -0
- package/dist/cjs/internal/utils/body.js +148 -0
- package/dist/cjs/internal/utils/body.js.map +1 -0
- package/dist/cjs/internal/utils/log.d.ts +7 -1
- package/dist/cjs/internal/utils/log.d.ts.map +1 -1
- package/dist/cjs/internal/utils/log.js +170 -23
- package/dist/cjs/internal/utils/log.js.map +1 -1
- package/dist/cjs/internal/utils/query-string.d.ts +21 -0
- package/dist/cjs/internal/utils/query-string.d.ts.map +1 -0
- package/dist/cjs/internal/utils/query-string.js +128 -0
- package/dist/cjs/internal/utils/query-string.js.map +1 -0
- package/dist/cjs/internal/utils/query.js +2 -35
- package/dist/cjs/internal/utils/query.js.map +1 -1
- package/dist/cjs/resources/integrations/integrations.d.ts +18 -2
- package/dist/cjs/resources/integrations/integrations.d.ts.map +1 -1
- package/dist/cjs/resources/integrations/integrations.js +1 -1
- package/dist/cjs/resources/integrations/integrations.js.map +1 -1
- package/dist/cjs/resources/live/ws-base.d.ts +5 -1
- package/dist/cjs/resources/live/ws-base.d.ts.map +1 -1
- package/dist/cjs/resources/live/ws-base.js +11 -1
- package/dist/cjs/resources/live/ws-base.js.map +1 -1
- package/dist/cjs/resources/models.d.ts +21 -7
- package/dist/cjs/resources/models.d.ts.map +1 -1
- package/dist/cjs/resources/models.js +2 -2
- package/dist/cjs/resources/models.js.map +1 -1
- package/dist/cjs/resources/runtimes.d.ts +10 -2
- package/dist/cjs/resources/runtimes.d.ts.map +1 -1
- package/dist/cjs/resources/skills/skills.d.ts +16 -2
- package/dist/cjs/resources/skills/skills.d.ts.map +1 -1
- package/dist/cjs/resources/skills/skills.js +1 -0
- package/dist/cjs/resources/skills/skills.js.map +1 -1
- package/dist/cjs/resources/users/settings.d.ts +3 -0
- package/dist/cjs/resources/users/settings.d.ts.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/api-promise.d.ts.map +1 -1
- package/dist/esm/api-promise.js +17 -6
- package/dist/esm/api-promise.js.map +1 -1
- package/dist/esm/client.d.ts +23 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +259 -14
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/internal/detect-platform.d.ts.map +1 -1
- package/dist/esm/internal/detect-platform.js +44 -21
- package/dist/esm/internal/detect-platform.js.map +1 -1
- package/dist/esm/internal/utils/body.d.ts +40 -0
- package/dist/esm/internal/utils/body.d.ts.map +1 -0
- package/dist/esm/internal/utils/body.js +140 -0
- package/dist/esm/internal/utils/body.js.map +1 -0
- package/dist/esm/internal/utils/log.d.ts +7 -1
- package/dist/esm/internal/utils/log.d.ts.map +1 -1
- package/dist/esm/internal/utils/log.js +170 -23
- package/dist/esm/internal/utils/log.js.map +1 -1
- package/dist/esm/internal/utils/query-string.d.ts +21 -0
- package/dist/esm/internal/utils/query-string.d.ts.map +1 -0
- package/dist/esm/internal/utils/query-string.js +125 -0
- package/dist/esm/internal/utils/query-string.js.map +1 -0
- package/dist/esm/internal/utils/query.js +2 -2
- package/dist/esm/internal/utils/query.js.map +1 -1
- package/dist/esm/resources/integrations/integrations.d.ts +18 -2
- package/dist/esm/resources/integrations/integrations.d.ts.map +1 -1
- package/dist/esm/resources/integrations/integrations.js +1 -1
- package/dist/esm/resources/integrations/integrations.js.map +1 -1
- package/dist/esm/resources/live/ws-base.d.ts +5 -1
- package/dist/esm/resources/live/ws-base.d.ts.map +1 -1
- package/dist/esm/resources/live/ws-base.js +11 -1
- package/dist/esm/resources/live/ws-base.js.map +1 -1
- package/dist/esm/resources/models.d.ts +21 -7
- package/dist/esm/resources/models.d.ts.map +1 -1
- package/dist/esm/resources/models.js +2 -2
- package/dist/esm/resources/models.js.map +1 -1
- package/dist/esm/resources/runtimes.d.ts +10 -2
- package/dist/esm/resources/runtimes.d.ts.map +1 -1
- package/dist/esm/resources/skills/skills.d.ts +16 -2
- package/dist/esm/resources/skills/skills.d.ts.map +1 -1
- package/dist/esm/resources/skills/skills.js +1 -0
- package/dist/esm/resources/skills/skills.js.map +1 -1
- package/dist/esm/resources/users/settings.d.ts +3 -0
- package/dist/esm/resources/users/settings.d.ts.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +5 -1
- package/dist/cjs/internal/qs/formats.d.ts +0 -7
- package/dist/cjs/internal/qs/formats.d.ts.map +0 -1
- package/dist/cjs/internal/qs/formats.js +0 -13
- package/dist/cjs/internal/qs/formats.js.map +0 -1
- package/dist/cjs/internal/qs/index.d.ts +0 -10
- package/dist/cjs/internal/qs/index.d.ts.map +0 -1
- package/dist/cjs/internal/qs/index.js +0 -14
- package/dist/cjs/internal/qs/index.js.map +0 -1
- package/dist/cjs/internal/qs/stringify.d.ts +0 -3
- package/dist/cjs/internal/qs/stringify.d.ts.map +0 -1
- package/dist/cjs/internal/qs/stringify.js +0 -278
- package/dist/cjs/internal/qs/stringify.js.map +0 -1
- package/dist/cjs/internal/qs/types.d.ts +0 -57
- package/dist/cjs/internal/qs/types.d.ts.map +0 -1
- package/dist/cjs/internal/qs/types.js +0 -3
- package/dist/cjs/internal/qs/types.js.map +0 -1
- package/dist/cjs/internal/qs/utils.d.ts +0 -15
- package/dist/cjs/internal/qs/utils.d.ts.map +0 -1
- package/dist/cjs/internal/qs/utils.js +0 -230
- package/dist/cjs/internal/qs/utils.js.map +0 -1
- package/dist/esm/internal/qs/formats.d.ts +0 -7
- package/dist/esm/internal/qs/formats.d.ts.map +0 -1
- package/dist/esm/internal/qs/formats.js +0 -9
- package/dist/esm/internal/qs/formats.js.map +0 -1
- package/dist/esm/internal/qs/index.d.ts +0 -10
- package/dist/esm/internal/qs/index.d.ts.map +0 -1
- package/dist/esm/internal/qs/index.js +0 -10
- package/dist/esm/internal/qs/index.js.map +0 -1
- package/dist/esm/internal/qs/stringify.d.ts +0 -3
- package/dist/esm/internal/qs/stringify.d.ts.map +0 -1
- package/dist/esm/internal/qs/stringify.js +0 -275
- package/dist/esm/internal/qs/stringify.js.map +0 -1
- package/dist/esm/internal/qs/types.d.ts +0 -57
- package/dist/esm/internal/qs/types.d.ts.map +0 -1
- package/dist/esm/internal/qs/types.js +0 -2
- package/dist/esm/internal/qs/types.js.map +0 -1
- package/dist/esm/internal/qs/utils.d.ts +0 -15
- package/dist/esm/internal/qs/utils.d.ts.map +0 -1
- package/dist/esm/internal/qs/utils.js +0 -217
- package/dist/esm/internal/qs/utils.js.map +0 -1
|
@@ -78,32 +78,55 @@ const getPlatformProperties = () => {
|
|
|
78
78
|
'X-Scalar-Runtime-Version': 'unknown',
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Reads the browser family and version from `navigator.userAgent`, or returns `null` outside a
|
|
83
|
+
* browser or for an agent it does not recognise.
|
|
84
|
+
*
|
|
85
|
+
* Every major browser also carries the tokens of the engines it grew out of (Edge says `Chrome/` and
|
|
86
|
+
* `Safari/`, Chrome says `Safari/`), so the most specific token is checked first.
|
|
87
|
+
*/
|
|
82
88
|
function getBrowserInfo() {
|
|
83
|
-
if (typeof navigator === 'undefined' || !navigator) {
|
|
89
|
+
if (typeof navigator === 'undefined' || !navigator || typeof navigator.userAgent !== 'string') {
|
|
84
90
|
return null;
|
|
85
91
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
]
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
92
|
+
const userAgent = navigator.userAgent;
|
|
93
|
+
const tokens = userAgentTokens(userAgent);
|
|
94
|
+
/** Returns the version of the first of `names` the agent carries a token for. */
|
|
95
|
+
const pick = (...names) => names.map((name) => tokens.get(name)).find((version) => version !== undefined);
|
|
96
|
+
const edge = pick('Edg', 'Edge', 'EdgA', 'EdgiOS');
|
|
97
|
+
if (edge)
|
|
98
|
+
return { browser: 'edge', version: edge };
|
|
99
|
+
// IE 11 dropped `MSIE`; it is told apart by its `Trident/` engine token and an `rv:` version.
|
|
100
|
+
const ie = /\bMSIE (\d+(?:\.\d+)*)/.exec(userAgent)?.[1] ??
|
|
101
|
+
(tokens.has('Trident') ? /\brv:(\d+(?:\.\d+)*)/.exec(userAgent)?.[1] : undefined);
|
|
102
|
+
if (ie)
|
|
103
|
+
return { browser: 'ie', version: ie };
|
|
104
|
+
const firefox = pick('Firefox', 'FxiOS');
|
|
105
|
+
if (firefox)
|
|
106
|
+
return { browser: 'firefox', version: firefox };
|
|
107
|
+
const chrome = pick('Chrome', 'CriOS', 'HeadlessChrome');
|
|
108
|
+
if (chrome)
|
|
109
|
+
return { browser: 'chrome', version: chrome };
|
|
110
|
+
// Safari's own version is the `Version/` token; its `Safari/` token is the WebKit build, so an
|
|
111
|
+
// iOS app's web view that carries only `Safari/` is still Safari, at a version it does not state.
|
|
112
|
+
if (tokens.has('Safari'))
|
|
113
|
+
return { browser: 'safari', version: tokens.get('Version') ?? 'unknown' };
|
|
105
114
|
return null;
|
|
106
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Collects the `Name/1.2.3` product tokens of a user-agent string, keeping the first version seen for
|
|
118
|
+
* each name.
|
|
119
|
+
*/
|
|
120
|
+
function userAgentTokens(userAgent) {
|
|
121
|
+
const tokens = new Map();
|
|
122
|
+
// The lookbehind starts a name only where a run of letters starts, so a long run is scanned once
|
|
123
|
+
// rather than retried from every letter in it.
|
|
124
|
+
for (const match of userAgent.matchAll(/(?<![A-Za-z])([A-Za-z]+)\/(\d+(?:\.\d+)*)/g)) {
|
|
125
|
+
if (!tokens.has(match[1]))
|
|
126
|
+
tokens.set(match[1], match[2]);
|
|
127
|
+
}
|
|
128
|
+
return tokens;
|
|
129
|
+
}
|
|
107
130
|
const normalizeArch = (arch) => {
|
|
108
131
|
// Node docs:
|
|
109
132
|
// - https://nodejs.org/api/process.html#processarch
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-platform.js","sourceRoot":"","sources":["../../../src/internal/detect-platform.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,OAAO;IACL,aAAa;IACb,OAAO,MAAM,KAAK,WAAW;QAC7B,aAAa;QACb,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;QACtC,aAAa;QACb,OAAO,SAAS,KAAK,WAAW,CACjC,CAAC;AACJ,CAAC,CAAC;AAIF;;GAEG;AACH,SAAS,mBAAmB;IAC1B,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACtD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IACE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAC5B,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,CAAC,CAAC,CAAE,UAAkB,CAAC,O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C;YAC7E,kBAAkB,EAAE,MAAM;YAC1B,0BAA0B,EAAG,UAAkB,CAAC,OAAO,CAAC,OAAO,IAAI,SAAS;SAC7E,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO;YACL,eAAe,EAAE,IAAI;YACrB,0BAA0B,EAAE,OAAO;YACnC,aAAa,EAAE,SAAS;YACxB,eAAe,EAAE,SAAS;YAC1B,kBAAkB,EAAE,WAAW,WAAW,CAAC,OAAO,EAAE;YACpD,0BAA0B,EAAE,WAAW,CAAC,OAAO;SAChD,CAAC;IACJ,CAAC;IAED,+EAA+E;IAC/E,OAAO;QACL,eAAe,EAAE,IAAI;QACrB,0BAA0B,EAAE,OAAO;QACnC,aAAa,EAAE,SAAS;QACxB,eAAe,EAAE,SAAS;QAC1B,kBAAkB,EAAE,SAAS;QAC7B,0BAA0B,EAAE,SAAS;KACtC,CAAC;AACJ,CAAC,CAAC;AASF
|
|
1
|
+
{"version":3,"file":"detect-platform.js","sourceRoot":"","sources":["../../../src/internal/detect-platform.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,OAAO;IACL,aAAa;IACb,OAAO,MAAM,KAAK,WAAW;QAC7B,aAAa;QACb,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;QACtC,aAAa;QACb,OAAO,SAAS,KAAK,WAAW,CACjC,CAAC;AACJ,CAAC,CAAC;AAIF;;GAEG;AACH,SAAS,mBAAmB;IAC1B,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACtD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC;I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O,OAAO,CAAC;IAC1C,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IAC3C,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC7C,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC7C,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,OAAO,CAAC;IACzC,IAAI,QAAQ;QAAE,OAAO,SAAS,QAAQ,EAAE,CAAC;IACzC,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,IAAI,gBAAoC,CAAC;AACzC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,OAAO,CAAC,gBAAgB,KAAK,qBAAqB,EAAE,CAAC,CAAC;AACxD,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TemboError } from '../../core/error.js';
|
|
2
|
+
/**
|
|
3
|
+
* The most a buffered (non-streaming) response body may hold, counted after transparent
|
|
4
|
+
* decompression. A body handed to the caller as a stream or a binary `Response` is not capped.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MAX_RESPONSE_BODY_BYTES: number;
|
|
7
|
+
/** The most of an error body the client reads for its message; anything after it is dropped. */
|
|
8
|
+
export declare const MAX_ERROR_BODY_BYTES: number;
|
|
9
|
+
/** The most a stream decoder holds for one pending line, event or frame before it gives up. */
|
|
10
|
+
export declare const MAX_STREAM_PENDING_BYTES: number;
|
|
11
|
+
/** The error a decoder or body read throws when the server sends more than `limit` bytes for one value. */
|
|
12
|
+
export declare const sizeLimitError: (what: string, limit: number) => TemboError;
|
|
13
|
+
/**
|
|
14
|
+
* Reads a response body as UTF-8 text, never holding more than `limit` bytes of it.
|
|
15
|
+
*
|
|
16
|
+
* `response.text()` buffers whatever the server sends, so a hostile or broken server could make the
|
|
17
|
+
* process hold gigabytes. Past `limit`, `'error'` throws (a success body cut short would only parse
|
|
18
|
+
* wrong) and `'truncate'` keeps what was read (an error message is still useful in part).
|
|
19
|
+
*/
|
|
20
|
+
export declare function readBodyText(response: Response, limit: number, overflow?: 'error' | 'truncate'): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Leaves a request's deadline armed until its buffered body has been read, so a server that sends
|
|
23
|
+
* headers promptly and then trickles the body is still cut off at the timeout.
|
|
24
|
+
*/
|
|
25
|
+
export declare const holdDeadline: (controller: AbortController, release: () => void) => void;
|
|
26
|
+
/** Disarms the deadline {@link holdDeadline} left armed for this request, if any. */
|
|
27
|
+
export declare const releaseDeadline: (controller: AbortController) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Runs a buffered body read under the request deadline, disarming it once the read settles.
|
|
30
|
+
*
|
|
31
|
+
* A read the deadline aborted rejects with a bare `AbortError`; it is reported as the timeout it was.
|
|
32
|
+
* One the caller's own signal aborted is left as it is.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readUnderDeadline<T>(props: {
|
|
35
|
+
controller: AbortController;
|
|
36
|
+
options: {
|
|
37
|
+
signal?: AbortSignal | null | undefined;
|
|
38
|
+
};
|
|
39
|
+
}, read: () => Promise<T>): Promise<T>;
|
|
40
|
+
//# sourceMappingURL=body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../../../src/internal/utils/body.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAIzE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,QAAmB,CAAC;AAExD,gGAAgG;AAChG,eAAO,MAAM,oBAAoB,QAAY,CAAC;AAE9C,+FAA+F;AAC/F,eAAO,MAAM,wBAAwB,QAAmB,CAAC;AASzD,2GAA2G;AAC3G,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,UACgC,CAAC;AAQ9F;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,OAAO,GAAG,UAAoB,GACvC,OAAO,CAAC,MAAM,CAAC,CAqCjB;AA4CD;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,YAAY,eAAe,EAAE,SAAS,MAAM,IAAI,KAAG,IAE/E,CAAC;AAEF,qFAAqF;AACrF,eAAO,MAAM,eAAe,GAAI,YAAY,eAAe,KAAG,IAI7D,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,KAAK,EAAE;IAAE,UAAU,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,CAAA;CAAE,EAC5F,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CAWZ"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Scalar. See README.md for details.
|
|
2
|
+
import { APIConnectionTimeoutError, TemboError } from '../../core/error.js';
|
|
3
|
+
import { isAbortError } from '../errors.js';
|
|
4
|
+
import { concatBytes, decodeUTF8, encodeUTF8 } from './bytes.js';
|
|
5
|
+
/**
|
|
6
|
+
* The most a buffered (non-streaming) response body may hold, counted after transparent
|
|
7
|
+
* decompression. A body handed to the caller as a stream or a binary `Response` is not capped.
|
|
8
|
+
*/
|
|
9
|
+
export const MAX_RESPONSE_BODY_BYTES = 64 * 1024 * 1024;
|
|
10
|
+
/** The most of an error body the client reads for its message; anything after it is dropped. */
|
|
11
|
+
export const MAX_ERROR_BODY_BYTES = 64 * 1024;
|
|
12
|
+
/** The most a stream decoder holds for one pending line, event or frame before it gives up. */
|
|
13
|
+
export const MAX_STREAM_PENDING_BYTES = 64 * 1024 * 1024;
|
|
14
|
+
/** A byte count as the error messages state it: whole MiB or KiB where it divides evenly. */
|
|
15
|
+
const formatLimit = (bytes) => {
|
|
16
|
+
if (bytes % (1024 * 1024) === 0)
|
|
17
|
+
return `${bytes / (1024 * 1024)} MiB`;
|
|
18
|
+
if (bytes % 1024 === 0)
|
|
19
|
+
return `${bytes / 1024} KiB`;
|
|
20
|
+
return `${bytes} bytes`;
|
|
21
|
+
};
|
|
22
|
+
/** The error a decoder or body read throws when the server sends more than `limit` bytes for one value. */
|
|
23
|
+
export const sizeLimitError = (what, limit) => new TemboError(`The ${what} is larger than the ${formatLimit(limit)} the SDK will buffer.`);
|
|
24
|
+
/**
|
|
25
|
+
* Reads a response body as UTF-8 text, never holding more than `limit` bytes of it.
|
|
26
|
+
*
|
|
27
|
+
* `response.text()` buffers whatever the server sends, so a hostile or broken server could make the
|
|
28
|
+
* process hold gigabytes. Past `limit`, `'error'` throws (a success body cut short would only parse
|
|
29
|
+
* wrong) and `'truncate'` keeps what was read (an error message is still useful in part).
|
|
30
|
+
*/
|
|
31
|
+
export async function readBodyText(response, limit, overflow = 'error') {
|
|
32
|
+
const body = response.body;
|
|
33
|
+
const reader = body && typeof body.getReader === 'function'
|
|
34
|
+
? body.getReader()
|
|
35
|
+
: body && typeof body[Symbol.asyncIterator] === 'function'
|
|
36
|
+
? iterableReader(body)
|
|
37
|
+
: undefined;
|
|
38
|
+
if (!reader)
|
|
39
|
+
return readWholeText(response, limit, overflow);
|
|
40
|
+
const chunks = [];
|
|
41
|
+
let total = 0;
|
|
42
|
+
let finished = false;
|
|
43
|
+
try {
|
|
44
|
+
for (;;) {
|
|
45
|
+
const { done, value } = await reader.read();
|
|
46
|
+
if (done) {
|
|
47
|
+
finished = true;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
if (value == null)
|
|
51
|
+
continue;
|
|
52
|
+
const bytes = typeof value === 'string' ? encodeUTF8(value) : value;
|
|
53
|
+
if (total + bytes.length > limit) {
|
|
54
|
+
if (overflow === 'error')
|
|
55
|
+
throw sizeLimitError('response body', limit);
|
|
56
|
+
chunks.push(bytes.subarray(0, limit - total));
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
chunks.push(bytes);
|
|
60
|
+
total += bytes.length;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
// Stops the download of whatever is left, rather than leaving the connection to drain it.
|
|
65
|
+
if (!finished)
|
|
66
|
+
reader.cancel().catch(() => { });
|
|
67
|
+
}
|
|
68
|
+
return decodeUTF8(concatBytes(chunks));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A {@link BodyReader} over an async-iterable body: a Node stream, which is what `node-fetch` passed
|
|
72
|
+
* as `fetch` hands back in place of a web `ReadableStream`. Cancelling ends the iteration, which
|
|
73
|
+
* destroys the stream.
|
|
74
|
+
*/
|
|
75
|
+
const iterableReader = (body) => {
|
|
76
|
+
const iterator = body[Symbol.asyncIterator]();
|
|
77
|
+
return {
|
|
78
|
+
read: async () => {
|
|
79
|
+
const next = await iterator.next();
|
|
80
|
+
return next.done ? { done: true } : { done: false, value: next.value };
|
|
81
|
+
},
|
|
82
|
+
cancel: async () => {
|
|
83
|
+
await iterator.return?.();
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Reads a body that offers no stream (some React Native polyfills) in one piece. It cannot be cut
|
|
89
|
+
* off part way, so a declared length over `limit` is refused before reading, and the text read is
|
|
90
|
+
* held to `limit` afterwards, which at least keeps an oversized body from reaching the caller.
|
|
91
|
+
*/
|
|
92
|
+
const readWholeText = async (response, limit, overflow) => {
|
|
93
|
+
const declared = Number(response.headers.get('content-length'));
|
|
94
|
+
if (overflow === 'error' && Number.isFinite(declared) && declared > limit) {
|
|
95
|
+
throw sizeLimitError('response body', limit);
|
|
96
|
+
}
|
|
97
|
+
const text = await response.text();
|
|
98
|
+
const bytes = encodeUTF8(text);
|
|
99
|
+
if (bytes.length <= limit)
|
|
100
|
+
return text;
|
|
101
|
+
if (overflow === 'error')
|
|
102
|
+
throw sizeLimitError('response body', limit);
|
|
103
|
+
return decodeUTF8(bytes.subarray(0, limit));
|
|
104
|
+
};
|
|
105
|
+
/** Deadlines left armed past the response headers, keyed by the request's abort controller. */
|
|
106
|
+
const pendingDeadlines = new WeakMap();
|
|
107
|
+
/**
|
|
108
|
+
* Leaves a request's deadline armed until its buffered body has been read, so a server that sends
|
|
109
|
+
* headers promptly and then trickles the body is still cut off at the timeout.
|
|
110
|
+
*/
|
|
111
|
+
export const holdDeadline = (controller, release) => {
|
|
112
|
+
pendingDeadlines.set(controller, release);
|
|
113
|
+
};
|
|
114
|
+
/** Disarms the deadline {@link holdDeadline} left armed for this request, if any. */
|
|
115
|
+
export const releaseDeadline = (controller) => {
|
|
116
|
+
const release = pendingDeadlines.get(controller);
|
|
117
|
+
pendingDeadlines.delete(controller);
|
|
118
|
+
release?.();
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Runs a buffered body read under the request deadline, disarming it once the read settles.
|
|
122
|
+
*
|
|
123
|
+
* A read the deadline aborted rejects with a bare `AbortError`; it is reported as the timeout it was.
|
|
124
|
+
* One the caller's own signal aborted is left as it is.
|
|
125
|
+
*/
|
|
126
|
+
export async function readUnderDeadline(props, read) {
|
|
127
|
+
try {
|
|
128
|
+
return await read();
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (isAbortError(error) && props.controller.signal.aborted && !props.options.signal?.aborted) {
|
|
132
|
+
throw new APIConnectionTimeoutError();
|
|
133
|
+
}
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
releaseDeadline(props.controller);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../../../src/internal/utils/body.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,YAAY,EA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AU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,+FAA+F;AAC/F,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAA+B,CAAC;AAEpE;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,UAA2B,EAAE,OAAmB,EAAQ,EAAE;IACrF,gBAAgB,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAA2B,EAAQ,EAAE;IACnE,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACjD,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACpC,OAAO,EAAE,EAAE,CAAC;AACd,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAA4F,EAC5F,IAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YAC7F,MAAM,IAAI,yBAAyB,EAAE,CAAC;QACxC,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"}
|
|
@@ -17,7 +17,13 @@ export declare function loggerFor(client: Tembo): Logger;
|
|
|
17
17
|
* same way an absolute one is and no parse can throw on the logging path.
|
|
18
18
|
*/
|
|
19
19
|
export declare const redactUrl: (url: string) => string;
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Replaces the value of every credential-bearing header, for a `Headers` or a plain record alike.
|
|
22
|
+
*
|
|
23
|
+
* Every other value is cleaned as free text: a response can echo the request URL back, in a
|
|
24
|
+
* `Location` or a `Link`, either as written or nested and encoded in a `return_to`, and a header's
|
|
25
|
+
* name says nothing about whether its value quotes a credential.
|
|
26
|
+
*/
|
|
21
27
|
export declare const redactHeaders: (headers: Headers | Record<string, string>) => Record<string, string>;
|
|
22
28
|
export declare const formatRequestDetails: (details: {
|
|
23
29
|
options?: RequestOptions | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../../src/internal/utils/log.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,KAAK,KAAK,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAC3D,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAUnE,eAAO,MAAM,aAAa,GACxB,YAAY,MAAM,GAAG,SAAS,EAC9B,YAAY,MAAM,EAClB,QAAQ,KAAK,KACZ,QAAQ,GAAG,SAab,CAAC;AAsBF,wBAAgB,SAAS,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,CAsB/C;
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../../src/internal/utils/log.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,c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C,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;cAVW,cAAc,GAAG,SAAS;cAC1B,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;0BAChC,MAAM,GAAG,SAAS;cAC9B,MAAM,GAAG,SAAS;UACtB,MAAM,GAAG,SAAS;aACf,MAAM,GAAG,SAAS;aAClB,MAAM,GAAG,SAAS;iBACd,MAAM,GAAG,SAAS;cACrB,OAAO;WACV,OAAO;CAyDf,CAAC"}
|
|
@@ -80,6 +80,84 @@ const REDACTED_HEADERS = new Set([
|
|
|
80
80
|
* verbose.
|
|
81
81
|
*/
|
|
82
82
|
const REDACTED_QUERY_PARAMS = [];
|
|
83
|
+
/**
|
|
84
|
+
* A byte's percent-encoded spelling at any depth and in either hex case, as a pattern: `%3F`,
|
|
85
|
+
* `%3f`, `%253F`. Each extra round of encoding turns the `%` into `%25` and leaves the hex alone,
|
|
86
|
+
* and encoders disagree on which case they write the hex in.
|
|
87
|
+
*/
|
|
88
|
+
const encodedBytePattern = (byte) => '%(?:25)*' +
|
|
89
|
+
[...byte.toString(16).padStart(2, '0')]
|
|
90
|
+
.map((digit) => (/[a-f]/u.test(digit) ? `[${digit}${digit.toUpperCase()}]` : digit))
|
|
91
|
+
.join('');
|
|
92
|
+
/**
|
|
93
|
+
* The UTF-8 bytes of one code point, worked out from `encodeURIComponent` rather than a
|
|
94
|
+
* `TextEncoder`: this runs while the module loads, and a runtime without `TextEncoder` (older React
|
|
95
|
+
* Native engines) must still be able to import the client. A lone surrogate, which has no UTF-8
|
|
96
|
+
* spelling, yields no bytes, and `namePattern` then matches that character only as written.
|
|
97
|
+
*/
|
|
98
|
+
const utf8Bytes = (char) => {
|
|
99
|
+
const code = char.charCodeAt(0);
|
|
100
|
+
if (char.length === 1 && code < 0x80)
|
|
101
|
+
return [code];
|
|
102
|
+
try {
|
|
103
|
+
return encodeURIComponent(char)
|
|
104
|
+
.split('%')
|
|
105
|
+
.slice(1)
|
|
106
|
+
.map((hex) => parseInt(hex, 16));
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* A pattern matching one credential query name in every spelling a URL can carry it in: each
|
|
114
|
+
* character as written or percent-encoded (its UTF-8 bytes, at any depth and in either hex case),
|
|
115
|
+
* and a space also as `+`. `redactUrl` decodes a top-level name before it compares, so this keeps
|
|
116
|
+
* a nested name, which nothing decodes, from slipping past with one of its bytes escaped
|
|
117
|
+
* (`api%5Fkey`). Only the hex ignores case, not the name.
|
|
118
|
+
*/
|
|
119
|
+
const namePattern = (name) => [...name]
|
|
120
|
+
.map((char) => {
|
|
121
|
+
// Only syntax characters: the pattern is compiled with the `u` flag, under which escaping
|
|
122
|
+
// anything else (`\-`) is a syntax error rather than a no-op.
|
|
123
|
+
const escaped = char.replace(/[.*+?^${}()|[\]\\/]/gu, '\\$&');
|
|
124
|
+
const encoded = utf8Bytes(char).map(encodedBytePattern).join('');
|
|
125
|
+
// A lone surrogate has no bytes to encode; an empty alternative would make it optional.
|
|
126
|
+
if (encoded === '')
|
|
127
|
+
return `(?:${escaped})`;
|
|
128
|
+
return `(?:${escaped}|${encoded}${char === ' ' ? '|\\+' : ''})`;
|
|
129
|
+
})
|
|
130
|
+
.join('');
|
|
131
|
+
/**
|
|
132
|
+
* Matches a credential query parameter wherever text carries one, nested or not, with the name,
|
|
133
|
+
* separator and `=` in group 1 and the value after it. `undefined` when this SDK places no
|
|
134
|
+
* credential in the query.
|
|
135
|
+
*
|
|
136
|
+
* A name counts after a separator, `?`, `&` or `;`, either literal or percent-encoded any number of
|
|
137
|
+
* times over (`%3F`, `%253F`): a server can echo a whole URL encoded inside another parameter's
|
|
138
|
+
* value, as a login redirect's `return_to` does, and splitting the outer query on `&` never looks
|
|
139
|
+
* inside it. `;` also counts because an HTML-escaped `&` reads `&`. The `=` after the name can
|
|
140
|
+
* be encoded the same way. The value then runs to the next literal `&`, `#` or whitespace: an
|
|
141
|
+
* encoded `%26` may end a nested value, but stopping there would leak the rest of one a sloppy
|
|
142
|
+
* encoder left half-encoded, and masking too much is harmless. `<`, `>` and `"` end it too, since
|
|
143
|
+
* no valid URL carries them unencoded, so a `Link` header's `<url>` or a quoted URL keeps its
|
|
144
|
+
* closing delimiter. `'` does not: a query value can hold it raw. No quantifier nests inside
|
|
145
|
+
* another, so matching stays linear on hostile input.
|
|
146
|
+
*/
|
|
147
|
+
const QUERY_CREDENTIAL = (() => {
|
|
148
|
+
// An empty name would build a pattern that masks every `?=`.
|
|
149
|
+
const names = REDACTED_QUERY_PARAMS.filter((name) => name !== '').map(namePattern);
|
|
150
|
+
if (names.length === 0)
|
|
151
|
+
return undefined;
|
|
152
|
+
// `\u0026` is `&` as a JSON string escapes it, which Go's `encoding/json` does by default, so a
|
|
153
|
+
// URL quoted in JSON text (a header value, a non-JSON error body quoting one) carries its
|
|
154
|
+
// separators that way.
|
|
155
|
+
const separator = `(?:[?&;]|\\\\u0026|${[0x3f, 0x26, 0x3b].map(encodedBytePattern).join('|')})`;
|
|
156
|
+
const equals = `(?:=|${encodedBytePattern(0x3d)})`;
|
|
157
|
+
return new RegExp(`(${separator}(?:${names.join('|')})${equals})[^&#\\s<>"]*`, 'gu');
|
|
158
|
+
})();
|
|
159
|
+
/** Masks the value of every credential query parameter in `text`, nested and encoded ones included. */
|
|
160
|
+
const redactQueryCredentials = (text) => QUERY_CREDENTIAL === undefined ? text : text.replace(QUERY_CREDENTIAL, `$1${REDACTED}`);
|
|
83
161
|
/**
|
|
84
162
|
* Blanks the userinfo of a URL, which is a credential wherever it appears.
|
|
85
163
|
*
|
|
@@ -129,8 +207,10 @@ export const redactUrl = (url) => {
|
|
|
129
207
|
if (REDACTED_QUERY_PARAMS.length === 0)
|
|
130
208
|
return url_;
|
|
131
209
|
const mark = url_.indexOf('?');
|
|
210
|
+
// A path can nest an encoded URL too (`/proxy/https%3A%2F%2Fh%2Fv1%3Fapi_key%3D…`), and so can a
|
|
211
|
+
// fragment, so the text outside the query is scanned for a nested credential as well.
|
|
132
212
|
if (mark === -1)
|
|
133
|
-
return url_;
|
|
213
|
+
return redactQueryCredentials(url_);
|
|
134
214
|
// A fragment is not part of the query, so splitting it off keeps it out of the rewrite.
|
|
135
215
|
const fragment = url_.indexOf('#', mark);
|
|
136
216
|
const end = fragment === -1 ? url_.length : fragment;
|
|
@@ -144,14 +224,19 @@ export const redactUrl = (url) => {
|
|
|
144
224
|
.split('&')
|
|
145
225
|
.map((pair) => {
|
|
146
226
|
const equals = pair.indexOf('=');
|
|
147
|
-
// A parameter with no `=` carries no value,
|
|
227
|
+
// A parameter with no `=` carries no value of its own, but it can still be a whole encoded URL
|
|
228
|
+
// (`?%2Fv1%3Fapi_key%3D…`), so it is scanned for a nested credential like any other value.
|
|
148
229
|
if (equals === -1)
|
|
149
|
-
return pair;
|
|
230
|
+
return redactQueryCredentials(pair);
|
|
150
231
|
const name = pair.slice(0, equals);
|
|
151
|
-
|
|
232
|
+
// Any other value still goes through `redactQueryCredentials`: it can nest a whole encoded URL
|
|
233
|
+
// that carries a credential, as a redirect target echoing the request in `return_to` does.
|
|
234
|
+
return REDACTED_QUERY_PARAMS.includes(decodeQueryName(name))
|
|
235
|
+
? name + '=' + REDACTED
|
|
236
|
+
: redactQueryCredentials(pair);
|
|
152
237
|
})
|
|
153
238
|
.join('&');
|
|
154
|
-
return url_.slice(0, mark +
|
|
239
|
+
return redactQueryCredentials(url_.slice(0, mark)) + '?' + query + redactQueryCredentials(url_.slice(end));
|
|
155
240
|
};
|
|
156
241
|
/**
|
|
157
242
|
* Replaces credential values in a caller-supplied query object.
|
|
@@ -161,29 +246,48 @@ export const redactUrl = (url) => {
|
|
|
161
246
|
*/
|
|
162
247
|
const redactQuery = (query) => {
|
|
163
248
|
const redacted = { ...query };
|
|
249
|
+
for (const [name, value] of Object.entries(redacted)) {
|
|
250
|
+
// Every other string value is cleaned as text: an operation parameter such as `return_to` can
|
|
251
|
+
// hold a URL that carries the credential, and the URL logged beside this masks it there.
|
|
252
|
+
if (typeof value === 'string')
|
|
253
|
+
redacted[name] = redactText(value);
|
|
254
|
+
else if (Array.isArray(value)) {
|
|
255
|
+
redacted[name] = value.map((item) => (typeof item === 'string' ? redactText(item) : item));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
164
258
|
for (const name of REDACTED_QUERY_PARAMS) {
|
|
165
259
|
if (hasOwn(redacted, name))
|
|
166
260
|
redacted[name] = REDACTED;
|
|
167
261
|
}
|
|
168
262
|
return redacted;
|
|
169
263
|
};
|
|
170
|
-
/**
|
|
264
|
+
/**
|
|
265
|
+
* Replaces the value of every credential-bearing header, for a `Headers` or a plain record alike.
|
|
266
|
+
*
|
|
267
|
+
* Every other value is cleaned as free text: a response can echo the request URL back, in a
|
|
268
|
+
* `Location` or a `Link`, either as written or nested and encoded in a `return_to`, and a header's
|
|
269
|
+
* name says nothing about whether its value quotes a credential.
|
|
270
|
+
*/
|
|
171
271
|
export const redactHeaders = (headers) => Object.fromEntries((headers instanceof Headers ? [...headers] : Object.entries(headers)).map(([name, value]) => [
|
|
172
272
|
name,
|
|
173
|
-
REDACTED_HEADERS.has(name.toLowerCase()) ? REDACTED : value,
|
|
273
|
+
REDACTED_HEADERS.has(name.toLowerCase()) ? REDACTED : redactText(value),
|
|
174
274
|
]));
|
|
175
|
-
/**
|
|
275
|
+
/**
|
|
276
|
+
* URL-shaped runs inside free text, for their userinfo. Whitespace, quotes, `<` and `>` end one, so
|
|
277
|
+
* two quoted URLs side by side stay two matches, each with its own userinfo masked, and an `@`
|
|
278
|
+
* further on in the text is not taken for one.
|
|
279
|
+
*/
|
|
176
280
|
const URL_IN_TEXT = /\bhttps?:\/\/[^\s"'<>]+/gu;
|
|
177
281
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* Trimmed back after the match instead of being excluded from it, because an IPv6 host carries its
|
|
181
|
-
* own `]` (`http://[::1]:8080/p?api_key=…`). Excluding the character cut the match short at the
|
|
182
|
-
* host and left the query — credential included — in the text.
|
|
282
|
+
* Text that cannot hold a URL credential: no query separator (literal, encoded or JSON-escaped), no
|
|
283
|
+
* `%` escape, no scheme.
|
|
183
284
|
*/
|
|
184
|
-
const
|
|
285
|
+
const NO_URL_CREDENTIAL = /^[^?&;%:\\]*$/u;
|
|
185
286
|
/**
|
|
186
|
-
* Redacts
|
|
287
|
+
* Redacts free text that may quote a URL anywhere in it: the userinfo of every absolute URL, then
|
|
288
|
+
* every credential query parameter anywhere in the text, which covers an absolute URL's own query,
|
|
289
|
+
* a relative URL (a `Location` of `/login?api_key=…`) and one nested, encoded, inside another
|
|
290
|
+
* parameter's value alike.
|
|
187
291
|
*
|
|
188
292
|
* Runs for every SDK, not only those with a query credential: Node's `fetch` rejects a URL carrying
|
|
189
293
|
* userinfo with a message that quotes the whole URL back (`Request cannot be constructed from a URL
|
|
@@ -191,14 +295,52 @@ const TRAILING_PUNCTUATION = /[.,;:!?)\]}]+$/u;
|
|
|
191
295
|
* this on the query list left the password in the log for every SDK whose document happens not to
|
|
192
296
|
* put a credential in the query.
|
|
193
297
|
*
|
|
194
|
-
* Only the
|
|
195
|
-
* handing one to `URLSearchParams` wholesale would swallow everything after
|
|
196
|
-
* take the diagnostic with it.
|
|
298
|
+
* Only the userinfo and the credential values are rewritten, never the whole string: a message is
|
|
299
|
+
* not a query string, and handing one to `URLSearchParams` wholesale would swallow everything after
|
|
300
|
+
* the first parameter and take the diagnostic with it. The query scan runs over the whole text in one
|
|
301
|
+
* pass rather than URL by URL, because where a URL ends in prose is a guess and a credential value
|
|
302
|
+
* can hold a raw `'` or end in punctuation: a masked value runs to the next whitespace, `&`, `#`,
|
|
303
|
+
* `<`, `>` or `"`, so punctuation right after it (`(https://h/v1?api_key=***): error`) goes with it.
|
|
304
|
+
* Text with none of the characters a credential needs is returned as is, since header values pass
|
|
305
|
+
* through here on every request whether or not anything logs them.
|
|
197
306
|
*/
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
307
|
+
const redactText = (text) => NO_URL_CREDENTIAL.test(text) ? text : redactQueryCredentials(text.replace(URL_IN_TEXT, redactUserinfo));
|
|
308
|
+
/**
|
|
309
|
+
* What a log line says about a request or response body: its kind and size, never its content.
|
|
310
|
+
*
|
|
311
|
+
* A body is the data an API exists to move — a token endpoint's answer, a customer's records — and
|
|
312
|
+
* no list of field names can tell which parts of it are secret, while a debug log ends up in CI
|
|
313
|
+
* output and support tickets. The response's `content-type` is logged with its headers beside this.
|
|
314
|
+
*/
|
|
315
|
+
const describeBody = (body) => {
|
|
316
|
+
if (body === null)
|
|
317
|
+
return '[empty body]';
|
|
318
|
+
if (typeof body === 'string')
|
|
319
|
+
return `[text body: ${body.length} characters]`;
|
|
320
|
+
if (body instanceof ArrayBuffer)
|
|
321
|
+
return `[binary body: ${body.byteLength} bytes]`;
|
|
322
|
+
if (ArrayBuffer.isView(body))
|
|
323
|
+
return `[binary body: ${body.byteLength} bytes]`;
|
|
324
|
+
const BlobClass = globalThis.Blob;
|
|
325
|
+
if (BlobClass && body instanceof BlobClass) {
|
|
326
|
+
return `[binary body: ${body.size} bytes${body.type ? `, ${body.type}` : ''}]`;
|
|
327
|
+
}
|
|
328
|
+
if (typeof body === 'object') {
|
|
329
|
+
// Plain data first: a parsed JSON body is a plain object or array, and its own `constructor` key
|
|
330
|
+
// is server text, so the class name is read only off an object that is neither.
|
|
331
|
+
const proto = Object.getPrototypeOf(body);
|
|
332
|
+
if (!Array.isArray(body) && proto !== Object.prototype && proto !== null) {
|
|
333
|
+
const name = proto.constructor?.name;
|
|
334
|
+
return typeof name === 'string' && name ? `[${name} body]` : '[object body]';
|
|
335
|
+
}
|
|
336
|
+
// Its shape rather than its serialized length: this runs on every parsed response whether or
|
|
337
|
+
// not debug logging is on, and serializing a large body just to measure it would cost each call.
|
|
338
|
+
if (Array.isArray(body))
|
|
339
|
+
return `[JSON body: array of ${body.length} items]`;
|
|
340
|
+
return `[JSON body: object with ${Object.keys(body).length} keys]`;
|
|
341
|
+
}
|
|
342
|
+
return `[${typeof body} body]`;
|
|
343
|
+
};
|
|
202
344
|
export const formatRequestDetails = (details) => {
|
|
203
345
|
if (details.options) {
|
|
204
346
|
// Swept through a record view rather than field by field: not every field below is declared on
|
|
@@ -220,6 +362,8 @@ export const formatRequestDetails = (details) => {
|
|
|
220
362
|
const query = options['query'];
|
|
221
363
|
if (query && typeof query === 'object')
|
|
222
364
|
options['query'] = redactQuery(query);
|
|
365
|
+
if (options['body'] !== undefined)
|
|
366
|
+
options['body'] = describeBody(options['body']);
|
|
223
367
|
// These three are URL strings, not route fragments: `buildURL` takes an absolute `path` whole --
|
|
224
368
|
// userinfo, query string and all -- while `defaultBaseURL` and the Speakeasy profile's
|
|
225
369
|
// `serverURL` each replace the base URL outright. The caller-supplied escape hatches therefore
|
|
@@ -235,6 +379,9 @@ export const formatRequestDetails = (details) => {
|
|
|
235
379
|
}
|
|
236
380
|
details.options = options;
|
|
237
381
|
}
|
|
382
|
+
if (details.body !== undefined) {
|
|
383
|
+
details.body = describeBody(details.body);
|
|
384
|
+
}
|
|
238
385
|
if (details.url) {
|
|
239
386
|
details.url = redactUrl(details.url);
|
|
240
387
|
}
|
|
@@ -245,7 +392,7 @@ export const formatRequestDetails = (details) => {
|
|
|
245
392
|
// request URL inside their text (see the note at the `connection failed` call sites), so a query
|
|
246
393
|
// credential rides along in a field none of the checks above look at.
|
|
247
394
|
if (typeof details.message === 'string') {
|
|
248
|
-
details.message =
|
|
395
|
+
details.message = redactText(details.message);
|
|
249
396
|
}
|
|
250
397
|
if ('retryOfRequestLogID' in details) {
|
|
251
398
|
if (details.retryOfRequestLogID) {
|