@warlock.js/core 5.11.0 → 5.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/CHANGELOG.md +92 -54
  2. package/esm/application/app.d.mts +3 -3
  3. package/esm/application/app.mjs +6 -6
  4. package/esm/application/app.mjs.map +1 -1
  5. package/esm/cli/cli-commands.utils.mjs +7 -3
  6. package/esm/cli/cli-commands.utils.mjs.map +1 -1
  7. package/esm/cli/commands/doctor/checks/health.check.mjs +1 -1
  8. package/esm/cli/commands/doctor/checks/health.check.mjs.map +1 -1
  9. package/esm/connectors/socket-connector.mjs +13 -16
  10. package/esm/connectors/socket-connector.mjs.map +1 -1
  11. package/esm/container/index.d.mts +20 -7
  12. package/esm/container/index.d.mts.map +1 -1
  13. package/esm/container/index.mjs +8 -5
  14. package/esm/container/index.mjs.map +1 -1
  15. package/esm/database/utils.d.mts +5 -1
  16. package/esm/database/utils.d.mts.map +1 -1
  17. package/esm/database/utils.mjs +7 -3
  18. package/esm/database/utils.mjs.map +1 -1
  19. package/esm/dev-server/dev-logger.mjs +12 -1
  20. package/esm/dev-server/dev-logger.mjs.map +1 -1
  21. package/esm/dev-server/development-server.mjs +1 -1
  22. package/esm/dev-server/development-server.mjs.map +1 -1
  23. package/esm/dev-server/file-event-handler.mjs +72 -13
  24. package/esm/dev-server/file-event-handler.mjs.map +1 -1
  25. package/esm/dev-server/file-manager.d.mts +8 -0
  26. package/esm/dev-server/file-manager.d.mts.map +1 -1
  27. package/esm/dev-server/file-manager.mjs +26 -4
  28. package/esm/dev-server/file-manager.mjs.map +1 -1
  29. package/esm/dev-server/files-orchestrator.mjs +3 -3
  30. package/esm/dev-server/files-orchestrator.mjs.map +1 -1
  31. package/esm/dev-server/files-watcher.mjs +16 -2
  32. package/esm/dev-server/files-watcher.mjs.map +1 -1
  33. package/esm/dev-server/flags.mjs +16 -1
  34. package/esm/dev-server/flags.mjs.map +1 -1
  35. package/esm/dev-server/layer-executor.mjs +19 -2
  36. package/esm/dev-server/layer-executor.mjs.map +1 -1
  37. package/esm/dev-server/translation-type-generator.mjs +28 -0
  38. package/esm/dev-server/translation-type-generator.mjs.map +1 -0
  39. package/esm/dev-server/tsconfig-manager.mjs +1 -0
  40. package/esm/dev-server/tsconfig-manager.mjs.map +1 -1
  41. package/esm/dev-server/type-generator.mjs +41 -5
  42. package/esm/dev-server/type-generator.mjs.map +1 -1
  43. package/esm/encryption/index.mjs +1 -1
  44. package/esm/errors/container-key-missing-error.mjs +18 -6
  45. package/esm/errors/container-key-missing-error.mjs.map +1 -1
  46. package/esm/generations/features/auth-google.feature.mjs +18 -0
  47. package/esm/generations/features/auth-google.feature.mjs.map +1 -0
  48. package/esm/generations/features/auth-passkeys.feature.mjs +19 -0
  49. package/esm/generations/features/auth-passkeys.feature.mjs.map +1 -0
  50. package/esm/generations/features/index.mjs +6 -0
  51. package/esm/generations/features/index.mjs.map +1 -1
  52. package/esm/generations/features/queue.feature.mjs +67 -0
  53. package/esm/generations/features/queue.feature.mjs.map +1 -0
  54. package/esm/generations/stubs.mjs +10 -10
  55. package/esm/generations/stubs.mjs.map +1 -1
  56. package/esm/http/context/request-context.d.mts +14 -11
  57. package/esm/http/context/request-context.d.mts.map +1 -1
  58. package/esm/http/context/request-context.mjs +13 -9
  59. package/esm/http/context/request-context.mjs.map +1 -1
  60. package/esm/http/createHttpApplication.d.mts.map +1 -1
  61. package/esm/http/createHttpApplication.mjs +2 -0
  62. package/esm/http/createHttpApplication.mjs.map +1 -1
  63. package/esm/http/csp.d.mts +139 -0
  64. package/esm/http/csp.d.mts.map +1 -0
  65. package/esm/http/csp.mjs +134 -0
  66. package/esm/http/csp.mjs.map +1 -0
  67. package/esm/http/errors/errors.d.mts +17 -1
  68. package/esm/http/errors/errors.d.mts.map +1 -1
  69. package/esm/http/errors/errors.mjs +20 -1
  70. package/esm/http/errors/errors.mjs.map +1 -1
  71. package/esm/http/index.d.mts +8 -3
  72. package/esm/http/index.mjs +6 -1
  73. package/esm/http/middleware/concurrency-limit.middleware.d.mts +2 -2
  74. package/esm/http/middleware/concurrency-limit.middleware.mjs +1 -1
  75. package/esm/http/middleware/concurrency-limit.middleware.mjs.map +1 -1
  76. package/esm/http/middleware/inject-request-context.d.mts +1 -1
  77. package/esm/http/middleware/inject-request-context.d.mts.map +1 -1
  78. package/esm/http/middleware/inject-request-context.mjs +10 -0
  79. package/esm/http/middleware/inject-request-context.mjs.map +1 -1
  80. package/esm/http/middleware/rate-limit.middleware.d.mts +1 -1
  81. package/esm/http/middleware/rate-limit.middleware.mjs.map +1 -1
  82. package/esm/http/middleware/utils/idempotency-key.d.mts.map +1 -1
  83. package/esm/http/middleware/utils/idempotency-key.mjs +13 -13
  84. package/esm/http/middleware/utils/idempotency-key.mjs.map +1 -1
  85. package/esm/http/request-controller.d.mts +1 -1
  86. package/esm/http/request.d.mts +32 -44
  87. package/esm/http/request.d.mts.map +1 -1
  88. package/esm/http/request.mjs +52 -44
  89. package/esm/http/request.mjs.map +1 -1
  90. package/esm/http/response.d.mts +18 -0
  91. package/esm/http/response.d.mts.map +1 -1
  92. package/esm/http/response.mjs +31 -0
  93. package/esm/http/response.mjs.map +1 -1
  94. package/esm/http/stream-react-response.d.mts +65 -0
  95. package/esm/http/stream-react-response.d.mts.map +1 -0
  96. package/esm/http/stream-react-response.mjs +46 -0
  97. package/esm/http/stream-react-response.mjs.map +1 -0
  98. package/esm/http/tracing/index.mjs +4 -0
  99. package/esm/http/tracing/trace-id.d.mts +14 -0
  100. package/esm/http/tracing/trace-id.d.mts.map +1 -0
  101. package/esm/http/tracing/trace-id.mjs +37 -0
  102. package/esm/http/tracing/trace-id.mjs.map +1 -0
  103. package/esm/http/tracing/tracing-dispatcher.d.mts +42 -0
  104. package/esm/http/tracing/tracing-dispatcher.d.mts.map +1 -0
  105. package/esm/http/tracing/tracing-dispatcher.mjs +94 -0
  106. package/esm/http/tracing/tracing-dispatcher.mjs.map +1 -0
  107. package/esm/http/tracing/tracing.type.d.mts +66 -0
  108. package/esm/http/tracing/tracing.type.d.mts.map +1 -0
  109. package/esm/http/types.d.mts +27 -21
  110. package/esm/http/types.d.mts.map +1 -1
  111. package/esm/index.d.mts +9 -4
  112. package/esm/index.mjs +7 -3
  113. package/esm/production/esbuild-preflight.mjs +47 -0
  114. package/esm/production/esbuild-preflight.mjs.map +1 -0
  115. package/esm/production/production-builder.mjs +19 -15
  116. package/esm/production/production-builder.mjs.map +1 -1
  117. package/esm/restful/restful.d.mts +1 -1
  118. package/esm/router/log-request-lifecycle.mjs +12 -2
  119. package/esm/router/log-request-lifecycle.mjs.map +1 -1
  120. package/esm/router/router.d.mts.map +1 -1
  121. package/esm/router/router.mjs +10 -0
  122. package/esm/router/router.mjs.map +1 -1
  123. package/esm/router/types.d.mts +1 -1
  124. package/esm/socket/utils.mjs +1 -2
  125. package/esm/socket/utils.mjs.map +1 -1
  126. package/esm/storage/drivers/cloud-driver.d.mts.map +1 -1
  127. package/esm/storage/drivers/cloud-driver.mjs +2 -5
  128. package/esm/storage/drivers/cloud-driver.mjs.map +1 -1
  129. package/esm/warlock-config/types.d.mts +12 -0
  130. package/esm/warlock-config/types.d.mts.map +1 -1
  131. package/llms-full.txt +314 -46
  132. package/llms.txt +1 -0
  133. package/package.json +11 -12
  134. package/skills/add-connector/SKILL.md +1 -1
  135. package/skills/build-restful/SKILL.md +2 -2
  136. package/skills/configure-app/SKILL.md +31 -0
  137. package/skills/create-controller/SKILL.md +4 -4
  138. package/skills/request-tracing/SKILL.md +208 -0
  139. package/skills/send-response/SKILL.md +16 -0
  140. package/skills/store-file/SKILL.md +1 -1
  141. package/skills/upload-file/SKILL.md +2 -2
  142. package/skills/use-app-context/SKILL.md +2 -2
  143. package/skills/use-localization/SKILL.md +24 -21
  144. package/skills/use-middleware/SKILL.md +2 -2
  145. package/skills/use-repository/SKILL.md +1 -1
  146. package/skills/use-request-locals/SKILL.md +1 -1
  147. package/skills/wire-socket/SKILL.md +3 -3
  148. package/skills/write-middleware/SKILL.md +11 -5
  149. package/skills/write-use-case/SKILL.md +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csp.mjs","names":[],"sources":["../../../../../../../core/src/http/csp.ts"],"sourcesContent":["import config from \"@mongez/config\";\nimport type { Request } from \"./request\";\nimport type { Response } from \"./response\";\n\n/**\n * App-facing `http.csp` configuration shape.\n *\n * Disabled by default: an app that never sets `http.csp` (or sets\n * `enabled: false`) gets no `Content-Security-Policy` header at all — zero\n * behaviour change for every existing app. Opting in only swaps `enabled` to\n * `true`; `reportOnly` and `directives` are optional refinements on top.\n *\n * @example\n * ```ts title=\"src/config/http.ts\"\n * const httpConfigurations: HttpConfigurations = {\n * csp: {\n * enabled: true,\n * directives: {\n * \"img-src\": [\"'self'\", \"data:\", \"https://cdn.example.com\"],\n * },\n * },\n * };\n * ```\n */\nexport type CspConfig = {\n /**\n * Turn the header on. Everything else in this type is inert while this is\n * `false`/unset.\n */\n enabled: boolean;\n /**\n * Emit `Content-Security-Policy-Report-Only` instead of the enforcing\n * `Content-Security-Policy` header — the browser reports violations\n * (via `report-to`/`report-uri`, if the app's directives configure one)\n * without blocking anything. Use this to observe a policy safely before\n * enforcing it.\n *\n * @default false\n */\n reportOnly?: boolean;\n /**\n * App-supplied directive values. A directive named here REPLACES the\n * framework's default list for that directive entirely (the two lists are\n * never merged element-wise) — declare the full value list you want.\n *\n * `script-src` is special-cased regardless of whether it is declared here:\n * the current request's CSP nonce (`'nonce-<value>'`) is always appended to\n * it, so the framework's own inline/module scripts keep working.\n */\n directives?: Record<string, string[]>;\n};\n\n/**\n * The policy every `http.csp`-enabled app starts from. Deliberately\n * conservative — same-origin by default, no plugins, no framing by other\n * sites — and documented here rather than only in the skill, since this is\n * the literal set an app's `directives` entry replaces one key at a time.\n */\nexport const DEFAULT_CSP_DIRECTIVES: Readonly<Record<string, readonly string[]>> = {\n \"default-src\": [\"'self'\"],\n \"script-src\": [\"'self'\"],\n \"style-src\": [\"'self'\"],\n \"img-src\": [\"'self'\", \"data:\"],\n \"object-src\": [\"'none'\"],\n \"base-uri\": [\"'self'\"],\n \"frame-ancestors\": [\"'self'\"],\n};\n\n/**\n * Thrown at boot when `http.csp.directives` contains a value the framework\n * refuses to ship as-is, rather than silently dropping or rewriting it.\n *\n * Two shapes are rejected:\n * - a value containing `;` — CSP directives are `;`-delimited, so a `;`\n * inside one value would prematurely close it and let the remainder be\n * parsed as a new, attacker-uncontrolled-but-developer-typo'd directive.\n * - a value with an odd number of `'` characters — every CSP keyword\n * (`'self'`, `'none'`, a nonce/hash source) is single-quote-wrapped, so an\n * unbalanced count means a keyword was truncated or malformed.\n */\nexport class InvalidCspDirectiveError extends Error {\n public constructor(\n public readonly directive: string,\n public readonly value: string,\n reason: string,\n ) {\n super(\n `Invalid \"http.csp.directives\" entry — directive \"${directive}\" has a value ` +\n `${JSON.stringify(value)} that ${reason} Fix the value in your app's http config; ` +\n `the framework will not silently repair it.`,\n );\n this.name = \"InvalidCspDirectiveError\";\n }\n}\n\n/**\n * Validate every directive value an app supplied, throwing\n * {@link InvalidCspDirectiveError} on the first offender.\n *\n * Exported so boot code and tests can call it directly, independent of\n * whether `http.csp` happens to be enabled.\n */\nexport function validateCspDirectives(directives: Record<string, string[]> | undefined): void {\n if (!directives) return;\n\n for (const [directive, values] of Object.entries(directives)) {\n for (const value of values) {\n if (value.includes(\";\")) {\n throw new InvalidCspDirectiveError(\n directive,\n value,\n \"contains a ';' character, which would truncate the directive.\",\n );\n }\n\n const quoteCount = (value.match(/'/g) ?? []).length;\n if (quoteCount % 2 !== 0) {\n throw new InvalidCspDirectiveError(\n directive,\n value,\n \"has an unbalanced number of ' characters.\",\n );\n }\n }\n }\n}\n\n/**\n * Read the app's `http.csp` config, if any.\n */\nexport function resolveCspConfig(): CspConfig | undefined {\n return config.get(\"http.csp\");\n}\n\n/**\n * Fail the boot loudly when `http.csp` is enabled with invalid directives.\n *\n * Called once, from {@link createHttpApplication} before the server starts\n * listening — never per-request. A per-request validation would let an app\n * boot successfully and only discover the bad config on first traffic;\n * checking once at boot surfaces it immediately, the same way a malformed\n * `warlock.config.ts` would.\n *\n * @throws {InvalidCspDirectiveError} when a directive value is malformed.\n */\nexport function validateCspConfigAtBoot(): void {\n const cspConfig = resolveCspConfig();\n\n if (!cspConfig?.enabled) return;\n\n validateCspDirectives(cspConfig.directives);\n}\n\n/**\n * Merge the app's directives over the framework defaults and fold in the\n * request's nonce.\n *\n * Per-directive replacement, not element-wise merging: a directive the app\n * names wins outright, everything else falls back to\n * {@link DEFAULT_CSP_DIRECTIVES}. `script-src` always gains\n * `'nonce-<nonce>'` on top, whichever list it started from, so the\n * framework's own inline payload script and hydration module script are\n * never blocked by an app's own policy.\n */\nexport function mergeCspDirectives(\n appDirectives: Record<string, string[]> | undefined,\n nonce: string,\n): Record<string, string[]> {\n const merged: Record<string, string[]> = {};\n\n for (const [directive, defaultValues] of Object.entries(DEFAULT_CSP_DIRECTIVES)) {\n merged[directive] = appDirectives?.[directive]\n ? [...appDirectives[directive]]\n : [...defaultValues];\n }\n\n if (appDirectives) {\n for (const [directive, values] of Object.entries(appDirectives)) {\n if (!(directive in merged)) {\n merged[directive] = [...values];\n }\n }\n }\n\n // `merged[\"script-src\"]` is always populated by the loop above —\n // `DEFAULT_CSP_DIRECTIVES` (:59-67) declares a `script-src` entry, and every\n // one of its keys is copied into `merged` unconditionally — but its type is\n // `Record<string, string[]>`, so `noUncheckedIndexedAccess` still widens the\n // read to `string[] | undefined`. Narrowed once, locally, rather than\n // asserted away.\n const scriptSrc = merged[\"script-src\"] ?? [];\n const nonceSource = `'nonce-${nonce}'`;\n\n merged[\"script-src\"] = scriptSrc.includes(nonceSource)\n ? scriptSrc\n : [...scriptSrc, nonceSource];\n\n return merged;\n}\n\n/**\n * Serialize a merged directive map into a header value —\n * `\"default-src 'self'; script-src 'self' 'nonce-...'; ...\"`.\n */\nexport function serializeCspDirectives(directives: Record<string, string[]>): string {\n return Object.entries(directives)\n .map(([directive, values]) => `${directive} ${values.join(\" \")}`)\n .join(\"; \");\n}\n\n/**\n * Build the full `Content-Security-Policy` (or `-Report-Only`) header value\n * for one request, using that request's own nonce.\n */\nexport function buildCspHeaderValue(cspConfig: CspConfig, nonce: string): string {\n return serializeCspDirectives(mergeCspDirectives(cspConfig.directives, nonce));\n}\n\n/**\n * Stamp the `Content-Security-Policy` (or, in `reportOnly` mode,\n * `Content-Security-Policy-Report-Only`) header on the response, when the\n * app opted in via `http.csp.enabled`.\n *\n * A no-op when `http.csp` is absent or `enabled` is falsy — the default,\n * behaviour-preserving state for every app that hasn't opted in.\n *\n * Reads `request.nonce`, which lazily generates and caches the per-request\n * nonce (`request.ts`) — calling this early in the request lifecycle (see\n * `inject-request-context.ts`) means the SAME nonce this stamps into the\n * header is the one still available later for the web layer's `<script>`\n * tags to read off `request.nonce`.\n */\nexport function applyCspHeader(request: Request, response: Response): void {\n const cspConfig = resolveCspConfig();\n\n if (!cspConfig?.enabled) return;\n\n const headerName = cspConfig.reportOnly\n ? \"Content-Security-Policy-Report-Only\"\n : \"Content-Security-Policy\";\n\n response.header(headerName, buildCspHeaderValue(cspConfig, request.nonce));\n}\n"],"mappings":";;;;;;;;;AA0DA,MAAa,yBAAsE;CACjF,eAAe,CAAC,QAAQ;CACxB,cAAc,CAAC,QAAQ;CACvB,aAAa,CAAC,QAAQ;CACtB,WAAW,CAAC,UAAU,OAAO;CAC7B,cAAc,CAAC,QAAQ;CACvB,YAAY,CAAC,QAAQ;CACrB,mBAAmB,CAAC,QAAQ;AAC9B;;;;;;;;;;;;;AAcA,IAAa,2BAAb,cAA8C,MAAM;CAClD,AAAO,YACL,AAAgB,WAChB,AAAgB,OAChB,QACA;EACA,MACE,oDAAoD,UAAU,gBACzD,KAAK,UAAU,KAAK,EAAE,QAAQ,OAAO,qFAE5C;EARgB;EACA;EAQhB,KAAK,OAAO;CACd;AACF;;;;;;;;AASA,SAAgB,sBAAsB,YAAwD;CAC5F,IAAI,CAAC,YAAY;CA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AAY,KAAK,CAAC;AAC/E;;;;;;;;;;;;;;;AAgBA,SAAgB,eAAe,SAAkB,UAA0B;CACzE,MAAM,YAAY,iBAAiB;CAEnC,IAAI,CAAC,WAAW,SAAS;CAEzB,MAAM,aAAa,UAAU,aACzB,wCACA;CAEJ,SAAS,OAAO,YAAY,oBAAoB,WAAW,QAAQ,KAAK,CAAC;AAC3E"}
