@tearleads/client-sdk 0.1.60 → 0.1.62

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 (299) hide show
  1. package/Tearleads.d.ts +8 -48
  2. package/Tearleads.js +18 -25
  3. package/Tearleads.js.map +1 -1
  4. package/TearleadsOptions.d.ts +49 -0
  5. package/TearleadsOptions.js +2 -0
  6. package/TearleadsOptions.js.map +1 -0
  7. package/client/containerContents/documentDiscovery.js +5 -5
  8. package/client/containerContents/documentDiscovery.js.map +1 -1
  9. package/client/containerContents/index.d.ts +7 -7
  10. package/client/containerContents/index.js +7 -7
  11. package/client/containerContents/index.js.map +1 -1
  12. package/client/containerContents/types.d.ts +6 -6
  13. package/client/containerContents/types.js.map +1 -1
  14. package/client/deviceFirst/index.js +2 -2
  15. package/client/deviceFirst/index.js.map +1 -1
  16. package/client/root/index.d.ts +1 -1
  17. package/client/root/index.js.map +1 -1
  18. package/client/runtime/workflowRuntime.d.ts +1 -1
  19. package/client/runtime/workflowRuntime.js.map +1 -1
  20. package/index.d.ts +2 -1
  21. package/index.js +1 -1
  22. package/index.js.map +1 -1
  23. package/package.json +1 -1
  24. package/stores/container-contents/containerStatePersistence.js +1 -1
  25. package/stores/container-contents/documentRecovery.js +2 -2
  26. package/stores/container-contents/documentRecovery.js.map +1 -1
  27. package/stores/container-contents/documentWork.js.map +1 -1
  28. package/stores/container-contents/localRefresh.js +2 -2
  29. package/stores/container-contents/localRefresh.js.map +1 -1
  30. package/stores/container-contents/operations.js +2 -2
  31. package/stores/container-contents/operations.js.map +1 -1
  32. package/stores/container-contents/remoteContainerIngestion.js +1 -1
  33. package/stores/container-contents/remoteEventSync.js +1 -1
  34. package/stores/container-contents/remoteHydrationRequest.js +1 -1
  35. package/stores/container-contents/setContainerIconOperation.js +2 -2
  36. package/stores/container-contents/setContainerIconOperation.js.map +1 -1
  37. package/stores/container-contents/shareOperations.js +1 -1
  38. package/stores/container-contents/startupHydration.js +1 -1
  39. package/stores/container-contents/syncAgent.d.ts +2 -2
  40. package/stores/container-contents/syncAgentTypes.d.ts +1 -1
  41. package/stores/container-contents/syncLaneIteration.js +2 -2
  42. package/stores/container-contents/syncLaneIteration.js.map +1 -1
  43. package/stores/container-contents/systemContainerIcon.js +1 -1
  44. package/stores/container-contents/systemContainerIcon.js.map +1 -1
  45. package/workflows/container-contents/{documentAttributionRanges.d.ts → attribution/documentAttributionRanges.d.ts} +1 -1
  46. package/workflows/container-contents/{documentCharacterBlame.js → attribution/documentCharacterBlame.js} +3 -3
  47. package/workflows/container-contents/attribution/documentCharacterBlame.js.map +1 -0
  48. package/workflows/container-contents/{documentFieldBlame.js → attribution/documentFieldBlame.js} +4 -4
  49. package/workflows/container-contents/attribution/documentFieldBlame.js.map +1 -0
  50. package/workflows/container-contents/container-state/createIntentSync.js +1 -1
  51. package/workflows/container-contents/container-state/createIntentSync.js.map +1 -1
  52. package/workflows/container-contents/container-state/moveIntentSync.js +1 -1
  53. package/workflows/container-contents/container-state/moveIntentSync.js.map +1 -1
  54. package/workflows/container-contents/container-state/purgeTree.js +2 -2
  55. package/workflows/container-contents/container-state/purgeTree.js.map +1 -1
  56. package/workflows/container-contents/container-state/sharePersistence.js +2 -2
  57. package/workflows/container-contents/container-state/sharePersistence.js.map +1 -1
  58. package/workflows/container-contents/{containerDocumentListing.js → documentDiscovery/containerDocumentListing.js} +1 -1
  59. package/workflows/container-contents/{documentDiscoveryApply.js → documentDiscovery/documentDiscoveryApply.js} +3 -3
  60. package/workflows/container-contents/documentDiscovery/documentDiscoveryApply.js.map +1 -0
  61. package/workflows/container-contents/{documentDiscoveryCandidates.js.map → documentDiscovery/documentDiscoveryCandidates.js.map} +1 -1
  62. package/workflows/container-contents/{documentDiscoveryEvidence.js → documentDiscovery/documentDiscoveryEvidence.js} +1 -1
  63. package/workflows/container-contents/documentDiscovery/documentDiscoveryEvidence.js.map +1 -0
  64. package/workflows/container-contents/{documentDiscoveryInputs.js → documentDiscovery/documentDiscoveryInputs.js} +2 -2
  65. package/workflows/container-contents/documentDiscovery/documentDiscoveryInputs.js.map +1 -0
  66. package/workflows/container-contents/documentDiscovery/documentDiscoveryLanes.js.map +1 -0
  67. package/workflows/container-contents/{documentDiscoveryTypes.d.ts → documentDiscovery/documentDiscoveryTypes.d.ts} +4 -4
  68. package/workflows/container-contents/documentDiscovery/documentDiscoveryTypes.js.map +1 -0
  69. package/workflows/container-contents/{documentDiscovery.d.ts → documentDiscovery/index.d.ts} +1 -1
  70. package/workflows/container-contents/{documentDiscovery.js → documentDiscovery/index.js} +5 -5
  71. package/workflows/container-contents/documentDiscovery/index.js.map +1 -0
  72. package/workflows/container-contents/{availableDocumentLinkIntent.js → documentLinks/availableDocumentLinkIntent.js} +1 -1
  73. package/workflows/container-contents/documentLinks/availableDocumentLinkIntent.js.map +1 -0
  74. package/workflows/container-contents/{deferredDocumentLinks.js → documentLinks/deferredDocumentLinks.js} +1 -1
  75. package/workflows/container-contents/documentLinks/deferredDocumentLinks.js.map +1 -0
  76. package/workflows/container-contents/{documentLinkIntent.js → documentLinks/documentLinkIntent.js} +4 -4
  77. package/workflows/container-contents/documentLinks/documentLinkIntent.js.map +1 -0
  78. package/workflows/container-contents/documentLinks/documentLocalRelink.js.map +1 -0
  79. package/workflows/container-contents/{documentLinks.d.ts → documentLinks/index.d.ts} +5 -5
  80. package/workflows/container-contents/{documentLinks.js → documentLinks/index.js} +10 -10
  81. package/workflows/container-contents/documentLinks/index.js.map +1 -0
  82. package/workflows/container-contents/documentMove/documentMoveDeniedReplay.js.map +1 -0
  83. package/workflows/container-contents/{documentMoveFailure.js → documentMove/documentMoveFailure.js} +1 -1
  84. package/workflows/container-contents/documentMove/documentMoveFailure.js.map +1 -0
  85. package/workflows/container-contents/{documentMoveIntent.js → documentMove/documentMoveIntent.js} +7 -7
  86. package/workflows/container-contents/documentMove/documentMoveIntent.js.map +1 -0
  87. package/workflows/container-contents/{documentMoveIntentErrors.js → documentMove/documentMoveIntentErrors.js} +1 -1
  88. package/workflows/container-contents/documentMove/documentMoveIntentErrors.js.map +1 -0
  89. package/workflows/container-contents/{documentMoveIntentSettlement.js → documentMove/documentMoveIntentSettlement.js} +4 -4
  90. package/workflows/container-contents/documentMove/documentMoveIntentSettlement.js.map +1 -0
  91. package/workflows/container-contents/{documentMoveIntentSync.js → documentMove/documentMoveIntentSync.js} +7 -7
  92. package/workflows/container-contents/documentMove/documentMoveIntentSync.js.map +1 -0
  93. package/workflows/container-contents/{documentMoveVanishedRefresh.js → documentMove/documentMoveVanishedRefresh.js} +3 -3
  94. package/workflows/container-contents/documentMove/documentMoveVanishedRefresh.js.map +1 -0
  95. package/workflows/container-contents/{documentHydrationProbe.js → documentPriming/documentHydrationProbe.js} +4 -4
  96. package/workflows/container-contents/documentPriming/documentHydrationProbe.js.map +1 -0
  97. package/workflows/container-contents/documentPriming/documentRuntimeTargetSync.js.map +1 -0
  98. package/workflows/container-contents/{documentPriming.js → documentPriming/index.js} +5 -5
  99. package/workflows/container-contents/documentPriming/index.js.map +1 -0
  100. package/workflows/container-contents/{documentStructure.d.ts → documentQueries/documentStructure.d.ts} +1 -1
  101. package/workflows/container-contents/{documentStructure.js → documentQueries/documentStructure.js} +4 -4
  102. package/workflows/container-contents/documentQueries/documentStructure.js.map +1 -0
  103. package/workflows/container-contents/{documentStructureTypes.d.ts → documentQueries/documentStructureTypes.d.ts} +4 -4
  104. package/workflows/container-contents/documentQueries/documentStructureTypes.js.map +1 -0
  105. package/workflows/container-contents/{documentSubtreeQueries.js → documentQueries/documentSubtreeQueries.js} +5 -5
  106. package/workflows/container-contents/documentQueries/documentSubtreeQueries.js.map +1 -0
  107. package/workflows/container-contents/{documentQueries.d.ts → documentQueries/index.d.ts} +8 -8
  108. package/workflows/container-contents/{documentQueries.js → documentQueries/index.js} +13 -13
  109. package/workflows/container-contents/documentQueries/index.js.map +1 -0
  110. package/workflows/container-contents/{orphanedDocumentSql.js → documentQueries/orphanedDocumentSql.js} +1 -1
  111. package/workflows/container-contents/documentQueries/orphanedDocumentSql.js.map +1 -0
  112. package/workflows/container-contents/{pendingDownloads.d.ts → documentQueries/pendingDownloads.d.ts} +1 -1
  113. package/workflows/container-contents/{pendingDownloads.js → documentQueries/pendingDownloads.js} +3 -3
  114. package/workflows/container-contents/documentQueries/pendingDownloads.js.map +1 -0
  115. package/workflows/container-contents/documentQueries/sql.js +1 -1
  116. package/workflows/container-contents/documentQueries/sql.js.map +1 -1
  117. package/workflows/container-contents/index.d.ts +13 -13
  118. package/workflows/container-contents/index.js +11 -11
  119. package/workflows/container-contents/index.js.map +1 -1
  120. package/workflows/container-contents/{blobInfo.d.ts → info/blobInfo.d.ts} +1 -1
  121. package/workflows/container-contents/{blobInfo.js → info/blobInfo.js} +4 -4
  122. package/workflows/container-contents/info/blobInfo.js.map +1 -0
  123. package/workflows/container-contents/{blobInfoTypes.d.ts → info/blobInfoTypes.d.ts} +1 -1
  124. package/workflows/container-contents/info/blobInfoTypes.js.map +1 -0
  125. package/workflows/container-contents/{containerInfo.d.ts → info/containerInfo.d.ts} +4 -4
  126. package/workflows/container-contents/{containerInfo.js → info/containerInfo.js} +5 -5
  127. package/workflows/container-contents/info/containerInfo.js.map +1 -0
  128. package/workflows/container-contents/{documentInfo.d.ts → info/documentInfo.d.ts} +3 -3
  129. package/workflows/container-contents/{documentInfo.js → info/documentInfo.js} +11 -11
  130. package/workflows/container-contents/info/documentInfo.js.map +1 -0
  131. package/workflows/container-contents/{documentInfoTypes.d.ts → info/documentInfoTypes.d.ts} +3 -3
  132. package/workflows/container-contents/info/documentInfoTypes.js.map +1 -0
  133. package/workflows/container-contents/{metadata.d.ts → metadata/index.d.ts} +2 -2
  134. package/workflows/container-contents/{metadata.js → metadata/index.js} +5 -5
  135. package/workflows/container-contents/metadata/index.js.map +1 -0
  136. package/workflows/container-contents/{metadataEvents.d.ts → metadata/metadataEvents.d.ts} +1 -1
  137. package/workflows/container-contents/{metadataEvents.js → metadata/metadataEvents.js} +1 -1
  138. package/workflows/container-contents/metadata/metadataEvents.js.map +1 -0
  139. package/workflows/container-contents/{metadataIncomingUpdateIsolation.js → metadata/metadataIncomingUpdateIsolation.js} +5 -5
  140. package/workflows/container-contents/metadata/metadataIncomingUpdateIsolation.js.map +1 -0
  141. package/workflows/container-contents/{metadataMutationPreparation.d.ts → metadata/metadataMutationPreparation.d.ts} +7 -7
  142. package/workflows/container-contents/{metadataMutationPreparation.js → metadata/metadataMutationPreparation.js} +5 -5
  143. package/workflows/container-contents/metadata/metadataMutationPreparation.js.map +1 -0
  144. package/workflows/container-contents/{metadataPersistence.d.ts → metadata/metadataPersistence.d.ts} +2 -2
  145. package/workflows/container-contents/{metadataPersistence.js → metadata/metadataPersistence.js} +4 -4
  146. package/workflows/container-contents/metadata/metadataPersistence.js.map +1 -0
  147. package/workflows/container-contents/{metadataPullContinuationInvalidation.js → metadata/metadataPullContinuationInvalidation.js} +4 -4
  148. package/workflows/container-contents/metadata/metadataPullContinuationInvalidation.js.map +1 -0
  149. package/workflows/container-contents/{metadataReadState.d.ts → metadata/metadataReadState.d.ts} +1 -1
  150. package/workflows/container-contents/metadata/metadataReadState.js.map +1 -0
  151. package/workflows/container-contents/{metadataRecord.js → metadata/metadataRecord.js} +2 -2
  152. package/workflows/container-contents/metadata/metadataRecord.js.map +1 -0
  153. package/workflows/container-contents/{metadataRemoteSync.d.ts → metadata/metadataRemoteSync.d.ts} +5 -5
  154. package/workflows/container-contents/{metadataRemoteSync.js → metadata/metadataRemoteSync.js} +3 -3
  155. package/workflows/container-contents/metadata/metadataRemoteSync.js.map +1 -0
  156. package/workflows/container-contents/{metadataStateInstallation.d.ts → metadata/metadataStateInstallation.d.ts} +1 -1
  157. package/workflows/container-contents/metadata/metadataStateInstallation.js.map +1 -0
  158. package/workflows/container-contents/{metadataStateIsolation.js → metadata/metadataStateIsolation.js} +3 -3
  159. package/workflows/container-contents/metadata/metadataStateIsolation.js.map +1 -0
  160. package/workflows/container-contents/{metadataSyncErrors.js → metadata/metadataSyncErrors.js} +3 -3
  161. package/workflows/container-contents/metadata/metadataSyncErrors.js.map +1 -0
  162. package/workflows/container-contents/{metadataSyncSettlement.d.ts → metadata/metadataSyncSettlement.d.ts} +2 -2
  163. package/workflows/container-contents/{metadataSyncSettlement.js → metadata/metadataSyncSettlement.js} +3 -3
  164. package/workflows/container-contents/metadata/metadataSyncSettlement.js.map +1 -0
  165. package/workflows/container-contents/{metadataTypes.d.ts → metadata/metadataTypes.d.ts} +5 -5
  166. package/workflows/container-contents/metadata/metadataTypes.js.map +1 -0
  167. package/workflows/container-contents/pendingWrites/aggregation.js.map +1 -1
  168. package/workflows/container-contents/pendingWrites/deferredTails.js.map +1 -1
  169. package/workflows/container-contents/{pendingWrites.d.ts → pendingWrites/index.d.ts} +1 -1
  170. package/workflows/container-contents/{pendingWrites.js → pendingWrites/index.js} +12 -12
  171. package/workflows/container-contents/pendingWrites/index.js.map +1 -0
  172. package/workflows/container-contents/projectionGeneration.js.map +1 -1
  173. package/workflows/container-contents/projectionKeys.d.ts +1 -1
  174. package/workflows/container-contents/projectionKeys.js.map +1 -1
  175. package/workflows/container-contents/projectionView.js +1 -1
  176. package/workflows/container-contents/projectionView.js.map +1 -1
  177. package/workflows/container-contents/{folderRecovery.d.ts → recovery/folderRecovery.d.ts} +1 -1
  178. package/workflows/container-contents/{folderRecovery.js → recovery/folderRecovery.js} +4 -4
  179. package/workflows/container-contents/recovery/folderRecovery.js.map +1 -0
  180. package/workflows/container-contents/{staleRootRecovery.js → recovery/staleRootRecovery.js} +1 -1
  181. package/workflows/container-contents/recovery/staleRootRecovery.js.map +1 -0
  182. package/workflows/container-contents/remoteHydration/completeHydration.js +1 -1
  183. package/workflows/container-contents/remoteHydration/completeHydration.js.map +1 -1
  184. package/workflows/container-contents/remoteHydration/heldContainerRebind.js +1 -1
  185. package/workflows/container-contents/remoteHydration/heldContainerRebind.js.map +1 -1
  186. package/workflows/container-contents/{remoteHydration.d.ts → remoteHydration/index.d.ts} +2 -2
  187. package/workflows/container-contents/{remoteHydration.js → remoteHydration/index.js} +6 -6
  188. package/workflows/container-contents/remoteHydration/index.js.map +1 -0
  189. package/workflows/container-contents/{remoteContainerPageHydration.js → remoteHydration/remoteContainerPageHydration.js} +8 -8
  190. package/workflows/container-contents/remoteHydration/remoteContainerPageHydration.js.map +1 -0
  191. package/workflows/container-contents/{remoteContainerState.js → remoteHydration/remoteContainerState.js} +11 -11
  192. package/workflows/container-contents/remoteHydration/remoteContainerState.js.map +1 -0
  193. package/workflows/container-contents/remoteHydration/types.d.ts +1 -1
  194. package/workflows/container-contents/runtime.d.ts +1 -1
  195. package/workflows/container-contents/runtime.js.map +1 -1
  196. package/workflows/container-contents/{documentPurge.d.ts → tombstones/documentPurge.d.ts} +6 -6
  197. package/workflows/container-contents/{documentPurge.js → tombstones/documentPurge.js} +6 -6
  198. package/workflows/container-contents/tombstones/documentPurge.js.map +1 -0
  199. package/workflows/container-contents/{documentTombstoneEvidence.js → tombstones/documentTombstoneEvidence.js} +9 -9
  200. package/workflows/container-contents/tombstones/documentTombstoneEvidence.js.map +1 -0
  201. package/workflows/container-contents/{documentTombstoneGate.js → tombstones/documentTombstoneGate.js} +1 -1
  202. package/workflows/container-contents/tombstones/documentTombstoneGate.js.map +1 -0
  203. package/workflows/documents/projectionKeys.d.ts +1 -1
  204. package/workflows/documents/projectionKeys.js.map +1 -1
  205. package/workflows/documents/reportDocumentSyncQuarantine.js.map +1 -1
  206. package/workflows/documents/runtime.d.ts +1 -1
  207. package/workflows/documents/runtime.js.map +1 -1
  208. package/workflows/{runtimeInput.d.ts → shared/runtimeInput.d.ts} +6 -6
  209. package/workflows/shared/runtimeInput.js.map +1 -0
  210. package/workflows/container-contents/availableDocumentLinkIntent.js.map +0 -1
  211. package/workflows/container-contents/blobInfo.js.map +0 -1
  212. package/workflows/container-contents/blobInfoTypes.js.map +0 -1
  213. package/workflows/container-contents/containerInfo.js.map +0 -1
  214. package/workflows/container-contents/deferredDocumentLinks.js.map +0 -1
  215. package/workflows/container-contents/documentCharacterBlame.js.map +0 -1
  216. package/workflows/container-contents/documentDiscovery.js.map +0 -1
  217. package/workflows/container-contents/documentDiscoveryApply.js.map +0 -1
  218. package/workflows/container-contents/documentDiscoveryEvidence.js.map +0 -1
  219. package/workflows/container-contents/documentDiscoveryInputs.js.map +0 -1
  220. package/workflows/container-contents/documentDiscoveryLanes.js.map +0 -1
  221. package/workflows/container-contents/documentDiscoveryTypes.js.map +0 -1
  222. package/workflows/container-contents/documentFieldBlame.js.map +0 -1
  223. package/workflows/container-contents/documentHydrationProbe.js.map +0 -1
  224. package/workflows/container-contents/documentInfo.js.map +0 -1
  225. package/workflows/container-contents/documentInfoTypes.js.map +0 -1
  226. package/workflows/container-contents/documentLinkIntent.js.map +0 -1
  227. package/workflows/container-contents/documentLinks.js.map +0 -1
  228. package/workflows/container-contents/documentLocalRelink.js.map +0 -1
  229. package/workflows/container-contents/documentMoveDeniedReplay.js.map +0 -1
  230. package/workflows/container-contents/documentMoveFailure.js.map +0 -1
  231. package/workflows/container-contents/documentMoveIntent.js.map +0 -1
  232. package/workflows/container-contents/documentMoveIntentErrors.js.map +0 -1
  233. package/workflows/container-contents/documentMoveIntentSettlement.js.map +0 -1
  234. package/workflows/container-contents/documentMoveIntentSync.js.map +0 -1
  235. package/workflows/container-contents/documentMoveVanishedRefresh.js.map +0 -1
  236. package/workflows/container-contents/documentPriming.js.map +0 -1
  237. package/workflows/container-contents/documentPurge.js.map +0 -1
  238. package/workflows/container-contents/documentQueries.js.map +0 -1
  239. package/workflows/container-contents/documentRuntimeTargetSync.js.map +0 -1
  240. package/workflows/container-contents/documentStructure.js.map +0 -1
  241. package/workflows/container-contents/documentStructureTypes.js.map +0 -1
  242. package/workflows/container-contents/documentSubtreeQueries.js.map +0 -1
  243. package/workflows/container-contents/documentTombstoneEvidence.js.map +0 -1
  244. package/workflows/container-contents/documentTombstoneGate.js.map +0 -1
  245. package/workflows/container-contents/folderRecovery.js.map +0 -1
  246. package/workflows/container-contents/metadata.js.map +0 -1
  247. package/workflows/container-contents/metadataEvents.js.map +0 -1
  248. package/workflows/container-contents/metadataIncomingUpdateIsolation.js.map +0 -1
  249. package/workflows/container-contents/metadataMutationPreparation.js.map +0 -1
  250. package/workflows/container-contents/metadataPersistence.js.map +0 -1
  251. package/workflows/container-contents/metadataPullContinuationInvalidation.js.map +0 -1
  252. package/workflows/container-contents/metadataReadState.js.map +0 -1
  253. package/workflows/container-contents/metadataRecord.js.map +0 -1
  254. package/workflows/container-contents/metadataRemoteSync.js.map +0 -1
  255. package/workflows/container-contents/metadataStateInstallation.js.map +0 -1
  256. package/workflows/container-contents/metadataStateIsolation.js.map +0 -1
  257. package/workflows/container-contents/metadataSyncErrors.js.map +0 -1
  258. package/workflows/container-contents/metadataSyncSettlement.js.map +0 -1
  259. package/workflows/container-contents/metadataTypes.js.map +0 -1
  260. package/workflows/container-contents/orphanedDocumentSql.js.map +0 -1
  261. package/workflows/container-contents/pendingDownloads.js.map +0 -1
  262. package/workflows/container-contents/pendingWrites.js.map +0 -1
  263. package/workflows/container-contents/remoteContainerPageHydration.js.map +0 -1
  264. package/workflows/container-contents/remoteContainerState.js.map +0 -1
  265. package/workflows/container-contents/remoteHydration.js.map +0 -1
  266. package/workflows/container-contents/staleRootRecovery.js.map +0 -1
  267. package/workflows/runtimeInput.js.map +0 -1
  268. /package/workflows/container-contents/{documentAttributionRanges.js → attribution/documentAttributionRanges.js} +0 -0
  269. /package/workflows/container-contents/{documentAttributionRanges.js.map → attribution/documentAttributionRanges.js.map} +0 -0
  270. /package/workflows/container-contents/{containerDocumentListing.js.map → documentDiscovery/containerDocumentListing.js.map} +0 -0
  271. /package/workflows/container-contents/{documentDiscoveryCandidates.js → documentDiscovery/documentDiscoveryCandidates.js} +0 -0
  272. /package/workflows/container-contents/{documentDiscoveryLanes.js → documentDiscovery/documentDiscoveryLanes.js} +0 -0
  273. /package/workflows/container-contents/{documentDiscoveryTypes.js → documentDiscovery/documentDiscoveryTypes.js} +0 -0
  274. /package/workflows/container-contents/{documentHeadScope.js → documentDiscovery/documentHeadScope.js} +0 -0
  275. /package/workflows/container-contents/{documentHeadScope.js.map → documentDiscovery/documentHeadScope.js.map} +0 -0
  276. /package/workflows/container-contents/{documentLocalRelink.js → documentLinks/documentLocalRelink.js} +0 -0
  277. /package/workflows/container-contents/{documentMoveDeniedReplay.js → documentMove/documentMoveDeniedReplay.js} +0 -0
  278. /package/workflows/container-contents/{documentMoveUnlinkIds.js → documentMove/documentMoveUnlinkIds.js} +0 -0
  279. /package/workflows/container-contents/{documentMoveUnlinkIds.js.map → documentMove/documentMoveUnlinkIds.js.map} +0 -0
  280. /package/workflows/container-contents/{documentRuntimeTargetSync.js → documentPriming/documentRuntimeTargetSync.js} +0 -0
  281. /package/workflows/container-contents/{documentStructureTypes.js → documentQueries/documentStructureTypes.js} +0 -0
  282. /package/workflows/container-contents/{blobInfoRows.js → info/blobInfoRows.js} +0 -0
  283. /package/workflows/container-contents/{blobInfoRows.js.map → info/blobInfoRows.js.map} +0 -0
  284. /package/workflows/container-contents/{blobInfoTypes.js → info/blobInfoTypes.js} +0 -0
  285. /package/workflows/container-contents/{documentInfoTypes.js → info/documentInfoTypes.js} +0 -0
  286. /package/workflows/container-contents/{metadataReadState.js → metadata/metadataReadState.js} +0 -0
  287. /package/workflows/container-contents/{metadataStateInstallation.js → metadata/metadataStateInstallation.js} +0 -0
  288. /package/workflows/container-contents/{metadataSyncFollowup.js → metadata/metadataSyncFollowup.js} +0 -0
  289. /package/workflows/container-contents/{metadataSyncFollowup.js.map → metadata/metadataSyncFollowup.js.map} +0 -0
  290. /package/workflows/container-contents/{metadataSyncRegistrations.d.ts → metadata/metadataSyncRegistrations.d.ts} +0 -0
  291. /package/workflows/container-contents/{metadataSyncRegistrations.js → metadata/metadataSyncRegistrations.js} +0 -0
  292. /package/workflows/container-contents/{metadataSyncRegistrations.js.map → metadata/metadataSyncRegistrations.js.map} +0 -0
  293. /package/workflows/container-contents/{metadataTypes.js → metadata/metadataTypes.js} +0 -0
  294. /package/workflows/container-contents/{pendingWritesTypes.d.ts → pendingWrites/pendingWritesTypes.d.ts} +0 -0
  295. /package/workflows/container-contents/{pendingWritesTypes.js → pendingWrites/pendingWritesTypes.js} +0 -0
  296. /package/workflows/container-contents/{pendingWritesTypes.js.map → pendingWrites/pendingWritesTypes.js.map} +0 -0
  297. /package/workflows/container-contents/{remoteHydrationLog.js → remoteHydration/remoteHydrationLog.js} +0 -0
  298. /package/workflows/container-contents/{remoteHydrationLog.js.map → remoteHydration/remoteHydrationLog.js.map} +0 -0
  299. /package/workflows/{runtimeInput.js → shared/runtimeInput.js} +0 -0
