135 lines · 5.2 KB
import { createServerFn } from "@tanstack/react-start";
import { viewerMiddleware } from "./middleware";
import { all, first } from "~/server/db";
import { accountDb } from "~/server/scoped-db";
import { periodOf } from "~/server/metering/record";
import { billingSettings, planBlock, withinSpendingLimit } from "~/server/metering/quota";
import { stripeEnabled } from "~/server/billing/config";
import { secondFactorMethods } from "~/server/two-factor";
import { meterDef } from "~/lib/meters";
import type { MeterId } from "~/lib/meters";
import { rateLabel } from "~/lib/pricing-display";
import { disabledNotice, disabledOrgsOf } from "~/server/account-disable";
import { canWriteAsViewer } from "~/lib/email-verification";

const MAXED = 100;
const MAX_NOTICES = 4;

export type QuotaNotice = {
  kind: "quota";
  id: string;
  accountName: string;
  accountKind: "user" | "org";
  billingPath: string;
  meter: string;
  meterLabel: string;
  rate: string | null;
  period: string;
  plan: string;
  /** Spending-limit notices name the limit, not a meter. */
  spend: boolean;
  canUpgrade: boolean;
};

export type SecurityNotice = { kind: "mfa"; id: string };

/** A verified account with no live personal access token cannot push or use the API yet. */
export type TokenNotice = { kind: "tokens"; id: string };

export type DisabledOrgNotice = {
  kind: "disabled";