- Apps tab: one-click Mint ledger account per app (POST /v1/accounts already existed on Mint; the gap was the UI), db/migrations/0012. - Console is now a real OIDC provider for Rithub (Gitea) SSO: RS256 id_token + self-contained access_token over the authorization-code grant, single-use codes (db/migrations/0013), discovery/jwks/ authorize/token/userinfo routes. A visitor who isn't signed in yet is bounced through existing sign-in and lands back on /oidc/authorize automatically. Gated on RAILYARD_OIDC_SIGNING_KEY/RAILYARD_OIDC_CLIENTS (scripts/gen-oidc-key.mjs generates the former); unset, every /oidc/* route is a clean 503. - Public, numbers-backed /compare/relay-vs-openrouter page with a spend-tier pricing table and a Console-signup CTA using the existing cross-sell attribution bridge. Verified: tsc clean, full `npm test` (167) and `npm run test:bundle` (3) green; a scratch script exercised the OIDC code/token/userinfo flow end to end against real generated RSA keys (found and fixed a missing email_verified claim); `next dev` used to curl every new route live (discovery, jwks, authorize's 400s and sign-in detour, token validation, userinfo auth, the comparison page, the mint-account API).
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
"use client";
|
|
// Mint self-serve account provisioning (backlog item 11): shows the app's
|
|
// billing ledger account id once minted, or a one-click "provision" action
|
|
// when there is none yet — replaces the operator curling Mint's admin API.
|
|
|
|
import { useState } from "react";
|
|
import { CopyIcon, WalletIcon } from "./Icons.tsx";
|
|
|
|
export function AppBillingAccount({ appId, mintAccountId }: { appId: string; mintAccountId: string | null }) {
|
|
const [id, setId] = useState(mintAccountId);
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
async function provision() {
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
const res = await fetch(`/api/apps/${appId}/mint-account`, { method: "POST" });
|
|
const body = (await res.json()) as { mint_account_id?: string; error?: string };
|
|
if (!res.ok || !body.mint_account_id) setError(body.error ?? "Could not provision a billing account.");
|
|
else setId(body.mint_account_id);
|
|
} catch {
|
|
setError("Could not reach Railyard. Check your connection.");
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
if (id) {
|
|
return (
|
|
<span className="row" style={{ gap: 6 }}>
|
|
<WalletIcon />
|
|
<code className="muted" title="Mint billing account id -- paste into this app's RAILYARD_MINT_ACCOUNT_ID / mint_account_id setting">
|
|
{id}
|
|
</code>
|
|
<button
|
|
className="icon"
|
|
type="button"
|
|
aria-label="Copy billing account id"
|
|
title="Copy"
|
|
onClick={() => navigator.clipboard?.writeText(id).then(() => setCopied(true), () => setCopied(false))}
|
|
>
|
|
<CopyIcon />
|
|
</button>
|
|
{copied ? <span className="muted">Copied</span> : null}
|
|
</span>
|
|
);
|
|
}
|
|
return (
|
|
<span className="row" style={{ gap: 6 }}>
|
|
<button className="icon" type="button" aria-label="Provision billing account" title="Create a Mint billing account for this app" onClick={provision} disabled={busy}>
|
|
<WalletIcon />
|
|
</button>
|
|
<span className="muted">{busy ? "Provisioning" : "No billing account yet"}</span>
|
|
{error ? <span className="error">{error}</span> : null}
|
|
</span>
|
|
);
|
|
}
|