Initial Commit
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
# OpenSpec Change: enterprise-api-plugin-procurement
|
||||
|
||||
- **Change ID**: enterprise-api-plugin-procurement
|
||||
- **Package**: `@suaveplan/api-plugin-procurement`
|
||||
- **Category**: api/logistics
|
||||
- **Target path**: `api/logistics/api-plugin-procurement`
|
||||
- **Status**: PROPOSED
|
||||
- **Date**: 2026-04-24
|
||||
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-procurement.md`
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Deliver `@suaveplan/api-plugin-procurement` on the genesis branch from scratch at enterprise quality. Procurement plugin: supplier management, purchase requisitions (PR), purchase orders (PO) with line items and approval workflow, goods-receipt note (GRN) creation on delivery, three-way matching (PO/GRN/invoice), and supplier performance tracking. Emits `procurement:grn:completed` on the bus so `@suaveplan/api-plugin-inventory` can auto-create stock movements. Routes under `/procurement`. Per-table SurrealQL. Events: `procurement:po:created`, `procurement:po:approved`, `procurement:grn:completed`, `procurement:invoice:matched`.
|
||||
|
||||
---
|
||||
|
||||
## Available workspace deps on genesis
|
||||
|
||||
| Package | Role |
|
||||
|---|---|
|
||||
| `@suaveplan/api` (`workspace:^`) | `definePlugin` |
|
||||
| `@suaveplan/api-shared` (`workspace:^`) | Helpers |
|
||||
| `@suaveplan/api-plugin-auth` (`workspace:^`) | `requireAuth`, approval roles |
|
||||
| `@suaveplan/api-plugin-database` (`workspace:^`) | SurrealDB |
|
||||
| `@suaveplan/events` (`workspace:^`) | Event bus |
|
||||
| `@suaveplan/error` (`workspace:^`) | `ProcurementError` hierarchy |
|
||||
| `@suaveplan/idempotency` (`workspace:^`) | Mutation guard |
|
||||
| `@suaveplan/audit-logging` (`workspace:^`) | Approval audit |
|
||||
| `@suaveplan/rate-limiter` (`workspace:^`) | Rate limits |
|
||||
| `hono` + `@hono/zod-openapi` + `zod` | Routes |
|
||||
| `@opentelemetry/api` | OTel |
|
||||
|
||||
---
|
||||
|
||||
## Public API surface
|
||||
|
||||
```ts
|
||||
function createProcurementPlugin(config?: ProcurementConfig): PluginDescriptor
|
||||
// Services: SupplierService, RequisitionService, PurchaseOrderService,
|
||||
// GrnService, MatchingService, PerformanceService
|
||||
// Routes: /procurement/suppliers, /procurement/requisitions, /procurement/purchase-orders,
|
||||
// /procurement/grns, /procurement/matching
|
||||
```
|
||||
|
||||
### Error codes
|
||||
|
||||
```ts
|
||||
type ProcurementErrorCode =
|
||||
| "PROCUREMENT_SUPPLIER_NOT_FOUND"
|
||||
| "PROCUREMENT_PO_NOT_FOUND"
|
||||
| "PROCUREMENT_PO_ALREADY_APPROVED"
|
||||
| "PROCUREMENT_GRN_NOT_FOUND"
|
||||
| "PROCUREMENT_MATCH_DISCREPANCY"
|
||||
| "PROCUREMENT_APPROVAL_UNAUTHORIZED"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## File layout
|
||||
|
||||
```text
|
||||
api/logistics/api-plugin-procurement/
|
||||
package.json tsconfig.json vitest.config.ts
|
||||
surql/ (supplier, requisition, purchase_order, po_line_item, grn, grn_line_item, invoice_match tables)
|
||||
src/
|
||||
index.ts events.ts types/ errors/
|
||||
services/supplier/ services/requisition/ services/purchase-order/
|
||||
services/grn/ services/matching/ services/performance/
|
||||
routes/procurement/
|
||||
tests/integration.test.ts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Impact
|
||||
|
||||
Prerequisites: `@suaveplan/api`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/events`, `@suaveplan/idempotency`, `@suaveplan/audit-logging`.
|
||||
56
openspec/changes/enterprise-api-plugin-procurement/tasks.md
Normal file
56
openspec/changes/enterprise-api-plugin-procurement/tasks.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Tasks: enterprise-api-plugin-procurement
|
||||
|
||||
**Change ID**: enterprise-api-plugin-procurement
|
||||
**Package**: `@suaveplan/api-plugin-procurement`
|
||||
**Target path**: `api/logistics/api-plugin-procurement`
|
||||
**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 + types + errors + events
|
||||
|
||||
- [ ] Create `api/logistics/api-plugin-procurement/`; `package.json` v0.0.0; standard tooling.
|
||||
- [ ] Types: `Supplier`, `Requisition`, `PurchaseOrder`, `PoLineItem`, `Grn`, `GrnLineItem`, `InvoiceMatch`, `ProcurementConfig` (Zod).
|
||||
- [ ] Errors: 6-code union + registration. Test + doc.
|
||||
- [ ] Events: `ProcurementEventMap` (procurement:po:created, :approved, :grn:completed, :invoice:matched).
|
||||
|
||||
---
|
||||
|
||||
## 2. SurrealQL
|
||||
|
||||
- [ ] Per-table files. All with tenantId indexes.
|
||||
|
||||
---
|
||||
|
||||
## 3. Services (all `.test.ts` + `.md`)
|
||||
|
||||
- [ ] **SupplierService**: CRUD + contact info + performance score.
|
||||
- [ ] **RequisitionService**: `createRequisition`, `approveRequisition` (converts to PO), `rejectRequisition`. Approval role check.
|
||||
- [ ] **PurchaseOrderService**: `createPo`, `approvePo` (state: draft→approved→sent→received), `cancelPo`. Audit approval. Emit `procurement:po:created` / `:approved`.
|
||||
- [ ] **GrnService**: `createGrn` (link to PO), `confirmGrn` — emit `procurement:grn:completed` (consumed by inventory plugin). Audit.
|
||||
- [ ] **MatchingService**: three-way match PO/GRN/invoice quantities+amounts; flag discrepancies; emit `:invoice:matched`.
|
||||
- [ ] **PerformanceService**: `recordDelivery`, `getPerformanceScore(supplierId)` — on-time delivery rate + defect rate.
|
||||
|
||||
---
|
||||
|
||||
## 4. Routes
|
||||
|
||||
- [ ] Full CRUD + state transitions for each entity.
|
||||
- [ ] Approval endpoints: `requireRole("PROCUREMENT_APPROVER")` + audit.
|
||||
- [ ] Route `.test.ts` + `.md`.
|
||||
|
||||
---
|
||||
|
||||
## 5. Plugin factory + integration tests + publish
|
||||
|
||||
- [ ] `createProcurementPlugin`: `definePlugin`, `dependencies: ["database", "auth"]`, `migrationsPath: "./surql"`.
|
||||
- [ ] Integration: supplier → PR → PO approve → GRN → three-way match (real SurrealDB). Verify `procurement:grn:completed` event emitted.
|
||||
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-procurement` — green; 100% coverage.
|
||||
- [ ] `bun scripts/publish.ts --package @suaveplan/api-plugin-procurement`.
|
||||
- [ ] Archive → `openspec/archive/2026-04-24-enterprise-api-plugin-procurement/`.
|
||||
Reference in New Issue
Block a user