@btst/stack 3.0.0-rc.1 → 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 +122 -46
- 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 +30 -12
- package/dist/next/index.d.mts +30 -12
- package/dist/next/index.d.ts +30 -12
- 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/next/page.cjs +8 -6
- package/dist/packages/stack/src/next/page.mjs +8 -6
- 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 +161 -105
- package/dist/packages/stack/src/plugins/comments/client/components/comment-thread.mjs +162 -106
- 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 +27 -16
- package/dist/packages/stack/src/react-router/page.mjs +28 -17
- 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 +11 -5
- package/dist/packages/stack/src/tanstack/page.mjs +11 -5
- 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 +7 -2
- package/dist/plugins/comments/client/components/index.d.mts +7 -2
- package/dist/plugins/comments/client/components/index.d.ts +7 -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 +41 -7
- package/dist/react-router/index.d.mts +41 -7
- package/dist/react-router/index.d.ts +41 -7
- 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.mts → stack.5_zzCejP.d.cts} +16 -14
- package/dist/shared/{stack.9BAOaSqE.d.ts → stack.5_zzCejP.d.mts} +16 -14
- package/dist/shared/{stack.9BAOaSqE.d.cts → 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.INBa9-TO.d.cts → stack.BGzgFx3R.d.cts} +5 -5
- 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.3di7vQs6.d.mts → stack.CjCSDfWy.d.mts} +5 -5
- 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.mts → stack.DjGixVx3.d.cts} +6 -2
- package/dist/shared/{stack.BMlLOMED.d.ts → stack.DjGixVx3.d.mts} +6 -2
- package/dist/shared/{stack.BMlLOMED.d.cts → 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.CRelKJfH.d.ts → stack.Dpg_JjIo.d.ts} +5 -5
- 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 +44 -14
- package/dist/tanstack/index.d.mts +44 -14
- package/dist/tanstack/index.d.ts +44 -14
- 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 +203 -8
- 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__/entry-factories.test.tsx +104 -4
- 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 +315 -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/index.tsx +2 -0
- package/src/next/layout.tsx +81 -0
- package/src/next/page.tsx +33 -12
- 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 +465 -79
- 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 +154 -112
- 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 +6 -0
- package/src/react-router/layout.ts +43 -0
- package/src/react-router/page.tsx +46 -17
- package/src/react-router/router.tsx +1 -1
- package/src/shared/auth-types.ts +19 -70
- package/src/shared/entry-factories.ts +12 -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 +7 -0
- package/src/tanstack/layout.ts +36 -0
- package/src/tanstack/page.tsx +35 -13
- package/src/tanstack/router.tsx +1 -1
- package/src/tanstack/server.ts +18 -0
- package/src/types.ts +557 -65
- package/dist/shared/stack.80-y2TTR.d.mts +0 -840
- package/dist/shared/stack.B-hEIoUw.d.ts +0 -406
- 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.Bk5UB_BT.d.ts +0 -840
- 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.BvxHSZYT.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.CMbX8Q5C.d.ts +0 -560
- package/dist/shared/stack.Cf-DbL1A.d.ts +0 -329
- 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.DQq8DEIv.d.mts +0 -461
- package/dist/shared/stack.Dd-8shBE.d.ts +0 -492
- package/dist/shared/stack.Dj04W2c3.d.mts +0 -560
- package/dist/shared/stack.DrUBX-QE.d.cts +0 -34
- package/dist/shared/stack.DrUBX-QE.d.mts +0 -34
- package/dist/shared/stack.DrUBX-QE.d.ts +0 -34
- package/dist/shared/stack.H5B8miAV.d.cts +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.eq5eg1yt.d.cts +0 -560
- package/dist/shared/stack.f8Vke-eH.d.mts +0 -406
- package/dist/shared/stack.oBokjN_J.d.mts +0 -416
- package/dist/shared/{stack.B0muOwUF.d.cts → stack.Csi-4Mgz.d.cts} +8 -8
- package/dist/shared/{stack.B0muOwUF.d.mts → stack.Csi-4Mgz.d.mts} +8 -8
- package/dist/shared/{stack.B0muOwUF.d.ts → stack.Csi-4Mgz.d.ts} +8 -8
|
@@ -0,0 +1,1493 @@
|
|
|
1
|
+
import type { DBAdapter as Adapter } from "@btst/db";
|
|
2
|
+
import {
|
|
3
|
+
defineOperation,
|
|
4
|
+
type DeepReadonly,
|
|
5
|
+
type Operation,
|
|
6
|
+
type OperationData,
|
|
7
|
+
OperationHttpError,
|
|
8
|
+
type OperationContext,
|
|
9
|
+
} from "@btst/stack/plugins/api";
|
|
10
|
+
import type { PermissionFactsFor } from "@btst/stack/authorization";
|
|
11
|
+
import { formSchemaToZod } from "@workspace/ui/lib/schema-converter";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { formBuilderPermissions } from "../permissions";
|
|
14
|
+
import {
|
|
15
|
+
createFormSchema,
|
|
16
|
+
listFormsQuerySchema,
|
|
17
|
+
listSubmissionsQuerySchema,
|
|
18
|
+
updateFormSchema,
|
|
19
|
+
} from "../schemas";
|
|
20
|
+
import type {
|
|
21
|
+
Form,
|
|
22
|
+
FormBuilderBackendHooks,
|
|
23
|
+
FormBuilderHookContext,
|
|
24
|
+
FormBuilderOperationHookContext,
|
|
25
|
+
FormInput,
|
|
26
|
+
SerializedForm,
|
|
27
|
+
FormSubmission,
|
|
28
|
+
FormSubmissionWithForm,
|
|
29
|
+
SerializedFormSubmission,
|
|
30
|
+
FormUpdate,
|
|
31
|
+
SubmissionHookContext,
|
|
32
|
+
SubmissionListFormContext,
|
|
33
|
+
SerializedFormSubmissionSummary,
|
|
34
|
+
} from "../types";
|
|
35
|
+
import { extractIpAddress, extractUserAgent, slugify } from "../utils";
|
|
36
|
+
import {
|
|
37
|
+
getAllForms,
|
|
38
|
+
getFormSubmissions,
|
|
39
|
+
serializeForm,
|
|
40
|
+
serializeFormSubmission,
|
|
41
|
+
serializeFormSubmissionSummary,
|
|
42
|
+
serializeFormSubmissionWithData,
|
|
43
|
+
} from "./getters";
|
|
44
|
+
|
|
45
|
+
const SubmissionDataSchema = z
|
|
46
|
+
.record(z.string(), z.unknown())
|
|
47
|
+
.transform((value) => value as Record<string, OperationData>);
|
|
48
|
+
const CreateFormHookResultSchema = createFormSchema.extend({
|
|
49
|
+
createdBy: z.string().min(1).optional(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const SubmitFormOperationInputSchema = z.object({
|
|
53
|
+
slug: z.string(),
|
|
54
|
+
data: SubmissionDataSchema,
|
|
55
|
+
});
|
|
56
|
+
export const UpdateFormOperationInputSchema = z.object({
|
|
57
|
+
id: z.string(),
|
|
58
|
+
data: updateFormSchema,
|
|
59
|
+
});
|
|
60
|
+
export const DeleteFormOperationInputSchema = z.object({ id: z.string() });
|
|
61
|
+
export const GetFormBySlugOperationInputSchema = z.object({ slug: z.string() });
|
|
62
|
+
export const GetFormByIdOperationInputSchema = z.object({ id: z.string() });
|
|
63
|
+
export const GetFormForUpdateOperationInputSchema = z.object({
|
|
64
|
+
id: z.string(),
|
|
65
|
+
});
|
|
66
|
+
export const ListSubmissionsOperationInputSchema = z.object({
|
|
67
|
+
formId: z.string(),
|
|
68
|
+
query: listSubmissionsQuerySchema,
|
|
69
|
+
});
|
|
70
|
+
export const GetSubmissionOperationInputSchema = z.object({
|
|
71
|
+
formId: z.string(),
|
|
72
|
+
submissionId: z.string(),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
type FormReadFacts = PermissionFactsFor<
|
|
76
|
+
typeof formBuilderPermissions.form.read
|
|
77
|
+
>;
|
|
78
|
+
type FormRenderFacts = PermissionFactsFor<
|
|
79
|
+
typeof formBuilderPermissions.form.render
|
|
80
|
+
>;
|
|
81
|
+
type FormUpdateFacts = PermissionFactsFor<
|
|
82
|
+
typeof formBuilderPermissions.form.update
|
|
83
|
+
>;
|
|
84
|
+
type FormDeleteFacts = PermissionFactsFor<
|
|
85
|
+
typeof formBuilderPermissions.form.delete
|
|
86
|
+
>;
|
|
87
|
+
type SubmissionCreateFacts = PermissionFactsFor<
|
|
88
|
+
typeof formBuilderPermissions.submission.create
|
|
89
|
+
>;
|
|
90
|
+
type SubmissionReadFacts = PermissionFactsFor<
|
|
91
|
+
typeof formBuilderPermissions.submission.read
|
|
92
|
+
>;
|
|
93
|
+
type SubmissionDeleteFacts = PermissionFactsFor<
|
|
94
|
+
typeof formBuilderPermissions.submission.delete
|
|
95
|
+
>;
|
|
96
|
+
|
|
97
|
+
type SubmissionOperationData = Record<string, OperationData>;
|
|
98
|
+
|
|
99
|
+
export interface FormListOperationResult {
|
|
100
|
+
readonly items: readonly SerializedForm[];
|
|
101
|
+
readonly total: number;
|
|
102
|
+
readonly limit?: number;
|
|
103
|
+
readonly offset?: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface SubmissionDetailOperationResult
|
|
107
|
+
extends SerializedFormSubmission {
|
|
108
|
+
readonly parsedData: SubmissionOperationData | null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface SubmissionListOperationResult {
|
|
112
|
+
readonly form: SubmissionListFormContext;
|
|
113
|
+
readonly items: readonly SerializedFormSubmissionSummary[];
|
|
114
|
+
readonly total: number;
|
|
115
|
+
readonly limit?: number;
|
|
116
|
+
readonly offset?: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface SubmitOperationResult extends SerializedFormSubmission {
|
|
120
|
+
readonly form: Pick<SerializedForm, "successMessage" | "redirectUrl">;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type FormBuilderOperations = {
|
|
124
|
+
readonly listForms: Operation<
|
|
125
|
+
typeof listFormsQuerySchema,
|
|
126
|
+
typeof formBuilderPermissions.form.read,
|
|
127
|
+
FormListOperationResult
|
|
128
|
+
>;
|
|
129
|
+
readonly getFormBySlug: Operation<
|
|
130
|
+
typeof GetFormBySlugOperationInputSchema,
|
|
131
|
+
typeof formBuilderPermissions.form.render,
|
|
132
|
+
SerializedForm
|
|
133
|
+
>;
|
|
134
|
+
readonly getFormById: Operation<
|
|
135
|
+
typeof GetFormByIdOperationInputSchema,
|
|
136
|
+
typeof formBuilderPermissions.form.read,
|
|
137
|
+
SerializedForm
|
|
138
|
+
>;
|
|
139
|
+
readonly getFormForUpdate: Operation<
|
|
140
|
+
typeof GetFormForUpdateOperationInputSchema,
|
|
141
|
+
typeof formBuilderPermissions.form.update,
|
|
142
|
+
SerializedForm
|
|
143
|
+
>;
|
|
144
|
+
readonly createForm: Operation<
|
|
145
|
+
typeof createFormSchema,
|
|
146
|
+
typeof formBuilderPermissions.form.create,
|
|
147
|
+
SerializedForm
|
|
148
|
+
>;
|
|
149
|
+
readonly updateForm: Operation<
|
|
150
|
+
typeof UpdateFormOperationInputSchema,
|
|
151
|
+
typeof formBuilderPermissions.form.update,
|
|
152
|
+
SerializedForm
|
|
153
|
+
>;
|
|
154
|
+
readonly deleteForm: Operation<
|
|
155
|
+
typeof DeleteFormOperationInputSchema,
|
|
156
|
+
typeof formBuilderPermissions.form.delete,
|
|
157
|
+
{ readonly success: true }
|
|
158
|
+
>;
|
|
159
|
+
readonly submitForm: Operation<
|
|
160
|
+
typeof SubmitFormOperationInputSchema,
|
|
161
|
+
typeof formBuilderPermissions.submission.create,
|
|
162
|
+
SubmitOperationResult
|
|
163
|
+
>;
|
|
164
|
+
readonly listSubmissions: Operation<
|
|
165
|
+
typeof ListSubmissionsOperationInputSchema,
|
|
166
|
+
typeof formBuilderPermissions.submission.read,
|
|
167
|
+
SubmissionListOperationResult
|
|
168
|
+
>;
|
|
169
|
+
readonly getSubmission: Operation<
|
|
170
|
+
typeof GetSubmissionOperationInputSchema,
|
|
171
|
+
typeof formBuilderPermissions.submission.read,
|
|
172
|
+
SubmissionDetailOperationResult
|
|
173
|
+
>;
|
|
174
|
+
readonly deleteSubmission: Operation<
|
|
175
|
+
typeof GetSubmissionOperationInputSchema,
|
|
176
|
+
typeof formBuilderPermissions.submission.delete,
|
|
177
|
+
{ readonly success: true }
|
|
178
|
+
>;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
type RequestFields = {
|
|
182
|
+
readonly request?: Request;
|
|
183
|
+
readonly headers?: Headers;
|
|
184
|
+
readonly ipAddress?: string;
|
|
185
|
+
readonly userAgent?: string;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/** A domain/HTTP error raised after Form Builder authorization succeeds. */
|
|
189
|
+
export class FormBuilderOperationError extends OperationHttpError {
|
|
190
|
+
constructor(
|
|
191
|
+
statusCode: number,
|
|
192
|
+
message: string,
|
|
193
|
+
code: string,
|
|
194
|
+
issues?: readonly unknown[],
|
|
195
|
+
) {
|
|
196
|
+
super(statusCode, message, code, issues);
|
|
197
|
+
this.name = "FormBuilderOperationError";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
interface FormSnapshot {
|
|
202
|
+
readonly id: string;
|
|
203
|
+
readonly slug: string;
|
|
204
|
+
readonly ownerId?: string;
|
|
205
|
+
readonly status: Form["status"];
|
|
206
|
+
readonly updatedAt: Date;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface SubmissionSnapshot {
|
|
210
|
+
readonly id: string;
|
|
211
|
+
readonly formId: string;
|
|
212
|
+
readonly submittedBy?: string;
|
|
213
|
+
readonly submittedAt: Date;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
interface SubmissionAuthorizationSnapshot {
|
|
217
|
+
readonly form: FormSnapshot;
|
|
218
|
+
readonly submission: SubmissionSnapshot;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
type ReadAdapter = Pick<Adapter, "findOne">;
|
|
222
|
+
type ClaimAdapter = Pick<Adapter, "updateMany">;
|
|
223
|
+
|
|
224
|
+
function snapshotForm(form: Form): FormSnapshot {
|
|
225
|
+
return {
|
|
226
|
+
id: form.id,
|
|
227
|
+
slug: form.slug,
|
|
228
|
+
...(form.createdBy ? { ownerId: form.createdBy } : {}),
|
|
229
|
+
status: form.status,
|
|
230
|
+
updatedAt: form.updatedAt,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function snapshotSubmission(submission: FormSubmission): SubmissionSnapshot {
|
|
235
|
+
return {
|
|
236
|
+
id: submission.id,
|
|
237
|
+
formId: submission.formId,
|
|
238
|
+
...(submission.submittedBy ? { submittedBy: submission.submittedBy } : {}),
|
|
239
|
+
submittedAt: submission.submittedAt,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function sameFormSnapshot(form: Form | null, expected: FormSnapshot | null) {
|
|
244
|
+
if (!form || !expected) return form === null && expected === null;
|
|
245
|
+
const current = snapshotForm(form);
|
|
246
|
+
return (
|
|
247
|
+
current.id === expected.id &&
|
|
248
|
+
current.slug === expected.slug &&
|
|
249
|
+
current.ownerId === expected.ownerId &&
|
|
250
|
+
current.status === expected.status &&
|
|
251
|
+
current.updatedAt.getTime() === expected.updatedAt.getTime()
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function sameSubmissionSnapshot(
|
|
256
|
+
submission: FormSubmission | null,
|
|
257
|
+
expected: SubmissionSnapshot,
|
|
258
|
+
) {
|
|
259
|
+
if (!submission) return false;
|
|
260
|
+
const current = snapshotSubmission(submission);
|
|
261
|
+
return (
|
|
262
|
+
current.id === expected.id &&
|
|
263
|
+
current.formId === expected.formId &&
|
|
264
|
+
current.submittedBy === expected.submittedBy &&
|
|
265
|
+
current.submittedAt.getTime() === expected.submittedAt.getTime()
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const AFFECTED_ROW_KEYS = [
|
|
270
|
+
"rowCount",
|
|
271
|
+
"affectedRows",
|
|
272
|
+
"rowsAffected",
|
|
273
|
+
"changes",
|
|
274
|
+
"numUpdatedRows",
|
|
275
|
+
] as const;
|
|
276
|
+
|
|
277
|
+
function hasPositiveCount(value: unknown): boolean {
|
|
278
|
+
if (typeof value === "number") return Number.isFinite(value) && value > 0;
|
|
279
|
+
if (typeof value === "bigint") return value > 0n;
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Normalize affected-row results across the supported adapters. */
|
|
284
|
+
function didAffectRow(result: unknown, expectedId: string): boolean {
|
|
285
|
+
if (typeof result === "number" || typeof result === "bigint") {
|
|
286
|
+
return hasPositiveCount(result);
|
|
287
|
+
}
|
|
288
|
+
if (!result || typeof result !== "object") return false;
|
|
289
|
+
const record = result as Record<string, unknown>;
|
|
290
|
+
if ("count" in record) return hasPositiveCount(record.count);
|
|
291
|
+
if (Array.isArray(result)) {
|
|
292
|
+
return result.length > 0 && didAffectRow(result[0], expectedId);
|
|
293
|
+
}
|
|
294
|
+
for (const key of AFFECTED_ROW_KEYS) {
|
|
295
|
+
if (key in record) return hasPositiveCount(record[key]);
|
|
296
|
+
}
|
|
297
|
+
if ("meta" in record) {
|
|
298
|
+
const meta = record.meta;
|
|
299
|
+
return Boolean(
|
|
300
|
+
meta &&
|
|
301
|
+
typeof meta === "object" &&
|
|
302
|
+
"changes" in meta &&
|
|
303
|
+
hasPositiveCount((meta as Record<string, unknown>).changes),
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
return record.id === expectedId;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function formSnapshotWhere(snapshot: FormSnapshot) {
|
|
310
|
+
return [
|
|
311
|
+
{ field: "id", value: snapshot.id, operator: "eq" as const },
|
|
312
|
+
{ field: "slug", value: snapshot.slug, operator: "eq" as const },
|
|
313
|
+
{ field: "status", value: snapshot.status, operator: "eq" as const },
|
|
314
|
+
{
|
|
315
|
+
field: "createdBy",
|
|
316
|
+
value: snapshot.ownerId ?? null,
|
|
317
|
+
operator: "eq" as const,
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
field: "updatedAt",
|
|
321
|
+
value: snapshot.updatedAt,
|
|
322
|
+
operator: "eq" as const,
|
|
323
|
+
},
|
|
324
|
+
];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function submissionSnapshotWhere(snapshot: SubmissionSnapshot) {
|
|
328
|
+
return [
|
|
329
|
+
{ field: "id", value: snapshot.id, operator: "eq" as const },
|
|
330
|
+
{ field: "formId", value: snapshot.formId, operator: "eq" as const },
|
|
331
|
+
{
|
|
332
|
+
field: "submittedBy",
|
|
333
|
+
value: snapshot.submittedBy ?? null,
|
|
334
|
+
operator: "eq" as const,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
field: "submittedAt",
|
|
338
|
+
value: snapshot.submittedAt,
|
|
339
|
+
operator: "eq" as const,
|
|
340
|
+
},
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function nextSnapshotDate(previous: Date) {
|
|
345
|
+
return new Date(Math.max(Date.now(), previous.getTime() + 1));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function requireAtomicTransactions(adapter: Adapter) {
|
|
349
|
+
if (
|
|
350
|
+
adapter.id === "memory" ||
|
|
351
|
+
typeof adapter.options?.adapterConfig.transaction !== "function"
|
|
352
|
+
) {
|
|
353
|
+
throw new FormBuilderOperationError(
|
|
354
|
+
500,
|
|
355
|
+
"Form Builder owner-sensitive writes require an adapter with isolated transaction support.",
|
|
356
|
+
"ATOMIC_TRANSACTION_REQUIRED",
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async function claimFormSnapshot(
|
|
362
|
+
adapter: ClaimAdapter,
|
|
363
|
+
snapshot: FormSnapshot,
|
|
364
|
+
stale: () => Error,
|
|
365
|
+
) {
|
|
366
|
+
const claimedAt = nextSnapshotDate(snapshot.updatedAt);
|
|
367
|
+
const matched = await adapter.updateMany({
|
|
368
|
+
model: "form",
|
|
369
|
+
where: formSnapshotWhere(snapshot),
|
|
370
|
+
update: { updatedAt: claimedAt },
|
|
371
|
+
});
|
|
372
|
+
if (!didAffectRow(matched, snapshot.id)) throw stale();
|
|
373
|
+
return claimedAt;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async function restoreFormSnapshot(
|
|
377
|
+
adapter: ClaimAdapter,
|
|
378
|
+
snapshot: FormSnapshot,
|
|
379
|
+
claimedAt: Date,
|
|
380
|
+
stale: () => Error,
|
|
381
|
+
) {
|
|
382
|
+
const restored = await adapter.updateMany({
|
|
383
|
+
model: "form",
|
|
384
|
+
where: formSnapshotWhere({ ...snapshot, updatedAt: claimedAt }),
|
|
385
|
+
update: { updatedAt: snapshot.updatedAt },
|
|
386
|
+
});
|
|
387
|
+
if (!didAffectRow(restored, snapshot.id)) throw stale();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
async function claimSubmissionSnapshot(
|
|
391
|
+
adapter: ClaimAdapter,
|
|
392
|
+
snapshot: SubmissionSnapshot,
|
|
393
|
+
) {
|
|
394
|
+
const claimedAt = nextSnapshotDate(snapshot.submittedAt);
|
|
395
|
+
const matched = await adapter.updateMany({
|
|
396
|
+
model: "formSubmission",
|
|
397
|
+
where: submissionSnapshotWhere(snapshot),
|
|
398
|
+
update: { submittedAt: claimedAt },
|
|
399
|
+
});
|
|
400
|
+
if (!didAffectRow(matched, snapshot.id)) throw staleSubmissionError();
|
|
401
|
+
return claimedAt;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function staleFormError() {
|
|
405
|
+
return new FormBuilderOperationError(
|
|
406
|
+
409,
|
|
407
|
+
"Form changed while authorization was being evaluated. Retry the operation.",
|
|
408
|
+
"FORM_STATE_CHANGED",
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function staleSubmissionError() {
|
|
413
|
+
return new FormBuilderOperationError(
|
|
414
|
+
409,
|
|
415
|
+
"Submission changed while authorization was being evaluated. Retry the operation.",
|
|
416
|
+
"SUBMISSION_STATE_CHANGED",
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function formNotFoundError() {
|
|
421
|
+
return new FormBuilderOperationError(404, "Form not found", "FORM_NOT_FOUND");
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function submissionNotFoundError() {
|
|
425
|
+
return new FormBuilderOperationError(
|
|
426
|
+
404,
|
|
427
|
+
"Submission not found",
|
|
428
|
+
"SUBMISSION_NOT_FOUND",
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async function findFormById(
|
|
433
|
+
adapter: ReadAdapter,
|
|
434
|
+
id: string,
|
|
435
|
+
): Promise<Form | null> {
|
|
436
|
+
return (
|
|
437
|
+
(await adapter.findOne<Form>({
|
|
438
|
+
model: "form",
|
|
439
|
+
where: [{ field: "id", value: id, operator: "eq" as const }],
|
|
440
|
+
})) ?? null
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async function findFormBySlug(
|
|
445
|
+
adapter: ReadAdapter,
|
|
446
|
+
slug: string,
|
|
447
|
+
): Promise<Form | null> {
|
|
448
|
+
return (
|
|
449
|
+
(await adapter.findOne<Form>({
|
|
450
|
+
model: "form",
|
|
451
|
+
where: [{ field: "slug", value: slug, operator: "eq" as const }],
|
|
452
|
+
})) ?? null
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async function findSubmission(
|
|
457
|
+
adapter: ReadAdapter,
|
|
458
|
+
submissionId: string,
|
|
459
|
+
): Promise<FormSubmission | null> {
|
|
460
|
+
return (
|
|
461
|
+
(await adapter.findOne<FormSubmission>({
|
|
462
|
+
model: "formSubmission",
|
|
463
|
+
where: [{ field: "id", value: submissionId, operator: "eq" as const }],
|
|
464
|
+
})) ?? null
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function requestFields(request: Request | undefined): RequestFields {
|
|
469
|
+
if (!request) return {};
|
|
470
|
+
return {
|
|
471
|
+
request,
|
|
472
|
+
headers: request.headers,
|
|
473
|
+
...(extractIpAddress(request.headers)
|
|
474
|
+
? { ipAddress: extractIpAddress(request.headers) }
|
|
475
|
+
: {}),
|
|
476
|
+
...(extractUserAgent(request.headers)
|
|
477
|
+
? { userAgent: extractUserAgent(request.headers) }
|
|
478
|
+
: {}),
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function hookContext<TInput, TFacts>(
|
|
483
|
+
context: OperationContext<TInput, TFacts>,
|
|
484
|
+
): FormBuilderHookContext<TInput, TFacts> {
|
|
485
|
+
return Object.freeze({
|
|
486
|
+
...context,
|
|
487
|
+
...(context.identity ? { userId: context.identity.id } : {}),
|
|
488
|
+
...requestFields(context.request),
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function submissionHookContext<TInput, TFacts>(
|
|
493
|
+
context: OperationContext<TInput, TFacts>,
|
|
494
|
+
formSlug: string,
|
|
495
|
+
formId: string,
|
|
496
|
+
): SubmissionHookContext<TInput, TFacts> {
|
|
497
|
+
return Object.freeze({
|
|
498
|
+
...hookContext(context),
|
|
499
|
+
formSlug,
|
|
500
|
+
formId,
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function normalizeError(error: unknown, fallback: string): Error {
|
|
505
|
+
if (error instanceof Error) return error;
|
|
506
|
+
return new Error(typeof error === "string" ? error : fallback, {
|
|
507
|
+
cause: error,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
async function notifyError(
|
|
512
|
+
hooks: FormBuilderBackendHooks | undefined,
|
|
513
|
+
error: unknown,
|
|
514
|
+
operation:
|
|
515
|
+
| "list"
|
|
516
|
+
| "get"
|
|
517
|
+
| "create"
|
|
518
|
+
| "update"
|
|
519
|
+
| "delete"
|
|
520
|
+
| "submit"
|
|
521
|
+
| "listSubmissions"
|
|
522
|
+
| "getSubmission"
|
|
523
|
+
| "deleteSubmission",
|
|
524
|
+
context: FormBuilderOperationHookContext,
|
|
525
|
+
) {
|
|
526
|
+
try {
|
|
527
|
+
await hooks?.onError?.(
|
|
528
|
+
normalizeError(error, "Form Builder operation failed."),
|
|
529
|
+
operation,
|
|
530
|
+
context,
|
|
531
|
+
);
|
|
532
|
+
} catch {
|
|
533
|
+
// Error hooks are observational and must not replace the operation error.
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async function runDomainHook<TResult>(
|
|
538
|
+
run: () => Promise<TResult> | TResult,
|
|
539
|
+
statusCode: number,
|
|
540
|
+
code: string,
|
|
541
|
+
): Promise<TResult> {
|
|
542
|
+
try {
|
|
543
|
+
return await run();
|
|
544
|
+
} catch (error) {
|
|
545
|
+
throw new FormBuilderOperationError(
|
|
546
|
+
statusCode,
|
|
547
|
+
normalizeError(error, "Operation rejected").message,
|
|
548
|
+
code,
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function publicReadFacts(slug: string, form: Form | null): FormRenderFacts {
|
|
554
|
+
return {
|
|
555
|
+
slug,
|
|
556
|
+
exists: form !== null,
|
|
557
|
+
...(form
|
|
558
|
+
? {
|
|
559
|
+
formId: form.id,
|
|
560
|
+
...(form.createdBy ? { ownerId: form.createdBy } : {}),
|
|
561
|
+
status: form.status,
|
|
562
|
+
}
|
|
563
|
+
: {}),
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function recordReadFacts(id: string, form: Form | null): FormReadFacts {
|
|
568
|
+
return {
|
|
569
|
+
scope: "record",
|
|
570
|
+
formId: id,
|
|
571
|
+
exists: form !== null,
|
|
572
|
+
...(form
|
|
573
|
+
? {
|
|
574
|
+
...(form.createdBy ? { ownerId: form.createdBy } : {}),
|
|
575
|
+
status: form.status,
|
|
576
|
+
}
|
|
577
|
+
: {}),
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function resolvedFormFacts(form: Form): FormUpdateFacts & FormDeleteFacts {
|
|
582
|
+
return {
|
|
583
|
+
formId: form.id,
|
|
584
|
+
...(form.createdBy ? { ownerId: form.createdBy } : {}),
|
|
585
|
+
status: form.status,
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function submissionRecordFacts(
|
|
590
|
+
formId: string,
|
|
591
|
+
submissionId: string,
|
|
592
|
+
form: Form | null,
|
|
593
|
+
submission: FormSubmission | null,
|
|
594
|
+
): SubmissionReadFacts {
|
|
595
|
+
const exists = submission?.formId === formId && form?.id === formId;
|
|
596
|
+
return {
|
|
597
|
+
scope: "record",
|
|
598
|
+
formId,
|
|
599
|
+
submissionId,
|
|
600
|
+
exists,
|
|
601
|
+
...(form?.createdBy ? { ownerId: form.createdBy } : {}),
|
|
602
|
+
...(exists && submission?.submittedBy
|
|
603
|
+
? { submittedBy: submission.submittedBy }
|
|
604
|
+
: {}),
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function assertValidJsonSchema(schema: string) {
|
|
609
|
+
try {
|
|
610
|
+
JSON.parse(schema);
|
|
611
|
+
} catch {
|
|
612
|
+
throw new FormBuilderOperationError(
|
|
613
|
+
400,
|
|
614
|
+
"Invalid JSON Schema",
|
|
615
|
+
"INVALID_FORM_SCHEMA",
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function sanitizeSlug(rawSlug: string) {
|
|
621
|
+
const slug = slugify(rawSlug);
|
|
622
|
+
if (!slug) {
|
|
623
|
+
throw new FormBuilderOperationError(
|
|
624
|
+
400,
|
|
625
|
+
"Invalid slug: must contain at least one alphanumeric character",
|
|
626
|
+
"INVALID_SLUG",
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
return slug;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function duplicateSlugError() {
|
|
633
|
+
return new FormBuilderOperationError(
|
|
634
|
+
409,
|
|
635
|
+
"Form with this slug already exists",
|
|
636
|
+
"DUPLICATE_FORM_SLUG",
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function operationForm(form: Form) {
|
|
641
|
+
const serialized = serializeForm(form);
|
|
642
|
+
return {
|
|
643
|
+
id: serialized.id,
|
|
644
|
+
name: serialized.name,
|
|
645
|
+
slug: serialized.slug,
|
|
646
|
+
description: serialized.description,
|
|
647
|
+
schema: serialized.schema,
|
|
648
|
+
successMessage: serialized.successMessage,
|
|
649
|
+
redirectUrl: serialized.redirectUrl,
|
|
650
|
+
status: serialized.status,
|
|
651
|
+
createdBy: serialized.createdBy,
|
|
652
|
+
createdAt: serialized.createdAt,
|
|
653
|
+
updatedAt: serialized.updatedAt,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function operationFormsResult(result: Awaited<ReturnType<typeof getAllForms>>) {
|
|
658
|
+
return {
|
|
659
|
+
items: result.items.map((form) => ({ ...form })),
|
|
660
|
+
total: result.total,
|
|
661
|
+
...(result.limit !== undefined ? { limit: result.limit } : {}),
|
|
662
|
+
...(result.offset !== undefined ? { offset: result.offset } : {}),
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function operationJson(value: unknown): SubmissionOperationData | null {
|
|
667
|
+
if (value === null) return null;
|
|
668
|
+
return JSON.parse(JSON.stringify(value)) as SubmissionOperationData;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function operationSubmissionWithData(submission: FormSubmission) {
|
|
672
|
+
const serialized = serializeFormSubmissionWithData(submission);
|
|
673
|
+
return {
|
|
674
|
+
id: serialized.id,
|
|
675
|
+
formId: serialized.formId,
|
|
676
|
+
data: serialized.data,
|
|
677
|
+
submittedAt: serialized.submittedAt,
|
|
678
|
+
submittedBy: serialized.submittedBy,
|
|
679
|
+
ipAddress: serialized.ipAddress,
|
|
680
|
+
userAgent: serialized.userAgent,
|
|
681
|
+
parsedData: operationJson(serialized.parsedData),
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function operationSubmissionsResult(
|
|
686
|
+
result: Awaited<ReturnType<typeof getFormSubmissions>>,
|
|
687
|
+
) {
|
|
688
|
+
return {
|
|
689
|
+
items: result.items.map(serializeFormSubmissionSummary),
|
|
690
|
+
total: result.total,
|
|
691
|
+
...(result.limit !== undefined ? { limit: result.limit } : {}),
|
|
692
|
+
...(result.offset !== undefined ? { offset: result.offset } : {}),
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function operationSubmissionFormContext(form: Form) {
|
|
697
|
+
return {
|
|
698
|
+
id: form.id,
|
|
699
|
+
name: form.name,
|
|
700
|
+
...(form.createdBy ? { createdBy: form.createdBy } : {}),
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/** Create the complete Form Builder operation inventory for every transport. */
|
|
705
|
+
export function createFormBuilderOperations(
|
|
706
|
+
adapter: Adapter,
|
|
707
|
+
hooks?: FormBuilderBackendHooks,
|
|
708
|
+
): FormBuilderOperations {
|
|
709
|
+
const formSnapshots = new WeakMap<object, FormSnapshot | null>();
|
|
710
|
+
const submissionSnapshots = new WeakMap<
|
|
711
|
+
object,
|
|
712
|
+
SubmissionAuthorizationSnapshot | null
|
|
713
|
+
>();
|
|
714
|
+
const submittedFormSnapshots = new WeakMap<object, SerializedForm>();
|
|
715
|
+
|
|
716
|
+
const listForms = defineOperation({
|
|
717
|
+
input: listFormsQuerySchema,
|
|
718
|
+
permission: formBuilderPermissions.form.read,
|
|
719
|
+
facts: () => ({ scope: "collection" as const }),
|
|
720
|
+
before: async (context) => {
|
|
721
|
+
await runDomainHook(
|
|
722
|
+
() => hooks?.onBeforeListForms?.(hookContext(context)),
|
|
723
|
+
403,
|
|
724
|
+
"LIST_FORMS_REJECTED",
|
|
725
|
+
);
|
|
726
|
+
},
|
|
727
|
+
execute: async ({ input }) =>
|
|
728
|
+
operationFormsResult(await getAllForms(adapter, input)),
|
|
729
|
+
onError: ({ error, ...context }) =>
|
|
730
|
+
notifyError(hooks, error, "list", hookContext(context)),
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
const getFormBySlug = defineOperation({
|
|
734
|
+
input: GetFormBySlugOperationInputSchema,
|
|
735
|
+
permission: formBuilderPermissions.form.render,
|
|
736
|
+
facts: async ({ input }) => {
|
|
737
|
+
const form = await findFormBySlug(adapter, input.slug);
|
|
738
|
+
formSnapshots.set(input as object, form ? snapshotForm(form) : null);
|
|
739
|
+
return publicReadFacts(input.slug, form);
|
|
740
|
+
},
|
|
741
|
+
before: async (context) => {
|
|
742
|
+
const current = await findFormBySlug(adapter, context.input.slug);
|
|
743
|
+
if (
|
|
744
|
+
!sameFormSnapshot(
|
|
745
|
+
current,
|
|
746
|
+
formSnapshots.get(context.input as object) ?? null,
|
|
747
|
+
)
|
|
748
|
+
) {
|
|
749
|
+
throw staleFormError();
|
|
750
|
+
}
|
|
751
|
+
await runDomainHook(
|
|
752
|
+
() =>
|
|
753
|
+
hooks?.onBeforeGetForm?.(context.input.slug, hookContext(context)),
|
|
754
|
+
403,
|
|
755
|
+
"GET_FORM_REJECTED",
|
|
756
|
+
);
|
|
757
|
+
},
|
|
758
|
+
execute: async (context) => {
|
|
759
|
+
const form = await findFormBySlug(adapter, context.input.slug);
|
|
760
|
+
if (
|
|
761
|
+
!sameFormSnapshot(
|
|
762
|
+
form,
|
|
763
|
+
formSnapshots.get(context.input as object) ?? null,
|
|
764
|
+
)
|
|
765
|
+
) {
|
|
766
|
+
throw staleFormError();
|
|
767
|
+
}
|
|
768
|
+
if (!form) throw formNotFoundError();
|
|
769
|
+
return operationForm(form);
|
|
770
|
+
},
|
|
771
|
+
onError: ({ error, ...context }) =>
|
|
772
|
+
notifyError(hooks, error, "get", hookContext(context)),
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
const getFormById = defineOperation({
|
|
776
|
+
input: GetFormByIdOperationInputSchema,
|
|
777
|
+
permission: formBuilderPermissions.form.read,
|
|
778
|
+
facts: async ({ input }) => {
|
|
779
|
+
const form = await findFormById(adapter, input.id);
|
|
780
|
+
formSnapshots.set(input as object, form ? snapshotForm(form) : null);
|
|
781
|
+
return recordReadFacts(input.id, form);
|
|
782
|
+
},
|
|
783
|
+
before: async (context) => {
|
|
784
|
+
const current = await findFormById(adapter, context.input.id);
|
|
785
|
+
if (
|
|
786
|
+
!sameFormSnapshot(
|
|
787
|
+
current,
|
|
788
|
+
formSnapshots.get(context.input as object) ?? null,
|
|
789
|
+
)
|
|
790
|
+
) {
|
|
791
|
+
throw staleFormError();
|
|
792
|
+
}
|
|
793
|
+
await runDomainHook(
|
|
794
|
+
() => hooks?.onBeforeGetForm?.(context.input.id, hookContext(context)),
|
|
795
|
+
403,
|
|
796
|
+
"GET_FORM_REJECTED",
|
|
797
|
+
);
|
|
798
|
+
},
|
|
799
|
+
execute: async (context) => {
|
|
800
|
+
const form = await findFormById(adapter, context.input.id);
|
|
801
|
+
if (
|
|
802
|
+
!sameFormSnapshot(
|
|
803
|
+
form,
|
|
804
|
+
formSnapshots.get(context.input as object) ?? null,
|
|
805
|
+
)
|
|
806
|
+
) {
|
|
807
|
+
throw staleFormError();
|
|
808
|
+
}
|
|
809
|
+
if (!form) throw formNotFoundError();
|
|
810
|
+
return operationForm(form);
|
|
811
|
+
},
|
|
812
|
+
onError: ({ error, ...context }) =>
|
|
813
|
+
notifyError(hooks, error, "get", hookContext(context)),
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
const getFormForUpdate = defineOperation({
|
|
817
|
+
input: GetFormForUpdateOperationInputSchema,
|
|
818
|
+
permission: formBuilderPermissions.form.update,
|
|
819
|
+
facts: async ({ input }) => {
|
|
820
|
+
const form = await findFormById(adapter, input.id);
|
|
821
|
+
if (!form) throw formNotFoundError();
|
|
822
|
+
formSnapshots.set(input as object, snapshotForm(form));
|
|
823
|
+
return resolvedFormFacts(form);
|
|
824
|
+
},
|
|
825
|
+
before: async (context) => {
|
|
826
|
+
const current = await findFormById(adapter, context.input.id);
|
|
827
|
+
if (
|
|
828
|
+
!sameFormSnapshot(
|
|
829
|
+
current,
|
|
830
|
+
formSnapshots.get(context.input as object) ?? null,
|
|
831
|
+
)
|
|
832
|
+
) {
|
|
833
|
+
throw staleFormError();
|
|
834
|
+
}
|
|
835
|
+
await runDomainHook(
|
|
836
|
+
() =>
|
|
837
|
+
hooks?.onBeforeGetFormForUpdate?.(
|
|
838
|
+
context.input.id,
|
|
839
|
+
hookContext(context),
|
|
840
|
+
),
|
|
841
|
+
403,
|
|
842
|
+
"GET_FORM_REJECTED",
|
|
843
|
+
);
|
|
844
|
+
},
|
|
845
|
+
execute: async (context) => {
|
|
846
|
+
const form = await findFormById(adapter, context.input.id);
|
|
847
|
+
if (
|
|
848
|
+
!sameFormSnapshot(
|
|
849
|
+
form,
|
|
850
|
+
formSnapshots.get(context.input as object) ?? null,
|
|
851
|
+
)
|
|
852
|
+
) {
|
|
853
|
+
throw staleFormError();
|
|
854
|
+
}
|
|
855
|
+
if (!form) throw formNotFoundError();
|
|
856
|
+
return operationForm(form);
|
|
857
|
+
},
|
|
858
|
+
onError: ({ error, ...context }) =>
|
|
859
|
+
notifyError(hooks, error, "get", hookContext(context)),
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
const createForm = defineOperation({
|
|
863
|
+
input: createFormSchema,
|
|
864
|
+
permission: formBuilderPermissions.form.create,
|
|
865
|
+
facts: () => undefined,
|
|
866
|
+
execute: async (context) => {
|
|
867
|
+
const initial: FormInput = {
|
|
868
|
+
...context.input,
|
|
869
|
+
slug: sanitizeSlug(context.input.slug),
|
|
870
|
+
redirectUrl: context.input.redirectUrl || undefined,
|
|
871
|
+
...(context.identity ? { createdBy: context.identity.id } : {}),
|
|
872
|
+
};
|
|
873
|
+
assertValidJsonSchema(initial.schema);
|
|
874
|
+
const modified = await runDomainHook(
|
|
875
|
+
async () =>
|
|
876
|
+
(await hooks?.onBeforeCreateForm?.(initial, hookContext(context))) ??
|
|
877
|
+
initial,
|
|
878
|
+
403,
|
|
879
|
+
"CREATE_FORM_REJECTED",
|
|
880
|
+
);
|
|
881
|
+
const validation = CreateFormHookResultSchema.safeParse(modified);
|
|
882
|
+
if (!validation.success) {
|
|
883
|
+
throw new FormBuilderOperationError(
|
|
884
|
+
400,
|
|
885
|
+
"Invalid form data",
|
|
886
|
+
"FORM_VALIDATION_FAILED",
|
|
887
|
+
validation.error.issues,
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
const formInput: FormInput = {
|
|
891
|
+
...validation.data,
|
|
892
|
+
slug: sanitizeSlug(validation.data.slug),
|
|
893
|
+
...(context.identity ? { createdBy: context.identity.id } : {}),
|
|
894
|
+
};
|
|
895
|
+
assertValidJsonSchema(formInput.schema);
|
|
896
|
+
return adapter.transaction(async (tx) => {
|
|
897
|
+
const duplicate = await findFormBySlug(tx, formInput.slug);
|
|
898
|
+
if (duplicate) throw duplicateSlugError();
|
|
899
|
+
const now = new Date();
|
|
900
|
+
return operationForm(
|
|
901
|
+
await tx.create<Form>({
|
|
902
|
+
model: "form",
|
|
903
|
+
data: {
|
|
904
|
+
name: formInput.name,
|
|
905
|
+
slug: formInput.slug,
|
|
906
|
+
description: formInput.description,
|
|
907
|
+
schema: formInput.schema,
|
|
908
|
+
successMessage: formInput.successMessage,
|
|
909
|
+
redirectUrl: formInput.redirectUrl,
|
|
910
|
+
status: formInput.status ?? "active",
|
|
911
|
+
createdBy: formInput.createdBy,
|
|
912
|
+
createdAt: now,
|
|
913
|
+
updatedAt: now,
|
|
914
|
+
},
|
|
915
|
+
}),
|
|
916
|
+
);
|
|
917
|
+
});
|
|
918
|
+
},
|
|
919
|
+
after: async (context) => {
|
|
920
|
+
await hooks?.onAfterCreateForm?.(context.result, hookContext(context));
|
|
921
|
+
},
|
|
922
|
+
onError: ({ error, ...context }) =>
|
|
923
|
+
notifyError(hooks, error, "create", hookContext(context)),
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
const updateForm = defineOperation({
|
|
927
|
+
input: UpdateFormOperationInputSchema,
|
|
928
|
+
permission: formBuilderPermissions.form.update,
|
|
929
|
+
facts: async ({ input }) => {
|
|
930
|
+
const form = await findFormById(adapter, input.id);
|
|
931
|
+
if (!form) throw formNotFoundError();
|
|
932
|
+
formSnapshots.set(input as object, snapshotForm(form));
|
|
933
|
+
return resolvedFormFacts(form);
|
|
934
|
+
},
|
|
935
|
+
execute: async (context) => {
|
|
936
|
+
const authorized = formSnapshots.get(context.input as object);
|
|
937
|
+
if (!authorized) throw staleFormError();
|
|
938
|
+
requireAtomicTransactions(adapter);
|
|
939
|
+
const initial: FormUpdate = {
|
|
940
|
+
...context.input.data,
|
|
941
|
+
...(context.input.data.slug !== undefined
|
|
942
|
+
? { slug: sanitizeSlug(context.input.data.slug) }
|
|
943
|
+
: {}),
|
|
944
|
+
};
|
|
945
|
+
if (initial.schema !== undefined) assertValidJsonSchema(initial.schema);
|
|
946
|
+
|
|
947
|
+
return adapter.transaction(async (tx) => {
|
|
948
|
+
const latest = await findFormById(tx, context.input.id);
|
|
949
|
+
if (!sameFormSnapshot(latest, authorized)) throw staleFormError();
|
|
950
|
+
const claimedAt = await claimFormSnapshot(
|
|
951
|
+
tx,
|
|
952
|
+
authorized,
|
|
953
|
+
staleFormError,
|
|
954
|
+
);
|
|
955
|
+
const modified = await runDomainHook(
|
|
956
|
+
async () =>
|
|
957
|
+
(await hooks?.onBeforeUpdateForm?.(
|
|
958
|
+
context.input.id,
|
|
959
|
+
initial,
|
|
960
|
+
hookContext(context),
|
|
961
|
+
)) ?? initial,
|
|
962
|
+
403,
|
|
963
|
+
"UPDATE_FORM_REJECTED",
|
|
964
|
+
);
|
|
965
|
+
const validation = updateFormSchema.safeParse(modified);
|
|
966
|
+
if (!validation.success) {
|
|
967
|
+
throw new FormBuilderOperationError(
|
|
968
|
+
400,
|
|
969
|
+
"Invalid form data",
|
|
970
|
+
"FORM_VALIDATION_FAILED",
|
|
971
|
+
validation.error.issues,
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
const update: FormUpdate = {
|
|
975
|
+
...validation.data,
|
|
976
|
+
...(validation.data.slug !== undefined
|
|
977
|
+
? { slug: sanitizeSlug(validation.data.slug) }
|
|
978
|
+
: {}),
|
|
979
|
+
};
|
|
980
|
+
if (update.schema !== undefined) assertValidJsonSchema(update.schema);
|
|
981
|
+
const claimed = await findFormById(tx, authorized.id);
|
|
982
|
+
if (
|
|
983
|
+
!sameFormSnapshot(claimed, { ...authorized, updatedAt: claimedAt })
|
|
984
|
+
) {
|
|
985
|
+
throw staleFormError();
|
|
986
|
+
}
|
|
987
|
+
if (update.slug && update.slug !== latest?.slug) {
|
|
988
|
+
const duplicate = await findFormBySlug(tx, update.slug);
|
|
989
|
+
if (duplicate) throw duplicateSlugError();
|
|
990
|
+
}
|
|
991
|
+
const updateData: Partial<Form> = {
|
|
992
|
+
updatedAt: nextSnapshotDate(claimedAt),
|
|
993
|
+
};
|
|
994
|
+
if (update.name !== undefined) updateData.name = update.name;
|
|
995
|
+
if (update.slug !== undefined) updateData.slug = update.slug;
|
|
996
|
+
if (update.description !== undefined)
|
|
997
|
+
updateData.description = update.description;
|
|
998
|
+
if (update.schema !== undefined) updateData.schema = update.schema;
|
|
999
|
+
if (update.successMessage !== undefined)
|
|
1000
|
+
updateData.successMessage = update.successMessage;
|
|
1001
|
+
if (update.redirectUrl !== undefined)
|
|
1002
|
+
updateData.redirectUrl = update.redirectUrl;
|
|
1003
|
+
if (update.status !== undefined) updateData.status = update.status;
|
|
1004
|
+
const matched = await tx.updateMany({
|
|
1005
|
+
model: "form",
|
|
1006
|
+
where: formSnapshotWhere({ ...authorized, updatedAt: claimedAt }),
|
|
1007
|
+
update: updateData,
|
|
1008
|
+
});
|
|
1009
|
+
if (!didAffectRow(matched, authorized.id)) throw staleFormError();
|
|
1010
|
+
const updated = await findFormById(tx, context.input.id);
|
|
1011
|
+
if (!updated) throw formNotFoundError();
|
|
1012
|
+
return operationForm(updated);
|
|
1013
|
+
});
|
|
1014
|
+
},
|
|
1015
|
+
after: async (context) => {
|
|
1016
|
+
await hooks?.onAfterUpdateForm?.(context.result, hookContext(context));
|
|
1017
|
+
},
|
|
1018
|
+
onError: ({ error, ...context }) =>
|
|
1019
|
+
notifyError(hooks, error, "update", hookContext(context)),
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
const deleteForm = defineOperation({
|
|
1023
|
+
input: DeleteFormOperationInputSchema,
|
|
1024
|
+
permission: formBuilderPermissions.form.delete,
|
|
1025
|
+
facts: async ({ input }) => {
|
|
1026
|
+
const form = await findFormById(adapter, input.id);
|
|
1027
|
+
if (!form) throw formNotFoundError();
|
|
1028
|
+
formSnapshots.set(input as object, snapshotForm(form));
|
|
1029
|
+
return resolvedFormFacts(form);
|
|
1030
|
+
},
|
|
1031
|
+
execute: async (context) => {
|
|
1032
|
+
const authorized = formSnapshots.get(context.input as object);
|
|
1033
|
+
if (!authorized) throw staleFormError();
|
|
1034
|
+
requireAtomicTransactions(adapter);
|
|
1035
|
+
return adapter.transaction(async (tx) => {
|
|
1036
|
+
const current = await findFormById(tx, context.input.id);
|
|
1037
|
+
if (!sameFormSnapshot(current, authorized)) throw staleFormError();
|
|
1038
|
+
const claimedAt = await claimFormSnapshot(
|
|
1039
|
+
tx,
|
|
1040
|
+
authorized,
|
|
1041
|
+
staleFormError,
|
|
1042
|
+
);
|
|
1043
|
+
await runDomainHook(
|
|
1044
|
+
() =>
|
|
1045
|
+
hooks?.onBeforeDeleteForm?.(context.input.id, hookContext(context)),
|
|
1046
|
+
403,
|
|
1047
|
+
"DELETE_FORM_REJECTED",
|
|
1048
|
+
);
|
|
1049
|
+
const claimed = await findFormById(tx, authorized.id);
|
|
1050
|
+
if (
|
|
1051
|
+
!sameFormSnapshot(claimed, { ...authorized, updatedAt: claimedAt })
|
|
1052
|
+
) {
|
|
1053
|
+
throw staleFormError();
|
|
1054
|
+
}
|
|
1055
|
+
await tx.deleteMany({
|
|
1056
|
+
model: "formSubmission",
|
|
1057
|
+
where: [
|
|
1058
|
+
{
|
|
1059
|
+
field: "formId",
|
|
1060
|
+
value: context.input.id,
|
|
1061
|
+
operator: "eq" as const,
|
|
1062
|
+
},
|
|
1063
|
+
],
|
|
1064
|
+
});
|
|
1065
|
+
const deleted = await tx.deleteMany({
|
|
1066
|
+
model: "form",
|
|
1067
|
+
where: [
|
|
1068
|
+
{ field: "id", value: authorized.id, operator: "eq" as const },
|
|
1069
|
+
{ field: "updatedAt", value: claimedAt, operator: "eq" as const },
|
|
1070
|
+
],
|
|
1071
|
+
});
|
|
1072
|
+
if (deleted !== 1) throw staleFormError();
|
|
1073
|
+
return { success: true } as const;
|
|
1074
|
+
});
|
|
1075
|
+
},
|
|
1076
|
+
after: async (context) => {
|
|
1077
|
+
await hooks?.onAfterDeleteForm?.(context.input.id, hookContext(context));
|
|
1078
|
+
},
|
|
1079
|
+
onError: ({ error, ...context }) =>
|
|
1080
|
+
notifyError(hooks, error, "delete", hookContext(context)),
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1083
|
+
const submitForm = defineOperation({
|
|
1084
|
+
input: SubmitFormOperationInputSchema,
|
|
1085
|
+
permission: formBuilderPermissions.submission.create,
|
|
1086
|
+
facts: async ({ input }) => {
|
|
1087
|
+
const form = await findFormBySlug(adapter, input.slug);
|
|
1088
|
+
formSnapshots.set(input as object, form ? snapshotForm(form) : null);
|
|
1089
|
+
return {
|
|
1090
|
+
slug: input.slug,
|
|
1091
|
+
exists: form !== null,
|
|
1092
|
+
...(form
|
|
1093
|
+
? {
|
|
1094
|
+
formId: form.id,
|
|
1095
|
+
...(form.createdBy ? { ownerId: form.createdBy } : {}),
|
|
1096
|
+
status: form.status,
|
|
1097
|
+
}
|
|
1098
|
+
: {}),
|
|
1099
|
+
} satisfies SubmissionCreateFacts;
|
|
1100
|
+
},
|
|
1101
|
+
execute: async (context) => {
|
|
1102
|
+
const authorized = formSnapshots.get(context.input as object) ?? null;
|
|
1103
|
+
const form = await findFormBySlug(adapter, context.input.slug);
|
|
1104
|
+
if (!sameFormSnapshot(form, authorized)) throw staleFormError();
|
|
1105
|
+
if (!form) throw formNotFoundError();
|
|
1106
|
+
if (!authorized) throw staleFormError();
|
|
1107
|
+
requireAtomicTransactions(adapter);
|
|
1108
|
+
if (form.status !== "active") {
|
|
1109
|
+
throw new FormBuilderOperationError(
|
|
1110
|
+
400,
|
|
1111
|
+
"Form is not accepting submissions",
|
|
1112
|
+
"FORM_NOT_ACTIVE",
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
try {
|
|
1117
|
+
const jsonSchema = JSON.parse(form.schema);
|
|
1118
|
+
const validation = formSchemaToZod(jsonSchema).safeParse(
|
|
1119
|
+
context.input.data,
|
|
1120
|
+
);
|
|
1121
|
+
if (!validation.success) {
|
|
1122
|
+
throw new FormBuilderOperationError(
|
|
1123
|
+
400,
|
|
1124
|
+
"Validation failed",
|
|
1125
|
+
"SUBMISSION_VALIDATION_FAILED",
|
|
1126
|
+
validation.error.issues,
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
} catch (error) {
|
|
1130
|
+
if (error instanceof FormBuilderOperationError) throw error;
|
|
1131
|
+
throw new FormBuilderOperationError(
|
|
1132
|
+
400,
|
|
1133
|
+
"Invalid form data",
|
|
1134
|
+
"INVALID_FORM_DATA",
|
|
1135
|
+
);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
const lifecycleContext = submissionHookContext(
|
|
1139
|
+
context,
|
|
1140
|
+
form.slug,
|
|
1141
|
+
form.id,
|
|
1142
|
+
);
|
|
1143
|
+
const submittedData = JSON.parse(
|
|
1144
|
+
JSON.stringify(context.input.data),
|
|
1145
|
+
) as Record<string, unknown>;
|
|
1146
|
+
return adapter.transaction(async (tx) => {
|
|
1147
|
+
const current = await findFormBySlug(tx, context.input.slug);
|
|
1148
|
+
if (!sameFormSnapshot(current, authorized)) throw staleFormError();
|
|
1149
|
+
if (!current || current.status !== "active") throw staleFormError();
|
|
1150
|
+
const claimedAt = await claimFormSnapshot(
|
|
1151
|
+
tx,
|
|
1152
|
+
authorized,
|
|
1153
|
+
staleFormError,
|
|
1154
|
+
);
|
|
1155
|
+
const hookResult = await runDomainHook<Record<string, unknown> | void>(
|
|
1156
|
+
() =>
|
|
1157
|
+
hooks?.onBeforeSubmission?.(
|
|
1158
|
+
form.slug,
|
|
1159
|
+
submittedData,
|
|
1160
|
+
lifecycleContext,
|
|
1161
|
+
),
|
|
1162
|
+
400,
|
|
1163
|
+
"SUBMISSION_REJECTED",
|
|
1164
|
+
);
|
|
1165
|
+
const finalData = hookResult ?? submittedData;
|
|
1166
|
+
const claimed = await findFormById(tx, authorized.id);
|
|
1167
|
+
if (
|
|
1168
|
+
!sameFormSnapshot(claimed, { ...authorized, updatedAt: claimedAt }) ||
|
|
1169
|
+
claimed?.status !== "active"
|
|
1170
|
+
) {
|
|
1171
|
+
throw staleFormError();
|
|
1172
|
+
}
|
|
1173
|
+
const submission = await tx.create<FormSubmission>({
|
|
1174
|
+
model: "formSubmission",
|
|
1175
|
+
data: {
|
|
1176
|
+
formId: current.id,
|
|
1177
|
+
data: JSON.stringify(finalData),
|
|
1178
|
+
submittedAt: new Date(),
|
|
1179
|
+
...(context.identity ? { submittedBy: context.identity.id } : {}),
|
|
1180
|
+
...(lifecycleContext.ipAddress
|
|
1181
|
+
? { ipAddress: lifecycleContext.ipAddress }
|
|
1182
|
+
: {}),
|
|
1183
|
+
...(lifecycleContext.userAgent
|
|
1184
|
+
? { userAgent: lifecycleContext.userAgent }
|
|
1185
|
+
: {}),
|
|
1186
|
+
},
|
|
1187
|
+
});
|
|
1188
|
+
await restoreFormSnapshot(tx, authorized, claimedAt, staleFormError);
|
|
1189
|
+
const serialized = serializeFormSubmission(submission);
|
|
1190
|
+
const result = {
|
|
1191
|
+
...serialized,
|
|
1192
|
+
form: {
|
|
1193
|
+
successMessage: current.successMessage,
|
|
1194
|
+
redirectUrl: current.redirectUrl,
|
|
1195
|
+
},
|
|
1196
|
+
};
|
|
1197
|
+
submittedFormSnapshots.set(result, serializeForm(current));
|
|
1198
|
+
return result;
|
|
1199
|
+
});
|
|
1200
|
+
},
|
|
1201
|
+
after: async (context) => {
|
|
1202
|
+
const form = submittedFormSnapshots.get(context.result as object);
|
|
1203
|
+
if (!form) {
|
|
1204
|
+
throw new FormBuilderOperationError(
|
|
1205
|
+
500,
|
|
1206
|
+
"Submission lifecycle state is unavailable",
|
|
1207
|
+
"SUBMISSION_LIFECYCLE_STATE_MISSING",
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
await hooks?.onAfterSubmission?.(
|
|
1211
|
+
context.result,
|
|
1212
|
+
form,
|
|
1213
|
+
submissionHookContext<
|
|
1214
|
+
z.infer<typeof SubmitFormOperationInputSchema>,
|
|
1215
|
+
SubmissionCreateFacts
|
|
1216
|
+
>(context, form.slug, form.id),
|
|
1217
|
+
);
|
|
1218
|
+
},
|
|
1219
|
+
onError: async ({ error, ...context }) => {
|
|
1220
|
+
const facts = context.facts as DeepReadonly<SubmissionCreateFacts>;
|
|
1221
|
+
const formId = facts.formId ?? "";
|
|
1222
|
+
const lifecycleContext = submissionHookContext<
|
|
1223
|
+
z.infer<typeof SubmitFormOperationInputSchema>,
|
|
1224
|
+
SubmissionCreateFacts
|
|
1225
|
+
>(context, context.input.slug, formId);
|
|
1226
|
+
try {
|
|
1227
|
+
await hooks?.onErrorSubmission?.(
|
|
1228
|
+
normalizeError(error, "Submission failed."),
|
|
1229
|
+
context.input.slug,
|
|
1230
|
+
JSON.parse(JSON.stringify(context.input.data)) as Record<
|
|
1231
|
+
string,
|
|
1232
|
+
unknown
|
|
1233
|
+
>,
|
|
1234
|
+
lifecycleContext,
|
|
1235
|
+
);
|
|
1236
|
+
} catch {
|
|
1237
|
+
// Observational error hook.
|
|
1238
|
+
}
|
|
1239
|
+
await notifyError(hooks, error, "submit", lifecycleContext);
|
|
1240
|
+
},
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
const listSubmissions = defineOperation({
|
|
1244
|
+
input: ListSubmissionsOperationInputSchema,
|
|
1245
|
+
permission: formBuilderPermissions.submission.read,
|
|
1246
|
+
facts: async ({ input }) => {
|
|
1247
|
+
const form = await findFormById(adapter, input.formId);
|
|
1248
|
+
formSnapshots.set(input as object, form ? snapshotForm(form) : null);
|
|
1249
|
+
return {
|
|
1250
|
+
scope: "collection" as const,
|
|
1251
|
+
formId: input.formId,
|
|
1252
|
+
formExists: form !== null,
|
|
1253
|
+
...(form?.createdBy ? { ownerId: form.createdBy } : {}),
|
|
1254
|
+
};
|
|
1255
|
+
},
|
|
1256
|
+
before: async (context) => {
|
|
1257
|
+
const expected = formSnapshots.get(context.input as object) ?? null;
|
|
1258
|
+
const current = await findFormById(adapter, context.input.formId);
|
|
1259
|
+
if (!sameFormSnapshot(current, expected)) throw staleFormError();
|
|
1260
|
+
if (!current) throw formNotFoundError();
|
|
1261
|
+
await runDomainHook(
|
|
1262
|
+
() =>
|
|
1263
|
+
hooks?.onBeforeListSubmissions?.(
|
|
1264
|
+
context.input.formId,
|
|
1265
|
+
hookContext(context),
|
|
1266
|
+
),
|
|
1267
|
+
403,
|
|
1268
|
+
"LIST_SUBMISSIONS_REJECTED",
|
|
1269
|
+
);
|
|
1270
|
+
},
|
|
1271
|
+
execute: async (context) => {
|
|
1272
|
+
const expected = formSnapshots.get(context.input as object) ?? null;
|
|
1273
|
+
return adapter.transaction(async (tx) => {
|
|
1274
|
+
const before = await findFormById(tx, context.input.formId);
|
|
1275
|
+
if (!sameFormSnapshot(before, expected)) throw staleFormError();
|
|
1276
|
+
if (!before) throw formNotFoundError();
|
|
1277
|
+
const result = await getFormSubmissions(
|
|
1278
|
+
tx,
|
|
1279
|
+
context.input.formId,
|
|
1280
|
+
context.input.query,
|
|
1281
|
+
);
|
|
1282
|
+
const after = await findFormById(tx, context.input.formId);
|
|
1283
|
+
if (!sameFormSnapshot(after, expected)) throw staleFormError();
|
|
1284
|
+
if (!after) throw formNotFoundError();
|
|
1285
|
+
return {
|
|
1286
|
+
form: operationSubmissionFormContext(after),
|
|
1287
|
+
...operationSubmissionsResult(result),
|
|
1288
|
+
};
|
|
1289
|
+
});
|
|
1290
|
+
},
|
|
1291
|
+
onError: ({ error, ...context }) =>
|
|
1292
|
+
notifyError(hooks, error, "listSubmissions", hookContext(context)),
|
|
1293
|
+
});
|
|
1294
|
+
|
|
1295
|
+
const getSubmission = defineOperation({
|
|
1296
|
+
input: GetSubmissionOperationInputSchema,
|
|
1297
|
+
permission: formBuilderPermissions.submission.read,
|
|
1298
|
+
facts: async ({ input }) => {
|
|
1299
|
+
const [form, submission] = await Promise.all([
|
|
1300
|
+
findFormById(adapter, input.formId),
|
|
1301
|
+
findSubmission(adapter, input.submissionId),
|
|
1302
|
+
]);
|
|
1303
|
+
const matches = form && submission?.formId === form.id;
|
|
1304
|
+
submissionSnapshots.set(
|
|
1305
|
+
input as object,
|
|
1306
|
+
matches
|
|
1307
|
+
? {
|
|
1308
|
+
form: snapshotForm(form),
|
|
1309
|
+
submission: snapshotSubmission(submission),
|
|
1310
|
+
}
|
|
1311
|
+
: null,
|
|
1312
|
+
);
|
|
1313
|
+
return submissionRecordFacts(
|
|
1314
|
+
input.formId,
|
|
1315
|
+
input.submissionId,
|
|
1316
|
+
form,
|
|
1317
|
+
submission,
|
|
1318
|
+
);
|
|
1319
|
+
},
|
|
1320
|
+
before: async (context) => {
|
|
1321
|
+
const snapshot = submissionSnapshots.get(context.input as object);
|
|
1322
|
+
if (!snapshot) throw submissionNotFoundError();
|
|
1323
|
+
const [form, submission] = await Promise.all([
|
|
1324
|
+
findFormById(adapter, context.input.formId),
|
|
1325
|
+
findSubmission(adapter, context.input.submissionId),
|
|
1326
|
+
]);
|
|
1327
|
+
if (
|
|
1328
|
+
!sameFormSnapshot(form, snapshot.form) ||
|
|
1329
|
+
!sameSubmissionSnapshot(submission, snapshot.submission)
|
|
1330
|
+
) {
|
|
1331
|
+
throw staleSubmissionError();
|
|
1332
|
+
}
|
|
1333
|
+
await runDomainHook(
|
|
1334
|
+
() =>
|
|
1335
|
+
hooks?.onBeforeGetSubmission?.(
|
|
1336
|
+
context.input.submissionId,
|
|
1337
|
+
hookContext(context),
|
|
1338
|
+
),
|
|
1339
|
+
403,
|
|
1340
|
+
"GET_SUBMISSION_REJECTED",
|
|
1341
|
+
);
|
|
1342
|
+
},
|
|
1343
|
+
execute: async (context) => {
|
|
1344
|
+
const snapshot = submissionSnapshots.get(context.input as object);
|
|
1345
|
+
if (!snapshot) throw submissionNotFoundError();
|
|
1346
|
+
const submission = await adapter.findOne<FormSubmissionWithForm>({
|
|
1347
|
+
model: "formSubmission",
|
|
1348
|
+
where: [
|
|
1349
|
+
{
|
|
1350
|
+
field: "id",
|
|
1351
|
+
value: context.input.submissionId,
|
|
1352
|
+
operator: "eq" as const,
|
|
1353
|
+
},
|
|
1354
|
+
],
|
|
1355
|
+
join: { form: true },
|
|
1356
|
+
});
|
|
1357
|
+
if (
|
|
1358
|
+
!submission ||
|
|
1359
|
+
submission.formId !== context.input.formId ||
|
|
1360
|
+
!sameSubmissionSnapshot(submission, snapshot.submission) ||
|
|
1361
|
+
!sameFormSnapshot(submission.form ?? null, snapshot.form)
|
|
1362
|
+
) {
|
|
1363
|
+
throw staleSubmissionError();
|
|
1364
|
+
}
|
|
1365
|
+
return operationSubmissionWithData(submission);
|
|
1366
|
+
},
|
|
1367
|
+
onError: ({ error, ...context }) =>
|
|
1368
|
+
notifyError(hooks, error, "getSubmission", hookContext(context)),
|
|
1369
|
+
});
|
|
1370
|
+
|
|
1371
|
+
const deleteSubmission = defineOperation({
|
|
1372
|
+
input: GetSubmissionOperationInputSchema,
|
|
1373
|
+
permission: formBuilderPermissions.submission.delete,
|
|
1374
|
+
facts: async ({ input }) => {
|
|
1375
|
+
const [form, submission] = await Promise.all([
|
|
1376
|
+
findFormById(adapter, input.formId),
|
|
1377
|
+
findSubmission(adapter, input.submissionId),
|
|
1378
|
+
]);
|
|
1379
|
+
if (!form || !submission || submission.formId !== form.id) {
|
|
1380
|
+
throw submissionNotFoundError();
|
|
1381
|
+
}
|
|
1382
|
+
submissionSnapshots.set(input as object, {
|
|
1383
|
+
form: snapshotForm(form),
|
|
1384
|
+
submission: snapshotSubmission(submission),
|
|
1385
|
+
});
|
|
1386
|
+
return {
|
|
1387
|
+
formId: form.id,
|
|
1388
|
+
submissionId: submission.id,
|
|
1389
|
+
exists: true,
|
|
1390
|
+
...(form.createdBy ? { ownerId: form.createdBy } : {}),
|
|
1391
|
+
...(submission.submittedBy
|
|
1392
|
+
? { submittedBy: submission.submittedBy }
|
|
1393
|
+
: {}),
|
|
1394
|
+
} satisfies SubmissionDeleteFacts;
|
|
1395
|
+
},
|
|
1396
|
+
execute: async (context) => {
|
|
1397
|
+
const snapshot = submissionSnapshots.get(context.input as object);
|
|
1398
|
+
if (!snapshot) throw staleSubmissionError();
|
|
1399
|
+
requireAtomicTransactions(adapter);
|
|
1400
|
+
return adapter.transaction(async (tx) => {
|
|
1401
|
+
const [form, submission] = await Promise.all([
|
|
1402
|
+
findFormById(tx, context.input.formId),
|
|
1403
|
+
findSubmission(tx, context.input.submissionId),
|
|
1404
|
+
]);
|
|
1405
|
+
if (
|
|
1406
|
+
!sameFormSnapshot(form, snapshot.form) ||
|
|
1407
|
+
!sameSubmissionSnapshot(submission, snapshot.submission)
|
|
1408
|
+
) {
|
|
1409
|
+
throw staleSubmissionError();
|
|
1410
|
+
}
|
|
1411
|
+
const claimedAt = await claimFormSnapshot(
|
|
1412
|
+
tx,
|
|
1413
|
+
snapshot.form,
|
|
1414
|
+
staleSubmissionError,
|
|
1415
|
+
);
|
|
1416
|
+
const claimedSubmissionAt = await claimSubmissionSnapshot(
|
|
1417
|
+
tx,
|
|
1418
|
+
snapshot.submission,
|
|
1419
|
+
);
|
|
1420
|
+
await runDomainHook(
|
|
1421
|
+
() =>
|
|
1422
|
+
hooks?.onBeforeDeleteSubmission?.(
|
|
1423
|
+
context.input.submissionId,
|
|
1424
|
+
hookContext(context),
|
|
1425
|
+
),
|
|
1426
|
+
403,
|
|
1427
|
+
"DELETE_SUBMISSION_REJECTED",
|
|
1428
|
+
);
|
|
1429
|
+
const [claimedForm, claimedSubmission] = await Promise.all([
|
|
1430
|
+
findFormById(tx, snapshot.form.id),
|
|
1431
|
+
findSubmission(tx, snapshot.submission.id),
|
|
1432
|
+
]);
|
|
1433
|
+
if (
|
|
1434
|
+
!sameFormSnapshot(claimedForm, {
|
|
1435
|
+
...snapshot.form,
|
|
1436
|
+
updatedAt: claimedAt,
|
|
1437
|
+
}) ||
|
|
1438
|
+
!sameSubmissionSnapshot(claimedSubmission, {
|
|
1439
|
+
...snapshot.submission,
|
|
1440
|
+
submittedAt: claimedSubmissionAt,
|
|
1441
|
+
})
|
|
1442
|
+
) {
|
|
1443
|
+
throw staleSubmissionError();
|
|
1444
|
+
}
|
|
1445
|
+
const deleted = await tx.deleteMany({
|
|
1446
|
+
model: "formSubmission",
|
|
1447
|
+
where: [
|
|
1448
|
+
{
|
|
1449
|
+
field: "id",
|
|
1450
|
+
value: context.input.submissionId,
|
|
1451
|
+
operator: "eq" as const,
|
|
1452
|
+
},
|
|
1453
|
+
{
|
|
1454
|
+
field: "submittedAt",
|
|
1455
|
+
value: claimedSubmissionAt,
|
|
1456
|
+
operator: "eq" as const,
|
|
1457
|
+
},
|
|
1458
|
+
],
|
|
1459
|
+
});
|
|
1460
|
+
if (deleted !== 1) throw staleSubmissionError();
|
|
1461
|
+
await restoreFormSnapshot(
|
|
1462
|
+
tx,
|
|
1463
|
+
snapshot.form,
|
|
1464
|
+
claimedAt,
|
|
1465
|
+
staleSubmissionError,
|
|
1466
|
+
);
|
|
1467
|
+
return { success: true } as const;
|
|
1468
|
+
});
|
|
1469
|
+
},
|
|
1470
|
+
after: async (context) => {
|
|
1471
|
+
await hooks?.onAfterDeleteSubmission?.(
|
|
1472
|
+
context.input.submissionId,
|
|
1473
|
+
hookContext(context),
|
|
1474
|
+
);
|
|
1475
|
+
},
|
|
1476
|
+
onError: ({ error, ...context }) =>
|
|
1477
|
+
notifyError(hooks, error, "deleteSubmission", hookContext(context)),
|
|
1478
|
+
});
|
|
1479
|
+
|
|
1480
|
+
return {
|
|
1481
|
+
listForms,
|
|
1482
|
+
getFormBySlug,
|
|
1483
|
+
getFormById,
|
|
1484
|
+
getFormForUpdate,
|
|
1485
|
+
createForm,
|
|
1486
|
+
updateForm,
|
|
1487
|
+
deleteForm,
|
|
1488
|
+
submitForm,
|
|
1489
|
+
listSubmissions,
|
|
1490
|
+
getSubmission,
|
|
1491
|
+
deleteSubmission,
|
|
1492
|
+
} as const;
|
|
1493
|
+
}
|