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
| Capability | Description |
|---|---|
| Fluent Builder Pattern | Chain methods to construct functions declaratively |
| Multiple Trigger Types | Firestore, Pub/Sub, Auth, Storage, Scheduled, Cloud Tasks, Remote Config |
| Type Safety | Strong TypeScript types for events and transformations |
| Event Processing Chains | Compose functions that publish to topics or enqueue tasks |
| Conditional Logic | Built-in helpers for publishing/enqueueing based on conditions |
| Error Standardization | Consistent error logging across all function types |
| Multi-Function Mappings | Run multiple handlers for the same event simultaneously |
| Authentication Integration | Extract Firebase Auth tokens from callable functions |
| Function Invocation | Invoke 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 generatorDatabaseMethodBuilder- Firestore triggersTopicMethodBuilder- Pub/Sub triggersScheduledFunctionBuilder- Cron triggersRemoteConfigBuilder- Remote Config triggersCloudTasksBuilder- Task integration
Helper Functions
sendToTopic(),sendToTopicIf(),sendToTopicIfValueChanged()sendToCloudTasks(),sendToCloudTasksIf(),sendToCloudTasksIfValueChanged()logErrorAndThrowForCloudTasks()- Error logginggetFunctionUrl()- Function URL resolutionsendToFunctionTasks()- Function invocation
Authentication
getAuthToken()- Extract Auth token from callable contextGoogleCloudAuth- 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