package/Tearleads.d.ts CHANGED
@@ -1,64 +1,22 @@
1
1
  import { ApiRequestMetrics } from "./internal/api-client/index.js";
2
- import { type BlobStoreFactory, Blobs } from "./client/blobs/index.js";
2
+ import { Blobs } from "./client/blobs/index.js";
3
3
  import { type ContainerContents } from "./client/containerContents/index.js";
4
4
  import { type DeviceFirst } from "./client/deviceFirst/index.js";
5
5
  import { type Documents } from "./client/documents/index.js";
6
- import { type Logger } from "./client/host/logger.js";
7
- import { type Identity, type IdentityOptions } from "./client/identity/index.js";
6
+ import { type Identity } from "./client/identity/index.js";
8
7
  import { type UserIdentities } from "./client/identity/userIdentities.js";
9
8
  import { type Organizations } from "./client/organizations/index.js";
10
9
  import { type Root } from "./client/root/index.js";
11
10
  import { ApiVersion } from "./client/runtime/apiVersion.js";
12
- import { Database, type DatabaseOptions } from "./client/runtime/database.js";
11
+ import { Database } from "./client/runtime/database.js";
13
12
  import { Events } from "./client/runtime/events.js";
14
13
  import { Network } from "./client/runtime/network.js";
15
- import type { PrincipalHistoryKeyProvider } from "./client/runtime/principalHistoryProtection.js";
16
14
  import { SyncBillingGate } from "./client/runtime/syncBillingGate.js";
17
15
  import { type Runtime } from "./client/runtime/workflowRuntime.js";
18
- import { type SecurityIncidentListener, type SecurityIncidents } from "./client/securityIncidents/index.js";
16
+ import { type SecurityIncidents } from "./client/securityIncidents/index.js";
19
17
  import type { Session } from "./client/session/sessionTypes.js";
20
- import type { BlobStore } from "./data/blobs/blobContracts.js";
21
- import { type DocumentProjectorRegistryInput } from "./data/documents/documentKinds.js";
22
18
  import { type DomainScope } from "./data/shared/domainScope.js";
