UNPKG

convex

Version:

Client for the Convex Cloud

95 lines (94 loc) 3.88 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var usage_exports = {}; __export(usage_exports, { usageStateWarning: () => usageStateWarning }); module.exports = __toCommonJS(usage_exports); var import_chalk = __toESM(require("chalk"), 1); var import_context = require("../../bundler/context.js"); var import_dashboard = require("../dashboard.js"); var import_api = require("./api.js"); var import_utils = require("./utils/utils.js"); async function warn(ctx, title, subtitle) { const configuredDeployment = await (0, import_utils.getConfiguredDeploymentOrCrash)(ctx); const { team } = await (0, import_api.fetchTeamAndProject)(ctx, configuredDeployment); (0, import_context.logWarning)(ctx, import_chalk.default.bold.yellow(title)); (0, import_context.logWarning)(ctx, import_chalk.default.yellow(subtitle)); (0, import_context.logWarning)( ctx, import_chalk.default.yellow(`Visit ${(0, import_dashboard.teamDashboardUrl)(team)} to learn more.`) ); } async function teamUsageState(ctx) { const configuredDeployment = await (0, import_utils.getConfiguredDeploymentName)(ctx); if (configuredDeployment === null) { return null; } const { teamId } = await (0, import_api.fetchTeamAndProject)(ctx, configuredDeployment); const { usageState } = await (0, import_utils.bigBrainAPI)({ ctx, method: "GET", url: "dashboard/teams/" + teamId + "/usage/team_usage_state" }); return usageState; } async function usageStateWarning(ctx) { const authHeader = await (0, import_utils.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