@@ -23,7 +23,7 @@ import {
23
23
} from './public_types' ;
24
24
import { RemoteConfigAbortSignal } from './client/remote_config_fetch_client' ;
25
25
import { RC_COMPONENT_NAME } from './constants' ;
26
- import { ErrorCode , hasErrorCode } from './errors' ;
26
+ import { ErrorCode , ERROR_FACTORY , 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' ;
@@ -73,6 +73,36 @@ export async function activate(remoteConfig: RemoteConfig): Promise<boolean> {
73
73
return true ;
74
74
}
75
75
76
+ /**
77
+ * Configures the Remote Config SDK to talk to a local emulator
78
+ * instead of product.
79
+ *
80
+ * Must be called before performing any fetches against production
81
+ * Remote Config.
82
+ *
83
+ * @param remoteConfig - The {@link RemoteConfig} instance.
84
+ * @param url - The url of the local emulator
85
+ *
86
+ * @public
87
+ */
88
+ export function connectRemoteConfigEmulator (
89
+ remoteConfig : RemoteConfig ,
90
+ url : string
91
+ ) {
92
+ const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
93
+
94
+ // To avoid the footgun of fetching from prod first,
95
+ // then the emulator, only allow emulator setup
96
+ // if no fetches have been made.
97
+ if ( rc . _storageCache . getLastFetchStatus ( ) !== undefined ) {
98
+ throw ERROR_FACTORY . create ( ErrorCode . ALREADY_FETCHED ) ;
99
+ }
100
+
101
+ window . FIREBASE_REMOTE_CONFIG_URL_BASE = url ;
102
+
103
+ rc . _logger . debug ( 'Connected to the Remote Config emulator.' ) ;
104
+ }
105
+
76
106
/**
77
107
* Ensures the last activated config are available to the getters.
78
108
* @param remoteConfig - The {@link RemoteConfig} instance.
0 commit comments