From 657a275357c060aab6ff45aae5e478c8be8d4edd Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:17:01 -0400 Subject: [PATCH 1/7] add connectRemoteConfigEmulator function --- common/api-review/remote-config.api.md | 3 +++ packages/remote-config/src/api.ts | 32 +++++++++++++++++++++++++- packages/remote-config/src/errors.ts | 7 ++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/common/api-review/remote-config.api.md b/common/api-review/remote-config.api.md index 980d8f3d287..d5497b37dcb 100644 --- a/common/api-review/remote-config.api.md +++ b/common/api-review/remote-config.api.md @@ -9,6 +9,9 @@ import { FirebaseApp } from '@firebase/app'; // @public export function activate(remoteConfig: RemoteConfig): Promise; +// @public +export function connectRemoteConfigEmulator(remoteConfig: RemoteConfig, url: string): void; + // @public export function ensureInitialized(remoteConfig: RemoteConfig): Promise; diff --git a/packages/remote-config/src/api.ts b/packages/remote-config/src/api.ts index aeae67d450e..aa3357db01e 100644 --- a/packages/remote-config/src/api.ts +++ b/packages/remote-config/src/api.ts @@ -23,7 +23,7 @@ import { } from './public_types'; import { RemoteConfigAbortSignal } from './client/remote_config_fetch_client'; import { RC_COMPONENT_NAME } from './constants'; -import { ErrorCode, hasErrorCode } from './errors'; +import { ErrorCode, ERROR_FACTORY, hasErrorCode } from './errors'; import { RemoteConfig as RemoteConfigImpl } from './remote_config'; import { Value as ValueImpl } from './value'; import { LogLevel as FirebaseLogLevel } from '@firebase/logger'; @@ -73,6 +73,36 @@ export async function activate(remoteConfig: RemoteConfig): Promise { return true; } +/** + * Configures the Remote Config SDK to talk to a local emulator + * instead of product. + * + * Must be called before performing any fetches against production + * Remote Config. + * + * @param remoteConfig - The {@link RemoteConfig} instance. + * @param url - The url of the local emulator + * + * @public + */ + export function connectRemoteConfigEmulator( + remoteConfig: RemoteConfig, + url: string +) { + const rc = getModularInstance(remoteConfig) as RemoteConfigImpl; + + // To avoid the footgun of fetching from prod first, + // then the emulator, only allow emulator setup + // if no fetches have been made. + if (rc._storageCache.getLastFetchStatus() !== undefined) { + throw ERROR_FACTORY.create(ErrorCode.ALREADY_FETCHED); + } + + window.FIREBASE_REMOTE_CONFIG_URL_BASE = url; + + rc._logger.debug('Connected to the Remote Config emulator.'); +} + /** * Ensures the last activated config are available to the getters. * @param remoteConfig - The {@link RemoteConfig} instance. diff --git a/packages/remote-config/src/errors.ts b/packages/remote-config/src/errors.ts index eac9a25657b..1b19afbfc1b 100644 --- a/packages/remote-config/src/errors.ts +++ b/packages/remote-config/src/errors.ts @@ -31,7 +31,8 @@ export const enum ErrorCode { FETCH_THROTTLE = 'fetch-throttle', FETCH_PARSE = 'fetch-client-parse', FETCH_STATUS = 'fetch-status', - INDEXED_DB_UNAVAILABLE = 'indexed-db-unavailable' + INDEXED_DB_UNAVAILABLE = 'indexed-db-unavailable', + ALREADY_FETCHED = 'already-fetched' } const ERROR_DESCRIPTION_MAP: { readonly [key in ErrorCode]: string } = { @@ -67,7 +68,9 @@ const ERROR_DESCRIPTION_MAP: { readonly [key in ErrorCode]: string } = { [ErrorCode.FETCH_STATUS]: 'Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.', [ErrorCode.INDEXED_DB_UNAVAILABLE]: - 'Indexed DB is not supported by current browser' + 'Indexed DB is not supported by current browser', + [ErrorCode.ALREADY_FETCHED]: + 'Cannot connect to emulator after a fetch has been made.' }; // Note this is effectively a type system binding a code to params. This approach overlaps with the From 2bfee9bd943751422255a1f493ec84e04676c290 Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Thu, 28 Jul 2022 11:02:52 -0400 Subject: [PATCH 2/7] add tests --- packages/remote-config/src/api.ts | 6 ++--- .../remote-config/test/remote_config.test.ts | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/remote-config/src/api.ts b/packages/remote-config/src/api.ts index aa3357db01e..60fdede3edc 100644 --- a/packages/remote-config/src/api.ts +++ b/packages/remote-config/src/api.ts @@ -76,7 +76,7 @@ export async function activate(remoteConfig: RemoteConfig): Promise { /** * Configures the Remote Config SDK to talk to a local emulator * instead of product. - * + * * Must be called before performing any fetches against production * Remote Config. * @@ -85,10 +85,10 @@ export async function activate(remoteConfig: RemoteConfig): Promise { * * @public */ - export function connectRemoteConfigEmulator( +export function connectRemoteConfigEmulator( remoteConfig: RemoteConfig, url: string -) { +): void { const rc = getModularInstance(remoteConfig) as RemoteConfigImpl; // To avoid the footgun of fetching from prod first, diff --git a/packages/remote-config/test/remote_config.test.ts b/packages/remote-config/test/remote_config.test.ts index d275adcad89..6373221bd27 100644 --- a/packages/remote-config/test/remote_config.test.ts +++ b/packages/remote-config/test/remote_config.test.ts @@ -518,4 +518,28 @@ describe('RemoteConfig', () => { ); }); }); + + describe('connectRemoteConfigEmulator', () => { + it('changes the remote config API URL', () => { + const emulatorUrl = 'http://localhost:9200'; + + // init storage as if it had never fetched + storageCache.getLastFetchStatus = sinon.stub().returns(undefined); + + api.connectRemoteConfigEmulator(rc, emulatorUrl); + expect(window.FIREBASE_REMOTE_CONFIG_URL_BASE === emulatorUrl).to.be.true; + }); + + it('can not be called if a fetch has already happened', () => { + const emulatorUrl = 'http://localhost:9200'; + + // init storage as if it had never fetched + storageCache.getLastFetchStatus = sinon.stub().returns('success'); + + const expectedError = ERROR_FACTORY.create(ErrorCode.ALREADY_FETCHED); + expect(() => api.connectRemoteConfigEmulator(rc, emulatorUrl)).to.throw( + expectedError.message + ); + }); + }); }); From 281931bbf30a89e8e5f6c732f09a6115403ae09b Mon Sep 17 00:00:00 2001 From: Jeff <3759507+jhuleatt@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:27:12 -0400 Subject: [PATCH 3/7] add changeset --- .changeset/proud-swans-tie.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/proud-swans-tie.md diff --git a/.changeset/proud-swans-tie.md b/.changeset/proud-swans-tie.md new file mode 100644 index 00000000000..20b9c10cc7e --- /dev/null +++ b/.changeset/proud-swans-tie.md @@ -0,0 +1,5 @@ +--- +"@firebase/remote-config": minor +--- + +[Remote Config] add `connectRemoteConfigEmulator` to allow the SDK to connect to the Remote Config emulator (#6486) From 28aab9f926e93a7c5c0afbf00cd695c0ea7a0eed Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Mon, 12 Dec 2022 13:57:46 -0500 Subject: [PATCH 4/7] fix comment typo --- packages/remote-config/test/remote_config.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/remote-config/test/remote_config.test.ts b/packages/remote-config/test/remote_config.test.ts index 6373221bd27..90d8db1bb29 100644 --- a/packages/remote-config/test/remote_config.test.ts +++ b/packages/remote-config/test/remote_config.test.ts @@ -533,7 +533,7 @@ describe('RemoteConfig', () => { it('can not be called if a fetch has already happened', () => { const emulatorUrl = 'http://localhost:9200'; - // init storage as if it had never fetched + // init storage as if it had already fetched storageCache.getLastFetchStatus = sinon.stub().returns('success'); const expectedError = ERROR_FACTORY.create(ErrorCode.ALREADY_FETCHED); From 20ebf37b1e925084d923060a51234df72f87d58a Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Wed, 21 Dec 2022 13:44:51 -0500 Subject: [PATCH 5/7] trying a build --- packages/analytics/package.json | 2 +- packages/app-check/package.json | 2 +- packages/app-compat/package.json | 2 +- packages/app/package.json | 2 +- packages/auth/package.json | 2 +- packages/database/package.json | 2 +- packages/firestore/package.json | 2 +- packages/functions/package.json | 2 +- packages/installations/package.json | 2 +- packages/messaging/package.json | 2 +- packages/remote-config/package.json | 2 +- packages/storage/package.json | 2 +- packages/util/package.json | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/analytics/package.json b/packages/analytics/package.json index 570dc494363..ca202e878b5 100644 --- a/packages/analytics/package.json +++ b/packages/analytics/package.json @@ -64,7 +64,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/analytics-public.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/app-check/package.json b/packages/app-check/package.json index 1a5605ca93c..4ede5aaea92 100644 --- a/packages/app-check/package.json +++ b/packages/app-check/package.json @@ -61,7 +61,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/app-check-public.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/app-compat/package.json b/packages/app-compat/package.json index 921674d3148..e21a2afa3ba 100644 --- a/packages/app-compat/package.json +++ b/packages/app-compat/package.json @@ -61,7 +61,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/app-compat-public.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/app/package.json b/packages/app/package.json index f0cc58d7f96..897983a9c59 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -60,7 +60,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/app/src/index.d.ts", + "typings": "./dist/app-public.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/auth/package.json b/packages/auth/package.json index d41368e41d6..afc02051639 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -137,7 +137,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/auth.d.ts", + "typings": "./dist/auth-public.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/database/package.json b/packages/database/package.json index 52a50e51ce6..f7c15e4ec44 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -70,7 +70,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/public.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/firestore/package.json b/packages/firestore/package.json index b23650a94f0..af7524c8e10 100644 --- a/packages/firestore/package.json +++ b/packages/firestore/package.json @@ -131,7 +131,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/firestore/src/index.d.ts", + "typings": "./dist/index.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/functions/package.json b/packages/functions/package.json index 236001ad41b..cba31b5b7e7 100644 --- a/packages/functions/package.json +++ b/packages/functions/package.json @@ -64,7 +64,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/functions-public.d.ts", "dependencies": { "@firebase/component": "0.6.3", "@firebase/messaging-interop-types": "0.2.0", diff --git a/packages/installations/package.json b/packages/installations/package.json index 2c7fad71ee5..fefb19fc6fc 100644 --- a/packages/installations/package.json +++ b/packages/installations/package.json @@ -15,7 +15,7 @@ }, "./package.json": "./package.json" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/installations-public.d.ts", "license": "Apache-2.0", "files": [ "dist" diff --git a/packages/messaging/package.json b/packages/messaging/package.json index 6bc60af86f2..d1c762e6db4 100644 --- a/packages/messaging/package.json +++ b/packages/messaging/package.json @@ -24,7 +24,7 @@ }, "./package.json": "./package.json" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/index-public.d.ts", "files": [ "dist", "sw/package.json" diff --git a/packages/remote-config/package.json b/packages/remote-config/package.json index 4e91b392b9e..db097cec9e1 100644 --- a/packages/remote-config/package.json +++ b/packages/remote-config/package.json @@ -62,7 +62,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/remote-config-public.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/storage/package.json b/packages/storage/package.json index 30acec2781a..7b95e2197ef 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -71,5 +71,5 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts" + "typings": "./dist/storage-public.d.ts" } diff --git a/packages/util/package.json b/packages/util/package.json index d8febe2a973..697c892a0ab 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -58,7 +58,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/index.d.ts", + "typings": "./dist/util-public.d.ts", "nyc": { "extension": [ ".ts" From fa979f7e55f7d9c5686c0f60b43263da65e16318 Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Fri, 13 Jan 2023 11:09:28 -0500 Subject: [PATCH 6/7] add useEmulator to compat --- packages/remote-config-compat/src/remoteConfig.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/remote-config-compat/src/remoteConfig.ts b/packages/remote-config-compat/src/remoteConfig.ts index 7617a7f2d0b..6196148dbf1 100644 --- a/packages/remote-config-compat/src/remoteConfig.ts +++ b/packages/remote-config-compat/src/remoteConfig.ts @@ -35,7 +35,8 @@ import { getNumber, getString, getValue, - isSupported + isSupported, + connectRemoteConfigEmulator } from '@firebase/remote-config'; export { isSupported }; @@ -73,6 +74,10 @@ export class RemoteConfigCompatImpl return activate(this._delegate); } + useEmulator(url: string): void { + connectRemoteConfigEmulator(this._delegate, url); + } + ensureInitialized(): Promise { return ensureInitialized(this._delegate); } From 40e184bc835a9bf85e1243b5acfe84679c210e93 Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Thu, 9 Feb 2023 14:12:25 -0500 Subject: [PATCH 7/7] fix package.json files --- packages/analytics/package.json | 2 +- packages/app-check/package.json | 2 +- packages/app-compat/package.json | 2 +- packages/app/package.json | 2 +- packages/auth/package.json | 2 +- packages/database/package.json | 2 +- packages/firestore/package.json | 2 +- packages/functions/package.json | 2 +- packages/installations/package.json | 2 +- packages/messaging/package.json | 2 +- packages/remote-config/package.json | 2 +- packages/storage/package.json | 2 +- packages/util/package.json | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/analytics/package.json b/packages/analytics/package.json index ca202e878b5..570dc494363 100644 --- a/packages/analytics/package.json +++ b/packages/analytics/package.json @@ -64,7 +64,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/analytics-public.d.ts", + "typings": "dist/src/index.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/app-check/package.json b/packages/app-check/package.json index 4ede5aaea92..1a5605ca93c 100644 --- a/packages/app-check/package.json +++ b/packages/app-check/package.json @@ -61,7 +61,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/app-check-public.d.ts", + "typings": "dist/src/index.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/app-compat/package.json b/packages/app-compat/package.json index e21a2afa3ba..921674d3148 100644 --- a/packages/app-compat/package.json +++ b/packages/app-compat/package.json @@ -61,7 +61,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/app-compat-public.d.ts", + "typings": "dist/src/index.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/app/package.json b/packages/app/package.json index 897983a9c59..f0cc58d7f96 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -60,7 +60,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/app-public.d.ts", + "typings": "./dist/app/src/index.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/auth/package.json b/packages/auth/package.json index afc02051639..d41368e41d6 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -137,7 +137,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/auth-public.d.ts", + "typings": "dist/auth.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/database/package.json b/packages/database/package.json index f7c15e4ec44..52a50e51ce6 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -70,7 +70,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/public.d.ts", + "typings": "dist/src/index.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/firestore/package.json b/packages/firestore/package.json index af7524c8e10..b23650a94f0 100644 --- a/packages/firestore/package.json +++ b/packages/firestore/package.json @@ -131,7 +131,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/index.d.ts", + "typings": "dist/firestore/src/index.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/functions/package.json b/packages/functions/package.json index cba31b5b7e7..236001ad41b 100644 --- a/packages/functions/package.json +++ b/packages/functions/package.json @@ -64,7 +64,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/functions-public.d.ts", + "typings": "dist/src/index.d.ts", "dependencies": { "@firebase/component": "0.6.3", "@firebase/messaging-interop-types": "0.2.0", diff --git a/packages/installations/package.json b/packages/installations/package.json index fefb19fc6fc..2c7fad71ee5 100644 --- a/packages/installations/package.json +++ b/packages/installations/package.json @@ -15,7 +15,7 @@ }, "./package.json": "./package.json" }, - "typings": "./dist/installations-public.d.ts", + "typings": "dist/src/index.d.ts", "license": "Apache-2.0", "files": [ "dist" diff --git a/packages/messaging/package.json b/packages/messaging/package.json index d1c762e6db4..6bc60af86f2 100644 --- a/packages/messaging/package.json +++ b/packages/messaging/package.json @@ -24,7 +24,7 @@ }, "./package.json": "./package.json" }, - "typings": "./dist/index-public.d.ts", + "typings": "dist/src/index.d.ts", "files": [ "dist", "sw/package.json" diff --git a/packages/remote-config/package.json b/packages/remote-config/package.json index db097cec9e1..4e91b392b9e 100644 --- a/packages/remote-config/package.json +++ b/packages/remote-config/package.json @@ -62,7 +62,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/remote-config-public.d.ts", + "typings": "dist/src/index.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/storage/package.json b/packages/storage/package.json index 7b95e2197ef..30acec2781a 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -71,5 +71,5 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/storage-public.d.ts" + "typings": "dist/src/index.d.ts" } diff --git a/packages/util/package.json b/packages/util/package.json index 697c892a0ab..d8febe2a973 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -58,7 +58,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "./dist/util-public.d.ts", + "typings": "dist/index.d.ts", "nyc": { "extension": [ ".ts"