23
- import type { ProvisionedSystemContainerSpec } from "./workflows/registration/index.js";
24
- export type ClientDatabaseOptions = Omit<DatabaseOptions, "status">;
25
- export interface ClientOptions {
26
- apiBaseUrl?: string | undefined;
27
- /** Reuse a memory-only request counter across client lifetimes. */
28
- apiRequestMetrics?: ApiRequestMetrics | undefined;
29
- blobStore?: BlobStore | undefined;
30
- blobStoreFactory?: BlobStoreFactory | undefined;
31
- database?: ClientDatabaseOptions | undefined;
32
- documentProjectors?: DocumentProjectorRegistryInput | undefined;
33
- events?: ReadonlyArray<unknown> | undefined;
34
- identity?: IdentityOptions | undefined;
35
- /**
36
- * Absolute, host-controlled API namespace for durable user-identity pins.
37
- * Required only when apiBaseUrl is relative and no browser origin exists.
38
- */
39
- identityTrustDomain?: string | undefined;
40
- identityProvisioning?: "auto" | "manual" | undefined;
41
- logger?: Logger | undefined;
42
- online?: boolean | undefined;
43
- /** Called after a trust-boundary verification failure is durably recorded. */
44
- onSecurityIncident?: SecurityIncidentListener | undefined;
45
- /**
46
- * Per-pane discriminator so documents in distinct panes derive distinct Loro
47
- * peer ids (e.g. the pane's local identity namespace). Omit for single-pane.
48
- */
49
- peerScope?: string | undefined;
50
- /** Private host key for durable history progress; omitted uses disposable session keys. */
51
- principalHistoryKeyProvider?: PrincipalHistoryKeyProvider | undefined;
52
- /** Compound policy dispatch/recovery deadline in milliseconds; defaults to 60 seconds. */
53
- principalMutationTimeoutMs?: number | undefined;
54
- /**
55
- * App-owned system containers born with every new organization (both
56
- * registration and additional-org creation provision them atomically in the
57
- * same server call), e.g. a trash bin. The app owns these because their slot
58
- * namespaces are app concepts the SDK stays agnostic to.
59
- */
60
- provisionedSystemContainers?: ReadonlyArray<ProvisionedSystemContainerSpec> | undefined;
61
- }
19
+ import type { TearleadsOptions } from "./TearleadsOptions.js";
62
20
  export declare class Tearleads {
63
21
  readonly apiVersion: ApiVersion;
64
22
  readonly apiRequests: ApiRequestMetrics;
@@ -91,7 +49,9 @@ export declare class Tearleads {
91
49
  private pinLocalUserIdentity;
92
50
  private primeProvisionedPrincipalHistory;
93
51
  private boundUserId;
94
- constructor(options?: ClientOptions);
52
+ constructor(options?: TearleadsOptions);
53
+ /** Durable incident records in this database, reported to the host's listener. */
54
+ private createSecurityIncidents;
95
55
  /** Trust callbacks reach the workflow runtime, which is created later. */
96
56
  private createClientSession;
97
57
  private createApiClient;
package/Tearleads.js CHANGED
@@ -4,7 +4,7 @@ import { createContainerContents, } from "./client/containerContents/index.js";
4
4
  import { createDeviceFirst } from "./client/deviceFirst/index.js";
5
5
  import { createDocuments } from "./client/documents/index.js";
6
6
  import { logErrorToConsole } from "./client/host/logger.js";
7
- import { createIdentity, } from "./client/identity/index.js";
7
+ import { createIdentity } from "./client/identity/index.js";
8
8
  import { createUserIdentities, } from "./client/identity/userIdentities.js";
9
9
  import { createOrganizations, } from "./client/organizations/index.js";
10
10
  import { createRoot, rootRuntimeOf } from "./client/root/index.js";
@@ -21,21 +21,6 @@ import { createVerifiedManifestCitations } from "./data/persistence/verifiedMani
21
21
  import { createDomainScope } from "./data/shared/domainScope.js";
22
22
  import { disposeDomainSyncCoordinator } from "./data/sync/syncCoordinator.js";
23
23
  import { resolveIdentityTrustDomain } from "./data/trustedUserIdentity/index.js";
24
- function createClientSecurityIncidentService(input) {
25
- const identityTrustDomain = resolveIdentityTrustDomain({
26
- apiBaseUrl: input.apiBaseUrl,
27
- identityTrustDomain: input.options.identityTrustDomain,
28
- });
29
- return {
30
- identityTrustDomain,
31
- service: createSecurityIncidentService({
32
- database: input.database,
33
- logError: input.logError,
34
- onIncident: input.options.onSecurityIncident,
35
- trustDomain: identityTrustDomain,
36
- }),
37
- };
38
- }
39
24
  export class Tearleads {
40
25
  apiVersion = new ApiVersion();
41
26
  apiRequests;
@@ -85,14 +70,13 @@ export class Tearleads {
85
70
  this.events = new Events(options.events, () => this.apiClient.clearWriterProjectionCaches());
86
71
  this.logHandler = options.logger?.log ?? (() => undefined);
87
72
  this.logErrorHandler = options.logger?.logError ?? logErrorToConsole;
88
- const security = createClientSecurityIncidentService({
73
+ const identityTrustDomain = resolveIdentityTrustDomain({
89
74
  apiBaseUrl,
90
- database: this.database,
91
- logError: this.logError,
92
- options,
75
+ identityTrustDomain: options.identityTrustDomain,
93
76
  });
94
- this.securityIncidents = security.service.incidents;
95
- this.disposeSecurityIncidents = security.service.dispose;
77
+ const security = this.createSecurityIncidents(identityTrustDomain, options);
78
+ this.securityIncidents = security.incidents;
79
+ this.disposeSecurityIncidents = security.dispose;
96
80
  this.network = new Network(options.online);
97
81
  this.syncBillingGate = new SyncBillingGate();
98
82
  let session = null;
@@ -108,9 +92,9 @@ export class Tearleads {
108
92
  },
109
93
  getUserId: () => session?.userId ?? null,
110
94
  });
111
- session = this.createClientSession(options, security.service.report);
95
+ session = this.createClientSession(options, security.report);
112
96
  this.session = session;
113
- const runtime = this.createWorkflowRuntime(security.identityTrustDomain, options, security.service.report);
97
+ const runtime = this.createWorkflowRuntime(identityTrustDomain, options, security.report);
114
98
  this.bindTrustedIdentityRuntime(runtime);
115
99
  this.runtime = runtime.publicRuntime;
116
100
  this.documents = createDocuments({
@@ -123,7 +107,7 @@ export class Tearleads {
123
107
  this.root = createRoot(rootRuntimeOf(runtime, this.session));
124
108
  this.userIdentities = createUserIdentities({
125
109
  getOrganizationId: () => this.session.organizationId,
126
- reportSecurityIncident: security.service.report,
110
+ reportSecurityIncident: security.report,
127
111
  identityLinks: runtime.identityLinks,
128
112
  log: this.log,
129
113
  resolveTrustedUserIdentity: (userId) => runtime.workflowInput().resolveTrustedUserIdentity(userId),
@@ -133,6 +117,15 @@ export class Tearleads {
133
117
  this.startAutomaticIdentityProvisioning();
134
118
  }
135
119
  }
120
+ /** Durable incident records in this database, reported to the host's listener. */
121
+ createSecurityIncidents(trustDomain, options) {
122
+ return createSecurityIncidentService({
123
+ database: this.database,
124
+ logError: this.logError,
125
+ onIncident: options.onSecurityIncident,
126
+ trustDomain,
127
+ });
128
+ }
136
129
  /** Trust callbacks reach the workflow runtime, which is created later. */
137
130
  createClientSession(options, reportSecurityIncident) {
138
131
  return createSession({
package/Tearleads.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Tearleads.js","sourceRoot":"","sources":["Tearleads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAyB,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAEL,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAoB,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAkB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAe,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EACL,cAAc,GAGf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,GAErB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mBAAmB,GAEpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAa,aAAa,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAwB,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EACL,aAAa,GAGd,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,6BAA6B,GAG9B,MAAM,4BAA4B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AI,CAAC;QACrB,CAAC,CAAC;QACF,MAAM,sBAAsB,GAAG,GAAG,EAAE;YAClC,IAAI,IAAI,CAAC,uBAAuB,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;gBACjE,wBAAwB,EAAE,CAAC;gBAC3B,OAAO;YACT,CAAC;YAED,IACE,IAAI,CAAC,+BAA+B;gBACpC,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,OAAO,EAChC,CAAC;gBACD,OAAO;YACT,CAAC;YAED,IAAI,CAAC,+BAA+B,GAAG,IAAI,CAAC,QAAQ;iBACjD,QAAQ,EAAE;iBACV,IAAI,CAAC,GAAG,EAAE;gBACT,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC;gBACpC,wBAAwB,EAAE,CAAC;YAC7B,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBACxB,IAAI,CAAC;oBACH,IAAI,CAAC,QAAQ,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;gBACjE,CAAC;gBAAC,MAAM,CAAC;oBACP,gFAAgF;gBAClF,CAAC;YACH,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE;gBACZ,IAAI,CAAC,+BAA+B,GAAG,IAAI,CAAC;YAC9C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QAEF,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;QAC9D,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { ApiClient, ApiRequestMetrics } from \"@tearleads/api-client\";\nimport { type BlobStoreFactory, Blobs } from \"./client/blobs\";\nimport {\n type ContainerContents,\n createContainerContents,\n} from \"./client/containerContents\";\nimport { createDeviceFirst, type DeviceFirst } from \"./client/deviceFirst\";\nimport { createDocuments, type Documents } from \"./client/documents\";\nimport { type Logger, logErrorToConsole } from \"./client/host/logger\";\nimport {\n createIdentity,\n type Identity,\n type IdentityOptions,\n} from \"./client/identity\";\nimport {\n createUserIdentities,\n type UserIdentities,\n} from \"./client/identity/userIdentities\";\nimport {\n createOrganizations,\n type Organizations,\n} from \"./client/organizations\";\nimport { createRoot, type Root, rootRuntimeOf } from \"./client/root\";\nimport { ApiVersion } from \"./client/runtime/apiVersion\";\nimport { Database, type DatabaseOptions } from \"./client/runtime/database\";\nimport { Events } from \"./client/runtime/events\";\nimport { Network } from \"./client/runtime/network\";\nimport type { PrincipalHistoryKeyProvider } from \"./client/runtime/principalHistoryProtection\";\nimport { SyncBillingGate } from \"./client/runtime/syncBillingGate\";\nimport {\n createRuntime,\n type InternalRuntime,\n type Runtime,\n} from \"./client/runtime/workflowRuntime\";\nimport {\n createSecurityIncidentService,\n type SecurityIncidentListener,\n type SecurityIncidents,\n} from \"./client/securityIncidents\";\nimport { createSession } from \"./client/session\";\nimport type { Session } from \"./client/session/sessionTypes\";\nimport type { BlobStore } from \"./data/blobs/blobContracts\";\nimport {\n type DocumentProjectorRegistry,\n type DocumentProjectorRegistryInput,\n resolveDocumentProjectorRegistry,\n} from \"./data/documents/documentKinds\";\nimport { createVerifiedManifestCitations } from \"./data/persistence/verifiedManifestBundlePersistence\";\nimport { createDomainScope, type DomainScope } from \"./data/shared/domainScope\";\nimport type { SecurityIncidentReporter } from \"./data/shared/securityIncidents\";\nimport { disposeDomainSyncCoordinator } from \"./data/sync/syncCoordinator\";\nimport { resolveIdentityTrustDomain } from \"./data/trustedUserIdentity\";\nimport type { ProvisionedSystemContainerSpec } from \"./workflows/registration\";\n\nfunction createClientSecurityIncidentService(input: {\n readonly apiBaseUrl: string;\n readonly database: Database;\n readonly logError: (message: string | Error, cause?: unknown) => void;\n readonly options: ClientOptions;\n}) {\n const identityTrustDomain = resolveIdentityTrustDomain({\n apiBaseUrl: input.apiBaseUrl,\n identityTrustDomain: input.options.identityTrustDomain,\n });\n return {\n identityTrustDomain,\n service: createSecurityIncidentService({\n database: input.database,\n logError: input.logError,\n onIncident: input.options.onSecurityIncident,\n trustDomain: identityTrustDomain,\n }),\n };\n}\n\nexport type ClientDatabaseOptions = Omit<DatabaseOptions, \"status\">;\n\nexport interface ClientOptions {\n apiBaseUrl?: string | undefined;\n /** Reuse a memory-only request counter across client lifetimes. */\n apiRequestMetrics?: ApiRequestMetrics | undefined;\n blobStore?: BlobStore | undefined;\n blobStoreFactory?: BlobStoreFactory | undefined;\n database?: ClientDatabaseOptions | undefined;\n documentProjectors?: DocumentProjectorRegistryInput | undefined;\n events?: ReadonlyArray<unknown> | undefined;\n identity?: IdentityOptions | undefined;\n /**\n * Absolute, host-controlled API namespace for durable user-identity pins.\n * Required only when apiBaseUrl is relative and no browser origin exists.\n */\n identityTrustDomain?: string | undefined;\n identityProvisioning?: \"auto\" | \"manual\" | undefined;\n logger?: Logger | undefined;\n online?: boolean | undefined;\n /** Called after a trust-boundary verification failure is durably recorded. */\n onSecurityIncident?: SecurityIncidentListener | undefined;\n /**\n * Per-pane discriminator so documents in distinct panes derive distinct Loro\n * peer ids (e.g. the pane's local identity namespace). Omit for single-pane.\n */\n peerScope?: string | undefined;\n /** Private host key for durable history progress; omitted uses disposable session keys. */\n principalHistoryKeyProvider?: PrincipalHistoryKeyProvider | undefined;\n /** Compound policy dispatch/recovery deadline in milliseconds; defaults to 60 seconds. */\n principalMutationTimeoutMs?: number | undefined;\n /**\n * App-owned system containers born with every new organization (both\n * registration and additional-org creation provision them atomically in the\n * same server call), e.g. a trash bin. The app owns these because their slot\n * namespaces are app concepts the SDK stays agnostic to.\n */\n provisionedSystemContainers?:\n | ReadonlyArray<ProvisionedSystemContainerSpec>\n | undefined;\n}\n\nexport class Tearleads {\n readonly apiVersion = new ApiVersion();\n readonly apiRequests: ApiRequestMetrics;\n readonly blobs: Blobs;\n readonly database: Database;\n readonly deviceFirst: DeviceFirst;\n readonly documents: Documents;\n readonly events: Events;\n readonly containerContents: ContainerContents;\n readonly identity: Identity;\n readonly network: Network;\n readonly organizations: Organizations;\n readonly root: Root;\n readonly runtime: Runtime;\n readonly securityIncidents: SecurityIncidents;\n readonly session: Session;\n readonly syncBillingGate: SyncBillingGate;\n readonly userIdentities: UserIdentities;\n\n private readonly apiClient: ApiClient;\n private readonly documentProjectors: DocumentProjectorRegistry;\n private readonly disposeSecurityIncidents: () => void;\n private retirePrincipalHistoryProtection = () => {};\n // Tracks the storage/identity pair that owns domain-scoped runtime state.\n private domainScopeKey: string | null = null;\n // Recreated when the storage database or signing identity changes.\n private domainScopeValue: DomainScope = createDomainScope();\n private readonly logErrorHandler: (\n message: string | Error,\n cause?: unknown,\n ) => void;\n private readonly logHandler: (message: string) => void;\n private autoIdentityProvisioned = false;\n private autoIdentityProvisioningPromise: Promise<void> | null = null;\n private expiredSessionLoginPromise: Promise<boolean> | null = null;\n // Rebound to the workflow runtime once it exists; the session is created first.\n private pinLocalUserIdentity: InternalRuntime[\"pinLocalUserIdentity\"] =\n async () => {\n throw new Error(\"Trusted user identity runtime is not initialized\");\n };\n private primeProvisionedPrincipalHistory: InternalRuntime[\"primeProvisionedPrincipalHistory\"] =\n async () => undefined;\n private boundUserId: InternalRuntime[\"boundUserId\"] = async () => {\n throw new Error(\"Trusted user identity runtime is not initialized\");\n };\n\n constructor(options: ClientOptions = {}) {\n const apiBaseUrl = options.apiBaseUrl ?? \"\";\n this.apiRequests = options.apiRequestMetrics ?? new ApiRequestMetrics();\n this.apiClient = this.createApiClient(apiBaseUrl);\n this.blobs = new Blobs(options.blobStore, options.blobStoreFactory);\n this.database = new Database(options.database);\n this.documentProjectors = resolveDocumentProjectorRegistry(\n options.documentProjectors,\n );\n this.events = new Events(options.events, () =>\n this.apiClient.clearWriterProjectionCaches(),\n );\n this.logHandler = options.logger?.log ?? (() => undefined);\n this.logErrorHandler = options.logger?.logError ?? logErrorToConsole;\n const security = createClientSecurityIncidentService({\n apiBaseUrl,\n database: this.database,\n logError: this.logError,\n options,\n });\n this.securityIncidents = security.service.incidents;\n this.disposeSecurityIncidents = security.service.dispose;\n this.network = new Network(options.online);\n this.syncBillingGate = new SyncBillingGate();\n let session: Session | null = null;\n this.identity = createIdentity(\n options.identity,\n (signingFingerprint) =>\n this.blobs.updateIdentityNamespace(signingFingerprint),\n this.log,\n {\n bootstrapLocalRootContainer: async () => {\n if (this.database.status !== \"ready\") {\n throw new Error(\n \"identity.generate requires a ready SQLite database.\",\n );\n }\n if (!session) {\n throw new Error(\n \"identity.generate requires an initialized session.\",\n );\n }\n\n return session.bootstrapLocalRootContainer();\n },\n getUserId: () => session?.userId ?? null,\n },\n );\n session = this.createClientSession(options, security.service.report);\n this.session = session;\n const runtime = this.createWorkflowRuntime(\n security.identityTrustDomain,\n options,\n security.service.report,\n );\n this.bindTrustedIdentityRuntime(runtime);\n this.runtime = runtime.publicRuntime;\n this.documents = createDocuments({\n getDefaultContainerId: () => this.session.containerId,\n runtime,\n });\n this.containerContents = createContainerContents(runtime);\n this.deviceFirst = createDeviceFirst(runtime, this.containerContents);\n this.organizations = createOrganizations(runtime, this.containerContents);\n this.root = createRoot(rootRuntimeOf(runtime, this.session));\n this.userIdentities = createUserIdentities({\n getOrganizationId: () => this.session.organizationId,\n reportSecurityIncident: security.service.report,\n identityLinks: runtime.identityLinks,\n log: this.log,\n resolveTrustedUserIdentity: (userId) =>\n runtime.workflowInput().resolveTrustedUserIdentity(userId),\n });\n\n this.configureApiClientCallbacks();\n\n if (options.identityProvisioning === \"auto\") {\n this.startAutomaticIdentityProvisioning();\n }\n }\n\n /** Trust callbacks reach the workflow runtime, which is created later. */\n private createClientSession(\n options: ClientOptions,\n reportSecurityIncident: SecurityIncidentReporter,\n ): Session {\n return createSession({\n api: this.apiClient,\n database: this.database,\n documentProjectors: this.documentProjectors,\n identity: this.identity,\n log: this.log,\n logError: this.logError,\n boundUserIdForSigningKey: (signingKeyFingerprint) =>\n this.boundUserId(signingKeyFingerprint),\n onUserIdentityAvailable: (userId, candidate) =>\n this.pinLocalUserIdentity(userId, candidate),\n primeProvisionedPrincipalHistory: (input) =>\n this.primeProvisionedPrincipalHistory(input),\n provisionedSystemContainers: options.provisionedSystemContainers,\n reportSecurityIncident,\n });\n }\n\n private createApiClient(apiBaseUrl: string): ApiClient {\n return new ApiClient(apiBaseUrl, {\n metrics: this.apiRequests,\n getIdentity: () => this.identity.signingFingerprint,\n });\n }\n\n /** Rebinds the session's trust callbacks once the runtime exists. */\n private bindTrustedIdentityRuntime(runtime: InternalRuntime): void {\n this.retirePrincipalHistoryProtection =\n runtime.retirePrincipalHistoryProtection;\n this.pinLocalUserIdentity = (userId, candidate) =>\n runtime.pinLocalUserIdentity(userId, candidate);\n this.primeProvisionedPrincipalHistory =\n runtime.primeProvisionedPrincipalHistory;\n this.boundUserId = (signingKeyFingerprint) =>\n runtime.boundUserId(signingKeyFingerprint);\n }\n\n private configureApiClientCallbacks(): void {\n // Projection reads cite bundles this identity's database already verified.\n this.apiClient.setVerifiedManifestCitations(\n createVerifiedManifestCitations(() => this.database.execSql),\n );\n this.apiClient.setOnError((message) => this.logError(message));\n // An authoritative host source owns connectivity. Without one, request\n // outcomes remain reachability hints. Browser and native app bindings both\n // install authoritative sources so a backend outage cannot stop retries.\n this.apiClient.setOnNetworkError(() =>\n this.network.reportReachability(false),\n );\n this.apiClient.setOnNetworkSuccess(() =>\n this.network.reportReachability(true),\n );\n this.apiClient.setOnApiVersion((version) =>\n this.apiVersion.observe(version),\n );\n this.apiClient.setOnSessionExpired(() => this.loginAfterSessionExpired());\n this.apiClient.setOnPaymentRequired((organizationId) =>\n this.syncBillingGate.notifyPaymentRequired(organizationId),\n );\n }\n\n private createWorkflowRuntime(\n identityTrustDomain: string | null,\n options: ClientOptions,\n reportSecurityIncident: SecurityIncidentReporter,\n ): InternalRuntime {\n return createRuntime({\n api: this.apiClient,\n blobs: this.blobs,\n database: this.database,\n documentProjectors: this.documentProjectors,\n events: this.events,\n getDomainScope: () => this.domainScope,\n identity: this.identity,\n identityTrustDomain,\n log: this.log,\n logError: this.logError,\n network: this.network,\n peerScope: options.peerScope ?? null,\n principalHistoryKeyProvider: options.principalHistoryKeyProvider,\n principalMutationTimeoutMs: options.principalMutationTimeoutMs,\n reportSecurityIncident,\n session: this.session,\n syncBillingGate: this.syncBillingGate,\n });\n }\n\n log = (message: string): void => {\n this.logHandler(message);\n };\n\n // Preserve the host's return value so best-effort callers can also catch\n // rejected promises from async loggers accepted by the void callback type.\n logError = (message: string | Error, cause?: unknown): void =>\n this.logErrorHandler(message, cause);\n\n /**\n * A single-use ticket to authenticate the server-events websocket handshake\n * (which cannot carry the bearer header): the one login returned for the\n * first connect of that session, otherwise a freshly minted one. Returns\n * null when no session is active. The caller appends it to the websocket URL.\n */\n requestWebSocketTicket(): Promise<string | null> {\n return this.apiClient.requestWebSocketTicket();\n }\n\n get domainScope(): DomainScope {\n const nextScopeKey = JSON.stringify([\n this.database.id,\n this.identity.signingFingerprint,\n ]);\n if (this.domainScopeKey !== nextScopeKey) {\n this.domainScopeKey = nextScopeKey;\n this.domainScopeValue = createDomainScope();\n }\n\n return this.domainScopeValue;\n }\n\n /**\n * Tear down background work for the active domain scope: stop the reconciler\n * and force-stop the sync coordinator pump, then drop the coordinator from\n * its registry. Hosts call this from unmount/cleanup so a pump cannot outlive\n * the React tree that created it. A later access for the same scope rebuilds\n * fresh state.\n */\n dispose(): void {\n const domainScope = this.domainScope;\n this.disposeSecurityIncidents();\n this.retirePrincipalHistoryProtection();\n this.deviceFirst.dispose();\n disposeDomainSyncCoordinator(domainScope);\n }\n\n private loginAfterSessionExpired(): Promise<boolean> {\n if (!this.session.authToken || !this.identity.signingKeyPair) {\n this.session.logout();\n return Promise.resolve(false);\n }\n\n // The API client replays requests the expired session sent, so a login is\n // their renewal only when the loaded keys authenticate that known user.\n const expiredUserId = this.session.userId;\n this.expiredSessionLoginPromise ??= this.session\n .login()\n .then(\n (renewed) =>\n renewed &&\n expiredUserId !== null &&\n this.session.userId === expiredUserId,\n )\n .finally(() => {\n this.expiredSessionLoginPromise = null;\n });\n return this.expiredSessionLoginPromise;\n }\n\n private startAutomaticIdentityProvisioning(): void {\n let unsubscribe: (() => void) | null = null;\n const stopProvisioningListener = () => {\n unsubscribe?.();\n unsubscribe = null;\n };\n const maybeProvisionIdentity = () => {\n if (this.autoIdentityProvisioned || this.identity.signingKeyPair) {\n stopProvisioningListener();\n return;\n }\n\n if (\n this.autoIdentityProvisioningPromise ||\n this.database.status !== \"ready\"\n ) {\n return;\n }\n\n this.autoIdentityProvisioningPromise = this.identity\n .generate()\n .then(() => {\n this.autoIdentityProvisioned = true;\n stopProvisioningListener();\n })\n .catch((error: unknown) => {\n try {\n this.logError(\"Automatic identity provisioning failed\", error);\n } catch {\n // Keep background provisioning failures from surfacing as unhandled rejections.\n }\n })\n .finally(() => {\n this.autoIdentityProvisioningPromise = null;\n });\n };\n\n unsubscribe = this.database.subscribe(maybeProvisionIdentity);\n void Promise.resolve().then(maybeProvisionIdentity);\n }\n}\n"]}
1
+ {"version":3,"file":"Tearleads.js","sourceRoot":"","sources":["Tearleads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAEL,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAoB,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAkB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAiB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACL,oBAAoB,GAErB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mBAAmB,GAEpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAa,aAAa,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,UAAU,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B,IAAI,CAAC;QAC5C,MAAM,wBAAwB,GAAG,GAAG,EAAE;YACpC,WAAW,EAAE,EAAE,CAAC;YAChB,WAAW,GAAG,IAAI,CAAC;QACrB,CAAC,CAAC;QACF,MAAM,sBAAsB,GAAG,GAAG,EAAE;YAClC,IAAI,IAAI,CAAC,uBAAuB,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;gBACjE,wBAAwB,EAAE,CAAC;gBAC3B,OAAO;YACT,CAAC;YAED,IACE,IAAI,CAAC,+BAA+B;gBACpC,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,OAAO,EAChC,CAAC;gBACD,OAAO;YACT,CAAC;YAED,IAAI,CAAC,+BAA+B,GAAG,IAAI,CAAC,QAAQ;iBACjD,QAAQ,EAAE;iBACV,IAAI,CAAC,GAAG,EAAE;gBACT,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC;gBACpC,wBAAwB,EAAE,CAAC;YAC7B,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBACxB,IAAI,CAAC;oBACH,IAAI,CAAC,QAAQ,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;gBACjE,CAAC;gBAAC,MAAM,CAAC;oBACP,gFAAgF;gBAClF,CAAC;YACH,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE;gBACZ,IAAI,CAAC,+BAA+B,GAAG,IAAI,CAAC;YAC9C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QAEF,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;QAC9D,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { ApiClient, ApiRequestMetrics } from \"@tearleads/api-client\";\nimport { Blobs } from \"./client/blobs\";\nimport {\n type ContainerContents,\n createContainerContents,\n} from \"./client/containerContents\";\nimport { createDeviceFirst, type DeviceFirst } from \"./client/deviceFirst\";\nimport { createDocuments, type Documents } from \"./client/documents\";\nimport { logErrorToConsole } from \"./client/host/logger\";\nimport { createIdentity, type Identity } from \"./client/identity\";\nimport {\n createUserIdentities,\n type UserIdentities,\n} from \"./client/identity/userIdentities\";\nimport {\n createOrganizations,\n type Organizations,\n} from \"./client/organizations\";\nimport { createRoot, type Root, rootRuntimeOf } from \"./client/root\";\nimport { ApiVersion } from \"./client/runtime/apiVersion\";\nimport { Database } from \"./client/runtime/database\";\nimport { Events } from \"./client/runtime/events\";\nimport { Network } from \"./client/runtime/network\";\nimport { SyncBillingGate } from \"./client/runtime/syncBillingGate\";\nimport {\n createRuntime,\n type InternalRuntime,\n type Runtime,\n} from \"./client/runtime/workflowRuntime\";\nimport {\n createSecurityIncidentService,\n type SecurityIncidents,\n} from \"./client/securityIncidents\";\nimport { createSession } from \"./client/session\";\nimport type { Session } from \"./client/session/sessionTypes\";\nimport {\n type DocumentProjectorRegistry,\n resolveDocumentProjectorRegistry,\n} from \"./data/documents/documentKinds\";\nimport { createVerifiedManifestCitations } from \"./data/persistence/verifiedManifestBundlePersistence\";\nimport { createDomainScope, type DomainScope } from \"./data/shared/domainScope\";\nimport type { SecurityIncidentReporter } from \"./data/shared/securityIncidents\";\nimport { disposeDomainSyncCoordinator } from \"./data/sync/syncCoordinator\";\nimport { resolveIdentityTrustDomain } from \"./data/trustedUserIdentity\";\nimport type { TearleadsOptions } from \"./TearleadsOptions\";\n\nexport class Tearleads {\n readonly apiVersion = new ApiVersion();\n readonly apiRequests: ApiRequestMetrics;\n readonly blobs: Blobs;\n readonly database: Database;\n readonly deviceFirst: DeviceFirst;\n readonly documents: Documents;\n readonly events: Events;\n readonly containerContents: ContainerContents;\n readonly identity: Identity;\n readonly network: Network;\n readonly organizations: Organizations;\n readonly root: Root;\n readonly runtime: Runtime;\n readonly securityIncidents: SecurityIncidents;\n readonly session: Session;\n readonly syncBillingGate: SyncBillingGate;\n readonly userIdentities: UserIdentities;\n\n private readonly apiClient: ApiClient;\n private readonly documentProjectors: DocumentProjectorRegistry;\n private readonly disposeSecurityIncidents: () => void;\n private retirePrincipalHistoryProtection = () => {};\n // Tracks the storage/identity pair that owns domain-scoped runtime state.\n private domainScopeKey: string | null = null;\n // Recreated when the storage database or signing identity changes.\n private domainScopeValue: DomainScope = createDomainScope();\n private readonly logErrorHandler: (\n message: string | Error,\n cause?: unknown,\n ) => void;\n private readonly logHandler: (message: string) => void;\n private autoIdentityProvisioned = false;\n private autoIdentityProvisioningPromise: Promise<void> | null = null;\n private expiredSessionLoginPromise: Promise<boolean> | null = null;\n // Rebound to the workflow runtime once it exists; the session is created first.\n private pinLocalUserIdentity: InternalRuntime[\"pinLocalUserIdentity\"] =\n async () => {\n throw new Error(\"Trusted user identity runtime is not initialized\");\n };\n private primeProvisionedPrincipalHistory: InternalRuntime[\"primeProvisionedPrincipalHistory\"] =\n async () => undefined;\n private boundUserId: InternalRuntime[\"boundUserId\"] = async () => {\n throw new Error(\"Trusted user identity runtime is not initialized\");\n };\n\n constructor(options: TearleadsOptions = {}) {\n const apiBaseUrl = options.apiBaseUrl ?? \"\";\n this.apiRequests = options.apiRequestMetrics ?? new ApiRequestMetrics();\n this.apiClient = this.createApiClient(apiBaseUrl);\n this.blobs = new Blobs(options.blobStore, options.blobStoreFactory);\n this.database = new Database(options.database);\n this.documentProjectors = resolveDocumentProjectorRegistry(\n options.documentProjectors,\n );\n this.events = new Events(options.events, () =>\n this.apiClient.clearWriterProjectionCaches(),\n );\n this.logHandler = options.logger?.log ?? (() => undefined);\n this.logErrorHandler = options.logger?.logError ?? logErrorToConsole;\n const identityTrustDomain = resolveIdentityTrustDomain({\n apiBaseUrl,\n identityTrustDomain: options.identityTrustDomain,\n });\n const security = this.createSecurityIncidents(identityTrustDomain, options);\n this.securityIncidents = security.incidents;\n this.disposeSecurityIncidents = security.dispose;\n this.network = new Network(options.online);\n this.syncBillingGate = new SyncBillingGate();\n let session: Session | null = null;\n this.identity = createIdentity(\n options.identity,\n (signingFingerprint) =>\n this.blobs.updateIdentityNamespace(signingFingerprint),\n this.log,\n {\n bootstrapLocalRootContainer: async () => {\n if (this.database.status !== \"ready\") {\n throw new Error(\n \"identity.generate requires a ready SQLite database.\",\n );\n }\n if (!session) {\n throw new Error(\n \"identity.generate requires an initialized session.\",\n );\n }\n\n return session.bootstrapLocalRootContainer();\n },\n getUserId: () => session?.userId ?? null,\n },\n );\n session = this.createClientSession(options, security.report);\n this.session = session;\n const runtime = this.createWorkflowRuntime(\n identityTrustDomain,\n options,\n security.report,\n );\n this.bindTrustedIdentityRuntime(runtime);\n this.runtime = runtime.publicRuntime;\n this.documents = createDocuments({\n getDefaultContainerId: () => this.session.containerId,\n runtime,\n });\n this.containerContents = createContainerContents(runtime);\n this.deviceFirst = createDeviceFirst(runtime, this.containerContents);\n this.organizations = createOrganizations(runtime, this.containerContents);\n this.root = createRoot(rootRuntimeOf(runtime, this.session));\n this.userIdentities = createUserIdentities({\n getOrganizationId: () => this.session.organizationId,\n reportSecurityIncident: security.report,\n identityLinks: runtime.identityLinks,\n log: this.log,\n resolveTrustedUserIdentity: (userId) =>\n runtime.workflowInput().resolveTrustedUserIdentity(userId),\n });\n\n this.configureApiClientCallbacks();\n\n if (options.identityProvisioning === \"auto\") {\n this.startAutomaticIdentityProvisioning();\n }\n }\n\n /** Durable incident records in this database, reported to the host's listener. */\n private createSecurityIncidents(\n trustDomain: string | null,\n options: TearleadsOptions,\n ) {\n return createSecurityIncidentService({\n database: this.database,\n logError: this.logError,\n onIncident: options.onSecurityIncident,\n trustDomain,\n });\n }\n\n /** Trust callbacks reach the workflow runtime, which is created later. */\n private createClientSession(\n options: TearleadsOptions,\n reportSecurityIncident: SecurityIncidentReporter,\n ): Session {\n return createSession({\n api: this.apiClient,\n database: this.database,\n documentProjectors: this.documentProjectors,\n identity: this.identity,\n log: this.log,\n logError: this.logError,\n boundUserIdForSigningKey: (signingKeyFingerprint) =>\n this.boundUserId(signingKeyFingerprint),\n onUserIdentityAvailable: (userId, candidate) =>\n this.pinLocalUserIdentity(userId, candidate),\n primeProvisionedPrincipalHistory: (input) =>\n this.primeProvisionedPrincipalHistory(input),\n provisionedSystemContainers: options.provisionedSystemContainers,\n reportSecurityIncident,\n });\n }\n\n private createApiClient(apiBaseUrl: string): ApiClient {\n return new ApiClient(apiBaseUrl, {\n metrics: this.apiRequests,\n getIdentity: () => this.identity.signingFingerprint,\n });\n }\n\n /** Rebinds the session's trust callbacks once the runtime exists. */\n private bindTrustedIdentityRuntime(runtime: InternalRuntime): void {\n this.retirePrincipalHistoryProtection =\n runtime.retirePrincipalHistoryProtection;\n this.pinLocalUserIdentity = (userId, candidate) =>\n runtime.pinLocalUserIdentity(userId, candidate);\n this.primeProvisionedPrincipalHistory =\n runtime.primeProvisionedPrincipalHistory;\n this.boundUserId = (signingKeyFingerprint) =>\n runtime.boundUserId(signingKeyFingerprint);\n }\n\n private configureApiClientCallbacks(): void {\n // Projection reads cite bundles this identity's database already verified.\n this.apiClient.setVerifiedManifestCitations(\n createVerifiedManifestCitations(() => this.database.execSql),\n );\n this.apiClient.setOnError((message) => this.logError(message));\n // An authoritative host source owns connectivity. Without one, request\n // outcomes remain reachability hints. Browser and native app bindings both\n // install authoritative sources so a backend outage cannot stop retries.\n this.apiClient.setOnNetworkError(() =>\n this.network.reportReachability(false),\n );\n this.apiClient.setOnNetworkSuccess(() =>\n this.network.reportReachability(true),\n );\n this.apiClient.setOnApiVersion((version) =>\n this.apiVersion.observe(version),\n );\n this.apiClient.setOnSessionExpired(() => this.loginAfterSessionExpired());\n this.apiClient.setOnPaymentRequired((organizationId) =>\n this.syncBillingGate.notifyPaymentRequired(organizationId),\n );\n }\n\n private createWorkflowRuntime(\n identityTrustDomain: string | null,\n options: TearleadsOptions,\n reportSecurityIncident: SecurityIncidentReporter,\n ): InternalRuntime {\n return createRuntime({\n api: this.apiClient,\n blobs: this.blobs,\n database: this.database,\n documentProjectors: this.documentProjectors,\n events: this.events,\n getDomainScope: () => this.domainScope,\n identity: this.identity,\n identityTrustDomain,\n log: this.log,\n logError: this.logError,\n network: this.network,\n peerScope: options.peerScope ?? null,\n principalHistoryKeyProvider: options.principalHistoryKeyProvider,\n principalMutationTimeoutMs: options.principalMutationTimeoutMs,\n reportSecurityIncident,\n session: this.session,\n syncBillingGate: this.syncBillingGate,\n });\n }\n\n log = (message: string): void => {\n this.logHandler(message);\n };\n\n // Preserve the host's return value so best-effort callers can also catch\n // rejected promises from async loggers accepted by the void callback type.\n logError = (message: string | Error, cause?: unknown): void =>\n this.logErrorHandler(message, cause);\n\n /**\n * A single-use ticket to authenticate the server-events websocket handshake\n * (which cannot carry the bearer header): the one login returned for the\n * first connect of that session, otherwise a freshly minted one. Returns\n * null when no session is active. The caller appends it to the websocket URL.\n */\n requestWebSocketTicket(): Promise<string | null> {\n return this.apiClient.requestWebSocketTicket();\n }\n\n get domainScope(): DomainScope {\n const nextScopeKey = JSON.stringify([\n this.database.id,\n this.identity.signingFingerprint,\n ]);\n if (this.domainScopeKey !== nextScopeKey) {\n this.domainScopeKey = nextScopeKey;\n this.domainScopeValue = createDomainScope();\n }\n\n return this.domainScopeValue;\n }\n\n /**\n * Tear down background work for the active domain scope: stop the reconciler\n * and force-stop the sync coordinator pump, then drop the coordinator from\n * its registry. Hosts call this from unmount/cleanup so a pump cannot outlive\n * the React tree that created it. A later access for the same scope rebuilds\n * fresh state.\n */\n dispose(): void {\n const domainScope = this.domainScope;\n this.disposeSecurityIncidents();\n this.retirePrincipalHistoryProtection();\n this.deviceFirst.dispose();\n disposeDomainSyncCoordinator(domainScope);\n }\n\n private loginAfterSessionExpired(): Promise<boolean> {\n if (!this.session.authToken || !this.identity.signingKeyPair) {\n this.session.logout();\n return Promise.resolve(false);\n }\n\n // The API client replays requests the expired session sent, so a login is\n // their renewal only when the loaded keys authenticate that known user.\n const expiredUserId = this.session.userId;\n this.expiredSessionLoginPromise ??= this.session\n .login()\n .then(\n (renewed) =>\n renewed &&\n expiredUserId !== null &&\n this.session.userId === expiredUserId,\n )\n .finally(() => {\n this.expiredSessionLoginPromise = null;\n });\n return this.expiredSessionLoginPromise;\n }\n\n private startAutomaticIdentityProvisioning(): void {\n let unsubscribe: (() => void) | null = null;\n const stopProvisioningListener = () => {\n unsubscribe?.();\n unsubscribe = null;\n };\n const maybeProvisionIdentity = () => {\n if (this.autoIdentityProvisioned || this.identity.signingKeyPair) {\n stopProvisioningListener();\n return;\n }\n\n if (\n this.autoIdentityProvisioningPromise ||\n this.database.status !== \"ready\"\n ) {\n return;\n }\n\n this.autoIdentityProvisioningPromise = this.identity\n .generate()\n .then(() => {\n this.autoIdentityProvisioned = true;\n stopProvisioningListener();\n })\n .catch((error: unknown) => {\n try {\n this.logError(\"Automatic identity provisioning failed\", error);\n } catch {\n // Keep background provisioning failures from surfacing as unhandled rejections.\n }\n })\n .finally(() => {\n this.autoIdentityProvisioningPromise = null;\n });\n };\n\n unsubscribe = this.database.subscribe(maybeProvisionIdentity);\n void Promise.resolve().then(maybeProvisionIdentity);\n }\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import type { ApiRequestMetrics } from "./internal/api-client/index.js";
2
+ import type { BlobStoreFactory } from "./client/blobs/index.js";
3
+ import type { Logger } from "./client/host/logger.js";
4
+ import type { IdentityOptions } from "./client/identity/index.js";
5
+ import type { DatabaseOptions } from "./client/runtime/database.js";
6
+ import type { PrincipalHistoryKeyProvider } from "./client/runtime/principalHistoryProtection.js";
7
+ import type { SecurityIncidentListener } from "./client/securityIncidents/index.js";
8
+ import type { BlobStore } from "./data/blobs/blobContracts.js";
9
+ import type { DocumentProjectorRegistryInput } from "./data/documents/documentKinds.js";
10
+ import type { ProvisionedSystemContainerSpec } from "./workflows/registration/index.js";
11
+ export type TearleadsDatabaseOptions = Omit<DatabaseOptions, "status">;
12
+ /** What a host passes to `new Tearleads(options)`; every field is optional. */
13
+ export interface TearleadsOptions {
14
+ apiBaseUrl?: string | undefined;
15
+ /** Reuse a memory-only request counter across client lifetimes. */
16
+ apiRequestMetrics?: ApiRequestMetrics | undefined;
17
+ blobStore?: BlobStore | undefined;
18
+ blobStoreFactory?: BlobStoreFactory | undefined;
19
+ database?: TearleadsDatabaseOptions | undefined;
20
+ documentProjectors?: DocumentProjectorRegistryInput | undefined;
21
+ events?: ReadonlyArray<unknown> | undefined;
22
+ identity?: IdentityOptions | undefined;
23
+ /**
24
+ * Absolute, host-controlled API namespace for durable user-identity pins.
25
+ * Required only when apiBaseUrl is relative and no browser origin exists.
26
+ */
27
+ identityTrustDomain?: string | undefined;
28
+ identityProvisioning?: "auto" | "manual" | undefined;
29
+ logger?: Logger | undefined;
30
+ online?: boolean | undefined;
31
+ /** Called after a trust-boundary verification failure is durably recorded. */
32
+ onSecurityIncident?: SecurityIncidentListener | undefined;
33
+ /**
34
+ * Per-pane discriminator so documents in distinct panes derive distinct Loro
35
+ * peer ids (e.g. the pane's local identity namespace). Omit for single-pane.
36
+ */
37
+ peerScope?: string | undefined;
38
+ /** Private host key for durable history progress; omitted uses disposable session keys. */
39
+ principalHistoryKeyProvider?: PrincipalHistoryKeyProvider | undefined;
40
+ /** Compound policy dispatch/recovery deadline in milliseconds; defaults to 60 seconds. */
41
+ principalMutationTimeoutMs?: number | undefined;
42
+ /**
43
+ * App-owned system containers born with every new organization (both
44
+ * registration and additional-org creation provision them atomically in the
45
+ * same server call), e.g. a trash bin. The app owns these because their slot
46
+ * namespaces are app concepts the SDK stays agnostic to.
47
+ */
48
+ provisionedSystemContainers?: ReadonlyArray<ProvisionedSystemContainerSpec> | undefined;
49
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TearleadsOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TearleadsOptions.js","sourceRoot":"","sources":["TearleadsOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ApiRequestMetrics } from \"@tearleads/api-client\";\nimport type { BlobStoreFactory } from \"./client/blobs\";\nimport type { Logger } from \"./client/host/logger\";\nimport type { IdentityOptions } from \"./client/identity\";\nimport type { DatabaseOptions } from \"./client/runtime/database\";\nimport type { PrincipalHistoryKeyProvider } from \"./client/runtime/principalHistoryProtection\";\nimport type { SecurityIncidentListener } from \"./client/securityIncidents\";\nimport type { BlobStore } from \"./data/blobs/blobContracts\";\nimport type { DocumentProjectorRegistryInput } from \"./data/documents/documentKinds\";\nimport type { ProvisionedSystemContainerSpec } from \"./workflows/registration\";\n\nexport type TearleadsDatabaseOptions = Omit<DatabaseOptions, \"status\">;\n\n/** What a host passes to `new Tearleads(options)`; every field is optional. */\nexport interface TearleadsOptions {\n apiBaseUrl?: string | undefined;\n /** Reuse a memory-only request counter across client lifetimes. */\n apiRequestMetrics?: ApiRequestMetrics | undefined;\n blobStore?: BlobStore | undefined;\n blobStoreFactory?: BlobStoreFactory | undefined;\n database?: TearleadsDatabaseOptions | undefined;\n documentProjectors?: DocumentProjectorRegistryInput | undefined;\n events?: ReadonlyArray<unknown> | undefined;\n identity?: IdentityOptions | undefined;\n /**\n * Absolute, host-controlled API namespace for durable user-identity pins.\n * Required only when apiBaseUrl is relative and no browser origin exists.\n */\n identityTrustDomain?: string | undefined;\n identityProvisioning?: \"auto\" | \"manual\" | undefined;\n logger?: Logger | undefined;\n online?: boolean | undefined;\n /** Called after a trust-boundary verification failure is durably recorded. */\n onSecurityIncident?: SecurityIncidentListener | undefined;\n /**\n * Per-pane discriminator so documents in distinct panes derive distinct Loro\n * peer ids (e.g. the pane's local identity namespace). Omit for single-pane.\n */\n peerScope?: string | undefined;\n /** Private host key for durable history progress; omitted uses disposable session keys. */\n principalHistoryKeyProvider?: PrincipalHistoryKeyProvider | undefined;\n /** Compound policy dispatch/recovery deadline in milliseconds; defaults to 60 seconds. */\n principalMutationTimeoutMs?: number | undefined;\n /**\n * App-owned system containers born with every new organization (both\n * registration and additional-org creation provision them atomically in the\n * same server call), e.g. a trash bin. The app owns these because their slot\n * namespaces are app concepts the SDK stays agnostic to.\n */\n provisionedSystemContainers?:\n | ReadonlyArray<ProvisionedSystemContainerSpec>\n | undefined;\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  import { sqlContainerContentsPersistence } from "../../data/persistence/container-contents/containerContentsPersistence.js";
2
2
  import { holdContainerDocumentTombstones, listKnownContainerDocumentPlacements, listRetryableHeldContainerDocumentTombstones, loadLocalDocumentAccessEpoch, refuteContainerDocumentTombstoneHolds, } from "../../data/persistence/documents/containerDocumentTombstoneHoldsPersistence.js";
3
3
  import { createDocumentDiscoveryEvidenceStore } from "../../data/persistence/documents/documentDiscoveryEvidencePersistence.js";
4
- import { listContainerDocumentLanesFromApi } from "../../workflows/container-contents/containerDocumentListing.js";
5
- import { createDiscoveredDocumentVerifier } from "../../workflows/container-contents/documentDiscoveryEvidence.js";
6
- import { discoverContainerDocumentLanes, } from "../../workflows/container-contents/documentDiscoveryLanes.js";
7
- import { createContainerDocumentQueriesFromRuntime } from "../../workflows/container-contents/documentQueries.js";
8
- import { createContainerDocumentTombstoneVerifier, createDocumentHeadLinkSetLoader, } from "../../workflows/container-contents/documentTombstoneEvidence.js";
4
+ import { listContainerDocumentLanesFromApi } from "../../workflows/container-contents/documentDiscovery/containerDocumentListing.js";
5
+ import { createDiscoveredDocumentVerifier } from "../../workflows/container-contents/documentDiscovery/documentDiscoveryEvidence.js";
6
+ import { discoverContainerDocumentLanes, } from "../../workflows/container-contents/documentDiscovery/documentDiscoveryLanes.js";
7
+ import { createContainerDocumentQueriesFromRuntime } from "../../workflows/container-contents/documentQueries/index.js";
9
8
  import { createContainerContentsWorkflowRuntime, } from "../../workflows/container-contents/runtime.js";
9
+ import { createContainerDocumentTombstoneVerifier, createDocumentHeadLinkSetLoader, } from "../../workflows/container-contents/tombstones/documentTombstoneEvidence.js";
10
10
  import { createRuntimePrincipalPolicyWarmer } from "../../workflows/principals/runtimePolicyWarmer.js";
11
11
  function createDiscoveryLane(input) {
12
12
  const { containerOrganizationId, execSql, request, runtime } = input;
@@ -1 +1 @@
1
- {"version":3,"file":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,KAAK,UAAU,oCAAoC,CAAC,EACzD,cAAc,EACd,GAAG,OAAO,EAGX;IACC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,wCAAwC,CAAC;QAC/D,QAAQ,EAAE,CAAC,OAAO,CAAC;QACnB,cAAc;KACf,CAAC,CAAC;IACH,IAAI,OAAO,EAAE,MAAM,KAAK,UAAU;QAAE,MAAM,OAAO,CAAC,MAAM,CAAC;IACzD,OAAO,OAAO,EAAE,KAAK,IAAI,IAAI,CAAC;AAChC,CAAC","sourcesContent":["import type { DocumentSummary } from \"../../data/documents/documentSummary\";\nimport { sqlContainerContentsPersistence } from \"../../data/persistence/container-contents/containerContentsPersistence\";\nimport {\n holdContainerDocumentTombstones,\n listKnownContainerDocumentPlacements,\n listRetryableHeldContainerDocumentTombstones,\n loadLocalDocumentAccessEpoch,\n refuteContainerDocumentTombstoneHolds,\n} from \"../../data/persistence/documents/containerDocumentTombstoneHoldsPersistence\";\nimport { createDocumentDiscoveryEvidenceStore } from \"../../data/persistence/documents/documentDiscoveryEvidencePersistence\";\nimport { listContainerDocumentLanesFromApi } from \"../../workflows/container-contents/containerDocumentListing\";\nimport { createDiscoveredDocumentVerifier } from \"../../workflows/container-contents/documentDiscoveryEvidence\";\nimport {\n type ContainerDocumentDiscoveryLane,\n type ContainerDocumentDiscoveryOutcome,\n type ContainerDocumentDiscoveryOutcomeHandler,\n discoverContainerDocumentLanes,\n} from \"../../workflows/container-contents/documentDiscoveryLanes\";\nimport { createContainerDocumentQueriesFromRuntime } from \"../../workflows/container-contents/documentQueries\";\nimport {\n createContainerDocumentTombstoneVerifier,\n createDocumentHeadLinkSetLoader,\n} from \"../../workflows/container-contents/documentTombstoneEvidence\";\nimport {\n type ContainerContentsWorkflowRuntime,\n createContainerContentsWorkflowRuntime,\n} from \"../../workflows/container-contents/runtime\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../workflows/principals/runtimePolicyWarmer\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\n\nexport type { ContainerDocumentDiscoveryOutcome } from \"../../workflows/container-contents/documentDiscoveryLanes\";\n\n/** One container to discover, with the reconciler's per-lane callbacks. */\nexport interface ContainerDocumentDiscoveryRequest {\n readonly containerId: string;\n readonly onFullListing?:\n | ((documentIds: ReadonlyArray<string>) => void)\n | undefined;\n readonly onPendingDiscovery?: ((delayMs: number) => void) | undefined;\n}\n\ntype ExecSql = ReturnType<InternalRuntime[\"workflowInput\"]>[\"infra\"][\"execSql\"];\n\nfunction createDiscoveryLane(input: {\n readonly containerOrganizationId: string | undefined;\n readonly evidenceStore: ReturnType<\n typeof createDocumentDiscoveryEvidenceStore\n >;\n readonly execSql: ExecSql;\n readonly queries: ReturnType<\n typeof createContainerDocumentQueriesFromRuntime\n >;\n readonly request: ContainerDocumentDiscoveryRequest;\n readonly runtime: ContainerContentsWorkflowRuntime;\n}): ContainerDocumentDiscoveryLane {\n const { containerOrganizationId, execSql, request, runtime } = input;\n const warmReferencedPrincipalPolicies =\n createRuntimePrincipalPolicyWarmer(runtime);\n const loadHead = createDocumentHeadLinkSetLoader(runtime);\n const loadEpoch = (documentId: string) =>\n loadLocalDocumentAccessEpoch(execSql, documentId);\n return {\n ...input.queries,\n cacheReferencedPrincipalPolicies: (references) =>\n containerOrganizationId\n ? warmReferencedPrincipalPolicies({\n organizationId: containerOrganizationId,\n references,\n })\n : Promise.resolve(),\n containerId: request.containerId,\n holdContainerDocumentTombstones: (tombstones) =>\n holdContainerDocumentTombstones(execSql, tombstones),\n listHeldContainerDocumentTombstones: (containerIds) =>\n listRetryableHeldContainerDocumentTombstones(execSql, containerIds),\n listKnownContainerDocumentPlacements: (placements) =>\n listKnownContainerDocumentPlacements(execSql, placements),\n onFullListing: request.onFullListing,\n refuteContainerDocumentTombstoneHolds: (placements) =>\n refuteContainerDocumentTombstoneHolds(execSql, placements),\n verifyContainerDocumentTombstones: createContainerDocumentTombstoneVerifier(\n containerOrganizationId,\n loadHead,\n loadEpoch,\n ),\n verifyDiscoveredDocuments: createDiscoveredDocumentVerifier(\n containerOrganizationId,\n loadHead,\n loadEpoch,\n input.evidenceStore,\n request.onPendingDiscovery,\n ),\n };\n}\n\n/**\n * Internal adapter shared by explicit discovery and background reconciliation:\n * one batched listing for every requested container, then per-container\n * verification scoped to each container's durable organization.\n */\nexport async function discoverContainerDocumentLanesForRuntime({\n onOutcome,\n requests,\n runtimeService,\n}: {\n readonly onOutcome?: ContainerDocumentDiscoveryOutcomeHandler | undefined;\n readonly requests: ReadonlyArray<ContainerDocumentDiscoveryRequest>;\n readonly runtimeService: InternalRuntime;\n}): Promise<ReadonlyArray<ContainerDocumentDiscoveryOutcome>> {\n const unlisted = (\n containerId: string,\n ): ContainerDocumentDiscoveryOutcome => ({\n containerId,\n status: \"fulfilled\",\n value: null,\n });\n const input = runtimeService.workflowInput();\n if (input.infra.dbStatus !== \"ready\") {\n return requests.map(({ containerId }) => unlisted(containerId));\n }\n const runtime = createContainerContentsWorkflowRuntime(input);\n const execSql = input.infra.execSql;\n const evidenceStore = createDocumentDiscoveryEvidenceStore(execSql);\n const queries = createContainerDocumentQueriesFromRuntime(runtime);\n // Capture the reset fence before reading any lane's scope, so a reset\n // between these reads and the listing cannot publish old-organization\n // evidence into its replacement.\n const generation = await evidenceStore.begin();\n const lanes: ContainerDocumentDiscoveryLane[] = [];\n for (const request of requests) {\n const stored =\n await sqlContainerContentsPersistence.loadContainerMetadataState(\n execSql,\n request.containerId,\n );\n if (stored)\n lanes.push(\n createDiscoveryLane({\n containerOrganizationId: stored.container.organizationId,\n evidenceStore,\n execSql,\n queries,\n request,\n runtime,\n }),\n );\n }\n const outcomes = await discoverContainerDocumentLanes({\n generation,\n lanes,\n listContainerDocumentLanes: (listed) =>\n listContainerDocumentLanesFromApi(runtime.apiClient, listed),\n loadContainerDocumentWatermark: queries.loadContainerDocumentWatermark,\n onOutcome,\n });\n const outcomeByContainerId = new Map(\n outcomes.map((outcome) => [outcome.containerId, outcome]),\n );\n return requests.map(\n ({ containerId }) =>\n outcomeByContainerId.get(containerId) ?? unlisted(containerId),\n );\n}\n\n/** Discovers one container; a rejected lane rethrows its failure. */\nexport async function discoverContainerDocumentsForRuntime({\n runtimeService,\n ...request\n}: ContainerDocumentDiscoveryRequest & {\n readonly runtimeService: InternalRuntime;\n}): Promise<ReadonlyArray<DocumentSummary> | null> {\n const [outcome] = await discoverContainerDocumentLanesForRuntime({\n requests: [request],\n runtimeService,\n });\n if (outcome?.status === \"rejected\") throw outcome.reason;\n return outcome?.value ?? null;\n}\n"]}
1
+ {"version":3,"file":"documentDiscovery.js","sourceRoot":"","sources":["documentDiscovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,wEAAwE,CAAC;AACzH,OAAO,EACL,+BAA+B,EAC/B,oCAAoC,EACpC,4CAA4C,EAC5C,4BAA4B,EAC5B,qCAAqC,GACtC,MAAM,6EAA6E,CAAC;AACrF,OAAO,EAAE,oCAAoC,EAAE,MAAM,uEAAuE,CAAC;AAC7H,OAAO,EAAE,iCAAiC,EAAE,MAAM,+EAA+E,CAAC;AAClI,OAAO,EAAE,gCAAgC,EAAE,MAAM,gFAAgF,CAAC;AAClI,OAAO,EAIL,8BAA8B,GAC/B,MAAM,6EAA6E,CAAC;AACrF,OAAO,EAAE,yCAAyC,EAAE,MAAM,oDAAoD,CAAC;AAC/G,OAAO,EAEL,sCAAsC,GACvC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,wCAAwC,EACxC,+BAA+B,GAChC,MAAM,yEAAyE,CAAC;AACjF,OAAO,EAAE,kCAAkC,EAAE,MAAM,gDAAgD,CAAC;AAgBpG,SAAS,mBAAmB,CAAC,KAW5B;IACC,MAAM,EAAE,uBAAuB,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IACrE,MAAM,+BAA+B,GACnC,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,+BAA+B,CAAC,OAAO,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GAAG,IAAI,GAAG,CAClC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAC1D,CAAC;IACF,OAAO,QAAQ,CAAC,GAAG,CACjB,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAClB,oBAAoB,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,WAAW,CAAC,CACjE,CAAC;AACJ,CAAC;AAED,qEAAqE;AACrE,MAAM,CAAC,KAAK,UAAU,oCAAoC,CAAC,EACzD,cAAc,EACd,GAAG,OAAO,EAGX;IACC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,wCAAwC,CAAC;QAC/D,QAAQ,EAAE,CAAC,OAAO,CAAC;QACnB,cAAc;KACf,CAAC,CAAC;IACH,IAAI,OAAO,EAAE,MAAM,KAAK,UAAU;QAAE,MAAM,OAAO,CAAC,MAAM,CAAC;IACzD,OAAO,OAAO,EAAE,KAAK,IAAI,IAAI,CAAC;AAChC,CAAC","sourcesContent":["import type { DocumentSummary } from \"../../data/documents/documentSummary\";\nimport { sqlContainerContentsPersistence } from \"../../data/persistence/container-contents/containerContentsPersistence\";\nimport {\n holdContainerDocumentTombstones,\n listKnownContainerDocumentPlacements,\n listRetryableHeldContainerDocumentTombstones,\n loadLocalDocumentAccessEpoch,\n refuteContainerDocumentTombstoneHolds,\n} from \"../../data/persistence/documents/containerDocumentTombstoneHoldsPersistence\";\nimport { createDocumentDiscoveryEvidenceStore } from \"../../data/persistence/documents/documentDiscoveryEvidencePersistence\";\nimport { listContainerDocumentLanesFromApi } from \"../../workflows/container-contents/documentDiscovery/containerDocumentListing\";\nimport { createDiscoveredDocumentVerifier } from \"../../workflows/container-contents/documentDiscovery/documentDiscoveryEvidence\";\nimport {\n type ContainerDocumentDiscoveryLane,\n type ContainerDocumentDiscoveryOutcome,\n type ContainerDocumentDiscoveryOutcomeHandler,\n discoverContainerDocumentLanes,\n} from \"../../workflows/container-contents/documentDiscovery/documentDiscoveryLanes\";\nimport { createContainerDocumentQueriesFromRuntime } from \"../../workflows/container-contents/documentQueries\";\nimport {\n type ContainerContentsWorkflowRuntime,\n createContainerContentsWorkflowRuntime,\n} from \"../../workflows/container-contents/runtime\";\nimport {\n createContainerDocumentTombstoneVerifier,\n createDocumentHeadLinkSetLoader,\n} from \"../../workflows/container-contents/tombstones/documentTombstoneEvidence\";\nimport { createRuntimePrincipalPolicyWarmer } from \"../../workflows/principals/runtimePolicyWarmer\";\nimport type { InternalRuntime } from \"../runtime/workflowRuntime\";\n\nexport type { ContainerDocumentDiscoveryOutcome } from \"../../workflows/container-contents/documentDiscovery/documentDiscoveryLanes\";\n\n/** One container to discover, with the reconciler's per-lane callbacks. */\nexport interface ContainerDocumentDiscoveryRequest {\n readonly containerId: string;\n readonly onFullListing?:\n | ((documentIds: ReadonlyArray<string>) => void)\n | undefined;\n readonly onPendingDiscovery?: ((delayMs: number) => void) | undefined;\n}\n\ntype ExecSql = ReturnType<InternalRuntime[\"workflowInput\"]>[\"infra\"][\"execSql\"];\n\nfunction createDiscoveryLane(input: {\n readonly containerOrganizationId: string | undefined;\n readonly evidenceStore: ReturnType<\n typeof createDocumentDiscoveryEvidenceStore\n >;\n readonly execSql: ExecSql;\n readonly queries: ReturnType<\n typeof createContainerDocumentQueriesFromRuntime\n >;\n readonly request: ContainerDocumentDiscoveryRequest;\n readonly runtime: ContainerContentsWorkflowRuntime;\n}): ContainerDocumentDiscoveryLane {\n const { containerOrganizationId, execSql, request, runtime } = input;\n const warmReferencedPrincipalPolicies =\n createRuntimePrincipalPolicyWarmer(runtime);\n const loadHead = createDocumentHeadLinkSetLoader(runtime);\n const loadEpoch = (documentId: string) =>\n loadLocalDocumentAccessEpoch(execSql, documentId);\n return {\n ...input.queries,\n cacheReferencedPrincipalPolicies: (references) =>\n containerOrganizationId\n ? warmReferencedPrincipalPolicies({\n organizationId: containerOrganizationId,\n references,\n })\n : Promise.resolve(),\n containerId: request.containerId,\n holdContainerDocumentTombstones: (tombstones) =>\n holdContainerDocumentTombstones(execSql, tombstones),\n listHeldContainerDocumentTombstones: (containerIds) =>\n listRetryableHeldContainerDocumentTombstones(execSql, containerIds),\n listKnownContainerDocumentPlacements: (placements) =>\n listKnownContainerDocumentPlacements(execSql, placements),\n onFullListing: request.onFullListing,\n refuteContainerDocumentTombstoneHolds: (placements) =>\n refuteContainerDocumentTombstoneHolds(execSql, placements),\n verifyContainerDocumentTombstones: createContainerDocumentTombstoneVerifier(\n containerOrganizationId,\n loadHead,\n loadEpoch,\n ),\n verifyDiscoveredDocuments: createDiscoveredDocumentVerifier(\n containerOrganizationId,\n loadHead,\n loadEpoch,\n input.evidenceStore,\n request.onPendingDiscovery,\n ),\n };\n}\n\n/**\n * Internal adapter shared by explicit discovery and background reconciliation:\n * one batched listing for every requested container, then per-container\n * verification scoped to each container's durable organization.\n */\nexport async function discoverContainerDocumentLanesForRuntime({\n onOutcome,\n requests,\n runtimeService,\n}: {\n readonly onOutcome?: ContainerDocumentDiscoveryOutcomeHandler | undefined;\n readonly requests: ReadonlyArray<ContainerDocumentDiscoveryRequest>;\n readonly runtimeService: InternalRuntime;\n}): Promise<ReadonlyArray<ContainerDocumentDiscoveryOutcome>> {\n const unlisted = (\n containerId: string,\n ): ContainerDocumentDiscoveryOutcome => ({\n containerId,\n status: \"fulfilled\",\n value: null,\n });\n const input = runtimeService.workflowInput();\n if (input.infra.dbStatus !== \"ready\") {\n return requests.map(({ containerId }) => unlisted(containerId));\n }\n const runtime = createContainerContentsWorkflowRuntime(input);\n const execSql = input.infra.execSql;\n const evidenceStore = createDocumentDiscoveryEvidenceStore(execSql);\n const queries = createContainerDocumentQueriesFromRuntime(runtime);\n // Capture the reset fence before reading any lane's scope, so a reset\n // between these reads and the listing cannot publish old-organization\n // evidence into its replacement.\n const generation = await evidenceStore.begin();\n const lanes: ContainerDocumentDiscoveryLane[] = [];\n for (const request of requests) {\n const stored =\n await sqlContainerContentsPersistence.loadContainerMetadataState(\n execSql,\n request.containerId,\n );\n if (stored)\n lanes.push(\n createDiscoveryLane({\n containerOrganizationId: stored.container.organizationId,\n evidenceStore,\n execSql,\n queries,\n request,\n runtime,\n }),\n );\n }\n const outcomes = await discoverContainerDocumentLanes({\n generation,\n lanes,\n listContainerDocumentLanes: (listed) =>\n listContainerDocumentLanesFromApi(runtime.apiClient, listed),\n loadContainerDocumentWatermark: queries.loadContainerDocumentWatermark,\n onOutcome,\n });\n const outcomeByContainerId = new Map(\n outcomes.map((outcome) => [outcome.containerId, outcome]),\n );\n return requests.map(\n ({ containerId }) =>\n outcomeByContainerId.get(containerId) ?? unlisted(containerId),\n );\n}\n\n/** Discovers one container; a rejected lane rethrows its failure. */\nexport async function discoverContainerDocumentsForRuntime({\n runtimeService,\n ...request\n}: ContainerDocumentDiscoveryRequest & {\n readonly runtimeService: InternalRuntime;\n}): Promise<ReadonlyArray<DocumentSummary> | null> {\n const [outcome] = await discoverContainerDocumentLanesForRuntime({\n requests: [request],\n runtimeService,\n });\n if (outcome?.status === \"rejected\") throw outcome.reason;\n return outcome?.value ?? null;\n}\n"]}
@@ -2,13 +2,13 @@ import { createContainerDocumentObjectSyncState } from "../../workflows/containe
2
2
  import type { InternalRuntime } from "../runtime/workflowRuntime.js";
3
3
  import type { ContainerContents } from "./types.js";
4
4
  export type { ContainerContentsContextValue, ContainerContentsStore, ContainerContentsStoreOptions, ContainerNode, } from "../../stores/container-contents/index.js";
5
- export type { BlobInfo, BlobInfoAttachmentKind, BlobInfoDocumentReference, BlobInfoInput, BlobInfoList, BlobInfoSort, BlobInfoSortDirection, BlobInfoSortKey, } from "../../workflows/container-contents/blobInfo.js";
6
- export type { ContainerInfo, ContainerShareAccessLevel, } from "../../workflows/container-contents/containerInfo.js";
7
- export type { DocumentAttributionRangesInput, DocumentAttributionRangesPage, } from "../../workflows/container-contents/documentAttributionRanges.js";
8
- export type { DocumentInfo } from "../../workflows/container-contents/documentInfo.js";
9
- export type { ContainerDocumentQueries, ContainerDocumentSidebarRow, ContainerItemRow, ContainerItemSort, ContainerItemSortDirection, ContainerItemSortKey, } from "../../workflows/container-contents/documentQueries.js";
10
- export type { SetLinkedContainerIdsForDocument } from "../../workflows/container-contents/documentStructure.js";
11
- export type { PendingWriteQueueItem, PendingWriteQueueItemStatus, PendingWriteQueueObjectKind, PendingWriteQueueOperation, PendingWriteQueueOperationKind, PendingWriteQueueOperationStatus, } from "../../workflows/container-contents/pendingWrites.js";
5
+ export type { DocumentAttributionRangesInput, DocumentAttributionRangesPage, } from "../../workflows/container-contents/attribution/documentAttributionRanges.js";
6
+ export type { ContainerDocumentQueries, ContainerDocumentSidebarRow, ContainerItemRow, ContainerItemSort, ContainerItemSortDirection, ContainerItemSortKey, } from "../../workflows/container-contents/documentQueries/index.js";
7
+ export type { SetLinkedContainerIdsForDocument } from "../../workflows/container-contents/documentQueries/documentStructure.js";
8
+ export type { BlobInfo, BlobInfoAttachmentKind, BlobInfoDocumentReference, BlobInfoInput, BlobInfoList, BlobInfoSort, BlobInfoSortDirection, BlobInfoSortKey, } from "../../workflows/container-contents/info/blobInfo.js";
9
+ export type { ContainerInfo, ContainerShareAccessLevel, } from "../../workflows/container-contents/info/containerInfo.js";
10
+ export type { DocumentInfo } from "../../workflows/container-contents/info/documentInfo.js";
11
+ export type { PendingWriteQueueItem, PendingWriteQueueItemStatus, PendingWriteQueueObjectKind, PendingWriteQueueOperation, PendingWriteQueueOperationKind, PendingWriteQueueOperationStatus, } from "../../workflows/container-contents/pendingWrites/index.js";
12
12
  export type { ContainerDocumentObjectSyncState, ContainerDocumentObjectSyncStatus, } from "../../workflows/container-contents/syncState.js";
13
13
  export type { ContainerContents, ContainerDocumentLinkInput, ContainerDocumentLinks, ContainerInfoInput, DocumentInfoInput, LinkDocumentToContainerInput, MergeDocumentSummary, MoveDocumentToContainerInput, OpenContainerDocumentInput, PurgeDocumentInput, PurgeDocumentResult, SetActiveDocumentContainerInput, UnlinkDocumentFromContainerInput, } from "./types.js";
14
14
  export { createContainerDocumentObjectSyncState };
@@ -3,16 +3,16 @@ import { inheritPrincipalHistoryProtection } from "../../data/principals/princip
3
3
  import { getOrCreateContainerContentsStore, } from "../../stores/container-contents/index.js";
4
4
  import { openDocumentStore } from "../../stores/documents/index.js";
5
5
  import { relinkDocumentStoreWithCommitSideEffect } from "../../stores/documents/documentStore/internalRelink.js";
6
- import { listBlobInfo, } from "../../workflows/container-contents/blobInfo.js";
7
- import { loadContainerInfo, } from "../../workflows/container-contents/containerInfo.js";
8
- import { loadDocumentAttributionRanges, } from "../../workflows/container-contents/documentAttributionRanges.js";
9
- import { loadDocumentInfo, } from "../../workflows/container-contents/documentInfo.js";
10
- import { purgeLocalContainerDocument, purgeRemoteContainerDocument, } from "../../workflows/container-contents/documentPurge.js";
11
- import { createContainerDocumentQueriesFromRuntime, } from "../../workflows/container-contents/documentQueries.js";
12
- import { activateDocumentLink, addDocumentLink, canMutateDocumentLink, canMutateLocalDocumentLink, moveDocumentLink, removeDocumentLink, } from "../../workflows/container-contents/documentStructure.js";
6
+ import { loadDocumentAttributionRanges, } from "../../workflows/container-contents/attribution/documentAttributionRanges.js";
7
+ import { createContainerDocumentQueriesFromRuntime, } from "../../workflows/container-contents/documentQueries/index.js";
8
+ import { activateDocumentLink, addDocumentLink, canMutateDocumentLink, canMutateLocalDocumentLink, moveDocumentLink, removeDocumentLink, } from "../../workflows/container-contents/documentQueries/documentStructure.js";
9
+ import { listBlobInfo, } from "../../workflows/container-contents/info/blobInfo.js";
10
+ import { loadContainerInfo, } from "../../workflows/container-contents/info/containerInfo.js";
11
+ import { loadDocumentInfo, } from "../../workflows/container-contents/info/documentInfo.js";
13
12
  import { createContainerContentsDocumentProjectionUserKeyResolver } from "../../workflows/container-contents/projectionKeys.js";
14
13
  import { createContainerContentsDocumentsRuntime, createContainerContentsStoreWorkflowRuntime, } from "../../workflows/container-contents/runtime.js";
15
14
  import { createContainerDocumentObjectSyncState } from "../../workflows/container-contents/syncState.js";
15
+ import { purgeLocalContainerDocument, purgeRemoteContainerDocument, } from "../../workflows/container-contents/tombstones/documentPurge.js";
16
16
  import { createOrganizationReadModelCoordinator, } from "../organizations/organizationReadModels.js";
17
17
  import { discoverContainerDocumentsForRuntime } from "./documentDiscovery.js";
18
18
  export { createContainerDocumentObjectSyncState };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,OAAO,EAAE,iCAAiC,EAAE,MAAM,+CAA+C,CAAC;AAClG,OAAO,EAGL,iCAAiC,GAClC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,uCAAuC,EAAE,MAAM,qDAAqD,CAAC;AAC9G,OAAO,EAGL,YAAY,GACb,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAEL,iBAAiB,GAClB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAGL,6BAA6B,GAC9B,MAAM,8DAA8D,CAAC;AACtE,OAAO,EAEL,gBAAgB,GACjB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAEL,yCAAyC,GAC1C,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,0BAA0B,EAE1B,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,wDAAwD,EAAE,MAAM,mDAAmD,CAAC;AAC7H,OAAO,EAEL,uCAAuC,EACvC,2CAA2C,GAC5C,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,sCAAsC,EAAE,MAAM,8CAA8C,CAAC;AAEtG,OAAO,EACL,sCAAsC,GAEvC,MAAM,yCAAyC,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cAAc,CAAC,aAAa,EAAE,CAAC,SAAS;YACxD,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,QAAuB,EAAE;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QACpD,OAAO,YAAY,CAAC;YAClB,GAAG,KAAK;YACR,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;IAED,eAAe;QACb,OAAO,2CAA2C,CAChD,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,EACnC,IAAI,CAAC,cAAc,CAAC,kBAAkB,CACvC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { DEFAULT_DOCUMENT_KIND } from \"../../data/documents/documentConstants\";\nimport type { DocumentSummary } from \"../../data/documents/documentSummary\";\nimport { inheritPrincipalHistoryProtection } from \"../../data/principals/principalHistoryRuntime\";\nimport {\n type ContainerContentsStore,\n type ContainerContentsStoreOptions,\n getOrCreateContainerContentsStore,\n} from \"../../stores/container-contents\";\nimport { openDocumentStore } from \"../../stores/documents\";\nimport { relinkDocumentStoreWithCommitSideEffect } from \"../../stores/documents/documentStore/internalRelink\";\nimport {\n type BlobInfoInput,\n type BlobInfoList,\n listBlobInfo,\n} from \"../../workflows/container-contents/blobInfo\";\nimport {\n type ContainerInfo,\n loadContainerInfo,\n} from \"../../workflows/container-contents/containerInfo\";\nimport {\n type DocumentAttributionRangesInput,\n type DocumentAttributionRangesPage,\n loadDocumentAttributionRanges,\n} from \"../../workflows/container-contents/documentAttributionRanges\";\nimport {\n type DocumentInfo,\n loadDocumentInfo,\n} from \"../../workflows/container-contents/documentInfo\";\nimport {\n purgeLocalContainerDocument,\n purgeRemoteContainerDocument,\n} from \"../../workflows/container-contents/documentPurge\";\nimport {\n type ContainerDocumentQueries,\n createContainerDocumentQueriesFromRuntime,\n} from \"../../workflows/container-contents/documentQueries\";\nimport {\n activateDocumentLink,\n addDocumentLink,\n canMutateDocumentLink,\n canMutateLocalDocumentLink,\n type DocumentStructuralMutationHost,\n moveDocumentLink,\n removeDocumentLink,\n} from \"../../workflows/container-contents/documentStructure\";\nimport { createContainerContentsDocumentProjectionUserKeyResolver } from \"../../workflows/container-contents/projectionKeys\";\nimport {\n type ContainerContentsStoreWorkflowRuntime,\n createContainerContentsDocumentsRuntime,\n createContainerContentsStoreWorkflowRuntime,\n} from \"../../workflows/container-contents/runtime\";\nimport { createContainerDocumentObjectSyncState } from \"../../workflows/container-contents/syncState\";\nimport type { DocumentsWorkflowRuntime } from \"../../workflows/documents\";\nimport {\n createOrganizationReadModelCoordinator,\n type OrganizationReadModelCoordinator,\n} from \"../organizations/organizationReadModels\";\nimport type {\n InternalRuntime,\n InternalWorkflowRuntimeInput,\n} from \"../runtime/workflowRuntime\";\nimport { discoverContainerDocumentsForRuntime } from \"./documentDiscovery\";\nimport type {\n ContainerContents,\n ContainerDocumentLinks,\n ContainerInfoInput,\n DocumentInfoInput,\n MergeDocumentSummary,\n MoveDocumentToContainerInput,\n OpenContainerDocumentInput,\n} from \"./types\";\n\nexport type {\n ContainerContentsContextValue,\n ContainerContentsStore,\n ContainerContentsStoreOptions,\n ContainerNode,\n} from \"../../stores/container-contents\";\nexport type {\n BlobInfo,\n BlobInfoAttachmentKind,\n BlobInfoDocumentReference,\n BlobInfoInput,\n BlobInfoList,\n BlobInfoSort,\n BlobInfoSortDirection,\n BlobInfoSortKey,\n} from \"../../workflows/container-contents/blobInfo\";\nexport type {\n ContainerInfo,\n ContainerShareAccessLevel,\n} from \"../../workflows/container-contents/containerInfo\";\nexport type {\n DocumentAttributionRangesInput,\n DocumentAttributionRangesPage,\n} from \"../../workflows/container-contents/documentAttributionRanges\";\nexport type { DocumentInfo } from \"../../workflows/container-contents/documentInfo\";\nexport type {\n ContainerDocumentQueries,\n ContainerDocumentSidebarRow,\n ContainerItemRow,\n ContainerItemSort,\n ContainerItemSortDirection,\n ContainerItemSortKey,\n} from \"../../workflows/container-contents/documentQueries\";\nexport type { SetLinkedContainerIdsForDocument } from \"../../workflows/container-contents/documentStructure\";\nexport type {\n PendingWriteQueueItem,\n PendingWriteQueueItemStatus,\n PendingWriteQueueObjectKind,\n PendingWriteQueueOperation,\n PendingWriteQueueOperationKind,\n PendingWriteQueueOperationStatus,\n} from \"../../workflows/container-contents/pendingWrites\";\nexport type {\n ContainerDocumentObjectSyncState,\n ContainerDocumentObjectSyncStatus,\n} from \"../../workflows/container-contents/syncState\";\nexport type {\n ContainerContents,\n ContainerDocumentLinkInput,\n ContainerDocumentLinks,\n ContainerInfoInput,\n DocumentInfoInput,\n LinkDocumentToContainerInput,\n MergeDocumentSummary,\n MoveDocumentToContainerInput,\n OpenContainerDocumentInput,\n PurgeDocumentInput,\n PurgeDocumentResult,\n SetActiveDocumentContainerInput,\n UnlinkDocumentFromContainerInput,\n} from \"./types\";\n\nexport { createContainerDocumentObjectSyncState };\n\nexport function createContainerContents(\n runtime: InternalRuntime,\n): ContainerContents {\n return new ContainerContentsService(runtime);\n}\n\nfunction createDocumentLinkHost(\n runtime: ContainerDocumentLinks,\n mergeDocumentSummary: MergeDocumentSummary,\n): DocumentStructuralMutationHost<DocumentsWorkflowRuntime> {\n return {\n documentWorkflowRuntime: runtime.documentRuntime,\n mergeDocumentSummary,\n openDocumentStore: (input) => {\n const store = runtime.openDocument({\n containerId: input.containerId,\n documentId: input.documentId,\n localId: input.localId,\n });\n return {\n ...store,\n relink: ({ commitSideEffect, ...relinkInput }) =>\n commitSideEffect\n ? relinkDocumentStoreWithCommitSideEffect(\n store,\n relinkInput,\n commitSideEffect,\n )\n : store.relink(relinkInput),\n };\n },\n };\n}\n\nfunction moveDocumentLinkNote(\n input: Pick<MoveDocumentToContainerInput, \"note\" | \"sourceContainerId\">,\n): DocumentSummary {\n if (\n input.note.documentId &&\n input.sourceContainerId &&\n input.sourceContainerId !== input.note.containerId\n ) {\n return { ...input.note, containerId: input.sourceContainerId };\n }\n\n return input.note;\n}\n\ninterface ContainerInfoOrganizationScope {\n readonly domainScope: InternalWorkflowRuntimeInput[\"state\"][\"domainScope\"];\n readonly organizationId: string;\n readonly userId: string;\n}\n\nfunction readyExecSql(\n runtime: InternalWorkflowRuntimeInput,\n): InternalWorkflowRuntimeInput[\"infra\"][\"execSql\"] | null {\n return runtime.infra.dbStatus === \"ready\" ? runtime.infra.execSql : null;\n}\n\nfunction isActiveContainerInfoOrganizationScope(\n runtime: InternalWorkflowRuntimeInput,\n scope: ContainerInfoOrganizationScope,\n): boolean {\n return (\n runtime.auth.isAuthenticated &&\n runtime.auth.organizationId === scope.organizationId &&\n runtime.auth.userId === scope.userId &&\n runtime.state.domainScope === scope.domainScope\n );\n}\n\nfunction purgeDocumentFromLinks(input: {\n readonly document: Parameters<ContainerDocumentLinks[\"purgeDocument\"]>[0];\n readonly resolveProjectionUserKey: ContainerDocumentLinks[\"resolveProjectionUserKey\"];\n readonly runtime: ContainerDocumentLinks;\n}) {\n const { note } = input.document;\n if (!note.documentId) {\n return purgeLocalContainerDocument({\n noteId: note.id,\n runtime: input.runtime,\n });\n }\n return purgeRemoteContainerDocument({\n documentId: note.documentId,\n documentKind: note.documentKind ?? DEFAULT_DOCUMENT_KIND,\n noteId: note.id,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n runtime: input.runtime,\n });\n}\n\nclass ContainerContentsService implements ContainerContents {\n private readonly organizationReadModels: OrganizationReadModelCoordinator;\n\n constructor(private readonly runtimeService: InternalRuntime) {\n this.organizationReadModels =\n createOrganizationReadModelCoordinator(runtimeService);\n }\n\n openTree(\n options?: ContainerContentsStoreOptions | undefined,\n ): ContainerContentsStore {\n const runtime = this.workflowRuntime();\n const store = getOrCreateContainerContentsStore(\n runtime.state.domainScope,\n runtime,\n options,\n );\n return store;\n }\n\n documentQueries(): ContainerDocumentQueries {\n return createContainerDocumentQueriesFromRuntime(this.workflowRuntime());\n }\n\n documentLinks(): ContainerDocumentLinks {\n const runtime = this.workflowRuntime();\n const resolveProjectionUserKey =\n createContainerContentsDocumentProjectionUserKeyResolver(runtime);\n const documentRuntime = (containerId: string | null) =>\n createContainerContentsDocumentsRuntime(runtime, containerId);\n const openContainerDocument = (input: OpenContainerDocumentInput) =>\n openDocumentStore(\n runtime.state.domainScope,\n input.localId,\n documentRuntime(input.containerId),\n input.documentId ?? null,\n input.initialText,\n input.initialDocumentKind,\n { deferInitialUpdate: input.deferInitialUpdate },\n );\n const documentLinks: ContainerDocumentLinks = {\n ...runtime,\n documentRuntime,\n openDocument: openContainerDocument,\n setActiveDocumentContainer: (input) =>\n activateDocumentLink({\n host: createDocumentLinkHost(\n documentLinks,\n input.mergeDocumentSummary,\n ),\n note: input.note,\n runtime: documentLinks,\n targetContainerId: input.targetContainerId,\n }),\n canMutateDocumentLinks: canMutateDocumentLink(runtime),\n canMutateUnsyncedDocumentLinks: canMutateLocalDocumentLink(runtime),\n linkDocumentToContainer: (input) =>\n addDocumentLink({\n host: createDocumentLinkHost(\n documentLinks,\n input.mergeDocumentSummary,\n ),\n note: input.note,\n runtime: documentLinks,\n scheduleSync: () => this.openTree().requestSync(),\n setLinkedContainerIdsForDocument:\n input.setLinkedContainerIdsForDocument,\n targetContainerId: input.targetContainerId,\n }),\n moveDocumentToContainer: (input) =>\n moveDocumentLink({\n expandNode: input.expandNode,\n host: createDocumentLinkHost(\n documentLinks,\n input.mergeDocumentSummary,\n ),\n note: moveDocumentLinkNote(input),\n replaceLinkedContainers: input.replaceLinkedContainers,\n runtime: documentLinks,\n scheduleSync: () => this.openTree().requestSync(),\n setLinkedContainerIdsForDocument:\n input.setLinkedContainerIdsForDocument,\n targetContainerId: input.targetContainerId,\n }),\n purgeDocument: (document) =>\n purgeDocumentFromLinks({\n document,\n resolveProjectionUserKey,\n runtime: documentLinks,\n }),\n resolveProjectionUserKey,\n unlinkDocumentFromContainer: (input) =>\n removeDocumentLink({\n host: createDocumentLinkHost(\n documentLinks,\n input.mergeDocumentSummary,\n ),\n note: input.note,\n removedContainerId: input.removedContainerId,\n runtime: documentLinks,\n scheduleSync: () => this.openTree().requestSync(),\n setLinkedContainerIdsForDocument:\n input.setLinkedContainerIdsForDocument,\n }),\n };\n\n return inheritPrincipalHistoryProtection(runtime, documentLinks);\n }\n\n discoverContainerDocuments(\n containerId: string,\n ): Promise<ReadonlyArray<DocumentSummary> | null> {\n return discoverContainerDocumentsForRuntime({\n containerId,\n runtimeService: this.runtimeService,\n });\n }\n\n pullDocumentContent(input: {\n containerId: string;\n localId: string;\n documentId?: string | null | undefined;\n }): void {\n const runtime = this.workflowRuntime();\n const store = openDocumentStore(\n runtime.state.domainScope,\n input.localId,\n createContainerContentsDocumentsRuntime(runtime, input.containerId),\n input.documentId ?? null,\n );\n store.requestRemoteSync();\n }\n\n loadContainerInfo(input: ContainerInfoInput): Promise<ContainerInfo> {\n const runtime = this.runtimeService.workflowInput();\n const organizationScope =\n runtime.auth.isAuthenticated &&\n runtime.auth.organizationId &&\n runtime.auth.userId\n ? {\n domainScope: runtime.state.domainScope,\n organizationId: runtime.auth.organizationId,\n userId: runtime.auth.userId,\n }\n : null;\n const cachedContainerProjection =\n input.remoteInfoMode === \"always\"\n ? null\n : this.openTree().getCachedContainerWriterProjection(input.containerId);\n return loadContainerInfo({\n ...input,\n apiClient: runtime.apiClient,\n containerProjection: cachedContainerProjection,\n execSql: readyExecSql(runtime),\n loadOrganizationGroups: async () => {\n if (\n !organizationScope ||\n !isActiveContainerInfoOrganizationScope(\n this.runtimeService.workflowInput(),\n organizationScope,\n )\n ) {\n return [];\n }\n // Organization groups are disposable presentation data. Container\n // writer projections remain the authority for grants and access.\n const projection = await this.organizationReadModels.loadLocal(\n organizationScope.organizationId,\n );\n return isActiveContainerInfoOrganizationScope(\n this.runtimeService.workflowInput(),\n organizationScope,\n )\n ? (projection?.groups ?? [])\n : [];\n },\n parentId: input.parentId ?? null,\n });\n }\n\n loadDocumentInfo(input: DocumentInfoInput): Promise<DocumentInfo> {\n const runtime = this.runtimeService.workflowInput();\n return loadDocumentInfo({\n ...input,\n apiClient: runtime.apiClient,\n execSql: readyExecSql(runtime),\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n });\n }\n\n loadDocumentEditAttribution(\n documentId: string,\n ): ReturnType<ContainerContents[\"loadDocumentEditAttribution\"]> {\n return this.runtimeService\n .workflowInput()\n .apiClient.getDocumentEditAttribution(documentId);\n }\n\n loadDocumentAttributionRanges(\n input: DocumentAttributionRangesInput,\n ): Promise<DocumentAttributionRangesPage> {\n return loadDocumentAttributionRanges({\n apiClient: this.runtimeService.workflowInput().apiClient,\n query: input,\n });\n }\n\n listBlobInfo(input: BlobInfoInput = {}): Promise<BlobInfoList> {\n const runtime = this.runtimeService.workflowInput();\n return listBlobInfo({\n ...input,\n execSql: readyExecSql(runtime),\n });\n }\n\n workflowRuntime(): ContainerContentsStoreWorkflowRuntime {\n return createContainerContentsStoreWorkflowRuntime(\n this.runtimeService.workflowInput(),\n this.runtimeService.adoptRootContainer,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,OAAO,EAAE,iCAAiC,EAAE,MAAM,+CAA+C,CAAC;AAClG,OAAO,EAGL,iCAAiC,GAClC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,uCAAuC,EAAE,MAAM,qDAAqD,CAAC;AAC9G,OAAO,EAGL,6BAA6B,GAC9B,MAAM,0EAA0E,CAAC;AAClF,OAAO,EAEL,yCAAyC,GAC1C,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,0BAA0B,EAE1B,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,sEAAsE,CAAC;AAC9E,OAAO,EAGL,YAAY,GACb,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAEL,i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R,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC;YAC9B,sBAAsB,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB;SAC5D,CAAC,CAAC;IACL,CAAC;IAED,2BAA2B,CACzB,UAAkB;QAElB,OAAO,IAAI,CAAC,cAAc;aACvB,aAAa,EAAE;aACf,SAAS,CAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IAED,6BAA6B,CAC3B,KAAqC;QAErC,OAAO,6BAA6B,CAAC;YACnC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC,SAAS;YACxD,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,QAAuB,EAAE;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QACpD,OAAO,YAAY,CAAC;YAClB,GAAG,KAAK;YACR,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;IAED,eAAe;QACb,OAAO,2CAA2C,CAChD,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,EACnC,IAAI,CAAC,cAAc,CAAC,kBAAkB,CACvC,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { DEFAULT_DOCUMENT_KIND } from \"../../data/documents/documentConstants\";\nimport type { DocumentSummary } from \"../../data/documents/documentSummary\";\nimport { inheritPrincipalHistoryProtection } from \"../../data/principals/principalHistoryRuntime\";\nimport {\n type ContainerContentsStore,\n type ContainerContentsStoreOptions,\n getOrCreateContainerContentsStore,\n} from \"../../stores/container-contents\";\nimport { openDocumentStore } from \"../../stores/documents\";\nimport { relinkDocumentStoreWithCommitSideEffect } from \"../../stores/documents/documentStore/internalRelink\";\nimport {\n type DocumentAttributionRangesInput,\n type DocumentAttributionRangesPage,\n loadDocumentAttributionRanges,\n} from \"../../workflows/container-contents/attribution/documentAttributionRanges\";\nimport {\n type ContainerDocumentQueries,\n createContainerDocumentQueriesFromRuntime,\n} from \"../../workflows/container-contents/documentQueries\";\nimport {\n activateDocumentLink,\n addDocumentLink,\n canMutateDocumentLink,\n canMutateLocalDocumentLink,\n type DocumentStructuralMutationHost,\n moveDocumentLink,\n removeDocumentLink,\n} from \"../../workflows/container-contents/documentQueries/documentStructure\";\nimport {\n type BlobInfoInput,\n type BlobInfoList,\n listBlobInfo,\n} from \"../../workflows/container-contents/info/blobInfo\";\nimport {\n type ContainerInfo,\n loadContainerInfo,\n} from \"../../workflows/container-contents/info/containerInfo\";\nimport {\n type DocumentInfo,\n loadDocumentInfo,\n} from \"../../workflows/container-contents/info/documentInfo\";\nimport { createContainerContentsDocumentProjectionUserKeyResolver } from \"../../workflows/container-contents/projectionKeys\";\nimport {\n type ContainerContentsStoreWorkflowRuntime,\n createContainerContentsDocumentsRuntime,\n createContainerContentsStoreWorkflowRuntime,\n} from \"../../workflows/container-contents/runtime\";\nimport { createContainerDocumentObjectSyncState } from \"../../workflows/container-contents/syncState\";\nimport {\n purgeLocalContainerDocument,\n purgeRemoteContainerDocument,\n} from \"../../workflows/container-contents/tombstones/documentPurge\";\nimport type { DocumentsWorkflowRuntime } from \"../../workflows/documents\";\nimport {\n createOrganizationReadModelCoordinator,\n type OrganizationReadModelCoordinator,\n} from \"../organizations/organizationReadModels\";\nimport type {\n InternalRuntime,\n InternalWorkflowRuntimeInput,\n} from \"../runtime/workflowRuntime\";\nimport { discoverContainerDocumentsForRuntime } from \"./documentDiscovery\";\nimport type {\n ContainerContents,\n ContainerDocumentLinks,\n ContainerInfoInput,\n DocumentInfoInput,\n MergeDocumentSummary,\n MoveDocumentToContainerInput,\n OpenContainerDocumentInput,\n} from \"./types\";\n\nexport type {\n ContainerContentsContextValue,\n ContainerContentsStore,\n ContainerContentsStoreOptions,\n ContainerNode,\n} from \"../../stores/container-contents\";\nexport type {\n DocumentAttributionRangesInput,\n DocumentAttributionRangesPage,\n} from \"../../workflows/container-contents/attribution/documentAttributionRanges\";\nexport type {\n ContainerDocumentQueries,\n ContainerDocumentSidebarRow,\n ContainerItemRow,\n ContainerItemSort,\n ContainerItemSortDirection,\n ContainerItemSortKey,\n} from \"../../workflows/container-contents/documentQueries\";\nexport type { SetLinkedContainerIdsForDocument } from \"../../workflows/container-contents/documentQueries/documentStructure\";\nexport type {\n BlobInfo,\n BlobInfoAttachmentKind,\n BlobInfoDocumentReference,\n BlobInfoInput,\n BlobInfoList,\n BlobInfoSort,\n BlobInfoSortDirection,\n BlobInfoSortKey,\n} from \"../../workflows/container-contents/info/blobInfo\";\nexport type {\n ContainerInfo,\n ContainerShareAccessLevel,\n} from \"../../workflows/container-contents/info/containerInfo\";\nexport type { DocumentInfo } from \"../../workflows/container-contents/info/documentInfo\";\nexport type {\n PendingWriteQueueItem,\n PendingWriteQueueItemStatus,\n PendingWriteQueueObjectKind,\n PendingWriteQueueOperation,\n PendingWriteQueueOperationKind,\n PendingWriteQueueOperationStatus,\n} from \"../../workflows/container-contents/pendingWrites\";\nexport type {\n ContainerDocumentObjectSyncState,\n ContainerDocumentObjectSyncStatus,\n} from \"../../workflows/container-contents/syncState\";\nexport type {\n ContainerContents,\n ContainerDocumentLinkInput,\n ContainerDocumentLinks,\n ContainerInfoInput,\n DocumentInfoInput,\n LinkDocumentToContainerInput,\n MergeDocumentSummary,\n MoveDocumentToContainerInput,\n OpenContainerDocumentInput,\n PurgeDocumentInput,\n PurgeDocumentResult,\n SetActiveDocumentContainerInput,\n UnlinkDocumentFromContainerInput,\n} from \"./types\";\n\nexport { createContainerDocumentObjectSyncState };\n\nexport function createContainerContents(\n runtime: InternalRuntime,\n): ContainerContents {\n return new ContainerContentsService(runtime);\n}\n\nfunction createDocumentLinkHost(\n runtime: ContainerDocumentLinks,\n mergeDocumentSummary: MergeDocumentSummary,\n): DocumentStructuralMutationHost<DocumentsWorkflowRuntime> {\n return {\n documentWorkflowRuntime: runtime.documentRuntime,\n mergeDocumentSummary,\n openDocumentStore: (input) => {\n const store = runtime.openDocument({\n containerId: input.containerId,\n documentId: input.documentId,\n localId: input.localId,\n });\n return {\n ...store,\n relink: ({ commitSideEffect, ...relinkInput }) =>\n commitSideEffect\n ? relinkDocumentStoreWithCommitSideEffect(\n store,\n relinkInput,\n commitSideEffect,\n )\n : store.relink(relinkInput),\n };\n },\n };\n}\n\nfunction moveDocumentLinkNote(\n input: Pick<MoveDocumentToContainerInput, \"note\" | \"sourceContainerId\">,\n): DocumentSummary {\n if (\n input.note.documentId &&\n input.sourceContainerId &&\n input.sourceContainerId !== input.note.containerId\n ) {\n return { ...input.note, containerId: input.sourceContainerId };\n }\n\n return input.note;\n}\n\ninterface ContainerInfoOrganizationScope {\n readonly domainScope: InternalWorkflowRuntimeInput[\"state\"][\"domainScope\"];\n readonly organizationId: string;\n readonly userId: string;\n}\n\nfunction readyExecSql(\n runtime: InternalWorkflowRuntimeInput,\n): InternalWorkflowRuntimeInput[\"infra\"][\"execSql\"] | null {\n return runtime.infra.dbStatus === \"ready\" ? runtime.infra.execSql : null;\n}\n\nfunction isActiveContainerInfoOrganizationScope(\n runtime: InternalWorkflowRuntimeInput,\n scope: ContainerInfoOrganizationScope,\n): boolean {\n return (\n runtime.auth.isAuthenticated &&\n runtime.auth.organizationId === scope.organizationId &&\n runtime.auth.userId === scope.userId &&\n runtime.state.domainScope === scope.domainScope\n );\n}\n\nfunction purgeDocumentFromLinks(input: {\n readonly document: Parameters<ContainerDocumentLinks[\"purgeDocument\"]>[0];\n readonly resolveProjectionUserKey: ContainerDocumentLinks[\"resolveProjectionUserKey\"];\n readonly runtime: ContainerDocumentLinks;\n}) {\n const { note } = input.document;\n if (!note.documentId) {\n return purgeLocalContainerDocument({\n noteId: note.id,\n runtime: input.runtime,\n });\n }\n return purgeRemoteContainerDocument({\n documentId: note.documentId,\n documentKind: note.documentKind ?? DEFAULT_DOCUMENT_KIND,\n noteId: note.id,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n runtime: input.runtime,\n });\n}\n\nclass ContainerContentsService implements ContainerContents {\n private readonly organizationReadModels: OrganizationReadModelCoordinator;\n\n constructor(private readonly runtimeService: InternalRuntime) {\n this.organizationReadModels =\n createOrganizationReadModelCoordinator(runtimeService);\n }\n\n openTree(\n options?: ContainerContentsStoreOptions | undefined,\n ): ContainerContentsStore {\n const runtime = this.workflowRuntime();\n const store = getOrCreateContainerContentsStore(\n runtime.state.domainScope,\n runtime,\n options,\n );\n return store;\n }\n\n documentQueries(): ContainerDocumentQueries {\n return createContainerDocumentQueriesFromRuntime(this.workflowRuntime());\n }\n\n documentLinks(): ContainerDocumentLinks {\n const runtime = this.workflowRuntime();\n const resolveProjectionUserKey =\n createContainerContentsDocumentProjectionUserKeyResolver(runtime);\n const documentRuntime = (containerId: string | null) =>\n createContainerContentsDocumentsRuntime(runtime, containerId);\n const openContainerDocument = (input: OpenContainerDocumentInput) =>\n openDocumentStore(\n runtime.state.domainScope,\n input.localId,\n documentRuntime(input.containerId),\n input.documentId ?? null,\n input.initialText,\n input.initialDocumentKind,\n { deferInitialUpdate: input.deferInitialUpdate },\n );\n const documentLinks: ContainerDocumentLinks = {\n ...runtime,\n documentRuntime,\n openDocument: openContainerDocument,\n setActiveDocumentContainer: (input) =>\n activateDocumentLink({\n host: createDocumentLinkHost(\n documentLinks,\n input.mergeDocumentSummary,\n ),\n note: input.note,\n runtime: documentLinks,\n targetContainerId: input.targetContainerId,\n }),\n canMutateDocumentLinks: canMutateDocumentLink(runtime),\n canMutateUnsyncedDocumentLinks: canMutateLocalDocumentLink(runtime),\n linkDocumentToContainer: (input) =>\n addDocumentLink({\n host: createDocumentLinkHost(\n documentLinks,\n input.mergeDocumentSummary,\n ),\n note: input.note,\n runtime: documentLinks,\n scheduleSync: () => this.openTree().requestSync(),\n setLinkedContainerIdsForDocument:\n input.setLinkedContainerIdsForDocument,\n targetContainerId: input.targetContainerId,\n }),\n moveDocumentToContainer: (input) =>\n moveDocumentLink({\n expandNode: input.expandNode,\n host: createDocumentLinkHost(\n documentLinks,\n input.mergeDocumentSummary,\n ),\n note: moveDocumentLinkNote(input),\n replaceLinkedContainers: input.replaceLinkedContainers,\n runtime: documentLinks,\n scheduleSync: () => this.openTree().requestSync(),\n setLinkedContainerIdsForDocument:\n input.setLinkedContainerIdsForDocument,\n targetContainerId: input.targetContainerId,\n }),\n purgeDocument: (document) =>\n purgeDocumentFromLinks({\n document,\n resolveProjectionUserKey,\n runtime: documentLinks,\n }),\n resolveProjectionUserKey,\n unlinkDocumentFromContainer: (input) =>\n removeDocumentLink({\n host: createDocumentLinkHost(\n documentLinks,\n input.mergeDocumentSummary,\n ),\n note: input.note,\n removedContainerId: input.removedContainerId,\n runtime: documentLinks,\n scheduleSync: () => this.openTree().requestSync(),\n setLinkedContainerIdsForDocument:\n input.setLinkedContainerIdsForDocument,\n }),\n };\n\n return inheritPrincipalHistoryProtection(runtime, documentLinks);\n }\n\n discoverContainerDocuments(\n containerId: string,\n ): Promise<ReadonlyArray<DocumentSummary> | null> {\n return discoverContainerDocumentsForRuntime({\n containerId,\n runtimeService: this.runtimeService,\n });\n }\n\n pullDocumentContent(input: {\n containerId: string;\n localId: string;\n documentId?: string | null | undefined;\n }): void {\n const runtime = this.workflowRuntime();\n const store = openDocumentStore(\n runtime.state.domainScope,\n input.localId,\n createContainerContentsDocumentsRuntime(runtime, input.containerId),\n input.documentId ?? null,\n );\n store.requestRemoteSync();\n }\n\n loadContainerInfo(input: ContainerInfoInput): Promise<ContainerInfo> {\n const runtime = this.runtimeService.workflowInput();\n const organizationScope =\n runtime.auth.isAuthenticated &&\n runtime.auth.organizationId &&\n runtime.auth.userId\n ? {\n domainScope: runtime.state.domainScope,\n organizationId: runtime.auth.organizationId,\n userId: runtime.auth.userId,\n }\n : null;\n const cachedContainerProjection =\n input.remoteInfoMode === \"always\"\n ? null\n : this.openTree().getCachedContainerWriterProjection(input.containerId);\n return loadContainerInfo({\n ...input,\n apiClient: runtime.apiClient,\n containerProjection: cachedContainerProjection,\n execSql: readyExecSql(runtime),\n loadOrganizationGroups: async () => {\n if (\n !organizationScope ||\n !isActiveContainerInfoOrganizationScope(\n this.runtimeService.workflowInput(),\n organizationScope,\n )\n ) {\n return [];\n }\n // Organization groups are disposable presentation data. Container\n // writer projections remain the authority for grants and access.\n const projection = await this.organizationReadModels.loadLocal(\n organizationScope.organizationId,\n );\n return isActiveContainerInfoOrganizationScope(\n this.runtimeService.workflowInput(),\n organizationScope,\n )\n ? (projection?.groups ?? [])\n : [];\n },\n parentId: input.parentId ?? null,\n });\n }\n\n loadDocumentInfo(input: DocumentInfoInput): Promise<DocumentInfo> {\n const runtime = this.runtimeService.workflowInput();\n return loadDocumentInfo({\n ...input,\n apiClient: runtime.apiClient,\n execSql: readyExecSql(runtime),\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n });\n }\n\n loadDocumentEditAttribution(\n documentId: string,\n ): ReturnType<ContainerContents[\"loadDocumentEditAttribution\"]> {\n return this.runtimeService\n .workflowInput()\n .apiClient.getDocumentEditAttribution(documentId);\n }\n\n loadDocumentAttributionRanges(\n input: DocumentAttributionRangesInput,\n ): Promise<DocumentAttributionRangesPage> {\n return loadDocumentAttributionRanges({\n apiClient: this.runtimeService.workflowInput().apiClient,\n query: input,\n });\n }\n\n listBlobInfo(input: BlobInfoInput = {}): Promise<BlobInfoList> {\n const runtime = this.runtimeService.workflowInput();\n return listBlobInfo({\n ...input,\n execSql: readyExecSql(runtime),\n });\n }\n\n workflowRuntime(): ContainerContentsStoreWorkflowRuntime {\n return createContainerContentsStoreWorkflowRuntime(\n this.runtimeService.workflowInput(),\n this.runtimeService.adoptRootContainer,\n );\n }\n}\n"]}