@@ -18,7 +18,7 @@ import {FirebaseApp} from '../firebase-app';
18
18
import { FirebaseFirestoreError } from '../utils/error' ;
19
19
import { FirebaseServiceInterface , FirebaseServiceInternalsInterface } from '../firebase-service' ;
20
20
import { ApplicationDefaultCredential , Certificate } from '../auth/credential' ;
21
- import { Firestore } from '@google-cloud/firestore' ;
21
+ import { Firestore , Settings } from '@google-cloud/firestore' ;
22
22
23
23
import * as validator from '../utils/validator' ;
24
24
import * as utils from '../utils/index' ;
@@ -63,7 +63,7 @@ export class FirestoreService implements FirebaseServiceInterface {
63
63
}
64
64
}
65
65
66
- export function getFirestoreOptions ( app : FirebaseApp ) : any {
66
+ export function getFirestoreOptions ( app : FirebaseApp ) : Settings {
67
67
if ( ! validator . isNonNullObject ( app ) || ! ( 'options' in app ) ) {
68
68
throw new FirebaseFirestoreError ( {
69
69
code : 'invalid-argument' ,
@@ -73,6 +73,7 @@ export function getFirestoreOptions(app: FirebaseApp): any {
73
73
74
74
const projectId : string = utils . getProjectId ( app ) ;
75
75
const cert : Certificate = app . options . credential . getCertificate ( ) ;
76
+ const { version : firebaseVersion } = require ( '../../package.json' ) ;
76
77
if ( cert != null ) {
77
78
// cert is available when the SDK has been initialized with a service account JSON file,
78
79
// or by setting the GOOGLE_APPLICATION_CREDENTIALS envrionment variable.
@@ -92,12 +93,13 @@ export function getFirestoreOptions(app: FirebaseApp): any {
92
93
client_email : cert . clientEmail ,
93
94
} ,
94
95
projectId,
96
+ firebaseVersion,
95
97
} ;
96
98
} else if ( app . options . credential instanceof ApplicationDefaultCredential ) {
97
99
// Try to use the Google application default credentials.
98
100
// If an explicit project ID is not available, let Firestore client discover one from the
99
101
// 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 } ;
101
103
}
102
104
103
105
throw new FirebaseFirestoreError ( {
@@ -122,5 +124,6 @@ function initFirestore(app: FirebaseApp): Firestore {
122
124
+ `Original error: ${ err } ` ,
123
125
} ) ;
124
126
}
127
+
125
128
return new firestoreDatabase ( options ) ;
126
129
}
0 commit comments