@xtandard/audit 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (423) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +384 -2
  3. package/bin/xtandard-audit.mjs +3 -0
  4. package/dist/basic-DU_nPrWV.mjs +176 -0
  5. package/dist/basic-DU_nPrWV.mjs.map +1 -0
  6. package/dist/basic-hcXnMF9X.cjs +199 -0
  7. package/dist/basic-hcXnMF9X.cjs.map +1 -0
  8. package/dist/canonical-BOgkrX9_.d.cts +17 -0
  9. package/dist/canonical-CL7gfwhb.d.mts +17 -0
  10. package/dist/chunk-D7D4PA-g.mjs +13 -0
  11. package/dist/cli.cjs +773 -0
  12. package/dist/cli.cjs.map +1 -0
  13. package/dist/cli.d.cts +46 -0
  14. package/dist/cli.d.mts +46 -0
  15. package/dist/cli.mjs +762 -0
  16. package/dist/cli.mjs.map +1 -0
  17. package/dist/context-BtR9k9Mt.d.mts +52 -0
  18. package/dist/context-CJM87uG8.d.cts +52 -0
  19. package/dist/context-shared-AgBWIRUQ.d.mts +29 -0
  20. package/dist/context-shared-CUq3cSpV.d.cts +29 -0
  21. package/dist/context-shared-CupikwQo.mjs +39 -0
  22. package/dist/context-shared-CupikwQo.mjs.map +1 -0
  23. package/dist/context-shared-X2ulHHSB.cjs +44 -0
  24. package/dist/context-shared-X2ulHHSB.cjs.map +1 -0
  25. package/dist/context.cjs +82 -0
  26. package/dist/context.cjs.map +1 -0
  27. package/dist/context.d.cts +2 -0
  28. package/dist/context.d.mts +2 -0
  29. package/dist/context.mjs +78 -0
  30. package/dist/context.mjs.map +1 -0
  31. package/dist/contract-BljSE-Hx.mjs +33 -0
  32. package/dist/contract-BljSE-Hx.mjs.map +1 -0
  33. package/dist/contract-BmwHIiMR.d.mts +150 -0
  34. package/dist/contract-CWJSYoJl.d.cts +150 -0
  35. package/dist/contract-Cht05WYQ.d.mts +159 -0
  36. package/dist/contract-CqYQzB6e.d.cts +49 -0
  37. package/dist/contract-DYvBNdnR.cjs +74 -0
  38. package/dist/contract-DYvBNdnR.cjs.map +1 -0
  39. package/dist/contract-DlTo4u2t.d.cts +30 -0
  40. package/dist/contract-DlTo4u2t.d.mts +30 -0
  41. package/dist/contract-DsVL5-gy.cjs +50 -0
  42. package/dist/contract-DsVL5-gy.cjs.map +1 -0
  43. package/dist/contract-isM9SjjQ.mjs +39 -0
  44. package/dist/contract-isM9SjjQ.mjs.map +1 -0
  45. package/dist/contract-pU3wGFmo.d.cts +159 -0
  46. package/dist/contract-yPNuFnVy.d.mts +49 -0
  47. package/dist/core-C0ceVOTk.d.cts +513 -0
  48. package/dist/core-CTr7dw0v.cjs +1725 -0
  49. package/dist/core-CTr7dw0v.cjs.map +1 -0
  50. package/dist/core-IdGEbYdM.mjs +1541 -0
  51. package/dist/core-IdGEbYdM.mjs.map +1 -0
  52. package/dist/core-KtEHRScZ.d.mts +513 -0
  53. package/dist/core.cjs +9 -0
  54. package/dist/core.d.cts +2 -0
  55. package/dist/core.d.mts +2 -0
  56. package/dist/core.mjs +2 -0
  57. package/dist/create-fetch-handler-1pXSEhGi.d.cts +311 -0
  58. package/dist/create-fetch-handler-BwQQ_IWf.mjs +2156 -0
  59. package/dist/create-fetch-handler-BwQQ_IWf.mjs.map +1 -0
  60. package/dist/create-fetch-handler-D8cTMVX9.cjs +2232 -0
  61. package/dist/create-fetch-handler-D8cTMVX9.cjs.map +1 -0
  62. package/dist/create-fetch-handler-zioPVS18.d.mts +311 -0
  63. package/dist/elysia-shared-C7geKqPP.mjs +55 -0
  64. package/dist/elysia-shared-C7geKqPP.mjs.map +1 -0
  65. package/dist/elysia-shared-DT4bfekR.d.cts +20 -0
  66. package/dist/elysia-shared-DXyAyGz_.cjs +66 -0
  67. package/dist/elysia-shared-DXyAyGz_.cjs.map +1 -0
  68. package/dist/elysia-shared-DoL5ab52.d.mts +20 -0
  69. package/dist/entry-auth-basic.cjs +5 -0
  70. package/dist/entry-auth-basic.d.cts +83 -0
  71. package/dist/entry-auth-basic.d.mts +83 -0
  72. package/dist/entry-auth-basic.mjs +2 -0
  73. package/dist/entry-auth-delegated.cjs +28 -0
  74. package/dist/entry-auth-delegated.cjs.map +1 -0
  75. package/dist/entry-auth-delegated.d.cts +36 -0
  76. package/dist/entry-auth-delegated.d.mts +36 -0
  77. package/dist/entry-auth-delegated.mjs +27 -0
  78. package/dist/entry-auth-delegated.mjs.map +1 -0
  79. package/dist/entry-auth-none.cjs +4 -0
  80. package/dist/entry-auth-none.d.cts +25 -0
  81. package/dist/entry-auth-none.d.mts +25 -0
  82. package/dist/entry-auth-none.mjs +2 -0
  83. package/dist/entry-authorization-delegated.cjs +28 -0
  84. package/dist/entry-authorization-delegated.cjs.map +1 -0
  85. package/dist/entry-authorization-delegated.d.cts +32 -0
  86. package/dist/entry-authorization-delegated.d.mts +32 -0
  87. package/dist/entry-authorization-delegated.mjs +27 -0
  88. package/dist/entry-authorization-delegated.mjs.map +1 -0
  89. package/dist/entry-authorization-none.cjs +3 -0
  90. package/dist/entry-authorization-none.d.cts +18 -0
  91. package/dist/entry-authorization-none.d.mts +18 -0
  92. package/dist/entry-authorization-none.mjs +2 -0
  93. package/dist/entry-authorization-roles.cjs +8 -0
  94. package/dist/entry-authorization-roles.d.cts +64 -0
  95. package/dist/entry-authorization-roles.d.mts +64 -0
  96. package/dist/entry-authorization-roles.mjs +3 -0
  97. package/dist/entry-bun.cjs +55 -0
  98. package/dist/entry-bun.cjs.map +1 -0
  99. package/dist/entry-bun.d.cts +29 -0
  100. package/dist/entry-bun.d.mts +29 -0
  101. package/dist/entry-bun.mjs +52 -0
  102. package/dist/entry-bun.mjs.map +1 -0
  103. package/dist/entry-drizzle-audit.cjs +191 -0
  104. package/dist/entry-drizzle-audit.cjs.map +1 -0
  105. package/dist/entry-drizzle-audit.d.cts +118 -0
  106. package/dist/entry-drizzle-audit.d.mts +118 -0
  107. package/dist/entry-drizzle-audit.mjs +186 -0
  108. package/dist/entry-drizzle-audit.mjs.map +1 -0
  109. package/dist/entry-drizzle-mysql.cjs +75 -0
  110. package/dist/entry-drizzle-mysql.cjs.map +1 -0
  111. package/dist/entry-drizzle-mysql.d.cts +42 -0
  112. package/dist/entry-drizzle-mysql.d.mts +42 -0
  113. package/dist/entry-drizzle-mysql.mjs +71 -0
  114. package/dist/entry-drizzle-mysql.mjs.map +1 -0
  115. package/dist/entry-drizzle-pg.cjs +82 -0
  116. package/dist/entry-drizzle-pg.cjs.map +1 -0
  117. package/dist/entry-drizzle-pg.d.cts +48 -0
  118. package/dist/entry-drizzle-pg.d.mts +48 -0
  119. package/dist/entry-drizzle-pg.mjs +78 -0
  120. package/dist/entry-drizzle-pg.mjs.map +1 -0
  121. package/dist/entry-drizzle-sqlite.cjs +71 -0
  122. package/dist/entry-drizzle-sqlite.cjs.map +1 -0
  123. package/dist/entry-drizzle-sqlite.d.cts +37 -0
  124. package/dist/entry-drizzle-sqlite.d.mts +37 -0
  125. package/dist/entry-drizzle-sqlite.mjs +67 -0
  126. package/dist/entry-drizzle-sqlite.mjs.map +1 -0
  127. package/dist/entry-elysia.cjs +112 -0
  128. package/dist/entry-elysia.cjs.map +1 -0
  129. package/dist/entry-elysia.d.cts +710 -0
  130. package/dist/entry-elysia.d.mts +710 -0
  131. package/dist/entry-elysia.mjs +109 -0
  132. package/dist/entry-elysia.mjs.map +1 -0
  133. package/dist/entry-elysia2.cjs +101 -0
  134. package/dist/entry-elysia2.cjs.map +1 -0
  135. package/dist/entry-elysia2.d.cts +905 -0
  136. package/dist/entry-elysia2.d.mts +905 -0
  137. package/dist/entry-elysia2.mjs +98 -0
  138. package/dist/entry-elysia2.mjs.map +1 -0
  139. package/dist/entry-express.cjs +90 -0
  140. package/dist/entry-express.cjs.map +1 -0
  141. package/dist/entry-express.d.cts +24 -0
  142. package/dist/entry-express.d.mts +24 -0
  143. package/dist/entry-express.mjs +88 -0
  144. package/dist/entry-express.mjs.map +1 -0
  145. package/dist/entry-hono.cjs +36 -0
  146. package/dist/entry-hono.cjs.map +1 -0
  147. package/dist/entry-hono.d.cts +24 -0
  148. package/dist/entry-hono.d.mts +24 -0
  149. package/dist/entry-hono.mjs +34 -0
  150. package/dist/entry-hono.mjs.map +1 -0
  151. package/dist/entry-hooks-log.cjs +22 -0
  152. package/dist/entry-hooks-log.cjs.map +1 -0
  153. package/dist/entry-hooks-log.d.cts +23 -0
  154. package/dist/entry-hooks-log.d.mts +23 -0
  155. package/dist/entry-hooks-log.mjs +21 -0
  156. package/dist/entry-hooks-log.mjs.map +1 -0
  157. package/dist/entry-sinks-console.cjs +43 -0
  158. package/dist/entry-sinks-console.cjs.map +1 -0
  159. package/dist/entry-sinks-console.d.cts +26 -0
  160. package/dist/entry-sinks-console.d.mts +26 -0
  161. package/dist/entry-sinks-console.mjs +41 -0
  162. package/dist/entry-sinks-console.mjs.map +1 -0
  163. package/dist/entry-sinks-datadog.cjs +97 -0
  164. package/dist/entry-sinks-datadog.cjs.map +1 -0
  165. package/dist/entry-sinks-datadog.d.cts +66 -0
  166. package/dist/entry-sinks-datadog.d.mts +66 -0
  167. package/dist/entry-sinks-datadog.mjs +91 -0
  168. package/dist/entry-sinks-datadog.mjs.map +1 -0
  169. package/dist/entry-sinks-file.cjs +100 -0
  170. package/dist/entry-sinks-file.cjs.map +1 -0
  171. package/dist/entry-sinks-file.d.cts +70 -0
  172. package/dist/entry-sinks-file.d.mts +70 -0
  173. package/dist/entry-sinks-file.mjs +97 -0
  174. package/dist/entry-sinks-file.mjs.map +1 -0
  175. package/dist/entry-sinks-http.cjs +63 -0
  176. package/dist/entry-sinks-http.cjs.map +1 -0
  177. package/dist/entry-sinks-http.d.cts +55 -0
  178. package/dist/entry-sinks-http.d.mts +55 -0
  179. package/dist/entry-sinks-http.mjs +60 -0
  180. package/dist/entry-sinks-http.mjs.map +1 -0
  181. package/dist/entry-sinks-s3.cjs +115 -0
  182. package/dist/entry-sinks-s3.cjs.map +1 -0
  183. package/dist/entry-sinks-s3.d.cts +79 -0
  184. package/dist/entry-sinks-s3.d.mts +79 -0
  185. package/dist/entry-sinks-s3.mjs +112 -0
  186. package/dist/entry-sinks-s3.mjs.map +1 -0
  187. package/dist/entry-sinks-splunk.cjs +80 -0
  188. package/dist/entry-sinks-splunk.cjs.map +1 -0
  189. package/dist/entry-sinks-splunk.d.cts +58 -0
  190. package/dist/entry-sinks-splunk.d.mts +58 -0
  191. package/dist/entry-sinks-splunk.mjs +77 -0
  192. package/dist/entry-sinks-splunk.mjs.map +1 -0
  193. package/dist/entry-sinks-webhook.cjs +130 -0
  194. package/dist/entry-sinks-webhook.cjs.map +1 -0
  195. package/dist/entry-sinks-webhook.d.cts +69 -0
  196. package/dist/entry-sinks-webhook.d.mts +69 -0
  197. package/dist/entry-sinks-webhook.mjs +125 -0
  198. package/dist/entry-sinks-webhook.mjs.map +1 -0
  199. package/dist/entry-sinks-xtandard-webhooks.cjs +64 -0
  200. package/dist/entry-sinks-xtandard-webhooks.cjs.map +1 -0
  201. package/dist/entry-sinks-xtandard-webhooks.d.cts +64 -0
  202. package/dist/entry-sinks-xtandard-webhooks.d.mts +64 -0
  203. package/dist/entry-sinks-xtandard-webhooks.mjs +63 -0
  204. package/dist/entry-sinks-xtandard-webhooks.mjs.map +1 -0
  205. package/dist/entry-storage-cloudflare-kv.cjs +47 -0
  206. package/dist/entry-storage-cloudflare-kv.cjs.map +1 -0
  207. package/dist/entry-storage-cloudflare-kv.d.cts +42 -0
  208. package/dist/entry-storage-cloudflare-kv.d.mts +42 -0
  209. package/dist/entry-storage-cloudflare-kv.mjs +46 -0
  210. package/dist/entry-storage-cloudflare-kv.mjs.map +1 -0
  211. package/dist/entry-storage-drizzle.cjs +228 -0
  212. package/dist/entry-storage-drizzle.cjs.map +1 -0
  213. package/dist/entry-storage-drizzle.d.cts +43 -0
  214. package/dist/entry-storage-drizzle.d.mts +43 -0
  215. package/dist/entry-storage-drizzle.mjs +227 -0
  216. package/dist/entry-storage-drizzle.mjs.map +1 -0
  217. package/dist/entry-storage-file.cjs +175 -0
  218. package/dist/entry-storage-file.cjs.map +1 -0
  219. package/dist/entry-storage-file.d.cts +41 -0
  220. package/dist/entry-storage-file.d.mts +41 -0
  221. package/dist/entry-storage-file.mjs +171 -0
  222. package/dist/entry-storage-file.mjs.map +1 -0
  223. package/dist/entry-storage-libsql.cjs +133 -0
  224. package/dist/entry-storage-libsql.cjs.map +1 -0
  225. package/dist/entry-storage-libsql.d.cts +60 -0
  226. package/dist/entry-storage-libsql.d.mts +60 -0
  227. package/dist/entry-storage-libsql.mjs +132 -0
  228. package/dist/entry-storage-libsql.mjs.map +1 -0
  229. package/dist/entry-storage-memory.cjs +3 -0
  230. package/dist/entry-storage-memory.d.cts +2 -0
  231. package/dist/entry-storage-memory.d.mts +2 -0
  232. package/dist/entry-storage-memory.mjs +2 -0
  233. package/dist/entry-storage-mongodb.cjs +306 -0
  234. package/dist/entry-storage-mongodb.cjs.map +1 -0
  235. package/dist/entry-storage-mongodb.d.cts +65 -0
  236. package/dist/entry-storage-mongodb.d.mts +65 -0
  237. package/dist/entry-storage-mongodb.mjs +304 -0
  238. package/dist/entry-storage-mongodb.mjs.map +1 -0
  239. package/dist/entry-storage-postgres.cjs +261 -0
  240. package/dist/entry-storage-postgres.cjs.map +1 -0
  241. package/dist/entry-storage-postgres.d.cts +66 -0
  242. package/dist/entry-storage-postgres.d.mts +66 -0
  243. package/dist/entry-storage-postgres.mjs +260 -0
  244. package/dist/entry-storage-postgres.mjs.map +1 -0
  245. package/dist/entry-storage-redis.cjs +223 -0
  246. package/dist/entry-storage-redis.cjs.map +1 -0
  247. package/dist/entry-storage-redis.d.cts +77 -0
  248. package/dist/entry-storage-redis.d.mts +77 -0
  249. package/dist/entry-storage-redis.mjs +221 -0
  250. package/dist/entry-storage-redis.mjs.map +1 -0
  251. package/dist/entry-storage-sqlite.cjs +85 -0
  252. package/dist/entry-storage-sqlite.cjs.map +1 -0
  253. package/dist/entry-storage-sqlite.d.cts +40 -0
  254. package/dist/entry-storage-sqlite.d.mts +40 -0
  255. package/dist/entry-storage-sqlite.mjs +84 -0
  256. package/dist/entry-storage-sqlite.mjs.map +1 -0
  257. package/dist/entry-storage-unstorage.cjs +57 -0
  258. package/dist/entry-storage-unstorage.cjs.map +1 -0
  259. package/dist/entry-storage-unstorage.d.cts +29 -0
  260. package/dist/entry-storage-unstorage.d.mts +29 -0
  261. package/dist/entry-storage-unstorage.mjs +56 -0
  262. package/dist/entry-storage-unstorage.mjs.map +1 -0
  263. package/dist/export-B9S-JeYl.mjs +239 -0
  264. package/dist/export-B9S-JeYl.mjs.map +1 -0
  265. package/dist/export-BZq0KCCn.d.mts +70 -0
  266. package/dist/export-DYfMd-ep.cjs +280 -0
  267. package/dist/export-DYfMd-ep.cjs.map +1 -0
  268. package/dist/export-Dh8T8I1p.d.cts +70 -0
  269. package/dist/index.cjs +279 -0
  270. package/dist/index.cjs.map +1 -0
  271. package/dist/index.d.cts +286 -0
  272. package/dist/index.d.mts +284 -0
  273. package/dist/index.mjs +177 -0
  274. package/dist/index.mjs.map +1 -0
  275. package/dist/integrity-BHhjTBNk.cjs +614 -0
  276. package/dist/integrity-BHhjTBNk.cjs.map +1 -0
  277. package/dist/integrity-kfY2DNAi.mjs +483 -0
  278. package/dist/integrity-kfY2DNAi.mjs.map +1 -0
  279. package/dist/memory-CfykUo9W.cjs +155 -0
  280. package/dist/memory-CfykUo9W.cjs.map +1 -0
  281. package/dist/memory-DrR-Tlbf.d.mts +28 -0
  282. package/dist/memory-GG2Nba1D.mjs +150 -0
  283. package/dist/memory-GG2Nba1D.mjs.map +1 -0
  284. package/dist/memory-HpFdlMR_.d.cts +28 -0
  285. package/dist/none-Be7r6kHH.cjs +33 -0
  286. package/dist/none-Be7r6kHH.cjs.map +1 -0
  287. package/dist/none-CGmIIbI8.cjs +49 -0
  288. package/dist/none-CGmIIbI8.cjs.map +1 -0
  289. package/dist/none-CkV5mZsB.mjs +33 -0
  290. package/dist/none-CkV5mZsB.mjs.map +1 -0
  291. package/dist/none-DBeBeU0Z.mjs +23 -0
  292. package/dist/none-DBeBeU0Z.mjs.map +1 -0
  293. package/dist/query-ChGGtlA7.cjs +243 -0
  294. package/dist/query-ChGGtlA7.cjs.map +1 -0
  295. package/dist/query-LvZbyi37.mjs +172 -0
  296. package/dist/query-LvZbyi37.mjs.map +1 -0
  297. package/dist/react.css +1 -0
  298. package/dist/react.js +31935 -0
  299. package/dist/recorder-B3dG3jbd.d.mts +64 -0
  300. package/dist/recorder-CGY7HK29.d.cts +64 -0
  301. package/dist/roles-BARtYLSX.cjs +112 -0
  302. package/dist/roles-BARtYLSX.cjs.map +1 -0
  303. package/dist/roles-D7Pg89IJ.mjs +83 -0
  304. package/dist/roles-D7Pg89IJ.mjs.map +1 -0
  305. package/dist/schema-DmU7Wp0F.d.cts +251 -0
  306. package/dist/schema-DmU7Wp0F.d.mts +251 -0
  307. package/dist/schema.cjs +20 -0
  308. package/dist/schema.cjs.map +1 -0
  309. package/dist/schema.d.cts +2 -0
  310. package/dist/schema.d.mts +2 -0
  311. package/dist/schema.mjs +17 -0
  312. package/dist/schema.mjs.map +1 -0
  313. package/dist/shared-CJOyJKqT.d.mts +20 -0
  314. package/dist/shared-DSDY-V0n.mjs +100 -0
  315. package/dist/shared-DSDY-V0n.mjs.map +1 -0
  316. package/dist/shared-EANCdRqn.d.cts +20 -0
  317. package/dist/shared-OOAq-U4S.cjs +141 -0
  318. package/dist/shared-OOAq-U4S.cjs.map +1 -0
  319. package/dist/sql-B7b6HzGy.cjs +280 -0
  320. package/dist/sql-B7b6HzGy.cjs.map +1 -0
  321. package/dist/sql-COjPyn3F.mjs +209 -0
  322. package/dist/sql-COjPyn3F.mjs.map +1 -0
  323. package/dist/sqlite-event-log-BnoG8eos.cjs +184 -0
  324. package/dist/sqlite-event-log-BnoG8eos.cjs.map +1 -0
  325. package/dist/sqlite-event-log-nXmS2DS_.mjs +179 -0
  326. package/dist/sqlite-event-log-nXmS2DS_.mjs.map +1 -0
  327. package/dist/streams-CRuxOYcb.d.cts +124 -0
  328. package/dist/streams-DU0_gvI8.d.mts +124 -0
  329. package/dist/table-BcarDd10.d.cts +48 -0
  330. package/dist/table-BcarDd10.d.mts +48 -0
  331. package/dist/testing.cjs +189 -0
  332. package/dist/testing.cjs.map +1 -0
  333. package/dist/testing.d.cts +103 -0
  334. package/dist/testing.d.mts +103 -0
  335. package/dist/testing.mjs +185 -0
  336. package/dist/testing.mjs.map +1 -0
  337. package/dist/types-elysia2/adapters/bun.d.ts +47 -0
  338. package/dist/types-elysia2/adapters/context-shared.d.ts +40 -0
  339. package/dist/types-elysia2/adapters/elysia-shared.d.ts +36 -0
  340. package/dist/types-elysia2/adapters/elysia2.d.ts +588 -0
  341. package/dist/types-elysia2/auth/contract.d.ts +26 -0
  342. package/dist/types-elysia2/authorization/contract.d.ts +54 -0
  343. package/dist/types-elysia2/canonical.d.ts +25 -0
  344. package/dist/types-elysia2/context.d.ts +61 -0
  345. package/dist/types-elysia2/core.d.ts +232 -0
  346. package/dist/types-elysia2/duration.d.ts +26 -0
  347. package/dist/types-elysia2/entry-elysia2.d.ts +10 -0
  348. package/dist/types-elysia2/event-log.d.ts +33 -0
  349. package/dist/types-elysia2/export.d.ts +77 -0
  350. package/dist/types-elysia2/hooks/contract.d.ts +177 -0
  351. package/dist/types-elysia2/id.d.ts +27 -0
  352. package/dist/types-elysia2/integrity.d.ts +193 -0
  353. package/dist/types-elysia2/keys.d.ts +91 -0
  354. package/dist/types-elysia2/portal.d.ts +137 -0
  355. package/dist/types-elysia2/query.d.ts +88 -0
  356. package/dist/types-elysia2/schema.d.ts +247 -0
  357. package/dist/types-elysia2/server/base-path.d.ts +15 -0
  358. package/dist/types-elysia2/server/cors.d.ts +36 -0
  359. package/dist/types-elysia2/server/create-fetch-handler.d.ts +140 -0
  360. package/dist/types-elysia2/server/openapi.d.ts +25 -0
  361. package/dist/types-elysia2/server/render-index-html.d.ts +18 -0
  362. package/dist/types-elysia2/server/routes.d.ts +83 -0
  363. package/dist/types-elysia2/server/static-assets.d.ts +13 -0
  364. package/dist/types-elysia2/standard-schema.d.ts +100 -0
  365. package/dist/types-elysia2/storage/contract.d.ts +106 -0
  366. package/dist/types-elysia2/streams.d.ts +134 -0
  367. package/dist/types-elysia2/transforms.d.ts +56 -0
  368. package/dist/types-elysia2/validation.d.ts +48 -0
  369. package/dist/types-react/canonical.d.ts +25 -0
  370. package/dist/types-react/context.d.ts +61 -0
  371. package/dist/types-react/core.d.ts +232 -0
  372. package/dist/types-react/duration.d.ts +26 -0
  373. package/dist/types-react/event-log.d.ts +33 -0
  374. package/dist/types-react/hooks/contract.d.ts +177 -0
  375. package/dist/types-react/id.d.ts +27 -0
  376. package/dist/types-react/integrity.d.ts +193 -0
  377. package/dist/types-react/keys.d.ts +91 -0
  378. package/dist/types-react/query.d.ts +88 -0
  379. package/dist/types-react/react.d.ts +114 -0
  380. package/dist/types-react/schema.d.ts +247 -0
  381. package/dist/types-react/standard-schema.d.ts +100 -0
  382. package/dist/types-react/storage/contract.d.ts +106 -0
  383. package/dist/types-react/streams.d.ts +134 -0
  384. package/dist/types-react/transforms.d.ts +56 -0
  385. package/dist/types-react/ui/App.d.ts +36 -0
  386. package/dist/types-react/ui/api.d.ts +61 -0
  387. package/dist/types-react/ui/components/ActionFilter.d.ts +17 -0
  388. package/dist/types-react/ui/components/ExportMenu.d.ts +13 -0
  389. package/dist/types-react/ui/components/JsonCodeEditor.d.ts +12 -0
  390. package/dist/types-react/ui/components/ThemeToggle.d.ts +2 -0
  391. package/dist/types-react/ui/components/Toast.d.ts +16 -0
  392. package/dist/types-react/ui/components/audit-bits.d.ts +91 -0
  393. package/dist/types-react/ui/components/integrity-bits.d.ts +19 -0
  394. package/dist/types-react/ui/components/primitives.d.ts +50 -0
  395. package/dist/types-react/ui/components/ui-bits.d.ts +22 -0
  396. package/dist/types-react/ui/lib/filters.d.ts +70 -0
  397. package/dist/types-react/ui/lib/format.d.ts +82 -0
  398. package/dist/types-react/ui/lib/nav-guard.d.ts +20 -0
  399. package/dist/types-react/ui/lib/portal-container.d.ts +24 -0
  400. package/dist/types-react/ui/lib/utils.d.ts +3 -0
  401. package/dist/types-react/ui/theme.d.ts +40 -0
  402. package/dist/types-react/ui/types.d.ts +67 -0
  403. package/dist/types-react/ui/views/ActionsView.d.ts +10 -0
  404. package/dist/types-react/ui/views/EventDrawer.d.ts +15 -0
  405. package/dist/types-react/ui/views/EventsView.d.ts +10 -0
  406. package/dist/types-react/ui/views/IntegrityView.d.ts +10 -0
  407. package/dist/types-react/ui/views/OverviewView.d.ts +9 -0
  408. package/dist/types-react/ui/views/StreamsView.d.ts +10 -0
  409. package/dist/types-react/ui/views/TenantsView.d.ts +6 -0
  410. package/dist/types-react/validation.d.ts +48 -0
  411. package/dist/ui/assets/favicon-BSj8MPnj.svg +11 -0
  412. package/dist/ui/assets/index-Cd-mcIwC.css +1 -0
  413. package/dist/ui/assets/index-DUAgpiot.js +244 -0
  414. package/dist/ui/index.html +15 -0
  415. package/dist/validation-DFrLESZD.mjs +150 -0
  416. package/dist/validation-DFrLESZD.mjs.map +1 -0
  417. package/dist/validation-lb0YXrxx.cjs +235 -0
  418. package/dist/validation-lb0YXrxx.cjs.map +1 -0
  419. package/dist/verify.cjs +14 -0
  420. package/dist/verify.d.cts +5 -0
  421. package/dist/verify.d.mts +5 -0
  422. package/dist/verify.mjs +3 -0
  423. package/package.json +610 -4
