Initial Commit

This commit is contained in:
2026-03-06 04:54:20 -04:00
commit 63677bfcf5
9332 changed files with 1507319 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"type":"module"}

View File

@@ -0,0 +1,13 @@
import { FirebaseExperimentDescription } from '../public_types';
import { RemoteConfig } from '../remote_config';
export declare class Experiment {
private storage;
private logger;
private analyticsProvider;
constructor(rc: RemoteConfig);
updateActiveExperiments(latestExperiments: FirebaseExperimentDescription[]): Promise<void>;
private createExperimentInfoMap;
private addActiveExperiments;
private removeInactiveExperiments;
private addExperimentToAnalytics;
}

View File

@@ -0,0 +1,144 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseApp } from '@firebase/app';
import { CustomSignals, LogLevel as RemoteConfigLogLevel, RemoteConfig, Value, RemoteConfigOptions, ConfigUpdateObserver, Unsubscribe } from './public_types';
/**
*
* @param app - The {@link @firebase/app#FirebaseApp} instance.
* @param options - Optional. The {@link RemoteConfigOptions} with which to instantiate the
* Remote Config instance.
* @returns A {@link RemoteConfig} instance.
*
* @public
*/
export declare function getRemoteConfig(app?: FirebaseApp, options?: RemoteConfigOptions): RemoteConfig;
/**
* Makes the last fetched config available to the getters.
* @param remoteConfig - The {@link RemoteConfig} instance.
* @returns A `Promise` which resolves to true if the current call activated the fetched configs.
* If the fetched configs were already activated, the `Promise` will resolve to false.
*
* @public
*/
export declare function activate(remoteConfig: RemoteConfig): Promise<boolean>;
/**
* Ensures the last activated config are available to the getters.
* @param remoteConfig - The {@link RemoteConfig} instance.
*
* @returns A `Promise` that resolves when the last activated config is available to the getters.
* @public
*/
export declare function ensureInitialized(remoteConfig: RemoteConfig): Promise<void>;
/**
* Fetches and caches configuration from the Remote Config service.
* @param remoteConfig - The {@link RemoteConfig} instance.
* @public
*/
export declare function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;
/**
* Gets all config.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
* @returns All config.
*
* @public
*/
export declare function getAll(remoteConfig: RemoteConfig): Record<string, Value>;
/**
* Gets the value for the given key as a boolean.
*
* Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
* @param key - The name of the parameter.
*
* @returns The value for the given key as a boolean.
* @public
*/
export declare function getBoolean(remoteConfig: RemoteConfig, key: string): boolean;
/**
* Gets the value for the given key as a number.
*
* Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
* @param key - The name of the parameter.
*
* @returns The value for the given key as a number.
*
* @public
*/
export declare function getNumber(remoteConfig: RemoteConfig, key: string): number;
/**
* Gets the value for the given key as a string.
* Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
* @param key - The name of the parameter.
*
* @returns The value for the given key as a string.
*
* @public
*/
export declare function getString(remoteConfig: RemoteConfig, key: string): string;
/**
* Gets the {@link Value} for the given key.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
* @param key - The name of the parameter.
*
* @returns The value for the given key.
*
* @public
*/
export declare function getValue(remoteConfig: RemoteConfig, key: string): Value;
/**
* Defines the log level to use.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
* @param logLevel - The log level to set.
*
* @public
*/
export declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: RemoteConfigLogLevel): void;
/**
* Sets the custom signals for the app instance.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
* @param customSignals - Map (key, value) of the custom signals to be set for the app instance. If
* a key already exists, the value is overwritten. Setting the value of a custom signal to null
* unsets the signal. The signals will be persisted locally on the client.
*
* @public
*/
export declare function setCustomSignals(remoteConfig: RemoteConfig, customSignals: CustomSignals): Promise<void>;
/**
* Starts listening for real-time config updates from the Remote Config backend and automatically
* fetches updates from the Remote Config backend when they are available.
*
* @remarks
* If a connection to the Remote Config backend is not already open, calling this method will
* open it. Multiple listeners can be added by calling this method again, but subsequent calls
* re-use the same connection to the backend.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
* @param observer - The {@link ConfigUpdateObserver} to be notified of config updates.
* @returns An {@link Unsubscribe} function to remove the listener.
*
* @public
*/
export declare function onConfigUpdate(remoteConfig: RemoteConfig, observer: ConfigUpdateObserver): Unsubscribe;

View File

