@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,206 @@
|
|
|
1
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
2
|
+
import { hasAllFeatures } from '@open-mercato/shared/lib/auth/featureMatch'
|
|
3
|
+
import { DocumentTemplate } from '../data/entities'
|
|
4
|
+
import {
|
|
5
|
+
documentTemplateContextSlotsSchema,
|
|
6
|
+
type DocumentTemplateFillSlotInput,
|
|
7
|
+
} from '../data/validators'
|
|
8
|
+
import { getEntityRegistryEntry, getEntityTokenFieldNames } from './entityRegistry'
|
|
9
|
+
import { isDocumentEntityRegistryModuleEnabled } from './entityRegistryAvailability.server'
|
|
10
|
+
import { verifyEntityRegistrySelections } from './entityRegistry.server'
|
|
11
|
+
import { materializeDocumentHtml, type MaterializedDocumentHtml } from './collabMaterializer'
|
|
12
|
+
import { renderTemplateTokens, type TemplateRenderResult } from './templateFill'
|
|
13
|
+
import {
|
|
14
|
+
canonicalizeTemplatePreviewInput,
|
|
15
|
+
computeTemplatePreviewDigest,
|
|
16
|
+
type CanonicalTemplatePreview,
|
|
17
|
+
} from './templatePreviewDigest'
|
|
18
|
+
|
|
19
|
+
export type PrepareTemplateRenderInput = {
|
|
20
|
+
request: Request
|
|
21
|
+
template: DocumentTemplate
|
|
22
|
+
title: string
|
|
23
|
+
locale: string
|
|
24
|
+
effectiveDate: string
|
|
25
|
+
templateUpdatedAt: string
|
|
26
|
+
slots: DocumentTemplateFillSlotInput[]
|
|
27
|
+
userFeatures: readonly string[]
|
|
28
|
+
expectedDigest?: string | null
|
|
29
|
+
rejectUnresolved?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type PreparedTemplateRender = {
|
|
33
|
+
canonical: CanonicalTemplatePreview
|
|
34
|
+
/**
|
|
35
|
+
* Authoritative registry snapshots in submitted slot order. Callers that
|
|
36
|
+
* persist entity links must use these records, never the submitted labels,
|
|
37
|
+
* hrefs, or token values.
|
|
38
|
+
*/
|
|
39
|
+
verifiedSlots: DocumentTemplateFillSlotInput[]
|
|
40
|
+
previewDigest: string
|
|
41
|
+
render: TemplateRenderResult
|
|
42
|
+
content: MaterializedDocumentHtml
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function dedupeTemplateLinkSlots<T extends Pick<DocumentTemplateFillSlotInput, 'entityType' | 'entityId'>>(
|
|
46
|
+
slots: readonly T[],
|
|
47
|
+
): T[] {
|
|
48
|
+
return Array.from(
|
|
49
|
+
new Map(slots.map((slot) => [`${slot.entityType}:${slot.entityId}`, slot])).values(),
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function clearOmittedOptionalSlotTokens(
|
|
54
|
+
bodyHtml: string,
|
|
55
|
+
contextSlots: DocumentTemplate['contextSlots'],
|
|
56
|
+
submittedSlots: readonly Pick<DocumentTemplateFillSlotInput, 'slot'>[],
|
|
57
|
+
): string {
|
|
58
|
+
const submitted = new Set(submittedSlots.map((slot) => slot.slot))
|
|
59
|
+
const omittedOptional = new Set(
|
|
60
|
+
documentTemplateContextSlotsSchema
|
|
61
|
+
.parse(contextSlots ?? [])
|
|
62
|
+
.filter((slot) => !slot.required && !submitted.has(slot.slot))
|
|
63
|
+
.map((slot) => slot.slot),
|
|
64
|
+
)
|
|
65
|
+
if (omittedOptional.size === 0) return bodyHtml
|
|
66
|
+
|
|
67
|
+
return bodyHtml.replace(
|
|
68
|
+
/{{\s*([a-z][a-zA-Z0-9]*)\.[^{}]+?\s*}}/g,
|
|
69
|
+
(token, slot: string) => omittedOptional.has(slot) ? '' : token,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function validateTemplateRevision(template: DocumentTemplate, submitted: string): void {
|
|
74
|
+
const revision = new Date(submitted)
|
|
75
|
+
if (Number.isNaN(revision.getTime()) || revision.toISOString() !== template.updatedAt.toISOString()) {
|
|
76
|
+
throw new CrudHttpError(409, { error: 'documents.templates.staleTemplate' })
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function validateTemplateSlots(
|
|
81
|
+
template: DocumentTemplate,
|
|
82
|
+
slots: DocumentTemplateFillSlotInput[],
|
|
83
|
+
features: readonly string[],
|
|
84
|
+
): void {
|
|
85
|
+
const expectedSlots = documentTemplateContextSlotsSchema.parse(template.contextSlots ?? [])
|
|
86
|
+
const submittedByName = new Map(slots.map((slot) => [slot.slot, slot]))
|
|
87
|
+
if (submittedByName.size !== slots.length) {
|
|
88
|
+
throw new CrudHttpError(400, { error: 'documents.templates.duplicateSlot' })
|
|
89
|
+
}
|
|
90
|
+
for (const expected of expectedSlots) {
|
|
91
|
+
const expectedEntry = getEntityRegistryEntry(expected.entityType)
|
|
92
|
+
if (!expectedEntry) {
|
|
93
|
+
throw new CrudHttpError(400, { error: 'documents.links.invalidEntityType' })
|
|
94
|
+
}
|
|
95
|
+
if (
|
|
96
|
+
expected.required
|
|
97
|
+
&& (
|
|
98
|
+
!isDocumentEntityRegistryModuleEnabled(expectedEntry)
|
|
99
|
+
|| !hasAllFeatures([expectedEntry.requiredFeature], Array.from(features))
|
|
100
|
+
)
|
|
101
|
+
) {
|
|
102
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
103
|
+
}
|
|
104
|
+
const submitted = submittedByName.get(expected.slot)
|
|
105
|
+
if (!submitted) {
|
|
106
|
+
if (expected.required) {
|
|
107
|
+
throw new CrudHttpError(400, { error: 'documents.templates.requiredSlotMissing' })
|
|
108
|
+
}
|
|
109
|
+
continue
|
|
110
|
+
}
|
|
111
|
+
if (submitted.entityType !== expected.entityType) {
|
|
112
|
+
throw new CrudHttpError(400, { error: 'documents.templates.slotTypeMismatch' })
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const submitted of slots) {
|
|
116
|
+
if (!expectedSlots.some((slot) => slot.slot === submitted.slot)) {
|
|
117
|
+
throw new CrudHttpError(400, { error: 'documents.templates.unknownSlot' })
|
|
118
|
+
}
|
|
119
|
+
const registryEntry = getEntityRegistryEntry(submitted.entityType)
|
|
120
|
+
if (
|
|
121
|
+
!registryEntry
|
|
122
|
+
|| !isDocumentEntityRegistryModuleEnabled(registryEntry)
|
|
123
|
+
|| !hasAllFeatures([registryEntry.requiredFeature], Array.from(features))
|
|
124
|
+
) {
|
|
125
|
+
throw new CrudHttpError(403, { error: 'Forbidden' })
|
|
126
|
+
}
|
|
127
|
+
const allowedFields = getEntityTokenFieldNames(submitted.entityType)
|
|
128
|
+
for (const field of Object.keys(submitted.values)) {
|
|
129
|
+
if (!allowedFields.has(field)) {
|
|
130
|
+
throw new CrudHttpError(400, { error: 'documents.templates.invalidTokenField' })
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function prepareTemplateRender(
|
|
137
|
+
input: PrepareTemplateRenderInput,
|
|
138
|
+
): Promise<PreparedTemplateRender> {
|
|
139
|
+
validateTemplateRevision(input.template, input.templateUpdatedAt)
|
|
140
|
+
validateTemplateSlots(input.template, input.slots, input.userFeatures)
|
|
141
|
+
const verifiedSelections = await verifyEntityRegistrySelections(
|
|
142
|
+
input.request,
|
|
143
|
+
input.slots.map((slot) => ({
|
|
144
|
+
entityType: slot.entityType,
|
|
145
|
+
entityId: slot.entityId,
|
|
146
|
+
label: slot.label,
|
|
147
|
+
href: slot.href,
|
|
148
|
+
})),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
const verifiedSlots = input.slots.map((slot) => {
|
|
152
|
+
const verified = verifiedSelections.get(`${slot.entityType}:${slot.entityId}`)
|
|
153
|
+
if (!verified) throw new CrudHttpError(400, { error: 'documents.links.targetMismatch' })
|
|
154
|
+
return {
|
|
155
|
+
...slot,
|
|
156
|
+
label: verified.label,
|
|
157
|
+
href: verified.href,
|
|
158
|
+
values: verified.values,
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
const digestInput = {
|
|
163
|
+
templateId: input.template.id,
|
|
164
|
+
templateUpdatedAt: input.templateUpdatedAt,
|
|
165
|
+
title: input.title,
|
|
166
|
+
locale: input.locale,
|
|
167
|
+
effectiveDate: input.effectiveDate,
|
|
168
|
+
slots: verifiedSlots,
|
|
169
|
+
}
|
|
170
|
+
const canonical = canonicalizeTemplatePreviewInput(digestInput)
|
|
171
|
+
const previewDigest = computeTemplatePreviewDigest(digestInput)
|
|
172
|
+
if (input.expectedDigest && previewDigest !== input.expectedDigest) {
|
|
173
|
+
throw new CrudHttpError(409, { error: 'documents.templates.previewChanged' })
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const tokenRender = renderTemplateTokens(
|
|
177
|
+
clearOmittedOptionalSlotTokens(
|
|
178
|
+
input.template.bodyHtml,
|
|
179
|
+
input.template.contextSlots,
|
|
180
|
+
canonical.slots,
|
|
181
|
+
),
|
|
182
|
+
canonical.slots.map((slot) => ({
|
|
183
|
+
slot: slot.slot,
|
|
184
|
+
entityType: slot.entityType,
|
|
185
|
+
entityId: slot.entityId,
|
|
186
|
+
label: slot.label,
|
|
187
|
+
href: slot.href,
|
|
188
|
+
values: slot.values,
|
|
189
|
+
})),
|
|
190
|
+
{ locale: canonical.locale, now: new Date(canonical.effectiveDate) },
|
|
191
|
+
)
|
|
192
|
+
if (input.rejectUnresolved && tokenRender.unresolvedTokens.length > 0) {
|
|
193
|
+
throw new CrudHttpError(400, {
|
|
194
|
+
error: 'documents.templates.unresolvedTokens',
|
|
195
|
+
unresolvedTokens: tokenRender.unresolvedTokens,
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const content = materializeDocumentHtml(tokenRender.html)
|
|
200
|
+
if (!content) {
|
|
201
|
+
throw new CrudHttpError(400, { error: 'documents.templates.invalidContent' })
|
|
202
|
+
}
|
|
203
|
+
const render = { ...tokenRender, html: content.html }
|
|
204
|
+
|
|
205
|
+
return { canonical, verifiedSlots, previewDigest, render, content }
|
|
206
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
|
|
3
|
+
import {
|
|
4
|
+
documentEntityTypeSchema,
|
|
5
|
+
documentTemplateFillSlotSchema,
|
|
6
|
+
documentTitleSchema,
|
|
7
|
+
type DocumentTemplateFillSlotInput,
|
|
8
|
+
} from '../data/validators'
|
|
9
|
+
|
|
10
|
+
export type TemplatePreviewDigestInput = {
|
|
11
|
+
templateId: string
|
|
12
|
+
templateUpdatedAt: string
|
|
13
|
+
title: string
|
|
14
|
+
locale: string
|
|
15
|
+
effectiveDate: string
|
|
16
|
+
slots: DocumentTemplateFillSlotInput[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CanonicalTemplatePreviewValue = string | number | null
|
|
20
|
+
|
|
21
|
+
export type CanonicalTemplatePreviewSlot = {
|
|
22
|
+
slot: string
|
|
23
|
+
entityType: DocumentTemplateFillSlotInput['entityType']
|
|
24
|
+
entityId: string
|
|
25
|
+
label: string
|
|
26
|
+
href: string
|
|
27
|
+
values: Record<string, CanonicalTemplatePreviewValue>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type CanonicalTemplatePreview = {
|
|
31
|
+
schema: 'documents-template-preview-v1'
|
|
32
|
+
templateId: string
|
|
33
|
+
templateUpdatedAt: string
|
|
34
|
+
title: string
|
|
35
|
+
locale: string
|
|
36
|
+
effectiveDate: string
|
|
37
|
+
slots: CanonicalTemplatePreviewSlot[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function normalizeDate(value: string, errorKey: string): string {
|
|
41
|
+
const parsed = new Date(value)
|
|
42
|
+
if (Number.isNaN(parsed.getTime())) throw new CrudHttpError(400, { error: errorKey })
|
|
43
|
+
return parsed.toISOString()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeValue(value: CanonicalTemplatePreviewValue): CanonicalTemplatePreviewValue {
|
|
47
|
+
if (typeof value === 'string') return value.normalize('NFC')
|
|
48
|
+
if (typeof value === 'number') {
|
|
49
|
+
if (!Number.isFinite(value)) {
|
|
50
|
+
throw new CrudHttpError(400, { error: 'documents.templates.invalidValue' })
|
|
51
|
+
}
|
|
52
|
+
return Object.is(value, -0) ? 0 : value
|
|
53
|
+
}
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function compareLexicographically(left: string, right: string): number {
|
|
58
|
+
return left < right ? -1 : left > right ? 1 : 0
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function canonicalizeSlot(slot: DocumentTemplateFillSlotInput): CanonicalTemplatePreviewSlot {
|
|
62
|
+
const parsed = documentTemplateFillSlotSchema.parse(slot)
|
|
63
|
+
const values: Record<string, CanonicalTemplatePreviewValue> = {}
|
|
64
|
+
const normalizedEntries = Object.entries(parsed.values).map(([key, value]) => [
|
|
65
|
+
key.normalize('NFC'),
|
|
66
|
+
normalizeValue(value),
|
|
67
|
+
] as const).sort(([left], [right]) => compareLexicographically(left, right))
|
|
68
|
+
for (const [index, [key, value]] of normalizedEntries.entries()) {
|
|
69
|
+
if (index > 0 && normalizedEntries[index - 1]![0] === key) {
|
|
70
|
+
throw new CrudHttpError(400, { error: 'documents.templates.duplicateValueField' })
|
|
71
|
+
}
|
|
72
|
+
values[key] = value
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
slot: parsed.slot.normalize('NFC'),
|
|
76
|
+
entityType: documentEntityTypeSchema.parse(parsed.entityType),
|
|
77
|
+
entityId: parsed.entityId,
|
|
78
|
+
label: parsed.label.normalize('NFC'),
|
|
79
|
+
href: parsed.href.normalize('NFC'),
|
|
80
|
+
values,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function canonicalizeTemplatePreviewInput(
|
|
85
|
+
input: TemplatePreviewDigestInput,
|
|
86
|
+
): CanonicalTemplatePreview {
|
|
87
|
+
let locale: string
|
|
88
|
+
try {
|
|
89
|
+
locale = new Intl.Locale(input.locale).toString()
|
|
90
|
+
} catch {
|
|
91
|
+
throw new CrudHttpError(400, { error: 'documents.templates.invalidLocale' })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const slots = input.slots.map(canonicalizeSlot).sort((left, right) => (
|
|
95
|
+
compareLexicographically(left.slot, right.slot)
|
|
96
|
+
|| compareLexicographically(left.entityType, right.entityType)
|
|
97
|
+
|| compareLexicographically(left.entityId, right.entityId)
|
|
98
|
+
))
|
|
99
|
+
const slotNames = new Set<string>()
|
|
100
|
+
for (const slot of slots) {
|
|
101
|
+
if (slotNames.has(slot.slot)) {
|
|
102
|
+
throw new CrudHttpError(400, { error: 'documents.templates.duplicateSlot' })
|
|
103
|
+
}
|
|
104
|
+
slotNames.add(slot.slot)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
schema: 'documents-template-preview-v1',
|
|
109
|
+
templateId: input.templateId,
|
|
110
|
+
templateUpdatedAt: normalizeDate(input.templateUpdatedAt, 'documents.templates.invalidRevision'),
|
|
111
|
+
title: documentTitleSchema.parse(input.title).normalize('NFC'),
|
|
112
|
+
locale,
|
|
113
|
+
effectiveDate: normalizeDate(input.effectiveDate, 'documents.templates.invalidEffectiveDate'),
|
|
114
|
+
slots,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function computeTemplatePreviewDigest(input: TemplatePreviewDigestInput): string {
|
|
119
|
+
const canonical = canonicalizeTemplatePreviewInput(input)
|
|
120
|
+
const digest = createHash('sha256').update(JSON.stringify(canonical), 'utf8').digest('hex')
|
|
121
|
+
return `sha256:${digest}`
|
|
122
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
+
import { randomUUID } from 'node:crypto'
|
|
3
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
4
|
+
import { DocumentTemplate } from '../data/entities'
|
|
5
|
+
|
|
6
|
+
export type DefaultDocumentTemplateSeed = {
|
|
7
|
+
name: string
|
|
8
|
+
description: string
|
|
9
|
+
bodyHtml: string
|
|
10
|
+
contextSlots: { slot: string; entityType: string; required?: boolean }[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Managed seed metadata is internal to the idempotent setup path. */
|
|
14
|
+
export type ManagedDocumentTemplateSeed = DefaultDocumentTemplateSeed & {
|
|
15
|
+
seedKey: string
|
|
16
|
+
legacyAdoptable?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const TEMPLATE_SEED_ACTOR_ID = '00000000-0000-4000-8000-000000000000'
|
|
20
|
+
const DEFAULT_NAME_SUFFIX = ' — Open Mercato default'
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_DOCUMENT_TEMPLATES: Array<ManagedDocumentTemplateSeed> = [
|
|
23
|
+
{
|
|
24
|
+
seedKey: 'offer-letter',
|
|
25
|
+
legacyAdoptable: true,
|
|
26
|
+
name: 'Offer letter',
|
|
27
|
+
description: 'A proposal starter with customer and quote context.',
|
|
28
|
+
bodyHtml: [
|
|
29
|
+
'<h1>Offer for {{customer.name}}</h1>',
|
|
30
|
+
'<p>{{customer.chip}}</p>',
|
|
31
|
+
'<p>Thank you for the opportunity to prepare offer {{quote.number}}.</p>',
|
|
32
|
+
'<p>Write your offer details here…</p>',
|
|
33
|
+
'<p>Prepared on {{date}}</p>',
|
|
34
|
+
].join(''),
|
|
35
|
+
contextSlots: [
|
|
36
|
+
{ slot: 'customer', entityType: 'customer-person', required: true },
|
|
37
|
+
{ slot: 'quote', entityType: 'quote', required: false },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
seedKey: 'meeting-notes',
|
|
42
|
+
legacyAdoptable: true,
|
|
43
|
+
name: 'Meeting notes',
|
|
44
|
+
description: 'A structured note template for meetings and follow-ups.',
|
|
45
|
+
bodyHtml: [
|
|
46
|
+
'<h1>Meeting notes — {{date}}</h1>',
|
|
47
|
+
'<p>{{company.chip}}</p>',
|
|
48
|
+
'<h2>Attendees</h2><ul></ul>',
|
|
49
|
+
'<h2>Agenda</h2><ul></ul>',
|
|
50
|
+
'<h2>Action items</h2><ul></ul>',
|
|
51
|
+
].join(''),
|
|
52
|
+
contextSlots: [{ slot: 'company', entityType: 'customer-company', required: false }],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
seedKey: 'deal-summary',
|
|
56
|
+
legacyAdoptable: true,
|
|
57
|
+
name: 'Deal summary',
|
|
58
|
+
description: 'A concise deal snapshot with customer context.',
|
|
59
|
+
bodyHtml: [
|
|
60
|
+
'<h1>Deal summary: {{deal.title}}</h1>',
|
|
61
|
+
'<p>{{deal.chip}}</p>',
|
|
62
|
+
'<table><tbody>',
|
|
63
|
+
'<tr><td>Status</td><td>{{deal.status}}</td></tr>',
|
|
64
|
+
'<tr><td>Value</td><td>{{deal.value}} {{deal.valueCurrency}}</td></tr>',
|
|
65
|
+
'<tr><td>Customer</td><td>{{customer.name}}</td></tr>',
|
|
66
|
+
'</tbody></table>',
|
|
67
|
+
'<h2>Notes</h2><p></p>',
|
|
68
|
+
].join(''),
|
|
69
|
+
contextSlots: [
|
|
70
|
+
{ slot: 'deal', entityType: 'deal', required: true },
|
|
71
|
+
{ slot: 'customer', entityType: 'customer-company', required: false },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
seedKey: 'customer-meeting-brief',
|
|
76
|
+
name: 'Customer meeting brief',
|
|
77
|
+
description: 'Prepare a customer conversation with context and clear outcomes.',
|
|
78
|
+
bodyHtml: [
|
|
79
|
+
'<h1>Meeting brief — {{customer.name}}</h1>',
|
|
80
|
+
'<p>{{customer.chip}}</p>',
|
|
81
|
+
'<h2>Purpose</h2><p></p>',
|
|
82
|
+
'<h2>Discussion points</h2><ul></ul>',
|
|
83
|
+
'<h2>Desired outcomes</h2><ul></ul>',
|
|
84
|
+
'<p>Prepared on {{date}}</p>',
|
|
85
|
+
].join(''),
|
|
86
|
+
contextSlots: [{ slot: 'customer', entityType: 'customer-person', required: true }],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
seedKey: 'deal-proposal',
|
|
90
|
+
name: 'Deal proposal',
|
|
91
|
+
description: 'A proposal grounded in the current deal value and stage.',
|
|
92
|
+
bodyHtml: [
|
|
93
|
+
'<h1>Proposal — {{deal.title}}</h1>',
|
|
94
|
+
'<p>{{deal.chip}}</p>',
|
|
95
|
+
'<p>Status: {{deal.status}}</p>',
|
|
96
|
+
'<p>Value: {{deal.value}} {{deal.valueCurrency}}</p>',
|
|
97
|
+
'<h2>Objectives</h2><p></p>',
|
|
98
|
+
'<h2>Approach</h2><p></p>',
|
|
99
|
+
'<h2>Next steps</h2><ol></ol>',
|
|
100
|
+
].join(''),
|
|
101
|
+
contextSlots: [{ slot: 'deal', entityType: 'deal', required: true }],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
seedKey: 'quote-cover-letter',
|
|
105
|
+
name: 'Quote cover letter',
|
|
106
|
+
description: 'A concise cover letter for a sales quote.',
|
|
107
|
+
bodyHtml: [
|
|
108
|
+
'<h1>Quote {{quote.number}}</h1>',
|
|
109
|
+
'<p>{{quote.chip}}</p>',
|
|
110
|
+
'<p>Thank you for considering this proposal.</p>',
|
|
111
|
+
'<p>Total: {{quote.total}} {{quote.currency}}</p>',
|
|
112
|
+
'<h2>Summary</h2><p></p>',
|
|
113
|
+
'<p>Prepared on {{date}}</p>',
|
|
114
|
+
].join(''),
|
|
115
|
+
contextSlots: [{ slot: 'quote', entityType: 'quote', required: true }],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
seedKey: 'order-handoff',
|
|
119
|
+
name: 'Order handoff',
|
|
120
|
+
description: 'Capture delivery context and ownership for an accepted order.',
|
|
121
|
+
bodyHtml: [
|
|
122
|
+
'<h1>Order handoff — {{order.number}}</h1>',
|
|
123
|
+
'<p>{{order.chip}}</p>',
|
|
124
|
+
'<p>Status: {{order.status}}</p>',
|
|
125
|
+
'<p>Total: {{order.total}} {{order.currency}}</p>',
|
|
126
|
+
'<h2>Delivery notes</h2><p></p>',
|
|
127
|
+
'<h2>Owners and next steps</h2><ul></ul>',
|
|
128
|
+
].join(''),
|
|
129
|
+
contextSlots: [{ slot: 'order', entityType: 'sales-order', required: true }],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
seedKey: 'product-brief',
|
|
133
|
+
name: 'Product brief',
|
|
134
|
+
description: 'A reusable product positioning and launch brief.',
|
|
135
|
+
bodyHtml: [
|
|
136
|
+
'<h1>Product brief — {{product.title}}</h1>',
|
|
137
|
+
'<p>{{product.chip}}</p>',
|
|
138
|
+
'<p>SKU: {{product.sku}}</p>',
|
|
139
|
+
'<h2>Audience</h2><p></p>',
|
|
140
|
+
'<h2>Value proposition</h2><p></p>',
|
|
141
|
+
'<h2>Launch checklist</h2><ul></ul>',
|
|
142
|
+
].join(''),
|
|
143
|
+
contextSlots: [{ slot: 'product', entityType: 'product', required: true }],
|
|
144
|
+
},
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
type SeedDocumentTemplatesScope = {
|
|
148
|
+
tenantId: string
|
|
149
|
+
organizationId: string
|
|
150
|
+
createdByUserId?: string | null
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function slotsMatch(
|
|
154
|
+
current: DocumentTemplate['contextSlots'],
|
|
155
|
+
expected: DefaultDocumentTemplateSeed['contextSlots'],
|
|
156
|
+
): boolean {
|
|
157
|
+
return JSON.stringify(current ?? []) === JSON.stringify(expected)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function findBySeedKey(
|
|
161
|
+
em: EntityManager,
|
|
162
|
+
scope: SeedDocumentTemplatesScope,
|
|
163
|
+
seedKey: string,
|
|
164
|
+
): Promise<DocumentTemplate | null> {
|
|
165
|
+
return findOneWithDecryption(
|
|
166
|
+
em,
|
|
167
|
+
DocumentTemplate,
|
|
168
|
+
{
|
|
169
|
+
tenantId: scope.tenantId,
|
|
170
|
+
organizationId: scope.organizationId,
|
|
171
|
+
seedKey,
|
|
172
|
+
},
|
|
173
|
+
{ filters: false },
|
|
174
|
+
scope,
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function findActiveByName(
|
|
179
|
+
em: EntityManager,
|
|
180
|
+
scope: SeedDocumentTemplatesScope,
|
|
181
|
+
name: string,
|
|
182
|
+
): Promise<DocumentTemplate | null> {
|
|
183
|
+
return findOneWithDecryption(
|
|
184
|
+
em,
|
|
185
|
+
DocumentTemplate,
|
|
186
|
+
{
|
|
187
|
+
tenantId: scope.tenantId,
|
|
188
|
+
organizationId: scope.organizationId,
|
|
189
|
+
name,
|
|
190
|
+
deletedAt: null,
|
|
191
|
+
},
|
|
192
|
+
undefined,
|
|
193
|
+
scope,
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export async function seedDefaultDocumentTemplates(
|
|
198
|
+
em: EntityManager,
|
|
199
|
+
scope: SeedDocumentTemplatesScope,
|
|
200
|
+
): Promise<void> {
|
|
201
|
+
// Setup can share an EntityManager with other module initializers. Isolate
|
|
202
|
+
// the unique-race recovery path so clearing a failed seed insert never drops
|
|
203
|
+
// unrelated pending setup changes from the caller's unit of work.
|
|
204
|
+
const seedEm = typeof em.fork === 'function' ? em.fork() : em
|
|
205
|
+
const createdByUserId = scope.createdByUserId ?? TEMPLATE_SEED_ACTOR_ID
|
|
206
|
+
|
|
207
|
+
for (const seed of DEFAULT_DOCUMENT_TEMPLATES) {
|
|
208
|
+
if (await findBySeedKey(seedEm, scope, seed.seedKey)) continue
|
|
209
|
+
|
|
210
|
+
const nameCollision = await findActiveByName(seedEm, scope, seed.name)
|
|
211
|
+
if (
|
|
212
|
+
seed.legacyAdoptable
|
|
213
|
+
&& nameCollision
|
|
214
|
+
&& nameCollision.description === seed.description
|
|
215
|
+
&& nameCollision.bodyHtml === seed.bodyHtml
|
|
216
|
+
&& slotsMatch(nameCollision.contextSlots, seed.contextSlots)
|
|
217
|
+
) {
|
|
218
|
+
nameCollision.seedKey = seed.seedKey
|
|
219
|
+
try {
|
|
220
|
+
await seedEm.flush()
|
|
221
|
+
} catch (error) {
|
|
222
|
+
seedEm.clear()
|
|
223
|
+
if (!await findBySeedKey(seedEm, scope, seed.seedKey)) throw error
|
|
224
|
+
}
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const template = seedEm.create(DocumentTemplate, {
|
|
229
|
+
id: randomUUID(),
|
|
230
|
+
tenantId: scope.tenantId,
|
|
231
|
+
organizationId: scope.organizationId,
|
|
232
|
+
seedKey: seed.seedKey,
|
|
233
|
+
name: nameCollision ? `${seed.name}${DEFAULT_NAME_SUFFIX}` : seed.name,
|
|
234
|
+
description: seed.description,
|
|
235
|
+
bodyHtml: seed.bodyHtml,
|
|
236
|
+
contextSlots: seed.contextSlots,
|
|
237
|
+
createdByUserId,
|
|
238
|
+
isActive: true,
|
|
239
|
+
})
|
|
240
|
+
seedEm.persist(template)
|
|
241
|
+
try {
|
|
242
|
+
await seedEm.flush()
|
|
243
|
+
} catch (error) {
|
|
244
|
+
seedEm.clear()
|
|
245
|
+
if (!await findBySeedKey(seedEm, scope, seed.seedKey)) throw error
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { sanitizeDocumentsDisplayLabel } from './displayLabels'
|
|
2
|
+
import {
|
|
3
|
+
resolveAuthPrincipalService,
|
|
4
|
+
type DocumentsServiceContainer,
|
|
5
|
+
} from './platformServices'
|
|
6
|
+
|
|
7
|
+
export type UserLabel = { label: string; secondary?: string | null }
|
|
8
|
+
export type ViewerSafeUserLabel = { label: string }
|
|
9
|
+
|
|
10
|
+
function cleanString(value: unknown): string | null {
|
|
11
|
+
return sanitizeDocumentsDisplayLabel(value)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function resolveUserLabels(
|
|
15
|
+
container: DocumentsServiceContainer | null | undefined,
|
|
16
|
+
scope: { tenantId: string; organizationId: string },
|
|
17
|
+
userIds: string[],
|
|
18
|
+
): Promise<Map<string, UserLabel>> {
|
|
19
|
+
const uniqueUserIds = Array.from(
|
|
20
|
+
new Set(userIds.map((id) => id.trim()).filter((id) => id.length > 0)),
|
|
21
|
+
)
|
|
22
|
+
const labels = new Map<string, UserLabel>()
|
|
23
|
+
if (uniqueUserIds.length === 0) return labels
|
|
24
|
+
|
|
25
|
+
const service = resolveAuthPrincipalService(container)
|
|
26
|
+
if (!service) return labels
|
|
27
|
+
const users = await service.resolveLabels({ type: 'user', ids: uniqueUserIds, scope })
|
|
28
|
+
|
|
29
|
+
for (const user of users) {
|
|
30
|
+
const label = cleanString(user.label)
|
|
31
|
+
const secondary = cleanString(user.secondary)
|
|
32
|
+
if (!label) continue
|
|
33
|
+
labels.set(user.id, { label, secondary: secondary && secondary !== label ? secondary : null })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return labels
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Resolve labels safe for document viewers. Comment history needs readable
|
|
41
|
+
* author names, but it is not a directory surface: secondary identifiers must
|
|
42
|
+
* not cross this boundary. The primary label itself is kept as the directory
|
|
43
|
+
* resolved it — for an account without a display name that is its email, the
|
|
44
|
+
* same label the list owner column and version history already show, so a
|
|
45
|
+
* commenter never degrades to the "unknown user" placeholder.
|
|
46
|
+
*/
|
|
47
|
+
export async function resolveViewerSafeUserLabels(
|
|
48
|
+
container: DocumentsServiceContainer | null | undefined,
|
|
49
|
+
scope: { tenantId: string; organizationId: string },
|
|
50
|
+
userIds: string[],
|
|
51
|
+
): Promise<Map<string, ViewerSafeUserLabel>> {
|
|
52
|
+
const resolved = await resolveUserLabels(container, scope, userIds)
|
|
53
|
+
const labels = new Map<string, ViewerSafeUserLabel>()
|
|
54
|
+
for (const [userId, value] of resolved.entries()) {
|
|
55
|
+
labels.set(userId, { label: value.label })
|
|
56
|
+
}
|
|
57
|
+
return labels
|
|
58
|
+
}
|