diff --git a/packages/config/e2e/config.e2e.js b/packages/config/e2e/config.e2e.js index 6764ec76..56d3161f 100644 --- a/packages/config/e2e/config.e2e.js +++ b/packages/config/e2e/config.e2e.js @@ -24,6 +24,23 @@ describe('config()', () => { }); }); + describe('statics', () => { + it('LastFetchStatus', () => { + firebase.config.LastFetchStatus.should.be.an.Object(); + firebase.config.LastFetchStatus.FAILURE.should.equal('failure'); + firebase.config.LastFetchStatus.SUCCESS.should.equal('success'); + firebase.config.LastFetchStatus.NO_FETCH_YET.should.equal('no_fetch_yet'); + firebase.config.LastFetchStatus.THROTTLED.should.equal('throttled'); + }); + + it('ValueSource', () => { + firebase.config.ValueSource.should.be.an.Object(); + firebase.config.ValueSource.REMOTE.should.equal('remote'); + firebase.config.ValueSource.STATIC.should.equal('static'); + firebase.config.ValueSource.DEFAULT.should.equal('default'); + }); + }); + describe('fetch()', () => { it('with expiration provided', () => firebase.config().fetch(0)); it('without expiration provided', () => firebase.config().fetch()); @@ -234,7 +251,6 @@ describe('config()', () => { describe('setDefaultsFromResource()', () => { it('sets defaults from remote_config_resource_test file', async () => { - await Utils.sleep(10000); await firebase.config().setDefaultsFromResource('remote_config_resource_test'); const config = await firebase.config().getValues(['company']); config.company.source.should.equal('default'); diff --git a/packages/config/lib/index.d.ts b/packages/config/lib/index.d.ts index 770dd828..9ed40bbc 100644 --- a/packages/config/lib/index.d.ts +++ b/packages/config/lib/index.d.ts @@ -58,7 +58,123 @@ import { * @firebase config */ export namespace Config { - export interface Statics {} + /** + * A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status. + * + * #### Example + * + * ```js + * firebase.config.LastFetchStatus; + * ``` + */ + export interface LastFetchStatus { + /** + * A value indicating that the last fetch was successful. + * + * ```js + * firebase.config.LastFetchStatus.SUCCESS; + * ``` + */ + SUCCESS: 'success'; + + /** + * A value indicating that the last fetch failed. + * + * ```js + * firebase.config.LastFetchStatus.FAILURE; + * ``` + */ + FAILURE: 'failure'; + + /** + * A value indicating that the last fetch was throttled. + * + * This usually occurs when calling fetch often with a low expiration duration. + * + * ```js + * firebase.config.LastFetchStatus.THROTTLED; + * ``` + */ + THROTTLED: 'throttled'; + + /** + * A value indicating that no fetches have occurred yet. + * + * This usually means you've not called fetch yet. + * + * ```js + * firebase.config.LastFetchStatus.NO_FETCH_YET; + * ``` + */ + NO_FETCH_YET: 'no_fetch_yet'; + } + + /** + * A pseudo-enum for usage with ConfigValue.source to determine the value source. + * + * #### Example + * + * ```js + * firebase.config.ValueSource; + * ``` + */ + export interface ValueSource { + /** + * If the value was retrieved from the server. + * + * ```js + * firebase.config.ValueSource.REMOTE; + * ``` + */ + REMOTE: 'remote'; + /** + * If the value was set as a default value. + * + * ```js + * firebase.config.ValueSource.DEFAULT; + * ``` + */ + DEFAULT: 'default'; + /** + * If no value was found and a static default value was returned instead. + * + * ```js + * firebase.config.ValueSource.STATIC; + * ``` + */ + STATIC: 'static'; + } + + /** + * Firebase Remote Config statics. + * + * ```js + * firebase.config; + * ``` + */ + export interface Statics { + /** + * A pseudo-enum for usage with ConfigValue.source to determine the value source. + * + * #### Example + * + * ```js + * firebase.config.ValueSource; + * ``` + */ + ValueSource: ValueSource; + + /** + * A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status. + * + * #### Example + * + * ```js + * firebase.config.LastFetchStatus; + * ``` + */ + LastFetchStatus: LastFetchStatus; + } /** * An Interface representing a Remote Config value. @@ -71,6 +187,8 @@ export namespace Config { * - `default`: If the value was set as a default value. * - `static`: If no value was found and a static default value was returned instead. * + * See the `ValueSource` statics definition. + * * #### Example * * ```js @@ -156,6 +274,8 @@ export namespace Config { isDeveloperModeEnabled: boolean; /** * The status of the latest Remote Config fetch action. + * + * See the `LastFetchStatus` statics definition. */ lastFetchStatus: 'success' | 'failure' | 'no_fetch_yet' | 'throttled'; } diff --git a/packages/config/lib/index.js b/packages/config/lib/index.js index b816420c..507d2515 100644 --- a/packages/config/lib/index.js +++ b/packages/config/lib/index.js @@ -32,7 +32,19 @@ import { import version from './version'; -const statics = {}; +const statics = { + LastFetchStatus: { + SUCCESS: 'success', + FAILURE: 'failure', + THROTTLED: 'throttled', + NO_FETCH_YET: 'no_fetch_yet', + }, + ValueSource: { + REMOTE: 'remote', + DEFAULT: 'default', + STATIC: 'static', + }, +}; const namespace = 'config'; diff --git a/packages/config/lib/index.js.flow b/packages/config/lib/index.js.flow index d362884d..f8664468 100644 --- a/packages/config/lib/index.js.flow +++ b/packages/config/lib/index.js.flow @@ -18,7 +18,123 @@ import type { ReactNativeFirebaseModule } from '@react-native-firebase/app-types/index.js.flow'; -export interface Statics {} +/** + * A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status. + * + * #### Example + * + * ```js + * firebase.config.LastFetchStatus; + * ``` + */ +export interface LastFetchStatus { + /** + * A value indicating that the last fetch was successful. + * + * ```js + * firebase.config.LastFetchStatus.SUCCESS; + * ``` + */ + SUCCESS: 'success'; + + /** + * A value indicating that the last fetch failed. + * + * ```js + * firebase.config.LastFetchStatus.FAILURE; + * ``` + */ + FAILURE: 'failure'; + + /** + * A value indicating that the last fetch was throttled. + * + * This usually occurs when calling fetch often with a low expiration duration. + * + * ```js + * firebase.config.LastFetchStatus.THROTTLED; + * ``` + */ + THROTTLED: 'throttled'; + + /** + * A value indicating that no fetches have occurred yet. + * + * This usually means you've not called fetch yet. + * + * ```js + * firebase.config.LastFetchStatus.NO_FETCH_YET; + * ``` + */ + NO_FETCH_YET: 'no_fetch_yet'; +} + +/** + * A pseudo-enum for usage with ConfigValue.source to determine the value source. + * + * #### Example + * + * ```js + * firebase.config.ValueSource; + * ``` + */ +export interface ValueSource { + /** + * If the value was retrieved from the server. + * + * ```js + * firebase.config.ValueSource.REMOTE; + * ``` + */ + REMOTE: 'remote'; + /** + * If the value was set as a default value. + * + * ```js + * firebase.config.ValueSource.DEFAULT; + * ``` + */ + DEFAULT: 'default'; + /** + * If no value was found and a static default value was returned instead. + * + * ```js + * firebase.config.ValueSource.STATIC; + * ``` + */ + STATIC: 'static'; +} + +/** + * Firebase Remote Config statics. + * + * ```js + * firebase.config; + * ``` + */ +export interface Statics { + /** + * A pseudo-enum for usage with ConfigValue.source to determine the value source. + * + * #### Example + * + * ```js + * firebase.config.ValueSource; + * ``` + */ + ValueSource: ValueSource; + + /** + * A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status. + * + * #### Example + * + * ```js + * firebase.config.LastFetchStatus; + * ``` + */ + LastFetchStatus: LastFetchStatus; +} /** * An Interface representing a Remote Config value