The 2nd gen API for Cloud Functions for Firebase. This SDK supports deep imports. For example, the namespace `pubsub` is available at `firebase-functions/v2` or is directly importable from `firebase-functions/v2/pubsub`.

## Functions

| Function | Description |
|---|---|
| [onInit(callback)](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#oninit) | Registers a callback that should be run when in a production environment before executing any functions code. Calling this function more than once leads to undefined behavior. |
| [requiresAPI(api, reason)](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#requiresapi) | Declare that this project requires a specific Google Cloud API to be enabled. |
| [requiresRole(role)](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#requiresrole) | Declares that this codebase requires the specified IAM role to operate. When deployed, the Firebase CLI will automatically provision a managed service account with this role and attach it to all functions in this codebase. |
| [setGlobalOptions(options)](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#setglobaloptions) | Sets default options for all functions written using the 2nd gen SDK. |

## Classes

| Class | Description |
|---|---|
| [Change](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.change#change_class) | The Cloud Functions interface for events that change state, such as Realtime Database or Cloud Firestore `onWrite` and `onUpdate` events.For more information about the format used to construct `Change` objects, see below. |

## Interfaces

| Interface | Description |
|---|---|
| [CloudEvent](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudevent#cloudevent_interface) | ***(BETA)*** A `CloudEventBase` is the base of a cross-platform format for encoding a serverless event. For more information, see https://github.com/cloudevents/spec. |
| [CloudFunction](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.cloudfunction#cloudfunction_interface) | ***(BETA)*** A handler for CloudEvents. |
| [EventHandlerOptions](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.eventhandleroptions#eventhandleroptions_interface) | Additional fields that can be set on any event-handling function. |
| [GlobalOptions](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.globaloptions#globaloptions_interface) | `GlobalOptions` are options that can be set across an entire project. These options are common to HTTPS and event handling functions. |

## Namespaces

| Namespace | Description |
|---|---|
| [ai](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.ai#ai_namespace) |   |
| [alerts](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.alerts#alerts_namespace) |   |
| [database](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.database#database_namespace) |   |
| [dataconnect](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.dataconnect#dataconnect_namespace) |   |
| [eventarc](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.eventarc#eventarc_namespace) |   |
| [firestore](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.firestore#firestore_namespace) |   |
| [https](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.https#https_namespace) |   |
| [identity](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.identity#identity_namespace) |   |
| [lifecycle](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.lifecycle#lifecycle_namespace) |   |
| [params](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.params#params_namespace) |   |
| [pubsub](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.pubsub#pubsub_namespace) |   |
| [remoteConfig](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.remoteconfig#remoteconfig_namespace) |   |
| [scheduler](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.scheduler#scheduler_namespace) |   |
| [storage](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.storage#storage_namespace) |   |
| [tasks](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.tasks#tasks_namespace) |   |
| [testLab](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.testlab#testlab_namespace) |   |

## Variables

| Variable | Description |
|---|---|
| [app](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#app) |   |
| [config](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#config) |   |
| [logger](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#logger) | Logger object containing all logging methods.Mockable for testing purposes. |
| [traceContext](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#tracecontext) |   |

## Type Aliases

| Type Alias | Description |
|---|---|
| [IngressSetting](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#ingresssetting) | List of available options for `IngressSettings`. |
| [MemoryOption](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#memoryoption) | List of available memory options supported by Cloud Functions. |
| [ParamsOf](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#paramsof) | A type that maps all parameter capture groups into keys of a record. For example, ParamsOf\<"users/{uid}"\> is { uid: string } ParamsOf\<"users/{uid}/logs/{log}"\> is { uid: string; log: string } ParamsOf\<"some/static/data"\> is {}For flexibility reasons, ParamsOf is Record\<string, string\> |
| [Role](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#role) | A TypeScript literal type for IAM roles to provide compile-time validation. |
| [SupportedRegion](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#supportedregion) | List of all regions supported by Cloud Functions (2nd gen). |
| [VpcEgressSetting](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#vpcegresssetting) | List of available options for `VpcConnectorEgressSettings`. |

## onInit()

Registers a callback that should be run when in a production environment before executing any functions code. Calling this function more than once leads to undefined behavior.

**Signature:**

    export declare function onInit(callback: () => unknown): void;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| callback | () =\> unknown | initialization callback to be run before any function executes. |

**Returns:**

void

## requiresAPI()

Declare that this project requires a specific Google Cloud API to be enabled.

**Signature:**

    export declare function requiresAPI(api: GoogleCloudApi, reason?: string): void;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| api | GoogleCloudApi | The API name, e.g. "secretmanager.googleapis.com" |
| reason | string | Optional reason why the API is needed. |

**Returns:**

void

## requiresRole()

Declares that this codebase requires the specified IAM role to operate. When deployed, the Firebase CLI will automatically provision a managed service account with this role and attach it to all functions in this codebase.

**Signature:**

    export declare function requiresRole(role: Role): void;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| role | [Role](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions#role) | The IAM role required (e.g. "roles/bigquery.dataEditor") |

**Returns:**

void

## setGlobalOptions()

Sets default options for all functions written using the 2nd gen SDK.

**Signature:**

    export declare function setGlobalOptions(options: GlobalOptions): void;

### Parameters

| Parameter | Type | Description |
|---|---|---|
| options | [GlobalOptions](https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.globaloptions#globaloptions_interface) | Options to set as default |

**Returns:**

void

## app

**Signature:**

    app: {
        setEmulatedAdminApp: typeof setEmulatedAdminApp;
    }

## config

> > [!WARNING]
> > **Warning:** This API is now obsolete.
>
> `functions.config()` has been removed in firebase-functions v7. Migrate to environment parameters using the `params` module immediately. Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config

**Signature:**

    config: never

## logger

Logger object containing all logging methods.

Mockable for testing purposes.

**Signature:**

    logger: {
        write: typeof write;
        debug: typeof debug;
        log: typeof log;
        info: typeof info;
        warn: typeof warn;
        error: typeof error;
    }

## traceContext

**Signature:**

    traceContext: AsyncLocalStorage<TraceContext>

## IngressSetting

List of available options for `IngressSettings`.

**Signature:**

    export type IngressSetting = "ALLOW_ALL" | "ALLOW_INTERNAL_ONLY" | "ALLOW_INTERNAL_AND_GCLB";

## MemoryOption

List of available memory options supported by Cloud Functions.

**Signature:**

    export type MemoryOption = "128MiB" | "256MiB" | "512MiB" | "1GiB" | "2GiB" | "4GiB" | "8GiB" | "16GiB" | "32GiB";

## ParamsOf

A type that maps all parameter capture groups into keys of a record. For example, ParamsOf\<"users/{uid}"\> is { uid: string } ParamsOf\<"users/{uid}/logs/{log}"\> is { uid: string; log: string } ParamsOf\<"some/static/data"\> is {}

For flexibility reasons, ParamsOf is Record\<string, string\>

**Signature:**

    export type ParamsOf<PathPattern extends string | Expression<string>> = PathPattern extends Expression<string> ? Record<string, string> : string extends PathPattern ? Record<string, string> : {
        [Key in VarName<Split<NullSafe<Exclude<PathPattern, Expression<string>>>, "/">[number]>]: string;
    };

## Role

A TypeScript literal type for IAM roles to provide compile-time validation.

**Signature:**

    export type Role = `roles/${string}.${string}` | `projects/${string}/roles/${string}` | `organizations/${string}/roles/${string}`;

## SupportedRegion

List of all regions supported by Cloud Functions (2nd gen).

**Signature:**

    export type SupportedRegion = "asia-east1" | "asia-northeast1" | "asia-northeast2" | "europe-north1" | "europe-west1" | "europe-west4" | "us-central1" | "us-east1" | "us-east4" | "us-west1" | "asia-east2" | "asia-northeast3" | "asia-southeast1" | "asia-southeast2" | "asia-south1" | "australia-southeast1" | "europe-central2" | "europe-west2" | "europe-west3" | "europe-west6" | "northamerica-northeast1" | "southamerica-east1" | "us-west2" | "us-west3" | "us-west4";

## VpcEgressSetting

List of available options for `VpcConnectorEgressSettings`.

**Signature:**

    export type VpcEgressSetting = "PRIVATE_RANGES_ONLY" | "ALL_TRAFFIC";