From 8093c57edea1da41c596efaa0ec79fccde05dc35 Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Wed, 27 May 2026 12:19:25 -0400 Subject: [PATCH 1/3] feat: remove legacy namespaces support --- entrypoints.json | 3 +- gulpfile.js | 11 +- src/app-check/app-check-namespace.ts | 86 -- src/app/firebase-namespace.ts | 400 -------- src/auth/auth-namespace.ts | 381 -------- src/database/database-namespace.ts | 107 --- src/default-namespace.d.ts | 23 - src/default-namespace.ts | 31 - src/firebase-namespace-api.ts | 104 -- src/firestore/firestore-namespace.ts | 77 -- src/index.d.ts | 23 - src/index.ts | 14 +- src/installations/installations-namespace.ts | 58 -- src/instance-id/instance-id-namespace.ts | 40 - .../machine-learning-namespace.ts | 101 -- src/messaging/messaging-namespace.ts | 195 ---- .../project-management-namespace.ts | 102 -- src/remote-config/remote-config-namespace.ts | 189 ---- .../security-rules-namespace.ts | 82 -- src/storage/storage-namespace.ts | 48 - test/integration/app.spec.ts | 64 +- test/integration/database.spec.ts | 20 +- test/integration/firestore.spec.ts | 53 +- test/integration/postcheck/tsconfig.json | 2 +- .../postcheck/typescript/example.test.ts | 102 -- .../postcheck/typescript/example.ts | 35 - test/resources/mocks.ts | 2 +- test/unit/app/firebase-app.spec.ts | 429 +-------- test/unit/app/firebase-namespace.spec.ts | 892 ------------------ test/unit/firebase.spec.ts | 289 ------ test/unit/index.spec.ts | 2 - test/unit/utils.ts | 2 +- tsconfig.json | 7 +- 33 files changed, 51 insertions(+), 3923 deletions(-) delete mode 100644 src/app-check/app-check-namespace.ts delete mode 100644 src/app/firebase-namespace.ts delete mode 100644 src/auth/auth-namespace.ts delete mode 100644 src/database/database-namespace.ts delete mode 100644 src/default-namespace.d.ts delete mode 100644 src/default-namespace.ts delete mode 100644 src/firebase-namespace-api.ts delete mode 100644 src/firestore/firestore-namespace.ts delete mode 100644 src/index.d.ts delete mode 100644 src/installations/installations-namespace.ts delete mode 100644 src/instance-id/instance-id-namespace.ts delete mode 100644 src/machine-learning/machine-learning-namespace.ts delete mode 100644 src/messaging/messaging-namespace.ts delete mode 100644 src/project-management/project-management-namespace.ts delete mode 100644 src/remote-config/remote-config-namespace.ts delete mode 100644 src/security-rules/security-rules-namespace.ts delete mode 100644 src/storage/storage-namespace.ts delete mode 100644 test/integration/postcheck/typescript/example.test.ts delete mode 100644 test/integration/postcheck/typescript/example.ts delete mode 100644 test/unit/app/firebase-namespace.spec.ts delete mode 100644 test/unit/firebase.spec.ts diff --git a/entrypoints.json b/entrypoints.json index 27906c2fa8..8c8535f5c2 100644 --- a/entrypoints.json +++ b/entrypoints.json @@ -1,7 +1,6 @@ { "firebase-admin": { - "legacy": true, - "typings": "./lib/default-namespace.d.ts", + "typings": "./lib/index.d.ts", "dist": "./lib/index.js" }, "firebase-admin/app": { diff --git a/gulpfile.js b/gulpfile.js index f5c2e06acd..6b0b70da25 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -105,14 +105,7 @@ gulp.task('compile_test', function() { .pipe(buildTest()) }); -gulp.task('copyTypings', function() { - return gulp.src(['src/index.d.ts', 'src/default-namespace.d.ts']) - // Add header - .pipe(header(banner)) - .pipe(gulp.dest(paths.build)) -}); - -gulp.task('compile_all', gulp.series('compile', 'copyTypings', 'compile_test')); +gulp.task('compile_all', gulp.series('compile', 'compile_test')); // Regenerates js every time a source file changes gulp.task('watch', function() { @@ -120,7 +113,7 @@ gulp.task('watch', function() { }); // Build task -gulp.task('build', gulp.series('cleanup', 'compile', 'copyTypings')); +gulp.task('build', gulp.series('cleanup', 'compile')); // Default task gulp.task('default', gulp.series('build')); diff --git a/src/app-check/app-check-namespace.ts b/src/app-check/app-check-namespace.ts deleted file mode 100644 index 85ac284bb4..0000000000 --- a/src/app-check/app-check-namespace.ts +++ /dev/null @@ -1,86 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app'; -import { - AppCheckToken as TAppCheckToken, - AppCheckTokenOptions as TAppCheckTokenOptions, - DecodedAppCheckToken as TDecodedAppCheckToken, - VerifyAppCheckTokenOptions as TVerifyAppCheckTokenOptions, - VerifyAppCheckTokenResponse as TVerifyAppCheckTokenResponse, -} from './app-check-api'; -import { AppCheck as TAppCheck } from './app-check'; - -/** - * Gets the {@link firebase-admin.app-check#AppCheck} service for the default app or a given app. - * - * `admin.appCheck()` can be called with no arguments to access the default - * app's `AppCheck` service or as `admin.appCheck(app)` to access the - * `AppCheck` service associated with a specific app. - * - * @example - * ```javascript - * // Get the `AppCheck` service for the default app - * var defaultAppCheck = admin.appCheck(); - * ``` - * - * @example - * ```javascript - * // Get the `AppCheck` service for a given app - * var otherAppCheck = admin.appCheck(otherApp); - * ``` - * - * @param app - Optional app for which to return the `AppCheck` service. - * If not provided, the default `AppCheck` service is returned. - * - * @returns The default `AppCheck` service if no - * app is provided, or the `AppCheck` service associated with the provided - * app. - */ -export declare function appCheck(app?: App): appCheck.AppCheck; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace appCheck { - /** - * Type alias to {@link firebase-admin.app-check#AppCheck}. - */ - export type AppCheck = TAppCheck; - - /** - * Type alias to {@link firebase-admin.app-check#AppCheckToken}. - */ - export type AppCheckToken = TAppCheckToken; - - /** - * Type alias to {@link firebase-admin.app-check#DecodedAppCheckToken}. - */ - export type DecodedAppCheckToken = TDecodedAppCheckToken; - - /** - * Type alias to {@link firebase-admin.app-check#VerifyAppCheckTokenResponse}. - */ - export type VerifyAppCheckTokenResponse = TVerifyAppCheckTokenResponse; - - /** - * Type alias to {@link firebase-admin.app-check#AppCheckTokenOptions}. - */ - export type AppCheckTokenOptions = TAppCheckTokenOptions; - - /** - * Type alias to {@link firebase-admin.app-check#VerifyAppCheckTokenOptions}. - */ - export type VerifyAppCheckTokenOptions = TVerifyAppCheckTokenOptions; -} diff --git a/src/app/firebase-namespace.ts b/src/app/firebase-namespace.ts deleted file mode 100644 index 80daf6867c..0000000000 --- a/src/app/firebase-namespace.ts +++ /dev/null @@ -1,400 +0,0 @@ -/*! - * @license - * Copyright 2017 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App as AppCore } from './core'; -import { AppStore, defaultAppStore } from './lifecycle'; -import { - app, appCheck, auth, messaging, machineLearning, storage, firestore, database, - instanceId, installations, projectManagement, securityRules , remoteConfig, AppOptions, -} from '../firebase-namespace-api'; -import { cert, refreshToken, applicationDefault } from './credential-factory'; -import { getSdkVersion } from '../utils/index'; - -import App = app.App; -import AppCheck = appCheck.AppCheck; -import Auth = auth.Auth; -import Database = database.Database; -import Firestore = firestore.Firestore; -import Installations = installations.Installations; -import InstanceId = instanceId.InstanceId; -import MachineLearning = machineLearning.MachineLearning; -import Messaging = messaging.Messaging; -import ProjectManagement = projectManagement.ProjectManagement; -import RemoteConfig = remoteConfig.RemoteConfig; -import SecurityRules = securityRules.SecurityRules; -import Storage = storage.Storage; - -export interface FirebaseServiceNamespace { - (app?: App): T; - [key: string]: any; -} - -/** - * Internals of a FirebaseNamespace instance. - */ -export class FirebaseNamespaceInternals { - - constructor(private readonly appStore: AppStore) {} - - /** - * Initializes the App instance. - * - * @param options - Optional options for the App instance. If none present will try to initialize - * from the FIREBASE_CONFIG environment variable. If the environment variable contains a string - * that starts with '{' it will be parsed as JSON, otherwise it will be assumed to be pointing - * to a file. - * @param appName - Optional name of the FirebaseApp instance. - * - * @returns A new App instance. - */ - public initializeApp(options?: AppOptions, appName?: string): App { - const app = this.appStore.initializeApp(options, appName); - return extendApp(app); - } - - /** - * Returns the App instance with the provided name (or the default App instance - * if no name is provided). - * - * @param appName - Optional name of the FirebaseApp instance to return. - * @returns The App instance which has the provided name. - */ - public app(appName?: string): App { - const app = this.appStore.getApp(appName); - return extendApp(app); - } - - /* - * Returns an array of all the non-deleted App instances. - */ - public get apps(): App[] { - return this.appStore.getApps().map((app) => extendApp(app)); - } -} - -const firebaseCredential = { - cert, refreshToken, applicationDefault -}; - -/** - * Global Firebase context object. - */ -export class FirebaseNamespace { - // Hack to prevent Babel from modifying the object returned as the default admin namespace. - /* tslint:disable:variable-name */ - public __esModule = true; - /* tslint:enable:variable-name */ - - public credential = firebaseCredential; - public SDK_VERSION = getSdkVersion(); - public INTERNAL: FirebaseNamespaceInternals; - - /* tslint:disable */ - // TODO(jwenger): Database is the only consumer of firebase.Promise. We should update it to use - // use the native Promise and then remove this. - public Promise: any = Promise; - /* tslint:enable */ - - constructor(appStore?: AppStore) { - this.INTERNAL = new FirebaseNamespaceInternals(appStore ?? new AppStore()); - } - - /** - * Gets the `Auth` service namespace. The returned namespace can be used to get the - * `Auth` service for the default app or an explicitly specified app. - */ - get auth(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).auth(); - }; - const auth = require('../auth/auth').Auth; - return Object.assign(fn, { Auth: auth }); - } - - /** - * Gets the `Database` service namespace. The returned namespace can be used to get the - * `Database` service for the default app or an explicitly specified app. - */ - get database(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).database(); - }; - - return Object.assign(fn, require('@firebase/database-compat/standalone')); - } - - /** - * Gets the `Messaging` service namespace. The returned namespace can be used to get the - * `Messaging` service for the default app or an explicitly specified app. - */ - get messaging(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).messaging(); - }; - const messaging = require('../messaging/messaging').Messaging; - return Object.assign(fn, { Messaging: messaging }); - } - - /** - * Gets the `Storage` service namespace. The returned namespace can be used to get the - * `Storage` service for the default app or an explicitly specified app. - */ - get storage(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).storage(); - }; - const storage = require('../storage/storage').Storage; - return Object.assign(fn, { Storage: storage }); - } - - /** - * Gets the `Firestore` service namespace. The returned namespace can be used to get the - * `Firestore` service for the default app or an explicitly specified app. - */ - get firestore(): FirebaseServiceNamespace { - let fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).firestore(); - }; - - const firestore = require('@google-cloud/firestore'); - - fn = Object.assign(fn, firestore.Firestore); - - // `v1beta1` and `v1` are lazy-loaded in the Firestore SDK. We use the same trick here - // to avoid triggering this lazy-loading upon initialization. - Object.defineProperty(fn, 'v1beta1', { - get: () => { - return firestore.v1beta1; - }, - }); - Object.defineProperty(fn, 'v1', { - get: () => { - return firestore.v1; - }, - }); - - return fn; - } - - /** - * Gets the `MachineLearning` service namespace. The returned namespace can be - * used to get the `MachineLearning` service for the default app or an - * explicityly specified app. - */ - get machineLearning(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = - (app?: App) => { - return this.ensureApp(app).machineLearning(); - }; - const machineLearning = - require('../machine-learning/machine-learning').MachineLearning; - return Object.assign(fn, { MachineLearning: machineLearning }); - } - - /** - * Gets the `Installations` service namespace. The returned namespace can be used to get the - * `Installations` service for the default app or an explicitly specified app. - */ - get installations(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).installations(); - }; - const installations = require('../installations/installations').Installations; - return Object.assign(fn, { Installations: installations }); - } - - /** - * Gets the `InstanceId` service namespace. The returned namespace can be used to get the - * `Instance` service for the default app or an explicitly specified app. - */ - get instanceId(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).instanceId(); - }; - const instanceId = require('../instance-id/instance-id').InstanceId; - return Object.assign(fn, { InstanceId: instanceId }); - } - - /** - * Gets the `ProjectManagement` service namespace. The returned namespace can be used to get the - * `ProjectManagement` service for the default app or an explicitly specified app. - */ - get projectManagement(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).projectManagement(); - }; - const projectManagement = require('../project-management/project-management').ProjectManagement; - return Object.assign(fn, { ProjectManagement: projectManagement }); - } - - /** - * Gets the `SecurityRules` service namespace. The returned namespace can be used to get the - * `SecurityRules` service for the default app or an explicitly specified app. - */ - get securityRules(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).securityRules(); - }; - const securityRules = require('../security-rules/security-rules').SecurityRules; - return Object.assign(fn, { SecurityRules: securityRules }); - } - - /** - * Gets the `RemoteConfig` service namespace. The returned namespace can be used to get the - * `RemoteConfig` service for the default app or an explicitly specified app. - */ - get remoteConfig(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).remoteConfig(); - }; - const remoteConfig = require('../remote-config/remote-config').RemoteConfig; - return Object.assign(fn, { RemoteConfig: remoteConfig }); - } - - /** - * Gets the `AppCheck` service namespace. The returned namespace can be used to get the - * `AppCheck` service for the default app or an explicitly specified app. - */ - get appCheck(): FirebaseServiceNamespace { - const fn: FirebaseServiceNamespace = (app?: App) => { - return this.ensureApp(app).appCheck(); - }; - const appCheck = require('../app-check/app-check').AppCheck; - return Object.assign(fn, { AppCheck: appCheck }); - } - - // TODO: Change the return types to app.App in the following methods. - - /** - * Initializes the FirebaseApp instance. - * - * @param options - Optional options for the FirebaseApp instance. - * If none present will try to initialize from the FIREBASE_CONFIG environment variable. - * If the environment variable contains a string that starts with '{' it will be parsed as JSON, - * otherwise it will be assumed to be pointing to a file. - * @param appName - Optional name of the FirebaseApp instance. - * - * @returns A new FirebaseApp instance. - */ - public initializeApp(options?: AppOptions, appName?: string): App { - return this.INTERNAL.initializeApp(options, appName); - } - - /** - * Returns the FirebaseApp instance with the provided name (or the default FirebaseApp instance - * if no name is provided). - * - * @param appName - Optional name of the FirebaseApp instance to return. - * @returns The FirebaseApp instance which has the provided name. - */ - public app(appName?: string): App { - return this.INTERNAL.app(appName); - } - - /* - * Returns an array of all the non-deleted FirebaseApp instances. - */ - public get apps(): App[] { - return this.INTERNAL.apps; - } - - private ensureApp(app?: App): App { - if (typeof app === 'undefined') { - app = this.app(); - } - return app; - } -} - -/** - * In order to maintain backward compatibility, we instantiate a default namespace instance in - * this module, and delegate all app lifecycle operations to it. In a future implementation where - * the old admin namespace is no longer supported, we should remove this. - * - * @internal - */ -export const defaultNamespace = new FirebaseNamespace(defaultAppStore); - -function extendApp(app: AppCore): App { - const result: App = app as App; - if ((result as any).__extended) { - return result; - } - - result.auth = () => { - const fn = require('../auth/index').getAuth; - return fn(app); - }; - - result.appCheck = () => { - const fn = require('../app-check/index').getAppCheck; - return fn(app); - }; - - result.database = (url?: string) => { - const fn = require('../database/index').getDatabaseWithUrl; - return fn(url, app); - }; - - result.messaging = () => { - const fn = require('../messaging/index').getMessaging; - return fn(app); - }; - - result.storage = () => { - const fn = require('../storage/index').getStorage; - return fn(app); - }; - - result.firestore = () => { - const fn = require('../firestore/index').getFirestore; - return fn(app); - }; - - result.instanceId = () => { - const fn = require('../instance-id/index').getInstanceId; - return fn(app); - } - - result.installations = () => { - const fn = require('../installations/index').getInstallations; - return fn(app); - }; - - result.machineLearning = () => { - const fn = require('../machine-learning/index').getMachineLearning; - return fn(app); - } - - result.projectManagement = () => { - const fn = require('../project-management/index').getProjectManagement; - return fn(app); - }; - - result.securityRules = () => { - const fn = require('../security-rules/index').getSecurityRules; - return fn(app); - }; - - result.remoteConfig = () => { - const fn = require('../remote-config/index').getRemoteConfig; - return fn(app); - }; - - (result as any).__extended = true; - return result; -} diff --git a/src/auth/auth-namespace.ts b/src/auth/auth-namespace.ts deleted file mode 100644 index 7c450e8a61..0000000000 --- a/src/auth/auth-namespace.ts +++ /dev/null @@ -1,381 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app/index'; - -// Import all public types with aliases, and re-export from the auth namespace. - -import { ActionCodeSettings as TActionCodeSettings } from './action-code-settings-builder'; - -import { Auth as TAuth } from './auth'; - -import { - AuthFactorType as TAuthFactorType, - AuthProviderConfig as TAuthProviderConfig, - AuthProviderConfigFilter as TAuthProviderConfigFilter, - CreateRequest as TCreateRequest, - CreateMultiFactorInfoRequest as TCreateMultiFactorInfoRequest, - CreatePhoneMultiFactorInfoRequest as TCreatePhoneMultiFactorInfoRequest, - EmailSignInProviderConfig as TEmailSignInProviderConfig, - ListProviderConfigResults as TListProviderConfigResults, - MultiFactorCreateSettings as TMultiFactorCreateSettings, - MultiFactorConfig as TMultiFactorConfig, - MultiFactorConfigState as TMultiFactorConfigState, - MultiFactorUpdateSettings as TMultiFactorUpdateSettings, - OIDCAuthProviderConfig as TOIDCAuthProviderConfig, - OIDCUpdateAuthProviderRequest as TOIDCUpdateAuthProviderRequest, - SAMLAuthProviderConfig as TSAMLAuthProviderConfig, - SAMLUpdateAuthProviderRequest as TSAMLUpdateAuthProviderRequest, - UpdateAuthProviderRequest as TUpdateAuthProviderRequest, - UpdateMultiFactorInfoRequest as TUpdateMultiFactorInfoRequest, - UpdatePhoneMultiFactorInfoRequest as TUpdatePhoneMultiFactorInfoRequest, - UpdateRequest as TUpdateRequest, -} from './auth-config'; - -import { - BaseAuth as TBaseAuth, - DeleteUsersResult as TDeleteUsersResult, - GetUsersResult as TGetUsersResult, - ListUsersResult as TListUsersResult, - SessionCookieOptions as TSessionCookieOptions, -} from './base-auth'; - -import { - EmailIdentifier as TEmailIdentifier, - PhoneIdentifier as TPhoneIdentifier, - ProviderIdentifier as TProviderIdentifier, - UserIdentifier as TUserIdentifier, - UidIdentifier as TUidIdentifier, -} from './identifier'; - -import { - CreateTenantRequest as TCreateTenantRequest, - Tenant as TTenant, - UpdateTenantRequest as TUpdateTenantRequest, -} from './tenant'; - -import { - ListTenantsResult as TListTenantsResult, - TenantAwareAuth as TTenantAwareAuth, - TenantManager as TTenantManager, -} from './tenant-manager'; - -import { - DecodedIdToken as TDecodedIdToken, - DecodedAuthBlockingToken as TDecodedAuthBlockingToken, -} from './token-verifier'; - -import { - HashAlgorithmType as THashAlgorithmType, - UserImportOptions as TUserImportOptions, - UserImportRecord as TUserImportRecord, - UserImportResult as TUserImportResult, - UserMetadataRequest as TUserMetadataRequest, - UserProviderRequest as TUserProviderRequest, -} from './user-import-builder'; - -import { - MultiFactorInfo as TMultiFactorInfo, - MultiFactorSettings as TMultiFactorSettings, - PhoneMultiFactorInfo as TPhoneMultiFactorInfo, - UserInfo as TUserInfo, - UserMetadata as TUserMetadata, - UserRecord as TUserRecord, -} from './user-record'; - -/** - * Gets the {@link firebase-admin.auth#Auth} service for the default app or a - * given app. - * - * `admin.auth()` can be called with no arguments to access the default app's - * {@link firebase-admin.auth#Auth} service or as `admin.auth(app)` to access the - * {@link firebase-admin.auth#Auth} service associated with a specific app. - * - * @example - * ```javascript - * // Get the Auth service for the default app - * var defaultAuth = admin.auth(); - * ``` - * - * @example - * ```javascript - * // Get the Auth service for a given app - * var otherAuth = admin.auth(otherApp); - * ``` - * - */ -export declare function auth(app?: App): auth.Auth; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace auth { - /** - * Type alias to {@link firebase-admin.auth#ActionCodeSettings}. - */ - export type ActionCodeSettings = TActionCodeSettings; - - /** - * Type alias to {@link firebase-admin.auth#Auth}. - */ - export type Auth = TAuth; - - /** - * Type alias to {@link firebase-admin.auth#AuthFactorType}. - */ - export type AuthFactorType = TAuthFactorType; - - /** - * Type alias to {@link firebase-admin.auth#AuthProviderConfig}. - */ - export type AuthProviderConfig = TAuthProviderConfig; - - /** - * Type alias to {@link firebase-admin.auth#AuthProviderConfigFilter}. - */ - export type AuthProviderConfigFilter = TAuthProviderConfigFilter; - - /** - * Type alias to {@link firebase-admin.auth#BaseAuth}. - */ - export type BaseAuth = TBaseAuth; - - /** - * Type alias to {@link firebase-admin.auth#CreateMultiFactorInfoRequest}. - */ - export type CreateMultiFactorInfoRequest = TCreateMultiFactorInfoRequest; - - /** - * Type alias to {@link firebase-admin.auth#CreatePhoneMultiFactorInfoRequest}. - */ - export type CreatePhoneMultiFactorInfoRequest = TCreatePhoneMultiFactorInfoRequest; - - /** - * Type alias to {@link firebase-admin.auth#CreateRequest}. - */ - export type CreateRequest = TCreateRequest; - - /** - * Type alias to {@link firebase-admin.auth#CreateTenantRequest}. - */ - export type CreateTenantRequest = TCreateTenantRequest; - - /** - * Type alias to {@link firebase-admin.auth#DecodedIdToken}. - */ - export type DecodedIdToken = TDecodedIdToken; - - /** @alpha */ - export type DecodedAuthBlockingToken = TDecodedAuthBlockingToken; - - /** - * Type alias to {@link firebase-admin.auth#DeleteUsersResult}. - */ - export type DeleteUsersResult = TDeleteUsersResult; - - /** - * Type alias to {@link firebase-admin.auth#EmailIdentifier}. - */ - export type EmailIdentifier = TEmailIdentifier; - - /** - * Type alias to {@link firebase-admin.auth#EmailSignInProviderConfig}. - */ - export type EmailSignInProviderConfig = TEmailSignInProviderConfig; - - /** - * Type alias to {@link firebase-admin.auth#GetUsersResult}. - */ - export type GetUsersResult = TGetUsersResult; - - /** - * Type alias to {@link firebase-admin.auth#HashAlgorithmType}. - */ - export type HashAlgorithmType = THashAlgorithmType; - - /** - * Type alias to {@link firebase-admin.auth#ListProviderConfigResults}. - */ - export type ListProviderConfigResults = TListProviderConfigResults; - - /** - * Type alias to {@link firebase-admin.auth#ListTenantsResult}. - */ - export type ListTenantsResult = TListTenantsResult; - - /** - * Type alias to {@link firebase-admin.auth#ListUsersResult}. - */ - export type ListUsersResult = TListUsersResult; - - /** - * Type alias to {@link firebase-admin.auth#MultiFactorCreateSettings}. - */ - export type MultiFactorCreateSettings = TMultiFactorCreateSettings; - - /** - * Type alias to {@link firebase-admin.auth#MultiFactorConfig}. - */ - export type MultiFactorConfig = TMultiFactorConfig; - - /** - * Type alias to {@link firebase-admin.auth#MultiFactorConfigState}. - */ - export type MultiFactorConfigState = TMultiFactorConfigState; - - /** - * Type alias to {@link firebase-admin.auth#MultiFactorInfo}. - */ - export type MultiFactorInfo = TMultiFactorInfo; - - /** - * Type alias to {@link firebase-admin.auth#MultiFactorUpdateSettings}. - */ - export type MultiFactorUpdateSettings = TMultiFactorUpdateSettings; - - /** - * Type alias to {@link firebase-admin.auth#MultiFactorSettings}. - */ - export type MultiFactorSettings = TMultiFactorSettings; - - /** - * Type alias to {@link firebase-admin.auth#OIDCAuthProviderConfig}. - */ - export type OIDCAuthProviderConfig = TOIDCAuthProviderConfig; - - /** - * Type alias to {@link firebase-admin.auth#OIDCUpdateAuthProviderRequest}. - */ - export type OIDCUpdateAuthProviderRequest = TOIDCUpdateAuthProviderRequest; - - /** - * Type alias to {@link firebase-admin.auth#PhoneIdentifier}. - */ - export type PhoneIdentifier = TPhoneIdentifier; - - /** - * Type alias to {@link firebase-admin.auth#PhoneMultiFactorInfo}. - */ - export type PhoneMultiFactorInfo = TPhoneMultiFactorInfo; - - /** - * Type alias to {@link firebase-admin.auth#ProviderIdentifier}. - */ - export type ProviderIdentifier = TProviderIdentifier; - - /** - * Type alias to {@link firebase-admin.auth#SAMLAuthProviderConfig}. - */ - export type SAMLAuthProviderConfig = TSAMLAuthProviderConfig; - - /** - * Type alias to {@link firebase-admin.auth#SAMLUpdateAuthProviderRequest}. - */ - export type SAMLUpdateAuthProviderRequest = TSAMLUpdateAuthProviderRequest; - - /** - * Type alias to {@link firebase-admin.auth#SessionCookieOptions}. - */ - export type SessionCookieOptions = TSessionCookieOptions; - - /** - * Type alias to {@link firebase-admin.auth#Tenant}. - */ - export type Tenant = TTenant; - - /** - * Type alias to {@link firebase-admin.auth#TenantAwareAuth}. - */ - export type TenantAwareAuth = TTenantAwareAuth; - - /** - * Type alias to {@link firebase-admin.auth#TenantManager}. - */ - export type TenantManager = TTenantManager; - - /** - * Type alias to {@link firebase-admin.auth#UidIdentifier}. - */ - export type UidIdentifier = TUidIdentifier; - - /** - * Type alias to {@link firebase-admin.auth#UpdateAuthProviderRequest}. - */ - export type UpdateAuthProviderRequest = TUpdateAuthProviderRequest; - - /** - * Type alias to {@link firebase-admin.auth#UpdateMultiFactorInfoRequest}. - */ - export type UpdateMultiFactorInfoRequest = TUpdateMultiFactorInfoRequest; - - /** - * Type alias to {@link firebase-admin.auth#UpdatePhoneMultiFactorInfoRequest}. - */ - export type UpdatePhoneMultiFactorInfoRequest = TUpdatePhoneMultiFactorInfoRequest; - - /** - * Type alias to {@link firebase-admin.auth#UpdateRequest}. - */ - export type UpdateRequest = TUpdateRequest; - - /** - * Type alias to {@link firebase-admin.auth#UpdateTenantRequest}. - */ - export type UpdateTenantRequest = TUpdateTenantRequest; - - /** - * Type alias to {@link firebase-admin.auth#UserIdentifier}. - */ - export type UserIdentifier = TUserIdentifier; - - /** - * Type alias to {@link firebase-admin.auth#UserImportOptions}. - */ - export type UserImportOptions = TUserImportOptions; - - /** - * Type alias to {@link firebase-admin.auth#UserImportRecord}. - */ - export type UserImportRecord = TUserImportRecord; - - /** - * Type alias to {@link firebase-admin.auth#UserImportResult}. - */ - export type UserImportResult = TUserImportResult; - - /** - * Type alias to {@link firebase-admin.auth#UserInfo}. - */ - export type UserInfo = TUserInfo; - - /** - * Type alias to {@link firebase-admin.auth#UserMetadata}. - */ - export type UserMetadata = TUserMetadata; - - /** - * Type alias to {@link firebase-admin.auth#UserMetadataRequest}. - */ - export type UserMetadataRequest = TUserMetadataRequest; - - /** - * Type alias to {@link firebase-admin.auth#UserProviderRequest}. - */ - export type UserProviderRequest = TUserProviderRequest; - - /** - * Type alias to {@link firebase-admin.auth#UserRecord}. - */ - export type UserRecord = TUserRecord; -} diff --git a/src/database/database-namespace.ts b/src/database/database-namespace.ts deleted file mode 100644 index 03d116b7d2..0000000000 --- a/src/database/database-namespace.ts +++ /dev/null @@ -1,107 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as rtdb from '@firebase/database-types'; -import { App } from '../app'; -import { Database as TDatabase } from './database'; - -/** - * Gets the {@link firebase-admin.database#Database} service for the default - * app or a given app. - * - * `admin.database()` can be called with no arguments to access the default - * app's `Database` service or as `admin.database(app)` to access the - * `Database` service associated with a specific app. - * - * `admin.database` is also a namespace that can be used to access global - * constants and methods associated with the `Database` service. - * - * @example - * ```javascript - * // Get the Database service for the default app - * var defaultDatabase = admin.database(); - * ``` - * - * @example - * ```javascript - * // Get the Database service for a specific app - * var otherDatabase = admin.database(app); - * ``` - * - * @param App - whose `Database` service to - * return. If not provided, the default `Database` service will be returned. - * - * @returns The default `Database` service if no app - * is provided or the `Database` service associated with the provided app. - */ -export declare function database(app?: App): database.Database; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace database { - /** - * Type alias to {@link firebase-admin.database#Database}. - */ - export type Database = TDatabase; - - /** - * Type alias to {@link https://firebase.google.com/docs/reference/js/v8/firebase.database.DataSnapshot | DataSnapshot} - * type from the `@firebase/database-compat` package. - */ - export type DataSnapshot = rtdb.DataSnapshot; - - /** - * Type alias to the {@link https://firebase.google.com/docs/reference/js/v8/firebase.database#eventtype | EventType} - * type from the `@firebase/database-compat` package. - */ - export type EventType = rtdb.EventType; - - /** - * Type alias to {@link https://firebase.google.com/docs/reference/js/v8/firebase.database.OnDisconnect | OnDisconnect} - * type from the `@firebase/database-compat` package. - */ - export type OnDisconnect = rtdb.OnDisconnect; - - /** - * Type alias to {@link https://firebase.google.com/docs/reference/js/v8/firebase.database.Query | Query} - * type from the `@firebase/database-compat` package. - */ - export type Query = rtdb.Query; - - /** - * Type alias to {@link https://firebase.google.com/docs/reference/js/v8/firebase.database.Reference | Reference} - * type from the `@firebase/database-compat` package. - */ - export type Reference = rtdb.Reference; - - /** - * Type alias to {@link https://firebase.google.com/docs/reference/js/v8/firebase.database.ThenableReference | - * ThenableReference} type from the `@firebase/database-compat` package. - */ - export type ThenableReference = rtdb.ThenableReference; - - /** - * {@link https://firebase.google.com/docs/reference/js/v8/firebase.database#enablelogging | enableLogging} - * function from the `@firebase/database-compat` package. - */ - export declare const enableLogging: typeof rtdb.enableLogging; - - /** - * {@link https://firebase.google.com/docs/reference/js/v8/firebase.database.ServerValue | ServerValue} - * constant from the `@firebase/database-compat` package. - */ - // eslint-disable-next-line @typescript-eslint/naming-convention - export declare const ServerValue: rtdb.ServerValue; -} diff --git a/src/default-namespace.d.ts b/src/default-namespace.d.ts deleted file mode 100644 index c5c826a1e6..0000000000 --- a/src/default-namespace.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/*! - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Firebase namespaced API (legacy). - * - * @packageDocumentation - */ - -export * from './firebase-namespace-api'; diff --git a/src/default-namespace.ts b/src/default-namespace.ts deleted file mode 100644 index bd250cd79c..0000000000 --- a/src/default-namespace.ts +++ /dev/null @@ -1,31 +0,0 @@ -/*! - * @license - * Copyright 2017 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { defaultNamespace as firebaseAdmin } from './app/firebase-namespace'; - -// Inject a circular default export to allow users to use both: -// -// import firebaseAdmin from 'firebase-admin'; -// which becomes: var firebaseAdmin = require('firebase-admin').default; -// -// as well as the more correct: -// -// import * as firebaseAdmin from 'firebase-admin'; -// which becomes: var firebaseAdmin = require('firebase-admin'); -(firebaseAdmin as any).default = firebaseAdmin; - -export = firebaseAdmin; diff --git a/src/firebase-namespace-api.ts b/src/firebase-namespace-api.ts deleted file mode 100644 index 0d908f4915..0000000000 --- a/src/firebase-namespace-api.ts +++ /dev/null @@ -1,104 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { appCheck } from './app-check/app-check-namespace'; -import { auth } from './auth/auth-namespace'; -import { database } from './database/database-namespace'; -import { firestore } from './firestore/firestore-namespace'; -import { instanceId } from './instance-id/instance-id-namespace'; -import { installations } from './installations/installations-namespace'; -import { machineLearning } from './machine-learning/machine-learning-namespace'; -import { messaging } from './messaging/messaging-namespace'; -import { projectManagement } from './project-management/project-management-namespace'; -import { remoteConfig } from './remote-config/remote-config-namespace'; -import { securityRules } from './security-rules/security-rules-namespace'; -import { storage } from './storage/storage-namespace'; - -import { App as AppCore, AppOptions } from './app/index'; - -export { AppOptions, FirebaseError, FirebaseArrayIndexError, ErrorInfo, HttpResponse } from './app/index'; - -// eslint-disable-next-line @typescript-eslint/no-namespace -export namespace app { - /** - * A Firebase app holds the initialization information for a collection of - * services. - * - * Do not call this constructor directly. Instead, use - * {@link firebase-admin.app#initializeApp} to create an app. - */ - export interface App extends AppCore { - appCheck(): appCheck.AppCheck; - auth(): auth.Auth; - database(url?: string): database.Database; - firestore(): firestore.Firestore; - installations(): installations.Installations; - /** - * @deprecated Use {@link firebase-admin.installations#Installations} instead. - */ - instanceId(): instanceId.InstanceId; - machineLearning(): machineLearning.MachineLearning; - messaging(): messaging.Messaging; - projectManagement(): projectManagement.ProjectManagement; - remoteConfig(): remoteConfig.RemoteConfig; - securityRules(): securityRules.SecurityRules; - storage(): storage.Storage; - - /** - * Renders this local `FirebaseApp` unusable and frees the resources of - * all associated services (though it does *not* clean up any backend - * resources). When running the SDK locally, this method - * must be called to ensure graceful termination of the process. - * - * @example - * ```javascript - * app.delete() - * .then(function() { - * console.log("App deleted successfully"); - * }) - * .catch(function(error) { - * console.log("Error deleting app:", error); - * }); - * ``` - */ - delete(): Promise; - } -} - -export * from './credential/index'; -export { appCheck } from './app-check/app-check-namespace'; -export { auth } from './auth/auth-namespace'; -export { database } from './database/database-namespace'; -export { firestore } from './firestore/firestore-namespace'; -export { instanceId } from './instance-id/instance-id-namespace'; -export { installations } from './installations/installations-namespace'; -export { machineLearning } from './machine-learning/machine-learning-namespace'; -export { messaging } from './messaging/messaging-namespace'; -export { projectManagement } from './project-management/project-management-namespace'; -export { remoteConfig } from './remote-config/remote-config-namespace'; -export { securityRules } from './security-rules/security-rules-namespace'; -export { storage } from './storage/storage-namespace'; - -// Declare other top-level members of the admin namespace below. Unfortunately, there's no -// compile-time mechanism to ensure that the FirebaseNamespace class actually provides these -// signatures. But this part of the API is quite small and stable. It should be easy enough to -// enforce conformance via disciplined coding and good integration tests. - -export declare const SDK_VERSION: string; -export declare const apps: (app.App | null)[]; - -export declare function app(name?: string): app.App; -export declare function initializeApp(options?: AppOptions, name?: string): app.App; diff --git a/src/firestore/firestore-namespace.ts b/src/firestore/firestore-namespace.ts deleted file mode 100644 index 209d425436..0000000000 --- a/src/firestore/firestore-namespace.ts +++ /dev/null @@ -1,77 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as _firestore from '@google-cloud/firestore'; -import { App } from '../app'; - -export declare function firestore(app?: App): _firestore.Firestore; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace firestore { - // See https://github.com/typescript-eslint/typescript-eslint/issues/363 - export import v1beta1 = _firestore.v1beta1; - export import v1 = _firestore.v1; - - export import AggregateField = _firestore.AggregateField; - export import AggregateFieldType = _firestore.AggregateFieldType; - export import AggregateQuery = _firestore.AggregateQuery; - export import AggregateQuerySnapshot = _firestore.AggregateQuerySnapshot; - export import AggregateSpecData = _firestore.AggregateSpecData; - export import AggregateSpec = _firestore.AggregateSpec; - export import AggregateType = _firestore.AggregateType; - export import BulkWriter = _firestore.BulkWriter; - export import BulkWriterOptions = _firestore.BulkWriterOptions; - export import BundleBuilder = _firestore.BundleBuilder; - export import CollectionGroup = _firestore.CollectionGroup; - export import CollectionReference = _firestore.CollectionReference; - export import DocumentChange = _firestore.DocumentChange; - export import DocumentChangeType = _firestore.DocumentChangeType; - export import DocumentData = _firestore.DocumentData; - export import DocumentReference = _firestore.DocumentReference; - export import DocumentSnapshot = _firestore.DocumentSnapshot; - export import FieldPath = _firestore.FieldPath; - export import FieldValue = _firestore.FieldValue; - export import Filter = _firestore.Filter; - export import Firestore = _firestore.Firestore; - export import FirestoreDataConverter = _firestore.FirestoreDataConverter; - export import GeoPoint = _firestore.GeoPoint; - export import GrpcStatus = _firestore.GrpcStatus; - export import OrderByDirection = _firestore.OrderByDirection; - export import Precondition = _firestore.Precondition; - export import Query = _firestore.Query; - export import QueryDocumentSnapshot = _firestore.QueryDocumentSnapshot; - export import QueryPartition = _firestore.QueryPartition; - export import QuerySnapshot = _firestore.QuerySnapshot; - export import ReadOptions = _firestore.ReadOptions; - export import Settings = _firestore.Settings; - export import SetOptions = _firestore.SetOptions; - export import Timestamp = _firestore.Timestamp; - export import Transaction = _firestore.Transaction; - export import UpdateData = _firestore.UpdateData; - export import WhereFilterOp = _firestore.WhereFilterOp; - export import WriteBatch = _firestore.WriteBatch; - export import WriteResult = _firestore.WriteResult; - export import PartialWithFieldValue = _firestore.PartialWithFieldValue; - export import WithFieldValue = _firestore.WithFieldValue; - export import Primitive = _firestore.Primitive; - export import NestedUpdateFields = _firestore.NestedUpdateFields; - export import ChildUpdateFields = _firestore.ChildUpdateFields; - export import AddPrefixToKeys = _firestore.AddPrefixToKeys; - export import UnionToIntersection = _firestore.UnionToIntersection; - export import ReadOnlyTransactionOptions = _firestore.ReadOnlyTransactionOptions; - - export import setLogFunction = _firestore.setLogFunction; -} diff --git a/src/index.d.ts b/src/index.d.ts deleted file mode 100644 index cb5413cd2d..0000000000 --- a/src/index.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/*! - * @license - * Copyright 2017 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as admin from './default-namespace'; - -declare module 'firebase-admin' { -} - -export = admin; diff --git a/src/index.ts b/src/index.ts index cdc5b6c64d..1d38018798 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firebase from './default-namespace'; +import { getSdkVersion } from './utils'; // Only Node.js has a process variable that is of [[Class]] process const processGlobal = typeof process !== 'undefined' ? process : 0; @@ -35,4 +35,14 @@ https://firebase.google.com/docs/web/setup console.error(message); } -export = firebase; +export { App, AppOptions, FirebaseArrayIndexError } from './app/core'; +export { initializeApp, getApp, getApps, deleteApp } from './app/lifecycle'; + +export { Credential, ServiceAccount, GoogleOAuthAccessToken } from './app/credential'; +export { applicationDefault, cert, refreshToken } from './app/credential-factory'; + +export { FirebaseError, ErrorInfo, HttpResponse } from './utils/error'; +export { FirebaseAppError, AppErrorCode } from './app/error'; + +export const SDK_VERSION = getSdkVersion(); + diff --git a/src/installations/installations-namespace.ts b/src/installations/installations-namespace.ts deleted file mode 100644 index f2bd180205..0000000000 --- a/src/installations/installations-namespace.ts +++ /dev/null @@ -1,58 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app/index'; -import { Installations as TInstallations } from './installations'; - -/** - * Gets the {@link firebase-admin.installations#Installations} service for the - * default app or a given app. - * - * `admin.installations()` can be called with no arguments to access the default - * app's {@link firebase-admin.installations#Installations} service or as - * `admin.installations(app)` to access the - * {@link firebase-admin.installations#Installations} service associated with a - * specific app. - * - * @example - * ```javascript - * // Get the Installations service for the default app - * var defaultInstallations = admin.installations(); - * ``` - * - * @example - * ```javascript - * // Get the Installations service for a given app - * var otherInstallations = admin.installations(otherApp); - *``` - * - * @param app - Optional app whose `Installations` service to - * return. If not provided, the default `Installations` service is - * returned. - * - * @returns The default `Installations` service if - * no app is provided or the `Installations` service associated with the - * provided app. - */ -export declare function installations(app?: App): installations.Installations; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace installations { - /** - * Type alias to {@link firebase-admin.installations#Installations}. - */ - export type Installations = TInstallations; -} diff --git a/src/instance-id/instance-id-namespace.ts b/src/instance-id/instance-id-namespace.ts deleted file mode 100644 index 285828e472..0000000000 --- a/src/instance-id/instance-id-namespace.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { App } from '../app/index'; -import { InstanceId as TInstanceId } from './instance-id'; - -/** - * Gets the {@link firebase-admin.instance-id#InstanceId} service for the - * default app or a given app. - * - * `admin.instanceId()` can be called with no arguments to access the default - * app's `InstanceId` service or as `admin.instanceId(app)` to access the - * `InstanceId` service associated with a specific app. - * - * @example - * ```javascript - * // Get the Instance ID service for the default app - * var defaultInstanceId = admin.instanceId(); - * ``` - * - * @example - * ```javascript - * // Get the Instance ID service for a given app - * var otherInstanceId = admin.instanceId(otherApp); - *``` - * - * @param app - Optional app whose `InstanceId` service to - * return. If not provided, the default `InstanceId` service will be - * returned. - * - * @returns The default `InstanceId` service if - * no app is provided or the `InstanceId` service associated with the - * provided app. - */ -export declare function instanceId(app?: App): instanceId.InstanceId; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace instanceId { - /** - * Type alias to {@link firebase-admin.instance-id#InstanceId}. - */ - export type InstanceId = TInstanceId; -} diff --git a/src/machine-learning/machine-learning-namespace.ts b/src/machine-learning/machine-learning-namespace.ts deleted file mode 100644 index 5131390a67..0000000000 --- a/src/machine-learning/machine-learning-namespace.ts +++ /dev/null @@ -1,101 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app'; -import { - ListModelsResult as TListModelsResult, - MachineLearning as TMachineLearning, - Model as TModel, - TFLiteModel as TTFLiteModel, -} from './machine-learning'; -import { - GcsTfliteModelOptions as TGcsTfliteModelOptions, - ListModelsOptions as TListModelsOptions, - ModelOptions as TModelOptions, - ModelOptionsBase as TModelOptionsBase, -} from './machine-learning-api-client'; - -/** - * Gets the {@link firebase-admin.machine-learning#MachineLearning} service for the - * default app or a given app. - * - * `admin.machineLearning()` can be called with no arguments to access the - * default app's `MachineLearning` service or as `admin.machineLearning(app)` to access - * the `MachineLearning` service associated with a specific app. - * - * @example - * ```javascript - * // Get the MachineLearning service for the default app - * var defaultMachineLearning = admin.machineLearning(); - * ``` - * - * @example - * ```javascript - * // Get the MachineLearning service for a given app - * var otherMachineLearning = admin.machineLearning(otherApp); - * ``` - * - * @param app - Optional app whose `MachineLearning` service to - * return. If not provided, the default `MachineLearning` service - * will be returned. - * - * @returns The default `MachineLearning` service if no app is provided or the - * `MachineLearning` service associated with the provided app. - */ -export declare function machineLearning(app?: App): machineLearning.MachineLearning; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace machineLearning { - /** - * Type alias to {@link firebase-admin.machine-learning#ListModelsResult}. - */ - export type ListModelsResult = TListModelsResult; - - /** - * Type alias to {@link firebase-admin.machine-learning#MachineLearning}. - */ - export type MachineLearning = TMachineLearning; - - /** - * Type alias to {@link firebase-admin.machine-learning#Model}. - */ - export type Model = TModel; - - /** - * Type alias to {@link firebase-admin.machine-learning#TFLiteModel}. - */ - export type TFLiteModel = TTFLiteModel; - - /** - * Type alias to {@link firebase-admin.machine-learning#GcsTfliteModelOptions}. - */ - export type GcsTfliteModelOptions = TGcsTfliteModelOptions; - - /** - * Type alias to {@link firebase-admin.machine-learning#ListModelsOptions}. - */ - export type ListModelsOptions = TListModelsOptions; - - /** - * Type alias to {@link firebase-admin.machine-learning#ModelOptions}. - */ - export type ModelOptions = TModelOptions; - - /** - * Type alias to {@link firebase-admin.machine-learning#ModelOptionsBase}. - */ - export type ModelOptionsBase = TModelOptionsBase; -} diff --git a/src/messaging/messaging-namespace.ts b/src/messaging/messaging-namespace.ts deleted file mode 100644 index be74cb4e79..0000000000 --- a/src/messaging/messaging-namespace.ts +++ /dev/null @@ -1,195 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app'; -import { Messaging as TMessaging } from './messaging'; -import { - AndroidConfig as TAndroidConfig, - AndroidFcmOptions as TAndroidFcmOptions, - AndroidNotification as TAndroidNotification, - ApnsConfig as TApnsConfig, - ApnsFcmOptions as TApnsFcmOptions, - ApnsPayload as TApnsPayload, - Aps as TAps, - ApsAlert as TApsAlert, - BatchResponse as TBatchResponse, - CriticalSound as TCriticalSound, - ConditionMessage as TConditionMessage, - FcmOptions as TFcmOptions, - LightSettings as TLightSettings, - Message as TMessage, - MessagingTopicManagementResponse as TMessagingTopicManagementResponse, - MulticastMessage as TMulticastMessage, - Notification as TNotification, - SendResponse as TSendResponse, - TokenMessage as TTokenMessage, - TopicMessage as TTopicMessage, - WebpushConfig as TWebpushConfig, - WebpushFcmOptions as TWebpushFcmOptions, - WebpushNotification as TWebpushNotification, -} from './messaging-api'; - -/** - * Gets the {@link firebase-admin.messaging#Messaging} service for the - * default app or a given app. - * - * `admin.messaging()` can be called with no arguments to access the default - * app's `Messaging` service or as `admin.messaging(app)` to access the - * `Messaging` service associated with a specific app. - * - * @example - * ```javascript - * // Get the Messaging service for the default app - * var defaultMessaging = admin.messaging(); - * ``` - * - * @example - * ```javascript - * // Get the Messaging service for a given app - * var otherMessaging = admin.messaging(otherApp); - * ``` - * - * @param app - Optional app whose `Messaging` service to - * return. If not provided, the default `Messaging` service will be returned. - * - * @returns The default `Messaging` service if no - * app is provided or the `Messaging` service associated with the provided - * app. - */ -export declare function messaging(app?: App): messaging.Messaging; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace messaging { - /** - * Type alias to {@link firebase-admin.messaging#Messaging}. - */ - export type Messaging = TMessaging; - - /** - * Type alias to {@link firebase-admin.messaging#AndroidConfig}. - */ - export type AndroidConfig = TAndroidConfig; - - /** - * Type alias to {@link firebase-admin.messaging#AndroidFcmOptions}. - */ - export type AndroidFcmOptions = TAndroidFcmOptions; - - /** - * Type alias to {@link firebase-admin.messaging#AndroidNotification}. - */ - export type AndroidNotification = TAndroidNotification; - - /** - * Type alias to {@link firebase-admin.messaging#ApnsConfig}. - */ - export type ApnsConfig = TApnsConfig; - - /** - * Type alias to {@link firebase-admin.messaging#ApnsFcmOptions}. - */ - export type ApnsFcmOptions = TApnsFcmOptions; - - /** - * Type alias to {@link firebase-admin.messaging#ApnsPayload}. - */ - export type ApnsPayload = TApnsPayload; - - /** - * Type alias to {@link firebase-admin.messaging#Aps}. - */ - export type Aps = TAps; - - /** - * Type alias to {@link firebase-admin.messaging#ApsAlert}. - */ - export type ApsAlert = TApsAlert; - - /** - * Type alias to {@link firebase-admin.messaging#BatchResponse}. - */ - export type BatchResponse = TBatchResponse; - - /** - * Type alias to {@link firebase-admin.messaging#CriticalSound}. - */ - export type CriticalSound = TCriticalSound; - - /** - * Type alias to {@link firebase-admin.messaging#ConditionMessage}. - */ - export type ConditionMessage = TConditionMessage; - - /** - * Type alias to {@link firebase-admin.messaging#FcmOptions}. - */ - export type FcmOptions = TFcmOptions; - - /** - * Type alias to {@link firebase-admin.messaging#LightSettings}. - */ - export type LightSettings = TLightSettings; - - /** - * Type alias to {@link firebase-admin.messaging#Message}. - */ - export type Message = TMessage; - - /** - * Type alias to {@link firebase-admin.messaging#MessagingTopicManagementResponse}. - */ - export type MessagingTopicManagementResponse = TMessagingTopicManagementResponse; - - /** - * Type alias to {@link firebase-admin.messaging#MulticastMessage}. - */ - export type MulticastMessage = TMulticastMessage; - - /** - * Type alias to {@link firebase-admin.messaging#Notification}. - */ - export type Notification = TNotification; - - /** - * Type alias to {@link firebase-admin.messaging#SendResponse}. - */ - export type SendResponse = TSendResponse; - - /** - * Type alias to {@link firebase-admin.messaging#TokenMessage}. - */ - export type TokenMessage = TTokenMessage; - - /** - * Type alias to {@link firebase-admin.messaging#TopicMessage}. - */ - export type TopicMessage = TTopicMessage; - - /** - * Type alias to {@link firebase-admin.messaging#WebpushConfig}. - */ - export type WebpushConfig = TWebpushConfig; - - /** - * Type alias to {@link firebase-admin.messaging#WebpushFcmOptions}. - */ - export type WebpushFcmOptions = TWebpushFcmOptions; - - /** - * Type alias to {@link firebase-admin.messaging#WebpushNotification}. - */ - export type WebpushNotification = TWebpushNotification; -} diff --git a/src/project-management/project-management-namespace.ts b/src/project-management/project-management-namespace.ts deleted file mode 100644 index ac58bc215e..0000000000 --- a/src/project-management/project-management-namespace.ts +++ /dev/null @@ -1,102 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app'; -import { - AppMetadata as TAppMetadata, - AppPlatform as TAppPlatform, -} from './app-metadata'; -import { ProjectManagement as TProjectManagement } from './project-management'; -import { - AndroidApp as TAndroidApp, - AndroidAppMetadata as TAndroidAppMetadata, - ShaCertificate as TShaCertificate, -} from './android-app'; -import { - IosApp as TIosApp, - IosAppMetadata as TIosAppMetadata, -} from './ios-app'; - -/** - * Gets the {@link firebase-admin.project-management#ProjectManagement} service for the - * default app or a given app. - * - * `admin.projectManagement()` can be called with no arguments to access the - * default app's `ProjectManagement` service, or as `admin.projectManagement(app)` to access - * the `ProjectManagement` service associated with a specific app. - * - * @example - * ```javascript - * // Get the ProjectManagement service for the default app - * var defaultProjectManagement = admin.projectManagement(); - * ``` - * - * @example - * ```javascript - * // Get the ProjectManagement service for a given app - * var otherProjectManagement = admin.projectManagement(otherApp); - * ``` - * - * @param app - Optional app whose `ProjectManagement` service - * to return. If not provided, the default `ProjectManagement` service will - * be returned. * - * @returns The default `ProjectManagement` service if no app is provided or the - * `ProjectManagement` service associated with the provided app. - */ -export declare function projectManagement(app?: App): projectManagement.ProjectManagement; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace projectManagement { - /** - * Type alias to {@link firebase-admin.project-management#AppMetadata}. - */ - export type AppMetadata = TAppMetadata; - - /** - * Type alias to {@link firebase-admin.project-management#AppPlatform}. - */ - export type AppPlatform = TAppPlatform; - - /** - * Type alias to {@link firebase-admin.project-management#ProjectManagement}. - */ - export type ProjectManagement = TProjectManagement; - - /** - * Type alias to {@link firebase-admin.project-management#IosApp}. - */ - export type IosApp = TIosApp; - - /** - * Type alias to {@link firebase-admin.project-management#IosAppMetadata}. - */ - export type IosAppMetadata = TIosAppMetadata; - - /** - * Type alias to {@link firebase-admin.project-management#AndroidApp}. - */ - export type AndroidApp = TAndroidApp; - - /** - * Type alias to {@link firebase-admin.project-management#AndroidAppMetadata}. - */ - export type AndroidAppMetadata = TAndroidAppMetadata; - - /** - * Type alias to {@link firebase-admin.project-management#ShaCertificate}. - */ - export type ShaCertificate = TShaCertificate; -} diff --git a/src/remote-config/remote-config-namespace.ts b/src/remote-config/remote-config-namespace.ts deleted file mode 100644 index abc315b150..0000000000 --- a/src/remote-config/remote-config-namespace.ts +++ /dev/null @@ -1,189 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app'; -import { - ExplicitParameterValue as TExplicitParameterValue, - InAppDefaultValue as TInAppDefaultValue, - RolloutValue as TRolloutValue, - PersonalizationValue as TPersonalizationValue, - ExperimentVariantExplicitValue as TExperimentVariantExplicitValue, - ExperimentVariantNoChange as TExperimentVariantNoChange, - ExperimentVariantValue as TExperimentVariantValue, - ExperimentValue as TExperimentValue, - RolloutParameterValue as TRolloutParameterValue, - PersonalizationParameterValue as TPersonalizationParameterValue, - ExperimentParameterValue as TExperimentParameterValue, - ListVersionsOptions as TListVersionsOptions, - ListVersionsResult as TListVersionsResult, - ParameterValueType as TParameterValueType, - RemoteConfigCondition as TRemoteConfigCondition, - RemoteConfigParameter as TRemoteConfigParameter, - RemoteConfigParameterGroup as TRemoteConfigParameterGroup, - RemoteConfigParameterValue as TRemoteConfigParameterValue, - RemoteConfigTemplate as TRemoteConfigTemplate, - RemoteConfigUser as TRemoteConfigUser, - TagColor as TTagColor, - Version as TVersion, -} from './remote-config-api'; -import { RemoteConfig as TRemoteConfig } from './remote-config'; - -/** - * Gets the {@link firebase-admin.remote-config#RemoteConfig} service for the - * default app or a given app. - * - * `admin.remoteConfig()` can be called with no arguments to access the default - * app's `RemoteConfig` service or as `admin.remoteConfig(app)` to access the - * `RemoteConfig` service associated with a specific app. - * - * @example - * ```javascript - * // Get the `RemoteConfig` service for the default app - * var defaultRemoteConfig = admin.remoteConfig(); - * ``` - * - * @example - * ```javascript - * // Get the `RemoteConfig` service for a given app - * var otherRemoteConfig = admin.remoteConfig(otherApp); - * ``` - * - * @param app - Optional app for which to return the `RemoteConfig` service. - * If not provided, the default `RemoteConfig` service is returned. - * - * @returns The default `RemoteConfig` service if no - * app is provided, or the `RemoteConfig` service associated with the provided - * app. - */ -export declare function remoteConfig(app?: App): remoteConfig.RemoteConfig; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace remoteConfig { - /** - * Type alias to {@link firebase-admin.remote-config#ExplicitParameterValue}. - */ - export type ExplicitParameterValue = TExplicitParameterValue; - - /** - * Type alias to {@link firebase-admin.remote-config#InAppDefaultValue}. - */ - export type InAppDefaultValue = TInAppDefaultValue; - - /** - * Type alias to {@link firebase-admin.remote-config#RolloutValue}. - */ - export type RolloutValue = TRolloutValue; - - /** - * Type alias to {@link firebase-admin.remote-config#PersonalizationValue}. - */ - export type PersonalizationValue = TPersonalizationValue; - - /** - * Type alias to {@link firebase-admin.remote-config#ExperimentVariantExplicitValue}. - */ - export type ExperimentVariantExplicitValue = TExperimentVariantExplicitValue; - - /** - * Type alias to {@link firebase-admin.remote-config#ExperimentVariantNoChange}. - */ - export type ExperimentVariantNoChange = TExperimentVariantNoChange; - - /** - * Type alias to {@link firebase-admin.remote-config#ExperimentVariantValue}. - */ - export type ExperimentVariantValue = TExperimentVariantValue; - - /** - * Type alias to {@link firebase-admin.remote-config#ExperimentValue}. - */ - export type ExperimentValue = TExperimentValue; - - /** - * Type alias to {@link firebase-admin.remote-config#RolloutParameterValue}. - */ - export type RolloutParameterValue = TRolloutParameterValue; - - /** - * Type alias to {@link firebase-admin.remote-config#PersonalizationParameterValue}. - */ - export type PersonalizationParameterValue = TPersonalizationParameterValue; - - /** - * Type alias to {@link firebase-admin.remote-config#ExperimentParameterValue}. - */ - export type ExperimentParameterValue = TExperimentParameterValue; - - /** - * Type alias to {@link firebase-admin.remote-config#ListVersionsOptions}. - */ - export type ListVersionsOptions = TListVersionsOptions; - - /** - * Type alias to {@link firebase-admin.remote-config#ListVersionsResult}. - */ - export type ListVersionsResult = TListVersionsResult; - - /** - * Type alias to {@link firebase-admin.remote-config#ParameterValueType}. - */ - export type ParameterValueType = TParameterValueType; - - /** - * Type alias to {@link firebase-admin.remote-config#RemoteConfig}. - */ - export type RemoteConfig = TRemoteConfig; - - /** - * Type alias to {@link firebase-admin.remote-config#RemoteConfigCondition}. - */ - export type RemoteConfigCondition = TRemoteConfigCondition; - - /** - * Type alias to {@link firebase-admin.remote-config#RemoteConfigParameter}. - */ - export type RemoteConfigParameter = TRemoteConfigParameter; - - /** - * Type alias to {@link firebase-admin.remote-config#RemoteConfigParameterGroup}. - */ - export type RemoteConfigParameterGroup = TRemoteConfigParameterGroup; - - /** - * Type alias to {@link firebase-admin.remote-config#RemoteConfigParameterValue}. - */ - export type RemoteConfigParameterValue = TRemoteConfigParameterValue; - - /** - * Type alias to {@link firebase-admin.remote-config#RemoteConfigTemplate}. - */ - export type RemoteConfigTemplate = TRemoteConfigTemplate; - - /** - * Type alias to {@link firebase-admin.remote-config#RemoteConfigUser}. - */ - export type RemoteConfigUser = TRemoteConfigUser; - - /** - * Type alias to {@link firebase-admin.remote-config#TagColor}. - */ - export type TagColor = TTagColor; - - /** - * Type alias to {@link firebase-admin.remote-config#Version}. - */ - export type Version = TVersion; -} diff --git a/src/security-rules/security-rules-namespace.ts b/src/security-rules/security-rules-namespace.ts deleted file mode 100644 index d61ba294fb..0000000000 --- a/src/security-rules/security-rules-namespace.ts +++ /dev/null @@ -1,82 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app'; -import { - RulesFile as TRulesFile, - Ruleset as TRuleset, - RulesetMetadata as TRulesetMetadata, - RulesetMetadataList as TRulesetMetadataList, - SecurityRules as TSecurityRules, -} from './security-rules'; - -/** - * Gets the {@link firebase-admin.security-rules#SecurityRules} service for the default - * app or a given app. - * - * `admin.securityRules()` can be called with no arguments to access the - * default app's {@link firebase-admin.security-rules#SecurityRules} - * service, or as `admin.securityRules(app)` to access - * the {@link firebase-admin.security-rules#SecurityRules} - * service associated with a specific app. - * - * @example - * ```javascript - * // Get the SecurityRules service for the default app - * var defaultSecurityRules = admin.securityRules(); - * ``` - * - * @example - * ```javascript - * // Get the SecurityRules service for a given app - * var otherSecurityRules = admin.securityRules(otherApp); - * ``` - * - * @param app - Optional app to return the `SecurityRules` service - * for. If not provided, the default `SecurityRules` service - * is returned. - * @returns The default `SecurityRules` service if no app is provided, or the - * `SecurityRules` service associated with the provided app. - */ -export declare function securityRules(app?: App): securityRules.SecurityRules; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace securityRules { - /** - * Type alias to {@link firebase-admin.security-rules#RulesFile}. - */ - export type RulesFile = TRulesFile; - - /** - * Type alias to {@link firebase-admin.security-rules#Ruleset}. - */ - export type Ruleset = TRuleset; - - /** - * Type alias to {@link firebase-admin.security-rules#RulesetMetadata}. - */ - export type RulesetMetadata = TRulesetMetadata; - - /** - * Type alias to {@link firebase-admin.security-rules#RulesetMetadataList}. - */ - export type RulesetMetadataList = TRulesetMetadataList; - - /** - * Type alias to {@link firebase-admin.security-rules#SecurityRules}. - */ - export type SecurityRules = TSecurityRules; -} diff --git a/src/storage/storage-namespace.ts b/src/storage/storage-namespace.ts deleted file mode 100644 index 29c88068cc..0000000000 --- a/src/storage/storage-namespace.ts +++ /dev/null @@ -1,48 +0,0 @@ -/*! - * Copyright 2021 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { App } from '../app'; -import { Storage as TStorage } from './storage'; - -/** - * Gets the {@link firebase-admin.storage#Storage} service for the - * default app or a given app. - * - * `admin.storage()` can be called with no arguments to access the default - * app's `Storage` service or as `admin.storage(app)` to access the - * `Storage` service associated with a specific app. - * - * @example - * ```javascript - * // Get the Storage service for the default app - * var defaultStorage = admin.storage(); - * ``` - * - * @example - * ```javascript - * // Get the Storage service for a given app - * var otherStorage = admin.storage(otherApp); - * ``` - */ -export declare function storage(app?: App): storage.Storage; - -/* eslint-disable @typescript-eslint/no-namespace */ -export namespace storage { - /** - * Type alias to {@link firebase-admin.storage#Storage}. - */ - export type Storage = TStorage; -} diff --git a/test/integration/app.spec.ts b/test/integration/app.spec.ts index d679dc5766..a86be4d737 100644 --- a/test/integration/app.spec.ts +++ b/test/integration/app.spec.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import * as admin from '../../lib/index'; import { App, deleteApp, getApp, initializeApp } from '../../lib/app/index'; import { getAuth } from '../../lib/auth/index'; import { expect } from 'chai'; @@ -53,25 +52,11 @@ describe('admin', () => { expect(firebaseRtdb).to.be.undefined; }); - it('loads RTDB when calling admin.database', () => { - const rtdbNamespace = admin.database; - expect(rtdbNamespace).to.not.be.null; - const firebaseRtdb = require.cache[require.resolve('@firebase/database-compat/standalone')]; - expect(firebaseRtdb).to.not.be.undefined; - }); - it('does not load Firestore by default', () => { const gcloud = require.cache[require.resolve('@google-cloud/firestore')]; expect(gcloud).to.be.undefined; }); - it('loads Firestore when calling admin.firestore', () => { - const firestoreNamespace = admin.firestore; - expect(firestoreNamespace).to.not.be.null; - const gcloud = require.cache[require.resolve('@google-cloud/firestore')]; - expect(gcloud).to.not.be.undefined; - }); - after(() => { dependencies.forEach((name) => { const resolvedName = require.resolve(name); @@ -82,51 +67,6 @@ describe('admin', () => { }); }); -describe('admin.app', () => { - it('admin.app() returns the default App', () => { - const app = admin.app(); - expect(app).to.deep.equal(defaultApp); - expect(app.name).to.equal('[DEFAULT]'); - expect(app.options.databaseURL).to.equal(databaseUrl); - expect(app.options.databaseAuthVariableOverride).to.be.undefined; - expect(app.options.storageBucket).to.equal(storageBucket); - }); - - it('admin.app("null") returns the App named "null"', () => { - const app = admin.app('null'); - expect(app).to.deep.equal(nullApp); - expect(app.name).to.equal('null'); - expect(app.options.databaseURL).to.equal(databaseUrl); - expect(app.options.databaseAuthVariableOverride).to.be.null; - expect(app.options.storageBucket).to.equal(storageBucket); - }); - - it('admin.app("nonNull") returns the App named "nonNull"', () => { - const app = admin.app('nonNull'); - expect(app).to.deep.equal(nonNullApp); - expect(app.name).to.equal('nonNull'); - expect(app.options.databaseURL).to.equal(databaseUrl); - expect((app.options.databaseAuthVariableOverride as any).uid).to.be.ok; - expect(app.options.storageBucket).to.equal(storageBucket); - }); - - it('namespace services are attached to the default App', () => { - const app = admin.app(); - expect(admin.auth(app).app).to.deep.equal(app); - expect(admin.database(app).app).to.deep.equal(app); - expect(admin.messaging(app).app).to.deep.equal(app); - expect(admin.storage(app).app).to.deep.equal(app); - }); - - it('namespace services are attached to the named App', () => { - const app = admin.app('null'); - expect(admin.auth(app).app).to.deep.equal(app); - expect(admin.database(app).app).to.deep.equal(app); - expect(admin.messaging(app).app).to.deep.equal(app); - expect(admin.storage(app).app).to.deep.equal(app); - }); -}); - describe('getApp', () => { it('getApp() returns the default App', () => { const app = getApp(); @@ -155,12 +95,12 @@ describe('getApp', () => { expect(app.options.storageBucket).to.equal(storageBucket); }); - it('namespace services are attached to the default App', () => { + it('modular services are attached to the default App', () => { const app = getApp(); expect(getAuth(app).app).to.deep.equal(app); }); - it('namespace services are attached to the named App', () => { + it('modular services are attached to the named App', () => { const app = getApp('null'); expect(getAuth(app).app).to.deep.equal(app); }); diff --git a/test/integration/database.spec.ts b/test/integration/database.spec.ts index 9b20d63e39..6bbbf321a9 100644 --- a/test/integration/database.spec.ts +++ b/test/integration/database.spec.ts @@ -16,7 +16,6 @@ import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import * as admin from '../../lib/index'; import { Database, DataSnapshot, EventType, Reference, ServerValue, getDatabase, getDatabaseWithUrl, } from '../../lib/database/index'; @@ -56,17 +55,6 @@ describe('admin.database', () => { expect(db).to.not.be.undefined; }); - it('admin.database() returns a database client', () => { - const db: admin.database.Database = admin.database(); - expect(db).to.not.be.undefined; - expect(db).to.equal(getDatabase()); - }); - - it('admin.database.ServerValue type is defined', () => { - const serverValue = admin.database.ServerValue; - expect(serverValue).to.not.be.null; - }); - it('default App is not blocked by security rules', () => { return getDatabase(defaultApp).ref('blocked').set(ServerValue.TIMESTAMP) .should.eventually.be.fulfilled; @@ -79,7 +67,7 @@ describe('admin.database', () => { // remove this once updating security rules through admin is in place. return this.skip(); } - return getDatabase(nullApp).ref('blocked').set(admin.database.ServerValue.TIMESTAMP) + return getDatabase(nullApp).ref('blocked').set(ServerValue.TIMESTAMP) .should.eventually.be.rejectedWith('PERMISSION_DENIED: Permission denied'); }); @@ -141,12 +129,6 @@ describe('admin.database', () => { expect(db).to.not.be.undefined; }); - it('app.database(url) returns a Database client for URL', () => { - const db: Database = admin.app().database(databaseUrl); - expect(db).to.not.be.undefined; - expect(db).to.equal(getDatabaseWithUrl(databaseUrl)); - }); - it('set() completes successfully', () => { return refWithUrl.set({ success: true, diff --git a/test/integration/firestore.spec.ts b/test/integration/firestore.spec.ts index 18cb9e75a8..08dcabe01c 100644 --- a/test/integration/firestore.spec.ts +++ b/test/integration/firestore.spec.ts @@ -17,7 +17,7 @@ import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import { clone } from 'lodash'; -import * as admin from '../../lib/index'; +import { getApp } from '../../lib/app/index'; import { DocumentReference, DocumentSnapshot, FieldValue, Firestore, FirestoreDataConverter, QueryDocumentSnapshot, Timestamp, getFirestore, initializeFirestore, setLogFunction, @@ -48,18 +48,7 @@ describe('admin.firestore', () => { }); it('initializeFirestore returns a Firestore client', () => { - const firestore: Firestore = initializeFirestore(admin.app()); - expect(firestore).to.not.be.undefined; - }); - - it('admin.firestore() returns a Firestore client', () => { - const firestore: admin.firestore.Firestore = admin.firestore(); - expect(firestore).to.not.be.undefined; - expect(firestore).to.equal(getFirestore()); - }); - - it('app.firestore() returns a Firestore client', () => { - const firestore: admin.firestore.Firestore = admin.app().firestore(); + const firestore: Firestore = initializeFirestore(getApp()); expect(firestore).to.not.be.undefined; }); @@ -98,44 +87,6 @@ describe('admin.firestore', () => { .should.eventually.be.fulfilled; }); - it('admin.firestore.CollectionReference type is defined', () => { - expect(typeof admin.firestore.CollectionReference).to.be.not.undefined; - }); - - it('admin.firestore.FieldPath type is defined', () => { - expect(typeof admin.firestore.FieldPath).to.be.not.undefined; - }); - - it('admin.firestore.FieldValue type is defined', () => { - expect(typeof admin.firestore.FieldValue).to.be.not.undefined; - }); - - it('admin.firestore.Filter type is defined', () => { - expect(typeof admin.firestore.Filter).to.be.not.undefined; - }); - - it('admin.firestore.GeoPoint type is defined', () => { - expect(typeof admin.firestore.GeoPoint).to.be.not.undefined; - }); - - it('admin.firestore.Timestamp type is defined', () => { - const now = admin.firestore.Timestamp.now(); - expect(typeof now.seconds).to.equal('number'); - expect(typeof now.nanoseconds).to.equal('number'); - }); - - it('admin.firestore.WriteBatch type is defined', () => { - expect(typeof admin.firestore.WriteBatch).to.be.not.undefined; - }); - - it('admin.firestore.WriteResult type is defined', () => { - expect(typeof admin.firestore.WriteResult).to.be.not.undefined; - }); - - it('admin.firestore.GrpcStatus type is defined', () => { - expect(typeof admin.firestore.GrpcStatus).to.be.not.undefined; - }); - it('supports operations with custom type converters', () => { const converter: FirestoreDataConverter = { toFirestore: (city: City) => { diff --git a/test/integration/postcheck/tsconfig.json b/test/integration/postcheck/tsconfig.json index c67333ffa1..3828395fd2 100644 --- a/test/integration/postcheck/tsconfig.json +++ b/test/integration/postcheck/tsconfig.json @@ -11,6 +11,6 @@ ] }, "files": [ - "./typescript/example.ts" + "./typescript/example-modular.test.ts" ] } diff --git a/test/integration/postcheck/typescript/example.test.ts b/test/integration/postcheck/typescript/example.test.ts deleted file mode 100644 index 9f94461e67..0000000000 --- a/test/integration/postcheck/typescript/example.test.ts +++ /dev/null @@ -1,102 +0,0 @@ -/*! - * @license - * Copyright 2017 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import initApp from './example'; -import { expect } from 'chai'; -import { Bucket } from '@google-cloud/storage'; -import { Firestore } from '@google-cloud/firestore'; - -import * as admin from 'firebase-admin'; - -const serviceAccount = require('../mock.key.json'); - -describe('Legacy API', () => { - let app: admin.app.App; - - before(() => { - app = initApp(serviceAccount, 'TestApp'); - }); - - after(() => { - return app.delete(); - }); - - it('Should return an initialized App', () => { - expect(app.name).to.equal('TestApp'); - }); - - it('Should return an Auth client', () => { - const client = admin.auth(app); - expect(client).to.be.instanceOf((admin.auth as any).Auth); - }); - - it('Should return a Messaging client', () => { - const client = admin.messaging(app); - expect(client).to.be.instanceOf((admin.messaging as any).Messaging); - }); - - it('Should return a ProjectManagement client', () => { - const client = admin.projectManagement(app); - expect(client).to.be.instanceOf((admin.projectManagement as any).ProjectManagement); - }); - - it('Should return a SecurityRules client', () => { - const client = admin.securityRules(app); - expect(client).to.be.instanceOf((admin.securityRules as any).SecurityRules); - }); - - it('Should return a Database client', () => { - const db = admin.database(app); - expect(db).to.be.instanceOf((admin.database as any).Database); - }); - - it('Should return a Database client for URL', () => { - const db = app.database('https://other-mock.firebaseio.com'); - expect(db).to.be.instanceOf((admin.database as any).Database); - }); - - it('Should return a Database ServerValue', () => { - const serverValue = admin.database.ServerValue; - expect(serverValue).to.not.be.null; - }); - - it('Should return a Cloud Storage client', () => { - const storage: admin.storage.Storage = app.storage(); - const bucket: Bucket = storage.bucket('TestBucket'); - expect(bucket.name).to.equal('TestBucket'); - }); - - it('Should return a Firestore client from the app', () => { - const firestore: Firestore = app.firestore(); - expect(firestore).to.be.instanceOf(admin.firestore.Firestore); - }); - - it('Should return a Firestore client', () => { - const firestore: Firestore = admin.firestore(app); - expect(firestore).to.be.instanceOf(admin.firestore.Firestore); - }); - - it('Should return a Firestore FieldValue', () => { - const fieldValue = admin.firestore.FieldValue; - expect(fieldValue).to.not.be.null; - }); - - it('Should return a DocumentReference', () => { - const ref: admin.firestore.DocumentReference = admin.firestore(app).collection('test').doc(); - expect(ref).to.not.be.null; - }); -}); diff --git a/test/integration/postcheck/typescript/example.ts b/test/integration/postcheck/typescript/example.ts deleted file mode 100644 index f626ba374c..0000000000 --- a/test/integration/postcheck/typescript/example.ts +++ /dev/null @@ -1,35 +0,0 @@ -/*! - * @license - * Copyright 2017 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as firebase from 'firebase-admin'; - -export function initApp(serviceAcct: any, name: string): firebase.app.App { - return firebase.initializeApp({ - credential: firebase.credential.cert(serviceAcct), - databaseURL: 'https://mock.firebaseio.com' - }, name); -} - -export function addValueEventListener( - // Check for type compilation - db: firebase.database.Database, - callback: (s: firebase.database.DataSnapshot) => any): void { - const eventType: firebase.database.EventType = 'value'; - db.ref().on(eventType, callback); -} - -export default initApp; diff --git a/test/resources/mocks.ts b/test/resources/mocks.ts index 22cec41fde..25967c44d1 100644 --- a/test/resources/mocks.ts +++ b/test/resources/mocks.ts @@ -27,7 +27,7 @@ import * as _ from 'lodash'; import * as jwt from 'jsonwebtoken'; import * as sinon from 'sinon'; -import { AppOptions } from '../../src/firebase-namespace-api'; +import { AppOptions } from '../../src/app/index'; import { FirebaseApp } from '../../src/app/firebase-app'; import { Credential, GoogleOAuthAccessToken, cert } from '../../src/app/index'; import { ApplicationDefaultCredential } from '../../src/app/credential-internal'; diff --git a/test/unit/app/firebase-app.spec.ts b/test/unit/app/firebase-app.spec.ts index ce2b07cdbc..b8d725bf80 100644 --- a/test/unit/app/firebase-app.spec.ts +++ b/test/unit/app/firebase-app.spec.ts @@ -29,26 +29,9 @@ import * as mocks from '../../resources/mocks'; import { GoogleOAuthAccessToken } from '../../../src/app/index'; import { ServiceAccountCredential } from '../../../src/app/credential-internal'; import { FirebaseApp, FirebaseAccessToken } from '../../../src/app/firebase-app'; -import { FirebaseNamespace } from '../../../src/app/firebase-namespace'; -import { AppStore, FIREBASE_CONFIG_VAR } from '../../../src/app/lifecycle'; -import { - auth, messaging, machineLearning, storage, firestore, database, - instanceId, installations, projectManagement, securityRules, remoteConfig, appCheck, -} from '../../../src/firebase-namespace-api'; +import { AppStore, FIREBASE_CONFIG_VAR, initializeApp, defaultAppStore } from '../../../src/app/lifecycle'; import { FirebaseAppError, AppErrorCode } from '../../../src/app/error'; -import Auth = auth.Auth; -import Database = database.Database; -import Messaging = messaging.Messaging; -import MachineLearning = machineLearning.MachineLearning; -import Storage = storage.Storage; -import Firestore = firestore.Firestore; -import Installations = installations.Installations; -import InstanceId = instanceId.InstanceId; -import ProjectManagement = projectManagement.ProjectManagement; -import SecurityRules = securityRules.SecurityRules; -import RemoteConfig = remoteConfig.RemoteConfig; -import AppCheck = appCheck.AppCheck; chai.should(); chai.use(sinonChai); @@ -75,7 +58,6 @@ describe('FirebaseApp', () => { let mockApp: FirebaseApp; let clock: sinon.SinonFakeTimers; let getTokenStub: sinon.SinonStub; - let firebaseNamespace: FirebaseNamespace; let firebaseConfigVar: string | undefined; beforeEach(() => { @@ -87,7 +69,6 @@ describe('FirebaseApp', () => { clock = sinon.useFakeTimers(1000); firebaseConfigVar = process.env[FIREBASE_CONFIG_VAR]; delete process.env[FIREBASE_CONFIG_VAR]; - firebaseNamespace = new FirebaseNamespace(); mockApp = new FirebaseApp(mocks.appOptions, mocks.appName); }); @@ -101,6 +82,7 @@ describe('FirebaseApp', () => { } deleteSpy.resetHistory(); + return defaultAppStore.clearAllApps(); }); describe('#name', () => { @@ -164,7 +146,7 @@ describe('FirebaseApp', () => { it('should ignore the config file when options is not null', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config.json'; - const app = firebaseNamespace.initializeApp(mocks.appOptionsNoDatabaseUrl, mocks.appName); + const app = initializeApp(mocks.appOptionsNoDatabaseUrl, mocks.appName); expect(app.options.databaseAuthVariableOverride).to.be.undefined; expect(app.options.databaseURL).to.undefined; expect(app.options.projectId).to.be.undefined; @@ -174,7 +156,7 @@ describe('FirebaseApp', () => { it('should throw when the environment variable points to non existing file', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/non_existant.json'; try { - firebaseNamespace.initializeApp(); + initializeApp(); expect.fail('Should have failed'); } catch (err: any) { expect(err).to.be.instanceOf(FirebaseAppError); @@ -186,7 +168,7 @@ describe('FirebaseApp', () => { it('should throw when the environment variable contains bad json', () => { process.env[FIREBASE_CONFIG_VAR] = '{,,'; try { - firebaseNamespace.initializeApp(); + initializeApp(); expect.fail('Should have failed'); } catch (err: any) { expect(err).to.be.instanceOf(FirebaseAppError); @@ -198,7 +180,7 @@ describe('FirebaseApp', () => { it('should throw when the environment variable points to an empty file', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config_empty.json'; try { - firebaseNamespace.initializeApp(); + initializeApp(); expect.fail('Should have failed'); } catch (err: any) { expect(err).to.be.instanceOf(FirebaseAppError); @@ -210,7 +192,7 @@ describe('FirebaseApp', () => { it('should throw when the environment variable points to bad json', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config_bad.json'; try { - firebaseNamespace.initializeApp(); + initializeApp(); expect.fail('Should have failed'); } catch (err: any) { expect(err).to.be.instanceOf(FirebaseAppError); @@ -221,7 +203,7 @@ describe('FirebaseApp', () => { it('should ignore a bad config key in the config file', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config_bad_key.json'; - const app = firebaseNamespace.initializeApp(); + const app = initializeApp(); expect(app.options.projectId).to.equal('hipster-chat-mock'); expect(app.options.databaseAuthVariableOverride).to.be.undefined; expect(app.options.databaseURL).to.undefined; @@ -234,7 +216,7 @@ describe('FirebaseApp', () => { "notAValidKeyValue": "The key value here is not valid.", "projectId": "hipster-chat-mock" }`; - const app = firebaseNamespace.initializeApp(); + const app = initializeApp(); expect(app.options.projectId).to.equal('hipster-chat-mock'); expect(app.options.databaseAuthVariableOverride).to.be.undefined; expect(app.options.databaseURL).to.undefined; @@ -243,7 +225,7 @@ describe('FirebaseApp', () => { it('should not throw when the config file has a bad key and the config file is unused', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config_bad_key.json'; - const app = firebaseNamespace.initializeApp(mocks.appOptionsWithOverride, mocks.appName); + const app = initializeApp(mocks.appOptionsWithOverride, mocks.appName); expect(app.options.projectId).to.equal('project_id'); expect(app.options.databaseAuthVariableOverride).to.deep.equal({ 'some#string': 'some#val' }); expect(app.options.databaseURL).to.equal('https://databaseName.firebaseio.com'); @@ -256,7 +238,7 @@ describe('FirebaseApp', () => { "notAValidKeyValue": "The key value here is not valid.", "projectId": "hipster-chat-mock" }`; - const app = firebaseNamespace.initializeApp(mocks.appOptionsWithOverride, mocks.appName); + const app = initializeApp(mocks.appOptionsWithOverride, mocks.appName); expect(app.options.projectId).to.equal('project_id'); expect(app.options.databaseAuthVariableOverride).to.deep.equal({ 'some#string': 'some#val' }); expect(app.options.databaseURL).to.equal('https://databaseName.firebaseio.com'); @@ -265,7 +247,7 @@ describe('FirebaseApp', () => { it('should use explicitly specified options when available and ignore the config file', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config.json'; - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); + const app = initializeApp(mocks.appOptions, mocks.appName); expect(app.options.credential).to.be.instanceOf(ServiceAccountCredential); expect(app.options.databaseAuthVariableOverride).to.be.undefined; expect(app.options.databaseURL).to.equal('https://databaseName.firebaseio.com'); @@ -275,14 +257,14 @@ describe('FirebaseApp', () => { it('should not throw if some fields are missing', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config_partial.json'; - const app = firebaseNamespace.initializeApp(mocks.appOptionsAuthDB, mocks.appName); + const app = initializeApp(mocks.appOptionsAuthDB, mocks.appName); expect(app.options.databaseURL).to.equal('https://databaseName.firebaseio.com'); expect(app.options.projectId).to.be.undefined; expect(app.options.storageBucket).to.be.undefined; }); it('should not throw when the config environment variable is not set, and some options are present', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptionsNoDatabaseUrl, mocks.appName); + const app = initializeApp(mocks.appOptionsNoDatabaseUrl, mocks.appName); expect(app.options.credential).to.be.instanceOf(ServiceAccountCredential); expect(app.options.databaseURL).to.be.undefined; expect(app.options.projectId).to.be.undefined; @@ -292,14 +274,14 @@ describe('FirebaseApp', () => { it('should not throw if initializeApp invoked with the same options', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config.json'; expect(() => { - const app = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); - const app2 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); + const app = initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); + const app2 = initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); expect(app2).to.equal(app); }).to.not.throw(); }); it('should init with application default creds when no options provided and env variable is not set', () => { - const app = firebaseNamespace.initializeApp(); + const app = initializeApp(); expect(app.options.credential).to.not.be.undefined; expect(app.options.databaseURL).to.be.undefined; expect(app.options.projectId).to.be.undefined; @@ -308,7 +290,7 @@ describe('FirebaseApp', () => { it('should init with application default creds when no options provided and env variable is an empty json', () => { process.env[FIREBASE_CONFIG_VAR] = '{}'; - const app = firebaseNamespace.initializeApp(); + const app = initializeApp(); expect(app.options.credential).to.not.be.undefined; expect(app.options.databaseURL).to.be.undefined; expect(app.options.projectId).to.be.undefined; @@ -317,7 +299,7 @@ describe('FirebaseApp', () => { it('should init when no init arguments are provided and config var points to a file', () => { process.env[FIREBASE_CONFIG_VAR] = './test/resources/firebase_config.json'; - const app = firebaseNamespace.initializeApp(); + const app = initializeApp(); expect(app.options.credential).to.not.be.undefined; expect(app.options.databaseAuthVariableOverride).to.deep.equal({ 'some#key': 'some#val' }); expect(app.options.databaseURL).to.equal('https://hipster-chat.firebaseio.mock'); @@ -332,7 +314,7 @@ describe('FirebaseApp', () => { "projectId": "hipster-chat-mock", "storageBucket": "hipster-chat.appspot.mock" }`; - const app = firebaseNamespace.initializeApp(); + const app = initializeApp(); expect(app.options.credential).to.not.be.undefined; expect(app.options.databaseAuthVariableOverride).to.deep.equal({ 'some#key': 'some#val' }); expect(app.options.databaseURL).to.equal('https://hipster-chat.firebaseio.mock'); @@ -360,387 +342,20 @@ describe('FirebaseApp', () => { }); it('should call delete() on each service\'s internals', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); + const app = initializeApp(mocks.appOptions, mocks.appName); const svc1 = new TestService(); const svc2 = new TestService(); (app as any).ensureService_(mocks.serviceName, () => svc1); (app as any).ensureService_(mocks.serviceName + '2', () => svc2); - return app.delete().then(() => { + return (app as FirebaseApp).delete().then(() => { expect(svc1.deleted).to.be.true; expect(svc2.deleted).to.be.true; }); }); }); - describe('auth()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.auth(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the Auth namespace', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const authNamespace: Auth = app.auth(); - expect(authNamespace).not.be.null; - }); - - it('should return a cached version of Auth on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const serviceNamespace1: Auth = app.auth(); - const serviceNamespace2: Auth = app.auth(); - expect(serviceNamespace1).to.deep.equal(serviceNamespace2); - }); - }); - - describe('messaging()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.messaging(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the Messaging namespace', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const fcmNamespace: Messaging = app.messaging(); - expect(fcmNamespace).not.be.null; - }); - - it('should return a cached version of Messaging on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const serviceNamespace1: Messaging = app.messaging(); - const serviceNamespace2: Messaging = app.messaging(); - expect(serviceNamespace1).to.deep.equal(serviceNamespace2); - }); - }); - - describe('machineLearning()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.machineLearning(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the machineLearning client', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const machineLearning: MachineLearning = app.machineLearning(); - expect(machineLearning).to.not.be.null; - }); - - it('should return a cached version of MachineLearning on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const service1: MachineLearning = app.machineLearning(); - const service2: MachineLearning = app.machineLearning(); - expect(service1).to.equal(service2); - }); - }); - - describe('database()', () => { - afterEach(() => { - try { - firebaseNamespace.app(mocks.appName).delete(); - } catch (e) { - // ignore - } - }); - - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.database(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the Database', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const db: Database = app.database(); - expect(db).not.be.null; - }); - - it('should return the Database for different apps', () => { - const app1 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const app2 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName + '-other'); - const db1: Database = app1.database(); - const db2: Database = app2.database(); - expect(db1).to.not.deep.equal(db2); - expect(db1.ref().toString()).to.equal('https://databasename.firebaseio.com/'); - expect(db2.ref().toString()).to.equal('https://databasename.firebaseio.com/'); - return app2.delete(); - }); - - it('should throw when databaseURL is not set', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptionsNoDatabaseUrl, mocks.appName); - expect(() => { - app.database(); - }).to.throw('Can\'t determine Firebase Database URL.'); - }); - - it('should return a cached version of Database on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const db1: Database = app.database(); - const db2: Database = app.database(); - const db3: Database = app.database(mocks.appOptions.databaseURL); - expect(db1).to.equal(db2); - expect(db1).to.equal(db3); - expect(db1.ref().toString()).to.equal('https://databasename.firebaseio.com/'); - }); - - it('should return a Database instance for the specified URL', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const db1: Database = app.database(); - const db2: Database = app.database('https://other-database.firebaseio.com'); - expect(db1.ref().toString()).to.equal('https://databasename.firebaseio.com/'); - expect(db2.ref().toString()).to.equal('https://other-database.firebaseio.com/'); - }); - - const invalidArgs = [null, NaN, 0, 1, true, false, '', [], [1, 'a'], {}, { a: 1 }, _.noop]; - invalidArgs.forEach((url) => { - it(`should throw given invalid URL argument: ${JSON.stringify(url)}`, () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - expect(() => { - (app as any).database(url); - }).to.throw('Database URL must be a valid, non-empty URL string.'); - }); - }); - - const invalidUrls = ['a', 'foo', 'google.com']; - invalidUrls.forEach((url) => { - it(`should throw given invalid URL string: '${url}'`, () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - expect(() => { - app.database(url); - }).to.throw('FIREBASE FATAL ERROR: Cannot parse Firebase url. ' + - 'Please use https://.firebaseio.com'); - }); - }); - }); - - describe('storage()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.storage(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the Storage namespace', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const gcsNamespace: Storage = app.storage(); - expect(gcsNamespace).not.be.null; - }); - - it('should return a cached version of Storage on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const serviceNamespace1: Storage = app.storage(); - const serviceNamespace2: Storage = app.storage(); - expect(serviceNamespace1).to.deep.equal(serviceNamespace2); - }); - }); - - describe('firestore()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.firestore(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the Firestore client', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const fs: Firestore = app.firestore(); - expect(fs).not.be.null; - }); - - it('should return a cached version of Firestore on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const service1: Firestore = app.firestore(); - const service2: Firestore = app.firestore(); - expect(service1).to.deep.equal(service2); - }); - }); - - describe('installations()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.installations(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the InstanceId client', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const fis: Installations = app.installations(); - expect(fis).not.be.null; - }); - - it('should return a cached version of InstanceId on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const service1: Installations = app.installations(); - const service2: Installations = app.installations(); - expect(service1).to.equal(service2); - }); - }); - - describe('instanceId()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.instanceId(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the InstanceId client', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const iid: InstanceId = app.instanceId(); - expect(iid).not.be.null; - }); - - it('should return a cached version of InstanceId on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const service1: InstanceId = app.instanceId(); - const service2: InstanceId = app.instanceId(); - expect(service1).to.equal(service2); - }); - }); - - describe('projectManagement()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.projectManagement(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the projectManagement client', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const projectManagement: ProjectManagement = app.projectManagement(); - expect(projectManagement).to.not.be.null; - }); - - it('should return a cached version of ProjectManagement on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const service1: ProjectManagement = app.projectManagement(); - const service2: ProjectManagement = app.projectManagement(); - expect(service1).to.equal(service2); - }); - }); - - describe('securityRules()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.securityRules(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the securityRules client', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const securityRules: SecurityRules = app.securityRules(); - expect(securityRules).to.not.be.null; - }); - - it('should return a cached version of SecurityRules on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const service1: SecurityRules = app.securityRules(); - const service2: SecurityRules = app.securityRules(); - expect(service1).to.equal(service2); - }); - }); - - describe('remoteConfig()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.remoteConfig(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the RemoteConfig client', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const remoteConfig: RemoteConfig = app.remoteConfig(); - expect(remoteConfig).to.not.be.null; - }); - - it('should return a cached version of RemoteConfig on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const service1: RemoteConfig = app.remoteConfig(); - const service2: RemoteConfig = app.remoteConfig(); - expect(service1).to.equal(service2); - }); - }); - - describe('appCheck()', () => { - it('should throw if the app has already been deleted', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - return app.delete().then(() => { - expect(() => { - return app.appCheck(); - }).to.throw(`Firebase app named "${mocks.appName}" has already been deleted.`); - }); - }); - - it('should return the AppCheck client', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - - const appCheck: AppCheck = app.appCheck(); - expect(appCheck).to.not.be.null; - }); - - it('should return a cached version of AppCheck on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - const service1: AppCheck = app.appCheck(); - const service2: AppCheck = app.appCheck(); - expect(service1).to.equal(service2); - }); - }); describe('INTERNAL.getToken()', () => { diff --git a/test/unit/app/firebase-namespace.spec.ts b/test/unit/app/firebase-namespace.spec.ts deleted file mode 100644 index 694c6f5ffe..0000000000 --- a/test/unit/app/firebase-namespace.spec.ts +++ /dev/null @@ -1,892 +0,0 @@ -/*! - * @license - * Copyright 2017 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -import http = require('http'); -import path = require('path'); - -import * as _ from 'lodash'; -import * as chai from 'chai'; -import * as sinonChai from 'sinon-chai'; -import * as chaiAsPromised from 'chai-as-promised'; - -import * as mocks from '../../resources/mocks'; - -import { FirebaseNamespace } from '../../../src/app/firebase-namespace'; -import { - enableLogging, - Database as DatabaseImpl, - DataSnapshot, - OnDisconnect, - Query, - Reference, - ServerValue, -} from '@firebase/database-compat/standalone'; - -import { - FieldPath, - FieldValue, - GeoPoint, - v1, - v1beta1, - setLogFunction, -} from '@google-cloud/firestore'; -import { getSdkVersion } from '../../../src/utils/index'; - -import { - app, auth, messaging, machineLearning, storage, firestore, database, - instanceId, installations, projectManagement, securityRules, remoteConfig, appCheck, -} from '../../../src/firebase-namespace-api'; -import { AppCheck as AppCheckImpl } from '../../../src/app-check/app-check'; -import { Auth as AuthImpl } from '../../../src/auth/auth'; -import { InstanceId as InstanceIdImpl } from '../../../src/instance-id/instance-id'; -import { Installations as InstallationsImpl } from '../../../src/installations/installations'; -import { MachineLearning as MachineLearningImpl } from '../../../src/machine-learning/machine-learning'; -import { Messaging as MessagingImpl } from '../../../src/messaging/messaging'; -import { ProjectManagement as ProjectManagementImpl } from '../../../src/project-management/project-management'; -import { RemoteConfig as RemoteConfigImpl } from '../../../src/remote-config/remote-config'; -import { SecurityRules as SecurityRulesImpl } from '../../../src/security-rules/security-rules'; -import { Storage as StorageImpl } from '../../../src/storage/storage'; - -import { clearGlobalAppDefaultCred } from '../../../src/app/credential-factory'; - -import App = app.App; -import AppCheck = appCheck.AppCheck; -import Auth = auth.Auth; -import Database = database.Database; -import Firestore = firestore.Firestore; -import Installations = installations.Installations; -import InstanceId = instanceId.InstanceId; -import MachineLearning = machineLearning.MachineLearning; -import Messaging = messaging.Messaging; -import ProjectManagement = projectManagement.ProjectManagement; -import RemoteConfig = remoteConfig.RemoteConfig; -import SecurityRules = securityRules.SecurityRules; -import Storage = storage.Storage; -import { ApplicationDefaultCredential } from '../../../src/app/credential-internal'; - -chai.should(); -chai.use(sinonChai); -chai.use(chaiAsPromised); - -const expect = chai.expect; - - -const DEFAULT_APP_NAME = '[DEFAULT]'; -const DEFAULT_APP_NOT_FOUND = 'The default Firebase app does not exist. Make sure you call initializeApp() ' - + 'before using any of the Firebase services.'; -const INITIALIZE_APP_CREDENTIAL_EXISTANCE_MISMATCH = 'An existing app named "mock-app-name" already ' - + 'exists with a different options configuration: Credential'; -const INITIALIZE_APP_HTTP_AGENT_EXISTANCE_MISMATCH = 'An existing app named "mock-app-name" already ' - + 'exists with a different options configuration: httpAgent'; -const INITIALIZE_APP_NOT_IDEMPOTENT_CREDENTIAL = 'Firebase app named "mock-app-name" already exists and ' - + 'initializeApp was invoked with an optional Credential. The SDK cannot confirm the equality ' - + 'of Credential objects with the existing app. Please use getApp or getApps to reuse the ' - + 'existing app instead.' -const INITIALIZE_APP_NOT_IDEMPOTENT_HTTP_AGENT = 'Firebase app named "mock-app-name" already exists and ' - + 'initializeApp was invoked with an optional http.Agent. The SDK cannot confirm the equality ' - + 'of http.Agent objects with the existing app. Please use getApp or getApps to reuse the ' - + 'existing app instead.' - - - -describe('FirebaseNamespace', () => { - let firebaseNamespace: FirebaseNamespace; - - beforeEach(() => { - firebaseNamespace = new FirebaseNamespace(); - }); - - describe('#SDK_VERSION', () => { - it('should return the SDK version', () => { - expect(firebaseNamespace.SDK_VERSION).to.equal(getSdkVersion()); - }); - }); - - describe('#apps', () => { - it('should return an empty array if there are no apps within this namespace', () => { - expect(firebaseNamespace.apps).to.deep.equal([]); - }); - - it('should return an array of apps within this namespace', () => { - const appNames = ['one', 'two', 'three']; - const apps = appNames.map((appName) => { - return firebaseNamespace.initializeApp(mocks.appOptions, appName); - }); - - expect(firebaseNamespace.apps).to.have.length(apps.length); - expect(firebaseNamespace.apps).to.deep.equal(apps); - }); - - it('should not include apps which have been deleted', () => { - const appNames = ['one', 'two', 'three']; - const apps = appNames.map((appName) => { - return firebaseNamespace.initializeApp(mocks.appOptions, appName); - }); - - return apps[0].delete().then(() => { - apps.shift(); - expect(firebaseNamespace.apps).to.have.length(apps.length); - expect(firebaseNamespace.apps).to.deep.equal(apps); - }); - }); - - it('should be read-only', () => { - expect(() => { - (firebaseNamespace as any).apps = 'foo'; - }).to.throw('Cannot set property apps of # which has only a getter'); - }); - }); - - describe('#app()', () => { - const invalidAppNames = [null, NaN, 0, 1, true, false, [], ['a'], {}, { a: 1 }, _.noop]; - invalidAppNames.forEach((invalidAppName) => { - it('should throw given non-string app name: ' + JSON.stringify(invalidAppName), () => { - expect(() => { - return firebaseNamespace.app(invalidAppName as any); - }).to.throw(`Invalid Firebase app name "${invalidAppName}" provided. App name must be a non-empty string.`); - }); - }); - - it('should throw given empty string app name', () => { - expect(() => { - return firebaseNamespace.app(''); - }).to.throw('Invalid Firebase app name "" provided. App name must be a non-empty string.'); - }); - - it('should throw given an app name which does not correspond to an existing app', () => { - expect(() => { - return firebaseNamespace.app(mocks.appName); - }).to.throw(`Firebase app named "${mocks.appName}" does not exist.`); - }); - - it('should throw given a deleted app', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - return app.delete().then(() => { - expect(() => { - return firebaseNamespace.app(mocks.appName); - }).to.throw(`Firebase app named "${mocks.appName}" does not exist.`); - }); - }); - - it('should throw given no app name if the default app does not exist', () => { - expect(() => { - return firebaseNamespace.app(); - }).to.throw('The default Firebase app does not exist.'); - }); - - it('should return the app associated with the provided app name', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - expect(firebaseNamespace.app(mocks.appName)).to.deep.equal(app); - }); - - it('should return the default app if no app name is provided', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions); - expect(firebaseNamespace.app()).to.deep.equal(app); - }); - - it('should return the default app if the default app name is provided', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions); - expect(firebaseNamespace.app(DEFAULT_APP_NAME)).to.deep.equal(app); - }); - }); - - describe('#initializeApp()', () => { - const invalidAppNames = [null, NaN, 0, 1, true, false, [], ['a'], {}, { a: 1 }, _.noop]; - invalidAppNames.forEach((invalidAppName) => { - it('should throw given non-string app name: ' + JSON.stringify(invalidAppName), () => { - expect(() => { - firebaseNamespace.initializeApp(mocks.appOptions, invalidAppName as any); - }).to.throw(`Invalid Firebase app name "${invalidAppName}" provided. App name must be a non-empty string.`); - }); - }); - - it('should throw given empty string app name', () => { - expect(() => { - firebaseNamespace.initializeApp(mocks.appOptions, ''); - }).to.throw('Invalid Firebase app name "" provided. App name must be a non-empty string.'); - }); - - it('should not throw given a name corresponding to an existing app', () => { - let app1: App | undefined; - let app2: App | undefined; - expect(() => { - app1 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); - app2 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); - }).to.not.throw(); - expect(app1).to.equal(app2); - }); - - it('should not throw given no app name if the default app already exists', () => { - let app1: App | undefined; - let app2: App | undefined; - expect(() => { - app1 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential); - app2 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential); - }).to.not.throw(); - expect(app1).to.equal(app2); - }); - - it('should throw due to the Credential option being not supported by idemopotency', () => { - let app1: App | undefined; - let app2: App | undefined; - expect(() => { - app1 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - app2 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - }).to.throw(INITIALIZE_APP_NOT_IDEMPOTENT_CREDENTIAL); - expect(app1).to.not.be.undefined; - expect(app2).to.be.undefined; - }); - - it('should throw due to idempotency check on Credential option on second app.', () => { - let app1: App | undefined; - let app2: App | undefined; - expect(() => { - app1 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - app2 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); - }).to.throw(INITIALIZE_APP_CREDENTIAL_EXISTANCE_MISMATCH); - expect(app1).to.not.be.undefined; - expect(app2).to.be.undefined; - }); - - it('should throw due to the httpAgent option being not supported by idemopotency', () => { - let app1: App | undefined; - let app2: App | undefined; - const httpAgent = new http.Agent(); - const appOptions = { - ...mocks.appOptionsWithoutCredential, - httpAgent - } - expect(() => { - app1 = firebaseNamespace.initializeApp(appOptions, mocks.appName); - app2 = firebaseNamespace.initializeApp(appOptions, mocks.appName); - }).to.throw(INITIALIZE_APP_NOT_IDEMPOTENT_HTTP_AGENT); - expect(app1).to.not.be.undefined; - expect(app2).to.be.undefined; - }); - - it('should throw due to idempotency check on httpAgent option on second app.', () => { - let app1: App | undefined; - let app2: App | undefined; - const httpAgent = new http.Agent(); - const appOptions = { - ...mocks.appOptionsWithoutCredential, - httpAgent - } - expect(() => { - app1 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); - app2 = firebaseNamespace.initializeApp(appOptions, mocks.appName); - }).to.throw(INITIALIZE_APP_NOT_IDEMPOTENT_HTTP_AGENT); - expect(app1).to.not.be.undefined; - expect(app2).to.be.undefined; - }); - - it('should throw due to idempotency check on httpAgent option on first app but not second app.', () => { - let app1: App | undefined; - let app2: App | undefined; - const httpAgent = new http.Agent(); - const appOptions = { - ...mocks.appOptionsWithoutCredential, - httpAgent - } - expect(() => { - app1 = firebaseNamespace.initializeApp(appOptions, mocks.appName); - app2 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); - }).to.throw(INITIALIZE_APP_HTTP_AGENT_EXISTANCE_MISMATCH); - expect(app1).to.not.be.undefined; - expect(app2).to.be.undefined; - }); - - it('should return a new app with the provided options and app name', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - expect(app.name).to.equal(mocks.appName); - expect(app.options).to.deep.equal(mocks.appOptions); - }); - - it('should return an app with the default app name if no app name is provided', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions); - expect(app.name).to.deep.equal(DEFAULT_APP_NAME); - }); - - it('should allow re-use of a deleted app name', () => { - const app1 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - let app2: App | undefined; - return app1.delete().then(() => { - app2 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - expect(firebaseNamespace.app(mocks.appName)).to.deep.equal(app2); - expect(app2).to.not.equal(app1); - }); - }); - - it('should add the new app to the namespace\'s app list', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); - expect(firebaseNamespace.app(mocks.appName)).to.deep.equal(app); - }); - }); - - describe('#auth()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.auth(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.auth(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const auth: Auth = firebaseNamespace.auth(); - expect(auth.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const auth: Auth = firebaseNamespace.auth(app); - expect(auth.app).to.be.deep.equal(app); - }); - - it('should return a reference to Auth type', () => { - expect(firebaseNamespace.auth.Auth).to.be.deep.equal(AuthImpl); - }); - - it('should return a cached version of Auth on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const serviceNamespace1: Auth = firebaseNamespace.auth(); - const serviceNamespace2: Auth = firebaseNamespace.auth(); - expect(serviceNamespace1).to.equal(serviceNamespace2); - }); - }); - - describe('#database()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.database(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.database(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const db: Database = firebaseNamespace.database(); - expect(db.app).to.be.deep.equal(app); - return app.delete(); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const db: Database = firebaseNamespace.database(app); - expect(db.app).to.be.deep.equal(app); - return app.delete(); - }); - - it('should return a reference to Database type', () => { - expect(firebaseNamespace.database.Database).to.be.deep.equal(DatabaseImpl); - }); - - it('should return a reference to DataSnapshot type', () => { - expect(firebaseNamespace.database.DataSnapshot).to.be.deep.equal(DataSnapshot); - }); - - it('should return a reference to OnDisconnect type', () => { - expect(firebaseNamespace.database.OnDisconnect).to.be.deep.equal(OnDisconnect); - }); - - it('should return a reference to Query type', () => { - expect(firebaseNamespace.database.Query).to.be.deep.equal(Query); - }); - - it('should return a reference to Reference type', () => { - expect(firebaseNamespace.database.Reference).to.be.deep.equal(Reference); - }); - - it('should return a reference to ServerValue type', () => { - expect(firebaseNamespace.database.ServerValue).to.be.deep.equal(ServerValue); - }); - - it('should return a reference to enableLogging function', () => { - expect(firebaseNamespace.database.enableLogging).to.be.deep.equal(enableLogging); - }); - - it('should return a cached version of Database on subsequent calls', () => { - const app = firebaseNamespace.initializeApp(mocks.appOptions); - const db1: Database = firebaseNamespace.database(); - const db2: Database = firebaseNamespace.database(); - expect(db1).to.equal(db2); - return app.delete(); - }); - }); - - describe('#messaging()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.messaging(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.messaging(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const fcm: Messaging = firebaseNamespace.messaging(); - expect(fcm.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const fcm: Messaging = firebaseNamespace.messaging(app); - expect(fcm.app).to.be.deep.equal(app); - }); - - it('should return a reference to Messaging type', () => { - expect(firebaseNamespace.messaging.Messaging).to.be.deep.equal(MessagingImpl); - }); - - it('should return a cached version of Messaging on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const serviceNamespace1: Messaging = firebaseNamespace.messaging(); - const serviceNamespace2: Messaging = firebaseNamespace.messaging(); - expect(serviceNamespace1).to.equal(serviceNamespace2); - }); - }); - - describe('#machineLearning()', () => { - it('should throw when called before initializating an app', () => { - expect(() => { - firebaseNamespace.machineLearning(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.machineLearning(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const ml: MachineLearning = firebaseNamespace.machineLearning(); - expect(ml.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const ml: MachineLearning = firebaseNamespace.machineLearning(app); - expect(ml.app).to.be.deep.equal(app); - }); - - it('should return a reference to Machine Learning type', () => { - expect(firebaseNamespace.machineLearning.MachineLearning) - .to.be.deep.equal(MachineLearningImpl); - }); - - it('should return a cached version of MachineLearning on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const service1: MachineLearning = firebaseNamespace.machineLearning(); - const service2: MachineLearning = firebaseNamespace.machineLearning(); - expect(service1).to.equal(service2); - }); - }); - - describe('#storage()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.storage(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.storage(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const gcs: Storage = firebaseNamespace.storage(); - expect(gcs.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const gcs: Storage = firebaseNamespace.storage(app); - expect(gcs.app).to.be.deep.equal(app); - }); - - it('should return a reference to Storage type', () => { - expect(firebaseNamespace.storage.Storage).to.be.deep.equal(StorageImpl); - }); - - it('should return a cached version of Storage on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const serviceNamespace1: Storage = firebaseNamespace.storage(); - const serviceNamespace2: Storage = firebaseNamespace.storage(); - expect(serviceNamespace1).to.equal(serviceNamespace2); - }); - }); - - describe('#firestore()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.firestore(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.firestore(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const fs: Firestore = firebaseNamespace.firestore(); - expect(fs).to.not.be.null; - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const fs: Firestore = firebaseNamespace.firestore(app); - expect(fs).to.not.be.null; - }); - - it('should return a reference to Firestore type', () => { - expect(firebaseNamespace.firestore.Firestore).to.be.deep.equal(Firestore); - }); - - it('should return a reference to FieldPath type', () => { - expect(firebaseNamespace.firestore.FieldPath).to.be.deep.equal(FieldPath); - }); - - it('should return a reference to FieldValue type', () => { - expect(firebaseNamespace.firestore.FieldValue).to.be.deep.equal(FieldValue); - }); - - it('should return a reference to GeoPoint type', () => { - expect(firebaseNamespace.firestore.GeoPoint).to.be.deep.equal(GeoPoint); - }); - - it('should return a reference to setLogFunction', () => { - expect(firebaseNamespace.firestore.setLogFunction).to.be.deep.equal(setLogFunction); - }); - - it('should return a reference to the v1beta1 namespace', () => { - expect(firebaseNamespace.firestore.v1beta1).to.be.deep.equal(v1beta1); - }); - - it('should return a reference to the v1 namespace', () => { - expect(firebaseNamespace.firestore.v1).to.be.deep.equal(v1); - }); - - it('should return a cached version of Firestore on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const service1: Firestore = firebaseNamespace.firestore(); - const service2: Firestore = firebaseNamespace.firestore(); - expect(service1).to.equal(service2); - }); - }); - - describe('#installations()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.installations(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.installations(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const fis: Installations = firebaseNamespace.installations(); - expect(fis).to.not.be.null; - expect(fis.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const fis: Installations = firebaseNamespace.installations(app); - expect(fis).to.not.be.null; - expect(fis.app).to.be.deep.equal(app); - }); - - it('should return a reference to Installations type', () => { - expect(firebaseNamespace.installations.Installations).to.be.deep.equal(InstallationsImpl); - }); - - it('should return a cached version of Installations on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const service1: Installations = firebaseNamespace.installations(); - const service2: Installations = firebaseNamespace.installations(); - expect(service1).to.equal(service2); - }); - }); - - describe('#instanceId()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.instanceId(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.instanceId(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const iid: InstanceId = firebaseNamespace.instanceId(); - expect(iid).to.not.be.null; - expect(iid.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const iid: InstanceId = firebaseNamespace.instanceId(app); - expect(iid).to.not.be.null; - expect(iid.app).to.be.deep.equal(app); - }); - - it('should return a reference to InstanceId type', () => { - expect(firebaseNamespace.instanceId.InstanceId).to.be.deep.equal(InstanceIdImpl); - }); - - it('should return a cached version of InstanceId on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const service1: InstanceId = firebaseNamespace.instanceId(); - const service2: InstanceId = firebaseNamespace.instanceId(); - expect(service1).to.equal(service2); - }); - }); - - describe('#projectManagement()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.projectManagement(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.projectManagement(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const projectManagement: ProjectManagement = firebaseNamespace.projectManagement(); - expect(projectManagement).to.not.be.null; - expect(projectManagement.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const projectManagement: ProjectManagement = firebaseNamespace.projectManagement(app); - expect(projectManagement).to.not.be.null; - expect(projectManagement.app).to.be.deep.equal(app); - }); - - it('should return a reference to ProjectManagement type', () => { - expect(firebaseNamespace.projectManagement.ProjectManagement) - .to.be.deep.equal(ProjectManagementImpl); - }); - - it('should return a cached version of ProjectManagement on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const service1: ProjectManagement = firebaseNamespace.projectManagement(); - const service2: ProjectManagement = firebaseNamespace.projectManagement(); - expect(service1).to.equal(service2); - }); - }); - - describe('#securityRules()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.securityRules(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.securityRules(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const securityRules: SecurityRules = firebaseNamespace.securityRules(); - expect(securityRules).to.not.be.null; - expect(securityRules.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const securityRules: SecurityRules = firebaseNamespace.securityRules(app); - expect(securityRules).to.not.be.null; - expect(securityRules.app).to.be.deep.equal(app); - }); - - it('should return a reference to SecurityRules type', () => { - expect(firebaseNamespace.securityRules.SecurityRules) - .to.be.deep.equal(SecurityRulesImpl); - }); - - it('should return a cached version of SecurityRules on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const service1: SecurityRules = firebaseNamespace.securityRules(); - const service2: SecurityRules = firebaseNamespace.securityRules(); - expect(service1).to.equal(service2); - }); - }); - - describe('#remoteConfig()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.remoteConfig(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.remoteConfig(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const rc: RemoteConfig = firebaseNamespace.remoteConfig(); - expect(rc.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const rc: RemoteConfig = firebaseNamespace.remoteConfig(app); - expect(rc.app).to.be.deep.equal(app); - }); - - it('should return a reference to RemoteConfig type', () => { - expect(firebaseNamespace.remoteConfig.RemoteConfig).to.be.deep.equal(RemoteConfigImpl); - }); - - it('should return a cached version of RemoteConfig on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const service1: RemoteConfig = firebaseNamespace.remoteConfig(); - const service2: RemoteConfig = firebaseNamespace.remoteConfig(); - expect(service1).to.equal(service2); - }); - }); - - describe('credentials', () => { - it('should create a service account credential from object', () => { - const mockCertificateObject = mocks.certificateObject; - const credential = firebaseNamespace.credential.cert(mockCertificateObject); - expect(credential).to.deep.include({ - projectId: mockCertificateObject.project_id, - clientEmail: mockCertificateObject.client_email, - privateKey: mockCertificateObject.private_key, - implicit: false, - }); - }); - - it('should create a refresh token credential from object', () => { - const mockRefreshToken = mocks.refreshToken; - const credential = firebaseNamespace.credential.refreshToken(mockRefreshToken); - expect(credential).to.deep.include({ - implicit: false, - }); - }); - - it('should create application default credentials from environment', async () => { - process.env.GOOGLE_APPLICATION_CREDENTIALS = path.resolve(__dirname, '../../resources/mock.key.json'); - const mockCertificateObject = mocks.certificateObject; - const credential = firebaseNamespace.credential.applicationDefault(); - const projectId = await (credential as ApplicationDefaultCredential).getProjectId(); - const clientEmail = await (credential as ApplicationDefaultCredential).getServiceAccountEmail(); - expect(projectId).to.eq(mockCertificateObject.project_id); - expect(clientEmail).to.eq(mockCertificateObject.client_email); - }); - - after(clearGlobalAppDefaultCred); - }); - - describe('#appCheck()', () => { - it('should throw when called before initializing an app', () => { - expect(() => { - firebaseNamespace.appCheck(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should throw when default app is not initialized', () => { - firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - expect(() => { - firebaseNamespace.appCheck(); - }).to.throw(DEFAULT_APP_NOT_FOUND); - }); - - it('should return a valid namespace when the default app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions); - const fac: AppCheck = firebaseNamespace.appCheck(); - expect(fac.app).to.be.deep.equal(app); - }); - - it('should return a valid namespace when the named app is initialized', () => { - const app: App = firebaseNamespace.initializeApp(mocks.appOptions, 'testApp'); - const fac: AppCheck = firebaseNamespace.appCheck(app); - expect(fac.app).to.be.deep.equal(app); - }); - - it('should return a reference to AppCheck type', () => { - expect(firebaseNamespace.appCheck.AppCheck).to.be.deep.equal(AppCheckImpl); - }); - - it('should return a cached version of AppCheck on subsequent calls', () => { - firebaseNamespace.initializeApp(mocks.appOptions); - const service1: AppCheck = firebaseNamespace.appCheck(); - const service2: AppCheck = firebaseNamespace.appCheck(); - expect(service1).to.equal(service2); - }); - }); -}); diff --git a/test/unit/firebase.spec.ts b/test/unit/firebase.spec.ts deleted file mode 100644 index 815fb1a5db..0000000000 --- a/test/unit/firebase.spec.ts +++ /dev/null @@ -1,289 +0,0 @@ -/*! - * @license - * Copyright 2017 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -// Use untyped import syntax for Node built-ins -import * as path from 'path'; - -import * as _ from 'lodash'; -import * as sinon from 'sinon'; -import * as chai from 'chai'; -import * as chaiAsPromised from 'chai-as-promised'; - -import * as mocks from '../resources/mocks'; - -import * as firebaseAdmin from '../../src/index'; -import { FirebaseApp, FirebaseAppInternals } from '../../src/app/firebase-app'; -import { - ApplicationDefaultCredential, - RefreshTokenCredential, ServiceAccountCredential, isApplicationDefault -} from '../../src/app/credential-internal'; -import { defaultAppStore, initializeApp } from '../../src/app/lifecycle'; - -chai.should(); -chai.use(chaiAsPromised); - -const expect = chai.expect; - - -describe('Firebase', () => { - let getTokenStub: sinon.SinonStub; - - before(() => { - getTokenStub = sinon.stub(ServiceAccountCredential.prototype, 'getAccessToken').resolves({ - access_token: 'mock-access-token', - expires_in: 3600, - }); - }); - - after(() => { - getTokenStub.restore(); - }); - - afterEach(() => { - return defaultAppStore.clearAllApps(); - }); - - describe('#initializeApp()', () => { - const invalidOptions: any[] = [null, NaN, 0, 1, true, false, '', 'a', [], _.noop]; - invalidOptions.forEach((invalidOption: any) => { - it('should throw given invalid options object: ' + JSON.stringify(invalidOption), () => { - expect(() => { - firebaseAdmin.initializeApp(invalidOption); - }).to.throw('Invalid Firebase app options'); - }); - }); - - it('should use application default credentials when no credentials are explicitly specified', () => { - const app = firebaseAdmin.initializeApp(mocks.appOptionsNoAuth); - expect(app.options).to.have.property('credential'); - expect(app.options.credential).to.not.be.undefined; - }); - - it('should not modify the provided options object', () => { - const optionsClone = _.clone(mocks.appOptions); - firebaseAdmin.initializeApp(mocks.appOptions); - expect(optionsClone).to.deep.equal(mocks.appOptions); - }); - - const invalidCredentials = [undefined, null, NaN, 0, 1, '', 'a', true, false, '', _.noop]; - invalidCredentials.forEach((invalidCredential) => { - it('should throw given non-object credential: ' + JSON.stringify(invalidCredential), () => { - expect(() => { - firebaseAdmin.initializeApp({ - credential: invalidCredential as any, - }); - }).to.throw('Invalid Firebase app options'); - }); - }); - - it('should throw given a credential which doesn\'t implement the Credential interface', () => { - expect(() => { - firebaseAdmin.initializeApp({ - credential: {}, - } as any); - }).to.throw('Invalid Firebase app options'); - - expect(() => { - firebaseAdmin.initializeApp({ - credential: { - getAccessToken: true, - }, - } as any); - }).to.throw('Invalid Firebase app options'); - }); - - it('should initialize SDK given a cert credential with a certificate object', () => { - firebaseAdmin.initializeApp({ - credential: firebaseAdmin.credential.cert(mocks.certificateObject), - }); - - expect(isApplicationDefault(firebaseAdmin.app().options.credential)).to.be.false; - return getAppInternals().getToken() - .should.eventually.have.keys(['accessToken', 'expirationTime']); - }); - - it('should initialize SDK given a cert credential with a valid path to a certificate key file', () => { - const keyPath = path.resolve(__dirname, '../resources/mock.key.json'); - firebaseAdmin.initializeApp({ - credential: firebaseAdmin.credential.cert(keyPath), - }); - - expect(isApplicationDefault(firebaseAdmin.app().options.credential)).to.be.false; - return getAppInternals().getToken() - .should.eventually.have.keys(['accessToken', 'expirationTime']); - }); - - it('should initialize SDK given an application default credential', () => { - getTokenStub.restore(); - getTokenStub = sinon.stub(ApplicationDefaultCredential.prototype, 'getAccessToken').resolves({ - access_token: 'mock-access-token', - expires_in: 3600, - }); - const credPath: string | undefined = process.env.GOOGLE_APPLICATION_CREDENTIALS; - process.env.GOOGLE_APPLICATION_CREDENTIALS = path.resolve(__dirname, '../resources/mock.key.json'); - firebaseAdmin.initializeApp({ - credential: firebaseAdmin.credential.applicationDefault(), - }); - expect(isApplicationDefault(firebaseAdmin.app().options.credential)).to.be.true; - return getAppInternals().getToken().then((token) => { - if (typeof credPath === 'undefined') { - delete process.env.GOOGLE_APPLICATION_CREDENTIALS; - } else { - process.env.GOOGLE_APPLICATION_CREDENTIALS = credPath; - } - return token; - }).should.eventually.have.keys(['accessToken', 'expirationTime']); - }); - - it('should initialize SDK given a refresh token credential', () => { - getTokenStub.restore(); - getTokenStub = sinon.stub(RefreshTokenCredential.prototype, 'getAccessToken') - .resolves({ - access_token: 'mock-access-token', - expires_in: 3600, - }); - firebaseAdmin.initializeApp({ - credential: firebaseAdmin.credential.refreshToken(mocks.refreshToken), - }); - - expect(isApplicationDefault(firebaseAdmin.app().options.credential)).to.be.false; - return getAppInternals().getToken() - .should.eventually.have.keys(['accessToken', 'expirationTime']); - }); - - it('should initialize App instance with extended service methods', () => { - const app = firebaseAdmin.initializeApp(mocks.appOptions); - expect((app as any).__extended).to.be.true; - expect(app.auth).to.be.not.undefined; - }); - - it('should add extended service methods when retrieved via namespace', () => { - const app = initializeApp(mocks.appOptions); - expect((app as any).__extended).to.be.undefined; - expect((app as any).auth).to.be.undefined; - - const extendedApp = firebaseAdmin.app(); - expect(app).to.equal(extendedApp); - expect((app as any).__extended).to.be.true; - expect((app as any).auth).to.be.not.undefined; - }); - }); - - describe('#database()', () => { - it('should throw if the app has not be initialized', () => { - expect(() => { - return firebaseAdmin.database(); - }).to.throw('The default Firebase app does not exist.'); - }); - - it('should throw given no databaseURL key when initializing the app', () => { - firebaseAdmin.initializeApp(mocks.appOptionsNoDatabaseUrl); - - expect(() => { - firebaseAdmin.database(); - }).to.throw('Can\'t determine Firebase Database URL'); - }); - - it('should return the database service', () => { - firebaseAdmin.initializeApp(mocks.appOptions); - expect(() => { - return firebaseAdmin.database(); - }).not.to.throw(); - }); - }); - - describe('#auth', () => { - it('should throw if the app has not be initialized', () => { - expect(() => { - return firebaseAdmin.auth(); - }).to.throw('The default Firebase app does not exist.'); - }); - - it('should return the auth service', () => { - firebaseAdmin.initializeApp(mocks.appOptions); - expect(() => { - return firebaseAdmin.auth(); - }).not.to.throw(); - }); - }); - - describe('#messaging', () => { - it('should throw if the app has not be initialized', () => { - expect(() => { - return firebaseAdmin.messaging(); - }).to.throw('The default Firebase app does not exist.'); - }); - - it('should return the messaging service', () => { - firebaseAdmin.initializeApp(mocks.appOptions); - expect(() => { - return firebaseAdmin.messaging(); - }).not.to.throw(); - }); - }); - - describe('#remoteConfig', () => { - it('should throw if the app has not be initialized', () => { - expect(() => { - return firebaseAdmin.remoteConfig(); - }).to.throw('The default Firebase app does not exist.'); - }); - - it('should return the remoteConfig service', () => { - firebaseAdmin.initializeApp(mocks.appOptions); - expect(() => { - return firebaseAdmin.remoteConfig(); - }).not.to.throw(); - }); - }); - - describe('#appCheck', () => { - it('should throw if the app has not been initialized', () => { - expect(() => { - return firebaseAdmin.appCheck(); - }).to.throw('The default Firebase app does not exist.'); - }); - - it('should return the appCheck service', () => { - firebaseAdmin.initializeApp(mocks.appOptions); - expect(() => { - return firebaseAdmin.appCheck(); - }).not.to.throw(); - }); - }); - - describe('#storage', () => { - it('should throw if the app has not be initialized', () => { - expect(() => { - return firebaseAdmin.storage(); - }).to.throw('The default Firebase app does not exist.'); - }); - - it('should return the storage service', () => { - firebaseAdmin.initializeApp(mocks.appOptions); - expect(() => { - return firebaseAdmin.storage(); - }).not.to.throw(); - }); - }); - - function getAppInternals(): FirebaseAppInternals { - return (firebaseAdmin.app() as unknown as FirebaseApp).INTERNAL; - } -}); diff --git a/test/unit/index.spec.ts b/test/unit/index.spec.ts index 9f2fecc1a1..e863064ad1 100644 --- a/test/unit/index.spec.ts +++ b/test/unit/index.spec.ts @@ -16,11 +16,9 @@ */ // General -import './firebase.spec'; import './app/credential-internal.spec'; import './app/index.spec'; import './app/firebase-app.spec'; -import './app/firebase-namespace.spec'; // Utilities import './utils/index.spec'; diff --git a/test/unit/utils.ts b/test/unit/utils.ts index 033015b96b..e88e9b7a36 100644 --- a/test/unit/utils.ts +++ b/test/unit/utils.ts @@ -18,7 +18,7 @@ import * as _ from 'lodash'; import * as sinon from 'sinon'; import * as mocks from '../resources/mocks'; -import { AppOptions } from '../../src/firebase-namespace-api'; +import { AppOptions } from '../../src/app/index'; import { FirebaseApp, FirebaseAppInternals, FirebaseAccessToken } from '../../src/app/firebase-app'; import { RequestResponseError, RequestResponse } from '../../src/utils/api-request'; diff --git a/tsconfig.json b/tsconfig.json index 1b21a0e365..769b09c228 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,5 +20,10 @@ }, "files": [ "src/index.ts" - ] + ], + "ts-node": { + "moduleTypes": { + "**/*.ts": "cjs" + } + } } From ffd37fe7a16cfb07fd58cedf1002742687aa4cdd Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Wed, 27 May 2026 12:39:34 -0400 Subject: [PATCH 2/3] test(integration): migrate app-check integration tests to modular API --- test/integration/app-check.spec.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/integration/app-check.spec.ts b/test/integration/app-check.spec.ts index 463dd027c8..e335bacc8b 100644 --- a/test/integration/app-check.spec.ts +++ b/test/integration/app-check.spec.ts @@ -15,7 +15,7 @@ */ import * as _ from 'lodash'; -import * as admin from '../../lib/index'; +import { getAppCheck, AppCheckToken } from '../../lib/app-check/index'; import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import fs = require('fs'); @@ -47,7 +47,7 @@ describe('admin.appCheck', () => { if (!appId) { this.skip(); } - return admin.appCheck().createToken(appId as string) + return getAppCheck().createToken(appId as string) .then((token) => { expect(token).to.have.keys(['token', 'ttlMillis']); expect(token.token).to.be.a('string').and.to.not.be.empty; @@ -60,7 +60,7 @@ describe('admin.appCheck', () => { if (!appId) { this.skip(); } - return admin.appCheck().createToken(appId as string, { limitedUse: true }) + return getAppCheck().createToken(appId as string, { limitedUse: true }) .then((token) => { expect(token).to.have.keys(['token', 'ttlMillis']); expect(token.token).to.be.a('string').and.to.not.be.empty; @@ -73,7 +73,7 @@ describe('admin.appCheck', () => { if (!appId) { this.skip(); } - return admin.appCheck().createToken(appId as string, { ttlMillis: 1800000 }) + return getAppCheck().createToken(appId as string, { ttlMillis: 1800000 }) .then((token) => { expect(token).to.have.keys(['token', 'ttlMillis']); expect(token.token).to.be.a('string').and.to.not.be.empty; @@ -84,35 +84,35 @@ describe('admin.appCheck', () => { it('should propagate API errors', () => { // rejects with invalid-argument when appId is incorrect - return admin.appCheck().createToken('incorrect-app-id') + return getAppCheck().createToken('incorrect-app-id') .should.eventually.be.rejected.and.have.property('code', 'app-check/invalid-argument'); }); const invalidAppIds = ['', null, NaN, 0, 1, true, false, [], {}, { a: 1 }, _.noop]; invalidAppIds.forEach((invalidAppId) => { it(`should throw given an invalid appId: ${JSON.stringify(invalidAppId)}`, () => { - expect(() => admin.appCheck().createToken(invalidAppId as any)) + expect(() => getAppCheck().createToken(invalidAppId as any)) .to.throw('appId` must be a non-empty string.'); }); }); }); describe('verifyToken', () => { - let validToken: admin.appCheck.AppCheckToken; + let validToken: AppCheckToken; before(async () => { if (!appId) { return; } // obtain a valid app check token - validToken = await admin.appCheck().createToken(appId as string); + validToken = await getAppCheck().createToken(appId as string); }); it('should succeed with a decoded verifed token response', function() { if (!appId) { this.skip(); } - return admin.appCheck().verifyToken(validToken.token) + return getAppCheck().verifyToken(validToken.token) .then((verifedToken) => { expect(verifedToken).to.have.keys(['token', 'appId']); expect(verifedToken.token).to.include.keys(['iss', 'sub', 'aud', 'exp', 'iat', 'app_id']); @@ -122,8 +122,9 @@ describe('admin.appCheck', () => { it('should propagate API errors', () => { // rejects with invalid-argument when the token is invalid - return admin.appCheck().verifyToken('invalid-token') + return getAppCheck().verifyToken('invalid-token') .should.eventually.be.rejected.and.have.property('code', 'app-check/invalid-argument'); }); }); }); + From f0b9743301d768a6ccf081eefc6d9d80a0e5317c Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Wed, 27 May 2026 12:48:03 -0400 Subject: [PATCH 3/3] fix api-extractor --- etc/firebase-admin.api.md | 482 +++----------------------------------- 1 file changed, 39 insertions(+), 443 deletions(-) diff --git a/etc/firebase-admin.api.md b/etc/firebase-admin.api.md index 3c2ace43c1..be3f34c209 100644 --- a/etc/firebase-admin.api.md +++ b/etc/firebase-admin.api.md @@ -5,68 +5,36 @@ ```ts import { Agent } from 'http'; -import { Bucket } from '@google-cloud/storage'; -import { FirebaseDatabase } from '@firebase/database-types'; -import * as _firestore from '@google-cloud/firestore'; -import * as rtdb from '@firebase/database-types'; -// @public (undocumented) -export function app(name?: string): app.App; - -// @public (undocumented) -export namespace app { - // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point default-namespace.d.ts - export interface App extends App { - // (undocumented) - appCheck(): appCheck.AppCheck; - // (undocumented) - auth(): auth.Auth; - // (undocumented) - database(url?: string): database.Database; - delete(): Promise; - // (undocumented) - firestore(): firestore.Firestore; - // (undocumented) - installations(): installations.Installations; - // @deprecated (undocumented) - instanceId(): instanceId.InstanceId; - // (undocumented) - machineLearning(): machineLearning.MachineLearning; - // (undocumented) - messaging(): messaging.Messaging; - // (undocumented) - projectManagement(): projectManagement.ProjectManagement; - // (undocumented) - remoteConfig(): remoteConfig.RemoteConfig; - // (undocumented) - securityRules(): securityRules.SecurityRules; - // (undocumented) - storage(): storage.Storage; - } +// @public +export interface App { + name: string; + options: AppOptions; } // @public -export function appCheck(app?: App): appCheck.AppCheck; +export const AppErrorCode: { + readonly APP_DELETED: "app-deleted"; + readonly DUPLICATE_APP: "duplicate-app"; + readonly INVALID_ARGUMENT: "invalid-argument"; + readonly INTERNAL_ERROR: "internal-error"; + readonly INVALID_APP_NAME: "invalid-app-name"; + readonly INVALID_APP_OPTIONS: "invalid-app-options"; + readonly INVALID_CREDENTIAL: "invalid-credential"; + readonly NETWORK_ERROR: "network-error"; + readonly NETWORK_TIMEOUT: "network-timeout"; + readonly NO_APP: "no-app"; + readonly UNABLE_TO_PARSE_RESPONSE: "unable-to-parse-response"; +}; -// @public (undocumented) -export namespace appCheck { - // Warning: (ae-forgotten-export) The symbol "AppCheck" needs to be exported by the entry point default-namespace.d.ts - export type AppCheck = AppCheck; - // Warning: (ae-forgotten-export) The symbol "AppCheckToken" needs to be exported by the entry point default-namespace.d.ts - export type AppCheckToken = AppCheckToken; - // Warning: (ae-forgotten-export) The symbol "AppCheckTokenOptions" needs to be exported by the entry point default-namespace.d.ts - export type AppCheckTokenOptions = AppCheckTokenOptions; - // Warning: (ae-forgotten-export) The symbol "DecodedAppCheckToken" needs to be exported by the entry point default-namespace.d.ts - export type DecodedAppCheckToken = DecodedAppCheckToken; - // Warning: (ae-forgotten-export) The symbol "VerifyAppCheckTokenOptions" needs to be exported by the entry point default-namespace.d.ts - export type VerifyAppCheckTokenOptions = VerifyAppCheckTokenOptions; - // Warning: (ae-forgotten-export) The symbol "VerifyAppCheckTokenResponse" needs to be exported by the entry point default-namespace.d.ts - export type VerifyAppCheckTokenResponse = VerifyAppCheckTokenResponse; -} +// @public +export type AppErrorCode = typeof AppErrorCode[keyof typeof AppErrorCode]; + +// @public +export function applicationDefault(httpAgent?: Agent): Credential; // @public export interface AppOptions { - // Warning: (ae-forgotten-export) The symbol "Credential" needs to be exported by the entry point default-namespace.d.ts credential?: Credential; databaseAuthVariableOverride?: object | null; databaseURL?: string; @@ -76,149 +44,16 @@ export interface AppOptions { storageBucket?: string; } -// @public (undocumented) -export const apps: (app.App | null)[]; - // @public -export function auth(app?: App): auth.Auth; - -// @public (undocumented) -export namespace auth { - // Warning: (ae-forgotten-export) The symbol "ActionCodeSettings" needs to be exported by the entry point default-namespace.d.ts - export type ActionCodeSettings = ActionCodeSettings; - // Warning: (ae-forgotten-export) The symbol "Auth" needs to be exported by the entry point default-namespace.d.ts - export type Auth = Auth; - // Warning: (ae-forgotten-export) The symbol "AuthFactorType" needs to be exported by the entry point default-namespace.d.ts - export type AuthFactorType = AuthFactorType; - // Warning: (ae-forgotten-export) The symbol "AuthProviderConfig" needs to be exported by the entry point default-namespace.d.ts - export type AuthProviderConfig = AuthProviderConfig; - // Warning: (ae-forgotten-export) The symbol "AuthProviderConfigFilter" needs to be exported by the entry point default-namespace.d.ts - export type AuthProviderConfigFilter = AuthProviderConfigFilter; - // Warning: (ae-forgotten-export) The symbol "BaseAuth" needs to be exported by the entry point default-namespace.d.ts - export type BaseAuth = BaseAuth; - // Warning: (ae-forgotten-export) The symbol "CreateMultiFactorInfoRequest" needs to be exported by the entry point default-namespace.d.ts - export type CreateMultiFactorInfoRequest = CreateMultiFactorInfoRequest; - // Warning: (ae-forgotten-export) The symbol "CreatePhoneMultiFactorInfoRequest" needs to be exported by the entry point default-namespace.d.ts - export type CreatePhoneMultiFactorInfoRequest = CreatePhoneMultiFactorInfoRequest; - // Warning: (ae-forgotten-export) The symbol "CreateRequest" needs to be exported by the entry point default-namespace.d.ts - export type CreateRequest = CreateRequest; - // Warning: (ae-forgotten-export) The symbol "CreateTenantRequest" needs to be exported by the entry point default-namespace.d.ts - export type CreateTenantRequest = CreateTenantRequest; - // Warning: (ae-forgotten-export) The symbol "DecodedAuthBlockingToken" needs to be exported by the entry point default-namespace.d.ts - // - // @alpha (undocumented) - export type DecodedAuthBlockingToken = DecodedAuthBlockingToken; - // Warning: (ae-forgotten-export) The symbol "DecodedIdToken" needs to be exported by the entry point default-namespace.d.ts - export type DecodedIdToken = DecodedIdToken; - // Warning: (ae-forgotten-export) The symbol "DeleteUsersResult" needs to be exported by the entry point default-namespace.d.ts - export type DeleteUsersResult = DeleteUsersResult; - // Warning: (ae-forgotten-export) The symbol "EmailIdentifier" needs to be exported by the entry point default-namespace.d.ts - export type EmailIdentifier = EmailIdentifier; - // Warning: (ae-forgotten-export) The symbol "EmailSignInProviderConfig" needs to be exported by the entry point default-namespace.d.ts - export type EmailSignInProviderConfig = EmailSignInProviderConfig; - // Warning: (ae-forgotten-export) The symbol "GetUsersResult" needs to be exported by the entry point default-namespace.d.ts - export type GetUsersResult = GetUsersResult; - // Warning: (ae-forgotten-export) The symbol "HashAlgorithmType" needs to be exported by the entry point default-namespace.d.ts - export type HashAlgorithmType = HashAlgorithmType; - // Warning: (ae-forgotten-export) The symbol "ListProviderConfigResults" needs to be exported by the entry point default-namespace.d.ts - export type ListProviderConfigResults = ListProviderConfigResults; - // Warning: (ae-forgotten-export) The symbol "ListTenantsResult" needs to be exported by the entry point default-namespace.d.ts - export type ListTenantsResult = ListTenantsResult; - // Warning: (ae-forgotten-export) The symbol "ListUsersResult" needs to be exported by the entry point default-namespace.d.ts - export type ListUsersResult = ListUsersResult; - // Warning: (ae-forgotten-export) The symbol "MultiFactorConfig" needs to be exported by the entry point default-namespace.d.ts - export type MultiFactorConfig = MultiFactorConfig; - // Warning: (ae-forgotten-export) The symbol "MultiFactorConfigState" needs to be exported by the entry point default-namespace.d.ts - export type MultiFactorConfigState = MultiFactorConfigState; - // Warning: (ae-forgotten-export) The symbol "MultiFactorCreateSettings" needs to be exported by the entry point default-namespace.d.ts - export type MultiFactorCreateSettings = MultiFactorCreateSettings; - // Warning: (ae-forgotten-export) The symbol "MultiFactorInfo" needs to be exported by the entry point default-namespace.d.ts - export type MultiFactorInfo = MultiFactorInfo; - // Warning: (ae-forgotten-export) The symbol "MultiFactorSettings" needs to be exported by the entry point default-namespace.d.ts - export type MultiFactorSettings = MultiFactorSettings; - // Warning: (ae-forgotten-export) The symbol "MultiFactorUpdateSettings" needs to be exported by the entry point default-namespace.d.ts - export type MultiFactorUpdateSettings = MultiFactorUpdateSettings; - // Warning: (ae-forgotten-export) The symbol "OIDCAuthProviderConfig" needs to be exported by the entry point default-namespace.d.ts - export type OIDCAuthProviderConfig = OIDCAuthProviderConfig; - // Warning: (ae-forgotten-export) The symbol "OIDCUpdateAuthProviderRequest" needs to be exported by the entry point default-namespace.d.ts - export type OIDCUpdateAuthProviderRequest = OIDCUpdateAuthProviderRequest; - // Warning: (ae-forgotten-export) The symbol "PhoneIdentifier" needs to be exported by the entry point default-namespace.d.ts - export type PhoneIdentifier = PhoneIdentifier; - // Warning: (ae-forgotten-export) The symbol "PhoneMultiFactorInfo" needs to be exported by the entry point default-namespace.d.ts - export type PhoneMultiFactorInfo = PhoneMultiFactorInfo; - // Warning: (ae-forgotten-export) The symbol "ProviderIdentifier" needs to be exported by the entry point default-namespace.d.ts - export type ProviderIdentifier = ProviderIdentifier; - // Warning: (ae-forgotten-export) The symbol "SAMLAuthProviderConfig" needs to be exported by the entry point default-namespace.d.ts - export type SAMLAuthProviderConfig = SAMLAuthProviderConfig; - // Warning: (ae-forgotten-export) The symbol "SAMLUpdateAuthProviderRequest" needs to be exported by the entry point default-namespace.d.ts - export type SAMLUpdateAuthProviderRequest = SAMLUpdateAuthProviderRequest; - // Warning: (ae-forgotten-export) The symbol "SessionCookieOptions" needs to be exported by the entry point default-namespace.d.ts - export type SessionCookieOptions = SessionCookieOptions; - // Warning: (ae-forgotten-export) The symbol "Tenant" needs to be exported by the entry point default-namespace.d.ts - export type Tenant = Tenant; - // Warning: (ae-forgotten-export) The symbol "TenantAwareAuth" needs to be exported by the entry point default-namespace.d.ts - export type TenantAwareAuth = TenantAwareAuth; - // Warning: (ae-forgotten-export) The symbol "TenantManager" needs to be exported by the entry point default-namespace.d.ts - export type TenantManager = TenantManager; - // Warning: (ae-forgotten-export) The symbol "UidIdentifier" needs to be exported by the entry point default-namespace.d.ts - export type UidIdentifier = UidIdentifier; - // Warning: (ae-forgotten-export) The symbol "UpdateAuthProviderRequest" needs to be exported by the entry point default-namespace.d.ts - export type UpdateAuthProviderRequest = UpdateAuthProviderRequest; - // Warning: (ae-forgotten-export) The symbol "UpdateMultiFactorInfoRequest" needs to be exported by the entry point default-namespace.d.ts - export type UpdateMultiFactorInfoRequest = UpdateMultiFactorInfoRequest; - // Warning: (ae-forgotten-export) The symbol "UpdatePhoneMultiFactorInfoRequest" needs to be exported by the entry point default-namespace.d.ts - export type UpdatePhoneMultiFactorInfoRequest = UpdatePhoneMultiFactorInfoRequest; - // Warning: (ae-forgotten-export) The symbol "UpdateRequest" needs to be exported by the entry point default-namespace.d.ts - export type UpdateRequest = UpdateRequest; - // Warning: (ae-forgotten-export) The symbol "UpdateTenantRequest" needs to be exported by the entry point default-namespace.d.ts - export type UpdateTenantRequest = UpdateTenantRequest; - // Warning: (ae-forgotten-export) The symbol "UserIdentifier" needs to be exported by the entry point default-namespace.d.ts - export type UserIdentifier = UserIdentifier; - // Warning: (ae-forgotten-export) The symbol "UserImportOptions" needs to be exported by the entry point default-namespace.d.ts - export type UserImportOptions = UserImportOptions; - // Warning: (ae-forgotten-export) The symbol "UserImportRecord" needs to be exported by the entry point default-namespace.d.ts - export type UserImportRecord = UserImportRecord; - // Warning: (ae-forgotten-export) The symbol "UserImportResult" needs to be exported by the entry point default-namespace.d.ts - export type UserImportResult = UserImportResult; - // Warning: (ae-forgotten-export) The symbol "UserInfo" needs to be exported by the entry point default-namespace.d.ts - export type UserInfo = UserInfo; - // Warning: (ae-forgotten-export) The symbol "UserMetadata" needs to be exported by the entry point default-namespace.d.ts - export type UserMetadata = UserMetadata; - // Warning: (ae-forgotten-export) The symbol "UserMetadataRequest" needs to be exported by the entry point default-namespace.d.ts - export type UserMetadataRequest = UserMetadataRequest; - // Warning: (ae-forgotten-export) The symbol "UserProviderRequest" needs to be exported by the entry point default-namespace.d.ts - export type UserProviderRequest = UserProviderRequest; - // Warning: (ae-forgotten-export) The symbol "UserRecord" needs to be exported by the entry point default-namespace.d.ts - export type UserRecord = UserRecord; -} +export function cert(serviceAccountPathOrObject: string | ServiceAccount, httpAgent?: Agent): Credential; -// @public (undocumented) -export namespace credential { - export type Credential = Credential; - const // Warning: (ae-forgotten-export) The symbol "applicationDefault" needs to be exported by the entry point default-namespace.d.ts - applicationDefault: typeof applicationDefault; - const // Warning: (ae-forgotten-export) The symbol "cert" needs to be exported by the entry point default-namespace.d.ts - cert: typeof cert; - const // Warning: (ae-forgotten-export) The symbol "refreshToken" needs to be exported by the entry point default-namespace.d.ts - refreshToken: typeof refreshToken; +// @public +export interface Credential { + getAccessToken(): Promise; } // @public -export function database(app?: App): database.Database; - -// @public (undocumented) -export namespace database { - // Warning: (ae-forgotten-export) The symbol "Database" needs to be exported by the entry point default-namespace.d.ts - export type Database = Database; - export type DataSnapshot = rtdb.DataSnapshot; - export type EventType = rtdb.EventType; - export type OnDisconnect = rtdb.OnDisconnect; - export type Query = rtdb.Query; - export type Reference = rtdb.Reference; - export type ThenableReference = rtdb.ThenableReference; - const enableLogging: typeof rtdb.enableLogging; - const ServerValue: rtdb.ServerValue; -} +export function deleteApp(app: App): Promise; // @public export interface ErrorInfo { @@ -228,6 +63,11 @@ export interface ErrorInfo { message: string; } +// @public +export class FirebaseAppError extends FirebaseError { + constructor(info: ErrorInfo, message?: string); +} + // @public export interface FirebaseArrayIndexError { error: FirebaseError; @@ -250,62 +90,11 @@ export class FirebaseError extends Error implements FirebaseError { constructor(errorInfo: ErrorInfo); } -// @public (undocumented) -export function firestore(app?: App): _firestore.Firestore; +// @public +export function getApp(appName?: string): App; -// @public (undocumented) -export namespace firestore { - import v1beta1 = _firestore.v1beta1; - import v1 = _firestore.v1; - import AggregateField = _firestore.AggregateField; - import AggregateFieldType = _firestore.AggregateFieldType; - import AggregateQuery = _firestore.AggregateQuery; - import AggregateQuerySnapshot = _firestore.AggregateQuerySnapshot; - import AggregateSpecData = _firestore.AggregateSpecData; - import AggregateSpec = _firestore.AggregateSpec; - import AggregateType = _firestore.AggregateType; - import BulkWriter = _firestore.BulkWriter; - import BulkWriterOptions = _firestore.BulkWriterOptions; - import BundleBuilder = _firestore.BundleBuilder; - import CollectionGroup = _firestore.CollectionGroup; - import CollectionReference = _firestore.CollectionReference; - import DocumentChange = _firestore.DocumentChange; - import DocumentChangeType = _firestore.DocumentChangeType; - import DocumentData = _firestore.DocumentData; - import DocumentReference = _firestore.DocumentReference; - import DocumentSnapshot = _firestore.DocumentSnapshot; - import FieldPath = _firestore.FieldPath; - import FieldValue = _firestore.FieldValue; - import Filter = _firestore.Filter; - import Firestore = _firestore.Firestore; - import FirestoreDataConverter = _firestore.FirestoreDataConverter; - import GeoPoint = _firestore.GeoPoint; - import GrpcStatus = _firestore.GrpcStatus; - import OrderByDirection = _firestore.OrderByDirection; - import Precondition = _firestore.Precondition; - import Query = _firestore.Query; - import QueryDocumentSnapshot = _firestore.QueryDocumentSnapshot; - import QueryPartition = _firestore.QueryPartition; - import QuerySnapshot = _firestore.QuerySnapshot; - import ReadOptions = _firestore.ReadOptions; - import Settings = _firestore.Settings; - import SetOptions = _firestore.SetOptions; - import Timestamp = _firestore.Timestamp; - import Transaction = _firestore.Transaction; - import UpdateData = _firestore.UpdateData; - import WhereFilterOp = _firestore.WhereFilterOp; - import WriteBatch = _firestore.WriteBatch; - import WriteResult = _firestore.WriteResult; - import PartialWithFieldValue = _firestore.PartialWithFieldValue; - import WithFieldValue = _firestore.WithFieldValue; - import Primitive = _firestore.Primitive; - import NestedUpdateFields = _firestore.NestedUpdateFields; - import ChildUpdateFields = _firestore.ChildUpdateFields; - import AddPrefixToKeys = _firestore.AddPrefixToKeys; - import UnionToIntersection = _firestore.UnionToIntersection; - import ReadOnlyTransactionOptions = _firestore.ReadOnlyTransactionOptions; - import setLogFunction = _firestore.setLogFunction; -} +// @public +export function getApps(): App[]; // @public export interface GoogleOAuthAccessToken { @@ -324,201 +113,15 @@ export interface HttpResponse { status: number; } -// @public (undocumented) -export function initializeApp(options?: AppOptions, name?: string): app.App; - -// @public -export function installations(app?: App): installations.Installations; - -// @public (undocumented) -export namespace installations { - // Warning: (ae-forgotten-export) The symbol "Installations" needs to be exported by the entry point default-namespace.d.ts - export type Installations = Installations; -} - -// @public -export function instanceId(app?: App): instanceId.InstanceId; - -// @public (undocumented) -export namespace instanceId { - // Warning: (ae-forgotten-export) The symbol "InstanceId" needs to be exported by the entry point default-namespace.d.ts - export type InstanceId = InstanceId; -} - -// @public -export function machineLearning(app?: App): machineLearning.MachineLearning; - -// @public (undocumented) -export namespace machineLearning { - // Warning: (ae-forgotten-export) The symbol "GcsTfliteModelOptions" needs to be exported by the entry point default-namespace.d.ts - export type GcsTfliteModelOptions = GcsTfliteModelOptions; - // Warning: (ae-forgotten-export) The symbol "ListModelsOptions" needs to be exported by the entry point default-namespace.d.ts - export type ListModelsOptions = ListModelsOptions; - // Warning: (ae-forgotten-export) The symbol "ListModelsResult" needs to be exported by the entry point default-namespace.d.ts - export type ListModelsResult = ListModelsResult; - // Warning: (ae-forgotten-export) The symbol "MachineLearning" needs to be exported by the entry point default-namespace.d.ts - export type MachineLearning = MachineLearning; - // Warning: (ae-forgotten-export) The symbol "Model" needs to be exported by the entry point default-namespace.d.ts - export type Model = Model; - // Warning: (ae-forgotten-export) The symbol "ModelOptions" needs to be exported by the entry point default-namespace.d.ts - export type ModelOptions = ModelOptions; - // Warning: (ae-forgotten-export) The symbol "ModelOptionsBase" needs to be exported by the entry point default-namespace.d.ts - export type ModelOptionsBase = ModelOptionsBase; - // Warning: (ae-forgotten-export) The symbol "TFLiteModel" needs to be exported by the entry point default-namespace.d.ts - export type TFLiteModel = TFLiteModel; -} - -// @public -export function messaging(app?: App): messaging.Messaging; - -// @public (undocumented) -export namespace messaging { - // Warning: (ae-forgotten-export) The symbol "AndroidConfig" needs to be exported by the entry point default-namespace.d.ts - export type AndroidConfig = AndroidConfig; - // Warning: (ae-forgotten-export) The symbol "AndroidFcmOptions" needs to be exported by the entry point default-namespace.d.ts - export type AndroidFcmOptions = AndroidFcmOptions; - // Warning: (ae-forgotten-export) The symbol "AndroidNotification" needs to be exported by the entry point default-namespace.d.ts - export type AndroidNotification = AndroidNotification; - // Warning: (ae-forgotten-export) The symbol "ApnsConfig" needs to be exported by the entry point default-namespace.d.ts - export type ApnsConfig = ApnsConfig; - // Warning: (ae-forgotten-export) The symbol "ApnsFcmOptions" needs to be exported by the entry point default-namespace.d.ts - export type ApnsFcmOptions = ApnsFcmOptions; - // Warning: (ae-forgotten-export) The symbol "ApnsPayload" needs to be exported by the entry point default-namespace.d.ts - export type ApnsPayload = ApnsPayload; - // Warning: (ae-forgotten-export) The symbol "Aps" needs to be exported by the entry point default-namespace.d.ts - export type Aps = Aps; - // Warning: (ae-forgotten-export) The symbol "ApsAlert" needs to be exported by the entry point default-namespace.d.ts - export type ApsAlert = ApsAlert; - // Warning: (ae-forgotten-export) The symbol "BatchResponse" needs to be exported by the entry point default-namespace.d.ts - export type BatchResponse = BatchResponse; - // Warning: (ae-forgotten-export) The symbol "ConditionMessage" needs to be exported by the entry point default-namespace.d.ts - export type ConditionMessage = ConditionMessage; - // Warning: (ae-forgotten-export) The symbol "CriticalSound" needs to be exported by the entry point default-namespace.d.ts - export type CriticalSound = CriticalSound; - // Warning: (ae-forgotten-export) The symbol "FcmOptions" needs to be exported by the entry point default-namespace.d.ts - export type FcmOptions = FcmOptions; - // Warning: (ae-forgotten-export) The symbol "LightSettings" needs to be exported by the entry point default-namespace.d.ts - export type LightSettings = LightSettings; - // Warning: (ae-forgotten-export) The symbol "Message" needs to be exported by the entry point default-namespace.d.ts - export type Message = Message; - // Warning: (ae-forgotten-export) The symbol "Messaging" needs to be exported by the entry point default-namespace.d.ts - export type Messaging = Messaging; - // Warning: (ae-forgotten-export) The symbol "MessagingTopicManagementResponse" needs to be exported by the entry point default-namespace.d.ts - export type MessagingTopicManagementResponse = MessagingTopicManagementResponse; - // Warning: (ae-forgotten-export) The symbol "MulticastMessage" needs to be exported by the entry point default-namespace.d.ts - export type MulticastMessage = MulticastMessage; - // Warning: (ae-forgotten-export) The symbol "Notification" needs to be exported by the entry point default-namespace.d.ts - export type Notification = Notification; - // Warning: (ae-forgotten-export) The symbol "SendResponse" needs to be exported by the entry point default-namespace.d.ts - export type SendResponse = SendResponse; - // Warning: (ae-forgotten-export) The symbol "TokenMessage" needs to be exported by the entry point default-namespace.d.ts - export type TokenMessage = TokenMessage; - // Warning: (ae-forgotten-export) The symbol "TopicMessage" needs to be exported by the entry point default-namespace.d.ts - export type TopicMessage = TopicMessage; - // Warning: (ae-forgotten-export) The symbol "WebpushConfig" needs to be exported by the entry point default-namespace.d.ts - export type WebpushConfig = WebpushConfig; - // Warning: (ae-forgotten-export) The symbol "WebpushFcmOptions" needs to be exported by the entry point default-namespace.d.ts - export type WebpushFcmOptions = WebpushFcmOptions; - // Warning: (ae-forgotten-export) The symbol "WebpushNotification" needs to be exported by the entry point default-namespace.d.ts - export type WebpushNotification = WebpushNotification; -} - // @public -export function projectManagement(app?: App): projectManagement.ProjectManagement; - -// @public (undocumented) -export namespace projectManagement { - // Warning: (ae-forgotten-export) The symbol "AndroidApp" needs to be exported by the entry point default-namespace.d.ts - export type AndroidApp = AndroidApp; - // Warning: (ae-forgotten-export) The symbol "AndroidAppMetadata" needs to be exported by the entry point default-namespace.d.ts - export type AndroidAppMetadata = AndroidAppMetadata; - // Warning: (ae-forgotten-export) The symbol "AppMetadata" needs to be exported by the entry point default-namespace.d.ts - export type AppMetadata = AppMetadata; - // Warning: (ae-forgotten-export) The symbol "AppPlatform" needs to be exported by the entry point default-namespace.d.ts - export type AppPlatform = AppPlatform; - // Warning: (ae-forgotten-export) The symbol "IosApp" needs to be exported by the entry point default-namespace.d.ts - export type IosApp = IosApp; - // Warning: (ae-forgotten-export) The symbol "IosAppMetadata" needs to be exported by the entry point default-namespace.d.ts - export type IosAppMetadata = IosAppMetadata; - // Warning: (ae-forgotten-export) The symbol "ProjectManagement" needs to be exported by the entry point default-namespace.d.ts - export type ProjectManagement = ProjectManagement; - // Warning: (ae-forgotten-export) The symbol "ShaCertificate" needs to be exported by the entry point default-namespace.d.ts - export type ShaCertificate = ShaCertificate; -} +export function initializeApp(options?: AppOptions, appName?: string): App; // @public -export function remoteConfig(app?: App): remoteConfig.RemoteConfig; - -// @public (undocumented) -export namespace remoteConfig { - // Warning: (ae-forgotten-export) The symbol "ExperimentParameterValue" needs to be exported by the entry point default-namespace.d.ts - export type ExperimentParameterValue = ExperimentParameterValue; - // Warning: (ae-forgotten-export) The symbol "ExperimentValue" needs to be exported by the entry point default-namespace.d.ts - export type ExperimentValue = ExperimentValue; - // Warning: (ae-forgotten-export) The symbol "ExperimentVariantExplicitValue" needs to be exported by the entry point default-namespace.d.ts - export type ExperimentVariantExplicitValue = ExperimentVariantExplicitValue; - // Warning: (ae-forgotten-export) The symbol "ExperimentVariantNoChange" needs to be exported by the entry point default-namespace.d.ts - export type ExperimentVariantNoChange = ExperimentVariantNoChange; - // Warning: (ae-forgotten-export) The symbol "ExperimentVariantValue" needs to be exported by the entry point default-namespace.d.ts - export type ExperimentVariantValue = ExperimentVariantValue; - // Warning: (ae-forgotten-export) The symbol "ExplicitParameterValue" needs to be exported by the entry point default-namespace.d.ts - export type ExplicitParameterValue = ExplicitParameterValue; - // Warning: (ae-forgotten-export) The symbol "InAppDefaultValue" needs to be exported by the entry point default-namespace.d.ts - export type InAppDefaultValue = InAppDefaultValue; - // Warning: (ae-forgotten-export) The symbol "ListVersionsOptions" needs to be exported by the entry point default-namespace.d.ts - export type ListVersionsOptions = ListVersionsOptions; - // Warning: (ae-forgotten-export) The symbol "ListVersionsResult" needs to be exported by the entry point default-namespace.d.ts - export type ListVersionsResult = ListVersionsResult; - // Warning: (ae-forgotten-export) The symbol "ParameterValueType" needs to be exported by the entry point default-namespace.d.ts - export type ParameterValueType = ParameterValueType; - // Warning: (ae-forgotten-export) The symbol "PersonalizationParameterValue" needs to be exported by the entry point default-namespace.d.ts - export type PersonalizationParameterValue = PersonalizationParameterValue; - // Warning: (ae-forgotten-export) The symbol "PersonalizationValue" needs to be exported by the entry point default-namespace.d.ts - export type PersonalizationValue = PersonalizationValue; - // Warning: (ae-forgotten-export) The symbol "RemoteConfig" needs to be exported by the entry point default-namespace.d.ts - export type RemoteConfig = RemoteConfig; - // Warning: (ae-forgotten-export) The symbol "RemoteConfigCondition" needs to be exported by the entry point default-namespace.d.ts - export type RemoteConfigCondition = RemoteConfigCondition; - // Warning: (ae-forgotten-export) The symbol "RemoteConfigParameter" needs to be exported by the entry point default-namespace.d.ts - export type RemoteConfigParameter = RemoteConfigParameter; - // Warning: (ae-forgotten-export) The symbol "RemoteConfigParameterGroup" needs to be exported by the entry point default-namespace.d.ts - export type RemoteConfigParameterGroup = RemoteConfigParameterGroup; - // Warning: (ae-forgotten-export) The symbol "RemoteConfigParameterValue" needs to be exported by the entry point default-namespace.d.ts - export type RemoteConfigParameterValue = RemoteConfigParameterValue; - // Warning: (ae-forgotten-export) The symbol "RemoteConfigTemplate" needs to be exported by the entry point default-namespace.d.ts - export type RemoteConfigTemplate = RemoteConfigTemplate; - // Warning: (ae-forgotten-export) The symbol "RemoteConfigUser" needs to be exported by the entry point default-namespace.d.ts - export type RemoteConfigUser = RemoteConfigUser; - // Warning: (ae-forgotten-export) The symbol "RolloutParameterValue" needs to be exported by the entry point default-namespace.d.ts - export type RolloutParameterValue = RolloutParameterValue; - // Warning: (ae-forgotten-export) The symbol "RolloutValue" needs to be exported by the entry point default-namespace.d.ts - export type RolloutValue = RolloutValue; - // Warning: (ae-forgotten-export) The symbol "TagColor" needs to be exported by the entry point default-namespace.d.ts - export type TagColor = TagColor; - // Warning: (ae-forgotten-export) The symbol "Version" needs to be exported by the entry point default-namespace.d.ts - export type Version = Version; -} +export function refreshToken(refreshTokenPathOrObject: string | object, httpAgent?: Agent): Credential; // @public (undocumented) export const SDK_VERSION: string; -// @public -export function securityRules(app?: App): securityRules.SecurityRules; - -// @public (undocumented) -export namespace securityRules { - // Warning: (ae-forgotten-export) The symbol "Ruleset" needs to be exported by the entry point default-namespace.d.ts - export type Ruleset = Ruleset; - // Warning: (ae-forgotten-export) The symbol "RulesetMetadata" needs to be exported by the entry point default-namespace.d.ts - export type RulesetMetadata = RulesetMetadata; - // Warning: (ae-forgotten-export) The symbol "RulesetMetadataList" needs to be exported by the entry point default-namespace.d.ts - export type RulesetMetadataList = RulesetMetadataList; - // Warning: (ae-forgotten-export) The symbol "RulesFile" needs to be exported by the entry point default-namespace.d.ts - export type RulesFile = RulesFile; - // Warning: (ae-forgotten-export) The symbol "SecurityRules" needs to be exported by the entry point default-namespace.d.ts - export type SecurityRules = SecurityRules; -} - // @public (undocumented) export interface ServiceAccount { // (undocumented) @@ -529,13 +132,6 @@ export interface ServiceAccount { projectId?: string; } -// @public -export function storage(app?: App): storage.Storage; - -// @public (undocumented) -export namespace storage { - // Warning: (ae-forgotten-export) The symbol "Storage_2" needs to be exported by the entry point default-namespace.d.ts - export type Storage = Storage_2; -} +// (No @packageDocumentation comment for this package) ```