@@ -37,6 +37,22 @@ declare class NotAllowedError extends HttpError {
37
37
  payload?: any | undefined;
38
38
  constructor(message: string, payload?: any | undefined);
39
39
  }
40
+ /**
41
+ * Thrown by `Request.prototype.user` in development to catch a call site
42
+ * still reading the removed `request.user` getter/setter after the 5.12.0
43
+ * move: the authenticated user now lives at `request.locals.user`, written
44
+ * by `@warlock.js/auth`'s middleware.
45
+ *
46
+ * Development-only diagnostic, not a runtime contract other code should
47
+ * catch — the getter itself is typed `never`, so a caller that still
48
+ * compiles against `request.user` only does so via `any`/an outdated type.
49
+ * Kept in core (not auth) because `request.user` is a core `Request`
50
+ * accessor and core cannot depend on `@warlock.js/auth` to react to it.
51
+ * Slated for removal one release after 5.12.0 — see the CHANGELOG.
52
+ */
53
+ declare class RequestUserMovedError extends Error {
54
+ constructor();
55
+ }
40
56
  //#endregion
41
- export { BadRequestError, ConflictError, ForbiddenError, HttpError, NotAcceptableError, NotAllowedError, ResourceNotFoundError, ServerError, UnAuthorizedError };
57
+ export { BadRequestError, ConflictError, ForbiddenError, HttpError, NotAcceptableError, NotAllowedError, RequestUserMovedError, ResourceNotFoundError, ServerError, UnAuthorizedError };
42
58
  //# sourceMappingURL=errors.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../../../../../../../../core/src/http/errors/errors.ts"],"mappings":";cAAa,SAAA,SAAkB,KAAK;EAEzB,MAAA;EACA,OAAA;EACA,OAAA;cAFA,MAAA,UACA,OAAA,UACA,OAAA;AAAA;AAAA,cAOE,qBAAA,SAA8B,SAAS;EAGzC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,iBAAA,SAA0B,SAAS;EAGrC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,cAAA,SAAuB,SAAS;EAGlC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,eAAA,SAAwB,SAAS;EAGnC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,WAAA,SAAoB,SAAS;EAG/B,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,aAAA,SAAsB,SAAS;EAGjC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,kBAAA,SAA2B,SAAS;EAGtC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,eAAA,SAAwB,SAAS;EAGnC,OAAA;cADP,OAAA,UACO,OAAA;AAAA"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../../../../../../../core/src/http/errors/errors.ts"],"mappings":";cAAa,SAAA,SAAkB,KAAK;EAEzB,MAAA;EACA,OAAA;EACA,OAAA;cAFA,MAAA,UACA,OAAA,UACA,OAAA;AAAA;AAAA,cAOE,qBAAA,SAA8B,SAAS;EAGzC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,iBAAA,SAA0B,SAAS;EAGrC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,cAAA,SAAuB,SAAS;EAGlC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,eAAA,SAAwB,SAAS;EAGnC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,WAAA,SAAoB,SAAS;EAG/B,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,aAAA,SAAsB,SAAS;EAGjC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,kBAAA,SAA2B,SAAS;EAGtC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;AAAA,cAOE,eAAA,SAAwB,SAAS;EAGnC,OAAA;cADP,OAAA,UACO,OAAA;AAAA;;;;;;;;;;AAlDa;AAOxB;;;cA+Da,qBAAA,SAA8B,KAAK;EAAL,WAAA;AAAA"}
@@ -64,7 +64,26 @@ var NotAllowedError = class extends HttpError {
64
64
  this.name = "NotAllowedError";
65
65
  }
66
66
  };
67
+ /**
68
+ * Thrown by `Request.prototype.user` in development to catch a call site
69
+ * still reading the removed `request.user` getter/setter after the 5.12.0
70
+ * move: the authenticated user now lives at `request.locals.user`, written
71
+ * by `@warlock.js/auth`'s middleware.
72
+ *
73
+ * Development-only diagnostic, not a runtime contract other code should
74
+ * catch — the getter itself is typed `never`, so a caller that still
75
+ * compiles against `request.user` only does so via `any`/an outdated type.
76
+ * Kept in core (not auth) because `request.user` is a core `Request`
77
+ * accessor and core cannot depend on `@warlock.js/auth` to react to it.
78
+ * Slated for removal one release after 5.12.0 — see the CHANGELOG.
79
+ */
80
+ var RequestUserMovedError = class extends Error {
81
+ constructor() {
82
+ super("request.user has been removed. The authenticated user now lives at request.locals.user, set by @warlock.js/auth's middleware.");
83
+ this.name = "RequestUserMovedError";
84
+ }
85
+ };
67
86
 
68
87
  //#endregion
