@dyrected/core 2.5.53 → 2.5.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (409) hide show
  1. package/dist/{app-config-oOarB6Fw.d.cts → app-config-Bxg_DVxv.d.cts} +3 -1
  2. package/dist/{app-config-oOarB6Fw.d.ts → app-config-Bxg_DVxv.d.ts} +3 -1
  3. package/dist/index.d.cts +2 -2
  4. package/dist/index.d.ts +2 -2
  5. package/dist/server.d.cts +1 -1
  6. package/dist/server.d.ts +1 -1
  7. package/package.json +1 -1
  8. package/dist/__tests__/admin-auth.test.d.ts +0 -2
  9. package/dist/__tests__/admin-auth.test.d.ts.map +0 -1
  10. package/dist/__tests__/admin-auth.test.js +0 -440
  11. package/dist/__tests__/admin-auth.test.js.map +0 -1
  12. package/dist/__tests__/app.test.d.ts +0 -2
  13. package/dist/__tests__/app.test.d.ts.map +0 -1
  14. package/dist/__tests__/app.test.js +0 -27
  15. package/dist/__tests__/app.test.js.map +0 -1
  16. package/dist/__tests__/config.test.d.ts +0 -2
  17. package/dist/__tests__/config.test.d.ts.map +0 -1
  18. package/dist/__tests__/config.test.js +0 -91
  19. package/dist/__tests__/config.test.js.map +0 -1
  20. package/dist/__tests__/deleteMany.test.d.ts +0 -2
  21. package/dist/__tests__/deleteMany.test.d.ts.map +0 -1
  22. package/dist/__tests__/deleteMany.test.js +0 -75
  23. package/dist/__tests__/deleteMany.test.js.map +0 -1
  24. package/dist/__tests__/depth.test.d.ts +0 -2
  25. package/dist/__tests__/depth.test.d.ts.map +0 -1
  26. package/dist/__tests__/depth.test.js +0 -81
  27. package/dist/__tests__/depth.test.js.map +0 -1
  28. package/dist/__tests__/dynamic-options.test.d.ts +0 -2
  29. package/dist/__tests__/dynamic-options.test.d.ts.map +0 -1
  30. package/dist/__tests__/dynamic-options.test.js +0 -132
  31. package/dist/__tests__/dynamic-options.test.js.map +0 -1
  32. package/dist/__tests__/email.service.test.d.ts +0 -2
  33. package/dist/__tests__/email.service.test.d.ts.map +0 -1
  34. package/dist/__tests__/email.service.test.js +0 -46
  35. package/dist/__tests__/email.service.test.js.map +0 -1
  36. package/dist/__tests__/field-inference.test-types.d.ts +0 -24
  37. package/dist/__tests__/field-inference.test-types.d.ts.map +0 -1
  38. package/dist/__tests__/field-inference.test-types.js +0 -87
  39. package/dist/__tests__/field-inference.test-types.js.map +0 -1
  40. package/dist/__tests__/fixtures/editorial-workflow.d.ts +0 -9
  41. package/dist/__tests__/fixtures/editorial-workflow.d.ts.map +0 -1
  42. package/dist/__tests__/fixtures/editorial-workflow.js +0 -12
  43. package/dist/__tests__/fixtures/editorial-workflow.js.map +0 -1
  44. package/dist/__tests__/hooks.test.d.ts +0 -2
  45. package/dist/__tests__/hooks.test.d.ts.map +0 -1
  46. package/dist/__tests__/hooks.test.js +0 -320
  47. package/dist/__tests__/hooks.test.js.map +0 -1
  48. package/dist/__tests__/mocks.d.ts +0 -74
  49. package/dist/__tests__/mocks.d.ts.map +0 -1
  50. package/dist/__tests__/mocks.js +0 -159
  51. package/dist/__tests__/mocks.js.map +0 -1
  52. package/dist/__tests__/openapi.test.d.ts +0 -2
  53. package/dist/__tests__/openapi.test.d.ts.map +0 -1
  54. package/dist/__tests__/openapi.test.js +0 -95
  55. package/dist/__tests__/openapi.test.js.map +0 -1
  56. package/dist/__tests__/parse-sort.test.d.ts +0 -2
  57. package/dist/__tests__/parse-sort.test.d.ts.map +0 -1
  58. package/dist/__tests__/parse-sort.test.js +0 -24
  59. package/dist/__tests__/parse-sort.test.js.map +0 -1
  60. package/dist/__tests__/preferences.test.d.ts +0 -2
  61. package/dist/__tests__/preferences.test.d.ts.map +0 -1
  62. package/dist/__tests__/preferences.test.js +0 -168
  63. package/dist/__tests__/preferences.test.js.map +0 -1
  64. package/dist/__tests__/router.test.d.ts +0 -2
  65. package/dist/__tests__/router.test.d.ts.map +0 -1
  66. package/dist/__tests__/router.test.js +0 -52
  67. package/dist/__tests__/router.test.js.map +0 -1
  68. package/dist/__tests__/where.test.d.ts +0 -2
  69. package/dist/__tests__/where.test.d.ts.map +0 -1
  70. package/dist/__tests__/where.test.js +0 -105
  71. package/dist/__tests__/where.test.js.map +0 -1
  72. package/dist/__tests__/workflow.test.d.ts +0 -2
  73. package/dist/__tests__/workflow.test.d.ts.map +0 -1
  74. package/dist/__tests__/workflow.test.js +0 -497
  75. package/dist/__tests__/workflow.test.js.map +0 -1
  76. package/dist/app-B2tg7Djj.d.cts +0 -1575
  77. package/dist/app-B2tg7Djj.d.ts +0 -1575
  78. package/dist/app-BElen1tP.d.cts +0 -1690
  79. package/dist/app-BElen1tP.d.ts +0 -1690
  80. package/dist/app-BOrsS7Tz.d.cts +0 -1771
  81. package/dist/app-BOrsS7Tz.d.ts +0 -1771
  82. package/dist/app-Bh4_Opv0.d.cts +0 -1522
  83. package/dist/app-Bh4_Opv0.d.ts +0 -1522
  84. package/dist/app-BibuoHQG.d.cts +0 -1764
  85. package/dist/app-BibuoHQG.d.ts +0 -1764
  86. package/dist/app-Bv9gaDAN.d.cts +0 -561
  87. package/dist/app-Bv9gaDAN.d.ts +0 -561
  88. package/dist/app-BvG3bRc8.d.cts +0 -419
  89. package/dist/app-BvG3bRc8.d.ts +0 -419
  90. package/dist/app-C-HgyliB.d.cts +0 -1694
  91. package/dist/app-C-HgyliB.d.ts +0 -1694
  92. package/dist/app-C3B9N1KR.d.cts +0 -1522
  93. package/dist/app-C3B9N1KR.d.ts +0 -1522
  94. package/dist/app-Cc2mG3zi.d.cts +0 -373
  95. package/dist/app-Cc2mG3zi.d.ts +0 -373
  96. package/dist/app-Ctfmo2Re.d.cts +0 -1692
  97. package/dist/app-Ctfmo2Re.d.ts +0 -1692
  98. package/dist/app-D0ffogDd.d.cts +0 -1690
  99. package/dist/app-D0ffogDd.d.ts +0 -1690
  100. package/dist/app-D2uR47gK.d.cts +0 -1690
  101. package/dist/app-D2uR47gK.d.ts +0 -1690
  102. package/dist/app-DDJJa0ep.d.cts +0 -1621
  103. package/dist/app-DDJJa0ep.d.ts +0 -1621
  104. package/dist/app-DO1s9YW1.d.cts +0 -1621
  105. package/dist/app-DO1s9YW1.d.ts +0 -1621
  106. package/dist/app-DTP3-9PJ.d.cts +0 -561
  107. package/dist/app-DTP3-9PJ.d.ts +0 -561
  108. package/dist/app-DZt5nslu.d.cts +0 -374
  109. package/dist/app-DZt5nslu.d.ts +0 -377
  110. package/dist/app-DbKDGYTI.d.cts +0 -566
  111. package/dist/app-DbKDGYTI.d.ts +0 -566
  112. package/dist/app-Dk3SzV1a.d.cts +0 -374
  113. package/dist/app-Dk3SzV1a.d.ts +0 -374
  114. package/dist/app-DnX9mNsh.d.cts +0 -374
  115. package/dist/app-DnX9mNsh.d.ts +0 -374
  116. package/dist/app-DqRO-CMi.d.cts +0 -1457
  117. package/dist/app-DqRO-CMi.d.ts +0 -1457
  118. package/dist/app-DvaFpOtj.d.cts +0 -398
  119. package/dist/app-DvaFpOtj.d.ts +0 -398
  120. package/dist/app-FGzip4XM.d.cts +0 -1563
  121. package/dist/app-FGzip4XM.d.ts +0 -1563
  122. package/dist/app-KApbf4XL.d.cts +0 -362
  123. package/dist/app-KApbf4XL.d.ts +0 -362
  124. package/dist/app-T0alZAE0.d.cts +0 -383
  125. package/dist/app-T0alZAE0.d.ts +0 -383
  126. package/dist/app-aW2FMuYM.d.cts +0 -1759
  127. package/dist/app-aW2FMuYM.d.ts +0 -1759
  128. package/dist/app-config-2vF6W56z.d.cts +0 -1335
  129. package/dist/app-config-2vF6W56z.d.ts +0 -1335
  130. package/dist/app-config-3XBnu9Xz.d.cts +0 -1379
  131. package/dist/app-config-3XBnu9Xz.d.ts +0 -1379
  132. package/dist/app-config-BLMX-9MN.d.cts +0 -1045
  133. package/dist/app-config-BLMX-9MN.d.ts +0 -1045
  134. package/dist/app-config-CaEQH0Kb.d.cts +0 -1383
  135. package/dist/app-config-CaEQH0Kb.d.ts +0 -1383
  136. package/dist/app-config-DLK6bCaP.d.cts +0 -1390
  137. package/dist/app-config-DLK6bCaP.d.ts +0 -1390
  138. package/dist/app-oQt5-9MU.d.cts +0 -1560
  139. package/dist/app-oQt5-9MU.d.ts +0 -1560
  140. package/dist/app-rZj1VFer.d.cts +0 -1621
  141. package/dist/app-rZj1VFer.d.ts +0 -1621
  142. package/dist/app-wo82JRHl.d.cts +0 -445
  143. package/dist/app-wo82JRHl.d.ts +0 -445
  144. package/dist/app.d.ts +0 -21
  145. package/dist/app.d.ts.map +0 -1
  146. package/dist/app.js +0 -56
  147. package/dist/app.js.map +0 -1
  148. package/dist/auth/jexl.d.ts +0 -10
  149. package/dist/auth/jexl.d.ts.map +0 -1
  150. package/dist/auth/jexl.js +0 -22
  151. package/dist/auth/jexl.js.map +0 -1
  152. package/dist/auth/password.d.ts +0 -10
  153. package/dist/auth/password.d.ts.map +0 -1
  154. package/dist/auth/password.js +0 -28
  155. package/dist/auth/password.js.map +0 -1
  156. package/dist/auth/token.d.ts +0 -22
  157. package/dist/auth/token.d.ts.map +0 -1
  158. package/dist/auth/token.js +0 -40
  159. package/dist/auth/token.js.map +0 -1
  160. package/dist/chunk-22JTWD74.js +0 -1784
  161. package/dist/chunk-23URSKPI.js +0 -2371
  162. package/dist/chunk-2JMA3M5S.js +0 -2475
  163. package/dist/chunk-3FZEUK36.js +0 -2470
  164. package/dist/chunk-3VUH2MNW.js +0 -1903
  165. package/dist/chunk-44O2LDPT.js +0 -1513
  166. package/dist/chunk-45JDQDA2.js +0 -1899
  167. package/dist/chunk-4C4L6SD2.js +0 -1524
  168. package/dist/chunk-4EDMZAM5.js +0 -2692
  169. package/dist/chunk-52T4RCFU.js +0 -1972
  170. package/dist/chunk-6ZXEGKT6.js +0 -619
  171. package/dist/chunk-7GGHK75W.js +0 -1835
  172. package/dist/chunk-ALNQINX7.js +0 -2496
  173. package/dist/chunk-B6KDKYXB.js +0 -2502
  174. package/dist/chunk-BEONZV6M.js +0 -1951
  175. package/dist/chunk-C4GEQ5RP.js +0 -1993
  176. package/dist/chunk-CQDVPMEU.js +0 -613
  177. package/dist/chunk-DOJHZ7XN.js +0 -2394
  178. package/dist/chunk-EH7G3LLL.js +0 -2065
  179. package/dist/chunk-EXXOPW3I.js +0 -2483
  180. package/dist/chunk-F4ZC6TXR.js +0 -2065
  181. package/dist/chunk-FCXE5CVC.js +0 -1528
  182. package/dist/chunk-FDQYPPG3.js +0 -2698
  183. package/dist/chunk-FURYJ254.mjs +0 -33
  184. package/dist/chunk-G2QQLBHW.js +0 -24
  185. package/dist/chunk-GM4WW6IE.js +0 -66
  186. package/dist/chunk-GZODLJ3C.js +0 -1861
  187. package/dist/chunk-IIY3E7Q7.js +0 -1996
  188. package/dist/chunk-JJN4J5NS.js +0 -2069
  189. package/dist/chunk-MRUHCNDM.js +0 -1940
  190. package/dist/chunk-NKDX67AW.js +0 -2698
  191. package/dist/chunk-NYUB4AHZ.js +0 -1951
  192. package/dist/chunk-OD4SLW7H.js +0 -1930
  193. package/dist/chunk-OE5MH3NB.js +0 -2070
  194. package/dist/chunk-PH36WQYS.js +0 -1875
  195. package/dist/chunk-PKNFV7KE.js +0 -2469
  196. package/dist/chunk-SUGK7UYL.js +0 -311
  197. package/dist/chunk-TIJHR54M.js +0 -1879
  198. package/dist/chunk-TUUHGLB5.js +0 -2609
  199. package/dist/chunk-UBTRANFX.js +0 -2476
  200. package/dist/chunk-VJWUG2XK.js +0 -1951
  201. package/dist/chunk-W6KURRMW.js +0 -2471
  202. package/dist/chunk-Y4AYI52W.js +0 -631
  203. package/dist/chunk-YDOBB7MY.js +0 -1457
  204. package/dist/chunk-YNJ3YC4N.js +0 -2483
  205. package/dist/chunk-ZFAOBRHT.js +0 -2709
  206. package/dist/controllers/admin-auth.controller.d.ts +0 -68
  207. package/dist/controllers/admin-auth.controller.d.ts.map +0 -1
  208. package/dist/controllers/admin-auth.controller.js +0 -414
  209. package/dist/controllers/admin-auth.controller.js.map +0 -1
  210. package/dist/controllers/auth.controller.d.ts +0 -125
  211. package/dist/controllers/auth.controller.d.ts.map +0 -1
  212. package/dist/controllers/auth.controller.js +0 -323
  213. package/dist/controllers/auth.controller.js.map +0 -1
  214. package/dist/controllers/collection.controller.d.ts +0 -157
  215. package/dist/controllers/collection.controller.d.ts.map +0 -1
  216. package/dist/controllers/collection.controller.js +0 -779
  217. package/dist/controllers/collection.controller.js.map +0 -1
  218. package/dist/controllers/global.controller.d.ts +0 -17
  219. package/dist/controllers/global.controller.d.ts.map +0 -1
  220. package/dist/controllers/global.controller.js +0 -132
  221. package/dist/controllers/global.controller.js.map +0 -1
  222. package/dist/controllers/media.controller.d.ts +0 -38
  223. package/dist/controllers/media.controller.d.ts.map +0 -1
  224. package/dist/controllers/media.controller.js +0 -162
  225. package/dist/controllers/media.controller.js.map +0 -1
  226. package/dist/controllers/preview.controller.d.ts +0 -37
  227. package/dist/controllers/preview.controller.d.ts.map +0 -1
  228. package/dist/controllers/preview.controller.js +0 -48
  229. package/dist/controllers/preview.controller.js.map +0 -1
  230. package/dist/index-BKYugiYp.d.cts +0 -1988
  231. package/dist/index-BKYugiYp.d.ts +0 -1988
  232. package/dist/index-BSWCiAen.d.cts +0 -1983
  233. package/dist/index-BSWCiAen.d.ts +0 -1983
  234. package/dist/index-BfLDb3b0.d.cts +0 -1467
  235. package/dist/index-BfLDb3b0.d.ts +0 -1467
  236. package/dist/index-Bi4sX_eC.d.cts +0 -1491
  237. package/dist/index-Bi4sX_eC.d.ts +0 -1491
  238. package/dist/index-Bp7PDOYG.d.cts +0 -1750
  239. package/dist/index-Bp7PDOYG.d.ts +0 -1750
  240. package/dist/index-ByXooLy-.d.cts +0 -1762
  241. package/dist/index-ByXooLy-.d.ts +0 -1762
  242. package/dist/index-C9Vp1DCT.d.cts +0 -1563
  243. package/dist/index-C9Vp1DCT.d.ts +0 -1563
  244. package/dist/index-CFezd8p1.d.cts +0 -1986
  245. package/dist/index-CFezd8p1.d.ts +0 -1986
  246. package/dist/index-CdQwnbfh.d.cts +0 -1889
  247. package/dist/index-CdQwnbfh.d.ts +0 -1889
  248. package/dist/index-D38_E0gf.d.cts +0 -336
  249. package/dist/index-D38_E0gf.d.ts +0 -336
  250. package/dist/index-DR2z1rrf.d.cts +0 -1503
  251. package/dist/index-DR2z1rrf.d.ts +0 -1503
  252. package/dist/index-DTrpTru7.d.cts +0 -1881
  253. package/dist/index-DTrpTru7.d.ts +0 -1881
  254. package/dist/index-DfAmTZXk.d.cts +0 -1749
  255. package/dist/index-DfAmTZXk.d.ts +0 -1749
  256. package/dist/index-DfkPT4NR.d.cts +0 -1584
  257. package/dist/index-DfkPT4NR.d.ts +0 -1584
  258. package/dist/index-DzUlE5Hc.d.cts +0 -1751
  259. package/dist/index-DzUlE5Hc.d.ts +0 -1751
  260. package/dist/index-M_m6dXZV.d.cts +0 -1889
  261. package/dist/index-M_m6dXZV.d.ts +0 -1889
  262. package/dist/index-RylhgOwj.d.cts +0 -340
  263. package/dist/index-RylhgOwj.d.ts +0 -340
  264. package/dist/index-qhLus8ZO.d.cts +0 -1881
  265. package/dist/index-qhLus8ZO.d.ts +0 -1881
  266. package/dist/index-xB1lMg79.d.cts +0 -1456
  267. package/dist/index-xB1lMg79.d.ts +0 -1456
  268. package/dist/index.d.mts +0 -417
  269. package/dist/index.d.ts.map +0 -1
  270. package/dist/index.js.map +0 -1
  271. package/dist/index.mjs +0 -1974
  272. package/dist/middleware/auth.d.ts +0 -18
  273. package/dist/middleware/auth.d.ts.map +0 -1
  274. package/dist/middleware/auth.js +0 -45
  275. package/dist/middleware/auth.js.map +0 -1
  276. package/dist/password-ACI2YUGZ.js +0 -8
  277. package/dist/router.d.ts +0 -8
  278. package/dist/router.d.ts.map +0 -1
  279. package/dist/router.js +0 -625
  280. package/dist/router.js.map +0 -1
  281. package/dist/server.d.ts.map +0 -1
  282. package/dist/server.js.map +0 -1
  283. package/dist/services/audit.service.d.ts +0 -23
  284. package/dist/services/audit.service.d.ts.map +0 -1
  285. package/dist/services/audit.service.js +0 -28
  286. package/dist/services/audit.service.js.map +0 -1
  287. package/dist/services/defaults.service.d.ts +0 -8
  288. package/dist/services/defaults.service.d.ts.map +0 -1
  289. package/dist/services/defaults.service.js +0 -55
  290. package/dist/services/defaults.service.js.map +0 -1
  291. package/dist/services/email-template.d.ts +0 -46
  292. package/dist/services/email-template.d.ts.map +0 -1
  293. package/dist/services/email-template.js +0 -88
  294. package/dist/services/email-template.js.map +0 -1
  295. package/dist/services/email.service.d.ts +0 -33
  296. package/dist/services/email.service.d.ts.map +0 -1
  297. package/dist/services/email.service.js +0 -96
  298. package/dist/services/email.service.js.map +0 -1
  299. package/dist/services/media.service.d.ts +0 -20
  300. package/dist/services/media.service.d.ts.map +0 -1
  301. package/dist/services/media.service.js +0 -49
  302. package/dist/services/media.service.js.map +0 -1
  303. package/dist/services/population.service.d.ts +0 -20
  304. package/dist/services/population.service.d.ts.map +0 -1
  305. package/dist/services/population.service.js +0 -194
  306. package/dist/services/population.service.js.map +0 -1
  307. package/dist/token-7QG5DBME.mjs +0 -10
  308. package/dist/types/access.d.ts +0 -38
  309. package/dist/types/access.d.ts.map +0 -1
  310. package/dist/types/access.js +0 -2
  311. package/dist/types/access.js.map +0 -1
  312. package/dist/types/adapters.d.ts +0 -146
  313. package/dist/types/adapters.d.ts.map +0 -1
  314. package/dist/types/adapters.js +0 -2
  315. package/dist/types/adapters.js.map +0 -1
  316. package/dist/types/admin-auth.d.ts +0 -132
  317. package/dist/types/admin-auth.d.ts.map +0 -1
  318. package/dist/types/admin-auth.js +0 -2
  319. package/dist/types/admin-auth.js.map +0 -1
  320. package/dist/types/admin.d.ts +0 -65
  321. package/dist/types/admin.d.ts.map +0 -1
  322. package/dist/types/admin.js +0 -2
  323. package/dist/types/admin.js.map +0 -1
  324. package/dist/types/app-config.d.ts +0 -143
  325. package/dist/types/app-config.d.ts.map +0 -1
  326. package/dist/types/app-config.js +0 -2
  327. package/dist/types/app-config.js.map +0 -1
  328. package/dist/types/documents.d.ts +0 -65
  329. package/dist/types/documents.d.ts.map +0 -1
  330. package/dist/types/documents.js +0 -2
  331. package/dist/types/documents.js.map +0 -1
  332. package/dist/types/hooks.d.ts +0 -122
  333. package/dist/types/hooks.d.ts.map +0 -1
  334. package/dist/types/hooks.js +0 -2
  335. package/dist/types/hooks.js.map +0 -1
  336. package/dist/types/index.d.ts +0 -13
  337. package/dist/types/index.d.ts.map +0 -1
  338. package/dist/types/index.js +0 -13
  339. package/dist/types/index.js.map +0 -1
  340. package/dist/types/request.d.ts +0 -42
  341. package/dist/types/request.d.ts.map +0 -1
  342. package/dist/types/request.js +0 -2
  343. package/dist/types/request.js.map +0 -1
  344. package/dist/types/schema-config.d.ts +0 -303
  345. package/dist/types/schema-config.d.ts.map +0 -1
  346. package/dist/types/schema-config.js +0 -2
  347. package/dist/types/schema-config.js.map +0 -1
  348. package/dist/types/schema-core.d.ts +0 -294
  349. package/dist/types/schema-core.d.ts.map +0 -1
  350. package/dist/types/schema-core.js +0 -2
  351. package/dist/types/schema-core.js.map +0 -1
  352. package/dist/types/schema-inference.d.ts +0 -73
  353. package/dist/types/schema-inference.d.ts.map +0 -1
  354. package/dist/types/schema-inference.js +0 -2
  355. package/dist/types/schema-inference.js.map +0 -1
  356. package/dist/types/workflows.d.ts +0 -84
  357. package/dist/types/workflows.d.ts.map +0 -1
  358. package/dist/types/workflows.js +0 -7
  359. package/dist/types/workflows.js.map +0 -1
  360. package/dist/utils/admin-auth.d.ts +0 -5
  361. package/dist/utils/admin-auth.d.ts.map +0 -1
  362. package/dist/utils/admin-auth.js +0 -39
  363. package/dist/utils/admin-auth.js.map +0 -1
  364. package/dist/utils/config.d.ts +0 -8
  365. package/dist/utils/config.d.ts.map +0 -1
  366. package/dist/utils/config.js +0 -238
  367. package/dist/utils/config.js.map +0 -1
  368. package/dist/utils/hooks.d.ts +0 -41
  369. package/dist/utils/hooks.d.ts.map +0 -1
  370. package/dist/utils/hooks.js +0 -173
  371. package/dist/utils/hooks.js.map +0 -1
  372. package/dist/utils/openapi.d.ts +0 -6
  373. package/dist/utils/openapi.d.ts.map +0 -1
  374. package/dist/utils/openapi.js +0 -842
  375. package/dist/utils/openapi.js.map +0 -1
  376. package/dist/utils/parse-sort.d.ts +0 -7
  377. package/dist/utils/parse-sort.d.ts.map +0 -1
  378. package/dist/utils/parse-sort.js +0 -23
  379. package/dist/utils/parse-sort.js.map +0 -1
  380. package/dist/utils/parse-where.d.ts +0 -63
  381. package/dist/utils/parse-where.d.ts.map +0 -1
  382. package/dist/utils/parse-where.js +0 -196
  383. package/dist/utils/parse-where.js.map +0 -1
  384. package/dist/utils/readonly-db.d.ts +0 -9
  385. package/dist/utils/readonly-db.d.ts.map +0 -1
  386. package/dist/utils/readonly-db.js +0 -21
  387. package/dist/utils/readonly-db.js.map +0 -1
  388. package/dist/utils/setup-prompt.d.ts +0 -11
  389. package/dist/utils/setup-prompt.d.ts.map +0 -1
  390. package/dist/utils/setup-prompt.js +0 -863
  391. package/dist/utils/setup-prompt.js.map +0 -1
  392. package/dist/utils/swagger.d.ts +0 -11
  393. package/dist/utils/swagger.d.ts.map +0 -1
  394. package/dist/utils/swagger.js +0 -62
  395. package/dist/utils/swagger.js.map +0 -1
  396. package/dist/utils/upload-validation.d.ts +0 -23
  397. package/dist/utils/upload-validation.d.ts.map +0 -1
  398. package/dist/utils/upload-validation.js +0 -44
  399. package/dist/utils/upload-validation.js.map +0 -1
  400. package/dist/utils/where-sanitizer.d.ts +0 -10
  401. package/dist/utils/where-sanitizer.d.ts.map +0 -1
  402. package/dist/utils/where-sanitizer.js +0 -67
  403. package/dist/utils/where-sanitizer.js.map +0 -1
  404. package/dist/where-sanitizer-7Q4JXMX6.js +0 -57
  405. package/dist/where-sanitizer-DQIWTQZW.js +0 -50
  406. package/dist/workflows.d.ts +0 -54
  407. package/dist/workflows.d.ts.map +0 -1
  408. package/dist/workflows.js +0 -282
  409. package/dist/workflows.js.map +0 -1
