@tearleads/client-sdk 0.1.62 → 0.1.63

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.
Files changed (653) hide show
  1. package/client/organizations/currentPrincipalMutations.js +5 -5
  2. package/client/organizations/currentPrincipalMutations.js.map +1 -1
  3. package/client/organizations/organizationDataUsage.js +1 -1
  4. package/client/organizations/organizationDataUsage.js.map +1 -1
  5. package/client/organizations/organizationGroupHistory.js +1 -1
  6. package/client/organizations/organizationGroupHistory.js.map +1 -1
  7. package/client/organizations/organizationGroupNameHydration.js +3 -3
  8. package/client/organizations/organizationGroupNameHydration.js.map +1 -1
  9. package/client/organizations/organizationHistory.js +2 -2
  10. package/client/organizations/organizationHistory.js.map +1 -1
  11. package/client/organizations/organizationReadModels.js +1 -1
  12. package/client/organizations/organizationReadModels.js.map +1 -1
  13. package/client/organizations/principalContainerMutations.js +1 -1
  14. package/client/organizations/principalContainerMutations.js.map +1 -1
  15. package/client/organizations/principalMutationRecovery.js.map +1 -1
  16. package/client/organizations/principalMutations.js +5 -5
  17. package/client/organizations/principalMutations.js.map +1 -1
  18. package/client/runtime/principalMutationApi.d.ts +1 -1
  19. package/client/runtime/principalMutationApi.js +2 -2
  20. package/client/runtime/principalMutationApi.js.map +1 -1
  21. package/client/runtime/principalMutationDispatch.js +1 -1
  22. package/client/runtime/principalMutationDispatch.js.map +1 -1
  23. package/client/session/index.js +1 -1
  24. package/client/session/index.js.map +1 -1
  25. package/client/session/sessionOrganizationCreation.js +1 -1
  26. package/client/session/sessionOrganizationCreation.js.map +1 -1
  27. package/client/session/sessionPurgeRecovery.js +2 -2
  28. package/client/session/sessionPurgeRecovery.js.map +1 -1
  29. package/package.json +1 -1
  30. package/stores/documents/documentStore/attachmentHydrationCommit.js +1 -1
  31. package/stores/documents/documentStore/attachmentHydrationCommit.js.map +1 -1
  32. package/stores/documents/documentStore/attachmentUploadAttempt.js +1 -1
  33. package/stores/documents/documentStore/syncRemoteSignals.js +1 -1
  34. package/stores/documents/documentStore/syncRemoteSignals.js.map +1 -1
  35. package/stores/documents/documentStore/syncShared.js +1 -1
  36. package/stores/documents/documentStore/syncShared.js.map +1 -1
  37. package/workflows/blobs/detach.js +1 -1
  38. package/workflows/blobs/detach.js.map +1 -1
  39. package/workflows/blobs/{blobChunkDecryption.js → hydration/blobChunkDecryption.js} +3 -3
  40. package/workflows/blobs/hydration/blobChunkDecryption.js.map +1 -0
  41. package/workflows/blobs/{decrypt.d.ts → hydration/decrypt.d.ts} +2 -2
  42. package/workflows/blobs/{decrypt.js → hydration/decrypt.js} +14 -14
  43. package/workflows/blobs/hydration/decrypt.js.map +1 -0
  44. package/workflows/blobs/{hydrate.d.ts → hydration/hydrate.d.ts} +7 -7
  45. package/workflows/blobs/{hydrate.js → hydration/hydrate.js} +5 -5
  46. package/workflows/blobs/hydration/hydrate.js.map +1 -0
  47. package/workflows/blobs/{hydrationResults.js → hydration/hydrationResults.js} +2 -2
  48. package/workflows/blobs/hydration/hydrationResults.js.map +1 -0
  49. package/workflows/blobs/index.d.ts +3 -3
  50. package/workflows/blobs/index.js +3 -3
  51. package/workflows/blobs/index.js.map +1 -1
  52. package/workflows/blobs/{automaticMultipartUpload.js → upload/automaticMultipartUpload.js} +1 -1
  53. package/workflows/blobs/upload/automaticMultipartUpload.js.map +1 -0
  54. package/workflows/blobs/{upload.d.ts → upload/index.d.ts} +2 -2
  55. package/workflows/blobs/{upload.js → upload/index.js} +14 -14
  56. package/workflows/blobs/upload/index.js.map +1 -0
  57. package/workflows/blobs/{multipartFirstParts.js → upload/multipartFirstParts.js} +4 -4
  58. package/workflows/blobs/upload/multipartFirstParts.js.map +1 -0
  59. package/workflows/blobs/{multipartStageFailures.js → upload/multipartStageFailures.js} +1 -1
  60. package/workflows/blobs/upload/multipartStageFailures.js.map +1 -0
  61. package/workflows/blobs/upload/multipartStageResolution.js.map +1 -0
  62. package/workflows/blobs/{multipartUpload.js → upload/multipartUpload.js} +3 -3
  63. package/workflows/blobs/upload/multipartUpload.js.map +1 -0
  64. package/workflows/blobs/{attachmentBindingVerification.js → verification/attachmentBindingVerification.js} +3 -3
  65. package/workflows/blobs/verification/attachmentBindingVerification.js.map +1 -0
  66. package/workflows/blobs/{attachmentDecryptor.js → verification/attachmentDecryptor.js} +3 -3
  67. package/workflows/blobs/verification/attachmentDecryptor.js.map +1 -0
  68. package/workflows/blobs/{attachmentKeyAuthenticator.js → verification/attachmentKeyAuthenticator.js} +5 -5
  69. package/workflows/blobs/verification/attachmentKeyAuthenticator.js.map +1 -0
  70. package/workflows/blobs/{retainedAttachmentVerification.js → verification/retainedAttachmentVerification.js} +5 -5
  71. package/workflows/blobs/verification/retainedAttachmentVerification.js.map +1 -0
  72. package/workflows/blobs/{verifiedWrapScope.js → verification/verifiedWrapScope.js} +2 -2
  73. package/workflows/blobs/verification/verifiedWrapScope.js.map +1 -0
  74. package/workflows/blobs/{writerProjection.js → verification/writerProjection.js} +3 -3
  75. package/workflows/blobs/verification/writerProjection.js.map +1 -0
  76. package/workflows/container-contents/container-state/purgeTree.js.map +1 -1
  77. package/workflows/container-contents/container-state/purgeTreeContainerDeletion.js.map +1 -1
  78. package/workflows/container-contents/container-state/remote.js +1 -1
  79. package/workflows/container-contents/container-state/remote.js.map +1 -1
  80. package/workflows/container-contents/documentLinks/index.d.ts +1 -1
  81. package/workflows/container-contents/documentLinks/index.js.map +1 -1
  82. package/workflows/container-contents/info/containerInfo.d.ts +1 -1
  83. package/workflows/container-contents/metadata/metadataIncomingUpdateIsolation.js +1 -1
  84. package/workflows/container-contents/metadata/metadataIncomingUpdateIsolation.js.map +1 -1
  85. package/workflows/container-contents/remoteHydration/destinationRootReload.js +1 -1
  86. package/workflows/container-contents/remoteHydration/destinationRootReload.js.map +1 -1
  87. package/workflows/container-contents/remoteHydration/verifiedDestination.js +1 -1
  88. package/workflows/container-contents/remoteHydration/verifiedDestination.js.map +1 -1
  89. package/workflows/container-contents/tombstones/documentPurge.d.ts +1 -1
  90. package/workflows/container-contents/tombstones/documentPurge.js.map +1 -1
  91. package/workflows/containers/child/currentShareGrantMutation.js +5 -5
  92. package/workflows/containers/child/currentShareGrantMutation.js.map +1 -1
  93. package/workflows/containers/child/currentSharePrincipalPolicy.js +5 -5
  94. package/workflows/containers/child/currentSharePrincipalPolicy.js.map +1 -1
  95. package/workflows/containers/child/runtimeCurrentGroupShare.js +1 -1
  96. package/workflows/containers/child/runtimeCurrentGroupShare.js.map +1 -1
  97. package/workflows/containers/child/share.d.ts +1 -1
  98. package/workflows/containers/child/share.js +4 -4
  99. package/workflows/containers/child/share.js.map +1 -1
  100. package/workflows/containers/child/sharePrincipalPolicy.d.ts +1 -1
  101. package/workflows/containers/child/sharePrincipalPolicy.js +2 -2
  102. package/workflows/containers/child/sharePrincipalPolicy.js.map +1 -1
  103. package/workflows/documents/{attachmentPersistence.d.ts → attachments/attachmentPersistence.d.ts} +2 -2
  104. package/workflows/documents/attachments/attachmentPersistence.js.map +1 -0
  105. package/workflows/documents/{blobMutationLock.d.ts → attachments/blobMutationLock.d.ts} +1 -1
  106. package/workflows/documents/{blobMutationLock.js → attachments/blobMutationLock.js} +1 -1
  107. package/workflows/documents/attachments/blobMutationLock.js.map +1 -0
  108. package/workflows/documents/attachments/orphanBlobReclaimState.js.map +1 -0
  109. package/workflows/documents/{orphanBlobReclaims.d.ts → attachments/orphanBlobReclaims.d.ts} +2 -2
  110. package/workflows/documents/{orphanBlobReclaims.js → attachments/orphanBlobReclaims.js} +3 -3
  111. package/workflows/documents/attachments/orphanBlobReclaims.js.map +1 -0
  112. package/workflows/documents/authorAccessFailure.js.map +1 -1
  113. package/workflows/documents/{createAdoption.js → create/createAdoption.js} +5 -5
  114. package/workflows/documents/create/createAdoption.js.map +1 -0
  115. package/workflows/documents/{createProjection.d.ts → create/createProjection.d.ts} +1 -1
  116. package/workflows/documents/{createProjectionFetch.d.ts → create/createProjectionFetch.d.ts} +2 -2
  117. package/workflows/documents/create/createProjectionFetch.js.map +1 -0
  118. package/workflows/documents/{createResponse.js → create/createResponse.js} +5 -5
  119. package/workflows/documents/create/createResponse.js.map +1 -0
  120. package/workflows/documents/{documentCreationPersistence.js → create/documentCreationPersistence.js} +2 -2
  121. package/workflows/documents/create/documentCreationPersistence.js.map +1 -0
  122. package/workflows/documents/{create.d.ts → create/index.d.ts} +4 -4
  123. package/workflows/documents/{create.js → create/index.js} +10 -10
  124. package/workflows/documents/create/index.js.map +1 -0
  125. package/workflows/documents/documentMutationCommit.js +1 -1
  126. package/workflows/documents/documentMutationCommit.js.map +1 -1
  127. package/workflows/documents/index.d.ts +17 -17
  128. package/workflows/documents/index.js +14 -14
  129. package/workflows/documents/index.js.map +1 -1
  130. package/workflows/documents/{linkSet.d.ts → linkSet/index.d.ts} +5 -5
  131. package/workflows/documents/{linkSet.js → linkSet/index.js} +12 -12
  132. package/workflows/documents/linkSet/index.js.map +1 -0
  133. package/workflows/documents/{linkSetAuthority.js → linkSet/linkSetAuthority.js} +6 -6
  134. package/workflows/documents/linkSet/linkSetAuthority.js.map +1 -0
  135. package/workflows/documents/{linkSetBlobRewraps.js → linkSet/linkSetBlobRewraps.js} +13 -13
  136. package/workflows/documents/linkSet/linkSetBlobRewraps.js.map +1 -0
  137. package/workflows/documents/{linkSetProjectionSeed.js → linkSet/linkSetProjectionSeed.js} +2 -2
  138. package/workflows/documents/linkSet/linkSetProjectionSeed.js.map +1 -0
  139. package/workflows/documents/{linkSetRemote.d.ts → linkSet/linkSetRemote.d.ts} +4 -4
  140. package/workflows/documents/{linkSetRemote.js → linkSet/linkSetRemote.js} +6 -6
  141. package/workflows/documents/linkSet/linkSetRemote.js.map +1 -0
  142. package/workflows/documents/{purge.d.ts → purge/index.d.ts} +5 -5
  143. package/workflows/documents/{purge.js → purge/index.js} +9 -9
  144. package/workflows/documents/purge/index.js.map +1 -0
  145. package/workflows/documents/{persistedDocumentRemoval.d.ts → purge/persistedDocumentRemoval.d.ts} +3 -3
  146. package/workflows/documents/{persistedDocumentRemoval.js → purge/persistedDocumentRemoval.js} +4 -4
  147. package/workflows/documents/purge/persistedDocumentRemoval.js.map +1 -0
  148. package/workflows/documents/{subtreePurgeScope.d.ts → purge/subtreePurgeScope.d.ts} +1 -1
  149. package/workflows/documents/{subtreePurgeScope.js → purge/subtreePurgeScope.js} +2 -2
  150. package/workflows/documents/purge/subtreePurgeScope.js.map +1 -0
  151. package/workflows/documents/rotationBaseline.js +1 -1
  152. package/workflows/documents/rotationBaseline.js.map +1 -1
  153. package/workflows/documents/{sync.d.ts → sync/index.d.ts} +1 -1
  154. package/workflows/documents/{sync.js → sync/index.js} +11 -11
  155. package/workflows/documents/sync/index.js.map +1 -0
  156. package/workflows/documents/{initialSync.js → sync/initialSync.js} +5 -5
  157. package/workflows/documents/sync/initialSync.js.map +1 -0
  158. package/workflows/documents/{readOnlyProjectionFailure.js → sync/readOnlyProjectionFailure.js} +5 -5
  159. package/workflows/documents/sync/readOnlyProjectionFailure.js.map +1 -0
  160. package/workflows/documents/{readOnlySync.d.ts → sync/readOnlySync.d.ts} +9 -9
  161. package/workflows/documents/{readOnlySync.js → sync/readOnlySync.js} +11 -11
  162. package/workflows/documents/sync/readOnlySync.js.map +1 -0
  163. package/workflows/documents/sync/reportDocumentSyncQuarantine.js.map +1 -0
  164. package/workflows/documents/{syncAttemptPlanning.js → sync/syncAttemptPlanning.js} +9 -9
  165. package/workflows/documents/sync/syncAttemptPlanning.js.map +1 -0
  166. package/workflows/documents/{syncAttemptState.d.ts → sync/syncAttemptState.d.ts} +5 -5
  167. package/workflows/documents/sync/syncAttemptState.js.map +1 -0
  168. package/workflows/documents/{syncLane.d.ts → sync/syncLane.d.ts} +3 -3
  169. package/workflows/documents/{syncLane.js → sync/syncLane.js} +2 -2
  170. package/workflows/documents/sync/syncLane.js.map +1 -0
  171. package/workflows/documents/{syncResponseResult.js → sync/syncResponseResult.js} +9 -9
  172. package/workflows/documents/sync/syncResponseResult.js.map +1 -0
  173. package/workflows/documents/{syncSubmittedResult.js → sync/syncSubmittedResult.js} +6 -6
  174. package/workflows/documents/sync/syncSubmittedResult.js.map +1 -0
  175. package/workflows/documents/{syncTrace.js → sync/syncTrace.js} +1 -1
  176. package/workflows/documents/{syncFailures.js → syncFailures/index.js} +5 -5
  177. package/workflows/documents/syncFailures/index.js.map +1 -0
  178. package/workflows/documents/{syncAbandon.js → syncFailures/syncAbandon.js} +1 -1
  179. package/workflows/documents/syncFailures/syncAbandon.js.map +1 -0
  180. package/workflows/documents/{syncFailureClassification.d.ts → syncFailures/syncFailureClassification.d.ts} +2 -2
  181. package/workflows/documents/{syncFailureClassification.js → syncFailures/syncFailureClassification.js} +6 -6
  182. package/workflows/documents/syncFailures/syncFailureClassification.js.map +1 -0
  183. package/workflows/documents/{syncPolicyRepair.js → syncFailures/syncPolicyRepair.js} +3 -3
  184. package/workflows/documents/syncFailures/syncPolicyRepair.js.map +1 -0
  185. package/workflows/documents/syncFailures/syncRepairAbandon.js.map +1 -0
  186. package/workflows/documents/{syncRepairAccess.js → syncFailures/syncRepairAccess.js} +2 -2
  187. package/workflows/documents/syncFailures/syncRepairAccess.js.map +1 -0
  188. package/workflows/documents/{syncContentKeys.d.ts → syncPlan/syncContentKeys.d.ts} +4 -4
  189. package/workflows/documents/{syncContentKeys.js → syncPlan/syncContentKeys.js} +8 -8
  190. package/workflows/documents/syncPlan/syncContentKeys.js.map +1 -0
  191. package/workflows/documents/{syncPlanIdentity.js → syncPlan/syncPlanIdentity.js} +3 -3
  192. package/workflows/documents/syncPlan/syncPlanIdentity.js.map +1 -0
  193. package/workflows/documents/{syncPlanMaterial.js → syncPlan/syncPlanMaterial.js} +9 -9
  194. package/workflows/documents/syncPlan/syncPlanMaterial.js.map +1 -0
  195. package/workflows/documents/syncPlan/syncPlanProjection.js.map +1 -0
  196. package/workflows/documents/{syncPlanRequestBounds.js → syncPlan/syncPlanRequestBounds.js} +1 -1
  197. package/workflows/documents/syncPlan/syncPlanRequestBounds.js.map +1 -0
  198. package/workflows/documents/{syncAutomaticContainerRekeys.js → syncRekeys/syncAutomaticContainerRekeys.js} +10 -10
  199. package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js.map +1 -0
  200. package/workflows/documents/{syncContainerRekeyPreparation.js → syncRekeys/syncContainerRekeyPreparation.js} +11 -11
  201. package/workflows/documents/syncRekeys/syncContainerRekeyPreparation.js.map +1 -0
  202. package/workflows/documents/{syncContainerRekeyProjection.js → syncRekeys/syncContainerRekeyProjection.js} +2 -2
  203. package/workflows/documents/syncRekeys/syncContainerRekeyProjection.js.map +1 -0
  204. package/workflows/documents/{syncContainerRekeys.js → syncRekeys/syncContainerRekeys.js} +3 -3
  205. package/workflows/documents/syncRekeys/syncContainerRekeys.js.map +1 -0
  206. package/workflows/documents/{syncRecoveryRekey.d.ts → syncRekeys/syncRecoveryRekey.d.ts} +4 -4
  207. package/workflows/documents/{syncRecoveryRekey.js → syncRekeys/syncRecoveryRekey.js} +4 -4
  208. package/workflows/documents/syncRekeys/syncRecoveryRekey.js.map +1 -0
  209. package/workflows/documents/{syncRekeyCommit.js → syncRekeys/syncRekeyCommit.js} +1 -1
  210. package/workflows/organizations/{currentGroupMetadataAuthority.js → groupMetadata/currentGroupMetadataAuthority.js} +5 -5
  211. package/workflows/organizations/groupMetadata/currentGroupMetadataAuthority.js.map +1 -0
  212. package/workflows/organizations/{groupMetadataAccess.d.ts → groupMetadata/groupMetadataAccess.d.ts} +5 -5
  213. package/workflows/organizations/{groupMetadataAccess.js → groupMetadata/groupMetadataAccess.js} +6 -6
  214. package/workflows/organizations/groupMetadata/groupMetadataAccess.js.map +1 -0
  215. package/workflows/organizations/{groupMetadataBinding.js → groupMetadata/groupMetadataBinding.js} +1 -1
  216. package/workflows/organizations/groupMetadata/groupMetadataBinding.js.map +1 -0
  217. package/workflows/organizations/{groupMetadataContainerAuthority.js → groupMetadata/groupMetadataContainerAuthority.js} +6 -6
  218. package/workflows/organizations/groupMetadata/groupMetadataContainerAuthority.js.map +1 -0
  219. package/workflows/organizations/{groupMetadataErrors.js → groupMetadata/groupMetadataErrors.js} +1 -1
  220. package/workflows/organizations/{groupMetadataRootBinding.js → groupMetadata/groupMetadataRootBinding.js} +3 -3
  221. package/workflows/organizations/groupMetadata/groupMetadataRootBinding.js.map +1 -0
  222. package/workflows/organizations/{groupMetadataRuntime.js → groupMetadata/groupMetadataRuntime.js} +4 -4
  223. package/workflows/organizations/groupMetadata/groupMetadataRuntime.js.map +1 -0
  224. package/workflows/organizations/{runtimeGroupMetadataAuthority.js → groupMetadata/runtimeGroupMetadataAuthority.js} +2 -2
  225. package/workflows/organizations/groupMetadata/runtimeGroupMetadataAuthority.js.map +1 -0
  226. package/workflows/organizations/{currentOrganizationGroupNames.js → groupNames/currentOrganizationGroupNames.js} +8 -8
  227. package/workflows/organizations/groupNames/currentOrganizationGroupNames.js.map +1 -0
  228. package/workflows/organizations/{groupMembershipName.d.ts → groupNames/groupMembershipName.d.ts} +3 -3
  229. package/workflows/organizations/{groupMembershipName.js → groupNames/groupMembershipName.js} +2 -2
  230. package/workflows/organizations/groupNames/groupMembershipName.js.map +1 -0
  231. package/workflows/organizations/{groupNameUniqueness.js → groupNames/groupNameUniqueness.js} +11 -11
  232. package/workflows/organizations/groupNames/groupNameUniqueness.js.map +1 -0
  233. package/workflows/organizations/{organizationGroupNamePolicies.js → groupNames/organizationGroupNamePolicies.js} +5 -5
  234. package/workflows/organizations/groupNames/organizationGroupNamePolicies.js.map +1 -0
  235. package/workflows/organizations/{organizationGroupNames.js → groupNames/organizationGroupNames.js} +1 -1
  236. package/workflows/organizations/groupNames/organizationGroupNames.js.map +1 -0
  237. package/workflows/organizations/{commitCurrentGroupPolicyMutation.js → groupPolicy/commitCurrentGroupPolicyMutation.js} +4 -4
  238. package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js.map +1 -0
  239. package/workflows/organizations/{currentGroupPolicyMutationContext.js → groupPolicy/currentGroupPolicyMutationContext.js} +7 -7
  240. package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js.map +1 -0
  241. package/workflows/organizations/{currentPolicyMutationAcknowledgement.js → groupPolicy/currentPolicyMutationAcknowledgement.js} +3 -3
  242. package/workflows/organizations/groupPolicy/currentPolicyMutationAcknowledgement.js.map +1 -0
  243. package/workflows/organizations/{groupPolicyMutationAcknowledgement.js → groupPolicy/groupPolicyMutationAcknowledgement.js} +4 -4
  244. package/workflows/organizations/groupPolicy/groupPolicyMutationAcknowledgement.js.map +1 -0
  245. package/workflows/organizations/{groupPolicyMutationContext.d.ts → groupPolicy/groupPolicyMutationContext.d.ts} +8 -8
  246. package/workflows/organizations/{groupPolicyMutationContext.js → groupPolicy/groupPolicyMutationContext.js} +5 -5
  247. package/workflows/organizations/groupPolicy/groupPolicyMutationContext.js.map +1 -0
  248. package/workflows/organizations/{groupPolicyMutationEvidence.d.ts → groupPolicy/groupPolicyMutationEvidence.d.ts} +4 -4
  249. package/workflows/organizations/{groupPolicyMutationEvidence.js → groupPolicy/groupPolicyMutationEvidence.js} +3 -3
  250. package/workflows/organizations/groupPolicy/groupPolicyMutationEvidence.js.map +1 -0
  251. package/workflows/organizations/{groupPolicyMutationHead.js → groupPolicy/groupPolicyMutationHead.js} +1 -1
  252. package/workflows/organizations/{groupPolicyRequests.js → groupPolicy/groupPolicyRequests.js} +5 -5
  253. package/workflows/organizations/groupPolicy/groupPolicyRequests.js.map +1 -0
  254. package/workflows/organizations/{groupPolicyVerification.js → groupPolicy/groupPolicyVerification.js} +5 -5
  255. package/workflows/organizations/groupPolicy/groupPolicyVerification.js.map +1 -0
  256. package/workflows/organizations/{submitGroupPolicyCommit.d.ts → groupPolicy/submitGroupPolicyCommit.d.ts} +3 -3
  257. package/workflows/organizations/{submitGroupPolicyCommit.js → groupPolicy/submitGroupPolicyCommit.js} +1 -1
  258. package/workflows/organizations/groupPolicy/submitGroupPolicyCommit.js.map +1 -0
  259. package/workflows/organizations/{createCurrentOrganizationGroup.js → groups/createCurrentOrganizationGroup.js} +9 -9
  260. package/workflows/organizations/groups/createCurrentOrganizationGroup.js.map +1 -0
  261. package/workflows/organizations/{deleteCurrentOrganizationGroup.js → groups/deleteCurrentOrganizationGroup.js} +2 -2
  262. package/workflows/organizations/groups/deleteCurrentOrganizationGroup.js.map +1 -0
  263. package/workflows/organizations/{deleteOrganizationGroup.d.ts → groups/deleteOrganizationGroup.d.ts} +6 -6
  264. package/workflows/organizations/{deleteOrganizationGroup.js → groups/deleteOrganizationGroup.js} +6 -6
  265. package/workflows/organizations/groups/deleteOrganizationGroup.js.map +1 -0
  266. package/workflows/organizations/{groupCreation.d.ts → groups/groupCreation.d.ts} +7 -7
  267. package/workflows/organizations/{groupCreation.js → groups/groupCreation.js} +4 -4
  268. package/workflows/organizations/groups/groupCreation.js.map +1 -0
  269. package/workflows/organizations/{organizationGroupDirectory.js → groups/organizationGroupDirectory.js} +10 -10
  270. package/workflows/organizations/groups/organizationGroupDirectory.js.map +1 -0
  271. package/workflows/organizations/index.d.ts +13 -13
  272. package/workflows/organizations/index.js +12 -12
  273. package/workflows/organizations/index.js.map +1 -1
  274. package/workflows/organizations/policyHistory/groupPolicyHistoryPage.js.map +1 -0
  275. package/workflows/organizations/{loadPolicyHistoryDetails.js → policyHistory/loadPolicyHistoryDetails.js} +5 -5
  276. package/workflows/organizations/policyHistory/loadPolicyHistoryDetails.js.map +1 -0
  277. package/workflows/organizations/{organizationPolicyHistoryDetails.js → policyHistory/organizationPolicyHistoryDetails.js} +2 -2
  278. package/workflows/organizations/policyHistory/organizationPolicyHistoryDetails.js.map +1 -0
  279. package/workflows/organizations/{organizationPolicyHistoryVerification.js → policyHistory/organizationPolicyHistoryVerification.js} +2 -2
  280. package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js.map +1 -0
  281. package/workflows/organizations/{policyHistoryAccessDenial.js → policyHistory/policyHistoryAccessDenial.js} +3 -3
  282. package/workflows/organizations/policyHistory/policyHistoryAccessDenial.js.map +1 -0
  283. package/workflows/organizations/{policyHistoryCache.js → policyHistory/policyHistoryCache.js} +1 -1
  284. package/workflows/organizations/policyHistory/policyHistoryCache.js.map +1 -0
  285. package/workflows/organizations/{policyHistoryReadModel.d.ts → policyHistory/policyHistoryReadModel.d.ts} +1 -1
  286. package/workflows/organizations/{policyHistoryTypes.d.ts → policyHistory/policyHistoryTypes.d.ts} +1 -1
  287. package/workflows/organizations/{acknowledgedDirectoryBindings.js → principalMutations/acknowledgedDirectoryBindings.js} +2 -2
  288. package/workflows/organizations/principalMutations/acknowledgedDirectoryBindings.js.map +1 -0
  289. package/workflows/organizations/{currentGroupMutationReferences.js → principalMutations/currentGroupMutationReferences.js} +2 -2
  290. package/workflows/organizations/principalMutations/currentGroupMutationReferences.js.map +1 -0
  291. package/workflows/organizations/{currentOrganizationMutationAuthority.js → principalMutations/currentOrganizationMutationAuthority.js} +3 -3
  292. package/workflows/organizations/principalMutations/currentOrganizationMutationAuthority.js.map +1 -0
  293. package/workflows/organizations/{currentOrganizationMutationRetention.js → principalMutations/currentOrganizationMutationRetention.js} +4 -4
  294. package/workflows/organizations/principalMutations/currentOrganizationMutationRetention.js.map +1 -0
  295. package/workflows/organizations/{currentPrincipalMutationLease.js → principalMutations/currentPrincipalMutationLease.js} +6 -6
  296. package/workflows/organizations/principalMutations/currentPrincipalMutationLease.js.map +1 -0
  297. package/workflows/organizations/{principalMutationJournalManagement.d.ts → principalMutations/principalMutationJournalManagement.d.ts} +1 -1
  298. package/workflows/organizations/{principalMutationJournalManagement.js → principalMutations/principalMutationJournalManagement.js} +7 -7
  299. package/workflows/organizations/principalMutations/principalMutationJournalManagement.js.map +1 -0
  300. package/workflows/organizations/{principalMutationJournalSession.d.ts → principalMutations/principalMutationJournalSession.d.ts} +4 -4
  301. package/workflows/organizations/{principalMutationJournalSession.js → principalMutations/principalMutationJournalSession.js} +4 -4
  302. package/workflows/organizations/principalMutations/principalMutationJournalSession.js.map +1 -0
  303. package/workflows/organizations/{principalMutationReceipt.js → principalMutations/principalMutationReceipt.js} +3 -3
  304. package/workflows/organizations/principalMutations/principalMutationReceipt.js.map +1 -0
  305. package/workflows/organizations/{principalOperationReceipt.d.ts → principalMutations/principalOperationReceipt.d.ts} +2 -2
  306. package/workflows/organizations/{principalOperationReceipt.js → principalMutations/principalOperationReceipt.js} +3 -3
  307. package/workflows/organizations/principalMutations/principalOperationReceipt.js.map +1 -0
  308. package/workflows/organizations/principalMutations/retainAcknowledgedPrincipalCurrents.d.ts +6 -0
  309. package/workflows/organizations/{retainAcknowledgedPrincipalCurrents.js → principalMutations/retainAcknowledgedPrincipalCurrents.js} +4 -4
  310. package/workflows/organizations/principalMutations/retainAcknowledgedPrincipalCurrents.js.map +1 -0
  311. package/workflows/organizations/{runtimeCurrentGroupMutation.js → principalMutations/runtimeCurrentGroupMutation.js} +5 -5
  312. package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js.map +1 -0
  313. package/workflows/organizations/{runtimeCurrentOrganizationMutation.js → principalMutations/runtimeCurrentOrganizationMutation.js} +2 -2
  314. package/workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation.js.map +1 -0
  315. package/workflows/organizations/{principalPolicy.d.ts → principalPolicy/index.d.ts} +8 -8
  316. package/workflows/organizations/{principalPolicy.js → principalPolicy/index.js} +9 -9
  317. package/workflows/organizations/principalPolicy/index.js.map +1 -0
  318. package/workflows/organizations/{principalPolicyApi.d.ts → principalPolicy/principalPolicyApi.d.ts} +4 -4
  319. package/workflows/organizations/principalPolicy/principalPolicyApi.js.map +1 -0
  320. package/workflows/organizations/{principalPolicyReceiptArtifacts.js → principalPolicy/principalPolicyReceiptArtifacts.js} +2 -2
  321. package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js.map +1 -0
  322. package/workflows/organizations/{principalPolicyRecipients.js → principalPolicy/principalPolicyRecipients.js} +2 -2
  323. package/workflows/organizations/principalPolicy/principalPolicyRecipients.js.map +1 -0
  324. package/workflows/organizations/{principalPolicyRequest.d.ts → principalPolicy/principalPolicyRequest.d.ts} +3 -3
  325. package/workflows/organizations/{principalPolicyRequest.js → principalPolicy/principalPolicyRequest.js} +2 -2
  326. package/workflows/organizations/{createOrganization.d.ts → provisioning/createOrganization.d.ts} +7 -7
  327. package/workflows/organizations/{createOrganization.js → provisioning/createOrganization.js} +3 -3
  328. package/workflows/organizations/provisioning/createOrganization.js.map +1 -0
  329. package/workflows/organizations/{organizationProvisioningAttempt.d.ts → provisioning/organizationProvisioningAttempt.d.ts} +3 -3
  330. package/workflows/organizations/{organizationProvisioningAttempt.js → provisioning/organizationProvisioningAttempt.js} +6 -6
  331. package/workflows/organizations/provisioning/organizationProvisioningAttempt.js.map +1 -0
  332. package/workflows/organizations/{organizationReplacementVerification.js → provisioning/organizationReplacementVerification.js} +2 -2
  333. package/workflows/organizations/provisioning/organizationReplacementVerification.js.map +1 -0
  334. package/workflows/organizations/{dataUsageReadModel.d.ts → readModel/dataUsageReadModel.d.ts} +3 -3
  335. package/workflows/organizations/{dataUsageReadModel.js → readModel/dataUsageReadModel.js} +2 -2
  336. package/workflows/organizations/readModel/dataUsageReadModel.js.map +1 -0
  337. package/workflows/organizations/{readModel.d.ts → readModel/index.d.ts} +5 -5
  338. package/workflows/organizations/{readModel.js → readModel/index.js} +2 -2
  339. package/workflows/organizations/readModel/index.js.map +1 -0
  340. package/workflows/organizations/{listLocalOrganizations.d.ts → readModel/listLocalOrganizations.d.ts} +1 -1
  341. package/workflows/organizations/{listLocalOrganizations.js → readModel/listLocalOrganizations.js} +8 -8
  342. package/workflows/organizations/readModel/listLocalOrganizations.js.map +1 -0
  343. package/workflows/organizations/{localReadModelDetails.d.ts → readModel/localReadModelDetails.d.ts} +3 -3
  344. package/workflows/organizations/{localReadModelDetails.js → readModel/localReadModelDetails.js} +6 -6
  345. package/workflows/organizations/readModel/localReadModelDetails.js.map +1 -0
  346. package/workflows/organizations/{organizationPresentationAccessState.js → readModel/organizationPresentationAccessState.js} +1 -1
  347. package/workflows/organizations/readModel/organizationPresentationAccessState.js.map +1 -0
  348. package/workflows/organizations/{organizationPresentationFailures.js → readModel/organizationPresentationFailures.js} +1 -1
  349. package/workflows/organizations/{readModelProjection.d.ts → readModel/readModelProjection.d.ts} +5 -5
  350. package/workflows/organizations/{readModelProjection.js → readModel/readModelProjection.js} +6 -6
  351. package/workflows/organizations/readModel/readModelProjection.js.map +1 -0
  352. package/workflows/organizations/{authoredPrincipalPolicyWarmer.js → rematerialization/authoredPrincipalPolicyWarmer.js} +2 -2
  353. package/workflows/organizations/rematerialization/authoredPrincipalPolicyWarmer.js.map +1 -0
  354. package/workflows/organizations/{precedingPrincipalRematerialization.js → rematerialization/precedingPrincipalRematerialization.js} +1 -1
  355. package/workflows/organizations/rematerialization/precedingPrincipalRematerialization.js.map +1 -0
  356. package/workflows/organizations/{principalContainerRematerialization.js → rematerialization/principalContainerRematerialization.js} +13 -13
  357. package/workflows/organizations/rematerialization/principalContainerRematerialization.js.map +1 -0
  358. package/workflows/organizations/{principalContainerRematerializationPlanning.js → rematerialization/principalContainerRematerializationPlanning.js} +2 -2
  359. package/workflows/organizations/rematerialization/principalContainerRematerializationPlanning.js.map +1 -0
  360. package/workflows/organizations/{principalContainerRematerializationTargets.js → rematerialization/principalContainerRematerializationTargets.js} +3 -3
  361. package/workflows/organizations/rematerialization/principalContainerRematerializationTargets.js.map +1 -0
  362. package/workflows/principals/{acknowledgedPrincipalCurrents.d.ts → acknowledgements/acknowledgedPrincipalCurrents.d.ts} +6 -6
  363. package/workflows/principals/{acknowledgedPrincipalCurrents.js → acknowledgements/acknowledgedPrincipalCurrents.js} +7 -7
  364. package/workflows/principals/acknowledgements/acknowledgedPrincipalCurrents.js.map +1 -0
  365. package/workflows/principals/{acknowledgedPrincipalPredecessor.d.ts → acknowledgements/acknowledgedPrincipalPredecessor.d.ts} +10 -10
  366. package/workflows/principals/{acknowledgedPrincipalPredecessor.js → acknowledgements/acknowledgedPrincipalPredecessor.js} +9 -9
  367. package/workflows/principals/acknowledgements/acknowledgedPrincipalPredecessor.js.map +1 -0
  368. package/workflows/principals/{initialPrincipalCurrentPublication.js → acknowledgements/initialPrincipalCurrentPublication.js} +7 -7
  369. package/workflows/principals/acknowledgements/initialPrincipalCurrentPublication.js.map +1 -0
  370. package/workflows/principals/{principalAcknowledgementChecks.d.ts → acknowledgements/principalAcknowledgementChecks.d.ts} +3 -3
  371. package/workflows/principals/{principalCurrentPublicationSeal.js → acknowledgements/principalCurrentPublicationSeal.js} +3 -3
  372. package/workflows/principals/acknowledgements/principalCurrentPublicationSeal.js.map +1 -0
  373. package/workflows/principals/{reconcileAcknowledgedPrincipalCurrent.js → acknowledgements/reconcileAcknowledgedPrincipalCurrent.js} +6 -6
  374. package/workflows/principals/acknowledgements/reconcileAcknowledgedPrincipalCurrent.js.map +1 -0
  375. package/workflows/principals/{loadRecoveredPrincipalHistoryPage.d.ts → historyRecovery/loadRecoveredPrincipalHistoryPage.d.ts} +1 -1
  376. package/workflows/principals/{loadRecoveredPrincipalHistoryPage.js → historyRecovery/loadRecoveredPrincipalHistoryPage.js} +7 -7
  377. package/workflows/principals/historyRecovery/loadRecoveredPrincipalHistoryPage.js.map +1 -0
  378. package/workflows/principals/{principalHistoryRecoveryAuthority.js → historyRecovery/principalHistoryRecoveryAuthority.js} +2 -2
  379. package/workflows/principals/historyRecovery/principalHistoryRecoveryAuthority.js.map +1 -0
  380. package/workflows/principals/{principalHistoryRecoveryPrefix.js → historyRecovery/principalHistoryRecoveryPrefix.js} +5 -5
  381. package/workflows/principals/historyRecovery/principalHistoryRecoveryPrefix.js.map +1 -0
  382. package/workflows/principals/{principalHistoryRecoveryReferences.js → historyRecovery/principalHistoryRecoveryReferences.js} +4 -4
  383. package/workflows/principals/historyRecovery/principalHistoryRecoveryReferences.js.map +1 -0
  384. package/workflows/principals/{principalHistoryRecoveryStage.js → historyRecovery/principalHistoryRecoveryStage.js} +4 -4
  385. package/workflows/principals/historyRecovery/principalHistoryRecoveryStage.js.map +1 -0
  386. package/workflows/principals/{principalHistoryRecoveryTypes.d.ts → historyRecovery/principalHistoryRecoveryTypes.d.ts} +5 -5
  387. package/workflows/principals/{principalHistoryRecoveryTypes.js → historyRecovery/principalHistoryRecoveryTypes.js} +1 -1
  388. package/workflows/principals/historyRecovery/principalHistoryRecoveryTypes.js.map +1 -0
  389. package/workflows/principals/{principalHistoryRecoveryVerification.js → historyRecovery/principalHistoryRecoveryVerification.js} +1 -1
  390. package/workflows/principals/{recoverCurrentOrganizationPolicy.js → historyRecovery/recoverCurrentOrganizationPolicy.js} +4 -4
  391. package/workflows/principals/historyRecovery/recoverCurrentOrganizationPolicy.js.map +1 -0
  392. package/workflows/principals/{recoverPrincipalHistoryPage.js → historyRecovery/recoverPrincipalHistoryPage.js} +2 -2
  393. package/workflows/principals/{recoverPrincipalPolicyHistory.js → historyRecovery/recoverPrincipalPolicyHistory.js} +8 -8
  394. package/workflows/principals/historyRecovery/recoverPrincipalPolicyHistory.js.map +1 -0
  395. package/workflows/principals/{recoverScopedPrincipalPolicyHistory.d.ts → historyRecovery/recoverScopedPrincipalPolicyHistory.d.ts} +3 -3
  396. package/workflows/principals/{recoverScopedPrincipalPolicyHistory.js → historyRecovery/recoverScopedPrincipalPolicyHistory.js} +7 -7
  397. package/workflows/principals/historyRecovery/recoverScopedPrincipalPolicyHistory.js.map +1 -0
  398. package/workflows/principals/index.d.ts +6 -6
  399. package/workflows/principals/index.js +6 -6
  400. package/workflows/principals/index.js.map +1 -1
  401. package/workflows/principals/{policyCache.d.ts → policyCache/index.d.ts} +5 -5
  402. package/workflows/principals/{policyCache.js → policyCache/index.js} +10 -10
  403. package/workflows/principals/policyCache/index.js.map +1 -0
  404. package/workflows/principals/{principalPolicyCacheAdvance.js → policyCache/principalPolicyCacheAdvance.js} +2 -2
  405. package/workflows/principals/policyCache/principalPolicyCacheAdvance.js.map +1 -0
  406. package/workflows/principals/{principalPolicyCacheValidation.js → policyCache/principalPolicyCacheValidation.js} +3 -3
  407. package/workflows/principals/policyCache/principalPolicyCacheValidation.js.map +1 -0
  408. package/workflows/principals/{principalPolicyOrganizationScope.js → policyCache/principalPolicyOrganizationScope.js} +7 -7
  409. package/workflows/principals/policyCache/principalPolicyOrganizationScope.js.map +1 -0
  410. package/workflows/principals/{publicPrincipalHistoryAuthority.js → publicHistory/publicPrincipalHistoryAuthority.js} +3 -3
  411. package/workflows/principals/publicHistory/publicPrincipalHistoryAuthority.js.map +1 -0
  412. package/workflows/principals/{publicPrincipalHistoryPage.js → publicHistory/publicPrincipalHistoryPage.js} +6 -6
  413. package/workflows/principals/publicHistory/publicPrincipalHistoryPage.js.map +1 -0
  414. package/workflows/principals/{publicPrincipalHistoryProgress.js → publicHistory/publicPrincipalHistoryProgress.js} +8 -8
  415. package/workflows/principals/publicHistory/publicPrincipalHistoryProgress.js.map +1 -0
  416. package/workflows/principals/{publicPrincipalHistoryTypes.d.ts → publicHistory/publicPrincipalHistoryTypes.d.ts} +7 -7
  417. package/workflows/principals/publicHistory/publicPrincipalHistoryTypes.js.map +1 -0
  418. package/workflows/principals/{publicProjectionDirectory.js → publicHistory/publicProjectionDirectory.js} +2 -2
  419. package/workflows/principals/publicHistory/publicProjectionDirectory.js.map +1 -0
  420. package/workflows/principals/{publicProjectionPrincipal.js → publicHistory/publicProjectionPrincipal.js} +4 -4
  421. package/workflows/principals/publicHistory/publicProjectionPrincipal.js.map +1 -0
  422. package/workflows/principals/{recoverProjectionPolicyHistory.d.ts → publicHistory/recoverProjectionPolicyHistory.d.ts} +2 -2
  423. package/workflows/principals/{recoverProjectionPolicyHistory.js → publicHistory/recoverProjectionPolicyHistory.js} +3 -3
  424. package/workflows/principals/publicHistory/recoverProjectionPolicyHistory.js.map +1 -0
  425. package/workflows/principals/{recoverPublicPrincipalHistory.js → publicHistory/recoverPublicPrincipalHistory.js} +7 -7
  426. package/workflows/principals/publicHistory/recoverPublicPrincipalHistory.js.map +1 -0
  427. package/workflows/principals/{selectPublicPrincipalHistory.js → publicHistory/selectPublicPrincipalHistory.js} +5 -5
  428. package/workflows/principals/publicHistory/selectPublicPrincipalHistory.js.map +1 -0
  429. package/workflows/principals/{principalCurrentRecoveryBatch.js → recoveryOperation/principalCurrentRecoveryBatch.js} +2 -2
  430. package/workflows/principals/recoveryOperation/principalCurrentRecoveryBatch.js.map +1 -0
  431. package/workflows/principals/{principalRecoveryDirectory.d.ts → recoveryOperation/principalRecoveryDirectory.d.ts} +3 -3
  432. package/workflows/principals/{principalRecoveryDirectory.js → recoveryOperation/principalRecoveryDirectory.js} +9 -9
  433. package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js.map +1 -0
  434. package/workflows/principals/recoveryOperation/principalRecoveryDiscoveryPage.js.map +1 -0
  435. package/workflows/principals/{principalRecoveryLocalPreference.js → recoveryOperation/principalRecoveryLocalPreference.js} +4 -4
  436. package/workflows/principals/recoveryOperation/principalRecoveryLocalPreference.js.map +1 -0
  437. package/workflows/principals/{principalRecoveryMemo.d.ts → recoveryOperation/principalRecoveryMemo.d.ts} +2 -2
  438. package/workflows/principals/{principalRecoveryMemo.js → recoveryOperation/principalRecoveryMemo.js} +4 -4
  439. package/workflows/principals/recoveryOperation/principalRecoveryMemo.js.map +1 -0
  440. package/workflows/principals/{principalRecoveryMemoValidity.js → recoveryOperation/principalRecoveryMemoValidity.js} +2 -2
  441. package/workflows/principals/recoveryOperation/principalRecoveryMemoValidity.js.map +1 -0
  442. package/workflows/principals/{principalRecoveryOutage.js → recoveryOperation/principalRecoveryOutage.js} +5 -5
  443. package/workflows/principals/recoveryOperation/principalRecoveryOutage.js.map +1 -0
  444. package/workflows/principals/runtimePolicyRecovery.js +3 -3
  445. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  446. package/workflows/principals/runtimeProjectionPolicyRecovery.js +3 -3
  447. package/workflows/principals/runtimeProjectionPolicyRecovery.js.map +1 -1
  448. package/workflows/registration/organizationProvisioningArtifacts.d.ts +1 -1
  449. package/workflows/registration/provisionedPrincipalHistory.js +1 -1
  450. package/workflows/registration/provisionedPrincipalHistory.js.map +1 -1
  451. package/workflows/registration/provisionedProfileDocument.js +1 -1
  452. package/workflows/registration/provisionedProfileDocument.js.map +1 -1
  453. package/workflows/registration/provisioningBootstrapBuilders.js +2 -2
  454. package/workflows/registration/provisioningBootstrapBuilders.js.map +1 -1
  455. package/workflows/registration/registerIdentity.js +2 -2
  456. package/workflows/registration/registerIdentity.js.map +1 -1
  457. package/workflows/sync/remoteReset.js +1 -1
  458. package/workflows/sync/remoteReset.js.map +1 -1
  459. package/workflows/blobs/attachmentBindingVerification.js.map +0 -1
  460. package/workflows/blobs/attachmentDecryptor.js.map +0 -1
  461. package/workflows/blobs/attachmentKeyAuthenticator.js.map +0 -1
  462. package/workflows/blobs/automaticMultipartUpload.js.map +0 -1
  463. package/workflows/blobs/blobChunkDecryption.js.map +0 -1
  464. package/workflows/blobs/decrypt.js.map +0 -1
  465. package/workflows/blobs/hydrate.js.map +0 -1
  466. package/workflows/blobs/hydrationResults.js.map +0 -1
  467. package/workflows/blobs/multipartFirstParts.js.map +0 -1
  468. package/workflows/blobs/multipartStageFailures.js.map +0 -1
  469. package/workflows/blobs/multipartStageResolution.js.map +0 -1
  470. package/workflows/blobs/multipartUpload.js.map +0 -1
  471. package/workflows/blobs/retainedAttachmentVerification.js.map +0 -1
  472. package/workflows/blobs/upload.js.map +0 -1
  473. package/workflows/blobs/verifiedWrapScope.js.map +0 -1
  474. package/workflows/blobs/writerProjection.js.map +0 -1
  475. package/workflows/documents/attachmentPersistence.js.map +0 -1
  476. package/workflows/documents/blobMutationLock.js.map +0 -1
  477. package/workflows/documents/create.js.map +0 -1
  478. package/workflows/documents/createAdoption.js.map +0 -1
  479. package/workflows/documents/createProjectionFetch.js.map +0 -1
  480. package/workflows/documents/createResponse.js.map +0 -1
  481. package/workflows/documents/documentCreationPersistence.js.map +0 -1
  482. package/workflows/documents/initialSync.js.map +0 -1
  483. package/workflows/documents/linkSet.js.map +0 -1
  484. package/workflows/documents/linkSetAuthority.js.map +0 -1
  485. package/workflows/documents/linkSetBlobRewraps.js.map +0 -1
  486. package/workflows/documents/linkSetProjectionSeed.js.map +0 -1
  487. package/workflows/documents/linkSetRemote.js.map +0 -1
  488. package/workflows/documents/orphanBlobReclaimState.js.map +0 -1
  489. package/workflows/documents/orphanBlobReclaims.js.map +0 -1
  490. package/workflows/documents/persistedDocumentRemoval.js.map +0 -1
  491. package/workflows/documents/purge.js.map +0 -1
  492. package/workflows/documents/readOnlyProjectionFailure.js.map +0 -1
  493. package/workflows/documents/readOnlySync.js.map +0 -1
  494. package/workflows/documents/reportDocumentSyncQuarantine.js.map +0 -1
  495. package/workflows/documents/subtreePurgeScope.js.map +0 -1
  496. package/workflows/documents/sync.js.map +0 -1
  497. package/workflows/documents/syncAbandon.js.map +0 -1
  498. package/workflows/documents/syncAttemptPlanning.js.map +0 -1
  499. package/workflows/documents/syncAttemptState.js.map +0 -1
  500. package/workflows/documents/syncAutomaticContainerRekeys.js.map +0 -1
  501. package/workflows/documents/syncContainerRekeyPreparation.js.map +0 -1
  502. package/workflows/documents/syncContainerRekeyProjection.js.map +0 -1
  503. package/workflows/documents/syncContainerRekeys.js.map +0 -1
  504. package/workflows/documents/syncContentKeys.js.map +0 -1
  505. package/workflows/documents/syncFailureClassification.js.map +0 -1
  506. package/workflows/documents/syncFailures.js.map +0 -1
  507. package/workflows/documents/syncLane.js.map +0 -1
  508. package/workflows/documents/syncPlanIdentity.js.map +0 -1
  509. package/workflows/documents/syncPlanMaterial.js.map +0 -1
  510. package/workflows/documents/syncPlanProjection.js.map +0 -1
  511. package/workflows/documents/syncPlanRequestBounds.js.map +0 -1
  512. package/workflows/documents/syncPolicyRepair.js.map +0 -1
  513. package/workflows/documents/syncRecoveryRekey.js.map +0 -1
  514. package/workflows/documents/syncRepairAbandon.js.map +0 -1
  515. package/workflows/documents/syncRepairAccess.js.map +0 -1
  516. package/workflows/documents/syncResponseResult.js.map +0 -1
  517. package/workflows/documents/syncSubmittedResult.js.map +0 -1
  518. package/workflows/organizations/acknowledgedDirectoryBindings.js.map +0 -1
  519. package/workflows/organizations/authoredPrincipalPolicyWarmer.js.map +0 -1
  520. package/workflows/organizations/commitCurrentGroupPolicyMutation.js.map +0 -1
  521. package/workflows/organizations/createCurrentOrganizationGroup.js.map +0 -1
  522. package/workflows/organizations/createOrganization.js.map +0 -1
  523. package/workflows/organizations/currentGroupMetadataAuthority.js.map +0 -1
  524. package/workflows/organizations/currentGroupMutationReferences.js.map +0 -1
  525. package/workflows/organizations/currentGroupPolicyMutationContext.js.map +0 -1
  526. package/workflows/organizations/currentOrganizationGroupNames.js.map +0 -1
  527. package/workflows/organizations/currentOrganizationMutationAuthority.js.map +0 -1
  528. package/workflows/organizations/currentOrganizationMutationRetention.js.map +0 -1
  529. package/workflows/organizations/currentPolicyMutationAcknowledgement.js.map +0 -1
  530. package/workflows/organizations/currentPrincipalMutationLease.js.map +0 -1
  531. package/workflows/organizations/dataUsageReadModel.js.map +0 -1
  532. package/workflows/organizations/deleteCurrentOrganizationGroup.js.map +0 -1
  533. package/workflows/organizations/deleteOrganizationGroup.js.map +0 -1
  534. package/workflows/organizations/groupCreation.js.map +0 -1
  535. package/workflows/organizations/groupMembershipName.js.map +0 -1
  536. package/workflows/organizations/groupMetadataAccess.js.map +0 -1
  537. package/workflows/organizations/groupMetadataBinding.js.map +0 -1
  538. package/workflows/organizations/groupMetadataContainerAuthority.js.map +0 -1
  539. package/workflows/organizations/groupMetadataRootBinding.js.map +0 -1
  540. package/workflows/organizations/groupMetadataRuntime.js.map +0 -1
  541. package/workflows/organizations/groupNameUniqueness.js.map +0 -1
  542. package/workflows/organizations/groupPolicyHistoryPage.js.map +0 -1
  543. package/workflows/organizations/groupPolicyMutationAcknowledgement.js.map +0 -1
  544. package/workflows/organizations/groupPolicyMutationContext.js.map +0 -1
  545. package/workflows/organizations/groupPolicyMutationEvidence.js.map +0 -1
  546. package/workflows/organizations/groupPolicyRequests.js.map +0 -1
  547. package/workflows/organizations/groupPolicyVerification.js.map +0 -1
  548. package/workflows/organizations/listLocalOrganizations.js.map +0 -1
  549. package/workflows/organizations/loadPolicyHistoryDetails.js.map +0 -1
  550. package/workflows/organizations/localReadModelDetails.js.map +0 -1
  551. package/workflows/organizations/organizationGroupDirectory.js.map +0 -1
  552. package/workflows/organizations/organizationGroupNamePolicies.js.map +0 -1
  553. package/workflows/organizations/organizationGroupNames.js.map +0 -1
  554. package/workflows/organizations/organizationPolicyHistoryDetails.js.map +0 -1
  555. package/workflows/organizations/organizationPolicyHistoryVerification.js.map +0 -1
  556. package/workflows/organizations/organizationPresentationAccessState.js.map +0 -1
  557. package/workflows/organizations/organizationProvisioningAttempt.js.map +0 -1
  558. package/workflows/organizations/organizationReplacementVerification.js.map +0 -1
  559. package/workflows/organizations/policyHistoryAccessDenial.js.map +0 -1
  560. package/workflows/organizations/policyHistoryCache.js.map +0 -1
  561. package/workflows/organizations/precedingPrincipalRematerialization.js.map +0 -1
  562. package/workflows/organizations/principalContainerRematerialization.js.map +0 -1
  563. package/workflows/organizations/principalContainerRematerializationPlanning.js.map +0 -1
  564. package/workflows/organizations/principalContainerRematerializationTargets.js.map +0 -1
  565. package/workflows/organizations/principalMutationJournalManagement.js.map +0 -1
  566. package/workflows/organizations/principalMutationJournalSession.js.map +0 -1
  567. package/workflows/organizations/principalMutationReceipt.js.map +0 -1
  568. package/workflows/organizations/principalOperationReceipt.js.map +0 -1
  569. package/workflows/organizations/principalPolicy.js.map +0 -1
  570. package/workflows/organizations/principalPolicyApi.js.map +0 -1
  571. package/workflows/organizations/principalPolicyReceiptArtifacts.js.map +0 -1
  572. package/workflows/organizations/principalPolicyRecipients.js.map +0 -1
  573. package/workflows/organizations/readModel.js.map +0 -1
  574. package/workflows/organizations/readModelProjection.js.map +0 -1
  575. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.d.ts +0 -6
  576. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js.map +0 -1
  577. package/workflows/organizations/runtimeCurrentGroupMutation.js.map +0 -1
  578. package/workflows/organizations/runtimeCurrentOrganizationMutation.js.map +0 -1
  579. package/workflows/organizations/runtimeGroupMetadataAuthority.js.map +0 -1
  580. package/workflows/organizations/submitGroupPolicyCommit.js.map +0 -1
  581. package/workflows/principals/acknowledgedPrincipalCurrents.js.map +0 -1
  582. package/workflows/principals/acknowledgedPrincipalPredecessor.js.map +0 -1
  583. package/workflows/principals/initialPrincipalCurrentPublication.js.map +0 -1
  584. package/workflows/principals/loadRecoveredPrincipalHistoryPage.js.map +0 -1
  585. package/workflows/principals/policyCache.js.map +0 -1
  586. package/workflows/principals/principalCurrentPublicationSeal.js.map +0 -1
  587. package/workflows/principals/principalCurrentRecoveryBatch.js.map +0 -1
  588. package/workflows/principals/principalHistoryRecoveryAuthority.js.map +0 -1
  589. package/workflows/principals/principalHistoryRecoveryPrefix.js.map +0 -1
  590. package/workflows/principals/principalHistoryRecoveryReferences.js.map +0 -1
  591. package/workflows/principals/principalHistoryRecoveryStage.js.map +0 -1
  592. package/workflows/principals/principalHistoryRecoveryTypes.js.map +0 -1
  593. package/workflows/principals/principalPolicyCacheAdvance.js.map +0 -1
  594. package/workflows/principals/principalPolicyCacheValidation.js.map +0 -1
  595. package/workflows/principals/principalPolicyOrganizationScope.js.map +0 -1
  596. package/workflows/principals/principalRecoveryDirectory.js.map +0 -1
  597. package/workflows/principals/principalRecoveryDiscoveryPage.js.map +0 -1
  598. package/workflows/principals/principalRecoveryLocalPreference.js.map +0 -1
  599. package/workflows/principals/principalRecoveryMemo.js.map +0 -1
  600. package/workflows/principals/principalRecoveryMemoValidity.js.map +0 -1
  601. package/workflows/principals/principalRecoveryOutage.js.map +0 -1
  602. package/workflows/principals/publicPrincipalHistoryAuthority.js.map +0 -1
  603. package/workflows/principals/publicPrincipalHistoryPage.js.map +0 -1
  604. package/workflows/principals/publicPrincipalHistoryProgress.js.map +0 -1
  605. package/workflows/principals/publicPrincipalHistoryTypes.js.map +0 -1
  606. package/workflows/principals/publicProjectionDirectory.js.map +0 -1
  607. package/workflows/principals/publicProjectionPrincipal.js.map +0 -1
  608. package/workflows/principals/reconcileAcknowledgedPrincipalCurrent.js.map +0 -1
  609. package/workflows/principals/recoverCurrentOrganizationPolicy.js.map +0 -1
  610. package/workflows/principals/recoverPrincipalPolicyHistory.js.map +0 -1
  611. package/workflows/principals/recoverProjectionPolicyHistory.js.map +0 -1
  612. package/workflows/principals/recoverPublicPrincipalHistory.js.map +0 -1
  613. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js.map +0 -1
  614. package/workflows/principals/selectPublicPrincipalHistory.js.map +0 -1
  615. /package/workflows/blobs/{readAttachmentTransfer.js → hydration/readAttachmentTransfer.js} +0 -0
  616. /package/workflows/blobs/{readAttachmentTransfer.js.map → hydration/readAttachmentTransfer.js.map} +0 -0
  617. /package/workflows/blobs/{multipartStageResolution.js → upload/multipartStageResolution.js} +0 -0
  618. /package/workflows/documents/{attachmentPersistence.js → attachments/attachmentPersistence.js} +0 -0
  619. /package/workflows/documents/{orphanBlobReclaimState.js → attachments/orphanBlobReclaimState.js} +0 -0
  620. /package/workflows/documents/{createProjection.js → create/createProjection.js} +0 -0
  621. /package/workflows/documents/{createProjection.js.map → create/createProjection.js.map} +0 -0
  622. /package/workflows/documents/{createProjectionFetch.js → create/createProjectionFetch.js} +0 -0
  623. /package/workflows/documents/{reportDocumentSyncQuarantine.js → sync/reportDocumentSyncQuarantine.js} +0 -0
  624. /package/workflows/documents/{syncAttemptState.js → sync/syncAttemptState.js} +0 -0
  625. /package/workflows/documents/{syncTrace.d.ts → sync/syncTrace.d.ts} +0 -0
  626. /package/workflows/documents/{syncTrace.js.map → sync/syncTrace.js.map} +0 -0
  627. /package/workflows/documents/{syncFailureClearance.d.ts → syncFailures/syncFailureClearance.d.ts} +0 -0
  628. /package/workflows/documents/{syncFailureClearance.js → syncFailures/syncFailureClearance.js} +0 -0
  629. /package/workflows/documents/{syncFailureClearance.js.map → syncFailures/syncFailureClearance.js.map} +0 -0
  630. /package/workflows/documents/{syncRepairAbandon.js → syncFailures/syncRepairAbandon.js} +0 -0
  631. /package/workflows/documents/{syncPlanProjection.js → syncPlan/syncPlanProjection.js} +0 -0
  632. /package/workflows/documents/{syncRekeyCommit.js.map → syncRekeys/syncRekeyCommit.js.map} +0 -0
  633. /package/workflows/organizations/{groupMetadataErrors.js.map → groupMetadata/groupMetadataErrors.js.map} +0 -0
  634. /package/workflows/organizations/{groupMutationAuthorization.js → groupPolicy/groupMutationAuthorization.js} +0 -0
  635. /package/workflows/organizations/{groupMutationAuthorization.js.map → groupPolicy/groupMutationAuthorization.js.map} +0 -0
  636. /package/workflows/organizations/{groupPolicyMutationHead.js.map → groupPolicy/groupPolicyMutationHead.js.map} +0 -0
  637. /package/workflows/organizations/{groupPolicyHistoryPage.js → policyHistory/groupPolicyHistoryPage.js} +0 -0
  638. /package/workflows/organizations/{policyHistoryReadModel.js → policyHistory/policyHistoryReadModel.js} +0 -0
  639. /package/workflows/organizations/{policyHistoryReadModel.js.map → policyHistory/policyHistoryReadModel.js.map} +0 -0
  640. /package/workflows/organizations/{policyHistoryTypes.js → policyHistory/policyHistoryTypes.js} +0 -0
  641. /package/workflows/organizations/{policyHistoryTypes.js.map → policyHistory/policyHistoryTypes.js.map} +0 -0
  642. /package/workflows/organizations/{principalPolicyApi.js → principalPolicy/principalPolicyApi.js} +0 -0
  643. /package/workflows/organizations/{principalPolicyRequest.js.map → principalPolicy/principalPolicyRequest.js.map} +0 -0
  644. /package/workflows/organizations/{organizationPresentationFailures.js.map → readModel/organizationPresentationFailures.js.map} +0 -0
  645. /package/workflows/principals/{principalAcknowledgementChecks.js → acknowledgements/principalAcknowledgementChecks.js} +0 -0
  646. /package/workflows/principals/{principalAcknowledgementChecks.js.map → acknowledgements/principalAcknowledgementChecks.js.map} +0 -0
  647. /package/workflows/principals/{principalHistoryRecoveryVerification.js.map → historyRecovery/principalHistoryRecoveryVerification.js.map} +0 -0
  648. /package/workflows/principals/{recoverPrincipalHistoryPage.js.map → historyRecovery/recoverPrincipalHistoryPage.js.map} +0 -0
  649. /package/workflows/principals/{recoverPrincipalPolicyHistory.d.ts → historyRecovery/recoverPrincipalPolicyHistory.d.ts} +0 -0
  650. /package/workflows/principals/{principalPolicyCacheScope.js → policyCache/principalPolicyCacheScope.js} +0 -0
  651. /package/workflows/principals/{principalPolicyCacheScope.js.map → policyCache/principalPolicyCacheScope.js.map} +0 -0
  652. /package/workflows/principals/{publicPrincipalHistoryTypes.js → publicHistory/publicPrincipalHistoryTypes.js} +0 -0
  653. /package/workflows/principals/{principalRecoveryDiscoveryPage.js → recoveryOperation/principalRecoveryDiscoveryPage.js} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncPlanIdentity.js","sourceRoot":"","sources":["syncPlanIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,mCAAmC,EACnC,mCAAmC,EACnC,eAAe,GAEhB,MAAM,mBAAmB,CAAC;AAO3B,OAAO,EACL,sCAAsC,EACtC,kCAAkC,EAClC,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,SAAS,8BAA8B,CACrC,KAAiD;IAEjD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,CAAC;IAC/C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,KAAK,UAAU,2BAA2B,CACxC,KAAiC;IAOjC,MAAM,gBAAgB,GAAG,MAAM,sCAAsC,CAAC;QACpE,MAAM,EAAE,KAAK,CAAC,gBAAgB;QAC9B,KAAK,EAAE,wBAAwB;KAChC,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,gBAAgB,CAAC,UAAU,CAAC;IACzE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,C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D,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAC/D,eAAe;QACf,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC;QAC3E,sBAAsB,EAAE,IAAI;KAC7B,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe;QACvD,UAAU;QACV,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,2BAA2B;QAC3B,kBAAkB;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,cAAc;QACd,OAAO;QACP,sBAAsB,EAAE,KAAK,CAAC,gBAAgB;KAC/C,CAAC;AACJ,CAAC","sourcesContent":["import {\n CONTENT_RECORD_ENCRYPTION_SUITE,\n computeContentRecordNonceDomainHash,\n computeDocumentContentKeyTargetHash,\n signWriteHeader,\n type UnsignedWriteHeader,\n} from \"@tearleads/crypto\";\nimport type {\n ContainerManifestRef,\n DocumentOutgoingUpdate,\n DocumentSyncRequest,\n} from \"@tearleads/validators/request\";\nimport type { DocumentCreateResponse } from \"@tearleads/validators/response\";\nimport {\n assertDocumentManifestBundleConsistent,\n normalizeDocumentKekTargetResponse,\n serializeCanonical,\n sortDocumentTargets,\n targetEnvelopeReference,\n} from \"../../data/documents/shared/readers\";\nimport type {\n BuildDocumentSyncPlanInput,\n DocumentCreateAuthor,\n DocumentSyncPlan,\n DocumentSyncPreparedUpdate,\n} from \"../../data/documents/shared/types\";\nimport { readCanonicalRecord } from \"../../data/keying/canonicalJson\";\n\nfunction contentKeyBundleForSyncRequest(\n input: DocumentCreateResponse[\"contentKeyBundle\"],\n): NonNullable<DocumentSyncRequest[\"contentKeyBundle\"]> {\n const { documentId: _omit, ...bundle } = input;\n return bundle;\n}\n\nasync function resolveDocumentSyncIdentity(\n input: BuildDocumentSyncPlanInput,\n): Promise<{\n documentId: string;\n expectedLinkSetManifestHash: string;\n expectedTargetHash: string;\n organizationId: string;\n}> {\n const manifestIdentity = await assertDocumentManifestBundleConsistent({\n bundle: input.documentManifest,\n label: \"Document sync manifest\",\n });\n const documentId = input.documentId ?? input.contentKeyBundle.documentId;\n if (documentId.length === 0) {\n throw new Error(\"Document sync document id is empty\");\n }\n if (\n input.contentKeyBundle.documentId !== documentId ||\n input.documentKekTargets.documentId !== documentId ||\n manifestIdentity.documentId !== documentId\n ) {\n throw new Error(\"Document sync state document id mismatch\");\n }\n if (manifestIdentity.organizationId !== input.author.organizationId) {\n throw new Error(\"Document sync author organization mismatch\");\n }\n if (\n input.documentManifest.manifestHash !==\n input.contentKeyBundle.linkSetManifestHash ||\n input.documentKekTargets.linkSetManifestHash !==\n input.contentKeyBundle.linkSetManifestHash\n ) {\n throw new Error(\"Document sync link manifest mismatch\");\n }\n if (\n input.documentKekTargets.documentKeyTargetHash !==\n input.contentKeyBundle.targetHash\n ) {\n throw new Error(\"Document sync target hash mismatch\");\n }\n\n const kekTargets = normalizeDocumentKekTargetResponse(\n input.documentKekTargets,\n );\n const contentKeyTargets = sortDocumentTargets(\n input.contentKeyBundle.targets.map(targetEnvelopeReference),\n );\n if (\n serializeCanonical(kekTargets, \"KEK targets\") !==\n serializeCanonical(contentKeyTargets, \"content-key targets\")\n ) {\n throw new Error(\"Document sync content-key targets mismatch\");\n }\n\n const targetHash = await computeDocumentContentKeyTargetHash(kekTargets);\n if (targetHash !== input.contentKeyBundle.targetHash) {\n throw new Error(\"Document sync target hash is not canonical\");\n }\n\n return {\n documentId,\n expectedLinkSetManifestHash: input.contentKeyBundle.linkSetManifestHash,\n expectedTargetHash: input.contentKeyBundle.targetHash,\n organizationId: manifestIdentity.organizationId,\n };\n}\n\nfunction normalizeAuthorizingContainerPathRefs(\n refs: readonly (readonly ContainerManifestRef[])[] | undefined,\n): ContainerManifestRef[][] {\n if (!refs || refs.length === 0) {\n throw new Error(\"Document sync write authorization path refs are missing\");\n }\n\n return refs.map((path, pathIndex) => {\n if (path.length === 0) {\n throw new Error(\n `Document sync write authorization path[${pathIndex}] is empty`,\n );\n }\n return [...path];\n });\n}\n\nexport async function signDocumentOutgoingUpdate(input: {\n authorizingContainerPathRefs: readonly (readonly ContainerManifestRef[])[];\n author: DocumentCreateAuthor;\n contentKeyEpoch: number;\n documentId: string;\n expectedLinkSetManifestHash: string;\n expectedTargetHash: string;\n organizationId: string;\n signedAt: string;\n update: DocumentSyncPreparedUpdate;\n}): Promise<DocumentOutgoingUpdate> {\n const contentRecordId = input.update.contentRecordId ?? input.update.id;\n const nonceDomain = {\n version: 1,\n organizationId: input.organizationId,\n objectKind: \"document\",\n objectId: input.documentId,\n contentKeyEpoch: input.contentKeyEpoch,\n encryptionSuite: CONTENT_RECORD_ENCRYPTION_SUITE,\n contentRecordId,\n } as const;\n const unsignedHeader: UnsignedWriteHeader = {\n ...nonceDomain,\n dependencyManifestHashes: [\n ...new Set(\n input.authorizingContainerPathRefs.flatMap((path) =>\n path.map((ref) => ref.manifestHash),\n ),\n ),\n ].sort(),\n accessManifestHash: input.expectedLinkSetManifestHash,\n targetHash: input.expectedTargetHash,\n nonceDomainHash: await computeContentRecordNonceDomainHash(nonceDomain),\n metadataHash: input.update.metadataHash,\n ciphertextHash: input.update.ciphertextHash,\n writerUserId: input.author.signerUserId,\n writerDeviceId: input.author.signerDeviceId,\n writerKeyFingerprint: input.author.signerKeyFingerprint,\n signedAt: input.update.signedAt ?? input.signedAt,\n };\n const writeHeader = await signWriteHeader(\n unsignedHeader,\n input.author.signerPrivateKey,\n );\n\n return {\n ...(input.update.checkpointKind === undefined\n ? {}\n : { checkpointKind: input.update.checkpointKind }),\n ...(input.update.checkpointPayloadKind === undefined\n ? {}\n : { checkpointPayloadKind: input.update.checkpointPayloadKind }),\n id: input.update.id,\n encryptedData: input.update.encryptedData,\n partialStartVersionVector: input.update.partialStartVersionVector,\n partialEndVersionVector: input.update.partialEndVersionVector,\n plaintextHash: input.update.plaintextHash,\n ...(input.update.sourceVersionVector === undefined\n ? {}\n : { sourceVersionVector: input.update.sourceVersionVector }),\n writeHeader: readCanonicalRecord(\n writeHeader,\n \"Document outgoing write header\",\n ),\n };\n}\n\nfunction assertUniqueDocumentOutgoingUpdates(\n updates: readonly DocumentSyncPreparedUpdate[],\n): void {\n const updateIds = new Set<string>();\n const contentRecordIds = new Set<string>();\n for (const update of updates) {\n if (updateIds.has(update.id)) {\n throw new Error(\"Document sync update id is duplicated\");\n }\n updateIds.add(update.id);\n\n const contentRecordId = (update.contentRecordId ?? update.id).toLowerCase();\n if (contentRecordIds.has(contentRecordId)) {\n throw new Error(\"Document sync content record id is duplicated\");\n }\n contentRecordIds.add(contentRecordId);\n }\n}\n\nfunction assertDocumentSyncRequestMode(\n input: BuildDocumentSyncPlanInput,\n hasContainerRekeys: boolean,\n hasOutgoingUpdates: boolean,\n): void {\n if (input.historyMode === \"raw\" && input.localVersionVector !== null) {\n throw new Error(\n \"Document raw-history sync must start from a null version vector\",\n );\n }\n const hasWrites = hasOutgoingUpdates || hasContainerRekeys;\n if (input.historyMode === \"raw\" && hasWrites) {\n throw new Error(\"Document raw-history sync must be read-only\");\n }\n if (input.pullCursor !== undefined && hasWrites) {\n throw new Error(\"Document sync continuation must be read-only\");\n }\n if (hasContainerRekeys && !hasOutgoingUpdates) {\n throw new Error(\n \"Document sync container rekeys require an outgoing update\",\n );\n }\n if (hasContainerRekeys !== (input.inlineRekeyCommitId !== undefined)) {\n throw new Error(\n \"Document sync inline rekey commit id must accompany container rekeys\",\n );\n }\n}\n\nexport async function buildDocumentSyncPlan(\n input: BuildDocumentSyncPlanInput,\n): Promise<DocumentSyncPlan> {\n const {\n documentId,\n expectedLinkSetManifestHash,\n expectedTargetHash,\n organizationId,\n } = await resolveDocumentSyncIdentity(input);\n const containerRekeys = [...(input.containerRekeys ?? [])];\n const outgoingUpdateInputs = [...(input.outgoingUpdates ?? [])];\n assertDocumentSyncRequestMode(\n input,\n containerRekeys.length > 0,\n outgoingUpdateInputs.length > 0,\n );\n const signedAt = input.signedAt ?? new Date().toISOString();\n assertUniqueDocumentOutgoingUpdates(outgoingUpdateInputs);\n\n const outgoingUpdates = await Promise.all(\n outgoingUpdateInputs.map((update) =>\n signDocumentOutgoingUpdate({\n authorizingContainerPathRefs: normalizeAuthorizingContainerPathRefs(\n input.authorizingContainerPathRefs,\n ),\n author: input.author,\n contentKeyEpoch: input.contentKeyBundle.contentKeyEpoch,\n documentId,\n expectedLinkSetManifestHash,\n expectedTargetHash,\n organizationId,\n signedAt,\n update,\n }),\n ),\n );\n // Writes always carry the verified current content-key bundle so the server\n // can validate and materialize the current wrapping material in the same\n // request. Read-only syncs omit it because they do not update server state.\n const shouldIncludeContentKeyBundle = outgoingUpdates.length > 0;\n const request: DocumentSyncRequest = {\n ...(shouldIncludeContentKeyBundle\n ? {\n contentKeyBundle: contentKeyBundleForSyncRequest(\n input.contentKeyBundle,\n ),\n }\n : {}),\n ...(containerRekeys.length === 0 ? {} : { containerRekeys }),\n contentKeyEpoch: input.contentKeyBundle.contentKeyEpoch,\n ...(outgoingUpdates.length === 0\n ? {}\n : {\n authorizingContainerPathRefs: normalizeAuthorizingContainerPathRefs(\n input.authorizingContainerPathRefs,\n ),\n }),\n expectedLinkSetManifestHash,\n expectedTargetHash,\n ...(input.historyMode === undefined\n ? {}\n : { historyMode: input.historyMode }),\n ...(input.inlineRekeyCommitId === undefined\n ? {}\n : { inlineRekeyCommitId: input.inlineRekeyCommitId }),\n localVersionVector: input.localVersionVector,\n ...(input.minLsn === undefined ? {} : { minLsn: input.minLsn }),\n outgoingUpdates,\n ...(input.pullCursor === undefined ? {} : { pullCursor: input.pullCursor }),\n supportsPullPagination: true,\n };\n\n return {\n contentKeyEpoch: input.contentKeyBundle.contentKeyEpoch,\n documentId,\n documentKekTargets: input.documentKekTargets,\n documentManifest: input.documentManifest,\n expectedLinkSetManifestHash,\n expectedTargetHash,\n minLsn: input.minLsn,\n organizationId,\n request,\n sourceContentKeyBundle: input.contentKeyBundle,\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncPlanMaterial.js","sourceRoot":"","sources":["syncPlanMaterial.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,sCAAsC,EAAE,MAAM,gCAAgC,CAAC;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,6BAA6B,EAAE,MAAM,kDAAkD,CAAC;AACjG,OAAO,EACL,wCAAwC,EACxC,4BAA4B,EAC5B,oCAAoC,EACpC,mCAAmC,EACnC,mCAAmC,EACnC,+BAA+B,EAC/B,kCAAkC,GACnC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,sCAAsC,EAAE,MAAM,qCAAqC,CAAC;AAO7F,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAIlF,OAAO,EAAE,+BAA+B,EAAE,MAAM,2CAA2C,CAAC;AAC5F,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAEL,2BAA2B,EAC3B,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AACH,KAAK,UAAU,uCAAuC,CACpD,qBAAqE;IAErE,MAAM,QAAQ,GAAG,qBAAqB,CAAC,CAAC,CA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d,CAAC;IACD,MAAM,EACJ,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GACf,GAAG,QAAQ,CAAC;IACb,MAAM,eAAe,GAAG,MAAM,8BAA8B,CAAC;QAC3D,UAAU;QACV,eAAe,EAAE,gBAAgB,CAAC,eAAe;QACjD,UAAU;QACV,cAAc,EAAE,gBAAgB,CAAC,cAAc;QAC/C,cAAc;KACf,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC;QAC3C,MAAM,EAAE;YACN,GAAG,KAAK,CAAC,MAAM;YACf,cAAc,EAAE,gBAAgB,CAAC,cAAc;SAChD;QACD,4BAA4B,EAAE,4BAA4B,CACxD,KAAK,CAAC,gBAAgB,CACvB;QACD,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,gBAAgB;QAChB,UAAU;QACV,kBAAkB;QAClB,gBAAgB;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,mBAAmB,EAAE,KAAK,CAAC,mBAAmB;QAC9C,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,eAAe;QACf,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC,CAAC;IACH,OAAO,oCAAoC,CAAC;QAC1C,QAAQ;QACR,QAAQ;QACR,mBAAmB;QACnB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;KACzC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n VerifiedContainerAccessManifest,\n VerifiedPrincipalPolicy,\n} from \"@tearleads/crypto\";\nimport {\n emptyVersionVector,\n getImportBlobMetadata,\n satisfiesVersionVector,\n versionVectorsEqual,\n} from \"@tearleads/loro\";\nimport type {\n DocumentCreateResponse,\n DocumentSyncResponse,\n DocumentWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { documentKekTargetsFromContentKeyBundle } from \"@tearleads/validators/response\";\nimport { createPendingUpdateFields } from \"../../data/documents/documentSync\";\nimport { assertDocumentKekPathsCurrent } from \"../../data/documents/shared/containerKekCurrency\";\nimport {\n assertDocumentWriterProjectionConsistent,\n authorizingContainerPathRefs,\n buildRotatedDocumentContentKeyBundle,\n ContainerKekHistoryUnavailableError,\n collectContainerKeksForDocumentSync,\n DocumentHistoryUnavailableError,\n unwrapDocumentContentKeyFromBundle,\n} from \"../../data/documents/shared/projection\";\nimport { assertDocumentManifestBundleConsistent } from \"../../data/documents/shared/readers\";\nimport type {\n BuildDocumentSyncPlanInput,\n DocumentCreateAuthor,\n MaterializedDocumentSyncPlan,\n ProjectionVerificationOptions,\n} from \"../../data/documents/shared/types\";\nimport { projectionVerificationOptions } from \"../../data/documents/shared/types\";\nimport type { DocumentWriterProjectionAuthorization } from \"../../data/keyingProjectionVerification\";\nimport type { PendingUpdateRecord } from \"../../data/sqlite/documentPersistence\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport { selectDocumentSyncOutgoingBatch } from \"../../data/sync/documentSyncOutgoingBatch\";\nimport { prepareDocumentOutgoingUpdates } from \"./syncContentKeys\";\nimport { buildDocumentSyncPlan } from \"./syncPlanIdentity\";\nimport { finalizeMaterializedDocumentSyncPlan } from \"./syncPlanProjection\";\nimport {\n type DocumentSyncTraceEmitter,\n traceCheckpointRegeneration,\n traceHealBlocked,\n traceHealPlanned,\n traceStaleBundle,\n traceStaleRead,\n} from \"./syncTrace\";\n\n/**\n * Builds the rotation baseline that anchors a stale-bundle heal: a full\n * history snapshot of the local document, re-encrypted under the fresh\n * content key so every current member (including post-rotation newcomers)\n * has an efficient current-epoch redirect. Predecessor KEKs remain the\n * correctness path when no covering baseline exists.\n */\nasync function buildStaleRecoveryBaselinePendingUpdate(\n buildRotationSnapshot: (() => Promise<Uint8Array | null>) | undefined,\n): Promise<PendingUpdateRecord> {\n const snapshot = buildRotationSnapshot ? await buildRotationSnapshot() : null;\n if (!snapshot) {\n throw new Error(\n \"Document content-key bundle is stale and no rotation snapshot is available to heal it\",\n );\n }\n const metadata = getImportBlobMetadata(snapshot);\n if (\n metadata.mode !== \"snapshot\" ||\n !versionVectorsEqual(\n metadata.partialStartVersionVector,\n emptyVersionVector(),\n )\n ) {\n throw new Error(\n \"Document stale-bundle recovery requires a full-history rotation snapshot\",\n );\n }\n const pendingFields = createPendingUpdateFields(\n snapshot,\n metadata.partialEndVersionVector,\n );\n if (!pendingFields) {\n throw new Error(\"Document stale-bundle recovery snapshot is empty\");\n }\n\n return {\n id: crypto.randomUUID(),\n ...pendingFields,\n };\n}\n\n/**\n * Resolves the content material a sync plan encrypts and carries. A stale\n * bundle names predecessor KEK targets while the document's current targets\n * name successor epochs, so it splits by intent: a write-bearing pass heals\n * the document with a FRESH content key at the next epoch, anchored by a\n * covering rotation baseline, while a read-only pass keeps the stale pair and\n * unwraps it through predecessor KEKs so the server can settle a complete pull.\n */\n/**\n * The manifest bundle a stale read-only plan must pair with: the one the\n * stale content-key bundle actually references. A stale bundle normally\n * still carries the current link-set manifest hash (KEK rotations do not\n * advance the document manifest), but the projection consistency check\n * defensively admits a bundle lagging the head as long as it appears in the\n * manifest history — pair with that historical bundle so the plan's own\n * identity checks hold.\n */\nfunction staleBundleDocumentManifest(\n writerProjection: DocumentWriterProjectionResponse,\n): DocumentCreateResponse[\"accessManifest\"] {\n const { contentKeyBundle, documentManifest } = writerProjection;\n if (contentKeyBundle.linkSetManifestHash === documentManifest.manifestHash) {\n return documentManifest;\n }\n const historicalManifest = writerProjection.documentManifestHistory.find(\n (bundle) => bundle.manifestHash === contentKeyBundle.linkSetManifestHash,\n );\n if (!historicalManifest) {\n throw new Error(\n \"Document stale bundle manifest is missing from the projection history\",\n );\n }\n return historicalManifest;\n}\n\n/**\n * Settling a superseded checkpoint deletes its queue row, so the fresh\n * baseline must PROVABLY subsume it — assumed coverage would silently drop\n * any ops the checkpoint alone carried.\n */\nfunction assertRecoveryBaselineCoversCheckpoints(\n recoveryBaseline: PendingUpdateRecord,\n checkpoints: readonly PendingUpdateRecord[],\n): void {\n for (const checkpoint of checkpoints) {\n if (\n !satisfiesVersionVector(\n recoveryBaseline.partialEndVersionVector,\n checkpoint.partialEndVersionVector,\n )\n ) {\n throw new Error(\n \"Document stale-bundle recovery snapshot does not cover a queued rotation checkpoint\",\n );\n }\n }\n}\n\ninterface ResolvedSyncPlanContentMaterial {\n contentKey: Uint8Array;\n contentKeyBundle: DocumentCreateResponse[\"contentKeyBundle\"];\n documentKekTargets: DocumentSyncResponse[\"documentKekTargets\"];\n documentManifest: DocumentCreateResponse[\"accessManifest\"];\n healedStaleContentKeyBundle: boolean;\n heldBackPendingUpdateIds: readonly string[];\n pendingUpdates: readonly PendingUpdateRecord[];\n staleRecoveryBaselineUpdateId?: string;\n}\n\nasync function resolveStaleHealMaterial(\n input: Parameters<typeof buildMaterializedDocumentSyncPlan>[0],\n containerKeksByEpochId: ReadonlyMap<string, Uint8Array>,\n pendingUpdates: readonly PendingUpdateRecord[],\n): Promise<ResolvedSyncPlanContentMaterial> {\n const contentKey = crypto.getRandomValues(new Uint8Array(32));\n // A rotation checkpoint left in the queue by an interrupted earlier\n // recovery is superseded by the fresh covering baseline built below:\n // submitting it alongside would trip the server's covering-baseline gate,\n // and resubmitting it after the heal could become the latest baseline at\n // the healed epoch and mask the covering one. Hold it out of the request;\n // on heal success its id is reported settled (the committed baseline\n // subsumes its full-history content) so the queue row is removed.\n //\n // A heal whose OWN baseline does not cover the committed frontier is\n // rejected by that same gate and surfaces as a terminal queue failure.\n // This write-bearing pass does not pull first. A device missing committed\n // history can independently rematerialize it through predecessor KEKs on a\n // read-only pass, then retry with a covering snapshot. The coverage proof\n // prevents a partial local view from becoming the redirect baseline.\n const ordinaryPendingUpdates = pendingUpdates.filter(\n (update) => update.sourceVersionVector == null,\n );\n const heldBackCheckpoints = pendingUpdates.filter(\n (update) => update.sourceVersionVector != null,\n );\n const recoveryBaseline = await buildStaleRecoveryBaselinePendingUpdate(\n input.buildRotationSnapshot,\n );\n const selectedOrdinaryPendingUpdates = selectDocumentSyncOutgoingBatch(\n ordinaryPendingUpdates,\n {\n reservedDataCharacters: recoveryBaseline.updateData.length,\n reservedUpdateCount: 1,\n },\n );\n assertRecoveryBaselineCoversCheckpoints(\n recoveryBaseline,\n heldBackCheckpoints,\n );\n const staleEpoch = input.writerProjection.contentKeyBundle.contentKeyEpoch;\n const contentKeyBundle = await buildRotatedDocumentContentKeyBundle({\n containerKeksByEpochId,\n contentKey,\n writerProjection: input.writerProjection,\n });\n traceHealPlanned(input.onSyncTrace, {\n documentId: input.writerProjection.documentId,\n fromEpoch: staleEpoch,\n heldBack: heldBackCheckpoints.length,\n toEpoch: contentKeyBundle.contentKeyEpoch,\n updates: selectedOrdinaryPendingUpdates.length,\n });\n return {\n contentKey,\n contentKeyBundle,\n documentKekTargets: input.writerProjection.documentKekTargets,\n documentManifest: input.writerProjection.documentManifest,\n healedStaleContentKeyBundle: true,\n heldBackPendingUpdateIds: heldBackCheckpoints.map((update) => update.id),\n pendingUpdates: [recoveryBaseline, ...selectedOrdinaryPendingUpdates],\n staleRecoveryBaselineUpdateId: recoveryBaseline.id,\n };\n}\n\n/**\n * Reactive repair for a healthy-projection pass whose queued rotation\n * checkpoint the server rejected via the covering-baseline gate (a leftover\n * from an interrupted recovery, a heal whose ack was lost, or a lost heal\n * race). Queued checkpoints normally pass through untouched — reset and\n * rotation flows legitimately submit them — but a rejected one would strand\n * the whole queue, and committing it could shrink redirect coverage. Replace\n * the stale checkpoints with one freshly regenerated covering baseline and\n * settle them on success (coverage proven above).\n */\nasync function resolveCheckpointRegenerationMaterial(\n input: Parameters<typeof buildMaterializedDocumentSyncPlan>[0],\n base: ResolvedSyncPlanContentMaterial,\n pendingUpdates: readonly PendingUpdateRecord[],\n): Promise<ResolvedSyncPlanContentMaterial> {\n const ordinaryPendingUpdates = pendingUpdates.filter(\n (update) => update.sourceVersionVector == null,\n );\n const queuedCheckpoints = pendingUpdates.filter(\n (update) => update.sourceVersionVector != null,\n );\n const recoveryBaseline = await buildStaleRecoveryBaselinePendingUpdate(\n input.buildRotationSnapshot,\n );\n const selectedOrdinaryPendingUpdates = selectDocumentSyncOutgoingBatch(\n ordinaryPendingUpdates,\n {\n reservedDataCharacters: recoveryBaseline.updateData.length,\n reservedUpdateCount: 1,\n },\n );\n assertRecoveryBaselineCoversCheckpoints(recoveryBaseline, queuedCheckpoints);\n traceCheckpointRegeneration(input.onSyncTrace, {\n checkpoints: queuedCheckpoints.length,\n documentId: input.writerProjection.documentId,\n updates: selectedOrdinaryPendingUpdates.length,\n });\n return {\n ...base,\n heldBackPendingUpdateIds: queuedCheckpoints.map((update) => update.id),\n pendingUpdates: [recoveryBaseline, ...selectedOrdinaryPendingUpdates],\n staleRecoveryBaselineUpdateId: recoveryBaseline.id,\n };\n}\n\nasync function resolveSyncPlanContentMaterial(\n input: Parameters<typeof buildMaterializedDocumentSyncPlan>[0],\n collectedKeks: Awaited<\n ReturnType<typeof collectContainerKeksForDocumentSync>\n >,\n): Promise<ResolvedSyncPlanContentMaterial> {\n const allPendingUpdates = input.pendingUpdates ?? [];\n if (allPendingUpdates.length > 0 || input.regenerateQueuedCheckpoints) {\n assertDocumentKekPathsCurrent(input.writerProjection);\n }\n const staleContentKeyBundle =\n input.writerProjection.contentKeyBundleStale === true;\n\n if (staleContentKeyBundle && allPendingUpdates.length > 0) {\n traceStaleBundle(input.onSyncTrace, {\n documentId: input.writerProjection.documentId,\n epoch: input.writerProjection.contentKeyBundle.contentKeyEpoch,\n pending: allPendingUpdates.length,\n });\n return resolveStaleHealMaterial(\n input,\n collectedKeks.keksByEpochId,\n allPendingUpdates,\n );\n }\n\n const pendingUpdates = selectDocumentSyncOutgoingBatch(allPendingUpdates);\n\n if (staleContentKeyBundle) {\n traceStaleRead(input.onSyncTrace, {\n documentId: input.writerProjection.documentId,\n epoch: input.writerProjection.contentKeyBundle.contentKeyEpoch,\n });\n // Current access includes every predecessor KEK. If damaged history makes\n // this old bundle unreachable, preserve the bridge-integrity failure: this\n // read actually needs that historical epoch and cannot safely continue.\n let staleContentKey: Uint8Array;\n try {\n staleContentKey = await unwrapDocumentContentKeyFromBundle(\n input.writerProjection.contentKeyBundle,\n input.writerProjection.documentId,\n collectedKeks.keksByEpochId,\n collectedKeks.predecessorFailuresByEpochId,\n collectedKeks.unattributedPredecessorFailuresByContainerId,\n );\n } catch (error) {\n if (error instanceof DocumentHistoryUnavailableError) {\n if (\n input.historyMode !== \"raw\" ||\n !(error.historyCause instanceof ContainerKekHistoryUnavailableError)\n ) {\n throw error;\n }\n }\n // A stale bundle can predate the requester's current authorizing links.\n // Keep the read-only pass alive; served updates that need this absent key\n // remain undecryptable until a spanning member heals the bundle.\n staleContentKey = new Uint8Array();\n }\n return {\n contentKey: staleContentKey,\n contentKeyBundle: input.writerProjection.contentKeyBundle,\n documentKekTargets: documentKekTargetsFromContentKeyBundle(\n input.writerProjection.contentKeyBundle,\n ),\n documentManifest: staleBundleDocumentManifest(input.writerProjection),\n healedStaleContentKeyBundle: false,\n heldBackPendingUpdateIds: [],\n pendingUpdates,\n };\n }\n\n const normalMaterial: ResolvedSyncPlanContentMaterial = {\n contentKey: await unwrapDocumentContentKeyFromBundle(\n input.writerProjection.contentKeyBundle,\n input.writerProjection.documentId,\n collectedKeks.keksByEpochId,\n collectedKeks.predecessorFailuresByEpochId,\n collectedKeks.unattributedPredecessorFailuresByContainerId,\n ),\n contentKeyBundle: input.writerProjection.contentKeyBundle,\n documentKekTargets: input.writerProjection.documentKekTargets,\n documentManifest: input.writerProjection.documentManifest,\n healedStaleContentKeyBundle: false,\n heldBackPendingUpdateIds: [],\n pendingUpdates,\n };\n if (\n input.regenerateQueuedCheckpoints === true &&\n allPendingUpdates.some((update) => update.sourceVersionVector != null)\n ) {\n return resolveCheckpointRegenerationMaterial(\n input,\n normalMaterial,\n allPendingUpdates,\n );\n }\n\n return normalMaterial;\n}\n\nexport async function buildMaterializedDocumentSyncPlan(\n input: {\n author: DocumentCreateAuthor;\n /**\n * Supplies a full-history Loro snapshot of the local document when a\n * stale content-key bundle must be healed, or when a leftover queued\n * rotation checkpoint must be regenerated as a covering baseline.\n * Without it those passes fail with a descriptive error instead.\n */\n buildRotationSnapshot?: (() => Promise<Uint8Array | null>) | undefined;\n containerRekeys?: BuildDocumentSyncPlanInput[\"containerRekeys\"];\n execSql?: ExecSql | undefined;\n historyMode?: \"raw\" | undefined;\n inlineRekeyCommitId?: string | undefined;\n localVersionVector: string | null;\n minLsn?: string | undefined;\n pullCursor?: string | undefined;\n /** Clipboard-safe trace sink (see syncTrace.ts); never receives content. */\n onSyncTrace?: DocumentSyncTraceEmitter | undefined;\n pendingUpdates?: readonly PendingUpdateRecord[] | undefined;\n persistVerificationCheckpoints?: boolean | undefined;\n /**\n * Replace queued rotation checkpoints with a freshly regenerated covering\n * baseline instead of passing them through. Set by the sync loop after\n * the server rejected a pass via the covering-baseline gate.\n */\n regenerateQueuedCheckpoints?: boolean | undefined;\n signedAt?: string | undefined;\n targetSecretKey: Uint8Array;\n writerProjection: DocumentWriterProjectionResponse;\n } & ProjectionVerificationOptions,\n): Promise<MaterializedDocumentSyncPlan> {\n // Reuse verification across consistency and unwrap passes; unwrap still\n // binds the key material independently.\n const verifiedByHash = new Map<string, VerifiedContainerAccessManifest>();\n const principalPolicyCache = new Map<string, VerifiedPrincipalPolicy>();\n let writerAuthorization: DocumentWriterProjectionAuthorization | undefined;\n await assertDocumentWriterProjectionConsistent(input.writerProjection, {\n allowStaleContentKeyBundle: true,\n execSql: input.execSql,\n persistVerificationCheckpoints: input.persistVerificationCheckpoints,\n onVerifiedAuthorization: (authorization) => {\n writerAuthorization = authorization;\n },\n principalPolicyCache,\n verifiedByHash,\n ...projectionVerificationOptions(input),\n });\n const collectedKeks = await collectContainerKeksForDocumentSync({\n execSql: input.execSql,\n persistVerificationCheckpoints: input.persistVerificationCheckpoints,\n principalPolicyCache,\n secretKey: input.targetSecretKey,\n verifiedByHash,\n writerProjection: input.writerProjection,\n ...projectionVerificationOptions(input),\n });\n const documentId = input.writerProjection.documentId;\n const manifestIdentity = await assertDocumentManifestBundleConsistent({\n bundle: input.writerProjection.documentManifest,\n label: \"Document sync manifest\",\n });\n let material: ResolvedSyncPlanContentMaterial;\n try {\n material = await resolveSyncPlanContentMaterial(input, collectedKeks);\n } catch (error) {\n // Only a stale-bundle HEAL (write-bearing) or a checkpoint regeneration\n // counts as a blocked recovery; an ordinary pass or a stale READ failing\n // here must not read as one in a support report. Enumerated reason only;\n // unknown errors emit nothing (fail closed).\n if (\n (input.writerProjection.contentKeyBundleStale === true &&\n (input.pendingUpdates ?? []).length > 0) ||\n input.regenerateQueuedCheckpoints === true\n ) {\n traceHealBlocked(input.onSyncTrace, {\n documentId: input.writerProjection.documentId,\n error,\n });\n }\n throw error;\n }\n const {\n contentKey,\n contentKeyBundle,\n documentKekTargets,\n documentManifest,\n pendingUpdates,\n } = material;\n const outgoingUpdates = await prepareDocumentOutgoingUpdates({\n contentKey,\n contentKeyEpoch: contentKeyBundle.contentKeyEpoch,\n documentId,\n organizationId: manifestIdentity.organizationId,\n pendingUpdates,\n });\n const basePlan = await buildDocumentSyncPlan({\n author: {\n ...input.author,\n organizationId: manifestIdentity.organizationId,\n },\n authorizingContainerPathRefs: authorizingContainerPathRefs(\n input.writerProjection,\n ),\n containerRekeys: input.containerRekeys,\n contentKeyBundle,\n documentId,\n documentKekTargets,\n documentManifest,\n historyMode: input.historyMode,\n inlineRekeyCommitId: input.inlineRekeyCommitId,\n localVersionVector: input.localVersionVector,\n minLsn: input.minLsn,\n outgoingUpdates,\n pullCursor: input.pullCursor,\n signedAt: input.signedAt,\n });\n return finalizeMaterializedDocumentSyncPlan({\n basePlan,\n material,\n writerAuthorization,\n writerProjection: input.writerProjection,\n });\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncPlanProjection.js","sourceRoot":"","sources":["syncPlanProjection.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC;AAYjC,SAAS,mCAAmC,CAC1C,QAAoC,EACpC,gBAAkD;IAElD,IAAI,CAAC,QAAQ,CAAC,2BAA2B;QAAE,OAAO,gBAAgB,CAAC;IACnE,MAAM,gBAAgB,GAAG;QACvB,GAAG,gBAAgB;QACnB,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;QAC3C,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB;QAC/C,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;KAC5C,CAAC;IACF,OAAO,gBAAgB,CAAC,qBAAqB,CAAC;IAC9C,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,oCAAoC,CAAC,KAOpD;IACC,MAAM,aAAa,GAAG,KAAK,CAAC,mBAAmB;QAC7C,CAAC,CAAC;YACE,GAAG,KAAK,CAAC,QAAQ;YACjB,2BAA2B,EAAE,KAAK,CAAC,mBAAmB;SACvD;QACH,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;IACnB,MAAM,IAAI,GAAG,4BAA4B,CACvC,aAAa,EACb,KAAK,CAAC,QAAQ,CAAC,6BAA6B,CAC7C,CAAC;IACF,OAAO,4BAA4B,CACjC,KAAK,CAAC,QAAQ,EACd,IAAI,EACJ,mCAAmC,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAC5E,CAAC;AACJ,CAAC","sourcesContent":["import type {\n DocumentCreateResponse,\n DocumentSyncResponse,\n DocumentWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport type {\n DocumentSyncPlan,\n MaterializedDocumentSyncPlan,\n} from \"../../data/documents/shared/types\";\nimport type { DocumentWriterProjectionAuthorization } from \"../../data/keyingProjectionVerification\";\nimport {\n boundDocumentSyncPlanRequest,\n materializedDocumentSyncPlan,\n} from \"./syncPlanRequestBounds\";\n\ninterface SyncPlanProjectionMaterial {\n readonly contentKey: Uint8Array;\n readonly contentKeyBundle: DocumentCreateResponse[\"contentKeyBundle\"];\n readonly documentKekTargets: DocumentSyncResponse[\"documentKekTargets\"];\n readonly documentManifest: DocumentCreateResponse[\"accessManifest\"];\n readonly healedStaleContentKeyBundle: boolean;\n readonly heldBackPendingUpdateIds: readonly string[];\n readonly staleRecoveryBaselineUpdateId?: string | undefined;\n}\n\nfunction writerProjectionAfterContentKeyHeal(\n material: SyncPlanProjectionMaterial,\n writerProjection: DocumentWriterProjectionResponse,\n): DocumentWriterProjectionResponse {\n if (!material.healedStaleContentKeyBundle) return writerProjection;\n const healedProjection = {\n ...writerProjection,\n contentKeyBundle: material.contentKeyBundle,\n documentKekTargets: material.documentKekTargets,\n documentManifest: material.documentManifest,\n };\n delete healedProjection.contentKeyBundleStale;\n return healedProjection;\n}\n\nexport function finalizeMaterializedDocumentSyncPlan(input: {\n readonly basePlan: DocumentSyncPlan;\n readonly material: SyncPlanProjectionMaterial;\n readonly writerAuthorization:\n | DocumentWriterProjectionAuthorization\n | undefined;\n readonly writerProjection: DocumentWriterProjectionResponse;\n}): MaterializedDocumentSyncPlan {\n const unboundedPlan = input.writerAuthorization\n ? {\n ...input.basePlan,\n documentWriterAuthorization: input.writerAuthorization,\n }\n : input.basePlan;\n const plan = boundDocumentSyncPlanRequest(\n unboundedPlan,\n input.material.staleRecoveryBaselineUpdateId,\n );\n return materializedDocumentSyncPlan(\n input.material,\n plan,\n writerProjectionAfterContentKeyHeal(input.material, input.writerProjection),\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncPlanRequestBounds.js","sourceRoot":"","sources":["syncPlanRequestBounds.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,6BAA6B,EAAE,MAAM,2CAA2C,CAAC;AAS1F,MAAM,UAAU,4BAA4B,CAC1C,IAA0C,EAC1C,wBAA4C;IAE5C,MAAM,OAAO,GAAG,6BAA6B,CAAC,IAAI,CAAC,OAAO,EAAE;QAC1D,wBAAwB;KACzB,CAAC,CAAC;IAC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AAG,CAAC;QACxC,KAAK,CAAC,uBAAuB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3C,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACvE,OAAO,CACL,KAAK,CAAC,uBAAuB,CAAC,MAAM,GAAG,CAAC;QACxC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CACzB,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC,CACrD,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,gBAA8C,EAC9C,QAA8B;IAE9B,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,6BAA6B,CAAC;IAC1E,OAAO,CACL,kBAAkB,KAAK,SAAS;QAChC,QAAQ,CAAC,yBAAyB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAChE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,gBAA8C,EAC9C,QAA8B;IAE9B,OAAO,gCAAgC,CAAC,gBAAgB,EAAE,QAAQ,CAAC;QACjE,CAAC,CAAC,gBAAgB,CAAC,wBAAwB;QAC3C,CAAC,CAAC,EAAE,CAAC;AACT,CAAC","sourcesContent":["import type { DocumentSyncResponse } from \"@tearleads/validators/response\";\nimport type { MaterializedDocumentSyncPlan } from \"../../data/documents/shared/types\";\nimport type { PendingUpdateRecord } from \"../../data/sqlite/documentPersistence\";\nimport { limitDocumentSyncRequestBytes } from \"../../data/sync/documentSyncOutgoingBatch\";\n\ninterface SyncPlanMaterial {\n readonly contentKey: Uint8Array;\n readonly healedStaleContentKeyBundle: boolean;\n readonly heldBackPendingUpdateIds: readonly string[];\n readonly staleRecoveryBaselineUpdateId?: string | undefined;\n}\n\nexport function boundDocumentSyncPlanRequest(\n plan: MaterializedDocumentSyncPlan[\"plan\"],\n requiredOutgoingUpdateId: string | undefined,\n): MaterializedDocumentSyncPlan[\"plan\"] {\n const request = limitDocumentSyncRequestBytes(plan.request, {\n requiredOutgoingUpdateId,\n });\n return request === plan.request ? plan : { ...plan, request };\n}\n\nexport function materializedDocumentSyncPlan(\n material: SyncPlanMaterial,\n plan: MaterializedDocumentSyncPlan[\"plan\"],\n writerProjection: MaterializedDocumentSyncPlan[\"writerProjection\"],\n): MaterializedDocumentSyncPlan {\n return {\n contentKey: material.contentKey,\n healedStaleContentKeyBundle: material.healedStaleContentKeyBundle,\n heldBackPendingUpdateIds: material.heldBackPendingUpdateIds,\n plan,\n writerProjection,\n ...(material.staleRecoveryBaselineUpdateId === undefined\n ? {}\n : {\n staleRecoveryBaselineUpdateId: material.staleRecoveryBaselineUpdateId,\n }),\n };\n}\n\nexport function recoverablePendingUpdates(\n pendingUpdates: readonly PendingUpdateRecord[],\n materializedPlan: MaterializedDocumentSyncPlan,\n): PendingUpdateRecord[] {\n const submittedIds = new Set(\n materializedPlan.plan.request.outgoingUpdates.map((update) => update.id),\n );\n const recoverableIds = new Set([\n ...submittedIds,\n ...materializedPlan.heldBackPendingUpdateIds,\n ]);\n return pendingUpdates.filter((update) => recoverableIds.has(update.id));\n}\n\nexport function hasDeferredPendingUpdatesAfterSubmit(input: {\n acceptedRecoveryBaseline: boolean;\n exhaustedPendingUpdateCount: number;\n pendingUpdateIds: readonly string[];\n rekeyedPendingUpdateIds: readonly string[];\n settledPendingUpdateIds: readonly string[];\n}): boolean {\n if (input.exhaustedPendingUpdateCount > 0) {\n return false;\n }\n\n const madeDurableProgress =\n input.acceptedRecoveryBaseline ||\n input.settledPendingUpdateIds.length > 0 ||\n input.rekeyedPendingUpdateIds.length > 0;\n if (!madeDurableProgress) {\n return false;\n }\n\n const settledPendingUpdateIds = new Set(input.settledPendingUpdateIds);\n return (\n input.rekeyedPendingUpdateIds.length > 0 ||\n input.pendingUpdateIds.some(\n (updateId) => !settledPendingUpdateIds.has(updateId),\n )\n );\n}\n\nexport function responseAcceptedRecoveryBaseline(\n materializedPlan: MaterializedDocumentSyncPlan,\n response: DocumentSyncResponse,\n): boolean {\n const recoveryBaselineId = materializedPlan.staleRecoveryBaselineUpdateId;\n return (\n recoveryBaselineId !== undefined &&\n response.acceptedOutgoingUpdateIds.includes(recoveryBaselineId)\n );\n}\n\nexport function acceptedHeldBackPendingUpdateIds(\n materializedPlan: MaterializedDocumentSyncPlan,\n response: DocumentSyncResponse,\n): readonly string[] {\n return responseAcceptedRecoveryBaseline(materializedPlan, response)\n ? materializedPlan.heldBackPendingUpdateIds\n : [];\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncPolicyRepair.js","sourceRoot":"","sources":["syncPolicyRepair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AAOxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAI1E,SAAS,oBAAoB,CAC3B,aAAmC,EACnC,WAAmB;IAEnB,OAAO,GAAG,aAAa,IAAI,WAAW,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,kCAAkC,CACzC,IAAsB;IAEtB,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IACrC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,EAAE,CAAC;QACvD,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC7C,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;YAC3D,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;YACvD,IACE,CAAC,aAAa,KAAK,OAAO,IAAI,aAAa,KAAK,cAAc,CAAC;gBAC/D,OAAO,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CAAC;QACjC,KAAK;QACL,+BAA+B,EAAE,KAAK,CAAC,+BAA+B;QACtE,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc;QACzC,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport type { ReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\nimport { isRetryableDocumentSyncConflict } from \"../../data/documents/shared/responses\";\nimport type {\n DocumentSyncPlan,\n DocumentSyncSubmitFailure,\n} from \"../../data/documents/shared/types\";\nimport type { ReferencedPrincipalPolicyWarmer } from \"../../data/keyingProjectionVerification\";\n\nimport { recoverPrincipalPolicyRepair } from \"../principals/policyRepair\";\n\ntype ManagedPrincipalType = \"group\" | \"organization\";\n\nfunction principalIdentityKey(\n principalType: ManagedPrincipalType,\n principalId: string,\n): string {\n return `${principalType}:${principalId}`;\n}\n\nfunction requestedRepairPrincipalIdentities(\n plan: DocumentSyncPlan,\n): Set<string> {\n const identities = new Set<string>();\n for (const rekey of plan.request.containerRekeys ?? []) {\n for (const policy of rekey.principalPolicies) {\n const principalType = Reflect.get(policy, \"principalType\");\n const principalId = Reflect.get(policy, \"principalId\");\n if (\n (principalType === \"group\" || principalType === \"organization\") &&\n typeof principalId === \"string\" &&\n principalId.length > 0\n ) {\n identities.add(principalIdentityKey(principalType, principalId));\n }\n }\n }\n return identities;\n}\n\nfunction assertDocumentSyncPolicyRepairHeadsRequested(input: {\n readonly heads: readonly ReferencedPrincipalStateResponse[];\n readonly plan: DocumentSyncPlan;\n}): void {\n const requested = requestedRepairPrincipalIdentities(input.plan);\n for (const head of input.heads) {\n const { principalId, principalType } = head;\n if (!requested.has(principalIdentityKey(principalType, principalId))) {\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Document sync policy repair head principal was not requested\",\n );\n }\n }\n}\n\nexport async function recoverDocumentSyncPolicyRepair(input: {\n failure: DocumentSyncSubmitFailure;\n plan: DocumentSyncPlan;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<void> {\n const heads = input.failure.stalePrincipalHeads;\n const resolve = input.warmReferencedPrincipalPolicies?.resolveReference;\n if (\n !isRetryableDocumentSyncConflict(input.failure) ||\n (input.plan.request.containerRekeys?.length ?? 0) === 0 ||\n !heads ||\n heads.length === 0 ||\n !resolve ||\n input.stillCurrent?.() === false\n ) {\n return;\n }\n\n assertDocumentSyncPolicyRepairHeadsRequested({ heads, plan: input.plan });\n await recoverPrincipalPolicyRepair({\n heads,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n organizationId: input.plan.organizationId,\n stillCurrent: input.stillCurrent,\n });\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncRecoveryRekey.js","sourceRoot":"","sources":["syncRecoveryRekey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EACL,yBAAyB,EAEzB,0BAA0B,GAC3B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,iCAAiC,EAAE,MAAM,4CAA4C,CAAC;AAC/F,OAAO,EAEL,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AAcrC,SAAS,UAAU,CAAC,IAAgB,EAAE,KAAiB;IACrD,OAAO,CACL,IAAI,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU;QACpC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CACrD,CAAC;AACJ,CAAC;AAED,SAAS,mCAAmC,CAC1C,aAAkC,EAClC,eAAgD;IAEhD,IACE,aAAa,CAAC,yBAAyB;QACrC,eAAe,CAAC,yBAAyB;QAC3C,aAAa,CAAC,uBAAuB;YACnC,eAAe,CAAC,uBAAuB,EACzC,CAAC;QACD,OAAO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AE,EAAE,EAAE,CAAC;IACzE,CAAC;IACD,IAAI,yBAAyB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,KAAK,CAAC,uBAAuB,EAAE,CACnC,uBAAuB,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAC1D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,2BAA2B,EAAE,yBAAyB,CAAC,MAAM;QAC7D,uBAAuB;KACxB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,cAAsB;IAEtB,OAAO;QACL,OAAO,EAAE,0CAA0C,yBAAyB,qBAAqB,cAAc,UAAU,cAAc,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;QAC3J,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;QAChB,MAAM,EAAE,IAAI;KACb,CAAC;AACJ,CAAC","sourcesContent":["import { base64ToBytes } from \"@tearleads/encoding\";\nimport type { DocumentSyncResponse } from \"@tearleads/validators/response\";\nimport type { DocumentSyncSubmitFailure } from \"../../data/documents/shared/types\";\nimport {\n MAX_PENDING_UPDATE_REKEYS,\n type PendingUpdateRecord,\n rekeyDocumentPendingUpdate,\n} from \"../../data/sqlite/documentPersistence\";\nimport { getClientSQLitePersistenceRuntime } from \"../../data/sqlite/sqlitePersistenceRuntime\";\nimport {\n type ExecSql,\n runSerializedSqlMutation,\n} from \"../../data/sqlite/sqlSchema\";\n\nexport type RekeyPendingUpdate = (\n execSql: ExecSql,\n id: string,\n) => Promise<string | null>;\n\ninterface DecryptedSyncUpdate {\n id: string;\n partialEndVersionVector: string;\n partialStartVersionVector: string;\n updateData: Uint8Array;\n}\n\nfunction bytesEqual(left: Uint8Array, right: Uint8Array): boolean {\n return (\n left.byteLength === right.byteLength &&\n left.every((value, index) => value === right[index])\n );\n}\n\nfunction pendingUpdateMatchesDecryptedUpdate(\n pendingUpdate: PendingUpdateRecord,\n decryptedUpdate: Omit<DecryptedSyncUpdate, \"id\">,\n): boolean {\n if (\n pendingUpdate.partialStartVersionVector !==\n decryptedUpdate.partialStartVersionVector ||\n pendingUpdate.partialEndVersionVector !==\n decryptedUpdate.partialEndVersionVector\n ) {\n return false;\n }\n\n return bytesEqual(\n base64ToBytes(pendingUpdate.updateData),\n decryptedUpdate.updateData,\n );\n}\n\nexport function settledPendingUpdateIdsFromSync(input: {\n decryptedUpdates: readonly DecryptedSyncUpdate[];\n recoveryPendingUpdatesById: ReadonlyMap<string, PendingUpdateRecord>;\n response: DocumentSyncResponse;\n}): string[] {\n const settled = new Set(input.response.acceptedOutgoingUpdateIds);\n\n for (const update of input.decryptedUpdates) {\n const pendingUpdate = input.recoveryPendingUpdatesById.get(update.id);\n if (\n pendingUpdate &&\n pendingUpdateMatchesDecryptedUpdate(pendingUpdate, update)\n ) {\n settled.add(update.id);\n }\n }\n\n return [...settled];\n}\n\n/**\n * A read-only recovery sync settles a conflicted pending update only when the\n * response carries it — but the server's frontier filter omits spans the\n * request's localVersionVector already covers, which a locally-applied\n * pending update always is. Left alone, the conflicted id is resubmitted (and\n * 409s the whole outgoing batch) forever: a lost ack leaves the server\n * holding the original ciphertext, and every rebuild encrypts with a fresh\n * IV, so a byte-identical retry can never be reproduced. Re-key what\n * recovery could not settle so the next sync pass submits the same ops under\n * a conflict-free id; the server-side copy stays harmless because CRDT\n * update import is idempotent.\n *\n * Re-keying goes through the caller's persistence implementation when given\n * (defaulting to the built-in pending-update table) and reports only ids\n * whose row actually changed, so a record living in some other queue never\n * counts as progress. Returns the fresh ids so callers can treat re-keying\n * as settlement-like progress and schedule the pass that submits them.\n *\n * A row whose persisted rekeyCount has reached the bound is not re-keyed\n * again: it is reported as exhausted so the caller can surface a terminal\n * failure instead of feeding an unbounded conflict loop that survives\n * restarts (each session's in-memory lane cap resets, this bound does not).\n */\nexport async function rekeyUnsettledRecoveryPendingUpdates(input: {\n execSql: ExecSql;\n recoveryPendingUpdatesById: ReadonlyMap<string, PendingUpdateRecord>;\n rekeyPendingUpdate?: RekeyPendingUpdate | undefined;\n settledPendingUpdateIds: readonly string[];\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<{\n exhaustedPendingUpdateIds: string[];\n rekeyedPendingUpdateIds: string[];\n}> {\n const rekeyPendingUpdate =\n input.rekeyPendingUpdate ?? rekeyDocumentPendingUpdate;\n const settled = new Set(input.settledPendingUpdateIds);\n const rekeyedPendingUpdateIds: string[] = [];\n const exhaustedPendingUpdateIds: string[] = [];\n for (const [pendingUpdateId, record] of input.recoveryPendingUpdatesById) {\n if (input.stillCurrent?.() === false) break;\n if (settled.has(pendingUpdateId)) {\n continue;\n }\n // Known multi-tab limitation: the count is the row as loaded at pass\n // start, so a sibling tab that settle-deleted the row can make this\n // record a failure for work that no longer exists. The stale failure is\n // transient — the document's next clean pass clears it.\n if ((record.rekeyCount ?? 0) >= MAX_PENDING_UPDATE_REKEYS) {\n exhaustedPendingUpdateIds.push(pendingUpdateId);\n continue;\n }\n const outcome = await runSerializedSqlMutation(\n input.execSql,\n (lockedExecSql) =>\n getClientSQLitePersistenceRuntime(lockedExecSql).guardedTransaction(\n async () =>\n input.stillCurrent?.() === false\n ? null\n : rekeyPendingUpdate(lockedExecSql, pendingUpdateId),\n () => input.stillCurrent?.() !== false,\n ),\n );\n if (!outcome.committed) break;\n const nextId = outcome.result;\n if (nextId !== null) {\n rekeyedPendingUpdateIds.push(nextId);\n }\n }\n if (input.stillCurrent?.() === false) {\n return { exhaustedPendingUpdateIds: [], rekeyedPendingUpdateIds: [] };\n }\n return { exhaustedPendingUpdateIds, rekeyedPendingUpdateIds };\n}\n\n/**\n * Re-key what recovery could not settle and surface exhausted rows through\n * the caller's terminal-failure handler. The exhausted count is also\n * returned so the sync result can carry it: a pass that recorded this\n * failure must not read as clean to callers that clear recorded failures\n * on success.\n */\nexport async function rekeyAndReportUnsettledRecoveryPendingUpdates(\n input: Parameters<typeof rekeyUnsettledRecoveryPendingUpdates>[0] & {\n onTerminalSubmitFailure?:\n | ((failure: DocumentSyncSubmitFailure) => Promise<void> | void)\n | undefined;\n },\n): Promise<{\n exhaustedPendingUpdateCount: number;\n rekeyedPendingUpdateIds: string[];\n}> {\n const { exhaustedPendingUpdateIds, rekeyedPendingUpdateIds } =\n await rekeyUnsettledRecoveryPendingUpdates(input);\n if (input.stillCurrent?.() === false) {\n return { exhaustedPendingUpdateCount: 0, rekeyedPendingUpdateIds: [] };\n }\n if (exhaustedPendingUpdateIds.length > 0) {\n await input.onTerminalSubmitFailure?.(\n rekeyLimitSubmitFailure(exhaustedPendingUpdateIds.length),\n );\n }\n return {\n exhaustedPendingUpdateCount: exhaustedPendingUpdateIds.length,\n rekeyedPendingUpdateIds,\n };\n}\n\n/**\n * Terminal failure recorded when conflict recovery gives up on pending\n * updates whose persisted re-key bound is exhausted. Shaped like a submit\n * failure so the existing write-queue surface (recordDocumentSyncFailure via\n * onTerminalSubmitFailure) explains the stuck write without new plumbing.\n */\nexport function rekeyLimitSubmitFailure(\n exhaustedCount: number,\n): DocumentSyncSubmitFailure {\n return {\n message: `Update conflict recovery gave up after ${MAX_PENDING_UPDATE_REKEYS} re-key attempts (${exhaustedCount} update${exhaustedCount === 1 ? \"\" : \"s\"})`,\n ok: false,\n report: () => {},\n status: null,\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncRepairAbandon.js","sourceRoot":"","sources":["syncRepairAbandon.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,oCAAqC,SAAQ,KAAK;IACxC;IAArB,YAAqB,MAAmC;QACtD,KAAK,CAAC,uCAAuC,MAAM,EAAE,CAAC,CAAC;QADpC,WAAM,GAAN,MAAM,CAA6B;QAEtD,IAAI,CAAC,IAAI,GAAG,sCAAsC,CAAC;IACrD,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,OAAO,oCAAqC,SAAQ,KAAK;IAC7D;QACE,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,sCAAsC,CAAC;IACrD,CAAC;CACF","sourcesContent":["import type { AncestorRepairAbandonReason } from \"./syncTrace\";\n\n/**\n * A repair that cannot proceed for a routine reason: the organization's writes\n * are gated, the server refused the rekey, a peer rotated an ancestor mid-pass,\n * the refreshed projection was unavailable, or the pass exhausted its repair\n * budget. None is a defect, so the sync lane abandons the attempt rather than\n * reporting a failed run; the next trigger re-plans from a fresh projection.\n *\n * Lives apart from both the planner and the preparation loop: each throws it,\n * and preparation already imports the planner, so declaring it in either would\n * close a dependency cycle.\n */\nexport class DocumentAncestorRepairAbandonedError extends Error {\n constructor(readonly reason: AncestorRepairAbandonReason) {\n super(`Document ancestor repair abandoned: ${reason}`);\n this.name = \"DocumentAncestorRepairAbandonedError\";\n }\n}\n\n/** A refreshed projection needs durable preparation before another pure plan. */\nexport class DocumentSyncPreparationRequiredError extends Error {\n constructor() {\n super(\"Document sync requires a new ancestor preparation step\");\n this.name = \"DocumentSyncPreparationRequiredError\";\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncRepairAccess.js","sourceRoot":"","sources":["syncRepairAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,mBAAmB,CAAC;AAExE,OAAO,EACL,gCAAgC,EAChC,2CAA2C,GAC5C,MAAM,yCAAyC,CAAC;AAGjD,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,IAA6B,EAC7B,UAA4C,EAC5C,uBAA+B;IAE/B,IAAI,UAAU,CAAC,yBAAyB,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAClE,MAAM,QAAQ,GAAG,MAAM,2CAA2C,CAAC;QACjE,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,8BAA8B,EAAE,KAAK;QACrC,UAAU;QACV,cAAc,EAAE,gCAAgC,CAC9C,IAAI,CAAC,wBAAwB,EAC7B,+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AAY;SACjC,CAAC,CAAC;QACH,OAAO,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,OAAO,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { resolveContainerPathUserAccessLevel } from \"@tearleads/crypto\";\nimport type { DocumentWriterProjectionResponse } from \"@tearleads/validators/response\";\nimport {\n requireProjectionUserKeyResolver,\n verifyDocumentWriterProjectionAuthorization,\n} from \"../../data/keyingProjectionVerification\";\nimport type { SyncRemoteDocumentInput } from \"./readOnlySync\";\n\n/** A repair refusal on one link does not revoke write access through another. */\nexport async function hasOtherLinkedWriteAccess(\n sync: SyncRemoteDocumentInput,\n projection: DocumentWriterProjectionResponse,\n inaccessibleContainerId: string,\n): Promise<boolean> {\n if (projection.authorizingContainerPaths.length < 2) return false;\n const verified = await verifyDocumentWriterProjectionAuthorization({\n execSql: sync.execSql,\n persistVerificationCheckpoints: false,\n projection,\n resolveUserKey: requireProjectionUserKeyResolver(\n sync.resolveProjectionUserKey,\n \"Document linked repair access\",\n ),\n stillCurrent: sync.stillCurrent,\n warmReferencedPrincipalPolicies: sync.warmReferencedPrincipalPolicies,\n });\n const document = verified.documentManifestByHash.get(\n projection.documentManifest.manifestHash,\n );\n if (\n !document ||\n document.state.documentId !== sync.documentId ||\n document.state.organizationId !== sync.author.organizationId\n )\n return false;\n // The map also contains historical paths. Only the verified current paths\n // named by this projection may establish present write authority.\n return projection.authorizingContainerPaths.some((candidate) => {\n const headHash = candidate.path.at(-1)?.manifestHash;\n const path = headHash\n ? verified.containerPathByManifestHash.get(headHash)\n : undefined;\n const leaf = path?.at(-1);\n if (\n !path ||\n !leaf ||\n leaf.state.containerId === inaccessibleContainerId ||\n leaf.state.organizationId !== document.state.organizationId ||\n !document.state.linkedContainerIds.includes(leaf.state.containerId)\n )\n return false;\n const access = resolveContainerPathUserAccessLevel({\n path,\n principalPolicies: verified.principalPolicies,\n userId: sync.author.signerUserId,\n });\n return access === \"write\" || access === \"admin\";\n });\n}\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@tearleads/crypto\";\nimport type {\n DocumentSyncResponse,\n DocumentWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { decryptDocumentSyncUpdatesByEpoch } from \"../../data/documents/shared/crypto\";\nimport {\n type IncomingDocumentSyncUpdateValidator,\n isolateDocumentSyncBatchError,\n} from \"../../data/documents/shared/documentSyncUpdateIsolation\";\nimport { assertDocumentWriterProjectionConsistent } from \"../../data/documents/shared/projection\";\nimport {\n DocumentSyncResponseUpdateContentKeyError,\n persistedDocumentSyncStateFromResponse,\n} from \"../../data/documents/shared/responses\";\nimport type {\n DocumentWriterPublicKeyResolver,\n MaterializedDocumentSyncPlan,\n SyncRemoteDocumentResult,\n} from \"../../data/documents/shared/types\";\nimport { projectionVerificationOptions } from \"../../data/documents/shared/types\";\nimport type {\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"../../data/keyingProjectionVerification\";\nimport type { PendingUpdateRecord } from \"../../data/sqlite/documentPersistence\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport { unwrapDocumentSyncResponseContentKeys } from \"./syncContentKeys\";\nimport type { TerminalSubmitFailureHandler } from \"./syncFailureClassification\";\nimport {\n acceptedHeldBackPendingUpdateIds,\n responseAcceptedRecoveryBaseline,\n} from \"./syncPlanRequestBounds\";\nimport {\n type RekeyPendingUpdate,\n rekeyAndReportUnsettledRecoveryPendingUpdates,\n settledPendingUpdateIdsFromSync,\n} from \"./syncRecoveryRekey\";\n\nfunction isolateContentKeyResponseFailure(\n error: unknown,\n response: DocumentSyncResponse,\n): never {\n if (\n !(error instanceof DocumentSyncResponseUpdateContentKeyError) ||\n response.updates.length === 0\n ) {\n throw error;\n }\n throw isolateDocumentSyncBatchError({\n cause: new KeyingVerificationError(\"invalid_shape\", error.message),\n stage: \"content_key\",\n updateIds: response.updates.map((update) => update.id),\n });\n}\n\ntype SyncRemoteDocumentResultInput = {\n execSql: ExecSql;\n materializedPlan: MaterializedDocumentSyncPlan;\n onTerminalSubmitFailure?: TerminalSubmitFailureHandler | undefined;\n recoveryPendingUpdatesById: ReadonlyMap<string, PendingUpdateRecord>;\n rekeyPendingUpdate?: RekeyPendingUpdate | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n resolveWriterPublicKey: DocumentWriterPublicKeyResolver;\n response: DocumentSyncResponse;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n validateIncomingUpdates: IncomingDocumentSyncUpdateValidator;\n writerProjection: DocumentWriterProjectionResponse;\n};\n\n/** @internal Exercises poison precedence for the decryptable subset of a raw page. */\nexport async function validateDecryptableRawHistorySiblings(input: {\n contentKeysByEpoch: ReadonlyMap<number, Uint8Array>;\n documentId: string;\n organizationId: string;\n response: DocumentSyncResponse;\n updates: readonly DocumentSyncResponse[\"updates\"][number][];\n validateIncomingUpdates: IncomingDocumentSyncUpdateValidator;\n}): Promise<void> {\n if (input.updates.length === 0) return;\n const decryptedUpdates = await decryptDocumentSyncUpdatesByEpoch({\n contentKeysByEpoch: input.contentKeysByEpoch,\n documentId: input.documentId,\n organizationId: input.organizationId,\n updates: input.updates,\n });\n // The current wire contract authenticates each update's operation range but\n // not its exact dependency set. An unresolved import therefore cannot prove\n // that the missing parent belongs to an unavailable sibling; preserve the\n // isolation failure instead of downgrading unrelated poison to availability.\n await input.validateIncomingUpdates({\n decryptedUpdates,\n response: { ...input.response, updates: [...input.updates] },\n });\n}\n\nasync function resolveVerifiedResponseState(\n input: SyncRemoteDocumentResultInput,\n) {\n const { plan } = input.materializedPlan;\n let persistedState: Awaited<\n ReturnType<typeof persistedDocumentSyncStateFromResponse>\n >;\n try {\n persistedState = await persistedDocumentSyncStateFromResponse(\n plan,\n input.response,\n {\n resolveWriterPublicKey: input.resolveWriterPublicKey,\n },\n );\n } catch (error) {\n // Missing or future bundles are response-integrity failures. They must be\n // poison-isolated before key availability is considered, because the\n // referenced update has not yet authenticated against a bundle.\n isolateContentKeyResponseFailure(error, input.response);\n }\n if ((plan.request.containerRekeys?.length ?? 0) > 0) {\n await assertDocumentWriterProjectionConsistent(input.writerProjection, {\n allowStaleContentKeyBundle: true,\n execSql: input.execSql,\n stillCurrent: input.stillCurrent,\n ...projectionVerificationOptions(input),\n });\n }\n const contentKeysByEpoch = await unwrapDocumentSyncResponseContentKeys({\n currentContentKey: input.materializedPlan.contentKey,\n currentContentKeyEpoch: plan.contentKeyEpoch,\n execSql: input.execSql,\n historyMode: plan.request.historyMode,\n onRawHistoryUnavailable: async ({ contentKeysByEpoch, updates }) =>\n validateDecryptableRawHistorySiblings({\n contentKeysByEpoch,\n documentId: plan.documentId,\n organizationId: plan.organizationId,\n response: input.response,\n updates,\n validateIncomingUpdates: input.validateIncomingUpdates,\n }),\n response: input.response,\n targetSecretKey: input.targetSecretKey,\n writerProjection: input.writerProjection,\n ...projectionVerificationOptions(input),\n });\n return { contentKeysByEpoch, persistedState };\n}\n\nexport async function syncRemoteDocumentResultFromResponse(\n input: SyncRemoteDocumentResultInput,\n): Promise<SyncRemoteDocumentResult> {\n const { plan } = input.materializedPlan;\n const { contentKeysByEpoch, persistedState } =\n await resolveVerifiedResponseState(input);\n const decryptedUpdates = await decryptDocumentSyncUpdatesByEpoch({\n contentKeysByEpoch,\n documentId: plan.documentId,\n organizationId: plan.organizationId,\n updates: input.response.updates,\n });\n await input.validateIncomingUpdates({\n decryptedUpdates,\n response: input.response,\n });\n const recoveryBaselineId =\n input.materializedPlan.staleRecoveryBaselineUpdateId;\n const acceptedRecoveryBaseline = responseAcceptedRecoveryBaseline(\n input.materializedPlan,\n input.response,\n );\n // Two heal-specific corrections: the synthetic heal baseline matches no\n // pending-queue row, so its ack must not count as a settled pending update;\n // and checkpoints the heal held back ARE settled by it — the committed\n // covering baseline subsumes their full-history content, and resubmitting\n // them post-heal could become the LATEST baseline at the healed epoch and\n // shrink the redirect's coverage below the pre-heal frontier.\n const settledPendingUpdateIds = [\n ...settledPendingUpdateIdsFromSync({\n decryptedUpdates,\n recoveryPendingUpdatesById: input.recoveryPendingUpdatesById,\n response: input.response,\n }).filter((updateId) => updateId !== recoveryBaselineId),\n ...acceptedHeldBackPendingUpdateIds(input.materializedPlan, input.response),\n ];\n const { exhaustedPendingUpdateCount, rekeyedPendingUpdateIds } =\n await rekeyAndReportUnsettledRecoveryPendingUpdates({\n execSql: input.execSql,\n onTerminalSubmitFailure: input.onTerminalSubmitFailure,\n recoveryPendingUpdatesById: input.recoveryPendingUpdatesById,\n rekeyPendingUpdate: input.rekeyPendingUpdate,\n settledPendingUpdateIds,\n stillCurrent: input.stillCurrent,\n });\n\n return {\n exhaustedPendingUpdateCount,\n contentKey: input.materializedPlan.contentKey,\n decryptedUpdates,\n hasDeferredPendingUpdates: false,\n hasIncompletePull: false,\n persistedState,\n plan,\n rekeyedPendingUpdateIds,\n response: input.response,\n settledPendingUpdateIds,\n acceptedRecoveryBaseline,\n writerProjection: input.writerProjection,\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncSubmittedResult.js","sourceRoot":"","sources":["syncSubmittedResult.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAEL,2CAA2C,GAC5C,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAC;AAG1F,OAAO,EAAE,kCAAkC,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,kCAAkC,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EACL,oCAAoC,EACpC,gCAAgC,GACjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAa1C,kFAAkF;AAClF,MAAM,UAAU,4BAA4B,CAAC,KAO5C;IACC,IACE,CAAC,KAAK,CAAC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kC,CACtD,KAAuC;IAEvC,IAAI,CAAC;QACH,OAAO,MAAM,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,iBAAiB,GACrB,yBAAyB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC;QAC1E,IACE,CAAC,iBAAiB;YAClB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,KAAK,KAAK;gBAC/B,CAAC,CAAC,KAAK,YAAY,kCAAkC,CAAC,CAAC,EACzD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QACD,OAAO,yCAAyC,CAC9C,KAAK,EACL,KAAK,EACL,iBAAiB,CAClB,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type {\n DocumentSyncResponse,\n DocumentWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport type {\n MaterializedDocumentSyncPlan,\n SyncRemoteDocumentResult,\n} from \"../../data/documents/shared/types\";\nimport { projectionVerificationOptions } from \"../../data/documents/shared/types\";\nimport {\n type ProjectionUserKeyResolver,\n verifyDocumentWriterProjectionAuthorization,\n} from \"../../data/keyingProjectionVerification\";\nimport { isKeyingVerificationError } from \"../../data/keyingProjectionVerification/error\";\nimport type { PendingUpdateRecord } from \"../../data/sqlite/documentPersistence\";\nimport type { SyncRemoteDocumentInput } from \"./readOnlySync\";\nimport { DocumentRawHistoryUnavailableError } from \"./syncContentKeys\";\nimport { refreshSyncAttemptWriterProjection } from \"./syncFailures\";\nimport {\n hasDeferredPendingUpdatesAfterSubmit,\n responseAcceptedRecoveryBaseline,\n} from \"./syncPlanRequestBounds\";\nimport { syncRemoteDocumentResultFromResponse } from \"./syncResponseResult\";\nimport { traceHealed } from \"./syncTrace\";\n\ntype SubmittedDocumentSyncResultInput = {\n materializedPlan: MaterializedDocumentSyncPlan;\n pendingUpdateIds: readonly string[];\n pullComplete: boolean;\n recoveryPendingUpdatesById: ReadonlyMap<string, PendingUpdateRecord>;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n response: DocumentSyncResponse;\n sync: SyncRemoteDocumentInput;\n writerProjection: DocumentWriterProjectionResponse;\n};\n\n/** @internal Applies post-verification heal effects under the sync generation. */\nexport function applyAcceptedHealSideEffects(input: {\n documentId: string;\n evictWriterProjection?: ((documentId: string) => void) | undefined;\n materializedPlan: MaterializedDocumentSyncPlan;\n onSyncTrace: SyncRemoteDocumentInput[\"onSyncTrace\"];\n response: DocumentSyncResponse;\n stillCurrent: SyncRemoteDocumentInput[\"stillCurrent\"];\n}): void {\n if (\n !input.materializedPlan.healedStaleContentKeyBundle ||\n !responseAcceptedRecoveryBaseline(input.materializedPlan, input.response) ||\n input.stillCurrent?.() === false\n ) {\n return;\n }\n input.evictWriterProjection?.(input.documentId);\n if (input.stillCurrent?.() === false) {\n return;\n }\n traceHealed(input.onSyncTrace, {\n accepted: input.response.acceptedOutgoingUpdateIds.length,\n documentId: input.materializedPlan.plan.documentId,\n epoch: input.materializedPlan.plan.contentKeyEpoch,\n });\n}\n\nasync function submittedDocumentSyncResult(\n input: SubmittedDocumentSyncResultInput,\n): Promise<SyncRemoteDocumentResult> {\n const result = await syncRemoteDocumentResultFromResponse({\n ...projectionVerificationOptions(input.sync),\n execSql: input.sync.execSql,\n materializedPlan: input.materializedPlan,\n onTerminalSubmitFailure: input.sync.onTerminalSubmitFailure,\n recoveryPendingUpdatesById: input.recoveryPendingUpdatesById,\n rekeyPendingUpdate: input.sync.rekeyPendingUpdate,\n resolveWriterPublicKey: input.sync.resolveWriterPublicKey,\n response: input.response,\n stillCurrent: input.sync.stillCurrent,\n targetSecretKey: input.sync.targetSecretKey,\n validateIncomingUpdates: input.sync.validateIncomingUpdates,\n writerProjection: input.writerProjection,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n });\n if (\n (input.materializedPlan.plan.request.containerRekeys?.length ?? 0) > 0 &&\n input.sync.stillCurrent?.() !== false\n ) {\n input.sync.apiClient.clearWriterProjectionCaches?.();\n }\n applyAcceptedHealSideEffects({\n documentId: input.sync.documentId,\n evictWriterProjection:\n input.sync.apiClient.evictDocumentWriterProjection?.bind(\n input.sync.apiClient,\n ),\n materializedPlan: input.materializedPlan,\n onSyncTrace: input.sync.onSyncTrace,\n response: input.response,\n stillCurrent: input.sync.stillCurrent,\n });\n return {\n ...result,\n hasDeferredPendingUpdates:\n (input.materializedPlan.plan.request.pullCursor !== undefined &&\n input.pendingUpdateIds.length > 0 &&\n result.exhaustedPendingUpdateCount === 0) ||\n hasDeferredPendingUpdatesAfterSubmit({\n acceptedRecoveryBaseline: result.acceptedRecoveryBaseline,\n exhaustedPendingUpdateCount: result.exhaustedPendingUpdateCount,\n pendingUpdateIds: input.pendingUpdateIds,\n rekeyedPendingUpdateIds: result.rekeyedPendingUpdateIds,\n settledPendingUpdateIds: result.settledPendingUpdateIds,\n }),\n hasIncompletePull: !input.pullComplete,\n };\n}\n\nasync function retrySubmittedResponseWithFreshProjection(\n input: SubmittedDocumentSyncResultInput,\n unavailableError: unknown,\n refreshAuthorization: boolean,\n): Promise<SyncRemoteDocumentResult | null> {\n const writerProjection = await refreshSyncAttemptWriterProjection({\n apiClient: input.sync.apiClient,\n documentId: input.sync.documentId,\n onRemoteDocumentDeleted: input.sync.onRemoteDocumentDeleted,\n onSyncAbandoned: input.sync.onSyncAbandoned,\n onSyncTrace: input.sync.onSyncTrace,\n onTerminalFailure: input.sync.onReadOnlyProjectionFailure,\n stillCurrent: input.sync.stillCurrent,\n unavailableError,\n });\n if (!writerProjection) return null;\n const materializedPlan = refreshAuthorization\n ? {\n ...input.materializedPlan,\n plan: {\n ...input.materializedPlan.plan,\n documentWriterAuthorization:\n await verifyDocumentWriterProjectionAuthorization({\n execSql: input.sync.execSql,\n projection: writerProjection,\n resolveUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.sync.stillCurrent,\n warmReferencedPrincipalPolicies:\n input.sync.warmReferencedPrincipalPolicies,\n }),\n },\n }\n : input.materializedPlan;\n // Keep the submitted request, keys, and response frozen. Only refreshed,\n // verified evidence may be added; this retry never resubmits outgoing edits.\n return submittedDocumentSyncResult({\n ...input,\n materializedPlan,\n writerProjection,\n });\n}\n\nexport async function resolveSubmittedDocumentSyncResult(\n input: SubmittedDocumentSyncResultInput,\n): Promise<SyncRemoteDocumentResult | null> {\n try {\n return await submittedDocumentSyncResult(input);\n } catch (error) {\n const missingDependency =\n isKeyingVerificationError(error) && error.code === \"missing_dependency\";\n if (\n !missingDependency &&\n (input.sync.historyMode !== \"raw\" ||\n !(error instanceof DocumentRawHistoryUnavailableError))\n ) {\n throw error;\n }\n return retrySubmittedResponseWithFreshProjection(\n input,\n error,\n missingDependency,\n );\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"acknowledgedDirectoryBindings.js","sourceRoot":"","sources":["acknowledgedDirectoryBindings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EACL,oCAAoC,EACpC,6BAA6B,GAC9B,MAAM,uDAAuD,CAAC;AAE/D,sFAAsF;AACtF,MAAM,UAAU,mCAAmC,CACjD,cAAsB,EACtB,QAAoD;IAEpD,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CACjC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,aAAa,KAAK,cAAc,CACnE,CAAC;IACF,IACE,WAAW,CAAC,MAAM,KAAK,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,aAAa,KAAK,OAAO,CAAC;QAE1E,MAAM,IAAI,uBAAuB,CAC/B,oBAAoB,EACpB,0DAA0D,CAC3D,CAAC;IACJ,KAAK,MAAM,SAAS,IAAI,WAAW,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,oCAAoC,CACrD,SAAS,CAAC,cAAc,CAAC,UAAU,CACpC,CAAC;QACF,IACE,SAAS,CAAC,YAAY,CAAC,WAAW,KAAK,cAAc;YACrD,UAAU,CAAC,cAAc,KAAK,cAAc;YAC5C,QAAQ,CAAC,IAAI,CACX,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CACnB,YAAY,CAAC,aAAa,KAAK,OAAO;gBACtC,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,6BAA6B,CAAC,IAAI,EAAE,YAAY,CAAC,CAClD,CACJ;YAED,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,2DAA2D,CAC5D,CAAC;IACN,CAAC;AACH,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport {\n parseOrganizationAuthorityDescriptor,\n principalHeadMatchesReference,\n} from \"../../data/principals/organizationAuthorityDescriptor\";\n\n/** Couple supplied group receipts to the directory acknowledged in the same batch. */\nexport function assertAcknowledgedDirectoryBindings(\n organizationId: string,\n receipts: readonly PrincipalPolicyMutationResponse[],\n) {\n const directories = receipts.filter(\n (receipt) => receipt.currentState.principalType === \"organization\",\n );\n if (\n directories.length === 0 &&\n receipts.some((receipt) => receipt.currentState.principalType === \"group\")\n )\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Acknowledged groups require their organization directory\",\n );\n for (const directory of directories) {\n const descriptor = parseOrganizationAuthorityDescriptor(\n directory.currentPayload.ciphertext,\n );\n if (\n directory.currentState.principalId !== organizationId ||\n descriptor.organizationId !== organizationId ||\n receipts.some(\n ({ currentState }) =>\n currentState.principalType === \"group\" &&\n !descriptor.groupHeads.some((head) =>\n principalHeadMatchesReference(head, currentState),\n ),\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Acknowledged organization does not bind its group receipt\",\n );\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"authoredPrincipalPolicyWarmer.js","sourceR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C;KACF,CACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n assertProjectionVerificationCurrent,\n type ReferencedPrincipalPolicyWarmer,\n type ResolvedPrincipalPolicyEvidence,\n} from \"../../data/keyingProjectionVerification/types\";\nimport { principalStateMatchesReference } from \"../../data/principals/principalPolicyStates\";\n\n/** Only exact, locally authored successors may resolve before their transaction commits. */\nexport function withAuthoredPrincipalPolicies(\n warmer: ReferencedPrincipalPolicyWarmer | undefined,\n authored: readonly ResolvedPrincipalPolicyEvidence[],\n): ReferencedPrincipalPolicyWarmer | undefined {\n if (!warmer?.resolveReference || authored.length === 0) return warmer;\n const resolve = warmer.resolveReference;\n const find = (\n organizationId: string,\n reference: Parameters<typeof resolve>[0][\"reference\"],\n ) =>\n authored.find(\n (entry) =>\n entry.organizationId === organizationId &&\n principalStateMatchesReference(entry.policy.state, reference),\n );\n return Object.assign(\n (input: Parameters<ReferencedPrincipalPolicyWarmer>[0]) =>\n warmer({\n ...input,\n references: input.references.filter(\n (reference) => !find(input.organizationId, reference),\n ),\n }),\n {\n ...warmer,\n resolveReference: async (input: Parameters<typeof resolve>[0]) => {\n const evidence = find(input.organizationId, input.reference);\n if (!evidence) return resolve(input);\n assertProjectionVerificationCurrent(input.stillCurrent);\n assertProjectionVerificationCurrent(evidence.stillCurrent);\n return evidence;\n },\n },\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"commitCurrentGroupPolicyMutation.js","sourceRoot":"","sources":["commitCurrentGroupPolicyMutation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AAEpG,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAEL,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,4CAA4C,EAC5C,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AAGtC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CAAC;QAClD,eAAe;QACf,UAAU;QACV,aAAa,EAAE,OAAO,CAAC,mBAAmB,CAAC,OAAO;QAClD,UAAU,EAAE,OAAO,CAAC,sBAAsB;QAC1C,UAAU;QACV,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n SigningKeyPair,\n VerifiedPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport { prepareAuthoredGroupPolicy } from \"./groupPolicyMutationAcknowledgement\";\nimport {\n type PrincipalPolicyReadWriteApi,\n submitGroupPolicyCommit,\n} from \"./groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"./groupPolicyMutationHead\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n replaceOrganizationGroupHead,\n} from \"./organizationGroupDirectory\";\nimport type { PreparedPrincipalContainerRematerializationBatch } from \"./principalContainerRematerialization\";\nimport type { PrincipalRematerializationPredecessor } from \"./principalContainerRematerializationPlanning\";\nimport { assertAuthoredPrincipalMutationReceipt } from \"./principalMutationReceipt\";\nimport type { RuntimeCurrentGroupMutationContext } from \"./runtimeCurrentGroupMutation\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"./trustedOrganizationUsers\";\n\ninterface GroupPolicyChange {\n readonly context: RuntimeCurrentGroupMutationContext;\n readonly request: PutPrincipalPolicyRequest;\n readonly prepareContainerMutations: (\n nextPolicy: VerifiedPrincipalPolicyCurrent,\n preceding?: PrincipalRematerializationPredecessor | undefined,\n ) => Promise<PreparedPrincipalContainerRematerializationBatch>;\n}\n\ninterface CommitInput extends GroupPolicyChange {\n readonly member?: GroupPolicyChange | undefined;\n readonly apiClient: PrincipalPolicyReadWriteApi;\n readonly groupId: string;\n readonly organizationId: string;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\n/** Commit and retain the group, optional roster enrollment and directory together. */\nexport async function commitCurrentGroupPolicyMutation(\n input: CommitInput,\n): Promise<PrincipalPolicyMutationResponse> {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const [signer] = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: [input.signerUserId],\n });\n if (!signer) throw new Error(\"Group policy signer is unavailable\");\n const member = input.member\n ? await prepareChange(input.member, signer)\n : null;\n const { expectedHead, prepared } = await prepareChange(\n input,\n signer,\n member?.preceding,\n );\n const organizationRequest = await prepareDirectory(\n input,\n expectedHead,\n member?.expectedHead,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n const response = await submitGroupPolicyCommit({\n apiClient: input.apiClient,\n groupId: input.groupId,\n organizationId: input.organizationId,\n request: input.request,\n organizationRequest,\n memberRequest: input.member?.request,\n // A compound retry must rebuild both batches' shared speculative heads.\n // Refuse the whole transaction if a damaged-key repair needs extra rekeys;\n // ordinary adds preserve key epochs and need no descendant carry retry.\n carryDescendantRekeys: member ? undefined : prepared.carry,\n stillCurrent: context.stillCurrent,\n });\n if (!response) throw new Error(\"Group policy update failed\");\n assertProjectionVerificationCurrent(context.stillCurrent);\n await assertAuthoredPrincipalMutationReceipt(\n {\n groupPolicy: input.request,\n organizationPolicy: organizationRequest,\n ...(input.member ? { memberPolicy: input.member.request } : {}),\n },\n response,\n );\n await context.retainAcknowledged({\n additionalGroups:\n input.member && response.memberPolicy\n ? [\n {\n ...input.member.context.groupRetention,\n request: input.member.request,\n response: response.memberPolicy,\n retiredContainerIds: member?.prepared.retiredContainerIds,\n },\n ]\n : [],\n request: input.request,\n organizationRequest,\n response,\n retiredContainerIds: prepared.retiredContainerIds,\n });\n if (member && response.memberPolicy) {\n await member.prepared.acknowledge(\n response.memberPolicy.containerMutations,\n context.stillCurrent,\n );\n }\n await prepared.acknowledge(\n response.groupPolicy.containerMutations,\n context.stillCurrent,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n return response.groupPolicy;\n}\n\nasync function prepareChange(\n change: GroupPolicyChange,\n signer: Awaited<ReturnType<typeof resolveRequiredUserIdentities>>[number],\n preceding?: PrincipalRematerializationPredecessor,\n) {\n const expectedHead = await groupPolicyMutationHead(change.request);\n const nextPolicy = await prepareAuthoredGroupPolicy({\n verifiedCurrentPolicy: change.context.verifiedCurrentPolicy,\n expectedHead,\n request: change.request,\n signerPublicKeys: [signer],\n externalAuthority: change.context.externalAuthority,\n localPolicyCheckpoint: change.context.localPolicyCheckpoint,\n stillCurrent: change.context.stillCurrent,\n });\n const prepared = await change.prepareContainerMutations(\n nextPolicy,\n preceding,\n );\n change.request.containerMutations = [...prepared.requests];\n return {\n expectedHead,\n prepared,\n preceding: prepared.preceding\n ? {\n ...prepared.preceding,\n authored: [\n ...(preceding?.authored ?? []),\n {\n organizationId:\n change.context.organizationDescriptor.organizationId,\n policy: nextPolicy,\n dependencies: [\n change.context.organizationCurrent.policy,\n change.context.adminCurrent.policy,\n ],\n stillCurrent: change.context.stillCurrent,\n },\n ],\n }\n : undefined,\n };\n}\n\nasync function prepareDirectory(\n input: CommitInput,\n expectedHead: Awaited<ReturnType<typeof groupPolicyMutationHead>>,\n memberHead: Awaited<ReturnType<typeof groupPolicyMutationHead>> | undefined,\n) {\n const { context } = input;\n if (\n input.member &&\n (input.member.context.currentPolicy.currentState.principalId !==\n context.memberGroupId ||\n input.member.context.organizationCurrent.current.currentState\n .stateHash !==\n context.organizationCurrent.current.currentState.stateHash)\n )\n throw new Error(\n \"Roster and group changes must share the same organization policy\",\n );\n let groupHeads = replaceOrganizationGroupHead({\n descriptor: context.organizationDescriptor,\n nextHead: expectedHead,\n });\n if (memberHead)\n groupHeads = replaceOrganizationGroupHead({\n descriptor: { ...context.organizationDescriptor, groupHeads },\n nextHead: memberHead,\n });\n const adminProjection = context.isOrganizationAdminsGroup\n ? input.request.projection\n : context.adminCurrent.current.currentProjection;\n const adminUsers = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n });\n return buildOrganizationGroupDirectoryPolicyRequest({\n adminProjection,\n adminUsers,\n currentPolicy: context.organizationCurrent.current,\n descriptor: context.organizationDescriptor,\n groupHeads,\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"createCurrentOrganizationGroup.js","sourceRoot":"","sources":["createCurrentOrganizationGroup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,kCAAkC,EAAE,MAAM,2DAA2D,CAAC;AAC/G,OAAO,EAAE,kCAAkC,EAAE,MAAM,mDAAmD,CAAC;AAKvG,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,sCAAsC,CAAC;AAErF,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,4CAA4C,EAC5C,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AAEpC,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAAC,KAgBp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KAAK,CAAC,cAAc;QACpC,OAAO;QACP,QAAQ,EAAE,MAAM,CAAC,KAAK;QACtB,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC,CAAC;IACH,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC;IAC/D,MAAM,OAAO,CAAC,kBAAkB,CAAC;QAC/B,OAAO,EAAE,OAAO,CAAC,kBAAkB;QACnC,QAAQ,EAAE,EAAE,GAAG,OAAO,EAAE,kBAAkB,EAAE,EAAE,EAAE;QAChD,mBAAmB;QACnB,oBAAoB,EAAE,MAAM,CAAC,kBAAkB;KAChD,CAAC,CAAC;IACH,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;AAC7E,CAAC","sourcesContent":["import type { EncapsulationKeyPair, SigningKeyPair } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { advanceKeyingCheckpointsAtomically } from \"../../data/persistence/keyingCheckpointAdvancePersistence\";\nimport { principalPolicyReferenceFromBundle } from \"../../data/principals/principalPolicyAdminSigners\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport type { createGroupMetadataAccess } from \"./groupMetadataAccess\";\nimport { assertGroupMetadataBinding } from \"./groupMetadataBinding\";\nimport { readDirectoryGroupName } from \"./groupNameUniqueness\";\nimport { acknowledgeInitialGroupPolicy } from \"./groupPolicyMutationAcknowledgement\";\nimport type { OrganizationPrincipalPolicyApi } from \"./groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"./groupPolicyMutationHead\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n replaceOrganizationGroupHead,\n} from \"./organizationGroupDirectory\";\nimport {\n buildInitialGroupPolicyRequest,\n canonicalGroupNameKey,\n} from \"./principalPolicyRequest\";\nimport type { OrganizationGroupSummary } from \"./readModel\";\nimport type { CurrentOrganizationMutationContext } from \"./runtimeCurrentOrganizationMutation\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"./trustedOrganizationUsers\";\n\n/** Create from bounded current evidence and publish its genuine genesis with the directory. */\nexport async function createCurrentOrganizationGroup(input: {\n readonly apiClient: Pick<\n OrganizationPrincipalPolicyApi,\n \"createOrganizationGroup\"\n >;\n readonly context: CurrentOrganizationMutationContext;\n readonly creatorEncapsulationKeyPair: EncapsulationKeyPair;\n readonly execSql: ExecSql;\n readonly metadataAccess: ReturnType<typeof createGroupMetadataAccess>;\n readonly name: string;\n readonly organizationId: string;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<OrganizationGroupSummary> {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const nameKey = canonicalGroupNameKey(input.name);\n // Each current recovery is queued by organization. Retain verified heads one\n // at a time so the walk stays bounded without collecting full group histories.\n for (const head of context.descriptor.groupHeads) {\n const group = await context.readGroup(head.principalId);\n const stillCurrent = () => context.stillCurrent() && group.stillCurrent();\n assertProjectionVerificationCurrent(stillCurrent);\n assertGroupMetadataBinding(group.current, context.descriptor);\n const name = await readDirectoryGroupName(\n { ...input, readEncryptedName: input.metadataAccess.readName },\n group.current,\n );\n // Remember independently verified heads even if uniqueness or dispatch\n // later fails; these are observed policies, never speculative successors.\n await advanceKeyingCheckpointsAtomically({\n execSql: input.execSql,\n organizationId: input.organizationId,\n access: [],\n policies: [...group.dependencies, group.policy],\n stillCurrent,\n });\n if (name !== null && canonicalGroupNameKey(name) === nameKey)\n throw new Error(\n \"Another signed group in this organization already carries this name\",\n );\n }\n const request = await buildInitialGroupPolicyRequest({\n ...input,\n groupId: crypto.randomUUID(),\n includeSignerAsAdmin: false,\n externalAuthority: {\n ...principalPolicyReferenceFromBundle(context.admins.current),\n principalType: \"group\",\n },\n metadataKey: await input.metadataAccess.loadEncryptionKey(),\n });\n const head = await groupPolicyMutationHead(request.initialGroupPolicy);\n const adminProjection = context.admins.policy.projection;\n const organizationRequest =\n await buildOrganizationGroupDirectoryPolicyRequest({\n ...input,\n currentPolicy: context.directory.current,\n descriptor: context.descriptor,\n groupHeads: replaceOrganizationGroupHead({\n descriptor: context.descriptor,\n nextHead: head,\n }),\n adminProjection,\n adminUsers: await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n }),\n });\n assertProjectionVerificationCurrent(context.stillCurrent);\n const stored = await input.apiClient.createOrganizationGroup(\n input.organizationId,\n { ...request, organizationPolicy: organizationRequest },\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n if (!stored) throw new Error(\"Group could not be created\");\n // Genesis really has one signed state. Reconstruct only the exact authored\n // artifacts whose commitments match the summary, then verify them privately.\n const { bundle } = await acknowledgeInitialGroupPolicy({\n organizationId: input.organizationId,\n request,\n response: stored.group,\n stateHash: head.stateHash,\n });\n const { previousStates: _previousStates, ...current } = bundle;\n await context.retainCreatedGroup({\n request: request.initialGroupPolicy,\n response: { ...current, containerMutations: [] },\n organizationRequest,\n organizationResponse: stored.organizationPolicy,\n });\n assertProjectionVerificationCurrent(context.stillCurrent);\n return { ...stored.group, name: input.name.trim(), nameUnreadable: false };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"createOrganization.js","sourceRoot":"","sources":["createOrganization.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wCAAwC,GACzC,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,aAAa,EAAE,MAAM,6BA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,SAAS,CAAC,SAAS;QAC9B,uBAAuB,EAAE,KAAK,CAAC,iBAAiB;QAChD,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,WAAW,EAAE,sBAAsB;QACnC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,iBAAiB,EAAE,SAAS,CAAC,iBAAiB;QAC9C,kBAAkB,EAAE,SAAS,CAAC,kBAAkB;QAChD,yBAAyB,EAAE,SAAS,CAAC,yBAAyB;QAC9D,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,6BAA6B,EAAE,SAAS,CAAC,6BAA6B;QACtE,qBAAqB,EAAE,KAAK,CAAC,qBAAqB;QAClD,QAAQ;QACR,aAAa,EAAE,SAAS,CAAC,aAAa;QACtC,oBAAoB,EAAE,SAAS,CAAC,oBAAoB;QACpD,2BAA2B,EAAE,SAAS,CAAC,2BAA2B;QAClE,sBAAsB,EAAE,SAAS,CAAC,sBAAsB;QACxD,yBAAyB,EAAE,SAAS,CAAC,yBAAyB;KAC/D,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n type EncapsulationKeyPair,\n type SigningKeyPair,\n signOrganizationReplacementAuthorization,\n} from \"@tearleads/crypto\";\nimport type { CreateOrganizationRequest } from \"@tearleads/validators/request\";\nimport type { CreateOrganizationResponse } from \"@tearleads/validators/response\";\nimport type { DocumentProjectorRegistryInput } from \"../../data/documents/documentKinds\";\nimport type { ExecSqlClientLike } from \"../../data/sqlite/sqlSchema\";\nimport { createExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { ProvisionedPrincipalHistoryPrimer } from \"../registration/provisionedPrincipalHistory\";\nimport {\n buildOrganizationProvisioningArtifacts,\n type OrganizationProvisioningArtifacts,\n type OrganizationProvisioningArtifactsInput,\n type ProvisionedSystemContainerSpec,\n persistOrganizationProvisioningState,\n} from \"../registration/registerIdentity\";\nimport {\n makeOrganizationProvisioningAttemptDurable,\n removeNativeSubscriptionRestoreProvisioningAttempt,\n} from \"./organizationProvisioningAttempt\";\nimport { pinOrganizationReplacementResponse } from \"./organizationReplacementVerification\";\n\nexport { removeNativeSubscriptionRestoreProvisioningAttempt };\n\nexport interface CreateOrganizationApi {\n createOrganization(\n request: CreateOrganizationRequest,\n ): Promise<CreateOrganizationResponse | null>;\n}\n\nexport interface CreateOrganizationInput {\n apiClient: CreateOrganizationApi;\n dbClient: ExecSqlClientLike;\n documentProjectors?: DocumentProjectorRegistryInput | undefined;\n encapsulationKeyPair: EncapsulationKeyPair;\n /**\n * Returns false once the identity that supplied the key pairs is no longer\n * active. Checked before the remote create (so a stale request is never\n * submitted) and again before local persistence: an identity switch closes\n * or renews the captured database client, so persisting would write another\n * identity's bootstrap — or throw — after the org already exists remotely.\n * The caller discards the result.\n */\n isIdentityCurrent?: (() => boolean) | undefined;\n /** @internal Forwarded to the bootstrap persist; test-only seam. */\n onPersistQueued?: (() => void) | undefined;\n log?: ((message: string) => void) | undefined;\n logError?: ((message: string | Error, cause?: unknown) => void) | undefined;\n /** Overrides the seeded organization profile name; see registration. */\n organizationProfileName?: string | undefined;\n /** Seeds verified recovery progress for the founding policy heads. */\n primePrincipalHistory?: ProvisionedPrincipalHistoryPrimer | undefined;\n /**\n * App-owned system containers to provision atomically with the new\n * organization (e.g. a trash bin). See registration.\n */\n provisionedSystemContainers?:\n | ReadonlyArray<ProvisionedSystemContainerSpec>\n | undefined;\n /** Purged organization whose personal-org generation this replaces. */\n replacesOrganizationId?: string | undefined;\n /** Marks and durably replays a fresh native-subscription restore target. */\n nativeSubscriptionRestore?: boolean | undefined;\n /** Overrides the seeded self roster-profile nickname; see registration. */\n rosterProfileNickname?: string | undefined;\n signingKeyPair: SigningKeyPair;\n /**\n * The already-registered user creating the organization; they become its\n * founding admin. The server independently requires this to match the\n * authenticated session.\n */\n userId: string;\n}\n\nfunction isAdoptedReplacementResponse(input: {\n creation: CreateOrganizationInput;\n request: CreateOrganizationRequest;\n response: CreateOrganizationResponse;\n}): boolean {\n if (\n input.response.organizationId === input.request.organizationId &&\n input.response.rootContainerId === input.request.rootContainerId\n ) {\n return false;\n }\n if (\n !input.creation.replacesOrganizationId ||\n input.response.userId !== input.creation.userId\n ) {\n throw new Error(\n \"Organization provisioning returned an unexpected organization\",\n );\n }\n input.creation.log?.(\n `Organization replacement adopted (${input.response.organizationId})`,\n );\n return true;\n}\n\nasync function buildOrganizationCandidate(\n input: CreateOrganizationInput,\n rootContainerId: string,\n): Promise<OrganizationProvisioningArtifacts | null> {\n const artifactsInput: OrganizationProvisioningArtifactsInput = {\n encapsulationKeyPair: input.encapsulationKeyPair,\n organizationProfileName: input.organizationProfileName,\n provisionedSystemContainers: input.provisionedSystemContainers,\n rootContainerId,\n rosterProfileNickname: input.rosterProfileNickname,\n signingKeyPair: input.signingKeyPair,\n userId: input.userId,\n };\n const artifacts: OrganizationProvisioningArtifacts =\n await buildOrganizationProvisioningArtifacts(artifactsInput);\n\n if (input.replacesOrganizationId) {\n artifacts.replacementAuthorization =\n await signOrganizationReplacementAuthorization(\n {\n ...artifacts,\n replacesOrganizationId: input.replacesOrganizationId,\n rootContainerId,\n userId: input.userId,\n },\n input.signingKeyPair,\n );\n }\n\n if (\n input.replacesOrganizationId &&\n input.isIdentityCurrent &&\n !input.isIdentityCurrent()\n ) {\n input.log?.(\n \"Organization creation aborted: identity changed while building artifacts\",\n );\n return null;\n }\n\n return artifacts;\n}\n\n/**\n * Provisions an additional organization for an already-registered user, reusing\n * the exact artifact-build and local-persistence path as registration\n * ({@link buildOrganizationProvisioningArtifacts} /\n * {@link persistOrganizationProvisioningState}). Unlike registration it mints a\n * fresh root container id, signs with the caller's existing identity, and needs\n * no auth challenge — the user is already authenticated.\n */\nexport async function createOrganization(\n input: CreateOrganizationInput,\n): Promise<CreateOrganizationResponse | null> {\n input.log?.(\"Creating organization...\");\n\n const rootContainerId = crypto.randomUUID();\n const candidateArtifacts = await buildOrganizationCandidate(\n input,\n rootContainerId,\n );\n\n if (!candidateArtifacts) return null;\n\n const durableAttempt = await makeOrganizationProvisioningAttemptDurable({\n artifacts: candidateArtifacts,\n canStartDurableMutation: input.isIdentityCurrent,\n dbClient: input.dbClient,\n nativeSubscriptionRestore: input.nativeSubscriptionRestore,\n replacesOrganizationId: input.replacesOrganizationId,\n rootContainerId,\n userId: input.userId,\n });\n if (!durableAttempt) {\n input.log?.(\n \"Organization creation aborted: identity changed before saving artifacts\",\n );\n return null;\n }\n const {\n artifacts,\n request,\n rootContainerId: durableRootContainerId,\n } = durableAttempt;\n\n if (input.isIdentityCurrent && !input.isIdentityCurrent()) {\n input.log?.(\n \"Organization creation aborted: identity changed before provisioning\",\n );\n return null;\n }\n\n const response = await input.apiClient.createOrganization(request);\n if (!response) {\n return null;\n }\n\n if (input.isIdentityCurrent && !input.isIdentityCurrent()) {\n input.log?.(\n \"Organization creation discarded: identity changed while provisioning\",\n );\n return null;\n }\n\n if (\n input.replacesOrganizationId &&\n !(await pinOrganizationReplacementResponse({\n replacesOrganizationId: input.replacesOrganizationId,\n response,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n userId: input.userId,\n execSql: createExecSql(input.dbClient),\n stillCurrent: input.isIdentityCurrent,\n }))\n )\n return null;\n\n if (isAdoptedReplacementResponse({ creation: input, request, response })) {\n // Another device authorized this winning genesis with the same identity.\n // Its encrypted bootstrap will hydrate normally; persisting\n // this device's losing candidate would instead create an unrelated local\n // root. The session reset rebinds retained local data to the winning ids.\n return response;\n }\n\n input.log?.(`Organization created (${response.organizationId})`);\n await persistOrganizationProvisioningState({\n bootstrap: artifacts.bootstrap,\n canStartDurableMutation: input.isIdentityCurrent,\n onPersistQueued: input.onPersistQueued,\n containerId: durableRootContainerId,\n dbClient: input.dbClient,\n documentProjectors: input.documentProjectors,\n initialAdminGroup: artifacts.initialAdminGroup,\n initialMemberGroup: artifacts.initialMemberGroup,\n initialOrganizationPolicy: artifacts.initialOrganizationPolicy,\n log: input.log,\n logError: input.logError,\n organizationMetadataBootstrap: artifacts.organizationMetadataBootstrap,\n primePrincipalHistory: input.primePrincipalHistory,\n response,\n rootContainer: artifacts.rootContainer,\n rootMetadataDocument: artifacts.rootMetadataDocument,\n rootMetadataDocumentRequest: artifacts.rootMetadataDocumentRequest,\n rosterProfileBootstrap: artifacts.rosterProfileBootstrap,\n systemContainerBootstraps: artifacts.systemContainerBootstraps,\n });\n\n return response;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentGroupMetadataAuthority.js","sourceRoot":"","sources":["currentGroupMetadataAuthority.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAEvE,+FAA+F;AAC/F,MAAM,UAAU,2CAA2C,CACzD,KAGC;IAED,OAAO,KAAK,EACV,KAAmC,EACnC,qBAA+C,EAChC,EAAE;QACjB,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxD,MAAM,SAAS,GAAG,MAAM,gCAAgC,CAAC;YACvD,GAAG,KAAK;YACR,qBAAqB;SACtB,CAAC,CAAC;QACH,MAAM,mDAAmD,CAAC;YACxD,SAAS;YACT,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC,CAAC,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,mDAAmD,CAAC,KAMnE;IACC,OA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MAAM,CAAC,MAAM;aAC3B;YACD,OAAO;YACP,KAAK;SACN,CAAC,CAAC;QACH,mCAAmC,CACjC,GAAG,EAAE,CAAC,YAAY,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,IAAI,OAAO,CAAC,YAAY,EAAE,CACxE,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ContainerAccessManifestState,\n KeyingVerificationError,\n type ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport { loadCurrentOrganizationAuthority } from \"./currentOrganizationAuthority\";\nimport { assertMetadataRootBinding } from \"./groupMetadataRootBinding\";\n\n/** Authenticate metadata-root grants with current policies and only its cited predecessors. */\nexport function createCurrentGroupMetadataContainerVerifier(\n input: Omit<\n Parameters<typeof loadCurrentOrganizationAuthority>[0],\n \"organizationReference\"\n >,\n) {\n return async (\n state: ContainerAccessManifestState,\n organizationReference?: ReferencedPrincipalHead,\n ): Promise<void> => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const authority = await loadCurrentOrganizationAuthority({\n ...input,\n organizationReference,\n });\n await createSelectedCurrentGroupMetadataContainerVerifier({\n authority,\n organizationId: input.organizationId,\n stillCurrent: input.stillCurrent,\n })(state, organizationReference);\n };\n}\n\n/** Reuse one mutation's verified authority without broadening its lease or scope. */\nexport function createSelectedCurrentGroupMetadataContainerVerifier(input: {\n readonly authority: Awaited<\n ReturnType<typeof loadCurrentOrganizationAuthority>\n >;\n readonly organizationId: string;\n readonly stillCurrent: () => boolean;\n}) {\n return async (\n state: ContainerAccessManifestState,\n organizationReference?: ReferencedPrincipalHead,\n ): Promise<void> => {\n const { authority } = input;\n const stillCurrent = () => input.stillCurrent() && authority.stillCurrent();\n assertProjectionVerificationCurrent(stillCurrent);\n if (organizationReference) {\n if (\n organizationReference.principalType !== \"organization\" ||\n organizationReference.principalId !== input.organizationId\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Current policy reference is outside its scope\",\n );\n if (\n !principalHeadMatchesReference(\n authority.directory.policy.state,\n organizationReference,\n )\n )\n throw new ProjectionDependencyUnavailableError(\n \"Metadata root belongs to a changed organization directory\",\n );\n }\n const { adminGroupId, memberGroupId } = authority.descriptor;\n const citation = (groupId: string) =>\n state.referencedPrincipalHeads.find(\n (head) =>\n head.principalType === \"group\" && head.principalId === groupId,\n );\n const admins = await authority.readGroup(\n adminGroupId,\n citation(adminGroupId),\n );\n const members = await authority.readGroup(\n memberGroupId,\n citation(memberGroupId),\n );\n assertMetadataRootBinding({\n organizationId: input.organizationId,\n authority: {\n descriptor: authority.descriptor,\n adminGroupId,\n memberGroupId,\n adminPolicy: admins.policy,\n },\n members,\n state,\n });\n assertProjectionVerificationCurrent(\n () => stillCurrent() && admins.stillCurrent() && members.stillCurrent(),\n );\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentGroupMutationReferences.js","sourceRoot":"","sources":["currentGroupMutationReferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iDAAiD,GAElD,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AAEpG,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,qCAAqC,CAAC,KAQ3D;IACC,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,CACb,OAAuC,EACvC,WAA2C,EAC3C,QAA4C,EAC5C,EAAE,CACF,iDAAiD,CAAC;QAChD,OAAO;QACP,WAAW;QACX,UAAU,EAAE,QAAQ;KACrB,CAAC,CAAC;IACL,uEAAuE;IACvE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACrE,IAAI,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC,KAAK,CAAC;IACrC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,oBAAoB;QAAE,MAAM,OAAO,CAAC,KAAK,CAAC;IACrE,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC5B,MAAM,QAAQ,GAA8B,EAAE,CAAC;IAC/C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxD,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzB,IAAI,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;YAC7D,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC;YACpE,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACxD,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,MAAM,MAAM,CAAC,KAAK,CAAC;QACnC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC;IACzB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n type ReferencedPrincipalHead,\n selectPrincipalPolicyCurrentPredecessorReferences,\n type VerifiedPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\n\n/** Select only this path's old citations, preserving the authored membership. */\nexport async function resolveCurrentGroupMutationReferences(input: {\n readonly current: VerifiedPrincipalPolicyCurrent;\n readonly predecessor: VerifiedPrincipalPolicyCurrent;\n readonly references: readonly ReferencedPrincipalHead[];\n readonly readPredecessorReference: (\n reference: ReferencedPrincipalHead,\n ) => Promise<VerifiedPrincipalPolicyCurrent>;\n readonly stillCurrent: () => boolean;\n}): Promise<VerifiedPrincipalPolicyCurrent> {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const references = structuredClone(input.references);\n const select = (\n current: VerifiedPrincipalPolicyCurrent,\n predecessor: VerifiedPrincipalPolicyCurrent,\n selected: readonly ReferencedPrincipalHead[],\n ) =>\n selectPrincipalPolicyCurrentPredecessorReferences({\n current,\n predecessor,\n references: selected,\n });\n // Normalize and bound the entire request before any per-reference I/O.\n const initial = select(input.current, input.predecessor, references);\n if (initial.ok) return initial.value;\n if (initial.error.code !== \"missing_dependency\") throw initial.error;\n let current = input.current;\n const selected: ReferencedPrincipalHead[] = [];\n for (const reference of references) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n selected.push(reference);\n let result = select(current, input.predecessor, selected);\n if (!result.ok && result.error.code === \"missing_dependency\") {\n const predecessor = await input.readPredecessorReference(reference);\n assertProjectionVerificationCurrent(input.stillCurrent);\n result = select(current, predecessor, selected);\n }\n if (!result.ok) throw result.error;\n current = result.value;\n }\n return current;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentGroupPolicyMutationContext.js","sourceRoot":"","sources":["currentGroupPolicyMutationContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,4BAA4B,GAE7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,kCAAkC,EAAE,MAAM,2DAA2D,CAAC;AAC/G,OAAO,EAAE,4BAA4B,EAAE,MAAM,uDAAuD,CAAC;AAGrG,OAAO,EAAE,mDAAmD,EAAE,MAAM,iCAAiC,CAAC;AAC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AAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBACtD,CAAC;gBACD,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBACpD,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAC/B,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBACtD,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO;oBAAE,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC5D,MAAM,KAAK,CAAC;YACd,CAAC,CAAC,CAAC;YACH,mCAAmC,CAAC,YAAY,CAAC,CAAC;YAClD,mCAAmC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC3D,OAAO,QAAQ,CAAC,MAAM,CAAC;QACzB,CAAC;QACD,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import {\n type PrincipalPolicyExternalAuthority,\n type ReferencedPrincipalHead,\n serializeKeyingCanonicalJson,\n type VerifiedPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { advanceKeyingCheckpointsAtomically } from \"../../data/persistence/keyingCheckpointAdvancePersistence\";\nimport { requireOrganizationGroupHead } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { createRuntimePrincipalPolicyCurrentResolver } from \"../principals/runtimePolicyRecovery\";\nimport { createSelectedCurrentGroupMetadataContainerVerifier } from \"./currentGroupMetadataAuthority\";\nimport { loadCurrentOrganizationMutationAuthority } from \"./currentOrganizationMutationAuthority\";\nimport { assertGroupMetadataBinding } from \"./groupMetadataBinding\";\nimport { requireSignerCanManageGroup } from \"./groupMutationAuthorization\";\n\n/** Exact current directory, strict Admins and group evidence for one mutation. */\nexport async function loadCurrentGroupPolicyMutationContext(input: {\n readonly execSql: ExecSql;\n readonly groupId: string;\n readonly organizationId: string;\n readonly signerUserId: string;\n readonly resolveCurrentPolicy: NonNullable<\n ReturnType<typeof createRuntimePrincipalPolicyCurrentResolver>\n >;\n readonly recoverPendingPrincipalMutation: (\n organizationId: string,\n ) => Promise<void>;\n readonly stillCurrent: () => boolean;\n}) {\n input = { ...input };\n const { authority, currentOrgAdminUserIds } =\n await loadCurrentOrganizationMutationAuthority(input);\n const group = await authority.readGroup(input.groupId);\n const stillCurrent = () =>\n input.stillCurrent() && authority.stillCurrent() && group.stillCurrent();\n assertProjectionVerificationCurrent(stillCurrent);\n assertGroupMetadataBinding(group.current, authority.descriptor);\n requireSignerCanManageGroup(\n group.current,\n currentOrgAdminUserIds,\n input.signerUserId,\n );\n await advanceKeyingCheckpointsAtomically({\n access: [],\n execSql: input.execSql,\n organizationId: input.organizationId,\n policies: [...group.dependencies, group.policy],\n stillCurrent,\n });\n assertProjectionVerificationCurrent(stillCurrent);\n const adminHead = requireOrganizationGroupHead(\n authority.descriptor,\n authority.descriptor.adminGroupId,\n );\n const externalAuthority: PrincipalPolicyExternalAuthority = {\n currentHead: adminHead,\n states: [\n { head: adminHead, projection: authority.admins.policy.projection },\n ],\n };\n // A reused citation keeps the lifetime of the read that produced it.\n const references = new Map<\n string,\n Promise<{\n readonly policy: VerifiedPrincipalPolicyCurrent;\n readonly stillCurrent: () => boolean;\n }>\n >();\n return {\n adminGroupId: authority.descriptor.adminGroupId,\n adminCurrent: authority.admins,\n currentPolicy: group.current,\n verifiedCurrentPolicy: group.policy,\n verifyMetadataContainer:\n createSelectedCurrentGroupMetadataContainerVerifier({\n authority,\n organizationId: input.organizationId,\n stillCurrent,\n }),\n currentOrgAdminUserIds,\n externalAuthority,\n isOrganizationAdminsGroup:\n input.groupId === authority.descriptor.adminGroupId,\n localPolicyCheckpoint: group.policy.checkpoint,\n memberGroupId: authority.descriptor.memberGroupId,\n organizationDescriptor: authority.descriptor,\n organizationCurrent: authority.directory,\n async readPredecessorReference(reference: ReferencedPrincipalHead) {\n assertProjectionVerificationCurrent(stillCurrent);\n const owned = structuredClone(reference);\n const key = serializeKeyingCanonicalJson({ ...owned });\n let pending = references.get(key);\n if (!pending) {\n // Keep at most one bounded selection's citations, even across many paths.\n if (references.size === 128) {\n const oldest = references.keys().next().value;\n if (oldest !== undefined) references.delete(oldest);\n }\n pending = authority.readGroup(input.groupId, owned);\n references.set(key, pending);\n }\n const selected = await pending.catch((error: unknown) => {\n if (references.get(key) === pending) references.delete(key);\n throw error;\n });\n assertProjectionVerificationCurrent(stillCurrent);\n assertProjectionVerificationCurrent(selected.stillCurrent);\n return selected.policy;\n },\n stillCurrent,\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentOrganizationGroupNames.js","sourceRoot":"","sources":["currentOrganizationGroupNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,kCAAkC,EAAE,MAAM,2DAA2D,CAAC;AAC/G,OAAO,EAAE,iCAAiC,EAAE,MAAM,uEAAuE,CAAC;AAE1H,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAEL,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC;AAclC,gGAAgG;AAChG,MAAM,CAAC,KAAK,UAAU,oCAAoC,CACxD,KAAY;IAEZ,MAAM,SAAS,GAAG,MAAM,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG;QAChB,GAAG,KAAK;QACR,iBAAiB,EACf,KAAK,CAAC,uBAAuB,EAAE,CAAC,SAAS,CAAC,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K,CAAC;QAClE,MAAM,KAAK,CAAC,sBAAsB,CAChC,IAAI,uBAAuB,CACzB,eAAe,EACf,8DAA8D,CAC/D,EACD;YACE,cAAc,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE;YAC7D,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,WAAW;YAC1C,UAAU,EAAE,WAAW;YACvB,SAAS,EAAE,wBAAwB;YACnC,cAAc,EAAE,KAAK,CAAC,cAAc;SACrC,CACF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { advanceKeyingCheckpointsAtomically } from \"../../data/persistence/keyingCheckpointAdvancePersistence\";\nimport { saveOrganizationGroupDisplayNames } from \"../../data/persistence/organizations/organizationGroupNamePersistence\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport { loadCurrentOrganizationAuthority } from \"./currentOrganizationAuthority\";\nimport { GroupMetadataUnreadableError } from \"./groupMetadataAccess\";\nimport { assertGroupMetadataBinding } from \"./groupMetadataBinding\";\nimport {\n type GroupPolicyNameReader,\n readGroupPolicyPayloadName,\n} from \"./principalPolicyRequest\";\nimport type { OrganizationDirectoryAndGroups } from \"./readModel\";\n\ntype Input = Parameters<typeof loadCurrentOrganizationAuthority>[0] & {\n readonly directory: OrganizationDirectoryAndGroups;\n readonly readEncryptedName?: GroupPolicyNameReader | undefined;\n readonly createCurrentNameReader?:\n | ((\n authority: Awaited<ReturnType<typeof loadCurrentOrganizationAuthority>>,\n ) => GroupPolicyNameReader)\n | undefined;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n};\n\n/** Names consume verified current artifacts; paged recovery retains their separate evidence. */\nexport async function hydrateCurrentOrganizationGroupNames(\n input: Input,\n): Promise<OrganizationDirectoryAndGroups> {\n const authority = await loadCurrentOrganizationAuthority(input);\n const nameInput = {\n ...input,\n readEncryptedName:\n input.createCurrentNameReader?.(authority) ?? input.readEncryptedName,\n };\n const names: { groupId: string; name: string; stateHash: string }[] = [];\n const unreadable = new Set<string>();\n const lifetimes: (() => boolean)[] = [authority.stillCurrent];\n for (const group of input.directory.groups) {\n const head = authority.descriptor.groupHeads.find(\n (head) => head.principalId === group.groupId,\n );\n if (!head || head.stateHash !== group.currentState?.stateHash)\n throw new Error(\"Group listing does not match the signed directory\");\n const verified = await authority.readGroup(group.groupId);\n lifetimes.push(verified.stillCurrent);\n assertGroupMetadataBinding(verified.current, authority.descriptor);\n const name = await readCurrentGroupName(nameInput, verified.current);\n if (name === null) unreadable.add(group.groupId);\n else\n names.push({ groupId: group.groupId, name, stateHash: head.stateHash });\n }\n const stillCurrent = () =>\n input.stillCurrent() && lifetimes.every((current) => current());\n assertProjectionVerificationCurrent(stillCurrent);\n // Match the authority admission performed by the full-bundle path. Group\n // name reads alone do not move group checkpoints.\n await advanceKeyingCheckpointsAtomically({\n access: [],\n execSql: input.execSql,\n organizationId: input.organizationId,\n policies: [authority.directory.policy, authority.admins.policy],\n stillCurrent,\n });\n await saveOrganizationGroupDisplayNames({ ...input, names, stillCurrent });\n assertProjectionVerificationCurrent(stillCurrent);\n const byId = new Map(names.map((entry) => [entry.groupId, entry.name]));\n return {\n ...input.directory,\n groups: input.directory.groups.map((group) => ({\n ...group,\n name: byId.get(group.groupId) ?? \"\",\n nameUnreadable: unreadable.has(group.groupId),\n })),\n };\n}\n\nasync function readCurrentGroupName(\n input: Input,\n current: Parameters<GroupPolicyNameReader>[0],\n) {\n try {\n return await readGroupPolicyPayloadName(current, input.readEncryptedName);\n } catch (error) {\n if (!(error instanceof GroupMetadataUnreadableError)) throw error;\n await input.reportSecurityIncident(\n new KeyingVerificationError(\n \"invalid_shape\",\n \"Signed group name does not open under the cited metadata key\",\n ),\n {\n evidenceHashes: { stateHash: current.currentState.stateHash },\n objectId: current.currentState.principalId,\n objectKind: \"principal\",\n operation: \"organization.groupName\",\n organizationId: input.organizationId,\n },\n );\n return null;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentOrganizationMutationAuthority.js","sourceRoot":"","sources":["currentOrganizationMutationAuthority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,8BAA8B,EAAE,MAAM,mDAAmD,CAAC;AACnG,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAElF,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,wCAAwC,CAC5D,KAQC;IAED,MAAM,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC3B,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,KAAK,CAAC,+BAA+B,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAClE,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,MAAM,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAChE,MAAM,sBAAsB,GAAG,8BAA8B,CAC3D,SAAS,CAAC,MAAM,CAAC,MAAM,CACxB,CAAC;IACF,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["import { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { organizationAdminSignerUserIds } from \"../../data/principals/principalPolicyAdminSigners\";\nimport { loadCurrentOrganizationAuthority } from \"./currentOrganizationAuthority\";\n\n/** Resolve uncertain work and verify the signing administrator before any mutation pins. */\nexport async function loadCurrentOrganizationMutationAuthority(\n input: Omit<\n Parameters<typeof loadCurrentOrganizationAuthority>[0],\n \"organizationReference\"\n > & {\n readonly signerUserId: string;\n readonly recoverPendingPrincipalMutation: (\n organizationId: string,\n ) => Promise<void>;\n },\n) {\n const owned = { ...input };\n assertProjectionVerificationCurrent(owned.stillCurrent);\n await owned.recoverPendingPrincipalMutation(owned.organizationId);\n assertProjectionVerificationCurrent(owned.stillCurrent);\n const authority = await loadCurrentOrganizationAuthority(owned);\n const currentOrgAdminUserIds = organizationAdminSignerUserIds(\n authority.admins.policy,\n );\n if (!currentOrgAdminUserIds.includes(owned.signerUserId))\n throw new Error(\"Organization admin authority is required\");\n return { authority, currentOrgAdminUserIds };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentOrganizationMutationRetention.js","sourceRoot":"","sources":["currentOrganizationMutationRetention.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,4BAA4B,EAAE,MAAM,uDAAuD,CAAC;AACrG,OAAO,EAAE,kCAAkC,EAAE,MAAM,mDAAmD,CAAC;AACvG,OAAO,EAAE,uCAAuC,EAAE,MAAM,gDAAgD,CAAC;AAIzG,OAAO,EAEL,mCAAmC,GACpC,MAAM,uCAAuC,CAAC;AAE/C,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,0CAA0C,CAAC,KAUhE;IACC,MAAM,WAAW,GAAG,MAAM,uCAAuC,CAAC;QAChE,GAAG,KAAK,CAAC,iBAAiB;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;QACpC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,KAAK,EAClB,OAAqD,EACrD,EAAE;QACF,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxD,MAAM,mCAAmC,CAAC;YACxC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;YACpC,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,QAAQ,EAAE,OAAO,CAAC,oBAAoB;oBACtC,QAAQ,EAAE,KAAK,CAAC,iBAAiB;iBAClC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PrincipalPolicyHistoryProgressOptions } from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { scopedGroupHistoryProtection } from \"../../data/principals/principalHistoryScopeProtection\";\nimport { principalPolicyReferenceFromBundle } from \"../../data/principals/principalPolicyAdminSigners\";\nimport { captureAcknowledgedPrincipalPredecessor } from \"../principals/acknowledgedPrincipalPredecessor\";\nimport type { PrincipalPolicyPageReader } from \"../principals/principalPolicyHistoryReader\";\nimport type { PrincipalPolicyRecoveryRuntime } from \"../principals/runtimePolicyRecovery\";\nimport type { loadCurrentOrganizationAuthority } from \"./currentOrganizationAuthority\";\nimport {\n type AcknowledgedPrincipalCurrentInput,\n retainAcknowledgedPrincipalCurrents,\n} from \"./retainAcknowledgedPrincipalCurrents\";\n\n/** Couple directory acknowledgements to any newly created group under the same lease. */\nexport async function createCurrentOrganizationMutationRetention(input: {\n readonly runtime: PrincipalPolicyRecoveryRuntime;\n readonly authority: Awaited<\n ReturnType<typeof loadCurrentOrganizationAuthority>\n >;\n readonly protection: PrincipalPolicyHistoryProgressOptions;\n readonly historyReader: PrincipalPolicyPageReader;\n readonly organizationId: string;\n readonly directoryRecovery: AcknowledgedPrincipalCurrentInput[\"recovery\"];\n readonly stillCurrent: () => boolean;\n}) {\n const predecessor = await captureAcknowledgedPrincipalPredecessor({\n ...input.directoryRecovery,\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n stillCurrent: input.stillCurrent,\n });\n const retain = async (\n entries: readonly AcknowledgedPrincipalCurrentInput[],\n ) => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n await retainAcknowledgedPrincipalCurrents({\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n entries,\n stillCurrent: input.stillCurrent,\n });\n };\n return {\n retainDirectory: (\n request: PutPrincipalPolicyRequest,\n response: PrincipalPolicyMutationResponse,\n ) =>\n retain([\n { predecessor, request, response, recovery: input.directoryRecovery },\n ]),\n retainCreatedGroup: (receipt: {\n readonly request: PutPrincipalPolicyRequest;\n readonly response: PrincipalPolicyMutationResponse;\n readonly organizationRequest: PutPrincipalPolicyRequest;\n readonly organizationResponse: PrincipalPolicyMutationResponse;\n }) => {\n const adminHead = {\n ...principalPolicyReferenceFromBundle(input.authority.admins.current),\n principalType: \"group\" as const,\n };\n return retain([\n {\n initialGroup: true,\n predecessor: null,\n request: receipt.request,\n response: receipt.response,\n recovery: {\n historyReader: input.historyReader,\n expectedHead: principalPolicyReferenceFromBundle(receipt.response),\n protection: scopedGroupHistoryProtection(\n input.protection,\n input.organizationId,\n input.authority.descriptor.adminGroupId,\n ),\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n loadExternalAuthority: async () => ({\n currentHead: adminHead,\n states: [\n {\n head: adminHead,\n projection: input.authority.admins.policy.projection,\n },\n ],\n }),\n },\n },\n {\n predecessor,\n request: receipt.organizationRequest,\n response: receipt.organizationResponse,\n recovery: input.directoryRecovery,\n },\n ]);\n },\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentPolicyMutationAcknowledgement.js","sourceRoot":"","sources":["currentPolicyMutationAcknowledgement.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,+BAA+B,EAC/B,qCAAqC,GACtC,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,4CAA4C,EAAE,MAAM,2BAA2B,CAAC;AAazF,qFAAqF;AACrF,MAAM,CA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BAAiB,EAAE,OAAO,CAAC,UAAU;YACrC,aAAa,EAAE,OAAO,CAAC,MAAM;YAC7B,cAAc,EAAE;gBACd,GAAG,OAAO,CAAC,gBAAgB;gBAC3B,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,SAAS,EAAE,KAAK,CAAC,SAAS;aAC3B;YACD,sBAAsB,EAAE;gBACtB,SAAS,EAAE,OAAO,CAAC,eAAe;gBAClC,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,KAAK,EAAE,KAAK,CAAC,QAAQ;aACtB;SACF;KACF,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,QAAQ,CAAC,KAAK,CAAC;IACvC,4CAA4C,CAC1C,QAAQ,CAAC,KAAK,CAAC,KAAK,EACpB,YAAY,CACb,CAAC;IACF,+BAA+B,CAAC;QAC9B,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,eAAe;QACrC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK;QAClC,eAAe,EAAE,KAAK,CAAC,qBAAqB;KAC7C,CAAC,CAAC;IACH,mCAAmC,CAAC,YAAY,CAAC,CAAC;IAClD,OAAO,QAAQ,CAAC,KAAK,CAAC;AACxB,CAAC","sourcesContent":["import {\n type PrincipalPolicyCheckpoint,\n type PrincipalPolicyExternalAuthority,\n type PrincipalPolicySignerPublicKey,\n type ReferencedPrincipalHead,\n type VerifiedPrincipalPolicyCurrent,\n verifyPrincipalPolicyCheckpoint,\n verifyPrincipalPolicyCurrentSuccessor,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalStateResponse } from \"@tearleads/validators/response\";\nimport { canonicalKeyingJsonString } from \"../../data/keying/canonicalJson\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { assertPrincipalPolicyCurrentStateMatchesHead } from \"./groupPolicyMutationHead\";\n\nexport interface CurrentPolicyMutationInput {\n readonly currentPolicy?: never;\n readonly verifiedCurrentPolicy: VerifiedPrincipalPolicyCurrent;\n readonly expectedHead: ReferencedPrincipalHead;\n readonly request: PutPrincipalPolicyRequest;\n readonly signerPublicKeys: readonly PrincipalPolicySignerPublicKey[];\n readonly externalAuthority?: PrincipalPolicyExternalAuthority | undefined;\n readonly localPolicyCheckpoint?: PrincipalPolicyCheckpoint | null;\n readonly stillCurrent: () => boolean;\n}\n\n/** Verify a single authored successor; this neither admits it nor persists a pin. */\nexport async function verifyCurrentPolicyMutation(\n input: CurrentPolicyMutationInput,\n acknowledgedState?: PrincipalStateResponse,\n): Promise<VerifiedPrincipalPolicyCurrent> {\n const previous = input.verifiedCurrentPolicy;\n const stillCurrent = input.stillCurrent;\n const owned = structuredClone({\n expectedHead: input.expectedHead,\n request: input.request,\n signerPublicKeys: input.signerPublicKeys,\n externalAuthority: input.externalAuthority,\n localPolicyCheckpoint: input.localPolicyCheckpoint,\n acknowledgedState,\n });\n assertProjectionVerificationCurrent(stillCurrent);\n const { request, expectedHead } = owned;\n const state = owned.acknowledgedState ?? {\n ...request.state,\n stateHash: expectedHead.stateHash,\n createdAt: request.state.signedAt,\n };\n if (owned.acknowledgedState) {\n const { createdAt: _createdAt, stateHash, ...responseState } = state;\n if (\n stateHash !== expectedHead.stateHash ||\n canonicalKeyingJsonString(responseState, \"stored group policy state\") !==\n canonicalKeyingJsonString(request.state, \"authored group policy state\")\n )\n throw new Error(\"Group policy state acknowledgement mismatch\");\n }\n const verified = await verifyPrincipalPolicyCurrentSuccessor({\n previous,\n signerPublicKeys: owned.signerPublicKeys,\n externalAuthority: owned.externalAuthority,\n current: {\n currentState: state,\n currentProjection: request.projection,\n currentGrants: request.grants,\n currentPayload: {\n ...request.encryptedPayload,\n principalId: state.principalId,\n principalType: state.principalType,\n stateHash: state.stateHash,\n },\n currentMemberEnvelopes: {\n envelopes: request.memberEnvelopes,\n principalId: state.principalId,\n principalType: state.principalType,\n stateHash: state.stateHash,\n epoch: state.keyEpoch,\n },\n },\n });\n if (!verified.ok) throw verified.error;\n assertPrincipalPolicyCurrentStateMatchesHead(\n verified.value.state,\n expectedHead,\n );\n verifyPrincipalPolicyCheckpoint({\n chain: verified.value.retainedHistory,\n currentState: verified.value.state,\n localCheckpoint: owned.localPolicyCheckpoint,\n });\n assertProjectionVerificationCurrent(stillCurrent);\n return verified.value;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentPrincipalMutationLease.js","sourceRoot":"","sources":["currentPrincipalMutationLease.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EAAE,0BAA0B,EAAE,MAAM,uDAAuD,CAAC;AACnG,OAAO,EAAE,kCAAkC,EAAE,MAAM,mDAAmD,CAAC;AACvG,OAAO,EACL,4BAA4B,GAE7B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,2CAA2C,GAE5C,MAAM,qCAAqC,CAAC;AAoB7C,yFAAyF;AACzF,MAAM,UAAU,mCAAmC,CACjD,OAAuC;IAEvC,MAAM,KAAK,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,oBAAoB,GACxB,2CAA2C,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,aAAa,GAAG,4BAA4B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtE,IAAI,CAAC,KAAK,IAAI,CAAC,oBAAoB,IAAI,CAAC,aAAa;QAAE,OAAO,SAAS,CAAC;IACxE,OAAO,KAAK,EACV,aAA4B,EAC5B,IAAmE,EACvD,EAAE,CACd,KAAK,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,EAAE,EAAE;QACzD,IAAI,MAAM,GAAG,IAAI,CAAC;QAClB,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,MAAM,IAAI,YAAY,EAAE,IAAI,aAAa,EAAE,CAAC;QACvE,IAAI,CAAC;YACH,mCAAmC,CAAC,YAAY,CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC;gBACxB,UAAU;gBACV,YAAY;gBACZ,oBAAoB;gBACpB,aAAa;gBACb,iBAAiB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBAC/B,aAAa;oBACb,YAAY,EAAE,kCAAkC,CAAC,OAAO,CAAC;oBACzD,UAAU,EAAE,0BAA0B,CAAC,UAAU,CAAC;oBAClD,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;iBAC/D,CAAC;aACH,CAAC,CAAC;YACH,mCAAmC,CAAC,YAAY,CAAC,CAAC;YAClD,OAAO,MAAM,CAAC;QAChB,CAAC;gBAAS,CAAC;YACT,MAAM,GAAG,KAAK,CAAC;QACjB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport type { PrincipalPolicyHistoryProgressOptions } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { readPrincipalHistoryProtection } from \"../../data/principals/principalHistoryRuntime\";\nimport { directoryHistoryProtection } from \"../../data/principals/principalHistoryScopeProtection\";\nimport { principalPolicyReferenceFromBundle } from \"../../data/principals/principalPolicyAdminSigners\";\nimport {\n apiPrincipalPolicyPageReader,\n type PrincipalPolicyPageReader,\n} from \"../principals/principalPolicyHistoryReader\";\nimport {\n createRuntimePrincipalPolicyCurrentResolver,\n type PrincipalPolicyRecoveryRuntime,\n} from \"../principals/runtimePolicyRecovery\";\nimport type { AcknowledgedPrincipalCurrentInput } from \"./retainAcknowledgedPrincipalCurrents\";\n\ninterface CurrentPrincipalMutationLeaseContext {\n readonly protection: PrincipalPolicyHistoryProgressOptions;\n readonly stillCurrent: () => boolean;\n readonly resolveCurrentPolicy: NonNullable<\n ReturnType<typeof createRuntimePrincipalPolicyCurrentResolver>\n >;\n readonly historyReader: PrincipalPolicyPageReader;\n readonly directoryRecovery: (\n current: PrincipalPolicyPageCurrent,\n ) => AcknowledgedPrincipalCurrentInput[\"recovery\"];\n}\n\ntype CurrentPrincipalMutationLease = <T>(\n callerCurrent: () => boolean,\n work: (context: CurrentPrincipalMutationLeaseContext) => Promise<T>,\n) => Promise<T>;\n\n/** One lifetime fence and private custody boundary for every current-policy mutation. */\nexport function createCurrentPrincipalMutationLease(\n runtime: PrincipalPolicyRecoveryRuntime,\n): CurrentPrincipalMutationLease | undefined {\n const lease = readPrincipalHistoryProtection(runtime);\n const resolveCurrentPolicy =\n createRuntimePrincipalPolicyCurrentResolver(runtime);\n const historyReader = apiPrincipalPolicyPageReader(runtime.apiClient);\n if (!lease || !resolveCurrentPolicy || !historyReader) return undefined;\n return async <T>(\n callerCurrent: () => boolean,\n work: (context: CurrentPrincipalMutationLeaseContext) => Promise<T>,\n ): Promise<T> =>\n lease(async ({ protection, stillCurrent: leaseCurrent }) => {\n let active = true;\n const stillCurrent = () => active && leaseCurrent() && callerCurrent();\n try {\n assertProjectionVerificationCurrent(stillCurrent);\n const result = await work({\n protection,\n stillCurrent,\n resolveCurrentPolicy,\n historyReader,\n directoryRecovery: (current) => ({\n historyReader,\n expectedHead: principalPolicyReferenceFromBundle(current),\n protection: directoryHistoryProtection(protection),\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n }),\n });\n assertProjectionVerificationCurrent(stillCurrent);\n return result;\n } finally {\n active = false;\n }\n });\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dataUsageReadModel.js","sourceRoot":"","sources":["dataUsageReadModel.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,GACpC,MA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AAK,CAAC,eAAe;gBACtC,QAAQ,EAAE,MAAM,CAAC,IAAI;aACtB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,KAAK,CAAC,QAAQ,EAAE,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;YACrE,OAAO,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,qCAAqC,CAAC,KAAK,EAAE,OAAO,CAAC;YAC1D,CAAC,CAAC,MAAM,CAAC,IAAI;YACb,CAAC,CAAC,IAAI,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n RequestResult,\n RequestResultOptions,\n} from \"@tearleads/api-client\";\nimport type { OrganizationDataUsageResponse } from \"@tearleads/validators/response\";\nimport {\n loadOrganizationDataUsageProjection,\n purgeOrganizationDataUsageProjection,\n saveOrganizationDataUsageProjection,\n} from \"../../data/persistence/organizations/organizationDataUsagePersistence\";\nimport { recordOrganizationPresentationDenials } from \"../../data/persistence/organizations/organizationPresentationDenialPersistence\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport {\n captureOrganizationPresentationAccessAttempt,\n denyOrganizationPresentationAccess,\n isOrganizationPresentationAccessAttemptCurrent,\n isOrganizationPresentationAccessReadable,\n type OrganizationPresentationAccessAttempt,\n restoreOrganizationPresentationAccess,\n runOrganizationPresentationMutation,\n runOrganizationPresentationRead,\n} from \"./organizationPresentationAccessState\";\nimport { isOrganizationPresentationAccessDeniedFailure } from \"./organizationPresentationFailures\";\n\nexport type OrganizationDataUsage = OrganizationDataUsageResponse;\n\ninterface OrganizationDataUsageApi {\n getOrganizationDataUsageResult(\n organizationId: string,\n options?: RequestResultOptions,\n ): Promise<RequestResult<OrganizationDataUsageResponse>>;\n}\n\ninterface OrganizationDataUsageProjectionInput {\n readonly execSql: ExecSql;\n readonly organizationId: string;\n readonly requesterUserId: string;\n}\n\nexport interface ReconcileOrganizationDataUsageInput\n extends OrganizationDataUsageProjectionInput {\n readonly apiClient: OrganizationDataUsageApi;\n readonly logError?:\n | ((message: string | Error, cause?: unknown) => void)\n | undefined;\n}\n\nexport async function loadLocalOrganizationDataUsage(\n input: OrganizationDataUsageProjectionInput,\n): Promise<OrganizationDataUsage | null> {\n return runOrganizationPresentationRead(input, \"usage\", () =>\n loadOrganizationDataUsageProjection(\n input.execSql,\n input.organizationId,\n input.requesterUserId,\n ),\n );\n}\n\nfunction retainedIfUsageReadable<T>(\n input: OrganizationDataUsageProjectionInput,\n attempt: OrganizationPresentationAccessAttempt,\n value: T,\n): T | null {\n return isOrganizationPresentationAccessAttemptCurrent(input, attempt) &&\n isOrganizationPresentationAccessReadable(input, \"usage\")\n ? value\n : null;\n}\n\nexport async function reconcileOrganizationDataUsage(\n input: ReconcileOrganizationDataUsageInput,\n): Promise<OrganizationDataUsage | null> {\n const attempt = captureOrganizationPresentationAccessAttempt(input, \"usage\");\n const local = await loadLocalOrganizationDataUsage(input);\n const result = await input.apiClient.getOrganizationDataUsageResult(\n input.organizationId,\n { reportErrors: false },\n );\n if (!result.ok) {\n if (isOrganizationPresentationAccessDeniedFailure(result)) {\n denyOrganizationPresentationAccess(input, [\"usage\"]);\n // Durable marker first: a failed purge plus a restart must not serve\n // the revoked usage projection.\n try {\n await runOrganizationPresentationMutation(input.execSql, () =>\n recordOrganizationPresentationDenials(input, [\"usage\"]),\n );\n } catch (error) {\n input.logError?.(\n \"Failed to record denied organization data usage\",\n error,\n );\n }\n try {\n await runOrganizationPresentationMutation(input.execSql, () =>\n purgeOrganizationDataUsageProjection(\n input.execSql,\n input.organizationId,\n input.requesterUserId,\n ),\n );\n } catch (error) {\n input.logError?.(\n \"Failed to purge denied organization data usage\",\n error,\n );\n }\n return null;\n }\n\n result.report();\n return retainedIfUsageReadable(input, attempt, local);\n }\n\n if (result.data.organizationId !== input.organizationId) {\n input.logError?.(\n `Organization data-usage response scope does not match ${input.organizationId}`,\n );\n return retainedIfUsageReadable(input, attempt, local);\n }\n\n return runOrganizationPresentationMutation(input.execSql, async () => {\n if (!isOrganizationPresentationAccessAttemptCurrent(input, attempt)) {\n return null;\n }\n try {\n await saveOrganizationDataUsageProjection({\n execSql: input.execSql,\n requesterUserId: input.requesterUserId,\n response: result.data,\n });\n } catch (error) {\n input.logError?.(\"Failed to persist organization data usage\", error);\n return retainedIfUsageReadable(input, attempt, local);\n }\n return restoreOrganizationPresentationAccess(input, attempt)\n ? result.data\n : null;\n });\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"deleteCurrentOrganizationGroup.js","sourceRoot":"","sources":["deleteCurrentOrganizationGroup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AAGpG,OAAO,EACL,4CAA4C,EAC5C,2BAA2B,GAC5B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,4BAA4B,CAAC;AAEpC,uFAAuF;AACvF,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAAC,KAYpD;IACC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;IACzD,MAAM,OAAO,GAAG,MAAM,4CAA4C,CAAC;QACjE,GAAG,KAAK;QACR,eAAe;QACf,UAAU,EAAE,MAAM,6BAA6B,CAAC;YAC9C,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;YAC5D,OAAO,EAAE,iBAAiB,CAAC,eAAe,CAAC;SAC5C,CAAC;QACF,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,OAAO;QACxC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,UAAU,EAAE,2BAA2B,CAAC;YACtC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC;KACH,CAAC,CAAC;IACH,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,uBAAuB,CAC1D,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAChC,CAAC;IACF,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC3D,IACE,MAAM,CAAC,cAAc,KAAK,KAAK,CAAC,cAAc;QAC9C,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;QAEhC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,MAAM,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAClE,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { SigningKeyPair } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport type { deleteOrganizationGroup } from \"./deleteOrganizationGroup\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n removeOrganizationGroupHead,\n} from \"./organizationGroupDirectory\";\nimport type { CurrentOrganizationMutationContext } from \"./runtimeCurrentOrganizationMutation\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"./trustedOrganizationUsers\";\n\n/** Delete against a verified directory without loading the removed group's history. */\nexport async function deleteCurrentOrganizationGroup(input: {\n readonly apiClient: Pick<\n Parameters<typeof deleteOrganizationGroup>[0][\"apiClient\"],\n \"deleteOrganizationGroup\"\n >;\n readonly context: CurrentOrganizationMutationContext;\n readonly groupId: string;\n readonly organizationId: string;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}) {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const adminProjection = context.admins.policy.projection;\n const request = await buildOrganizationGroupDirectoryPolicyRequest({\n ...input,\n adminProjection,\n adminUsers: await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n }),\n currentPolicy: context.directory.current,\n descriptor: context.descriptor,\n groupHeads: removeOrganizationGroupHead({\n descriptor: context.descriptor,\n groupId: input.groupId,\n }),\n });\n assertProjectionVerificationCurrent(context.stillCurrent);\n const stored = await input.apiClient.deleteOrganizationGroup(\n input.organizationId,\n input.groupId,\n { organizationPolicy: request },\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n if (!stored) throw new Error(\"Group could not be deleted\");\n if (\n stored.organizationId !== input.organizationId ||\n stored.groupId !== input.groupId\n )\n throw new Error(\"Group deletion response target mismatch\");\n await context.retainDirectory(request, stored.organizationPolicy);\n assertProjectionVerificationCurrent(context.stillCurrent);\n return stored;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"deleteOrganizationGroup.js","sourceRoot":"","sources":["deleteOrganizationGroup.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,gDAAgD,EAAE,MAAM,iEAAiE,CAAC;AAGnI,OAAO,EAAE,mCAAmC,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,4CAA4C,EAC5C,2BAA2B,GAC5B,MAAM,8BAA8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EAAE,CAAC;QACrE,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,YAAY;KACb,CAAC,CAAC;IACH,mCAAmC,CAAC,YAAY,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { SigningKeyPair } from \"@tearleads/crypto\";\nimport type { DeleteOrganizationGroupRequest } from \"@tearleads/validators/request\";\nimport type { DeleteOrganizationGroupResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { persistLocallyAcknowledgedPrincipalPolicyBundles } from \"../../data/persistence/locallyAcknowledgedCheckpointPersistence\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport { loadOrganizationExternalAdminPolicy } from \"../principals/externalAdminPolicy\";\nimport {\n acknowledgeGroupPolicyState,\n buildAcknowledgedGroupPolicyBundle,\n} from \"./groupPolicyMutationAcknowledgement\";\nimport type { PrincipalPolicyReadApi } from \"./groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"./groupPolicyMutationHead\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n removeOrganizationGroupHead,\n} from \"./organizationGroupDirectory\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"./trustedOrganizationUsers\";\n\nexport async function deleteOrganizationGroup(input: {\n readonly apiClient: PrincipalPolicyReadApi & {\n deleteOrganizationGroup: (\n organizationId: string,\n groupId: string,\n request: DeleteOrganizationGroupRequest,\n ) => Promise<DeleteOrganizationGroupResponse | null>;\n };\n readonly execSql: ExecSql;\n readonly groupId: string;\n readonly organizationId: string;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<DeleteOrganizationGroupResponse> {\n const stillCurrent = input.stillCurrent;\n assertProjectionVerificationCurrent(stillCurrent);\n await input.apiClient.recoverPendingPrincipalMutation?.(input.organizationId);\n assertProjectionVerificationCurrent(stillCurrent);\n const externalAdminPolicy = await loadOrganizationExternalAdminPolicy({\n currentPolicyReader: input.apiClient,\n execSql: input.execSql,\n organizationId: input.organizationId,\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n stillCurrent,\n });\n assertProjectionVerificationCurrent(stillCurrent);\n if (!externalAdminPolicy?.signerUserIds.includes(input.signerUserId)) {\n throw new Error(\"Organization admin authority could not be verified\");\n }\n const adminProjection = externalAdminPolicy.adminBundle.currentProjection;\n const adminUsers = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n });\n const organizationRequest =\n await buildOrganizationGroupDirectoryPolicyRequest({\n adminProjection,\n adminUsers,\n currentPolicy: externalAdminPolicy.bundle,\n descriptor: externalAdminPolicy.descriptor,\n groupHeads: removeOrganizationGroupHead({\n descriptor: externalAdminPolicy.descriptor,\n groupId: input.groupId,\n }),\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n assertProjectionVerificationCurrent(stillCurrent);\n const stored = await input.apiClient.deleteOrganizationGroup(\n input.organizationId,\n input.groupId,\n { organizationPolicy: organizationRequest },\n );\n assertProjectionVerificationCurrent(stillCurrent);\n if (!stored) {\n throw new Error(\"Group could not be deleted\");\n }\n if (\n stored.organizationId !== input.organizationId ||\n stored.groupId !== input.groupId\n ) {\n throw new Error(\"Group deletion response target mismatch\");\n }\n const organizationHead = await groupPolicyMutationHead(organizationRequest);\n const organizationPolicy = await acknowledgeGroupPolicyState({\n currentPolicy: externalAdminPolicy.bundle,\n expectedHead: organizationHead,\n request: organizationRequest,\n response: stored.organizationPolicy.currentState,\n });\n const organizationBundle = buildAcknowledgedGroupPolicyBundle({\n currentPolicy: externalAdminPolicy.bundle,\n expectedHead: organizationHead,\n request: organizationRequest,\n response: stored.organizationPolicy,\n });\n await persistLocallyAcknowledgedPrincipalPolicyBundles({\n entries: [{ bundle: organizationBundle, policy: organizationPolicy }],\n execSql: input.execSql,\n organizationId: input.organizationId,\n updatedAt: new Date().toISOString(),\n stillCurrent,\n });\n assertProjectionVerificationCurrent(stillCurrent);\n return stored;\n}\n"]}