@btst/stack 3.0.0-rc.2 → 3.0.0-rc.3
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.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.B8PG21zX.d.mts +764 -0
- package/dist/shared/stack.BFP_9pRX.d.cts +707 -0
- package/dist/shared/{stack.DzwZw-Ck.d.cts → stack.BGzgFx3R.d.cts} +2 -2
- 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.BMmvEBH_.d.ts +118 -0
- package/dist/shared/stack.BOZRaVpu.d.cts +1184 -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.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.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.BuxUQqL8.d.ts +408 -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.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.CX83YNuS.d.cts +408 -0
- 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.oVIdV7XS.d.mts → stack.CjCSDfWy.d.mts} +2 -2
- 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.CvlC5kqe.d.cts +331 -0
- package/dist/shared/stack.CxKc9evq.d.ts +23 -0
- package/dist/shared/stack.CyalJ0j6.d.ts +764 -0
- package/dist/shared/stack.D6Pg-ufX.d.cts +764 -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.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.DlBoNqYu.d.ts +1184 -0
- 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.DseBJmGF.d.ts → stack.Dpg_JjIo.d.ts} +2 -2
- package/dist/shared/stack.Dvy7FmaA.d.mts +1184 -0
- package/dist/shared/stack.DxHPKr2R.d.mts +436 -0
- package/dist/shared/stack.Egr3RWhA.d.mts +408 -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.v2O65JqF.d.cts +351 -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.Csi-4Mgz.d.cts} +1 -1
- package/dist/shared/{stack.D18Dq3ve.d.ts → stack.Csi-4Mgz.d.mts} +1 -1
- package/dist/shared/{stack.D18Dq3ve.d.cts → stack.Csi-4Mgz.d.ts} +1 -1
|
@@ -0,0 +1,1769 @@
|
|
|
1
|
+
import { createMemoryAdapter } from "@btst/adapter-memory";
|
|
2
|
+
import { type DatabaseDefinition, type DBAdapter, defineDb } from "@btst/db";
|
|
3
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { createHmac } from "node:crypto";
|
|
5
|
+
import { describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { createBackendStack } from "../../../api";
|
|
8
|
+
import { defineAuthorization } from "../../../authorization";
|
|
9
|
+
import {
|
|
10
|
+
createServerAuth,
|
|
11
|
+
type ServerAuth,
|
|
12
|
+
} from "../../../authorization/server";
|
|
13
|
+
import {
|
|
14
|
+
MEDIA_LIFECYCLE_HOOK_MIGRATIONS,
|
|
15
|
+
MEDIA_QUERY_KEYS,
|
|
16
|
+
VercelBlobOperationInputSchema,
|
|
17
|
+
getAssetById,
|
|
18
|
+
mediaBackendPlugin,
|
|
19
|
+
type MediaBackendHooks,
|
|
20
|
+
} from "../api";
|
|
21
|
+
import type {
|
|
22
|
+
DirectStorageAdapter,
|
|
23
|
+
S3StorageAdapter,
|
|
24
|
+
VercelBlobStorageAdapter,
|
|
25
|
+
} from "../api/storage-adapter";
|
|
26
|
+
import { mediaPermissions } from "../permissions";
|
|
27
|
+
import type { Asset, Folder } from "../types";
|
|
28
|
+
|
|
29
|
+
const memoryAdapter = (db: DatabaseDefinition) => createMemoryAdapter(db)({});
|
|
30
|
+
|
|
31
|
+
function affectedRowResultAdapter(
|
|
32
|
+
shape: (changes: number) => unknown,
|
|
33
|
+
): (db: DatabaseDefinition) => DBAdapter {
|
|
34
|
+
return (db) => {
|
|
35
|
+
const adapter = createMemoryAdapter(db)({});
|
|
36
|
+
const transaction = adapter.transaction.bind(adapter);
|
|
37
|
+
return {
|
|
38
|
+
...adapter,
|
|
39
|
+
transaction: ((callback) =>
|
|
40
|
+
transaction((tx) =>
|
|
41
|
+
callback({
|
|
42
|
+
...tx,
|
|
43
|
+
updateMany: (async (
|
|
44
|
+
input: Parameters<DBAdapter["updateMany"]>[0],
|
|
45
|
+
) =>
|
|
46
|
+
shape(
|
|
47
|
+
(await tx.updateMany(input)) ? 1 : 0,
|
|
48
|
+
)) as unknown as DBAdapter["updateMany"],
|
|
49
|
+
deleteMany: (async (
|
|
50
|
+
input: Parameters<DBAdapter["deleteMany"]>[0],
|
|
51
|
+
) =>
|
|
52
|
+
shape(
|
|
53
|
+
await tx.deleteMany(input),
|
|
54
|
+
)) as unknown as DBAdapter["deleteMany"],
|
|
55
|
+
}),
|
|
56
|
+
)) as DBAdapter["transaction"],
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const d1ResultAdapter = affectedRowResultAdapter((changes) => ({
|
|
62
|
+
meta: { changes },
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
const identitySchema = z.object({
|
|
66
|
+
id: z.string(),
|
|
67
|
+
role: z.enum(["member", "admin"]),
|
|
68
|
+
tenantIds: z.array(z.string()),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const authorization = defineAuthorization({
|
|
72
|
+
identity: identitySchema,
|
|
73
|
+
permissions: [mediaPermissions] as const,
|
|
74
|
+
rules: ({ media }) => {
|
|
75
|
+
const belongsToTenant = ({
|
|
76
|
+
identity,
|
|
77
|
+
facts,
|
|
78
|
+
}: {
|
|
79
|
+
identity: Identity | null;
|
|
80
|
+
facts: { tenantId?: string };
|
|
81
|
+
}) =>
|
|
82
|
+
identity?.role === "admin" ||
|
|
83
|
+
Boolean(
|
|
84
|
+
identity &&
|
|
85
|
+
(!facts.tenantId || identity.tenantIds.includes(facts.tenantId)),
|
|
86
|
+
);
|
|
87
|
+
return [
|
|
88
|
+
media.library.read.when(({ identity }) => identity !== null),
|
|
89
|
+
media.asset.read.when(belongsToTenant),
|
|
90
|
+
media.asset.upload.when(
|
|
91
|
+
({ identity, facts }) =>
|
|
92
|
+
facts.phase === "callback" || belongsToTenant({ identity, facts }),
|
|
93
|
+
),
|
|
94
|
+
media.asset.update.when(belongsToTenant),
|
|
95
|
+
media.asset.delete.when(belongsToTenant),
|
|
96
|
+
media.folder.create.when(belongsToTenant),
|
|
97
|
+
media.folder.delete.when(belongsToTenant),
|
|
98
|
+
];
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
type Identity = {
|
|
103
|
+
id: string;
|
|
104
|
+
role: "member" | "admin";
|
|
105
|
+
tenantIds: string[];
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const tenantMember = {
|
|
109
|
+
id: "member-a",
|
|
110
|
+
role: "member",
|
|
111
|
+
tenantIds: ["tenant-a"],
|
|
112
|
+
} as const satisfies Identity;
|
|
113
|
+
const outsider = {
|
|
114
|
+
id: "member-b",
|
|
115
|
+
role: "member",
|
|
116
|
+
tenantIds: ["tenant-b"],
|
|
117
|
+
} as const satisfies Identity;
|
|
118
|
+
const admin = {
|
|
119
|
+
id: "admin",
|
|
120
|
+
role: "admin",
|
|
121
|
+
tenantIds: [],
|
|
122
|
+
} as const satisfies Identity;
|
|
123
|
+
|
|
124
|
+
function identityFromRequest(request: Request): Identity | null {
|
|
125
|
+
const id = request.headers.get("x-user-id");
|
|
126
|
+
const role = request.headers.get("x-user-role");
|
|
127
|
+
if (!id || (role !== "member" && role !== "admin")) return null;
|
|
128
|
+
return {
|
|
129
|
+
id,
|
|
130
|
+
role,
|
|
131
|
+
tenantIds:
|
|
132
|
+
request.headers.get("x-tenant-ids")?.split(",").filter(Boolean) ?? [],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function createAuth(
|
|
137
|
+
getIdentity: (
|
|
138
|
+
request: Request,
|
|
139
|
+
) => Identity | null | Promise<Identity | null> = identityFromRequest,
|
|
140
|
+
definition = authorization,
|
|
141
|
+
) {
|
|
142
|
+
return createServerAuth({
|
|
143
|
+
authorization: definition,
|
|
144
|
+
getIdentity: ({ request }) => getIdentity(request),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function directStorage(
|
|
149
|
+
overrides: Partial<DirectStorageAdapter> = {},
|
|
150
|
+
): DirectStorageAdapter {
|
|
151
|
+
return {
|
|
152
|
+
type: "local",
|
|
153
|
+
upload: vi.fn(async (_buffer, input) => ({
|
|
154
|
+
url: `https://files.example/${input.filename}`,
|
|
155
|
+
})),
|
|
156
|
+
delete: vi.fn(async () => undefined),
|
|
157
|
+
...overrides,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function s3Storage(
|
|
162
|
+
overrides: Partial<S3StorageAdapter> = {},
|
|
163
|
+
): S3StorageAdapter {
|
|
164
|
+
return {
|
|
165
|
+
type: "s3",
|
|
166
|
+
urlPrefix: "https://files.example",
|
|
167
|
+
generateUploadToken: vi.fn(async (input) => ({
|
|
168
|
+
type: "presigned-url" as const,
|
|
169
|
+
payload: {
|
|
170
|
+
uploadUrl: "https://storage.example/signed-secret",
|
|
171
|
+
publicUrl: `https://files.example/${input.filename}`,
|
|
172
|
+
key: input.filename,
|
|
173
|
+
method: "PUT" as const,
|
|
174
|
+
headers: { "content-type": input.mimeType },
|
|
175
|
+
},
|
|
176
|
+
})),
|
|
177
|
+
delete: vi.fn(async () => undefined),
|
|
178
|
+
...overrides,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function vercelStorage(
|
|
183
|
+
overrides: Partial<VercelBlobStorageAdapter> = {},
|
|
184
|
+
): VercelBlobStorageAdapter {
|
|
185
|
+
return {
|
|
186
|
+
type: "vercel-blob",
|
|
187
|
+
urlHostnameSuffix: ".public.blob.vercel-storage.com",
|
|
188
|
+
verifyCallback: vi.fn(async (request, body) => {
|
|
189
|
+
if (request.headers.get("x-vercel-signature") !== "valid") {
|
|
190
|
+
throw new Error("Invalid provider signature");
|
|
191
|
+
}
|
|
192
|
+
const context = JSON.parse(body.payload.tokenPayload ?? "null") as {
|
|
193
|
+
pathname?: string;
|
|
194
|
+
mimeType?: string;
|
|
195
|
+
folderId?: string;
|
|
196
|
+
tenantId?: string;
|
|
197
|
+
};
|
|
198
|
+
if (!context.pathname || !context.mimeType) {
|
|
199
|
+
throw new Error("Invalid server-issued upload context");
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
pathname: context.pathname,
|
|
203
|
+
mimeType: context.mimeType,
|
|
204
|
+
...(context.folderId ? { folderId: context.folderId } : {}),
|
|
205
|
+
...(context.tenantId ? { tenantId: context.tenantId } : {}),
|
|
206
|
+
};
|
|
207
|
+
}),
|
|
208
|
+
handleRequest: vi.fn(async (_request, body, callbacks) => {
|
|
209
|
+
if (body.type === "blob.generate-client-token") {
|
|
210
|
+
return {
|
|
211
|
+
type: body.type,
|
|
212
|
+
tokenOptions: await callbacks.onBeforeGenerateToken?.(
|
|
213
|
+
body.payload.pathname,
|
|
214
|
+
body.payload.clientPayload,
|
|
215
|
+
),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return { type: body.type, response: "ok" };
|
|
219
|
+
}),
|
|
220
|
+
delete: vi.fn(async () => undefined),
|
|
221
|
+
...overrides,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function makeBackend(
|
|
226
|
+
options: {
|
|
227
|
+
storage?:
|
|
228
|
+
| DirectStorageAdapter
|
|
229
|
+
| S3StorageAdapter
|
|
230
|
+
| VercelBlobStorageAdapter;
|
|
231
|
+
hooks?: MediaBackendHooks;
|
|
232
|
+
auth?: ServerAuth<any>;
|
|
233
|
+
adapter?: (db: DatabaseDefinition) => DBAdapter;
|
|
234
|
+
tenantId?: string;
|
|
235
|
+
} = {},
|
|
236
|
+
) {
|
|
237
|
+
return createBackendStack({
|
|
238
|
+
basePath: "/api",
|
|
239
|
+
plugins: {
|
|
240
|
+
media: mediaBackendPlugin({
|
|
241
|
+
storageAdapter: options.storage ?? directStorage(),
|
|
242
|
+
allowedUrlPrefixes: ["https://files.example/"],
|
|
243
|
+
hooks: options.hooks,
|
|
244
|
+
resolveTenantId: () => options.tenantId,
|
|
245
|
+
}),
|
|
246
|
+
},
|
|
247
|
+
adapter: options.adapter ?? memoryAdapter,
|
|
248
|
+
...(options.auth ? { auth: options.auth as never } : {}),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function request(
|
|
253
|
+
path: string,
|
|
254
|
+
options: { method?: string; identity?: Identity; body?: unknown } = {},
|
|
255
|
+
) {
|
|
256
|
+
const headers = new Headers();
|
|
257
|
+
if (options.identity) {
|
|
258
|
+
headers.set("x-user-id", options.identity.id);
|
|
259
|
+
headers.set("x-user-role", options.identity.role);
|
|
260
|
+
headers.set("x-tenant-ids", options.identity.tenantIds.join(","));
|
|
261
|
+
}
|
|
262
|
+
if (options.body !== undefined)
|
|
263
|
+
headers.set("content-type", "application/json");
|
|
264
|
+
return new Request(`http://localhost/api${path}`, {
|
|
265
|
+
method: options.method ?? "GET",
|
|
266
|
+
headers,
|
|
267
|
+
...(options.body !== undefined
|
|
268
|
+
? { body: JSON.stringify(options.body) }
|
|
269
|
+
: {}),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function uploadRequest(identity?: Identity) {
|
|
274
|
+
const body = new FormData();
|
|
275
|
+
body.set("file", new File(["photo"], "photo.jpg", { type: "image/jpeg" }));
|
|
276
|
+
const headers = new Headers();
|
|
277
|
+
if (identity) {
|
|
278
|
+
headers.set("x-user-id", identity.id);
|
|
279
|
+
headers.set("x-user-role", identity.role);
|
|
280
|
+
headers.set("x-tenant-ids", identity.tenantIds.join(","));
|
|
281
|
+
}
|
|
282
|
+
return new Request("http://localhost/api/media/upload", {
|
|
283
|
+
method: "POST",
|
|
284
|
+
headers,
|
|
285
|
+
body,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function seedFolder(
|
|
290
|
+
backend: ReturnType<typeof makeBackend>,
|
|
291
|
+
overrides: Partial<Folder> = {},
|
|
292
|
+
) {
|
|
293
|
+
const now = new Date("2026-01-01T00:00:00.000Z");
|
|
294
|
+
return backend.adapter.create<Folder>({
|
|
295
|
+
model: "mediaFolder",
|
|
296
|
+
data: {
|
|
297
|
+
name: "Photos",
|
|
298
|
+
tenantId: "tenant-a",
|
|
299
|
+
createdAt: now,
|
|
300
|
+
updatedAt: now,
|
|
301
|
+
...overrides,
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async function seedAsset(
|
|
307
|
+
backend: ReturnType<typeof makeBackend>,
|
|
308
|
+
overrides: Partial<Asset> = {},
|
|
309
|
+
) {
|
|
310
|
+
const now = new Date("2026-01-01T00:00:00.000Z");
|
|
311
|
+
return backend.adapter.create<Asset>({
|
|
312
|
+
model: "mediaAsset",
|
|
313
|
+
data: {
|
|
314
|
+
filename: "photo.jpg",
|
|
315
|
+
originalName: "Photo.jpg",
|
|
316
|
+
mimeType: "image/jpeg",
|
|
317
|
+
size: 5,
|
|
318
|
+
url: "https://files.example/photo.jpg",
|
|
319
|
+
tenantId: "tenant-a",
|
|
320
|
+
createdAt: now,
|
|
321
|
+
updatedAt: now,
|
|
322
|
+
...overrides,
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
describe("Media authorization inventory", () => {
|
|
328
|
+
it("records public hook migrations without renaming storage callbacks", () => {
|
|
329
|
+
expect(MEDIA_LIFECYCLE_HOOK_MIGRATIONS).toEqual({
|
|
330
|
+
onBeforeDelete: "onBeforeDeleteAsset",
|
|
331
|
+
onAfterDelete: "onAfterDeleteAsset",
|
|
332
|
+
onOperationError: "onError",
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("covers every maintained transport behavior with runtime-schema-backed descriptors", () => {
|
|
337
|
+
const plugin = mediaBackendPlugin({ storageAdapter: directStorage() });
|
|
338
|
+
const adapter = createMemoryAdapter(defineDb({}).use(plugin.dbPlugin))({});
|
|
339
|
+
const operations = plugin.operations?.(adapter);
|
|
340
|
+
expect(Object.keys(operations ?? {}).sort()).toEqual([
|
|
341
|
+
"createAsset",
|
|
342
|
+
"createFolder",
|
|
343
|
+
"deleteAsset",
|
|
344
|
+
"deleteFolder",
|
|
345
|
+
"listAssets",
|
|
346
|
+
"listFolders",
|
|
347
|
+
"updateAsset",
|
|
348
|
+
"uploadDirect",
|
|
349
|
+
"uploadToken",
|
|
350
|
+
"uploadVercelBlob",
|
|
351
|
+
]);
|
|
352
|
+
expect(
|
|
353
|
+
Object.fromEntries(
|
|
354
|
+
Object.entries(operations ?? {}).map(([key, operation]) => [
|
|
355
|
+
key,
|
|
356
|
+
operation.permission.id,
|
|
357
|
+
]),
|
|
358
|
+
),
|
|
359
|
+
).toEqual({
|
|
360
|
+
listAssets: "media:library.read",
|
|
361
|
+
createAsset: "media:asset.upload",
|
|
362
|
+
updateAsset: "media:asset.update",
|
|
363
|
+
deleteAsset: "media:asset.delete",
|
|
364
|
+
listFolders: "media:library.read",
|
|
365
|
+
createFolder: "media:folder.create",
|
|
366
|
+
deleteFolder: "media:folder.delete",
|
|
367
|
+
uploadDirect: "media:asset.upload",
|
|
368
|
+
uploadToken: "media:asset.upload",
|
|
369
|
+
uploadVercelBlob: "media:asset.upload",
|
|
370
|
+
});
|
|
371
|
+
expect(mediaPermissions.library.read()).toMatchObject({
|
|
372
|
+
id: "media:library.read",
|
|
373
|
+
});
|
|
374
|
+
expect(
|
|
375
|
+
mediaPermissions.asset.delete({
|
|
376
|
+
assetId: "asset-1",
|
|
377
|
+
mimeType: "image/png",
|
|
378
|
+
}),
|
|
379
|
+
).toMatchObject({ id: "media:asset.delete" });
|
|
380
|
+
expect(() =>
|
|
381
|
+
mediaPermissions.asset.delete({
|
|
382
|
+
assetId: "asset-1",
|
|
383
|
+
// @ts-expect-error MIME type is a required asset fact.
|
|
384
|
+
mimeType: undefined,
|
|
385
|
+
}),
|
|
386
|
+
).toThrow();
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
describe("Media operation-first authorization", () => {
|
|
391
|
+
it("runs canonical asset-delete hooks across request and trusted calls", async () => {
|
|
392
|
+
const events: string[] = [];
|
|
393
|
+
const storage = directStorage();
|
|
394
|
+
const backend = makeBackend({
|
|
395
|
+
auth: createAuth(),
|
|
396
|
+
storage,
|
|
397
|
+
tenantId: "tenant-a",
|
|
398
|
+
hooks: {
|
|
399
|
+
onBeforeDeleteAsset: (asset, context) => {
|
|
400
|
+
events.push(
|
|
401
|
+
`before:${asset.filename}:${context.identity?.id ?? "trusted"}`,
|
|
402
|
+
);
|
|
403
|
+
if (asset.filename === "rejected.jpg") {
|
|
404
|
+
throw new Error("retention policy rejected deletion");
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
onAfterDeleteAsset: (_assetId, context) => {
|
|
408
|
+
events.push(`after:${context.identity?.id}`);
|
|
409
|
+
},
|
|
410
|
+
onError: (_error, context) => {
|
|
411
|
+
events.push(`error:${context.identity?.id ?? "trusted"}`);
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
const requestedAsset = await seedAsset(backend);
|
|
416
|
+
const rejectedAsset = await seedAsset(backend, {
|
|
417
|
+
filename: "rejected.jpg",
|
|
418
|
+
originalName: "Rejected.jpg",
|
|
419
|
+
url: "https://files.example/rejected.jpg",
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
await backend
|
|
423
|
+
.forRequest(request("/delete", { identity: tenantMember }))
|
|
424
|
+
.operations.media.deleteAsset({ id: requestedAsset.id });
|
|
425
|
+
await expect(
|
|
426
|
+
backend.trusted.media.deleteAsset({ id: rejectedAsset.id }),
|
|
427
|
+
).rejects.toMatchObject({
|
|
428
|
+
code: "DELETE_ASSET_REJECTED",
|
|
429
|
+
message: "retention policy rejected deletion",
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
expect(events).toEqual([
|
|
433
|
+
`before:photo.jpg:${tenantMember.id}`,
|
|
434
|
+
`after:${tenantMember.id}`,
|
|
435
|
+
"before:rejected.jpg:trusted",
|
|
436
|
+
"error:trusted",
|
|
437
|
+
]);
|
|
438
|
+
expect(storage.delete).toHaveBeenCalledTimes(1);
|
|
439
|
+
await expect(
|
|
440
|
+
getAssetById(backend.adapter, rejectedAsset.id),
|
|
441
|
+
).resolves.toMatchObject({ filename: "rejected.jpg" });
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it("preserves omitted-auth compatibility while retaining validation and hooks", async () => {
|
|
445
|
+
const events: string[] = [];
|
|
446
|
+
const backend = makeBackend({
|
|
447
|
+
tenantId: "tenant-a",
|
|
448
|
+
hooks: {
|
|
449
|
+
onBeforeCreateFolder: (_input, context) => {
|
|
450
|
+
events.push(`before:${context.identity?.id ?? "anonymous"}`);
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
const response = await backend.handler(
|
|
455
|
+
request("/media/folders", {
|
|
456
|
+
method: "POST",
|
|
457
|
+
body: { name: "Compatible" },
|
|
458
|
+
}),
|
|
459
|
+
);
|
|
460
|
+
expect(response.status).toBe(200);
|
|
461
|
+
expect(await response.json()).toMatchObject({ name: "Compatible" });
|
|
462
|
+
expect(events).toEqual(["before:anonymous"]);
|
|
463
|
+
await expect(
|
|
464
|
+
backend.trusted.media.createFolder({ name: "" }),
|
|
465
|
+
).rejects.toBeInstanceOf(z.ZodError);
|
|
466
|
+
expect(events).toHaveLength(1);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it("returns 401/403 before hooks and derives tenant, folder, and asset facts on the server", async () => {
|
|
470
|
+
const facts: unknown[] = [];
|
|
471
|
+
const beforeDelete = vi.fn();
|
|
472
|
+
const backend = makeBackend({
|
|
473
|
+
auth: createAuth(),
|
|
474
|
+
tenantId: "tenant-a",
|
|
475
|
+
hooks: { onBeforeDeleteAsset: beforeDelete },
|
|
476
|
+
});
|
|
477
|
+
const folder = await seedFolder(backend);
|
|
478
|
+
const asset = await seedAsset(backend, { folderId: folder.id });
|
|
479
|
+
|
|
480
|
+
expect(
|
|
481
|
+
authorization.can(
|
|
482
|
+
mediaPermissions.asset.delete({
|
|
483
|
+
assetId: asset.id,
|
|
484
|
+
folderId: folder.id,
|
|
485
|
+
mimeType: asset.mimeType,
|
|
486
|
+
tenantId: "tenant-b",
|
|
487
|
+
}),
|
|
488
|
+
outsider,
|
|
489
|
+
),
|
|
490
|
+
).toBe(true);
|
|
491
|
+
expect(
|
|
492
|
+
(
|
|
493
|
+
await backend.handler(
|
|
494
|
+
request(`/media/assets/${asset.id}`, { method: "DELETE" }),
|
|
495
|
+
)
|
|
496
|
+
).status,
|
|
497
|
+
).toBe(401);
|
|
498
|
+
expect(
|
|
499
|
+
(
|
|
500
|
+
await backend.handler(
|
|
501
|
+
request(`/media/assets/${asset.id}`, {
|
|
502
|
+
method: "DELETE",
|
|
503
|
+
identity: outsider,
|
|
504
|
+
}),
|
|
505
|
+
)
|
|
506
|
+
).status,
|
|
507
|
+
).toBe(403);
|
|
508
|
+
expect(beforeDelete).not.toHaveBeenCalled();
|
|
509
|
+
|
|
510
|
+
const captureAuthorization = defineAuthorization({
|
|
511
|
+
identity: identitySchema,
|
|
512
|
+
permissions: [mediaPermissions] as const,
|
|
513
|
+
rules: ({ media }) => [
|
|
514
|
+
media.asset.update.when(({ facts: trustedFacts }) => {
|
|
515
|
+
facts.push(trustedFacts);
|
|
516
|
+
return true;
|
|
517
|
+
}),
|
|
518
|
+
],
|
|
519
|
+
});
|
|
520
|
+
const captureAuth = createAuth(
|
|
521
|
+
async () => tenantMember,
|
|
522
|
+
captureAuthorization,
|
|
523
|
+
);
|
|
524
|
+
const captured = makeBackend({
|
|
525
|
+
auth: captureAuth,
|
|
526
|
+
tenantId: "tenant-a",
|
|
527
|
+
});
|
|
528
|
+
const capturedFolder = await seedFolder(captured);
|
|
529
|
+
const capturedAsset = await seedAsset(captured, {
|
|
530
|
+
folderId: capturedFolder.id,
|
|
531
|
+
});
|
|
532
|
+
await captured
|
|
533
|
+
.forRequest(request("/authorized"))
|
|
534
|
+
.operations.media.updateAsset({
|
|
535
|
+
id: capturedAsset.id,
|
|
536
|
+
data: { alt: "Trusted" },
|
|
537
|
+
});
|
|
538
|
+
expect(facts).toContainEqual(
|
|
539
|
+
expect.objectContaining({
|
|
540
|
+
assetId: capturedAsset.id,
|
|
541
|
+
folderId: capturedFolder.id,
|
|
542
|
+
mimeType: "image/jpeg",
|
|
543
|
+
tenantId: "tenant-a",
|
|
544
|
+
}),
|
|
545
|
+
);
|
|
546
|
+
await expect(
|
|
547
|
+
backend
|
|
548
|
+
.forRequest(request("/member", { identity: tenantMember }))
|
|
549
|
+
.operations.media.updateAsset({
|
|
550
|
+
id: asset.id,
|
|
551
|
+
data: { alt: "Allowed" },
|
|
552
|
+
}),
|
|
553
|
+
).resolves.toMatchObject({ alt: "Allowed" });
|
|
554
|
+
const adminBackend = makeBackend({
|
|
555
|
+
auth: createAuth(),
|
|
556
|
+
tenantId: "tenant-a",
|
|
557
|
+
});
|
|
558
|
+
const adminAsset = await seedAsset(adminBackend);
|
|
559
|
+
await expect(
|
|
560
|
+
adminBackend
|
|
561
|
+
.forRequest(request("/admin", { identity: admin }))
|
|
562
|
+
.operations.media.deleteAsset({ id: adminAsset.id }),
|
|
563
|
+
).resolves.toEqual({ success: true });
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("distinguishes metadata updates from an explicit move to the root folder", async () => {
|
|
567
|
+
const metadataOnlyAuthorization = defineAuthorization({
|
|
568
|
+
identity: identitySchema,
|
|
569
|
+
permissions: [mediaPermissions] as const,
|
|
570
|
+
rules: ({ media }) => [
|
|
571
|
+
media.asset.update.when(
|
|
572
|
+
({ identity, facts }) =>
|
|
573
|
+
identity !== null && facts.targetFolderId === undefined,
|
|
574
|
+
),
|
|
575
|
+
],
|
|
576
|
+
});
|
|
577
|
+
const backend = makeBackend({
|
|
578
|
+
auth: createAuth(identityFromRequest, metadataOnlyAuthorization),
|
|
579
|
+
tenantId: "tenant-a",
|
|
580
|
+
});
|
|
581
|
+
const folder = await seedFolder(backend);
|
|
582
|
+
const asset = await seedAsset(backend, { folderId: folder.id });
|
|
583
|
+
const api = backend.forRequest(
|
|
584
|
+
request("/metadata-only", { identity: tenantMember }),
|
|
585
|
+
).operations.media;
|
|
586
|
+
|
|
587
|
+
await expect(
|
|
588
|
+
api.updateAsset({ id: asset.id, data: { alt: "Allowed" } }),
|
|
589
|
+
).resolves.toMatchObject({ alt: "Allowed", folderId: folder.id });
|
|
590
|
+
await expect(
|
|
591
|
+
api.updateAsset({ id: asset.id, data: { folderId: null } }),
|
|
592
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
593
|
+
await expect(
|
|
594
|
+
api.updateAsset({ id: asset.id, data: { folderId: undefined } }),
|
|
595
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
596
|
+
await expect(
|
|
597
|
+
getAssetById(backend.adapter, asset.id),
|
|
598
|
+
).resolves.toMatchObject({
|
|
599
|
+
folderId: folder.id,
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it("fails closed across the maintained anonymous HTTP inventory", async () => {
|
|
604
|
+
const direct = makeBackend({ auth: createAuth(), tenantId: "tenant-a" });
|
|
605
|
+
const folder = await seedFolder(direct);
|
|
606
|
+
const asset = await seedAsset(direct, { folderId: folder.id });
|
|
607
|
+
const directRequests = [
|
|
608
|
+
request("/media/assets"),
|
|
609
|
+
request("/media/assets", {
|
|
610
|
+
method: "POST",
|
|
611
|
+
body: {
|
|
612
|
+
filename: "new.jpg",
|
|
613
|
+
originalName: "new.jpg",
|
|
614
|
+
mimeType: "image/jpeg",
|
|
615
|
+
size: 5,
|
|
616
|
+
url: "https://files.example/new.jpg",
|
|
617
|
+
},
|
|
618
|
+
}),
|
|
619
|
+
request(`/media/assets/${asset.id}`, {
|
|
620
|
+
method: "PATCH",
|
|
621
|
+
body: { alt: "Denied" },
|
|
622
|
+
}),
|
|
623
|
+
request(`/media/assets/${asset.id}`, { method: "DELETE" }),
|
|
624
|
+
request("/media/folders"),
|
|
625
|
+
request("/media/folders", {
|
|
626
|
+
method: "POST",
|
|
627
|
+
body: { name: "Denied" },
|
|
628
|
+
}),
|
|
629
|
+
request(`/media/folders/${folder.id}`, { method: "DELETE" }),
|
|
630
|
+
uploadRequest(),
|
|
631
|
+
];
|
|
632
|
+
for (const protectedRequest of directRequests) {
|
|
633
|
+
expect((await direct.handler(protectedRequest)).status).toBe(401);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const s3 = makeBackend({
|
|
637
|
+
auth: createAuth(),
|
|
638
|
+
storage: s3Storage(),
|
|
639
|
+
tenantId: "tenant-a",
|
|
640
|
+
});
|
|
641
|
+
expect(
|
|
642
|
+
(
|
|
643
|
+
await s3.handler(
|
|
644
|
+
request("/media/upload/token", {
|
|
645
|
+
method: "POST",
|
|
646
|
+
body: {
|
|
647
|
+
filename: "secret.jpg",
|
|
648
|
+
mimeType: "image/jpeg",
|
|
649
|
+
size: 5,
|
|
650
|
+
},
|
|
651
|
+
}),
|
|
652
|
+
)
|
|
653
|
+
).status,
|
|
654
|
+
).toBe(401);
|
|
655
|
+
|
|
656
|
+
const blob = makeBackend({
|
|
657
|
+
auth: createAuth(),
|
|
658
|
+
storage: vercelStorage(),
|
|
659
|
+
tenantId: "tenant-a",
|
|
660
|
+
});
|
|
661
|
+
expect(
|
|
662
|
+
(
|
|
663
|
+
await blob.handler(
|
|
664
|
+
request("/media/upload/vercel-blob", {
|
|
665
|
+
method: "POST",
|
|
666
|
+
body: {
|
|
667
|
+
type: "blob.generate-client-token",
|
|
668
|
+
payload: {
|
|
669
|
+
pathname: "secret.jpg",
|
|
670
|
+
multipart: false,
|
|
671
|
+
clientPayload: JSON.stringify({ mimeType: "image/jpeg" }),
|
|
672
|
+
},
|
|
673
|
+
},
|
|
674
|
+
}),
|
|
675
|
+
)
|
|
676
|
+
).status,
|
|
677
|
+
).toBe(401);
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
it("keeps HTTP, forRequest, and trusted on one validated lifecycle", async () => {
|
|
681
|
+
const events: string[] = [];
|
|
682
|
+
const getIdentity = vi.fn(() => tenantMember);
|
|
683
|
+
const backend = makeBackend({
|
|
684
|
+
auth: createAuth(getIdentity),
|
|
685
|
+
tenantId: "tenant-a",
|
|
686
|
+
hooks: {
|
|
687
|
+
onBeforeCreateFolder: (_input, context) => {
|
|
688
|
+
events.push(context.identity?.id ?? "trusted");
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
});
|
|
692
|
+
expect(
|
|
693
|
+
(
|
|
694
|
+
await backend.handler(
|
|
695
|
+
request("/media/folders", {
|
|
696
|
+
method: "POST",
|
|
697
|
+
identity: tenantMember,
|
|
698
|
+
body: { name: "HTTP" },
|
|
699
|
+
}),
|
|
700
|
+
)
|
|
701
|
+
).status,
|
|
702
|
+
).toBe(200);
|
|
703
|
+
await backend
|
|
704
|
+
.forRequest(request("/request", { identity: tenantMember }))
|
|
705
|
+
.operations.media.createFolder({ name: "Request" });
|
|
706
|
+
await backend.trusted.media.createFolder({ name: "Trusted" });
|
|
707
|
+
await expect(
|
|
708
|
+
backend.trusted.media.createFolder({ name: "" }),
|
|
709
|
+
).rejects.toBeInstanceOf(z.ZodError);
|
|
710
|
+
expect(events).toEqual([tenantMember.id, tenantMember.id, "trusted"]);
|
|
711
|
+
expect(getIdentity).toHaveBeenCalledTimes(2);
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
it("inherits authoritative folder tenants for trusted writes and rejects cross-tenant moves", async () => {
|
|
715
|
+
const uploadFacts: unknown[] = [];
|
|
716
|
+
const backend = makeBackend({
|
|
717
|
+
tenantId: "tenant-a",
|
|
718
|
+
hooks: {
|
|
719
|
+
onBeforeUpload: (_input, context) => {
|
|
720
|
+
uploadFacts.push(context.facts);
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
});
|
|
724
|
+
const parent = await seedFolder(backend, { name: "Tenant A parent" });
|
|
725
|
+
const child = await backend.trusted.media.createFolder({
|
|
726
|
+
name: "Trusted child",
|
|
727
|
+
parentId: parent.id,
|
|
728
|
+
});
|
|
729
|
+
const finalized = await backend.trusted.media.createAsset({
|
|
730
|
+
filename: "finalized.jpg",
|
|
731
|
+
originalName: "finalized.jpg",
|
|
732
|
+
mimeType: "image/jpeg",
|
|
733
|
+
size: 5,
|
|
734
|
+
url: "https://files.example/finalized.jpg",
|
|
735
|
+
folderId: child.id,
|
|
736
|
+
});
|
|
737
|
+
const direct = await backend.trusted.media.uploadDirect({
|
|
738
|
+
filename: "direct.jpg",
|
|
739
|
+
mimeType: "image/jpeg",
|
|
740
|
+
size: 5,
|
|
741
|
+
contentBase64: Buffer.from("photo").toString("base64"),
|
|
742
|
+
folderId: child.id,
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
expect(
|
|
746
|
+
await backend.adapter.findOne<Folder>({
|
|
747
|
+
model: "mediaFolder",
|
|
748
|
+
where: [{ field: "id", value: child.id }],
|
|
749
|
+
}),
|
|
750
|
+
).toMatchObject({ tenantId: "tenant-a" });
|
|
751
|
+
for (const assetId of [finalized.id, direct.id]) {
|
|
752
|
+
expect(
|
|
753
|
+
await backend.adapter.findOne<Asset>({
|
|
754
|
+
model: "mediaAsset",
|
|
755
|
+
where: [{ field: "id", value: assetId }],
|
|
756
|
+
}),
|
|
757
|
+
).toMatchObject({ folderId: child.id, tenantId: "tenant-a" });
|
|
758
|
+
}
|
|
759
|
+
expect(uploadFacts).toEqual([
|
|
760
|
+
expect.objectContaining({ tenantId: "tenant-a" }),
|
|
761
|
+
expect.objectContaining({ tenantId: "tenant-a" }),
|
|
762
|
+
]);
|
|
763
|
+
|
|
764
|
+
const foreign = await seedFolder(backend, {
|
|
765
|
+
name: "Tenant B",
|
|
766
|
+
tenantId: "tenant-b",
|
|
767
|
+
});
|
|
768
|
+
await expect(
|
|
769
|
+
backend.trusted.media.updateAsset({
|
|
770
|
+
id: finalized.id,
|
|
771
|
+
data: { folderId: foreign.id },
|
|
772
|
+
}),
|
|
773
|
+
).rejects.toMatchObject({ statusCode: 404, code: "FOLDER_NOT_FOUND" });
|
|
774
|
+
expect(
|
|
775
|
+
await backend.adapter.findOne<Asset>({
|
|
776
|
+
model: "mediaAsset",
|
|
777
|
+
where: [{ field: "id", value: finalized.id }],
|
|
778
|
+
}),
|
|
779
|
+
).toMatchObject({ folderId: child.id, tenantId: "tenant-a" });
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
it("binds authoritative folder tenants into unscoped upload initialization", async () => {
|
|
783
|
+
const s3Facts: unknown[] = [];
|
|
784
|
+
const s3Backend = makeBackend({
|
|
785
|
+
storage: s3Storage(),
|
|
786
|
+
hooks: {
|
|
787
|
+
onBeforeUpload: (_input, context) => {
|
|
788
|
+
s3Facts.push(context.facts);
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
});
|
|
792
|
+
const s3Folder = await seedFolder(s3Backend, { name: "S3 tenant folder" });
|
|
793
|
+
await expect(
|
|
794
|
+
s3Backend
|
|
795
|
+
.forRequest(request("/unscoped-s3"))
|
|
796
|
+
.operations.media.uploadToken({
|
|
797
|
+
filename: "token.jpg",
|
|
798
|
+
mimeType: "image/jpeg",
|
|
799
|
+
size: 5,
|
|
800
|
+
folderId: s3Folder.id,
|
|
801
|
+
}),
|
|
802
|
+
).resolves.toMatchObject({ type: "presigned-url" });
|
|
803
|
+
expect(s3Facts).toEqual([
|
|
804
|
+
expect.objectContaining({
|
|
805
|
+
phase: "initialize",
|
|
806
|
+
folderId: s3Folder.id,
|
|
807
|
+
tenantId: "tenant-a",
|
|
808
|
+
}),
|
|
809
|
+
]);
|
|
810
|
+
|
|
811
|
+
const blobFacts: unknown[] = [];
|
|
812
|
+
const blobBackend = makeBackend({
|
|
813
|
+
storage: vercelStorage(),
|
|
814
|
+
hooks: {
|
|
815
|
+
onBeforeUpload: (_input, context) => {
|
|
816
|
+
blobFacts.push(context.facts);
|
|
817
|
+
},
|
|
818
|
+
},
|
|
819
|
+
});
|
|
820
|
+
const blobFolder = await seedFolder(blobBackend, {
|
|
821
|
+
name: "Blob tenant folder",
|
|
822
|
+
});
|
|
823
|
+
const response = await blobBackend.handler(
|
|
824
|
+
request("/media/upload/vercel-blob", {
|
|
825
|
+
method: "POST",
|
|
826
|
+
body: {
|
|
827
|
+
type: "blob.generate-client-token",
|
|
828
|
+
payload: {
|
|
829
|
+
pathname: "blob.jpg",
|
|
830
|
+
multipart: false,
|
|
831
|
+
clientPayload: JSON.stringify({
|
|
832
|
+
mimeType: "image/jpeg",
|
|
833
|
+
folderId: blobFolder.id,
|
|
834
|
+
}),
|
|
835
|
+
},
|
|
836
|
+
},
|
|
837
|
+
}),
|
|
838
|
+
);
|
|
839
|
+
expect(response.status).toBe(200);
|
|
840
|
+
const body = (await response.json()) as {
|
|
841
|
+
tokenOptions: { tokenPayload: string };
|
|
842
|
+
};
|
|
843
|
+
expect(JSON.parse(body.tokenOptions.tokenPayload)).toEqual({
|
|
844
|
+
version: 1,
|
|
845
|
+
pathname: "blob.jpg",
|
|
846
|
+
mimeType: "image/jpeg",
|
|
847
|
+
folderId: blobFolder.id,
|
|
848
|
+
tenantId: "tenant-a",
|
|
849
|
+
});
|
|
850
|
+
expect(blobFacts).toEqual([
|
|
851
|
+
expect.objectContaining({
|
|
852
|
+
phase: "initialize",
|
|
853
|
+
folderId: blobFolder.id,
|
|
854
|
+
tenantId: "tenant-a",
|
|
855
|
+
}),
|
|
856
|
+
]);
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
it("preserves missing-rule, rule, identity, and fact failures before hooks", async () => {
|
|
860
|
+
const before = vi.fn();
|
|
861
|
+
const missing = defineAuthorization({
|
|
862
|
+
identity: identitySchema,
|
|
863
|
+
permissions: [mediaPermissions] as const,
|
|
864
|
+
rules: ({ media }) => [media.library.read.allow()],
|
|
865
|
+
});
|
|
866
|
+
const missingBackend = makeBackend({
|
|
867
|
+
auth: createAuth(identityFromRequest, missing),
|
|
868
|
+
tenantId: "tenant-a",
|
|
869
|
+
hooks: { onBeforeUpdateAsset: before },
|
|
870
|
+
});
|
|
871
|
+
const missingAsset = await seedAsset(missingBackend);
|
|
872
|
+
await expect(
|
|
873
|
+
missingBackend
|
|
874
|
+
.forRequest(request("/missing", { identity: tenantMember }))
|
|
875
|
+
.operations.media.updateAsset({
|
|
876
|
+
id: missingAsset.id,
|
|
877
|
+
data: { alt: "Denied" },
|
|
878
|
+
}),
|
|
879
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
880
|
+
|
|
881
|
+
const identityBackend = makeBackend({
|
|
882
|
+
auth: createAuth(() => {
|
|
883
|
+
throw new Error("session unavailable");
|
|
884
|
+
}),
|
|
885
|
+
tenantId: "tenant-a",
|
|
886
|
+
hooks: { onBeforeUpdateAsset: before },
|
|
887
|
+
});
|
|
888
|
+
const identityAsset = await seedAsset(identityBackend);
|
|
889
|
+
await expect(
|
|
890
|
+
identityBackend
|
|
891
|
+
.forRequest(request("/identity"))
|
|
892
|
+
.operations.media.updateAsset({
|
|
893
|
+
id: identityAsset.id,
|
|
894
|
+
data: { alt: "Denied" },
|
|
895
|
+
}),
|
|
896
|
+
).rejects.toThrow("session unavailable");
|
|
897
|
+
|
|
898
|
+
const failingRule = defineAuthorization({
|
|
899
|
+
identity: identitySchema,
|
|
900
|
+
permissions: [mediaPermissions] as const,
|
|
901
|
+
rules: ({ media }) => [
|
|
902
|
+
media.asset.update.when(() => {
|
|
903
|
+
throw new Error("policy unavailable");
|
|
904
|
+
}),
|
|
905
|
+
],
|
|
906
|
+
});
|
|
907
|
+
const ruleBackend = makeBackend({
|
|
908
|
+
auth: createAuth(identityFromRequest, failingRule),
|
|
909
|
+
tenantId: "tenant-a",
|
|
910
|
+
hooks: { onBeforeUpdateAsset: before },
|
|
911
|
+
});
|
|
912
|
+
const ruleAsset = await seedAsset(ruleBackend);
|
|
913
|
+
await expect(
|
|
914
|
+
ruleBackend
|
|
915
|
+
.forRequest(request("/rule", { identity: tenantMember }))
|
|
916
|
+
.operations.media.updateAsset({
|
|
917
|
+
id: ruleAsset.id,
|
|
918
|
+
data: { alt: "Denied" },
|
|
919
|
+
}),
|
|
920
|
+
).rejects.toThrow("policy unavailable");
|
|
921
|
+
|
|
922
|
+
const factBackend = makeBackend({
|
|
923
|
+
auth: createAuth(),
|
|
924
|
+
tenantId: "tenant-a",
|
|
925
|
+
hooks: { onBeforeUpdateAsset: before },
|
|
926
|
+
});
|
|
927
|
+
const factAsset = await seedAsset(factBackend);
|
|
928
|
+
vi.spyOn(factBackend.adapter, "findOne").mockRejectedValueOnce(
|
|
929
|
+
new Error("database unavailable"),
|
|
930
|
+
);
|
|
931
|
+
await expect(
|
|
932
|
+
factBackend
|
|
933
|
+
.forRequest(request("/facts", { identity: tenantMember }))
|
|
934
|
+
.operations.media.updateAsset({
|
|
935
|
+
id: factAsset.id,
|
|
936
|
+
data: { alt: "Denied" },
|
|
937
|
+
}),
|
|
938
|
+
).rejects.toThrow("database unavailable");
|
|
939
|
+
expect(before).not.toHaveBeenCalled();
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
it("rejects stale and competing asset facts before hooks while preserving the winner", async () => {
|
|
943
|
+
const events: string[] = [];
|
|
944
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
945
|
+
let raced = false;
|
|
946
|
+
backend = makeBackend({
|
|
947
|
+
tenantId: "tenant-a",
|
|
948
|
+
auth: createAuth(async () => {
|
|
949
|
+
if (!raced) {
|
|
950
|
+
raced = true;
|
|
951
|
+
const current = await backend.adapter.findOne<Asset>({
|
|
952
|
+
model: "mediaAsset",
|
|
953
|
+
where: [{ field: "filename", value: "race.jpg" }],
|
|
954
|
+
});
|
|
955
|
+
if (current) {
|
|
956
|
+
await backend.adapter.update<Asset>({
|
|
957
|
+
model: "mediaAsset",
|
|
958
|
+
where: [{ field: "id", value: current.id }],
|
|
959
|
+
update: {
|
|
960
|
+
alt: "Winner",
|
|
961
|
+
updatedAt: new Date("2026-02-01T00:00:00.000Z"),
|
|
962
|
+
},
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return tenantMember;
|
|
967
|
+
}),
|
|
968
|
+
hooks: {
|
|
969
|
+
onBeforeUpdateAsset: () => {
|
|
970
|
+
events.push("hook");
|
|
971
|
+
},
|
|
972
|
+
},
|
|
973
|
+
});
|
|
974
|
+
const asset = await seedAsset(backend, { filename: "race.jpg" });
|
|
975
|
+
await expect(
|
|
976
|
+
backend
|
|
977
|
+
.forRequest(request("/race", { identity: tenantMember }))
|
|
978
|
+
.operations.media.updateAsset({ id: asset.id, data: { alt: "Loser" } }),
|
|
979
|
+
).rejects.toMatchObject({
|
|
980
|
+
statusCode: 409,
|
|
981
|
+
code: "MEDIA_STATE_CHANGED",
|
|
982
|
+
});
|
|
983
|
+
expect(events).toEqual([]);
|
|
984
|
+
expect(
|
|
985
|
+
await backend.adapter.findOne<Asset>({
|
|
986
|
+
model: "mediaAsset",
|
|
987
|
+
where: [{ field: "id", value: asset.id }],
|
|
988
|
+
}),
|
|
989
|
+
).toMatchObject({ alt: "Winner" });
|
|
990
|
+
|
|
991
|
+
const concurrent = makeBackend({
|
|
992
|
+
tenantId: "tenant-a",
|
|
993
|
+
auth: createAuth(),
|
|
994
|
+
hooks: {
|
|
995
|
+
onBeforeUpdateAsset: () => {
|
|
996
|
+
events.push("winner-hook");
|
|
997
|
+
},
|
|
998
|
+
},
|
|
999
|
+
});
|
|
1000
|
+
const concurrentAsset = await seedAsset(concurrent);
|
|
1001
|
+
const api = concurrent.forRequest(
|
|
1002
|
+
request("/concurrent", { identity: tenantMember }),
|
|
1003
|
+
).operations.media;
|
|
1004
|
+
const settled = await Promise.allSettled([
|
|
1005
|
+
api.updateAsset({ id: concurrentAsset.id, data: { alt: "First" } }),
|
|
1006
|
+
api.updateAsset({ id: concurrentAsset.id, data: { alt: "Second" } }),
|
|
1007
|
+
]);
|
|
1008
|
+
expect(settled.filter(({ status }) => status === "fulfilled")).toHaveLength(
|
|
1009
|
+
1,
|
|
1010
|
+
);
|
|
1011
|
+
expect(settled.filter(({ status }) => status === "rejected")).toHaveLength(
|
|
1012
|
+
1,
|
|
1013
|
+
);
|
|
1014
|
+
expect(events.filter((event) => event === "winner-hook")).toHaveLength(1);
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
it("keeps published memory rows created before the version field usable", async () => {
|
|
1018
|
+
const backend = makeBackend({
|
|
1019
|
+
auth: createAuth(),
|
|
1020
|
+
tenantId: "tenant-a",
|
|
1021
|
+
});
|
|
1022
|
+
const legacy = await backend.adapter.create<Asset>({
|
|
1023
|
+
model: "mediaAsset",
|
|
1024
|
+
data: {
|
|
1025
|
+
filename: "legacy.jpg",
|
|
1026
|
+
originalName: "legacy.jpg",
|
|
1027
|
+
mimeType: "image/jpeg",
|
|
1028
|
+
size: 5,
|
|
1029
|
+
url: "https://files.example/legacy.jpg",
|
|
1030
|
+
tenantId: "tenant-a",
|
|
1031
|
+
createdAt: new Date("2025-01-01T00:00:00.000Z"),
|
|
1032
|
+
},
|
|
1033
|
+
});
|
|
1034
|
+
await backend.adapter.update<Asset>({
|
|
1035
|
+
model: "mediaAsset",
|
|
1036
|
+
where: [{ field: "id", value: legacy.id }],
|
|
1037
|
+
update: { updatedAt: undefined },
|
|
1038
|
+
});
|
|
1039
|
+
await expect(
|
|
1040
|
+
backend
|
|
1041
|
+
.forRequest(request("/legacy", { identity: tenantMember }))
|
|
1042
|
+
.operations.media.updateAsset({
|
|
1043
|
+
id: legacy.id,
|
|
1044
|
+
data: { alt: "Still works" },
|
|
1045
|
+
}),
|
|
1046
|
+
).resolves.toMatchObject({ alt: "Still works" });
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
it("accepts D1 nested affected-row results for CAS updates and deletes", async () => {
|
|
1050
|
+
const backend = makeBackend({
|
|
1051
|
+
adapter: d1ResultAdapter,
|
|
1052
|
+
auth: createAuth(),
|
|
1053
|
+
tenantId: "tenant-a",
|
|
1054
|
+
});
|
|
1055
|
+
const updatedAsset = await seedAsset(backend, { filename: "update.jpg" });
|
|
1056
|
+
const deletedAsset = await seedAsset(backend, { filename: "delete.jpg" });
|
|
1057
|
+
const api = backend.forRequest(request("/d1", { identity: tenantMember }))
|
|
1058
|
+
.operations.media;
|
|
1059
|
+
|
|
1060
|
+
await expect(
|
|
1061
|
+
api.updateAsset({ id: updatedAsset.id, data: { alt: "Updated" } }),
|
|
1062
|
+
).resolves.toMatchObject({ id: updatedAsset.id, alt: "Updated" });
|
|
1063
|
+
await expect(api.deleteAsset({ id: deletedAsset.id })).resolves.toEqual({
|
|
1064
|
+
success: true,
|
|
1065
|
+
});
|
|
1066
|
+
expect(
|
|
1067
|
+
await backend.adapter.findOne<Asset>({
|
|
1068
|
+
model: "mediaAsset",
|
|
1069
|
+
where: [{ field: "id", value: deletedAsset.id }],
|
|
1070
|
+
}),
|
|
1071
|
+
).toBeNull();
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
it("accepts array results with a positive count and rejects zero", async () => {
|
|
1075
|
+
const positiveBackend = makeBackend({
|
|
1076
|
+
adapter: affectedRowResultAdapter((changes) =>
|
|
1077
|
+
Object.assign([], { count: changes }),
|
|
1078
|
+
),
|
|
1079
|
+
auth: createAuth(),
|
|
1080
|
+
tenantId: "tenant-a",
|
|
1081
|
+
});
|
|
1082
|
+
const positiveAsset = await seedAsset(positiveBackend);
|
|
1083
|
+
await expect(
|
|
1084
|
+
positiveBackend
|
|
1085
|
+
.forRequest(request("/array-count", { identity: tenantMember }))
|
|
1086
|
+
.operations.media.updateAsset({
|
|
1087
|
+
id: positiveAsset.id,
|
|
1088
|
+
data: { alt: "Updated" },
|
|
1089
|
+
}),
|
|
1090
|
+
).resolves.toMatchObject({ alt: "Updated" });
|
|
1091
|
+
|
|
1092
|
+
const zeroBackend = makeBackend({
|
|
1093
|
+
adapter: affectedRowResultAdapter(() => Object.assign([], { count: 0 })),
|
|
1094
|
+
auth: createAuth(),
|
|
1095
|
+
tenantId: "tenant-a",
|
|
1096
|
+
});
|
|
1097
|
+
const zeroAsset = await seedAsset(zeroBackend);
|
|
1098
|
+
await expect(
|
|
1099
|
+
zeroBackend
|
|
1100
|
+
.forRequest(request("/array-zero", { identity: tenantMember }))
|
|
1101
|
+
.operations.media.updateAsset({
|
|
1102
|
+
id: zeroAsset.id,
|
|
1103
|
+
data: { alt: "Must roll back" },
|
|
1104
|
+
}),
|
|
1105
|
+
).rejects.toMatchObject({
|
|
1106
|
+
statusCode: 409,
|
|
1107
|
+
code: "MEDIA_STATE_CHANGED",
|
|
1108
|
+
});
|
|
1109
|
+
expect(
|
|
1110
|
+
await zeroBackend.adapter.findOne<Asset>({
|
|
1111
|
+
model: "mediaAsset",
|
|
1112
|
+
where: [{ field: "id", value: zeroAsset.id }],
|
|
1113
|
+
}),
|
|
1114
|
+
).not.toMatchObject({ alt: "Must roll back" });
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
it("authorizes every folder in a recursive delete before hooks or mutation", async () => {
|
|
1118
|
+
let allowedParentId = "";
|
|
1119
|
+
const evaluated: Array<{ folderId: string; parentId?: string }> = [];
|
|
1120
|
+
const subtreeAuthorization = defineAuthorization({
|
|
1121
|
+
identity: identitySchema,
|
|
1122
|
+
permissions: [mediaPermissions] as const,
|
|
1123
|
+
rules: ({ media }) => [
|
|
1124
|
+
media.folder.delete.when(({ identity, facts }) => {
|
|
1125
|
+
evaluated.push({
|
|
1126
|
+
folderId: facts.folderId,
|
|
1127
|
+
...(facts.parentId ? { parentId: facts.parentId } : {}),
|
|
1128
|
+
});
|
|
1129
|
+
return identity !== null && facts.parentId === allowedParentId;
|
|
1130
|
+
}),
|
|
1131
|
+
],
|
|
1132
|
+
});
|
|
1133
|
+
const beforeDelete = vi.fn();
|
|
1134
|
+
const backend = makeBackend({
|
|
1135
|
+
auth: createAuth(identityFromRequest, subtreeAuthorization),
|
|
1136
|
+
tenantId: "tenant-a",
|
|
1137
|
+
hooks: { onBeforeDeleteFolder: beforeDelete },
|
|
1138
|
+
});
|
|
1139
|
+
const allowedParent = await seedFolder(backend, { name: "Allowed parent" });
|
|
1140
|
+
const root = await seedFolder(backend, {
|
|
1141
|
+
name: "Delete root",
|
|
1142
|
+
parentId: allowedParent.id,
|
|
1143
|
+
});
|
|
1144
|
+
const deniedChild = await seedFolder(backend, {
|
|
1145
|
+
name: "Denied child",
|
|
1146
|
+
parentId: root.id,
|
|
1147
|
+
});
|
|
1148
|
+
allowedParentId = allowedParent.id;
|
|
1149
|
+
|
|
1150
|
+
await expect(
|
|
1151
|
+
backend
|
|
1152
|
+
.forRequest(request("/delete-subtree", { identity: tenantMember }))
|
|
1153
|
+
.operations.media.deleteFolder({ id: root.id }),
|
|
1154
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
1155
|
+
expect(evaluated).toEqual([
|
|
1156
|
+
{ folderId: root.id, parentId: allowedParent.id },
|
|
1157
|
+
{ folderId: deniedChild.id, parentId: root.id },
|
|
1158
|
+
]);
|
|
1159
|
+
expect(beforeDelete).not.toHaveBeenCalled();
|
|
1160
|
+
expect(await backend.adapter.count({ model: "mediaFolder" })).toBe(3);
|
|
1161
|
+
});
|
|
1162
|
+
it("rejects a recursive delete when a descendant gains a concurrent child", async () => {
|
|
1163
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
1164
|
+
let descendantId = "";
|
|
1165
|
+
let raced = false;
|
|
1166
|
+
const beforeDelete = vi.fn();
|
|
1167
|
+
const raceAuth = createAuth(() => tenantMember);
|
|
1168
|
+
const authorize = raceAuth.authorize.bind(raceAuth);
|
|
1169
|
+
vi.spyOn(raceAuth, "authorize").mockImplementation(
|
|
1170
|
+
async (authRequest, permission) => {
|
|
1171
|
+
const identity = await authorize(authRequest, permission);
|
|
1172
|
+
if (
|
|
1173
|
+
!raced &&
|
|
1174
|
+
permission.id === mediaPermissions.folder.delete.id &&
|
|
1175
|
+
permission.facts.folderId === descendantId
|
|
1176
|
+
) {
|
|
1177
|
+
raced = true;
|
|
1178
|
+
await backend.trusted.media.createFolder({
|
|
1179
|
+
name: "Concurrent winner",
|
|
1180
|
+
parentId: descendantId,
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
return identity;
|
|
1184
|
+
},
|
|
1185
|
+
);
|
|
1186
|
+
backend = makeBackend({
|
|
1187
|
+
auth: raceAuth,
|
|
1188
|
+
tenantId: "tenant-a",
|
|
1189
|
+
hooks: { onBeforeDeleteFolder: beforeDelete },
|
|
1190
|
+
});
|
|
1191
|
+
const root = await seedFolder(backend, { name: "Delete root" });
|
|
1192
|
+
descendantId = (
|
|
1193
|
+
await seedFolder(backend, {
|
|
1194
|
+
name: "Existing child",
|
|
1195
|
+
parentId: root.id,
|
|
1196
|
+
})
|
|
1197
|
+
).id;
|
|
1198
|
+
|
|
1199
|
+
await expect(
|
|
1200
|
+
backend
|
|
1201
|
+
.forRequest(request("/delete-race", { identity: tenantMember }))
|
|
1202
|
+
.operations.media.deleteFolder({ id: root.id }),
|
|
1203
|
+
).rejects.toMatchObject({
|
|
1204
|
+
statusCode: 409,
|
|
1205
|
+
code: "MEDIA_STATE_CHANGED",
|
|
1206
|
+
});
|
|
1207
|
+
expect(beforeDelete).not.toHaveBeenCalled();
|
|
1208
|
+
expect(
|
|
1209
|
+
(await backend.adapter.findMany<Folder>({ model: "mediaFolder" })).map(
|
|
1210
|
+
(folder) => ({ name: folder.name, parentId: folder.parentId }),
|
|
1211
|
+
),
|
|
1212
|
+
).toEqual([
|
|
1213
|
+
{ name: "Delete root", parentId: undefined },
|
|
1214
|
+
{ name: "Existing child", parentId: root.id },
|
|
1215
|
+
{ name: "Concurrent winner", parentId: descendantId },
|
|
1216
|
+
]);
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
it.each(["folder", "asset"] as const)(
|
|
1220
|
+
"rechecks the claimed subtree after a delete hook creates a %s",
|
|
1221
|
+
async (winner) => {
|
|
1222
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
1223
|
+
let descendantId = "";
|
|
1224
|
+
const beforeDelete = vi.fn(async () => {
|
|
1225
|
+
if (winner === "folder") {
|
|
1226
|
+
await backend.trusted.media.createFolder({
|
|
1227
|
+
name: "Hook child",
|
|
1228
|
+
parentId: descendantId,
|
|
1229
|
+
});
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
1232
|
+
await backend.trusted.media.createAsset({
|
|
1233
|
+
filename: "hook.jpg",
|
|
1234
|
+
originalName: "hook.jpg",
|
|
1235
|
+
mimeType: "image/jpeg",
|
|
1236
|
+
size: 5,
|
|
1237
|
+
url: "https://files.example/hook.jpg",
|
|
1238
|
+
folderId: descendantId,
|
|
1239
|
+
});
|
|
1240
|
+
});
|
|
1241
|
+
backend = makeBackend({
|
|
1242
|
+
auth: createAuth(),
|
|
1243
|
+
tenantId: "tenant-a",
|
|
1244
|
+
hooks: { onBeforeDeleteFolder: beforeDelete },
|
|
1245
|
+
});
|
|
1246
|
+
const root = await seedFolder(backend, { name: "Delete root" });
|
|
1247
|
+
descendantId = (
|
|
1248
|
+
await seedFolder(backend, {
|
|
1249
|
+
name: "Existing child",
|
|
1250
|
+
parentId: root.id,
|
|
1251
|
+
})
|
|
1252
|
+
).id;
|
|
1253
|
+
|
|
1254
|
+
await expect(
|
|
1255
|
+
backend
|
|
1256
|
+
.forRequest(request("/delete-hook", { identity: tenantMember }))
|
|
1257
|
+
.operations.media.deleteFolder({ id: root.id }),
|
|
1258
|
+
).rejects.toMatchObject({
|
|
1259
|
+
statusCode: 409,
|
|
1260
|
+
code: winner === "folder" ? "MEDIA_STATE_CHANGED" : "FOLDER_NOT_EMPTY",
|
|
1261
|
+
});
|
|
1262
|
+
expect(beforeDelete).toHaveBeenCalledOnce();
|
|
1263
|
+
expect(await backend.adapter.count({ model: "mediaFolder" })).toBe(2);
|
|
1264
|
+
expect(await backend.adapter.count({ model: "mediaAsset" })).toBe(0);
|
|
1265
|
+
},
|
|
1266
|
+
);
|
|
1267
|
+
|
|
1268
|
+
it("fails closed when a raw import crosses the resolved tenant subtree", async () => {
|
|
1269
|
+
const beforeDelete = vi.fn();
|
|
1270
|
+
const backend = makeBackend({
|
|
1271
|
+
auth: createAuth(),
|
|
1272
|
+
tenantId: "tenant-a",
|
|
1273
|
+
hooks: { onBeforeDeleteFolder: beforeDelete },
|
|
1274
|
+
});
|
|
1275
|
+
const root = await seedFolder(backend, { name: "Tenant A root" });
|
|
1276
|
+
const foreignChild = await seedFolder(backend, {
|
|
1277
|
+
name: "Tenant B child",
|
|
1278
|
+
parentId: root.id,
|
|
1279
|
+
tenantId: "tenant-b",
|
|
1280
|
+
});
|
|
1281
|
+
|
|
1282
|
+
await expect(
|
|
1283
|
+
backend
|
|
1284
|
+
.forRequest(request("/tenant-boundary", { identity: admin }))
|
|
1285
|
+
.operations.media.deleteFolder({ id: root.id }),
|
|
1286
|
+
).rejects.toMatchObject({
|
|
1287
|
+
statusCode: 409,
|
|
1288
|
+
code: "MEDIA_STATE_CHANGED",
|
|
1289
|
+
});
|
|
1290
|
+
expect(beforeDelete).not.toHaveBeenCalled();
|
|
1291
|
+
expect(
|
|
1292
|
+
await backend.adapter.findOne<Folder>({
|
|
1293
|
+
model: "mediaFolder",
|
|
1294
|
+
where: [{ field: "id", value: root.id }],
|
|
1295
|
+
}),
|
|
1296
|
+
).not.toBeNull();
|
|
1297
|
+
expect(
|
|
1298
|
+
await backend.adapter.findOne<Folder>({
|
|
1299
|
+
model: "mediaFolder",
|
|
1300
|
+
where: [{ field: "id", value: foreignChild.id }],
|
|
1301
|
+
}),
|
|
1302
|
+
).not.toBeNull();
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1305
|
+
it("rejects stale upload initialization and finalization before hooks, tokens, or writes", async () => {
|
|
1306
|
+
const storage = s3Storage();
|
|
1307
|
+
const hook = vi.fn();
|
|
1308
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
1309
|
+
let folderId = "";
|
|
1310
|
+
let racePhase: "initialize" | "finalize" | undefined;
|
|
1311
|
+
const getIdentity = async () => {
|
|
1312
|
+
if (racePhase) {
|
|
1313
|
+
await backend.adapter.update<Folder>({
|
|
1314
|
+
model: "mediaFolder",
|
|
1315
|
+
where: [{ field: "id", value: folderId }],
|
|
1316
|
+
update: {
|
|
1317
|
+
name: `${racePhase} winner`,
|
|
1318
|
+
updatedAt: new Date(
|
|
1319
|
+
racePhase === "initialize"
|
|
1320
|
+
? "2026-02-01T00:00:00.000Z"
|
|
1321
|
+
: "2026-03-01T00:00:00.000Z",
|
|
1322
|
+
),
|
|
1323
|
+
},
|
|
1324
|
+
});
|
|
1325
|
+
racePhase = undefined;
|
|
1326
|
+
}
|
|
1327
|
+
return tenantMember;
|
|
1328
|
+
};
|
|
1329
|
+
backend = makeBackend({
|
|
1330
|
+
auth: createAuth(getIdentity),
|
|
1331
|
+
storage,
|
|
1332
|
+
tenantId: "tenant-a",
|
|
1333
|
+
hooks: { onBeforeUpload: hook },
|
|
1334
|
+
});
|
|
1335
|
+
folderId = (await seedFolder(backend)).id;
|
|
1336
|
+
const api = backend.forRequest(
|
|
1337
|
+
request("/upload-race", { identity: tenantMember }),
|
|
1338
|
+
).operations.media;
|
|
1339
|
+
|
|
1340
|
+
racePhase = "initialize";
|
|
1341
|
+
await expect(
|
|
1342
|
+
api.uploadToken({
|
|
1343
|
+
filename: "race.jpg",
|
|
1344
|
+
mimeType: "image/jpeg",
|
|
1345
|
+
size: 5,
|
|
1346
|
+
folderId,
|
|
1347
|
+
}),
|
|
1348
|
+
).rejects.toMatchObject({
|
|
1349
|
+
statusCode: 409,
|
|
1350
|
+
code: "MEDIA_STATE_CHANGED",
|
|
1351
|
+
});
|
|
1352
|
+
expect(storage.generateUploadToken).not.toHaveBeenCalled();
|
|
1353
|
+
expect(hook).not.toHaveBeenCalled();
|
|
1354
|
+
|
|
1355
|
+
racePhase = "finalize";
|
|
1356
|
+
const finalizeApi = backend.forRequest(
|
|
1357
|
+
request("/finalize-race", { identity: tenantMember }),
|
|
1358
|
+
).operations.media;
|
|
1359
|
+
await expect(
|
|
1360
|
+
finalizeApi.createAsset({
|
|
1361
|
+
filename: "race.jpg",
|
|
1362
|
+
originalName: "race.jpg",
|
|
1363
|
+
mimeType: "image/jpeg",
|
|
1364
|
+
size: 5,
|
|
1365
|
+
url: "https://files.example/race.jpg",
|
|
1366
|
+
folderId,
|
|
1367
|
+
}),
|
|
1368
|
+
).rejects.toMatchObject({
|
|
1369
|
+
statusCode: 409,
|
|
1370
|
+
code: "MEDIA_STATE_CHANGED",
|
|
1371
|
+
});
|
|
1372
|
+
expect(hook).not.toHaveBeenCalled();
|
|
1373
|
+
expect(await backend.adapter.count({ model: "mediaAsset" })).toBe(0);
|
|
1374
|
+
});
|
|
1375
|
+
|
|
1376
|
+
it("serializes memory rollback so rejected uploads cannot erase later raw or API winners", async () => {
|
|
1377
|
+
let startRejected = () => {};
|
|
1378
|
+
const rejectedStarted = new Promise<void>((resolve) => {
|
|
1379
|
+
startRejected = resolve;
|
|
1380
|
+
});
|
|
1381
|
+
let releaseRejected = () => {};
|
|
1382
|
+
const rejectedGate = new Promise<void>((resolve) => {
|
|
1383
|
+
releaseRejected = resolve;
|
|
1384
|
+
});
|
|
1385
|
+
const backend = makeBackend({
|
|
1386
|
+
auth: createAuth(),
|
|
1387
|
+
tenantId: "tenant-a",
|
|
1388
|
+
hooks: {
|
|
1389
|
+
onBeforeCreateFolder: async (input) => {
|
|
1390
|
+
if (input.name !== "Rejected") return;
|
|
1391
|
+
startRejected();
|
|
1392
|
+
await rejectedGate;
|
|
1393
|
+
throw new Error("workflow rejected");
|
|
1394
|
+
},
|
|
1395
|
+
},
|
|
1396
|
+
});
|
|
1397
|
+
const api = backend.forRequest(request("/race", { identity: tenantMember }))
|
|
1398
|
+
.operations.media;
|
|
1399
|
+
const rejected = api.createFolder({ name: "Rejected" });
|
|
1400
|
+
await rejectedStarted;
|
|
1401
|
+
const now = new Date();
|
|
1402
|
+
const rawWinner = backend.adapter.create<Folder>({
|
|
1403
|
+
model: "mediaFolder",
|
|
1404
|
+
data: {
|
|
1405
|
+
name: "Raw winner",
|
|
1406
|
+
tenantId: "tenant-a",
|
|
1407
|
+
createdAt: now,
|
|
1408
|
+
updatedAt: now,
|
|
1409
|
+
},
|
|
1410
|
+
});
|
|
1411
|
+
const apiWinner = api.createFolder({ name: "API winner" });
|
|
1412
|
+
releaseRejected();
|
|
1413
|
+
await expect(rejected).rejects.toMatchObject({
|
|
1414
|
+
statusCode: 403,
|
|
1415
|
+
code: "CREATE_FOLDER_REJECTED",
|
|
1416
|
+
});
|
|
1417
|
+
await expect(rawWinner).resolves.toMatchObject({ name: "Raw winner" });
|
|
1418
|
+
await expect(apiWinner).resolves.toMatchObject({ name: "API winner" });
|
|
1419
|
+
expect(
|
|
1420
|
+
(await backend.adapter.findMany<Folder>({ model: "mediaFolder" })).map(
|
|
1421
|
+
({ name }) => name,
|
|
1422
|
+
),
|
|
1423
|
+
).toEqual(["Raw winner", "API winner"]);
|
|
1424
|
+
});
|
|
1425
|
+
|
|
1426
|
+
it("rolls back a caught nested after-hook failure with its memory parent", async () => {
|
|
1427
|
+
let backend: ReturnType<typeof makeBackend>;
|
|
1428
|
+
const caught: string[] = [];
|
|
1429
|
+
backend = makeBackend({
|
|
1430
|
+
auth: createAuth(),
|
|
1431
|
+
tenantId: "tenant-a",
|
|
1432
|
+
hooks: {
|
|
1433
|
+
onBeforeCreateFolder: async (input) => {
|
|
1434
|
+
if (input.name !== "Outer") return;
|
|
1435
|
+
try {
|
|
1436
|
+
await backend.trusted.media.createAsset({
|
|
1437
|
+
filename: "nested.jpg",
|
|
1438
|
+
originalName: "nested.jpg",
|
|
1439
|
+
mimeType: "image/jpeg",
|
|
1440
|
+
size: 5,
|
|
1441
|
+
url: "https://files.example/nested.jpg",
|
|
1442
|
+
});
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
caught.push(error instanceof Error ? error.message : "unknown");
|
|
1445
|
+
}
|
|
1446
|
+
},
|
|
1447
|
+
onAfterUpload: (asset) => {
|
|
1448
|
+
if (asset.filename === "nested.jpg") {
|
|
1449
|
+
throw new Error("nested after rejected");
|
|
1450
|
+
}
|
|
1451
|
+
},
|
|
1452
|
+
},
|
|
1453
|
+
});
|
|
1454
|
+
await expect(
|
|
1455
|
+
backend
|
|
1456
|
+
.forRequest(request("/nested", { identity: tenantMember }))
|
|
1457
|
+
.operations.media.createFolder({ name: "Outer" }),
|
|
1458
|
+
).rejects.toThrow("nested after rejected");
|
|
1459
|
+
expect(caught).toEqual(["nested after rejected"]);
|
|
1460
|
+
expect(await backend.adapter.count({ model: "mediaAsset" })).toBe(0);
|
|
1461
|
+
expect(await backend.adapter.count({ model: "mediaFolder" })).toBe(0);
|
|
1462
|
+
}, 1_000);
|
|
1463
|
+
|
|
1464
|
+
it("enforces upload initialization, finalization, and deletion without leaking tokens from collection reads", async () => {
|
|
1465
|
+
const storage = s3Storage();
|
|
1466
|
+
const events: string[] = [];
|
|
1467
|
+
const initializeOnly = defineAuthorization({
|
|
1468
|
+
identity: identitySchema,
|
|
1469
|
+
permissions: [mediaPermissions] as const,
|
|
1470
|
+
rules: ({ media }) => [
|
|
1471
|
+
media.library.read.when(({ identity }) => identity !== null),
|
|
1472
|
+
media.asset.read.when(({ identity }) => identity !== null),
|
|
1473
|
+
media.asset.upload.when(
|
|
1474
|
+
({ identity, facts }) =>
|
|
1475
|
+
identity !== null && facts.phase === "initialize",
|
|
1476
|
+
),
|
|
1477
|
+
],
|
|
1478
|
+
});
|
|
1479
|
+
const backend = makeBackend({
|
|
1480
|
+
auth: createAuth(identityFromRequest, initializeOnly),
|
|
1481
|
+
storage,
|
|
1482
|
+
tenantId: "tenant-a",
|
|
1483
|
+
hooks: {
|
|
1484
|
+
onBeforeUpload: (_meta, context) => {
|
|
1485
|
+
events.push(context.facts.phase);
|
|
1486
|
+
},
|
|
1487
|
+
onBeforeDeleteAsset: () => {
|
|
1488
|
+
events.push("delete");
|
|
1489
|
+
},
|
|
1490
|
+
},
|
|
1491
|
+
});
|
|
1492
|
+
await seedAsset(backend);
|
|
1493
|
+
const list = await backend.handler(
|
|
1494
|
+
request("/media/assets", { identity: tenantMember }),
|
|
1495
|
+
);
|
|
1496
|
+
expect(list.status).toBe(200);
|
|
1497
|
+
expect(JSON.stringify(await list.json())).not.toContain("signed-secret");
|
|
1498
|
+
expect(storage.generateUploadToken).not.toHaveBeenCalled();
|
|
1499
|
+
const token = await backend.handler(
|
|
1500
|
+
request("/media/upload/token", {
|
|
1501
|
+
method: "POST",
|
|
1502
|
+
identity: tenantMember,
|
|
1503
|
+
body: {
|
|
1504
|
+
filename: "new.jpg",
|
|
1505
|
+
mimeType: "image/jpeg",
|
|
1506
|
+
size: 5,
|
|
1507
|
+
},
|
|
1508
|
+
}),
|
|
1509
|
+
);
|
|
1510
|
+
expect(token.status).toBe(200);
|
|
1511
|
+
expect(await token.json()).toMatchObject({
|
|
1512
|
+
payload: { uploadUrl: "https://storage.example/signed-secret" },
|
|
1513
|
+
});
|
|
1514
|
+
const finalize = await backend.handler(
|
|
1515
|
+
request("/media/assets", {
|
|
1516
|
+
method: "POST",
|
|
1517
|
+
identity: tenantMember,
|
|
1518
|
+
body: {
|
|
1519
|
+
filename: "new.jpg",
|
|
1520
|
+
originalName: "new.jpg",
|
|
1521
|
+
mimeType: "image/jpeg",
|
|
1522
|
+
size: 5,
|
|
1523
|
+
url: "https://files.example/new.jpg",
|
|
1524
|
+
},
|
|
1525
|
+
}),
|
|
1526
|
+
);
|
|
1527
|
+
expect(finalize.status).toBe(403);
|
|
1528
|
+
const existing = await backend.adapter.findOne<Asset>({
|
|
1529
|
+
model: "mediaAsset",
|
|
1530
|
+
where: [{ field: "filename", value: "photo.jpg" }],
|
|
1531
|
+
});
|
|
1532
|
+
expect(existing).not.toBeNull();
|
|
1533
|
+
const deletion = await backend.handler(
|
|
1534
|
+
request(`/media/assets/${existing?.id}`, {
|
|
1535
|
+
method: "DELETE",
|
|
1536
|
+
identity: tenantMember,
|
|
1537
|
+
}),
|
|
1538
|
+
);
|
|
1539
|
+
expect(deletion.status).toBe(403);
|
|
1540
|
+
expect(events).toEqual(["initialize"]);
|
|
1541
|
+
});
|
|
1542
|
+
|
|
1543
|
+
it("does not release asset response data under collection-only permission", async () => {
|
|
1544
|
+
const collectionOnly = defineAuthorization({
|
|
1545
|
+
identity: identitySchema,
|
|
1546
|
+
permissions: [mediaPermissions] as const,
|
|
1547
|
+
rules: ({ media }) => [media.library.read.allow()],
|
|
1548
|
+
});
|
|
1549
|
+
const backend = makeBackend({
|
|
1550
|
+
auth: createAuth(identityFromRequest, collectionOnly),
|
|
1551
|
+
tenantId: "tenant-a",
|
|
1552
|
+
});
|
|
1553
|
+
await seedAsset(backend, {
|
|
1554
|
+
filename: "protected.jpg",
|
|
1555
|
+
url: "https://files.example/protected.jpg",
|
|
1556
|
+
});
|
|
1557
|
+
const response = await backend.handler(
|
|
1558
|
+
request("/media/assets", { identity: tenantMember }),
|
|
1559
|
+
);
|
|
1560
|
+
expect(response.status).toBe(403);
|
|
1561
|
+
const body = JSON.stringify(await response.json());
|
|
1562
|
+
expect(body).not.toContain("protected.jpg");
|
|
1563
|
+
expect(body).not.toContain("https://files.example/protected.jpg");
|
|
1564
|
+
});
|
|
1565
|
+
|
|
1566
|
+
it("verifies and binds provider callbacks before public authorization or effects", async () => {
|
|
1567
|
+
const storage = vercelStorage();
|
|
1568
|
+
const getIdentity = vi.fn(() => null);
|
|
1569
|
+
const backend = makeBackend({
|
|
1570
|
+
auth: createAuth(getIdentity),
|
|
1571
|
+
storage,
|
|
1572
|
+
tenantId: "tenant-a",
|
|
1573
|
+
});
|
|
1574
|
+
const callbackBody = {
|
|
1575
|
+
type: "blob.upload-completed",
|
|
1576
|
+
payload: {
|
|
1577
|
+
blob: {
|
|
1578
|
+
url: "https://evil.example/spoof.jpg",
|
|
1579
|
+
pathname: "spoof.jpg",
|
|
1580
|
+
},
|
|
1581
|
+
tokenPayload: JSON.stringify({
|
|
1582
|
+
pathname: "bound.jpg",
|
|
1583
|
+
mimeType: "image/jpeg",
|
|
1584
|
+
tenantId: "tenant-a",
|
|
1585
|
+
}),
|
|
1586
|
+
},
|
|
1587
|
+
} as const;
|
|
1588
|
+
const invalid = await backend.handler(
|
|
1589
|
+
request("/media/upload/vercel-blob", {
|
|
1590
|
+
method: "POST",
|
|
1591
|
+
body: callbackBody,
|
|
1592
|
+
}),
|
|
1593
|
+
);
|
|
1594
|
+
expect(invalid.status).toBe(401);
|
|
1595
|
+
expect(await invalid.json()).toMatchObject({
|
|
1596
|
+
code: "INVALID_PROVIDER_CALLBACK",
|
|
1597
|
+
});
|
|
1598
|
+
expect(getIdentity).not.toHaveBeenCalled();
|
|
1599
|
+
expect(storage.handleRequest).not.toHaveBeenCalled();
|
|
1600
|
+
|
|
1601
|
+
const validRequest = request("/media/upload/vercel-blob", {
|
|
1602
|
+
method: "POST",
|
|
1603
|
+
body: callbackBody,
|
|
1604
|
+
});
|
|
1605
|
+
validRequest.headers.set("x-vercel-signature", "valid");
|
|
1606
|
+
const valid = await backend.handler(validRequest);
|
|
1607
|
+
expect(valid.status).toBe(200);
|
|
1608
|
+
expect(await valid.json()).toEqual({
|
|
1609
|
+
type: "blob.upload-completed",
|
|
1610
|
+
response: "ok",
|
|
1611
|
+
});
|
|
1612
|
+
expect(storage.verifyCallback).toHaveBeenCalledTimes(2);
|
|
1613
|
+
expect(storage.handleRequest).toHaveBeenCalledOnce();
|
|
1614
|
+
expect(getIdentity).toHaveBeenCalledOnce();
|
|
1615
|
+
});
|
|
1616
|
+
|
|
1617
|
+
it("rejects concurrent destructive losers before a second storage effect", async () => {
|
|
1618
|
+
const storage = directStorage();
|
|
1619
|
+
const hooks = vi.fn();
|
|
1620
|
+
const backend = makeBackend({
|
|
1621
|
+
auth: createAuth(),
|
|
1622
|
+
storage,
|
|
1623
|
+
tenantId: "tenant-a",
|
|
1624
|
+
hooks: { onBeforeDeleteAsset: hooks },
|
|
1625
|
+
});
|
|
1626
|
+
const asset = await seedAsset(backend);
|
|
1627
|
+
const api = backend.forRequest(
|
|
1628
|
+
request("/delete", { identity: tenantMember }),
|
|
1629
|
+
).operations.media;
|
|
1630
|
+
const settled = await Promise.allSettled([
|
|
1631
|
+
api.deleteAsset({ id: asset.id }),
|
|
1632
|
+
api.deleteAsset({ id: asset.id }),
|
|
1633
|
+
]);
|
|
1634
|
+
expect(settled.filter(({ status }) => status === "fulfilled")).toHaveLength(
|
|
1635
|
+
1,
|
|
1636
|
+
);
|
|
1637
|
+
expect(settled.filter(({ status }) => status === "rejected")).toHaveLength(
|
|
1638
|
+
1,
|
|
1639
|
+
);
|
|
1640
|
+
expect(storage.delete).toHaveBeenCalledOnce();
|
|
1641
|
+
expect(hooks).toHaveBeenCalledOnce();
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
it("keeps raw helpers out of request/trusted namespaces and raw prefetch tenant-free", async () => {
|
|
1645
|
+
const backend = makeBackend({ auth: createAuth(), tenantId: "tenant-a" });
|
|
1646
|
+
const folder = await seedFolder(backend);
|
|
1647
|
+
const child = await seedFolder(backend, {
|
|
1648
|
+
name: "Nested",
|
|
1649
|
+
parentId: folder.id,
|
|
1650
|
+
});
|
|
1651
|
+
await seedAsset(backend, {
|
|
1652
|
+
folderId: folder.id,
|
|
1653
|
+
url: "/uploads/photo.jpg",
|
|
1654
|
+
});
|
|
1655
|
+
expect("prefetchForRoute" in backend.trusted.media).toBe(false);
|
|
1656
|
+
expect("getAssetById" in backend.trusted.media).toBe(false);
|
|
1657
|
+
expect(
|
|
1658
|
+
"prefetchForRoute" in
|
|
1659
|
+
backend.forRequest(request("/raw")).operations.media,
|
|
1660
|
+
).toBe(false);
|
|
1661
|
+
expect("updateAsset" in backend.trusted.media).toBe(true);
|
|
1662
|
+
const queryClient = new QueryClient();
|
|
1663
|
+
const endpoint = {
|
|
1664
|
+
baseURL: "https://media.example.com",
|
|
1665
|
+
basePath: "/api/data",
|
|
1666
|
+
};
|
|
1667
|
+
await backend.raw.media.prefetchForRoute("library", queryClient, endpoint);
|
|
1668
|
+
const cached = queryClient.getQueryData(
|
|
1669
|
+
MEDIA_QUERY_KEYS.assetsList({ limit: 40 }, undefined, endpoint),
|
|
1670
|
+
);
|
|
1671
|
+
expect(JSON.stringify(cached)).not.toContain("tenant-a");
|
|
1672
|
+
expect(JSON.stringify(cached)).toContain(
|
|
1673
|
+
"https://media.example.com/uploads/photo.jpg",
|
|
1674
|
+
);
|
|
1675
|
+
expect(
|
|
1676
|
+
queryClient.getQueryData(
|
|
1677
|
+
MEDIA_QUERY_KEYS.foldersList(undefined, undefined, endpoint),
|
|
1678
|
+
),
|
|
1679
|
+
).toEqual(
|
|
1680
|
+
expect.arrayContaining([
|
|
1681
|
+
expect.objectContaining({ id: folder.id }),
|
|
1682
|
+
expect.objectContaining({ id: child.id, parentId: folder.id }),
|
|
1683
|
+
]),
|
|
1684
|
+
);
|
|
1685
|
+
expect(
|
|
1686
|
+
JSON.stringify(
|
|
1687
|
+
queryClient.getQueryData(
|
|
1688
|
+
MEDIA_QUERY_KEYS.foldersList(undefined, undefined, endpoint),
|
|
1689
|
+
),
|
|
1690
|
+
),
|
|
1691
|
+
).not.toContain("tenant-a");
|
|
1692
|
+
expect(
|
|
1693
|
+
queryClient.getQueryData(
|
|
1694
|
+
MEDIA_QUERY_KEYS.foldersList(null, undefined, endpoint),
|
|
1695
|
+
),
|
|
1696
|
+
).toBeUndefined();
|
|
1697
|
+
});
|
|
1698
|
+
|
|
1699
|
+
it("allows cold anonymous reads only through explicit library and asset public rules", async () => {
|
|
1700
|
+
const publicAuthorization = defineAuthorization({
|
|
1701
|
+
identity: identitySchema,
|
|
1702
|
+
permissions: [mediaPermissions] as const,
|
|
1703
|
+
rules: ({ media }) => [
|
|
1704
|
+
media.library.read.allow(),
|
|
1705
|
+
media.asset.read.allow(),
|
|
1706
|
+
],
|
|
1707
|
+
});
|
|
1708
|
+
const backend = makeBackend({
|
|
1709
|
+
auth: createAuth(identityFromRequest, publicAuthorization),
|
|
1710
|
+
tenantId: "tenant-a",
|
|
1711
|
+
});
|
|
1712
|
+
await seedAsset(backend);
|
|
1713
|
+
const response = await backend.handler(request("/media/assets"));
|
|
1714
|
+
expect(response.status).toBe(200);
|
|
1715
|
+
expect(await response.json()).toMatchObject({ total: 1 });
|
|
1716
|
+
});
|
|
1717
|
+
});
|
|
1718
|
+
|
|
1719
|
+
describe("Vercel callback verifier", () => {
|
|
1720
|
+
it("uses the configured secret for an exact body signature", async () => {
|
|
1721
|
+
const token = "vercel-secret";
|
|
1722
|
+
const body = {
|
|
1723
|
+
type: "blob.upload-completed" as const,
|
|
1724
|
+
payload: {
|
|
1725
|
+
blob: {
|
|
1726
|
+
url: "https://x.public.blob.vercel-storage.com/a",
|
|
1727
|
+
downloadUrl: "https://x.public.blob.vercel-storage.com/a?download=1",
|
|
1728
|
+
pathname: "a",
|
|
1729
|
+
contentType: "image/png",
|
|
1730
|
+
contentDisposition: 'inline; filename="a"',
|
|
1731
|
+
},
|
|
1732
|
+
tokenPayload: JSON.stringify({
|
|
1733
|
+
version: 1,
|
|
1734
|
+
pathname: "a",
|
|
1735
|
+
mimeType: "image/png",
|
|
1736
|
+
}),
|
|
1737
|
+
},
|
|
1738
|
+
};
|
|
1739
|
+
const signature = createHmac("sha256", token)
|
|
1740
|
+
.update(JSON.stringify(body))
|
|
1741
|
+
.digest("hex");
|
|
1742
|
+
const parsedBody = VercelBlobOperationInputSchema.parse({ body }).body;
|
|
1743
|
+
expect(JSON.stringify(parsedBody)).toBe(JSON.stringify(body));
|
|
1744
|
+
if (
|
|
1745
|
+
!("type" in parsedBody) ||
|
|
1746
|
+
parsedBody.type !== "blob.upload-completed"
|
|
1747
|
+
) {
|
|
1748
|
+
throw new Error("Expected a parsed Vercel Blob callback");
|
|
1749
|
+
}
|
|
1750
|
+
const { vercelBlobAdapter } = await import("../api/adapters/vercel-blob");
|
|
1751
|
+
const adapter = vercelBlobAdapter({ token });
|
|
1752
|
+
await expect(
|
|
1753
|
+
adapter.verifyCallback(
|
|
1754
|
+
new Request("http://localhost", {
|
|
1755
|
+
headers: { "x-vercel-signature": signature },
|
|
1756
|
+
}),
|
|
1757
|
+
parsedBody,
|
|
1758
|
+
),
|
|
1759
|
+
).resolves.toEqual({ pathname: "a", mimeType: "image/png" });
|
|
1760
|
+
await expect(
|
|
1761
|
+
adapter.verifyCallback(
|
|
1762
|
+
new Request("http://localhost", {
|
|
1763
|
+
headers: { "x-vercel-signature": `${signature.slice(0, -2)}00` },
|
|
1764
|
+
}),
|
|
1765
|
+
parsedBody,
|
|
1766
|
+
),
|
|
1767
|
+
).rejects.toThrow("Invalid Vercel Blob callback signature");
|
|
1768
|
+
});
|
|
1769
|
+
});
|