@credal/sdk 0.1.10 → 0.1.12

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 (76) hide show
  1. package/dist/cjs/BaseClient.d.ts +6 -1
  2. package/dist/cjs/BaseClient.js +47 -0
  3. package/dist/cjs/Client.d.ts +16 -16
  4. package/dist/cjs/Client.js +8 -49
  5. package/dist/cjs/api/resources/copilots/client/Client.d.ts +21 -21
  6. package/dist/cjs/api/resources/copilots/client/Client.js +41 -22
  7. package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +12 -12
  8. package/dist/cjs/api/resources/documentCatalog/client/Client.js +22 -13
  9. package/dist/cjs/api/resources/documentCollections/client/Client.d.ts +18 -18
  10. package/dist/cjs/api/resources/documentCollections/client/Client.js +34 -19
  11. package/dist/cjs/api/resources/search/client/Client.d.ts +6 -6
  12. package/dist/cjs/api/resources/search/client/Client.js +10 -7
  13. package/dist/cjs/api/resources/users/client/Client.d.ts +6 -6
  14. package/dist/cjs/api/resources/users/client/Client.js +10 -7
  15. package/dist/cjs/core/exports.d.ts +1 -0
  16. package/dist/cjs/core/exports.js +1 -0
  17. package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -1
  18. package/dist/cjs/core/fetcher/Fetcher.js +202 -9
  19. package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
  20. package/dist/cjs/core/fetcher/getRequestBody.js +4 -0
  21. package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
  22. package/dist/cjs/core/fetcher/makeRequest.js +0 -2
  23. package/dist/cjs/core/fetcher/requestWithRetries.js +0 -9
  24. package/dist/cjs/core/fetcher/signals.d.ts +0 -6
  25. package/dist/cjs/core/fetcher/signals.js +0 -12
  26. package/dist/cjs/core/headers.js +6 -4
  27. package/dist/cjs/core/index.d.ts +1 -0
  28. package/dist/cjs/core/index.js +2 -1
  29. package/dist/cjs/core/logging/exports.d.ts +18 -0
  30. package/dist/cjs/core/logging/exports.js +45 -0
  31. package/dist/cjs/core/logging/index.d.ts +1 -0
  32. package/dist/cjs/core/logging/index.js +17 -0
  33. package/dist/cjs/core/logging/logger.d.ts +126 -0
  34. package/dist/cjs/core/logging/logger.js +144 -0
  35. package/dist/cjs/core/url/join.js +0 -1
  36. package/dist/cjs/version.d.ts +1 -1
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/esm/BaseClient.d.mts +6 -1
  39. package/dist/esm/BaseClient.mjs +13 -1
  40. package/dist/esm/Client.d.mts +16 -16
  41. package/dist/esm/Client.mjs +13 -21
  42. package/dist/esm/api/resources/copilots/client/Client.d.mts +21 -21
  43. package/dist/esm/api/resources/copilots/client/Client.mjs +39 -20
  44. package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +12 -12
  45. package/dist/esm/api/resources/documentCatalog/client/Client.mjs +20 -11
  46. package/dist/esm/api/resources/documentCollections/client/Client.d.mts +18 -18
  47. package/dist/esm/api/resources/documentCollections/client/Client.mjs +32 -17
  48. package/dist/esm/api/resources/search/client/Client.d.mts +6 -6
  49. package/dist/esm/api/resources/search/client/Client.mjs +8 -5
  50. package/dist/esm/api/resources/users/client/Client.d.mts +6 -6
  51. package/dist/esm/api/resources/users/client/Client.mjs +8 -5
  52. package/dist/esm/core/exports.d.mts +1 -0
  53. package/dist/esm/core/exports.mjs +1 -0
  54. package/dist/esm/core/fetcher/Fetcher.d.mts +4 -1
  55. package/dist/esm/core/fetcher/Fetcher.mjs +202 -9
  56. package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
  57. package/dist/esm/core/fetcher/getRequestBody.mjs +4 -0
  58. package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
  59. package/dist/esm/core/fetcher/makeRequest.mjs +0 -2
  60. package/dist/esm/core/fetcher/requestWithRetries.mjs +0 -9
  61. package/dist/esm/core/fetcher/signals.d.mts +0 -6
  62. package/dist/esm/core/fetcher/signals.mjs +0 -12
  63. package/dist/esm/core/headers.mjs +6 -4
  64. package/dist/esm/core/index.d.mts +1 -0
  65. package/dist/esm/core/index.mjs +1 -0
  66. package/dist/esm/core/logging/exports.d.mts +18 -0
  67. package/dist/esm/core/logging/exports.mjs +9 -0
  68. package/dist/esm/core/logging/index.d.mts +1 -0
  69. package/dist/esm/core/logging/index.mjs +1 -0
  70. package/dist/esm/core/logging/logger.d.mts +126 -0
  71. package/dist/esm/core/logging/logger.mjs +138 -0
  72. package/dist/esm/core/url/join.mjs +0 -1
  73. package/dist/esm/version.d.mts +1 -1
  74. package/dist/esm/version.mjs +1 -1
  75. package/package.json +3 -2
  76. package/reference.md +21 -21