69
- export { BadRequestError, ConflictError, ForbiddenError, HttpError, NotAcceptableError, NotAllowedError, ResourceNotFoundError, ServerError, UnAuthorizedError };
88
+ export { BadRequestError, ConflictError, ForbiddenError, HttpError, NotAcceptableError, NotAllowedError, RequestUserMovedError, ResourceNotFoundError, ServerError, UnAuthorizedError };
70
89
  //# sourceMappingURL=errors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../core/src/http/errors/errors.ts"],"sourcesContent":["export class HttpError extends Error {\r\n public constructor(\r\n public status: number,\r\n public message: string,\r\n public payload?: any,\r\n ) {\r\n super(message);\r\n this.name = \"HttpError\";\r\n }\r\n}\r\n\r\nexport class ResourceNotFoundError extends HttpError {\r\n public constructor(\r\n message: string,\r\n public payload?: any,\r\n ) {\r\n super(404, message, payload);\r\n this.name = \"ResourceNotFoundError\";\r\n }\r\n}\r\n\r\nexport class UnAuthorizedError extends HttpError {\r\n public constructor(\r\n message: string,\r\n public payload?: any,\r\n ) {\r\n super(401, message, payload);\r\n this.name = \"UnAuthorizedError\";\r\n }\r\n}\r\n\r\nexport class ForbiddenError extends HttpError {\r\n public constructor(\r\n message: string,\r\n public payload?: any,\r\n ) {\r\n super(403, message, payload);\r\n this.name = \"ForbiddenError\";\r\n }\r\n}\r\n\r\nexport class BadRequestError extends HttpError {\r\n public constructor(\r\n message: string,\r\n public payload?: any,\r\n ) {\r\n super(400, message, payload);\r\n this.name = \"BadRequestError\";\r\n }\r\n}\r\n\r\nexport class ServerError extends HttpError {\r\n public constructor(\r\n message: string,\r\n public payload?: any,\r\n ) {\r\n super(500, message, payload);\r\n this.name = \"ServerError\";\r\n }\r\n}\r\n\r\nexport class ConflictError extends HttpError {\r\n public constructor(\r\n message: string,\r\n public payload?: any,\r\n ) {\r\n super(409, message, payload);\r\n this.name = \"ConflictError\";\r\n }\r\n}\r\n\r\nexport class NotAcceptableError extends HttpError {\r\n public constructor(\r\n message: string,\r\n public payload?: any,\r\n ) {\r\n super(406, message, payload);\r\n this.name = \"NotAcceptableError\";\r\n }\r\n}\r\n\r\nexport class NotAllowedError extends HttpError {\r\n public constructor(\r\n message: string,\r\n public payload?: any,\r\n ) {\r\n super(405, message, payload);\r\n this.name = \"NotAllowedError\";\r\n }\r\n}\r\n"],"mappings":";AAAA,IAAa,YAAb,cAA+B,MAAM;CACnC,AAAO,YACL,AAAO,QACP,AAAO,SACP,AAAO,SACP;EACA,MAAM,OAAO;EAJN;EACA;EACA;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,wBAAb,cAA2C,UAAU;CACnD,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,oBAAb,cAAuC,UAAU;CAC/C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,iBAAb,cAAoC,UAAU;CAC5C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC7C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,cAAb,cAAiC,UAAU;CACzC,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,UAAU;CAChD,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC7C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF"}
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../core/src/http/errors/errors.ts"],"sourcesContent":["export class HttpError extends Error {\n public constructor(\n public status: number,\n public message: string,\n public payload?: any,\n ) {\n super(message);\n this.name = \"HttpError\";\n }\n}\n\nexport class ResourceNotFoundError extends HttpError {\n public constructor(\n message: string,\n public payload?: any,\n ) {\n super(404, message, payload);\n this.name = \"ResourceNotFoundError\";\n }\n}\n\nexport class UnAuthorizedError extends HttpError {\n public constructor(\n message: string,\n public payload?: any,\n ) {\n super(401, message, payload);\n this.name = \"UnAuthorizedError\";\n }\n}\n\nexport class ForbiddenError extends HttpError {\n public constructor(\n message: string,\n public payload?: any,\n ) {\n super(403, message, payload);\n this.name = \"ForbiddenError\";\n }\n}\n\nexport class BadRequestError extends HttpError {\n public constructor(\n message: string,\n public payload?: any,\n ) {\n super(400, message, payload);\n this.name = \"BadRequestError\";\n }\n}\n\nexport class ServerError extends HttpError {\n public constructor(\n message: string,\n public payload?: any,\n ) {\n super(500, message, payload);\n this.name = \"ServerError\";\n }\n}\n\nexport class ConflictError extends HttpError {\n public constructor(\n message: string,\n public payload?: any,\n ) {\n super(409, message, payload);\n this.name = \"ConflictError\";\n }\n}\n\nexport class NotAcceptableError extends HttpError {\n public constructor(\n message: string,\n public payload?: any,\n ) {\n super(406, message, payload);\n this.name = \"NotAcceptableError\";\n }\n}\n\nexport class NotAllowedError extends HttpError {\n public constructor(\n message: string,\n public payload?: any,\n ) {\n super(405, message, payload);\n this.name = \"NotAllowedError\";\n }\n}\n\n/**\n * Thrown by `Request.prototype.user` in development to catch a call site\n * still reading the removed `request.user` getter/setter after the 5.12.0\n * move: the authenticated user now lives at `request.locals.user`, written\n * by `@warlock.js/auth`'s middleware.\n *\n * Development-only diagnostic, not a runtime contract other code should\n * catch — the getter itself is typed `never`, so a caller that still\n * compiles against `request.user` only does so via `any`/an outdated type.\n * Kept in core (not auth) because `request.user` is a core `Request`\n * accessor and core cannot depend on `@warlock.js/auth` to react to it.\n * Slated for removal one release after 5.12.0 — see the CHANGELOG.\n */\nexport class RequestUserMovedError extends Error {\n public constructor() {\n super(\n \"request.user has been removed. The authenticated user now lives at \" +\n \"request.locals.user, set by @warlock.js/auth's middleware.\",\n );\n this.name = \"RequestUserMovedError\";\n }\n}\n"],"mappings":";AAAA,IAAa,YAAb,cAA+B,MAAM;CACnC,AAAO,YACL,AAAO,QACP,AAAO,SACP,AAAO,SACP;EACA,MAAM,OAAO;EAJN;EACA;EACA;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,wBAAb,cAA2C,UAAU;CACnD,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,oBAAb,cAAuC,UAAU;CAC/C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,iBAAb,cAAoC,UAAU;CAC5C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC7C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,cAAb,cAAiC,UAAU;CACzC,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,UAAU;CAChD,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC7C,AAAO,YACL,SACA,AAAO,SACP;EACA,MAAM,KAAK,SAAS,OAAO;EAFpB;EAGP,KAAK,OAAO;CACd;AACF;;;;;;;;;;;;;;AAeA,IAAa,wBAAb,cAA2C,MAAM;CAC/C,AAAO,cAAc;EACnB,MACE,+HAEF;EACA,KAAK,OAAO;CACd;AACF"}
@@ -1,8 +1,11 @@
1
+ import { PipeableReactStream, StreamReactResponseOptions, streamReactResponse } from "./stream-react-response.mjs";
2
+ import { CookieOptions, Response, ResponseStatus, SendBufferOptions, SendFileOptions } from "./response.mjs";
1
3
  import { FileNamingStrategy, ImageTransformCallback, ImageTransformConfig, PrefixConfig, PrefixOptions, SaveAsOptions, SaveOptions, UploadedFileImageOptions, UploadsConfigurations } from "./uploads-types.mjs";
2
4
  import { FileValidationOptions, UploadedFile, UploadedFileJson } from "./uploaded-file.mjs";
3
5
  import { Request } from "./request.mjs";
4
- import { CookieOptions, Response, ResponseStatus, SendBufferOptions, SendFileOptions } from "./response.mjs";
5
- import { DecodedAccessToken, HttpConfigurations, PartialMiddleware, RequestEvent, RequestLocals, RequestUser, ResponseEvent, ResponseSSEController, ResponseStreamController, ReturnedResponse } from "./types.mjs";
6
+ import { CspConfig, DEFAULT_CSP_DIRECTIVES, InvalidCspDirectiveError, applyCspHeader, buildCspHeaderValue, mergeCspDirectives, resolveCspConfig, serializeCspDirectives, validateCspConfigAtBoot, validateCspDirectives } from "./csp.mjs";
7
+ import { HttpTracingConfig, TracingContext, TracingHooks, TracingPhaseInfo, TracingRequestEndInfo } from "./tracing/tracing.type.mjs";
8
+ import { DecodedAccessToken, HttpConfigurations, PartialMiddleware, RequestEvent, RequestLocals, ResponseEvent, ResponseSSEController, ResponseStreamController, ReturnedResponse } from "./types.mjs";
6
9
  import { defaultHttpConfigurations, httpConfig } from "./config.mjs";
7
10
  import { createHttpApplication, stopHttpApplication } from "./createHttpApplication.mjs";
8
11
  import { RequestLog } from "./database/RequestLog.mjs";
@@ -11,7 +14,7 @@ import { logResponse, wrapResponseInDataKey } from "./events.mjs";
11
14
  import { HealthCheck, HealthStatus, health } from "./health.mjs";
12
15
  import { RequestController } from "./request-controller.mjs";
13
16
  import { UPLOADS_DEFAULTS, uploadsConfig } from "./uploads-config.mjs";
14
- import { BadRequestError, ConflictError, ForbiddenError, HttpError, NotAcceptableError, NotAllowedError, ResourceNotFoundError, ServerError, UnAuthorizedError } from "./errors/errors.mjs";
17
+ import { BadRequestError, ConflictError, ForbiddenError, HttpError, NotAcceptableError, NotAllowedError, RequestUserMovedError, ResourceNotFoundError, ServerError, UnAuthorizedError } from "./errors/errors.mjs";
15
18
  import { CacheMiddlewareOptions } from "./middleware/cache-response-middleware.mjs";
16
19
  import { ConcurrencyLimitOptions } from "./middleware/concurrency-limit.middleware.mjs";
17
20
  import { IdempotencyOptions } from "./middleware/idempotency.middleware.mjs";
@@ -28,5 +31,7 @@ import { registerHttpPlugins } from "./plugins.mjs";
28
31
  import { assertConfiguredHttpPortIsFree, preflightConfiguredHttpPort, remedyLines, shouldPreflightHttpPort } from "./boot-port-preflight.mjs";
29
32
  import { PortInUseError, assertPortIsAvailable, isPortAvailable } from "./port-preflight.mjs";
30
33
  import { HttpReadyReport, getHttpReadyReport, resetHttpReadyReport, setHttpReadyReport } from "./ready-report.mjs";
34
+ import { deriveTraceId, parseTraceparentTraceId } from "./tracing/trace-id.mjs";
35
+ import { TracingContextSource, buildTracingContext, dispatchPhase, dispatchRequestEnd, dispatchRequestStart, isTracingEnabled, resetTracingConfigForTests, resolveTracingConfig } from "./tracing/tracing-dispatcher.mjs";
31
36
  import { RequestContextStore, requestContext, useCurrentUser, useRequest, useRequestStore } from "./context/request-context.mjs";
32
37
  import { requestMemo } from "./context/request-memo.mjs";
@@ -1,7 +1,12 @@
1
1
  import { requestContext, useCurrentUser, useRequest, useRequestStore } from "./context/request-context.mjs";
2
- import { BadRequestError, ConflictError, ForbiddenError, HttpError, NotAcceptableError, NotAllowedError, ResourceNotFoundError, ServerError, UnAuthorizedError } from "./errors/errors.mjs";
2
+ import { DEFAULT_CSP_DIRECTIVES, InvalidCspDirectiveError, applyCspHeader, buildCspHeaderValue, mergeCspDirectives, resolveCspConfig, serializeCspDirectives, validateCspConfigAtBoot, validateCspDirectives } from "./csp.mjs";
3
+ import { BadRequestError, ConflictError, ForbiddenError, HttpError, NotAcceptableError, NotAllowedError, RequestUserMovedError, ResourceNotFoundError, ServerError, UnAuthorizedError } from "./errors/errors.mjs";
4
+ import { deriveTraceId, parseTraceparentTraceId } from "./tracing/trace-id.mjs";
5
+ import { buildTracingContext, dispatchPhase, dispatchRequestEnd, dispatchRequestStart, isTracingEnabled, resetTracingConfigForTests, resolveTracingConfig } from "./tracing/tracing-dispatcher.mjs";
6
+ import "./tracing/index.mjs";
3
7
  import { createRequestStore, t } from "./middleware/inject-request-context.mjs";
4
8
  import { defaultHttpConfigurations, httpConfig } from "./config.mjs";
9
+ import { streamReactResponse } from "./stream-react-response.mjs";
5
10
  import { Response, ResponseStatus } from "./response.mjs";
6
11
  import { UPLOADS_DEFAULTS, uploadsConfig } from "./uploads-config.mjs";
7
12
  import { UploadedFile } from "./uploaded-file.mjs";
