@kyro-cms/core 0.12.71 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/README.md +6 -0
  2. package/dist/{WebhookService-DQyM9fVo.d.ts → WebhookService-BLi5Rz2m.d.ts} +1 -1
  3. package/dist/{WebhookService-bo1NrgBW.d.cts → WebhookService-BcuD8tnn.d.cts} +1 -1
  4. package/dist/WebhookService-D5PSI5t6.d.cts +143 -0
  5. package/dist/WebhookService-DPCCn_12.d.ts +143 -0
  6. package/dist/WebhookService-Dncnbgm9.d.cts +143 -0
  7. package/dist/WebhookService-UY5p89Bj.d.ts +143 -0
  8. package/dist/WebhookService-YZXBCRXA.d.ts +143 -0
  9. package/dist/WebhookService-zrDmAx7L.d.cts +143 -0
  10. package/dist/api-handler-graphql.cjs +1 -1
  11. package/dist/api-handler-graphql.js +1 -1
  12. package/dist/api-handler-trpc.cjs +1 -1
  13. package/dist/api-handler-trpc.js +1 -1
  14. package/dist/api-handler.cjs +1 -1
  15. package/dist/api-handler.js +1 -1
  16. package/dist/{base-urWvrsX8.d.cts → base-B--L0lCn.d.cts} +1 -1
  17. package/dist/base-BVoDPNjJ.d.cts +218 -0
  18. package/dist/base-CAb9EYQs.d.ts +218 -0
  19. package/dist/base-CyG7aF1e.d.cts +218 -0
  20. package/dist/{base-BcfNgOqZ.d.ts → base-DOImeJ-F.d.ts} +1 -1
  21. package/dist/base-DbnwE42-.d.cts +218 -0
  22. package/dist/base-NyiSsD-n.d.ts +218 -0
  23. package/dist/base-xflndGDO.d.ts +218 -0
  24. package/dist/bootstrap-QQ6D3OYG.js +1 -0
  25. package/dist/bootstrap-QVKSKXJF.cjs +1 -0
  26. package/dist/bootstrap-RILR44UM.cjs +1 -0
  27. package/dist/bootstrap-ZRRUPRUR.js +1 -0
  28. package/dist/chunk-262YP5XA.cjs +1 -0
  29. package/dist/chunk-2FSOHXOU.cjs +56 -0
  30. package/dist/chunk-2OS5Y4LE.cjs +1 -0
  31. package/dist/chunk-2PXXQKN3.cjs +3 -0
  32. package/dist/{chunk-K6ZW5M6S.cjs → chunk-355R4LS5.cjs} +3 -3
  33. package/dist/chunk-35IVNLMA.js +122 -0
  34. package/dist/{chunk-FSWDDVLA.js → chunk-3GXLOYM3.js} +1 -1
  35. package/dist/chunk-3KZXF4US.js +2 -0
  36. package/dist/{chunk-H7PC2ENZ.cjs → chunk-3LAWUINR.cjs} +1 -1
  37. package/dist/chunk-3O3AVMWM.cjs +1 -0
  38. package/dist/chunk-3U6MKWET.cjs +120 -0
  39. package/dist/chunk-4BMWWGJN.js +384 -0
  40. package/dist/chunk-5A7E7N4B.cjs +431 -0
  41. package/dist/chunk-6DD4J7LI.js +2 -0
  42. package/dist/chunk-6GGPY7U2.js +4 -0
  43. package/dist/chunk-6MNLRAKM.cjs +121 -0
  44. package/dist/chunk-6NBZDW53.js +133 -0
  45. package/dist/{chunk-2HATK4C5.js → chunk-73Y63IPP.js} +4 -4
  46. package/dist/chunk-7K6ZUNJM.js +4 -0
  47. package/dist/chunk-7NKNSRCB.cjs +448 -0
  48. package/dist/chunk-A3IOQOV6.js +2 -0
  49. package/dist/chunk-A3XVL6ED.cjs +3 -0
  50. package/dist/{chunk-LKQHIOPW.cjs → chunk-APDQ6ZTG.cjs} +1 -1
  51. package/dist/chunk-ATI2UZ7U.js +2 -0
  52. package/dist/chunk-B4AC23SG.js +122 -0
  53. package/dist/chunk-BD6XHMMM.cjs +2 -0
  54. package/dist/chunk-CH4TZZI5.js +449 -0
  55. package/dist/{chunk-26KFM3P6.js → chunk-CNHUCCQJ.js} +1 -1
  56. package/dist/chunk-CRP6PSCE.js +2 -0
  57. package/dist/chunk-DI6TCZSE.js +122 -0
  58. package/dist/chunk-DORUYZQV.cjs +1 -0
  59. package/dist/chunk-EFKEVWAD.js +4 -0
  60. package/dist/chunk-EI7FRSNY.js +57 -0
  61. package/dist/chunk-EON4XLKQ.cjs +1 -0
  62. package/dist/chunk-EUQAOYEO.cjs +121 -0
  63. package/dist/chunk-EVAUBT7H.js +57 -0
  64. package/dist/chunk-EYHD7HZE.cjs +1 -0
  65. package/dist/chunk-EYYIPA5N.js +432 -0
  66. package/dist/chunk-F2O4QO5N.cjs +383 -0
  67. package/dist/chunk-FBWLSWZ4.js +122 -0
  68. package/dist/chunk-FGN6IMPY.cjs +3 -0
  69. package/dist/chunk-FK2BG4HU.js +3 -0
  70. package/dist/chunk-GWIZT2P5.js +57 -0
  71. package/dist/chunk-H3FJ54KB.cjs +121 -0
  72. package/dist/chunk-HY3EAWB2.js +4 -0
  73. package/dist/chunk-I6UJVO2P.js +57 -0
  74. package/dist/chunk-IQSF6XRV.js +57 -0
  75. package/dist/chunk-IXGDTAES.js +4 -0
  76. package/dist/chunk-JA44K75G.js +2 -0
  77. package/dist/chunk-K5XGP57D.cjs +19 -0
  78. package/dist/chunk-KEITOXIP.js +2 -0
  79. package/dist/chunk-LPFRMQFQ.js +121 -0
  80. package/dist/chunk-LYU44UNN.cjs +56 -0
  81. package/dist/chunk-MDLJTZLV.cjs +1 -0
  82. package/dist/chunk-MJAODEFC.cjs +121 -0
  83. package/dist/chunk-MYHNTJLR.cjs +56 -0
  84. package/dist/chunk-N2YHO2WI.cjs +3 -0
  85. package/dist/chunk-N4FXLQE3.cjs +132 -0
  86. package/dist/chunk-NPBXLPOP.js +3 -0
  87. package/dist/chunk-ON5XJEPO.cjs +3 -0
  88. package/dist/chunk-OT2Z4XBD.cjs +1 -0
  89. package/dist/chunk-PFTBTWSC.cjs +1 -0
  90. package/dist/chunk-PTPVFLET.js +20 -0
  91. package/dist/chunk-PZDLPRJF.js +4 -0
  92. package/dist/chunk-Q5TFO66G.cjs +1 -0
  93. package/dist/chunk-QUTYCUST.js +4 -0
  94. package/dist/chunk-REKKBAQX.cjs +56 -0
  95. package/dist/chunk-REQ622YC.js +3 -0
  96. package/dist/chunk-RTNQP6BV.js +2 -0
  97. package/dist/chunk-RUJW47ZJ.js +2 -0
  98. package/dist/chunk-RXYCFZJC.cjs +121 -0
  99. package/dist/chunk-RYHOWZLK.js +2 -0
  100. package/dist/chunk-S2MZNEBQ.cjs +1 -0
  101. package/dist/chunk-S73YERS2.js +57 -0
  102. package/dist/chunk-SBNMXQNO.cjs +2 -0
  103. package/dist/chunk-T3DJ3UTP.cjs +121 -0
  104. package/dist/chunk-TJZO7ZSX.cjs +3 -0
  105. package/dist/chunk-TKUNRCRH.js +4 -0
  106. package/dist/chunk-TQLCOMKC.js +4 -0
  107. package/dist/chunk-TRXYDWGE.cjs +1 -0
  108. package/dist/chunk-TS55CUNJ.js +57 -0
  109. package/dist/chunk-UFBJ3WOZ.js +2 -0
  110. package/dist/chunk-UQRVQUVR.js +2 -0
  111. package/dist/chunk-UW5W35NP.js +122 -0
  112. package/dist/chunk-VI7WCO2J.cjs +3 -0
  113. package/dist/chunk-W2GPP6RB.js +122 -0
  114. package/dist/chunk-WHOA7YJU.cjs +1 -0
  115. package/dist/chunk-WNRUPL26.js +2 -0
  116. package/dist/chunk-WXT2XW7T.js +13 -0
  117. package/dist/chunk-XFYSADHV.cjs +2 -0
  118. package/dist/chunk-XIAJQLGS.js +2 -0
  119. package/dist/chunk-XK6UB77Q.js +4 -0
  120. package/dist/chunk-Y2VHO66Q.cjs +3 -0
  121. package/dist/chunk-Y5O2OD7J.cjs +3 -0
  122. package/dist/chunk-YARB43JG.cjs +56 -0
  123. package/dist/chunk-YLCEMVYY.cjs +56 -0
  124. package/dist/chunk-YSOM57GK.cjs +3 -0
  125. package/dist/chunk-Z3UVDGYS.cjs +56 -0
  126. package/dist/chunk-ZTLGK6R4.cjs +12 -0
  127. package/dist/chunk-ZUBJ6RLQ.cjs +1 -0
  128. package/dist/cli/index.cjs +1 -1
  129. package/dist/cli/index.js +1 -1
  130. package/dist/client.cjs +8 -8
  131. package/dist/client.d.cts +1248 -0
  132. package/dist/client.d.ts +1248 -0
  133. package/dist/client.js +8 -8
  134. package/dist/drizzle/index.cjs +1 -1
  135. package/dist/drizzle/index.d.cts +3 -3
  136. package/dist/drizzle/index.d.ts +3 -3
  137. package/dist/drizzle/index.js +1 -1
  138. package/dist/fields/index.cjs +1 -1
  139. package/dist/fields/index.d.cts +2 -2
  140. package/dist/fields/index.d.ts +2 -2
  141. package/dist/fields/index.js +1 -1
  142. package/dist/graphql/index.d.cts +3 -3
  143. package/dist/graphql/index.d.ts +3 -3
  144. package/dist/{index-d1m_oup7.d.cts → index-B9BFNOHd.d.cts} +1 -1
  145. package/dist/index-BMcYFpTv.d.cts +105 -0
  146. package/dist/index-BttsFZDa.d.ts +105 -0
  147. package/dist/index-CxA9uOv0.d.ts +105 -0
  148. package/dist/{index-4cH-BjtP.d.ts → index-D6AXbuPI.d.ts} +1 -1
  149. package/dist/index-DF0KDBaM.d.cts +105 -0
  150. package/dist/index-DG4Xu7gA.d.cts +105 -0
  151. package/dist/index-eHex8Iwj.d.ts +105 -0
  152. package/dist/index.cjs +32 -32
  153. package/dist/index.d.cts +73 -11
  154. package/dist/index.d.ts +73 -11
  155. package/dist/index.js +32 -32
  156. package/dist/lib-A2D63VXD.cjs +1 -0
  157. package/dist/lib-JQD2JAOO.js +2 -0
  158. package/dist/local-KR3AIGVA.cjs +1 -0
  159. package/dist/local-T7GISZBL.js +1 -0
  160. package/dist/mongo-auth-adapter-GR2CFFEA.js +1 -0
  161. package/dist/mongo-auth-adapter-UOO2LZUJ.cjs +1 -0
  162. package/dist/mongodb/index.cjs +1 -1
  163. package/dist/mongodb/index.d.cts +4 -3
  164. package/dist/mongodb/index.d.ts +4 -3
  165. package/dist/mongodb/index.js +1 -1
  166. package/dist/nodemailer-transport-3VWVUBM5.cjs +1 -0
  167. package/dist/nodemailer-transport-7RHATUKL.js +1 -0
  168. package/dist/nodemailer-transport-CHO2WKIY.js +1 -0
  169. package/dist/nodemailer-transport-ED2IXNGW.cjs +1 -0
  170. package/dist/rest/index.cjs +1 -1
  171. package/dist/rest/index.d.cts +4 -4
  172. package/dist/rest/index.d.ts +4 -4
  173. package/dist/rest/index.js +1 -1
  174. package/dist/templates/index.cjs +1 -1
  175. package/dist/templates/index.d.cts +2 -2
  176. package/dist/templates/index.d.ts +2 -2
  177. package/dist/templates/index.js +1 -1
  178. package/dist/trpc/index.cjs +1 -1
  179. package/dist/trpc/index.d.cts +3 -3
  180. package/dist/trpc/index.d.ts +3 -3
  181. package/dist/trpc/index.js +1 -1
  182. package/dist/types-B5Qz1svz.d.cts +822 -0
  183. package/dist/types-Bii0bhUV.d.cts +329 -0
  184. package/dist/types-Bii0bhUV.d.ts +329 -0
  185. package/dist/{types-BADIMVGF.d.ts → types-Bt2_ycUO.d.ts} +36 -1
  186. package/dist/types-C4wXHImf.d.ts +822 -0
  187. package/dist/types-DCWgPFmi.d.cts +822 -0
  188. package/dist/types-DROqAsr0.d.cts +330 -0
  189. package/dist/types-DROqAsr0.d.ts +330 -0
  190. package/dist/{types-YAVR0H9Z.d.cts → types-DsF64Wrc.d.cts} +36 -1
  191. package/dist/types-ZrjEVWfi.d.ts +811 -0
  192. package/dist/types-dEy5JxvN.d.ts +822 -0
  193. package/dist/types-tVJc9YbX.d.cts +811 -0
  194. package/dist/ws/index.cjs +1 -1
  195. package/dist/ws/index.d.cts +121 -1
  196. package/dist/ws/index.d.ts +121 -1
  197. package/dist/ws/index.js +1 -1
  198. package/package.json +2 -2
  199. package/dist/chunk-5M3FKE2V.js +0 -2
  200. package/dist/chunk-WCFHS7EZ.cjs +0 -1