@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { RemoteConfig } from './public_types';
/**
*
* Performs fetch and activate operations, as a convenience.
*
* @param remoteConfig - The {@link RemoteConfig} instance.
*
* @returns A `Promise` which resolves to true if the current call activated the fetched configs.
* If the fetched configs were already activated, the `Promise` will resolve to false.
*
* @public
*/
export declare function fetchAndActivate(remoteConfig: RemoteConfig): Promise<boolean>;
/**
* This method provides two different checks:
*
* 1. Check if IndexedDB exists in the browser environment.
* 2. Check if the current browser context allows IndexedDB `open()` calls.
*
* @returns A `Promise` which resolves to true if a {@link RemoteConfig} instance
* can be initialized in this environment, or false if it cannot.
* @public
*/
export declare function isSupported(): Promise<boolean>;

View File

@@ -0,0 +1,46 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { StorageCache } from '../storage/storage_cache';
import { FetchResponse } from '../public_types';
import { RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
import { Storage } from '../storage/storage';
import { Logger } from '@firebase/logger';
/**
* Implements the {@link RemoteConfigClient} abstraction with success response caching.
*
* <p>Comparable to the browser's Cache API for responses, but the Cache API requires a Service
* Worker, which requires HTTPS, which would significantly complicate SDK installation. Also, the
* Cache API doesn't support matching entries by time.
*/
export declare class CachingClient implements RemoteConfigFetchClient {
private readonly client;
private readonly storage;
private readonly storageCache;
private readonly logger;
constructor(client: RemoteConfigFetchClient, storage: Storage, storageCache: StorageCache, logger: Logger);
/**
* Returns true if the age of the cached fetched configs is less than or equal to
* {@link Settings#minimumFetchIntervalInSeconds}.
*
* <p>This is comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the
* native Fetch API.
*
* <p>Visible for testing.
*/
isCachedDataFresh(cacheMaxAgeMillis: number, lastSuccessfulFetchTimestampMillis: number | undefined): boolean;
fetch(request: FetchRequest): Promise<FetchResponse>;
}

View File

@@ -0,0 +1,39 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Base class to be used if you want to emit events. Call the constructor with
* the set of allowed event names.
*/
export declare abstract class EventEmitter {
private allowedEvents_;
private listeners_;
constructor(allowedEvents_: string[]);
/**
* To be overridden by derived classes in order to fire an initial event when
* somebody subscribes for data.
*
* @returns {Array.<*>} Array of parameters to trigger initial event with.
*/
abstract getInitialEvent(eventType: string): unknown[];
/**
* To be called by derived classes to trigger events.
*/
protected trigger(eventType: string, ...varArgs: unknown[]): void;
on(eventType: string, callback: (a: unknown) => void, context: unknown): void;
off(eventType: string, callback: (a: unknown) => void, context: unknown): void;
private validateEventType_;
}

View File

@@ -0,0 +1,141 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { _FirebaseInstallationsInternal } from '@firebase/installations';
import { Logger } from '@firebase/logger';
import { ConfigUpdateObserver } from '../public_types';
import { Storage } from '../storage/storage';
import { StorageCache } from '../storage/storage_cache';
import { CachingClient } from './caching_client';
export declare class RealtimeHandler {
private readonly firebaseInstallations;
private readonly storage;
private readonly sdkVersion;
private readonly namespace;
private readonly projectId;
private readonly apiKey;
private readonly appId;
private readonly logger;
private readonly storageCache;
private readonly cachingClient;
constructor(firebaseInstallations: _FirebaseInstallationsInternal, storage: Storage, sdkVersion: string, namespace: string, projectId: string, apiKey: string, appId: string, logger: Logger, storageCache: StorageCache, cachingClient: CachingClient);
private observers;
private isConnectionActive;
private isRealtimeDisabled;
private controller?;
private reader;
private httpRetriesRemaining;
private isInBackground;
private readonly decoder;
private isClosingConnection;
private setRetriesRemaining;
private propagateError;
/**
* Increment the number of failed stream attempts, increase the backoff duration, set the backoff
* end time to "backoff duration" after `lastFailedStreamTime` and persist the new
* values to storage metadata.
*/
private updateBackoffMetadataWithLastFailedStreamConnectionTime;
/**
* Increase the backoff duration with a new end time based on Retry Interval.
*/
private updateBackoffMetadataWithRetryInterval;
/**
* HTTP status code that the Realtime client should retry on.
*/
private isStatusCodeRetryable;
/**
* Closes the realtime HTTP connection.
* Note: This method is designed to be called only once at a time.
* If a call is already in progress, subsequent calls will be ignored.
*/
private closeRealtimeHttpConnection;
private resetRealtimeBackoff;
private resetRetryCount;
/**
* Assembles the request headers and body and executes the fetch request to
* establish the real-time streaming connection. This is the "worker" method
* that performs the actual network communication.
*/
private establishRealtimeConnection;
private getRealtimeUrl;
private createRealtimeConnection;
/**
* Retries HTTP stream connection asyncly in random time intervals.
*/
private retryHttpConnectionWhenBackoffEnds;
private setIsHttpConnectionRunning;
/**
* Combines the check and set operations to prevent multiple asynchronous
* calls from redundantly starting an HTTP connection. This ensures that
* only one attempt is made at a time.
*/
private checkAndSetHttpConnectionFlagIfNotRunning;
private fetchResponseIsUpToDate;
private parseAndValidateConfigUpdateMessage;
private isEventListenersEmpty;
private getRandomInt;
private executeAllListenerCallbacks;
/**
* Compares two configuration objects and returns a set of keys that have changed.
* A key is considered changed if it's new, removed, or has a different value.
*/
private getChangedParams;
private fetchLatestConfig;
private autoFetch;
/**
* Processes a stream of real-time messages for configuration updates.
* This method reassembles fragmented messages, validates and parses the JSON,
* and automatically fetches a new config if a newer template version is available.
* It also handles server-specified retry intervals and propagates errors for
* invalid messages or when real-time updates are disabled.
*/
private handleNotifications;
private listenForNotifications;
/**
* Open the real-time connection, begin listening for updates, and auto-fetch when an update is
* received.
*
* If the connection is successful, this method will block on its thread while it reads the
* chunk-encoded HTTP body. When the connection closes, it attempts to reestablish the stream.
*/
private prepareAndBeginRealtimeHttpStream;
/**
* Checks whether connection can be made or not based on some conditions
* @returns booelean
*/
private canEstablishStreamConnection;
private makeRealtimeHttpConnection;
private beginRealtime;
/**
* Adds an observer to the realtime updates.
* @param observer The observer to add.
*/
addObserver(observer: ConfigUpdateObserver): void;
/**
* Removes an observer from the realtime updates.
* @param observer The observer to remove.
*/
removeObserver(observer: ConfigUpdateObserver): void;
/**
* Handles changes to the application's visibility state, managing the real-time connection.
*
* When the application is moved to the background, this method closes the existing
* real-time connection to save resources. When the application returns to the
* foreground, it attempts to re-establish the connection.
*/
private onVisibilityChange;
}

View File

@@ -0,0 +1,104 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CustomSignals, FetchResponse, FetchType } from '../public_types';
/**
* Defines a client, as in https://en.wikipedia.org/wiki/Client%E2%80%93server_model, for the
* Remote Config server (https://firebase.google.com/docs/reference/remote-config/rest).
*
* <p>Abstracts throttle, response cache and network implementation details.
*
* <p>Modeled after the native {@link GlobalFetch} interface, which is relatively modern and
* convenient, but simplified for Remote Config's use case.
*
* Disambiguation: {@link GlobalFetch} interface and the Remote Config service define "fetch"
* methods. The RestClient uses the former to make HTTP calls. This interface abstracts the latter.
*/
export interface RemoteConfigFetchClient {
/**
* @throws if response status is not 200 or 304.
*/
fetch(request: FetchRequest): Promise<FetchResponse>;
}
/**
* Shims a minimal AbortSignal.
*
* <p>AbortController's AbortSignal conveniently decouples fetch timeout logic from other aspects
* of networking, such as retries. Firebase doesn't use AbortController enough to justify a
* polyfill recommendation, like we do with the Fetch API, but this minimal shim can easily be
* swapped out if/when we do.
*/
export declare class RemoteConfigAbortSignal {
listeners: Array<() => void>;
addEventListener(listener: () => void): void;
abort(): void;
}
/**
* Defines per-request inputs for the Remote Config fetch request.
*
* <p>Modeled after the native {@link Request} interface, but simplified for Remote Config's
* use case.
*/
export interface FetchRequest {
/**
* Uses cached config if it is younger than this age.
*
* <p>Required because it's defined by settings, which always have a value.
*
* <p>Comparable to passing `headers = { 'Cache-Control': max-age <maxAge> }` to the native
* Fetch API.
*/
cacheMaxAgeMillis: number;
/**
* An event bus for the signal to abort a request.
*
* <p>Required because all requests should be abortable.
*
* <p>Comparable to the native
* Fetch API's "signal" field on its request configuration object
* https://fetch.spec.whatwg.org/#dom-requestinit-signal.
*
* <p>Disambiguation: Remote Config commonly refers to API inputs as
* "signals". See the private ConfigFetchRequestBody interface for those:
* http://google3/firebase/remote_config/web/src/core/rest_client.ts?l=14&rcl=255515243.
*/
signal: RemoteConfigAbortSignal;
/**
* The ETag header value from the last response.
*
* <p>Optional in case this is the first request.
*
* <p>Comparable to passing `headers = { 'If-None-Match': <eTag> }` to the native Fetch API.
*/
eTag?: string;
/** The custom signals stored for the app instance.
*
* <p>Optional in case no custom signals are set for the instance.
*/
customSignals?: CustomSignals;
/**
* The type of fetch to perform, such as a regular fetch or a real-time fetch.
*
* Optional as not all fetch requests need to be distinguished.
*/
fetchType?: FetchType;
/**
* The number of fetch attempts made so far for this request.
*
* Optional as not all fetch requests are part of a retry series.
*/
fetchAttempt?: number;
}

