Skip to content

Commit 960b88e

Browse files
committed
fixing yarn lint errors
1 parent 5b23deb commit 960b88e

File tree

6 files changed

+64
-33
lines changed

6 files changed

+64
-33
lines changed

docs-devsite/remote-config.fetchresponse.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface FetchResponse
2727
| [config](./remote-config.fetchresponse.md#fetchresponseconfig) | [FirebaseRemoteConfigObject](./remote-config.firebaseremoteconfigobject.md#firebaseremoteconfigobject_interface) | Defines the map of parameters returned as "entries" in the fetch response body.<p>Only defined for 200 responses. |
2828
| [eTag](./remote-config.fetchresponse.md#fetchresponseetag) | string | Defines the ETag response header value.<p>Only defined for 200 and 304 responses. |
2929
| [status](./remote-config.fetchresponse.md#fetchresponsestatus) | number | 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 <code>Fetch</code> 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. |
30+
| [templateVersion](./remote-config.fetchresponse.md#fetchresponsetemplateversion) | number | The version number of the config template fetched from the server. |
3031

3132
## FetchResponse.config
3233

@@ -65,3 +66,13 @@ The HTTP status, which is useful for differentiating success responses with data
6566
```typescript
6667
status: number;
6768
```
69+
70+
## FetchResponse.templateVersion
71+
72+
The version number of the config template fetched from the server.
73+
74+
<b>Signature:</b>
75+
76+
```typescript
77+
templateVersion?: number;
78+
```

docs-devsite/remote-config.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The Firebase Remote Config Web SDK. This SDK does not work in a Node.js environm
5353
| Type Alias | Description |
5454
| --- | --- |
5555
| [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> |
56+
| [FetchType](./remote-config.md#fetchtype) | 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> |
5657
| [LogLevel](./remote-config.md#loglevel) | Defines levels of Remote Config logging. |
5758
| [Unsubscribe](./remote-config.md#unsubscribe) | A function that unsubscribes from a real-time event stream. |
5859
| [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> |
@@ -384,6 +385,18 @@ Summarizes the outcome of the last attempt to fetch config from the Firebase Rem
384385
export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
385386
```
386387

388+
## FetchType
389+
390+
Indicates the type of fetch request.
391+
392+
<ul> <li>"BASE" indicates a standard fetch request.</li> <li>"REALTIME" indicates a fetch request triggered by a real-time update.</li> </ul>
393+
394+
<b>Signature:</b>
395+
396+
```typescript
397+
export type FetchType = 'BASE' | 'REALTIME';
398+
```
399+
387400
## LogLevel
388401

389402
Defines levels of Remote Config logging.

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

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class RealtimeHandler {
120120
backoffEndTimeMillis: backoffEndTime,
121121
numFailedStreams
122122
});
123-
this.retryHttpConnectionWhenBackoffEnds();
123+
await this.retryHttpConnectionWhenBackoffEnds();
124124
}
125125

126126
/**
@@ -270,7 +270,7 @@ export class RealtimeHandler {
270270
if (fetchResponse.config != null && fetchResponse.templateVersion) {
271271
return fetchResponse.templateVersion >= lastKnownVersion;
272272
}
273-
return this.storageCache.getLastFetchStatus() === 'success' ;
273+
return this.storageCache.getLastFetchStatus() === 'success';
274274
}
275275

276276
private parseAndValidateConfigUpdateMessage(message: string): string {
@@ -299,30 +299,23 @@ export class RealtimeHandler {
299299
newConfig: FirebaseRemoteConfigObject,
300300
oldConfig: FirebaseRemoteConfigObject
301301
): Set<string> {
302-
const changed = new Set<string>();
302+
const changedKeys = new Set<string>();
303303
const newKeys = new Set(Object.keys(newConfig || {}));
304304
const oldKeys = new Set(Object.keys(oldConfig || {}));
305305

306306
for (const key of newKeys) {
307-
if (!oldKeys.has(key)) {
308-
changed.add(key);
309-
continue;
310-
}
311-
if (
312-
JSON.stringify((newConfig as any)[key]) !==
313-
JSON.stringify((oldConfig as any)[key])
314-
) {
315-
changed.add(key);
316-
continue;
307+
if (!oldKeys.has(key) || newConfig[key] !== oldConfig[key]) {
308+
changedKeys.add(key);
317309
}
318310
}
319311

320312
for (const key of oldKeys) {
321313
if (!newKeys.has(key)) {
322-
changed.add(key);
314+
changedKeys.add(key);
323315
}
324316
}
325-
return changed;
317+
318+
return changedKeys;
326319
}
327320

328321
private async fetchLatestConfig(
@@ -337,12 +330,12 @@ export class RealtimeHandler {
337330
`Fetching config with custom signals: ${JSON.stringify(customSignals)}`
338331
);
339332
}
340-
const abortSignal =new RemoteConfigAbortSignal();
333+
const abortSignal = new RemoteConfigAbortSignal();
341334
try {
342335
const fetchRequest: FetchRequest = {
343336
cacheMaxAgeMillis: 0,
344337
signal: abortSignal,
345-
customSignals: customSignals,
338+
customSignals,
346339
fetchType: 'REALTIME',
347340
fetchAttempt: currentAttempt
348341
};
@@ -471,7 +464,7 @@ export class RealtimeHandler {
471464
if (TEMPLATE_VERSION_KEY in jsonObject) {
472465
const oldTemplateVersion =
473466
await this.storage.getLastKnownTemplateVersion();
474-
let targetTemplateVersion = Number(
467+
const targetTemplateVersion = Number(
475468
jsonObject[TEMPLATE_VERSION_KEY]
476469
);
477470
if (
@@ -497,11 +490,12 @@ export class RealtimeHandler {
497490
retryIntervalSeconds
498491
);
499492
}
500-
} catch (e: any) {
493+
} catch (e: unknown) {
501494
this.logger.error('Unable to parse latest config update message.', e);
495+
const errorMessage = e instanceof Error ? e.message : String(e);
502496
this.propagateError(
503497
ERROR_FACTORY.create(ErrorCode.CONFIG_UPDATE_MESSAGE_INVALID, {
504-
originalErrorMessage: e
498+
originalErrorMessage: errorMessage
505499
})
506500
);
507501
}
@@ -510,7 +504,7 @@ export class RealtimeHandler {
510504
}
511505
}
512506

513-
public async listenForNotifications(
507+
private async listenForNotifications(
514508
reader: ReadableStreamDefaultReader
515509
): Promise<void> {
516510
try {
@@ -521,15 +515,14 @@ export class RealtimeHandler {
521515
if (!this.isInBackground) {
522516
// Otherwise, the real-time server connection was closed due to a transient issue.
523517
this.logger.debug(
524-
'Real-time connection was closed due to an exception.',
525-
e
518+
'Real-time connection was closed due to an exception.'
526519
);
527520
}
528521
} finally {
529522
// Only need to close the reader, beginRealtimeHttpStream will disconnect
530523
// the connection
531524
if (this.reader) {
532-
this.reader.cancel();
525+
void this.reader.cancel();
533526
this.reader = undefined;
534527
}
535528
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ export class RestClient implements RemoteConfigFetchClient {
163163
state = responseBody['state'];
164164
templateVersion = responseBody['templateVersion'];
165165

166-
if (templateVersion != undefined) {
167-
this.storage.setLastKnownTemplateVersion(templateVersion);
166+
if (templateVersion !== undefined) {
167+
await this.storage.setLastKnownTemplateVersion(templateVersion);
168168
}
169169
}
170170

packages/remote-config/src/public_types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export interface RemoteConfig {
5252

5353
/**
5454
* Defines a self-descriptive reference for config key-value pairs.
55+
*
56+
* @public
5557
*/
5658
export interface FirebaseRemoteConfigObject {
5759
[key: string]: string;
@@ -62,6 +64,8 @@ export interface FirebaseRemoteConfigObject {
6264
*
6365
* <p>Modeled after the native `Response` interface, but simplified for Remote Config's
6466
* use case.
67+
*
68+
* @public
6569
*/
6670
export interface FetchResponse {
6771
/**

packages/remote-config/test/client/rest_client.test.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
FetchRequest,
2727
RemoteConfigAbortSignal
2828
} from '../../src/client/remote_config_fetch_client';
29+
import { Storage } from '../../src/storage/storage';
2930

3031
const DEFAULT_REQUEST: FetchRequest = {
3132
cacheMaxAgeMillis: 1,
@@ -34,6 +35,7 @@ const DEFAULT_REQUEST: FetchRequest = {
3435

3536
describe('RestClient', () => {
3637
const firebaseInstallations = {} as FirebaseInstallations;
38+
const storage = {} as Storage;
3739
let client: RestClient;
3840

3941
beforeEach(() => {
@@ -43,14 +45,16 @@ describe('RestClient', () => {
4345
'namespace',
4446
'project-id',
4547
'api-key',
46-
'app-id'
48+
'app-id',
49+
storage
4750
);
4851
firebaseInstallations.getId = sinon
4952
.stub()
5053
.returns(Promise.resolve('fis-id'));
5154
firebaseInstallations.getToken = sinon
5255
.stub()
5356
.returns(Promise.resolve('fis-token'));
57+
storage.setLastKnownTemplateVersion = sinon.stub();
5458
});
5559

5660
describe('fetch', () => {
@@ -74,7 +78,8 @@ describe('RestClient', () => {
7478
status: 200,
7579
eTag: 'etag',
7680
state: 'UPDATE',
77-
entries: { color: 'sparkling' }
81+
entries: { color: 'sparkling' },
82+
templateVersion: 1
7883
};
7984

8085
fetchStub.returns(
@@ -85,7 +90,8 @@ describe('RestClient', () => {
8590
json: () =>
8691
Promise.resolve({
8792
entries: expectedResponse.entries,
88-
state: expectedResponse.state
93+
state: expectedResponse.state,
94+
templateVersion: expectedResponse.templateVersion
8995
})
9096
} as Response)
9197
);
@@ -95,7 +101,8 @@ describe('RestClient', () => {
95101
expect(response).to.deep.eq({
96102
status: expectedResponse.status,
97103
eTag: expectedResponse.eTag,
98-
config: expectedResponse.entries
104+
config: expectedResponse.entries,
105+
templateVersion: expectedResponse.templateVersion
99106
});
100107
});
101108

@@ -184,7 +191,8 @@ describe('RestClient', () => {
184191
expect(response).to.deep.eq({
185192
status: 304,
186193
eTag: 'response-etag',
187-
config: undefined
194+
config: undefined,
195+
templateVersion: undefined
188196
});
189197
});
190198

@@ -222,7 +230,8 @@ describe('RestClient', () => {
222230
expect(response).to.deep.eq({
223231
status: 304,
224232
eTag: 'etag',
225-
config: undefined
233+
config: undefined,
234+
templateVersion: undefined
226235
});
227236
});
228237

@@ -239,7 +248,8 @@ describe('RestClient', () => {
239248
await expect(client.fetch(DEFAULT_REQUEST)).to.eventually.be.deep.eq({
240249
status: 200,
241250
eTag: 'etag',
242-
config: {}
251+
config: {},
252+
templateVersion: undefined
243253
});
244254
}
245255
});

0 commit comments

Comments
 (0)