@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,375 @@
|
|
|
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 { escapeLikePattern } from '@open-mercato/shared/lib/db/escapeLikePattern'
|
|
6
|
+
import { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
7
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
8
|
+
import {
|
|
9
|
+
SortDir,
|
|
10
|
+
type QueryEngine,
|
|
11
|
+
type QueryOptions,
|
|
12
|
+
type QueryResult,
|
|
13
|
+
} from '@open-mercato/shared/lib/query/types'
|
|
14
|
+
import { sortRowsInMemory } from '@open-mercato/shared/lib/query/encrypted-sort'
|
|
15
|
+
import { resolveSearchMinTokenLength } from '@open-mercato/shared/lib/search/config'
|
|
16
|
+
import {
|
|
17
|
+
firstSafeDocumentsDisplayLabel,
|
|
18
|
+
sanitizeDocumentsDisplayLabel,
|
|
19
|
+
} from '../../../lib/displayLabels'
|
|
20
|
+
import { resolveUserLabels } from '../../../lib/userLabels'
|
|
21
|
+
import { resolveAuthPrincipalService } from '../../../lib/platformServices'
|
|
22
|
+
import { DocumentShare } from '../../../data/entities'
|
|
23
|
+
import {
|
|
24
|
+
handleDocumentsRouteError,
|
|
25
|
+
resolveDocumentCapabilityProjection,
|
|
26
|
+
resolveDocumentsContext,
|
|
27
|
+
routeErrorSchema,
|
|
28
|
+
withDocumentsContextErrors,
|
|
29
|
+
} from '../../_shared'
|
|
30
|
+
|
|
31
|
+
type RouteContext = {
|
|
32
|
+
params: Promise<{ id: string }> | { id: string }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const principalTypeSchema = z.enum(['user', 'role'])
|
|
36
|
+
const principalModeSchema = z.enum(['mention', 'share'])
|
|
37
|
+
const MAX_PRINCIPAL_PAGES = 50
|
|
38
|
+
const MAX_PRINCIPAL_PAGE_SIZE = 20
|
|
39
|
+
const PRINCIPAL_SEARCH_MIN_LENGTH = resolveSearchMinTokenLength()
|
|
40
|
+
const boundedSearchSchema = z.preprocess(
|
|
41
|
+
(value) => {
|
|
42
|
+
if (typeof value !== 'string') return value
|
|
43
|
+
const normalized = value.trim()
|
|
44
|
+
return normalized.length === 0 ? undefined : normalized
|
|
45
|
+
},
|
|
46
|
+
z.string().min(PRINCIPAL_SEARCH_MIN_LENGTH).max(120).optional(),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
export const principalsQuerySchema = z.object({
|
|
50
|
+
mode: principalModeSchema.default('share'),
|
|
51
|
+
type: principalTypeSchema.default('user'),
|
|
52
|
+
search: boundedSearchSchema,
|
|
53
|
+
page: z.coerce.number().int().min(1).max(MAX_PRINCIPAL_PAGES).default(1),
|
|
54
|
+
pageSize: z.coerce.number().int().min(1).max(MAX_PRINCIPAL_PAGE_SIZE).default(MAX_PRINCIPAL_PAGE_SIZE),
|
|
55
|
+
}).superRefine((value, context) => {
|
|
56
|
+
if (value.mode === 'mention' && value.type !== 'user') {
|
|
57
|
+
context.addIssue({ code: 'custom', path: ['type'], message: 'documents.principals.mentionUsersOnly' })
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const principalItemSchema = z.object({
|
|
62
|
+
id: z.string().uuid(),
|
|
63
|
+
label: z.string(),
|
|
64
|
+
secondary: z.string().nullable(),
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const principalsResponseSchema = z.object({
|
|
68
|
+
items: z.array(principalItemSchema),
|
|
69
|
+
page: z.number().int().positive(),
|
|
70
|
+
pageSize: z.number().int().positive(),
|
|
71
|
+
total: z.number().int().nonnegative(),
|
|
72
|
+
totalPages: z.number().int().positive(),
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const PRINCIPAL_ENTITY_IDS = {
|
|
76
|
+
user: 'auth:user',
|
|
77
|
+
role: 'auth:role',
|
|
78
|
+
} as const
|
|
79
|
+
|
|
80
|
+
type PrincipalType = z.infer<typeof principalTypeSchema>
|
|
81
|
+
type PrincipalRecord = Record<string, unknown>
|
|
82
|
+
|
|
83
|
+
// `name` and `email` are encrypted. Sorting either in QueryEngine disables the
|
|
84
|
+
// database limit so it can decrypt and sort the complete result set. A stable
|
|
85
|
+
// id order keeps every branch SQL-pageable; the picker remains search-first.
|
|
86
|
+
const PRINCIPAL_SORT = [{ field: 'id', dir: SortDir.Asc }] as const
|
|
87
|
+
|
|
88
|
+
function readString(record: Record<string, unknown>, ...keys: string[]): string | null {
|
|
89
|
+
for (const key of keys) {
|
|
90
|
+
const value = record[key]
|
|
91
|
+
if (typeof value === 'string' && value.trim().length > 0) return value.trim()
|
|
92
|
+
}
|
|
93
|
+
return null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function buildSearchPattern(search: string): string {
|
|
97
|
+
return `%${escapeLikePattern(search)}%`
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function excludedPrincipalFilter(excludedIds: readonly string[]) {
|
|
101
|
+
return excludedIds.length > 0 ? { id: { $nin: [...excludedIds] } } : {}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function buildPrincipalFilters(
|
|
105
|
+
type: PrincipalType,
|
|
106
|
+
search: string | undefined,
|
|
107
|
+
excludedIds: readonly string[],
|
|
108
|
+
) {
|
|
109
|
+
if (type === 'user') {
|
|
110
|
+
return search
|
|
111
|
+
? {
|
|
112
|
+
is_confirmed: true,
|
|
113
|
+
name: { $ilike: buildSearchPattern(search) },
|
|
114
|
+
...excludedPrincipalFilter(excludedIds),
|
|
115
|
+
}
|
|
116
|
+
: { is_confirmed: true, ...excludedPrincipalFilter(excludedIds) }
|
|
117
|
+
}
|
|
118
|
+
if (!search) return excludedIds.length > 0 ? excludedPrincipalFilter(excludedIds) : undefined
|
|
119
|
+
return {
|
|
120
|
+
name: { $ilike: buildSearchPattern(search) },
|
|
121
|
+
...excludedPrincipalFilter(excludedIds),
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function buildUserSearchFilters(
|
|
126
|
+
search: string,
|
|
127
|
+
field: 'name' | 'email' | 'intersection',
|
|
128
|
+
excludedIds: readonly string[],
|
|
129
|
+
) {
|
|
130
|
+
const pattern = `%${escapeLikePattern(search)}%`
|
|
131
|
+
return {
|
|
132
|
+
is_confirmed: true,
|
|
133
|
+
...(field === 'name' || field === 'intersection' ? { name: { $ilike: pattern } } : {}),
|
|
134
|
+
...(field === 'email' || field === 'intersection' ? { email: { $ilike: pattern } } : {}),
|
|
135
|
+
...excludedPrincipalFilter(excludedIds),
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function buildPrincipalQueryOptions(input: {
|
|
140
|
+
type: PrincipalType
|
|
141
|
+
search?: string
|
|
142
|
+
page: number
|
|
143
|
+
pageSize: number
|
|
144
|
+
tenantId: string
|
|
145
|
+
organizationId: string
|
|
146
|
+
excludedIds: readonly string[]
|
|
147
|
+
filters?: QueryOptions['filters']
|
|
148
|
+
fields?: string[]
|
|
149
|
+
sort?: QueryOptions['sort']
|
|
150
|
+
}): QueryOptions {
|
|
151
|
+
return {
|
|
152
|
+
// User name/email are encrypted. QueryEngine only selects matching ids;
|
|
153
|
+
// the scoped decryption helper resolves display labels after pagination.
|
|
154
|
+
fields: input.fields ?? (input.type === 'user' ? ['id'] : ['id', 'name']),
|
|
155
|
+
tenantId: input.tenantId,
|
|
156
|
+
// QueryEngine's organizationIds contract treats an empty entry as the
|
|
157
|
+
// tenant-wide NULL partition. This includes users assigned to this document
|
|
158
|
+
// organization plus tenant-wide users while still applying tokenized search
|
|
159
|
+
// and automatic tenant/soft-delete guards.
|
|
160
|
+
...(input.type === 'user' ? { organizationIds: [input.organizationId, ''] } : {}),
|
|
161
|
+
withDeleted: false,
|
|
162
|
+
filters: input.filters ?? buildPrincipalFilters(input.type, input.search, input.excludedIds),
|
|
163
|
+
sort: input.sort ?? [...PRINCIPAL_SORT],
|
|
164
|
+
page: { page: input.page, pageSize: input.pageSize },
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function safeQueryTotal(result: QueryResult<PrincipalRecord>): number {
|
|
169
|
+
return Number.isFinite(result.total) && result.total > 0 ? Math.floor(result.total) : 0
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function queryPrincipalPage(input: {
|
|
173
|
+
queryEngine: QueryEngine
|
|
174
|
+
type: PrincipalType
|
|
175
|
+
search?: string
|
|
176
|
+
page: number
|
|
177
|
+
pageSize: number
|
|
178
|
+
tenantId: string
|
|
179
|
+
organizationId: string
|
|
180
|
+
excludedIds: readonly string[]
|
|
181
|
+
}): Promise<QueryResult<PrincipalRecord>> {
|
|
182
|
+
if (input.type !== 'user' || !input.search) {
|
|
183
|
+
return input.queryEngine.query<PrincipalRecord>(
|
|
184
|
+
PRINCIPAL_ENTITY_IDS[input.type],
|
|
185
|
+
buildPrincipalQueryOptions(input),
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// A QueryEngine `$or` group compiles base-field comparisons directly. That is
|
|
190
|
+
// unsafe for encrypted auth:user fields because the raw email ciphertext can
|
|
191
|
+
// never satisfy ILIKE. Keep each search predicate flat so both Basic and
|
|
192
|
+
// Hybrid engines route it through search_tokens. The intersection count makes
|
|
193
|
+
// the union total exact without loading every duplicate solely to count it.
|
|
194
|
+
const prefixSize = input.page * input.pageSize
|
|
195
|
+
const common = {
|
|
196
|
+
...input,
|
|
197
|
+
page: 1,
|
|
198
|
+
pageSize: prefixSize,
|
|
199
|
+
}
|
|
200
|
+
const [nameMatches, emailMatches, intersection] = await Promise.all([
|
|
201
|
+
input.queryEngine.query<PrincipalRecord>(
|
|
202
|
+
PRINCIPAL_ENTITY_IDS.user,
|
|
203
|
+
buildPrincipalQueryOptions({
|
|
204
|
+
...common,
|
|
205
|
+
filters: buildUserSearchFilters(input.search, 'name', input.excludedIds),
|
|
206
|
+
}),
|
|
207
|
+
),
|
|
208
|
+
input.queryEngine.query<PrincipalRecord>(
|
|
209
|
+
PRINCIPAL_ENTITY_IDS.user,
|
|
210
|
+
buildPrincipalQueryOptions({
|
|
211
|
+
...common,
|
|
212
|
+
filters: buildUserSearchFilters(input.search, 'email', input.excludedIds),
|
|
213
|
+
}),
|
|
214
|
+
),
|
|
215
|
+
input.queryEngine.query<PrincipalRecord>(
|
|
216
|
+
PRINCIPAL_ENTITY_IDS.user,
|
|
217
|
+
buildPrincipalQueryOptions({
|
|
218
|
+
...common,
|
|
219
|
+
pageSize: 1,
|
|
220
|
+
fields: ['id'],
|
|
221
|
+
filters: buildUserSearchFilters(input.search, 'intersection', input.excludedIds),
|
|
222
|
+
sort: [{ field: 'id', dir: SortDir.Asc }],
|
|
223
|
+
}),
|
|
224
|
+
),
|
|
225
|
+
])
|
|
226
|
+
|
|
227
|
+
const byId = new Map<string, PrincipalRecord>()
|
|
228
|
+
for (const item of [...nameMatches.items, ...emailMatches.items]) {
|
|
229
|
+
const id = readString(item, 'id')
|
|
230
|
+
if (id && !byId.has(id)) byId.set(id, item)
|
|
231
|
+
}
|
|
232
|
+
const merged = sortRowsInMemory(Array.from(byId.values()), [...PRINCIPAL_SORT])
|
|
233
|
+
const offset = (input.page - 1) * input.pageSize
|
|
234
|
+
const items = merged.slice(offset, offset + input.pageSize)
|
|
235
|
+
const nameTotal = safeQueryTotal(nameMatches)
|
|
236
|
+
const emailTotal = safeQueryTotal(emailMatches)
|
|
237
|
+
const overlapTotal = Math.min(nameTotal, emailTotal, safeQueryTotal(intersection))
|
|
238
|
+
const total = Math.max(byId.size, nameTotal + emailTotal - overlapTotal)
|
|
239
|
+
|
|
240
|
+
return { items, page: input.page, pageSize: input.pageSize, total }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export const metadata = {
|
|
244
|
+
GET: { requireAuth: true, requireFeatures: ['documents.view'] },
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export async function GET(request: Request, context: RouteContext): Promise<Response> {
|
|
248
|
+
try {
|
|
249
|
+
const { id: documentId } = await context.params
|
|
250
|
+
const url = new URL(request.url)
|
|
251
|
+
const query = principalsQuerySchema.parse(Object.fromEntries(url.searchParams.entries()))
|
|
252
|
+
const requiredFeature = query.mode === 'mention' ? 'documents.view' : 'documents.share'
|
|
253
|
+
const ctx = await resolveDocumentsContext(request, [requiredFeature])
|
|
254
|
+
const projection = await resolveDocumentCapabilityProjection(ctx, documentId)
|
|
255
|
+
const allowed = query.mode === 'mention'
|
|
256
|
+
? projection.capabilities.canComment
|
|
257
|
+
: projection.capabilities.canShare
|
|
258
|
+
if (!allowed) throw new CrudHttpError(403, { error: 'api.errors.forbidden' })
|
|
259
|
+
|
|
260
|
+
const authPrincipalService = resolveAuthPrincipalService(ctx.container)
|
|
261
|
+
if (!authPrincipalService) throw new CrudHttpError(403, { error: 'api.errors.forbidden' })
|
|
262
|
+
const protectedUserIds: string[] = !ctx.auth.isSuperAdmin && query.type === 'user'
|
|
263
|
+
? await authPrincipalService.listSuperAdminUserIds(ctx.tenantId)
|
|
264
|
+
: []
|
|
265
|
+
const existingShares = query.mode === 'share'
|
|
266
|
+
? await findWithDecryption(
|
|
267
|
+
ctx.em,
|
|
268
|
+
DocumentShare,
|
|
269
|
+
{
|
|
270
|
+
documentId,
|
|
271
|
+
tenantId: ctx.tenantId,
|
|
272
|
+
organizationId: ctx.organizationId,
|
|
273
|
+
principalType: query.type,
|
|
274
|
+
deletedAt: null,
|
|
275
|
+
},
|
|
276
|
+
{ fields: ['principalId'] as const },
|
|
277
|
+
{ tenantId: ctx.tenantId, organizationId: ctx.organizationId },
|
|
278
|
+
)
|
|
279
|
+
: []
|
|
280
|
+
const excludedIds = Array.from(new Set([
|
|
281
|
+
...protectedUserIds,
|
|
282
|
+
...existingShares.map((share) => share.principalId),
|
|
283
|
+
]))
|
|
284
|
+
let result: QueryResult<PrincipalRecord>
|
|
285
|
+
if (query.type === 'role') {
|
|
286
|
+
if (typeof authPrincipalService.queryActiveRolePage !== 'function') {
|
|
287
|
+
throw new CrudHttpError(403, { error: 'api.errors.forbidden' })
|
|
288
|
+
}
|
|
289
|
+
const rolePage = await authPrincipalService.queryActiveRolePage({
|
|
290
|
+
scope: { tenantId: ctx.tenantId, organizationId: ctx.organizationId },
|
|
291
|
+
search: query.search,
|
|
292
|
+
excludedIds,
|
|
293
|
+
page: query.page,
|
|
294
|
+
pageSize: query.pageSize,
|
|
295
|
+
})
|
|
296
|
+
result = { ...rolePage, items: rolePage.items.map((item) => ({ ...item })) }
|
|
297
|
+
} else {
|
|
298
|
+
const queryEngine = ctx.container.resolve('queryEngine') as QueryEngine
|
|
299
|
+
result = await queryPrincipalPage({
|
|
300
|
+
queryEngine,
|
|
301
|
+
type: query.type,
|
|
302
|
+
search: query.search,
|
|
303
|
+
page: query.page,
|
|
304
|
+
pageSize: query.pageSize,
|
|
305
|
+
tenantId: ctx.tenantId,
|
|
306
|
+
organizationId: ctx.organizationId,
|
|
307
|
+
excludedIds,
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
const { translate } = await resolveTranslations()
|
|
311
|
+
const fallbackLabel = query.type === 'user'
|
|
312
|
+
? translate('documents.users.unknown', 'Unknown user')
|
|
313
|
+
: translate('documents.roles.unknown', 'Unknown role')
|
|
314
|
+
const safeFallback = sanitizeDocumentsDisplayLabel(fallbackLabel)
|
|
315
|
+
?? (query.type === 'user' ? 'Unknown user' : 'Unknown role')
|
|
316
|
+
const userLabels = query.type === 'user'
|
|
317
|
+
? await resolveUserLabels(
|
|
318
|
+
ctx.container,
|
|
319
|
+
{ tenantId: ctx.tenantId, organizationId: ctx.organizationId },
|
|
320
|
+
result.items.flatMap((item) => {
|
|
321
|
+
const id = readString(item, 'id')
|
|
322
|
+
return id ? [id] : []
|
|
323
|
+
}),
|
|
324
|
+
)
|
|
325
|
+
: null
|
|
326
|
+
const items = result.items.flatMap((item) => {
|
|
327
|
+
const id = readString(item, 'id')
|
|
328
|
+
if (!id) return []
|
|
329
|
+
const resolvedUser = userLabels?.get(id) ?? null
|
|
330
|
+
const label = firstSafeDocumentsDisplayLabel(
|
|
331
|
+
resolvedUser?.label,
|
|
332
|
+
readString(item, 'label', 'name'),
|
|
333
|
+
safeFallback,
|
|
334
|
+
) ?? safeFallback
|
|
335
|
+
const secondary = sanitizeDocumentsDisplayLabel(
|
|
336
|
+
resolvedUser?.secondary ?? readString(item, 'secondary'),
|
|
337
|
+
)
|
|
338
|
+
return [{ id, label, secondary }]
|
|
339
|
+
})
|
|
340
|
+
const total = Math.max(0, Number.isFinite(result.total) ? result.total : items.length)
|
|
341
|
+
const totalPages = Math.min(
|
|
342
|
+
MAX_PRINCIPAL_PAGES,
|
|
343
|
+
Math.max(1, Math.ceil(total / query.pageSize)),
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
return NextResponse.json(
|
|
347
|
+
{ items, page: query.page, pageSize: query.pageSize, total, totalPages },
|
|
348
|
+
{ headers: { 'Cache-Control': 'private, no-store' } },
|
|
349
|
+
)
|
|
350
|
+
} catch (error) {
|
|
351
|
+
return handleDocumentsRouteError(error, 'documents.principals.list')
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export const openApi: OpenApiRouteDoc = withDocumentsContextErrors({
|
|
356
|
+
tag: 'Documents',
|
|
357
|
+
summary: 'Document-scoped principal picker',
|
|
358
|
+
pathParams: z.object({ id: z.string().uuid() }),
|
|
359
|
+
methods: {
|
|
360
|
+
GET: {
|
|
361
|
+
summary: 'List principals eligible for document mentions or sharing',
|
|
362
|
+
description:
|
|
363
|
+
'Returns a bounded, document-authorized user or role page without requiring broad Auth administration grants.',
|
|
364
|
+
query: principalsQuerySchema,
|
|
365
|
+
responses: [{ status: 200, description: 'Eligible principal page', schema: principalsResponseSchema }],
|
|
366
|
+
errors: [
|
|
367
|
+
{ status: 400, description: 'Invalid picker query', schema: routeErrorSchema },
|
|
368
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
369
|
+
{ status: 403, description: 'Document capability denied', schema: routeErrorSchema },
|
|
370
|
+
],
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
export default { GET }
|
|
@@ -0,0 +1,267 @@
|
|
|
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 { documentUpdateSchema } from '../../data/validators'
|
|
6
|
+
import { DOCUMENTS_ENTITY_IDS } from '../../lib/constants'
|
|
7
|
+
import { deriveDocumentCapabilities } from '../../lib/capabilities'
|
|
8
|
+
import { isDocumentFavorite } from '../../lib/favorites'
|
|
9
|
+
import { isDocumentWatched } from '../../lib/watchers'
|
|
10
|
+
import {
|
|
11
|
+
assertDocumentNotArchived,
|
|
12
|
+
handleDocumentsRouteError,
|
|
13
|
+
hasDocumentsFeature,
|
|
14
|
+
loadScopedDocument,
|
|
15
|
+
readBody,
|
|
16
|
+
resolveActorUserId,
|
|
17
|
+
resolveDocumentCapabilityProjection,
|
|
18
|
+
resolveDocumentsContext,
|
|
19
|
+
routeErrorSchema,
|
|
20
|
+
runMutationGuardAfterSuccess,
|
|
21
|
+
serializeDocument,
|
|
22
|
+
validateMutationGuard,
|
|
23
|
+
withDocumentsContextErrors,
|
|
24
|
+
} from '../_shared'
|
|
25
|
+
import {
|
|
26
|
+
attachDocumentsOperationMetadata,
|
|
27
|
+
buildDocumentsCommandRuntimeContext,
|
|
28
|
+
resolveDocumentsCommandBus,
|
|
29
|
+
} from '../_commands'
|
|
30
|
+
import type {
|
|
31
|
+
DocumentDeleteCommandInput,
|
|
32
|
+
DocumentUpdateCommandInput,
|
|
33
|
+
} from '../../commands/document-crud'
|
|
34
|
+
|
|
35
|
+
type RouteContext = {
|
|
36
|
+
params: Promise<{ id: string }> | { id: string }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const capabilitiesSchema = z.object({
|
|
40
|
+
canView: z.boolean(),
|
|
41
|
+
canComment: z.boolean(),
|
|
42
|
+
canEdit: z.boolean(),
|
|
43
|
+
canShare: z.boolean(),
|
|
44
|
+
canDelete: z.boolean(),
|
|
45
|
+
canCreate: z.boolean(),
|
|
46
|
+
canManageTemplates: z.boolean(),
|
|
47
|
+
canArchive: z.boolean(),
|
|
48
|
+
canDuplicate: z.boolean(),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const detailResponseSchema = z.object({
|
|
52
|
+
id: z.string().uuid(),
|
|
53
|
+
title: z.string(),
|
|
54
|
+
folderId: z.string().uuid().nullable(),
|
|
55
|
+
ownerUserId: z.string().uuid(),
|
|
56
|
+
createdByUserId: z.string().uuid(),
|
|
57
|
+
isActive: z.boolean(),
|
|
58
|
+
archivedAt: z.string().nullable(),
|
|
59
|
+
isFavorite: z.boolean(),
|
|
60
|
+
isWatching: z.boolean(),
|
|
61
|
+
createdAt: z.string(),
|
|
62
|
+
updatedAt: z.string(),
|
|
63
|
+
tier: z.enum(['owner', 'editor', 'commenter', 'viewer']),
|
|
64
|
+
canShare: z.boolean(),
|
|
65
|
+
capabilities: capabilitiesSchema,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const mutationResponseSchema = z.object({
|
|
69
|
+
id: z.string().uuid(),
|
|
70
|
+
updatedAt: z.string(),
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const deleteResponseSchema = z.object({
|
|
74
|
+
ok: z.boolean(),
|
|
75
|
+
id: z.string().uuid(),
|
|
76
|
+
updatedAt: z.string(),
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
export const metadata = {
|
|
80
|
+
GET: { requireAuth: true, requireFeatures: ['documents.view'] },
|
|
81
|
+
PUT: { requireAuth: true, requireFeatures: ['documents.edit'] },
|
|
82
|
+
DELETE: { requireAuth: true, requireFeatures: ['documents.delete'] },
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function resolveId(context: RouteContext): Promise<string> {
|
|
86
|
+
const params = await context.params
|
|
87
|
+
return params.id
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function GET(request: Request, context: RouteContext): Promise<Response> {
|
|
91
|
+
try {
|
|
92
|
+
const id = await resolveId(context)
|
|
93
|
+
const ctx = await resolveDocumentsContext(request, ['documents.view'])
|
|
94
|
+
const projection = await resolveDocumentCapabilityProjection(ctx, id)
|
|
95
|
+
if (!projection.relationshipTier || !projection.capabilities.canView) {
|
|
96
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
97
|
+
}
|
|
98
|
+
const document = await loadScopedDocument(ctx, id)
|
|
99
|
+
const archivedAt = document.archivedAt?.toISOString() ?? null
|
|
100
|
+
const capabilities = deriveDocumentCapabilities({
|
|
101
|
+
relationshipTier: projection.relationshipTier,
|
|
102
|
+
managerOverride: hasDocumentsFeature(ctx.auth, 'documents.manage'),
|
|
103
|
+
archived: archivedAt !== null,
|
|
104
|
+
userFeatures: ctx.auth.features,
|
|
105
|
+
})
|
|
106
|
+
const isFavorite = await isDocumentFavorite(
|
|
107
|
+
ctx.em,
|
|
108
|
+
{
|
|
109
|
+
tenantId: ctx.tenantId,
|
|
110
|
+
organizationId: ctx.organizationId,
|
|
111
|
+
userId: resolveActorUserId(ctx.auth),
|
|
112
|
+
},
|
|
113
|
+
id,
|
|
114
|
+
)
|
|
115
|
+
const isWatching = await isDocumentWatched(
|
|
116
|
+
ctx.em,
|
|
117
|
+
{
|
|
118
|
+
tenantId: ctx.tenantId,
|
|
119
|
+
organizationId: ctx.organizationId,
|
|
120
|
+
userId: resolveActorUserId(ctx.auth),
|
|
121
|
+
},
|
|
122
|
+
id,
|
|
123
|
+
)
|
|
124
|
+
return NextResponse.json({
|
|
125
|
+
...serializeDocument(document),
|
|
126
|
+
archivedAt,
|
|
127
|
+
isFavorite,
|
|
128
|
+
isWatching,
|
|
129
|
+
tier: projection.relationshipTier,
|
|
130
|
+
canShare: capabilities.canShare,
|
|
131
|
+
capabilities,
|
|
132
|
+
})
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return handleDocumentsRouteError(error, 'documents.detail')
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export async function PUT(request: Request, context: RouteContext): Promise<Response> {
|
|
139
|
+
try {
|
|
140
|
+
const id = await resolveId(context)
|
|
141
|
+
const ctx = await resolveDocumentsContext(request, ['documents.edit'])
|
|
142
|
+
const projection = await resolveDocumentCapabilityProjection(ctx, id)
|
|
143
|
+
if (!projection.capabilities.canEdit) {
|
|
144
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
145
|
+
}
|
|
146
|
+
await assertDocumentNotArchived(ctx, id)
|
|
147
|
+
const body = await readBody(request)
|
|
148
|
+
const input = documentUpdateSchema.parse({ ...body, id })
|
|
149
|
+
const guardResult = await validateMutationGuard(ctx, {
|
|
150
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
151
|
+
resourceId: id,
|
|
152
|
+
operation: 'update',
|
|
153
|
+
mutationPayload: input,
|
|
154
|
+
mutationPayloadSchema: documentUpdateSchema,
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const commandInput: DocumentUpdateCommandInput = {
|
|
158
|
+
...input,
|
|
159
|
+
tenantId: ctx.tenantId,
|
|
160
|
+
organizationId: ctx.organizationId,
|
|
161
|
+
}
|
|
162
|
+
const { result, logEntry } = await resolveDocumentsCommandBus(ctx).execute<
|
|
163
|
+
DocumentUpdateCommandInput,
|
|
164
|
+
{ id: string; updatedAt: string }
|
|
165
|
+
>('documents.document.update', {
|
|
166
|
+
input: commandInput,
|
|
167
|
+
ctx: buildDocumentsCommandRuntimeContext(ctx),
|
|
168
|
+
})
|
|
169
|
+
await runMutationGuardAfterSuccess(ctx, guardResult, {
|
|
170
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
171
|
+
resourceId: id,
|
|
172
|
+
operation: 'update',
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const response = NextResponse.json({ id: result.id, updatedAt: result.updatedAt })
|
|
176
|
+
return attachDocumentsOperationMetadata(response, logEntry, {
|
|
177
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
178
|
+
resourceId: result.id,
|
|
179
|
+
})
|
|
180
|
+
} catch (error) {
|
|
181
|
+
return handleDocumentsRouteError(error, 'documents.update')
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function DELETE(request: Request, context: RouteContext): Promise<Response> {
|
|
186
|
+
try {
|
|
187
|
+
const id = await resolveId(context)
|
|
188
|
+
const ctx = await resolveDocumentsContext(request, ['documents.delete'])
|
|
189
|
+
const projection = await resolveDocumentCapabilityProjection(ctx, id)
|
|
190
|
+
if (!projection.capabilities.canDelete) {
|
|
191
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
192
|
+
}
|
|
193
|
+
const guardResult = await validateMutationGuard(ctx, {
|
|
194
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
195
|
+
resourceId: id,
|
|
196
|
+
operation: 'delete',
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
const commandInput: DocumentDeleteCommandInput = {
|
|
200
|
+
id,
|
|
201
|
+
tenantId: ctx.tenantId,
|
|
202
|
+
organizationId: ctx.organizationId,
|
|
203
|
+
}
|
|
204
|
+
const { result, logEntry } = await resolveDocumentsCommandBus(ctx).execute<
|
|
205
|
+
DocumentDeleteCommandInput,
|
|
206
|
+
{ id: string; updatedAt: string }
|
|
207
|
+
>('documents.document.delete', {
|
|
208
|
+
input: commandInput,
|
|
209
|
+
ctx: buildDocumentsCommandRuntimeContext(ctx),
|
|
210
|
+
})
|
|
211
|
+
await runMutationGuardAfterSuccess(ctx, guardResult, {
|
|
212
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
213
|
+
resourceId: id,
|
|
214
|
+
operation: 'delete',
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
const response = NextResponse.json({ ok: true, id: result.id, updatedAt: result.updatedAt })
|
|
218
|
+
return attachDocumentsOperationMetadata(response, logEntry, {
|
|
219
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.document,
|
|
220
|
+
resourceId: result.id,
|
|
221
|
+
})
|
|
222
|
+
} catch (error) {
|
|
223
|
+
return handleDocumentsRouteError(error, 'documents.delete')
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export const openApi: OpenApiRouteDoc = withDocumentsContextErrors({
|
|
228
|
+
tag: 'Documents',
|
|
229
|
+
summary: 'Document detail',
|
|
230
|
+
pathParams: z.object({ id: z.string().uuid() }),
|
|
231
|
+
methods: {
|
|
232
|
+
GET: {
|
|
233
|
+
summary: 'Get document metadata',
|
|
234
|
+
responses: [{ status: 200, description: 'Document metadata', schema: detailResponseSchema }],
|
|
235
|
+
errors: [
|
|
236
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
237
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
238
|
+
{ status: 404, description: 'Not found', schema: routeErrorSchema },
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
PUT: {
|
|
242
|
+
summary: 'Update document metadata',
|
|
243
|
+
requestBody: { contentType: 'application/json', schema: documentUpdateSchema },
|
|
244
|
+
responses: [{ status: 200, description: 'Document updated', schema: mutationResponseSchema }],
|
|
245
|
+
errors: [
|
|
246
|
+
{ status: 400, description: 'Validation failed', schema: routeErrorSchema },
|
|
247
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
248
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
249
|
+
{ status: 409, description: 'Optimistic lock conflict', schema: routeErrorSchema },
|
|
250
|
+
{ status: 413, description: 'Request body exceeds the safe resource bound', schema: routeErrorSchema },
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
DELETE: {
|
|
254
|
+
summary: 'Delete document',
|
|
255
|
+
description: 'Transactionally releases every document-owned attachment row and its quota usage, soft-deletes the document record, then runs reference-checked provider cleanup after commit. Because attachment bytes cannot be restored, this operation is intentionally not undoable.',
|
|
256
|
+
responses: [{ status: 200, description: 'Document deleted', schema: deleteResponseSchema }],
|
|
257
|
+
errors: [
|
|
258
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
259
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
260
|
+
{ status: 404, description: 'Not found', schema: routeErrorSchema },
|
|
261
|
+
{ status: 409, description: 'Optimistic lock conflict', schema: routeErrorSchema },
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
export default { GET, PUT, DELETE }
|