@dyrected/core 2.8.3 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-config-BccpBUqJ.d.cts → app-config-DQhcrGDE.d.cts} +472 -85
- package/dist/{app-config-BccpBUqJ.d.ts → app-config-DQhcrGDE.d.ts} +472 -85
- package/dist/chunk-JSBRDJBE.js +30 -0
- package/dist/{chunk-GFFGDHST.js → chunk-TYPDQTE2.js} +1879 -42
- package/dist/index.cjs +1954 -41
- package/dist/index.d.cts +20 -5
- package/dist/index.d.ts +20 -5
- package/dist/index.js +87 -9
- package/dist/{observability-KCMTV7GO.js → observability-HQF4EUSV.js} +1 -0
- package/dist/server.cjs +2109 -45
- package/dist/server.d.cts +38 -16
- package/dist/server.d.ts +38 -16
- package/dist/server.js +250 -17
- package/dist/{where-sanitizer-WJ2W2QCE.js → where-sanitizer-3MNFMYA2.js} +2 -0
- package/package.json +3 -3
- package/dist/__tests__/access-features.test.d.ts +0 -2
- package/dist/__tests__/access-features.test.d.ts.map +0 -1
- package/dist/__tests__/access-features.test.js +0 -159
- package/dist/__tests__/access-features.test.js.map +0 -1
- package/dist/__tests__/access-parity.test.d.ts +0 -2
- package/dist/__tests__/access-parity.test.d.ts.map +0 -1
- package/dist/__tests__/access-parity.test.js +0 -338
- package/dist/__tests__/access-parity.test.js.map +0 -1
- package/dist/__tests__/access.test.d.ts +0 -2
- package/dist/__tests__/access.test.d.ts.map +0 -1
- package/dist/__tests__/access.test.js +0 -137
- package/dist/__tests__/access.test.js.map +0 -1
- package/dist/__tests__/admin-auth.test.d.ts +0 -2
- package/dist/__tests__/admin-auth.test.d.ts.map +0 -1
- package/dist/__tests__/admin-auth.test.js +0 -440
- package/dist/__tests__/admin-auth.test.js.map +0 -1
- package/dist/__tests__/app.test.d.ts +0 -2
- package/dist/__tests__/app.test.d.ts.map +0 -1
- package/dist/__tests__/app.test.js +0 -112
- package/dist/__tests__/app.test.js.map +0 -1
- package/dist/__tests__/audit.test.d.ts +0 -2
- package/dist/__tests__/audit.test.d.ts.map +0 -1
- package/dist/__tests__/audit.test.js +0 -125
- package/dist/__tests__/audit.test.js.map +0 -1
- package/dist/__tests__/auth-hydration.test.d.ts +0 -2
- package/dist/__tests__/auth-hydration.test.d.ts.map +0 -1
- package/dist/__tests__/auth-hydration.test.js +0 -90
- package/dist/__tests__/auth-hydration.test.js.map +0 -1
- package/dist/__tests__/auth-invite.test.d.ts +0 -2
- package/dist/__tests__/auth-invite.test.d.ts.map +0 -1
- package/dist/__tests__/auth-invite.test.js +0 -152
- package/dist/__tests__/auth-invite.test.js.map +0 -1
- package/dist/__tests__/auth-lockout.test.d.ts +0 -2
- package/dist/__tests__/auth-lockout.test.d.ts.map +0 -1
- package/dist/__tests__/auth-lockout.test.js +0 -154
- package/dist/__tests__/auth-lockout.test.js.map +0 -1
- package/dist/__tests__/auth-sessions.test.d.ts +0 -2
- package/dist/__tests__/auth-sessions.test.d.ts.map +0 -1
- package/dist/__tests__/auth-sessions.test.js +0 -118
- package/dist/__tests__/auth-sessions.test.js.map +0 -1
- package/dist/__tests__/config.test.d.ts +0 -2
- package/dist/__tests__/config.test.d.ts.map +0 -1
- package/dist/__tests__/config.test.js +0 -402
- package/dist/__tests__/config.test.js.map +0 -1
- package/dist/__tests__/define-field.test.d.ts +0 -2
- package/dist/__tests__/define-field.test.d.ts.map +0 -1
- package/dist/__tests__/define-field.test.js +0 -121
- package/dist/__tests__/define-field.test.js.map +0 -1
- package/dist/__tests__/deleteMany.test.d.ts +0 -2
- package/dist/__tests__/deleteMany.test.d.ts.map +0 -1
- package/dist/__tests__/deleteMany.test.js +0 -75
- package/dist/__tests__/deleteMany.test.js.map +0 -1
- package/dist/__tests__/depth.test.d.ts +0 -2
- package/dist/__tests__/depth.test.d.ts.map +0 -1
- package/dist/__tests__/depth.test.js +0 -115
- package/dist/__tests__/depth.test.js.map +0 -1
- package/dist/__tests__/dynamic-options.test.d.ts +0 -2
- package/dist/__tests__/dynamic-options.test.d.ts.map +0 -1
- package/dist/__tests__/dynamic-options.test.js +0 -168
- package/dist/__tests__/dynamic-options.test.js.map +0 -1
- package/dist/__tests__/email.service.test.d.ts +0 -2
- package/dist/__tests__/email.service.test.d.ts.map +0 -1
- package/dist/__tests__/email.service.test.js +0 -52
- package/dist/__tests__/email.service.test.js.map +0 -1
- package/dist/__tests__/field-inference.test-types.d.ts +0 -161
- package/dist/__tests__/field-inference.test-types.d.ts.map +0 -1
- package/dist/__tests__/field-inference.test-types.js +0 -87
- package/dist/__tests__/field-inference.test-types.js.map +0 -1
- package/dist/__tests__/fixtures/editorial-workflow.d.ts +0 -14
- package/dist/__tests__/fixtures/editorial-workflow.d.ts.map +0 -1
- package/dist/__tests__/fixtures/editorial-workflow.js +0 -12
- package/dist/__tests__/fixtures/editorial-workflow.js.map +0 -1
- package/dist/__tests__/hooks.test.d.ts +0 -2
- package/dist/__tests__/hooks.test.d.ts.map +0 -1
- package/dist/__tests__/hooks.test.js +0 -320
- package/dist/__tests__/hooks.test.js.map +0 -1
- package/dist/__tests__/mocks.d.ts +0 -75
- package/dist/__tests__/mocks.d.ts.map +0 -1
- package/dist/__tests__/mocks.js +0 -170
- package/dist/__tests__/mocks.js.map +0 -1
- package/dist/__tests__/observability.test.d.ts +0 -2
- package/dist/__tests__/observability.test.d.ts.map +0 -1
- package/dist/__tests__/observability.test.js +0 -233
- package/dist/__tests__/observability.test.js.map +0 -1
- package/dist/__tests__/openapi.test.d.ts +0 -2
- package/dist/__tests__/openapi.test.d.ts.map +0 -1
- package/dist/__tests__/openapi.test.js +0 -105
- package/dist/__tests__/openapi.test.js.map +0 -1
- package/dist/__tests__/parse-sort.test.d.ts +0 -2
- package/dist/__tests__/parse-sort.test.d.ts.map +0 -1
- package/dist/__tests__/parse-sort.test.js +0 -24
- package/dist/__tests__/parse-sort.test.js.map +0 -1
- package/dist/__tests__/preferences.test.d.ts +0 -2
- package/dist/__tests__/preferences.test.d.ts.map +0 -1
- package/dist/__tests__/preferences.test.js +0 -168
- package/dist/__tests__/preferences.test.js.map +0 -1
- package/dist/__tests__/router.test.d.ts +0 -2
- package/dist/__tests__/router.test.d.ts.map +0 -1
- package/dist/__tests__/router.test.js +0 -70
- package/dist/__tests__/router.test.js.map +0 -1
- package/dist/__tests__/search.test.d.ts +0 -2
- package/dist/__tests__/search.test.d.ts.map +0 -1
- package/dist/__tests__/search.test.js +0 -174
- package/dist/__tests__/search.test.js.map +0 -1
- package/dist/__tests__/upload-validation.test.d.ts +0 -2
- package/dist/__tests__/upload-validation.test.d.ts.map +0 -1
- package/dist/__tests__/upload-validation.test.js +0 -41
- package/dist/__tests__/upload-validation.test.js.map +0 -1
- package/dist/__tests__/where.test.d.ts +0 -2
- package/dist/__tests__/where.test.d.ts.map +0 -1
- package/dist/__tests__/where.test.js +0 -105
- package/dist/__tests__/where.test.js.map +0 -1
- package/dist/__tests__/workflow.test.d.ts +0 -2
- package/dist/__tests__/workflow.test.d.ts.map +0 -1
- package/dist/__tests__/workflow.test.js +0 -684
- package/dist/__tests__/workflow.test.js.map +0 -1
- package/dist/app-config-7G-3tF_I.d.cts +0 -2259
- package/dist/app-config-7G-3tF_I.d.ts +0 -2259
- package/dist/app-config-9hs8DRED.d.cts +0 -1718
- package/dist/app-config-9hs8DRED.d.ts +0 -1718
- package/dist/app-config-B3ByBjCN.d.cts +0 -2222
- package/dist/app-config-B3ByBjCN.d.ts +0 -2222
- package/dist/app-config-B5tYsZaH.d.cts +0 -2404
- package/dist/app-config-B5tYsZaH.d.ts +0 -2404
- package/dist/app-config-BEuyPktb.d.cts +0 -2556
- package/dist/app-config-BEuyPktb.d.ts +0 -2556
- package/dist/app-config-BIkjQWzU.d.cts +0 -2218
- package/dist/app-config-BIkjQWzU.d.ts +0 -2218
- package/dist/app-config-BcuZIpvL.d.cts +0 -1951
- package/dist/app-config-BcuZIpvL.d.ts +0 -1951
- package/dist/app-config-BfpeE3bF.d.cts +0 -2100
- package/dist/app-config-BfpeE3bF.d.ts +0 -2100
- package/dist/app-config-Bm9-2Am6.d.cts +0 -1875
- package/dist/app-config-Bm9-2Am6.d.ts +0 -1875
- package/dist/app-config-BqhrBrSM.d.cts +0 -1522
- package/dist/app-config-BqhrBrSM.d.ts +0 -1522
- package/dist/app-config-Bxg_DVxv.d.cts +0 -1413
- package/dist/app-config-Bxg_DVxv.d.ts +0 -1413
- package/dist/app-config-C0twGIaF.d.cts +0 -1597
- package/dist/app-config-C0twGIaF.d.ts +0 -1597
- package/dist/app-config-C0uxEU7Q.d.cts +0 -1874
- package/dist/app-config-C0uxEU7Q.d.ts +0 -1874
- package/dist/app-config-C3X5BAyK.d.cts +0 -1539
- package/dist/app-config-C3X5BAyK.d.ts +0 -1539
- package/dist/app-config-C9VJ6rTv.d.cts +0 -2092
- package/dist/app-config-C9VJ6rTv.d.ts +0 -2092
- package/dist/app-config-CBOn8IyZ.d.cts +0 -1838
- package/dist/app-config-CBOn8IyZ.d.ts +0 -1838
- package/dist/app-config-CCe-yq9q.d.cts +0 -2222
- package/dist/app-config-CCe-yq9q.d.ts +0 -2222
- package/dist/app-config-CJAGGPrk.d.cts +0 -1900
- package/dist/app-config-CJAGGPrk.d.ts +0 -1900
- package/dist/app-config-CPOs7THF.d.cts +0 -2217
- package/dist/app-config-CPOs7THF.d.ts +0 -2217
- package/dist/app-config-CYV70eoF.d.cts +0 -2100
- package/dist/app-config-CYV70eoF.d.ts +0 -2100
- package/dist/app-config-ChsrBB7p.d.cts +0 -2100
- package/dist/app-config-ChsrBB7p.d.ts +0 -2100
- package/dist/app-config-CiEDJm0e.d.cts +0 -1912
- package/dist/app-config-CiEDJm0e.d.ts +0 -1912
- package/dist/app-config-CstocO9M.d.cts +0 -1580
- package/dist/app-config-CstocO9M.d.ts +0 -1580
- package/dist/app-config-Ctp454zB.d.cts +0 -2214
- package/dist/app-config-Ctp454zB.d.ts +0 -2214
- package/dist/app-config-CwaU1de2.d.cts +0 -1868
- package/dist/app-config-CwaU1de2.d.ts +0 -1868
- package/dist/app-config-DCDh8Gbx.d.cts +0 -1926
- package/dist/app-config-DCDh8Gbx.d.ts +0 -1926
- package/dist/app-config-DCWinlNK.d.cts +0 -2091
- package/dist/app-config-DCWinlNK.d.ts +0 -2091
- package/dist/app-config-DIwvzbpe.d.cts +0 -1555
- package/dist/app-config-DIwvzbpe.d.ts +0 -1555
- package/dist/app-config-DJmNYgYh.d.cts +0 -2305
- package/dist/app-config-DJmNYgYh.d.ts +0 -2305
- package/dist/app-config-DO3laV58.d.cts +0 -2397
- package/dist/app-config-DO3laV58.d.ts +0 -2397
- package/dist/app-config-DVdSospO.d.cts +0 -1842
- package/dist/app-config-DVdSospO.d.ts +0 -1842
- package/dist/app-config-DZf_mmi9.d.cts +0 -2211
- package/dist/app-config-DZf_mmi9.d.ts +0 -2211
- package/dist/app-config-DbK2Tv6i.d.cts +0 -2080
- package/dist/app-config-DbK2Tv6i.d.ts +0 -2080
- package/dist/app-config-Dkndq5ni.d.cts +0 -1580
- package/dist/app-config-Dkndq5ni.d.ts +0 -1580
- package/dist/app-config-Dms6kvE-.d.cts +0 -2072
- package/dist/app-config-Dms6kvE-.d.ts +0 -2072
- package/dist/app-config-DqCipvSI.d.cts +0 -1411
- package/dist/app-config-DqCipvSI.d.ts +0 -1411
- package/dist/app-config-Dv5XACR4.d.cts +0 -2065
- package/dist/app-config-Dv5XACR4.d.ts +0 -2065
- package/dist/app-config-P-SF5nnR.d.cts +0 -1568
- package/dist/app-config-P-SF5nnR.d.ts +0 -1568
- package/dist/app-config-SkUoN5JU.d.cts +0 -2192
- package/dist/app-config-SkUoN5JU.d.ts +0 -2192
- package/dist/app-config-WzqpuZMr.d.cts +0 -2566
- package/dist/app-config-WzqpuZMr.d.ts +0 -2566
- package/dist/app-config-_kkj71CB.d.cts +0 -2010
- package/dist/app-config-_kkj71CB.d.ts +0 -2010
- package/dist/app-config-fEjRm1o9.d.cts +0 -2402
- package/dist/app-config-fEjRm1o9.d.ts +0 -2402
- package/dist/app-config-oU1EGHND.d.cts +0 -1538
- package/dist/app-config-oU1EGHND.d.ts +0 -1538
- package/dist/app-config-ouBRb6Bf.d.cts +0 -1716
- package/dist/app-config-ouBRb6Bf.d.ts +0 -1716
- package/dist/app-config-oz8H_MOX.d.cts +0 -2224
- package/dist/app-config-oz8H_MOX.d.ts +0 -2224
- package/dist/app-config-tITj_0sn.d.cts +0 -1926
- package/dist/app-config-tITj_0sn.d.ts +0 -1926
- package/dist/app-config-wnLtFu6c.d.cts +0 -1538
- package/dist/app-config-wnLtFu6c.d.ts +0 -1538
- package/dist/app-config-x-CnipcA.d.cts +0 -2072
- package/dist/app-config-x-CnipcA.d.ts +0 -2072
- package/dist/app.d.ts +0 -35
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -164
- package/dist/app.js.map +0 -1
- package/dist/auth/access.d.ts +0 -5
- package/dist/auth/access.d.ts.map +0 -1
- package/dist/auth/access.js +0 -59
- package/dist/auth/access.js.map +0 -1
- package/dist/auth/jexl.d.ts +0 -13
- package/dist/auth/jexl.d.ts.map +0 -1
- package/dist/auth/jexl.js +0 -30
- package/dist/auth/jexl.js.map +0 -1
- package/dist/auth/lockout.d.ts +0 -11
- package/dist/auth/lockout.d.ts.map +0 -1
- package/dist/auth/lockout.js +0 -37
- package/dist/auth/lockout.js.map +0 -1
- package/dist/auth/password.d.ts +0 -10
- package/dist/auth/password.d.ts.map +0 -1
- package/dist/auth/password.js +0 -28
- package/dist/auth/password.js.map +0 -1
- package/dist/auth/sessions.d.ts +0 -39
- package/dist/auth/sessions.d.ts.map +0 -1
- package/dist/auth/sessions.js +0 -126
- package/dist/auth/sessions.js.map +0 -1
- package/dist/auth/token.d.ts +0 -23
- package/dist/auth/token.d.ts.map +0 -1
- package/dist/auth/token.js +0 -40
- package/dist/auth/token.js.map +0 -1
- package/dist/chunk-23NM4LDU.js +0 -2883
- package/dist/chunk-2TKDCCIR.js +0 -2622
- package/dist/chunk-2UXLA4YN.js +0 -3139
- package/dist/chunk-2WODKOUB.js +0 -1627
- package/dist/chunk-35NM2WPO.js +0 -1658
- package/dist/chunk-3CMG2BH2.js +0 -1618
- package/dist/chunk-3SFITPX4.js +0 -2628
- package/dist/chunk-3TRRTN6U.js +0 -3441
- package/dist/chunk-57FNM42D.js +0 -2392
- package/dist/chunk-5U2WRCNH.js +0 -3140
- package/dist/chunk-5ZIA5COH.js +0 -3414
- package/dist/chunk-6TWQ6GTD.js +0 -3480
- package/dist/chunk-AKYYGMFS.js +0 -3365
- package/dist/chunk-AQO4HI2Y.js +0 -3204
- package/dist/chunk-BAMX7YUC.js +0 -1815
- package/dist/chunk-BQV3QW3Y.js +0 -2588
- package/dist/chunk-CQVTQ67D.js +0 -2632
- package/dist/chunk-CUOPCOU2.js +0 -1644
- package/dist/chunk-DCY7QHRB.js +0 -1637
- package/dist/chunk-DFBLNYUH.js +0 -3402
- package/dist/chunk-EH3MJGB5.js +0 -2571
- package/dist/chunk-EJG6AMYB.js +0 -3537
- package/dist/chunk-ELHRRPKX.js +0 -2863
- package/dist/chunk-EOW4YMAV.js +0 -1637
- package/dist/chunk-G43REXPX.js +0 -3147
- package/dist/chunk-GFKBPBJJ.js +0 -3637
- package/dist/chunk-HRLSFTLR.js +0 -3061
- package/dist/chunk-JFA22YFB.js +0 -1625
- package/dist/chunk-K3ASMUKV.js +0 -2601
- package/dist/chunk-KEKOEAX6.js +0 -3139
- package/dist/chunk-L65PQYDP.js +0 -1536
- package/dist/chunk-LFGSRQLX.js +0 -3568
- package/dist/chunk-M3HKRN7E.js +0 -1665
- package/dist/chunk-MQZH7RQC.js +0 -1667
- package/dist/chunk-NNZRYF3U.js +0 -3537
- package/dist/chunk-PRQ2RF5C.js +0 -3485
- package/dist/chunk-PYE2JSY4.js +0 -3568
- package/dist/chunk-PZMDK3MH.js +0 -3203
- package/dist/chunk-QCXLDKZO.js +0 -3272
- package/dist/chunk-QTIAQBNH.js +0 -3097
- package/dist/chunk-ROECUARS.js +0 -2615
- package/dist/chunk-SM32ND5M.js +0 -3472
- package/dist/chunk-T2DGC4MD.js +0 -3008
- package/dist/chunk-T626OZMH.js +0 -2602
- package/dist/chunk-TEGRS6J7.js +0 -2609
- package/dist/chunk-TLU77TLE.js +0 -3203
- package/dist/chunk-UKUEKTAO.js +0 -513
- package/dist/chunk-VCYYBN5J.js +0 -1873
- package/dist/chunk-VM43G3IG.js +0 -506
- package/dist/chunk-VWJKFZQU.js +0 -3139
- package/dist/chunk-WF5A6PDJ.js +0 -1618
- package/dist/chunk-WVD7PORQ.js +0 -1672
- package/dist/chunk-XX7N64NL.js +0 -3550
- package/dist/chunk-XZLIBQSO.js +0 -2397
- package/dist/chunk-YEBCT77K.js +0 -3269
- package/dist/chunk-YSSHLGQ6.js +0 -3139
- package/dist/chunk-YXEKNN5X.js +0 -3085
- package/dist/chunk-Z7CFUYVP.js +0 -3653
- package/dist/chunk-ZISFMAEL.js +0 -3550
- package/dist/controllers/admin-auth.controller.d.ts +0 -71
- package/dist/controllers/admin-auth.controller.d.ts.map +0 -1
- package/dist/controllers/admin-auth.controller.js +0 -450
- package/dist/controllers/admin-auth.controller.js.map +0 -1
- package/dist/controllers/audit.controller.d.ts +0 -42
- package/dist/controllers/audit.controller.d.ts.map +0 -1
- package/dist/controllers/audit.controller.js +0 -149
- package/dist/controllers/audit.controller.js.map +0 -1
- package/dist/controllers/auth.controller.d.ts +0 -143
- package/dist/controllers/auth.controller.d.ts.map +0 -1
- package/dist/controllers/auth.controller.js +0 -572
- package/dist/controllers/auth.controller.js.map +0 -1
- package/dist/controllers/collection.controller.d.ts +0 -170
- package/dist/controllers/collection.controller.d.ts.map +0 -1
- package/dist/controllers/collection.controller.js +0 -1033
- package/dist/controllers/collection.controller.js.map +0 -1
- package/dist/controllers/global.controller.d.ts +0 -20
- package/dist/controllers/global.controller.d.ts.map +0 -1
- package/dist/controllers/global.controller.js +0 -182
- package/dist/controllers/global.controller.js.map +0 -1
- package/dist/controllers/media.controller.d.ts +0 -39
- package/dist/controllers/media.controller.d.ts.map +0 -1
- package/dist/controllers/media.controller.js +0 -178
- package/dist/controllers/media.controller.js.map +0 -1
- package/dist/controllers/preview.controller.d.ts +0 -37
- package/dist/controllers/preview.controller.d.ts.map +0 -1
- package/dist/controllers/preview.controller.js +0 -48
- package/dist/controllers/preview.controller.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/middleware/auth.d.ts +0 -19
- package/dist/middleware/auth.d.ts.map +0 -1
- package/dist/middleware/auth.js +0 -157
- package/dist/middleware/auth.js.map +0 -1
- package/dist/middleware/rate-limit.d.ts +0 -9
- package/dist/middleware/rate-limit.d.ts.map +0 -1
- package/dist/middleware/rate-limit.js +0 -75
- package/dist/middleware/rate-limit.js.map +0 -1
- package/dist/network.d.ts +0 -6
- package/dist/network.d.ts.map +0 -1
- package/dist/network.js +0 -70
- package/dist/network.js.map +0 -1
- package/dist/observability-CNM4QFE4.js +0 -34
- package/dist/observability-L5BORBB2.js +0 -34
- package/dist/observability.d.ts +0 -113
- package/dist/observability.d.ts.map +0 -1
- package/dist/observability.js +0 -497
- package/dist/observability.js.map +0 -1
- package/dist/router.d.ts +0 -8
- package/dist/router.d.ts.map +0 -1
- package/dist/router.js +0 -704
- package/dist/router.js.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/services/audit.service.d.ts +0 -23
- package/dist/services/audit.service.d.ts.map +0 -1
- package/dist/services/audit.service.js +0 -39
- package/dist/services/audit.service.js.map +0 -1
- package/dist/services/defaults.service.d.ts +0 -8
- package/dist/services/defaults.service.d.ts.map +0 -1
- package/dist/services/defaults.service.js +0 -55
- package/dist/services/defaults.service.js.map +0 -1
- package/dist/services/email-template.d.ts +0 -46
- package/dist/services/email-template.d.ts.map +0 -1
- package/dist/services/email-template.js +0 -88
- package/dist/services/email-template.js.map +0 -1
- package/dist/services/email.service.d.ts +0 -34
- package/dist/services/email.service.d.ts.map +0 -1
- package/dist/services/email.service.js +0 -129
- package/dist/services/email.service.js.map +0 -1
- package/dist/services/media.service.d.ts +0 -20
- package/dist/services/media.service.d.ts.map +0 -1
- package/dist/services/media.service.js +0 -49
- package/dist/services/media.service.js.map +0 -1
- package/dist/services/population.service.d.ts +0 -20
- package/dist/services/population.service.d.ts.map +0 -1
- package/dist/services/population.service.js +0 -224
- package/dist/services/population.service.js.map +0 -1
- package/dist/types/access.d.ts +0 -48
- package/dist/types/access.d.ts.map +0 -1
- package/dist/types/access.js +0 -2
- package/dist/types/access.js.map +0 -1
- package/dist/types/adapters.d.ts +0 -152
- package/dist/types/adapters.d.ts.map +0 -1
- package/dist/types/adapters.js +0 -2
- package/dist/types/adapters.js.map +0 -1
- package/dist/types/admin-auth.d.ts +0 -132
- package/dist/types/admin-auth.d.ts.map +0 -1
- package/dist/types/admin-auth.js +0 -2
- package/dist/types/admin-auth.js.map +0 -1
- package/dist/types/admin.d.ts +0 -86
- package/dist/types/admin.d.ts.map +0 -1
- package/dist/types/admin.js +0 -2
- package/dist/types/admin.js.map +0 -1
- package/dist/types/app-config.d.ts +0 -279
- package/dist/types/app-config.d.ts.map +0 -1
- package/dist/types/app-config.js +0 -2
- package/dist/types/app-config.js.map +0 -1
- package/dist/types/documents.d.ts +0 -65
- package/dist/types/documents.d.ts.map +0 -1
- package/dist/types/documents.js +0 -2
- package/dist/types/documents.js.map +0 -1
- package/dist/types/hooks.d.ts +0 -122
- package/dist/types/hooks.d.ts.map +0 -1
- package/dist/types/hooks.js +0 -2
- package/dist/types/hooks.js.map +0 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -13
- package/dist/types/index.js.map +0 -1
- package/dist/types/request.d.ts +0 -42
- package/dist/types/request.d.ts.map +0 -1
- package/dist/types/request.js +0 -2
- package/dist/types/request.js.map +0 -1
- package/dist/types/schema-config.d.ts +0 -443
- package/dist/types/schema-config.d.ts.map +0 -1
- package/dist/types/schema-config.js +0 -2
- package/dist/types/schema-config.js.map +0 -1
- package/dist/types/schema-core.d.ts +0 -628
- package/dist/types/schema-core.d.ts.map +0 -1
- package/dist/types/schema-core.js +0 -2
- package/dist/types/schema-core.js.map +0 -1
- package/dist/types/schema-inference.d.ts +0 -73
- package/dist/types/schema-inference.d.ts.map +0 -1
- package/dist/types/schema-inference.js +0 -2
- package/dist/types/schema-inference.js.map +0 -1
- package/dist/types/workflows.d.ts +0 -121
- package/dist/types/workflows.d.ts.map +0 -1
- package/dist/types/workflows.js +0 -7
- package/dist/types/workflows.js.map +0 -1
- package/dist/utils/access-control.d.ts +0 -35
- package/dist/utils/access-control.d.ts.map +0 -1
- package/dist/utils/access-control.js +0 -161
- package/dist/utils/access-control.js.map +0 -1
- package/dist/utils/admin-auth.d.ts +0 -5
- package/dist/utils/admin-auth.d.ts.map +0 -1
- package/dist/utils/admin-auth.js +0 -39
- package/dist/utils/admin-auth.js.map +0 -1
- package/dist/utils/block-references.d.ts +0 -10
- package/dist/utils/block-references.d.ts.map +0 -1
- package/dist/utils/block-references.js +0 -100
- package/dist/utils/block-references.js.map +0 -1
- package/dist/utils/collection-search.d.ts +0 -11
- package/dist/utils/collection-search.d.ts.map +0 -1
- package/dist/utils/collection-search.js +0 -204
- package/dist/utils/collection-search.js.map +0 -1
- package/dist/utils/config.d.ts +0 -8
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -336
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/hooks.d.ts +0 -41
- package/dist/utils/hooks.d.ts.map +0 -1
- package/dist/utils/hooks.js +0 -177
- package/dist/utils/hooks.js.map +0 -1
- package/dist/utils/openapi.d.ts +0 -6
- package/dist/utils/openapi.d.ts.map +0 -1
- package/dist/utils/openapi.js +0 -981
- package/dist/utils/openapi.js.map +0 -1
- package/dist/utils/parse-sort.d.ts +0 -43
- package/dist/utils/parse-sort.d.ts.map +0 -1
- package/dist/utils/parse-sort.js +0 -70
- package/dist/utils/parse-sort.js.map +0 -1
- package/dist/utils/parse-where.d.ts +0 -69
- package/dist/utils/parse-where.d.ts.map +0 -1
- package/dist/utils/parse-where.js +0 -202
- package/dist/utils/parse-where.js.map +0 -1
- package/dist/utils/readonly-db.d.ts +0 -9
- package/dist/utils/readonly-db.d.ts.map +0 -1
- package/dist/utils/readonly-db.js +0 -21
- package/dist/utils/readonly-db.js.map +0 -1
- package/dist/utils/swagger.d.ts +0 -11
- package/dist/utils/swagger.d.ts.map +0 -1
- package/dist/utils/swagger.js +0 -62
- package/dist/utils/swagger.js.map +0 -1
- package/dist/utils/upload-validation.d.ts +0 -23
- package/dist/utils/upload-validation.d.ts.map +0 -1
- package/dist/utils/upload-validation.js +0 -46
- package/dist/utils/upload-validation.js.map +0 -1
- package/dist/utils/where-sanitizer.d.ts +0 -10
- package/dist/utils/where-sanitizer.d.ts.map +0 -1
- package/dist/utils/where-sanitizer.js +0 -67
- package/dist/utils/where-sanitizer.js.map +0 -1
- package/dist/workflows.d.ts +0 -86
- package/dist/workflows.d.ts.map +0 -1
- package/dist/workflows.js +0 -405
- package/dist/workflows.js.map +0 -1
package/dist/chunk-6TWQ6GTD.js
DELETED
|
@@ -1,3480 +0,0 @@
|
|
|
1
|
-
// src/workflows.ts
|
|
2
|
-
var WORKFLOW_HISTORY_COLLECTION = "__workflow_history";
|
|
3
|
-
var LIFECYCLE_EVENTS_COLLECTION = "__lifecycle_events";
|
|
4
|
-
var EDITOR_CAPABILITIES = ["entry.edit", "entry.submit"];
|
|
5
|
-
var PUBLISHER_CAPABILITIES = ["entry.edit", "entry.submit", "entry.publish", "entry.unpublish"];
|
|
6
|
-
function definePublishingWorkflow(options = {}) {
|
|
7
|
-
const editors = options.editors ?? ["editor"];
|
|
8
|
-
const publishers = options.publishers ?? ["publisher", "admin"];
|
|
9
|
-
return {
|
|
10
|
-
initialState: "draft",
|
|
11
|
-
draftState: "draft",
|
|
12
|
-
states: [
|
|
13
|
-
{ name: "draft", label: "Draft", color: "neutral" },
|
|
14
|
-
{ name: "in_review", label: "In review", color: "warning" },
|
|
15
|
-
{ name: "published", label: "Published", color: "success", published: true }
|
|
16
|
-
],
|
|
17
|
-
transitions: [
|
|
18
|
-
{
|
|
19
|
-
name: "submit",
|
|
20
|
-
label: "Submit for review",
|
|
21
|
-
from: "draft",
|
|
22
|
-
to: "in_review",
|
|
23
|
-
requiredCapabilities: ["entry.submit"]
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "publish",
|
|
27
|
-
label: "Publish",
|
|
28
|
-
from: "in_review",
|
|
29
|
-
to: "published",
|
|
30
|
-
requiredCapabilities: ["entry.publish"]
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: "reject",
|
|
34
|
-
label: "Request changes",
|
|
35
|
-
from: "in_review",
|
|
36
|
-
to: "draft",
|
|
37
|
-
requiredCapabilities: ["entry.publish"],
|
|
38
|
-
requireComment: true
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: "unpublish",
|
|
42
|
-
label: "Unpublish",
|
|
43
|
-
from: "published",
|
|
44
|
-
to: "draft",
|
|
45
|
-
requiredCapabilities: ["entry.unpublish"],
|
|
46
|
-
unpublish: true
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
roles: [
|
|
50
|
-
...editors.map((role) => ({ role, capabilities: [...EDITOR_CAPABILITIES] })),
|
|
51
|
-
...publishers.map((role) => ({ role, capabilities: [...PUBLISHER_CAPABILITIES] }))
|
|
52
|
-
]
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function publishingWorkflow() {
|
|
56
|
-
return definePublishingWorkflow();
|
|
57
|
-
}
|
|
58
|
-
function simplePublishingWorkflow() {
|
|
59
|
-
return {
|
|
60
|
-
initialState: "draft",
|
|
61
|
-
draftState: "draft",
|
|
62
|
-
states: [
|
|
63
|
-
{ name: "draft", label: "Draft", color: "neutral" },
|
|
64
|
-
{ name: "published", label: "Published", color: "success", published: true }
|
|
65
|
-
],
|
|
66
|
-
transitions: [
|
|
67
|
-
{ name: "publish", label: "Publish", from: ["draft", "published"], to: "published" },
|
|
68
|
-
{ name: "unpublish", label: "Unpublish", from: "published", to: "draft", unpublish: true }
|
|
69
|
-
]
|
|
70
|
-
// Intentionally no `roles`: this lightweight workflow (synthesized from
|
|
71
|
-
// `drafts: true`) does no capability-based gating. Draft visibility for a
|
|
72
|
-
// no-roles workflow is handled in `canViewWorkflowDraft`.
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function publicMetadata(meta) {
|
|
76
|
-
const { availableTransitions: _availableTransitions, ...safe } = meta;
|
|
77
|
-
return safe;
|
|
78
|
-
}
|
|
79
|
-
function workflowCapabilities(workflow, user) {
|
|
80
|
-
const capabilities = new Set(Array.isArray(user?.capabilities) ? user.capabilities : []);
|
|
81
|
-
const roles = Array.isArray(user?.roles) ? user.roles : [];
|
|
82
|
-
for (const mapping of workflow.roles ?? []) {
|
|
83
|
-
if (roles.includes(mapping.role)) mapping.capabilities.forEach((capability) => capabilities.add(capability));
|
|
84
|
-
}
|
|
85
|
-
return capabilities;
|
|
86
|
-
}
|
|
87
|
-
function canViewWorkflowDraft(workflow, user) {
|
|
88
|
-
if (!user) return false;
|
|
89
|
-
const capabilities = workflowCapabilities(workflow, user);
|
|
90
|
-
if (capabilities.has("entry.edit")) return true;
|
|
91
|
-
if (workflow.transitions.some(
|
|
92
|
-
(transition) => (transition.requiredCapabilities ?? []).some((capability) => capabilities.has(capability))
|
|
93
|
-
)) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
if (!workflow.roles || workflow.roles.length === 0) return true;
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
function availableWorkflowTransitions(workflow, state, user) {
|
|
100
|
-
const capabilities = workflowCapabilities(workflow, user);
|
|
101
|
-
return workflow.transitions.filter((transition) => {
|
|
102
|
-
const from = Array.isArray(transition.from) ? transition.from : [transition.from];
|
|
103
|
-
return from.includes(state) && (transition.requiredCapabilities ?? []).every((item) => capabilities.has(item));
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function initializeWorkflowDocument(data, workflow) {
|
|
107
|
-
return {
|
|
108
|
-
...data,
|
|
109
|
-
__workflow: { state: workflow.initialState, revision: 1 }
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function publishedStateName(workflow) {
|
|
113
|
-
return workflow.states.find((state) => state.published)?.name ?? workflow.states[workflow.states.length - 1]?.name ?? workflow.initialState;
|
|
114
|
-
}
|
|
115
|
-
function materializeWorkflowDocument(doc, workflow, user) {
|
|
116
|
-
const meta = doc.__workflow;
|
|
117
|
-
const publishedState = publishedStateName(workflow);
|
|
118
|
-
if (!meta) {
|
|
119
|
-
const { __published: _legacyPublished, __workflow: _legacyWorkflow, ...working2 } = doc;
|
|
120
|
-
const state = publishedStateName(workflow);
|
|
121
|
-
return {
|
|
122
|
-
...working2,
|
|
123
|
-
_workflow: {
|
|
124
|
-
state,
|
|
125
|
-
revision: 1,
|
|
126
|
-
availableTransitions: availableWorkflowTransitions(workflow, state, user).map((item) => item.name)
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
const { __published, __workflow, ...working } = doc;
|
|
131
|
-
if (!canViewWorkflowDraft(workflow, user)) {
|
|
132
|
-
if (!__published || typeof __published !== "object") {
|
|
133
|
-
if (meta.state === publishedState) {
|
|
134
|
-
return { ...working, _workflow: publicMetadata(meta) };
|
|
135
|
-
}
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
return { id: doc.id, ...__published, _workflow: publicMetadata(meta) };
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
...working,
|
|
142
|
-
_workflow: {
|
|
143
|
-
...meta,
|
|
144
|
-
availableTransitions: availableWorkflowTransitions(workflow, meta.state, user).map((item) => item.name)
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function eventId() {
|
|
149
|
-
return globalThis.crypto?.randomUUID?.() ?? `evt_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
150
|
-
}
|
|
151
|
-
function createLifecycleEvent(args) {
|
|
152
|
-
return {
|
|
153
|
-
id: eventId(),
|
|
154
|
-
name: args.name,
|
|
155
|
-
collection: args.collection,
|
|
156
|
-
documentId: args.documentId,
|
|
157
|
-
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
158
|
-
actorId: args.actorId,
|
|
159
|
-
payload: args.payload,
|
|
160
|
-
attempts: 0,
|
|
161
|
-
status: "pending"
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
async function persistEvent(db, event) {
|
|
165
|
-
await db.create({ collection: LIFECYCLE_EVENTS_COLLECTION, data: event });
|
|
166
|
-
}
|
|
167
|
-
async function dispatchLifecycleEvent(config, event) {
|
|
168
|
-
const db = config.db;
|
|
169
|
-
if (!db || !config.events?.handlers.length) return;
|
|
170
|
-
const maxAttempts = config.events.maxAttempts ?? 8;
|
|
171
|
-
const retryDelayMs = config.events.retryDelayMs ?? 1e3;
|
|
172
|
-
const attempts = event.attempts + 1;
|
|
173
|
-
try {
|
|
174
|
-
await db.update({
|
|
175
|
-
collection: LIFECYCLE_EVENTS_COLLECTION,
|
|
176
|
-
id: event.id,
|
|
177
|
-
data: { status: "processing", attempts }
|
|
178
|
-
});
|
|
179
|
-
for (const handler of config.events.handlers) await handler({ ...event, status: "processing", attempts });
|
|
180
|
-
await db.update({
|
|
181
|
-
collection: LIFECYCLE_EVENTS_COLLECTION,
|
|
182
|
-
id: event.id,
|
|
183
|
-
data: { status: "delivered", attempts, deliveredAt: (/* @__PURE__ */ new Date()).toISOString(), lastError: null }
|
|
184
|
-
});
|
|
185
|
-
} catch (error) {
|
|
186
|
-
const exhausted = attempts >= maxAttempts;
|
|
187
|
-
await db.update({
|
|
188
|
-
collection: LIFECYCLE_EVENTS_COLLECTION,
|
|
189
|
-
id: event.id,
|
|
190
|
-
data: {
|
|
191
|
-
status: "failed",
|
|
192
|
-
attempts,
|
|
193
|
-
lastError: error instanceof Error ? error.message : String(error),
|
|
194
|
-
nextAttemptAt: exhausted ? null : new Date(Date.now() + retryDelayMs * 2 ** (attempts - 1)).toISOString()
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async function dispatchPendingLifecycleEvents(config, limit = 50) {
|
|
200
|
-
if (!config.db || !config.events?.handlers.length) return 0;
|
|
201
|
-
const maxAttempts = config.events.maxAttempts ?? 8;
|
|
202
|
-
const result = await config.db.find({
|
|
203
|
-
collection: LIFECYCLE_EVENTS_COLLECTION,
|
|
204
|
-
where: { status: { in: ["pending", "failed"] } },
|
|
205
|
-
sort: "occurredAt",
|
|
206
|
-
limit
|
|
207
|
-
});
|
|
208
|
-
const now2 = Date.now();
|
|
209
|
-
const due = result.docs.filter(
|
|
210
|
-
(doc) => Number(doc.attempts ?? 0) < maxAttempts && (!doc.nextAttemptAt || new Date(doc.nextAttemptAt).getTime() <= now2)
|
|
211
|
-
);
|
|
212
|
-
for (const event of due) await dispatchLifecycleEvent(config, event);
|
|
213
|
-
return due.length;
|
|
214
|
-
}
|
|
215
|
-
async function saveWorkflowDraft(args) {
|
|
216
|
-
const { config, collection, id, originalDoc, data, user } = args;
|
|
217
|
-
const db = config.db;
|
|
218
|
-
const workflow = collection.workflow;
|
|
219
|
-
if (!db.transaction) throw new Error(`The configured database adapter does not support workflow transactions.`);
|
|
220
|
-
const previous = originalDoc.__workflow;
|
|
221
|
-
const isLegacyPublishedDoc = !previous;
|
|
222
|
-
const baselineRevision = previous?.revision ?? 1;
|
|
223
|
-
const event = createLifecycleEvent({
|
|
224
|
-
name: "revision.created",
|
|
225
|
-
collection: collection.slug,
|
|
226
|
-
documentId: id,
|
|
227
|
-
actorId: user?.sub,
|
|
228
|
-
payload: {
|
|
229
|
-
revision: baselineRevision + 1,
|
|
230
|
-
previousRevision: isLegacyPublishedDoc ? baselineRevision : previous?.revision ?? null
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
const doc = await db.transaction(async (tx) => {
|
|
234
|
-
const nextMeta = {
|
|
235
|
-
...previous ?? {},
|
|
236
|
-
state: isLegacyPublishedDoc ? workflow.draftState ?? workflow.initialState : originalDoc.__published ? workflow.draftState ?? workflow.initialState : previous.state,
|
|
237
|
-
revision: baselineRevision + 1,
|
|
238
|
-
...isLegacyPublishedDoc ? { publishedRevision: baselineRevision } : {}
|
|
239
|
-
};
|
|
240
|
-
const updateData = {
|
|
241
|
-
...data,
|
|
242
|
-
__workflow: nextMeta
|
|
243
|
-
};
|
|
244
|
-
if (isLegacyPublishedDoc) {
|
|
245
|
-
const { __workflow: _legacyWorkflow, __published: _legacyPublished, ...publishedSnapshot } = originalDoc;
|
|
246
|
-
updateData.__published = publishedSnapshot;
|
|
247
|
-
}
|
|
248
|
-
const updated = await tx.update({ collection: collection.slug, id, data: updateData });
|
|
249
|
-
await persistEvent(tx, event);
|
|
250
|
-
return updated;
|
|
251
|
-
});
|
|
252
|
-
void dispatchLifecycleEvent(config, event);
|
|
253
|
-
return { doc, event };
|
|
254
|
-
}
|
|
255
|
-
async function createWorkflowDocument(args) {
|
|
256
|
-
const { config, collection, data, user } = args;
|
|
257
|
-
const db = config.db;
|
|
258
|
-
if (!db.transaction) throw new Error(`The configured database adapter does not support workflow transactions.`);
|
|
259
|
-
let event;
|
|
260
|
-
const doc = await db.transaction(async (tx) => {
|
|
261
|
-
const created = await tx.create({ collection: collection.slug, data });
|
|
262
|
-
event = createLifecycleEvent({
|
|
263
|
-
name: "revision.created",
|
|
264
|
-
collection: collection.slug,
|
|
265
|
-
documentId: created.id,
|
|
266
|
-
actorId: user?.sub,
|
|
267
|
-
payload: { revision: 1, previousRevision: null }
|
|
268
|
-
});
|
|
269
|
-
await persistEvent(tx, event);
|
|
270
|
-
return created;
|
|
271
|
-
});
|
|
272
|
-
void dispatchLifecycleEvent(config, event);
|
|
273
|
-
return { doc, event };
|
|
274
|
-
}
|
|
275
|
-
async function transitionWorkflow(args) {
|
|
276
|
-
const { config, collection, id, transitionName, expectedRevision, comment, user, req } = args;
|
|
277
|
-
const db = config.db;
|
|
278
|
-
const workflow = collection.workflow;
|
|
279
|
-
if (!db.transaction) throw new Error(`The configured database adapter does not support workflow transactions.`);
|
|
280
|
-
const original = await db.findOne({ collection: collection.slug, id });
|
|
281
|
-
if (!original) throw Object.assign(new Error("Not Found"), { statusCode: 404 });
|
|
282
|
-
const meta = original.__workflow;
|
|
283
|
-
if (!meta) throw Object.assign(new Error("Entry has no workflow metadata"), { statusCode: 409 });
|
|
284
|
-
if (expectedRevision !== void 0 && expectedRevision !== meta.revision) {
|
|
285
|
-
throw Object.assign(new Error("This entry changed since it was loaded. Refresh before transitioning it."), {
|
|
286
|
-
statusCode: 409
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
const transition = workflow.transitions.find((item) => item.name === transitionName);
|
|
290
|
-
const fromStates = transition ? Array.isArray(transition.from) ? transition.from : [transition.from] : [];
|
|
291
|
-
if (!transition || !fromStates.includes(meta.state)) {
|
|
292
|
-
throw Object.assign(new Error(`Transition "${transitionName}" is not valid from "${meta.state}".`), {
|
|
293
|
-
statusCode: 409
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
if (!availableWorkflowTransitions(workflow, meta.state, user).some((item) => item.name === transition.name)) {
|
|
297
|
-
throw Object.assign(new Error(`You do not have permission to perform "${transition.label}".`), { statusCode: 403 });
|
|
298
|
-
}
|
|
299
|
-
if (transition.requireComment && !comment?.trim()) {
|
|
300
|
-
throw Object.assign(new Error(`A comment is required for "${transition.label}".`), { statusCode: 400 });
|
|
301
|
-
}
|
|
302
|
-
const hookContext = { transition, from: meta.state, to: transition.to, doc: original, user, comment, req, db };
|
|
303
|
-
for (const hook of workflow.hooks?.beforeTransition ?? []) await hook(hookContext);
|
|
304
|
-
const events = [
|
|
305
|
-
createLifecycleEvent({
|
|
306
|
-
name: "workflow.transitioned",
|
|
307
|
-
collection: collection.slug,
|
|
308
|
-
documentId: id,
|
|
309
|
-
actorId: user?.sub,
|
|
310
|
-
payload: { transition: transition.name, from: meta.state, to: transition.to, revision: meta.revision, comment }
|
|
311
|
-
})
|
|
312
|
-
];
|
|
313
|
-
const targetState = workflow.states.find((state) => state.name === transition.to);
|
|
314
|
-
if (targetState.published) {
|
|
315
|
-
events.push(
|
|
316
|
-
createLifecycleEvent({
|
|
317
|
-
name: "entry.published",
|
|
318
|
-
collection: collection.slug,
|
|
319
|
-
documentId: id,
|
|
320
|
-
actorId: user?.sub,
|
|
321
|
-
payload: { revision: meta.revision }
|
|
322
|
-
})
|
|
323
|
-
);
|
|
324
|
-
} else if (transition.unpublish) {
|
|
325
|
-
events.push(
|
|
326
|
-
createLifecycleEvent({
|
|
327
|
-
name: "entry.unpublished",
|
|
328
|
-
collection: collection.slug,
|
|
329
|
-
documentId: id,
|
|
330
|
-
actorId: user?.sub,
|
|
331
|
-
payload: { revision: meta.publishedRevision }
|
|
332
|
-
})
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
const updated = await db.transaction(async (tx) => {
|
|
336
|
-
const locked = await tx.findOne({ collection: collection.slug, id });
|
|
337
|
-
if (!locked) throw Object.assign(new Error("Not Found"), { statusCode: 404 });
|
|
338
|
-
const lockedMeta = locked.__workflow;
|
|
339
|
-
if (lockedMeta.revision !== meta.revision || lockedMeta.state !== meta.state || expectedRevision !== void 0 && lockedMeta.revision !== expectedRevision) {
|
|
340
|
-
throw Object.assign(new Error("This entry changed since it was loaded. Refresh before transitioning it."), {
|
|
341
|
-
statusCode: 409
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
345
|
-
const { __published: _published, __workflow: _workflow, id: _id, ...working } = locked;
|
|
346
|
-
const nextMeta = {
|
|
347
|
-
...lockedMeta,
|
|
348
|
-
state: transition.to,
|
|
349
|
-
...targetState.published ? { publishedRevision: lockedMeta.revision, publishedAt: now2, publishedBy: user?.sub } : {},
|
|
350
|
-
...transition.unpublish ? { publishedRevision: void 0, publishedAt: void 0, publishedBy: void 0 } : {}
|
|
351
|
-
};
|
|
352
|
-
const data = { __workflow: nextMeta };
|
|
353
|
-
if (targetState.published) data.__published = working;
|
|
354
|
-
if (transition.unpublish) data.__published = null;
|
|
355
|
-
const next = await tx.update({ collection: collection.slug, id, data });
|
|
356
|
-
await tx.create({
|
|
357
|
-
collection: WORKFLOW_HISTORY_COLLECTION,
|
|
358
|
-
data: {
|
|
359
|
-
collection: collection.slug,
|
|
360
|
-
documentId: id,
|
|
361
|
-
transition: transition.name,
|
|
362
|
-
from: lockedMeta.state,
|
|
363
|
-
to: transition.to,
|
|
364
|
-
revision: lockedMeta.revision,
|
|
365
|
-
comment: comment ?? null,
|
|
366
|
-
actorId: user?.sub ?? null,
|
|
367
|
-
createdAt: now2
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
for (const event of events) await persistEvent(tx, event);
|
|
371
|
-
if (collection.audit) {
|
|
372
|
-
await tx.create({
|
|
373
|
-
collection: "__audit",
|
|
374
|
-
data: {
|
|
375
|
-
collection: collection.slug,
|
|
376
|
-
documentId: id,
|
|
377
|
-
operation: "workflow.transition",
|
|
378
|
-
user: user?.sub ?? null,
|
|
379
|
-
timestamp: now2,
|
|
380
|
-
changes: JSON.stringify({
|
|
381
|
-
transition: transition.name,
|
|
382
|
-
from: lockedMeta.state,
|
|
383
|
-
to: transition.to,
|
|
384
|
-
revision: lockedMeta.revision
|
|
385
|
-
})
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
return next;
|
|
390
|
-
});
|
|
391
|
-
for (const event of events) void dispatchLifecycleEvent(config, event);
|
|
392
|
-
for (const hook of workflow.hooks?.afterTransition ?? []) {
|
|
393
|
-
try {
|
|
394
|
-
await hook({ ...hookContext, doc: updated, event: events[0] });
|
|
395
|
-
} catch (error) {
|
|
396
|
-
try {
|
|
397
|
-
const { getConfigLogger, getObservabilityRuntime } = await import("./observability-KCMTV7GO.js");
|
|
398
|
-
getObservabilityRuntime(config)?.recordWorkflowHookFailure({
|
|
399
|
-
collection: collection.slug,
|
|
400
|
-
transition: transition.name
|
|
401
|
-
});
|
|
402
|
-
getConfigLogger(config, "workflow").error({
|
|
403
|
-
err: error,
|
|
404
|
-
msg: "afterTransition hook failed",
|
|
405
|
-
collection: collection.slug,
|
|
406
|
-
transition: transition.name,
|
|
407
|
-
documentId: id
|
|
408
|
-
});
|
|
409
|
-
} catch {
|
|
410
|
-
console.error("afterTransition hook failed:", error);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return updated;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// src/utils/admin-auth.ts
|
|
418
|
-
function getAdminAuthCollection(config) {
|
|
419
|
-
const adminCollection = resolveAdminAuthCollection(config.collections, config.adminAuth?.collectionSlug);
|
|
420
|
-
return adminCollection ?? null;
|
|
421
|
-
}
|
|
422
|
-
function resolveAdminAuthCollection(collections, collectionSlug) {
|
|
423
|
-
const adminsCollection = collections.find((collection) => collection.slug === "__admins");
|
|
424
|
-
if (adminsCollection) return adminsCollection;
|
|
425
|
-
if (collectionSlug) {
|
|
426
|
-
const requestedCollection = collections.find((collection) => collection.slug === collectionSlug);
|
|
427
|
-
if (requestedCollection) return requestedCollection;
|
|
428
|
-
}
|
|
429
|
-
return collections.find((collection) => collection.auth);
|
|
430
|
-
}
|
|
431
|
-
function getPublicAdminAuthConfig(adminAuth, collections) {
|
|
432
|
-
const providers = (adminAuth?.providers ?? []).map((provider) => ({
|
|
433
|
-
id: provider.id,
|
|
434
|
-
type: provider.type,
|
|
435
|
-
displayName: provider.displayName || humanizeProviderName(provider.id, provider.type),
|
|
436
|
-
autoRedirect: provider.autoRedirect
|
|
437
|
-
}));
|
|
438
|
-
const resolvedCollectionSlug = collections ? resolveAdminAuthCollection(collections, adminAuth?.collectionSlug)?.slug : adminAuth?.collectionSlug;
|
|
439
|
-
return {
|
|
440
|
-
mode: adminAuth?.mode ?? "local",
|
|
441
|
-
collectionSlug: resolvedCollectionSlug,
|
|
442
|
-
provisioningMode: adminAuth?.provisioningMode,
|
|
443
|
-
providers
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
function humanizeProviderName(id, type) {
|
|
447
|
-
const cleaned = id.replace(/[-_]+/g, " ").trim();
|
|
448
|
-
if (!cleaned) return type.toUpperCase();
|
|
449
|
-
return cleaned.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// src/utils/jexl-helpers.ts
|
|
453
|
-
import jexl from "jexl";
|
|
454
|
-
function slugify(val) {
|
|
455
|
-
if (val === void 0 || val === null) return "";
|
|
456
|
-
return String(val).normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
457
|
-
}
|
|
458
|
-
function lower(val) {
|
|
459
|
-
if (val === void 0 || val === null) return "";
|
|
460
|
-
return String(val).toLowerCase();
|
|
461
|
-
}
|
|
462
|
-
function upper(val) {
|
|
463
|
-
if (val === void 0 || val === null) return "";
|
|
464
|
-
return String(val).toUpperCase();
|
|
465
|
-
}
|
|
466
|
-
function trim(val) {
|
|
467
|
-
if (val === void 0 || val === null) return "";
|
|
468
|
-
return String(val).trim();
|
|
469
|
-
}
|
|
470
|
-
function capitalize(val) {
|
|
471
|
-
if (val === void 0 || val === null) return "";
|
|
472
|
-
const str = String(val).trim();
|
|
473
|
-
if (!str) return "";
|
|
474
|
-
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
475
|
-
}
|
|
476
|
-
function truncate(val, length2, ellipsis = "...") {
|
|
477
|
-
if (val === void 0 || val === null) return "";
|
|
478
|
-
const str = String(val);
|
|
479
|
-
const maxLen = typeof length2 === "number" && length2 > 0 ? length2 : 100;
|
|
480
|
-
if (str.length <= maxLen) return str;
|
|
481
|
-
return str.slice(0, maxLen).trim() + String(ellipsis ?? "...");
|
|
482
|
-
}
|
|
483
|
-
function readingTime(val, wpm = 200) {
|
|
484
|
-
if (val === void 0 || val === null) return 1;
|
|
485
|
-
const str = String(val).trim();
|
|
486
|
-
if (!str) return 1;
|
|
487
|
-
const words = str.split(/\s+/).filter(Boolean).length;
|
|
488
|
-
return Math.max(1, Math.ceil(words / (typeof wpm === "number" && wpm > 0 ? wpm : 200)));
|
|
489
|
-
}
|
|
490
|
-
function wordCount(val) {
|
|
491
|
-
if (val === void 0 || val === null) return 0;
|
|
492
|
-
const str = String(val).trim();
|
|
493
|
-
if (!str) return 0;
|
|
494
|
-
return str.split(/\s+/).filter(Boolean).length;
|
|
495
|
-
}
|
|
496
|
-
function replace(val, search, replacement) {
|
|
497
|
-
if (val === void 0 || val === null) return "";
|
|
498
|
-
return String(val).replace(new RegExp(String(search || ""), "g"), String(replacement ?? ""));
|
|
499
|
-
}
|
|
500
|
-
function startsWith(str, prefix) {
|
|
501
|
-
if (str === void 0 || str === null) return false;
|
|
502
|
-
return String(str).startsWith(String(prefix ?? ""));
|
|
503
|
-
}
|
|
504
|
-
function endsWith(str, suffix) {
|
|
505
|
-
if (str === void 0 || str === null) return false;
|
|
506
|
-
return String(str).endsWith(String(suffix ?? ""));
|
|
507
|
-
}
|
|
508
|
-
function now() {
|
|
509
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
510
|
-
}
|
|
511
|
-
function today() {
|
|
512
|
-
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
513
|
-
}
|
|
514
|
-
function formatDate(val, style = "short") {
|
|
515
|
-
if (!val) return "";
|
|
516
|
-
const d = new Date(val);
|
|
517
|
-
if (Number.isNaN(d.getTime())) return "";
|
|
518
|
-
const styleStr = String(style).toLowerCase();
|
|
519
|
-
if (styleStr === "iso" || styleStr === "date") return d.toISOString().slice(0, 10);
|
|
520
|
-
if (styleStr === "datetime" || styleStr === "full") return d.toISOString();
|
|
521
|
-
return d.toLocaleDateString("en-US", {
|
|
522
|
-
year: "numeric",
|
|
523
|
-
month: "short",
|
|
524
|
-
day: "numeric"
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
function addDays(val, days) {
|
|
528
|
-
const d = val ? new Date(val) : /* @__PURE__ */ new Date();
|
|
529
|
-
if (Number.isNaN(d.getTime())) return "";
|
|
530
|
-
const daysNum = typeof days === "number" ? days : Number(days) || 0;
|
|
531
|
-
d.setDate(d.getDate() + daysNum);
|
|
532
|
-
return d.toISOString();
|
|
533
|
-
}
|
|
534
|
-
function diffDays(dateA, dateB) {
|
|
535
|
-
const dA = dateA ? new Date(dateA) : /* @__PURE__ */ new Date();
|
|
536
|
-
const dB = dateB ? new Date(dateB) : /* @__PURE__ */ new Date();
|
|
537
|
-
if (Number.isNaN(dA.getTime()) || Number.isNaN(dB.getTime())) return 0;
|
|
538
|
-
const diffMs = Math.abs(dA.getTime() - dB.getTime());
|
|
539
|
-
return Math.floor(diffMs / (1e3 * 60 * 60 * 24));
|
|
540
|
-
}
|
|
541
|
-
function isPast(val) {
|
|
542
|
-
if (!val) return false;
|
|
543
|
-
const d = new Date(val);
|
|
544
|
-
if (Number.isNaN(d.getTime())) return false;
|
|
545
|
-
return d.getTime() < Date.now();
|
|
546
|
-
}
|
|
547
|
-
function isFuture(val) {
|
|
548
|
-
if (!val) return false;
|
|
549
|
-
const d = new Date(val);
|
|
550
|
-
if (Number.isNaN(d.getTime())) return false;
|
|
551
|
-
return d.getTime() > Date.now();
|
|
552
|
-
}
|
|
553
|
-
function includes(arrOrStr, item) {
|
|
554
|
-
if (Array.isArray(arrOrStr)) {
|
|
555
|
-
return arrOrStr.includes(item);
|
|
556
|
-
}
|
|
557
|
-
if (typeof arrOrStr === "string") {
|
|
558
|
-
return arrOrStr.includes(String(item ?? ""));
|
|
559
|
-
}
|
|
560
|
-
return false;
|
|
561
|
-
}
|
|
562
|
-
function join(arr, separator = ", ") {
|
|
563
|
-
if (!Array.isArray(arr)) return "";
|
|
564
|
-
return arr.filter((item) => item !== void 0 && item !== null).join(String(separator));
|
|
565
|
-
}
|
|
566
|
-
function first(arr) {
|
|
567
|
-
if (Array.isArray(arr)) return arr[0] ?? null;
|
|
568
|
-
return null;
|
|
569
|
-
}
|
|
570
|
-
function last(arr) {
|
|
571
|
-
if (Array.isArray(arr)) return arr[arr.length - 1] ?? null;
|
|
572
|
-
return null;
|
|
573
|
-
}
|
|
574
|
-
function compact(arr) {
|
|
575
|
-
if (!Array.isArray(arr)) return [];
|
|
576
|
-
return arr.filter((item) => item !== void 0 && item !== null && item !== "");
|
|
577
|
-
}
|
|
578
|
-
function unique(arr) {
|
|
579
|
-
if (!Array.isArray(arr)) return [];
|
|
580
|
-
return Array.from(new Set(arr));
|
|
581
|
-
}
|
|
582
|
-
function length(val) {
|
|
583
|
-
if (Array.isArray(val) || typeof val === "string") return val.length;
|
|
584
|
-
if (val && typeof val === "object") return Object.keys(val).length;
|
|
585
|
-
return 0;
|
|
586
|
-
}
|
|
587
|
-
function round(val, decimals = 0) {
|
|
588
|
-
const num = Number(val);
|
|
589
|
-
if (Number.isNaN(num)) return 0;
|
|
590
|
-
const dec = typeof decimals === "number" ? decimals : Number(decimals) || 0;
|
|
591
|
-
const factor = Math.pow(10, dec);
|
|
592
|
-
return Math.round(num * factor) / factor;
|
|
593
|
-
}
|
|
594
|
-
function clamp(val, minVal, maxVal) {
|
|
595
|
-
const num = Number(val) || 0;
|
|
596
|
-
const min2 = Number(minVal) || 0;
|
|
597
|
-
const max2 = Number(maxVal) || 0;
|
|
598
|
-
return Math.min(Math.max(num, min2), max2);
|
|
599
|
-
}
|
|
600
|
-
function ceil(val) {
|
|
601
|
-
return Math.ceil(Number(val) || 0);
|
|
602
|
-
}
|
|
603
|
-
function floor(val) {
|
|
604
|
-
return Math.floor(Number(val) || 0);
|
|
605
|
-
}
|
|
606
|
-
function abs(val) {
|
|
607
|
-
return Math.abs(Number(val) || 0);
|
|
608
|
-
}
|
|
609
|
-
function min(...args) {
|
|
610
|
-
const nums = args.flat().map((n) => Number(n) || 0);
|
|
611
|
-
return nums.length ? Math.min(...nums) : 0;
|
|
612
|
-
}
|
|
613
|
-
function max(...args) {
|
|
614
|
-
const nums = args.flat().map((n) => Number(n) || 0);
|
|
615
|
-
return nums.length ? Math.max(...nums) : 0;
|
|
616
|
-
}
|
|
617
|
-
function pow(base, exp) {
|
|
618
|
-
return Math.pow(Number(base) || 0, Number(exp) || 0);
|
|
619
|
-
}
|
|
620
|
-
function sqrt(val) {
|
|
621
|
-
return Math.sqrt(Number(val) || 0);
|
|
622
|
-
}
|
|
623
|
-
function sum(arr) {
|
|
624
|
-
if (!Array.isArray(arr)) return Number(arr) || 0;
|
|
625
|
-
return arr.reduce((acc, val) => acc + (Number(val) || 0), 0);
|
|
626
|
-
}
|
|
627
|
-
function count(val) {
|
|
628
|
-
if (Array.isArray(val)) return val.length;
|
|
629
|
-
if (typeof val === "string") return val.length;
|
|
630
|
-
if (val !== void 0 && val !== null && val !== false) return 1;
|
|
631
|
-
return 0;
|
|
632
|
-
}
|
|
633
|
-
function defaultValue(val, fallback) {
|
|
634
|
-
if (val === void 0 || val === null || val === "") return fallback;
|
|
635
|
-
return val;
|
|
636
|
-
}
|
|
637
|
-
function coalesce(...args) {
|
|
638
|
-
for (const arg of args) {
|
|
639
|
-
if (arg !== void 0 && arg !== null && arg !== "") return arg;
|
|
640
|
-
}
|
|
641
|
-
return null;
|
|
642
|
-
}
|
|
643
|
-
function isEmpty(val) {
|
|
644
|
-
if (val === void 0 || val === null || val === "") return true;
|
|
645
|
-
if (Array.isArray(val)) return val.length === 0;
|
|
646
|
-
if (typeof val === "object") return Object.keys(val).length === 0;
|
|
647
|
-
return false;
|
|
648
|
-
}
|
|
649
|
-
function get(obj, path, fallback = null) {
|
|
650
|
-
if (obj === void 0 || obj === null || typeof obj !== "object") return fallback;
|
|
651
|
-
if (typeof path !== "string") return fallback;
|
|
652
|
-
const parts = path.split(".").filter(Boolean);
|
|
653
|
-
let curr = obj;
|
|
654
|
-
for (const part of parts) {
|
|
655
|
-
if (curr === void 0 || curr === null || typeof curr !== "object") return fallback;
|
|
656
|
-
curr = curr[part];
|
|
657
|
-
}
|
|
658
|
-
return curr === void 0 || curr === null ? fallback : curr;
|
|
659
|
-
}
|
|
660
|
-
function registerJexlHelpers(jexlInstance = jexl) {
|
|
661
|
-
const helpers = {
|
|
662
|
-
// Strings
|
|
663
|
-
slugify,
|
|
664
|
-
lower,
|
|
665
|
-
upper,
|
|
666
|
-
trim,
|
|
667
|
-
capitalize,
|
|
668
|
-
truncate,
|
|
669
|
-
readingTime,
|
|
670
|
-
wordCount,
|
|
671
|
-
replace,
|
|
672
|
-
startsWith,
|
|
673
|
-
endsWith,
|
|
674
|
-
// Dates
|
|
675
|
-
now,
|
|
676
|
-
today,
|
|
677
|
-
formatDate,
|
|
678
|
-
addDays,
|
|
679
|
-
diffDays,
|
|
680
|
-
isPast,
|
|
681
|
-
isFuture,
|
|
682
|
-
// Arrays
|
|
683
|
-
includes,
|
|
684
|
-
join,
|
|
685
|
-
first,
|
|
686
|
-
last,
|
|
687
|
-
compact,
|
|
688
|
-
unique,
|
|
689
|
-
length,
|
|
690
|
-
// Math
|
|
691
|
-
round,
|
|
692
|
-
clamp,
|
|
693
|
-
ceil,
|
|
694
|
-
floor,
|
|
695
|
-
abs,
|
|
696
|
-
min,
|
|
697
|
-
max,
|
|
698
|
-
pow,
|
|
699
|
-
sqrt,
|
|
700
|
-
sum,
|
|
701
|
-
count,
|
|
702
|
-
// Objects & Logical
|
|
703
|
-
default: defaultValue,
|
|
704
|
-
coalesce,
|
|
705
|
-
isEmpty,
|
|
706
|
-
get
|
|
707
|
-
};
|
|
708
|
-
for (const [name, fn] of Object.entries(helpers)) {
|
|
709
|
-
try {
|
|
710
|
-
jexlInstance.addFunction(name, fn);
|
|
711
|
-
} catch {
|
|
712
|
-
}
|
|
713
|
-
try {
|
|
714
|
-
jexlInstance.addTransform(name, fn);
|
|
715
|
-
} catch {
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
registerJexlHelpers(jexl);
|
|
720
|
-
async function evaluateJexl(expression, context = {}) {
|
|
721
|
-
if (!expression || typeof expression !== "string") return void 0;
|
|
722
|
-
try {
|
|
723
|
-
const evalContext = {
|
|
724
|
-
null: null,
|
|
725
|
-
undefined: void 0,
|
|
726
|
-
...context,
|
|
727
|
-
math: Math,
|
|
728
|
-
Math
|
|
729
|
-
};
|
|
730
|
-
return await jexl.eval(expression, evalContext);
|
|
731
|
-
} catch (_err) {
|
|
732
|
-
return void 0;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
function evaluateJexlSync(expression, context = {}) {
|
|
736
|
-
if (!expression || typeof expression !== "string") return void 0;
|
|
737
|
-
try {
|
|
738
|
-
const evalContext = {
|
|
739
|
-
null: null,
|
|
740
|
-
undefined: void 0,
|
|
741
|
-
...context,
|
|
742
|
-
math: Math,
|
|
743
|
-
Math
|
|
744
|
-
};
|
|
745
|
-
return jexl.evalSync(expression, evalContext);
|
|
746
|
-
} catch (_err) {
|
|
747
|
-
return void 0;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
var BUILTIN_JEXL_HELPERS = [
|
|
751
|
-
// Strings
|
|
752
|
-
"slugify",
|
|
753
|
-
"lower",
|
|
754
|
-
"upper",
|
|
755
|
-
"trim",
|
|
756
|
-
"capitalize",
|
|
757
|
-
"truncate",
|
|
758
|
-
"readingTime",
|
|
759
|
-
"wordCount",
|
|
760
|
-
"replace",
|
|
761
|
-
"startsWith",
|
|
762
|
-
"endsWith",
|
|
763
|
-
// Dates
|
|
764
|
-
"now",
|
|
765
|
-
"today",
|
|
766
|
-
"formatDate",
|
|
767
|
-
"addDays",
|
|
768
|
-
"diffDays",
|
|
769
|
-
"isPast",
|
|
770
|
-
"isFuture",
|
|
771
|
-
// Arrays
|
|
772
|
-
"includes",
|
|
773
|
-
"join",
|
|
774
|
-
"first",
|
|
775
|
-
"last",
|
|
776
|
-
"compact",
|
|
777
|
-
"unique",
|
|
778
|
-
"length",
|
|
779
|
-
// Math
|
|
780
|
-
"round",
|
|
781
|
-
"clamp",
|
|
782
|
-
// Objects & Logical
|
|
783
|
-
"default",
|
|
784
|
-
"coalesce",
|
|
785
|
-
"isEmpty",
|
|
786
|
-
"get"
|
|
787
|
-
];
|
|
788
|
-
|
|
789
|
-
// src/utils/declarative-hooks.ts
|
|
790
|
-
import jexl2 from "jexl";
|
|
791
|
-
registerJexlHelpers(jexl2);
|
|
792
|
-
var SURFACE_ROOTS = {
|
|
793
|
-
"collection.beforeRead": ["req", "user", "query", ...BUILTIN_JEXL_HELPERS],
|
|
794
|
-
"collection.afterRead": ["req", "user", "doc", ...BUILTIN_JEXL_HELPERS],
|
|
795
|
-
"collection.beforeChange": ["req", "user", "data", "doc", "operation", ...BUILTIN_JEXL_HELPERS],
|
|
796
|
-
"global.beforeRead": ["req", "user", "query", ...BUILTIN_JEXL_HELPERS],
|
|
797
|
-
"global.afterRead": ["req", "user", "doc", ...BUILTIN_JEXL_HELPERS],
|
|
798
|
-
"global.beforeChange": ["req", "user", "data", "doc", "operation", ...BUILTIN_JEXL_HELPERS],
|
|
799
|
-
"field.beforeChange": ["value", "data", "originalDoc", "user", ...BUILTIN_JEXL_HELPERS],
|
|
800
|
-
"field.admin.onChange": ["value", "siblingData", "data", ...BUILTIN_JEXL_HELPERS]
|
|
801
|
-
};
|
|
802
|
-
var ACCESS_ROOTS = ["user", "req", "doc", "data", "id", "config", ...BUILTIN_JEXL_HELPERS];
|
|
803
|
-
var ADMIN_CONDITION_RESERVED_ROOTS = ["data", "siblingData", "user", "id", ...BUILTIN_JEXL_HELPERS];
|
|
804
|
-
var PREVIEW_URL_RESERVED_ROOTS = ["siteUrl", "id", ...BUILTIN_JEXL_HELPERS];
|
|
805
|
-
var COMPILE_CACHE = /* @__PURE__ */ new Map();
|
|
806
|
-
function compileExpression(expression) {
|
|
807
|
-
const cached = COMPILE_CACHE.get(expression);
|
|
808
|
-
if (cached) return cached;
|
|
809
|
-
const compiled = jexl2.compile(expression);
|
|
810
|
-
const next = { ast: compiled._ast };
|
|
811
|
-
COMPILE_CACHE.set(expression, next);
|
|
812
|
-
return next;
|
|
813
|
-
}
|
|
814
|
-
function isPlainObject(value) {
|
|
815
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
816
|
-
}
|
|
817
|
-
function quoteSegment(value) {
|
|
818
|
-
return `["${value.replace(/"/g, '\\"')}"]`;
|
|
819
|
-
}
|
|
820
|
-
function fieldSegment(field, index) {
|
|
821
|
-
return typeof field.name === "string" && field.name.length > 0 ? `fields${quoteSegment(field.name)}` : `fields[${index}]`;
|
|
822
|
-
}
|
|
823
|
-
function blockSegment(block, index) {
|
|
824
|
-
return typeof block.slug === "string" && block.slug.length > 0 ? `blocks${quoteSegment(block.slug)}` : `blocks[${index}]`;
|
|
825
|
-
}
|
|
826
|
-
function collectionSegment(collection, index) {
|
|
827
|
-
return typeof collection.slug === "string" && collection.slug.length > 0 ? `collections${quoteSegment(collection.slug)}` : `collections[${index}]`;
|
|
828
|
-
}
|
|
829
|
-
function globalSegment(global, index) {
|
|
830
|
-
return typeof global.slug === "string" && global.slug.length > 0 ? `globals${quoteSegment(global.slug)}` : `globals[${index}]`;
|
|
831
|
-
}
|
|
832
|
-
function colorize(value, code, enabled) {
|
|
833
|
-
return enabled ? `\x1B[${code}m${value}\x1B[0m` : value;
|
|
834
|
-
}
|
|
835
|
-
function collectRootIdentifiers(node, roots, seen) {
|
|
836
|
-
if (!node || typeof node !== "object" || seen.has(node)) return;
|
|
837
|
-
seen.add(node);
|
|
838
|
-
const candidate = node;
|
|
839
|
-
if (candidate.type === "Identifier") {
|
|
840
|
-
if (candidate.from) {
|
|
841
|
-
collectRootIdentifiers(candidate.from, roots, seen);
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
if (typeof candidate.value === "string" && candidate.value !== "null") {
|
|
845
|
-
roots.add(candidate.value);
|
|
846
|
-
}
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
if (Array.isArray(node)) {
|
|
850
|
-
for (const entry of node) collectRootIdentifiers(entry, roots, seen);
|
|
851
|
-
return;
|
|
852
|
-
}
|
|
853
|
-
for (const value of Object.values(node)) {
|
|
854
|
-
if (Array.isArray(value)) {
|
|
855
|
-
for (const entry of value) collectRootIdentifiers(entry, roots, seen);
|
|
856
|
-
continue;
|
|
857
|
-
}
|
|
858
|
-
if (value && typeof value === "object") {
|
|
859
|
-
collectRootIdentifiers(value, roots, seen);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
function getInvalidRoots(expression, allowedRoots) {
|
|
864
|
-
const { ast } = compileExpression(expression);
|
|
865
|
-
const roots = /* @__PURE__ */ new Set();
|
|
866
|
-
collectRootIdentifiers(ast, roots, /* @__PURE__ */ new Set());
|
|
867
|
-
const allowed = new Set(allowedRoots);
|
|
868
|
-
return [...roots].filter((root) => !allowed.has(root));
|
|
869
|
-
}
|
|
870
|
-
function validateDeclarativeHookExpression(expression, surface, path) {
|
|
871
|
-
try {
|
|
872
|
-
const invalidRoots = getInvalidRoots(expression, SURFACE_ROOTS[surface]);
|
|
873
|
-
if (invalidRoots.length === 0) return [];
|
|
874
|
-
return [
|
|
875
|
-
{
|
|
876
|
-
path,
|
|
877
|
-
surface,
|
|
878
|
-
expression,
|
|
879
|
-
message: `uses unsupported context ${invalidRoots.map((root) => `"${root}"`).join(", ")}. Allowed context: ${SURFACE_ROOTS[surface].map((root) => `"${root}"`).join(", ")}`
|
|
880
|
-
}
|
|
881
|
-
];
|
|
882
|
-
} catch (error) {
|
|
883
|
-
return [
|
|
884
|
-
{
|
|
885
|
-
path,
|
|
886
|
-
surface,
|
|
887
|
-
expression,
|
|
888
|
-
message: `has invalid syntax: ${error.message}`
|
|
889
|
-
}
|
|
890
|
-
];
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
function validateDeclarativeAccessExpression(expression, surface, path) {
|
|
894
|
-
try {
|
|
895
|
-
const invalidRoots = getInvalidRoots(expression, ACCESS_ROOTS);
|
|
896
|
-
if (invalidRoots.length === 0) return [];
|
|
897
|
-
return [
|
|
898
|
-
{
|
|
899
|
-
path,
|
|
900
|
-
surface,
|
|
901
|
-
expression,
|
|
902
|
-
message: `uses unsupported context ${invalidRoots.map((root) => `"${root}"`).join(", ")}. Allowed context: ${ACCESS_ROOTS.map((root) => `"${root}"`).join(", ")}`
|
|
903
|
-
}
|
|
904
|
-
];
|
|
905
|
-
} catch (error) {
|
|
906
|
-
return [
|
|
907
|
-
{
|
|
908
|
-
path,
|
|
909
|
-
surface,
|
|
910
|
-
expression,
|
|
911
|
-
message: `has invalid syntax: ${error.message}`
|
|
912
|
-
}
|
|
913
|
-
];
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
function validateAdminConditionExpression(expression, path, allowedRoots) {
|
|
917
|
-
try {
|
|
918
|
-
const invalidRoots = getInvalidRoots(expression, allowedRoots);
|
|
919
|
-
if (invalidRoots.length === 0) return [];
|
|
920
|
-
return [
|
|
921
|
-
{
|
|
922
|
-
path,
|
|
923
|
-
surface: "field.admin.condition",
|
|
924
|
-
expression,
|
|
925
|
-
message: `uses unsupported context ${invalidRoots.map((root) => `"${root}"`).join(", ")}. Allowed context: ${allowedRoots.map((root) => `"${root}"`).join(", ")}`
|
|
926
|
-
}
|
|
927
|
-
];
|
|
928
|
-
} catch (error) {
|
|
929
|
-
return [
|
|
930
|
-
{
|
|
931
|
-
path,
|
|
932
|
-
surface: "field.admin.condition",
|
|
933
|
-
expression,
|
|
934
|
-
message: `has invalid syntax: ${error.message}`
|
|
935
|
-
}
|
|
936
|
-
];
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
function validatePreviewUrlExpression(expression, path, allowedRoots) {
|
|
940
|
-
try {
|
|
941
|
-
const invalidRoots = getInvalidRoots(expression, allowedRoots);
|
|
942
|
-
if (invalidRoots.length === 0) return [];
|
|
943
|
-
return [
|
|
944
|
-
{
|
|
945
|
-
path,
|
|
946
|
-
surface: "collection.admin.previewUrl",
|
|
947
|
-
expression,
|
|
948
|
-
message: `uses unsupported context ${invalidRoots.map((root) => `"${root}"`).join(", ")}. Allowed context: ${allowedRoots.map((root) => `"${root}"`).join(", ")}`
|
|
949
|
-
}
|
|
950
|
-
];
|
|
951
|
-
} catch (error) {
|
|
952
|
-
return [
|
|
953
|
-
{
|
|
954
|
-
path,
|
|
955
|
-
surface: "collection.admin.previewUrl",
|
|
956
|
-
expression,
|
|
957
|
-
message: `has invalid syntax: ${error.message}`
|
|
958
|
-
}
|
|
959
|
-
];
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
function assertValidDeclarativeHookExpression(expression, surface, path) {
|
|
963
|
-
const issues = validateDeclarativeHookExpression(expression, surface, path);
|
|
964
|
-
if (issues.length === 0) return;
|
|
965
|
-
throw new Error(`Invalid declarative hook at ${path}: ${issues[0].message}`);
|
|
966
|
-
}
|
|
967
|
-
function assertValidDeclarativeHookResult(result, surface, path) {
|
|
968
|
-
if (isPlainObject(result)) return;
|
|
969
|
-
throw new Error(`Invalid declarative hook result at ${path}: ${surface} expressions must return an object`);
|
|
970
|
-
}
|
|
971
|
-
function collectFieldIssues(fields, path, issues) {
|
|
972
|
-
fields.forEach((field, index) => {
|
|
973
|
-
const fieldPath = `${path}.${fieldSegment(field, index)}`;
|
|
974
|
-
field.hooks?.beforeChange?.forEach((hook, hookIndex) => {
|
|
975
|
-
if (typeof hook !== "string") return;
|
|
976
|
-
issues.push(
|
|
977
|
-
...validateDeclarativeHookExpression(
|
|
978
|
-
hook,
|
|
979
|
-
"field.beforeChange",
|
|
980
|
-
`${fieldPath}.hooks.beforeChange[${hookIndex}]`
|
|
981
|
-
)
|
|
982
|
-
);
|
|
983
|
-
});
|
|
984
|
-
field.hooks?.afterRead?.forEach((hook, hookIndex) => {
|
|
985
|
-
if (typeof hook !== "string") return;
|
|
986
|
-
issues.push({
|
|
987
|
-
path: `${fieldPath}.hooks.afterRead[${hookIndex}]`,
|
|
988
|
-
surface: "unsupported",
|
|
989
|
-
expression: hook,
|
|
990
|
-
message: "declarative strings are not supported on field hooks.afterRead"
|
|
991
|
-
});
|
|
992
|
-
});
|
|
993
|
-
if (typeof field.admin?.hooks?.onChange === "string") {
|
|
994
|
-
issues.push(
|
|
995
|
-
...validateDeclarativeHookExpression(
|
|
996
|
-
field.admin.hooks.onChange,
|
|
997
|
-
"field.admin.onChange",
|
|
998
|
-
`${fieldPath}.admin.hooks.onChange`
|
|
999
|
-
)
|
|
1000
|
-
);
|
|
1001
|
-
}
|
|
1002
|
-
if (typeof field.admin?.hooks?.options === "string") {
|
|
1003
|
-
issues.push({
|
|
1004
|
-
path: `${fieldPath}.admin.hooks.options`,
|
|
1005
|
-
surface: "unsupported",
|
|
1006
|
-
expression: field.admin.hooks.options,
|
|
1007
|
-
message: "declarative strings are not supported on field admin.hooks.options"
|
|
1008
|
-
});
|
|
1009
|
-
}
|
|
1010
|
-
if (Array.isArray(field.fields)) {
|
|
1011
|
-
collectFieldIssues(field.fields, fieldPath, issues);
|
|
1012
|
-
}
|
|
1013
|
-
if (Array.isArray(field.blocks)) {
|
|
1014
|
-
field.blocks.forEach((block, blockIndex) => {
|
|
1015
|
-
if (!Array.isArray(block.fields)) return;
|
|
1016
|
-
collectFieldIssues(block.fields, `${fieldPath}.${blockSegment(block, blockIndex)}`, issues);
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
function collectFieldNames(fields) {
|
|
1022
|
-
return fields.flatMap(
|
|
1023
|
-
(field) => typeof field.name === "string" && field.name.length > 0 ? [field.name] : []
|
|
1024
|
-
);
|
|
1025
|
-
}
|
|
1026
|
-
function collectAdminConditionIssues(fields, path, rootFieldNames, issues) {
|
|
1027
|
-
const scopeFieldNames = collectFieldNames(fields);
|
|
1028
|
-
const allowedRoots = [.../* @__PURE__ */ new Set([...ADMIN_CONDITION_RESERVED_ROOTS, ...rootFieldNames, ...scopeFieldNames])];
|
|
1029
|
-
fields.forEach((field, index) => {
|
|
1030
|
-
const fieldPath = `${path}.${fieldSegment(field, index)}`;
|
|
1031
|
-
if (typeof field.admin?.condition === "string") {
|
|
1032
|
-
issues.push(
|
|
1033
|
-
...validateAdminConditionExpression(
|
|
1034
|
-
field.admin.condition,
|
|
1035
|
-
`${fieldPath}.admin.condition`,
|
|
1036
|
-
allowedRoots
|
|
1037
|
-
)
|
|
1038
|
-
);
|
|
1039
|
-
}
|
|
1040
|
-
if (Array.isArray(field.fields)) {
|
|
1041
|
-
collectAdminConditionIssues(field.fields, fieldPath, rootFieldNames, issues);
|
|
1042
|
-
}
|
|
1043
|
-
if (Array.isArray(field.blocks)) {
|
|
1044
|
-
field.blocks.forEach((block, blockIndex) => {
|
|
1045
|
-
if (!Array.isArray(block.fields)) return;
|
|
1046
|
-
collectAdminConditionIssues(
|
|
1047
|
-
block.fields,
|
|
1048
|
-
`${fieldPath}.${blockSegment(block, blockIndex)}`,
|
|
1049
|
-
rootFieldNames,
|
|
1050
|
-
issues
|
|
1051
|
-
);
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
function collectFieldAccessIssues(fields, path, issues) {
|
|
1057
|
-
fields.forEach((field, index) => {
|
|
1058
|
-
const fieldPath = `${path}.${fieldSegment(field, index)}`;
|
|
1059
|
-
if (typeof field.access?.read === "string") {
|
|
1060
|
-
issues.push(...validateDeclarativeAccessExpression(field.access.read, "field.access", `${fieldPath}.access.read`));
|
|
1061
|
-
}
|
|
1062
|
-
if (typeof field.access?.create === "string") {
|
|
1063
|
-
issues.push(
|
|
1064
|
-
...validateDeclarativeAccessExpression(field.access.create, "field.access", `${fieldPath}.access.create`)
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
if (typeof field.access?.update === "string") {
|
|
1068
|
-
issues.push(
|
|
1069
|
-
...validateDeclarativeAccessExpression(field.access.update, "field.access", `${fieldPath}.access.update`)
|
|
1070
|
-
);
|
|
1071
|
-
}
|
|
1072
|
-
if (Array.isArray(field.fields)) {
|
|
1073
|
-
collectFieldAccessIssues(field.fields, fieldPath, issues);
|
|
1074
|
-
}
|
|
1075
|
-
if (Array.isArray(field.blocks)) {
|
|
1076
|
-
field.blocks.forEach((block, blockIndex) => {
|
|
1077
|
-
if (!Array.isArray(block.fields)) return;
|
|
1078
|
-
collectFieldAccessIssues(
|
|
1079
|
-
block.fields,
|
|
1080
|
-
`${fieldPath}.${blockSegment(block, blockIndex)}`,
|
|
1081
|
-
issues
|
|
1082
|
-
);
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
});
|
|
1086
|
-
}
|
|
1087
|
-
function collectHookIssues(hooks, scope, path, issues) {
|
|
1088
|
-
if (!hooks) return;
|
|
1089
|
-
const supported = {
|
|
1090
|
-
beforeRead: `${scope}.beforeRead`,
|
|
1091
|
-
afterRead: `${scope}.afterRead`,
|
|
1092
|
-
beforeChange: `${scope}.beforeChange`
|
|
1093
|
-
};
|
|
1094
|
-
for (const [key, value] of Object.entries(hooks)) {
|
|
1095
|
-
if (!Array.isArray(value)) continue;
|
|
1096
|
-
value.forEach((hook, index) => {
|
|
1097
|
-
if (typeof hook !== "string") return;
|
|
1098
|
-
const surface = supported[key];
|
|
1099
|
-
if (!surface) {
|
|
1100
|
-
issues.push({
|
|
1101
|
-
path: `${path}.${key}[${index}]`,
|
|
1102
|
-
surface: "unsupported",
|
|
1103
|
-
expression: hook,
|
|
1104
|
-
message: `declarative strings are not supported on ${scope} hooks.${key}`
|
|
1105
|
-
});
|
|
1106
|
-
return;
|
|
1107
|
-
}
|
|
1108
|
-
issues.push(...validateDeclarativeHookExpression(hook, surface, `${path}.${key}[${index}]`));
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
function collectDeclarativeHookValidationIssues(config) {
|
|
1113
|
-
const issues = [];
|
|
1114
|
-
config.blocks?.forEach((block, blockIndex) => {
|
|
1115
|
-
if (!Array.isArray(block.fields)) return;
|
|
1116
|
-
collectFieldIssues(
|
|
1117
|
-
block.fields,
|
|
1118
|
-
blockSegment(block, blockIndex),
|
|
1119
|
-
issues
|
|
1120
|
-
);
|
|
1121
|
-
});
|
|
1122
|
-
config.collections.forEach((collection, collectionIndex) => {
|
|
1123
|
-
const collectionPath = collectionSegment(collection, collectionIndex);
|
|
1124
|
-
collectHookIssues(
|
|
1125
|
-
collection.hooks,
|
|
1126
|
-
"collection",
|
|
1127
|
-
`${collectionPath}.hooks`,
|
|
1128
|
-
issues
|
|
1129
|
-
);
|
|
1130
|
-
collectFieldIssues(collection.fields, collectionPath, issues);
|
|
1131
|
-
});
|
|
1132
|
-
config.globals?.forEach((global, globalIndex) => {
|
|
1133
|
-
const globalPath = globalSegment(global, globalIndex);
|
|
1134
|
-
collectHookIssues(
|
|
1135
|
-
global.hooks,
|
|
1136
|
-
"global",
|
|
1137
|
-
`${globalPath}.hooks`,
|
|
1138
|
-
issues
|
|
1139
|
-
);
|
|
1140
|
-
collectFieldIssues(global.fields, globalPath, issues);
|
|
1141
|
-
});
|
|
1142
|
-
return issues;
|
|
1143
|
-
}
|
|
1144
|
-
function collectDeclarativeAccessValidationIssues(config) {
|
|
1145
|
-
const issues = [];
|
|
1146
|
-
Object.entries(config.accessPolicies ?? {}).forEach(([name, value]) => {
|
|
1147
|
-
if (typeof value !== "string") return;
|
|
1148
|
-
issues.push(
|
|
1149
|
-
...validateDeclarativeAccessExpression(value, "config.accessPolicy", `accessPolicies.${name}`)
|
|
1150
|
-
);
|
|
1151
|
-
});
|
|
1152
|
-
config.blocks?.forEach((block, blockIndex) => {
|
|
1153
|
-
if (!Array.isArray(block.fields)) return;
|
|
1154
|
-
collectFieldAccessIssues(
|
|
1155
|
-
block.fields,
|
|
1156
|
-
blockSegment(block, blockIndex),
|
|
1157
|
-
issues
|
|
1158
|
-
);
|
|
1159
|
-
});
|
|
1160
|
-
config.collections.forEach((collection, collectionIndex) => {
|
|
1161
|
-
const collectionPath = collectionSegment(collection, collectionIndex);
|
|
1162
|
-
if (typeof collection.access?.read === "string") {
|
|
1163
|
-
issues.push(
|
|
1164
|
-
...validateDeclarativeAccessExpression(
|
|
1165
|
-
collection.access.read,
|
|
1166
|
-
"collection.access",
|
|
1167
|
-
`${collectionPath}.access.read`
|
|
1168
|
-
)
|
|
1169
|
-
);
|
|
1170
|
-
}
|
|
1171
|
-
if (typeof collection.access?.create === "string") {
|
|
1172
|
-
issues.push(
|
|
1173
|
-
...validateDeclarativeAccessExpression(
|
|
1174
|
-
collection.access.create,
|
|
1175
|
-
"collection.access",
|
|
1176
|
-
`${collectionPath}.access.create`
|
|
1177
|
-
)
|
|
1178
|
-
);
|
|
1179
|
-
}
|
|
1180
|
-
if (typeof collection.access?.update === "string") {
|
|
1181
|
-
issues.push(
|
|
1182
|
-
...validateDeclarativeAccessExpression(
|
|
1183
|
-
collection.access.update,
|
|
1184
|
-
"collection.access",
|
|
1185
|
-
`${collectionPath}.access.update`
|
|
1186
|
-
)
|
|
1187
|
-
);
|
|
1188
|
-
}
|
|
1189
|
-
if (typeof collection.access?.delete === "string") {
|
|
1190
|
-
issues.push(
|
|
1191
|
-
...validateDeclarativeAccessExpression(
|
|
1192
|
-
collection.access.delete,
|
|
1193
|
-
"collection.access",
|
|
1194
|
-
`${collectionPath}.access.delete`
|
|
1195
|
-
)
|
|
1196
|
-
);
|
|
1197
|
-
}
|
|
1198
|
-
if (typeof collection.access?.readAudit === "string") {
|
|
1199
|
-
issues.push(
|
|
1200
|
-
...validateDeclarativeAccessExpression(
|
|
1201
|
-
collection.access.readAudit,
|
|
1202
|
-
"collection.access",
|
|
1203
|
-
`${collectionPath}.access.readAudit`
|
|
1204
|
-
)
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
collectFieldAccessIssues(collection.fields, collectionPath, issues);
|
|
1208
|
-
});
|
|
1209
|
-
config.globals?.forEach((global, globalIndex) => {
|
|
1210
|
-
const globalPath = globalSegment(global, globalIndex);
|
|
1211
|
-
if (typeof global.access?.read === "string") {
|
|
1212
|
-
issues.push(
|
|
1213
|
-
...validateDeclarativeAccessExpression(global.access.read, "global.access", `${globalPath}.access.read`)
|
|
1214
|
-
);
|
|
1215
|
-
}
|
|
1216
|
-
if (typeof global.access?.update === "string") {
|
|
1217
|
-
issues.push(
|
|
1218
|
-
...validateDeclarativeAccessExpression(
|
|
1219
|
-
global.access.update,
|
|
1220
|
-
"global.access",
|
|
1221
|
-
`${globalPath}.access.update`
|
|
1222
|
-
)
|
|
1223
|
-
);
|
|
1224
|
-
}
|
|
1225
|
-
collectFieldAccessIssues(global.fields, globalPath, issues);
|
|
1226
|
-
});
|
|
1227
|
-
return issues;
|
|
1228
|
-
}
|
|
1229
|
-
function collectAdminConditionValidationIssues(config) {
|
|
1230
|
-
const issues = [];
|
|
1231
|
-
config.blocks?.forEach((block, blockIndex) => {
|
|
1232
|
-
if (!Array.isArray(block.fields)) return;
|
|
1233
|
-
collectAdminConditionIssues(
|
|
1234
|
-
block.fields,
|
|
1235
|
-
blockSegment(block, blockIndex),
|
|
1236
|
-
collectFieldNames(block.fields),
|
|
1237
|
-
issues
|
|
1238
|
-
);
|
|
1239
|
-
});
|
|
1240
|
-
config.collections.forEach((collection, collectionIndex) => {
|
|
1241
|
-
const collectionPath = collectionSegment(collection, collectionIndex);
|
|
1242
|
-
const rootFieldNames = collectFieldNames(collection.fields);
|
|
1243
|
-
collectAdminConditionIssues(collection.fields, collectionPath, rootFieldNames, issues);
|
|
1244
|
-
});
|
|
1245
|
-
config.globals?.forEach((global, globalIndex) => {
|
|
1246
|
-
const globalPath = globalSegment(global, globalIndex);
|
|
1247
|
-
const rootFieldNames = collectFieldNames(global.fields);
|
|
1248
|
-
collectAdminConditionIssues(global.fields, globalPath, rootFieldNames, issues);
|
|
1249
|
-
});
|
|
1250
|
-
return issues;
|
|
1251
|
-
}
|
|
1252
|
-
function collectPreviewUrlValidationIssues(config) {
|
|
1253
|
-
const issues = [];
|
|
1254
|
-
config.collections.forEach((collection, collectionIndex) => {
|
|
1255
|
-
if (typeof collection.admin?.previewUrl !== "string") return;
|
|
1256
|
-
const collectionPath = collectionSegment(collection, collectionIndex);
|
|
1257
|
-
const allowedRoots = [
|
|
1258
|
-
.../* @__PURE__ */ new Set([...PREVIEW_URL_RESERVED_ROOTS, ...collectFieldNames(collection.fields)])
|
|
1259
|
-
];
|
|
1260
|
-
issues.push(
|
|
1261
|
-
...validatePreviewUrlExpression(
|
|
1262
|
-
collection.admin.previewUrl,
|
|
1263
|
-
`${collectionPath}.admin.previewUrl`,
|
|
1264
|
-
allowedRoots
|
|
1265
|
-
)
|
|
1266
|
-
);
|
|
1267
|
-
});
|
|
1268
|
-
return issues;
|
|
1269
|
-
}
|
|
1270
|
-
function assertValidAdminConditionsInConfig(config, source = "config") {
|
|
1271
|
-
const diagnostics = collectAdminConditionValidationIssues(config).map((issue) => ({
|
|
1272
|
-
severity: "error",
|
|
1273
|
-
source: "adminCondition",
|
|
1274
|
-
path: issue.path,
|
|
1275
|
-
surface: issue.surface,
|
|
1276
|
-
message: issue.message,
|
|
1277
|
-
expression: issue.expression
|
|
1278
|
-
}));
|
|
1279
|
-
if (diagnostics.length === 0) return;
|
|
1280
|
-
throw new ConfigValidationError(source, diagnostics);
|
|
1281
|
-
}
|
|
1282
|
-
function assertValidPreviewUrlsInConfig(config, source = "config") {
|
|
1283
|
-
const diagnostics = collectPreviewUrlValidationIssues(config).map((issue) => ({
|
|
1284
|
-
severity: "error",
|
|
1285
|
-
source: "previewUrl",
|
|
1286
|
-
path: issue.path,
|
|
1287
|
-
surface: issue.surface,
|
|
1288
|
-
message: issue.message,
|
|
1289
|
-
expression: issue.expression
|
|
1290
|
-
}));
|
|
1291
|
-
if (diagnostics.length === 0) return;
|
|
1292
|
-
throw new ConfigValidationError(source, diagnostics);
|
|
1293
|
-
}
|
|
1294
|
-
function collectConfigDiagnostics(config) {
|
|
1295
|
-
const hookIssues = collectDeclarativeHookValidationIssues(config).map((issue) => ({
|
|
1296
|
-
severity: "error",
|
|
1297
|
-
source: "declarativeHook",
|
|
1298
|
-
path: issue.path,
|
|
1299
|
-
surface: issue.surface,
|
|
1300
|
-
message: issue.message,
|
|
1301
|
-
expression: issue.expression
|
|
1302
|
-
}));
|
|
1303
|
-
const accessIssues = collectDeclarativeAccessValidationIssues(config).map((issue) => ({
|
|
1304
|
-
severity: "error",
|
|
1305
|
-
source: "declarativeAccess",
|
|
1306
|
-
path: issue.path,
|
|
1307
|
-
surface: issue.surface,
|
|
1308
|
-
message: issue.message,
|
|
1309
|
-
expression: issue.expression
|
|
1310
|
-
}));
|
|
1311
|
-
const adminConditionIssues = collectAdminConditionValidationIssues(config).map((issue) => ({
|
|
1312
|
-
severity: "error",
|
|
1313
|
-
source: "adminCondition",
|
|
1314
|
-
path: issue.path,
|
|
1315
|
-
surface: issue.surface,
|
|
1316
|
-
message: issue.message,
|
|
1317
|
-
expression: issue.expression
|
|
1318
|
-
}));
|
|
1319
|
-
const previewUrlIssues = collectPreviewUrlValidationIssues(config).map((issue) => ({
|
|
1320
|
-
severity: "error",
|
|
1321
|
-
source: "previewUrl",
|
|
1322
|
-
path: issue.path,
|
|
1323
|
-
surface: issue.surface,
|
|
1324
|
-
message: issue.message,
|
|
1325
|
-
expression: issue.expression
|
|
1326
|
-
}));
|
|
1327
|
-
return [...hookIssues, ...accessIssues, ...adminConditionIssues, ...previewUrlIssues];
|
|
1328
|
-
}
|
|
1329
|
-
function formatConfigDiagnostics(source, diagnostics, options = {}) {
|
|
1330
|
-
const color = options.color ?? false;
|
|
1331
|
-
const header = `${colorize("Config validation failed", 31, color)} in ${colorize(source, 36, color)}`;
|
|
1332
|
-
const docLink = `${colorize(" Learn how to write declarative rules:", 90, color)} ${colorize("https://docs.dyrected.com/docs/editor-experience/form-and-field-hooks", 34, color)}`;
|
|
1333
|
-
const lines = diagnostics.flatMap((issue, index) => [
|
|
1334
|
-
`${colorize(`${index + 1}.`, 31, color)} ${colorize(issue.path, 1, color)}`,
|
|
1335
|
-
` ${issue.message}`,
|
|
1336
|
-
` ${colorize("surface:", 90, color)} ${issue.surface}`
|
|
1337
|
-
]);
|
|
1338
|
-
return `${header}
|
|
1339
|
-
${lines.join("\n")}
|
|
1340
|
-
|
|
1341
|
-
${docLink}`;
|
|
1342
|
-
}
|
|
1343
|
-
var ConfigValidationError = class extends Error {
|
|
1344
|
-
diagnostics;
|
|
1345
|
-
source;
|
|
1346
|
-
constructor(source, diagnostics) {
|
|
1347
|
-
super(formatConfigDiagnostics(source, diagnostics));
|
|
1348
|
-
this.name = "ConfigValidationError";
|
|
1349
|
-
this.source = source;
|
|
1350
|
-
this.diagnostics = diagnostics;
|
|
1351
|
-
}
|
|
1352
|
-
};
|
|
1353
|
-
function isConfigValidationError(error) {
|
|
1354
|
-
return error instanceof ConfigValidationError;
|
|
1355
|
-
}
|
|
1356
|
-
function assertValidDeclarativeHooksInConfig(config, source = "config") {
|
|
1357
|
-
const diagnostics = collectDeclarativeHookValidationIssues(config).map((issue) => ({
|
|
1358
|
-
severity: "error",
|
|
1359
|
-
source: "declarativeHook",
|
|
1360
|
-
path: issue.path,
|
|
1361
|
-
surface: issue.surface,
|
|
1362
|
-
message: issue.message,
|
|
1363
|
-
expression: issue.expression
|
|
1364
|
-
}));
|
|
1365
|
-
if (diagnostics.length === 0) return;
|
|
1366
|
-
throw new ConfigValidationError(source, diagnostics);
|
|
1367
|
-
}
|
|
1368
|
-
function assertValidDeclarativeAccessInConfig(config, source = "config") {
|
|
1369
|
-
const diagnostics = collectDeclarativeAccessValidationIssues(config).map((issue) => ({
|
|
1370
|
-
severity: "error",
|
|
1371
|
-
source: "declarativeAccess",
|
|
1372
|
-
path: issue.path,
|
|
1373
|
-
surface: issue.surface,
|
|
1374
|
-
message: issue.message,
|
|
1375
|
-
expression: issue.expression
|
|
1376
|
-
}));
|
|
1377
|
-
if (diagnostics.length === 0) return;
|
|
1378
|
-
throw new ConfigValidationError(source, diagnostics);
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
// src/auth/token.ts
|
|
1382
|
-
import { SignJWT, jwtVerify, decodeJwt } from "jose";
|
|
1383
|
-
function getSecret() {
|
|
1384
|
-
const secret = process.env.DYRECTED_JWT_SECRET;
|
|
1385
|
-
if (!secret) {
|
|
1386
|
-
throw new Error(
|
|
1387
|
-
"[dyrected/core] DYRECTED_JWT_SECRET is not set. Add it to your environment variables to enable auth collections."
|
|
1388
|
-
);
|
|
1389
|
-
}
|
|
1390
|
-
return new TextEncoder().encode(secret);
|
|
1391
|
-
}
|
|
1392
|
-
var DEFAULT_EXPIRY = "7d";
|
|
1393
|
-
async function signCollectionToken(payload, expiresIn = DEFAULT_EXPIRY) {
|
|
1394
|
-
return new SignJWT({ ...payload }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(getSecret());
|
|
1395
|
-
}
|
|
1396
|
-
async function verifyCollectionToken(token) {
|
|
1397
|
-
const { payload } = await jwtVerify(token, getSecret());
|
|
1398
|
-
return payload;
|
|
1399
|
-
}
|
|
1400
|
-
function decodeCollectionToken(token) {
|
|
1401
|
-
try {
|
|
1402
|
-
return decodeJwt(token);
|
|
1403
|
-
} catch {
|
|
1404
|
-
return null;
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
// src/auth/sessions.ts
|
|
1409
|
-
var AUTH_SESSIONS_COLLECTION = "__auth_sessions";
|
|
1410
|
-
async function issueAuthSessionToken(args) {
|
|
1411
|
-
const sessionId = createSessionId();
|
|
1412
|
-
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
1413
|
-
const db = args.config.db;
|
|
1414
|
-
if (db) {
|
|
1415
|
-
await db.create({
|
|
1416
|
-
collection: AUTH_SESSIONS_COLLECTION,
|
|
1417
|
-
data: {
|
|
1418
|
-
id: sessionId,
|
|
1419
|
-
userId: args.userId,
|
|
1420
|
-
email: args.email,
|
|
1421
|
-
collection: args.collection,
|
|
1422
|
-
authSource: args.authSource ?? "local",
|
|
1423
|
-
providerId: args.providerId,
|
|
1424
|
-
lastIp: args.ip,
|
|
1425
|
-
lastSeenAt: now2,
|
|
1426
|
-
revokedAt: null,
|
|
1427
|
-
expiresAt: null
|
|
1428
|
-
}
|
|
1429
|
-
});
|
|
1430
|
-
}
|
|
1431
|
-
const token = await signCollectionToken(
|
|
1432
|
-
{
|
|
1433
|
-
sub: args.userId,
|
|
1434
|
-
email: args.email,
|
|
1435
|
-
collection: args.collection,
|
|
1436
|
-
authSource: args.authSource,
|
|
1437
|
-
providerId: args.providerId,
|
|
1438
|
-
sid: sessionId
|
|
1439
|
-
},
|
|
1440
|
-
args.expiresIn
|
|
1441
|
-
);
|
|
1442
|
-
const payload = decodeCollectionToken(token);
|
|
1443
|
-
const expiresAt = payload?.exp != null ? new Date(payload.exp * 1e3).toISOString() : null;
|
|
1444
|
-
if (db && expiresAt) {
|
|
1445
|
-
await db.update({
|
|
1446
|
-
collection: AUTH_SESSIONS_COLLECTION,
|
|
1447
|
-
id: sessionId,
|
|
1448
|
-
data: {
|
|
1449
|
-
expiresAt,
|
|
1450
|
-
lastSeenAt: now2,
|
|
1451
|
-
lastIp: args.ip
|
|
1452
|
-
}
|
|
1453
|
-
});
|
|
1454
|
-
}
|
|
1455
|
-
return token;
|
|
1456
|
-
}
|
|
1457
|
-
async function getAuthSession(config, sessionId) {
|
|
1458
|
-
const db = config.db;
|
|
1459
|
-
if (!db) return null;
|
|
1460
|
-
return await db.findOne({
|
|
1461
|
-
collection: AUTH_SESSIONS_COLLECTION,
|
|
1462
|
-
id: sessionId
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
function isAuthSessionActive(session) {
|
|
1466
|
-
if (!session) return false;
|
|
1467
|
-
if (session.revokedAt) return false;
|
|
1468
|
-
if (session.expiresAt && new Date(session.expiresAt).getTime() <= Date.now()) {
|
|
1469
|
-
return false;
|
|
1470
|
-
}
|
|
1471
|
-
return true;
|
|
1472
|
-
}
|
|
1473
|
-
async function touchAuthSession(config, sessionId, args) {
|
|
1474
|
-
const db = config.db;
|
|
1475
|
-
if (!db) return;
|
|
1476
|
-
await db.update({
|
|
1477
|
-
collection: AUTH_SESSIONS_COLLECTION,
|
|
1478
|
-
id: sessionId,
|
|
1479
|
-
data: {
|
|
1480
|
-
lastSeenAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1481
|
-
...args.ip ? { lastIp: args.ip } : {}
|
|
1482
|
-
}
|
|
1483
|
-
});
|
|
1484
|
-
}
|
|
1485
|
-
async function revokeAuthSession(config, sessionId) {
|
|
1486
|
-
const db = config.db;
|
|
1487
|
-
if (!db) return;
|
|
1488
|
-
await db.update({
|
|
1489
|
-
collection: AUTH_SESSIONS_COLLECTION,
|
|
1490
|
-
id: sessionId,
|
|
1491
|
-
data: {
|
|
1492
|
-
revokedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1493
|
-
}
|
|
1494
|
-
});
|
|
1495
|
-
}
|
|
1496
|
-
async function revokeAllAuthSessions(config, args) {
|
|
1497
|
-
const db = config.db;
|
|
1498
|
-
if (!db) return 0;
|
|
1499
|
-
let page = 1;
|
|
1500
|
-
let revoked = 0;
|
|
1501
|
-
while (true) {
|
|
1502
|
-
const result = await db.find({
|
|
1503
|
-
collection: AUTH_SESSIONS_COLLECTION,
|
|
1504
|
-
where: {
|
|
1505
|
-
userId: { equals: args.userId },
|
|
1506
|
-
collection: { equals: args.collection }
|
|
1507
|
-
},
|
|
1508
|
-
page,
|
|
1509
|
-
limit: 100
|
|
1510
|
-
});
|
|
1511
|
-
for (const session of result.docs) {
|
|
1512
|
-
if (session.revokedAt) continue;
|
|
1513
|
-
await revokeAuthSession(config, session.id);
|
|
1514
|
-
revoked += 1;
|
|
1515
|
-
}
|
|
1516
|
-
if (!result.hasNextPage) break;
|
|
1517
|
-
page += 1;
|
|
1518
|
-
}
|
|
1519
|
-
return revoked;
|
|
1520
|
-
}
|
|
1521
|
-
function createSessionId() {
|
|
1522
|
-
return globalThis.crypto?.randomUUID?.() ? globalThis.crypto.randomUUID() : `sess_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
// src/utils/block-references.ts
|
|
1526
|
-
function mergeUniqueBlocks(blocks) {
|
|
1527
|
-
const seen = /* @__PURE__ */ new Map();
|
|
1528
|
-
for (const block of blocks) {
|
|
1529
|
-
const existing = seen.get(block.slug);
|
|
1530
|
-
if (existing && existing !== block) {
|
|
1531
|
-
throw new Error(
|
|
1532
|
-
`Duplicate block slug "${block.slug}" found in the reusable block registry. Block slugs must be unique.`
|
|
1533
|
-
);
|
|
1534
|
-
}
|
|
1535
|
-
if (!existing) seen.set(block.slug, block);
|
|
1536
|
-
}
|
|
1537
|
-
return Array.from(seen.values());
|
|
1538
|
-
}
|
|
1539
|
-
function buildRegistry(blocks) {
|
|
1540
|
-
return new Map(blocks.map((block) => [block.slug, block]));
|
|
1541
|
-
}
|
|
1542
|
-
function resolveField(field, registry, blockCache) {
|
|
1543
|
-
const next = { ...field };
|
|
1544
|
-
if (next.fields) {
|
|
1545
|
-
next.fields = next.fields.map(
|
|
1546
|
-
(child) => resolveField(child, registry, blockCache)
|
|
1547
|
-
);
|
|
1548
|
-
}
|
|
1549
|
-
if (next.type !== "blocks") return next;
|
|
1550
|
-
const hasInlineBlocks = Array.isArray(next.blocks) && next.blocks.length > 0;
|
|
1551
|
-
const hasReferences = Array.isArray(next.blockReferences) && next.blockReferences.length > 0;
|
|
1552
|
-
if (hasInlineBlocks && hasReferences) {
|
|
1553
|
-
throw new Error(
|
|
1554
|
-
`Blocks field "${next.name ?? "(unnamed)"}" cannot define both "blocks" and "blockReferences". Use one or the other.`
|
|
1555
|
-
);
|
|
1556
|
-
}
|
|
1557
|
-
if (hasReferences) {
|
|
1558
|
-
next.blocks = next.blockReferences.map((slug) => {
|
|
1559
|
-
const block = registry.get(slug);
|
|
1560
|
-
if (!block) {
|
|
1561
|
-
throw new Error(
|
|
1562
|
-
`Unknown block reference "${slug}" on blocks field "${next.name ?? "(unnamed)"}". Add it to defineConfig({ blocks: [...] }).`
|
|
1563
|
-
);
|
|
1564
|
-
}
|
|
1565
|
-
return resolveBlock(block, registry, blockCache);
|
|
1566
|
-
});
|
|
1567
|
-
return next;
|
|
1568
|
-
}
|
|
1569
|
-
if (hasInlineBlocks) {
|
|
1570
|
-
next.blocks = next.blocks.map(
|
|
1571
|
-
(block) => resolveBlock(block, registry, blockCache)
|
|
1572
|
-
);
|
|
1573
|
-
}
|
|
1574
|
-
return next;
|
|
1575
|
-
}
|
|
1576
|
-
function resolveBlock(block, registry, blockCache) {
|
|
1577
|
-
const cached = blockCache.get(block);
|
|
1578
|
-
if (cached) return cached;
|
|
1579
|
-
const resolved = {
|
|
1580
|
-
...block,
|
|
1581
|
-
fields: []
|
|
1582
|
-
};
|
|
1583
|
-
blockCache.set(block, resolved);
|
|
1584
|
-
resolved.fields = block.fields.map(
|
|
1585
|
-
(field) => resolveField(field, registry, blockCache)
|
|
1586
|
-
);
|
|
1587
|
-
return resolved;
|
|
1588
|
-
}
|
|
1589
|
-
function resolveFields(fields, registry, blockCache) {
|
|
1590
|
-
return fields.map((field) => resolveField(field, registry, blockCache));
|
|
1591
|
-
}
|
|
1592
|
-
function normalizeSchemaFragment(fragment) {
|
|
1593
|
-
const reusableBlocks = mergeUniqueBlocks(fragment.blocks ?? []);
|
|
1594
|
-
const registry = buildRegistry(reusableBlocks);
|
|
1595
|
-
const blockCache = /* @__PURE__ */ new WeakMap();
|
|
1596
|
-
const resolvedBlocks = reusableBlocks.map(
|
|
1597
|
-
(block) => resolveBlock(block, registry, blockCache)
|
|
1598
|
-
);
|
|
1599
|
-
const resolvedCollections = (fragment.collections ?? []).map(
|
|
1600
|
-
(collection) => ({
|
|
1601
|
-
...collection,
|
|
1602
|
-
fields: resolveFields(collection.fields ?? [], registry, blockCache)
|
|
1603
|
-
})
|
|
1604
|
-
);
|
|
1605
|
-
const resolvedGlobals = (fragment.globals ?? []).map((global) => ({
|
|
1606
|
-
...global,
|
|
1607
|
-
fields: resolveFields(global.fields ?? [], registry, blockCache)
|
|
1608
|
-
}));
|
|
1609
|
-
return {
|
|
1610
|
-
...fragment,
|
|
1611
|
-
...fragment.blocks ? { blocks: resolvedBlocks } : {},
|
|
1612
|
-
...fragment.collections ? { collections: resolvedCollections } : {},
|
|
1613
|
-
...fragment.globals ? { globals: resolvedGlobals } : {}
|
|
1614
|
-
};
|
|
1615
|
-
}
|
|
1616
|
-
function mergeDynamicConfig(baseConfig, dynamic) {
|
|
1617
|
-
const normalizedDynamic = normalizeSchemaFragment({
|
|
1618
|
-
...dynamic,
|
|
1619
|
-
blocks: [...baseConfig.blocks ?? [], ...dynamic.blocks ?? []]
|
|
1620
|
-
});
|
|
1621
|
-
return {
|
|
1622
|
-
...baseConfig,
|
|
1623
|
-
...normalizedDynamic.blocks ? { blocks: normalizedDynamic.blocks } : {},
|
|
1624
|
-
...dynamic.accessPolicies ? {
|
|
1625
|
-
accessPolicies: {
|
|
1626
|
-
...baseConfig.accessPolicies ?? {},
|
|
1627
|
-
...dynamic.accessPolicies
|
|
1628
|
-
}
|
|
1629
|
-
} : {},
|
|
1630
|
-
...dynamic.admin ? { admin: { ...baseConfig.admin, ...dynamic.admin } } : {},
|
|
1631
|
-
...dynamic.adminAuth ? { adminAuth: { ...baseConfig.adminAuth, ...dynamic.adminAuth } } : {},
|
|
1632
|
-
collections: normalizedDynamic.collections ? [...baseConfig.collections, ...normalizedDynamic.collections] : baseConfig.collections,
|
|
1633
|
-
globals: normalizedDynamic.globals ? [...baseConfig.globals, ...normalizedDynamic.globals] : baseConfig.globals
|
|
1634
|
-
};
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
// src/utils/config.ts
|
|
1638
|
-
var AUDIT_COLLECTION_SLUG = "__audit";
|
|
1639
|
-
var SYSTEM_FIELDS = [
|
|
1640
|
-
{
|
|
1641
|
-
name: "createdAt",
|
|
1642
|
-
type: "date",
|
|
1643
|
-
label: "Created At",
|
|
1644
|
-
admin: { readOnly: true, hidden: true }
|
|
1645
|
-
},
|
|
1646
|
-
{
|
|
1647
|
-
name: "updatedAt",
|
|
1648
|
-
type: "date",
|
|
1649
|
-
label: "Updated At",
|
|
1650
|
-
admin: { readOnly: true, hidden: true }
|
|
1651
|
-
},
|
|
1652
|
-
{
|
|
1653
|
-
name: "createdBy",
|
|
1654
|
-
type: "text",
|
|
1655
|
-
label: "Created By",
|
|
1656
|
-
admin: { readOnly: true, hidden: true }
|
|
1657
|
-
},
|
|
1658
|
-
{
|
|
1659
|
-
name: "updatedBy",
|
|
1660
|
-
type: "text",
|
|
1661
|
-
label: "Updated By",
|
|
1662
|
-
admin: { readOnly: true, hidden: true }
|
|
1663
|
-
}
|
|
1664
|
-
];
|
|
1665
|
-
var AUDIT_COLLECTION = {
|
|
1666
|
-
slug: AUDIT_COLLECTION_SLUG,
|
|
1667
|
-
labels: { singular: "Audit Log", plural: "Audit Logs" },
|
|
1668
|
-
fields: [
|
|
1669
|
-
{ name: "collection", type: "text", label: "Collection", required: true },
|
|
1670
|
-
{ name: "documentId", type: "text", label: "Document ID" },
|
|
1671
|
-
{
|
|
1672
|
-
name: "operation",
|
|
1673
|
-
type: "select",
|
|
1674
|
-
label: "Operation",
|
|
1675
|
-
options: ["create", "update", "delete"],
|
|
1676
|
-
required: true
|
|
1677
|
-
},
|
|
1678
|
-
{ name: "user", type: "text", label: "User ID" },
|
|
1679
|
-
{ name: "timestamp", type: "date", label: "Timestamp", required: true },
|
|
1680
|
-
{ name: "changes", type: "json", label: "Changes" }
|
|
1681
|
-
],
|
|
1682
|
-
access: {
|
|
1683
|
-
read: () => false,
|
|
1684
|
-
create: () => false,
|
|
1685
|
-
update: () => false,
|
|
1686
|
-
delete: () => false
|
|
1687
|
-
},
|
|
1688
|
-
admin: { hidden: true }
|
|
1689
|
-
};
|
|
1690
|
-
var WORKFLOW_HISTORY_COLLECTION_CONFIG = {
|
|
1691
|
-
slug: WORKFLOW_HISTORY_COLLECTION,
|
|
1692
|
-
labels: { singular: "Workflow transition", plural: "Workflow transitions" },
|
|
1693
|
-
fields: [
|
|
1694
|
-
{ name: "collection", type: "text", required: true },
|
|
1695
|
-
{ name: "documentId", type: "text", required: true },
|
|
1696
|
-
{ name: "transition", type: "text", required: true },
|
|
1697
|
-
{ name: "from", type: "text", required: true },
|
|
1698
|
-
{ name: "to", type: "text", required: true },
|
|
1699
|
-
{ name: "revision", type: "number", required: true },
|
|
1700
|
-
{ name: "comment", type: "textarea" },
|
|
1701
|
-
{ name: "actorId", type: "text" },
|
|
1702
|
-
{ name: "createdAt", type: "date", required: true }
|
|
1703
|
-
],
|
|
1704
|
-
access: {
|
|
1705
|
-
read: ({ user }) => !!user,
|
|
1706
|
-
create: () => false,
|
|
1707
|
-
update: () => false,
|
|
1708
|
-
delete: () => false
|
|
1709
|
-
},
|
|
1710
|
-
admin: { hidden: true }
|
|
1711
|
-
};
|
|
1712
|
-
var LIFECYCLE_EVENTS_COLLECTION_CONFIG = {
|
|
1713
|
-
slug: LIFECYCLE_EVENTS_COLLECTION,
|
|
1714
|
-
labels: { singular: "Lifecycle event", plural: "Lifecycle events" },
|
|
1715
|
-
fields: [
|
|
1716
|
-
{ name: "name", type: "text", required: true },
|
|
1717
|
-
{ name: "collection", type: "text", required: true },
|
|
1718
|
-
{ name: "documentId", type: "text", required: true },
|
|
1719
|
-
{ name: "occurredAt", type: "date", required: true },
|
|
1720
|
-
{ name: "actorId", type: "text" },
|
|
1721
|
-
{ name: "payload", type: "json", required: true },
|
|
1722
|
-
{ name: "attempts", type: "number", required: true },
|
|
1723
|
-
{
|
|
1724
|
-
name: "status",
|
|
1725
|
-
type: "select",
|
|
1726
|
-
options: ["pending", "processing", "delivered", "failed"],
|
|
1727
|
-
required: true
|
|
1728
|
-
},
|
|
1729
|
-
{ name: "nextAttemptAt", type: "date" },
|
|
1730
|
-
{ name: "deliveredAt", type: "date" },
|
|
1731
|
-
{ name: "lastError", type: "textarea" }
|
|
1732
|
-
],
|
|
1733
|
-
access: {
|
|
1734
|
-
read: ({ user }) => !!user?.roles?.includes("admin"),
|
|
1735
|
-
create: () => false,
|
|
1736
|
-
update: () => false,
|
|
1737
|
-
delete: () => false
|
|
1738
|
-
},
|
|
1739
|
-
admin: { hidden: true }
|
|
1740
|
-
};
|
|
1741
|
-
var AUTH_SESSIONS_COLLECTION_CONFIG = {
|
|
1742
|
-
slug: AUTH_SESSIONS_COLLECTION,
|
|
1743
|
-
labels: { singular: "Auth session", plural: "Auth sessions" },
|
|
1744
|
-
fields: [
|
|
1745
|
-
{ name: "userId", type: "text", required: true },
|
|
1746
|
-
{ name: "email", type: "email", required: true },
|
|
1747
|
-
{ name: "collection", type: "text", required: true },
|
|
1748
|
-
{ name: "authSource", type: "text" },
|
|
1749
|
-
{ name: "providerId", type: "text" },
|
|
1750
|
-
{ name: "lastIp", type: "text" },
|
|
1751
|
-
{ name: "lastSeenAt", type: "date" },
|
|
1752
|
-
{ name: "expiresAt", type: "date" },
|
|
1753
|
-
{ name: "revokedAt", type: "date" }
|
|
1754
|
-
],
|
|
1755
|
-
access: {
|
|
1756
|
-
read: () => false,
|
|
1757
|
-
create: () => false,
|
|
1758
|
-
update: () => false,
|
|
1759
|
-
delete: () => false
|
|
1760
|
-
},
|
|
1761
|
-
admin: { hidden: true }
|
|
1762
|
-
};
|
|
1763
|
-
function normalizeConfig(config) {
|
|
1764
|
-
const schemaAwareConfig = normalizeSchemaFragment(config);
|
|
1765
|
-
assertValidDeclarativeHooksInConfig(schemaAwareConfig, "config");
|
|
1766
|
-
assertValidDeclarativeAccessInConfig(schemaAwareConfig, "config");
|
|
1767
|
-
assertValidAdminConditionsInConfig(schemaAwareConfig, "config");
|
|
1768
|
-
assertValidPreviewUrlsInConfig(schemaAwareConfig, "config");
|
|
1769
|
-
const collections = schemaAwareConfig?.collections || [];
|
|
1770
|
-
const globals = schemaAwareConfig?.globals || [];
|
|
1771
|
-
const needsAudit = collections.some((col) => col.audit);
|
|
1772
|
-
const needsWorkflow = collections.some((col) => col.workflow || col.drafts);
|
|
1773
|
-
const needsAuthSessions = collections.some((col) => !!col.auth);
|
|
1774
|
-
const adminAuthCollectionSlug = getAdminAuthCollection({
|
|
1775
|
-
collections,
|
|
1776
|
-
adminAuth: schemaAwareConfig.adminAuth
|
|
1777
|
-
})?.slug;
|
|
1778
|
-
const normalizedCollections = collections.map((col) => {
|
|
1779
|
-
let fields = col.fields || [];
|
|
1780
|
-
const existingFieldNames = new Set(fields.map((f) => f.name));
|
|
1781
|
-
if (col.auth) {
|
|
1782
|
-
if (!existingFieldNames.has("email")) {
|
|
1783
|
-
fields = [
|
|
1784
|
-
...fields,
|
|
1785
|
-
{
|
|
1786
|
-
name: "email",
|
|
1787
|
-
type: "email",
|
|
1788
|
-
label: "Email",
|
|
1789
|
-
required: true,
|
|
1790
|
-
unique: true,
|
|
1791
|
-
promoted: true,
|
|
1792
|
-
access: {
|
|
1793
|
-
update: "!id"
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
];
|
|
1797
|
-
}
|
|
1798
|
-
if (!existingFieldNames.has("password")) {
|
|
1799
|
-
fields = [
|
|
1800
|
-
...fields,
|
|
1801
|
-
{
|
|
1802
|
-
name: "password",
|
|
1803
|
-
type: "text",
|
|
1804
|
-
label: "Password",
|
|
1805
|
-
required: true,
|
|
1806
|
-
access: {
|
|
1807
|
-
update: "!id || user.id == id"
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
];
|
|
1811
|
-
}
|
|
1812
|
-
if (!existingFieldNames.has("roles")) {
|
|
1813
|
-
fields = [
|
|
1814
|
-
...fields,
|
|
1815
|
-
{
|
|
1816
|
-
name: "roles",
|
|
1817
|
-
type: "select",
|
|
1818
|
-
label: "Roles",
|
|
1819
|
-
defaultValue: [],
|
|
1820
|
-
options: [
|
|
1821
|
-
{ value: "admin", label: "Admin" },
|
|
1822
|
-
{ value: "editor", label: "Editor" },
|
|
1823
|
-
{ value: "viewer", label: "Viewer" }
|
|
1824
|
-
],
|
|
1825
|
-
access: {
|
|
1826
|
-
update: "user.roles && 'admin' in user.roles"
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
];
|
|
1830
|
-
}
|
|
1831
|
-
if (!existingFieldNames.has("status")) {
|
|
1832
|
-
fields = [
|
|
1833
|
-
...fields,
|
|
1834
|
-
{
|
|
1835
|
-
name: "status",
|
|
1836
|
-
type: "select",
|
|
1837
|
-
label: "Status",
|
|
1838
|
-
defaultValue: "active",
|
|
1839
|
-
options: [
|
|
1840
|
-
{ value: "active", label: "Active" },
|
|
1841
|
-
{ value: "pending", label: "Pending" }
|
|
1842
|
-
],
|
|
1843
|
-
access: {
|
|
1844
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
1845
|
-
},
|
|
1846
|
-
admin: {
|
|
1847
|
-
condition: `!(data.roles && "admin" in data.roles)`
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
];
|
|
1851
|
-
}
|
|
1852
|
-
fields = fields.map((field) => {
|
|
1853
|
-
if (field.name === "email") {
|
|
1854
|
-
return {
|
|
1855
|
-
...field,
|
|
1856
|
-
// Email is the login identifier. Keep the integrity constraints
|
|
1857
|
-
// auth relies on even when the field is explicitly redefined, so a
|
|
1858
|
-
// custom `email` field can never silently drop uniqueness.
|
|
1859
|
-
required: true,
|
|
1860
|
-
unique: true,
|
|
1861
|
-
promoted: true,
|
|
1862
|
-
access: {
|
|
1863
|
-
...field.access || {},
|
|
1864
|
-
update: "!id"
|
|
1865
|
-
}
|
|
1866
|
-
};
|
|
1867
|
-
}
|
|
1868
|
-
if (field.name === "password") {
|
|
1869
|
-
return {
|
|
1870
|
-
...field,
|
|
1871
|
-
// Password is required to authenticate; enforce it regardless of
|
|
1872
|
-
// how the field was declared.
|
|
1873
|
-
required: true,
|
|
1874
|
-
admin: { ...field.admin || {} },
|
|
1875
|
-
access: {
|
|
1876
|
-
...field.access || {},
|
|
1877
|
-
update: "!id || user.id == id"
|
|
1878
|
-
}
|
|
1879
|
-
};
|
|
1880
|
-
}
|
|
1881
|
-
if (field.name === "roles") {
|
|
1882
|
-
return {
|
|
1883
|
-
...field,
|
|
1884
|
-
access: {
|
|
1885
|
-
...field.access || {},
|
|
1886
|
-
// Must be an admin; cannot edit own roles (no self-elevation).
|
|
1887
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
1888
|
-
}
|
|
1889
|
-
};
|
|
1890
|
-
}
|
|
1891
|
-
if (field.name === "status") {
|
|
1892
|
-
return {
|
|
1893
|
-
...field,
|
|
1894
|
-
access: {
|
|
1895
|
-
...field.access || {},
|
|
1896
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
1897
|
-
}
|
|
1898
|
-
};
|
|
1899
|
-
}
|
|
1900
|
-
return field;
|
|
1901
|
-
});
|
|
1902
|
-
}
|
|
1903
|
-
if (adminAuthCollectionSlug && col.slug === adminAuthCollectionSlug && schemaAwareConfig.adminAuth?.mode === "external") {
|
|
1904
|
-
const externalAdminFields = [
|
|
1905
|
-
{
|
|
1906
|
-
name: "authProvider",
|
|
1907
|
-
type: "text",
|
|
1908
|
-
label: "Auth Provider",
|
|
1909
|
-
admin: { readOnly: true, hidden: true }
|
|
1910
|
-
},
|
|
1911
|
-
{
|
|
1912
|
-
name: "externalSubject",
|
|
1913
|
-
type: "text",
|
|
1914
|
-
label: "External Subject",
|
|
1915
|
-
admin: { readOnly: true, hidden: true }
|
|
1916
|
-
},
|
|
1917
|
-
{
|
|
1918
|
-
name: "authSource",
|
|
1919
|
-
type: "text",
|
|
1920
|
-
label: "Auth Source",
|
|
1921
|
-
admin: { readOnly: true, hidden: true }
|
|
1922
|
-
},
|
|
1923
|
-
{
|
|
1924
|
-
name: "lastLoginAt",
|
|
1925
|
-
type: "date",
|
|
1926
|
-
label: "Last Login At",
|
|
1927
|
-
admin: { readOnly: true, hidden: true }
|
|
1928
|
-
}
|
|
1929
|
-
];
|
|
1930
|
-
for (const field of externalAdminFields) {
|
|
1931
|
-
if (!existingFieldNames.has(field.name)) {
|
|
1932
|
-
fields = [...fields, field];
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
const updatedFieldNames = new Set(fields.map((f) => f.name));
|
|
1937
|
-
const fieldsToInject = SYSTEM_FIELDS.filter((f) => !updatedFieldNames.has(f.name));
|
|
1938
|
-
const workflow = col.workflow || (col.drafts ? simplePublishingWorkflow() : void 0);
|
|
1939
|
-
return {
|
|
1940
|
-
...col,
|
|
1941
|
-
workflow,
|
|
1942
|
-
fields: [...fields, ...fieldsToInject]
|
|
1943
|
-
};
|
|
1944
|
-
});
|
|
1945
|
-
const hasAuditCollection = normalizedCollections.some((col) => col.slug === AUDIT_COLLECTION_SLUG);
|
|
1946
|
-
const systemCollections = [];
|
|
1947
|
-
if (needsAudit && !hasAuditCollection) systemCollections.push(AUDIT_COLLECTION);
|
|
1948
|
-
if (needsWorkflow && !normalizedCollections.some((col) => col.slug === WORKFLOW_HISTORY_COLLECTION)) {
|
|
1949
|
-
systemCollections.push(WORKFLOW_HISTORY_COLLECTION_CONFIG);
|
|
1950
|
-
}
|
|
1951
|
-
if (needsWorkflow && !normalizedCollections.some((col) => col.slug === LIFECYCLE_EVENTS_COLLECTION)) {
|
|
1952
|
-
systemCollections.push(LIFECYCLE_EVENTS_COLLECTION_CONFIG);
|
|
1953
|
-
}
|
|
1954
|
-
if (needsAuthSessions && !normalizedCollections.some((col) => col.slug === AUTH_SESSIONS_COLLECTION)) {
|
|
1955
|
-
systemCollections.push(AUTH_SESSIONS_COLLECTION_CONFIG);
|
|
1956
|
-
}
|
|
1957
|
-
return {
|
|
1958
|
-
...schemaAwareConfig,
|
|
1959
|
-
collections: [...normalizedCollections, ...systemCollections],
|
|
1960
|
-
globals
|
|
1961
|
-
};
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
// src/utils/hooks.ts
|
|
1965
|
-
import jexl3 from "jexl";
|
|
1966
|
-
async function runCollectionHooks(hooks, args, options = {}) {
|
|
1967
|
-
if (!hooks || hooks.length === 0) {
|
|
1968
|
-
return args.data ?? args.doc ?? args.query ?? void 0;
|
|
1969
|
-
}
|
|
1970
|
-
const payloadKey = args.data !== void 0 ? "data" : args.doc !== void 0 ? "doc" : "query" in args ? "query" : void 0;
|
|
1971
|
-
let currentPayload = payloadKey === void 0 ? void 0 : args[payloadKey];
|
|
1972
|
-
for (const hook of hooks) {
|
|
1973
|
-
try {
|
|
1974
|
-
const hookArgs = {
|
|
1975
|
-
...args,
|
|
1976
|
-
...payloadKey !== void 0 ? { [payloadKey]: currentPayload } : {}
|
|
1977
|
-
};
|
|
1978
|
-
const result = typeof hook === "string" ? await (() => {
|
|
1979
|
-
if (options.surface) {
|
|
1980
|
-
assertValidDeclarativeHookExpression(
|
|
1981
|
-
hook,
|
|
1982
|
-
options.surface,
|
|
1983
|
-
options.path ?? options.surface
|
|
1984
|
-
);
|
|
1985
|
-
}
|
|
1986
|
-
return jexl3.eval(hook, hookArgs);
|
|
1987
|
-
})() : await hook(hookArgs);
|
|
1988
|
-
if (result !== void 0) {
|
|
1989
|
-
if (typeof hook === "string" && options.surface) {
|
|
1990
|
-
assertValidDeclarativeHookResult(
|
|
1991
|
-
result,
|
|
1992
|
-
options.surface,
|
|
1993
|
-
options.path ?? options.surface
|
|
1994
|
-
);
|
|
1995
|
-
}
|
|
1996
|
-
currentPayload = typeof hook === "string" && currentPayload && typeof currentPayload === "object" && !Array.isArray(currentPayload) && result && typeof result === "object" && !Array.isArray(result) ? {
|
|
1997
|
-
...currentPayload,
|
|
1998
|
-
...result
|
|
1999
|
-
} : result;
|
|
2000
|
-
}
|
|
2001
|
-
} catch (err) {
|
|
2002
|
-
if (options.isolated) {
|
|
2003
|
-
console.error("Side-effect hook failed after a successful write", err);
|
|
2004
|
-
} else {
|
|
2005
|
-
throw err;
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
return currentPayload;
|
|
2010
|
-
}
|
|
2011
|
-
async function executeFieldBeforeChange(fields, data, originalDoc, user, db, pathPrefix = "") {
|
|
2012
|
-
if (!data || typeof data !== "object") return data;
|
|
2013
|
-
const result = { ...data };
|
|
2014
|
-
for (const field of fields) {
|
|
2015
|
-
if (!field.name) continue;
|
|
2016
|
-
const fieldPath = pathPrefix ? `${pathPrefix}.${field.name}` : field.name;
|
|
2017
|
-
const value = result[field.name];
|
|
2018
|
-
const origValue = originalDoc?.[field.name];
|
|
2019
|
-
let updatedValue = value;
|
|
2020
|
-
if (field.hooks?.beforeChange) {
|
|
2021
|
-
for (const hook of field.hooks.beforeChange) {
|
|
2022
|
-
const hookArgs = {
|
|
2023
|
-
value: updatedValue,
|
|
2024
|
-
originalDoc: originalDoc ?? void 0,
|
|
2025
|
-
data: result,
|
|
2026
|
-
user,
|
|
2027
|
-
db
|
|
2028
|
-
};
|
|
2029
|
-
updatedValue = typeof hook === "string" ? await (() => {
|
|
2030
|
-
assertValidDeclarativeHookExpression(
|
|
2031
|
-
hook,
|
|
2032
|
-
"field.beforeChange",
|
|
2033
|
-
fieldPath
|
|
2034
|
-
);
|
|
2035
|
-
return jexl3.eval(hook, hookArgs);
|
|
2036
|
-
})() : await hook(hookArgs);
|
|
2037
|
-
}
|
|
2038
|
-
result[field.name] = updatedValue;
|
|
2039
|
-
}
|
|
2040
|
-
if (updatedValue !== void 0 && updatedValue !== null) {
|
|
2041
|
-
if (field.type === "object" && field.fields) {
|
|
2042
|
-
result[field.name] = await executeFieldBeforeChange(
|
|
2043
|
-
field.fields,
|
|
2044
|
-
updatedValue,
|
|
2045
|
-
origValue,
|
|
2046
|
-
user,
|
|
2047
|
-
db,
|
|
2048
|
-
fieldPath
|
|
2049
|
-
);
|
|
2050
|
-
} else if (field.type === "array" && field.fields && Array.isArray(updatedValue)) {
|
|
2051
|
-
const arrayResult = [];
|
|
2052
|
-
for (let i = 0; i < updatedValue.length; i++) {
|
|
2053
|
-
const item = updatedValue[i];
|
|
2054
|
-
const origItem = Array.isArray(origValue) ? origValue[i] : null;
|
|
2055
|
-
arrayResult.push(
|
|
2056
|
-
await executeFieldBeforeChange(
|
|
2057
|
-
field.fields,
|
|
2058
|
-
item,
|
|
2059
|
-
origItem,
|
|
2060
|
-
user,
|
|
2061
|
-
db,
|
|
2062
|
-
fieldPath
|
|
2063
|
-
)
|
|
2064
|
-
);
|
|
2065
|
-
}
|
|
2066
|
-
result[field.name] = arrayResult;
|
|
2067
|
-
} else if (field.type === "blocks" && field.blocks && Array.isArray(updatedValue)) {
|
|
2068
|
-
const blocksResult = [];
|
|
2069
|
-
for (let i = 0; i < updatedValue.length; i++) {
|
|
2070
|
-
const blockData = updatedValue[i];
|
|
2071
|
-
const origBlock = Array.isArray(origValue) ? origValue[i] : null;
|
|
2072
|
-
const blockConfig = field.blocks.find(
|
|
2073
|
-
(b) => b.slug === blockData.blockType
|
|
2074
|
-
);
|
|
2075
|
-
if (blockConfig) {
|
|
2076
|
-
blocksResult.push(
|
|
2077
|
-
await executeFieldBeforeChange(
|
|
2078
|
-
blockConfig.fields,
|
|
2079
|
-
blockData,
|
|
2080
|
-
origBlock,
|
|
2081
|
-
user,
|
|
2082
|
-
db,
|
|
2083
|
-
fieldPath
|
|
2084
|
-
)
|
|
2085
|
-
);
|
|
2086
|
-
} else {
|
|
2087
|
-
blocksResult.push(blockData);
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
result[field.name] = blocksResult;
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
return result;
|
|
2095
|
-
}
|
|
2096
|
-
async function executeFieldAfterRead(fields, doc, user, db) {
|
|
2097
|
-
if (!doc || typeof doc !== "object") return doc;
|
|
2098
|
-
const result = { ...doc };
|
|
2099
|
-
for (const field of fields) {
|
|
2100
|
-
if (!field.name) continue;
|
|
2101
|
-
const value = result[field.name];
|
|
2102
|
-
let updatedValue = value;
|
|
2103
|
-
if (field.hooks?.afterRead) {
|
|
2104
|
-
for (const hook of field.hooks.afterRead) {
|
|
2105
|
-
const typedHook = hook;
|
|
2106
|
-
const hookArgs = {
|
|
2107
|
-
value: updatedValue,
|
|
2108
|
-
doc: result,
|
|
2109
|
-
user,
|
|
2110
|
-
db
|
|
2111
|
-
};
|
|
2112
|
-
updatedValue = await typedHook(hookArgs);
|
|
2113
|
-
}
|
|
2114
|
-
result[field.name] = updatedValue;
|
|
2115
|
-
}
|
|
2116
|
-
if (updatedValue !== void 0 && updatedValue !== null) {
|
|
2117
|
-
if (field.type === "object" && field.fields) {
|
|
2118
|
-
result[field.name] = await executeFieldAfterRead(
|
|
2119
|
-
field.fields,
|
|
2120
|
-
updatedValue,
|
|
2121
|
-
user,
|
|
2122
|
-
db
|
|
2123
|
-
);
|
|
2124
|
-
} else if (field.type === "array" && field.fields && Array.isArray(updatedValue)) {
|
|
2125
|
-
const arrayResult = [];
|
|
2126
|
-
for (const item of updatedValue) {
|
|
2127
|
-
arrayResult.push(
|
|
2128
|
-
await executeFieldAfterRead(
|
|
2129
|
-
field.fields,
|
|
2130
|
-
item,
|
|
2131
|
-
user,
|
|
2132
|
-
db
|
|
2133
|
-
)
|
|
2134
|
-
);
|
|
2135
|
-
}
|
|
2136
|
-
result[field.name] = arrayResult;
|
|
2137
|
-
} else if (field.type === "blocks" && field.blocks && Array.isArray(updatedValue)) {
|
|
2138
|
-
const blocksResult = [];
|
|
2139
|
-
for (const blockData of updatedValue) {
|
|
2140
|
-
const typedBlock = blockData;
|
|
2141
|
-
const blockConfig = field.blocks.find(
|
|
2142
|
-
(b) => b.slug === typedBlock.blockType
|
|
2143
|
-
);
|
|
2144
|
-
if (blockConfig) {
|
|
2145
|
-
blocksResult.push(
|
|
2146
|
-
await executeFieldAfterRead(
|
|
2147
|
-
blockConfig.fields,
|
|
2148
|
-
typedBlock,
|
|
2149
|
-
user,
|
|
2150
|
-
db
|
|
2151
|
-
)
|
|
2152
|
-
);
|
|
2153
|
-
} else {
|
|
2154
|
-
blocksResult.push(blockData);
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
result[field.name] = blocksResult;
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
}
|
|
2161
|
-
return result;
|
|
2162
|
-
}
|
|
2163
|
-
|
|
2164
|
-
// src/utils/openapi.ts
|
|
2165
|
-
function getCollectionLabels(collection) {
|
|
2166
|
-
return collection.labels || { singular: collection.slug, plural: collection.slug };
|
|
2167
|
-
}
|
|
2168
|
-
function getCollectionTag(collection) {
|
|
2169
|
-
return `Collection: ${getCollectionLabels(collection).plural}`;
|
|
2170
|
-
}
|
|
2171
|
-
function getGlobalTag(global) {
|
|
2172
|
-
return `Global: ${global.label || global.slug}`;
|
|
2173
|
-
}
|
|
2174
|
-
function generateOpenApi(config) {
|
|
2175
|
-
const spec = {
|
|
2176
|
-
openapi: "3.0.0",
|
|
2177
|
-
info: {
|
|
2178
|
-
title: "Dyrected API",
|
|
2179
|
-
version: "1.0.0",
|
|
2180
|
-
description: "Automatically generated OpenAPI specification for the Dyrected project."
|
|
2181
|
-
},
|
|
2182
|
-
components: {
|
|
2183
|
-
schemas: {
|
|
2184
|
-
WorkflowMetadata: {
|
|
2185
|
-
type: "object",
|
|
2186
|
-
required: ["state", "revision"],
|
|
2187
|
-
properties: {
|
|
2188
|
-
state: { type: "string" },
|
|
2189
|
-
revision: { type: "integer", minimum: 1 },
|
|
2190
|
-
publishedRevision: { type: "integer", minimum: 1 },
|
|
2191
|
-
publishedAt: { type: "string", format: "date-time" },
|
|
2192
|
-
publishedBy: { type: "string" },
|
|
2193
|
-
availableTransitions: { type: "array", items: { type: "string" } }
|
|
2194
|
-
}
|
|
2195
|
-
},
|
|
2196
|
-
WorkflowTransitionRequest: {
|
|
2197
|
-
type: "object",
|
|
2198
|
-
properties: {
|
|
2199
|
-
expectedRevision: { type: "integer", minimum: 1 },
|
|
2200
|
-
comment: { type: "string" }
|
|
2201
|
-
}
|
|
2202
|
-
},
|
|
2203
|
-
WorkflowHistoryEntry: {
|
|
2204
|
-
type: "object",
|
|
2205
|
-
required: [
|
|
2206
|
-
"collection",
|
|
2207
|
-
"documentId",
|
|
2208
|
-
"transition",
|
|
2209
|
-
"from",
|
|
2210
|
-
"to",
|
|
2211
|
-
"revision",
|
|
2212
|
-
"createdAt"
|
|
2213
|
-
],
|
|
2214
|
-
properties: {
|
|
2215
|
-
id: { type: "string" },
|
|
2216
|
-
collection: { type: "string" },
|
|
2217
|
-
documentId: { type: "string" },
|
|
2218
|
-
transition: { type: "string" },
|
|
2219
|
-
from: { type: "string" },
|
|
2220
|
-
to: { type: "string" },
|
|
2221
|
-
revision: { type: "integer" },
|
|
2222
|
-
comment: { type: "string", nullable: true },
|
|
2223
|
-
actorId: { type: "string", nullable: true },
|
|
2224
|
-
createdAt: { type: "string", format: "date-time" }
|
|
2225
|
-
}
|
|
2226
|
-
},
|
|
2227
|
-
AuditEntry: {
|
|
2228
|
-
type: "object",
|
|
2229
|
-
required: ["collection", "operation", "timestamp"],
|
|
2230
|
-
properties: {
|
|
2231
|
-
id: { type: "string" },
|
|
2232
|
-
collection: { type: "string" },
|
|
2233
|
-
documentId: { type: "string", nullable: true },
|
|
2234
|
-
operation: { type: "string" },
|
|
2235
|
-
user: { type: "string", nullable: true },
|
|
2236
|
-
timestamp: { type: "string", format: "date-time" },
|
|
2237
|
-
changes: {
|
|
2238
|
-
oneOf: [
|
|
2239
|
-
{ type: "string" },
|
|
2240
|
-
{ type: "object", additionalProperties: true },
|
|
2241
|
-
{ type: "null" }
|
|
2242
|
-
]
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
},
|
|
2246
|
-
Error: {
|
|
2247
|
-
type: "object",
|
|
2248
|
-
properties: {
|
|
2249
|
-
message: { type: "string" },
|
|
2250
|
-
errors: {
|
|
2251
|
-
type: "array",
|
|
2252
|
-
items: { type: "object", additionalProperties: true }
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
},
|
|
2256
|
-
AuthCredentials: {
|
|
2257
|
-
type: "object",
|
|
2258
|
-
required: ["email", "password"],
|
|
2259
|
-
properties: {
|
|
2260
|
-
email: { type: "string", format: "email" },
|
|
2261
|
-
password: { type: "string" }
|
|
2262
|
-
}
|
|
2263
|
-
},
|
|
2264
|
-
TokenResponse: {
|
|
2265
|
-
type: "object",
|
|
2266
|
-
properties: {
|
|
2267
|
-
token: { type: "string" },
|
|
2268
|
-
user: { type: "object", additionalProperties: true }
|
|
2269
|
-
}
|
|
2270
|
-
}
|
|
2271
|
-
},
|
|
2272
|
-
securitySchemes: {
|
|
2273
|
-
ApiKeyAuth: {
|
|
2274
|
-
type: "apiKey",
|
|
2275
|
-
in: "header",
|
|
2276
|
-
name: "x-api-key"
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
},
|
|
2280
|
-
paths: {},
|
|
2281
|
-
security: [{ ApiKeyAuth: [] }]
|
|
2282
|
-
};
|
|
2283
|
-
spec.paths["/api/schemas"] = {
|
|
2284
|
-
get: {
|
|
2285
|
-
tags: ["System"],
|
|
2286
|
-
summary: "Get the serialized Dyrected schema",
|
|
2287
|
-
security: [],
|
|
2288
|
-
responses: {
|
|
2289
|
-
200: { description: "Collection and global schema definitions" }
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
};
|
|
2293
|
-
spec.paths["/api/openapi.json"] = {
|
|
2294
|
-
get: {
|
|
2295
|
-
tags: ["System"],
|
|
2296
|
-
summary: "Get the OpenAPI specification",
|
|
2297
|
-
security: [],
|
|
2298
|
-
responses: { 200: { description: "OpenAPI 3.0 document" } }
|
|
2299
|
-
}
|
|
2300
|
-
};
|
|
2301
|
-
spec.paths["/api/docs"] = {
|
|
2302
|
-
get: {
|
|
2303
|
-
tags: ["System"],
|
|
2304
|
-
summary: "Open interactive API documentation",
|
|
2305
|
-
security: [],
|
|
2306
|
-
responses: { 200: { description: "Swagger UI HTML" } }
|
|
2307
|
-
}
|
|
2308
|
-
};
|
|
2309
|
-
spec.paths["/api/dyrected/options/{collection}/{field}"] = {
|
|
2310
|
-
get: {
|
|
2311
|
-
tags: ["System"],
|
|
2312
|
-
summary: "Resolve dynamic field options",
|
|
2313
|
-
parameters: [
|
|
2314
|
-
{
|
|
2315
|
-
name: "collection",
|
|
2316
|
-
in: "path",
|
|
2317
|
-
required: true,
|
|
2318
|
-
schema: { type: "string" }
|
|
2319
|
-
},
|
|
2320
|
-
{
|
|
2321
|
-
name: "field",
|
|
2322
|
-
in: "path",
|
|
2323
|
-
required: true,
|
|
2324
|
-
schema: { type: "string" }
|
|
2325
|
-
}
|
|
2326
|
-
],
|
|
2327
|
-
responses: { 200: { description: "Resolved option items" } }
|
|
2328
|
-
}
|
|
2329
|
-
};
|
|
2330
|
-
spec.paths["/api/preferences/{key}"] = {
|
|
2331
|
-
get: {
|
|
2332
|
-
tags: ["Preferences"],
|
|
2333
|
-
summary: "Get an authenticated user preference",
|
|
2334
|
-
parameters: [
|
|
2335
|
-
{ name: "key", in: "path", required: true, schema: { type: "string" } }
|
|
2336
|
-
],
|
|
2337
|
-
responses: { 200: { description: "Preference value" } }
|
|
2338
|
-
},
|
|
2339
|
-
put: {
|
|
2340
|
-
tags: ["Preferences"],
|
|
2341
|
-
summary: "Set an authenticated user preference",
|
|
2342
|
-
parameters: [
|
|
2343
|
-
{ name: "key", in: "path", required: true, schema: { type: "string" } }
|
|
2344
|
-
],
|
|
2345
|
-
requestBody: {
|
|
2346
|
-
required: true,
|
|
2347
|
-
content: { "application/json": { schema: { type: "object" } } }
|
|
2348
|
-
},
|
|
2349
|
-
responses: { 200: { description: "Updated preference" } }
|
|
2350
|
-
}
|
|
2351
|
-
};
|
|
2352
|
-
spec.paths["/api/preview-token"] = {
|
|
2353
|
-
post: {
|
|
2354
|
-
tags: ["Preview"],
|
|
2355
|
-
summary: "Create a preview token",
|
|
2356
|
-
responses: { 200: { description: "Short-lived preview token" } }
|
|
2357
|
-
}
|
|
2358
|
-
};
|
|
2359
|
-
spec.paths["/api/preview-data"] = {
|
|
2360
|
-
get: {
|
|
2361
|
-
tags: ["Preview"],
|
|
2362
|
-
summary: "Resolve preview data from a token",
|
|
2363
|
-
security: [],
|
|
2364
|
-
parameters: [
|
|
2365
|
-
{
|
|
2366
|
-
name: "token",
|
|
2367
|
-
in: "query",
|
|
2368
|
-
required: true,
|
|
2369
|
-
schema: { type: "string" }
|
|
2370
|
-
}
|
|
2371
|
-
],
|
|
2372
|
-
responses: { 200: { description: "Preview document data" } }
|
|
2373
|
-
}
|
|
2374
|
-
};
|
|
2375
|
-
spec.paths["/api/audit"] = {
|
|
2376
|
-
get: {
|
|
2377
|
-
tags: ["Audit"],
|
|
2378
|
-
summary: "Get audit entries across all readable audited collections",
|
|
2379
|
-
parameters: [
|
|
2380
|
-
{
|
|
2381
|
-
name: "limit",
|
|
2382
|
-
in: "query",
|
|
2383
|
-
schema: { type: "integer", default: 50, maximum: 100 }
|
|
2384
|
-
},
|
|
2385
|
-
{ name: "page", in: "query", schema: { type: "integer", default: 1 } },
|
|
2386
|
-
{
|
|
2387
|
-
name: "where",
|
|
2388
|
-
in: "query",
|
|
2389
|
-
schema: { type: "string" },
|
|
2390
|
-
description: "JSON filter"
|
|
2391
|
-
},
|
|
2392
|
-
{
|
|
2393
|
-
name: "sort",
|
|
2394
|
-
in: "query",
|
|
2395
|
-
schema: { type: "string", default: "-timestamp" }
|
|
2396
|
-
}
|
|
2397
|
-
],
|
|
2398
|
-
responses: {
|
|
2399
|
-
200: {
|
|
2400
|
-
description: "Audit entries",
|
|
2401
|
-
content: {
|
|
2402
|
-
"application/json": {
|
|
2403
|
-
schema: {
|
|
2404
|
-
type: "object",
|
|
2405
|
-
properties: {
|
|
2406
|
-
docs: {
|
|
2407
|
-
type: "array",
|
|
2408
|
-
items: { $ref: "#/components/schemas/AuditEntry" }
|
|
2409
|
-
},
|
|
2410
|
-
total: { type: "integer" },
|
|
2411
|
-
limit: { type: "integer" },
|
|
2412
|
-
page: { type: "integer" }
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
}
|
|
2420
|
-
};
|
|
2421
|
-
for (const collection of config.collections) {
|
|
2422
|
-
spec.components.schemas[collection.slug] = collectionToSchema(collection);
|
|
2423
|
-
}
|
|
2424
|
-
for (const global of config.globals) {
|
|
2425
|
-
spec.components.schemas[global.slug] = globalToSchema(global);
|
|
2426
|
-
}
|
|
2427
|
-
for (const collection of config.collections) {
|
|
2428
|
-
const slug = collection.slug;
|
|
2429
|
-
const path = `/api/collections/${slug}`;
|
|
2430
|
-
const labels = getCollectionLabels(collection);
|
|
2431
|
-
const collectionTag = getCollectionTag(collection);
|
|
2432
|
-
spec.paths[path] = {
|
|
2433
|
-
get: {
|
|
2434
|
-
tags: [collectionTag],
|
|
2435
|
-
summary: `Find ${labels.plural}`,
|
|
2436
|
-
parameters: [
|
|
2437
|
-
{
|
|
2438
|
-
name: "limit",
|
|
2439
|
-
in: "query",
|
|
2440
|
-
schema: { type: "integer", default: 10 }
|
|
2441
|
-
},
|
|
2442
|
-
{
|
|
2443
|
-
name: "page",
|
|
2444
|
-
in: "query",
|
|
2445
|
-
schema: { type: "integer", default: 1 }
|
|
2446
|
-
},
|
|
2447
|
-
{
|
|
2448
|
-
name: "where",
|
|
2449
|
-
in: "query",
|
|
2450
|
-
schema: { type: "string" },
|
|
2451
|
-
description: "JSON filter"
|
|
2452
|
-
},
|
|
2453
|
-
{
|
|
2454
|
-
name: "search",
|
|
2455
|
-
in: "query",
|
|
2456
|
-
schema: { type: "string" },
|
|
2457
|
-
description: "Free-text search across configured searchable fields"
|
|
2458
|
-
},
|
|
2459
|
-
{
|
|
2460
|
-
name: "sort",
|
|
2461
|
-
in: "query",
|
|
2462
|
-
schema: { type: "string" },
|
|
2463
|
-
description: "Sort field (e.g. -createdAt)"
|
|
2464
|
-
}
|
|
2465
|
-
],
|
|
2466
|
-
responses: {
|
|
2467
|
-
200: {
|
|
2468
|
-
description: "Success",
|
|
2469
|
-
content: {
|
|
2470
|
-
"application/json": {
|
|
2471
|
-
schema: {
|
|
2472
|
-
type: "object",
|
|
2473
|
-
properties: {
|
|
2474
|
-
docs: {
|
|
2475
|
-
type: "array",
|
|
2476
|
-
items: { $ref: `#/components/schemas/${slug}` }
|
|
2477
|
-
},
|
|
2478
|
-
total: { type: "integer" },
|
|
2479
|
-
limit: { type: "integer" },
|
|
2480
|
-
page: { type: "integer" }
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
}
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
},
|
|
2488
|
-
post: {
|
|
2489
|
-
tags: [collectionTag],
|
|
2490
|
-
summary: `Create ${labels.singular}`,
|
|
2491
|
-
requestBody: {
|
|
2492
|
-
required: true,
|
|
2493
|
-
content: {
|
|
2494
|
-
"application/json": {
|
|
2495
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
},
|
|
2499
|
-
responses: {
|
|
2500
|
-
201: {
|
|
2501
|
-
description: "Created",
|
|
2502
|
-
content: {
|
|
2503
|
-
"application/json": {
|
|
2504
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
}
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
};
|
|
2511
|
-
spec.paths[`${path}/{id}`] = {
|
|
2512
|
-
get: {
|
|
2513
|
-
tags: [collectionTag],
|
|
2514
|
-
summary: `Get a single ${labels.singular}`,
|
|
2515
|
-
parameters: [
|
|
2516
|
-
{
|
|
2517
|
-
name: "id",
|
|
2518
|
-
in: "path",
|
|
2519
|
-
required: true,
|
|
2520
|
-
schema: { type: "string" }
|
|
2521
|
-
}
|
|
2522
|
-
],
|
|
2523
|
-
responses: {
|
|
2524
|
-
200: {
|
|
2525
|
-
description: "Success",
|
|
2526
|
-
content: {
|
|
2527
|
-
"application/json": {
|
|
2528
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
},
|
|
2534
|
-
patch: {
|
|
2535
|
-
tags: [collectionTag],
|
|
2536
|
-
summary: `Update ${labels.singular}`,
|
|
2537
|
-
parameters: [
|
|
2538
|
-
{
|
|
2539
|
-
name: "id",
|
|
2540
|
-
in: "path",
|
|
2541
|
-
required: true,
|
|
2542
|
-
schema: { type: "string" }
|
|
2543
|
-
}
|
|
2544
|
-
],
|
|
2545
|
-
requestBody: {
|
|
2546
|
-
required: true,
|
|
2547
|
-
content: {
|
|
2548
|
-
"application/json": {
|
|
2549
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
},
|
|
2553
|
-
responses: {
|
|
2554
|
-
200: {
|
|
2555
|
-
description: "Updated",
|
|
2556
|
-
content: {
|
|
2557
|
-
"application/json": {
|
|
2558
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
},
|
|
2564
|
-
delete: {
|
|
2565
|
-
tags: [collectionTag],
|
|
2566
|
-
summary: `Delete ${labels.singular}`,
|
|
2567
|
-
parameters: [
|
|
2568
|
-
{
|
|
2569
|
-
name: "id",
|
|
2570
|
-
in: "path",
|
|
2571
|
-
required: true,
|
|
2572
|
-
schema: { type: "string" }
|
|
2573
|
-
}
|
|
2574
|
-
],
|
|
2575
|
-
responses: {
|
|
2576
|
-
204: { description: "Deleted" }
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
};
|
|
2580
|
-
spec.paths[`${path}/delete-many`] = {
|
|
2581
|
-
delete: {
|
|
2582
|
-
tags: [collectionTag],
|
|
2583
|
-
summary: `Delete multiple ${labels.plural}`,
|
|
2584
|
-
requestBody: {
|
|
2585
|
-
required: true,
|
|
2586
|
-
content: {
|
|
2587
|
-
"application/json": {
|
|
2588
|
-
schema: {
|
|
2589
|
-
type: "object",
|
|
2590
|
-
required: ["ids"],
|
|
2591
|
-
properties: {
|
|
2592
|
-
ids: { type: "array", items: { type: "string" } }
|
|
2593
|
-
}
|
|
2594
|
-
}
|
|
2595
|
-
}
|
|
2596
|
-
}
|
|
2597
|
-
},
|
|
2598
|
-
responses: { 200: { description: "Deleted and failed document IDs" } }
|
|
2599
|
-
}
|
|
2600
|
-
};
|
|
2601
|
-
if (collection.audit) {
|
|
2602
|
-
spec.paths[`${path}/__audit`] = {
|
|
2603
|
-
get: {
|
|
2604
|
-
tags: [collectionTag],
|
|
2605
|
-
summary: `Get ${labels.singular} audit entries`,
|
|
2606
|
-
parameters: [
|
|
2607
|
-
{
|
|
2608
|
-
name: "limit",
|
|
2609
|
-
in: "query",
|
|
2610
|
-
schema: { type: "integer", default: 50, maximum: 100 }
|
|
2611
|
-
},
|
|
2612
|
-
{
|
|
2613
|
-
name: "page",
|
|
2614
|
-
in: "query",
|
|
2615
|
-
schema: { type: "integer", default: 1 }
|
|
2616
|
-
},
|
|
2617
|
-
{
|
|
2618
|
-
name: "where",
|
|
2619
|
-
in: "query",
|
|
2620
|
-
schema: { type: "string" },
|
|
2621
|
-
description: "JSON filter"
|
|
2622
|
-
},
|
|
2623
|
-
{
|
|
2624
|
-
name: "sort",
|
|
2625
|
-
in: "query",
|
|
2626
|
-
schema: { type: "string", default: "-timestamp" }
|
|
2627
|
-
}
|
|
2628
|
-
],
|
|
2629
|
-
responses: {
|
|
2630
|
-
200: {
|
|
2631
|
-
description: "Audit entries for this collection",
|
|
2632
|
-
content: {
|
|
2633
|
-
"application/json": {
|
|
2634
|
-
schema: {
|
|
2635
|
-
type: "object",
|
|
2636
|
-
properties: {
|
|
2637
|
-
docs: {
|
|
2638
|
-
type: "array",
|
|
2639
|
-
items: { $ref: "#/components/schemas/AuditEntry" }
|
|
2640
|
-
},
|
|
2641
|
-
total: { type: "integer" },
|
|
2642
|
-
limit: { type: "integer" },
|
|
2643
|
-
page: { type: "integer" }
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
}
|
|
2647
|
-
}
|
|
2648
|
-
},
|
|
2649
|
-
403: { description: "Collection read access denied" },
|
|
2650
|
-
404: { description: "Audit is not enabled for this collection" }
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
};
|
|
2654
|
-
}
|
|
2655
|
-
if (collection.upload) {
|
|
2656
|
-
spec.paths[`${path}/media`] = {
|
|
2657
|
-
get: {
|
|
2658
|
-
tags: [collectionTag],
|
|
2659
|
-
summary: `List ${labels.plural}`,
|
|
2660
|
-
responses: { 200: { description: "Paginated media documents" } }
|
|
2661
|
-
},
|
|
2662
|
-
post: {
|
|
2663
|
-
tags: [collectionTag],
|
|
2664
|
-
summary: `Upload ${labels.singular}`,
|
|
2665
|
-
requestBody: {
|
|
2666
|
-
required: true,
|
|
2667
|
-
content: {
|
|
2668
|
-
"multipart/form-data": {
|
|
2669
|
-
schema: {
|
|
2670
|
-
type: "object",
|
|
2671
|
-
required: ["file"],
|
|
2672
|
-
properties: { file: { type: "string", format: "binary" } }
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
}
|
|
2676
|
-
},
|
|
2677
|
-
responses: { 201: { description: "Uploaded media document" } }
|
|
2678
|
-
}
|
|
2679
|
-
};
|
|
2680
|
-
spec.paths[`${path}/media/{filename}`] = {
|
|
2681
|
-
get: {
|
|
2682
|
-
tags: [collectionTag],
|
|
2683
|
-
summary: `Serve ${labels.singular} bytes`,
|
|
2684
|
-
parameters: [
|
|
2685
|
-
{
|
|
2686
|
-
name: "filename",
|
|
2687
|
-
in: "path",
|
|
2688
|
-
required: true,
|
|
2689
|
-
schema: { type: "string" }
|
|
2690
|
-
}
|
|
2691
|
-
],
|
|
2692
|
-
security: [],
|
|
2693
|
-
responses: {
|
|
2694
|
-
200: { description: "Stored file" },
|
|
2695
|
-
404: { description: "File not found" }
|
|
2696
|
-
}
|
|
2697
|
-
}
|
|
2698
|
-
};
|
|
2699
|
-
}
|
|
2700
|
-
if (collection.auth) {
|
|
2701
|
-
const publicAuthPost = (summary) => ({
|
|
2702
|
-
tags: [collectionTag],
|
|
2703
|
-
summary,
|
|
2704
|
-
security: [],
|
|
2705
|
-
requestBody: {
|
|
2706
|
-
required: true,
|
|
2707
|
-
content: {
|
|
2708
|
-
"application/json": {
|
|
2709
|
-
schema: { type: "object", additionalProperties: true }
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2712
|
-
},
|
|
2713
|
-
responses: {
|
|
2714
|
-
200: { description: "Success" },
|
|
2715
|
-
400: { description: "Invalid request" }
|
|
2716
|
-
}
|
|
2717
|
-
});
|
|
2718
|
-
spec.paths[`${path}/login`] = {
|
|
2719
|
-
post: {
|
|
2720
|
-
...publicAuthPost(`Log in to ${labels.plural}`),
|
|
2721
|
-
requestBody: {
|
|
2722
|
-
required: true,
|
|
2723
|
-
content: {
|
|
2724
|
-
"application/json": {
|
|
2725
|
-
schema: { $ref: "#/components/schemas/AuthCredentials" }
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
},
|
|
2729
|
-
responses: {
|
|
2730
|
-
200: {
|
|
2731
|
-
description: "Authenticated",
|
|
2732
|
-
content: {
|
|
2733
|
-
"application/json": {
|
|
2734
|
-
schema: { $ref: "#/components/schemas/TokenResponse" }
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
},
|
|
2738
|
-
401: { description: "Invalid credentials" }
|
|
2739
|
-
}
|
|
2740
|
-
}
|
|
2741
|
-
};
|
|
2742
|
-
spec.paths[`${path}/logout`] = {
|
|
2743
|
-
post: {
|
|
2744
|
-
tags: [collectionTag],
|
|
2745
|
-
summary: `Log out of ${labels.plural}`,
|
|
2746
|
-
parameters: [
|
|
2747
|
-
{
|
|
2748
|
-
name: "allSessions",
|
|
2749
|
-
in: "query",
|
|
2750
|
-
required: false,
|
|
2751
|
-
schema: { type: "boolean" },
|
|
2752
|
-
description: "Revoke every active session for this account instead of only the current one."
|
|
2753
|
-
}
|
|
2754
|
-
],
|
|
2755
|
-
responses: { 200: { description: "Logged out" } }
|
|
2756
|
-
}
|
|
2757
|
-
};
|
|
2758
|
-
spec.paths[`${path}/init`] = {
|
|
2759
|
-
get: {
|
|
2760
|
-
tags: [collectionTag],
|
|
2761
|
-
summary: `Get ${labels.plural} initialization state`,
|
|
2762
|
-
security: [],
|
|
2763
|
-
responses: { 200: { description: "Initialization state" } }
|
|
2764
|
-
}
|
|
2765
|
-
};
|
|
2766
|
-
spec.paths[`${path}/first-user`] = {
|
|
2767
|
-
post: publicAuthPost(`Register the first ${labels.singular}`)
|
|
2768
|
-
};
|
|
2769
|
-
spec.paths[`${path}/me`] = {
|
|
2770
|
-
get: {
|
|
2771
|
-
tags: [collectionTag],
|
|
2772
|
-
summary: `Get the current ${labels.singular}`,
|
|
2773
|
-
responses: { 200: { description: "Authenticated user" } }
|
|
2774
|
-
}
|
|
2775
|
-
};
|
|
2776
|
-
spec.paths[`${path}/refresh-token`] = {
|
|
2777
|
-
post: {
|
|
2778
|
-
tags: [collectionTag],
|
|
2779
|
-
summary: "Refresh an authentication token",
|
|
2780
|
-
responses: {
|
|
2781
|
-
200: {
|
|
2782
|
-
description: "Refreshed token for the current active session"
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
}
|
|
2786
|
-
};
|
|
2787
|
-
spec.paths[`${path}/forgot-password`] = {
|
|
2788
|
-
post: publicAuthPost("Request a password reset")
|
|
2789
|
-
};
|
|
2790
|
-
spec.paths[`${path}/reset-password`] = {
|
|
2791
|
-
post: publicAuthPost("Reset a password")
|
|
2792
|
-
};
|
|
2793
|
-
spec.paths[`${path}/invite`] = {
|
|
2794
|
-
post: {
|
|
2795
|
-
tags: [collectionTag],
|
|
2796
|
-
summary: `Invite a ${labels.singular}`,
|
|
2797
|
-
responses: { 200: { description: "Invitation sent" } }
|
|
2798
|
-
}
|
|
2799
|
-
};
|
|
2800
|
-
spec.paths[`${path}/accept-invite`] = {
|
|
2801
|
-
post: publicAuthPost("Accept an invitation")
|
|
2802
|
-
};
|
|
2803
|
-
spec.paths[`${path}/{id}/change-password`] = {
|
|
2804
|
-
post: {
|
|
2805
|
-
tags: [collectionTag],
|
|
2806
|
-
summary: `Change a ${labels.singular} password`,
|
|
2807
|
-
parameters: [
|
|
2808
|
-
{
|
|
2809
|
-
name: "id",
|
|
2810
|
-
in: "path",
|
|
2811
|
-
required: true,
|
|
2812
|
-
schema: { type: "string" }
|
|
2813
|
-
}
|
|
2814
|
-
],
|
|
2815
|
-
responses: {
|
|
2816
|
-
200: {
|
|
2817
|
-
description: "Password changed and active sessions revoked"
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
};
|
|
2822
|
-
}
|
|
2823
|
-
if (collection.workflow) {
|
|
2824
|
-
spec.paths[`${path}/{id}/transitions/{transition}`] = {
|
|
2825
|
-
post: {
|
|
2826
|
-
tags: [collectionTag],
|
|
2827
|
-
summary: `Transition ${labels.singular} workflow`,
|
|
2828
|
-
parameters: [
|
|
2829
|
-
{
|
|
2830
|
-
name: "id",
|
|
2831
|
-
in: "path",
|
|
2832
|
-
required: true,
|
|
2833
|
-
schema: { type: "string" }
|
|
2834
|
-
},
|
|
2835
|
-
{
|
|
2836
|
-
name: "transition",
|
|
2837
|
-
in: "path",
|
|
2838
|
-
required: true,
|
|
2839
|
-
schema: {
|
|
2840
|
-
type: "string",
|
|
2841
|
-
enum: collection.workflow.transitions.map((item) => item.name)
|
|
2842
|
-
}
|
|
2843
|
-
}
|
|
2844
|
-
],
|
|
2845
|
-
requestBody: {
|
|
2846
|
-
content: {
|
|
2847
|
-
"application/json": {
|
|
2848
|
-
schema: {
|
|
2849
|
-
$ref: "#/components/schemas/WorkflowTransitionRequest"
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
},
|
|
2854
|
-
responses: {
|
|
2855
|
-
200: {
|
|
2856
|
-
description: "Transition applied",
|
|
2857
|
-
content: {
|
|
2858
|
-
"application/json": {
|
|
2859
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2860
|
-
}
|
|
2861
|
-
}
|
|
2862
|
-
},
|
|
2863
|
-
400: { description: "Required transition input is missing" },
|
|
2864
|
-
403: { description: "Transition capability denied" },
|
|
2865
|
-
409: { description: "Invalid state or stale revision" }
|
|
2866
|
-
}
|
|
2867
|
-
}
|
|
2868
|
-
};
|
|
2869
|
-
spec.paths[`${path}/{id}/workflow-history`] = {
|
|
2870
|
-
get: {
|
|
2871
|
-
tags: [collectionTag],
|
|
2872
|
-
summary: `Get ${labels.singular} workflow history`,
|
|
2873
|
-
parameters: [
|
|
2874
|
-
{
|
|
2875
|
-
name: "id",
|
|
2876
|
-
in: "path",
|
|
2877
|
-
required: true,
|
|
2878
|
-
schema: { type: "string" }
|
|
2879
|
-
},
|
|
2880
|
-
{
|
|
2881
|
-
name: "limit",
|
|
2882
|
-
in: "query",
|
|
2883
|
-
schema: { type: "integer", default: 50, maximum: 100 }
|
|
2884
|
-
}
|
|
2885
|
-
],
|
|
2886
|
-
responses: {
|
|
2887
|
-
200: {
|
|
2888
|
-
description: "Workflow transition history",
|
|
2889
|
-
content: {
|
|
2890
|
-
"application/json": {
|
|
2891
|
-
schema: {
|
|
2892
|
-
type: "object",
|
|
2893
|
-
properties: {
|
|
2894
|
-
docs: {
|
|
2895
|
-
type: "array",
|
|
2896
|
-
items: {
|
|
2897
|
-
$ref: "#/components/schemas/WorkflowHistoryEntry"
|
|
2898
|
-
}
|
|
2899
|
-
},
|
|
2900
|
-
total: { type: "integer" },
|
|
2901
|
-
limit: { type: "integer" },
|
|
2902
|
-
page: { type: "integer" }
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
}
|
|
2906
|
-
}
|
|
2907
|
-
},
|
|
2908
|
-
403: { description: "Collection read access denied" }
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
};
|
|
2912
|
-
}
|
|
2913
|
-
}
|
|
2914
|
-
for (const global of config.globals) {
|
|
2915
|
-
const slug = global.slug;
|
|
2916
|
-
const path = `/api/globals/${slug}`;
|
|
2917
|
-
const globalTag = getGlobalTag(global);
|
|
2918
|
-
spec.paths[path] = {
|
|
2919
|
-
get: {
|
|
2920
|
-
tags: [globalTag],
|
|
2921
|
-
summary: `Get ${global.label || slug}`,
|
|
2922
|
-
responses: {
|
|
2923
|
-
200: {
|
|
2924
|
-
description: "Success",
|
|
2925
|
-
content: {
|
|
2926
|
-
"application/json": {
|
|
2927
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2928
|
-
}
|
|
2929
|
-
}
|
|
2930
|
-
}
|
|
2931
|
-
}
|
|
2932
|
-
},
|
|
2933
|
-
patch: {
|
|
2934
|
-
tags: [globalTag],
|
|
2935
|
-
summary: `Update ${global.label || slug}`,
|
|
2936
|
-
requestBody: {
|
|
2937
|
-
required: true,
|
|
2938
|
-
content: {
|
|
2939
|
-
"application/json": {
|
|
2940
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
},
|
|
2944
|
-
responses: {
|
|
2945
|
-
200: {
|
|
2946
|
-
description: "Updated",
|
|
2947
|
-
content: {
|
|
2948
|
-
"application/json": {
|
|
2949
|
-
schema: { $ref: `#/components/schemas/${slug}` }
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
};
|
|
2956
|
-
}
|
|
2957
|
-
if (config.storage) {
|
|
2958
|
-
spec.paths["/api/media/{filename}"] = {
|
|
2959
|
-
get: {
|
|
2960
|
-
tags: ["Media"],
|
|
2961
|
-
summary: "Serve a stored file",
|
|
2962
|
-
security: [],
|
|
2963
|
-
parameters: [
|
|
2964
|
-
{
|
|
2965
|
-
name: "filename",
|
|
2966
|
-
in: "path",
|
|
2967
|
-
required: true,
|
|
2968
|
-
schema: { type: "string" }
|
|
2969
|
-
}
|
|
2970
|
-
],
|
|
2971
|
-
responses: {
|
|
2972
|
-
200: { description: "Stored file bytes" },
|
|
2973
|
-
404: { description: "File not found" }
|
|
2974
|
-
}
|
|
2975
|
-
}
|
|
2976
|
-
};
|
|
2977
|
-
}
|
|
2978
|
-
return spec;
|
|
2979
|
-
}
|
|
2980
|
-
function collectionToSchema(collection) {
|
|
2981
|
-
const { properties, required } = fieldsToProperties(collection.fields);
|
|
2982
|
-
return {
|
|
2983
|
-
type: "object",
|
|
2984
|
-
properties: {
|
|
2985
|
-
id: { type: "string" },
|
|
2986
|
-
createdAt: { type: "string", format: "date-time" },
|
|
2987
|
-
updatedAt: { type: "string", format: "date-time" },
|
|
2988
|
-
...collection.workflow ? { _workflow: { $ref: "#/components/schemas/WorkflowMetadata" } } : {},
|
|
2989
|
-
...properties
|
|
2990
|
-
},
|
|
2991
|
-
required: ["id", ...required]
|
|
2992
|
-
};
|
|
2993
|
-
}
|
|
2994
|
-
function globalToSchema(global) {
|
|
2995
|
-
const { properties, required } = fieldsToProperties(global.fields);
|
|
2996
|
-
return {
|
|
2997
|
-
type: "object",
|
|
2998
|
-
properties,
|
|
2999
|
-
required
|
|
3000
|
-
};
|
|
3001
|
-
}
|
|
3002
|
-
function fieldsToProperties(fields) {
|
|
3003
|
-
const props = {};
|
|
3004
|
-
const required = [];
|
|
3005
|
-
for (const field of fields) {
|
|
3006
|
-
if (field.type === "row") {
|
|
3007
|
-
const nested = fieldsToProperties(field.fields || []);
|
|
3008
|
-
Object.assign(props, nested.properties);
|
|
3009
|
-
required.push(...nested.required);
|
|
3010
|
-
continue;
|
|
3011
|
-
}
|
|
3012
|
-
if (!field.name) continue;
|
|
3013
|
-
props[field.name] = fieldToSchema(field);
|
|
3014
|
-
if (field.required) {
|
|
3015
|
-
required.push(field.name);
|
|
3016
|
-
}
|
|
3017
|
-
}
|
|
3018
|
-
return { properties: props, required };
|
|
3019
|
-
}
|
|
3020
|
-
function fieldToSchema(field) {
|
|
3021
|
-
let schema;
|
|
3022
|
-
switch (field.type) {
|
|
3023
|
-
case "text":
|
|
3024
|
-
case "textarea":
|
|
3025
|
-
case "email":
|
|
3026
|
-
schema = { type: "string" };
|
|
3027
|
-
break;
|
|
3028
|
-
case "url":
|
|
3029
|
-
schema = {
|
|
3030
|
-
oneOf: [
|
|
3031
|
-
{ type: "string" },
|
|
3032
|
-
{ type: "object", additionalProperties: true }
|
|
3033
|
-
]
|
|
3034
|
-
};
|
|
3035
|
-
break;
|
|
3036
|
-
case "icon":
|
|
3037
|
-
schema = { type: "string" };
|
|
3038
|
-
break;
|
|
3039
|
-
case "number":
|
|
3040
|
-
schema = { type: "number" };
|
|
3041
|
-
break;
|
|
3042
|
-
case "boolean":
|
|
3043
|
-
schema = { type: "boolean" };
|
|
3044
|
-
break;
|
|
3045
|
-
case "date":
|
|
3046
|
-
schema = { type: "string", format: "date" };
|
|
3047
|
-
break;
|
|
3048
|
-
case "datetime":
|
|
3049
|
-
schema = { type: "string", format: "date-time" };
|
|
3050
|
-
break;
|
|
3051
|
-
case "time":
|
|
3052
|
-
schema = { type: "string", format: "time" };
|
|
3053
|
-
break;
|
|
3054
|
-
case "select":
|
|
3055
|
-
case "radio":
|
|
3056
|
-
schema = {
|
|
3057
|
-
type: "string",
|
|
3058
|
-
enum: Array.isArray(field.options) ? field.options.map((o) => typeof o === "string" ? o : o.value) : void 0
|
|
3059
|
-
};
|
|
3060
|
-
break;
|
|
3061
|
-
case "multiSelect":
|
|
3062
|
-
schema = {
|
|
3063
|
-
type: "array",
|
|
3064
|
-
items: {
|
|
3065
|
-
type: "string",
|
|
3066
|
-
enum: Array.isArray(field.options) ? field.options.map((o) => typeof o === "string" ? o : o.value) : void 0
|
|
3067
|
-
}
|
|
3068
|
-
};
|
|
3069
|
-
break;
|
|
3070
|
-
case "relationship":
|
|
3071
|
-
case "image": {
|
|
3072
|
-
const valueSchema = {
|
|
3073
|
-
type: "string",
|
|
3074
|
-
description: `ID of a ${field.relationTo} record`
|
|
3075
|
-
};
|
|
3076
|
-
schema = field.hasMany ? { type: "array", items: valueSchema } : valueSchema;
|
|
3077
|
-
break;
|
|
3078
|
-
}
|
|
3079
|
-
case "join":
|
|
3080
|
-
schema = {
|
|
3081
|
-
type: "array",
|
|
3082
|
-
readOnly: true,
|
|
3083
|
-
items: { type: "object", additionalProperties: true }
|
|
3084
|
-
};
|
|
3085
|
-
break;
|
|
3086
|
-
case "object": {
|
|
3087
|
-
const { properties, required } = fieldsToProperties(field.fields || []);
|
|
3088
|
-
schema = { type: "object", properties, required };
|
|
3089
|
-
break;
|
|
3090
|
-
}
|
|
3091
|
-
case "array": {
|
|
3092
|
-
const { properties, required } = fieldsToProperties(field.fields || []);
|
|
3093
|
-
schema = {
|
|
3094
|
-
type: "array",
|
|
3095
|
-
items: { type: "object", properties, required }
|
|
3096
|
-
};
|
|
3097
|
-
break;
|
|
3098
|
-
}
|
|
3099
|
-
case "json":
|
|
3100
|
-
case "richText":
|
|
3101
|
-
schema = { type: "object", additionalProperties: true };
|
|
3102
|
-
break;
|
|
3103
|
-
case "blocks":
|
|
3104
|
-
schema = {
|
|
3105
|
-
type: "array",
|
|
3106
|
-
items: {
|
|
3107
|
-
oneOf: field.blocks?.map((block) => {
|
|
3108
|
-
const { properties, required } = fieldsToProperties(block.fields);
|
|
3109
|
-
return {
|
|
3110
|
-
type: "object",
|
|
3111
|
-
properties: {
|
|
3112
|
-
blockType: { type: "string", enum: [block.slug] },
|
|
3113
|
-
...properties
|
|
3114
|
-
},
|
|
3115
|
-
required: ["blockType", ...required]
|
|
3116
|
-
};
|
|
3117
|
-
})
|
|
3118
|
-
}
|
|
3119
|
-
};
|
|
3120
|
-
break;
|
|
3121
|
-
default:
|
|
3122
|
-
schema = { type: "string" };
|
|
3123
|
-
}
|
|
3124
|
-
if (field.label) schema.description = field.label;
|
|
3125
|
-
return schema;
|
|
3126
|
-
}
|
|
3127
|
-
|
|
3128
|
-
// src/detail.ts
|
|
3129
|
-
function normalizeDetailItem(item) {
|
|
3130
|
-
if (typeof item === "string") {
|
|
3131
|
-
return {
|
|
3132
|
-
type: "field",
|
|
3133
|
-
field: item
|
|
3134
|
-
};
|
|
3135
|
-
}
|
|
3136
|
-
return item;
|
|
3137
|
-
}
|
|
3138
|
-
function displaySection(title, items, options) {
|
|
3139
|
-
return {
|
|
3140
|
-
type: "section",
|
|
3141
|
-
title,
|
|
3142
|
-
items,
|
|
3143
|
-
options
|
|
3144
|
-
};
|
|
3145
|
-
}
|
|
3146
|
-
function displayTab(label, items, options) {
|
|
3147
|
-
return {
|
|
3148
|
-
type: "tab",
|
|
3149
|
-
label,
|
|
3150
|
-
items,
|
|
3151
|
-
options
|
|
3152
|
-
};
|
|
3153
|
-
}
|
|
3154
|
-
function displayTabs(tabs, options) {
|
|
3155
|
-
return {
|
|
3156
|
-
type: "tabs",
|
|
3157
|
-
tabs,
|
|
3158
|
-
options
|
|
3159
|
-
};
|
|
3160
|
-
}
|
|
3161
|
-
function displayGrid(columns, items, options) {
|
|
3162
|
-
return {
|
|
3163
|
-
type: "grid",
|
|
3164
|
-
columns,
|
|
3165
|
-
items,
|
|
3166
|
-
options
|
|
3167
|
-
};
|
|
3168
|
-
}
|
|
3169
|
-
function displayField(fieldName, options) {
|
|
3170
|
-
return {
|
|
3171
|
-
type: "field",
|
|
3172
|
-
field: fieldName,
|
|
3173
|
-
options
|
|
3174
|
-
};
|
|
3175
|
-
}
|
|
3176
|
-
function displayRepeat(fieldName, items, options) {
|
|
3177
|
-
return {
|
|
3178
|
-
type: "repeat",
|
|
3179
|
-
field: fieldName,
|
|
3180
|
-
items,
|
|
3181
|
-
options
|
|
3182
|
-
};
|
|
3183
|
-
}
|
|
3184
|
-
function displayComputed(label, expressionOrOptionsOrHandler, options) {
|
|
3185
|
-
let expression;
|
|
3186
|
-
let handler;
|
|
3187
|
-
let finalOptions = options;
|
|
3188
|
-
if (typeof expressionOrOptionsOrHandler === "string") {
|
|
3189
|
-
expression = expressionOrOptionsOrHandler;
|
|
3190
|
-
} else if (typeof expressionOrOptionsOrHandler === "function") {
|
|
3191
|
-
handler = expressionOrOptionsOrHandler;
|
|
3192
|
-
} else if (expressionOrOptionsOrHandler && typeof expressionOrOptionsOrHandler === "object") {
|
|
3193
|
-
expression = expressionOrOptionsOrHandler.expression;
|
|
3194
|
-
handler = expressionOrOptionsOrHandler.handler;
|
|
3195
|
-
finalOptions = {
|
|
3196
|
-
...expressionOrOptionsOrHandler,
|
|
3197
|
-
...options
|
|
3198
|
-
};
|
|
3199
|
-
}
|
|
3200
|
-
const id = finalOptions?.id || label.toLowerCase().trim().replace(/[^a-z0-9]+/g, "_");
|
|
3201
|
-
return {
|
|
3202
|
-
type: "computed",
|
|
3203
|
-
id,
|
|
3204
|
-
label,
|
|
3205
|
-
expression,
|
|
3206
|
-
handler,
|
|
3207
|
-
options: finalOptions
|
|
3208
|
-
};
|
|
3209
|
-
}
|
|
3210
|
-
function displayDivider(options) {
|
|
3211
|
-
return {
|
|
3212
|
-
type: "divider",
|
|
3213
|
-
options
|
|
3214
|
-
};
|
|
3215
|
-
}
|
|
3216
|
-
function displayText(content, options) {
|
|
3217
|
-
return {
|
|
3218
|
-
type: "text",
|
|
3219
|
-
content,
|
|
3220
|
-
options
|
|
3221
|
-
};
|
|
3222
|
-
}
|
|
3223
|
-
function displayCustom(name, options) {
|
|
3224
|
-
return {
|
|
3225
|
-
type: "custom",
|
|
3226
|
-
name,
|
|
3227
|
-
options
|
|
3228
|
-
};
|
|
3229
|
-
}
|
|
3230
|
-
function displayCustomComponent(name, options) {
|
|
3231
|
-
return displayCustom(name, options);
|
|
3232
|
-
}
|
|
3233
|
-
async function evaluateDetailComputed(detail, doc, user, db) {
|
|
3234
|
-
if (!doc || !detail || !Array.isArray(detail)) {
|
|
3235
|
-
return doc;
|
|
3236
|
-
}
|
|
3237
|
-
const computedItems = [];
|
|
3238
|
-
const extractComputed = (items) => {
|
|
3239
|
-
for (const rawItem of items) {
|
|
3240
|
-
if (!rawItem) continue;
|
|
3241
|
-
const item = normalizeDetailItem(rawItem);
|
|
3242
|
-
if (item.type === "computed") {
|
|
3243
|
-
const id = item.id || item.label?.toLowerCase().replace(/[^a-z0-9]+/g, "_");
|
|
3244
|
-
if (id) {
|
|
3245
|
-
computedItems.push({
|
|
3246
|
-
id,
|
|
3247
|
-
label: item.label,
|
|
3248
|
-
expression: item.expression,
|
|
3249
|
-
handler: item.handler
|
|
3250
|
-
});
|
|
3251
|
-
}
|
|
3252
|
-
} else if (item.type === "section" || item.type === "grid" || item.type === "repeat") {
|
|
3253
|
-
if (item.items && Array.isArray(item.items)) {
|
|
3254
|
-
extractComputed(item.items);
|
|
3255
|
-
}
|
|
3256
|
-
} else if (item.type === "tabs" && item.tabs && Array.isArray(item.tabs)) {
|
|
3257
|
-
for (const tab of item.tabs) {
|
|
3258
|
-
if (tab.items) extractComputed(tab.items);
|
|
3259
|
-
}
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
};
|
|
3263
|
-
extractComputed(detail);
|
|
3264
|
-
if (computedItems.length === 0) return doc;
|
|
3265
|
-
const evaluated = {};
|
|
3266
|
-
for (const item of computedItems) {
|
|
3267
|
-
try {
|
|
3268
|
-
if (typeof item.handler === "function") {
|
|
3269
|
-
evaluated[item.id] = await item.handler({ doc, user, db });
|
|
3270
|
-
} else if (item.expression) {
|
|
3271
|
-
evaluated[item.id] = await evaluateJexl(item.expression, { doc, user });
|
|
3272
|
-
}
|
|
3273
|
-
} catch (_err) {
|
|
3274
|
-
evaluated[item.id] = null;
|
|
3275
|
-
}
|
|
3276
|
-
}
|
|
3277
|
-
return {
|
|
3278
|
-
...doc,
|
|
3279
|
-
_meta: {
|
|
3280
|
-
...doc._meta || {},
|
|
3281
|
-
computed: evaluated
|
|
3282
|
-
}
|
|
3283
|
-
};
|
|
3284
|
-
}
|
|
3285
|
-
var SENSITIVE_DETAIL_FIELDS = /* @__PURE__ */ new Set([
|
|
3286
|
-
"password",
|
|
3287
|
-
"salt",
|
|
3288
|
-
"resetPasswordToken",
|
|
3289
|
-
"resetPasswordExpires",
|
|
3290
|
-
"loginAttempts",
|
|
3291
|
-
"lockUntil",
|
|
3292
|
-
"apiKey",
|
|
3293
|
-
"secret"
|
|
3294
|
-
]);
|
|
3295
|
-
function generateDefaultDetailSchema(schema) {
|
|
3296
|
-
const fields = schema.fields || [];
|
|
3297
|
-
const sidebarFieldTypes = /* @__PURE__ */ new Set([
|
|
3298
|
-
"select",
|
|
3299
|
-
"radio",
|
|
3300
|
-
"boolean",
|
|
3301
|
-
"date",
|
|
3302
|
-
"datetime",
|
|
3303
|
-
"relationship"
|
|
3304
|
-
]);
|
|
3305
|
-
const mainFields = [];
|
|
3306
|
-
const sidebarFields = [];
|
|
3307
|
-
for (const field of fields) {
|
|
3308
|
-
if (!field.name) continue;
|
|
3309
|
-
if (SENSITIVE_DETAIL_FIELDS.has(field.name)) continue;
|
|
3310
|
-
if (field.hidden) continue;
|
|
3311
|
-
if (field.admin?.hidden) continue;
|
|
3312
|
-
const isSidebar = sidebarFieldTypes.has(field.type) && field.type !== "relationship" && !field.hasMany;
|
|
3313
|
-
if (isSidebar && sidebarFields.length < 5) {
|
|
3314
|
-
sidebarFields.push(
|
|
3315
|
-
displayField(field.name, {
|
|
3316
|
-
span: 12,
|
|
3317
|
-
display: field.type === "select" || field.type === "radio" ? "badge" : void 0
|
|
3318
|
-
})
|
|
3319
|
-
);
|
|
3320
|
-
} else {
|
|
3321
|
-
const span = field.type === "richText" || field.type === "blocks" || field.type === "textarea" || field.type === "array" || field.type === "json" || field.type === "object" ? 12 : 6;
|
|
3322
|
-
mainFields.push(
|
|
3323
|
-
displayField(field.name, {
|
|
3324
|
-
span
|
|
3325
|
-
})
|
|
3326
|
-
);
|
|
3327
|
-
}
|
|
3328
|
-
}
|
|
3329
|
-
const sections = [];
|
|
3330
|
-
const mainTitle = schema.labels?.singular || schema.label || "Details";
|
|
3331
|
-
if (sidebarFields.length > 0) {
|
|
3332
|
-
sections.push(
|
|
3333
|
-
displaySection(mainTitle, mainFields, {
|
|
3334
|
-
span: 8
|
|
3335
|
-
})
|
|
3336
|
-
);
|
|
3337
|
-
sections.push(
|
|
3338
|
-
displaySection("Overview", sidebarFields, {
|
|
3339
|
-
span: 4
|
|
3340
|
-
})
|
|
3341
|
-
);
|
|
3342
|
-
} else {
|
|
3343
|
-
sections.push(
|
|
3344
|
-
displaySection(mainTitle, mainFields, {
|
|
3345
|
-
span: 12
|
|
3346
|
-
})
|
|
3347
|
-
);
|
|
3348
|
-
}
|
|
3349
|
-
return sections;
|
|
3350
|
-
}
|
|
3351
|
-
function isDetailItemVisible(item, doc, user) {
|
|
3352
|
-
if (!item) return true;
|
|
3353
|
-
const it = normalizeDetailItem(item);
|
|
3354
|
-
const visible = it.options?.visible;
|
|
3355
|
-
if (visible === void 0 || visible === null) return true;
|
|
3356
|
-
if (typeof visible === "boolean") return visible;
|
|
3357
|
-
if (typeof visible === "string") {
|
|
3358
|
-
if (visible.trim().length === 0) return true;
|
|
3359
|
-
try {
|
|
3360
|
-
return Boolean(evaluateJexlSync(visible, { doc, user }));
|
|
3361
|
-
} catch {
|
|
3362
|
-
return true;
|
|
3363
|
-
}
|
|
3364
|
-
}
|
|
3365
|
-
return true;
|
|
3366
|
-
}
|
|
3367
|
-
|
|
3368
|
-
export {
|
|
3369
|
-
signCollectionToken,
|
|
3370
|
-
verifyCollectionToken,
|
|
3371
|
-
issueAuthSessionToken,
|
|
3372
|
-
getAuthSession,
|
|
3373
|
-
isAuthSessionActive,
|
|
3374
|
-
touchAuthSession,
|
|
3375
|
-
revokeAuthSession,
|
|
3376
|
-
revokeAllAuthSessions,
|
|
3377
|
-
WORKFLOW_HISTORY_COLLECTION,
|
|
3378
|
-
LIFECYCLE_EVENTS_COLLECTION,
|
|
3379
|
-
definePublishingWorkflow,
|
|
3380
|
-
publishingWorkflow,
|
|
3381
|
-
simplePublishingWorkflow,
|
|
3382
|
-
workflowCapabilities,
|
|
3383
|
-
canViewWorkflowDraft,
|
|
3384
|
-
availableWorkflowTransitions,
|
|
3385
|
-
initializeWorkflowDocument,
|
|
3386
|
-
publishedStateName,
|
|
3387
|
-
materializeWorkflowDocument,
|
|
3388
|
-
createLifecycleEvent,
|
|
3389
|
-
dispatchLifecycleEvent,
|
|
3390
|
-
dispatchPendingLifecycleEvents,
|
|
3391
|
-
saveWorkflowDraft,
|
|
3392
|
-
createWorkflowDocument,
|
|
3393
|
-
transitionWorkflow,
|
|
3394
|
-
getAdminAuthCollection,
|
|
3395
|
-
resolveAdminAuthCollection,
|
|
3396
|
-
getPublicAdminAuthConfig,
|
|
3397
|
-
mergeDynamicConfig,
|
|
3398
|
-
slugify,
|
|
3399
|
-
lower,
|
|
3400
|
-
upper,
|
|
3401
|
-
trim,
|
|
3402
|
-
capitalize,
|
|
3403
|
-
truncate,
|
|
3404
|
-
readingTime,
|
|
3405
|
-
wordCount,
|
|
3406
|
-
replace,
|
|
3407
|
-
startsWith,
|
|
3408
|
-
endsWith,
|
|
3409
|
-
now,
|
|
3410
|
-
today,
|
|
3411
|
-
formatDate,
|
|
3412
|
-
addDays,
|
|
3413
|
-
diffDays,
|
|
3414
|
-
isPast,
|
|
3415
|
-
isFuture,
|
|
3416
|
-
includes,
|
|
3417
|
-
join,
|
|
3418
|
-
first,
|
|
3419
|
-
last,
|
|
3420
|
-
compact,
|
|
3421
|
-
unique,
|
|
3422
|
-
length,
|
|
3423
|
-
round,
|
|
3424
|
-
clamp,
|
|
3425
|
-
ceil,
|
|
3426
|
-
floor,
|
|
3427
|
-
abs,
|
|
3428
|
-
min,
|
|
3429
|
-
max,
|
|
3430
|
-
pow,
|
|
3431
|
-
sqrt,
|
|
3432
|
-
sum,
|
|
3433
|
-
count,
|
|
3434
|
-
defaultValue,
|
|
3435
|
-
coalesce,
|
|
3436
|
-
isEmpty,
|
|
3437
|
-
get,
|
|
3438
|
-
registerJexlHelpers,
|
|
3439
|
-
evaluateJexl,
|
|
3440
|
-
evaluateJexlSync,
|
|
3441
|
-
BUILTIN_JEXL_HELPERS,
|
|
3442
|
-
validateDeclarativeHookExpression,
|
|
3443
|
-
validateDeclarativeAccessExpression,
|
|
3444
|
-
validateAdminConditionExpression,
|
|
3445
|
-
validatePreviewUrlExpression,
|
|
3446
|
-
assertValidDeclarativeHookExpression,
|
|
3447
|
-
assertValidDeclarativeHookResult,
|
|
3448
|
-
collectDeclarativeHookValidationIssues,
|
|
3449
|
-
collectDeclarativeAccessValidationIssues,
|
|
3450
|
-
collectAdminConditionValidationIssues,
|
|
3451
|
-
collectPreviewUrlValidationIssues,
|
|
3452
|
-
assertValidAdminConditionsInConfig,
|
|
3453
|
-
assertValidPreviewUrlsInConfig,
|
|
3454
|
-
collectConfigDiagnostics,
|
|
3455
|
-
formatConfigDiagnostics,
|
|
3456
|
-
ConfigValidationError,
|
|
3457
|
-
isConfigValidationError,
|
|
3458
|
-
assertValidDeclarativeHooksInConfig,
|
|
3459
|
-
assertValidDeclarativeAccessInConfig,
|
|
3460
|
-
normalizeConfig,
|
|
3461
|
-
runCollectionHooks,
|
|
3462
|
-
executeFieldBeforeChange,
|
|
3463
|
-
executeFieldAfterRead,
|
|
3464
|
-
generateOpenApi,
|
|
3465
|
-
normalizeDetailItem,
|
|
3466
|
-
displaySection,
|
|
3467
|
-
displayTab,
|
|
3468
|
-
displayTabs,
|
|
3469
|
-
displayGrid,
|
|
3470
|
-
displayField,
|
|
3471
|
-
displayRepeat,
|
|
3472
|
-
displayComputed,
|
|
3473
|
-
displayDivider,
|
|
3474
|
-
displayText,
|
|
3475
|
-
displayCustom,
|
|
3476
|
-
displayCustomComponent,
|
|
3477
|
-
evaluateDetailComputed,
|
|
3478
|
-
generateDefaultDetailSchema,
|
|
3479
|
-
isDetailItemVisible
|
|
3480
|
-
};
|