---
id: spay4-bo-ui-foundation-contract
status: current
audience: [bo-frontend, backend, qa, operator]
source_documents: [backoffice-menu-api-reference.md, bo-demo-api-coverage-audit.md]
---

# A1／A2 BO UI foundation 接線與驗收

## 結論與範圍

本次只實作本人入口、五種 root 管理 metadata、16 條 additive reads、三個 filters 與 BO formal login IP。**不是 demo 全站完成，也不是已部署。** Department 已接受排除；不新增部門 schema/request/response/filter。B/C/D、frontend、擴權、新角色、金融模型與 readiness gates 不在本次範圍。

舊欄位、owner、排序、count、deleted-row、分頁與 response 包裝保留。共用 VO 的 mutation response 同步 additive 增加顯示欄位，沒有新增 create/update request 的 metadata/IP 欄位。options、JWT claims、LoginResponse、password reset/MFA 語意不變。

## 本人入口

`GET /bo/v2/auth/me`：SUPERADMIN、PREFIX、SUPPLIER、GATEWAY 的有效 formal session。route 宣告 hidden `AUTH_MENU_BOOTSTRAP:VIEW`，catalog 對四種 principal 直接授權、不經 role grant（登入即可），但仍 fresh-check principal、owner chain、session epoch；不代表免除其他 API 的 grant。

- HTTP 200、單層 `ResponseVo<PrincipalSelfVo>`，`Cache-Control: no-store`。
- 無 selector 或 body contract；未知 query（包含 principalId/account 等）回既有 HTTP 400／40005。只能讀本人。
- 不回傳 credential、token、lastLoginIp 或 session internal；GET 不寫任何資料或 audit。
- inactive User/Role、失效 owner chain、expired/revoked JWT、password-change token 拒絕。Supply operational-INACTIVE owner 沿用既有可登入規則，row lifecycle 必須有效。

| 欄位 | 來源／不適用語意 |
| --- | --- |
| principalType / principalId / account | 本人 formal principal realm、UserPrincipal/SupplyAccount identity 與 account |
| displayName | BO User.name；Supply Account.account |
| version | 本人 UserPrincipal.version 或 SupplyAccount.version；**不是 sessionEpoch、Agent/Supplier/Gateway version** |
| agentId / agentPrefix | Prefix owner Agent；其他 realm null |
| supplierId / supplierLoginId / supplierName | Supply owner chain Supplier；BO null |
| gatewayId / gatewayCode / gatewayName | Gateway owner；其他 realm null |
| roleId / roleName | BO Role；Supply null |
| supplyRole | Supplier／Gateway SupplyAccount.role（#738 回填前的舊 Gateway 帳號可能仍為 null）；BO null |

Auth 只透過 Supply service interface 與安全 DTO 取得 Supply projection，不跨 concept 讀 DAO/entity。

**接線鏈：**login → me → 使用 me.version 手動呼叫既有 `PUT /bo/v2/auth/password`。成功仍撤銷全部 session、不發 replacement JWT，須重新登入。409 時重新 me、由使用者重確認，**不可自動 retry**；me 不授與 `RESET_PASSWORD:UPDATE`。

## 16 條既有 reads

metadata 固定為 `creator, createTime, modifier, modifyTime`。時間依 ADR-0409（此參考僅供內部環境使用，公開版本未提供） 輸出 ISO-8601 UTC 帶 `Z`（例 `2026-10-10T03:04:05.120Z`），由 `spay4-bo` 全域 `LocalDateTime` serializer 統一套用。以下 API **保留既有 raw VO／PageVo**，不要額外解 `.data`；只有新 me 使用上述 ResponseVo。既有 options／allocation 的局部 advice 不變。

