# @dudousxd/nestjs-context

## 1.1.1

### Patch Changes

- [#101](https://github.com/DavideCarvalho/nestjs-context/pull/101) [`763475c`](https://github.com/DavideCarvalho/nestjs-context/commit/763475c0e7b16d65aae46751cf2a4992375e79cc) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Fix the `userRefFrom` TSDoc: the default uses `user.id ?? user.sub`.

## 1.1.0

### Minor Changes

- [#98](https://github.com/DavideCarvalho/nestjs-context/pull/98) [`30377f8`](https://github.com/DavideCarvalho/nestjs-context/commit/30377f86a7a89a0bbd37aa793adc22b12d675c18) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Bridge to the official `@nestjs/authentication` (optional peer, `>=0.1.5`). Read the user from its `AuthenticationContext`; nestjs-context only carries a reference to it across processes.

  - `ContextAuthenticationInterceptor` (registered by `ContextModule`) sets `userRef` from `AuthenticationContext.user`, mapped by the new `userRefFrom` option (default `{ type: 'user', id: user.id }`). Import `ContextModule` after `AuthenticationModule` so it runs inside the official interceptor. If it's imported first, it warns once.
  - `ContextRunner.run(carrier, fn)` (injectable) = `Context.deserialize` + `AuthenticationContext.run(await rehydrateUser(carrier.userRef), fn)`, using the new `rehydrateUser` option. The carrier never holds the user or the session.

## 1.0.4

### Patch Changes

- [`6544704`](https://github.com/DavideCarvalho/nestjs-context/commit/6544704f128c89de4c0e73a1b95b1e7833592163) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Say what keeps `VERSION` in sync, and that nothing checks it

  Comment only. The constant is rewritten by `scripts/sync-version.mjs` during the release; a
  release that does not run it ships a build reporting the previous version, and no test here
  catches that. Worth stating where the constant is declared rather than only in the script
  that moves it.

## 1.0.3

### Patch Changes

- [`cd69557`](https://github.com/DavideCarvalho/nestjs-context/commit/cd695574b9cf0cefc85ccdfb495d02551230a2ac) - Support NestJS 12.

  The `@nestjs/common` / `@nestjs/core` peer ranges are already `>=10.0.0`, so they
  admit 12 unchanged. The dev/test matrix now runs on `@nestjs/*@12.0.1`, so v12 is
  covered by CI rather than merely allowed by the range. No source changes were needed.

## 1.0.2

### Patch Changes

- [#8](https://github.com/DavideCarvalho/nestjs-context/pull/8) [`680aa63`](https://github.com/DavideCarvalho/nestjs-context/commit/680aa63731982560cccb12a7ab5b19a355cdb051) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Ship TanStack Intent agent skills (SKILL.md) inside the package.

- [#8](https://github.com/DavideCarvalho/nestjs-context/pull/8) [`013b074`](https://github.com/DavideCarvalho/nestjs-context/commit/013b07484643867e0183759cc08f393ecbb97ea8) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - fix: sync the exported `VERSION` const with package.json at release time. The plain `tsc` build does no version injection and `changeset version` only bumps package.json, so the hard-coded `VERSION` in `src/index.ts` could ship stale (it was `0.1.0-alpha.0` while the package was `0.2.0`). Corrected the literal and added `scripts/sync-version.mjs`, chained into `version-packages` to re-sync on every bump, with a `--check` guard in `release` that fails the publish on drift.

## 1.0.1

### Patch Changes

- [`693b19b`](https://github.com/DavideCarvalho/nestjs-context/commit/693b19b30920d3f3c28329ab879a49650ef53a79) - Register `context:accessor` as a typed capability in the ecosystem protocol's `CapabilityRegistry` (type-only augmentation) and add a conformance test (`assertCapabilityNaming`) that locks the canonical token naming. `@dudousxd/nestjs-diagnostics` stays an OPTIONAL peer — no runtime dependency added; context still works standalone.

## 1.0.0

### Minor Changes

- [#5](https://github.com/DavideCarvalho/nestjs-context/pull/5) [`d7d038c`](https://github.com/DavideCarvalho/nestjs-context/commit/d7d038c339eb4fdbdf01c0dd4b10a8b9df4a6fe9) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Ecosystem improvements for `@dudousxd/nestjs-context`.

  - **Faithful `toTraceparent`**: now preserves the upstream parent-id and sampling
    flags when an inbound `traceparent` header is present, instead of synthesizing a
    fresh one. Outgoing headers correctly continue the caller's trace.
  - **Guarded `Context.set`**: emits a development-mode warning when called outside
    of an active context (where the write would otherwise be silently lost), making
    misuse easy to catch during development.
  - **`Context.bind()` snapshot helper**: captures the current context and returns a
    wrapped function that restores it on invocation, so context propagates correctly
    across `setTimeout`, `EventEmitter` callbacks, queue/worker boundaries, and other
    places where the async chain would otherwise break.
  - **W3C / OpenTelemetry baggage interop**: serialize and deserialize context
    fields (e.g. `tenant`, `userRef`) to and from the standard `baggage` header,
    enabling propagation across service boundaries with OTel-compatible tooling.
  - **Enrichers + `Context.lazy()`**: register enrichers to augment the context and
    resolve values lazily on first access.
  - **`ContextModule.forRootAsync`**: async configuration of the module, allowing
    options to be built from injected dependencies (e.g. `ConfigService`).
  - **Packaging hygiene**: declared `sideEffects` and `exports` maps for correct
    tree-shaking and module resolution.

  Note: this release also adds a `LICENSE` file (MIT).

## 0.2.1

### Patch Changes

- [`eba468f`](https://github.com/DavideCarvalho/nestjs-context/commit/eba468fd399aea462170dda214c9d7ad2ab991a5) - perf: faster per-request context hot path — constant-compare the traceparent all-zero check, skip the redundant traceId rewrite when no `initialize()` hook is configured, and hand-roll `defaultSerialize` for the default carrier.

## 0.2.0

### Minor Changes

- [#2](https://github.com/DavideCarvalho/nestjs-context/pull/2) [`f1c4f5c`](https://github.com/DavideCarvalho/nestjs-context/commit/f1c4f5c20df05b156da2bc9da63caa46aa6cfebf) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Auto-wire `traceId` into `@dudousxd/nestjs-diagnostics` when it is installed. On
  module init `ContextModule` soft-detects diagnostics (a new OPTIONAL peer — no
  static import, a failed dynamic import is a silent no-op) and registers this
  context's accessor via `setContextAccessor`. As a result every `aviary:*`
  diagnostic event — authz decisions, inertia renders, durable, notifications, and
  any future emitter — carries the current request's `traceId` automatically, with
  zero configuration. Apps that don't use diagnostics are unaffected.

## 0.1.0

### Minor Changes

- [`a2d5869`](https://github.com/DavideCarvalho/nestjs-context/commit/a2d5869455e83f45fb23eed649513813465be151) - Initial release: shared AsyncLocalStorage context (`Context` singleton + `ContextStore`), W3C traceparent helpers, `ContextMiddleware`, global `ContextModule.forRoot()` with the `CONTEXT_ACCESSOR` token, and the `@dudousxd/nestjs-context-testing` helper (`runWithContext`).
