@passcod/faith 0.0.2 → 0.0.5

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/index.d.ts CHANGED
@@ -1,68 +1,519 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+ /**
4
+ * The `Agent` interface of the Fáith API represents an instance of an HTTP client. Each `Agent` has
5
+ * its own options, connection pool, caches, etc. There are also conveniences such as `headers` for
6
+ * setting default headers on all requests done with the agent, and statistics collected by the agent.
7
+ *
8
+ * Re-using connections between requests is a significant performance improvement: not only because
9
+ * the TCP and TLS handshake is only performed once across many different requests, but also because
10
+ * the DNS lookup doesn't need to occur for subsequent requests on the same connection. Depending on
11
+ * DNS technology (DoH and DoT add a whole separate handshake to the process) and overall latency,
12
+ * this can not only speed up requests on average, but also reduce system load.
13
+ *
14
+ * For this reason, and also because in browsers this behaviour is standard, **all** requests with
15
+ * Fáith use an `Agent`. For `fetch()` calls that don't specify one explicitly, a global agent with
16
+ * default options is created on first use.
17
+ *
18
+ * There are a lot more options that could be exposed here; if you want one, open an issue.
19
+ */
3
20
  export declare class Agent {
4
21
  constructor(options?: AgentOptions | undefined | null)
22
+ /**
23
+ * Add a cookie into the agent.
24
+ *
25
+ * Does nothing if:
26
+ * - the cookie store is disabled
27
+ * - the url is malformed
28
+ */
5
29
  addCookie(url: string, cookie: string): void
30
+ /**
31
+ * Retrieve a cookie from the store.
32
+ *
33
+ * Returns `null` if:
34
+ * - there's no cookie at this url
35
+ * - the cookie store is disabled
36
+ * - the url is malformed
37
+ * - the cookie cannot be represented as a string
38
+ */
6
39
  getCookie(url: string): string | null
40
+ /**
41
+ * Returns statistics gathered by this agent:
42
+ *
43
+ * - `requestsSent`
44
+ * - `responsesReceived`
45
+ * - `bodiesStarted`
46
+ * - `bodiesFinished`
47
+ */
7
48
  stats(): AgentStats
8
49
  }
9
50
 
10
51
  export declare class AgentStats {
11
52
  requestsSent: number
12
53
  responsesReceived: number
54
+ /**
55
+ * Number of response body streams that have been started (converted from raw body to stream).
56
+ * This happens when `.body`, `.text()`, `.json()`, `.bytes()`, or similar methods are called.
57
+ */
58
+ bodiesStarted: number
59
+ /**
60
+ * Number of response body streams that have been fully consumed.
61
+ * When `bodies_started - bodies_finished > 0`, there are bodies holding connections open.
62
+ */
63
+ bodiesFinished: number
13
64
  }
14
65
 
