Repository navigation
Functions can declare dependencies on additional APIs - #10621
Conversation
There was a problem hiding this comment.
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.
| export async function ensureAllRequiredAPIsEnabled( | ||
| projectNumber: string, | ||
| wantBackend: backend.Backend, | ||
| options: { force?: boolean; nonInteractive?: boolean }, |
There was a problem hiding this comment.
| "cloudtasks.googleapis.com", | ||
| ]; | ||
|
|
||
| const requiredApis = Object.values(wantBackend.requiredAPIs); |
There was a problem hiding this comment.
To adhere to defensive programming practices, safely handle cases where wantBackend.requiredAPIs might be undefined or null by using the nullish coalescing operator (??).
| const requiredApis = Object.values(wantBackend.requiredAPIs); | |
| const requiredApis = Object.values(wantBackend.requiredAPIs ?? {}); |
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.
c121cae to
c8b9294
Compare
| wantBackend: backend.Backend, | ||
| options: { force?: boolean; nonInteractive?: boolean } = {}, | ||
| ): Promise<void> { | ||
| const STANDARD_APIS = [ |
There was a problem hiding this comment.
Where does this list come from?
There was a problem hiding this comment.
OK I see, thanks. On this note, would this be better as a global constant?
There was a problem hiding this comment.
Yeah, I'll do that and add a comment.
* 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
* 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
* 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
Description
Updates
ensureAllRequiredAPIsEnabledduring 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
--forceconfirms andnonInteractivewithout--forceaborts.