Skip to Content
Engineering11 Documentation 🔥

Cloud Functions API

Builder pattern framework for creating Firebase Cloud Functions with type safety and error handling.

What It Does

The Cloud Functions API provides a comprehensive framework for building Firebase Cloud Functions using a fluent builder pattern. It supports multiple trigger types (Firestore, Pub/Sub, Auth, Storage, Scheduled), simplifies function creation, and provides built-in error handling, logging, and helper utilities for conditional event publishing and task enqueueing.

Key Capabilities

CapabilityDescription
Fluent Builder PatternChain methods to construct functions declaratively
Multiple Trigger TypesFirestore, Pub/Sub, Auth, Storage, Scheduled, Cloud Tasks, Remote Config
Type SafetyStrong TypeScript types for events and transformations
Event Processing ChainsCompose functions that publish to topics or enqueue tasks
Conditional LogicBuilt-in helpers for publishing/enqueueing based on conditions
Error StandardizationConsistent error logging across all function types
Multi-Function MappingsRun multiple handlers for the same event simultaneously
Authentication IntegrationExtract Firebase Auth tokens from callable functions
Function InvocationInvoke other Cloud Functions with automatic URL resolution

Configuration

Runtime Options

  • Default Memory: 1GB (v1), 1GiB (v2)
  • Configurable: Via withOptions()
  • Per-function override: Supported

Naming Conventions

  • Prefix: Enforced camelCase
  • Pattern: {prefix}{EventType}{CollectionName}
  • Example: myServiceOnCreateUser

Exports

Builder Classes

  • CloudFunctionGenerator - Main generator
  • DatabaseMethodBuilder - Firestore triggers
  • TopicMethodBuilder - Pub/Sub triggers
  • ScheduledFunctionBuilder - Cron triggers
  • RemoteConfigBuilder - Remote Config triggers
  • CloudTasksBuilder - Task integration

Helper Functions

  • sendToTopic(), sendToTopicIf(), sendToTopicIfValueChanged()
  • sendToCloudTasks(), sendToCloudTasksIf(), sendToCloudTasksIfValueChanged()
  • logErrorAndThrowForCloudTasks() - Error logging
  • getFunctionUrl() - Function URL resolution
  • sendToFunctionTasks() - Function invocation

Authentication

  • getAuthToken() - Extract Auth token from callable context
  • GoogleCloudAuth - Singleton auth client

Types

  • Function signatures and mappings
  • Event types
  • Storage operations enum

Common Use Cases

  • Database triggers: React to Firestore document changes
  • Async workflows: Chain functions via topics and tasks
  • Scheduled jobs: Cron-based cleanup, reporting, batch processing
  • Auth lifecycle: User creation and deletion workflows
  • Storage processing: Image processing, file validation, metadata extraction
  • Event transformation: Transform database events into domain events
  • Remote Config: Respond to configuration changes
  • Function orchestration: Coordinate multiple Cloud Functions

Roadmap

Multi-Cloud Support

This API currently supports Google Cloud Platform. Future versions will add support for additional cloud providers and container-based deployment options, enabling greater flexibility in infrastructure choices.

What Customers Don’t Have to Build

  • Cloud Function builder infrastructure
  • Firestore trigger handlers
  • Pub/Sub topic handlers
  • Auth event handlers
  • Storage trigger handlers
  • Scheduled function wrappers
  • Remote Config handlers
  • Conditional publishing logic
  • Conditional task enqueueing
  • Field change detection
  • Function URL resolution
  • Cross-function invocation
  • Error handling wrappers
  • Type-safe event conversions
  • Multi-function mapping support
  • Function naming conventions
  • Export orchestration
  • Authentication extraction
  • Message parsing
Last updated on