UNPKG

2.79 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2020 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @fileoverview Most logic is copied from packages/remote-config/src/client/retrying_client.ts
19 */
20import { FirebaseApp } from '@firebase/app';
21import { DynamicConfig, ThrottleMetadata, MinimalDynamicConfig } from './types';
22export interface AppFields {
23 appId: string;
24 apiKey: string;
25 measurementId?: string;
26}
27/**
28 * Backoff factor for 503 errors, which we want to be conservative about
29 * to avoid overloading servers. Each retry interval will be
30 * BASE_INTERVAL_MILLIS * LONG_RETRY_FACTOR ^ retryCount, so the second one
31 * will be ~30 seconds (with fuzzing).
32 */
33export declare const LONG_RETRY_FACTOR = 30;
34/**
35 * Stubbable retry data storage class.
36 */
37declare class RetryData {
38 throttleMetadata: {
39 [appId: string]: ThrottleMetadata;
40 };
41 intervalMillis: number;
42 constructor(throttleMetadata?: {
43 [appId: string]: ThrottleMetadata;
44 }, intervalMillis?: number);
45 getThrottleMetadata(appId: string): ThrottleMetadata;
46 setThrottleMetadata(appId: string, metadata: ThrottleMetadata): void;
47 deleteThrottleMetadata(appId: string): void;
48}
49/**
50 * Fetches dynamic config from backend.
51 * @param app Firebase app to fetch config for.
52 */
53export declare function fetchDynamicConfig(appFields: AppFields): Promise<DynamicConfig>;
54/**
55 * Fetches dynamic config from backend, retrying if failed.
56 * @param app Firebase app to fetch config for.
57 */
58export declare function fetchDynamicConfigWithRetry(app: FirebaseApp, retryData?: RetryData, timeoutMillis?: number): Promise<DynamicConfig | MinimalDynamicConfig>;
59/**
60 * Shims a minimal AbortSignal (copied from Remote Config).
61 *
62 * <p>AbortController's AbortSignal conveniently decouples fetch timeout logic from other aspects
63 * of networking, such as retries. Firebase doesn't use AbortController enough to justify a
64 * polyfill recommendation, like we do with the Fetch API, but this minimal shim can easily be
65 * swapped out if/when we do.
66 */
67export declare class AnalyticsAbortSignal {
68 listeners: Array<() => void>;
69 addEventListener(listener: () => void): void;
70 abort(): void;
71}
72export {};