Classes
FetchError<T>
Error class for representing fetch operation failures. This class extends the standard Error to include additional information about failed requests, including the response body, status code, and headers. The error message is automatically extracted from common error response formats.Extends
Error
Type Parameters
Type Parameter | Default type | Description |
---|---|---|
T | unknown | The type of the response body |
Constructors
Constructor
Parameters
Parameter | Type | Description |
---|---|---|
body | T | The response body from the failed request |
status | number | The HTTP status code |
headers | Headers | The response headers |
Returns
FetchError
<T
>
Overrides
Properties
Property | Type | Description |
---|---|---|
body | T | The original response body |
headers | Headers | Response headers |
status | number | HTTP status code of the failed response |
Interfaces
FetchResponse<T>
Interface representing a structured API response. This interface provides a consistent structure for responses across the SDK, offering access to the parsed response body along with status and headers.Type Parameters
Type Parameter | Description |
---|---|
T | The type of the response body |
Properties
body
headers
status
Type Aliases
ChainFunction()
- Authentication token handling
- Error handling and retry logic
- Request and response transformations
- Logging and metrics
Parameters
Parameter | Type |
---|---|
next | FetchFunction |
Returns
FetchFunction
FetchFunction()
Parameters
Parameter | Type |
---|---|
url | string |
options? | RequestInit |
Returns
Promise
<Response
>
Functions
attachAccessTokenMiddleware()
- Gets the current session from storage
- Adds the authorization header with the access token to outgoing requests
Parameters
Parameter | Type | Description |
---|---|---|
storage | SessionStorage | Storage implementation for retrieving session data |
Returns
ChainFunction
A middleware function that adds Authorization headers
createEnhancedFetch()
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
chainFunctions | ChainFunction [] | [] | Array of chain functions to apply in order |
Returns
FetchFunction
Enhanced fetch function with all middleware applied
Example
sessionRefreshMiddleware()
- Checks if the current token is about to expire
- If so, uses the refresh token to obtain a new access token
Parameters
Parameter | Type | Description |
---|---|---|
auth | Client | Auth API client for token refresh operations |
storage | SessionStorage | Storage implementation for persisting session data |
options? | { marginSeconds? : number ; } | Configuration options for token refresh behavior |
options.marginSeconds? | number | Number of seconds before token expiration to trigger a refresh, default is 60 seconds |
Returns
ChainFunction
A middleware function that can be used in the fetch chain
updateSessionFromResponseMiddleware()
- Monitors responses from authentication-related endpoints
- Extracts session information when present
- Stores the session in the provided storage implementation
- Handles session removal on sign-out
Parameters
Parameter | Type | Description |
---|---|---|
storage | SessionStorage | Storage implementation for persisting session data |
Returns
ChainFunction
A middleware function that can be used in the fetch chain