Repository navigation
feat(audit): structured audit interceptor on the internal event bus - #478
Merged
Cjay-Cyber-2 merged 1 commit intoOct 22, 2026
Merged
Conversation
Closes ASTROIDX556#402, closes ASTROIDX556#403, closes ASTROIDX556#404, closes ASTROIDX556#405 ASTROIDX556#405 — Structured audit log interceptor - New `StructuredAuditInterceptor` audits only the routes marked with `@AuditAction()` and publishes an `audit.recorded` event on the internal event bus (`EventBusService` -> `@nestjs/event-emitter`). The publication is never awaited, so the response cycle is not blocked by the audit write. - The event captures the request metadata (method, path, sanitized body, params, query), the authenticated user id, the acting agent id, the client IP and user agent, the timestamp, the response status code and the handler duration. Payloads pass through the shared audit sanitizer, so private keys, secrets, API keys, bearer tokens and JWTs are redacted before the record is built. - `@AuditAction()` now also accepts `{ action, entity, description }`; `normalizeAuditAction()` resolves both the string and the object form. - New `AuditRecordedListener` turns the event into the hash-chained audit-log row and swallows (but logs) persistence failures. - `AuditInterceptor` and `AuditLogInterceptor` skip the routes owned by the structured path, so every audited operation leaves exactly one row. ASTROIDX556#402 — Zod-validated agent identity module - The agent schemas are strict, trim and bound the display name, capabilities and metadata, and reject duplicated capabilities. - A new optional `publicKey` is validated against the Stellar strkey checksum and persisted as agent metadata. - Duplicate agent handles are rejected with a `409 CONFLICT` before the Prisma repository is touched. - New controller spec asserts the standardized RFC 9457 error envelope for invalid payloads over real HTTP. ASTROIDX556#403 — Retry and dead-letter handling for the transaction worker - The transaction queue is registered with an explicit retry ceiling (5) and an exponential backoff base (2s). - `runWorkerJob` exposes an `onFailure` hook with the failure classification. - The transaction worker warns on a retryable failure and emits a `dead_letter.job_failed` domain event when the retries are exhausted, so a permanently failed transaction is visible in the event ledger next to the dead-letter queue entry. ASTROIDX556#404 — Enhanced spending policy rule evaluator - New `velocity` rule capping the number of transactions per rolling window, with per-window counters resolved by the repository. - New multi-condition `rules` groups with `AND`/`OR` logic, seven comparable fields and eight operators. - Time windows are now evaluated in an optional IANA time zone. - New engine, repository and service tests cover the pass, fail and edge cases of every new rule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #402
Closes #403
Closes #404
Closes #405
#405 — Structured audit log interceptor
StructuredAuditInterceptoraudits only the routes marked with@AuditAction()and publishes anaudit.recordedevent on the internal event bus (EventBusService->@nestjs/event-emitter). The publication is never awaited, so the response cycle is not blocked by the audit write.@AuditAction()now also accepts{ action, entity, description };normalizeAuditAction()resolves both the string and the object form.AuditRecordedListenerturns the event into the hash-chained audit-log row and swallows (but logs) persistence failures.AuditInterceptorandAuditLogInterceptorskip the routes owned by the structured path, so every audited operation leaves exactly one row.#402 — Zod-validated agent identity module
publicKeyis validated against the Stellar strkey checksum and persisted as agent metadata.409 CONFLICTbefore the Prisma repository is touched.#403 — Retry and dead-letter handling for the transaction worker
runWorkerJobexposes anonFailurehook with the failure classification.dead_letter.job_faileddomain event when the retries are exhausted, so a permanently failed transaction is visible in the event ledger next to the dead-letter queue entry.#404 — Enhanced spending policy rule evaluator
velocityrule capping the number of transactions per rolling window, with per-window counters resolved by the repository.rulesgroups withAND/ORlogic, seven comparable fields and eight operators.