diff --git a/etc/firebase-admin.app.api.md b/etc/firebase-admin.app.api.md index 96c5a4ea55..08d145df0c 100644 --- a/etc/firebase-admin.app.api.md +++ b/etc/firebase-admin.app.api.md @@ -37,6 +37,20 @@ export interface Credential { // @public (undocumented) export function deleteApp(app: App): Promise; +// @public +export interface FirebaseArrayIndexError { + error: FirebaseError; + index: number; +} + +// @public +export interface FirebaseError { + code: string; + message: string; + stack?: string; + toJSON(): object; +} + // @public (undocumented) export function getApp(name?: string): App; diff --git a/src/app/core.ts b/src/app/core.ts index 397ce189a5..c234b2875f 100644 --- a/src/app/core.ts +++ b/src/app/core.ts @@ -123,3 +123,82 @@ export interface App { */ options: AppOptions; } + +/** + * `FirebaseError` is a subclass of the standard JavaScript `Error` object. In + * addition to a message string and stack trace, it contains a string code. + */ +export interface FirebaseError { + + /** + * Error codes are strings using the following format: `"service/string-code"`. + * Some examples include `"auth/invalid-uid"` and + * `"messaging/invalid-recipient"`. + * + * While the message for a given error can change, the code will remain the same + * between backward-compatible versions of the Firebase SDK. + */ + code: string; + + /** + * An explanatory message for the error that just occurred. + * + * This message is designed to be helpful to you, the developer. Because + * it generally does not convey meaningful information to end users, + * this message should not be displayed in your application. + */ + message: string; + + /** + * A string value containing the execution backtrace when the error originally + * occurred. + * + * This information can be useful to you and can be sent to + * {@link https://firebase.google.com/support/ Firebase Support} to help + * explain the cause of an error. + */ + stack?: string; + + /** + * @return A JSON-serializable representation of this object. + */ + toJSON(): object; +} + +/** + * Composite type which includes both a `FirebaseError` object and an index + * which can be used to get the errored item. + * + * @example + * ```javascript + * var registrationTokens = [token1, token2, token3]; + * admin.messaging().subscribeToTopic(registrationTokens, 'topic-name') + * .then(function(response) { + * if (response.failureCount > 0) { + * console.log("Following devices unsucessfully subscribed to topic:"); + * response.errors.forEach(function(error) { + * var invalidToken = registrationTokens[error.index]; + * console.log(invalidToken, error.error); + * }); + * } else { + * console.log("All devices successfully subscribed to topic:", response); + * } + * }) + * .catch(function(error) { + * console.log("Error subscribing to topic:", error); + * }); + *``` + */ +export interface FirebaseArrayIndexError { + + /** + * The index of the errored item within the original array passed as part of the + * called API method. + */ + index: number; + + /** + * The error object. + */ + error: FirebaseError; +} diff --git a/src/app/index.ts b/src/app/index.ts index 9aeef5b363..e343e4fac2 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -17,7 +17,7 @@ import { getSdkVersion } from '../utils'; -export { App, AppOptions } from './core' +export { App, AppOptions, FirebaseArrayIndexError, FirebaseError } from './core' export { initializeApp, getApp, getApps, deleteApp } from './lifecycle'; export { Credential, ServiceAccount, GoogleOAuthAccessToken } from './credential'; diff --git a/src/auth/user-import-builder.ts b/src/auth/user-import-builder.ts index 72faa5304e..c0e151abaa 100644 --- a/src/auth/user-import-builder.ts +++ b/src/auth/user-import-builder.ts @@ -14,11 +14,11 @@ * limitations under the License. */ +import { FirebaseArrayIndexError } from '../app/index'; import { deepCopy, deepExtend } from '../utils/deep-copy'; import * as utils from '../utils'; import * as validator from '../utils/validator'; import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error'; -import { FirebaseArrayIndexError } from '../firebase-namespace-api'; import { UpdateMultiFactorInfoRequest, UpdatePhoneMultiFactorInfoRequest, MultiFactorUpdateSettings } from './auth-config'; diff --git a/src/firebase-namespace-api.ts b/src/firebase-namespace-api.ts index 9a56547118..798d8c426c 100644 --- a/src/firebase-namespace-api.ts +++ b/src/firebase-namespace-api.ts @@ -29,85 +29,6 @@ import { App as AppCore, AppOptions } from './app/index'; export * from './app/index'; -/** - * `FirebaseError` is a subclass of the standard JavaScript `Error` object. In - * addition to a message string and stack trace, it contains a string code. - */ -export interface FirebaseError { - - /** - * Error codes are strings using the following format: `"service/string-code"`. - * Some examples include `"auth/invalid-uid"` and - * `"messaging/invalid-recipient"`. - * - * While the message for a given error can change, the code will remain the same - * between backward-compatible versions of the Firebase SDK. - */ - code: string; - - /** - * An explanatory message for the error that just occurred. - * - * This message is designed to be helpful to you, the developer. Because - * it generally does not convey meaningful information to end users, - * this message should not be displayed in your application. - */ - message: string; - - /** - * A string value containing the execution backtrace when the error originally - * occurred. - * - * This information can be useful to you and can be sent to - * {@link https://firebase.google.com/support/ Firebase Support} to help - * explain the cause of an error. - */ - stack?: string; - - /** - * @return A JSON-serializable representation of this object. - */ - toJSON(): object; -} - -/** - * Composite type which includes both a `FirebaseError` object and an index - * which can be used to get the errored item. - * - * @example - * ```javascript - * var registrationTokens = [token1, token2, token3]; - * admin.messaging().subscribeToTopic(registrationTokens, 'topic-name') - * .then(function(response) { - * if (response.failureCount > 0) { - * console.log("Following devices unsucessfully subscribed to topic:"); - * response.errors.forEach(function(error) { - * var invalidToken = registrationTokens[error.index]; - * console.log(invalidToken, error.error); - * }); - * } else { - * console.log("All devices successfully subscribed to topic:", response); - * } - * }) - * .catch(function(error) { - * console.log("Error subscribing to topic:", error); - * }); - *``` - */ -export interface FirebaseArrayIndexError { - - /** - * The index of the errored item within the original array passed as part of the - * called API method. - */ - index: number; - - /** - * The error object. - */ - error: FirebaseError; -} - // eslint-disable-next-line @typescript-eslint/no-namespace export namespace app { /** diff --git a/src/messaging/messaging-api.ts b/src/messaging/messaging-api.ts index 44c68e66eb..e586ba039d 100644 --- a/src/messaging/messaging-api.ts +++ b/src/messaging/messaging-api.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { FirebaseArrayIndexError, FirebaseError } from '../firebase-namespace-api'; +import { FirebaseArrayIndexError, FirebaseError } from '../app/index'; export interface BaseMessage { data?: { [key: string]: string }; diff --git a/test/unit/auth/auth.spec.ts b/test/unit/auth/auth.spec.ts index 406d1c7ee7..d896e75f20 100644 --- a/test/unit/auth/auth.spec.ts +++ b/test/unit/auth/auth.spec.ts @@ -27,8 +27,6 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as utils from '../utils'; import * as mocks from '../../resources/mocks'; -import { Auth, TenantAwareAuth, BaseAuth } from '../../../src/auth/index'; -import { UserRecord } from '../../../src/auth/user-record'; import { FirebaseApp } from '../../../src/app/firebase-app'; import { AuthRequestHandler, TenantAwareAuthRequestHandler, AbstractAuthRequestHandler, @@ -41,10 +39,12 @@ import { OIDCConfig, SAMLConfig, OIDCConfigServerResponse, SAMLConfigServerResponse, } from '../../../src/auth/auth-config'; import { deepCopy } from '../../../src/utils/deep-copy'; -import { TenantManager } from '../../../src/auth/tenant-manager'; import { ServiceAccountCredential } from '../../../src/app/credential-internal'; import { HttpClient } from '../../../src/utils/api-request'; -import { DecodedIdToken, UpdateRequest, AuthProviderConfigFilter } from '../../../src/auth/index'; +import { + Auth, TenantAwareAuth, BaseAuth, UserRecord, DecodedIdToken, + UpdateRequest, AuthProviderConfigFilter, TenantManager, +} from '../../../src/auth/index'; chai.should(); chai.use(sinonChai); diff --git a/test/unit/auth/tenant-manager.spec.ts b/test/unit/auth/tenant-manager.spec.ts index b769d236b0..720ba32b01 100644 --- a/test/unit/auth/tenant-manager.spec.ts +++ b/test/unit/auth/tenant-manager.spec.ts @@ -25,11 +25,10 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as mocks from '../../resources/mocks'; import { FirebaseApp } from '../../../src/app/firebase-app'; import { AuthRequestHandler } from '../../../src/auth/auth-api-request'; -import { Tenant, TenantServerResponse } from '../../../src/auth/tenant'; -import { TenantManager } from '../../../src/auth/tenant-manager'; +import { TenantServerResponse } from '../../../src/auth/tenant'; import { AuthClientErrorCode, FirebaseAuthError } from '../../../src/utils/error'; import { - CreateTenantRequest, UpdateTenantRequest, ListTenantsResult, + CreateTenantRequest, UpdateTenantRequest, ListTenantsResult, Tenant, TenantManager, } from '../../../src/auth/index'; chai.should(); diff --git a/test/unit/auth/tenant.spec.ts b/test/unit/auth/tenant.spec.ts index 31370e17bc..fbb94d3b23 100644 --- a/test/unit/auth/tenant.spec.ts +++ b/test/unit/auth/tenant.spec.ts @@ -21,9 +21,9 @@ import * as chaiAsPromised from 'chai-as-promised'; import { deepCopy } from '../../../src/utils/deep-copy'; import { EmailSignInConfig, MultiFactorAuthConfig } from '../../../src/auth/auth-config'; -import { Tenant, TenantServerResponse } from '../../../src/auth/tenant'; +import { TenantServerResponse } from '../../../src/auth/tenant'; import { - CreateTenantRequest, UpdateTenantRequest, EmailSignInProviderConfig, + CreateTenantRequest, UpdateTenantRequest, EmailSignInProviderConfig, Tenant, } from '../../../src/auth/index'; chai.should(); diff --git a/test/unit/instance-id/instance-id.spec.ts b/test/unit/instance-id/instance-id.spec.ts index 90bbacdb8d..e6669c7fa8 100644 --- a/test/unit/instance-id/instance-id.spec.ts +++ b/test/unit/instance-id/instance-id.spec.ts @@ -26,7 +26,7 @@ import * as chaiAsPromised from 'chai-as-promised'; import * as utils from '../utils'; import * as mocks from '../../resources/mocks'; -import { InstanceId } from '../../../src/instance-id/instance-id'; +import { InstanceId } from '../../../src/instance-id/index'; import { FirebaseInstanceIdRequestHandler } from '../../../src/instance-id/instance-id-request-internal'; import { FirebaseApp } from '../../../src/app/firebase-app'; import { FirebaseInstanceIdError, InstanceIdClientErrorCode } from '../../../src/utils/error'; diff --git a/test/unit/messaging/messaging.spec.ts b/test/unit/messaging/messaging.spec.ts index b322030a18..3277edeefe 100644 --- a/test/unit/messaging/messaging.spec.ts +++ b/test/unit/messaging/messaging.spec.ts @@ -31,9 +31,8 @@ import { FirebaseApp } from '../../../src/app/firebase-app'; import { Message, MessagingOptions, MessagingPayload, MessagingDevicesResponse, MessagingDeviceGroupResponse, MessagingTopicManagementResponse, BatchResponse, - SendResponse, MulticastMessage, + SendResponse, MulticastMessage, Messaging, } from '../../../src/messaging/index'; -import { Messaging } from '../../../src/messaging/messaging'; import { BLACKLISTED_OPTIONS_KEYS, BLACKLISTED_DATA_PAYLOAD_KEYS } from '../../../src/messaging/messaging-internal'; import { HttpClient } from '../../../src/utils/api-request'; import { getSdkVersion } from '../../../src/utils/index'; diff --git a/test/unit/remote-config/remote-config-api-client.spec.ts b/test/unit/remote-config/remote-config-api-client.spec.ts index 2d982e8808..70ca7bae97 100644 --- a/test/unit/remote-config/remote-config-api-client.spec.ts +++ b/test/unit/remote-config/remote-config-api-client.spec.ts @@ -19,7 +19,6 @@ import * as _ from 'lodash'; import * as chai from 'chai'; import * as sinon from 'sinon'; -import { remoteConfig } from '../../../src/remote-config/index'; import { FirebaseRemoteConfigError, RemoteConfigApiClient @@ -31,10 +30,9 @@ import { FirebaseAppError } from '../../../src/utils/error'; import { FirebaseApp } from '../../../src/app/firebase-app'; import { deepCopy } from '../../../src/utils/deep-copy'; import { getSdkVersion } from '../../../src/utils/index'; - -import RemoteConfigTemplate = remoteConfig.RemoteConfigTemplate; -import Version = remoteConfig.Version; -import ListVersionsResult = remoteConfig.ListVersionsResult; +import { + RemoteConfigTemplate, Version, ListVersionsResult, +} from '../../../src/remote-config/index'; const expect = chai.expect; diff --git a/test/unit/storage/storage.spec.ts b/test/unit/storage/storage.spec.ts index 80cb49ab92..5f59250930 100644 --- a/test/unit/storage/storage.spec.ts +++ b/test/unit/storage/storage.spec.ts @@ -22,7 +22,7 @@ import { expect } from 'chai'; import * as mocks from '../../resources/mocks'; import { FirebaseApp } from '../../../src/app/firebase-app'; -import { Storage } from '../../../src/storage/storage'; +import { Storage } from '../../../src/storage/index'; describe('Storage', () => { let mockApp: FirebaseApp;