Firebase Extensions

repository·next·Indexed 21 days ago

https://github.com/firebase/extensions

Official source code for Firebase Extensions, providing pre-packaged functionality to reduce custom code. Includes documentation for extensions such as Delete User Data, which automates data removal from Cloud Firestore, Realtime Database, and Cloud Storage upon user deletion, and Stream Firestore to BigQuery, which enables real-time incremental updates from Firestore collections to BigQuery datasets.

Tokens
64.9K
Snippets
163
Records
282
Agent score
64%

What's inside firebase-extensions

  1. What is the firestore-bigquery-change-tracker package?

    next

    The firestore-bigquery-change-tracker package is a utility dependency used to manage the BigQuery infrastructure created by the Stream Firestore to BigQuery Firebase Extension. Its primary responsibility is to initialize and update the BigQuery tables and views that are generated when using the extension.

    It is a required dependency for the following components:

    • The official Stream Firestore to BigQuery extension (firestore-bigquery-export).
    • The schema views script (GENERATE_SCHEMA_VIEWS.md).
    • The import Firestore documents script (IMPORT_EXISTING_DOCUMENTS.md).
  2. Overview of the Distributed Counter extension

    next

    The Distributed Counter extension provides a highly scalable counter service for Cloud Firestore. It is designed to handle high-velocity writes (such as views, likes, or shares) that would otherwise exceed Firestore's limit of one sustained write per second per document.

    How it works: Instead of writing to a single document, the extension shards writes across multiple documents in a _counter_shards_ subcollection. Each client increments its own unique shard. Background workers (provided by the extension) monitor and aggregate these shards into a single main document.

    Key Features:

    • Scales from 0 to 10,000 updates per second.
    • Supports an arbitrary number of counters.
    • Works offline and provides latency compensation for the main counter.
    • Note: This extension requires client-side logic to manage shard increments.
  3. Overview of Translate Text in Firestore extension

    next

    The Translate Text in Firestore extension automatically translates strings written to a specified Cloud Firestore collection into multiple target languages. It uses either the Cloud Translation API or Gemini (via Google AI or Vertex AI) to perform the translations.

    Key Behaviors:

    • Automatic Detection: The source language of the string is automatically detected.
    • Automatic Updates: If the original non-translated field is updated, the translations are automatically updated.
    • Output: Translations are written to a separate specified field within the same document.
    • Multi-collection support: To translate multiple collections, install the extension multiple times with different collection paths.
    • Multi-field support: To translate multiple fields in a single document, store a map of input strings in the designated input field.
    // Example of translating multiple fields by storing a map in the input field
    admin.firestore().collection('translations').add({
      first: "My name is Bob",
      second: "Hello, friend"
    })
  4. Overview of the Limit Child Nodes extension

    next
    The Limit Child Nodes extension allows you to control the maximum number of nodes stored in a specific Firebase Realtime Database path. When the number of child nodes in the specified path exceeds your defined maximum count, the extension automatically deletes the oldest nodes first until the path is back within the limit. This is useful for managing data growth and preventing unbounded storage in specific database locations.
  5. Resize Images Extension Overview

    next

    The Resize Images extension automatically detects image uploads to a specified Cloud Storage bucket and creates resized versions based on your dimensions. It supports JPEG, PNG, WebP, GIF, AVIF, and TIFF formats.

    Key Features:

    • Aspect Ratio Preservation: The extension maintains the original aspect ratio, shrinking the image until it fits within your specified maximum width and height.
    • Metadata Copying: Automatically copies Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Type, and user-provided metadata (including download tokens) to the resized images.
    • Multiple Sizes: You can configure multiple output dimensions (e.g., 200x200, 400x400) for a single upload.
    • Event Notifications: Can publish resize completion events via Eventarc, allowing you to trigger custom logic (like Cloud Functions) upon successful resizing.
    • Content Filtering: Uses Google AI models (via Genkit) to detect and block inappropriate content based on configurable strictness levels or custom yes/no prompts.
  6. Use the Delete User Data extension

    next

    The Delete User Data extension automatically removes data keyed on a user ID from Cloud Firestore, Realtime Database, or Cloud Storage when a user is deleted from Firebase Authentication. This helps in managing user privacy and fulfilling compliance requirements by ensuring that user-specific data is cleaned up following account deletion.

    Prerequisites

    • Your Firebase project must be on the Blaze (pay as you go) plan.
    • You must have Firebase Authentication set up to manage users.
    • Depending on your configuration, you must have Cloud Firestore, Realtime Database, or Cloud Storage initialized in your project.

    Core Functionality

    • Trigger: The extension is triggered by the deletion of a user from Firebase Authentication.
    • Scope: It can delete data from Firestore, Realtime Database, and/or Cloud Storage based on your configuration.
    • Identification: Data discovery is primarily keyed to the user's UID.
  7. Stream Firestore to BigQuery Overview

    next

    The Stream Firestore to BigQuery extension sends real-time, incremental updates from a specified Cloud Firestore collection to BigQuery. It creates a BigQuery dataset containing:

    1. A raw data table: Stores a full change history of documents. Key metadata fields include timestamp, document_name, and the operation (e.g., CREATE, UPDATE, IMPORT, DELETE).
    2. A view: Represents the current state of the data in your collection, showing the latest operation for each document.

    Key Behaviors:

    • Real-time & Incremental: Data in BigQuery mirrors your Firestore content as changes occur.
    • Scope: It only listens to changes in the specified collection, not its subcollections. To monitor subcollections, use {wildcard} notation in the collection path (e.g., chats/{chatid}/posts).
    • Wildcards: Enabling wildcard references adds a STRING column containing a JSON object of the wildcard IDs, which can be extracted using JSON_EXTRACT_SCALAR in BigQuery.
  8. Browse official Firebase extensions

    next

    You can discover and browse official Firebase extensions through several interfaces:

    • Firebase Extensions product page: General information and overview.
    • Firebase Extensions dashboard: Located in the Firebase console, where you can manage extensions for your specific projects.
    • Extensions Marketplace: A searchable catalog of available extensions at extensions.dev.
  9. Shorten URLs in Firestore using Bitly

    next

    The Shorten URLs in Firestore extension automatically generates shortened Bitly URLs when a long URL is written to a specific field in a Cloud Firestore document. It listens to a specified collection and updates the document with the shortened version in a new field. If the original URL is updated, the extension automatically updates the shortened URL as well.

    Prerequisites

    • A Firebase project on the Blaze (pay as you go) plan.
    • A configured Cloud Firestore database.
    • A Bitly account and a generated Bitly access token (obtainable via Bitly OAuth Apps).

    Configuration Parameters

    When installing the extension, you must provide the following configuration:

    ParameterDescription
    Bitly access tokenYour Bitly access token for API authentication.
    Collection pathThe path to the Firestore collection containing the URLs to be shortened.
    URL field nameThe name of the field in your documents that contains the original long URLs.
    Short URL field nameThe name of the field where the extension will store the resulting shortened URLs.
    Firestore Instance IDThe ID of the Firestore database to use. Use (default) for the default database.
    Firestore Instance LocationThe location of your Firestore database.

    IAM Permissions

    The extension requires the following IAM role to function:

    • datastore.user: Required to write the shortened URLs back to Cloud Firestore.
  10. Use the fs-bq-schema-views script to create BigQuery views

    next
    The fs-bq-schema-views script is a utility for the official Firebase Extension [Stream Firestore to BigQuery]. It automates the creation of BigQuery views by reading a provided JSON schema configuration file and querying the firestore-bigquery-export extension's changelog table. This allows you to transform raw changelog data into structured views based on your defined schema.
  11. Use the Flutter/Dart client for Distributed Counter

    next
    The Flutter/Dart client provides an interface for interacting with the Distributed Counter Firebase Extension within Flutter or Dart applications. It allows you to increment or decrement counters in a distributed manner, which is useful for high-concurrency scenarios where standard Firestore increments might lead to contention.
  12. What is the fs-bq-schema-views script?

    next

    The fs-bq-schema-views script (the "schema-views script") is a utility used with the Stream Firestore to BigQuery extension.

    While the extension mirrors raw Firestore data to BigQuery without applying types, the schema-views script generates richly-typed BigQuery views based on a JSON schema configuration file. It uses BigQuery's built-in JSON functions and user-defined functions (UDFs) provided by the extension to convert Firestore document properties into typed BigQuery cells.

    This decoupling ensures that schema validation is low-risk: if a Firestore document does not match the schema, the resulting BigQuery columns will simply contain null values rather than causing data loss or errors.