View File

@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FetchResponse } from '../public_types';
import { RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
import { _FirebaseInstallationsInternal } from '@firebase/installations';
/**
* Implements the Client abstraction for the Remote Config REST API.
*/
export declare class RestClient implements RemoteConfigFetchClient {
private readonly firebaseInstallations;
private readonly sdkVersion;
private readonly namespace;
private readonly projectId;
private readonly apiKey;
private readonly appId;
constructor(firebaseInstallations: _FirebaseInstallationsInternal, sdkVersion: string, namespace: string, projectId: string, apiKey: string, appId: string);
/**
* Fetches from the Remote Config REST API.
*
* @throws a {@link ErrorCode.FETCH_NETWORK} error if {@link GlobalFetch#fetch} can't
* connect to the network.
* @throws a {@link ErrorCode.FETCH_PARSE} error if {@link Response#json} can't parse the
* fetch response.
* @throws a {@link ErrorCode.FETCH_STATUS} error if the service returns an HTTP error status.
*/
fetch(request: FetchRequest): Promise<FetchResponse>;
}

View File

@@ -0,0 +1,50 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FetchResponse } from '../public_types';
import { RemoteConfigAbortSignal, RemoteConfigFetchClient, FetchRequest } from './remote_config_fetch_client';
import { ThrottleMetadata, Storage } from '../storage/storage';
/**
* Supports waiting on a backoff by:
*
* <ul>
* <li>Promisifying setTimeout, so we can set a timeout in our Promise chain</li>
* <li>Listening on a signal bus for abort events, just like the Fetch API</li>
* <li>Failing in the same way the Fetch API fails, so timing out a live request and a throttled
* request appear the same.</li>
* </ul>
*
* <p>Visible for testing.
*/
export declare function setAbortableTimeout(signal: RemoteConfigAbortSignal, throttleEndTimeMillis: number): Promise<void>;
/**
* Decorates a Client with retry logic.
*
* <p>Comparable to CachingClient, but uses backoff logic instead of cache max age and doesn't cache
* responses (because the SDK has no use for error responses).
*/
export declare class RetryingClient implements RemoteConfigFetchClient {
private readonly client;
private readonly storage;
constructor(client: RemoteConfigFetchClient, storage: Storage);
fetch(request: FetchRequest): Promise<FetchResponse>;
/**
* A recursive helper for attempting a fetch request repeatedly.
*
* @throws any non-retriable errors.
*/
attemptFetch(request: FetchRequest, { throttleEndTimeMillis, backoffCount }: ThrottleMetadata): Promise<FetchResponse>;
}

