@kyro-cms/core 0.12.44 → 0.12.45

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 (311) hide show
  1. package/dist/{WebhookService-C19xR8qE.d.ts → WebhookService-CZf_na-J.d.ts} +1 -1
  2. package/dist/{WebhookService-BBcCHBo8.d.cts → WebhookService-DgIx21X-.d.cts} +1 -1
  3. package/dist/api-handler-graphql.cjs +1 -1
  4. package/dist/api-handler-graphql.js +2 -1
  5. package/dist/api-handler-trpc.cjs +1 -1
  6. package/dist/api-handler-trpc.js +2 -1
  7. package/dist/api-handler.cjs +1 -1
  8. package/dist/api-handler.js +1 -1
  9. package/dist/{base-yXdYZxFK.d.ts → base-7vJMzr4V.d.ts} +1 -1
  10. package/dist/{base-C2iwjdJQ.d.cts → base-DDEmdRqV.d.cts} +1 -1
  11. package/dist/bcryptjs-AZA6WEN2.js +2 -0
  12. package/dist/bcryptjs-WIQSWJGK.cjs +1 -0
  13. package/dist/better-sqlite3-42Q3FG3E.js +2 -0
  14. package/dist/better-sqlite3-5IISPX34.cjs +1 -0
  15. package/dist/bootstrap-7CI3NVSY.js +1 -0
  16. package/dist/bootstrap-DOOM2CNQ.cjs +1 -0
  17. package/dist/bowser-FI5JQGKZ.js +11 -0
  18. package/dist/bowser-VX6B6ZSE.cjs +10 -0
  19. package/dist/chokidar-24HVS6XD.cjs +5 -0
  20. package/dist/chokidar-43DT7CVN.js +6 -0
  21. package/dist/chunk-26Q7JXM4.cjs +3 -0
  22. package/dist/chunk-2BUODBE2.js +2 -0
  23. package/dist/chunk-2WFTETFB.js +2 -0
  24. package/dist/chunk-35PGCW3S.cjs +1 -0
  25. package/dist/chunk-3VXEK5ZW.cjs +1 -0
  26. package/dist/chunk-45TJAB5X.js +301 -0
  27. package/dist/chunk-5DWYVUQR.cjs +1 -0
  28. package/dist/chunk-5LPNEYK5.cjs +1 -0
  29. package/dist/chunk-66BJXVFJ.js +2 -0
  30. package/dist/chunk-6KRR7YHA.js +2 -0
  31. package/dist/chunk-6KUL2BSA.cjs +133 -0
  32. package/dist/chunk-6MSS5X77.js +2 -0
  33. package/dist/chunk-6QWLXJ7L.js +2 -0
  34. package/dist/chunk-6V3AP7HR.cjs +269 -0
  35. package/dist/chunk-73D2PNHD.cjs +7 -0
  36. package/dist/chunk-7ACHOBWY.cjs +13 -0
  37. package/dist/chunk-7AQSH3KR.js +2 -0
  38. package/dist/chunk-7GGZA5YU.cjs +2 -0
  39. package/dist/chunk-7I6URA6F.js +4 -0
  40. package/dist/chunk-7JWQ2PZP.cjs +1 -0
  41. package/dist/chunk-7SSFHJTR.js +57 -0
  42. package/dist/chunk-7T35572E.js +75 -0
  43. package/dist/chunk-7V67ONUD.js +4 -0
  44. package/dist/chunk-7WMMKGEO.cjs +1 -0
  45. package/dist/chunk-A73AVVFR.js +11 -0
  46. package/dist/chunk-AK754S3T.cjs +2 -0
  47. package/dist/chunk-AMGJ5AFH.cjs +1 -0
  48. package/dist/chunk-ATBH763U.js +2 -0
  49. package/dist/chunk-B3GDQ7UI.cjs +114 -0
  50. package/dist/chunk-BAVN7VDR.cjs +1 -0
  51. package/dist/chunk-BCEE4NBZ.cjs +2 -0
  52. package/dist/{chunk-J4252I5B.cjs → chunk-BHR7OAU4.cjs} +4 -4
  53. package/dist/chunk-BLH2MRK4.js +2 -0
  54. package/dist/chunk-BPMA2ECA.js +10 -0
  55. package/dist/chunk-BUNLC3II.cjs +1 -0
  56. package/dist/chunk-C2PXMVR5.js +2 -0
  57. package/dist/chunk-CGPAS4U5.js +4 -0
  58. package/dist/chunk-DS5DE5BU.js +2 -0
  59. package/dist/chunk-DUO523BH.cjs +1 -0
  60. package/dist/chunk-DVWYO3KK.cjs +1 -0
  61. package/dist/chunk-E27KEZPT.js +2 -0
  62. package/dist/chunk-EHWUALGH.cjs +1 -0
  63. package/dist/chunk-EN65ZEK2.cjs +2 -0
  64. package/dist/chunk-EOOZDOL7.js +3 -0
  65. package/dist/chunk-EZIDQBXI.cjs +1 -0
  66. package/dist/chunk-F4ITQ6XQ.cjs +3 -0
  67. package/dist/chunk-FLM37UVD.js +2 -0
  68. package/dist/chunk-GIS6X43A.cjs +3 -0
  69. package/dist/chunk-GNEVCEJU.cjs +3 -0
  70. package/dist/chunk-GNOSG3PK.cjs +1 -0
  71. package/dist/chunk-HLAEJB5R.js +384 -0
  72. package/dist/chunk-HPYH7GTS.cjs +1 -0
  73. package/dist/chunk-HT44I66C.js +24 -0
  74. package/dist/chunk-HTYVI2HK.cjs +9 -0
  75. package/dist/chunk-ICVQWR2A.js +2 -0
  76. package/dist/chunk-IP6JUEH3.js +3 -0
  77. package/dist/chunk-IPXOY4RI.js +2 -0
  78. package/dist/chunk-J6U5LWZ7.js +11 -0
  79. package/dist/{chunk-UHFDH3PG.js → chunk-JT36FTHY.cjs} +4 -4
  80. package/dist/chunk-JUJZOG6P.js +2 -0
  81. package/dist/{chunk-2BTRHVT3.cjs → chunk-K7YNEKVE.js} +5 -4
  82. package/dist/chunk-KCHPADCH.cjs +7 -0
  83. package/dist/chunk-KH7LM52S.js +3 -0
  84. package/dist/chunk-LEBM6ZSZ.cjs +10 -0
  85. package/dist/chunk-LQ3YZTPU.cjs +15 -0
  86. package/dist/chunk-LY7N3UHH.cjs +23 -0
  87. package/dist/chunk-M6ESQ5TE.cjs +56 -0
  88. package/dist/chunk-MCZ3YZ2L.js +2 -0
  89. package/dist/chunk-MP5VC5ER.cjs +1 -0
  90. package/dist/chunk-MVX2PYJJ.cjs +1 -0
  91. package/dist/chunk-MY42EWZP.js +2 -0
  92. package/dist/chunk-MZOWPV4D.js +20 -0
  93. package/dist/chunk-NGNJSUGL.cjs +1 -0
  94. package/dist/chunk-NWCREF47.js +3 -0
  95. package/dist/chunk-OMWQVPV7.js +14 -0
  96. package/dist/chunk-ORG67NXX.js +3 -0
  97. package/dist/chunk-OSAVAYJZ.js +16 -0
  98. package/dist/chunk-P7XYIKL6.cjs +300 -0
  99. package/dist/chunk-PBOZJOKN.js +2 -0
  100. package/dist/chunk-PITMDQYN.cjs +18 -0
  101. package/dist/chunk-PL5AIE6F.js +2 -0
  102. package/dist/chunk-QC4YXUBT.cjs +383 -0
  103. package/dist/chunk-QDHP5E4P.cjs +2 -0
  104. package/dist/chunk-QYI3GOHF.cjs +1 -0
  105. package/dist/chunk-R3NEPC4I.js +3 -0
  106. package/dist/chunk-R4LXRAMX.js +2 -0
  107. package/dist/chunk-S5HTTLN7.cjs +2 -0
  108. package/dist/chunk-STX5V7HG.cjs +20 -0
  109. package/dist/chunk-SVYUTQVE.js +115 -0
  110. package/dist/chunk-SYEP5QLG.js +19 -0
  111. package/dist/chunk-TR3ZS3T3.js +3 -0
  112. package/dist/chunk-UB5TJHQR.js +2 -0
  113. package/dist/chunk-UD6ZPO7T.js +2 -0
  114. package/dist/chunk-UK43ADRO.js +270 -0
  115. package/dist/chunk-UNYXWPLZ.cjs +2 -0
  116. package/dist/chunk-VBPAAQEF.js +2 -0
  117. package/dist/chunk-VIUU4D5I.js +2 -0
  118. package/dist/chunk-VJ2WMKPK.js +21 -0
  119. package/dist/chunk-VOQUO2EZ.cjs +74 -0
  120. package/dist/chunk-VQ53TFYA.cjs +1 -0
  121. package/dist/chunk-VRZC4TTF.cjs +1 -0
  122. package/dist/chunk-W46LZ4MY.js +2 -0
  123. package/dist/chunk-WCFHS7EZ.cjs +1 -0
  124. package/dist/chunk-WGESLAWV.js +8 -0
  125. package/dist/chunk-WSP7PSXC.js +8 -0
  126. package/dist/chunk-X54XZACS.cjs +10 -0
  127. package/dist/{chunk-Q2UYCYKV.js → chunk-XBH4YMC7.js} +5 -4
  128. package/dist/chunk-XDE7CFV6.cjs +19 -0
  129. package/dist/chunk-XOACKBG7.js +4 -0
  130. package/dist/chunk-XPPVX4GQ.cjs +1 -0
  131. package/dist/chunk-ZJE3VAAW.js +134 -0
  132. package/dist/chunk-ZO3YB5DK.cjs +1 -0
  133. package/dist/chunk-ZOVH6QT5.cjs +1 -0
  134. package/dist/chunk-ZYDOF65Q.cjs +1 -0
  135. package/dist/cli/index.cjs +197 -78
  136. package/dist/cli/index.js +198 -78
  137. package/dist/client.cjs +1 -1
  138. package/dist/client.d.cts +1 -1
  139. package/dist/client.d.ts +1 -1
  140. package/dist/client.js +2 -1
  141. package/dist/d1-5ZQJOFDX.cjs +1 -0
  142. package/dist/d1-VPH75GI2.js +2 -0
  143. package/dist/dist-es-3SSNUZST.cjs +1 -0
  144. package/dist/dist-es-6SVFVYN3.js +1 -0
  145. package/dist/dist-es-6TQTDPE7.js +2 -0
  146. package/dist/dist-es-A5OF2STN.cjs +2 -0
  147. package/dist/dist-es-BOW5V247.cjs +6 -0
  148. package/dist/dist-es-CRIMATLL.cjs +2 -0
  149. package/dist/dist-es-DL3VLVP6.cjs +1 -0
  150. package/dist/dist-es-EMUQ6ZNZ.js +3 -0
  151. package/dist/dist-es-MNIQZC4U.js +2 -0
  152. package/dist/dist-es-P25IKLBI.cjs +1 -0
  153. package/dist/dist-es-SJ76GYCI.js +2 -0
  154. package/dist/dist-es-SRPWSAF4.cjs +1 -0
  155. package/dist/dist-es-T2H2W5BX.cjs +3 -0
  156. package/dist/dist-es-TX4DBXEW.js +3 -0
  157. package/dist/dist-es-U4ZB3ZDA.js +7 -0
  158. package/dist/dist-es-XZBHIIKY.js +4 -0
  159. package/dist/drizzle/index.cjs +1 -1
  160. package/dist/drizzle/index.d.cts +2 -2
  161. package/dist/drizzle/index.d.ts +2 -2
  162. package/dist/drizzle/index.js +1 -1
  163. package/dist/drizzle-orm-47ELDEM6.cjs +1 -0
  164. package/dist/drizzle-orm-7YTX5NTT.js +1 -0
  165. package/dist/event-streams-25YJ2Z6R.js +1 -0
  166. package/dist/event-streams-JBMWCI2O.cjs +1 -0
  167. package/dist/fields/index.cjs +1 -1
  168. package/dist/fields/index.js +1 -1
  169. package/dist/fs-DGKZLRM6.cjs +1 -0
  170. package/dist/fs-YZJ5FM6J.js +2 -0
  171. package/dist/graphql/index.cjs +1 -1
  172. package/dist/graphql/index.d.cts +2 -2
  173. package/dist/graphql/index.d.ts +2 -2
  174. package/dist/graphql/index.js +1 -1
  175. package/dist/{index-DTz6u7w9.d.cts → index-BJ1rwHxk.d.cts} +1 -1
  176. package/dist/{index-BeQtbl3z.d.ts → index-BTjlptCL.d.ts} +1 -1
  177. package/dist/index.cjs +28 -46
  178. package/dist/index.d.cts +23 -9
  179. package/dist/index.d.ts +23 -9
  180. package/dist/index.js +29 -46
  181. package/dist/integration.cjs +1 -1
  182. package/dist/integration.js +1 -1
  183. package/dist/jsonwebtoken-DFB6ZBZA.cjs +8 -0
  184. package/dist/jsonwebtoken-S7BG2YWK.js +9 -0
  185. package/dist/lib-5QYYN6ML.cjs +12 -0
  186. package/dist/lib-IYW32OER.js +13 -0
  187. package/dist/loadSso-JY4WDQPS.cjs +2 -0
  188. package/dist/loadSso-YTG2GQGW.js +3 -0
  189. package/dist/local-VDCSEMC2.js +1 -0
  190. package/dist/local-YCWBUF3R.cjs +1 -0
  191. package/dist/media-3Z6YW5J4.cjs +1 -0
  192. package/dist/media-HK2IZMUZ.js +1 -0
  193. package/dist/mongo-auth-adapter-7K64Y2QM.cjs +1 -0
  194. package/dist/mongo-auth-adapter-BUKINEZL.js +1 -0
  195. package/dist/mongodb/index.cjs +1 -1
  196. package/dist/mongodb/index.d.cts +2 -2
  197. package/dist/mongodb/index.d.ts +2 -2
  198. package/dist/mongodb/index.js +1 -1
  199. package/dist/nodemailer-AXROO37D.js +54 -0
  200. package/dist/nodemailer-IDML4L6W.cjs +53 -0
  201. package/dist/postgres-auth-adapter-2M4RNEY3.cjs +1 -0
  202. package/dist/postgres-auth-adapter-MKSHIJDL.js +1 -0
  203. package/dist/postgres-js-3Y54EXVQ.cjs +1 -0
  204. package/dist/postgres-js-INQPBHJP.js +1 -0
  205. package/dist/redis-adapter-EGMUN65D.cjs +1 -0
  206. package/dist/redis-adapter-SXOXLHNH.js +1 -0
  207. package/dist/rest/index.cjs +1 -1
  208. package/dist/rest/index.d.cts +5 -5
  209. package/dist/rest/index.d.ts +5 -5
  210. package/dist/rest/index.js +1 -1
  211. package/dist/schema-RT6WSUYC.cjs +1 -0
  212. package/dist/schema-XC5ISGNR.js +2 -0
  213. package/dist/signin-KZBIAHGS.js +3 -0
  214. package/dist/signin-VFBLX7EL.cjs +2 -0
  215. package/dist/sqlite-adapter-DV7ZX2EJ.js +1 -0
  216. package/dist/sqlite-adapter-ZTABLT2X.cjs +1 -0
  217. package/dist/src-6LAUXXDM.cjs +1 -0
  218. package/dist/src-GZRZ4VAO.js +1 -0
  219. package/dist/sso-oidc-54BIRYR6.cjs +2 -0
  220. package/dist/sso-oidc-SX5OIQGG.js +3 -0
  221. package/dist/sts-HVGDJYIF.js +3 -0
  222. package/dist/sts-YLXXIB3X.cjs +2 -0
  223. package/dist/templates/index.cjs +1 -1
  224. package/dist/templates/index.d.cts +1 -1
  225. package/dist/templates/index.d.ts +1 -1
  226. package/dist/templates/index.js +1 -1
  227. package/dist/trpc/index.cjs +1 -1
  228. package/dist/trpc/index.d.cts +7 -7
  229. package/dist/trpc/index.d.ts +7 -7
  230. package/dist/trpc/index.js +1 -1
  231. package/dist/{types-CaXXmV9h.d.ts → types-CYGXsNcJ.d.ts} +5 -5
  232. package/dist/{types-BjivdGbU.d.cts → types-DOKMyC3y.d.cts} +5 -5
  233. package/dist/ws/index.cjs +1 -1
  234. package/dist/ws/index.js +1 -1
  235. package/package.json +2 -2
  236. package/dist/bootstrap-ROSTPMVL.js +0 -1
  237. package/dist/bootstrap-WW5NJ6EB.cjs +0 -1
  238. package/dist/chunk-3CVLI5C5.cjs +0 -3
  239. package/dist/chunk-3Q2WUG63.cjs +0 -2
  240. package/dist/chunk-3RSMK4DA.cjs +0 -2
  241. package/dist/chunk-4IGWJMBY.cjs +0 -2
  242. package/dist/chunk-4ORJMSJU.cjs +0 -1
  243. package/dist/chunk-4RMFCTWH.js +0 -1
  244. package/dist/chunk-5B6X2GBJ.js +0 -2
  245. package/dist/chunk-5J6HXUF6.js +0 -1
  246. package/dist/chunk-5KOQYQEE.js +0 -1
  247. package/dist/chunk-5SEHX7ON.js +0 -1
  248. package/dist/chunk-6ROHVUXF.js +0 -1
  249. package/dist/chunk-6SPPR5JZ.js +0 -3
  250. package/dist/chunk-7IVN6TTY.js +0 -133
  251. package/dist/chunk-AHSFSERC.cjs +0 -1
  252. package/dist/chunk-B5XWYVWK.js +0 -1
  253. package/dist/chunk-BGX27ZRG.cjs +0 -300
  254. package/dist/chunk-C2W5PSHC.js +0 -300
  255. package/dist/chunk-CCUQZ66T.cjs +0 -133
  256. package/dist/chunk-D5P2IPGX.cjs +0 -3
  257. package/dist/chunk-EPMGPNBE.js +0 -1
  258. package/dist/chunk-FHJJKFAU.cjs +0 -1
  259. package/dist/chunk-FVZ5RFLO.js +0 -2
  260. package/dist/chunk-FZ6Q2EBJ.cjs +0 -20
  261. package/dist/chunk-G3J2EU5D.cjs +0 -1
  262. package/dist/chunk-G7SSHELM.cjs +0 -1
  263. package/dist/chunk-GKYEJ2UF.js +0 -1
  264. package/dist/chunk-GO34AOBZ.cjs +0 -1
  265. package/dist/chunk-GYQMNXXW.cjs +0 -114
  266. package/dist/chunk-HLSB2MCK.js +0 -1
  267. package/dist/chunk-HQP2Y7QQ.js +0 -251
  268. package/dist/chunk-HS2KNFAB.cjs +0 -2
  269. package/dist/chunk-HVXO3OFB.cjs +0 -1
  270. package/dist/chunk-IETGL7WJ.js +0 -1
  271. package/dist/chunk-IFJ73O3A.cjs +0 -1
  272. package/dist/chunk-ILEZ3NYX.cjs +0 -2
  273. package/dist/chunk-INB4LNA6.js +0 -90
  274. package/dist/chunk-K6WUOU6P.js +0 -1
  275. package/dist/chunk-KD7LUCFY.cjs +0 -1
  276. package/dist/chunk-KDNYHLD2.js +0 -1
  277. package/dist/chunk-LHW4R367.js +0 -1
  278. package/dist/chunk-MIOMMB23.cjs +0 -1
  279. package/dist/chunk-N5VNHUJS.cjs +0 -4
  280. package/dist/chunk-NRLIGDYF.js +0 -1
  281. package/dist/chunk-NY47CFVP.cjs +0 -1
  282. package/dist/chunk-NZJAGASC.cjs +0 -251
  283. package/dist/chunk-OG7CNQGU.js +0 -1
  284. package/dist/chunk-PP5S2UBV.js +0 -0
  285. package/dist/chunk-PP7W5UKL.js +0 -2
  286. package/dist/chunk-Q3Q7BJVQ.cjs +0 -1
  287. package/dist/chunk-QCA3AP3M.cjs +0 -1
  288. package/dist/chunk-QOCHBPMK.js +0 -2
  289. package/dist/chunk-QYFU5Y7S.js +0 -3
  290. package/dist/chunk-RHCWCG3O.js +0 -114
  291. package/dist/chunk-SK2Q4PRV.cjs +0 -90
  292. package/dist/chunk-TFBHE5FF.cjs +0 -1
  293. package/dist/chunk-UBRYJP2G.js +0 -1
  294. package/dist/chunk-V65NPSR5.cjs +0 -1
  295. package/dist/chunk-VGQ4VUG6.js +0 -2
  296. package/dist/chunk-W7C6SJXZ.js +0 -20
  297. package/dist/chunk-WIZ6C5QZ.cjs +0 -1
  298. package/dist/chunk-ZIWJJRWQ.js +0 -4
  299. package/dist/chunk-ZUVP4UK7.cjs +0 -1
  300. package/dist/media-L5XDD47D.js +0 -1
  301. package/dist/media-OUBQTIQP.cjs +0 -1
  302. package/dist/mongo-auth-adapter-5TJO5J5U.js +0 -1
  303. package/dist/mongo-auth-adapter-JVE5M3S4.cjs +0 -1
  304. package/dist/postgres-auth-adapter-33QOIRXT.js +0 -1
  305. package/dist/postgres-auth-adapter-JKDYYULH.cjs +0 -1
  306. package/dist/redis-adapter-NN3H4GRX.js +0 -1
  307. package/dist/redis-adapter-OUKQGYCH.cjs +0 -1
  308. package/dist/schema-HIUSHSUI.cjs +0 -1
  309. package/dist/schema-KFYUM674.js +0 -1
  310. package/dist/sqlite-adapter-GTTVSXRV.cjs +0 -1
  311. package/dist/sqlite-adapter-UPANATIW.js +0 -1