66
+ /**
67
+ * The `Response` interface of the Fetch API represents the response to a request.
68
+ *
69
+ * Fáith does not allow its `Response` object to be constructed. If you need to, you may use the
70
+ * `webResponse()` method to convert one into a Web API `Response` object; note the caveats.
71
+ */
15
72
  export declare class FaithResponse {
16
- get headers(): Array<[string, string]>
73
+ /**
74
+ * The `headers` read-only property of the `Response` interface contains the `Headers` object
75
+ * associated with the response.
76
+ *
77
+ * Note that Fáith does not provide a custom `Headers` class; instead the Web API `Headers` structure
78
+ * is used directly and constructed by Fáith when needed.
79
+ *
80
+ * This is a function as an internal implementation detail and the wrapper makes it a property.
81
+ */
82
+ headers(): Array<[string, string]>
83
+ /**
84
+ * The `ok` read-only property of the `Response` interface contains a boolean stating whether the
85
+ * response was successful (status in the range 200-299) or not.
86
+ */
17
87
  get ok(): boolean
18
- get redirected(): boolean
19
- get status(): number
20
- get statusText(): string
21
- get type(): string
22
- get url(): string
23
- get version(): string
24
- /** Check if the response body has been disturbed (read) */
25
- get bodyUsed(): boolean
26
- /** Get the response body as a ReadableStream */
27
- get body(): ReadableStream<Buffer> | null
28
88
  /**
29
- * Get response body as bytes
89
+ * Custom to Fáith.
90
+ *
91
+ * The `peer` read-only property of the `Response` interface contains an object with information about
92
+ * the remote peer that sent this response:
93
+ */
94
+ get peer(): { address?: string; certificate?: Buffer }
95
+ /**
96
+ * The `redirected` read-only property of the `Response` interface indicates whether or not the
97
+ * response is the result of a request you made which was redirected.
98
+ *
99
+ * Note that by the time you read this property, the redirect will already have happened, and you
100
+ * cannot prevent it by aborting the fetch at this point.
101
+ */
102
+ get redirected(): boolean
103
+ /**
104
+ * The `status` read-only property of the `Response` interface contains the HTTP status codes of the
105
+ * response. For example, 200 for success, 404 if the resource could not be found.
106
+ *
107
+ * A value is `0` is returned for a response whose `type` is `opaque`, `opaqueredirect`, or `error`.
108
+ */
109
+ get status(): number
110
+ /**
111
+ * The `statusText` read-only property of the `Response` interface contains the status message
112
+ * corresponding to the HTTP status code in `Response.status`. For example, this would be `OK` for a
113
+ * status code `200`, `Continue` for `100`, `Not Found` for `404`.
114
+ *
115
+ * In HTTP/1, servers can send custom status text. This is returned here. In HTTP/2 and HTTP/3, custom
116
+ * status text is not supported at all, and the `statusText` property is either empty or simulated
117
+ * from well-known status codes.
118
+ */
119
+ get statusText(): string
120
+ /**
121
+ * The `type` read-only property of the `Response` interface contains the type of the response. The
122
+ * type determines whether scripts are able to access the response body and headers.
123
+ *
124
+ * In Fáith, this is always set to `basic`.
125
+ */
126
+ get type(): string
127
+ /**
128
+ * The `url` read-only property of the `Response` interface contains the URL of the response. The
129
+ * value of the `url` property will be the final URL obtained after any redirects.
130
+ */
131
+ get url(): string
132
+ /**
133
+ * The `version` read-only property of the `Response` interface contains the HTTP version of the
134
+ * response. The value will be the final HTTP version after any redirects and protocol upgrades.
135
+ *
136
+ * This is custom to Fáith.
137
+ */
138
+ get version(): string
139
+ /**
140
+ * The `bodyUsed` read-only property of the `Response` interface is a boolean value that indicates
141
+ * whether the body has been read yet.
142
+ *
143
+ * In Fáith, this indicates whether the body stream has ever been read from or canceled, as defined
144
+ * [in the spec](https://streams.spec.whatwg.org/#is-readable-stream-disturbed). Note that accessing
145
+ * the `.body` property counts as a read, even if you don't actually consume any bytes of content.
146
+ */
147
+ get bodyUsed(): boolean
148
+ /**
149
+ * The `body` read-only property of the `Response` interface is a `ReadableStream` of the body
150
+ * contents, or `null` for any actual HTTP response that has no body, such as `HEAD` requests and
151
+ * `204 No Content` responses.
152
+ *
153
+ * Note that browsers currently do not return `null` for those responses, but the spec requires
154
+ * it. Fáith chooses to respect the spec rather than the browsers in this case.
155
+ *
156
+ * An important consideration exists in conjunction with the connection pool: if you start the
157
+ * body stream, this will hold the connection until the stream is fully consumed. If another
158
+ * request is started during that time, and you don't have an available connection in the pool
159
+ * for the host already, the new request will open one.
160
+ *
161
+ * Note that this is a function as an implementation detail; the wrapper makes it a property.
162
+ */
163
+ body(): ReadableStream<Buffer> | null
164
+ /**
165
+ * The `bytes()` method of the `Response` interface takes a `Response` stream and reads it to
166
+ * completion. It returns a promise that resolves with a `Uint8Array`.
167
+ *
168
+ * In Fáith, this returns a Node.js `Buffer`, which can be used as (and is a subclass of) a `Uint8Array`.
169
+ */
170
+ bytes(): Async<Buffer>
171
+ /**
172
+ * The `text()` method of the `Response` interface takes a `Response` stream and reads it to
173
+ * completion. It returns a promise that resolves with a `String`. The response is always decoded
174
+ * using UTF-8.
175
+ */
176
+ text(): Async<string>
177
+ /**
178
+ * The `json()` method of the `Response` interface takes a `Response` stream and reads it to
179
+ * completion. It returns a promise which resolves with the result of parsing the body text as
180
+ * `JSON`.
181
+ *
182
+ * Note that despite the method being named `json()`, the result is not JSON but is instead the
183
+ * result of taking JSON as input and parsing it to produce a JavaScript object.
184
+ *
185
+ * Further note that, at least in Fáith, this method first reads the entire response body as bytes,
186
+ * and then parses that as JSON. This can use up to double the amount of memory. If you need more
187
+ * efficient access, consider handling the response body as a stream.
188
+ */
189
+ json(): Async<any>
190
+ /**
191
+ * The `trailers()` read-only property of the `Response` interface returns a promise that
192
+ * resolves to either `null` or a `Headers` structure that contains the HTTP/2 or /3 trailing
193
+ * headers.
194
+ *
195
+ * This was once in the spec as a getter but was removed as it wasn't implemented by any browser.
196
+ *
197
+ * Note that this will never resolve if you don't also consume the body in some way.
198
+ *
199
+ * This is an async fn as an internal implementation detail and the wrapper makes it a property.
200
+ */
201
+ trailers(): Promise<Array<[string, string]> | null>
202
+ /**
203
+ * The `clone()` method of the `Response` interface creates a clone of a response object, identical
204
+ * in every way, but stored in a different variable.
205
+ *
206
+ * `clone()` throws an `Error` if the response body has already been used.
207
+ *
208
+ * (In-spec, this should throw a `TypeError`, but for technical reasons this is not possible with Fáith.)
209
+ */
210
+ clone(): FaithResponse
211
+ }
212
+
213
+ /** Settings related to the HTTP cache. This is a nested object. */
214
+ export interface AgentCacheOptions {
215
+ /**
216
+ * Which cache store to use: either `disk` or `memory`.
30
217
  *
31
- * This may use up to 2x the amount of memory that the response body takes
32
- * when the Response is cloned() and will create a full copy of the data.
218
+ * Default: none (cache disabled).
33
219
  */
34
- bytes(): Async<Buffer>
35
- /** Convert response body to text (UTF-8) */
36
- text(): Async<string>
37
- /** Parse response body as JSON */
38
- json(): Async<any>
220
+ store?: CacheStore
39
221
  /**
40
- * Create a clone of the response
222
+ * If `cache.store: "memory"`, the maximum amount of items stored.
41
223
  *
42
- * Specially, this doesn't set the disturbed flag, so that `body()` or other such
43
- * methods can work afterwards. However, it will throw if the body has already
44
- * been read from.
224
+ * Default: 10_000.
225
+ */
226
+ capacity?: number
227
+ /**
228
+ * Default cache mode. This is the same as [`FetchOptions.cache`](#fetchoptionscache), and is used if
229
+ * no cache mode is set on a request.
230
+ *
231
+ * Default: `"default"`.
232
+ */
233
+ mode?: RequestCacheMode
234
+ /**
235
+ * If `cache.store: "disk"`, then this is the path at which the cache data is. Must be writeable.
45
236
  *
46
- * Clones will cache in memory the section of the response body that is read
47
- * from one clone and not yet consumed by all others. In the worst case, you can
48
- * end up with a copy of the entire response body if you end up not consuming one
49
- * of the clones.
237
+ * Required if `cache.store: "disk"`.
50
238
  */
51
- clone(): FaithResponse
239
+ path?: string
240
+ /**
241
+ * If `true`, then the response is evaluated from a perspective of a shared cache (i.e. `private` is
242
+ * not cacheable and `s-maxage` is respected). If `false`, then the response is evaluated from a
243
+ * perspective of a single-user cache (i.e. `private` is cacheable and `s-maxage` is ignored).
244
+ * `shared: true` is required for proxies and multi-user caches.
245
+ *
246
+ * Default: true.
247
+ */
248
+ shared?: boolean
249
+ }
250
+
251
+ /** Settings related to DNS. This is a nested object. */
252
+ export interface AgentDnsOptions {
253
+ /**
254
+ * Use the system's DNS (via `getaddrinfo` or equivalent) rather than Fáith's own DNS client (based on
255
+ * [Hickory]). If you experience issues with DNS where Fáith does not work but e.g. curl or native
256
+ * fetch does, this should be your first port of call.
257
+ *
258
+ * Enabling this also disables Happy Eyeballs (for IPv6 / IPv4 best-effort resolution), the in-memory
259
+ * DNS cache, and may lead to worse performance even discounting the cache.
260
+ *
261
+ * Default: false.
262
+ *
263
+ * [Hickory]: https://hickory-dns.org/
264
+ */
265
+ system?: boolean
266
+ /**
267
+ * Override DNS resolution for specific domains. This takes effect even with `dns.system: true`.
268
+ *
269
+ * Will throw if addresses are in invalid formats. You may provide a port number as part of the
270
+ * address, it will default to port 0 otherwise, which will select the conventional port for the
271
+ * protocol in use (e.g. 80 for plaintext HTTP). If the URL passed to `fetch()` has an explicit port
272
+ * number, that one will be used instead. Resolving a domain to an empty `addresses` array effectively
273
+ * blocks that domain from this agent.
274
+ *
275
+ * Default: no overrides.
276
+ */
277
+ overrides?: Array<DnsOverride>
278
+ }
279
+
280
+ /** Settings related to HTTP/3. This is a nested object. */
281
+ export interface AgentHttp3Options {
282
+ /**
283
+ * The congestion control algorithm. The default is `cubic`, which is the same used in TCP in the
284
+ * Linux stack. It's fair for all traffic, but not the most optimal, especially for networks with
285
+ * a lot of available bandwidth, high latency, or a lot of packet loss. Cubic reacts to packet loss by
286
+ * dropping the speed by 30%, and takes a long time to recover. BBR instead tries to maximise
287
+ * bandwidth use and optimises for round-trip time, while ignoring packet loss.
288
+ *
289
+ * In some networks, BBR can lead to pathological degradation of overall network conditions, by
290
+ * flooding the network by up to **100 times** more retransmissions. This is fixed in BBRv2 and BBRv3,
291
+ * but Fáith (or rather its underlying QUIC library quinn, [does not implement those yet][2]).
292
+ *
293
+ * [2]: https://github.com/quinn-rs/quinn/issues/1254
294
+ *
295
+ * Default: `cubic`. Accepted values: `cubic`, `bbr1`.
296
+ */
297
+ congestion?: Http3Congestion
298
+ /**
299
+ * Maximum duration of inactivity to accept before timing out the connection, in seconds. Note that
300
+ * this only sets the timeout on this side of the connection: the true idle timeout is the _minimum_
301
+ * of this and the peer's own max idle timeout. While the underlying library has no limits, Fáith
302
+ * defines bounds for safety: minimum 1 second, maximum 2 minutes (120 seconds).
303
+ *
304
+ * Default: 30.
305
+ */
306
+ maxIdleTimeout?: number
52
307
  }
