@open-mercato/documents 0.6.8-develop.7016.1.4ed7b1e49d

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 (602) hide show
  1. package/README.md +88 -0
  2. package/build.mjs +23 -0
  3. package/dist/index.js +5 -0
  4. package/dist/index.js.map +7 -0
  5. package/dist/modules/documents/acl.js +15 -0
  6. package/dist/modules/documents/acl.js.map +7 -0
  7. package/dist/modules/documents/api/[id]/archive/route.js +116 -0
  8. package/dist/modules/documents/api/[id]/archive/route.js.map +7 -0
  9. package/dist/modules/documents/api/[id]/attachments/[attachmentId]/route.js +155 -0
  10. package/dist/modules/documents/api/[id]/attachments/[attachmentId]/route.js.map +7 -0
  11. package/dist/modules/documents/api/[id]/attachments/route.js +153 -0
  12. package/dist/modules/documents/api/[id]/attachments/route.js.map +7 -0
  13. package/dist/modules/documents/api/[id]/collab-token/route.js +180 -0
  14. package/dist/modules/documents/api/[id]/collab-token/route.js.map +7 -0
  15. package/dist/modules/documents/api/[id]/comments/access-check/route.js +86 -0
  16. package/dist/modules/documents/api/[id]/comments/access-check/route.js.map +7 -0
  17. package/dist/modules/documents/api/[id]/comments/route.js +387 -0
  18. package/dist/modules/documents/api/[id]/comments/route.js.map +7 -0
  19. package/dist/modules/documents/api/[id]/content/route.js +143 -0
  20. package/dist/modules/documents/api/[id]/content/route.js.map +7 -0
  21. package/dist/modules/documents/api/[id]/duplicate/route.js +200 -0
  22. package/dist/modules/documents/api/[id]/duplicate/route.js.map +7 -0
  23. package/dist/modules/documents/api/[id]/export/route.js +421 -0
  24. package/dist/modules/documents/api/[id]/export/route.js.map +7 -0
  25. package/dist/modules/documents/api/[id]/favorite/route.js +96 -0
  26. package/dist/modules/documents/api/[id]/favorite/route.js.map +7 -0
  27. package/dist/modules/documents/api/[id]/links/[linkId]/route.js +85 -0
  28. package/dist/modules/documents/api/[id]/links/[linkId]/route.js.map +7 -0
  29. package/dist/modules/documents/api/[id]/links/route.js +257 -0
  30. package/dist/modules/documents/api/[id]/links/route.js.map +7 -0
  31. package/dist/modules/documents/api/[id]/principals/route.js +299 -0
  32. package/dist/modules/documents/api/[id]/principals/route.js.map +7 -0
  33. package/dist/modules/documents/api/[id]/route.js +246 -0
  34. package/dist/modules/documents/api/[id]/route.js.map +7 -0
  35. package/dist/modules/documents/api/[id]/shares/route.js +335 -0
  36. package/dist/modules/documents/api/[id]/shares/route.js.map +7 -0
  37. package/dist/modules/documents/api/[id]/unarchive/route.js +39 -0
  38. package/dist/modules/documents/api/[id]/unarchive/route.js.map +7 -0
  39. package/dist/modules/documents/api/[id]/versions/[versionId]/restore/route.js +133 -0
  40. package/dist/modules/documents/api/[id]/versions/[versionId]/restore/route.js.map +7 -0
  41. package/dist/modules/documents/api/[id]/versions/[versionId]/route.js +93 -0
  42. package/dist/modules/documents/api/[id]/versions/[versionId]/route.js.map +7 -0
  43. package/dist/modules/documents/api/[id]/versions/route.js +193 -0
  44. package/dist/modules/documents/api/[id]/versions/route.js.map +7 -0
  45. package/dist/modules/documents/api/[id]/watch/route.js +97 -0
  46. package/dist/modules/documents/api/[id]/watch/route.js.map +7 -0
  47. package/dist/modules/documents/api/_commands.js +34 -0
  48. package/dist/modules/documents/api/_commands.js.map +7 -0
  49. package/dist/modules/documents/api/_shared.js +490 -0
  50. package/dist/modules/documents/api/_shared.js.map +7 -0
  51. package/dist/modules/documents/api/folders/route.js +256 -0
  52. package/dist/modules/documents/api/folders/route.js.map +7 -0
  53. package/dist/modules/documents/api/instantiate/route.js +108 -0
  54. package/dist/modules/documents/api/instantiate/route.js.map +7 -0
  55. package/dist/modules/documents/api/route.js +322 -0
  56. package/dist/modules/documents/api/route.js.map +7 -0
  57. package/dist/modules/documents/api/templates/[templateId]/preview/route.js +94 -0
  58. package/dist/modules/documents/api/templates/[templateId]/preview/route.js.map +7 -0
  59. package/dist/modules/documents/api/templates/[templateId]/route.js +82 -0
  60. package/dist/modules/documents/api/templates/[templateId]/route.js.map +7 -0
  61. package/dist/modules/documents/api/templates/route.js +344 -0
  62. package/dist/modules/documents/api/templates/route.js.map +7 -0
  63. package/dist/modules/documents/backend/documents/DocumentsPageClient.js +160 -0
  64. package/dist/modules/documents/backend/documents/DocumentsPageClient.js.map +7 -0
  65. package/dist/modules/documents/backend/documents/DocumentsTable.js +143 -0
  66. package/dist/modules/documents/backend/documents/DocumentsTable.js.map +7 -0
  67. package/dist/modules/documents/backend/documents/FolderDialog.js +55 -0
  68. package/dist/modules/documents/backend/documents/FolderDialog.js.map +7 -0
  69. package/dist/modules/documents/backend/documents/FolderTree.js +40 -0
  70. package/dist/modules/documents/backend/documents/FolderTree.js.map +7 -0
  71. package/dist/modules/documents/backend/documents/MoveDocumentDialog.js +64 -0
  72. package/dist/modules/documents/backend/documents/MoveDocumentDialog.js.map +7 -0
  73. package/dist/modules/documents/backend/documents/[id]/CommentAnchorNavigation.js +77 -0
  74. package/dist/modules/documents/backend/documents/[id]/CommentAnchorNavigation.js.map +7 -0
  75. package/dist/modules/documents/backend/documents/[id]/CommentComposer.js +126 -0
  76. package/dist/modules/documents/backend/documents/[id]/CommentComposer.js.map +7 -0
  77. package/dist/modules/documents/backend/documents/[id]/CommentThreadList.js +88 -0
  78. package/dist/modules/documents/backend/documents/[id]/CommentThreadList.js.map +7 -0
  79. package/dist/modules/documents/backend/documents/[id]/CommentsRail.js +123 -0
  80. package/dist/modules/documents/backend/documents/[id]/CommentsRail.js.map +7 -0
  81. package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js +91 -0
  82. package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js.map +7 -0
  83. package/dist/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.js +27 -0
  84. package/dist/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.js.map +7 -0
  85. package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js +50 -0
  86. package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js.map +7 -0
  87. package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js +168 -0
  88. package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js.map +7 -0
  89. package/dist/modules/documents/backend/documents/[id]/DocumentNavigator.js +129 -0
  90. package/dist/modules/documents/backend/documents/[id]/DocumentNavigator.js.map +7 -0
  91. package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js +429 -0
  92. package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js.map +7 -0
  93. package/dist/modules/documents/backend/documents/[id]/EditorColorTools.js +68 -0
  94. package/dist/modules/documents/backend/documents/[id]/EditorColorTools.js.map +7 -0
  95. package/dist/modules/documents/backend/documents/[id]/EditorStatusPresence.js +69 -0
  96. package/dist/modules/documents/backend/documents/[id]/EditorStatusPresence.js.map +7 -0
  97. package/dist/modules/documents/backend/documents/[id]/EditorToolbar.js +151 -0
  98. package/dist/modules/documents/backend/documents/[id]/EditorToolbar.js.map +7 -0
  99. package/dist/modules/documents/backend/documents/[id]/ExportMenu.js +121 -0
  100. package/dist/modules/documents/backend/documents/[id]/ExportMenu.js.map +7 -0
  101. package/dist/modules/documents/backend/documents/[id]/MentionPicker.js +114 -0
  102. package/dist/modules/documents/backend/documents/[id]/MentionPicker.js.map +7 -0
  103. package/dist/modules/documents/backend/documents/[id]/OutlinePane.js +70 -0
  104. package/dist/modules/documents/backend/documents/[id]/OutlinePane.js.map +7 -0
  105. package/dist/modules/documents/backend/documents/[id]/RecordFieldsDialog.js +157 -0
  106. package/dist/modules/documents/backend/documents/[id]/RecordFieldsDialog.js.map +7 -0
  107. package/dist/modules/documents/backend/documents/[id]/RelatedRecordsPanel.js +266 -0
  108. package/dist/modules/documents/backend/documents/[id]/RelatedRecordsPanel.js.map +7 -0
  109. package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js +227 -0
  110. package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js.map +7 -0
  111. package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js +157 -0
  112. package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js.map +7 -0
  113. package/dist/modules/documents/backend/documents/[id]/commentTypes.js +150 -0
  114. package/dist/modules/documents/backend/documents/[id]/commentTypes.js.map +7 -0
  115. package/dist/modules/documents/backend/documents/[id]/componentCapabilities.js +13 -0
  116. package/dist/modules/documents/backend/documents/[id]/componentCapabilities.js.map +7 -0
  117. package/dist/modules/documents/backend/documents/[id]/documentPagination.js +295 -0
  118. package/dist/modules/documents/backend/documents/[id]/documentPagination.js.map +7 -0
  119. package/dist/modules/documents/backend/documents/[id]/editorPresenceStyles.js +81 -0
  120. package/dist/modules/documents/backend/documents/[id]/editorPresenceStyles.js.map +7 -0
  121. package/dist/modules/documents/backend/documents/[id]/editorTypes.js +52 -0
  122. package/dist/modules/documents/backend/documents/[id]/editorTypes.js.map +7 -0
  123. package/dist/modules/documents/backend/documents/[id]/page.js +10 -0
  124. package/dist/modules/documents/backend/documents/[id]/page.js.map +7 -0
  125. package/dist/modules/documents/backend/documents/[id]/page.meta.js +16 -0
  126. package/dist/modules/documents/backend/documents/[id]/page.meta.js.map +7 -0
  127. package/dist/modules/documents/backend/documents/[id]/relatedRecordModel.js +38 -0
  128. package/dist/modules/documents/backend/documents/[id]/relatedRecordModel.js.map +7 -0
  129. package/dist/modules/documents/backend/documents/[id]/restoreVersion.js +33 -0
  130. package/dist/modules/documents/backend/documents/[id]/restoreVersion.js.map +7 -0
  131. package/dist/modules/documents/backend/documents/[id]/useDocumentCollaboration.js +392 -0
  132. package/dist/modules/documents/backend/documents/[id]/useDocumentCollaboration.js.map +7 -0
  133. package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js +253 -0
  134. package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js.map +7 -0
  135. package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js +149 -0
  136. package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js.map +7 -0
  137. package/dist/modules/documents/backend/documents/[id]/useDocumentTitle.js +82 -0
  138. package/dist/modules/documents/backend/documents/[id]/useDocumentTitle.js.map +7 -0
  139. package/dist/modules/documents/backend/documents/[id]/useEditorInsertions.js +144 -0
  140. package/dist/modules/documents/backend/documents/[id]/useEditorInsertions.js.map +7 -0
  141. package/dist/modules/documents/backend/documents/[id]/useFallbackContentPersistence.js +237 -0
  142. package/dist/modules/documents/backend/documents/[id]/useFallbackContentPersistence.js.map +7 -0
  143. package/dist/modules/documents/backend/documents/[id]/useMentionPicker.js +216 -0
  144. package/dist/modules/documents/backend/documents/[id]/useMentionPicker.js.map +7 -0
  145. package/dist/modules/documents/backend/documents/[id]/versionHistoryModel.js +25 -0
  146. package/dist/modules/documents/backend/documents/[id]/versionHistoryModel.js.map +7 -0
  147. package/dist/modules/documents/backend/documents/components/EntityPicker.js +156 -0
  148. package/dist/modules/documents/backend/documents/components/EntityPicker.js.map +7 -0
  149. package/dist/modules/documents/backend/documents/components/EntityPickerResults.js +46 -0
  150. package/dist/modules/documents/backend/documents/components/EntityPickerResults.js.map +7 -0
  151. package/dist/modules/documents/backend/documents/components/NewFromTemplateDialog.js +127 -0
  152. package/dist/modules/documents/backend/documents/components/NewFromTemplateDialog.js.map +7 -0
  153. package/dist/modules/documents/backend/documents/components/PrincipalPicker.js +84 -0
  154. package/dist/modules/documents/backend/documents/components/PrincipalPicker.js.map +7 -0
  155. package/dist/modules/documents/backend/documents/components/ShareDialog.js +77 -0
  156. package/dist/modules/documents/backend/documents/components/ShareDialog.js.map +7 -0
  157. package/dist/modules/documents/backend/documents/components/ShareDialogAddForm.js +93 -0
  158. package/dist/modules/documents/backend/documents/components/ShareDialogAddForm.js.map +7 -0
  159. package/dist/modules/documents/backend/documents/components/ShareDialogList.js +82 -0
  160. package/dist/modules/documents/backend/documents/components/ShareDialogList.js.map +7 -0
  161. package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js +96 -0
  162. package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js.map +7 -0
  163. package/dist/modules/documents/backend/documents/components/TemplateEditorDialog.js +169 -0
  164. package/dist/modules/documents/backend/documents/components/TemplateEditorDialog.js.map +7 -0
  165. package/dist/modules/documents/backend/documents/components/TemplatePreview.js +38 -0
  166. package/dist/modules/documents/backend/documents/components/TemplatePreview.js.map +7 -0
  167. package/dist/modules/documents/backend/documents/components/TemplateSlotFields.js +69 -0
  168. package/dist/modules/documents/backend/documents/components/TemplateSlotFields.js.map +7 -0
  169. package/dist/modules/documents/backend/documents/components/TemplateSlotsEditor.js +71 -0
  170. package/dist/modules/documents/backend/documents/components/TemplateSlotsEditor.js.map +7 -0
  171. package/dist/modules/documents/backend/documents/components/principalPickerModel.js +63 -0
  172. package/dist/modules/documents/backend/documents/components/principalPickerModel.js.map +7 -0
  173. package/dist/modules/documents/backend/documents/components/shareDialogModel.js +68 -0
  174. package/dist/modules/documents/backend/documents/components/shareDialogModel.js.map +7 -0
  175. package/dist/modules/documents/backend/documents/components/templateUi.js +89 -0
  176. package/dist/modules/documents/backend/documents/components/templateUi.js.map +7 -0
  177. package/dist/modules/documents/backend/documents/components/useAvailableEntityRegistry.js +30 -0
  178. package/dist/modules/documents/backend/documents/components/useAvailableEntityRegistry.js.map +7 -0
  179. package/dist/modules/documents/backend/documents/components/useEntitySearch.js +191 -0
  180. package/dist/modules/documents/backend/documents/components/useEntitySearch.js.map +7 -0
  181. package/dist/modules/documents/backend/documents/components/usePrincipalPicker.js +221 -0
  182. package/dist/modules/documents/backend/documents/components/usePrincipalPicker.js.map +7 -0
  183. package/dist/modules/documents/backend/documents/components/useShareDialog.js +236 -0
  184. package/dist/modules/documents/backend/documents/components/useShareDialog.js.map +7 -0
  185. package/dist/modules/documents/backend/documents/components/useTemplateDetail.js +49 -0
  186. package/dist/modules/documents/backend/documents/components/useTemplateDetail.js.map +7 -0
  187. package/dist/modules/documents/backend/documents/components/useTemplateInstantiation.js +234 -0
  188. package/dist/modules/documents/backend/documents/components/useTemplateInstantiation.js.map +7 -0
  189. package/dist/modules/documents/backend/documents/documentUi.js +106 -0
  190. package/dist/modules/documents/backend/documents/documentUi.js.map +7 -0
  191. package/dist/modules/documents/backend/documents/documentsListTypes.js +132 -0
  192. package/dist/modules/documents/backend/documents/documentsListTypes.js.map +7 -0
  193. package/dist/modules/documents/backend/documents/page.js +9 -0
  194. package/dist/modules/documents/backend/documents/page.js.map +7 -0
  195. package/dist/modules/documents/backend/documents/page.meta.js +26 -0
  196. package/dist/modules/documents/backend/documents/page.meta.js.map +7 -0
  197. package/dist/modules/documents/backend/documents/templates/TemplatesPageClient.js +91 -0
  198. package/dist/modules/documents/backend/documents/templates/TemplatesPageClient.js.map +7 -0
  199. package/dist/modules/documents/backend/documents/templates/TemplatesTable.js +58 -0
  200. package/dist/modules/documents/backend/documents/templates/TemplatesTable.js.map +7 -0
  201. package/dist/modules/documents/backend/documents/templates/page.js +9 -0
  202. package/dist/modules/documents/backend/documents/templates/page.js.map +7 -0
  203. package/dist/modules/documents/backend/documents/templates/page.meta.js +34 -0
  204. package/dist/modules/documents/backend/documents/templates/page.meta.js.map +7 -0
  205. package/dist/modules/documents/backend/documents/templates/useTemplatesPage.js +139 -0
  206. package/dist/modules/documents/backend/documents/templates/useTemplatesPage.js.map +7 -0
  207. package/dist/modules/documents/backend/documents/useDocumentsList.js +314 -0
  208. package/dist/modules/documents/backend/documents/useDocumentsList.js.map +7 -0
  209. package/dist/modules/documents/ce.js +8 -0
  210. package/dist/modules/documents/ce.js.map +7 -0
  211. package/dist/modules/documents/commands/aggregate.js +99 -0
  212. package/dist/modules/documents/commands/aggregate.js.map +7 -0
  213. package/dist/modules/documents/commands/attachments.js +252 -0
  214. package/dist/modules/documents/commands/attachments.js.map +7 -0
  215. package/dist/modules/documents/commands/comments.js +782 -0
  216. package/dist/modules/documents/commands/comments.js.map +7 -0
  217. package/dist/modules/documents/commands/content.js +238 -0
  218. package/dist/modules/documents/commands/content.js.map +7 -0
  219. package/dist/modules/documents/commands/document-crud.js +505 -0
  220. package/dist/modules/documents/commands/document-crud.js.map +7 -0
  221. package/dist/modules/documents/commands/documents.js +473 -0
  222. package/dist/modules/documents/commands/documents.js.map +7 -0
  223. package/dist/modules/documents/commands/duplicate.js +640 -0
  224. package/dist/modules/documents/commands/duplicate.js.map +7 -0
  225. package/dist/modules/documents/commands/favorites.js +150 -0
  226. package/dist/modules/documents/commands/favorites.js.map +7 -0
  227. package/dist/modules/documents/commands/folders.js +420 -0
  228. package/dist/modules/documents/commands/folders.js.map +7 -0
  229. package/dist/modules/documents/commands/index.js +64 -0
  230. package/dist/modules/documents/commands/index.js.map +7 -0
  231. package/dist/modules/documents/commands/interceptors.js +300 -0
  232. package/dist/modules/documents/commands/interceptors.js.map +7 -0
  233. package/dist/modules/documents/commands/lifecycle.js +249 -0
  234. package/dist/modules/documents/commands/lifecycle.js.map +7 -0
  235. package/dist/modules/documents/commands/links.js +410 -0
  236. package/dist/modules/documents/commands/links.js.map +7 -0
  237. package/dist/modules/documents/commands/mutation-helpers.js +42 -0
  238. package/dist/modules/documents/commands/mutation-helpers.js.map +7 -0
  239. package/dist/modules/documents/commands/projection-types.js +1 -0
  240. package/dist/modules/documents/commands/projection-types.js.map +7 -0
  241. package/dist/modules/documents/commands/shared.js +143 -0
  242. package/dist/modules/documents/commands/shared.js.map +7 -0
  243. package/dist/modules/documents/commands/shares.js +527 -0
  244. package/dist/modules/documents/commands/shares.js.map +7 -0
  245. package/dist/modules/documents/commands/side-effects.js +103 -0
  246. package/dist/modules/documents/commands/side-effects.js.map +7 -0
  247. package/dist/modules/documents/commands/templates.js +461 -0
  248. package/dist/modules/documents/commands/templates.js.map +7 -0
  249. package/dist/modules/documents/commands/versions.js +432 -0
  250. package/dist/modules/documents/commands/versions.js.map +7 -0
  251. package/dist/modules/documents/commands/watchers.js +164 -0
  252. package/dist/modules/documents/commands/watchers.js.map +7 -0
  253. package/dist/modules/documents/data/entities.js +653 -0
  254. package/dist/modules/documents/data/entities.js.map +7 -0
  255. package/dist/modules/documents/data/extensions.js +44 -0
  256. package/dist/modules/documents/data/extensions.js.map +7 -0
  257. package/dist/modules/documents/data/validators.js +219 -0
  258. package/dist/modules/documents/data/validators.js.map +7 -0
  259. package/dist/modules/documents/di.js +35 -0
  260. package/dist/modules/documents/di.js.map +7 -0
  261. package/dist/modules/documents/encryption.js +12 -0
  262. package/dist/modules/documents/encryption.js.map +7 -0
  263. package/dist/modules/documents/events.js +27 -0
  264. package/dist/modules/documents/events.js.map +7 -0
  265. package/dist/modules/documents/index.js +19 -0
  266. package/dist/modules/documents/index.js.map +7 -0
  267. package/dist/modules/documents/lib/attachmentServicePort.js +30 -0
  268. package/dist/modules/documents/lib/attachmentServicePort.js.map +7 -0
  269. package/dist/modules/documents/lib/capabilities.js +32 -0
  270. package/dist/modules/documents/lib/capabilities.js.map +7 -0
  271. package/dist/modules/documents/lib/collabCloseEvents.js +17 -0
  272. package/dist/modules/documents/lib/collabCloseEvents.js.map +7 -0
  273. package/dist/modules/documents/lib/collabEndpoint.js +22 -0
  274. package/dist/modules/documents/lib/collabEndpoint.js.map +7 -0
  275. package/dist/modules/documents/lib/collabMaterializer.js +107 -0
  276. package/dist/modules/documents/lib/collabMaterializer.js.map +7 -0
  277. package/dist/modules/documents/lib/collabToken.js +120 -0
  278. package/dist/modules/documents/lib/collabToken.js.map +7 -0
  279. package/dist/modules/documents/lib/collaborationAwareness.js +68 -0
  280. package/dist/modules/documents/lib/collaborationAwareness.js.map +7 -0
  281. package/dist/modules/documents/lib/commentAnchors.js +15 -0
  282. package/dist/modules/documents/lib/commentAnchors.js.map +7 -0
  283. package/dist/modules/documents/lib/constants.js +25 -0
  284. package/dist/modules/documents/lib/constants.js.map +7 -0
  285. package/dist/modules/documents/lib/contentService.js +248 -0
  286. package/dist/modules/documents/lib/contentService.js.map +7 -0
  287. package/dist/modules/documents/lib/displayLabels.js +23 -0
  288. package/dist/modules/documents/lib/displayLabels.js.map +7 -0
  289. package/dist/modules/documents/lib/docxRenderer.js +601 -0
  290. package/dist/modules/documents/lib/docxRenderer.js.map +7 -0
  291. package/dist/modules/documents/lib/duplicateContent.js +22 -0
  292. package/dist/modules/documents/lib/duplicateContent.js.map +7 -0
  293. package/dist/modules/documents/lib/editorConfig.js +287 -0
  294. package/dist/modules/documents/lib/editorConfig.js.map +7 -0
  295. package/dist/modules/documents/lib/entityLinks.js +148 -0
  296. package/dist/modules/documents/lib/entityLinks.js.map +7 -0
  297. package/dist/modules/documents/lib/entityRegistry.js +258 -0
  298. package/dist/modules/documents/lib/entityRegistry.js.map +7 -0
  299. package/dist/modules/documents/lib/entityRegistry.server.js +189 -0
  300. package/dist/modules/documents/lib/entityRegistry.server.js.map +7 -0
  301. package/dist/modules/documents/lib/entityRegistryAvailability.server.js +9 -0
  302. package/dist/modules/documents/lib/entityRegistryAvailability.server.js.map +7 -0
  303. package/dist/modules/documents/lib/entitySuggestion.js +50 -0
  304. package/dist/modules/documents/lib/entitySuggestion.js.map +7 -0
  305. package/dist/modules/documents/lib/favorites.js +22 -0
  306. package/dist/modules/documents/lib/favorites.js.map +7 -0
  307. package/dist/modules/documents/lib/folderHierarchySerialization.js +19 -0
  308. package/dist/modules/documents/lib/folderHierarchySerialization.js.map +7 -0
  309. package/dist/modules/documents/lib/historyLimits.js +100 -0
  310. package/dist/modules/documents/lib/historyLimits.js.map +7 -0
  311. package/dist/modules/documents/lib/historyPolicy.js +14 -0
  312. package/dist/modules/documents/lib/historyPolicy.js.map +7 -0
  313. package/dist/modules/documents/lib/organizationAccess.js +17 -0
  314. package/dist/modules/documents/lib/organizationAccess.js.map +7 -0
  315. package/dist/modules/documents/lib/pdfHtml.js +62 -0
  316. package/dist/modules/documents/lib/pdfHtml.js.map +7 -0
  317. package/dist/modules/documents/lib/pdfRenderer.js +284 -0
  318. package/dist/modules/documents/lib/pdfRenderer.js.map +7 -0
  319. package/dist/modules/documents/lib/permissions.js +222 -0
  320. package/dist/modules/documents/lib/permissions.js.map +7 -0
  321. package/dist/modules/documents/lib/platformServices.js +35 -0
  322. package/dist/modules/documents/lib/platformServices.js.map +7 -0
  323. package/dist/modules/documents/lib/recordFieldInsertion.js +58 -0
  324. package/dist/modules/documents/lib/recordFieldInsertion.js.map +7 -0
  325. package/dist/modules/documents/lib/requestBody.js +80 -0
  326. package/dist/modules/documents/lib/requestBody.js.map +7 -0
  327. package/dist/modules/documents/lib/resourceLimits.js +62 -0
  328. package/dist/modules/documents/lib/resourceLimits.js.map +7 -0
  329. package/dist/modules/documents/lib/shareCounts.js +25 -0
  330. package/dist/modules/documents/lib/shareCounts.js.map +7 -0
  331. package/dist/modules/documents/lib/templateFill.js +84 -0
  332. package/dist/modules/documents/lib/templateFill.js.map +7 -0
  333. package/dist/modules/documents/lib/templateInstantiation.js +147 -0
  334. package/dist/modules/documents/lib/templateInstantiation.js.map +7 -0
  335. package/dist/modules/documents/lib/templatePreviewDigest.js +82 -0
  336. package/dist/modules/documents/lib/templatePreviewDigest.js.map +7 -0
  337. package/dist/modules/documents/lib/templateSeeds.js +201 -0
  338. package/dist/modules/documents/lib/templateSeeds.js.map +7 -0
  339. package/dist/modules/documents/lib/userLabels.js +37 -0
  340. package/dist/modules/documents/lib/userLabels.js.map +7 -0
  341. package/dist/modules/documents/lib/versionContent.js +131 -0
  342. package/dist/modules/documents/lib/versionContent.js.map +7 -0
  343. package/dist/modules/documents/lib/versionLabels.js +12 -0
  344. package/dist/modules/documents/lib/versionLabels.js.map +7 -0
  345. package/dist/modules/documents/lib/versioning.js +14 -0
  346. package/dist/modules/documents/lib/versioning.js.map +7 -0
  347. package/dist/modules/documents/lib/visibility.js +422 -0
  348. package/dist/modules/documents/lib/visibility.js.map +7 -0
  349. package/dist/modules/documents/lib/watchers.js +106 -0
  350. package/dist/modules/documents/lib/watchers.js.map +7 -0
  351. package/dist/modules/documents/migrations/Migration20260708163836_documents.js +44 -0
  352. package/dist/modules/documents/migrations/Migration20260708163836_documents.js.map +7 -0
  353. package/dist/modules/documents/migrations/Migration20260709164720_documents.js +17 -0
  354. package/dist/modules/documents/migrations/Migration20260709164720_documents.js.map +7 -0
  355. package/dist/modules/documents/migrations/Migration20260710002318_documents.js +32 -0
  356. package/dist/modules/documents/migrations/Migration20260710002318_documents.js.map +7 -0
  357. package/dist/modules/documents/migrations/Migration20260710071003_documents.js +13 -0
  358. package/dist/modules/documents/migrations/Migration20260710071003_documents.js.map +7 -0
  359. package/dist/modules/documents/migrations/Migration20260712120000_documents.js +13 -0
  360. package/dist/modules/documents/migrations/Migration20260712120000_documents.js.map +7 -0
  361. package/dist/modules/documents/migrations/Migration20260712183000_documents.js +14 -0
  362. package/dist/modules/documents/migrations/Migration20260712183000_documents.js.map +7 -0
  363. package/dist/modules/documents/migrations/Migration20260713092156_documents.js +29 -0
  364. package/dist/modules/documents/migrations/Migration20260713092156_documents.js.map +7 -0
  365. package/dist/modules/documents/migrations/Migration20260717000000_documents.js +37 -0
  366. package/dist/modules/documents/migrations/Migration20260717000000_documents.js.map +7 -0
  367. package/dist/modules/documents/notifications.js +47 -0
  368. package/dist/modules/documents/notifications.js.map +7 -0
  369. package/dist/modules/documents/search.js +101 -0
  370. package/dist/modules/documents/search.js.map +7 -0
  371. package/dist/modules/documents/setup.js +19 -0
  372. package/dist/modules/documents/setup.js.map +7 -0
  373. package/dist/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.js +214 -0
  374. package/dist/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.js.map +7 -0
  375. package/dist/modules/documents/widgets/injection/related-documents/context.js +84 -0
  376. package/dist/modules/documents/widgets/injection/related-documents/context.js.map +7 -0
  377. package/dist/modules/documents/widgets/injection/related-documents/useRelatedDocuments.js +98 -0
  378. package/dist/modules/documents/widgets/injection/related-documents/useRelatedDocuments.js.map +7 -0
  379. package/dist/modules/documents/widgets/injection/related-documents/widget.client.js +83 -0
  380. package/dist/modules/documents/widgets/injection/related-documents/widget.client.js.map +7 -0
  381. package/dist/modules/documents/widgets/injection/related-documents/widget.js +19 -0
  382. package/dist/modules/documents/widgets/injection/related-documents/widget.js.map +7 -0
  383. package/dist/modules/documents/widgets/injection-table.js +21 -0
  384. package/dist/modules/documents/widgets/injection-table.js.map +7 -0
  385. package/dist/server/documents-collab-server.js +2260 -0
  386. package/dist/server/documents-collab-server.js.map +7 -0
  387. package/generated/entities/document/index.ts +12 -0
  388. package/generated/entities/document_attachment/index.ts +9 -0
  389. package/generated/entities/document_comment/index.ts +14 -0
  390. package/generated/entities/document_content/index.ts +11 -0
  391. package/generated/entities/document_entity_link/index.ts +19 -0
  392. package/generated/entities/document_favorite/index.ts +7 -0
  393. package/generated/entities/document_folder/index.ts +9 -0
  394. package/generated/entities/document_share/index.ts +11 -0
  395. package/generated/entities/document_template/index.ts +13 -0
  396. package/generated/entities/document_version/index.ts +9 -0
  397. package/generated/entities/document_watcher/index.ts +7 -0
  398. package/generated/entities.ids.generated.ts +21 -0
  399. package/generated/entity-fields-registry.ts +151 -0
  400. package/jest.config.cjs +34 -0
  401. package/package.json +149 -0
  402. package/server/documents-collab-server.ts +3416 -0
  403. package/src/index.ts +1 -0
  404. package/src/modules/documents/acl.ts +11 -0
  405. package/src/modules/documents/api/[id]/archive/route.ts +132 -0
  406. package/src/modules/documents/api/[id]/attachments/[attachmentId]/route.ts +166 -0
  407. package/src/modules/documents/api/[id]/attachments/route.ts +173 -0
  408. package/src/modules/documents/api/[id]/collab-token/route.ts +203 -0
  409. package/src/modules/documents/api/[id]/comments/access-check/route.ts +96 -0
  410. package/src/modules/documents/api/[id]/comments/route.ts +442 -0
  411. package/src/modules/documents/api/[id]/content/route.ts +156 -0
  412. package/src/modules/documents/api/[id]/duplicate/route.ts +231 -0
  413. package/src/modules/documents/api/[id]/export/route.ts +535 -0
  414. package/src/modules/documents/api/[id]/favorite/route.ts +110 -0
  415. package/src/modules/documents/api/[id]/links/[linkId]/route.ts +92 -0
  416. package/src/modules/documents/api/[id]/links/route.ts +301 -0
  417. package/src/modules/documents/api/[id]/principals/route.ts +375 -0
  418. package/src/modules/documents/api/[id]/route.ts +267 -0
  419. package/src/modules/documents/api/[id]/shares/route.ts +372 -0
  420. package/src/modules/documents/api/[id]/unarchive/route.ts +42 -0
  421. package/src/modules/documents/api/[id]/versions/[versionId]/restore/route.ts +152 -0
  422. package/src/modules/documents/api/[id]/versions/[versionId]/route.ts +100 -0
  423. package/src/modules/documents/api/[id]/versions/route.ts +207 -0
  424. package/src/modules/documents/api/[id]/watch/route.ts +111 -0
  425. package/src/modules/documents/api/_commands.ts +53 -0
  426. package/src/modules/documents/api/_shared.ts +676 -0
  427. package/src/modules/documents/api/folders/route.ts +287 -0
  428. package/src/modules/documents/api/instantiate/route.ts +114 -0
  429. package/src/modules/documents/api/route.ts +362 -0
  430. package/src/modules/documents/api/templates/[templateId]/preview/route.ts +97 -0
  431. package/src/modules/documents/api/templates/[templateId]/route.ts +92 -0
  432. package/src/modules/documents/api/templates/route.ts +370 -0
  433. package/src/modules/documents/backend/documents/DocumentsPageClient.tsx +150 -0
  434. package/src/modules/documents/backend/documents/DocumentsTable.tsx +168 -0
  435. package/src/modules/documents/backend/documents/FolderDialog.tsx +62 -0
  436. package/src/modules/documents/backend/documents/FolderTree.tsx +72 -0
  437. package/src/modules/documents/backend/documents/MoveDocumentDialog.tsx +70 -0
  438. package/src/modules/documents/backend/documents/[id]/CommentAnchorNavigation.ts +88 -0
  439. package/src/modules/documents/backend/documents/[id]/CommentComposer.tsx +136 -0
  440. package/src/modules/documents/backend/documents/[id]/CommentThreadList.tsx +131 -0
  441. package/src/modules/documents/backend/documents/[id]/CommentsRail.tsx +138 -0
  442. package/src/modules/documents/backend/documents/[id]/DocumentCanvas.tsx +111 -0
  443. package/src/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.tsx +39 -0
  444. package/src/modules/documents/backend/documents/[id]/DocumentEditorIsland.tsx +50 -0
  445. package/src/modules/documents/backend/documents/[id]/DocumentEditorSurface.tsx +162 -0
  446. package/src/modules/documents/backend/documents/[id]/DocumentNavigator.tsx +129 -0
  447. package/src/modules/documents/backend/documents/[id]/DocumentPageClient.tsx +463 -0
  448. package/src/modules/documents/backend/documents/[id]/EditorColorTools.tsx +71 -0
  449. package/src/modules/documents/backend/documents/[id]/EditorStatusPresence.tsx +78 -0
  450. package/src/modules/documents/backend/documents/[id]/EditorToolbar.tsx +108 -0
  451. package/src/modules/documents/backend/documents/[id]/ExportMenu.tsx +144 -0
  452. package/src/modules/documents/backend/documents/[id]/MentionPicker.tsx +137 -0
  453. package/src/modules/documents/backend/documents/[id]/OutlinePane.tsx +98 -0
  454. package/src/modules/documents/backend/documents/[id]/RecordFieldsDialog.tsx +185 -0
  455. package/src/modules/documents/backend/documents/[id]/RelatedRecordsPanel.tsx +320 -0
  456. package/src/modules/documents/backend/documents/[id]/VersionHistoryPanel.tsx +244 -0
  457. package/src/modules/documents/backend/documents/[id]/VersionPreviewDialog.tsx +197 -0
  458. package/src/modules/documents/backend/documents/[id]/commentTypes.ts +192 -0
  459. package/src/modules/documents/backend/documents/[id]/componentCapabilities.ts +17 -0
  460. package/src/modules/documents/backend/documents/[id]/documentPagination.ts +352 -0
  461. package/src/modules/documents/backend/documents/[id]/editorPresenceStyles.ts +77 -0
  462. package/src/modules/documents/backend/documents/[id]/editorTypes.ts +84 -0
  463. package/src/modules/documents/backend/documents/[id]/page.meta.ts +12 -0
  464. package/src/modules/documents/backend/documents/[id]/page.tsx +6 -0
  465. package/src/modules/documents/backend/documents/[id]/relatedRecordModel.ts +49 -0
  466. package/src/modules/documents/backend/documents/[id]/restoreVersion.ts +49 -0
  467. package/src/modules/documents/backend/documents/[id]/useDocumentCollaboration.ts +458 -0
  468. package/src/modules/documents/backend/documents/[id]/useDocumentComments.ts +286 -0
  469. package/src/modules/documents/backend/documents/[id]/useDocumentEditor.ts +157 -0
  470. package/src/modules/documents/backend/documents/[id]/useDocumentTitle.ts +77 -0
  471. package/src/modules/documents/backend/documents/[id]/useEditorInsertions.ts +147 -0
  472. package/src/modules/documents/backend/documents/[id]/useFallbackContentPersistence.ts +277 -0
  473. package/src/modules/documents/backend/documents/[id]/useMentionPicker.ts +259 -0
  474. package/src/modules/documents/backend/documents/[id]/versionHistoryModel.ts +29 -0
  475. package/src/modules/documents/backend/documents/components/EntityPicker.tsx +171 -0
  476. package/src/modules/documents/backend/documents/components/EntityPickerResults.tsx +64 -0
  477. package/src/modules/documents/backend/documents/components/NewFromTemplateDialog.tsx +136 -0
  478. package/src/modules/documents/backend/documents/components/PrincipalPicker.tsx +90 -0
  479. package/src/modules/documents/backend/documents/components/ShareDialog.tsx +88 -0
  480. package/src/modules/documents/backend/documents/components/ShareDialogAddForm.tsx +113 -0
  481. package/src/modules/documents/backend/documents/components/ShareDialogList.tsx +117 -0
  482. package/src/modules/documents/backend/documents/components/TemplateBodyEditor.tsx +96 -0
  483. package/src/modules/documents/backend/documents/components/TemplateEditorDialog.tsx +171 -0
  484. package/src/modules/documents/backend/documents/components/TemplatePreview.tsx +43 -0
  485. package/src/modules/documents/backend/documents/components/TemplateSlotFields.tsx +72 -0
  486. package/src/modules/documents/backend/documents/components/TemplateSlotsEditor.tsx +72 -0
  487. package/src/modules/documents/backend/documents/components/principalPickerModel.ts +86 -0
  488. package/src/modules/documents/backend/documents/components/shareDialogModel.ts +94 -0
  489. package/src/modules/documents/backend/documents/components/templateUi.ts +128 -0
  490. package/src/modules/documents/backend/documents/components/useAvailableEntityRegistry.ts +43 -0
  491. package/src/modules/documents/backend/documents/components/useEntitySearch.ts +197 -0
  492. package/src/modules/documents/backend/documents/components/usePrincipalPicker.ts +165 -0
  493. package/src/modules/documents/backend/documents/components/useShareDialog.ts +267 -0
  494. package/src/modules/documents/backend/documents/components/useTemplateDetail.ts +54 -0
  495. package/src/modules/documents/backend/documents/components/useTemplateInstantiation.ts +252 -0
  496. package/src/modules/documents/backend/documents/documentUi.ts +134 -0
  497. package/src/modules/documents/backend/documents/documentsListTypes.ts +163 -0
  498. package/src/modules/documents/backend/documents/page.meta.ts +24 -0
  499. package/src/modules/documents/backend/documents/page.tsx +5 -0
  500. package/src/modules/documents/backend/documents/templates/TemplatesPageClient.tsx +93 -0
  501. package/src/modules/documents/backend/documents/templates/TemplatesTable.tsx +71 -0
  502. package/src/modules/documents/backend/documents/templates/page.meta.ts +32 -0
  503. package/src/modules/documents/backend/documents/templates/page.tsx +5 -0
  504. package/src/modules/documents/backend/documents/templates/useTemplatesPage.tsx +148 -0
  505. package/src/modules/documents/backend/documents/useDocumentsList.tsx +305 -0
  506. package/src/modules/documents/ce.ts +6 -0
  507. package/src/modules/documents/commands/aggregate.ts +128 -0
  508. package/src/modules/documents/commands/attachments.ts +309 -0
  509. package/src/modules/documents/commands/comments.ts +966 -0
  510. package/src/modules/documents/commands/content.ts +294 -0
  511. package/src/modules/documents/commands/document-crud.ts +609 -0
  512. package/src/modules/documents/commands/documents.ts +581 -0
  513. package/src/modules/documents/commands/duplicate.ts +772 -0
  514. package/src/modules/documents/commands/favorites.ts +171 -0
  515. package/src/modules/documents/commands/folders.ts +506 -0
  516. package/src/modules/documents/commands/index.ts +33 -0
  517. package/src/modules/documents/commands/interceptors.ts +402 -0
  518. package/src/modules/documents/commands/lifecycle.ts +333 -0
  519. package/src/modules/documents/commands/links.ts +486 -0
  520. package/src/modules/documents/commands/mutation-helpers.ts +48 -0
  521. package/src/modules/documents/commands/projection-types.ts +77 -0
  522. package/src/modules/documents/commands/shared.ts +219 -0
  523. package/src/modules/documents/commands/shares.ts +612 -0
  524. package/src/modules/documents/commands/side-effects.ts +130 -0
  525. package/src/modules/documents/commands/templates.ts +522 -0
  526. package/src/modules/documents/commands/versions.ts +537 -0
  527. package/src/modules/documents/commands/watchers.ts +181 -0
  528. package/src/modules/documents/data/entities.ts +631 -0
  529. package/src/modules/documents/data/extensions.ts +42 -0
  530. package/src/modules/documents/data/validators.ts +248 -0
  531. package/src/modules/documents/di.ts +33 -0
  532. package/src/modules/documents/encryption.ts +14 -0
  533. package/src/modules/documents/events.ts +23 -0
  534. package/src/modules/documents/i18n/.hardcoded-allowlist.json +9 -0
  535. package/src/modules/documents/i18n/de.json +522 -0
  536. package/src/modules/documents/i18n/en.json +522 -0
  537. package/src/modules/documents/i18n/es.json +522 -0
  538. package/src/modules/documents/i18n/ko.json +522 -0
  539. package/src/modules/documents/i18n/pl.json +522 -0
  540. package/src/modules/documents/index.ts +17 -0
  541. package/src/modules/documents/lib/attachmentServicePort.ts +94 -0
  542. package/src/modules/documents/lib/capabilities.ts +57 -0
  543. package/src/modules/documents/lib/collabCloseEvents.ts +26 -0
  544. package/src/modules/documents/lib/collabEndpoint.ts +43 -0
  545. package/src/modules/documents/lib/collabMaterializer.ts +140 -0
  546. package/src/modules/documents/lib/collabToken.ts +170 -0
  547. package/src/modules/documents/lib/collaborationAwareness.ts +102 -0
  548. package/src/modules/documents/lib/commentAnchors.ts +19 -0
  549. package/src/modules/documents/lib/constants.ts +39 -0
  550. package/src/modules/documents/lib/contentService.ts +340 -0
  551. package/src/modules/documents/lib/displayLabels.ts +31 -0
  552. package/src/modules/documents/lib/docxRenderer.ts +685 -0
  553. package/src/modules/documents/lib/duplicateContent.ts +32 -0
  554. package/src/modules/documents/lib/editorConfig.ts +371 -0
  555. package/src/modules/documents/lib/entityLinks.ts +250 -0
  556. package/src/modules/documents/lib/entityRegistry.server.ts +267 -0
  557. package/src/modules/documents/lib/entityRegistry.ts +345 -0
  558. package/src/modules/documents/lib/entityRegistryAvailability.server.ts +19 -0
  559. package/src/modules/documents/lib/entitySuggestion.ts +61 -0
  560. package/src/modules/documents/lib/favorites.ts +35 -0
  561. package/src/modules/documents/lib/folderHierarchySerialization.ts +34 -0
  562. package/src/modules/documents/lib/historyLimits.ts +154 -0
  563. package/src/modules/documents/lib/historyPolicy.ts +7 -0
  564. package/src/modules/documents/lib/organizationAccess.ts +44 -0
  565. package/src/modules/documents/lib/pdfHtml.ts +65 -0
  566. package/src/modules/documents/lib/pdfRenderer.ts +367 -0
  567. package/src/modules/documents/lib/permissions.ts +299 -0
  568. package/src/modules/documents/lib/platformServices.ts +70 -0
  569. package/src/modules/documents/lib/recordFieldInsertion.ts +72 -0
  570. package/src/modules/documents/lib/requestBody.ts +97 -0
  571. package/src/modules/documents/lib/resourceLimits.ts +94 -0
  572. package/src/modules/documents/lib/shareCounts.ts +44 -0
  573. package/src/modules/documents/lib/templateFill.ts +138 -0
  574. package/src/modules/documents/lib/templateInstantiation.ts +206 -0
  575. package/src/modules/documents/lib/templatePreviewDigest.ts +122 -0
  576. package/src/modules/documents/lib/templateSeeds.ts +248 -0
  577. package/src/modules/documents/lib/userLabels.ts +58 -0
  578. package/src/modules/documents/lib/versionContent.ts +163 -0
  579. package/src/modules/documents/lib/versionLabels.ts +9 -0
  580. package/src/modules/documents/lib/versioning.ts +29 -0
  581. package/src/modules/documents/lib/visibility.ts +610 -0
  582. package/src/modules/documents/lib/watchers.ts +129 -0
  583. package/src/modules/documents/migrations/.snapshot-open-mercato.json +2892 -0
  584. package/src/modules/documents/migrations/Migration20260708163836_documents.ts +50 -0
  585. package/src/modules/documents/migrations/Migration20260709164720_documents.ts +19 -0
  586. package/src/modules/documents/migrations/Migration20260710002318_documents.ts +35 -0
  587. package/src/modules/documents/migrations/Migration20260710071003_documents.ts +13 -0
  588. package/src/modules/documents/migrations/Migration20260712120000_documents.ts +13 -0
  589. package/src/modules/documents/migrations/Migration20260712183000_documents.ts +12 -0
  590. package/src/modules/documents/migrations/Migration20260713092156_documents.ts +43 -0
  591. package/src/modules/documents/migrations/Migration20260717000000_documents.ts +40 -0
  592. package/src/modules/documents/notifications.ts +45 -0
  593. package/src/modules/documents/search.ts +118 -0
  594. package/src/modules/documents/setup.ts +19 -0
  595. package/src/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.tsx +224 -0
  596. package/src/modules/documents/widgets/injection/related-documents/context.ts +101 -0
  597. package/src/modules/documents/widgets/injection/related-documents/useRelatedDocuments.ts +112 -0
  598. package/src/modules/documents/widgets/injection/related-documents/widget.client.tsx +76 -0
  599. package/src/modules/documents/widgets/injection/related-documents/widget.ts +19 -0
  600. package/src/modules/documents/widgets/injection-table.ts +20 -0
  601. package/tsconfig.json +9 -0
  602. package/watch.mjs +6 -0