| GET API | Additive 欄位／filters |
| --- | --- |
| `/bo/v2/agents/page`、`/agents/list` | status、currencyId、currencyCode、metadata；仍僅 Superadmin |
| `/bo/v2/agents/{agentId}`、`/agents/me` | currencyCode、metadata；Prefix 仍需 active AGENT_MANAGEMENT:VIEW，限 own Agent |
| `/bo/v2/access/roles`、`/roles/{roleId}` | metadata；原 grants、owner 與 version 不變 |
| `/bo/v2/access/users`、`/users/{userId}` | metadata、nullable lastLoginIp；list 新增同名 filter |
| `/bo/v2/suppliers`、`/suppliers/{supplierId}` | metadata |
| `/bo/v2/supplyGateways`、`/supplyGateways/{gatewayId}` | metadata；list 新增 supplierId／currencyId filters |
| `/bo/v2/supplierAccounts`、`/supplierAccounts/{accountId}` | gaReady、nullable lastLoginTime |
| `/bo/v2/gatewayAccounts`、`/gatewayAccounts/{accountId}` | gatewayName；既有 gaReady／lastLoginTime 保留 |

- Gateway 新 filters 必須 positive；僅加入 supplied predicates，與 server scope **AND**。跨 scope／不存在的 filter target 都回空頁，不做 target-existence lookup、不洩漏存在性。
- User IP filter：trim 後最多45字元、literal contains；escape `%`、`_` 與 escape character，空白忽略，不支援 CIDR 搜尋。過長回400，不截斷。
- 保留 zero-based pageNumber、pageSize 1..500、既有 count/sort/deleted-row 語意。
- display 由後端 batch owner lookup／currenciesByIds 補足；1與500 rows 的新增 lookup 次數不線性增加。缺失 master 保留 id，display 為 null。
- gaReady 與 Gateway 相同，僅判定 TOTP ciphertext 非 null，不解密、不表示本次 MFA 通過。lastLoginTime 只取 lastSessionIssuedAt，ISO-8601 UTC；temporary challenge 不算登入。

## Metadata 保存

五種 root 為 Agent、Role、UserPrincipal、Supplier、SupplyGateway。映射既有 creator/modifier/time 欄位，不造重複 schema。

- 新建時 creator/modifier 同為 verified actor.account snapshot；onboarding 的 Role/User 同步保存。
- 實際 profile/name、status、Role/grants/assignment、delete、Agent banks/credential、Gateway limits 的管理異動更新 modifier/modifyTime；creator 不覆寫。
- 管理連帶 User session revoke 沿用該次 actor，同 domain mutation/audit 交易；no-op、拒絕、rollback 不更新。
- 登入、失敗計數、IP 更新、allocation/routing/financial background facts 不標成 master 管理異動。
- 無人類 actor 的 bootstrap 保留既有值或 null；未知歷史 metadata 不回補、不推測。
- Gateway modifier 擴至100字元，完整保存合法 Supply account，不截斷。

## Trusted proxy 與登入 IP

`spay4.security.trusted-proxy-cidrs` 預設空清單，可透過 `SPAY4_TRUSTED_PROXY_CIDRS` 提供 comma-separated literal CIDRs。hostname、缺 mask、`/0`、越界 mask、port/zone 等設定在啟動時拒絕。不新增 dependency。

`server.forward-headers-strategy=none` 必須維持，保留 socket peer，不讓 framework 先改寫 remoteAddr；operator 不可覆寫為 native/framework 或另加 forwarded-address filter。

1. peer 不可信：忽略 XFF，使用正規化 peer IP。
2. peer 可信：從 XFF 右側剝除可信 proxies，第一個不可信 hop 為 client；忽略其左側聲稱。
3. 可信 peer 缺 XFF、全鏈可信或任何格式非法：來源 null，登入不因此失敗。
4. literal only，無 DNS；拒絕 hostname、unknown、port、zone、控制字元。合併多行 XFF，上限8 KiB／32 hops；其餘 forwarded headers 忽略。
5. IPv4/IPv6 使用 JDK normalization；IPv4-mapped IPv6 正規化為 IPv4，mapped CIDR 同步換算 mask，禁止有效 IPv4 `/0` 或更廣 trust。

僅 SUPERADMIN/PREFIX **成功發行 formal session 的原登入交易**保存 user.lastLoginIp。失敗不覆寫；未知來源成功保存 null，不能保留舊 IP 冒充最新來源。Supply Account 不保存本次 IP。IP 由 server-only login context 傳入，不加入 LoginRequest、JWT、credential audit 或一般 log。

