diff --git a/gulpfile.js b/gulpfile.js index 6932e9cb82..7c8b8e7f6d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -85,6 +85,7 @@ gulp.task('compile', function() { 'lib/**/*.js', 'lib/credential/index.d.ts', 'lib/firebase-namespace-api.d.ts', + 'lib/instance-id/index.d.ts', 'lib/messaging/index.d.ts', 'lib/remote-config/index.d.ts', ]; diff --git a/src/firebase-namespace-api.ts b/src/firebase-namespace-api.ts index 248fe4b1df..679744b4c5 100644 --- a/src/firebase-namespace-api.ts +++ b/src/firebase-namespace-api.ts @@ -16,6 +16,7 @@ import { Agent } from 'http'; import { credential } from './credential/index'; +import { instanceId } from './instance-id/index'; import { messaging } from './messaging/index'; import { remoteConfig } from './remote-config/index'; @@ -214,6 +215,7 @@ export namespace app { */ options: AppOptions; + instanceId(): instanceId.InstanceId; messaging(): messaging.Messaging; remoteConfig(): remoteConfig.RemoteConfig; diff --git a/src/firebase-namespace.d.ts b/src/firebase-namespace.d.ts index 7bf2d1dda4..4431bbcb89 100644 --- a/src/firebase-namespace.d.ts +++ b/src/firebase-namespace.d.ts @@ -16,5 +16,6 @@ export * from './credential/index'; export * from './firebase-namespace-api'; +export * from './instance-id/index'; export * from './messaging/index'; export * from './remote-config/index'; diff --git a/src/instance-id/index.ts b/src/instance-id/index.ts index 8f984cdc4b..7ed4829ff0 100644 --- a/src/instance-id/index.ts +++ b/src/instance-id/index.ts @@ -14,24 +14,72 @@ * limitations under the License. */ -import { FirebaseApp } from '../firebase-app'; -import * as instanceIdApi from './instance-id'; - -export declare function instanceId(app?: FirebaseApp): instanceIdApi.InstanceId; +import { app } from '../firebase-namespace-api'; /** - * We must define a namespace to make the typings work correctly. Otherwise - * `admin.instanceId()` cannot be called like a function. Temporarily, - * admin.instanceId is used as the namespace name because we cannot barrel - * re-export the contents from instance-id, and we want it to - * match the namespacing in the re-export inside src/index.d.ts + * Gets the {@link admin.instanceId.InstanceId `InstanceId`} service for the + * default app or a given app. + * + * `admin.instanceId()` can be called with no arguments to access the default + * app's {@link admin.instanceId.InstanceId `InstanceId`} service or as + * `admin.instanceId(app)` to access the + * {@link admin.instanceId.InstanceId `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. + * + * @return The default `InstanceId` service if + * no app is provided or the `InstanceId` service associated with the + * provided app. */ +export declare function instanceId(app?: app.App): instanceId.InstanceId; + /* eslint-disable @typescript-eslint/no-namespace */ -export namespace admin.instanceId { - // See https://github.com/microsoft/TypeScript/issues/4336 - /* eslint-disable @typescript-eslint/no-unused-vars */ - // See https://github.com/typescript-eslint/typescript-eslint/issues/363 - // Allows for exposing classes as interfaces in typings - /* eslint-disable @typescript-eslint/no-empty-interface */ - export interface InstanceId extends instanceIdApi.InstanceId {} +export namespace instanceId { + /** + * Gets the {@link InstanceId `InstanceId`} service for the + * current app. + * + * @example + * ```javascript + * var instanceId = app.instanceId(); + * // The above is shorthand for: + * // var instanceId = admin.instanceId(app); + * ``` + * + * @return The `InstanceId` service for the + * current app. + */ + export interface InstanceId { + app: app.App; + + /** + * Deletes the specified instance ID and the associated data from Firebase. + * + * Note that Google Analytics for Firebase uses its own form of Instance ID to + * keep track of analytics data. Therefore deleting a Firebase Instance ID does + * not delete Analytics data. See + * [Delete an Instance ID](/support/privacy/manage-iids#delete_an_instance_id) + * for more information. + * + * @param instanceId The instance ID to be deleted. + * + * @return A promise fulfilled when the instance ID is deleted. + */ + deleteInstanceId(instanceId: string): Promise; + } } diff --git a/src/instance-id/instance-id.ts b/src/instance-id/instance-id.ts index b17434e9a3..e09c630440 100644 --- a/src/instance-id/instance-id.ts +++ b/src/instance-id/instance-id.ts @@ -18,9 +18,11 @@ import { FirebaseApp } from '../firebase-app'; import { FirebaseServiceInterface, FirebaseServiceInternalsInterface } from '../firebase-service'; import { FirebaseInstanceIdError, InstanceIdClientErrorCode } from '../utils/error'; import { FirebaseInstanceIdRequestHandler } from './instance-id-request-internal'; - +import { instanceId } from './index'; import * as validator from '../utils/validator'; +import InstanceIdInterface = instanceId.InstanceId; + /** * Internals of an InstanceId service instance. */ @@ -50,7 +52,7 @@ class InstanceIdInternals implements FirebaseServiceInternalsInterface { * @return The `InstanceId` service for the * current app. */ -export class InstanceId implements FirebaseServiceInterface { +export class InstanceId implements FirebaseServiceInterface, InstanceIdInterface { public INTERNAL: InstanceIdInternals = new InstanceIdInternals(); private app_: FirebaseApp;