{"_id":"@dcsv-io/d2-request-context-abstractions","_rev":"2-873005ee7f80bd41b09b333118b8ac39","name":"@dcsv-io/d2-request-context-abstractions","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.1":{"name":"@dcsv-io/d2-request-context-abstractions","version":"0.1.1","_id":"@dcsv-io/d2-request-context-abstractions@0.1.1","maintainers":[{"name":"dcsv-tristan","email":"tristan@dcsv.io"}],"dist":{"shasum":"cbae6692a714b2cce51920170a8cd90a9b8dbf30","tarball":"https://registry.npmjs.org/@dcsv-io/d2-request-context-abstractions/-/d2-request-context-abstractions-0.1.1.tgz","fileCount":19,"integrity":"sha512-chWW5beNd8ga6gW7wpJvAEzSUOMOXwSXkFgPPNCKsCV2znnpM7409+kFfAM++rBxdCLS46dwuDeASWoHqkBPOg==","signatures":[{"sig":"MEUCIQC3oykPeq7B4vLoqLL1RmfF8co18+YYaGKzgrjLLUV3MgIgX2cEt3LvM0LFqdCZEbjCoZl7YmO8/wAbQVvlp6LTiQE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":53652},"main":"./dist/index.js","type":"module","_from":"file:bundle/npm/dcsv-io-d2-request-context-abstractions-0.1.1.tgz","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"vitest run","build":"tsc -b","prebuild":"node ../scripts/run-ts-codegen.mjs src/request-context-emit.ts","type-check:test":"tsc -p tsconfig.test.json"},"_npmUser":{"name":"dcsv-tristan","email":"tristan@dcsv.io"},"_resolved":"/home/runner/work/D2-Public/D2-Public/bundle/npm/dcsv-io-d2-request-context-abstractions-0.1.1.tgz","_integrity":"sha512-chWW5beNd8ga6gW7wpJvAEzSUOMOXwSXkFgPPNCKsCV2znnpM7409+kFfAM++rBxdCLS46dwuDeASWoHqkBPOg==","_npmVersion":"11.16.0","description":"<!-- Copyright (c) DCSV. Licensed under the Apache License, Version 2.0. -->","directories":{},"_nodeVersion":"24.18.0","dependencies":{"@dcsv-io/d2-auth-context-abstractions":"0.1.1"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"4.0.18","typescript":"5.9.3"},"_npmOperationalInternal":{"tmp":"tmp/d2-request-context-abstractions_0.1.1_1784262848945_0.3874448827332442","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@dcsv-io/d2-request-context-abstractions","version":"0.1.2","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"dependencies":{"@dcsv-io/d2-auth-context-abstractions":"0.1.2"},"devDependencies":{"typescript":"5.9.3","vitest":"4.0.18"},"scripts":{"prebuild":"node ../scripts/run-ts-codegen.mjs src/request-context-emit.ts","build":"tsc -b","test":"vitest run","type-check:test":"tsc -p tsconfig.test.json"},"_id":"@dcsv-io/d2-request-context-abstractions@0.1.2","description":"<!-- Copyright (c) DCSV. Licensed under the Apache License, Version 2.0. -->","_integrity":"sha512-mLHTGDrmtUdBSuOHGZYaWfRDqJuanaoMskI8cW2fUUaUXcwLtkIJ2WU15h1XUbfitwJMCKtEzHn0NeTUSOXNSA==","_resolved":"/home/runner/work/D2-Public/D2-Public/bundle/npm/dcsv-io-d2-request-context-abstractions-0.1.2.tgz","_from":"file:bundle/npm/dcsv-io-d2-request-context-abstractions-0.1.2.tgz","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-mLHTGDrmtUdBSuOHGZYaWfRDqJuanaoMskI8cW2fUUaUXcwLtkIJ2WU15h1XUbfitwJMCKtEzHn0NeTUSOXNSA==","shasum":"7568c1b9d9c71f583a4d399899bb644afeb49829","tarball":"https://registry.npmjs.org/@dcsv-io/d2-request-context-abstractions/-/d2-request-context-abstractions-0.1.2.tgz","fileCount":19,"unpackedSize":53590,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDmVWlEfQLL3N7tOAJ+CkOHio0Sn+Z82zGY5SCRaCRY6AIgf7XmXV/JTnH62PexEH54l+YEc/4rhmUJCSp5QYDaWLY="}]},"_npmUser":{"name":"dcsv-tristan","email":"tristan@dcsv.io"},"directories":{},"maintainers":[{"name":"dcsv-tristan","email":"tristan@dcsv.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/d2-request-context-abstractions_0.1.2_1784287073345_0.342318755591851"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-17T04:34:08.750Z","modified":"2026-07-17T11:17:53.690Z","0.1.1":"2026-07-17T04:34:09.086Z","0.1.2":"2026-07-17T11:17:53.508Z"},"description":"<!-- Copyright (c) DCSV. Licensed under the Apache License, Version 2.0. -->","maintainers":[{"name":"dcsv-tristan","email":"tristan@dcsv.io"}],"readme":"<!--\nCopyright (c) DCSV. Licensed under the Apache License, Version 2.0.\n-->\n\n# @dcsv-io/d2-request-context-abstractions\n\n`IRequestContext` interface (extends `IAuthContext`) + `IPropagatedContext`\ncross-hop subset + `PropagatedContextSerializer` round-trip helper.\nEmitted from `contracts/request-context/IRequestContext.spec.json` via\nthe request-context spec (sources committed). Mirrors `DcsvIo.D2.Context.Abstractions` (.NET).\n\n## Install\n\n```bash\npnpm add @dcsv-io/d2-request-context-abstractions\n```\n\n## Public API\n\nGenerated artifacts (committed to git):\n\n| Export                        | Source                                                               |\n| ----------------------------- | -------------------------------------------------------------------- |\n| `IRequestContext`             | `IRequestContext.g.ts`                                               |\n| `IRequestContextRedactPaths`  | `IRequestContext.g.ts` (PII paths from spec `redact: true`)          |\n| `IPropagatedContext`          | `IPropagatedContext.g.ts` (cross-hop subset, `propagate: true` only) |\n| `PropagatedContextSerializer` | `PropagatedContextSerializer.g.ts` (`serialize` + `tryDecode`)       |\n\nPlus all `@dcsv-io/d2-auth-context-abstractions` exports re-exported transitively.\n\n## Codegen workflow\n\n`prebuild` runs the `request-context-emit.ts` script before `tsc -b`, so\n`pnpm -r build` regenerates transparently. The emitter reuses the\n`emitAuthContext` core for the interface + emits the additional propagated\nartifacts.\n\nThe emitter honors the spec's `extends` field: when set (as it is for\n`IRequestContext.spec.json:6` `\"extends\": \"DcsvIo.D2.AuthContext.Abstractions.IAuthContext\"`),\nthe generated `IRequestContext.g.ts` declares\n`export interface IRequestContext extends IAuthContext { ... }` and\nemits a `import type { IAuthContext } from \"@dcsv-io/d2-auth-context-abstractions\";`\nline at the top. Consumers see the unified `IRequestContext` shape as a\nsingle import — IAuthContext properties are inherited transitively.\n\n## Dependencies\n\n- `@dcsv-io/d2-auth-context-abstractions` — `IAuthContext` + supporting enums.\n\n## Usage example\n\n```ts\nimport {\n  PropagatedContextSerializer,\n  IRequestContextRedactPaths,\n} from \"@dcsv-io/d2-request-context-abstractions\";\nimport { setupLogger } from \"@dcsv-io/d2-logging\";\n\n// Encode envelope for cross-hop propagation.\nconst envelope = PropagatedContextSerializer.serialize(propagatedCtx);\namqpHeaders[\"x-d2-context\"] = envelope;\n\n// Decode incoming envelope (returns undefined on tamper / oversize).\nconst decoded = PropagatedContextSerializer.tryDecode(headers[\"x-d2-context\"]);\n\n// Wire PII paths into Pino redaction.\nconst log = setupLogger({\n  serviceName: \"edge\",\n  redactPaths: [IRequestContextRedactPaths],\n});\n```\n\n## Parity with .NET\n\nMirrors `DcsvIo.D2.Context.Abstractions`:\n\n- `IRequestContext` ↔ same property set, camelCased.\n- `PropagatedContextSerializer` ↔ 1:1 type-named class with\n `Serialize`/`Deserialize`.\n- `IPropagatedContext` ↔ same propagated subset.\n\n## Nullability convention\n\n> Canonical nullability rule (same as `@dcsv-io/d2-auth-context-abstractions`): `IRequestContext` extends `IAuthContext` and inherits the same spec-driven `T | null` emission for spec-emitted property types (the spec's `?` suffix on a type entry — e.g. `\"string?\"` in `IRequestContext.spec.json` — triggers the `| null` emission).\n\n## Edge cases\n\n- `tryDecode` enforces per-field `maxLength` caps from the spec — a\n forged envelope with any cap exceeded is dropped wholesale (returns\n `undefined`). Propagation is opportunistic, never required.\n- `tryDecode` type-checks numeric / boolean fields and rejects on\n shape mismatch.\n- `null` values survive serialize → deserialize without becoming the\n string `\"null\"`.\n- Generated files (`*.g.ts`) are committed to git.\n","readmeFilename":"README.md"}