@tearleads/client-sdk 0.1.75 → 0.1.77
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/data/containers/shared/mutationAcknowledgement.d.ts +38 -0
- package/data/{containers → persistence/container-contents}/containerBinding.js +1 -1
- package/data/persistence/container-contents/containerContentsPersistence.js +2 -2
- package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerContentsPersistenceTypes.d.ts +2 -2
- package/data/persistence/container-contents/containerContentsPersistenceTypes.js.map +1 -1
- package/data/persistence/container-contents/containerDeletionPersistence.js +2 -2
- package/data/persistence/container-contents/containerDeletionPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerHydrationPersistence.js +2 -2
- package/data/persistence/container-contents/containerHydrationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js +2 -2
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerMetadataRows.js +1 -1
- package/data/persistence/container-contents/containerMetadataRows.js.map +1 -1
- package/data/persistence/container-contents/containerRebindPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerReconcilePersistence.js +2 -2
- package/data/persistence/container-contents/containerReconcilePersistence.js.map +1 -1
- package/data/persistence/container-contents/containerStructuralRepair.js +1 -1
- package/data/persistence/container-contents/containerStructuralRepair.js.map +1 -1
- package/data/persistence/container-contents/dormantMetadataSweep.js +1 -1
- package/data/persistence/container-contents/dormantMetadataSweep.js.map +1 -1
- package/data/persistence/documents/internal/containerDocumentTombstoneHolds.js +1 -1
- package/data/persistence/documents/internal/containerDocumentTombstoneHolds.js.map +1 -1
- package/data/persistence/documents/internal/containerDocumentTombstones.js +1 -1
- package/data/persistence/documents/internal/containerDocumentTombstones.js.map +1 -1
- package/data/persistence/documents/internal/discoveredDocumentPlacement.js +1 -1
- package/data/persistence/documents/internal/discoveredDocumentPlacement.js.map +1 -1
- package/data/principals/currentPolicyReferenceResolver.d.ts +3 -0
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/stores/container-contents/systemContainers/systemContainerIcon.js +1 -1
- package/stores/container-contents/systemContainers/systemContainerIcon.js.map +1 -1
- package/workflows/container-contents/container-state/create/createChild.js +1 -1
- package/workflows/container-contents/container-state/create/createChild.js.map +1 -1
- package/workflows/container-contents/container-state/purge/purgeTree.js +1 -1
- package/workflows/container-contents/container-state/purge/purgeTree.js.map +1 -1
- package/workflows/container-contents/container-state/remote.js +1 -1
- package/workflows/container-contents/container-state/remote.js.map +1 -1
- package/workflows/container-contents/container-state/share/groupGrantVerification.js +1 -1
- package/workflows/container-contents/container-state/share/groupGrantVerification.js.map +1 -1
- package/workflows/container-contents/container-state/share/groupShareEpoch.js +1 -1
- package/workflows/container-contents/container-state/share/groupShareEpoch.js.map +1 -1
- package/workflows/container-contents/container-state/types.js.map +1 -1
- package/workflows/container-contents/containerPersistence.d.ts +3 -3
- package/workflows/container-contents/containerPersistence.js +1 -1
- package/workflows/container-contents/containerPersistence.js.map +1 -1
- package/workflows/container-contents/documentLinks/documentLinkIntent.js +1 -1
- package/workflows/container-contents/documentLinks/documentLinkIntent.js.map +1 -1
- package/workflows/container-contents/documentLinks/index.js +1 -1
- package/workflows/container-contents/documentLinks/index.js.map +1 -1
- package/workflows/container-contents/documentMove/documentMoveIntent.js +1 -1
- package/workflows/container-contents/documentMove/documentMoveIntent.js.map +1 -1
- package/workflows/container-contents/documentMove/documentMoveIntentSettlement.js +2 -2
- package/workflows/container-contents/documentMove/documentMoveIntentSettlement.js.map +1 -1
- package/workflows/container-contents/documentQueries/documentSubtreeQueries.js +1 -1
- package/workflows/container-contents/documentQueries/documentSubtreeQueries.js.map +1 -1
- package/workflows/container-contents/documentQueries/index.js +3 -3
- package/workflows/container-contents/documentQueries/index.js.map +1 -1
- package/workflows/container-contents/documentQueries/pendingDownloads.js +1 -1
- package/workflows/container-contents/documentQueries/pendingDownloads.js.map +1 -1
- package/workflows/container-contents/index.d.ts +1 -1
- package/workflows/container-contents/index.js +1 -1
- package/workflows/container-contents/index.js.map +1 -1
- package/workflows/container-contents/info/blobInfo.js +1 -1
- package/workflows/container-contents/info/blobInfo.js.map +1 -1
- package/workflows/container-contents/info/containerInfo.js +2 -2
- package/workflows/container-contents/info/containerInfo.js.map +1 -1
- package/{data/containers → workflows/container-contents/metadata}/containerMetadataDocument.d.ts +1 -1
- package/{data/containers → workflows/container-contents/metadata}/containerMetadataDocument.js +2 -2
- package/workflows/container-contents/metadata/containerMetadataDocument.js.map +1 -0
- package/workflows/container-contents/metadata/metadataMutationPreparation.js +1 -1
- package/workflows/container-contents/metadata/metadataMutationPreparation.js.map +1 -1
- package/workflows/container-contents/metadata/metadataPersistence.js +1 -1
- package/workflows/container-contents/metadata/metadataPersistence.js.map +1 -1
- package/workflows/container-contents/metadata/metadataRecord.js.map +1 -1
- package/workflows/container-contents/metadata/metadataStateIsolation.js +1 -1
- package/workflows/container-contents/metadata/metadataStateIsolation.js.map +1 -1
- package/workflows/container-contents/metadata/metadataSyncSettlement.js +1 -1
- package/workflows/container-contents/metadata/metadataSyncSettlement.js.map +1 -1
- package/workflows/container-contents/metadata/metadataTypes.d.ts +2 -2
- package/workflows/container-contents/metadata/metadataTypes.js.map +1 -1
- package/workflows/container-contents/recovery/folderRecovery.js +1 -1
- package/workflows/container-contents/recovery/folderRecovery.js.map +1 -1
- package/workflows/container-contents/remoteHydration/destination/replacementBinding.js +1 -1
- package/workflows/container-contents/remoteHydration/destination/replacementBinding.js.map +1 -1
- package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js +1 -1
- package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js.map +1 -1
- package/workflows/container-contents/remoteHydration/heldContainerRebind.js +1 -1
- package/workflows/container-contents/remoteHydration/heldContainerRebind.js.map +1 -1
- package/workflows/container-contents/remoteHydration/reattachMetadata.js +1 -1
- package/workflows/container-contents/remoteHydration/reattachMetadata.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/insertRemoteContainer.js +2 -2
- package/workflows/container-contents/remoteHydration/remoteContainers/insertRemoteContainer.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/types.d.ts +1 -1
- package/workflows/container-contents/remoteHydration/types.js.map +1 -1
- package/workflows/container-contents/storedContainerState.js +1 -1
- package/workflows/container-contents/storedContainerState.js.map +1 -1
- package/workflows/containers/child/mutationSubmit.d.ts +76 -0
- package/workflows/containers/child/rekey/carriedDescendantRekeys.d.ts +70 -0
- package/workflows/containers/child/share/index.d.ts +1 -38
- package/workflows/containers/child/share/index.js +1 -205
- package/workflows/containers/child/share/index.js.map +1 -1
- package/workflows/containers/child/share/shareAncestorRepair.d.ts +37 -0
- package/workflows/containers/child/share/shareProjection.d.ts +7 -0
- package/workflows/containers/index.d.ts +3 -2
- package/workflows/containers/index.js +4 -2
- package/workflows/containers/index.js.map +1 -1
- package/workflows/organizations/currentOrganizationAuthority.d.ts +21 -0
- package/workflows/organizations/groupMetadata/groupMetadataAccess.js +1 -1
- package/workflows/organizations/groupMetadata/groupMetadataAccess.js.map +1 -1
- package/workflows/organizations/groupMetadata/groupMetadataRuntime.d.ts +30 -0
- package/workflows/{containers/child/share → organizations/groupShare}/currentShareGrantMutation.js +6 -6
- package/workflows/organizations/groupShare/currentShareGrantMutation.js.map +1 -0
- package/workflows/organizations/groupShare/currentSharePrincipalPolicy.d.ts +30 -0
- package/workflows/{containers/child/share → organizations/groupShare}/currentSharePrincipalPolicy.js +10 -10
- package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js.map +1 -0
- package/workflows/organizations/groupShare/index.d.ts +4 -0
- package/workflows/organizations/groupShare/index.js +7 -0
- package/workflows/organizations/groupShare/index.js.map +1 -0
- package/workflows/organizations/groupShare/runtimeCurrentGroupShare.d.ts +4 -0
- package/workflows/{containers/child/share → organizations/groupShare}/runtimeCurrentGroupShare.js +6 -8
- package/workflows/organizations/groupShare/runtimeCurrentGroupShare.js.map +1 -0
- package/workflows/{containers/child/share → organizations/groupShare}/sharePrincipalPolicy.d.ts +9 -9
- package/workflows/{containers/child/share → organizations/groupShare}/sharePrincipalPolicy.js +13 -13
- package/workflows/organizations/groupShare/sharePrincipalPolicy.js.map +1 -0
- package/workflows/organizations/groupShare/shareWithGroup.d.ts +44 -0
- package/workflows/organizations/groupShare/shareWithGroup.js +210 -0
- package/workflows/organizations/groupShare/shareWithGroup.js.map +1 -0
- package/workflows/organizations/index.d.ts +1 -0
- package/workflows/organizations/index.js +1 -0
- package/workflows/organizations/index.js.map +1 -1
- package/workflows/organizations/principalMutations/currentPrincipalMutationLease.d.ts +16 -0
- package/workflows/organizations/readModel/localReadModelDetails.js +1 -1
- package/workflows/organizations/readModel/localReadModelDetails.js.map +1 -1
- package/workflows/principals/runtimePolicyRecovery.d.ts +42 -0
- package/workflows/registration/bootstrapRootContainer.js +1 -1
- package/workflows/registration/bootstrapRootContainer.js.map +1 -1
- package/workflows/registration/provisioningBootstrapBuilders.js +1 -1
- package/workflows/registration/provisioningBootstrapBuilders.js.map +1 -1
- package/workflows/registration/rootMetadataBootstrap.js +1 -1
- package/workflows/registration/rootMetadataBootstrap.js.map +1 -1
- package/workflows/sync/remoteReset.js +1 -1
- package/workflows/sync/remoteReset.js.map +1 -1
- package/data/containers/containerMetadataDocument.js.map +0 -1
- package/workflows/containers/child/share/currentShareGrantMutation.js.map +0 -1
- package/workflows/containers/child/share/currentSharePrincipalPolicy.js.map +0 -1
- package/workflows/containers/child/share/runtimeCurrentGroupShare.js.map +0 -1
- package/workflows/containers/child/share/sharePrincipalPolicy.js.map +0 -1
- /package/data/{containers → persistence/container-contents}/containerBinding.d.ts +0 -0
- /package/data/{containers → persistence/container-contents}/containerBinding.js.map +0 -0
- /package/data/persistence/{containers → container-contents}/containerPersistence.d.ts +0 -0
- /package/data/persistence/{containers → container-contents}/containerPersistence.js +0 -0
- /package/data/persistence/{containers → container-contents}/containerPersistence.js.map +0 -0
- /package/data/persistence/{containers → container-contents}/containerSyncWatermarkPersistence.d.ts +0 -0
- /package/data/persistence/{containers → container-contents}/containerSyncWatermarkPersistence.js +0 -0
- /package/data/persistence/{containers → container-contents}/containerSyncWatermarkPersistence.js.map +0 -0
- /package/data/persistence/{containers → container-contents}/documentContainerProjectionPersistence.js +0 -0
- /package/data/persistence/{containers → container-contents}/documentContainerProjectionPersistence.js.map +0 -0
- /package/data/persistence/{containers → container-contents}/documentPlacement.js +0 -0
- /package/data/persistence/{containers → container-contents}/documentPlacement.js.map +0 -0
package/workflows/container-contents/remoteHydration/remoteContainers/insertRemoteContainer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertRemoteContainer.js","sourceRoot":"","sources":["insertRemoteContainer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,uDAAuD,CAAC;AAE/D,OAAO,EAAE,uCAAuC,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AAQrE,OAAO,EACL,8BAA8B,EAC9B,mCAAmC,GACpC,MAAM,6BAA6B,CAAC;AAYrC,SAAS,kCAAkC,CAAC,KAQ3C;IACC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IACtD,MAAM,UAAU,GAAG,gCAAgC,CAAC;QAClD,WAAW,EAAE,uBAAuB,CAAC,eAAe,CAAC,QAAQ,CAAC;QAC9D,GAAG;QACH,aAAa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B,EAClB,eAAe,CAAC,EAAE,EAClB,cAAc,CAAC,SAAS,CAAC,QAAQ,CAClC,CAAC;IACJ,CAAC;IACD,MAAM,gCAAgC,CAAC;QACrC,kBAAkB;QAClB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,eAAe,EAAE,cAAc;QAC/B,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;QACnD,KAAK;KACN,CAAC,CAAC;IACH,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import type { AccessManifestCheckpoint } from \"@tearleads/crypto\";\nimport {\n assertHeldContainerBinding,\n heldContainerBinding,\n} from \"../../../../data/containers/containerBinding\";\nimport {\n createContainerMetadataDocument,\n getDefaultContainerName,\n} from \"../../../../data/containers/containerMetadataDocument\";\nimport type { ContainerHydrationTombstone } from \"../../containerPersistence\";\nimport { materializeStoredContainerStateReadOnly } from \"../../storedContainerState\";\nimport { addIndexedContainerChild } from \"../lanes/childIndex\";\nimport { reattachDormantContainerMetadata } from \"../reattachMetadata\";\nimport { reconcileLocalOnlyRootContainers } from \"../reconciliation\";\nimport type {\n ContainerChildIndex,\n ContainerState,\n RemoteContainer,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport {\n applyRemoteContainerTimestamps,\n remoteContainerHydrationSaveOptions,\n} from \"./remoteContainerTimestamps\";\n\ninterface InsertRemoteContainerStateInput {\n childIdsByParentId?: ContainerChildIndex | undefined;\n host: RemoteContainerHydrationHost;\n expectedHydrationTombstone: ContainerHydrationTombstone | null;\n expectedPlacementCheckpoint?: AccessManifestCheckpoint | undefined;\n isCurrent?: (() => boolean) | undefined;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}\n\nfunction createInsertedRemoteContainerState(input: {\n doc: ContainerState[\"doc\"];\n dormantRecord: Awaited<\n ReturnType<\n RemoteContainerHydrationState[\"persistence\"][\"loadContainerMetadataRecord\"]\n >\n >;\n remoteContainer: RemoteContainer;\n}): ContainerState {\n const { doc, dormantRecord, remoteContainer } = input;\n const reattached = reattachDormantContainerMetadata({\n defaultName: getDefaultContainerName(remoteContainer.parentId),\n doc,\n dormantRecord,\n remoteMetadataDocumentId: remoteContainer.metadataDocumentId,\n });\n return {\n container: applyRemoteContainerTimestamps(\n {\n id: remoteContainer.id,\n effectiveAccessLevel: remoteContainer.effectiveAccessLevel,\n organizationId: remoteContainer.organizationId,\n parentId: remoteContainer.parentId,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n systemSlot: remoteContainer.systemSlot ?? null,\n name: reattached.name,\n icon: reattached.icon,\n },\n remoteContainer,\n ),\n metadataReferencedPrincipals: remoteContainer.metadataReferencedPrincipals,\n doc,\n record: {\n accessEpoch: remoteContainer.metadataAccessEpoch,\n accessStateHash: remoteContainer.metadataAccessStateHash,\n documentId: remoteContainer.metadataDocumentId,\n id: remoteContainer.id,\n lastCommitLsn: reattached.lastCommitLsn,\n metadataUpdates: reattached.initialSnapshot,\n ...(reattached.pullContinuation === undefined\n ? {}\n : { pullContinuation: reattached.pullContinuation }),\n ...(reattached.pullContinuationRecoveryRequired\n ? { pullContinuationRecoveryRequired: true as const }\n : {}),\n snapshotEndVersion: reattached.snapshotEndVersion,\n contentKeyBundle: null,\n documentKekTargets: null,\n documentManifestBundle: null,\n },\n };\n}\n\n/**\n * Insert a verified container the device holds no live row for, re-attaching\n * retained dormant metadata whose binding matches.\n */\nexport async function insertRemoteContainerState(\n input: InsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n const { childIdsByParentId, host, remoteContainer, state } = input;\n const execSql = state.runtime.infra.execSql;\n const persistence = state.persistence;\n const doc = await createContainerMetadataDocument(remoteContainer.id);\n if (input.isCurrent?.() === false) {\n return null;\n }\n // A container inserted with dormant retained metadata (row 4's\n // access_revoked branch) is a re-attach, not a fresh discovery: import the\n // retained content and markers instead of overwriting them with an empty\n // document. Access and keying fields still come from the remote container —\n // revocation may have rotated them.\n const dormantRecord = await persistence.loadContainerMetadataRecord(\n execSql,\n remoteContainer.id,\n );\n if (input.isCurrent?.() === false) {\n return null;\n }\n // Destination verification refused a relisting that conflicts with the\n // retained organization or metadata target. A record committed since then\n // by a concurrent hydration is refused here; commit rechecks both durably.\n assertHeldContainerBinding(\n {\n organizationId: \"\",\n metadataDocumentId: dormantRecord?.documentId ?? null,\n },\n {\n organizationId: remoteContainer.organizationId,\n metadataDocumentIds: [remoteContainer.metadataDocumentId],\n },\n );\n const containerState = createInsertedRemoteContainerState({\n doc,\n dormantRecord,\n remoteContainer,\n });\n\n const committed = await persistence.commitHydratedContainer(execSql, {\n container: containerState.container,\n expectedDormantRecord: dormantRecord,\n expectedHydrationTombstone: input.expectedHydrationTombstone,\n expectedPlacementCheckpoint: input.expectedPlacementCheckpoint,\n record: containerState.record,\n remoteUpdatedAt: remoteContainer.updatedAt,\n saveOptions: remoteContainerHydrationSaveOptions({ remoteContainer }),\n stillCurrent: input.isCurrent,\n });\n let installedState = containerState;\n if (committed.committed) {\n installedState.container = committed.container;\n } else {\n const winningStoredState = await persistence.loadContainerMetadataState(\n execSql,\n remoteContainer.id,\n );\n if (!winningStoredState) return null;\n // A concurrent hydration that won the insert holds the binding now.\n assertHeldContainerBinding(heldContainerBinding(winningStoredState), {\n organizationId: remoteContainer.organizationId,\n metadataDocumentIds: [remoteContainer.metadataDocumentId],\n });\n const winningState = await materializeStoredContainerStateReadOnly({\n storedContainer: winningStoredState,\n });\n if (\n !winningState ||\n !(await persistence.containerExists(execSql, remoteContainer.id))\n ) {\n return null;\n }\n installedState = winningState;\n installedState.metadataReferencedPrincipals =\n remoteContainer.metadataReferencedPrincipals;\n }\n if (input.isCurrent?.() === false) {\n return null;\n }\n state.containersById.set(remoteContainer.id, installedState);\n if (childIdsByParentId) {\n addIndexedContainerChild(\n childIdsByParentId,\n remoteContainer.id,\n installedState.container.parentId,\n );\n }\n await reconcileLocalOnlyRootContainers({\n childIdsByParentId,\n isCurrent: input.isCurrent,\n remoteRootState: installedState,\n requestDocumentPriming: host.requestDocumentPriming,\n state,\n });\n return installedState;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"insertRemoteContainer.js","sourceRoot":"","sources":["insertRemoteContainer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,kEAAkE,CAAC;AAE1E,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,uCAAuC,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AAQrE,OAAO,EACL,8BAA8B,EAC9B,mCAAmC,GACpC,MAAM,6BAA6B,CAAC;AAYrC,SAAS,kCAAkC,CAAC,KAQ3C;IACC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IACtD,MAAM,UAAU,GAAG,gCAAgC,CAAC;QAClD,WAAW,EAAE,uBAAuB,CAAC,eAAe,CAAC,QAAQ,CAAC;QAC9D,GAAG;QACH,aAAa;QACb,wBAAwB,EAAE,eAAe,CAAC,kBAAkB;KAC7D,CAAC,CAAC;IACH,OAAO;QACL,SAAS,EAAE,8BAA8B,CACvC;YACE,EAAE,EAAE,eAAe,CAAC,EAAE;YACtB,oBAAoB,EAAE,eAAe,CAAC,oBAAoB;YAC1D,cAAc,EAAE,eAAe,CAAC,cAAc;YAC9C,QAAQ,EAAE,eAAe,CAAC,QAAQ;YAClC,kBAAkB,EAAE,eAAe,CAAC,kBAAkB;YACtD,UAAU,EAAE,eAAe,CAAC,UAAU,IAAI,IAAI;YAC9C,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,IAAI,EAAE,UAAU,CAAC,IAAI;SACtB,EACD,eAAe,CAChB;QACD,4BAA4B,EAAE,eAAe,CAAC,4B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AoE;QACpE,0BAA0B,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,EAAE;YACnE,cAAc,EAAE,eAAe,CAAC,cAAc;YAC9C,mBAAmB,EAAE,CAAC,eAAe,CAAC,kBAAkB,CAAC;SAC1D,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,uCAAuC,CAAC;YACjE,eAAe,EAAE,kBAAkB;SACpC,CAAC,CAAC;QACH,IACE,CAAC,YAAY;YACb,CAAC,CAAC,MAAM,WAAW,CAAC,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC,EACjE,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,cAAc,GAAG,YAAY,CAAC;QAC9B,cAAc,CAAC,4BAA4B;YACzC,eAAe,CAAC,4BAA4B,CAAC;IACjD,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;IAC7D,IAAI,kBAAkB,EAAE,CAAC;QACvB,wBAAwB,CACtB,kBAAkB,EAClB,eAAe,CAAC,EAAE,EAClB,cAAc,CAAC,SAAS,CAAC,QAAQ,CAClC,CAAC;IACJ,CAAC;IACD,MAAM,gCAAgC,CAAC;QACrC,kBAAkB;QAClB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,eAAe,EAAE,cAAc;QAC/B,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;QACnD,KAAK;KACN,CAAC,CAAC;IACH,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import type { AccessManifestCheckpoint } from \"@tearleads/crypto\";\nimport {\n assertHeldContainerBinding,\n heldContainerBinding,\n} from \"../../../../data/persistence/container-contents/containerBinding\";\nimport type { ContainerHydrationTombstone } from \"../../containerPersistence\";\nimport {\n createContainerMetadataDocument,\n getDefaultContainerName,\n} from \"../../metadata/containerMetadataDocument\";\nimport { materializeStoredContainerStateReadOnly } from \"../../storedContainerState\";\nimport { addIndexedContainerChild } from \"../lanes/childIndex\";\nimport { reattachDormantContainerMetadata } from \"../reattachMetadata\";\nimport { reconcileLocalOnlyRootContainers } from \"../reconciliation\";\nimport type {\n ContainerChildIndex,\n ContainerState,\n RemoteContainer,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport {\n applyRemoteContainerTimestamps,\n remoteContainerHydrationSaveOptions,\n} from \"./remoteContainerTimestamps\";\n\ninterface InsertRemoteContainerStateInput {\n childIdsByParentId?: ContainerChildIndex | undefined;\n host: RemoteContainerHydrationHost;\n expectedHydrationTombstone: ContainerHydrationTombstone | null;\n expectedPlacementCheckpoint?: AccessManifestCheckpoint | undefined;\n isCurrent?: (() => boolean) | undefined;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}\n\nfunction createInsertedRemoteContainerState(input: {\n doc: ContainerState[\"doc\"];\n dormantRecord: Awaited<\n ReturnType<\n RemoteContainerHydrationState[\"persistence\"][\"loadContainerMetadataRecord\"]\n >\n >;\n remoteContainer: RemoteContainer;\n}): ContainerState {\n const { doc, dormantRecord, remoteContainer } = input;\n const reattached = reattachDormantContainerMetadata({\n defaultName: getDefaultContainerName(remoteContainer.parentId),\n doc,\n dormantRecord,\n remoteMetadataDocumentId: remoteContainer.metadataDocumentId,\n });\n return {\n container: applyRemoteContainerTimestamps(\n {\n id: remoteContainer.id,\n effectiveAccessLevel: remoteContainer.effectiveAccessLevel,\n organizationId: remoteContainer.organizationId,\n parentId: remoteContainer.parentId,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n systemSlot: remoteContainer.systemSlot ?? null,\n name: reattached.name,\n icon: reattached.icon,\n },\n remoteContainer,\n ),\n metadataReferencedPrincipals: remoteContainer.metadataReferencedPrincipals,\n doc,\n record: {\n accessEpoch: remoteContainer.metadataAccessEpoch,\n accessStateHash: remoteContainer.metadataAccessStateHash,\n documentId: remoteContainer.metadataDocumentId,\n id: remoteContainer.id,\n lastCommitLsn: reattached.lastCommitLsn,\n metadataUpdates: reattached.initialSnapshot,\n ...(reattached.pullContinuation === undefined\n ? {}\n : { pullContinuation: reattached.pullContinuation }),\n ...(reattached.pullContinuationRecoveryRequired\n ? { pullContinuationRecoveryRequired: true as const }\n : {}),\n snapshotEndVersion: reattached.snapshotEndVersion,\n contentKeyBundle: null,\n documentKekTargets: null,\n documentManifestBundle: null,\n },\n };\n}\n\n/**\n * Insert a verified container the device holds no live row for, re-attaching\n * retained dormant metadata whose binding matches.\n */\nexport async function insertRemoteContainerState(\n input: InsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n const { childIdsByParentId, host, remoteContainer, state } = input;\n const execSql = state.runtime.infra.execSql;\n const persistence = state.persistence;\n const doc = await createContainerMetadataDocument(remoteContainer.id);\n if (input.isCurrent?.() === false) {\n return null;\n }\n // A container inserted with dormant retained metadata (row 4's\n // access_revoked branch) is a re-attach, not a fresh discovery: import the\n // retained content and markers instead of overwriting them with an empty\n // document. Access and keying fields still come from the remote container —\n // revocation may have rotated them.\n const dormantRecord = await persistence.loadContainerMetadataRecord(\n execSql,\n remoteContainer.id,\n );\n if (input.isCurrent?.() === false) {\n return null;\n }\n // Destination verification refused a relisting that conflicts with the\n // retained organization or metadata target. A record committed since then\n // by a concurrent hydration is refused here; commit rechecks both durably.\n assertHeldContainerBinding(\n {\n organizationId: \"\",\n metadataDocumentId: dormantRecord?.documentId ?? null,\n },\n {\n organizationId: remoteContainer.organizationId,\n metadataDocumentIds: [remoteContainer.metadataDocumentId],\n },\n );\n const containerState = createInsertedRemoteContainerState({\n doc,\n dormantRecord,\n remoteContainer,\n });\n\n const committed = await persistence.commitHydratedContainer(execSql, {\n container: containerState.container,\n expectedDormantRecord: dormantRecord,\n expectedHydrationTombstone: input.expectedHydrationTombstone,\n expectedPlacementCheckpoint: input.expectedPlacementCheckpoint,\n record: containerState.record,\n remoteUpdatedAt: remoteContainer.updatedAt,\n saveOptions: remoteContainerHydrationSaveOptions({ remoteContainer }),\n stillCurrent: input.isCurrent,\n });\n let installedState = containerState;\n if (committed.committed) {\n installedState.container = committed.container;\n } else {\n const winningStoredState = await persistence.loadContainerMetadataState(\n execSql,\n remoteContainer.id,\n );\n if (!winningStoredState) return null;\n // A concurrent hydration that won the insert holds the binding now.\n assertHeldContainerBinding(heldContainerBinding(winningStoredState), {\n organizationId: remoteContainer.organizationId,\n metadataDocumentIds: [remoteContainer.metadataDocumentId],\n });\n const winningState = await materializeStoredContainerStateReadOnly({\n storedContainer: winningStoredState,\n });\n if (\n !winningState ||\n !(await persistence.containerExists(execSql, remoteContainer.id))\n ) {\n return null;\n }\n installedState = winningState;\n installedState.metadataReferencedPrincipals =\n remoteContainer.metadataReferencedPrincipals;\n }\n if (input.isCurrent?.() === false) {\n return null;\n }\n state.containersById.set(remoteContainer.id, installedState);\n if (childIdsByParentId) {\n addIndexedContainerChild(\n childIdsByParentId,\n remoteContainer.id,\n installedState.container.parentId,\n );\n }\n await reconcileLocalOnlyRootContainers({\n childIdsByParentId,\n isCurrent: input.isCurrent,\n remoteRootState: installedState,\n requestDocumentPriming: host.requestDocumentPriming,\n state,\n });\n return installedState;\n}\n"]}
|
package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { heldContainerBinding, listingRepeatsHeldOrdinaryBinding, } from "../../../../data/containers/containerBinding.js";
|
|
2
1
|
import { isKeyingVerificationError, runWithSecurityIncidentReporting, } from "../../../../data/keyingProjectionVerification/error.js";
|
|
3
2
|
import { isProjectionVerificationCancelledError } from "../../../../data/keyingProjectionVerification/types.js";
|
|
3
|
+
import { heldContainerBinding, listingRepeatsHeldOrdinaryBinding, } from "../../../../data/persistence/container-contents/containerBinding.js";
|
|
4
4
|
import { installContainerMetadataRecord } from "../../metadata/metadataPersistence.js";
|
|
5
5
|
import { projectionGeneration } from "../../projectionGeneration.js";
|
|
6
6
|
import { verifyRemoteContainerDestination } from "../destination/verifiedDestination.js";
|
package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteContainerState.js","sourceRoot":"","sources":["remoteContainerState.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,iCAAiC,GAClC,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,sCAAsC,EAAE,MAAM,qDAAqD,CAAC;AAE7G,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EACL,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,gCAAgC,EAChC,kCAAkC,GACnC,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EACL,8BAA8B,EAC9B,mCAAmC,EACnC,6CAA6C,GAC9C,MAAM,6BAA6B,CAAC;AAErC,8EAA8E;AAC9E,gFAAgF;AAChF,6EAA6E;AAC7E,sEAAsE;AACtE,4EAA4E;AAC5E,2EAA2E;AAC3E,+EAA+E;AAC/E,8CAA8C;AAC9C,qFAAqF;AACrF,4EAA4E;AAC5E,wBAAwB;AACxB,MAAM,CAAC,KAAK,UAAU,kDAAkD,CAAC,KAGxE;IACC,IAAI,KAAK,CAAC,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,OAAO,IAAI,GAAG,EAAE,CAAC;IACnB,CAA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AAa;YACb,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC;QACJ,CAAC,CAAC,0BAA0B,CAAC;YACzB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,0BAA0B,EAAE,KAAK,CAAC,0BAA0B,IAAI,IAAI;YACpE,2BAA2B;YAC3B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type { AccessManifestCheckpoint } from \"@tearleads/crypto\";\nimport {\n heldContainerBinding,\n listingRepeatsHeldOrdinaryBinding,\n} from \"../../../../data/containers/containerBinding\";\nimport {\n isKeyingVerificationError,\n runWithSecurityIncidentReporting,\n} from \"../../../../data/keyingProjectionVerification/error\";\nimport { isProjectionVerificationCancelledError } from \"../../../../data/keyingProjectionVerification/types\";\nimport type { ContainerHydrationTombstone } from \"../../containerPersistence\";\nimport { installContainerMetadataRecord } from \"../../metadata/metadataPersistence\";\nimport { projectionGeneration } from \"../../projectionGeneration\";\nimport type { PrefetchedDestinationProjection } from \"../destination/destinationPrefetch\";\nimport { verifyRemoteContainerDestination } from \"../destination/verifiedDestination\";\nimport { rebindReHomedContainer } from \"../heldContainerRebind\";\nimport {\n moveIndexedContainerChild,\n removeIndexedContainerChild,\n} from \"../lanes/childIndex\";\nimport {\n reconcileLocalOnlyRootContainers,\n reconcileLocalOnlySystemContainers,\n} from \"../reconciliation\";\nimport type {\n ContainerChildIndex,\n ContainerState,\n RemoteContainer,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport { insertRemoteContainerState } from \"./insertRemoteContainer\";\nimport {\n applyRemoteContainerTimestamps,\n remoteContainerHydrationSaveOptions,\n resolveRemoteContainerHydrationLocalUpdatedAt,\n} from \"./remoteContainerTimestamps\";\n\n// Container ids (restricted to the inbound page) that carry an unsynced local\n// create or move intent. Such a container's parent and local-edit timestamp are\n// owned by its structural-intent lane until that lane reconciles, so inbound\n// hydration must not revert parentId to the server value nor collapse\n// localUpdatedAt — doing so silently undoes a queued move and falsely reads\n// \"synced\". Move intents are read via listUnsyncedMoveIntents so a blocked\n// move — one whose destination parent has not synced yet, the common boot-time\n// case — is protected too. Pending *metadata*\n// updates are handled separately (listRemoteContainerIdsWithPendingMetadataUpdates);\n// structural intents live in the local outbox's container lanes, which that\n// query does not cover.\nexport async function listRemoteContainerIdsWithPendingStructuralIntents(input: {\n remoteContainers: ReadonlyArray<RemoteContainer>;\n state: RemoteContainerHydrationState;\n}): Promise<Set<string>> {\n if (input.remoteContainers.length === 0) {\n return new Set();\n }\n const remoteContainerIds = new Set(\n input.remoteContainers.map((remoteContainer) => remoteContainer.id),\n );\n\n const execSql = input.state.runtime.infra.execSql;\n const [pendingCreateIntents, unsyncedMoveIntents] = await Promise.all([\n input.state.persistence.listPendingCreateIntents(execSql),\n input.state.persistence.listUnsyncedMoveIntents(execSql),\n ]);\n const containerIdsWithPendingStructuralIntents = new Set<string>();\n for (const intent of pendingCreateIntents) {\n if (remoteContainerIds.has(intent.containerId)) {\n containerIdsWithPendingStructuralIntents.add(intent.containerId);\n }\n }\n for (const intent of unsyncedMoveIntents) {\n if (remoteContainerIds.has(intent.containerId)) {\n containerIdsWithPendingStructuralIntents.add(intent.containerId);\n }\n }\n return containerIdsWithPendingStructuralIntents;\n}\n\nexport async function listRemoteContainerIdsWithPendingMetadataUpdates(input: {\n remoteContainers: ReadonlyArray<RemoteContainer>;\n state: RemoteContainerHydrationState;\n}): Promise<Set<string>> {\n const containerIds = input.remoteContainers.flatMap((remoteContainer) => {\n const previousLocalUpdatedAt = input.state.containersById.get(\n remoteContainer.id,\n )?.container.localUpdatedAt;\n\n return previousLocalUpdatedAt &&\n previousLocalUpdatedAt.localeCompare(remoteContainer.updatedAt) > 0\n ? [remoteContainer.id]\n : [];\n });\n if (containerIds.length === 0) {\n return new Set();\n }\n\n const execSql = input.state.runtime.infra.execSql;\n return new Set(\n await input.state.persistence.listContainerIdsWithPendingUpdates(\n execSql,\n containerIds,\n ),\n );\n}\n\nfunction removeMissingHydratedContainer(input: {\n childIdsByParentId?: ContainerChildIndex | undefined;\n existingState: ContainerState;\n host: RemoteContainerHydrationHost;\n previousParentId: string | null;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): void {\n const { existingState, remoteContainer, state } = input;\n if (state.containersById.get(remoteContainer.id) !== existingState) {\n return;\n }\n\n state.containersById.delete(remoteContainer.id);\n if (input.childIdsByParentId) {\n removeIndexedContainerChild(\n input.childIdsByParentId,\n remoteContainer.id,\n input.previousParentId,\n );\n input.childIdsByParentId.delete(remoteContainer.id);\n }\n input.host.updateSnapshot();\n}\n\nfunction createUpdatedRemoteContainerState(\n existingState: ContainerState,\n remoteContainer: RemoteContainer,\n): ContainerState {\n return {\n ...existingState,\n container: applyRemoteContainerTimestamps(\n existingState.container,\n remoteContainer,\n ),\n containerWriterProjection: null,\n metadataReferencedPrincipals: remoteContainer.metadataReferencedPrincipals,\n };\n}\n\nfunction installUpdatedRemoteContainerState(\n existingState: ContainerState,\n nextState: ContainerState,\n host: RemoteContainerHydrationHost,\n): void {\n const wasLocalOnly = existingState.container.serverCreatedAt == null;\n existingState.container = nextState.container;\n existingState.containerWriterProjection = nextState.containerWriterProjection;\n existingState.metadataReferencedPrincipals =\n nextState.metadataReferencedPrincipals;\n // The snapshot copied the live generation when it was taken; a hint that\n // landed during the persist leaves the live metadata projection dropped.\n if (projectionGeneration(existingState) === projectionGeneration(nextState))\n existingState.metadataWriterProjection = nextState.metadataWriterProjection;\n installContainerMetadataRecord(existingState, nextState.record);\n // A document pass may have deferred while this root was awaiting proof.\n // The first durable remote acknowledgement makes its pending creates runnable.\n if (wasLocalOnly && existingState.container.serverCreatedAt != null)\n host.requestDocumentPriming?.();\n}\n\nasync function updateExistingRemoteContainerState(input: {\n childIdsByParentId?: ContainerChildIndex | undefined;\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n existingState: ContainerState;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): Promise<ContainerState | null> {\n const { childIdsByParentId, existingState, host, remoteContainer, state } =\n input;\n const previousParentId = existingState.container.parentId;\n const previousLocalUpdatedAt = existingState.container.localUpdatedAt;\n // A queued, not-yet-synced local move/create owns this container's parent\n // until its intent lane reconciles. Omit the remote parent when the page scan\n // saw one; persistence also rechecks the intent transactionally so a move\n // created after that scan wins. Both paths preserve the durable local clock.\n const hasPendingStructuralIntent =\n input.containerIdsWithPendingStructuralIntents.has(remoteContainer.id);\n const nextParentId = hasPendingStructuralIntent\n ? undefined\n : remoteContainer.parentId;\n const localUpdatedAt = resolveRemoteContainerHydrationLocalUpdatedAt({\n containerIdsWithPendingMetadataUpdates:\n input.containerIdsWithPendingMetadataUpdates,\n hasPendingStructuralIntent,\n previousLocalUpdatedAt,\n remoteContainer,\n });\n const nextState = createUpdatedRemoteContainerState(\n existingState,\n remoteContainer,\n );\n const persistenceResult = await host.persistContainerState(\n nextState,\n {\n accessEpoch: remoteContainer.metadataAccessEpoch,\n accessStateHash: remoteContainer.metadataAccessStateHash,\n documentId: remoteContainer.metadataDocumentId,\n effectiveAccessLevel: remoteContainer.effectiveAccessLevel,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n systemSlot: remoteContainer.systemSlot ?? null,\n organizationId: remoteContainer.organizationId,\n ...(nextParentId !== undefined ? { parentId: nextParentId } : {}),\n },\n false,\n remoteContainerHydrationSaveOptions({\n localUpdatedAt,\n remoteContainer,\n }),\n {\n preserveDurableStructureWhenPending: true,\n },\n );\n if (persistenceResult.status === \"missing\") {\n // Hydration persists a detached candidate so an in-flight response cannot\n // mutate mapped state before its guards settle. Retire the exact state this\n // hydration read because store-level reference cleanup cannot see the clone.\n removeMissingHydratedContainer({\n childIdsByParentId,\n existingState,\n host,\n previousParentId,\n remoteContainer,\n state,\n });\n return null;\n }\n if (persistenceResult.status !== \"persisted\") return null;\n const { record: nextRecord } = persistenceResult;\n installContainerMetadataRecord(nextState, nextRecord);\n if (input.isCurrent?.() === false) {\n return existingState;\n }\n nextState.container = {\n ...nextState.container,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n organizationId: remoteContainer.organizationId,\n parentId: nextState.container.parentId,\n };\n\n installUpdatedRemoteContainerState(existingState, nextState, host);\n moveIndexedContainerChild(\n childIdsByParentId,\n remoteContainer.id,\n previousParentId,\n existingState.container.parentId,\n );\n await reconcileLocalOnlyRootContainers({\n childIdsByParentId,\n isCurrent: input.isCurrent,\n remoteRootState: existingState,\n requestDocumentPriming: host.requestDocumentPriming,\n state,\n });\n return existingState;\n}\n\ninterface UpsertRemoteContainerStateInput {\n childIdsByParentId?: ContainerChildIndex | undefined;\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n host: RemoteContainerHydrationHost;\n expectedHydrationTombstone?: ContainerHydrationTombstone | null | undefined;\n isCurrent?: (() => boolean) | undefined;\n prefetchedProjection?: PrefetchedDestinationProjection | undefined;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}\n\nexport async function upsertRemoteContainerState(\n input: UpsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n let expectedPlacementCheckpoint: AccessManifestCheckpoint | undefined;\n const heldState = input.state.containersById.get(input.remoteContainer.id);\n const heldBinding = heldState\n ? heldContainerBinding(heldState)\n : await input.state.persistence.loadHeldContainerBinding(\n input.state.runtime.infra.execSql,\n input.remoteContainer.id,\n );\n const listed = input.remoteContainer;\n // A folder re-homed away from the listed organization never returns there,\n // whatever binding (possibly none, after a reset) the device holds now.\n const supersededListing =\n !listingRepeatsHeldOrdinaryBinding(heldBinding, listed) &&\n (await input.state.persistence.isSupersededContainerBinding(\n input.state.runtime.infra.execSql,\n { containerId: listed.id, organizationId: listed.organizationId },\n ));\n if (input.isCurrent?.() === false) return null;\n const verified = await verifyRemoteContainerDestination({\n ...input,\n heldBinding,\n supersededListing,\n refresh: !!input.expectedHydrationTombstone,\n onVerifiedCheckpoint: (checkpoint) => {\n expectedPlacementCheckpoint = checkpoint;\n },\n });\n if (!verified || input.isCurrent?.() === false) return null;\n input = { ...input, remoteContainer: verified };\n const existingState = input.state.containersById.get(\n input.remoteContainer.id,\n );\n const remoteState = await runWithSecurityIncidentReporting(\n input.state.runtime.util.reportSecurityIncident,\n {\n objectId: verified.id,\n objectKind: \"container\",\n operation: \"container.binding.persist\",\n organizationId: verified.organizationId,\n },\n async () =>\n (await rebindReHomedContainer({\n existingState,\n heldBinding,\n isCurrent: input.isCurrent,\n state: input.state,\n verified,\n }))\n ? persistVerifiedRemoteContainer({\n ...input,\n existingState,\n expectedPlacementCheckpoint,\n })\n : null,\n );\n if (!remoteState) {\n return null;\n }\n await reconcileLocalOnlySystemContainers({\n childIdsByParentId: input.childIdsByParentId,\n isCurrent: input.isCurrent,\n requestDocumentPriming: input.host.requestDocumentPriming,\n remoteSystemState: remoteState,\n state: input.state,\n });\n return remoteState;\n}\n\n/**\n * Upsert one listed folder, isolating a rejected proof or binding. The refusal\n * was already reported; returning no state leaves the item unapplied without\n * blocking independent folders.\n */\nexport async function upsertIsolatedRemoteContainerState(\n input: UpsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n try {\n return await upsertRemoteContainerState(input);\n } catch (error) {\n if (\n !isKeyingVerificationError(error) &&\n !isProjectionVerificationCancelledError(error)\n )\n throw error;\n return null;\n }\n}\n\nfunction persistVerifiedRemoteContainer(\n input: UpsertRemoteContainerStateInput & {\n existingState: ContainerState | undefined;\n expectedPlacementCheckpoint: AccessManifestCheckpoint | undefined;\n },\n): Promise<ContainerState | null> {\n const { existingState, expectedPlacementCheckpoint } = input;\n return existingState\n ? updateExistingRemoteContainerState({\n childIdsByParentId: input.childIdsByParentId,\n containerIdsWithPendingMetadataUpdates:\n input.containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents:\n input.containerIdsWithPendingStructuralIntents,\n existingState,\n host: input.host,\n isCurrent: input.isCurrent,\n remoteContainer: input.remoteContainer,\n state: input.state,\n })\n : insertRemoteContainerState({\n childIdsByParentId: input.childIdsByParentId,\n host: input.host,\n expectedHydrationTombstone: input.expectedHydrationTombstone ?? null,\n expectedPlacementCheckpoint,\n isCurrent: input.isCurrent,\n remoteContainer: input.remoteContainer,\n state: input.state,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"remoteContainerState.js","sourceRoot":"","sources":["remoteContainerState.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,sCAAsC,EAAE,MAAM,qDAAqD,CAAC;AAC7G,OAAO,EACL,oBAAoB,EACpB,iCAAiC,GAClC,MAAM,kEAAkE,CAAC;AAE1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EACL,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,gCAAgC,EAChC,kCAAkC,GACnC,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EACL,8BAA8B,EAC9B,mCAAmC,EACnC,6CAA6C,GAC9C,MAAM,6BAA6B,CAA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,KAAK,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,8BAA8B,CACrC,KAGC;IAED,MAAM,EAAE,aAAa,EAAE,2BAA2B,EAAE,GAAG,KAAK,CAAC;IAC7D,OAAO,aAAa;QAClB,CAAC,CAAC,kCAAkC,CAAC;YACjC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,sCAAsC,EACpC,KAAK,CAAC,sCAAsC;YAC9C,wCAAwC,EACtC,KAAK,CAAC,wCAAwC;YAChD,aAAa;YACb,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC;QACJ,CAAC,CAAC,0BAA0B,CAAC;YACzB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,0BAA0B,EAAE,KAAK,CAAC,0BAA0B,IAAI,IAAI;YACpE,2BAA2B;YAC3B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type { AccessManifestCheckpoint } from \"@tearleads/crypto\";\nimport {\n isKeyingVerificationError,\n runWithSecurityIncidentReporting,\n} from \"../../../../data/keyingProjectionVerification/error\";\nimport { isProjectionVerificationCancelledError } from \"../../../../data/keyingProjectionVerification/types\";\nimport {\n heldContainerBinding,\n listingRepeatsHeldOrdinaryBinding,\n} from \"../../../../data/persistence/container-contents/containerBinding\";\nimport type { ContainerHydrationTombstone } from \"../../containerPersistence\";\nimport { installContainerMetadataRecord } from \"../../metadata/metadataPersistence\";\nimport { projectionGeneration } from \"../../projectionGeneration\";\nimport type { PrefetchedDestinationProjection } from \"../destination/destinationPrefetch\";\nimport { verifyRemoteContainerDestination } from \"../destination/verifiedDestination\";\nimport { rebindReHomedContainer } from \"../heldContainerRebind\";\nimport {\n moveIndexedContainerChild,\n removeIndexedContainerChild,\n} from \"../lanes/childIndex\";\nimport {\n reconcileLocalOnlyRootContainers,\n reconcileLocalOnlySystemContainers,\n} from \"../reconciliation\";\nimport type {\n ContainerChildIndex,\n ContainerState,\n RemoteContainer,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport { insertRemoteContainerState } from \"./insertRemoteContainer\";\nimport {\n applyRemoteContainerTimestamps,\n remoteContainerHydrationSaveOptions,\n resolveRemoteContainerHydrationLocalUpdatedAt,\n} from \"./remoteContainerTimestamps\";\n\n// Container ids (restricted to the inbound page) that carry an unsynced local\n// create or move intent. Such a container's parent and local-edit timestamp are\n// owned by its structural-intent lane until that lane reconciles, so inbound\n// hydration must not revert parentId to the server value nor collapse\n// localUpdatedAt — doing so silently undoes a queued move and falsely reads\n// \"synced\". Move intents are read via listUnsyncedMoveIntents so a blocked\n// move — one whose destination parent has not synced yet, the common boot-time\n// case — is protected too. Pending *metadata*\n// updates are handled separately (listRemoteContainerIdsWithPendingMetadataUpdates);\n// structural intents live in the local outbox's container lanes, which that\n// query does not cover.\nexport async function listRemoteContainerIdsWithPendingStructuralIntents(input: {\n remoteContainers: ReadonlyArray<RemoteContainer>;\n state: RemoteContainerHydrationState;\n}): Promise<Set<string>> {\n if (input.remoteContainers.length === 0) {\n return new Set();\n }\n const remoteContainerIds = new Set(\n input.remoteContainers.map((remoteContainer) => remoteContainer.id),\n );\n\n const execSql = input.state.runtime.infra.execSql;\n const [pendingCreateIntents, unsyncedMoveIntents] = await Promise.all([\n input.state.persistence.listPendingCreateIntents(execSql),\n input.state.persistence.listUnsyncedMoveIntents(execSql),\n ]);\n const containerIdsWithPendingStructuralIntents = new Set<string>();\n for (const intent of pendingCreateIntents) {\n if (remoteContainerIds.has(intent.containerId)) {\n containerIdsWithPendingStructuralIntents.add(intent.containerId);\n }\n }\n for (const intent of unsyncedMoveIntents) {\n if (remoteContainerIds.has(intent.containerId)) {\n containerIdsWithPendingStructuralIntents.add(intent.containerId);\n }\n }\n return containerIdsWithPendingStructuralIntents;\n}\n\nexport async function listRemoteContainerIdsWithPendingMetadataUpdates(input: {\n remoteContainers: ReadonlyArray<RemoteContainer>;\n state: RemoteContainerHydrationState;\n}): Promise<Set<string>> {\n const containerIds = input.remoteContainers.flatMap((remoteContainer) => {\n const previousLocalUpdatedAt = input.state.containersById.get(\n remoteContainer.id,\n )?.container.localUpdatedAt;\n\n return previousLocalUpdatedAt &&\n previousLocalUpdatedAt.localeCompare(remoteContainer.updatedAt) > 0\n ? [remoteContainer.id]\n : [];\n });\n if (containerIds.length === 0) {\n return new Set();\n }\n\n const execSql = input.state.runtime.infra.execSql;\n return new Set(\n await input.state.persistence.listContainerIdsWithPendingUpdates(\n execSql,\n containerIds,\n ),\n );\n}\n\nfunction removeMissingHydratedContainer(input: {\n childIdsByParentId?: ContainerChildIndex | undefined;\n existingState: ContainerState;\n host: RemoteContainerHydrationHost;\n previousParentId: string | null;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): void {\n const { existingState, remoteContainer, state } = input;\n if (state.containersById.get(remoteContainer.id) !== existingState) {\n return;\n }\n\n state.containersById.delete(remoteContainer.id);\n if (input.childIdsByParentId) {\n removeIndexedContainerChild(\n input.childIdsByParentId,\n remoteContainer.id,\n input.previousParentId,\n );\n input.childIdsByParentId.delete(remoteContainer.id);\n }\n input.host.updateSnapshot();\n}\n\nfunction createUpdatedRemoteContainerState(\n existingState: ContainerState,\n remoteContainer: RemoteContainer,\n): ContainerState {\n return {\n ...existingState,\n container: applyRemoteContainerTimestamps(\n existingState.container,\n remoteContainer,\n ),\n containerWriterProjection: null,\n metadataReferencedPrincipals: remoteContainer.metadataReferencedPrincipals,\n };\n}\n\nfunction installUpdatedRemoteContainerState(\n existingState: ContainerState,\n nextState: ContainerState,\n host: RemoteContainerHydrationHost,\n): void {\n const wasLocalOnly = existingState.container.serverCreatedAt == null;\n existingState.container = nextState.container;\n existingState.containerWriterProjection = nextState.containerWriterProjection;\n existingState.metadataReferencedPrincipals =\n nextState.metadataReferencedPrincipals;\n // The snapshot copied the live generation when it was taken; a hint that\n // landed during the persist leaves the live metadata projection dropped.\n if (projectionGeneration(existingState) === projectionGeneration(nextState))\n existingState.metadataWriterProjection = nextState.metadataWriterProjection;\n installContainerMetadataRecord(existingState, nextState.record);\n // A document pass may have deferred while this root was awaiting proof.\n // The first durable remote acknowledgement makes its pending creates runnable.\n if (wasLocalOnly && existingState.container.serverCreatedAt != null)\n host.requestDocumentPriming?.();\n}\n\nasync function updateExistingRemoteContainerState(input: {\n childIdsByParentId?: ContainerChildIndex | undefined;\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n existingState: ContainerState;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}): Promise<ContainerState | null> {\n const { childIdsByParentId, existingState, host, remoteContainer, state } =\n input;\n const previousParentId = existingState.container.parentId;\n const previousLocalUpdatedAt = existingState.container.localUpdatedAt;\n // A queued, not-yet-synced local move/create owns this container's parent\n // until its intent lane reconciles. Omit the remote parent when the page scan\n // saw one; persistence also rechecks the intent transactionally so a move\n // created after that scan wins. Both paths preserve the durable local clock.\n const hasPendingStructuralIntent =\n input.containerIdsWithPendingStructuralIntents.has(remoteContainer.id);\n const nextParentId = hasPendingStructuralIntent\n ? undefined\n : remoteContainer.parentId;\n const localUpdatedAt = resolveRemoteContainerHydrationLocalUpdatedAt({\n containerIdsWithPendingMetadataUpdates:\n input.containerIdsWithPendingMetadataUpdates,\n hasPendingStructuralIntent,\n previousLocalUpdatedAt,\n remoteContainer,\n });\n const nextState = createUpdatedRemoteContainerState(\n existingState,\n remoteContainer,\n );\n const persistenceResult = await host.persistContainerState(\n nextState,\n {\n accessEpoch: remoteContainer.metadataAccessEpoch,\n accessStateHash: remoteContainer.metadataAccessStateHash,\n documentId: remoteContainer.metadataDocumentId,\n effectiveAccessLevel: remoteContainer.effectiveAccessLevel,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n systemSlot: remoteContainer.systemSlot ?? null,\n organizationId: remoteContainer.organizationId,\n ...(nextParentId !== undefined ? { parentId: nextParentId } : {}),\n },\n false,\n remoteContainerHydrationSaveOptions({\n localUpdatedAt,\n remoteContainer,\n }),\n {\n preserveDurableStructureWhenPending: true,\n },\n );\n if (persistenceResult.status === \"missing\") {\n // Hydration persists a detached candidate so an in-flight response cannot\n // mutate mapped state before its guards settle. Retire the exact state this\n // hydration read because store-level reference cleanup cannot see the clone.\n removeMissingHydratedContainer({\n childIdsByParentId,\n existingState,\n host,\n previousParentId,\n remoteContainer,\n state,\n });\n return null;\n }\n if (persistenceResult.status !== \"persisted\") return null;\n const { record: nextRecord } = persistenceResult;\n installContainerMetadataRecord(nextState, nextRecord);\n if (input.isCurrent?.() === false) {\n return existingState;\n }\n nextState.container = {\n ...nextState.container,\n metadataDocumentId: remoteContainer.metadataDocumentId,\n organizationId: remoteContainer.organizationId,\n parentId: nextState.container.parentId,\n };\n\n installUpdatedRemoteContainerState(existingState, nextState, host);\n moveIndexedContainerChild(\n childIdsByParentId,\n remoteContainer.id,\n previousParentId,\n existingState.container.parentId,\n );\n await reconcileLocalOnlyRootContainers({\n childIdsByParentId,\n isCurrent: input.isCurrent,\n remoteRootState: existingState,\n requestDocumentPriming: host.requestDocumentPriming,\n state,\n });\n return existingState;\n}\n\ninterface UpsertRemoteContainerStateInput {\n childIdsByParentId?: ContainerChildIndex | undefined;\n containerIdsWithPendingMetadataUpdates: ReadonlySet<string>;\n containerIdsWithPendingStructuralIntents: ReadonlySet<string>;\n host: RemoteContainerHydrationHost;\n expectedHydrationTombstone?: ContainerHydrationTombstone | null | undefined;\n isCurrent?: (() => boolean) | undefined;\n prefetchedProjection?: PrefetchedDestinationProjection | undefined;\n remoteContainer: RemoteContainer;\n state: RemoteContainerHydrationState;\n}\n\nexport async function upsertRemoteContainerState(\n input: UpsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n let expectedPlacementCheckpoint: AccessManifestCheckpoint | undefined;\n const heldState = input.state.containersById.get(input.remoteContainer.id);\n const heldBinding = heldState\n ? heldContainerBinding(heldState)\n : await input.state.persistence.loadHeldContainerBinding(\n input.state.runtime.infra.execSql,\n input.remoteContainer.id,\n );\n const listed = input.remoteContainer;\n // A folder re-homed away from the listed organization never returns there,\n // whatever binding (possibly none, after a reset) the device holds now.\n const supersededListing =\n !listingRepeatsHeldOrdinaryBinding(heldBinding, listed) &&\n (await input.state.persistence.isSupersededContainerBinding(\n input.state.runtime.infra.execSql,\n { containerId: listed.id, organizationId: listed.organizationId },\n ));\n if (input.isCurrent?.() === false) return null;\n const verified = await verifyRemoteContainerDestination({\n ...input,\n heldBinding,\n supersededListing,\n refresh: !!input.expectedHydrationTombstone,\n onVerifiedCheckpoint: (checkpoint) => {\n expectedPlacementCheckpoint = checkpoint;\n },\n });\n if (!verified || input.isCurrent?.() === false) return null;\n input = { ...input, remoteContainer: verified };\n const existingState = input.state.containersById.get(\n input.remoteContainer.id,\n );\n const remoteState = await runWithSecurityIncidentReporting(\n input.state.runtime.util.reportSecurityIncident,\n {\n objectId: verified.id,\n objectKind: \"container\",\n operation: \"container.binding.persist\",\n organizationId: verified.organizationId,\n },\n async () =>\n (await rebindReHomedContainer({\n existingState,\n heldBinding,\n isCurrent: input.isCurrent,\n state: input.state,\n verified,\n }))\n ? persistVerifiedRemoteContainer({\n ...input,\n existingState,\n expectedPlacementCheckpoint,\n })\n : null,\n );\n if (!remoteState) {\n return null;\n }\n await reconcileLocalOnlySystemContainers({\n childIdsByParentId: input.childIdsByParentId,\n isCurrent: input.isCurrent,\n requestDocumentPriming: input.host.requestDocumentPriming,\n remoteSystemState: remoteState,\n state: input.state,\n });\n return remoteState;\n}\n\n/**\n * Upsert one listed folder, isolating a rejected proof or binding. The refusal\n * was already reported; returning no state leaves the item unapplied without\n * blocking independent folders.\n */\nexport async function upsertIsolatedRemoteContainerState(\n input: UpsertRemoteContainerStateInput,\n): Promise<ContainerState | null> {\n try {\n return await upsertRemoteContainerState(input);\n } catch (error) {\n if (\n !isKeyingVerificationError(error) &&\n !isProjectionVerificationCancelledError(error)\n )\n throw error;\n return null;\n }\n}\n\nfunction persistVerifiedRemoteContainer(\n input: UpsertRemoteContainerStateInput & {\n existingState: ContainerState | undefined;\n expectedPlacementCheckpoint: AccessManifestCheckpoint | undefined;\n },\n): Promise<ContainerState | null> {\n const { existingState, expectedPlacementCheckpoint } = input;\n return existingState\n ? updateExistingRemoteContainerState({\n childIdsByParentId: input.childIdsByParentId,\n containerIdsWithPendingMetadataUpdates:\n input.containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents:\n input.containerIdsWithPendingStructuralIntents,\n existingState,\n host: input.host,\n isCurrent: input.isCurrent,\n remoteContainer: input.remoteContainer,\n state: input.state,\n })\n : insertRemoteContainerState({\n childIdsByParentId: input.childIdsByParentId,\n host: input.host,\n expectedHydrationTombstone: input.expectedHydrationTombstone ?? null,\n expectedPlacementCheckpoint,\n isCurrent: input.isCurrent,\n remoteContainer: input.remoteContainer,\n state: input.state,\n });\n}\n"]}
|
|
@@ -2,11 +2,11 @@ import type { RequestResult } from "../../../internal/api-client/index.js";
|
|
|
2
2
|
import type { ContainerReplacementAuthorizationsResponse } from "../../../internal/validators/operation/index.js";
|
|
3
3
|
import type { ListContainerParentLanesRequest } from "../../../internal/validators/request/index.js";
|
|
4
4
|
import type { ContainerSummary, ContainerWriterProjectionResponse, DocumentWriterProjectionResponse, ListContainerParentLanesResponse, ListContainersResponse, ReferencedPrincipalStateResponse } from "../../../internal/validators/response/index.js";
|
|
5
|
-
import type { createContainerMetadataDocument } from "../../../data/containers/containerMetadataDocument.js";
|
|
6
5
|
import type { CurrentPrincipalPolicyReader } from "../../principals/currentPrincipalPolicyReader.js";
|
|
7
6
|
import type { PrincipalPolicyHistoryReader } from "../../principals/principalPolicyHistoryReader.js";
|
|
8
7
|
import type { ContainerContentsPersistence, ContainerDocumentRecord, ContainerHydrationTombstone, ContainerRecord, createContainerParentSyncLane } from "../containerPersistence.js";
|
|
9
8
|
import type { ContainerMetadataPatch } from "../metadata/index.js";
|
|
9
|
+
import type { createContainerMetadataDocument } from "../metadata/containerMetadataDocument.js";
|
|
10
10
|
import type { ContainerContentsWorkflowRuntime } from "../runtime.js";
|
|
11
11
|
export type ListedRemoteContainerPageItem = ListContainersResponse["items"][number];
|
|
12
12
|
export type ContainerChildIndex = Map<string, Set<string>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type { RequestResult } from \"@tearleads/api-client\";\nimport type { ContainerReplacementAuthorizationsResponse } from \"@tearleads/validators/operation\";\nimport type { ListContainerParentLanesRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerSummary,\n ContainerWriterProjectionResponse,\n DocumentWriterProjectionResponse,\n ListContainerParentLanesResponse,\n ListContainersResponse,\n ReferencedPrincipalStateResponse,\n} from \"@tearleads/validators/response\";\nimport type {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type { RequestResult } from \"@tearleads/api-client\";\nimport type { ContainerReplacementAuthorizationsResponse } from \"@tearleads/validators/operation\";\nimport type { ListContainerParentLanesRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerSummary,\n ContainerWriterProjectionResponse,\n DocumentWriterProjectionResponse,\n ListContainerParentLanesResponse,\n ListContainersResponse,\n ReferencedPrincipalStateResponse,\n} from \"@tearleads/validators/response\";\nimport type { CurrentPrincipalPolicyReader } from \"../../principals/currentPrincipalPolicyReader\";\nimport type { PrincipalPolicyHistoryReader } from \"../../principals/principalPolicyHistoryReader\";\nimport type {\n ContainerContentsPersistence,\n ContainerDocumentRecord,\n ContainerHydrationTombstone,\n ContainerRecord,\n createContainerParentSyncLane,\n} from \"../containerPersistence\";\nimport type { ContainerMetadataPatch } from \"../metadata\";\nimport type { createContainerMetadataDocument } from \"../metadata/containerMetadataDocument\";\nimport type { ContainerContentsWorkflowRuntime } from \"../runtime\";\n\nexport type ListedRemoteContainerPageItem =\n ListContainersResponse[\"items\"][number];\nexport type ContainerChildIndex = Map<string, Set<string>>;\nexport type QueueContainerParentLane = (parentId: string | null) => void;\nexport type RemoteContainerIngestQueue = Map<string, RemoteContainer>;\nexport type SaveContainerOptions = Parameters<\n ContainerContentsPersistence[\"saveContainer\"]\n>[3];\n\nexport type ContainerMetadataDocumentState = Awaited<\n ReturnType<typeof createContainerMetadataDocument>\n>;\nexport type RemoteContainer = Pick<\n ContainerSummary,\n | \"createdAt\"\n | \"effectiveAccessLevel\"\n | \"systemSlot\"\n | \"id\"\n | \"metadataAccessEpoch\"\n | \"metadataAccessStateHash\"\n | \"metadataDocumentId\"\n | \"metadataReferencedPrincipals\"\n | \"organizationId\"\n | \"parentId\"\n | \"updatedAt\"\n>;\n\nexport interface ContainerState {\n containerWriterProjection?:\n | ContainerWriterProjectionResponse\n | null\n | undefined;\n /**\n * Bumped whenever a realtime hint drops this container's cached writer\n * projections (container and metadata document alike); an operation that\n * fetched or carried a projection installs it only if this is unchanged\n * since it started, so a pre-hint answer never lands after the hint.\n */\n writerProjectionGeneration?: number | undefined;\n metadataReferencedPrincipals?:\n | readonly ReferencedPrincipalStateResponse[]\n | undefined;\n container: ContainerRecord;\n doc: ContainerMetadataDocumentState;\n metadataWriterProjection?:\n | DocumentWriterProjectionResponse\n | null\n | undefined;\n /** Durable pull progress mirrored from the metadata document record. */\n pullContinuation?: ContainerDocumentRecord[\"pullContinuation\"] | undefined;\n record: ContainerDocumentRecord;\n}\n\ninterface RemoteContainerHydrationApi\n extends Partial<PrincipalPolicyHistoryReader>,\n CurrentPrincipalPolicyReader {\n getContainerReplacementAuthorizationsResult(\n containerId: string,\n replacesOrganizationId: string,\n ): Promise<RequestResult<ContainerReplacementAuthorizationsResponse>>;\n evictContainerWriterProjection(containerId: string): void;\n getContainerWriterProjection(\n containerId: string,\n ): Promise<ContainerWriterProjectionResponse | null>;\n listContainerParentLanes(\n input: ListContainerParentLanesRequest,\n ): Promise<ListContainerParentLanesResponse | null>;\n}\n\ninterface RemoteContainerHydrationRuntime\n extends Pick<\n ContainerContentsWorkflowRuntime,\n | \"auth\"\n | \"adoptRootContainer\"\n | \"crypto\"\n | \"infra\"\n | \"resolveTrustedUserIdentity\"\n | \"state\"\n | \"util\"\n > {\n apiClient: RemoteContainerHydrationApi;\n}\n\nexport interface RemoteContainerHydrationState {\n containersById: Map<string, ContainerState>;\n lifecycleGeneration?: number | undefined;\n persistence: ContainerContentsPersistence;\n rootLaneHydrated?: boolean | undefined;\n runtime: RemoteContainerHydrationRuntime;\n structuralGeneration?: number | undefined;\n}\n\nexport type PersistContainerStateResult =\n | { status: \"identity-superseded\"; record: ContainerDocumentRecord }\n | { status: \"missing\" }\n | {\n status: \"persisted\";\n record: ContainerDocumentRecord;\n createIntentSettled?: true | undefined;\n moveIntentSettled?: true | undefined;\n }\n | { status: \"stale-generation\" };\n\nexport interface RemoteContainerHydrationHost {\n persistContainerState: (\n containerState: ContainerState,\n patch?: Partial<ContainerMetadataPatch>,\n updateView?: boolean,\n saveOptions?: SaveContainerOptions,\n mutationOptions?: {\n /** Queued metadata rows the server committed, settled in this write. */\n acceptedPendingUpdateIds?: readonly string[] | undefined;\n clearSyncFailure?: boolean | undefined;\n expectedStateWhenMissing?: ContainerState | undefined;\n isCurrent?: (() => boolean) | undefined;\n createIntentSettlement?: Parameters<\n ContainerContentsPersistence[\"commitMetadataMutation\"]\n >[1][\"createIntentSettlement\"];\n moveIntentSettlement?: Parameters<\n ContainerContentsPersistence[\"commitMetadataMutation\"]\n >[1][\"moveIntentSettlement\"];\n preserveDurableStructureWhenPending?: boolean | undefined;\n },\n ) => Promise<PersistContainerStateResult>;\n requestDocumentPriming?: (() => void) | undefined;\n updateSnapshot: () => void;\n}\n\nexport interface ContainerParentHydrationLane {\n parentId: string | null;\n watermark?: ListContainersResponse[\"nextWatermark\"];\n}\n\nexport interface ExpectedContainerState {\n container: ContainerRecord;\n fingerprint: string;\n}\n\nexport interface FetchedContainerParentLanePage {\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n expectedHydrationTombstones: ReadonlyMap<string, ContainerHydrationTombstone>;\n lane: ContainerParentHydrationLane;\n response: ListContainersResponse;\n syncLane: ReturnType<typeof createContainerParentSyncLane>;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { base64ToBytes, bytesToBase64 } from "../../internal/encoding/index.js";
|
|
2
2
|
import { exportAllUpdates, importUpdates } from "../../internal/loro/index.js";
|
|
3
|
-
import { createContainerMetadataDocument, getDefaultContainerName, readContainerMetadataValue, writeContainerMetadataValue, } from "../../data/containers/containerMetadataDocument.js";
|
|
4
3
|
import { enqueuePendingContainerUpdate, } from "./containerPersistence.js";
|
|
4
|
+
import { createContainerMetadataDocument, getDefaultContainerName, readContainerMetadataValue, writeContainerMetadataValue, } from "./metadata/containerMetadataDocument.js";
|
|
5
5
|
function createInitialContainerRecord(input) {
|
|
6
6
|
return {
|
|
7
7
|
accessEpoch: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storedContainerState.js","sourceRoot":"","sources":["storedContainerState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"storedContainerState.js","sourceRoot":"","sources":["storedContainerState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,gBAAgB,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aAAa;aACtB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAC/D,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,uCAAuC,CAAC,KAE7D;IACC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,eAAe,CAAC;IACpD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,GAAG,GAAG,MAAM,+BAA+B,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAChE,IAAI,aAAa,GAAG,SAAS,CAAC;IAC9B,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;QAC3B,aAAa,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,QAAQ,GAAG,0BAA0B,CACzC,GAAG,EACH,uBAAuB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAC5C,CAAC;QACF,aAAa,GAAG,EAAE,GAAG,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7E,CAAC;SAAM,CAAC;QACN,2BAA2B,CAAC,GAAG,EAAE;YAC/B,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,IAAI,EAAE,SAAS,CAAC,IAAI;SACrB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACnD,CAAC","sourcesContent":["import { base64ToBytes, bytesToBase64 } from \"@tearleads/encoding\";\nimport { exportAllUpdates, importUpdates } from \"@tearleads/loro\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport {\n type ContainerContentsPersistence,\n type ContainerMetadataRecord,\n enqueuePendingContainerUpdate,\n type StoredContainerState,\n} from \"./containerPersistence\";\nimport {\n createContainerMetadataDocument,\n getDefaultContainerName,\n readContainerMetadataValue,\n writeContainerMetadataValue,\n} from \"./metadata/containerMetadataDocument\";\nimport type { ContainerState } from \"./remoteHydration/types\";\n\ntype SaveContainerOptions = Parameters<\n ContainerContentsPersistence[\"saveContainer\"]\n>[3];\n\nfunction createInitialContainerRecord(input: {\n container: StoredContainerState[\"container\"];\n metadataUpdates: string;\n}): ContainerMetadataRecord {\n return {\n accessEpoch: 1,\n accessStateHash: null,\n contentKeyBundle: null,\n documentId: input.container.metadataDocumentId,\n documentKekTargets: null,\n documentManifestBundle: null,\n id: input.container.id,\n lastCommitLsn: null,\n metadataUpdates: input.metadataUpdates,\n snapshotEndVersion: \"\",\n };\n}\n\nfunction metadataProjectionChanged(\n left: StoredContainerState[\"container\"],\n right: StoredContainerState[\"container\"],\n): boolean {\n return left.icon !== right.icon || left.name !== right.name;\n}\n\nfunction replaySaveOptions(\n container: StoredContainerState[\"container\"],\n): SaveContainerOptions {\n const localUpdatedAt =\n container.localUpdatedAt ?? container.updatedAt ?? null;\n return localUpdatedAt ? { localUpdatedAt } : undefined;\n}\n\nexport async function hydrateStoredContainerState(input: {\n execSql: ExecSql;\n persistence: ContainerContentsPersistence;\n storedContainer: StoredContainerState;\n}): Promise<ContainerState> {\n const { execSql, persistence, storedContainer } = input;\n const { container } = storedContainer;\n const doc = await createContainerMetadataDocument(container.id);\n let nextContainer = container;\n let nextRecord = storedContainer.record;\n\n if (nextRecord?.metadataUpdates) {\n importUpdates(doc, [base64ToBytes(nextRecord.metadataUpdates)]);\n const metadata = readContainerMetadataValue(\n doc,\n getDefaultContainerName(container.parentId),\n );\n nextContainer = {\n ...container,\n icon: metadata.icon,\n name: metadata.name,\n };\n if (metadataProjectionChanged(container, nextContainer)) {\n await persistence.saveContainer(\n execSql,\n nextContainer,\n nextRecord,\n replaySaveOptions(container),\n );\n }\n } else {\n writeContainerMetadataValue(doc, {\n icon: container.icon,\n name: container.name,\n });\n const initialUpdate = exportAllUpdates(doc);\n nextRecord = createInitialContainerRecord({\n container,\n metadataUpdates: bytesToBase64(initialUpdate),\n });\n await persistence.saveContainer(execSql, nextContainer, nextRecord);\n\n // A device-first child's first metadata waits for its create. A root's\n // never does: only registration creates a root remotely, and provisioning\n // commits the root's metadata itself, so a queued copy would only be\n // replayed after login as duplicate ops.\n if (!container.metadataDocumentId && container.parentId !== null) {\n await enqueuePendingContainerUpdate(execSql, persistence, {\n containerId: container.id,\n update: initialUpdate,\n });\n }\n }\n\n return { container: nextContainer, doc, record: nextRecord };\n}\n\n/** Materialize a CAS winner without writing repair rows from a stale caller. */\nexport async function materializeStoredContainerStateReadOnly(input: {\n storedContainer: StoredContainerState;\n}): Promise<ContainerState | null> {\n const { container, record } = input.storedContainer;\n if (!record) return null;\n const doc = await createContainerMetadataDocument(container.id);\n let nextContainer = container;\n if (record.metadataUpdates) {\n importUpdates(doc, [base64ToBytes(record.metadataUpdates)]);\n const metadata = readContainerMetadataValue(\n doc,\n getDefaultContainerName(container.parentId),\n );\n nextContainer = { ...container, icon: metadata.icon, name: metadata.name };\n } else {\n writeContainerMetadataValue(doc, {\n icon: container.icon,\n name: container.name,\n });\n }\n return { container: nextContainer, doc, record };\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ContainerMutationRequest } from "../../../internal/validators/request/index.js";
|
|
2
|
+
import { type ContainerRotationResponse } from "../../../internal/validators/response/index.js";
|
|
3
|
+
import { acknowledgeContainerMutation } from "../../../data/containers/shared/mutationAcknowledgement.js";
|
|
4
|
+
import type { ContainerReciteApi } from "../../../data/containers/shared/reciteApi.js";
|
|
5
|
+
import type { ContainerMutationAuthor, ContainerRotationResult, MaterializedContainerRekeyPlan } from "../../../data/containers/shared/types.js";
|
|
6
|
+
import type { PrincipalPolicyCheckpointEvidence } from "../../../data/principals/principalPolicyEvidence.js";
|
|
7
|
+
import type { SecurityIncidentReporter } from "../../../data/shared/securityIncidents.js";
|
|
8
|
+
import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
|
|
9
|
+
import { type CarriedRekeyPlanningInput, type SpeculativePath } from "./rekey/carriedDescendantRekeys.js";
|
|
10
|
+
/**
|
|
11
|
+
* Supplied by mutations that mint a new key epoch (rekey, revoke, move). The
|
|
12
|
+
* server refuses one that would strand a level above a directly granted
|
|
13
|
+
* container, and names the descendant rekeys it must carry instead (#2340).
|
|
14
|
+
*/
|
|
15
|
+
export interface CarriedRekeys {
|
|
16
|
+
readonly planning: CarriedRekeyPlanningInput;
|
|
17
|
+
/** The rotated container's own path once the rotation is accepted. */
|
|
18
|
+
readonly rotated: () => Promise<SpeculativePath>;
|
|
19
|
+
}
|
|
20
|
+
/** A mutation with no status-bearing variant: a share mints nothing to carry. */
|
|
21
|
+
export declare function submitPlainContainerMutation(plain: () => Promise<ContainerRotationResponse | null>): Promise<ContainerRotationResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Adapt a rotation endpoint pair to one status-bearing call. An adapter with
|
|
24
|
+
* only the plain method still rotates; it just cannot learn what to carry, so a
|
|
25
|
+
* rotation that needs descendants fails as any other refusal does.
|
|
26
|
+
*/
|
|
27
|
+
export declare function submitContainerRotation(input: {
|
|
28
|
+
plain: () => Promise<ContainerRotationResponse | null>;
|
|
29
|
+
result: (() => Promise<ContainerRotationResult>) | undefined;
|
|
30
|
+
}): Promise<ContainerRotationResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Submit a rotation; if the server refuses it for stranding a level above a
|
|
33
|
+
* directly granted container, sign the descendant rekeys it names and resubmit
|
|
34
|
+
* once with them carried. The refused attempt rolled back whole, so the signed
|
|
35
|
+
* rotation still extends the current head and only the descendants need
|
|
36
|
+
* signing. A second refusal means the tree moved underneath, and the caller's
|
|
37
|
+
* own retry starts from a fresh projection.
|
|
38
|
+
*/
|
|
39
|
+
export declare function submitRotationCarryingDescendants(input: {
|
|
40
|
+
carriedRekeys?: CarriedRekeys | undefined;
|
|
41
|
+
stillCurrent?: (() => boolean) | undefined;
|
|
42
|
+
submit: (carried: readonly ContainerMutationRequest[]) => Promise<ContainerRotationResult>;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
carriedPlans: MaterializedContainerRekeyPlan[];
|
|
45
|
+
result: ContainerRotationResult;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Submit and acknowledge remote share/rekey/revoke/move plans before scheduling
|
|
49
|
+
* opportunistic descendant re-citations. Create separately handles its lost
|
|
50
|
+
* response conflict; group share caches the rotated policy after this tail.
|
|
51
|
+
*/
|
|
52
|
+
export declare function submitAcknowledgedContainerMutation<TPlan extends Parameters<typeof acknowledgeContainerMutation>[0]["plan"]>(input: {
|
|
53
|
+
apiClient: ContainerReciteApi;
|
|
54
|
+
author: ContainerMutationAuthor;
|
|
55
|
+
/** Present exactly when the plan minted a new key epoch. */
|
|
56
|
+
carriedRekeys?: CarriedRekeys | undefined;
|
|
57
|
+
containerKey: Uint8Array;
|
|
58
|
+
execSql: ExecSql;
|
|
59
|
+
plan: TPlan;
|
|
60
|
+
recitationPolicies: readonly PrincipalPolicyCheckpointEvidence[];
|
|
61
|
+
/**
|
|
62
|
+
* Called once the server has accepted the mutation, before this device
|
|
63
|
+
* acknowledges it, so a caller can tell an accepted mutation it failed to
|
|
64
|
+
* settle from one that never committed.
|
|
65
|
+
*/
|
|
66
|
+
onAccepted?: (() => void) | undefined;
|
|
67
|
+
/** Session lifetime for best-effort work after durable acknowledgement. */
|
|
68
|
+
recitationStillCurrent?: (() => boolean) | undefined;
|
|
69
|
+
reportSecurityIncident: SecurityIncidentReporter;
|
|
70
|
+
stillCurrent?: (() => boolean) | undefined;
|
|
71
|
+
submit: (carried: readonly ContainerMutationRequest[]) => Promise<ContainerRotationResult>;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
containerKey: Uint8Array;
|
|
74
|
+
plan: TPlan;
|
|
75
|
+
response: ContainerRotationResponse;
|
|
76
|
+
} | null>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ContainerWriterProjectionResponse } from "../../../../internal/validators/response/index.js";
|
|
2
|
+
import type { ContainerMutationAuthor, ContainerRekeyApi, MaterializedContainerRekeyPlan } from "../../../../data/containers/shared/types.js";
|
|
3
|
+
import { type PrincipalPolicyCache, type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../../data/keyingProjectionVerification/index.js";
|
|
4
|
+
import type { CurrentPolicyReferenceResolver } from "../../../../data/principals/currentPolicyReferenceResolver.js";
|
|
5
|
+
import type { PrincipalPolicyCurrentEvidence } from "../../../../data/principals/principalPolicyEvidence.js";
|
|
6
|
+
import type { ExecSql } from "../../../../data/sqlite/sqlSchema.js";
|
|
7
|
+
/** What a rotation needs in hand to sign the descendant rekeys it must carry. */
|
|
8
|
+
export interface CarriedRekeyPlanningInput {
|
|
9
|
+
readonly apiClient: Pick<ContainerRekeyApi, "getContainerWriterProjection">;
|
|
10
|
+
readonly author: ContainerMutationAuthor;
|
|
11
|
+
readonly execSql: ExecSql;
|
|
12
|
+
/**
|
|
13
|
+
* Keys the batch minted and has yet to commit, by epoch id. A rotation's
|
|
14
|
+
* successor is wrapped to recipients at heads the batch itself commits, so
|
|
15
|
+
* no wrap on a re-rooted path opens it for the signer before then; the key
|
|
16
|
+
* the signer just minted does, and its keyring then opens what sits below.
|
|
17
|
+
*/
|
|
18
|
+
readonly knownContainerKeks?: ReadonlyMap<string, Uint8Array> | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Verified policies the batch itself commits, which the rebased paths cite
|
|
21
|
+
* before any store holds them; and the one each carried rekey cites anew.
|
|
22
|
+
*/
|
|
23
|
+
readonly principalPolicyCache?: PrincipalPolicyCache | undefined;
|
|
24
|
+
readonly replacementPrincipalPolicy?: PrincipalPolicyCurrentEvidence | undefined;
|
|
25
|
+
readonly resolveAuthoredPolicyReferences?: CurrentPolicyReferenceResolver | undefined;
|
|
26
|
+
readonly resolveProjectionUserKey: ProjectionUserKeyResolver;
|
|
27
|
+
readonly stillCurrent?: (() => boolean) | undefined;
|
|
28
|
+
readonly targetSecretKey: Uint8Array;
|
|
29
|
+
readonly warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** A rotated container's own path once its batch is accepted. */
|
|
32
|
+
export type SpeculativePath = Pick<ContainerWriterProjectionResponse, "containerKeks" | "organizationId" | "path" | "policyEvidence">;
|
|
33
|
+
/**
|
|
34
|
+
* Re-root a served projection on the deepest not-yet-accepted proper ancestor
|
|
35
|
+
* among `speculativePaths`. Each carried plan's own path was built the same
|
|
36
|
+
* way, so the deepest one already holds every speculative level above it. The
|
|
37
|
+
* container's own path, when the batch rotates it too, is not an ancestor: the
|
|
38
|
+
* caller is re-planning that rotation, and it extends what sits above.
|
|
39
|
+
*/
|
|
40
|
+
export declare function rebaseOnDeepestAncestor(served: ContainerWriterProjectionResponse, speculativePaths: readonly SpeculativePath[]): {
|
|
41
|
+
ancestor: SpeculativePath;
|
|
42
|
+
projection: ContainerWriterProjectionResponse;
|
|
43
|
+
} | null;
|
|
44
|
+
/**
|
|
45
|
+
* Sign one carried rekey against the path its batch will leave behind. The
|
|
46
|
+
* served projection is fetched by the caller; here it is verified, must sit
|
|
47
|
+
* below one of the rotated containers and in that container's organization,
|
|
48
|
+
* and is signed only if this signer holds its key and write access — which a
|
|
49
|
+
* member able to rotate the ancestor always does, since both inherit downward.
|
|
50
|
+
*/
|
|
51
|
+
export declare function planCarriedDescendantRekey(input: CarriedRekeyPlanningInput & {
|
|
52
|
+
readonly rotated: readonly SpeculativePath[];
|
|
53
|
+
readonly served: ContainerWriterProjectionResponse;
|
|
54
|
+
}): Promise<MaterializedContainerRekeyPlan>;
|
|
55
|
+
/**
|
|
56
|
+
* Sign the descendant rekeys a rotation must commit with (#2340). The server
|
|
57
|
+
* refuses a rotation that would leave a level above a directly granted
|
|
58
|
+
* container pinned to a retired epoch, because the grantee could never re-key
|
|
59
|
+
* that level itself and its writes would wait on another device. It names the
|
|
60
|
+
* levels; this signs them, parent-first, each against the path the batch will
|
|
61
|
+
* leave behind rather than the one currently served.
|
|
62
|
+
*
|
|
63
|
+
* `requiredContainerIds` is a hint, never an authority: each container is
|
|
64
|
+
* fetched and verified here, and refused unless it sits below a rotation.
|
|
65
|
+
*/
|
|
66
|
+
export declare function planCarriedDescendantRekeys(input: CarriedRekeyPlanningInput & {
|
|
67
|
+
readonly requiredContainerIds: readonly string[];
|
|
68
|
+
/** Each rotated container's own path once the batch is accepted. */
|
|
69
|
+
readonly rotated: readonly SpeculativePath[];
|
|
70
|
+
}): Promise<MaterializedContainerRekeyPlan[]>;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { ContainerAccessLevel
|
|
1
|
+
import type { ContainerAccessLevel } from "../../../../internal/crypto/index.js";
|
|
2
2
|
import type { ContainerMutationResponse, ContainerWriterProjectionResponse } from "../../../../internal/validators/response/index.js";
|
|
3
3
|
import type { ContainerMutationAuthor, ContainerShareApi, ContainerSharePlan } from "../../../../data/containers/shared/types.js";
|
|
4
4
|
import { type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../../data/keyingProjectionVerification/index.js";
|
|
5
5
|
import type { SecurityIncidentReporter } from "../../../../data/shared/securityIncidents.js";
|
|
6
6
|
import type { ExecSql } from "../../../../data/sqlite/sqlSchema.js";
|
|
7
7
|
import { type TrustedUserIdentityResolver } from "../../../../data/trustedUserIdentity/index.js";
|
|
8
|
-
import type { GroupPolicyNameReader } from "../../../organizations/principalPolicy/principalPolicyRequest.js";
|
|
9
|
-
import { type ContainerManagedPrincipalShareApi } from "./sharePrincipalPolicy.js";
|
|
10
8
|
export declare function shareRemoteContainer(input: {
|
|
11
9
|
reportSecurityIncident: SecurityIncidentReporter;
|
|
12
10
|
accessLevel: ContainerAccessLevel;
|
|
@@ -28,38 +26,3 @@ export declare function shareRemoteContainer(input: {
|
|
|
28
26
|
plan: ContainerSharePlan;
|
|
29
27
|
response: ContainerMutationResponse;
|
|
30
28
|
} | null>;
|
|
31
|
-
interface RemoteContainerGroupShareInput {
|
|
32
|
-
reportSecurityIncident: SecurityIncidentReporter;
|
|
33
|
-
accessLevel: ContainerAccessLevel;
|
|
34
|
-
apiClient: ContainerManagedPrincipalShareApi;
|
|
35
|
-
author: ContainerMutationAuthor;
|
|
36
|
-
containerId: string;
|
|
37
|
-
eventId?: string | undefined;
|
|
38
|
-
execSql: ExecSql;
|
|
39
|
-
/**
|
|
40
|
-
* The display name the user chose the group by, checked against the name
|
|
41
|
-
* committed in the verified group policy so a relabeled read-model row
|
|
42
|
-
* cannot redirect the share onto another group. `null` is reserved for the
|
|
43
|
-
* grant-preserving re-wrap: a share that would mint a new grant without a
|
|
44
|
-
* name is refused.
|
|
45
|
-
*/
|
|
46
|
-
expectedGroupName: string | null;
|
|
47
|
-
readEncryptedName?: GroupPolicyNameReader | undefined;
|
|
48
|
-
knownContainerKeks?: ReadonlyMap<string, Uint8Array> | undefined;
|
|
49
|
-
previousProjection?: ContainerWriterProjectionResponse | undefined;
|
|
50
|
-
recipientGroupId: string;
|
|
51
|
-
resolveProjectionUserKey: ProjectionUserKeyResolver;
|
|
52
|
-
resolveTrustedUserIdentity: TrustedUserIdentityResolver;
|
|
53
|
-
signedAt?: string | undefined;
|
|
54
|
-
signingKeyPair?: SigningKeyPair | null | undefined;
|
|
55
|
-
stillCurrent?: (() => boolean) | undefined;
|
|
56
|
-
targetSecretKey: Uint8Array;
|
|
57
|
-
warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;
|
|
58
|
-
}
|
|
59
|
-
interface RemoteContainerGroupShareResult {
|
|
60
|
-
containerKey: Uint8Array;
|
|
61
|
-
plan: ContainerSharePlan;
|
|
62
|
-
response: ContainerMutationResponse;
|
|
63
|
-
}
|
|
64
|
-
export declare function shareRemoteContainerWithGroup(input: RemoteContainerGroupShareInput): Promise<RemoteContainerGroupShareResult | null>;
|
|
65
|
-
export {};
|