@passcod/faith 0.0.2 → 0.0.4

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