@open-mercato/documents 0.9.1-develop.7574.1.837288eec1 → 0.10.0
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/dist/contentSecurityPolicy.js +23 -0
- package/dist/contentSecurityPolicy.js.map +7 -0
- package/dist/modules/documents/api/[id]/comments/access-check/route.js +13 -6
- package/dist/modules/documents/api/[id]/comments/access-check/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/comments/route.js +2 -0
- package/dist/modules/documents/api/[id]/comments/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/content/route.js +2 -0
- package/dist/modules/documents/api/[id]/content/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/route.js +3 -0
- package/dist/modules/documents/api/[id]/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/shares/route.js +2 -0
- package/dist/modules/documents/api/[id]/shares/route.js.map +2 -2
- package/dist/modules/documents/api/[id]/versions/route.js +2 -0
- package/dist/modules/documents/api/[id]/versions/route.js.map +2 -2
- package/dist/modules/documents/api/_shared.js +10 -27
- package/dist/modules/documents/api/_shared.js.map +3 -3
- package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js +3 -1
- package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js +1 -1
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js +15 -1
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js +15 -1
- package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js +20 -8
- package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js +3 -0
- package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/editorTypes.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/saveCollaborativeContent.js +46 -0
- package/dist/modules/documents/backend/documents/[id]/saveCollaborativeContent.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js +14 -6
- package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js.map +2 -2
- package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js +3 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js.map +2 -2
- package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js +3 -0
- package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js.map +2 -2
- package/dist/modules/documents/backend/documents/components/TemplatePreview.js +3 -0
- package/dist/modules/documents/backend/documents/components/TemplatePreview.js.map +2 -2
- package/dist/modules/documents/commands/comments.js +2 -2
- package/dist/modules/documents/commands/comments.js.map +2 -2
- package/dist/modules/documents/commands/folders.js +1 -0
- package/dist/modules/documents/commands/folders.js.map +2 -2
- package/dist/modules/documents/commands/interceptors.js +11 -0
- package/dist/modules/documents/commands/interceptors.js.map +2 -2
- package/dist/modules/documents/data/attachment-access.js +84 -0
- package/dist/modules/documents/data/attachment-access.js.map +7 -0
- package/dist/modules/documents/data/validators.js +11 -0
- package/dist/modules/documents/data/validators.js.map +2 -2
- package/dist/modules/documents/lib/actor.js +32 -0
- package/dist/modules/documents/lib/actor.js.map +7 -0
- package/dist/modules/documents/lib/collabMaterializer.js +52 -9
- package/dist/modules/documents/lib/collabMaterializer.js.map +2 -2
- package/dist/modules/documents/lib/collabPersistence.js +13 -0
- package/dist/modules/documents/lib/collabPersistence.js.map +7 -0
- package/dist/modules/documents/lib/permissions.js +35 -2
- package/dist/modules/documents/lib/permissions.js.map +2 -2
- package/dist/modules/documents/widgets/injection/related-documents/widget.client.js +3 -2
- package/dist/modules/documents/widgets/injection/related-documents/widget.client.js.map +2 -2
- package/dist/modules/documents/widgets/injection-table.js +12 -3
- package/dist/modules/documents/widgets/injection-table.js.map +2 -2
- package/dist/server/documents-collab-server.js +74 -1
- package/dist/server/documents-collab-server.js.map +2 -2
- package/jest.config.cjs +1 -1
- package/package.json +37 -37
- package/server/documents-collab-server.ts +79 -0
- package/src/contentSecurityPolicy.ts +21 -0
- package/src/modules/documents/api/[id]/comments/access-check/route.ts +13 -6
- package/src/modules/documents/api/[id]/comments/route.ts +2 -0
- package/src/modules/documents/api/[id]/content/route.ts +2 -0
- package/src/modules/documents/api/[id]/route.ts +3 -0
- package/src/modules/documents/api/[id]/shares/route.ts +2 -0
- package/src/modules/documents/api/[id]/versions/route.ts +2 -0
- package/src/modules/documents/api/_shared.ts +10 -36
- package/src/modules/documents/backend/documents/[id]/DocumentCanvas.tsx +3 -1
- package/src/modules/documents/backend/documents/[id]/DocumentEditorIsland.tsx +4 -1
- package/src/modules/documents/backend/documents/[id]/DocumentEditorSurface.tsx +19 -1
- package/src/modules/documents/backend/documents/[id]/DocumentPageClient.tsx +14 -0
- package/src/modules/documents/backend/documents/[id]/VersionHistoryPanel.tsx +23 -8
- package/src/modules/documents/backend/documents/[id]/VersionPreviewDialog.tsx +3 -0
- package/src/modules/documents/backend/documents/[id]/editorTypes.ts +1 -0
- package/src/modules/documents/backend/documents/[id]/saveCollaborativeContent.ts +43 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentComments.ts +17 -7
- package/src/modules/documents/backend/documents/[id]/useDocumentEditor.ts +3 -0
- package/src/modules/documents/backend/documents/components/TemplateBodyEditor.tsx +3 -0
- package/src/modules/documents/backend/documents/components/TemplatePreview.tsx +3 -0
- package/src/modules/documents/commands/comments.ts +2 -2
- package/src/modules/documents/commands/folders.ts +1 -3
- package/src/modules/documents/commands/interceptors.ts +11 -0
- package/src/modules/documents/data/attachment-access.ts +83 -0
- package/src/modules/documents/data/validators.ts +12 -0
- package/src/modules/documents/lib/actor.ts +39 -0
- package/src/modules/documents/lib/collabMaterializer.ts +62 -11
- package/src/modules/documents/lib/collabPersistence.ts +10 -0
- package/src/modules/documents/lib/permissions.ts +52 -0
- package/src/modules/documents/widgets/injection/related-documents/widget.client.tsx +3 -2
- package/src/modules/documents/widgets/injection-table.ts +17 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/documents/widgets/injection/related-documents/widget.client.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport Link from 'next/link'\nimport { ExternalLink, FilePlus2, Link2 } from 'lucide-react'\nimport type { InjectionWidgetComponentProps } from '@open-mercato/shared/modules/widgets/injection'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { SectionHeader } from '@open-mercato/ui/backend/SectionHeader'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { LinkButton } from '@open-mercato/ui/primitives/link-button'\nimport { EmptyState } from '@open-mercato/ui/primitives/empty-state'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { formatDateTime } from '../../../backend/documents/documentUi'\nimport { LinkDocumentDialog } from './LinkDocumentDialog'\nimport { resolveRelatedDocumentActions, resolveRelatedDocumentContext } from './context'\nimport { useRelatedDocuments } from './useRelatedDocuments'\n\nfunction NewFromTemplateDialogLoading({ error, retry }: { error?: Error | null; retry?: () => void }) {\n const t = useT()\n if (error) {\n return (\n <ErrorMessage\n label={t('documents.templates.instantiate.error.load')}\n action={<Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={retry}>{t('documents.actions.retry')}</Button>}\n />\n )\n }\n return (\n <div role=\"status\" aria-live=\"polite\">\n <LoadingMessage label={t('documents.templates.instantiate.loading')} />\n </div>\n )\n}\n\nconst NewFromTemplateDialog = dynamic(\n () => import('../../../backend/documents/components/NewFromTemplateDialog').then((module) => module.NewFromTemplateDialog),\n { ssr: false, loading: NewFromTemplateDialogLoading },\n)\n\nexport default function RelatedDocumentsWidget({ context, data, disabled }: InjectionWidgetComponentProps<Record<string, unknown>, Record<string, unknown>>) {\n const t = useT()\n const target = React.useMemo(() => resolveRelatedDocumentContext(context, data), [context, data])\n const related = useRelatedDocuments(target)\n const [linkOpen, setLinkOpen] = React.useState(false)\n const [createOpen, setCreateOpen] = React.useState(false)\n if (!target || related.status === 'hidden') return null\n const label = target.label ?? t('documents.relatedDocuments.recordFallback')\n const actions = resolveRelatedDocumentActions(related.capabilities, Boolean(disabled))\n\n return (\n <section className=\"rounded-lg border border-border bg-card p-4\">\n <SectionHeader\n title={t('documents.relatedDocuments.title')}\n count={related.items.length}\n action={actions.canLink || actions.canCreate ?
|
|
5
|
-
"mappings": ";AAwBgB,
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport Link from 'next/link'\nimport { ExternalLink, FilePlus2, Link2 } from 'lucide-react'\nimport type { InjectionWidgetComponentProps } from '@open-mercato/shared/modules/widgets/injection'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { SectionHeader } from '@open-mercato/ui/backend/SectionHeader'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { LinkButton } from '@open-mercato/ui/primitives/link-button'\nimport { EmptyState } from '@open-mercato/ui/primitives/empty-state'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { formatDateTime } from '../../../backend/documents/documentUi'\nimport { LinkDocumentDialog } from './LinkDocumentDialog'\nimport { resolveRelatedDocumentActions, resolveRelatedDocumentContext } from './context'\nimport { useRelatedDocuments } from './useRelatedDocuments'\n\nfunction NewFromTemplateDialogLoading({ error, retry }: { error?: Error | null; retry?: () => void }) {\n const t = useT()\n if (error) {\n return (\n <ErrorMessage\n label={t('documents.templates.instantiate.error.load')}\n action={<Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={retry}>{t('documents.actions.retry')}</Button>}\n />\n )\n }\n return (\n <div role=\"status\" aria-live=\"polite\">\n <LoadingMessage label={t('documents.templates.instantiate.loading')} />\n </div>\n )\n}\n\nconst NewFromTemplateDialog = dynamic(\n () => import('../../../backend/documents/components/NewFromTemplateDialog').then((module) => module.NewFromTemplateDialog),\n { ssr: false, loading: NewFromTemplateDialogLoading },\n)\n\nexport default function RelatedDocumentsWidget({ context, data, disabled }: InjectionWidgetComponentProps<Record<string, unknown>, Record<string, unknown>>) {\n const t = useT()\n const target = React.useMemo(() => resolveRelatedDocumentContext(context, data), [context, data])\n const related = useRelatedDocuments(target)\n const [linkOpen, setLinkOpen] = React.useState(false)\n const [createOpen, setCreateOpen] = React.useState(false)\n if (!target || related.status === 'hidden') return null\n const label = target.label ?? t('documents.relatedDocuments.recordFallback')\n const actions = resolveRelatedDocumentActions(related.capabilities, Boolean(disabled))\n\n return (\n <section className=\"rounded-lg border border-border bg-card p-4\">\n <SectionHeader\n className=\"flex-col items-start gap-3 sm:flex-row sm:items-center\"\n title={t('documents.relatedDocuments.title')}\n count={related.items.length}\n action={actions.canLink || actions.canCreate ? <div className=\"flex flex-wrap gap-1\" data-testid=\"related-documents-actions\">\n {actions.canLink ? <Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={() => setLinkOpen(true)}><Link2 />{t('documents.relatedDocuments.actions.link')}</Button> : null}\n {actions.canCreate ? <Button type=\"button\" size=\"sm\" onClick={() => setCreateOpen(true)}><FilePlus2 />{t('documents.relatedDocuments.actions.create')}</Button> : null}\n </div> : undefined}\n />\n <div className=\"mt-4\">\n {related.status === 'loading' ? <LoadingMessage label={t('documents.relatedDocuments.loading')} /> : null}\n {related.status === 'error' ? <ErrorMessage label={t('documents.relatedDocuments.error.load')} action={<Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={related.retry}>{t('documents.actions.retry')}</Button>} /> : null}\n {related.status === 'ready' && related.items.length === 0 ? <EmptyState size=\"sm\" variant=\"subtle\" title={t('documents.relatedDocuments.empty')} icon={<Link2 className=\"size-5\" />} /> : null}\n {related.status === 'ready' && related.items.length > 0 ? <div className=\"space-y-2\">{related.items.map((row) => (\n <div key={row.id} className=\"flex flex-wrap items-center justify-between gap-3 rounded-md border border-border p-3\">\n <div className=\"min-w-0\"><Link className=\"block truncate text-sm font-medium hover:underline focus-visible:underline focus-visible:outline-none\" href={`/backend/documents/${row.id}`}>{row.title}</Link><p className=\"truncate text-xs text-muted-foreground\">{t('documents.relatedDocuments.meta', { owner: row.ownerLabel, updated: formatDateTime(row.updatedAt, t('documents.relatedDocuments.unknownDate')) })}</p></div>\n <LinkButton asChild size=\"sm\" variant=\"gray\"><Link href={`/backend/documents/${row.id}`}><ExternalLink />{t('documents.actions.open')}</Link></LinkButton>\n </div>\n ))}</div> : null}\n </div>\n {actions.canLink && linkOpen ? <LinkDocumentDialog open target={{ ...target, label }} onOpenChange={setLinkOpen} onLinked={related.retry} /> : null}\n {actions.canCreate && createOpen ? <NewFromTemplateDialog open onOpenChange={setCreateOpen} presetContext={{ entityType: target.entityType, entityId: target.entityId, label, values: target.values }} /> : null}\n </section>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAwBgB,cAiCa,YAjCb;AAtBhB,YAAY,WAAW;AACvB,OAAO,aAAa;AACpB,OAAO,UAAU;AACjB,SAAS,cAAc,WAAW,aAAa;AAE/C,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,+BAA+B,qCAAqC;AAC7E,SAAS,2BAA2B;AAEpC,SAAS,6BAA6B,EAAE,OAAO,MAAM,GAAiD;AACpG,QAAM,IAAI,KAAK;AACf,MAAI,OAAO;AACT,WACE;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,EAAE,4CAA4C;AAAA,QACrD,QAAQ,oBAAC,UAAO,MAAK,UAAS,MAAK,MAAK,SAAQ,WAAU,S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Q,WAAW,WAAW,oBAAC,sBAAmB,MAAI,MAAC,QAAQ,EAAE,GAAG,QAAQ,MAAM,GAAG,cAAc,aAAa,UAAU,QAAQ,OAAO,IAAK;AAAA,IAC9I,QAAQ,aAAa,aAAa,oBAAC,yBAAsB,MAAI,MAAC,cAAc,eAAe,eAAe,EAAE,YAAY,OAAO,YAAY,UAAU,OAAO,UAAU,OAAO,QAAQ,OAAO,OAAO,GAAG,IAAK;AAAA,KAC9M;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,12 +3,21 @@ const relatedDocuments = {
|
|
|
3
3
|
kind: "stack",
|
|
4
4
|
priority: 80
|
|
5
5
|
};
|
|
6
|
+
const relatedDocumentsTab = {
|
|
7
|
+
widgetId: "documents.injection.related-documents",
|
|
8
|
+
kind: "tab",
|
|
9
|
+
groupId: "related-documents",
|
|
10
|
+
groupLabel: "documents.relatedDocuments.title",
|
|
11
|
+
icon: "file-text",
|
|
12
|
+
// Negative: after the host's built-in tabs (#8020 ordering contract).
|
|
13
|
+
priority: -20
|
|
14
|
+
};
|
|
6
15
|
const injectionTable = {
|
|
7
|
-
"detail:customers.person:
|
|
16
|
+
"detail:customers.person:tabs": [relatedDocumentsTab],
|
|
8
17
|
"customers.person.detail:details": [relatedDocuments],
|
|
9
|
-
"detail:customers.company:
|
|
18
|
+
"detail:customers.company:tabs": [relatedDocumentsTab],
|
|
10
19
|
"customers.company.detail:details": [relatedDocuments],
|
|
11
|
-
"detail:customers.deal:
|
|
20
|
+
"detail:customers.deal:tabs": [relatedDocumentsTab],
|
|
12
21
|
"sales.document.detail.quote:details": [relatedDocuments],
|
|
13
22
|
"sales.document.detail.order:details": [relatedDocuments],
|
|
14
23
|
"crud-form:catalog.product": [relatedDocuments]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/documents/widgets/injection-table.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ModuleInjectionTable } from '@open-mercato/shared/modules/widgets/injection'\n\nconst relatedDocuments = {\n widgetId: 'documents.injection.related-documents',\n kind: 'stack' as const,\n priority: 80,\n}\n\nexport const injectionTable: ModuleInjectionTable = {\n 'detail:customers.person:
|
|
5
|
-
"mappings": "AAEA,MAAM,mBAAmB;AAAA,EACvB,UAAU;AAAA,EACV,MAAM;AAAA,EACN,UAAU;AACZ;AAEO,MAAM,iBAAuC;AAAA,EAClD,
|
|
4
|
+
"sourcesContent": ["import type { ModuleInjectionTable } from '@open-mercato/shared/modules/widgets/injection'\n\nconst relatedDocuments = {\n widgetId: 'documents.injection.related-documents',\n kind: 'stack' as const,\n priority: 80,\n}\n\n// The three CRM detail pages (people-v2, companies-v2, deals) mount the panel\n// as a tab of their related-content workspace (#7488). Their tab loaders\n// ignore `kind: 'stack'`, hence a separate descriptor; the legacy CRM, sales\n// and catalog hosts keep the inline stack below.\nconst relatedDocumentsTab = {\n widgetId: 'documents.injection.related-documents',\n kind: 'tab' as const,\n groupId: 'related-documents',\n groupLabel: 'documents.relatedDocuments.title',\n icon: 'file-text',\n // Negative: after the host's built-in tabs (#8020 ordering contract).\n priority: -20,\n}\n\nexport const injectionTable: ModuleInjectionTable = {\n 'detail:customers.person:tabs': [relatedDocumentsTab],\n 'customers.person.detail:details': [relatedDocuments],\n 'detail:customers.company:tabs': [relatedDocumentsTab],\n 'customers.company.detail:details': [relatedDocuments],\n 'detail:customers.deal:tabs': [relatedDocumentsTab],\n 'sales.document.detail.quote:details': [relatedDocuments],\n 'sales.document.detail.order:details': [relatedDocuments],\n 'crud-form:catalog.product': [relatedDocuments],\n}\n\nexport default injectionTable\n"],
|
|
5
|
+
"mappings": "AAEA,MAAM,mBAAmB;AAAA,EACvB,UAAU;AAAA,EACV,MAAM;AAAA,EACN,UAAU;AACZ;AAMA,MAAM,sBAAsB;AAAA,EAC1B,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,MAAM;AAAA;AAAA,EAEN,UAAU;AACZ;AAEO,MAAM,iBAAuC;AAAA,EAClD,gCAAgC,CAAC,mBAAmB;AAAA,EACpD,mCAAmC,CAAC,gBAAgB;AAAA,EACpD,iCAAiC,CAAC,mBAAmB;AAAA,EACrD,oCAAoC,CAAC,gBAAgB;AAAA,EACrD,8BAA8B,CAAC,mBAAmB;AAAA,EAClD,uCAAuC,CAAC,gBAAgB;AAAA,EACxD,uCAAuC,CAAC,gBAAgB;AAAA,EACxD,6BAA6B,CAAC,gBAAgB;AAChD;AAEA,IAAO,0BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
} from "@hocuspocus/server";
|
|
12
12
|
import { Redis as HocuspocusRedis } from "@hocuspocus/extension-redis";
|
|
13
13
|
import * as Y from "yjs";
|
|
14
|
+
import { collabContentSaveRequestSchema } from "@open-mercato/documents/modules/documents/data/validators";
|
|
15
|
+
import { containsDocumentSnapshot } from "@open-mercato/documents/modules/documents/lib/collabPersistence";
|
|
14
16
|
import { hasAllFeatures } from "@open-mercato/shared/lib/auth/featureMatch";
|
|
15
17
|
import { isCrudHttpError } from "@open-mercato/shared/lib/crud/errors";
|
|
16
18
|
import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
|
|
@@ -1531,6 +1533,24 @@ function createCollabHooks(deps) {
|
|
|
1531
1533
|
assertConnectionAuthorization,
|
|
1532
1534
|
establishConnectionAuthorization,
|
|
1533
1535
|
releaseConnectionAuthorization,
|
|
1536
|
+
async saveContent(data) {
|
|
1537
|
+
try {
|
|
1538
|
+
assertScopedContext(data.context);
|
|
1539
|
+
const scope = roomScopes.get(data.document);
|
|
1540
|
+
const isCurrent = () => data.context.documentId === data.documentName && scope?.tenantId === data.context.tenantId && scope.organizationId === data.context.organizationId && !data.context.readOnly && !isInvalidated(data.documentName, data.document) && !isFinalDrainPending(data.documentName);
|
|
1541
|
+
if (!isCurrent() || !await deps.authorizeContext(data.context) || !isCurrent()) return false;
|
|
1542
|
+
const requested = Y.snapshot(data.document);
|
|
1543
|
+
const confirmation = { snapshot: null };
|
|
1544
|
+
await data.store((snapshot) => {
|
|
1545
|
+
confirmation.snapshot = snapshot;
|
|
1546
|
+
});
|
|
1547
|
+
if (!isCurrent() || !await deps.authorizeContext(data.context) || !isCurrent()) return false;
|
|
1548
|
+
const durable = confirmation.snapshot;
|
|
1549
|
+
return Boolean(durable && containsDocumentSnapshot(durable, requested));
|
|
1550
|
+
} catch {
|
|
1551
|
+
return false;
|
|
1552
|
+
}
|
|
1553
|
+
},
|
|
1534
1554
|
reauthorizeActiveConnection,
|
|
1535
1555
|
recordRedisAggregate(document, byteLength) {
|
|
1536
1556
|
const previous = roomResourceBudgets.get(document);
|
|
@@ -1779,6 +1799,7 @@ function createCollabHooks(deps) {
|
|
|
1779
1799
|
logger.warn("materialization failed; preserving previous html/text", { room: data.documentName });
|
|
1780
1800
|
}
|
|
1781
1801
|
const yjsState = Buffer.from(Y.encodeStateAsUpdate(data.document));
|
|
1802
|
+
const storingSnapshot = Y.snapshot(data.document);
|
|
1782
1803
|
const resourceBudgetRevision = roomResourceBudgets.get(data.document)?.revision ?? 0;
|
|
1783
1804
|
assertDocumentContentResourceLimits({
|
|
1784
1805
|
yjsState,
|
|
@@ -1873,6 +1894,7 @@ function createCollabHooks(deps) {
|
|
|
1873
1894
|
});
|
|
1874
1895
|
}
|
|
1875
1896
|
deps.onPersisted?.(data.document, yjsState, collaborationGeneration);
|
|
1897
|
+
if (materialized) data.confirmPersistence?.(storingSnapshot);
|
|
1876
1898
|
if (finalDrainAuthorized) deps.finalDrainRegistry?.complete(data.document);
|
|
1877
1899
|
return;
|
|
1878
1900
|
}
|
|
@@ -1968,6 +1990,8 @@ async function main() {
|
|
|
1968
1990
|
const finalDrainRegistry = createCollabFinalDrainRegistry();
|
|
1969
1991
|
let server = null;
|
|
1970
1992
|
let redisStoreExtension = null;
|
|
1993
|
+
const savingConnections = /* @__PURE__ */ new WeakSet();
|
|
1994
|
+
const storeConfirmations = /* @__PURE__ */ new WeakMap();
|
|
1971
1995
|
const closeRoomConnectionsForContentReset = (documentName) => {
|
|
1972
1996
|
if (server) closeCollabRoomConnectionsForContentReset(server.hocuspocus, documentName);
|
|
1973
1997
|
};
|
|
@@ -2144,9 +2168,58 @@ async function main() {
|
|
|
2144
2168
|
return await hooks.onStoreDocument({
|
|
2145
2169
|
documentName: data.documentName,
|
|
2146
2170
|
context: data.lastContext,
|
|
2147
|
-
document: data.document
|
|
2171
|
+
document: data.document,
|
|
2172
|
+
confirmPersistence: storeConfirmations.get(data)
|
|
2148
2173
|
});
|
|
2149
2174
|
},
|
|
2175
|
+
async onStateless(data) {
|
|
2176
|
+
let value;
|
|
2177
|
+
try {
|
|
2178
|
+
value = JSON.parse(data.payload);
|
|
2179
|
+
} catch {
|
|
2180
|
+
return;
|
|
2181
|
+
}
|
|
2182
|
+
const request = collabContentSaveRequestSchema.safeParse(value);
|
|
2183
|
+
if (!request.success) return;
|
|
2184
|
+
const respond = (saved) => data.connection.sendStateless(JSON.stringify({
|
|
2185
|
+
type: "documents.content.saved",
|
|
2186
|
+
requestId: request.data.requestId,
|
|
2187
|
+
saved
|
|
2188
|
+
}));
|
|
2189
|
+
if (savingConnections.has(data.connection) || !server) {
|
|
2190
|
+
respond(false);
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
savingConnections.add(data.connection);
|
|
2194
|
+
try {
|
|
2195
|
+
const runtime = server.hocuspocus;
|
|
2196
|
+
const context = data.connection.context;
|
|
2197
|
+
const saved = await hooks.saveContent({
|
|
2198
|
+
documentName: data.documentName,
|
|
2199
|
+
document: data.document,
|
|
2200
|
+
context,
|
|
2201
|
+
store: async (confirmPersistence) => {
|
|
2202
|
+
const payload = {
|
|
2203
|
+
instance: runtime,
|
|
2204
|
+
document: data.document,
|
|
2205
|
+
documentName: data.documentName,
|
|
2206
|
+
clientsCount: data.document.getConnectionsCount(),
|
|
2207
|
+
lastContext: context,
|
|
2208
|
+
lastTransactionOrigin: { source: "local", context }
|
|
2209
|
+
};
|
|
2210
|
+
storeConfirmations.set(payload, confirmPersistence);
|
|
2211
|
+
try {
|
|
2212
|
+
await runtime.storeDocumentHooks(data.document, payload, true);
|
|
2213
|
+
} finally {
|
|
2214
|
+
storeConfirmations.delete(payload);
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
});
|
|
2218
|
+
respond(saved);
|
|
2219
|
+
} finally {
|
|
2220
|
+
savingConnections.delete(data.connection);
|
|
2221
|
+
}
|
|
2222
|
+
},
|
|
2150
2223
|
async onRequest(data) {
|
|
2151
2224
|
return handleCollabServerRequest(data);
|
|
2152
2225
|
},
|