@@ -0,0 +1,2 @@
1
+ import {createRequire}from'module';import {b}from'./chunk-6KRR7YHA.js';import {g as g$1}from'./chunk-C2PXMVR5.js';createRequire(import.meta.url);
2
+ g$1();var d=class{collections=new Map;globals=new Map;connected=false;tenantContext;setTenantContext(e){this.tenantContext=e;}getTenantContext(){return this.tenantContext}async init(e,n=[]){for(let t of e)this.collections.set(t.slug,t);for(let t of n)this.globals.set(t.slug,t);await this.connect();}getCollection(e){let n=this.collections.get(e);if(!n)throw console.error(`[Adapter] Missing collection "${e}". Available collections:`,Array.from(this.collections.keys())),new Error(`Collection "${e}" not found in adapter`);return n}applyTenantFilter(e={},n){return n?{...e,tenantId:{equals:n}}:e}getTableName(e){return e.replace(/-/g,"_")}prepareData(e,n){let t={...e};if(n.timestamps){let r=new Date().toISOString();t.updatedAt=r,t.createdAt||(t.createdAt=r);}return n.auth&&t.password,t}processRelationships(e,n,t){return e}parseSort(e){return e?e.startsWith("-")?{field:e.slice(1),direction:"desc"}:{field:e,direction:"asc"}:{field:"createdAt",direction:"desc"}}calculatePagination(e,n,t){let r=Math.ceil(t/n);return {totalDocs:t,limit:n,totalPages:r,page:e,pagingCounter:(e-1)*n+1,hasPrevPage:e>1,hasNextPage:e<r,prevPage:e>1?e-1:null,nextPage:e<r?e+1:null}}selectFields(e,n){if(!n||n.length===0)return e;let t={};for(let r of n)r in e&&(t[r]=e[r]);return t.id=e.id,t}isRelationshipField(e){return e.type==="relationship"}isUploadField(e){return e.type==="upload"}getRelationshipFields(e){let n=[];for(let t of e)t.type==="relationship"?n.push(t):"fields"in t&&t.fields&&n.push(...this.getRelationshipFields(t.fields));return n}getUploadFields(e){let n=[];for(let t of e)t.type==="upload"?n.push(t):"fields"in t&&t.fields&&n.push(...this.getUploadFields(t.fields));return n}};g$1();var o={tenantEnabled:true,tenantField:"tenantId",ownershipRules:{posts:{ownerField:"authorId",bypassRoles:["super_admin","admin","editor"]},pages:{ownerField:"authorId",bypassRoles:["super_admin","admin","editor"]},media:{ownerField:"uploadedBy",bypassRoles:["super_admin","admin","editor"]},orders:{ownerField:"customerId",bypassRoles:["super_admin","admin","editor"]},customers:{ownerField:"id",bypassRoles:["super_admin","admin"]},navigation:{ownerField:"id",bypassRoles:["super_admin","admin"]}}};function g(i,e,n=o){return !n.tenantEnabled||e.isSuperAdmin?i:{...i,where:{...i.where,[n.tenantField]:e.tenantId}}}function p(i,e,n,t=o){let r=t.ownershipRules[e];return !r||r.bypassRoles&&b({role:n.role},r.bypassRoles)?i:r.ownerField==="id"&&n.userId?{...i,where:{...i.where,id:n.userId}}:r.ownerField&&n.userId?{...i,where:{...i.where,[r.ownerField]:n.userId}}:i}function m(i,e,n,t=o){let r=i;return r=g(r,n,t),r=p(r,e,n,t),r}function h(i,e,n,t=o){if(n.isSuperAdmin)return true;if(t.tenantEnabled&&i[t.tenantField]!==n.tenantId)return false;let r=t.ownershipRules[e];return !r||r.bypassRoles&&b({role:n.role},r.bypassRoles)?true:r.ownerField==="id"?i.id===n.userId:r.ownerField?i[r.ownerField]===n.userId:true}export{d as a,o as b,m as c,h as d};
@@ -0,0 +1 @@
1
+ 'use strict';var chunkAK754S3T_cjs=require('./chunk-AK754S3T.cjs'),chunkDUO523BH_cjs=require('./chunk-DUO523BH.cjs'),chunkZOVH6QT5_cjs=require('./chunk-ZOVH6QT5.cjs'),chunkBUNLC3II_cjs=require('./chunk-BUNLC3II.cjs');chunkBUNLC3II_cjs.h();chunkBUNLC3II_cjs.h();async function V(e){let a=chunkAK754S3T_cjs.o(e.db),t={db:e.db,registry:e.registry,req:e.req,user:e.user,tenantId:e.tenantId,webhookService:a,settings:e.settings},n=chunkDUO523BH_cjs.f(e.req);if(n){let r=await chunkDUO523BH_cjs.e(n,e.db,async o=>{try{return await e.db.findByID({collection:"users",id:o})||null}catch{return null}});r.valid&&(t.user=r.user||e.user,t.tenantId=r.tenantId||e.tenantId,t.apiKey=chunkDUO523BH_cjs.g(r));}return t}chunkBUNLC3II_cjs.h();var G={_media:{create:chunkAK754S3T_cjs.d.MEDIA_UPLOAD,update:chunkAK754S3T_cjs.d.MEDIA_UPLOAD,delete:chunkAK754S3T_cjs.d.MEDIA_DELETE}};function R(e,a){let t=G[e];return t?t[a]:`collection.${a}`}async function q(e,a,t){if(e.webhookService)try{await e.webhookService.trigger(a,{collection:t.collection,operation:t.operation,data:t.data,previousData:t.previousData,user:e.user?{id:e.user.id,email:e.user.email,role:e.user.role}:void 0,tenantId:e.tenantId});}catch(n){console.error(`[Webhook] Failed to trigger ${a}:`,n);}}function I(e,a){if(!(!e||typeof e!="object"))for(let t of a){if(t.type==="tabs"&&Array.isArray(t.tabs)){let r=t.name?e[t.name]:e;if(r&&typeof r=="object")for(let o of t.tabs)Array.isArray(o.fields)&&I(r,o.fields);continue}if(!t.name||!(t.name in e))continue;if(e[t.name]===""&&(t.type==="text"||t.type==="textarea"||t.type==="code"||t.type==="markdown"||t.type==="email"||t.type==="password"||t.type==="color"||(e[t.name]=null)),(t.type==="group"||t.type==="collapsible")&&t.name&&Array.isArray(t.fields)&&e[t.name]&&typeof e[t.name]=="object")I(e[t.name],t.fields);else if(t.type==="array"&&t.name&&Array.isArray(t.fields)&&Array.isArray(e[t.name]))for(let r of e[t.name])r&&typeof r=="object"&&I(r,t.fields);else if(t.type==="blocks"&&t.name&&Array.isArray(t.blocks)&&Array.isArray(e[t.name]))for(let r of e[t.name]){if(!r||typeof r!="object")continue;let o=r.type||r.blockType;if(!o)continue;let s=t.blocks.find(i=>i.slug===o);if(!s||!Array.isArray(s.fields))continue;let u=r.data&&typeof r.data=="object"?r.data:r;I(u,s.fields);}}}async function b(e,a,t){let n=await chunkAK754S3T_cjs.b(e,a,{user:t.user,req:t.req,tenantId:t.tenantId,apiKey:t.apiKey});if(!n.allowed)throw new Error(n.error||"Access denied");t.tenantId&&t.db.setTenantContext({tenantId:t.tenantId,userId:t.user?.id??"",role:t.user?.role,isSuperAdmin:t.user?.role==="super_admin"});}function P(e){return async a=>{let{collection:t,where:n,sort:r,limit:o,page:s,depth:u,select:i,draft:d}=a,l=e.registry.getCollection(t);if(await b(l,"read",e),l.hooks?.beforeRead)for(let p of l.hooks.beforeRead)await p({collection:t,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read",where:n});let c=d??!!e.user,h=await e.db.find({collection:t,where:n||{},sort:r,limit:o||10,page:s||1,depth:u||0,tenantId:e.tenantId,select:i,draft:c});if(l.hooks?.afterRead)for(let p of h.docs)for(let k of l.hooks.afterRead)await k({collection:t,doc:p,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read"});return await chunkAK754S3T_cjs.a(h.docs,l.fields,e.db,e.registry,1,u||0),chunkZOVH6QT5_cjs.a(h)}}function v(e){return async a=>{let{collection:t,id:n,depth:r,select:o,draft:s}=a,u=e.registry.getCollection(t);await b(u,"read",e);let i=s??!!e.user,d=await e.db.findByID({collection:t,id:n,depth:r||0,tenantId:e.tenantId,select:o,draft:i});if(!d)throw new Error(`Document not found: ${t}/${n}`);if(u.hooks?.afterRead)for(let l of u.hooks.afterRead)await l({collection:t,doc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read",id:n});return await chunkAK754S3T_cjs.a([d],u.fields,e.db,e.registry,1,r||0),chunkZOVH6QT5_cjs.a(d)}}function K(e){return async a=>{let{collection:t,data:n,depth:r,select:o}=a,s=e.registry.getCollection(t);await b(s,"create",e);let i=e.registry.getCreateZodSchema(t).parse(n);if(s.tenantScoped&&e.tenantId&&(i.tenantId=e.tenantId),s.hooks?.beforeValidate)for(let l of s.hooks.beforeValidate){let c=await l({collection:t,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});c&&typeof c=="object"&&!Array.isArray(c)&&Object.assign(i,c);}if(s.hooks?.beforeChange)for(let l of s.hooks.beforeChange){let c=await l({collection:t,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});c&&typeof c=="object"&&!Array.isArray(c)&&Object.assign(i,c);}let d=await e.db.create({collection:t,data:i,depth:r||0,tenantId:e.tenantId,select:o});if(s.hooks?.afterChange)for(let l of s.hooks.afterChange)await l({collection:t,doc:d,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});return await q(e,R(t,"create"),{collection:t,data:d,operation:"create"}),{doc:d}}}function E(e){return async a=>{let{collection:t,id:n,data:r,depth:o,select:s,baseUpdatedAt:u}=a,i=e.registry.getCollection(t);await b(i,"update",e);let d=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true});if(!d)throw new Error(`Document not found: ${t}/${n}`);if(u&&d.updatedAt&&u!==d.updatedAt)throw new Error(`Revision conflict: document has changed since ${u}. Current updatedAt: ${d.updatedAt}`);I(r,i.fields);let c=e.registry.getUpdateZodSchema(t).parse(r);if(i.tenantScoped&&e.tenantId&&(c.tenantId=e.tenantId),i.hooks?.beforeValidate)for(let m of i.hooks.beforeValidate){let f=await m({collection:t,data:c,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});f&&typeof f=="object"&&!Array.isArray(f)&&Object.assign(c,f);}if(i.hooks?.beforeChange)for(let m of i.hooks.beforeChange){let f=await m({collection:t,data:c,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});f&&typeof f=="object"&&!Array.isArray(f)&&Object.assign(c,f);}let h=e.req&&typeof e.req.headers?.get=="function"&&e.req.headers.get("x-draft")==="true"||a.draft===true,p=i.versions?.drafts===true,k=e.req?.query?.autosave==="true"||e.req?.url?.includes("autosave=true")||a.autosave===true,g;if(p&&h?(await e.db.createVersion({collection:t,documentId:n,data:c,status:"draft",autosave:k,createdBy:e.user?.id,tenantId:e.tenantId}),g=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true})):p?(g=await e.db.update({collection:t,id:n,data:{...c,status:"published"},depth:o||0,tenantId:e.tenantId,select:s}),await e.db.createVersion({collection:t,documentId:n,data:c,status:"published",createdBy:e.user?.id,tenantId:e.tenantId})):g=await e.db.update({collection:t,id:n,data:c,depth:o||0,tenantId:e.tenantId,select:s}),i.hooks?.afterChange)for(let m of i.hooks.afterChange)await m({collection:t,doc:g,data:c,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});return await q(e,R(t,"update"),{collection:t,data:g,previousData:d,operation:"update"}),{doc:g}}}function j(e){return async a=>{let{collection:t,id:n}=a,r=e.registry.getCollection(t);await b(r,"delete",e);let o=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true});if(!o)throw new Error(`Document not found: ${t}/${n}`);if(r.hooks?.beforeDelete)for(let u of r.hooks.beforeDelete)await u({collection:t,doc:o,req:e.req,user:e.user,tenantId:e.tenantId,operation:"delete",id:n});let s=await e.db.delete({collection:t,id:n,tenantId:e.tenantId});if(r.hooks?.afterDelete)for(let u of r.hooks.afterDelete)await u({collection:t,doc:s,req:e.req,user:e.user,tenantId:e.tenantId,operation:"delete",id:n});return await q(e,R(t,"delete"),{collection:t,data:s,previousData:o,operation:"delete"}),{doc:s,message:"Deleted successfully"}}}function S(e){return async a=>{let{collection:t,where:n}=a,r=e.registry.getCollection(t);return await b(r,"read",e),{totalDocs:await e.db.count({collection:t,where:n||{},tenantId:e.tenantId})}}}chunkBUNLC3II_cjs.h();async function W(e,a,t){let n=await chunkAK754S3T_cjs.c(e,a,{user:t.user,req:t.req,tenantId:t.tenantId});if(!n.allowed)throw new Error(n.error||"Access denied");t.tenantId&&t.db.setTenantContext({tenantId:t.tenantId,userId:t.user?.id??"",role:t.user?.role,isSuperAdmin:t.user?.role==="super_admin"});}function O(e){let a={},t=e.registry.getCollections();for(let r of t){let o=r.slug;a[o]={find:P(e),findByID:v(e),create:K(e),update:E(e),delete:j(e),count:S(e)};}let n=e.registry.getGlobals();for(let r of n){let o=r.slug;a[`_globals_${o}`]={get:async s=>(await W(r,"read",e),await e.db.findOne({collection:`_globals_${o}`,where:{},tenantId:e.tenantId,depth:s?.depth,draft:s?.draft,select:s?.select})),update:async s=>{await W(r,"update",e);let i=e.registry.getZodSchema(o).parse(s.data),d=await e.db.findOne({collection:`_globals_${o}`,where:{},tenantId:e.tenantId,draft:true}),l;return d?l=await e.db.update({collection:`_globals_${o}`,id:d.id,data:i,tenantId:e.tenantId}):l=await e.db.create({collection:`_globals_${o}`,data:{...i,id:o},tenantId:e.tenantId}),l}};}return a}function L(e){if(e.settings?.access?.apiAccess?.trpcEnabled===false)throw new Error("tRPC API is disabled");return O(e)}exports.a=V;exports.b=P;exports.c=v;exports.d=K;exports.e=E;exports.f=j;exports.g=S;exports.h=O;exports.i=L;
@@ -0,0 +1 @@
1
+ 'use strict';var chunkBUNLC3II_cjs=require('./chunk-BUNLC3II.cjs');chunkBUNLC3II_cjs.h();function n(e){return {ipAddress:e.headers.get("x-forwarded-for")?.split(",")[0]?.trim()||e.headers.get("x-real-ip")||"unknown",userAgent:e.headers.get("user-agent")||"unknown"}}exports.a=n;
@@ -0,0 +1,2 @@
1
+ import {createRequire}from'module';import {b}from'./chunk-A73AVVFR.js';import {p as p$1}from'./chunk-XOACKBG7.js';import {g}from'./chunk-C2PXMVR5.js';createRequire(import.meta.url);
2
+ g();g();var C="AWS_ACCESS_KEY_ID",A="AWS_SECRET_ACCESS_KEY",p="AWS_SESSION_TOKEN",I="AWS_CREDENTIAL_EXPIRATION",a="AWS_CREDENTIAL_SCOPE",i="AWS_ACCOUNT_ID",V=o=>async()=>{o?.logger?.debug("@aws-sdk/credential-provider-env - fromEnv");let E=process.env[C],r=process.env[A],n=process.env[p],s=process.env[I],t=process.env[a],c=process.env[i];if(E&&r){let _={accessKeyId:E,secretAccessKey:r,...n&&{sessionToken:n},...s&&{expiration:new Date(s)},...t&&{credentialScope:t},...c&&{accountId:c}};return b(_,"CREDENTIALS_ENV_VARS","g"),_}throw new p$1("Unable to find environment variable credentials.",{logger:o?.logger})};export{C as a,A as b,p as c,I as d,a as e,i as f,V as g};
@@ -0,0 +1,20 @@
1
+ import {createRequire}from'module';import {a,c,b,d}from'./chunk-MCZ3YZ2L.js';import {a as a$1}from'./chunk-BLH2MRK4.js';import {g}from'./chunk-C2PXMVR5.js';import {randomBytes}from'crypto';createRequire(import.meta.url);
2
+ g();g();var _;function x(){return _||(_=createRequire("file:///")("node:sqlite").DatabaseSync,_)}function N(T){let e=[];for(let a of T)if(a.type==="tabs"&&"tabs"in a)for(let n of a.tabs)e.push(...N(n.fields));else a.type==="row"&&"fields"in a?e.push(...N(a.fields)):a.type==="collapsible"&&"fields"in a?e.push(...N(a.fields)):e.push(a);return e}function B(T,e){let a=e,n=T[a.name];if(a.type==="json"||a.type==="richtext"||a.type==="array"||a.type==="group"||a.type==="blocks"||a.type==="list"||a.type==="relationship-block")try{n=n?JSON.parse(n):null;}catch{n=null;}if(a.type==="checkbox"&&(n=!!n),a.type==="date"&&n)try{let i=new Date(n);isNaN(i.getTime())?n=null:n=i.toISOString();}catch{n=null;}if((a.type==="upload"||a.type==="image")&&n)try{let i=JSON.parse(n);Array.isArray(i)?n=i.map(o=>typeof o=="object"&&o!==null?o:{id:o}):n=typeof i=="object"?i:{id:i};}catch{n={id:n};}if(a.type==="relationship"&&n)try{let i=JSON.parse(n);Array.isArray(i),n=i;}catch{n={relationTo:Array.isArray(a.relationTo)?a.relationTo[0]:a.relationTo,value:n};}if(a.type==="list"&&n)try{let i=JSON.parse(n);n=Array.isArray(i)?i:[];}catch{n=[];}if(a.type==="relationship-block"&&n)try{let i=JSON.parse(n);n=Array.isArray(i)?i:[];}catch{n=[];}return n}function P(T,e){return Array.isArray(T)?T.map(a=>{if(!a||typeof a!="object")return a;let n=a.data?{...a.data}:void 0;if(!n)return a;let i=e.find(o=>o.slug===a.type||o.slug===a.slug);if(!i||!Array.isArray(i.fields))return a;for(let o of i.fields){if(o.name&&(o.type==="upload"||o.type==="image")&&n[o.name]){let t=n[o.name];Array.isArray(t)?n[o.name]=t.map(s=>typeof s=="string"?{id:s}:s):typeof t=="string"&&(n[o.name]={id:t});}if(o.type==="blocks"&&o.name&&n[o.name]){let t=o.blocks||[];n[o.name]=P(n[o.name],t);}}return {...a,data:n}}):T}function O(T,e){try{return T.prepare(`PRAGMA table_info(${e})`).all().map(n=>n.name)}catch{return []}}var L=class extends a{db;path;migrations=new Map;versionsTableName="kyro_versions";constructor(e){super(),this.path=e.path,e.db?this.db=e.db:this.db=null;}async connect(){if(!this.db)this.db=new(x())(this.path||":memory:");else try{this.db.exec("SELECT 1");}catch{this.db=new(x())(this.path||":memory:");}if(this.db&&typeof this.db.prepare=="function"&&!this.db.prepare.__wrapped){let e=this.db.prepare.bind(this.db),a=n=>{let i=e(n),o=t=>typeof t=="boolean"?t?1:0:t===void 0?null:t;return new Proxy(i,{get(t,s,r){if(s==="all")return (...c)=>t.all(...c.map(o));if(s==="get")return (...c)=>t.get(...c.map(o));if(s==="run")return (...c)=>t.run(...c.map(o));let l=Reflect.get(t,s,r);return typeof l=="function"?l.bind(t):l}})};a.__wrapped=true,this.db.prepare=a;}this.db.exec("PRAGMA journal_mode = WAL"),this.db.exec("PRAGMA foreign_keys = ON"),this.connected=true;}async disconnect(){if(this.db){try{this.db.close();}catch{}this.db=null;}this.connected=false;}ensureTable(e,a){let n=a||this.getTableNameFor(e.slug),i=["id TEXT PRIMARY KEY"];for(let s of N(e.fields)){if(!s.name||s.name==="id")continue;let r=this.fieldToSQL(s);r&&i.push(r);}let o=N(e.fields);o.some(s=>s.name==="createdAt")||i.push(`${this.col("createdAt")} TEXT DEFAULT (datetime('now'))`),o.some(s=>s.name==="updatedAt")||i.push(`${this.col("updatedAt")} TEXT DEFAULT (datetime('now'))`),o.some(s=>s.name==="status")||i.push("status TEXT DEFAULT 'draft'"),o.some(s=>s.name==="hasDraft")||i.push("hasDraft INTEGER DEFAULT 0"),e.tenantScoped&&i.push("tenant_id TEXT NOT NULL");let t=O(this.db,n);if(t.length===0){let s=`CREATE TABLE IF NOT EXISTS ${n} (${i.join(", ")})`;this.db.exec(s),this.db.exec(`CREATE INDEX IF NOT EXISTS idx_${n}_status ON ${n}(status)`);for(let r of N(e.fields))r.name&&r.indexed&&this.db.exec(`CREATE INDEX IF NOT EXISTS idx_${n}_${r.name} ON ${n}(${this.col(r.name)})`),r.name&&r.unique&&this.db.exec(`CREATE UNIQUE INDEX IF NOT EXISTS idx_${n}_${r.name}_unique ON ${n}(${this.col(r.name)})`);}else {let s=new Set(t);for(let r of i){let l=r.split(" ")[0].replace(/^"/,"").replace(/"$/,"");if(!s.has(l)&&l!=="id")try{l==="status"?this.db.exec(`ALTER TABLE ${n} ADD COLUMN ${this.col(l)} TEXT DEFAULT 'published'`):l==="hasDraft"?this.db.exec(`ALTER TABLE ${n} ADD COLUMN ${this.col(l)} INTEGER DEFAULT 0`):this.db.exec(`ALTER TABLE ${n} ADD COLUMN ${this.col(l)} TEXT`);}catch{}}}this.migrations.set(n,true);}ensureVersionsTable(){this.db.exec(`
3
+ CREATE TABLE IF NOT EXISTS ${this.versionsTableName} (
4
+ id TEXT PRIMARY KEY,
5
+ collection_slug TEXT NOT NULL,
6
+ document_id TEXT NOT NULL,
7
+ tenant_id TEXT,
8
+ version INTEGER NOT NULL,
9
+ status TEXT NOT NULL DEFAULT 'draft',
10
+ autosave INTEGER NOT NULL DEFAULT 0,
11
+ data TEXT NOT NULL,
12
+ created_by TEXT,
13
+ change_description TEXT,
14
+ published_at TEXT,
15
+ created_at TEXT DEFAULT (datetime('now')),
16
+ updated_at TEXT DEFAULT (datetime('now'))
17
+ )
18
+ `);try{this.db.exec(`ALTER TABLE ${this.versionsTableName} ADD COLUMN autosave INTEGER NOT NULL DEFAULT 0`);}catch{}this.db.exec(`CREATE INDEX IF NOT EXISTS idx_${this.versionsTableName}_doc ON ${this.versionsTableName}(collection_slug, document_id)`),this.db.exec(`CREATE INDEX IF NOT EXISTS idx_${this.versionsTableName}_status ON ${this.versionsTableName}(status)`),this.db.exec(`CREATE INDEX IF NOT EXISTS idx_${this.versionsTableName}_autosave ON ${this.versionsTableName}(autosave)`);}resolveCol(e,a){let n=a.replace(/^-/,""),i=O(this.db,e);if(!i.includes(n)){if(n==="created_at"&&i.includes("createdAt"))return '"createdAt"';if(n==="createdAt"&&i.includes("created_at"))return '"created_at"';if(n==="updated_at"&&i.includes("updatedAt"))return '"updatedAt"';if(n==="updatedAt"&&i.includes("updated_at"))return '"updated_at"'}return this.col(n)}col(e){return `"${e}"`}fieldToSQL(e){switch(e.type){case "text":case "email":case "password":case "textarea":case "color":case "icon":case "code":case "markdown":case "url":return this.col(e.name)+" TEXT";case "number":return this.col(e.name)+" REAL";case "checkbox":return this.col(e.name)+" INTEGER DEFAULT 0";case "date":return this.col(e.name)+" TEXT";case "select":case "radio":return this.col(e.name)+" TEXT";case "relationship":case "upload":return this.col(e.name)+" TEXT";case "json":case "richtext":case "array":case "group":case "blocks":return this.col(e.name)+" TEXT";default:return null}}parseGlobalsSlug(e){if(e.startsWith("_globals_")){let a=e.replace("_globals_","");return {isGlobal:true,globalSlug:a,tableName:`global_${a.replace(/-/g,"_")}`}}return {isGlobal:false,globalSlug:"",tableName:this.getTableNameFor(e)}}async find(e){let{collection:a,where:n={},sort:i,limit:o=10,page:t=1,tenantId:s,draft:r=false}=e,l=this.parseGlobalsSlug(a),c$1=l.isGlobal?this.globals.get(l.globalSlug):this.getCollection(a);this.ensureTable(c$1,l.tableName);let d$1=l.tableName,y=`SELECT * FROM ${d$1}`,u=[],p=[],f={...n};this.tenantContext&&c$1.tenantScoped&&(f=c({where:f},a,this.tenantContext,b).where||{});let E=c$1.fields.find(h=>h.name==="status"),b$1=E?.type==="select"&&Array.isArray(E.options)&&E.options.some(h=>h.value==="published");!r&&b$1&&(p.push("status = ?"),u.push("published")),s&&c$1.tenantScoped&&(p.push("tenant_id = ?"),u.push(s));for(let[h,m]of Object.entries(f)){if(h==="AND"||h==="OR")continue;let S=this.resolveCol(d$1,h);typeof m=="object"&&m!==null?(m.equals!==void 0&&(p.push(`${S} = ?`),u.push(m.equals)),m.in!==void 0&&(p.push(`${S} IN (${m.in.map(()=>"?").join(", ")})`),u.push(...m.in)),m.not_equals!==void 0&&(p.push(`${S} != ?`),u.push(m.not_equals))):(p.push(`${S} = ?`),u.push(m));}p.length>0&&(y+=` WHERE ${p.join(" AND ")}`);let g=i||"-createdAt",w=this.resolveCol(d$1,g),M=g.startsWith("-")?"DESC":"ASC";y+=` ORDER BY ${w} ${M}`;let U=y.replace("SELECT *","SELECT COUNT(*) as count"),D=this.db.prepare(U).get(...u)?.count||0;y+=" LIMIT ? OFFSET ?",u.push(o,(t-1)*o);let A=this.db.prepare(y).all(...u).map(h=>this.rowToDoc(h,c$1));return this.tenantContext&&!this.tenantContext.isSuperAdmin&&(A=A.filter(h=>d(h,a,this.tenantContext,b))),r&&(A=await Promise.all(A.map(async h=>{let m=this.db.prepare(`SELECT * FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ? AND tenant_id IS NULL ORDER BY version DESC LIMIT 1`).get(a,h.id);if(m){let S=m.data?JSON.parse(m.data):{};return a$1({...h,...S,status:h.status})}return h}))),A=A.map(h=>a$1(h)),{docs:A,totalDocs:D,limit:o,totalPages:Math.ceil(D/o),page:t,pagingCounter:(t-1)*o+1,hasPrevPage:t>1,hasNextPage:t<Math.ceil(D/o),prevPage:t>1?t-1:null,nextPage:t<Math.ceil(D/o)?t+1:null}}async findByID(e){let{collection:a,id:n,tenantId:i,draft:o=false}=e,t=this.parseGlobalsSlug(a),s=t.isGlobal?this.globals.get(t.globalSlug):this.getCollection(a);this.ensureTable(s,t.tableName);let l=`SELECT * FROM ${t.tableName} WHERE id = ?`,c=[n];if(this.tenantContext&&s.tenantScoped){let f={id:n,tenant_id:this.tenantContext.tenantId};if(!d(f,a,this.tenantContext,b))return null}let d$1=s.fields.find(f=>f.name==="status"),y=d$1?.type==="select"&&Array.isArray(d$1.options)&&d$1.options.some(f=>f.value==="published");!o&&y&&(l+=" AND status = ?",c.push("published")),i&&s.tenantScoped&&(l+=" AND tenant_id = ?",c.push(i));let u=this.db.prepare(l).get(...c);if(!u)return null;let p=this.rowToDoc(u,s);if(o){let f=this.db.prepare(`SELECT * FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ? AND tenant_id IS NULL ORDER BY version DESC LIMIT 1`).get(a,p.id);if(f){let E=f.data?JSON.parse(f.data):{};p={...p,...E,status:p.status};}}return a$1(p)}async create(e){let{collection:a,data:n,tenantId:i}=e,o=this.parseGlobalsSlug(a),t=o.isGlobal?this.globals.get(o.globalSlug):this.getCollection(a);this.ensureTable(t,o.tableName);let s=o.tableName,r=o.isGlobal?o.globalSlug:n.id||this.generateId(),l=this.prepareData(n,t);l.id=r;let c=new Date().toISOString();l.created_at=c,l.updated_at=c,i&&t.tenantScoped&&(l.tenant_id=i);let d=Object.keys(l),y=O(this.db,s),u={};for(let g of d)y.includes(g)&&(u[g]=l[g]);let p=Object.keys(u),f=p.map(g=>this.col(g)),E=p.map(()=>"?").join(", "),b=Object.values(u).map(g=>g!==null&&typeof g=="object"?JSON.stringify(g):g);return this.db.prepare(`INSERT OR REPLACE INTO ${s} (${f.join(", ")}) VALUES (${E})`).run(...b),this.ensureVersionsTable(),this.findByID({collection:a,id:r,tenantId:i,draft:true})}async update(e){let{collection:a,id:n,data:i,tenantId:o}=e,t=this.parseGlobalsSlug(a),s=t.isGlobal?this.globals.get(t.globalSlug):this.getCollection(a);this.ensureTable(s,t.tableName);let r=t.tableName,l=this.prepareData(i,s);l.updated_at=new Date().toISOString();let c=O(this.db,r),d={};for(let b of Object.keys(l))c.includes(b)&&(d[b]=l[b]);let u=Object.keys(d).map(b=>`${this.col(b)} = ?`).join(", "),p=Object.values(d).map(b=>b!==null&&typeof b=="object"?JSON.stringify(b):b),f=`UPDATE ${r} SET ${u} WHERE id = ?`,E=[...p,n];return o&&s.tenantScoped&&(f+=" AND tenant_id = ?",E.push(o)),this.db.prepare(f).run(...E),this.ensureVersionsTable(),this.findByID({collection:a,id:n,tenantId:o,draft:true})}async delete(e){let{collection:a,id:n,tenantId:i}=e,o=this.parseGlobalsSlug(a),t=o.isGlobal?this.globals.get(o.globalSlug):this.getCollection(a);this.ensureTable(t,o.tableName),this.ensureVersionsTable();let s=await this.findByID({collection:a,id:n,tenantId:i,draft:true});if(!s)throw new Error(`Document not found: ${a}/${n}`);let l=`DELETE FROM ${o.tableName} WHERE id = ?`,c=[n];return i&&t.tenantScoped&&(l+=" AND tenant_id = ?",c.push(i)),this.db.prepare(l).run(...c),s}async count(e){let{collection:a,tenantId:n}=e,i=this.parseGlobalsSlug(a),o=i.isGlobal?this.globals.get(i.globalSlug):this.getCollection(a);this.ensureTable(o,i.tableName);let s=`SELECT COUNT(*) as count FROM ${i.tableName}`,r=[];return n&&o.tenantScoped&&(s+=" WHERE tenant_id = ?",r.push(n)),this.db.prepare(s).get(...r)?.count||0}async findOne(e){let a=this.parseGlobalsSlug(e.collection);if(a.isGlobal){let i=this.globals.get(a.globalSlug);if(!i)throw new Error(`Global "${a.globalSlug}" not found in adapter`);this.ensureTable(i,a.tableName);let o=`SELECT * FROM ${a.tableName}`,t=[],s=[],r=i.fields.find(d=>d.name==="status"),l=r?.type==="select"&&Array.isArray(r.options)&&r.options.some(d=>d.value==="published");!e.draft&&i.versions&&l&&t.push("status = 'published'"),t.length>0&&(o+=` WHERE ${t.join(" AND ")}`),o+=" LIMIT 1";let c=this.db.prepare(o).get(...s);if(c){let d=this.rowToDoc(c,i);if(e.draft){let y=this.db.prepare(`SELECT * FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ? AND tenant_id IS NULL ORDER BY version DESC LIMIT 1`).get(e.collection,a.globalSlug);if(y){let u=y.data?JSON.parse(y.data):{};d={...d,...u,status:d.status};}}return d}return null}return (await this.find({...e,limit:1})).docs[0]||null}async findVersions(e){this.ensureVersionsTable();let{collection:a,documentId:n,tenantId:i,limit:o=20,page:t=1}=e,s=["collection_slug = ?","document_id = ?","autosave = 0"],r=[a,n];i?(s.push("tenant_id = ?"),r.push(i)):s.push("tenant_id IS NULL");let l=`WHERE ${s.join(" AND ")}`,d=this.db.prepare(`SELECT COUNT(*) as count FROM ${this.versionsTableName} ${l}`).get(...r)?.count||0,y=(t-1)*o;return {docs:this.db.prepare(`SELECT * FROM ${this.versionsTableName} ${l} ORDER BY version DESC LIMIT ? OFFSET ?`).all(...r,o,y).map(f=>this.rowToVersion(f)),totalDocs:d,limit:o,totalPages:Math.ceil(d/o),page:t,pagingCounter:(t-1)*o+1,hasPrevPage:t>1,hasNextPage:t<Math.ceil(d/o),prevPage:t>1?t-1:null,nextPage:t<Math.ceil(d/o)?t+1:null}}async findVersionByID(e){this.ensureVersionsTable();let a=this.db.prepare(`SELECT * FROM ${this.versionsTableName} WHERE id = ? AND collection_slug = ? LIMIT 1`).get(e.versionId,e.collection);return a?this.rowToVersion(a):null}async createVersion(e){this.ensureVersionsTable();let a=new Date().toISOString();if(e.autosave){let s=`SELECT * FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ? AND autosave = 1`,r=[e.collection,e.documentId];e.tenantId?(s+=" AND tenant_id = ?",r.push(e.tenantId)):s+=" AND tenant_id IS NULL",s+=" LIMIT 1";let l=this.db.prepare(s).get(...r);if(l){this.db.prepare(`UPDATE ${this.versionsTableName} SET data = ?, status = ?, updated_at = ? WHERE id = ?`).run(JSON.stringify(e.data),e.status,a,l.id);let c=await this.findVersionByID({collection:e.collection,versionId:l.id});if(c)return c}}let n=this.generateId(),o=(this.db.prepare(`SELECT version FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ? AND autosave = 0 ORDER BY version DESC LIMIT 1`).get(e.collection,e.documentId)?.version??0)+1;if(this.db.prepare(`INSERT INTO ${this.versionsTableName} (
19
+ id, collection_slug, document_id, tenant_id, version, status, autosave, data, created_by, change_description, published_at, created_at, updated_at
20
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(n,e.collection,e.documentId,e.tenantId??null,o,e.status,e.autosave?1:0,JSON.stringify(e.data),e.createdBy??null,e.changeDescription??null,e.status==="published"?a:null,a,a),!e.autosave){let r=this.collections.get(e.collection)?.versions?.maxPerDoc;r&&r>0&&await this.deleteVersions({collection:e.collection,documentId:e.documentId,keepLatest:r,tenantId:e.tenantId});}return await this.findVersionByID({collection:e.collection,versionId:n})}async updateLatestVersion(e){return this.createVersion({...e,autosave:true})}async deleteVersions(e){this.ensureVersionsTable();let{collection:a,documentId:n,keepLatest:i,tenantId:o}=e;if(i&&i>0){let t=this.db.prepare(`SELECT id, status, autosave FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ? ORDER BY version DESC`).all(a,n),s=0,r=[];for(let l of t)l.status==="published"||l.autosave===1||(s++,s>i&&r.push(l.id));for(let l of r)this.db.prepare(`DELETE FROM ${this.versionsTableName} WHERE id = ?`).run(l);}else {let t=`DELETE FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ?`,s=[a,n];o&&(t+=" AND tenant_id = ?",s.push(o)),this.db.prepare(t).run(...s);}}rowToVersion(e){return {id:String(e.id),collection:e.collection_slug,documentId:e.document_id,version:e.version,status:e.status,data:e.data?JSON.parse(e.data):{},createdBy:e.created_by??void 0,changeDescription:e.change_description??void 0,publishedAt:e.published_at??null,createdAt:e.created_at,updatedAt:e.updated_at}}prepareData(e,a){let n={},i=N(a.fields),o=(t,s)=>{let r=t;if(r.type==="json"||r.type==="richtext"||r.type==="array"||r.type==="group"||r.type==="blocks"||r.type==="list"||r.type==="relationship-block")return s!=null?JSON.stringify(s):null;if(r.type==="checkbox")return s?1:0;if(r.type==="number")return s!==null&&s!==""?Number(s):null;if(r.type==="upload"||r.type==="image"){if(s==null)return null;if(Array.isArray(s)){let l=s.map(c=>typeof c=="string"?c:typeof c=="object"?c.id||c._id||c:String(c));return JSON.stringify(l)}return typeof s=="string"?s:typeof s=="object"?JSON.stringify(s):String(s)}else if(t.type==="relationship"){if(s==null)return null;if(Array.isArray(s)){let l=s.map(c=>typeof c=="string"?c:typeof c=="object"?JSON.stringify({relationTo:t.relationTo,value:c.id||c}):String(c));return JSON.stringify(l)}return typeof s=="string"?s:typeof s=="object"?JSON.stringify({relationTo:t.relationTo,value:s.id||s}):String(s)}return s};for(let t of i){if(!t.name||t.name==="id"||a.fields.some(l=>l.type==="tabs"&&l.name&&"tabs"in l&&l.tabs.some(c=>c.fields.some(d=>d.name===t.name))))continue;let r=e[t.name];r!==void 0&&(n[t.name]=o(t,r));}for(let t of a.fields)if(t.type==="tabs"&&"tabs"in t&&t.name){let s=e[t.name];if(s&&typeof s=="object"){for(let r of t.tabs)for(let l of r.fields)if(l.name&&l.name!=="id"){let c=s[l.name];c!==void 0&&(n[l.name]=o(l,c));}}}return n}rowToDoc(e,a){let n={id:e.id};for(let i of N(a.fields)){if(!i.name||i.name==="id")continue;let o=i,t=e[o.name];if(o.type==="json"||o.type==="richtext"||o.type==="array"||o.type==="group"||o.type==="blocks"||o.type==="list"||o.type==="relationship-block")try{t=t?JSON.parse(t):null;}catch{t=null;}if(o.type==="blocks"&&t&&Array.isArray(t)){let s=o.blocks||[];t=P(t,s);}if(i.type==="checkbox"&&(t=!!t),i.type==="date"&&t)try{let s=new Date(t);isNaN(s.getTime())?(console.warn(`[LocalAdapter] Invalid date value for field "${i.name}":`,t),t=null):t=s.toISOString();}catch{t=null;}if((i.type==="upload"||i.type==="image")&&t)try{let s=JSON.parse(t);Array.isArray(s)?t=s.map(r=>typeof r=="object"&&r!==null?r:{id:r}):t=typeof s=="object"?s:{id:s};}catch{t={id:t};}if(i.type==="relationship"&&t)try{let s=JSON.parse(t);Array.isArray(s),t=s;}catch{t={relationTo:Array.isArray(i.relationTo)?i.relationTo[0]:i.relationTo,value:t};}n[i.name]=t;}for(let i of a.fields)if(!(!i.name||i.name==="id"||i.name==="row"||i.name==="collapsible")&&i.type==="tabs"&&"tabs"in i){let o={};for(let t of i.tabs)for(let s of t.fields)s.name&&s.name!=="id"&&(o[s.name]=B(e,s));n[i.name]=o;}if(a.timestamps){let i=e.createdAt||e.created_at,o=e.updatedAt||e.updated_at;if(i)try{let t=new Date(i);isNaN(t.getTime())||(n.createdAt=t.toISOString());}catch{}if(o)try{let t=new Date(o);isNaN(t.getTime())||(n.updatedAt=t.toISOString());}catch{}}a.tenantScoped&&(n.tenantId=e.tenant_id),n.status=e.status??"published",n.hasDraft=e.hasDraft?!!e.hasDraft:false;for(let i of Object.keys(n))/^\d+$/.test(i)&&delete n[i];return n}generateId(){let e=Date.now().toString(16).padStart(12,"0"),a=randomBytes(6).toString("hex");return e+a}getMediaById(e){try{let a=this.getTableNameFor("media"),n=this.db.prepare(`SELECT id, url, thumbnail_url FROM ${a} WHERE id = ?`).get(e);if(n)return {id:n.id,url:n.url,thumbnailUrl:n.thumbnail_url||n.url}}catch{}return null}getTableNameFor(e){return e.replace(/-/g,"_")}async migrate(){for(let e of this.collections.values())this.ensureTable(e);}async rollback(){}async transaction(e){return new Promise((a,n)=>{let i=this.db.transaction(async()=>e({db:this.db}));try{let o=i();a(o);}catch(o){n(o);}})}getDatabase(){return this.db}exec(e){this.db.exec(e);}prepare(e){return this.db.prepare(e)}};function k(T){return new L(T||{})}export{L as a,k as b};
@@ -0,0 +1 @@
1
+ 'use strict';var chunkVRZC4TTF_cjs=require('./chunk-VRZC4TTF.cjs'),chunkBUNLC3II_cjs=require('./chunk-BUNLC3II.cjs');chunkBUNLC3II_cjs.h();chunkBUNLC3II_cjs.h();function p(r){return chunkVRZC4TTF_cjs.J`count(${r||chunkVRZC4TTF_cjs.J.raw("*")})`.mapWith(Number)}function a(r){return chunkVRZC4TTF_cjs.J`count(distinct ${r})`.mapWith(Number)}function s(r){return chunkVRZC4TTF_cjs.J`avg(${r})`.mapWith(String)}function x(r){return chunkVRZC4TTF_cjs.J`avg(distinct ${r})`.mapWith(String)}function y(r){return chunkVRZC4TTF_cjs.J`sum(${r})`.mapWith(String)}function g(r){return chunkVRZC4TTF_cjs.J`sum(distinct ${r})`.mapWith(String)}function A(r){return chunkVRZC4TTF_cjs.J`max(${r})`.mapWith(chunkVRZC4TTF_cjs.c(r,chunkVRZC4TTF_cjs.d)?r:String)}function h(r){return chunkVRZC4TTF_cjs.J`min(${r})`.mapWith(chunkVRZC4TTF_cjs.c(r,chunkVRZC4TTF_cjs.d)?r:String)}chunkBUNLC3II_cjs.h();function o(r){return JSON.stringify(r)}function d(r,t){return Array.isArray(t)?chunkVRZC4TTF_cjs.J`${r} <-> ${o(t)}`:chunkVRZC4TTF_cjs.J`${r} <-> ${t}`}function q(r,t){return Array.isArray(t)?chunkVRZC4TTF_cjs.J`${r} <+> ${o(t)}`:chunkVRZC4TTF_cjs.J`${r} <+> ${t}`}function N(r,t){return Array.isArray(t)?chunkVRZC4TTF_cjs.J`${r} <#> ${o(t)}`:chunkVRZC4TTF_cjs.J`${r} <#> ${t}`}function b(r,t){return Array.isArray(t)?chunkVRZC4TTF_cjs.J`${r} <=> ${o(t)}`:chunkVRZC4TTF_cjs.J`${r} <=> ${t}`}function j(r,t){return Array.isArray(t)?chunkVRZC4TTF_cjs.J`${r} <~> ${o(t)}`:chunkVRZC4TTF_cjs.J`${r} <~> ${t}`}function w(r,t){return Array.isArray(t)?chunkVRZC4TTF_cjs.J`${r} <%> ${o(t)}`:chunkVRZC4TTF_cjs.J`${r} <%> ${t}`}exports.a=p;exports.b=a;exports.c=s;exports.d=x;exports.e=y;exports.f=g;exports.g=A;exports.h=h;exports.i=d;exports.j=q;exports.k=N;exports.l=b;exports.m=j;exports.n=w;
@@ -0,0 +1,3 @@
1
+ import {createRequire}from'module';import {a as a$1,h}from'./chunk-E27KEZPT.js';import {a}from'./chunk-BLH2MRK4.js';import {a as a$2}from'./chunk-6KRR7YHA.js';import {g}from'./chunk-C2PXMVR5.js';import {createHmac,randomBytes,randomUUID}from'crypto';createRequire(import.meta.url);
2
+ g();var _={COLLECTION_CREATE:"collection.create",COLLECTION_UPDATE:"collection.update",COLLECTION_DELETE:"collection.delete",MEDIA_UPLOAD:"media.upload",MEDIA_DELETE:"media.delete",AUTH_LOGIN:"auth.login",AUTH_REGISTER:"auth.register",AUTH_LOGOUT:"auth.logout",ORDER_CREATED:"order.created",ORDER_PAID:"order.paid",ORDER_SHIPPED:"order.shipped",ORDER_DELIVERED:"order.delivered"},G=Object.values(_);var k="_webhooks",w="_webhook_deliveries";g();g();g();g();async function L(o,t,s,e={}){let r=e.timeout||3e4,i=Date.now(),u=new AbortController,c=setTimeout(()=>u.abort(),r);try{let a=await fetch(o,{method:"POST",headers:t,body:s,signal:u.signal});clearTimeout(c);let n=Date.now()-i,l;try{l=(await a.text()).slice(0,1e3);}catch{}let d={success:a.ok,status:a.status,statusText:a.statusText,body:l,duration:n};return d.success&&e.onSuccess?e.onSuccess(d):!d.success&&e.onFailure&&e.onFailure(`HTTP ${a.status}: ${a.statusText}`),d}catch(a){clearTimeout(c);let n=Date.now()-i,l=a.name==="AbortError"?`Request timed out after ${r}ms`:a.message||"Unknown error";return e.onFailure&&e.onFailure(l),{success:false,status:0,duration:n,error:l}}}async function $(o,t,s={}){let e=JSON.stringify(t),r={"Content-Type":"application/json","User-Agent":"Kyro-CMS-Webhook/1.0","X-Webhook-Event":t.event,"X-Webhook-Delivery":t.id,"X-Webhook-Timestamp":t.timestamp,...o.headers||{}};return o.secret&&(r["X-Webhook-Signature"]=P(e,o.secret)),L(o.url,r,e,s)}g();async function j(o,t,s={}){let e=o.config||{},r=process.env.GITHUB_TOKEN;if(!r)return {success:false,status:0,duration:0,error:"GITHUB_TOKEN environment variable is not set"};if(!e.githubOwner||!e.githubRepo)return {success:false,status:0,duration:0,error:"GitHub owner and repo are required"};let i=e.githubBranch||"main",u=Date.now(),c=async(a,n,l)=>{let d=await fetch(a,{method:n,headers:{"Content-Type":"application/json",Accept:"application/vnd.github+json",Authorization:`Bearer ${r}`,"X-GitHub-Api-Version":"2022-11-28","User-Agent":"Kyro-CMS-Webhook/1.0"},body:l?JSON.stringify(l):void 0});if(!d.ok){let y=await d.text();throw new Error(`GitHub API HTTP ${d.status}: ${y}`)}return d.json()};try{let a=`https://api.github.com/repos/${e.githubOwner}/${e.githubRepo}/git/refs/heads/${i}`,l=(await c(a,"GET")).object.sha,d=`https://api.github.com/repos/${e.githubOwner}/${e.githubRepo}/git/commits/${l}`,f=(await c(d,"GET")).tree.sha,p=`https://api.github.com/repos/${e.githubOwner}/${e.githubRepo}/git/commits`,b=(await c(p,"POST",{message:`Content updated via Kyro CMS (${t.event})`,tree:f,parents:[l]})).sha;return await c(a,"PATCH",{sha:b,force:!1}),{success:!0,status:201,duration:Date.now()-u,body:`Successfully pushed empty commit ${b} to branch ${i}`}}catch(a){return {success:false,status:0,duration:Date.now()-u,error:a.message||"Failed to push empty commit to GitHub"}}}var K={generic:$,"github-push":j};function S(o){return K[o||"generic"]||K.generic}function P(o,t){return `sha256=${createHmac("sha256",t).update(o).digest("hex")}`}function x(){return randomBytes(32).toString("hex")}async function U(o,t,s={}){return S(o.action)(o,t,s)}async function I(o,t,s,e={}){let r=e.maxRetries??5,i=e.retryDelay??1e3,u=null;for(let c=0;c<=r;c++){if(c>0){let a=Math.min(i*Math.pow(2,c-1),3e4);e.onRetry&&e.onRetry(c,`Retrying in ${a}ms...`),await F(a);}if(e.onRetry&&c>0&&e.onRetry(c,`Attempt ${c+1}/${r+1}`),u=await U(o,t,{...e,onRetry:void 0,onSuccess:void 0,onFailure:void 0}),u.success)return u;if(!(u.error?.includes("timed out")&&c<r)&&u.status>=400&&u.status<500)return u}return u||{success:false,status:0,duration:0,error:"All delivery attempts failed"}}function H(o,t,s,e,r,i){return {id:o,webhookId:t,event:s,payload:e,attempt:r,status:i.success?"success":"failed",responseStatus:i.status||void 0,responseBody:i.body,duration:i.duration,error:i.error,createdAt:new Date().toISOString(),deliveredAt:i.success?new Date().toISOString():void 0}}function F(o){return new Promise(t=>setTimeout(t,o))}function z(){return {id:`test_${Date.now()}`,event:"collection.create",timestamp:new Date().toISOString(),collection:"test",operation:"create",data:{message:"This is a test webhook delivery"},user:{id:"system",email:"system@kyro.dev",role:"super_admin"}}}g();function N(o){let t=new Set,s=[];for(let e of o){let r=e==="create"||e==="update"||e==="delete"?`collection.${e}`:e;t.has(r)||(t.add(r),s.push(r));}return s}var O=class{db;constructor(t){this.db=t;}async getWebhooks(t){let e=(await this.db.find({collection:k,where:t?.status?{status:{equals:t.status}}:{},limit:100,page:1,draft:true})).docs;return t?.event?e.filter(r=>r.events.includes(t.event)):e}async getWebhookById(t){return this.db.findByID({collection:k,id:t,draft:true})}async createWebhook(t){let s=new Date().toISOString(),e=t.secret||x(),r={id:randomUUID(),name:t.name,url:t.url,events:N(t.events),collections:t.collections||[],status:t.status||"active",secret:e,headers:t.headers||{},action:t.action||"generic",config:t.config||{},createdAt:s,updatedAt:s};return await this.db.create({collection:k,data:r}),r}async updateWebhook(t,s){let e=await this.getWebhookById(t);if(!e)return null;let r={...e,...s,events:s.events?N(s.events):e.events,collections:s.collections!==void 0?s.collections:e.collections,action:s.action!==void 0?s.action:e.action,config:s.config!==void 0?{...e.config,...s.config}:e.config,updatedAt:new Date().toISOString()};return s.secret===""&&"secret"in s&&delete r.secret,await this.db.update({collection:k,id:t,data:r}),r}async deleteWebhook(t){await this.db.delete({collection:k,id:t});}async trigger(t,s){let e=await this.getWebhooks({status:"active",event:t}),r=s.collection,i=e.filter(a=>!a.collections||a.collections.length===0||!r?true:a.collections.includes(r));if(i.length===0)return [];let u={id:randomUUID(),event:t,timestamp:new Date().toISOString(),...s},c=[];for(let a of i){let n=await this.triggerWebhook(a,u);c.push(n);}return c}async triggerWebhook(t,s){let e=randomUUID();try{let r=await I(t,s,e,{maxRetries:5,retryDelay:1e3}),i=H(e,t.id,t.events[0],s,1,r);try{await this.db.create({collection:w,data:i});}catch{console.warn("[WebhookService] Failed to save delivery record:",e);}return r.success?await this.updateWebhook(t.id,{lastTriggered:new Date().toISOString(),lastError:null}).catch(()=>{}):await this.updateWebhook(t.id,{lastError:r.error||`HTTP ${r.status}`}).catch(()=>{}),{deliveryId:e,webhookId:t.id,event:t.events[0],status:r.success?"success":"failed",responseStatus:r.status,duration:r.duration,error:r.error}}catch(r){return {deliveryId:e,webhookId:t.id,event:t.events[0],status:"failed",error:r.message}}}async testWebhook(t){let s=await this.getWebhookById(t);if(!s)return null;let e={id:randomUUID(),event:s.events[0]||"collection.create",timestamp:new Date().toISOString(),collection:"test",operation:"create",data:{message:"This is a test webhook delivery from Kyro CMS"},user:{id:"system",email:"system@kyro.dev",role:"super_admin"}};return this.triggerWebhook(s,e)}async getDeliveryHistory(t,s=50){return (await this.db.find({collection:w,where:{webhookId:{equals:t}},sort:"-createdAt",limit:s,page:1})).docs}async retryDelivery(t){let s=await this.db.findByID({collection:w,id:t});if(!s)return null;let e=await this.getWebhookById(s.webhookId);return e?this.triggerWebhook(e,s.payload):null}};function X(o){return new O(o)}g();g();function Y(o){if(!o)return [];if(typeof o=="string")return [{id:o}];if(Array.isArray(o))return o.map(t=>typeof t=="object"?{id:t.value??t.id??t,relationTo:t.relationTo}:{id:t});if(typeof o=="object"){let t=o.value??o.id??o;if(typeof t=="string")return [{id:t,relationTo:o.relationTo}];if(Array.isArray(t))return t.map(s=>({id:s,relationTo:o.relationTo}))}return []}function W(o,t,s){if(!(!o||typeof o!="object")){for(let e of t)if(!(!e.name&&e.type!=="row"&&e.type!=="collapsible"&&e.type!=="tabs")){if(e.type==="relationship"||e.type==="upload")s(e,o);else if(e.type==="group"||e.type==="collapsible"||e.type==="row"){let r=e.name?o[e.name]:o;W(r,e.fields||[],s);}else if(e.type==="tabs"&&e.tabs){let r=e.name?o[e.name]:o;for(let i of e.tabs)W(r,i.fields||[],s);}else if(e.type==="array"&&e.name&&Array.isArray(o[e.name]))for(let r of o[e.name])W(r,e.fields||[],s);else if(e.type==="blocks"&&e.name&&Array.isArray(o[e.name]))for(let r of o[e.name]){if(!r||typeof r!="object")continue;let i=r.type||r.blockType;if(!i)continue;let u=e.blocks?.find(c=>c.slug===i);if(u&&Array.isArray(u.fields)){let c=r.data&&typeof r.data=="object"?r.data:r;W(c,u.fields,s);}}}}}function J(o,t,s){W(o,t,(e,r)=>{let i=r[e.name];if(!i)return;let u=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],c=Y(i);for(let a of c){if(!a.id)continue;let n=a.relationTo?[a.relationTo]:u;for(let l of n)l!=="*"&&(s.has(l)||s.set(l,new Set),s.get(l).add(a.id));}});}function Q(o,t,s){W(o,t,(e,r)=>{let i=r[e.name];if(!i)return;let u=Array.isArray(e.relationTo)?e.relationTo:[e.relationTo],c=n=>{r[e.name]=n;},a=(n,l)=>{let d=l?[l]:u;for(let y of d){let f=s.get(y);if(f&&f.has(n))return f.get(n)}return null};if(typeof i=="string"){let n=a(i);c(n||{id:i});}else if(Array.isArray(i))c(i.map(n=>{let l=typeof n=="object"?n.value??n.id:n,d=typeof n=="object"?n.relationTo:void 0,y=a(l,d);return y||{id:l}}));else if(typeof i=="object"){let n=i.value??i.id,l=i.relationTo,d=a(n,l);c(d||{id:n});}});}async function Z(o,t,s,e,r=1,i=0){if(!o||o.length===0||r>i)return;let u=new Map;for(let n of o)J(n,t,u);if(u.size===0)return;let c=new Map,a$1=new Map;for(let[n,l]of u.entries()){if(l.size===0||!e.getCollection(n))continue;let y=new Map,f=Array.from(l),p=[];for(let E of f){try{let v=(await s.find({collection:n,where:{id:{in:f}},limit:f.length,draft:!0}))?.docs||[];for(let A of v)A&&A.id&&(y.set(String(A.id),A),p.push(A));}catch{for(let b of f)try{let v=await s.findByID({collection:n,id:b,draft:!0});v&&(y.set(b,v),p.push(v));}catch{}}break}c.set(n,y),p.length>0&&a$1.set(n,p);}if(r<i)for(let[n,l]of a$1.entries()){let d=e.getCollection(n);d&&await Z(l,d.fields,s,e,r+1,i);}for(let n=0;n<o.length;n++)Q(o[n],t,c),o[n]=a(o[n]);}g();function M(o){return o==="read"?"read":o==="create"?"create":o==="update"?"update":"delete"}function ee(o,t){return {none:false,read:o==="read",create:o==="read"||o==="create",update:o==="read"||o==="create"||o==="update",delete:o==="read"||o==="create"||o==="update"||o==="delete",admin:true}[t]||false}async function Le(o,t,s,e={}){let{user:r,req:i,tenantId:u,apiKey:c}=s,{enablePublicAccess:a=true,defaultAccess:n="none"}=e,l=o.access?.[t];if(l){let y=await a$1(l,{req:i,user:r,tenantId:u});return y===false?{allowed:false,error:"Access denied",status:403}:typeof y=="object"?{allowed:true,extraWhere:y}:{allowed:true}}if(c?.permissions?.length>0){let y=o.slug,f=M(t),p=`${y}:${f}`;return !h(c.permissions,p)&&!h(c.permissions,`${y}:admin`)?{allowed:false,error:"Access denied: insufficient permissions",status:403}:{allowed:true}}if(r){let y=o.slug,f=M(t),p=`${y}:${f}`,E=a$2({id:r.id,email:r.email,role:r.role},p),b=a$2({id:r.id,email:r.email,role:r.role},`${y}:admin`);return E||b?{allowed:true}:{allowed:false,error:"Access denied: missing RBAC permission",status:403}}let d=ee(t,n);return a&&d?{allowed:true}:{allowed:false,error:"Authentication required",status:401}}async function $e(o,t,s,e={}){let{user:r,req:i,tenantId:u}=s,{enablePublicAccess:c=true}=e,a=o.access?.[t];if(a)return await a$1(a,{req:i,user:r,tenantId:u})===false?{allowed:false,error:"Access denied",status:403}:{allowed:true};if(r){let n=`globals:${t}`,l=a$2({id:r.id,email:r.email,role:r.role},n),d=a$2({id:r.id,email:r.email,role:r.role},"globals:admin");return l||d?{allowed:true}:{allowed:false,error:"Access denied: missing RBAC permission",status:403}}return c?{allowed:true}:{allowed:false,error:"Authentication required",status:401}}
3
+ export{Z as a,Le as b,$e as c,_ as d,G as e,k as f,w as g,P as h,x as i,U as j,I as k,H as l,z as m,O as n,X as o};
@@ -0,0 +1,14 @@
1
+ import {createRequire}from'module';import {b}from'./chunk-VBPAAQEF.js';import {f,R as R$1,h,g as g$1,S as S$1,X as X$1,p,n,P,j,Q,d as d$1}from'./chunk-IP6JUEH3.js';import {t,a,Y,N,J as J$1,c,A,d,R,v,i,l,H as H$1,w,e,f as f$1,_}from'./chunk-7AQSH3KR.js';import {g}from'./chunk-C2PXMVR5.js';createRequire(import.meta.url);
2
+ g();g();g();var X=class{static[a]="SQLiteForeignKeyBuilder";reference;_onUpdate;_onDelete;constructor(e,t){this.reference=()=>{let{name:n,columns:s,foreignColumns:o}=e();return {name:n,columns:s,foreignTable:o[0].table,foreignColumns:o}},t&&(this._onUpdate=t.onUpdate,this._onDelete=t.onDelete);}onUpdate(e){return this._onUpdate=e,this}onDelete(e){return this._onDelete=e,this}build(e){return new re(e,this)}},re=class{constructor(e,t){this.table=e,this.reference=t.reference,this.onUpdate=t._onUpdate,this.onDelete=t._onDelete;}static[a]="SQLiteForeignKey";reference;onUpdate;onDelete;getName(){let{name:e,columns:t,foreignColumns:n}=this.reference(),s=t.map(r=>r.name),o=n.map(r=>r.name),u=[this.table[f$1],...s,n[0].table[f$1],...o];return e??`${u.join("_")}_fk`}};g();function ue(a,e){return `${a[f$1]}_${e.join("_")}_unique`}var q=class extends e{static[a]="SQLiteColumnBuilder";foreignKeyConfigs=[];references(e,t={}){return this.foreignKeyConfigs.push({ref:e,actions:t}),this}unique(e){return this.config.isUnique=true,this.config.uniqueName=e,this}generatedAlwaysAs(e,t){return this.config.generated={as:e,type:"always",mode:t?.mode??"virtual"},this}buildForeignKeys(e,t){return this.foreignKeyConfigs.map(({ref:n,actions:s})=>((o,u)=>{let r=new X(()=>{let c=o();return {columns:[e],foreignColumns:[c]}});return u.onUpdate&&r.onUpdate(u.onUpdate),u.onDelete&&r.onDelete(u.onDelete),r.build(t)})(n,s))}},S=class extends d{constructor(e,t){t.uniqueName||(t.uniqueName=ue(e,[t.name])),super(e,t),this.table=e;}static[a]="SQLiteColumn"};var k=class extends q{static[a]="SQLiteBaseIntegerBuilder";constructor(e,t,n){super(e,t,n),this.config.autoIncrement=false;}primaryKey(e){return e?.autoIncrement&&(this.config.autoIncrement=true),this.config.hasDefault=true,super.primaryKey()}},J=class extends S{static[a]="SQLiteBaseInteger";autoIncrement=this.config.autoIncrement;getSQLType(){return "integer"}},ae=class extends k{static[a]="SQLiteIntegerBuilder";constructor(e){super(e,"number","SQLiteInteger");}build(e){return new le(e,this.config)}},le=class extends J{static[a]="SQLiteInteger"},me=class extends k{static[a]="SQLiteTimestampBuilder";constructor(e,t){super(e,"date","SQLiteTimestamp"),this.config.mode=t;}defaultNow(){return this.default(J$1`(cast((julianday('now') - 2440587.5)*86400000 as integer))`)}build(e){return new ce(e,this.config)}},ce=class extends J{static[a]="SQLiteTimestamp";mode=this.config.mode;mapFromDriverValue(e){return this.config.mode==="timestamp"?new Date(e*1e3):new Date(e)}mapToDriverValue(e){let t=e.getTime();return this.config.mode==="timestamp"?Math.floor(t/1e3):t}},fe=class extends k{static[a]="SQLiteBooleanBuilder";constructor(e,t){super(e,"boolean","SQLiteBoolean"),this.config.mode=t;}build(e){return new de(e,this.config)}},de=class extends J{static[a]="SQLiteBoolean";mode=this.config.mode;mapFromDriverValue(e){return Number(e)===1}mapToDriverValue(e){return e?1:0}};function Ge(a,e){let{name:t,config:n}=Y(a,e);return n?.mode==="timestamp"||n?.mode==="timestamp_ms"?new me(t,n.mode):n?.mode==="boolean"?new fe(t,n.mode):new ae(t)}g();var pe=class extends q{static[a]="SQLiteNumericBuilder";constructor(e){super(e,"string","SQLiteNumeric");}build(e){return new he(e,this.config)}},he=class extends S{static[a]="SQLiteNumeric";mapFromDriverValue(e){return typeof e=="string"?e:String(e)}getSQLType(){return "numeric"}},ge=class extends q{static[a]="SQLiteNumericNumberBuilder";constructor(e){super(e,"number","SQLiteNumericNumber");}build(e){return new ye(e,this.config)}},ye=class extends S{static[a]="SQLiteNumericNumber";mapFromDriverValue(e){return typeof e=="number"?e:Number(e)}mapToDriverValue=String;getSQLType(){return "numeric"}},be=class extends q{static[a]="SQLiteNumericBigIntBuilder";constructor(e){super(e,"bigint","SQLiteNumericBigInt");}build(e){return new Se(e,this.config)}},Se=class extends S{static[a]="SQLiteNumericBigInt";mapFromDriverValue=BigInt;mapToDriverValue=String;getSQLType(){return "numeric"}};function He(a,e){let{name:t,config:n}=Y(a,e),s=n?.mode;return s==="number"?new ge(t):s==="bigint"?new be(t):new pe(t)}g();var $e=class extends q{static[a]="SQLiteTextBuilder";constructor(e,t){super(e,"string","SQLiteText"),this.config.enumValues=t.enum,this.config.length=t.length;}build(e){return new Te(e,this.config)}},Te=class extends S{static[a]="SQLiteText";enumValues=this.config.enumValues;length=this.config.length;constructor(e,t){super(e,t);}getSQLType(){return `text${this.config.length?`(${this.config.length})`:""}`}},Ce=class extends q{static[a]="SQLiteTextJsonBuilder";constructor(e){super(e,"json","SQLiteTextJson");}build(e){return new we(e,this.config)}},we=class extends S{static[a]="SQLiteTextJson";getSQLType(){return "text"}mapFromDriverValue(e){return JSON.parse(e)}mapToDriverValue(e){return JSON.stringify(e)}};function Ze(a,e={}){let{name:t,config:n}=Y(a,e);return n.mode==="json"?new Ce(t):new $e(t,n)}g();g();g();var Le=class extends q{static[a]="SQLiteBigIntBuilder";constructor(e){super(e,"bigint","SQLiteBigInt");}build(e){return new qe(e,this.config)}},qe=class extends S{static[a]="SQLiteBigInt";getSQLType(){return "blob"}mapFromDriverValue(e){if(typeof Buffer<"u"&&Buffer.from){let t=Buffer.isBuffer(e)?e:e instanceof ArrayBuffer?Buffer.from(e):e.buffer?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);return BigInt(t.toString("utf8"))}return BigInt(_.decode(e))}mapToDriverValue(e){return Buffer.from(e.toString())}},xe=class extends q{static[a]="SQLiteBlobJsonBuilder";constructor(e){super(e,"json","SQLiteBlobJson");}build(e){return new Qe(e,this.config)}},Qe=class extends S{static[a]="SQLiteBlobJson";getSQLType(){return "blob"}mapFromDriverValue(e){if(typeof Buffer<"u"&&Buffer.from){let t=Buffer.isBuffer(e)?e:e instanceof ArrayBuffer?Buffer.from(e):e.buffer?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);return JSON.parse(t.toString("utf8"))}return JSON.parse(_.decode(e))}mapToDriverValue(e){return Buffer.from(JSON.stringify(e))}},Be=class extends q{static[a]="SQLiteBlobBufferBuilder";constructor(e){super(e,"buffer","SQLiteBlobBuffer");}build(e){return new Ne(e,this.config)}},Ne=class extends S{static[a]="SQLiteBlobBuffer";mapFromDriverValue(e){return Buffer.isBuffer(e)?e:Buffer.from(e)}getSQLType(){return "blob"}};function et(a,e){let{name:t,config:n}=Y(a,e);return n?.mode==="json"?new xe(t):n?.mode==="bigint"?new Le(t):new Be(t)}g();var Oe=class extends q{static[a]="SQLiteCustomColumnBuilder";constructor(e,t,n){super(e,"custom","SQLiteCustomColumn"),this.config.fieldConfig=t,this.config.customTypeParams=n;}build(e){return new ve(e,this.config)}},ve=class extends S{static[a]="SQLiteCustomColumn";sqlName;mapTo;mapFrom;constructor(e,t){super(e,t),this.sqlName=t.customTypeParams.dataType(t.fieldConfig),this.mapTo=t.customTypeParams.toDriver,this.mapFrom=t.customTypeParams.fromDriver;}getSQLType(){return this.sqlName}mapFromDriverValue(e){return typeof this.mapFrom=="function"?this.mapFrom(e):e}mapToDriverValue(e){return typeof this.mapTo=="function"?this.mapTo(e):e}};function tt(a){return (e,t)=>{let{name:n,config:s}=Y(e,t);return new Oe(n,s,a)}}g();var _e=class extends q{static[a]="SQLiteRealBuilder";constructor(e){super(e,"number","SQLiteReal");}build(e){return new De(e,this.config)}},De=class extends S{static[a]="SQLiteReal";getSQLType(){return "real"}};function it(a){return new _e(a??"")}function nt(){return {blob:et,customType:tt,integer:Ge,numeric:He,real:it,text:Ze}}var Ke=Symbol.for("drizzle:SQLiteInlineForeignKeys"),F=class extends t{static[a]="SQLiteTable";static Symbol=Object.assign({},t.Symbol,{InlineForeignKeys:Ke});[t.Symbol.Columns];[Ke]=[];[t.Symbol.ExtraConfigBuilder]=void 0};function lt(a,e,t$1,n,s=a){let o=new F(a,n,s),u=typeof e=="function"?e(nt()):e,r=Object.fromEntries(Object.entries(u).map(([f,p])=>{let $=p;$.setName(f);let x=$.build(o);return o[Ke].push(...$.buildForeignKeys(x,o)),[f,x]})),c=Object.assign(o,r);return c[t.Symbol.Columns]=r,c[t.Symbol.ExtraConfigColumns]=r,t$1&&(c[F.Symbol.ExtraConfigBuilder]=t$1),c}var fi=(a,e,t)=>lt(a,e,t);g();g();var G=class extends N{static[a]="SQLiteViewBase"};var H=class{static[a]="SQLiteDialect";casing;constructor(e){this.casing=new b(e?.casing);}escapeName(e){return `"${e}"`}escapeParam(e){return "?"}escapeString(e){return `'${e.replace(/'/g,"''")}'`}buildWithCTE(e){if(!e?.length)return;let t=[J$1`with `];for(let[n,s]of e.entries())t.push(J$1`${J$1.identifier(s._.alias)} as (${s._.sql})`),n<e.length-1&&t.push(J$1`, `);return t.push(J$1` `),J$1.join(t)}buildDeleteQuery({table:e,where:t,returning:n,withList:s,limit:o,orderBy:u}){let r=this.buildWithCTE(s),c=n?J$1` returning ${this.buildSelection(n,{isSingleTable:true})}`:void 0,f=t?J$1` where ${t}`:void 0,p=this.buildOrderBy(u),$=this.buildLimit(o);return J$1`${r}delete from ${e}${f}${c}${p}${$}`}buildUpdateSet(e,t$1){let n=e[t.Symbol.Columns],s=Object.keys(n).filter(u=>t$1[u]!==void 0||n[u]?.onUpdateFn!==void 0),o=s.length;return J$1.join(s.flatMap((u,r)=>{let c=n[u],f=t$1[u]??J$1.param(c.onUpdateFn(),c),p=J$1`${J$1.identifier(this.casing.getColumnCasing(c))} = ${f}`;return r<o-1?[p,J$1.raw(", ")]:[p]}))}buildUpdateQuery({table:e,set:t,where:n,returning:s,withList:o,joins:u,from:r,limit:c,orderBy:f}){let p=this.buildWithCTE(o),$=this.buildUpdateSet(e,t),x=r&&J$1.join([J$1.raw(" from "),this.buildFromTable(r)]),Q=this.buildJoins(u),w=s?J$1` returning ${this.buildSelection(s,{isSingleTable:true})}`:void 0,b=n?J$1` where ${n}`:void 0,T=this.buildOrderBy(f),C=this.buildLimit(c);return J$1`${p}update ${e} set ${$}${x}${Q}${b}${w}${T}${C}`}buildSelection(e,{isSingleTable:t$1=false}={}){let n=e.length,s=e.flatMap(({field:o},u)=>{let r=[];if(c(o,A.Aliased)&&o.isSelectionField)r.push(J$1.identifier(o.fieldAlias));else if(c(o,A.Aliased)||c(o,A)){let c$1=c(o,A.Aliased)?o.sql:o;t$1?r.push(new A(c$1.queryChunks.map(f=>c(f,d)?J$1.identifier(this.casing.getColumnCasing(f)):f))):r.push(c$1),c(o,A.Aliased)&&r.push(J$1` as ${J$1.identifier(o.fieldAlias)}`);}else if(c(o,d)){let c=o.table[t.Symbol.Name];o.columnType==="SQLiteNumericBigInt"?t$1?r.push(J$1`cast(${J$1.identifier(this.casing.getColumnCasing(o))} as text)`):r.push(J$1`cast(${J$1.identifier(c)}.${J$1.identifier(this.casing.getColumnCasing(o))} as text)`):t$1?r.push(J$1.identifier(this.casing.getColumnCasing(o))):r.push(J$1`${J$1.identifier(c)}.${J$1.identifier(this.casing.getColumnCasing(o))}`);}return u<n-1&&r.push(J$1`, `),r});return J$1.join(s)}buildJoins(e){if(!e||e.length===0)return;let t=[];if(e)for(let[n,s]of e.entries()){n===0&&t.push(J$1` `);let o=s.table,u=s.on?J$1` on ${s.on}`:void 0;if(c(o,F)){let r=o[F.Symbol.Name],c=o[F.Symbol.Schema],f=o[F.Symbol.OriginalName],p=r===f?void 0:s.alias;t.push(J$1`${J$1.raw(s.joinType)} join ${c?J$1`${J$1.identifier(c)}.`:void 0}${J$1.identifier(f)}${p&&J$1` ${J$1.identifier(p)}`}${u}`);}else t.push(J$1`${J$1.raw(s.joinType)} join ${o}${u}`);n<e.length-1&&t.push(J$1` `);}return J$1.join(t)}buildLimit(e){return typeof e=="object"||typeof e=="number"&&e>=0?J$1` limit ${e}`:void 0}buildOrderBy(e){let t=[];if(e)for(let[n,s]of e.entries())t.push(s),n<e.length-1&&t.push(J$1`, `);return t.length>0?J$1` order by ${J$1.join(t)}`:void 0}buildFromTable(e){return c(e,t)&&e[t.Symbol.IsAlias]?J$1`${J$1`${J$1.identifier(e[t.Symbol.Schema]??"")}.`.if(e[t.Symbol.Schema])}${J$1.identifier(e[t.Symbol.OriginalName])} ${J$1.identifier(e[t.Symbol.Name])}`:e}buildSelectQuery({withList:e,fields:t$1,fieldsFlat:n,where:s,having:o,table:u,joins:r,orderBy:c$1,groupBy:f,limit:p,offset:$,distinct:x,setOperators:Q}){let w=n??R(t$1);for(let K of w)if(c(K.field,d)&&v(K.field.table)!==(c(u,i)?u._.alias:c(u,G)?u[l].name:c(u,A)?void 0:v(u))&&!(j=>r?.some(({alias:Y})=>Y===(j[t.Symbol.IsAlias]?v(j):j[t.Symbol.BaseName])))(K.field.table)){let j=v(K.field.table);throw new Error(`Your "${K.path.join("->")}" field references a column "${j}"."${K.field.name}", but the table "${j}" is not part of the query! Did you forget to join it?`)}let b=!r||r.length===0,T=this.buildWithCTE(e),C=x?J$1` distinct`:void 0,O=this.buildSelection(w,{isSingleTable:b}),B=this.buildFromTable(u),h=this.buildJoins(r),V=s?J$1` where ${s}`:void 0,v$1=o?J$1` having ${o}`:void 0,m=[];if(f)for(let[K,j]of f.entries())m.push(j),K<f.length-1&&m.push(J$1`, `);let g=m.length>0?J$1` group by ${J$1.join(m)}`:void 0,R$1=this.buildOrderBy(c$1),P=this.buildLimit(p),Z=$?J$1` offset ${$}`:void 0,A$1=J$1`${T}select${C} ${O} from ${B}${h}${V}${g}${v$1}${R$1}${P}${Z}`;return Q.length>0?this.buildSetOperations(A$1,Q):A$1}buildSetOperations(e,t){let[n,...s]=t;if(!n)throw new Error("Cannot pass undefined values to any set operator");return s.length===0?this.buildSetOperationQuery({leftSelect:e,setOperator:n}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:n}),s)}buildSetOperationQuery({leftSelect:e,setOperator:{type:t,isAll:n,rightSelect:s,limit:o,orderBy:u,offset:r}}){let c$1=J$1`${e.getSQL()} `,f=J$1`${s.getSQL()}`,p;if(u&&u.length>0){let w=[];for(let b of u)if(c(b,S))w.push(J$1.identifier(b.name));else if(c(b,A)){for(let T=0;T<b.queryChunks.length;T++){let C=b.queryChunks[T];c(C,S)&&(b.queryChunks[T]=J$1.identifier(this.casing.getColumnCasing(C)));}w.push(J$1`${b}`);}else w.push(J$1`${b}`);p=J$1` order by ${J$1.join(w,J$1`, `)}`;}let $=typeof o=="object"||typeof o=="number"&&o>=0?J$1` limit ${o}`:void 0,x=J$1.raw(`${t} ${n?"all ":""}`),Q=r?J$1` offset ${r}`:void 0;return J$1`${c$1}${x}${f}${p}${$}${Q}`}buildInsertQuery({table:e,values:t$1,onConflict:n,returning:s,withList:o,select:u}){let r=[],c$1=e[t.Symbol.Columns],f=Object.entries(c$1).filter(([b,T])=>!T.shouldDisableInsert()),p=f.map(([,b])=>J$1.identifier(this.casing.getColumnCasing(b)));if(u){let b=t$1;c(b,A)?r.push(b):r.push(b.getSQL());}else {let b=t$1;r.push(J$1.raw("values "));for(let[T,C]of b.entries()){let O=[];for(let[B,h]of f){let V=C[B];if(V===void 0||c(V,H$1)&&V.value===void 0){let v;if(h.default!==null&&h.default!==void 0)v=c(h.default,A)?h.default:J$1.param(h.default,h);else if(h.defaultFn!==void 0){let m=h.defaultFn();v=c(m,A)?m:J$1.param(m,h);}else if(!h.default&&h.onUpdateFn!==void 0){let m=h.onUpdateFn();v=c(m,A)?m:J$1.param(m,h);}else v=J$1`null`;O.push(v);}else O.push(V);}r.push(O),T<b.length-1&&r.push(J$1`, `);}}let $=this.buildWithCTE(o),x=J$1.join(r),Q=s?J$1` returning ${this.buildSelection(s,{isSingleTable:true})}`:void 0,w=n?.length?J$1.join(n):void 0;return J$1`${$}insert into ${e} ${p} ${x}${w}${Q}`}sqlToQuery(e,t){return e.toQuery({casing:this.casing,escapeName:this.escapeName,escapeParam:this.escapeParam,escapeString:this.escapeString,invokeSource:t})}buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:n$1,table:s,tableConfig:o,queryConfig:u,tableAlias:r,nestedQueryRelation:c$1,joinOn:f$1}){let p$1=[],$,x,Q$1=[],w$1,b=[];if(u===true)p$1=Object.entries(o.columns).map(([O,B])=>({dbKey:B.name,tsKey:O,field:f(B,r),relationTableTsKey:void 0,isJson:false,selection:[]}));else {let C=Object.fromEntries(Object.entries(o.columns).map(([m,g])=>[m,f(g,r)]));if(u.where){let m=typeof u.where=="function"?u.where(C,R$1()):u.where;w$1=m&&h(m,r);}let O=[],B=[];if(u.columns){let m=false;for(let[g,R]of Object.entries(u.columns))R!==void 0&&g in o.columns&&(!m&&R===true&&(m=true),B.push(g));B.length>0&&(B=m?B.filter(g=>u.columns?.[g]===true):Object.keys(o.columns).filter(g=>!B.includes(g)));}else B=Object.keys(o.columns);for(let m of B){let g=o.columns[m];O.push({tsKey:m,value:g});}let h$1=[];u.with&&(h$1=Object.entries(u.with).filter(m=>!!m[1]).map(([m,g])=>({tsKey:m,queryConfig:g,relation:o.relations[m]})));let V;if(u.extras){V=typeof u.extras=="function"?u.extras(C,{sql:J$1}):u.extras;for(let[m,g]of Object.entries(V))O.push({tsKey:m,value:g$1(g,r)});}for(let{tsKey:m,value:g}of O)p$1.push({dbKey:c(g,A.Aliased)?g.fieldAlias:o.columns[m].name,tsKey:m,field:c(g,d)?f(g,r):g,relationTableTsKey:void 0,isJson:false,selection:[]});let v=typeof u.orderBy=="function"?u.orderBy(C,S$1()):u.orderBy??[];Array.isArray(v)||(v=[v]),Q$1=v.map(m=>c(m,d)?f(m,r):h(m,r)),$=u.limit,x=u.offset;for(let{tsKey:m,queryConfig:g,relation:R}of h$1){let P$1=X$1(t,n$1,R),Z=w(R.referencedTable),A=n$1[Z],K=`${r}_${m}`,j=p(...P$1.fields.map((ut,at)=>n(f(P$1.references[at],K),f(ut,r)))),Y=this.buildRelationalQuery({fullSchema:e,schema:t,tableNamesMap:n$1,table:e[A],tableConfig:t[A],queryConfig:c(R,P)?g===true?{limit:1}:{...g,limit:1}:g,tableAlias:K,joinOn:j,nestedQueryRelation:R}),st=J$1`(${Y.sql})`.as(m);p$1.push({dbKey:m,tsKey:m,field:st,relationTableTsKey:A,isJson:true,selection:Y.selection});}}if(p$1.length===0)throw new j({message:`No fields selected for table "${o.tsName}" ("${r}"). You need to have at least one item in "columns", "with" or "extras". If you need to select all columns, omit the "columns" key or set it to undefined.`});let T;if(w$1=p(f$1,w$1),c$1){let C=J$1`json_array(${J$1.join(p$1.map(({field:h})=>c(h,S)?J$1.identifier(this.casing.getColumnCasing(h)):c(h,A.Aliased)?h.sql:h),J$1`, `)})`;c(c$1,Q)&&(C=J$1`coalesce(json_group_array(${C}), json_array())`);let O=[{dbKey:"data",tsKey:"data",field:C.as("data"),isJson:true,relationTableTsKey:o.tsName,selection:p$1}];$!==void 0||x!==void 0||Q$1.length>0?(T=this.buildSelectQuery({table:d$1(s,r),fields:{},fieldsFlat:[{path:[],field:J$1.raw("*")}],where:w$1,limit:$,offset:x,orderBy:Q$1,setOperators:[]}),w$1=void 0,$=void 0,x=void 0,Q$1=void 0):T=d$1(s,r),T=this.buildSelectQuery({table:c(T,F)?T:new i(T,{},r),fields:{},fieldsFlat:O.map(({field:h})=>({path:[],field:c(h,d)?f(h,r):h})),joins:b,where:w$1,limit:$,offset:x,orderBy:Q$1,setOperators:[]});}else T=this.buildSelectQuery({table:d$1(s,r),fields:{},fieldsFlat:p$1.map(({field:C})=>({path:[],field:c(C,d)?f(C,r):C})),joins:b,where:w$1,limit:$,offset:x,orderBy:Q$1,setOperators:[]});return {tableTsKey:o.tsName,sql:T,selection:p$1}}},rt=class extends H{static[a]="SQLiteSyncDialect";migrate(e,t,n){let s=n===void 0||typeof n=="string"?"__drizzle_migrations":n.migrationsTable??"__drizzle_migrations",o=J$1`
3
+ CREATE TABLE IF NOT EXISTS ${J$1.identifier(s)} (
4
+ id SERIAL PRIMARY KEY,
5
+ hash text NOT NULL,
6
+ created_at numeric
7
+ )
8
+ `;t.run(o);let r=t.values(J$1`SELECT id, hash, created_at FROM ${J$1.identifier(s)} ORDER BY created_at DESC LIMIT 1`)[0]??void 0;t.run(J$1`BEGIN`);try{for(let c of e)if(!r||Number(r[2])<c.folderMillis){for(let f of c.sql)t.run(J$1.raw(f));t.run(J$1`INSERT INTO ${J$1.identifier(s)} ("hash", "created_at") VALUES(${c.hash}, ${c.folderMillis})`);}t.run(J$1`COMMIT`);}catch(c){throw t.run(J$1`ROLLBACK`),c}}},ot=class extends H{static[a]="SQLiteAsyncDialect";async migrate(e,t,n){let s=n===void 0||typeof n=="string"?"__drizzle_migrations":n.migrationsTable??"__drizzle_migrations",o=J$1`
9
+ CREATE TABLE IF NOT EXISTS ${J$1.identifier(s)} (
10
+ id SERIAL PRIMARY KEY,
11
+ hash text NOT NULL,
12
+ created_at numeric
13
+ )
14
+ `;await t.run(o);let r=(await t.values(J$1`SELECT id, hash, created_at FROM ${J$1.identifier(s)} ORDER BY created_at DESC LIMIT 1`))[0]??void 0;await t.transaction(async c=>{for(let f of e)if(!r||Number(r[2])<f.folderMillis){for(let p of f.sql)await c.run(J$1.raw(p));await c.run(J$1`INSERT INTO ${J$1.identifier(s)} ("hash", "created_at") VALUES(${f.hash}, ${f.folderMillis})`);}});}};export{Ge as a,He as b,Ze as c,F as d,fi as e,G as f,H as g,rt as h,ot as i};
@@ -0,0 +1,3 @@
1
+ import {createRequire}from'module';createRequire(import.meta.url);
2
+ var i={name:"@aws-sdk/nested-clients",version:"3.997.33",description:"Nested clients for AWS SDK packages.",homepage:"https://github.com/aws/aws-sdk-js-v3/tree/main/packages/nested-clients",license:"Apache-2.0",author:{name:"AWS SDK for JavaScript Team",url:"https://aws.amazon.com/sdk-for-javascript/"},repository:{type:"git",url:"https://github.com/aws/aws-sdk-js-v3.git",directory:"packages/nested-clients"},files:["./cognito-identity.d.ts","./cognito-identity.js","./signin.d.ts","./signin.js","./sso-oidc.d.ts","./sso-oidc.js","./sso.d.ts","./sso.js","./sts.d.ts","./sts.js","dist-*/**"],sideEffects:false,main:"./dist-cjs/index.js",module:"./dist-es/index.js",browser:{"./dist-es/submodules/cognito-identity/runtimeConfig":"./dist-es/submodules/cognito-identity/runtimeConfig.browser","./dist-es/submodules/signin/runtimeConfig":"./dist-es/submodules/signin/runtimeConfig.browser","./dist-es/submodules/sso-oidc/runtimeConfig":"./dist-es/submodules/sso-oidc/runtimeConfig.browser","./dist-es/submodules/sso/runtimeConfig":"./dist-es/submodules/sso/runtimeConfig.browser","./dist-es/submodules/sts/runtimeConfig":"./dist-es/submodules/sts/runtimeConfig.browser"},types:"./dist-types/index.d.ts",typesVersions:{"<4.5":{"dist-types/*":["dist-types/ts3.4/*"],"*":["dist-types/ts3.4/submodules/*/index.d.ts"]}},"react-native":{},exports:{"./package.json":"./package.json","./sso-oidc":{types:"./dist-types/submodules/sso-oidc/index.d.ts",module:"./dist-es/submodules/sso-oidc/index.js",node:"./dist-cjs/submodules/sso-oidc/index.js",import:"./dist-es/submodules/sso-oidc/index.js",require:"./dist-cjs/submodules/sso-oidc/index.js"},"./sts":{types:"./dist-types/submodules/sts/index.d.ts",module:"./dist-es/submodules/sts/index.js",node:"./dist-cjs/submodules/sts/index.js",import:"./dist-es/submodules/sts/index.js",require:"./dist-cjs/submodules/sts/index.js"},"./signin":{types:"./dist-types/submodules/signin/index.d.ts",module:"./dist-es/submodules/signin/index.js",node:"./dist-cjs/submodules/signin/index.js",import:"./dist-es/submodules/signin/index.js",require:"./dist-cjs/submodules/signin/index.js"},"./cognito-identity":{types:"./dist-types/submodules/cognito-identity/index.d.ts",module:"./dist-es/submodules/cognito-identity/index.js",node:"./dist-cjs/submodules/cognito-identity/index.js",import:"./dist-es/submodules/cognito-identity/index.js",require:"./dist-cjs/submodules/cognito-identity/index.js"},"./sso":{types:"./dist-types/submodules/sso/index.d.ts",module:"./dist-es/submodules/sso/index.js",node:"./dist-cjs/submodules/sso/index.js",import:"./dist-es/submodules/sso/index.js",require:"./dist-cjs/submodules/sso/index.js"}},scripts:{build:"concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs","build:cjs":"node ../../scripts/compilation/inline","build:es":"premove dist-es && tsc -p tsconfig.es.json","build:include:deps":'yarn g:turbo run build -F="$npm_package_name"',"build:types":"premove dist-types && tsc -p tsconfig.types.json","build:types:downlevel":"downlevel-dts dist-types dist-types/ts3.4",clean:"premove dist-cjs dist-es dist-types",lint:"node ../../scripts/validation/submodules-linter.js",prebuild:"yarn lint",test:"yarn g:vitest run","test:watch":"yarn g:vitest watch"},dependencies:{"@aws-sdk/core":"^3.975.3","@aws-sdk/signature-v4-multi-region":"^3.996.41","@aws-sdk/types":"^3.974.2","@smithy/core":"^3.29.4","@smithy/fetch-http-handler":"^5.6.6","@smithy/node-http-handler":"^4.9.6","@smithy/types":"^4.16.1",tslib:"^2.6.2"},devDependencies:{concurrently:"7.0.0","downlevel-dts":"0.10.1",premove:"4.0.0",typescript:"~5.8.3"},engines:{node:">=20.0.0"}};
3
+ export{i as a};
@@ -0,0 +1,16 @@
1
+ import {createRequire}from'module';import {g as g$1}from'./chunk-C2PXMVR5.js';import {getRandomValues}from'crypto';import {ReadStream,lstatSync,fstatSync}from'fs';import {Readable,Writable}from'stream';createRequire(import.meta.url);
2
+ g$1();g$1();g$1();var J=e=>typeof ArrayBuffer=="function"&&e instanceof ArrayBuffer||Object.prototype.toString.call(e)==="[object ArrayBuffer]";var B=(e,t=0,r=e.byteLength-t)=>{if(!J(e))throw new TypeError(`The "input" argument must be ArrayBuffer. Received type ${typeof e} (${e})`);return Buffer.from(e,t,r)},U=(e,t)=>{if(typeof e!="string")throw new TypeError(`The "input" argument must be of type string. Received type ${typeof e} (${e})`);return t?Buffer.from(e,t):Buffer.from(e)};var R=e=>{let t=U(e,"utf8");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength/Uint8Array.BYTES_PER_ELEMENT)};g$1();var se=e=>{if(typeof e=="string")return e;if(typeof e!="object"||typeof e.byteOffset!="number"||typeof e.byteLength!="number")throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");return B(e.buffer,e.byteOffset,e.byteLength).toString("utf8")};g$1();var ie={},W={};for(let e=0;e<256;e++){let t=e.toString(16).toLowerCase();t.length===1&&(t=`0${t}`),ie[e]=t,W[t]=e;}function De(e){if(e.length%2!==0)throw new Error("Hex encoded strings must have an even number length");let t=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2){let n=e.slice(r,r+2).toLowerCase();if(n in W)t[r/2]=W[n];else throw new Error(`Cannot decode unrecognized sequence ${n} as hexadecimal`)}return t}function z(e){let t="";for(let r=0;r<e.byteLength;r++)t+=ie[e[r]];return t}g$1();g$1();var _e=/^[A-Za-z0-9+/]*={0,2}$/,ae=e=>{if(e.length*3%4!==0)throw new TypeError("Incorrect padding on base64 string.");if(!_e.exec(e))throw new TypeError("Invalid base64 string.");let t=U(e,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)};g$1();var F=e=>{let t;if(typeof e=="string"?t=R(e):t=e,typeof t!="object"||typeof t.byteOffset!="number"||typeof t.byteLength!="number")throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");return B(t.buffer,t.byteOffset,t.byteLength).toString("base64")};g$1();function fe(e,t,r,n){return class O extends Uint8Array{static fromString(s,a="utf-8"){if(typeof s=="string")return a==="base64"?O.mutate(n(s)):O.mutate(t(s));throw new Error(`Unsupported conversion from ${typeof s} to Uint8ArrayBlobAdapter.`)}static mutate(s){return Object.setPrototypeOf(s,O.prototype),s}transformToString(s="utf-8"){return s==="base64"?r(this):e(this)}}}g$1();var l=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ce(e){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?()=>crypto.randomUUID():()=>{let t=new Uint8Array(16);return e(t),t[6]=t[6]&15|64,t[8]=t[8]&63|128,l[t[0]]+l[t[1]]+l[t[2]]+l[t[3]]+"-"+l[t[4]]+l[t[5]]+"-"+l[t[6]]+l[t[7]]+"-"+l[t[8]]+l[t[9]]+"-"+l[t[10]]+l[t[11]]+l[t[12]]+l[t[13]]+l[t[14]]+l[t[15]]}}g$1();g$1();var j=e=>{if(e!=null){if(typeof e=="string"){let t=parseFloat(e);if(!Number.isNaN(t))return String(t)!==String(e)&&ze.warn(We(`Expected number but observed string: ${e}`)),t}if(typeof e=="number")return e;throw new TypeError(`Expected number, got ${typeof e}: ${e}`)}},ke=Math.ceil(34028234663852886e22),ue=e=>{let t=j(e);if(t!==void 0&&!Number.isNaN(t)&&t!==1/0&&t!==-1/0&&Math.abs(t)>ke)throw new TypeError(`Expected 32-bit float, got ${e}`);return t},Pe=e=>{if(e!=null){if(Number.isInteger(e)&&!Number.isNaN(e))return e;throw new TypeError(`Expected integer, got ${typeof e}: ${e}`)}};var de=e=>me(e,16),pe=e=>me(e,8),me=(e,t)=>{let r=Pe(e);if(r!==void 0&&He(r,t)!==r)throw new TypeError(`Expected ${t}-bit integer, got ${e}`);return r},He=(e,t)=>{switch(t){case 32:return Int32Array.of(e)[0];case 16:return Int16Array.of(e)[0];case 8:return Int8Array.of(e)[0]}};var he=e=>j(typeof e=="string"?L(e):e);var ye=e=>ue(typeof e=="string"?L(e):e),Je=/(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)|(-?Infinity)|(NaN)/g,L=e=>{let t=e.match(Je);if(t===null||t[0].length!==e.length)throw new TypeError("Expected real number, got implicit NaN");return parseFloat(e)};var N=e=>de(typeof e=="string"?L(e):e),le=e=>pe(typeof e=="string"?L(e):e),We=e=>String(new TypeError(e).stack||e).split(`
3
+ `).slice(0,5).filter(t=>!t.includes("stackTraceWarning")).join(`
4
+ `),ze={warn:console.warn};var je=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Y=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function qe(e){let t=e.getUTCFullYear(),r=e.getUTCMonth(),n=e.getUTCDay(),o=e.getUTCDate(),s=e.getUTCHours(),a=e.getUTCMinutes(),f=e.getUTCSeconds(),c=o<10?`0${o}`:`${o}`,u=s<10?`0${s}`:`${s}`,m=a<10?`0${a}`:`${a}`,h=f<10?`0${f}`:`${f}`;return `${je[n]}, ${c} ${Y[r]} ${t} ${u}:${m}:${h} GMT`}var Ye=new RegExp(/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?[zZ]$/),Ve=e=>{if(e==null)return;if(typeof e!="string")throw new TypeError("RFC-3339 date-times must be expressed as strings");let t=Ye.exec(e);if(!t)throw new TypeError("Invalid RFC-3339 date-time value");let[r,n,o,s,a,f,c,u]=t,m=N(C(n)),h=w(o,"month",1,12),y=w(s,"day",1,31);return M(m,h,y,{hours:a,minutes:f,seconds:c,fractionalMilliseconds:u})},Ge=new RegExp(/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(([-+]\d{2}:\d{2})|[zZ])$/),Xe=e=>{if(e==null)return;if(typeof e!="string")throw new TypeError("RFC-3339 date-times must be expressed as strings");let t=Ge.exec(e);if(!t)throw new TypeError("Invalid RFC-3339 date-time value");let[r,n,o,s,a,f,c,u,m]=t,h=N(C(n)),y=w(o,"month",1,12),b=w(s,"day",1,31),x=M(h,y,b,{hours:a,minutes:f,seconds:c,fractionalMilliseconds:u});return m.toUpperCase()!="Z"&&x.setTime(x.getTime()-ft(m)),x},Ze=new RegExp(/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? GMT$/),Ke=new RegExp(/^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d{2})-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{2}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? GMT$/),Qe=new RegExp(/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( [1-9]|\d{2}) (\d{1,2}):(\d{2}):(\d{2})(?:\.(\d+))? (\d{4})$/),ve=e=>{if(e==null)return;if(typeof e!="string")throw new TypeError("RFC-7231 date-times must be expressed as strings");let t=Ze.exec(e);if(t){let[r,n,o,s,a,f,c,u]=t;return M(N(C(s)),q(o),w(n,"day",1,31),{hours:a,minutes:f,seconds:c,fractionalMilliseconds:u})}if(t=Ke.exec(e),t){let[r,n,o,s,a,f,c,u]=t;return nt(M(tt(s),q(o),w(n,"day",1,31),{hours:a,minutes:f,seconds:c,fractionalMilliseconds:u}))}if(t=Qe.exec(e),t){let[r,n,o,s,a,f,c,u]=t;return M(N(C(u)),q(n),w(o.trimLeft(),"day",1,31),{hours:s,minutes:a,seconds:f,fractionalMilliseconds:c})}throw new TypeError("Invalid RFC-7231 date-time value")},et=e=>{if(e==null)return;let t;if(typeof e=="number")t=e;else if(typeof e=="string")t=he(e);else if(typeof e=="object"&&e.tag===1)t=e.value;else throw new TypeError("Epoch timestamps must be expressed as floating point numbers or their string representation");if(Number.isNaN(t)||t===1/0||t===-1/0)throw new TypeError("Epoch timestamps must be valid, non-Infinite, non-NaN numerics");return new Date(Math.round(t*1e3))},M=(e,t,r,n)=>{let o=t-1;return st(e,o,r),new Date(Date.UTC(e,o,r,w(n.hours,"hour",0,23),w(n.minutes,"minute",0,59),w(n.seconds,"seconds",0,60),at(n.fractionalMilliseconds)))},tt=e=>{let t=new Date().getUTCFullYear(),r=Math.floor(t/100)*100+N(C(e));return r<t?r+100:r},rt=50*365*24*60*60*1e3,nt=e=>e.getTime()-new Date().getTime()>rt?new Date(Date.UTC(e.getUTCFullYear()-100,e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds())):e,q=e=>{let t=Y.indexOf(e);if(t<0)throw new TypeError(`Invalid month: ${e}`);return t+1},ot=[31,28,31,30,31,30,31,31,30,31,30,31],st=(e,t,r)=>{let n=ot[t];if(t===1&&it(e)&&(n=29),r>n)throw new TypeError(`Invalid day for ${Y[t]} in ${e}: ${r}`)},it=e=>e%4===0&&(e%100!==0||e%400===0),w=(e,t,r,n)=>{let o=le(C(e));if(o<r||o>n)throw new TypeError(`${t} must be between ${r} and ${n}, inclusive`);return o},at=e=>e==null?0:ye("0."+e)*1e3,ft=e=>{let t=e[0],r=1;if(t=="+")r=1;else if(t=="-")r=-1;else throw new TypeError(`Offset direction, ${t}, must be "+" or "-"`);let n=Number(e.substring(1,3)),o=Number(e.substring(4,6));return r*(n*60+o)*60*1e3},C=e=>{let t=0;for(;t<e.length-1&&e.charAt(t)==="0";)t++;return t===0?e:e.slice(t)};g$1();var T=function(t){return Object.assign(new String(t),{deserializeJSON(){return JSON.parse(String(t))},toString(){return String(t)},toJSON(){return String(t)}})};T.from=e=>e&&typeof e=="object"&&(e instanceof T||"deserializeJSON"in e)?e:typeof e=="string"||Object.getPrototypeOf(e)===String.prototype?T(String(e)):T(JSON.stringify(e));T.fromObject=T.from;g$1();function ct(e){return (e.includes(",")||e.includes('"'))&&(e=`"${e.replace(/"/g,'\\"')}"`),e}g$1();var V="(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)(?:[ne|u?r]?s?day)?",G="(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)",X="(\\d?\\d):(\\d{2}):(\\d{2})(?:\\.(\\d+))?",be="(\\d?\\d)",ge="(\\d{4})",ut=new RegExp(/^(\d{4})-(\d\d)-(\d\d)[tT](\d\d):(\d\d):(\d\d)(\.(\d+))?(([-+]\d\d:\d\d)|[zZ])$/),dt=new RegExp(`^${V}, ${be} ${G} ${ge} ${X} GMT$`),pt=new RegExp(`^${V}, ${be}-${G}-(\\d\\d) ${X} GMT$`),mt=new RegExp(`^${V} ${G} ( [1-9]|\\d\\d) ${X} ${ge}$`),ht=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],yt=e=>{if(e==null)return;let t=NaN;if(typeof e=="number")t=e;else if(typeof e=="string"){if(!/^-?\d*\.?\d+$/.test(e))throw new TypeError("parseEpochTimestamp - numeric string invalid.");t=Number.parseFloat(e);}else typeof e=="object"&&e.tag===1&&(t=e.value);if(isNaN(t)||Math.abs(t)===1/0)throw new TypeError("Epoch timestamps must be valid finite numbers.");return new Date(Math.round(t*1e3))},lt=e=>{if(e==null)return;if(typeof e!="string")throw new TypeError("RFC3339 timestamps must be strings");let t=ut.exec(e);if(!t)throw new TypeError(`Invalid RFC3339 timestamp format ${e}`);let[,r,n,o,s,a,f,,c,u]=t;S(n,1,12),S(o,1,31),S(s,0,23),S(a,0,59),S(f,0,60);let m=new Date(Date.UTC(Number(r),Number(n)-1,Number(o),Number(s),Number(a),Number(f),Number(c)?Math.round(parseFloat(`0.${c}`)*1e3):0));if(m.setUTCFullYear(Number(r)),u.toUpperCase()!="Z"){let[,h,y,b]=/([+-])(\d\d):(\d\d)/.exec(u)||[void 0,"+",0,0],x=h==="-"?1:-1;m.setTime(m.getTime()+x*(Number(y)*60*60*1e3+Number(b)*60*1e3));}return m},bt=e=>{if(e==null)return;if(typeof e!="string")throw new TypeError("RFC7231 timestamps must be strings.");let t,r,n,o,s,a,f,c;if((c=dt.exec(e))?[,t,r,n,o,s,a,f]=c:(c=pt.exec(e))?([,t,r,n,o,s,a,f]=c,n=(Number(n)+1900).toString()):(c=mt.exec(e))&&([,r,t,o,s,a,f,n]=c),n&&a){let u=Date.UTC(Number(n),ht.indexOf(r),Number(t),Number(o),Number(s),Number(a),f?Math.round(parseFloat(`0.${f}`)*1e3):0);S(t,1,31),S(o,0,23),S(s,0,59),S(a,0,60);let m=new Date(u);return m.setUTCFullYear(Number(n)),m}throw new TypeError(`Invalid RFC7231 date-time value ${e}.`)};function S(e,t,r){let n=Number(e);if(n<t||n>r)throw new Error(`Value ${n} out of range [${t}, ${r}]`)}g$1();function gt(e,t,r){if(r<=0||!Number.isInteger(r))throw new Error("Invalid number of delimiters ("+r+") for splitEvery.");let n=e.split(t);if(r===1)return n;let o=[],s="";for(let a=0;a<n.length;a++)s===""?s=n[a]:s+=t+n[a],(a+1)%r===0&&(o.push(s),s="");return s!==""&&o.push(s),o}g$1();var wt=e=>{let t=e.length,r=[],n=false,o,s=0;for(let a=0;a<t;++a){let f=e[a];switch(f){case '"':o!=="\\"&&(n=!n);break;case ",":n||(r.push(e.slice(s,a)),s=a+1);break;}o=f;}return r.push(e.slice(s)),r.map(a=>{a=a.trim();let f=a.length;return f<2?a:(a[0]==='"'&&a[f-1]==='"'&&(a=a.slice(1,f-1)),a.replace(/\\"/g,'"'))})};g$1();var we=/^-?\d*(\.\d+)?$/,Z=class e{string;type;constructor(t,r){if(this.string=t,this.type=r,!we.test(t))throw new Error('@smithy/core/serde - NumericValue must only contain [0-9], at most one decimal point ".", and an optional negation prefix "-".')}toString(){return this.string}static[Symbol.hasInstance](t){if(!t||typeof t!="object")return false;let r=t;return e.prototype.isPrototypeOf(t)||r.type==="bigDecimal"&&we.test(r.string)}};g$1();var Tt=e=>{if(!e)return 0;if(typeof e=="string")return Buffer.byteLength(e);if(typeof e.byteLength=="number")return e.byteLength;if(typeof e.size=="number")return e.size;if(typeof e.start=="number"&&typeof e.end=="number")return e.end+1-e.start;if(e instanceof ReadStream){if(e.path!=null)return lstatSync(e.path).size;if(typeof e.fd=="number")return fstatSync(e.fd).size}throw new Error(`Body Length computation failed for ${e}`)};g$1();var $t=e=>e instanceof Uint8Array?e:typeof e=="string"?R(e):ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength/Uint8Array.BYTES_PER_ELEMENT):new Uint8Array(e);g$1();function I(e,t){if(t===void 0){t=0;for(let o of e)t+=o.byteLength;}let r=new Uint8Array(t),n=0;for(let o of e)r.set(o,n),n+=o.byteLength;return r}g$1();var D=class extends Readable{expectedChecksum;checksumSourceLocation;checksum;source;base64Encoder;constructor({expectedChecksum:t,checksum:r,source:n,checksumSourceLocation:o,base64Encoder:s}){if(super(),typeof n.pipe!="function")throw new Error(`@smithy/util-stream: unsupported source type ${n?.constructor?.name??n} in ChecksumStream.`);this.source=n,this.base64Encoder=s??F,this.expectedChecksum=t,this.checksum=r,this.checksumSourceLocation=o,this.source.on("data",this.onSourceData),this.source.on("end",this.onSourceEnd),this.source.on("error",this.onSourceError),this.source.on("close",this.onSourceClose),this.source.pause();}onSourceData=t=>{if(!this.destroyed){try{this.checksum.update(t);}catch(r){this.destroy(r);return}this.push(t)||this.source.pause();}};onSourceEnd=async()=>{if(!this.destroyed){try{let t=await this.checksum.digest(),r=this.base64Encoder(t);if(this.expectedChecksum!==r){this.destroy(new Error(`Checksum mismatch: expected "${this.expectedChecksum}" but received "${r}" in response header "${this.checksumSourceLocation}".`));return}}catch(t){this.destroy(t);return}this.push(null);}};onSourceError=t=>{this.destroy(t);};onSourceClose=()=>{!this.destroyed&&!this.source.readableEnded&&this.destroy(new Error("Connection lost or stream closed before all data was received."));};_read(t){this.source.resume();}_destroy(t,r){this.source?.removeListener("data",this.onSourceData),this.source?.removeListener("end",this.onSourceEnd),this.source?.removeListener("error",this.onSourceError),this.source?.removeListener("close",this.onSourceClose),this.source?.destroy(),r(t);}};g$1();g$1();var g=e=>typeof ReadableStream=="function"&&(e?.constructor?.name===ReadableStream.name||e instanceof ReadableStream),_=e=>typeof Blob=="function"&&(e?.constructor?.name===Blob.name||e instanceof Blob);g$1();g$1();g$1();var xe=e=>new TextEncoder().encode(e);g$1();var Se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";Object.entries(Se).reduce((e,[t,r])=>(e[r]=Number(t),e),{});var Ee=Se.split(""),k=6,K=8,Te=63;function P(e){let t;typeof e=="string"?t=xe(e):t=e;let r=typeof t=="object"&&typeof t.length=="number",n=typeof t=="object"&&typeof t.byteOffset=="number"&&typeof t.byteLength=="number";if(!r&&!n)throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");let o="";for(let s=0;s<t.length;s+=3){let a=0,f=0;for(let u=s,m=Math.min(s+3,t.length);u<m;u++)a|=t[u]<<(m-u-1)*K,f+=K;let c=Math.ceil(f/k);a<<=c*k-f;for(let u=1;u<=c;u++){let m=(c-u)*k;o+=Ee[(a&Te<<m)>>m];}o+="==".slice(0,4-c);}return o}g$1();var Bt=typeof ReadableStream=="function"?ReadableStream:function(){},H=class extends Bt{};var $e=({expectedChecksum:e,checksum:t,source:r,checksumSourceLocation:n,base64Encoder:o})=>{if(!g(r))throw new Error(`@smithy/util-stream: unsupported source type ${r?.constructor?.name??r} in ChecksumStream.`);let s=o??P;if(typeof TransformStream!="function")throw new Error("@smithy/util-stream: unable to instantiate ChecksumStream because API unavailable: ReadableStream/TransformStream.");let a=new TransformStream({start(){},async transform(c,u){t.update(c),u.enqueue(c);},async flush(c){let u=await t.digest(),m=s(u);if(e!==m){let h=new Error(`Checksum mismatch: expected "${e}" but received "${m}" in response header "${n}".`);c.error(h);}else c.terminate();}});r.pipeThrough(a);let f=a.readable;return Object.setPrototypeOf(f,H.prototype),f};function Rt(e){return typeof ReadableStream=="function"&&g(e.source)?$e(e):new D(e)}g$1();g$1();var $=class{allocByteArray;byteLength=0;byteArrays=[];constructor(t){this.allocByteArray=t;}push(t){this.byteArrays.push(t),this.byteLength+=t.byteLength;}flush(){if(this.byteArrays.length===1){let n=this.byteArrays[0];return this.reset(),n}let t=this.allocByteArray(this.byteLength),r=0;for(let n=0;n<this.byteArrays.length;++n){let o=this.byteArrays[n];t.set(o,r),r+=o.byteLength;}return this.reset(),t}reset(){this.byteArrays=[],this.byteLength=0;}};g$1();function Ae(e,t,r){let n=e.getReader(),o=false,s=0,a=["",new $(u=>new Uint8Array(u))],f=-1,c=async u=>{let{value:m,done:h}=await n.read(),y=m;if(h){if(f!==-1){let b=A(a,f);E(b)>0&&u.enqueue(b);}u.close();}else {let b=v(y,false);if(f!==b&&(f>=0&&u.enqueue(A(a,f)),f=b),f===-1){u.enqueue(y);return}let x=E(y);s+=x;let Le=E(a[f]);if(x>=t&&Le===0)u.enqueue(y);else {let Ie=Q(a,f,y);!o&&s>t*2&&(o=true,r?.warn(`@smithy/util-stream - stream chunk size ${x} is below threshold of ${t}, automatically buffering.`)),Ie>=t?u.enqueue(A(a,f)):await c(u);}}};return new ReadableStream({pull:c})}function Q(e,t,r){switch(t){case 0:return e[0]+=r,E(e[0]);case 1:case 2:return e[t].push(r),E(e[t])}}function A(e,t){switch(t){case 0:let r=e[0];return e[0]="",r;case 1:case 2:return e[t].flush()}throw new Error(`@smithy/util-stream - invalid index ${t} given to flush()`)}function E(e){return e?.byteLength??e?.length??0}function v(e,t=true){return t&&typeof Buffer<"u"&&e instanceof Buffer?2:e instanceof Uint8Array?1:typeof e=="string"?0:-1}function Ct(e,t,r){if(g(e))return Ae(e,t,r);let n=new Readable({read(){}}),o=false,s=0,a=["",new $(c=>new Uint8Array(c)),new $(c=>Buffer.from(new Uint8Array(c)))],f=-1;return e.on("data",c=>{let u=v(c,true);if(f!==u&&(f>=0&&n.push(A(a,f)),f=u),f===-1){n.push(c);return}let m=E(c);s+=m;let h=E(a[f]);if(m>=t&&h===0)n.push(c);else {let y=Q(a,f,c);!o&&s>t*2&&(o=true,r?.warn(`@smithy/util-stream - stream chunk size ${m} is below threshold of ${t}, automatically buffering.`)),y>=t&&n.push(A(a,f));}}),e.on("end",()=>{if(f!==-1){let c=A(a,f);E(c)>0&&n.push(c);}n.push(null);}),n}g$1();g$1();var Be=(e,t)=>{let{base64Encoder:r,bodyLengthChecker:n,checksumAlgorithmFn:o,checksumLocationName:s,streamHasher:a}=t,f=r!==void 0&&n!==void 0&&o!==void 0&&s!==void 0&&a!==void 0,c=f?a(o,e):void 0,u=e.getReader();return new ReadableStream({async pull(m){let{value:h,done:y}=await u.read();if(y){if(m.enqueue(`0\r
5
+ `),f){let b=r(await c);m.enqueue(`${s}:${b}\r
6
+ `),m.enqueue(`\r
7
+ `);}m.close();}else m.enqueue(`${(n(h)||0).toString(16)}\r
8
+ ${h}\r
9
+ `);}})};function Ut(e,t){let r=e,n=e;if(g(n))return Be(n,t);let{base64Encoder:o,bodyLengthChecker:s,checksumAlgorithmFn:a,checksumLocationName:f,streamHasher:c}=t,u=o!==void 0&&a!==void 0&&f!==void 0&&c!==void 0,m=u?c(a,r):void 0,h=new Readable({read:()=>{}});return r.on("data",y=>{let b=s(y)||0;b!==0&&(h.push(`${b.toString(16)}\r
10
+ `),h.push(y),h.push(`\r
11
+ `));}),r.on("end",async()=>{if(h.push(`0\r
12
+ `),u){let y=o(await m);h.push(`${f}:${y}\r
13
+ `),h.push(`\r
14
+ `);}h.push(null);}),h}g$1();g$1();g$1();var Re=e=>{if(typeof e=="string")return e;if(typeof e!="object"||typeof e.byteOffset!="number"||typeof e.byteLength!="number")throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");return new TextDecoder("utf-8").decode(e)};g$1();var Ne=async e=>_(e)?ee(e):te(e);async function ee(e){return e.arrayBuffer().then(t=>new Uint8Array(t))}async function te(e){let t=[],r=e.getReader(),n=0;for(;;){let{done:o,value:s}=await r.read();if(s&&(t.push(s),n+=s.length),o)break}return I(t,n)}var Ce="The stream has already been transformed.",Ue=e=>{if(!Me(e)&&!g(e)){let o=e?.__proto__?.constructor?.name||e;throw new Error(`Unexpected stream implementation, expect Blob or ReadableStream, got ${o}`)}let t=false,r=async()=>{if(t)throw new Error(Ce);return t=true,await Ne(e)},n=o=>{if(typeof o.stream!="function")throw new Error(`Cannot transform payload Blob to web stream. Please make sure the Blob.stream() is polyfilled.
15
+ If you are using React Native, this API is not yet supported, see: https://react-native.canny.io/feature-requests/p/fetch-streaming-body`);return o.stream()};return Object.assign(e,{transformToByteArray:r,transformToString:async o=>{let s=await r();if(o==="base64")return P(s);if(o==="hex")return z(s);if(o===void 0||o==="utf8"||o==="utf-8")return Re(s);if(typeof TextDecoder=="function")return new TextDecoder(o).decode(s);throw new Error("TextDecoder is not available, please make sure polyfill is provided.")},transformToWebStream:()=>{if(t)throw new Error(Ce);if(t=true,Me(e))return n(e);if(g(e))return e;throw new Error(`Cannot transform payload to web stream, got ${e}`)}})},Me=e=>typeof Blob=="function"&&e instanceof Blob;g$1();var ne=e=>_(e)?ee(e):g(e)?te(e):new Promise((t,r)=>{let n=new re,o=e;o.pipe(n),o.on("error",s=>{n.end(),r(s);}),n.on("error",r),n.on("finish",function(){let s=I(this.bufferedBytes);t(s);});}),re=class extends Writable{bufferedBytes=[];_write(t,r,n){this.bufferedBytes.push(t),n();}};var Fe="The stream has already been transformed.",Ot=e=>{if(!(e instanceof Readable))try{return Ue(e)}catch{let o=e?.__proto__?.constructor?.name||e;throw new Error(`Unexpected stream implementation, expect Stream.Readable instance, got ${o}`)}let t=false,r=async()=>{if(t)throw new Error(Fe);return t=true,await ne(e)};return Object.assign(e,{transformToByteArray:r,transformToString:async n=>{let o=await r();return n===void 0||Buffer.isEncoding(n)?B(o.buffer,o.byteOffset,o.byteLength).toString(n):new TextDecoder(n).decode(o)},transformToWebStream:()=>{if(t)throw new Error(Fe);if(e.readableFlowing!==null)throw new Error("The stream has been consumed by other callbacks.");if(typeof Readable.toWeb!="function")throw new Error("Readable.toWeb() is not supported. Please ensure a polyfill is available.");return t=true,Readable.toWeb(e)}})};var Oe=class extends fe(se,R,F,ae){},It=getRandomValues,Dt=ce(It),no=Dt;
16
+ export{Ot as A,Oe as B,Dt as C,no as D,J as a,ae as b,R as c,F as d,se as e,qe as f,Ve as g,Xe as h,ve as i,et as j,T as k,ct as l,yt as m,lt as n,bt as o,gt as p,wt as q,Z as r,De as s,z as t,Tt as u,$t as v,Rt as w,Ct as x,Ut as y,ne as z};