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,57 @@
# Tasks: enterprise-api-plugin-vatdash-bridge
**Change ID**: enterprise-api-plugin-vatdash-bridge
**Package**: `@suaveplan/api-plugin-vatdash-bridge`
**Target path**: `api/logistics/api-plugin-vatdash-bridge`
**Prerequisite packages on Verdaccio**: `@suaveplan/api`, `@suaveplan/api-shared`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/api-plugin-export`, `@suaveplan/datetime`, `@suaveplan/events`, `@suaveplan/audit-logging`, `@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 + types + errors + events
- [ ] Create `api/logistics/api-plugin-vatdash-bridge/`; `package.json` v0.0.0; standard tooling.
- [ ] Types: `VatTransaction`, `VatRate`, `VatReturn`, `VatPeriod`, `MtdAdapter`, `MtdSubmissionResult`, `VatdashBridgeConfig` (Zod).
- [ ] Errors: 5-code union + registration. Test + doc.
- [ ] Events: `VatdashEventMap` (vatdash:vat-return:submitted, vatdash:transaction:tagged).
---
## 2. SurrealQL
- [ ] `vat_transaction.surql`, `vat_rate.surql` (reference: country+type+rate), `vat_return.surql`. tenantId indexes.
---
## 3. Services (all `.test.ts` + `.md`)
- [ ] **VatRateService**: `lookupRate(countryCode, txType)` — check override table then EC VIES fallback; cache 24 h.
- [ ] **TransactionService**: `tagTransaction(txId, vatCode)`, `listTransactions(period)`, `calculateVatDue(period)`.
- [ ] **VatReturnService**: `prepareReturn(period)` — aggregate transactions by box; `getReturn(period)`, `submitReturn(period)` via `MtdAdapter`; audit-log submission; emit event.
- [ ] **ReportService**: `generateReport(period, format)` — CSV/JSON export via `@suaveplan/api-plugin-export`.
---
## 4. Routes
- [ ] `GET/POST /vatdash/transactions`, `PATCH /vatdash/transactions/:id/tag` — `requireAuth`.
- [ ] `GET /vatdash/vat-rates?country=...` — `requireAuth`.
- [ ] `GET /vatdash/returns`, `GET /vatdash/returns/:period` — `requireAuth` + `requireRole("ACCOUNTANT")`.
- [ ] `POST /vatdash/returns/:period/submit` — `requireAuth` + `requireRole("ACCOUNTANT")` + audit.
- [ ] `GET /vatdash/returns/:period/report` — `requireAuth`.
- [ ] Route `.test.ts` + `.md`.
---
## 5. Plugin factory + integration tests + publish
- [ ] `createVatdashBridgePlugin`: `definePlugin`, `dependencies: ["database", "auth"]`, `migrationsPath: "./surql"`.
- [ ] Integration: tag transactions → prepare return → submit (stub MtdAdapter) → audit entry created (real SurrealDB).
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-vatdash-bridge` — green; 100% coverage.
- [ ] `bun scripts/publish.ts --package @suaveplan/api-plugin-vatdash-bridge`.
- [ ] Archive → `openspec/archive/2026-04-24-enterprise-api-plugin-vatdash-bridge/`.