@classytic/arc 2.52.0 → 2.53.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 (222) hide show
  1. package/README.md +2 -1
  2. package/dist/{EventTransport-DeNze_-C.mjs → EventTransport-B3jTKMQH.mjs} +2 -2
  3. package/dist/{HookSystem-DTffXM1X.mjs → HookSystem-DNwxV463.mjs} +2 -2
  4. package/dist/{ResourceRegistry-tlqXSZoK.mjs → ResourceRegistry-Ck7RFodL.mjs} +2 -2
  5. package/dist/{acquire-7JKEkKnN.mjs → acquire-DkLruwhL.mjs} +1 -1
  6. package/dist/audit/index.d.mts +1 -1
  7. package/dist/audit/index.mjs +4 -4
  8. package/dist/auth/audit.mjs +1 -1
  9. package/dist/auth/index.d.mts +1 -1
  10. package/dist/auth/index.mjs +7 -7
  11. package/dist/auth/redis-session.mjs +1 -1
  12. package/dist/auth/social/index.mjs +1 -1
  13. package/dist/{authorizationDecision-DKmH4tZ-.mjs → authorizationDecision-gB5-bHDp.mjs} +5 -5
  14. package/dist/bootError-BT3z3cvX.mjs +38 -0
  15. package/dist/{boundedMap-zxGBpXX0.mjs → boundedMap-Ddw2yGb2.mjs} +1 -1
  16. package/dist/{buildHandler-ZDV6LRZ_.mjs → buildHandler-B8IDGmhD.mjs} +5 -5
  17. package/dist/cache/index.mjs +4 -4
  18. package/dist/{caching-DceUN9Xk.mjs → caching-BitJDAY0.mjs} +2 -2
  19. package/dist/{claimed-DsP5Hi_f.mjs → claimed-CM_-lFHX.mjs} +1 -1
  20. package/dist/cleanup/index.d.mts +2 -2
  21. package/dist/cleanup/index.mjs +4 -4
  22. package/dist/cli/commands/describe.d.mts +18 -1
  23. package/dist/cli/commands/describe.mjs +39 -7
  24. package/dist/cli/commands/docs.mjs +3 -3
  25. package/dist/cli/commands/doctor.d.mts +3 -1
  26. package/dist/cli/commands/doctor.mjs +135 -22
  27. package/dist/cli/commands/generate.mjs +2 -2
  28. package/dist/cli/commands/init.mjs +2 -2
  29. package/dist/cli/commands/introspect.mjs +2 -2
  30. package/dist/cli/index.mjs +3 -3
  31. package/dist/{constants-Ca2IQFy2.mjs → constants-D9EiaO5s.mjs} +1 -1
  32. package/dist/context/index.d.mts +5 -2
  33. package/dist/context/index.mjs +5 -5
  34. package/dist/core/index.d.mts +2 -2
  35. package/dist/core/index.mjs +7 -7
  36. package/dist/{core-M18RhMqi.mjs → core-B_06Fcn0.mjs} +3 -3
  37. package/dist/{createActionRouter-zXlrwWVs.mjs → createActionRouter-DtxUXOCI.mjs} +5 -5
  38. package/dist/{createAggregationRouter-CN0Da9nC.mjs → createAggregationRouter-BMiKyDoW.mjs} +7 -7
  39. package/dist/{createApp-BC67ACu4.mjs → createApp-CEdGZtkP.mjs} +207 -44
  40. package/dist/{createMcpServer-CS2KOVP6.d.mts → createMcpServer-Bk3ls5jS.d.mts} +1 -1
  41. package/dist/{defineAggregation-DqAGb5oI.mjs → defineAggregation-DUsrGcsm.mjs} +1 -1
  42. package/dist/{defineResource-DC5UqkQv.mjs → defineResource-q8TsJpOm.mjs} +92 -36
  43. package/dist/deprecation-DX625dth.mjs +27 -0
  44. package/dist/discovery/index.mjs +1 -1
  45. package/dist/docs/index.d.mts +1 -1
  46. package/dist/docs/index.mjs +3 -3
  47. package/dist/{elevation-DiXVg98q.mjs → elevation-NJ3908pJ.mjs} +5 -5
  48. package/dist/encryption/index.mjs +3 -3
  49. package/dist/{errorHandler-BUTm9P_f.mjs → errorHandler-Ke6PGvF7.mjs} +7 -4
  50. package/dist/{errors-DxpHZBlW.mjs → errors-Ukhmfmmx.mjs} +1 -1
  51. package/dist/{eventPlugin-BY38F6yK.d.mts → eventPlugin-BeJasppx.d.mts} +7 -18
  52. package/dist/{eventPlugin-ZsIQPRso.mjs → eventPlugin-DTKAgSvb.mjs} +10 -8
  53. package/dist/{eventTypes-D-pFtqT1.mjs → eventTypes-DpDQtyR6.mjs} +2 -2
  54. package/dist/events/index.d.mts +2 -2
  55. package/dist/events/index.mjs +8 -8
  56. package/dist/events/transports/redis-stream-entry.mjs +4 -4
  57. package/dist/events/transports/redis.mjs +2 -2
  58. package/dist/factory/index.d.mts +28 -5
  59. package/dist/factory/index.mjs +12 -7
  60. package/dist/{fastify-augmentation-CPReFhZ1.d.mts → fastify-augmentation-DjxuSRG4.d.mts} +4 -3
  61. package/dist/{fieldTypes-f-3TZgR3.mjs → fieldTypes-BtFpQO6I.mjs} +2 -2
  62. package/dist/{fields-kCbIDTjA.mjs → fields-B7fuROWK.mjs} +1 -1
  63. package/dist/{filter-merge-UJCgjbZR.mjs → filter-merge-BuzZ-r9z.mjs} +1 -1
  64. package/dist/{generate-CLpmzbJ_.mjs → generate-c4F39pk1.mjs} +4 -4
  65. package/dist/{headers-Bh47h0XH.mjs → headers-Ib7BDgRI.mjs} +2 -2
  66. package/dist/{health-CEpgVAl7.mjs → health-22T82HAa.mjs} +1 -1
  67. package/dist/health-skjSwNaC.d.mts +36 -0
  68. package/dist/hooks/index.d.mts +1 -1
  69. package/dist/hooks/index.mjs +2 -2
  70. package/dist/http-cache/index.mjs +4 -4
  71. package/dist/http-cache/purgers/cloudflare.mjs +2 -2
  72. package/dist/http-cache/purgers/fastly.mjs +2 -2
  73. package/dist/http-cache/testing/index.mjs +1 -1
  74. package/dist/idempotency/index.d.mts +7 -1
  75. package/dist/idempotency/index.mjs +9 -7
  76. package/dist/idempotency/redis.mjs +2 -2
  77. package/dist/{index-CMNpMBtW.d.mts → index-BzUyno-u.d.mts} +14 -5
  78. package/dist/{index-yXXCsKl7.d.mts → index-CXqYFGoH.d.mts} +13 -4
  79. package/dist/{index-CSbDhif4.d.mts → index-CaBFPmnu.d.mts} +10 -6
  80. package/dist/{index-DCH08eqQ.d.mts → index-DWn0o4U7.d.mts} +2 -2
  81. package/dist/{index-DLCcLUQT.d.mts → index-DtHACefu.d.mts} +109 -116
  82. package/dist/index.d.mts +5 -5
  83. package/dist/index.mjs +12 -12
  84. package/dist/{init-B43DXBpc.mjs → init-XY5slyuS.mjs} +3 -3
  85. package/dist/integrations/event-gateway.mjs +2 -2
  86. package/dist/integrations/index.d.mts +1 -1
  87. package/dist/integrations/index.mjs +1 -1
  88. package/dist/integrations/jobs/index.mjs +3 -3
  89. package/dist/integrations/mcp/index.d.mts +9 -4
  90. package/dist/integrations/mcp/index.mjs +2 -2
  91. package/dist/integrations/mcp/testing.d.mts +2 -2
  92. package/dist/integrations/mcp/testing.mjs +2 -2
  93. package/dist/integrations/streamline.mjs +3 -3
  94. package/dist/integrations/webhooks.d.mts +1 -1
  95. package/dist/integrations/webhooks.mjs +4 -4
  96. package/dist/integrations/websocket-pushref-redis.mjs +1 -1
  97. package/dist/integrations/websocket-redis.mjs +1 -1
  98. package/dist/integrations/websocket.mjs +2 -2
  99. package/dist/invariants-COekUeoh.mjs +120 -0
  100. package/dist/{jsonBody-CkKs6dA_.mjs → jsonBody-BNlcGUnb.mjs} +2 -2
  101. package/dist/{keys-DHrHnT0f.mjs → keys-DwvXJwUX.mjs} +1 -1
  102. package/dist/{loadResources-CFdzAWQZ.mjs → loadResources-izEeQLO_.mjs} +3 -3
  103. package/dist/{loadResourcesFromEntry-DkoSiJsI.mjs → loadResourcesFromEntry-CijqjbHE.mjs} +2 -2
  104. package/dist/logger/index.mjs +2 -2
  105. package/dist/{logger-DJwz_-Pl.mjs → logger-DdMS0XC_.mjs} +1 -1
  106. package/dist/{mcpPlugin-CA_MDFlS.mjs → mcpPlugin-D0tSZqKk.mjs} +24 -22
  107. package/dist/{memory-B9CFHbA_.mjs → memory-Ay0haw9n.mjs} +3 -3
  108. package/dist/{metrics-DSKv-T9K.mjs → metrics-Bpgf4UL6.mjs} +3 -3
  109. package/dist/middleware/index.d.mts +1 -1
  110. package/dist/middleware/index.mjs +3 -3
  111. package/dist/migrations/index.mjs +2 -2
  112. package/dist/{module-C0JCsnO7.mjs → module-BLrTmMyk.mjs} +1 -1
  113. package/dist/{multiTenant-QtDzxx_K.d.mts → multiTenant-Cf0Ye-Wu.d.mts} +1 -1
  114. package/dist/{multipartBody-Bxz-q6hI.mjs → multipartBody-L2gr96df.mjs} +1 -1
  115. package/dist/{observeSend-DfNkdGww.mjs → observeSend-B7FEdk_g.mjs} +1 -1
  116. package/dist/{openapi-Dmp7Ipsi.mjs → openapi-COrL_33P.mjs} +6 -6
  117. package/dist/outbox-admin/index.d.mts +1 -1
  118. package/dist/outbox-admin/index.mjs +6 -6
  119. package/dist/{outbox-module-vT6PaThj.mjs → outbox-module-BY2HtnjU.mjs} +7 -7
  120. package/dist/{outbox-module-DzW6zwWJ.d.mts → outbox-module-C1QWMloZ.d.mts} +5 -8
  121. package/dist/permissions/index.d.mts +2 -2
  122. package/dist/permissions/index.mjs +8 -8
  123. package/dist/{permissions-Cga6KBOX.mjs → permissions-CEyeDHtT.mjs} +36 -17
  124. package/dist/{pipe-CqPweKdL.mjs → pipe-DIAr91at.mjs} +2 -2
  125. package/dist/pipeline/index.d.mts +1 -1
  126. package/dist/pipeline/index.mjs +2 -2
  127. package/dist/{plan-CbDTFbTj.mjs → plan-BhKHIkFl.mjs} +75 -20
  128. package/dist/{plugin-8Z1khbAI.mjs → plugin-D6hrdx-j.mjs} +72 -38
  129. package/dist/plugins/index.d.mts +4 -3
  130. package/dist/plugins/index.mjs +18 -18
  131. package/dist/plugins/response-cache.mjs +4 -4
  132. package/dist/plugins/tracing-entry.mjs +177 -85
  133. package/dist/{pluralize-D4vcPLVs.mjs → pluralize-CJKgYkVc.mjs} +1 -1
  134. package/dist/presetPermission-2pcRVYRG.mjs +23 -0
  135. package/dist/presets/filesUpload.d.mts +4 -2
  136. package/dist/presets/filesUpload.mjs +11 -6
  137. package/dist/presets/index.d.mts +6 -4
  138. package/dist/presets/index.mjs +2 -2
  139. package/dist/presets/multiTenant.d.mts +1 -1
  140. package/dist/presets/multiTenant.mjs +5 -5
  141. package/dist/presets/search.d.mts +2 -2
  142. package/dist/presets/search.mjs +54 -38
  143. package/dist/{presets-D28IABZe.mjs → presets-st11ePNn.mjs} +150 -41
  144. package/dist/{projection-aHCtDQQ9.mjs → projection-B4rqiJTi.mjs} +2 -2
  145. package/dist/{purger.types-CNFmEtFu.mjs → purger.types-BcHeAhY_.mjs} +1 -1
  146. package/dist/{queryCachePlugin-CwpEjCwz.mjs → queryCachePlugin-BgSc2bga.mjs} +6 -6
  147. package/dist/rateLimitKey-DLGdeFd2.mjs +138 -0
  148. package/dist/{realtime-Dvu8ES2z.mjs → realtime-CpYpIFsm.mjs} +11 -11
  149. package/dist/registry/index.d.mts +2 -2
  150. package/dist/registry/index.mjs +3 -3
  151. package/dist/{registry-DmxbzW7-.mjs → registry-BQsdAlZ_.mjs} +2 -2
  152. package/dist/{relay-CEaCmUfG.mjs → relay-CmT3gtkP.mjs} +11 -12
  153. package/dist/{renewingLease-g2FjB3im.mjs → renewingLease-DaoP0K-e.mjs} +1 -1
  154. package/dist/{replyHelpers-CSByAX_Z.mjs → replyHelpers-SiLr1wK4.mjs} +2 -2
  155. package/dist/{requestContext-yc7MSgmq.mjs → requestContext-B-TjFpWt.mjs} +8 -3
  156. package/dist/{health-W4S2yFBL.mjs → requestId-ClcKoWLq.mjs} +154 -116
  157. package/dist/{requirement-Dm8njSoC.mjs → requirement-BygDzjDS.mjs} +1 -1
  158. package/dist/{resourceRateLimit-PQaY3HW1.mjs → resourceRateLimit-DdIYis3m.mjs} +2 -2
  159. package/dist/{rolldown-runtime-BBBkGgwA.mjs → rolldown-runtime-Cy6j0m8_.mjs} +1 -1
  160. package/dist/{routeValidator-fuG51bQA.mjs → routeValidator-Bn-x2gaJ.mjs} +1 -1
  161. package/dist/{runtimeCapabilities-B8IT7xiQ.mjs → runtimeCapabilities-DY20Pibh.mjs} +7 -2
  162. package/dist/{schedules-0-aS4jDV.mjs → schedules-CwqC0Mp0.mjs} +5 -5
  163. package/dist/{schemaConverter-Cs3SwP4R.mjs → schemaConverter-XoLKVpzG.mjs} +2 -2
  164. package/dist/{schemaIR-By8XiNeE.mjs → schemaIR-DP7mMj7c.mjs} +16 -16
  165. package/dist/schemas/index.mjs +1 -1
  166. package/dist/scim/index.mjs +2 -2
  167. package/dist/scope/index.d.mts +6 -2
  168. package/dist/scope/index.mjs +5 -5
  169. package/dist/{scope-BWNAlBj0.mjs → scope-B0vgM2Zw.mjs} +4 -4
  170. package/dist/{shutdown-Cf-27xsS.mjs → shutdown-C76Hn-Th.mjs} +1 -1
  171. package/dist/{simpleEqualityMatcher-e-dgJcUO.mjs → simpleEqualityMatcher-Qbl-11cE.mjs} +1 -1
  172. package/dist/{sse-C3bj5qWi.mjs → sse-eyb8lNuI.mjs} +7 -7
  173. package/dist/{sseStream-BYZbpFDa.mjs → sseStream-BsBesrfw.mjs} +2 -2
  174. package/dist/{store-helpers-B9HierHY.mjs → store-helpers-D1yIVa91.mjs} +1 -1
  175. package/dist/{streaming-EN8NJWxr.mjs → streaming-DKziqs1Z.mjs} +1 -1
  176. package/dist/{subscriberIdentity-DSqCh38x.mjs → subscriberIdentity-DpdSQMQq.mjs} +1 -1
  177. package/dist/{tenancy-CAqjGQcQ.mjs → tenancy-YuRYsOPr.mjs} +2 -2
  178. package/dist/{tenantPreparation-CVBWarqs.mjs → tenantPreparation-Bk8ouRB3.mjs} +17 -5
  179. package/dist/testing/cleanupStoreContract.mjs +1 -1
  180. package/dist/testing/index.d.mts +4 -4
  181. package/dist/testing/index.mjs +11 -11
  182. package/dist/testing/outboxStoreContract.mjs +2 -2
  183. package/dist/testing/requiredPorts.d.mts +1 -1
  184. package/dist/testing/requiredPorts.mjs +2 -2
  185. package/dist/testing/storageContract.mjs +1 -1
  186. package/dist/{timing-CKI_Oyub.mjs → timing-BtIDIdQz.mjs} +1 -1
  187. package/dist/{transactionContext-D0UZFoSy.mjs → transactionContext-BsQ5ortM.mjs} +1 -1
  188. package/dist/{typeGuards-CLYkmBLT.mjs → typeGuards-Cr2_zEW0.mjs} +1 -1
  189. package/dist/types/index.d.mts +2 -2
  190. package/dist/types/index.mjs +1 -1
  191. package/dist/types/storage.mjs +1 -1
  192. package/dist/{types-BeEJm-DV.d.mts → types-CQhHTZXs.d.mts} +48 -35
  193. package/dist/{types-B4E0sc6D.d.mts → types-DWFgq8EP.d.mts} +1 -1
  194. package/dist/{types-Cunc4shv.mjs → types-ZvdR7MVa.mjs} +4 -4
  195. package/dist/usage/index.mjs +4 -4
  196. package/dist/{userHelpers-cT5j1kgp.mjs → userHelpers-CwpEK36a.mjs} +1 -1
  197. package/dist/utils/index.d.mts +1 -1
  198. package/dist/utils/index.mjs +12 -12
  199. package/dist/{utils-DlNkm1dI.mjs → utils-CnrfcYMq.mjs} +6 -6
  200. package/dist/{validate-63QThRoS.mjs → validate-BTQBh-Dr.mjs} +3 -3
  201. package/dist/{versioning-f2YGmh4i.mjs → versioning-DiLykI6U.mjs} +3 -3
  202. package/dist/{workScope-DwspXz70.mjs → workScope-C3tPz_Gt.mjs} +2 -2
  203. package/package.json +34 -9
  204. package/skills/arc/SKILL.md +5 -5
  205. package/skills/arc/references/api-reference.md +1 -1
  206. package/skills/arc/references/boot.md +17 -2
  207. package/skills/arc/references/events.md +0 -1
  208. package/skills/arc/references/mcp-setup.md +3 -2
  209. package/skills/arc/references/multi-tenancy.md +1 -1
  210. package/skills/arc/references/production-api.md +19 -12
  211. package/skills/arc/references/production-audit.md +1 -1
  212. package/skills/arc/references/production-boot.md +3 -3
  213. package/skills/arc/references/production-idempotency.md +2 -2
  214. package/skills/arc/references/production-observability.md +14 -2
  215. package/skills/arc/references/production-reliability.md +1 -1
  216. package/skills/arc/references/querying.md +1 -2
  217. package/skills/arc/references/resources.md +8 -6
  218. package/skills/arc/references/testing.md +1 -1
  219. package/skills/arc-code-review/references/arc-cheatsheet.md +1 -1
  220. package/skills/arc-code-review/references/recipe-scope-permissions.md +1 -1
  221. package/skills/arc-module-publishing/references/resource-assembly.md +2 -2
  222. package/dist/rateLimitKey-D9dl3FQn.mjs +0 -40