View File

@@ -0,0 +1,23 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { EventEmitter } from './eventEmitter';
export declare class VisibilityMonitor extends EventEmitter {
private visible_;
static getInstance(): VisibilityMonitor;
constructor();
getInitialEvent(eventType: string): boolean[];
}

View File

@@ -0,0 +1,20 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const RC_COMPONENT_NAME = "remote-config";
export declare const RC_CUSTOM_SIGNAL_MAX_ALLOWED_SIGNALS = 100;
export declare const RC_CUSTOM_SIGNAL_KEY_MAX_LENGTH = 250;
export declare const RC_CUSTOM_SIGNAL_VALUE_MAX_LENGTH = 500;

View File

@@ -0,0 +1,87 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ErrorFactory } from '@firebase/util';
export declare const enum ErrorCode {
ALREADY_INITIALIZED = "already-initialized",
REGISTRATION_WINDOW = "registration-window",
REGISTRATION_PROJECT_ID = "registration-project-id",
REGISTRATION_API_KEY = "registration-api-key",
REGISTRATION_APP_ID = "registration-app-id",
STORAGE_OPEN = "storage-open",
STORAGE_GET = "storage-get",
STORAGE_SET = "storage-set",
STORAGE_DELETE = "storage-delete",
FETCH_NETWORK = "fetch-client-network",
FETCH_TIMEOUT = "fetch-timeout",
FETCH_THROTTLE = "fetch-throttle",
FETCH_PARSE = "fetch-client-parse",
FETCH_STATUS = "fetch-status",
INDEXED_DB_UNAVAILABLE = "indexed-db-unavailable",
CUSTOM_SIGNAL_MAX_ALLOWED_SIGNALS = "custom-signal-max-allowed-signals",
CONFIG_UPDATE_STREAM_ERROR = "stream-error",
CONFIG_UPDATE_UNAVAILABLE = "realtime-unavailable",
CONFIG_UPDATE_MESSAGE_INVALID = "update-message-invalid",
CONFIG_UPDATE_NOT_FETCHED = "update-not-fetched",
ANALYTICS_UNAVAILABLE = "analytics-unavailable"
}
interface ErrorParams {
[ErrorCode.STORAGE_OPEN]: {
originalErrorMessage: string | undefined;
};
[ErrorCode.STORAGE_GET]: {
originalErrorMessage: string | undefined;
};
[ErrorCode.STORAGE_SET]: {
originalErrorMessage: string | undefined;
};
[ErrorCode.STORAGE_DELETE]: {
originalErrorMessage: string | undefined;
};
[ErrorCode.FETCH_NETWORK]: {
originalErrorMessage: string;
};
[ErrorCode.FETCH_THROTTLE]: {
throttleEndTimeMillis: number;
};
[ErrorCode.FETCH_PARSE]: {
originalErrorMessage: string;
};
[ErrorCode.FETCH_STATUS]: {
httpStatus: number;
};
[ErrorCode.CUSTOM_SIGNAL_MAX_ALLOWED_SIGNALS]: {
maxSignals: number;
};
[ErrorCode.CONFIG_UPDATE_STREAM_ERROR]: {
originalErrorMessage: string;
};
[ErrorCode.CONFIG_UPDATE_UNAVAILABLE]: {
originalErrorMessage: string;
};
[ErrorCode.CONFIG_UPDATE_MESSAGE_INVALID]: {
originalErrorMessage: string;
};
[ErrorCode.CONFIG_UPDATE_NOT_FETCHED]: {
originalErrorMessage: string;
};
[ErrorCode.ANALYTICS_UNAVAILABLE]: {
originalErrorMessage: string;
};
}
export declare const ERROR_FACTORY: ErrorFactory<ErrorCode, ErrorParams>;
export declare function hasErrorCode(e: Error, errorCode: ErrorCode): boolean;
export {};