53
308
 
54
309
  export interface AgentOptions {
310
+ /** Settings related to the HTTP cache. This is a nested object. */
311
+ cache?: AgentCacheOptions
312
+ /**
313
+ * Enable a persistent cookie store for the agent. Cookies received in responses will be preserved and
314
+ * included in additional requests.
315
+ *
316
+ * Default: `false`.
317
+ *
318
+ * You may use `agent.getCookie(url: string)` and `agent.addCookie(url: string, value: string)` to add
319
+ * and retrieve cookies from the store.
320
+ */
55
321
  cookies?: boolean
322
+ /** Settings related to DNS. This is a nested object. */
323
+ dns?: AgentDnsOptions
324
+ /**
325
+ * Sets the default headers for every request.
326
+ *
327
+ * If header names or values are invalid, they are silently omitted.
328
+ * Sensitive headers (e.g. `Authorization`) should be marked.
329
+ *
330
+ * Default: none.
331
+ */
56
332
  headers?: Array<Header>
333
+ /** Settings related to HTTP/3. This is a nested object. */
334
+ http3?: AgentHttp3Options
335
+ /** Settings related to the connection pool. This is a nested object. */
336
+ pool?: AgentPoolOptions
337
+ /** Determines the behavior in case the server replies with a redirect status. */
338
+ redirect?: Redirect
339
+ /** Timeouts for requests made with this agent. This is a nested object. */
340
+ timeout?: AgentTimeoutOptions
341
+ /** Settings related to the connection pool. This is a nested object. */
342
+ tls?: AgentTlsOptions
343
+ /**
344
+ * Custom user agent string.
345
+ *
346
+ * Default: `Faith/{version} reqwest/{version}`.
347
+ */
57
348
  userAgent?: string
58
349
  }