@@ -8,21 +8,153 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { toJson } from "../json.mjs";
11
+ import { createLogger } from "../logging/logger.mjs";
11
12
  import { createRequestUrl } from "./createRequestUrl.mjs";
12
13
  import { EndpointSupplier } from "./EndpointSupplier.mjs";
13
14
  import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
14
15
  import { getFetchFn } from "./getFetchFn.mjs";
15
16
  import { getRequestBody } from "./getRequestBody.mjs";
16
17
  import { getResponseBody } from "./getResponseBody.mjs";
18
+ import { Headers } from "./Headers.mjs";
17
19
  import { makeRequest } from "./makeRequest.mjs";
18
20
  import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
19
21
  import { requestWithRetries } from "./requestWithRetries.mjs";
22
+ const SENSITIVE_HEADERS = new Set([
23
+ "authorization",
24
+ "www-authenticate",
25
+ "x-api-key",
26
+ "api-key",
27
+ "apikey",
28
+ "x-api-token",
29
+ "x-auth-token",
30
+ "auth-token",
31
+ "cookie",
32
+ "set-cookie",
33
+ "proxy-authorization",
34
+ "proxy-authenticate",
35
+ "x-csrf-token",
36
+ "x-xsrf-token",
37
+ "x-session-token",
38
+ "x-access-token",
39
+ ]);
40
+ function redactHeaders(headers) {
41
+ const filtered = {};
42
+ for (const [key, value] of headers instanceof Headers ? headers.entries() : Object.entries(headers)) {
43
+ if (SENSITIVE_HEADERS.has(key.toLowerCase())) {
44
+ filtered[key] = "[REDACTED]";
45
+ }
46
+ else {
47
+ filtered[key] = value;
48
+ }
49
+ }
50
+ return filtered;
51
+ }
52
+ const SENSITIVE_QUERY_PARAMS = new Set([
53
+ "api_key",
54
+ "api-key",
55
+ "apikey",
56
+ "token",
57
+ "access_token",
58
+ "access-token",
59
+ "auth_token",
60
+ "auth-token",
61
+ "password",
62
+ "passwd",
63
+ "secret",
64
+ "api_secret",
65
+ "api-secret",
66
+ "apisecret",
67
+ "key",
68
+ "session",
69
+ "session_id",
70
+ "session-id",
71
+ ]);
72
+ function redactQueryParameters(queryParameters) {
73
+ if (queryParameters == null) {
74
+ return queryParameters;
75
+ }
76
+ const redacted = {};
77
+ for (const [key, value] of Object.entries(queryParameters)) {
78
+ if (SENSITIVE_QUERY_PARAMS.has(key.toLowerCase())) {
79
+ redacted[key] = "[REDACTED]";
80
+ }
81
+ else {
82
+ redacted[key] = value;
83
+ }
84
+ }
85
+ return redacted;
86
+ }
87
+ function redactUrl(url) {
88
+ const protocolIndex = url.indexOf("://");
89
+ if (protocolIndex === -1)
90
+ return url;
91
+ const afterProtocol = protocolIndex + 3;
92
+ // Find the first delimiter that marks the end of the authority section
93
+ const pathStart = url.indexOf("/", afterProtocol);
94
+ let queryStart = url.indexOf("?", afterProtocol);
95
+ let fragmentStart = url.indexOf("#", afterProtocol);
96
+ const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
97
+ // Find the LAST @ before the delimiter (handles multiple @ in credentials)
98
+ let atIndex = -1;
99
+ for (let i = afterProtocol; i < firstDelimiter; i++) {
100
+ if (url[i] === "@") {
101
+ atIndex = i;
102
+ }
103
+ }
104
+ if (atIndex !== -1) {
105
+ url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
106
+ }
107
+ // Recalculate queryStart since url might have changed
108
+ queryStart = url.indexOf("?");
109
+ if (queryStart === -1)
110
+ return url;
111
+ fragmentStart = url.indexOf("#", queryStart);
112
+ const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
113
+ const queryString = url.slice(queryStart + 1, queryEnd);
114
+ if (queryString.length === 0)
115
+ return url;
116
+ // FAST PATH: Quick check if any sensitive keywords present
117
+ // Using indexOf is faster than regex for simple substring matching
118
+ const lower = queryString.toLowerCase();
119
+ const hasSensitive = lower.includes("token") ||
120
+ lower.includes("key") ||
121
+ lower.includes("password") ||
122
+ lower.includes("passwd") ||
123
+ lower.includes("secret") ||
124
+ lower.includes("session") ||
125
+ lower.includes("auth");
126
+ if (!hasSensitive) {
127
+ return url;
128
+ }
129
+ // SLOW PATH: Parse and redact
130
+ const redactedParams = [];
131
+ const params = queryString.split("&");
132
+ for (const param of params) {
133
+ const equalIndex = param.indexOf("=");
134
+ if (equalIndex === -1) {
135
+ redactedParams.push(param);
136
+ continue;
137
+ }
138
+ const key = param.slice(0, equalIndex);
139
+ let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
140
+ if (!shouldRedact && key.includes("%")) {
141
+ try {
142
+ const decodedKey = decodeURIComponent(key);
143
+ shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
144
+ }
145
+ catch (_a) { }
146
+ }
147
+ redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
148
+ }
149
+ return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
150
+ }
20
151
  function getHeaders(args) {
21
152
  return __awaiter(this, void 0, void 0, function* () {
22
153
  var _a;
23
- const newHeaders = {};
154
+ const newHeaders = new Headers();
155
+ newHeaders.set("Accept", args.responseType === "json" ? "application/json" : args.responseType === "text" ? "text/plain" : "*/*");
24
156
  if (args.body !== undefined && args.contentType != null) {
25
- newHeaders["Content-Type"] = args.contentType;
157
+ newHeaders.set("Content-Type", args.contentType);
26
158
  }
27
159
  if (args.headers == null) {
28
160
  return newHeaders;
@@ -30,31 +162,52 @@ function getHeaders(args) {
30
162
  for (const [key, value] of Object.entries(args.headers)) {
31
163
  const result = yield EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
32
164
  if (typeof result === "string") {
33
- newHeaders[key] = result;
165
+ newHeaders.set(key, result);
34
166
  continue;
35
167
  }
36
168
  if (result == null) {
37
169
  continue;
38
170
  }
39
- newHeaders[key] = `${result}`;
171
+ newHeaders.set(key, `${result}`);
40
172
  }
41
173
  return newHeaders;
42
174
  });
43
175
  }
44
176
  export function fetcherImpl(args) {
45
177
  return __awaiter(this, void 0, void 0, function* () {
46
- var _a;
178
+ var _a, _b, _c;
47
179
  const url = createRequestUrl(args.url, args.queryParameters);
48
180
  const requestBody = yield getRequestBody({
49
181
  body: args.body,
50
- type: args.requestType === "json" ? "json" : "other",
182
+ type: (_a = args.requestType) !== null && _a !== void 0 ? _a : "other",
51
183
  });
52
- const fetchFn = yield getFetchFn();
184
+ const fetchFn = (_b = args.fetchFn) !== null && _b !== void 0 ? _b : (yield getFetchFn());
185
+ const headers = yield getHeaders(args);
186
+ const logger = createLogger(args.logging);
187
+ if (logger.isDebug()) {
188
+ const metadata = {
189
+ method: args.method,
190
+ url: redactUrl(url),
191
+ headers: redactHeaders(headers),
192
+ queryParameters: redactQueryParameters(args.queryParameters),
193
+ hasBody: requestBody != null,
194
+ };
195
+ logger.debug("Making HTTP request", metadata);
196
+ }
53
197
  try {
54
198
  const response = yield requestWithRetries(() => __awaiter(this, void 0, void 0, function* () {
55
- return makeRequest(fetchFn, url, args.method, yield getHeaders(args), requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
199
+ return makeRequest(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
56
200
  }), args.maxRetries);
57
201
  if (response.status >= 200 && response.status < 400) {
202
+ if (logger.isDebug()) {
203
+ const metadata = {
204
+ method: args.method,
205
+ url: redactUrl(url),
206
+ statusCode: response.status,
207
+ responseHeaders: redactHeaders(response.headers),
208
+ };
209
+ logger.debug("HTTP request succeeded", metadata);
210
+ }
58
211
  return {
59
212
  ok: true,
60
213
  body: (yield getResponseBody(response, args.responseType)),
@@ -63,6 +216,15 @@ export function fetcherImpl(args) {
63
216
  };
64
217
  }
65
218
  else {
219
+ if (logger.isError()) {
220
+ const metadata = {
221
+ method: args.method,
222
+ url: redactUrl(url),
223
+ statusCode: response.status,
224
+ responseHeaders: redactHeaders(Object.fromEntries(response.headers.entries())),
225
+ };
226
+ logger.error("HTTP request failed with error status", metadata);
227
+ }
66
228
  return {
67
229
  ok: false,
68
230
  error: {
@@ -75,7 +237,14 @@ export function fetcherImpl(args) {
75
237
  }
76
238
  }
77
239
  catch (error) {
78
- if ((_a = args.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
240
+ if ((_c = args.abortSignal) === null || _c === void 0 ? void 0 : _c.aborted) {
241
+ if (logger.isError()) {
242
+ const metadata = {
243
+ method: args.method,
244
+ url: redactUrl(url),
245
+ };
246
+ logger.error("HTTP request was aborted", metadata);
247
+ }
79
248
  return {
80
249
  ok: false,
81
250
  error: {
@@ -86,6 +255,14 @@ export function fetcherImpl(args) {
86
255
  };
87
256
  }
88
257
  else if (error instanceof Error && error.name === "AbortError") {
258
+ if (logger.isError()) {
259
+ const metadata = {
260
+ method: args.method,
261
+ url: redactUrl(url),
262
+ timeoutMs: args.timeoutMs,
263
+ };
264
+ logger.error("HTTP request timed out", metadata);
265
+ }
89
266
  return {
90
267
  ok: false,
91
268
  error: {
@@ -95,6 +272,14 @@ export function fetcherImpl(args) {
95
272
  };
96
273
  }
97
274
  else if (error instanceof Error) {
275
+ if (logger.isError()) {
276
+ const metadata = {
277
+ method: args.method,
278
+ url: redactUrl(url),
279
+ errorMessage: error.message,
280
+ };
281
+ logger.error("HTTP request failed with error", metadata);
282
+ }
98
283
  return {
99
284
  ok: false,
100
285
  error: {
@@ -104,6 +289,14 @@ export function fetcherImpl(args) {
104
289
  rawResponse: unknownRawResponse,
105
290
  };
106
291
  }
292
+ if (logger.isError()) {
293
+ const metadata = {
294
+ method: args.method,
295
+ url: redactUrl(url),
296
+ error: toJson(error),
297
+ };
298
+ logger.error("HTTP request failed with unknown error", metadata);
299
+ }
107
300
  return {
108
301
  ok: false,
109
302
  error: {
@@ -1,7 +1,7 @@
1
1
  export declare namespace GetRequestBody {
2
2
  interface Args {
3
3
  body: unknown;
4
- type: "json" | "file" | "bytes" | "other";
4
+ type: "json" | "file" | "bytes" | "form" | "other";
5
5
  }
6
6
  }
7
7
  export declare function getRequestBody({ body, type }: GetRequestBody.Args): Promise<BodyInit | undefined>;
@@ -8,8 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { toJson } from "../json.mjs";
11
+ import { toQueryString } from "../url/qs.mjs";
11
12
  export function getRequestBody(_a) {
12
13
  return __awaiter(this, arguments, void 0, function* ({ body, type }) {
14
+ if (type === "form") {
15
+ return toQueryString(body, { arrayFormat: "repeat", encode: true });
16
+ }
13
17
  if (type.includes("json")) {
14
18
  return toJson(body);
15
19
  }
@@ -1 +1 @@
1
- export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
1
+ export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Headers | Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
@@ -10,14 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { anySignal, getTimeoutSignal } from "./signals.mjs";
11
11
  export const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abortSignal, withCredentials, duplex) => __awaiter(void 0, void 0, void 0, function* () {
12
12
  const signals = [];
13
- // Add timeout signal
14
13
  let timeoutAbortId;
15
14
  if (timeoutMs != null) {
16
15
  const { signal, abortId } = getTimeoutSignal(timeoutMs);
17
16
  timeoutAbortId = abortId;
18
17
  signals.push(signal);
19
18
  }
20
- // Add arbitrary signal
21
19
  if (abortSignal != null) {
22
20
  signals.push(abortSignal);
23
21
  }
@@ -12,25 +12,20 @@ const MAX_RETRY_DELAY = 60000; // in milliseconds
12
12
  const DEFAULT_MAX_RETRIES = 2;
13
13
  const JITTER_FACTOR = 0.2; // 20% random jitter
14
14
  function addPositiveJitter(delay) {
15
- // Generate a random value between 0 and +JITTER_FACTOR
16
15
  const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
17
16
  return delay * jitterMultiplier;
18
17
  }
19
18
  function addSymmetricJitter(delay) {
20
- // Generate a random value in a JITTER_FACTOR-sized percentage range around delay
21
19
  const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
22
20
  return delay * jitterMultiplier;
23
21
  }
24
22
  function getRetryDelayFromHeaders(response, retryAttempt) {
25
- // Check for Retry-After header first (RFC 7231), with no jitter
26
23
  const retryAfter = response.headers.get("Retry-After");
27
24
  if (retryAfter) {
28
- // Parse as number of seconds...
29
25
  const retryAfterSeconds = parseInt(retryAfter, 10);
30
26
  if (!Number.isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
31
27
  return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
32
28
  }
33
- // ...or as an HTTP date; both are valid
34
29
  const retryAfterDate = new Date(retryAfter);
35
30
  if (!Number.isNaN(retryAfterDate.getTime())) {
36
31
  const delay = retryAfterDate.getTime() - Date.now();
@@ -39,19 +34,16 @@ function getRetryDelayFromHeaders(response, retryAttempt) {
39
34
  }
40
35
  }
41
36
  }
42
- // Then check for industry-standard X-RateLimit-Reset header, with positive jitter
43
37
  const rateLimitReset = response.headers.get("X-RateLimit-Reset");
44
38
  if (rateLimitReset) {
45
39
  const resetTime = parseInt(rateLimitReset, 10);
46
40
  if (!Number.isNaN(resetTime)) {
47
- // Assume Unix timestamp in epoch seconds
48
41
  const delay = resetTime * 1000 - Date.now();
49
42
  if (delay > 0) {
50
43
  return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
51
44
  }
52
45
  }
53
46
  }
54
- // Fall back to exponential backoff, with symmetric jitter
55
47
  return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
56
48
  }
57
49
  export function requestWithRetries(requestFn_1) {
@@ -59,7 +51,6 @@ export function requestWithRetries(requestFn_1) {
59
51
  let response = yield requestFn();
60
52
  for (let i = 0; i < maxRetries; ++i) {
61
53
  if ([408, 429].includes(response.status) || response.status >= 500) {
62
- // Get delay with appropriate jitter applied
63
54
  const delay = getRetryDelayFromHeaders(response, i);
64
55
  yield new Promise((resolve) => setTimeout(resolve, delay));
65
56
  response = yield requestFn();
@@ -2,10 +2,4 @@ export declare function getTimeoutSignal(timeoutMs: number): {
2
2
  signal: AbortSignal;
3
3
  abortId: NodeJS.Timeout;
4
4
  };
5
- /**
6
- * Returns an abort signal that is getting aborted when
7
- * at least one of the specified abort signals is aborted.
8
- *
9
- * Requires at least node.js 18.
10
- */
11
5
  export declare function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal;
@@ -4,26 +4,14 @@ export function getTimeoutSignal(timeoutMs) {
4
4
  const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
5
5
  return { signal: controller.signal, abortId };
6
6
  }
7
- /**
8
- * Returns an abort signal that is getting aborted when
9
- * at least one of the specified abort signals is aborted.
10
- *
11
- * Requires at least node.js 18.
12
- */
13
7
  export function anySignal(...args) {
14
- // Allowing signals to be passed either as array
15
- // of signals or as multiple arguments.
16
8
  const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args);
17
9
  const controller = new AbortController();
18
10
  for (const signal of signals) {
19
11
  if (signal.aborted) {
20
- // Exiting early if one of the signals
21
- // is already aborted.
22
12
  controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
23
13
  break;
24
14
  }
25
- // Listening for signals and removing the listeners
26
- // when at least one symbol is aborted.
27
15
  signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
28
16
  signal: controller.signal,
29
17
  });
@@ -3,11 +3,12 @@ export function mergeHeaders(...headersArray) {
3
3
  for (const [key, value] of headersArray
4
4
  .filter((headers) => headers != null)
5
5
  .flatMap((headers) => Object.entries(headers))) {
6
+ const insensitiveKey = key.toLowerCase();
6
7
  if (value != null) {
7
- result[key] = value;
8
+ result[insensitiveKey] = value;
8
9
  }
9
- else if (key in result) {
10
- delete result[key];
10
+ else if (insensitiveKey in result) {
11
+ delete result[insensitiveKey];
11
12
  }
12
13
  }
13
14
  return result;
@@ -17,8 +18,9 @@ export function mergeOnlyDefinedHeaders(...headersArray) {
17
18
  for (const [key, value] of headersArray
18
19
  .filter((headers) => headers != null)
19
20
  .flatMap((headers) => Object.entries(headers))) {
21
+ const insensitiveKey = key.toLowerCase();
20
22
  if (value != null) {
21
- result[key] = value;
23
+ result[insensitiveKey] = value;
22
24
  }
23
25
  }
24
26
  return result;
@@ -3,6 +3,7 @@ export * from "./base64.mjs";
3
3
  export * from "./fetcher/index.mjs";
4
4
  export * as file from "./file/index.mjs";
5
5
  export * from "./form-data-utils/index.mjs";
6
+ export * as logging from "./logging/index.mjs";
6
7
  export * from "./runtime/index.mjs";
7
8
  export * from "./stream/index.mjs";
8
9
  export * as url from "./url/index.mjs";
@@ -3,6 +3,7 @@ export * from "./base64.mjs";
3
3
  export * from "./fetcher/index.mjs";
4
4
  export * as file from "./file/index.mjs";
5
5
  export * from "./form-data-utils/index.mjs";
6
+ export * as logging from "./logging/index.mjs";
6
7
  export * from "./runtime/index.mjs";
7
8
  export * from "./stream/index.mjs";
8
9
  export * as url from "./url/index.mjs";
@@ -0,0 +1,18 @@
1
+ import * as logger from "./logger.mjs";
2
+ export declare namespace logging {
3
+ /**
4
+ * Configuration for logger instances.
5
+ */
6
+ type LogConfig = logger.LogConfig;
7
+ type LogLevel = logger.LogLevel;
8
+ const LogLevel: typeof logger.LogLevel;
9
+ type ILogger = logger.ILogger;
10
+ /**
11
+ * Console logger implementation that outputs to the console.
12
+ */
13
+ type ConsoleLogger = logger.ConsoleLogger;
14
+ /**
15
+ * Console logger implementation that outputs to the console.
16
+ */
17
+ const ConsoleLogger: typeof logger.ConsoleLogger;
18
+ }
@@ -0,0 +1,9 @@
1
+ import * as logger from "./logger.mjs";
2
+ export var logging;
3
+ (function (logging) {
4
+ logging.LogLevel = logger.LogLevel;
5
+ /**
6
+ * Console logger implementation that outputs to the console.
7
+ */
8
+ logging.ConsoleLogger = logger.ConsoleLogger;
9
+ })(logging || (logging = {}));
@@ -0,0 +1 @@
1
+ export * from "./logger.mjs";
@@ -0,0 +1 @@
1
+ export * from "./logger.mjs";
@@ -0,0 +1,126 @@
1
+ export declare const LogLevel: {
2
+ readonly Debug: "debug";
3
+ readonly Info: "info";
4
+ readonly Warn: "warn";
5
+ readonly Error: "error";
6
+ };
7
+ export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
8
+ export interface ILogger {
9
+ /**
10
+ * Logs a debug message.
11
+ * @param message - The message to log
12
+ * @param args - Additional arguments to log
13
+ */
14
+ debug(message: string, ...args: unknown[]): void;
15
+ /**
16
+ * Logs an info message.
17
+ * @param message - The message to log
18
+ * @param args - Additional arguments to log
19
+ */
20
+ info(message: string, ...args: unknown[]): void;
21
+ /**
22
+ * Logs a warning message.
23
+ * @param message - The message to log
24
+ * @param args - Additional arguments to log
25
+ */
26
+ warn(message: string, ...args: unknown[]): void;
27
+ /**
28
+ * Logs an error message.
29
+ * @param message - The message to log
30
+ * @param args - Additional arguments to log
31
+ */
32
+ error(message: string, ...args: unknown[]): void;
33
+ }
34
+ /**
35
+ * Configuration for logger initialization.
36
+ */
37
+ export interface LogConfig {
38
+ /**
39
+ * Minimum log level to output.
40
+ * @default LogLevel.Info
41
+ */
42
+ level?: LogLevel;
43
+ /**
44
+ * Logger implementation to use.
45
+ * @default new ConsoleLogger()
46
+ */
47
+ logger?: ILogger;
48
+ /**
49
+ * Whether logging should be silenced.
50
+ * @default true
51
+ */
52
+ silent?: boolean;
53
+ }
54
+ /**
55
+ * Default console-based logger implementation.
56
+ */
57
+ export declare class ConsoleLogger implements ILogger {
58
+ debug(message: string, ...args: unknown[]): void;
59
+ info(message: string, ...args: unknown[]): void;
60
+ warn(message: string, ...args: unknown[]): void;
61
+ error(message: string, ...args: unknown[]): void;
62
+ }
63
+ /**
64
+ * Logger class that provides level-based logging functionality.
65
+ */
66
+ export declare class Logger {
67
+ private readonly level;
68
+ private readonly logger;
69
+ private readonly silent;
70
+ /**
71
+ * Creates a new logger instance.
72
+ * @param config - Logger configuration
73
+ */
74
+ constructor(config: Required<LogConfig>);
75
+ /**
76
+ * Checks if a log level should be output based on configuration.
77
+ * @param level - The log level to check
78
+ * @returns True if the level should be logged
79
+ */
80
+ shouldLog(level: LogLevel): boolean;
81
+ /**
82
+ * Checks if debug logging is enabled.
83
+ * @returns True if debug logs should be output
84
+ */
85
+ isDebug(): boolean;
86
+ /**
87
+ * Logs a debug message if debug logging is enabled.
88
+ * @param message - The message to log
89
+ * @param args - Additional arguments to log
90
+ */
91
+ debug(message: string, ...args: unknown[]): void;
92
+ /**
93
+ * Checks if info logging is enabled.
94
+ * @returns True if info logs should be output
95
+ */
96
+ isInfo(): boolean;
97
+ /**
98
+ * Logs an info message if info logging is enabled.
99
+ * @param message - The message to log
100
+ * @param args - Additional arguments to log
101
+ */
102
+ info(message: string, ...args: unknown[]): void;
103
+ /**
104
+ * Checks if warning logging is enabled.
105
+ * @returns True if warning logs should be output
106
+ */
107
+ isWarn(): boolean;
108
+ /**
109
+ * Logs a warning message if warning logging is enabled.
110
+ * @param message - The message to log
111
+ * @param args - Additional arguments to log
112
+ */
113
+ warn(message: string, ...args: unknown[]): void;
114
+ /**
115
+ * Checks if error logging is enabled.
116
+ * @returns True if error logs should be output
117
+ */
118
+ isError(): boolean;
119
+ /**
120
+ * Logs an error message if error logging is enabled.
121
+ * @param message - The message to log
122
+ * @param args - Additional arguments to log
123
+ */
124
+ error(message: string, ...args: unknown[]): void;
125
+ }
126
+ export declare function createLogger(config?: LogConfig | Logger): Logger;