@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,535 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
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 { sanitizeRichTextHtml } from '@open-mercato/shared/lib/html/sanitizeRichText'
|
|
6
|
+
import { assertTier } from '../../../lib/permissions'
|
|
7
|
+
import { loadDocumentContent } from '../../../lib/contentService'
|
|
8
|
+
import {
|
|
9
|
+
isDocxRenderFailedError,
|
|
10
|
+
isDocxRenderOutputTooLargeError,
|
|
11
|
+
isDocxRenderOverloadedError,
|
|
12
|
+
isDocxRenderTimeoutError,
|
|
13
|
+
renderDocxWithCapacity,
|
|
14
|
+
} from '../../../lib/docxRenderer'
|
|
15
|
+
import {
|
|
16
|
+
isPdfRenderOutputTooLargeError,
|
|
17
|
+
isPdfRenderOverloadedError,
|
|
18
|
+
isPdfRenderTimeoutError,
|
|
19
|
+
renderPdfWithChromium,
|
|
20
|
+
} from '../../../lib/pdfRenderer'
|
|
21
|
+
import { buildDocumentPdfHtml } from '../../../lib/pdfHtml'
|
|
22
|
+
import {
|
|
23
|
+
assertDocumentContentResourceLimits,
|
|
24
|
+
DOCUMENTS_MAX_CONTENT_HTML_BYTES,
|
|
25
|
+
maxBase64EncodedLength,
|
|
26
|
+
} from '../../../lib/resourceLimits'
|
|
27
|
+
import { DOCUMENTS_JSON_BODY_LIMITS } from '../../../lib/requestBody'
|
|
28
|
+
import {
|
|
29
|
+
handleDocumentsRouteError,
|
|
30
|
+
loadScopedDocument,
|
|
31
|
+
readBody,
|
|
32
|
+
resolveDocumentsContext,
|
|
33
|
+
routeErrorSchema,
|
|
34
|
+
withDocumentsContextErrors,
|
|
35
|
+
} from '../../_shared'
|
|
36
|
+
|
|
37
|
+
type RouteContext = {
|
|
38
|
+
params: Promise<{ id: string }> | { id: string }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type ExportFormat = 'docx' | 'pdf'
|
|
42
|
+
|
|
43
|
+
export type PdfRequestDescriptor = {
|
|
44
|
+
url: string
|
|
45
|
+
resourceType: string
|
|
46
|
+
isNavigationRequest: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const exportQuerySchema = z.object({
|
|
50
|
+
format: z.enum(['docx', 'pdf']).optional(),
|
|
51
|
+
})
|
|
52
|
+
const docxSnapshotSchema = z.object({
|
|
53
|
+
contentHtml: z.string().max(DOCUMENTS_MAX_CONTENT_HTML_BYTES),
|
|
54
|
+
pageBreakMarker: z.string().regex(/^OM_DOCX_PAGE_BREAK_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i),
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const fileResponseSchema = z.string().describe('Binary .docx or PDF file attachment')
|
|
58
|
+
|
|
59
|
+
const COMMON_CHROMIUM_PATHS = [
|
|
60
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
61
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
62
|
+
'/usr/bin/google-chrome',
|
|
63
|
+
'/usr/bin/chromium',
|
|
64
|
+
'/usr/bin/chromium-browser',
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
export const DOCX_MAX_EMBEDDED_IMAGE_BYTES = 1024 * 1024
|
|
68
|
+
export const PDF_MAX_EMBEDDED_IMAGE_BYTES = 1024 * 1024
|
|
69
|
+
export const MAX_EMBEDDED_RASTER_DIMENSION = 4096
|
|
70
|
+
export const MAX_EMBEDDED_RASTER_PIXELS = 16 * 1024 * 1024
|
|
71
|
+
const DATA_IMAGE_PATTERN = /^data:image\/(png|jpeg);base64,([a-z0-9+/]+={0,2})$/i
|
|
72
|
+
const IMAGE_TAG_PATTERN = /<img\b[^>]*>/gi
|
|
73
|
+
const ENTITY_REF_SPAN_PATTERN = /<span\b(?=[^>]*\bdata-entity-ref(?:\s|=|>))[^>]*>([\s\S]*?)<\/span>/gi
|
|
74
|
+
const HIGHLIGHT_OPEN_PATTERN = /<mark\b([^>]*)>/gi
|
|
75
|
+
const HIGHLIGHT_CLOSE_PATTERN = /<\/mark>/gi
|
|
76
|
+
const LEADING_TABLE_HEADER_ROW_PATTERN = /(<table\b[^>]*>)(\s*)<tbody>(\s*)(<tr>(?:(?:\s*)<th\b[^>]*>[\s\S]*?<\/th>)+\s*<\/tr>)([\s\S]*?)<\/tbody>/gi
|
|
77
|
+
const IMAGE_SOURCE_PATTERN = /\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi
|
|
78
|
+
|
|
79
|
+
export const metadata = {
|
|
80
|
+
GET: { requireAuth: true, requireFeatures: ['documents.view'] },
|
|
81
|
+
POST: { requireAuth: true, requireFeatures: ['documents.view'] },
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function resolveId(context: RouteContext): Promise<string> {
|
|
85
|
+
const params = await context.params
|
|
86
|
+
return params.id
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function resolveExportFormat(value: string | null): ExportFormat | null {
|
|
90
|
+
if (value === null || value === 'docx') return 'docx'
|
|
91
|
+
if (value === 'pdf') return 'pdf'
|
|
92
|
+
return null
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function escapeHtml(value: string): string {
|
|
96
|
+
return value
|
|
97
|
+
.replace(/&/g, '&')
|
|
98
|
+
.replace(/</g, '<')
|
|
99
|
+
.replace(/>/g, '>')
|
|
100
|
+
.replace(/"/g, '"')
|
|
101
|
+
.replace(/'/g, ''')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function buildSafeFilename(title: string): string {
|
|
105
|
+
return title.replace(/[^a-z0-9\-_. ]/gi, '_').slice(0, 120) || 'document'
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type ImageSource = {
|
|
109
|
+
index: number
|
|
110
|
+
length: number
|
|
111
|
+
value: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function readSingleImageSource(tag: string): ImageSource | null {
|
|
115
|
+
const matches = Array.from(tag.matchAll(IMAGE_SOURCE_PATTERN))
|
|
116
|
+
if (matches.length !== 1 || matches[0].index === undefined) return null
|
|
117
|
+
return {
|
|
118
|
+
index: matches[0].index,
|
|
119
|
+
length: matches[0][0].length,
|
|
120
|
+
value: matches[0][1] ?? matches[0][2] ?? matches[0][3] ?? '',
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function replaceImageSource(tag: string, source: ImageSource, value: string): string {
|
|
125
|
+
return `${tag.slice(0, source.index)}src="${escapeHtml(value)}"${tag.slice(source.index + source.length)}`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function hasSafeRasterDimensions(width: number, height: number): boolean {
|
|
129
|
+
return Number.isSafeInteger(width)
|
|
130
|
+
&& Number.isSafeInteger(height)
|
|
131
|
+
&& width > 0
|
|
132
|
+
&& height > 0
|
|
133
|
+
&& width <= MAX_EMBEDDED_RASTER_DIMENSION
|
|
134
|
+
&& height <= MAX_EMBEDDED_RASTER_DIMENSION
|
|
135
|
+
&& width * height <= MAX_EMBEDDED_RASTER_PIXELS
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function pngCrc32(bytes: Buffer): number {
|
|
139
|
+
let crc = 0xffffffff
|
|
140
|
+
for (const byte of bytes) {
|
|
141
|
+
crc ^= byte
|
|
142
|
+
for (let bit = 0; bit < 8; bit += 1) {
|
|
143
|
+
crc = (crc >>> 1) ^ ((crc & 1) ? 0xedb88320 : 0)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return (crc ^ 0xffffffff) >>> 0
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function readPngDimensions(bytes: Buffer): { width: number; height: number } | null {
|
|
150
|
+
const signature = '89504e470d0a1a0a'
|
|
151
|
+
if (bytes.length < 45 || bytes.subarray(0, 8).toString('hex') !== signature) return null
|
|
152
|
+
|
|
153
|
+
let offset = 8
|
|
154
|
+
let dimensions: { width: number; height: number } | null = null
|
|
155
|
+
let sawImageData = false
|
|
156
|
+
while (offset + 12 <= bytes.length) {
|
|
157
|
+
const length = bytes.readUInt32BE(offset)
|
|
158
|
+
const chunkEnd = offset + 12 + length
|
|
159
|
+
if (chunkEnd > bytes.length) return null
|
|
160
|
+
const type = bytes.subarray(offset + 4, offset + 8)
|
|
161
|
+
const data = bytes.subarray(offset + 8, offset + 8 + length)
|
|
162
|
+
const expectedCrc = bytes.readUInt32BE(offset + 8 + length)
|
|
163
|
+
if (pngCrc32(bytes.subarray(offset + 4, offset + 8 + length)) !== expectedCrc) return null
|
|
164
|
+
const chunkType = type.toString('ascii')
|
|
165
|
+
if (offset === 8) {
|
|
166
|
+
if (chunkType !== 'IHDR' || length !== 13) return null
|
|
167
|
+
const width = data.readUInt32BE(0)
|
|
168
|
+
const height = data.readUInt32BE(4)
|
|
169
|
+
const bitDepth = data[8]
|
|
170
|
+
const colorType = data[9]
|
|
171
|
+
const validBitDepth = (
|
|
172
|
+
(colorType === 0 && [1, 2, 4, 8, 16].includes(bitDepth!))
|
|
173
|
+
|| (colorType === 2 && [8, 16].includes(bitDepth!))
|
|
174
|
+
|| (colorType === 3 && [1, 2, 4, 8].includes(bitDepth!))
|
|
175
|
+
|| (colorType === 4 && [8, 16].includes(bitDepth!))
|
|
176
|
+
|| (colorType === 6 && [8, 16].includes(bitDepth!))
|
|
177
|
+
)
|
|
178
|
+
if (
|
|
179
|
+
!validBitDepth
|
|
180
|
+
|| data[10] !== 0
|
|
181
|
+
|| data[11] !== 0
|
|
182
|
+
|| (data[12] !== 0 && data[12] !== 1)
|
|
183
|
+
|| !hasSafeRasterDimensions(width, height)
|
|
184
|
+
) return null
|
|
185
|
+
dimensions = { width, height }
|
|
186
|
+
} else if (chunkType === 'IHDR') {
|
|
187
|
+
return null
|
|
188
|
+
}
|
|
189
|
+
if (chunkType === 'IDAT') sawImageData = true
|
|
190
|
+
if (chunkType === 'IEND') {
|
|
191
|
+
return length === 0 && chunkEnd === bytes.length && sawImageData
|
|
192
|
+
? dimensions
|
|
193
|
+
: null
|
|
194
|
+
}
|
|
195
|
+
offset = chunkEnd
|
|
196
|
+
}
|
|
197
|
+
return null
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const JPEG_START_OF_FRAME_MARKERS = new Set([
|
|
201
|
+
0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7,
|
|
202
|
+
0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf,
|
|
203
|
+
])
|
|
204
|
+
|
|
205
|
+
function readJpegDimensions(bytes: Buffer): { width: number; height: number } | null {
|
|
206
|
+
if (
|
|
207
|
+
bytes.length < 12
|
|
208
|
+
|| bytes[0] !== 0xff
|
|
209
|
+
|| bytes[1] !== 0xd8
|
|
210
|
+
|| bytes.at(-2) !== 0xff
|
|
211
|
+
|| bytes.at(-1) !== 0xd9
|
|
212
|
+
) return null
|
|
213
|
+
|
|
214
|
+
let offset = 2
|
|
215
|
+
while (offset + 4 <= bytes.length - 2) {
|
|
216
|
+
if (bytes[offset] !== 0xff) return null
|
|
217
|
+
while (bytes[offset] === 0xff) offset += 1
|
|
218
|
+
const marker = bytes[offset]
|
|
219
|
+
offset += 1
|
|
220
|
+
if (marker === undefined || marker === 0xda || marker === 0xd9) return null
|
|
221
|
+
if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) continue
|
|
222
|
+
if (offset + 2 > bytes.length - 2) return null
|
|
223
|
+
const segmentLength = bytes.readUInt16BE(offset)
|
|
224
|
+
if (segmentLength < 2 || offset + segmentLength > bytes.length - 2) return null
|
|
225
|
+
if (JPEG_START_OF_FRAME_MARKERS.has(marker)) {
|
|
226
|
+
if (segmentLength < 7) return null
|
|
227
|
+
const height = bytes.readUInt16BE(offset + 3)
|
|
228
|
+
const width = bytes.readUInt16BE(offset + 5)
|
|
229
|
+
return hasSafeRasterDimensions(width, height) ? { width, height } : null
|
|
230
|
+
}
|
|
231
|
+
offset += segmentLength
|
|
232
|
+
}
|
|
233
|
+
return null
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function readSafeEmbeddedImageBytes(source: string, maxDecodedBytes: number): number | null {
|
|
237
|
+
const match = DATA_IMAGE_PATTERN.exec(source)
|
|
238
|
+
if (!match) return null
|
|
239
|
+
const mimeType = match[1].toLowerCase()
|
|
240
|
+
const payload = match[2]
|
|
241
|
+
if (
|
|
242
|
+
!payload
|
|
243
|
+
|| payload.length > maxBase64EncodedLength(maxDecodedBytes)
|
|
244
|
+
|| payload.length % 4 !== 0
|
|
245
|
+
) return null
|
|
246
|
+
const bytes = Buffer.from(payload, 'base64')
|
|
247
|
+
if (
|
|
248
|
+
bytes.length === 0
|
|
249
|
+
|| bytes.length > maxDecodedBytes
|
|
250
|
+
|| bytes.toString('base64') !== payload
|
|
251
|
+
) return null
|
|
252
|
+
const dimensions = mimeType === 'png'
|
|
253
|
+
? readPngDimensions(bytes)
|
|
254
|
+
: readJpegDimensions(bytes)
|
|
255
|
+
if (!dimensions) return null
|
|
256
|
+
return bytes.length
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Keep only bounded embedded PNG/JPEG payloads for the in-process OpenXML
|
|
261
|
+
* renderer. Replace those small raster images with sanitizer-safe placeholders,
|
|
262
|
+
* sanitize the full rich text, then restore the in-memory payloads. Every URL,
|
|
263
|
+
* relative path, blob source, malformed data URI, SVG, duplicate src attribute,
|
|
264
|
+
* and aggregate payload beyond the bound is removed before conversion, so no
|
|
265
|
+
* exporter ever dereferences a remote image.
|
|
266
|
+
*/
|
|
267
|
+
function sanitizeEmbeddedRasterExportContent(
|
|
268
|
+
contentHtml: string,
|
|
269
|
+
maxEmbeddedBytes: number,
|
|
270
|
+
placeholderNamespace: 'docx' | 'pdf',
|
|
271
|
+
): string {
|
|
272
|
+
assertDocumentContentResourceLimits(
|
|
273
|
+
{ contentHtml },
|
|
274
|
+
{ error: 'documents.export.inputTooLarge' },
|
|
275
|
+
)
|
|
276
|
+
const embeddedImages = new Map<string, string>()
|
|
277
|
+
let embeddedBytes = 0
|
|
278
|
+
const placeholderHtml = contentHtml.replace(IMAGE_TAG_PATTERN, (tag) => {
|
|
279
|
+
const source = readSingleImageSource(tag)
|
|
280
|
+
if (!source) return ''
|
|
281
|
+
const remainingBytes = maxEmbeddedBytes - embeddedBytes
|
|
282
|
+
const imageBytes = readSafeEmbeddedImageBytes(source.value, remainingBytes)
|
|
283
|
+
if (imageBytes === null || embeddedBytes + imageBytes > maxEmbeddedBytes) return ''
|
|
284
|
+
embeddedBytes += imageBytes
|
|
285
|
+
const placeholder = `https://${placeholderNamespace}.invalid/__embedded-image-${embeddedImages.size}`
|
|
286
|
+
embeddedImages.set(placeholder, source.value)
|
|
287
|
+
return replaceImageSource(tag, source, placeholder)
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
return sanitizeRichTextHtml(placeholderHtml).replace(IMAGE_TAG_PATTERN, (tag) => {
|
|
291
|
+
const source = readSingleImageSource(tag)
|
|
292
|
+
if (!source) return ''
|
|
293
|
+
const embeddedSource = embeddedImages.get(source.value)
|
|
294
|
+
return embeddedSource ? replaceImageSource(tag, source, embeddedSource) : ''
|
|
295
|
+
})
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export function sanitizeDocxExportContent(contentHtml: string): string {
|
|
299
|
+
return sanitizeEmbeddedRasterExportContent(
|
|
300
|
+
contentHtml,
|
|
301
|
+
DOCX_MAX_EMBEDDED_IMAGE_BYTES,
|
|
302
|
+
'docx',
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Sanitize stored rich text and bound the decoded aggregate raster payload
|
|
308
|
+
* before authored HTML reaches Chromium. Request interception remains a
|
|
309
|
+
* defense-in-depth boundary, not the primary content validator.
|
|
310
|
+
*/
|
|
311
|
+
export function sanitizePdfExportContent(contentHtml: string): string {
|
|
312
|
+
const semanticHtml = contentHtml
|
|
313
|
+
.replace(ENTITY_REF_SPAN_PATTERN, '<strong><code><span>$1</span></code></strong>')
|
|
314
|
+
.replace(HIGHLIGHT_OPEN_PATTERN, (_tag, attributes: string) => (
|
|
315
|
+
/\bstyle\s*=/i.test(attributes)
|
|
316
|
+
? `<span${attributes}>`
|
|
317
|
+
: `<span style="background-color:#fef08a"${attributes}>`
|
|
318
|
+
))
|
|
319
|
+
.replace(HIGHLIGHT_CLOSE_PATTERN, '</span>')
|
|
320
|
+
const sanitized = sanitizeEmbeddedRasterExportContent(
|
|
321
|
+
semanticHtml,
|
|
322
|
+
PDF_MAX_EMBEDDED_IMAGE_BYTES,
|
|
323
|
+
'pdf',
|
|
324
|
+
)
|
|
325
|
+
return sanitized.replace(
|
|
326
|
+
LEADING_TABLE_HEADER_ROW_PATTERN,
|
|
327
|
+
'$1$2<thead>$4</thead><tbody>$3$5</tbody>',
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function buildExportHtml(title: string, contentHtml: string): string {
|
|
332
|
+
return `<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'none'; frame-src 'none'; connect-src 'none'; base-uri 'none'; form-action 'none'"><title>${escapeHtml(title)}</title></head><body>${contentHtml}</body></html>`
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export function applyDocxPageBreakMarkers(contentHtml: string, marker: string): string {
|
|
336
|
+
const markerParagraph = `<p>${marker}</p>`
|
|
337
|
+
const breakCount = contentHtml.split(markerParagraph).length - 1
|
|
338
|
+
if (breakCount > 100) {
|
|
339
|
+
throw new CrudHttpError(413, { error: 'documents.export.inputTooLarge' })
|
|
340
|
+
}
|
|
341
|
+
return contentHtml.replaceAll(
|
|
342
|
+
markerParagraph,
|
|
343
|
+
'<div class="page-break" style="page-break-after: always"></div>',
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function resolveChromiumExecutablePath(): string | null {
|
|
348
|
+
const configured =
|
|
349
|
+
process.env.DOCUMENTS_PDF_CHROMIUM_PATH?.trim() ||
|
|
350
|
+
process.env.PUPPETEER_EXECUTABLE_PATH?.trim()
|
|
351
|
+
if (configured) return configured
|
|
352
|
+
return COMMON_CHROMIUM_PATHS.find((path) => existsSync(path)) ?? null
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function toArrayBuffer(bytes: Uint8Array): ArrayBuffer {
|
|
356
|
+
const arrayBuffer = new ArrayBuffer(bytes.byteLength)
|
|
357
|
+
new Uint8Array(arrayBuffer).set(bytes)
|
|
358
|
+
return arrayBuffer
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* PDF rendering is an inert conversion boundary, not a browser session. Never
|
|
363
|
+
* allow a top-level/frame navigation or network fetch from authored content.
|
|
364
|
+
* The only request class retained is a raster image embedded entirely in the
|
|
365
|
+
* HTML itself; current editor configuration normally strips those too.
|
|
366
|
+
*/
|
|
367
|
+
export function isAllowedPdfAssetRequest(request: PdfRequestDescriptor): boolean {
|
|
368
|
+
if (request.isNavigationRequest || request.resourceType !== 'image') return false
|
|
369
|
+
const embeddedBytes = readSafeEmbeddedImageBytes(request.url, PDF_MAX_EMBEDDED_IMAGE_BYTES)
|
|
370
|
+
return embeddedBytes !== null && embeddedBytes <= PDF_MAX_EMBEDDED_IMAGE_BYTES
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
async function handleExport(
|
|
374
|
+
request: Request,
|
|
375
|
+
context: RouteContext,
|
|
376
|
+
options?: {
|
|
377
|
+
loadSnapshot?: () => Promise<z.infer<typeof docxSnapshotSchema>>
|
|
378
|
+
operation?: string
|
|
379
|
+
},
|
|
380
|
+
): Promise<Response> {
|
|
381
|
+
try {
|
|
382
|
+
const format = resolveExportFormat(new URL(request.url).searchParams.get('format'))
|
|
383
|
+
if (!format) {
|
|
384
|
+
throw new CrudHttpError(400, { error: 'documents.export.unsupportedFormat' })
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const id = await resolveId(context)
|
|
388
|
+
const ctx = await resolveDocumentsContext(request, ['documents.view'])
|
|
389
|
+
await assertTier(ctx.em, id, ctx.auth, 'viewer')
|
|
390
|
+
const doc = await loadScopedDocument(ctx, id)
|
|
391
|
+
// The snapshot body is buffered and validated only after the caller has
|
|
392
|
+
// proven document access, so an unauthenticated request cannot make the
|
|
393
|
+
// server process multi-megabyte payloads.
|
|
394
|
+
const snapshot = options?.loadSnapshot ? await options.loadSnapshot() : undefined
|
|
395
|
+
const content = await loadDocumentContent(ctx.em, id, {
|
|
396
|
+
tenantId: ctx.tenantId,
|
|
397
|
+
organizationId: ctx.organizationId,
|
|
398
|
+
})
|
|
399
|
+
const contentHtml = format === 'docx' && snapshot ? snapshot.contentHtml : content?.contentHtml ?? ''
|
|
400
|
+
assertDocumentContentResourceLimits(
|
|
401
|
+
{ contentHtml, contentText: content?.contentText },
|
|
402
|
+
{ error: 'documents.export.inputTooLarge' },
|
|
403
|
+
)
|
|
404
|
+
const safeName = buildSafeFilename(doc.title)
|
|
405
|
+
|
|
406
|
+
if (format === 'docx') {
|
|
407
|
+
const sanitized = sanitizeDocxExportContent(contentHtml)
|
|
408
|
+
const paginated = snapshot
|
|
409
|
+
? applyDocxPageBreakMarkers(sanitized, snapshot.pageBreakMarker)
|
|
410
|
+
: sanitized
|
|
411
|
+
const docxHtml = buildExportHtml(doc.title, paginated)
|
|
412
|
+
let bufferBytes: Uint8Array
|
|
413
|
+
try {
|
|
414
|
+
bufferBytes = await renderDocxWithCapacity(docxHtml)
|
|
415
|
+
} catch (error) {
|
|
416
|
+
if (isDocxRenderOverloadedError(error)) {
|
|
417
|
+
throw new CrudHttpError(503, { error: 'documents.export.overloaded' })
|
|
418
|
+
}
|
|
419
|
+
if (isDocxRenderTimeoutError(error)) {
|
|
420
|
+
throw new CrudHttpError(503, { error: 'documents.export.renderTimeout' })
|
|
421
|
+
}
|
|
422
|
+
if (isDocxRenderOutputTooLargeError(error)) {
|
|
423
|
+
throw new CrudHttpError(413, { error: 'documents.export.outputTooLarge' })
|
|
424
|
+
}
|
|
425
|
+
if (isDocxRenderFailedError(error)) {
|
|
426
|
+
throw new CrudHttpError(503, { error: 'documents.export.runtimeUnavailable' })
|
|
427
|
+
}
|
|
428
|
+
throw error
|
|
429
|
+
}
|
|
430
|
+
return new Response(toArrayBuffer(bufferBytes), {
|
|
431
|
+
headers: {
|
|
432
|
+
'content-type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
433
|
+
'content-disposition': `attachment; filename="${safeName}.docx"`,
|
|
434
|
+
'cache-control': 'private, no-store',
|
|
435
|
+
},
|
|
436
|
+
})
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const executablePath = resolveChromiumExecutablePath()
|
|
440
|
+
if (!executablePath) {
|
|
441
|
+
throw new CrudHttpError(503, { error: 'documents.export.runtimeUnavailable' })
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const pdfHtml = buildDocumentPdfHtml(doc.title, sanitizePdfExportContent(contentHtml))
|
|
445
|
+
let pdf: Uint8Array
|
|
446
|
+
try {
|
|
447
|
+
pdf = await renderPdfWithChromium({
|
|
448
|
+
html: pdfHtml,
|
|
449
|
+
executablePath,
|
|
450
|
+
isAllowedRequest: (interceptedRequest) => isAllowedPdfAssetRequest({
|
|
451
|
+
url: interceptedRequest.url(),
|
|
452
|
+
resourceType: interceptedRequest.resourceType(),
|
|
453
|
+
isNavigationRequest: interceptedRequest.isNavigationRequest(),
|
|
454
|
+
}),
|
|
455
|
+
})
|
|
456
|
+
} catch (error) {
|
|
457
|
+
if (isPdfRenderOverloadedError(error)) {
|
|
458
|
+
throw new CrudHttpError(503, { error: 'documents.export.overloaded' })
|
|
459
|
+
}
|
|
460
|
+
if (isPdfRenderTimeoutError(error)) {
|
|
461
|
+
throw new CrudHttpError(503, { error: 'documents.export.renderTimeout' })
|
|
462
|
+
}
|
|
463
|
+
if (isPdfRenderOutputTooLargeError(error)) {
|
|
464
|
+
throw new CrudHttpError(413, { error: 'documents.export.outputTooLarge' })
|
|
465
|
+
}
|
|
466
|
+
throw new CrudHttpError(503, { error: 'documents.export.runtimeUnavailable' })
|
|
467
|
+
}
|
|
468
|
+
return new Response(toArrayBuffer(pdf), {
|
|
469
|
+
headers: {
|
|
470
|
+
'content-type': 'application/pdf',
|
|
471
|
+
'content-disposition': `attachment; filename="${safeName}.pdf"`,
|
|
472
|
+
'cache-control': 'private, no-store',
|
|
473
|
+
},
|
|
474
|
+
})
|
|
475
|
+
} catch (error) {
|
|
476
|
+
return handleDocumentsRouteError(error, options?.operation ?? 'documents.export.get')
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export async function GET(request: Request, context: RouteContext): Promise<Response> {
|
|
481
|
+
return handleExport(request, context)
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export async function POST(request: Request, context: RouteContext): Promise<Response> {
|
|
485
|
+
return handleExport(request, context, {
|
|
486
|
+
loadSnapshot: async () => docxSnapshotSchema.parse(await readBody(
|
|
487
|
+
request,
|
|
488
|
+
DOCUMENTS_JSON_BODY_LIMITS.exportSnapshot,
|
|
489
|
+
)),
|
|
490
|
+
operation: 'documents.export.post',
|
|
491
|
+
})
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export const openApi: OpenApiRouteDoc = withDocumentsContextErrors({
|
|
495
|
+
tag: 'Documents',
|
|
496
|
+
summary: 'Document export',
|
|
497
|
+
pathParams: z.object({ id: z.string().uuid() }),
|
|
498
|
+
methods: {
|
|
499
|
+
GET: {
|
|
500
|
+
summary: 'Export document',
|
|
501
|
+
description: 'Returns a binary .docx or PDF file attachment for a document.',
|
|
502
|
+
query: exportQuerySchema,
|
|
503
|
+
responses: [
|
|
504
|
+
{ status: 200, description: 'Document export file', schema: fileResponseSchema, mediaType: 'application/octet-stream' },
|
|
505
|
+
],
|
|
506
|
+
errors: [
|
|
507
|
+
{ status: 400, description: 'Unsupported format', schema: routeErrorSchema },
|
|
508
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
509
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
510
|
+
{ status: 404, description: 'Not found', schema: routeErrorSchema },
|
|
511
|
+
{ status: 413, description: 'Document or generated export exceeds the safe resource bound', schema: routeErrorSchema },
|
|
512
|
+
{ status: 503, description: 'Export runtime is unavailable, overloaded, or timed out', schema: routeErrorSchema },
|
|
513
|
+
],
|
|
514
|
+
},
|
|
515
|
+
POST: {
|
|
516
|
+
summary: 'Export a paginated DOCX document',
|
|
517
|
+
description: 'Returns a DOCX attachment using the editor pagination snapshot supplied by the client.',
|
|
518
|
+
query: exportQuerySchema,
|
|
519
|
+
requestBody: { contentType: 'application/json', schema: docxSnapshotSchema },
|
|
520
|
+
responses: [
|
|
521
|
+
{ status: 200, description: 'Paginated DOCX export file', schema: fileResponseSchema, mediaType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' },
|
|
522
|
+
],
|
|
523
|
+
errors: [
|
|
524
|
+
{ status: 400, description: 'Invalid pagination snapshot or unsupported format', schema: routeErrorSchema },
|
|
525
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
526
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
527
|
+
{ status: 404, description: 'Not found', schema: routeErrorSchema },
|
|
528
|
+
{ status: 413, description: 'Document or generated export exceeds the safe resource bound', schema: routeErrorSchema },
|
|
529
|
+
{ status: 503, description: 'Export runtime is unavailable, overloaded, or timed out', schema: routeErrorSchema },
|
|
530
|
+
],
|
|
531
|
+
},
|
|
532
|
+
},
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
export default { GET, POST }
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import { NextResponse } from 'next/server'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'
|
|
5
|
+
import type { CommandBus } from '@open-mercato/shared/lib/commands'
|
|
6
|
+
import { DOCUMENTS_ENTITY_IDS } from '../../../lib/constants'
|
|
7
|
+
import type { FavoriteCommandInput, FavoriteCommandResult } from '../../../commands/favorites'
|
|
8
|
+
import {
|
|
9
|
+
buildDocumentsCommandRuntimeContext,
|
|
10
|
+
resolveDocumentsCommandBus,
|
|
11
|
+
} from '../../_commands'
|
|
12
|
+
import {
|
|
13
|
+
handleDocumentsRouteError,
|
|
14
|
+
resolveActorUserId,
|
|
15
|
+
resolveDocumentsContext,
|
|
16
|
+
routeErrorSchema,
|
|
17
|
+
runMutationGuardAfterSuccess,
|
|
18
|
+
validateMutationGuard,
|
|
19
|
+
type DocumentsRouteContext,
|
|
20
|
+
withDocumentsContextErrors,
|
|
21
|
+
} from '../../_shared'
|
|
22
|
+
|
|
23
|
+
type RouteContext = {
|
|
24
|
+
params: Promise<{ id: string }> | { id: string }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const toggleResponseSchema = z.object({
|
|
28
|
+
id: z.string().uuid(),
|
|
29
|
+
active: z.boolean(),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export const metadata = {
|
|
33
|
+
POST: { requireAuth: true, requireFeatures: ['documents.view'] },
|
|
34
|
+
DELETE: { requireAuth: true, requireFeatures: ['documents.view'] },
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function runFavoriteToggle(
|
|
38
|
+
request: Request,
|
|
39
|
+
context: RouteContext,
|
|
40
|
+
commandId: 'documents.favorite.create' | 'documents.favorite.delete',
|
|
41
|
+
operation: 'create' | 'delete',
|
|
42
|
+
errorScope: string,
|
|
43
|
+
): Promise<Response> {
|
|
44
|
+
try {
|
|
45
|
+
const { id: documentId } = await context.params
|
|
46
|
+
const ctx: DocumentsRouteContext = await resolveDocumentsContext(request, ['documents.view'])
|
|
47
|
+
const guardResult = await validateMutationGuard(ctx, {
|
|
48
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentFavorite,
|
|
49
|
+
resourceId: documentId,
|
|
50
|
+
operation,
|
|
51
|
+
mutationPayload: { documentId },
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const input: FavoriteCommandInput = {
|
|
55
|
+
tenantId: ctx.tenantId,
|
|
56
|
+
organizationId: ctx.organizationId,
|
|
57
|
+
documentId,
|
|
58
|
+
favoriteId: randomUUID(),
|
|
59
|
+
actorUserId: resolveActorUserId(ctx.auth),
|
|
60
|
+
}
|
|
61
|
+
const commandBus: CommandBus = resolveDocumentsCommandBus(ctx)
|
|
62
|
+
const { result } = await commandBus.execute<FavoriteCommandInput, FavoriteCommandResult>(
|
|
63
|
+
commandId,
|
|
64
|
+
{ input, ctx: buildDocumentsCommandRuntimeContext(ctx) },
|
|
65
|
+
)
|
|
66
|
+
await runMutationGuardAfterSuccess(ctx, guardResult, {
|
|
67
|
+
resourceKind: DOCUMENTS_ENTITY_IDS.documentFavorite,
|
|
68
|
+
resourceId: documentId,
|
|
69
|
+
operation,
|
|
70
|
+
})
|
|
71
|
+
return NextResponse.json({ id: result.id, active: result.active })
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return handleDocumentsRouteError(error, errorScope)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function POST(request: Request, context: RouteContext): Promise<Response> {
|
|
78
|
+
return runFavoriteToggle(request, context, 'documents.favorite.create', 'create', 'documents.favorite.create')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function DELETE(request: Request, context: RouteContext): Promise<Response> {
|
|
82
|
+
return runFavoriteToggle(request, context, 'documents.favorite.delete', 'delete', 'documents.favorite.delete')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const openApi: OpenApiRouteDoc = withDocumentsContextErrors({
|
|
86
|
+
tag: 'Documents',
|
|
87
|
+
summary: 'Document favorite toggle',
|
|
88
|
+
pathParams: z.object({ id: z.string().uuid() }),
|
|
89
|
+
methods: {
|
|
90
|
+
POST: {
|
|
91
|
+
summary: 'Star a document for the current user',
|
|
92
|
+
responses: [{ status: 200, description: 'Favorite state', schema: toggleResponseSchema }],
|
|
93
|
+
errors: [
|
|
94
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
95
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
96
|
+
{ status: 404, description: 'Document not found', schema: routeErrorSchema },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
DELETE: {
|
|
100
|
+
summary: 'Remove the current user star from a document',
|
|
101
|
+
responses: [{ status: 200, description: 'Favorite state', schema: toggleResponseSchema }],
|
|
102
|
+
errors: [
|
|
103
|
+
{ status: 401, description: 'Unauthorized', schema: routeErrorSchema },
|
|
104
|
+
{ status: 403, description: 'Forbidden', schema: routeErrorSchema },
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
export default { POST, DELETE }
|