@gauts/ft 0.1.2 → 0.1.3

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 (2) hide show
  1. package/README.md +26 -28
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @gauts/ft
2
2
 
3
+ [![Minified Size](https://img.shields.io/badge/minified-11.1_kB-007ec6)](https://bundlephobia.com/package/@gauts/ft)
4
+ [![Minified and Gzipped Size](https://img.shields.io/badge/minified_%2B_gzip-4.2_kB-007ec6)](https://bundlephobia.com/package/@gauts/ft)
5
+
3
6
  A small, typed HTTP client built on the native Fetch API.
4
7
 
5
8
  - ✅ Ready-to-use default client
@@ -184,22 +187,22 @@ The explicit `filename` has priority. When omitted, the name is read from the st
184
187
 
185
188
  ### Instance options
186
189
 
187
- | Property | Type | Default | Description |
188
- | ----------------- | -------------------------------- | ------- | ----------------------------------------------------- |
189
- | `baseUrl` | `string \| URL \| RuntimeBaseUrl` | — | Static URL or automatic client/server URLs. |
190
- | `prefix` | `string` | — | Path inserted between `baseUrl` and the request path. |
191
- | `searchParams` | `SearchParams` | — | Parameters included in every request. |
192
- | `headers` | `HeadersInit` | — | Headers included in every request. |
193
- | `forwardHeaders` | `boolean \| { extra: string[] }` | `false` | Forwards allowlisted incoming headers on the server. |
194
- | `getHeaders` | `() => HeadersInit \| Promise<HeadersInit>` | — | Provides the current incoming server headers. |
195
- | `timeout` | `number \| false` | `false` | Request timeout in milliseconds. |
196
- | `retry` | `number \| RetryConfig \| false` | `false` | Enables retries. A number is the retry limit. |
197
- | `throwHttpErrors` | `boolean` | `true` | Throws `HTTPError` for non-2xx responses. |
198
- | `beforeRequest` | `BeforeRequest` | — | Runs before every attempt. |
199
- | `afterResponse` | `AfterResponse` | — | Runs after every received response. |
200
- | `onRetry` | `OnRetry` | — | Runs before a retry delay. |
201
- | `onError` | `OnError` | — | Observes or replaces the final error. |
202
- | `onStatus` | `StatusHandlers` | — | Runs an action for the final response status. |
190
+ | Property | Type | Default | Description |
191
+ | ----------------- | ------------------------------------------- | ------- | ----------------------------------------------------- |
192
+ | `baseUrl` | `string \| URL \| RuntimeBaseUrl` | — | Static URL or automatic client/server URLs. |
193
+ | `prefix` | `string` | — | Path inserted between `baseUrl` and the request path. |
194
+ | `searchParams` | `SearchParams` | — | Parameters included in every request. |
195
+ | `headers` | `HeadersInit` | — | Headers included in every request. |
196
+ | `forwardHeaders` | `boolean \| { extra: string[] }` | `false` | Forwards allowlisted incoming headers on the server. |
197
+ | `getHeaders` | `() => HeadersInit \| Promise<HeadersInit>` | — | Provides the current incoming server headers. |
198
+ | `timeout` | `number \| false` | `false` | Request timeout in milliseconds. |
199
+ | `retry` | `number \| RetryConfig \| false` | `false` | Enables retries. A number is the retry limit. |
200
+ | `throwHttpErrors` | `boolean` | `true` | Throws `HTTPError` for non-2xx responses. |
201
+ | `beforeRequest` | `BeforeRequest` | — | Runs before every attempt. |
202
+ | `afterResponse` | `AfterResponse` | — | Runs after every received response. |
203
+ | `onRetry` | `OnRetry` | — | Runs before a retry delay. |
204
+ | `onError` | `OnError` | — | Observes or replaces the final error. |
205
+ | `onStatus` | `StatusHandlers` | — | Runs an action for the final response status. |
203
206
 
204
207
  All other native `RequestInit` properties, such as `cache`, `credentials`, `mode`, and `redirect`, are supported.
205
208
 
@@ -338,15 +341,16 @@ const api = ft.create({
338
341
  request.headers.set("x-runtime", isServer ? "server" : "client");
339
342
  },
340
343
 
341
- afterResponse: ({ response }) => {
342
- console.log(response.status);
344
+ afterResponse: ({ response, attempt, request, isServer }) => {
345
+ console.log(response.status, attempt, request, isServer);
343
346
  },
344
347
 
345
- onRetry: ({ attempt, delay, error }) => {
346
- console.log({ attempt, delay, error });
348
+ onRetry: ({ attempt, delay, error, isServer }) => {
349
+ console.log({ attempt, delay, error, isServer });
347
350
  },
348
351
 
349
- onError: ({ error }) => {
352
+ onError: ({ error, attempt, request, isServer }) => {
353
+ console.log({ error, attempt, request, isServer });
350
354
  return new Error("API request failed", { cause: error });
351
355
  },
352
356
  });
@@ -415,13 +419,7 @@ await api
415
419
  ## Errors
416
420
 
417
421
  ```ts
418
- import {
419
- errorInfo,
420
- FetchError,
421
- HTTPError,
422
- NetworkError,
423
- TimeoutError,
424
- } from "@gauts/ft";
422
+ import { errorInfo, FetchError, HTTPError, NetworkError, TimeoutError } from "@gauts/ft";
425
423
  ```
426
424
 
427
425
  - `HTTPError` exposes `request` and `response`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gauts/ft",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A small, typed HTTP client built on the native Fetch API.",
5
5
  "license": "MIT",
6
6
  "author": "GVALFER",