59
350
 
351
+ /** Settings related to the connection pool. This is a nested object. */
352
+ export interface AgentPoolOptions {
353
+ /**
354
+ * How many seconds of inactivity before a connection is closed.
355
+ *
356
+ * Default: 90 seconds.
357
+ */
358
+ idleTimeout?: number
359
+ /**
360
+ * The maximum amount of idle connections per host to allow in the pool. Connections will be closed
361
+ * to keep the idle connections (per host) under that number.
362
+ *
363
+ * Default: `null` (no limit).
364
+ */
365
+ maxIdlePerHost?: number
366
+ }
367
+
368
+ /** Timeouts for requests made with this agent. This is a nested object. */
369
+ export interface AgentTimeoutOptions {
370
+ /**
371
+ * Set a timeout for only the connect phase, in milliseconds.
372
+ *
373
+ * Default: none.
374
+ */
375
+ connect?: number
376
+ /**
377
+ * Set a timeout for read operations, in milliseconds.
378
+ *
379
+ * The timeout applies to each read operation, and resets after a successful read. This is more
380
+ * appropriate for detecting stalled connections when the size isn't known beforehand.
381
+ *
382
+ * Default: none.
383
+ */
384
+ read?: number
385
+ /**
386
+ * Set a timeout for the entire request-response cycle, in milliseconds.
387
+ *
388
+ * The timeout applies from when the request starts connecting until the response body has finished.
389
+ * Also considered a total deadline.
390
+ *
391
+ * Default: none.
392
+ */
393
+ total?: number
394
+ }
395
+
396
+ /** Settings related to the connection pool. This is a nested object. */
397
+ export interface AgentTlsOptions {
398
+ /**
399
+ * Enable TLS 1.3 Early Data. Early data is an optimisation where the client sends the first packet
400
+ * of application data alongside the opening packet of the TLS handshake. That can enable the server
401
+ * to answer faster, improving latency by up to one round-trip. However, Early Data has significant
402
+ * security implications: it's vulnerable to replay attacks and has weaker forward secrecy. It should
403
+ * really only be used for static assets or to squeeze out the last drop of performance for endpoints
404
+ * that are replay-safe.
405
+ *
406
+ * Default: false.
407
+ */
408
+ earlyData?: boolean
409
+ /**
410
+ * Provide a PEM-formatted certificate and private key to present as a TLS client certificate (also
411
+ * called mutual TLS or mTLS) authentication.
412
+ *
413
+ * The input should contain a PEM encoded private key and at least one PEM encoded certificate. The
414
+ * private key must be in RSA, SEC1 Elliptic Curve or PKCS#8 format. This is one of the few options
415
+ * that will cause the `Agent` constructor to throw if the input is in the wrong format.
416
+ */
417
+ identity?: Buffer | string
418
+ /**
419
+ * Disables plain-text HTTP.
420
+ *
421
+ * Default: false.
422
+ */
423
+ required?: boolean
424
+ }
425
+
426
+ /**
427
+ * The cache mode you want to use for the request. This may be any one of the following values:
428
+ *
429
+ * - `default`: The client looks in its HTTP cache for a response matching the request.
430
+ * - If there is a match and it is fresh, it will be returned from the cache.
431
+ * - If there is a match but it is stale, the client will make a conditional request to the remote
432
+ * server. If the server indicates that the resource has not changed, it will be returned from the
433
+ * cache. Otherwise the resource will be downloaded from the server and the cache will be updated.
434
+ * - If there is no match, the client will make a normal request, and will update the cache with
435
+ * the downloaded resource.
436
+ *
437
+ * - `no-store`: The client fetches the resource from the remote server without first looking in the
438
+ * cache, and will not update the cache with the downloaded resource.
439
+ *
440
+ * - `reload`: The client fetches the resource from the remote server without first looking in the
441
+ * cache, but then will update the cache with the downloaded resource.
442
+ *
443
+ * - `no-cache`: The client looks in its HTTP cache for a response matching the request.
444
+ * - If there is a match, fresh or stale, the client will make a conditional request to the remote
445
+ * server. If the server indicates that the resource has not changed, it will be returned from the
446
+ * cache. Otherwise the resource will be downloaded from the server and the cache will be updated.
447
+ * - If there is no match, the client will make a normal request, and will update the cache with
448
+ * the downloaded resource.
449
+ *
450
+ * - `force-cache`: The client looks in its HTTP cache for a response matching the request.
451
+ * - If there is a match, fresh or stale, it will be returned from the cache.
452
+ * - If there is no match, the client will make a normal request, and will update the cache with
453
+ * the downloaded resource.
454
+ *
455
+ * - `only-if-cached`: The client looks in its HTTP cache for a response matching the request.
456
+ * - If there is a match, fresh or stale, it will be returned from the cache.
457
+ * - If there is no match, a network error is returned.
458
+ *
459
+ * - `ignore-rules`: Custom to Fáith. Overrides the check that determines if a response can be cached
460
+ * to always return true on 200. Uses any response in the HTTP cache matching the request, not
461
+ * paying attention to staleness. If there was no response, it creates a normal request and updates
462
+ * the HTTP cache with the response.
463
+ */
464
+ export declare const enum CacheMode {
465
+ Default = 'default',
466
+ ForceCache = 'force-cache',
467
+ IgnoreRules = 'ignore-rules',
468
+ NoCache = 'no-cache',
469
+ NoStore = 'no-store',
470
+ OnlyIfCached = 'only-if-cached',
471
+ Reload = 'reload'
472
+ }
473
+
474
+ export declare const enum CacheStore {
475
+ Disk = 'disk',
476
+ Memory = 'memory'
477
+ }
478
+
479
+ /**
480
+ * Controls whether or not the client sends credentials with the request, as well as whether any
481
+ * `Set-Cookie` response headers are respected. Credentials are cookies, ~~TLS client certificates,~~
482
+ * or authentication headers containing a username and password. This option may be any one of the
483
+ * following values:
484
+ *
485
+ * - `omit`: Never send credentials in the request or include credentials in the response.
486
+ * - ~~`same-origin`~~: Fáith does not implement this, as there is no concept of "origin" on the server.
487
+ * - `include`: Always include credentials, ~~even for cross-origin requests.~~
488
+ *
489
+ * Fáith ignores the `Access-Control-Allow-Credentials` and `Access-Control-Allow-Origin` headers.
490
+ *
491
+ * Fáith currently does not `omit` the TLS client certificate when the request's `Agent` has one
492
+ * configured. This is an upstream limitation.
493
+ *
494
+ * If the request's `Agent` has cookies enabled, new cookies from the response will be added to the
495
+ * cookie jar, even as Fáith strips them from the request and response headers returned to the user.
496
+ * This is an upstream limitation.
497
+ *
498
+ * Defaults to `include` (browsers default to `same-origin`).
499
+ */
60
500
  export declare const enum CredentialsOption {
61
501
  Omit = 'omit',
62
502
  SameOrigin = 'same-origin',
63
503
  Include = 'include'
64
504
  }
