Pre-stamp prepaid balance check in Sign in with Verae (DEC-658): refuse before stamping when the price exceeds available credits (offer top-up), show included credits and balance after; balance re-read before every stamp. Live on mcp.verae.ai 2026-10-10 16:28 ET (backup site-P-20261010T202836Z)

This commit is contained in:
Grok Bot 2026-10-10 16:33:13 -04:00
commit 3cacdc36d4

View file

@ -121,6 +121,7 @@ export function mountSignIn(host, opts = {}) {
line.textContent = "Signed in as " + (acct.email || acct.name || acct.customer_id) +
" · price per new document " + (acct.stamp_price_credits == null ? "n/a" : fmt(acct.stamp_price_credits)) +
" · balance " + fmt(acct.balance_credits) +
(typeof acct.included_left_credits === "number" && acct.included_left_credits > 0 ? " (+" + fmt(acct.included_left_credits) + " included this month)" : "") +
" · this month " + fmt(acct.period_spend_credits);
} else if (!pending) {
line.textContent = "Checking and looking up documents is free and needs no account. Registering a new document needs a Verae account; it is charged to that account.";
@ -160,7 +161,8 @@ export function mountSignIn(host, opts = {}) {
return {
account: () => acct,
refresh,
async ensureSignedIn() { return acct || (await refresh()) || start(); },
// DEC-658: always re-read the balance right before a stamp (pre-stamp balance check)
async ensureSignedIn() { return (currentKey() && (await refresh())) || start(); },
};
}
@ -168,9 +170,22 @@ export function mountSignIn(host, opts = {}) {
export function confirmCharge(acct, count, scope = "global") {
const price = scope !== "global" ? 0 : (acct && typeof acct.stamp_price_credits === "number" ? acct.stamp_price_credits : null);
const total = price == null ? null : price * count;
const bal = (acct && acct.balance_credits) || 0;
const inc = acct && typeof acct.included_left_credits === "number" ? acct.included_left_credits : null;
const avail = acct && typeof acct.available_credits === "number" ? acct.available_credits : null;
// DEC-658 pre-stamp balance check: stamps debit the prepaid balance (after this month's included credits)
if (total != null && total > 0 && avail != null && total > avail) {
const msg = "Not enough credits to register " + count + " new document" + (count === 1 ? "" : "s") + ".\n\n" +
"Price: " + total + " credits\nAvailable: " + avail + " credits (balance " + bal +
(inc ? ", " + inc + " included this month" : "") + ")\n\nNothing was stamped or charged. Add funds to your Verae account now?";
if (window.confirm(msg)) window.open((acct && acct.top_up_url) || "https://zap.verae.ai/portal/", "_blank", "noopener");
return false;
}
const after = total == null ? null : Math.max(0, bal - Math.max(0, total - (inc || 0)));
const msg = "Register " + count + " new document" + (count === 1 ? "" : "s") + " with Verae?\n\n" +
(price == null ? "Price: see your Verae plan" : ("Price: " + price + " credits each, " + total + " credits in total")) +
"\nBalance: " + ((acct && acct.balance_credits) || 0) + " credits" +
"\nBalance: " + bal + " credits" + (inc ? " (+" + inc + " included this month, used first)" : "") +
(after == null ? "" : "\nBalance after: " + after + " credits") +
"\nCharged to: " + ((acct && (acct.email || acct.name || acct.customer_id)) || "your Verae account") +
"\n\nDocuments already registered are not charged again.";
return window.confirm(msg);