Skip to content

馃悰 [@firebase-function-kits/firestore-bundle-builder] Missing requiresAPI declarations for Cloud Firestore and Cloud Storage APIs#3116

Description

@shettyvarun268

[REQUIRED] Step 2: Describe your configuration

  • Extension / Kit name: firestore-bundle-builder (@firebase-function-kits/firestore-bundle-builder)
  • Extension / Kit version: 0.0.2-rc.2
  • Firebase Tools version: 15.29.0
  • Configuration values:
    • Clean GCP / Firebase project deployment where Cloud Firestore API was not previously enabled.

[REQUIRED] Step 3: Describe the problem

@firebase-function-kits/firestore-bundle-builder fails with HTTP 500 / 7 PERMISSION_DENIED: Cloud Firestore API has not been used in project ... before or it is disabled upon initial request on fresh projects because requiresAPI("firestore.googleapis.com", ...) is not declared in src/index.ts.

Steps to reproduce:

  1. Create a brand-new GCP/Firebase project (or test on a clean project where firestore.googleapis.com is not pre-enabled).
  2. Scaffold and deploy @firebase-function-kits/firestore-bundle-builder@0.0.2-rc.2 using Firebase CLI 15.29.0 with standard .env:
    FUNCTION_DEFAULT_REGION=us-central1
    BUNDLESPEC_COLLECTION=bundles
    BUNDLE_STORAGE_BUCKET=<bucket-name>
    STORAGE_PREFIX=bundles
    firebase deploy --only functions --force
  3. Invoke the deployed function URL:
    curl -i https://<function-url>/test-bundle
Expected result

firebase deploy identifies the required Google Cloud APIs via requiresAPI() and enables firestore.googleapis.com and storage.googleapis.com automatically during deployment. The function successfully queries Firestore and returns HTTP 404: Could not find bundle with ID test-bundle.

Actual result

firebase deploy completes without enabling firestore.googleapis.com because requiresAPI is missing from src/index.ts. When invoked, the function throws a runtime error and returns HTTP 500:

Unhandled error Error: 7 PERMISSION_DENIED: Cloud Firestore API has not been used in project <project-id> before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/firestore.googleapis.com/overview?project=<project-id> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
    at callErrorFromStatus (/workspace/node_modules/@firebase-function-kits/firestore-bundle-builder/node_modules/@grpc/grpc-js/build/src/call.js:32:19)
    at Object.onReceiveStatus (/workspace/node_modules/@firebase-function-kits/firestore-bundle-builder/node_modules/@grpc/grpc-js/build/src/client.js:359:73)
    at Object.onReceiveStatus (/workspace/node_modules/@firebase-function-kits/firestore-bundle-builder/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:327:181)
    at /workspace/node_modules/@firebase-function-kits/firestore-bundle-builder/node_modules/@grpc/grpc-js/build/src/resolving-call.js:135:78
    at process.processTicksAndRejections (node:internal/process/task_queues:85:11)

Proposed Fix:

In src/index.ts, declare the required APIs:

import { requiresAPI, requiresRole } from "firebase-functions/v2";

const REQUIRED_APIS = [
  {
    api: "firestore.googleapis.com",
    reason: "Needed to read bundle specifications and documents from Cloud Firestore.",
  },
  {
    api: "storage.googleapis.com",
    reason: "Needed to read and write bundle file caches in Cloud Storage.",
  },
];

for (const { api, reason } of REQUIRED_APIS) {
  requiresAPI(api, reason);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions