ration/proto/gateway.proto
caelum0x c3236f0bca feat(card-issuance,gateway,cli): add CloseCard — issued cards could never be shut off
CARD_STATUS_SUSPENDED/CLOSED have existed in common.proto since the
original build, and the Airwallex client package even defined
CardStatusSuspended/CardStatusClosed constants, but nothing in this
repo ever transitioned a stored card into either state: card-issuance's
airwallex.Client interface only exposed IssueCard/GetCard/
SetCardControls (limit/controls only, never status), so a leaked
credential, an offboarded cardholder's card, or any card that should
stop spending forever had no real operator path to close — only
"adjust-limit" to a smaller (but still nonzero-possible, still active)
limit.

Adds card_issuance.proto/gateway.proto's CloseCard RPC, a real
airwallex.Client.CloseCard on both Mock and Live (POST
/api/v1/issuing/cards/{id}/close), cardsvc.Service.CloseCard (releases
the card's full remaining ledger HOLD back to the tenant's available
balance, idempotent on an already-closed card), the gateway fan-out,
and `ration card close --card <id>`. AdjustCardLimit now rejects a
closed card instead of silently reopening a zombie hold.

tenantauth/ratelimit needed zero changes: both resolve card_id via
reflection, so CloseCardRequest's card_id field is automatically
tenant-scoped and rate-limited the same way GetCard/AdjustCardLimit
already are.

Verified live against the real bare-metal 7-service stack
(scripts/run-demo.sh): issued a real card (Held 1,000.00 USD), closed
it (status CLOSED, Held back to 0.00, Available back to 7,500.00),
re-closed it (idempotent — Available unchanged, no double-release),
confirmed adjust-limit on the closed card is rejected, and confirmed
closing an unknown card_id surfaces the same NotFound-wrapped error
GetCard/AdjustCardLimit already do. verify-chain: intact (5 records).
`go build`/`go vet` clean across every Go module (gateway,
card-issuance, cli, tui, auth, tenant-registry, webhook-ingestion,
agent, audit-log, sdk/go/ration), full `make build` (Rust+Go+SDK)
clean, 0 regressions.
2026-10-29 11:35:23 +03:00

164 lines
5.0 KiB
Protocol Buffer

syntax = "proto3";
package ration.gateway.v1;
import "common.proto";
option go_package = "github.com/caelum0x/ration/pkg/pb/gateway";
// Gateway is the Go service that owns the Airwallex integration
// (Issuing API, Global Accounts, webhooks) and fronts LedgerCore for
// the TUI, CLI and Agent. It never stores money state itself — every
// balance-affecting call is proxied to LedgerCore so there is one
// source of truth.
service Gateway {
rpc IssueCard(IssueCardRequest) returns (Card);
rpc AdjustCardLimit(AdjustCardLimitRequest) returns (Card);
rpc GetCard(GetCardRequest) returns (Card);
rpc ListCards(ListCardsRequest) returns (ListCardsResponse);
// CloseCard permanently closes a card — see card_issuance.proto's
// identical RPC, which this is a direct fan-out to (docs/adr/0004).
rpc CloseCard(CloseCardRequest) returns (Card);
rpc RationBridgeFunding(RationBridgeFundingRequest) returns (RationBridgeFundingResponse);
rpc SimulateDeposit(SimulateDepositRequest) returns (SimulateDepositResponse);
rpc StreamActivity(StreamActivityRequest) returns (stream ActivityEvent);
// GetDashboardSnapshot is the one aggregate read the judge-facing web
// dashboard (services/gateway/internal/httpapi's "/v1/dashboard"
// routes) polls: every tenant's reserve-floor headroom in one round
// trip, plus the most recent agent decisions (rationale and
// policy_snapshot_json included) across every tenant, newest first.
// Nothing here is new business logic — it's the same ListTenants/
// GetBalance/CheckReserveFloor/ListAgentDecisions data
// services/tui/internal/client already fetches per-tenant over
// separate gRPC calls, aggregated server-side into one response so a
// browser polling this endpoint doesn't need N+1 round trips per
// refresh.
rpc GetDashboardSnapshot(GetDashboardSnapshotRequest) returns (GetDashboardSnapshotResponse);
}
message Card {
string id = 1;
string tenant_id = 2;
string airwallex_card_id = 3;
string cardholder_name = 4;
ration.common.v1.CardStatus status = 5;
int64 limit_minor_units = 6;
string limit_interval = 7; // "daily" | "monthly"
string currency = 8;
int64 created_at_unix = 9;
}
message IssueCardRequest {
string tenant_id = 1;
string cardholder_name = 2;
int64 limit_minor_units = 3;
string limit_interval = 4;
string currency = 5;
}
message AdjustCardLimitRequest {
string card_id = 1;
int64 new_limit_minor_units = 2;
string reason = 3;
}
message GetCardRequest {
string card_id = 1;
}
message CloseCardRequest {
string card_id = 1;
}
message ListCardsRequest {
string tenant_id = 1;
}
message ListCardsResponse {
repeated Card cards = 1;
}
message RationBridgeFundingRequest {
string tenant_id = 1;
int64 requested_minor_units = 2;
string reason = 3;
}
message RationBridgeFundingResponse {
int64 granted_minor_units = 1;
bool fully_granted = 2;
string explanation = 3;
}
message SimulateDepositRequest {
string tenant_id = 1;
int64 amount_minor_units = 2;
int64 expected_at_unix = 3;
bool mark_late = 4; // if true, created already past expected_at_unix
}
message SimulateDepositResponse {
string deposit_id = 1;
}
message StreamActivityRequest {
string tenant_id = 1; // empty = all tenants
}
message ActivityEvent {
string id = 1;
string tenant_id = 2;
string kind = 3; // "deposit", "card", "agent_decision", "ledger_entry"
string summary = 4;
int64 at_unix = 5;
}
message GetDashboardSnapshotRequest {
// decisions_per_tenant bounds how many of each tenant's most recent
// agent decisions are fetched before merging and sorting across
// tenants (see services/tui's identical decisionsPerTenant constant
// for the same demo-scale rationale). 0 = server default (20).
int32 decisions_per_tenant = 1;
// max_decisions bounds the total size of recent_decisions after
// merging across every tenant. 0 = server default (50).
int32 max_decisions = 2;
}
message TenantSnapshot {
string tenant_id = 1;
string tenant_name = 2;
string currency = 3;
int64 reserve_floor_minor_units = 4;
int64 available_minor_units = 5;
int64 held_minor_units = 6;
// headroom_minor_units is available_minor_units - reserve_floor_minor_units
// (ration.ledger.v1's CheckReserveFloor RPC, the exact same number
// every bridge-funding decision is gated on) — never recomputed
// client-side from the other two fields, so the dashboard can never
// silently drift from the authoritative definition if that math ever
// changes.
int64 headroom_minor_units = 7;
}
message AgentDecisionSummary {
string tenant_id = 1;
string tenant_name = 2;
string trigger = 3;
ration.common.v1.AgentAction action = 4;
string rationale = 5;
string policy_snapshot_json = 6;
int64 created_at_unix = 7;
}
message GetDashboardSnapshotResponse {
repeated TenantSnapshot tenants = 1;
// recent_decisions is sorted newest first, merged across every
// tenant and capped at the request's max_decisions.
repeated AgentDecisionSummary recent_decisions = 2;
}