View File

@@ -0,0 +1,14 @@
/**
* The Firebase Remote Config Web SDK.
* This SDK does not work in a Node.js environment.
*
* @packageDocumentation
*/
declare global {
interface Window {
FIREBASE_REMOTE_CONFIG_URL_BASE: string;
}
}
export * from './api';
export * from './api2';
export * from './public_types';

View File

@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Attempts to get the most accurate browser language setting.
*
* <p>Adapted from getUserLanguage in packages/auth/src/utils.js for TypeScript.
*
* <p>Defers default language specification to server logic for consistency.
*
* @param navigatorLanguage Enables tests to override read-only {@link NavigatorLanguage}.
*/
export declare function getUserLanguage(navigatorLanguage?: NavigatorLanguage): string;

View File

@@ -0,0 +1,274 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseApp, FirebaseError } from '@firebase/app';
/**
* The Firebase Remote Config service interface.
*
* @public
*/
export interface RemoteConfig {
/**
* The {@link @firebase/app#FirebaseApp} this `RemoteConfig` instance is associated with.
*/
app: FirebaseApp;
/**
* Defines configuration for the Remote Config SDK.
*/
settings: RemoteConfigSettings;
/**
* Object containing default values for configs.
*/
defaultConfig: {
[key: string]: string | number | boolean;
};
/**
* The Unix timestamp in milliseconds of the last <i>successful</i> fetch, or negative one if
* the {@link RemoteConfig} instance either hasn't fetched or initialization
* is incomplete.
*/
fetchTimeMillis: number;
/**
* The status of the last fetch <i>attempt</i>.
*/
lastFetchStatus: FetchStatus;
}
/**
* Defines a self-descriptive reference for config key-value pairs.
*
* @public
*/
export interface FirebaseRemoteConfigObject {
[key: string]: string;
}
/**
* Defines experiment and variant attached to a config parameter.
*
* @public
*/
export interface FirebaseExperimentDescription {
experimentId: string;
variantId: string;
experimentStartTime: string;
triggerTimeoutMillis: string;
timeToLiveMillis: string;
affectedParameterKeys?: string[];
}
/**
* Defines a successful response (200 or 304).
*
* <p>Modeled after the native `Response` interface, but simplified for Remote Config's
* use case.
*
* @public
*/
export interface FetchResponse {
/**
* The HTTP status, which is useful for differentiating success responses with data from
* those without.
*
* <p>The Remote Config client is modeled after the native `Fetch` interface, so
* HTTP status is first-class.
*
* <p>Disambiguation: the fetch response returns a legacy "state" value that is redundant with the
* HTTP status code. The former is normalized into the latter.
*/
status: number;
/**
* Defines the ETag response header value.
*
* <p>Only defined for 200 and 304 responses.
*/
eTag?: string;
/**
* Defines the map of parameters returned as "entries" in the fetch response body.
*
* <p>Only defined for 200 responses.
*/
config?: FirebaseRemoteConfigObject;
/**
* The version number of the config template fetched from the server.
*/
templateVersion?: number;
/**
* Metadata for A/B testing and Remote Config Rollout experiments.
*
* @remarks Only defined for 200 responses.
*/
experiments?: FirebaseExperimentDescription[];
}
/**
* Options for Remote Config initialization.
*
* @public
*/
export interface RemoteConfigOptions {
/**
* The ID of the template to use. If not provided, defaults to "firebase".
*/
templateId?: string;
/**
* Hydrates the state with an initial fetch response.
*/
initialFetchResponse?: FetchResponse;
}
/**
* Indicates the source of a value.
*
* <ul>
* <li>"static" indicates the value was defined by a static constant.</li>
* <li>"default" indicates the value was defined by default config.</li>
* <li>"remote" indicates the value was defined by fetched config.</li>
* </ul>
*
* @public
*/
export type ValueSource = 'static' | 'default' | 'remote';
/**
* Wraps a value with metadata and type-safe getters.
*
* @public
*/
export interface Value {
/**
* Gets the value as a boolean.
*
* The following values (case-insensitive) are interpreted as true:
* "1", "true", "t", "yes", "y", "on". Other values are interpreted as false.
*/
asBoolean(): boolean;
/**
* Gets the value as a number. Comparable to calling <code>Number(value) || 0</code>.
*/
asNumber(): number;
/**
* Gets the value as a string.
*/
asString(): string;
/**
* Gets the {@link ValueSource} for the given key.
*/
getSource(): ValueSource;
}
/**
* Defines configuration options for the Remote Config SDK.
*
* @public
*/
export interface RemoteConfigSettings {
/**
* Defines the maximum age in milliseconds of an entry in the config cache before
* it is considered stale. Defaults to 43200000 (Twelve hours).
*/
minimumFetchIntervalMillis: number;
/**
* Defines the maximum amount of milliseconds to wait for a response when fetching
* configuration from the Remote Config server. Defaults to 60000 (One minute).
*/
fetchTimeoutMillis: number;
}
/**
* Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.
*
* <ul>
* <li>"no-fetch-yet" indicates the {@link RemoteConfig} instance has not yet attempted
* to fetch config, or that SDK initialization is incomplete.</li>
* <li>"success" indicates the last attempt succeeded.</li>
* <li>"failure" indicates the last attempt failed.</li>
* <li>"throttle" indicates the last attempt was rate-limited.</li>
* </ul>
*
* @public
*/
export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
/**
* Defines levels of Remote Config logging.
*
* @public
*/
export type LogLevel = 'debug' | 'error' | 'silent';
/**
* Defines the type for representing custom signals and their values.
*
* <p>The values in CustomSignals must be one of the following types:
*
* <ul>
* <li><code>string</code>
* <li><code>number</code>
* <li><code>null</code>
* </ul>
*
* @public
*/
export interface CustomSignals {
[key: string]: string | number | null;
}
/**
* Contains information about which keys have been updated.
*
* @public
*/
export interface ConfigUpdate {
/**
* Parameter keys whose values have been updated from the currently activated values.
* Includes keys that are added, deleted, or whose value, value source, or metadata has changed.
*/
getUpdatedKeys(): Set<string>;
}
/**
* Observer interface for receiving real-time Remote Config update notifications.
*
* NOTE: Although an `complete` callback can be provided, it will
* never be called because the ConfigUpdate stream is never-ending.
*
* @public
*/
export interface ConfigUpdateObserver {
/**
* Called when a new ConfigUpdate is available.
*/
next: (configUpdate: ConfigUpdate) => void;
/**
* Called if an error occurs during the stream.
*/
error: (error: FirebaseError) => void;
/**
* Called when the stream is gracefully terminated.
*/
complete: () => void;
}
/**
* A function that unsubscribes from a real-time event stream.
*
* @public
*/
export type Unsubscribe = () => void;
/**
* Indicates the type of fetch request.
*
* <ul>
* <li>"BASE" indicates a standard fetch request.</li>
* <li>"REALTIME" indicates a fetch request triggered by a real-time update.</li>
* </ul>
*
* @public
*/
export type FetchType = 'BASE' | 'REALTIME';
declare module '@firebase/component' {
interface NameServiceMapping {
'remote-config': RemoteConfig;
}
}