@@ -1,115 +1,7 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { n as bootError } from "./bootError-BT3z3cvX.mjs";
2
3
  import { randomUUID } from "node:crypto";
3
4
  import fp from "fastify-plugin";
4
- // src/plugins/requestId.ts
5
- /**
6
- * Request ID Plugin
7
- *
8
- * Propagates request IDs for distributed tracing.
9
- * - Accepts incoming x-request-id header (sanitized)
10
- * - Generates UUID if not provided
11
- * - Echoes the id on the response header + W3C trace-context propagation
12
- *
13
- * ID RESOLUTION LIVES AT THE SERVER LEVEL, NOT HERE. Fastify binds
14
- * `request.log = logger.child({ reqId: request.id })` at request
15
- * construction — before any hook runs — so an id assigned inside a hook
16
- * never reaches the logs. `createApp` therefore wires
17
- * {@link createRequestIdGenerator} into Fastify's `genReqId` option, and
18
- * this plugin simply adopts `request.id`. Standalone registration on a
19
- * bare Fastify instance falls back to the legacy in-hook resolution
20
- * (header echo / UUID), with the documented limitation that
21
- * `request.log`'s `reqId` binding predates the overwrite — pass
22
- * `genReqId: createRequestIdGenerator()` to `Fastify()` to fix that.
23
- *
24
- * @example
25
- * import { requestIdPlugin, createRequestIdGenerator } from '@classytic/arc';
26
- *
27
- * const fastify = Fastify({ genReqId: createRequestIdGenerator() });
28
- * await fastify.register(requestIdPlugin);
29
- *
30
- * fastify.get('/', async (request) => {
31
- * request.log.info('traced'); // carries the same reqId as the header
32
- * return { id: request.id };
33
- * });
34
- */
35
- /**
36
- * Sanitize an incoming request-id header value: max 128 chars, alphanumeric
37
- * plus dashes/underscores/dots/colons only. Returns `undefined` for anything
38
- * else (crafted values could pollute logs or response headers). Array values
39
- * (repeated headers) are rejected outright — a client sending multiple
40
- * request-id headers is not tracing in good faith.
41
- */
42
- function sanitizeRequestId(value) {
43
- if (typeof value !== "string") return void 0;
44
- const trimmed = value.trim();
45
- return trimmed.length > 0 && trimmed.length <= 128 && /^[\w.:-]+$/.test(trimmed) ? trimmed : void 0;
46
- }
47
- /**
48
- * Build a Fastify `genReqId` function: adopt a sanitized incoming request-id
49
- * header, or generate one. Wire this into the `Fastify()` constructor so
50
- * `request.id`, `request.log`'s `reqId` binding, and the echoed response
51
- * header all agree — `createApp` does this automatically.
52
- */
53
- function createRequestIdGenerator(opts = {}) {
54
- const { header = "x-request-id", generator = randomUUID } = opts;
55
- const headerName = header.toLowerCase();
56
- return (req) => sanitizeRequestId(req.headers[headerName]) ?? generator();
57
- }
58
- /** Fastify's default request ids are `req-<base36 counter>`. */
59
- const FASTIFY_DEFAULT_ID = /^req-[0-9a-z]+$/;
60
- /** W3C traceparent format: `version-traceid-parentid-flags` */
61
- const TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/i;
62
- /** W3C spec: version ff is reserved and invalid; trace/parent IDs must not be all zeros */
63
- const TRACEID_ZEROS = "0".repeat(32);
64
- const PARENTID_ZEROS = "0".repeat(16);
65
- /** tracestate: printable ASCII, <= 512 bytes */
66
- const TRACESTATE_MAX = 512;
67
- function isValidTraceparent(tp) {
68
- const m = TRACEPARENT_RE.exec(tp);
69
- if (!m) return false;
70
- const version = m[1] ?? "";
71
- const traceId = m[2] ?? "";
72
- const parentId = m[3] ?? "";
73
- if (version.toLowerCase() === "ff") return false;
74
- if (traceId.toLowerCase() === TRACEID_ZEROS) return false;
75
- if (parentId.toLowerCase() === PARENTID_ZEROS) return false;
76
- return true;
77
- }
78
- const requestIdPlugin = async (fastify, opts = {}) => {
79
- const { header = "x-request-id", generator = randomUUID, setResponseHeader = true, propagateTraceContext = true } = opts;
80
- if (!fastify.hasRequestDecorator("requestId")) fastify.decorateRequest("requestId", "");
81
- if (!fastify.hasRequestDecorator("traceContext")) fastify.decorateRequest("traceContext", void 0);
82
- fastify.addHook("onRequest", async (request, reply) => {
83
- const incoming = sanitizeRequestId(request.headers[header]);
84
- let requestId = String(request.id);
85
- if (incoming && incoming !== requestId) requestId = incoming;
86
- else if (!incoming && FASTIFY_DEFAULT_ID.test(requestId)) requestId = generator();
87
- if (requestId !== request.id) request.id = requestId;
88
- request.requestId = requestId;
89
- if (setResponseHeader) reply.header(header, requestId);
90
- if (propagateTraceContext) {
91
- const rawTraceparent = request.headers.traceparent;
92
- const rawTracestate = request.headers.tracestate;
93
- if (typeof rawTraceparent === "string") {
94
- const tp = rawTraceparent.trim();
95
- if (isValidTraceparent(tp)) {
96
- const ts = typeof rawTracestate === "string" && rawTracestate.length > 0 && rawTracestate.length <= TRACESTATE_MAX ? rawTracestate : void 0;
97
- request.traceContext = {
98
- traceparent: tp,
99
- ...ts ? { tracestate: ts } : {}
100
- };
101
- reply.header("traceparent", tp);
102
- if (ts) reply.header("tracestate", ts);
103
- }
104
- }
105
- }
106
- });
107
- fastify.log?.debug?.("Request ID plugin registered");
108
- };
109
- var requestId_default = fp(requestIdPlugin, {
110
- name: "arc-request-id",
111
- fastify: "5.x"
112
- });
113
5
  // src/utils/metricSeries.ts
