@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,410 @@
1
+ import { LockMode } from "@mikro-orm/core";
2
+ import { z } from "zod";
3
+ import { registerCommand } from "@open-mercato/shared/lib/commands";
4
+ import { extractUndoPayload } from "@open-mercato/shared/lib/commands/undo";
5
+ import { withAtomicFlush } from "@open-mercato/shared/lib/commands/flush";
6
+ import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
7
+ import {
8
+ assertOptimisticLock,
9
+ buildOptimisticLockConflictBody,
10
+ enforceCommandOptimisticLockWithGuards
11
+ } from "@open-mercato/shared/lib/crud/optimistic-lock-command";
12
+ import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
13
+ import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
14
+ import { DocumentEntityLink } from "../data/entities.js";
15
+ import { documentEntityLinkCreateSchema } from "../data/validators.js";
16
+ import { DOCUMENTS_ENTITY_IDS } from "../lib/constants.js";
17
+ import {
18
+ assertDocumentEntityLinkCapacity,
19
+ buildDocumentEntityLinkTargetWhere,
20
+ createDocumentEntityLinkData,
21
+ getDocumentEntityLinkEntityId,
22
+ getDocumentEntityLinkType
23
+ } from "../lib/entityLinks.js";
24
+ import { getEntityRegistryEntry } from "../lib/entityRegistry.js";
25
+ import { isDocumentEntityRegistryModuleEnabled } from "../lib/entityRegistryAvailability.server.js";
26
+ import {
27
+ verifyEntityRegistrySelection
28
+ } from "../lib/entityRegistry.server.js";
29
+ import { lockDocumentAggregateRoot } from "./aggregate.js";
30
+ import { bufferLinkMutationSideEffects } from "./side-effects.js";
31
+ import {
32
+ assertCommandFeature,
33
+ assertDocumentCommandCanEdit,
34
+ resolveDocumentsCommandActor,
35
+ resolveDocumentsCommandEntityManager,
36
+ resolveDocumentsCommandFeatures,
37
+ resolveDocumentsCommandScope
38
+ } from "./shared.js";
39
+ import { nextDocumentVersion } from "./mutation-helpers.js";
40
+ const scopedSchema = z.object({
41
+ tenantId: z.string().uuid(),
42
+ organizationId: z.string().uuid()
43
+ });
44
+ const linkCreateCommandSchema = scopedSchema.extend({
45
+ linkId: z.string().uuid(),
46
+ documentId: z.string().uuid(),
47
+ link: documentEntityLinkCreateSchema
48
+ });
49
+ const linkDeleteCommandSchema = scopedSchema.extend({
50
+ documentId: z.string().uuid(),
51
+ linkId: z.string().uuid()
52
+ });
53
+ function buildCanonicalLinkInput(input, verified) {
54
+ return {
55
+ ...input,
56
+ link: {
57
+ ...input.link,
58
+ label: verified.label,
59
+ href: verified.href
60
+ }
61
+ };
62
+ }
63
+ function assertVerifiedLinkTargetMatchesRow(verified, link) {
64
+ if (verified.id !== getDocumentEntityLinkEntityId(link)) {
65
+ throw new CrudHttpError(409, { error: "Record changed by another user" });
66
+ }
67
+ }
68
+ function captureLinkState(link, fallbackId) {
69
+ return {
70
+ id: link?.id ?? fallbackId,
71
+ existed: link !== null,
72
+ deletedAt: link?.deletedAt?.toISOString() ?? null,
73
+ updatedAt: link?.updatedAt?.toISOString() ?? null
74
+ };
75
+ }
76
+ function assertLinkStateUnchanged(link, expected) {
77
+ if (!expected.updatedAt) throw new CrudHttpError(409, { error: "Record changed by another user" });
78
+ assertOptimisticLock({
79
+ resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,
80
+ resourceId: link.id,
81
+ current: link.updatedAt,
82
+ expected: expected.updatedAt,
83
+ envValue: "all"
84
+ });
85
+ const deletedAt = link.deletedAt?.toISOString() ?? null;
86
+ if (deletedAt !== expected.deletedAt) {
87
+ throw new CrudHttpError(409, buildOptimisticLockConflictBody(
88
+ link.updatedAt.toISOString(),
89
+ expected.updatedAt
90
+ ));
91
+ }
92
+ }
93
+ async function authorizeLinkCreateUndo(ctx, em, input, entityType) {
94
+ const scope = resolveDocumentsCommandScope(ctx, input);
95
+ const features = await assertDocumentCommandCanEdit(ctx, em, input.documentId, scope);
96
+ const registryEntry = getEntityRegistryEntry(entityType);
97
+ if (!registryEntry) throw new CrudHttpError(400, { error: "documents.links.invalidEntityType" });
98
+ if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {
99
+ throw new CrudHttpError(403, { error: "documents.links.targetRestricted" });
100
+ }
101
+ assertCommandFeature(features, registryEntry.requiredFeature);
102
+ }
103
+ async function loadLinkById(em, input, includeDeleted = false, lock = false) {
104
+ return findOneWithDecryption(
105
+ em,
106
+ DocumentEntityLink,
107
+ {
108
+ id: input.linkId,
109
+ documentId: input.documentId,
110
+ tenantId: input.tenantId,
111
+ organizationId: input.organizationId,
112
+ ...includeDeleted ? {} : { deletedAt: null }
113
+ },
114
+ {
115
+ ...includeDeleted ? { filters: false } : {},
116
+ ...lock ? { lockMode: LockMode.PESSIMISTIC_WRITE } : {}
117
+ },
118
+ { tenantId: input.tenantId, organizationId: input.organizationId }
119
+ );
120
+ }
121
+ async function loadLinkByTarget(em, input, lock = false) {
122
+ return findOneWithDecryption(
123
+ em,
124
+ DocumentEntityLink,
125
+ {
126
+ documentId: input.documentId,
127
+ tenantId: input.tenantId,
128
+ organizationId: input.organizationId,
129
+ ...buildDocumentEntityLinkTargetWhere(input.link.entityType, input.link.entityId)
130
+ },
131
+ {
132
+ filters: false,
133
+ orderBy: { updatedAt: "DESC" },
134
+ ...lock ? { lockMode: LockMode.PESSIMISTIC_WRITE } : {}
135
+ },
136
+ { tenantId: input.tenantId, organizationId: input.organizationId }
137
+ );
138
+ }
139
+ const createLinkCommand = {
140
+ id: "documents.link.create",
141
+ async execute(rawInput, ctx) {
142
+ const input = linkCreateCommandSchema.parse(rawInput);
143
+ const scope = resolveDocumentsCommandScope(ctx, input);
144
+ const registryEntry = getEntityRegistryEntry(input.link.entityType);
145
+ if (!registryEntry) {
146
+ throw new CrudHttpError(400, { error: "documents.links.invalidEntityType" });
147
+ }
148
+ if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {
149
+ throw new CrudHttpError(403, { error: "documents.links.targetRestricted" });
150
+ }
151
+ const preflightFeatures = await resolveDocumentsCommandFeatures(ctx, scope);
152
+ assertCommandFeature(preflightFeatures, registryEntry.requiredFeature);
153
+ const request = ctx.request;
154
+ if (!request) {
155
+ throw new CrudHttpError(503, { error: "documents.links.targetUnavailable" });
156
+ }
157
+ const verified = await verifyEntityRegistrySelection(request, input.link);
158
+ const canonicalInput = buildCanonicalLinkInput(input, verified);
159
+ const writeEm = resolveDocumentsCommandEntityManager(ctx);
160
+ let link = null;
161
+ let created = false;
162
+ let before;
163
+ let after;
164
+ await withAtomicFlush(writeEm, [
165
+ async () => {
166
+ await lockDocumentAggregateRoot(writeEm, input.documentId, scope);
167
+ const features = await assertDocumentCommandCanEdit(ctx, writeEm, input.documentId, scope);
168
+ if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {
169
+ throw new CrudHttpError(403, { error: "documents.links.targetRestricted" });
170
+ }
171
+ assertCommandFeature(features, registryEntry.requiredFeature);
172
+ const existing = await loadLinkByTarget(writeEm, canonicalInput, true);
173
+ before = captureLinkState(existing, input.linkId);
174
+ if (existing && !existing.deletedAt) {
175
+ link = existing;
176
+ return;
177
+ }
178
+ await assertDocumentEntityLinkCapacity(writeEm, input.documentId, scope);
179
+ link = existing ?? writeEm.create(
180
+ DocumentEntityLink,
181
+ createDocumentEntityLinkData({
182
+ id: input.linkId,
183
+ documentId: input.documentId,
184
+ scope,
185
+ actorUserId: resolveDocumentsCommandActor(ctx),
186
+ link: canonicalInput.link
187
+ })
188
+ );
189
+ if (!existing) writeEm.persist(link);
190
+ link.labelSnapshot = canonicalInput.link.label;
191
+ link.hrefSnapshot = canonicalInput.link.href;
192
+ link.source = canonicalInput.link.source;
193
+ link.createdByUserId = resolveDocumentsCommandActor(ctx);
194
+ link.deletedAt = null;
195
+ link.updatedAt = nextDocumentVersion(link.updatedAt);
196
+ created = true;
197
+ },
198
+ () => {
199
+ const captured = link;
200
+ if (!captured) throw new Error("[internal] document link create produced no row");
201
+ after = captureLinkState(captured, captured.id);
202
+ }
203
+ ], { transaction: true, label: "documents.link.create" });
204
+ const finalLink = link;
205
+ if (!finalLink) throw new Error("[internal] document link create produced no row");
206
+ if (!created) {
207
+ return {
208
+ id: finalLink.id,
209
+ created: false,
210
+ updatedAt: finalLink.updatedAt.toISOString(),
211
+ before,
212
+ after
213
+ };
214
+ }
215
+ await bufferLinkMutationSideEffects(ctx, "created", finalLink, {
216
+ entityType: input.link.entityType,
217
+ entityId: input.link.entityId
218
+ });
219
+ return {
220
+ id: finalLink.id,
221
+ created: true,
222
+ updatedAt: finalLink.updatedAt.toISOString(),
223
+ before,
224
+ after
225
+ };
226
+ },
227
+ async buildLog({ input, result }) {
228
+ if (!result.created) return { skipLog: true };
229
+ const { translate } = await resolveTranslations();
230
+ return {
231
+ actionLabel: translate("documents.audit.linkCreated", "Link document to record"),
232
+ resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,
233
+ resourceId: result.id,
234
+ parentResourceKind: DOCUMENTS_ENTITY_IDS.document,
235
+ parentResourceId: input.documentId,
236
+ tenantId: input.tenantId,
237
+ organizationId: input.organizationId,
238
+ snapshotBefore: result.before,
239
+ snapshotAfter: result.after,
240
+ payload: {
241
+ undo: {
242
+ before: result.before,
243
+ after: result.after,
244
+ createdByCommand: result.created
245
+ }
246
+ }
247
+ };
248
+ },
249
+ async undo({ logEntry, ctx }) {
250
+ const undo = extractUndoPayload(logEntry);
251
+ if (!undo?.createdByCommand) return;
252
+ const before = undo?.before;
253
+ const after = undo?.after;
254
+ if (!after || before?.existed && before.deletedAt === null) return;
255
+ const input = linkCreateCommandSchema.parse(
256
+ logEntry.commandPayload && typeof logEntry.commandPayload === "object" ? logEntry.commandPayload.__redoInput : {}
257
+ );
258
+ const em = resolveDocumentsCommandEntityManager(ctx);
259
+ let link = null;
260
+ await withAtomicFlush(em, [async () => {
261
+ await lockDocumentAggregateRoot(em, input.documentId, {
262
+ tenantId: input.tenantId,
263
+ organizationId: input.organizationId
264
+ });
265
+ await authorizeLinkCreateUndo(ctx, em, input, input.link.entityType);
266
+ link = await loadLinkById(em, { ...input, linkId: after.id }, true, true);
267
+ if (!link) throw new CrudHttpError(409, { error: "Record changed by another user" });
268
+ assertLinkStateUnchanged(link, after);
269
+ const version = nextDocumentVersion(link.updatedAt);
270
+ link.deletedAt = before?.deletedAt ? new Date(before.deletedAt) : version;
271
+ link.updatedAt = version;
272
+ }], { transaction: true, label: "documents.link.create.undo" });
273
+ if (link) await bufferLinkMutationSideEffects(ctx, "deleted", link, { undo: true });
274
+ }
275
+ };
276
+ const deleteLinkCommand = {
277
+ id: "documents.link.delete",
278
+ async execute(rawInput, ctx) {
279
+ const input = linkDeleteCommandSchema.parse(rawInput);
280
+ const scope = resolveDocumentsCommandScope(ctx, input);
281
+ const em = resolveDocumentsCommandEntityManager(ctx);
282
+ let link = null;
283
+ let before;
284
+ let after;
285
+ await withAtomicFlush(em, [
286
+ async () => {
287
+ await lockDocumentAggregateRoot(em, input.documentId, scope);
288
+ await assertDocumentCommandCanEdit(ctx, em, input.documentId, scope);
289
+ link = await loadLinkById(em, input, false, true);
290
+ if (!link) throw new CrudHttpError(404, { error: "documents.links.notFound" });
291
+ before = captureLinkState(link, input.linkId);
292
+ await enforceCommandOptimisticLockWithGuards(ctx.container, {
293
+ resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,
294
+ resourceId: link.id,
295
+ current: link.updatedAt,
296
+ request: ctx.request ?? null
297
+ });
298
+ const version = nextDocumentVersion(link.updatedAt);
299
+ link.deletedAt = version;
300
+ link.updatedAt = version;
301
+ },
302
+ () => {
303
+ const captured = link;
304
+ if (!captured) throw new Error("[internal] document link delete produced no row");
305
+ after = captureLinkState(captured, captured.id);
306
+ }
307
+ ], { transaction: true, label: "documents.link.delete" });
308
+ const deletedLink = link;
309
+ if (!deletedLink) throw new Error("[internal] document link delete produced no row");
310
+ await bufferLinkMutationSideEffects(ctx, "deleted", deletedLink);
311
+ return {
312
+ id: deletedLink.id,
313
+ updatedAt: deletedLink.updatedAt.toISOString(),
314
+ before,
315
+ after
316
+ };
317
+ },
318
+ async buildLog({ input, result }) {
319
+ const { translate } = await resolveTranslations();
320
+ return {
321
+ actionLabel: translate("documents.audit.linkDeleted", "Unlink document from record"),
322
+ resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,
323
+ resourceId: result.id,
324
+ parentResourceKind: DOCUMENTS_ENTITY_IDS.document,
325
+ parentResourceId: input.documentId,
326
+ tenantId: input.tenantId,
327
+ organizationId: input.organizationId,
328
+ snapshotBefore: result.before,
329
+ snapshotAfter: result.after,
330
+ payload: {
331
+ undo: {
332
+ before: result.before,
333
+ after: result.after
334
+ }
335
+ }
336
+ };
337
+ },
338
+ async undo({ logEntry, ctx }) {
339
+ const undo = extractUndoPayload(logEntry);
340
+ const before = undo?.before;
341
+ const after = undo?.after;
342
+ if (!before?.existed || before.deletedAt !== null) return;
343
+ const input = linkDeleteCommandSchema.parse(
344
+ logEntry.commandPayload && typeof logEntry.commandPayload === "object" ? logEntry.commandPayload.__redoInput : {}
345
+ );
346
+ const em = resolveDocumentsCommandEntityManager(ctx);
347
+ if (!after) throw new CrudHttpError(409, { error: "Record changed by another user" });
348
+ const preflightLink = await loadLinkById(
349
+ ctx.container.resolve("em").fork(),
350
+ input,
351
+ true
352
+ );
353
+ if (!preflightLink) throw new CrudHttpError(409, { error: "Record changed by another user" });
354
+ const preflightRegistryEntry = getEntityRegistryEntry(getDocumentEntityLinkType(preflightLink));
355
+ if (!preflightRegistryEntry) {
356
+ throw new CrudHttpError(400, { error: "documents.links.invalidEntityType" });
357
+ }
358
+ if (!isDocumentEntityRegistryModuleEnabled(preflightRegistryEntry)) {
359
+ throw new CrudHttpError(403, { error: "documents.links.targetRestricted" });
360
+ }
361
+ if (!ctx.request) {
362
+ throw new CrudHttpError(503, { error: "documents.links.targetUnavailable" });
363
+ }
364
+ const verified = await verifyEntityRegistrySelection(ctx.request, {
365
+ entityType: preflightRegistryEntry.type,
366
+ entityId: getDocumentEntityLinkEntityId(preflightLink),
367
+ label: preflightLink.labelSnapshot,
368
+ href: preflightLink.hrefSnapshot
369
+ });
370
+ let link = null;
371
+ await withAtomicFlush(em, [async () => {
372
+ await lockDocumentAggregateRoot(em, input.documentId, {
373
+ tenantId: input.tenantId,
374
+ organizationId: input.organizationId
375
+ });
376
+ const features = await assertDocumentCommandCanEdit(ctx, em, input.documentId, {
377
+ tenantId: input.tenantId,
378
+ organizationId: input.organizationId
379
+ });
380
+ link = await loadLinkById(em, input, true, true);
381
+ if (!link) throw new CrudHttpError(409, { error: "Record changed by another user" });
382
+ assertLinkStateUnchanged(link, after);
383
+ const registryEntry = getEntityRegistryEntry(getDocumentEntityLinkType(link));
384
+ if (!registryEntry) throw new CrudHttpError(400, { error: "documents.links.invalidEntityType" });
385
+ if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {
386
+ throw new CrudHttpError(403, { error: "documents.links.targetRestricted" });
387
+ }
388
+ assertCommandFeature(features, registryEntry.requiredFeature);
389
+ assertVerifiedLinkTargetMatchesRow(verified, link);
390
+ await assertDocumentEntityLinkCapacity(em, input.documentId, {
391
+ tenantId: input.tenantId,
392
+ organizationId: input.organizationId
393
+ });
394
+ link.labelSnapshot = verified.label;
395
+ link.hrefSnapshot = verified.href;
396
+ link.deletedAt = null;
397
+ link.updatedAt = nextDocumentVersion(link.updatedAt);
398
+ }], { transaction: true, label: "documents.link.delete.undo" });
399
+ if (link) await bufferLinkMutationSideEffects(ctx, "created", link, { undo: true });
400
+ }
401
+ };
402
+ registerCommand(createLinkCommand);
403
+ registerCommand(deleteLinkCommand);
404
+ export {
405
+ createLinkCommand,
406
+ deleteLinkCommand,
407
+ linkCreateCommandSchema,
408
+ linkDeleteCommandSchema
409
+ };
410
+ //# sourceMappingURL=links.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/documents/commands/links.ts"],
4
+ "sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { LockMode } from '@mikro-orm/core'\nimport { z } from 'zod'\nimport { registerCommand, type CommandHandler } from '@open-mercato/shared/lib/commands'\nimport { extractUndoPayload } from '@open-mercato/shared/lib/commands/undo'\nimport { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'\nimport { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport {\n assertOptimisticLock,\n buildOptimisticLockConflictBody,\n enforceCommandOptimisticLockWithGuards,\n} from '@open-mercato/shared/lib/crud/optimistic-lock-command'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { DocumentEntityLink } from '../data/entities'\nimport { documentEntityLinkCreateSchema } from '../data/validators'\nimport { DOCUMENTS_ENTITY_IDS } from '../lib/constants'\nimport {\n assertDocumentEntityLinkCapacity,\n buildDocumentEntityLinkTargetWhere,\n createDocumentEntityLinkData,\n getDocumentEntityLinkEntityId,\n getDocumentEntityLinkType,\n} from '../lib/entityLinks'\nimport { getEntityRegistryEntry } from '../lib/entityRegistry'\nimport { isDocumentEntityRegistryModuleEnabled } from '../lib/entityRegistryAvailability.server'\nimport {\n verifyEntityRegistrySelection,\n type VerifiedEntityRegistrySelection,\n} from '../lib/entityRegistry.server'\nimport { lockDocumentAggregateRoot } from './aggregate'\nimport { bufferLinkMutationSideEffects } from './side-effects'\nimport {\n assertCommandFeature,\n assertDocumentCommandCanEdit,\n resolveDocumentsCommandActor,\n resolveDocumentsCommandEntityManager,\n resolveDocumentsCommandFeatures,\n resolveDocumentsCommandScope,\n} from './shared'\nimport { nextDocumentVersion } from './mutation-helpers'\n\nconst scopedSchema = z.object({\n tenantId: z.string().uuid(),\n organizationId: z.string().uuid(),\n})\n\nexport const linkCreateCommandSchema = scopedSchema.extend({\n linkId: z.string().uuid(),\n documentId: z.string().uuid(),\n link: documentEntityLinkCreateSchema,\n})\n\nexport const linkDeleteCommandSchema = scopedSchema.extend({\n documentId: z.string().uuid(),\n linkId: z.string().uuid(),\n})\n\nexport type LinkCreateCommandInput = z.infer<typeof linkCreateCommandSchema>\nexport type LinkDeleteCommandInput = z.infer<typeof linkDeleteCommandSchema>\n\ntype LinkStateSnapshot = {\n id: string\n existed: boolean\n deletedAt: string | null\n updatedAt: string | null\n}\n\ntype LinkUndoPayload = {\n before?: LinkStateSnapshot | null\n after?: LinkStateSnapshot | null\n createdByCommand?: boolean\n}\n\nexport type LinkCreateCommandResult = {\n id: string\n created: boolean\n updatedAt: string\n before: LinkStateSnapshot\n after: LinkStateSnapshot\n}\n\nexport type LinkDeleteCommandResult = {\n id: string\n updatedAt: string\n before: LinkStateSnapshot\n after: LinkStateSnapshot\n}\n\nfunction buildCanonicalLinkInput(\n input: LinkCreateCommandInput,\n verified: VerifiedEntityRegistrySelection,\n): LinkCreateCommandInput {\n return {\n ...input,\n link: {\n ...input.link,\n label: verified.label,\n href: verified.href,\n },\n }\n}\n\nfunction assertVerifiedLinkTargetMatchesRow(\n verified: VerifiedEntityRegistrySelection,\n link: DocumentEntityLink,\n): void {\n if (verified.id !== getDocumentEntityLinkEntityId(link)) {\n throw new CrudHttpError(409, { error: 'Record changed by another user' })\n }\n}\n\nfunction captureLinkState(link: DocumentEntityLink | null, fallbackId: string): LinkStateSnapshot {\n return {\n id: link?.id ?? fallbackId,\n existed: link !== null,\n deletedAt: link?.deletedAt?.toISOString() ?? null,\n updatedAt: link?.updatedAt?.toISOString() ?? null,\n }\n}\n\nfunction assertLinkStateUnchanged(link: DocumentEntityLink, expected: LinkStateSnapshot): void {\n if (!expected.updatedAt) throw new CrudHttpError(409, { error: 'Record changed by another user' })\n assertOptimisticLock({\n resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,\n resourceId: link.id,\n current: link.updatedAt,\n expected: expected.updatedAt,\n envValue: 'all',\n })\n const deletedAt = link.deletedAt?.toISOString() ?? null\n if (deletedAt !== expected.deletedAt) {\n throw new CrudHttpError(409, buildOptimisticLockConflictBody(\n link.updatedAt.toISOString(),\n expected.updatedAt,\n ))\n }\n}\n\nasync function authorizeLinkCreateUndo(\n ctx: Parameters<NonNullable<CommandHandler['undo']>>[0]['ctx'],\n em: EntityManager,\n input: LinkDeleteCommandInput,\n entityType: Parameters<typeof getEntityRegistryEntry>[0],\n): Promise<void> {\n const scope = resolveDocumentsCommandScope(ctx, input)\n const features = await assertDocumentCommandCanEdit(ctx, em, input.documentId, scope)\n const registryEntry = getEntityRegistryEntry(entityType)\n if (!registryEntry) throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })\n if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {\n throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })\n }\n assertCommandFeature(features, registryEntry.requiredFeature)\n}\n\nasync function loadLinkById(\n em: EntityManager,\n input: LinkDeleteCommandInput,\n includeDeleted = false,\n lock = false,\n): Promise<DocumentEntityLink | null> {\n return findOneWithDecryption(\n em,\n DocumentEntityLink,\n {\n id: input.linkId,\n documentId: input.documentId,\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n ...(includeDeleted ? {} : { deletedAt: null }),\n },\n {\n ...(includeDeleted ? { filters: false } : {}),\n ...(lock ? { lockMode: LockMode.PESSIMISTIC_WRITE } : {}),\n },\n { tenantId: input.tenantId, organizationId: input.organizationId },\n )\n}\n\nasync function loadLinkByTarget(\n em: EntityManager,\n input: LinkCreateCommandInput,\n lock = false,\n): Promise<DocumentEntityLink | null> {\n return findOneWithDecryption(\n em,\n DocumentEntityLink,\n {\n documentId: input.documentId,\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n ...buildDocumentEntityLinkTargetWhere(input.link.entityType, input.link.entityId),\n },\n {\n filters: false,\n orderBy: { updatedAt: 'DESC' },\n ...(lock ? { lockMode: LockMode.PESSIMISTIC_WRITE } : {}),\n },\n { tenantId: input.tenantId, organizationId: input.organizationId },\n )\n}\n\nconst createLinkCommand: CommandHandler<LinkCreateCommandInput, LinkCreateCommandResult> = {\n id: 'documents.link.create',\n async execute(rawInput, ctx) {\n const input = linkCreateCommandSchema.parse(rawInput)\n const scope = resolveDocumentsCommandScope(ctx, input)\n const registryEntry = getEntityRegistryEntry(input.link.entityType)\n if (!registryEntry) {\n throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })\n }\n if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {\n throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })\n }\n const preflightFeatures = await resolveDocumentsCommandFeatures(ctx, scope)\n assertCommandFeature(preflightFeatures, registryEntry.requiredFeature)\n const request = ctx.request\n if (!request) {\n throw new CrudHttpError(503, { error: 'documents.links.targetUnavailable' })\n }\n // The registry lookup is a loopback HTTP request; it must complete before\n // the aggregate transaction so it never pins the PESSIMISTIC_WRITE lock or\n // a second pool connection. Freshness at commit is preserved by the\n // in-transaction re-checks below (fresh ACL, module availability, feature).\n const verified = await verifyEntityRegistrySelection(request, input.link)\n const canonicalInput = buildCanonicalLinkInput(input, verified)\n const writeEm = resolveDocumentsCommandEntityManager(ctx)\n let link: DocumentEntityLink | null = null\n let created = false\n let before!: LinkStateSnapshot\n let after!: LinkStateSnapshot\n await withAtomicFlush(writeEm, [\n async () => {\n await lockDocumentAggregateRoot(writeEm, input.documentId, scope)\n const features = await assertDocumentCommandCanEdit(ctx, writeEm, input.documentId, scope)\n if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {\n throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })\n }\n assertCommandFeature(features, registryEntry.requiredFeature)\n const existing = await loadLinkByTarget(writeEm, canonicalInput, true)\n before = captureLinkState(existing, input.linkId)\n if (existing && !existing.deletedAt) {\n link = existing\n return\n }\n await assertDocumentEntityLinkCapacity(writeEm, input.documentId, scope)\n link = existing ?? writeEm.create(\n DocumentEntityLink,\n createDocumentEntityLinkData({\n id: input.linkId,\n documentId: input.documentId,\n scope,\n actorUserId: resolveDocumentsCommandActor(ctx),\n link: canonicalInput.link,\n }),\n )\n if (!existing) writeEm.persist(link)\n link.labelSnapshot = canonicalInput.link.label\n link.hrefSnapshot = canonicalInput.link.href\n link.source = canonicalInput.link.source\n link.createdByUserId = resolveDocumentsCommandActor(ctx)\n link.deletedAt = null\n link.updatedAt = nextDocumentVersion(link.updatedAt)\n created = true\n },\n () => {\n const captured = link as DocumentEntityLink | null\n if (!captured) throw new Error('[internal] document link create produced no row')\n after = captureLinkState(captured, captured.id)\n },\n ], { transaction: true, label: 'documents.link.create' })\n const finalLink = link as DocumentEntityLink | null\n if (!finalLink) throw new Error('[internal] document link create produced no row')\n\n if (!created) {\n return {\n id: finalLink.id,\n created: false,\n updatedAt: finalLink.updatedAt.toISOString(),\n before,\n after,\n }\n }\n\n await bufferLinkMutationSideEffects(ctx, 'created', finalLink, {\n entityType: input.link.entityType,\n entityId: input.link.entityId,\n })\n return {\n id: finalLink.id,\n created: true,\n updatedAt: finalLink.updatedAt.toISOString(),\n before,\n after,\n }\n },\n async buildLog({ input, result }) {\n if (!result.created) return { skipLog: true }\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('documents.audit.linkCreated', 'Link document to record'),\n resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,\n resourceId: result.id,\n parentResourceKind: DOCUMENTS_ENTITY_IDS.document,\n parentResourceId: input.documentId,\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n snapshotBefore: result.before,\n snapshotAfter: result.after,\n payload: {\n undo: {\n before: result.before,\n after: result.after,\n createdByCommand: result.created,\n } satisfies LinkUndoPayload,\n },\n }\n },\n async undo({ logEntry, ctx }) {\n const undo = extractUndoPayload<LinkUndoPayload>(logEntry)\n if (!undo?.createdByCommand) return\n const before = undo?.before\n const after = undo?.after\n if (!after || (before?.existed && before.deletedAt === null)) return\n const input = linkCreateCommandSchema.parse(\n logEntry.commandPayload && typeof logEntry.commandPayload === 'object'\n ? (logEntry.commandPayload as { __redoInput?: unknown }).__redoInput\n : {},\n )\n const em = resolveDocumentsCommandEntityManager(ctx)\n let link: DocumentEntityLink | null = null\n await withAtomicFlush(em, [async () => {\n await lockDocumentAggregateRoot(em, input.documentId, {\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n })\n await authorizeLinkCreateUndo(ctx, em, input, input.link.entityType)\n link = await loadLinkById(em, { ...input, linkId: after.id }, true, true)\n if (!link) throw new CrudHttpError(409, { error: 'Record changed by another user' })\n assertLinkStateUnchanged(link, after)\n const version = nextDocumentVersion(link.updatedAt)\n link.deletedAt = before?.deletedAt ? new Date(before.deletedAt) : version\n link.updatedAt = version\n }], { transaction: true, label: 'documents.link.create.undo' })\n if (link) await bufferLinkMutationSideEffects(ctx, 'deleted', link, { undo: true })\n },\n}\n\nconst deleteLinkCommand: CommandHandler<LinkDeleteCommandInput, LinkDeleteCommandResult> = {\n id: 'documents.link.delete',\n async execute(rawInput, ctx) {\n const input = linkDeleteCommandSchema.parse(rawInput)\n const scope = resolveDocumentsCommandScope(ctx, input)\n const em = resolveDocumentsCommandEntityManager(ctx)\n let link: DocumentEntityLink | null = null\n let before!: LinkStateSnapshot\n let after!: LinkStateSnapshot\n await withAtomicFlush(em, [\n async () => {\n await lockDocumentAggregateRoot(em, input.documentId, scope)\n await assertDocumentCommandCanEdit(ctx, em, input.documentId, scope)\n link = await loadLinkById(em, input, false, true)\n if (!link) throw new CrudHttpError(404, { error: 'documents.links.notFound' })\n before = captureLinkState(link, input.linkId)\n await enforceCommandOptimisticLockWithGuards(ctx.container, {\n resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,\n resourceId: link.id,\n current: link.updatedAt,\n request: ctx.request ?? null,\n })\n const version = nextDocumentVersion(link.updatedAt)\n link.deletedAt = version\n link.updatedAt = version\n },\n () => {\n const captured = link as DocumentEntityLink | null\n if (!captured) throw new Error('[internal] document link delete produced no row')\n after = captureLinkState(captured, captured.id)\n },\n ], { transaction: true, label: 'documents.link.delete' })\n const deletedLink = link as DocumentEntityLink | null\n if (!deletedLink) throw new Error('[internal] document link delete produced no row')\n await bufferLinkMutationSideEffects(ctx, 'deleted', deletedLink)\n return {\n id: deletedLink.id,\n updatedAt: deletedLink.updatedAt.toISOString(),\n before,\n after,\n }\n },\n async buildLog({ input, result }) {\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('documents.audit.linkDeleted', 'Unlink document from record'),\n resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,\n resourceId: result.id,\n parentResourceKind: DOCUMENTS_ENTITY_IDS.document,\n parentResourceId: input.documentId,\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n snapshotBefore: result.before,\n snapshotAfter: result.after,\n payload: {\n undo: {\n before: result.before,\n after: result.after,\n } satisfies LinkUndoPayload,\n },\n }\n },\n async undo({ logEntry, ctx }) {\n const undo = extractUndoPayload<LinkUndoPayload>(logEntry)\n const before = undo?.before\n const after = undo?.after\n if (!before?.existed || before.deletedAt !== null) return\n const input = linkDeleteCommandSchema.parse(\n logEntry.commandPayload && typeof logEntry.commandPayload === 'object'\n ? (logEntry.commandPayload as { __redoInput?: unknown }).__redoInput\n : {},\n )\n const em = resolveDocumentsCommandEntityManager(ctx)\n if (!after) throw new CrudHttpError(409, { error: 'Record changed by another user' })\n // Re-verify the resurrected target over HTTP before the aggregate\n // transaction so the loopback request never runs under the\n // PESSIMISTIC_WRITE lock. The locked revalidation below pins the row to\n // the undo snapshot (monotonic versions), so the state verified here is\n // exactly the state that gets resurrected.\n const preflightLink = await loadLinkById(\n (ctx.container.resolve('em') as EntityManager).fork(),\n input,\n true,\n )\n if (!preflightLink) throw new CrudHttpError(409, { error: 'Record changed by another user' })\n const preflightRegistryEntry = getEntityRegistryEntry(getDocumentEntityLinkType(preflightLink))\n if (!preflightRegistryEntry) {\n throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })\n }\n if (!isDocumentEntityRegistryModuleEnabled(preflightRegistryEntry)) {\n throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })\n }\n if (!ctx.request) {\n throw new CrudHttpError(503, { error: 'documents.links.targetUnavailable' })\n }\n const verified = await verifyEntityRegistrySelection(ctx.request, {\n entityType: preflightRegistryEntry.type,\n entityId: getDocumentEntityLinkEntityId(preflightLink),\n label: preflightLink.labelSnapshot,\n href: preflightLink.hrefSnapshot,\n })\n let link: DocumentEntityLink | null = null\n await withAtomicFlush(em, [async () => {\n await lockDocumentAggregateRoot(em, input.documentId, {\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n })\n const features = await assertDocumentCommandCanEdit(ctx, em, input.documentId, {\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n })\n link = await loadLinkById(em, input, true, true)\n if (!link) throw new CrudHttpError(409, { error: 'Record changed by another user' })\n assertLinkStateUnchanged(link, after)\n const registryEntry = getEntityRegistryEntry(getDocumentEntityLinkType(link))\n if (!registryEntry) throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })\n if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {\n throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })\n }\n assertCommandFeature(features, registryEntry.requiredFeature)\n assertVerifiedLinkTargetMatchesRow(verified, link)\n await assertDocumentEntityLinkCapacity(em, input.documentId, {\n tenantId: input.tenantId,\n organizationId: input.organizationId,\n })\n link.labelSnapshot = verified.label\n link.hrefSnapshot = verified.href\n link.deletedAt = null\n link.updatedAt = nextDocumentVersion(link.updatedAt)\n }], { transaction: true, label: 'documents.link.delete.undo' })\n if (link) await bufferLinkMutationSideEffects(ctx, 'created', link, { undo: true })\n },\n}\n\nregisterCommand(createLinkCommand)\nregisterCommand(deleteLinkCommand)\n\nexport { createLinkCommand, deleteLinkCommand }\n"],
5
+ "mappings": "AACA,SAAS,gBAAgB;AACzB,SAAS,SAAS;AAClB,SAAS,uBAA4C;AACrD,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,sCAAsC;AAC/C,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,O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AChB,gBAAgB,MAAM;AAAA,MACxB,CAAC;AACD,YAAM,WAAW,MAAM,6BAA6B,KAAK,IAAI,MAAM,YAAY;AAAA,QAC7E,UAAU,MAAM;AAAA,QAChB,gBAAgB,MAAM;AAAA,MACxB,CAAC;AACD,aAAO,MAAM,aAAa,IAAI,OAAO,MAAM,IAAI;AAC/C,UAAI,CAAC,KAAM,OAAM,IAAI,cAAc,KAAK,EAAE,OAAO,iCAAiC,CAAC;AACnF,+BAAyB,MAAM,KAAK;AACpC,YAAM,gBAAgB,uBAAuB,0BAA0B,IAAI,CAAC;AAC5E,UAAI,CAAC,cAAe,OAAM,IAAI,cAAc,KAAK,EAAE,OAAO,oCAAoC,CAAC;AAC/F,UAAI,CAAC,sCAAsC,aAAa,GAAG;AACzD,cAAM,IAAI,cAAc,KAAK,EAAE,OAAO,mCAAmC,CAAC;AAAA,MAC5E;AACA,2BAAqB,UAAU,cAAc,eAAe;AAC5D,yCAAmC,UAAU,IAAI;AACjD,YAAM,iCAAiC,IAAI,MAAM,YAAY;AAAA,QAC3D,UAAU,MAAM;AAAA,QAChB,gBAAgB,MAAM;AAAA,MACxB,CAAC;AACD,WAAK,gBAAgB,SAAS;AAC9B,WAAK,eAAe,SAAS;AAC7B,WAAK,YAAY;AACjB,WAAK,YAAY,oBAAoB,KAAK,SAAS;AAAA,IACrD,CAAC,GAAG,EAAE,aAAa,MAAM,OAAO,6BAA6B,CAAC;AAC9D,QAAI,KAAM,OAAM,8BAA8B,KAAK,WAAW,MAAM,EAAE,MAAM,KAAK,CAAC;AAAA,EACpF;AACF;AAEA,gBAAgB,iBAAiB;AACjC,gBAAgB,iBAAiB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import {
3
+ assertOptimisticLock,
4
+ buildOptimisticLockConflictBody
5
+ } from "@open-mercato/shared/lib/crud/optimistic-lock-command";
6
+ import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
7
+ import { nextDocumentVersion } from "../lib/versioning.js";
8
+ const documentsScopedCommandSchema = z.object({
9
+ tenantId: z.string().uuid(),
10
+ organizationId: z.string().uuid()
11
+ });
12
+ function assertVersionedSnapshot(entity, expected, resourceKind) {
13
+ if (!entity || !expected) {
14
+ throw new CrudHttpError(409, { error: "Record changed by another user" });
15
+ }
16
+ assertOptimisticLock({
17
+ resourceKind,
18
+ resourceId: expected.id,
19
+ current: entity.updatedAt,
20
+ expected: expected.updatedAt,
21
+ envValue: "all"
22
+ });
23
+ const deletedAt = entity.deletedAt?.toISOString() ?? null;
24
+ if (deletedAt !== expected.deletedAt) {
25
+ throw new CrudHttpError(409, buildOptimisticLockConflictBody(
26
+ entity.updatedAt.toISOString(),
27
+ expected.updatedAt
28
+ ));
29
+ }
30
+ }
31
+ function readCommandRedoInput(logEntry) {
32
+ const payload = logEntry.commandPayload;
33
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) return null;
34
+ return payload.__redoInput ?? null;
35
+ }
36
+ export {
37
+ assertVersionedSnapshot,
38
+ documentsScopedCommandSchema,
39
+ nextDocumentVersion,
40
+ readCommandRedoInput
41
+ };
42
+ //# sourceMappingURL=mutation-helpers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/documents/commands/mutation-helpers.ts"],
4
+ "sourcesContent": ["import { z } from 'zod'\nimport {\n assertOptimisticLock,\n buildOptimisticLockConflictBody,\n} from '@open-mercato/shared/lib/crud/optimistic-lock-command'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nexport { nextDocumentVersion } from '../lib/versioning'\n\nexport const documentsScopedCommandSchema = z.object({\n tenantId: z.string().uuid(),\n organizationId: z.string().uuid(),\n})\n\nexport type VersionedEntitySnapshot = {\n id: string\n updatedAt: string\n deletedAt: string | null\n}\n\nexport function assertVersionedSnapshot(\n entity: { id: string; updatedAt: Date; deletedAt?: Date | null } | null,\n expected: VersionedEntitySnapshot | null | undefined,\n resourceKind: string,\n): void {\n if (!entity || !expected) {\n throw new CrudHttpError(409, { error: 'Record changed by another user' })\n }\n assertOptimisticLock({\n resourceKind,\n resourceId: expected.id,\n current: entity.updatedAt,\n expected: expected.updatedAt,\n envValue: 'all',\n })\n const deletedAt = entity.deletedAt?.toISOString() ?? null\n if (deletedAt !== expected.deletedAt) {\n throw new CrudHttpError(409, buildOptimisticLockConflictBody(\n entity.updatedAt.toISOString(),\n expected.updatedAt,\n ))\n }\n}\n\nexport function readCommandRedoInput(logEntry: { commandPayload?: unknown }): unknown {\n const payload = logEntry.commandPayload\n if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return null\n return (payload as { __redoInput?: unknown }).__redoInput ?? null\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AAE7B,MAAM,+BAA+B,EAAE,OAAO;AAAA,EACnD,UAAU,EAAE,OAAO,EAAE,KAAK;AAAA,EAC1B,gBAAgB,EAAE,OAAO,EAAE,KAAK;AAClC,CAAC;AAQM,SAAS,wBACd,QACA,UACA,cACM;AACN,MAAI,CAAC,UAAU,CAAC,UAAU;AACxB,UAAM,IAAI,cAAc,KAAK,EAAE,OAAO,iCAAiC,CAAC;AAAA,EAC1E;AACA,uBAAqB;AAAA,IACnB;AAAA,IACA,YAAY,SAAS;AAAA,IACrB,SAAS,OAAO;AAAA,IAChB,UAAU,SAAS;AAAA,IACnB,UAAU;AAAA,EACZ,CAAC;AACD,QAAM,YAAY,OAAO,WAAW,YAAY,KAAK;AACrD,MAAI,cAAc,SAAS,WAAW;AACpC,UAAM,IAAI,cAAc,KAAK;AAAA,MAC3B,OAAO,UAAU,YAAY;AAAA,MAC7B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEO,SAAS,qBAAqB,UAAiD;AACpF,QAAM,UAAU,SAAS;AACzB,MAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,EAAG,QAAO;AAC9E,SAAQ,QAAsC,eAAe;AAC/D;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=projection-types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }