import { ContextMgr, Secrets } from '@webpieces/core-util'; import { ApiPrototype, ClientConfig, IdTokenMinter } from './ClientConfig'; /** * ClientHttpFactory - builds type-safe HTTP clients from API prototypes carrying * @ApiPath/@Endpoint decorators. * * This is the client-side equivalent of ApiRoutingFactory. * - Server: ApiRoutingFactory reads decorators -> routes HTTP requests to controllers * - Client: ClientHttpFactory reads decorators -> generates HTTP requests from method calls * * The factory holds the COLLABORATORS shared by every client it builds (contextMgr, * idTokenMinter, secrets); each {@link ClientConfig} holds only that one client's STATE * (its baseUrl). Build the factory once per process and reuse it: * * ```typescript * // Node.js server-side: * const factory = new ClientHttpFactory(new ContextMgr(new RequestContextReader()), mintIdToken, secrets); * const saveClient = factory.createClient(SaveApi, new ClientConfig('http://localhost:3000')); * const response = await saveClient.save({ query: 'test' }); // Type-safe! * * // Browser (no minter, no secrets — a browser cannot hold service credentials): * const factory = new ClientHttpFactory(new ContextMgr(new MutableContextStore())); * const saveClient = factory.createClient(SaveApi, new ClientConfig(apiBaseUrl)); * ``` * * Deliberately a plain class with NO inversify decorators: Angular bundles this package * into the browser, so it must not pull in a Node DI container. A Node app binds it with * `toDynamicValue`; Angular with `useFactory`. */ export declare class ClientHttpFactory { private readonly contextMgr?; private readonly idTokenMinter?; private readonly secrets?; constructor(contextMgr?: ContextMgr | undefined, idTokenMinter?: IdTokenMinter | undefined, secrets?: Secrets | undefined); /** * Create a type-safe HTTP client for one API contract. * * @param apiPrototype - The API prototype class with @ApiPath/@Endpoint decorators * @param config - This client's state (its baseUrl) * @returns A proxy object that implements the API interface */ createClient(apiPrototype: ApiPrototype, config: ClientConfig): T; }