# Tasks: enterprise-events-schema - **Change ID**: enterprise-events-schema - **Package**: `@suaveplan/events-schema` - **Date**: 2026-04-24 ## Prerequisites (must be published to Verdaccio first) - [x] `@suaveplan/events` - [x] `@suaveplan/schema-registry` - [x] `@suaveplan/error` - [x] `@suaveplan/types` ## Tasks ### 1. Scaffold package - [x] Create `universal/events/events-schema/` directory tree per file layout in `proposal.md` - [x] Write `package.json` (name `@suaveplan/events-schema`, version `0.1.0`, `sideEffects: false`, correct workspace deps and catalog externals) - [x] Write `tsconfig.json` extending `@suaveplan/typescript-config/library.json` - [x] Write `vitest.config.ts` using `createTestConfig()` from `@suaveplan/testing/config` ### 2. Error codes (`src/error-codes.ts`) - [x] Define `EventsSchemaErrorCode` union type - [x] Call `defineCodes` to register all `EVENTS_SCHEMA.*` codes - [x] Export `registerEventsSchemaErrorCodes()` and `EventsSchemaError` ### 3. Types (`src/types/common.ts`) - [x] Define and export `EventSchemasOptions`, `EventSchemasHandle`, `ValidationMode`, `RejectionHandler`, `ValidationRejection`, `ValidationError`, `SchemaValidationStats`, `SchemaRegistrationOptions` - [x] Write `common.md` ### 4. Sensitive field redaction (`src/validation/redaction/`) - [x] Implement redaction logic: scan `ZodError` issues for paths, mask `.received` values when field schema carries `.meta({ sensitive: true })` - [x] Write `.md`, `.test.ts`, `index.ts` ### 5. Validator (`src/validation/validator/`) - [x] Implement validation logic for `strict`, `warn`, and `sample` modes - [x] Inject `rng` for sample-rate decisions - [x] Apply redaction before constructing `ValidationError` entries - [x] Write `.md`, `.types.ts`, `.test.ts`, `index.ts` ### 6. Schema registration helper (`src/schema/register-event-schema/`) - [x] Implement `registerEventSchema(registry, eventName, schema, options?)` that calls `registry.checkCompatibility` before registering - [x] Throw `EventsSchemaError("EVENTS_SCHEMA_COMPATIBILITY_BREAK")` on incompatible change - [x] Write `.md`, `.test.ts`, `index.ts` ### 7. Core `attachEventSchemas` (`src/core/attach-event-schemas/`) - [x] Implement `attachEventSchemas(bus, options?)` via `@suaveplan/events` interceptor API only - [x] Validate payload against registered schema on each dispatch using configured `mode` - [x] Accumulate `SchemaValidationStats` - [x] Emit OTel counters and histogram per `proposal.md` §4 - [x] Return `EventSchemasHandle` with `detach()`, `registerSchema()`, `stats()` - [x] Write `.md`, `.types.ts`, `.test.ts`, `index.ts` ### 8. Tests - [x] Unit tests co-located (100% coverage target) - [x] `tests/integration.test.ts` — attach to real EventBus, register schema, dispatch valid and invalid payloads, assert rejection counts and mode behaviour - [x] `tests/property.test.ts` — fast-check properties per `proposal.md` §5 ### 9. Docs - [x] Every `.ts` implementation file has a sibling `.md` - [x] Root `README.md` ### 10. Pre-publish gate - [x] `bunx turbo lint typecheck test --filter=@suaveplan/events-schema` green - [x] `bunx turbo test:coverage --filter=@suaveplan/events-schema` ≥ 100% on touched modules ### 11. Publish - [x] `bun scripts/publish.ts --package @suaveplan/events-schema` ### 12. Archive - [x] Fold spec delta into `openspec/specs/events/spec.md` - [x] `mv openspec/changes/enterprise-events-schema openspec/archive/2026-04-24-enterprise-events-schema`