@geekmidas/constructs 10.0.0-alpha.9 → 10.0.0-alpha.91

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 (425) hide show
  1. package/README.md +222 -158
  2. package/dist/{Construct-BD5neF7w.mjs → Construct-B1vGBPme.mjs} +33 -34
  3. package/dist/Construct-B1vGBPme.mjs.map +1 -0
  4. package/dist/Construct-BQALFCh2.d.cts +230 -0
  5. package/dist/Construct-BQALFCh2.d.cts.map +1 -0
  6. package/dist/{Construct-CyS3RpTL.cjs → Construct-DUSXuTHP.cjs} +53 -48
  7. package/dist/Construct-DUSXuTHP.cjs.map +1 -0
  8. package/dist/Construct-QXnl3VqT.d.mts +230 -0
  9. package/dist/Construct-QXnl3VqT.d.mts.map +1 -0
  10. package/dist/{Cron-DmQ8vQ4b.d.cts → Cron-DI3nKoic.d.cts} +15 -9
  11. package/dist/Cron-DI3nKoic.d.cts.map +1 -0
  12. package/dist/{Cron-dh4rUgib.d.mts → Cron-uYAHPnp7.d.mts} +15 -9
  13. package/dist/Cron-uYAHPnp7.d.mts.map +1 -0
  14. package/dist/{CronBuilder-Da0C0edR.cjs → CronBuilder-C0Ek1-RA.cjs} +47 -31
  15. package/dist/CronBuilder-C0Ek1-RA.cjs.map +1 -0
  16. package/dist/CronBuilder-DaSUm2Na.d.mts +47 -0
  17. package/dist/CronBuilder-DaSUm2Na.d.mts.map +1 -0
  18. package/dist/{CronBuilder-CYKT5RiO.mjs → CronBuilder-Dmix_Pen.mjs} +37 -21
  19. package/dist/CronBuilder-Dmix_Pen.mjs.map +1 -0
  20. package/dist/CronBuilder-g1lZLWyG.d.cts +47 -0
  21. package/dist/CronBuilder-g1lZLWyG.d.cts.map +1 -0
  22. package/dist/{Endpoint-DCQPMdUX.mjs → Endpoint-BG4UJ9oA.mjs} +146 -109
  23. package/dist/Endpoint-BG4UJ9oA.mjs.map +1 -0
  24. package/dist/{Endpoint-DcWXE-SZ.cjs → Endpoint-BoUg8ocM.cjs} +174 -131
  25. package/dist/Endpoint-BoUg8ocM.cjs.map +1 -0
  26. package/dist/{Endpoint-BjWKinFA.d.mts → Endpoint-Du-NwPX2.d.mts} +83 -91
  27. package/dist/Endpoint-Du-NwPX2.d.mts.map +1 -0
  28. package/dist/{Endpoint-dav89W6-.d.cts → Endpoint-aCvBMPoH.d.cts} +82 -90
  29. package/dist/Endpoint-aCvBMPoH.d.cts.map +1 -0
  30. package/dist/{EndpointFactory-CjV8F_lJ.mjs → EndpointFactory-BDtsrEvJ.mjs} +57 -76
  31. package/dist/EndpointFactory-BDtsrEvJ.mjs.map +1 -0
  32. package/dist/{EndpointFactory-CdWB7wPw.cjs → EndpointFactory-DJ7gXLpR.cjs} +93 -112
  33. package/dist/EndpointFactory-DJ7gXLpR.cjs.map +1 -0
  34. package/dist/{index-Bd5FqCoe.d.cts → EndpointFactory-DMYdJCOj.d.mts} +78 -134
  35. package/dist/EndpointFactory-DMYdJCOj.d.mts.map +1 -0
  36. package/dist/{index-lAO9egTb.d.mts → EndpointFactory-I7s1co3Y.d.cts} +79 -135
  37. package/dist/EndpointFactory-I7s1co3Y.d.cts.map +1 -0
  38. package/dist/Function-DuqGcbOI.d.mts +76 -0
  39. package/dist/Function-DuqGcbOI.d.mts.map +1 -0
  40. package/dist/Function-Pu-1kKZz.d.cts +76 -0
  41. package/dist/Function-Pu-1kKZz.d.cts.map +1 -0
  42. package/dist/{HonoEndpointAdaptor-P1ahhZHu.mjs → HonoEndpointAdaptor-PtPlbeKY.mjs} +75 -56
  43. package/dist/HonoEndpointAdaptor-PtPlbeKY.mjs.map +1 -0
  44. package/dist/{HonoEndpointAdaptor-DtL9j19R.cjs → HonoEndpointAdaptor-zVzVLJEO.cjs} +83 -61
  45. package/dist/HonoEndpointAdaptor-zVzVLJEO.cjs.map +1 -0
  46. package/dist/Queue-A3wfD0it.cjs +109 -0
  47. package/dist/Queue-A3wfD0it.cjs.map +1 -0
  48. package/dist/Queue-D6USGS4q.mjs +104 -0
  49. package/dist/Queue-D6USGS4q.mjs.map +1 -0
  50. package/dist/{Queue-D7ZuwBhy.d.cts → Queue-DlsHRzUp.d.mts} +48 -48
  51. package/dist/Queue-DlsHRzUp.d.mts.map +1 -0
  52. package/dist/{Queue-gVGfi2Yk.d.mts → Queue-HPyi0e1i.d.cts} +49 -49
  53. package/dist/Queue-HPyi0e1i.d.cts.map +1 -0
  54. package/dist/QueueBuilder-BjuF0UBl.cjs +135 -0
  55. package/dist/QueueBuilder-BjuF0UBl.cjs.map +1 -0
  56. package/dist/QueueBuilder-Cue73M4t.mjs +118 -0
  57. package/dist/QueueBuilder-Cue73M4t.mjs.map +1 -0
  58. package/dist/QueueBuilder-OSi6LkV9.d.cts +75 -0
  59. package/dist/QueueBuilder-OSi6LkV9.d.cts.map +1 -0
  60. package/dist/QueueBuilder-QHsnVt1P.d.mts +75 -0
  61. package/dist/QueueBuilder-QHsnVt1P.d.mts.map +1 -0
  62. package/dist/{Subscriber-2mEi0ImH.d.cts → Subscriber-Bpp02cGr.d.cts} +29 -20
  63. package/dist/Subscriber-Bpp02cGr.d.cts.map +1 -0
  64. package/dist/{Subscriber-xTJ9ayPN.d.mts → Subscriber-CtN9R48-.d.mts} +29 -20
  65. package/dist/Subscriber-CtN9R48-.d.mts.map +1 -0
  66. package/dist/{SubscriberBuilder-BjkbeT9l.mjs → SubscriberBuilder-CDy4nHCz.mjs} +50 -24
  67. package/dist/SubscriberBuilder-CDy4nHCz.mjs.map +1 -0
  68. package/dist/SubscriberBuilder-CuCMFpYW.d.mts +67 -0
  69. package/dist/SubscriberBuilder-CuCMFpYW.d.mts.map +1 -0
  70. package/dist/{SubscriberBuilder-4OPehf2R.cjs → SubscriberBuilder-D_owVoHo.cjs} +61 -36
  71. package/dist/SubscriberBuilder-D_owVoHo.cjs.map +1 -0
  72. package/dist/SubscriberBuilder-g3fAVWgs.d.cts +67 -0
  73. package/dist/SubscriberBuilder-g3fAVWgs.d.cts.map +1 -0
  74. package/dist/Topic-D74b5cgs.mjs +99 -0
  75. package/dist/Topic-D74b5cgs.mjs.map +1 -0
  76. package/dist/Topic-GHxcU8AG.cjs +104 -0
  77. package/dist/Topic-GHxcU8AG.cjs.map +1 -0
  78. package/dist/adaptors/aws.cjs +131 -220
  79. package/dist/adaptors/aws.cjs.map +1 -1
  80. package/dist/adaptors/aws.d.cts +34 -53
  81. package/dist/adaptors/aws.d.cts.map +1 -1
  82. package/dist/adaptors/aws.d.mts +34 -53
  83. package/dist/adaptors/aws.d.mts.map +1 -1
  84. package/dist/adaptors/aws.mjs +102 -193
  85. package/dist/adaptors/aws.mjs.map +1 -1
  86. package/dist/adaptors/hono.cjs +3 -10
  87. package/dist/adaptors/hono.d.cts +7 -16
  88. package/dist/adaptors/hono.d.cts.map +1 -1
  89. package/dist/adaptors/hono.d.mts +8 -17
  90. package/dist/adaptors/hono.d.mts.map +1 -1
  91. package/dist/adaptors/hono.mjs +2 -10
  92. package/dist/adaptors/testing.cjs +743 -89
  93. package/dist/adaptors/testing.cjs.map +1 -1
  94. package/dist/adaptors/testing.d.cts +351 -54
  95. package/dist/adaptors/testing.d.cts.map +1 -1
  96. package/dist/adaptors/testing.d.mts +351 -54
  97. package/dist/adaptors/testing.d.mts.map +1 -1
  98. package/dist/adaptors/testing.mjs +706 -70
  99. package/dist/adaptors/testing.mjs.map +1 -1
  100. package/dist/auth-BMCJN30Y.d.cts +268 -0
  101. package/dist/auth-BMCJN30Y.d.cts.map +1 -0
  102. package/dist/auth-CcuceLYo.d.mts +268 -0
  103. package/dist/auth-CcuceLYo.d.mts.map +1 -0
  104. package/dist/auth.cjs +301 -33
  105. package/dist/auth.cjs.map +1 -1
  106. package/dist/auth.d.cts +2 -108
  107. package/dist/auth.d.mts +2 -108
  108. package/dist/auth.mjs +289 -27
  109. package/dist/auth.mjs.map +1 -1
  110. package/dist/{cache-BrRz3fEB.d.mts → cache-CXh6GIgb.d.mts} +3 -6
  111. package/dist/cache-CXh6GIgb.d.mts.map +1 -0
  112. package/dist/{cache-BtZY_tHe.d.cts → cache-DnGDGly3.d.cts} +3 -6
  113. package/dist/cache-DnGDGly3.d.cts.map +1 -0
  114. package/dist/cache.cjs +68 -2
  115. package/dist/cache.cjs.map +1 -0
  116. package/dist/cache.d.cts +1 -2
  117. package/dist/cache.d.mts +1 -2
  118. package/dist/cache.mjs +67 -2
  119. package/dist/cache.mjs.map +1 -0
  120. package/dist/cipher-C1lEFX63.mjs +225 -0
  121. package/dist/cipher-C1lEFX63.mjs.map +1 -0
  122. package/dist/cipher-CVxfwLjk.cjs +332 -0
  123. package/dist/cipher-CVxfwLjk.cjs.map +1 -0
  124. package/dist/{clone-DblgEZZa.mjs → clone-EKNovYHu.mjs} +3 -3
  125. package/dist/clone-EKNovYHu.mjs.map +1 -0
  126. package/dist/{clone-Dy0cR2SZ.cjs → clone-UGJpvQnL.cjs} +7 -8
  127. package/dist/clone-UGJpvQnL.cjs.map +1 -0
  128. package/dist/{construct-interface-D9d4Gm4p.d.cts → construct-interface-B1AfqRl4.d.cts} +42 -11
  129. package/dist/construct-interface-B1AfqRl4.d.cts.map +1 -0
  130. package/dist/{construct-interface-g5GM5pwR.d.mts → construct-interface-DluK3_da.d.mts} +42 -11
  131. package/dist/construct-interface-DluK3_da.d.mts.map +1 -0
  132. package/dist/construct-interface.cjs +113 -7
  133. package/dist/construct-interface.cjs.map +1 -0
  134. package/dist/construct-interface.d.cts +2 -2
  135. package/dist/construct-interface.d.mts +2 -2
  136. package/dist/construct-interface.mjs +106 -2
  137. package/dist/construct-interface.mjs.map +1 -0
  138. package/dist/credential.cjs +77 -17
  139. package/dist/credential.cjs.map +1 -1
  140. package/dist/credential.d.cts +34 -9
  141. package/dist/credential.d.cts.map +1 -1
  142. package/dist/credential.d.mts +34 -9
  143. package/dist/credential.d.mts.map +1 -1
  144. package/dist/credential.mjs +71 -13
  145. package/dist/credential.mjs.map +1 -1
  146. package/dist/crons/index.cjs +129 -7
  147. package/dist/crons/index.cjs.map +1 -1
  148. package/dist/crons/index.d.cts +45 -11
  149. package/dist/crons/index.d.cts.map +1 -1
  150. package/dist/crons/index.d.mts +45 -11
  151. package/dist/crons/index.d.mts.map +1 -1
  152. package/dist/crons/index.mjs +127 -8
  153. package/dist/crons/index.mjs.map +1 -1
  154. package/dist/database/kysely.cjs +4 -181
  155. package/dist/database/kysely.d.cts +2 -152
  156. package/dist/database/kysely.d.mts +2 -152
  157. package/dist/database/kysely.mjs +2 -180
  158. package/dist/email.cjs +25 -12
  159. package/dist/email.cjs.map +1 -1
  160. package/dist/email.d.cts +3 -7
  161. package/dist/email.d.cts.map +1 -1
  162. package/dist/email.d.mts +3 -7
  163. package/dist/email.d.mts.map +1 -1
  164. package/dist/email.mjs +16 -3
  165. package/dist/email.mjs.map +1 -1
  166. package/dist/encryption.cjs +96 -0
  167. package/dist/encryption.cjs.map +1 -0
  168. package/dist/encryption.d.cts +117 -0
  169. package/dist/encryption.d.cts.map +1 -0
  170. package/dist/encryption.d.mts +117 -0
  171. package/dist/encryption.d.mts.map +1 -0
  172. package/dist/encryption.mjs +83 -0
  173. package/dist/encryption.mjs.map +1 -0
  174. package/dist/endpoints/index.cjs +8 -10
  175. package/dist/endpoints/index.d.cts +51 -7
  176. package/dist/endpoints/index.d.cts.map +1 -0
  177. package/dist/endpoints/index.d.mts +51 -7
  178. package/dist/endpoints/index.d.mts.map +1 -0
  179. package/dist/endpoints/index.mjs +6 -10
  180. package/dist/external-api-MJ8id87V.d.mts +105 -0
  181. package/dist/external-api-MJ8id87V.d.mts.map +1 -0
  182. package/dist/external-api-O107yzZJ.d.cts +105 -0
  183. package/dist/external-api-O107yzZJ.d.cts.map +1 -0
  184. package/dist/external-api.cjs +142 -0
  185. package/dist/external-api.cjs.map +1 -0
  186. package/dist/external-api.d.cts +2 -0
  187. package/dist/external-api.d.mts +2 -0
  188. package/dist/external-api.mjs +139 -0
  189. package/dist/external-api.mjs.map +1 -0
  190. package/dist/file-server.cjs +42 -10
  191. package/dist/file-server.cjs.map +1 -1
  192. package/dist/file-server.d.cts +6 -10
  193. package/dist/file-server.d.cts.map +1 -1
  194. package/dist/file-server.d.mts +6 -10
  195. package/dist/file-server.d.mts.map +1 -1
  196. package/dist/file-server.mjs +34 -2
  197. package/dist/file-server.mjs.map +1 -1
  198. package/dist/functions/index.cjs +3 -6
  199. package/dist/functions/index.d.cts +3 -4
  200. package/dist/functions/index.d.mts +3 -4
  201. package/dist/functions/index.mjs +2 -6
  202. package/dist/{functions-14lpEFL4.mjs → functions-BFizikJU.mjs} +376 -238
  203. package/dist/{functions-14lpEFL4.mjs.map → functions-BFizikJU.mjs.map} +1 -1
  204. package/dist/{functions-i_la-N5r.cjs → functions-CfzJG9hK.cjs} +414 -264
  205. package/dist/functions-CfzJG9hK.cjs.map +1 -0
  206. package/dist/index-BuzRvKOQ.d.cts +115 -0
  207. package/dist/index-BuzRvKOQ.d.cts.map +1 -0
  208. package/dist/index-CTkKOer4.d.mts +115 -0
  209. package/dist/index-CTkKOer4.d.mts.map +1 -0
  210. package/dist/index-CeEtxDmK.d.cts +79 -0
  211. package/dist/index-CeEtxDmK.d.cts.map +1 -0
  212. package/dist/index-CeEtxDmK.d.mts +79 -0
  213. package/dist/index-CeEtxDmK.d.mts.map +1 -0
  214. package/dist/index.cjs +6 -3
  215. package/dist/index.d.cts +27 -4
  216. package/dist/index.d.cts.map +1 -0
  217. package/dist/index.d.mts +27 -4
  218. package/dist/index.d.mts.map +1 -0
  219. package/dist/index.mjs +3 -3
  220. package/dist/kms-B-Hm3d5r.cjs +85 -0
  221. package/dist/kms-B-Hm3d5r.cjs.map +1 -0
  222. package/dist/kms-BdUlMJEZ.mjs +85 -0
  223. package/dist/kms-BdUlMJEZ.mjs.map +1 -0
  224. package/dist/kysely-Bii4l6eP.mjs +370 -0
  225. package/dist/kysely-Bii4l6eP.mjs.map +1 -0
  226. package/dist/kysely-CO_Dk43W.cjs +383 -0
  227. package/dist/kysely-CO_Dk43W.cjs.map +1 -0
  228. package/dist/kysely-D0bpzgPs.d.cts +175 -0
  229. package/dist/kysely-D0bpzgPs.d.cts.map +1 -0
  230. package/dist/kysely-DUqC3Ie0.d.mts +175 -0
  231. package/dist/kysely-DUqC3Ie0.d.mts.map +1 -0
  232. package/dist/{telemetry-C3L0iS28.d.cts → lambdaTelemetry-8vnmVZQ5.d.cts} +3 -6
  233. package/dist/lambdaTelemetry-8vnmVZQ5.d.cts.map +1 -0
  234. package/dist/{telemetry-D7bVFLGi.d.mts → lambdaTelemetry-8vnmVZQ5.d.mts} +3 -6
  235. package/dist/lambdaTelemetry-8vnmVZQ5.d.mts.map +1 -0
  236. package/dist/{lazyAccessors-BoJN3SMd.mjs → lazyAccessors-CFanua0O.mjs} +20 -60
  237. package/dist/lazyAccessors-CFanua0O.mjs.map +1 -0
  238. package/dist/{lazyAccessors-e3j2oE2m.cjs → lazyAccessors-hJKGv8Ay.cjs} +60 -113
  239. package/dist/lazyAccessors-hJKGv8Ay.cjs.map +1 -0
  240. package/dist/mobile-app.cjs +73 -0
  241. package/dist/mobile-app.cjs.map +1 -0
  242. package/dist/mobile-app.d.cts +61 -0
  243. package/dist/mobile-app.d.cts.map +1 -0
  244. package/dist/mobile-app.d.mts +61 -0
  245. package/dist/mobile-app.d.mts.map +1 -0
  246. package/dist/mobile-app.mjs +72 -0
  247. package/dist/mobile-app.mjs.map +1 -0
  248. package/dist/object-storage.cjs +18 -10
  249. package/dist/object-storage.cjs.map +1 -1
  250. package/dist/object-storage.d.cts +3 -7
  251. package/dist/object-storage.d.cts.map +1 -1
  252. package/dist/object-storage.d.mts +3 -7
  253. package/dist/object-storage.d.mts.map +1 -1
  254. package/dist/object-storage.mjs +11 -3
  255. package/dist/object-storage.mjs.map +1 -1
  256. package/dist/processAudits-BRRVVHUB.mjs +131 -0
  257. package/dist/processAudits-BRRVVHUB.mjs.map +1 -0
  258. package/dist/processAudits-DasOZjPl.cjs +154 -0
  259. package/dist/processAudits-DasOZjPl.cjs.map +1 -0
  260. package/dist/queue/index.cjs +6 -189
  261. package/dist/queue/index.d.cts +3 -60
  262. package/dist/queue/index.d.mts +3 -60
  263. package/dist/queue/index.mjs +3 -186
  264. package/dist/rest-api.cjs +90 -59
  265. package/dist/rest-api.cjs.map +1 -1
  266. package/dist/rest-api.d.cts +70 -42
  267. package/dist/rest-api.d.cts.map +1 -1
  268. package/dist/rest-api.d.mts +70 -42
  269. package/dist/rest-api.d.mts.map +1 -1
  270. package/dist/rest-api.mjs +82 -51
  271. package/dist/rest-api.mjs.map +1 -1
  272. package/dist/{chunk-DWy1uDak.cjs → rolldown-runtime-y5ARvAq5.cjs} +14 -18
  273. package/dist/runSubscriber-BHvJ8POr.mjs +109 -0
  274. package/dist/runSubscriber-BHvJ8POr.mjs.map +1 -0
  275. package/dist/runSubscriber-D8nLXIv1.cjs +126 -0
  276. package/dist/runSubscriber-D8nLXIv1.cjs.map +1 -0
  277. package/dist/shutdown-BMJmAhSt.cjs +38 -0
  278. package/dist/shutdown-BMJmAhSt.cjs.map +1 -0
  279. package/dist/shutdown-C7xa8x9S.mjs +27 -0
  280. package/dist/shutdown-C7xa8x9S.mjs.map +1 -0
  281. package/dist/site.cjs +33 -7
  282. package/dist/site.cjs.map +1 -1
  283. package/dist/site.d.cts +17 -7
  284. package/dist/site.d.cts.map +1 -1
  285. package/dist/site.d.mts +17 -7
  286. package/dist/site.d.mts.map +1 -1
  287. package/dist/site.mjs +29 -3
  288. package/dist/site.mjs.map +1 -1
  289. package/dist/stages-BSCF19o2.d.cts +56 -0
  290. package/dist/stages-BSCF19o2.d.cts.map +1 -0
  291. package/dist/stages-BSCF19o2.d.mts +56 -0
  292. package/dist/stages-BSCF19o2.d.mts.map +1 -0
  293. package/dist/subscribers/index.cjs +118 -6
  294. package/dist/subscribers/index.cjs.map +1 -0
  295. package/dist/subscribers/index.d.cts +51 -6
  296. package/dist/subscribers/index.d.cts.map +1 -0
  297. package/dist/subscribers/index.d.mts +51 -6
  298. package/dist/subscribers/index.d.mts.map +1 -0
  299. package/dist/subscribers/index.mjs +115 -5
  300. package/dist/subscribers/index.mjs.map +1 -0
  301. package/dist/surfaceEnv-CNimK76p.cjs +56 -0
  302. package/dist/surfaceEnv-CNimK76p.cjs.map +1 -0
  303. package/dist/surfaceEnv-wMT5QzgZ.mjs +45 -0
  304. package/dist/surfaceEnv-wMT5QzgZ.mjs.map +1 -0
  305. package/dist/telemetry-B48RLjyk.d.cts +40 -0
  306. package/dist/telemetry-B48RLjyk.d.cts.map +1 -0
  307. package/dist/telemetry-DRtT1_0A.d.mts +40 -0
  308. package/dist/telemetry-DRtT1_0A.d.mts.map +1 -0
  309. package/dist/telemetry.cjs +56 -0
  310. package/dist/telemetry.cjs.map +1 -0
  311. package/dist/telemetry.d.cts +2 -0
  312. package/dist/telemetry.d.mts +2 -0
  313. package/dist/telemetry.mjs +55 -0
  314. package/dist/telemetry.mjs.map +1 -0
  315. package/dist/topic/index.cjs +3 -137
  316. package/dist/topic/index.d.cts +2 -4
  317. package/dist/topic/index.d.mts +2 -4
  318. package/dist/topic/index.mjs +2 -134
  319. package/dist/tracing-CxaZ98IB.mjs +110 -0
  320. package/dist/tracing-CxaZ98IB.mjs.map +1 -0
  321. package/dist/tracing-DPMidF_r.cjs +127 -0
  322. package/dist/tracing-DPMidF_r.cjs.map +1 -0
  323. package/dist/{types-BlAkSuGI.d.cts → types-DMuSQeLL.d.cts} +3 -5
  324. package/dist/types-DMuSQeLL.d.cts.map +1 -0
  325. package/dist/{types-aKksMEWL.d.mts → types-DMuSQeLL.d.mts} +3 -5
  326. package/dist/types-DMuSQeLL.d.mts.map +1 -0
  327. package/dist/types.d.cts +1 -1
  328. package/dist/types.d.mts +1 -1
  329. package/dist/types.mjs +1 -0
  330. package/dist/worker.cjs +59 -34
  331. package/dist/worker.cjs.map +1 -1
  332. package/dist/worker.d.cts +70 -45
  333. package/dist/worker.d.cts.map +1 -1
  334. package/dist/worker.d.mts +70 -44
  335. package/dist/worker.d.mts.map +1 -1
  336. package/dist/worker.mjs +54 -29
  337. package/dist/worker.mjs.map +1 -1
  338. package/package.json +96 -42
  339. package/dist/Construct-BD5neF7w.mjs.map +0 -1
  340. package/dist/Construct-C0ijr2qp.d.cts +0 -117
  341. package/dist/Construct-C0ijr2qp.d.cts.map +0 -1
  342. package/dist/Construct-Ct8nalEi.d.mts +0 -117
  343. package/dist/Construct-Ct8nalEi.d.mts.map +0 -1
  344. package/dist/Construct-CyS3RpTL.cjs.map +0 -1
  345. package/dist/Cron-DmQ8vQ4b.d.cts.map +0 -1
  346. package/dist/Cron-dh4rUgib.d.mts.map +0 -1
  347. package/dist/CronBuilder-BquXDbDI.d.cts +0 -44
  348. package/dist/CronBuilder-BquXDbDI.d.cts.map +0 -1
  349. package/dist/CronBuilder-CGgY2080.d.mts +0 -44
  350. package/dist/CronBuilder-CGgY2080.d.mts.map +0 -1
  351. package/dist/CronBuilder-CYKT5RiO.mjs.map +0 -1
  352. package/dist/CronBuilder-Da0C0edR.cjs.map +0 -1
  353. package/dist/Endpoint-BjWKinFA.d.mts.map +0 -1
  354. package/dist/Endpoint-DCQPMdUX.mjs.map +0 -1
  355. package/dist/Endpoint-DcWXE-SZ.cjs.map +0 -1
  356. package/dist/Endpoint-dav89W6-.d.cts.map +0 -1
  357. package/dist/EndpointFactory-CdWB7wPw.cjs.map +0 -1
  358. package/dist/EndpointFactory-CjV8F_lJ.mjs.map +0 -1
  359. package/dist/HonoEndpointAdaptor-DtL9j19R.cjs.map +0 -1
  360. package/dist/HonoEndpointAdaptor-P1ahhZHu.mjs.map +0 -1
  361. package/dist/Queue-D7ZuwBhy.d.cts.map +0 -1
  362. package/dist/Queue-gVGfi2Yk.d.mts.map +0 -1
  363. package/dist/Subscriber-2mEi0ImH.d.cts.map +0 -1
  364. package/dist/Subscriber-xTJ9ayPN.d.mts.map +0 -1
  365. package/dist/SubscriberBuilder-4OPehf2R.cjs.map +0 -1
  366. package/dist/SubscriberBuilder-BjkbeT9l.mjs.map +0 -1
  367. package/dist/SubscriberBuilder-Dptmo-1A.d.mts +0 -62
  368. package/dist/SubscriberBuilder-Dptmo-1A.d.mts.map +0 -1
  369. package/dist/SubscriberBuilder-waNhzjSM.d.cts +0 -62
  370. package/dist/SubscriberBuilder-waNhzjSM.d.cts.map +0 -1
  371. package/dist/Topic-19QeHBIR.d.cts +0 -91
  372. package/dist/Topic-19QeHBIR.d.cts.map +0 -1
  373. package/dist/Topic-DuFeqkBh.d.mts +0 -91
  374. package/dist/Topic-DuFeqkBh.d.mts.map +0 -1
  375. package/dist/auth.d.cts.map +0 -1
  376. package/dist/auth.d.mts.map +0 -1
  377. package/dist/cache-0ANvRQnD.mjs +0 -51
  378. package/dist/cache-0ANvRQnD.mjs.map +0 -1
  379. package/dist/cache-3WSvAulx.cjs +0 -57
  380. package/dist/cache-3WSvAulx.cjs.map +0 -1
  381. package/dist/cache-BrRz3fEB.d.mts.map +0 -1
  382. package/dist/cache-BtZY_tHe.d.cts.map +0 -1
  383. package/dist/clone-DblgEZZa.mjs.map +0 -1
  384. package/dist/clone-Dy0cR2SZ.cjs.map +0 -1
  385. package/dist/construct-interface-BfjcOD_E.cjs +0 -117
  386. package/dist/construct-interface-BfjcOD_E.cjs.map +0 -1
  387. package/dist/construct-interface-D9d4Gm4p.d.cts.map +0 -1
  388. package/dist/construct-interface-Z4CpS8tK.mjs +0 -81
  389. package/dist/construct-interface-Z4CpS8tK.mjs.map +0 -1
  390. package/dist/construct-interface-g5GM5pwR.d.mts.map +0 -1
  391. package/dist/database/kysely.cjs.map +0 -1
  392. package/dist/database/kysely.d.cts.map +0 -1
  393. package/dist/database/kysely.d.mts.map +0 -1
  394. package/dist/database/kysely.mjs.map +0 -1
  395. package/dist/functions-i_la-N5r.cjs.map +0 -1
  396. package/dist/index-Bd5FqCoe.d.cts.map +0 -1
  397. package/dist/index-BknhM6Ux.d.mts +0 -31
  398. package/dist/index-BknhM6Ux.d.mts.map +0 -1
  399. package/dist/index-CBSfrowv.d.cts +0 -31
  400. package/dist/index-CBSfrowv.d.cts.map +0 -1
  401. package/dist/index-D24Xm79M.d.cts +0 -171
  402. package/dist/index-D24Xm79M.d.cts.map +0 -1
  403. package/dist/index-_ajboYxK.d.mts +0 -171
  404. package/dist/index-_ajboYxK.d.mts.map +0 -1
  405. package/dist/index-lAO9egTb.d.mts.map +0 -1
  406. package/dist/lazyAccessors-BoJN3SMd.mjs.map +0 -1
  407. package/dist/lazyAccessors-e3j2oE2m.cjs.map +0 -1
  408. package/dist/processAudits-CGqttuXm.cjs +0 -92
  409. package/dist/processAudits-CGqttuXm.cjs.map +0 -1
  410. package/dist/processAudits-Dmts9H_b.mjs +0 -80
  411. package/dist/processAudits-Dmts9H_b.mjs.map +0 -1
  412. package/dist/queue/index.cjs.map +0 -1
  413. package/dist/queue/index.d.cts.map +0 -1
  414. package/dist/queue/index.d.mts.map +0 -1
  415. package/dist/queue/index.mjs.map +0 -1
  416. package/dist/surfaceEnv-BFXEms2f.cjs +0 -39
  417. package/dist/surfaceEnv-BFXEms2f.cjs.map +0 -1
  418. package/dist/surfaceEnv-C3Ktahea.mjs +0 -27
  419. package/dist/surfaceEnv-C3Ktahea.mjs.map +0 -1
  420. package/dist/telemetry-C3L0iS28.d.cts.map +0 -1
  421. package/dist/telemetry-D7bVFLGi.d.mts.map +0 -1
  422. package/dist/topic/index.cjs.map +0 -1
  423. package/dist/topic/index.mjs.map +0 -1
  424. package/dist/types-BlAkSuGI.d.cts.map +0 -1
  425. package/dist/types-aKksMEWL.d.mts.map +0 -1