@@ -0,0 +1,300 @@
1
+ import { extractUndoPayload } from "@open-mercato/shared/lib/commands/undo";
2
+ import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
3
+ import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
4
+ import { createLogger } from "@open-mercato/shared/lib/logger";
5
+ import { Document } from "../data/entities.js";
6
+ import { DOCUMENTS_ENTITY_IDS } from "../lib/constants.js";
7
+ import { resolveWatcherRecipients } from "../lib/watchers.js";
8
+ import { emitDocumentsEvent } from "../events.js";
9
+ const logger = createLogger("documents").child({ component: "command-projections" });
10
+ const PROJECTED_COMMAND_IDS = [
11
+ "documents.content.replace",
12
+ "documents.share.create",
13
+ "documents.share.update",
14
+ "documents.share.delete",
15
+ "documents.comment.create",
16
+ "documents.comment.resolve",
17
+ "documents.version.restore",
18
+ "documents.document.archive",
19
+ "documents.document.unarchive",
20
+ "documents.document.duplicate"
21
+ ];
22
+ function resolveDocumentsNotificationService(container) {
23
+ const service = container.resolve("notificationService");
24
+ if (!service || typeof service.create !== "function" || typeof service.deleteBySource !== "function") {
25
+ throw new Error("[internal] Notification service is unavailable");
26
+ }
27
+ return service;
28
+ }
29
+ function readResultProjections(result) {
30
+ if (!result || typeof result !== "object" || Array.isArray(result)) return [];
31
+ const projections = result.projections;
32
+ return Array.isArray(projections) ? projections : [];
33
+ }
34
+ async function emitProjectedEvent(descriptor, context, options = {}) {
35
+ const currentActorUserId = context.auth?.userId ?? context.auth?.sub ?? null;
36
+ const payload = {
37
+ ...descriptor.payload,
38
+ ...currentActorUserId && (options.overrideActor || !("userId" in descriptor.payload)) ? { userId: currentActorUserId } : {}
39
+ };
40
+ try {
41
+ await emitDocumentsEvent(descriptor.eventId, payload, {
42
+ tenantId: descriptor.tenantId,
43
+ organizationId: descriptor.organizationId
44
+ });
45
+ } catch (error) {
46
+ logger.error("Command event projection failed", {
47
+ commandId: context.commandId,
48
+ eventId: descriptor.eventId,
49
+ err: error
50
+ });
51
+ }
52
+ }
53
+ async function emitMentionProjection(descriptor, context) {
54
+ try {
55
+ const notificationService = resolveDocumentsNotificationService(context.container);
56
+ await notificationService.create(
57
+ {
58
+ recipientUserId: descriptor.recipientUserId,
59
+ type: "documents.comment.mentioned",
60
+ titleKey: "documents.notifications.comment.mentioned.title",
61
+ bodyKey: "documents.notifications.comment.mentioned.body",
62
+ severity: "info",
63
+ titleVariables: { documentTitle: descriptor.documentTitle },
64
+ bodyVariables: {
65
+ documentTitle: descriptor.documentTitle,
66
+ authorUserId: descriptor.authorUserId
67
+ },
68
+ sourceEntityType: DOCUMENTS_ENTITY_IDS.documentComment,
69
+ sourceEntityId: descriptor.commentId,
70
+ linkHref: `/backend/documents/${encodeURIComponent(descriptor.documentId)}?commentId=${encodeURIComponent(descriptor.commentId)}`
71
+ },
72
+ {
73
+ tenantId: descriptor.tenantId,
74
+ organizationId: descriptor.organizationId
75
+ }
76
+ );
77
+ } catch (error) {
78
+ logger.error("Mention notification projection failed", {
79
+ commandId: context.commandId,
80
+ commentId: descriptor.commentId,
81
+ recipientUserId: descriptor.recipientUserId,
82
+ err: error
83
+ });
84
+ }
85
+ }
86
+ const WATCH_NOTIFICATION_TITLE_KEYS = {
87
+ "documents.watch.commented": "documents.notifications.watch.commented.title",
88
+ "documents.watch.changed": "documents.notifications.watch.changed.title"
89
+ };
90
+ async function emitWatchProjection(descriptor, context) {
91
+ try {
92
+ const notificationService = resolveDocumentsNotificationService(context.container);
93
+ await notificationService.create(
94
+ {
95
+ recipientUserId: descriptor.recipientUserId,
96
+ type: descriptor.notificationType,
97
+ titleKey: WATCH_NOTIFICATION_TITLE_KEYS[descriptor.notificationType],
98
+ bodyKey: descriptor.bodyKey,
99
+ severity: "info",
100
+ titleVariables: { documentTitle: descriptor.documentTitle },
101
+ bodyVariables: { documentTitle: descriptor.documentTitle },
102
+ sourceEntityType: descriptor.sourceEntityType,
103
+ sourceEntityId: descriptor.sourceEntityId,
104
+ linkHref: descriptor.linkHref
105
+ },
106
+ {
107
+ tenantId: descriptor.tenantId,
108
+ organizationId: descriptor.organizationId
109
+ }
110
+ );
111
+ } catch (error) {
112
+ logger.error("Watch notification projection failed", {
113
+ commandId: context.commandId,
114
+ documentId: descriptor.documentId,
115
+ recipientUserId: descriptor.recipientUserId,
116
+ err: error
117
+ });
118
+ }
119
+ }
120
+ async function emitWatchFanoutProjection(descriptor, context) {
121
+ try {
122
+ const em = context.container.resolve("em");
123
+ const scope = { tenantId: descriptor.tenantId, organizationId: descriptor.organizationId };
124
+ const document = await findOneWithDecryption(
125
+ em,
126
+ Document,
127
+ { id: descriptor.documentId, tenantId: scope.tenantId, organizationId: scope.organizationId, deletedAt: null },
128
+ { fields: ["id", "title"] },
129
+ scope
130
+ );
131
+ if (!document) return;
132
+ const recipientUserIds = await resolveWatcherRecipients({
133
+ em,
134
+ container: context.container,
135
+ scope,
136
+ documentId: descriptor.documentId,
137
+ actorUserId: context.auth?.userId ?? context.auth?.sub ?? descriptor.actorUserId
138
+ });
139
+ for (const recipientUserId of recipientUserIds) {
140
+ await emitWatchProjection(
141
+ {
142
+ kind: "watch-notification",
143
+ recipientUserId,
144
+ tenantId: descriptor.tenantId,
145
+ organizationId: descriptor.organizationId,
146
+ documentId: descriptor.documentId,
147
+ documentTitle: document.title,
148
+ notificationType: descriptor.notificationType,
149
+ bodyKey: descriptor.bodyKey,
150
+ sourceEntityType: descriptor.sourceEntityType,
151
+ sourceEntityId: descriptor.sourceEntityId,
152
+ linkHref: descriptor.linkHref
153
+ },
154
+ context
155
+ );
156
+ }
157
+ } catch (error) {
158
+ logger.error("Watch notification fanout projection failed", {
159
+ commandId: context.commandId,
160
+ documentId: descriptor.documentId,
161
+ err: error
162
+ });
163
+ }
164
+ }
165
+ async function emitDocumentIndexProjection(descriptor, context) {
166
+ try {
167
+ const searchIndexer = context.container.resolve("searchIndexer");
168
+ await searchIndexer.indexRecordById({
169
+ entityId: DOCUMENTS_ENTITY_IDS.document,
170
+ recordId: descriptor.documentId,
171
+ tenantId: descriptor.tenantId,
172
+ organizationId: descriptor.organizationId
173
+ });
174
+ } catch (error) {
175
+ logger.error("Document index projection failed", {
176
+ commandId: context.commandId,
177
+ documentId: descriptor.documentId,
178
+ err: error
179
+ });
180
+ }
181
+ }
182
+ async function deleteMentionNotificationProjection(descriptor, context) {
183
+ try {
184
+ const notificationService = resolveDocumentsNotificationService(context.container);
185
+ await notificationService.deleteBySource(
186
+ DOCUMENTS_ENTITY_IDS.documentComment,
187
+ descriptor.commentId,
188
+ {
189
+ tenantId: descriptor.tenantId,
190
+ organizationId: descriptor.organizationId
191
+ }
192
+ );
193
+ } catch (error) {
194
+ logger.error("Mention notification cleanup projection failed", {
195
+ commandId: context.commandId,
196
+ commentId: descriptor.commentId,
197
+ err: error
198
+ });
199
+ }
200
+ }
201
+ async function projectDescriptors(projections, context, options = {}) {
202
+ for (const projection of projections) {
203
+ if (projection.kind === "event") {
204
+ await emitProjectedEvent(projection, context, { overrideActor: options.overrideEventActor });
205
+ } else if (projection.kind === "mention-notification") await emitMentionProjection(projection, context);
206
+ else if (projection.kind === "watch-notification") await emitWatchProjection(projection, context);
207
+ else if (projection.kind === "watch-notification-fanout") await emitWatchFanoutProjection(projection, context);
208
+ else if (projection.kind === "document-index") await emitDocumentIndexProjection(projection, context);
209
+ else await deleteMentionNotificationProjection(projection, context);
210
+ }
211
+ }
212
+ function buildProjectionInterceptor(commandId) {
213
+ return {
214
+ id: `documents.${commandId.slice("documents.".length).replaceAll(".", "-")}-projections`,
215
+ targetCommand: commandId,
216
+ priority: 90,
217
+ async afterExecute(_input, result, context) {
218
+ await projectDescriptors(readResultProjections(result), context);
219
+ },
220
+ async afterUndo(undoContext, context) {
221
+ const undo = extractUndoPayload(
222
+ undoContext.logEntry
223
+ );
224
+ await projectDescriptors(
225
+ undo?.projectionsAfterUndo ?? [],
226
+ context,
227
+ { overrideEventActor: true }
228
+ );
229
+ }
230
+ };
231
+ }
232
+ const ARCHIVED_UNDO_GUARDED_COMMAND_IDS = [
233
+ "documents.document.update",
234
+ "documents.share.create",
235
+ "documents.share.update",
236
+ "documents.share.delete",
237
+ "documents.comment.create",
238
+ "documents.comment.resolve",
239
+ "documents.link.create",
240
+ "documents.link.delete",
241
+ "documents.version.restore"
242
+ ];
243
+ function resolveUndoDocumentId(logEntry) {
244
+ if (logEntry.parentResourceKind === DOCUMENTS_ENTITY_IDS.document && logEntry.parentResourceId) {
245
+ return logEntry.parentResourceId;
246
+ }
247
+ if (logEntry.resourceKind === DOCUMENTS_ENTITY_IDS.document && logEntry.resourceId) {
248
+ return logEntry.resourceId;
249
+ }
250
+ const payload = logEntry.commandPayload;
251
+ if (payload && typeof payload === "object") {
252
+ const redoInput = payload.__redoInput;
253
+ if (redoInput && typeof redoInput === "object") {
254
+ const documentId = redoInput.documentId;
255
+ if (typeof documentId === "string" && documentId.length > 0) return documentId;
256
+ }
257
+ }
258
+ return null;
259
+ }
260
+ function buildArchivedUndoGuard(commandId) {
261
+ return {
262
+ id: `documents.${commandId.slice("documents.".length).replaceAll(".", "-")}-archived-undo-guard`,
263
+ targetCommand: commandId,
264
+ priority: 100,
265
+ async beforeUndo(undoContext, context) {
266
+ const logEntry = undoContext.logEntry;
267
+ const documentId = resolveUndoDocumentId(logEntry);
268
+ if (!documentId || !logEntry.tenantId || !logEntry.organizationId) {
269
+ logger.error("Archived-undo guard could not resolve the guarded document scope", {
270
+ commandId,
271
+ resourceKind: logEntry.resourceKind ?? null,
272
+ resourceId: logEntry.resourceId ?? null
273
+ });
274
+ throw new CrudHttpError(403, { error: "api.errors.forbidden" });
275
+ }
276
+ const em = context.container.resolve("em");
277
+ const scope = { tenantId: logEntry.tenantId, organizationId: logEntry.organizationId };
278
+ const document = await findOneWithDecryption(
279
+ em,
280
+ Document,
281
+ { id: documentId, tenantId: scope.tenantId, organizationId: scope.organizationId },
282
+ { fields: ["id", "archivedAt"], filters: false },
283
+ scope
284
+ );
285
+ if (document?.archivedAt) {
286
+ throw new CrudHttpError(403, { error: "documents.errors.documentArchived" });
287
+ }
288
+ }
289
+ };
290
+ }
291
+ const interceptors = [
292
+ ...PROJECTED_COMMAND_IDS.map(buildProjectionInterceptor),
293
+ ...ARCHIVED_UNDO_GUARDED_COMMAND_IDS.map(buildArchivedUndoGuard)
294
+ ];
295
+ var interceptors_default = interceptors;
296
+ export {
297
+ interceptors_default as default,
298
+ interceptors
299
+ };
300
+ //# sourceMappingURL=interceptors.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/documents/commands/interceptors.ts"],
4
+ "sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport type {\n CommandInterceptor,\n CommandInterceptorContext,\n CommandInterceptorUndoContext,\n} from '@open-mercato/shared/lib/commands/command-interceptor'\nimport { extractUndoPayload } from '@open-mercato/shared/lib/commands/undo'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\nimport { Document } from '../data/entities'\nimport { DOCUMENTS_ENTITY_IDS } from '../lib/constants'\nimport { resolveWatcherRecipients } from '../lib/watchers'\nimport type { DocumentsServiceContainer } from '../lib/platformServices'\nimport { emitDocumentsEvent } from '../events'\nimport type {\n DocumentsProjectedCommandResult,\n DocumentsProjectionDescriptor,\n DocumentsProjectionUndoPayload,\n} from './projection-types'\n\nconst logger = createLogger('documents').child({ component: 'command-projections' })\n\nconst PROJECTED_COMMAND_IDS = [\n 'documents.content.replace',\n 'documents.share.create',\n 'documents.share.update',\n 'documents.share.delete',\n 'documents.comment.create',\n 'documents.comment.resolve',\n 'documents.version.restore',\n 'documents.document.archive',\n 'documents.document.unarchive',\n 'documents.document.duplicate',\n] as const\n\ntype DocumentsNotificationService = {\n create: (\n input: Record<string, unknown>,\n scope: { tenantId: string; organizationId: string },\n ) => Promise<unknown>\n deleteBySource: (\n sourceEntityType: string,\n sourceEntityId: string,\n scope: { tenantId: string; organizationId: string },\n ) => Promise<unknown>\n}\n\nfunction resolveDocumentsNotificationService(\n container: CommandInterceptorContext['container'],\n): DocumentsNotificationService {\n const service = container.resolve('notificationService') as Partial<DocumentsNotificationService> | null\n if (!service || typeof service.create !== 'function' || typeof service.deleteBySource !== 'function') {\n throw new Error('[internal] Notification service is unavailable')\n }\n return service as DocumentsNotificationService\n}\n\nfunction readResultProjections(result: unknown): DocumentsProjectionDescriptor[] {\n if (!result || typeof result !== 'object' || Array.isArray(result)) return []\n const projections = (result as DocumentsProjectedCommandResult).projections\n return Array.isArray(projections) ? projections : []\n}\n\nasync function emitProjectedEvent(\n descriptor: Extract<DocumentsProjectionDescriptor, { kind: 'event' }>,\n context: CommandInterceptorContext,\n options: { overrideActor?: boolean } = {},\n): Promise<void> {\n const currentActorUserId = context.auth?.userId ?? context.auth?.sub ?? null\n const payload = {\n ...descriptor.payload,\n ...(currentActorUserId && (options.overrideActor || !('userId' in descriptor.payload))\n ? { userId: currentActorUserId }\n : {}),\n }\n try {\n await emitDocumentsEvent(descriptor.eventId, payload, {\n tenantId: descriptor.tenantId,\n organizationId: descriptor.organizationId,\n })\n } catch (error) {\n logger.error('Command event projection failed', {\n commandId: context.commandId,\n eventId: descriptor.eventId,\n err: error,\n })\n }\n}\n\nasync function emitMentionProjection(\n descriptor: Extract<DocumentsProjectionDescriptor, { kind: 'mention-notification' }>,\n context: CommandInterceptorContext,\n): Promise<void> {\n try {\n const notificationService = resolveDocumentsNotificationService(context.container)\n await notificationService.create(\n {\n recipientUserId: descriptor.recipientUserId,\n type: 'documents.comment.mentioned',\n titleKey: 'documents.notifications.comment.mentioned.title',\n bodyKey: 'documents.notifications.comment.mentioned.body',\n severity: 'info',\n titleVariables: { documentTitle: descriptor.documentTitle },\n bodyVariables: {\n documentTitle: descriptor.documentTitle,\n authorUserId: descriptor.authorUserId,\n },\n sourceEntityType: DOCUMENTS_ENTITY_IDS.documentComment,\n sourceEntityId: descriptor.commentId,\n linkHref: `/backend/documents/${encodeURIComponent(descriptor.documentId)}?commentId=${encodeURIComponent(descriptor.commentId)}`,\n },\n {\n tenantId: descriptor.tenantId,\n organizationId: descriptor.organizationId,\n },\n )\n } catch (error) {\n logger.error('Mention notification projection failed', {\n commandId: context.commandId,\n commentId: descriptor.commentId,\n recipientUserId: descriptor.recipientUserId,\n err: error,\n })\n }\n}\n\nconst WATCH_NOTIFICATION_TITLE_KEYS: Record<string, string> = {\n 'documents.watch.commented': 'documents.notifications.watch.commented.title',\n 'documents.watch.changed': 'documents.notifications.watch.changed.title',\n}\n\nasync function emitWatchProjection(\n descriptor: Extract<DocumentsProjectionDescriptor, { kind: 'watch-notification' }>,\n context: CommandInterceptorContext,\n): Promise<void> {\n try {\n const notificationService = resolveDocumentsNotificationService(context.container)\n await notificationService.create(\n {\n recipientUserId: descriptor.recipientUserId,\n type: descriptor.notificationType,\n titleKey: WATCH_NOTIFICATION_TITLE_KEYS[descriptor.notificationType],\n bodyKey: descriptor.bodyKey,\n severity: 'info',\n titleVariables: { documentTitle: descriptor.documentTitle },\n bodyVariables: { documentTitle: descriptor.documentTitle },\n sourceEntityType: descriptor.sourceEntityType,\n sourceEntityId: descriptor.sourceEntityId,\n linkHref: descriptor.linkHref,\n },\n {\n tenantId: descriptor.tenantId,\n organizationId: descriptor.organizationId,\n },\n )\n } catch (error) {\n logger.error('Watch notification projection failed', {\n commandId: context.commandId,\n documentId: descriptor.documentId,\n recipientUserId: descriptor.recipientUserId,\n err: error,\n })\n }\n}\n\nasync function emitWatchFanoutProjection(\n descriptor: Extract<DocumentsProjectionDescriptor, { kind: 'watch-notification-fanout' }>,\n context: CommandInterceptorContext,\n): Promise<void> {\n try {\n const em = context.container.resolve('em') as EntityManager\n const scope = { tenantId: descriptor.tenantId, organizationId: descriptor.organizationId }\n const document = await findOneWithDecryption(\n em,\n Document,\n { id: descriptor.documentId, tenantId: scope.tenantId, organizationId: scope.organizationId, deletedAt: null },\n { fields: ['id', 'title'] },\n scope,\n )\n if (!document) return\n const recipientUserIds = await resolveWatcherRecipients({\n em,\n container: context.container as unknown as DocumentsServiceContainer,\n scope,\n documentId: descriptor.documentId,\n actorUserId: context.auth?.userId ?? context.auth?.sub ?? descriptor.actorUserId,\n })\n for (const recipientUserId of recipientUserIds) {\n await emitWatchProjection(\n {\n kind: 'watch-notification',\n recipientUserId,\n tenantId: descriptor.tenantId,\n organizationId: descriptor.organizationId,\n documentId: descriptor.documentId,\n documentTitle: document.title,\n notificationType: descriptor.notificationType,\n bodyKey: descriptor.bodyKey,\n sourceEntityType: descriptor.sourceEntityType,\n sourceEntityId: descriptor.sourceEntityId,\n linkHref: descriptor.linkHref,\n },\n context,\n )\n }\n } catch (error) {\n logger.error('Watch notification fanout projection failed', {\n commandId: context.commandId,\n documentId: descriptor.documentId,\n err: error,\n })\n }\n}\n\nasync function emitDocumentIndexProjection(\n descriptor: Extract<DocumentsProjectionDescriptor, { kind: 'document-index' }>,\n context: CommandInterceptorContext,\n): Promise<void> {\n try {\n const searchIndexer = context.container.resolve('searchIndexer') as {\n indexRecordById: (input: {\n entityId: string\n recordId: string\n tenantId: string\n organizationId: string\n }) => Promise<unknown>\n }\n await searchIndexer.indexRecordById({\n entityId: DOCUMENTS_ENTITY_IDS.document,\n recordId: descriptor.documentId,\n tenantId: descriptor.tenantId,\n organizationId: descriptor.organizationId,\n })\n } catch (error) {\n logger.error('Document index projection failed', {\n commandId: context.commandId,\n documentId: descriptor.documentId,\n err: error,\n })\n }\n}\n\nasync function deleteMentionNotificationProjection(\n descriptor: Extract<DocumentsProjectionDescriptor, { kind: 'mention-notification-delete' }>,\n context: CommandInterceptorContext,\n): Promise<void> {\n try {\n const notificationService = resolveDocumentsNotificationService(context.container)\n await notificationService.deleteBySource(\n DOCUMENTS_ENTITY_IDS.documentComment,\n descriptor.commentId,\n {\n tenantId: descriptor.tenantId,\n organizationId: descriptor.organizationId,\n },\n )\n } catch (error) {\n logger.error('Mention notification cleanup projection failed', {\n commandId: context.commandId,\n commentId: descriptor.commentId,\n err: error,\n })\n }\n}\n\nasync function projectDescriptors(\n projections: readonly DocumentsProjectionDescriptor[],\n context: CommandInterceptorContext,\n options: { overrideEventActor?: boolean } = {},\n): Promise<void> {\n for (const projection of projections) {\n if (projection.kind === 'event') {\n await emitProjectedEvent(projection, context, { overrideActor: options.overrideEventActor })\n }\n else if (projection.kind === 'mention-notification') await emitMentionProjection(projection, context)\n else if (projection.kind === 'watch-notification') await emitWatchProjection(projection, context)\n else if (projection.kind === 'watch-notification-fanout') await emitWatchFanoutProjection(projection, context)\n else if (projection.kind === 'document-index') await emitDocumentIndexProjection(projection, context)\n else await deleteMentionNotificationProjection(projection, context)\n }\n}\n\nfunction buildProjectionInterceptor(commandId: typeof PROJECTED_COMMAND_IDS[number]): CommandInterceptor {\n return {\n id: `documents.${commandId.slice('documents.'.length).replaceAll('.', '-')}-projections`,\n targetCommand: commandId,\n priority: 90,\n async afterExecute(_input, result, context): Promise<void> {\n await projectDescriptors(readResultProjections(result), context)\n },\n async afterUndo(\n undoContext: CommandInterceptorUndoContext,\n context: CommandInterceptorContext,\n ): Promise<void> {\n const undo = extractUndoPayload<DocumentsProjectionUndoPayload>(\n undoContext.logEntry as Parameters<typeof extractUndoPayload>[0],\n )\n await projectDescriptors(\n undo?.projectionsAfterUndo ?? [],\n context,\n { overrideEventActor: true },\n )\n },\n }\n}\n\nconst ARCHIVED_UNDO_GUARDED_COMMAND_IDS = [\n 'documents.document.update',\n 'documents.share.create',\n 'documents.share.update',\n 'documents.share.delete',\n 'documents.comment.create',\n 'documents.comment.resolve',\n 'documents.link.create',\n 'documents.link.delete',\n 'documents.version.restore',\n] as const\n\ntype UndoLogEntryShape = {\n resourceKind?: string | null\n resourceId?: string | null\n parentResourceKind?: string | null\n parentResourceId?: string | null\n tenantId?: string | null\n organizationId?: string | null\n commandPayload?: unknown\n}\n\nfunction resolveUndoDocumentId(logEntry: UndoLogEntryShape): string | null {\n if (logEntry.parentResourceKind === DOCUMENTS_ENTITY_IDS.document && logEntry.parentResourceId) {\n return logEntry.parentResourceId\n }\n if (logEntry.resourceKind === DOCUMENTS_ENTITY_IDS.document && logEntry.resourceId) {\n return logEntry.resourceId\n }\n const payload = logEntry.commandPayload\n if (payload && typeof payload === 'object') {\n const redoInput = (payload as { __redoInput?: unknown }).__redoInput\n if (redoInput && typeof redoInput === 'object') {\n const documentId = (redoInput as { documentId?: unknown }).documentId\n if (typeof documentId === 'string' && documentId.length > 0) return documentId\n }\n }\n return null\n}\n\n/**\n * Read-only means the undo path too: reversing a pre-archive share, comment,\n * link, or restore would mutate an archived document, so the guard refuses\n * with the same error the execute path uses. Delete-like undos (duplicate,\n * instantiate) stay allowed, matching delete-of-archived semantics.\n */\nfunction buildArchivedUndoGuard(commandId: typeof ARCHIVED_UNDO_GUARDED_COMMAND_IDS[number]): CommandInterceptor {\n return {\n id: `documents.${commandId.slice('documents.'.length).replaceAll('.', '-')}-archived-undo-guard`,\n targetCommand: commandId,\n priority: 100,\n async beforeUndo(\n undoContext: CommandInterceptorUndoContext,\n context: CommandInterceptorContext,\n ): Promise<void> {\n const logEntry = undoContext.logEntry as UndoLogEntryShape\n const documentId = resolveUndoDocumentId(logEntry)\n if (!documentId || !logEntry.tenantId || !logEntry.organizationId) {\n // Every guarded command records the document and its scope. Without\n // them the archived state cannot be read, so refuse the undo instead of\n // waving through a mutation this guard was unable to check.\n logger.error('Archived-undo guard could not resolve the guarded document scope', {\n commandId,\n resourceKind: logEntry.resourceKind ?? null,\n resourceId: logEntry.resourceId ?? null,\n })\n throw new CrudHttpError(403, { error: 'api.errors.forbidden' })\n }\n const em = context.container.resolve('em') as EntityManager\n const scope = { tenantId: logEntry.tenantId, organizationId: logEntry.organizationId }\n const document = await findOneWithDecryption(\n em,\n Document,\n { id: documentId, tenantId: scope.tenantId, organizationId: scope.organizationId },\n { fields: ['id', 'archivedAt'], filters: false },\n scope,\n )\n if (document?.archivedAt) {\n throw new CrudHttpError(403, { error: 'documents.errors.documentArchived' })\n }\n },\n }\n}\n\n/**\n * Projection hooks are deliberately post-command. CommandBus persists the\n * ActionLog (or marks it undone) before these hooks run, so a flaky event bus\n * or notification store can never roll back an acknowledged document write.\n */\nexport const interceptors: CommandInterceptor[] = [\n ...PROJECTED_COMMAND_IDS.map(buildProjectionInterceptor),\n ...ARCHIVED_UNDO_GUARDED_COMMAND_IDS.map(buildArchivedUndoGuard),\n]\n\nexport default interceptors\n"],
5
+ "mappings": "AAMA,SAAS,0BAA0B;AACnC,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AACrC,SAAS,gCAAgC;AAEzC,SAAS,0BAA0B;AAOnC,MAAM,SAAS,aAAa,WAAW,EAAE,MAAM,EAAE,WAAW,sBAAsB,CAAC;AAEnF,MAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAcA,SAAS,oCACP,WAC8B;AAC9B,QAAM,UAAU,UAAU,QAAQ,qBAAqB;AACvD,MAAI,CAAC,WAAW,OAAO,QAAQ,WAAW,cAAc,OAAO,QAAQ,mBAAmB,YAAY;AACpG,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,SAAO;AACT;AAEA,SAAS,sBAAsB,QAAkD;AAC/E,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,EAAG,QAAO,CAAC;AAC5E,QAAM,cAAe,OAA2C;AAChE,SAAO,MAAM,QAAQ,WAAW,IAAI,cAAc,CAAC;AACrD;AAEA,eAAe,mBACb,YACA,SACA,UAAuC,CAAC,GACzB;AACf,QAAM,qBAAqB,QAAQ,MAAM,UAAU,QAAQ,MAAM,OAAO;AACxE,QAAM,UAAU;AAAA,IACd,GAAG,WAAW;AAAA,IACd,GAAI,uBAAuB,QAAQ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AkC,IAAI,sBAAsB;AACjE;AAEA,IAAO,uBAAQ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,249 @@
1
+ import { z } from "zod";
2
+ import {
3
+ registerCommand
4
+ } from "@open-mercato/shared/lib/commands";
5
+ import { withAtomicFlush } from "@open-mercato/shared/lib/commands/flush";
6
+ import { extractUndoPayload } from "@open-mercato/shared/lib/commands/undo";
7
+ import { hasAllFeatures } from "@open-mercato/shared/lib/auth/featureMatch";
8
+ import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
9
+ import {
10
+ assertOptimisticLock,
11
+ enforceCommandOptimisticLockWithGuards
12
+ } from "@open-mercato/shared/lib/crud/optimistic-lock-command";
13
+ import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
14
+ import { DOCUMENTS_ENTITY_IDS } from "../lib/constants.js";
15
+ import { resolveWatcherRecipients } from "../lib/watchers.js";
16
+ import { lockDocumentAggregateRoot } from "./aggregate.js";
17
+ import { nextDocumentVersion } from "./mutation-helpers.js";
18
+ import {
19
+ resolveDocumentsCommandActor,
20
+ resolveDocumentsCommandEntityManager,
21
+ resolveDocumentsCommandFeatures,
22
+ resolveDocumentsCommandScope
23
+ } from "./shared.js";
24
+ const lifecycleStateSchema = z.object({
25
+ archivedAt: z.string().datetime().nullable(),
26
+ updatedAt: z.string().datetime()
27
+ });
28
+ const lifecycleRedoExpectationSchema = z.object({
29
+ archivedAt: z.string().datetime().nullable()
30
+ });
31
+ const documentLifecycleCommandSchema = z.object({
32
+ tenantId: z.string().uuid(),
33
+ organizationId: z.string().uuid(),
34
+ documentId: z.string().uuid(),
35
+ actorUserId: z.string().uuid(),
36
+ expectedUpdatedAt: z.string().datetime().nullable().optional(),
37
+ redoExpectation: lifecycleRedoExpectationSchema.optional()
38
+ });
39
+ function captureLifecycleState(document) {
40
+ return {
41
+ archivedAt: document.archivedAt?.toISOString() ?? null,
42
+ updatedAt: document.updatedAt.toISOString()
43
+ };
44
+ }
45
+ function assertActor(input, ctx) {
46
+ if (resolveDocumentsCommandActor(ctx) !== input.actorUserId) {
47
+ throw new CrudHttpError(403, { error: "Forbidden" });
48
+ }
49
+ }
50
+ async function assertCanArchive(ctx, document, input) {
51
+ const scope = resolveDocumentsCommandScope(ctx, input);
52
+ const features = await resolveDocumentsCommandFeatures(ctx, scope);
53
+ const ownsDocument = document.ownerUserId === resolveDocumentsCommandActor(ctx);
54
+ const managerOverride = hasAllFeatures(["documents.manage"], features);
55
+ if (!(ownsDocument || managerOverride) || !hasAllFeatures(["documents.edit"], features)) {
56
+ throw new CrudHttpError(403, { error: "Forbidden" });
57
+ }
58
+ }
59
+ function assertLifecycleStateMatches(document, expected) {
60
+ if ((document.archivedAt?.toISOString() ?? null) !== expected.archivedAt) {
61
+ throw new CrudHttpError(409, { error: "Record changed by another user" });
62
+ }
63
+ }
64
+ function lifecycleEventProjection(transition, input, includeActor = true) {
65
+ return {
66
+ kind: "event",
67
+ eventId: transition === "archive" ? "documents.document.archived" : "documents.document.unarchived",
68
+ tenantId: input.tenantId,
69
+ organizationId: input.organizationId,
70
+ payload: {
71
+ id: input.documentId,
72
+ documentId: input.documentId,
73
+ tenantId: input.tenantId,
74
+ organizationId: input.organizationId,
75
+ ...includeActor ? { userId: input.actorUserId } : {}
76
+ }
77
+ };
78
+ }
79
+ function watcherProjections(transition, input, documentTitle, recipientUserIds) {
80
+ const bodyKey = transition === "archive" ? "documents.notifications.watch.changed.archivedBody" : "documents.notifications.watch.changed.unarchivedBody";
81
+ return recipientUserIds.map((recipientUserId) => ({
82
+ kind: "watch-notification",
83
+ recipientUserId,
84
+ tenantId: input.tenantId,
85
+ organizationId: input.organizationId,
86
+ documentId: input.documentId,
87
+ documentTitle,
88
+ notificationType: "documents.watch.changed",
89
+ bodyKey,
90
+ sourceEntityType: DOCUMENTS_ENTITY_IDS.document,
91
+ sourceEntityId: input.documentId,
92
+ linkHref: `/backend/documents/${encodeURIComponent(input.documentId)}`
93
+ }));
94
+ }
95
+ async function executeLifecycleTransition(rawInput, ctx, transition) {
96
+ const input = documentLifecycleCommandSchema.parse(rawInput);
97
+ const scope = resolveDocumentsCommandScope(ctx, input);
98
+ const em = resolveDocumentsCommandEntityManager(ctx);
99
+ const shouldArchive = transition === "archive";
100
+ let document = null;
101
+ let before = null;
102
+ let after = null;
103
+ let changed = false;
104
+ await withAtomicFlush(em, [async () => {
105
+ document = await lockDocumentAggregateRoot(em, input.documentId, scope);
106
+ assertActor(input, ctx);
107
+ await assertCanArchive(ctx, document, input);
108
+ if (input.redoExpectation) {
109
+ assertLifecycleStateMatches(document, input.redoExpectation);
110
+ } else {
111
+ await enforceCommandOptimisticLockWithGuards(ctx.container, {
112
+ resourceKind: DOCUMENTS_ENTITY_IDS.document,
113
+ resourceId: document.id,
114
+ current: document.updatedAt,
115
+ expected: input.expectedUpdatedAt,
116
+ request: ctx.request ?? null
117
+ });
118
+ }
119
+ before = captureLifecycleState(document);
120
+ if ((document.archivedAt !== null && document.archivedAt !== void 0) === shouldArchive) {
121
+ after = before;
122
+ return;
123
+ }
124
+ const version = nextDocumentVersion(document.updatedAt);
125
+ document.archivedAt = shouldArchive ? version : null;
126
+ document.updatedAt = version;
127
+ changed = true;
128
+ }, () => {
129
+ if (!document) throw new Error("[internal] document lifecycle transition produced no row");
130
+ after = captureLifecycleState(document);
131
+ }], { transaction: true, label: `documents.document.${transition}` });
132
+ const finalDocument = document;
133
+ const beforeState = before;
134
+ const afterState = after;
135
+ if (!finalDocument || !beforeState || !afterState) {
136
+ throw new Error("[internal] document lifecycle transition produced no snapshot");
137
+ }
138
+ const recipientUserIds = changed ? await resolveWatcherRecipients({
139
+ em,
140
+ container: ctx.container,
141
+ scope,
142
+ documentId: input.documentId,
143
+ actorUserId: input.actorUserId
144
+ }) : [];
145
+ const projections = changed ? [
146
+ lifecycleEventProjection(transition, input),
147
+ ...watcherProjections(transition, input, finalDocument.title, recipientUserIds)
148
+ ] : [];
149
+ const undoTransition = transition === "archive" ? "unarchive" : "archive";
150
+ const projectionsAfterUndo = changed ? [
151
+ lifecycleEventProjection(undoTransition, input, false),
152
+ // Undo may run long after the archive flip; resolve watchers and the
153
+ // title at delivery time instead of replaying the execute-time set.
154
+ {
155
+ kind: "watch-notification-fanout",
156
+ tenantId: input.tenantId,
157
+ organizationId: input.organizationId,
158
+ documentId: input.documentId,
159
+ actorUserId: input.actorUserId,
160
+ notificationType: "documents.watch.changed",
161
+ bodyKey: undoTransition === "archive" ? "documents.notifications.watch.changed.archivedBody" : "documents.notifications.watch.changed.unarchivedBody",
162
+ sourceEntityType: DOCUMENTS_ENTITY_IDS.document,
163
+ sourceEntityId: input.documentId,
164
+ linkHref: `/backend/documents/${encodeURIComponent(input.documentId)}`
165
+ }
166
+ ] : [];
167
+ return {
168
+ id: finalDocument.id,
169
+ archivedAt: afterState.archivedAt,
170
+ updatedAt: afterState.updatedAt,
171
+ changed,
172
+ before: beforeState,
173
+ after: afterState,
174
+ projections,
175
+ projectionsAfterUndo
176
+ };
177
+ }
178
+ function readRedoInput(logEntry) {
179
+ const raw = logEntry.commandPayload && typeof logEntry.commandPayload === "object" ? logEntry.commandPayload.__redoInput : null;
180
+ return documentLifecycleCommandSchema.parse(raw);
181
+ }
182
+ function buildLifecycleCommand(transition) {
183
+ const inverseTransition = transition === "archive" ? "unarchive" : "archive";
184
+ return {
185
+ id: `documents.document.${transition}`,
186
+ async execute(rawInput, ctx) {
187
+ return executeLifecycleTransition(rawInput, ctx, transition);
188
+ },
189
+ async buildLog({ input, result }) {
190
+ if (!result.changed) return { skipLog: true };
191
+ const before = lifecycleStateSchema.parse(result.before);
192
+ const after = lifecycleStateSchema.parse(result.after);
193
+ const { translate } = await resolveTranslations();
194
+ return {
195
+ actionLabel: transition === "archive" ? translate("documents.audit.documentArchived", "Archive document") : translate("documents.audit.documentUnarchived", "Unarchive document"),
196
+ resourceKind: DOCUMENTS_ENTITY_IDS.document,
197
+ resourceId: result.id,
198
+ tenantId: input.tenantId,
199
+ organizationId: input.organizationId,
200
+ snapshotBefore: before,
201
+ snapshotAfter: after,
202
+ payload: {
203
+ undo: {
204
+ before,
205
+ after,
206
+ projectionsAfterUndo: result.projectionsAfterUndo ?? []
207
+ },
208
+ __redoInput: {
209
+ ...input,
210
+ expectedUpdatedAt: null,
211
+ redoExpectation: { archivedAt: before.archivedAt }
212
+ }
213
+ }
214
+ };
215
+ },
216
+ async undo({ logEntry, ctx }) {
217
+ const undo = extractUndoPayload(logEntry);
218
+ if (!undo?.before || !undo.after) return;
219
+ const input = readRedoInput(logEntry);
220
+ const scope = resolveDocumentsCommandScope(ctx, input);
221
+ const em = resolveDocumentsCommandEntityManager(ctx);
222
+ await withAtomicFlush(em, [async () => {
223
+ const document = await lockDocumentAggregateRoot(em, input.documentId, scope);
224
+ assertActor(input, ctx);
225
+ await assertCanArchive(ctx, document, input);
226
+ assertOptimisticLock({
227
+ resourceKind: DOCUMENTS_ENTITY_IDS.document,
228
+ resourceId: document.id,
229
+ current: document.updatedAt,
230
+ expected: undo.after.updatedAt,
231
+ envValue: "all"
232
+ });
233
+ assertLifecycleStateMatches(document, undo.after);
234
+ document.archivedAt = undo.before.archivedAt ? new Date(undo.before.archivedAt) : null;
235
+ document.updatedAt = nextDocumentVersion(document.updatedAt);
236
+ }], { transaction: true, label: `documents.document.${transition}.undo` });
237
+ }
238
+ };
239
+ }
240
+ const archiveDocumentCommand = buildLifecycleCommand("archive");
241
+ const unarchiveDocumentCommand = buildLifecycleCommand("unarchive");
242
+ registerCommand(archiveDocumentCommand);
243
+ registerCommand(unarchiveDocumentCommand);
244
+ export {
245
+ archiveDocumentCommand,
246
+ documentLifecycleCommandSchema,
247
+ unarchiveDocumentCommand
248
+ };
249
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/documents/commands/lifecycle.ts"],
4
+ "sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { z } from 'zod'\nimport {\n registerCommand,\n type CommandHandler,\n type CommandRuntimeContext,\n} from '@open-mercato/shared/lib/commands'\nimport { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'\nimport { extractUndoPayload } from '@open-mercato/shared/lib/commands/undo'\nimport { hasAllFeatures } from '@open-mercato/shared/lib/auth/featureMatch'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport {\n assertOptimisticLock,\n enforceCommandOptimisticLockWithGuards,\n} from '@open-mercato/shared/lib/crud/optimistic-lock-command'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { Document } from '../data/entities'\nimport { DOCUMENTS_ENTITY_IDS } from '../lib/constants'\nimport { resolveWatcherRecipients } from '../lib/watchers'\nimport { lockDocumentAggregateRoot } from './aggregate'\nimport { nextDocumentVersion } from './mutation-helpers'\nimport type { DocumentsProjectionDescriptor } from './projection-types'\nimport {\n resolveDocumentsCommandActor,\n resolveDocumentsCommandEntityManager,\n resolveDocumentsCommandFeatures,\n resolveDocumentsCommandScope,\n} from './shared'\n\nconst lifecycleStateSchema = z.object({\n archivedAt: z.string().datetime().nullable(),\n updatedAt: z.string().datetime(),\n})\n\nconst lifecycleRedoExpectationSchema = z.object({\n archivedAt: z.string().datetime().nullable(),\n})\n\nexport const documentLifecycleCommandSchema = z.object({\n tenantId: z.string().uuid(),\n organizationId: z.string().uuid(),\n documentId: z.string().uuid(),\n actorUserId: z.string().uuid(),\n expectedUpdatedAt: z.string().datetime().nullable().optional(),\n redoExpectation: lifecycleRedoExpectationSchema.optional(),\n})\n\nexport type DocumentLifecycleCommandInput = z.infer<typeof documentLifecycleCommandSchema>\ntype DocumentLifecycleState = z.infer<typeof lifecycleStateSchema>\n\nexport type DocumentLifecycleCommandResult = {\n id: string\n archivedAt: string | null\n updatedAt: string\n changed: boolean\n before: DocumentLifecycleState\n after: DocumentLifecycleState\n projections?: DocumentsProjectionDescriptor[]\n projectionsAfterUndo?: DocumentsProjectionDescriptor[]\n}\n\ntype DocumentLifecycleUndoPayload = {\n before?: DocumentLifecycleState | null\n after?: DocumentLifecycleState | null\n projectionsAfterUndo?: DocumentsProjectionDescriptor[]\n}\n\ntype LifecycleTransition = 'archive' | 'unarchive'\n\nfunction captureLifecycleState(document: Document): DocumentLifecycleState {\n return {\n archivedAt: document.archivedAt?.toISOString() ?? null,\n updatedAt: document.updatedAt.toISOString(),\n }\n}\n\nfunction assertActor(input: DocumentLifecycleCommandInput, ctx: CommandRuntimeContext): void {\n if (resolveDocumentsCommandActor(ctx) !== input.actorUserId) {\n throw new CrudHttpError(403, { error: 'Forbidden' })\n }\n}\n\nasync function assertCanArchive(\n ctx: CommandRuntimeContext,\n document: Document,\n input: DocumentLifecycleCommandInput,\n): Promise<void> {\n const scope = resolveDocumentsCommandScope(ctx, input)\n const features = await resolveDocumentsCommandFeatures(ctx, scope)\n const ownsDocument = document.ownerUserId === resolveDocumentsCommandActor(ctx)\n const managerOverride = hasAllFeatures(['documents.manage'], features)\n if (\n !(ownsDocument || managerOverride)\n || !hasAllFeatures(['documents.edit'], features)\n ) {\n throw new CrudHttpError(403, { error: 'Forbidden' })\n }\n}\n\nfunction assertLifecycleStateMatches(\n document: Document,\n expected: Pick<DocumentLifecycleState, 'archivedAt'>,\n): void {\n if ((document.archivedAt?.toISOString() ?? null) !== expected.archivedAt) {\n throw new CrudHttpError(409, { error: 'Record changed by another user' })\n }\n}\n\nfunction lifecycleEventProjection(\n transition: LifecycleTransition,\n input: DocumentLifecycleCommandInput,\n includeActor = true,\n): DocumentsProjectionDescriptor {\n return {\n kind: 'event',\n eventId: transition === 'archive'\n ? 'documents.document.archived'\n : 'documents.document.unarchived',\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n payload: {\n id: input.documentId,\n documentId: input.documentId,\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n ...(includeActor ? { userId: input.actorUserId } : {}),\n },\n }\n}\n\nfunction watcherProjections(\n transition: LifecycleTransition,\n input: DocumentLifecycleCommandInput,\n documentTitle: string,\n recipientUserIds: readonly string[],\n): DocumentsProjectionDescriptor[] {\n const bodyKey = transition === 'archive'\n ? 'documents.notifications.watch.changed.archivedBody'\n : 'documents.notifications.watch.changed.unarchivedBody'\n return recipientUserIds.map((recipientUserId) => ({\n kind: 'watch-notification',\n recipientUserId,\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n documentId: input.documentId,\n documentTitle,\n notificationType: 'documents.watch.changed',\n bodyKey,\n sourceEntityType: DOCUMENTS_ENTITY_IDS.document,\n sourceEntityId: input.documentId,\n linkHref: `/backend/documents/${encodeURIComponent(input.documentId)}`,\n }))\n}\n\nasync function executeLifecycleTransition(\n rawInput: DocumentLifecycleCommandInput,\n ctx: CommandRuntimeContext,\n transition: LifecycleTransition,\n): Promise<DocumentLifecycleCommandResult> {\n const input = documentLifecycleCommandSchema.parse(rawInput)\n const scope = resolveDocumentsCommandScope(ctx, input)\n const em = resolveDocumentsCommandEntityManager(ctx)\n const shouldArchive = transition === 'archive'\n let document: Document | null = null\n let before: DocumentLifecycleState | null = null\n let after: DocumentLifecycleState | null = null\n let changed = false\n\n await withAtomicFlush(em, [async () => {\n document = await lockDocumentAggregateRoot(em, input.documentId, scope)\n assertActor(input, ctx)\n await assertCanArchive(ctx, document, input)\n if (input.redoExpectation) {\n assertLifecycleStateMatches(document, input.redoExpectation)\n } else {\n await enforceCommandOptimisticLockWithGuards(ctx.container, {\n resourceKind: DOCUMENTS_ENTITY_IDS.document,\n resourceId: document.id,\n current: document.updatedAt,\n expected: input.expectedUpdatedAt,\n request: ctx.request ?? null,\n })\n }\n\n before = captureLifecycleState(document)\n if ((document.archivedAt !== null && document.archivedAt !== undefined) === shouldArchive) {\n after = before\n return\n }\n\n const version = nextDocumentVersion(document.updatedAt)\n document.archivedAt = shouldArchive ? version : null\n document.updatedAt = version\n changed = true\n }, () => {\n if (!document) throw new Error('[internal] document lifecycle transition produced no row')\n after = captureLifecycleState(document)\n }], { transaction: true, label: `documents.document.${transition}` })\n\n const finalDocument = document as Document | null\n const beforeState = before as DocumentLifecycleState | null\n const afterState = after as DocumentLifecycleState | null\n if (!finalDocument || !beforeState || !afterState) {\n throw new Error('[internal] document lifecycle transition produced no snapshot')\n }\n\n const recipientUserIds = changed\n ? await resolveWatcherRecipients({\n em,\n container: ctx.container,\n scope,\n documentId: input.documentId,\n actorUserId: input.actorUserId,\n })\n : []\n const projections = changed\n ? [\n lifecycleEventProjection(transition, input),\n ...watcherProjections(transition, input, finalDocument.title, recipientUserIds),\n ]\n : []\n const undoTransition: LifecycleTransition = transition === 'archive' ? 'unarchive' : 'archive'\n const projectionsAfterUndo: DocumentsProjectionDescriptor[] = changed\n ? [\n lifecycleEventProjection(undoTransition, input, false),\n // Undo may run long after the archive flip; resolve watchers and the\n // title at delivery time instead of replaying the execute-time set.\n {\n kind: 'watch-notification-fanout',\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n documentId: input.documentId,\n actorUserId: input.actorUserId,\n notificationType: 'documents.watch.changed',\n bodyKey: undoTransition === 'archive'\n ? 'documents.notifications.watch.changed.archivedBody'\n : 'documents.notifications.watch.changed.unarchivedBody',\n sourceEntityType: DOCUMENTS_ENTITY_IDS.document,\n sourceEntityId: input.documentId,\n linkHref: `/backend/documents/${encodeURIComponent(input.documentId)}`,\n },\n ]\n : []\n return {\n id: finalDocument.id,\n archivedAt: afterState.archivedAt,\n updatedAt: afterState.updatedAt,\n changed,\n before: beforeState,\n after: afterState,\n projections,\n projectionsAfterUndo,\n }\n}\n\nfunction readRedoInput(logEntry: { commandPayload?: unknown }): DocumentLifecycleCommandInput {\n const raw = logEntry.commandPayload && typeof logEntry.commandPayload === 'object'\n ? (logEntry.commandPayload as { __redoInput?: unknown }).__redoInput\n : null\n return documentLifecycleCommandSchema.parse(raw)\n}\n\nfunction buildLifecycleCommand(transition: LifecycleTransition): CommandHandler<\n DocumentLifecycleCommandInput,\n DocumentLifecycleCommandResult\n> {\n const inverseTransition: LifecycleTransition = transition === 'archive' ? 'unarchive' : 'archive'\n return {\n id: `documents.document.${transition}`,\n async execute(rawInput, ctx) {\n return executeLifecycleTransition(rawInput, ctx, transition)\n },\n async buildLog({ input, result }) {\n if (!result.changed) return { skipLog: true }\n const before = lifecycleStateSchema.parse(result.before)\n const after = lifecycleStateSchema.parse(result.after)\n const { translate } = await resolveTranslations()\n return {\n actionLabel: transition === 'archive'\n ? translate('documents.audit.documentArchived', 'Archive document')\n : translate('documents.audit.documentUnarchived', 'Unarchive document'),\n resourceKind: DOCUMENTS_ENTITY_IDS.document,\n resourceId: result.id,\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n snapshotBefore: before,\n snapshotAfter: after,\n payload: {\n undo: {\n before,\n after,\n projectionsAfterUndo: result.projectionsAfterUndo ?? [],\n } satisfies DocumentLifecycleUndoPayload,\n __redoInput: {\n ...input,\n expectedUpdatedAt: null,\n redoExpectation: { archivedAt: before.archivedAt },\n } satisfies DocumentLifecycleCommandInput,\n },\n }\n },\n async undo({ logEntry, ctx }) {\n const undo = extractUndoPayload<DocumentLifecycleUndoPayload>(logEntry)\n if (!undo?.before || !undo.after) return\n const input = readRedoInput(logEntry)\n const scope = resolveDocumentsCommandScope(ctx, input)\n const em: EntityManager = resolveDocumentsCommandEntityManager(ctx)\n await withAtomicFlush(em, [async () => {\n const document = await lockDocumentAggregateRoot(em, input.documentId, scope)\n assertActor(input, ctx)\n await assertCanArchive(ctx, document, input)\n assertOptimisticLock({\n resourceKind: DOCUMENTS_ENTITY_IDS.document,\n resourceId: document.id,\n current: document.updatedAt,\n expected: undo.after!.updatedAt,\n envValue: 'all',\n })\n assertLifecycleStateMatches(document, undo.after!)\n document.archivedAt = undo.before!.archivedAt\n ? new Date(undo.before!.archivedAt)\n : null\n document.updatedAt = nextDocumentVersion(document.updatedAt)\n }], { transaction: true, label: `documents.document.${transition}.undo` })\n },\n }\n}\n\nexport const archiveDocumentCommand = buildLifecycleCommand('archive')\nexport const unarchiveDocumentCommand = buildLifecycleCommand('unarchive')\n\nregisterCommand(archiveDocumentCommand)\nregisterCommand(un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