Skip to content

Commit

Permalink
Merge branch 'master' into lm-fix-createtoken
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirumaramba authored Dec 12, 2024
2 parents 3b8d5a3 + 69d6494 commit 5ffd9e7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"uuid": "^11.0.2"
},
"optionalDependencies": {
"@google-cloud/firestore": "^7.10.0",
"@google-cloud/firestore": "^7.11.0",
"@google-cloud/storage": "^7.14.0"
},
"devDependencies": {
Expand Down
22 changes: 16 additions & 6 deletions src/firestore/firestore-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function getFirestoreOptions(app: App, firestoreSettings?: FirestoreSetti
const projectId: string | null = utils.getExplicitProjectId(app);
const credential = app.options.credential;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version: firebaseVersion } = require('../../package.json');
const sdkVersion = utils.getSdkVersion();
const preferRest = firestoreSettings?.preferRest;
if (credential instanceof ServiceAccountCredential) {
return {
Expand All @@ -124,16 +124,26 @@ export function getFirestoreOptions(app: App, firestoreSettings?: FirestoreSetti
// When the SDK is initialized with ServiceAccountCredentials an explicit projectId is
// guaranteed to be available.
projectId: projectId!,
firebaseVersion,
firebaseVersion: sdkVersion,
firebaseAdminVersion: sdkVersion,
preferRest,
};
} else if (isApplicationDefault(app.options.credential)) {
// Try to use the Google application default credentials.
// If an explicit project ID is not available, let Firestore client discover one from the
// environment. This prevents the users from having to set GOOGLE_CLOUD_PROJECT in GCP runtimes.
return validator.isNonEmptyString(projectId)
? { projectId, firebaseVersion, preferRest }
: { firebaseVersion, preferRest };
? {
projectId,
firebaseVersion: sdkVersion,
firebaseAdminVersion: sdkVersion,
preferRest
}
: {
firebaseVersion: sdkVersion,
firebaseAdminVersion: sdkVersion,
preferRest
};
}

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

Expand Down
21 changes: 18 additions & 3 deletions test/unit/firestore/firestore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
RefreshTokenCredential
} from '../../../src/app/credential-internal';
import { FirestoreService, getFirestoreOptions } from '../../../src/firestore/firestore-internal';
import { getSdkVersion } from '../../../src/utils/index';
import { DEFAULT_DATABASE_ID } from '@google-cloud/firestore/build/src/path';

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

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version: firebaseVersion } = require('../../../package.json');
const sdkVersion = getSdkVersion();
const defaultCredentialApps = [
{
name: 'ComputeEngineCredentials',
Expand Down Expand Up @@ -191,13 +192,27 @@ describe('Firestore', () => {
describe('options.firebaseVersion', () => {
it('should return firebaseVersion when using credential with service account certificate', () => {
const options = getFirestoreOptions(mockApp);
expect(options.firebaseVersion).to.equal(firebaseVersion);
expect(options.firebaseVersion).to.equal(sdkVersion);
});

defaultCredentialApps.forEach((config) => {
it(`should return firebaseVersion when using default ${config.name}`, () => {
const options = getFirestoreOptions(config.app);
expect(options.firebaseVersion).to.equal(firebaseVersion);
expect(options.firebaseVersion).to.equal(sdkVersion);
});
});
});

describe('options.firebaseAdminVersion', () => {
it('should return firebaseAdminVersion when using credential with service account certificate', () => {
const options = getFirestoreOptions(mockApp);
expect(options.firebaseAdminVersion).to.equal(sdkVersion);
});

defaultCredentialApps.forEach((config) => {
it(`should return firebaseAdminVersion when using default ${config.name}`, () => {
const options = getFirestoreOptions(config.app);
expect(options.firebaseAdminVersion).to.equal(sdkVersion);
});
});
});
Expand Down

0 comments on commit 5ffd9e7

Please sign in to comment.