123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- import { FirebaseApp } from '../app/firebase-app';
- import http = require('http');
- import { EventEmitter } from 'events';
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD';
- export type ApiCallbackFunction = (data: object) => void;
- export interface HttpRequestConfig {
- method: HttpMethod;
-
- url: string;
- headers?: {
- [key: string]: string;
- };
- data?: string | object | Buffer | null;
-
- timeout?: number;
- httpAgent?: http.Agent;
- }
- export interface HttpResponse {
- readonly status: number;
- readonly headers: any;
-
- readonly text?: string;
-
- readonly data?: any;
-
- readonly multipart?: Buffer[];
-
- isJson(): boolean;
- }
- export declare class HttpError extends Error {
- readonly response: HttpResponse;
- constructor(response: HttpResponse);
- }
- export interface RetryConfig {
-
- maxRetries: number;
-
- statusCodes?: number[];
-
- ioErrorCodes?: string[];
-
- backOffFactor?: number;
-
- maxDelayInMillis: number;
- }
- export declare function defaultRetryConfig(): RetryConfig;
- export declare class HttpClient {
- private readonly retry;
- constructor(retry?: RetryConfig | null);
-
- send(config: HttpRequestConfig): Promise<HttpResponse>;
-
- private sendWithRetry;
- private createHttpResponse;
- private waitForRetry;
-
- private getRetryDelayMillis;
- private isRetryEligible;
-
- private parseRetryAfterIntoMillis;
- private backOffDelayMillis;
- }
- export declare function parseHttpResponse(response: string | Buffer, config: HttpRequestConfig): HttpResponse;
- export declare class AuthorizedHttpClient extends HttpClient {
- private readonly app;
- constructor(app: FirebaseApp);
- send(request: HttpRequestConfig): Promise<HttpResponse>;
- protected getToken(): Promise<string>;
- }
- export declare class ApiSettings {
- private endpoint;
- private httpMethod;
- private requestValidator;
- private responseValidator;
- constructor(endpoint: string, httpMethod?: HttpMethod);
-
- getEndpoint(): string;
-
- getHttpMethod(): HttpMethod;
-
- setRequestValidator(requestValidator: ApiCallbackFunction | null): ApiSettings;
-
- getRequestValidator(): ApiCallbackFunction;
-
- setResponseValidator(responseValidator: ApiCallbackFunction | null): ApiSettings;
-
- getResponseValidator(): ApiCallbackFunction;
- }
- export declare class ExponentialBackoffPoller<T> extends EventEmitter {
- private readonly initialPollingDelayMillis;
- private readonly maxPollingDelayMillis;
- private readonly masterTimeoutMillis;
- private numTries;
- private completed;
- private masterTimer;
- private repollTimer;
- private pollCallback?;
- private resolve;
- private reject;
- constructor(initialPollingDelayMillis?: number, maxPollingDelayMillis?: number, masterTimeoutMillis?: number);
-
- poll(callback: () => Promise<T>): Promise<T>;
- private repoll;
- private getPollingDelayMillis;
- private markCompleted;
- }
|