@@ -18,7 +18,7 @@ import {FirebaseApp} from '../firebase-app';
1818import { FirebaseFirestoreError } from '../utils/error' ;
1919import { FirebaseServiceInterface , FirebaseServiceInternalsInterface } from '../firebase-service' ;
2020import { ApplicationDefaultCredential , Certificate } from '../auth/credential' ;
21- import { Firestore } from '@google-cloud/firestore' ;
21+ import { Firestore , Settings } from '@google-cloud/firestore' ;
2222
2323import * as validator from '../utils/validator' ;
2424import * as utils from '../utils/index' ;
@@ -63,7 +63,7 @@ export class FirestoreService implements FirebaseServiceInterface {
6363 }
6464}
6565
66- export function getFirestoreOptions ( app : FirebaseApp ) : any {
66+ export function getFirestoreOptions ( app : FirebaseApp ) : Settings {
6767 if ( ! validator . isNonNullObject ( app ) || ! ( 'options' in app ) ) {
6868 throw new FirebaseFirestoreError ( {
6969 code : 'invalid-argument' ,
@@ -73,6 +73,7 @@ export function getFirestoreOptions(app: FirebaseApp): any {
7373
7474 const projectId : string = utils . getProjectId ( app ) ;
7575 const cert : Certificate = app . options . credential . getCertificate ( ) ;
76+ const { version : firebaseVersion } = require ( '../../package.json' ) ;
7677 if ( cert != null ) {
7778 // cert is available when the SDK has been initialized with a service account JSON file,
7879 // or by setting the GOOGLE_APPLICATION_CREDENTIALS envrionment variable.
@@ -92,12 +93,13 @@ export function getFirestoreOptions(app: FirebaseApp): any {
9293 client_email : cert . clientEmail ,
9394 } ,
9495 projectId,
96+ firebaseVersion,
9597 } ;
9698 } else if ( app . options . credential instanceof ApplicationDefaultCredential ) {
9799 // Try to use the Google application default credentials.
98100 // If an explicit project ID is not available, let Firestore client discover one from the
99101 // environment. This prevents the users from having to set GOOGLE_CLOUD_PROJECT in GCP runtimes.
100- return validator . isNonEmptyString ( projectId ) ? { projectId} : { } ;
102+ return validator . isNonEmptyString ( projectId ) ? { projectId, firebaseVersion } : { firebaseVersion } ;
101103 }
102104
103105 throw new FirebaseFirestoreError ( {
@@ -122,5 +124,6 @@ function initFirestore(app: FirebaseApp): Firestore {
122124 + `Original error: ${ err } ` ,
123125 } ) ;
124126 }
127+
125128 return new firestoreDatabase ( options ) ;
126129}
0 commit comments