feat(api): add customer accounts with live summary and append-only ledger

One balance row per (user, kind, currency): available and frozen carry the
platform base currency, points carries none. Monetary and points rows use
separate partial unique indexes because a plain UNIQUE lets NULL repeat.

Balance changes go through transactional primitives that debits guard with a
conditional update, credits add atomically, and freeze/release move both sides
in one transaction after locking rows by primary key. Every change appends an
immutable entry holding its resulting balance. Registration and a migration
backfill create the zero rows; GET /api/me/stats is the only public surface and
no endpoint mutates a balance.

The mall buyer center and points page drop the USER_STATS fixture for the
shared contract; the fixture stays exported so the fixed-data adapter can still
serve the account domain as a rollback path.

Implements openspec change add-customer-accounts.
This commit is contained in:
2026-09-18 11:54:53 +00:00
parent bcd97ab48f
commit 7a2745fb16
19 changed files with 818 additions and 21 deletions
+9
View File
@@ -4,6 +4,7 @@
import { ApiError } from "@vmall/shared";
import type {
AccountSummary,
Address,
AddressBookEntry,
AddressInput,
@@ -30,6 +31,7 @@ import {
MOCK_QUICK_LINKS,
MOCK_STORES,
MOCK_USER,
USER_STATS,
MOCK_ADDRESSES,
defaultAddress,
mockConvertMinor,
@@ -179,6 +181,13 @@ export function createMockApi(): ApiClient {
register: () => Promise.resolve(tokens()),
login: () => Promise.resolve(tokens()),
me: (): Promise<User> => Promise.resolve(MOCK_USER),
getAccountSummary: (): Promise<AccountSummary> =>
Promise.resolve({
balance_minor: USER_STATS.balanceMinor,
frozen_minor: USER_STATS.frozenMinor,
currency: BASE_CURRENCY,
points: USER_STATS.points,
}),
listProducts: (q = {}) =>
Promise.resolve(