Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
# OpenSpec Change: enterprise-gaming-api-plugin-bank
- **Change ID**: enterprise-gaming-api-plugin-bank
- **Package**: `@suaveplan/api-plugin-bank`
- **Category**: gaming/server
- **Target path**: `gaming/server/api-plugin-bank`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-bank.md`
---
## Summary
Deliver `@suaveplan/api-plugin-bank` on the genesis branch from scratch at enterprise quality. The package is a game-oriented virtual-currency bank built on top of `@suaveplan/economy`. It adds per-account-type interest accrual (`savingsInterestRate` vs. `currentInterestRate`), configurable currency code (default `"GOLD"`), transfer support, and deposit/withdrawal tracking with a full transaction audit trail. Four Hono route groups expose HTTP endpoints: `/accounts`, `/interest`, `/transactions`, `/config`. A `GameBankService` and `InterestService` are registered as plugin services. Genesis adds Zod request/response schemas, structured errors, OTel route instrumentation, and 100% coverage.
---
## Current-state audit (genesis)
Package does not exist on genesis yet — fresh build.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/error` (`workspace:^`) | `BankError`; `BANK.*` codes |
| `@suaveplan/types` (`workspace:^`) | `Clock` |
| `@suaveplan/economy` (`workspace:^`) | `Wallet` for balance management |
| `@suaveplan/events` (`workspace:^`) | `bank:deposit`, `bank:withdrawal`, `bank:transfer`, `bank:interest` events |
| `zod` (`catalog:forms`) | Request/response schemas |
| `@opentelemetry/api` (`catalog:observability`) | Route span instrumentation |
---
## Public API surface
```ts
type AccountType = 'current' | 'savings'
interface BankAccount {
id: string
playerId: string
type: AccountType
balance: number
currency: string
createdAt: number
lastInterestAt: number
}
interface BankTransaction {
id: string
accountId: string
type: 'deposit' | 'withdrawal' | 'transfer' | 'interest'
amount: number
currency: string
description?: string
timestamp: number
}
function createGameBankService(options: BankServiceOptions): GameBankService
interface BankServiceOptions {
currency?: string
savingsInterestRate?: number // per day, e.g. 0.005
currentInterestRate?: number
clock?: Clock
}
interface GameBankService {
openAccount(playerId: string, type: AccountType): BankAccount
getAccount(accountId: string): BankAccount | undefined
listAccounts(playerId: string): BankAccount[]
deposit(accountId: string, amount: number, description?: string): BankTransaction
withdraw(accountId: string, amount: number, description?: string): BankTransaction
transfer(fromId: string, toId: string, amount: number): [BankTransaction, BankTransaction]
listTransactions(accountId: string, limit?: number): BankTransaction[]
}
function createInterestService(bank: GameBankService, clock?: Clock): InterestService
interface InterestService {
accrueAll(): void
tick(dt: number): void // daily accrual on interval
}
// Hono plugin
function bankPlugin(options: BankPluginOptions): HonoPlugin
```
### Error codes
```ts
type BankErrorCode =
| 'BANK_ACCOUNT_NOT_FOUND'
| 'BANK_INSUFFICIENT_FUNDS'
| 'BANK_ACCOUNT_LIMIT'
| 'BANK_INVALID_AMOUNT'
| 'BANK_TRANSFER_FAILED'
```
---
## File layout
```text
gaming/server/api-plugin-bank/
package.json
tsconfig.json
vitest.config.ts
src/
index.ts
error-codes.ts
constants/index.ts
types/common.ts
types/common.md
services/
game-bank-service/
game-bank-service.ts
game-bank-service.md
game-bank-service.types.ts
game-bank-service.test.ts
index.ts
interest-service/
interest-service.ts
interest-service.md
interest-service.types.ts
interest-service.test.ts
index.ts
routes/
accounts.ts
accounts.md
interest.ts
transactions.ts
config.ts
plugin.ts
plugin.md
tests/
integration.test.ts
```
---
## Impact
**Downstream**: `@suaveplan/react-bank` and `@suaveplan/api-plugin-virtual-currency` build on this. Prerequisites: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/economy`, `@suaveplan/events`.

View File

@@ -0,0 +1,52 @@
# Tasks: enterprise-gaming-api-plugin-bank
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## Phase 1 — Scaffold
- [ ] Create `gaming/server/api-plugin-bank/` (`@suaveplan/api-plugin-bank`, `0.1.0`, `sideEffects: false`)
- [ ] `tsconfig.json`, `vitest.config.ts`
## Phase 2 — Error codes & constants
- [ ] `src/error-codes.ts` + `src/constants/index.ts` — `DEFAULT_CURRENCY`, interest rate defaults
## Phase 3 — Types
- [ ] `src/types/common.ts` + `common.md`
## Phase 4 — Game bank service
- [ ] `src/services/game-bank-service/game-bank-service.ts` — openAccount/deposit/withdraw/transfer/list, in-memory store, OTel
- [ ] Tests + docs
## Phase 5 — Interest service
- [ ] `src/services/interest-service/interest-service.ts` — accrueAll, daily timer tick
- [ ] Tests + docs
## Phase 6 — Hono routes
- [ ] `src/routes/accounts.ts` — GET/POST /accounts, GET /accounts/:id
- [ ] `src/routes/interest.ts` — POST /interest/accrue
- [ ] `src/routes/transactions.ts` — GET /accounts/:id/transactions
- [ ] `src/routes/config.ts` — GET/PUT /config
## Phase 7 — Plugin wiring
- [ ] `src/plugin.ts` — `bankPlugin()` factory, service registration
- [ ] Docs
## Phase 8 — Integration tests
- [ ] `tests/integration.test.ts` — HTTP round-trips for all routes using Hono test client
## Phase 9 — Pre-publish gate
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-bank` green
- [ ] 100% coverage
- [ ] Publish: `bun scripts/publish.ts --package @suaveplan/api-plugin-bank`