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,83 @@
# OpenSpec Change: enterprise-gaming-api-plugin-virtual-currency
- **Change ID**: enterprise-gaming-api-plugin-virtual-currency
- **Package**: `@suaveplan/api-plugin-virtual-currency`
- **Category**: gaming/server
- **Target path**: `gaming/server/api-plugin-virtual-currency`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-virtual-currency.md`
---
## Summary
Deliver `@suaveplan/api-plugin-virtual-currency` on the genesis branch from scratch at enterprise quality. The package provides virtual currency wallets, transfers, premium purchases, and cashout. A `VirtualCurrencyService` manages per-player multi-wallet balances, a `PurchaseService` handles real-money-to-VC conversion (injectable payment gateway), and a `CashoutService` manages VC-to-reward conversion with configurable rate and daily limits. HTTP routes expose wallet, purchase, cashout, and transfer endpoints. Genesis adds Zod schemas, structured errors, OTel transaction counters, injectable clock, 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:^`) | `VCError`; `VC.*` codes |
| `@suaveplan/types` (`workspace:^`) | `Clock` |
| `@suaveplan/economy` (`workspace:^`) | `Wallet` for VC balance |
| `@suaveplan/events` (`workspace:^`) | `vc:purchase`, `vc:transfer`, `vc:cashout` events |
| `zod` (`catalog:forms`) | Request schemas |
| `@opentelemetry/api` (`catalog:observability`) | Transaction counter |
---
## HTTP Routes
| Method | Path | Description |
|---|---|---|
| `GET` | `/wallets/:playerId` | Get VC balance |
| `POST` | `/wallets/:playerId/purchase` | Buy VC with real money |
| `POST` | `/wallets/:playerId/transfer` | Transfer VC to player |
| `POST` | `/wallets/:playerId/cashout` | Convert VC to rewards |
| `GET` | `/wallets/:playerId/history` | Transaction history |
| `GET` | `/config` | Rates and limits |
---
## File layout
```text
gaming/server/api-plugin-virtual-currency/
package.json
tsconfig.json
vitest.config.ts
src/
index.ts
error-codes.ts
types/common.ts
types/common.md
services/
vc-service/
vc-service.ts
vc-service.md
vc-service.types.ts
vc-service.test.ts
index.ts
routes/
wallets.ts
wallets.md
plugin.ts
plugin.md
tests/
integration.test.ts
```
---
## Impact
**Downstream**: `@suaveplan/react-bank` reads VC wallet. Prerequisites: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/economy`, `@suaveplan/events`.

View File

@@ -0,0 +1,40 @@
# Tasks: enterprise-gaming-api-plugin-virtual-currency
## 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-virtual-currency/` (`@suaveplan/api-plugin-virtual-currency`, `0.1.0`, `sideEffects: false`)
- [ ] `tsconfig.json`, `vitest.config.ts`
## Phase 2 — Error codes + types
- [ ] `src/error-codes.ts` + `src/types/common.ts` + `common.md`
## Phase 3 — VC service
- [ ] `src/services/vc-service/vc-service.ts` — balance/purchase/transfer/cashout, daily limits, OTel
- [ ] Tests + docs
## Phase 4 — Wallet routes
- [ ] `src/routes/wallets.ts` — all wallet HTTP endpoints
- [ ] `src/routes/wallets.md`
## Phase 5 — Plugin factory
- [ ] `src/plugin.ts` + `src/plugin.md`
## Phase 6 — Integration tests
- [ ] `tests/integration.test.ts` — purchase → transfer → cashout → history
## Phase 7 — Pre-publish gate
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-virtual-currency` green
- [ ] 100% coverage
- [ ] Publish: `bun scripts/publish.ts --package @suaveplan/api-plugin-virtual-currency`