114
6
  /** Retains a fixed number of label sets; excess observations share one overflow series. */
115
7
  var MetricSeries = class {
@@ -231,7 +123,11 @@ function mergeHealthChecks(groups) {
231
123
  const merged = [];
232
124
  for (const group of groups) for (const check of group.checks ?? []) {
233
125
  const prior = owners.get(check.name);
234
- if (prior !== void 0) throw new Error(`[arc] duplicate health-check name "${check.name}" — declared by ${prior} and ${group.owner}. Health-check names must be unique.`);
126
+ if (prior !== void 0) throw bootError({
127
+ code: "duplicate-health-check",
128
+ message: `[arc] duplicate health-check name "${check.name}" — declared by ${prior} and ${group.owner}. Health-check names must be unique.`,
129
+ fix: `rename one of the "${check.name}" health checks`
130
+ });
235
131
  owners.set(check.name, group.owner);
236
132
  merged.push(check);
237
133
  }
@@ -312,8 +208,7 @@ const healthPlugin = async (fastify, opts = {}) => {
312
208
  properties: {
313
209
  name: { type: "string" },
314
210
  healthy: { type: "boolean" },
315
- duration: { type: "number" },
316
- error: { type: "string" }
211
+ duration: { type: "number" }
317
212
  }
318
213
  }
319
214
  }
@@ -331,7 +226,7 @@ const healthPlugin = async (fastify, opts = {}) => {
331
226
  }
332
227
  }
