@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
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { metadata } from './modules/documents/index'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const features = [
|
|
2
|
+
{ id: 'documents.view', title: 'View documents', module: 'documents' },
|
|
3
|
+
{ id: 'documents.create', title: 'Create documents', module: 'documents', dependsOn: ['documents.view'] },
|
|
4
|
+
{ id: 'documents.edit', title: 'Edit documents', module: 'documents', dependsOn: ['documents.view'] },
|
|
5
|
+
{ id: 'documents.delete', title: 'Delete documents', module: 'documents', dependsOn: ['documents.view'] },
|
|
6
|
+
{ id: 'documents.share', title: 'Share documents', module: 'documents', dependsOn: ['documents.view'] },
|
|
7
|
+
{ id: 'documents.templates.manage', title: 'Manage document templates', module: 'documents', dependsOn: ['documents.view'] },
|
|
8
|
+
{ id: 'documents.manage', title: 'Manage all documents', module: 'documents', dependsOn: ['documents.view'] },
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
export default features
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
5
|
+
import { enforceCommandOptimisticLockWithGuards } from '@open-mercato/shared/lib/crud/optimistic-lock-command'
|
|
6
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
7
|
+
import { Document } from '../../../data/entities'
|
|
8
|
+
import { DOCUMENTS_ENTITY_IDS } from '../../../lib/constants'
|
|
9
|
+
import type { DocumentLifecycleCommandInput, DocumentLifecycleCommandResult } from '../../../commands/lifecycle'
|
|
10
|
+
import {
|
|
11
|
+
attachDocumentsOperationMetadata,
|
|
12
|
+
buildDocumentsCommandRuntimeContext,
|
|
13
|
+
resolveDocumentsCommandBus,
|
|
14
|
+
} from '../../_commands'
|
|
15
|
+
import {
|
|
16
|
+
handleDocumentsRouteError,
|
|
17
|
+
resolveActorUserId,
|
|
18
|
+
resolveDocumentCapabilityProjection,
|
|
19
|
+
resolveDocumentsContext,
|
|
20
|
+
routeErrorSchema,
|
|
21
|
+
runMutationGuardAfterSuccess,
|
|
22
|
+
validateMutationGuard,
|
|
23
|
+
withDocumentsContextErrors,
|
|
24
|
+
} from '../../_shared'
|
|
25
|
+
|
|
26
|
+
type RouteContext = {
|
|
27
|
+
params: Promise<{ id: string }> | { id: string }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const lifecycleResponseSchema = z.object({
|
|
31
|
+
id: z.string().uuid(),
|
|
32
|
+
archivedAt: z.string().nullable(),
|
|
33
|
+
updatedAt: z.string(),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export const metadata = {
|
|
37
|
+
POST: { requireAuth: true, requireFeatures: ['documents.edit'] },
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function runDocumentLifecycleRoute(
|
|
41
|
+
request: Request,
|
|
42
|
+
context: RouteContext,
|
|
43
|
+
commandId: 'documents.document.archive' | 'documents.document.unarchive',
|
|
44
|
+
errorScope: string,
|
|
45
|
+
): Promise<Response> {
|
|
46
|
+
try {
|
|
47
|
+
const { id: documentId } = await context.params
|
|
48
|
+
const ctx = await resolveDocumentsContext(request, ['documents.edit'])
|
|
49
|
+
const projection = await resolveDocumentCapabilityProjection(ctx, documentId)
|
|
50
|
+
if (!projection.capabilities.canArchive) throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
51
|
+
|
|
52
|
+
const document = await findOneWithDecryption(
|
|
53
|
+
ctx.em,
|
|
54
|
+
Document,
|
|
55
|
+
{
|
|
56
|
+
id: documentId,
|
|
57
|
+
tenantId: ctx.tenantId,
|
|
58
|
+
organizationId: ctx.organizationId,
|
|
59
|
+
deletedAt: null,
|
|
60
|
+
},
|
|
61
|
+
{ fields: ['id', 'archivedAt', 'updatedAt'] },
|
|
62
|
+
{ tenantId: ctx.tenantId, organizationId: ctx.organizationId },
|
|
63
|
+
)
|
|
64
|
+
if (!document) throw new CrudHttpError(404, { error: 'documents.documents.notFound' })
|
|
65
|
+
await enforceCommandOptimisticLockWithGuards(ctx.container, {
|
|
66
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
67
|
+
resourceId: documentId,
|
|
68
|
+
current: document.updatedAt,
|
|
69
|
+
request,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const guardResult = await validateMutationGuard(ctx, {
|
|
73
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
74
|
+
resourceId: documentId,
|
|
75
|
+
operation: 'update',
|
|
76
|
+
mutationPayload: { action: commandId === 'documents.document.archive' ? 'archive' : 'unarchive' },
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const input: DocumentLifecycleCommandInput = {
|
|
80
|
+
tenantId: ctx.tenantId,
|
|
81
|
+
organizationId: ctx.organizationId,
|
|
82
|
+
documentId,
|
|
83
|
+
actorUserId: resolveActorUserId(ctx.auth),
|
|
84
|
+
expectedUpdatedAt: document.updatedAt.toISOString(),
|
|
85
|
+
}
|
|
86
|
+
const execution = await resolveDocumentsCommandBus(ctx).execute<
|
|
87
|
+
DocumentLifecycleCommandInput,
|
|
88
|
+
DocumentLifecycleCommandResult
|
|
89
|
+
>(commandId, { input, ctx: buildDocumentsCommandRuntimeContext(ctx) })
|
|
90
|
+
|
|
91
|
+
await runMutationGuardAfterSuccess(ctx, guardResult, {
|
|
92
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
93
|
+
resourceId: documentId,
|
|
94
|
+
operation: 'update',
|
|
95
|
+
})
|
|
96
|
+
return attachDocumentsOperationMetadata(
|
|
97
|
+
NextResponse.json({
|
|
98
|
+
id: execution.result.id,
|
|
99
|
+
archivedAt: execution.result.archivedAt,
|
|
100
|
+
updatedAt: execution.result.updatedAt,
|
|
101
|
+
}),
|
|
102
|
+
execution.logEntry,
|
|
103
|
+
{ resourceKind: DOCUMENTS_ENTITY_IDS.document, resourceId: documentId },
|
|
104
|
+
)
|
|
105
|
+
} catch (error) {
|
|
106
|
+
return handleDocumentsRouteError(error, errorScope)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function POST(request: Request, context: RouteContext): Promise<Response> {
|
|
111
|
+
return runDocumentLifecycleRoute(request, context, 'documents.document.archive', 'documents.archive')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const openApi: OpenApiRouteDoc = withDocumentsContextErrors({
|
|
115
|
+
tag: 'Documents',
|
|
116
|
+
summary: 'Archive document',
|
|
117
|
+
pathParams: z.object({ id: z.string().uuid() }),
|
|
118
|
+
methods: {
|
|
119
|
+
POST: {
|
|
120
|
+
summary: 'Archive a document, making it read-only and hidden from default listings',
|
|
121
|
+
responses: [{ status: 200, description: 'Archived document state', schema: lifecycleResponseSchema }],
|
|
122
|
+
errors: [
|
|
123
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
124
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
125
|
+
{ status: 404, description: 'Document not found', schema: routeErrorSchema },
|
|
126
|
+
{ status: 409, description: 'Document changed concurrently', schema: routeErrorSchema },
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
export default { POST }
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
5
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
6
|
+
import { DocumentAttachment } from '../../../../data/entities'
|
|
7
|
+
import { DOCUMENTS_ENTITY_IDS } from '../../../../lib/constants'
|
|
8
|
+
import { resolveAttachmentServicePort } from '../../../../lib/attachmentServicePort'
|
|
9
|
+
import { assertTier } from '../../../../lib/permissions'
|
|
10
|
+
import {
|
|
11
|
+
assertDocumentNotArchived,
|
|
12
|
+
handleDocumentsRouteError,
|
|
13
|
+
resolveDocumentsContext,
|
|
14
|
+
routeErrorSchema,
|
|
15
|
+
runMutationGuardAfterSuccess,
|
|
16
|
+
validateMutationGuard,
|
|
17
|
+
withDocumentsContextErrors,
|
|
18
|
+
} from '../../../_shared'
|
|
19
|
+
import {
|
|
20
|
+
buildDocumentsCommandRuntimeContext,
|
|
21
|
+
resolveDocumentsCommandBus,
|
|
22
|
+
} from '../../../_commands'
|
|
23
|
+
import type { DocumentAttachmentDeleteCommandInput } from '../../../../commands/attachments'
|
|
24
|
+
|
|
25
|
+
type RouteContext = {
|
|
26
|
+
params: Promise<{ id: string; attachmentId: string }> | { id: string; attachmentId: string }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const attachmentBinaryResponseSchema = z.unknown().describe('Binary file content')
|
|
30
|
+
const attachmentDeleteResponseSchema = z.object({ ok: z.boolean() })
|
|
31
|
+
const DOCUMENT_ATTACHMENT_PARTITION_CODE = 'privateAttachments'
|
|
32
|
+
|
|
33
|
+
export const metadata = {
|
|
34
|
+
GET: { requireAuth: true, requireFeatures: ['documents.view'] },
|
|
35
|
+
DELETE: { requireAuth: true, requireFeatures: ['documents.edit'] },
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function resolveParams(context: RouteContext): Promise<{ documentId: string; attachmentId: string }> {
|
|
39
|
+
const params = await context.params
|
|
40
|
+
return { documentId: params.id, attachmentId: params.attachmentId }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function loadDocumentAttachment(
|
|
44
|
+
ctx: Awaited<ReturnType<typeof resolveDocumentsContext>>,
|
|
45
|
+
documentId: string,
|
|
46
|
+
attachmentId: string,
|
|
47
|
+
): Promise<DocumentAttachment> {
|
|
48
|
+
const documentAttachment = await findOneWithDecryption(
|
|
49
|
+
ctx.em,
|
|
50
|
+
DocumentAttachment,
|
|
51
|
+
{
|
|
52
|
+
documentId,
|
|
53
|
+
attachmentId,
|
|
54
|
+
tenantId: ctx.tenantId,
|
|
55
|
+
organizationId: ctx.organizationId,
|
|
56
|
+
deletedAt: null,
|
|
57
|
+
},
|
|
58
|
+
undefined,
|
|
59
|
+
{ tenantId: ctx.tenantId, organizationId: ctx.organizationId },
|
|
60
|
+
)
|
|
61
|
+
if (!documentAttachment) throw new CrudHttpError(404, { error: 'Attachment not found' })
|
|
62
|
+
return documentAttachment
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function GET(request: Request, context: RouteContext): Promise<Response> {
|
|
66
|
+
try {
|
|
67
|
+
const { documentId, attachmentId } = await resolveParams(context)
|
|
68
|
+
const ctx = await resolveDocumentsContext(request, ['documents.view'])
|
|
69
|
+
await assertTier(ctx.em, documentId, ctx.auth, 'viewer')
|
|
70
|
+
await loadDocumentAttachment(ctx, documentId, attachmentId)
|
|
71
|
+
const forceDownload = new URL(request.url).searchParams.get('download') === '1'
|
|
72
|
+
const attachmentService = resolveAttachmentServicePort(ctx.container)
|
|
73
|
+
const result = await attachmentService.readScoped({
|
|
74
|
+
attachmentId,
|
|
75
|
+
auth: ctx.auth,
|
|
76
|
+
expectedOwner: { entityId: DOCUMENTS_ENTITY_IDS.document, recordId: documentId },
|
|
77
|
+
expectedAssignment: { type: DOCUMENTS_ENTITY_IDS.document, id: documentId },
|
|
78
|
+
expectedPartitionCode: DOCUMENT_ATTACHMENT_PARTITION_CODE,
|
|
79
|
+
requirePrivatePartition: true,
|
|
80
|
+
forceDownload,
|
|
81
|
+
})
|
|
82
|
+
const headers: Record<string, string> = {
|
|
83
|
+
'Cache-Control': 'private, no-store, max-age=0, must-revalidate',
|
|
84
|
+
'Content-Security-Policy': "default-src 'none'; sandbox",
|
|
85
|
+
'Content-Type': result.contentType,
|
|
86
|
+
'Content-Disposition': result.contentDisposition,
|
|
87
|
+
'Content-Length': String(result.buffer.length),
|
|
88
|
+
'Expires': '0',
|
|
89
|
+
'Pragma': 'no-cache',
|
|
90
|
+
'X-Content-Type-Options': 'nosniff',
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return new NextResponse(new Uint8Array(result.buffer), { status: 200, headers })
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return handleDocumentsRouteError(error, 'documents.attachments.read')
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function DELETE(request: Request, context: RouteContext): Promise<Response> {
|
|
100
|
+
try {
|
|
101
|
+
const { documentId, attachmentId } = await resolveParams(context)
|
|
102
|
+
const ctx = await resolveDocumentsContext(request, ['documents.edit'])
|
|
103
|
+
await assertTier(ctx.em, documentId, ctx.auth, 'editor')
|
|
104
|
+
await assertDocumentNotArchived(ctx, documentId)
|
|
105
|
+
const documentAttachment = await loadDocumentAttachment(ctx, documentId, attachmentId)
|
|
106
|
+
const guardResult = await validateMutationGuard(ctx, {
|
|
107
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentAttachment,
|
|
108
|
+
resourceId: documentAttachment.id,
|
|
109
|
+
operation: 'delete',
|
|
110
|
+
mutationPayload: { documentId, attachmentId },
|
|
111
|
+
})
|
|
112
|
+
const input: DocumentAttachmentDeleteCommandInput = {
|
|
113
|
+
documentId,
|
|
114
|
+
attachmentId,
|
|
115
|
+
tenantId: ctx.tenantId,
|
|
116
|
+
organizationId: ctx.organizationId,
|
|
117
|
+
}
|
|
118
|
+
await resolveDocumentsCommandBus(ctx).execute('documents.attachment.delete', {
|
|
119
|
+
input,
|
|
120
|
+
ctx: buildDocumentsCommandRuntimeContext(ctx),
|
|
121
|
+
})
|
|
122
|
+
await runMutationGuardAfterSuccess(ctx, guardResult, {
|
|
123
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentAttachment,
|
|
124
|
+
resourceId: documentAttachment.id,
|
|
125
|
+
operation: 'delete',
|
|
126
|
+
})
|
|
127
|
+
return NextResponse.json({ ok: true })
|
|
128
|
+
} catch (error) {
|
|
129
|
+
return handleDocumentsRouteError(error, 'documents.attachments.delete')
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const openApi: OpenApiRouteDoc = withDocumentsContextErrors({
|
|
134
|
+
tag: 'Documents',
|
|
135
|
+
summary: 'Read document attachment',
|
|
136
|
+
pathParams: z.object({
|
|
137
|
+
id: z.string().uuid(),
|
|
138
|
+
attachmentId: z.string().uuid(),
|
|
139
|
+
}),
|
|
140
|
+
methods: {
|
|
141
|
+
GET: {
|
|
142
|
+
summary: 'Read a document-scoped attachment',
|
|
143
|
+
responses: [{ status: 200, description: 'Attachment bytes', schema: attachmentBinaryResponseSchema }],
|
|
144
|
+
errors: [
|
|
145
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
146
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
147
|
+
{ status: 404, description: 'Attachment not found', schema: routeErrorSchema },
|
|
148
|
+
{ status: 500, description: 'Partition misconfigured', schema: routeErrorSchema },
|
|
149
|
+
{ status: 503, description: 'Attachment service unavailable', schema: routeErrorSchema },
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
DELETE: {
|
|
153
|
+
summary: 'Detach a document-scoped attachment',
|
|
154
|
+
description: 'Transactionally removes the document attachment row and quota usage, then runs reference-checked provider cleanup after commit. This operation is audited and intentionally not undoable.',
|
|
155
|
+
responses: [{ status: 200, description: 'Attachment deletion committed', schema: attachmentDeleteResponseSchema }],
|
|
156
|
+
errors: [
|
|
157
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
158
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
159
|
+
{ status: 404, description: 'Attachment not found', schema: routeErrorSchema },
|
|
160
|
+
{ status: 409, description: 'Optimistic lock conflict or attachment still referenced', schema: routeErrorSchema },
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
export default { GET, DELETE }
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
5
|
+
import {
|
|
6
|
+
DOCUMENT_ATTACHMENT_UPLOAD_CONTEXT,
|
|
7
|
+
type DocumentAttachmentCreateCommandInput,
|
|
8
|
+
type DocumentAttachmentCreateCommandResult,
|
|
9
|
+
} from '../../../commands/attachments'
|
|
10
|
+
import { DOCUMENTS_ENTITY_IDS } from '../../../lib/constants'
|
|
11
|
+
import { readAttachmentUploadForm, resolveAttachmentServicePort } from '../../../lib/attachmentServicePort'
|
|
12
|
+
import { assertTier } from '../../../lib/permissions'
|
|
13
|
+
import {
|
|
14
|
+
assertDocumentNotArchived,
|
|
15
|
+
handleDocumentsRouteError,
|
|
16
|
+
loadScopedDocument,
|
|
17
|
+
resolveDocumentsContext,
|
|
18
|
+
routeErrorSchema,
|
|
19
|
+
runMutationGuardAfterSuccess,
|
|
20
|
+
validateMutationGuard,
|
|
21
|
+
withDocumentsContextErrors,
|
|
22
|
+
} from '../../_shared'
|
|
23
|
+
import {
|
|
24
|
+
attachDocumentsOperationMetadata,
|
|
25
|
+
buildDocumentsCommandRuntimeContext,
|
|
26
|
+
resolveDocumentsCommandBus,
|
|
27
|
+
} from '../../_commands'
|
|
28
|
+
|
|
29
|
+
type RouteContext = {
|
|
30
|
+
params: Promise<{ id: string }> | { id: string }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const attachmentUploadBodySchema = z.object({
|
|
34
|
+
file: z.string().min(1).describe('Binary file payload supplied as multipart form-data'),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// The guard sees exactly the fields the command consumes. `fileSize` is pinned
|
|
38
|
+
// to the real byte length: a guard may rename or retype a file, but it must not
|
|
39
|
+
// be able to talk the route past the upload-size validation below.
|
|
40
|
+
const attachmentGuardPayloadSchema = z.object({
|
|
41
|
+
fileName: z.string().trim().min(1),
|
|
42
|
+
fileType: z.string(),
|
|
43
|
+
fileSize: z.number().int().nonnegative(),
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const attachmentUploadResponseSchema = z.object({
|
|
47
|
+
id: z.string().uuid(),
|
|
48
|
+
attachmentId: z.string().uuid(),
|
|
49
|
+
updatedAt: z.string().datetime(),
|
|
50
|
+
url: z.string(),
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
export const metadata = {
|
|
54
|
+
POST: { requireAuth: true, requireFeatures: ['documents.edit'] },
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function resolveId(context: RouteContext): Promise<string> {
|
|
58
|
+
const params = await context.params
|
|
59
|
+
return params.id
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function assertMultipartUpload(request: Request): void {
|
|
63
|
+
const contentType = request.headers.get('content-type') ?? ''
|
|
64
|
+
if (!contentType.toLowerCase().includes('multipart/form-data')) {
|
|
65
|
+
throw new CrudHttpError(400, { error: 'Expected multipart/form-data' })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function readUploadFile(form: FormData): File {
|
|
70
|
+
const file = form.get('file')
|
|
71
|
+
if (!(file instanceof File)) {
|
|
72
|
+
throw new CrudHttpError(400, { error: 'File is required' })
|
|
73
|
+
}
|
|
74
|
+
return file
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function POST(request: Request, context: RouteContext): Promise<Response> {
|
|
78
|
+
try {
|
|
79
|
+
const documentId = await resolveId(context)
|
|
80
|
+
const ctx = await resolveDocumentsContext(request, ['documents.edit'])
|
|
81
|
+
await assertTier(ctx.em, documentId, ctx.auth, 'editor')
|
|
82
|
+
await assertDocumentNotArchived(ctx, documentId)
|
|
83
|
+
await loadScopedDocument(ctx, documentId)
|
|
84
|
+
const attachmentService = resolveAttachmentServicePort(ctx.container)
|
|
85
|
+
assertMultipartUpload(request)
|
|
86
|
+
const form = await readAttachmentUploadForm(attachmentService, request)
|
|
87
|
+
const file = readUploadFile(form)
|
|
88
|
+
attachmentService.validateUpload({ fileName: file.name, fileSize: file.size })
|
|
89
|
+
const guardPayload = attachmentGuardPayloadSchema.parse({
|
|
90
|
+
fileName: file.name,
|
|
91
|
+
fileType: file.type,
|
|
92
|
+
fileSize: file.size,
|
|
93
|
+
})
|
|
94
|
+
const guardResult = await validateMutationGuard(ctx, {
|
|
95
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentAttachment,
|
|
96
|
+
resourceId: documentId,
|
|
97
|
+
operation: 'create',
|
|
98
|
+
mutationPayload: guardPayload,
|
|
99
|
+
mutationPayloadSchema: attachmentGuardPayloadSchema.refine(
|
|
100
|
+
(payload) => payload.fileSize === file.size,
|
|
101
|
+
{ path: ['fileSize'], message: '[internal] mutation guard changed the file size' },
|
|
102
|
+
),
|
|
103
|
+
})
|
|
104
|
+
// Re-validate against the possibly rewritten name before the bytes are read.
|
|
105
|
+
attachmentService.validateUpload({
|
|
106
|
+
fileName: guardPayload.fileName,
|
|
107
|
+
fileSize: guardPayload.fileSize,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const buffer = Buffer.from(await file.arrayBuffer())
|
|
111
|
+
const commandInput: DocumentAttachmentCreateCommandInput = {
|
|
112
|
+
documentId,
|
|
113
|
+
tenantId: ctx.tenantId,
|
|
114
|
+
organizationId: ctx.organizationId,
|
|
115
|
+
fileName: guardPayload.fileName,
|
|
116
|
+
fileType: guardPayload.fileType || null,
|
|
117
|
+
fileSize: guardPayload.fileSize,
|
|
118
|
+
}
|
|
119
|
+
const commandContext = {
|
|
120
|
+
...buildDocumentsCommandRuntimeContext(ctx),
|
|
121
|
+
[DOCUMENT_ATTACHMENT_UPLOAD_CONTEXT]: { buffer },
|
|
122
|
+
}
|
|
123
|
+
const { result, logEntry } = await resolveDocumentsCommandBus(ctx).execute<
|
|
124
|
+
DocumentAttachmentCreateCommandInput,
|
|
125
|
+
DocumentAttachmentCreateCommandResult
|
|
126
|
+
>('documents.attachment.create', {
|
|
127
|
+
input: commandInput,
|
|
128
|
+
ctx: commandContext,
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
await runMutationGuardAfterSuccess(ctx, guardResult, {
|
|
132
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentAttachment,
|
|
133
|
+
resourceId: result.linkId,
|
|
134
|
+
operation: 'create',
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const url = `/api/documents/${encodeURIComponent(documentId)}/attachments/${encodeURIComponent(result.attachmentId)}`
|
|
138
|
+
const response = NextResponse.json({
|
|
139
|
+
id: result.id,
|
|
140
|
+
attachmentId: result.attachmentId,
|
|
141
|
+
updatedAt: result.updatedAt,
|
|
142
|
+
url,
|
|
143
|
+
}, { status: 201 })
|
|
144
|
+
return attachDocumentsOperationMetadata(response, logEntry, {
|
|
145
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentAttachment,
|
|
146
|
+
resourceId: result.linkId,
|
|
147
|
+
})
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return handleDocumentsRouteError(error, 'documents.attachments.create')
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const openApi: OpenApiRouteDoc = withDocumentsContextErrors({
|
|
154
|
+
tag: 'Documents',
|
|
155
|
+
summary: 'Document attachments',
|
|
156
|
+
pathParams: z.object({ id: z.string().uuid() }),
|
|
157
|
+
methods: {
|
|
158
|
+
POST: {
|
|
159
|
+
summary: 'Upload document attachment',
|
|
160
|
+
requestBody: { contentType: 'multipart/form-data', schema: attachmentUploadBodySchema },
|
|
161
|
+
responses: [{ status: 201, description: 'Document-scoped attachment uploaded', schema: attachmentUploadResponseSchema }],
|
|
162
|
+
errors: [
|
|
163
|
+
{ status: 400, description: 'Payload validation error', schema: routeErrorSchema },
|
|
164
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
165
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
166
|
+
{ status: 413, description: 'Attachment too large', schema: routeErrorSchema },
|
|
167
|
+
{ status: 503, description: 'Attachment service unavailable', schema: routeErrorSchema },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
export default { POST }
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
4
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
5
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
6
|
+
import { createLogger } from '@open-mercato/shared/lib/logger'
|
|
7
|
+
import {
|
|
8
|
+
COLLAB_TOKEN_TTL_SECONDS,
|
|
9
|
+
isCollabTokenV2Ready,
|
|
10
|
+
mintCollabTokenV2,
|
|
11
|
+
verifyCollabTokenV2,
|
|
12
|
+
} from '../../../lib/collabToken'
|
|
13
|
+
import { resolveUserLabels } from '../../../lib/userLabels'
|
|
14
|
+
import { resolveCollaborationUserColor } from '../../../lib/collaborationAwareness'
|
|
15
|
+
import { resolveDocumentsCollaborationEndpoint } from '../../../lib/collabEndpoint'
|
|
16
|
+
import { resolvePermission } from '../../../lib/permissions'
|
|
17
|
+
import {
|
|
18
|
+
loadDocumentArchivedState,
|
|
19
|
+
deriveCapabilitiesForContext,
|
|
20
|
+
handleDocumentsRouteError,
|
|
21
|
+
resolveActorUserId,
|
|
22
|
+
resolveDocumentsContext,
|
|
23
|
+
routeErrorSchema,
|
|
24
|
+
withDocumentsContextErrors,
|
|
25
|
+
} from '../../_shared'
|
|
26
|
+
|
|
27
|
+
type RouteContext = {
|
|
28
|
+
params: Promise<{ id: string }> | { id: string }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const collabTokenResponseSchema = z.object({
|
|
32
|
+
token: z.string(),
|
|
33
|
+
url: z.string().nullable(),
|
|
34
|
+
documentId: z.string(),
|
|
35
|
+
tier: z.enum(['owner', 'editor', 'commenter', 'viewer']),
|
|
36
|
+
expiresInSec: z.number(),
|
|
37
|
+
expiresAt: z.string(),
|
|
38
|
+
userName: z.string(),
|
|
39
|
+
userColor: z.string(),
|
|
40
|
+
canEdit: z.boolean(),
|
|
41
|
+
readOnly: z.boolean(),
|
|
42
|
+
user: z.object({
|
|
43
|
+
id: z.string(),
|
|
44
|
+
name: z.string(),
|
|
45
|
+
color: z.string(),
|
|
46
|
+
}),
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
export const metadata = {
|
|
50
|
+
GET: { requireAuth: true, requireFeatures: ['documents.view'] },
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const logger = createLogger('documents').child({ component: 'api' })
|
|
54
|
+
|
|
55
|
+
let warnedCollabTokenSecretNotReady = false
|
|
56
|
+
let warnedCollabEndpointInvalid = false
|
|
57
|
+
|
|
58
|
+
function warnCollabTokenSecretNotReadyOnce(): void {
|
|
59
|
+
if (warnedCollabTokenSecretNotReady) return
|
|
60
|
+
warnedCollabTokenSecretNotReady = true
|
|
61
|
+
logger.warn(
|
|
62
|
+
'DOCUMENTS_COLLAB_JWT_SECRET_V2 is missing, shorter than 32 UTF-8 bytes, '
|
|
63
|
+
+ 'or equal to DOCUMENTS_COLLAB_JWT_SECRET; collaboration tokens cannot be minted '
|
|
64
|
+
+ 'and clients fall back to non-collaborative editing.',
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function warnCollabEndpointInvalidOnce(): void {
|
|
69
|
+
if (warnedCollabEndpointInvalid) return
|
|
70
|
+
warnedCollabEndpointInvalid = true
|
|
71
|
+
logger.warn(
|
|
72
|
+
'Ignoring NEXT_PUBLIC_DOCUMENTS_COLLAB_URL because it is not a valid browser-reachable '
|
|
73
|
+
+ 'ws(s) endpoint; collaboration is disabled and clients fall back to non-collaborative editing.',
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function GET(request: Request, context: RouteContext): Promise<Response> {
|
|
78
|
+
try {
|
|
79
|
+
const params = await context.params
|
|
80
|
+
const id = params.id
|
|
81
|
+
const ctx = await resolveDocumentsContext(request, ['documents.view'])
|
|
82
|
+
// The collaboration sidecar currently reauthorizes the signed user
|
|
83
|
+
// identity and has no API-key subject with which to reload the key's
|
|
84
|
+
// restricted ACL/roles. Do not mint a token that would silently promote a
|
|
85
|
+
// bound key to its backing user's full collaboration access.
|
|
86
|
+
if (ctx.auth.isApiKey === true || ctx.auth.sub.startsWith('api_key:')) {
|
|
87
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
88
|
+
}
|
|
89
|
+
// One relationship lookup feeds both projections. The pre-archive check
|
|
90
|
+
// still runs first so an unauthorized caller cannot tell an existing
|
|
91
|
+
// document apart from a missing one via the 404 the archived read raises.
|
|
92
|
+
const relationshipTier = await resolvePermission(ctx.em, id, ctx.auth)
|
|
93
|
+
if (!relationshipTier || !deriveCapabilitiesForContext(ctx, relationshipTier).canView) {
|
|
94
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
95
|
+
}
|
|
96
|
+
const archivedState = await loadDocumentArchivedState(ctx, id)
|
|
97
|
+
const capabilities = deriveCapabilitiesForContext(ctx, relationshipTier, {
|
|
98
|
+
archived: archivedState.archivedAt !== null,
|
|
99
|
+
})
|
|
100
|
+
if (!capabilities.canView) {
|
|
101
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
102
|
+
}
|
|
103
|
+
const userId = resolveActorUserId(ctx.auth)
|
|
104
|
+
const [userLabels, translations] = await Promise.all([
|
|
105
|
+
resolveUserLabels(
|
|
106
|
+
ctx.container,
|
|
107
|
+
{ tenantId: ctx.tenantId, organizationId: ctx.organizationId },
|
|
108
|
+
[userId],
|
|
109
|
+
),
|
|
110
|
+
resolveTranslations(),
|
|
111
|
+
])
|
|
112
|
+
const userName = userLabels.get(userId)?.label
|
|
113
|
+
?? translations.translate('documents.users.unknown', 'Unknown user')
|
|
114
|
+
const userColor = resolveCollaborationUserColor(userId)
|
|
115
|
+
const readOnly = !capabilities.canEdit
|
|
116
|
+
if (!isCollabTokenV2Ready()) {
|
|
117
|
+
// A misconfigured capability secret must degrade to the same graceful
|
|
118
|
+
// non-collaborative response as an unset NEXT_PUBLIC_DOCUMENTS_COLLAB_URL
|
|
119
|
+
// (url: null) instead of a 500 the client would classify as transient
|
|
120
|
+
// and retry until its fallback timer.
|
|
121
|
+
warnCollabTokenSecretNotReadyOnce()
|
|
122
|
+
return NextResponse.json(
|
|
123
|
+
{
|
|
124
|
+
token: '',
|
|
125
|
+
url: null,
|
|
126
|
+
documentId: id,
|
|
127
|
+
tier: relationshipTier,
|
|
128
|
+
expiresInSec: COLLAB_TOKEN_TTL_SECONDS,
|
|
129
|
+
expiresAt: new Date(Date.now() + COLLAB_TOKEN_TTL_SECONDS * 1000).toISOString(),
|
|
130
|
+
userName,
|
|
131
|
+
userColor,
|
|
132
|
+
canEdit: capabilities.canEdit,
|
|
133
|
+
readOnly,
|
|
134
|
+
user: {
|
|
135
|
+
id: userId,
|
|
136
|
+
name: userName,
|
|
137
|
+
color: userColor,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{ headers: { 'Cache-Control': 'private, no-store' } },
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
const collaborationEndpoint = resolveDocumentsCollaborationEndpoint()
|
|
144
|
+
if (process.env.NEXT_PUBLIC_DOCUMENTS_COLLAB_URL && !collaborationEndpoint) {
|
|
145
|
+
warnCollabEndpointInvalidOnce()
|
|
146
|
+
}
|
|
147
|
+
const token = mintCollabTokenV2({
|
|
148
|
+
userId,
|
|
149
|
+
tenantId: ctx.tenantId,
|
|
150
|
+
organizationId: ctx.organizationId,
|
|
151
|
+
documentId: id,
|
|
152
|
+
tier: relationshipTier,
|
|
153
|
+
tokenVersion: 2,
|
|
154
|
+
readOnly,
|
|
155
|
+
})
|
|
156
|
+
const verifiedToken = verifyCollabTokenV2(token)
|
|
157
|
+
if (!verifiedToken) {
|
|
158
|
+
throw new Error('[internal] Failed to verify a freshly minted collaboration token')
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return NextResponse.json(
|
|
162
|
+
{
|
|
163
|
+
token,
|
|
164
|
+
url: collaborationEndpoint,
|
|
165
|
+
documentId: id,
|
|
166
|
+
tier: relationshipTier,
|
|
167
|
+
expiresInSec: COLLAB_TOKEN_TTL_SECONDS,
|
|
168
|
+
expiresAt: new Date(verifiedToken.exp * 1000).toISOString(),
|
|
169
|
+
userName,
|
|
170
|
+
userColor,
|
|
171
|
+
canEdit: capabilities.canEdit,
|
|
172
|
+
readOnly,
|
|
173
|
+
user: {
|
|
174
|
+
id: userId,
|
|
175
|
+
name: userName,
|
|
176
|
+
color: userColor,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{ headers: { 'Cache-Control': 'private, no-store' } },
|
|
180
|
+
)
|
|
181
|
+
} catch (error) {
|
|
182
|
+
return handleDocumentsRouteError(error, 'documents.collabToken.get')
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export const openApi: OpenApiRouteDoc = withDocumentsContextErrors({
|
|
187
|
+
tag: 'Documents',
|
|
188
|
+
summary: 'Document collaboration token',
|
|
189
|
+
pathParams: z.object({ id: z.string().uuid() }),
|
|
190
|
+
methods: {
|
|
191
|
+
GET: {
|
|
192
|
+
summary: 'Mint document collaboration token',
|
|
193
|
+
responses: [{ status: 200, description: 'Collaboration token', schema: collabTokenResponseSchema }],
|
|
194
|
+
errors: [
|
|
195
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
196
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
197
|
+
{ status: 404, description: 'Not found', schema: routeErrorSchema },
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
export default { GET }
|