@geekmidas/constructs 10.0.0-alpha.15 → 10.0.0-alpha.150

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 (454) hide show
  1. package/README.md +222 -158
  2. package/dist/Construct-127M7yrl.d.cts +231 -0
  3. package/dist/Construct-127M7yrl.d.cts.map +1 -0
  4. package/dist/{Construct-BeYVu_QF.mjs → Construct-CGuc_Ijk.mjs} +8 -9
  5. package/dist/Construct-CGuc_Ijk.mjs.map +1 -0
  6. package/dist/{Construct-DqdlARxq.cjs → Construct-DorKS0Ua.cjs} +8 -9
  7. package/dist/Construct-DorKS0Ua.cjs.map +1 -0
  8. package/dist/Construct-DySlwh8o.d.mts +231 -0
  9. package/dist/Construct-DySlwh8o.d.mts.map +1 -0
  10. package/dist/{Cron-DKqnnTdH.d.cts → Cron-D8mB_cPX.d.mts} +16 -9
  11. package/dist/Cron-D8mB_cPX.d.mts.map +1 -0
  12. package/dist/{Cron-SyqS5oWJ.d.mts → Cron-D_sfaMGz.d.cts} +16 -9
  13. package/dist/Cron-D_sfaMGz.d.cts.map +1 -0
  14. package/dist/{CronBuilder-D_0HNBTr.mjs → CronBuilder-BJ5LoadF.mjs} +28 -11
  15. package/dist/CronBuilder-BJ5LoadF.mjs.map +1 -0
  16. package/dist/{CronBuilder-BdnI6lxF.cjs → CronBuilder-B_NSP-Y5.cjs} +27 -10
  17. package/dist/CronBuilder-B_NSP-Y5.cjs.map +1 -0
  18. package/dist/CronBuilder-C91MVLSr.d.cts +47 -0
  19. package/dist/CronBuilder-C91MVLSr.d.cts.map +1 -0
  20. package/dist/CronBuilder-Cmajva3g.d.mts +47 -0
  21. package/dist/CronBuilder-Cmajva3g.d.mts.map +1 -0
  22. package/dist/Endpoint-52z1P0Ue.cjs +581 -0
  23. package/dist/Endpoint-52z1P0Ue.cjs.map +1 -0
  24. package/dist/{Endpoint-DuT4TEEq.d.mts → Endpoint-BbHh3Qoc.d.mts} +124 -43
  25. package/dist/Endpoint-BbHh3Qoc.d.mts.map +1 -0
  26. package/dist/{Endpoint-C6yyHpRS.d.cts → Endpoint-YYwjqtS1.d.cts} +122 -41
  27. package/dist/Endpoint-YYwjqtS1.d.cts.map +1 -0
  28. package/dist/Endpoint-sUOU7uLx.mjs +552 -0
  29. package/dist/Endpoint-sUOU7uLx.mjs.map +1 -0
  30. package/dist/{EndpointFactory-Bm3aKRdV.mjs → EndpointFactory-Bzi9Sl7r.mjs} +269 -53
  31. package/dist/EndpointFactory-Bzi9Sl7r.mjs.map +1 -0
  32. package/dist/{EndpointFactory-CLvWuHyt.cjs → EndpointFactory-Cf_Cs1ym.cjs} +309 -51
  33. package/dist/EndpointFactory-Cf_Cs1ym.cjs.map +1 -0
  34. package/dist/{index-BPSZ_Lp_.d.cts → EndpointFactory-Hh1r6J_C.d.cts} +187 -104
  35. package/dist/EndpointFactory-Hh1r6J_C.d.cts.map +1 -0
  36. package/dist/{index-BoZ-iisU.d.mts → EndpointFactory-qcLzi4f-.d.mts} +188 -105
  37. package/dist/EndpointFactory-qcLzi4f-.d.mts.map +1 -0
  38. package/dist/Function-BIEsY0Hm.d.cts +76 -0
  39. package/dist/Function-BIEsY0Hm.d.cts.map +1 -0
  40. package/dist/Function-DfMzTGS4.d.mts +76 -0
  41. package/dist/Function-DfMzTGS4.d.mts.map +1 -0
  42. package/dist/{HonoEndpointAdaptor-92zavCsV.cjs → HonoEndpointAdaptor-BXBdb2Bt.cjs} +79 -31
  43. package/dist/HonoEndpointAdaptor-BXBdb2Bt.cjs.map +1 -0
  44. package/dist/{HonoEndpointAdaptor-yYaU7jVJ.mjs → HonoEndpointAdaptor-DR3j7S35.mjs} +76 -28
  45. package/dist/HonoEndpointAdaptor-DR3j7S35.mjs.map +1 -0
  46. package/dist/ObjectSubscriberBuilder-Cv8C7yS1.d.mts +129 -0
  47. package/dist/ObjectSubscriberBuilder-Cv8C7yS1.d.mts.map +1 -0
  48. package/dist/ObjectSubscriberBuilder-LWkey_oq.d.cts +129 -0
  49. package/dist/ObjectSubscriberBuilder-LWkey_oq.d.cts.map +1 -0
  50. package/dist/ProcessorBuilder-CwfP-M33.d.mts +216 -0
  51. package/dist/ProcessorBuilder-CwfP-M33.d.mts.map +1 -0
  52. package/dist/ProcessorBuilder-_jdZlbfW.d.cts +216 -0
  53. package/dist/ProcessorBuilder-_jdZlbfW.d.cts.map +1 -0
  54. package/dist/{Queue-D9X6OoON.d.mts → Queue-BnK3UH8r.d.mts} +42 -41
  55. package/dist/Queue-BnK3UH8r.d.mts.map +1 -0
  56. package/dist/{Queue-DYPB2KWL.d.cts → Queue-C4rijiM7.d.cts} +43 -42
  57. package/dist/Queue-C4rijiM7.d.cts.map +1 -0
  58. package/dist/Queue-D4Iaidrs.cjs +109 -0
  59. package/dist/Queue-D4Iaidrs.cjs.map +1 -0
  60. package/dist/Queue-u8w8_HpE.mjs +104 -0
  61. package/dist/Queue-u8w8_HpE.mjs.map +1 -0
  62. package/dist/QueueBuilder-2wP5lEC8.mjs +118 -0
  63. package/dist/QueueBuilder-2wP5lEC8.mjs.map +1 -0
  64. package/dist/QueueBuilder-BxsZ9o5z.cjs +135 -0
  65. package/dist/QueueBuilder-BxsZ9o5z.cjs.map +1 -0
  66. package/dist/QueueBuilder-DmwFtLzQ.d.mts +75 -0
  67. package/dist/QueueBuilder-DmwFtLzQ.d.mts.map +1 -0
  68. package/dist/QueueBuilder-SQli59An.d.cts +75 -0
  69. package/dist/QueueBuilder-SQli59An.d.cts.map +1 -0
  70. package/dist/Subscriber-5rCX1Nph.d.cts +83 -0
  71. package/dist/Subscriber-5rCX1Nph.d.cts.map +1 -0
  72. package/dist/Subscriber-CW_Dl-YR.d.mts +83 -0
  73. package/dist/Subscriber-CW_Dl-YR.d.mts.map +1 -0
  74. package/dist/SubscriberBuilder-BL_GTcwh.mjs +237 -0
  75. package/dist/SubscriberBuilder-BL_GTcwh.mjs.map +1 -0
  76. package/dist/SubscriberBuilder-CWzKwX1p.cjs +260 -0
  77. package/dist/SubscriberBuilder-CWzKwX1p.cjs.map +1 -0
  78. package/dist/Topic-DN2gYJ-p.mjs +99 -0
  79. package/dist/Topic-DN2gYJ-p.mjs.map +1 -0
  80. package/dist/Topic-Dp9Q7Lj2.cjs +104 -0
  81. package/dist/Topic-Dp9Q7Lj2.cjs.map +1 -0
  82. package/dist/adaptors/aws.cjs +134 -160
  83. package/dist/adaptors/aws.cjs.map +1 -1
  84. package/dist/adaptors/aws.d.cts +57 -48
  85. package/dist/adaptors/aws.d.cts.map +1 -1
  86. package/dist/adaptors/aws.d.mts +58 -49
  87. package/dist/adaptors/aws.d.mts.map +1 -1
  88. package/dist/adaptors/aws.mjs +130 -157
  89. package/dist/adaptors/aws.mjs.map +1 -1
  90. package/dist/adaptors/hono.cjs +1 -1
  91. package/dist/adaptors/hono.d.cts +5 -6
  92. package/dist/adaptors/hono.d.cts.map +1 -1
  93. package/dist/adaptors/hono.d.mts +6 -7
  94. package/dist/adaptors/hono.d.mts.map +1 -1
  95. package/dist/adaptors/hono.mjs +1 -1
  96. package/dist/adaptors/testing.cjs +955 -38
  97. package/dist/adaptors/testing.cjs.map +1 -1
  98. package/dist/adaptors/testing.d.cts +437 -39
  99. package/dist/adaptors/testing.d.cts.map +1 -1
  100. package/dist/adaptors/testing.d.mts +436 -38
  101. package/dist/adaptors/testing.d.mts.map +1 -1
  102. package/dist/adaptors/testing.mjs +929 -34
  103. package/dist/adaptors/testing.mjs.map +1 -1
  104. package/dist/auth-BqWz2JxC.d.cts +274 -0
  105. package/dist/auth-BqWz2JxC.d.cts.map +1 -0
  106. package/dist/auth-DnB9H9KL.d.mts +274 -0
  107. package/dist/auth-DnB9H9KL.d.mts.map +1 -0
  108. package/dist/auth.cjs +320 -21
  109. package/dist/auth.cjs.map +1 -1
  110. package/dist/auth.d.cts +2 -104
  111. package/dist/auth.d.mts +2 -104
  112. package/dist/auth.mjs +316 -23
  113. package/dist/auth.mjs.map +1 -1
  114. package/dist/cache-CQjMNPrC.d.cts +44 -0
  115. package/dist/cache-CQjMNPrC.d.cts.map +1 -0
  116. package/dist/cache-e3tfMQ9g.d.mts +44 -0
  117. package/dist/cache-e3tfMQ9g.d.mts.map +1 -0
  118. package/dist/cache.d.cts +2 -43
  119. package/dist/cache.d.mts +2 -43
  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/cipher-DSDxPRIp.d.cts +106 -0
  125. package/dist/cipher-DSDxPRIp.d.cts.map +1 -0
  126. package/dist/cipher-DSDxPRIp.d.mts +106 -0
  127. package/dist/cipher-DSDxPRIp.d.mts.map +1 -0
  128. package/dist/{construct-interface-DPlxfpoS.d.mts → construct-interface-CSA9VeWM.d.mts} +47 -8
  129. package/dist/construct-interface-CSA9VeWM.d.mts.map +1 -0
  130. package/dist/{construct-interface-DgXTJcOD.d.cts → construct-interface-DugP0E5q.d.cts} +47 -8
  131. package/dist/construct-interface-DugP0E5q.d.cts.map +1 -0
  132. package/dist/construct-interface.cjs +38 -4
  133. package/dist/construct-interface.cjs.map +1 -1
  134. package/dist/construct-interface.d.cts +2 -2
  135. package/dist/construct-interface.d.mts +2 -2
  136. package/dist/construct-interface.mjs +37 -5
  137. package/dist/construct-interface.mjs.map +1 -1
  138. package/dist/credential-DYymbp_7.cjs +257 -0
  139. package/dist/credential-DYymbp_7.cjs.map +1 -0
  140. package/dist/credential-DfSAOOdY.mjs +222 -0
  141. package/dist/credential-DfSAOOdY.mjs.map +1 -0
  142. package/dist/credential.cjs +7 -129
  143. package/dist/credential.d.cts +2 -58
  144. package/dist/credential.d.mts +2 -58
  145. package/dist/credential.mjs +2 -128
  146. package/dist/crons/index.cjs +126 -1
  147. package/dist/crons/index.cjs.map +1 -1
  148. package/dist/crons/index.d.cts +43 -3
  149. package/dist/crons/index.d.cts.map +1 -1
  150. package/dist/crons/index.d.mts +43 -3
  151. package/dist/crons/index.d.mts.map +1 -1
  152. package/dist/crons/index.mjs +125 -2
  153. package/dist/crons/index.mjs.map +1 -1
  154. package/dist/database/kysely.cjs +3 -194
  155. package/dist/database/kysely.d.cts +2 -149
  156. package/dist/database/kysely.d.mts +2 -149
  157. package/dist/database/kysely.mjs +2 -192
  158. package/dist/email.d.cts +1 -1
  159. package/dist/email.d.cts.map +1 -1
  160. package/dist/email.d.mts +2 -2
  161. package/dist/email.d.mts.map +1 -1
  162. package/dist/encryption/kms.cjs +95 -0
  163. package/dist/encryption/kms.cjs.map +1 -0
  164. package/dist/encryption/kms.d.cts +7 -0
  165. package/dist/encryption/kms.d.cts.map +1 -0
  166. package/dist/encryption/kms.d.mts +7 -0
  167. package/dist/encryption/kms.d.mts.map +1 -0
  168. package/dist/encryption/kms.mjs +93 -0
  169. package/dist/encryption/kms.mjs.map +1 -0
  170. package/dist/encryption.cjs +116 -0
  171. package/dist/encryption.cjs.map +1 -0
  172. package/dist/encryption.d.cts +37 -0
  173. package/dist/encryption.d.cts.map +1 -0
  174. package/dist/encryption.d.mts +37 -0
  175. package/dist/encryption.d.mts.map +1 -0
  176. package/dist/encryption.mjs +101 -0
  177. package/dist/encryption.mjs.map +1 -0
  178. package/dist/endpoints/index.cjs +32 -10
  179. package/dist/endpoints/index.d.cts +106 -3
  180. package/dist/endpoints/index.d.cts.map +1 -0
  181. package/dist/endpoints/index.d.mts +106 -3
  182. package/dist/endpoints/index.d.mts.map +1 -0
  183. package/dist/endpoints/index.mjs +6 -4
  184. package/dist/expire-C586zznE.d.cts +38 -0
  185. package/dist/expire-C586zznE.d.cts.map +1 -0
  186. package/dist/expire-C586zznE.d.mts +38 -0
  187. package/dist/expire-C586zznE.d.mts.map +1 -0
  188. package/dist/expire-CieftS01.cjs +67 -0
  189. package/dist/expire-CieftS01.cjs.map +1 -0
  190. package/dist/expire-CpzUAfr9.mjs +50 -0
  191. package/dist/expire-CpzUAfr9.mjs.map +1 -0
  192. package/dist/external-api.cjs +106 -0
  193. package/dist/external-api.cjs.map +1 -0
  194. package/dist/external-api.d.cts +2 -0
  195. package/dist/external-api.d.mts +2 -0
  196. package/dist/external-api.mjs +103 -0
  197. package/dist/external-api.mjs.map +1 -0
  198. package/dist/fake-BqhP8RRQ.d.mts +201 -0
  199. package/dist/fake-BqhP8RRQ.d.mts.map +1 -0
  200. package/dist/fake-DqieDYYA.d.cts +201 -0
  201. package/dist/fake-DqieDYYA.d.cts.map +1 -0
  202. package/dist/file-server.cjs +123 -30
  203. package/dist/file-server.cjs.map +1 -1
  204. package/dist/file-server.d.cts +115 -1
  205. package/dist/file-server.d.cts.map +1 -1
  206. package/dist/file-server.d.mts +115 -1
  207. package/dist/file-server.d.mts.map +1 -1
  208. package/dist/file-server.mjs +122 -32
  209. package/dist/file-server.mjs.map +1 -1
  210. package/dist/functions/index.cjs +1 -1
  211. package/dist/functions/index.d.cts +2 -1
  212. package/dist/functions/index.d.mts +2 -1
  213. package/dist/functions/index.mjs +1 -1
  214. package/dist/{functions-C53GW2eQ.mjs → functions-BvIDQKAA.mjs} +117 -22
  215. package/dist/functions-BvIDQKAA.mjs.map +1 -0
  216. package/dist/{functions-B6qCvfmy.cjs → functions-DLF6-IK8.cjs} +122 -18
  217. package/dist/functions-DLF6-IK8.cjs.map +1 -0
  218. package/dist/inbox-CR3L1fOI.d.cts +195 -0
  219. package/dist/inbox-CR3L1fOI.d.cts.map +1 -0
  220. package/dist/inbox-CjxpLVkH.d.mts +195 -0
  221. package/dist/inbox-CjxpLVkH.d.mts.map +1 -0
  222. package/dist/inbox.cjs +291 -0
  223. package/dist/inbox.cjs.map +1 -0
  224. package/dist/inbox.d.cts +2 -0
  225. package/dist/inbox.d.mts +2 -0
  226. package/dist/inbox.mjs +283 -0
  227. package/dist/inbox.mjs.map +1 -0
  228. package/dist/index-DCkDQkwj.d.mts +115 -0
  229. package/dist/index-DCkDQkwj.d.mts.map +1 -0
  230. package/dist/index-DPTHa6Ud.d.cts +115 -0
  231. package/dist/index-DPTHa6Ud.d.cts.map +1 -0
  232. package/dist/{index-CeEtxDmK.d.cts → index-DdRjYhiJ.d.cts} +42 -2
  233. package/dist/{index-CeEtxDmK.d.cts.map → index-DdRjYhiJ.d.cts.map} +1 -1
  234. package/dist/{index-CeEtxDmK.d.mts → index-DdRjYhiJ.d.mts} +42 -2
  235. package/dist/{index-CeEtxDmK.d.mts.map → index-DdRjYhiJ.d.mts.map} +1 -1
  236. package/dist/index.cjs +4 -1
  237. package/dist/index.d.cts +26 -3
  238. package/dist/index.d.cts.map +1 -0
  239. package/dist/index.d.mts +26 -3
  240. package/dist/index.d.mts.map +1 -0
  241. package/dist/index.mjs +3 -2
  242. package/dist/kysely-CebjCWTl.d.cts +216 -0
  243. package/dist/kysely-CebjCWTl.d.cts.map +1 -0
  244. package/dist/kysely-Cs4uPO8k.mjs +371 -0
  245. package/dist/kysely-Cs4uPO8k.mjs.map +1 -0
  246. package/dist/kysely-CukArHJ0.cjs +384 -0
  247. package/dist/kysely-CukArHJ0.cjs.map +1 -0
  248. package/dist/kysely-DE4kADWD.d.mts +216 -0
  249. package/dist/kysely-DE4kADWD.d.mts.map +1 -0
  250. package/dist/{telemetry-DGcFlVpB.d.cts → lambdaTelemetry-8vnmVZQ5.d.cts} +2 -2
  251. package/dist/lambdaTelemetry-8vnmVZQ5.d.cts.map +1 -0
  252. package/dist/{telemetry-DGcFlVpB.d.mts → lambdaTelemetry-8vnmVZQ5.d.mts} +2 -2
  253. package/dist/lambdaTelemetry-8vnmVZQ5.d.mts.map +1 -0
  254. package/dist/mobile-app.cjs +74 -0
  255. package/dist/mobile-app.cjs.map +1 -0
  256. package/dist/mobile-app.d.cts +73 -0
  257. package/dist/mobile-app.d.cts.map +1 -0
  258. package/dist/mobile-app.d.mts +73 -0
  259. package/dist/mobile-app.d.mts.map +1 -0
  260. package/dist/mobile-app.mjs +73 -0
  261. package/dist/mobile-app.mjs.map +1 -0
  262. package/dist/object-storage.cjs +8 -1
  263. package/dist/object-storage.cjs.map +1 -1
  264. package/dist/object-storage.d.cts +10 -1
  265. package/dist/object-storage.d.cts.map +1 -1
  266. package/dist/object-storage.d.mts +10 -1
  267. package/dist/object-storage.d.mts.map +1 -1
  268. package/dist/object-storage.mjs +7 -2
  269. package/dist/object-storage.mjs.map +1 -1
  270. package/dist/pattern-C1CEcglD.mjs +241 -0
  271. package/dist/pattern-C1CEcglD.mjs.map +1 -0
  272. package/dist/pattern-QFaUIr77.cjs +288 -0
  273. package/dist/pattern-QFaUIr77.cjs.map +1 -0
  274. package/dist/processors/index.cjs +214 -0
  275. package/dist/processors/index.cjs.map +1 -0
  276. package/dist/processors/index.d.cts +78 -0
  277. package/dist/processors/index.d.cts.map +1 -0
  278. package/dist/processors/index.d.mts +78 -0
  279. package/dist/processors/index.d.mts.map +1 -0
  280. package/dist/processors/index.mjs +193 -0
  281. package/dist/processors/index.mjs.map +1 -0
  282. package/dist/queue/index.cjs +5 -192
  283. package/dist/queue/index.d.cts +3 -53
  284. package/dist/queue/index.d.mts +3 -53
  285. package/dist/queue/index.mjs +3 -190
  286. package/dist/random-password.cjs +86 -0
  287. package/dist/random-password.cjs.map +1 -0
  288. package/dist/random-password.d.cts +30 -0
  289. package/dist/random-password.d.cts.map +1 -0
  290. package/dist/random-password.d.mts +30 -0
  291. package/dist/random-password.d.mts.map +1 -0
  292. package/dist/random-password.mjs +84 -0
  293. package/dist/random-password.mjs.map +1 -0
  294. package/dist/{lazyAccessors-BHtcqgz2.mjs → readRequestBody-BTIl3k-D.mjs} +99 -39
  295. package/dist/readRequestBody-BTIl3k-D.mjs.map +1 -0
  296. package/dist/{lazyAccessors-Dx9NLwJZ.cjs → readRequestBody-Dej_L3c4.cjs} +118 -46
  297. package/dist/readRequestBody-Dej_L3c4.cjs.map +1 -0
  298. package/dist/requestLogger-BZcXwdBs.cjs +207 -0
  299. package/dist/requestLogger-BZcXwdBs.cjs.map +1 -0
  300. package/dist/requestLogger-pA4gi3E1.mjs +178 -0
  301. package/dist/requestLogger-pA4gi3E1.mjs.map +1 -0
  302. package/dist/rest-api.cjs +85 -70
  303. package/dist/rest-api.cjs.map +1 -1
  304. package/dist/rest-api.d.cts +77 -59
  305. package/dist/rest-api.d.cts.map +1 -1
  306. package/dist/rest-api.d.mts +77 -59
  307. package/dist/rest-api.d.mts.map +1 -1
  308. package/dist/rest-api.mjs +87 -72
  309. package/dist/rest-api.mjs.map +1 -1
  310. package/dist/runSubscriber-CC_2C9F2.cjs +133 -0
  311. package/dist/runSubscriber-CC_2C9F2.cjs.map +1 -0
  312. package/dist/runSubscriber-DyHWp_Lf.mjs +116 -0
  313. package/dist/runSubscriber-DyHWp_Lf.mjs.map +1 -0
  314. package/dist/shutdown-BMJmAhSt.cjs +38 -0
  315. package/dist/shutdown-BMJmAhSt.cjs.map +1 -0
  316. package/dist/shutdown-C7xa8x9S.mjs +27 -0
  317. package/dist/shutdown-C7xa8x9S.mjs.map +1 -0
  318. package/dist/site.cjs +85 -8
  319. package/dist/site.cjs.map +1 -1
  320. package/dist/site.d.cts +98 -2
  321. package/dist/site.d.cts.map +1 -1
  322. package/dist/site.d.mts +98 -2
  323. package/dist/site.d.mts.map +1 -1
  324. package/dist/site.mjs +84 -11
  325. package/dist/site.mjs.map +1 -1
  326. package/dist/stages-DaTaoQei.d.cts +73 -0
  327. package/dist/stages-DaTaoQei.d.cts.map +1 -0
  328. package/dist/stages-DaTaoQei.d.mts +73 -0
  329. package/dist/stages-DaTaoQei.d.mts.map +1 -0
  330. package/dist/subscribers/index.cjs +134 -1
  331. package/dist/subscribers/index.cjs.map +1 -0
  332. package/dist/subscribers/index.d.cts +74 -3
  333. package/dist/subscribers/index.d.cts.map +1 -0
  334. package/dist/subscribers/index.d.mts +74 -3
  335. package/dist/subscribers/index.d.mts.map +1 -0
  336. package/dist/subscribers/index.mjs +132 -2
  337. package/dist/subscribers/index.mjs.map +1 -0
  338. package/dist/telemetry-C1oqncFY.d.cts +40 -0
  339. package/dist/telemetry-C1oqncFY.d.cts.map +1 -0
  340. package/dist/telemetry-CObow3Dn.d.mts +40 -0
  341. package/dist/telemetry-CObow3Dn.d.mts.map +1 -0
  342. package/dist/telemetry.cjs +56 -0
  343. package/dist/telemetry.cjs.map +1 -0
  344. package/dist/telemetry.d.cts +2 -0
  345. package/dist/telemetry.d.mts +2 -0
  346. package/dist/telemetry.mjs +55 -0
  347. package/dist/telemetry.mjs.map +1 -0
  348. package/dist/topic/index.cjs +2 -134
  349. package/dist/topic/index.d.cts +2 -3
  350. package/dist/topic/index.d.mts +2 -3
  351. package/dist/topic/index.mjs +2 -132
  352. package/dist/tracing-Bbj1uoFJ.mjs +127 -0
  353. package/dist/tracing-Bbj1uoFJ.mjs.map +1 -0
  354. package/dist/tracing-C0ooU0V2.cjs +150 -0
  355. package/dist/tracing-C0ooU0V2.cjs.map +1 -0
  356. package/dist/websocket-api.cjs +951 -0
  357. package/dist/websocket-api.cjs.map +1 -0
  358. package/dist/websocket-api.d.cts +556 -0
  359. package/dist/websocket-api.d.cts.map +1 -0
  360. package/dist/websocket-api.d.mts +556 -0
  361. package/dist/websocket-api.d.mts.map +1 -0
  362. package/dist/websocket-api.mjs +933 -0
  363. package/dist/websocket-api.mjs.map +1 -0
  364. package/dist/worker.cjs +174 -32
  365. package/dist/worker.cjs.map +1 -1
  366. package/dist/worker.d.cts +147 -47
  367. package/dist/worker.d.cts.map +1 -1
  368. package/dist/worker.d.mts +147 -47
  369. package/dist/worker.d.mts.map +1 -1
  370. package/dist/worker.mjs +175 -33
  371. package/dist/worker.mjs.map +1 -1
  372. package/package.json +155 -44
  373. package/dist/Construct-BeYVu_QF.mjs.map +0 -1
  374. package/dist/Construct-DfbwIntp.d.cts +0 -115
  375. package/dist/Construct-DfbwIntp.d.cts.map +0 -1
  376. package/dist/Construct-DqdlARxq.cjs.map +0 -1
  377. package/dist/Construct-l5aOn_jv.d.mts +0 -115
  378. package/dist/Construct-l5aOn_jv.d.mts.map +0 -1
  379. package/dist/Cron-DKqnnTdH.d.cts.map +0 -1
  380. package/dist/Cron-SyqS5oWJ.d.mts.map +0 -1
  381. package/dist/CronBuilder-BdnI6lxF.cjs.map +0 -1
  382. package/dist/CronBuilder-CRGnDfTq.d.mts +0 -41
  383. package/dist/CronBuilder-CRGnDfTq.d.mts.map +0 -1
  384. package/dist/CronBuilder-D_0HNBTr.mjs.map +0 -1
  385. package/dist/CronBuilder-Df1q9PNy.d.cts +0 -41
  386. package/dist/CronBuilder-Df1q9PNy.d.cts.map +0 -1
  387. package/dist/Endpoint-BpZHtJ2W.cjs +0 -1689
  388. package/dist/Endpoint-BpZHtJ2W.cjs.map +0 -1
  389. package/dist/Endpoint-C6yyHpRS.d.cts.map +0 -1
  390. package/dist/Endpoint-DuT4TEEq.d.mts.map +0 -1
  391. package/dist/Endpoint-ONsly_dq.mjs +0 -1671
  392. package/dist/Endpoint-ONsly_dq.mjs.map +0 -1
  393. package/dist/EndpointFactory-Bm3aKRdV.mjs.map +0 -1
  394. package/dist/EndpointFactory-CLvWuHyt.cjs.map +0 -1
  395. package/dist/HonoEndpointAdaptor-92zavCsV.cjs.map +0 -1
  396. package/dist/HonoEndpointAdaptor-yYaU7jVJ.mjs.map +0 -1
  397. package/dist/Queue-D9X6OoON.d.mts.map +0 -1
  398. package/dist/Queue-DYPB2KWL.d.cts.map +0 -1
  399. package/dist/Subscriber-C4heaAyO.d.mts +0 -51
  400. package/dist/Subscriber-C4heaAyO.d.mts.map +0 -1
  401. package/dist/Subscriber-CotDUELC.d.cts +0 -51
  402. package/dist/Subscriber-CotDUELC.d.cts.map +0 -1
  403. package/dist/SubscriberBuilder-BEv0eoHy.d.cts +0 -59
  404. package/dist/SubscriberBuilder-BEv0eoHy.d.cts.map +0 -1
  405. package/dist/SubscriberBuilder-C0ZEtGDI.cjs +0 -125
  406. package/dist/SubscriberBuilder-C0ZEtGDI.cjs.map +0 -1
  407. package/dist/SubscriberBuilder-h7B_cHMr.mjs +0 -114
  408. package/dist/SubscriberBuilder-h7B_cHMr.mjs.map +0 -1
  409. package/dist/SubscriberBuilder-tyH5yTk5.d.mts +0 -59
  410. package/dist/SubscriberBuilder-tyH5yTk5.d.mts.map +0 -1
  411. package/dist/Topic-DEVGo0Dm.d.cts +0 -89
  412. package/dist/Topic-DEVGo0Dm.d.cts.map +0 -1
  413. package/dist/Topic-zk_6Gthr.d.mts +0 -89
  414. package/dist/Topic-zk_6Gthr.d.mts.map +0 -1
  415. package/dist/auth.d.cts.map +0 -1
  416. package/dist/auth.d.mts.map +0 -1
  417. package/dist/cache.d.cts.map +0 -1
  418. package/dist/cache.d.mts.map +0 -1
  419. package/dist/construct-interface-DPlxfpoS.d.mts.map +0 -1
  420. package/dist/construct-interface-DgXTJcOD.d.cts.map +0 -1
  421. package/dist/credential.cjs.map +0 -1
  422. package/dist/credential.d.cts.map +0 -1
  423. package/dist/credential.d.mts.map +0 -1
  424. package/dist/credential.mjs.map +0 -1
  425. package/dist/database/kysely.cjs.map +0 -1
  426. package/dist/database/kysely.d.cts.map +0 -1
  427. package/dist/database/kysely.d.mts.map +0 -1
  428. package/dist/database/kysely.mjs.map +0 -1
  429. package/dist/functions-B6qCvfmy.cjs.map +0 -1
  430. package/dist/functions-C53GW2eQ.mjs.map +0 -1
  431. package/dist/index-B2urf3YI.d.cts +0 -26
  432. package/dist/index-B2urf3YI.d.cts.map +0 -1
  433. package/dist/index-BPSZ_Lp_.d.cts.map +0 -1
  434. package/dist/index-BoZ-iisU.d.mts.map +0 -1
  435. package/dist/index-CdaU--_B.d.cts +0 -165
  436. package/dist/index-CdaU--_B.d.cts.map +0 -1
  437. package/dist/index-DMCDvnsM.d.mts +0 -26
  438. package/dist/index-DMCDvnsM.d.mts.map +0 -1
  439. package/dist/index-PQRWOQj4.d.mts +0 -165
  440. package/dist/index-PQRWOQj4.d.mts.map +0 -1
  441. package/dist/lazyAccessors-BHtcqgz2.mjs.map +0 -1
  442. package/dist/lazyAccessors-Dx9NLwJZ.cjs.map +0 -1
  443. package/dist/processAudits-BpRlPQMW.mjs +0 -77
  444. package/dist/processAudits-BpRlPQMW.mjs.map +0 -1
  445. package/dist/processAudits-D_2W5x8k.cjs +0 -88
  446. package/dist/processAudits-D_2W5x8k.cjs.map +0 -1
  447. package/dist/queue/index.cjs.map +0 -1
  448. package/dist/queue/index.d.cts.map +0 -1
  449. package/dist/queue/index.d.mts.map +0 -1
  450. package/dist/queue/index.mjs.map +0 -1
  451. package/dist/telemetry-DGcFlVpB.d.cts.map +0 -1
  452. package/dist/telemetry-DGcFlVpB.d.mts.map +0 -1
  453. package/dist/topic/index.cjs.map +0 -1
  454. package/dist/topic/index.mjs.map +0 -1