333
228
  }
334
- } }, async (_, reply) => {
229
+ } }, async (request, reply) => {
335
230
  if (fastify.hasDecorator("shutdownState") && fastify.shutdownState.draining) {
336
231
  reply.code(503);
337
232
  return {
@@ -342,10 +237,19 @@ const healthPlugin = async (fastify, opts = {}) => {
342
237
  }
343
238
  const results = await runChecks(readinessChecks);
344
239
  const criticalFailed = results.some((result, index) => !result.healthy && (readinessChecks[index]?.critical ?? true));
240
+ const failed = results.filter((r) => r.error !== void 0);
241
+ if (failed.length > 0) request.log.warn({ checks: failed.map(({ name, error }) => ({
242
+ name,
243
+ error
244
+ })) }, "[arc] readiness check failed");
345
245
  const response = {
346
246
  status: criticalFailed ? "not_ready" : "ready",
347
247
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
348
- checks: results
248
+ checks: results.map(({ name, healthy, duration }) => ({
249
+ name,
250
+ healthy,
251
+ duration
252
+ }))
349
253
  };
350
254
  if (criticalFailed) reply.code(503);
351
255
  return response;
@@ -436,8 +340,142 @@ async function runChecks(checks) {
436
340
  }
437
341
  }));
438
342
  }
