Skip to content

Commit aadecd6

Browse files
authored
feat(remote-config): expose value source on Web (#979)
* feat(remote-config): expose value source on Web for getBoolean, getNumber, getString, and getAll * fix(remote-config): keep `source` optional to avoid breaking change
1 parent 91a4627 commit aadecd6

4 files changed

Lines changed: 58 additions & 35 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@capacitor-firebase/remote-config': minor
3+
---
4+
5+
feat: expose value `source` on Web for `getBoolean(...)`, `getNumber(...)`, `getString(...)`, and `getAll()`

packages/remote-config/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ Remove all listeners for this plugin.
419419

420420
#### GetBooleanResult
421421

422-
| Prop | Type | Description | Since |
423-
| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
424-
| **`value`** | <code>boolean</code> | The value for the given key as a boolean. | 1.3.0 |
425-
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. Only available for Android and iOS. | 1.3.0 |
422+
| Prop | Type | Description | Since |
423+
| ------------ | --------------------------------------------------------- | ----------------------------------------------- | ----- |
424+
| **`value`** | <code>boolean</code> | The value for the given key as a boolean. | 1.3.0 |
425+
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. | 1.3.0 |
426426

427427

428428
#### GetOptions
@@ -434,18 +434,18 @@ Remove all listeners for this plugin.
434434

435435
#### GetNumberResult
436436

437-
| Prop | Type | Description | Since |
438-
| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
439-
| **`value`** | <code>number</code> | The value for the given key as a number. | 1.3.0 |
440-
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. Only available for Android and iOS. | 1.3.0 |
437+
| Prop | Type | Description | Since |
438+
| ------------ | --------------------------------------------------------- | ----------------------------------------------- | ----- |
439+
| **`value`** | <code>number</code> | The value for the given key as a number. | 1.3.0 |
440+
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. | 1.3.0 |
441441

442442

443443
#### GetStringResult
444444

445-
| Prop | Type | Description | Since |
446-
| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
447-
| **`value`** | <code>string</code> | The value for the given key as a string. | 1.3.0 |
448-
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. Only available for Android and iOS. | 1.3.0 |
445+
| Prop | Type | Description | Since |
446+
| ------------ | --------------------------------------------------------- | ----------------------------------------------- | ----- |
447+
| **`value`** | <code>string</code> | The value for the given key as a string. | 1.3.0 |
448+
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. | 1.3.0 |
449449

450450

451451
#### GetAllResult
@@ -457,10 +457,10 @@ Remove all listeners for this plugin.
457457

458458
#### GetAllResultValue
459459

460-
| Prop | Type | Description | Since |
461-
| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
462-
| **`value`** | <code>string</code> | The value as a string. | 8.3.0 |
463-
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. Only available for Android and iOS. | 8.3.0 |
460+
| Prop | Type | Description | Since |
461+
| ------------ | --------------------------------------------------------- | ----------------------------------------------- | ----- |
462+
| **`value`** | <code>string</code> | The value as a string. | 8.3.0 |
463+
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. | 8.3.0 |
464464

465465

466466
#### GetInfoResult

packages/remote-config/src/definitions.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ export interface GetBooleanResult {
157157
/**
158158
* Indicates at which source this value came from.
159159
*
160-
* Only available for Android and iOS.
161-
*
162160
* @since 1.3.0
163161
*/
164162
source?: GetValueSource;
@@ -177,8 +175,6 @@ export interface GetNumberResult {
177175
/**
178176
* Indicates at which source this value came from.
179177
*
180-
* Only available for Android and iOS.
181-
*
182178
* @since 1.3.0
183179
*/
184180
source?: GetValueSource;
@@ -197,8 +193,6 @@ export interface GetStringResult {
197193
/**
198194
* Indicates at which source this value came from.
199195
*
200-
* Only available for Android and iOS.
201-
*
202196
* @since 1.3.0
203197
*/
204198
source?: GetValueSource;
@@ -229,8 +223,6 @@ export interface GetAllResultValue {
229223
/**
230224
* Indicates at which source this value came from.
231225
*
232-
* Only available for Android and iOS.
233-
*
234226
* @since 8.3.0
235227
*/
236228
source?: GetValueSource;

packages/remote-config/src/web.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import {
44
fetchAndActivate,
55
fetchConfig,
66
getAll,
7-
getBoolean,
8-
getNumber,
97
getRemoteConfig,
10-
getString,
8+
getValue,
119
} from 'firebase/remote-config';
10+
import type { Value } from 'firebase/remote-config';
1211

1312
import type {
1413
AddConfigUpdateListenerOptionsCallback,
@@ -25,7 +24,7 @@ import type {
2524
SetDefaultsOptions,
2625
SetSettingsOptions,
2726
} from './definitions';
28-
import { LastFetchStatus } from './definitions';
27+
import { GetValueSource, LastFetchStatus } from './definitions';
2928

3029
export class FirebaseRemoteConfigWeb
3130
extends WebPlugin
@@ -48,28 +47,41 @@ export class FirebaseRemoteConfigWeb
4847

4948
public async getBoolean(options: GetOptions): Promise<GetBooleanResult> {
5049
const remoteConfig = getRemoteConfig();
51-
const value = getBoolean(remoteConfig, options.key);
52-
return { value };
50+
const value = getValue(remoteConfig, options.key);
51+
return {
52+
value: value.asBoolean(),
53+
source: this.mapValueSource(value.getSource()),
54+
};
5355
}
5456

5557
public async getNumber(options: GetOptions): Promise<GetNumberResult> {
5658
const remoteConfig = getRemoteConfig();
57-
const value = getNumber(remoteConfig, options.key);
58-
return { value };
59+
const value = getValue(remoteConfig, options.key);
60+
return {
61+
value: value.asNumber(),
62+
source: this.mapValueSource(value.getSource()),
63+
};
5964
}
6065

6166
public async getString(options: GetOptions): Promise<GetStringResult> {
6267
const remoteConfig = getRemoteConfig();
63-
const value = getString(remoteConfig, options.key);
64-
return { value };
68+
const value = getValue(remoteConfig, options.key);
69+
return {
70+
value: value.asString(),
71+
source: this.mapValueSource(value.getSource()),
72+
};
6573
}
6674

6775
public async getAll(): Promise<GetAllResult> {
6876
const remoteConfig = getRemoteConfig();
6977
const all = getAll(remoteConfig);
7078
const values: Record<string, GetAllResultValue> = {};
7179
for (const key of Object.keys(all)) {
72-
values[key] = { value: all[key].asString() };
80+
const value = all[key];
81+
values[key] = {
82+
value: value.asString(),
83+
source: this.mapValueSource(value.getSource()),
84+
};
7385
}
7486
return { values };
7587
}
@@ -127,6 +139,20 @@ export class FirebaseRemoteConfigWeb
127139
this.throwUnimplementedError();
128140
}
129141

142+
private mapValueSource(
143+
source: ReturnType<Value['getSource']>,
144+
): GetValueSource {
145+
switch (source) {
146+
case 'default':
147+
return GetValueSource.Default;
148+
case 'remote':
149+
return GetValueSource.Remote;
150+
case 'static':
151+
default:
152+
return GetValueSource.Static;
153+
}
154+
}
155+
130156
private throwUnimplementedError(): never {
131157
throw this.unimplemented('Not implemented on web.');
132158
}

0 commit comments

Comments
 (0)