Skip to content

Commit 77a6aca

Browse files
committed
Fix check failures
1 parent c5d7dfb commit 77a6aca

File tree

12 files changed

+198
-18
lines changed

12 files changed

+198
-18
lines changed

common/api-review/remote-config.api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,23 @@
55
```ts
66

77
import { FirebaseApp } from '@firebase/app';
8+
import { FirebaseError } from '@firebase/app';
89

910
// @public
1011
export function activate(remoteConfig: RemoteConfig): Promise<boolean>;
1112

13+
// @public
14+
export interface ConfigUpdate {
15+
getUpdatedKeys(): Set<string>;
16+
}
17+
18+
// @public
19+
export interface ConfigUpdateObserver {
20+
complete: () => void;
21+
error: (error: FirebaseError) => void;
22+
next: (configUpdate: ConfigUpdate) => void;
23+
}
24+
1225
// @public
1326
export interface CustomSignals {
1427
// (undocumented)
@@ -64,6 +77,9 @@ export function isSupported(): Promise<boolean>;
6477
// @public
6578
export type LogLevel = 'debug' | 'error' | 'silent';
6679

80+
// @public
81+
export function onConfigUpdate(remoteConfig: RemoteConfig, observer: ConfigUpdateObserver): Promise<Unsubscribe>;
82+
6783
// @public
6884
export interface RemoteConfig {
6985
app: FirebaseApp;
@@ -93,6 +109,9 @@ export function setCustomSignals(remoteConfig: RemoteConfig, customSignals: Cust
93109
// @public
94110
export function setLogLevel(remoteConfig: RemoteConfig, logLevel: LogLevel): void;
95111

112+
// @public
113+
export type Unsubscribe = () => void;
114+
96115
// @public
97116
export interface Value {
98117
asBoolean(): boolean;

docs-devsite/_toc.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ toc:
607607
- title: remote-config
608608
path: /docs/reference/js/remote-config.md
609609
section:
610+
- title: ConfigUpdate
611+
path: /docs/reference/js/remote-config.configupdate.md
612+
- title: ConfigUpdateObserver
613+
path: /docs/reference/js/remote-config.configupdateobserver.md
610614
- title: CustomSignals
611615
path: /docs/reference/js/remote-config.customsignals.md
612616
- title: FetchResponse
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# ConfigUpdate interface
13+
Contains information about which keys have been updated.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface ConfigUpdate
19+
```
20+
21+
## Methods
22+
23+
| Method | Description |
24+
| --- | --- |
25+
| [getUpdatedKeys()](./remote-config.configupdate.md#configupdategetupdatedkeys) | 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. |
26+
27+
## ConfigUpdate.getUpdatedKeys()
28+
29+
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.
30+
31+
<b>Signature:</b>
32+
33+
```typescript
34+
getUpdatedKeys(): Set<string>;
35+
```
36+
<b>Returns:</b>
37+
38+
Set&lt;string&gt;
39+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# ConfigUpdateObserver interface
13+
Observer interface for receiving real-time Remote Config update notifications.
14+
15+
NOTE: Although an `complete` callback can be provided, it will never be called because the ConfigUpdate stream is never-ending.
16+
17+
<b>Signature:</b>
18+
19+
```typescript
20+
export interface ConfigUpdateObserver
21+
```
22+
23+
## Properties
24+
25+
| Property | Type | Description |
26+
| --- | --- | --- |
27+
| [complete](./remote-config.configupdateobserver.md#configupdateobservercomplete) | () =&gt; void | Called when the stream is gracefully terminated. |
28+
| [error](./remote-config.configupdateobserver.md#configupdateobservererror) | (error: [FirebaseError](./util.firebaseerror.md#firebaseerror_class)<!-- -->) =&gt; void | Called if an error occurs during the stream. |
29+
| [next](./remote-config.configupdateobserver.md#configupdateobservernext) | (configUpdate: [ConfigUpdate](./remote-config.configupdate.md#configupdate_interface)<!-- -->) =&gt; void | Called when a new ConfigUpdate is available. |
30+
31+
## ConfigUpdateObserver.complete
32+
33+
Called when the stream is gracefully terminated.
34+
35+
<b>Signature:</b>
36+
37+
```typescript
38+
complete: () => void;
39+
```
40+
41+
## ConfigUpdateObserver.error
42+
43+
Called if an error occurs during the stream.
44+
45+
<b>Signature:</b>
46+
47+
```typescript
48+
error: (error: FirebaseError) => void;
49+
```
50+
51+
## ConfigUpdateObserver.next
52+
53+
Called when a new ConfigUpdate is available.
54+
55+
<b>Signature:</b>
56+
57+
```typescript
58+
next: (configUpdate: ConfigUpdate) => void;
59+
```

docs-devsite/remote-config.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The Firebase Remote Config Web SDK. This SDK does not work in a Node.js environm
2828
| [getNumber(remoteConfig, key)](./remote-config.md#getnumber_476c09f) | Gets the value for the given key as a number.<!-- -->Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>. |
2929
| [getString(remoteConfig, key)](./remote-config.md#getstring_476c09f) | Gets the value for the given key as a string. Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>. |
3030
| [getValue(remoteConfig, key)](./remote-config.md#getvalue_476c09f) | Gets the [Value](./remote-config.value.md#value_interface) for the given key. |
31+
| [onConfigUpdate(remoteConfig, observer)](./remote-config.md#onconfigupdate_8b13b26) | Starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the RC backend when they are available.<p>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. |
3132
| [setCustomSignals(remoteConfig, customSignals)](./remote-config.md#setcustomsignals_aeeb95e) | Sets the custom signals for the app instance. |
3233
| [setLogLevel(remoteConfig, logLevel)](./remote-config.md#setloglevel_039a45b) | Defines the log level to use. |
3334
| <b>function()</b> |
@@ -37,6 +38,8 @@ The Firebase Remote Config Web SDK. This SDK does not work in a Node.js environm
3738

3839
| Interface | Description |
3940
| --- | --- |
41+
| [ConfigUpdate](./remote-config.configupdate.md#configupdate_interface) | Contains information about which keys have been updated. |
42+
| [ConfigUpdateObserver](./remote-config.configupdateobserver.md#configupdateobserver_interface) | Observer interface for receiving real-time Remote Config update notifications.<!-- -->NOTE: Although an <code>complete</code> callback can be provided, it will never be called because the ConfigUpdate stream is never-ending. |
4043
| [CustomSignals](./remote-config.customsignals.md#customsignals_interface) | 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> |
4144
| [FetchResponse](./remote-config.fetchresponse.md#fetchresponse_interface) | Defines a successful response (200 or 304).<p>Modeled after the native <code>Response</code> interface, but simplified for Remote Config's use case. |
4245
| [FirebaseRemoteConfigObject](./remote-config.firebaseremoteconfigobject.md#firebaseremoteconfigobject_interface) | Defines a self-descriptive reference for config key-value pairs. |
@@ -51,6 +54,7 @@ The Firebase Remote Config Web SDK. This SDK does not work in a Node.js environm
5154
| --- | --- |
5255
| [FetchStatus](./remote-config.md#fetchstatus) | Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.<ul> <li>"no-fetch-yet" indicates the [RemoteConfig](./remote-config.remoteconfig.md#remoteconfig_interface) 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> |
5356
| [LogLevel](./remote-config.md#loglevel) | Defines levels of Remote Config logging. |
57+
| [Unsubscribe](./remote-config.md#unsubscribe) | A function that unsubscribes from a real-time event stream. |
5458
| [ValueSource](./remote-config.md#valuesource) | 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> |
5559

5660
## function(app, ...)
@@ -282,6 +286,31 @@ export declare function getValue(remoteConfig: RemoteConfig, key: string): Value
282286

283287
The value for the given key.
284288

289+
### onConfigUpdate(remoteConfig, observer) {:#onconfigupdate_8b13b26}
290+
291+
Starts listening for real-time config updates from the Remote Config backend and automatically fetches updates from the RC backend when they are available.
292+
293+
<p>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.
294+
295+
<b>Signature:</b>
296+
297+
```typescript
298+
export declare function onConfigUpdate(remoteConfig: RemoteConfig, observer: ConfigUpdateObserver): Promise<Unsubscribe>;
299+
```
300+
301+
#### Parameters
302+
303+
| Parameter | Type | Description |
304+
| --- | --- | --- |
305+
| remoteConfig | [RemoteConfig](./remote-config.remoteconfig.md#remoteconfig_interface) | The [RemoteConfig](./remote-config.remoteconfig.md#remoteconfig_interface) instance. |
306+
| observer | [ConfigUpdateObserver](./remote-config.configupdateobserver.md#configupdateobserver_interface) | The [ConfigUpdateObserver](./remote-config.configupdateobserver.md#configupdateobserver_interface) to be notified of config updates. |
307+
308+
<b>Returns:</b>
309+
310+
Promise&lt;[Unsubscribe](./remote-config.md#unsubscribe)<!-- -->&gt;
311+
312+
An [Unsubscribe](./remote-config.md#unsubscribe) function to remove the listener.
313+
285314
### setCustomSignals(remoteConfig, customSignals) {:#setcustomsignals_aeeb95e}
286315

287316
Sets the custom signals for the app instance.
@@ -365,6 +394,16 @@ Defines levels of Remote Config logging.
365394
export type LogLevel = 'debug' | 'error' | 'silent';
366395
```
367396

397+
## Unsubscribe
398+
399+
A function that unsubscribes from a real-time event stream.
400+
401+
<b>Signature:</b>
402+
403+
```typescript
404+
export type Unsubscribe = () => void;
405+
```
406+
368407
## ValueSource
369408

370409
Indicates the source of a value.

packages/remote-config/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@firebase/logger": "0.5.0",
4545
"@firebase/util": "1.13.0",
4646
"@firebase/component": "0.7.0",
47+
"date-fns": "4.1.0",
4748
"tslib": "^2.1.0"
4849
},
4950
"license": "Apache-2.0",

packages/remote-config/src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,12 @@ export async function setCustomSignals(
369369
*
370370
* @public
371371
*/
372-
export function onConfigUpdate(
372+
export async function onConfigUpdate(
373373
remoteConfig: RemoteConfig,
374374
observer: ConfigUpdateObserver
375-
): Unsubscribe {
375+
): Promise<Unsubscribe> {
376376
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
377-
rc._realtimeHandler.addObserver(observer);
377+
await rc._realtimeHandler.addObserver(observer);
378378
return () => {
379379
rc._realtimeHandler.removeObserver(observer);
380380
};

packages/remote-config/src/client/realtime_handler.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { _FirebaseInstallationsInternal } from '@firebase/installations';
19+
import { Logger } from '@firebase/logger';
1920
import { ConfigUpdateObserver } from '../public_types';
2021
import { calculateBackoffMillis, FirebaseError } from '@firebase/util';
2122
import { ERROR_FACTORY, ErrorCode } from '../errors';
@@ -36,9 +37,10 @@ export class RealtimeHandler {
3637
private readonly namespace: string,
3738
private readonly projectId: string,
3839
private readonly apiKey: string,
39-
private readonly appId: string
40+
private readonly appId: string,
41+
private readonly logger: Logger
4042
) {
41-
this.setRetriesRemaining();
43+
void this.setRetriesRemaining();
4244
}
4345

4446
private observers: Set<ConfigUpdateObserver> =
@@ -49,7 +51,7 @@ export class RealtimeHandler {
4951
private reader: ReadableStreamDefaultReader | undefined;
5052
private httpRetriesRemaining: number = ORIGINAL_RETRIES;
5153

52-
private async setRetriesRemaining() {
54+
private async setRetriesRemaining(): Promise<void> {
5355
// Retrieve number of remaining retries from last session. The minimum retry count being one.
5456
const metadata = await this.storage.getRealtimeBackoffMetadata();
5557
const numFailedStreams = metadata?.numFailedStreams || 0;
@@ -59,7 +61,7 @@ export class RealtimeHandler {
5961
);
6062
}
6163

62-
private propagateError = (e: FirebaseError) =>
64+
private propagateError = (e: FirebaseError): void =>
6365
this.observers.forEach(o => o.error?.(e));
6466

6567
/**
@@ -107,7 +109,7 @@ export class RealtimeHandler {
107109
}
108110

109111
if (this.reader) {
110-
this.reader.cancel();
112+
void this.reader.cancel();
111113
this.reader = undefined;
112114
}
113115
}
@@ -150,7 +152,7 @@ export class RealtimeHandler {
150152
const requestBody = {
151153
project: this.projectId,
152154
namespace: this.namespace,
153-
lastKnownVersionNumber: lastKnownVersionNumber,
155+
lastKnownVersionNumber,
154156
appId: this.appId,
155157
sdkVersion: this.sdkVersion,
156158
appInstanceId: installationId
@@ -160,7 +162,7 @@ export class RealtimeHandler {
160162
method: 'POST',
161163
headers,
162164
body: JSON.stringify(requestBody),
163-
signal: signal
165+
signal
164166
});
165167
return response;
166168
}
@@ -181,12 +183,13 @@ export class RealtimeHandler {
181183
]);
182184
this.controller = new AbortController();
183185
const url = this.getRealtimeUrl();
184-
return await this.establishRealtimeConnection(
186+
const realtimeConnection = await this.establishRealtimeConnection(
185187
url,
186188
installationId,
187189
installationTokenResult,
188190
this.controller.signal
189191
);
192+
return realtimeConnection;
190193
}
191194

192195
/**
@@ -205,7 +208,7 @@ export class RealtimeHandler {
205208
).getTime();
206209
const currentTime = Date.now();
207210
const retryMillis = Math.max(0, backoffEndTime - currentTime);
208-
this.makeRealtimeHttpConnection(retryMillis);
211+
await this.makeRealtimeHttpConnection(retryMillis);
209212
}
210213

211214
private setIsHttpConnectionRunning(connectionRunning: boolean): void {
@@ -259,7 +262,7 @@ export class RealtimeHandler {
259262
}
260263
} catch (error) {
261264
//there might have been a transient error so the client will retry the connection.
262-
console.error(
265+
this.logger.error(
263266
'Exception connecting to real-time RC backend. Retrying the connection...:',
264267
error
265268
);
@@ -281,7 +284,7 @@ export class RealtimeHandler {
281284
if (connectionFailed || response?.ok) {
282285
await this.retryHttpConnectionWhenBackoffEnds();
283286
} else {
284-
let errorMessage = `Unable to connect to the server. HTTP status code: ${responseCode}`;
287+
const errorMessage = `Unable to connect to the server. HTTP status code: ${responseCode}`;
285288
const firebaseError = ERROR_FACTORY.create(
286289
ErrorCode.CONFIG_UPDATE_STREAM_ERROR,
287290
{

packages/remote-config/src/register.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export function registerRemoteConfig(): void {
115115
namespace,
116116
projectId,
117117
apiKey,
118-
appId
118+
appId,
119+
logger
119120
);
120121

121122
const remoteConfigInstance = new RemoteConfigImpl(

packages/remote-config/src/storage/storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ export abstract class Storage {
197197
}
198198

199199
setRealtimeBackoffMetadata(
200-
realtime_metadata: RealtimeBackoffMetadata
200+
realtimeMetadata: RealtimeBackoffMetadata
201201
): Promise<void> {
202202
return this.set<RealtimeBackoffMetadata>(
203203
'realtime_backoff_metadata',
204-
realtime_metadata
204+
realtimeMetadata
205205
);
206206
}
207207
}

0 commit comments

Comments
 (0)