@btst/stack 3.0.0-rc.2 → 3.0.0-rc.4
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/README.md +118 -38
- package/dist/api/index.cjs +133 -29
- package/dist/api/index.d.cts +14 -32
- package/dist/api/index.d.mts +14 -32
- package/dist/api/index.d.ts +14 -32
- package/dist/api/index.mjs +133 -28
- package/dist/authorization/client.cjs +154 -0
- package/dist/authorization/client.d.cts +70 -0
- package/dist/authorization/client.d.mts +70 -0
- package/dist/authorization/client.d.ts +70 -0
- package/dist/authorization/client.mjs +152 -0
- package/dist/authorization/index.cjs +371 -0
- package/dist/authorization/index.d.cts +201 -0
- package/dist/authorization/index.d.mts +201 -0
- package/dist/authorization/index.d.ts +201 -0
- package/dist/authorization/index.mjs +365 -0
- package/dist/authorization/remote.cjs +117 -0
- package/dist/authorization/remote.d.cts +79 -0
- package/dist/authorization/remote.d.mts +79 -0
- package/dist/authorization/remote.d.ts +79 -0
- package/dist/authorization/remote.mjs +111 -0
- package/dist/authorization/server.cjs +77 -0
- package/dist/authorization/server.d.cts +51 -0
- package/dist/authorization/server.d.mts +51 -0
- package/dist/authorization/server.d.ts +51 -0
- package/dist/authorization/server.mjs +73 -0
- package/dist/client/components/index.cjs +1 -0
- package/dist/client/components/index.d.cts +23 -6
- package/dist/client/components/index.d.mts +23 -6
- package/dist/client/components/index.d.ts +23 -6
- package/dist/client/components/index.mjs +1 -1
- package/dist/client/hooks/index.cjs +8 -0
- package/dist/client/hooks/index.d.cts +25 -0
- package/dist/client/hooks/index.d.mts +25 -0
- package/dist/client/hooks/index.d.ts +25 -0
- package/dist/client/hooks/index.mjs +2 -0
- package/dist/client/index.cjs +38 -7
- package/dist/client/index.d.cts +30 -100
- package/dist/client/index.d.mts +30 -100
- package/dist/client/index.d.ts +30 -100
- package/dist/client/index.mjs +38 -7
- package/dist/client/server.cjs +96 -0
- package/dist/client/server.d.cts +57 -0
- package/dist/client/server.d.mts +57 -0
- package/dist/client/server.d.ts +57 -0
- package/dist/client/server.mjs +92 -0
- package/dist/components/auto-form/index.d.cts +2 -2
- package/dist/components/auto-form/index.d.mts +2 -2
- package/dist/components/auto-form/index.d.ts +2 -2
- package/dist/components/form-builder/index.d.cts +1 -1
- package/dist/components/form-builder/index.d.mts +1 -1
- package/dist/components/form-builder/index.d.ts +1 -1
- package/dist/components/stepped-auto-form/index.d.cts +1 -1
- package/dist/components/stepped-auto-form/index.d.mts +1 -1
- package/dist/components/stepped-auto-form/index.d.ts +1 -1
- package/dist/context/index.cjs +8 -2
- package/dist/context/index.d.cts +111 -89
- package/dist/context/index.d.mts +111 -89
- package/dist/context/index.d.ts +111 -89
- package/dist/context/index.mjs +3 -1
- package/dist/index.cjs +1 -2
- package/dist/index.d.cts +8 -3
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.mjs +1 -1
- package/dist/next/index.d.cts +19 -7
- package/dist/next/index.d.mts +19 -7
- package/dist/next/index.d.ts +19 -7
- package/dist/next/server.cjs +7 -0
- package/dist/next/server.d.cts +56 -0
- package/dist/next/server.d.mts +56 -0
- package/dist/next/server.d.ts +56 -0
- package/dist/next/server.mjs +1 -0
- package/dist/packages/stack/src/authorization/json.cjs +57 -0
- package/dist/packages/stack/src/authorization/json.mjs +55 -0
- package/dist/packages/stack/src/client/components/compose.cjs +91 -9
- package/dist/packages/stack/src/client/components/compose.mjs +92 -11
- package/dist/packages/stack/src/client/runtime.cjs +295 -0
- package/dist/packages/stack/src/client/runtime.mjs +293 -0
- package/dist/packages/stack/src/context/auth.cjs +141 -73
- package/dist/packages/stack/src/context/auth.mjs +139 -73
- package/dist/packages/stack/src/context/provider.cjs +11 -5
- package/dist/packages/stack/src/context/provider.mjs +11 -5
- package/dist/packages/stack/src/context/router.cjs +9 -0
- package/dist/packages/stack/src/context/router.mjs +7 -0
- package/dist/packages/stack/src/context/site-navigation.cjs +40 -0
- package/dist/packages/stack/src/context/site-navigation.mjs +38 -0
- package/dist/packages/stack/src/next/layout.cjs +27 -0
- package/dist/packages/stack/src/next/layout.mjs +25 -0
- package/dist/packages/stack/src/plugin-registration.cjs +59 -0
- package/dist/packages/stack/src/plugin-registration.mjs +57 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/lifecycle-migrations.cjs +18 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/lifecycle-migrations.mjs +16 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/operations.cjs +1341 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/operations.mjs +1333 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.cjs +82 -640
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.mjs +78 -641
- package/dist/packages/stack/src/plugins/ai-chat/api/serializers.cjs +23 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/serializers.mjs +20 -0
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-input.cjs +183 -111
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-input.mjs +187 -115
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-interface.cjs +562 -116
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-interface.mjs +567 -121
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-layout.cjs +6 -6
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-layout.mjs +6 -6
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-message.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-message.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-sidebar.cjs +45 -29
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-sidebar.mjs +46 -30
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/404-page.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/404-page.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/chat-page.cjs +46 -7
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/chat-page.internal.cjs +5 -3
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/chat-page.internal.mjs +5 -3
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/chat-page.mjs +48 -9
- package/dist/packages/stack/src/plugins/ai-chat/client/components/shared/default-error.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/shared/default-error.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/tool-call-display.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/tool-call-display.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/hooks/ai-chat-resource.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/hooks/ai-chat-resource.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/hooks/chat-hooks.cjs +179 -19
- package/dist/packages/stack/src/plugins/ai-chat/client/hooks/chat-hooks.mjs +180 -21
- package/dist/packages/stack/src/plugins/ai-chat/client/navigation.cjs +11 -0
- package/dist/packages/stack/src/plugins/ai-chat/client/navigation.mjs +9 -0
- package/dist/packages/stack/src/plugins/ai-chat/client/overrides.cjs +24 -0
- package/dist/packages/stack/src/plugins/ai-chat/client/overrides.mjs +21 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/plugin.cjs +152 -82
- package/dist/packages/stack/src/plugins/ai-chat/client/plugin.mjs +152 -82
- package/dist/packages/stack/src/plugins/api/create-endpoint.cjs +27 -9
- package/dist/packages/stack/src/plugins/api/create-endpoint.mjs +27 -10
- package/dist/packages/stack/src/plugins/api/endpoint-inventory.cjs +125 -0
- package/dist/packages/stack/src/plugins/api/endpoint-inventory.mjs +123 -0
- package/dist/packages/stack/src/plugins/api/operation.cjs +208 -0
- package/dist/packages/stack/src/plugins/api/operation.mjs +198 -0
- package/dist/packages/stack/src/plugins/blog/api/lifecycle-migrations.cjs +17 -0
- package/dist/packages/stack/src/plugins/blog/api/lifecycle-migrations.mjs +15 -0
- package/dist/packages/stack/src/plugins/blog/api/mutations.cjs +10 -2
- package/dist/packages/stack/src/plugins/blog/api/mutations.mjs +10 -2
- package/dist/packages/stack/src/plugins/blog/api/operations.cjs +455 -0
- package/dist/packages/stack/src/plugins/blog/api/operations.mjs +448 -0
- package/dist/packages/stack/src/plugins/blog/api/plugin.cjs +51 -298
- package/dist/packages/stack/src/plugins/blog/api/plugin.mjs +55 -304
- package/dist/packages/stack/src/plugins/blog/client/components/forms/image-field.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/image-field.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/markdown-editor-with-overrides.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/markdown-editor-with-overrides.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/post-forms.cjs +82 -67
- package/dist/packages/stack/src/plugins/blog/client/components/forms/post-forms.mjs +84 -69
- package/dist/packages/stack/src/plugins/blog/client/components/pages/404-page.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/404-page.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.cjs +22 -4
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.mjs +23 -5
- package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.cjs +6 -2
- package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.mjs +6 -2
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.cjs +4 -2
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.mjs +4 -2
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.cjs +30 -3
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.mjs +31 -4
- package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.cjs +4 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.mjs +4 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/collapsible-tag-list.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/collapsible-tag-list.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/default-error.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/default-error.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/on-this-page.cjs +3 -2
- package/dist/packages/stack/src/plugins/blog/client/components/shared/on-this-page.mjs +3 -2
- package/dist/packages/stack/src/plugins/blog/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/post-card.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/post-card.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/posts-list.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/posts-list.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/recent-posts-carousel.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/recent-posts-carousel.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/search-input.cjs +2 -2
- package/dist/packages/stack/src/plugins/blog/client/components/shared/search-input.mjs +1 -1
- package/dist/packages/stack/src/plugins/blog/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/blog/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/blog/client/hooks/blog-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/hooks/blog-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/plugin.cjs +169 -163
- package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +169 -163
- package/dist/packages/stack/src/plugins/client/resource/hooks.cjs +31 -16
- package/dist/packages/stack/src/plugins/client/resource/hooks.mjs +31 -16
- package/dist/packages/stack/src/plugins/client/resource/internal.cjs +66 -52
- package/dist/packages/stack/src/plugins/client/resource/internal.mjs +66 -52
- package/dist/packages/stack/src/plugins/client/resource/use-form.cjs +20 -17
- package/dist/packages/stack/src/plugins/client/resource/use-form.mjs +20 -17
- package/dist/packages/stack/src/plugins/client/resource/use-select.cjs +39 -33
- package/dist/packages/stack/src/plugins/client/resource/use-select.mjs +39 -33
- package/dist/packages/stack/src/plugins/cms/api/lifecycle-migrations.cjs +13 -0
- package/dist/packages/stack/src/plugins/cms/api/lifecycle-migrations.mjs +11 -0
- package/dist/packages/stack/src/plugins/cms/api/operations.cjs +1763 -0
- package/dist/packages/stack/src/plugins/cms/api/operations.mjs +1756 -0
- package/dist/packages/stack/src/plugins/cms/api/plugin.cjs +165 -752
- package/dist/packages/stack/src/plugins/cms/api/plugin.mjs +164 -755
- package/dist/packages/stack/src/plugins/cms/client/components/forms/content-form.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/content-form.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/file-upload.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/file-upload.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/relation-field.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/relation-field.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/inverse-relations-panel.cjs +23 -13
- package/dist/packages/stack/src/plugins/cms/client/components/inverse-relations-panel.mjs +24 -14
- package/dist/packages/stack/src/plugins/cms/client/components/pages/404-page.cjs +5 -4
- package/dist/packages/stack/src/plugins/cms/client/components/pages/404-page.mjs +6 -5
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.cjs +40 -7
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.cjs +15 -9
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.mjs +14 -8
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.mjs +41 -8
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-list-page.cjs +7 -1
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-list-page.internal.cjs +42 -29
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-list-page.internal.mjs +40 -27
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-list-page.mjs +7 -1
- package/dist/packages/stack/src/plugins/cms/client/components/pages/dashboard-page.cjs +4 -1
- package/dist/packages/stack/src/plugins/cms/client/components/pages/dashboard-page.internal.cjs +13 -7
- package/dist/packages/stack/src/plugins/cms/client/components/pages/dashboard-page.internal.mjs +12 -6
- package/dist/packages/stack/src/plugins/cms/client/components/pages/dashboard-page.mjs +4 -1
- package/dist/packages/stack/src/plugins/cms/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/cms/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/cms/client/hooks/cms-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/hooks/cms-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/overrides.cjs +26 -0
- package/dist/packages/stack/src/plugins/cms/client/overrides.mjs +24 -0
- package/dist/packages/stack/src/plugins/cms/client/plugin.cjs +102 -81
- package/dist/packages/stack/src/plugins/cms/client/plugin.mjs +103 -82
- package/dist/packages/stack/src/plugins/comments/api/getters.cjs +6 -2
- package/dist/packages/stack/src/plugins/comments/api/getters.mjs +6 -3
- package/dist/packages/stack/src/plugins/comments/api/lifecycle-migrations.cjs +18 -0
- package/dist/packages/stack/src/plugins/comments/api/lifecycle-migrations.mjs +16 -0
- package/dist/packages/stack/src/plugins/comments/api/mutations.cjs +179 -68
- package/dist/packages/stack/src/plugins/comments/api/mutations.mjs +179 -68
- package/dist/packages/stack/src/plugins/comments/api/operations.cjs +453 -0
- package/dist/packages/stack/src/plugins/comments/api/operations.mjs +445 -0
- package/dist/packages/stack/src/plugins/comments/api/plugin.cjs +51 -276
- package/dist/packages/stack/src/plugins/comments/api/plugin.mjs +48 -277
- package/dist/packages/stack/src/plugins/comments/client/components/comment-count.cjs +32 -5
- package/dist/packages/stack/src/plugins/comments/client/components/comment-count.mjs +34 -7
- package/dist/packages/stack/src/plugins/comments/client/components/comment-thread.cjs +160 -104
- package/dist/packages/stack/src/plugins/comments/client/components/comment-thread.mjs +161 -105
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-page.cjs +14 -2
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-page.internal.cjs +141 -71
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-page.internal.mjs +142 -72
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-page.mjs +14 -2
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-state.cjs +12 -0
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-state.mjs +9 -0
- package/dist/packages/stack/src/plugins/comments/client/components/pages/my-comments-page.cjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/pages/my-comments-page.internal.cjs +40 -26
- package/dist/packages/stack/src/plugins/comments/client/components/pages/my-comments-page.internal.mjs +40 -26
- package/dist/packages/stack/src/plugins/comments/client/components/pages/my-comments-page.mjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/pages/resource-comments-page.cjs +9 -1
- package/dist/packages/stack/src/plugins/comments/client/components/pages/resource-comments-page.internal.cjs +25 -20
- package/dist/packages/stack/src/plugins/comments/client/components/pages/resource-comments-page.internal.mjs +26 -21
- package/dist/packages/stack/src/plugins/comments/client/components/pages/resource-comments-page.mjs +9 -1
- package/dist/packages/stack/src/plugins/comments/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/shared/pagination.cjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/shared/pagination.mjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/comments/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/comments/client/hooks/use-comments.cjs +323 -290
- package/dist/packages/stack/src/plugins/comments/client/hooks/use-comments.mjs +325 -292
- package/dist/packages/stack/src/plugins/comments/client/localization/comments-thread.cjs +1 -0
- package/dist/packages/stack/src/plugins/comments/client/localization/comments-thread.mjs +1 -0
- package/dist/packages/stack/src/plugins/comments/client/plugin.cjs +78 -46
- package/dist/packages/stack/src/plugins/comments/client/plugin.mjs +80 -48
- package/dist/packages/stack/src/plugins/form-builder/api/getters.cjs +9 -0
- package/dist/packages/stack/src/plugins/form-builder/api/getters.mjs +9 -1
- package/dist/packages/stack/src/plugins/form-builder/api/lifecycle-migrations.cjs +15 -0
- package/dist/packages/stack/src/plugins/form-builder/api/lifecycle-migrations.mjs +13 -0
- package/dist/packages/stack/src/plugins/form-builder/api/operations.cjs +1093 -0
- package/dist/packages/stack/src/plugins/form-builder/api/operations.mjs +1082 -0
- package/dist/packages/stack/src/plugins/form-builder/api/plugin.cjs +97 -466
- package/dist/packages/stack/src/plugins/form-builder/api/plugin.mjs +92 -468
- package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.cjs +5 -0
- package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.mjs +5 -0
- package/dist/packages/stack/src/plugins/form-builder/client/components/forms/form-renderer.cjs +41 -11
- package/dist/packages/stack/src/plugins/form-builder/client/components/forms/form-renderer.mjs +42 -12
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/404-page.cjs +8 -5
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/404-page.mjs +9 -6
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-builder-page.cjs +36 -3
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.cjs +32 -11
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.mjs +35 -14
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-builder-page.mjs +37 -4
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-list-page.cjs +6 -1
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.cjs +34 -26
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.mjs +34 -26
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-list-page.mjs +6 -1
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.cjs +24 -7
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +72 -40
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +76 -44
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.mjs +25 -8
- package/dist/packages/stack/src/plugins/form-builder/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/form-builder/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/form-builder/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/form-builder/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/form-builder/client/hooks/form-builder-hooks.cjs +29 -0
- package/dist/packages/stack/src/plugins/form-builder/client/hooks/form-builder-hooks.mjs +28 -1
- package/dist/packages/stack/src/plugins/form-builder/client/hooks/form-builder-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/form-builder/client/hooks/form-builder-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/form-builder/client/plugin.cjs +113 -86
- package/dist/packages/stack/src/plugins/form-builder/client/plugin.mjs +114 -87
- package/dist/packages/stack/src/plugins/form-builder/schemas.cjs +9 -3
- package/dist/packages/stack/src/plugins/form-builder/schemas.mjs +9 -3
- package/dist/packages/stack/src/plugins/kanban/api/getters.cjs +47 -36
- package/dist/packages/stack/src/plugins/kanban/api/getters.mjs +47 -37
- package/dist/packages/stack/src/plugins/kanban/api/lifecycle-migrations.cjs +23 -0
- package/dist/packages/stack/src/plugins/kanban/api/lifecycle-migrations.mjs +21 -0
- package/dist/packages/stack/src/plugins/kanban/api/operations.cjs +1552 -0
- package/dist/packages/stack/src/plugins/kanban/api/operations.mjs +1543 -0
- package/dist/packages/stack/src/plugins/kanban/api/plugin.cjs +64 -631
- package/dist/packages/stack/src/plugins/kanban/api/plugin.mjs +62 -634
- package/dist/packages/stack/src/plugins/kanban/api/serializers.cjs +21 -0
- package/dist/packages/stack/src/plugins/kanban/api/serializers.mjs +21 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/board-form.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/board-form.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/column-form.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/column-form.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/task-form.cjs +72 -54
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/task-form.mjs +74 -56
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/404-page.cjs +4 -6
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/404-page.mjs +5 -7
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/board-page.cjs +22 -6
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/board-page.internal.cjs +82 -77
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/board-page.internal.mjs +83 -78
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/board-page.mjs +23 -7
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/boards-list-page.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/boards-list-page.internal.cjs +34 -24
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/boards-list-page.internal.mjs +35 -25
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/boards-list-page.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/new-board-page.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/new-board-page.internal.cjs +6 -9
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/new-board-page.internal.mjs +7 -10
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/new-board-page.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/column-content.cjs +72 -45
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/column-content.mjs +73 -46
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/default-error.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/default-error.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/kanban-board.cjs +4 -4
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/kanban-board.mjs +4 -4
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/permission-access-any.cjs +23 -0
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/permission-access-any.mjs +21 -0
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/task-card.cjs +54 -17
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/task-card.mjs +55 -18
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/user-avatar.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/user-avatar.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/kanban/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-hooks.cjs +38 -9
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-hooks.mjs +39 -10
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/plugin.cjs +177 -104
- package/dist/packages/stack/src/plugins/kanban/client/plugin.mjs +178 -105
- package/dist/packages/stack/src/plugins/kanban/schemas.cjs +32 -23
- package/dist/packages/stack/src/plugins/kanban/schemas.mjs +33 -21
- package/dist/packages/stack/src/plugins/media/api/lifecycle-migrations.cjs +9 -0
- package/dist/packages/stack/src/plugins/media/api/lifecycle-migrations.mjs +7 -0
- package/dist/packages/stack/src/plugins/media/api/mutations.cjs +7 -2
- package/dist/packages/stack/src/plugins/media/api/mutations.mjs +7 -2
- package/dist/packages/stack/src/plugins/media/api/operations.cjs +1299 -0
- package/dist/packages/stack/src/plugins/media/api/operations.mjs +1290 -0
- package/dist/packages/stack/src/plugins/media/api/plugin.cjs +131 -508
- package/dist/packages/stack/src/plugins/media/api/plugin.mjs +127 -510
- package/dist/packages/stack/src/plugins/media/api/query-key-defs.cjs +26 -2
- package/dist/packages/stack/src/plugins/media/api/query-key-defs.mjs +25 -3
- package/dist/packages/stack/src/plugins/media/api/serializers.cjs +4 -2
- package/dist/packages/stack/src/plugins/media/api/serializers.mjs +4 -2
- package/dist/packages/stack/src/plugins/media/asset-url.cjs +13 -0
- package/dist/packages/stack/src/plugins/media/asset-url.mjs +11 -0
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/asset-card.cjs +10 -10
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/asset-card.mjs +12 -12
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/folder-tree.cjs +47 -27
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/folder-tree.mjs +49 -29
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/index.cjs +225 -180
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/index.mjs +228 -183
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/upload-tab.cjs +1 -8
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/upload-tab.mjs +2 -9
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/url-tab.cjs +0 -6
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/url-tab.mjs +1 -7
- package/dist/packages/stack/src/plugins/media/client/components/pages/library-page.cjs +4 -2
- package/dist/packages/stack/src/plugins/media/client/components/pages/library-page.internal.cjs +92 -75
- package/dist/packages/stack/src/plugins/media/client/components/pages/library-page.internal.mjs +93 -76
- package/dist/packages/stack/src/plugins/media/client/components/pages/library-page.mjs +4 -2
- package/dist/packages/stack/src/plugins/media/client/components/upload-permission-check.cjs +52 -0
- package/dist/packages/stack/src/plugins/media/client/components/upload-permission-check.mjs +49 -0
- package/dist/packages/stack/src/plugins/media/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/media/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/media/client/hooks/media-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/media/client/hooks/media-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/media/client/hooks/use-media.cjs +214 -43
- package/dist/packages/stack/src/plugins/media/client/hooks/use-media.mjs +217 -46
- package/dist/packages/stack/src/plugins/media/client/plugin.cjs +122 -62
- package/dist/packages/stack/src/plugins/media/client/plugin.mjs +123 -63
- package/dist/packages/stack/src/plugins/media/client/upload.cjs +121 -52
- package/dist/packages/stack/src/plugins/media/client/upload.mjs +121 -53
- package/dist/packages/stack/src/plugins/media/db.cjs +8 -0
- package/dist/packages/stack/src/plugins/media/db.mjs +8 -0
- package/dist/packages/stack/src/plugins/open-api/api/generator.cjs +36 -5
- package/dist/packages/stack/src/plugins/open-api/api/generator.mjs +36 -5
- package/dist/packages/stack/src/plugins/open-api/api/plugin.cjs +22 -11
- package/dist/packages/stack/src/plugins/open-api/api/plugin.mjs +22 -11
- package/dist/packages/stack/src/plugins/route-docs/client/components/pages/docs-page.cjs +65 -34
- package/dist/packages/stack/src/plugins/route-docs/client/components/pages/docs-page.mjs +56 -25
- package/dist/packages/stack/src/plugins/route-docs/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/route-docs/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/route-docs/client/hooks.cjs +9 -8
- package/dist/packages/stack/src/plugins/route-docs/client/hooks.mjs +10 -9
- package/dist/packages/stack/src/plugins/route-docs/client/plugin.cjs +143 -75
- package/dist/packages/stack/src/plugins/route-docs/client/plugin.mjs +144 -74
- package/dist/packages/stack/src/plugins/route-docs/client/schema.cjs +26 -0
- package/dist/packages/stack/src/plugins/route-docs/client/schema.mjs +23 -0
- package/dist/packages/stack/src/plugins/route-docs/generator.cjs +7 -4
- package/dist/packages/stack/src/plugins/route-docs/generator.mjs +7 -4
- package/dist/packages/stack/src/plugins/ui-builder/client/components/page-renderer.cjs +41 -12
- package/dist/packages/stack/src/plugins/ui-builder/client/components/page-renderer.mjs +42 -13
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.cjs +37 -3
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.cjs +32 -20
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.mjs +34 -22
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.mjs +38 -4
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-list-page.cjs +8 -2
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-list-page.internal.cjs +37 -19
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-list-page.internal.mjs +38 -20
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-list-page.mjs +8 -2
- package/dist/packages/stack/src/plugins/ui-builder/client/components/shared/default-error.cjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/components/shared/default-error.mjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/hooks/ui-builder-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/hooks/ui-builder-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/overrides.cjs +8 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/overrides.mjs +6 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/plugin.cjs +93 -53
- package/dist/packages/stack/src/plugins/ui-builder/client/plugin.mjs +94 -54
- package/dist/packages/stack/src/plugins/utils.cjs +4 -12
- package/dist/packages/stack/src/plugins/utils.mjs +5 -12
- package/dist/packages/stack/src/react-router/layout.cjs +14 -0
- package/dist/packages/stack/src/react-router/layout.mjs +12 -0
- package/dist/packages/stack/src/react-router/page.cjs +10 -5
- package/dist/packages/stack/src/react-router/page.mjs +11 -6
- package/dist/packages/stack/src/shared/initial-identity.cjs +27 -0
- package/dist/packages/stack/src/shared/initial-identity.mjs +23 -0
- package/dist/packages/stack/src/tanstack/layout.cjs +10 -0
- package/dist/packages/stack/src/tanstack/layout.mjs +8 -0
- package/dist/packages/stack/src/tanstack/page.cjs +6 -2
- package/dist/packages/stack/src/tanstack/page.mjs +6 -2
- package/dist/plugins/ai-chat/api/index.cjs +10 -0
- package/dist/plugins/ai-chat/api/index.d.cts +31 -5
- package/dist/plugins/ai-chat/api/index.d.mts +31 -5
- package/dist/plugins/ai-chat/api/index.d.ts +31 -5
- package/dist/plugins/ai-chat/api/index.mjs +3 -1
- package/dist/plugins/ai-chat/client/components/index.d.cts +1 -1
- package/dist/plugins/ai-chat/client/components/index.d.mts +1 -1
- package/dist/plugins/ai-chat/client/components/index.d.ts +1 -1
- package/dist/plugins/ai-chat/client/hooks/index.cjs +1 -0
- package/dist/plugins/ai-chat/client/hooks/index.d.cts +14 -8
- package/dist/plugins/ai-chat/client/hooks/index.d.mts +14 -8
- package/dist/plugins/ai-chat/client/hooks/index.d.ts +14 -8
- package/dist/plugins/ai-chat/client/hooks/index.mjs +1 -1
- package/dist/plugins/ai-chat/client/index.d.cts +21 -25
- package/dist/plugins/ai-chat/client/index.d.mts +21 -25
- package/dist/plugins/ai-chat/client/index.d.ts +21 -25
- package/dist/plugins/ai-chat/permissions.cjs +90 -0
- package/dist/plugins/ai-chat/permissions.d.cts +84 -0
- package/dist/plugins/ai-chat/permissions.d.mts +84 -0
- package/dist/plugins/ai-chat/permissions.d.ts +84 -0
- package/dist/plugins/ai-chat/permissions.mjs +88 -0
- package/dist/plugins/ai-chat/query-keys.cjs +116 -18
- package/dist/plugins/ai-chat/query-keys.d.cts +6 -2
- package/dist/plugins/ai-chat/query-keys.d.mts +6 -2
- package/dist/plugins/ai-chat/query-keys.d.ts +6 -2
- package/dist/plugins/ai-chat/query-keys.mjs +116 -19
- package/dist/plugins/api/index.cjs +4 -0
- package/dist/plugins/api/index.d.cts +13 -18
- package/dist/plugins/api/index.d.mts +13 -18
- package/dist/plugins/api/index.d.ts +13 -18
- package/dist/plugins/api/index.mjs +1 -0
- package/dist/plugins/blog/api/index.cjs +9 -2
- package/dist/plugins/blog/api/index.d.cts +118 -4
- package/dist/plugins/blog/api/index.d.mts +118 -4
- package/dist/plugins/blog/api/index.d.ts +118 -4
- package/dist/plugins/blog/api/index.mjs +4 -1
- package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
- package/dist/plugins/blog/client/index.d.cts +210 -226
- package/dist/plugins/blog/client/index.d.mts +210 -226
- package/dist/plugins/blog/client/index.d.ts +210 -226
- package/dist/plugins/blog/permissions.cjs +47 -0
- package/dist/plugins/blog/permissions.d.cts +49 -0
- package/dist/plugins/blog/permissions.d.mts +49 -0
- package/dist/plugins/blog/permissions.d.ts +49 -0
- package/dist/plugins/blog/permissions.mjs +45 -0
- package/dist/plugins/blog/query-keys.d.cts +7 -3
- package/dist/plugins/blog/query-keys.d.mts +7 -3
- package/dist/plugins/blog/query-keys.d.ts +7 -3
- package/dist/plugins/client/hooks/index.d.cts +2 -2
- package/dist/plugins/client/hooks/index.d.mts +2 -2
- package/dist/plugins/client/hooks/index.d.ts +2 -2
- package/dist/plugins/client/index.cjs +3 -0
- package/dist/plugins/client/index.d.cts +30 -10
- package/dist/plugins/client/index.d.mts +30 -10
- package/dist/plugins/client/index.d.ts +30 -10
- package/dist/plugins/client/index.mjs +3 -0
- package/dist/plugins/cms/api/index.cjs +7 -0
- package/dist/plugins/cms/api/index.d.cts +173 -4
- package/dist/plugins/cms/api/index.d.mts +173 -4
- package/dist/plugins/cms/api/index.d.ts +173 -4
- package/dist/plugins/cms/api/index.mjs +2 -0
- package/dist/plugins/cms/client/hooks/index.d.cts +1 -1
- package/dist/plugins/cms/client/hooks/index.d.mts +1 -1
- package/dist/plugins/cms/client/hooks/index.d.ts +1 -1
- package/dist/plugins/cms/client/index.d.cts +188 -184
- package/dist/plugins/cms/client/index.d.mts +188 -184
- package/dist/plugins/cms/client/index.d.ts +188 -184
- package/dist/plugins/cms/permissions.cjs +46 -0
- package/dist/plugins/cms/permissions.d.cts +42 -0
- package/dist/plugins/cms/permissions.d.mts +42 -0
- package/dist/plugins/cms/permissions.d.ts +42 -0
- package/dist/plugins/cms/permissions.mjs +44 -0
- package/dist/plugins/cms/query-keys.d.cts +4 -4
- package/dist/plugins/cms/query-keys.d.mts +4 -4
- package/dist/plugins/cms/query-keys.d.ts +4 -4
- package/dist/plugins/comments/api/index.cjs +10 -0
- package/dist/plugins/comments/api/index.d.cts +54 -18
- package/dist/plugins/comments/api/index.d.mts +54 -18
- package/dist/plugins/comments/api/index.d.ts +54 -18
- package/dist/plugins/comments/api/index.mjs +3 -0
- package/dist/plugins/comments/client/components/index.d.cts +2 -2
- package/dist/plugins/comments/client/components/index.d.mts +2 -2
- package/dist/plugins/comments/client/components/index.d.ts +2 -2
- package/dist/plugins/comments/client/hooks/index.d.cts +12 -18
- package/dist/plugins/comments/client/hooks/index.d.mts +12 -18
- package/dist/plugins/comments/client/hooks/index.d.ts +12 -18
- package/dist/plugins/comments/client/index.d.cts +96 -114
- package/dist/plugins/comments/client/index.d.mts +96 -114
- package/dist/plugins/comments/client/index.d.ts +96 -114
- package/dist/plugins/comments/permissions.cjs +70 -0
- package/dist/plugins/comments/permissions.d.cts +76 -0
- package/dist/plugins/comments/permissions.d.mts +76 -0
- package/dist/plugins/comments/permissions.d.ts +76 -0
- package/dist/plugins/comments/permissions.mjs +68 -0
- package/dist/plugins/comments/query-keys.cjs +1 -1
- package/dist/plugins/comments/query-keys.d.cts +16 -19
- package/dist/plugins/comments/query-keys.d.mts +16 -19
- package/dist/plugins/comments/query-keys.d.ts +16 -19
- package/dist/plugins/comments/query-keys.mjs +1 -1
- package/dist/plugins/form-builder/api/index.cjs +8 -0
- package/dist/plugins/form-builder/api/index.d.cts +115 -4
- package/dist/plugins/form-builder/api/index.d.mts +115 -4
- package/dist/plugins/form-builder/api/index.d.ts +115 -4
- package/dist/plugins/form-builder/api/index.mjs +4 -1
- package/dist/plugins/form-builder/client/components/index.d.cts +6 -2
- package/dist/plugins/form-builder/client/components/index.d.mts +6 -2
- package/dist/plugins/form-builder/client/components/index.d.ts +6 -2
- package/dist/plugins/form-builder/client/hooks/index.cjs +2 -0
- package/dist/plugins/form-builder/client/hooks/index.d.cts +34 -8
- package/dist/plugins/form-builder/client/hooks/index.d.mts +34 -8
- package/dist/plugins/form-builder/client/hooks/index.d.ts +34 -8
- package/dist/plugins/form-builder/client/hooks/index.mjs +1 -1
- package/dist/plugins/form-builder/client/index.d.cts +153 -174
- package/dist/plugins/form-builder/client/index.d.mts +153 -174
- package/dist/plugins/form-builder/client/index.d.ts +153 -174
- package/dist/plugins/form-builder/permissions.cjs +95 -0
- package/dist/plugins/form-builder/permissions.d.cts +94 -0
- package/dist/plugins/form-builder/permissions.d.mts +94 -0
- package/dist/plugins/form-builder/permissions.d.ts +94 -0
- package/dist/plugins/form-builder/permissions.mjs +93 -0
- package/dist/plugins/form-builder/query-keys.cjs +11 -4
- package/dist/plugins/form-builder/query-keys.d.cts +38 -12
- package/dist/plugins/form-builder/query-keys.d.mts +38 -12
- package/dist/plugins/form-builder/query-keys.d.ts +38 -12
- package/dist/plugins/form-builder/query-keys.mjs +11 -4
- package/dist/plugins/kanban/api/index.cjs +9 -0
- package/dist/plugins/kanban/api/index.d.cts +137 -5
- package/dist/plugins/kanban/api/index.d.mts +137 -5
- package/dist/plugins/kanban/api/index.d.ts +137 -5
- package/dist/plugins/kanban/api/index.mjs +5 -2
- package/dist/plugins/kanban/client/components/index.d.cts +18 -10
- package/dist/plugins/kanban/client/components/index.d.mts +18 -10
- package/dist/plugins/kanban/client/components/index.d.ts +18 -10
- package/dist/plugins/kanban/client/hooks/index.d.cts +15 -7
- package/dist/plugins/kanban/client/hooks/index.d.mts +15 -7
- package/dist/plugins/kanban/client/hooks/index.d.ts +15 -7
- package/dist/plugins/kanban/client/index.d.cts +32 -28
- package/dist/plugins/kanban/client/index.d.mts +32 -28
- package/dist/plugins/kanban/client/index.d.ts +32 -28
- package/dist/plugins/kanban/permissions.cjs +101 -0
- package/dist/plugins/kanban/permissions.d.cts +109 -0
- package/dist/plugins/kanban/permissions.d.mts +109 -0
- package/dist/plugins/kanban/permissions.d.ts +109 -0
- package/dist/plugins/kanban/permissions.mjs +99 -0
- package/dist/plugins/kanban/query-keys.cjs +14 -15
- package/dist/plugins/kanban/query-keys.d.cts +63 -42
- package/dist/plugins/kanban/query-keys.d.mts +63 -42
- package/dist/plugins/kanban/query-keys.d.ts +63 -42
- package/dist/plugins/kanban/query-keys.mjs +14 -15
- package/dist/plugins/media/api/adapters/local.d.cts +1 -1
- package/dist/plugins/media/api/adapters/local.d.mts +1 -1
- package/dist/plugins/media/api/adapters/local.d.ts +1 -1
- package/dist/plugins/media/api/adapters/s3.d.cts +1 -1
- package/dist/plugins/media/api/adapters/s3.d.mts +1 -1
- package/dist/plugins/media/api/adapters/s3.d.ts +1 -1
- package/dist/plugins/media/api/adapters/vercel-blob.cjs +46 -0
- package/dist/plugins/media/api/adapters/vercel-blob.d.cts +6 -9
- package/dist/plugins/media/api/adapters/vercel-blob.d.mts +6 -9
- package/dist/plugins/media/api/adapters/vercel-blob.d.ts +6 -9
- package/dist/plugins/media/api/adapters/vercel-blob.mjs +46 -0
- package/dist/plugins/media/api/index.cjs +10 -0
- package/dist/plugins/media/api/index.d.cts +93 -6
- package/dist/plugins/media/api/index.d.mts +93 -6
- package/dist/plugins/media/api/index.d.ts +93 -6
- package/dist/plugins/media/api/index.mjs +2 -0
- package/dist/plugins/media/client/components/index.d.cts +1 -1
- package/dist/plugins/media/client/components/index.d.mts +1 -1
- package/dist/plugins/media/client/components/index.d.ts +1 -1
- package/dist/plugins/media/client/hooks/index.d.cts +20 -10
- package/dist/plugins/media/client/hooks/index.d.mts +20 -10
- package/dist/plugins/media/client/hooks/index.d.ts +20 -10
- package/dist/plugins/media/client/index.cjs +1 -0
- package/dist/plugins/media/client/index.d.cts +112 -100
- package/dist/plugins/media/client/index.d.mts +112 -100
- package/dist/plugins/media/client/index.d.ts +112 -100
- package/dist/plugins/media/client/index.mjs +1 -1
- package/dist/plugins/media/permissions.cjs +63 -0
- package/dist/plugins/media/permissions.d.cts +64 -0
- package/dist/plugins/media/permissions.d.mts +64 -0
- package/dist/plugins/media/permissions.d.ts +64 -0
- package/dist/plugins/media/permissions.mjs +61 -0
- package/dist/plugins/media/query-keys.cjs +29 -17
- package/dist/plugins/media/query-keys.d.cts +24 -31
- package/dist/plugins/media/query-keys.d.mts +24 -31
- package/dist/plugins/media/query-keys.d.ts +24 -31
- package/dist/plugins/media/query-keys.mjs +30 -18
- package/dist/plugins/open-api/api/index.d.cts +9 -4
- package/dist/plugins/open-api/api/index.d.mts +9 -4
- package/dist/plugins/open-api/api/index.d.ts +9 -4
- package/dist/plugins/route-docs/client/index.cjs +2 -2
- package/dist/plugins/route-docs/client/index.d.cts +54 -53
- package/dist/plugins/route-docs/client/index.d.mts +54 -53
- package/dist/plugins/route-docs/client/index.d.ts +54 -53
- package/dist/plugins/route-docs/client/index.mjs +2 -1
- package/dist/plugins/ui-builder/client/components/index.d.cts +8 -5
- package/dist/plugins/ui-builder/client/components/index.d.mts +8 -5
- package/dist/plugins/ui-builder/client/components/index.d.ts +8 -5
- package/dist/plugins/ui-builder/client/hooks/index.d.cts +5 -5
- package/dist/plugins/ui-builder/client/hooks/index.d.mts +5 -5
- package/dist/plugins/ui-builder/client/hooks/index.d.ts +5 -5
- package/dist/plugins/ui-builder/client/index.d.cts +151 -199
- package/dist/plugins/ui-builder/client/index.d.mts +151 -199
- package/dist/plugins/ui-builder/client/index.d.ts +151 -199
- package/dist/plugins/ui-builder/index.d.cts +11 -8
- package/dist/plugins/ui-builder/index.d.mts +11 -8
- package/dist/plugins/ui-builder/index.d.ts +11 -8
- package/dist/plugins/ui-builder/query-keys.d.cts +6 -6
- package/dist/plugins/ui-builder/query-keys.d.mts +6 -6
- package/dist/plugins/ui-builder/query-keys.d.ts +6 -6
- package/dist/react-router/index.cjs +2 -0
- package/dist/react-router/index.d.cts +29 -5
- package/dist/react-router/index.d.mts +29 -5
- package/dist/react-router/index.d.ts +29 -5
- package/dist/react-router/index.mjs +1 -0
- package/dist/shared/stack.0O62uXqP.d.ts +613 -0
- package/dist/shared/stack.0y6iTP03.d.ts +533 -0
- package/dist/shared/{stack.CbZenbej.d.cts → stack.1ukVJym7.d.cts} +3 -4
- package/dist/shared/{stack.CbZenbej.d.mts → stack.1ukVJym7.d.mts} +3 -4
- package/dist/shared/{stack.CbZenbej.d.ts → stack.1ukVJym7.d.ts} +3 -4
- package/dist/shared/stack.3Sr6qRtT.d.ts +507 -0
- package/dist/shared/{stack.9BAOaSqE.d.cts → stack.5_zzCejP.d.cts} +16 -14
- package/dist/shared/{stack.9BAOaSqE.d.mts → stack.5_zzCejP.d.mts} +16 -14
- package/dist/shared/{stack.9BAOaSqE.d.ts → stack.5_zzCejP.d.ts} +16 -14
- package/dist/shared/{stack.oVIdV7XS.d.mts → stack.94kN3pEK.d.mts} +4 -4
- package/dist/shared/stack.B1UrNoVl.d.mts +533 -0
- package/dist/shared/{stack.B2xi4jj7.d.cts → stack.B1srlBud.d.mts} +2 -2
- package/dist/shared/stack.B3_aDcYL.d.cts +281 -0
- package/dist/shared/stack.B3_aDcYL.d.mts +281 -0
- package/dist/shared/stack.B3_aDcYL.d.ts +281 -0
- package/dist/shared/stack.B5yPgHsp.d.mts +507 -0
- package/dist/shared/stack.BFP_9pRX.d.cts +707 -0
- package/dist/shared/stack.BJx1ZXrN.d.cts +118 -0
- package/dist/shared/{stack.7b3vsM8_.d.ts → stack.BK9Z2dcL.d.ts} +2 -2
- package/dist/shared/stack.BMHoxAn7.d.mts +707 -0
- package/dist/shared/stack.BMlTZnZp.d.ts +764 -0
- package/dist/shared/stack.BMmvEBH_.d.ts +118 -0
- package/dist/shared/stack.BPLykw4s.d.ts +436 -0
- package/dist/shared/{stack.aqVZ6PEW.d.mts → stack.BRvqQWGt.d.cts} +40 -1
- package/dist/shared/{stack.aqVZ6PEW.d.cts → stack.BRvqQWGt.d.mts} +40 -1
- package/dist/shared/{stack.aqVZ6PEW.d.ts → stack.BRvqQWGt.d.ts} +40 -1
- package/dist/shared/stack.BSACE667.d.cts +23 -0
- package/dist/shared/{stack.DzwZw-Ck.d.cts → stack.BTStHVTy.d.cts} +4 -4
- package/dist/shared/stack.BV0uNV4f.d.cts +764 -0
- package/dist/shared/stack.BYMentwB.d.cts +47 -0
- package/dist/shared/stack.BYMentwB.d.mts +47 -0
- package/dist/shared/stack.BYMentwB.d.ts +47 -0
- package/dist/shared/stack.BggTHKlo.d.mts +1184 -0
- package/dist/shared/stack.Bt8hfw9o.d.ts +707 -0
- package/dist/shared/{stack.D7bewlgt.d.mts → stack.Bu2IPOLi.d.cts} +1 -0
- package/dist/shared/{stack.D7bewlgt.d.ts → stack.Bu2IPOLi.d.mts} +1 -0
- package/dist/shared/{stack.D7bewlgt.d.cts → stack.Bu2IPOLi.d.ts} +1 -0
- package/dist/shared/stack.BzWGB5MG.d.cts +436 -0
- package/dist/shared/stack.C3bU9w6L.d.ts +351 -0
- package/dist/shared/stack.C4oVW2qK.d.cts +507 -0
- package/dist/shared/stack.CGmh-Lpe.d.ts +408 -0
- package/dist/shared/stack.CKXzdGiJ.d.cts +3 -0
- package/dist/shared/stack.CKXzdGiJ.d.mts +3 -0
- package/dist/shared/stack.CKXzdGiJ.d.ts +3 -0
- package/dist/shared/{stack.C3GBG8in.d.ts → stack.COrJrztD.d.cts} +1 -1
- package/dist/shared/{stack.C3GBG8in.d.cts → stack.COrJrztD.d.mts} +1 -1
- package/dist/shared/{stack.C3GBG8in.d.mts → stack.COrJrztD.d.ts} +1 -1
- package/dist/shared/stack.Cbd7sD5M.d.mts +118 -0
- package/dist/shared/{stack.B9NtGpAR.d.ts → stack.CcjENrr4.d.cts} +1 -5
- package/dist/shared/stack.CfK5NKlK.d.mts +613 -0
- package/dist/shared/stack.Cmg7lzzy.d.cts +44 -0
- package/dist/shared/stack.Cmg7lzzy.d.mts +44 -0
- package/dist/shared/stack.Cmg7lzzy.d.ts +44 -0
- package/dist/shared/stack.CpE1mS3p.d.ts +331 -0
- package/dist/shared/stack.CskhFw3z.d.mts +23 -0
- package/dist/shared/stack.CtrnoQgH.d.cts +1184 -0
- package/dist/shared/stack.CvlC5kqe.d.cts +331 -0
- package/dist/shared/stack.CxKc9evq.d.ts +23 -0
- package/dist/shared/{stack.lkebw2nj.d.mts → stack.DVEjWKCT.d.cts} +19 -5
- package/dist/shared/{stack.lkebw2nj.d.ts → stack.DVEjWKCT.d.mts} +19 -5
- package/dist/shared/{stack.lkebw2nj.d.cts → stack.DVEjWKCT.d.ts} +19 -5
- package/dist/shared/{stack.Cp_6mO5s.d.mts → stack.DbbvHbhn.d.mts} +1 -5
- package/dist/shared/{stack.DseBJmGF.d.ts → stack.DfrRYOIl.d.ts} +4 -4
- package/dist/shared/stack.DiuRuzIs.d.cts +613 -0
- package/dist/shared/{stack.BMlLOMED.d.cts → stack.DjGixVx3.d.cts} +6 -2
- package/dist/shared/{stack.BMlLOMED.d.mts → stack.DjGixVx3.d.mts} +6 -2
- package/dist/shared/{stack.BMlLOMED.d.ts → stack.DjGixVx3.d.ts} +6 -2
- package/dist/shared/stack.DlCycSM-.d.mts +331 -0
- package/dist/shared/{stack.DycBcTeg.d.mts → stack.DmpPDPxA.d.cts} +2 -2
- package/dist/shared/stack.Doy2_wgl.d.mts +408 -0
- package/dist/shared/stack.DxHPKr2R.d.mts +436 -0
- package/dist/shared/stack.Mak7pzIV.d.cts +533 -0
- package/dist/shared/stack.OYT8WU4n.d.mts +351 -0
- package/dist/shared/{stack.CPsYC2-Z.d.cts → stack.fdi94T4S.d.cts} +7 -7
- package/dist/shared/{stack.CPsYC2-Z.d.mts → stack.fdi94T4S.d.mts} +7 -7
- package/dist/shared/{stack.CPsYC2-Z.d.ts → stack.fdi94T4S.d.ts} +7 -7
- package/dist/shared/{stack.Dlgtumru.d.cts → stack.kaCV7vEL.d.ts} +1 -5
- package/dist/shared/stack.lPKwd_v0.d.ts +1184 -0
- package/dist/shared/stack.lsbdKRj7.d.mts +764 -0
- package/dist/shared/stack.v2O65JqF.d.cts +351 -0
- package/dist/shared/stack.zch70Loj.d.cts +408 -0
- package/dist/tanstack/index.cjs +2 -0
- package/dist/tanstack/index.d.cts +27 -5
- package/dist/tanstack/index.d.mts +27 -5
- package/dist/tanstack/index.d.ts +27 -5
- package/dist/tanstack/index.mjs +1 -0
- package/dist/tanstack/server.cjs +9 -0
- package/dist/tanstack/server.d.cts +15 -0
- package/dist/tanstack/server.d.mts +15 -0
- package/dist/tanstack/server.d.ts +15 -0
- package/dist/tanstack/server.mjs +7 -0
- package/package.json +198 -3
- package/src/__tests__/ai-chat-client-runtime.test.ts +481 -0
- package/src/__tests__/ai-chat-client-runtime.typecheck.tsx +130 -0
- package/src/__tests__/ai-chat-lifecycle-migrations.typecheck.ts +61 -0
- package/src/__tests__/ai-chat-query-keys.test.ts +125 -22
- package/src/__tests__/auth-provider.test.tsx +41 -314
- package/src/__tests__/auth-test-utils.ts +24 -0
- package/src/__tests__/authorization-client.test.tsx +767 -0
- package/src/__tests__/authorization-contraction.test.ts +182 -0
- package/src/__tests__/authorization-remote.test.ts +222 -0
- package/src/__tests__/authorization-server.test.ts +90 -0
- package/src/__tests__/authorization.test.ts +652 -0
- package/src/__tests__/authorization.typecheck.ts +671 -0
- package/src/__tests__/backend-plugin-factories.test.ts +54 -0
- package/src/__tests__/backend-plugin-factories.typecheck.ts +133 -0
- package/src/__tests__/client-plugin-ssr-loaders.test.ts +304 -138
- package/src/__tests__/client-runtime.test.ts +1021 -0
- package/src/__tests__/client-runtime.typecheck.ts +107 -0
- package/src/__tests__/client-stack-test-utils.ts +36 -0
- package/src/__tests__/content-lifecycle-migrations.typecheck.ts +122 -0
- package/src/__tests__/endpoint-inventory.test.ts +768 -0
- package/src/__tests__/form-builder-query-keys.test.ts +32 -0
- package/src/__tests__/i18n-provider.test.tsx +4 -3
- package/src/__tests__/initial-identity-hydration.test.tsx +156 -0
- package/src/__tests__/initial-identity-layouts.test.tsx +204 -0
- package/src/__tests__/kanban-query-keys.test.ts +189 -2
- package/src/__tests__/managed-origin-hydration.browser.test.tsx +163 -0
- package/src/__tests__/media-query-keys.test.ts +91 -17
- package/src/__tests__/notify-provider.test.tsx +3 -2
- package/src/__tests__/package-metadata.test.ts +294 -0
- package/src/__tests__/page-component-overrides.test.tsx +3 -4
- package/src/__tests__/plugin-registration.test.tsx +183 -0
- package/src/__tests__/plugin-registration.typecheck.tsx +139 -0
- package/src/__tests__/plugins.test.tsx +72 -42
- package/src/__tests__/resource-factory.test.tsx +79 -2
- package/src/__tests__/resource-use-form.test.tsx +2 -2
- package/src/__tests__/resource-use-select.test.tsx +2 -4
- package/src/__tests__/router-overrides.test.tsx +20 -8
- package/src/__tests__/sitemap.test.ts +38 -22
- package/src/__tests__/stack-api.test.ts +39 -34
- package/src/__tests__/stack-auth.test.ts +44 -140
- package/src/__tests__/stack-constructors.test.ts +96 -0
- package/src/__tests__/stack-constructors.typecheck.ts +115 -0
- package/src/__tests__/use-list-state.test.tsx +7 -6
- package/src/__tests__/workflow-lifecycle-migrations.typecheck.ts +150 -0
- package/src/api/index.ts +204 -99
- package/src/authorization/client.tsx +310 -0
- package/src/authorization/index.ts +873 -0
- package/src/authorization/json.ts +70 -0
- package/src/authorization/remote.ts +234 -0
- package/src/authorization/server.ts +171 -0
- package/src/client/__tests__/server-origin.test.ts +119 -0
- package/src/client/components/compose.tsx +126 -18
- package/src/client/hooks/index.ts +12 -0
- package/src/client/hooks/use-list-state.ts +7 -13
- package/src/client/index.ts +105 -50
- package/src/client/runtime.ts +414 -0
- package/src/client/server.ts +174 -0
- package/src/context/auth.tsx +205 -154
- package/src/context/index.ts +10 -4
- package/src/context/provider.tsx +96 -57
- package/src/context/router.tsx +7 -0
- package/src/context/site-navigation.ts +52 -0
- package/src/next/layout.tsx +81 -0
- package/src/next/page.tsx +16 -3
- package/src/next/router.tsx +1 -1
- package/src/next/server.ts +5 -0
- package/src/plugin-registration.ts +70 -0
- package/src/plugins/ai-chat/__tests__/authorization.test.ts +2051 -0
- package/src/plugins/ai-chat/__tests__/chat-hooks.test.tsx +147 -0
- package/src/plugins/ai-chat/__tests__/chat-input-authorization.test.tsx +188 -0
- package/src/plugins/ai-chat/__tests__/client-sweep.test.tsx +1506 -34
- package/src/plugins/ai-chat/__tests__/hooks.test.tsx +131 -23
- package/src/plugins/ai-chat/api/getters.ts +2 -2
- package/src/plugins/ai-chat/api/index.ts +6 -1
- package/src/plugins/ai-chat/api/lifecycle-migrations.ts +20 -0
- package/src/plugins/ai-chat/api/operations.ts +1865 -0
- package/src/plugins/ai-chat/api/plugin.ts +78 -1168
- package/src/plugins/ai-chat/api/serializers.ts +30 -0
- package/src/plugins/ai-chat/client/components/chat-input.tsx +228 -129
- package/src/plugins/ai-chat/client/components/chat-interface.tsx +776 -183
- package/src/plugins/ai-chat/client/components/chat-layout.tsx +6 -7
- package/src/plugins/ai-chat/client/components/chat-message.tsx +1 -1
- package/src/plugins/ai-chat/client/components/chat-sidebar.tsx +57 -37
- package/src/plugins/ai-chat/client/components/pages/404-page.tsx +1 -1
- package/src/plugins/ai-chat/client/components/pages/chat-page.internal.tsx +5 -3
- package/src/plugins/ai-chat/client/components/pages/chat-page.tsx +56 -15
- package/src/plugins/ai-chat/client/components/shared/default-error.tsx +1 -1
- package/src/plugins/ai-chat/client/components/tool-call-display.tsx +1 -1
- package/src/plugins/ai-chat/client/hooks/ai-chat-resource.ts +1 -1
- package/src/plugins/ai-chat/client/hooks/chat-hooks.tsx +253 -20
- package/src/plugins/ai-chat/client/index.ts +1 -0
- package/src/plugins/ai-chat/client/navigation.ts +11 -0
- package/src/plugins/ai-chat/client/overrides.ts +47 -11
- package/src/plugins/ai-chat/client/plugin.tsx +208 -111
- package/src/plugins/ai-chat/permissions.ts +89 -0
- package/src/plugins/ai-chat/query-keys.ts +183 -25
- package/src/plugins/ai-chat/types.ts +7 -5
- package/src/plugins/api/create-endpoint.ts +40 -22
- package/src/plugins/api/endpoint-inventory.ts +206 -0
- package/src/plugins/api/index.ts +38 -4
- package/src/plugins/api/operation.ts +600 -0
- package/src/plugins/blog/__tests__/authorization.test.ts +1366 -0
- package/src/plugins/blog/__tests__/client-runtime.browser.test.tsx +257 -0
- package/src/plugins/blog/__tests__/client-runtime.test.ts +283 -0
- package/src/plugins/blog/__tests__/client-runtime.typecheck.tsx +98 -0
- package/src/plugins/blog/__tests__/client-sweep.test.tsx +212 -37
- package/src/plugins/blog/api/getters.ts +3 -3
- package/src/plugins/blog/api/index.ts +2 -0
- package/src/plugins/blog/api/lifecycle-migrations.ts +19 -0
- package/src/plugins/blog/api/mutations.ts +26 -5
- package/src/plugins/blog/api/operations.ts +727 -0
- package/src/plugins/blog/api/plugin.ts +99 -504
- package/src/plugins/blog/client/components/forms/image-field.tsx +2 -1
- package/src/plugins/blog/client/components/forms/markdown-editor-with-overrides.tsx +2 -1
- package/src/plugins/blog/client/components/forms/post-forms.tsx +61 -33
- package/src/plugins/blog/client/components/pages/404-page.tsx +3 -1
- package/src/plugins/blog/client/components/pages/edit-post-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/edit-post-page.tsx +28 -5
- package/src/plugins/blog/client/components/pages/home-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/home-page.tsx +7 -4
- package/src/plugins/blog/client/components/pages/new-post-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/new-post-page.tsx +5 -2
- package/src/plugins/blog/client/components/pages/post-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/post-page.tsx +38 -4
- package/src/plugins/blog/client/components/pages/tag-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/tag-page.tsx +5 -1
- package/src/plugins/blog/client/components/shared/collapsible-tag-list.tsx +2 -1
- package/src/plugins/blog/client/components/shared/default-error.tsx +3 -1
- package/src/plugins/blog/client/components/shared/on-this-page.tsx +5 -2
- package/src/plugins/blog/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/blog/client/components/shared/post-card.tsx +2 -1
- package/src/plugins/blog/client/components/shared/posts-list.tsx +2 -1
- package/src/plugins/blog/client/components/shared/recent-posts-carousel.tsx +2 -1
- package/src/plugins/blog/client/components/shared/search-input.tsx +1 -1
- package/src/plugins/blog/client/constants.ts +2 -0
- package/src/plugins/blog/client/hooks/blog-resource.ts +2 -1
- package/src/plugins/blog/client/overrides.ts +1 -6
- package/src/plugins/blog/client/plugin.tsx +145 -129
- package/src/plugins/blog/permissions.ts +44 -0
- package/src/plugins/client/index.ts +108 -7
- package/src/plugins/client/resource/hooks.tsx +41 -18
- package/src/plugins/client/resource/internal.ts +77 -61
- package/src/plugins/client/resource/queries.ts +3 -4
- package/src/plugins/client/resource/use-form.ts +23 -20
- package/src/plugins/client/resource/use-select.ts +40 -34
- package/src/plugins/cms/__tests__/authorization.test.ts +2188 -0
- package/src/plugins/cms/__tests__/client-runtime.browser.test.tsx +245 -0
- package/src/plugins/cms/__tests__/client-runtime.test.ts +320 -0
- package/src/plugins/cms/__tests__/client-runtime.typecheck.tsx +208 -0
- package/src/plugins/cms/__tests__/client-sweep.test.tsx +202 -50
- package/src/plugins/cms/api/getters.ts +4 -4
- package/src/plugins/cms/api/index.ts +20 -0
- package/src/plugins/cms/api/lifecycle-migrations.ts +15 -0
- package/src/plugins/cms/api/mutations.ts +2 -2
- package/src/plugins/cms/api/operations.ts +2218 -0
- package/src/plugins/cms/api/plugin.ts +169 -1047
- package/src/plugins/cms/api/relations.ts +3 -1
- package/src/plugins/cms/client/components/forms/content-form.tsx +2 -1
- package/src/plugins/cms/client/components/forms/file-upload.tsx +3 -1
- package/src/plugins/cms/client/components/forms/relation-field.tsx +3 -1
- package/src/plugins/cms/client/components/inverse-relations-panel.tsx +29 -17
- package/src/plugins/cms/client/components/pages/404-page.tsx +7 -5
- package/src/plugins/cms/client/components/pages/content-editor-page.internal.tsx +19 -10
- package/src/plugins/cms/client/components/pages/content-editor-page.tsx +50 -12
- package/src/plugins/cms/client/components/pages/content-list-page.internal.tsx +48 -34
- package/src/plugins/cms/client/components/pages/content-list-page.tsx +8 -1
- package/src/plugins/cms/client/components/pages/dashboard-page.internal.tsx +15 -8
- package/src/plugins/cms/client/components/pages/dashboard-page.tsx +5 -1
- package/src/plugins/cms/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/cms/client/constants.ts +2 -0
- package/src/plugins/cms/client/hooks/cms-resource.ts +2 -1
- package/src/plugins/cms/client/index.ts +6 -1
- package/src/plugins/cms/client/overrides.ts +46 -6
- package/src/plugins/cms/client/plugin.tsx +135 -80
- package/src/plugins/cms/permissions.ts +43 -0
- package/src/plugins/cms/types.ts +174 -46
- package/src/plugins/comments/__tests__/authorization.test.ts +1570 -0
- package/src/plugins/comments/__tests__/client-runtime.browser.test.tsx +207 -0
- package/src/plugins/comments/__tests__/client-runtime.test.ts +224 -0
- package/src/plugins/comments/__tests__/client-runtime.typecheck.tsx +85 -0
- package/src/plugins/comments/__tests__/client-sweep.test.tsx +445 -82
- package/src/plugins/comments/api/getters.ts +19 -3
- package/src/plugins/comments/api/index.ts +2 -6
- package/src/plugins/comments/api/lifecycle-migrations.ts +20 -0
- package/src/plugins/comments/api/mutations.ts +261 -88
- package/src/plugins/comments/api/operations.ts +742 -0
- package/src/plugins/comments/api/plugin.ts +76 -548
- package/src/plugins/comments/client/components/comment-count.tsx +38 -5
- package/src/plugins/comments/client/components/comment-thread.tsx +148 -110
- package/src/plugins/comments/client/components/pages/moderation-page.internal.tsx +144 -78
- package/src/plugins/comments/client/components/pages/moderation-page.tsx +18 -2
- package/src/plugins/comments/client/components/pages/moderation-state.ts +13 -0
- package/src/plugins/comments/client/components/pages/my-comments-page.internal.tsx +38 -30
- package/src/plugins/comments/client/components/pages/my-comments-page.tsx +3 -1
- package/src/plugins/comments/client/components/pages/resource-comments-page.internal.tsx +29 -30
- package/src/plugins/comments/client/components/pages/resource-comments-page.tsx +10 -1
- package/src/plugins/comments/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/comments/client/components/shared/pagination.tsx +2 -1
- package/src/plugins/comments/client/constants.ts +2 -0
- package/src/plugins/comments/client/hooks/use-comments.tsx +430 -421
- package/src/plugins/comments/client/localization/comments-thread.ts +1 -0
- package/src/plugins/comments/client/plugin.tsx +113 -72
- package/src/plugins/comments/permissions.ts +68 -0
- package/src/plugins/comments/query-keys.ts +9 -10
- package/src/plugins/comments/schemas.ts +7 -8
- package/src/plugins/form-builder/__tests__/authorization.test.ts +1600 -0
- package/src/plugins/form-builder/__tests__/client-runtime.browser.test.tsx +255 -0
- package/src/plugins/form-builder/__tests__/client-runtime.test.ts +132 -0
- package/src/plugins/form-builder/__tests__/client-runtime.typecheck.tsx +77 -0
- package/src/plugins/form-builder/__tests__/client-sweep.test.tsx +350 -54
- package/src/plugins/form-builder/__tests__/form-renderer-authorization.test.tsx +162 -0
- package/src/plugins/form-builder/api/getters.ts +21 -5
- package/src/plugins/form-builder/api/index.ts +31 -0
- package/src/plugins/form-builder/api/lifecycle-migrations.ts +17 -0
- package/src/plugins/form-builder/api/operations.ts +1493 -0
- package/src/plugins/form-builder/api/plugin.ts +125 -632
- package/src/plugins/form-builder/api/query-key-defs.ts +7 -0
- package/src/plugins/form-builder/api/serializers.ts +1 -0
- package/src/plugins/form-builder/client/components/forms/form-renderer.tsx +49 -19
- package/src/plugins/form-builder/client/components/pages/404-page.tsx +9 -9
- package/src/plugins/form-builder/client/components/pages/form-builder-page.internal.tsx +54 -30
- package/src/plugins/form-builder/client/components/pages/form-builder-page.tsx +42 -9
- package/src/plugins/form-builder/client/components/pages/form-list-page.internal.tsx +46 -34
- package/src/plugins/form-builder/client/components/pages/form-list-page.tsx +6 -2
- package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +98 -64
- package/src/plugins/form-builder/client/components/pages/submissions-page.tsx +29 -9
- package/src/plugins/form-builder/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/form-builder/client/constants.ts +2 -0
- package/src/plugins/form-builder/client/hooks/form-builder-hooks.tsx +68 -4
- package/src/plugins/form-builder/client/hooks/form-builder-resource.ts +2 -1
- package/src/plugins/form-builder/client/hooks/index.tsx +1 -0
- package/src/plugins/form-builder/client/overrides.ts +1 -6
- package/src/plugins/form-builder/client/plugin.tsx +128 -96
- package/src/plugins/form-builder/permissions.ts +94 -0
- package/src/plugins/form-builder/query-keys.ts +28 -3
- package/src/plugins/form-builder/schemas.ts +9 -1
- package/src/plugins/form-builder/types.ts +173 -41
- package/src/plugins/kanban/__tests__/authorization.test.ts +1382 -0
- package/src/plugins/kanban/__tests__/client-runtime.browser.test.tsx +302 -0
- package/src/plugins/kanban/__tests__/client-runtime.test.ts +130 -0
- package/src/plugins/kanban/__tests__/client-runtime.typecheck.tsx +81 -0
- package/src/plugins/kanban/__tests__/client-sweep.test.tsx +418 -33
- package/src/plugins/kanban/__tests__/identity-partition.test.tsx +306 -0
- package/src/plugins/kanban/api/getters.ts +65 -50
- package/src/plugins/kanban/api/index.ts +55 -4
- package/src/plugins/kanban/api/lifecycle-migrations.ts +25 -0
- package/src/plugins/kanban/api/mutations.ts +3 -3
- package/src/plugins/kanban/api/operations.ts +2065 -0
- package/src/plugins/kanban/api/plugin.ts +83 -1013
- package/src/plugins/kanban/api/serializers.ts +26 -0
- package/src/plugins/kanban/client/components/forms/board-form.tsx +3 -1
- package/src/plugins/kanban/client/components/forms/column-form.tsx +3 -1
- package/src/plugins/kanban/client/components/forms/task-form.tsx +92 -74
- package/src/plugins/kanban/client/components/pages/404-page.tsx +6 -9
- package/src/plugins/kanban/client/components/pages/board-page.internal.tsx +57 -74
- package/src/plugins/kanban/client/components/pages/board-page.tsx +31 -7
- package/src/plugins/kanban/client/components/pages/boards-list-page.internal.tsx +54 -45
- package/src/plugins/kanban/client/components/pages/boards-list-page.tsx +2 -1
- package/src/plugins/kanban/client/components/pages/new-board-page.internal.tsx +8 -12
- package/src/plugins/kanban/client/components/pages/new-board-page.tsx +2 -1
- package/src/plugins/kanban/client/components/shared/column-content.tsx +61 -48
- package/src/plugins/kanban/client/components/shared/default-error.tsx +3 -1
- package/src/plugins/kanban/client/components/shared/kanban-board.tsx +6 -6
- package/src/plugins/kanban/client/components/shared/permission-access-any.tsx +32 -0
- package/src/plugins/kanban/client/components/shared/task-card.tsx +64 -20
- package/src/plugins/kanban/client/components/shared/user-avatar.tsx +3 -1
- package/src/plugins/kanban/client/constants.ts +2 -0
- package/src/plugins/kanban/client/hooks/kanban-hooks.tsx +55 -10
- package/src/plugins/kanban/client/hooks/kanban-resource.ts +2 -1
- package/src/plugins/kanban/client/overrides.ts +0 -5
- package/src/plugins/kanban/client/plugin.tsx +201 -113
- package/src/plugins/kanban/permissions.ts +100 -0
- package/src/plugins/kanban/query-keys.ts +61 -21
- package/src/plugins/kanban/schemas.ts +44 -18
- package/src/plugins/kanban/types.ts +381 -1
- package/src/plugins/media/__tests__/authorization.test.ts +1769 -0
- package/src/plugins/media/__tests__/client-runtime.browser.test.tsx +975 -0
- package/src/plugins/media/__tests__/client-runtime.test.ts +539 -0
- package/src/plugins/media/__tests__/client-runtime.typecheck.tsx +135 -0
- package/src/plugins/media/__tests__/client-sweep.test.tsx +292 -24
- package/src/plugins/media/__tests__/identity-partition.test.tsx +741 -0
- package/src/plugins/media/__tests__/plugin.test.ts +68 -28
- package/src/plugins/media/__tests__/query-key-defs.test.ts +32 -2
- package/src/plugins/media/api/adapters/vercel-blob.ts +84 -8
- package/src/plugins/media/api/getters.ts +6 -6
- package/src/plugins/media/api/index.ts +3 -0
- package/src/plugins/media/api/lifecycle-migrations.ts +11 -0
- package/src/plugins/media/api/mutations.ts +19 -13
- package/src/plugins/media/api/operations.ts +1873 -0
- package/src/plugins/media/api/plugin.ts +211 -899
- package/src/plugins/media/api/query-key-defs.ts +66 -4
- package/src/plugins/media/api/serializers.ts +4 -2
- package/src/plugins/media/api/storage-adapter.ts +22 -4
- package/src/plugins/media/asset-url.ts +14 -0
- package/src/plugins/media/client/components/media-picker/asset-card.tsx +105 -98
- package/src/plugins/media/client/components/media-picker/folder-tree.tsx +82 -60
- package/src/plugins/media/client/components/media-picker/index.tsx +235 -171
- package/src/plugins/media/client/components/media-picker/upload-tab.tsx +2 -10
- package/src/plugins/media/client/components/media-picker/url-tab.tsx +1 -8
- package/src/plugins/media/client/components/pages/library-page.internal.tsx +103 -82
- package/src/plugins/media/client/components/pages/library-page.tsx +4 -2
- package/src/plugins/media/client/components/upload-permission-check.tsx +75 -0
- package/src/plugins/media/client/constants.ts +2 -0
- package/src/plugins/media/client/hooks/media-resource.ts +2 -1
- package/src/plugins/media/client/hooks/use-media.tsx +292 -49
- package/src/plugins/media/client/index.ts +16 -3
- package/src/plugins/media/client/overrides.ts +6 -17
- package/src/plugins/media/client/plugin.tsx +188 -123
- package/src/plugins/media/client/upload.ts +170 -53
- package/src/plugins/media/db.ts +8 -0
- package/src/plugins/media/permissions.ts +61 -0
- package/src/plugins/media/query-keys.ts +63 -19
- package/src/plugins/media/types.ts +8 -2
- package/src/plugins/open-api/__tests__/route-introspection.test.ts +277 -0
- package/src/plugins/open-api/api/generator.ts +49 -8
- package/src/plugins/open-api/api/plugin.ts +36 -14
- package/src/plugins/route-docs/client/components/pages/docs-page.tsx +63 -23
- package/src/plugins/route-docs/client/constants.ts +2 -0
- package/src/plugins/route-docs/client/hooks.ts +23 -13
- package/src/plugins/route-docs/client/index.ts +7 -1
- package/src/plugins/route-docs/client/plugin.tsx +222 -145
- package/src/plugins/route-docs/client/schema.ts +31 -0
- package/src/plugins/route-docs/generator.ts +9 -5
- package/src/plugins/ui-builder/__tests__/client-sweep.test.tsx +427 -48
- package/src/plugins/ui-builder/client/components/page-renderer.tsx +58 -16
- package/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.tsx +47 -26
- package/src/plugins/ui-builder/client/components/pages/page-builder-page.tsx +43 -8
- package/src/plugins/ui-builder/client/components/pages/page-list-page.internal.tsx +38 -19
- package/src/plugins/ui-builder/client/components/pages/page-list-page.tsx +8 -2
- package/src/plugins/ui-builder/client/components/shared/default-error.tsx +2 -1
- package/src/plugins/ui-builder/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/ui-builder/client/constants.ts +2 -0
- package/src/plugins/ui-builder/client/hooks/ui-builder-resource.ts +2 -1
- package/src/plugins/ui-builder/client/index.ts +4 -1
- package/src/plugins/ui-builder/client/overrides.ts +16 -21
- package/src/plugins/ui-builder/client/plugin.tsx +119 -66
- package/src/plugins/ui-builder/client/registry.ts +3 -5
- package/src/plugins/ui-builder/types.ts +7 -4
- package/src/plugins/utils.ts +5 -1
- package/src/react-router/index.tsx +5 -0
- package/src/react-router/layout.ts +43 -0
- package/src/react-router/page.tsx +12 -5
- package/src/react-router/router.tsx +1 -1
- package/src/shared/auth-types.ts +19 -70
- package/src/shared/entry-factories.ts +3 -3
- package/src/shared/initial-identity.ts +73 -0
- package/src/shared/list-state.ts +12 -0
- package/src/shared/types.ts +1 -0
- package/src/tanstack/index.tsx +5 -0
- package/src/tanstack/layout.ts +36 -0
- package/src/tanstack/page.tsx +7 -2
- package/src/tanstack/router.tsx +1 -1
- package/src/tanstack/server.ts +18 -0
- package/src/types.ts +557 -65
- package/dist/shared/stack.B8vdOMnQ.d.cts +0 -329
- package/dist/shared/stack.BISAZ5LX.d.mts +0 -492
- package/dist/shared/stack.BL5PvShn.d.mts +0 -193
- package/dist/shared/stack.Be1QIHEn.d.cts +0 -23
- package/dist/shared/stack.Be1QIHEn.d.mts +0 -23
- package/dist/shared/stack.Be1QIHEn.d.ts +0 -23
- package/dist/shared/stack.BjvOk_Bs.d.cts +0 -492
- package/dist/shared/stack.BozPgbrZ.d.cts +0 -201
- package/dist/shared/stack.BozPgbrZ.d.mts +0 -201
- package/dist/shared/stack.BozPgbrZ.d.ts +0 -201
- package/dist/shared/stack.BqTR6qi2.d.ts +0 -193
- package/dist/shared/stack.BsmDN8r9.d.cts +0 -406
- package/dist/shared/stack.C1ATQ3pd.d.ts +0 -416
- package/dist/shared/stack.C4_gEENS.d.cts +0 -97
- package/dist/shared/stack.C4_gEENS.d.mts +0 -97
- package/dist/shared/stack.C4_gEENS.d.ts +0 -97
- package/dist/shared/stack.C5Y5lViI.d.cts +0 -461
- package/dist/shared/stack.C8SwdUz8.d.ts +0 -461
- package/dist/shared/stack.CBsp9rDM.d.cts +0 -193
- package/dist/shared/stack.CKGjOI3Z.d.cts +0 -840
- package/dist/shared/stack.Cf-DbL1A.d.ts +0 -329
- package/dist/shared/stack.CuI_-z-_.d.cts +0 -560
- package/dist/shared/stack.D2RVkQD8.d.mts +0 -560
- package/dist/shared/stack.DHTvwoNG.d.mts +0 -329
- package/dist/shared/stack.DJaKVY7v.d.cts +0 -76
- package/dist/shared/stack.DJaKVY7v.d.mts +0 -76
- package/dist/shared/stack.DJaKVY7v.d.ts +0 -76
- package/dist/shared/stack.DKZMaVr6.d.cts +0 -416
- package/dist/shared/stack.DOzsgzkY.d.ts +0 -406
- package/dist/shared/stack.DQq8DEIv.d.mts +0 -461
- package/dist/shared/stack.DXrOtuek.d.ts +0 -560
- package/dist/shared/stack.DZHEHd-S.d.mts +0 -840
- package/dist/shared/stack.Dd-8shBE.d.ts +0 -492
- package/dist/shared/stack.EOPVnJrF.d.cts +0 -39
- package/dist/shared/stack.EOPVnJrF.d.mts +0 -39
- package/dist/shared/stack.EOPVnJrF.d.ts +0 -39
- package/dist/shared/stack.NGKtwA6S.d.mts +0 -406
- package/dist/shared/stack.WELCDuMs.d.ts +0 -840
- package/dist/shared/stack.aXdBOJAR.d.cts +0 -173
- package/dist/shared/stack.aXdBOJAR.d.mts +0 -173
- package/dist/shared/stack.aXdBOJAR.d.ts +0 -173
- package/dist/shared/stack.oBokjN_J.d.mts +0 -416
- package/dist/shared/{stack.D18Dq3ve.d.mts → stack.CKc_Bais.d.cts} +8 -8
- package/dist/shared/{stack.D18Dq3ve.d.ts → stack.CKc_Bais.d.mts} +8 -8
- package/dist/shared/{stack.D18Dq3ve.d.cts → stack.CKc_Bais.d.ts} +8 -8
|
@@ -0,0 +1,2188 @@
|
|
|
1
|
+
import { createMemoryAdapter } from "@btst/adapter-memory";
|
|
2
|
+
import { defineDb, type DatabaseDefinition } from "@btst/db";
|
|
3
|
+
import { zodToFormSchema } from "@workspace/ui/lib/schema-converter";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { createBackendStack } from "../../../api";
|
|
7
|
+
import { defineAuthorization } from "../../../authorization";
|
|
8
|
+
import {
|
|
9
|
+
createServerAuth,
|
|
10
|
+
type ServerAuth,
|
|
11
|
+
} from "../../../authorization/server";
|
|
12
|
+
import {
|
|
13
|
+
cmsBackendPlugin,
|
|
14
|
+
CMS_LIFECYCLE_HOOK_MIGRATIONS,
|
|
15
|
+
type CMSBackendHooks,
|
|
16
|
+
} from "../api";
|
|
17
|
+
import { cmsPermissions } from "../permissions";
|
|
18
|
+
import type { ContentItem, ContentRelation, ContentType } from "../types";
|
|
19
|
+
|
|
20
|
+
const memoryAdapter = (db: DatabaseDefinition) => createMemoryAdapter(db)({});
|
|
21
|
+
|
|
22
|
+
const articleSchema = z.object({ title: z.string() });
|
|
23
|
+
const categorySchema = z.object({ name: z.string() });
|
|
24
|
+
const resourceSchema = z.object({
|
|
25
|
+
name: z.string(),
|
|
26
|
+
categoryIds: z
|
|
27
|
+
.array(z.object({ id: z.string() }))
|
|
28
|
+
.default([])
|
|
29
|
+
.meta({
|
|
30
|
+
fieldType: "relation",
|
|
31
|
+
relation: {
|
|
32
|
+
type: "manyToMany",
|
|
33
|
+
targetType: "category",
|
|
34
|
+
displayField: "name",
|
|
35
|
+
creatable: true,
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
const changedResourceRelationSchema = z.object({
|
|
40
|
+
name: z.string(),
|
|
41
|
+
categoryIds: z
|
|
42
|
+
.array(z.object({ id: z.string() }))
|
|
43
|
+
.default([])
|
|
44
|
+
.meta({
|
|
45
|
+
fieldType: "relation",
|
|
46
|
+
relation: {
|
|
47
|
+
type: "manyToMany",
|
|
48
|
+
targetType: "secret",
|
|
49
|
+
displayField: "title",
|
|
50
|
+
creatable: true,
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
const missingResourceRelationSchema = z.object({
|
|
55
|
+
name: z.string(),
|
|
56
|
+
categoryIds: z
|
|
57
|
+
.array(z.object({ id: z.string() }))
|
|
58
|
+
.default([])
|
|
59
|
+
.meta({
|
|
60
|
+
fieldType: "relation",
|
|
61
|
+
relation: {
|
|
62
|
+
type: "manyToMany",
|
|
63
|
+
targetType: "missing-target",
|
|
64
|
+
displayField: "name",
|
|
65
|
+
creatable: true,
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
const inverseResourceRelationSchema = z.object({
|
|
70
|
+
name: z.string(),
|
|
71
|
+
categoryId: z.object({ id: z.string() }).meta({
|
|
72
|
+
fieldType: "relation",
|
|
73
|
+
relation: {
|
|
74
|
+
type: "belongsTo",
|
|
75
|
+
targetType: "category",
|
|
76
|
+
displayField: "name",
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
const categoryNoteSchema = z.object({
|
|
81
|
+
message: z.string(),
|
|
82
|
+
categoryId: z.object({ id: z.string() }).meta({
|
|
83
|
+
fieldType: "relation",
|
|
84
|
+
relation: {
|
|
85
|
+
type: "belongsTo",
|
|
86
|
+
targetType: "category",
|
|
87
|
+
displayField: "name",
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
const contentTypes = [
|
|
92
|
+
{ name: "Article", slug: "article", schema: articleSchema },
|
|
93
|
+
{ name: "Secret", slug: "secret", schema: articleSchema },
|
|
94
|
+
{ name: "Category", slug: "category", schema: categorySchema },
|
|
95
|
+
{ name: "Resource", slug: "resource", schema: resourceSchema },
|
|
96
|
+
{
|
|
97
|
+
name: "Category note",
|
|
98
|
+
slug: "category-note",
|
|
99
|
+
schema: categoryNoteSchema,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
const authorization = defineAuthorization({
|
|
104
|
+
identity: z.object({
|
|
105
|
+
id: z.string(),
|
|
106
|
+
role: z.enum(["user", "admin"]),
|
|
107
|
+
}),
|
|
108
|
+
permissions: [cmsPermissions] as const,
|
|
109
|
+
rules: ({ cms }) => [
|
|
110
|
+
cms.contentType.read.allow(),
|
|
111
|
+
cms.record.read.allow(),
|
|
112
|
+
cms.record.create.when(({ identity }) => identity !== null),
|
|
113
|
+
cms.record.update.when(
|
|
114
|
+
({ identity, facts }) =>
|
|
115
|
+
identity !== null &&
|
|
116
|
+
(identity.role === "admin" || identity.id === facts.authorId),
|
|
117
|
+
),
|
|
118
|
+
cms.record.delete.when(
|
|
119
|
+
({ identity, facts }) =>
|
|
120
|
+
identity !== null &&
|
|
121
|
+
(identity.role === "admin" || identity.id === facts.authorId),
|
|
122
|
+
),
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
function createAuth(
|
|
127
|
+
getIdentity: (
|
|
128
|
+
request: Request,
|
|
129
|
+
) =>
|
|
130
|
+
| { id: string; role: "user" | "admin" }
|
|
131
|
+
| null
|
|
132
|
+
| Promise<{ id: string; role: "user" | "admin" } | null> = (request) => {
|
|
133
|
+
const id = request.headers.get("x-user-id");
|
|
134
|
+
const role = request.headers.get("x-user-role");
|
|
135
|
+
if (!id || (role !== "user" && role !== "admin")) return null;
|
|
136
|
+
return { id, role };
|
|
137
|
+
},
|
|
138
|
+
) {
|
|
139
|
+
return createServerAuth({
|
|
140
|
+
authorization,
|
|
141
|
+
getIdentity: ({ request }) => getIdentity(request),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function makeBackend(options?: {
|
|
146
|
+
auth?: ServerAuth<any>;
|
|
147
|
+
hooks?: CMSBackendHooks;
|
|
148
|
+
}) {
|
|
149
|
+
return createBackendStack({
|
|
150
|
+
basePath: "/api",
|
|
151
|
+
plugins: {
|
|
152
|
+
cms: cmsBackendPlugin({
|
|
153
|
+
contentTypes,
|
|
154
|
+
...(options?.hooks ? { hooks: options.hooks } : {}),
|
|
155
|
+
}),
|
|
156
|
+
},
|
|
157
|
+
adapter: memoryAdapter,
|
|
158
|
+
...(options?.auth ? { auth: options.auth as never } : {}),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function allContentTypes(backend: ReturnType<typeof makeBackend>) {
|
|
163
|
+
return backend.trusted.cms.listContentTypes({});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function allContentItems(
|
|
167
|
+
backend: ReturnType<typeof makeBackend>,
|
|
168
|
+
typeSlug: string,
|
|
169
|
+
) {
|
|
170
|
+
return backend.trusted.cms.listContentItems({ typeSlug, query: {} });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function request(
|
|
174
|
+
path: string,
|
|
175
|
+
options?: {
|
|
176
|
+
method?: string;
|
|
177
|
+
identity?: { id: string; role: "user" | "admin" };
|
|
178
|
+
body?: unknown;
|
|
179
|
+
},
|
|
180
|
+
) {
|
|
181
|
+
const headers = new Headers();
|
|
182
|
+
if (options?.identity) {
|
|
183
|
+
headers.set("x-user-id", options.identity.id);
|
|
184
|
+
headers.set("x-user-role", options.identity.role);
|
|
185
|
+
}
|
|
186
|
+
if (options?.body !== undefined)
|
|
187
|
+
headers.set("content-type", "application/json");
|
|
188
|
+
return new Request(`http://localhost/api${path}`, {
|
|
189
|
+
method: options?.method ?? "GET",
|
|
190
|
+
headers,
|
|
191
|
+
...(options?.body !== undefined
|
|
192
|
+
? { body: JSON.stringify(options.body) }
|
|
193
|
+
: {}),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function seedRecord(
|
|
198
|
+
backend: ReturnType<typeof makeBackend>,
|
|
199
|
+
options: { typeSlug?: string; slug: string; authorId?: string },
|
|
200
|
+
) {
|
|
201
|
+
const typeSlug = options.typeSlug ?? "article";
|
|
202
|
+
const contentType = (await allContentTypes(backend)).find(
|
|
203
|
+
(value) => value.slug === typeSlug,
|
|
204
|
+
);
|
|
205
|
+
if (!contentType) throw new Error(`Missing test content type ${typeSlug}`);
|
|
206
|
+
return backend.adapter.create<ContentItem>({
|
|
207
|
+
model: "contentItem",
|
|
208
|
+
data: {
|
|
209
|
+
contentTypeId: contentType.id,
|
|
210
|
+
slug: options.slug,
|
|
211
|
+
data: JSON.stringify({ title: options.slug }),
|
|
212
|
+
...(options.authorId ? { authorId: options.authorId } : {}),
|
|
213
|
+
createdAt: new Date(),
|
|
214
|
+
updatedAt: new Date(),
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
describe("CMS authorization inventory", () => {
|
|
220
|
+
it("records every removed lifecycle name and canonical replacement", () => {
|
|
221
|
+
expect(CMS_LIFECYCLE_HOOK_MIGRATIONS).toEqual({
|
|
222
|
+
onBeforeCreate: "onBeforeCreateContent",
|
|
223
|
+
onAfterCreate: "onAfterCreateContent",
|
|
224
|
+
onBeforeUpdate: "onBeforeUpdateContent",
|
|
225
|
+
onAfterUpdate: "onAfterUpdateContent",
|
|
226
|
+
onBeforeDelete: "onBeforeDeleteContent",
|
|
227
|
+
onAfterDelete: "onAfterDeleteContent",
|
|
228
|
+
onError: "onErrorExecuteContentOperation",
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("binds every maintained route behavior to the CMS catalog", () => {
|
|
233
|
+
const plugin = cmsBackendPlugin({ contentTypes });
|
|
234
|
+
const adapter = memoryAdapter(defineDb({}).use(plugin.dbPlugin));
|
|
235
|
+
const operations = plugin.operations?.(adapter);
|
|
236
|
+
expect(Object.keys(operations ?? {}).sort()).toEqual([
|
|
237
|
+
"createContentItem",
|
|
238
|
+
"deleteContentItem",
|
|
239
|
+
"getContentItem",
|
|
240
|
+
"getContentItemPopulated",
|
|
241
|
+
"getContentTypeBySlug",
|
|
242
|
+
"getInverseRelations",
|
|
243
|
+
"listContentByRelation",
|
|
244
|
+
"listContentItems",
|
|
245
|
+
"listContentTypes",
|
|
246
|
+
"listInverseRelationItems",
|
|
247
|
+
"updateContentItem",
|
|
248
|
+
]);
|
|
249
|
+
expect(
|
|
250
|
+
Object.fromEntries(
|
|
251
|
+
Object.entries(operations ?? {}).map(([name, operation]) => [
|
|
252
|
+
name,
|
|
253
|
+
operation.permission.id,
|
|
254
|
+
]),
|
|
255
|
+
),
|
|
256
|
+
).toEqual({
|
|
257
|
+
listContentTypes: "cms:contentType.read",
|
|
258
|
+
getContentTypeBySlug: "cms:contentType.read",
|
|
259
|
+
listContentItems: "cms:record.read",
|
|
260
|
+
getContentItem: "cms:record.read",
|
|
261
|
+
createContentItem: "cms:record.create",
|
|
262
|
+
updateContentItem: "cms:record.update",
|
|
263
|
+
deleteContentItem: "cms:record.delete",
|
|
264
|
+
getContentItemPopulated: "cms:record.read",
|
|
265
|
+
listContentByRelation: "cms:record.read",
|
|
266
|
+
getInverseRelations: "cms:contentType.read",
|
|
267
|
+
listInverseRelationItems: "cms:record.read",
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
expect(
|
|
271
|
+
cmsPermissions.record.update({
|
|
272
|
+
contentType: "article",
|
|
273
|
+
recordId: "record-1",
|
|
274
|
+
authorId: "author-1",
|
|
275
|
+
}),
|
|
276
|
+
).toMatchObject({ id: "cms:record.update" });
|
|
277
|
+
expect(() =>
|
|
278
|
+
cmsPermissions.record.update({
|
|
279
|
+
contentType: "article",
|
|
280
|
+
recordId: 1,
|
|
281
|
+
} as never),
|
|
282
|
+
).toThrow();
|
|
283
|
+
if (false) {
|
|
284
|
+
// @ts-expect-error CMS descriptors reject the RC fact vocabulary.
|
|
285
|
+
cmsPermissions.record.delete({ typeSlug: "article", id: "record-1" });
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("keeps raw SSG helpers out of request and trusted operation namespaces", async () => {
|
|
290
|
+
const backend = makeBackend();
|
|
291
|
+
const operationRequest = request("/content-types");
|
|
292
|
+
expect(typeof backend.raw.cms.prefetchForRoute).toBe("function");
|
|
293
|
+
expect(
|
|
294
|
+
"prefetchForRoute" in backend.forRequest(operationRequest).operations.cms,
|
|
295
|
+
).toBe(false);
|
|
296
|
+
expect("prefetchForRoute" in backend.trusted.cms).toBe(false);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe("CMS operation-first authorization", () => {
|
|
301
|
+
it("keeps public reads explicit and preserves HTTP/request/trusted parity", async () => {
|
|
302
|
+
const backend = makeBackend({ auth: createAuth() });
|
|
303
|
+
const seeded = await seedRecord(backend, {
|
|
304
|
+
slug: "public-article",
|
|
305
|
+
authorId: "author-1",
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const http = await backend.handler(request("/content/article"));
|
|
309
|
+
expect(http.status).toBe(200);
|
|
310
|
+
expect((await http.json()).items).toHaveLength(1);
|
|
311
|
+
const requestResult = await backend
|
|
312
|
+
.forRequest(request("/content/article"))
|
|
313
|
+
.operations.cms.listContentItems({ typeSlug: "article", query: {} });
|
|
314
|
+
expect(requestResult.items[0]?.id).toBe(seeded.id);
|
|
315
|
+
const trustedResult = await backend.trusted.cms.listContentItems({
|
|
316
|
+
typeSlug: "article",
|
|
317
|
+
query: {},
|
|
318
|
+
});
|
|
319
|
+
expect(trustedResult.items[0]?.id).toBe(seeded.id);
|
|
320
|
+
const httpCatalog = await backend.handler(request("/content-types"));
|
|
321
|
+
expect(httpCatalog.status).toBe(200);
|
|
322
|
+
expect(
|
|
323
|
+
(
|
|
324
|
+
(await httpCatalog.json()) as Array<{ slug: string; itemCount: number }>
|
|
325
|
+
).find((contentType) => contentType.slug === "article")?.itemCount,
|
|
326
|
+
).toBe(1);
|
|
327
|
+
const requestCatalog = await backend
|
|
328
|
+
.forRequest(request("/content-types"))
|
|
329
|
+
.operations.cms.listContentTypes({});
|
|
330
|
+
expect(
|
|
331
|
+
requestCatalog.find((contentType) => contentType.slug === "article")
|
|
332
|
+
?.itemCount,
|
|
333
|
+
).toBe(1);
|
|
334
|
+
expect(
|
|
335
|
+
authorization.can(
|
|
336
|
+
cmsPermissions.record.read({
|
|
337
|
+
contentType: "article",
|
|
338
|
+
scope: "collection",
|
|
339
|
+
}),
|
|
340
|
+
null,
|
|
341
|
+
),
|
|
342
|
+
).toBe(true);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("authorizes every collection count before returning the content-type catalog", async () => {
|
|
346
|
+
const checkedCollections: string[] = [];
|
|
347
|
+
const catalogAuthorization = defineAuthorization({
|
|
348
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
349
|
+
permissions: [cmsPermissions] as const,
|
|
350
|
+
rules: ({ cms }) => [
|
|
351
|
+
cms.contentType.read.allow(),
|
|
352
|
+
cms.record.read.when(({ facts }) => {
|
|
353
|
+
checkedCollections.push(`${facts.contentType}:${facts.scope}`);
|
|
354
|
+
return facts.contentType !== "secret";
|
|
355
|
+
}),
|
|
356
|
+
],
|
|
357
|
+
});
|
|
358
|
+
const backend = makeBackend({
|
|
359
|
+
auth: createServerAuth({
|
|
360
|
+
authorization: catalogAuthorization,
|
|
361
|
+
getIdentity: () => ({ id: "reader-1", role: "user" as const }),
|
|
362
|
+
}),
|
|
363
|
+
});
|
|
364
|
+
await seedRecord(backend, { slug: "counted-article" });
|
|
365
|
+
await seedRecord(backend, {
|
|
366
|
+
typeSlug: "secret",
|
|
367
|
+
slug: "counted-secret",
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const http = await backend.handler(request("/content-types"));
|
|
371
|
+
expect(http.status).toBe(403);
|
|
372
|
+
expect(await http.text()).not.toContain("itemCount");
|
|
373
|
+
await expect(
|
|
374
|
+
backend
|
|
375
|
+
.forRequest(request("/content-types"))
|
|
376
|
+
.operations.cms.listContentTypes({}),
|
|
377
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
378
|
+
expect(new Set(checkedCollections)).toEqual(
|
|
379
|
+
new Set([
|
|
380
|
+
"article:collection",
|
|
381
|
+
"secret:collection",
|
|
382
|
+
"category:collection",
|
|
383
|
+
"resource:collection",
|
|
384
|
+
"category-note:collection",
|
|
385
|
+
]),
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
const trustedCatalog = await backend.trusted.cms.listContentTypes({});
|
|
389
|
+
expect(
|
|
390
|
+
trustedCatalog.find((contentType) => contentType.slug === "article")
|
|
391
|
+
?.itemCount,
|
|
392
|
+
).toBe(1);
|
|
393
|
+
expect(
|
|
394
|
+
trustedCatalog.find((contentType) => contentType.slug === "secret")
|
|
395
|
+
?.itemCount,
|
|
396
|
+
).toBe(1);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("returns 401/403 and derives identity plus ownership on the server", async () => {
|
|
400
|
+
const events: string[] = [];
|
|
401
|
+
const backend = makeBackend({
|
|
402
|
+
auth: createAuth(),
|
|
403
|
+
hooks: {
|
|
404
|
+
onBeforeCreateContent: (_data, context) => {
|
|
405
|
+
if (false) {
|
|
406
|
+
// @ts-expect-error Authorized lifecycle input is immutable.
|
|
407
|
+
context.input.body.slug = "rewritten";
|
|
408
|
+
// @ts-expect-error Nested CMS input is immutable.
|
|
409
|
+
context.input.body.data.title = "rewritten";
|
|
410
|
+
}
|
|
411
|
+
events.push(`create:${context.identity?.id}`);
|
|
412
|
+
expect(context.facts).toEqual({ contentType: "article" });
|
|
413
|
+
},
|
|
414
|
+
onAfterCreateContent: (item, context) => {
|
|
415
|
+
if (false) {
|
|
416
|
+
// @ts-expect-error Authorized lifecycle results are deeply immutable.
|
|
417
|
+
item.contentType!.slug = "rewritten";
|
|
418
|
+
}
|
|
419
|
+
events.push(`created:${item.authorId}`);
|
|
420
|
+
expect(context.result).toBe(item);
|
|
421
|
+
},
|
|
422
|
+
onBeforeUpdateContent: (_id, _data, context) => {
|
|
423
|
+
events.push(`update:${context.identity?.id}`);
|
|
424
|
+
},
|
|
425
|
+
onAfterUpdateContent: (item, context) => {
|
|
426
|
+
events.push(`updated:${item.authorId}`);
|
|
427
|
+
expect(context.result).toBe(item);
|
|
428
|
+
},
|
|
429
|
+
onBeforeDeleteContent: (_id, context) => {
|
|
430
|
+
events.push(`delete:${context.identity?.id ?? "trusted"}`);
|
|
431
|
+
},
|
|
432
|
+
onAfterDeleteContent: (_id, context) => {
|
|
433
|
+
events.push(`deleted:${context.result.success}`);
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
const body = { slug: "owned", data: { title: "Owned" } };
|
|
438
|
+
const anonymousCreate = await backend.handler(
|
|
439
|
+
request("/content/article", { method: "POST", body }),
|
|
440
|
+
);
|
|
441
|
+
expect(anonymousCreate.status).toBe(401);
|
|
442
|
+
expect(events).toEqual([]);
|
|
443
|
+
|
|
444
|
+
const createdResponse = await backend.handler(
|
|
445
|
+
request("/content/article", {
|
|
446
|
+
method: "POST",
|
|
447
|
+
identity: { id: "author-1", role: "user" },
|
|
448
|
+
body,
|
|
449
|
+
}),
|
|
450
|
+
);
|
|
451
|
+
expect(createdResponse.status).toBe(200);
|
|
452
|
+
const created = (await createdResponse.json()) as ContentItem;
|
|
453
|
+
expect(created.authorId).toBe("author-1");
|
|
454
|
+
expect(events).toEqual(["create:author-1", "created:author-1"]);
|
|
455
|
+
|
|
456
|
+
const denied = await backend.handler(
|
|
457
|
+
request(`/content/article/${created.id}`, {
|
|
458
|
+
method: "PUT",
|
|
459
|
+
identity: { id: "viewer-1", role: "user" },
|
|
460
|
+
body: { data: { title: "Spoofed" } },
|
|
461
|
+
}),
|
|
462
|
+
);
|
|
463
|
+
expect(denied.status).toBe(403);
|
|
464
|
+
expect(events).toHaveLength(2);
|
|
465
|
+
|
|
466
|
+
const updated = await backend
|
|
467
|
+
.forRequest(
|
|
468
|
+
request(`/content/article/${created.id}`, {
|
|
469
|
+
identity: { id: "author-1", role: "user" },
|
|
470
|
+
}),
|
|
471
|
+
)
|
|
472
|
+
.operations.cms.updateContentItem({
|
|
473
|
+
typeSlug: "article",
|
|
474
|
+
id: created.id,
|
|
475
|
+
body: { data: { title: "Owner update" } },
|
|
476
|
+
});
|
|
477
|
+
expect(
|
|
478
|
+
(updated as unknown as { parsedData: { title: string } }).parsedData
|
|
479
|
+
.title,
|
|
480
|
+
).toBe("Owner update");
|
|
481
|
+
expect(events).toContain("update:author-1");
|
|
482
|
+
|
|
483
|
+
await backend.trusted.cms.deleteContentItem({
|
|
484
|
+
typeSlug: "article",
|
|
485
|
+
id: created.id,
|
|
486
|
+
});
|
|
487
|
+
expect(events).toContain("delete:trusted");
|
|
488
|
+
expect(events).toContain("deleted:true");
|
|
489
|
+
expect(
|
|
490
|
+
await backend.adapter.findOne({
|
|
491
|
+
model: "contentItem",
|
|
492
|
+
where: [{ field: "id", value: created.id }],
|
|
493
|
+
}),
|
|
494
|
+
).toBeFalsy();
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it.each(["request", "trusted"] as const)(
|
|
498
|
+
"invokes every canonical CMS mutation lifecycle through %s execution",
|
|
499
|
+
async (transport) => {
|
|
500
|
+
const events: string[] = [];
|
|
501
|
+
const record = (event: string) => {
|
|
502
|
+
events.push(event);
|
|
503
|
+
};
|
|
504
|
+
const backend = makeBackend({
|
|
505
|
+
auth: createAuth(),
|
|
506
|
+
hooks: {
|
|
507
|
+
onBeforeCreateContent: (_data, context) => {
|
|
508
|
+
if (context.input.body.slug.startsWith("rejected-")) {
|
|
509
|
+
events.push("before-error:create");
|
|
510
|
+
throw new Error("create rejected");
|
|
511
|
+
}
|
|
512
|
+
events.push("before:create");
|
|
513
|
+
},
|
|
514
|
+
onAfterCreateContent: () => record("after:create"),
|
|
515
|
+
onBeforeUpdateContent: () => record("before:update"),
|
|
516
|
+
onAfterUpdateContent: () => record("after:update"),
|
|
517
|
+
onBeforeDeleteContent: () => record("before:delete"),
|
|
518
|
+
onAfterDeleteContent: () => record("after:delete"),
|
|
519
|
+
onErrorExecuteContentOperation: (_error, operation) => {
|
|
520
|
+
events.push(`error:${operation}`);
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
const api =
|
|
525
|
+
transport === "request"
|
|
526
|
+
? backend.forRequest(
|
|
527
|
+
request("/lifecycle", {
|
|
528
|
+
identity: { id: "author-1", role: "user" },
|
|
529
|
+
}),
|
|
530
|
+
).operations.cms
|
|
531
|
+
: backend.trusted.cms;
|
|
532
|
+
const created = await api.createContentItem({
|
|
533
|
+
typeSlug: "article",
|
|
534
|
+
body: {
|
|
535
|
+
slug: `lifecycle-${transport}`,
|
|
536
|
+
data: { title: "Lifecycle article" },
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
await api.updateContentItem({
|
|
540
|
+
typeSlug: "article",
|
|
541
|
+
id: created.id,
|
|
542
|
+
body: { data: { title: "Lifecycle article updated" } },
|
|
543
|
+
});
|
|
544
|
+
await api.deleteContentItem({
|
|
545
|
+
typeSlug: "article",
|
|
546
|
+
id: created.id,
|
|
547
|
+
});
|
|
548
|
+
await expect(
|
|
549
|
+
api.createContentItem({
|
|
550
|
+
typeSlug: "article",
|
|
551
|
+
body: {
|
|
552
|
+
slug: `rejected-${transport}`,
|
|
553
|
+
data: { title: "Rejected article" },
|
|
554
|
+
},
|
|
555
|
+
}),
|
|
556
|
+
).rejects.toThrow("create rejected");
|
|
557
|
+
|
|
558
|
+
expect(events).toEqual([
|
|
559
|
+
"before:create",
|
|
560
|
+
"after:create",
|
|
561
|
+
"before:update",
|
|
562
|
+
"after:update",
|
|
563
|
+
"before:delete",
|
|
564
|
+
"after:delete",
|
|
565
|
+
"before-error:create",
|
|
566
|
+
"error:create",
|
|
567
|
+
]);
|
|
568
|
+
},
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
it("authorizes inline related-record creation for the server-derived target type", async () => {
|
|
572
|
+
const sourceOnlyAuthorization = defineAuthorization({
|
|
573
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
574
|
+
permissions: [cmsPermissions] as const,
|
|
575
|
+
rules: ({ cms }) => [
|
|
576
|
+
cms.contentType.read.allow(),
|
|
577
|
+
cms.record.create.when(
|
|
578
|
+
({ identity, facts }) =>
|
|
579
|
+
identity !== null && facts.contentType === "resource",
|
|
580
|
+
),
|
|
581
|
+
cms.record.update.when(
|
|
582
|
+
({ identity, facts }) =>
|
|
583
|
+
identity !== null && facts.contentType === "resource",
|
|
584
|
+
),
|
|
585
|
+
],
|
|
586
|
+
});
|
|
587
|
+
const events: string[] = [];
|
|
588
|
+
const backend = makeBackend({
|
|
589
|
+
auth: createServerAuth({
|
|
590
|
+
authorization: sourceOnlyAuthorization,
|
|
591
|
+
getIdentity: () => ({ id: "author-1", role: "user" as const }),
|
|
592
|
+
}),
|
|
593
|
+
hooks: {
|
|
594
|
+
onBeforeCreateContent: () => {
|
|
595
|
+
events.push("before");
|
|
596
|
+
},
|
|
597
|
+
onBeforeUpdateContent: () => {
|
|
598
|
+
events.push("before");
|
|
599
|
+
},
|
|
600
|
+
onErrorExecuteContentOperation: () => {
|
|
601
|
+
events.push("error");
|
|
602
|
+
},
|
|
603
|
+
},
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
const response = await backend.handler(
|
|
607
|
+
request("/content/resource", {
|
|
608
|
+
method: "POST",
|
|
609
|
+
identity: { id: "author-1", role: "user" },
|
|
610
|
+
body: {
|
|
611
|
+
slug: "source",
|
|
612
|
+
data: {
|
|
613
|
+
name: "Source",
|
|
614
|
+
categoryIds: [{ _new: true, data: { name: "Forbidden category" } }],
|
|
615
|
+
},
|
|
616
|
+
},
|
|
617
|
+
}),
|
|
618
|
+
);
|
|
619
|
+
|
|
620
|
+
expect(response.status).toBe(403);
|
|
621
|
+
expect(events).toEqual([]);
|
|
622
|
+
expect((await allContentItems(backend, "resource")).total).toBe(0);
|
|
623
|
+
|
|
624
|
+
const source = await seedRecord(backend, {
|
|
625
|
+
typeSlug: "resource",
|
|
626
|
+
slug: "existing-source",
|
|
627
|
+
authorId: "author-1",
|
|
628
|
+
});
|
|
629
|
+
const updateResponse = await backend.handler(
|
|
630
|
+
request(`/content/resource/${source.id}`, {
|
|
631
|
+
method: "PUT",
|
|
632
|
+
identity: { id: "author-1", role: "user" },
|
|
633
|
+
body: {
|
|
634
|
+
data: {
|
|
635
|
+
name: "Source",
|
|
636
|
+
categoryIds: [{ _new: true, data: { name: "Forbidden category" } }],
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
}),
|
|
640
|
+
);
|
|
641
|
+
expect(updateResponse.status).toBe(403);
|
|
642
|
+
expect(events).toEqual([]);
|
|
643
|
+
expect((await allContentItems(backend, "category")).total).toBe(0);
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
it("authorizes authoritative existing relation targets before linking them", async () => {
|
|
647
|
+
const ownerReadAuthorization = defineAuthorization({
|
|
648
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
649
|
+
permissions: [cmsPermissions] as const,
|
|
650
|
+
rules: ({ cms }) => [
|
|
651
|
+
cms.contentType.read.allow(),
|
|
652
|
+
cms.record.read.when(
|
|
653
|
+
({ identity, facts }) => identity?.id === facts.authorId,
|
|
654
|
+
),
|
|
655
|
+
cms.record.create.when(({ facts }) => facts.contentType === "resource"),
|
|
656
|
+
cms.record.update.when(({ facts }) => facts.contentType === "resource"),
|
|
657
|
+
],
|
|
658
|
+
});
|
|
659
|
+
const events: string[] = [];
|
|
660
|
+
const backend = makeBackend({
|
|
661
|
+
auth: createServerAuth({
|
|
662
|
+
authorization: ownerReadAuthorization,
|
|
663
|
+
getIdentity: () => ({ id: "author-1", role: "user" as const }),
|
|
664
|
+
}),
|
|
665
|
+
hooks: {
|
|
666
|
+
onBeforeCreateContent: () => {
|
|
667
|
+
events.push("before:create");
|
|
668
|
+
},
|
|
669
|
+
onBeforeUpdateContent: () => {
|
|
670
|
+
events.push("before:update");
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
});
|
|
674
|
+
const privateCategory = await seedRecord(backend, {
|
|
675
|
+
typeSlug: "category",
|
|
676
|
+
slug: "private-category",
|
|
677
|
+
authorId: "other-owner",
|
|
678
|
+
});
|
|
679
|
+
const source = await seedRecord(backend, {
|
|
680
|
+
typeSlug: "resource",
|
|
681
|
+
slug: "existing-source",
|
|
682
|
+
authorId: "author-1",
|
|
683
|
+
});
|
|
684
|
+
const relationData = {
|
|
685
|
+
name: "Source",
|
|
686
|
+
categoryIds: [{ id: privateCategory.id }],
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
const createResponse = await backend.handler(
|
|
690
|
+
request("/content/resource", {
|
|
691
|
+
method: "POST",
|
|
692
|
+
identity: { id: "author-1", role: "user" },
|
|
693
|
+
body: { slug: "denied-link", data: relationData },
|
|
694
|
+
}),
|
|
695
|
+
);
|
|
696
|
+
expect(createResponse.status).toBe(403);
|
|
697
|
+
const updateResponse = await backend.handler(
|
|
698
|
+
request(`/content/resource/${source.id}`, {
|
|
699
|
+
method: "PUT",
|
|
700
|
+
identity: { id: "author-1", role: "user" },
|
|
701
|
+
body: { data: relationData },
|
|
702
|
+
}),
|
|
703
|
+
);
|
|
704
|
+
expect(updateResponse.status).toBe(403);
|
|
705
|
+
expect(events).toEqual([]);
|
|
706
|
+
expect((await allContentItems(backend, "resource")).total).toBe(1);
|
|
707
|
+
expect(
|
|
708
|
+
await backend.adapter.findOne<ContentRelation>({
|
|
709
|
+
model: "contentRelation",
|
|
710
|
+
where: [{ field: "targetId", value: privateCategory.id }],
|
|
711
|
+
}),
|
|
712
|
+
).toBeFalsy();
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
it("rejects wrong-type and stale existing relation targets before writing", async () => {
|
|
716
|
+
const events: string[] = [];
|
|
717
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
718
|
+
backend = makeBackend({
|
|
719
|
+
auth: createAuth(),
|
|
720
|
+
hooks: {
|
|
721
|
+
onBeforeCreateContent: async () => {
|
|
722
|
+
events.push("before");
|
|
723
|
+
await backend.adapter.update<ContentItem>({
|
|
724
|
+
model: "contentItem",
|
|
725
|
+
where: [{ field: "slug", value: "owned-category" }],
|
|
726
|
+
update: { authorId: "other-owner" },
|
|
727
|
+
});
|
|
728
|
+
},
|
|
729
|
+
onErrorExecuteContentOperation: (_error, operation) => {
|
|
730
|
+
events.push(`error:${operation}`);
|
|
731
|
+
},
|
|
732
|
+
},
|
|
733
|
+
});
|
|
734
|
+
const wrongType = await seedRecord(backend, {
|
|
735
|
+
typeSlug: "secret",
|
|
736
|
+
slug: "not-a-category",
|
|
737
|
+
authorId: "author-1",
|
|
738
|
+
});
|
|
739
|
+
const wrongTypeResponse = await backend.handler(
|
|
740
|
+
request("/content/resource", {
|
|
741
|
+
method: "POST",
|
|
742
|
+
identity: { id: "author-1", role: "user" },
|
|
743
|
+
body: {
|
|
744
|
+
slug: "wrong-type-link",
|
|
745
|
+
data: {
|
|
746
|
+
name: "Wrong type",
|
|
747
|
+
categoryIds: [{ id: wrongType.id }],
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
}),
|
|
751
|
+
);
|
|
752
|
+
expect(wrongTypeResponse.status).toBe(404);
|
|
753
|
+
expect(await wrongTypeResponse.json()).toMatchObject({
|
|
754
|
+
code: "RECORD_NOT_FOUND",
|
|
755
|
+
});
|
|
756
|
+
expect(events).toEqual([]);
|
|
757
|
+
|
|
758
|
+
const category = await seedRecord(backend, {
|
|
759
|
+
typeSlug: "category",
|
|
760
|
+
slug: "owned-category",
|
|
761
|
+
authorId: "author-1",
|
|
762
|
+
});
|
|
763
|
+
const staleResponse = await backend.handler(
|
|
764
|
+
request("/content/resource", {
|
|
765
|
+
method: "POST",
|
|
766
|
+
identity: { id: "author-1", role: "user" },
|
|
767
|
+
body: {
|
|
768
|
+
slug: "stale-link",
|
|
769
|
+
data: {
|
|
770
|
+
name: "Stale target",
|
|
771
|
+
categoryIds: [{ id: category.id }],
|
|
772
|
+
},
|
|
773
|
+
},
|
|
774
|
+
}),
|
|
775
|
+
);
|
|
776
|
+
expect(staleResponse.status).toBe(409);
|
|
777
|
+
expect(await staleResponse.json()).toMatchObject({
|
|
778
|
+
code: "RECORD_STATE_CHANGED",
|
|
779
|
+
});
|
|
780
|
+
expect(events).toEqual(["before", "error:create"]);
|
|
781
|
+
expect((await allContentItems(backend, "resource")).total).toBe(0);
|
|
782
|
+
expect(
|
|
783
|
+
await backend.adapter.findOne<ContentRelation>({
|
|
784
|
+
model: "contentRelation",
|
|
785
|
+
where: [{ field: "targetId", value: category.id }],
|
|
786
|
+
}),
|
|
787
|
+
).toBeFalsy();
|
|
788
|
+
});
|
|
789
|
+
it("does not reuse unreadable records submitted as inline new relations", async () => {
|
|
790
|
+
const createWithoutReadAuthorization = defineAuthorization({
|
|
791
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
792
|
+
permissions: [cmsPermissions] as const,
|
|
793
|
+
rules: ({ cms }) => [
|
|
794
|
+
cms.contentType.read.allow(),
|
|
795
|
+
cms.record.create.when(
|
|
796
|
+
({ facts }) =>
|
|
797
|
+
facts.contentType === "resource" ||
|
|
798
|
+
facts.contentType === "category",
|
|
799
|
+
),
|
|
800
|
+
cms.record.update.when(({ facts }) => facts.contentType === "resource"),
|
|
801
|
+
],
|
|
802
|
+
});
|
|
803
|
+
const events: string[] = [];
|
|
804
|
+
const backend = makeBackend({
|
|
805
|
+
auth: createServerAuth({
|
|
806
|
+
authorization: createWithoutReadAuthorization,
|
|
807
|
+
getIdentity: () => ({ id: "author-1", role: "user" as const }),
|
|
808
|
+
}),
|
|
809
|
+
hooks: {
|
|
810
|
+
onBeforeCreateContent: () => {
|
|
811
|
+
events.push("before:create");
|
|
812
|
+
},
|
|
813
|
+
onBeforeUpdateContent: () => {
|
|
814
|
+
events.push("before:update");
|
|
815
|
+
},
|
|
816
|
+
onErrorExecuteContentOperation: (_error, operation) => {
|
|
817
|
+
events.push(`error:${operation}`);
|
|
818
|
+
},
|
|
819
|
+
},
|
|
820
|
+
});
|
|
821
|
+
const privateCategory = await seedRecord(backend, {
|
|
822
|
+
typeSlug: "category",
|
|
823
|
+
slug: "private-category",
|
|
824
|
+
authorId: "other-owner",
|
|
825
|
+
});
|
|
826
|
+
const inlineCollision = {
|
|
827
|
+
name: "Source",
|
|
828
|
+
categoryIds: [{ _new: true, data: { name: "Private category" } }],
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
const createResponse = await backend.handler(
|
|
832
|
+
request("/content/resource", {
|
|
833
|
+
method: "POST",
|
|
834
|
+
identity: { id: "author-1", role: "user" },
|
|
835
|
+
body: { slug: "collision-source", data: inlineCollision },
|
|
836
|
+
}),
|
|
837
|
+
);
|
|
838
|
+
expect(createResponse.status).toBe(409);
|
|
839
|
+
expect(await createResponse.json()).toMatchObject({
|
|
840
|
+
code: "RELATED_RECORD_SLUG_CONFLICT",
|
|
841
|
+
});
|
|
842
|
+
expect(events).toEqual(["error:create"]);
|
|
843
|
+
expect((await allContentItems(backend, "resource")).total).toBe(0);
|
|
844
|
+
expect((await allContentItems(backend, "category")).total).toBe(1);
|
|
845
|
+
|
|
846
|
+
const source = await seedRecord(backend, {
|
|
847
|
+
typeSlug: "resource",
|
|
848
|
+
slug: "existing-source",
|
|
849
|
+
authorId: "author-1",
|
|
850
|
+
});
|
|
851
|
+
const updateResponse = await backend.handler(
|
|
852
|
+
request(`/content/resource/${source.id}`, {
|
|
853
|
+
method: "PUT",
|
|
854
|
+
identity: { id: "author-1", role: "user" },
|
|
855
|
+
body: { data: inlineCollision },
|
|
856
|
+
}),
|
|
857
|
+
);
|
|
858
|
+
expect(updateResponse.status).toBe(409);
|
|
859
|
+
expect(await updateResponse.json()).toMatchObject({
|
|
860
|
+
code: "RELATED_RECORD_SLUG_CONFLICT",
|
|
861
|
+
});
|
|
862
|
+
expect(events).toEqual(["error:create", "error:update"]);
|
|
863
|
+
const persistedSource = await backend.adapter.findOne<ContentItem>({
|
|
864
|
+
model: "contentItem",
|
|
865
|
+
where: [{ field: "id", value: source.id }],
|
|
866
|
+
});
|
|
867
|
+
expect(JSON.parse(persistedSource?.data ?? "{}")).toMatchObject({
|
|
868
|
+
title: "existing-source",
|
|
869
|
+
});
|
|
870
|
+
expect(
|
|
871
|
+
await backend.adapter.findOne<ContentRelation>({
|
|
872
|
+
model: "contentRelation",
|
|
873
|
+
where: [
|
|
874
|
+
{ field: "sourceId", value: source.id },
|
|
875
|
+
{ field: "targetId", value: privateCategory.id },
|
|
876
|
+
],
|
|
877
|
+
}),
|
|
878
|
+
).toBeFalsy();
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
it("rejects duplicate inline-new slugs instead of merging their data", async () => {
|
|
882
|
+
const backend = makeBackend({ auth: createAuth() });
|
|
883
|
+
|
|
884
|
+
const response = await backend.handler(
|
|
885
|
+
request("/content/resource", {
|
|
886
|
+
method: "POST",
|
|
887
|
+
identity: { id: "author-1", role: "user" },
|
|
888
|
+
body: {
|
|
889
|
+
slug: "duplicate-inline-relations",
|
|
890
|
+
data: {
|
|
891
|
+
name: "Duplicate inline relations",
|
|
892
|
+
categoryIds: [
|
|
893
|
+
{ _new: true, data: { name: "Duplicate category" } },
|
|
894
|
+
{ _new: true, data: { name: "Duplicate-category" } },
|
|
895
|
+
],
|
|
896
|
+
},
|
|
897
|
+
},
|
|
898
|
+
}),
|
|
899
|
+
);
|
|
900
|
+
|
|
901
|
+
expect(response.status).toBe(409);
|
|
902
|
+
expect(await response.json()).toMatchObject({
|
|
903
|
+
code: "RELATED_RECORD_SLUG_CONFLICT",
|
|
904
|
+
});
|
|
905
|
+
expect((await allContentItems(backend, "resource")).total).toBe(0);
|
|
906
|
+
expect((await allContentItems(backend, "category")).total).toBe(0);
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
it("fails closed when a relation schema changes after compound authorization", async () => {
|
|
910
|
+
const relationAuthorization = defineAuthorization({
|
|
911
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
912
|
+
permissions: [cmsPermissions] as const,
|
|
913
|
+
rules: ({ cms }) => [
|
|
914
|
+
cms.contentType.read.allow(),
|
|
915
|
+
cms.record.create.when(
|
|
916
|
+
({ facts }) =>
|
|
917
|
+
facts.contentType === "resource" ||
|
|
918
|
+
facts.contentType === "category",
|
|
919
|
+
),
|
|
920
|
+
cms.record.update.when(({ facts }) => facts.contentType === "resource"),
|
|
921
|
+
],
|
|
922
|
+
});
|
|
923
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
924
|
+
let changedJsonSchema = JSON.stringify(
|
|
925
|
+
zodToFormSchema(changedResourceRelationSchema),
|
|
926
|
+
);
|
|
927
|
+
const baseAuth = createServerAuth({
|
|
928
|
+
authorization: relationAuthorization,
|
|
929
|
+
getIdentity: () => ({ id: "author-1", role: "user" as const }),
|
|
930
|
+
});
|
|
931
|
+
const authorize = baseAuth.authorize.bind(baseAuth);
|
|
932
|
+
const authorizationCalls = new WeakMap<Request, number>();
|
|
933
|
+
const racingAuth: typeof baseAuth = {
|
|
934
|
+
...baseAuth,
|
|
935
|
+
async authorize(request, permissionRequest) {
|
|
936
|
+
const identity = await authorize(request, permissionRequest);
|
|
937
|
+
const count = (authorizationCalls.get(request) ?? 0) + 1;
|
|
938
|
+
authorizationCalls.set(request, count);
|
|
939
|
+
if (count === 3) {
|
|
940
|
+
const resourceType = await backend.adapter.findOne<ContentType>({
|
|
941
|
+
model: "contentType",
|
|
942
|
+
where: [{ field: "slug", value: "resource" }],
|
|
943
|
+
});
|
|
944
|
+
if (!resourceType) throw new Error("Missing resource content type");
|
|
945
|
+
await backend.adapter.update<ContentType>({
|
|
946
|
+
model: "contentType",
|
|
947
|
+
where: [{ field: "id", value: resourceType.id }],
|
|
948
|
+
update: {
|
|
949
|
+
jsonSchema: changedJsonSchema,
|
|
950
|
+
updatedAt: new Date(),
|
|
951
|
+
},
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
return identity;
|
|
955
|
+
},
|
|
956
|
+
};
|
|
957
|
+
backend = makeBackend({ auth: racingAuth });
|
|
958
|
+
await allContentTypes(backend);
|
|
959
|
+
const originalResourceType = await backend.adapter.findOne<ContentType>({
|
|
960
|
+
model: "contentType",
|
|
961
|
+
where: [{ field: "slug", value: "resource" }],
|
|
962
|
+
});
|
|
963
|
+
if (!originalResourceType) throw new Error("Missing resource content type");
|
|
964
|
+
const resetResourceSchema = () =>
|
|
965
|
+
backend.adapter.update<ContentType>({
|
|
966
|
+
model: "contentType",
|
|
967
|
+
where: [{ field: "id", value: originalResourceType.id }],
|
|
968
|
+
update: {
|
|
969
|
+
jsonSchema: originalResourceType.jsonSchema,
|
|
970
|
+
updatedAt: new Date(),
|
|
971
|
+
},
|
|
972
|
+
});
|
|
973
|
+
const relationInput = {
|
|
974
|
+
name: "Source",
|
|
975
|
+
categoryIds: [{ _new: true, data: { title: "Denied secret" } }],
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
const createResponse = await backend.handler(
|
|
979
|
+
request("/content/resource", {
|
|
980
|
+
method: "POST",
|
|
981
|
+
identity: { id: "author-1", role: "user" },
|
|
982
|
+
body: { slug: "racing-create", data: relationInput },
|
|
983
|
+
}),
|
|
984
|
+
);
|
|
985
|
+
expect(createResponse.status).toBe(409);
|
|
986
|
+
expect(await createResponse.json()).toMatchObject({
|
|
987
|
+
code: "RELATION_SCHEMA_CHANGED",
|
|
988
|
+
});
|
|
989
|
+
expect((await allContentItems(backend, "resource")).total).toBe(0);
|
|
990
|
+
expect((await allContentItems(backend, "secret")).total).toBe(0);
|
|
991
|
+
|
|
992
|
+
await resetResourceSchema();
|
|
993
|
+
const source = await seedRecord(backend, {
|
|
994
|
+
typeSlug: "resource",
|
|
995
|
+
slug: "racing-update",
|
|
996
|
+
authorId: "author-1",
|
|
997
|
+
});
|
|
998
|
+
const updateResponse = await backend.handler(
|
|
999
|
+
request(`/content/resource/${source.id}`, {
|
|
1000
|
+
method: "PUT",
|
|
1001
|
+
identity: { id: "author-1", role: "user" },
|
|
1002
|
+
body: { data: relationInput },
|
|
1003
|
+
}),
|
|
1004
|
+
);
|
|
1005
|
+
expect(updateResponse.status).toBe(409);
|
|
1006
|
+
expect(await updateResponse.json()).toMatchObject({
|
|
1007
|
+
code: "RELATION_SCHEMA_CHANGED",
|
|
1008
|
+
});
|
|
1009
|
+
expect((await allContentItems(backend, "category")).total).toBe(0);
|
|
1010
|
+
expect((await allContentItems(backend, "secret")).total).toBe(0);
|
|
1011
|
+
|
|
1012
|
+
changedJsonSchema = JSON.stringify(
|
|
1013
|
+
zodToFormSchema(missingResourceRelationSchema),
|
|
1014
|
+
);
|
|
1015
|
+
await resetResourceSchema();
|
|
1016
|
+
const missingCreateResponse = await backend.handler(
|
|
1017
|
+
request("/content/resource", {
|
|
1018
|
+
method: "POST",
|
|
1019
|
+
identity: { id: "author-1", role: "user" },
|
|
1020
|
+
body: { slug: "missing-target-create", data: relationInput },
|
|
1021
|
+
}),
|
|
1022
|
+
);
|
|
1023
|
+
expect(missingCreateResponse.status).toBe(409);
|
|
1024
|
+
expect(await missingCreateResponse.json()).toMatchObject({
|
|
1025
|
+
code: "RELATION_SCHEMA_CHANGED",
|
|
1026
|
+
});
|
|
1027
|
+
await resetResourceSchema();
|
|
1028
|
+
const missingUpdateResponse = await backend.handler(
|
|
1029
|
+
request(`/content/resource/${source.id}`, {
|
|
1030
|
+
method: "PUT",
|
|
1031
|
+
identity: { id: "author-1", role: "user" },
|
|
1032
|
+
body: { data: relationInput },
|
|
1033
|
+
}),
|
|
1034
|
+
);
|
|
1035
|
+
expect(missingUpdateResponse.status).toBe(409);
|
|
1036
|
+
expect(await missingUpdateResponse.json()).toMatchObject({
|
|
1037
|
+
code: "RELATION_SCHEMA_CHANGED",
|
|
1038
|
+
});
|
|
1039
|
+
expect((await allContentItems(backend, "resource")).total).toBe(1);
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
it("ignores spoofed browser ownership and content-type facts", async () => {
|
|
1043
|
+
const backend = makeBackend({ auth: createAuth() });
|
|
1044
|
+
const record = await seedRecord(backend, {
|
|
1045
|
+
typeSlug: "secret",
|
|
1046
|
+
slug: "private",
|
|
1047
|
+
authorId: "author-1",
|
|
1048
|
+
});
|
|
1049
|
+
expect(
|
|
1050
|
+
authorization.can(
|
|
1051
|
+
cmsPermissions.record.delete({
|
|
1052
|
+
contentType: "article",
|
|
1053
|
+
recordId: record.id,
|
|
1054
|
+
authorId: "viewer-1",
|
|
1055
|
+
}),
|
|
1056
|
+
{ id: "viewer-1", role: "user" },
|
|
1057
|
+
),
|
|
1058
|
+
).toBe(true);
|
|
1059
|
+
|
|
1060
|
+
const spoofedOwner = await backend.handler(
|
|
1061
|
+
request(`/content/secret/${record.id}`, {
|
|
1062
|
+
method: "DELETE",
|
|
1063
|
+
identity: { id: "viewer-1", role: "user" },
|
|
1064
|
+
}),
|
|
1065
|
+
);
|
|
1066
|
+
expect(spoofedOwner.status).toBe(403);
|
|
1067
|
+
const spoofedType = await backend.handler(
|
|
1068
|
+
request(`/content/article/${record.id}`, {
|
|
1069
|
+
identity: { id: "viewer-1", role: "user" },
|
|
1070
|
+
}),
|
|
1071
|
+
);
|
|
1072
|
+
expect(spoofedType.status).toBe(404);
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
it("requires content-type read authorization before embedding record metadata", async () => {
|
|
1076
|
+
const recordOnlyAuthorization = defineAuthorization({
|
|
1077
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1078
|
+
permissions: [cmsPermissions] as const,
|
|
1079
|
+
rules: ({ cms }) => [
|
|
1080
|
+
cms.record.read.when(({ facts }) => facts.contentType === "article"),
|
|
1081
|
+
],
|
|
1082
|
+
});
|
|
1083
|
+
const events: string[] = [];
|
|
1084
|
+
const backend = makeBackend({
|
|
1085
|
+
auth: createServerAuth({
|
|
1086
|
+
authorization: recordOnlyAuthorization,
|
|
1087
|
+
getIdentity: () => ({ id: "reader-1", role: "user" as const }),
|
|
1088
|
+
}),
|
|
1089
|
+
hooks: {
|
|
1090
|
+
onErrorExecuteContentOperation: () => {
|
|
1091
|
+
events.push("error");
|
|
1092
|
+
},
|
|
1093
|
+
},
|
|
1094
|
+
});
|
|
1095
|
+
const record = await seedRecord(backend, { slug: "metadata-boundary" });
|
|
1096
|
+
|
|
1097
|
+
expect(
|
|
1098
|
+
await backend.handler(request(`/content/article/${record.id}`)),
|
|
1099
|
+
).toMatchObject({ status: 403 });
|
|
1100
|
+
expect(
|
|
1101
|
+
await backend.handler(request("/content/article?limit=1")),
|
|
1102
|
+
).toMatchObject({ status: 403 });
|
|
1103
|
+
expect(events).toEqual([]);
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1106
|
+
it("authorizes relation-filter targets before querying junction rows", async () => {
|
|
1107
|
+
const sourceOnlyAuthorization = defineAuthorization({
|
|
1108
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1109
|
+
permissions: [cmsPermissions] as const,
|
|
1110
|
+
rules: ({ cms }) => [
|
|
1111
|
+
cms.contentType.read.when(
|
|
1112
|
+
({ facts }) => facts.contentType === "resource",
|
|
1113
|
+
),
|
|
1114
|
+
cms.record.read.when(({ facts }) => facts.contentType === "resource"),
|
|
1115
|
+
],
|
|
1116
|
+
});
|
|
1117
|
+
const events: string[] = [];
|
|
1118
|
+
const backend = makeBackend({
|
|
1119
|
+
auth: createServerAuth({
|
|
1120
|
+
authorization: sourceOnlyAuthorization,
|
|
1121
|
+
getIdentity: () => ({ id: "reader-1", role: "user" as const }),
|
|
1122
|
+
}),
|
|
1123
|
+
hooks: {
|
|
1124
|
+
onErrorExecuteContentOperation: () => {
|
|
1125
|
+
events.push("error");
|
|
1126
|
+
},
|
|
1127
|
+
},
|
|
1128
|
+
});
|
|
1129
|
+
const source = await seedRecord(backend, {
|
|
1130
|
+
typeSlug: "resource",
|
|
1131
|
+
slug: "relation-filter-source",
|
|
1132
|
+
});
|
|
1133
|
+
const target = await seedRecord(backend, {
|
|
1134
|
+
typeSlug: "category",
|
|
1135
|
+
slug: "private-filter-target",
|
|
1136
|
+
});
|
|
1137
|
+
await backend.adapter.create<ContentRelation>({
|
|
1138
|
+
model: "contentRelation",
|
|
1139
|
+
data: {
|
|
1140
|
+
sourceId: source.id,
|
|
1141
|
+
targetId: target.id,
|
|
1142
|
+
fieldName: "categoryIds",
|
|
1143
|
+
createdAt: new Date(),
|
|
1144
|
+
},
|
|
1145
|
+
});
|
|
1146
|
+
const findMany = backend.adapter.findMany.bind(backend.adapter);
|
|
1147
|
+
let relationReads = 0;
|
|
1148
|
+
vi.spyOn(backend.adapter, "findMany").mockImplementation(async (query) => {
|
|
1149
|
+
if (query.model === "contentRelation") relationReads += 1;
|
|
1150
|
+
return findMany(query);
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
const response = await backend.handler(
|
|
1154
|
+
request(
|
|
1155
|
+
`/content/resource/by-relation?field=categoryIds&targetId=${target.id}`,
|
|
1156
|
+
),
|
|
1157
|
+
);
|
|
1158
|
+
expect(response.status).toBe(403);
|
|
1159
|
+
expect(relationReads).toBe(0);
|
|
1160
|
+
expect(events).toEqual([]);
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
it("fails closed when relation-filter schemas or targets change after authorization", async () => {
|
|
1164
|
+
const relationFilterAuthorization = defineAuthorization({
|
|
1165
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1166
|
+
permissions: [cmsPermissions] as const,
|
|
1167
|
+
rules: ({ cms }) => [
|
|
1168
|
+
cms.contentType.read.allow(),
|
|
1169
|
+
cms.record.read.allow(),
|
|
1170
|
+
],
|
|
1171
|
+
});
|
|
1172
|
+
const runRace = async (kind: "schema" | "target") => {
|
|
1173
|
+
const baseAuth = createServerAuth({
|
|
1174
|
+
authorization: relationFilterAuthorization,
|
|
1175
|
+
getIdentity: () => ({ id: "reader-1", role: "user" as const }),
|
|
1176
|
+
});
|
|
1177
|
+
const authorize = baseAuth.authorize.bind(baseAuth);
|
|
1178
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
1179
|
+
let targetId = "";
|
|
1180
|
+
const calls = new WeakMap<Request, number>();
|
|
1181
|
+
const racingAuth: typeof baseAuth = {
|
|
1182
|
+
...baseAuth,
|
|
1183
|
+
async authorize(currentRequest, permissionRequest) {
|
|
1184
|
+
const identity = await authorize(currentRequest, permissionRequest);
|
|
1185
|
+
const count = (calls.get(currentRequest) ?? 0) + 1;
|
|
1186
|
+
calls.set(currentRequest, count);
|
|
1187
|
+
if (count === 3) {
|
|
1188
|
+
if (kind === "schema") {
|
|
1189
|
+
const resourceType = await backend.adapter.findOne<ContentType>({
|
|
1190
|
+
model: "contentType",
|
|
1191
|
+
where: [{ field: "slug", value: "resource" }],
|
|
1192
|
+
});
|
|
1193
|
+
if (!resourceType)
|
|
1194
|
+
throw new Error("Missing resource content type");
|
|
1195
|
+
await backend.adapter.update<ContentType>({
|
|
1196
|
+
model: "contentType",
|
|
1197
|
+
where: [{ field: "id", value: resourceType.id }],
|
|
1198
|
+
update: {
|
|
1199
|
+
jsonSchema: JSON.stringify(zodToFormSchema(articleSchema)),
|
|
1200
|
+
updatedAt: new Date(),
|
|
1201
|
+
},
|
|
1202
|
+
});
|
|
1203
|
+
} else {
|
|
1204
|
+
await backend.adapter.delete({
|
|
1205
|
+
model: "contentItem",
|
|
1206
|
+
where: [{ field: "id", value: targetId }],
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
return identity;
|
|
1211
|
+
},
|
|
1212
|
+
};
|
|
1213
|
+
backend = makeBackend({ auth: racingAuth });
|
|
1214
|
+
const source = await seedRecord(backend, {
|
|
1215
|
+
typeSlug: "resource",
|
|
1216
|
+
slug: `${kind}-race-source`,
|
|
1217
|
+
});
|
|
1218
|
+
const target = await seedRecord(backend, {
|
|
1219
|
+
typeSlug: "category",
|
|
1220
|
+
slug: `${kind}-race-target`,
|
|
1221
|
+
});
|
|
1222
|
+
targetId = target.id;
|
|
1223
|
+
await backend.adapter.create<ContentRelation>({
|
|
1224
|
+
model: "contentRelation",
|
|
1225
|
+
data: {
|
|
1226
|
+
sourceId: source.id,
|
|
1227
|
+
targetId: target.id,
|
|
1228
|
+
fieldName: "categoryIds",
|
|
1229
|
+
createdAt: new Date(),
|
|
1230
|
+
},
|
|
1231
|
+
});
|
|
1232
|
+
const response = await backend.handler(
|
|
1233
|
+
request(
|
|
1234
|
+
`/content/resource/by-relation?field=categoryIds&targetId=${target.id}`,
|
|
1235
|
+
),
|
|
1236
|
+
);
|
|
1237
|
+
expect(response.status).toBe(409);
|
|
1238
|
+
expect(await response.json()).toMatchObject({
|
|
1239
|
+
code:
|
|
1240
|
+
kind === "schema"
|
|
1241
|
+
? "RELATION_SCHEMA_CHANGED"
|
|
1242
|
+
: "RECORD_STATE_CHANGED",
|
|
1243
|
+
});
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
await runRace("schema");
|
|
1247
|
+
await runRace("target");
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
it("authorizes every populated relation target before returning its record", async () => {
|
|
1251
|
+
const sourceOnlyAuthorization = defineAuthorization({
|
|
1252
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1253
|
+
permissions: [cmsPermissions] as const,
|
|
1254
|
+
rules: ({ cms }) => [
|
|
1255
|
+
cms.contentType.read.when(
|
|
1256
|
+
({ facts }) =>
|
|
1257
|
+
facts.contentType === "resource" ||
|
|
1258
|
+
facts.contentType === "category",
|
|
1259
|
+
),
|
|
1260
|
+
cms.record.read.when(({ facts }) => facts.contentType === "resource"),
|
|
1261
|
+
],
|
|
1262
|
+
});
|
|
1263
|
+
const events: string[] = [];
|
|
1264
|
+
const backend = makeBackend({
|
|
1265
|
+
auth: createServerAuth({
|
|
1266
|
+
authorization: sourceOnlyAuthorization,
|
|
1267
|
+
getIdentity: () => ({ id: "reader-1", role: "user" as const }),
|
|
1268
|
+
}),
|
|
1269
|
+
hooks: {
|
|
1270
|
+
onErrorExecuteContentOperation: () => {
|
|
1271
|
+
events.push("error");
|
|
1272
|
+
},
|
|
1273
|
+
},
|
|
1274
|
+
});
|
|
1275
|
+
const source = await seedRecord(backend, {
|
|
1276
|
+
typeSlug: "resource",
|
|
1277
|
+
slug: "source-with-secret-relation",
|
|
1278
|
+
});
|
|
1279
|
+
const target = await seedRecord(backend, {
|
|
1280
|
+
typeSlug: "category",
|
|
1281
|
+
slug: "secret-category",
|
|
1282
|
+
});
|
|
1283
|
+
await backend.adapter.create<ContentRelation>({
|
|
1284
|
+
model: "contentRelation",
|
|
1285
|
+
data: {
|
|
1286
|
+
sourceId: source.id,
|
|
1287
|
+
targetId: target.id,
|
|
1288
|
+
fieldName: "categoryIds",
|
|
1289
|
+
createdAt: new Date(),
|
|
1290
|
+
},
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1293
|
+
const response = await backend.handler(
|
|
1294
|
+
request(`/content/resource/${source.id}/populated`, {
|
|
1295
|
+
identity: { id: "reader-1", role: "user" },
|
|
1296
|
+
}),
|
|
1297
|
+
);
|
|
1298
|
+
expect(response.status).toBe(403);
|
|
1299
|
+
expect(events).toEqual([]);
|
|
1300
|
+
|
|
1301
|
+
const trusted = await backend.trusted.cms.getContentItemPopulated({
|
|
1302
|
+
typeSlug: "resource",
|
|
1303
|
+
id: source.id,
|
|
1304
|
+
});
|
|
1305
|
+
expect(trusted._relations.categoryIds?.[0]?.id).toBe(target.id);
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
it("does not return a populated target whose trusted facts change after authorization", async () => {
|
|
1309
|
+
const ownerReadAuthorization = defineAuthorization({
|
|
1310
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1311
|
+
permissions: [cmsPermissions] as const,
|
|
1312
|
+
rules: ({ cms }) => [
|
|
1313
|
+
cms.contentType.read.allow(),
|
|
1314
|
+
cms.record.read.when(
|
|
1315
|
+
({ identity, facts }) =>
|
|
1316
|
+
facts.contentType === "resource" || identity?.id === facts.authorId,
|
|
1317
|
+
),
|
|
1318
|
+
],
|
|
1319
|
+
});
|
|
1320
|
+
const events: string[] = [];
|
|
1321
|
+
const backend = makeBackend({
|
|
1322
|
+
auth: createServerAuth({
|
|
1323
|
+
authorization: ownerReadAuthorization,
|
|
1324
|
+
getIdentity: () => ({ id: "reader-1", role: "user" as const }),
|
|
1325
|
+
}),
|
|
1326
|
+
hooks: {
|
|
1327
|
+
onErrorExecuteContentOperation: (_error, operation) => {
|
|
1328
|
+
events.push(`error:${operation}`);
|
|
1329
|
+
},
|
|
1330
|
+
},
|
|
1331
|
+
});
|
|
1332
|
+
const source = await seedRecord(backend, {
|
|
1333
|
+
typeSlug: "resource",
|
|
1334
|
+
slug: "source-with-racing-relation",
|
|
1335
|
+
});
|
|
1336
|
+
const target = await seedRecord(backend, {
|
|
1337
|
+
typeSlug: "category",
|
|
1338
|
+
slug: "owned-category",
|
|
1339
|
+
authorId: "reader-1",
|
|
1340
|
+
});
|
|
1341
|
+
await backend.adapter.create<ContentRelation>({
|
|
1342
|
+
model: "contentRelation",
|
|
1343
|
+
data: {
|
|
1344
|
+
sourceId: source.id,
|
|
1345
|
+
targetId: target.id,
|
|
1346
|
+
fieldName: "categoryIds",
|
|
1347
|
+
createdAt: new Date(),
|
|
1348
|
+
},
|
|
1349
|
+
});
|
|
1350
|
+
const findMany = backend.adapter.findMany.bind(backend.adapter);
|
|
1351
|
+
let relationReads = 0;
|
|
1352
|
+
vi.spyOn(backend.adapter, "findMany").mockImplementation(async (query) => {
|
|
1353
|
+
if (query.model === "contentRelation" && ++relationReads === 2) {
|
|
1354
|
+
await backend.adapter.update<ContentItem>({
|
|
1355
|
+
model: "contentItem",
|
|
1356
|
+
where: [{ field: "id", value: target.id }],
|
|
1357
|
+
update: { authorId: "other-owner" },
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
return findMany(query);
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
const response = await backend.handler(
|
|
1364
|
+
request(`/content/resource/${source.id}/populated`, {
|
|
1365
|
+
identity: { id: "reader-1", role: "user" },
|
|
1366
|
+
}),
|
|
1367
|
+
);
|
|
1368
|
+
expect(response.status).toBe(409);
|
|
1369
|
+
expect(await response.json()).toMatchObject({
|
|
1370
|
+
code: "RECORD_STATE_CHANGED",
|
|
1371
|
+
});
|
|
1372
|
+
expect(events).toEqual(["error:get"]);
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1375
|
+
it("authorizes referring source types before returning inverse metadata", async () => {
|
|
1376
|
+
const targetOnlyAuthorization = defineAuthorization({
|
|
1377
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1378
|
+
permissions: [cmsPermissions] as const,
|
|
1379
|
+
rules: ({ cms }) => [
|
|
1380
|
+
cms.contentType.read.when(
|
|
1381
|
+
({ facts }) => facts.contentType === "category",
|
|
1382
|
+
),
|
|
1383
|
+
],
|
|
1384
|
+
});
|
|
1385
|
+
const backend = makeBackend({
|
|
1386
|
+
auth: createServerAuth({
|
|
1387
|
+
authorization: targetOnlyAuthorization,
|
|
1388
|
+
getIdentity: () => ({ id: "reader-1", role: "user" as const }),
|
|
1389
|
+
}),
|
|
1390
|
+
});
|
|
1391
|
+
|
|
1392
|
+
const response = await backend.handler(
|
|
1393
|
+
request("/content-types/category/inverse-relations", {
|
|
1394
|
+
identity: { id: "reader-1", role: "user" },
|
|
1395
|
+
}),
|
|
1396
|
+
);
|
|
1397
|
+
expect(response.status).toBe(403);
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
it("authorizes the target record and source collections before inverse counts", async () => {
|
|
1401
|
+
const inverseCountAuthorization = defineAuthorization({
|
|
1402
|
+
identity: z.object({
|
|
1403
|
+
id: z.string(),
|
|
1404
|
+
mode: z.enum([
|
|
1405
|
+
"target-only",
|
|
1406
|
+
"source-only",
|
|
1407
|
+
"all",
|
|
1408
|
+
"racing",
|
|
1409
|
+
"schema-racing",
|
|
1410
|
+
]),
|
|
1411
|
+
}),
|
|
1412
|
+
permissions: [cmsPermissions] as const,
|
|
1413
|
+
rules: ({ cms }) => [
|
|
1414
|
+
cms.contentType.read.when(
|
|
1415
|
+
({ facts }) =>
|
|
1416
|
+
facts.contentType === "category" ||
|
|
1417
|
+
facts.contentType === "category-note",
|
|
1418
|
+
),
|
|
1419
|
+
cms.record.read.when(({ identity, facts }) => {
|
|
1420
|
+
const targetRecord =
|
|
1421
|
+
facts.contentType === "category" && facts.scope === "record";
|
|
1422
|
+
const sourceCollection =
|
|
1423
|
+
facts.contentType === "category-note" &&
|
|
1424
|
+
facts.scope === "collection";
|
|
1425
|
+
if (identity?.mode === "target-only") return targetRecord;
|
|
1426
|
+
if (identity?.mode === "source-only") return sourceCollection;
|
|
1427
|
+
return (
|
|
1428
|
+
(identity?.mode === "all" ||
|
|
1429
|
+
identity?.mode === "racing" ||
|
|
1430
|
+
identity?.mode === "schema-racing") &&
|
|
1431
|
+
(targetRecord || sourceCollection)
|
|
1432
|
+
);
|
|
1433
|
+
}),
|
|
1434
|
+
],
|
|
1435
|
+
});
|
|
1436
|
+
const modes = [
|
|
1437
|
+
"target-only",
|
|
1438
|
+
"source-only",
|
|
1439
|
+
"all",
|
|
1440
|
+
"racing",
|
|
1441
|
+
"schema-racing",
|
|
1442
|
+
] as const;
|
|
1443
|
+
const baseAuth = createServerAuth({
|
|
1444
|
+
authorization: inverseCountAuthorization,
|
|
1445
|
+
getIdentity: ({ request: currentRequest }) => {
|
|
1446
|
+
const mode = currentRequest.headers.get("x-mode");
|
|
1447
|
+
return modes.includes(mode as (typeof modes)[number])
|
|
1448
|
+
? { id: "reader-1", mode: mode as (typeof modes)[number] }
|
|
1449
|
+
: null;
|
|
1450
|
+
},
|
|
1451
|
+
});
|
|
1452
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
1453
|
+
let targetId = "";
|
|
1454
|
+
const authorizationCalls = new WeakMap<Request, number>();
|
|
1455
|
+
const authorize = baseAuth.authorize.bind(baseAuth);
|
|
1456
|
+
const racingAuth: typeof baseAuth = {
|
|
1457
|
+
...baseAuth,
|
|
1458
|
+
async authorize(currentRequest, permissionRequest) {
|
|
1459
|
+
const identity = await authorize(currentRequest, permissionRequest);
|
|
1460
|
+
const count = (authorizationCalls.get(currentRequest) ?? 0) + 1;
|
|
1461
|
+
authorizationCalls.set(currentRequest, count);
|
|
1462
|
+
if (currentRequest.headers.get("x-mode") === "racing" && count === 4) {
|
|
1463
|
+
await backend.adapter.update<ContentItem>({
|
|
1464
|
+
model: "contentItem",
|
|
1465
|
+
where: [{ field: "id", value: targetId }],
|
|
1466
|
+
update: { authorId: "other-owner" },
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
if (
|
|
1470
|
+
currentRequest.headers.get("x-mode") === "schema-racing" &&
|
|
1471
|
+
count === 2
|
|
1472
|
+
) {
|
|
1473
|
+
const sourceType = await backend.adapter.findOne<ContentType>({
|
|
1474
|
+
model: "contentType",
|
|
1475
|
+
where: [{ field: "slug", value: "category-note" }],
|
|
1476
|
+
});
|
|
1477
|
+
if (!sourceType)
|
|
1478
|
+
throw new Error("Missing category-note content type");
|
|
1479
|
+
await backend.adapter.update<ContentType>({
|
|
1480
|
+
model: "contentType",
|
|
1481
|
+
where: [{ field: "id", value: sourceType.id }],
|
|
1482
|
+
update: {
|
|
1483
|
+
jsonSchema: JSON.stringify(zodToFormSchema(articleSchema)),
|
|
1484
|
+
updatedAt: new Date(),
|
|
1485
|
+
},
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
return identity;
|
|
1489
|
+
},
|
|
1490
|
+
};
|
|
1491
|
+
backend = makeBackend({ auth: racingAuth });
|
|
1492
|
+
const target = await seedRecord(backend, {
|
|
1493
|
+
typeSlug: "category",
|
|
1494
|
+
slug: "counted-category",
|
|
1495
|
+
authorId: "reader-1",
|
|
1496
|
+
});
|
|
1497
|
+
targetId = target.id;
|
|
1498
|
+
const source = await seedRecord(backend, {
|
|
1499
|
+
typeSlug: "category-note",
|
|
1500
|
+
slug: "counted-note",
|
|
1501
|
+
});
|
|
1502
|
+
const wrongTypeTarget = await seedRecord(backend, {
|
|
1503
|
+
typeSlug: "article",
|
|
1504
|
+
slug: "wrong-target-type",
|
|
1505
|
+
});
|
|
1506
|
+
await backend.adapter.create<ContentRelation>({
|
|
1507
|
+
model: "contentRelation",
|
|
1508
|
+
data: {
|
|
1509
|
+
sourceId: source.id,
|
|
1510
|
+
targetId: target.id,
|
|
1511
|
+
fieldName: "categoryId",
|
|
1512
|
+
createdAt: new Date(),
|
|
1513
|
+
},
|
|
1514
|
+
});
|
|
1515
|
+
const findMany = backend.adapter.findMany.bind(backend.adapter);
|
|
1516
|
+
let relationReads = 0;
|
|
1517
|
+
vi.spyOn(backend.adapter, "findMany").mockImplementation(async (query) => {
|
|
1518
|
+
if (query.model === "contentRelation") relationReads += 1;
|
|
1519
|
+
return findMany(query);
|
|
1520
|
+
});
|
|
1521
|
+
const countRequest = (mode: (typeof modes)[number]) =>
|
|
1522
|
+
new Request(
|
|
1523
|
+
`http://localhost/api/content-types/category/inverse-relations?itemId=${target.id}`,
|
|
1524
|
+
{ headers: { "x-mode": mode } },
|
|
1525
|
+
);
|
|
1526
|
+
const listRequest = (
|
|
1527
|
+
mode: (typeof modes)[number],
|
|
1528
|
+
options?: { itemId?: string; fieldName?: string },
|
|
1529
|
+
) =>
|
|
1530
|
+
new Request(
|
|
1531
|
+
`http://localhost/api/content-types/category/inverse-relations/category-note?itemId=${options?.itemId ?? target.id}&fieldName=${options?.fieldName ?? "categoryId"}`,
|
|
1532
|
+
{ headers: { "x-mode": mode } },
|
|
1533
|
+
);
|
|
1534
|
+
|
|
1535
|
+
const listTargetDenied = await backend.handler(listRequest("source-only"));
|
|
1536
|
+
expect(listTargetDenied.status).toBe(403);
|
|
1537
|
+
const wrongTargetType = await backend.handler(
|
|
1538
|
+
listRequest("all", { itemId: wrongTypeTarget.id }),
|
|
1539
|
+
);
|
|
1540
|
+
expect(wrongTargetType.status).toBe(404);
|
|
1541
|
+
const invalidField = await backend.handler(
|
|
1542
|
+
listRequest("all", { fieldName: "notACategoryRelation" }),
|
|
1543
|
+
);
|
|
1544
|
+
expect(invalidField.status).toBe(404);
|
|
1545
|
+
expect(await invalidField.json()).toMatchObject({
|
|
1546
|
+
code: "INVERSE_RELATION_NOT_FOUND",
|
|
1547
|
+
});
|
|
1548
|
+
expect(relationReads).toBe(0);
|
|
1549
|
+
|
|
1550
|
+
const allowedList = await backend.handler(listRequest("all"));
|
|
1551
|
+
expect(allowedList.status).toBe(200);
|
|
1552
|
+
expect(await allowedList.json()).toMatchObject({
|
|
1553
|
+
total: 1,
|
|
1554
|
+
items: [{ id: source.id }],
|
|
1555
|
+
});
|
|
1556
|
+
expect(relationReads).toBe(1);
|
|
1557
|
+
|
|
1558
|
+
const sourceDenied = await backend.handler(countRequest("target-only"));
|
|
1559
|
+
expect(sourceDenied.status).toBe(403);
|
|
1560
|
+
const targetDenied = await backend.handler(countRequest("source-only"));
|
|
1561
|
+
expect(targetDenied.status).toBe(403);
|
|
1562
|
+
expect(relationReads).toBe(1);
|
|
1563
|
+
|
|
1564
|
+
const allowed = await backend.handler(countRequest("all"));
|
|
1565
|
+
expect(allowed.status).toBe(200);
|
|
1566
|
+
expect(await allowed.json()).toMatchObject({
|
|
1567
|
+
inverseRelations: [{ sourceType: "category-note", count: 1 }],
|
|
1568
|
+
});
|
|
1569
|
+
expect(relationReads).toBe(2);
|
|
1570
|
+
|
|
1571
|
+
const staleTarget = await backend.handler(countRequest("racing"));
|
|
1572
|
+
expect(staleTarget.status).toBe(409);
|
|
1573
|
+
expect(await staleTarget.json()).toMatchObject({
|
|
1574
|
+
code: "RECORD_STATE_CHANGED",
|
|
1575
|
+
});
|
|
1576
|
+
expect(relationReads).toBe(2);
|
|
1577
|
+
|
|
1578
|
+
const staleSchema = await backend.handler(listRequest("schema-racing"));
|
|
1579
|
+
expect(staleSchema.status).toBe(409);
|
|
1580
|
+
expect(await staleSchema.json()).toMatchObject({
|
|
1581
|
+
code: "RELATION_SCHEMA_CHANGED",
|
|
1582
|
+
});
|
|
1583
|
+
expect(relationReads).toBe(2);
|
|
1584
|
+
});
|
|
1585
|
+
|
|
1586
|
+
it("fails closed when inverse relation schemas change after authorization", async () => {
|
|
1587
|
+
const inverseAuthorization = defineAuthorization({
|
|
1588
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1589
|
+
permissions: [cmsPermissions] as const,
|
|
1590
|
+
rules: ({ cms }) => [
|
|
1591
|
+
cms.contentType.read.when(
|
|
1592
|
+
({ facts }) =>
|
|
1593
|
+
facts.contentType === "category" ||
|
|
1594
|
+
facts.contentType === "category-note",
|
|
1595
|
+
),
|
|
1596
|
+
],
|
|
1597
|
+
});
|
|
1598
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
1599
|
+
const baseAuth = createServerAuth({
|
|
1600
|
+
authorization: inverseAuthorization,
|
|
1601
|
+
getIdentity: () => ({ id: "reader-1", role: "user" as const }),
|
|
1602
|
+
});
|
|
1603
|
+
const authorize = baseAuth.authorize.bind(baseAuth);
|
|
1604
|
+
let authorizationCalls = 0;
|
|
1605
|
+
const racingAuth: typeof baseAuth = {
|
|
1606
|
+
...baseAuth,
|
|
1607
|
+
async authorize(request, permissionRequest) {
|
|
1608
|
+
const identity = await authorize(request, permissionRequest);
|
|
1609
|
+
if (++authorizationCalls === 2) {
|
|
1610
|
+
const resourceType = await backend.adapter.findOne<ContentType>({
|
|
1611
|
+
model: "contentType",
|
|
1612
|
+
where: [{ field: "slug", value: "resource" }],
|
|
1613
|
+
});
|
|
1614
|
+
if (!resourceType) throw new Error("Missing resource content type");
|
|
1615
|
+
await backend.adapter.update<ContentType>({
|
|
1616
|
+
model: "contentType",
|
|
1617
|
+
where: [{ field: "id", value: resourceType.id }],
|
|
1618
|
+
update: {
|
|
1619
|
+
jsonSchema: JSON.stringify(
|
|
1620
|
+
zodToFormSchema(inverseResourceRelationSchema),
|
|
1621
|
+
),
|
|
1622
|
+
updatedAt: new Date(),
|
|
1623
|
+
},
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
return identity;
|
|
1627
|
+
},
|
|
1628
|
+
};
|
|
1629
|
+
backend = makeBackend({ auth: racingAuth });
|
|
1630
|
+
await allContentTypes(backend);
|
|
1631
|
+
|
|
1632
|
+
const response = await backend.handler(
|
|
1633
|
+
request("/content-types/category/inverse-relations", {
|
|
1634
|
+
identity: { id: "reader-1", role: "user" },
|
|
1635
|
+
}),
|
|
1636
|
+
);
|
|
1637
|
+
expect(response.status).toBe(409);
|
|
1638
|
+
expect(await response.json()).toMatchObject({
|
|
1639
|
+
code: "RELATION_SCHEMA_CHANGED",
|
|
1640
|
+
});
|
|
1641
|
+
});
|
|
1642
|
+
|
|
1643
|
+
it("derives detail-by-slug facts for UI Builder and other page renderers", async () => {
|
|
1644
|
+
const ownerReadAuthorization = defineAuthorization({
|
|
1645
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
1646
|
+
permissions: [cmsPermissions] as const,
|
|
1647
|
+
rules: ({ cms }) => [
|
|
1648
|
+
cms.contentType.read.when(
|
|
1649
|
+
({ facts }) => facts.contentType === "article",
|
|
1650
|
+
),
|
|
1651
|
+
cms.record.read.when(
|
|
1652
|
+
({ identity, facts }) =>
|
|
1653
|
+
identity?.id === facts.authorId && facts.recordId !== undefined,
|
|
1654
|
+
),
|
|
1655
|
+
],
|
|
1656
|
+
});
|
|
1657
|
+
const backend = makeBackend({
|
|
1658
|
+
auth: createServerAuth({
|
|
1659
|
+
authorization: ownerReadAuthorization,
|
|
1660
|
+
getIdentity: ({ request: currentRequest }) => {
|
|
1661
|
+
const id = currentRequest.headers.get("x-user-id");
|
|
1662
|
+
return id ? { id, role: "user" as const } : null;
|
|
1663
|
+
},
|
|
1664
|
+
}),
|
|
1665
|
+
});
|
|
1666
|
+
const record = await seedRecord(backend, {
|
|
1667
|
+
slug: "rendered-page",
|
|
1668
|
+
authorId: "owner-1",
|
|
1669
|
+
});
|
|
1670
|
+
|
|
1671
|
+
const owner = await backend.handler(
|
|
1672
|
+
request("/content/article?slug=rendered-page&limit=1", {
|
|
1673
|
+
identity: { id: "owner-1", role: "user" },
|
|
1674
|
+
}),
|
|
1675
|
+
);
|
|
1676
|
+
expect(owner.status).toBe(200);
|
|
1677
|
+
expect((await owner.json()).items[0]?.id).toBe(record.id);
|
|
1678
|
+
const viewer = await backend.handler(
|
|
1679
|
+
request("/content/article?slug=rendered-page&limit=1", {
|
|
1680
|
+
identity: { id: "viewer-1", role: "user" },
|
|
1681
|
+
}),
|
|
1682
|
+
);
|
|
1683
|
+
expect(viewer.status).toBe(403);
|
|
1684
|
+
});
|
|
1685
|
+
|
|
1686
|
+
it("keeps anonymous by-slug rendering public without exposing the admin list", async () => {
|
|
1687
|
+
const publicPageAuthorization = defineAuthorization({
|
|
1688
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
1689
|
+
permissions: [cmsPermissions] as const,
|
|
1690
|
+
rules: ({ cms }) => [
|
|
1691
|
+
cms.contentType.read.when(
|
|
1692
|
+
({ facts }) => facts.contentType === "article",
|
|
1693
|
+
),
|
|
1694
|
+
cms.record.read.when(
|
|
1695
|
+
({ facts }) =>
|
|
1696
|
+
facts.contentType === "article" && facts.scope === "record",
|
|
1697
|
+
),
|
|
1698
|
+
],
|
|
1699
|
+
});
|
|
1700
|
+
const backend = makeBackend({
|
|
1701
|
+
auth: createServerAuth({
|
|
1702
|
+
authorization: publicPageAuthorization,
|
|
1703
|
+
getIdentity: () => null,
|
|
1704
|
+
}),
|
|
1705
|
+
});
|
|
1706
|
+
const record = await seedRecord(backend, {
|
|
1707
|
+
slug: "public-render",
|
|
1708
|
+
authorId: "owner-1",
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1711
|
+
const publicRender = await backend.handler(
|
|
1712
|
+
request("/content/article?slug=public-render&limit=1"),
|
|
1713
|
+
);
|
|
1714
|
+
expect(publicRender.status).toBe(200);
|
|
1715
|
+
expect((await publicRender.json()).items[0]?.id).toBe(record.id);
|
|
1716
|
+
const missingRender = await backend.handler(
|
|
1717
|
+
request("/content/article?slug=missing-render&limit=1"),
|
|
1718
|
+
);
|
|
1719
|
+
expect(missingRender.status).toBe(200);
|
|
1720
|
+
expect(await missingRender.json()).toMatchObject({ items: [], total: 0 });
|
|
1721
|
+
expect(await backend.handler(request("/content/article"))).toMatchObject({
|
|
1722
|
+
status: 401,
|
|
1723
|
+
});
|
|
1724
|
+
});
|
|
1725
|
+
|
|
1726
|
+
it("preserves empty by-slug results when pagination or search excludes the authorized record", async () => {
|
|
1727
|
+
const publicPageAuthorization = defineAuthorization({
|
|
1728
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1729
|
+
permissions: [cmsPermissions] as const,
|
|
1730
|
+
rules: ({ cms }) => [
|
|
1731
|
+
cms.contentType.read.when(
|
|
1732
|
+
({ facts }) => facts.contentType === "article",
|
|
1733
|
+
),
|
|
1734
|
+
cms.record.read.when(({ facts }) => facts.scope === "record"),
|
|
1735
|
+
],
|
|
1736
|
+
});
|
|
1737
|
+
const backend = makeBackend({
|
|
1738
|
+
auth: createServerAuth({
|
|
1739
|
+
authorization: publicPageAuthorization,
|
|
1740
|
+
getIdentity: () => null,
|
|
1741
|
+
}),
|
|
1742
|
+
});
|
|
1743
|
+
await seedRecord(backend, {
|
|
1744
|
+
slug: "filtered-render",
|
|
1745
|
+
authorId: "owner-1",
|
|
1746
|
+
});
|
|
1747
|
+
|
|
1748
|
+
const paginated = await backend.handler(
|
|
1749
|
+
request("/content/article?slug=filtered-render&limit=1&offset=1"),
|
|
1750
|
+
);
|
|
1751
|
+
expect(paginated.status).toBe(200);
|
|
1752
|
+
expect(await paginated.json()).toMatchObject({
|
|
1753
|
+
items: [],
|
|
1754
|
+
total: 1,
|
|
1755
|
+
limit: 1,
|
|
1756
|
+
offset: 1,
|
|
1757
|
+
});
|
|
1758
|
+
|
|
1759
|
+
const searched = await backend.handler(
|
|
1760
|
+
request(
|
|
1761
|
+
"/content/article?slug=filtered-render&search=does-not-match&limit=1",
|
|
1762
|
+
),
|
|
1763
|
+
);
|
|
1764
|
+
expect(searched.status).toBe(200);
|
|
1765
|
+
expect(await searched.json()).toMatchObject({
|
|
1766
|
+
items: [],
|
|
1767
|
+
total: 0,
|
|
1768
|
+
limit: 1,
|
|
1769
|
+
offset: 0,
|
|
1770
|
+
});
|
|
1771
|
+
});
|
|
1772
|
+
|
|
1773
|
+
it("does not return a by-slug record whose ownership changes after authorization", async () => {
|
|
1774
|
+
const ownerReadAuthorization = defineAuthorization({
|
|
1775
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1776
|
+
permissions: [cmsPermissions] as const,
|
|
1777
|
+
rules: ({ cms }) => [
|
|
1778
|
+
cms.contentType.read.when(
|
|
1779
|
+
({ facts }) => facts.contentType === "article",
|
|
1780
|
+
),
|
|
1781
|
+
cms.record.read.when(
|
|
1782
|
+
({ identity, facts }) => identity?.id === facts.authorId,
|
|
1783
|
+
),
|
|
1784
|
+
],
|
|
1785
|
+
});
|
|
1786
|
+
const backend = makeBackend({
|
|
1787
|
+
auth: createServerAuth({
|
|
1788
|
+
authorization: ownerReadAuthorization,
|
|
1789
|
+
getIdentity: () => ({ id: "owner-1", role: "user" as const }),
|
|
1790
|
+
}),
|
|
1791
|
+
});
|
|
1792
|
+
const record = await seedRecord(backend, {
|
|
1793
|
+
slug: "ownership-race",
|
|
1794
|
+
authorId: "owner-1",
|
|
1795
|
+
});
|
|
1796
|
+
const findMany = backend.adapter.findMany.bind(backend.adapter);
|
|
1797
|
+
vi.spyOn(backend.adapter, "findMany").mockImplementation(async (query) => {
|
|
1798
|
+
if (query.model === "contentItem") {
|
|
1799
|
+
await backend.adapter.update<ContentItem>({
|
|
1800
|
+
model: "contentItem",
|
|
1801
|
+
where: [{ field: "id", value: record.id }],
|
|
1802
|
+
update: { authorId: "other-owner" },
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
return findMany(query);
|
|
1806
|
+
});
|
|
1807
|
+
|
|
1808
|
+
const response = await backend.handler(
|
|
1809
|
+
request("/content/article?slug=ownership-race&limit=1"),
|
|
1810
|
+
);
|
|
1811
|
+
expect(response.status).toBe(409);
|
|
1812
|
+
expect(await response.json()).toMatchObject({
|
|
1813
|
+
code: "RECORD_STATE_CHANGED",
|
|
1814
|
+
});
|
|
1815
|
+
});
|
|
1816
|
+
|
|
1817
|
+
it("does not expose a by-slug record created after a public missing-record check", async () => {
|
|
1818
|
+
const publicPageAuthorization = defineAuthorization({
|
|
1819
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1820
|
+
permissions: [cmsPermissions] as const,
|
|
1821
|
+
rules: ({ cms }) => [
|
|
1822
|
+
cms.contentType.read.when(
|
|
1823
|
+
({ facts }) => facts.contentType === "article",
|
|
1824
|
+
),
|
|
1825
|
+
cms.record.read.when(({ facts }) => facts.scope === "record"),
|
|
1826
|
+
],
|
|
1827
|
+
});
|
|
1828
|
+
const backend = makeBackend({
|
|
1829
|
+
auth: createServerAuth({
|
|
1830
|
+
authorization: publicPageAuthorization,
|
|
1831
|
+
getIdentity: () => null,
|
|
1832
|
+
}),
|
|
1833
|
+
});
|
|
1834
|
+
const contentType = (await allContentTypes(backend)).find(
|
|
1835
|
+
(value) => value.slug === "article",
|
|
1836
|
+
);
|
|
1837
|
+
if (!contentType) throw new Error("Missing article content type");
|
|
1838
|
+
const findMany = backend.adapter.findMany.bind(backend.adapter);
|
|
1839
|
+
let inserted = false;
|
|
1840
|
+
vi.spyOn(backend.adapter, "findMany").mockImplementation(async (query) => {
|
|
1841
|
+
if (query.model === "contentItem" && !inserted) {
|
|
1842
|
+
inserted = true;
|
|
1843
|
+
await backend.adapter.create<ContentItem>({
|
|
1844
|
+
model: "contentItem",
|
|
1845
|
+
data: {
|
|
1846
|
+
contentTypeId: contentType.id,
|
|
1847
|
+
slug: "just-created",
|
|
1848
|
+
data: JSON.stringify({ title: "Just created" }),
|
|
1849
|
+
authorId: "private-owner",
|
|
1850
|
+
createdAt: new Date(),
|
|
1851
|
+
updatedAt: new Date(),
|
|
1852
|
+
},
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
return findMany(query);
|
|
1856
|
+
});
|
|
1857
|
+
|
|
1858
|
+
const response = await backend.handler(
|
|
1859
|
+
request("/content/article?slug=just-created&limit=1&offset=1"),
|
|
1860
|
+
);
|
|
1861
|
+
expect(response.status).toBe(409);
|
|
1862
|
+
expect(await response.json()).toMatchObject({
|
|
1863
|
+
code: "RECORD_STATE_CHANGED",
|
|
1864
|
+
});
|
|
1865
|
+
});
|
|
1866
|
+
|
|
1867
|
+
it("keeps identity, missing-rule, policy, fact, and input failures outside hooks", async () => {
|
|
1868
|
+
const events: string[] = [];
|
|
1869
|
+
const hooks: CMSBackendHooks = {
|
|
1870
|
+
onBeforeDeleteContent: () => {
|
|
1871
|
+
events.push("before");
|
|
1872
|
+
},
|
|
1873
|
+
onAfterDeleteContent: () => {
|
|
1874
|
+
events.push("after");
|
|
1875
|
+
},
|
|
1876
|
+
onErrorExecuteContentOperation: () => {
|
|
1877
|
+
events.push("error");
|
|
1878
|
+
},
|
|
1879
|
+
};
|
|
1880
|
+
const identityFailure = makeBackend({
|
|
1881
|
+
auth: createAuth(() => {
|
|
1882
|
+
throw new Error("session unavailable");
|
|
1883
|
+
}),
|
|
1884
|
+
hooks,
|
|
1885
|
+
});
|
|
1886
|
+
const identityRecord = await seedRecord(identityFailure, {
|
|
1887
|
+
slug: "identity-failure",
|
|
1888
|
+
authorId: "author-1",
|
|
1889
|
+
});
|
|
1890
|
+
await expect(
|
|
1891
|
+
identityFailure
|
|
1892
|
+
.forRequest(request("/delete"))
|
|
1893
|
+
.operations.cms.deleteContentItem({
|
|
1894
|
+
typeSlug: "article",
|
|
1895
|
+
id: identityRecord.id,
|
|
1896
|
+
}),
|
|
1897
|
+
).rejects.toThrow("session unavailable");
|
|
1898
|
+
|
|
1899
|
+
for (const [rule, expected] of [
|
|
1900
|
+
[undefined, { statusCode: 403 }],
|
|
1901
|
+
["throw", "policy unavailable"],
|
|
1902
|
+
] as const) {
|
|
1903
|
+
const definition = defineAuthorization({
|
|
1904
|
+
identity: z.object({ id: z.string(), role: z.literal("user") }),
|
|
1905
|
+
permissions: [cmsPermissions] as const,
|
|
1906
|
+
rules: ({ cms }) =>
|
|
1907
|
+
rule === "throw"
|
|
1908
|
+
? [
|
|
1909
|
+
cms.record.delete.when(() => {
|
|
1910
|
+
throw new Error("policy unavailable");
|
|
1911
|
+
}),
|
|
1912
|
+
]
|
|
1913
|
+
: [],
|
|
1914
|
+
});
|
|
1915
|
+
const backend = makeBackend({
|
|
1916
|
+
auth: createServerAuth({
|
|
1917
|
+
authorization: definition,
|
|
1918
|
+
getIdentity: () => ({ id: "author-1", role: "user" as const }),
|
|
1919
|
+
}),
|
|
1920
|
+
hooks,
|
|
1921
|
+
});
|
|
1922
|
+
const record = await seedRecord(backend, {
|
|
1923
|
+
slug: `rule-${rule ?? "missing"}`,
|
|
1924
|
+
authorId: "author-1",
|
|
1925
|
+
});
|
|
1926
|
+
const rejection = expect(
|
|
1927
|
+
backend
|
|
1928
|
+
.forRequest(request("/delete"))
|
|
1929
|
+
.operations.cms.deleteContentItem({
|
|
1930
|
+
typeSlug: "article",
|
|
1931
|
+
id: record.id,
|
|
1932
|
+
}),
|
|
1933
|
+
).rejects;
|
|
1934
|
+
if (typeof expected === "string") await rejection.toThrow(expected);
|
|
1935
|
+
else await rejection.toMatchObject(expected);
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
const factFailure = makeBackend({ hooks });
|
|
1939
|
+
vi.spyOn(factFailure.adapter, "findOne").mockRejectedValueOnce(
|
|
1940
|
+
new Error("facts unavailable"),
|
|
1941
|
+
);
|
|
1942
|
+
await expect(
|
|
1943
|
+
factFailure.trusted.cms.deleteContentItem({
|
|
1944
|
+
typeSlug: "article",
|
|
1945
|
+
id: "missing",
|
|
1946
|
+
}),
|
|
1947
|
+
).rejects.toThrow("facts unavailable");
|
|
1948
|
+
await expect(
|
|
1949
|
+
factFailure.trusted.cms.deleteContentItem({
|
|
1950
|
+
typeSlug: "article",
|
|
1951
|
+
id: 1,
|
|
1952
|
+
} as never),
|
|
1953
|
+
).rejects.toBeInstanceOf(z.ZodError);
|
|
1954
|
+
expect(events).toEqual([]);
|
|
1955
|
+
});
|
|
1956
|
+
|
|
1957
|
+
it("preserves 403 denials from plain before-hook errors", async () => {
|
|
1958
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
1959
|
+
backend = makeBackend({
|
|
1960
|
+
auth: createAuth(),
|
|
1961
|
+
hooks: {
|
|
1962
|
+
onBeforeCreateContent: async (data) => {
|
|
1963
|
+
expect(data).toMatchObject({
|
|
1964
|
+
name: "Denied",
|
|
1965
|
+
categoryIds: [{ id: expect.any(String) }],
|
|
1966
|
+
});
|
|
1967
|
+
expect((await allContentItems(backend, "category")).total).toBe(0);
|
|
1968
|
+
throw new Error("Create denied by hook");
|
|
1969
|
+
},
|
|
1970
|
+
onBeforeUpdateContent: (_id, data) => {
|
|
1971
|
+
expect(data).toMatchObject({ title: "hook-protected" });
|
|
1972
|
+
throw new Error("Update denied by hook");
|
|
1973
|
+
},
|
|
1974
|
+
onBeforeDeleteContent: () => {
|
|
1975
|
+
throw new Error("Delete denied by hook");
|
|
1976
|
+
},
|
|
1977
|
+
},
|
|
1978
|
+
});
|
|
1979
|
+
const record = await seedRecord(backend, {
|
|
1980
|
+
slug: "hook-protected",
|
|
1981
|
+
authorId: "author-1",
|
|
1982
|
+
});
|
|
1983
|
+
const identity = { id: "author-1", role: "user" as const };
|
|
1984
|
+
|
|
1985
|
+
for (const [response, message] of [
|
|
1986
|
+
[
|
|
1987
|
+
await backend.handler(
|
|
1988
|
+
request("/content/resource", {
|
|
1989
|
+
method: "POST",
|
|
1990
|
+
identity,
|
|
1991
|
+
body: {
|
|
1992
|
+
slug: "denied-create",
|
|
1993
|
+
data: {
|
|
1994
|
+
name: "Denied",
|
|
1995
|
+
categoryIds: [
|
|
1996
|
+
{ _new: true, data: { name: "Should not persist" } },
|
|
1997
|
+
],
|
|
1998
|
+
},
|
|
1999
|
+
},
|
|
2000
|
+
}),
|
|
2001
|
+
),
|
|
2002
|
+
"Create denied by hook",
|
|
2003
|
+
],
|
|
2004
|
+
[
|
|
2005
|
+
await backend.handler(
|
|
2006
|
+
request(`/content/article/${record.id}`, {
|
|
2007
|
+
method: "PUT",
|
|
2008
|
+
identity,
|
|
2009
|
+
body: { data: {} },
|
|
2010
|
+
}),
|
|
2011
|
+
),
|
|
2012
|
+
"Update denied by hook",
|
|
2013
|
+
],
|
|
2014
|
+
[
|
|
2015
|
+
await backend.handler(
|
|
2016
|
+
request(`/content/article/${record.id}`, {
|
|
2017
|
+
method: "PUT",
|
|
2018
|
+
identity,
|
|
2019
|
+
body: { slug: "denied-rename" },
|
|
2020
|
+
}),
|
|
2021
|
+
),
|
|
2022
|
+
"Update denied by hook",
|
|
2023
|
+
],
|
|
2024
|
+
[
|
|
2025
|
+
await backend.handler(
|
|
2026
|
+
request(`/content/article/${record.id}`, {
|
|
2027
|
+
method: "DELETE",
|
|
2028
|
+
identity,
|
|
2029
|
+
}),
|
|
2030
|
+
),
|
|
2031
|
+
"Delete denied by hook",
|
|
2032
|
+
],
|
|
2033
|
+
] as const) {
|
|
2034
|
+
expect(response.status).toBe(403);
|
|
2035
|
+
expect(await response.json()).toMatchObject({
|
|
2036
|
+
code: "HOOK_DENIED",
|
|
2037
|
+
message,
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
expect((await allContentItems(backend, "article")).total).toBe(1);
|
|
2042
|
+
expect((await allContentItems(backend, "category")).total).toBe(0);
|
|
2043
|
+
expect((await allContentItems(backend, "resource")).total).toBe(0);
|
|
2044
|
+
expect(
|
|
2045
|
+
JSON.parse(
|
|
2046
|
+
(
|
|
2047
|
+
await backend.adapter.findOne<ContentItem>({
|
|
2048
|
+
model: "contentItem",
|
|
2049
|
+
where: [{ field: "id", value: record.id }],
|
|
2050
|
+
})
|
|
2051
|
+
)?.data ?? "{}",
|
|
2052
|
+
).title,
|
|
2053
|
+
).toBe("hook-protected");
|
|
2054
|
+
});
|
|
2055
|
+
|
|
2056
|
+
it("detects ownership changes after authorization before an update commits", async () => {
|
|
2057
|
+
const events: string[] = [];
|
|
2058
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
2059
|
+
backend = makeBackend({
|
|
2060
|
+
auth: createAuth(),
|
|
2061
|
+
hooks: {
|
|
2062
|
+
onBeforeUpdateContent: async (id) => {
|
|
2063
|
+
events.push("before");
|
|
2064
|
+
expect((await allContentItems(backend, "category")).total).toBe(0);
|
|
2065
|
+
await backend.adapter.update<ContentItem>({
|
|
2066
|
+
model: "contentItem",
|
|
2067
|
+
where: [{ field: "id", value: id }],
|
|
2068
|
+
update: { authorId: "other-owner" },
|
|
2069
|
+
});
|
|
2070
|
+
},
|
|
2071
|
+
onAfterUpdateContent: () => {
|
|
2072
|
+
events.push("after");
|
|
2073
|
+
},
|
|
2074
|
+
onErrorExecuteContentOperation: (_error, operation, context) => {
|
|
2075
|
+
events.push(`error:${operation}`);
|
|
2076
|
+
expect(context.error).toMatchObject({
|
|
2077
|
+
code: "RECORD_STATE_CHANGED",
|
|
2078
|
+
});
|
|
2079
|
+
},
|
|
2080
|
+
},
|
|
2081
|
+
});
|
|
2082
|
+
const record = await seedRecord(backend, {
|
|
2083
|
+
typeSlug: "resource",
|
|
2084
|
+
slug: "stale-owner",
|
|
2085
|
+
authorId: "author-1",
|
|
2086
|
+
});
|
|
2087
|
+
await expect(
|
|
2088
|
+
backend
|
|
2089
|
+
.forRequest(
|
|
2090
|
+
request(`/content/resource/${record.id}`, {
|
|
2091
|
+
identity: { id: "author-1", role: "user" },
|
|
2092
|
+
}),
|
|
2093
|
+
)
|
|
2094
|
+
.operations.cms.updateContentItem({
|
|
2095
|
+
typeSlug: "resource",
|
|
2096
|
+
id: record.id,
|
|
2097
|
+
body: {
|
|
2098
|
+
data: {
|
|
2099
|
+
name: "Must not commit",
|
|
2100
|
+
categoryIds: [{ _new: true, data: { name: "Must not persist" } }],
|
|
2101
|
+
},
|
|
2102
|
+
},
|
|
2103
|
+
}),
|
|
2104
|
+
).rejects.toMatchObject({ statusCode: 409, code: "RECORD_STATE_CHANGED" });
|
|
2105
|
+
expect(events).toEqual(["before", "error:update"]);
|
|
2106
|
+
const persisted = await backend.adapter.findOne<ContentItem>({
|
|
2107
|
+
model: "contentItem",
|
|
2108
|
+
where: [{ field: "id", value: record.id }],
|
|
2109
|
+
});
|
|
2110
|
+
expect(JSON.parse(persisted?.data ?? "{}").title).toBe("stale-owner");
|
|
2111
|
+
expect((await allContentItems(backend, "category")).total).toBe(0);
|
|
2112
|
+
});
|
|
2113
|
+
|
|
2114
|
+
it("revalidates delete ownership before entering lifecycle hooks", async () => {
|
|
2115
|
+
const events: string[] = [];
|
|
2116
|
+
const baseAuth = createAuth();
|
|
2117
|
+
const authorize = baseAuth.authorize.bind(baseAuth);
|
|
2118
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
2119
|
+
let record: Awaited<ReturnType<typeof seedRecord>>;
|
|
2120
|
+
let ownershipChanged = false;
|
|
2121
|
+
const racingAuth: typeof baseAuth = {
|
|
2122
|
+
...baseAuth,
|
|
2123
|
+
async authorize(request, permissionRequest) {
|
|
2124
|
+
const identity = await authorize(request, permissionRequest);
|
|
2125
|
+
if (!ownershipChanged) {
|
|
2126
|
+
ownershipChanged = true;
|
|
2127
|
+
await backend.adapter.update<ContentItem>({
|
|
2128
|
+
model: "contentItem",
|
|
2129
|
+
where: [{ field: "id", value: record.id }],
|
|
2130
|
+
update: { authorId: "other-owner" },
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
return identity;
|
|
2134
|
+
},
|
|
2135
|
+
};
|
|
2136
|
+
backend = makeBackend({
|
|
2137
|
+
auth: racingAuth,
|
|
2138
|
+
hooks: {
|
|
2139
|
+
onBeforeDeleteContent: () => {
|
|
2140
|
+
events.push("before");
|
|
2141
|
+
},
|
|
2142
|
+
onAfterDeleteContent: () => {
|
|
2143
|
+
events.push("after");
|
|
2144
|
+
},
|
|
2145
|
+
onErrorExecuteContentOperation: (_error, operation, context) => {
|
|
2146
|
+
events.push(`error:${operation}`);
|
|
2147
|
+
expect(context.error).toMatchObject({
|
|
2148
|
+
code: "RECORD_STATE_CHANGED",
|
|
2149
|
+
});
|
|
2150
|
+
},
|
|
2151
|
+
},
|
|
2152
|
+
});
|
|
2153
|
+
record = await seedRecord(backend, {
|
|
2154
|
+
slug: "delete-ownership-race",
|
|
2155
|
+
authorId: "author-1",
|
|
2156
|
+
});
|
|
2157
|
+
|
|
2158
|
+
const response = await backend.handler(
|
|
2159
|
+
request(`/content/article/${record.id}`, {
|
|
2160
|
+
method: "DELETE",
|
|
2161
|
+
identity: { id: "author-1", role: "user" },
|
|
2162
|
+
}),
|
|
2163
|
+
);
|
|
2164
|
+
|
|
2165
|
+
expect(response.status).toBe(409);
|
|
2166
|
+
expect(await response.json()).toMatchObject({
|
|
2167
|
+
code: "RECORD_STATE_CHANGED",
|
|
2168
|
+
});
|
|
2169
|
+
expect(events).toEqual(["error:delete"]);
|
|
2170
|
+
expect(
|
|
2171
|
+
await backend.adapter.findOne<ContentItem>({
|
|
2172
|
+
model: "contentItem",
|
|
2173
|
+
where: [{ field: "id", value: record.id }],
|
|
2174
|
+
}),
|
|
2175
|
+
).toMatchObject({ authorId: "other-owner" });
|
|
2176
|
+
});
|
|
2177
|
+
|
|
2178
|
+
it("preserves permissive compatibility when authorization is omitted", async () => {
|
|
2179
|
+
const backend = makeBackend();
|
|
2180
|
+
const response = await backend.handler(
|
|
2181
|
+
request("/content/article", {
|
|
2182
|
+
method: "POST",
|
|
2183
|
+
body: { slug: "legacy", data: { title: "Legacy" } },
|
|
2184
|
+
}),
|
|
2185
|
+
);
|
|
2186
|
+
expect(response.status).toBe(200);
|
|
2187
|
+
});
|
|
2188
|
+
});
|