View File

@@ -0,0 +1,2 @@
import '@firebase/installations';
export declare function registerRemoteConfig(): void;

View File

@@ -0,0 +1,98 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FirebaseApp } from '@firebase/app';
import { RemoteConfig as RemoteConfigType, FetchStatus, RemoteConfigSettings } from './public_types';
import { StorageCache } from './storage/storage_cache';
import { RemoteConfigFetchClient } from './client/remote_config_fetch_client';
import { Storage } from './storage/storage';
import { Logger } from '@firebase/logger';
import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types';
import { Provider } from '@firebase/component';
import { RealtimeHandler } from './client/realtime_handler';
/**
* Encapsulates business logic mapping network and storage dependencies to the public SDK API.
*
* See {@link https://github.com/firebase/firebase-js-sdk/blob/main/packages/firebase/compat/index.d.ts|interface documentation} for method descriptions.
*/
export declare class RemoteConfig implements RemoteConfigType {
readonly app: FirebaseApp;
/**
* @internal
*/
readonly _client: RemoteConfigFetchClient;
/**
* @internal
*/
readonly _storageCache: StorageCache;
/**
* @internal
*/
readonly _storage: Storage;
/**
* @internal
*/
readonly _logger: Logger;
/**
* @internal
*/
readonly _realtimeHandler: RealtimeHandler;
/**
* @internal
*/
readonly _analyticsProvider: Provider<FirebaseAnalyticsInternalName>;
/**
* Tracks completion of initialization promise.
* @internal
*/
_isInitializationComplete: boolean;
/**
* De-duplicates initialization calls.
* @internal
*/
_initializePromise?: Promise<void>;
settings: RemoteConfigSettings;
defaultConfig: {
[key: string]: string | number | boolean;
};
get fetchTimeMillis(): number;
get lastFetchStatus(): FetchStatus;
constructor(app: FirebaseApp,
/**
* @internal
*/
_client: RemoteConfigFetchClient,
/**
* @internal
*/
_storageCache: StorageCache,
/**
* @internal
*/
_storage: Storage,
/**
* @internal
*/
_logger: Logger,
/**
* @internal
*/
_realtimeHandler: RealtimeHandler,
/**
* @internal
*/
_analyticsProvider: Provider<FirebaseAnalyticsInternalName>);
}

