From d095ad3e5026d82513b0c97105b14944a77d0b2e Mon Sep 17 00:00:00 2001 From: Feiyang Date: Mon, 3 May 2021 23:24:20 -0700 Subject: [PATCH] Log correct version for v9 Firestore and RTDB (#4842) * report correct version for v8 and v9 * set correct version for firestore compat * use SDK_VERSION from app-exp * use v8 version by default * update lite * update lock * fix lint errors * address comments * get SDK_VERSION value correctly * fix lint --- packages/database/exp/register.ts | 10 ++++++++-- packages/firestore/compat/index.node.ts | 2 ++ packages/firestore/compat/index.rn.ts | 3 ++- packages/firestore/compat/index.ts | 2 ++ packages/firestore/exp/register.ts | 8 +++++++- packages/firestore/lite/register.ts | 8 +++++++- packages/firestore/src/core/version.ts | 6 +++++- packages/firestore/src/remote/rest_connection.ts | 8 ++++++-- yarn.lock | 11 ++++++++--- 9 files changed, 47 insertions(+), 11 deletions(-) diff --git a/packages/database/exp/register.ts b/packages/database/exp/register.ts index 9814f3f2a2e..86ae47e876a 100644 --- a/packages/database/exp/register.ts +++ b/packages/database/exp/register.ts @@ -15,11 +15,16 @@ * limitations under the License. */ -// eslint-disable-next-line import/no-extraneous-dependencies -import { _registerComponent, registerVersion } from '@firebase/app-exp'; +import { + _registerComponent, + registerVersion, + SDK_VERSION + // eslint-disable-next-line import/no-extraneous-dependencies +} from '@firebase/app-exp'; import { Component, ComponentType } from '@firebase/component'; import { name, version } from '../package.json'; +import { setSDKVersion } from '../src/core/version'; import { FirebaseDatabase, repoManagerDatabaseFromApp @@ -32,6 +37,7 @@ declare module '@firebase/component' { } export function registerDatabase(variant?: string): void { + setSDKVersion(SDK_VERSION); _registerComponent( new Component( 'database-exp', diff --git a/packages/firestore/compat/index.node.ts b/packages/firestore/compat/index.node.ts index 6370fd30631..21ecd90dbf1 100644 --- a/packages/firestore/compat/index.node.ts +++ b/packages/firestore/compat/index.node.ts @@ -20,6 +20,7 @@ import firebase from '@firebase/app-compat'; import { FirebaseNamespace } from '@firebase/app-types'; import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database'; +import { setSDKVersion } from '../src/core/version'; import { registerBundle } from './bundle'; import { configureForFirebase } from './config'; @@ -30,6 +31,7 @@ import { name, version } from './package.json'; * Persistence can be enabled via `firebase.firestore().enablePersistence()`. */ export function registerFirestore(instance: FirebaseNamespace): void { + setSDKVersion(instance.SDK_VERSION); configureForFirebase( instance, (app, firestoreExp) => diff --git a/packages/firestore/compat/index.rn.ts b/packages/firestore/compat/index.rn.ts index a07370c6adb..32f2e0dab4a 100644 --- a/packages/firestore/compat/index.rn.ts +++ b/packages/firestore/compat/index.rn.ts @@ -20,16 +20,17 @@ import firebase from '@firebase/app-compat'; import { FirebaseNamespace } from '@firebase/app-types'; import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database'; +import { setSDKVersion } from '../src/core/version'; import { registerBundle } from './bundle'; import { configureForFirebase } from './config'; import { name, version } from './package.json'; - /** * Registers the main Firestore ReactNative build with the components framework. * Persistence can be enabled via `firebase.firestore().enablePersistence()`. */ export function registerFirestore(instance: FirebaseNamespace): void { + setSDKVersion(instance.SDK_VERSION); configureForFirebase( instance, (app, firestoreExp) => diff --git a/packages/firestore/compat/index.ts b/packages/firestore/compat/index.ts index e35b68d823b..9084fe34150 100644 --- a/packages/firestore/compat/index.ts +++ b/packages/firestore/compat/index.ts @@ -21,6 +21,7 @@ import { FirebaseNamespace } from '@firebase/app-types'; import * as types from '@firebase/firestore-types'; import { Firestore, IndexedDbPersistenceProvider } from '../src/api/database'; +import { setSDKVersion } from '../src/core/version'; import { registerBundle } from './bundle'; import { configureForFirebase } from './config'; @@ -33,6 +34,7 @@ import '../register-module'; * Persistence can be enabled via `firebase.firestore().enablePersistence()`. */ export function registerFirestore(instance: FirebaseNamespace): void { + setSDKVersion(instance.SDK_VERSION); configureForFirebase( instance, (app, firestoreExp) => diff --git a/packages/firestore/exp/register.ts b/packages/firestore/exp/register.ts index 740f8d2e3c1..20f54426322 100644 --- a/packages/firestore/exp/register.ts +++ b/packages/firestore/exp/register.ts @@ -15,10 +15,15 @@ * limitations under the License. */ -import { _registerComponent, registerVersion } from '@firebase/app-exp'; +import { + _registerComponent, + registerVersion, + SDK_VERSION +} from '@firebase/app-exp'; import { Component, ComponentType } from '@firebase/component'; import { name, version } from '../package.json'; +import { setSDKVersion } from '../src/core/version'; import { FirebaseFirestore } from '../src/exp/database'; import { Settings } from '../src/exp/settings'; @@ -29,6 +34,7 @@ declare module '@firebase/component' { } export function registerFirestore(variant?: string): void { + setSDKVersion(SDK_VERSION); _registerComponent( new Component( 'firestore-exp', diff --git a/packages/firestore/lite/register.ts b/packages/firestore/lite/register.ts index cb17b6a25fe..e753a3d216b 100644 --- a/packages/firestore/lite/register.ts +++ b/packages/firestore/lite/register.ts @@ -15,10 +15,15 @@ * limitations under the License. */ -import { _registerComponent, registerVersion } from '@firebase/app-exp'; +import { + _registerComponent, + registerVersion, + SDK_VERSION +} from '@firebase/app-exp'; import { Component, ComponentType } from '@firebase/component'; import { version } from '../package.json'; +import { setSDKVersion } from '../src/core/version'; import { FirebaseFirestore } from '../src/lite/database'; import { Settings } from '../src/lite/settings'; @@ -29,6 +34,7 @@ declare module '@firebase/component' { } export function registerFirestore(): void { + setSDKVersion(`${SDK_VERSION}_lite`); _registerComponent( new Component( 'firestore/lite', diff --git a/packages/firestore/src/core/version.ts b/packages/firestore/src/core/version.ts index 5d6dc71524e..27f3ffc5589 100644 --- a/packages/firestore/src/core/version.ts +++ b/packages/firestore/src/core/version.ts @@ -16,4 +16,8 @@ */ /** The semver (www.semver.org) version of the SDK. */ -export { version as SDK_VERSION } from '../../../firebase/package.json'; +import { version } from '../../../firebase/package.json'; +export let SDK_VERSION = version; +export function setSDKVersion(version: string): void { + SDK_VERSION = version; +} diff --git a/packages/firestore/src/remote/rest_connection.ts b/packages/firestore/src/remote/rest_connection.ts index 0ed08673a91..2f4b75e192b 100644 --- a/packages/firestore/src/remote/rest_connection.ts +++ b/packages/firestore/src/remote/rest_connection.ts @@ -39,8 +39,12 @@ RPC_NAME_URL_MAPPING['Commit'] = 'commit'; RPC_NAME_URL_MAPPING['RunQuery'] = 'runQuery'; const RPC_URL_VERSION = 'v1'; -const X_GOOG_API_CLIENT_VALUE = 'gl-js/ fire/' + SDK_VERSION; +// SDK_VERSION is updated to different value at runtime depending on the entry point, +// so we need to get its value when we need it in a function. +function getGoogApiClientValue(): string { + return 'gl-js/ fire/' + SDK_VERSION; +} /** * Base class for all Rest-based connections to the backend (WebChannel and * HTTP). @@ -118,7 +122,7 @@ export abstract class RestConnection implements Connection { headers: StringMap, token: Token | null ): void { - headers['X-Goog-Api-Client'] = X_GOOG_API_CLIENT_VALUE; + headers['X-Goog-Api-Client'] = getGoogApiClientValue(); // Content-Type: text/plain will avoid preflight requests which might // mess with CORS and redirects by proxies. If we add custom headers diff --git a/yarn.lock b/yarn.lock index 7cd52158485..11009a5f49f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1196,6 +1196,11 @@ resolved "https://registry.npmjs.org/@firebase/app-types/-/app-types-0.6.1.tgz#dcbd23030a71c0c74fc95d4a3f75ba81653850e9" integrity sha512-L/ZnJRAq7F++utfuoTKX4CLBG5YR7tFO3PLzG1/oXXKEezJ0kRL3CMRoueBEmTCzVb/6SIs2Qlaw++uDgi5Xyg== +"@firebase/auth-interop-types@0.1.5": + version "0.1.5" + resolved "https://registry.npmjs.org/@firebase/auth-interop-types/-/auth-interop-types-0.1.5.tgz#9fc9bd7c879f16b8d1bb08373a0f48c3a8b74557" + integrity sha512-88h74TMQ6wXChPA6h9Q3E1Jg6TkTHep2+k63OWg3s0ozyGVMeY+TTOti7PFPzq5RhszQPQOoCi59es4MaRvgCw== + "@firebase/component@0.1.21": version "0.1.21" resolved "https://registry.npmjs.org/@firebase/component/-/component-0.1.21.tgz#56062eb0d449dc1e7bbef3c084a9b5fa48c7c14d" @@ -7482,8 +7487,8 @@ firebase-admin@9.4.2: "@firebase/app-exp" "0.0.900" "@firebase/auth-compat" "0.0.900" "@firebase/auth-exp" "0.0.900" - "@firebase/database" "0.9.10" - "@firebase/firestore" "2.2.4" + "@firebase/database" "0.9.11" + "@firebase/firestore" "2.2.5" "@firebase/functions-compat" "0.0.900" "@firebase/functions-exp" "0.0.900" "@firebase/messaging-compat" "0.0.900" @@ -7492,7 +7497,7 @@ firebase-admin@9.4.2: "@firebase/performance-exp" "0.0.900" "@firebase/remote-config-compat" "0.0.900" "@firebase/remote-config-exp" "0.0.900" - "@firebase/storage" "0.5.0" + "@firebase/storage" "0.5.1" firebase-functions@3.13.0: version "3.13.0"