@tearleads/client-sdk 0.1.217 → 0.1.219

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 (168) hide show
  1. package/client/containerContents/documentDiscovery.js +6 -4
  2. package/client/containerContents/documentDiscovery.js.map +1 -1
  3. package/client/containerContents/index.js +3 -4
  4. package/client/containerContents/index.js.map +1 -1
  5. package/client/deviceFirst/index.js +2 -2
  6. package/client/deviceFirst/index.js.map +1 -1
  7. package/client/documents/index.js +2 -2
  8. package/client/documents/index.js.map +1 -1
  9. package/client/organizations/organizationGroupHistory.js +1 -2
  10. package/client/organizations/organizationGroupHistory.js.map +1 -1
  11. package/client/organizations/organizationGroupNameHydration.js +1 -2
  12. package/client/organizations/organizationGroupNameHydration.js.map +1 -1
  13. package/client/organizations/organizationHistory.js +2 -4
  14. package/client/organizations/organizationHistory.js.map +1 -1
  15. package/client/organizations/principalContainerMutations.js +1 -2
  16. package/client/organizations/principalContainerMutations.js.map +1 -1
  17. package/client/organizations/principalMutations.js +1 -2
  18. package/client/organizations/principalMutations.js.map +1 -1
  19. package/client/organizations/rosterAdmissionEvidence.js +1 -2
  20. package/client/organizations/rosterAdmissionEvidence.js.map +1 -1
  21. package/client/runtime/workflowRuntime.d.ts +3 -2
  22. package/client/runtime/workflowRuntime.js +13 -3
  23. package/client/runtime/workflowRuntime.js.map +1 -1
  24. package/index.d.ts +3 -3
  25. package/index.js +1 -1
  26. package/index.js.map +1 -1
  27. package/package.json +1 -1
  28. package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -1
  29. package/stores/documents/documentStore/attachments/attachmentHydration.js +3 -2
  30. package/stores/documents/documentStore/attachments/attachmentHydration.js.map +1 -1
  31. package/stores/documents/documentStore/history/historyRebuild.js.map +1 -1
  32. package/stores/documents/documentStore/rotation/index.js +11 -8
  33. package/stores/documents/documentStore/rotation/index.js.map +1 -1
  34. package/stores/documents/documentStore/rotation/rotationSettlement.js +1 -1
  35. package/stores/documents/documentStore/rotation/rotationSettlement.js.map +1 -1
  36. package/stores/documents/documentStore/state.js.map +1 -1
  37. package/stores/documents/documentStore/sync/carriedFirstUpdate.js.map +1 -1
  38. package/stores/documents/documentStore/sync/createdDocumentPersistence.js.map +1 -1
  39. package/stores/documents/documentStore/sync/index.js.map +1 -1
  40. package/stores/documents/documentStore/sync/syncAttachments.js +3 -2
  41. package/stores/documents/documentStore/sync/syncAttachments.js.map +1 -1
  42. package/stores/documents/documentStore/sync/syncDetachedAttachments.js +3 -2
  43. package/stores/documents/documentStore/sync/syncDetachedAttachments.js.map +1 -1
  44. package/stores/documents/documentStore/sync/syncRequest.js +12 -8
  45. package/stores/documents/documentStore/sync/syncRequest.js.map +1 -1
  46. package/stores/documents/documentStore/sync/syncRevalidation.js.map +1 -1
  47. package/stores/documents/documentStore/sync/syncSeededCreate.js.map +1 -1
  48. package/stores/documents/documentStore/sync/syncShared.js +12 -8
  49. package/stores/documents/documentStore/sync/syncShared.js.map +1 -1
  50. package/workflows/container-contents/container-state/create/createAdoption.js +1 -2
  51. package/workflows/container-contents/container-state/create/createAdoption.js.map +1 -1
  52. package/workflows/container-contents/container-state/create/createWithMetadata.js +1 -2
  53. package/workflows/container-contents/container-state/create/createWithMetadata.js.map +1 -1
  54. package/workflows/container-contents/container-state/create/createWithMetadataPlan.js +1 -2
  55. package/workflows/container-contents/container-state/create/createWithMetadataPlan.js.map +1 -1
  56. package/workflows/container-contents/container-state/move/moveIntentSync.js +1 -2
  57. package/workflows/container-contents/container-state/move/moveIntentSync.js.map +1 -1
  58. package/workflows/container-contents/container-state/purge/purgeTreeScope.js +1 -2
  59. package/workflows/container-contents/container-state/purge/purgeTreeScope.js.map +1 -1
  60. package/workflows/container-contents/container-state/remote.js +3 -4
  61. package/workflows/container-contents/container-state/remote.js.map +1 -1
  62. package/workflows/container-contents/container-state/share/groupGrantVerification.js +1 -2
  63. package/workflows/container-contents/container-state/share/groupGrantVerification.js.map +1 -1
  64. package/workflows/container-contents/container-state/share/index.js +2 -3
  65. package/workflows/container-contents/container-state/share/index.js.map +1 -1
  66. package/workflows/container-contents/container-state/types.js.map +1 -1
  67. package/workflows/container-contents/documentLinks/documentLinksMove.js +4 -2
  68. package/workflows/container-contents/documentLinks/documentLinksMove.js.map +1 -1
  69. package/workflows/container-contents/documentLinks/index.js +3 -2
  70. package/workflows/container-contents/documentLinks/index.js.map +1 -1
  71. package/workflows/container-contents/index.d.ts +1 -1
  72. package/workflows/container-contents/index.js +1 -1
  73. package/workflows/container-contents/index.js.map +1 -1
  74. package/workflows/container-contents/metadata/index.d.ts +1 -1
  75. package/workflows/container-contents/metadata/index.js.map +1 -1
  76. package/workflows/container-contents/metadata/metadataRemoteSync.d.ts +6 -8
  77. package/workflows/container-contents/metadata/metadataRemoteSync.js +14 -9
  78. package/workflows/container-contents/metadata/metadataRemoteSync.js.map +1 -1
  79. package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js +1 -2
  80. package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js.map +1 -1
  81. package/workflows/container-contents/remoteHydration/index.js +1 -2
  82. package/workflows/container-contents/remoteHydration/index.js.map +1 -1
  83. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +4 -2
  84. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
  85. package/workflows/container-contents/remoteHydration/types.d.ts +1 -1
  86. package/workflows/container-contents/remoteHydration/types.js.map +1 -1
  87. package/workflows/container-contents/runtime.d.ts +13 -2
  88. package/workflows/container-contents/runtime.js +33 -21
  89. package/workflows/container-contents/runtime.js.map +1 -1
  90. package/workflows/container-contents/syncLane.d.ts +1 -1
  91. package/workflows/container-contents/syncLane.js.map +1 -1
  92. package/workflows/container-contents/tombstones/documentPurge.d.ts +2 -3
  93. package/workflows/container-contents/tombstones/documentPurge.js +1 -2
  94. package/workflows/container-contents/tombstones/documentPurge.js.map +1 -1
  95. package/workflows/container-contents/tombstones/documentTombstoneEvidence.js +3 -2
  96. package/workflows/container-contents/tombstones/documentTombstoneEvidence.js.map +1 -1
  97. package/workflows/documents/create/index.d.ts +5 -42
  98. package/workflows/documents/create/index.js +12 -1
  99. package/workflows/documents/create/index.js.map +1 -1
  100. package/workflows/documents/create/remoteDocumentCreateRequest.d.ts +47 -0
  101. package/workflows/documents/create/remoteDocumentCreateRequest.js +2 -0
  102. package/workflows/documents/create/remoteDocumentCreateRequest.js.map +1 -0
  103. package/workflows/documents/index.d.ts +6 -5
  104. package/workflows/documents/index.js +2 -3
  105. package/workflows/documents/index.js.map +1 -1
  106. package/workflows/documents/remote/remoteDocumentCollaborators.d.ts +6 -4
  107. package/workflows/documents/remote/remoteDocumentCollaborators.js.map +1 -1
  108. package/workflows/documents/remote/remoteDocumentService.d.ts +12 -5
  109. package/workflows/documents/remote/remoteDocumentService.js +14 -4
  110. package/workflows/documents/remote/remoteDocumentService.js.map +1 -1
  111. package/workflows/documents/runtime.d.ts +12 -1
  112. package/workflows/documents/runtime.js +24 -16
  113. package/workflows/documents/runtime.js.map +1 -1
  114. package/workflows/documents/sync/index.js +18 -6
  115. package/workflows/documents/sync/index.js.map +1 -1
  116. package/workflows/documents/sync/readOnlySync.js.map +1 -1
  117. package/workflows/documents/sync/{readOnlySync.d.ts → remoteDocumentSyncPass.d.ts} +18 -18
  118. package/workflows/documents/sync/remoteDocumentSyncPass.js +2 -0
  119. package/workflows/documents/sync/remoteDocumentSyncPass.js.map +1 -0
  120. package/workflows/documents/sync/syncAttemptPlanning.js.map +1 -1
  121. package/workflows/documents/sync/syncLane.d.ts +1 -1
  122. package/workflows/documents/sync/syncLane.js.map +1 -1
  123. package/workflows/documents/sync/syncSubmittedResult.js.map +1 -1
  124. package/workflows/documents/syncFailures/syncAbandon.js.map +1 -1
  125. package/workflows/documents/syncFailures/syncRepairAccess.js.map +1 -1
  126. package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js.map +1 -1
  127. package/workflows/documents/syncRekeys/syncContainerRekeyPreparation.js +4 -3
  128. package/workflows/documents/syncRekeys/syncContainerRekeyPreparation.js.map +1 -1
  129. package/workflows/documents/syncRekeys/syncContainerRekeys.js.map +1 -1
  130. package/workflows/organizations/currentOrganizationAuthority.d.ts +1 -2
  131. package/workflows/organizations/currentOrganizationAuthority.js.map +1 -1
  132. package/workflows/organizations/groupMetadata/groupMetadataRuntime.d.ts +5 -4
  133. package/workflows/organizations/groupMetadata/groupMetadataRuntime.js +2 -4
  134. package/workflows/organizations/groupMetadata/groupMetadataRuntime.js.map +1 -1
  135. package/workflows/organizations/groupMetadata/runtimeGroupMetadataAuthority.js +1 -2
  136. package/workflows/organizations/groupMetadata/runtimeGroupMetadataAuthority.js.map +1 -1
  137. package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js.map +1 -1
  138. package/workflows/organizations/groupShare/currentSharePrincipalPolicy.d.ts +1 -2
  139. package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js +2 -2
  140. package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js.map +1 -1
  141. package/workflows/organizations/groupShare/runtimeCurrentGroupShare.js +4 -8
  142. package/workflows/organizations/groupShare/runtimeCurrentGroupShare.js.map +1 -1
  143. package/workflows/organizations/memberships/leaveRequestMembersEvidence.js +2 -3
  144. package/workflows/organizations/memberships/leaveRequestMembersEvidence.js.map +1 -1
  145. package/workflows/organizations/principalMutations/currentOrganizationMutationRetention.js.map +1 -1
  146. package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js +2 -2
  147. package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js.map +1 -1
  148. package/workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation.js +2 -2
  149. package/workflows/organizations/principalMutations/runtimeCurrentOrganizationMutation.js.map +1 -1
  150. package/workflows/principals/index.d.ts +1 -0
  151. package/workflows/principals/index.js.map +1 -1
  152. package/workflows/principals/principalPolicyService.d.ts +64 -0
  153. package/workflows/principals/principalPolicyService.js +117 -0
  154. package/workflows/principals/principalPolicyService.js.map +1 -0
  155. package/workflows/principals/runtimePolicyRecovery.d.ts +13 -10
  156. package/workflows/principals/runtimePolicyRecovery.js +9 -17
  157. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  158. package/workflows/principals/runtimeProjectionPolicyRecovery.js +7 -8
  159. package/workflows/principals/runtimeProjectionPolicyRecovery.js.map +1 -1
  160. package/data/principals/principalHistoryRuntime.js +0 -12
  161. package/data/principals/principalHistoryRuntime.js.map +0 -1
  162. package/workflows/documents/sync/index.d.ts +0 -3
  163. package/workflows/organizations/principalMutations/currentPrincipalMutationLease.d.ts +0 -16
  164. package/workflows/organizations/principalMutations/currentPrincipalMutationLease.js +0 -39
  165. package/workflows/organizations/principalMutations/currentPrincipalMutationLease.js.map +0 -1
  166. package/workflows/principals/runtimePolicyWarmer.d.ts +0 -26
  167. package/workflows/principals/runtimePolicyWarmer.js +0 -48
  168. package/workflows/principals/runtimePolicyWarmer.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"runtimePolicyRecovery.js","sourceRoot":"","sources":["runtimePolicyRecovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EACL,mCAAmC,GAIpC,MAAM,+CAA+C,CAAC;AAEvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EACL,qCAAqC,GAEtC,MAAM,kDAAkD,CAAC;AAK1D,OAAO,EACL,iCAAiC,EACjC,+BAA+B,GAChC,MAAM,iDAAiD,CAAC;AAEzD,OAAO,EACL,4BAA4B,GAE7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,mCAAmC,EAAE,MAAM,mDAAmD,CAAC;AACxG,OAAO,EAAE,mCAAmC,EAAE,MAAM,sDAAsD,CAAC;AAC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QAAE,OAAO;IAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC;IAC/C,IACE,CAAC,KAAK,CAAC,SAAS;QAChB,CAAC,MAAM,KAAK,SAAS;YACnB,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;gBAC5B,MAAM,IAAI,CAAC;gBACX,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;QAE1C,MAAM,IAAI,uBAAuB,CAC/B,eAAe,EACf,iEAAiE,CAClE,CAAC;AACN,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n assertProjectionVerificationCurrent,\n type PrincipalPolicyResolveRequest,\n type ReferencedPrincipalPolicyWarmer,\n type ResolvedPrincipalPolicyEvidence,\n} from \"../../data/keyingProjectionVerification/types\";\nimport type { PrincipalHistoryProtectionLease } from \"../../data/principals/principalHistoryProtection\";\nimport { readPrincipalHistoryProtection } from \"../../data/principals/principalHistoryRuntime\";\nimport {\n getOrCreatePrincipalPolicyCoordinator,\n type PrincipalPolicyCoordinator,\n} from \"../../data/principals/principalPolicyCoordinator\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport type { RecoveredPrincipalHistoryPage } from \"./historyRecovery/loadRecoveredPrincipalHistoryPage\";\nimport {\n PrincipalHistoryRecoveryRaceError,\n PrincipalPolicyHistoryReadError,\n} from \"./historyRecovery/principalHistoryRecoveryTypes\";\nimport type { ScopedPrincipalPolicyRecovery } from \"./historyRecovery/recoverScopedPrincipalPolicyHistory\";\nimport {\n apiPrincipalPolicyPageReader,\n type PrincipalPolicyHistoryReader,\n} from \"./principalPolicyHistoryReader\";\nimport { createPrincipalCurrentRecoveryBatch } from \"./recoveryOperation/principalCurrentRecoveryBatch\";\nimport { recoverWithPrincipalLocalPreference } from \"./recoveryOperation/principalRecoveryLocalPreference\";\nimport { resumeAfterSupersededStage } from \"./recoveryOperation/supersededStageResume\";\n\nexport interface PrincipalPolicyRecoveryRuntime {\n readonly apiClient: Partial<PrincipalPolicyHistoryReader>;\n readonly infra: { readonly execSql: ExecSql };\n readonly state?: { readonly online: boolean } | undefined;\n readonly util: { readonly reportSecurityIncident: SecurityIncidentReporter };\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly withPrincipalHistoryProtection?:\n | PrincipalHistoryProtectionLease\n | undefined;\n}\n\n/** Keep the private recovery key inside its runtime lease while resolving cited evidence. */\nexport function createRuntimePrincipalPolicyResolver(\n runtime: PrincipalPolicyRecoveryRuntime,\n options: { readonly preferLocalCurrent?: boolean } = {},\n): ReferencedPrincipalPolicyWarmer[\"resolveReference\"] {\n const resolve = createRuntimePrincipalPolicyCurrentResolver(runtime);\n return resolve\n ? (input) =>\n resolve({ ...input, preferLocalCurrent: options.preferLocalCurrent })\n : undefined;\n}\n\nexport interface ResolvedPrincipalPolicyCurrent\n extends ResolvedPrincipalPolicyEvidence {\n readonly current: PrincipalPolicyPageCurrent;\n /** Rows end at the selected reference; current/policy may describe a newer recovered head. */\n readonly historyPage?: RecoveredPrincipalHistoryPage | undefined;\n}\n\ninterface PrincipalPolicyCurrentRequest\n extends Omit<PrincipalPolicyResolveRequest, \"reference\"> {\n readonly reference?: PrincipalPolicyResolveRequest[\"reference\"] | undefined;\n /** A read-model caller has selected this exact signed head; not a freshness read. */\n readonly preferLocalCurrent?: boolean | undefined;\n readonly historyPage?: { readonly beforeVersion?: number } | undefined;\n}\n\ntype PrincipalCurrentRecoveryBatch = ReturnType<\n typeof createPrincipalCurrentRecoveryBatch\n>;\n\n/**\n * Operation batches belong to the database's coordinator, keyed by the\n * operation token, so every resolver and warmer one operation creates for that\n * database shares one authenticated view. A batch dies with its token (the end\n * of the pass or workflow) and its entries with any organization hint.\n */\nconst operationBatches = new WeakMap<\n PrincipalPolicyCoordinator,\n WeakMap<object, PrincipalCurrentRecoveryBatch>\n>();\n\nfunction operationRecoveryBatch(\n coordinator: PrincipalPolicyCoordinator,\n operation: object | undefined,\n): PrincipalCurrentRecoveryBatch {\n if (!operation) return createPrincipalCurrentRecoveryBatch();\n let batches = operationBatches.get(coordinator);\n if (!batches) {\n batches = new WeakMap();\n operationBatches.set(coordinator, batches);\n }\n let batch = batches.get(operation);\n if (!batch) {\n batch = createPrincipalCurrentRecoveryBatch();\n batches.set(operation, batch);\n }\n return batch;\n}\n\n/** One recovery attempt for a resolver request through the operation's batch. */\nfunction recoverPolicyCurrent(\n batch: ReturnType<typeof createPrincipalCurrentRecoveryBatch>,\n options: Parameters<\n ReturnType<typeof createPrincipalCurrentRecoveryBatch>[\"discover\"]\n >[0],\n input: PrincipalPolicyCurrentRequest,\n): Promise<ScopedPrincipalPolicyRecovery> {\n return input.reference\n ? recoverWithPrincipalLocalPreference(\n batch.recover,\n {\n ...options,\n reference: input.reference,\n historyPage: input.historyPage,\n },\n input.preferLocalCurrent === true || input.preferLocalHistory === true,\n input.preferLocalHistory === true,\n )\n : batch.discover(options);\n}\n\n/** Keep current artifacts with their verified evidence and private runtime lifetime. */\nexport function createRuntimePrincipalPolicyCurrentResolver(\n runtime: PrincipalPolicyRecoveryRuntime,\n):\n | ((\n input: PrincipalPolicyCurrentRequest,\n ) => Promise<ResolvedPrincipalPolicyCurrent>)\n | undefined {\n const lease = readPrincipalHistoryProtection(runtime);\n const historyReader = apiPrincipalPolicyPageReader(runtime.apiClient);\n if (!lease || !historyReader) return undefined;\n const coordinator = getOrCreatePrincipalPolicyCoordinator(\n runtime.infra.execSql,\n );\n return (input) =>\n coordinator.queueRecovery(input.organizationId, () =>\n runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: input.reference?.principalId ?? input.organizationId,\n objectKind: \"principal\",\n operation: \"principal.policy.recover\",\n organizationId: input.organizationId,\n },\n () =>\n lease(async ({ protection, stillCurrent: leaseCurrent }) => {\n const stillCurrent = () =>\n leaseCurrent() && input.stillCurrent?.() !== false;\n assertProjectionVerificationCurrent(stillCurrent);\n assertHistoryPageRequest(input);\n const offline = runtime.state?.online === false;\n try {\n const options = {\n historyReader,\n execSql: runtime.infra.execSql,\n offline,\n organizationId: input.organizationId,\n protection,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n stillCurrent,\n };\n const result = await resumeAfterSupersededStage(\n () =>\n recoverPolicyCurrent(\n operationRecoveryBatch(coordinator, input.recoveryBatch),\n options,\n input,\n ),\n stillCurrent,\n );\n // Reused evidence stays bound to every producer lifetime.\n const resultCurrent = () =>\n stillCurrent() && result.stillCurrent();\n assertProjectionVerificationCurrent(resultCurrent);\n return {\n current: result.current,\n organizationId: input.organizationId,\n policy: result.policy,\n dependencies: result.dependencies,\n historyPage: result.historyPage,\n stillCurrent: resultCurrent,\n };\n } catch (error) {\n assertProjectionVerificationCurrent(stillCurrent);\n if (\n error instanceof PrincipalPolicyHistoryReadError ||\n error instanceof PrincipalHistoryRecoveryRaceError ||\n (error instanceof KeyingVerificationError &&\n error.code === \"missing_dependency\")\n )\n throw new ProjectionDependencyUnavailableError(error.message);\n throw error;\n }\n }),\n ),\n );\n}\n\nfunction assertHistoryPageRequest(input: PrincipalPolicyCurrentRequest) {\n if (!input.historyPage) return;\n const before = input.historyPage.beforeVersion;\n if (\n !input.reference ||\n (before !== undefined &&\n (!Number.isSafeInteger(before) ||\n before <= 1 ||\n before > input.reference.version + 1))\n )\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"History display requires a selected head and an in-range cursor\",\n );\n}\n"]}