部署 proxy 必須 append 真實上游 peer（edge 應 overwrite／移除不可信 caller 的 XFF），不得只 pass-through caller header。可信網段由 operator 提供；避免將 client 網段列為 trusted proxy。

## Operator schema／部署 gate

Fresh target 初始化使用 `sql/V4/ddl.sql`（此參考僅供內部環境使用，公開版本未提供），下列兩項已整合；#216 source 核對後已退休舊 manual migration，`BoUiFoundationSchemaIntegrationTest` 直接核對初始化契約，不再重現舊 schema upgrade：

1. `user.last_login_ip VARCHAR(45) NULL`。
2. `supply_gateway.modifier VARCHAR(100) NULL`。

Operator：

1. 確認 target/schema identity、fresh-target 條件、備份及相關 writers，審核 artifact；DDL implicit commit 不能靠 ROLLBACK 還原。
2. 依 SQL README（此參考僅供內部環境使用，公開版本未提供） 完成初始化審核、schema read-back 與受管 seed provisioning；**不使用 force／忽略錯誤**，遇錯立即停止。Source 核對不是實際初始化或 bootstrap 安全驗收。
3. Existing target 升級須另案準備並審核 artifact，不得直接重跑初始化 DDL、清庫或 backfill；不新增 FOREIGN KEY、不使用 ADD COLUMN IF NOT EXISTS。既有資料、version/session/歷史時間的保留須有獨立 read-back 證據。
4. **先新 schema、再新 application**；application 回退保留 additive schema，不 DROP IP 或縮回 modifier。
5. 實際 proxy trusted networks 設定後，用 BO login → me／User projection 驗證真實 IP、偽造 XFF、未知來源及失敗登入不覆寫。沒有 live smoke 證據不宣稱部署完成。

Agent 不連 target、不自動執行 SQL、不 commit/push/部署。

## Postman 與 OpenAPI

- OpenAPI 由 runtime controller/VO annotations 產生；me 僅本人、無 selector，User/Gateway 新 query records 與 additive VO fields 有描述。
- A1/A2 enrichment 工具：`node docs/spay4/tools/update-bo-ui-foundation-postman.mjs`；唯讀同步驗證加 `--check`。後續已由使用者授權全站 inventory 同步，完整重建流程為 generator → A1/A2 enrichment → validator；只同步 source-backed 文件／templates，不變更其他 batches 的業務、permissions 或 readiness。
- 新 optional filters 在 Postman 預設 disabled。me 沒有 body/query，沒有自動保存 version／credential、mutation chaining 或自動 retry；409 由使用者重確認。
- inventory以當前generator／validator逐一比較每個 source method/path、query keys、body templates與unique routes，不硬編「現在」routes/requests數字。Operations另列，非BO transports採exact exclusion；source inventory不是runtime-ready，conditional controllers保留既有gates。唯讀validator結果只適用當次source版本，完整產品驗收另立。

- 已檢視的3條非 BO transports（internal HOUSE ingress、Agent Deposit V1 create/query）明確排除，避免誤套 BO bearer credential；新 namespace 或 alias 不會以 broad prefix 靜默忽略。其專用 HMAC／internal contract 與 gates 不變。
- 可重現重建、fully-qualified annotations、hidden me selector、query records、strict parser allow-list、同數量 route 置換／新增／刪除／重複、未知 body types、BOM／credential／folder-level chaining 均由負向 fixtures 檢查；新增不支援的 mapping aliases 或 method-level RequestMapping 一律 fail closed，不默默少生成 endpoint。

## 現行驗收界線

本人入口、16條read、metadata與trusted proxy已有source切片；舊固定snapshot回歸只證明當時範圍。完整source inputs與當前依賴尚待核對，不把handler、documentation或局部PASS當完整產品驗收。正式權限、no-store、response例外、安全IP與transaction規則仍依上文保留。

規格與後端兩維現況見[各模組](../pages/backoffice-menu-api-progress.html)；跨contract包裝／scope衝突見待決策問題（已移除，見 git 874290e8e）。本文件不授權target/database/proxy操作。
