Skip to content

Commit e68fc6b

Browse files
committed
add missing billing check
1 parent 1a9e7c1 commit e68fc6b

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎packages/cli/src/utils/billing.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { isBillingEnabled } from '../lib/billing.js';
2+
import type { DoctorCheckResult } from './node-version.js';
3+
4+
const name = 'Blaze plan';
5+
6+
/**
7+
* Warns when the selected Firebase project isn't on the Blaze plan, which
8+
* deploying Cloud Functions requires. Local development with the emulators
9+
* works without it, so this never fails `doctor`.
10+
*/
11+
export const checkBilling = async (
12+
repoRoot: string | undefined,
13+
projectId: string | undefined,
14+
): Promise<DoctorCheckResult> => {
15+
if (!repoRoot || !projectId) {
16+
return { name, ok: true, warning: true, message: 'Skipped, no Firebase project selected.' };
17+
}
18+
19+
try {
20+
if (await isBillingEnabled(repoRoot, projectId)) {
21+
return { name, ok: true, message: `Billing is enabled for ${projectId}.` };
22+
}
23+
return {
24+
name,
25+
ok: true,
26+
warning: true,
27+
message:
28+
`${projectId} is not on the Blaze plan, which deploying Cloud Functions requires. ` +
29+
`Upgrade at https://console.firebase.google.com/project/${projectId}/usage/details ` +
30+
'and set a spend cap (see docs/tutorials/02-firebase.md#billing).',
31+
};
32+
} catch (error) {
33+
const reason = error instanceof Error ? error.message : String(error);
34+
return {
35+
name,
36+
ok: true,
37+
warning: true,
38+
message: `Could not check billing for ${projectId}: ${reason}`,
39+
};
40+
}
41+
};

0 commit comments

Comments
 (0)