View File

@@ -0,0 +1,118 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FetchStatus, CustomSignals } from '@firebase/remote-config-types';
import { FetchResponse, FirebaseRemoteConfigObject } from '../public_types';
/**
* A general-purpose store keyed by app + namespace + {@link
* ProjectNamespaceKeyFieldValue}.
*
* <p>The Remote Config SDK can be used with multiple app installations, and each app can interact
* with multiple namespaces, so this store uses app (ID + name) and namespace as common parent keys
* for a set of key-value pairs. See {@link Storage#createCompositeKey}.
*
* <p>Visible for testing.
*/
export declare const APP_NAMESPACE_STORE = "app_namespace_store";
/**
* Encapsulates metadata concerning throttled fetch requests.
*/
export interface ThrottleMetadata {
backoffCount: number;
throttleEndTimeMillis: number;
}
export interface RealtimeBackoffMetadata {
numFailedStreams: number;
backoffEndTimeMillis: Date;
}
/**
* Provides type-safety for the "key" field used by {@link APP_NAMESPACE_STORE}.
*
* <p>This seems like a small price to avoid potentially subtle bugs caused by a typo.
*/
type ProjectNamespaceKeyFieldValue = 'active_config' | 'active_config_etag' | 'active_experiments' | 'last_fetch_status' | 'last_successful_fetch_timestamp_millis' | 'last_successful_fetch_response' | 'settings' | 'throttle_metadata' | 'custom_signals' | 'realtime_backoff_metadata' | 'last_known_template_version';
export declare function openDatabase(): Promise<IDBDatabase>;
/**
* Abstracts data persistence.
*/
export declare abstract class Storage {
getLastFetchStatus(): Promise<FetchStatus | undefined>;
setLastFetchStatus(status: FetchStatus): Promise<void>;
getLastSuccessfulFetchTimestampMillis(): Promise<number | undefined>;
setLastSuccessfulFetchTimestampMillis(timestamp: number): Promise<void>;
getLastSuccessfulFetchResponse(): Promise<FetchResponse | undefined>;
setLastSuccessfulFetchResponse(response: FetchResponse): Promise<void>;
getActiveConfig(): Promise<FirebaseRemoteConfigObject | undefined>;
setActiveConfig(config: FirebaseRemoteConfigObject): Promise<void>;
getActiveConfigEtag(): Promise<string | undefined>;
setActiveConfigEtag(etag: string): Promise<void>;
getActiveExperiments(): Promise<Set<string> | undefined>;
setActiveExperiments(experiments: Set<string>): Promise<void>;
getThrottleMetadata(): Promise<ThrottleMetadata | undefined>;
setThrottleMetadata(metadata: ThrottleMetadata): Promise<void>;
deleteThrottleMetadata(): Promise<void>;
getCustomSignals(): Promise<CustomSignals | undefined>;
abstract setCustomSignals(customSignals: CustomSignals): Promise<CustomSignals>;
abstract get<T>(key: ProjectNamespaceKeyFieldValue): Promise<T | undefined>;
abstract set<T>(key: ProjectNamespaceKeyFieldValue, value: T): Promise<void>;
abstract delete(key: ProjectNamespaceKeyFieldValue): Promise<void>;
getRealtimeBackoffMetadata(): Promise<RealtimeBackoffMetadata | undefined>;
setRealtimeBackoffMetadata(realtimeMetadata: RealtimeBackoffMetadata): Promise<void>;
getActiveConfigTemplateVersion(): Promise<number | undefined>;
setActiveConfigTemplateVersion(version: number): Promise<void>;
}
export declare class IndexedDbStorage extends Storage {
private readonly appId;
private readonly appName;
private readonly namespace;
private readonly openDbPromise;
/**
* @param appId enables storage segmentation by app (ID + name).
* @param appName enables storage segmentation by app (ID + name).
* @param namespace enables storage segmentation by namespace.
*/
constructor(appId: string, appName: string, namespace: string, openDbPromise?: Promise<IDBDatabase>);
setCustomSignals(customSignals: CustomSignals): Promise<CustomSignals>;
/**
* Gets a value from the database using the provided transaction.
*
* @param key The key of the value to get.
* @param transaction The transaction to use for the operation.
* @returns The value associated with the key, or undefined if no such value exists.
*/
getWithTransaction<T>(key: ProjectNamespaceKeyFieldValue, transaction: IDBTransaction): Promise<T | undefined>;
/**
* Sets a value in the database using the provided transaction.
*
* @param key The key of the value to set.
* @param value The value to set.
* @param transaction The transaction to use for the operation.
* @returns A promise that resolves when the operation is complete.
*/
setWithTransaction<T>(key: ProjectNamespaceKeyFieldValue, value: T, transaction: IDBTransaction): Promise<void>;
get<T>(key: ProjectNamespaceKeyFieldValue): Promise<T | undefined>;
set<T>(key: ProjectNamespaceKeyFieldValue, value: T): Promise<void>;
delete(key: ProjectNamespaceKeyFieldValue): Promise<void>;
createCompositeKey(key: ProjectNamespaceKeyFieldValue): string;
}
export declare class InMemoryStorage extends Storage {
private storage;
get<T>(key: ProjectNamespaceKeyFieldValue): Promise<T>;
set<T>(key: ProjectNamespaceKeyFieldValue, value: T): Promise<void>;
delete(key: ProjectNamespaceKeyFieldValue): Promise<void>;
setCustomSignals(customSignals: CustomSignals): Promise<CustomSignals>;
}
export {};