@@ -0,0 +1,131 @@
1
+ //#region src/endpoints/optionalPeers.ts
2
+ /**
3
+ * The optional peers an endpoint needs only for a feature it opted into.
4
+ *
5
+ * `@geekmidas/audit`, `@geekmidas/rate-limit` and `@geekmidas/db` are optional
6
+ * peers of this package: an app that audits nothing, limits nothing and sets
7
+ * no row-level security need not install them. The adaptor every endpoint is
8
+ * served by used to import them at the top, so serving any endpoint needed
9
+ * them all — and a production bundle of an app without them failed to build.
10
+ * They are loaded here, when an endpoint that uses one is served, which is
11
+ * also when the app declaring that endpoint has installed it: an auditor's
12
+ * storage, a rate limit's store and an RLS policy's database come from these
13
+ * packages.
14
+ *
15
+ * The `try` is load-bearing beyond the error it names: a bundler leaves an
16
+ * import it cannot resolve to run time when the import is guarded, and fails
17
+ * the build when it is not.
18
+ */
19
+ /** An endpoint uses a feature whose optional peer is not installed. */
20
+ var OptionalPeerMissing = class extends Error {
21
+ packageName;
22
+ feature;
23
+ constructor(packageName, feature, cause) {
24
+ super(`${feature} needs '${packageName}', which could not be loaded. Add it to the dependencies of the app that serves this endpoint.`, { cause });
25
+ this.packageName = packageName;
26
+ this.feature = feature;
27
+ this.name = "OptionalPeerMissing";
28
+ }
29
+ };
30
+ /** `@geekmidas/audit`, for an endpoint with an auditor. */
31
+ async function loadAudit() {
32
+ try {
33
+ return await import("@geekmidas/audit");
34
+ } catch (cause) {
35
+ throw new OptionalPeerMissing("@geekmidas/audit", "An endpoint with an auditor", cause);
36
+ }
37
+ }
38
+ /** `@geekmidas/rate-limit`, for an endpoint with a rate limit. */
39
+ async function loadRateLimit() {
40
+ try {
41
+ return await import("@geekmidas/rate-limit");
42
+ } catch (cause) {
43
+ throw new OptionalPeerMissing("@geekmidas/rate-limit", "An endpoint with a rate limit", cause);
44
+ }
45
+ }
46
+ /** `@geekmidas/db/rls`, for an endpoint with row-level security. */
47
+ async function loadRls() {
48
+ try {
49
+ return await import("@geekmidas/db/rls");
50
+ } catch (cause) {
51
+ throw new OptionalPeerMissing("@geekmidas/db", "An endpoint with row-level security", cause);
52
+ }
53
+ }
54
+ //#endregion
55
+ //#region src/endpoints/processAudits.ts
56
+ /**
57
+ * Create audit context for handler execution.
58
+ * Returns the auditor and storage for use in the handler.
59
+ *
60
+ * @param endpoint - The endpoint with audit configuration
61
+ * @param serviceDiscovery - Service discovery for getting audit storage
62
+ * @param logger - Logger for debug/error messages
63
+ * @param ctx - Request context for actor extraction
64
+ * @returns Audit context with auditor and storage, or undefined if not configured
65
+ */
66
+ async function createAuditContext(endpoint, serviceDiscovery, logger, ctx) {
67
+ if (!endpoint.auditorStorageService) return;
68
+ const storage = (await serviceDiscovery.register([endpoint.auditorStorageService]))[endpoint.auditorStorageService.serviceName];
69
+ let actor = {
70
+ id: "system",
71
+ type: "system"
72
+ };
73
+ if (endpoint.actorExtractor) try {
74
+ actor = await endpoint.actorExtractor({
75
+ services: ctx.services,
76
+ session: ctx.session,
77
+ header: ctx.header,
78
+ cookie: ctx.cookie,
79
+ logger
80
+ });
81
+ } catch (error) {
82
+ logger.error(error, "Failed to extract actor for audits");
83
+ }
84
+ const { DefaultAuditor } = await loadAudit();
85
+ return {
86
+ auditor: new DefaultAuditor({
87
+ actor,
88
+ storage,
89
+ metadata: {
90
+ endpoint: endpoint.route,
91
+ method: endpoint.method
92
+ }
93
+ }),
94
+ storage
95
+ };
96
+ }
97
+ /**
98
+ * Execute a handler with automatic audit transaction support.
99
+ * If the audit storage provides a withTransaction method, wraps execution
100
+ * in a transaction so audits are atomic with handler's database operations.
101
+ *
102
+ * This is database-agnostic - each storage implementation provides its own
103
+ * transaction handling based on the underlying database (Kysely, Drizzle, etc.).
104
+ *
105
+ * If the db parameter is provided and is already a transaction, the storage
106
+ * will reuse it instead of creating a nested transaction (similar to
107
+ * packages/db/src/kysely.ts#withTransaction).
108
+ *
109
+ * @param auditContext - The audit context from createAuditContext
110
+ * @param handler - The handler function to execute (receives auditor)
111
+ * @param onComplete - Called after handler with response, to process declarative audits
112
+ * @param options - Optional configuration including database connection
113
+ * @returns The handler result
114
+ */
115
+ async function executeWithAuditTransaction(auditContext, handler, onComplete, options) {
116
+ if (!auditContext) return handler(void 0);
117
+ const { auditor, storage } = auditContext;
118
+ if (storage.withTransaction) return storage.withTransaction(auditor, async () => {
119
+ const response = await handler(auditor);
120
+ if (onComplete) await onComplete(response, auditor);
121
+ return response;
122
+ }, options?.db);
123
+ const response = await handler(auditor);
124
+ if (onComplete) await onComplete(response, auditor);
125
+ await auditor.flush();
126
+ return response;
127
+ }
128
+ //#endregion
129
+ export { loadRls as i, executeWithAuditTransaction as n, loadRateLimit as r, createAuditContext as t };
130
+
131
+ //# sourceMappingURL=processAudits-BRRVVHUB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processAudits-BRRVVHUB.mjs","names":[],"sources":["../src/endpoints/optionalPeers.ts","../src/endpoints/processAudits.ts"],"sourcesContent":["/**\n * The optional peers an endpoint needs only for a feature it opted into.\n *\n * `@geekmidas/audit`, `@geekmidas/rate-limit` and `@geekmidas/db` are optional\n * peers of this package: an app that audits nothing, limits nothing and sets\n * no row-level security need not install them. The adaptor every endpoint is\n * served by used to import them at the top, so serving any endpoint needed\n * them all — and a production bundle of an app without them failed to build.\n * They are loaded here, when an endpoint that uses one is served, which is\n * also when the app declaring that endpoint has installed it: an auditor's\n * storage, a rate limit's store and an RLS policy's database come from these\n * packages.\n *\n * The `try` is load-bearing beyond the error it names: a bundler leaves an\n * import it cannot resolve to run time when the import is guarded, and fails\n * the build when it is not.\n */\n\n/** An endpoint uses a feature whose optional peer is not installed. */\nexport class OptionalPeerMissing extends Error {\n\tconstructor(\n\t\treadonly packageName: string,\n\t\treadonly feature: string,\n\t\tcause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`${feature} needs '${packageName}', which could not be loaded. ` +\n\t\t\t\t`Add it to the dependencies of the app that serves this endpoint.`,\n\t\t\t{ cause },\n\t\t);\n\t\tthis.name = 'OptionalPeerMissing';\n\t}\n}\n\n/** `@geekmidas/audit`, for an endpoint with an auditor. */\nexport async function loadAudit(): Promise<typeof import('@geekmidas/audit')> {\n\ttry {\n\t\treturn await import('@geekmidas/audit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/audit',\n\t\t\t'An endpoint with an auditor',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/rate-limit`, for an endpoint with a rate limit. */\nexport async function loadRateLimit(): Promise<\n\ttypeof import('@geekmidas/rate-limit')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/rate-limit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/rate-limit',\n\t\t\t'An endpoint with a rate limit',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/db/rls`, for an endpoint with row-level security. */\nexport async function loadRls(): Promise<typeof import('@geekmidas/db/rls')> {\n\ttry {\n\t\treturn await import('@geekmidas/db/rls');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/db',\n\t\t\t'An endpoint with row-level security',\n\t\t\tcause,\n\t\t);\n\t}\n}\n","import type {\n\tAuditActor,\n\tAuditableAction,\n\tAuditor,\n\tAuditStorage,\n} from '@geekmidas/audit';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceDiscovery } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { ActorExtractor, MappedAudit } from './audit';\nimport type { CookieFn, Endpoint, HeaderFn } from './Endpoint';\nimport { loadAudit } from './optionalPeers';\n\n/**\n * Process declarative audit definitions after successful endpoint execution.\n * Similar to publishConstructEvents for events.\n *\n * @param endpoint - The endpoint with audit configuration\n * @param response - The handler response to generate audit payloads from\n * @param serviceDiscovery - Service discovery for registering audit storage\n * @param logger - Logger for debug/error messages\n * @param ctx - Request context (session, headers, cookies, services)\n * @param existingAuditor - Optional existing auditor instance (e.g., from handler context).\n * If provided, uses this auditor (with its stored transaction).\n * If not provided, creates a new auditor.\n */\nexport async function processEndpointAudits<\n\tTServices extends Service[] = [],\n\tTSession = unknown,\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n>(\n\tendpoint: Endpoint<\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tOutSchema,\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tTAuditStorage,\n\t\tTAuditStorageServiceName,\n\t\tTAuditAction\n\t>,\n\tresponse: InferStandardSchema<OutSchema>,\n\tserviceDiscovery: ServiceDiscovery<any>,\n\tlogger: TLogger,\n\tctx: {\n\t\tsession: TSession;\n\t\theader: HeaderFn;\n\t\tcookie: CookieFn;\n\t\tservices: Record<string, unknown>;\n\t},\n\texistingAuditor?: Auditor<TAuditAction>,\n): Promise<void> {\n\ttry {\n\t\tconst audits = endpoint.audits as MappedAudit<TAuditAction, OutSchema>[];\n\n\t\t// If we have an existing auditor (from handler context), we need to flush\n\t\t// any manual audits it collected, even if there are no declarative audits\n\t\tconst hasExistingRecords =\n\t\t\texistingAuditor && existingAuditor.getRecords().length > 0;\n\n\t\t// Skip if no declarative audits and no existing records to flush\n\t\tif (!audits?.length && !hasExistingRecords) {\n\t\t\tlogger.debug('No audits to process');\n\t\t\treturn;\n\t\t}\n\n\t\t// If no auditor storage service and we have things to process, warn\n\t\tif (!endpoint.auditorStorageService) {\n\t\t\tif (hasExistingRecords || audits?.length) {\n\t\t\t\tlogger.warn('No auditor storage service available');\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Get or create auditor\n\t\tlet auditor: Auditor<TAuditAction>;\n\n\t\tif (existingAuditor) {\n\t\t\t// Use existing auditor (preserves stored transaction and manual audits)\n\t\t\tauditor = existingAuditor;\n\t\t\tlogger.debug('Using existing auditor from handler context');\n\t\t} else {\n\t\t\t// Create new auditor (backward compatibility)\n\t\t\tconst services = await serviceDiscovery.register([\n\t\t\t\tendpoint.auditorStorageService,\n\t\t\t]);\n\t\t\tconst storage = services[\n\t\t\t\tendpoint.auditorStorageService.serviceName\n\t\t\t] as AuditStorage;\n\n\t\t\t// Extract actor if configured\n\t\t\tlet actor: AuditActor = { id: 'system', type: 'system' };\n\t\t\tif (endpoint.actorExtractor) {\n\t\t\t\ttry {\n\t\t\t\t\tactor = await (\n\t\t\t\t\t\tendpoint.actorExtractor as ActorExtractor<\n\t\t\t\t\t\t\tTServices,\n\t\t\t\t\t\t\tTSession,\n\t\t\t\t\t\t\tTLogger\n\t\t\t\t\t\t>\n\t\t\t\t\t)({\n\t\t\t\t\t\tservices: ctx.services as any,\n\t\t\t\t\t\tsession: ctx.session,\n\t\t\t\t\t\theader: ctx.header,\n\t\t\t\t\t\tcookie: ctx.cookie,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error(error as Error, 'Failed to extract actor for audits');\n\t\t\t\t\t// Continue with system actor\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { DefaultAuditor } = await loadAudit();\n\t\t\tauditor = new DefaultAuditor<TAuditAction>({\n\t\t\t\tactor,\n\t\t\t\tstorage,\n\t\t\t\tmetadata: {\n\t\t\t\t\tendpoint: endpoint.route,\n\t\t\t\t\tmethod: endpoint.method,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Process each declarative audit\n\t\tif (audits?.length) {\n\t\t\tfor (const audit of audits) {\n\t\t\t\tlogger.debug({ audit: audit.type }, 'Processing declarative audit');\n\n\t\t\t\t// Check when condition\n\t\t\t\tif (audit.when && !audit.when(response as any)) {\n\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t{ audit: audit.type },\n\t\t\t\t\t\t'Audit skipped due to when condition',\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Extract payload\n\t\t\t\tconst payload = audit.payload(response as any);\n\n\t\t\t\t// Extract entityId if configured\n\t\t\t\tconst entityId = audit.entityId?.(response as any);\n\n\t\t\t\t// Record the audit\n\t\t\t\tauditor.audit(audit.type as any, payload as any, {\n\t\t\t\t\ttable: audit.table,\n\t\t\t\t\tentityId,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Flush audits to storage\n\t\t// Note: If existingAuditor has a stored transaction (via setTransaction),\n\t\t// flush() will use it automatically\n\t\tconst recordCount = auditor.getRecords().length;\n\t\tif (recordCount > 0) {\n\t\t\t// Check if auditor has a stored transaction (for logging purposes)\n\t\t\tconst trx =\n\t\t\t\t'getTransaction' in auditor\n\t\t\t\t\t? (auditor as { getTransaction(): unknown }).getTransaction()\n\t\t\t\t\t: undefined;\n\t\t\tlogger.debug(\n\t\t\t\t{ auditCount: recordCount, hasTransaction: !!trx },\n\t\t\t\t'Flushing audits',\n\t\t\t);\n\t\t\tawait auditor.flush();\n\t\t}\n\t} catch (error) {\n\t\tlogger.error(error as Error, 'Failed to process audits');\n\t\t// Don't rethrow - audit failures shouldn't fail the request\n\t}\n}\n\n/**\n * Context for audit-aware handler execution.\n */\nexport interface AuditExecutionContext<\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\t/** The auditor instance for recording audits */\n\tauditor: Auditor<TAuditAction>;\n\t/** The audit storage instance */\n\tstorage: AuditStorage;\n}\n\n/**\n * Create audit context for handler execution.\n * Returns the auditor and storage for use in the handler.\n *\n * @param endpoint - The endpoint with audit configuration\n * @param serviceDiscovery - Service discovery for getting audit storage\n * @param logger - Logger for debug/error messages\n * @param ctx - Request context for actor extraction\n * @returns Audit context with auditor and storage, or undefined if not configured\n */\nexport async function createAuditContext<\n\tTServices extends Service[] = [],\n\tTSession = unknown,\n\tTLogger extends Logger = Logger,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n>(\n\tendpoint: Endpoint<\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tTAuditStorage,\n\t\tTAuditStorageServiceName,\n\t\tTAuditAction,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t>,\n\tserviceDiscovery: ServiceDiscovery<any>,\n\tlogger: TLogger,\n\tctx: {\n\t\tsession: TSession;\n\t\theader: HeaderFn;\n\t\tcookie: CookieFn;\n\t\tservices: Record<string, unknown>;\n\t},\n): Promise<AuditExecutionContext<TAuditAction> | undefined> {\n\tif (!endpoint.auditorStorageService) {\n\t\treturn undefined;\n\t}\n\n\tconst services = await serviceDiscovery.register([\n\t\tendpoint.auditorStorageService,\n\t]);\n\tconst storage = services[\n\t\tendpoint.auditorStorageService.serviceName\n\t] as AuditStorage;\n\n\t// Extract actor if configured\n\tlet actor: AuditActor = { id: 'system', type: 'system' };\n\tif (endpoint.actorExtractor) {\n\t\ttry {\n\t\t\tactor = await (\n\t\t\t\tendpoint.actorExtractor as ActorExtractor<TServices, TSession, TLogger>\n\t\t\t)({\n\t\t\t\tservices: ctx.services as any,\n\t\t\t\tsession: ctx.session,\n\t\t\t\theader: ctx.header,\n\t\t\t\tcookie: ctx.cookie,\n\t\t\t\tlogger,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tlogger.error(error as Error, 'Failed to extract actor for audits');\n\t\t}\n\t}\n\n\tconst { DefaultAuditor } = await loadAudit();\n\tconst auditor = new DefaultAuditor<TAuditAction>({\n\t\tactor,\n\t\tstorage,\n\t\tmetadata: {\n\t\t\tendpoint: endpoint.route,\n\t\t\tmethod: endpoint.method,\n\t\t},\n\t});\n\n\treturn { auditor, storage };\n}\n\n/**\n * Options for executeWithAuditTransaction.\n */\nexport interface ExecuteWithAuditTransactionOptions {\n\t/**\n\t * Database connection to use for the transaction.\n\t * If this is already a transaction, it will be reused instead of creating a nested one.\n\t * If not provided, the storage's internal database is used.\n\t */\n\tdb?: unknown;\n}\n\n/**\n * Execute a handler with automatic audit transaction support.\n * If the audit storage provides a withTransaction method, wraps execution\n * in a transaction so audits are atomic with handler's database operations.\n *\n * This is database-agnostic - each storage implementation provides its own\n * transaction handling based on the underlying database (Kysely, Drizzle, etc.).\n *\n * If the db parameter is provided and is already a transaction, the storage\n * will reuse it instead of creating a nested transaction (similar to\n * packages/db/src/kysely.ts#withTransaction).\n *\n * @param auditContext - The audit context from createAuditContext\n * @param handler - The handler function to execute (receives auditor)\n * @param onComplete - Called after handler with response, to process declarative audits\n * @param options - Optional configuration including database connection\n * @returns The handler result\n */\nexport async function executeWithAuditTransaction<\n\tT,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n>(\n\tauditContext: AuditExecutionContext<TAuditAction> | undefined,\n\thandler: (auditor?: Auditor<TAuditAction>) => Promise<T>,\n\tonComplete?: (response: T, auditor: Auditor<TAuditAction>) => Promise<void>,\n\toptions?: ExecuteWithAuditTransactionOptions,\n): Promise<T> {\n\t// No audit context - just run handler\n\tif (!auditContext) {\n\t\treturn handler(undefined);\n\t}\n\n\tconst { auditor, storage } = auditContext;\n\n\t// Check if storage provides a transaction wrapper\n\tif (storage.withTransaction) {\n\t\t// Wrap in transaction - audits are atomic with handler operations\n\t\t// The storage's withTransaction handles setTransaction and flush\n\t\t// Pass db so existing transactions are reused\n\t\treturn storage.withTransaction(\n\t\t\tauditor,\n\t\t\tasync () => {\n\t\t\t\tconst response = await handler(auditor);\n\n\t\t\t\t// Process declarative audits within the transaction\n\t\t\t\tif (onComplete) {\n\t\t\t\t\tawait onComplete(response, auditor);\n\t\t\t\t}\n\n\t\t\t\treturn response;\n\t\t\t},\n\t\t\toptions?.db,\n\t\t);\n\t}\n\n\t// No transaction support - run handler and flush audits after\n\tconst response = await handler(auditor);\n\n\tif (onComplete) {\n\t\tawait onComplete(response, auditor);\n\t}\n\n\t// Flush audits (no transaction)\n\tawait auditor.flush();\n\n\treturn response;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,IAAa,sBAAb,cAAyC,MAAM;CAEpC;CACA;CAFV,YACC,aACA,SACA,OACC;EACD,MACC,GAAG,QAAQ,UAAU,YAAY,iGAEjC,EAAE,MAAM,CACT;EARS,KAAA,cAAA;EACA,KAAA,UAAA;EAQT,KAAK,OAAO;CACb;AACD;;AAGA,eAAsB,YAAwD;CAC7E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,oBACA,+BACA,KACD;CACD;AACD;;AAGA,eAAsB,gBAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,yBACA,iCACA,KACD;CACD;AACD;;AAGA,eAAsB,UAAuD;CAC5E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,iBACA,uCACA,KACD;CACD;AACD;;;;;;;;;;;;;ACwIA,eAAsB,mBAarB,UAcA,kBACA,QACA,KAM2D;CAC3D,IAAI,CAAC,SAAS,uBACb;CAMD,MAAM,WAAU,MAHO,iBAAiB,SAAS,CAChD,SAAS,qBACV,CAAC,EAAA,CAEA,SAAS,sBAAsB;CAIhC,IAAI,QAAoB;EAAE,IAAI;EAAU,MAAM;CAAS;CACvD,IAAI,SAAS,gBACZ,IAAI;EACH,QAAQ,MACP,SAAS,eACR;GACD,UAAU,IAAI;GACd,SAAS,IAAI;GACb,QAAQ,IAAI;GACZ,QAAQ,IAAI;GACZ;EACD,CAAC;CACF,SAAS,OAAO;EACf,OAAO,MAAM,OAAgB,oCAAoC;CAClE;CAGD,MAAM,EAAE,mBAAmB,MAAM,UAAU;CAU3C,OAAO;EAAE,SAAA,IATW,eAA6B;GAChD;GACA;GACA,UAAU;IACT,UAAU,SAAS;IACnB,QAAQ,SAAS;GAClB;EACD,CAEe;EAAG;CAAQ;AAC3B;;;;;;;;;;;;;;;;;;;AAgCA,eAAsB,4BAOrB,cACA,SACA,YACA,SACa;CAEb,IAAI,CAAC,cACJ,OAAO,QAAQ,KAAA,CAAS;CAGzB,MAAM,EAAE,SAAS,YAAY;CAG7B,IAAI,QAAQ,iBAIX,OAAO,QAAQ,gBACd,SACA,YAAY;EACX,MAAM,WAAW,MAAM,QAAQ,OAAO;EAGtC,IAAI,YACH,MAAM,WAAW,UAAU,OAAO;EAGnC,OAAO;CACR,GACA,SAAS,EACV;CAID,MAAM,WAAW,MAAM,QAAQ,OAAO;CAEtC,IAAI,YACH,MAAM,WAAW,UAAU,OAAO;CAInC,MAAM,QAAQ,MAAM;CAEpB,OAAO;AACR"}
@@ -0,0 +1,154 @@
1
+ //#region src/endpoints/optionalPeers.ts
2
+ /**
3
+ * The optional peers an endpoint needs only for a feature it opted into.
4
+ *
5
+ * `@geekmidas/audit`, `@geekmidas/rate-limit` and `@geekmidas/db` are optional
6
+ * peers of this package: an app that audits nothing, limits nothing and sets
7
+ * no row-level security need not install them. The adaptor every endpoint is
8
+ * served by used to import them at the top, so serving any endpoint needed
9
+ * them all — and a production bundle of an app without them failed to build.
10
+ * They are loaded here, when an endpoint that uses one is served, which is
11
+ * also when the app declaring that endpoint has installed it: an auditor's
12
+ * storage, a rate limit's store and an RLS policy's database come from these
13
+ * packages.
14
+ *
15
+ * The `try` is load-bearing beyond the error it names: a bundler leaves an
16
+ * import it cannot resolve to run time when the import is guarded, and fails
17
+ * the build when it is not.
18
+ */
19
+ /** An endpoint uses a feature whose optional peer is not installed. */
20
+ var OptionalPeerMissing = class extends Error {
21
+ packageName;
22
+ feature;
23
+ constructor(packageName, feature, cause) {
24
+ super(`${feature} needs '${packageName}', which could not be loaded. Add it to the dependencies of the app that serves this endpoint.`, { cause });
25
+ this.packageName = packageName;
26
+ this.feature = feature;
27
+ this.name = "OptionalPeerMissing";
28
+ }
29
+ };
30
+ /** `@geekmidas/audit`, for an endpoint with an auditor. */
31
+ async function loadAudit() {
32
+ try {
33
+ return await import("@geekmidas/audit");
34
+ } catch (cause) {
35
+ throw new OptionalPeerMissing("@geekmidas/audit", "An endpoint with an auditor", cause);
36
+ }
37
+ }
38
+ /** `@geekmidas/rate-limit`, for an endpoint with a rate limit. */
39
+ async function loadRateLimit() {
40
+ try {
41
+ return await import("@geekmidas/rate-limit");
42
+ } catch (cause) {
43
+ throw new OptionalPeerMissing("@geekmidas/rate-limit", "An endpoint with a rate limit", cause);
44
+ }
45
+ }
46
+ /** `@geekmidas/db/rls`, for an endpoint with row-level security. */
47
+ async function loadRls() {
48
+ try {
49
+ return await import("@geekmidas/db/rls");
50
+ } catch (cause) {
51
+ throw new OptionalPeerMissing("@geekmidas/db", "An endpoint with row-level security", cause);
52
+ }
53
+ }
54
+ //#endregion
55
+ //#region src/endpoints/processAudits.ts
56
+ /**
57
+ * Create audit context for handler execution.
58
+ * Returns the auditor and storage for use in the handler.
59
+ *
60
+ * @param endpoint - The endpoint with audit configuration
61
+ * @param serviceDiscovery - Service discovery for getting audit storage
62
+ * @param logger - Logger for debug/error messages
63
+ * @param ctx - Request context for actor extraction
64
+ * @returns Audit context with auditor and storage, or undefined if not configured
65
+ */
66
+ async function createAuditContext(endpoint, serviceDiscovery, logger, ctx) {
67
+ if (!endpoint.auditorStorageService) return;
68
+ const storage = (await serviceDiscovery.register([endpoint.auditorStorageService]))[endpoint.auditorStorageService.serviceName];
69
+ let actor = {
70
+ id: "system",
71
+ type: "system"
72
+ };
73
+ if (endpoint.actorExtractor) try {
74
+ actor = await endpoint.actorExtractor({
75
+ services: ctx.services,
76
+ session: ctx.session,
77
+ header: ctx.header,
78
+ cookie: ctx.cookie,
79
+ logger
80
+ });
81
+ } catch (error) {
82
+ logger.error(error, "Failed to extract actor for audits");
83
+ }
84
+ const { DefaultAuditor } = await loadAudit();
85
+ return {
86
+ auditor: new DefaultAuditor({
87
+ actor,
88
+ storage,
89
+ metadata: {
90
+ endpoint: endpoint.route,
91
+ method: endpoint.method
92
+ }
93
+ }),
94
+ storage
95
+ };
96
+ }
97
+ /**
98
+ * Execute a handler with automatic audit transaction support.
99
+ * If the audit storage provides a withTransaction method, wraps execution
100
+ * in a transaction so audits are atomic with handler's database operations.
101
+ *
102
+ * This is database-agnostic - each storage implementation provides its own
103
+ * transaction handling based on the underlying database (Kysely, Drizzle, etc.).
104
+ *
105
+ * If the db parameter is provided and is already a transaction, the storage
106
+ * will reuse it instead of creating a nested transaction (similar to
107
+ * packages/db/src/kysely.ts#withTransaction).
108
+ *
109
+ * @param auditContext - The audit context from createAuditContext
110
+ * @param handler - The handler function to execute (receives auditor)
111
+ * @param onComplete - Called after handler with response, to process declarative audits
112
+ * @param options - Optional configuration including database connection
113
+ * @returns The handler result
114
+ */
115
+ async function executeWithAuditTransaction(auditContext, handler, onComplete, options) {
116
+ if (!auditContext) return handler(void 0);
117
+ const { auditor, storage } = auditContext;
118
+ if (storage.withTransaction) return storage.withTransaction(auditor, async () => {
119
+ const response = await handler(auditor);
120
+ if (onComplete) await onComplete(response, auditor);
121
+ return response;
122
+ }, options?.db);
123
+ const response = await handler(auditor);
124
+ if (onComplete) await onComplete(response, auditor);
125
+ await auditor.flush();
126
+ return response;
127
+ }
128
+ //#endregion
129
+ Object.defineProperty(exports, "createAuditContext", {
130
+ enumerable: true,
131
+ get: function() {
132
+ return createAuditContext;
133
+ }
134
+ });
135
+ Object.defineProperty(exports, "executeWithAuditTransaction", {
136
+ enumerable: true,
137
+ get: function() {
138
+ return executeWithAuditTransaction;
139
+ }
140
+ });
141
+ Object.defineProperty(exports, "loadRateLimit", {
142
+ enumerable: true,
143
+ get: function() {
144
+ return loadRateLimit;
145
+ }
146
+ });
147
+ Object.defineProperty(exports, "loadRls", {
148
+ enumerable: true,
149
+ get: function() {
150
+ return loadRls;
151
+ }
152
+ });
153
+
154
+ //# sourceMappingURL=processAudits-DasOZjPl.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processAudits-DasOZjPl.cjs","names":[],"sources":["../src/endpoints/optionalPeers.ts","../src/endpoints/processAudits.ts"],"sourcesContent":["/**\n * The optional peers an endpoint needs only for a feature it opted into.\n *\n * `@geekmidas/audit`, `@geekmidas/rate-limit` and `@geekmidas/db` are optional\n * peers of this package: an app that audits nothing, limits nothing and sets\n * no row-level security need not install them. The adaptor every endpoint is\n * served by used to import them at the top, so serving any endpoint needed\n * them all — and a production bundle of an app without them failed to build.\n * They are loaded here, when an endpoint that uses one is served, which is\n * also when the app declaring that endpoint has installed it: an auditor's\n * storage, a rate limit's store and an RLS policy's database come from these\n * packages.\n *\n * The `try` is load-bearing beyond the error it names: a bundler leaves an\n * import it cannot resolve to run time when the import is guarded, and fails\n * the build when it is not.\n */\n\n/** An endpoint uses a feature whose optional peer is not installed. */\nexport class OptionalPeerMissing extends Error {\n\tconstructor(\n\t\treadonly packageName: string,\n\t\treadonly feature: string,\n\t\tcause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`${feature} needs '${packageName}', which could not be loaded. ` +\n\t\t\t\t`Add it to the dependencies of the app that serves this endpoint.`,\n\t\t\t{ cause },\n\t\t);\n\t\tthis.name = 'OptionalPeerMissing';\n\t}\n}\n\n/** `@geekmidas/audit`, for an endpoint with an auditor. */\nexport async function loadAudit(): Promise<typeof import('@geekmidas/audit')> {\n\ttry {\n\t\treturn await import('@geekmidas/audit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/audit',\n\t\t\t'An endpoint with an auditor',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/rate-limit`, for an endpoint with a rate limit. */\nexport async function loadRateLimit(): Promise<\n\ttypeof import('@geekmidas/rate-limit')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/rate-limit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/rate-limit',\n\t\t\t'An endpoint with a rate limit',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/db/rls`, for an endpoint with row-level security. */\nexport async function loadRls(): Promise<typeof import('@geekmidas/db/rls')> {\n\ttry {\n\t\treturn await import('@geekmidas/db/rls');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/db',\n\t\t\t'An endpoint with row-level security',\n\t\t\tcause,\n\t\t);\n\t}\n}\n","import type {\n\tAuditActor,\n\tAuditableAction,\n\tAuditor,\n\tAuditStorage,\n} from '@geekmidas/audit';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceDiscovery } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { ActorExtractor, MappedAudit } from './audit';\nimport type { CookieFn, Endpoint, HeaderFn } from './Endpoint';\nimport { loadAudit } from './optionalPeers';\n\n/**\n * Process declarative audit definitions after successful endpoint execution.\n * Similar to publishConstructEvents for events.\n *\n * @param endpoint - The endpoint with audit configuration\n * @param response - The handler response to generate audit payloads from\n * @param serviceDiscovery - Service discovery for registering audit storage\n * @param logger - Logger for debug/error messages\n * @param ctx - Request context (session, headers, cookies, services)\n * @param existingAuditor - Optional existing auditor instance (e.g., from handler context).\n * If provided, uses this auditor (with its stored transaction).\n * If not provided, creates a new auditor.\n */\nexport async function processEndpointAudits<\n\tTServices extends Service[] = [],\n\tTSession = unknown,\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n>(\n\tendpoint: Endpoint<\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tOutSchema,\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tTAuditStorage,\n\t\tTAuditStorageServiceName,\n\t\tTAuditAction\n\t>,\n\tresponse: InferStandardSchema<OutSchema>,\n\tserviceDiscovery: ServiceDiscovery<any>,\n\tlogger: TLogger,\n\tctx: {\n\t\tsession: TSession;\n\t\theader: HeaderFn;\n\t\tcookie: CookieFn;\n\t\tservices: Record<string, unknown>;\n\t},\n\texistingAuditor?: Auditor<TAuditAction>,\n): Promise<void> {\n\ttry {\n\t\tconst audits = endpoint.audits as MappedAudit<TAuditAction, OutSchema>[];\n\n\t\t// If we have an existing auditor (from handler context), we need to flush\n\t\t// any manual audits it collected, even if there are no declarative audits\n\t\tconst hasExistingRecords =\n\t\t\texistingAuditor && existingAuditor.getRecords().length > 0;\n\n\t\t// Skip if no declarative audits and no existing records to flush\n\t\tif (!audits?.length && !hasExistingRecords) {\n\t\t\tlogger.debug('No audits to process');\n\t\t\treturn;\n\t\t}\n\n\t\t// If no auditor storage service and we have things to process, warn\n\t\tif (!endpoint.auditorStorageService) {\n\t\t\tif (hasExistingRecords || audits?.length) {\n\t\t\t\tlogger.warn('No auditor storage service available');\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Get or create auditor\n\t\tlet auditor: Auditor<TAuditAction>;\n\n\t\tif (existingAuditor) {\n\t\t\t// Use existing auditor (preserves stored transaction and manual audits)\n\t\t\tauditor = existingAuditor;\n\t\t\tlogger.debug('Using existing auditor from handler context');\n\t\t} else {\n\t\t\t// Create new auditor (backward compatibility)\n\t\t\tconst services = await serviceDiscovery.register([\n\t\t\t\tendpoint.auditorStorageService,\n\t\t\t]);\n\t\t\tconst storage = services[\n\t\t\t\tendpoint.auditorStorageService.serviceName\n\t\t\t] as AuditStorage;\n\n\t\t\t// Extract actor if configured\n\t\t\tlet actor: AuditActor = { id: 'system', type: 'system' };\n\t\t\tif (endpoint.actorExtractor) {\n\t\t\t\ttry {\n\t\t\t\t\tactor = await (\n\t\t\t\t\t\tendpoint.actorExtractor as ActorExtractor<\n\t\t\t\t\t\t\tTServices,\n\t\t\t\t\t\t\tTSession,\n\t\t\t\t\t\t\tTLogger\n\t\t\t\t\t\t>\n\t\t\t\t\t)({\n\t\t\t\t\t\tservices: ctx.services as any,\n\t\t\t\t\t\tsession: ctx.session,\n\t\t\t\t\t\theader: ctx.header,\n\t\t\t\t\t\tcookie: ctx.cookie,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error(error as Error, 'Failed to extract actor for audits');\n\t\t\t\t\t// Continue with system actor\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { DefaultAuditor } = await loadAudit();\n\t\t\tauditor = new DefaultAuditor<TAuditAction>({\n\t\t\t\tactor,\n\t\t\t\tstorage,\n\t\t\t\tmetadata: {\n\t\t\t\t\tendpoint: endpoint.route,\n\t\t\t\t\tmethod: endpoint.method,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Process each declarative audit\n\t\tif (audits?.length) {\n\t\t\tfor (const audit of audits) {\n\t\t\t\tlogger.debug({ audit: audit.type }, 'Processing declarative audit');\n\n\t\t\t\t// Check when condition\n\t\t\t\tif (audit.when && !audit.when(response as any)) {\n\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t{ audit: audit.type },\n\t\t\t\t\t\t'Audit skipped due to when condition',\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Extract payload\n\t\t\t\tconst payload = audit.payload(response as any);\n\n\t\t\t\t// Extract entityId if configured\n\t\t\t\tconst entityId = audit.entityId?.(response as any);\n\n\t\t\t\t// Record the audit\n\t\t\t\tauditor.audit(audit.type as any, payload as any, {\n\t\t\t\t\ttable: audit.table,\n\t\t\t\t\tentityId,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Flush audits to storage\n\t\t// Note: If existingAuditor has a stored transaction (via setTransaction),\n\t\t// flush() will use it automatically\n\t\tconst recordCount = auditor.getRecords().length;\n\t\tif (recordCount > 0) {\n\t\t\t// Check if auditor has a stored transaction (for logging purposes)\n\t\t\tconst trx =\n\t\t\t\t'getTransaction' in auditor\n\t\t\t\t\t? (auditor as { getTransaction(): unknown }).getTransaction()\n\t\t\t\t\t: undefined;\n\t\t\tlogger.debug(\n\t\t\t\t{ auditCount: recordCount, hasTransaction: !!trx },\n\t\t\t\t'Flushing audits',\n\t\t\t);\n\t\t\tawait auditor.flush();\n\t\t}\n\t} catch (error) {\n\t\tlogger.error(error as Error, 'Failed to process audits');\n\t\t// Don't rethrow - audit failures shouldn't fail the request\n\t}\n}\n\n/**\n * Context for audit-aware handler execution.\n */\nexport interface AuditExecutionContext<\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\t/** The auditor instance for recording audits */\n\tauditor: Auditor<TAuditAction>;\n\t/** The audit storage instance */\n\tstorage: AuditStorage;\n}\n\n/**\n * Create audit context for handler execution.\n * Returns the auditor and storage for use in the handler.\n *\n * @param endpoint - The endpoint with audit configuration\n * @param serviceDiscovery - Service discovery for getting audit storage\n * @param logger - Logger for debug/error messages\n * @param ctx - Request context for actor extraction\n * @returns Audit context with auditor and storage, or undefined if not configured\n */\nexport async function createAuditContext<\n\tTServices extends Service[] = [],\n\tTSession = unknown,\n\tTLogger extends Logger = Logger,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n>(\n\tendpoint: Endpoint<\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tTServices,\n\t\tTLogger,\n\t\tTSession,\n\t\tTAuditStorage,\n\t\tTAuditStorageServiceName,\n\t\tTAuditAction,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t>,\n\tserviceDiscovery: ServiceDiscovery<any>,\n\tlogger: TLogger,\n\tctx: {\n\t\tsession: TSession;\n\t\theader: HeaderFn;\n\t\tcookie: CookieFn;\n\t\tservices: Record<string, unknown>;\n\t},\n): Promise<AuditExecutionContext<TAuditAction> | undefined> {\n\tif (!endpoint.auditorStorageService) {\n\t\treturn undefined;\n\t}\n\n\tconst services = await serviceDiscovery.register([\n\t\tendpoint.auditorStorageService,\n\t]);\n\tconst storage = services[\n\t\tendpoint.auditorStorageService.serviceName\n\t] as AuditStorage;\n\n\t// Extract actor if configured\n\tlet actor: AuditActor = { id: 'system', type: 'system' };\n\tif (endpoint.actorExtractor) {\n\t\ttry {\n\t\t\tactor = await (\n\t\t\t\tendpoint.actorExtractor as ActorExtractor<TServices, TSession, TLogger>\n\t\t\t)({\n\t\t\t\tservices: ctx.services as any,\n\t\t\t\tsession: ctx.session,\n\t\t\t\theader: ctx.header,\n\t\t\t\tcookie: ctx.cookie,\n\t\t\t\tlogger,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tlogger.error(error as Error, 'Failed to extract actor for audits');\n\t\t}\n\t}\n\n\tconst { DefaultAuditor } = await loadAudit();\n\tconst auditor = new DefaultAuditor<TAuditAction>({\n\t\tactor,\n\t\tstorage,\n\t\tmetadata: {\n\t\t\tendpoint: endpoint.route,\n\t\t\tmethod: endpoint.method,\n\t\t},\n\t});\n\n\treturn { auditor, storage };\n}\n\n/**\n * Options for executeWithAuditTransaction.\n */\nexport interface ExecuteWithAuditTransactionOptions {\n\t/**\n\t * Database connection to use for the transaction.\n\t * If this is already a transaction, it will be reused instead of creating a nested one.\n\t * If not provided, the storage's internal database is used.\n\t */\n\tdb?: unknown;\n}\n\n/**\n * Execute a handler with automatic audit transaction support.\n * If the audit storage provides a withTransaction method, wraps execution\n * in a transaction so audits are atomic with handler's database operations.\n *\n * This is database-agnostic - each storage implementation provides its own\n * transaction handling based on the underlying database (Kysely, Drizzle, etc.).\n *\n * If the db parameter is provided and is already a transaction, the storage\n * will reuse it instead of creating a nested transaction (similar to\n * packages/db/src/kysely.ts#withTransaction).\n *\n * @param auditContext - The audit context from createAuditContext\n * @param handler - The handler function to execute (receives auditor)\n * @param onComplete - Called after handler with response, to process declarative audits\n * @param options - Optional configuration including database connection\n * @returns The handler result\n */\nexport async function executeWithAuditTransaction<\n\tT,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n>(\n\tauditContext: AuditExecutionContext<TAuditAction> | undefined,\n\thandler: (auditor?: Auditor<TAuditAction>) => Promise<T>,\n\tonComplete?: (response: T, auditor: Auditor<TAuditAction>) => Promise<void>,\n\toptions?: ExecuteWithAuditTransactionOptions,\n): Promise<T> {\n\t// No audit context - just run handler\n\tif (!auditContext) {\n\t\treturn handler(undefined);\n\t}\n\n\tconst { auditor, storage } = auditContext;\n\n\t// Check if storage provides a transaction wrapper\n\tif (storage.withTransaction) {\n\t\t// Wrap in transaction - audits are atomic with handler operations\n\t\t// The storage's withTransaction handles setTransaction and flush\n\t\t// Pass db so existing transactions are reused\n\t\treturn storage.withTransaction(\n\t\t\tauditor,\n\t\t\tasync () => {\n\t\t\t\tconst response = await handler(auditor);\n\n\t\t\t\t// Process declarative audits within the transaction\n\t\t\t\tif (onComplete) {\n\t\t\t\t\tawait onComplete(response, auditor);\n\t\t\t\t}\n\n\t\t\t\treturn response;\n\t\t\t},\n\t\t\toptions?.db,\n\t\t);\n\t}\n\n\t// No transaction support - run handler and flush audits after\n\tconst response = await handler(auditor);\n\n\tif (onComplete) {\n\t\tawait onComplete(response, auditor);\n\t}\n\n\t// Flush audits (no transaction)\n\tawait auditor.flush();\n\n\treturn response;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,IAAa,sBAAb,cAAyC,MAAM;CAEpC;CACA;CAFV,YACC,aACA,SACA,OACC;EACD,MACC,GAAG,QAAQ,UAAU,YAAY,iGAEjC,EAAE,MAAM,CACT;EARS,KAAA,cAAA;EACA,KAAA,UAAA;EAQT,KAAK,OAAO;CACb;AACD;;AAGA,eAAsB,YAAwD;CAC7E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,oBACA,+BACA,KACD;CACD;AACD;;AAGA,eAAsB,gBAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,yBACA,iCACA,KACD;CACD;AACD;;AAGA,eAAsB,UAAuD;CAC5E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,iBACA,uCACA,KACD;CACD;AACD;;;;;;;;;;;;;ACwIA,eAAsB,mBAarB,UAcA,kBACA,QACA,KAM2D;CAC3D,IAAI,CAAC,SAAS,uBACb;CAMD,MAAM,WAAU,MAHO,iBAAiB,SAAS,CAChD,SAAS,qBACV,CAAC,EAAA,CAEA,SAAS,sBAAsB;CAIhC,IAAI,QAAoB;EAAE,IAAI;EAAU,MAAM;CAAS;CACvD,IAAI,SAAS,gBACZ,IAAI;EACH,QAAQ,MACP,SAAS,eACR;GACD,UAAU,IAAI;GACd,SAAS,IAAI;GACb,QAAQ,IAAI;GACZ,QAAQ,IAAI;GACZ;EACD,CAAC;CACF,SAAS,OAAO;EACf,OAAO,MAAM,OAAgB,oCAAoC;CAClE;CAGD,MAAM,EAAE,mBAAmB,MAAM,UAAU;CAU3C,OAAO;EAAE,SAAA,IATW,eAA6B;GAChD;GACA;GACA,UAAU;IACT,UAAU,SAAS;IACnB,QAAQ,SAAS;GAClB;EACD,CAEe;EAAG;CAAQ;AAC3B;;;;;;;;;;;;;;;;;;;AAgCA,eAAsB,4BAOrB,cACA,SACA,YACA,SACa;CAEb,IAAI,CAAC,cACJ,OAAO,QAAQ,KAAA,CAAS;CAGzB,MAAM,EAAE,SAAS,YAAY;CAG7B,IAAI,QAAQ,iBAIX,OAAO,QAAQ,gBACd,SACA,YAAY;EACX,MAAM,WAAW,MAAM,QAAQ,OAAO;EAGtC,IAAI,YACH,MAAM,WAAW,UAAU,OAAO;EAGnC,OAAO;CACR,GACA,SAAS,EACV;CAID,MAAM,WAAW,MAAM,QAAQ,OAAO;CAEtC,IAAI,YACH,MAAM,WAAW,UAAU,OAAO;CAInC,MAAM,QAAQ,MAAM;CAEpB,OAAO;AACR"}
@@ -1,189 +1,6 @@
1
- const require_chunk = require('../chunk-DWy1uDak.cjs');
2
- const require_construct_interface = require('../construct-interface-BfjcOD_E.cjs');
3
- const require_Construct = require('../Construct-CyS3RpTL.cjs');
4
- const require_clone = require('../clone-Dy0cR2SZ.cjs');
5
- const __geekmidas_manifest = require_chunk.__toESM(require("@geekmidas/manifest"));
6
- const __geekmidas_logger_console = require_chunk.__toESM(require("@geekmidas/logger/console"));
7
- const __geekmidas_events = require_chunk.__toESM(require("@geekmidas/events"));
8
-
9
- //#region src/queue/Queue.ts
10
- /**
11
- * A queue worker — a point-to-point SQS-style queue and its single consumer.
12
- * Unlike a `Subscriber` (topic fan-out, filtered by `subscribedEvents`), a queue
13
- * drains every message of its one `message` type. Build one with `q` (see
14
- * `QueueBuilder`); `gkm build` discovers it into the manifest's `queues` field.
15
- *
16
- * The producer side is {@link Queue.publisher} — a ready-to-inject `Service`
17
- * that any endpoint/function drops into `.services([...])` to send messages.
18
- */
19
- var Queue = class extends require_Construct.Construct {
20
- __IS_QUEUE__ = true;
21
- static isQueue(obj) {
22
- return Boolean(obj && obj.__IS_QUEUE__ === true && obj.type === require_Construct.ConstructType.Queue);
23
- }
24
- /**
25
- * The canonical id this queue is declared under.
26
- *
27
- * Derived from the name rather than given separately, so `emails` and
28
- * `Emails` are one queue. The name stays what it was: it is the wire `type`
29
- * a producer sends and the worker subscribes to, and changing that would
30
- * silently orphan in-flight messages.
31
- */
32
- id;
33
- /**
34
- * The producer's env key. Read by both {@link declare} and
35
- * {@link publisher}, so what the target publishes and what the producer
36
- * looks up cannot drift.
37
- */
38
- connectionKey;
39
- constructor(name, handler, messageSchema, timeout = 3e4, services = [], logger = __geekmidas_logger_console.DEFAULT_LOGGER, batchSize, fifo, constructs = []) {
40
- super(require_Construct.ConstructType.Queue, logger, services, [], void 0, void 0, timeout, void 0, void 0, constructs);
41
- this.name = name;
42
- this.handler = handler;
43
- this.messageSchema = messageSchema;
44
- this.timeout = timeout;
45
- this.services = services;
46
- this.logger = logger;
47
- this.batchSize = batchSize;
48
- this.fifo = fifo;
49
- this.id = (0, __geekmidas_manifest.canonicalId)(name);
50
- this.connectionKey = (0, __geekmidas_manifest.provideKey)(this.id, "publisherConnectionString");
51
- }
52
- /**
53
- * What this queue is in the manifest.
54
- *
55
- * A queue is a resource, not a handler: the worker is reached *through* it,
56
- * so the declaration carries the producer's key and nothing about the code
57
- * that drains it. The local target reads this to know which broker has to be
58
- * running and what connection string to inject.
59
- */
60
- declare() {
61
- return [{
62
- kind: "queue",
63
- id: this.id,
64
- provides: [this.connectionKey],
65
- ...this.fifo ? { fifo: true } : {},
66
- worker: {
67
- id: `${this.id}Worker`,
68
- handler: `${this.id}.handler`,
69
- dependencies: []
70
- }
71
- }];
72
- }
73
- /**
74
- * The producer side — a `Service` exposing an `EventPublisher` typed to this
75
- * queue's message. Inject it via `.services([queue.publisher])`; the handler
76
- * then calls `services.<name>Publisher.publish([{ type, payload }])`.
77
- *
78
- * It reads `<NAME>_PUBLISHER_CONNECTION_STRING` and builds the transport from
79
- * the URL protocol — `pgboss://` locally, `sqs://` deployed — so the same
80
- * code publishes to Postgres in dev and SQS in prod. Because it's a `Service`,
81
- * `Construct.getEnvironment()` sniffs it, so the env requirement flows into
82
- * the manifest and infra links exactly this queue with least privilege.
83
- */
84
- /**
85
- * The queue as a dependency — what `.dependsOn([emailsQueue])` dissolves
86
- * into, reachable as `services.emails`.
87
- *
88
- * It is the producer: a consumer is the worker written right here, so the
89
- * only thing another construct can want from a queue is the ability to send
90
- * to it. {@link publisher} is the same service under its older
91
- * `<name>Publisher` key, kept for `.services([queue.publisher])`.
92
- */
93
- get service() {
94
- const { register } = this.publisher;
95
- return {
96
- serviceName: (0, __geekmidas_manifest.serviceKey)(this.id),
97
- register
98
- };
99
- }
100
- get publisher() {
101
- const envVar = this.connectionKey;
102
- return {
103
- serviceName: `${this.name}Publisher`,
104
- async register({ envParser }) {
105
- const { connectionString } = envParser.create((get) => ({ connectionString: get(envVar).string() })).parse();
106
- return __geekmidas_events.Publisher.fromConnectionString(connectionString);
107
- }
108
- };
109
- }
110
- };
111
-
112
- //#endregion
113
- //#region src/queue/QueueBuilder.ts
114
- /**
115
- * Builds a {@link Queue} worker — `q.queue('orders').services([db]).message(schema).handle(fn)`.
116
- * Services are an array (sniffed for required env vars); `message` is the typed
117
- * job payload; `handle` is the single consumer. The queue name is captured as a
118
- * literal so `queue.publisher` is typed to `{ type: '<name>', payload }`.
119
- */
120
- var QueueBuilder = class {
121
- _name;
122
- _messageSchema;
123
- _timeout = 3e4;
124
- _batchSize;
125
- _fifo;
126
- _services = [];
127
- /** The construct ids `.dependsOn()` named — what the manifest records. */
128
- _constructs = [];
129
- _logger = __geekmidas_logger_console.DEFAULT_LOGGER;
130
- /** The queue name — drives the infra queue and its `<NAME>_*` env vars. */
131
- queue(name) {
132
- return require_clone.cloneWith(this, { _name: name });
133
- }
134
- timeout(timeout) {
135
- return require_clone.cloneWith(this, { _timeout: timeout });
136
- }
137
- /** SQS event-source batch size (deployed). */
138
- batchSize(batchSize) {
139
- return require_clone.cloneWith(this, { _batchSize: batchSize });
140
- }
141
- /** Mark the queue as FIFO (deployed). */
142
- fifo(fifo = true) {
143
- return require_clone.cloneWith(this, { _fifo: fifo });
144
- }
145
- /**
146
- * Depend on constructs — a database, a bucket, a mail sender, a queue, a
147
- * topic.
148
- *
149
- * It records the edge and dissolves each construct's client into the
150
- * handler's service record under the construct's own id, so
151
- * `.dependsOn([uploads])` is what makes `services.uploads` exist and type.
152
- *
153
- * Constructs only. A `Service` does not match the shape, which is what keeps
154
- * env sniffing confined to `.services()` and the explicit lift.
155
- */
156
- dependsOn(constructs) {
157
- const services = require_construct_interface.servicesOf(constructs);
158
- return require_clone.cloneWith(this, {
159
- _services: [...this._services, ...services],
160
- _constructs: require_construct_interface.idsOf(constructs, this._constructs)
161
- });
162
- }
163
- services(services) {
164
- return require_clone.cloneWith(this, { _services: [...this._services, ...services] });
165
- }
166
- logger(logger) {
167
- return require_clone.cloneWith(this, { _logger: logger });
168
- }
169
- /** The typed message (job) payload the queue carries. */
170
- message(schema) {
171
- return require_clone.cloneWith(this, { _messageSchema: schema });
172
- }
173
- handle(fn) {
174
- if (!this._name) throw new Error("Queue requires a name — call .queue(name) before .handle().");
175
- if (!this._messageSchema) throw new Error("Queue requires a message schema — call .message(schema) before .handle().");
176
- const queue = new Queue(this._name, fn, this._messageSchema, this._timeout, this._services, this._logger, this._batchSize, this._fifo, this._constructs);
177
- return queue;
178
- }
179
- };
180
-
181
- //#endregion
182
- //#region src/queue/index.ts
183
- const q = new QueueBuilder();
184
-
185
- //#endregion
186
- exports.Queue = Queue;
187
- exports.QueueBuilder = QueueBuilder;
188
- exports.q = q;
189
- //# sourceMappingURL=index.cjs.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_Queue = require("../Queue-A3wfD0it.cjs");
3
+ const require_QueueBuilder = require("../QueueBuilder-BjuF0UBl.cjs");
4
+ exports.Queue = require_Queue.Queue;
5
+ exports.QueueNeedsMessage = require_QueueBuilder.QueueNeedsMessage;
6
+ exports.QueueNeedsName = require_QueueBuilder.QueueNeedsName;
@@ -1,60 +1,3 @@
1
- import "../Construct-C0ijr2qp.cjs";
2
- import { Consumable, ServicesOf } from "../construct-interface-D9d4Gm4p.cjs";
3
- import { Queue, QueueContext, QueueHandler, QueueMessage } from "../Queue-D7ZuwBhy.cjs";
4
- import * as _geekmidas_logger24 from "@geekmidas/logger";
5
- import { Logger } from "@geekmidas/logger";
6
- import { Service } from "@geekmidas/services";
7
- import { StandardSchemaV1 } from "@standard-schema/spec";
8
-
9
- //#region src/queue/QueueBuilder.d.ts
10
-
11
- /**
12
- * Builds a {@link Queue} worker — `q.queue('orders').services([db]).message(schema).handle(fn)`.
13
- * Services are an array (sniffed for required env vars); `message` is the typed
14
- * job payload; `handle` is the single consumer. The queue name is captured as a
15
- * literal so `queue.publisher` is typed to `{ type: '<name>', payload }`.
16
- */
17
- declare class QueueBuilder<TName extends string = string, TMessage extends StandardSchemaV1 | undefined = undefined, TServices extends Service[] = [], TLogger extends Logger = Logger> {
18
- private _name?;
19
- private _messageSchema?;
20
- private _timeout;
21
- private _batchSize?;
22
- private _fifo?;
23
- private _services;
24
- /** The construct ids `.dependsOn()` named — what the manifest records. */
25
- _constructs: string[];
26
- private _logger;
27
- /** The queue name — drives the infra queue and its `<NAME>_*` env vars. */
28
- queue<T extends string>(name: T): QueueBuilder<T, TMessage, TServices, TLogger>;
29
- timeout(timeout: number): this;
30
- /** SQS event-source batch size (deployed). */
31
- batchSize(batchSize: number): this;
32
- /** Mark the queue as FIFO (deployed). */
33
- fifo(fifo?: boolean): this;
34
- /**
35
- * Depend on constructs — a database, a bucket, a mail sender, a queue, a
36
- * topic.
37
- *
38
- * It records the edge and dissolves each construct's client into the
39
- * handler's service record under the construct's own id, so
40
- * `.dependsOn([uploads])` is what makes `services.uploads` exist and type.
41
- *
42
- * Constructs only. A `Service` does not match the shape, which is what keeps
43
- * env sniffing confined to `.services()` and the explicit lift.
44
- */
45
- dependsOn<const T extends readonly Consumable[]>(constructs: T): QueueBuilder<TName, TMessage, [...TServices, ...ServicesOf<T>], TLogger>;
46
- services<T extends Service[]>(services: T): QueueBuilder<TName, TMessage, [...TServices, ...T], TLogger>;
47
- logger<T extends Logger>(logger: T): QueueBuilder<TName, TMessage, TServices, T>;
48
- /** The typed message (job) payload the queue carries. */
49
- message<T extends StandardSchemaV1>(schema: T): QueueBuilder<TName, T, TServices, TLogger>;
50
- handle(fn: QueueHandler<NonNullable<TMessage>, TServices, TLogger>): Queue<TName, NonNullable<TMessage>, TServices, TLogger>;
51
- }
52
- //# sourceMappingURL=QueueBuilder.d.ts.map
53
- //#endregion
54
- //#region src/queue/index.d.ts
55
- declare const q: QueueBuilder<string, undefined, [], _geekmidas_logger24.Logger>;
56
- //# sourceMappingURL=index.d.ts.map
57
-
58
- //#endregion
59
- export { Queue, QueueBuilder, QueueContext, QueueHandler, QueueMessage, q };
60
- //# sourceMappingURL=index.d.cts.map
1
+ import { i as QueueMessage, n as QueueContext, r as QueueHandler, t as Queue } from "../Queue-HPyi0e1i.cjs";
2
+ import { n as QueueNeedsMessage, r as QueueNeedsName } from "../QueueBuilder-OSi6LkV9.cjs";
3
+ export { Queue, type QueueContext, type QueueHandler, type QueueMessage, QueueNeedsMessage, QueueNeedsName };