343
+ /**
344
+ * Run every readiness check once and log ONE line: names, pass/fail, duration. Never throws
345
+ * and never fails boot — a dependency that is down at boot is the readiness probe's business.
346
+ * `production` adds a note when no check is critical (readiness can then never go not-ready).
347
+ */
348
+ async function logBootHealthSummary(log, checks, options = {}) {
349
+ const critical = checks.filter((c) => c.critical ?? true).length;
350
+ const noCritical = options.production === true && critical === 0;
351
+ if (checks.length === 0 && !noCritical) return;
352
+ try {
353
+ const start = Date.now();
354
+ const results = await runChecks(checks);
355
+ const failed = results.filter((r) => !r.healthy);
356
+ const summary = results.map((r) => `${r.name} ${r.healthy ? "ok" : "FAILED"} (${r.duration}ms)`).join(", ");
357
+ const note = noCritical ? " — no critical readiness check is registered, so /ready can never report not_ready" : "";
358
+ const line = `[arc] boot health: ${results.length - failed.length}/${results.length} passing${summary ? ` — ${summary}` : ""}${note}`;
359
+ const fields = {
360
+ durationMs: Date.now() - start,
361
+ criticalChecks: critical,
362
+ checks: results
363
+ };
364
+ if (failed.length > 0) log.warn(fields, line);
365
+ else log.info(fields, line);
366
+ } catch {}
367
+ }
439
368
  var health_default = fp(healthPlugin, {
440
369
  name: "arc-health",
441
370
  fastify: "5.x"
442
371
  });
443
- export { MetricHistogram as a, createRequestIdGenerator as c, DURATION_BUCKETS_SECONDS as i, requestId_default as l, health_default as n, MetricSeries as o, mergeHealthChecks as r, renderMetricSample as s, healthPlugin as t, sanitizeRequestId as u };
372
+ // src/plugins/requestId.ts
373
+ /**
374
+ * Request ID Plugin
375
+ *
376
+ * Propagates request IDs for distributed tracing.
377
+ * - Accepts incoming x-request-id header (sanitized)
378
+ * - Generates UUID if not provided
379
+ * - Echoes the id on the response header + W3C trace-context propagation
380
+ *
381
+ * ID RESOLUTION LIVES AT THE SERVER LEVEL, NOT HERE. Fastify binds
382
+ * `request.log = logger.child({ reqId: request.id })` at request
383
+ * construction — before any hook runs — so an id assigned inside a hook
384
+ * never reaches the logs. `createApp` therefore wires
385
+ * {@link createRequestIdGenerator} into Fastify's `genReqId` option, and
386
+ * this plugin simply adopts `request.id`. Standalone registration on a
387
+ * bare Fastify instance falls back to the legacy in-hook resolution
388
+ * (header echo / UUID), with the documented limitation that
389
+ * `request.log`'s `reqId` binding predates the overwrite — pass
390
+ * `genReqId: createRequestIdGenerator()` to `Fastify()` to fix that.
391
+ *
392
+ * @example
393
+ * import { requestIdPlugin, createRequestIdGenerator } from '@classytic/arc';
394
+ *
395
+ * const fastify = Fastify({ genReqId: createRequestIdGenerator() });
396
+ * await fastify.register(requestIdPlugin);
397
+ *
398
+ * fastify.get('/', async (request) => {
399
+ * request.log.info('traced'); // carries the same reqId as the header
400
+ * return { id: request.id };
401
+ * });
402
+ */
403
+ /**
404
+ * Sanitize an incoming request-id header value: max 128 chars, alphanumeric
405
+ * plus dashes/underscores/dots/colons only. Returns `undefined` for anything
406
+ * else (crafted values could pollute logs or response headers). Array values
407
+ * (repeated headers) are rejected outright — a client sending multiple
408
+ * request-id headers is not tracing in good faith.
409
+ */
410
+ function sanitizeRequestId(value) {
411
+ if (typeof value !== "string") return void 0;
412
+ const trimmed = value.trim();
413
+ return trimmed.length > 0 && trimmed.length <= 128 && /^[\w.:-]+$/.test(trimmed) ? trimmed : void 0;
414
+ }
415
+ /**
416
+ * Build a Fastify `genReqId` function: adopt a sanitized incoming request-id
417
+ * header, or generate one. Wire this into the `Fastify()` constructor so
418
+ * `request.id`, `request.log`'s `reqId` binding, and the echoed response
419
+ * header all agree — `createApp` does this automatically.
420
+ */
421
+ function createRequestIdGenerator(opts = {}) {
422
+ const { header = "x-request-id", generator = randomUUID } = opts;
423
+ const headerName = header.toLowerCase();
424
+ return (req) => sanitizeRequestId(req.headers[headerName]) ?? generator();
425
+ }
426
+ /** Fastify's default request ids are `req-<base36 counter>`. */
427
+ const FASTIFY_DEFAULT_ID = /^req-[0-9a-z]+$/;
428
+ /** W3C traceparent format: `version-traceid-parentid-flags` */
429
+ const TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/i;
430
+ /** W3C spec: version ff is reserved and invalid; trace/parent IDs must not be all zeros */
431
+ const TRACEID_ZEROS = "0".repeat(32);
432
+ const PARENTID_ZEROS = "0".repeat(16);
433
+ /** tracestate: printable ASCII, <= 512 bytes */
434
+ const TRACESTATE_MAX = 512;
435
+ function isValidTraceparent(tp) {
436
+ const m = TRACEPARENT_RE.exec(tp);
437
+ if (!m) return false;
438
+ const version = m[1] ?? "";
439
+ const traceId = m[2] ?? "";
440
+ const parentId = m[3] ?? "";
441
+ if (version.toLowerCase() === "ff") return false;
442
+ if (traceId.toLowerCase() === TRACEID_ZEROS) return false;
443
+ if (parentId.toLowerCase() === PARENTID_ZEROS) return false;
444
+ return true;
445
+ }
446
+ const requestIdPlugin = async (fastify, opts = {}) => {
447
+ const { header = "x-request-id", generator = randomUUID, setResponseHeader = true, propagateTraceContext = true } = opts;
448
+ if (!fastify.hasRequestDecorator("requestId")) fastify.decorateRequest("requestId", "");
449
+ if (!fastify.hasRequestDecorator("traceContext")) fastify.decorateRequest("traceContext", void 0);
450
+ fastify.addHook("onRequest", async (request, reply) => {
451
+ const incoming = sanitizeRequestId(request.headers[header]);
452
+ let requestId = String(request.id);
453
+ if (incoming && incoming !== requestId) requestId = incoming;
454
+ else if (!incoming && FASTIFY_DEFAULT_ID.test(requestId)) requestId = generator();
455
+ if (requestId !== request.id) request.id = requestId;
456
+ request.requestId = requestId;
457
+ if (setResponseHeader) reply.header(header, requestId);
458
+ if (propagateTraceContext) {
459
+ const rawTraceparent = request.headers.traceparent;
460
+ const rawTracestate = request.headers.tracestate;
461
+ if (typeof rawTraceparent === "string") {
462
+ const tp = rawTraceparent.trim();
463
+ if (isValidTraceparent(tp)) {
464
+ const ts = typeof rawTracestate === "string" && rawTracestate.length > 0 && rawTracestate.length <= TRACESTATE_MAX ? rawTracestate : void 0;
465
+ request.traceContext = {
466
+ traceparent: tp,
467
+ ...ts ? { tracestate: ts } : {}
468
+ };
469
+ reply.header("traceparent", tp);
470
+ if (ts) reply.header("tracestate", ts);
471
+ }
472
+ }
473
+ }
474
+ });
475
+ fastify.log?.debug?.("Request ID plugin registered");
476
+ };
477
+ var requestId_default = fp(requestIdPlugin, {
478
+ name: "arc-request-id",
479
+ fastify: "5.x"
480
+ });
481
+ export { health_default as a, DURATION_BUCKETS_SECONDS as c, renderMetricSample as d, healthPlugin as i, MetricHistogram as l, requestId_default as n, logBootHealthSummary as o, sanitizeRequestId as r, mergeHealthChecks as s, createRequestIdGenerator as t, MetricSeries as u };
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  // src/idempotency/requirement.ts
3
3
  /** What is wrong with a route's idempotency declaration, or `undefined` when it is sound. */