View File

@@ -0,0 +1,51 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FetchStatus, CustomSignals } from '@firebase/remote-config-types';
import { FirebaseRemoteConfigObject } from '../public_types';
import { Storage } from './storage';
/**
* A memory cache layer over storage to support the SDK's synchronous read requirements.
*/
export declare class StorageCache {
private readonly storage;
constructor(storage: Storage);
/**
* Memory caches.
*/
private lastFetchStatus?;
private lastSuccessfulFetchTimestampMillis?;
private activeConfig?;
private customSignals?;
/**
* Memory-only getters
*/
getLastFetchStatus(): FetchStatus | undefined;
getLastSuccessfulFetchTimestampMillis(): number | undefined;
getActiveConfig(): FirebaseRemoteConfigObject | undefined;
getCustomSignals(): CustomSignals | undefined;
/**
* Read-ahead getter
*/
loadFromStorage(): Promise<void>;
/**
* Write-through setters
*/
setLastFetchStatus(status: FetchStatus): Promise<void>;
setLastSuccessfulFetchTimestampMillis(timestampMillis: number): Promise<void>;
setActiveConfig(activeConfig: FirebaseRemoteConfigObject): Promise<void>;
setCustomSignals(customSignals: CustomSignals): Promise<void>;
}

View File

@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Value as ValueType, ValueSource } from '@firebase/remote-config-types';
export declare class Value implements ValueType {
private readonly _source;
private readonly _value;
constructor(_source: ValueSource, _value?: string);
asString(): string;
asBoolean(): boolean;
asNumber(): number;
getSource(): ValueSource;
}

View File

@@ -0,0 +1,17 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {};