firebase-auth-cloudflare-workers
Version:
Zero-dependencies firebase auth library for Cloudflare Workers.
47 lines (46 loc) • 1.97 kB
TypeScript
import type { ApiSettings } from './api-requests';
import type { Credential } from './credential';
import { type EmulatorEnv } from './emulator';
/**
* Specifies how failing HTTP requests should be retried.
*/
export interface RetryConfig {
/** Maximum number of times to retry a given request. */
maxRetries: number;
/** HTTP status codes that should be retried. */
statusCodes?: number[];
/** Low-level I/O error codes that should be retried. */
ioErrorCodes?: string[];
/**
* The multiplier for exponential back off. The retry delay is calculated in seconds using the formula
* `(2^n) * backOffFactor`, where n is the number of retries performed so far. When the backOffFactor is set
* to 0, retries are not delayed. When the backOffFactor is 1, retry duration is doubled each iteration.
*/
backOffFactor?: number;
/** Maximum duration to wait before initiating a retry. */
maxDelayInMillis: number;
}
/**
* Default retry configuration for HTTP requests. Retries up to 4 times on connection reset and timeout errors
* as well as HTTP 503 errors. Exposed as a function to ensure that every HttpClient gets its own RetryConfig
* instance.
*/
export declare function defaultRetryConfig(): RetryConfig;
export declare function buildApiUrl(projectId: string, apiSettings: ApiSettings, env?: EmulatorEnv): string;
export declare class BaseClient {
private projectId;
private credential;
private retryConfig;
constructor(projectId: string, credential: Credential, retryConfig?: RetryConfig);
private getToken;
protected fetch<T>(apiSettings: ApiSettings, requestData?: object, env?: EmulatorEnv): Promise<T>;
private fetchWithRetry;
/**
* @param response - The response to check for errors.
* @returns The error code if present; null otherwise.
*/
private getErrorCode;
private waitForRetry;
private isRetryEligible;
private backOffDelayMillis;
}