1
+ {"version":3,"file":"runtimePolicyRecovery.js","sourceRoot":"","sources":["runtimePolicyRecovery.ts"],"names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AAoC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAChE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CACL,CACF,CAAC;AACN,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAoC;IACpE,IAAI,CAAC,KAAK,CAAC,WAAW;QAAE,OAAO;IAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC;IAC/C,IACE,CAAC,KAAK,CAAC,SAAS;QAChB,CAAC,MAAM,KAAK,SAAS;YACnB,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;gBAC5B,MAAM,IAAI,CAAC;gBACX,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;QAE1C,MAAM,IAAI,uBAAuB,CAC/B,eAAe,EACf,iEAAiE,CAClE,CAAC;AACN,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n assertProjectionVerificationCurrent,\n type PrincipalPolicyResolveRequest,\n type ResolvedPrincipalPolicyEvidence,\n} from \"../../data/keyingProjectionVerification/types\";\nimport type { PrincipalHistoryProtectionLease } from \"../../data/principals/principalHistoryProtection\";\nimport {\n getOrCreatePrincipalPolicyCoordinator,\n type PrincipalPolicyCoordinator,\n} from \"../../data/principals/principalPolicyCoordinator\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport type { RecoveredPrincipalHistoryPage } from \"./historyRecovery/loadRecoveredPrincipalHistoryPage\";\nimport {\n PrincipalHistoryRecoveryRaceError,\n PrincipalPolicyHistoryReadError,\n} from \"./historyRecovery/principalHistoryRecoveryTypes\";\nimport type { ScopedPrincipalPolicyRecovery } from \"./historyRecovery/recoverScopedPrincipalPolicyHistory\";\nimport {\n apiPrincipalPolicyPageReader,\n type PrincipalPolicyHistoryReader,\n} from \"./principalPolicyHistoryReader\";\nimport { createPrincipalCurrentRecoveryBatch } from \"./recoveryOperation/principalCurrentRecoveryBatch\";\nimport { recoverWithPrincipalLocalPreference } from \"./recoveryOperation/principalRecoveryLocalPreference\";\nimport { resumeAfterSupersededStage } from \"./recoveryOperation/supersededStageResume\";\n\n/**\n * The slices of one runtime snapshot a `PrincipalPolicyService` reads. Each\n * service method reads them when it is called and its resolvers per request,\n * as the snapshot's other consumers do. The lease is the snapshot's bound\n * history custody; the service never binds one itself.\n */\nexport interface PrincipalPolicyCollaborators {\n readonly apiClient: Partial<PrincipalPolicyHistoryReader>;\n readonly infra: { readonly execSql: ExecSql };\n readonly state?: { readonly online: boolean } | undefined;\n readonly util: {\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly log?: ((message: string) => void) | undefined;\n };\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly withPrincipalHistoryProtection?:\n | PrincipalHistoryProtectionLease\n | undefined;\n}\n\nexport interface ResolvedPrincipalPolicyCurrent\n extends ResolvedPrincipalPolicyEvidence {\n readonly current: PrincipalPolicyPageCurrent;\n /** Rows end at the selected reference; current/policy may describe a newer recovered head. */\n readonly historyPage?: RecoveredPrincipalHistoryPage | undefined;\n}\n\nexport interface PrincipalPolicyCurrentRequest\n extends Omit<PrincipalPolicyResolveRequest, \"reference\"> {\n readonly reference?: PrincipalPolicyResolveRequest[\"reference\"] | undefined;\n /** A read-model caller has selected this exact signed head; not a freshness read. */\n readonly preferLocalCurrent?: boolean | undefined;\n readonly historyPage?: { readonly beforeVersion?: number } | undefined;\n}\n\nexport type PrincipalPolicyCurrentResolver = (\n input: PrincipalPolicyCurrentRequest,\n) => Promise<ResolvedPrincipalPolicyCurrent>;\n\ntype PrincipalCurrentRecoveryBatch = ReturnType<\n typeof createPrincipalCurrentRecoveryBatch\n>;\n\n/**\n * Operation batches belong to the database's coordinator, keyed by the\n * operation token, so every resolver and warmer one operation creates for that\n * database shares one authenticated view. A batch dies with its token (the end\n * of the pass or workflow) and its entries with any organization hint.\n */\nconst operationBatches = new WeakMap<\n PrincipalPolicyCoordinator,\n WeakMap<object, PrincipalCurrentRecoveryBatch>\n>();\n\nfunction operationRecoveryBatch(\n coordinator: PrincipalPolicyCoordinator,\n operation: object | undefined,\n): PrincipalCurrentRecoveryBatch {\n if (!operation) return createPrincipalCurrentRecoveryBatch();\n let batches = operationBatches.get(coordinator);\n if (!batches) {\n batches = new WeakMap();\n operationBatches.set(coordinator, batches);\n }\n let batch = batches.get(operation);\n if (!batch) {\n batch = createPrincipalCurrentRecoveryBatch();\n batches.set(operation, batch);\n }\n return batch;\n}\n\n/** One recovery attempt for a resolver request through the operation's batch. */\nfunction recoverPolicyCurrent(\n batch: ReturnType<typeof createPrincipalCurrentRecoveryBatch>,\n options: Parameters<\n ReturnType<typeof createPrincipalCurrentRecoveryBatch>[\"discover\"]\n >[0],\n input: PrincipalPolicyCurrentRequest,\n): Promise<ScopedPrincipalPolicyRecovery> {\n return input.reference\n ? recoverWithPrincipalLocalPreference(\n batch.recover,\n {\n ...options,\n reference: input.reference,\n historyPage: input.historyPage,\n },\n input.preferLocalCurrent === true || input.preferLocalHistory === true,\n input.preferLocalHistory === true,\n )\n : batch.discover(options);\n}\n\n/** Keep current artifacts with their verified evidence and private snapshot lifetime. */\nexport function createPrincipalPolicyCurrentResolver(\n policies: PrincipalPolicyCollaborators,\n): PrincipalPolicyCurrentResolver | undefined {\n const lease = policies.withPrincipalHistoryProtection;\n const historyReader = apiPrincipalPolicyPageReader(policies.apiClient);\n if (!lease || !historyReader) return undefined;\n const coordinator = getOrCreatePrincipalPolicyCoordinator(\n policies.infra.execSql,\n );\n return (input) =>\n coordinator.queueRecovery(input.organizationId, () =>\n runWithSecurityIncidentReporting(\n policies.util.reportSecurityIncident,\n {\n objectId: input.reference?.principalId ?? input.organizationId,\n objectKind: \"principal\",\n operation: \"principal.policy.recover\",\n organizationId: input.organizationId,\n },\n () =>\n lease(async ({ protection, stillCurrent: leaseCurrent }) => {\n const stillCurrent = () =>\n leaseCurrent() && input.stillCurrent?.() !== false;\n assertProjectionVerificationCurrent(stillCurrent);\n assertHistoryPageRequest(input);\n const offline = policies.state?.online === false;\n try {\n const options = {\n historyReader,\n execSql: policies.infra.execSql,\n offline,\n organizationId: input.organizationId,\n protection,\n resolveTrustedUserIdentity: policies.resolveTrustedUserIdentity,\n stillCurrent,\n };\n const result = await resumeAfterSupersededStage(\n () =>\n recoverPolicyCurrent(\n operationRecoveryBatch(coordinator, input.recoveryBatch),\n options,\n input,\n ),\n stillCurrent,\n );\n // Reused evidence stays bound to every producer lifetime.\n const resultCurrent = () =>\n stillCurrent() && result.stillCurrent();\n assertProjectionVerificationCurrent(resultCurrent);\n return {\n current: result.current,\n organizationId: input.organizationId,\n policy: result.policy,\n dependencies: result.dependencies,\n historyPage: result.historyPage,\n stillCurrent: resultCurrent,\n };\n } catch (error) {\n assertProjectionVerificationCurrent(stillCurrent);\n if (\n error instanceof PrincipalPolicyHistoryReadError ||\n error instanceof PrincipalHistoryRecoveryRaceError ||\n (error instanceof KeyingVerificationError &&\n error.code === \"missing_dependency\")\n )\n throw new ProjectionDependencyUnavailableError(error.message);\n throw error;\n }\n }),\n ),\n );\n}\n\nfunction assertHistoryPageRequest(input: PrincipalPolicyCurrentRequest) {\n if (!input.historyPage) return;\n const before = input.historyPage.beforeVersion;\n if (\n !input.reference ||\n (before !== undefined &&\n (!Number.isSafeInteger(before) ||\n before <= 1 ||\n before > input.reference.version + 1))\n )\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"History display requires a selected head and an in-range cursor\",\n );\n}\n"]}
@@ -2,7 +2,6 @@ import { KeyingVerificationError } from "../../internal/crypto/index.js";
2
2
  import { ProjectionDependencyUnavailableError } from "../../data/keyingProjectionVerification/dependencyUnavailable.js";