@@ -0,0 +1,207 @@
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
+ //#region src/endpoints/rateLimit.ts
130
+ /**
131
+ * An endpoint's `.rateLimit()`, checked the one way every adaptor checks it —
132
+ * Hono, Lambda and the test adaptor — after the request is authorized.
133
+ *
134
+ * Under the limit, it answers the headers the response carries:
135
+ * `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (and
136
+ * `Retry-After` on the last request the window allows).
137
+ *
138
+ * @throws {TooManyRequestsError} over the limit — `@geekmidas/errors`' 429,
139
+ * whose `headers` hold `Retry-After` (seconds until the window resets) and the
140
+ * same `X-RateLimit-*`, which every adaptor sets on the error response.
141
+ */
142
+ async function enforceRateLimit(config, ctx) {
143
+ const { checkRateLimit, getRateLimitHeaders } = await loadRateLimit();
144
+ const info = await checkRateLimit(config, ctx);
145
+ const headers = {};
146
+ for (const [key, value] of Object.entries(getRateLimitHeaders(info, config))) if (value !== void 0) headers[key] = value;
147
+ return headers;
148
+ }
149
+ //#endregion
150
+ //#region src/endpoints/requestLogger.ts
151
+ /**
152
+ * The logger for one request to `endpoint`: the surface's, bound with which
153
+ * request it is and what it was for — the request id, the endpoint, its route
154
+ * and method — plus whatever the adaptor knows of the request itself (host,
155
+ * path, the Lambda and API Gateway context).
156
+ *
157
+ * One per request, made once, and the one the request context carries: the
158
+ * handler logs through it, a service reaches it through the context, and
159
+ * identifying the request (`identifyRequest`) derives the signed-in user's
160
+ * logger from it — so a line says whose request it was without losing which
161
+ * route it came from. A field the request does not have is left out rather
162
+ * than logged as `undefined`.
163
+ */
164
+ function requestLogger(endpoint, fields) {
165
+ const { requestId, ...request } = fields;
166
+ const bindings = {
167
+ requestId,
168
+ endpoint: endpoint.fullPath,
169
+ route: endpoint.route,
170
+ method: endpoint.method
171
+ };
172
+ for (const [key, value] of Object.entries(request)) if (value !== void 0) bindings[key] = value;
173
+ return endpoint.logger.child(bindings);
174
+ }
175
+ //#endregion
176
+ Object.defineProperty(exports, "createAuditContext", {
177
+ enumerable: true,
178
+ get: function() {
179
+ return createAuditContext;
180
+ }
181
+ });
182
+ Object.defineProperty(exports, "enforceRateLimit", {
183
+ enumerable: true,
184
+ get: function() {
185
+ return enforceRateLimit;
186
+ }
187
+ });
188
+ Object.defineProperty(exports, "executeWithAuditTransaction", {
189
+ enumerable: true,
190
+ get: function() {
191
+ return executeWithAuditTransaction;
192
+ }
193
+ });
194
+ Object.defineProperty(exports, "loadRls", {
195
+ enumerable: true,
196
+ get: function() {
197
+ return loadRls;
198
+ }
199
+ });
200
+ Object.defineProperty(exports, "requestLogger", {
201
+ enumerable: true,
202
+ get: function() {
203
+ return requestLogger;
204
+ }
205
+ });
206
+
207
+ //# sourceMappingURL=requestLogger-BZcXwdBs.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestLogger-BZcXwdBs.cjs","names":[],"sources":["../src/endpoints/optionalPeers.ts","../src/endpoints/processAudits.ts","../src/endpoints/rateLimit.ts","../src/endpoints/requestLogger.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","import type { RateLimitConfig, RateLimitContext } from '@geekmidas/rate-limit';\nimport { loadRateLimit } from './optionalPeers';\n\n/**\n * An endpoint's `.rateLimit()`, checked the one way every adaptor checks it —\n * Hono, Lambda and the test adaptor — after the request is authorized.\n *\n * Under the limit, it answers the headers the response carries:\n * `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (and\n * `Retry-After` on the last request the window allows).\n *\n * @throws {TooManyRequestsError} over the limit — `@geekmidas/errors`' 429,\n * whose `headers` hold `Retry-After` (seconds until the window resets) and the\n * same `X-RateLimit-*`, which every adaptor sets on the error response.\n */\nexport async function enforceRateLimit(\n\tconfig: RateLimitConfig,\n\tctx: RateLimitContext<any, any, any>,\n): Promise<Record<string, string>> {\n\tconst { checkRateLimit, getRateLimitHeaders } = await loadRateLimit();\n\tconst info = await checkRateLimit(config, ctx);\n\n\tconst headers: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries(\n\t\tgetRateLimitHeaders(info, config),\n\t)) {\n\t\tif (value !== undefined) headers[key] = value;\n\t}\n\treturn headers;\n}\n","import type { Logger } from '@geekmidas/logger';\n\n/** What an endpoint contributes to every line logged for one of its requests. */\ninterface LoggingEndpoint {\n\tlogger: Logger;\n\tfullPath: string;\n\troute: string;\n\tmethod: string;\n}\n\n/**\n * The logger for one request to `endpoint`: the surface's, bound with which\n * request it is and what it was for — the request id, the endpoint, its route\n * and method — plus whatever the adaptor knows of the request itself (host,\n * path, the Lambda and API Gateway context).\n *\n * One per request, made once, and the one the request context carries: the\n * handler logs through it, a service reaches it through the context, and\n * identifying the request (`identifyRequest`) derives the signed-in user's\n * logger from it — so a line says whose request it was without losing which\n * route it came from. A field the request does not have is left out rather\n * than logged as `undefined`.\n */\nexport function requestLogger<TLogger extends Logger>(\n\tendpoint: LoggingEndpoint,\n\tfields: { requestId: string } & Record<string, unknown>,\n): TLogger {\n\tconst { requestId, ...request } = fields;\n\tconst bindings: Record<string, unknown> = {\n\t\trequestId,\n\t\tendpoint: endpoint.fullPath,\n\t\troute: endpoint.route,\n\t\tmethod: endpoint.method,\n\t};\n\tfor (const [key, value] of Object.entries(request)) {\n\t\tif (value !== undefined) bindings[key] = value;\n\t}\n\treturn endpoint.logger.child(bindings) as TLogger;\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;;;;;;;;;;;;;;;ACjWA,eAAsB,iBACrB,QACA,KACkC;CAClC,MAAM,EAAE,gBAAgB,wBAAwB,MAAM,cAAc;CACpE,MAAM,OAAO,MAAM,eAAe,QAAQ,GAAG;CAE7C,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QACjC,oBAAoB,MAAM,MAAM,CACjC,GACC,IAAI,UAAU,KAAA,GAAW,QAAQ,OAAO;CAEzC,OAAO;AACR;;;;;;;;;;;;;;;;ACNA,SAAgB,cACf,UACA,QACU;CACV,MAAM,EAAE,WAAW,GAAG,YAAY;CAClC,MAAM,WAAoC;EACzC;EACA,UAAU,SAAS;EACnB,OAAO,SAAS;EAChB,QAAQ,SAAS;CAClB;CACA,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAChD,IAAI,UAAU,KAAA,GAAW,SAAS,OAAO;CAE1C,OAAO,SAAS,OAAO,MAAM,QAAQ;AACtC"}
@@ -0,0 +1,178 @@
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
+ //#region src/endpoints/rateLimit.ts
130
+ /**
131
+ * An endpoint's `.rateLimit()`, checked the one way every adaptor checks it —
132
+ * Hono, Lambda and the test adaptor — after the request is authorized.
133
+ *
134
+ * Under the limit, it answers the headers the response carries:
135
+ * `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (and
136
+ * `Retry-After` on the last request the window allows).
137
+ *
138
+ * @throws {TooManyRequestsError} over the limit — `@geekmidas/errors`' 429,
139
+ * whose `headers` hold `Retry-After` (seconds until the window resets) and the
140
+ * same `X-RateLimit-*`, which every adaptor sets on the error response.
141
+ */
142
+ async function enforceRateLimit(config, ctx) {
143
+ const { checkRateLimit, getRateLimitHeaders } = await loadRateLimit();
144
+ const info = await checkRateLimit(config, ctx);
145
+ const headers = {};
146
+ for (const [key, value] of Object.entries(getRateLimitHeaders(info, config))) if (value !== void 0) headers[key] = value;
147
+ return headers;
148
+ }
149
+ //#endregion
150
+ //#region src/endpoints/requestLogger.ts
151
+ /**
152
+ * The logger for one request to `endpoint`: the surface's, bound with which
153
+ * request it is and what it was for — the request id, the endpoint, its route
154
+ * and method — plus whatever the adaptor knows of the request itself (host,
155
+ * path, the Lambda and API Gateway context).
156
+ *
157
+ * One per request, made once, and the one the request context carries: the
158
+ * handler logs through it, a service reaches it through the context, and
159
+ * identifying the request (`identifyRequest`) derives the signed-in user's
160
+ * logger from it — so a line says whose request it was without losing which
161
+ * route it came from. A field the request does not have is left out rather
162
+ * than logged as `undefined`.
163
+ */
164
+ function requestLogger(endpoint, fields) {
165
+ const { requestId, ...request } = fields;
166
+ const bindings = {
167
+ requestId,
168
+ endpoint: endpoint.fullPath,
169
+ route: endpoint.route,
170
+ method: endpoint.method
171
+ };
172
+ for (const [key, value] of Object.entries(request)) if (value !== void 0) bindings[key] = value;
173
+ return endpoint.logger.child(bindings);
174
+ }
175
+ //#endregion
176
+ export { loadRls as a, executeWithAuditTransaction as i, enforceRateLimit as n, createAuditContext as r, requestLogger as t };
177
+
178
+ //# sourceMappingURL=requestLogger-pA4gi3E1.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestLogger-pA4gi3E1.mjs","names":[],"sources":["../src/endpoints/optionalPeers.ts","../src/endpoints/processAudits.ts","../src/endpoints/rateLimit.ts","../src/endpoints/requestLogger.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","import type { RateLimitConfig, RateLimitContext } from '@geekmidas/rate-limit';\nimport { loadRateLimit } from './optionalPeers';\n\n/**\n * An endpoint's `.rateLimit()`, checked the one way every adaptor checks it —\n * Hono, Lambda and the test adaptor — after the request is authorized.\n *\n * Under the limit, it answers the headers the response carries:\n * `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (and\n * `Retry-After` on the last request the window allows).\n *\n * @throws {TooManyRequestsError} over the limit — `@geekmidas/errors`' 429,\n * whose `headers` hold `Retry-After` (seconds until the window resets) and the\n * same `X-RateLimit-*`, which every adaptor sets on the error response.\n */\nexport async function enforceRateLimit(\n\tconfig: RateLimitConfig,\n\tctx: RateLimitContext<any, any, any>,\n): Promise<Record<string, string>> {\n\tconst { checkRateLimit, getRateLimitHeaders } = await loadRateLimit();\n\tconst info = await checkRateLimit(config, ctx);\n\n\tconst headers: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries(\n\t\tgetRateLimitHeaders(info, config),\n\t)) {\n\t\tif (value !== undefined) headers[key] = value;\n\t}\n\treturn headers;\n}\n","import type { Logger } from '@geekmidas/logger';\n\n/** What an endpoint contributes to every line logged for one of its requests. */\ninterface LoggingEndpoint {\n\tlogger: Logger;\n\tfullPath: string;\n\troute: string;\n\tmethod: string;\n}\n\n/**\n * The logger for one request to `endpoint`: the surface's, bound with which\n * request it is and what it was for — the request id, the endpoint, its route\n * and method — plus whatever the adaptor knows of the request itself (host,\n * path, the Lambda and API Gateway context).\n *\n * One per request, made once, and the one the request context carries: the\n * handler logs through it, a service reaches it through the context, and\n * identifying the request (`identifyRequest`) derives the signed-in user's\n * logger from it — so a line says whose request it was without losing which\n * route it came from. A field the request does not have is left out rather\n * than logged as `undefined`.\n */\nexport function requestLogger<TLogger extends Logger>(\n\tendpoint: LoggingEndpoint,\n\tfields: { requestId: string } & Record<string, unknown>,\n): TLogger {\n\tconst { requestId, ...request } = fields;\n\tconst bindings: Record<string, unknown> = {\n\t\trequestId,\n\t\tendpoint: endpoint.fullPath,\n\t\troute: endpoint.route,\n\t\tmethod: endpoint.method,\n\t};\n\tfor (const [key, value] of Object.entries(request)) {\n\t\tif (value !== undefined) bindings[key] = value;\n\t}\n\treturn endpoint.logger.child(bindings) as TLogger;\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;;;;;;;;;;;;;;;ACjWA,eAAsB,iBACrB,QACA,KACkC;CAClC,MAAM,EAAE,gBAAgB,wBAAwB,MAAM,cAAc;CACpE,MAAM,OAAO,MAAM,eAAe,QAAQ,GAAG;CAE7C,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QACjC,oBAAoB,MAAM,MAAM,CACjC,GACC,IAAI,UAAU,KAAA,GAAW,QAAQ,OAAO;CAEzC,OAAO;AACR;;;;;;;;;;;;;;;;ACNA,SAAgB,cACf,UACA,QACU;CACV,MAAM,EAAE,WAAW,GAAG,YAAY;CAClC,MAAM,WAAoC;EACzC;EACA,UAAU,SAAS;EACnB,OAAO,SAAS;EAChB,QAAQ,SAAS;CAClB;CACA,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAChD,IAAI,UAAU,KAAA,GAAW,SAAS,OAAO;CAE1C,OAAO,SAAS,OAAO,MAAM,QAAQ;AACtC"}