Skip to content

Functions can declare dependencies on additional APIs - #10621

Merged
inlined merged 10 commits into
mainfrom
add-requires-api-feature
Jun 12, 2026
Merged

inlined merged 10 commits into
mainfrom
add-requires-api-feature

Conversation

@inlined

@inlined inlined commented Jun 10, 2026

Copy link
Copy Markdown
Member

Description

Updates ensureAllRequiredAPIsEnabled during function deployment to check manifest-required APIs against a built-in allowlist of standard Firebase APIs. For any additional APIs, it prompts the user to enable them if they are currently disabled.

Scenarios Tested

  • CLI unit tests verify prompting logic (presented when additional APIs are missing, not presented otherwise).
  • Verified that --force confirms and nonInteractive without --force aborts.

@inlined
inlined requested a review from wandamora June 10, 2026 20:29

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a prompt to ask users to enable non-standard Google Cloud APIs during function deployments. It partitions required APIs into standard and additional ones, checks if additional APIs are enabled, prompts the user to enable them if they are disabled, and throws a FirebaseError if they decline. The feedback suggests making the options parameter in ensureAllRequiredAPIsEnabled optional with a default value of {} to prevent runtime crashes, safely handling wantBackend.requiredAPIs with nullish coalescing, and simplifying the filtering of missing APIs using additionalApis.filter((_, i) => !checks[i]) which also allows removing the unused zip import.

Comment thread src/deploy/functions/prepare.ts Resolved
Comment thread src/deploy/functions/prepare.ts Outdated
export async function ensureAllRequiredAPIsEnabled(
projectNumber: string,
wantBackend: backend.Backend,
options: { force?: boolean; nonInteractive?: boolean },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential runtime crashes if options is omitted by other callers or in future refactors, make the options parameter optional by defaulting to {}.

Suggested change
options: { force?: boolean; nonInteractive?: boolean },
options: { force?: boolean; nonInteractive?: boolean } = {},

Comment thread src/deploy/functions/prepare.ts Outdated
"cloudtasks.googleapis.com",
];

const requiredApis = Object.values(wantBackend.requiredAPIs);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To adhere to defensive programming practices, safely handle cases where wantBackend.requiredAPIs might be undefined or null by using the nullish coalescing operator (??).

Suggested change
const requiredApis = Object.values(wantBackend.requiredAPIs);
const requiredApis = Object.values(wantBackend.requiredAPIs ?? {});

Comment thread src/deploy/functions/prepare.ts Resolved
inlined added 2 commits June 10, 2026 23:52
Updates `ensureAllRequiredAPIsEnabled` during function deployment to check manifest-required APIs against a built-in allowlist of standard Firebase APIs. For any additional APIs, it prompts the user to enable them if they are currently disabled.

- CLI unit tests verify prompting logic (presented when additional APIs are missing, not presented otherwise).
- Verified that `--force` confirms and `nonInteractive` without `--force` aborts.
- Removed unused `zip` import.
- Added defensive nullish coalescing to `wantBackend.requiredAPIs` access.
- Simplified `missingApis` filter logic using the array index.
@inlined
inlined force-pushed the add-requires-api-feature branch from c121cae to c8b9294 Compare June 10, 2026 23:53
Comment thread src/deploy/functions/prepare.ts Outdated
wantBackend: backend.Backend,
options: { force?: boolean; nonInteractive?: boolean } = {},
): Promise<void> {
const STANDARD_APIS = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this list come from?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I see, thanks. On this note, would this be better as a global constant?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll do that and add a comment.

@inlined
inlined enabled auto-merge (squash) June 12, 2026 23:22
@inlined
inlined merged commit b3be593 into main Jun 12, 2026
46 of 47 checks passed
@inlined
inlined deleted the add-requires-api-feature branch June 12, 2026 23:29
bkendall pushed a commit that referenced this pull request Jul 9, 2026
* feat: Prompt for non-standard required APIs

Updates `ensureAllRequiredAPIsEnabled` during function deployment to check manifest-required APIs against a built-in allowlist of standard Firebase APIs. For any additional APIs, it prompts the user to enable them if they are currently disabled.

- CLI unit tests verify prompting logic (presented when additional APIs are missing, not presented otherwise).
- Verified that `--force` confirms and `nonInteractive` without `--force` aborts.

* fix: Address code review feedback

- Removed unused `zip` import.
- Added defensive nullish coalescing to `wantBackend.requiredAPIs` access.
- Simplified `missingApis` filter logic using the array index.

* style: Auto-format files

* docs: Update JSDoc for ensureAllRequiredAPIsEnabled

* docs: Add explanatory comment for STANDARD_APIS allowlist

* docs: Expand explanatory comment for STANDARD_APIS allowlist

* refactor: Move STANDARD_APIS to top-level constant and accept optional Backend spec
bkendall pushed a commit that referenced this pull request Jul 9, 2026
* feat: Prompt for non-standard required APIs

Updates `ensureAllRequiredAPIsEnabled` during function deployment to check manifest-required APIs against a built-in allowlist of standard Firebase APIs. For any additional APIs, it prompts the user to enable them if they are currently disabled.

- CLI unit tests verify prompting logic (presented when additional APIs are missing, not presented otherwise).
- Verified that `--force` confirms and `nonInteractive` without `--force` aborts.

* fix: Address code review feedback

- Removed unused `zip` import.
- Added defensive nullish coalescing to `wantBackend.requiredAPIs` access.
- Simplified `missingApis` filter logic using the array index.

* style: Auto-format files

* docs: Update JSDoc for ensureAllRequiredAPIsEnabled

* docs: Add explanatory comment for STANDARD_APIS allowlist

* docs: Expand explanatory comment for STANDARD_APIS allowlist

* refactor: Move STANDARD_APIS to top-level constant and accept optional Backend spec
yuichi0301 pushed a commit to yuichi0301/firebase-tools that referenced this pull request Aug 16, 2026
* feat: Prompt for non-standard required APIs

Updates `ensureAllRequiredAPIsEnabled` during function deployment to check manifest-required APIs against a built-in allowlist of standard Firebase APIs. For any additional APIs, it prompts the user to enable them if they are currently disabled.

- CLI unit tests verify prompting logic (presented when additional APIs are missing, not presented otherwise).
- Verified that `--force` confirms and `nonInteractive` without `--force` aborts.

* fix: Address code review feedback

- Removed unused `zip` import.
- Added defensive nullish coalescing to `wantBackend.requiredAPIs` access.
- Simplified `missingApis` filter logic using the array index.

* style: Auto-format files

* docs: Update JSDoc for ensureAllRequiredAPIsEnabled

* docs: Add explanatory comment for STANDARD_APIS allowlist

* docs: Expand explanatory comment for STANDARD_APIS allowlist

* refactor: Move STANDARD_APIS to top-level constant and accept optional Backend spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants