@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.
- package/README.md +88 -0
- package/build.mjs +23 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/dist/modules/documents/acl.js +15 -0
- package/dist/modules/documents/acl.js.map +7 -0
- package/dist/modules/documents/api/[id]/archive/route.js +116 -0
- package/dist/modules/documents/api/[id]/archive/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/attachments/[attachmentId]/route.js +155 -0
- package/dist/modules/documents/api/[id]/attachments/[attachmentId]/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/attachments/route.js +153 -0
- package/dist/modules/documents/api/[id]/attachments/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/collab-token/route.js +180 -0
- package/dist/modules/documents/api/[id]/collab-token/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/comments/access-check/route.js +86 -0
- package/dist/modules/documents/api/[id]/comments/access-check/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/comments/route.js +387 -0
- package/dist/modules/documents/api/[id]/comments/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/content/route.js +143 -0
- package/dist/modules/documents/api/[id]/content/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/duplicate/route.js +200 -0
- package/dist/modules/documents/api/[id]/duplicate/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/export/route.js +421 -0
- package/dist/modules/documents/api/[id]/export/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/favorite/route.js +96 -0
- package/dist/modules/documents/api/[id]/favorite/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/links/[linkId]/route.js +85 -0
- package/dist/modules/documents/api/[id]/links/[linkId]/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/links/route.js +257 -0
- package/dist/modules/documents/api/[id]/links/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/principals/route.js +299 -0
- package/dist/modules/documents/api/[id]/principals/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/route.js +246 -0
- package/dist/modules/documents/api/[id]/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/shares/route.js +335 -0
- package/dist/modules/documents/api/[id]/shares/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/unarchive/route.js +39 -0
- package/dist/modules/documents/api/[id]/unarchive/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/versions/[versionId]/restore/route.js +133 -0
- package/dist/modules/documents/api/[id]/versions/[versionId]/restore/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/versions/[versionId]/route.js +93 -0
- package/dist/modules/documents/api/[id]/versions/[versionId]/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/versions/route.js +193 -0
- package/dist/modules/documents/api/[id]/versions/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/watch/route.js +97 -0
- package/dist/modules/documents/api/[id]/watch/route.js.map +7 -0
- package/dist/modules/documents/api/_commands.js +34 -0
- package/dist/modules/documents/api/_commands.js.map +7 -0
- package/dist/modules/documents/api/_shared.js +490 -0
- package/dist/modules/documents/api/_shared.js.map +7 -0
- package/dist/modules/documents/api/folders/route.js +256 -0
- package/dist/modules/documents/api/folders/route.js.map +7 -0
- package/dist/modules/documents/api/instantiate/route.js +108 -0
- package/dist/modules/documents/api/instantiate/route.js.map +7 -0
- package/dist/modules/documents/api/route.js +322 -0
- package/dist/modules/documents/api/route.js.map +7 -0
- package/dist/modules/documents/api/templates/[templateId]/preview/route.js +94 -0
- package/dist/modules/documents/api/templates/[templateId]/preview/route.js.map +7 -0
- package/dist/modules/documents/api/templates/[templateId]/route.js +82 -0
- package/dist/modules/documents/api/templates/[templateId]/route.js.map +7 -0
- package/dist/modules/documents/api/templates/route.js +344 -0
- package/dist/modules/documents/api/templates/route.js.map +7 -0
- package/dist/modules/documents/backend/documents/DocumentsPageClient.js +160 -0
- package/dist/modules/documents/backend/documents/DocumentsPageClient.js.map +7 -0
- package/dist/modules/documents/backend/documents/DocumentsTable.js +143 -0
- package/dist/modules/documents/backend/documents/DocumentsTable.js.map +7 -0
- package/dist/modules/documents/backend/documents/FolderDialog.js +55 -0
- package/dist/modules/documents/backend/documents/FolderDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/FolderTree.js +40 -0
- package/dist/modules/documents/backend/documents/FolderTree.js.map +7 -0
- package/dist/modules/documents/backend/documents/MoveDocumentDialog.js +64 -0
- package/dist/modules/documents/backend/documents/MoveDocumentDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/CommentAnchorNavigation.js +77 -0
- package/dist/modules/documents/backend/documents/[id]/CommentAnchorNavigation.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/CommentComposer.js +126 -0
- package/dist/modules/documents/backend/documents/[id]/CommentComposer.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/CommentThreadList.js +88 -0
- package/dist/modules/documents/backend/documents/[id]/CommentThreadList.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/CommentsRail.js +123 -0
- package/dist/modules/documents/backend/documents/[id]/CommentsRail.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js +91 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.js +27 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js +50 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js +168 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentNavigator.js +129 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentNavigator.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js +429 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/EditorColorTools.js +68 -0
- package/dist/modules/documents/backend/documents/[id]/EditorColorTools.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/EditorStatusPresence.js +69 -0
- package/dist/modules/documents/backend/documents/[id]/EditorStatusPresence.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/EditorToolbar.js +151 -0
- package/dist/modules/documents/backend/documents/[id]/EditorToolbar.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/ExportMenu.js +121 -0
- package/dist/modules/documents/backend/documents/[id]/ExportMenu.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/MentionPicker.js +114 -0
- package/dist/modules/documents/backend/documents/[id]/MentionPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/OutlinePane.js +70 -0
- package/dist/modules/documents/backend/documents/[id]/OutlinePane.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/RecordFieldsDialog.js +157 -0
- package/dist/modules/documents/backend/documents/[id]/RecordFieldsDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/RelatedRecordsPanel.js +266 -0
- package/dist/modules/documents/backend/documents/[id]/RelatedRecordsPanel.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js +227 -0
- package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js +157 -0
- package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/commentTypes.js +150 -0
- package/dist/modules/documents/backend/documents/[id]/commentTypes.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/componentCapabilities.js +13 -0
- package/dist/modules/documents/backend/documents/[id]/componentCapabilities.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/documentPagination.js +295 -0
- package/dist/modules/documents/backend/documents/[id]/documentPagination.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/editorPresenceStyles.js +81 -0
- package/dist/modules/documents/backend/documents/[id]/editorPresenceStyles.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/editorTypes.js +52 -0
- package/dist/modules/documents/backend/documents/[id]/editorTypes.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/page.js +10 -0
- package/dist/modules/documents/backend/documents/[id]/page.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/page.meta.js +16 -0
- package/dist/modules/documents/backend/documents/[id]/page.meta.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/relatedRecordModel.js +38 -0
- package/dist/modules/documents/backend/documents/[id]/relatedRecordModel.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/restoreVersion.js +33 -0
- package/dist/modules/documents/backend/documents/[id]/restoreVersion.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentCollaboration.js +392 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentCollaboration.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js +253 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js +149 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentTitle.js +82 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentTitle.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useEditorInsertions.js +144 -0
- package/dist/modules/documents/backend/documents/[id]/useEditorInsertions.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useFallbackContentPersistence.js +237 -0
- package/dist/modules/documents/backend/documents/[id]/useFallbackContentPersistence.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useMentionPicker.js +216 -0
- package/dist/modules/documents/backend/documents/[id]/useMentionPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/versionHistoryModel.js +25 -0
- package/dist/modules/documents/backend/documents/[id]/versionHistoryModel.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/EntityPicker.js +156 -0
- package/dist/modules/documents/backend/documents/components/EntityPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/EntityPickerResults.js +46 -0
- package/dist/modules/documents/backend/documents/components/EntityPickerResults.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/NewFromTemplateDialog.js +127 -0
- package/dist/modules/documents/backend/documents/components/NewFromTemplateDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/PrincipalPicker.js +84 -0
- package/dist/modules/documents/backend/documents/components/PrincipalPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/ShareDialog.js +77 -0
- package/dist/modules/documents/backend/documents/components/ShareDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/ShareDialogAddForm.js +93 -0
- package/dist/modules/documents/backend/documents/components/ShareDialogAddForm.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/ShareDialogList.js +82 -0
- package/dist/modules/documents/backend/documents/components/ShareDialogList.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js +96 -0
- package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplateEditorDialog.js +169 -0
- package/dist/modules/documents/backend/documents/components/TemplateEditorDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplatePreview.js +38 -0
- package/dist/modules/documents/backend/documents/components/TemplatePreview.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplateSlotFields.js +69 -0
- package/dist/modules/documents/backend/documents/components/TemplateSlotFields.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplateSlotsEditor.js +71 -0
- package/dist/modules/documents/backend/documents/components/TemplateSlotsEditor.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/principalPickerModel.js +63 -0
- package/dist/modules/documents/backend/documents/components/principalPickerModel.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/shareDialogModel.js +68 -0
- package/dist/modules/documents/backend/documents/components/shareDialogModel.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/templateUi.js +89 -0
- package/dist/modules/documents/backend/documents/components/templateUi.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useAvailableEntityRegistry.js +30 -0
- package/dist/modules/documents/backend/documents/components/useAvailableEntityRegistry.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useEntitySearch.js +191 -0
- package/dist/modules/documents/backend/documents/components/useEntitySearch.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/usePrincipalPicker.js +221 -0
- package/dist/modules/documents/backend/documents/components/usePrincipalPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useShareDialog.js +236 -0
- package/dist/modules/documents/backend/documents/components/useShareDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useTemplateDetail.js +49 -0
- package/dist/modules/documents/backend/documents/components/useTemplateDetail.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useTemplateInstantiation.js +234 -0
- package/dist/modules/documents/backend/documents/components/useTemplateInstantiation.js.map +7 -0
- package/dist/modules/documents/backend/documents/documentUi.js +106 -0
- package/dist/modules/documents/backend/documents/documentUi.js.map +7 -0
- package/dist/modules/documents/backend/documents/documentsListTypes.js +132 -0
- package/dist/modules/documents/backend/documents/documentsListTypes.js.map +7 -0
- package/dist/modules/documents/backend/documents/page.js +9 -0
- package/dist/modules/documents/backend/documents/page.js.map +7 -0
- package/dist/modules/documents/backend/documents/page.meta.js +26 -0
- package/dist/modules/documents/backend/documents/page.meta.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/TemplatesPageClient.js +91 -0
- package/dist/modules/documents/backend/documents/templates/TemplatesPageClient.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/TemplatesTable.js +58 -0
- package/dist/modules/documents/backend/documents/templates/TemplatesTable.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/page.js +9 -0
- package/dist/modules/documents/backend/documents/templates/page.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/page.meta.js +34 -0
- package/dist/modules/documents/backend/documents/templates/page.meta.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/useTemplatesPage.js +139 -0
- package/dist/modules/documents/backend/documents/templates/useTemplatesPage.js.map +7 -0
- package/dist/modules/documents/backend/documents/useDocumentsList.js +314 -0
- package/dist/modules/documents/backend/documents/useDocumentsList.js.map +7 -0
- package/dist/modules/documents/ce.js +8 -0
- package/dist/modules/documents/ce.js.map +7 -0
- package/dist/modules/documents/commands/aggregate.js +99 -0
- package/dist/modules/documents/commands/aggregate.js.map +7 -0
- package/dist/modules/documents/commands/attachments.js +252 -0
- package/dist/modules/documents/commands/attachments.js.map +7 -0
- package/dist/modules/documents/commands/comments.js +782 -0
- package/dist/modules/documents/commands/comments.js.map +7 -0
- package/dist/modules/documents/commands/content.js +238 -0
- package/dist/modules/documents/commands/content.js.map +7 -0
- package/dist/modules/documents/commands/document-crud.js +505 -0
- package/dist/modules/documents/commands/document-crud.js.map +7 -0
- package/dist/modules/documents/commands/documents.js +473 -0
- package/dist/modules/documents/commands/documents.js.map +7 -0
- package/dist/modules/documents/commands/duplicate.js +640 -0
- package/dist/modules/documents/commands/duplicate.js.map +7 -0
- package/dist/modules/documents/commands/favorites.js +150 -0
- package/dist/modules/documents/commands/favorites.js.map +7 -0
- package/dist/modules/documents/commands/folders.js +420 -0
- package/dist/modules/documents/commands/folders.js.map +7 -0
- package/dist/modules/documents/commands/index.js +64 -0
- package/dist/modules/documents/commands/index.js.map +7 -0
- package/dist/modules/documents/commands/interceptors.js +300 -0
- package/dist/modules/documents/commands/interceptors.js.map +7 -0
- package/dist/modules/documents/commands/lifecycle.js +249 -0
- package/dist/modules/documents/commands/lifecycle.js.map +7 -0
- package/dist/modules/documents/commands/links.js +410 -0
- package/dist/modules/documents/commands/links.js.map +7 -0
- package/dist/modules/documents/commands/mutation-helpers.js +42 -0
- package/dist/modules/documents/commands/mutation-helpers.js.map +7 -0
- package/dist/modules/documents/commands/projection-types.js +1 -0
- package/dist/modules/documents/commands/projection-types.js.map +7 -0
- package/dist/modules/documents/commands/shared.js +143 -0
- package/dist/modules/documents/commands/shared.js.map +7 -0
- package/dist/modules/documents/commands/shares.js +527 -0
- package/dist/modules/documents/commands/shares.js.map +7 -0
- package/dist/modules/documents/commands/side-effects.js +103 -0
- package/dist/modules/documents/commands/side-effects.js.map +7 -0
- package/dist/modules/documents/commands/templates.js +461 -0
- package/dist/modules/documents/commands/templates.js.map +7 -0
- package/dist/modules/documents/commands/versions.js +432 -0
- package/dist/modules/documents/commands/versions.js.map +7 -0
- package/dist/modules/documents/commands/watchers.js +164 -0
- package/dist/modules/documents/commands/watchers.js.map +7 -0
- package/dist/modules/documents/data/entities.js +653 -0
- package/dist/modules/documents/data/entities.js.map +7 -0
- package/dist/modules/documents/data/extensions.js +44 -0
- package/dist/modules/documents/data/extensions.js.map +7 -0
- package/dist/modules/documents/data/validators.js +219 -0
- package/dist/modules/documents/data/validators.js.map +7 -0
- package/dist/modules/documents/di.js +35 -0
- package/dist/modules/documents/di.js.map +7 -0
- package/dist/modules/documents/encryption.js +12 -0
- package/dist/modules/documents/encryption.js.map +7 -0
- package/dist/modules/documents/events.js +27 -0
- package/dist/modules/documents/events.js.map +7 -0
- package/dist/modules/documents/index.js +19 -0
- package/dist/modules/documents/index.js.map +7 -0
- package/dist/modules/documents/lib/attachmentServicePort.js +30 -0
- package/dist/modules/documents/lib/attachmentServicePort.js.map +7 -0
- package/dist/modules/documents/lib/capabilities.js +32 -0
- package/dist/modules/documents/lib/capabilities.js.map +7 -0
- package/dist/modules/documents/lib/collabCloseEvents.js +17 -0
- package/dist/modules/documents/lib/collabCloseEvents.js.map +7 -0
- package/dist/modules/documents/lib/collabEndpoint.js +22 -0
- package/dist/modules/documents/lib/collabEndpoint.js.map +7 -0
- package/dist/modules/documents/lib/collabMaterializer.js +107 -0
- package/dist/modules/documents/lib/collabMaterializer.js.map +7 -0
- package/dist/modules/documents/lib/collabToken.js +120 -0
- package/dist/modules/documents/lib/collabToken.js.map +7 -0
- package/dist/modules/documents/lib/collaborationAwareness.js +68 -0
- package/dist/modules/documents/lib/collaborationAwareness.js.map +7 -0
- package/dist/modules/documents/lib/commentAnchors.js +15 -0
- package/dist/modules/documents/lib/commentAnchors.js.map +7 -0
- package/dist/modules/documents/lib/constants.js +25 -0
- package/dist/modules/documents/lib/constants.js.map +7 -0
- package/dist/modules/documents/lib/contentService.js +248 -0
- package/dist/modules/documents/lib/contentService.js.map +7 -0
- package/dist/modules/documents/lib/displayLabels.js +23 -0
- package/dist/modules/documents/lib/displayLabels.js.map +7 -0
- package/dist/modules/documents/lib/docxRenderer.js +601 -0
- package/dist/modules/documents/lib/docxRenderer.js.map +7 -0
- package/dist/modules/documents/lib/duplicateContent.js +22 -0
- package/dist/modules/documents/lib/duplicateContent.js.map +7 -0
- package/dist/modules/documents/lib/editorConfig.js +287 -0
- package/dist/modules/documents/lib/editorConfig.js.map +7 -0
- package/dist/modules/documents/lib/entityLinks.js +148 -0
- package/dist/modules/documents/lib/entityLinks.js.map +7 -0
- package/dist/modules/documents/lib/entityRegistry.js +258 -0
- package/dist/modules/documents/lib/entityRegistry.js.map +7 -0
- package/dist/modules/documents/lib/entityRegistry.server.js +189 -0
- package/dist/modules/documents/lib/entityRegistry.server.js.map +7 -0
- package/dist/modules/documents/lib/entityRegistryAvailability.server.js +9 -0
- package/dist/modules/documents/lib/entityRegistryAvailability.server.js.map +7 -0
- package/dist/modules/documents/lib/entitySuggestion.js +50 -0
- package/dist/modules/documents/lib/entitySuggestion.js.map +7 -0
- package/dist/modules/documents/lib/favorites.js +22 -0
- package/dist/modules/documents/lib/favorites.js.map +7 -0
- package/dist/modules/documents/lib/folderHierarchySerialization.js +19 -0
- package/dist/modules/documents/lib/folderHierarchySerialization.js.map +7 -0
- package/dist/modules/documents/lib/historyLimits.js +100 -0
- package/dist/modules/documents/lib/historyLimits.js.map +7 -0
- package/dist/modules/documents/lib/historyPolicy.js +14 -0
- package/dist/modules/documents/lib/historyPolicy.js.map +7 -0
- package/dist/modules/documents/lib/organizationAccess.js +17 -0
- package/dist/modules/documents/lib/organizationAccess.js.map +7 -0
- package/dist/modules/documents/lib/pdfHtml.js +62 -0
- package/dist/modules/documents/lib/pdfHtml.js.map +7 -0
- package/dist/modules/documents/lib/pdfRenderer.js +284 -0
- package/dist/modules/documents/lib/pdfRenderer.js.map +7 -0
- package/dist/modules/documents/lib/permissions.js +222 -0
- package/dist/modules/documents/lib/permissions.js.map +7 -0
- package/dist/modules/documents/lib/platformServices.js +35 -0
- package/dist/modules/documents/lib/platformServices.js.map +7 -0
- package/dist/modules/documents/lib/recordFieldInsertion.js +58 -0
- package/dist/modules/documents/lib/recordFieldInsertion.js.map +7 -0
- package/dist/modules/documents/lib/requestBody.js +80 -0
- package/dist/modules/documents/lib/requestBody.js.map +7 -0
- package/dist/modules/documents/lib/resourceLimits.js +62 -0
- package/dist/modules/documents/lib/resourceLimits.js.map +7 -0
- package/dist/modules/documents/lib/shareCounts.js +25 -0
- package/dist/modules/documents/lib/shareCounts.js.map +7 -0
- package/dist/modules/documents/lib/templateFill.js +84 -0
- package/dist/modules/documents/lib/templateFill.js.map +7 -0
- package/dist/modules/documents/lib/templateInstantiation.js +147 -0
- package/dist/modules/documents/lib/templateInstantiation.js.map +7 -0
- package/dist/modules/documents/lib/templatePreviewDigest.js +82 -0
- package/dist/modules/documents/lib/templatePreviewDigest.js.map +7 -0
- package/dist/modules/documents/lib/templateSeeds.js +201 -0
- package/dist/modules/documents/lib/templateSeeds.js.map +7 -0
- package/dist/modules/documents/lib/userLabels.js +37 -0
- package/dist/modules/documents/lib/userLabels.js.map +7 -0
- package/dist/modules/documents/lib/versionContent.js +131 -0
- package/dist/modules/documents/lib/versionContent.js.map +7 -0
- package/dist/modules/documents/lib/versionLabels.js +12 -0
- package/dist/modules/documents/lib/versionLabels.js.map +7 -0
- package/dist/modules/documents/lib/versioning.js +14 -0
- package/dist/modules/documents/lib/versioning.js.map +7 -0
- package/dist/modules/documents/lib/visibility.js +422 -0
- package/dist/modules/documents/lib/visibility.js.map +7 -0
- package/dist/modules/documents/lib/watchers.js +106 -0
- package/dist/modules/documents/lib/watchers.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260708163836_documents.js +44 -0
- package/dist/modules/documents/migrations/Migration20260708163836_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260709164720_documents.js +17 -0
- package/dist/modules/documents/migrations/Migration20260709164720_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260710002318_documents.js +32 -0
- package/dist/modules/documents/migrations/Migration20260710002318_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260710071003_documents.js +13 -0
- package/dist/modules/documents/migrations/Migration20260710071003_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260712120000_documents.js +13 -0
- package/dist/modules/documents/migrations/Migration20260712120000_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260712183000_documents.js +14 -0
- package/dist/modules/documents/migrations/Migration20260712183000_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260713092156_documents.js +29 -0
- package/dist/modules/documents/migrations/Migration20260713092156_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260717000000_documents.js +37 -0
- package/dist/modules/documents/migrations/Migration20260717000000_documents.js.map +7 -0
- package/dist/modules/documents/notifications.js +47 -0
- package/dist/modules/documents/notifications.js.map +7 -0
- package/dist/modules/documents/search.js +101 -0
- package/dist/modules/documents/search.js.map +7 -0
- package/dist/modules/documents/setup.js +19 -0
- package/dist/modules/documents/setup.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.js +214 -0
- package/dist/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/context.js +84 -0
- package/dist/modules/documents/widgets/injection/related-documents/context.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/useRelatedDocuments.js +98 -0
- package/dist/modules/documents/widgets/injection/related-documents/useRelatedDocuments.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/widget.client.js +83 -0
- package/dist/modules/documents/widgets/injection/related-documents/widget.client.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/widget.js +19 -0
- package/dist/modules/documents/widgets/injection/related-documents/widget.js.map +7 -0
- package/dist/modules/documents/widgets/injection-table.js +21 -0
- package/dist/modules/documents/widgets/injection-table.js.map +7 -0
- package/dist/server/documents-collab-server.js +2260 -0
- package/dist/server/documents-collab-server.js.map +7 -0
- package/generated/entities/document/index.ts +12 -0
- package/generated/entities/document_attachment/index.ts +9 -0
- package/generated/entities/document_comment/index.ts +14 -0
- package/generated/entities/document_content/index.ts +11 -0
- package/generated/entities/document_entity_link/index.ts +19 -0
- package/generated/entities/document_favorite/index.ts +7 -0
- package/generated/entities/document_folder/index.ts +9 -0
- package/generated/entities/document_share/index.ts +11 -0
- package/generated/entities/document_template/index.ts +13 -0
- package/generated/entities/document_version/index.ts +9 -0
- package/generated/entities/document_watcher/index.ts +7 -0
- package/generated/entities.ids.generated.ts +21 -0
- package/generated/entity-fields-registry.ts +151 -0
- package/jest.config.cjs +34 -0
- package/package.json +149 -0
- package/server/documents-collab-server.ts +3416 -0
- package/src/index.ts +1 -0
- package/src/modules/documents/acl.ts +11 -0
- package/src/modules/documents/api/[id]/archive/route.ts +132 -0
- package/src/modules/documents/api/[id]/attachments/[attachmentId]/route.ts +166 -0
- package/src/modules/documents/api/[id]/attachments/route.ts +173 -0
- package/src/modules/documents/api/[id]/collab-token/route.ts +203 -0
- package/src/modules/documents/api/[id]/comments/access-check/route.ts +96 -0
- package/src/modules/documents/api/[id]/comments/route.ts +442 -0
- package/src/modules/documents/api/[id]/content/route.ts +156 -0
- package/src/modules/documents/api/[id]/duplicate/route.ts +231 -0
- package/src/modules/documents/api/[id]/export/route.ts +535 -0
- package/src/modules/documents/api/[id]/favorite/route.ts +110 -0
- package/src/modules/documents/api/[id]/links/[linkId]/route.ts +92 -0
- package/src/modules/documents/api/[id]/links/route.ts +301 -0
- package/src/modules/documents/api/[id]/principals/route.ts +375 -0
- package/src/modules/documents/api/[id]/route.ts +267 -0
- package/src/modules/documents/api/[id]/shares/route.ts +372 -0
- package/src/modules/documents/api/[id]/unarchive/route.ts +42 -0
- package/src/modules/documents/api/[id]/versions/[versionId]/restore/route.ts +152 -0
- package/src/modules/documents/api/[id]/versions/[versionId]/route.ts +100 -0
- package/src/modules/documents/api/[id]/versions/route.ts +207 -0
- package/src/modules/documents/api/[id]/watch/route.ts +111 -0
- package/src/modules/documents/api/_commands.ts +53 -0
- package/src/modules/documents/api/_shared.ts +676 -0
- package/src/modules/documents/api/folders/route.ts +287 -0
- package/src/modules/documents/api/instantiate/route.ts +114 -0
- package/src/modules/documents/api/route.ts +362 -0
- package/src/modules/documents/api/templates/[templateId]/preview/route.ts +97 -0
- package/src/modules/documents/api/templates/[templateId]/route.ts +92 -0
- package/src/modules/documents/api/templates/route.ts +370 -0
- package/src/modules/documents/backend/documents/DocumentsPageClient.tsx +150 -0
- package/src/modules/documents/backend/documents/DocumentsTable.tsx +168 -0
- package/src/modules/documents/backend/documents/FolderDialog.tsx +62 -0
- package/src/modules/documents/backend/documents/FolderTree.tsx +72 -0
- package/src/modules/documents/backend/documents/MoveDocumentDialog.tsx +70 -0
- package/src/modules/documents/backend/documents/[id]/CommentAnchorNavigation.ts +88 -0
- package/src/modules/documents/backend/documents/[id]/CommentComposer.tsx +136 -0
- package/src/modules/documents/backend/documents/[id]/CommentThreadList.tsx +131 -0
- package/src/modules/documents/backend/documents/[id]/CommentsRail.tsx +138 -0
- package/src/modules/documents/backend/documents/[id]/DocumentCanvas.tsx +111 -0
- package/src/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.tsx +39 -0
- package/src/modules/documents/backend/documents/[id]/DocumentEditorIsland.tsx +50 -0
- package/src/modules/documents/backend/documents/[id]/DocumentEditorSurface.tsx +162 -0
- package/src/modules/documents/backend/documents/[id]/DocumentNavigator.tsx +129 -0
- package/src/modules/documents/backend/documents/[id]/DocumentPageClient.tsx +463 -0
- package/src/modules/documents/backend/documents/[id]/EditorColorTools.tsx +71 -0
- package/src/modules/documents/backend/documents/[id]/EditorStatusPresence.tsx +78 -0
- package/src/modules/documents/backend/documents/[id]/EditorToolbar.tsx +108 -0
- package/src/modules/documents/backend/documents/[id]/ExportMenu.tsx +144 -0
- package/src/modules/documents/backend/documents/[id]/MentionPicker.tsx +137 -0
- package/src/modules/documents/backend/documents/[id]/OutlinePane.tsx +98 -0
- package/src/modules/documents/backend/documents/[id]/RecordFieldsDialog.tsx +185 -0
- package/src/modules/documents/backend/documents/[id]/RelatedRecordsPanel.tsx +320 -0
- package/src/modules/documents/backend/documents/[id]/VersionHistoryPanel.tsx +244 -0
- package/src/modules/documents/backend/documents/[id]/VersionPreviewDialog.tsx +197 -0
- package/src/modules/documents/backend/documents/[id]/commentTypes.ts +192 -0
- package/src/modules/documents/backend/documents/[id]/componentCapabilities.ts +17 -0
- package/src/modules/documents/backend/documents/[id]/documentPagination.ts +352 -0
- package/src/modules/documents/backend/documents/[id]/editorPresenceStyles.ts +77 -0
- package/src/modules/documents/backend/documents/[id]/editorTypes.ts +84 -0
- package/src/modules/documents/backend/documents/[id]/page.meta.ts +12 -0
- package/src/modules/documents/backend/documents/[id]/page.tsx +6 -0
- package/src/modules/documents/backend/documents/[id]/relatedRecordModel.ts +49 -0
- package/src/modules/documents/backend/documents/[id]/restoreVersion.ts +49 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentCollaboration.ts +458 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentComments.ts +286 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentEditor.ts +157 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentTitle.ts +77 -0
- package/src/modules/documents/backend/documents/[id]/useEditorInsertions.ts +147 -0
- package/src/modules/documents/backend/documents/[id]/useFallbackContentPersistence.ts +277 -0
- package/src/modules/documents/backend/documents/[id]/useMentionPicker.ts +259 -0
- package/src/modules/documents/backend/documents/[id]/versionHistoryModel.ts +29 -0
- package/src/modules/documents/backend/documents/components/EntityPicker.tsx +171 -0
- package/src/modules/documents/backend/documents/components/EntityPickerResults.tsx +64 -0
- package/src/modules/documents/backend/documents/components/NewFromTemplateDialog.tsx +136 -0
- package/src/modules/documents/backend/documents/components/PrincipalPicker.tsx +90 -0
- package/src/modules/documents/backend/documents/components/ShareDialog.tsx +88 -0
- package/src/modules/documents/backend/documents/components/ShareDialogAddForm.tsx +113 -0
- package/src/modules/documents/backend/documents/components/ShareDialogList.tsx +117 -0
- package/src/modules/documents/backend/documents/components/TemplateBodyEditor.tsx +96 -0
- package/src/modules/documents/backend/documents/components/TemplateEditorDialog.tsx +171 -0
- package/src/modules/documents/backend/documents/components/TemplatePreview.tsx +43 -0
- package/src/modules/documents/backend/documents/components/TemplateSlotFields.tsx +72 -0
- package/src/modules/documents/backend/documents/components/TemplateSlotsEditor.tsx +72 -0
- package/src/modules/documents/backend/documents/components/principalPickerModel.ts +86 -0
- package/src/modules/documents/backend/documents/components/shareDialogModel.ts +94 -0
- package/src/modules/documents/backend/documents/components/templateUi.ts +128 -0
- package/src/modules/documents/backend/documents/components/useAvailableEntityRegistry.ts +43 -0
- package/src/modules/documents/backend/documents/components/useEntitySearch.ts +197 -0
- package/src/modules/documents/backend/documents/components/usePrincipalPicker.ts +165 -0
- package/src/modules/documents/backend/documents/components/useShareDialog.ts +267 -0
- package/src/modules/documents/backend/documents/components/useTemplateDetail.ts +54 -0
- package/src/modules/documents/backend/documents/components/useTemplateInstantiation.ts +252 -0
- package/src/modules/documents/backend/documents/documentUi.ts +134 -0
- package/src/modules/documents/backend/documents/documentsListTypes.ts +163 -0
- package/src/modules/documents/backend/documents/page.meta.ts +24 -0
- package/src/modules/documents/backend/documents/page.tsx +5 -0
- package/src/modules/documents/backend/documents/templates/TemplatesPageClient.tsx +93 -0
- package/src/modules/documents/backend/documents/templates/TemplatesTable.tsx +71 -0
- package/src/modules/documents/backend/documents/templates/page.meta.ts +32 -0
- package/src/modules/documents/backend/documents/templates/page.tsx +5 -0
- package/src/modules/documents/backend/documents/templates/useTemplatesPage.tsx +148 -0
- package/src/modules/documents/backend/documents/useDocumentsList.tsx +305 -0
- package/src/modules/documents/ce.ts +6 -0
- package/src/modules/documents/commands/aggregate.ts +128 -0
- package/src/modules/documents/commands/attachments.ts +309 -0
- package/src/modules/documents/commands/comments.ts +966 -0
- package/src/modules/documents/commands/content.ts +294 -0
- package/src/modules/documents/commands/document-crud.ts +609 -0
- package/src/modules/documents/commands/documents.ts +581 -0
- package/src/modules/documents/commands/duplicate.ts +772 -0
- package/src/modules/documents/commands/favorites.ts +171 -0
- package/src/modules/documents/commands/folders.ts +506 -0
- package/src/modules/documents/commands/index.ts +33 -0
- package/src/modules/documents/commands/interceptors.ts +402 -0
- package/src/modules/documents/commands/lifecycle.ts +333 -0
- package/src/modules/documents/commands/links.ts +486 -0
- package/src/modules/documents/commands/mutation-helpers.ts +48 -0
- package/src/modules/documents/commands/projection-types.ts +77 -0
- package/src/modules/documents/commands/shared.ts +219 -0
- package/src/modules/documents/commands/shares.ts +612 -0
- package/src/modules/documents/commands/side-effects.ts +130 -0
- package/src/modules/documents/commands/templates.ts +522 -0
- package/src/modules/documents/commands/versions.ts +537 -0
- package/src/modules/documents/commands/watchers.ts +181 -0
- package/src/modules/documents/data/entities.ts +631 -0
- package/src/modules/documents/data/extensions.ts +42 -0
- package/src/modules/documents/data/validators.ts +248 -0
- package/src/modules/documents/di.ts +33 -0
- package/src/modules/documents/encryption.ts +14 -0
- package/src/modules/documents/events.ts +23 -0
- package/src/modules/documents/i18n/.hardcoded-allowlist.json +9 -0
- package/src/modules/documents/i18n/de.json +522 -0
- package/src/modules/documents/i18n/en.json +522 -0
- package/src/modules/documents/i18n/es.json +522 -0
- package/src/modules/documents/i18n/ko.json +522 -0
- package/src/modules/documents/i18n/pl.json +522 -0
- package/src/modules/documents/index.ts +17 -0
- package/src/modules/documents/lib/attachmentServicePort.ts +94 -0
- package/src/modules/documents/lib/capabilities.ts +57 -0
- package/src/modules/documents/lib/collabCloseEvents.ts +26 -0
- package/src/modules/documents/lib/collabEndpoint.ts +43 -0
- package/src/modules/documents/lib/collabMaterializer.ts +140 -0
- package/src/modules/documents/lib/collabToken.ts +170 -0
- package/src/modules/documents/lib/collaborationAwareness.ts +102 -0
- package/src/modules/documents/lib/commentAnchors.ts +19 -0
- package/src/modules/documents/lib/constants.ts +39 -0
- package/src/modules/documents/lib/contentService.ts +340 -0
- package/src/modules/documents/lib/displayLabels.ts +31 -0
- package/src/modules/documents/lib/docxRenderer.ts +685 -0
- package/src/modules/documents/lib/duplicateContent.ts +32 -0
- package/src/modules/documents/lib/editorConfig.ts +371 -0
- package/src/modules/documents/lib/entityLinks.ts +250 -0
- package/src/modules/documents/lib/entityRegistry.server.ts +267 -0
- package/src/modules/documents/lib/entityRegistry.ts +345 -0
- package/src/modules/documents/lib/entityRegistryAvailability.server.ts +19 -0
- package/src/modules/documents/lib/entitySuggestion.ts +61 -0
- package/src/modules/documents/lib/favorites.ts +35 -0
- package/src/modules/documents/lib/folderHierarchySerialization.ts +34 -0
- package/src/modules/documents/lib/historyLimits.ts +154 -0
- package/src/modules/documents/lib/historyPolicy.ts +7 -0
- package/src/modules/documents/lib/organizationAccess.ts +44 -0
- package/src/modules/documents/lib/pdfHtml.ts +65 -0
- package/src/modules/documents/lib/pdfRenderer.ts +367 -0
- package/src/modules/documents/lib/permissions.ts +299 -0
- package/src/modules/documents/lib/platformServices.ts +70 -0
- package/src/modules/documents/lib/recordFieldInsertion.ts +72 -0
- package/src/modules/documents/lib/requestBody.ts +97 -0
- package/src/modules/documents/lib/resourceLimits.ts +94 -0
- package/src/modules/documents/lib/shareCounts.ts +44 -0
- package/src/modules/documents/lib/templateFill.ts +138 -0
- package/src/modules/documents/lib/templateInstantiation.ts +206 -0
- package/src/modules/documents/lib/templatePreviewDigest.ts +122 -0
- package/src/modules/documents/lib/templateSeeds.ts +248 -0
- package/src/modules/documents/lib/userLabels.ts +58 -0
- package/src/modules/documents/lib/versionContent.ts +163 -0
- package/src/modules/documents/lib/versionLabels.ts +9 -0
- package/src/modules/documents/lib/versioning.ts +29 -0
- package/src/modules/documents/lib/visibility.ts +610 -0
- package/src/modules/documents/lib/watchers.ts +129 -0
- package/src/modules/documents/migrations/.snapshot-open-mercato.json +2892 -0
- package/src/modules/documents/migrations/Migration20260708163836_documents.ts +50 -0
- package/src/modules/documents/migrations/Migration20260709164720_documents.ts +19 -0
- package/src/modules/documents/migrations/Migration20260710002318_documents.ts +35 -0
- package/src/modules/documents/migrations/Migration20260710071003_documents.ts +13 -0
- package/src/modules/documents/migrations/Migration20260712120000_documents.ts +13 -0
- package/src/modules/documents/migrations/Migration20260712183000_documents.ts +12 -0
- package/src/modules/documents/migrations/Migration20260713092156_documents.ts +43 -0
- package/src/modules/documents/migrations/Migration20260717000000_documents.ts +40 -0
- package/src/modules/documents/notifications.ts +45 -0
- package/src/modules/documents/search.ts +118 -0
- package/src/modules/documents/setup.ts +19 -0
- package/src/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.tsx +224 -0
- package/src/modules/documents/widgets/injection/related-documents/context.ts +101 -0
- package/src/modules/documents/widgets/injection/related-documents/useRelatedDocuments.ts +112 -0
- package/src/modules/documents/widgets/injection/related-documents/widget.client.tsx +76 -0
- package/src/modules/documents/widgets/injection/related-documents/widget.ts +19 -0
- package/src/modules/documents/widgets/injection-table.ts +20 -0
- package/tsconfig.json +9 -0
- package/watch.mjs +6 -0
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
+
import { LockMode } from '@mikro-orm/core'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import { registerCommand, type CommandHandler } from '@open-mercato/shared/lib/commands'
|
|
5
|
+
import { extractUndoPayload } from '@open-mercato/shared/lib/commands/undo'
|
|
6
|
+
import { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'
|
|
7
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
8
|
+
import {
|
|
9
|
+
assertOptimisticLock,
|
|
10
|
+
buildOptimisticLockConflictBody,
|
|
11
|
+
enforceCommandOptimisticLockWithGuards,
|
|
12
|
+
} from '@open-mercato/shared/lib/crud/optimistic-lock-command'
|
|
13
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
14
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
15
|
+
import { DocumentEntityLink } from '../data/entities'
|
|
16
|
+
import { documentEntityLinkCreateSchema } from '../data/validators'
|
|
17
|
+
import { DOCUMENTS_ENTITY_IDS } from '../lib/constants'
|
|
18
|
+
import {
|
|
19
|
+
assertDocumentEntityLinkCapacity,
|
|
20
|
+
buildDocumentEntityLinkTargetWhere,
|
|
21
|
+
createDocumentEntityLinkData,
|
|
22
|
+
getDocumentEntityLinkEntityId,
|
|
23
|
+
getDocumentEntityLinkType,
|
|
24
|
+
} from '../lib/entityLinks'
|
|
25
|
+
import { getEntityRegistryEntry } from '../lib/entityRegistry'
|
|
26
|
+
import { isDocumentEntityRegistryModuleEnabled } from '../lib/entityRegistryAvailability.server'
|
|
27
|
+
import {
|
|
28
|
+
verifyEntityRegistrySelection,
|
|
29
|
+
type VerifiedEntityRegistrySelection,
|
|
30
|
+
} from '../lib/entityRegistry.server'
|
|
31
|
+
import { lockDocumentAggregateRoot } from './aggregate'
|
|
32
|
+
import { bufferLinkMutationSideEffects } from './side-effects'
|
|
33
|
+
import {
|
|
34
|
+
assertCommandFeature,
|
|
35
|
+
assertDocumentCommandCanEdit,
|
|
36
|
+
resolveDocumentsCommandActor,
|
|
37
|
+
resolveDocumentsCommandEntityManager,
|
|
38
|
+
resolveDocumentsCommandFeatures,
|
|
39
|
+
resolveDocumentsCommandScope,
|
|
40
|
+
} from './shared'
|
|
41
|
+
import { nextDocumentVersion } from './mutation-helpers'
|
|
42
|
+
|
|
43
|
+
const scopedSchema = z.object({
|
|
44
|
+
tenantId: z.string().uuid(),
|
|
45
|
+
organizationId: z.string().uuid(),
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export const linkCreateCommandSchema = scopedSchema.extend({
|
|
49
|
+
linkId: z.string().uuid(),
|
|
50
|
+
documentId: z.string().uuid(),
|
|
51
|
+
link: documentEntityLinkCreateSchema,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
export const linkDeleteCommandSchema = scopedSchema.extend({
|
|
55
|
+
documentId: z.string().uuid(),
|
|
56
|
+
linkId: z.string().uuid(),
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
export type LinkCreateCommandInput = z.infer<typeof linkCreateCommandSchema>
|
|
60
|
+
export type LinkDeleteCommandInput = z.infer<typeof linkDeleteCommandSchema>
|
|
61
|
+
|
|
62
|
+
type LinkStateSnapshot = {
|
|
63
|
+
id: string
|
|
64
|
+
existed: boolean
|
|
65
|
+
deletedAt: string | null
|
|
66
|
+
updatedAt: string | null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type LinkUndoPayload = {
|
|
70
|
+
before?: LinkStateSnapshot | null
|
|
71
|
+
after?: LinkStateSnapshot | null
|
|
72
|
+
createdByCommand?: boolean
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type LinkCreateCommandResult = {
|
|
76
|
+
id: string
|
|
77
|
+
created: boolean
|
|
78
|
+
updatedAt: string
|
|
79
|
+
before: LinkStateSnapshot
|
|
80
|
+
after: LinkStateSnapshot
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type LinkDeleteCommandResult = {
|
|
84
|
+
id: string
|
|
85
|
+
updatedAt: string
|
|
86
|
+
before: LinkStateSnapshot
|
|
87
|
+
after: LinkStateSnapshot
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function buildCanonicalLinkInput(
|
|
91
|
+
input: LinkCreateCommandInput,
|
|
92
|
+
verified: VerifiedEntityRegistrySelection,
|
|
93
|
+
): LinkCreateCommandInput {
|
|
94
|
+
return {
|
|
95
|
+
...input,
|
|
96
|
+
link: {
|
|
97
|
+
...input.link,
|
|
98
|
+
label: verified.label,
|
|
99
|
+
href: verified.href,
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function assertVerifiedLinkTargetMatchesRow(
|
|
105
|
+
verified: VerifiedEntityRegistrySelection,
|
|
106
|
+
link: DocumentEntityLink,
|
|
107
|
+
): void {
|
|
108
|
+
if (verified.id !== getDocumentEntityLinkEntityId(link)) {
|
|
109
|
+
throw new CrudHttpError(409, { error: 'Record changed by another user' })
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function captureLinkState(link: DocumentEntityLink | null, fallbackId: string): LinkStateSnapshot {
|
|
114
|
+
return {
|
|
115
|
+
id: link?.id ?? fallbackId,
|
|
116
|
+
existed: link !== null,
|
|
117
|
+
deletedAt: link?.deletedAt?.toISOString() ?? null,
|
|
118
|
+
updatedAt: link?.updatedAt?.toISOString() ?? null,
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function assertLinkStateUnchanged(link: DocumentEntityLink, expected: LinkStateSnapshot): void {
|
|
123
|
+
if (!expected.updatedAt) throw new CrudHttpError(409, { error: 'Record changed by another user' })
|
|
124
|
+
assertOptimisticLock({
|
|
125
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,
|
|
126
|
+
resourceId: link.id,
|
|
127
|
+
current: link.updatedAt,
|
|
128
|
+
expected: expected.updatedAt,
|
|
129
|
+
envValue: 'all',
|
|
130
|
+
})
|
|
131
|
+
const deletedAt = link.deletedAt?.toISOString() ?? null
|
|
132
|
+
if (deletedAt !== expected.deletedAt) {
|
|
133
|
+
throw new CrudHttpError(409, buildOptimisticLockConflictBody(
|
|
134
|
+
link.updatedAt.toISOString(),
|
|
135
|
+
expected.updatedAt,
|
|
136
|
+
))
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function authorizeLinkCreateUndo(
|
|
141
|
+
ctx: Parameters<NonNullable<CommandHandler['undo']>>[0]['ctx'],
|
|
142
|
+
em: EntityManager,
|
|
143
|
+
input: LinkDeleteCommandInput,
|
|
144
|
+
entityType: Parameters<typeof getEntityRegistryEntry>[0],
|
|
145
|
+
): Promise<void> {
|
|
146
|
+
const scope = resolveDocumentsCommandScope(ctx, input)
|
|
147
|
+
const features = await assertDocumentCommandCanEdit(ctx, em, input.documentId, scope)
|
|
148
|
+
const registryEntry = getEntityRegistryEntry(entityType)
|
|
149
|
+
if (!registryEntry) throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })
|
|
150
|
+
if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {
|
|
151
|
+
throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })
|
|
152
|
+
}
|
|
153
|
+
assertCommandFeature(features, registryEntry.requiredFeature)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function loadLinkById(
|
|
157
|
+
em: EntityManager,
|
|
158
|
+
input: LinkDeleteCommandInput,
|
|
159
|
+
includeDeleted = false,
|
|
160
|
+
lock = false,
|
|
161
|
+
): Promise<DocumentEntityLink | null> {
|
|
162
|
+
return findOneWithDecryption(
|
|
163
|
+
em,
|
|
164
|
+
DocumentEntityLink,
|
|
165
|
+
{
|
|
166
|
+
id: input.linkId,
|
|
167
|
+
documentId: input.documentId,
|
|
168
|
+
tenantId: input.tenantId,
|
|
169
|
+
organizationId: input.organizationId,
|
|
170
|
+
...(includeDeleted ? {} : { deletedAt: null }),
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
...(includeDeleted ? { filters: false } : {}),
|
|
174
|
+
...(lock ? { lockMode: LockMode.PESSIMISTIC_WRITE } : {}),
|
|
175
|
+
},
|
|
176
|
+
{ tenantId: input.tenantId, organizationId: input.organizationId },
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function loadLinkByTarget(
|
|
181
|
+
em: EntityManager,
|
|
182
|
+
input: LinkCreateCommandInput,
|
|
183
|
+
lock = false,
|
|
184
|
+
): Promise<DocumentEntityLink | null> {
|
|
185
|
+
return findOneWithDecryption(
|
|
186
|
+
em,
|
|
187
|
+
DocumentEntityLink,
|
|
188
|
+
{
|
|
189
|
+
documentId: input.documentId,
|
|
190
|
+
tenantId: input.tenantId,
|
|
191
|
+
organizationId: input.organizationId,
|
|
192
|
+
...buildDocumentEntityLinkTargetWhere(input.link.entityType, input.link.entityId),
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
filters: false,
|
|
196
|
+
orderBy: { updatedAt: 'DESC' },
|
|
197
|
+
...(lock ? { lockMode: LockMode.PESSIMISTIC_WRITE } : {}),
|
|
198
|
+
},
|
|
199
|
+
{ tenantId: input.tenantId, organizationId: input.organizationId },
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const createLinkCommand: CommandHandler<LinkCreateCommandInput, LinkCreateCommandResult> = {
|
|
204
|
+
id: 'documents.link.create',
|
|
205
|
+
async execute(rawInput, ctx) {
|
|
206
|
+
const input = linkCreateCommandSchema.parse(rawInput)
|
|
207
|
+
const scope = resolveDocumentsCommandScope(ctx, input)
|
|
208
|
+
const registryEntry = getEntityRegistryEntry(input.link.entityType)
|
|
209
|
+
if (!registryEntry) {
|
|
210
|
+
throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })
|
|
211
|
+
}
|
|
212
|
+
if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {
|
|
213
|
+
throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })
|
|
214
|
+
}
|
|
215
|
+
const preflightFeatures = await resolveDocumentsCommandFeatures(ctx, scope)
|
|
216
|
+
assertCommandFeature(preflightFeatures, registryEntry.requiredFeature)
|
|
217
|
+
const request = ctx.request
|
|
218
|
+
if (!request) {
|
|
219
|
+
throw new CrudHttpError(503, { error: 'documents.links.targetUnavailable' })
|
|
220
|
+
}
|
|
221
|
+
// The registry lookup is a loopback HTTP request; it must complete before
|
|
222
|
+
// the aggregate transaction so it never pins the PESSIMISTIC_WRITE lock or
|
|
223
|
+
// a second pool connection. Freshness at commit is preserved by the
|
|
224
|
+
// in-transaction re-checks below (fresh ACL, module availability, feature).
|
|
225
|
+
const verified = await verifyEntityRegistrySelection(request, input.link)
|
|
226
|
+
const canonicalInput = buildCanonicalLinkInput(input, verified)
|
|
227
|
+
const writeEm = resolveDocumentsCommandEntityManager(ctx)
|
|
228
|
+
let link: DocumentEntityLink | null = null
|
|
229
|
+
let created = false
|
|
230
|
+
let before!: LinkStateSnapshot
|
|
231
|
+
let after!: LinkStateSnapshot
|
|
232
|
+
await withAtomicFlush(writeEm, [
|
|
233
|
+
async () => {
|
|
234
|
+
await lockDocumentAggregateRoot(writeEm, input.documentId, scope)
|
|
235
|
+
const features = await assertDocumentCommandCanEdit(ctx, writeEm, input.documentId, scope)
|
|
236
|
+
if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {
|
|
237
|
+
throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })
|
|
238
|
+
}
|
|
239
|
+
assertCommandFeature(features, registryEntry.requiredFeature)
|
|
240
|
+
const existing = await loadLinkByTarget(writeEm, canonicalInput, true)
|
|
241
|
+
before = captureLinkState(existing, input.linkId)
|
|
242
|
+
if (existing && !existing.deletedAt) {
|
|
243
|
+
link = existing
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
await assertDocumentEntityLinkCapacity(writeEm, input.documentId, scope)
|
|
247
|
+
link = existing ?? writeEm.create(
|
|
248
|
+
DocumentEntityLink,
|
|
249
|
+
createDocumentEntityLinkData({
|
|
250
|
+
id: input.linkId,
|
|
251
|
+
documentId: input.documentId,
|
|
252
|
+
scope,
|
|
253
|
+
actorUserId: resolveDocumentsCommandActor(ctx),
|
|
254
|
+
link: canonicalInput.link,
|
|
255
|
+
}),
|
|
256
|
+
)
|
|
257
|
+
if (!existing) writeEm.persist(link)
|
|
258
|
+
link.labelSnapshot = canonicalInput.link.label
|
|
259
|
+
link.hrefSnapshot = canonicalInput.link.href
|
|
260
|
+
link.source = canonicalInput.link.source
|
|
261
|
+
link.createdByUserId = resolveDocumentsCommandActor(ctx)
|
|
262
|
+
link.deletedAt = null
|
|
263
|
+
link.updatedAt = nextDocumentVersion(link.updatedAt)
|
|
264
|
+
created = true
|
|
265
|
+
},
|
|
266
|
+
() => {
|
|
267
|
+
const captured = link as DocumentEntityLink | null
|
|
268
|
+
if (!captured) throw new Error('[internal] document link create produced no row')
|
|
269
|
+
after = captureLinkState(captured, captured.id)
|
|
270
|
+
},
|
|
271
|
+
], { transaction: true, label: 'documents.link.create' })
|
|
272
|
+
const finalLink = link as DocumentEntityLink | null
|
|
273
|
+
if (!finalLink) throw new Error('[internal] document link create produced no row')
|
|
274
|
+
|
|
275
|
+
if (!created) {
|
|
276
|
+
return {
|
|
277
|
+
id: finalLink.id,
|
|
278
|
+
created: false,
|
|
279
|
+
updatedAt: finalLink.updatedAt.toISOString(),
|
|
280
|
+
before,
|
|
281
|
+
after,
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
await bufferLinkMutationSideEffects(ctx, 'created', finalLink, {
|
|
286
|
+
entityType: input.link.entityType,
|
|
287
|
+
entityId: input.link.entityId,
|
|
288
|
+
})
|
|
289
|
+
return {
|
|
290
|
+
id: finalLink.id,
|
|
291
|
+
created: true,
|
|
292
|
+
updatedAt: finalLink.updatedAt.toISOString(),
|
|
293
|
+
before,
|
|
294
|
+
after,
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
async buildLog({ input, result }) {
|
|
298
|
+
if (!result.created) return { skipLog: true }
|
|
299
|
+
const { translate } = await resolveTranslations()
|
|
300
|
+
return {
|
|
301
|
+
actionLabel: translate('documents.audit.linkCreated', 'Link document to record'),
|
|
302
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,
|
|
303
|
+
resourceId: result.id,
|
|
304
|
+
parentResourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
305
|
+
parentResourceId: input.documentId,
|
|
306
|
+
tenantId: input.tenantId,
|
|
307
|
+
organizationId: input.organizationId,
|
|
308
|
+
snapshotBefore: result.before,
|
|
309
|
+
snapshotAfter: result.after,
|
|
310
|
+
payload: {
|
|
311
|
+
undo: {
|
|
312
|
+
before: result.before,
|
|
313
|
+
after: result.after,
|
|
314
|
+
createdByCommand: result.created,
|
|
315
|
+
} satisfies LinkUndoPayload,
|
|
316
|
+
},
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
async undo({ logEntry, ctx }) {
|
|
320
|
+
const undo = extractUndoPayload<LinkUndoPayload>(logEntry)
|
|
321
|
+
if (!undo?.createdByCommand) return
|
|
322
|
+
const before = undo?.before
|
|
323
|
+
const after = undo?.after
|
|
324
|
+
if (!after || (before?.existed && before.deletedAt === null)) return
|
|
325
|
+
const input = linkCreateCommandSchema.parse(
|
|
326
|
+
logEntry.commandPayload && typeof logEntry.commandPayload === 'object'
|
|
327
|
+
? (logEntry.commandPayload as { __redoInput?: unknown }).__redoInput
|
|
328
|
+
: {},
|
|
329
|
+
)
|
|
330
|
+
const em = resolveDocumentsCommandEntityManager(ctx)
|
|
331
|
+
let link: DocumentEntityLink | null = null
|
|
332
|
+
await withAtomicFlush(em, [async () => {
|
|
333
|
+
await lockDocumentAggregateRoot(em, input.documentId, {
|
|
334
|
+
tenantId: input.tenantId,
|
|
335
|
+
organizationId: input.organizationId,
|
|
336
|
+
})
|
|
337
|
+
await authorizeLinkCreateUndo(ctx, em, input, input.link.entityType)
|
|
338
|
+
link = await loadLinkById(em, { ...input, linkId: after.id }, true, true)
|
|
339
|
+
if (!link) throw new CrudHttpError(409, { error: 'Record changed by another user' })
|
|
340
|
+
assertLinkStateUnchanged(link, after)
|
|
341
|
+
const version = nextDocumentVersion(link.updatedAt)
|
|
342
|
+
link.deletedAt = before?.deletedAt ? new Date(before.deletedAt) : version
|
|
343
|
+
link.updatedAt = version
|
|
344
|
+
}], { transaction: true, label: 'documents.link.create.undo' })
|
|
345
|
+
if (link) await bufferLinkMutationSideEffects(ctx, 'deleted', link, { undo: true })
|
|
346
|
+
},
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const deleteLinkCommand: CommandHandler<LinkDeleteCommandInput, LinkDeleteCommandResult> = {
|
|
350
|
+
id: 'documents.link.delete',
|
|
351
|
+
async execute(rawInput, ctx) {
|
|
352
|
+
const input = linkDeleteCommandSchema.parse(rawInput)
|
|
353
|
+
const scope = resolveDocumentsCommandScope(ctx, input)
|
|
354
|
+
const em = resolveDocumentsCommandEntityManager(ctx)
|
|
355
|
+
let link: DocumentEntityLink | null = null
|
|
356
|
+
let before!: LinkStateSnapshot
|
|
357
|
+
let after!: LinkStateSnapshot
|
|
358
|
+
await withAtomicFlush(em, [
|
|
359
|
+
async () => {
|
|
360
|
+
await lockDocumentAggregateRoot(em, input.documentId, scope)
|
|
361
|
+
await assertDocumentCommandCanEdit(ctx, em, input.documentId, scope)
|
|
362
|
+
link = await loadLinkById(em, input, false, true)
|
|
363
|
+
if (!link) throw new CrudHttpError(404, { error: 'documents.links.notFound' })
|
|
364
|
+
before = captureLinkState(link, input.linkId)
|
|
365
|
+
await enforceCommandOptimisticLockWithGuards(ctx.container, {
|
|
366
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,
|
|
367
|
+
resourceId: link.id,
|
|
368
|
+
current: link.updatedAt,
|
|
369
|
+
request: ctx.request ?? null,
|
|
370
|
+
})
|
|
371
|
+
const version = nextDocumentVersion(link.updatedAt)
|
|
372
|
+
link.deletedAt = version
|
|
373
|
+
link.updatedAt = version
|
|
374
|
+
},
|
|
375
|
+
() => {
|
|
376
|
+
const captured = link as DocumentEntityLink | null
|
|
377
|
+
if (!captured) throw new Error('[internal] document link delete produced no row')
|
|
378
|
+
after = captureLinkState(captured, captured.id)
|
|
379
|
+
},
|
|
380
|
+
], { transaction: true, label: 'documents.link.delete' })
|
|
381
|
+
const deletedLink = link as DocumentEntityLink | null
|
|
382
|
+
if (!deletedLink) throw new Error('[internal] document link delete produced no row')
|
|
383
|
+
await bufferLinkMutationSideEffects(ctx, 'deleted', deletedLink)
|
|
384
|
+
return {
|
|
385
|
+
id: deletedLink.id,
|
|
386
|
+
updatedAt: deletedLink.updatedAt.toISOString(),
|
|
387
|
+
before,
|
|
388
|
+
after,
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
async buildLog({ input, result }) {
|
|
392
|
+
const { translate } = await resolveTranslations()
|
|
393
|
+
return {
|
|
394
|
+
actionLabel: translate('documents.audit.linkDeleted', 'Unlink document from record'),
|
|
395
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentEntityLink,
|
|
396
|
+
resourceId: result.id,
|
|
397
|
+
parentResourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
398
|
+
parentResourceId: input.documentId,
|
|
399
|
+
tenantId: input.tenantId,
|
|
400
|
+
organizationId: input.organizationId,
|
|
401
|
+
snapshotBefore: result.before,
|
|
402
|
+
snapshotAfter: result.after,
|
|
403
|
+
payload: {
|
|
404
|
+
undo: {
|
|
405
|
+
before: result.before,
|
|
406
|
+
after: result.after,
|
|
407
|
+
} satisfies LinkUndoPayload,
|
|
408
|
+
},
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
async undo({ logEntry, ctx }) {
|
|
412
|
+
const undo = extractUndoPayload<LinkUndoPayload>(logEntry)
|
|
413
|
+
const before = undo?.before
|
|
414
|
+
const after = undo?.after
|
|
415
|
+
if (!before?.existed || before.deletedAt !== null) return
|
|
416
|
+
const input = linkDeleteCommandSchema.parse(
|
|
417
|
+
logEntry.commandPayload && typeof logEntry.commandPayload === 'object'
|
|
418
|
+
? (logEntry.commandPayload as { __redoInput?: unknown }).__redoInput
|
|
419
|
+
: {},
|
|
420
|
+
)
|
|
421
|
+
const em = resolveDocumentsCommandEntityManager(ctx)
|
|
422
|
+
if (!after) throw new CrudHttpError(409, { error: 'Record changed by another user' })
|
|
423
|
+
// Re-verify the resurrected target over HTTP before the aggregate
|
|
424
|
+
// transaction so the loopback request never runs under the
|
|
425
|
+
// PESSIMISTIC_WRITE lock. The locked revalidation below pins the row to
|
|
426
|
+
// the undo snapshot (monotonic versions), so the state verified here is
|
|
427
|
+
// exactly the state that gets resurrected.
|
|
428
|
+
const preflightLink = await loadLinkById(
|
|
429
|
+
(ctx.container.resolve('em') as EntityManager).fork(),
|
|
430
|
+
input,
|
|
431
|
+
true,
|
|
432
|
+
)
|
|
433
|
+
if (!preflightLink) throw new CrudHttpError(409, { error: 'Record changed by another user' })
|
|
434
|
+
const preflightRegistryEntry = getEntityRegistryEntry(getDocumentEntityLinkType(preflightLink))
|
|
435
|
+
if (!preflightRegistryEntry) {
|
|
436
|
+
throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })
|
|
437
|
+
}
|
|
438
|
+
if (!isDocumentEntityRegistryModuleEnabled(preflightRegistryEntry)) {
|
|
439
|
+
throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })
|
|
440
|
+
}
|
|
441
|
+
if (!ctx.request) {
|
|
442
|
+
throw new CrudHttpError(503, { error: 'documents.links.targetUnavailable' })
|
|
443
|
+
}
|
|
444
|
+
const verified = await verifyEntityRegistrySelection(ctx.request, {
|
|
445
|
+
entityType: preflightRegistryEntry.type,
|
|
446
|
+
entityId: getDocumentEntityLinkEntityId(preflightLink),
|
|
447
|
+
label: preflightLink.labelSnapshot,
|
|
448
|
+
href: preflightLink.hrefSnapshot,
|
|
449
|
+
})
|
|
450
|
+
let link: DocumentEntityLink | null = null
|
|
451
|
+
await withAtomicFlush(em, [async () => {
|
|
452
|
+
await lockDocumentAggregateRoot(em, input.documentId, {
|
|
453
|
+
tenantId: input.tenantId,
|
|
454
|
+
organizationId: input.organizationId,
|
|
455
|
+
})
|
|
456
|
+
const features = await assertDocumentCommandCanEdit(ctx, em, input.documentId, {
|
|
457
|
+
tenantId: input.tenantId,
|
|
458
|
+
organizationId: input.organizationId,
|
|
459
|
+
})
|
|
460
|
+
link = await loadLinkById(em, input, true, true)
|
|
461
|
+
if (!link) throw new CrudHttpError(409, { error: 'Record changed by another user' })
|
|
462
|
+
assertLinkStateUnchanged(link, after)
|
|
463
|
+
const registryEntry = getEntityRegistryEntry(getDocumentEntityLinkType(link))
|
|
464
|
+
if (!registryEntry) throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })
|
|
465
|
+
if (!isDocumentEntityRegistryModuleEnabled(registryEntry)) {
|
|
466
|
+
throw new CrudHttpError(403, { error: 'documents.links.targetRestricted' })
|
|
467
|
+
}
|
|
468
|
+
assertCommandFeature(features, registryEntry.requiredFeature)
|
|
469
|
+
assertVerifiedLinkTargetMatchesRow(verified, link)
|
|
470
|
+
await assertDocumentEntityLinkCapacity(em, input.documentId, {
|
|
471
|
+
tenantId: input.tenantId,
|
|
472
|
+
organizationId: input.organizationId,
|
|
473
|
+
})
|
|
474
|
+
link.labelSnapshot = verified.label
|
|
475
|
+
link.hrefSnapshot = verified.href
|
|
476
|
+
link.deletedAt = null
|
|
477
|
+
link.updatedAt = nextDocumentVersion(link.updatedAt)
|
|
478
|
+
}], { transaction: true, label: 'documents.link.delete.undo' })
|
|
479
|
+
if (link) await bufferLinkMutationSideEffects(ctx, 'created', link, { undo: true })
|
|
480
|
+
},
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
registerCommand(createLinkCommand)
|
|
484
|
+
registerCommand(deleteLinkCommand)
|
|
485
|
+
|
|
486
|
+
export { createLinkCommand, deleteLinkCommand }
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
export { nextDocumentVersion } from '../lib/versioning'
|
|
8
|
+
|
|
9
|
+
export const documentsScopedCommandSchema = z.object({
|
|
10
|
+
tenantId: z.string().uuid(),
|
|
11
|
+
organizationId: z.string().uuid(),
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export type VersionedEntitySnapshot = {
|
|
15
|
+
id: string
|
|
16
|
+
updatedAt: string
|
|
17
|
+
deletedAt: string | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function assertVersionedSnapshot(
|
|
21
|
+
entity: { id: string; updatedAt: Date; deletedAt?: Date | null } | null,
|
|
22
|
+
expected: VersionedEntitySnapshot | null | undefined,
|
|
23
|
+
resourceKind: string,
|
|
24
|
+
): void {
|
|
25
|
+
if (!entity || !expected) {
|
|
26
|
+
throw new CrudHttpError(409, { error: 'Record changed by another user' })
|
|
27
|
+
}
|
|
28
|
+
assertOptimisticLock({
|
|
29
|
+
resourceKind,
|
|
30
|
+
resourceId: expected.id,
|
|
31
|
+
current: entity.updatedAt,
|
|
32
|
+
expected: expected.updatedAt,
|
|
33
|
+
envValue: 'all',
|
|
34
|
+
})
|
|
35
|
+
const deletedAt = entity.deletedAt?.toISOString() ?? null
|
|
36
|
+
if (deletedAt !== expected.deletedAt) {
|
|
37
|
+
throw new CrudHttpError(409, buildOptimisticLockConflictBody(
|
|
38
|
+
entity.updatedAt.toISOString(),
|
|
39
|
+
expected.updatedAt,
|
|
40
|
+
))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function readCommandRedoInput(logEntry: { commandPayload?: unknown }): unknown {
|
|
45
|
+
const payload = logEntry.commandPayload
|
|
46
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return null
|
|
47
|
+
return (payload as { __redoInput?: unknown }).__redoInput ?? null
|
|
48
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { EventPayload } from '@open-mercato/shared/modules/events'
|
|
2
|
+
|
|
3
|
+
export type DocumentsProjectedEventId =
|
|
4
|
+
| 'documents.document.updated'
|
|
5
|
+
| 'documents.document.archived'
|
|
6
|
+
| 'documents.document.duplicated'
|
|
7
|
+
| 'documents.document.unarchived'
|
|
8
|
+
| 'documents.document.shared'
|
|
9
|
+
| 'documents.document.unshared'
|
|
10
|
+
| 'documents.comment.created'
|
|
11
|
+
| 'documents.comment.mentioned'
|
|
12
|
+
| 'documents.comment.resolved'
|
|
13
|
+
| 'documents.version.restored'
|
|
14
|
+
|
|
15
|
+
export type DocumentsProjectionDescriptor =
|
|
16
|
+
| {
|
|
17
|
+
kind: 'event'
|
|
18
|
+
eventId: DocumentsProjectedEventId
|
|
19
|
+
tenantId: string
|
|
20
|
+
organizationId: string
|
|
21
|
+
payload: EventPayload
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
kind: 'mention-notification'
|
|
25
|
+
recipientUserId: string
|
|
26
|
+
tenantId: string
|
|
27
|
+
organizationId: string
|
|
28
|
+
documentId: string
|
|
29
|
+
documentTitle: string
|
|
30
|
+
commentId: string
|
|
31
|
+
authorUserId: string
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
kind: 'watch-notification'
|
|
35
|
+
recipientUserId: string
|
|
36
|
+
tenantId: string
|
|
37
|
+
organizationId: string
|
|
38
|
+
documentId: string
|
|
39
|
+
documentTitle: string
|
|
40
|
+
notificationType: 'documents.watch.commented' | 'documents.watch.changed'
|
|
41
|
+
bodyKey: string
|
|
42
|
+
sourceEntityType: string
|
|
43
|
+
sourceEntityId: string
|
|
44
|
+
linkHref: string
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
kind: 'watch-notification-fanout'
|
|
48
|
+
tenantId: string
|
|
49
|
+
organizationId: string
|
|
50
|
+
documentId: string
|
|
51
|
+
actorUserId: string
|
|
52
|
+
notificationType: 'documents.watch.commented' | 'documents.watch.changed'
|
|
53
|
+
bodyKey: string
|
|
54
|
+
sourceEntityType: string
|
|
55
|
+
sourceEntityId: string
|
|
56
|
+
linkHref: string
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
kind: 'document-index'
|
|
60
|
+
documentId: string
|
|
61
|
+
tenantId: string
|
|
62
|
+
organizationId: string
|
|
63
|
+
}
|
|
64
|
+
| {
|
|
65
|
+
kind: 'mention-notification-delete'
|
|
66
|
+
commentId: string
|
|
67
|
+
tenantId: string
|
|
68
|
+
organizationId: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type DocumentsProjectedCommandResult = {
|
|
72
|
+
projections?: DocumentsProjectionDescriptor[]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type DocumentsProjectionUndoPayload = {
|
|
76
|
+
projectionsAfterUndo?: DocumentsProjectionDescriptor[]
|
|
77
|
+
}
|