@firebase/remote-config 0.6.6 → 0.7.0-canary.cb3bdd812
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.esm.js +737 -8
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/api.d.ts +17 -1
- package/dist/esm/src/client/eventEmitter.d.ts +39 -0
- package/dist/esm/src/client/realtime_handler.d.ts +141 -0
- package/dist/esm/src/client/remote_config_fetch_client.d.ts +13 -1
- package/dist/esm/src/client/visibility_monitor.d.ts +23 -0
- package/dist/esm/src/errors.d.ts +17 -1
- package/dist/esm/src/public_types.d.ts +60 -1
- package/dist/esm/src/remote_config.d.ts +10 -1
- package/dist/esm/src/storage/storage.d.ts +9 -1
- package/dist/index.cjs.js +736 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/remote-config-public.d.ts +81 -0
- package/dist/remote-config.d.ts +81 -0
- package/dist/src/api.d.ts +17 -1
- package/dist/src/client/eventEmitter.d.ts +39 -0
- package/dist/src/client/realtime_handler.d.ts +141 -0
- package/dist/src/client/remote_config_fetch_client.d.ts +13 -1
- package/dist/src/client/visibility_monitor.d.ts +23 -0
- package/dist/src/errors.d.ts +17 -1
- package/dist/src/global_index.d.ts +90 -1
- package/dist/src/public_types.d.ts +60 -1
- package/dist/src/remote_config.d.ts +10 -1
- package/dist/src/storage/storage.d.ts +9 -1
- package/package.json +7 -7
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { FirebaseApp } from '@firebase/app';
|
|
9
|
+
import { FirebaseError } from '@firebase/app';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Makes the last fetched config available to the getters.
|
|
@@ -17,6 +18,42 @@ import { FirebaseApp } from '@firebase/app';
|
|
|
17
18
|
*/
|
|
18
19
|
export declare function activate(remoteConfig: RemoteConfig): Promise<boolean>;
|
|
19
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Contains information about which keys have been updated.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare interface ConfigUpdate {
|
|
27
|
+
/**
|
|
28
|
+
* Parameter keys whose values have been updated from the currently activated values.
|
|
29
|
+
* Includes keys that are added, deleted, or whose value, value source, or metadata has changed.
|
|
30
|
+
*/
|
|
31
|
+
getUpdatedKeys(): Set<string>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Observer interface for receiving real-time Remote Config update notifications.
|
|
36
|
+
*
|
|
37
|
+
* NOTE: Although an `complete` callback can be provided, it will
|
|
38
|
+
* never be called because the ConfigUpdate stream is never-ending.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare interface ConfigUpdateObserver {
|
|
43
|
+
/**
|
|
44
|
+
* Called when a new ConfigUpdate is available.
|
|
45
|
+
*/
|
|
46
|
+
next: (configUpdate: ConfigUpdate) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Called if an error occurs during the stream.
|
|
49
|
+
*/
|
|
50
|
+
error: (error: FirebaseError) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Called when the stream is gracefully terminated.
|
|
53
|
+
*/
|
|
54
|
+
complete: () => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
20
57
|
/**
|
|
21
58
|
* Defines the type for representing custom signals and their values.
|
|
22
59
|
*
|
|
@@ -68,6 +105,8 @@ export declare function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;
|
|
|
68
105
|
*
|
|
69
106
|
* <p>Modeled after the native `Response` interface, but simplified for Remote Config's
|
|
70
107
|
* use case.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
71
110
|
*/
|
|
72
111
|
export declare interface FetchResponse {
|
|
73
112
|
/**
|
|
@@ -93,6 +132,10 @@ export declare interface FetchResponse {
|
|
|
93
132
|
* <p>Only defined for 200 responses.
|
|
94
133
|
*/
|
|
95
134
|
config?: FirebaseRemoteConfigObject;
|
|
135
|
+
/**
|
|
136
|
+
* The version number of the config template fetched from the server.
|
|
137
|
+
*/
|
|
138
|
+
templateVersion?: number;
|
|
96
139
|
}
|
|
97
140
|
|
|
98
141
|
/**
|
|
@@ -110,8 +153,22 @@ export declare interface FetchResponse {
|
|
|
110
153
|
*/
|
|
111
154
|
export declare type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
|
|
112
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Indicates the type of fetch request.
|
|
158
|
+
*
|
|
159
|
+
* <ul>
|
|
160
|
+
* <li>"BASE" indicates a standard fetch request.</li>
|
|
161
|
+
* <li>"REALTIME" indicates a fetch request triggered by a real-time update.</li>
|
|
162
|
+
* </ul>
|
|
163
|
+
*
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
export declare type FetchType = 'BASE' | 'REALTIME';
|
|
167
|
+
|
|
113
168
|
/**
|
|
114
169
|
* Defines a self-descriptive reference for config key-value pairs.
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
115
172
|
*/
|
|
116
173
|
export declare interface FirebaseRemoteConfigObject {
|
|
117
174
|
[key: string]: string;
|
|
@@ -209,6 +266,23 @@ export declare function isSupported(): Promise<boolean>;
|
|
|
209
266
|
*/
|
|
210
267
|
export declare type LogLevel = 'debug' | 'error' | 'silent';
|
|
211
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Starts listening for real-time config updates from the Remote Config backend and automatically
|
|
271
|
+
* fetches updates from the Remote Config backend when they are available.
|
|
272
|
+
*
|
|
273
|
+
* @remarks
|
|
274
|
+
* If a connection to the Remote Config backend is not already open, calling this method will
|
|
275
|
+
* open it. Multiple listeners can be added by calling this method again, but subsequent calls
|
|
276
|
+
* re-use the same connection to the backend.
|
|
277
|
+
*
|
|
278
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
279
|
+
* @param observer - The {@link ConfigUpdateObserver} to be notified of config updates.
|
|
280
|
+
* @returns An {@link Unsubscribe} function to remove the listener.
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
export declare function onConfigUpdate(remoteConfig: RemoteConfig, observer: ConfigUpdateObserver): Unsubscribe;
|
|
285
|
+
|
|
212
286
|
/**
|
|
213
287
|
* The Firebase Remote Config service interface.
|
|
214
288
|
*
|
|
@@ -297,6 +371,13 @@ export declare function setCustomSignals(remoteConfig: RemoteConfig, customSigna
|
|
|
297
371
|
*/
|
|
298
372
|
export declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: LogLevel): void;
|
|
299
373
|
|
|
374
|
+
/**
|
|
375
|
+
* A function that unsubscribes from a real-time event stream.
|
|
376
|
+
*
|
|
377
|
+
* @public
|
|
378
|
+
*/
|
|
379
|
+
export declare type Unsubscribe = () => void;
|
|
380
|
+
|
|
300
381
|
/**
|
|
301
382
|
* Wraps a value with metadata and type-safe getters.
|
|
302
383
|
*
|
package/dist/remote-config.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { FirebaseApp } from '@firebase/app';
|
|
9
|
+
import { FirebaseError } from '@firebase/app';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Makes the last fetched config available to the getters.
|
|
@@ -17,6 +18,42 @@ import { FirebaseApp } from '@firebase/app';
|
|
|
17
18
|
*/
|
|
18
19
|
export declare function activate(remoteConfig: RemoteConfig): Promise<boolean>;
|
|
19
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Contains information about which keys have been updated.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare interface ConfigUpdate {
|
|
27
|
+
/**
|
|
28
|
+
* Parameter keys whose values have been updated from the currently activated values.
|
|
29
|
+
* Includes keys that are added, deleted, or whose value, value source, or metadata has changed.
|
|
30
|
+
*/
|
|
31
|
+
getUpdatedKeys(): Set<string>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Observer interface for receiving real-time Remote Config update notifications.
|
|
36
|
+
*
|
|
37
|
+
* NOTE: Although an `complete` callback can be provided, it will
|
|
38
|
+
* never be called because the ConfigUpdate stream is never-ending.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare interface ConfigUpdateObserver {
|
|
43
|
+
/**
|
|
44
|
+
* Called when a new ConfigUpdate is available.
|
|
45
|
+
*/
|
|
46
|
+
next: (configUpdate: ConfigUpdate) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Called if an error occurs during the stream.
|
|
49
|
+
*/
|
|
50
|
+
error: (error: FirebaseError) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Called when the stream is gracefully terminated.
|
|
53
|
+
*/
|
|
54
|
+
complete: () => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
20
57
|
/**
|
|
21
58
|
* Defines the type for representing custom signals and their values.
|
|
22
59
|
*
|
|
@@ -68,6 +105,8 @@ export declare function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;
|
|
|
68
105
|
*
|
|
69
106
|
* <p>Modeled after the native `Response` interface, but simplified for Remote Config's
|
|
70
107
|
* use case.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
71
110
|
*/
|
|
72
111
|
export declare interface FetchResponse {
|
|
73
112
|
/**
|
|
@@ -93,6 +132,10 @@ export declare interface FetchResponse {
|
|
|
93
132
|
* <p>Only defined for 200 responses.
|
|
94
133
|
*/
|
|
95
134
|
config?: FirebaseRemoteConfigObject;
|
|
135
|
+
/**
|
|
136
|
+
* The version number of the config template fetched from the server.
|
|
137
|
+
*/
|
|
138
|
+
templateVersion?: number;
|
|
96
139
|
}
|
|
97
140
|
|
|
98
141
|
/**
|
|
@@ -110,8 +153,22 @@ export declare interface FetchResponse {
|
|
|
110
153
|
*/
|
|
111
154
|
export declare type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
|
|
112
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Indicates the type of fetch request.
|
|
158
|
+
*
|
|
159
|
+
* <ul>
|
|
160
|
+
* <li>"BASE" indicates a standard fetch request.</li>
|
|
161
|
+
* <li>"REALTIME" indicates a fetch request triggered by a real-time update.</li>
|
|
162
|
+
* </ul>
|
|
163
|
+
*
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
export declare type FetchType = 'BASE' | 'REALTIME';
|
|
167
|
+
|
|
113
168
|
/**
|
|
114
169
|
* Defines a self-descriptive reference for config key-value pairs.
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
115
172
|
*/
|
|
116
173
|
export declare interface FirebaseRemoteConfigObject {
|
|
117
174
|
[key: string]: string;
|
|
@@ -209,6 +266,23 @@ export declare function isSupported(): Promise<boolean>;
|
|
|
209
266
|
*/
|
|
210
267
|
export declare type LogLevel = 'debug' | 'error' | 'silent';
|
|
211
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Starts listening for real-time config updates from the Remote Config backend and automatically
|
|
271
|
+
* fetches updates from the Remote Config backend when they are available.
|
|
272
|
+
*
|
|
273
|
+
* @remarks
|
|
274
|
+
* If a connection to the Remote Config backend is not already open, calling this method will
|
|
275
|
+
* open it. Multiple listeners can be added by calling this method again, but subsequent calls
|
|
276
|
+
* re-use the same connection to the backend.
|
|
277
|
+
*
|
|
278
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
279
|
+
* @param observer - The {@link ConfigUpdateObserver} to be notified of config updates.
|
|
280
|
+
* @returns An {@link Unsubscribe} function to remove the listener.
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
export declare function onConfigUpdate(remoteConfig: RemoteConfig, observer: ConfigUpdateObserver): Unsubscribe;
|
|
285
|
+
|
|
212
286
|
/**
|
|
213
287
|
* The Firebase Remote Config service interface.
|
|
214
288
|
*
|
|
@@ -297,6 +371,13 @@ export declare function setCustomSignals(remoteConfig: RemoteConfig, customSigna
|
|
|
297
371
|
*/
|
|
298
372
|
export declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: LogLevel): void;
|
|
299
373
|
|
|
374
|
+
/**
|
|
375
|
+
* A function that unsubscribes from a real-time event stream.
|
|
376
|
+
*
|
|
377
|
+
* @public
|
|
378
|
+
*/
|
|
379
|
+
export declare type Unsubscribe = () => void;
|
|
380
|
+
|
|
300
381
|
/**
|
|
301
382
|
* Wraps a value with metadata and type-safe getters.
|
|
302
383
|
*
|
package/dist/src/api.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { FirebaseApp } from '@firebase/app';
|
|
18
|
-
import { CustomSignals, LogLevel as RemoteConfigLogLevel, RemoteConfig, Value, RemoteConfigOptions } from './public_types';
|
|
18
|
+
import { CustomSignals, LogLevel as RemoteConfigLogLevel, RemoteConfig, Value, RemoteConfigOptions, ConfigUpdateObserver, Unsubscribe } from './public_types';
|
|
19
19
|
/**
|
|
20
20
|
*
|
|
21
21
|
* @param app - The {@link @firebase/app#FirebaseApp} instance.
|
|
@@ -126,3 +126,19 @@ export declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: Remote
|
|
|
126
126
|
* @public
|
|
127
127
|
*/
|
|
128
128
|
export declare function setCustomSignals(remoteConfig: RemoteConfig, customSignals: CustomSignals): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Starts listening for real-time config updates from the Remote Config backend and automatically
|
|
131
|
+
* fetches updates from the Remote Config backend when they are available.
|
|
132
|
+
*
|
|
133
|
+
* @remarks
|
|
134
|
+
* If a connection to the Remote Config backend is not already open, calling this method will
|
|
135
|
+
* open it. Multiple listeners can be added by calling this method again, but subsequent calls
|
|
136
|
+
* re-use the same connection to the backend.
|
|
137
|
+
*
|
|
138
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
139
|
+
* @param observer - The {@link ConfigUpdateObserver} to be notified of config updates.
|
|
140
|
+
* @returns An {@link Unsubscribe} function to remove the listener.
|
|
141
|
+
*
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
144
|
+
export declare function onConfigUpdate(remoteConfig: RemoteConfig, observer: ConfigUpdateObserver): Unsubscribe;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 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
|
+
* Base class to be used if you want to emit events. Call the constructor with
|
|
19
|
+
* the set of allowed event names.
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class EventEmitter {
|
|
22
|
+
private allowedEvents_;
|
|
23
|
+
private listeners_;
|
|
24
|
+
constructor(allowedEvents_: string[]);
|
|
25
|
+
/**
|
|
26
|
+
* To be overridden by derived classes in order to fire an initial event when
|
|
27
|
+
* somebody subscribes for data.
|
|
28
|
+
*
|
|
29
|
+
* @returns {Array.<*>} Array of parameters to trigger initial event with.
|
|
30
|
+
*/
|
|
31
|
+
abstract getInitialEvent(eventType: string): unknown[];
|
|
32
|
+
/**
|
|
33
|
+
* To be called by derived classes to trigger events.
|
|
34
|
+
*/
|
|
35
|
+
protected trigger(eventType: string, ...varArgs: unknown[]): void;
|
|
36
|
+
on(eventType: string, callback: (a: unknown) => void, context: unknown): void;
|
|
37
|
+
off(eventType: string, callback: (a: unknown) => void, context: unknown): void;
|
|
38
|
+
private validateEventType_;
|
|
39
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 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
|
+
import { _FirebaseInstallationsInternal } from '@firebase/installations';
|
|
18
|
+
import { Logger } from '@firebase/logger';
|
|
19
|
+
import { ConfigUpdateObserver } from '../public_types';
|
|
20
|
+
import { Storage } from '../storage/storage';
|
|
21
|
+
import { StorageCache } from '../storage/storage_cache';
|
|
22
|
+
import { CachingClient } from './caching_client';
|
|
23
|
+
export declare class RealtimeHandler {
|
|
24
|
+
private readonly firebaseInstallations;
|
|
25
|
+
private readonly storage;
|
|
26
|
+
private readonly sdkVersion;
|
|
27
|
+
private readonly namespace;
|
|
28
|
+
private readonly projectId;
|
|
29
|
+
private readonly apiKey;
|
|
30
|
+
private readonly appId;
|
|
31
|
+
private readonly logger;
|
|
32
|
+
private readonly storageCache;
|
|
33
|
+
private readonly cachingClient;
|
|
34
|
+
constructor(firebaseInstallations: _FirebaseInstallationsInternal, storage: Storage, sdkVersion: string, namespace: string, projectId: string, apiKey: string, appId: string, logger: Logger, storageCache: StorageCache, cachingClient: CachingClient);
|
|
35
|
+
private observers;
|
|
36
|
+
private isConnectionActive;
|
|
37
|
+
private isRealtimeDisabled;
|
|
38
|
+
private controller?;
|
|
39
|
+
private reader;
|
|
40
|
+
private httpRetriesRemaining;
|
|
41
|
+
private isInBackground;
|
|
42
|
+
private readonly decoder;
|
|
43
|
+
private isClosingConnection;
|
|
44
|
+
private setRetriesRemaining;
|
|
45
|
+
private propagateError;
|
|
46
|
+
/**
|
|
47
|
+
* Increment the number of failed stream attempts, increase the backoff duration, set the backoff
|
|
48
|
+
* end time to "backoff duration" after `lastFailedStreamTime` and persist the new
|
|
49
|
+
* values to storage metadata.
|
|
50
|
+
*/
|
|
51
|
+
private updateBackoffMetadataWithLastFailedStreamConnectionTime;
|
|
52
|
+
/**
|
|
53
|
+
* Increase the backoff duration with a new end time based on Retry Interval.
|
|
54
|
+
*/
|
|
55
|
+
private updateBackoffMetadataWithRetryInterval;
|
|
56
|
+
/**
|
|
57
|
+
* HTTP status code that the Realtime client should retry on.
|
|
58
|
+
*/
|
|
59
|
+
private isStatusCodeRetryable;
|
|
60
|
+
/**
|
|
61
|
+
* Closes the realtime HTTP connection.
|
|
62
|
+
* Note: This method is designed to be called only once at a time.
|
|
63
|
+
* If a call is already in progress, subsequent calls will be ignored.
|
|
64
|
+
*/
|
|
65
|
+
private closeRealtimeHttpConnection;
|
|
66
|
+
private resetRealtimeBackoff;
|
|
67
|
+
private resetRetryCount;
|
|
68
|
+
/**
|
|
69
|
+
* Assembles the request headers and body and executes the fetch request to
|
|
70
|
+
* establish the real-time streaming connection. This is the "worker" method
|
|
71
|
+
* that performs the actual network communication.
|
|
72
|
+
*/
|
|
73
|
+
private establishRealtimeConnection;
|
|
74
|
+
private getRealtimeUrl;
|
|
75
|
+
private createRealtimeConnection;
|
|
76
|
+
/**
|
|
77
|
+
* Retries HTTP stream connection asyncly in random time intervals.
|
|
78
|
+
*/
|
|
79
|
+
private retryHttpConnectionWhenBackoffEnds;
|
|
80
|
+
private setIsHttpConnectionRunning;
|
|
81
|
+
/**
|
|
82
|
+
* Combines the check and set operations to prevent multiple asynchronous
|
|
83
|
+
* calls from redundantly starting an HTTP connection. This ensures that
|
|
84
|
+
* only one attempt is made at a time.
|
|
85
|
+
*/
|
|
86
|
+
private checkAndSetHttpConnectionFlagIfNotRunning;
|
|
87
|
+
private fetchResponseIsUpToDate;
|
|
88
|
+
private parseAndValidateConfigUpdateMessage;
|
|
89
|
+
private isEventListenersEmpty;
|
|
90
|
+
private getRandomInt;
|
|
91
|
+
private executeAllListenerCallbacks;
|
|
92
|
+
/**
|
|
93
|
+
* Compares two configuration objects and returns a set of keys that have changed.
|
|
94
|
+
* A key is considered changed if it's new, removed, or has a different value.
|
|
95
|
+
*/
|
|
96
|
+
private getChangedParams;
|
|
97
|
+
private fetchLatestConfig;
|
|
98
|
+
private autoFetch;
|
|
99
|
+
/**
|
|
100
|
+
* Processes a stream of real-time messages for configuration updates.
|
|
101
|
+
* This method reassembles fragmented messages, validates and parses the JSON,
|
|
102
|
+
* and automatically fetches a new config if a newer template version is available.
|
|
103
|
+
* It also handles server-specified retry intervals and propagates errors for
|
|
104
|
+
* invalid messages or when real-time updates are disabled.
|
|
105
|
+
*/
|
|
106
|
+
private handleNotifications;
|
|
107
|
+
private listenForNotifications;
|
|
108
|
+
/**
|
|
109
|
+
* Open the real-time connection, begin listening for updates, and auto-fetch when an update is
|
|
110
|
+
* received.
|
|
111
|
+
*
|
|
112
|
+
* If the connection is successful, this method will block on its thread while it reads the
|
|
113
|
+
* chunk-encoded HTTP body. When the connection closes, it attempts to reestablish the stream.
|
|
114
|
+
*/
|
|
115
|
+
private prepareAndBeginRealtimeHttpStream;
|
|
116
|
+
/**
|
|
117
|
+
* Checks whether connection can be made or not based on some conditions
|
|
118
|
+
* @returns booelean
|
|
119
|
+
*/
|
|
120
|
+
private canEstablishStreamConnection;
|
|
121
|
+
private makeRealtimeHttpConnection;
|
|
122
|
+
private beginRealtime;
|
|
123
|
+
/**
|
|
124
|
+
* Adds an observer to the realtime updates.
|
|
125
|
+
* @param observer The observer to add.
|
|
126
|
+
*/
|
|
127
|
+
addObserver(observer: ConfigUpdateObserver): void;
|
|
128
|
+
/**
|
|
129
|
+
* Removes an observer from the realtime updates.
|
|
130
|
+
* @param observer The observer to remove.
|
|
131
|
+
*/
|
|
132
|
+
removeObserver(observer: ConfigUpdateObserver): void;
|
|
133
|
+
/**
|
|
134
|
+
* Handles changes to the application's visibility state, managing the real-time connection.
|
|
135
|
+
*
|
|
136
|
+
* When the application is moved to the background, this method closes the existing
|
|
137
|
+
* real-time connection to save resources. When the application returns to the
|
|
138
|
+
* foreground, it attempts to re-establish the connection.
|
|
139
|
+
*/
|
|
140
|
+
private onVisibilityChange;
|
|
141
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { CustomSignals, FetchResponse } from '../public_types';
|
|
17
|
+
import { CustomSignals, FetchResponse, FetchType } from '../public_types';
|
|
18
18
|
/**
|
|
19
19
|
* Defines a client, as in https://en.wikipedia.org/wiki/Client%E2%80%93server_model, for the
|
|
20
20
|
* Remote Config server (https://firebase.google.com/docs/reference/remote-config/rest).
|
|
@@ -89,4 +89,16 @@ export interface FetchRequest {
|
|
|
89
89
|
* <p>Optional in case no custom signals are set for the instance.
|
|
90
90
|
*/
|
|
91
91
|
customSignals?: CustomSignals;
|
|
92
|
+
/**
|
|
93
|
+
* The type of fetch to perform, such as a regular fetch or a real-time fetch.
|
|
94
|
+
*
|
|
95
|
+
* Optional as not all fetch requests need to be distinguished.
|
|
96
|
+
*/
|
|
97
|
+
fetchType?: FetchType;
|
|
98
|
+
/**
|
|
99
|
+
* The number of fetch attempts made so far for this request.
|
|
100
|
+
*
|
|
101
|
+
* Optional as not all fetch requests are part of a retry series.
|
|
102
|
+
*/
|
|
103
|
+
fetchAttempt?: number;
|
|
92
104
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 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
|
+
import { EventEmitter } from './eventEmitter';
|
|
18
|
+
export declare class VisibilityMonitor extends EventEmitter {
|
|
19
|
+
private visible_;
|
|
20
|
+
static getInstance(): VisibilityMonitor;
|
|
21
|
+
constructor();
|
|
22
|
+
getInitialEvent(eventType: string): boolean[];
|
|
23
|
+
}
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -31,7 +31,11 @@ export declare const enum ErrorCode {
|
|
|
31
31
|
FETCH_PARSE = "fetch-client-parse",
|
|
32
32
|
FETCH_STATUS = "fetch-status",
|
|
33
33
|
INDEXED_DB_UNAVAILABLE = "indexed-db-unavailable",
|
|
34
|
-
CUSTOM_SIGNAL_MAX_ALLOWED_SIGNALS = "custom-signal-max-allowed-signals"
|
|
34
|
+
CUSTOM_SIGNAL_MAX_ALLOWED_SIGNALS = "custom-signal-max-allowed-signals",
|
|
35
|
+
CONFIG_UPDATE_STREAM_ERROR = "stream-error",
|
|
36
|
+
CONFIG_UPDATE_UNAVAILABLE = "realtime-unavailable",
|
|
37
|
+
CONFIG_UPDATE_MESSAGE_INVALID = "update-message-invalid",
|
|
38
|
+
CONFIG_UPDATE_NOT_FETCHED = "update-not-fetched"
|
|
35
39
|
}
|
|
36
40
|
interface ErrorParams {
|
|
37
41
|
[ErrorCode.STORAGE_OPEN]: {
|
|
@@ -61,6 +65,18 @@ interface ErrorParams {
|
|
|
61
65
|
[ErrorCode.CUSTOM_SIGNAL_MAX_ALLOWED_SIGNALS]: {
|
|
62
66
|
maxSignals: number;
|
|
63
67
|
};
|
|
68
|
+
[ErrorCode.CONFIG_UPDATE_STREAM_ERROR]: {
|
|
69
|
+
originalErrorMessage: string;
|
|
70
|
+
};
|
|
71
|
+
[ErrorCode.CONFIG_UPDATE_UNAVAILABLE]: {
|
|
72
|
+
originalErrorMessage: string;
|
|
73
|
+
};
|
|
74
|
+
[ErrorCode.CONFIG_UPDATE_MESSAGE_INVALID]: {
|
|
75
|
+
originalErrorMessage: string;
|
|
76
|
+
};
|
|
77
|
+
[ErrorCode.CONFIG_UPDATE_NOT_FETCHED]: {
|
|
78
|
+
originalErrorMessage: string;
|
|
79
|
+
};
|
|
64
80
|
}
|
|
65
81
|
export declare const ERROR_FACTORY: ErrorFactory<ErrorCode, ErrorParams>;
|
|
66
82
|
export declare function hasErrorCode(e: Error, errorCode: ErrorCode): boolean;
|
|
@@ -185,6 +185,20 @@ declare global {
|
|
|
185
185
|
var __FIREBASE_DEFAULTS__: FirebaseDefaults | undefined;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
declare class FirebaseError extends Error {
|
|
189
|
+
/** The error code for this error. */
|
|
190
|
+
readonly code: string;
|
|
191
|
+
/** Custom data for this error. */
|
|
192
|
+
customData?: Record<string, unknown> | undefined;
|
|
193
|
+
/** The custom name for all FirebaseErrors. */
|
|
194
|
+
readonly name: string;
|
|
195
|
+
constructor(
|
|
196
|
+
/** The error code for this error. */
|
|
197
|
+
code: string, message: string,
|
|
198
|
+
/** Custom data for this error. */
|
|
199
|
+
customData?: Record<string, unknown> | undefined);
|
|
200
|
+
}
|
|
201
|
+
|
|
188
202
|
/**
|
|
189
203
|
* @license
|
|
190
204
|
* Copyright 2020 Google LLC
|
|
@@ -235,6 +249,8 @@ interface RemoteConfig {
|
|
|
235
249
|
}
|
|
236
250
|
/**
|
|
237
251
|
* Defines a self-descriptive reference for config key-value pairs.
|
|
252
|
+
*
|
|
253
|
+
* @public
|
|
238
254
|
*/
|
|
239
255
|
interface FirebaseRemoteConfigObject {
|
|
240
256
|
[key: string]: string;
|
|
@@ -244,6 +260,8 @@ interface FirebaseRemoteConfigObject {
|
|
|
244
260
|
*
|
|
245
261
|
* <p>Modeled after the native `Response` interface, but simplified for Remote Config's
|
|
246
262
|
* use case.
|
|
263
|
+
*
|
|
264
|
+
* @public
|
|
247
265
|
*/
|
|
248
266
|
interface FetchResponse {
|
|
249
267
|
/**
|
|
@@ -269,6 +287,10 @@ interface FetchResponse {
|
|
|
269
287
|
* <p>Only defined for 200 responses.
|
|
270
288
|
*/
|
|
271
289
|
config?: FirebaseRemoteConfigObject;
|
|
290
|
+
/**
|
|
291
|
+
* The version number of the config template fetched from the server.
|
|
292
|
+
*/
|
|
293
|
+
templateVersion?: number;
|
|
272
294
|
}
|
|
273
295
|
/**
|
|
274
296
|
* Options for Remote Config initialization.
|
|
@@ -376,6 +398,57 @@ type LogLevel = 'debug' | 'error' | 'silent';
|
|
|
376
398
|
interface CustomSignals {
|
|
377
399
|
[key: string]: string | number | null;
|
|
378
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Contains information about which keys have been updated.
|
|
403
|
+
*
|
|
404
|
+
* @public
|
|
405
|
+
*/
|
|
406
|
+
interface ConfigUpdate {
|
|
407
|
+
/**
|
|
408
|
+
* Parameter keys whose values have been updated from the currently activated values.
|
|
409
|
+
* Includes keys that are added, deleted, or whose value, value source, or metadata has changed.
|
|
410
|
+
*/
|
|
411
|
+
getUpdatedKeys(): Set<string>;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Observer interface for receiving real-time Remote Config update notifications.
|
|
415
|
+
*
|
|
416
|
+
* NOTE: Although an `complete` callback can be provided, it will
|
|
417
|
+
* never be called because the ConfigUpdate stream is never-ending.
|
|
418
|
+
*
|
|
419
|
+
* @public
|
|
420
|
+
*/
|
|
421
|
+
interface ConfigUpdateObserver {
|
|
422
|
+
/**
|
|
423
|
+
* Called when a new ConfigUpdate is available.
|
|
424
|
+
*/
|
|
425
|
+
next: (configUpdate: ConfigUpdate) => void;
|
|
426
|
+
/**
|
|
427
|
+
* Called if an error occurs during the stream.
|
|
428
|
+
*/
|
|
429
|
+
error: (error: FirebaseError) => void;
|
|
430
|
+
/**
|
|
431
|
+
* Called when the stream is gracefully terminated.
|
|
432
|
+
*/
|
|
433
|
+
complete: () => void;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* A function that unsubscribes from a real-time event stream.
|
|
437
|
+
*
|
|
438
|
+
* @public
|
|
439
|
+
*/
|
|
440
|
+
type Unsubscribe = () => void;
|
|
441
|
+
/**
|
|
442
|
+
* Indicates the type of fetch request.
|
|
443
|
+
*
|
|
444
|
+
* <ul>
|
|
445
|
+
* <li>"BASE" indicates a standard fetch request.</li>
|
|
446
|
+
* <li>"REALTIME" indicates a fetch request triggered by a real-time update.</li>
|
|
447
|
+
* </ul>
|
|
448
|
+
*
|
|
449
|
+
* @public
|
|
450
|
+
*/
|
|
451
|
+
type FetchType = 'BASE' | 'REALTIME';
|
|
379
452
|
declare module '@firebase/component' {
|
|
380
453
|
interface NameServiceMapping {
|
|
381
454
|
'remote-config': RemoteConfig;
|
|
@@ -509,6 +582,22 @@ declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: LogLevel): vo
|
|
|
509
582
|
* @public
|
|
510
583
|
*/
|
|
511
584
|
declare function setCustomSignals(remoteConfig: RemoteConfig, customSignals: CustomSignals): Promise<void>;
|
|
585
|
+
/**
|
|
586
|
+
* Starts listening for real-time config updates from the Remote Config backend and automatically
|
|
587
|
+
* fetches updates from the Remote Config backend when they are available.
|
|
588
|
+
*
|
|
589
|
+
* @remarks
|
|
590
|
+
* If a connection to the Remote Config backend is not already open, calling this method will
|
|
591
|
+
* open it. Multiple listeners can be added by calling this method again, but subsequent calls
|
|
592
|
+
* re-use the same connection to the backend.
|
|
593
|
+
*
|
|
594
|
+
* @param remoteConfig - The {@link RemoteConfig} instance.
|
|
595
|
+
* @param observer - The {@link ConfigUpdateObserver} to be notified of config updates.
|
|
596
|
+
* @returns An {@link Unsubscribe} function to remove the listener.
|
|
597
|
+
*
|
|
598
|
+
* @public
|
|
599
|
+
*/
|
|
600
|
+
declare function onConfigUpdate(remoteConfig: RemoteConfig, observer: ConfigUpdateObserver): Unsubscribe;
|
|
512
601
|
|
|
513
602
|
/**
|
|
514
603
|
* @license
|
|
@@ -563,4 +652,4 @@ declare global {
|
|
|
563
652
|
}
|
|
564
653
|
}
|
|
565
654
|
|
|
566
|
-
export { CustomSignals, FetchResponse, FetchStatus, FirebaseRemoteConfigObject, LogLevel, RemoteConfig, RemoteConfigOptions, RemoteConfigSettings, Value, ValueSource, activate, ensureInitialized, fetchAndActivate, fetchConfig, getAll, getBoolean, getNumber, getRemoteConfig, getString, getValue, isSupported, setCustomSignals, setLogLevel };
|
|
655
|
+
export { ConfigUpdate, ConfigUpdateObserver, CustomSignals, FetchResponse, FetchStatus, FetchType, FirebaseRemoteConfigObject, LogLevel, RemoteConfig, RemoteConfigOptions, RemoteConfigSettings, Unsubscribe, Value, ValueSource, activate, ensureInitialized, fetchAndActivate, fetchConfig, getAll, getBoolean, getNumber, getRemoteConfig, getString, getValue, isSupported, onConfigUpdate, setCustomSignals, setLogLevel };
|