UNPKG

7.28 kBTypeScriptView Raw
1/**
2 * Firebase Remote Config
3 *
4 * @packageDocumentation
5 */
6
7import { FirebaseApp } from '@firebase/app';
8
9/**
10 * Makes the last fetched config available to the getters.
11 * @param remoteConfig - The {@link RemoteConfig} instance.
12 * @returns A `Promise` which resolves to true if the current call activated the fetched configs.
13 * If the fetched configs were already activated, the `Promise` will resolve to false.
14 *
15 * @public
16 */
17export declare function activate(remoteConfig: RemoteConfig): Promise<boolean>;
18
19/**
20 * Ensures the last activated config are available to the getters.
21 * @param remoteConfig - The {@link RemoteConfig} instance.
22 *
23 * @returns A `Promise` that resolves when the last activated config is available to the getters.
24 * @public
25 */
26export declare function ensureInitialized(remoteConfig: RemoteConfig): Promise<void>;
27
28/**
29 *
30 * Performs fetch and activate operations, as a convenience.
31 *
32 * @param remoteConfig - The {@link RemoteConfig} instance.
33 *
34 * @returns A `Promise` which resolves to true if the current call activated the fetched configs.
35 * If the fetched configs were already activated, the `Promise` will resolve to false.
36 *
37 * @public
38 */
39export declare function fetchAndActivate(remoteConfig: RemoteConfig): Promise<boolean>;
40
41/**
42 * Fetches and caches configuration from the Remote Config service.
43 * @param remoteConfig - The {@link RemoteConfig} instance.
44 * @public
45 */
46export declare function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;
47
48/**
49 * Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.
50 *
51 * <ul>
52 * <li>"no-fetch-yet" indicates the {@link RemoteConfig} instance has not yet attempted
53 * to fetch config, or that SDK initialization is incomplete.</li>
54 * <li>"success" indicates the last attempt succeeded.</li>
55 * <li>"failure" indicates the last attempt failed.</li>
56 * <li>"throttle" indicates the last attempt was rate-limited.</li>
57 * </ul>
58 *
59 * @public
60 */
61export declare type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
62
63/**
64 * Gets all config.
65 *
66 * @param remoteConfig - The {@link RemoteConfig} instance.
67 * @returns All config.
68 *
69 * @public
70 */
71export declare function getAll(remoteConfig: RemoteConfig): Record<string, Value>;
72
73/**
74 * Gets the value for the given key as a boolean.
75 *
76 * Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
77 *
78 * @param remoteConfig - The {@link RemoteConfig} instance.
79 * @param key - The name of the parameter.
80 *
81 * @returns The value for the given key as a boolean.
82 * @public
83 */
84export declare function getBoolean(remoteConfig: RemoteConfig, key: string): boolean;
85
86/**
87 * Gets the value for the given key as a number.
88 *
89 * Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
90 *
91 * @param remoteConfig - The {@link RemoteConfig} instance.
92 * @param key - The name of the parameter.
93 *
94 * @returns The value for the given key as a number.
95 *
96 * @public
97 */
98export declare function getNumber(remoteConfig: RemoteConfig, key: string): number;
99
100/**
101 *
102 * @param app - The {@link @firebase/app#FirebaseApp} instance.
103 * @returns A {@link RemoteConfig} instance.
104 *
105 * @public
106 */
107export declare function getRemoteConfig(app?: FirebaseApp): RemoteConfig;
108
109/**
110 * Gets the value for the given key as a string.
111 * Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
112 *
113 * @param remoteConfig - The {@link RemoteConfig} instance.
114 * @param key - The name of the parameter.
115 *
116 * @returns The value for the given key as a string.
117 *
118 * @public
119 */
120export declare function getString(remoteConfig: RemoteConfig, key: string): string;
121
122/**
123 * Gets the {@link Value} for the given key.
124 *
125 * @param remoteConfig - The {@link RemoteConfig} instance.
126 * @param key - The name of the parameter.
127 *
128 * @returns The value for the given key.
129 *
130 * @public
131 */
132export declare function getValue(remoteConfig: RemoteConfig, key: string): Value;
133
134/**
135 * This method provides two different checks:
136 *
137 * 1. Check if IndexedDB exists in the browser environment.
138 * 2. Check if the current browser context allows IndexedDB `open()` calls.
139 *
140 * @returns A `Promise` which resolves to true if a {@link RemoteConfig} instance
141 * can be initialized in this environment, or false if it cannot.
142 * @public
143 */
144export declare function isSupported(): Promise<boolean>;
145
146/**
147 * Defines levels of Remote Config logging.
148 *
149 * @public
150 */
151export declare type LogLevel = 'debug' | 'error' | 'silent';
152
153/**
154 * The Firebase Remote Config service interface.
155 *
156 * @public
157 */
158export declare interface RemoteConfig {
159 /**
160 * The {@link @firebase/app#FirebaseApp} this `RemoteConfig` instance is associated with.
161 */
162 app: FirebaseApp;
163 /**
164 * Defines configuration for the Remote Config SDK.
165 */
166 settings: RemoteConfigSettings;
167 /**
168 * Object containing default values for configs.
169 */
170 defaultConfig: {
171 [key: string]: string | number | boolean;
172 };
173 /**
174 * The Unix timestamp in milliseconds of the last <i>successful</i> fetch, or negative one if
175 * the {@link RemoteConfig} instance either hasn't fetched or initialization
176 * is incomplete.
177 */
178 fetchTimeMillis: number;
179 /**
180 * The status of the last fetch <i>attempt</i>.
181 */
182 lastFetchStatus: FetchStatus;
183}
184
185/**
186 * Defines configuration options for the Remote Config SDK.
187 *
188 * @public
189 */
190export declare interface RemoteConfigSettings {
191 /**
192 * Defines the maximum age in milliseconds of an entry in the config cache before
193 * it is considered stale. Defaults to 43200000 (Twelve hours).
194 */
195 minimumFetchIntervalMillis: number;
196 /**
197 * Defines the maximum amount of milliseconds to wait for a response when fetching
198 * configuration from the Remote Config server. Defaults to 60000 (One minute).
199 */
200 fetchTimeoutMillis: number;
201}
202
203/**
204 * Defines the log level to use.
205 *
206 * @param remoteConfig - The {@link RemoteConfig} instance.
207 * @param logLevel - The log level to set.
208 *
209 * @public
210 */
211export declare function setLogLevel(remoteConfig: RemoteConfig, logLevel: LogLevel): void;
212
213/**
214 * Wraps a value with metadata and type-safe getters.
215 *
216 * @public
217 */
218export declare interface Value {
219 /**
220 * Gets the value as a boolean.
221 *
222 * The following values (case insensitive) are interpreted as true:
223 * "1", "true", "t", "yes", "y", "on". Other values are interpreted as false.
224 */
225 asBoolean(): boolean;
226 /**
227 * Gets the value as a number. Comparable to calling <code>Number(value) || 0</code>.
228 */
229 asNumber(): number;
230 /**
231 * Gets the value as a string.
232 */
233 asString(): string;
234 /**
235 * Gets the {@link ValueSource} for the given key.
236 */
237 getSource(): ValueSource;
238}
239
240/**
241 * Indicates the source of a value.
242 *
243 * <ul>
244 * <li>"static" indicates the value was defined by a static constant.</li>
245 * <li>"default" indicates the value was defined by default config.</li>
246 * <li>"remote" indicates the value was defined by fetched config.</li>
247 * </ul>
248 *
249 * @public
250 */
251export declare type ValueSource = 'static' | 'default' | 'remote';
252
253export { }