UNPKG

convex

Version:

Client for the Convex Cloud

68 lines (67 loc) 2.21 kB
"use strict"; import chalk from "chalk"; import { logWarning } from "../../bundler/context.js"; import { teamDashboardUrl } from "../dashboard.js"; import { fetchTeamAndProject } from "./api.js"; import { bigBrainAPI, getAuthHeaderForBigBrain, getConfiguredDeploymentName, getConfiguredDeploymentOrCrash } from "./utils/utils.js"; async function warn(ctx, title, subtitle) { const configuredDeployment = await getConfiguredDeploymentOrCrash(ctx); const { team } = await fetchTeamAndProject(ctx, configuredDeployment); logWarning(ctx, chalk.bold.yellow(title)); logWarning(ctx, chalk.yellow(subtitle)); logWarning( ctx, chalk.yellow(`Visit ${teamDashboardUrl(team)} to learn more.`) ); } async function teamUsageState(ctx) { const configuredDeployment = await getConfiguredDeploymentName(ctx); if (configuredDeployment === null) { return null; } const { teamId } = await fetchTeamAndProject(ctx, configuredDeployment); const { usageState } = await bigBrainAPI({ ctx, method: "GET", url: "dashboard/teams/" + teamId + "/usage/team_usage_state" }); return usageState; } export async function usageStateWarning(ctx) { const authHeader = await getAuthHeaderForBigBrain(ctx); if (authHeader === null) { return; } const usageState = await teamUsageState(ctx); if (usageState === "Approaching") { await warn( ctx, "Your projects are approaching the Starter plan limits.", "Consider upgrading to avoid service interruption." ); } else if (usageState === "Exceeded") { await warn( ctx, "Your projects are above the Starter plan limits.", "Decrease your usage or upgrade to avoid service interruption." ); } else if (usageState === "Disabled") { await warn( ctx, "Your projects are disabled because the team exceeded Starter plan limits.", "Decrease your usage or upgrade to reenable your projects." ); } else if (usageState === "Paused") { await warn( ctx, "Your projects are disabled because the team previously exceeded Starter plan limits.", "Restore your projects by going to the dashboard." ); } } //# sourceMappingURL=usage.js.map