@dyrected/core 2.5.53 → 2.5.55

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