94 lines
4.3 KiB
Markdown
94 lines
4.3 KiB
Markdown
# Tasks — network-plugin-middleware
|
||
|
||
> Blocked on: `network-core`.
|
||
|
||
## 1. Scaffold
|
||
|
||
- [x] 1.1 `packages/network/network-plugin-middleware/` with `package.json` (`@suaveplan/network-plugin-middleware@0.0.0`), `tsconfig.json`, `vitest.config.ts`, `README.md`.
|
||
- [x] 1.2 Workspace deps: `@suaveplan/network`, `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/events`, `@suaveplan/rate-limiter`, `@opentelemetry/api`, `zod`.
|
||
- [x] 1.3 `sideEffects: false`.
|
||
|
||
## 2. Types
|
||
|
||
- [x] 2.1 `src/types/middleware.types.ts` — `Middleware`, `MiddlewareContext`, `MiddlewarePriority`.
|
||
- [x] 2.2 `src/types/chain.types.ts` — `ChainDirection`, `ChainResult`, `ErrorPolicy`.
|
||
- [x] 2.3 `src/error-codes.ts` — `defineCodes("NET_MW", [...])`.
|
||
|
||
## 3. Middleware manager
|
||
|
||
- [x] 3.1 `src/manager/middleware-manager.ts` — `MiddlewareManager`.
|
||
- [x] 3.2 `register(middleware)`, `unregister(id)`, `enable(id)`, `disable(id)`.
|
||
- [x] 3.3 Orders by priority band: CRITICAL (0–99), HIGH (100–199), NORMAL (200–299), LOW (300–399), BACKGROUND (400+).
|
||
- [x] 3.4 Executes incoming and outgoing chains independently.
|
||
|
||
## 4. Logging middleware
|
||
|
||
- [x] 4.1 `src/logging/logging-middleware.ts` — `LoggingMiddleware`.
|
||
- [x] 4.2 Configurable body inclusion, max body size, custom formatter.
|
||
- [x] 4.3 Publishes `middleware:logged` on bus.
|
||
|
||
## 5. Validation middleware
|
||
|
||
- [x] 5.1 `src/validation/validation-middleware.ts` — `ValidationMiddleware`.
|
||
- [x] 5.2 Per-`MessageType` Zod schemas.
|
||
- [x] 5.3 Strict mode: reject invalid. Lenient mode: log warning, forward.
|
||
|
||
## 6. Transformation middleware
|
||
|
||
- [x] 6.1 `src/transformation/transformation-middleware.ts` — `TransformationMiddleware`.
|
||
- [x] 6.2 Type-specific transform functions.
|
||
- [x] 6.3 Examples: compress large payloads, strip debug fields, inject trace context.
|
||
|
||
## 7. Metrics middleware
|
||
|
||
- [x] 7.1 `src/metrics/metrics-middleware.ts` — `MetricsMiddleware`.
|
||
- [x] 7.2 Collects size, processing time, queue wait time per message.
|
||
- [x] 7.3 Publishes `middleware:metrics` on bus.
|
||
|
||
## 8. Throttling middleware
|
||
|
||
- [x] 8.1 `src/throttling/throttling-middleware.ts` — `ThrottlingMiddleware`.
|
||
- [x] 8.2 Token-bucket rate limiting using `@suaveplan/rate-limiter`.
|
||
- [x] 8.3 Global, per-peer, per-type limits with burst support.
|
||
|
||
## 9. Security middleware
|
||
|
||
- [x] 9.1 `src/security/security-middleware.ts` — `SecurityMiddleware`.
|
||
- [x] 9.2 Auto-applies crypto transforms based on message type and destination tier.
|
||
- [x] 9.3 Integrates with `network-plugin-crypto-messages` for signing/encryption.
|
||
|
||
## 10. I18n middleware
|
||
|
||
- [x] 10.1 `src/i18n/i18n-middleware.ts` — `I18nMiddleware`.
|
||
- [x] 10.2 Injects locale metadata into message headers.
|
||
- [x] 10.3 Handles RTL text markers.
|
||
- [x] 10.4 Standardizes timestamps to UTC internally.
|
||
|
||
## 11. Plugin wrapper
|
||
|
||
- [x] 11.1 `src/plugin/middleware-plugin.ts` — `MiddlewarePlugin` implements `NetworkPlugin`.
|
||
- [x] 11.2 Installs all middleware on `install()`, wires into `NetworkNode.send()` and incoming path.
|
||
|
||
## 12. Spec
|
||
|
||
- [x] 12.1 Update `openspec/specs/network/spec.md` with `NET-41`.
|
||
|
||
## 13. Conformance tests
|
||
|
||
- [x] 13.1 `src/manager/manager.spec-conformance.test.ts` — registration, ordering, enable/disable.
|
||
- [x] 13.2 `src/logging/logging.spec-conformance.test.ts` — body inclusion, formatting, max size.
|
||
- [x] 13.3 `src/validation/validation.spec-conformance.test.ts` — schema validation, strict/lenient.
|
||
- [x] 13.4 `src/transformation/transformation.spec-conformance.test.ts` — type-specific transforms.
|
||
- [x] 13.5 `src/metrics/metrics.spec-conformance.test.ts` — size/timing, bus publication.
|
||
- [x] 13.6 `src/throttling/throttling.spec-conformance.test.ts` — global/per-peer/per-type, burst.
|
||
- [x] 13.7 `src/security/security.spec-conformance.test.ts` — auto-crypto per policy.
|
||
- [x] 13.8 `src/i18n/i18n.spec-conformance.test.ts` — locale injection, RTL, timestamps.
|
||
- [x] 13.9 `src/chain/chain.spec-conformance.test.ts` — null-drop, error-policy, direction.
|
||
- [x] 13.10 `src/error-codes.spec-conformance.test.ts` — frozen registry.
|
||
|
||
## 14. Verify
|
||
|
||
- [x] 14.1 `bunx turbo lint typecheck test --filter=@suaveplan/network-plugin-middleware` green.
|
||
- [x] 14.2 `bunx turbo test:coverage --filter=@suaveplan/network-plugin-middleware` 100/100/100/100.
|
||
- [x] 14.3 `bun scripts/openspec-conformance.ts @suaveplan/network-plugin-middleware` PASS.
|