Brand-new sibling Next.js app at app/investor/ for investor.lux.financial,
mirroring the layout/auth/build idiom of @luxbank/console while moving to
Next 15 + React 19 + Tailwind 4 + TypeScript strict.
Foundation (this commit):
- Edge middleware (src/middleware.ts) — verifies the IAM-issued JWT against
iam.luxfi.io's JWKS via jose, scopes to investorID + tenantID, and
injects X-Lux-* identity headers on every (authed) request.
- Gateway client library (src/lib/gateway/{transport,captable,transfer,
treasury,broker,audit}.ts) — typed REST surface routed through the
operator gateway (api.lux.financial) with investor scope. Zero direct
backend exposure to the browser; non-2xx responses throw GatewayError.
- Shell (src/components/shell/{Shell,Sidebar,TopBar}.tsx) — top bar with
brand + account menu, sidebar with grouped nav across all G-22 routes,
responsive grid layout. Brand interop via @luxbank/brand.
- Shared UI primitives (src/components/{data,forms}/) — Card, DataTable,
Notice, Stat, PageHeader, Button, Select.
- Sign-in/out (src/app/(unauthed)/{signin,signout}/) plus API routes for
OIDC callback and magic-link request.
Stage 10.1 — Account dashboard (src/app/(authed)/dashboard/):
- Portfolio NAV summary card with 24h/7d/30d deltas.
- Positions table per offering with quantity, cost basis, NAV, unrealized
P&L, lockup remaining, restrictions label.
- Cost-basis method toggle (FIFO / LIFO / specific-lot) drives a server
re-fetch via ?method=.
- Pending settlement panel with T+0/T+1/T+2 bucket badges and per-trade
side/price/gross.
- Server-side data fetched in parallel via Promise.allSettled so a
single backend hiccup degrades gracefully.
Stage 10.10 — Audit log (src/app/(authed)/activity/):
- Filterable timeline of investor-initiated actions (auth, document,
trade, withdrawal, profile, beneficiary, kyc, comms).
- Filters: category, outcome, since, until — URL-driven.
- Per-entry: timestamp, action verb, target ref, description, IP, UA,
outcome, optional error.
- CSV export — same-origin /api/audit/export.csv proxies the gateway
endpoint with the caller's identity and streams text/csv back.
Tests (vitest + happy-dom + @testing-library/react) — 29 tests across 8
files, all passing:
- auth/session — header extraction + SessionError surface.
- auth/sign-in-url — OIDC authorize + signout URL construction.
- gateway/transport — URL prefixing, identity-header injection, JSON
body + content-type, 204 handling, GatewayError mapping.
- gateway/audit — CSV row escaping (RFC 4180-aware column counter).
- format — currency / percent / number / date / signClass.
- dashboard — render of PortfolioSummaryCard, PositionsTable,
PendingSettlementsCard against typed fixtures.
- activity — render of AuditTimeline (multiple categories + outcomes).
- middleware — matcher regex shape.
Build: pnpm install + pnpm -F @luxbank/investor build → green; 8 routes
compiled (/, /dashboard, /activity, /signin, /signout,
/api/auth/callback, /api/auth/magic-link, /api/audit/export.csv) +
40 kB middleware bundle.
Contract for other G-22 agents:
- Middleware sets X-Lux-Sub / X-Lux-Investor-Id / X-Lux-Tenant-Id /
X-Lux-Email / X-Lux-Name / X-Lux-Exp on every (authed) request.
Read via headers() in any server component / route handler, or use
the readSessionFromHeaders helper.
- gateway clients are server-only (transport.ts lazy-imports
next/headers). Client components must call through a server action or
API route — never import @/lib/gateway directly in 'use client' files.
- New backend sub-clients append to src/lib/gateway/index.ts; they
reuse callGateway() from transport.ts (one path-prefix per service
→ captable / transfer / treasury / broker / audit). Add the entry
to src/components/shell/Sidebar.tsx for nav.
Source-of-design: Lux-Prior-IP
Source-ref: 96510a0caf
Clean-Team-Member: dev-agent (G-22a foundation + dashboard + audit)
Signed-off-by: dev <[email protected]>
6.8 KiB
@luxbank/investor — Lux Investor Portal
Investor-facing portal for investor.lux.financial. Next.js 15 + React 19 +
Tailwind 4, TypeScript strict mode, deployed to Cloudflare Pages.
Counterpart to the operator console at app.lux.financial (@luxbank/console)
and the marketing site at lux.financial (@luxbank/site). Reads from the
four backend services (luxfi/captable, luxfi/transfer, luxfi/treasury,
luxfi/broker) through the operator gateway — never directly.
What's in here
This portal implements the §10 substages of the Lux RWA / Digital Securities gap analysis (gap G-22). Substage ownership is split across three parallel build agents:
| Stage | Surface | Owner |
|---|---|---|
| 10.1 | Account dashboard (positions, NAV, cost basis, unrealized P&L, pending settlement) | A (foundation) |
| 10.2 | Document vault | B |
| 10.3 | Communications inbox | B |
| 10.4 | Wallet / payment methods | C |
| 10.5 | Secondary market | C |
| 10.6 | Tax documents (1099 / K-1 / 1042-S / cost basis) | B |
| 10.7 | KYC refresh + W-8 renewal | C |
| 10.8 | Beneficial-owner / address change | C |
| 10.9 | Beneficiary / TOD designation | C |
| 10.10 | Audit log (investor-initiated actions) | A (this) |
The foundation — auth middleware, gateway clients, shell, sign-in flow — is owned by agent A and used by all substages.
Architecture
investor.lux.financial (this app)
│
│ 1. browser holds an HTTP-only session cookie containing the
│ JWT issued by Hanzo IAM (iam.luxfi.io)
│
│ 2. src/middleware.ts verifies the JWT (jose + JWKS) and injects
│ X-Lux-Sub / X-Lux-Investor-Id / X-Lux-Tenant-Id headers
│
│ 3. server components call src/lib/gateway/* which proxies through
│ the operator gateway at NEXT_PUBLIC_GATEWAY_URL
│
▼
api.lux.financial (operator gateway)
│
│ enforces tenant + investor scope; signs requests forward
│
▼
┌───────────┬───────────┬────────────┬──────────┐
│ captable │ transfer │ treasury │ broker │
└───────────┴───────────┴────────────┴──────────┘
The browser never sees a backend URL. Every gateway client function in
src/lib/gateway/* builds a request to the gateway and the gateway routes
by URL prefix (/v1/captable/…, /v1/transfer/…, …) with the identity
headers preserved.
Routes
| Path | What |
|---|---|
/ |
Redirect to /dashboard. |
/dashboard |
Positions, NAV, cost basis, unrealized P&L, pending settlements. |
/activity |
Audit-log timeline of investor-initiated actions with CSV export. |
/signin |
OIDC + magic-link sign-in. |
/signout |
Clears the session cookie and bounces to IAM logout. |
/api/auth/callback |
OIDC code-exchange handler. |
/api/auth/magic-link |
Magic-link request handler. |
/api/audit/export.csv |
Proxies the gateway CSV export endpoint. |
Agent B / C own the routes for §10.2–§10.9; they live alongside this in
src/app/(authed)/{documents,inbox,tax,wallet,market,kyc,profile,beneficiary}.
Run
pnpm -F @luxbank/investor dev
# → http://localhost:3002
Static export for Cloudflare Pages:
pnpm -F @luxbank/investor export
pnpm -F @luxbank/investor deploy:cf
Tests
pnpm -F @luxbank/investor test
Vitest + Testing Library + happy-dom. Covers:
auth/session— header-based session extraction and validation.auth/sign-in-url— OIDC authorize / sign-out URL construction.gateway/transport— URL routing, identity-header injection, JSON body handling, error mapping (GatewayError).gateway/audit— CSV row serialization with escape rules.format— currency / percent / number / date formatters.dashboard— render of summary card, positions table, settlements card.activity— render of audit timeline.middleware— matcher configuration.
Environment variables
| Key | Default | Used by |
|---|---|---|
NEXT_PUBLIC_GATEWAY_URL |
https://api.lux.financial |
Browser + server fetch base. |
NEXT_PUBLIC_IAM_URL |
https://iam.luxfi.io |
OIDC authorize / logout URLs. |
NEXT_PUBLIC_IAM_CLIENT_ID |
lux-investor-portal |
OIDC client. |
IAM_AUDIENCE |
lux-investor-portal |
JWT audience claim check. |
IAM_JWKS_URL |
https://iam.luxfi.io/.well-known/jwks.json |
JWT signature verification. |
IAM_ISSUER |
https://iam.luxfi.io |
JWT issuer claim check. |
NEXT_PUBLIC_SESSION_COOKIE |
lux_investor_session |
Session cookie name. |
NEXT_PUBLIC_PORTAL_URL |
https://investor.lux.financial |
Used by sign-out for absolute redirect. |
LUX_BRAND_INLINE |
(unset) | Optional JSON brand override for white-label deploys. |
Secrets (anything not NEXT_PUBLIC_*) flow from KMS into the runtime via
the standard deploy pipeline. Nothing is committed to git.
Auth contract — for other agents working in this app
The middleware sets these headers on every (authed) request; any new page,
server component, or API route can read them via next/headers:
| Header | Meaning |
|---|---|
X-Lux-Sub |
Stable IAM subject ID. |
X-Lux-Investor-Id |
Investor record ID; the gateway scopes data to this. |
X-Lux-Tenant-Id |
Issuer tenant ID. |
X-Lux-Email |
Display email. |
X-Lux-Name |
Display name. |
X-Lux-Exp |
Token expiry (unix seconds). |
Helpers:
import { headers } from 'next/headers';
import { readSessionFromHeaders } from '@/lib/auth';
const session = readSessionFromHeaders(await headers());
Gateway-client contract
import { gateway } from '@/lib/gateway';
const summary = await gateway.captable.portfolioSummary('fifo');
const positions = await gateway.captable.listPositions('fifo');
const pending = await gateway.transfer.listPendingSettlements();
const balances = await gateway.treasury.balances();
const orders = await gateway.broker.listOpenOrders();
const audit = await gateway.audit.list({ category: 'trade' });
Each method returns a typed Promise. Errors throw GatewayError with
{service, status, body, message} for diagnostic logging. No silent
failures, no soft-typed any.
Adding a new sub-client (e.g. wallet, market):
- Create
src/lib/gateway/<name>.tswithexport const <name> = { … }. - Add the import + entry to
src/lib/gateway/index.ts. - Re-use
callGateway()fromtransport.ts. Never callfetchdirectly.
Provenance
This module is built under the Clean-Room Engineering Protocol — see
legal/INDEPENDENT-IMPLEMENTATION-CLEAN-ROOM-PROTOCOL.md. Each commit
carries the provenance trailer required by §4 of that protocol.