@kyro-cms/core 0.13.5 → 0.13.7
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.
- package/dist/api-handler-graphql.cjs +1 -1
- package/dist/api-handler-graphql.js +2 -2
- package/dist/api-handler-trpc.cjs +1 -1
- package/dist/api-handler-trpc.js +2 -2
- package/dist/api-handler.cjs +1 -1
- package/dist/api-handler.js +1 -1
- package/dist/auth-session-4WJUKESW.js +1 -0
- package/dist/auth-session-VHUHDBCL.cjs +1 -0
- package/dist/bootstrap-JYAUQ52D.cjs +1 -0
- package/dist/bootstrap-TTMLNQM3.js +1 -0
- package/dist/chunk-23RSKVJP.cjs +1 -0
- package/dist/chunk-24W5I6SJ.cjs +2 -0
- package/dist/{chunk-CH4TZZI5.js → chunk-2I2AXTKY.cjs} +38 -39
- package/dist/chunk-34LCWI5X.cjs +1 -0
- package/dist/chunk-3A5UO6OQ.cjs +114 -0
- package/dist/chunk-3N34WXBS.js +2 -0
- package/dist/chunk-3RIGRHON.js +109 -0
- package/dist/chunk-5BUAWCU6.js +91 -0
- package/dist/{chunk-7NKNSRCB.cjs → chunk-5I3BM5TV.js} +33 -32
- package/dist/chunk-5RBGM5N5.js +3 -0
- package/dist/chunk-7EY3GXRA.js +2 -0
- package/dist/chunk-7KTPBTH5.cjs +1 -0
- package/dist/chunk-A7763NCF.cjs +19 -0
- package/dist/chunk-AQWTJGML.cjs +1 -0
- package/dist/chunk-DCFOVCJX.cjs +1 -0
- package/dist/chunk-DCKJT247.cjs +1 -0
- package/dist/chunk-EG4SRTYS.cjs +2 -0
- package/dist/chunk-FAG2645P.js +2 -0
- package/dist/chunk-FIVTKI25.cjs +3 -0
- package/dist/chunk-FU76HURF.cjs +1 -0
- package/dist/chunk-GS4CMYKS.cjs +1 -0
- package/dist/chunk-GTAKGVUY.js +2 -0
- package/dist/chunk-GWUHIIPO.cjs +132 -0
- package/dist/chunk-H2IJDTA2.cjs +1 -0
- package/dist/chunk-HCM2G674.cjs +20 -0
- package/dist/chunk-I22MSXGL.js +2 -0
- package/dist/chunk-IIPSXKNV.js +115 -0
- package/dist/{chunk-WNU76M2C.js → chunk-IIVBEZC2.js} +6 -6
- package/dist/chunk-JHFD3IAU.cjs +1 -0
- package/dist/chunk-JJY2F6NL.cjs +3 -0
- package/dist/chunk-JQ4V2MGJ.cjs +2 -0
- package/dist/chunk-JXJTFBHG.js +3 -0
- package/dist/chunk-KOSR7235.cjs +1 -0
- package/dist/chunk-KUY4QDAL.js +2 -0
- package/dist/chunk-LGUHXOEW.js +3 -0
- package/dist/chunk-LXTVMP5F.cjs +6 -0
- package/dist/chunk-MCK2QRAU.cjs +4 -0
- package/dist/chunk-N2BMGZIX.cjs +90 -0
- package/dist/chunk-N7CDHWQH.cjs +2 -0
- package/dist/chunk-NGNXOXI5.js +2 -0
- package/dist/chunk-O2SA56P2.cjs +108 -0
- package/dist/chunk-O4PPZOVI.cjs +1 -0
- package/dist/chunk-O4RKZQYQ.js +2 -0
- package/dist/chunk-O6I26T6A.js +3 -0
- package/dist/chunk-OJBL4CXK.cjs +2 -0
- package/dist/chunk-OPKZYQV7.js +3 -0
- package/dist/chunk-OXEJCIOA.cjs +1 -0
- package/dist/chunk-OXH6CANN.js +2 -0
- package/dist/chunk-PPGZHOYR.cjs +1 -0
- package/dist/{chunk-EQN3HDES.cjs → chunk-PW6Y5MQL.cjs} +5 -5
- package/dist/chunk-RLW6AQF2.js +2 -0
- package/dist/chunk-SBFVITY2.js +7 -0
- package/dist/chunk-SEJ7LMYY.js +4 -0
- package/dist/chunk-SYE3OS5T.js +5 -0
- package/dist/chunk-SZY25KAE.js +21 -0
- package/dist/chunk-TJ6N5ZPZ.js +133 -0
- package/dist/chunk-TVWHTVLI.js +2 -0
- package/dist/chunk-UE7DTBD7.cjs +1 -0
- package/dist/chunk-V2RMDMWN.js +2 -0
- package/dist/chunk-V4SR7DU5.js +3 -0
- package/dist/chunk-VLFM66BZ.js +4 -0
- package/dist/chunk-VPBGZW4P.cjs +1 -0
- package/dist/chunk-W5GDZG64.js +2 -0
- package/dist/chunk-WLSVS3NC.js +2 -0
- package/dist/chunk-XL64URKD.cjs +2 -0
- package/dist/chunk-YNBJGPIU.js +2 -0
- package/dist/chunk-YNSKDTFG.js +2 -0
- package/dist/chunk-YOJOVQIH.cjs +1 -0
- package/dist/chunk-ZE2X3FBU.js +20 -0
- package/dist/chunk-ZMH35QYG.js +2 -0
- package/dist/cli/index.cjs +53 -182
- package/dist/cli/index.js +54 -183
- package/dist/drizzle/index.cjs +1 -1
- package/dist/drizzle/index.js +1 -1
- package/dist/fields/index.cjs +1 -1
- package/dist/fields/index.js +1 -1
- package/dist/graphql/index.cjs +1 -1
- package/dist/graphql/index.js +1 -1
- package/dist/index-B_39z2jP.d.cts +217 -0
- package/dist/index-xqpVL2Zq.d.ts +217 -0
- package/dist/index.cjs +30 -30
- package/dist/index.d.cts +2 -31
- package/dist/index.d.ts +2 -31
- package/dist/index.js +31 -31
- package/dist/integration.cjs +1 -1
- package/dist/integration.js +1 -1
- package/dist/local-DKP43BWQ.cjs +1 -0
- package/dist/local-TF5ZMHWW.js +1 -0
- package/dist/media-M3EIZ4QS.cjs +1 -0
- package/dist/media-WYEILC6K.js +1 -0
- package/dist/mongo-auth-adapter-22MV3TI3.cjs +1 -0
- package/dist/mongo-auth-adapter-66PWVRZW.js +1 -0
- package/dist/mongodb/index.cjs +1 -1
- package/dist/mongodb/index.d.cts +3 -130
- package/dist/mongodb/index.d.ts +3 -130
- package/dist/mongodb/index.js +1 -1
- package/dist/nodemailer-transport-7F3VLLBW.js +1 -0
- package/dist/nodemailer-transport-WAPZD3SJ.cjs +1 -0
- package/dist/postgres-auth-adapter-7BCPXNBO.js +1 -0
- package/dist/postgres-auth-adapter-HMXFUM5W.cjs +1 -0
- package/dist/redis-adapter-2E5AWMMA.cjs +1 -0
- package/dist/redis-adapter-GFH74CF4.js +1 -0
- package/dist/rest/index.cjs +1 -1
- package/dist/rest/index.js +1 -1
- package/dist/schema-FNIDQKIJ.cjs +1 -0
- package/dist/schema-KD736QFN.js +1 -0
- package/dist/sqlite-adapter-HL53RLSN.cjs +1 -0
- package/dist/sqlite-adapter-TT6ZASDG.js +1 -0
- package/dist/templates/index.cjs +1 -1
- package/dist/templates/index.js +1 -1
- package/dist/trpc/index.cjs +1 -1
- package/dist/trpc/index.js +1 -1
- package/dist/ws/index.cjs +1 -1
- package/dist/ws/index.js +1 -1
- package/package.json +2 -10
- package/dist/WebhookService-CGxHtw7E.d.cts +0 -143
- package/dist/WebhookService-CNC1lYz7.d.ts +0 -143
- package/dist/auth-session-DHVGXHOH.cjs +0 -1
- package/dist/auth-session-O7IIH7EP.js +0 -1
- package/dist/base-A9AJPCG5.d.ts +0 -219
- package/dist/base-C6wyX2nC.d.cts +0 -219
- package/dist/bcryptjs-WIQSWJGK.cjs +0 -1
- package/dist/bcryptjs-ZEEHSMAG.js +0 -2
- package/dist/better-sqlite3-5IISPX34.cjs +0 -1
- package/dist/better-sqlite3-B34RIU4C.js +0 -2
- package/dist/bootstrap-PG2LGDLB.js +0 -1
- package/dist/bootstrap-YD3GLTWX.cjs +0 -1
- package/dist/bowser-SB3ZUPO4.js +0 -11
- package/dist/bowser-VX6B6ZSE.cjs +0 -10
- package/dist/chokidar-5RVQZVHP.cjs +0 -5
- package/dist/chokidar-BOYGRT4Q.js +0 -6
- package/dist/chunk-262YP5XA.cjs +0 -1
- package/dist/chunk-2HA6EKXX.js +0 -24
- package/dist/chunk-2SPWRQ5O.js +0 -122
- package/dist/chunk-2TYITUOC.js +0 -122
- package/dist/chunk-35PGCW3S.cjs +0 -1
- package/dist/chunk-3CIMGC2F.cjs +0 -56
- package/dist/chunk-3KZXF4US.js +0 -2
- package/dist/chunk-3NSZZCOJ.js +0 -2
- package/dist/chunk-3TAUNYEM.js +0 -8
- package/dist/chunk-3VXEK5ZW.cjs +0 -1
- package/dist/chunk-47CXBWMA.js +0 -2
- package/dist/chunk-4BMWWGJN.js +0 -384
- package/dist/chunk-4NTIK6DF.cjs +0 -2
- package/dist/chunk-6E44MQQ5.js +0 -115
- package/dist/chunk-6LWF5MPL.js +0 -20
- package/dist/chunk-6NBZDW53.js +0 -133
- package/dist/chunk-6TPICJ2L.js +0 -7
- package/dist/chunk-6YS6XLOD.cjs +0 -121
- package/dist/chunk-73D2PNHD.cjs +0 -7
- package/dist/chunk-7ACHOBWY.cjs +0 -13
- package/dist/chunk-7GGZA5YU.cjs +0 -2
- package/dist/chunk-7JWQ2PZP.cjs +0 -1
- package/dist/chunk-7KLEANTO.cjs +0 -1
- package/dist/chunk-7MNDQU6K.js +0 -8
- package/dist/chunk-7NH7H3WA.js +0 -10
- package/dist/chunk-7WMMKGEO.cjs +0 -1
- package/dist/chunk-ALTU3FDG.js +0 -2
- package/dist/chunk-BAVN7VDR.cjs +0 -1
- package/dist/chunk-BCEE4NBZ.cjs +0 -2
- package/dist/chunk-BUNLC3II.cjs +0 -1
- package/dist/chunk-C7QCZX7X.js +0 -2
- package/dist/chunk-D6SDGHY6.js +0 -2
- package/dist/chunk-DVWYO3KK.cjs +0 -1
- package/dist/chunk-EHWUALGH.cjs +0 -1
- package/dist/chunk-EML5FDUU.js +0 -2
- package/dist/chunk-EN65ZEK2.cjs +0 -2
- package/dist/chunk-EW424IBO.cjs +0 -1
- package/dist/chunk-EZIDQBXI.cjs +0 -1
- package/dist/chunk-F2O4QO5N.cjs +0 -383
- package/dist/chunk-F4ITQ6XQ.cjs +0 -3
- package/dist/chunk-FK2BG4HU.js +0 -3
- package/dist/chunk-FLMUMPDE.js +0 -2
- package/dist/chunk-GIS6X43A.cjs +0 -3
- package/dist/chunk-GNEVCEJU.cjs +0 -3
- package/dist/chunk-GNOSG3PK.cjs +0 -1
- package/dist/chunk-GQGFNTDZ.js +0 -2
- package/dist/chunk-GTR7JAKP.cjs +0 -3
- package/dist/chunk-HPIJI7TM.js +0 -3
- package/dist/chunk-HPYH7GTS.cjs +0 -1
- package/dist/chunk-HRAY65XH.js +0 -3
- package/dist/chunk-HTYVI2HK.cjs +0 -9
- package/dist/chunk-IKGVPXMK.js +0 -3
- package/dist/chunk-J6V573PE.cjs +0 -1
- package/dist/chunk-JA44K75G.js +0 -2
- package/dist/chunk-JRUQ5ABB.js +0 -4
- package/dist/chunk-JV4HJBXW.js +0 -14
- package/dist/chunk-KEITOXIP.js +0 -2
- package/dist/chunk-KMFLHGD5.cjs +0 -1
- package/dist/chunk-KZHXYXSH.cjs +0 -10
- package/dist/chunk-L3Q64RUX.js +0 -3
- package/dist/chunk-LEBM6ZSZ.cjs +0 -10
- package/dist/chunk-LKRI5X2V.cjs +0 -1
- package/dist/chunk-LQ3YZTPU.cjs +0 -15
- package/dist/chunk-LVBHOZZF.js +0 -4
- package/dist/chunk-LWM4WABU.js +0 -3
- package/dist/chunk-LY7N3UHH.cjs +0 -23
- package/dist/chunk-MCIZG4A3.cjs +0 -1
- package/dist/chunk-MDLJTZLV.cjs +0 -1
- package/dist/chunk-N4FXLQE3.cjs +0 -132
- package/dist/chunk-N5POANYV.js +0 -2
- package/dist/chunk-NGNJSUGL.cjs +0 -1
- package/dist/chunk-NRE6VKL6.cjs +0 -121
- package/dist/chunk-O4YE57OS.cjs +0 -6
- package/dist/chunk-OBYAIJVU.js +0 -11
- package/dist/chunk-OLRCZ6E3.js +0 -2
- package/dist/chunk-OOVNTOZC.cjs +0 -56
- package/dist/chunk-P6JITOFF.js +0 -4
- package/dist/chunk-PITMDQYN.cjs +0 -18
- package/dist/chunk-PYUWSKKP.js +0 -57
- package/dist/chunk-Q5TFO66G.cjs +0 -1
- package/dist/chunk-QO5ZWQA3.cjs +0 -74
- package/dist/chunk-QYN6C3FZ.cjs +0 -114
- package/dist/chunk-REQ622YC.js +0 -3
- package/dist/chunk-RPRGGGIW.js +0 -11
- package/dist/chunk-RVBSJ4UQ.cjs +0 -7
- package/dist/chunk-RYHOWZLK.js +0 -2
- package/dist/chunk-RYXLEFS5.js +0 -2
- package/dist/chunk-SBNMXQNO.cjs +0 -2
- package/dist/chunk-SLMIYECU.js +0 -2
- package/dist/chunk-SRIXRJHL.js +0 -4
- package/dist/chunk-TBHNE4VV.js +0 -2
- package/dist/chunk-TCFL3UWT.cjs +0 -2
- package/dist/chunk-TYQYKKWJ.js +0 -16
- package/dist/chunk-U6KFONKM.js +0 -2
- package/dist/chunk-UNYXWPLZ.cjs +0 -2
- package/dist/chunk-UWHWSWDE.js +0 -2
- package/dist/chunk-V4FAL7AG.js +0 -2
- package/dist/chunk-VQ53TFYA.cjs +0 -1
- package/dist/chunk-VRZC4TTF.cjs +0 -1
- package/dist/chunk-W45TLOOT.js +0 -2
- package/dist/chunk-WAVGRSE6.js +0 -2
- package/dist/chunk-WPM6LFCY.js +0 -2
- package/dist/chunk-WXT2XW7T.js +0 -13
- package/dist/chunk-X473JI7Z.js +0 -75
- package/dist/chunk-X6HUA6EF.cjs +0 -20
- package/dist/chunk-XDPLVJRO.js +0 -21
- package/dist/chunk-XDQVYCIR.cjs +0 -1
- package/dist/chunk-XFYSADHV.cjs +0 -2
- package/dist/chunk-XOR64WUQ.cjs +0 -19
- package/dist/chunk-Y2YAKDEQ.js +0 -2
- package/dist/chunk-YENNL5HG.js +0 -2
- package/dist/chunk-YGI5W4RS.js +0 -2
- package/dist/chunk-YIFKTA5N.js +0 -57
- package/dist/chunk-YUUXFD73.js +0 -19
- package/dist/chunk-ZAKYTBEN.js +0 -3
- package/dist/chunk-ZHA446FA.cjs +0 -1
- package/dist/chunk-ZTLGK6R4.cjs +0 -12
- package/dist/chunk-ZUBJ6RLQ.cjs +0 -1
- package/dist/client.d.cts +0 -1291
- package/dist/client.d.ts +0 -1291
- package/dist/d1-5ZQJOFDX.cjs +0 -1
- package/dist/d1-HPB6B253.js +0 -2
- package/dist/dist-es-3SSNUZST.cjs +0 -1
- package/dist/dist-es-64F22JL2.js +0 -2
- package/dist/dist-es-A5OF2STN.cjs +0 -2
- package/dist/dist-es-BOW5V247.cjs +0 -6
- package/dist/dist-es-CRIMATLL.cjs +0 -2
- package/dist/dist-es-DL3VLVP6.cjs +0 -1
- package/dist/dist-es-F2ZR55UK.js +0 -4
- package/dist/dist-es-IPSSZNFP.js +0 -1
- package/dist/dist-es-M2F7M27Y.js +0 -2
- package/dist/dist-es-M66JKZF5.js +0 -7
- package/dist/dist-es-OKLLRYI3.js +0 -2
- package/dist/dist-es-P25IKLBI.cjs +0 -1
- package/dist/dist-es-SRPWSAF4.cjs +0 -1
- package/dist/dist-es-SVHZDVUF.js +0 -3
- package/dist/dist-es-T2H2W5BX.cjs +0 -3
- package/dist/dist-es-WFI55HKT.js +0 -3
- package/dist/drizzle-orm-47ELDEM6.cjs +0 -1
- package/dist/drizzle-orm-XRTSOQJS.js +0 -1
- package/dist/event-streams-7NAWZW2I.js +0 -1
- package/dist/event-streams-JBMWCI2O.cjs +0 -1
- package/dist/fs-KWBRQ6T6.js +0 -1
- package/dist/fs-ZQYOJOIO.cjs +0 -1
- package/dist/index-NGnJpSgf.d.ts +0 -105
- package/dist/index-Zrg3sZ6R.d.cts +0 -105
- package/dist/jsonwebtoken-DFB6ZBZA.cjs +0 -8
- package/dist/jsonwebtoken-OD67R5JS.js +0 -9
- package/dist/lib-A2D63VXD.cjs +0 -1
- package/dist/lib-JQD2JAOO.js +0 -2
- package/dist/loadSso-JY4WDQPS.cjs +0 -2
- package/dist/loadSso-UQR6545M.js +0 -3
- package/dist/local-6UUGBZ4M.js +0 -1
- package/dist/local-ZYHV3J2K.cjs +0 -1
- package/dist/media-3Z6YW5J4.cjs +0 -1
- package/dist/media-E762GEHL.js +0 -1
- package/dist/mongo-auth-adapter-2H2AXDRH.cjs +0 -1
- package/dist/mongo-auth-adapter-YWMEOC42.js +0 -1
- package/dist/nodemailer-IDML4L6W.cjs +0 -53
- package/dist/nodemailer-NITB45SS.js +0 -54
- package/dist/nodemailer-transport-3VWVUBM5.cjs +0 -1
- package/dist/nodemailer-transport-7RHATUKL.js +0 -1
- package/dist/postgres-auth-adapter-QKBNXVPT.js +0 -1
- package/dist/postgres-auth-adapter-WMLM4UUC.cjs +0 -1
- package/dist/postgres-js-7YBZKGXG.cjs +0 -1
- package/dist/postgres-js-JLFIWOBH.js +0 -1
- package/dist/redis-adapter-EVK2SMKH.cjs +0 -1
- package/dist/redis-adapter-LY2NBSAG.js +0 -1
- package/dist/schema-RT6WSUYC.cjs +0 -1
- package/dist/schema-YFMSJK2P.js +0 -2
- package/dist/signin-N3T2KF5Q.js +0 -3
- package/dist/signin-VFBLX7EL.cjs +0 -2
- package/dist/sqlite-adapter-KPSISY6E.cjs +0 -1
- package/dist/sqlite-adapter-PI6SIY7O.js +0 -1
- package/dist/src-6LAUXXDM.cjs +0 -1
- package/dist/src-QBADSZV4.js +0 -1
- package/dist/sso-oidc-54BIRYR6.cjs +0 -2
- package/dist/sso-oidc-UB7G4END.js +0 -3
- package/dist/sts-WAA6I22C.js +0 -3
- package/dist/sts-YLXXIB3X.cjs +0 -2
- package/dist/types-BCOhfwHC.d.ts +0 -839
- package/dist/types-DxaK39ix.d.cts +0 -330
- package/dist/types-DxaK39ix.d.ts +0 -330
- package/dist/types-QglJ7PwT.d.cts +0 -839
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {generateHTML}from'@tiptap/html';import c from'@tiptap/starter-kit';import p from'@tiptap/extension-link';import g from'@tiptap/extension-image';import x from'@tiptap/extension-text-align';import u from'@tiptap/extension-underline';import m from'@tiptap/extension-highlight';import F from'@tiptap/extension-task-list';import y from'@tiptap/extension-task-item';import {TextStyle}from'@tiptap/extension-text-style';import f from'@tiptap/extension-color';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
|
|
2
|
+
function k(e){return e.type==="text"}function R(e){return e.type==="number"}function B(e){return e.type==="relationship"}function T(e){return e.type==="array"}function w(e){return e.type==="group"}function I(e){return e.type==="blocks"}function D(e){return e.type==="upload"}function A(e){return e.type==="image"}function L(e){return e.type==="richtext"}function C(e){return e.type==="select"}function V(e){return e.type==="row"||e.type==="collapsible"||e.type==="tabs"}function E(e){return e.type==="icon"}function S(e){return e.type==="embedding"}var o=["text","number","checkbox","date","email","password","textarea","select","radio","color","icon"],a=["richtext","json","code","upload","image","markdown","embedding"],l=["relationship","array","group","blocks"],d=["row","collapsible","tabs"],q=[...o,...a,...l,...d];function O(e,t,i){return {name:e,type:"relationship",relationTo:t,...i,required:i?.required??false}}var X=`
|
|
3
|
+
.kyro-richtext {
|
|
4
|
+
color: inherit;
|
|
5
|
+
line-height: 1.7;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.kyro-richtext > *:first-child {
|
|
9
|
+
margin-top: 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.kyro-richtext > *:last-child {
|
|
13
|
+
margin-bottom: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.kyro-richtext p,
|
|
17
|
+
.kyro-richtext ul,
|
|
18
|
+
.kyro-richtext ol,
|
|
19
|
+
.kyro-richtext blockquote,
|
|
20
|
+
.kyro-richtext pre {
|
|
21
|
+
margin: 0 0 1rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.kyro-richtext h1,
|
|
25
|
+
.kyro-richtext h2,
|
|
26
|
+
.kyro-richtext h3,
|
|
27
|
+
.kyro-richtext h4,
|
|
28
|
+
.kyro-richtext h5,
|
|
29
|
+
.kyro-richtext h6 {
|
|
30
|
+
margin: 0 0 0.75rem;
|
|
31
|
+
line-height: 1.2;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.kyro-richtext ul,
|
|
35
|
+
.kyro-richtext ol {
|
|
36
|
+
padding-left: 1.5rem;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.kyro-richtext blockquote {
|
|
40
|
+
border-left: 4px solid rgba(148, 163, 184, 0.5);
|
|
41
|
+
margin-left: 0;
|
|
42
|
+
padding-left: 1rem;
|
|
43
|
+
font-style: italic;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.kyro-richtext pre {
|
|
47
|
+
overflow-x: auto;
|
|
48
|
+
border-radius: 0.75rem;
|
|
49
|
+
background: rgba(15, 23, 42, 0.92);
|
|
50
|
+
color: #f8fafc;
|
|
51
|
+
padding: 1rem;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.kyro-richtext code {
|
|
55
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.kyro-richtext img {
|
|
59
|
+
display: block;
|
|
60
|
+
max-width: 100%;
|
|
61
|
+
height: auto;
|
|
62
|
+
border-radius: 0.75rem;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.kyro-richtext ul[data-type="taskList"] {
|
|
66
|
+
list-style: none;
|
|
67
|
+
padding: 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.kyro-richtext li[data-type="taskItem"] {
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: flex-start;
|
|
73
|
+
gap: 0.5rem;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.kyro-richtext li[data-type="taskItem"] > label {
|
|
77
|
+
user-select: none;
|
|
78
|
+
pointer-events: none;
|
|
79
|
+
margin-top: 0.2rem;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.kyro-richtext li[data-type="taskItem"] > div {
|
|
83
|
+
flex: 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.kyro-richtext mark {
|
|
87
|
+
background-color: #fef08a;
|
|
88
|
+
border-radius: 0.25rem;
|
|
89
|
+
padding: 0.125rem 0.25rem;
|
|
90
|
+
}
|
|
91
|
+
`.trim(),h=[c,p.configure({openOnClick:false}),g,x.configure({types:["heading","paragraph"]}),u,m.configure({multicolor:true}),F,y.configure({nested:true}),TextStyle,f];function $(e){return typeof e=="object"&&e!==null?e:{}}function Q(e){if(typeof e!="object"||e===null)return "";try{return `<div class="kyro-richtext">${generateHTML(e,h)}</div>`}catch(t){return console.error("Failed to render rich text:",t),""}}export{k as a,R as b,B as c,T as d,w as e,I as f,D as g,A as h,L as i,C as j,V as k,E as l,S as m,o as n,a as o,l as p,d as q,q as r,O as s,X as t,$ as u,Q as v};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {a}from'./chunk-W5GDZG64.js';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
|
|
2
|
+
function c(o){let{brand:e,title:t,badge:r,previewText:s=t,bodyHtml:i,ctaText:n,ctaUrl:a,secondaryCtaText:l,secondaryCtaUrl:g}=o,f=e?.siteName||"Lagos Buka",m=e?.logoUrl||"https://resources.lagosbukasantonio.com/lagosbuka.svg",u=e?.logoDarkUrl||e?.logoUrl||m,K=e?.appUrl||"https://lagosbukasantonio.com";return `<!DOCTYPE html>
|
|
2
3
|
<html lang="en">
|
|
3
4
|
<head>
|
|
4
5
|
<meta charset="UTF-8">
|
|
@@ -80,8 +81,8 @@
|
|
|
80
81
|
<a href="${a}" target="_blank" class="email-btn-primary" style="display: inline-block; padding: 12px 24px; background-color: #0b3b24; color: #ffffff; font-size: 13px; font-weight: 600; text-decoration: none; border-radius: 12px; box-shadow: 0 2px 6px rgba(11, 59, 36, 0.15);">
|
|
81
82
|
${n} →
|
|
82
83
|
</a>
|
|
83
|
-
${l&&
|
|
84
|
-
<a href="${
|
|
84
|
+
${l&&g?`
|
|
85
|
+
<a href="${g}" target="_blank" style="display: inline-block; padding: 12px 20px; margin-left: 8px; background-color: #f8fafc; border: 1px solid #e2e8f0; color: #334155; font-size: 13px; font-weight: 500; text-decoration: none; border-radius: 12px;">
|
|
85
86
|
${l}
|
|
86
87
|
</a>
|
|
87
88
|
`:""}
|
|
@@ -103,7 +104,7 @@
|
|
|
103
104
|
</tr>
|
|
104
105
|
</table>
|
|
105
106
|
</body>
|
|
106
|
-
</html>`}
|
|
107
|
+
</html>`}function b(o,e="User",t){let r="Confirm your email address \u2014 Kyro CMS",s=`
|
|
107
108
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
108
109
|
Hello <strong class="email-strong" style="color: #09090b;">${e}</strong>,
|
|
109
110
|
</p>
|
|
@@ -124,14 +125,14 @@
|
|
|
124
125
|
<p class="email-text" style="margin: 0 0 8px; font-size: 12px; color: #71717a;">
|
|
125
126
|
This verification link will expire in 24 hours. If you did not create an account, you can safely ignore this email.
|
|
126
127
|
</p>
|
|
127
|
-
`,i=
|
|
128
|
+
`,i=c({brand:t,title:"Confirm Your Email Address",previewText:"Please confirm your email address to activate your Kyro CMS account.",bodyHtml:s,ctaText:"Confirm Email Address",ctaUrl:o,secondaryCtaText:"Documentation",secondaryCtaUrl:"https://kyro-cms.com/docs"}),n=`Welcome, ${e}!
|
|
128
129
|
|
|
129
130
|
Please verify your email address by visiting:
|
|
130
131
|
${o}
|
|
131
132
|
|
|
132
133
|
This link expires in 24 hours.
|
|
133
134
|
|
|
134
|
-
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:r,html:i,text:n}}
|
|
135
|
+
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:r,html:i,text:n}}function x(o,e="User",t){let r="Reset your password \u2014 Kyro CMS",s=`
|
|
135
136
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
136
137
|
Hello <strong class="email-strong" style="color: #09090b;">${e}</strong>,
|
|
137
138
|
</p>
|
|
@@ -152,14 +153,14 @@ Kyro CMS \u2014 https://kyro-cms.com`;return {subject:r,html:i,text:n}}chunkBUNL
|
|
|
152
153
|
<p class="email-text" style="margin: 0 0 8px; font-size: 12px; color: #71717a;">
|
|
153
154
|
For security reasons, this link will expire in 1 hour. If you did not request a password reset, no further action is required.
|
|
154
155
|
</p>
|
|
155
|
-
`,i=
|
|
156
|
+
`,i=c({brand:t,title:"Reset Your Password",previewText:"Use this secure link to reset your Kyro CMS password.",bodyHtml:s,ctaText:"Reset Password",ctaUrl:o}),n=`Hello ${e},
|
|
156
157
|
|
|
157
158
|
Reset your password using the following link:
|
|
158
159
|
${o}
|
|
159
160
|
|
|
160
161
|
This link will expire in 1 hour.
|
|
161
162
|
|
|
162
|
-
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:r,html:i,text:n}}
|
|
163
|
+
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:r,html:i,text:n}}function _(o="User",e="https://kyro-cms.com",t){let r="Welcome to Kyro CMS!",s=`
|
|
163
164
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
164
165
|
Welcome <strong class="email-strong" style="color: #09090b;">${o}</strong>,
|
|
165
166
|
</p>
|
|
@@ -180,11 +181,11 @@ Kyro CMS \u2014 https://kyro-cms.com`;return {subject:r,html:i,text:n}}chunkBUNL
|
|
|
180
181
|
</td>
|
|
181
182
|
</tr>
|
|
182
183
|
</table>
|
|
183
|
-
`,i=
|
|
184
|
+
`,i=c({brand:t,title:"Welcome to Kyro CMS",previewText:"Your account is verified and ready. Start building content applications.",bodyHtml:s,ctaText:"Open Dashboard",ctaUrl:e,secondaryCtaText:"Documentation",secondaryCtaUrl:"https://kyro-cms.com/docs"}),n=`Welcome to Kyro CMS, ${o}!
|
|
184
185
|
|
|
185
186
|
Your account is active. Log in at ${e} to start building.
|
|
186
187
|
|
|
187
|
-
Documentation: https://kyro-cms.com/docs`;return {subject:r,html:i,text:n}}
|
|
188
|
+
Documentation: https://kyro-cms.com/docs`;return {subject:r,html:i,text:n}}function w(o="User",e,t,r){let s="Security Alert: Password Changed \u2014 Kyro CMS",i=new Date().toUTCString(),n=`
|
|
188
189
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b; text-align: center;">
|
|
189
190
|
Hello <strong class="email-strong" style="color: #09090b;">${o}</strong>,
|
|
190
191
|
</p>
|
|
@@ -211,11 +212,11 @@ Documentation: https://kyro-cms.com/docs`;return {subject:r,html:i,text:n}}chunk
|
|
|
211
212
|
</td>
|
|
212
213
|
</tr>
|
|
213
214
|
</table>`:""}
|
|
214
|
-
`,a=
|
|
215
|
+
`,a=c({brand:e,title:"Password Updated",previewText:"Your Kyro CMS account password was updated.",bodyHtml:n,ctaText:"Account Security",ctaUrl:"https://kyro-cms.com"}),l=`Security Alert: Your Kyro CMS password was updated at ${i}.
|
|
215
216
|
|
|
216
217
|
If you did not make this change, please reset your password immediately.
|
|
217
218
|
|
|
218
|
-
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:a,text:l}}
|
|
219
|
+
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:a,text:l}}function S(o,e,t="User",r){let s="Your one-time login link \u2014 Kyro CMS",i=`
|
|
219
220
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
220
221
|
Hello <strong class="email-strong" style="color: #09090b;">${t}</strong>,
|
|
221
222
|
</p>
|
|
@@ -241,7 +242,7 @@ Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:a,text:l}}chunkBUNL
|
|
|
241
242
|
<p class="email-text" style="margin: 0 0 8px; font-size: 12px; color: #71717a;">
|
|
242
243
|
This single-use link will expire in 10 minutes. Never share authentication links with anyone.
|
|
243
244
|
</p>
|
|
244
|
-
`,n=
|
|
245
|
+
`,n=c({brand:r,title:"Sign in to Kyro CMS",previewText:"Your secure magic login link for Kyro CMS.",bodyHtml:i,ctaText:"Sign In Now",ctaUrl:o}),a=`Hello ${t},
|
|
245
246
|
|
|
246
247
|
Sign in to Kyro CMS using the link below:
|
|
247
248
|
${o}${e?`
|
|
@@ -250,7 +251,7 @@ Or enter code: ${e}`:""}
|
|
|
250
251
|
|
|
251
252
|
This link expires in 10 minutes.
|
|
252
253
|
|
|
253
|
-
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:n,text:a}}
|
|
254
|
+
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:n,text:a}}function C(o,e,t="User",r,s,i){let n="Security Alert: Account Temporarily Locked \u2014 Kyro CMS",a=`
|
|
254
255
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b; text-align: center;">
|
|
255
256
|
Hello <strong class="email-strong" style="color: #09090b;">${t}</strong>,
|
|
256
257
|
</p>
|
|
@@ -277,9 +278,9 @@ Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:n,text:a}}chunkBUNL
|
|
|
277
278
|
</td>
|
|
278
279
|
</tr>
|
|
279
280
|
</table>`:""}
|
|
280
|
-
`,l=
|
|
281
|
+
`,l=c({brand:r,title:"Account Temporarily Locked",previewText:"Your Kyro CMS account was locked due to multiple failed login attempts.",bodyHtml:a,ctaText:"Unlock Instructions",ctaUrl:"https://kyro-cms.com/docs"}),g=`Security Alert: Account temporarily locked for ${t} after ${o} failed login attempts. Unlocks in ${e} minutes.
|
|
281
282
|
|
|
282
|
-
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:n,html:l,text:
|
|
283
|
+
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:n,html:l,text:g}}function T(o,e="Editor",t="An Administrator",r){let s="You're invited to join Kyro CMS",i=`
|
|
283
284
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
284
285
|
Hello,
|
|
285
286
|
</p>
|
|
@@ -296,12 +297,12 @@ Kyro CMS \u2014 https://kyro-cms.com`;return {subject:n,html:l,text:p}}chunkBUNL
|
|
|
296
297
|
</td>
|
|
297
298
|
</tr>
|
|
298
299
|
</table>
|
|
299
|
-
`,n=
|
|
300
|
+
`,n=c({brand:r,title:"Workspace Invitation",previewText:`You have been invited to join Kyro CMS as an ${e}.`,bodyHtml:i,ctaText:"Accept Invitation",ctaUrl:o,secondaryCtaText:"Documentation",secondaryCtaUrl:"https://kyro-cms.com/docs"}),a=`You're invited to join Kyro CMS as an ${e} by ${t}.
|
|
300
301
|
|
|
301
302
|
Accept your invitation here:
|
|
302
303
|
${o}
|
|
303
304
|
|
|
304
|
-
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:n,text:a}}
|
|
305
|
+
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:n,text:a}}function k(o,e,t="User",r,s="Unknown Device"){let i="Security Alert: New Sign-in to Kyro CMS",n=`
|
|
305
306
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b; text-align: center;">
|
|
306
307
|
Hello <strong class="email-strong" style="color: #09090b;">${t}</strong>,
|
|
307
308
|
</p>
|
|
@@ -329,7 +330,7 @@ Kyro CMS \u2014 https://kyro-cms.com`;return {subject:s,html:n,text:a}}chunkBUNL
|
|
|
329
330
|
</td>
|
|
330
331
|
</tr>
|
|
331
332
|
</table>
|
|
332
|
-
`,a=
|
|
333
|
+
`,a=c({brand:r,title:"New Sign-in Detected",previewText:"A new sign-in was detected on your Kyro CMS account.",bodyHtml:n,ctaText:"Review Account Security",ctaUrl:"https://kyro-cms.com"}),l=`Security Alert: New Sign-in to Kyro CMS
|
|
333
334
|
|
|
334
335
|
Hello ${t},
|
|
335
336
|
|
|
@@ -337,7 +338,7 @@ A new sign-in to your account was detected at ${e} from ${o} using ${s}.
|
|
|
337
338
|
|
|
338
339
|
If you did not sign in recently, please reset your password immediately.
|
|
339
340
|
|
|
340
|
-
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:i,html:a,text:l}}
|
|
341
|
+
Kyro CMS \u2014 https://kyro-cms.com`;return {subject:i,html:a,text:l}}function E(o,e="Customer",t,r,s){let i=`Order confirmed #${o}`,n=`
|
|
341
342
|
<p class="email-text" style="margin: 0 0 14px; font-size: 14px; line-height: 1.6; color: #475569; text-align: center;">
|
|
342
343
|
Hi ${e}, thanks for your order. We're getting your food freshly prepared.
|
|
343
344
|
</p>
|
|
@@ -362,13 +363,13 @@ Kyro CMS \u2014 https://kyro-cms.com`;return {subject:i,html:a,text:l}}chunkBUNL
|
|
|
362
363
|
<p style="margin: 0; font-size: 12px; color: #94a3b8; text-align: center; line-height: 1.5;">
|
|
363
364
|
You can track the live preparation and delivery status anytime.
|
|
364
365
|
</p>
|
|
365
|
-
`,a=
|
|
366
|
+
`,a=c({brand:s,title:"Order Confirmed",badge:"Order received",previewText:`Your order #${o} has been confirmed.`,bodyHtml:n,ctaText:"Track order live",ctaUrl:r||"https://lagosbukasantonio.com/track-order"}),l=`Hi ${e},
|
|
366
367
|
|
|
367
368
|
Thank you for your order #${o}!
|
|
368
369
|
|
|
369
370
|
Total: ${t}
|
|
370
371
|
|
|
371
|
-
Track your order: ${r||"https://lagosbukasantonio.com"}`;return {subject:i,html:a,text:l}}
|
|
372
|
+
Track your order: ${r||"https://lagosbukasantonio.com"}`;return {subject:i,html:a,text:l}}function v(o,e="Customer",t,r,s){let i=`Your Order #${o} is on the way!`,n=`
|
|
372
373
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
373
374
|
Great news, <strong class="email-strong" style="color: #09090b;">${e}</strong>!
|
|
374
375
|
</p>
|
|
@@ -383,12 +384,12 @@ Track your order: ${r||"https://lagosbukasantonio.com"}`;return {subject:i,html:
|
|
|
383
384
|
</td>
|
|
384
385
|
</tr>
|
|
385
386
|
</table>
|
|
386
|
-
`,a=
|
|
387
|
+
`,a=c({brand:s,title:"Order Shipped",previewText:`Your order #${o} has shipped. Track your package now.`,bodyHtml:n,ctaText:"Track Package",ctaUrl:r}),l=`Hi ${e},
|
|
387
388
|
|
|
388
389
|
Your order #${o} has been shipped!
|
|
389
390
|
|
|
390
391
|
Tracking Number: ${t}
|
|
391
|
-
Track it here: ${r}`;return {subject:i,html:a,text:l}}
|
|
392
|
+
Track it here: ${r}`;return {subject:i,html:a,text:l}}function A(o,e="Customer",t,r){let s=`Your Order #${o} has been delivered`,i=`
|
|
392
393
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
393
394
|
Hi <strong class="email-strong" style="color: #09090b;">${e}</strong>,
|
|
394
395
|
</p>
|
|
@@ -398,11 +399,11 @@ Track it here: ${r}`;return {subject:i,html:a,text:l}}chunkBUNLC3II_cjs.h();func
|
|
|
398
399
|
<p class="email-text" style="margin: 0 0 20px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
399
400
|
We'd love to hear your thoughts. If you have a minute, please leave a review for your items.
|
|
400
401
|
</p>
|
|
401
|
-
`,n=
|
|
402
|
+
`,n=c({brand:r,title:"Order Delivered",previewText:`Your order #${o} has arrived!`,bodyHtml:i,ctaText:"Leave a Review",ctaUrl:t}),a=`Hi ${e},
|
|
402
403
|
|
|
403
404
|
Your order #${o} has been delivered!
|
|
404
405
|
|
|
405
|
-
Leave a review here: ${t}`;return {subject:s,html:n,text:a}}
|
|
406
|
+
Leave a review here: ${t}`;return {subject:s,html:n,text:a}}function R(o,e="Customer",t,r){let s=`Refund Processed for Order #${o}`,i=`
|
|
406
407
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
407
408
|
Hi <strong class="email-strong" style="color: #09090b;">${e}</strong>,
|
|
408
409
|
</p>
|
|
@@ -417,20 +418,20 @@ Leave a review here: ${t}`;return {subject:s,html:n,text:a}}chunkBUNLC3II_cjs.h(
|
|
|
417
418
|
</td>
|
|
418
419
|
</tr>
|
|
419
420
|
</table>
|
|
420
|
-
`,n=
|
|
421
|
+
`,n=c({brand:r,title:"Refund Processed",previewText:`We have processed a refund of ${t} for order #${o}.`,bodyHtml:i,ctaText:"View Store",ctaUrl:"https://kyro-cms.com"}),a=`Hi ${e},
|
|
421
422
|
|
|
422
423
|
We have processed a refund of ${t} for order #${o}.
|
|
423
424
|
|
|
424
|
-
View store: https://kyro-cms.com`;return {subject:s,html:n,text:a}}
|
|
425
|
+
View store: https://kyro-cms.com`;return {subject:s,html:n,text:a}}function I(o="Customer",e,t){let r="You left something behind...",s=`
|
|
425
426
|
<p class="email-text" style="margin: 0 0 16px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
426
427
|
Hi <strong class="email-strong" style="color: #09090b;">${o}</strong>,
|
|
427
428
|
</p>
|
|
428
429
|
<p class="email-text" style="margin: 0 0 20px; font-size: 14px; line-height: 1.6; color: #52525b;">
|
|
429
430
|
We noticed you left some great items in your shopping cart. They are still waiting for you, but they might sell out soon!
|
|
430
431
|
</p>
|
|
431
|
-
`,i=
|
|
432
|
+
`,i=c({brand:t,title:"Complete Your Purchase",previewText:"Your shopping cart is waiting for you. Complete your purchase now.",bodyHtml:s,ctaText:"Return to Checkout",ctaUrl:e}),n=`Hi ${o},
|
|
432
433
|
|
|
433
|
-
You left some items in your cart! Complete your purchase here: ${e}`;return {subject:r,html:i,text:n}}function $(o){return {verifyEmail:(e,t)=>b(e,t,o),resetPassword:(e,t)=>x(e,t,o),welcome:(e,t)=>_(e,t,o),passwordChanged:e=>w(e,o),magicLink:(e,t,r)=>S(e,t,r,o),accountLocked:(e,t,r)=>C(e,t,r,o),newLogin:(e,t,r)=>k(e,t,r,o),userInvite:(e,t,r)=>T(e,t,r,o),orderConfirmation:(e,t,r,s)=>E(e,t,r||"0.00",s,o),orderShipped:(e,t,r,s)=>v(e,t,r||"",s||"",o),orderDelivered:(e,t,r)=>A(e,t,r||"",o),orderRefunded:(e,t,r)=>R(e,t,r||"0.00",o),abandonedCart:(e,t)=>I(e,t||"",o)}}
|
|
434
|
+
You left some items in your cart! Complete your purchase here: ${e}`;return {subject:r,html:i,text:n}}function $(o){return {verifyEmail:(e,t)=>b(e,t,o),resetPassword:(e,t)=>x(e,t,o),welcome:(e,t)=>_(e,t,o),passwordChanged:e=>w(e,o),magicLink:(e,t,r)=>S(e,t,r,o),accountLocked:(e,t,r)=>C(e,t,r,o),newLogin:(e,t,r)=>k(e,t,r,o),userInvite:(e,t,r)=>T(e,t,r,o),orderConfirmation:(e,t,r,s)=>E(e,t,r||"0.00",s,o),orderShipped:(e,t,r,s)=>v(e,t,r||"",s||"",o),orderDelivered:(e,t,r)=>A(e,t,r||"",o),orderRefunded:(e,t,r)=>R(e,t,r||"0.00",o),abandonedCart:(e,t)=>I(e,t||"",o)}}var O=false,y=class o{db;cache={};loaded=false;static SENSITIVE_KEYS=["storage.s3.secret_access_key","storage.r2.secret_access_key","storage.gcs.private_key","storage.backblaze.application_key","storage.wasabi.secret_access_key","storage.ftp.password","storage.bunny.api_key","storage.cloudinary.api_secret","storage.imgix.sign_key","email.smtp.pass","auth.jwt_secret","auth.github_secret","auth.google_secret","auth.app_secret","database.url","redis.url","auth.admin_password"];constructor(e){this.db=e;}async load(){if(!this.loaded){await this.ensureSettingsTable();try{if(typeof this.db?.select=="function"){let e=await this.db.select().from(a);this.cache=e.reduce((t,r)=>(t[r.key]=r.value,t),{});}await this.loadFromGlobals();}catch{console.warn("ConfigService: Could not load settings from database, using environment fallbacks.");}this.loaded=true;}}async ensureSettingsTable(){if(!O)try{if(typeof this.db?.execute=="function"){let{sql:e}=await import('drizzle-orm');await this.db.execute(e`
|
|
434
435
|
CREATE TABLE IF NOT EXISTS "settings" (
|
|
435
436
|
"key" VARCHAR(255) PRIMARY KEY,
|
|
436
437
|
"value" TEXT NOT NULL,
|
|
@@ -444,5 +445,5 @@ You left some items in your cart! Complete your purchase here: ${e}`;return {sub
|
|
|
444
445
|
description TEXT,
|
|
445
446
|
updated_at TEXT
|
|
446
447
|
)
|
|
447
|
-
`),O=!0);}catch{}}async loadFromGlobals(){try{let e=null;if(typeof this.db?.findOne=="function")try{let s=await this.db.findOne({collection:"_globals_storage-settings",where:{},draft:!0});s&&(e=s);}catch{}if(!e&&typeof this.db?.execute=="function"){let{sql:s}=await import('./drizzle-orm-47ELDEM6.cjs'),i=['"_globals_storage-settings"','"_globals_storage_settings"','"global_storage_settings"'];for(let n of i)try{let a=await this.db.execute(s`SELECT * FROM ${s.raw(n)} LIMIT 1`);if(e=Array.isArray(a)?a[0]:a?.rows?a.rows[0]:null,e)break}catch{}}else if(!e&&typeof this.db?.prepare=="function"){let s=['"_globals_storage-settings"','"_globals_storage_settings"','"global_storage_settings"'];for(let i of s)try{if(e=this.db.prepare(`SELECT * FROM ${i} LIMIT 1`).get(),e)break}catch{}}if(!e)return;let t=s=>{if(!s)return null;if(typeof s=="string")try{return JSON.parse(s)}catch{return null}return s},r=e.provider||"local";if(this.cache["storage.type"]=r,r==="local"){let s=t(e.local);this.cache["storage.local.dir"]=s?.uploadDir||"./public/uploads",this.cache["storage.local.url"]=s?.baseUrl||"/uploads";}if(r==="aws"){let s=t(e.aws);this.cache["storage.s3.bucket"]=s?.bucket||"",this.cache["storage.s3.region"]=s?.region||"us-east-1",this.cache["storage.s3.access_key_id"]=s?.accessKeyId||"",this.cache["storage.s3.secret_access_key"]=s?.secretAccessKey||"",this.cache["storage.s3.endpoint"]=s?.endpoint||"",this.cache["storage.s3.cdn_url"]=s?.cdnUrl||"",this.cache["storage.s3.prefix"]=s?.prefix||"";}if(r==="r2"){let s=t(e.r2);this.cache["storage.r2.account_id"]=s?.accountId||"",this.cache["storage.r2.access_key_id"]=s?.accessKeyId||"",this.cache["storage.r2.secret_access_key"]=s?.secretAccessKey||"",this.cache["storage.r2.bucket"]=s?.bucket||"",this.cache["storage.r2.cdn_url"]=s?.cdnUrl||"",this.cache["storage.r2.prefix"]=s?.prefix||"";}if(r==="cloudinary"){let s=t(e.cloudinary);this.cache["storage.cloudinary.cloud_name"]=s?.cloudName||"",this.cache["storage.cloudinary.api_key"]=s?.apiKey||"",this.cache["storage.cloudinary.api_secret"]=s?.apiSecret||"",this.cache["storage.cloudinary.folder"]=s?.folder||"";}if(r==="ftp"){let s=t(e.ftp);this.cache["storage.ftp.host"]=s?.host||"",this.cache["storage.ftp.port"]=String(s?.port||"21"),this.cache["storage.ftp.user"]=s?.user||"",this.cache["storage.ftp.password"]=s?.password||"",this.cache["storage.ftp.secure"]=s?.secure?"true":"false",this.cache["storage.ftp.base_url"]=s?.baseUrl||"",this.cache["storage.ftp.prefix"]=s?.prefix||"";}}catch(e){console.warn("ConfigService: Could not load storage settings from globals table:",e);}try{let e=null;if(typeof this.db?.findOne=="function")try{let t=await this.db.findOne({collection:"_globals_email-settings",where:{},draft:!0});t&&(e=t);}catch{}if(!e&&typeof this.db?.execute=="function"){let{sql:t}=await import('./drizzle-orm-47ELDEM6.cjs'),r=['"_globals_email-settings"','"_globals_email_settings"','"global_email_settings"'];for(let s of r)try{let i=await this.db.execute(t`SELECT * FROM ${t.raw(s)} LIMIT 1`);if(e=Array.isArray(i)?i[0]:i?.rows?i.rows[0]:null,e)break}catch{}}else if(!e&&typeof this.db?.prepare=="function"){let t=['"_globals_email-settings"','"_globals_email_settings"','"global_email_settings"'];for(let r of t)try{if(e=this.db.prepare(`SELECT * FROM ${r} LIMIT 1`).get(),e)break}catch{}}if(e){let t=r=>{if(!r)return null;if(typeof r=="string")try{return JSON.parse(r)}catch{return null}return r};if(this.cache["email.provider"]=e.provider||"smtp",this.cache["email.smtp.from"]=e.fromEmail||"",this.cache["email.smtp.from_name"]=e.fromName||"",this.cache["email.smtp.reply_to"]=e.replyTo||"",e.provider==="smtp"){let r=t(e.smtp);this.cache["email.smtp.host"]=r?.host||"",this.cache["email.smtp.port"]=String(r?.port||"587"),this.cache["email.smtp.user"]=r?.username||"",this.cache["email.smtp.pass"]=r?.password||"",this.cache["email.smtp.secure"]=r?.secure?"true":"false";}else if(e.provider==="resend"){let r=t(e.resend);this.cache["email.smtp.pass"]=r?.apiKey||"";}else if(e.provider==="sendgrid"){let r=t(e.sendgrid);this.cache["email.smtp.pass"]=r?.apiKey||"";}else if(e.provider==="mailgun"){let r=t(e.mailgun);this.cache["email.smtp.pass"]=r?.apiKey||"";}else if(e.provider==="ses"){let r=t(e.ses);this.cache["email.smtp.user"]=r?.accessKeyId||"",this.cache["email.smtp.pass"]=r?.secretAccessKey||"";}}}catch(e){console.warn("ConfigService: Could not load email settings from globals table:",e);}}get(e,t,r){return this.cache[e]?this.cache[e]:t&&process.env[t]?process.env[t]:r}getStorageConfig(){let e="local";return typeof globalThis.STORAGE_BUCKET<"u"&&(e="cloudflare_r2"),{type:this.get("storage.type","STORAGE_TYPE",e),s3:{bucket:this.get("storage.s3.bucket","STORAGE_BUCKET"),region:this.get("storage.s3.region","STORAGE_REGION","us-east-1"),accessKeyId:this.get("storage.s3.access_key_id","STORAGE_ACCESS_KEY_ID"),secretAccessKey:this.get("storage.s3.secret_access_key","STORAGE_SECRET_ACCESS_KEY"),endpoint:this.get("storage.s3.endpoint","STORAGE_ENDPOINT"),cdnUrl:this.get("storage.s3.cdn_url","STORAGE_CDN_URL"),prefix:this.get("storage.s3.prefix","STORAGE_PREFIX")},r2:{accountId:this.get("storage.r2.account_id","R2_ACCOUNT_ID"),accessKeyId:this.get("storage.r2.access_key_id","R2_ACCESS_KEY_ID"),secretAccessKey:this.get("storage.r2.secret_access_key","R2_SECRET_ACCESS_KEY"),bucket:this.get("storage.r2.bucket","R2_BUCKET"),cdnUrl:this.get("storage.r2.cdn_url","R2_CDN_URL"),prefix:this.get("storage.r2.prefix","R2_PREFIX")},gcs:{bucket:this.get("storage.gcs.bucket","GCS_BUCKET"),projectId:this.get("storage.gcs.project_id","GCS_PROJECT_ID"),clientEmail:this.get("storage.gcs.client_email","GCS_CLIENT_EMAIL"),privateKey:this.get("storage.gcs.private_key","GCS_PRIVATE_KEY"),cdnUrl:this.get("storage.gcs.cdn_url","GCS_CDN_URL"),prefix:this.get("storage.gcs.prefix","GCS_PREFIX")},digitalocean:{bucket:this.get("storage.digitalocean.bucket","DO_BUCKET"),region:this.get("storage.digitalocean.region","DO_REGION","nyc3"),accessKeyId:this.get("storage.digitalocean.access_key_id","DO_ACCESS_KEY_ID"),secretAccessKey:this.get("storage.digitalocean.secret_access_key","DO_SECRET_ACCESS_KEY"),cdnUrl:this.get("storage.digitalocean.cdn_url","DO_CDN_URL"),prefix:this.get("storage.digitalocean.prefix","DO_PREFIX")},backblaze:{bucket:this.get("storage.backblaze.bucket","BB_BUCKET"),accountId:this.get("storage.backblaze.account_id","BB_ACCOUNT_ID"),applicationKeyId:this.get("storage.backblaze.application_key_id","BB_APPLICATION_KEY_ID"),applicationKey:this.get("storage.backblaze.application_key","BB_APPLICATION_KEY"),cdnUrl:this.get("storage.backblaze.cdn_url","BB_CDN_URL"),prefix:this.get("storage.backblaze.prefix","BB_PREFIX")},wasabi:{bucket:this.get("storage.wasabi.bucket","WASABI_BUCKET"),region:this.get("storage.wasabi.region","WASABI_REGION","us-east-1"),accessKeyId:this.get("storage.wasabi.access_key_id","WASABI_ACCESS_KEY_ID"),secretAccessKey:this.get("storage.wasabi.secret_access_key","WASABI_SECRET_ACCESS_KEY"),cdnUrl:this.get("storage.wasabi.cdn_url","WASABI_CDN_URL"),prefix:this.get("storage.wasabi.prefix","WASABI_PREFIX")},bunny:{storageZone:this.get("storage.bunny.storage_zone","BUNNY_STORAGE_ZONE"),apiKey:this.get("storage.bunny.api_key","BUNNY_API_KEY"),cdnUrl:this.get("storage.bunny.cdn_url","BUNNY_CDN_URL"),prefix:this.get("storage.bunny.prefix","BUNNY_PREFIX")},ftp:{host:this.get("storage.ftp.host","FTP_HOST"),port:parseInt(this.get("storage.ftp.port","FTP_PORT","21"),10),user:this.get("storage.ftp.user","FTP_USER"),password:this.get("storage.ftp.password","FTP_PASSWORD"),secure:this.get("storage.ftp.secure","FTP_SECURE")==="true",baseUrl:this.get("storage.ftp.base_url","FTP_BASE_URL"),prefix:this.get("storage.ftp.prefix","FTP_PREFIX")},cloudinary:{cloudName:this.get("storage.cloudinary.cloud_name","CLOUDINARY_CLOUD_NAME"),apiKey:this.get("storage.cloudinary.api_key","CLOUDINARY_API_KEY"),apiSecret:this.get("storage.cloudinary.api_secret","CLOUDINARY_API_SECRET"),folder:this.get("storage.cloudinary.folder","CLOUDINARY_FOLDER")},imgix:{domain:this.get("storage.imgix.domain","IMGIX_DOMAIN"),signKey:this.get("storage.imgix.sign_key","IMGIX_SIGN_KEY")},local:{uploadDir:this.get("storage.local.dir","STORAGE_LOCAL_DIR","./public/uploads"),baseUrl:this.get("storage.local.url","STORAGE_LOCAL_URL","/uploads")}}}getEmailConfig(){return {provider:this.get("email.provider","EMAIL_PROVIDER","smtp"),host:this.get("email.smtp.host","SMTP_HOST"),port:parseInt(this.get("email.smtp.port","SMTP_PORT","587"),10),secure:this.get("email.smtp.secure","SMTP_SECURE")==="true",user:this.get("email.smtp.user","SMTP_USER"),pass:this.get("email.smtp.pass","SMTP_PASS"),from:this.get("email.smtp.from","SMTP_FROM","noreply@example.com"),fromName:this.get("email.smtp.from_name","SMTP_FROM_NAME","Kyro CMS"),replyTo:this.get("email.smtp.reply_to","SMTP_REPLY_TO")}}maskSensitive(e,t){return t&&(o.SENSITIVE_KEYS.includes(e)?"********":t)}async set(e,t,r){await this.db.insert(chunkHPYH7GTS_cjs.a).values({key:e,value:t,description:r,updatedAt:new Date}).onConflictDoUpdate({target:[chunkHPYH7GTS_cjs.a.key],set:{value:t,description:r,updatedAt:new Date}}),this.cache[e]=t;}};var U=class o{transporter;config;templates;transporterInitialized=false;constructor(e,t){this.config=e,this.templates={...$(e.brand),...t};}async ensureTransporter(){if(this.transporterInitialized)return this.transporter;let{default:e}=await import('./nodemailer-IDML4L6W.cjs');return this.config.provider==="smtp"&&this.config.smtp?this.transporter=e.createTransport({host:this.config.smtp.host,port:this.config.smtp.port,secure:this.config.smtp.secure,auth:this.config.smtp.auth}):this.config.provider==="ses"&&this.config.ses&&(this.transporter=e.createTransport({host:`email-smtp.${this.config.ses.region}.amazonaws.com`,port:587,secure:false,auth:{user:this.config.ses.accessKeyId,pass:this.config.ses.secretAccessKey}})),this.transporterInitialized=true,this.transporter}async send(e){let{provider:t,from:r,fromName:s,replyTo:i}=this.config,n=`"${s||"Kyro CMS"}" <${r}>`,a=e.replyTo||i;try{let l;switch(t){case "smtp":case "ses":{let p=await this.ensureTransporter();if(!p)throw new Error(`${t} transporter not initialized`);l=await p.sendMail({from:n,to:Array.isArray(e.to)?e.to.join(", "):e.to,subject:e.subject,html:e.html,text:e.text,replyTo:a});}break;case "resend":l=await this.sendViaResend(n,e,a);break;case "sendgrid":l=await this.sendViaSendGrid(n,e,a);break;case "mailgun":l=await this.sendViaMailgun(n,e,a);break;default:throw new Error(`Unsupported email provider: ${t}`)}return l}catch(l){throw console.error("[EmailTransport] FAILED to send email:",l.message),l.response&&console.error("[EmailTransport] Provider Error Detail:",JSON.stringify(l.response,null,2)),l}}async sendViaResend(e,t,r){let s=this.config.resend?.apiKey;if(!s)throw new Error("Resend API Key missing");let i={from:e,to:t.to,subject:t.subject,html:t.html,text:t.text,reply_to:r},n=await fetch("https://api.resend.com/emails",{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.ok){let a=await n.json();throw new Error(`Resend Error: ${JSON.stringify(a)}`)}return n.json()}async sendViaSendGrid(e,t,r){let s=this.config.sendgrid?.apiKey;if(!s)throw new Error("SendGrid API Key missing");let i={personalizations:[{to:Array.isArray(t.to)?t.to.map(a=>({email:a})):[{email:t.to}]}],from:{email:e.match(/<(.+)>/)?.[1]||e,name:e.match(/"(.+)"/)?.[1]},subject:t.subject,content:[{type:"text/plain",value:t.text||""},{type:"text/html",value:t.html}],reply_to:r?{email:r}:void 0},n=await fetch("https://api.sendgrid.com/v3/mail/send",{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.ok){let a=await n.json();throw new Error(`SendGrid Error: ${JSON.stringify(a)}`)}return {success:true}}async sendViaMailgun(e,t,r){let{apiKey:s,domain:i,region:n}=this.config.mailgun||{};if(!s||!i)throw new Error("Mailgun config missing");let a=n==="eu"?"api.eu.mailgun.net":"api.mailgun.net",l=btoa(`api:${s}`),p=new URLSearchParams;p.append("from",e);let f=Array.isArray(t.to)?t.to.join(", "):t.to;p.append("to",f),p.append("subject",t.subject),p.append("html",t.html),t.text&&p.append("text",t.text),r&&p.append("h:Reply-To",r);let m=await fetch(`https://${a}/v3/${i}/messages`,{method:"POST",headers:{Authorization:`Basic ${l}`,"Content-Type":"application/x-www-form-urlencoded"},body:p});if(!m.ok){let u=await m.json();throw new Error(`Mailgun Error: ${JSON.stringify(u)}`)}return m.json()}getTemplates(){return this.templates}async verifyConnection(){if(this.config.provider==="smtp"||this.config.provider==="ses")try{let e=await this.ensureTransporter();if(e)return await e.verify(),!0}catch{return false}return !!(this.config.resend?.apiKey||this.config.sendgrid?.apiKey||this.config.mailgun?.apiKey)}static async fetchBrandConfig(e){let t="Kyro CMS",r="https://kyro-cms.com/logo.svg",s="https://kyro-cms.com/logo-white.svg";try{let i=null,n=null;if(typeof e?.findOne=="function")i=await e.findOne({collection:"_globals_store-settings",where:{},draft:!0}),n=await e.findOne({collection:"_globals_brand-settings",where:{},draft:!0});else if(typeof e?.execute=="function"){let{sql:a}=await import('./drizzle-orm-47ELDEM6.cjs');try{let l=await e.execute(a`SELECT * FROM "_globals_store-settings" LIMIT 1`);i=Array.isArray(l)?l[0]:l?.rows?l.rows[0]:null;}catch{}try{let l=await e.execute(a`SELECT * FROM "_globals_brand-settings" LIMIT 1`);n=Array.isArray(l)?l[0]:l?.rows?l.rows[0]:null;}catch{}}else if(typeof e?.prepare=="function"){try{i=e.prepare('SELECT * FROM "_globals_store-settings" LIMIT 1').get();}catch{}try{n=e.prepare('SELECT * FROM "_globals_brand-settings" LIMIT 1').get();}catch{}}if(i?.storeName&&(t=i.storeName),n?.identity){let a=typeof n.identity=="string"?JSON.parse(n.identity):n.identity,l=async p=>{if(typeof e?.findOne=="function")return (await e.findOne({collection:"media",where:{id:{equals:p}}}))?.url;if(typeof e?.execute=="function"){let{sql:f}=await import('./drizzle-orm-47ELDEM6.cjs');try{let m=await e.execute(f`SELECT url FROM "media" WHERE id = ${p}`);return (Array.isArray(m)?m[0]:m?.rows?m.rows[0]:null)?.url}catch{}}else if(typeof e?.prepare=="function")try{return e.prepare('SELECT url FROM "media" WHERE id = ?').get(p)?.url}catch{}};if(a.primaryLogo){let p=await l(a.primaryLogo);p&&(r=p);}if(a.darkLogo){let p=await l(a.darkLogo);p&&(s=p);}}}catch{}return {siteName:t,logoUrl:r,logoDarkUrl:s,appUrl:process.env.PUBLIC_URL||"https://kyro-cms.com"}}static async fromConfig(e){let t=new y(e);await t.load();let r=t.getEmailConfig();if(!r.provider)return this.fromEnv();let i={brand:await this.fetchBrandConfig(e),provider:r.provider||"smtp",from:r.from||"noreply@example.com",fromName:r.fromName,replyTo:r.replyTo,smtp:r.provider==="smtp"?{host:r.host||"",port:r.port||587,secure:r.secure||false,auth:{user:r.user||"",pass:r.pass||""}}:void 0,resend:r.provider==="resend"?{apiKey:r.pass||""}:void 0,sendgrid:r.provider==="sendgrid"?{apiKey:r.pass||""}:void 0,mailgun:r.provider==="mailgun"?{apiKey:r.pass||"",domain:r.host||"",region:r.secure?"eu":"us"}:void 0,ses:r.provider==="ses"?{accessKeyId:r.user||"",secretAccessKey:r.pass||"",region:r.host||"us-east-1"}:void 0};return new o(i)}static fromEnv(){let e=process.env.EMAIL_PROVIDER||"smtp",t=process.env.SMTP_FROM||process.env.DEFAULT_FROM||"noreply@example.com",r=process.env.SMTP_FROM_NAME||"Kyro CMS",s=process.env.SMTP_REPLY_TO;if(e==="smtp"){let i=process.env.SMTP_HOST,n=process.env.SMTP_USER,a=process.env.SMTP_PASS;return !i||!n||!a?null:new o({provider:"smtp",from:t,fromName:r,replyTo:s,smtp:{host:i,port:parseInt(process.env.SMTP_PORT||"587",10),secure:process.env.SMTP_SECURE==="true",auth:{user:n,pass:a}}})}if(e==="resend"){let i=process.env.RESEND_API_KEY||process.env.SMTP_PASS;return i?new o({provider:"resend",from:t,fromName:r,replyTo:s,resend:{apiKey:i}}):null}if(e==="sendgrid"){let i=process.env.SENDGRID_API_KEY||process.env.SMTP_PASS;return i?new o({provider:"sendgrid",from:t,fromName:r,replyTo:s,sendgrid:{apiKey:i}}):null}if(e==="mailgun"){let i=process.env.MAILGUN_API_KEY||process.env.SMTP_PASS,n=process.env.MAILGUN_DOMAIN||process.env.SMTP_HOST;return !i||!n?null:new o({provider:"mailgun",from:t,fromName:r,replyTo:s,mailgun:{apiKey:i,domain:n,region:process.env.MAILGUN_REGION||(process.env.SMTP_SECURE==="true"?"eu":"us")}})}if(e==="ses"){let i=process.env.AWS_ACCESS_KEY_ID||process.env.SMTP_USER,n=process.env.AWS_SECRET_ACCESS_KEY||process.env.SMTP_PASS,a=process.env.AWS_REGION||process.env.SMTP_HOST||"us-east-1";return !i||!n?null:new o({provider:"ses",from:t,fromName:r,replyTo:s,ses:{accessKeyId:i,secretAccessKey:n,region:a}})}return null}};
|
|
448
|
-
|
|
448
|
+
`),O=!0);}catch{}}async loadFromGlobals(){try{let e=null;if(typeof this.db?.findOne=="function")try{let s=await this.db.findOne({collection:"_globals_storage-settings",where:{},draft:!0});s&&(e=s);}catch{}if(!e&&typeof this.db?.execute=="function"){let{sql:s}=await import('drizzle-orm'),i=['"_globals_storage-settings"','"_globals_storage_settings"','"global_storage_settings"'];for(let n of i)try{let a=await this.db.execute(s`SELECT * FROM ${s.raw(n)} LIMIT 1`);if(e=Array.isArray(a)?a[0]:a?.rows?a.rows[0]:null,e)break}catch{}}else if(!e&&typeof this.db?.prepare=="function"){let s=['"_globals_storage-settings"','"_globals_storage_settings"','"global_storage_settings"'];for(let i of s)try{if(e=this.db.prepare(`SELECT * FROM ${i} LIMIT 1`).get(),e)break}catch{}}if(!e)return;let t=s=>{if(!s)return null;if(typeof s=="string")try{return JSON.parse(s)}catch{return null}return s},r=e.provider||"local";if(this.cache["storage.type"]=r,r==="local"){let s=t(e.local);this.cache["storage.local.dir"]=s?.uploadDir||"./public/uploads",this.cache["storage.local.url"]=s?.baseUrl||"/uploads";}if(r==="aws"){let s=t(e.aws);this.cache["storage.s3.bucket"]=s?.bucket||"",this.cache["storage.s3.region"]=s?.region||"us-east-1",this.cache["storage.s3.access_key_id"]=s?.accessKeyId||"",this.cache["storage.s3.secret_access_key"]=s?.secretAccessKey||"",this.cache["storage.s3.endpoint"]=s?.endpoint||"",this.cache["storage.s3.cdn_url"]=s?.cdnUrl||"",this.cache["storage.s3.prefix"]=s?.prefix||"";}if(r==="r2"){let s=t(e.r2);this.cache["storage.r2.account_id"]=s?.accountId||"",this.cache["storage.r2.access_key_id"]=s?.accessKeyId||"",this.cache["storage.r2.secret_access_key"]=s?.secretAccessKey||"",this.cache["storage.r2.bucket"]=s?.bucket||"",this.cache["storage.r2.cdn_url"]=s?.cdnUrl||"",this.cache["storage.r2.prefix"]=s?.prefix||"";}if(r==="cloudinary"){let s=t(e.cloudinary);this.cache["storage.cloudinary.cloud_name"]=s?.cloudName||"",this.cache["storage.cloudinary.api_key"]=s?.apiKey||"",this.cache["storage.cloudinary.api_secret"]=s?.apiSecret||"",this.cache["storage.cloudinary.folder"]=s?.folder||"";}if(r==="ftp"){let s=t(e.ftp);this.cache["storage.ftp.host"]=s?.host||"",this.cache["storage.ftp.port"]=String(s?.port||"21"),this.cache["storage.ftp.user"]=s?.user||"",this.cache["storage.ftp.password"]=s?.password||"",this.cache["storage.ftp.secure"]=s?.secure?"true":"false",this.cache["storage.ftp.base_url"]=s?.baseUrl||"",this.cache["storage.ftp.prefix"]=s?.prefix||"";}}catch(e){console.warn("ConfigService: Could not load storage settings from globals table:",e);}try{let e=null;if(typeof this.db?.findOne=="function")try{let t=await this.db.findOne({collection:"_globals_email-settings",where:{},draft:!0});t&&(e=t);}catch{}if(!e&&typeof this.db?.execute=="function"){let{sql:t}=await import('drizzle-orm'),r=['"_globals_email-settings"','"_globals_email_settings"','"global_email_settings"'];for(let s of r)try{let i=await this.db.execute(t`SELECT * FROM ${t.raw(s)} LIMIT 1`);if(e=Array.isArray(i)?i[0]:i?.rows?i.rows[0]:null,e)break}catch{}}else if(!e&&typeof this.db?.prepare=="function"){let t=['"_globals_email-settings"','"_globals_email_settings"','"global_email_settings"'];for(let r of t)try{if(e=this.db.prepare(`SELECT * FROM ${r} LIMIT 1`).get(),e)break}catch{}}if(e){let t=r=>{if(!r)return null;if(typeof r=="string")try{return JSON.parse(r)}catch{return null}return r};if(this.cache["email.provider"]=e.provider||"smtp",this.cache["email.smtp.from"]=e.fromEmail||"",this.cache["email.smtp.from_name"]=e.fromName||"",this.cache["email.smtp.reply_to"]=e.replyTo||"",e.provider==="smtp"){let r=t(e.smtp);this.cache["email.smtp.host"]=r?.host||"",this.cache["email.smtp.port"]=String(r?.port||"587"),this.cache["email.smtp.user"]=r?.username||"",this.cache["email.smtp.pass"]=r?.password||"",this.cache["email.smtp.secure"]=r?.secure?"true":"false";}else if(e.provider==="resend"){let r=t(e.resend);this.cache["email.smtp.pass"]=r?.apiKey||"";}else if(e.provider==="sendgrid"){let r=t(e.sendgrid);this.cache["email.smtp.pass"]=r?.apiKey||"";}else if(e.provider==="mailgun"){let r=t(e.mailgun);this.cache["email.smtp.pass"]=r?.apiKey||"";}else if(e.provider==="ses"){let r=t(e.ses);this.cache["email.smtp.user"]=r?.accessKeyId||"",this.cache["email.smtp.pass"]=r?.secretAccessKey||"";}}}catch(e){console.warn("ConfigService: Could not load email settings from globals table:",e);}}get(e,t,r){return this.cache[e]?this.cache[e]:t&&process.env[t]?process.env[t]:r}getStorageConfig(){let e="local";return typeof globalThis.STORAGE_BUCKET<"u"&&(e="cloudflare_r2"),{type:this.get("storage.type","STORAGE_TYPE",e),s3:{bucket:this.get("storage.s3.bucket","STORAGE_BUCKET"),region:this.get("storage.s3.region","STORAGE_REGION","us-east-1"),accessKeyId:this.get("storage.s3.access_key_id","STORAGE_ACCESS_KEY_ID"),secretAccessKey:this.get("storage.s3.secret_access_key","STORAGE_SECRET_ACCESS_KEY"),endpoint:this.get("storage.s3.endpoint","STORAGE_ENDPOINT"),cdnUrl:this.get("storage.s3.cdn_url","STORAGE_CDN_URL"),prefix:this.get("storage.s3.prefix","STORAGE_PREFIX")},r2:{accountId:this.get("storage.r2.account_id","R2_ACCOUNT_ID"),accessKeyId:this.get("storage.r2.access_key_id","R2_ACCESS_KEY_ID"),secretAccessKey:this.get("storage.r2.secret_access_key","R2_SECRET_ACCESS_KEY"),bucket:this.get("storage.r2.bucket","R2_BUCKET"),cdnUrl:this.get("storage.r2.cdn_url","R2_CDN_URL"),prefix:this.get("storage.r2.prefix","R2_PREFIX")},gcs:{bucket:this.get("storage.gcs.bucket","GCS_BUCKET"),projectId:this.get("storage.gcs.project_id","GCS_PROJECT_ID"),clientEmail:this.get("storage.gcs.client_email","GCS_CLIENT_EMAIL"),privateKey:this.get("storage.gcs.private_key","GCS_PRIVATE_KEY"),cdnUrl:this.get("storage.gcs.cdn_url","GCS_CDN_URL"),prefix:this.get("storage.gcs.prefix","GCS_PREFIX")},digitalocean:{bucket:this.get("storage.digitalocean.bucket","DO_BUCKET"),region:this.get("storage.digitalocean.region","DO_REGION","nyc3"),accessKeyId:this.get("storage.digitalocean.access_key_id","DO_ACCESS_KEY_ID"),secretAccessKey:this.get("storage.digitalocean.secret_access_key","DO_SECRET_ACCESS_KEY"),cdnUrl:this.get("storage.digitalocean.cdn_url","DO_CDN_URL"),prefix:this.get("storage.digitalocean.prefix","DO_PREFIX")},backblaze:{bucket:this.get("storage.backblaze.bucket","BB_BUCKET"),accountId:this.get("storage.backblaze.account_id","BB_ACCOUNT_ID"),applicationKeyId:this.get("storage.backblaze.application_key_id","BB_APPLICATION_KEY_ID"),applicationKey:this.get("storage.backblaze.application_key","BB_APPLICATION_KEY"),cdnUrl:this.get("storage.backblaze.cdn_url","BB_CDN_URL"),prefix:this.get("storage.backblaze.prefix","BB_PREFIX")},wasabi:{bucket:this.get("storage.wasabi.bucket","WASABI_BUCKET"),region:this.get("storage.wasabi.region","WASABI_REGION","us-east-1"),accessKeyId:this.get("storage.wasabi.access_key_id","WASABI_ACCESS_KEY_ID"),secretAccessKey:this.get("storage.wasabi.secret_access_key","WASABI_SECRET_ACCESS_KEY"),cdnUrl:this.get("storage.wasabi.cdn_url","WASABI_CDN_URL"),prefix:this.get("storage.wasabi.prefix","WASABI_PREFIX")},bunny:{storageZone:this.get("storage.bunny.storage_zone","BUNNY_STORAGE_ZONE"),apiKey:this.get("storage.bunny.api_key","BUNNY_API_KEY"),cdnUrl:this.get("storage.bunny.cdn_url","BUNNY_CDN_URL"),prefix:this.get("storage.bunny.prefix","BUNNY_PREFIX")},ftp:{host:this.get("storage.ftp.host","FTP_HOST"),port:parseInt(this.get("storage.ftp.port","FTP_PORT","21"),10),user:this.get("storage.ftp.user","FTP_USER"),password:this.get("storage.ftp.password","FTP_PASSWORD"),secure:this.get("storage.ftp.secure","FTP_SECURE")==="true",baseUrl:this.get("storage.ftp.base_url","FTP_BASE_URL"),prefix:this.get("storage.ftp.prefix","FTP_PREFIX")},cloudinary:{cloudName:this.get("storage.cloudinary.cloud_name","CLOUDINARY_CLOUD_NAME"),apiKey:this.get("storage.cloudinary.api_key","CLOUDINARY_API_KEY"),apiSecret:this.get("storage.cloudinary.api_secret","CLOUDINARY_API_SECRET"),folder:this.get("storage.cloudinary.folder","CLOUDINARY_FOLDER")},imgix:{domain:this.get("storage.imgix.domain","IMGIX_DOMAIN"),signKey:this.get("storage.imgix.sign_key","IMGIX_SIGN_KEY")},local:{uploadDir:this.get("storage.local.dir","STORAGE_LOCAL_DIR","./public/uploads"),baseUrl:this.get("storage.local.url","STORAGE_LOCAL_URL","/uploads")}}}getEmailConfig(){return {provider:this.get("email.provider","EMAIL_PROVIDER","smtp"),host:this.get("email.smtp.host","SMTP_HOST"),port:parseInt(this.get("email.smtp.port","SMTP_PORT","587"),10),secure:this.get("email.smtp.secure","SMTP_SECURE")==="true",user:this.get("email.smtp.user","SMTP_USER"),pass:this.get("email.smtp.pass","SMTP_PASS"),from:this.get("email.smtp.from","SMTP_FROM","noreply@example.com"),fromName:this.get("email.smtp.from_name","SMTP_FROM_NAME","Kyro CMS"),replyTo:this.get("email.smtp.reply_to","SMTP_REPLY_TO")}}maskSensitive(e,t){return t&&(o.SENSITIVE_KEYS.includes(e)?"********":t)}async set(e,t,r){await this.db.insert(a).values({key:e,value:t,description:r,updatedAt:new Date}).onConflictDoUpdate({target:[a.key],set:{value:t,description:r,updatedAt:new Date}}),this.cache[e]=t;}};var U=class o{transporter;config;templates;transporterInitialized=false;constructor(e,t){this.config=e,this.templates={...$(e.brand),...t};}async ensureTransporter(){if(this.transporterInitialized)return this.transporter;let{default:e}=await import('nodemailer');return this.config.provider==="smtp"&&this.config.smtp?this.transporter=e.createTransport({host:this.config.smtp.host,port:this.config.smtp.port,secure:this.config.smtp.secure,auth:this.config.smtp.auth}):this.config.provider==="ses"&&this.config.ses&&(this.transporter=e.createTransport({host:`email-smtp.${this.config.ses.region}.amazonaws.com`,port:587,secure:false,auth:{user:this.config.ses.accessKeyId,pass:this.config.ses.secretAccessKey}})),this.transporterInitialized=true,this.transporter}async send(e){let{provider:t,from:r,fromName:s,replyTo:i}=this.config,n=`"${s||"Kyro CMS"}" <${r}>`,a=e.replyTo||i;try{let l;switch(t){case "smtp":case "ses":{let g=await this.ensureTransporter();if(!g)throw new Error(`${t} transporter not initialized`);l=await g.sendMail({from:n,to:Array.isArray(e.to)?e.to.join(", "):e.to,subject:e.subject,html:e.html,text:e.text,replyTo:a});}break;case "resend":l=await this.sendViaResend(n,e,a);break;case "sendgrid":l=await this.sendViaSendGrid(n,e,a);break;case "mailgun":l=await this.sendViaMailgun(n,e,a);break;default:throw new Error(`Unsupported email provider: ${t}`)}return l}catch(l){throw console.error("[EmailTransport] FAILED to send email:",l.message),l.response&&console.error("[EmailTransport] Provider Error Detail:",JSON.stringify(l.response,null,2)),l}}async sendViaResend(e,t,r){let s=this.config.resend?.apiKey;if(!s)throw new Error("Resend API Key missing");let i={from:e,to:t.to,subject:t.subject,html:t.html,text:t.text,reply_to:r},n=await fetch("https://api.resend.com/emails",{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.ok){let a=await n.json();throw new Error(`Resend Error: ${JSON.stringify(a)}`)}return n.json()}async sendViaSendGrid(e,t,r){let s=this.config.sendgrid?.apiKey;if(!s)throw new Error("SendGrid API Key missing");let i={personalizations:[{to:Array.isArray(t.to)?t.to.map(a=>({email:a})):[{email:t.to}]}],from:{email:e.match(/<(.+)>/)?.[1]||e,name:e.match(/"(.+)"/)?.[1]},subject:t.subject,content:[{type:"text/plain",value:t.text||""},{type:"text/html",value:t.html}],reply_to:r?{email:r}:void 0},n=await fetch("https://api.sendgrid.com/v3/mail/send",{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.ok){let a=await n.json();throw new Error(`SendGrid Error: ${JSON.stringify(a)}`)}return {success:true}}async sendViaMailgun(e,t,r){let{apiKey:s,domain:i,region:n}=this.config.mailgun||{};if(!s||!i)throw new Error("Mailgun config missing");let a=n==="eu"?"api.eu.mailgun.net":"api.mailgun.net",l=btoa(`api:${s}`),g=new URLSearchParams;g.append("from",e);let f=Array.isArray(t.to)?t.to.join(", "):t.to;g.append("to",f),g.append("subject",t.subject),g.append("html",t.html),t.text&&g.append("text",t.text),r&&g.append("h:Reply-To",r);let m=await fetch(`https://${a}/v3/${i}/messages`,{method:"POST",headers:{Authorization:`Basic ${l}`,"Content-Type":"application/x-www-form-urlencoded"},body:g});if(!m.ok){let u=await m.json();throw new Error(`Mailgun Error: ${JSON.stringify(u)}`)}return m.json()}getTemplates(){return this.templates}async verifyConnection(){if(this.config.provider==="smtp"||this.config.provider==="ses")try{let e=await this.ensureTransporter();if(e)return await e.verify(),!0}catch{return false}return !!(this.config.resend?.apiKey||this.config.sendgrid?.apiKey||this.config.mailgun?.apiKey)}static async fetchBrandConfig(e){let t="Kyro CMS",r="https://kyro-cms.com/logo.svg",s="https://kyro-cms.com/logo-white.svg";try{let i=null,n=null;if(typeof e?.findOne=="function")i=await e.findOne({collection:"_globals_store-settings",where:{},draft:!0}),n=await e.findOne({collection:"_globals_brand-settings",where:{},draft:!0});else if(typeof e?.execute=="function"){let{sql:a}=await import('drizzle-orm');try{let l=await e.execute(a`SELECT * FROM "_globals_store-settings" LIMIT 1`);i=Array.isArray(l)?l[0]:l?.rows?l.rows[0]:null;}catch{}try{let l=await e.execute(a`SELECT * FROM "_globals_brand-settings" LIMIT 1`);n=Array.isArray(l)?l[0]:l?.rows?l.rows[0]:null;}catch{}}else if(typeof e?.prepare=="function"){try{i=e.prepare('SELECT * FROM "_globals_store-settings" LIMIT 1').get();}catch{}try{n=e.prepare('SELECT * FROM "_globals_brand-settings" LIMIT 1').get();}catch{}}if(i?.storeName&&(t=i.storeName),n?.identity){let a=typeof n.identity=="string"?JSON.parse(n.identity):n.identity,l=async g=>{if(typeof e?.findOne=="function")return (await e.findOne({collection:"media",where:{id:{equals:g}}}))?.url;if(typeof e?.execute=="function"){let{sql:f}=await import('drizzle-orm');try{let m=await e.execute(f`SELECT url FROM "media" WHERE id = ${g}`);return (Array.isArray(m)?m[0]:m?.rows?m.rows[0]:null)?.url}catch{}}else if(typeof e?.prepare=="function")try{return e.prepare('SELECT url FROM "media" WHERE id = ?').get(g)?.url}catch{}};if(a.primaryLogo){let g=await l(a.primaryLogo);g&&(r=g);}if(a.darkLogo){let g=await l(a.darkLogo);g&&(s=g);}}}catch{}return {siteName:t,logoUrl:r,logoDarkUrl:s,appUrl:process.env.PUBLIC_URL||"https://kyro-cms.com"}}static async fromConfig(e){let t=new y(e);await t.load();let r=t.getEmailConfig();if(!r.provider)return this.fromEnv();let i={brand:await this.fetchBrandConfig(e),provider:r.provider||"smtp",from:r.from||"noreply@example.com",fromName:r.fromName,replyTo:r.replyTo,smtp:r.provider==="smtp"?{host:r.host||"",port:r.port||587,secure:r.secure||false,auth:{user:r.user||"",pass:r.pass||""}}:void 0,resend:r.provider==="resend"?{apiKey:r.pass||""}:void 0,sendgrid:r.provider==="sendgrid"?{apiKey:r.pass||""}:void 0,mailgun:r.provider==="mailgun"?{apiKey:r.pass||"",domain:r.host||"",region:r.secure?"eu":"us"}:void 0,ses:r.provider==="ses"?{accessKeyId:r.user||"",secretAccessKey:r.pass||"",region:r.host||"us-east-1"}:void 0};return new o(i)}static fromEnv(){let e=process.env.EMAIL_PROVIDER||"smtp",t=process.env.SMTP_FROM||process.env.DEFAULT_FROM||"noreply@example.com",r=process.env.SMTP_FROM_NAME||"Kyro CMS",s=process.env.SMTP_REPLY_TO;if(e==="smtp"){let i=process.env.SMTP_HOST,n=process.env.SMTP_USER,a=process.env.SMTP_PASS;return !i||!n||!a?null:new o({provider:"smtp",from:t,fromName:r,replyTo:s,smtp:{host:i,port:parseInt(process.env.SMTP_PORT||"587",10),secure:process.env.SMTP_SECURE==="true",auth:{user:n,pass:a}}})}if(e==="resend"){let i=process.env.RESEND_API_KEY||process.env.SMTP_PASS;return i?new o({provider:"resend",from:t,fromName:r,replyTo:s,resend:{apiKey:i}}):null}if(e==="sendgrid"){let i=process.env.SENDGRID_API_KEY||process.env.SMTP_PASS;return i?new o({provider:"sendgrid",from:t,fromName:r,replyTo:s,sendgrid:{apiKey:i}}):null}if(e==="mailgun"){let i=process.env.MAILGUN_API_KEY||process.env.SMTP_PASS,n=process.env.MAILGUN_DOMAIN||process.env.SMTP_HOST;return !i||!n?null:new o({provider:"mailgun",from:t,fromName:r,replyTo:s,mailgun:{apiKey:i,domain:n,region:process.env.MAILGUN_REGION||(process.env.SMTP_SECURE==="true"?"eu":"us")}})}if(e==="ses"){let i=process.env.AWS_ACCESS_KEY_ID||process.env.SMTP_USER,n=process.env.AWS_SECRET_ACCESS_KEY||process.env.SMTP_PASS,a=process.env.AWS_REGION||process.env.SMTP_HOST||"us-east-1";return !i||!n?null:new o({provider:"ses",from:t,fromName:r,replyTo:s,ses:{accessKeyId:i,secretAccessKey:n,region:a}})}return null}};
|
|
449
|
+
export{c as a,b,x as c,_ as d,w as e,S as f,C as g,T as h,k as i,E as j,v as k,A as l,R as m,I as n,$ as o,y as p,U as q};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import {e,h}from'./chunk-3N34WXBS.js';import {a}from'./chunk-O4RKZQYQ.js';import {GraphQLScalarType,Kind,GraphQLObjectType,GraphQLString,GraphQLInputObjectType,GraphQLBoolean,GraphQLInt,GraphQLList,GraphQLNonNull,GraphQLSchema,GraphQLUnionType,GraphQLFloat}from'graphql';export{printSchema as e}from'graphql';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
|
|
2
|
+
var N=class{db;tenantId;user;caches=new Map;pending=new Map;waiting=new Map;flushScheduled=false;constructor(t){this.db=t.db,this.tenantId=t.tenantId,this.user=t.user;}getCacheKey(t){return t}async load(t,e){let d=this.getCacheKey(t),y=this.caches.get(d);if(y||(y=new Map,this.caches.set(d,y)),y.has(e)&&!this.pending.get(d)?.has(e))return y.get(e);let s=this.pending.get(d);return s||(s=new Set,this.pending.set(d,s)),s.add(e),this.flushScheduled||(this.flushScheduled=true,queueMicrotask(()=>{this.flushScheduled=false,this.flushAll();})),new Promise(i=>{let o=this.waiting.get(`${d}:${e}`);o||(o=[],this.waiting.set(`${d}:${e}`,o)),o.push(i);})}async flushAll(){for(let[t,e]of this.pending){if(e.size===0)continue;let d=t,y=Array.from(e);this.pending.delete(t);try{let s=await this.db.find({collection:d,where:{id:{in:y}},limit:y.length,tenantId:this.tenantId}),i=this.caches.get(t)||new Map,o=new Map;for(let l of s.docs)o.set(l.id,l),i.set(l.id,l);for(let l of y){let w=this.waiting.get(`${t}:${l}`);if(w){let I=o.get(l);for(let m of w)m(I);this.waiting.delete(`${t}:${l}`);}}}catch(s){console.error(`[RelationLoader] Failed to batch load ${d}:`,s);for(let i of y){let o=this.waiting.get(`${t}:${i}`);if(o){for(let l of o)l(void 0);this.waiting.delete(`${t}:${i}`);}}}}}async loadMany(t,e){return Promise.all(e.map(d=>this.load(t,d)))}resolveOne(t,e){return this.caches.get(this.getCacheKey(t))?.get(e)}};var q=new GraphQLScalarType({name:"JSON",description:"Arbitrary JSON value",serialize(n){return n},parseValue(n){return n},parseLiteral(n){switch(n.kind){case Kind.STRING:return n.value;case Kind.INT:case Kind.FLOAT:return parseFloat(n.value);case Kind.BOOLEAN:return n.value;case Kind.OBJECT:{let t={};for(let e of n.fields)t[e.name.value]=q.parseLiteral(e.value);return t}case Kind.LIST:return n.values.map(t=>q.parseLiteral(t));case Kind.NULL:return null;default:return null}}});function oe(n){return t=>{let e=0;return {Field(){e++,e>n&&t.reportError(new Error(`Query exceeds max depth of ${n}`));},leaveField(){e--;}}}}function L(n){return n.split(/[-_]/).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function Z(n){let t=L(n);return t.charAt(0).toLowerCase()+t.slice(1)}function O(n){return n.endsWith("s")&&n.length>1?n.slice(0,-1):n}async function P(n,t,e$1){let d=n.access?.[t];if(e$1.apiKey){if(e$1.apiKey.permissions?.length>0){let s=n.slug,o=`${s}:${t==="read"?"read":t==="create"?"create":"update"}`;return !e(e$1.apiKey.permissions,o)&&!e(e$1.apiKey.permissions,`${s}:admin`)?{allowed:false}:{allowed:true}}if(d){let s=await h(d,{req:e$1.req,user:e$1.user,tenantId:e$1.tenantId});return typeof s=="boolean"?{allowed:s}:{allowed:true,extraWhere:s}}return {allowed:true}}if(e$1.user){let s=n.slug,o=`${s}:${t==="read"?"read":t==="create"?"create":t==="update"?"update":"delete"}`;if(!a({id:e$1.user.id,email:e$1.user.email,role:e$1.user.role},o)&&!a({id:e$1.user.id,email:e$1.user.email,role:e$1.user.role},`${s}:admin`)&&!d)return {allowed:false}}if(!d)return e$1.user?{allowed:true}:{allowed:false};let y=await h(d,{req:e$1.req,user:e$1.user,tenantId:e$1.tenantId});return typeof y=="boolean"?{allowed:y}:{allowed:true,extraWhere:y}}async function ee(n,t,e$1){let d=n.access?.[t];if(e$1.apiKey){if(e$1.apiKey.permissions?.length>0){let s=n.slug,i=`${s}:${t}`;return !e(e$1.apiKey.permissions,i)&&!e(e$1.apiKey.permissions,`${s}:admin`)&&!e(e$1.apiKey.permissions,`${s}:*`)?{allowed:false}:{allowed:true}}if(d){let s=await h(d,{req:e$1.req,user:e$1.user,tenantId:e$1.tenantId});return {allowed:typeof s=="boolean"?s:true}}return {allowed:true}}if(!d){if(!e$1.user)return {allowed:false};let s=e$1.user.role;return s==="super_admin"||s==="admin"?{allowed:true}:{allowed:false}}let y=await h(d,{req:e$1.req,user:e$1.user,tenantId:e$1.tenantId});return typeof y=="boolean"?{allowed:y}:{allowed:true}}function ne(n,t){return n?n.startsWith("http://")||n.startsWith("https://")||n.startsWith("blob:")||n.startsWith("data:")?n:`${(process.env.KYRO_BASE_URL||t||"http://localhost:4321").replace(/\/+$/,"")}${n.startsWith("/")?"":"/"}${n}`:null}function K(n,t){return n&&(n.url&&(n.url=ne(n.url,t)),n.thumbnailUrl&&(n.thumbnailUrl=ne(n.thumbnailUrl,t)),n)}function U(n,t,e,d=false,y="Root",s=new Map){switch(n.type){case "text":case "email":case "password":case "textarea":case "color":case "code":case "markdown":case "date":case "select":case "radio":return n.hasMany?new GraphQLList(GraphQLString):GraphQLString;case "list":return new GraphQLList(GraphQLString);case "upload":{let i=n;if(d)return i.hasMany?new GraphQLList(GraphQLString):GraphQLString;if(i.relationTo&&e?.[i.relationTo]){let o=e[i.relationTo];return i.hasMany?new GraphQLList(o):o}return q}case "image":{if(d)return GraphQLString;let i=n;return i.relationTo&&e?.[i.relationTo]?e[i.relationTo]:q}case "number":{let i=n.integer?GraphQLInt:GraphQLFloat;return n.hasMany?new GraphQLList(i):i}case "checkbox":return GraphQLBoolean;case "json":case "richtext":return q;case "blocks":{if(d)return q;let i=n,o=(i.blocks||[]).map(I=>{let m=`Block_${L(I.slug)}`,u=s.get(m);return u||(u=new GraphQLObjectType({name:m,fields:()=>{let f=k(I.fields||[],t,e,m,s);return f.blockType={type:GraphQLString},f.name={type:GraphQLString},f}}),s.set(m,u)),u});if(o.length===0)return q;let l=`${y}_${L(i.name)}_Blocks`,w=s.get(l);return w||(w=new GraphQLUnionType({name:l,types:o,resolveType:I=>`Block_${L(I.blockType||I.type)}`}),s.set(l,w)),new GraphQLList(w)}case "tabs":{if(d)return q;let i=n,o=`${y}_${L(i.name)}_Tabs`,l=s.get(o);return l||(l=new GraphQLObjectType({name:o,fields:()=>k(i.tabs?.flatMap(w=>w.fields||[])||[],t,e,o,s)}),s.set(o,l)),l}case "relationship":{let i=n.relationTo;if((i==="*"||Array.isArray(i)&&i.includes("*"))&&(i=t.getCollections().map(o=>o.slug)),typeof i=="string"){if(d)return n.hasMany?new GraphQLList(GraphQLString):GraphQLString;if(e?.[i])return n.hasMany?new GraphQLList(e[i]):e[i];let o=t.getCollection(i);if(o)return new GraphQLObjectType({name:`${L(i)}Ref`,fields:()=>({id:{type:GraphQLString},...J(o,t,e,s)})})}else if(Array.isArray(i)){if(d)return n.hasMany?new GraphQLList(q):q;let o=i.map(u=>{if(e?.[u])return e[u];let f=t.getCollection(u);if(f){let c=s.get(`${L(u)}Ref`);return c||(c=new GraphQLObjectType({name:`${L(u)}Ref`,fields:()=>({id:{type:GraphQLString},...J(f,t,e,s)})}),s.set(`${L(u)}Ref`,c)),c}return null}).filter(Boolean);if(o.length===0)return q;let l=`${y}_${L(n.name||"Ref")}_PolyUnion`,w=s.get(l);w||(w=new GraphQLUnionType({name:l,types:o,resolveType:u=>{if(u.__collection&&u.__collection!=="*")return e?.[u.__collection]?e[u.__collection].name:`${L(u.__collection)}Ref`}}),s.set(l,w));let I=`${y}_${L(n.name||"Ref")}_PolyWrapper`,m=s.get(I);return m||(m=new GraphQLObjectType({name:I,fields:{relationTo:{type:GraphQLString},value:{type:w}}}),s.set(I,m)),n.hasMany?new GraphQLList(m):m}return q}case "array":{if(d)return new GraphQLList(q);let i=n,o=`${y}_${L(i.name)}_ArrayItem`,l=s.get(o);return l||(l=new GraphQLObjectType({name:o,fields:()=>{let w=k(i.fields||[],t,e,o,s);return w.id={type:GraphQLString},w}}),s.set(o,l)),new GraphQLList(l)}case "group":{if(d)return q;let i=n,o=`${y}_${L(i.name)}_Group`,l=s.get(o);return l||(l=new GraphQLObjectType({name:o,fields:()=>k(i.fields||[],t,e,o,s)}),s.set(o,l)),l}default:return GraphQLString}}function k(n,t,e,d,y=new Map){let s={};for(let i of n){if(i.type==="tabs"&&!i.name){for(let o of i.tabs||[]){let l=k(o.fields||[],t,e,d,y);Object.assign(s,l);}continue}if(i.type==="row"||i.type==="collapsible"){let o=k(i.fields||[],t,e,d,y);Object.assign(s,o);continue}if(i.name&&i.admin?.hidden!==true){let o=le(i,t,e,d,y);o&&(s[i.name]=o);}}return s}function J(n,t,e,d=new Map){return k(n.fields,t,e,L(O(n.slug)),d)}function le(n,t,e,d,y=new Map){if(!n.name)return null;let s=n.deprecated||void 0;if(n.type==="upload"){let o=U(n,t,e,false,d,y),l=n;return {type:o,description:n.admin?.description||n.label,deprecationReason:s,resolve:async(w,I,m)=>{let u=m?.relationLoader,f=w?.[l.name],c=m?.req?.url?new URL(m.req.url).origin:void 0;if(!f)return null;if(l.hasMany){let T=Array.isArray(f)?f:[];return Promise.all(T.map(async g=>{let G=typeof g=="string"?g:g?.id;if(!G||typeof g=="object"&&g?.url)return K(g,c);if(u){let S=u.resolveOne(l.relationTo,G);if(S)return K(S,c);let r=await u.load(l.relationTo,G);return r?K(r,c):null}return {id:G}}))}let b=typeof f=="string"?f:f?.id;if(!b||typeof f=="object"&&f?.url)return K(f,c);if(u){let T=u.resolveOne(l.relationTo,b);if(T)return K(T,c);let g=await u.load(l.relationTo,b);return g?K(g,c):null}return {id:b}}}}return n.type==="relationship"&&!n.hasMany?{type:U(n,t,e,false,d,y),description:n.admin?.description||n.label,deprecationReason:s,resolve:async(l,w,I)=>{let m=I?.relationLoader,u=n,f=l?.[u.name];if(!f)return null;let c=Array.isArray(u.relationTo)||u.relationTo==="*",b=c?f?.relationTo:u.relationTo,T=c?f?.value:f;if(c&&typeof f=="string"&&(b=u.relationTo[0],T=f),c&&b==="*")return null;if(m&&typeof T=="string"&&typeof b=="string"&&b!=="*"){let G=m.resolveOne(b,T);if(G)return c?{relationTo:b,value:{...G,__collection:b}}:G;let S=await m.load(b,T);return S?c?{relationTo:b,value:{...S,__collection:b}}:S:null}let g=typeof T=="object"&&T!==null?T:{id:T};return c?{relationTo:b,value:{...g,__collection:b}}:g}}:n.type==="relationship"&&n.hasMany?{type:U(n,t,e,false,d,y),description:n.admin?.description||n.label,deprecationReason:s,resolve:async(l,w,I)=>{let m=I?.relationLoader,u=n,f=l?.[u.name]||[];if(typeof f=="string")try{f=JSON.parse(f);}catch{}if(Array.isArray(f)||(f=[]),!f.length)return [];let c=Array.isArray(u.relationTo)||u.relationTo==="*";if(m){let b=[];for(let T of f){let g=c?T?.relationTo:u.relationTo,G=c?T?.value:T;if(c&&typeof T=="string"&&(g=u.relationTo[0],G=T),c&&g==="*")continue;if(typeof G=="string"&&typeof g=="string"&&g!=="*"){let r=m.resolveOne(g,G);if(r){b.push(c?{relationTo:g,value:{...r,__collection:g}}:r);continue}let $=await m.load(g,G);if($){b.push(c?{relationTo:g,value:{...$,__collection:g}}:$);continue}continue}let S=typeof G=="object"&&G!==null?G:{id:G};b.push(c?{relationTo:g,value:{...S,__collection:g}}:S);}return b}return f.map(b=>{let T=c?b?.relationTo:u.relationTo,g=c?b?.value:b;c&&typeof b=="string"&&(T=u.relationTo[0],g=b);let G=typeof g=="object"&&g!==null?g:{id:g};return c?{relationTo:T,value:{...G,__collection:T}}:G})}}:n.type==="blocks"?{type:U(n,t,e,false,d,y),description:n.admin?.description||n.label,deprecationReason:s,resolve:l=>{let w=l?.[n.name];if(typeof w=="string")try{w=JSON.parse(w);}catch{}return Array.isArray(w)?w.map(I=>I&&I.data&&I.type?{...I.data,id:I.id,type:I.type,blockType:I.type,name:I.name}:I):w}}:{type:U(n,t,e,false,d,y),description:n.admin?.description||n.label,deprecationReason:s,resolve:o=>{let l=o?.[n.name];if(typeof l=="string"&&["array","group","tabs","blocks","json","richtext","list"].includes(n.type))try{l=JSON.parse(l);}catch{}return l}}}function te(n){let{registry:t,db:e,user:d,req:y,tenantId:s,apiKey:i,settings:o}=n;if(o?.access?.apiAccess?.graphqlEnabled===false)throw new Error("GraphQL API is disabled");let w=t.getCollections(),I=t.getGlobals(),m={},u={},f=new Map;for(let r of w){m[r.slug]=new GraphQLObjectType({name:L(O(r.slug)),fields:()=>({id:{type:GraphQLString},...J(r,t,m,f),...r.timestamps?{createdAt:{type:GraphQLString},updatedAt:{type:GraphQLString}}:{},...r.tenantScoped?{tenantId:{type:GraphQLString}}:{}})});let $={};for(let A of r.fields)A.name&&A.name!=="id"&&($[A.name]={type:U(A,t,m,true)});u[r.slug]=new GraphQLInputObjectType({name:`${L(O(r.slug))}Input`,fields:()=>$});}let c={},b={};for(let r of I)c[r.slug]=new GraphQLObjectType({name:`${L(r.slug)}Global`,fields:()=>({id:{type:GraphQLString},...J({slug:r.slug,fields:r.fields},t,m)})}),b[r.slug]=new GraphQLInputObjectType({name:`${L(r.slug)}GlobalInput`,fields:()=>{let $={};for(let A of r.fields)A.name&&A.name!=="id"&&($[A.name]={type:U(A,t,m,true)});return $}});let T={};for(let r of w){let $=m[r.slug];$&&(T[Z(r.slug)]={type:new GraphQLObjectType({name:`${L(O(r.slug))}FindResult`,fields:{docs:{type:new GraphQLList($)},totalDocs:{type:GraphQLInt},page:{type:GraphQLInt},totalPages:{type:GraphQLInt},hasNextPage:{type:GraphQLBoolean},hasPrevPage:{type:GraphQLBoolean}}}),args:{where:{type:GraphQLString},sort:{type:GraphQLString},limit:{type:GraphQLInt},page:{type:GraphQLInt},draft:{type:GraphQLBoolean}},resolve:async(A,_,a)=>{let p=await P(r,"read",{user:a.user,req:a.req,tenantId:a.tenantId,apiKey:a.apiKey});if(!p.allowed)throw new Error("Access denied");a.tenantId&&e.setTenantContext({tenantId:a.tenantId,userId:a.user?.id??"",role:a.user?.role,isSuperAdmin:a.user?.role==="super_admin"});let R={};if(_.where)try{R=JSON.parse(_.where);}catch{}p.extraWhere&&(R={...R,...p.extraWhere});let F=_.draft??!!a.user;return e.find({collection:r.slug,where:R,sort:_.sort,limit:_.limit||10,page:_.page||1,tenantId:a.tenantId,draft:F})}},T[Z(O(r.slug))]={type:$,args:{id:{type:GraphQLString},slug:{type:GraphQLString},draft:{type:GraphQLBoolean}},resolve:async(A,_,a)=>{if(!_.id&&!_.slug)throw new Error("Either id or slug is required");if(!(await P(r,"read",{user:a.user,req:a.req,tenantId:a.tenantId,apiKey:a.apiKey})).allowed)throw new Error("Access denied");a.tenantId&&e.setTenantContext({tenantId:a.tenantId,userId:a.user?.id??"",role:a.user?.role,isSuperAdmin:a.user?.role==="super_admin"});let R=_.draft??!!a.user;return _.id?e.findByID({collection:r.slug,id:_.id,tenantId:a.tenantId,draft:R}):(await e.find({collection:r.slug,where:{slug:{equals:_.slug}},limit:1,page:1,tenantId:a.tenantId,draft:R})).docs?.[0]||null}},T[`count${L(r.slug)}`]={type:new GraphQLObjectType({name:`${L(O(r.slug))}Count`,fields:{totalDocs:{type:GraphQLInt}}}),args:{where:{type:GraphQLString}},resolve:async(A,_,a)=>{if(!(await P(r,"read",{user:a.user,req:a.req,tenantId:a.tenantId,apiKey:a.apiKey})).allowed)return {totalDocs:0};let R={};if(_.where)try{R=JSON.parse(_.where);}catch{}return {totalDocs:await e.count({collection:r.slug,where:R,tenantId:a.tenantId})}}});}for(let r of I){let $=c[r.slug];$&&(T[Z(O(r.slug))]={type:$,resolve:async(A,_,a)=>{if(!(await ee(r,"read",{user:a.user,req:a.req,tenantId:a.tenantId,apiKey:a.apiKey})).allowed)throw new Error("Access denied: cannot read global");return a.tenantId&&e.setTenantContext({tenantId:a.tenantId,userId:a.user?.id??"",role:a.user?.role,isSuperAdmin:a.user?.role==="super_admin"}),e.findOne({collection:`_globals_${r.slug}`,where:{},tenantId:a.tenantId})}});}let g=new GraphQLObjectType({name:"Query",fields:T}),G={};for(let r of w){let $=m[r.slug],A=u[r.slug];!$||!A||(G[`create${L(O(r.slug))}`]={type:new GraphQLObjectType({name:`${L(O(r.slug))}CreateResult`,fields:{doc:{type:$},message:{type:GraphQLString}}}),args:{data:{type:new GraphQLNonNull(A)}},resolve:async(_,a,p)=>{if(!(await P(r,"create",{user:p.user,req:p.req,tenantId:p.tenantId,apiKey:p.apiKey})).allowed)throw new Error("Access denied: cannot create");p.tenantId&&e.setTenantContext({tenantId:p.tenantId,userId:p.user?.id??"",role:p.user?.role,isSuperAdmin:p.user?.role==="super_admin"});let z=t.getCreateZodSchema(r.slug).parse(a.data);return {doc:await e.create({collection:r.slug,data:z,tenantId:p.tenantId}),message:"Created successfully"}}},G[`update${L(O(r.slug))}`]={type:new GraphQLObjectType({name:`${L(O(r.slug))}UpdateResult`,fields:{doc:{type:$},message:{type:GraphQLString}}}),args:{id:{type:new GraphQLNonNull(GraphQLString)},data:{type:new GraphQLNonNull(A)},baseUpdatedAt:{type:GraphQLString}},resolve:async(_,a,p)=>{if(!(await P(r,"update",{user:p.user,req:p.req,tenantId:p.tenantId,apiKey:p.apiKey})).allowed)throw new Error("Access denied: cannot update");if(p.tenantId&&e.setTenantContext({tenantId:p.tenantId,userId:p.user?.id??"",role:p.user?.role,isSuperAdmin:p.user?.role==="super_admin"}),a.baseUpdatedAt){let D=await e.findByID({collection:r.slug,id:a.id,tenantId:p.tenantId,draft:true});if(D&&D.updatedAt&&a.baseUpdatedAt!==D.updatedAt)throw new Error(`Revision conflict: document has changed since ${a.baseUpdatedAt}. Current updatedAt: ${D.updatedAt}`)}let z=t.getUpdateZodSchema(r.slug).parse(a.data);return {doc:await e.update({collection:r.slug,id:a.id,data:z,tenantId:p.tenantId}),message:"Updated successfully"}}},G[`delete${L(O(r.slug))}`]={type:new GraphQLObjectType({name:`${L(O(r.slug))}DeleteResult`,fields:{doc:{type:$},message:{type:GraphQLString}}}),args:{id:{type:new GraphQLNonNull(GraphQLString)}},resolve:async(_,a,p)=>{if(!(await P(r,"delete",{user:p.user,req:p.req,tenantId:p.tenantId,apiKey:p.apiKey})).allowed)throw new Error("Access denied: cannot delete");return p.tenantId&&e.setTenantContext({tenantId:p.tenantId,userId:p.user?.id??"",role:p.user?.role,isSuperAdmin:p.user?.role==="super_admin"}),{doc:await e.delete({collection:r.slug,id:a.id,tenantId:p.tenantId}),message:"Deleted successfully"}}});}for(let r of I){let $=b[r.slug];$&&(G[`update${L(r.slug)}`]={type:new GraphQLObjectType({name:`${L(r.slug)}UpdateResult`,fields:{doc:{type:c[r.slug]||GraphQLString},message:{type:GraphQLString}}}),args:{data:{type:new GraphQLNonNull($)}},resolve:async(A,_,a)=>{if(!(await ee(r,"update",{user:a.user,req:a.req,tenantId:a.tenantId,apiKey:a.apiKey})).allowed)throw new Error("Access denied: cannot update global");a.tenantId&&e.setTenantContext({tenantId:a.tenantId,userId:a.user?.id??"",role:a.user?.role,isSuperAdmin:a.user?.role==="super_admin"});let R=await e.findOne({collection:`_globals_${r.slug}`,where:{},tenantId:a.tenantId}),F;return R?F=await e.update({collection:`_globals_${r.slug}`,id:R.id,data:_.data,tenantId:a.tenantId}):F=await e.create({collection:`_globals_${r.slug}`,data:_.data,tenantId:a.tenantId}),{doc:F,message:"Updated successfully"}}});}let S=new GraphQLObjectType({name:"Mutation",fields:G});return new GraphQLSchema({query:g,mutation:S})}function de(n,t,e){return te({registry:n,db:t,user:e?.user,req:e?.req,tenantId:e?.tenantId,apiKey:e?.apiKey})}
|
|
3
|
+
export{N as a,oe as b,te as c,de as d};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {pgTable,timestamp,jsonb,integer,boolean,varchar,uuid,uniqueIndex,index,text}from'drizzle-orm/pg-core';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
|
|
2
|
+
var d=pgTable("users",{id:uuid("id").primaryKey().defaultRandom(),name:varchar("name",{length:255}),email:varchar("email",{length:255}).notNull(),passwordHash:varchar("password_hash",{length:255}),role:varchar("role",{length:50}).notNull().default("customer"),tenantId:uuid("tenant_id"),emailVerified:boolean("email_verified").default(false),avatar:varchar("avatar",{length:255}),locked:boolean("locked").default(false),lastLogin:timestamp("last_login"),failedLoginAttempts:integer("failed_login_attempts").default(0),metadata:jsonb("metadata").$type(),createdAt:timestamp("created_at").defaultNow().notNull(),updatedAt:timestamp("updated_at").defaultNow().notNull()},e=>[uniqueIndex("users_email_idx").on(e.email),index("users_tenant_idx").on(e.tenantId),index("users_role_idx").on(e.role)]),c=pgTable("roles",{id:uuid("id").primaryKey().defaultRandom(),name:varchar("name",{length:100}).notNull().unique(),level:integer("level").notNull().default(0),inherits:text("inherits").array(),description:text("description"),permissions:jsonb("permissions").$type().default([]),isSystem:boolean("is_system").default(false),createdAt:timestamp("created_at").defaultNow().notNull(),updatedAt:timestamp("updated_at").defaultNow().notNull()},e=>[index("roles_level_idx").on(e.level)]),m=pgTable("permissions",{id:uuid("id").primaryKey().defaultRandom(),roleId:uuid("role_id").references(()=>c.id,{onDelete:"cascade"}),resource:varchar("resource",{length:100}).notNull(),action:varchar("action",{length:50}).notNull(),conditions:jsonb("conditions").$type(),createdAt:timestamp("created_at").defaultNow().notNull()},e=>[index("permissions_role_idx").on(e.roleId),index("permissions_resource_idx").on(e.resource)]),x=pgTable("sessions",{id:uuid("id").primaryKey().defaultRandom(),userId:uuid("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),token:varchar("token",{length:512}).notNull().unique(),refreshToken:varchar("refresh_token",{length:512}),ipAddress:varchar("ip_address",{length:45}),userAgent:text("user_agent"),expiresAt:timestamp("expires_at").notNull(),createdAt:timestamp("created_at").defaultNow().notNull()},e=>[index("sessions_user_idx").on(e.userId),index("sessions_token_idx").on(e.token),index("sessions_expires_idx").on(e.expiresAt)]),g=pgTable("audit_logs",{id:uuid("id").primaryKey().defaultRandom(),action:varchar("action",{length:100}).notNull(),userId:uuid("user_id").references(()=>d.id,{onDelete:"set null"}),userEmail:varchar("user_email",{length:255}),role:varchar("role",{length:50}),resource:varchar("resource",{length:100}).notNull(),resourceId:varchar("resource_id",{length:255}),changes:jsonb("changes").$type(),ipAddress:varchar("ip_address",{length:45}),userAgent:text("user_agent"),success:boolean("success").notNull().default(true),error:text("error"),metadata:jsonb("metadata").$type(),timestamp:timestamp("timestamp").defaultNow().notNull()},e=>[index("audit_logs_user_idx").on(e.userId),index("audit_logs_action_idx").on(e.action),index("audit_logs_resource_idx").on(e.resource),index("audit_logs_timestamp_idx").on(e.timestamp)]),N=pgTable("tenants",{id:uuid("id").primaryKey().defaultRandom(),name:varchar("name",{length:255}).notNull(),slug:varchar("slug",{length:100}).notNull().unique(),settings:jsonb("settings").$type().default({}),isActive:boolean("is_active").default(true),createdAt:timestamp("created_at").defaultNow().notNull(),updatedAt:timestamp("updated_at").defaultNow().notNull()},e=>[uniqueIndex("tenants_slug_idx").on(e.slug)]),h=pgTable("api_keys",{id:uuid("id").primaryKey().defaultRandom(),userId:uuid("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),name:varchar("name",{length:255}).notNull(),key:varchar("key",{length:64}).notNull().unique(),keyPrefix:varchar("key_prefix",{length:8}).notNull(),permissions:jsonb("permissions").$type().default([]),lastUsedAt:timestamp("last_used_at"),expiresAt:timestamp("expires_at"),createdAt:timestamp("created_at").defaultNow().notNull()},e=>[index("api_keys_user_idx").on(e.userId),index("api_keys_key_idx").on(e.key)]),A=pgTable("email_verifications",{id:uuid("id").primaryKey().defaultRandom(),userId:uuid("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),token:varchar("token",{length:64}).notNull().unique(),expiresAt:timestamp("expires_at").notNull(),createdAt:timestamp("created_at").defaultNow().notNull()},e=>[index("email_verifications_token_idx").on(e.token),index("email_verifications_user_idx").on(e.userId)]),k=pgTable("password_resets",{id:uuid("id").primaryKey().defaultRandom(),userId:uuid("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),token:varchar("token",{length:64}).notNull().unique(),expiresAt:timestamp("expires_at").notNull(),usedAt:timestamp("used_at"),createdAt:timestamp("created_at").defaultNow().notNull()},e=>[index("password_resets_token_idx").on(e.token),index("password_resets_user_idx").on(e.userId)]),w=pgTable("password_history",{id:uuid("id").primaryKey().defaultRandom(),userId:uuid("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),passwordHash:varchar("password_hash",{length:255}).notNull(),createdAt:timestamp("created_at").defaultNow().notNull()},e=>[index("password_history_user_idx").on(e.userId)]),I=pgTable("lockouts",{id:uuid("id").primaryKey().defaultRandom(),userId:uuid("user_id").notNull().references(()=>d.id,{onDelete:"cascade"}),ipAddress:varchar("ip_address",{length:45}),reason:varchar("reason",{length:255}),lockedUntil:timestamp("locked_until").notNull(),releasedAt:timestamp("released_at"),createdAt:timestamp("created_at").defaultNow().notNull()},e=>[index("lockouts_user_idx").on(e.userId),index("lockouts_ip_idx").on(e.ipAddress),index("lockouts_locked_until_idx").on(e.lockedUntil)]);export{d as a,c as b,m as c,x as d,g as e,N as f,h as g,A as h,k as i,w as j,I as k};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkOJBL4CXK_cjs=require('./chunk-OJBL4CXK.cjs'),chunkDCFOVCJX_cjs=require('./chunk-DCFOVCJX.cjs'),chunkOXEJCIOA_cjs=require('./chunk-OXEJCIOA.cjs');async function O(e){let a=chunkOJBL4CXK_cjs.n(e.db),t={db:e.db,registry:e.registry,req:e.req,user:e.user,tenantId:e.tenantId,webhookService:a,settings:e.settings},n=chunkDCFOVCJX_cjs.c(e.req);if(n){let r=await chunkDCFOVCJX_cjs.b(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=chunkDCFOVCJX_cjs.d(r));}return t}var V={_media:{create:chunkOJBL4CXK_cjs.c.MEDIA_UPLOAD,update:chunkOJBL4CXK_cjs.c.MEDIA_UPLOAD,delete:chunkOJBL4CXK_cjs.c.MEDIA_DELETE}};function D(e,a){let t=V[e];return t?t[a]:`collection.${a}`}async function R(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 m(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)&&m(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")m(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"&&m(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;m(u,s.fields);}}}async function g(e,a,t){let n=await chunkOJBL4CXK_cjs.a(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 q(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 g(l,"read",e),l.hooks?.beforeRead)for(let y of l.hooks.beforeRead)await y({collection:t,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read",where:n});let c=d??!!e.user,b=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 y of b.docs)for(let w of l.hooks.afterRead)await w({collection:t,doc:y,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read"});return await chunkOJBL4CXK_cjs.o(b.docs,l.fields,e.db,e.registry,1,u||0),chunkOXEJCIOA_cjs.a(b)}}function P(e){return async a=>{let{collection:t,id:n,depth:r,select:o,draft:s}=a,u=e.registry.getCollection(t);await g(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 chunkOJBL4CXK_cjs.o([d],u.fields,e.db,e.registry,1,r||0),chunkOXEJCIOA_cjs.a(d)}}function v(e){return async a=>{let{collection:t,data:n,depth:r,select:o}=a,s=e.registry.getCollection(t);await g(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 R(e,D(t,"create"),{collection:t,data:d,operation:"create"}),{doc:d}}}function K(e){return async a=>{let{collection:t,id:n,data:r,depth:o,select:s,baseUpdatedAt:u}=a,i=e.registry.getCollection(t);await g(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}`);m(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 h of i.hooks.beforeValidate){let f=await h({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 h of i.hooks.beforeChange){let f=await h({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 b=e.req&&typeof e.req.headers?.get=="function"&&e.req.headers.get("x-draft")==="true"||a.draft===true,y=i.versions?.drafts===true,w=e.req?.query?.autosave==="true"||e.req?.url?.includes("autosave=true")||a.autosave===true,p;if(y&&b?(await e.db.createVersion({collection:t,documentId:n,data:c,status:"draft",autosave:w,createdBy:e.user?.id,tenantId:e.tenantId}),p=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true})):y?(p=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})):p=await e.db.update({collection:t,id:n,data:c,depth:o||0,tenantId:e.tenantId,select:s}),i.hooks?.afterChange)for(let h of i.hooks.afterChange)await h({collection:t,doc:p,data:c,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});return await R(e,D(t,"update"),{collection:t,data:p,previousData:d,operation:"update"}),{doc:p}}}function E(e){return async a=>{let{collection:t,id:n}=a,r=e.registry.getCollection(t);await g(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 R(e,D(t,"delete"),{collection:t,data:s,previousData:o,operation:"delete"}),{doc:s,message:"Deleted successfully"}}}function j(e){return async a=>{let{collection:t,where:n}=a,r=e.registry.getCollection(t);return await g(r,"read",e),{totalDocs:await e.db.count({collection:t,where:n||{},tenantId:e.tenantId})}}}async function T(e,a,t){let n=await chunkOJBL4CXK_cjs.b(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 W(e){let a={},t=e.registry.getCollections();for(let r of t){let o=r.slug;a[o]={find:q(e),findByID:P(e),create:v(e),update:K(e),delete:E(e),count:j(e)};}let n=e.registry.getGlobals();for(let r of n){let o=r.slug;a[`_globals_${o}`]={get:async s=>(await T(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 T(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 G(e){if(e.settings?.access?.apiAccess?.trpcEnabled===false)throw new Error("tRPC API is disabled");return W(e)}exports.a=O;exports.b=q;exports.c=P;exports.d=v;exports.e=K;exports.f=E;exports.g=j;exports.h=W;exports.i=G;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';var chunkYOJOVQIH_cjs=require('./chunk-YOJOVQIH.cjs'),chunkO4PPZOVI_cjs=require('./chunk-O4PPZOVI.cjs'),chunkOXEJCIOA_cjs=require('./chunk-OXEJCIOA.cjs'),module$1=require('module'),crypto=require('crypto');function P(T,t){let i=t,n=T[i.name];if(i.type==="json"||i.type==="richtext"||i.type==="array"||i.type==="group"||i.type==="blocks"||i.type==="list"||i.type==="relationship-block")try{n=n?JSON.parse(n):null;}catch{n=null;}if(i.type==="checkbox"&&(n=!!n),i.type==="date"&&n)try{let a=new Date(n);isNaN(a.getTime())?n=null:n=a.toISOString();}catch{n=null;}if((i.type==="upload"||i.type==="image")&&n)try{let a=JSON.parse(n);Array.isArray(a)?n=a.map(o=>typeof o=="object"&&o!==null?o:{id:o}):n=typeof a=="object"?a:{id:a};}catch{n=typeof n=="string"?{id:n}:n;}return n}var C;function w(){return C||(C=module$1.createRequire("file:///")("node:sqlite").DatabaseSync,C)}function R(T,t){try{return T.prepare(`PRAGMA table_info(${t})`).all().map(n=>n.name)}catch{return []}}var I=class extends chunkO4PPZOVI_cjs.a{db;path;migrations=new Map;versionsTableName="kyro_versions";constructor(t){super(),this.path=t.path,t.db?this.db=t.db:this.db=null;}async connect(){if(!this.db)this.db=new(w())(this.path||":memory:");else try{this.db.exec("SELECT 1");}catch{this.db=new(w())(this.path||":memory:");}if(this.db&&typeof this.db.prepare=="function"&&!this.db.prepare.__wrapped){let t=this.db.prepare.bind(this.db),i=n=>{let a=t(n),o=e=>typeof e=="boolean"?e?1:0:e===void 0?null:e;return new Proxy(a,{get(e,s,r){if(s==="all")return (...c)=>e.all(...c.map(o));if(s==="get")return (...c)=>e.get(...c.map(o));if(s==="run")return (...c)=>e.run(...c.map(o));let l=Reflect.get(e,s,r);return typeof l=="function"?l.bind(e):l}})};i.__wrapped=true,this.db.prepare=i;}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(t,i){let n=i||this.getTableNameFor(t.slug),a=["id TEXT PRIMARY KEY"];for(let s of chunkYOJOVQIH_cjs.c(t.fields)){if(!s.name||s.name==="id")continue;let r=this.fieldToSQL(s);r&&a.push(r);}let o=chunkYOJOVQIH_cjs.c(t.fields);o.some(s=>s.name==="createdAt")||a.push(`${this.col("createdAt")} TEXT DEFAULT (datetime('now'))`),o.some(s=>s.name==="updatedAt")||a.push(`${this.col("updatedAt")} TEXT DEFAULT (datetime('now'))`),o.some(s=>s.name==="status")||a.push("status TEXT DEFAULT 'draft'"),o.some(s=>s.name==="hasDraft")||a.push("hasDraft INTEGER DEFAULT 0"),t.tenantScoped&&a.push("tenant_id TEXT NOT NULL");let e=R(this.db,n);if(e.length===0){let s=`CREATE TABLE IF NOT EXISTS ${n} (${a.join(", ")})`;this.db.exec(s),this.db.exec(`CREATE INDEX IF NOT EXISTS idx_${n}_status ON ${n}(status)`);for(let r of chunkYOJOVQIH_cjs.c(t.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(e);for(let r of a){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(`
|
|
2
|
+
CREATE TABLE IF NOT EXISTS ${this.versionsTableName} (
|
|
3
|
+
id TEXT PRIMARY KEY,
|
|
4
|
+
collection_slug TEXT NOT NULL,
|
|
5
|
+
document_id TEXT NOT NULL,
|
|
6
|
+
tenant_id TEXT,
|
|
7
|
+
version INTEGER NOT NULL,
|
|
8
|
+
status TEXT NOT NULL DEFAULT 'draft',
|
|
9
|
+
autosave INTEGER NOT NULL DEFAULT 0,
|
|
10
|
+
data TEXT NOT NULL,
|
|
11
|
+
created_by TEXT,
|
|
12
|
+
change_description TEXT,
|
|
13
|
+
published_at TEXT,
|
|
14
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
15
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
16
|
+
)
|
|
17
|
+
`);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(t,i){let n=i.replace(/^-/,""),a=R(this.db,t);if(!a.includes(n)){if(n==="created_at"&&a.includes("createdAt"))return '"createdAt"';if(n==="createdAt"&&a.includes("created_at"))return '"created_at"';if(n==="updated_at"&&a.includes("updatedAt"))return '"updatedAt"';if(n==="updatedAt"&&a.includes("updated_at"))return '"updated_at"'}return this.col(n)}col(t){return `"${t}"`}fieldToSQL(t){switch(t.type){case "text":case "email":case "password":case "textarea":case "color":case "icon":case "code":case "markdown":case "url":return this.col(t.name)+" TEXT";case "number":return this.col(t.name)+" REAL";case "checkbox":return this.col(t.name)+" INTEGER DEFAULT 0";case "date":return this.col(t.name)+" TEXT";case "select":case "radio":return this.col(t.name)+" TEXT";case "relationship":case "upload":case "image":return this.col(t.name)+" TEXT";case "json":case "richtext":case "array":case "group":case "blocks":return this.col(t.name)+" TEXT";default:return null}}parseGlobalsSlug(t){if(t.startsWith("_globals_")){let i=t.replace("_globals_","");return {isGlobal:true,globalSlug:i,tableName:`global_${i.replace(/-/g,"_")}`}}return {isGlobal:false,globalSlug:"",tableName:this.getTableNameFor(t)}}buildWhere(t,i){let n=[],a=[];for(let[o,e]of Object.entries(t)){let s=o.toUpperCase();if((s==="AND"||s==="OR")&&Array.isArray(e)){let l=[];for(let c of e)if(typeof c=="object"&&c!==null){let d=this.buildWhere(c,i);d.clause&&(l.push(`(${d.clause})`),a.push(...d.params));}l.length>0&&n.push(`(${l.join(` ${s} `)})`);continue}let r=this.resolveCol(i,o);typeof e=="object"&&e!==null&&!Array.isArray(e)?(e.equals!==void 0&&(n.push(`${r} = ?`),a.push(e.equals)),e.not_equals!==void 0&&(n.push(`${r} != ?`),a.push(e.not_equals)),e.in!==void 0&&Array.isArray(e.in)&&(e.in.length===0?n.push("1 = 0"):(n.push(`${r} IN (${e.in.map(()=>"?").join(", ")})`),a.push(...e.in))),e.contains!==void 0&&(n.push(`LOWER(${r}) LIKE LOWER(?)`),a.push(`%${e.contains}%`)),e.like!==void 0&&(n.push(`LOWER(${r}) LIKE LOWER(?)`),a.push(e.like)),e.greater_than!==void 0&&(n.push(`${r} > ?`),a.push(e.greater_than)),e.greater_than_equal!==void 0&&(n.push(`${r} >= ?`),a.push(e.greater_than_equal)),e.less_than!==void 0&&(n.push(`${r} < ?`),a.push(e.less_than)),e.less_than_equal!==void 0&&(n.push(`${r} <= ?`),a.push(e.less_than_equal))):e!==void 0&&(n.push(`${r} = ?`),a.push(e));}return {clause:n.join(" AND "),params:a}}async find(t){let{collection:i,where:n={},sort:a,limit:o=10,page:e=1,tenantId:s,select:r,draft:l=false}=t,c=this.parseGlobalsSlug(i),d=c.isGlobal?this.globals.get(c.globalSlug):this.getCollection(i);this.ensureTable(d,c.tableName);let m=c.tableName,h=`SELECT * FROM ${m}`,f=[],u=[],y={...n};this.tenantContext&&d.tenantScoped&&(y=chunkO4PPZOVI_cjs.c({where:y},i,this.tenantContext,chunkO4PPZOVI_cjs.b).where||{});let b=d.fields.find(p=>p.name==="status"),g=b?.type==="select"&&Array.isArray(b.options)&&b.options.some(p=>p.value==="published");if(!l&&g&&(u.push("status = ?"),f.push("published")),s&&d.tenantScoped&&(u.push("tenant_id = ?"),f.push(s)),y&&Object.keys(y).length>0){let p=this.buildWhere(y,m);p.clause&&(u.push(`(${p.clause})`),f.push(...p.params));}u.length>0&&(h+=` WHERE ${u.join(" AND ")}`);let O=a||"-createdAt",U=this.resolveCol(m,O),j=O.startsWith("-")?"DESC":"ASC";h+=` ORDER BY ${U} ${j}`;let M=h.replace("SELECT *","SELECT COUNT(*) as count"),A=this.db.prepare(M).get(...f)?.count||0;h+=" LIMIT ? OFFSET ?",f.push(o,(e-1)*o);let E=this.db.prepare(h).all(...f).map(p=>this.rowToDoc(p,d));return this.tenantContext&&!this.tenantContext.isSuperAdmin&&(E=E.filter(p=>chunkO4PPZOVI_cjs.d(p,i,this.tenantContext,chunkO4PPZOVI_cjs.b))),l&&(E=await Promise.all(E.map(async p=>{let S=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(i,p.id);if(S){let V=S.data?JSON.parse(S.data):{};return chunkOXEJCIOA_cjs.a({...p,...V,status:p.status,_hasUnpublishedChanges:S.status==="draft"})}return p}))),E=E.map(p=>chunkOXEJCIOA_cjs.a(p)),{docs:E,totalDocs:A,limit:o,totalPages:Math.ceil(A/o),page:e,pagingCounter:(e-1)*o+1,hasPrevPage:e>1,hasNextPage:e<Math.ceil(A/o),prevPage:e>1?e-1:null,nextPage:e<Math.ceil(A/o)?e+1:null}}async findByID(t){let{collection:i,id:n,tenantId:a,draft:o=false}=t,e=this.parseGlobalsSlug(i),s=e.isGlobal?this.globals.get(e.globalSlug):this.getCollection(i);this.ensureTable(s,e.tableName);let l=`SELECT * FROM ${e.tableName} WHERE id = ?`,c=[n];if(this.tenantContext&&s.tenantScoped){let u={id:n,tenant_id:this.tenantContext.tenantId};if(!chunkO4PPZOVI_cjs.d(u,i,this.tenantContext,chunkO4PPZOVI_cjs.b))return null}let d=s.fields.find(u=>u.name==="status"),m=d?.type==="select"&&Array.isArray(d.options)&&d.options.some(u=>u.value==="published");!o&&m&&(l+=" AND status = ?",c.push("published")),a&&s.tenantScoped&&(l+=" AND tenant_id = ?",c.push(a));let h=this.db.prepare(l).get(...c);if(!h)return null;let f=this.rowToDoc(h,s);if(o){let u=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(i,f.id);if(u){let y=u.data?JSON.parse(u.data):{};f={...f,...y,status:f.status,_hasUnpublishedChanges:u.status==="draft"};}}return chunkOXEJCIOA_cjs.a(f)}async create(t){let{collection:i,data:n,tenantId:a}=t,o=this.parseGlobalsSlug(i),e=o.isGlobal?this.globals.get(o.globalSlug):this.getCollection(i);this.ensureTable(e,o.tableName);let s=o.tableName,r=o.isGlobal?o.globalSlug:n.id||this.generateId(),l=this.prepareData(n,e);l.id=r;let c=new Date().toISOString();l.created_at=c,l.updated_at=c,a&&e.tenantScoped&&(l.tenant_id=a);let d=Object.keys(l),m=R(this.db,s),h={};for(let g of d)m.includes(g)&&(h[g]=l[g]);let f=Object.keys(h),u=f.map(g=>this.col(g)),y=f.map(()=>"?").join(", "),b=Object.values(h).map(g=>g!==null&&typeof g=="object"?JSON.stringify(g):g);return this.db.prepare(`INSERT OR REPLACE INTO ${s} (${u.join(", ")}) VALUES (${y})`).run(...b),this.ensureVersionsTable(),this.findByID({collection:i,id:r,tenantId:a,draft:true})}async update(t){let{collection:i,id:n,data:a,tenantId:o}=t,e=this.parseGlobalsSlug(i),s=e.isGlobal?this.globals.get(e.globalSlug):this.getCollection(i);this.ensureTable(s,e.tableName);let r=e.tableName,l=this.prepareData(a,s);l.updated_at=new Date().toISOString();let c=R(this.db,r),d={};for(let b of Object.keys(l))c.includes(b)&&(d[b]=l[b]);let h=Object.keys(d).map(b=>`${this.col(b)} = ?`).join(", "),f=Object.values(d).map(b=>b!==null&&typeof b=="object"?JSON.stringify(b):b),u=`UPDATE ${r} SET ${h} WHERE id = ?`,y=[...f,n];return o&&s.tenantScoped&&(u+=" AND tenant_id = ?",y.push(o)),this.db.prepare(u).run(...y),this.ensureVersionsTable(),this.findByID({collection:i,id:n,tenantId:o,draft:true})}async delete(t){let{collection:i,id:n,tenantId:a}=t,o=this.parseGlobalsSlug(i),e=o.isGlobal?this.globals.get(o.globalSlug):this.getCollection(i);this.ensureTable(e,o.tableName),this.ensureVersionsTable();let s=await this.findByID({collection:i,id:n,tenantId:a,draft:true});if(!s)throw new Error(`Document not found: ${i}/${n}`);let l=`DELETE FROM ${o.tableName} WHERE id = ?`,c=[n];return a&&e.tenantScoped&&(l+=" AND tenant_id = ?",c.push(a)),this.db.prepare(l).run(...c),s}async count(t){let{collection:i,tenantId:n}=t,a=this.parseGlobalsSlug(i),o=a.isGlobal?this.globals.get(a.globalSlug):this.getCollection(i);this.ensureTable(o,a.tableName);let e=a.tableName,s=`SELECT COUNT(*) as count FROM ${e}`,r=[],l=[];if(n&&o.tenantScoped&&(r.push("tenant_id = ?"),l.push(n)),t.where&&Object.keys(t.where).length>0){let d=this.buildWhere(t.where,e);d.clause&&(r.push(`(${d.clause})`),l.push(...d.params));}return r.length>0&&(s+=` WHERE ${r.join(" AND ")}`),this.db.prepare(s).get(...l)?.count||0}async findOne(t){let i=this.parseGlobalsSlug(t.collection);if(i.isGlobal){let a=this.globals.get(i.globalSlug);if(!a)throw new Error(`Global "${i.globalSlug}" not found in adapter`);this.ensureTable(a,i.tableName);let o=`SELECT * FROM ${i.tableName}`,e=[],s=[],r=a.fields.find(d=>d.name==="status"),l=r?.type==="select"&&Array.isArray(r.options)&&r.options.some(d=>d.value==="published");!t.draft&&a.versions&&l&&e.push("status = 'published'"),e.length>0&&(o+=` WHERE ${e.join(" AND ")}`),o+=" LIMIT 1";let c=this.db.prepare(o).get(...s);if(c){let d=this.rowToDoc(c,a);if(t.draft){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(t.collection,i.globalSlug);if(m){let h=m.data?JSON.parse(m.data):{};d={...d,...h,status:d.status,_hasUnpublishedChanges:m.status==="draft"};}}return d}return null}return (await this.find({...t,limit:1})).docs[0]||null}async findVersions(t){this.ensureVersionsTable();let{collection:i,documentId:n,tenantId:a,limit:o=20,page:e=1}=t,s=["collection_slug = ?","document_id = ?","autosave = 0"],r=[i,n];a?(s.push("tenant_id = ?"),r.push(a)):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,m=(e-1)*o;return {docs:this.db.prepare(`SELECT * FROM ${this.versionsTableName} ${l} ORDER BY version DESC LIMIT ? OFFSET ?`).all(...r,o,m).map(u=>this.rowToVersion(u)),totalDocs:d,limit:o,totalPages:Math.ceil(d/o),page:e,pagingCounter:(e-1)*o+1,hasPrevPage:e>1,hasNextPage:e<Math.ceil(d/o),prevPage:e>1?e-1:null,nextPage:e<Math.ceil(d/o)?e+1:null}}async findVersionByID(t){this.ensureVersionsTable();let i=this.db.prepare(`SELECT * FROM ${this.versionsTableName} WHERE id = ? AND collection_slug = ? LIMIT 1`).get(t.versionId,t.collection);return i?this.rowToVersion(i):null}async createVersion(t){this.ensureVersionsTable();let i=new Date().toISOString();if(t.autosave){let s=`SELECT * FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ? AND autosave = 1`,r=[t.collection,t.documentId];t.tenantId?(s+=" AND tenant_id = ?",r.push(t.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(t.data),t.status,i,l.id);let c=await this.findVersionByID({collection:t.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(t.collection,t.documentId)?.version??0)+1;if(this.db.prepare(`INSERT INTO ${this.versionsTableName} (
|
|
18
|
+
id, collection_slug, document_id, tenant_id, version, status, autosave, data, created_by, change_description, published_at, created_at, updated_at
|
|
19
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(n,t.collection,t.documentId,t.tenantId??null,o,t.status,t.autosave?1:0,JSON.stringify(t.data),t.createdBy??null,t.changeDescription??null,t.status==="published"?i:null,i,i),!t.autosave){let r=this.collections.get(t.collection)?.versions?.maxPerDoc;r&&r>0&&await this.deleteVersions({collection:t.collection,documentId:t.documentId,keepLatest:r,tenantId:t.tenantId});}return await this.findVersionByID({collection:t.collection,versionId:n})}async updateLatestVersion(t){return this.createVersion({...t,autosave:true})}async deleteVersions(t){this.ensureVersionsTable();let{collection:i,documentId:n,keepLatest:a,tenantId:o}=t;if(a&&a>0){let e=this.db.prepare(`SELECT id, status, autosave FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ? ORDER BY version DESC`).all(i,n),s=0,r=[];for(let l of e)l.status==="published"||l.autosave===1||(s++,s>a&&r.push(l.id));for(let l of r)this.db.prepare(`DELETE FROM ${this.versionsTableName} WHERE id = ?`).run(l);}else {let e=`DELETE FROM ${this.versionsTableName} WHERE collection_slug = ? AND document_id = ?`,s=[i,n];o&&(e+=" AND tenant_id = ?",s.push(o)),this.db.prepare(e).run(...s);}}rowToVersion(t){return {id:String(t.id),collection:t.collection_slug,documentId:t.document_id,version:t.version,status:t.status,data:t.data?JSON.parse(t.data):{},createdBy:t.created_by??void 0,changeDescription:t.change_description??void 0,publishedAt:t.published_at??null,createdAt:t.created_at,updatedAt:t.updated_at}}prepareData(t,i){let n={},a=chunkYOJOVQIH_cjs.c(i.fields),o=(e,s)=>{let r=e;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(e.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:e.relationTo,value:c.id||c}):String(c));return JSON.stringify(l)}return typeof s=="string"?s:typeof s=="object"?JSON.stringify({relationTo:e.relationTo,value:s.id||s}):String(s)}return s};for(let e of a){if(!e.name||e.name==="id"||i.fields.some(l=>l.type==="tabs"&&l.name&&"tabs"in l&&l.tabs.some(c=>c.fields.some(d=>d.name===e.name))))continue;let r=t[e.name];r!==void 0&&(n[e.name]=o(e,r));}for(let e of i.fields)if(e.type==="tabs"&&"tabs"in e&&e.name){let s=t[e.name];if(s&&typeof s=="object"){for(let r of e.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(t,i){let n={id:t.id};for(let a of chunkYOJOVQIH_cjs.c(i.fields)){if(!a.name||a.name==="id")continue;let o=a,e=t[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{e=e?JSON.parse(e):null;}catch{e=null;}if(o.type==="blocks"&&e&&Array.isArray(e)){let s=o.blocks||[];e=chunkYOJOVQIH_cjs.d(e,s);}if(a.type==="checkbox"&&(e=!!e),a.type==="date"&&e)try{let s=new Date(e);isNaN(s.getTime())?(console.warn(`[LocalAdapter] Invalid date value for field "${a.name}":`,e),e=null):e=s.toISOString();}catch{e=null;}if((a.type==="upload"||a.type==="image")&&e)try{let s=JSON.parse(e);Array.isArray(s)?e=s.map(r=>typeof r=="object"&&r!==null?r:{id:r}):e=typeof s=="object"?s:{id:s};}catch{e={id:e};}if(a.type==="relationship"&&e)try{let s=JSON.parse(e);Array.isArray(s),e=s;}catch{e={relationTo:Array.isArray(a.relationTo)?a.relationTo[0]:a.relationTo,value:e};}n[a.name]=e;}for(let a of i.fields)if(!(!a.name||a.name==="id"||a.name==="row"||a.name==="collapsible")&&a.type==="tabs"&&"tabs"in a){let o={};for(let e of a.tabs)for(let s of e.fields)s.name&&s.name!=="id"&&(o[s.name]=P(t,s));n[a.name]=o;}if(i.timestamps){let a=t.createdAt||t.created_at,o=t.updatedAt||t.updated_at;if(a)try{let e=new Date(a);isNaN(e.getTime())||(n.createdAt=e.toISOString());}catch{}if(o)try{let e=new Date(o);isNaN(e.getTime())||(n.updatedAt=e.toISOString());}catch{}}i.tenantScoped&&(n.tenantId=t.tenant_id),n.status=t.status??"published",n.hasDraft=t.hasDraft?!!t.hasDraft:false;for(let a of Object.keys(n))/^\d+$/.test(a)&&delete n[a];return n}generateId(){let t=Date.now().toString(16).padStart(12,"0"),i=crypto.randomBytes(6).toString("hex");return t+i}getMediaById(t){try{let i=this.getTableNameFor("media"),n=this.db.prepare(`SELECT id, url, thumbnail_url FROM ${i} WHERE id = ?`).get(t);if(n)return {id:n.id,url:n.url,thumbnailUrl:n.thumbnail_url||n.url}}catch{}return null}getTableNameFor(t){return t.replace(/-/g,"_")}async migrate(){for(let t of this.collections.values())this.ensureTable(t);}async rollback(){}async transaction(t){return new Promise((i,n)=>{let a=this.db.transaction(async()=>t({db:this.db}));try{let o=a();i(o);}catch(o){n(o);}})}getDatabase(){return this.db}exec(t){this.db.exec(t);}prepare(t){return this.db.prepare(t)}};function G(T){return new I(T||{})}exports.a=I;exports.b=G;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var pgCore=require('drizzle-orm/pg-core');var p=pgCore.pgTable("media",{id:pgCore.uuid("id").primaryKey().defaultRandom(),filename:pgCore.varchar("filename",{length:255}).notNull().unique(),title:pgCore.varchar("title",{length:255}),originalName:pgCore.varchar("original_name",{length:255}).notNull(),mimeType:pgCore.varchar("mime_type",{length:100}).notNull(),fileSize:pgCore.integer("file_size").notNull(),width:pgCore.integer("width"),height:pgCore.integer("height"),url:pgCore.text("url").notNull().unique(),thumbnailUrl:pgCore.text("thumbnail_url"),folder:pgCore.varchar("folder",{length:255}),provider:pgCore.varchar("provider",{length:50}).notNull(),alt:pgCore.text("alt"),caption:pgCore.text("caption"),type:pgCore.varchar("type",{length:50}).notNull().default("other"),status:pgCore.varchar("status",{length:20}).notNull().default("active"),metadata:pgCore.jsonb("metadata").$type(),createdAt:pgCore.timestamp("created_at").defaultNow().notNull(),updatedAt:pgCore.timestamp("updated_at").defaultNow().notNull()},t=>[pgCore.index("media_folder_idx").on(t.folder),pgCore.index("media_provider_idx").on(t.provider),pgCore.index("media_filename_idx").on(t.filename)]),h=pgCore.pgTable("media_folders",{path:pgCore.varchar("path",{length:500}).primaryKey(),name:pgCore.varchar("name",{length:255}).notNull(),parentPath:pgCore.varchar("parent_path",{length:500}),createdAt:pgCore.timestamp("created_at").defaultNow().notNull()},t=>[pgCore.index("media_folders_parent_idx").on(t.parentPath)]);exports.a=p;exports.b=h;
|