/** * HTTP bond accessor and convenience request functions. * * If no custom client is bonded, a fetch-based client is returned — it is NOT * bonded, so a client bonded later is what every subsequent call sees. * Provides `get`, `post`, `put`, `patch`, and `del` shorthand functions that * delegate to the bonded client. * * @module */ import type { AuthTokenResolver, HttpClient } from './client.js'; /** * Registers the token source every bonded client reads on EACH request, or removes it with * `null`. * * Every client that receives the source — the one bonded now, any bonded later, and the * fallback {@link getClient} returns while none is bonded — is hydrated from `source()` and * reads it again for every request: through {@link HttpClient.setAuthTokenResolver} where the * client implements it (`createFetchClient`, `@molecule/app-http-axios` from 1.2.0), else * through a request interceptor that pushes it with `setAuthToken`, which a transport applying * its token after its interceptors sends on that same request and one applying it before them * from the next request on. So a restored session reaches a client bonded after the auth setup * (which holds no client reference), and a session adopted later with no auth event * (`setSession`, `setAccessToken`) never leaves the previous account's bearer on the wire. * * A source that returns `null` means "no body token": the client sends no `Authorization` * header of its own (see {@link HttpClient.setAuthTokenResolver} for why a kept bearer is a * bug). A header passed per request or in a client's default headers keeps the precedence that * client's transport gives it over the client's token. * * A replaced source is followed from the next request on. Removing it (`null`) leaves the * bonded client (and the fallback) on the token the source returned at that moment, as a * static token that `setAuthToken` controls from then on. * * @param source - Returns the current access token (null when signed out), or `null` to remove it. * * @example * ```typescript * setAuthTokenSource(() => authClient.getAccessToken()) * ``` */ export declare const setAuthTokenSource: (source: AuthTokenResolver | null) => void; /** * Registers an HTTP client as the active singleton. * * A registered `setAuthTokenSource` token source is applied to the client * here, so a client bonded after the auth setup resolves the restored * session's token on every request it makes. * * @param client - The HTTP client implementation to bond. * * @example * ```typescript * import { setClient, createFetchClient } from '@molecule/app-http' * setClient(createFetchClient({ baseURL: 'https://api.example.com' })) * ``` */ export declare const setClient: (client: HttpClient) => void; /** * Retrieves the bonded HTTP client. Before setup, returns a live handle which uses * a fetch fallback until the application bonds its transport. It is NOT bonded. * * The fallback has NO `baseURL` — a core cannot know an app's API prefix. A relative * call then resolves against the page origin, where a dev server answers its own HTML * shell with a 200. It warns once so the misconfiguration is named instead of showing up * as a crash three components later; a scaffold bonds the shared client with its API * prefix, so the fallback only runs in an app that never bonded one. * * A service imported before setup may capture this handle, or one of its methods. * Each invocation uses the current bonded transport, including its API prefix, * interceptors and token source. Explicitly constructed clients remain independent. * Subscriptions and configuration writes apply to the transport active when made; * configure the application transport before registering interceptors on it. * The fallback follows a registered `setAuthTokenSource` source like a bonded client * does, so an app that bonds no client at all still sends the current session. * * @returns The active HTTP client, or the unbonded fallback when none is bonded. */ export declare const getClient: () => HttpClient; /** * Makes a GET request using the bonded HTTP client. * * @param url - The request URL (relative to baseURL if configured). * @param config - Optional request configuration (headers, params, timeout). * @returns The HTTP response with typed data. */ export declare const get: HttpClient['get']; /** * Makes a POST request using the bonded HTTP client. * * The body is `data` — the SECOND argument. `post(url, { data: body })` sends the JSON body * `{"data":body}`, not `body`, so the API finds none of its fields at the top level; pass the * body directly (`post('/users', { user })`). The config is the THIRD argument. * * @param url - The request URL. * @param data - The request body itself (never `{ data: body }`). * @param config - Optional request configuration (headers, params, timeout). * @returns The HTTP response with typed data. */ export declare const post: HttpClient['post']; /** * Makes a PUT request using the bonded HTTP client. * * @param url - The request URL. * The body is `data` — the SECOND argument, never `{ data: body }`. * * @param data - The request body itself. * @param config - Optional request configuration (the third argument). * @returns The HTTP response with typed data. */ export declare const put: HttpClient['put']; /** * Makes a PATCH request using the bonded HTTP client. * * @param url - The request URL. * The body is `data` — the SECOND argument, never `{ data: body }`. * * @param data - The request body itself (the partial update). * @param config - Optional request configuration (the third argument). * @returns The HTTP response with typed data. */ export declare const patch: HttpClient['patch']; /** * Makes a DELETE request using the bonded HTTP client. * * @param url - The request URL. * @param config - Optional request configuration. * @returns The HTTP response with typed data. */ export declare const del: HttpClient['delete']; /** * Pre-created fetch client for environments where `fetch` is available. * `null` in environments without a global `fetch`. */ export declare const fetchClient: HttpClient | null; //# sourceMappingURL=utilities.d.ts.map