diff --git a/src/auth/credential.ts b/src/auth/credential.ts index b526c338c1..38d7945812 100644 --- a/src/auth/credential.ts +++ b/src/auth/credential.ts @@ -14,15 +14,10 @@ * limitations under the License. */ -import * as jwt from 'jsonwebtoken'; -import * as forge from 'node-forge'; - // Use untyped import syntax for Node built-ins import fs = require('fs'); import os = require('os'); -import http = require('http'); import path = require('path'); -import https = require('https'); import {AppErrorCodes, FirebaseAppError} from '../utils/error'; @@ -169,6 +164,7 @@ export class Certificate { throw new FirebaseAppError(AppErrorCodes.INVALID_CREDENTIAL, errorMessage); } + const forge = require('node-forge'); try { forge.pki.privateKeyFromPem(this.privateKey); } catch (error) { @@ -257,6 +253,7 @@ export class CertCredential implements Credential { 'Content-Length': postData.length, }, }; + const https = require('https'); return requestAccessToken(https, options, postData); } @@ -275,6 +272,7 @@ export class CertCredential implements Credential { ].join(' '), }; + const jwt = require('jsonwebtoken'); // This method is actually synchronous so we can capture and return the buffer. return jwt.sign(claims, this.certificate_.privateKey, { audience: GOOGLE_TOKEN_AUDIENCE, @@ -321,6 +319,7 @@ export class RefreshTokenCredential implements Credential { 'Content-Length': postData.length, }, }; + const https = require('https'); return requestAccessToken(https, options, postData); } @@ -345,6 +344,7 @@ export class MetadataServiceCredential implements Credential { 'Content-Length': 0, }, }; + const http = require('http'); return requestAccessToken(http, options); } diff --git a/src/firebase-app.ts b/src/firebase-app.ts index 75c083c9a6..be0b2da6ac 100644 --- a/src/firebase-app.ts +++ b/src/firebase-app.ts @@ -286,7 +286,8 @@ export class FirebaseApp { */ public auth(): Auth { return this.ensureService_('auth', () => { - return new Auth(this); + const authService: typeof Auth = require('./auth/auth').Auth; + return new authService(this); }); } @@ -297,7 +298,8 @@ export class FirebaseApp { */ public database(url?: string): Database { const service: DatabaseService = this.ensureService_('database', () => { - return new DatabaseService(this); + const dbService: typeof DatabaseService = require('./database/database').DatabaseService; + return new dbService(this); }); return service.getDatabase(url); } @@ -309,7 +311,8 @@ export class FirebaseApp { */ public messaging(): Messaging { return this.ensureService_('messaging', () => { - return new Messaging(this); + const messagingService: typeof Messaging = require('./messaging/messaging').Messaging; + return new messagingService(this); }); } @@ -320,13 +323,15 @@ export class FirebaseApp { */ public storage(): Storage { return this.ensureService_('storage', () => { - return new Storage(this); + const storageService: typeof Storage = require('./storage/storage').Storage; + return new storageService(this); }); } public firestore(): Firestore { const service: FirestoreService = this.ensureService_('firestore', () => { - return new FirestoreService(this); + const firestoreService: typeof FirestoreService = require('./firestore/firestore').FirestoreService; + return new firestoreService(this); }); return service.client; } @@ -338,7 +343,8 @@ export class FirebaseApp { */ public instanceId(): InstanceId { return this.ensureService_('iid', () => { - return new InstanceId(this); + const iidService: typeof InstanceId = require('./instance-id/instance-id').InstanceId; + return new iidService(this); }); } diff --git a/src/firebase-namespace.ts b/src/firebase-namespace.ts index 7330a64a66..dcfab00538 100644 --- a/src/firebase-namespace.ts +++ b/src/firebase-namespace.ts @@ -325,7 +325,8 @@ export class FirebaseNamespace { const fn: FirebaseServiceNamespace = (app?: FirebaseApp) => { return this.ensureApp(app).auth(); }; - return Object.assign(fn, {Auth}); + const auth = require('./auth/auth').Auth; + return Object.assign(fn, {Auth: auth}); } /** @@ -347,7 +348,8 @@ export class FirebaseNamespace { const fn: FirebaseServiceNamespace = (app?: FirebaseApp) => { return this.ensureApp(app).messaging(); }; - return Object.assign(fn, {Messaging}); + const messaging = require('./messaging/messaging').Messaging; + return Object.assign(fn, {Messaging: messaging}); } /** @@ -358,7 +360,8 @@ export class FirebaseNamespace { const fn: FirebaseServiceNamespace = (app?: FirebaseApp) => { return this.ensureApp(app).storage(); }; - return Object.assign(fn, {Storage}); + const storage = require('./storage/storage').Storage; + return Object.assign(fn, {Storage: storage}); } /** @@ -380,7 +383,8 @@ export class FirebaseNamespace { const fn: FirebaseServiceNamespace = (app?: FirebaseApp) => { return this.ensureApp(app).instanceId(); }; - return Object.assign(fn, {InstanceId}); + const instanceId = require('./instance-id/instance-id').InstanceId; + return Object.assign(fn, {InstanceId: instanceId}); } /**