65
505
 
506
+ export interface DnsOverride {
507
+ domain: string
508
+ addresses: Array<string>
509
+ }
510
+
511
+ /**
512
+ * Controls duplex behavior of the request. If this is present it must have the value `half`, meaning
513
+ * that Fáith will send the entire request before processing the response.
514
+ *
515
+ * This option must be present when `body` is a `ReadableStream`.
516
+ */
66
517
  export declare const enum DuplexOption {
67
518
  Half = 'half'
68
519
  }
@@ -71,14 +522,53 @@ export declare function errorCodes(): Array<string>
71
522
 
72
523
  export const FAITH_VERSION: string
73
524
 
525
+ /**
526
+ * Fáith produces fine-grained errors, but maps them to a few javascript error types for fetch
527
+ * compatibility. The `.code` property on errors thrown from Fáith is set to a stable name for each
528
+ * error kind, documented in this comprehensive mapping:
529
+ *
530
+ * - JS `AbortError`:
531
+ * - `Aborted` — request was aborted using `signal`
532
+ * - `Timeout` — request timed out
533
+ * - JS `NetworkError`:
534
+ * - `Network` — network error
535
+ * - `Redirect` — when the agent is configured to error on redirects
536
+ * - JS `SyntaxError`:
537
+ * - `JsonParse` — JSON parse error for `response.json()`
538
+ * - `PemParse` — PEM parse error for `AgentOptions.tls.identity`
539
+ * - `Utf8Parse` — UTF8 decoding error for `response.text()`
540
+ * - JS `TypeError`:
541
+ * - `InvalidHeader` — invalid header name or value
542
+ * - `InvalidMethod` — invalid HTTP method
543
+ * - `InvalidUrl` — invalid URL string
544
+ * - `ResponseAlreadyDisturbed` — body already read (mutually exclusive operations)
545
+ * - `ResponseBodyNotAvailable` — body is null or not available
546
+ * - JS generic `Error`:
547
+ * - `BodyStream` — internal stream handling error
548
+ * - `Config` — invalid agent configuration
549
+ * - `RuntimeThread` — failed to start or schedule threads on the internal tokio runtime
550
+ *
551
+ * The library exports an `ERROR_CODES` object which has every error code the library throws, and
552
+ * every error thrown also has a `code` property that is set to one of those codes. So you can
553
+ * accurately respond to the exact error kind by checking its code and matching against the right
554
+ * constant from `ERROR_CODES`, instead of doing string matching on the error message, or coarse
555
+ * `instance of` matching.
556
+ *
557
+ * Due to technical limitations, when reading a body stream, reads might fail, but that error
558
+ * will not have a `code` property.
559
+ */
74
560
  export declare const enum FaithErrorKind {
75
561
  Aborted = 'Aborted',
562
+ AddressParse = 'AddressParse',
76
563
  BodyStream = 'BodyStream',
564
+ Config = 'Config',
77
565
  InvalidHeader = 'InvalidHeader',
78
566
  InvalidMethod = 'InvalidMethod',
79
567
  InvalidUrl = 'InvalidUrl',
80
568
  JsonParse = 'JsonParse',
81
569
  Network = 'Network',
570
+ PemParse = 'PemParse',
571
+ Redirect = 'Redirect',
82
572
  ResponseAlreadyDisturbed = 'ResponseAlreadyDisturbed',
83
573
  ResponseBodyNotAvailable = 'ResponseBodyNotAvailable',
84
574
  RuntimeThread = 'RuntimeThread',
@@ -89,21 +579,67 @@ export declare const enum FaithErrorKind {
89
579
  export declare function faithFetch(url: string, options: FaithOptionsAndBody, signal?: AbortSignal | undefined | null): Async<FaithResponse>
90
580
 
91
581
  export interface FaithOptionsAndBody {
92
- method?: string
93
- headers?: Array<[string, string]>
582
+ agent: Agent
94
583
  body?: string | Buffer | Uint8Array
95
- timeout?: number
584
+ cache?: CacheMode
96
585
  credentials?: CredentialsOption
97
586
  duplex?: DuplexOption
98
- agent: Agent
587
+ headers?: Array<[string, string]>
588
+ method?: string
589
+ timeout?: number
99
590
  }
100
591
 
592
+ /**
593
+ * Sets the default headers for every request.
594
+ *
595
+ * If header names or values are invalid, they are silently omitted.
596
+ * Sensitive headers (e.g. `Authorization`) should be marked.
597
+ *
598
+ * Default: none.
599
+ */
101
600
  export interface Header {
102
601
  name: string
103
602
  value: string
104
603
  sensitive?: boolean
105
604
  }
106
605
 
606
+ export declare const enum Http3Congestion {
607
+ Cubic = 'cubic',
608
+ Bbr1 = 'bbr1'
609
+ }
610
+
611
+ /**
612
+ * Determines the behavior in case the server replies with a redirect status.
613
+ * One of the following values:
614
+ *
615
+ * - `follow`: automatically follow redirects. Fáith limits this to 10 redirects.
616
+ * - `error`: reject the promise with a network error when a redirect status is returned.
617
+ * - ~~`manual`~~: not supported.
618
+ * - `stop`: (Fáith custom) don't follow any redirects, return the responses.
619
+ *
620
+ * Defaults to `follow`.
621
+ */
622
+ export declare const enum Redirect {
623
+ Follow = 'follow',
624
+ Error = 'error',
625
+ Manual = 'manual',
626
+ Stop = 'stop'
627
+ }
628
+
107
629
  export const REQWEST_VERSION: string
108
630
 
631
+ /**
632
+ * Custom user agent string.
633
+ *
634
+ * Default: `Faith/{version} reqwest/{version}`.
635
+ *
636
+ * You may use the `USER_AGENT` constant if you wish to prepend your own agent to the default, e.g.
637
+ *
638
+ * ```javascript
639
+ * import { Agent, USER_AGENT } from '@passcod/faith';
640
+ * const agent = new Agent({
641
+ * userAgent: `YourApp/1.2.3 ${USER_AGENT}`,
642
+ * });
643
+ * ```
644
+ */
109
645
  export const USER_AGENT: string