Skip to content

Commit 69d6494

Browse files
authored
chore: Add firebaseAdminVersion to Firestore settings (#2795)
* chore: Add firebaseAdminVersion to Firestore options * bump @google-cloud/firestore to v7.11.0
1 parent 79b78c4 commit 69d6494

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
"uuid": "^11.0.2"
217217
},
218218
"optionalDependencies": {
219-
"@google-cloud/firestore": "^7.10.0",
219+
"@google-cloud/firestore": "^7.11.0",
220220
"@google-cloud/storage": "^7.14.0"
221221
},
222222
"devDependencies": {

src/firestore/firestore-internal.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function getFirestoreOptions(app: App, firestoreSettings?: FirestoreSetti
113113
const projectId: string | null = utils.getExplicitProjectId(app);
114114
const credential = app.options.credential;
115115
// eslint-disable-next-line @typescript-eslint/no-var-requires
116-
const { version: firebaseVersion } = require('../../package.json');
116+
const sdkVersion = utils.getSdkVersion();
117117
const preferRest = firestoreSettings?.preferRest;
118118
if (credential instanceof ServiceAccountCredential) {
119119
return {
@@ -124,16 +124,26 @@ export function getFirestoreOptions(app: App, firestoreSettings?: FirestoreSetti
124124
// When the SDK is initialized with ServiceAccountCredentials an explicit projectId is
125125
// guaranteed to be available.
126126
projectId: projectId!,
127-
firebaseVersion,
127+
firebaseVersion: sdkVersion,
128+
firebaseAdminVersion: sdkVersion,
128129
preferRest,
129130
};
130131
} else if (isApplicationDefault(app.options.credential)) {
131132
// Try to use the Google application default credentials.
132133
// If an explicit project ID is not available, let Firestore client discover one from the
133134
// environment. This prevents the users from having to set GOOGLE_CLOUD_PROJECT in GCP runtimes.
134135
return validator.isNonEmptyString(projectId)
135-
? { projectId, firebaseVersion, preferRest }
136-
: { firebaseVersion, preferRest };
136+
? {
137+
projectId,
138+
firebaseVersion: sdkVersion,
139+
firebaseAdminVersion: sdkVersion,
140+
preferRest
141+
}
142+
: {
143+
firebaseVersion: sdkVersion,
144+
firebaseAdminVersion: sdkVersion,
145+
preferRest
146+
};
137147
}
138148

139149
throw new FirebaseFirestoreError({
@@ -155,8 +165,8 @@ function initFirestore(app: App, databaseId: string, firestoreSettings?: Firesto
155165
throw new FirebaseFirestoreError({
156166
code: 'missing-dependencies',
157167
message: 'Failed to import the Cloud Firestore client library for Node.js. '
158-
+ 'Make sure to install the "@google-cloud/firestore" npm package. '
159-
+ `Original error: ${err}`,
168+
+ 'Make sure to install the "@google-cloud/firestore" npm package. '
169+
+ `Original error: ${err}`,
160170
});
161171
}
162172

test/unit/firestore/firestore.spec.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
RefreshTokenCredential
2828
} from '../../../src/app/credential-internal';
2929
import { FirestoreService, getFirestoreOptions } from '../../../src/firestore/firestore-internal';
30+
import { getSdkVersion } from '../../../src/utils/index';
3031
import { DEFAULT_DATABASE_ID } from '@google-cloud/firestore/build/src/path';
3132

3233
describe('Firestore', () => {
@@ -44,7 +45,7 @@ describe('Firestore', () => {
4445
+ 'credentials to use Cloud Firestore API.';
4546

4647
// eslint-disable-next-line @typescript-eslint/no-var-requires
47-
const { version: firebaseVersion } = require('../../../package.json');
48+
const sdkVersion = getSdkVersion();
4849
const defaultCredentialApps = [
4950
{
5051
name: 'ComputeEngineCredentials',
@@ -191,13 +192,27 @@ describe('Firestore', () => {
191192
describe('options.firebaseVersion', () => {
192193
it('should return firebaseVersion when using credential with service account certificate', () => {
193194
const options = getFirestoreOptions(mockApp);
194-
expect(options.firebaseVersion).to.equal(firebaseVersion);
195+
expect(options.firebaseVersion).to.equal(sdkVersion);
195196
});
196197

197198
defaultCredentialApps.forEach((config) => {
198199
it(`should return firebaseVersion when using default ${config.name}`, () => {
199200
const options = getFirestoreOptions(config.app);
200-
expect(options.firebaseVersion).to.equal(firebaseVersion);
201+
expect(options.firebaseVersion).to.equal(sdkVersion);
202+
});
203+
});
204+
});
205+
206+
describe('options.firebaseAdminVersion', () => {
207+
it('should return firebaseAdminVersion when using credential with service account certificate', () => {
208+
const options = getFirestoreOptions(mockApp);
209+
expect(options.firebaseAdminVersion).to.equal(sdkVersion);
210+
});
211+
212+
defaultCredentialApps.forEach((config) => {
213+
it(`should return firebaseAdminVersion when using default ${config.name}`, () => {
214+
const options = getFirestoreOptions(config.app);
215+
expect(options.firebaseAdminVersion).to.equal(sdkVersion);
201216
});
202217
});
203218
});

0 commit comments

Comments
 (0)