@@ -0,0 +1,3 @@
1
+ import {h,e}from'./chunk-GQGFNTDZ.js';import {a as a$1}from'./chunk-JA44K75G.js';import {a}from'./chunk-TBHNE4VV.js';import {g}from'./chunk-Y2YAKDEQ.js';import {createHmac,randomBytes,randomUUID}from'crypto';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); 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 M(o){return o==="read"?"read":o==="create"?"create":o==="update"?"update":"delete"}function Y(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 He(o,t,s,e$1={}){let{user:r,req:i,tenantId:u,apiKey:c}=s,{enablePublicAccess:a$1=true,defaultAccess:n="none"}=e$1,l=o.access?.[t];if(l){let y=await h(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 !e(c.permissions,p)&&!e(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({id:r.id,email:r.email,role:r.role},p),b=a({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=Y(t,n);return a$1&&d?{allowed:true}:{allowed:false,error:"Authentication required",status:401}}async function Be(o,t,s,e={}){let{user:r,req:i,tenantId:u}=s,{enablePublicAccess:c=true}=e,a$1=o.access?.[t];if(a$1)return await h(a$1,{req:i,user:r,tenantId:u})===false?{allowed:false,error:"Access denied",status:403}:{allowed:true};if(r){let n=`globals:${t}`,l=a({id:r.id,email:r.email,role:r.role},n),d=a({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}}g();function J(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 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=J(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 Z(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 ee(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)Q(n,t,u);if(u.size===0)return;let c=new Map,a=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.set(n,p);}if(r<i)for(let[n,l]of a.entries()){let d=e.getCollection(n);d&&await ee(l,d.fields,s,e,r+1,i);}for(let n=0;n<o.length;n++)Z(o[n],t,c),o[n]=a$1(o[n]);}
3
+ export{He as a,Be as b,_ as c,G as d,k as e,w as f,P as g,x as h,U as i,I as j,H as k,z as l,O as m,X as n,ee as o};
@@ -0,0 +1,2 @@
1
+ import {K,H}from'./chunk-73Y63IPP.js';import {e}from'./chunk-CHYVUWZ3.js';import {hb}from'./chunk-35IVNLMA.js';import {a as a$1}from'./chunk-N6MNQIQU.js';import {c}from'./chunk-FUFS65Q5.js';import {a}from'./chunk-ZWDBPEXL.js';import {a as a$2}from'./chunk-5ZEYOFAK.js';import {g}from'./chunk-Y2YAKDEQ.js';import w from'kyro:config';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
2
+ g();var r=null,l=null;async function b(){if(!r){if(globalThis.__KYRO_INSTANCE__)try{await globalThis.__KYRO_INSTANCE__.shutdown();}catch{}try{let e$1=w.default||w,t=e$1.adapter,o=t&&!t.dialect&&typeof t.connect=="function";if(globalThis.DB&&(!t||o)){let s=globalThis.DB;e$1.adapter=new c({type:"sqlite",client:s}),K.info("Hot-swapped to D1 DrizzleAdapter");}r=H(e$1),await r.init();let a$3=e$1.adapter,p=a$3&&a$3.dialect&&(a$3.dialect==="postgres"||a$3.dialect==="sqlite"),c$1=a$3&&a$3.dialect==="mongodb",n;if(p)a$3.dialect==="postgres"?n=new a({db:a$3.client}):a$3.dialect==="sqlite"&&(n=new hb({db:a$3.rawClient||a$3.client}));else if(o&&!globalThis.DB){let s=process.env.KYRO_AUTH_DB_PATH||"./data/auth.db";n=new a$1({path:s});}else c$1&&(n=new a$2({adapter:a$3}));if(n?.connect)try{await n.connect();}catch(s){K.warn("Auth connect warning:",s);}try{await r.loadSettings();}catch(s){K.warn("loadSettings warning:",s);}try{await e(n);}catch(s){K.warn("autoBootstrap warning:",s);}globalThis.__KYRO_INSTANCE__=r;}catch(e){throw r=null,l=null,K.error("Init failed, will retry:",e),e}}}async function E(e){let t=globalThis.DB?globalThis:null;try{let{env:o}=await import('cloudflare:workers');o&&(t=o);}catch{}if(e)try{t=e.locals?.cfContext?.env||e?.env||t;}catch{}if(!t)try{t=process.env;}catch{}t?.DB&&(globalThis.DB=t.DB),t?.STORAGE_BUCKET&&(globalThis.STORAGE_BUCKET=t.STORAGE_BUCKET),l||(l=b()),await l;}var _={graphqlEnabled:false,trpcEnabled:false,wsEnabled:false,requireAuth:false};function T(e){return r?r.settings?.access?.apiAccess?.[e]??_[e]??true:_[e]??true}var R=async e=>{if(!r)try{await Promise.race([E(e),new Promise((t,o)=>setTimeout(()=>o(new Error("Initialization timeout")),3e4))]);}catch(t){return console.error("[Kyro API] Warm error:",t?.stack||t?.message||t),new Response(JSON.stringify({error:"Service Unavailable",message:"Kyro CMS is still starting up. Please try again in a moment."}),{status:503,headers:{"Content-Type":"application/json","Retry-After":"5"}})}try{let o=new URL(e.request.url).pathname,a=__KYRO_API_PATH__;if(o===`${a}/graphql`&&typeof r.getGraphQL=="function"){if(!T("graphqlEnabled"))return new Response(JSON.stringify({error:"GraphQL is disabled"}),{status:503,headers:{"Content-Type":"application/json"}});let n=await r.getGraphQL().fetch(e.request,e.locals);return new Response(n.body,n)}if(o.startsWith(`${a}/trpc/`)&&typeof r.getTRPC=="function"){if(!T("trpcEnabled"))return new Response(JSON.stringify({error:"tRPC is disabled"}),{status:503,headers:{"Content-Type":"application/json"}});let n=await r.getTRPC().fetch(e.request,e.locals);return new Response(n.body,n)}return await(await r.getREST()).fetch(e.request,e.locals)}catch(t){return console.error("[Kyro API Execution Error]:",t?.stack||t?.message||t),new Response(JSON.stringify({error:"Internal Server Error",message:t?.message||String(t),stack:t?.stack}),{status:500,headers:{"Content-Type":"application/json"}})}},N=R;export{r as a,E as b,R as c,N as d};
@@ -0,0 +1,2 @@
1
+ import {K,H}from'./chunk-GWIZT2P5.js';import {e}from'./chunk-CHYVUWZ3.js';import {hb}from'./chunk-LPFRMQFQ.js';import {a as a$1}from'./chunk-N6MNQIQU.js';import {c}from'./chunk-FUFS65Q5.js';import {a}from'./chunk-ZWDBPEXL.js';import {a as a$2}from'./chunk-5ZEYOFAK.js';import {g}from'./chunk-Y2YAKDEQ.js';import w from'kyro:config';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
2
+ g();var r=null,l=null;async function b(){if(!r){if(globalThis.__KYRO_INSTANCE__)try{await globalThis.__KYRO_INSTANCE__.shutdown();}catch{}try{let e$1=w.default||w,t=e$1.adapter,o=t&&!t.dialect&&typeof t.connect=="function";if(globalThis.DB&&(!t||o)){let s=globalThis.DB;e$1.adapter=new c({type:"sqlite",client:s}),K.info("Hot-swapped to D1 DrizzleAdapter");}r=H(e$1),await r.init();let a$3=e$1.adapter,p=a$3&&a$3.dialect&&(a$3.dialect==="postgres"||a$3.dialect==="sqlite"),c$1=a$3&&a$3.dialect==="mongodb",n;if(p)a$3.dialect==="postgres"?n=new a({db:a$3.client}):a$3.dialect==="sqlite"&&(n=new hb({db:a$3.rawClient||a$3.client}));else if(o&&!globalThis.DB){let s=process.env.KYRO_AUTH_DB_PATH||"./data/auth.db";n=new a$1({path:s});}else c$1&&(n=new a$2({adapter:a$3}));if(n?.connect)try{await n.connect();}catch(s){K.warn("Auth connect warning:",s);}try{await r.loadSettings();}catch(s){K.warn("loadSettings warning:",s);}try{await e(n);}catch(s){K.warn("autoBootstrap warning:",s);}globalThis.__KYRO_INSTANCE__=r;}catch(e){throw r=null,l=null,K.error("Init failed, will retry:",e),e}}}async function E(e){let t=globalThis.DB?globalThis:null;try{let{env:o}=await import('cloudflare:workers');o&&(t=o);}catch{}if(e)try{t=e.locals?.cfContext?.env||e?.env||t;}catch{}if(!t)try{t=process.env;}catch{}t?.DB&&(globalThis.DB=t.DB),t?.STORAGE_BUCKET&&(globalThis.STORAGE_BUCKET=t.STORAGE_BUCKET),l||(l=b()),await l;}var _={graphqlEnabled:false,trpcEnabled:false,wsEnabled:false,requireAuth:false};function T(e){return r?r.settings?.access?.apiAccess?.[e]??_[e]??true:_[e]??true}var R=async e=>{if(!r)try{await Promise.race([E(e),new Promise((t,o)=>setTimeout(()=>o(new Error("Initialization timeout")),3e4))]);}catch(t){return console.error("[Kyro API] Warm error:",t?.stack||t?.message||t),new Response(JSON.stringify({error:"Service Unavailable",message:"Kyro CMS is still starting up. Please try again in a moment."}),{status:503,headers:{"Content-Type":"application/json","Retry-After":"5"}})}try{let o=new URL(e.request.url).pathname,a=__KYRO_API_PATH__;if(o===`${a}/graphql`&&typeof r.getGraphQL=="function"){if(!T("graphqlEnabled"))return new Response(JSON.stringify({error:"GraphQL is disabled"}),{status:503,headers:{"Content-Type":"application/json"}});let n=await r.getGraphQL().fetch(e.request,e.locals);return new Response(n.body,n)}if(o.startsWith(`${a}/trpc/`)&&typeof r.getTRPC=="function"){if(!T("trpcEnabled"))return new Response(JSON.stringify({error:"tRPC is disabled"}),{status:503,headers:{"Content-Type":"application/json"}});let n=await r.getTRPC().fetch(e.request,e.locals);return new Response(n.body,n)}return await(await r.getREST()).fetch(e.request,e.locals)}catch(t){return console.error("[Kyro API Execution Error]:",t?.stack||t?.message||t),new Response(JSON.stringify({error:"Internal Server Error",message:t?.message||String(t),stack:t?.stack}),{status:500,headers:{"Content-Type":"application/json"}})}},N=R;export{r as a,E as b,R as c,N as d};