@@ -27,6 +27,7 @@ import { ErrorCode, hasErrorCode } from './errors';
27
27
import { RemoteConfig as RemoteConfigImpl } from './remote_config' ;
28
28
import { Value as ValueImpl } from './value' ;
29
29
import { LogLevel as FirebaseLogLevel } from '@firebase/logger' ;
30
+ import { getModularInstance } from '@firebase/util' ;
30
31
31
32
/**
32
33
*
@@ -36,6 +37,7 @@ import { LogLevel as FirebaseLogLevel } from '@firebase/logger';
36
37
* @public
37
38
*/
38
39
export function getRemoteConfig ( app : FirebaseApp ) : RemoteConfig {
40
+ app = getModularInstance ( app ) ;
39
41
const rcProvider = _getProvider ( app , RC_COMPONENT_NAME ) ;
40
42
return rcProvider . getImmediate ( ) ;
41
43
}
@@ -49,7 +51,7 @@ export function getRemoteConfig(app: FirebaseApp): RemoteConfig {
49
51
* @public
50
52
*/
51
53
export async function activate ( remoteConfig : RemoteConfig ) : Promise < boolean > {
52
- const rc = remoteConfig as RemoteConfigImpl ;
54
+ const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
53
55
const [ lastSuccessfulFetchResponse , activeConfigEtag ] = await Promise . all ( [
54
56
rc . _storage . getLastSuccessfulFetchResponse ( ) ,
55
57
rc . _storage . getActiveConfigEtag ( )
@@ -79,7 +81,7 @@ export async function activate(remoteConfig: RemoteConfig): Promise<boolean> {
79
81
* @public
80
82
*/
81
83
export function ensureInitialized ( remoteConfig : RemoteConfig ) : Promise < void > {
82
- const rc = remoteConfig as RemoteConfigImpl ;
84
+ const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
83
85
if ( ! rc . _initializePromise ) {
84
86
rc . _initializePromise = rc . _storageCache . loadFromStorage ( ) . then ( ( ) => {
85
87
rc . _isInitializationComplete = true ;
@@ -94,7 +96,7 @@ export function ensureInitialized(remoteConfig: RemoteConfig): Promise<void> {
94
96
* @public
95
97
*/
96
98
export async function fetchConfig ( remoteConfig : RemoteConfig ) : Promise < void > {
97
- const rc = remoteConfig as RemoteConfigImpl ;
99
+ const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
98
100
// Aborts the request after the given timeout, causing the fetch call to
99
101
// reject with an AbortError.
100
102
//
@@ -138,7 +140,7 @@ export async function fetchConfig(remoteConfig: RemoteConfig): Promise<void> {
138
140
* @public
139
141
*/
140
142
export function getAll ( remoteConfig : RemoteConfig ) : Record < string , Value > {
141
- const rc = remoteConfig as RemoteConfigImpl ;
143
+ const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
142
144
return getAllKeys (
143
145
rc . _storageCache . getActiveConfig ( ) ,
144
146
rc . defaultConfig
@@ -160,7 +162,7 @@ export function getAll(remoteConfig: RemoteConfig): Record<string, Value> {
160
162
* @public
161
163
*/
162
164
export function getBoolean ( remoteConfig : RemoteConfig , key : string ) : boolean {
163
- return getValue ( remoteConfig , key ) . asBoolean ( ) ;
165
+ return getValue ( getModularInstance ( remoteConfig ) , key ) . asBoolean ( ) ;
164
166
}
165
167
166
168
/**
@@ -176,7 +178,7 @@ export function getBoolean(remoteConfig: RemoteConfig, key: string): boolean {
176
178
* @public
177
179
*/
178
180
export function getNumber ( remoteConfig : RemoteConfig , key : string ) : number {
179
- return getValue ( remoteConfig , key ) . asNumber ( ) ;
181
+ return getValue ( getModularInstance ( remoteConfig ) , key ) . asNumber ( ) ;
180
182
}
181
183
182
184
/**
@@ -191,7 +193,7 @@ export function getNumber(remoteConfig: RemoteConfig, key: string): number {
191
193
* @public
192
194
*/
193
195
export function getString ( remoteConfig : RemoteConfig , key : string ) : string {
194
- return getValue ( remoteConfig , key ) . asString ( ) ;
196
+ return getValue ( getModularInstance ( remoteConfig ) , key ) . asString ( ) ;
195
197
}
196
198
197
199
/**
@@ -205,7 +207,7 @@ export function getString(remoteConfig: RemoteConfig, key: string): string {
205
207
* @public
206
208
*/
207
209
export function getValue ( remoteConfig : RemoteConfig , key : string ) : Value {
208
- const rc = remoteConfig as RemoteConfigImpl ;
210
+ const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
209
211
if ( ! rc . _isInitializationComplete ) {
210
212
rc . _logger . debug (
211
213
`A value was requested for key "${ key } " before SDK initialization completed.` +
@@ -237,7 +239,7 @@ export function setLogLevel(
237
239
remoteConfig : RemoteConfig ,
238
240
logLevel : RemoteConfigLogLevel
239
241
) : void {
240
- const rc = remoteConfig as RemoteConfigImpl ;
242
+ const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
241
243
switch ( logLevel ) {
242
244
case 'debug' :
243
245
rc . _logger . logLevel = FirebaseLogLevel . DEBUG ;
0 commit comments