@btst/stack 3.0.0-rc.2 → 3.0.0-rc.3

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