4
4
  function idempotencyConfigProblem(config) {
@@ -1,5 +1,5 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { t as createTenantKeyGenerator } from "./rateLimitKey-D9dl3FQn.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { t as createTenantKeyGenerator } from "./rateLimitKey-DLGdeFd2.mjs";
3
3
  // src/permissions/resourceRateLimit.ts
4
4
  function decision(allowed, max, remaining, ttlSeconds) {
5
5
  const reset = Math.max(1, ttlSeconds);
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  import "node:module";
3
3
  // \0rolldown/runtime.js
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  import { AjvCompiler } from "@fastify/ajv-compiler";
3
3
  // src/core/routeValidator.ts
4
4
  /**
@@ -1,4 +1,5 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { t as ArcBootError } from "./bootError-BT3z3cvX.mjs";
2
3
  // src/utils/runtimeCapabilities.ts
3
4
  /**
4
5
  * `Symbol.for` so declarations from two arc copies in one dependency graph
@@ -68,7 +69,11 @@ function auditRuntimeCapabilities(fastify, runtime) {
68
69
  if (acceptedMemory.length > 0) fastify.log.info({ accepted: acceptedMemory.map((d) => d.subsystem) }, "[arc] per-process state accepted by design under runtime: 'distributed'");
69
70
  if (violations.length > 0) {
70
71
  const lines = violations.map((d) => ` - ${d.subsystem}${d.detail ? ` — ${d.detail}` : ""}`).join("\n");
71
- throw new Error(`runtime: 'distributed' — ${violations.length} subsystem(s) hold PER-PROCESS state that multi-replica deployment breaks:\n${lines}\nWire a shared store for each, or — where per-process is genuinely intended — have the declarant pass \`accepted: true\` with a reason.`);
72
+ throw new ArcBootError(`runtime: 'distributed' — ${violations.length} subsystem(s) hold PER-PROCESS state that multi-replica deployment breaks:\n${lines}\nWire a shared store for each, or — where per-process is genuinely intended — have the declarant pass \`accepted: true\` with a reason.`, violations.map((d) => ({
73
+ code: "runtime-memory-state",
74
+ message: `${d.subsystem} holds per-process state${d.detail ? ` — ${d.detail}` : ""}`,
75
+ fix: `wire a shared store for ${d.subsystem}, or declare it with accepted: true and a reason`
76
+ })));
72
77
  }
73
78
  }
74
79
  export { declareRuntimeCapability as n, initRuntimeCapabilityRegistry as r, auditRuntimeCapabilities as t };
@@ -1,8 +1,8 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { t as __exportAll } from "./rolldown-runtime-BBBkGgwA.mjs";
3
- import { t as runWorkScope } from "./workScope-DwspXz70.mjs";
4
- import { t as startRenewingLease } from "./renewingLease-g2FjB3im.mjs";
5
- import { a as runShutdown, i as runAdmittedWork, r as registerShutdownParticipant } from "./shutdown-Cf-27xsS.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { t as __exportAll } from "./rolldown-runtime-Cy6j0m8_.mjs";
3
+ import { t as runWorkScope } from "./workScope-C3tPz_Gt.mjs";
4
+ import { t as startRenewingLease } from "./renewingLease-DaoP0K-e.mjs";
5
+ import { a as runShutdown, i as runAdmittedWork, r as registerShutdownParticipant } from "./shutdown-C76Hn-Th.mjs";
6
6
  import fp from "fastify-plugin";
7
7
  import { civilDateOf, civilDateToInstant, isValidTimeZone, localTimeParts } from "@classytic/primitives/timezone";
8
8
  // src/plugins/dailyGate.ts
@@ -1,5 +1,5 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { t as arcLog } from "./logger-DJwz_-Pl.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { t as arcLog } from "./logger-DdMS0XC_.mjs";
3
3
  // src/utils/schemaConverter.ts
4
4
  /**
5
5
  * Schema Converter — Detect-First, Convert-Only-When-Needed
@@ -1,17 +1,17 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { f as createError } from "./errors-DxpHZBlW.mjs";
3
- import { n as getUserRoles } from "./userHelpers-cT5j1kgp.mjs";
4
- import { b as isElevated, n as PUBLIC_SCOPE, u as getRequestScope, x as isMember } from "./types-Cunc4shv.mjs";
5
- import { a as resolveEffectiveRoles, r as deriveHiddenFieldPermissions, t as applyFieldReadPermissions } from "./fields-kCbIDTjA.mjs";
6
- import { o as toJsonSchema } from "./schemaConverter-Cs3SwP4R.mjs";
7
- import { t as buildRequestScopeProjection } from "./projection-aHCtDQQ9.mjs";
8
- import { n as requestContext } from "./requestContext-yc7MSgmq.mjs";
9
- import { n as isTenantPreparation } from "./tenantPreparation-CVBWarqs.mjs";
10
- import { n as evaluateAndApplyPermission } from "./authorizationDecision-DKmH4tZ-.mjs";
11
- import { t as executePipeline } from "./pipe-CqPweKdL.mjs";
12
- import { n as idempotencyConfigProblem, t as declaresIdempotencyFence } from "./requirement-Dm8njSoC.mjs";
13
- import { i as resolveResourceRateLimiter, r as recordUnenforcedRateLimit } from "./resourceRateLimit-PQaY3HW1.mjs";
14
- import { n as arcRouteValidatorCompiler } from "./routeValidator-fuG51bQA.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { f as createError } from "./errors-Ukhmfmmx.mjs";
3
+ import { n as getUserRoles } from "./userHelpers-CwpEK36a.mjs";
4
+ import { b as isElevated, n as PUBLIC_SCOPE, u as getRequestScope, x as isMember } from "./types-ZvdR7MVa.mjs";
5
+ import { a as resolveEffectiveRoles, r as deriveHiddenFieldPermissions, t as applyFieldReadPermissions } from "./fields-B7fuROWK.mjs";
6
+ import { n as isTenantPreparation } from "./tenantPreparation-Bk8ouRB3.mjs";
7
+ import { o as toJsonSchema } from "./schemaConverter-XoLKVpzG.mjs";
8
+ import { t as buildRequestScopeProjection } from "./projection-B4rqiJTi.mjs";
9
+ import { n as requestContext } from "./requestContext-B-TjFpWt.mjs";
10
+ import { n as evaluateAndApplyPermission } from "./authorizationDecision-gB5-bHDp.mjs";
11
+ import { t as executePipeline } from "./pipe-DIAr91at.mjs";
12
+ import { n as idempotencyConfigProblem, t as declaresIdempotencyFence } from "./requirement-BygDzjDS.mjs";
13
+ import { i as resolveResourceRateLimiter, r as recordUnenforcedRateLimit } from "./resourceRateLimit-DdIYis3m.mjs";
14
+ import { n as arcRouteValidatorCompiler } from "./routeValidator-Bn-x2gaJ.mjs";
15
15
  import { isPaginatedResult, toCanonicalList } from "@classytic/repo-core/pagination";
16
16
  // src/core/fastifyAdapter.ts
17
17
  /** Type guard for Mongoose-like documents with toObject() */
@@ -683,7 +683,7 @@ const groupLimits = /* @__PURE__ */ new WeakMap();
683
683
  * mounting two resources at the same prefix, custom routes that share a
684
684
  * URL with another plugin. Fastify's default message ("Method 'GET'
685
685
  * already declared for route '/'") gives no hint at the resource-shaped
686
- * fix — `disabledRoutes: ['list']` — so wrap it with one.
686
+ * fix — leave the op out of `crud` — so wrap it with one.
687
687
  */
688
688
  function tryRegisterRoute(fastify, opts, context) {
689
689
  const ratePolicy = opts.config?.rateLimit;
@@ -777,7 +777,7 @@ function tryRegisterRoute(fastify, opts, context) {
777
777
  "create",
778
778
  "update",
779
779
  "delete"
780
- ].includes(context.op) ? ` Suppress the auto-CRUD route with \`disabledRoutes: ['${context.op}']\`.` : " If a custom route in `routes:` collides with auto-CRUD, add `disabledRoutes: ['list' | 'get' | 'create' | 'update' | 'delete']` to `defineResource()` to suppress the matching auto-CRUD route.";
780
+ ].includes(context.op) ? ` Suppress the auto-CRUD route by leaving '${context.op}' out of the \`crud\` allow-list.` : " If a custom route in `routes:` collides with auto-CRUD, leave the matching op out of the `crud` allow-list (`crud: { list: true, get: true, ... }`) in `defineResource()` to suppress the auto-CRUD route.";
781
781
  const enhanced = /* @__PURE__ */ new Error(`[arc] Duplicate route ${method} ${url} on resource "${context.resourceName}"${opHint}.${fixHint} Original: ${fastifyErr.message ?? "FST_ERR_DUPLICATED_ROUTE"}`);
782
782
  enhanced.code = "FST_ERR_DUPLICATED_ROUTE";
783
783
  enhanced.cause = err;
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  import { errorContractSchema, errorDetailSchema } from "@classytic/repo-core/errors";
3
3
  import { Type, Type as Type$1 } from "typebox";
4
4
  // src/schemas/index.ts
@@ -1,5 +1,5 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { t as parseJsonBody } from "../jsonBody-CkKs6dA_.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { t as parseJsonBody } from "../jsonBody-BNlcGUnb.mjs";
3
3
  import fp from "fastify-plugin";
4
4
  // src/scim/errors.ts
5
5
  var ScimError = class extends Error {
@@ -7,8 +7,12 @@ interface RateLimitKeyContext {
7
7
  scope?: RequestScope;
8
8
  }
9
9
  interface TenantKeyGeneratorOptions {
10
- /** Custom strategy — overrides default scope-based logic */
11
- strategy?: (ctx: RateLimitKeyContext) => string;
10
+ /**
11
+ * `'organization'` (the default when omitted) — one bucket per organisation, see the
12
+ * module docblock for the full chain. `'user'` — one bucket per signed-in user, IP when
13
+ * anonymous (`createApp`'s default key). A function — your own key.
14
+ */
15
+ strategy?: "organization" | "user" | ((ctx: RateLimitKeyContext) => string);
12
16
  }
13
17
  export declare function createTenantKeyGenerator(opts?: TenantKeyGeneratorOptions): (ctx: RateLimitKeyContext) => string;
14
18
  interface ResolveOrgFromHeaderOptions {
@@ -1,6 +1,6 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { C as isService, D as requireUserId, E as requireTeamId, O as scopeFirstCtx, S as isOrgInScope, T as requireOrgId, _ as getUserRoles, a as getDPoPJkt, b as isElevated, c as getOrgId, d as getScopeContext, f as getScopeContextMap, g as getUserId, h as getTenantFromRequest, i as getClientId, l as getOrgRoles, m as getTeamId, n as PUBLIC_SCOPE, o as getMandate, p as getServiceScopes, r as getAncestorOrgIds, s as getOrgContext, t as AUTHENTICATED_SCOPE, u as getRequestScope, v as hasOrgAccess, w as requireClientId, x as isMember, y as isAuthenticated } from "../types-Cunc4shv.mjs";
3
- import { t as createTenantKeyGenerator } from "../rateLimitKey-D9dl3FQn.mjs";
4
- import { t as elevation_default } from "../elevation-DiXVg98q.mjs";
5
- import { t as resolveOrgFromHeader } from "../scope-BWNAlBj0.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { C as isService, D as requireUserId, E as requireTeamId, O as scopeFirstCtx, S as isOrgInScope, T as requireOrgId, _ as getUserRoles, a as getDPoPJkt, b as isElevated, c as getOrgId, d as getScopeContext, f as getScopeContextMap, g as getUserId, h as getTenantFromRequest, i as getClientId, l as getOrgRoles, m as getTeamId, n as PUBLIC_SCOPE, o as getMandate, p as getServiceScopes, r as getAncestorOrgIds, s as getOrgContext, t as AUTHENTICATED_SCOPE, u as getRequestScope, v as hasOrgAccess, w as requireClientId, x as isMember, y as isAuthenticated } from "../types-ZvdR7MVa.mjs";
3
+ import { t as createTenantKeyGenerator } from "../rateLimitKey-DLGdeFd2.mjs";
4
+ import { t as elevation_default } from "../elevation-NJ3908pJ.mjs";
5
+ import { t as resolveOrgFromHeader } from "../scope-B0vgM2Zw.mjs";
6
6
  export { AUTHENTICATED_SCOPE, PUBLIC_SCOPE, createTenantKeyGenerator, elevation_default as elevationPlugin, getAncestorOrgIds, getClientId, getDPoPJkt, getMandate, getOrgContext, getOrgId, getOrgRoles, getRequestScope, getScopeContext, getScopeContextMap, getServiceScopes, getTeamId, getTenantFromRequest, getUserId, getUserRoles, hasOrgAccess, isAuthenticated, isElevated, isMember, isOrgInScope, isService, requireClientId, requireOrgId, requireTeamId, requireUserId, resolveOrgFromHeader, scopeFirstCtx };
@@ -1,7 +1,7 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { a as OrgAccessDeniedError, l as UnauthorizedError } from "./errors-DxpHZBlW.mjs";
3
- import { n as requireSingleHeaderValue } from "./headers-Bh47h0XH.mjs";
4
- import { n as getUserRoles } from "./userHelpers-cT5j1kgp.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { a as OrgAccessDeniedError, l as UnauthorizedError } from "./errors-Ukhmfmmx.mjs";
3
+ import { n as requireSingleHeaderValue } from "./headers-Ib7BDgRI.mjs";
4
+ import { n as getUserRoles } from "./userHelpers-CwpEK36a.mjs";
5
5
  // src/scope/resolveOrgFromHeader.ts
6
6
  /**
7
7
  * Create a preHandler hook that resolves org scope from a header.
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  // src/utils/shutdown.ts
4
4
  /** Stop admissions across every runtime before draining work and disposing domain engines. */
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  // src/utils/simpleEqualityMatcher.ts
3
3
  /**
4
4
  * `simpleEqualityMatcher` — a minimal, dialect-agnostic flat-key equality
@@ -1,10 +1,10 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { t as __exportAll } from "./rolldown-runtime-BBBkGgwA.mjs";
3
- import { n as isEventVisible, t as eventAudienceOf } from "./tenancy-CAqjGQcQ.mjs";
4
- import { t as arcLog } from "./logger-DJwz_-Pl.mjs";
5
- import { g as getUserId, n as PUBLIC_SCOPE } from "./types-Cunc4shv.mjs";
6
- import { a as registerSseStats, r as openSseStream } from "./sseStream-BYZbpFDa.mjs";
7
- import { a as promoteStreamTokenToHeader } from "./streaming-EN8NJWxr.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { t as __exportAll } from "./rolldown-runtime-Cy6j0m8_.mjs";
3
+ import { n as isEventVisible, t as eventAudienceOf } from "./tenancy-YuRYsOPr.mjs";
4
+ import { t as arcLog } from "./logger-DdMS0XC_.mjs";
5
+ import { g as getUserId, n as PUBLIC_SCOPE } from "./types-ZvdR7MVa.mjs";
6
+ import { a as registerSseStats, r as openSseStream } from "./sseStream-BsBesrfw.mjs";
7
+ import { a as promoteStreamTokenToHeader } from "./streaming-DKziqs1Z.mjs";
8
8
  import fp from "fastify-plugin";
9
9
  // src/plugins/sse.ts
10
10
  var sse_exports = /* @__PURE__ */ __exportAll({ default: () => sse_default });
@@ -1,5 +1,5 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { n as forwardedStreamHeaders } from "./streaming-EN8NJWxr.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { n as forwardedStreamHeaders } from "./streaming-DKziqs1Z.mjs";
3
3
  // src/utils/sseStats.ts
4
4
  /** Per-instance stats providers behind one `sseStats` decorator. */
5
5
  const statsProviders = /* @__PURE__ */ new WeakMap();
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  // src/utils/store-helpers.ts
3
3
  /**
4
4
  * Classify an error thrown by `getOne` / `getById` / `update` as a
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  import { Readable } from "node:stream";
3
3
  // src/utils/streaming.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  // src/events/subscriberIdentity.ts
3
3
  const SUBSCRIBER_ID = Symbol.for("@classytic/arc/subscriber-id");
4
4
  /** Assign a deployment-stable identity for durable per-handler progress; never use an index. */
@@ -1,5 +1,5 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { b as isElevated, c as getOrgId } from "./types-Cunc4shv.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { b as isElevated, c as getOrgId } from "./types-ZvdR7MVa.mjs";
3
3
  // src/core/tenancy.ts
4
4
  function eventAudienceOf(scope) {
5
5
  const tenancy = resolveTenancy({ _scope: scope }, "organizationId");
@@ -1,7 +1,7 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
2
- import { t as conjoinPolicyFilters } from "./filter-merge-UJCgjbZR.mjs";
3
- import { b as isElevated, c as getOrgId, d as getScopeContext, m as getTeamId, v as hasOrgAccess } from "./types-Cunc4shv.mjs";
4
- import { d as createDomainError } from "./errors-DxpHZBlW.mjs";
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
+ import { t as conjoinPolicyFilters } from "./filter-merge-BuzZ-r9z.mjs";
3
+ import { b as isElevated, c as getOrgId, d as getScopeContext, m as getTeamId, v as hasOrgAccess } from "./types-ZvdR7MVa.mjs";
4
+ import { d as createDomainError } from "./errors-Ukhmfmmx.mjs";
5
5
  // src/permissions/tenantPreparation.ts
6
6
  /** Tenant preparation shared by HTTP middleware and direct transport invocation. */
7
7
  const PREPARATION = Symbol.for("arc.tenantPreparation");
@@ -23,6 +23,18 @@ function withoutTenantInjection(middlewares) {
23
23
  return !(typeof preparation === "object" && preparation !== null && "mode" in preparation && preparation.mode === "inject");
24
24
  });
25
25
  }
26
+ /**
27
+ * The tenant middlewares a custom or preset route runs, per `RouteDefinition.tenantScope`.
28
+ * The one rule HTTP and MCP share; empty when the resource has no multiTenant preset.
29
+ */
30
+ function routeTenantMiddlewares(route, middlewares) {
31
+ const scoped = middlewares?.tenantScope;
32
+ if (!scoped?.length || route.tenantScope === false) return [];
33
+ if (route.tenantScope === true) return [...scoped];
34
+ if (route.rawHandler !== void 0) return [];
35
+ if (route._tenantSlot) return (middlewares?.[route._tenantSlot] ?? []).filter((mw) => isTenantPreparation(mw));
36
+ return withoutTenantInjection(scoped);
37
+ }
26
38
  function prepareTenancy(scope, preparation) {
27
39
  if (preparation.mode === "crossTenant") return { crossTenant: true };
28
40
  const elevated = isElevated(scope);
@@ -63,4 +75,4 @@ function prepareTenantContext(ctx, middlewares) {
63
75
  if (meta._tenantFields) ctx._tenantFields = meta._tenantFields;
64
76
  }
65
77
  }
66
- export { withoutTenantInjection as a, tagTenantPreparation as i, isTenantPreparation as n, prepareTenantContext as r, applyTenantPreparation as t };
78
+ export { tagTenantPreparation as a, routeTenantMiddlewares as i, isTenantPreparation as n, withoutTenantInjection as o, prepareTenantContext as r, applyTenantPreparation as t };
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
2
2
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
3
3
  // src/testing/cleanupStoreContract.ts
4
4
  /**