Skip to content

Commit 92b0d37

Browse files
authored
chore: Remove instances of XXX_SDK_VERSION_XXX by reading version from package.json (#952)
* Remove instances of XXX_SDK_VERSION_XXX by reading version from package.json * fix: Lowercase module * fix: Use function to lazily get SDK version, simplify unit test
1 parent eca00ee commit 92b0d37

18 files changed

+45
-20
lines changed

gulpfile.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ gulp.task('compile', function() {
7676
// Compile Typescript into .js and .d.ts files
7777
.pipe(buildProject())
7878

79-
// Replace SDK version
80-
.pipe(replace(/\<XXX_SDK_VERSION_XXX\>/g, pkg.version))
81-
8279
// Add header
8380
.pipe(header(banner))
8481

src/auth/auth-api-request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { Tenant, TenantOptions, TenantServerResponse } from './tenant';
4444

4545
/** Firebase Auth request header. */
4646
const FIREBASE_AUTH_HEADER = {
47-
'X-Client-Version': 'Node/Admin/<XXX_SDK_VERSION_XXX>',
47+
'X-Client-Version': `Node/Admin/${utils.getSdkVersion()}`,
4848
};
4949
/** Firebase Auth request timeout duration in milliseconds. */
5050
const FIREBASE_AUTH_TIMEOUT = 25000;

src/database/database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Database } from '@firebase/database';
88

99
import * as validator from '../utils/validator';
1010
import { AuthorizedHttpClient, HttpRequestConfig, HttpError } from '../utils/api-request';
11+
import { getSdkVersion } from '../utils/index';
1112

1213

1314
/**
@@ -78,8 +79,7 @@ export class DatabaseService implements FirebaseServiceInterface {
7879
let db: Database = this.INTERNAL.databases[dbUrl];
7980
if (typeof db === 'undefined') {
8081
const rtdb = require('@firebase/database'); // eslint-disable-line @typescript-eslint/no-var-requires
81-
const { version } = require('../../package.json'); // eslint-disable-line @typescript-eslint/no-var-requires
82-
db = rtdb.initStandalone(this.appInternal, dbUrl, version).instance;
82+
db = rtdb.initStandalone(this.appInternal, dbUrl, getSdkVersion()).instance;
8383

8484
const rulesClient = new DatabaseRulesClient(this.app, dbUrl);
8585
db.getRules = () => {

src/firebase-namespace.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { SecurityRules } from './security-rules/security-rules';
3939
import { RemoteConfig } from './remote-config/remote-config';
4040

4141
import * as validator from './utils/validator';
42+
import { getSdkVersion } from './utils/index';
4243

4344
const DEFAULT_APP_NAME = '[DEFAULT]';
4445

@@ -309,7 +310,7 @@ export class FirebaseNamespace {
309310
/* tslint:enable:variable-name */
310311

311312
public credential = firebaseCredential;
312-
public SDK_VERSION = '<XXX_SDK_VERSION_XXX>';
313+
public SDK_VERSION = getSdkVersion();
313314
public INTERNAL: FirebaseNamespaceInternals;
314315

315316
/* tslint:disable */

src/machine-learning/machine-learning-api-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { FirebaseApp } from '../firebase-app';
2323

2424
const ML_V1BETA2_API = 'https://firebaseml.googleapis.com/v1beta2';
2525
const FIREBASE_VERSION_HEADER = {
26-
'X-Firebase-Client': 'fire-admin-node/<XXX_SDK_VERSION_XXX>',
26+
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`,
2727
};
2828

2929
export interface StatusErrorResponse {

src/messaging/messaging-api-request.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ import {
2121
import { createFirebaseError, getErrorCode } from './messaging-errors';
2222
import { SubRequest, BatchRequestClient } from './batch-request';
2323
import { SendResponse, BatchResponse } from './messaging-types';
24+
import { getSdkVersion } from '../utils/index';
2425

2526
// FCM backend constants
2627
const FIREBASE_MESSAGING_TIMEOUT = 10000;
2728
const FIREBASE_MESSAGING_BATCH_URL = 'https://fcm.googleapis.com/batch';
2829
const FIREBASE_MESSAGING_HTTP_METHOD: HttpMethod = 'POST';
2930
const FIREBASE_MESSAGING_HEADERS = {
30-
'X-Firebase-Client': 'fire-admin-node/<XXX_SDK_VERSION_XXX>',
31+
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
3132
};
3233
const LEGACY_FIREBASE_MESSAGING_HEADERS = {
33-
'X-Firebase-Client': 'fire-admin-node/<XXX_SDK_VERSION_XXX>',
34+
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
3435
'access_token_auth': 'true',
3536
};
3637

src/project-management/project-management-api-request.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { FirebaseProjectManagementError, ProjectManagementErrorCode } from '../utils/error';
2222
import * as validator from '../utils/validator';
2323
import { ShaCertificate } from './android-app';
24+
import { getSdkVersion } from '../utils/index';
2425

2526
/** Project management backend host and port. */
2627
const PROJECT_MANAGEMENT_HOST_AND_PORT = 'firebase.googleapis.com:443';
@@ -30,7 +31,7 @@ const PROJECT_MANAGEMENT_PATH = '/v1/';
3031
const PROJECT_MANAGEMENT_BETA_PATH = '/v1beta1/';
3132
/** Project management request header. */
3233
const PROJECT_MANAGEMENT_HEADERS = {
33-
'X-Client-Version': 'Node/Admin/<XXX_SDK_VERSION_XXX>',
34+
'X-Client-Version': `Node/Admin/${getSdkVersion()}`,
3435
};
3536
/** Project management request timeout duration in milliseconds. */
3637
const PROJECT_MANAGEMENT_TIMEOUT_MILLIS = 10000;

src/remote-config/remote-config-api-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { deepCopy } from '../utils/deep-copy';
2525
// Remote Config backend constants
2626
const FIREBASE_REMOTE_CONFIG_V1_API = 'https://firebaseremoteconfig.googleapis.com/v1';
2727
const FIREBASE_REMOTE_CONFIG_HEADERS = {
28-
'X-Firebase-Client': 'fire-admin-node/<XXX_SDK_VERSION_XXX>',
28+
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`,
2929
// There is a known issue in which the ETag is not properly returned in cases where the request
3030
// does not specify a compression type. Currently, it is required to include the header
3131
// `Accept-Encoding: gzip` or equivalent in all requests.

src/security-rules/security-rules-api-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { FirebaseApp } from '../firebase-app';
2323

2424
const RULES_V1_API = 'https://firebaserules.googleapis.com/v1';
2525
const FIREBASE_VERSION_HEADER = {
26-
'X-Firebase-Client': 'fire-admin-node/<XXX_SDK_VERSION_XXX>',
26+
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`,
2727
};
2828

2929
export interface Release {

src/utils/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ import { ServiceAccountCredential, ComputeEngineCredential } from '../auth/crede
1919

2020
import * as validator from './validator';
2121

22+
let sdkVersion: string;
23+
24+
export function getSdkVersion(): string {
25+
if (!sdkVersion) {
26+
const { version } = require('../../package.json'); // eslint-disable-line @typescript-eslint/no-var-requires
27+
sdkVersion = version;
28+
}
29+
return sdkVersion;
30+
}
31+
2232
/**
2333
* Renames properties on an object given a mapping from old to new property names.
2434
*

0 commit comments

Comments
 (0)