@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,367 @@
|
|
|
1
|
+
import puppeteer from 'puppeteer-core'
|
|
2
|
+
|
|
3
|
+
export const PDF_RENDER_MAX_CONCURRENCY = 2
|
|
4
|
+
export const PDF_RENDER_MAX_QUEUE = 4
|
|
5
|
+
export const PDF_RENDER_ACQUIRE_TIMEOUT_MS = 2_000
|
|
6
|
+
export const PDF_RENDER_TIMEOUT_MS = 20_000
|
|
7
|
+
export const PDF_PAGE_CLOSE_TIMEOUT_MS = 1_000
|
|
8
|
+
export const PDF_MAX_OUTPUT_BYTES = 25 * 1024 * 1024
|
|
9
|
+
|
|
10
|
+
const PDF_OVERLOADED_MARKER = Symbol.for('open-mercato.documents.pdfRenderer.overloaded')
|
|
11
|
+
const PDF_TIMEOUT_MARKER = Symbol.for('open-mercato.documents.pdfRenderer.timeout')
|
|
12
|
+
const PDF_OUTPUT_TOO_LARGE_MARKER = Symbol.for('open-mercato.documents.pdfRenderer.outputTooLarge')
|
|
13
|
+
|
|
14
|
+
export class PdfRenderOverloadedError extends Error {
|
|
15
|
+
readonly [PDF_OVERLOADED_MARKER] = true
|
|
16
|
+
constructor() {
|
|
17
|
+
super('PDF renderer is at capacity')
|
|
18
|
+
this.name = 'PdfRenderOverloadedError'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class PdfRenderTimeoutError extends Error {
|
|
23
|
+
readonly [PDF_TIMEOUT_MARKER] = true
|
|
24
|
+
constructor() {
|
|
25
|
+
super('PDF renderer timed out')
|
|
26
|
+
this.name = 'PdfRenderTimeoutError'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class PdfRenderOutputTooLargeError extends Error {
|
|
31
|
+
readonly [PDF_OUTPUT_TOO_LARGE_MARKER] = true
|
|
32
|
+
constructor() {
|
|
33
|
+
super('PDF renderer output exceeded its byte limit')
|
|
34
|
+
this.name = 'PdfRenderOutputTooLargeError'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function hasErrorMarker(error: unknown, marker: symbol): boolean {
|
|
39
|
+
return Boolean(error && typeof error === 'object' && (error as Record<symbol, unknown>)[marker] === true)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const isPdfRenderOverloadedError = (error: unknown): boolean => (
|
|
43
|
+
error instanceof PdfRenderOverloadedError || hasErrorMarker(error, PDF_OVERLOADED_MARKER)
|
|
44
|
+
)
|
|
45
|
+
export const isPdfRenderTimeoutError = (error: unknown): boolean => (
|
|
46
|
+
error instanceof PdfRenderTimeoutError || hasErrorMarker(error, PDF_TIMEOUT_MARKER)
|
|
47
|
+
)
|
|
48
|
+
export const isPdfRenderOutputTooLargeError = (error: unknown): boolean => (
|
|
49
|
+
error instanceof PdfRenderOutputTooLargeError || hasErrorMarker(error, PDF_OUTPUT_TOO_LARGE_MARKER)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
export type PdfAssetRequest = {
|
|
53
|
+
url: () => string
|
|
54
|
+
resourceType: () => string
|
|
55
|
+
isNavigationRequest: () => boolean
|
|
56
|
+
continue: () => Promise<unknown>
|
|
57
|
+
abort: () => Promise<unknown>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type PdfPage = {
|
|
61
|
+
setJavaScriptEnabled: (enabled: boolean) => Promise<unknown>
|
|
62
|
+
setRequestInterception: (enabled: boolean) => Promise<unknown>
|
|
63
|
+
on: (event: 'request', listener: (request: PdfAssetRequest) => void) => unknown
|
|
64
|
+
setContent: (html: string, options: { waitUntil: 'load' }) => Promise<unknown>
|
|
65
|
+
createPDFStream: (options: { format: 'A4'; printBackground: true; preferCSSPageSize: true }) => Promise<ReadableStream<Uint8Array>>
|
|
66
|
+
close: () => Promise<unknown>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type PdfBrowser = {
|
|
70
|
+
connected?: boolean
|
|
71
|
+
newPage: () => Promise<PdfPage>
|
|
72
|
+
close: () => Promise<unknown>
|
|
73
|
+
on: (event: 'disconnected', listener: () => void) => unknown
|
|
74
|
+
process?: () => { kill: (signal?: NodeJS.Signals) => unknown } | null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type PdfBrowserLauncher = (options: {
|
|
78
|
+
executablePath: string
|
|
79
|
+
headless: true
|
|
80
|
+
args: string[]
|
|
81
|
+
timeout: number
|
|
82
|
+
protocolTimeout: number
|
|
83
|
+
}) => Promise<PdfBrowser>
|
|
84
|
+
|
|
85
|
+
type PdfRendererOptions = {
|
|
86
|
+
maxConcurrency?: number
|
|
87
|
+
maxQueue?: number
|
|
88
|
+
acquireTimeoutMs?: number
|
|
89
|
+
renderTimeoutMs?: number
|
|
90
|
+
pageCloseTimeoutMs?: number
|
|
91
|
+
maxOutputBytes?: number
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
class BoundedSemaphore {
|
|
95
|
+
private active = 0
|
|
96
|
+
private readonly waiters: Array<{
|
|
97
|
+
resolve: (release: () => void) => void
|
|
98
|
+
reject: (error: Error) => void
|
|
99
|
+
timer: ReturnType<typeof setTimeout>
|
|
100
|
+
}> = []
|
|
101
|
+
|
|
102
|
+
constructor(
|
|
103
|
+
private readonly capacity: number,
|
|
104
|
+
private readonly maxQueue: number,
|
|
105
|
+
private readonly acquireTimeoutMs: number,
|
|
106
|
+
) {}
|
|
107
|
+
|
|
108
|
+
async acquire(): Promise<() => void> {
|
|
109
|
+
if (this.active < this.capacity) return this.grant()
|
|
110
|
+
if (this.waiters.length >= this.maxQueue) throw new PdfRenderOverloadedError()
|
|
111
|
+
|
|
112
|
+
return await new Promise<() => void>((resolve, reject) => {
|
|
113
|
+
const waiter = {
|
|
114
|
+
resolve,
|
|
115
|
+
reject,
|
|
116
|
+
timer: setTimeout(() => {
|
|
117
|
+
const index = this.waiters.indexOf(waiter)
|
|
118
|
+
if (index >= 0) this.waiters.splice(index, 1)
|
|
119
|
+
reject(new PdfRenderOverloadedError())
|
|
120
|
+
}, this.acquireTimeoutMs),
|
|
121
|
+
}
|
|
122
|
+
this.waiters.push(waiter)
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private grant(): () => void {
|
|
127
|
+
this.active += 1
|
|
128
|
+
let released = false
|
|
129
|
+
return () => {
|
|
130
|
+
if (released) return
|
|
131
|
+
released = true
|
|
132
|
+
this.active -= 1
|
|
133
|
+
const waiter = this.waiters.shift()
|
|
134
|
+
if (!waiter) return
|
|
135
|
+
clearTimeout(waiter.timer)
|
|
136
|
+
waiter.resolve(this.grant())
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function withTimeout<T>(
|
|
142
|
+
promise: Promise<T>,
|
|
143
|
+
timeoutMs: number,
|
|
144
|
+
onTimeout: () => void,
|
|
145
|
+
): Promise<T> {
|
|
146
|
+
return new Promise<T>((resolve, reject) => {
|
|
147
|
+
let settled = false
|
|
148
|
+
const timer = setTimeout(() => {
|
|
149
|
+
if (settled) return
|
|
150
|
+
settled = true
|
|
151
|
+
onTimeout()
|
|
152
|
+
reject(new PdfRenderTimeoutError())
|
|
153
|
+
}, timeoutMs)
|
|
154
|
+
promise.then(
|
|
155
|
+
(value) => {
|
|
156
|
+
if (settled) return
|
|
157
|
+
settled = true
|
|
158
|
+
clearTimeout(timer)
|
|
159
|
+
resolve(value)
|
|
160
|
+
},
|
|
161
|
+
(error: unknown) => {
|
|
162
|
+
if (settled) return
|
|
163
|
+
settled = true
|
|
164
|
+
clearTimeout(timer)
|
|
165
|
+
reject(error)
|
|
166
|
+
},
|
|
167
|
+
)
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function readBoundedPdfStream(
|
|
172
|
+
stream: ReadableStream<Uint8Array>,
|
|
173
|
+
maxOutputBytes: number,
|
|
174
|
+
): Promise<Uint8Array> {
|
|
175
|
+
const reader = stream.getReader()
|
|
176
|
+
const chunks: Uint8Array[] = []
|
|
177
|
+
let totalBytes = 0
|
|
178
|
+
try {
|
|
179
|
+
while (true) {
|
|
180
|
+
const { done, value } = await reader.read()
|
|
181
|
+
if (done) break
|
|
182
|
+
if (!value || value.byteLength === 0) continue
|
|
183
|
+
if (totalBytes + value.byteLength > maxOutputBytes) {
|
|
184
|
+
await reader.cancel('PDF output exceeded its byte limit').catch(() => undefined)
|
|
185
|
+
throw new PdfRenderOutputTooLargeError()
|
|
186
|
+
}
|
|
187
|
+
totalBytes += value.byteLength
|
|
188
|
+
chunks.push(value)
|
|
189
|
+
}
|
|
190
|
+
} finally {
|
|
191
|
+
reader.releaseLock()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const output = new Uint8Array(totalBytes)
|
|
195
|
+
let offset = 0
|
|
196
|
+
for (const chunk of chunks) {
|
|
197
|
+
output.set(chunk, offset)
|
|
198
|
+
offset += chunk.byteLength
|
|
199
|
+
}
|
|
200
|
+
return output
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A process-local, bounded Chromium supervisor. The browser is reused between
|
|
205
|
+
* requests, discarded after a crash/timeout, and never launched with sandbox-
|
|
206
|
+
* disabling flags. Capacity is deliberately small so PDF work cannot starve
|
|
207
|
+
* the application server.
|
|
208
|
+
*/
|
|
209
|
+
export function createPdfRenderer(
|
|
210
|
+
launch: PdfBrowserLauncher,
|
|
211
|
+
options: PdfRendererOptions = {},
|
|
212
|
+
) {
|
|
213
|
+
const renderTimeoutMs = options.renderTimeoutMs ?? PDF_RENDER_TIMEOUT_MS
|
|
214
|
+
const pageCloseTimeoutMs = options.pageCloseTimeoutMs ?? PDF_PAGE_CLOSE_TIMEOUT_MS
|
|
215
|
+
const maxOutputBytes = options.maxOutputBytes ?? PDF_MAX_OUTPUT_BYTES
|
|
216
|
+
const semaphore = new BoundedSemaphore(
|
|
217
|
+
options.maxConcurrency ?? PDF_RENDER_MAX_CONCURRENCY,
|
|
218
|
+
options.maxQueue ?? PDF_RENDER_MAX_QUEUE,
|
|
219
|
+
options.acquireTimeoutMs ?? PDF_RENDER_ACQUIRE_TIMEOUT_MS,
|
|
220
|
+
)
|
|
221
|
+
let browserState: {
|
|
222
|
+
executablePath: string
|
|
223
|
+
promise: Promise<PdfBrowser>
|
|
224
|
+
browser?: PdfBrowser
|
|
225
|
+
} | null = null
|
|
226
|
+
|
|
227
|
+
const terminateBrowser = async (browser: PdfBrowser): Promise<void> => {
|
|
228
|
+
let closed = false
|
|
229
|
+
const closePromise = browser.close().then(
|
|
230
|
+
() => { closed = true },
|
|
231
|
+
() => undefined,
|
|
232
|
+
)
|
|
233
|
+
let closeTimer: ReturnType<typeof setTimeout> | undefined
|
|
234
|
+
const closeTimeout = new Promise<void>((resolve) => {
|
|
235
|
+
closeTimer = setTimeout(resolve, 1_000)
|
|
236
|
+
})
|
|
237
|
+
await Promise.race([
|
|
238
|
+
closePromise,
|
|
239
|
+
closeTimeout,
|
|
240
|
+
])
|
|
241
|
+
if (closeTimer) clearTimeout(closeTimer)
|
|
242
|
+
if (!closed) browser.process?.()?.kill('SIGKILL')
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const invalidateBrowser = (browser?: PdfBrowser): void => {
|
|
246
|
+
const state = browserState
|
|
247
|
+
if (!state) return
|
|
248
|
+
if (browser && state.browser && state.browser !== browser) return
|
|
249
|
+
if (browser && !state.browser) {
|
|
250
|
+
void state.promise.then((resolved) => {
|
|
251
|
+
if (resolved !== browser) return
|
|
252
|
+
if (browserState?.promise === state.promise) browserState = null
|
|
253
|
+
return terminateBrowser(resolved)
|
|
254
|
+
}).catch(() => undefined)
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
browserState = null
|
|
258
|
+
void state.promise.then((resolved) => {
|
|
259
|
+
if (!browser || browser === resolved) return terminateBrowser(resolved)
|
|
260
|
+
}).catch(() => undefined)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const getBrowser = async (executablePath: string): Promise<PdfBrowser> => {
|
|
264
|
+
if (browserState && browserState.executablePath !== executablePath) {
|
|
265
|
+
invalidateBrowser()
|
|
266
|
+
}
|
|
267
|
+
if (!browserState) {
|
|
268
|
+
const promise = launch({
|
|
269
|
+
executablePath,
|
|
270
|
+
headless: true,
|
|
271
|
+
args: [],
|
|
272
|
+
timeout: Math.min(renderTimeoutMs, 10_000),
|
|
273
|
+
protocolTimeout: renderTimeoutMs,
|
|
274
|
+
})
|
|
275
|
+
browserState = { executablePath, promise }
|
|
276
|
+
promise.then((browser) => {
|
|
277
|
+
if (browserState?.promise === promise) browserState.browser = browser
|
|
278
|
+
browser.on('disconnected', () => {
|
|
279
|
+
if (browserState?.promise === promise) browserState = null
|
|
280
|
+
})
|
|
281
|
+
}).catch(() => {
|
|
282
|
+
if (browserState?.promise === promise) browserState = null
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
const browser = await browserState.promise
|
|
286
|
+
if (browser.connected === false) {
|
|
287
|
+
invalidateBrowser(browser)
|
|
288
|
+
return getBrowser(executablePath)
|
|
289
|
+
}
|
|
290
|
+
return browser
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const render = async (input: {
|
|
294
|
+
html: string
|
|
295
|
+
executablePath: string
|
|
296
|
+
isAllowedRequest: (request: PdfAssetRequest) => boolean
|
|
297
|
+
}): Promise<Uint8Array> => {
|
|
298
|
+
const release = await semaphore.acquire()
|
|
299
|
+
let browser: PdfBrowser | undefined
|
|
300
|
+
let page: PdfPage | undefined
|
|
301
|
+
try {
|
|
302
|
+
const renderOperation = (async () => {
|
|
303
|
+
browser = await getBrowser(input.executablePath)
|
|
304
|
+
page = await browser.newPage()
|
|
305
|
+
await page.setJavaScriptEnabled(false)
|
|
306
|
+
await page.setRequestInterception(true)
|
|
307
|
+
page.on('request', (request) => {
|
|
308
|
+
// A page can disappear between interception and resolution (timeout,
|
|
309
|
+
// overflow, browser crash). Never turn that normal teardown race into
|
|
310
|
+
// an unhandled rejection in the app process.
|
|
311
|
+
void Promise.resolve()
|
|
312
|
+
.then(() => (input.isAllowedRequest(request) ? request.continue() : request.abort()))
|
|
313
|
+
.catch(() => undefined)
|
|
314
|
+
})
|
|
315
|
+
await page.setContent(input.html, { waitUntil: 'load' })
|
|
316
|
+
const pdfStream = await page.createPDFStream({
|
|
317
|
+
format: 'A4',
|
|
318
|
+
printBackground: true,
|
|
319
|
+
preferCSSPageSize: true,
|
|
320
|
+
})
|
|
321
|
+
return readBoundedPdfStream(pdfStream, maxOutputBytes)
|
|
322
|
+
})()
|
|
323
|
+
try {
|
|
324
|
+
return await withTimeout(renderOperation, renderTimeoutMs, () => invalidateBrowser(browser))
|
|
325
|
+
} catch (error) {
|
|
326
|
+
if (isPdfRenderOutputTooLargeError(error)) invalidateBrowser(browser)
|
|
327
|
+
throw error
|
|
328
|
+
}
|
|
329
|
+
} finally {
|
|
330
|
+
if (page) {
|
|
331
|
+
let closeSettled = false
|
|
332
|
+
let closeTimer: ReturnType<typeof setTimeout> | undefined
|
|
333
|
+
const closePromise = page.close().then(
|
|
334
|
+
() => { closeSettled = true },
|
|
335
|
+
() => { closeSettled = true },
|
|
336
|
+
)
|
|
337
|
+
const closeTimeout = new Promise<void>((resolve) => {
|
|
338
|
+
closeTimer = setTimeout(resolve, pageCloseTimeoutMs)
|
|
339
|
+
})
|
|
340
|
+
await Promise.race([closePromise, closeTimeout])
|
|
341
|
+
if (closeTimer) clearTimeout(closeTimer)
|
|
342
|
+
if (!closeSettled) invalidateBrowser(browser)
|
|
343
|
+
}
|
|
344
|
+
release()
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
render,
|
|
350
|
+
dispose: async () => {
|
|
351
|
+
const state = browserState
|
|
352
|
+
browserState = null
|
|
353
|
+
if (state) await state.promise.then(terminateBrowser).catch(() => undefined)
|
|
354
|
+
},
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const PDF_RENDERER_KEY = Symbol.for('open-mercato.documents.pdfRenderer')
|
|
359
|
+
const globalStore = globalThis as typeof globalThis & {
|
|
360
|
+
[PDF_RENDERER_KEY]?: ReturnType<typeof createPdfRenderer>
|
|
361
|
+
}
|
|
362
|
+
const processPdfRenderer = globalStore[PDF_RENDERER_KEY]
|
|
363
|
+
?? (globalStore[PDF_RENDERER_KEY] = createPdfRenderer(
|
|
364
|
+
(options) => puppeteer.launch(options) as unknown as Promise<PdfBrowser>,
|
|
365
|
+
))
|
|
366
|
+
|
|
367
|
+
export const renderPdfWithChromium = processPdfRenderer.render
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
+
import type { FilterQuery } from '@mikro-orm/core'
|
|
3
|
+
import type { AuthContext } from '@open-mercato/shared/lib/auth/server'
|
|
4
|
+
import { hasAllFeatures } from '@open-mercato/shared/lib/auth/featureMatch'
|
|
5
|
+
import { forbidden } from '@open-mercato/shared/lib/crud/errors'
|
|
6
|
+
import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
7
|
+
import { Document, DocumentShare } from '../data/entities'
|
|
8
|
+
import {
|
|
9
|
+
resolveApiKeyPrincipalService,
|
|
10
|
+
resolveAuthPrincipalService,
|
|
11
|
+
resolveDocumentsRbacService,
|
|
12
|
+
type DocumentsServiceContainer,
|
|
13
|
+
} from './platformServices'
|
|
14
|
+
|
|
15
|
+
export type DocumentTier = 'owner' | 'editor' | 'commenter' | 'viewer'
|
|
16
|
+
|
|
17
|
+
export const TIER_RANK: Record<DocumentTier, number> = {
|
|
18
|
+
owner: 3,
|
|
19
|
+
editor: 2,
|
|
20
|
+
commenter: 1,
|
|
21
|
+
viewer: 0,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type DocumentsPermissionContext = NonNullable<AuthContext> & {
|
|
25
|
+
features?: string[]
|
|
26
|
+
roleIds?: string[]
|
|
27
|
+
resolvedRoleIds?: string[]
|
|
28
|
+
organizationId?: string | null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function resolveUserId(ctx: AuthContext): string | null {
|
|
32
|
+
if (!ctx) return null
|
|
33
|
+
if (typeof ctx.userId === 'string' && ctx.userId.trim().length > 0) return ctx.userId
|
|
34
|
+
if (typeof ctx.sub === 'string' && ctx.sub.trim().length > 0 && !ctx.sub.startsWith('api_key:')) return ctx.sub
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function resolveOrganizationId(ctx: DocumentsPermissionContext): string | null {
|
|
39
|
+
if (typeof ctx.organizationId === 'string' && ctx.organizationId.trim().length > 0) {
|
|
40
|
+
return ctx.organizationId
|
|
41
|
+
}
|
|
42
|
+
if (typeof ctx.orgId === 'string' && ctx.orgId.trim().length > 0) return ctx.orgId
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeStrings(values: unknown): string[] {
|
|
47
|
+
if (!Array.isArray(values)) return []
|
|
48
|
+
return Array.from(
|
|
49
|
+
new Set(
|
|
50
|
+
values
|
|
51
|
+
.map((value) => (typeof value === 'string' ? value.trim() : ''))
|
|
52
|
+
.filter((value) => value.length > 0),
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function hasDocumentsManage(ctx: DocumentsPermissionContext): boolean {
|
|
58
|
+
if (ctx.isSuperAdmin === true) return true
|
|
59
|
+
const features = normalizeStrings(ctx.features)
|
|
60
|
+
return hasAllFeatures(['documents.manage'], features)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function resolveActiveUserRoleIds(
|
|
64
|
+
container: DocumentsServiceContainer | null | undefined,
|
|
65
|
+
scope: { tenantId: string; organizationId: string },
|
|
66
|
+
userId: string,
|
|
67
|
+
): Promise<string[]> {
|
|
68
|
+
const service = resolveAuthPrincipalService(container)
|
|
69
|
+
if (!service) return []
|
|
70
|
+
return normalizeStrings(await service.resolveActiveUserRoleIds(userId, scope))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function resolveActiveSubjectRoleIds(
|
|
74
|
+
container: DocumentsServiceContainer | null | undefined,
|
|
75
|
+
scope: { tenantId: string; organizationId: string },
|
|
76
|
+
subject: string,
|
|
77
|
+
): Promise<string[]> {
|
|
78
|
+
if (!subject.startsWith('api_key:')) {
|
|
79
|
+
return resolveActiveUserRoleIds(container, scope, subject)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const apiKeyId = subject.slice('api_key:'.length).trim()
|
|
83
|
+
if (!apiKeyId) return []
|
|
84
|
+
const apiKeyService = resolveApiKeyPrincipalService(container)
|
|
85
|
+
const authService = resolveAuthPrincipalService(container)
|
|
86
|
+
if (!apiKeyService || !authService) return []
|
|
87
|
+
const assigned = normalizeStrings(await apiKeyService.resolveAssignedRoleIds(apiKeyId, scope))
|
|
88
|
+
if (assigned.length === 0) return []
|
|
89
|
+
return normalizeStrings(await authService.filterActiveRoleIds(assigned, scope))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function maxShareTier(shares: DocumentShare[]): DocumentTier | null {
|
|
93
|
+
let best: DocumentTier | null = null
|
|
94
|
+
for (const share of shares) {
|
|
95
|
+
const permission = share.permission
|
|
96
|
+
if (permission !== 'viewer' && permission !== 'commenter' && permission !== 'editor') continue
|
|
97
|
+
if (!best || TIER_RANK[permission] > TIER_RANK[best]) best = permission
|
|
98
|
+
}
|
|
99
|
+
return best
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function resolvePermission(
|
|
103
|
+
em: EntityManager,
|
|
104
|
+
documentId: string,
|
|
105
|
+
ctx: AuthContext,
|
|
106
|
+
): Promise<DocumentTier | null> {
|
|
107
|
+
if (!ctx || !ctx.tenantId) return null
|
|
108
|
+
const permissionCtx = ctx as DocumentsPermissionContext
|
|
109
|
+
const organizationId = resolveOrganizationId(permissionCtx)
|
|
110
|
+
if (!organizationId) return null
|
|
111
|
+
|
|
112
|
+
const document = await findOneWithDecryption(
|
|
113
|
+
em,
|
|
114
|
+
Document,
|
|
115
|
+
{
|
|
116
|
+
id: documentId,
|
|
117
|
+
tenantId: ctx.tenantId,
|
|
118
|
+
organizationId,
|
|
119
|
+
deletedAt: null,
|
|
120
|
+
},
|
|
121
|
+
undefined,
|
|
122
|
+
{ tenantId: ctx.tenantId, organizationId },
|
|
123
|
+
)
|
|
124
|
+
if (!document) return null
|
|
125
|
+
|
|
126
|
+
const userId = resolveUserId(ctx)
|
|
127
|
+
if ((userId && document.ownerUserId === userId) || hasDocumentsManage(permissionCtx)) {
|
|
128
|
+
return 'owner'
|
|
129
|
+
}
|
|
130
|
+
if (!userId) return null
|
|
131
|
+
|
|
132
|
+
// Never trust role ids/names carried by the request token. Role shares are
|
|
133
|
+
// resolved from active UserRole links to active roles in the current tenant.
|
|
134
|
+
// Only consume the server-projected role set. Raw token roleIds/roles are
|
|
135
|
+
// authentication hints and can outlive an assignment revocation.
|
|
136
|
+
const roleIds = normalizeStrings(permissionCtx.resolvedRoleIds)
|
|
137
|
+
const principals: Array<FilterQuery<DocumentShare>> = [
|
|
138
|
+
{ principalType: 'user', principalId: userId },
|
|
139
|
+
]
|
|
140
|
+
if (roleIds.length > 0) {
|
|
141
|
+
principals.push({ principalType: 'role', principalId: { $in: roleIds } } as FilterQuery<DocumentShare>)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const shares = await findWithDecryption(
|
|
145
|
+
em,
|
|
146
|
+
DocumentShare,
|
|
147
|
+
{
|
|
148
|
+
documentId,
|
|
149
|
+
tenantId: ctx.tenantId,
|
|
150
|
+
organizationId,
|
|
151
|
+
deletedAt: null,
|
|
152
|
+
$or: principals,
|
|
153
|
+
} as FilterQuery<DocumentShare>,
|
|
154
|
+
undefined,
|
|
155
|
+
{ tenantId: ctx.tenantId, organizationId },
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return maxShareTier(shares)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function loadScopedDocument(
|
|
162
|
+
em: EntityManager,
|
|
163
|
+
documentId: string,
|
|
164
|
+
scope: { tenantId: string; organizationId: string },
|
|
165
|
+
): Promise<Document | null> {
|
|
166
|
+
return findOneWithDecryption(
|
|
167
|
+
em,
|
|
168
|
+
Document,
|
|
169
|
+
{
|
|
170
|
+
id: documentId,
|
|
171
|
+
tenantId: scope.tenantId,
|
|
172
|
+
organizationId: scope.organizationId,
|
|
173
|
+
deletedAt: null,
|
|
174
|
+
},
|
|
175
|
+
undefined,
|
|
176
|
+
scope,
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Resolve one user's tier against an already scoped document. Callers that
|
|
182
|
+
* evaluate many users for the same document load it once and reuse it here
|
|
183
|
+
* instead of re-reading the identical row per user.
|
|
184
|
+
*/
|
|
185
|
+
export async function resolveLoadedDocumentUserAccess(
|
|
186
|
+
em: EntityManager,
|
|
187
|
+
document: Document,
|
|
188
|
+
scope: { tenantId: string; organizationId: string },
|
|
189
|
+
userId: string,
|
|
190
|
+
container?: DocumentsServiceContainer | null,
|
|
191
|
+
): Promise<DocumentTier | null> {
|
|
192
|
+
if (document.ownerUserId === userId) return 'owner'
|
|
193
|
+
if (await resolveDocumentsRbacService(container)?.userHasAllFeatures(
|
|
194
|
+
userId,
|
|
195
|
+
['documents.manage'],
|
|
196
|
+
scope,
|
|
197
|
+
)) return 'owner'
|
|
198
|
+
|
|
199
|
+
const roleIds = await resolveActiveUserRoleIds(container, scope, userId)
|
|
200
|
+
|
|
201
|
+
const principals: Array<FilterQuery<DocumentShare>> = [
|
|
202
|
+
{ principalType: 'user', principalId: userId },
|
|
203
|
+
]
|
|
204
|
+
if (roleIds.length > 0) {
|
|
205
|
+
principals.push({ principalType: 'role', principalId: { $in: roleIds } } as FilterQuery<DocumentShare>)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const shares = await findWithDecryption(
|
|
209
|
+
em,
|
|
210
|
+
DocumentShare,
|
|
211
|
+
{
|
|
212
|
+
documentId: document.id,
|
|
213
|
+
tenantId: scope.tenantId,
|
|
214
|
+
organizationId: scope.organizationId,
|
|
215
|
+
deletedAt: null,
|
|
216
|
+
$or: principals,
|
|
217
|
+
} as FilterQuery<DocumentShare>,
|
|
218
|
+
undefined,
|
|
219
|
+
scope,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
return maxShareTier(shares)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export async function resolveUserAccess(
|
|
226
|
+
em: EntityManager,
|
|
227
|
+
documentId: string,
|
|
228
|
+
scope: { tenantId: string; organizationId: string },
|
|
229
|
+
userId: string,
|
|
230
|
+
container?: DocumentsServiceContainer | null,
|
|
231
|
+
): Promise<DocumentTier | null> {
|
|
232
|
+
const document = await loadScopedDocument(em, documentId, scope)
|
|
233
|
+
if (!document) return null
|
|
234
|
+
return resolveLoadedDocumentUserAccess(em, document, scope, userId, container)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export async function resolveSubjectAccess(
|
|
238
|
+
em: EntityManager,
|
|
239
|
+
documentId: string,
|
|
240
|
+
scope: { tenantId: string; organizationId: string },
|
|
241
|
+
identity: { subject: string; userId: string },
|
|
242
|
+
container?: DocumentsServiceContainer | null,
|
|
243
|
+
): Promise<DocumentTier | null> {
|
|
244
|
+
const document = await findOneWithDecryption(
|
|
245
|
+
em,
|
|
246
|
+
Document,
|
|
247
|
+
{
|
|
248
|
+
id: documentId,
|
|
249
|
+
tenantId: scope.tenantId,
|
|
250
|
+
organizationId: scope.organizationId,
|
|
251
|
+
deletedAt: null,
|
|
252
|
+
},
|
|
253
|
+
undefined,
|
|
254
|
+
scope,
|
|
255
|
+
)
|
|
256
|
+
if (!document) return null
|
|
257
|
+
if (document.ownerUserId === identity.userId) return 'owner'
|
|
258
|
+
|
|
259
|
+
const roleIds = await resolveActiveSubjectRoleIds(container, scope, identity.subject)
|
|
260
|
+
const principals: Array<FilterQuery<DocumentShare>> = [
|
|
261
|
+
{ principalType: 'user', principalId: identity.userId },
|
|
262
|
+
]
|
|
263
|
+
if (roleIds.length > 0) {
|
|
264
|
+
principals.push({ principalType: 'role', principalId: { $in: roleIds } } as FilterQuery<DocumentShare>)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const shares = await findWithDecryption(
|
|
268
|
+
em,
|
|
269
|
+
DocumentShare,
|
|
270
|
+
{
|
|
271
|
+
documentId,
|
|
272
|
+
tenantId: scope.tenantId,
|
|
273
|
+
organizationId: scope.organizationId,
|
|
274
|
+
deletedAt: null,
|
|
275
|
+
$or: principals,
|
|
276
|
+
} as FilterQuery<DocumentShare>,
|
|
277
|
+
undefined,
|
|
278
|
+
scope,
|
|
279
|
+
)
|
|
280
|
+
return maxShareTier(shares)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function hasTier(tier: DocumentTier | null, required: DocumentTier): boolean {
|
|
284
|
+
if (!tier) return false
|
|
285
|
+
return TIER_RANK[tier] >= TIER_RANK[required]
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export async function assertTier(
|
|
289
|
+
em: EntityManager,
|
|
290
|
+
documentId: string,
|
|
291
|
+
ctx: AuthContext,
|
|
292
|
+
required: DocumentTier,
|
|
293
|
+
): Promise<DocumentTier> {
|
|
294
|
+
const tier = await resolvePermission(em, documentId, ctx)
|
|
295
|
+
if (!tier || !hasTier(tier, required)) {
|
|
296
|
+
throw forbidden('Forbidden')
|
|
297
|
+
}
|
|
298
|
+
return tier
|
|
299
|
+
}
|