firebase-functions package

Functions

Function Description
config() Store and retrieve project configuration data such as third-party API keys or other settings. You can set configuration values using the Firebase CLI as described in https://firebase.google.com/docs/functions/config-env.
onInit(callback) 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.
optionsToEndpoint(options)
optionsToTrigger(options)
region(regions) Configure the regions that the function is deployed to.
runWith(runtimeOptions) Configure runtime options for the function.

Classes

Class Description
Change 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.
FunctionBuilder

Interfaces

Interface Description
BlockingFunction The function type for Auth Blocking triggers.
CloudFunction The function type for all non-HTTPS triggers. This should be exported from your JavaScript file to define a Cloud Function.This type is a special JavaScript function which takes a templated Event object as its only argument.
DeploymentOptions Configuration options for a function that applies during function deployment.
Event Wire format for an event.
EventContext The context in which an event occurred.
FailurePolicy Configuration option for failure policy on background functions.
HttpsFunction The function type for HTTPS triggers. This should be exported from your JavaScript file to define a Cloud Function.
Resource Resource is a standard format for defining a resource (google.rpc.context.AttributeContext.Resource). In Cloud Functions, it is the resource that triggered the function - such as a storage bucket.
Runnable A Runnable has a run method which directly invokes the user-defined function - useful for unit testing.
RuntimeOptions Configuration options for a function that applicable at runtime.
Schedule Configuration options for scheduled functions.
ScheduleRetryConfig Scheduler retry options. Applies only to scheduled functions.

Namespaces

Namespace Description
analytics
auth
database
firestore
https
logger
params
pubsub
remoteConfig
storage
tasks
testLab

Variables

Variable Description
app
DEFAULT_FAILURE_POLICY
INGRESS_SETTINGS_OPTIONS List of available options for IngressSettings.
MAX_NUMBER_USER_LABELS
MAX_TIMEOUT_SECONDS Cloud Functions max timeout value.
MIN_TIMEOUT_SECONDS Cloud Functions min timeout value.
RESET_VALUE Special configuration value to reset configuration to platform default.
SUPPORTED_REGIONS List of all regions supported by Cloud Functions.
VALID_MEMORY_OPTIONS List of available memory options supported by Cloud Functions.
VPC_EGRESS_SETTINGS_OPTIONS List of available options for VpcConnectorEgressSettings.

config()

Using functions.config() is discouraged. See https://firebase.google.com/docs/functions/config-env.

Store and retrieve project configuration data such as third-party API keys or other settings. You can set configuration values using the Firebase CLI as described in https://firebase.google.com/docs/functions/config-env.

Signature:

export declare function config(): Record<string, any>;

Returns:

Record<string, any>

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

optionsToEndpoint()

Signature:

export declare function optionsToEndpoint(options: DeploymentOptions): ManifestEndpoint;

Parameters

Parameter Type Description
options DeploymentOptions

Returns:

ManifestEndpoint

optionsToTrigger()

Signature:

export declare function optionsToTrigger(options: DeploymentOptions): any;

Parameters

Parameter Type Description
options DeploymentOptions

Returns:

any

region()

Configure the regions that the function is deployed to.

Signature:

export declare function region(...regions: Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression<string> | ResetValue>): FunctionBuilder;

Parameters

Parameter Type Description
regions Array<(typeof SUPPORTED_REGIONS)[number] | string | Expression<string> | ResetValue> One of more region strings.

Returns:

FunctionBuilder

Example 1

functions.region('us-east1')

Example 2

functions.region('us-east1', 'us-central1')

runWith()

Configure runtime options for the function.

Signature:

export declare function runWith(runtimeOptions: RuntimeOptions): FunctionBuilder;

Parameters

Parameter Type Description
runtimeOptions RuntimeOptions Object with optional fields: 1. memory: amount of memory to allocate to the function, possible values are: '128MB', '256MB', '512MB', '1GB', '2GB', '4GB', and '8GB'. 2. timeoutSeconds: timeout for the function in seconds, possible values are 0 to 540. 3. failurePolicy: failure policy of the function, with boolean true being equivalent to providing an empty retry object. 4. vpcConnector: id of a VPC connector in same project and region. 5. vpcConnectorEgressSettings: when a vpcConnector is set, control which egress traffic is sent through the vpcConnector. 6. serviceAccount: Specific service account for the function. 7. ingressSettings: ingress settings for the function, which control where a HTTPS function can be called from.Value must not be null.

Returns:

FunctionBuilder

app

Signature:

app: {
    setEmulatedAdminApp: typeof setEmulatedAdminApp;
}

DEFAULT_FAILURE_POLICY

Signature:

DEFAULT_FAILURE_POLICY: FailurePolicy

INGRESS_SETTINGS_OPTIONS

List of available options for IngressSettings.

Signature:

INGRESS_SETTINGS_OPTIONS: readonly ["INGRESS_SETTINGS_UNSPECIFIED", "ALLOW_ALL", "ALLOW_INTERNAL_ONLY", "ALLOW_INTERNAL_AND_GCLB"]

MAX_NUMBER_USER_LABELS

Signature:

MAX_NUMBER_USER_LABELS = 58

MAX_TIMEOUT_SECONDS

Cloud Functions max timeout value.

Signature:

MAX_TIMEOUT_SECONDS = 540

MIN_TIMEOUT_SECONDS

Cloud Functions min timeout value.

Signature:

MIN_TIMEOUT_SECONDS = 0

RESET_VALUE

Special configuration value to reset configuration to platform default.

Signature:

RESET_VALUE: ResetValue

SUPPORTED_REGIONS

List of all regions supported by Cloud Functions.

Signature:

SUPPORTED_REGIONS: readonly ["us-central1", "us-east1", "us-east4", "us-west2", "us-west3", "us-west4", "europe-central2", "europe-west1", "europe-west2", "europe-west3", "europe-west6", "asia-east1", "asia-east2", "asia-northeast1", "asia-northeast2", "asia-northeast3", "asia-south1", "asia-southeast1", "asia-southeast2", "northamerica-northeast1", "southamerica-east1", "australia-southeast1"]

VALID_MEMORY_OPTIONS

List of available memory options supported by Cloud Functions.

Signature:

VALID_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB", "4GB", "8GB"]

VPC_EGRESS_SETTINGS_OPTIONS

List of available options for VpcConnectorEgressSettings.

Signature:

VPC_EGRESS_SETTINGS_OPTIONS: readonly ["VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED", "PRIVATE_RANGES_ONLY", "ALL_TRAFFIC"]