@@ -0,0 +1,70 @@
1
+ import { u as RecordInput } from "./core-C0ceVOTk.cjs";
2
+ import { n as StreamBatch, t as AuditSink } from "./streams-CRuxOYcb.cjs";
3
+ import { n as RecorderFallback } from "./recorder-CGY7HK29.cjs";
4
+
5
+ //#region src/sinks/file.d.ts
6
+ /** Options for {@link fileSink}. */
7
+ interface FileSinkOptions {
8
+ /** File to append to, or a function of the batch (e.g. one file per tenant). */
9
+ path: string | ((batch: StreamBatch) => string);
10
+ /** `fsync` after each append. Default `true`. */
11
+ fsync?: boolean;
12
+ }
13
+ /** Options for {@link fileFallback}. */
14
+ interface FileFallbackOptions {
15
+ /** `fsync` after each append. Default `true`. */
16
+ fsync?: boolean;
17
+ }
18
+ /**
19
+ * Create a JSONL file sink.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { fileSink } from "@xtandard/audit/sinks/file";
24
+ *
25
+ * const sink = fileSink({ path: (batch) => `./audit-archive/${batch.tenant}.jsonl` });
26
+ * ```
27
+ */
28
+ declare function fileSink(options: FileSinkOptions): AuditSink;
29
+ /** One line written by {@link fileFallback}. */
30
+ interface FallbackLine {
31
+ /** ISO-8601 time the batch was parked. */
32
+ at: string;
33
+ /** The storage error message. */
34
+ error: string;
35
+ /** The original record input (ambient context already resolved). */
36
+ input: RecordInput;
37
+ }
38
+ /**
39
+ * A {@link RecorderFallback} that appends batches the recorder could not
40
+ * persist to a JSONL file.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { createRecorder } from "@xtandard/audit";
45
+ * import { fileFallback } from "@xtandard/audit/sinks/file";
46
+ *
47
+ * const recorder = createRecorder(audit, {
48
+ * fallback: fileFallback("/var/lib/app/audit-fallback.jsonl"),
49
+ * onError: (err, batch) => logger.error({ err, parked: batch.length }, "audit storage down"),
50
+ * });
51
+ * ```
52
+ */
53
+ declare function fileFallback(path: string, options?: FileFallbackOptions): RecorderFallback;
54
+ /**
55
+ * Parse a fallback file's content back into record inputs (for replay with
56
+ * `core.recordMany`). Blank lines are skipped.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { readFile } from "node:fs/promises";
61
+ * import { readFallbackLines } from "@xtandard/audit/sinks/file";
62
+ *
63
+ * const lines = readFallbackLines(await readFile(path, "utf8"));
64
+ * await audit.recordMany(lines.map((l) => l.input));
65
+ * ```
66
+ */
67
+ declare function readFallbackLines(text: string): FallbackLine[];
68
+ //#endregion
69
+ export { FallbackLine, FileFallbackOptions, FileSinkOptions, fileFallback, fileSink, readFallbackLines };
70
+ //# sourceMappingURL=entry-sinks-file.d.cts.map
@@ -0,0 +1,70 @@
1
+ import { u as RecordInput } from "./core-KtEHRScZ.mjs";
2
+ import { n as StreamBatch, t as AuditSink } from "./streams-DU0_gvI8.mjs";
3
+ import { n as RecorderFallback } from "./recorder-B3dG3jbd.mjs";
4
+
5
+ //#region src/sinks/file.d.ts
6
+ /** Options for {@link fileSink}. */
7
+ interface FileSinkOptions {
8
+ /** File to append to, or a function of the batch (e.g. one file per tenant). */
9
+ path: string | ((batch: StreamBatch) => string);
10
+ /** `fsync` after each append. Default `true`. */
11
+ fsync?: boolean;
12
+ }
13
+ /** Options for {@link fileFallback}. */
14
+ interface FileFallbackOptions {
15
+ /** `fsync` after each append. Default `true`. */
16
+ fsync?: boolean;
17
+ }
18
+ /**
19
+ * Create a JSONL file sink.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { fileSink } from "@xtandard/audit/sinks/file";
24
+ *
25
+ * const sink = fileSink({ path: (batch) => `./audit-archive/${batch.tenant}.jsonl` });
26
+ * ```
27
+ */
28
+ declare function fileSink(options: FileSinkOptions): AuditSink;
29
+ /** One line written by {@link fileFallback}. */
30
+ interface FallbackLine {
31
+ /** ISO-8601 time the batch was parked. */
32
+ at: string;
33
+ /** The storage error message. */
34
+ error: string;
35
+ /** The original record input (ambient context already resolved). */
36
+ input: RecordInput;
37
+ }
38
+ /**
39
+ * A {@link RecorderFallback} that appends batches the recorder could not
40
+ * persist to a JSONL file.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { createRecorder } from "@xtandard/audit";
45
+ * import { fileFallback } from "@xtandard/audit/sinks/file";
46
+ *
47
+ * const recorder = createRecorder(audit, {
48
+ * fallback: fileFallback("/var/lib/app/audit-fallback.jsonl"),
49
+ * onError: (err, batch) => logger.error({ err, parked: batch.length }, "audit storage down"),
50
+ * });
51
+ * ```
52
+ */
53
+ declare function fileFallback(path: string, options?: FileFallbackOptions): RecorderFallback;
54
+ /**
55
+ * Parse a fallback file's content back into record inputs (for replay with
56
+ * `core.recordMany`). Blank lines are skipped.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { readFile } from "node:fs/promises";
61
+ * import { readFallbackLines } from "@xtandard/audit/sinks/file";
62
+ *
63
+ * const lines = readFallbackLines(await readFile(path, "utf8"));
64
+ * await audit.recordMany(lines.map((l) => l.input));
65
+ * ```
66
+ */
67
+ declare function readFallbackLines(text: string): FallbackLine[];
68
+ //#endregion
69
+ export { FallbackLine, FileFallbackOptions, FileSinkOptions, fileFallback, fileSink, readFallbackLines };
70
+ //# sourceMappingURL=entry-sinks-file.d.mts.map
@@ -0,0 +1,97 @@
1
+ import { mkdir, open } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ //#region src/sinks/file.ts
4
+ /**
5
+ * File sink + recorder fallback, both appending JSON Lines with `node:fs`
6
+ * (Bun and Node):
7
+ *
8
+ * - `fileSink({ path })` — a stream sink: appends one `StreamItem` per line
9
+ * (`{ "kind": "event", "event": … }` / `{ "kind": "checkpoint", … }`);
10
+ * `path` may depend on the batch (per-tenant files).
11
+ * - `fileFallback(path)` — a `RecorderFallback` for the buffered recorder
12
+ * (ADR 0002): when storage keeps failing, the batch is appended as
13
+ * `{ "at", "error", "input" }` lines so nothing is lost; replay them later
14
+ * with `core.recordMany(lines.map((l) => l.input))`.
15
+ *
16
+ * Both `fsync` by default — the write is durable before the promise resolves.
17
+ *
18
+ * @module
19
+ */
20
+ /** Append text to a file (creating parent directories), optionally fsync'd. */
21
+ async function appendDurable(path, text, fsync) {
22
+ await mkdir(dirname(path), { recursive: true });
23
+ const handle = await open(path, "a");
24
+ try {
25
+ await handle.appendFile(text, "utf8");
26
+ if (fsync) await handle.sync();
27
+ } finally {
28
+ await handle.close();
29
+ }
30
+ }
31
+ /**
32
+ * Create a JSONL file sink.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { fileSink } from "@xtandard/audit/sinks/file";
37
+ *
38
+ * const sink = fileSink({ path: (batch) => `./audit-archive/${batch.tenant}.jsonl` });
39
+ * ```
40
+ */
41
+ function fileSink(options) {
42
+ const fsync = options.fsync ?? true;
43
+ return {
44
+ kind: "file",
45
+ async send(batch) {
46
+ if (batch.items.length === 0) return;
47
+ await appendDurable(typeof options.path === "function" ? options.path(batch) : options.path, batch.items.map((item) => JSON.stringify(item) + "\n").join(""), fsync);
48
+ }
49
+ };
50
+ }
51
+ /**
52
+ * A {@link RecorderFallback} that appends batches the recorder could not
53
+ * persist to a JSONL file.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { createRecorder } from "@xtandard/audit";
58
+ * import { fileFallback } from "@xtandard/audit/sinks/file";
59
+ *
60
+ * const recorder = createRecorder(audit, {
61
+ * fallback: fileFallback("/var/lib/app/audit-fallback.jsonl"),
62
+ * onError: (err, batch) => logger.error({ err, parked: batch.length }, "audit storage down"),
63
+ * });
64
+ * ```
65
+ */
66
+ function fileFallback(path, options = {}) {
67
+ const fsync = options.fsync ?? true;
68
+ return { async write(inputs, error) {
69
+ const at = (/* @__PURE__ */ new Date()).toISOString();
70
+ const message = error instanceof Error ? error.message : String(error);
71
+ await appendDurable(path, inputs.map((input) => JSON.stringify({
72
+ at,
73
+ error: message,
74
+ input
75
+ }) + "\n").join(""), fsync);
76
+ } };
77
+ }
78
+ /**
79
+ * Parse a fallback file's content back into record inputs (for replay with
80
+ * `core.recordMany`). Blank lines are skipped.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { readFile } from "node:fs/promises";
85
+ * import { readFallbackLines } from "@xtandard/audit/sinks/file";
86
+ *
87
+ * const lines = readFallbackLines(await readFile(path, "utf8"));
88
+ * await audit.recordMany(lines.map((l) => l.input));
89
+ * ```
90
+ */
91
+ function readFallbackLines(text) {
92
+ return text.split("\n").filter((line) => line.trim() !== "").map((line) => JSON.parse(line));
93
+ }
94
+ //#endregion
95
+ export { fileFallback, fileSink, readFallbackLines };
96
+
97
+ //# sourceMappingURL=entry-sinks-file.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-sinks-file.mjs","names":[],"sources":["../src/sinks/file.ts"],"sourcesContent":["/**\n * File sink + recorder fallback, both appending JSON Lines with `node:fs`\n * (Bun and Node):\n *\n * - `fileSink({ path })` — a stream sink: appends one `StreamItem` per line\n * (`{ \"kind\": \"event\", \"event\": … }` / `{ \"kind\": \"checkpoint\", … }`);\n * `path` may depend on the batch (per-tenant files).\n * - `fileFallback(path)` — a `RecorderFallback` for the buffered recorder\n * (ADR 0002): when storage keeps failing, the batch is appended as\n * `{ \"at\", \"error\", \"input\" }` lines so nothing is lost; replay them later\n * with `core.recordMany(lines.map((l) => l.input))`.\n *\n * Both `fsync` by default — the write is durable before the promise resolves.\n *\n * @module\n */\n\nimport { mkdir, open } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { RecordInput } from \"../core.ts\";\nimport type { RecorderFallback } from \"../recorder.ts\";\nimport type { AuditSink, StreamBatch } from \"../streams.ts\";\n\n/** Options for {@link fileSink}. */\nexport interface FileSinkOptions {\n /** File to append to, or a function of the batch (e.g. one file per tenant). */\n path: string | ((batch: StreamBatch) => string);\n /** `fsync` after each append. Default `true`. */\n fsync?: boolean;\n}\n\n/** Options for {@link fileFallback}. */\nexport interface FileFallbackOptions {\n /** `fsync` after each append. Default `true`. */\n fsync?: boolean;\n}\n\n/** Append text to a file (creating parent directories), optionally fsync'd. */\nasync function appendDurable(path: string, text: string, fsync: boolean): Promise<void> {\n await mkdir(dirname(path), { recursive: true });\n const handle = await open(path, \"a\");\n try {\n await handle.appendFile(text, \"utf8\");\n if (fsync) await handle.sync();\n } finally {\n await handle.close();\n }\n}\n\n/**\n * Create a JSONL file sink.\n *\n * @example\n * ```ts\n * import { fileSink } from \"@xtandard/audit/sinks/file\";\n *\n * const sink = fileSink({ path: (batch) => `./audit-archive/${batch.tenant}.jsonl` });\n * ```\n */\nexport function fileSink(options: FileSinkOptions): AuditSink {\n const fsync = options.fsync ?? true;\n return {\n kind: \"file\",\n async send(batch) {\n if (batch.items.length === 0) return;\n const path = typeof options.path === \"function\" ? options.path(batch) : options.path;\n const text = batch.items.map((item) => JSON.stringify(item) + \"\\n\").join(\"\");\n await appendDurable(path, text, fsync);\n },\n };\n}\n\n/** One line written by {@link fileFallback}. */\nexport interface FallbackLine {\n /** ISO-8601 time the batch was parked. */\n at: string;\n /** The storage error message. */\n error: string;\n /** The original record input (ambient context already resolved). */\n input: RecordInput;\n}\n\n/**\n * A {@link RecorderFallback} that appends batches the recorder could not\n * persist to a JSONL file.\n *\n * @example\n * ```ts\n * import { createRecorder } from \"@xtandard/audit\";\n * import { fileFallback } from \"@xtandard/audit/sinks/file\";\n *\n * const recorder = createRecorder(audit, {\n * fallback: fileFallback(\"/var/lib/app/audit-fallback.jsonl\"),\n * onError: (err, batch) => logger.error({ err, parked: batch.length }, \"audit storage down\"),\n * });\n * ```\n */\nexport function fileFallback(path: string, options: FileFallbackOptions = {}): RecorderFallback {\n const fsync = options.fsync ?? true;\n return {\n async write(inputs, error) {\n const at = new Date().toISOString();\n const message = error instanceof Error ? error.message : String(error);\n const text = inputs\n .map((input) => JSON.stringify({ at, error: message, input } satisfies FallbackLine) + \"\\n\")\n .join(\"\");\n await appendDurable(path, text, fsync);\n },\n };\n}\n\n/**\n * Parse a fallback file's content back into record inputs (for replay with\n * `core.recordMany`). Blank lines are skipped.\n *\n * @example\n * ```ts\n * import { readFile } from \"node:fs/promises\";\n * import { readFallbackLines } from \"@xtandard/audit/sinks/file\";\n *\n * const lines = readFallbackLines(await readFile(path, \"utf8\"));\n * await audit.recordMany(lines.map((l) => l.input));\n * ```\n */\nexport function readFallbackLines(text: string): FallbackLine[] {\n return text\n .split(\"\\n\")\n .filter((line) => line.trim() !== \"\")\n .map((line) => JSON.parse(line) as FallbackLine);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsCA,eAAe,cAAc,MAAc,MAAc,OAA+B;CACtF,MAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC9C,MAAM,SAAS,MAAM,KAAK,MAAM,GAAG;CACnC,IAAI;EACF,MAAM,OAAO,WAAW,MAAM,MAAM;EACpC,IAAI,OAAO,MAAM,OAAO,KAAK;CAC/B,UAAU;EACR,MAAM,OAAO,MAAM;CACrB;AACF;;;;;;;;;;;AAYA,SAAgB,SAAS,SAAqC;CAC5D,MAAM,QAAQ,QAAQ,SAAS;CAC/B,OAAO;EACL,MAAM;EACN,MAAM,KAAK,OAAO;GAChB,IAAI,MAAM,MAAM,WAAW,GAAG;GAG9B,MAAM,cAFO,OAAO,QAAQ,SAAS,aAAa,QAAQ,KAAK,KAAK,IAAI,QAAQ,MACnE,MAAM,MAAM,KAAK,SAAS,KAAK,UAAU,IAAI,IAAI,IAAI,EAAE,KAAK,EAC5C,GAAG,KAAK;EACvC;CACF;AACF;;;;;;;;;;;;;;;;AA2BA,SAAgB,aAAa,MAAc,UAA+B,CAAC,GAAqB;CAC9F,MAAM,QAAQ,QAAQ,SAAS;CAC/B,OAAO,EACL,MAAM,MAAM,QAAQ,OAAO;EACzB,MAAM,sBAAK,IAAI,KAAK,GAAE,YAAY;EAClC,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAIrE,MAAM,cAAc,MAHP,OACV,KAAK,UAAU,KAAK,UAAU;GAAE;GAAI,OAAO;GAAS;EAAM,CAAwB,IAAI,IAAI,EAC1F,KAAK,EACqB,GAAG,KAAK;CACvC,EACF;AACF;;;;;;;;;;;;;;AAeA,SAAgB,kBAAkB,MAA8B;CAC9D,OAAO,KACJ,MAAM,IAAI,EACV,QAAQ,SAAS,KAAK,KAAK,MAAM,EAAE,EACnC,KAAK,SAAS,KAAK,MAAM,IAAI,CAAiB;AACnD"}
@@ -0,0 +1,63 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_shared = require("./shared-OOAq-U4S.cjs");
3
+ //#region src/sinks/http.ts
4
+ /** Serialize a batch for {@link httpSink}. */
5
+ function encodeHttpBatch(batch, format = "json") {
6
+ if (format === "ndjson") return batch.items.map((item) => JSON.stringify(item)).join("\n") + "\n";
7
+ return JSON.stringify({
8
+ stream: batch.stream,
9
+ tenant: batch.tenant,
10
+ items: batch.items
11
+ });
12
+ }
13
+ /**
14
+ * Create a generic HTTP sink.
15
+ *
16
+ * Delivery is at-least-once: a batch can arrive again after a timeout or a
17
+ * crash between the 2xx and the cursor write. Receivers dedupe on
18
+ * `item.event.id` / `item.checkpoint.id`.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { createStreamRunner } from "@xtandard/audit";
23
+ * import { httpSink } from "@xtandard/audit/sinks/http";
24
+ *
25
+ * createStreamRunner(audit, {
26
+ * streams: [
27
+ * {
28
+ * name: "siem",
29
+ * sink: httpSink({
30
+ * url: "https://siem.example.com/ingest",
31
+ * headers: { authorization: `Bearer ${process.env.SIEM_TOKEN}` },
32
+ * format: "ndjson",
33
+ * }),
34
+ * },
35
+ * ],
36
+ * }).start();
37
+ * ```
38
+ */
39
+ function httpSink(options) {
40
+ const format = options.format ?? "json";
41
+ if (format !== "json" && format !== "ndjson") throw new TypeError(`httpSink: unknown format "${String(format)}"`);
42
+ const contentType = format === "json" ? "application/json" : "application/x-ndjson";
43
+ return {
44
+ kind: "http",
45
+ async send(batch) {
46
+ if (batch.items.length === 0) return;
47
+ await require_shared.sendRequest("http", options.url, {
48
+ method: options.method ?? "POST",
49
+ headers: {
50
+ "content-type": contentType,
51
+ ...await require_shared.resolveHeaders(options.headers, batch)
52
+ },
53
+ body: encodeHttpBatch(batch, format)
54
+ }, options);
55
+ }
56
+ };
57
+ }
58
+ //#endregion
59
+ exports.SinkHttpError = require_shared.SinkHttpError;
60
+ exports.encodeHttpBatch = encodeHttpBatch;
61
+ exports.httpSink = httpSink;
62
+
63
+ //# sourceMappingURL=entry-sinks-http.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-sinks-http.cjs","names":["sendRequest","resolveHeaders"],"sources":["../src/sinks/http.ts"],"sourcesContent":["/**\n * Generic HTTP sink: POSTs each stream batch to a URL, as one JSON document\n * (`{ stream, tenant, items }`) or as NDJSON (one item per line). Any non-2xx\n * answer throws, so the stream runner keeps the cursor and backs off\n * (ADR 0008). Zero dependencies — uses the runtime's `fetch`.\n *\n * @module\n */\n\nimport type { AuditSink, StreamBatch } from \"../streams.ts\";\nimport { sendRequest, resolveHeaders, type SinkFetch, type SinkHeaders } from \"./shared.ts\";\n\nexport { SinkHttpError, type SinkFetch, type SinkHeaders } from \"./shared.ts\";\n\n/** Options for {@link httpSink}. */\nexport interface HttpSinkOptions {\n /** Destination URL. */\n url: string;\n /** Extra headers (auth tokens…), static or resolved per batch. */\n headers?: SinkHeaders;\n /**\n * Body format:\n * - `\"json\"` (default) — `{ \"stream\", \"tenant\", \"items\": [...] }`, `application/json`;\n * - `\"ndjson\"` — one `StreamItem` JSON object per line, `application/x-ndjson`.\n */\n format?: \"json\" | \"ndjson\";\n /** HTTP method. Default `\"POST\"`. */\n method?: \"POST\" | \"PUT\";\n /** Request timeout. Default 10 000 ms. */\n timeoutMs?: number;\n /** Custom `fetch` (tests, proxies). Default `globalThis.fetch`. */\n fetch?: SinkFetch;\n}\n\n/** Serialize a batch for {@link httpSink}. */\nexport function encodeHttpBatch(batch: StreamBatch, format: \"json\" | \"ndjson\" = \"json\"): string {\n if (format === \"ndjson\") return batch.items.map((item) => JSON.stringify(item)).join(\"\\n\") + \"\\n\";\n return JSON.stringify({ stream: batch.stream, tenant: batch.tenant, items: batch.items });\n}\n\n/**\n * Create a generic HTTP sink.\n *\n * Delivery is at-least-once: a batch can arrive again after a timeout or a\n * crash between the 2xx and the cursor write. Receivers dedupe on\n * `item.event.id` / `item.checkpoint.id`.\n *\n * @example\n * ```ts\n * import { createStreamRunner } from \"@xtandard/audit\";\n * import { httpSink } from \"@xtandard/audit/sinks/http\";\n *\n * createStreamRunner(audit, {\n * streams: [\n * {\n * name: \"siem\",\n * sink: httpSink({\n * url: \"https://siem.example.com/ingest\",\n * headers: { authorization: `Bearer ${process.env.SIEM_TOKEN}` },\n * format: \"ndjson\",\n * }),\n * },\n * ],\n * }).start();\n * ```\n */\nexport function httpSink(options: HttpSinkOptions): AuditSink {\n const format = options.format ?? \"json\";\n if (format !== \"json\" && format !== \"ndjson\") {\n throw new TypeError(`httpSink: unknown format \"${String(format)}\"`);\n }\n const contentType = format === \"json\" ? \"application/json\" : \"application/x-ndjson\";\n return {\n kind: \"http\",\n async send(batch) {\n if (batch.items.length === 0) return;\n await sendRequest(\n \"http\",\n options.url,\n {\n method: options.method ?? \"POST\",\n headers: {\n \"content-type\": contentType,\n ...(await resolveHeaders(options.headers, batch)),\n },\n body: encodeHttpBatch(batch, format),\n },\n options,\n );\n },\n };\n}\n"],"mappings":";;;;AAmCA,SAAgB,gBAAgB,OAAoB,SAA4B,QAAgB;CAC9F,IAAI,WAAW,UAAU,OAAO,MAAM,MAAM,KAAK,SAAS,KAAK,UAAU,IAAI,CAAC,EAAE,KAAK,IAAI,IAAI;CAC7F,OAAO,KAAK,UAAU;EAAE,QAAQ,MAAM;EAAQ,QAAQ,MAAM;EAAQ,OAAO,MAAM;CAAM,CAAC;AAC1F;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,SAAS,SAAqC;CAC5D,MAAM,SAAS,QAAQ,UAAU;CACjC,IAAI,WAAW,UAAU,WAAW,UAClC,MAAM,IAAI,UAAU,6BAA6B,OAAO,MAAM,EAAE,EAAE;CAEpE,MAAM,cAAc,WAAW,SAAS,qBAAqB;CAC7D,OAAO;EACL,MAAM;EACN,MAAM,KAAK,OAAO;GAChB,IAAI,MAAM,MAAM,WAAW,GAAG;GAC9B,MAAMA,eAAAA,YACJ,QACA,QAAQ,KACR;IACE,QAAQ,QAAQ,UAAU;IAC1B,SAAS;KACP,gBAAgB;KAChB,GAAI,MAAMC,eAAAA,eAAe,QAAQ,SAAS,KAAK;IACjD;IACA,MAAM,gBAAgB,OAAO,MAAM;GACrC,GACA,OACF;EACF;CACF;AACF"}
@@ -0,0 +1,55 @@
1
+ import { n as StreamBatch, t as AuditSink } from "./streams-CRuxOYcb.cjs";
2
+ import { n as SinkHeaders, r as SinkHttpError, t as SinkFetch } from "./shared-EANCdRqn.cjs";
3
+
4
+ //#region src/sinks/http.d.ts
5
+ /** Options for {@link httpSink}. */
6
+ interface HttpSinkOptions {
7
+ /** Destination URL. */
8
+ url: string;
9
+ /** Extra headers (auth tokens…), static or resolved per batch. */
10
+ headers?: SinkHeaders;
11
+ /**
12
+ * Body format:
13
+ * - `"json"` (default) — `{ "stream", "tenant", "items": [...] }`, `application/json`;
14
+ * - `"ndjson"` — one `StreamItem` JSON object per line, `application/x-ndjson`.
15
+ */
16
+ format?: "json" | "ndjson";
17
+ /** HTTP method. Default `"POST"`. */
18
+ method?: "POST" | "PUT";
19
+ /** Request timeout. Default 10 000 ms. */
20
+ timeoutMs?: number;
21
+ /** Custom `fetch` (tests, proxies). Default `globalThis.fetch`. */
22
+ fetch?: SinkFetch;
23
+ }
24
+ /** Serialize a batch for {@link httpSink}. */
25
+ declare function encodeHttpBatch(batch: StreamBatch, format?: "json" | "ndjson"): string;
26
+ /**
27
+ * Create a generic HTTP sink.
28
+ *
29
+ * Delivery is at-least-once: a batch can arrive again after a timeout or a
30
+ * crash between the 2xx and the cursor write. Receivers dedupe on
31
+ * `item.event.id` / `item.checkpoint.id`.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { createStreamRunner } from "@xtandard/audit";
36
+ * import { httpSink } from "@xtandard/audit/sinks/http";
37
+ *
38
+ * createStreamRunner(audit, {
39
+ * streams: [
40
+ * {
41
+ * name: "siem",
42
+ * sink: httpSink({
43
+ * url: "https://siem.example.com/ingest",
44
+ * headers: { authorization: `Bearer ${process.env.SIEM_TOKEN}` },
45
+ * format: "ndjson",
46
+ * }),
47
+ * },
48
+ * ],
49
+ * }).start();
50
+ * ```
51
+ */
52
+ declare function httpSink(options: HttpSinkOptions): AuditSink;
53
+ //#endregion
54
+ export { HttpSinkOptions, type SinkFetch, type SinkHeaders, SinkHttpError, encodeHttpBatch, httpSink };
55
+ //# sourceMappingURL=entry-sinks-http.d.cts.map
@@ -0,0 +1,55 @@
1
+ import { n as StreamBatch, t as AuditSink } from "./streams-DU0_gvI8.mjs";
2
+ import { n as SinkHeaders, r as SinkHttpError, t as SinkFetch } from "./shared-CJOyJKqT.mjs";
3
+
4
+ //#region src/sinks/http.d.ts
5
+ /** Options for {@link httpSink}. */
6
+ interface HttpSinkOptions {
7
+ /** Destination URL. */
8
+ url: string;
9
+ /** Extra headers (auth tokens…), static or resolved per batch. */
10
+ headers?: SinkHeaders;
11
+ /**
12
+ * Body format:
13
+ * - `"json"` (default) — `{ "stream", "tenant", "items": [...] }`, `application/json`;
14
+ * - `"ndjson"` — one `StreamItem` JSON object per line, `application/x-ndjson`.
15
+ */
16
+ format?: "json" | "ndjson";
17
+ /** HTTP method. Default `"POST"`. */
18
+ method?: "POST" | "PUT";
19
+ /** Request timeout. Default 10 000 ms. */
20
+ timeoutMs?: number;
21
+ /** Custom `fetch` (tests, proxies). Default `globalThis.fetch`. */
22
+ fetch?: SinkFetch;
23
+ }
24
+ /** Serialize a batch for {@link httpSink}. */
25
+ declare function encodeHttpBatch(batch: StreamBatch, format?: "json" | "ndjson"): string;
26
+ /**
27
+ * Create a generic HTTP sink.
28
+ *
29
+ * Delivery is at-least-once: a batch can arrive again after a timeout or a
30
+ * crash between the 2xx and the cursor write. Receivers dedupe on
31
+ * `item.event.id` / `item.checkpoint.id`.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { createStreamRunner } from "@xtandard/audit";
36
+ * import { httpSink } from "@xtandard/audit/sinks/http";
37
+ *
38
+ * createStreamRunner(audit, {
39
+ * streams: [
40
+ * {
41
+ * name: "siem",
42
+ * sink: httpSink({
43
+ * url: "https://siem.example.com/ingest",
44
+ * headers: { authorization: `Bearer ${process.env.SIEM_TOKEN}` },
45
+ * format: "ndjson",
46
+ * }),
47
+ * },
48
+ * ],
49
+ * }).start();
50
+ * ```
51
+ */
52
+ declare function httpSink(options: HttpSinkOptions): AuditSink;
53
+ //#endregion
54
+ export { HttpSinkOptions, type SinkFetch, type SinkHeaders, SinkHttpError, encodeHttpBatch, httpSink };
55
+ //# sourceMappingURL=entry-sinks-http.d.mts.map
@@ -0,0 +1,60 @@
1
+ import { o as resolveHeaders, s as sendRequest, t as SinkHttpError } from "./shared-DSDY-V0n.mjs";
2
+ //#region src/sinks/http.ts
3
+ /** Serialize a batch for {@link httpSink}. */
4
+ function encodeHttpBatch(batch, format = "json") {
5
+ if (format === "ndjson") return batch.items.map((item) => JSON.stringify(item)).join("\n") + "\n";
6
+ return JSON.stringify({
7
+ stream: batch.stream,
8
+ tenant: batch.tenant,
9
+ items: batch.items
10
+ });
11
+ }
12
+ /**
13
+ * Create a generic HTTP sink.
14
+ *
15
+ * Delivery is at-least-once: a batch can arrive again after a timeout or a
16
+ * crash between the 2xx and the cursor write. Receivers dedupe on
17
+ * `item.event.id` / `item.checkpoint.id`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { createStreamRunner } from "@xtandard/audit";
22
+ * import { httpSink } from "@xtandard/audit/sinks/http";
23
+ *
24
+ * createStreamRunner(audit, {
25
+ * streams: [
26
+ * {
27
+ * name: "siem",
28
+ * sink: httpSink({
29
+ * url: "https://siem.example.com/ingest",
30
+ * headers: { authorization: `Bearer ${process.env.SIEM_TOKEN}` },
31
+ * format: "ndjson",
32
+ * }),
33
+ * },
34
+ * ],
35
+ * }).start();
36
+ * ```
37
+ */
38
+ function httpSink(options) {
39
+ const format = options.format ?? "json";
40
+ if (format !== "json" && format !== "ndjson") throw new TypeError(`httpSink: unknown format "${String(format)}"`);
41
+ const contentType = format === "json" ? "application/json" : "application/x-ndjson";
42
+ return {
43
+ kind: "http",
44
+ async send(batch) {
45
+ if (batch.items.length === 0) return;
46
+ await sendRequest("http", options.url, {
47
+ method: options.method ?? "POST",
48
+ headers: {
49
+ "content-type": contentType,
50
+ ...await resolveHeaders(options.headers, batch)
51
+ },
52
+ body: encodeHttpBatch(batch, format)
53
+ }, options);
54
+ }
55
+ };
56
+ }
57
+ //#endregion
58
+ export { SinkHttpError, encodeHttpBatch, httpSink };
59
+
60
+ //# sourceMappingURL=entry-sinks-http.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-sinks-http.mjs","names":[],"sources":["../src/sinks/http.ts"],"sourcesContent":["/**\n * Generic HTTP sink: POSTs each stream batch to a URL, as one JSON document\n * (`{ stream, tenant, items }`) or as NDJSON (one item per line). Any non-2xx\n * answer throws, so the stream runner keeps the cursor and backs off\n * (ADR 0008). Zero dependencies — uses the runtime's `fetch`.\n *\n * @module\n */\n\nimport type { AuditSink, StreamBatch } from \"../streams.ts\";\nimport { sendRequest, resolveHeaders, type SinkFetch, type SinkHeaders } from \"./shared.ts\";\n\nexport { SinkHttpError, type SinkFetch, type SinkHeaders } from \"./shared.ts\";\n\n/** Options for {@link httpSink}. */\nexport interface HttpSinkOptions {\n /** Destination URL. */\n url: string;\n /** Extra headers (auth tokens…), static or resolved per batch. */\n headers?: SinkHeaders;\n /**\n * Body format:\n * - `\"json\"` (default) — `{ \"stream\", \"tenant\", \"items\": [...] }`, `application/json`;\n * - `\"ndjson\"` — one `StreamItem` JSON object per line, `application/x-ndjson`.\n */\n format?: \"json\" | \"ndjson\";\n /** HTTP method. Default `\"POST\"`. */\n method?: \"POST\" | \"PUT\";\n /** Request timeout. Default 10 000 ms. */\n timeoutMs?: number;\n /** Custom `fetch` (tests, proxies). Default `globalThis.fetch`. */\n fetch?: SinkFetch;\n}\n\n/** Serialize a batch for {@link httpSink}. */\nexport function encodeHttpBatch(batch: StreamBatch, format: \"json\" | \"ndjson\" = \"json\"): string {\n if (format === \"ndjson\") return batch.items.map((item) => JSON.stringify(item)).join(\"\\n\") + \"\\n\";\n return JSON.stringify({ stream: batch.stream, tenant: batch.tenant, items: batch.items });\n}\n\n/**\n * Create a generic HTTP sink.\n *\n * Delivery is at-least-once: a batch can arrive again after a timeout or a\n * crash between the 2xx and the cursor write. Receivers dedupe on\n * `item.event.id` / `item.checkpoint.id`.\n *\n * @example\n * ```ts\n * import { createStreamRunner } from \"@xtandard/audit\";\n * import { httpSink } from \"@xtandard/audit/sinks/http\";\n *\n * createStreamRunner(audit, {\n * streams: [\n * {\n * name: \"siem\",\n * sink: httpSink({\n * url: \"https://siem.example.com/ingest\",\n * headers: { authorization: `Bearer ${process.env.SIEM_TOKEN}` },\n * format: \"ndjson\",\n * }),\n * },\n * ],\n * }).start();\n * ```\n */\nexport function httpSink(options: HttpSinkOptions): AuditSink {\n const format = options.format ?? \"json\";\n if (format !== \"json\" && format !== \"ndjson\") {\n throw new TypeError(`httpSink: unknown format \"${String(format)}\"`);\n }\n const contentType = format === \"json\" ? \"application/json\" : \"application/x-ndjson\";\n return {\n kind: \"http\",\n async send(batch) {\n if (batch.items.length === 0) return;\n await sendRequest(\n \"http\",\n options.url,\n {\n method: options.method ?? \"POST\",\n headers: {\n \"content-type\": contentType,\n ...(await resolveHeaders(options.headers, batch)),\n },\n body: encodeHttpBatch(batch, format),\n },\n options,\n );\n },\n };\n}\n"],"mappings":";;;AAmCA,SAAgB,gBAAgB,OAAoB,SAA4B,QAAgB;CAC9F,IAAI,WAAW,UAAU,OAAO,MAAM,MAAM,KAAK,SAAS,KAAK,UAAU,IAAI,CAAC,EAAE,KAAK,IAAI,IAAI;CAC7F,OAAO,KAAK,UAAU;EAAE,QAAQ,MAAM;EAAQ,QAAQ,MAAM;EAAQ,OAAO,MAAM;CAAM,CAAC;AAC1F;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,SAAS,SAAqC;CAC5D,MAAM,SAAS,QAAQ,UAAU;CACjC,IAAI,WAAW,UAAU,WAAW,UAClC,MAAM,IAAI,UAAU,6BAA6B,OAAO,MAAM,EAAE,EAAE;CAEpE,MAAM,cAAc,WAAW,SAAS,qBAAqB;CAC7D,OAAO;EACL,MAAM;EACN,MAAM,KAAK,OAAO;GAChB,IAAI,MAAM,MAAM,WAAW,GAAG;GAC9B,MAAM,YACJ,QACA,QAAQ,KACR;IACE,QAAQ,QAAQ,UAAU;IAC1B,SAAS;KACP,gBAAgB;KAChB,GAAI,MAAM,eAAe,QAAQ,SAAS,KAAK;IACjD;IACA,MAAM,gBAAgB,OAAO,MAAM;GACrC,GACA,OACF;EACF;CACF;AACF"}
@@ -0,0 +1,115 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_contract = require("./contract-DYvBNdnR.cjs");
3
+ const require_shared = require("./shared-OOAq-U4S.cjs");
4
+ //#region src/sinks/s3.ts
5
+ const pad = (n) => String(n).padStart(12, "0");
6
+ const encodeKey = (key) => key.split("/").map(encodeURIComponent).join("/");
7
+ /**
8
+ * The object keys a batch is written to (exported for tooling and tests).
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * s3ObjectKeys(batch, "audit/");
13
+ * // { events: "audit/acme/2026/11/20/000000000001-000000000100.jsonl",
14
+ * // checkpoints: ["audit/acme/checkpoints/chk_01J….json"] }
15
+ * ```
16
+ */
17
+ function s3ObjectKeys(batch, prefix = "") {
18
+ const events = batch.items.flatMap((i) => i.kind === "event" ? [i.event] : []);
19
+ let eventsKey = null;
20
+ if (events.length > 0) {
21
+ const first = events[0];
22
+ const last = events[events.length - 1];
23
+ const d = new Date(first.recordedAt);
24
+ const yyyy = String(d.getUTCFullYear());
25
+ const mm = String(d.getUTCMonth() + 1).padStart(2, "0");
26
+ const dd = String(d.getUTCDate()).padStart(2, "0");
27
+ eventsKey = `${prefix}${batch.tenant}/${yyyy}/${mm}/${dd}/${pad(first.seq)}-${pad(last.seq)}.jsonl`;
28
+ }
29
+ const checkpoints = batch.items.flatMap((i) => i.kind === "checkpoint" ? [`${prefix}${batch.tenant}/checkpoints/${i.checkpoint.id}.json`] : []);
30
+ return {
31
+ events: eventsKey,
32
+ checkpoints
33
+ };
34
+ }
35
+ /**
36
+ * Create an S3-compatible archive sink.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { s3Sink } from "@xtandard/audit/sinks/s3";
41
+ *
42
+ * // Cloudflare R2
43
+ * const sink = s3Sink({
44
+ * bucket: "audit-archive",
45
+ * prefix: "prod/",
46
+ * endpoint: `https://${ACCOUNT_ID}.r2.cloudflarestorage.com`,
47
+ * accessKeyId: process.env.R2_ACCESS_KEY_ID!,
48
+ * secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
49
+ * });
50
+ *
51
+ * // or a prebuilt client
52
+ * import { AwsClient } from "aws4fetch";
53
+ * const sink2 = s3Sink({ bucket: "audit", region: "eu-west-1", client: new AwsClient({ … }) });
54
+ * ```
55
+ */
56
+ function s3Sink(options) {
57
+ if (!options.bucket) throw new TypeError("s3Sink: bucket is required");
58
+ if (!options.client && !(options.accessKeyId && options.secretAccessKey)) throw new TypeError("s3Sink: pass a client, or accessKeyId + secretAccessKey");
59
+ const region = options.region ?? (options.endpoint ? "auto" : "us-east-1");
60
+ const pathStyle = options.pathStyle ?? options.endpoint !== void 0;
61
+ const base = new URL(options.endpoint ?? `https://s3.${region}.amazonaws.com`);
62
+ const origin = pathStyle ? `${base.origin}${base.pathname.replace(/\/+$/, "")}/${encodeURIComponent(options.bucket)}` : `${base.protocol}//${options.bucket}.${base.host}${base.pathname.replace(/\/+$/, "")}`;
63
+ const prefix = options.prefix ?? "";
64
+ let client = options.client ? Promise.resolve(options.client) : null;
65
+ function getClient() {
66
+ client ??= import("aws4fetch").then(({ AwsClient }) => new AwsClient({
67
+ accessKeyId: options.accessKeyId,
68
+ secretAccessKey: options.secretAccessKey,
69
+ ...options.sessionToken ? { sessionToken: options.sessionToken } : {},
70
+ service: "s3",
71
+ region
72
+ }), () => require_contract.requirePeer("aws4fetch", "sinks/s3"));
73
+ return client;
74
+ }
75
+ async function put(key, body, contentType) {
76
+ const c = await getClient();
77
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(body));
78
+ const sha256 = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
79
+ await require_shared.sendRequest("s3", `${origin}/${encodeKey(key)}`, {
80
+ method: "PUT",
81
+ headers: {
82
+ "content-type": contentType,
83
+ "x-amz-content-sha256": sha256
84
+ },
85
+ body
86
+ }, {
87
+ fetch: (input, init) => c.fetch(String(input), init),
88
+ timeoutMs: options.timeoutMs ?? 3e4
89
+ });
90
+ }
91
+ return {
92
+ kind: "s3",
93
+ async send(batch) {
94
+ if (batch.items.length === 0) return;
95
+ const keys = s3ObjectKeys(batch, prefix);
96
+ if (keys.events) {
97
+ const lines = batch.items.flatMap((i) => i.kind === "event" ? [JSON.stringify(i.event)] : []);
98
+ await put(keys.events, lines.join("\n") + "\n", "application/x-ndjson");
99
+ }
100
+ if (options.checkpoints ?? true) {
101
+ let n = 0;
102
+ for (const item of batch.items) {
103
+ if (item.kind !== "checkpoint") continue;
104
+ await put(keys.checkpoints[n++], JSON.stringify(item.checkpoint), "application/json");
105
+ }
106
+ }
107
+ }
108
+ };
109
+ }
110
+ //#endregion
111
+ exports.SinkHttpError = require_shared.SinkHttpError;
112
+ exports.s3ObjectKeys = s3ObjectKeys;
113
+ exports.s3Sink = s3Sink;
114
+
115
+ //# sourceMappingURL=entry-sinks-s3.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-sinks-s3.cjs","names":["requirePeer","sendRequest"],"sources":["../src/sinks/s3.ts"],"sourcesContent":["/**\n * S3-compatible object-store sink (AWS S3, Cloudflare R2, MinIO, Backblaze B2,\n * …): archives each batch as one JSONL object at an **idempotent** key, plus\n * one JSON object per signed checkpoint (witness copies, ADR 0004).\n *\n * ```txt\n * {prefix}{tenant}/{yyyy}/{mm}/{dd}/{firstSeq}-{lastSeq}.jsonl one event per line\n * {prefix}{tenant}/checkpoints/{checkpoint id}.json one per checkpoint\n * ```\n *\n * Seqs are zero-padded to 12 digits so a listing sorts in chain order; the\n * date is the first event's `recordedAt` (UTC), which grows with `seq`. A\n * re-sent batch overwrites the same key with the same content.\n *\n * Requests are signed with SigV4 by the optional peer\n * [`aws4fetch`](https://github.com/mhart/aws4fetch) (`bun add aws4fetch`), or\n * by any client you pass with a compatible `fetch` method.\n *\n * @module\n */\n\nimport type { AuditSink, StreamBatch } from \"../streams.ts\";\nimport { requirePeer } from \"../storage/contract.ts\";\nimport { sendRequest } from \"./shared.ts\";\n\nexport { SinkHttpError } from \"./shared.ts\";\n\n/** A SigV4-signing client: `aws4fetch`'s `AwsClient` or anything with the same `fetch`. */\nexport interface S3Client {\n fetch(input: string, init?: RequestInit): Promise<Response>;\n}\n\n/** Options for {@link s3Sink}. */\nexport interface S3SinkOptions {\n /** Bucket name. */\n bucket: string;\n /** Key prefix, e.g. `\"audit/\"`. Default `\"\"`. */\n prefix?: string;\n /** A prebuilt signing client (e.g. `new AwsClient({ … })`). Otherwise pass credentials. */\n client?: S3Client;\n /** Access key id (with `secretAccessKey`; ignored when `client` is given). */\n accessKeyId?: string;\n secretAccessKey?: string;\n sessionToken?: string;\n /**\n * Region. Default `\"us-east-1\"` for AWS, `\"auto\"` when `endpoint` is set\n * (R2 expects `\"auto\"`).\n */\n region?: string;\n /**\n * Endpoint for S3-compatible stores, e.g. `https://<account>.r2.cloudflarestorage.com`\n * or `http://localhost:9000` (MinIO). Default: AWS (`https://s3.<region>.amazonaws.com`).\n */\n endpoint?: string;\n /**\n * Path-style URLs (`{endpoint}/{bucket}/{key}`) instead of virtual-hosted\n * (`{bucket}.{host}/{key}`). Default `true` with `endpoint`, `false` for AWS.\n */\n pathStyle?: boolean;\n /** Upload checkpoints too (default `true`). */\n checkpoints?: boolean;\n /** Request timeout. Default 30 000 ms. */\n timeoutMs?: number;\n}\n\nconst pad = (n: number) => String(n).padStart(12, \"0\");\nconst encodeKey = (key: string) => key.split(\"/\").map(encodeURIComponent).join(\"/\");\n\n/**\n * The object keys a batch is written to (exported for tooling and tests).\n *\n * @example\n * ```ts\n * s3ObjectKeys(batch, \"audit/\");\n * // { events: \"audit/acme/2026/11/20/000000000001-000000000100.jsonl\",\n * // checkpoints: [\"audit/acme/checkpoints/chk_01J….json\"] }\n * ```\n */\nexport function s3ObjectKeys(\n batch: StreamBatch,\n prefix = \"\",\n): { events: string | null; checkpoints: string[] } {\n const events = batch.items.flatMap((i) => (i.kind === \"event\" ? [i.event] : []));\n let eventsKey: string | null = null;\n if (events.length > 0) {\n const first = events[0]!;\n const last = events[events.length - 1]!;\n const d = new Date(first.recordedAt);\n const yyyy = String(d.getUTCFullYear());\n const mm = String(d.getUTCMonth() + 1).padStart(2, \"0\");\n const dd = String(d.getUTCDate()).padStart(2, \"0\");\n eventsKey = `${prefix}${batch.tenant}/${yyyy}/${mm}/${dd}/${pad(first.seq)}-${pad(last.seq)}.jsonl`;\n }\n const checkpoints = batch.items.flatMap((i) =>\n i.kind === \"checkpoint\" ? [`${prefix}${batch.tenant}/checkpoints/${i.checkpoint.id}.json`] : [],\n );\n return { events: eventsKey, checkpoints };\n}\n\n/**\n * Create an S3-compatible archive sink.\n *\n * @example\n * ```ts\n * import { s3Sink } from \"@xtandard/audit/sinks/s3\";\n *\n * // Cloudflare R2\n * const sink = s3Sink({\n * bucket: \"audit-archive\",\n * prefix: \"prod/\",\n * endpoint: `https://${ACCOUNT_ID}.r2.cloudflarestorage.com`,\n * accessKeyId: process.env.R2_ACCESS_KEY_ID!,\n * secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,\n * });\n *\n * // or a prebuilt client\n * import { AwsClient } from \"aws4fetch\";\n * const sink2 = s3Sink({ bucket: \"audit\", region: \"eu-west-1\", client: new AwsClient({ … }) });\n * ```\n */\nexport function s3Sink(options: S3SinkOptions): AuditSink {\n if (!options.bucket) throw new TypeError(\"s3Sink: bucket is required\");\n if (!options.client && !(options.accessKeyId && options.secretAccessKey)) {\n throw new TypeError(\"s3Sink: pass a client, or accessKeyId + secretAccessKey\");\n }\n const region = options.region ?? (options.endpoint ? \"auto\" : \"us-east-1\");\n const pathStyle = options.pathStyle ?? options.endpoint !== undefined;\n const base = new URL(options.endpoint ?? `https://s3.${region}.amazonaws.com`);\n const origin = pathStyle\n ? `${base.origin}${base.pathname.replace(/\\/+$/, \"\")}/${encodeURIComponent(options.bucket)}`\n : `${base.protocol}//${options.bucket}.${base.host}${base.pathname.replace(/\\/+$/, \"\")}`;\n const prefix = options.prefix ?? \"\";\n\n let client: Promise<S3Client> | null = options.client ? Promise.resolve(options.client) : null;\n function getClient(): Promise<S3Client> {\n client ??= import(\"aws4fetch\").then(\n ({ AwsClient }) =>\n new AwsClient({\n accessKeyId: options.accessKeyId!,\n secretAccessKey: options.secretAccessKey!,\n ...(options.sessionToken ? { sessionToken: options.sessionToken } : {}),\n service: \"s3\",\n region,\n }),\n () => requirePeer(\"aws4fetch\", \"sinks/s3\"),\n );\n return client;\n }\n\n async function put(key: string, body: string, contentType: string): Promise<void> {\n const c = await getClient();\n // Sign the real payload hash (not UNSIGNED-PAYLOAD): S3 rejects a body altered in flight.\n const digest = await crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(body));\n const sha256 = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, \"0\")).join(\n \"\",\n );\n await sendRequest(\n \"s3\",\n `${origin}/${encodeKey(key)}`,\n {\n method: \"PUT\",\n headers: { \"content-type\": contentType, \"x-amz-content-sha256\": sha256 },\n body,\n },\n {\n fetch: (input, init) => c.fetch(String(input), init),\n timeoutMs: options.timeoutMs ?? 30_000,\n },\n );\n }\n\n return {\n kind: \"s3\",\n async send(batch) {\n if (batch.items.length === 0) return;\n const keys = s3ObjectKeys(batch, prefix);\n if (keys.events) {\n const lines = batch.items.flatMap((i) =>\n i.kind === \"event\" ? [JSON.stringify(i.event)] : [],\n );\n await put(keys.events, lines.join(\"\\n\") + \"\\n\", \"application/x-ndjson\");\n }\n if (options.checkpoints ?? true) {\n let n = 0;\n for (const item of batch.items) {\n if (item.kind !== \"checkpoint\") continue;\n await put(keys.checkpoints[n++]!, JSON.stringify(item.checkpoint), \"application/json\");\n }\n }\n },\n };\n}\n"],"mappings":";;;;AAiEA,MAAM,OAAO,MAAc,OAAO,CAAC,EAAE,SAAS,IAAI,GAAG;AACrD,MAAM,aAAa,QAAgB,IAAI,MAAM,GAAG,EAAE,IAAI,kBAAkB,EAAE,KAAK,GAAG;;;;;;;;;;;AAYlF,SAAgB,aACd,OACA,SAAS,IACyC;CAClD,MAAM,SAAS,MAAM,MAAM,SAAS,MAAO,EAAE,SAAS,UAAU,CAAC,EAAE,KAAK,IAAI,CAAC,CAAE;CAC/E,IAAI,YAA2B;CAC/B,IAAI,OAAO,SAAS,GAAG;EACrB,MAAM,QAAQ,OAAO;EACrB,MAAM,OAAO,OAAO,OAAO,SAAS;EACpC,MAAM,IAAI,IAAI,KAAK,MAAM,UAAU;EACnC,MAAM,OAAO,OAAO,EAAE,eAAe,CAAC;EACtC,MAAM,KAAK,OAAO,EAAE,YAAY,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG;EACtD,MAAM,KAAK,OAAO,EAAE,WAAW,CAAC,EAAE,SAAS,GAAG,GAAG;EACjD,YAAY,GAAG,SAAS,MAAM,OAAO,GAAG,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,MAAM,GAAG,EAAE,GAAG,IAAI,KAAK,GAAG,EAAE;CAC9F;CACA,MAAM,cAAc,MAAM,MAAM,SAAS,MACvC,EAAE,SAAS,eAAe,CAAC,GAAG,SAAS,MAAM,OAAO,eAAe,EAAE,WAAW,GAAG,MAAM,IAAI,CAAC,CAChG;CACA,OAAO;EAAE,QAAQ;EAAW;CAAY;AAC1C;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,OAAO,SAAmC;CACxD,IAAI,CAAC,QAAQ,QAAQ,MAAM,IAAI,UAAU,4BAA4B;CACrE,IAAI,CAAC,QAAQ,UAAU,EAAE,QAAQ,eAAe,QAAQ,kBACtD,MAAM,IAAI,UAAU,yDAAyD;CAE/E,MAAM,SAAS,QAAQ,WAAW,QAAQ,WAAW,SAAS;CAC9D,MAAM,YAAY,QAAQ,aAAa,QAAQ,aAAa,KAAA;CAC5D,MAAM,OAAO,IAAI,IAAI,QAAQ,YAAY,cAAc,OAAO,eAAe;CAC7E,MAAM,SAAS,YACX,GAAG,KAAK,SAAS,KAAK,SAAS,QAAQ,QAAQ,EAAE,EAAE,GAAG,mBAAmB,QAAQ,MAAM,MACvF,GAAG,KAAK,SAAS,IAAI,QAAQ,OAAO,GAAG,KAAK,OAAO,KAAK,SAAS,QAAQ,QAAQ,EAAE;CACvF,MAAM,SAAS,QAAQ,UAAU;CAEjC,IAAI,SAAmC,QAAQ,SAAS,QAAQ,QAAQ,QAAQ,MAAM,IAAI;CAC1F,SAAS,YAA+B;EACtC,WAAW,OAAO,aAAa,MAC5B,EAAE,gBACD,IAAI,UAAU;GACZ,aAAa,QAAQ;GACrB,iBAAiB,QAAQ;GACzB,GAAI,QAAQ,eAAe,EAAE,cAAc,QAAQ,aAAa,IAAI,CAAC;GACrE,SAAS;GACT;EACF,CAAC,SACGA,iBAAAA,YAAY,aAAa,UAAU,CAC3C;EACA,OAAO;CACT;CAEA,eAAe,IAAI,KAAa,MAAc,aAAoC;EAChF,MAAM,IAAI,MAAM,UAAU;EAE1B,MAAM,SAAS,MAAM,OAAO,OAAO,OAAO,WAAW,IAAI,YAAY,EAAE,OAAO,IAAI,CAAC;EACnF,MAAM,SAAS,MAAM,KAAK,IAAI,WAAW,MAAM,IAAI,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KACxF,EACF;EACA,MAAMC,eAAAA,YACJ,MACA,GAAG,OAAO,GAAG,UAAU,GAAG,KAC1B;GACE,QAAQ;GACR,SAAS;IAAE,gBAAgB;IAAa,wBAAwB;GAAO;GACvE;EACF,GACA;GACE,QAAQ,OAAO,SAAS,EAAE,MAAM,OAAO,KAAK,GAAG,IAAI;GACnD,WAAW,QAAQ,aAAa;EAClC,CACF;CACF;CAEA,OAAO;EACL,MAAM;EACN,MAAM,KAAK,OAAO;GAChB,IAAI,MAAM,MAAM,WAAW,GAAG;GAC9B,MAAM,OAAO,aAAa,OAAO,MAAM;GACvC,IAAI,KAAK,QAAQ;IACf,MAAM,QAAQ,MAAM,MAAM,SAAS,MACjC,EAAE,SAAS,UAAU,CAAC,KAAK,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,CACpD;IACA,MAAM,IAAI,KAAK,QAAQ,MAAM,KAAK,IAAI,IAAI,MAAM,sBAAsB;GACxE;GACA,IAAI,QAAQ,eAAe,MAAM;IAC/B,IAAI,IAAI;IACR,KAAK,MAAM,QAAQ,MAAM,OAAO;KAC9B,IAAI,KAAK,SAAS,cAAc;KAChC,MAAM,IAAI,KAAK,YAAY,MAAO,KAAK,UAAU,KAAK,UAAU,GAAG,kBAAkB;IACvF;GACF;EACF;CACF;AACF"}