@@ -11,7 +11,7 @@ type ConcurrencyLimitOptions = {
11
11
  * or per-tenant.
12
12
  *
13
13
  * @example
14
- * keyGenerator: (request) => `${request.route.path}:${request.user?.id ?? request.ip}`,
14
+ * keyGenerator: (request) => `${request.route.path}:${request.locals.user?.id ?? request.ip}`,
15
15
  */
16
16
  keyGenerator?: (request: Request) => string;
17
17
  /**
@@ -42,7 +42,7 @@ type ConcurrencyLimitOptions = {
42
42
  * router.post("/ai/summarize", summarizeController, {
43
43
  * middleware: [
44
44
  * middleware.concurrencyLimit(10, {
45
- * keyGenerator: (request) => `ai:${request.user?.id ?? request.ip}`,
45
+ * keyGenerator: (request) => `ai:${request.locals.user?.id ?? request.ip}`,
46
46
  * }),
47
47
  * ],
48
48
  * });
@@ -34,7 +34,7 @@ function release(key) {
34
34
  * router.post("/ai/summarize", summarizeController, {
35
35
  * middleware: [
36
36
  * middleware.concurrencyLimit(10, {
37
- * keyGenerator: (request) => `ai:${request.user?.id ?? request.ip}`,
37
+ * keyGenerator: (request) => `ai:${request.locals.user?.id ?? request.ip}`,
38
38
  * }),
39
39
  * ],
40
40
  * });
@@ -1 +1 @@
1
- {"version":3,"file":"concurrency-limit.middleware.mjs","names":[],"sources":["../../../../../../../../core/src/http/middleware/concurrency-limit.middleware.ts"],"sourcesContent":["import type { Middleware } from \"../../router\";\nimport { HttpErrorCodes } from \"../error-codes\";\nimport type { Request } from \"../request\";\nimport type { Response } from \"../response\";\nimport { t } from \"./inject-request-context\";\n\n/**\n * Options for the concurrency limit middleware.\n */\nexport type ConcurrencyLimitOptions = {\n /**\n * Group key generator. Defaults to `request.route.path` — i.e. the cap\n * applies across all callers of that route. Override to scope per-user\n * or per-tenant.\n *\n * @example\n * keyGenerator: (request) => `${request.route.path}:${request.user?.id ?? request.ip}`,\n */\n keyGenerator?: (request: Request) => string;\n /**\n * Override the default error message.\n */\n errorMessage?: string;\n};\n\nconst counters = new Map<string, number>();\n\nfunction release(key: string) {\n const after = (counters.get(key) || 1) - 1;\n\n if (after <= 0) {\n counters.delete(key);\n\n return;\n }\n\n counters.set(key, after);\n}\n\n/**\n * Cap the number of in-flight requests against a route. Above the cap, new\n * requests get a fast 429 + `Retry-After: 1` — no queue, no timeout.\n *\n * Use for endpoints whose cost is unbounded per-request: report generation,\n * AI completions, image processing, expensive aggregations. Different from\n * `rateLimit()` — rate-limit caps requests-per-time, concurrency caps\n * in-flight requests at any instant.\n *\n * The counter is process-local. With `N` replicas the effective cap is\n * `N × max`. Document this in the route's behavior; if you need shared\n * concurrency across replicas, reach for a `@warlock.js/cache` lock instead.\n *\n * @example\n * import { middleware } from \"@warlock.js/core\";\n *\n * router.post(\"/reports/generate\", reportController, {\n * middleware: [middleware.concurrencyLimit(3)],\n * });\n *\n * router.post(\"/ai/summarize\", summarizeController, {\n * middleware: [\n * middleware.concurrencyLimit(10, {\n * keyGenerator: (request) => `ai:${request.user?.id ?? request.ip}`,\n * }),\n * ],\n * });\n */\nexport function concurrencyLimitMiddleware(\n max: number,\n options: ConcurrencyLimitOptions = {},\n): Middleware {\n return ({ request, response }) => {\n const key = options.keyGenerator?.(request) || request.route.path;\n const current = counters.get(key) || 0;\n\n if (current >= max) {\n response.header(\"Retry-After\", 1);\n\n return response.tooManyRequests({\n error: options.errorMessage || t(\"http.concurrencyLimitReached\"),\n errorCode: HttpErrorCodes.ConcurrencyLimitReached,\n limit: max,\n });\n }\n\n counters.set(key, current + 1);\n\n let released = false;\n\n const releaseOnce = () => {\n if (released) {\n return;\n }\n\n released = true;\n release(key);\n };\n\n // `onSent` only fires from Response.send()/stream().end()/sse().end().\n // Bare-reply paths (noContent, redirect, sendFile, download, sendBuffer,\n // raw send) never trigger it, so the slot would leak and the route would\n // permanently 429 after `max` such requests. Bind to the raw socket\n // lifecycle as well so the slot frees regardless of response path —\n // `releaseOnce` is idempotent, so double-firing is harmless.\n response.onSent((_sentResponse: Response) => releaseOnce());\n response.baseResponse.raw.once(\"finish\", releaseOnce);\n response.baseResponse.raw.once(\"close\", releaseOnce);\n };\n}\n"],"mappings":";;;;AAyBA,MAAM,2BAAW,IAAI,IAAoB;AAEzC,SAAS,QAAQ,KAAa;CAC5B,MAAM,SAAS,SAAS,IAAI,GAAG,KAAK,KAAK;CAEzC,IAAI,SAAS,GAAG;EACd,SAAS,OAAO,GAAG;EAEnB;CACF;CAEA,SAAS,IAAI,KAAK,KAAK;AACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,2BACd,KACA,UAAmC,CAAC,GACxB;CACZ,QAAQ,EAAE,SAAS,eAAe;EAChC,MAAM,MAAM,QAAQ,eAAe,OAAO,KAAK,QAAQ,MAAM;EAC7D,MAAM,UAAU,SAAS,IAAI,GAAG,KAAK;EAErC,IAAI,WAAW,KAAK;GAClB,SAAS,OAAO,eAAe,CAAC;GAEhC,OAAO,SAAS,gBAAgB;IAC9B,OAAO,QAAQ,gBAAgB,EAAE,8BAA8B;IAC/D;IACA,OAAO;GACT,CAAC;EACH;EAEA,SAAS,IAAI,KAAK,UAAU,CAAC;EAE7B,IAAI,WAAW;EAEf,MAAM,oBAAoB;GACxB,IAAI,UACF;GAGF,WAAW;GACX,QAAQ,GAAG;EACb;EAQA,SAAS,QAAQ,kBAA4B,YAAY,CAAC;EAC1D,SAAS,aAAa,IAAI,KAAK,UAAU,WAAW;EACpD,SAAS,aAAa,IAAI,KAAK,SAAS,WAAW;CACrD;AACF"}
1
+ {"version":3,"file":"concurrency-limit.middleware.mjs","names":[],"sources":["../../../../../../../../core/src/http/middleware/concurrency-limit.middleware.ts"],"sourcesContent":["import type { Middleware } from \"../../router\";\nimport { HttpErrorCodes } from \"../error-codes\";\nimport type { Request } from \"../request\";\nimport type { Response } from \"../response\";\nimport { t } from \"./inject-request-context\";\n\n/**\n * Options for the concurrency limit middleware.\n */\nexport type ConcurrencyLimitOptions = {\n /**\n * Group key generator. Defaults to `request.route.path` — i.e. the cap\n * applies across all callers of that route. Override to scope per-user\n * or per-tenant.\n *\n * @example\n * keyGenerator: (request) => `${request.route.path}:${request.locals.user?.id ?? request.ip}`,\n */\n keyGenerator?: (request: Request) => string;\n /**\n * Override the default error message.\n */\n errorMessage?: string;\n};\n\nconst counters = new Map<string, number>();\n\nfunction release(key: string) {\n const after = (counters.get(key) || 1) - 1;\n\n if (after <= 0) {\n counters.delete(key);\n\n return;\n }\n\n counters.set(key, after);\n}\n\n/**\n * Cap the number of in-flight requests against a route. Above the cap, new\n * requests get a fast 429 + `Retry-After: 1` — no queue, no timeout.\n *\n * Use for endpoints whose cost is unbounded per-request: report generation,\n * AI completions, image processing, expensive aggregations. Different from\n * `rateLimit()` — rate-limit caps requests-per-time, concurrency caps\n * in-flight requests at any instant.\n *\n * The counter is process-local. With `N` replicas the effective cap is\n * `N × max`. Document this in the route's behavior; if you need shared\n * concurrency across replicas, reach for a `@warlock.js/cache` lock instead.\n *\n * @example\n * import { middleware } from \"@warlock.js/core\";\n *\n * router.post(\"/reports/generate\", reportController, {\n * middleware: [middleware.concurrencyLimit(3)],\n * });\n *\n * router.post(\"/ai/summarize\", summarizeController, {\n * middleware: [\n * middleware.concurrencyLimit(10, {\n * keyGenerator: (request) => `ai:${request.locals.user?.id ?? request.ip}`,\n * }),\n * ],\n * });\n */\nexport function concurrencyLimitMiddleware(\n max: number,\n options: ConcurrencyLimitOptions = {},\n): Middleware {\n return ({ request, response }) => {\n const key = options.keyGenerator?.(request) || request.route.path;\n const current = counters.get(key) || 0;\n\n if (current >= max) {\n response.header(\"Retry-After\", 1);\n\n return response.tooManyRequests({\n error: options.errorMessage || t(\"http.concurrencyLimitReached\"),\n errorCode: HttpErrorCodes.ConcurrencyLimitReached,\n limit: max,\n });\n }\n\n counters.set(key, current + 1);\n\n let released = false;\n\n const releaseOnce = () => {\n if (released) {\n return;\n }\n\n released = true;\n release(key);\n };\n\n // `onSent` only fires from Response.send()/stream().end()/sse().end().\n // Bare-reply paths (noContent, redirect, sendFile, download, sendBuffer,\n // raw send) never trigger it, so the slot would leak and the route would\n // permanently 429 after `max` such requests. Bind to the raw socket\n // lifecycle as well so the slot frees regardless of response path —\n // `releaseOnce` is idempotent, so double-firing is harmless.\n response.onSent((_sentResponse: Response) => releaseOnce());\n response.baseResponse.raw.once(\"finish\", releaseOnce);\n response.baseResponse.raw.once(\"close\", releaseOnce);\n };\n}\n"],"mappings":";;;;AAyBA,MAAM,2BAAW,IAAI,IAAoB;AAEzC,SAAS,QAAQ,KAAa;CAC5B,MAAM,SAAS,SAAS,IAAI,GAAG,KAAK,KAAK;CAEzC,IAAI,SAAS,GAAG;EACd,SAAS,OAAO,GAAG;EAEnB;CACF;CAEA,SAAS,IAAI,KAAK,KAAK;AACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,2BACd,KACA,UAAmC,CAAC,GACxB;CACZ,QAAQ,EAAE,SAAS,eAAe;EAChC,MAAM,MAAM,QAAQ,eAAe,OAAO,KAAK,QAAQ,MAAM;EAC7D,MAAM,UAAU,SAAS,IAAI,GAAG,KAAK;EAErC,IAAI,WAAW,KAAK;GAClB,SAAS,OAAO,eAAe,CAAC;GAEhC,OAAO,SAAS,gBAAgB;IAC9B,OAAO,QAAQ,gBAAgB,EAAE,8BAA8B;IAC/D;IACA,OAAO;GACT,CAAC;EACH;EAEA,SAAS,IAAI,KAAK,UAAU,CAAC;EAE7B,IAAI,WAAW;EAEf,MAAM,oBAAoB;GACxB,IAAI,UACF;GAGF,WAAW;GACX,QAAQ,GAAG;EACb;EAQA,SAAS,QAAQ,kBAA4B,YAAY,CAAC;EAC1D,SAAS,aAAa,IAAI,KAAK,UAAU,WAAW;EACpD,SAAS,aAAa,IAAI,KAAK,SAAS,WAAW;CACrD;AACF"}
@@ -1,5 +1,5 @@
1
- import { Request } from "../request.mjs";
2
1
  import { Response } from "../response.mjs";
2
+ import { Request } from "../request.mjs";
3
3
  import { ReturnedResponse } from "../types.mjs";
4
4
 
5
5
  //#region ../core/src/http/middleware/inject-request-context.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"inject-request-context.d.mts","names":[],"sources":["../../../../../../../../core/src/http/middleware/inject-request-context.ts"],"mappings":";;;;;;;AA0CA;;;iBAAgB,kBAAA,CACd,OAAA,EAAS,OAAA,OACT,QAAA,EAAU,QAAA,GACT,OAAA,CAAQ,gBAAA;;;;iBAiGK,CAAA,CAAE,OAAA,UAAiB,YAAkB"}
1
+ {"version":3,"file":"inject-request-context.d.mts","names":[],"sources":["../../../../../../../../core/src/http/middleware/inject-request-context.ts"],"mappings":";;;;;;;AA4CA;;;iBAAgB,kBAAA,CACd,OAAA,EAAS,OAAA,OACT,QAAA,EAAU,QAAA,GACT,OAAA,CAAQ,gBAAA;;;;iBAkHK,CAAA,CAAE,OAAA,UAAiB,YAAkB"}
@@ -1,7 +1,10 @@
1
1
  import { environment } from "../../utils/environment.mjs";
2
2
  import { requestContext } from "../context/request-context.mjs";
3
3
  import "../../utils/index.mjs";
4
+ import { applyCspHeader } from "../csp.mjs";
4
5
  import { HttpError } from "../errors/errors.mjs";
6
+ import { buildTracingContext, dispatchPhase, isTracingEnabled } from "../tracing/tracing-dispatcher.mjs";
7
+ import "../tracing/index.mjs";
5
8
  import config from "@mongez/config";
6
9
  import { trans } from "@mongez/localization";
7
10
  import { DatabaseWriterValidationError } from "@warlock.js/cascade";
@@ -34,6 +37,7 @@ function stampRequestIdHeader(request, response) {
34
37
  */
35
38
  function createRequestStore(request, response) {
36
39
  stampRequestIdHeader(request, response);
40
+ applyCspHeader(request, response);
37
41
  const httpContextStore = contextManager.buildStores({
38
42
  request,
39
43
  response
@@ -45,10 +49,16 @@ function createRequestStore(request, response) {
45
49
  request.trigger("executingAction", request.route);
46
50
  const handler = request.getHandler();
47
51
  request.log("Executing Handler", "info");
52
+ const tracingEnabled = isTracingEnabled();
53
+ const handlerStartedAt = tracingEnabled ? performance.now() : 0;
48
54
  const output = await handler({
49
55
  request,
50
56
  response
51
57
  });
58
+ if (tracingEnabled) dispatchPhase(buildTracingContext(request), {
59
+ name: "handler",
60
+ durationMs: performance.now() - handlerStartedAt
61
+ });
52
62
  request.log("Handler Executed Successfully", "success");
53
63
  request.trigger("executedAction", request.route);
54
64
  return output;
@@ -1 +1 @@
1
- {"version":3,"file":"inject-request-context.mjs","names":["requestContextInstance"],"sources":["../../../../../../../../core/src/http/middleware/inject-request-context.ts"],"sourcesContent":["/**\n * Request Context Middleware\n *\n * Creates a unified context for each request using the ContextManager.\n * All framework contexts (request, storage, database) are available throughout the request lifecycle.\n */\nimport { trans } from \"@mongez/localization\";\nimport { type GenericObject } from \"@mongez/reinforcements\";\nimport { DatabaseWriterValidationError } from \"@warlock.js/cascade\";\nimport { contextManager } from \"@warlock.js/context\";\nimport config from \"@mongez/config\";\nimport { environment } from \"../../utils\";\nimport { requestContext as requestContextInstance } from \"../context/request-context\";\nimport { HttpError } from \"../errors\";\nimport { type Request } from \"../request\";\nimport { type Response } from \"../response\";\nimport { type ReturnedResponse } from \"./../types\";\n\n// Contexts are now registered in core/context/init-contexts.ts via initializeContexts()\n\n/**\n * Echo `request.id` back as a response header so the FE / proxies / log\n * aggregators can correlate by the same value the server logs against.\n *\n * Reads the header name from `http.requestId.header` (default `X-Request-Id`).\n * Skip when `http.requestId.enabled` is explicitly false.\n */\nfunction stampRequestIdHeader(request: Request, response: Response) {\n const requestIdConfig = config.get(\"http.requestId\", {} as Record<string, any>);\n\n if (requestIdConfig.enabled === false) return;\n\n const headerName = requestIdConfig.header || \"X-Request-Id\";\n\n response.header(headerName, request.id);\n}\n\n/**\n * Create request store and execute middleware + handler\n *\n * Runs all registered contexts together using ContextManager.\n */\nexport function createRequestStore(\n request: Request<any>,\n response: Response,\n): Promise<ReturnedResponse> {\n stampRequestIdHeader(request, response);\n\n // Build all context stores using the immutable API\n // Each context defines its own store initialization via buildStore()\n const httpContextStore = contextManager.buildStores({ request, response });\n\n // Run all contexts together!\n return contextManager.runAll(httpContextStore, async () => {\n try {\n // Run middleware chain\n const result = await request.runMiddleware();\n\n if (result) {\n return result as ReturnedResponse;\n }\n\n // Execute route handler\n request.trigger(\"executingAction\", request.route);\n\n const handler = request.getHandler();\n\n request.log(\"Executing Handler\", \"info\");\n\n const output = await handler({ request, response });\n\n request.log(\"Handler Executed Successfully\", \"success\");\n\n request.trigger(\"executedAction\", request.route);\n\n return output as ReturnedResponse;\n } catch (error) {\n request.log(error, \"error\");\n return handleRequestError(error, response);\n }\n });\n}\n\n/**\n * Handle request errors\n * @internal\n */\nfunction handleRequestError(error: unknown, response: Response): ReturnedResponse {\n // Availability floor, not a cache-policy nit: `handleRequestError` is the\n // single funnel every unhandled error in every Warlock app passes through\n // (`createRequestStore`'s catch above), and none of the branches below set\n // a `Cache-Control` header. Without this, an error response — a 500 as\n // much as a 401/403/404 carrying per-request/-user state — can be stored\n // by a shared cache or CDN and replayed to other requests/users long after\n // the condition that caused it is gone: a cached 500 becomes an outage\n // that outlives its cause; a cached 401/403 becomes a leak across users.\n // Set once, here, before any branch runs — not per branch — because the\n // branches below do not partition by status. `ResourceNotFoundError`,\n // `UnAuthorizedError`, `ForbiddenError`, `BadRequestError` and `ServerError`\n // all extend `HttpError`, so the `HttpError` branch answers for every one of\n // them, and a raw `HttpError` can carry any caller-chosen status, 4xx or 5xx.\n // Gating the floor on the eventual status would mean re-deriving that status\n // per branch — one rule meeting one form while others reach the same output.\n // Applying it once, unconditionally, is both simpler and safer.\n response.header(\"Cache-Control\", \"private, no-store\");\n\n if (error instanceof HttpError) {\n const payload: GenericObject = {\n error: error.message,\n };\n if (error.payload) {\n payload.payload = error.payload;\n }\n\n if (environment() === \"development\") {\n payload.stack = error.stack;\n }\n\n return response.setStatusCode(error.status).send(payload);\n }\n\n if (error instanceof DatabaseWriterValidationError) {\n return response.badRequest({\n errors: error.errors,\n });\n }\n\n // Last resort: the error matched none of the known shapes above, so the\n // client gets a deliberately opaque message. Without this line the error\n // itself is discarded here — no stack, no message, nothing in any log — and\n // an unrecognised failure becomes indistinguishable from a working server\n // returning 500. Never swallow the only copy of an error (`65e476ee`).\n console.error(\"[warlock] unhandled request error:\", error);\n\n return response.serverError({\n error: \"Internal server error.\",\n });\n}\n\n/**\n * Translate a keyword (uses request context for locale)\n */\nexport function t(keyword: string, placeholders?: any) {\n return (\n requestContextInstance.getRequest()?.trans(keyword, placeholders) ||\n trans(keyword, placeholders)\n );\n}\n\n// `fromRequest` was removed in v5. It cached computed values as dynamic\n// properties on the Request instance, which only compiled because of the\n// `[key: string]: any` index signature that v5 deletes (eed20184). Use\n// `requestMemo(key, fn)` from `../context/request-memo` instead — same\n// per-request lifetime, single-flight, and it never touches the Request object.\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,qBAAqB,SAAkB,UAAoB;CAClE,MAAM,kBAAkB,OAAO,IAAI,kBAAkB,CAAC,CAAwB;CAE9E,IAAI,gBAAgB,YAAY,OAAO;CAEvC,MAAM,aAAa,gBAAgB,UAAU;CAE7C,SAAS,OAAO,YAAY,QAAQ,EAAE;AACxC;;;;;;AAOA,SAAgB,mBACd,SACA,UAC2B;CAC3B,qBAAqB,SAAS,QAAQ;CAItC,MAAM,mBAAmB,eAAe,YAAY;EAAE;EAAS;CAAS,CAAC;CAGzE,OAAO,eAAe,OAAO,kBAAkB,YAAY;EACzD,IAAI;GAEF,MAAM,SAAS,MAAM,QAAQ,cAAc;GAE3C,IAAI,QACF,OAAO;GAIT,QAAQ,QAAQ,mBAAmB,QAAQ,KAAK;GAEhD,MAAM,UAAU,QAAQ,WAAW;GAEnC,QAAQ,IAAI,qBAAqB,MAAM;GAEvC,MAAM,SAAS,MAAM,QAAQ;IAAE;IAAS;GAAS,CAAC;GAElD,QAAQ,IAAI,iCAAiC,SAAS;GAEtD,QAAQ,QAAQ,kBAAkB,QAAQ,KAAK;GAE/C,OAAO;EACT,SAAS,OAAO;GACd,QAAQ,IAAI,OAAO,OAAO;GAC1B,OAAO,mBAAmB,OAAO,QAAQ;EAC3C;CACF,CAAC;AACH;;;;;AAMA,SAAS,mBAAmB,OAAgB,UAAsC;CAiBhF,SAAS,OAAO,iBAAiB,mBAAmB;CAEpD,IAAI,iBAAiB,WAAW;EAC9B,MAAM,UAAyB,EAC7B,OAAO,MAAM,QACf;EACA,IAAI,MAAM,SACR,QAAQ,UAAU,MAAM;EAG1B,IAAI,YAAY,MAAM,eACpB,QAAQ,QAAQ,MAAM;EAGxB,OAAO,SAAS,cAAc,MAAM,MAAM,CAAC,CAAC,KAAK,OAAO;CAC1D;CAEA,IAAI,iBAAiB,+BACnB,OAAO,SAAS,WAAW,EACzB,QAAQ,MAAM,OAChB,CAAC;CAQH,QAAQ,MAAM,sCAAsC,KAAK;CAEzD,OAAO,SAAS,YAAY,EAC1B,OAAO,yBACT,CAAC;AACH;;;;AAKA,SAAgB,EAAE,SAAiB,cAAoB;CACrD,OACEA,eAAuB,WAAW,CAAC,EAAE,MAAM,SAAS,YAAY,KAChE,MAAM,SAAS,YAAY;AAE/B"}
1
+ {"version":3,"file":"inject-request-context.mjs","names":["requestContextInstance"],"sources":["../../../../../../../../core/src/http/middleware/inject-request-context.ts"],"sourcesContent":["/**\n * Request Context Middleware\n *\n * Creates a unified context for each request using the ContextManager.\n * All framework contexts (request, storage, database) are available throughout the request lifecycle.\n */\nimport { trans } from \"@mongez/localization\";\nimport { type GenericObject } from \"@mongez/reinforcements\";\nimport { DatabaseWriterValidationError } from \"@warlock.js/cascade\";\nimport { contextManager } from \"@warlock.js/context\";\nimport config from \"@mongez/config\";\nimport { environment } from \"../../utils\";\nimport { requestContext as requestContextInstance } from \"../context/request-context\";\nimport { applyCspHeader } from \"../csp\";\nimport { HttpError } from \"../errors\";\nimport { type Request } from \"../request\";\nimport { type Response } from \"../response\";\nimport { buildTracingContext, dispatchPhase, isTracingEnabled } from \"../tracing\";\nimport { type ReturnedResponse } from \"./../types\";\n\n// Contexts are now registered in core/context/init-contexts.ts via initializeContexts()\n\n/**\n * Echo `request.id` back as a response header so the FE / proxies / log\n * aggregators can correlate by the same value the server logs against.\n *\n * Reads the header name from `http.requestId.header` (default `X-Request-Id`).\n * Skip when `http.requestId.enabled` is explicitly false.\n */\nfunction stampRequestIdHeader(request: Request, response: Response) {\n const requestIdConfig = config.get(\"http.requestId\", {} as Record<string, any>);\n\n if (requestIdConfig.enabled === false) return;\n\n const headerName = requestIdConfig.header || \"X-Request-Id\";\n\n response.header(headerName, request.id);\n}\n\n/**\n * Create request store and execute middleware + handler\n *\n * Runs all registered contexts together using ContextManager.\n */\nexport function createRequestStore(\n request: Request<any>,\n response: Response,\n): Promise<ReturnedResponse> {\n stampRequestIdHeader(request, response);\n\n // Stamped this early — before any middleware or handler runs — so the\n // header carries the SAME nonce the web layer later reads off\n // `request.nonce` for its `<script>` tags: `request.nonce` caches on first\n // read, and this is deliberately the first read. A no-op when the app\n // hasn't opted into `http.csp` (see `csp.ts`).\n applyCspHeader(request, response);\n\n // Build all context stores using the immutable API\n // Each context defines its own store initialization via buildStore()\n const httpContextStore = contextManager.buildStores({ request, response });\n\n // Run all contexts together!\n return contextManager.runAll(httpContextStore, async () => {\n try {\n // Run middleware chain\n const result = await request.runMiddleware();\n\n if (result) {\n return result as ReturnedResponse;\n }\n\n // Execute route handler\n request.trigger(\"executingAction\", request.route);\n\n const handler = request.getHandler();\n\n request.log(\"Executing Handler\", \"info\");\n\n const tracingEnabled = isTracingEnabled();\n const handlerStartedAt = tracingEnabled ? performance.now() : 0;\n\n const output = await handler({ request, response });\n\n if (tracingEnabled) {\n dispatchPhase(buildTracingContext(request), {\n name: \"handler\",\n durationMs: performance.now() - handlerStartedAt,\n });\n }\n\n request.log(\"Handler Executed Successfully\", \"success\");\n\n request.trigger(\"executedAction\", request.route);\n\n return output as ReturnedResponse;\n } catch (error) {\n request.log(error, \"error\");\n return handleRequestError(error, response);\n }\n });\n}\n\n/**\n * Handle request errors\n * @internal\n */\nfunction handleRequestError(error: unknown, response: Response): ReturnedResponse {\n // Availability floor, not a cache-policy nit: `handleRequestError` is the\n // single funnel every unhandled error in every Warlock app passes through\n // (`createRequestStore`'s catch above), and none of the branches below set\n // a `Cache-Control` header. Without this, an error response — a 500 as\n // much as a 401/403/404 carrying per-request/-user state — can be stored\n // by a shared cache or CDN and replayed to other requests/users long after\n // the condition that caused it is gone: a cached 500 becomes an outage\n // that outlives its cause; a cached 401/403 becomes a leak across users.\n // Set once, here, before any branch runs — not per branch — because the\n // branches below do not partition by status. `ResourceNotFoundError`,\n // `UnAuthorizedError`, `ForbiddenError`, `BadRequestError` and `ServerError`\n // all extend `HttpError`, so the `HttpError` branch answers for every one of\n // them, and a raw `HttpError` can carry any caller-chosen status, 4xx or 5xx.\n // Gating the floor on the eventual status would mean re-deriving that status\n // per branch — one rule meeting one form while others reach the same output.\n // Applying it once, unconditionally, is both simpler and safer.\n response.header(\"Cache-Control\", \"private, no-store\");\n\n if (error instanceof HttpError) {\n const payload: GenericObject = {\n error: error.message,\n };\n if (error.payload) {\n payload.payload = error.payload;\n }\n\n if (environment() === \"development\") {\n payload.stack = error.stack;\n }\n\n return response.setStatusCode(error.status).send(payload);\n }\n\n if (error instanceof DatabaseWriterValidationError) {\n return response.badRequest({\n errors: error.errors,\n });\n }\n\n // Last resort: the error matched none of the known shapes above, so the\n // client gets a deliberately opaque message. Without this line the error\n // itself is discarded here — no stack, no message, nothing in any log — and\n // an unrecognised failure becomes indistinguishable from a working server\n // returning 500. Never swallow the only copy of an error (`65e476ee`).\n console.error(\"[warlock] unhandled request error:\", error);\n\n return response.serverError({\n error: \"Internal server error.\",\n });\n}\n\n/**\n * Translate a keyword (uses request context for locale)\n */\nexport function t(keyword: string, placeholders?: any) {\n return (\n requestContextInstance.getRequest()?.trans(keyword, placeholders) ||\n trans(keyword, placeholders)\n );\n}\n\n// `fromRequest` was removed in v5. It cached computed values as dynamic\n// properties on the Request instance, which only compiled because of the\n// `[key: string]: any` index signature that v5 deletes (eed20184). Use\n// `requestMemo(key, fn)` from `../context/request-memo` instead — same\n// per-request lifetime, single-flight, and it never touches the Request object.\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAS,qBAAqB,SAAkB,UAAoB;CAClE,MAAM,kBAAkB,OAAO,IAAI,kBAAkB,CAAC,CAAwB;CAE9E,IAAI,gBAAgB,YAAY,OAAO;CAEvC,MAAM,aAAa,gBAAgB,UAAU;CAE7C,SAAS,OAAO,YAAY,QAAQ,EAAE;AACxC;;;;;;AAOA,SAAgB,mBACd,SACA,UAC2B;CAC3B,qBAAqB,SAAS,QAAQ;CAOtC,eAAe,SAAS,QAAQ;CAIhC,MAAM,mBAAmB,eAAe,YAAY;EAAE;EAAS;CAAS,CAAC;CAGzE,OAAO,eAAe,OAAO,kBAAkB,YAAY;EACzD,IAAI;GAEF,MAAM,SAAS,MAAM,QAAQ,cAAc;GAE3C,IAAI,QACF,OAAO;GAIT,QAAQ,QAAQ,mBAAmB,QAAQ,KAAK;GAEhD,MAAM,UAAU,QAAQ,WAAW;GAEnC,QAAQ,IAAI,qBAAqB,MAAM;GAEvC,MAAM,iBAAiB,iBAAiB;GACxC,MAAM,mBAAmB,iBAAiB,YAAY,IAAI,IAAI;GAE9D,MAAM,SAAS,MAAM,QAAQ;IAAE;IAAS;GAAS,CAAC;GAElD,IAAI,gBACF,cAAc,oBAAoB,OAAO,GAAG;IAC1C,MAAM;IACN,YAAY,YAAY,IAAI,IAAI;GAClC,CAAC;GAGH,QAAQ,IAAI,iCAAiC,SAAS;GAEtD,QAAQ,QAAQ,kBAAkB,QAAQ,KAAK;GAE/C,OAAO;EACT,SAAS,OAAO;GACd,QAAQ,IAAI,OAAO,OAAO;GAC1B,OAAO,mBAAmB,OAAO,QAAQ;EAC3C;CACF,CAAC;AACH;;;;;AAMA,SAAS,mBAAmB,OAAgB,UAAsC;CAiBhF,SAAS,OAAO,iBAAiB,mBAAmB;CAEpD,IAAI,iBAAiB,WAAW;EAC9B,MAAM,UAAyB,EAC7B,OAAO,MAAM,QACf;EACA,IAAI,MAAM,SACR,QAAQ,UAAU,MAAM;EAG1B,IAAI,YAAY,MAAM,eACpB,QAAQ,QAAQ,MAAM;EAGxB,OAAO,SAAS,cAAc,MAAM,MAAM,CAAC,CAAC,KAAK,OAAO;CAC1D;CAEA,IAAI,iBAAiB,+BACnB,OAAO,SAAS,WAAW,EACzB,QAAQ,MAAM,OAChB,CAAC;CAQH,QAAQ,MAAM,sCAAsC,KAAK;CAEzD,OAAO,SAAS,YAAY,EAC1B,OAAO,yBACT,CAAC;AACH;;;;AAKA,SAAgB,EAAE,SAAiB,cAAoB;CACrD,OACEA,eAAuB,WAAW,CAAC,EAAE,MAAM,SAAS,YAAY,KAChE,MAAM,SAAS,YAAY;AAE/B"}
@@ -18,7 +18,7 @@ type RateLimitOptions = {
18
18
  * per-organization, per-tenant, etc.
19
19
  *
20
20
  * @example
21
- * keyGenerator: (request) => request.user?.id ?? request.ip,
21
+ * keyGenerator: (request) => request.locals.user?.id ?? request.ip,
22
22
  */
23
23
  keyGenerator?: (request: Request) => string;
24
24
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"rate-limit.middleware.mjs","names":[],"sources":["../../../../../../../../core/src/http/middleware/rate-limit.middleware.ts"],"sourcesContent":["import type { Middleware } from \"../../router\";\nimport { HttpErrorCodes } from \"../error-codes\";\nimport type { Request } from \"../request\";\nimport { t } from \"./inject-request-context\";\n\n/**\n * Options for the per-route rate limit middleware.\n */\nexport type RateLimitOptions = {\n /**\n * Max requests allowed within the time window.\n */\n max: number;\n /**\n * Time window in milliseconds.\n */\n duration: number;\n /**\n * Group key generator. Defaults to the client IP. Override to scope per-user,\n * per-organization, per-tenant, etc.\n *\n * @example\n * keyGenerator: (request) => request.user?.id ?? request.ip,\n */\n keyGenerator?: (request: Request) => string;\n /**\n * Override the default error message.\n */\n errorMessage?: string;\n};\n\ntype Bucket = {\n count: number;\n resetAt: number;\n};\n\nconst buckets = new Map<string, Bucket>();\n\n/**\n * Sweep expired buckets so the Map doesn't grow unbounded with one-shot keys\n * (rare per-user keys, dynamic path parameters in `keyGenerator`, etc.).\n * Called opportunistically, at most once per minute, not on a timer — keeps\n * the module side-effect-free for testing.\n */\nlet lastPruneAt = 0;\n\nfunction pruneExpired(now: number) {\n for (const [key, bucket] of buckets) {\n if (bucket.resetAt <= now) {\n buckets.delete(key);\n }\n }\n}\n\n/**\n * Per-route / per-group rate limit. Layers on top of `@fastify/rate-limit`'s\n * global cap (configured via `http.rateLimit`) — both run, and either can\n * 429. Use this for endpoints that need a tighter cap than the global default:\n * login, OTP request, password reset, expensive search, AI completions.\n *\n * The counter lives in-process. With `N` replicas the effective cap is\n * `N × max`. For genuinely shared limits, configure `@fastify/rate-limit`'s\n * Redis store via `http.rateLimit` instead.\n *\n * Sets `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` on\n * every response; adds `Retry-After` (seconds) on a 429.\n *\n * @example\n * import { middleware } from \"@warlock.js/core\";\n * router.post(\"/auth/login\", loginController, {\n * middleware: [middleware.rateLimit({ max: 5, duration: 60_000 })],\n * });\n */\nexport function rateLimitMiddleware(options: RateLimitOptions): Middleware {\n return ({ request, response }) => {\n const now = Date.now();\n\n if (now - lastPruneAt > 60_000) {\n pruneExpired(now);\n lastPruneAt = now;\n }\n\n const groupKey = options.keyGenerator?.(request) || request.detectIp() || \"unknown\";\n const cacheKey = `${request.route.path}:${groupKey}`;\n\n let bucket = buckets.get(cacheKey);\n\n if (!bucket || bucket.resetAt <= now) {\n bucket = { count: 0, resetAt: now + options.duration };\n buckets.set(cacheKey, bucket);\n }\n\n bucket.count++;\n\n const remaining = Math.max(0, options.max - bucket.count);\n const retryAfter = Math.max(1, Math.ceil((bucket.resetAt - now) / 1000));\n\n response.header(\"X-RateLimit-Limit\", options.max);\n response.header(\"X-RateLimit-Remaining\", remaining);\n response.header(\"X-RateLimit-Reset\", Math.ceil(bucket.resetAt / 1000));\n\n if (bucket.count > options.max) {\n response.header(\"Retry-After\", retryAfter);\n\n return response.tooManyRequests({\n error: options.errorMessage || t(\"http.rateLimitExceeded\"),\n errorCode: HttpErrorCodes.RateLimitExceeded,\n });\n }\n };\n}\n"],"mappings":";;;;AAoCA,MAAM,0BAAU,IAAI,IAAoB;;;;;;;AAQxC,IAAI,cAAc;AAElB,SAAS,aAAa,KAAa;CACjC,KAAK,MAAM,CAAC,KAAK,WAAW,SAC1B,IAAI,OAAO,WAAW,KACpB,QAAQ,OAAO,GAAG;AAGxB;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,oBAAoB,SAAuC;CACzE,QAAQ,EAAE,SAAS,eAAe;EAChC,MAAM,MAAM,KAAK,IAAI;EAErB,IAAI,MAAM,cAAc,KAAQ;GAC9B,aAAa,GAAG;GAChB,cAAc;EAChB;EAEA,MAAM,WAAW,QAAQ,eAAe,OAAO,KAAK,QAAQ,SAAS,KAAK;EAC1E,MAAM,WAAW,GAAG,QAAQ,MAAM,KAAK,GAAG;EAE1C,IAAI,SAAS,QAAQ,IAAI,QAAQ;EAEjC,IAAI,CAAC,UAAU,OAAO,WAAW,KAAK;GACpC,SAAS;IAAE,OAAO;IAAG,SAAS,MAAM,QAAQ;GAAS;GACrD,QAAQ,IAAI,UAAU,MAAM;EAC9B;EAEA,OAAO;EAEP,MAAM,YAAY,KAAK,IAAI,GAAG,QAAQ,MAAM,OAAO,KAAK;EACxD,MAAM,aAAa,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,UAAU,OAAO,GAAI,CAAC;EAEvE,SAAS,OAAO,qBAAqB,QAAQ,GAAG;EAChD,SAAS,OAAO,yBAAyB,SAAS;EAClD,SAAS,OAAO,qBAAqB,KAAK,KAAK,OAAO,UAAU,GAAI,CAAC;EAErE,IAAI,OAAO,QAAQ,QAAQ,KAAK;GAC9B,SAAS,OAAO,eAAe,UAAU;GAEzC,OAAO,SAAS,gBAAgB;IAC9B,OAAO,QAAQ,gBAAgB,EAAE,wBAAwB;IACzD;GACF,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"rate-limit.middleware.mjs","names":[],"sources":["../../../../../../../../core/src/http/middleware/rate-limit.middleware.ts"],"sourcesContent":["import type { Middleware } from \"../../router\";\nimport { HttpErrorCodes } from \"../error-codes\";\nimport type { Request } from \"../request\";\nimport { t } from \"./inject-request-context\";\n\n/**\n * Options for the per-route rate limit middleware.\n */\nexport type RateLimitOptions = {\n /**\n * Max requests allowed within the time window.\n */\n max: number;\n /**\n * Time window in milliseconds.\n */\n duration: number;\n /**\n * Group key generator. Defaults to the client IP. Override to scope per-user,\n * per-organization, per-tenant, etc.\n *\n * @example\n * keyGenerator: (request) => request.locals.user?.id ?? request.ip,\n */\n keyGenerator?: (request: Request) => string;\n /**\n * Override the default error message.\n */\n errorMessage?: string;\n};\n\ntype Bucket = {\n count: number;\n resetAt: number;\n};\n\nconst buckets = new Map<string, Bucket>();\n\n/**\n * Sweep expired buckets so the Map doesn't grow unbounded with one-shot keys\n * (rare per-user keys, dynamic path parameters in `keyGenerator`, etc.).\n * Called opportunistically, at most once per minute, not on a timer — keeps\n * the module side-effect-free for testing.\n */\nlet lastPruneAt = 0;\n\nfunction pruneExpired(now: number) {\n for (const [key, bucket] of buckets) {\n if (bucket.resetAt <= now) {\n buckets.delete(key);\n }\n }\n}\n\n/**\n * Per-route / per-group rate limit. Layers on top of `@fastify/rate-limit`'s\n * global cap (configured via `http.rateLimit`) — both run, and either can\n * 429. Use this for endpoints that need a tighter cap than the global default:\n * login, OTP request, password reset, expensive search, AI completions.\n *\n * The counter lives in-process. With `N` replicas the effective cap is\n * `N × max`. For genuinely shared limits, configure `@fastify/rate-limit`'s\n * Redis store via `http.rateLimit` instead.\n *\n * Sets `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` on\n * every response; adds `Retry-After` (seconds) on a 429.\n *\n * @example\n * import { middleware } from \"@warlock.js/core\";\n * router.post(\"/auth/login\", loginController, {\n * middleware: [middleware.rateLimit({ max: 5, duration: 60_000 })],\n * });\n */\nexport function rateLimitMiddleware(options: RateLimitOptions): Middleware {\n return ({ request, response }) => {\n const now = Date.now();\n\n if (now - lastPruneAt > 60_000) {\n pruneExpired(now);\n lastPruneAt = now;\n }\n\n const groupKey = options.keyGenerator?.(request) || request.detectIp() || \"unknown\";\n const cacheKey = `${request.route.path}:${groupKey}`;\n\n let bucket = buckets.get(cacheKey);\n\n if (!bucket || bucket.resetAt <= now) {\n bucket = { count: 0, resetAt: now + options.duration };\n buckets.set(cacheKey, bucket);\n }\n\n bucket.count++;\n\n const remaining = Math.max(0, options.max - bucket.count);\n const retryAfter = Math.max(1, Math.ceil((bucket.resetAt - now) / 1000));\n\n response.header(\"X-RateLimit-Limit\", options.max);\n response.header(\"X-RateLimit-Remaining\", remaining);\n response.header(\"X-RateLimit-Reset\", Math.ceil(bucket.resetAt / 1000));\n\n if (bucket.count > options.max) {\n response.header(\"Retry-After\", retryAfter);\n\n return response.tooManyRequests({\n error: options.errorMessage || t(\"http.rateLimitExceeded\"),\n errorCode: HttpErrorCodes.RateLimitExceeded,\n });\n }\n };\n}\n"],"mappings":";;;;AAoCA,MAAM,0BAAU,IAAI,IAAoB;;;;;;;AAQxC,IAAI,cAAc;AAElB,SAAS,aAAa,KAAa;CACjC,KAAK,MAAM,CAAC,KAAK,WAAW,SAC1B,IAAI,OAAO,WAAW,KACpB,QAAQ,OAAO,GAAG;AAGxB;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,oBAAoB,SAAuC;CACzE,QAAQ,EAAE,SAAS,eAAe;EAChC,MAAM,MAAM,KAAK,IAAI;EAErB,IAAI,MAAM,cAAc,KAAQ;GAC9B,aAAa,GAAG;GAChB,cAAc;EAChB;EAEA,MAAM,WAAW,QAAQ,eAAe,OAAO,KAAK,QAAQ,SAAS,KAAK;EAC1E,MAAM,WAAW,GAAG,QAAQ,MAAM,KAAK,GAAG;EAE1C,IAAI,SAAS,QAAQ,IAAI,QAAQ;EAEjC,IAAI,CAAC,UAAU,OAAO,WAAW,KAAK;GACpC,SAAS;IAAE,OAAO;IAAG,SAAS,MAAM,QAAQ;GAAS;GACrD,QAAQ,IAAI,UAAU,MAAM;EAC9B;EAEA,OAAO;EAEP,MAAM,YAAY,KAAK,IAAI,GAAG,QAAQ,MAAM,OAAO,KAAK;EACxD,MAAM,aAAa,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,UAAU,OAAO,GAAI,CAAC;EAEvE,SAAS,OAAO,qBAAqB,QAAQ,GAAG;EAChD,SAAS,OAAO,yBAAyB,SAAS;EAClD,SAAS,OAAO,qBAAqB,KAAK,KAAK,OAAO,UAAU,GAAI,CAAC;EAErE,IAAI,OAAO,QAAQ,QAAQ,KAAK;GAC9B,SAAS,OAAO,eAAe,UAAU;GAEzC,OAAO,SAAS,gBAAgB;IAC9B,OAAO,QAAQ,gBAAgB,EAAE,wBAAwB;IACzD;GACF,CAAC;EACH;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"idempotency-key.d.mts","names":[],"sources":["../../../../../../../../../core/src/http/middleware/utils/idempotency-key.ts"],"mappings":";;;iBAegB,qBAAA,CAAsB,KAAA,YAAiB,KAAK;;AAA5D;;;;AAA4D;AAmB5D;;;;iBAAgB,QAAA,CAAS,IAAa;AAAA,iBAyCtB,wBAAA,CAAyB,OAAA,EAAS,OAAO,EAAE,cAAA"}
1
+ {"version":3,"file":"idempotency-key.d.mts","names":[],"sources":["../../../../../../../../../core/src/http/middleware/utils/idempotency-key.ts"],"mappings":";;;iBAcgB,qBAAA,CAAsB,KAAA,YAAiB,KAAK;;AAA5D;;;;AAA4D;AAmB5D;;;;iBAAgB,QAAA,CAAS,IAAa;AAAA,iBAuCtB,wBAAA,CAAyB,OAAA,EAAS,OAAO,EAAE,cAAA"}
@@ -36,24 +36,22 @@ function hashBody(body) {
36
36
  * user B used a guessable value — while still letting the primitive work on
37
37
  * public endpoints.
38
38
  *
39
- * Idempotency middleware must run **after** `authMiddleware` so `request.user`
40
- * and `request.decodedAccessToken` are populated.
39
+ * Idempotency middleware must run **after** `authMiddleware` so
40
+ * `request.locals.user` (written by `@warlock.js/auth`) and
41
+ * `request.decodedAccessToken` are populated.
41
42
  *
42
43
  * @example
43
44
  * buildIdempotencyCacheKey(request, "01J9XZQ-ABC"); // "idem:client:user_123:01J9XZQ-ABC"
44
45
  */
45
46
  /**
46
- * Read `id` off `request.user` without assuming every app's `RequestUser`
47
- * augmentation declares it.
47
+ * Read `id` off `request.locals.user` without assuming any app's
48
+ * `RequestUser` augmentation (declared by `@warlock.js/auth`, which core
49
+ * cannot import) declares it, and without assuming `@warlock.js/auth` is
50
+ * even installed — hence the untyped `unknown` read here rather than a
51
+ * typed `RequestLocals["user"]` access.
48
52
  *
49
- * `RequestUser` (`core/src/http/types.ts`) is empty by defaultapps narrow
50
- * it to their own model shape. Adding `id` directly to `RequestUser` here
51
- * would force that exact field (and type) onto every app: TypeScript
52
- * interface merging requires all declarations of a shared member to have an
53
- * identical type, so an app augmenting `RequestUser` with, say, `id: string`
54
- * only would conflict with a core-declared `id?: string | number`. A local,
55
- * narrow read survives any augmentation shape (eed20184 step (b) —
56
- * `implementation/2026-08-20-A2-request-locals.md` §6.2) — no `as any`.
53
+ * A local, narrow runtime read survives any augmentation shape no
54
+ * `as any`.
57
55
  */
58
56
  function readUserId(user) {
59
57
  if (!user || typeof user !== "object" || !("id" in user)) return void 0;
@@ -61,7 +59,9 @@ function readUserId(user) {
61
59
  return typeof id === "string" || typeof id === "number" ? id : void 0;
62
60
  }
63
61
  function buildIdempotencyCacheKey(request, idempotencyKey) {
64
- return `idem:${request.decodedAccessToken?.userType || "anonymous"}:${readUserId(request.user) || request.detectIp() || "unknown"}:${idempotencyKey}`;
62
+ const userType = request.decodedAccessToken?.userType || "anonymous";
63
+ const locals = request.locals;
64
+ return `idem:${userType}:${readUserId(locals.user) || request.detectIp() || "unknown"}:${idempotencyKey}`;
65
65
  }
66
66
 
67
67
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"idempotency-key.mjs","names":[],"sources":["../../../../../../../../../core/src/http/middleware/utils/idempotency-key.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Request } from \"../../request\";\nimport type { RequestUser } from \"../../types\";\n\n/**\n * Idempotency-key validation rules.\n *\n * RFC draft-ietf-httpapi-idempotency-key suggests UUIDs or ULIDs but doesn't\n * mandate a format. We accept any printable ASCII string up to 255 chars —\n * tight enough to reject log-injection (no control characters / newlines),\n * loose enough to accept whatever ID scheme the client picks.\n */\nconst MAX_KEY_LENGTH = 255;\nconst PRINTABLE_ASCII = /^[\\x21-\\x7e]+$/;\n\nexport function isValidIdempotencyKey(value: unknown): value is string {\n return (\n typeof value === \"string\" &&\n value.length > 0 &&\n value.length <= MAX_KEY_LENGTH &&\n PRINTABLE_ASCII.test(value)\n );\n}\n\n/**\n * Hash a request body to a stable hex digest.\n *\n * Used to detect \"same key, different body\" — that's a client bug, not a retry.\n * sha256 is overkill for collision resistance here, but it's the dependency-free\n * choice and avoids importing a faster hasher.\n *\n * @example\n * hashBody({ amount: 100, currency: \"USD\" }); // \"a1b2c3...\"\n */\nexport function hashBody(body: unknown): string {\n const serialized = typeof body === \"string\" ? body : JSON.stringify(body ?? {});\n\n return createHash(\"sha256\").update(serialized).digest(\"hex\");\n}\n\n/**\n * Build the cache key for an idempotency record.\n *\n * Scope is `userType:userId` when authenticated, falling back to the client IP\n * when anonymous. This prevents user A from replaying user B's key — even if\n * user B used a guessable value — while still letting the primitive work on\n * public endpoints.\n *\n * Idempotency middleware must run **after** `authMiddleware` so `request.user`\n * and `request.decodedAccessToken` are populated.\n *\n * @example\n * buildIdempotencyCacheKey(request, \"01J9XZQ-ABC\"); // \"idem:client:user_123:01J9XZQ-ABC\"\n */\n/**\n * Read `id` off `request.user` without assuming every app's `RequestUser`\n * augmentation declares it.\n *\n * `RequestUser` (`core/src/http/types.ts`) is empty by default apps narrow\n * it to their own model shape. Adding `id` directly to `RequestUser` here\n * would force that exact field (and type) onto every app: TypeScript\n * interface merging requires all declarations of a shared member to have an\n * identical type, so an app augmenting `RequestUser` with, say, `id: string`\n * only would conflict with a core-declared `id?: string | number`. A local,\n * narrow read survives any augmentation shape (eed20184 step (b) —\n * `implementation/2026-08-20-A2-request-locals.md` §6.2) — no `as any`.\n */\nfunction readUserId(user: RequestUser | undefined): string | number | undefined {\n if (!user || typeof user !== \"object\" || !(\"id\" in user)) return undefined;\n\n const id = (user as { id?: unknown }).id;\n\n return typeof id === \"string\" || typeof id === \"number\" ? id : undefined;\n}\n\nexport function buildIdempotencyCacheKey(request: Request, idempotencyKey: string): string {\n const userType = request.decodedAccessToken?.userType || \"anonymous\";\n const userId = readUserId(request.user) || request.detectIp() || \"unknown\";\n\n return `idem:${userType}:${userId}:${idempotencyKey}`;\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AAExB,SAAgB,sBAAsB,OAAiC;CACrE,OACE,OAAO,UAAU,YACjB,MAAM,SAAS,KACf,MAAM,UAAU,kBAChB,gBAAgB,KAAK,KAAK;AAE9B;;;;;;;;;;;AAYA,SAAgB,SAAS,MAAuB;CAC9C,MAAM,aAAa,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,QAAQ,CAAC,CAAC;CAE9E,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,OAAO,KAAK;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAS,WAAW,MAA4D;CAC9E,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,EAAE,QAAQ,OAAO,OAAO;CAEjE,MAAM,KAAM,KAA0B;CAEtC,OAAO,OAAO,OAAO,YAAY,OAAO,OAAO,WAAW,KAAK;AACjE;AAEA,SAAgB,yBAAyB,SAAkB,gBAAgC;CAIzF,OAAO,QAHU,QAAQ,oBAAoB,YAAY,YAGjC,GAFT,WAAW,QAAQ,IAAI,KAAK,QAAQ,SAAS,KAAK,UAE/B,GAAG;AACvC"}
1
+ {"version":3,"file":"idempotency-key.mjs","names":[],"sources":["../../../../../../../../../core/src/http/middleware/utils/idempotency-key.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Request } from \"../../request\";\n\n/**\n * Idempotency-key validation rules.\n *\n * RFC draft-ietf-httpapi-idempotency-key suggests UUIDs or ULIDs but doesn't\n * mandate a format. We accept any printable ASCII string up to 255 chars —\n * tight enough to reject log-injection (no control characters / newlines),\n * loose enough to accept whatever ID scheme the client picks.\n */\nconst MAX_KEY_LENGTH = 255;\nconst PRINTABLE_ASCII = /^[\\x21-\\x7e]+$/;\n\nexport function isValidIdempotencyKey(value: unknown): value is string {\n return (\n typeof value === \"string\" &&\n value.length > 0 &&\n value.length <= MAX_KEY_LENGTH &&\n PRINTABLE_ASCII.test(value)\n );\n}\n\n/**\n * Hash a request body to a stable hex digest.\n *\n * Used to detect \"same key, different body\" — that's a client bug, not a retry.\n * sha256 is overkill for collision resistance here, but it's the dependency-free\n * choice and avoids importing a faster hasher.\n *\n * @example\n * hashBody({ amount: 100, currency: \"USD\" }); // \"a1b2c3...\"\n */\nexport function hashBody(body: unknown): string {\n const serialized = typeof body === \"string\" ? body : JSON.stringify(body ?? {});\n\n return createHash(\"sha256\").update(serialized).digest(\"hex\");\n}\n\n/**\n * Build the cache key for an idempotency record.\n *\n * Scope is `userType:userId` when authenticated, falling back to the client IP\n * when anonymous. This prevents user A from replaying user B's key — even if\n * user B used a guessable value — while still letting the primitive work on\n * public endpoints.\n *\n * Idempotency middleware must run **after** `authMiddleware` so\n * `request.locals.user` (written by `@warlock.js/auth`) and\n * `request.decodedAccessToken` are populated.\n *\n * @example\n * buildIdempotencyCacheKey(request, \"01J9XZQ-ABC\"); // \"idem:client:user_123:01J9XZQ-ABC\"\n */\n/**\n * Read `id` off `request.locals.user` without assuming any app's\n * `RequestUser` augmentation (declared by `@warlock.js/auth`, which core\n * cannot import) declares it, and without assuming `@warlock.js/auth` is\n * even installed hence the untyped `unknown` read here rather than a\n * typed `RequestLocals[\"user\"]` access.\n *\n * A local, narrow runtime read survives any augmentation shape no\n * `as any`.\n */\nfunction readUserId(user: unknown): string | number | undefined {\n if (!user || typeof user !== \"object\" || !(\"id\" in user)) return undefined;\n\n const id = (user as { id?: unknown }).id;\n\n return typeof id === \"string\" || typeof id === \"number\" ? id : undefined;\n}\n\nexport function buildIdempotencyCacheKey(request: Request, idempotencyKey: string): string {\n const userType = request.decodedAccessToken?.userType || \"anonymous\";\n const locals = request.locals as Record<string, unknown>;\n const userId = readUserId(locals.user) || request.detectIp() || \"unknown\";\n\n return `idem:${userType}:${userId}:${idempotencyKey}`;\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AAExB,SAAgB,sBAAsB,OAAiC;CACrE,OACE,OAAO,UAAU,YACjB,MAAM,SAAS,KACf,MAAM,UAAU,kBAChB,gBAAgB,KAAK,KAAK;AAE9B;;;;;;;;;;;AAYA,SAAgB,SAAS,MAAuB;CAC9C,MAAM,aAAa,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,QAAQ,CAAC,CAAC;CAE9E,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,OAAO,KAAK;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,WAAW,MAA4C;CAC9D,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,EAAE,QAAQ,OAAO,OAAO;CAEjE,MAAM,KAAM,KAA0B;CAEtC,OAAO,OAAO,OAAO,YAAY,OAAO,OAAO,WAAW,KAAK;AACjE;AAEA,SAAgB,yBAAyB,SAAkB,gBAAgC;CACzF,MAAM,WAAW,QAAQ,oBAAoB,YAAY;CACzD,MAAM,SAAS,QAAQ;CAGvB,OAAO,QAAQ,SAAS,GAFT,WAAW,OAAO,IAAI,KAAK,QAAQ,SAAS,KAAK,UAE9B,GAAG;AACvC"}
@@ -1,5 +1,5 @@
1
- import { Request } from "./request.mjs";
2
1
  import { Response } from "./response.mjs";
2
+ import { Request } from "./request.mjs";
3
3
  import { ReturnedResponse } from "./types.mjs";
4
4
  import { RequestControllerContract } from "../router/types.mjs";
5
5
 
@@ -1,6 +1,6 @@
1
- import { UploadedFile } from "./uploaded-file.mjs";
2
1
  import { Response } from "./response.mjs";
3
- import { DecodedAccessToken, RequestEvent, RequestLocals, RequestUser } from "./types.mjs";
2
+ import { UploadedFile } from "./uploaded-file.mjs";
3
+ import { DecodedAccessToken, RequestEvent, RequestLocals } from "./types.mjs";
4
4
  import { Middleware, RequestHandler, Route } from "../router/types.mjs";
5
5
  import { BaseValidator } from "@warlock.js/seal";
6
6
  import { trans } from "@mongez/localization";
@@ -18,7 +18,8 @@ declare class Request<RequestValidation = any> {
18
18
  *
19
19
  * **Prefer framework methods first**: `request.input()`, `request.header()`,
20
20
  * `request.body`, `request.query`, `request.params`, `request.file()`,
21
- * `request.user`, `request.detectIp()`, etc. They handle locale, parsing,
21
+ * `request.locals.user` (set by `@warlock.js/auth`), `request.detectIp()`,
22
+ * etc. They handle locale, parsing,
22
23
  * trust-proxy, and validation pipeline integration correctly.
23
24
  *
24
25
  * **Reach for `baseRequest` only** when the framework genuinely lacks a
@@ -54,38 +55,23 @@ declare class Request<RequestValidation = any> {
54
55
  get decodedAccessToken(): DecodedAccessToken | undefined;
55
56
  set decodedAccessToken(value: DecodedAccessToken | undefined);
56
57
  /**
57
- * Backing field for `user` see the accessor below.
58
- */
59
- private _user?;
60
- /**
61
- * The authenticated user attached to this request, if any.
62
- *
63
- * `RequestUser` is empty by default, so ANY shape is assignable here at the
64
- * declaration site — the app or auth package declares its real fields via
65
- * module augmentation:
58
+ * REMOVED in 5.12.0 — the authenticated user now lives at
59
+ * `request.locals.user`, a key `@warlock.js/auth` declares via module
60
+ * augmentation on `RequestLocals` and writes from its middleware after a
61
+ * successful token resolution. `RequestUser` moved out of core to
62
+ * `@warlock.js/auth` alongside it.
66
63
  *
67
- * ```typescript
68
- * declare module "@warlock.js/core" {
69
- * interface RequestUser {
70
- * id: string | number;
71
- * }
72
- * }
73
- * ```
64
+ * This getter is a development-time diagnostic only, kept for one release
65
+ * so a call site that still reads `request.user` fails loudly at runtime
66
+ * instead of silently reading `undefined`. It is typed `never` so it
67
+ * cannot reintroduce an auth-shaped type into core, and it throws
68
+ * unconditionally outside production so the failure is impossible to miss
69
+ * in local dev — see `RequestUserMovedError`.
74
70
  *
75
- * Replaces the v4 `GuardedRequest` convention
76
- * (`create-warlock/.../guarded.request.ts` — `Request<T> & { user: User }`,
77
- * an intersection type hand-declared per app) with a property core itself
78
- * declares and types. `clearCurrentUser()` below is the one place core
79
- * writes it directly; auth middleware writes it after a successful token
80
- * resolution.
81
- *
82
- * A prototype accessor, not a plain field: the setter also marks the
83
- * request `authDerived` (see below), so `clearCurrentUser()`'s
84
- * `this.user = undefined` still counts as touching auth state rather than
85
- * un-marking it.
71
+ * There is no setter: nothing in core or downstream packages should ever
72
+ * assign to `request.user` again.
86
73
  */
87
- get user(): RequestUser | undefined;
88
- set user(value: RequestUser | undefined);
74
+ get user(): never;
89
75
  /**
90
76
  * Private, server-only, per-request data bag.
91
77
  *
@@ -115,18 +101,6 @@ declare class Request<RequestValidation = any> {
115
101
  * a prior one.
116
102
  */
117
103
  locals: RequestLocals;
118
- /**
119
- * Forget the authenticated user for this request.
120
- *
121
- * The `user` documentation above already names this as "the one place core
122
- * writes it directly", and `@warlock.js/auth`'s middleware already calls it when
123
- * a token is forged, malformed, expired, or of the wrong type. It was designed,
124
- * documented and called — just never written, so `auth` could not typecheck.
125
- *
126
- * Clearing rather than leaving a stale value matters: a request that failed
127
- * authentication must not carry the identity of whoever this object last held.
128
- */
129
- clearCurrentUser(): void;
130
104
  /**
131
105
  * Backing field for the lazily-generated CSP nonce. Left `undefined` until
132
106
  * the first `request.nonce` read; see the `nonce` getter below.
@@ -180,6 +154,12 @@ declare class Request<RequestValidation = any> {
180
154
  * Request id
181
155
  */
182
156
  id: string;
157
+ /**
158
+ * Trace id. The inbound `traceparent` header's trace id
159
+ * when valid, otherwise `id`. Resolved once in `setRequest`, alongside
160
+ * `id` itself — see `resolveTraceId`.
161
+ */
162
+ traceId: string;
183
163
  /**
184
164
  * Start Time
185
165
  */
@@ -202,6 +182,14 @@ declare class Request<RequestValidation = any> {
202
182
  * default is used regardless of any incoming header.
203
183
  */
204
184
  protected resolveRequestId(): void;
185
+ /**
186
+ * Derive `traceId`: the inbound
187
+ * `traceparent` header's trace id when it is a valid W3C traceparent,
188
+ * otherwise `id`. Always runs — unlike request-id inheritance this has no
189
+ * `enabled: false` escape hatch, since `traceId` is only ever read when
190
+ * tracing hooks are enabled (see `./tracing`).
191
+ */
192
+ protected resolveTraceId(): void;
205
193
  /**
206
194
  * Validate a candidate request-id value. Accepts non-empty printable ASCII
207
195
  * up to 128 characters — tight enough to reject newline / control-character
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.mts","names":[],"sources":["../../../../../../../core/src/http/request.ts"],"mappings":";;;;;;;;;;;KAoBK,eAAA,iBAIU,mBAAA,mBAAsC,CAAA,0BAA2B,CAAA,WAAY,CAAA,GACvF,mBAAA,CAAoB,CAAA;AAAA,KAGpB,UAAA,SAAmB,eAAe;AAAA,cAE1B,OAAA;;;;;;;;;;;;;;;;EAgBJ,WAAA,EAAc,cAAA;EArBG;AAAA;AAAA;EA0BjB,QAAA,EAAW,QAAA;;;AAvBmB;EA4B9B,KAAA,EAAQ,KAAA;EA1BG;;;EAAA,UA+BR,OAAA;EALK;;;EAAA,QAUP,mBAAA;EAsDe;;;;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