@exceptionless/fetchclient
Version:
A simple fetch client with middleware support for Deno and the browser.
109 lines • 4.25 kB
TypeScript
import { FetchClient } from "./FetchClient.js";
import { Counter } from "./Counter.js";
import type { FetchClientMiddleware } from "./FetchClientMiddleware.js";
import type { ProblemDetails } from "./ProblemDetails.js";
import { FetchClientCache } from "./FetchClientCache.js";
import type { FetchClientOptions } from "./FetchClientOptions.js";
import { type IObjectEvent } from "./ObjectEvent.js";
import { type RateLimitMiddlewareOptions } from "./RateLimitMiddleware.js";
import { type RateLimiter } from "./RateLimiter.js";
type Fetch = typeof globalThis.fetch;
/**
* Represents a provider for creating instances of the FetchClient class with shared default options and cache.
*/
export declare class FetchClientProvider {
#private;
/**
* Creates a new instance of FetchClientProvider.
* @param fetch - The fetch function to use. If not provided, the global fetch function will be used.
*/
constructor(fetch?: Fetch);
/**
* Gets the fetch function used for making requests.
*/
get fetch(): Fetch | undefined;
/**
* Sets the fetch function used for making requests.
*/
set fetch(value: Fetch | undefined);
/**
* Gets a value indicating whether there are ongoing requests.
*/
get isLoading(): boolean;
/**
* Gets an event that is triggered when the loading state changes.
*/
get loading(): IObjectEvent<boolean>;
/**
* Gets the number of ongoing requests.
*/
get requestCount(): number;
/**
* Gets the counter used for tracking ongoing requests.
*/
get counter(): Counter;
/**
* Gets the options used for FetchClient instances.
*/
get options(): FetchClientOptions;
/**
* Sets the options used for FetchClient instances.
*/
set options(value: FetchClientOptions);
/**
* Gets the cache used for storing HTTP responses.
*/
get cache(): FetchClientCache;
/**
* Creates a new instance of FetchClient using the current provider.
* @param options - The options to use for the FetchClient instance.
* @returns A new instance of FetchClient.
*/
getFetchClient(options?: FetchClientOptions): FetchClient;
/**
* Applies the specified options by merging with the current options.
*/
applyOptions(options: FetchClientOptions): void;
/**
* Sets the function used for retrieving the access token.
* @param accessTokenFunc - The function that retrieves the access token.
*/
setAccessTokenFunc(accessTokenFunc: () => string | null): void;
/**
* Sets the default model validator function for all FetchClient instances created by this provider.
* @param validate - The function that validates the model.
*/
setModelValidator(validate: (model: object | null) => Promise<ProblemDetails | null>): void;
/**
* Sets the default base URL for all FetchClient instances created by this provider.
* @param url - The URL to set as the default base URL.
*/
setBaseUrl(url: string): void;
/**
* Adds a middleware to all FetchClient instances created by this provider.
* @param middleware - The middleware function to be added.
*/
useMiddleware(middleware: FetchClientMiddleware): void;
/**
* Enables rate limiting for all FetchClient instances created by this provider.
* @param options - The rate limiting configuration options.
*/
useRateLimit(options: RateLimitMiddlewareOptions): void;
/**
* Enables rate limiting for all FetchClient instances created by this provider.
* @param options - The rate limiting configuration options.
*/
usePerDomainRateLimit(options: Omit<RateLimitMiddlewareOptions, "getGroupFunc">): void;
/**
* Gets the rate limiter instance used for rate limiting.
* @returns The rate limiter instance, or undefined if rate limiting is not enabled.
*/
get rateLimiter(): RateLimiter | undefined;
/**
* Removes the rate limiting middleware from all FetchClient instances created by this provider.
*/
removeRateLimit(): void;
}
export declare const defaultInstance: FetchClientProvider;
export {};
//# sourceMappingURL=FetchClientProvider.d.ts.map