@@ -1,1951 +0,0 @@
1
- import {
2
- hashPassword,
3
- verifyPassword
4
- } from "./chunk-G2QQLBHW.js";
5
-
6
- // src/utils/config.ts
7
- var AUDIT_COLLECTION_SLUG = "__audit";
8
- var SYSTEM_FIELDS = [
9
- {
10
- name: "createdAt",
11
- type: "date",
12
- label: "Created At",
13
- admin: { readOnly: true, hidden: true }
14
- },
15
- {
16
- name: "updatedAt",
17
- type: "date",
18
- label: "Updated At",
19
- admin: { readOnly: true, hidden: true }
20
- },
21
- {
22
- name: "createdBy",
23
- type: "text",
24
- label: "Created By",
25
- admin: { readOnly: true, hidden: true }
26
- },
27
- {
28
- name: "updatedBy",
29
- type: "text",
30
- label: "Updated By",
31
- admin: { readOnly: true, hidden: true }
32
- }
33
- ];
34
- var AUDIT_COLLECTION = {
35
- slug: AUDIT_COLLECTION_SLUG,
36
- labels: { singular: "Audit Log", plural: "Audit Logs" },
37
- fields: [
38
- { name: "collection", type: "text", label: "Collection", required: true },
39
- { name: "documentId", type: "text", label: "Document ID" },
40
- { name: "operation", type: "select", label: "Operation", options: ["create", "update", "delete"], required: true },
41
- { name: "user", type: "text", label: "User ID" },
42
- { name: "timestamp", type: "date", label: "Timestamp", required: true },
43
- { name: "changes", type: "json", label: "Changes" }
44
- ],
45
- admin: { hidden: true }
46
- };
47
- function normalizeConfig(config) {
48
- const collections = config?.collections || [];
49
- const globals = config?.globals || [];
50
- const needsAudit = collections.some((col) => col.audit);
51
- const normalizedCollections = collections.map((col) => {
52
- let fields = col.fields || [];
53
- const existingFieldNames = new Set(fields.map((f) => f.name));
54
- if (col.auth) {
55
- if (!existingFieldNames.has("email")) {
56
- fields = [
57
- ...fields,
58
- {
59
- name: "email",
60
- type: "email",
61
- label: "Email",
62
- required: true,
63
- unique: true,
64
- promoted: true,
65
- access: {
66
- update: "!id || user.id == id || (user.roles && 'admin' in user.roles)"
67
- }
68
- }
69
- ];
70
- }
71
- if (!existingFieldNames.has("password")) {
72
- fields = [
73
- ...fields,
74
- {
75
- name: "password",
76
- type: "text",
77
- label: "Password",
78
- required: true,
79
- access: {
80
- update: "!id || user.id == id"
81
- }
82
- }
83
- ];
84
- }
85
- }
86
- const updatedFieldNames = new Set(fields.map((f) => f.name));
87
- const fieldsToInject = SYSTEM_FIELDS.filter((f) => !updatedFieldNames.has(f.name));
88
- return {
89
- ...col,
90
- fields: [...fields, ...fieldsToInject]
91
- };
92
- });
93
- const hasAuditCollection = normalizedCollections.some(
94
- (col) => col.slug === AUDIT_COLLECTION_SLUG
95
- );
96
- return {
97
- ...config,
98
- collections: [
99
- ...normalizedCollections,
100
- ...needsAudit && !hasAuditCollection ? [AUDIT_COLLECTION] : []
101
- ],
102
- globals
103
- };
104
- }
105
-
106
- // src/services/defaults.service.ts
107
- var DefaultsService = class {
108
- /**
109
- * Recursively apply default values to a data object based on field definitions.
110
- */
111
- static apply(fields, data = {}) {
112
- const result = { ...data || {} };
113
- fields.forEach((field) => {
114
- if (field.type === "join") return;
115
- if (field.type === "row" && field.fields) {
116
- Object.assign(result, this.apply(field.fields, data));
117
- return;
118
- }
119
- if (!field.name) return;
120
- let value = result[field.name];
121
- if ((value === void 0 || value === null) && field.renameTo) {
122
- const legacyValue = result[field.renameTo];
123
- if (legacyValue !== void 0 && legacyValue !== null) {
124
- value = legacyValue;
125
- result[field.name] = legacyValue;
126
- }
127
- }
128
- if (value === void 0 || value === null) {
129
- if (field.defaultValue !== void 0) {
130
- result[field.name] = field.defaultValue;
131
- } else {
132
- if (field.type === "boolean") result[field.name] = false;
133
- else if (field.type === "array") result[field.name] = [];
134
- else if (field.type === "multiSelect") result[field.name] = [];
135
- else if (field.type === "object") {
136
- result[field.name] = this.apply(field.fields || [], {});
137
- }
138
- }
139
- } else if (field.type === "object" && field.fields) {
140
- result[field.name] = this.apply(field.fields, value);
141
- } else if (field.type === "array" && field.fields && Array.isArray(value)) {
142
- result[field.name] = value.map((item) => this.apply(field.fields, item));
143
- }
144
- });
145
- return result;
146
- }
147
- };
148
-
149
- // src/services/population.service.ts
150
- var PopulationService = class {
151
- db;
152
- collections;
153
- constructor(db, collections) {
154
- this.db = db;
155
- this.collections = collections;
156
- }
157
- /**
158
- * Recursively populate relationship fields in a document or array of documents.
159
- */
160
- async populate(args) {
161
- const { data, fields, currentDepth = 0, maxDepth = 10 } = args;
162
- if (currentDepth >= maxDepth || !data) {
163
- return data;
164
- }
165
- if (Array.isArray(data)) {
166
- return Promise.all(data.map((item) => this.populate({ ...args, data: item })));
167
- }
168
- const populatedDoc = { ...data };
169
- for (const field of fields) {
170
- if (field.type === "join") continue;
171
- if (field.type === "row" && field.fields) {
172
- const rowPopulated = await this.populate({ data, fields: field.fields, currentDepth, maxDepth });
173
- Object.assign(populatedDoc, rowPopulated);
174
- continue;
175
- }
176
- if (!field.name) continue;
177
- const value = populatedDoc[field.name];
178
- if (field.type === "relationship" && field.relationTo && value) {
179
- const relatedCollection = this.collections.find((c) => c.slug === field.relationTo);
180
- if (!relatedCollection) continue;
181
- if (Array.isArray(value)) {
182
- populatedDoc[field.name] = await Promise.all(
183
- value.map(async (id) => {
184
- if (!id) return id;
185
- let doc = id;
186
- if (typeof id === "string") {
187
- doc = await this.db.findOne({ collection: field.relationTo, id });
188
- }
189
- if (!doc || typeof doc !== "object") return id;
190
- const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
191
- return this.populate({
192
- data: docWithDefaults,
193
- fields: relatedCollection.fields,
194
- currentDepth: currentDepth + 1,
195
- maxDepth
196
- });
197
- })
198
- );
199
- } else if (value) {
200
- let doc = value;
201
- if (typeof value === "string") {
202
- doc = await this.db.findOne({ collection: field.relationTo, id: value });
203
- }
204
- if (doc && typeof doc === "object") {
205
- const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
206
- populatedDoc[field.name] = await this.populate({
207
- data: docWithDefaults,
208
- fields: relatedCollection.fields,
209
- currentDepth: currentDepth + 1,
210
- maxDepth
211
- });
212
- }
213
- }
214
- }
215
- if (field.type === "url" && value && typeof value === "object" && value.type === "internal" && value.relationTo && value.value) {
216
- const relatedCollection = this.collections.find((c) => c.slug === value.relationTo);
217
- if (relatedCollection) {
218
- const doc = await this.db.findOne({ collection: value.relationTo, id: value.value });
219
- if (doc && typeof doc === "object") {
220
- const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
221
- const populatedDocValue = await this.populate({
222
- data: docWithDefaults,
223
- fields: relatedCollection.fields,
224
- currentDepth: currentDepth + 1,
225
- maxDepth
226
- });
227
- const identifier = docWithDefaults.slug || docWithDefaults.id;
228
- const resolvedUrl = `/collections/${value.relationTo}/${identifier}`;
229
- populatedDoc[field.name] = {
230
- ...value,
231
- url: resolvedUrl,
232
- doc: populatedDocValue
233
- };
234
- }
235
- }
236
- }
237
- if ((field.type === "array" || field.type === "object") && field.fields && value) {
238
- populatedDoc[field.name] = await this.populate({
239
- data: value,
240
- fields: field.fields,
241
- currentDepth,
242
- // Nested fields don't consume depth, only relationships do
243
- maxDepth
244
- });
245
- }
246
- if (field.type === "blocks" && field.blocks && Array.isArray(value)) {
247
- populatedDoc[field.name] = await Promise.all(
248
- value.map(async (blockData) => {
249
- const blockConfig = field.blocks.find((b) => b.slug === blockData.blockType);
250
- if (!blockConfig) return blockData;
251
- return this.populate({
252
- data: blockData,
253
- fields: blockConfig.fields,
254
- currentDepth,
255
- maxDepth
256
- });
257
- })
258
- );
259
- }
260
- }
261
- return populatedDoc;
262
- }
263
- /**
264
- * Helper to populate a PaginatedResult
265
- */
266
- async populateResult(result, fields, maxDepth) {
267
- if (maxDepth <= 0) return result;
268
- const populatedDocs = await this.populate({
269
- data: result.docs,
270
- fields,
271
- currentDepth: 0,
272
- maxDepth
273
- });
274
- return {
275
- ...result,
276
- docs: populatedDocs
277
- };
278
- }
279
- };
280
-
281
- // src/services/audit.service.ts
282
- var AuditService = class {
283
- /**
284
- * Writes a single entry to the __audit collection.
285
- * Called without await — runs asynchronously and never blocks the primary operation.
286
- */
287
- static async log(db, args) {
288
- try {
289
- await db.create({
290
- collection: "__audit",
291
- data: {
292
- collection: args.collection,
293
- documentId: args.documentId ?? null,
294
- operation: args.operation,
295
- user: args.user?.id ?? null,
296
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
297
- changes: JSON.stringify({
298
- before: args.before ?? null,
299
- after: args.after ?? null
300
- })
301
- }
302
- });
303
- } catch (err) {
304
- console.error("[dyrected/audit] Failed to write audit log:", err);
305
- }
306
- }
307
- };
308
-
309
- // src/controllers/collection.controller.ts
310
- var CollectionController = class {
311
- collection;
312
- constructor(collection) {
313
- this.collection = collection;
314
- }
315
- async find(c) {
316
- const config = c.get("config");
317
- const db = config.db;
318
- if (!db) return c.json({ message: "Database not configured" }, 500);
319
- const limit = Number(c.req.query("limit")) || 10;
320
- const page = Number(c.req.query("page")) || 1;
321
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 2;
322
- const sort = c.req.query("sort") || void 0;
323
- let where = void 0;
324
- const whereRaw = c.req.query("where");
325
- if (whereRaw) {
326
- try {
327
- where = JSON.parse(decodeURIComponent(whereRaw));
328
- } catch {
329
- }
330
- }
331
- let result = await db.find({
332
- collection: this.collection.slug,
333
- limit,
334
- page,
335
- sort,
336
- where
337
- });
338
- if (result.total === 0 && this.collection.initialData && !where && page === 1) {
339
- console.log(`[dyrected/core] Auto-seeding collection "${this.collection.slug}" from config.initialData`);
340
- for (const data of this.collection.initialData) {
341
- await db.create({ collection: this.collection.slug, data });
342
- }
343
- result = await db.find({
344
- collection: this.collection.slug,
345
- limit,
346
- page,
347
- sort,
348
- where
349
- });
350
- }
351
- result.docs = result.docs.map((doc) => DefaultsService.apply(this.collection.fields, doc));
352
- if (depth > 0) {
353
- const populationService = new PopulationService(db, config.collections);
354
- result = await populationService.populateResult(result, this.collection.fields, depth);
355
- }
356
- return c.json(result);
357
- }
358
- async findOne(c) {
359
- const config = c.get("config");
360
- const db = config.db;
361
- if (!db) return c.json({ message: "Database not configured" }, 500);
362
- const id = c.req.param("id");
363
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
364
- if (!id) return c.json({ message: "Missing ID" }, 400);
365
- const doc = await db.findOne({ collection: this.collection.slug, id });
366
- if (!doc) return c.json({ message: "Not Found" }, 404);
367
- const docWithDefaults = DefaultsService.apply(this.collection.fields, doc);
368
- if (depth > 0 && docWithDefaults) {
369
- const populationService = new PopulationService(db, config.collections);
370
- const populatedDoc = await populationService.populate({
371
- data: docWithDefaults,
372
- fields: this.collection.fields,
373
- currentDepth: 0,
374
- maxDepth: depth
375
- });
376
- return c.json(populatedDoc);
377
- }
378
- return c.json(docWithDefaults);
379
- }
380
- async create(c) {
381
- const config = c.get("config");
382
- const db = config.db;
383
- if (!db) return c.json({ message: "Database not configured" }, 500);
384
- const contentType = c.req.header("Content-Type") || "";
385
- if (contentType.toLowerCase().includes("multipart/form-data")) {
386
- return this.upload(c);
387
- }
388
- const body = await c.req.json();
389
- const user = c.get("user");
390
- const now = (/* @__PURE__ */ new Date()).toISOString();
391
- const data = {
392
- ...body,
393
- createdAt: now,
394
- updatedAt: now,
395
- createdBy: user?.sub ?? null,
396
- updatedBy: user?.sub ?? null
397
- };
398
- if (this.collection.auth && data.password) {
399
- data.password = await hashPassword(data.password);
400
- }
401
- const doc = await db.create({ collection: this.collection.slug, data });
402
- if (this.collection.audit && db) {
403
- AuditService.log(db, {
404
- operation: "create",
405
- collection: this.collection.slug,
406
- documentId: doc.id,
407
- user: user ? { id: user.sub, collection: user.collection, email: user.email } : void 0,
408
- before: null,
409
- after: doc
410
- });
411
- }
412
- return c.json(doc, 201);
413
- }
414
- async upload(c) {
415
- const config = c.get("config");
416
- const storage = config.storage;
417
- if (!storage) return c.json({ message: "Storage not configured" }, 500);
418
- const formData = await c.req.formData();
419
- const file = formData.get("file");
420
- if (!file) return c.json({ message: "No file uploaded" }, 400);
421
- const buffer = new Uint8Array(await file.arrayBuffer());
422
- const siteId = c.get("siteId");
423
- const workspaceId = c.get("workspaceId");
424
- const prefix = workspaceId ? `${workspaceId}/${siteId}` : siteId;
425
- const fileData = await storage.upload({
426
- filename: file.name,
427
- buffer,
428
- mimeType: file.type,
429
- prefix
430
- });
431
- const otherData = {};
432
- formData.forEach((value, key) => {
433
- if (key !== "file" && typeof value === "string") {
434
- otherData[key] = value;
435
- }
436
- });
437
- const user = c.get("user");
438
- const now = (/* @__PURE__ */ new Date()).toISOString();
439
- const doc = await config.db.create({
440
- collection: this.collection.slug,
441
- data: {
442
- ...otherData,
443
- ...fileData,
444
- createdAt: now,
445
- updatedAt: now,
446
- createdBy: user?.sub ?? null,
447
- updatedBy: user?.sub ?? null
448
- }
449
- });
450
- return c.json(doc, 201);
451
- }
452
- async update(c) {
453
- const config = c.get("config");
454
- const db = config.db;
455
- if (!db) return c.json({ message: "Database not configured" }, 500);
456
- const id = c.req.param("id");
457
- if (!id) return c.json({ message: "Missing ID" }, 400);
458
- const body = await c.req.json();
459
- const user = c.get("user");
460
- const data = {
461
- ...body,
462
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
463
- updatedBy: user?.sub ?? null
464
- };
465
- if (this.collection.auth) {
466
- if (data.password) {
467
- if (user && user.sub === id) {
468
- if (!data.oldPassword) {
469
- return c.json({ message: "Current password is required to change password" }, 400);
470
- }
471
- const existing = await db.findOne({ collection: this.collection.slug, id });
472
- if (existing && existing.password) {
473
- const { verifyPassword: verifyPassword2 } = await import("./password-ACI2YUGZ.js");
474
- const isValid = await verifyPassword2(data.oldPassword, existing.password);
475
- if (!isValid) {
476
- return c.json({ message: "Invalid current password" }, 400);
477
- }
478
- }
479
- }
480
- data.password = await hashPassword(data.password);
481
- } else {
482
- delete data.password;
483
- }
484
- delete data.oldPassword;
485
- delete data.confirmPassword;
486
- }
487
- let before = null;
488
- if (this.collection.audit) {
489
- before = await db.findOne({ collection: this.collection.slug, id });
490
- }
491
- const doc = await db.update({ collection: this.collection.slug, id, data });
492
- if (this.collection.audit && db) {
493
- AuditService.log(db, {
494
- operation: "update",
495
- collection: this.collection.slug,
496
- documentId: id,
497
- user: user ? { id: user.sub, collection: user.collection, email: user.email } : void 0,
498
- before,
499
- after: doc
500
- });
501
- }
502
- return c.json(doc);
503
- }
504
- async delete(c) {
505
- const config = c.get("config");
506
- const db = config.db;
507
- if (!db) return c.json({ message: "Database not configured" }, 500);
508
- const id = c.req.param("id");
509
- if (!id) return c.json({ message: "Missing ID" }, 400);
510
- const user = c.get("user");
511
- let before = null;
512
- if (this.collection.audit) {
513
- before = await db.findOne({ collection: this.collection.slug, id });
514
- }
515
- await db.delete({ collection: this.collection.slug, id });
516
- if (this.collection.audit && db) {
517
- AuditService.log(db, {
518
- operation: "delete",
519
- collection: this.collection.slug,
520
- documentId: id,
521
- user: user ? { id: user.sub, collection: user.collection, email: user.email } : void 0,
522
- before,
523
- after: null
524
- });
525
- }
526
- return c.json({ message: "Deleted" });
527
- }
528
- async deleteMany(c) {
529
- const config = c.get("config");
530
- const db = config.db;
531
- if (!db) return c.json({ message: "Database not configured" }, 500);
532
- const user = c.get("user");
533
- let ids = [];
534
- try {
535
- const body = await c.req.json().catch(() => null);
536
- if (body?.ids && Array.isArray(body.ids)) {
537
- ids = body.ids;
538
- }
539
- } catch {
540
- }
541
- if (!ids.length) {
542
- const raw = c.req.queries("ids") ?? c.req.queries("ids[]") ?? [];
543
- ids = raw.filter(Boolean);
544
- }
545
- if (!ids.length) return c.json({ message: "No IDs provided" }, 400);
546
- const deleted = [];
547
- const failed = [];
548
- for (const id of ids) {
549
- try {
550
- let before = null;
551
- if (this.collection.audit) {
552
- before = await db.findOne({ collection: this.collection.slug, id });
553
- }
554
- await db.delete({ collection: this.collection.slug, id });
555
- deleted.push(id);
556
- if (this.collection.audit) {
557
- AuditService.log(db, {
558
- operation: "delete",
559
- collection: this.collection.slug,
560
- documentId: id,
561
- user: user ? { id: user.sub, collection: user.collection, email: user.email } : void 0,
562
- before,
563
- after: null
564
- });
565
- }
566
- } catch (err) {
567
- failed.push({ id, error: err?.message ?? "Unknown error" });
568
- }
569
- }
570
- return c.json({
571
- message: `Deleted ${deleted.length} document(s)`,
572
- deleted,
573
- ...failed.length ? { failed } : {}
574
- });
575
- }
576
- async seed(c) {
577
- const config = c.get("config");
578
- const db = config.db;
579
- if (!db) return c.json({ message: "Database not configured" }, 500);
580
- const body = await c.req.json();
581
- const initialData = body.data;
582
- if (!initialData || !Array.isArray(initialData)) {
583
- return c.json({ message: "Invalid initial data" }, 400);
584
- }
585
- const result = await db.find({ collection: this.collection.slug, limit: 1 });
586
- if (result.total > 0) {
587
- return c.json({ message: "Collection is not empty, skipping seed" });
588
- }
589
- console.log(`[dyrected/core] Auto-seeding collection: ${this.collection.slug}`);
590
- const createdDocs = [];
591
- for (const data of initialData) {
592
- const doc = await db.create({ collection: this.collection.slug, data });
593
- createdDocs.push(doc);
594
- }
595
- return c.json({ message: "Seed successful", count: createdDocs.length }, 201);
596
- }
597
- };
598
-
599
- // src/controllers/global.controller.ts
600
- var GlobalController = class {
601
- global;
602
- constructor(global) {
603
- this.global = global;
604
- }
605
- async get(c) {
606
- const config = c.get("config");
607
- const db = config.db;
608
- if (!db) return c.json({ message: "Database not configured" }, 500);
609
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
610
- let data = await db.getGlobal({ slug: this.global.slug });
611
- const isEmpty = !data || Object.keys(data).length === 0;
612
- if (isEmpty && this.global.initialData) {
613
- console.log(`[dyrected/core] Auto-seeding global "${this.global.slug}" from config.initialData`);
614
- await db.updateGlobal({ slug: this.global.slug, data: this.global.initialData });
615
- data = this.global.initialData;
616
- }
617
- const dataWithDefaults = DefaultsService.apply(this.global.fields, data);
618
- if (depth > 0 && dataWithDefaults) {
619
- const populationService = new PopulationService(db, config.collections);
620
- const populatedData = await populationService.populate({
621
- data: dataWithDefaults,
622
- fields: this.global.fields,
623
- currentDepth: 0,
624
- maxDepth: depth
625
- });
626
- return c.json(populatedData);
627
- }
628
- return c.json(dataWithDefaults);
629
- }
630
- async update(c) {
631
- const db = c.get("config").db;
632
- if (!db) return c.json({ message: "Database not configured" }, 500);
633
- const body = await c.req.json();
634
- const data = await db.updateGlobal({ slug: this.global.slug, data: body });
635
- return c.json(data);
636
- }
637
- async seed(c) {
638
- const config = c.get("config");
639
- const db = config.db;
640
- if (!db) return c.json({ message: "Database not configured" }, 500);
641
- const body = await c.req.json();
642
- const initialData = body.data;
643
- if (!initialData) {
644
- return c.json({ message: "Invalid initial data" }, 400);
645
- }
646
- const existing = await db.getGlobal({ slug: this.global.slug });
647
- if (existing && Object.keys(existing).length > 0) {
648
- return c.json({ message: "Global is not empty, skipping seed" });
649
- }
650
- console.log(`[dyrected/core] Auto-seeding global: ${this.global.slug}`);
651
- await db.updateGlobal({ slug: this.global.slug, data: initialData });
652
- return c.json({ message: "Seed successful", data: initialData }, 201);
653
- }
654
- };
655
-
656
- // src/controllers/media.controller.ts
657
- var MediaController = class {
658
- collection;
659
- constructor(collection = "media") {
660
- this.collection = collection;
661
- }
662
- async upload(c) {
663
- const config = c.get("config");
664
- const storage = config.storage;
665
- const imageService = config.image;
666
- if (!storage) {
667
- return c.json({ message: "Storage not configured" }, 500);
668
- }
669
- const body = await c.req.parseBody();
670
- const file = body["file"];
671
- const focalPointStr = body["focalPoint"];
672
- const focalPoint = focalPointStr ? JSON.parse(focalPointStr) : void 0;
673
- if (!file) {
674
- return c.json({ message: "No file uploaded" }, 400);
675
- }
676
- const buffer = new Uint8Array(await file.arrayBuffer());
677
- const siteId = c.get("siteId");
678
- const workspaceId = c.get("workspaceId");
679
- const prefix = workspaceId ? `${workspaceId}/${siteId}` : siteId || "default";
680
- let imageMetadata = {};
681
- let imageSizes = {};
682
- if (imageService && file.type.startsWith("image/")) {
683
- let colConfig = config.collections.find((col) => col.slug === this.collection);
684
- if (!colConfig && config.onSchemaFetch && siteId) {
685
- const dynamic = await config.onSchemaFetch(siteId);
686
- colConfig = dynamic.collections?.find((col) => col.slug === this.collection);
687
- }
688
- try {
689
- const processed = await imageService.process({
690
- buffer,
691
- mimeType: file.type,
692
- config: colConfig?.upload,
693
- focalPoint
694
- });
695
- imageMetadata = processed.metadata;
696
- imageSizes = processed.sizes;
697
- } catch (err) {
698
- console.error("[MediaController] Image processing failed:", err);
699
- }
700
- }
701
- const fileData = await storage.upload({
702
- filename: file.name,
703
- buffer,
704
- mimeType: file.type,
705
- prefix
706
- });
707
- const finalFileData = {
708
- ...fileData,
709
- ...imageMetadata,
710
- focalPoint,
711
- sizes: {}
712
- };
713
- if (imageSizes) {
714
- for (const [sizeName, sizeData] of Object.entries(imageSizes)) {
715
- const ext = file.name.split(".").pop();
716
- const baseName = file.name.substring(0, file.name.lastIndexOf("."));
717
- const sizeFilename = `${baseName}-${sizeName}.${ext}`;
718
- try {
719
- const sizeFileData = await storage.upload({
720
- filename: sizeFilename,
721
- buffer: sizeData.buffer,
722
- mimeType: file.type,
723
- prefix
724
- });
725
- finalFileData.sizes[sizeName] = {
726
- ...sizeFileData,
727
- width: sizeData.width,
728
- height: sizeData.height
729
- };
730
- } catch (err) {
731
- console.error(`[MediaController] Failed to upload size ${sizeName}:`, err);
732
- }
733
- }
734
- }
735
- const db = config.db;
736
- if (!db) return c.json({ message: "Database not configured" }, 500);
737
- const doc = await db.create({
738
- collection: this.collection,
739
- data: finalFileData
740
- });
741
- return c.json(doc, 201);
742
- }
743
- async find(c) {
744
- const db = c.get("config").db;
745
- if (!db) return c.json({ message: "Database not configured" }, 500);
746
- const limit = Number(c.req.query("limit")) || 10;
747
- const page = Number(c.req.query("page")) || 1;
748
- const result = await db.find({
749
- collection: this.collection,
750
- limit,
751
- page
752
- });
753
- return c.json(result);
754
- }
755
- async delete(c) {
756
- const config = c.get("config");
757
- const storage = config.storage;
758
- const db = config.db;
759
- if (!db) return c.json({ message: "Database not configured" }, 500);
760
- const id = c.req.param("id");
761
- if (!id) return c.json({ message: "Missing ID" }, 400);
762
- const doc = await db.findOne({ collection: this.collection, id });
763
- if (!doc) return c.json({ message: "Not Found" }, 404);
764
- if (storage) {
765
- await storage.delete({ filename: doc.filename });
766
- if (doc.sizes) {
767
- for (const size of Object.values(doc.sizes)) {
768
- if (size.filename) {
769
- await storage.delete({ filename: size.filename });
770
- }
771
- }
772
- }
773
- }
774
- await db.delete({ collection: this.collection, id });
775
- return c.json({ message: "Deleted" });
776
- }
777
- async serve(c) {
778
- const config = c.get("config");
779
- const storage = config.storage;
780
- if (!storage || !storage.resolve) {
781
- return c.json({ message: "Storage not configured for serving" }, 404);
782
- }
783
- const filename = c.req.param("filename");
784
- if (!filename) return c.json({ message: "Missing filename" }, 400);
785
- let res = await storage.resolve({ filename });
786
- if (!res && !filename.includes("/")) {
787
- res = await storage.resolve({ filename: `default/${filename}` });
788
- }
789
- if (!res) return c.json({ message: "Not Found" }, 404);
790
- c.header("Content-Type", res.mimeType);
791
- return c.body(res.buffer);
792
- }
793
- };
794
-
795
- // src/auth/token.ts
796
- import { SignJWT, jwtVerify, decodeJwt } from "jose";
797
- import { TextEncoder } from "util";
798
- function getSecret() {
799
- const secret = process.env.DYRECTED_JWT_SECRET || process.env.JWT_SECRET;
800
- if (!secret) {
801
- throw new Error(
802
- "[dyrected/core] DYRECTED_JWT_SECRET is not set. Add it to your environment variables to enable auth collections."
803
- );
804
- }
805
- return new TextEncoder().encode(secret);
806
- }
807
- var DEFAULT_EXPIRY = "7d";
808
- async function signCollectionToken(payload, expiresIn = DEFAULT_EXPIRY) {
809
- return new SignJWT({ ...payload }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(getSecret());
810
- }
811
- async function verifyCollectionToken(token) {
812
- const { payload } = await jwtVerify(token, getSecret());
813
- return payload;
814
- }
815
-
816
- // src/services/email.service.ts
817
- var _devSend = null;
818
- var _devSendPromise = null;
819
- async function getDevSend() {
820
- if (_devSend) return _devSend;
821
- if (_devSendPromise) return _devSendPromise;
822
- _devSendPromise = (async () => {
823
- try {
824
- const nodemailer = await import("nodemailer");
825
- const account = await nodemailer.default.createTestAccount();
826
- const transport = nodemailer.default.createTransport({
827
- host: "smtp.ethereal.email",
828
- port: 587,
829
- auth: { user: account.user, pass: account.pass }
830
- });
831
- console.log("[dyrected/core] No email config \u2014 using Ethereal for dev email preview.");
832
- console.log(`[dyrected/core] Ethereal login: https://ethereal.email user: ${account.user} pass: ${account.pass}`);
833
- _devSend = async ({ to, subject, html }) => {
834
- const info = await transport.sendMail({ from: '"Dyrected Dev" <dev@dyrected.local>', to, subject, html });
835
- console.log(`[dyrected/core] Email preview URL: ${nodemailer.default.getTestMessageUrl(info)}`);
836
- };
837
- return _devSend;
838
- } catch {
839
- console.warn("[dyrected/core] nodemailer not available \u2014 emails will not be sent in dev.");
840
- return null;
841
- }
842
- })();
843
- return _devSendPromise;
844
- }
845
- async function sendEmail(config, payload) {
846
- if (config.email) {
847
- await config.email.send(payload);
848
- return;
849
- }
850
- if (process.env.NODE_ENV !== "production") {
851
- const devSend = await getDevSend();
852
- await devSend?.(payload);
853
- }
854
- }
855
- function buildWelcomeEmail(config, args) {
856
- const custom = config.email?.templates?.welcome?.(args);
857
- return {
858
- subject: custom?.subject ?? "Welcome \u2014 your account is ready",
859
- html: custom?.html ?? `
860
- <div style="font-family:sans-serif;max-width:600px;margin:0 auto">
861
- <h2>Welcome!</h2>
862
- <p>Your account has been created. You can now log in with:</p>
863
- <p><strong>${args.email}</strong></p>
864
- </div>`
865
- };
866
- }
867
- function buildInviteEmail(config, args) {
868
- const custom = config.email?.templates?.invite?.(args);
869
- return {
870
- subject: custom?.subject ?? "You've been invited",
871
- html: custom?.html ?? `
872
- <div style="font-family:sans-serif;max-width:600px;margin:0 auto">
873
- <h2>You've been invited</h2>
874
- ${args.invitedByEmail ? `<p>Invited by <strong>${args.invitedByEmail}</strong>.</p>` : ""}
875
- <p>Use the token below to accept your invitation. It expires in 7 days.</p>
876
- <pre style="background:#f4f4f4;padding:12px;border-radius:4px;word-break:break-all">${args.token}</pre>
877
- </div>`
878
- };
879
- }
880
- function buildResetPasswordEmail(config, args) {
881
- const custom = config.email?.templates?.resetPassword?.(args);
882
- return {
883
- subject: custom?.subject ?? "Reset your password",
884
- html: custom?.html ?? `
885
- <div style="font-family:sans-serif;max-width:600px;margin:0 auto">
886
- <h2>Reset your password</h2>
887
- <p>Use the token below to reset your password. It expires in 1 hour.</p>
888
- <pre style="background:#f4f4f4;padding:12px;border-radius:4px;word-break:break-all">${args.token}</pre>
889
- </div>`
890
- };
891
- }
892
- function buildPasswordChangedEmail(config, args) {
893
- const custom = config.email?.templates?.passwordChanged?.(args);
894
- return {
895
- subject: custom?.subject ?? "Your password has been changed",
896
- html: custom?.html ?? `
897
- <div style="font-family:sans-serif;max-width:600px;margin:0 auto">
898
- <h2>Password changed</h2>
899
- <p>The password for <strong>${args.email}</strong> was just changed.</p>
900
- <p>If you did not make this change, please contact support immediately.</p>
901
- </div>`
902
- };
903
- }
904
-
905
- // src/controllers/auth.controller.ts
906
- var AuthController = class {
907
- collection;
908
- constructor(collection) {
909
- this.collection = collection;
910
- }
911
- // ---------------------------------------------------------------------------
912
- // GET /init
913
- // Checks if the first user needs to be created.
914
- // ---------------------------------------------------------------------------
915
- async init(c) {
916
- const db = c.get("config").db;
917
- if (!db) return c.json({ message: "Database not configured" }, 500);
918
- const result = await db.find({
919
- collection: this.collection.slug,
920
- limit: 1
921
- });
922
- return c.json({
923
- initialized: result.total > 0
924
- });
925
- }
926
- // ---------------------------------------------------------------------------
927
- // POST /first-user
928
- // Creates the first user if none exist.
929
- // ---------------------------------------------------------------------------
930
- async registerFirstUser(c) {
931
- const config = c.get("config");
932
- const db = config.db;
933
- if (!db) return c.json({ message: "Database not configured" }, 500);
934
- const check = await db.find({
935
- collection: this.collection.slug,
936
- limit: 1
937
- });
938
- if (check.total > 0) {
939
- return c.json({ error: true, message: "Initial user already exists." }, 403);
940
- }
941
- const body = await c.req.json().catch(() => null);
942
- if (!body?.email || !body?.password) {
943
- return c.json({ error: true, message: "email and password are required." }, 400);
944
- }
945
- const hashedPassword = await hashPassword(body.password);
946
- const user = await db.create({
947
- collection: this.collection.slug,
948
- data: {
949
- ...body,
950
- password: hashedPassword,
951
- roles: ["admin"]
952
- // Default first user to admin
953
- }
954
- });
955
- const token = await signCollectionToken({
956
- sub: user.id,
957
- email: user.email,
958
- collection: this.collection.slug
959
- });
960
- const { subject, html } = buildWelcomeEmail(config, { email: body.email });
961
- sendEmail(config, { to: body.email, subject, html }).catch(
962
- (err) => console.error("[dyrected/core] Failed to send welcome email:", err)
963
- );
964
- const { password: _, ...safeUser } = user;
965
- return c.json({ token, user: safeUser });
966
- }
967
- // ---------------------------------------------------------------------------
968
- // POST /login
969
- // ---------------------------------------------------------------------------
970
- async login(c) {
971
- const db = c.get("config").db;
972
- if (!db) return c.json({ message: "Database not configured" }, 500);
973
- const body = await c.req.json().catch(() => null);
974
- if (!body?.email || !body?.password) {
975
- return c.json({ error: true, message: "email and password are required." }, 400);
976
- }
977
- const result = await db.find({
978
- collection: this.collection.slug,
979
- where: { email: body.email },
980
- limit: 1
981
- });
982
- const user = result.docs[0];
983
- if (!user) {
984
- return c.json({ error: true, message: "Invalid email or password." }, 401);
985
- }
986
- const valid = await verifyPassword(body.password, user.password);
987
- if (!valid) {
988
- return c.json({ error: true, message: "Invalid email or password." }, 401);
989
- }
990
- const token = await signCollectionToken({
991
- sub: user.id,
992
- email: user.email,
993
- collection: this.collection.slug
994
- });
995
- const { password: _, ...safeUser } = user;
996
- return c.json({ token, user: safeUser });
997
- }
998
- // ---------------------------------------------------------------------------
999
- // POST /logout
1000
- // Auth collections use stateless JWTs — logout is handled client-side.
1001
- // This endpoint exists so clients have a consistent API surface.
1002
- // ---------------------------------------------------------------------------
1003
- async logout(c) {
1004
- return c.json({ success: true, message: "Logged out. Discard your token." });
1005
- }
1006
- // ---------------------------------------------------------------------------
1007
- // GET /me
1008
- // ---------------------------------------------------------------------------
1009
- async me(c) {
1010
- const db = c.get("config").db;
1011
- if (!db) return c.json({ message: "Database not configured" }, 500);
1012
- const requestUser = c.get("user");
1013
- if (!requestUser) {
1014
- return c.json({ error: true, message: "Authentication required." }, 401);
1015
- }
1016
- const user = await db.findOne({ collection: this.collection.slug, id: requestUser.sub });
1017
- if (!user) {
1018
- return c.json({ error: true, message: "User not found." }, 404);
1019
- }
1020
- const { password: _, ...safeUser } = user;
1021
- return c.json(safeUser);
1022
- }
1023
- // ---------------------------------------------------------------------------
1024
- // POST /refresh-token
1025
- // ---------------------------------------------------------------------------
1026
- async refreshToken(c) {
1027
- const requestUser = c.get("user");
1028
- if (!requestUser) {
1029
- return c.json({ error: true, message: "Authentication required." }, 401);
1030
- }
1031
- const token = await signCollectionToken({
1032
- sub: requestUser.sub,
1033
- email: requestUser.email,
1034
- collection: this.collection.slug
1035
- });
1036
- return c.json({ token });
1037
- }
1038
- // ---------------------------------------------------------------------------
1039
- // POST /forgot-password
1040
- // Requires config.email to be set. Silently succeeds if email not found
1041
- // to prevent email enumeration.
1042
- // ---------------------------------------------------------------------------
1043
- async forgotPassword(c) {
1044
- const config = c.get("config");
1045
- const db = config.db;
1046
- if (!db) return c.json({ message: "Database not configured" }, 500);
1047
- const body = await c.req.json().catch(() => null);
1048
- if (!body?.email) {
1049
- return c.json({ error: true, message: "email is required." }, 400);
1050
- }
1051
- const result = await db.find({
1052
- collection: this.collection.slug,
1053
- where: { email: body.email },
1054
- limit: 1
1055
- });
1056
- const user = result.docs[0];
1057
- if (user) {
1058
- const resetToken = await signCollectionToken(
1059
- { sub: user.id, email: user.email, collection: this.collection.slug, purpose: "reset" },
1060
- "1h"
1061
- );
1062
- try {
1063
- const { subject, html } = buildResetPasswordEmail(config, { token: resetToken });
1064
- await sendEmail(config, { to: user.email, subject, html });
1065
- } catch (err) {
1066
- console.error("[dyrected/core] Failed to send password reset email:", err);
1067
- }
1068
- }
1069
- return c.json({
1070
- success: true,
1071
- message: "If an account with that email exists, a reset link has been sent."
1072
- });
1073
- }
1074
- // ---------------------------------------------------------------------------
1075
- // POST /reset-password
1076
- // Expects { token: string, password: string } in body.
1077
- // The token is the reset JWT issued by /forgot-password.
1078
- // ---------------------------------------------------------------------------
1079
- async resetPassword(c) {
1080
- const config = c.get("config");
1081
- const db = config.db;
1082
- if (!db) return c.json({ message: "Database not configured" }, 500);
1083
- const body = await c.req.json().catch(() => null);
1084
- if (!body?.token || !body?.password) {
1085
- return c.json({ error: true, message: "token and password are required." }, 400);
1086
- }
1087
- let payload;
1088
- try {
1089
- payload = await verifyCollectionToken(body.token);
1090
- } catch {
1091
- return c.json({ error: true, message: "Reset token is invalid or has expired." }, 400);
1092
- }
1093
- if (payload.collection !== this.collection.slug || payload.purpose !== "reset") {
1094
- return c.json({ error: true, message: "Reset token is invalid or has expired." }, 400);
1095
- }
1096
- const hashedPassword = await hashPassword(body.password);
1097
- await db.update({
1098
- collection: this.collection.slug,
1099
- id: payload.sub,
1100
- data: { password: hashedPassword }
1101
- });
1102
- const { subject, html } = buildPasswordChangedEmail(config, { email: payload.email });
1103
- sendEmail(config, { to: payload.email, subject, html }).catch(
1104
- (err) => console.error("[dyrected/core] Failed to send password-changed email:", err)
1105
- );
1106
- return c.json({ success: true, message: "Password has been reset. You can now log in." });
1107
- }
1108
- // ---------------------------------------------------------------------------
1109
- // POST /invite
1110
- // Requires auth. Issues a signed invite token and emails it to the invitee.
1111
- // ---------------------------------------------------------------------------
1112
- async invite(c) {
1113
- const config = c.get("config");
1114
- const db = config.db;
1115
- if (!db) return c.json({ message: "Database not configured" }, 500);
1116
- const requestUser = c.get("user");
1117
- if (!requestUser) {
1118
- return c.json({ error: true, message: "Authentication required." }, 401);
1119
- }
1120
- const body = await c.req.json().catch(() => null);
1121
- if (!body?.email) {
1122
- return c.json({ error: true, message: "email is required." }, 400);
1123
- }
1124
- const existing = await db.find({
1125
- collection: this.collection.slug,
1126
- where: { email: body.email },
1127
- limit: 1
1128
- });
1129
- if (existing.total > 0) {
1130
- return c.json({ error: true, message: "An account with that email already exists." }, 409);
1131
- }
1132
- const inviteToken = await signCollectionToken(
1133
- { sub: body.email, email: body.email, collection: this.collection.slug, purpose: "invite" },
1134
- "7d"
1135
- );
1136
- try {
1137
- const { subject, html } = buildInviteEmail(config, {
1138
- token: inviteToken,
1139
- invitedByEmail: requestUser.email
1140
- });
1141
- await sendEmail(config, { to: body.email, subject, html });
1142
- } catch (err) {
1143
- console.error("[dyrected/core] Failed to send invite email:", err);
1144
- }
1145
- return c.json({ success: true, message: `Invite sent to ${body.email}.` });
1146
- }
1147
- // ---------------------------------------------------------------------------
1148
- // POST /accept-invite
1149
- // Public. Validates the invite token and creates the user account.
1150
- // Body: { token, password, ...extraFields }
1151
- // ---------------------------------------------------------------------------
1152
- async acceptInvite(c) {
1153
- const config = c.get("config");
1154
- const db = config.db;
1155
- if (!db) return c.json({ message: "Database not configured" }, 500);
1156
- const body = await c.req.json().catch(() => null);
1157
- if (!body?.token || !body?.password) {
1158
- return c.json({ error: true, message: "token and password are required." }, 400);
1159
- }
1160
- let payload;
1161
- try {
1162
- payload = await verifyCollectionToken(body.token);
1163
- } catch {
1164
- return c.json({ error: true, message: "Invite token is invalid or has expired." }, 400);
1165
- }
1166
- if (payload.collection !== this.collection.slug || payload.purpose !== "invite") {
1167
- return c.json({ error: true, message: "Invite token is invalid or has expired." }, 400);
1168
- }
1169
- const inviteeEmail = payload.sub;
1170
- const existing = await db.find({
1171
- collection: this.collection.slug,
1172
- where: { email: inviteeEmail },
1173
- limit: 1
1174
- });
1175
- if (existing.total > 0) {
1176
- return c.json({ error: true, message: "An account with that email already exists." }, 409);
1177
- }
1178
- const { token: _t, password: _p, ...extraFields } = body;
1179
- const hashedPassword = await hashPassword(body.password);
1180
- const user = await db.create({
1181
- collection: this.collection.slug,
1182
- data: { ...extraFields, email: inviteeEmail, password: hashedPassword }
1183
- });
1184
- const sessionToken = await signCollectionToken({
1185
- sub: user.id,
1186
- email: inviteeEmail,
1187
- collection: this.collection.slug
1188
- });
1189
- const { subject, html } = buildWelcomeEmail(config, { email: inviteeEmail });
1190
- sendEmail(config, { to: inviteeEmail, subject, html }).catch(
1191
- (err) => console.error("[dyrected/core] Failed to send welcome email:", err)
1192
- );
1193
- const { password: _, ...safeUser } = user;
1194
- return c.json({ token: sessionToken, user: safeUser }, 201);
1195
- }
1196
- };
1197
-
1198
- // src/controllers/preview.controller.ts
1199
- import { SignJWT as SignJWT2, jwtVerify as jwtVerify2 } from "jose";
1200
- import { TextEncoder as TextEncoder2 } from "util";
1201
- var PreviewController = class {
1202
- getSecret() {
1203
- const secret = process.env.DYRECTED_JWT_SECRET || process.env.JWT_SECRET || "dyrected-preview-secret-change-me";
1204
- return new TextEncoder2().encode(secret);
1205
- }
1206
- /**
1207
- * POST /api/preview-token
1208
- * Generates a short-lived token for previewing unsaved data.
1209
- */
1210
- async createToken(c) {
1211
- const body = await c.req.json().catch(() => null);
1212
- if (!body?.collectionSlug || !body?.data) {
1213
- return c.json({ error: true, message: "collectionSlug and data are required." }, 400);
1214
- }
1215
- const token = await new SignJWT2({
1216
- collectionSlug: body.collectionSlug,
1217
- documentId: body.documentId,
1218
- data: body.data
1219
- }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime("15m").sign(this.getSecret());
1220
- const expiresAt = new Date(Date.now() + 15 * 60 * 1e3).toISOString();
1221
- return c.json({ token, expiresAt });
1222
- }
1223
- /**
1224
- * GET /api/preview-data?token=<jwt>
1225
- * Returns the data stored in the preview token.
1226
- */
1227
- async getData(c) {
1228
- const token = c.req.query("token");
1229
- if (!token) {
1230
- return c.json({ error: true, message: "token query parameter is required." }, 400);
1231
- }
1232
- try {
1233
- const { payload } = await jwtVerify2(token, this.getSecret());
1234
- return c.json(payload);
1235
- } catch (err) {
1236
- return c.json({ error: true, message: "Invalid or expired preview token." }, 401);
1237
- }
1238
- }
1239
- };
1240
-
1241
- // src/middleware/auth.ts
1242
- function requireAuth() {
1243
- return async (c, next) => {
1244
- const authHeader = c.req.header("Authorization");
1245
- const token = authHeader?.replace(/^Bearer\s+/i, "");
1246
- if (!token) {
1247
- return c.json({ error: true, message: "Authentication required." }, 401);
1248
- }
1249
- try {
1250
- const user = await verifyCollectionToken(token);
1251
- c.set("user", user);
1252
- await next();
1253
- } catch {
1254
- return c.json({ error: true, message: "Invalid or expired token." }, 401);
1255
- }
1256
- };
1257
- }
1258
- function optionalAuth() {
1259
- return async (c, next) => {
1260
- const authHeader = c.req.header("Authorization");
1261
- const token = authHeader?.replace(/^Bearer\s+/i, "");
1262
- if (token) {
1263
- try {
1264
- const user = await verifyCollectionToken(token);
1265
- c.set("user", user);
1266
- } catch {
1267
- }
1268
- }
1269
- await next();
1270
- };
1271
- }
1272
-
1273
- // src/utils/openapi.ts
1274
- function generateOpenApi(config) {
1275
- const spec = {
1276
- openapi: "3.0.0",
1277
- info: {
1278
- title: "Dyrected API",
1279
- version: "1.0.0",
1280
- description: "Automatically generated OpenAPI specification for the Dyrected project."
1281
- },
1282
- components: {
1283
- schemas: {},
1284
- securitySchemes: {
1285
- ApiKeyAuth: {
1286
- type: "apiKey",
1287
- in: "header",
1288
- name: "x-api-key"
1289
- }
1290
- }
1291
- },
1292
- paths: {},
1293
- security: [{ ApiKeyAuth: [] }]
1294
- };
1295
- for (const collection of config.collections) {
1296
- spec.components.schemas[collection.slug] = collectionToSchema(collection);
1297
- }
1298
- for (const global of config.globals) {
1299
- spec.components.schemas[global.slug] = globalToSchema(global);
1300
- }
1301
- for (const collection of config.collections) {
1302
- const slug = collection.slug;
1303
- const path = `/api/collections/${slug}`;
1304
- const labels = collection.labels || { singular: slug, plural: `${slug}s` };
1305
- spec.paths[path] = {
1306
- get: {
1307
- tags: ["Collections"],
1308
- summary: `Find ${labels.plural}`,
1309
- parameters: [
1310
- { name: "limit", in: "query", schema: { type: "integer", default: 10 } },
1311
- { name: "page", in: "query", schema: { type: "integer", default: 1 } },
1312
- { name: "where", in: "query", schema: { type: "string" }, description: "JSON filter" },
1313
- { name: "sort", in: "query", schema: { type: "string" }, description: "Sort field (e.g. -createdAt)" }
1314
- ],
1315
- responses: {
1316
- 200: {
1317
- description: "Success",
1318
- content: {
1319
- "application/json": {
1320
- schema: {
1321
- type: "object",
1322
- properties: {
1323
- docs: { type: "array", items: { $ref: `#/components/schemas/${slug}` } },
1324
- total: { type: "integer" },
1325
- limit: { type: "integer" },
1326
- page: { type: "integer" }
1327
- }
1328
- }
1329
- }
1330
- }
1331
- }
1332
- }
1333
- },
1334
- post: {
1335
- tags: ["Collections"],
1336
- summary: `Create ${labels.singular}`,
1337
- requestBody: {
1338
- required: true,
1339
- content: {
1340
- "application/json": {
1341
- schema: { $ref: `#/components/schemas/${slug}` }
1342
- }
1343
- }
1344
- },
1345
- responses: {
1346
- 201: {
1347
- description: "Created",
1348
- content: {
1349
- "application/json": {
1350
- schema: { $ref: `#/components/schemas/${slug}` }
1351
- }
1352
- }
1353
- }
1354
- }
1355
- }
1356
- };
1357
- spec.paths[`${path}/{id}`] = {
1358
- get: {
1359
- tags: ["Collections"],
1360
- summary: `Get a single ${labels.singular}`,
1361
- parameters: [{ name: "id", in: "path", required: true, schema: { type: "string" } }],
1362
- responses: {
1363
- 200: {
1364
- description: "Success",
1365
- content: {
1366
- "application/json": {
1367
- schema: { $ref: `#/components/schemas/${slug}` }
1368
- }
1369
- }
1370
- }
1371
- }
1372
- },
1373
- patch: {
1374
- tags: ["Collections"],
1375
- summary: `Update ${labels.singular}`,
1376
- parameters: [{ name: "id", in: "path", required: true, schema: { type: "string" } }],
1377
- requestBody: {
1378
- required: true,
1379
- content: {
1380
- "application/json": {
1381
- schema: { $ref: `#/components/schemas/${slug}` }
1382
- }
1383
- }
1384
- },
1385
- responses: {
1386
- 200: {
1387
- description: "Updated",
1388
- content: {
1389
- "application/json": {
1390
- schema: { $ref: `#/components/schemas/${slug}` }
1391
- }
1392
- }
1393
- }
1394
- }
1395
- },
1396
- delete: {
1397
- tags: ["Collections"],
1398
- summary: `Delete ${labels.singular}`,
1399
- parameters: [{ name: "id", in: "path", required: true, schema: { type: "string" } }],
1400
- responses: {
1401
- 204: { description: "Deleted" }
1402
- }
1403
- }
1404
- };
1405
- }
1406
- for (const global of config.globals) {
1407
- const slug = global.slug;
1408
- const path = `/api/globals/${slug}`;
1409
- spec.paths[path] = {
1410
- get: {
1411
- tags: ["Globals"],
1412
- summary: `Get ${global.label || slug}`,
1413
- responses: {
1414
- 200: {
1415
- description: "Success",
1416
- content: {
1417
- "application/json": {
1418
- schema: { $ref: `#/components/schemas/${slug}` }
1419
- }
1420
- }
1421
- }
1422
- }
1423
- },
1424
- patch: {
1425
- tags: ["Globals"],
1426
- summary: `Update ${global.label || slug}`,
1427
- requestBody: {
1428
- required: true,
1429
- content: {
1430
- "application/json": {
1431
- schema: { $ref: `#/components/schemas/${slug}` }
1432
- }
1433
- }
1434
- },
1435
- responses: {
1436
- 200: {
1437
- description: "Updated",
1438
- content: {
1439
- "application/json": {
1440
- schema: { $ref: `#/components/schemas/${slug}` }
1441
- }
1442
- }
1443
- }
1444
- }
1445
- }
1446
- };
1447
- }
1448
- if (config.storage) {
1449
- spec.paths["/api/media"] = {
1450
- get: {
1451
- tags: ["Media"],
1452
- summary: "List Media",
1453
- responses: {
1454
- 200: {
1455
- description: "Success",
1456
- content: {
1457
- "application/json": {
1458
- schema: {
1459
- type: "object",
1460
- properties: {
1461
- docs: { type: "array", items: { type: "object", additionalProperties: true } }
1462
- }
1463
- }
1464
- }
1465
- }
1466
- }
1467
- }
1468
- },
1469
- post: {
1470
- tags: ["Media"],
1471
- summary: "Upload Media",
1472
- requestBody: {
1473
- content: {
1474
- "multipart/form-data": {
1475
- schema: {
1476
- type: "object",
1477
- properties: {
1478
- file: { type: "string", format: "binary" }
1479
- }
1480
- }
1481
- }
1482
- }
1483
- },
1484
- responses: {
1485
- 201: { description: "Uploaded" }
1486
- }
1487
- }
1488
- };
1489
- }
1490
- return spec;
1491
- }
1492
- function collectionToSchema(collection) {
1493
- const { properties, required } = fieldsToProperties(collection.fields);
1494
- return {
1495
- type: "object",
1496
- properties: {
1497
- id: { type: "string" },
1498
- createdAt: { type: "string", format: "date-time" },
1499
- updatedAt: { type: "string", format: "date-time" },
1500
- ...properties
1501
- },
1502
- required: ["id", ...required]
1503
- };
1504
- }
1505
- function globalToSchema(global) {
1506
- const { properties, required } = fieldsToProperties(global.fields);
1507
- return {
1508
- type: "object",
1509
- properties,
1510
- required
1511
- };
1512
- }
1513
- function fieldsToProperties(fields) {
1514
- const props = {};
1515
- const required = [];
1516
- for (const field of fields) {
1517
- if (!field.name || field.type === "join" || field.type === "row") continue;
1518
- props[field.name] = fieldToSchema(field);
1519
- if (field.required) {
1520
- required.push(field.name);
1521
- }
1522
- }
1523
- return { properties: props, required };
1524
- }
1525
- function fieldToSchema(field) {
1526
- let schema = {};
1527
- switch (field.type) {
1528
- case "text":
1529
- case "textarea":
1530
- case "email":
1531
- case "url":
1532
- schema = { type: "string" };
1533
- break;
1534
- case "number":
1535
- schema = { type: "number" };
1536
- break;
1537
- case "boolean":
1538
- schema = { type: "boolean" };
1539
- break;
1540
- case "date":
1541
- schema = { type: "string", format: "date-time" };
1542
- break;
1543
- case "select":
1544
- schema = { type: "string", enum: field.options?.map((o) => typeof o === "string" ? o : o.value) };
1545
- break;
1546
- case "multiSelect":
1547
- schema = {
1548
- type: "array",
1549
- items: { type: "string", enum: field.options?.map((o) => typeof o === "string" ? o : o.value) }
1550
- };
1551
- break;
1552
- case "relationship":
1553
- schema = { type: "string", description: `ID of a ${field.relationTo} record` };
1554
- break;
1555
- case "object": {
1556
- const { properties, required } = fieldsToProperties(field.fields || []);
1557
- schema = { type: "object", properties, required };
1558
- break;
1559
- }
1560
- case "array": {
1561
- const { properties, required } = fieldsToProperties(field.fields || []);
1562
- schema = { type: "array", items: { type: "object", properties, required } };
1563
- break;
1564
- }
1565
- case "json":
1566
- case "richText":
1567
- schema = { type: "object", additionalProperties: true };
1568
- break;
1569
- case "blocks":
1570
- schema = {
1571
- type: "array",
1572
- items: {
1573
- oneOf: field.blocks?.map((block) => {
1574
- const { properties, required } = fieldsToProperties(block.fields);
1575
- return {
1576
- type: "object",
1577
- properties: {
1578
- blockType: { type: "string", enum: [block.slug] },
1579
- ...properties
1580
- },
1581
- required: ["blockType", ...required]
1582
- };
1583
- })
1584
- }
1585
- };
1586
- break;
1587
- default:
1588
- schema = { type: "string" };
1589
- }
1590
- if (field.label) schema.description = field.label;
1591
- return schema;
1592
- }
1593
-
1594
- // src/utils/swagger.ts
1595
- function getSwaggerHtml(specUrl = "/api/openapi.json") {
1596
- return `
1597
- <!DOCTYPE html>
1598
- <html lang="en">
1599
- <head>
1600
- <meta charset="utf-8" />
1601
- <meta name="viewport" content="width=device-width, initial-scale=1" />
1602
- <meta name="description" content="SwaggerUI" />
1603
- <title>Dyrected API Documentation</title>
1604
- <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui.css" />
1605
- </head>
1606
- <body>
1607
- <div id="swagger-ui"></div>
1608
- <script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js" charset="UTF-8"></script>
1609
- <script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-standalone-preset.js" charset="UTF-8"></script>
1610
- <script>
1611
- window.onload = () => {
1612
- // Forward the apikey query param when loading the spec and making API calls
1613
- const params = new URLSearchParams(window.location.search);
1614
- const apiKey = params.get('apikey');
1615
- const specUrlWithKey = apiKey ? '${specUrl}?apikey=' + encodeURIComponent(apiKey) : '${specUrl}';
1616
-
1617
- window.ui = SwaggerUIBundle({
1618
- url: specUrlWithKey,
1619
- dom_id: '#swagger-ui',
1620
- presets: [
1621
- SwaggerUIBundle.presets.apis,
1622
- SwaggerUIStandalonePreset
1623
- ],
1624
- layout: "BaseLayout",
1625
- deepLinking: true,
1626
- showExtensions: true,
1627
- showCommonExtensions: true,
1628
- // Inject x-api-key header on every request made from the Swagger UI
1629
- requestInterceptor: (request) => {
1630
- if (apiKey) {
1631
- request.headers['x-api-key'] = apiKey;
1632
- }
1633
- return request;
1634
- }
1635
- });
1636
- };
1637
- </script>
1638
- </body>
1639
- </html>
1640
- `;
1641
- }
1642
-
1643
- // src/auth/jexl.ts
1644
- import jexl from "jexl";
1645
- async function evaluateAccess(expression, context) {
1646
- if (expression === void 0 || expression === null) return false;
1647
- if (typeof expression === "boolean") return expression;
1648
- try {
1649
- const result = await jexl.eval(expression, context);
1650
- return !!result;
1651
- } catch (err) {
1652
- console.error("[dyrected/core] Jexl evaluation failed:", err);
1653
- return false;
1654
- }
1655
- }
1656
-
1657
- // src/router.ts
1658
- function accessGate(target, action) {
1659
- return async (c, next) => {
1660
- const user = c.get("user");
1661
- const accessExpr = target.access?.[action];
1662
- if (accessExpr === void 0 || accessExpr === null) {
1663
- return await next();
1664
- }
1665
- const accessArgs = { user, req: c.req, doc: null };
1666
- const allowed = await evaluateAccess(accessExpr, accessArgs);
1667
- if (!allowed) {
1668
- return c.json({ error: true, message: `Access denied: ${action} on ${target.slug}` }, 403);
1669
- }
1670
- await next();
1671
- };
1672
- }
1673
- function registerRoutes(app, config) {
1674
- app.get("/api/schemas", optionalAuth(), async (c) => {
1675
- const siteId = c.req.header("X-Site-Id");
1676
- let collections = [...config.collections];
1677
- let globals = [...config.globals];
1678
- if (siteId && config.onSchemaFetch) {
1679
- const dynamic = await config.onSchemaFetch(siteId);
1680
- if (dynamic.collections) collections = [...collections, ...dynamic.collections];
1681
- if (dynamic.globals) globals = [...globals, ...dynamic.globals];
1682
- if (dynamic.admin) {
1683
- config.admin = { ...config.admin, ...dynamic.admin };
1684
- }
1685
- }
1686
- const user = c.get("user");
1687
- const accessArgs = { user, req: c.req, doc: null };
1688
- const resolveAccess = async (access) => {
1689
- if (access === void 0 || access === null) return true;
1690
- if (typeof access === "function") {
1691
- try {
1692
- const result = await access(accessArgs);
1693
- return typeof result === "boolean" ? result : !!result;
1694
- } catch (err) {
1695
- console.error("[dyrected/core] Functional access check failed:", err);
1696
- return false;
1697
- }
1698
- }
1699
- if (typeof access === "string" || typeof access === "boolean") {
1700
- return evaluateAccess(access, accessArgs);
1701
- }
1702
- return true;
1703
- };
1704
- const serializeAccess = async (access) => {
1705
- if (typeof access === "string") return access;
1706
- if (typeof access === "boolean") return access;
1707
- return resolveAccess(access);
1708
- };
1709
- const filteredCollections = await Promise.all(collections.filter((col) => !siteId || col.shared || !col.siteId || col.siteId === siteId).map(async (col) => ({
1710
- slug: col.slug,
1711
- labels: col.labels,
1712
- access: {
1713
- read: await serializeAccess(col.access?.read),
1714
- create: await serializeAccess(col.access?.create),
1715
- update: await serializeAccess(col.access?.update),
1716
- delete: await serializeAccess(col.access?.delete)
1717
- },
1718
- fields: await Promise.all(col.fields.map(async (f) => ({
1719
- name: f.name,
1720
- type: f.type,
1721
- label: f.label,
1722
- required: f.required,
1723
- defaultValue: f.defaultValue,
1724
- options: f.options,
1725
- relationTo: f.relationTo,
1726
- hasMany: f.hasMany,
1727
- fields: f.fields,
1728
- blocks: f.blocks,
1729
- admin: f.admin,
1730
- access: {
1731
- read: await serializeAccess(f.access?.read),
1732
- update: await serializeAccess(f.access?.update)
1733
- }
1734
- }))),
1735
- upload: !!col.upload,
1736
- auth: !!col.auth,
1737
- admin: col.admin
1738
- })));
1739
- const filteredGlobals = await Promise.all(globals.filter((glb) => !siteId || glb.shared || !glb.siteId || glb.siteId === siteId).map(async (glb) => ({
1740
- slug: glb.slug,
1741
- label: glb.label,
1742
- access: {
1743
- read: await serializeAccess(glb.access?.read),
1744
- update: await serializeAccess(glb.access?.update)
1745
- },
1746
- fields: await Promise.all(glb.fields.map(async (f) => ({
1747
- name: f.name,
1748
- type: f.type,
1749
- label: f.label,
1750
- required: f.required,
1751
- defaultValue: f.defaultValue,
1752
- options: f.options,
1753
- relationTo: f.relationTo,
1754
- hasMany: f.hasMany,
1755
- fields: f.fields,
1756
- blocks: f.blocks,
1757
- admin: f.admin,
1758
- access: {
1759
- read: await serializeAccess(f.access?.read),
1760
- update: await serializeAccess(f.access?.update)
1761
- }
1762
- }))),
1763
- admin: glb.admin
1764
- })));
1765
- return c.json({
1766
- collections: filteredCollections,
1767
- globals: filteredGlobals,
1768
- admin: config.admin || {}
1769
- });
1770
- });
1771
- app.get("/api/openapi.json", (c) => {
1772
- return c.json(generateOpenApi(config));
1773
- });
1774
- app.get("/api/docs", (c) => {
1775
- return c.html(getSwaggerHtml());
1776
- });
1777
- app.get("/api/media/:filename{.+$}", async (c) => {
1778
- const mediaController = new MediaController("media");
1779
- return mediaController.serve(c);
1780
- });
1781
- app.get("/media/:filename{.+$}", async (c) => {
1782
- const mediaController = new MediaController("media");
1783
- return mediaController.serve(c);
1784
- });
1785
- if (config.storage) {
1786
- const uploadCollections = config.collections.filter((c) => c.upload);
1787
- for (const col of uploadCollections) {
1788
- const mediaController = new MediaController(col.slug);
1789
- const prefix = `/api/collections/${col.slug}`;
1790
- app.get(`${prefix}/media`, accessGate(col, "read"), (c) => mediaController.find(c));
1791
- app.get(`${prefix}/media/:filename{.+$}`, (c) => mediaController.serve(c));
1792
- app.post(`${prefix}/media`, accessGate(col, "create"), (c) => mediaController.upload(c));
1793
- app.delete(`${prefix}/media/:id`, accessGate(col, "delete"), (c) => mediaController.delete(c));
1794
- }
1795
- }
1796
- for (const collection of config.collections) {
1797
- if (!collection.auth) continue;
1798
- const path = `/api/collections/${collection.slug}`;
1799
- const authController = new AuthController(collection);
1800
- app.post(`${path}/login`, (c) => authController.login(c));
1801
- app.post(`${path}/logout`, (c) => authController.logout(c));
1802
- app.get(`${path}/init`, (c) => authController.init(c));
1803
- app.post(`${path}/first-user`, (c) => authController.registerFirstUser(c));
1804
- app.get(`${path}/me`, requireAuth(), (c) => authController.me(c));
1805
- app.post(`${path}/refresh-token`, requireAuth(), (c) => authController.refreshToken(c));
1806
- app.post(`${path}/forgot-password`, (c) => authController.forgotPassword(c));
1807
- app.post(`${path}/reset-password`, (c) => authController.resetPassword(c));
1808
- app.post(`${path}/invite`, requireAuth(), (c) => authController.invite(c));
1809
- app.post(`${path}/accept-invite`, (c) => authController.acceptInvite(c));
1810
- }
1811
- for (const collection of config.collections) {
1812
- const path = `/api/collections/${collection.slug}`;
1813
- const controller = new CollectionController(collection);
1814
- app.get(path, accessGate(collection, "read"), (c) => controller.find(c));
1815
- app.post(path, accessGate(collection, "create"), (c) => controller.create(c));
1816
- app.post(`${path}/media`, accessGate(collection, "create"), (c) => controller.create(c));
1817
- app.delete(`${path}/delete-many`, accessGate(collection, "delete"), (c) => controller.deleteMany(c));
1818
- app.get(`${path}/:id`, accessGate(collection, "read"), (c) => controller.findOne(c));
1819
- app.patch(`${path}/:id`, accessGate(collection, "update"), (c) => controller.update(c));
1820
- app.delete(`${path}/:id`, accessGate(collection, "delete"), (c) => controller.delete(c));
1821
- app.post(`${path}/seed`, (c) => controller.seed(c));
1822
- }
1823
- for (const global of config.globals) {
1824
- const path = `/api/globals/${global.slug}`;
1825
- const controller = new GlobalController(global);
1826
- app.get(path, accessGate(global, "read"), (c) => controller.get(c));
1827
- app.patch(path, accessGate(global, "update"), (c) => controller.update(c));
1828
- app.post(`${path}/seed`, (c) => controller.seed(c));
1829
- }
1830
- const previewController = new PreviewController();
1831
- app.post("/api/preview-token", requireAuth(), (c) => previewController.createToken(c));
1832
- app.get("/api/preview-data", (c) => previewController.getData(c));
1833
- app.all("/api/collections/:slug/:id?", async (c) => {
1834
- const slug = c.req.param("slug");
1835
- const id = c.req.param("id");
1836
- const siteId = c.req.header("X-Site-Id") || c.get("siteId");
1837
- const config2 = c.get("config");
1838
- if (config2.collections.some((col) => col.slug === slug)) {
1839
- return c.json({ message: "Method Not Allowed" }, 405);
1840
- }
1841
- if (config2.onSchemaFetch && siteId) {
1842
- const dynamic = await config2.onSchemaFetch(siteId);
1843
- let collection = dynamic.collections?.find((col) => col.slug === slug);
1844
- if (!collection && slug === "media") {
1845
- collection = {
1846
- slug: "media",
1847
- labels: { singular: "Media", plural: "Media" },
1848
- upload: true,
1849
- fields: []
1850
- };
1851
- }
1852
- if (collection) {
1853
- if (collection.auth && id) {
1854
- const authController = new AuthController(collection);
1855
- const method2 = c.req.method;
1856
- if (method2 === "POST" && id === "login") return authController.login(c);
1857
- if (method2 === "POST" && id === "logout") return authController.logout(c);
1858
- if (method2 === "GET" && id === "me") return authController.me(c);
1859
- if (method2 === "POST" && id === "refresh-token") return authController.refreshToken(c);
1860
- if (method2 === "POST" && id === "forgot-password") return authController.forgotPassword(c);
1861
- if (method2 === "POST" && id === "reset-password") return authController.resetPassword(c);
1862
- }
1863
- const controller = new CollectionController(collection);
1864
- const method = c.req.method;
1865
- if (id) {
1866
- if (method === "GET") return controller.findOne(c);
1867
- if (method === "PATCH") return controller.update(c);
1868
- if (method === "DELETE" && id === "delete-many") return controller.deleteMany(c);
1869
- if (method === "DELETE") return controller.delete(c);
1870
- if (method === "POST" && id === "media") return controller.create(c);
1871
- if (method === "POST" && id === "seed") return controller.seed(c);
1872
- } else {
1873
- if (method === "GET") return controller.find(c);
1874
- if (method === "POST") return controller.create(c);
1875
- }
1876
- }
1877
- }
1878
- return c.json({ message: `Collection "${slug}" not found` }, 404);
1879
- });
1880
- app.all("/api/globals/:slug", async (c) => {
1881
- const slug = c.req.param("slug");
1882
- const siteId = c.req.header("X-Site-Id") || c.get("siteId");
1883
- const config2 = c.get("config");
1884
- if (config2.globals.some((glb) => glb.slug === slug)) {
1885
- return c.json({ message: "Method Not Allowed" }, 405);
1886
- }
1887
- if (config2.onSchemaFetch && siteId) {
1888
- const dynamic = await config2.onSchemaFetch(siteId);
1889
- const global = dynamic.globals?.find((glb) => glb.slug === slug);
1890
- if (global) {
1891
- const controller = new GlobalController(global);
1892
- if (c.req.method === "GET") return controller.get(c);
1893
- if (c.req.method === "PATCH") return controller.update(c);
1894
- }
1895
- }
1896
- return c.json({ message: `Global "${slug}" not found` }, 404);
1897
- });
1898
- }
1899
-
1900
- // src/app.ts
1901
- import { Hono } from "hono";
1902
- import { cors } from "hono/cors";
1903
- import { requestId } from "hono/request-id";
1904
- async function createDyrectedApp(rawConfig) {
1905
- const config = normalizeConfig(rawConfig);
1906
- const app = new Hono();
1907
- if (config.db?.sync) {
1908
- await config.db.sync(config.collections, config.globals);
1909
- }
1910
- app.use("*", requestId());
1911
- app.use("*", optionalAuth());
1912
- app.use("*", async (c, next) => {
1913
- const start = Date.now();
1914
- await next();
1915
- const ms = Date.now() - start;
1916
- console.log(`[dyrected/api] ${c.req.method} ${c.req.path} ${c.res.status} - ${ms}ms`);
1917
- });
1918
- app.use("*", cors());
1919
- app.use("*", async (c, next) => {
1920
- c.set("config", config);
1921
- if (!c.get("siteId")) {
1922
- c.set("siteId", "default");
1923
- }
1924
- await next();
1925
- });
1926
- app.get("/health", (c) => c.json({ status: "ok", version: "0.0.1" }));
1927
- app.get("/routes", (c) => {
1928
- const routes = app.routes.map((r) => ({ method: r.method, path: r.path }));
1929
- return c.json({ routes });
1930
- });
1931
- app.onError((err, c) => {
1932
- console.error(`[dyrected/core] Uncaught Error:`, err);
1933
- return c.json({
1934
- message: err.message || "Internal Server Error",
1935
- stack: process.env.NODE_ENV === "development" ? err.stack : void 0
1936
- }, 500);
1937
- });
1938
- registerRoutes(app, config);
1939
- return app;
1940
- }
1941
-
1942
- export {
1943
- normalizeConfig,
1944
- CollectionController,
1945
- GlobalController,
1946
- MediaController,
1947
- AuthController,
1948
- PreviewController,
1949
- registerRoutes,
1950
- createDyrectedApp
1951
- };