3
3
  import { runWithSecurityIncidentReporting } from "../../data/keyingProjectionVerification/error.js";
4
4
  import { assertProjectionVerificationCurrent, } from "../../data/keyingProjectionVerification/types.js";
5
- import { readPrincipalHistoryProtection } from "../../data/principals/principalHistoryRuntime.js";
6
5
  import { getOrCreatePrincipalPolicyCoordinator } from "../../data/principals/principalPolicyCoordinator.js";
7
6
  import { PrincipalPolicyHistoryReadError } from "./historyRecovery/principalHistoryRecoveryTypes.js";
8
7
  import { apiProjectionPolicyHistoryReader } from "./principalPolicyHistoryReader.js";
@@ -19,12 +18,12 @@ async function recoverWithOutageFallback(options) {
19
18
  return recoverProjectionPolicyHistory({ ...options, offline: true });
20
19
  }
21
20
  }
22
- export function createRuntimeProjectionPolicyResolver(runtime) {
23
- const lease = readPrincipalHistoryProtection(runtime);
24
- const historyReader = apiProjectionPolicyHistoryReader(runtime.apiClient);
21
+ export function createProjectionPolicyHistoryResolver(collaborators) {
22
+ const lease = collaborators.withPrincipalHistoryProtection;
23
+ const historyReader = apiProjectionPolicyHistoryReader(collaborators.apiClient);
25
24
  if (!lease || !historyReader)
26
25
  return undefined;
27
- return (input) => getOrCreatePrincipalPolicyCoordinator(runtime.infra.execSql).queueRecovery(input.organizationId, () => runWithSecurityIncidentReporting(runtime.util.reportSecurityIncident, {
26
+ return (input) => getOrCreatePrincipalPolicyCoordinator(collaborators.infra.execSql).queueRecovery(input.organizationId, () => runWithSecurityIncidentReporting(collaborators.util.reportSecurityIncident, {
28
27
  objectId: input.organizationId,
29
28
  objectKind: "principal",
30
29
  operation: "principal.projection.recover",
@@ -36,11 +35,11 @@ export function createRuntimeProjectionPolicyResolver(runtime) {
36
35
  const policies = await recoverWithOutageFallback({
37
36
  ...input,
38
37
  historyReader,
39
- execSql: runtime.infra.execSql,
38
+ execSql: collaborators.infra.execSql,
40
39
  protection,
41
40
  stillCurrent,
42
- offline: runtime.state?.online === false,
43
- resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,
41
+ offline: collaborators.state?.online === false,
42
+ resolveTrustedUserIdentity: collaborators.resolveTrustedUserIdentity,
44
43
  });
45
44
  return { policies, stillCurrent };
46
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"runtimeProjectionPolicyRecovery.js","sourceRoot":"","sources":["runtimeProjectionPolicyRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EACL,mCAAmC,GAEpC,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EAAE,qCAAqC,EAAE,MAAM,kDAAkD,CAAC;AACzG,OAAO,EAAE,+BAA+B,EAAE,MAAM,iDAAiD,CAAC;AAClG,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAEL,8BAA8B,GAC/B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAGxF,KAAK,UAAU,yBAAyB,CACtC,OAA+C;IAE/C,IAAI,CAAC;QACH,OAAO,MAAM,8BAA8B,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,yBAAyB,CAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QACtE,OAAO,8BAA8B,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qCAAqC,CACnD,OAAuC;IAE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AC,KAAK,YAAY,uBAAuB;oBACvC,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC;gBAEtC,MAAM,IAAI,oCAAoC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAChE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CACL,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n assertProjectionVerificationCurrent,\n type ReferencedPrincipalPolicyWarmer,\n} from \"../../data/keyingProjectionVerification/types\";\nimport { readPrincipalHistoryProtection } from \"../../data/principals/principalHistoryRuntime\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../data/principals/principalPolicyCoordinator\";\nimport { PrincipalPolicyHistoryReadError } from \"./historyRecovery/principalHistoryRecoveryTypes\";\nimport { apiProjectionPolicyHistoryReader } from \"./principalPolicyHistoryReader\";\nimport {\n type ProjectionPolicyHistoryRecoveryOptions,\n recoverProjectionPolicyHistory,\n} from \"./publicHistory/recoverProjectionPolicyHistory\";\nimport { isPrincipalRecoveryOutage } from \"./recoveryOperation/principalRecoveryOutage\";\nimport type { PrincipalPolicyRecoveryRuntime } from \"./runtimePolicyRecovery\";\n\nasync function recoverWithOutageFallback(\n options: ProjectionPolicyHistoryRecoveryOptions,\n) {\n try {\n return await recoverProjectionPolicyHistory(options);\n } catch (error) {\n assertProjectionVerificationCurrent(options.stillCurrent);\n if (options.offline || !isPrincipalRecoveryOutage(error)) throw error;\n return recoverProjectionPolicyHistory({ ...options, offline: true });\n }\n}\n\nexport function createRuntimeProjectionPolicyResolver(\n runtime: PrincipalPolicyRecoveryRuntime,\n): ReferencedPrincipalPolicyWarmer[\"resolveProjectionHistory\"] {\n const lease = readPrincipalHistoryProtection(runtime);\n const historyReader = apiProjectionPolicyHistoryReader(runtime.apiClient);\n if (!lease || !historyReader) return undefined;\n return (input) =>\n getOrCreatePrincipalPolicyCoordinator(runtime.infra.execSql).queueRecovery(\n input.organizationId,\n () =>\n runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: input.organizationId,\n objectKind: \"principal\",\n operation: \"principal.projection.recover\",\n organizationId: input.organizationId,\n },\n () =>\n lease(async ({ protection, stillCurrent: leaseCurrent }) => {\n const stillCurrent = () =>\n leaseCurrent() && input.stillCurrent?.() !== false;\n assertProjectionVerificationCurrent(stillCurrent);\n try {\n const policies = await recoverWithOutageFallback({\n ...input,\n historyReader,\n execSql: runtime.infra.execSql,\n protection,\n stillCurrent,\n offline: runtime.state?.online === false,\n resolveTrustedUserIdentity:\n runtime.resolveTrustedUserIdentity,\n });\n return { policies, stillCurrent };\n } catch (error) {\n assertProjectionVerificationCurrent(stillCurrent);\n if (\n error instanceof PrincipalPolicyHistoryReadError ||\n (error instanceof KeyingVerificationError &&\n error.code === \"missing_dependency\")\n )\n throw new ProjectionDependencyUnavailableError(error.message);\n throw error;\n }\n }),\n ),\n );\n}\n"]}
1
+ {"version":3,"file":"runtimeProjectionPolicyRecovery.js","sourceRoot":"","sources":["runtimeProjectionPolicyRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EACL,mCAAmC,GAEpC,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,qCAAqC,EAAE,MAAM,kDAAkD,CAAC;AACzG,OAAO,EAAE,+BAA+B,EAAE,MAAM,iDAAiD,CAAC;AAClG,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,EAEL,8BAA8B,GAC/B,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,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AAY,CAAC,CAAC;QAClD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,yBAAyB,CAAC;gBAC/C,GAAG,KAAK;gBACR,aAAa;gBACb,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,OAAO;gBACpC,UAAU;gBACV,YAAY;gBACZ,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK;gBAC9C,0BAA0B,EACxB,aAAa,CAAC,0BAA0B;aAC3C,CAAC,CAAC;YACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,mCAAmC,CAAC,YAAY,CAAC,CAAC;YAClD,IACE,KAAK,YAAY,+BAA+B;gBAChD,CAAC,KAAK,YAAY,uBAAuB;oBACvC,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC;gBAEtC,MAAM,IAAI,oCAAoC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAChE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CACL,CACF,CAAC;AACN,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n assertProjectionVerificationCurrent,\n type ReferencedPrincipalPolicyWarmer,\n} from \"../../data/keyingProjectionVerification/types\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../data/principals/principalPolicyCoordinator\";\nimport { PrincipalPolicyHistoryReadError } from \"./historyRecovery/principalHistoryRecoveryTypes\";\nimport { apiProjectionPolicyHistoryReader } from \"./principalPolicyHistoryReader\";\nimport {\n type ProjectionPolicyHistoryRecoveryOptions,\n recoverProjectionPolicyHistory,\n} from \"./publicHistory/recoverProjectionPolicyHistory\";\nimport { isPrincipalRecoveryOutage } from \"./recoveryOperation/principalRecoveryOutage\";\nimport type { PrincipalPolicyCollaborators } from \"./runtimePolicyRecovery\";\n\nasync function recoverWithOutageFallback(\n options: ProjectionPolicyHistoryRecoveryOptions,\n) {\n try {\n return await recoverProjectionPolicyHistory(options);\n } catch (error) {\n assertProjectionVerificationCurrent(options.stillCurrent);\n if (options.offline || !isPrincipalRecoveryOutage(error)) throw error;\n return recoverProjectionPolicyHistory({ ...options, offline: true });\n }\n}\n\nexport function createProjectionPolicyHistoryResolver(\n collaborators: PrincipalPolicyCollaborators,\n): ReferencedPrincipalPolicyWarmer[\"resolveProjectionHistory\"] {\n const lease = collaborators.withPrincipalHistoryProtection;\n const historyReader = apiProjectionPolicyHistoryReader(\n collaborators.apiClient,\n );\n if (!lease || !historyReader) return undefined;\n return (input) =>\n getOrCreatePrincipalPolicyCoordinator(\n collaborators.infra.execSql,\n ).queueRecovery(input.organizationId, () =>\n runWithSecurityIncidentReporting(\n collaborators.util.reportSecurityIncident,\n {\n objectId: input.organizationId,\n objectKind: \"principal\",\n operation: \"principal.projection.recover\",\n organizationId: input.organizationId,\n },\n () =>\n lease(async ({ protection, stillCurrent: leaseCurrent }) => {\n const stillCurrent = () =>\n leaseCurrent() && input.stillCurrent?.() !== false;\n assertProjectionVerificationCurrent(stillCurrent);\n try {\n const policies = await recoverWithOutageFallback({\n ...input,\n historyReader,\n execSql: collaborators.infra.execSql,\n protection,\n stillCurrent,\n offline: collaborators.state?.online === false,\n resolveTrustedUserIdentity:\n collaborators.resolveTrustedUserIdentity,\n });\n return { policies, stillCurrent };\n } catch (error) {\n assertProjectionVerificationCurrent(stillCurrent);\n if (\n error instanceof PrincipalPolicyHistoryReadError ||\n (error instanceof KeyingVerificationError &&\n error.code === \"missing_dependency\")\n )\n throw new ProjectionDependencyUnavailableError(error.message);\n throw error;\n }\n }),\n ),\n );\n}\n"]}
@@ -1,12 +0,0 @@
1
- const leases = new WeakMap();
2
- /** Internal workflow adapters carry custody without exposing it on public views. */
3
- export function readPrincipalHistoryProtection(runtime) {
4
- return leases.get(runtime) ?? runtime.withPrincipalHistoryProtection;
5
- }
6
- export function inheritPrincipalHistoryProtection(source, target) {
7
- const lease = readPrincipalHistoryProtection(source);
8
- if (lease)
9
- leases.set(target, lease);
10
- return target;
11
- }
12
- //# sourceMappingURL=principalHistoryRuntime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"principalHistoryRuntime.js","sourceRoot":"","sources":["principalHistoryRuntime.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAG,IAAI,OAAO,EAA2C,CAAC;AAEtE,oFAAoF;AACpF,MAAM,UAAU,8BAA8B,CAC5C,OAIC;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,8BAA8B,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,MAAc,EACd,MAAS;IAET,MAAM,KAAK,GAAG,8BAA8B,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,KAAK;QAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { PrincipalHistoryProtectionLease } from \"./principalHistoryProtection\";\n\nconst leases = new WeakMap<object, PrincipalHistoryProtectionLease>();\n\n/** Internal workflow adapters carry custody without exposing it on public views. */\nexport function readPrincipalHistoryProtection(\n runtime: object & {\n readonly withPrincipalHistoryProtection?:\n | PrincipalHistoryProtectionLease\n | undefined;\n },\n) {\n return leases.get(runtime) ?? runtime.withPrincipalHistoryProtection;\n}\n\nexport function inheritPrincipalHistoryProtection<T extends object>(\n source: object,\n target: T,\n): T {\n const lease = readPrincipalHistoryProtection(source);\n if (lease) leases.set(target, lease);\n return target;\n}\n"]}
@@ -1,3 +0,0 @@
1
- import type { SyncRemoteDocumentResult } from "../../../data/documents/shared/sync/documentSyncTypes.js";
2
- import { type SyncRemoteDocumentInput } from "./readOnlySync.js";
3
- export declare function syncRemoteDocument(input: SyncRemoteDocumentInput): Promise<SyncRemoteDocumentResult | null>;
@@ -1,16 +0,0 @@
1
- import type { PrincipalPolicyPageCurrent } from "../../../internal/api-client/index.js";
2
- import type { PrincipalPolicyHistoryProgressOptions } from "../../../internal/crypto/index.js";
3
- import { type PrincipalPolicyPageReader } from "../../principals/principalPolicyHistoryReader.js";
4
- import { createRuntimePrincipalPolicyCurrentResolver, type PrincipalPolicyRecoveryRuntime } from "../../principals/runtimePolicyRecovery.js";
5
- import type { AcknowledgedPrincipalCurrentInput } from "./retainAcknowledgedPrincipalCurrents.js";
6
- interface CurrentPrincipalMutationLeaseContext {
7
- readonly protection: PrincipalPolicyHistoryProgressOptions;
8
- readonly stillCurrent: () => boolean;
9
- readonly resolveCurrentPolicy: NonNullable<ReturnType<typeof createRuntimePrincipalPolicyCurrentResolver>>;
10
- readonly historyReader: PrincipalPolicyPageReader;
11
- readonly directoryRecovery: (current: PrincipalPolicyPageCurrent) => AcknowledgedPrincipalCurrentInput["recovery"];
12
- }
13
- type CurrentPrincipalMutationLease = <T>(callerCurrent: () => boolean, work: (context: CurrentPrincipalMutationLeaseContext) => Promise<T>) => Promise<T>;
14
- /** One lifetime fence and private custody boundary for every current-policy mutation. */
15
- export declare function createCurrentPrincipalMutationLease(runtime: PrincipalPolicyRecoveryRuntime): CurrentPrincipalMutationLease | undefined;
16
- export {};
@@ -1,39 +0,0 @@
1
- import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
2
- import { readPrincipalHistoryProtection } from "../../../data/principals/principalHistoryRuntime.js";
3
- import { directoryHistoryProtection } from "../../../data/principals/principalHistoryScopeProtection.js";
4
- import { principalPolicyReferenceFromBundle } from "../../../data/principals/principalPolicyAdminSigners.js";
5
- import { apiPrincipalPolicyPageReader, } from "../../principals/principalPolicyHistoryReader.js";
6
- import { createRuntimePrincipalPolicyCurrentResolver, } from "../../principals/runtimePolicyRecovery.js";
7
- /** One lifetime fence and private custody boundary for every current-policy mutation. */
8
- export function createCurrentPrincipalMutationLease(runtime) {
9
- const lease = readPrincipalHistoryProtection(runtime);
10
- const resolveCurrentPolicy = createRuntimePrincipalPolicyCurrentResolver(runtime);
11
- const historyReader = apiPrincipalPolicyPageReader(runtime.apiClient);
12
- if (!lease || !resolveCurrentPolicy || !historyReader)
13
- return undefined;
14
- return async (callerCurrent, work) => lease(async ({ protection, stillCurrent: leaseCurrent }) => {
15
- let active = true;
16
- const stillCurrent = () => active && leaseCurrent() && callerCurrent();
17
- try {
18
- assertProjectionVerificationCurrent(stillCurrent);
19
- const result = await work({
20
- protection,
21
- stillCurrent,
22
- resolveCurrentPolicy,
23
- historyReader,
24
- directoryRecovery: (current) => ({
25
- historyReader,
26
- expectedHead: principalPolicyReferenceFromBundle(current),
27
- protection: directoryHistoryProtection(protection),
28
- resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,
29
- }),
30
- });
31
- assertProjectionVerificationCurrent(stillCurrent);
32
- return result;
33
- }
34
- finally {
35
- active = false;
36
- }
37
- });
38
- }
39
- //# sourceMappingURL=currentPrincipalMutationLease.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentPrincipalMutationLease.js","sourceRoot":"","sources":["currentPrincipalMutationLease.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,8BAA8B,EAAE,MAAM,kDAAkD,CAAC;AAClG,OAAO,EAAE,0BAA0B,EAAE,MAAM,0DAA0D,CAAC;AACtG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sDAAsD,CAAC;AAC1G,OAAO,EACL,4BAA4B,GAE7B,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,2CAA2C,GAE5C,MAAM,wCAAwC,CAAC;AAoBhD,yFAAyF;AACzF,MAAM,UAAU,mCAAmC,CACjD,OAAuC;IAEvC,MAAM,KAAK,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,oBAAoB,GACxB,2CAA2C,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,aAAa,GAAG,4BAA4B,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtE,IAAI,CAAC,KAAK,IAAI,CAAC,oBAAoB,IAAI,CAAC,aAAa;QAAE,OAAO,SAAS,CAAC;IACxE,OAAO,KAAK,EACV,aAA4B,EAC5B,IAAmE,EACvD,EAAE,CACd,KAAK,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,EAAE,EAAE;QACzD,IAAI,MAAM,GAAG,IAAI,CAAC;QAClB,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,MAAM,IAAI,YAAY,EAAE,IAAI,aAAa,EAAE,CAAC;QACvE,IAAI,CAAC;YACH,mCAAmC,CAAC,YAAY,CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC;gBACxB,UAAU;gBACV,YAAY;gBACZ,oBAAoB;gBACpB,aAAa;gBACb,iBAAiB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;oBAC/B,aAAa;oBACb,YAAY,EAAE,kCAAkC,CAAC,OAAO,CAAC;oBACzD,UAAU,EAAE,0BAA0B,CAAC,UAAU,CAAC;oBAClD,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;iBAC/D,CAAC;aACH,CAAC,CAAC;YACH,mCAAmC,CAAC,YAAY,CAAC,CAAC;YAClD,OAAO,MAAM,CAAC;QAChB,CAAC;gBAAS,CAAC;YACT,MAAM,GAAG,KAAK,CAAC;QACjB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport type { PrincipalPolicyHistoryProgressOptions } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { readPrincipalHistoryProtection } from \"../../../data/principals/principalHistoryRuntime\";\nimport { directoryHistoryProtection } from \"../../../data/principals/principalHistoryScopeProtection\";\nimport { principalPolicyReferenceFromBundle } from \"../../../data/principals/principalPolicyAdminSigners\";\nimport {\n apiPrincipalPolicyPageReader,\n type PrincipalPolicyPageReader,\n} from \"../../principals/principalPolicyHistoryReader\";\nimport {\n createRuntimePrincipalPolicyCurrentResolver,\n type PrincipalPolicyRecoveryRuntime,\n} from \"../../principals/runtimePolicyRecovery\";\nimport type { AcknowledgedPrincipalCurrentInput } from \"./retainAcknowledgedPrincipalCurrents\";\n\ninterface CurrentPrincipalMutationLeaseContext {\n readonly protection: PrincipalPolicyHistoryProgressOptions;\n readonly stillCurrent: () => boolean;\n readonly resolveCurrentPolicy: NonNullable<\n ReturnType<typeof createRuntimePrincipalPolicyCurrentResolver>\n >;\n readonly historyReader: PrincipalPolicyPageReader;\n readonly directoryRecovery: (\n current: PrincipalPolicyPageCurrent,\n ) => AcknowledgedPrincipalCurrentInput[\"recovery\"];\n}\n\ntype CurrentPrincipalMutationLease = <T>(\n callerCurrent: () => boolean,\n work: (context: CurrentPrincipalMutationLeaseContext) => Promise<T>,\n) => Promise<T>;\n\n/** One lifetime fence and private custody boundary for every current-policy mutation. */\nexport function createCurrentPrincipalMutationLease(\n runtime: PrincipalPolicyRecoveryRuntime,\n): CurrentPrincipalMutationLease | undefined {\n const lease = readPrincipalHistoryProtection(runtime);\n const resolveCurrentPolicy =\n createRuntimePrincipalPolicyCurrentResolver(runtime);\n const historyReader = apiPrincipalPolicyPageReader(runtime.apiClient);\n if (!lease || !resolveCurrentPolicy || !historyReader) return undefined;\n return async <T>(\n callerCurrent: () => boolean,\n work: (context: CurrentPrincipalMutationLeaseContext) => Promise<T>,\n ): Promise<T> =>\n lease(async ({ protection, stillCurrent: leaseCurrent }) => {\n let active = true;\n const stillCurrent = () => active && leaseCurrent() && callerCurrent();\n try {\n assertProjectionVerificationCurrent(stillCurrent);\n const result = await work({\n protection,\n stillCurrent,\n resolveCurrentPolicy,\n historyReader,\n directoryRecovery: (current) => ({\n historyReader,\n expectedHead: principalPolicyReferenceFromBundle(current),\n protection: directoryHistoryProtection(protection),\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n }),\n });\n assertProjectionVerificationCurrent(stillCurrent);\n return result;\n } finally {\n active = false;\n }\n });\n}\n"]}
@@ -1,26 +0,0 @@
1
- import { type ReferencedPrincipalPolicyWarmer } from "../../data/keyingProjectionVerification/types.js";
2
- import { type PrincipalPolicyRecoveryRuntime } from "./runtimePolicyRecovery.js";
3
- interface PrincipalPolicyWarmRuntime extends PrincipalPolicyRecoveryRuntime {
4
- readonly util: PrincipalPolicyRecoveryRuntime["util"] & {
5
- readonly log?: ((message: string) => void) | undefined;
6
- };
7
- }
8
- /**
9
- * The token of one reconciliation pass or user workflow. Every warmer created
10
- * with it shares one authenticated directory view, discovered once; the view
11
- * dies with the token, an organization hint, a durable pin past it, or the end
12
- * of its producing lease. Mint one at the pass or workflow root.
13
- */
14
- export type PrincipalPolicyOperation = object;
15
- export declare function createPrincipalPolicyOperation(): PrincipalPolicyOperation;
16
- /**
17
- * One warmer serves one workflow operation: either the `operation` its root
18
- * minted, or a fresh one of its own. Its projection collections share one
19
- * authenticated directory view per operation. Prefetch is best-effort; exact
20
- * resolution still rejects unavailable evidence.
21
- */
22
- export declare function createRuntimePrincipalPolicyWarmer(runtime: PrincipalPolicyWarmRuntime, options?: {
23
- readonly preferLocalCurrent?: boolean;
24
- readonly operation?: PrincipalPolicyOperation | undefined;
25
- }): ReferencedPrincipalPolicyWarmer;
26
- export {};
@@ -1,48 +0,0 @@
1
- import { ProjectionDependencyUnavailableError } from "../../data/keyingProjectionVerification/dependencyUnavailable.js";
2
- import { rethrowKeyingVerificationError } from "../../data/keyingProjectionVerification/error.js";
3
- import { assertProjectionVerificationCurrent, isProjectionVerificationCancelledError, } from "../../data/keyingProjectionVerification/types.js";
4
- import { errorMessage } from "../../data/shared/errorMessage.js";
5
- import { createRuntimePrincipalPolicyResolver, } from "./runtimePolicyRecovery.js";
6
- import { createRuntimeProjectionPolicyResolver } from "./runtimeProjectionPolicyRecovery.js";
7
- export function createPrincipalPolicyOperation() {
8
- return {};
9
- }
10
- /**
11
- * One warmer serves one workflow operation: either the `operation` its root
12
- * minted, or a fresh one of its own. Its projection collections share one
13
- * authenticated directory view per operation. Prefetch is best-effort; exact
14
- * resolution still rejects unavailable evidence.
15
- */
16
- export function createRuntimePrincipalPolicyWarmer(runtime, options = {}) {
17
- const resolve = createRuntimePrincipalPolicyResolver(runtime, options);
18
- const operation = options.operation ?? createPrincipalPolicyOperation();
19
- const resolveReference = async (input) => {
20
- if (!resolve)
21
- throw new ProjectionDependencyUnavailableError("Principal policies require private paged recovery");
22
- return resolve({
23
- ...input,
24
- recoveryBatch: input.recoveryBatch ?? operation,
25
- });
26
- };
27
- return Object.assign((input) => prefetchReferences(runtime, resolveReference, input), {
28
- resolveReference,
29
- resolveProjectionHistory: createRuntimeProjectionPolicyResolver(runtime),
30
- });
31
- }
32
- async function prefetchReferences(runtime, resolve, input) {
33
- for (const reference of input.references) {
34
- try {
35
- assertProjectionVerificationCurrent(input.stillCurrent);
36
- const resolved = await resolve({ ...input, reference });
37
- assertProjectionVerificationCurrent(resolved.stillCurrent);
38
- }
39
- catch (error) {
40
- if (isProjectionVerificationCancelledError(error))
41
- return;
42
- // Recovery already reports signature/authority failures. Keep them fatal.
43
- rethrowKeyingVerificationError(error);
44
- runtime.util.log?.(`Principal policy prefetch: ${reference.principalId}: ${errorMessage(error)}`);
45
- }
46
- }
47
- }
48
- //# sourceMappingURL=runtimePolicyWarmer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtimePolicyWarmer.js","sourceRoot":"","sources":["runtimePolicyWarmer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EACL,mCAAmC,EACnC,sCAAsC,GAEvC,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE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AAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,sCAAsC,CAAC,KAAK,CAAC;gBAAE,OAAO;YAC1D,0EAA0E;YAC1E,8BAA8B,CAAC,KAAK,CAAC,CAAC;YACtC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAChB,8BAA8B,SAAS,CAAC,WAAW,KAAK,YAAY,CAAC,KAAK,CAAC,EAAE,CAC9E,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { rethrowKeyingVerificationError } from \"../../data/keyingProjectionVerification/error\";\nimport {\n assertProjectionVerificationCurrent,\n isProjectionVerificationCancelledError,\n type ReferencedPrincipalPolicyWarmer,\n} from \"../../data/keyingProjectionVerification/types\";\nimport { errorMessage } from \"../../data/shared/errorMessage\";\nimport {\n createRuntimePrincipalPolicyResolver,\n type PrincipalPolicyRecoveryRuntime,\n} from \"./runtimePolicyRecovery\";\nimport { createRuntimeProjectionPolicyResolver } from \"./runtimeProjectionPolicyRecovery\";\n\ntype PolicyResolver = NonNullable<\n ReferencedPrincipalPolicyWarmer[\"resolveReference\"]\n>;\ninterface PrincipalPolicyWarmRuntime extends PrincipalPolicyRecoveryRuntime {\n readonly util: PrincipalPolicyRecoveryRuntime[\"util\"] & {\n readonly log?: ((message: string) => void) | undefined;\n };\n}\n\n/**\n * The token of one reconciliation pass or user workflow. Every warmer created\n * with it shares one authenticated directory view, discovered once; the view\n * dies with the token, an organization hint, a durable pin past it, or the end\n * of its producing lease. Mint one at the pass or workflow root.\n */\nexport type PrincipalPolicyOperation = object;\n\nexport function createPrincipalPolicyOperation(): PrincipalPolicyOperation {\n return {};\n}\n\n/**\n * One warmer serves one workflow operation: either the `operation` its root\n * minted, or a fresh one of its own. Its projection collections share one\n * authenticated directory view per operation. Prefetch is best-effort; exact\n * resolution still rejects unavailable evidence.\n */\nexport function createRuntimePrincipalPolicyWarmer(\n runtime: PrincipalPolicyWarmRuntime,\n options: {\n readonly preferLocalCurrent?: boolean;\n readonly operation?: PrincipalPolicyOperation | undefined;\n } = {},\n): ReferencedPrincipalPolicyWarmer {\n const resolve = createRuntimePrincipalPolicyResolver(runtime, options);\n const operation = options.operation ?? createPrincipalPolicyOperation();\n const resolveReference: PolicyResolver = async (input) => {\n if (!resolve)\n throw new ProjectionDependencyUnavailableError(\n \"Principal policies require private paged recovery\",\n );\n return resolve({\n ...input,\n recoveryBatch: input.recoveryBatch ?? operation,\n });\n };\n return Object.assign(\n (input: Parameters<ReferencedPrincipalPolicyWarmer>[0]) =>\n prefetchReferences(runtime, resolveReference, input),\n {\n resolveReference,\n resolveProjectionHistory: createRuntimeProjectionPolicyResolver(runtime),\n },\n );\n}\n\nasync function prefetchReferences(\n runtime: PrincipalPolicyWarmRuntime,\n resolve: PolicyResolver,\n input: Parameters<ReferencedPrincipalPolicyWarmer>[0],\n): Promise<void> {\n for (const reference of input.references) {\n try {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const resolved = await resolve({ ...input, reference });\n assertProjectionVerificationCurrent(resolved.stillCurrent);\n } catch (error) {\n if (isProjectionVerificationCancelledError(error)) return;\n // Recovery already reports signature/authority failures. Keep them fatal.\n rethrowKeyingVerificationError(error);\n runtime.util.log?.(\n `Principal policy prefetch: ${reference.principalId}: ${errorMessage(error)}`,\n );\n }\n }\n}\n"]}