Initial Commit
This commit is contained in:
88
openspec/changes/enterprise-api-plugin-banking/proposal.md
Normal file
88
openspec/changes/enterprise-api-plugin-banking/proposal.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# OpenSpec Change: enterprise-api-plugin-banking
|
||||
|
||||
- **Change ID**: enterprise-api-plugin-banking
|
||||
- **Package**: `@suaveplan/api-plugin-banking`
|
||||
- **Category**: api/commerce
|
||||
- **Target path**: `api/commerce/api-plugin-banking`
|
||||
- **Status**: PROPOSED
|
||||
- **Date**: 2026-04-24
|
||||
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-bank.md`
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Deliver `@suaveplan/api-plugin-banking` on the genesis branch from scratch at enterprise quality. The plugin provides open-banking connectivity: account aggregation, transaction listing, balance queries, and bank-initiated payment initiation (PIS). Pluggable bank adapter interface (Open Banking UK / PSD2 / Plaid). Routes mounted under `/banking`. Per-table SurrealQL. Typed event bus for `banking:transaction:received`, `banking:payment:initiated`. Rate-limited, auth-gated, audit-logged, idempotent on payment initiation. PSD2 SCA step-up enforced on payment routes.
|
||||
|
||||
---
|
||||
|
||||
## Available workspace deps on genesis
|
||||
|
||||
| Package | Role |
|
||||
|---|---|
|
||||
| `@suaveplan/api` (`workspace:^`) | `definePlugin` |
|
||||
| `@suaveplan/api-shared` (`workspace:^`) | Helpers |
|
||||
| `@suaveplan/api-plugin-auth` (`workspace:^`) | `requireAuth` |
|
||||
| `@suaveplan/api-plugin-database` (`workspace:^`) | SurrealDB |
|
||||
| `@suaveplan/events` (`workspace:^`) | Event bus |
|
||||
| `@suaveplan/error` (`workspace:^`) | `BankingError` hierarchy |
|
||||
| `@suaveplan/idempotency` (`workspace:^`) | Payment initiation guard |
|
||||
| `@suaveplan/audit-logging` (`workspace:^`) | Audit trail |
|
||||
| `@suaveplan/rate-limiter` (`workspace:^`) | Rate limits |
|
||||
| `hono` + `@hono/zod-openapi` + `zod` | Routes |
|
||||
| `@opentelemetry/api` | OTel |
|
||||
|
||||
---
|
||||
|
||||
## Public API surface
|
||||
|
||||
```ts
|
||||
function createBankingPlugin(adapter: BankAdapter, config?: BankingPluginConfig): PluginDescriptor<BankingPluginConfig>
|
||||
|
||||
interface BankAdapter {
|
||||
listAccounts(tenantId: string, userId: string): Promise<BankAccount[]>
|
||||
getBalance(accountId: string): Promise<Balance>
|
||||
listTransactions(accountId: string, query: TxQuery): Promise<Transaction[]>
|
||||
initiatePayment(payment: PaymentRequest): Promise<PaymentInitResult>
|
||||
getConsentUrl(userId: string, scopes: string[]): Promise<string>
|
||||
exchangeConsent(code: string): Promise<ConsentToken>
|
||||
}
|
||||
|
||||
// Routes: GET /banking/accounts, GET /banking/accounts/:id/balance,
|
||||
// GET /banking/accounts/:id/transactions, POST /banking/payments,
|
||||
// POST /banking/consent, GET /banking/consent/callback
|
||||
```
|
||||
|
||||
### Error codes
|
||||
|
||||
```ts
|
||||
type BankingErrorCode =
|
||||
| "BANKING_ACCOUNT_NOT_FOUND"
|
||||
| "BANKING_CONSENT_REQUIRED"
|
||||
| "BANKING_CONSENT_EXPIRED"
|
||||
| "BANKING_PAYMENT_FAILED"
|
||||
| "BANKING_SCA_REQUIRED"
|
||||
| "BANKING_ADAPTER_ERROR"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## File layout
|
||||
|
||||
```text
|
||||
api/commerce/api-plugin-banking/
|
||||
package.json tsconfig.json vitest.config.ts
|
||||
surql/ (bank_account, bank_transaction, bank_consent, bank_payment tables)
|
||||
src/
|
||||
index.ts events.ts types/ errors/
|
||||
adapters/bank-adapter.port.ts
|
||||
services/banking/
|
||||
routes/banking/
|
||||
tests/integration.test.ts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Impact
|
||||
|
||||
Prerequisites: `@suaveplan/api`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/events`, `@suaveplan/idempotency`, `@suaveplan/audit-logging`.
|
||||
61
openspec/changes/enterprise-api-plugin-banking/tasks.md
Normal file
61
openspec/changes/enterprise-api-plugin-banking/tasks.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Tasks: enterprise-api-plugin-banking
|
||||
|
||||
**Change ID**: enterprise-api-plugin-banking
|
||||
**Package**: `@suaveplan/api-plugin-banking`
|
||||
**Target path**: `api/commerce/api-plugin-banking`
|
||||
**Prerequisite packages on Verdaccio**: `@suaveplan/api`, `@suaveplan/api-shared`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/events`, `@suaveplan/idempotency`, `@suaveplan/audit-logging`, `@suaveplan/rate-limiter`, `@suaveplan/error`
|
||||
|
||||
---
|
||||
|
||||
## 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.
|
||||
|
||||
## 1. Scaffold
|
||||
|
||||
- [ ] Create `api/commerce/api-plugin-banking/`; `package.json` v0.0.0; standard tooling.
|
||||
|
||||
---
|
||||
|
||||
## 2. Types, errors, events
|
||||
|
||||
- [ ] Types: `BankAdapter` interface, `BankAccount`, `Balance`, `Transaction`, `TxQuery`, `PaymentRequest`, `PaymentInitResult`, `ConsentToken`, `BankingPluginConfig` (Zod).
|
||||
- [ ] Errors: 6-code union, metadata, registration. Test + doc.
|
||||
- [ ] Events: `BankingEventMap` (banking:transaction:received, banking:payment:initiated, banking:consent:granted).
|
||||
|
||||
---
|
||||
|
||||
## 3. SurrealQL
|
||||
|
||||
- [ ] `surql/bank_account.surql`, `bank_transaction.surql`, `bank_consent.surql`, `bank_payment.surql`.
|
||||
|
||||
---
|
||||
|
||||
## 4. BankAdapter port + BankingService
|
||||
|
||||
- [ ] `src/adapters/bank-adapter.port.ts` — `BankAdapter` interface (injectable for testing without mocks — pass a real stub implementation).
|
||||
- [ ] `BankingService`: `getAccounts`, `getBalance`, `listTransactions`, `initiatePayment`, `getConsentUrl`, `exchangeConsent`, `revokeConsent`.
|
||||
- [ ] Cache account list + balance in SurrealDB; refresh on stale TTL.
|
||||
- [ ] `.test.ts` + `.md`.
|
||||
|
||||
---
|
||||
|
||||
## 5. Routes
|
||||
|
||||
- [ ] `GET /banking/accounts`, `GET /banking/accounts/:id/balance`, `GET /banking/accounts/:id/transactions` — `requireAuth`.
|
||||
- [ ] `POST /banking/payments` — `requireAuth` + idempotency + rate-limit + audit + PSD2 SCA header check.
|
||||
- [ ] `POST /banking/consent`, `GET /banking/consent/callback` — consent flow.
|
||||
- [ ] Route `.test.ts` + `.md`.
|
||||
|
||||
---
|
||||
|
||||
## 6. Plugin factory + integration tests + publish
|
||||
|
||||
- [ ] `createBankingPlugin(adapter, config?)`: `definePlugin`, `dependencies: ["database", "auth"]`, `migrationsPath: "./surql"`.
|
||||
- [ ] `onTenantCreate` / `onTenantDelete`: provision/teardown consent records.
|
||||
- [ ] Integration test with real `BankAdapter` stub + real SurrealDB.
|
||||
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-banking` — green; 100% coverage.
|
||||
- [ ] `bun scripts/publish.ts --package @suaveplan/api-plugin-banking`.
|
||||
- [ ] Archive → `openspec/archive/2026-04-24-enterprise-api-plugin-banking/`.
|
||||
Reference in New Issue
Block a user