@tearleads/client-sdk 0.1.200 → 0.1.202

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 (47) hide show
  1. package/client/organizations/principalMutations.js +8 -4
  2. package/client/organizations/principalMutations.js.map +1 -1
  3. package/data/persistence/principalMutationJournalPersistence.d.ts +20 -13
  4. package/data/persistence/principalMutationJournalPersistence.js +54 -43
  5. package/data/persistence/principalMutationJournalPersistence.js.map +1 -1
  6. package/index.d.ts +2 -2
  7. package/index.js +1 -1
  8. package/index.js.map +1 -1
  9. package/package.json +1 -1
  10. package/workflows/container-contents/container-state/remote.js +23 -28
  11. package/workflows/container-contents/container-state/remote.js.map +1 -1
  12. package/workflows/container-contents/container-state/types.js.map +1 -1
  13. package/workflows/containers/child/create/createSubmission.d.ts +6 -8
  14. package/workflows/containers/child/create/createSubmission.js.map +1 -1
  15. package/workflows/containers/child/create/index.d.ts +4 -3
  16. package/workflows/containers/child/create/index.js +7 -1
  17. package/workflows/containers/child/create/index.js.map +1 -1
  18. package/workflows/containers/child/move/index.d.ts +6 -10
  19. package/workflows/containers/child/move/index.js +5 -4
  20. package/workflows/containers/child/move/index.js.map +1 -1
  21. package/workflows/containers/child/rekey/rekeyRemote.d.ts +6 -9
  22. package/workflows/containers/child/rekey/rekeyRemote.js +3 -1
  23. package/workflows/containers/child/rekey/rekeyRemote.js.map +1 -1
  24. package/workflows/containers/child/revoke.d.ts +4 -9
  25. package/workflows/containers/child/revoke.js +3 -1
  26. package/workflows/containers/child/revoke.js.map +1 -1
  27. package/workflows/containers/child/share/index.d.ts +5 -13
  28. package/workflows/containers/child/share/index.js +7 -1
  29. package/workflows/containers/child/share/index.js.map +1 -1
  30. package/workflows/containers/child/share/shareAncestorRepair.js +5 -4
  31. package/workflows/containers/child/share/shareAncestorRepair.js.map +1 -1
  32. package/workflows/containers/containerMutationCollaborators.d.ts +30 -0
  33. package/workflows/containers/containerMutationCollaborators.js +9 -0
  34. package/workflows/containers/containerMutationCollaborators.js.map +1 -0
  35. package/workflows/containers/containerMutationService.d.ts +32 -0
  36. package/workflows/containers/containerMutationService.js +43 -0
  37. package/workflows/containers/containerMutationService.js.map +1 -0
  38. package/workflows/containers/index.d.ts +9 -6
  39. package/workflows/containers/index.js +3 -5
  40. package/workflows/containers/index.js.map +1 -1
  41. package/workflows/organizations/containerGrantRevocation.d.ts +3 -11
  42. package/workflows/organizations/containerGrantRevocation.js +1 -6
  43. package/workflows/organizations/containerGrantRevocation.js.map +1 -1
  44. package/workflows/organizations/principalMutations/principalMutationJournalManagement.js +5 -7
  45. package/workflows/organizations/principalMutations/principalMutationJournalManagement.js.map +1 -1
  46. package/workflows/organizations/principalMutations/principalMutationJournalSession.js +4 -6
  47. package/workflows/organizations/principalMutations/principalMutationJournalSession.js.map +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containerMutationService.js","sourceRoot":"","sources":["containerMutationService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAGL,mBAAmB,EACnB,yBAAyB,GAE1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,oBAAoB,GACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAGL,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAGvB;;;;;;GAMG;AACH,MAAM,OAAO,wBAAwB;IAClB,UAAU,CAAiC;IAE5D,YAAY,aAA6C;QACvD,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC;IAClC,CAAC;IAED,qBAAqB,CACnB,OAAqC;QAErC,OAAO,qBAAqB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,oBAAoB,CAClB,OAAoC;QAEpC,OAAO,oBAAoB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAED,yEAAyE;IACzE,mBAAmB,CACjB,OAAmC;QAEnC,OAAO,mBAAmB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IAED;;;OAGG;IACH,yBAAyB,CACvB,OAAmC;QAInC,OAAO,yBAAyB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,oBAAoB,CAClB,OAAoC;QAEpC,OAAO,oBAAoB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAED,8EAA8E;IAC9E,qBAAqB,CACnB,OAAqC;QAErC,OAAO,qBAAqB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;CACF","sourcesContent":["import type { CreateRemoteContainerResult } from \"../../data/containers/shared/types\";\nimport { createRemoteContainer } from \"./child/create\";\nimport type { RemoteContainerCreateRequest } from \"./child/create/createSubmission\";\nimport {\n type AppliedContainerMove,\n type MoveRemoteContainerRequest,\n moveRemoteContainer,\n replayRemoteContainerMove,\n type SubmittedContainerMove,\n} from \"./child/move\";\nimport {\n type RekeyedRemoteContainer,\n type RekeyRemoteContainerRequest,\n rekeyRemoteContainer,\n} from \"./child/rekey/rekeyRemote\";\nimport {\n type RevokedRemoteContainer,\n type RevokeRemoteContainerRequest,\n revokeRemoteContainer,\n} from \"./child/revoke\";\nimport {\n type SharedRemoteContainer,\n type ShareRemoteContainerRequest,\n shareRemoteContainer,\n} from \"./child/share\";\nimport type { ContainerMutationCollaborators } from \"./containerMutationCollaborators\";\n\n/**\n * Container Data: creates, shares, moves, re-keys, and revokes remote\n * containers. One instance binds the API client, executor, encapsulation\n * secret key, incident reporter, and identity resolver of one runtime\n * snapshot; each request carries what varies per call, such as the author,\n * ids, the projection key resolver, the policy warmer, and currency checks.\n */\nexport class ContainerMutationService {\n private readonly containers: ContainerMutationCollaborators;\n\n constructor(collaborators: ContainerMutationCollaborators) {\n this.containers = collaborators;\n }\n\n createRemoteContainer(\n request: RemoteContainerCreateRequest,\n ): Promise<CreateRemoteContainerResult | null> {\n return createRemoteContainer(this.containers, request);\n }\n\n shareRemoteContainer(\n request: ShareRemoteContainerRequest,\n ): Promise<SharedRemoteContainer | null> {\n return shareRemoteContainer(this.containers, request);\n }\n\n /** Signs and submits a move; `null` when it was refused or abandoned. */\n moveRemoteContainer(\n request: MoveRemoteContainerRequest,\n ): Promise<SubmittedContainerMove | null> {\n return moveRemoteContainer(this.containers, request);\n }\n\n /**\n * Replays a queued move. When the verified source head already sits under\n * the destination it signs nothing and returns that head.\n */\n replayRemoteContainerMove(\n request: MoveRemoteContainerRequest,\n ): Promise<\n SubmittedContainerMove | { applied: AppliedContainerMove } | null\n > {\n return replayRemoteContainerMove(this.containers, request);\n }\n\n rekeyRemoteContainer(\n request: RekeyRemoteContainerRequest,\n ): Promise<RekeyedRemoteContainer | null> {\n return rekeyRemoteContainer(this.containers, request);\n }\n\n /** A concurrent mutation can advance the path while a revoke is in flight. */\n revokeRemoteContainer(\n request: RevokeRemoteContainerRequest,\n ): Promise<RevokedRemoteContainer | null> {\n return revokeRemoteContainer(this.containers, request);\n }\n}\n"]}
@@ -1,22 +1,25 @@
1
1
  export { ContainerAuthorAccessError } from "../../data/containers/shared/authorAccess.js";
2
2
  export { ContainerPathTooDeepError } from "../../data/containers/shared/containerPathLimits.js";
3
3
  export type { ContainerReciteApi } from "../../data/containers/shared/reciteApi.js";
4
- export type { ContainerMutationAuthor, MaterializedContainerRekeyPlan, } from "../../data/containers/shared/types.js";
4
+ export type { ContainerMutationAuthor, CreateRemoteContainerResult, MaterializedContainerRekeyPlan, } from "../../data/containers/shared/types.js";
5
5
  export type { AggregatedContainerKekLog, KeyringRebuildResult, } from "../../data/documents/shared/containerKek/index.js";
6
6
  export { ContainerKekRepairInaccessibleError, ContainerKekRepairRequiredError, fetchContainerKekLog, HistoricalWrapUnavailableError, type HistoricalWrapUnavailableReason, rebuildKeyringEntriesFromLog, recoverKeyringEntryFromWraps, } from "../../data/documents/shared/containerKek/index.js";
7
7
  export { isProjectionVerificationCancelledError } from "../../data/keyingProjectionVerification/types.js";
8
- export { buildContainerCreatePlan, buildMaterializedContainerCreatePlan, childContainerWriterProjectionFromCreatePlan, createRemoteContainer, } from "./child/create/index.js";
9
- export { type AppliedContainerMove, moveRemoteContainer, replayRemoteContainerMove, } from "./child/move/index.js";
8
+ export { buildContainerCreatePlan, buildMaterializedContainerCreatePlan, childContainerWriterProjectionFromCreatePlan, } from "./child/create/index.js";
9
+ export type { RemoteContainerCreateRequest } from "./child/create/createSubmission.js";
10
+ export type { AppliedContainerMove, MoveRemoteContainerRequest, SubmittedContainerMove, } from "./child/move/index.js";
10
11
  export { submitAcknowledgedContainerMutation, submitPlainContainerMutation, } from "./child/mutationSubmit.js";
11
12
  export { buildMaterializedContainerRekeyPlan } from "./child/rekey/index.js";
12
13
  export { ContainerKeyringOverrideStaleError } from "./child/rekey/keyringOverrideLineage.js";
13
14
  export { containerWriterProjectionFromRekeyPlan } from "./child/rekey/rekeyProjection.js";
14
- export { rekeyRemoteContainer } from "./child/rekey/rekeyRemote.js";
15
- export { buildMaterializedContainerRevokePlan, revokeRemoteContainer, } from "./child/revoke.js";
16
- export { shareRemoteContainer } from "./child/share/index.js";
15
+ export type { RekeyedRemoteContainer, RekeyRemoteContainerRequest, } from "./child/rekey/rekeyRemote.js";
16
+ export { buildMaterializedContainerRevokePlan, type RevokedRemoteContainer, type RevokeRemoteContainerRequest, } from "./child/revoke.js";
17
+ export type { SharedRemoteContainer, ShareRemoteContainerRequest, } from "./child/share/index.js";
17
18
  export { buildMaterializedContainerSharePlan } from "./child/share/shareMaterialization.js";
18
19
  export { referencedPrincipalHeadFromPolicy } from "./child/share/sharePlanCore.js";
19
20
  export { resolveShareProjection } from "./child/share/shareProjection.js";
21
+ export type { ContainerMutationCollaborators, ContainerMutationServiceApi, } from "./containerMutationCollaborators.js";
22
+ export { ContainerMutationService } from "./containerMutationService.js";
20
23
  export { signedContainerMetadataDocumentId, signedContainerReferencedPrincipalHeads, } from "./mutationResponse.js";
21
24
  export { buildRootContainerCreatePlan, rootContainerWriterProjectionFromCreatePlan, } from "./root/create.js";
22
25
  export { type ContainerWriteRefusal, classifyContainerWriteRefusal, } from "./writeRefusal.js";
@@ -8,20 +8,18 @@ export { ContainerKekRepairInaccessibleError, ContainerKekRepairRequiredError, f
8
8
  // A share's projection verification can be cancelled by a newer generation
9
9
  // underneath the caller; hosts filter that outcome from their own reporting.
10
10
  export { isProjectionVerificationCancelledError } from "../../data/keyingProjectionVerification/types.js";
11
- export { buildContainerCreatePlan, buildMaterializedContainerCreatePlan, childContainerWriterProjectionFromCreatePlan, createRemoteContainer, } from "./child/create/index.js";
12
- export { moveRemoteContainer, replayRemoteContainerMove, } from "./child/move/index.js";
11
+ export { buildContainerCreatePlan, buildMaterializedContainerCreatePlan, childContainerWriterProjectionFromCreatePlan, } from "./child/create/index.js";
13
12
  // Organizations' group shares submit and acknowledge their container mutation.
14
13
  export { submitAcknowledgedContainerMutation, submitPlainContainerMutation, } from "./child/mutationSubmit.js";
15
14
  export { buildMaterializedContainerRekeyPlan } from "./child/rekey/index.js";
16
15
  // A rebuilt keyring override that a concurrent rotation outdated: rebuild it.
17
16
  export { ContainerKeyringOverrideStaleError } from "./child/rekey/keyringOverrideLineage.js";
18
17
  export { containerWriterProjectionFromRekeyPlan } from "./child/rekey/rekeyProjection.js";
19
- export { rekeyRemoteContainer } from "./child/rekey/rekeyRemote.js";
20
- export { buildMaterializedContainerRevokePlan, revokeRemoteContainer, } from "./child/revoke.js";
21
- export { shareRemoteContainer } from "./child/share/index.js";
18
+ export { buildMaterializedContainerRevokePlan, } from "./child/revoke.js";
22
19
  export { buildMaterializedContainerSharePlan } from "./child/share/shareMaterialization.js";
23
20
  export { referencedPrincipalHeadFromPolicy } from "./child/share/sharePlanCore.js";
24
21
  export { resolveShareProjection } from "./child/share/shareProjection.js";
22
+ export { ContainerMutationService } from "./containerMutationService.js";
25
23
  export { signedContainerMetadataDocumentId, signedContainerReferencedPrincipalHeads, } from "./mutationResponse.js";
26
24
  export { buildRootContainerCreatePlan, rootContainerWriterProjectionFromCreatePlan, } from "./root/create.js";
27
25
  export { classifyContainerWriteRefusal, } from "./writeRefusal.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,iEAAiE;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,4DAA4D;AAC5D,8EAA8E;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAU7F,OAAO,EACL,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,8BAA8B,EAE9B,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,0CAA0C,CAAC;AAClD,2EAA2E;AAC3E,6EAA6E;AAC7E,OAAO,EAAE,sCAAsC,EAAE,MAAM,+CAA+C,CAAC;AACvG,OAAO,EACL,wBAAwB,EACxB,oCAAoC,EACpC,4CAA4C,EAC5C,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AACtB,+EAA+E;AAC/E,OAAO,EACL,mCAAmC,EACnC,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mCAAmC,EAAE,MAAM,eAAe,CAAC;AACpE,8EAA8E;AAC9E,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EAAE,sCAAsC,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EACL,iCAAiC,EACjC,uCAAuC,GACxC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,4BAA4B,EAC5B,2CAA2C,GAC5C,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,6BAA6B,GAC9B,MAAM,gBAAgB,CAAC","sourcesContent":["// Refusals the SDK raises before it encrypts or sends a container-scoped\n// write; hosts classify them with classifyContainerWriteRefusal.\nexport { ContainerAuthorAccessError } from \"../../data/containers/shared/authorAccess\";\n// A create or move past the readable path length; `code` is\n// `container_path_too_deep`. Queued moves are abandoned, queued creates wait.\nexport { ContainerPathTooDeepError } from \"../../data/containers/shared/containerPathLimits\";\nexport type { ContainerReciteApi } from \"../../data/containers/shared/reciteApi\";\nexport type {\n ContainerMutationAuthor,\n MaterializedContainerRekeyPlan,\n} from \"../../data/containers/shared/types\";\nexport type {\n AggregatedContainerKekLog,\n KeyringRebuildResult,\n} from \"../../data/documents/shared/containerKek\";\nexport {\n ContainerKekRepairInaccessibleError,\n ContainerKekRepairRequiredError,\n fetchContainerKekLog,\n HistoricalWrapUnavailableError,\n type HistoricalWrapUnavailableReason,\n rebuildKeyringEntriesFromLog,\n recoverKeyringEntryFromWraps,\n} from \"../../data/documents/shared/containerKek\";\n// A share's projection verification can be cancelled by a newer generation\n// underneath the caller; hosts filter that outcome from their own reporting.\nexport { isProjectionVerificationCancelledError } from \"../../data/keyingProjectionVerification/types\";\nexport {\n buildContainerCreatePlan,\n buildMaterializedContainerCreatePlan,\n childContainerWriterProjectionFromCreatePlan,\n createRemoteContainer,\n} from \"./child/create\";\nexport {\n type AppliedContainerMove,\n moveRemoteContainer,\n replayRemoteContainerMove,\n} from \"./child/move\";\n// Organizations' group shares submit and acknowledge their container mutation.\nexport {\n submitAcknowledgedContainerMutation,\n submitPlainContainerMutation,\n} from \"./child/mutationSubmit\";\nexport { buildMaterializedContainerRekeyPlan } from \"./child/rekey\";\n// A rebuilt keyring override that a concurrent rotation outdated: rebuild it.\nexport { ContainerKeyringOverrideStaleError } from \"./child/rekey/keyringOverrideLineage\";\nexport { containerWriterProjectionFromRekeyPlan } from \"./child/rekey/rekeyProjection\";\nexport { rekeyRemoteContainer } from \"./child/rekey/rekeyRemote\";\nexport {\n buildMaterializedContainerRevokePlan,\n revokeRemoteContainer,\n} from \"./child/revoke\";\nexport { shareRemoteContainer } from \"./child/share\";\nexport { buildMaterializedContainerSharePlan } from \"./child/share/shareMaterialization\";\nexport { referencedPrincipalHeadFromPolicy } from \"./child/share/sharePlanCore\";\nexport { resolveShareProjection } from \"./child/share/shareProjection\";\nexport {\n signedContainerMetadataDocumentId,\n signedContainerReferencedPrincipalHeads,\n} from \"./mutationResponse\";\nexport {\n buildRootContainerCreatePlan,\n rootContainerWriterProjectionFromCreatePlan,\n} from \"./root/create\";\nexport {\n type ContainerWriteRefusal,\n classifyContainerWriteRefusal,\n} from \"./writeRefusal\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,iEAAiE;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,4DAA4D;AAC5D,8EAA8E;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAW7F,OAAO,EACL,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,8BAA8B,EAE9B,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,0CAA0C,CAAC;AAClD,2EAA2E;AAC3E,6EAA6E;AAC7E,OAAO,EAAE,sCAAsC,EAAE,MAAM,+CAA+C,CAAC;AACvG,OAAO,EACL,wBAAwB,EACxB,oCAAoC,EACpC,4CAA4C,GAC7C,MAAM,gBAAgB,CAAC;AAOxB,+EAA+E;AAC/E,OAAO,EACL,mCAAmC,EACnC,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mCAAmC,EAAE,MAAM,eAAe,CAAC;AACpE,8EAA8E;AAC9E,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EAAE,sCAAsC,EAAE,MAAM,+BAA+B,CAAC;AAKvF,OAAO,EACL,oCAAoC,GAGrC,MAAM,gBAAgB,CAAC;AAKxB,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAKvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EACL,iCAAiC,EACjC,uCAAuC,GACxC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,4BAA4B,EAC5B,2CAA2C,GAC5C,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,6BAA6B,GAC9B,MAAM,gBAAgB,CAAC","sourcesContent":["// Refusals the SDK raises before it encrypts or sends a container-scoped\n// write; hosts classify them with classifyContainerWriteRefusal.\nexport { ContainerAuthorAccessError } from \"../../data/containers/shared/authorAccess\";\n// A create or move past the readable path length; `code` is\n// `container_path_too_deep`. Queued moves are abandoned, queued creates wait.\nexport { ContainerPathTooDeepError } from \"../../data/containers/shared/containerPathLimits\";\nexport type { ContainerReciteApi } from \"../../data/containers/shared/reciteApi\";\nexport type {\n ContainerMutationAuthor,\n CreateRemoteContainerResult,\n MaterializedContainerRekeyPlan,\n} from \"../../data/containers/shared/types\";\nexport type {\n AggregatedContainerKekLog,\n KeyringRebuildResult,\n} from \"../../data/documents/shared/containerKek\";\nexport {\n ContainerKekRepairInaccessibleError,\n ContainerKekRepairRequiredError,\n fetchContainerKekLog,\n HistoricalWrapUnavailableError,\n type HistoricalWrapUnavailableReason,\n rebuildKeyringEntriesFromLog,\n recoverKeyringEntryFromWraps,\n} from \"../../data/documents/shared/containerKek\";\n// A share's projection verification can be cancelled by a newer generation\n// underneath the caller; hosts filter that outcome from their own reporting.\nexport { isProjectionVerificationCancelledError } from \"../../data/keyingProjectionVerification/types\";\nexport {\n buildContainerCreatePlan,\n buildMaterializedContainerCreatePlan,\n childContainerWriterProjectionFromCreatePlan,\n} from \"./child/create\";\nexport type { RemoteContainerCreateRequest } from \"./child/create/createSubmission\";\nexport type {\n AppliedContainerMove,\n MoveRemoteContainerRequest,\n SubmittedContainerMove,\n} from \"./child/move\";\n// Organizations' group shares submit and acknowledge their container mutation.\nexport {\n submitAcknowledgedContainerMutation,\n submitPlainContainerMutation,\n} from \"./child/mutationSubmit\";\nexport { buildMaterializedContainerRekeyPlan } from \"./child/rekey\";\n// A rebuilt keyring override that a concurrent rotation outdated: rebuild it.\nexport { ContainerKeyringOverrideStaleError } from \"./child/rekey/keyringOverrideLineage\";\nexport { containerWriterProjectionFromRekeyPlan } from \"./child/rekey/rekeyProjection\";\nexport type {\n RekeyedRemoteContainer,\n RekeyRemoteContainerRequest,\n} from \"./child/rekey/rekeyRemote\";\nexport {\n buildMaterializedContainerRevokePlan,\n type RevokedRemoteContainer,\n type RevokeRemoteContainerRequest,\n} from \"./child/revoke\";\nexport type {\n SharedRemoteContainer,\n ShareRemoteContainerRequest,\n} from \"./child/share\";\nexport { buildMaterializedContainerSharePlan } from \"./child/share/shareMaterialization\";\nexport { referencedPrincipalHeadFromPolicy } from \"./child/share/sharePlanCore\";\nexport { resolveShareProjection } from \"./child/share/shareProjection\";\nexport type {\n ContainerMutationCollaborators,\n ContainerMutationServiceApi,\n} from \"./containerMutationCollaborators\";\nexport { ContainerMutationService } from \"./containerMutationService\";\nexport {\n signedContainerMetadataDocumentId,\n signedContainerReferencedPrincipalHeads,\n} from \"./mutationResponse\";\nexport {\n buildRootContainerCreatePlan,\n rootContainerWriterProjectionFromCreatePlan,\n} from \"./root/create\";\nexport {\n type ContainerWriteRefusal,\n classifyContainerWriteRefusal,\n} from \"./writeRefusal\";\n"]}
@@ -1,22 +1,14 @@
1
1
  import type { ContainerDirectGrant } from "../../internal/crypto/index.js";
2
2
  import type { ContainerMutationResponse } from "../../internal/validators/response/index.js";
3
3
  import type { ReferencedPrincipalPolicyWarmer } from "../../data/keyingProjectionVerification/index.js";
4
- import type { SecurityIncidentReporter } from "../../data/shared/securityIncidents.js";
5
- import type { ExecSql } from "../../data/sqlite/sqlSchema.js";
6
4
  import type { TrustedUserIdentityResolver } from "../../data/trustedUserIdentity/index.js";
7
- import { revokeRemoteContainer } from "../containers/index.js";
5
+ import type { ContainerMutationService } from "../containers/index.js";
8
6
  type OrganizationContainerGrantSubject = Pick<ContainerDirectGrant, "subjectId" | "subjectType">;
9
- type OrganizationContainerGrantRevocationApi = Parameters<typeof revokeRemoteContainer>[0]["apiClient"];
10
7
  export declare function revokeOrganizationContainerGrant(input: {
11
8
  readonly stillCurrent: () => boolean;
12
- readonly reportSecurityIncident: SecurityIncidentReporter;
13
- readonly apiClient: OrganizationContainerGrantRevocationApi;
14
9
  readonly containerId: string;
15
- readonly encapsulationKeyPair: {
16
- readonly publicKey: Uint8Array;
17
- readonly secretKey: Uint8Array;
18
- };
19
- readonly execSql: ExecSql;
10
+ /** Bound to the runtime snapshot whose encapsulation key reaches the container. */
11
+ readonly containers: ContainerMutationService;
20
12
  readonly organizationId: string;
21
13
  readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;
22
14
  readonly revokedSubject: OrganizationContainerGrantSubject;
@@ -1,5 +1,4 @@
1
1
  import { createProjectionUserKeyResolver } from "../../data/keyingProjectionVerification/userKeyResolver.js";
2
- import { revokeRemoteContainer } from "../containers/index.js";
3
2
  import { resolveDocumentCreateAuthor } from "../documents/index.js";
4
3
  export async function revokeOrganizationContainerGrant(input) {
5
4
  const author = resolveDocumentCreateAuthor({
@@ -15,18 +14,14 @@ export async function revokeOrganizationContainerGrant(input) {
15
14
  if (!author) {
16
15
  throw new Error("Org Manager signing context is unavailable");
17
16
  }
18
- const revoked = await revokeRemoteContainer({
17
+ const revoked = await input.containers.revokeRemoteContainer({
19
18
  stillCurrent: input.stillCurrent,
20
- reportSecurityIncident: input.reportSecurityIncident,
21
- apiClient: input.apiClient,
22
19
  author,
23
20
  containerId: input.containerId,
24
- execSql: input.execSql,
25
21
  revokedSubject: input.revokedSubject,
26
22
  resolveProjectionUserKey: createProjectionUserKeyResolver({
27
23
  resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,
28
24
  }),
29
- targetSecretKey: input.encapsulationKeyPair.secretKey,
30
25
  warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,
31
26
  });
32
27
  if (!revoked) {
@@ -1 +1 @@
1
- {"version":3,"file":"containerGrantRevocation.js","sourceRoot":"","sources":["containerGrantRevocation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,+BAA+B,EAAE,MAAM,yDAAyD,CAAC;AAI1G,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAW3D,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAAC,KAsBtD;IACC,MAAM,MAAM,GAAG,2BAA2B,CAAC;QACzC,IAAI,EAAE;YACJ,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,MAAM,EAAE,KAAK,CAAC,YAAY;SAC3B;QACD,MAAM,EAAE;YACN,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;SACrC;KACF,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,qBAAqB,CAAC;QAC1C,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,sBAAsB,EAAE,KAAK,CAAC,sBAAsB;QACpD,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,MAAM;QACN,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,wBAAwB,EAAE,+BAA+B,CAAC;YACxD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;SAC7D,CAAC;QACF,eAAe,EAAE,KAAK,CAAC,oBAAoB,CAAC,SAAS;QACrD,+BAA+B,EAAE,KAAK,CAAC,+BAA+B;KACvE,CAAC,CAAC;IACH,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,OAAO,CAAC,QAAQ,CAAC;AAC1B,CAAC","sourcesContent":["import type { ContainerDirectGrant } from \"@tearleads/crypto\";\nimport type { ContainerMutationResponse } from \"@tearleads/validators/response\";\nimport type { ReferencedPrincipalPolicyWarmer } from \"../../data/keyingProjectionVerification\";\nimport { createProjectionUserKeyResolver } from \"../../data/keyingProjectionVerification/userKeyResolver\";\nimport type { SecurityIncidentReporter } from \"../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport { revokeRemoteContainer } from \"../containers\";\nimport { resolveDocumentCreateAuthor } from \"../documents\";\n\ntype OrganizationContainerGrantSubject = Pick<\n ContainerDirectGrant,\n \"subjectId\" | \"subjectType\"\n>;\n\ntype OrganizationContainerGrantRevocationApi = Parameters<\n typeof revokeRemoteContainer\n>[0][\"apiClient\"];\n\nexport async function revokeOrganizationContainerGrant(input: {\n readonly stillCurrent: () => boolean;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly apiClient: OrganizationContainerGrantRevocationApi;\n readonly containerId: string;\n readonly encapsulationKeyPair: {\n readonly publicKey: Uint8Array;\n readonly secretKey: Uint8Array;\n };\n readonly execSql: ExecSql;\n readonly organizationId: string;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly revokedSubject: OrganizationContainerGrantSubject;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: {\n readonly signingPrivateKey: Uint8Array;\n readonly signingPublicKey: Uint8Array;\n };\n readonly warmReferencedPrincipalPolicies?:\n | ReferencedPrincipalPolicyWarmer\n | undefined;\n}): Promise<ContainerMutationResponse> {\n const author = resolveDocumentCreateAuthor({\n auth: {\n organizationId: input.organizationId,\n userId: input.signerUserId,\n },\n crypto: {\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n },\n });\n if (!author) {\n throw new Error(\"Org Manager signing context is unavailable\");\n }\n\n const revoked = await revokeRemoteContainer({\n stillCurrent: input.stillCurrent,\n reportSecurityIncident: input.reportSecurityIncident,\n apiClient: input.apiClient,\n author,\n containerId: input.containerId,\n execSql: input.execSql,\n revokedSubject: input.revokedSubject,\n resolveProjectionUserKey: createProjectionUserKeyResolver({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n }),\n targetSecretKey: input.encapsulationKeyPair.secretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n if (!revoked) {\n throw new Error(\"Container grant could not be revoked\");\n }\n\n return revoked.response;\n}\n"]}
1
+ {"version":3,"file":"containerGrantRevocation.js","sourceRoot":"","sources":["containerGrantRevocation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,+BAA+B,EAAE,MAAM,yDAAyD,CAAC;AAG1G,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAO3D,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAAC,KAiBtD;IACC,MAAM,MAAM,GAAG,2BAA2B,CAAC;QACzC,IAAI,EAAE;YACJ,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,MAAM,EAAE,KAAK,CAAC,YAAY;SAC3B;QACD,MAAM,EAAE;YACN,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;SACrC;KACF,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC;QAC3D,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,MAAM;QACN,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,wBAAwB,EAAE,+BAA+B,CAAC;YACxD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;SAC7D,CAAC;QACF,+BAA+B,EAAE,KAAK,CAAC,+BAA+B;KACvE,CAAC,CAAC;IACH,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,OAAO,CAAC,QAAQ,CAAC;AAC1B,CAAC","sourcesContent":["import type { ContainerDirectGrant } from \"@tearleads/crypto\";\nimport type { ContainerMutationResponse } from \"@tearleads/validators/response\";\nimport type { ReferencedPrincipalPolicyWarmer } from \"../../data/keyingProjectionVerification\";\nimport { createProjectionUserKeyResolver } from \"../../data/keyingProjectionVerification/userKeyResolver\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport type { ContainerMutationService } from \"../containers\";\nimport { resolveDocumentCreateAuthor } from \"../documents\";\n\ntype OrganizationContainerGrantSubject = Pick<\n ContainerDirectGrant,\n \"subjectId\" | \"subjectType\"\n>;\n\nexport async function revokeOrganizationContainerGrant(input: {\n readonly stillCurrent: () => boolean;\n readonly containerId: string;\n /** Bound to the runtime snapshot whose encapsulation key reaches the container. */\n readonly containers: ContainerMutationService;\n readonly organizationId: string;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly revokedSubject: OrganizationContainerGrantSubject;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: {\n readonly signingPrivateKey: Uint8Array;\n readonly signingPublicKey: Uint8Array;\n };\n readonly warmReferencedPrincipalPolicies?:\n | ReferencedPrincipalPolicyWarmer\n | undefined;\n}): Promise<ContainerMutationResponse> {\n const author = resolveDocumentCreateAuthor({\n auth: {\n organizationId: input.organizationId,\n userId: input.signerUserId,\n },\n crypto: {\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n },\n });\n if (!author) {\n throw new Error(\"Org Manager signing context is unavailable\");\n }\n\n const revoked = await input.containers.revokeRemoteContainer({\n stillCurrent: input.stillCurrent,\n author,\n containerId: input.containerId,\n revokedSubject: input.revokedSubject,\n resolveProjectionUserKey: createProjectionUserKeyResolver({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n }),\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n if (!revoked) {\n throw new Error(\"Container grant could not be revoked\");\n }\n\n return revoked.response;\n}\n"]}
@@ -1,13 +1,13 @@
1
1
  import { KeyingVerificationError } from "../../../internal/crypto/index.js";
2
2
  import { canonicalKeyingJsonString } from "../../../data/keying/canonicalJson.js";
3
3
  import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
4
- import { clearPrincipalMutationJournal, loadPrincipalMutationJournal, } from "../../../data/persistence/principalMutationJournalPersistence.js";
4
+ import { PrincipalMutationJournalRepository } from "../../../data/persistence/principalMutationJournalPersistence.js";
5
5
  import { openPrincipalMutation, principalMutationJournalScopeId, } from "../../../data/principals/principalMutationJournal.js";
6
6
  import { principalMutationJournalRecordId, UnreadablePrincipalMutationError, } from "../../../data/principals/principalMutationJournalRecord.js";
7
7
  import { getOrCreatePrincipalPolicyCoordinator } from "../../../data/principals/principalPolicyCoordinator.js";
8
8
  async function loadAuthenticatedMutation(input) {
9
9
  assertProjectionVerificationCurrent(input.stillCurrent);
10
- const row = await loadPrincipalMutationJournal(input.execSql, await principalMutationJournalScopeId(input.scope));
10
+ const row = await new PrincipalMutationJournalRepository(input.execSql).loadPrincipalMutationJournal(await principalMutationJournalScopeId(input.scope));
11
11
  assertProjectionVerificationCurrent(input.stillCurrent);
12
12
  if (!row)
13
13
  return null;
@@ -37,7 +37,7 @@ export async function discardUnreadableJournaledPrincipalMutation(input) {
37
37
  const expected = input.recordId;
38
38
  return getOrCreatePrincipalPolicyCoordinator(input.execSql).runJournalOperation(input.scope, async () => {
39
39
  assertProjectionVerificationCurrent(input.stillCurrent);
40
- const row = await loadPrincipalMutationJournal(input.execSql, await principalMutationJournalScopeId(input.scope));
40
+ const row = await new PrincipalMutationJournalRepository(input.execSql).loadPrincipalMutationJournal(await principalMutationJournalScopeId(input.scope));
41
41
  assertProjectionVerificationCurrent(input.stillCurrent);
42
42
  if (!row)
43
43
  return false;
@@ -58,8 +58,7 @@ export async function discardUnreadableJournaledPrincipalMutation(input) {
58
58
  }
59
59
  if (!unreadable)
60
60
  throw new Error("Readable principal mutations require ordinary abandonment");
61
- const removed = await clearPrincipalMutationJournal({
62
- execSql: input.execSql,
61
+ const removed = await new PrincipalMutationJournalRepository(input.execSql).clearPrincipalMutationJournal({
63
62
  row,
64
63
  stillCurrent: input.stillCurrent,
65
64
  });
@@ -90,8 +89,7 @@ export async function abandonJournaledPrincipalMutation(input) {
90
89
  if (canonicalKeyingJsonString(saved.mutation, "saved authored mutation") !==
91
90
  expected)
92
91
  throw new Error("The pending principal mutation changed after inspection");
93
- const removed = await clearPrincipalMutationJournal({
94
- execSql: input.execSql,
92
+ const removed = await new PrincipalMutationJournalRepository(input.execSql).clearPrincipalMutationJournal({
95
93
  row: saved.row,
96
94
  stillCurrent: input.stillCurrent,
97
95
  });
@@ -1 +1 @@
1
- {"version":3,"file":"principalMutationJournalManagement.js","sourceRoot":"","sources":["principalMutationJournalManagement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAm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AQ;YAER,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;QACJ,MAAM,OAAO,GAAG,MAAM,6BAA6B,CAAC;YAClD,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC,CAAC,CAAC;QACH,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO;YACV,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;QACJ,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { canonicalKeyingJsonString } from \"../../../data/keying/canonicalJson\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport {\n clearPrincipalMutationJournal,\n loadPrincipalMutationJournal,\n} from \"../../../data/persistence/principalMutationJournalPersistence\";\nimport {\n type AuthoredPrincipalMutation,\n openPrincipalMutation,\n principalMutationJournalScopeId,\n} from \"../../../data/principals/principalMutationJournal\";\nimport {\n principalMutationJournalRecordId,\n UnreadablePrincipalMutationError,\n} from \"../../../data/principals/principalMutationJournalRecord\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../../data/principals/principalPolicyCoordinator\";\nimport type { PrincipalMutationJournalContext } from \"./principalMutationJournalSession\";\n\nexport interface PrincipalMutationRecoveryApi {\n readonly readPendingPrincipalMutation: (\n organizationId: string,\n ) => Promise<AuthoredPrincipalMutation | null>;\n readonly recoverPendingPrincipalMutation: (\n organizationId: string,\n ) => Promise<void>;\n readonly abandonPendingPrincipalMutation: (\n organizationId: string,\n mutation: AuthoredPrincipalMutation,\n acknowledgeUnknownOutcome: true,\n ) => Promise<boolean>;\n readonly discardUnreadablePrincipalMutation: (\n organizationId: string,\n recordId: string,\n acknowledgeUnknownOutcome: true,\n ) => Promise<boolean>;\n}\n\ntype JournalIdentity = Pick<\n PrincipalMutationJournalContext,\n \"execSql\" | \"scope\" | \"signingKeyPair\" | \"stillCurrent\"\n>;\n\nasync function loadAuthenticatedMutation(input: JournalIdentity) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const row = await loadPrincipalMutationJournal(\n input.execSql,\n await principalMutationJournalScopeId(input.scope),\n );\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!row) return null;\n let mutation: AuthoredPrincipalMutation;\n try {\n mutation = await openPrincipalMutation({\n scope: input.scope,\n row,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n });\n } catch (error) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!(error instanceof KeyingVerificationError)) throw error;\n const recordId = await principalMutationJournalRecordId(row);\n assertProjectionVerificationCurrent(input.stillCurrent);\n throw new UnreadablePrincipalMutationError(\n recordId,\n error.code === \"invalid_shape\" ? \"format\" : \"authentication\",\n );\n }\n assertProjectionVerificationCurrent(input.stillCurrent);\n return { row, mutation };\n}\n\n/** Discard only the inspected unreadable bytes; never parse them for submission. */\nexport async function discardUnreadableJournaledPrincipalMutation(\n input: JournalIdentity & {\n readonly recordId: string;\n readonly acknowledgeUnknownOutcome: true;\n },\n): Promise<boolean> {\n if (input.acknowledgeUnknownOutcome !== true)\n throw new Error(\n \"Discarding unreadable work requires acknowledging its unknown outcome\",\n );\n const expected = input.recordId;\n return getOrCreatePrincipalPolicyCoordinator(\n input.execSql,\n ).runJournalOperation(input.scope, async () => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const row = await loadPrincipalMutationJournal(\n input.execSql,\n await principalMutationJournalScopeId(input.scope),\n );\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!row) return false;\n if ((await principalMutationJournalRecordId(row)) !== expected)\n throw new Error(\n \"The unreadable principal mutation changed after inspection\",\n );\n let unreadable = false;\n try {\n await openPrincipalMutation({\n scope: input.scope,\n row,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n });\n } catch (error) {\n if (!(error instanceof KeyingVerificationError)) throw error;\n unreadable = true;\n }\n if (!unreadable)\n throw new Error(\n \"Readable principal mutations require ordinary abandonment\",\n );\n const removed = await clearPrincipalMutationJournal({\n execSql: input.execSql,\n row,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!removed)\n throw new Error(\n \"The unreadable principal mutation changed during discard\",\n );\n return true;\n });\n}\n\n/** Inspect authenticated authored work without retrying it or changing checkpoints. */\nexport async function readJournaledPrincipalMutation(\n input: JournalIdentity,\n): Promise<AuthoredPrincipalMutation | null> {\n // Inspection may observe an owned dispatch; all mutations still use the lane.\n return (await loadAuthenticatedMutation(input))?.mutation ?? null;\n}\n\n/**\n * An explicit host/user choice to stop retries, not a claim that the write failed.\n * The exact inspected request must still own the lane; ordinary recovery never\n * calls this. Future authoring must still verify the latest policy state.\n */\nexport async function abandonJournaledPrincipalMutation(\n input: JournalIdentity & {\n readonly mutation: AuthoredPrincipalMutation;\n readonly acknowledgeUnknownOutcome: true;\n },\n): Promise<boolean> {\n if (input.acknowledgeUnknownOutcome !== true)\n throw new Error(\n \"Abandoning authored work requires acknowledging its unknown outcome\",\n );\n const expected = canonicalKeyingJsonString(\n JSON.parse(JSON.stringify(input.mutation)),\n \"inspected authored mutation\",\n );\n return getOrCreatePrincipalPolicyCoordinator(\n input.execSql,\n ).runJournalOperation(input.scope, async () => {\n const saved = await loadAuthenticatedMutation(input);\n if (!saved) return false;\n if (\n canonicalKeyingJsonString(saved.mutation, \"saved authored mutation\") !==\n expected\n )\n throw new Error(\n \"The pending principal mutation changed after inspection\",\n );\n const removed = await clearPrincipalMutationJournal({\n execSql: input.execSql,\n row: saved.row,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!removed)\n throw new Error(\n \"The pending principal mutation changed during abandonment\",\n );\n return true;\n });\n}\n"]}
1
+ {"version":3,"file":"principalMutationJournalManagement.js","sourceRoot":"","sources":["principalMutationJournalManagement.ts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AI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QACzB,IACE,yBAAyB,CAAC,KAAK,CAAC,QAAQ,EAAE,yBAAyB,CAAC;YACpE,QAAQ;YAER,MAAM,IAAI,KAAK,CACb,yDAAyD,CAC1D,CAAC;QACJ,MAAM,OAAO,GAAG,MAAM,IAAI,kCAAkC,CAC1D,KAAK,CAAC,OAAO,CACd,CAAC,6BAA6B,CAAC;YAC9B,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC,CAAC,CAAC;QACH,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO;YACV,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;QACJ,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { canonicalKeyingJsonString } from \"../../../data/keying/canonicalJson\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { PrincipalMutationJournalRepository } from \"../../../data/persistence/principalMutationJournalPersistence\";\nimport {\n type AuthoredPrincipalMutation,\n openPrincipalMutation,\n principalMutationJournalScopeId,\n} from \"../../../data/principals/principalMutationJournal\";\nimport {\n principalMutationJournalRecordId,\n UnreadablePrincipalMutationError,\n} from \"../../../data/principals/principalMutationJournalRecord\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../../data/principals/principalPolicyCoordinator\";\nimport type { PrincipalMutationJournalContext } from \"./principalMutationJournalSession\";\n\nexport interface PrincipalMutationRecoveryApi {\n readonly readPendingPrincipalMutation: (\n organizationId: string,\n ) => Promise<AuthoredPrincipalMutation | null>;\n readonly recoverPendingPrincipalMutation: (\n organizationId: string,\n ) => Promise<void>;\n readonly abandonPendingPrincipalMutation: (\n organizationId: string,\n mutation: AuthoredPrincipalMutation,\n acknowledgeUnknownOutcome: true,\n ) => Promise<boolean>;\n readonly discardUnreadablePrincipalMutation: (\n organizationId: string,\n recordId: string,\n acknowledgeUnknownOutcome: true,\n ) => Promise<boolean>;\n}\n\ntype JournalIdentity = Pick<\n PrincipalMutationJournalContext,\n \"execSql\" | \"scope\" | \"signingKeyPair\" | \"stillCurrent\"\n>;\n\nasync function loadAuthenticatedMutation(input: JournalIdentity) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const row = await new PrincipalMutationJournalRepository(\n input.execSql,\n ).loadPrincipalMutationJournal(\n await principalMutationJournalScopeId(input.scope),\n );\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!row) return null;\n let mutation: AuthoredPrincipalMutation;\n try {\n mutation = await openPrincipalMutation({\n scope: input.scope,\n row,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n });\n } catch (error) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!(error instanceof KeyingVerificationError)) throw error;\n const recordId = await principalMutationJournalRecordId(row);\n assertProjectionVerificationCurrent(input.stillCurrent);\n throw new UnreadablePrincipalMutationError(\n recordId,\n error.code === \"invalid_shape\" ? \"format\" : \"authentication\",\n );\n }\n assertProjectionVerificationCurrent(input.stillCurrent);\n return { row, mutation };\n}\n\n/** Discard only the inspected unreadable bytes; never parse them for submission. */\nexport async function discardUnreadableJournaledPrincipalMutation(\n input: JournalIdentity & {\n readonly recordId: string;\n readonly acknowledgeUnknownOutcome: true;\n },\n): Promise<boolean> {\n if (input.acknowledgeUnknownOutcome !== true)\n throw new Error(\n \"Discarding unreadable work requires acknowledging its unknown outcome\",\n );\n const expected = input.recordId;\n return getOrCreatePrincipalPolicyCoordinator(\n input.execSql,\n ).runJournalOperation(input.scope, async () => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const row = await new PrincipalMutationJournalRepository(\n input.execSql,\n ).loadPrincipalMutationJournal(\n await principalMutationJournalScopeId(input.scope),\n );\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!row) return false;\n if ((await principalMutationJournalRecordId(row)) !== expected)\n throw new Error(\n \"The unreadable principal mutation changed after inspection\",\n );\n let unreadable = false;\n try {\n await openPrincipalMutation({\n scope: input.scope,\n row,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n });\n } catch (error) {\n if (!(error instanceof KeyingVerificationError)) throw error;\n unreadable = true;\n }\n if (!unreadable)\n throw new Error(\n \"Readable principal mutations require ordinary abandonment\",\n );\n const removed = await new PrincipalMutationJournalRepository(\n input.execSql,\n ).clearPrincipalMutationJournal({\n row,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!removed)\n throw new Error(\n \"The unreadable principal mutation changed during discard\",\n );\n return true;\n });\n}\n\n/** Inspect authenticated authored work without retrying it or changing checkpoints. */\nexport async function readJournaledPrincipalMutation(\n input: JournalIdentity,\n): Promise<AuthoredPrincipalMutation | null> {\n // Inspection may observe an owned dispatch; all mutations still use the lane.\n return (await loadAuthenticatedMutation(input))?.mutation ?? null;\n}\n\n/**\n * An explicit host/user choice to stop retries, not a claim that the write failed.\n * The exact inspected request must still own the lane; ordinary recovery never\n * calls this. Future authoring must still verify the latest policy state.\n */\nexport async function abandonJournaledPrincipalMutation(\n input: JournalIdentity & {\n readonly mutation: AuthoredPrincipalMutation;\n readonly acknowledgeUnknownOutcome: true;\n },\n): Promise<boolean> {\n if (input.acknowledgeUnknownOutcome !== true)\n throw new Error(\n \"Abandoning authored work requires acknowledging its unknown outcome\",\n );\n const expected = canonicalKeyingJsonString(\n JSON.parse(JSON.stringify(input.mutation)),\n \"inspected authored mutation\",\n );\n return getOrCreatePrincipalPolicyCoordinator(\n input.execSql,\n ).runJournalOperation(input.scope, async () => {\n const saved = await loadAuthenticatedMutation(input);\n if (!saved) return false;\n if (\n canonicalKeyingJsonString(saved.mutation, \"saved authored mutation\") !==\n expected\n )\n throw new Error(\n \"The pending principal mutation changed after inspection\",\n );\n const removed = await new PrincipalMutationJournalRepository(\n input.execSql,\n ).clearPrincipalMutationJournal({\n row: saved.row,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!removed)\n throw new Error(\n \"The pending principal mutation changed during abandonment\",\n );\n return true;\n });\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
2
- import { claimPrincipalMutationJournal, clearPrincipalMutationJournal, loadPrincipalMutationJournal, } from "../../../data/persistence/principalMutationJournalPersistence.js";
2
+ import { PrincipalMutationJournalRepository, } from "../../../data/persistence/principalMutationJournalPersistence.js";
3
3
  import { openPrincipalMutation, principalMutationJournalScopeId, sealPrincipalMutation, } from "../../../data/principals/principalMutationJournal.js";
4
4
  import { getOrCreatePrincipalPolicyCoordinator } from "../../../data/principals/principalPolicyCoordinator.js";
5
5
  import { assertAuthoredPrincipalOperationReceipt, } from "./principalOperationReceipt.js";
@@ -47,8 +47,7 @@ async function submitSavedMutation(input, row, recovering) {
47
47
  // an earlier disconnected attempt committed. Preserve the original intent.
48
48
  throw new PrincipalMutationOutcomeUnknownError();
49
49
  }
50
- await clearPrincipalMutationJournal({
51
- execSql: input.execSql,
50
+ await new PrincipalMutationJournalRepository(input.execSql).clearPrincipalMutationJournal({
52
51
  row,
53
52
  stillCurrent: input.stillCurrent,
54
53
  });
@@ -60,8 +59,7 @@ export async function submitJournaledPrincipalMutation(input) {
60
59
  return getOrCreatePrincipalPolicyCoordinator(input.execSql).runJournalOperation(input.scope, async () => {
61
60
  assertProjectionVerificationCurrent(input.stillCurrent);
62
61
  const row = await sealPrincipalMutation(input);
63
- await claimPrincipalMutationJournal({
64
- execSql: input.execSql,
62
+ await new PrincipalMutationJournalRepository(input.execSql).claimPrincipalMutationJournal({
65
63
  row,
66
64
  stillCurrent: input.stillCurrent,
67
65
  });
@@ -72,7 +70,7 @@ export async function submitJournaledPrincipalMutation(input) {
72
70
  export async function recoverJournaledPrincipalMutation(input) {
73
71
  return getOrCreatePrincipalPolicyCoordinator(input.execSql).runJournalOperation(input.scope, async () => {
74
72
  assertProjectionVerificationCurrent(input.stillCurrent);
75
- const row = await loadPrincipalMutationJournal(input.execSql, await principalMutationJournalScopeId(input.scope));
73
+ const row = await new PrincipalMutationJournalRepository(input.execSql).loadPrincipalMutationJournal(await principalMutationJournalScopeId(input.scope));
76
74
  assertProjectionVerificationCurrent(input.stillCurrent);
77
75
  if (!row)
78
76
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"principalMutationJournalSession.js","sourceRoot":"","sources":["principalMutationJournalSession.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,EAC7B,4BAA4B,GAE7B,MAAM,+DAA+D,CAAC;AACvE,OAAO,EAEL,qBAAqB,EAErB,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,qCAAqC,EAAE,MAAM,qDAAqD,CAAC;AAE5G,OAAO,EACL,uCAAuC,GAExC,MAAM,6BAA6B,CAAC;AAcrC,MAAM,OAAO,oCAAqC,SAAQ,KAAK;IAC7D,YAAY,OAAsB;QAChC,KAAK,CACH,wHAAwH,EACxH,OAAO,CACR,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sCAAsC,CAAC;IACrD,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,MAAsB;IACjD,IAAI,MAAM,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IAC5B,8EAA8E;IAC9E,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACzC,OAAO,CACL,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;QACtD,CAAC,MAAM,CAAC,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E,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { RequestResult } from \"@tearleads/api-client\";\nimport type { SigningKeyPair } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport {\n claimPrincipalMutationJournal,\n clearPrincipalMutationJournal,\n loadPrincipalMutationJournal,\n type PrincipalMutationJournalRow,\n} from \"../../../data/persistence/principalMutationJournalPersistence\";\nimport {\n type AuthoredPrincipalMutation,\n openPrincipalMutation,\n type PrincipalMutationJournalScope,\n principalMutationJournalScopeId,\n sealPrincipalMutation,\n} from \"../../../data/principals/principalMutationJournal\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../../data/principals/principalPolicyCoordinator\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n assertAuthoredPrincipalOperationReceipt,\n type PrincipalMutationResponse,\n} from \"./principalOperationReceipt\";\n\ntype MutationResult = RequestResult<PrincipalMutationResponse>;\n\nexport interface PrincipalMutationJournalContext {\n readonly execSql: ExecSql;\n readonly scope: PrincipalMutationJournalScope;\n readonly signingKeyPair: SigningKeyPair;\n readonly stillCurrent: () => boolean;\n readonly submit: (\n mutation: AuthoredPrincipalMutation,\n ) => Promise<MutationResult>;\n}\n\nexport class PrincipalMutationOutcomeUnknownError extends Error {\n constructor(options?: ErrorOptions) {\n super(\n \"A saved policy request may have committed; resolve its outcome or explicitly abandon its retry before another mutation\",\n options,\n );\n this.name = \"PrincipalMutationOutcomeUnknownError\";\n }\n}\n\nfunction knownInitialRefusal(result: MutationResult): boolean {\n if (result.ok) return false;\n // ApiClient separates pre-dispatch cancellation from an uncertain sent write.\n if (result.kind === \"cancelled\") return true;\n if (result.kind !== \"http\") return false;\n return (\n [400, 401, 402, 403, 409].includes(result.status ?? 0) ||\n (result.status === 503 &&\n result.code === \"principal_history_preparation_unavailable\")\n );\n}\n\nasync function submitSavedMutation(\n input: PrincipalMutationJournalContext,\n row: PrincipalMutationJournalRow,\n recovering: boolean,\n): Promise<{ mutation: AuthoredPrincipalMutation; result: MutationResult }> {\n const mutation = await openPrincipalMutation({\n scope: input.scope,\n row,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n // Keep the authenticated copy for acknowledgement checks even if a transport\n // mutates its argument while preparing or retrying the HTTP request.\n let result: MutationResult;\n try {\n result = await input.submit(structuredClone(mutation));\n } catch (cause) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n throw new PrincipalMutationOutcomeUnknownError({ cause });\n }\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (result.ok) {\n await assertAuthoredPrincipalOperationReceipt(mutation, result.data);\n } else if (recovering || !knownInitialRefusal(result)) {\n // A refusal today (including loss of admin access) cannot establish whether\n // an earlier disconnected attempt committed. Preserve the original intent.\n throw new PrincipalMutationOutcomeUnknownError();\n }\n await clearPrincipalMutationJournal({\n execSql: input.execSql,\n row,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n return { mutation, result };\n}\n\n/** No HTTP begins until the exact authored request is durably claimed. */\nexport async function submitJournaledPrincipalMutation(\n input: PrincipalMutationJournalContext & {\n readonly mutation: AuthoredPrincipalMutation;\n },\n): Promise<MutationResult> {\n return getOrCreatePrincipalPolicyCoordinator(\n input.execSql,\n ).runJournalOperation(input.scope, async () => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const row = await sealPrincipalMutation(input);\n await claimPrincipalMutationJournal({\n execSql: input.execSql,\n row,\n stillCurrent: input.stillCurrent,\n });\n return (await submitSavedMutation(input, row, false)).result;\n });\n}\n\n/** Retry only authenticated saved bytes, never an application mutation callback. */\nexport async function recoverJournaledPrincipalMutation(\n input: PrincipalMutationJournalContext,\n): Promise<{\n readonly mutation: AuthoredPrincipalMutation;\n readonly response: PrincipalMutationResponse;\n} | null> {\n return getOrCreatePrincipalPolicyCoordinator(\n input.execSql,\n ).runJournalOperation(input.scope, async () => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const row = await loadPrincipalMutationJournal(\n input.execSql,\n await principalMutationJournalScopeId(input.scope),\n );\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!row) return null;\n const { mutation, result } = await submitSavedMutation(input, row, true);\n if (!result.ok) throw new PrincipalMutationOutcomeUnknownError();\n return { mutation, response: result.data };\n });\n}\n"]}
1
+ {"version":3,"file":"principalMutationJournalSession.js","sourceRoot":"","sources":["principalMutationJournalSession.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EACL,kCAAkC,GAEnC,MAAM,+DAA+D,CAAC;AACvE,OAAO,EAEL,qBAAqB,EAErB,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,qCAAqC,EAAE,MAAM,qDAAqD,CAAC;AAE5G,OAAO,EACL,uCAAuC,GAExC,MAAM,6BAA6B,CAAC;AAcrC,MAAM,OAAO,oCAAqC,SAAQ,KAAK;IAC7D,YAAY,OAAsB;QAChC,KAAK,CACH,wHAAwH,EACxH,OAAO,CACR,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sCAAsC,CAAC;IACrD,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,MAAsB;IACjD,IAAI,MAAM,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IAC5B,8EAA8E;IAC9E,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACzC,OAAO,CACL,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;QACtD,CAAC,MAA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CAAC,EAAE;YAAE,MAAM,IAAI,oCAAoC,EAAE,CAAC;QACjE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { RequestResult } from \"@tearleads/api-client\";\nimport type { SigningKeyPair } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport {\n PrincipalMutationJournalRepository,\n type PrincipalMutationJournalRow,\n} from \"../../../data/persistence/principalMutationJournalPersistence\";\nimport {\n type AuthoredPrincipalMutation,\n openPrincipalMutation,\n type PrincipalMutationJournalScope,\n principalMutationJournalScopeId,\n sealPrincipalMutation,\n} from \"../../../data/principals/principalMutationJournal\";\nimport { getOrCreatePrincipalPolicyCoordinator } from \"../../../data/principals/principalPolicyCoordinator\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n assertAuthoredPrincipalOperationReceipt,\n type PrincipalMutationResponse,\n} from \"./principalOperationReceipt\";\n\ntype MutationResult = RequestResult<PrincipalMutationResponse>;\n\nexport interface PrincipalMutationJournalContext {\n readonly execSql: ExecSql;\n readonly scope: PrincipalMutationJournalScope;\n readonly signingKeyPair: SigningKeyPair;\n readonly stillCurrent: () => boolean;\n readonly submit: (\n mutation: AuthoredPrincipalMutation,\n ) => Promise<MutationResult>;\n}\n\nexport class PrincipalMutationOutcomeUnknownError extends Error {\n constructor(options?: ErrorOptions) {\n super(\n \"A saved policy request may have committed; resolve its outcome or explicitly abandon its retry before another mutation\",\n options,\n );\n this.name = \"PrincipalMutationOutcomeUnknownError\";\n }\n}\n\nfunction knownInitialRefusal(result: MutationResult): boolean {\n if (result.ok) return false;\n // ApiClient separates pre-dispatch cancellation from an uncertain sent write.\n if (result.kind === \"cancelled\") return true;\n if (result.kind !== \"http\") return false;\n return (\n [400, 401, 402, 403, 409].includes(result.status ?? 0) ||\n (result.status === 503 &&\n result.code === \"principal_history_preparation_unavailable\")\n );\n}\n\nasync function submitSavedMutation(\n input: PrincipalMutationJournalContext,\n row: PrincipalMutationJournalRow,\n recovering: boolean,\n): Promise<{ mutation: AuthoredPrincipalMutation; result: MutationResult }> {\n const mutation = await openPrincipalMutation({\n scope: input.scope,\n row,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n // Keep the authenticated copy for acknowledgement checks even if a transport\n // mutates its argument while preparing or retrying the HTTP request.\n let result: MutationResult;\n try {\n result = await input.submit(structuredClone(mutation));\n } catch (cause) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n throw new PrincipalMutationOutcomeUnknownError({ cause });\n }\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (result.ok) {\n await assertAuthoredPrincipalOperationReceipt(mutation, result.data);\n } else if (recovering || !knownInitialRefusal(result)) {\n // A refusal today (including loss of admin access) cannot establish whether\n // an earlier disconnected attempt committed. Preserve the original intent.\n throw new PrincipalMutationOutcomeUnknownError();\n }\n await new PrincipalMutationJournalRepository(\n input.execSql,\n ).clearPrincipalMutationJournal({\n row,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n return { mutation, result };\n}\n\n/** No HTTP begins until the exact authored request is durably claimed. */\nexport async function submitJournaledPrincipalMutation(\n input: PrincipalMutationJournalContext & {\n readonly mutation: AuthoredPrincipalMutation;\n },\n): Promise<MutationResult> {\n return getOrCreatePrincipalPolicyCoordinator(\n input.execSql,\n ).runJournalOperation(input.scope, async () => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const row = await sealPrincipalMutation(input);\n await new PrincipalMutationJournalRepository(\n input.execSql,\n ).claimPrincipalMutationJournal({\n row,\n stillCurrent: input.stillCurrent,\n });\n return (await submitSavedMutation(input, row, false)).result;\n });\n}\n\n/** Retry only authenticated saved bytes, never an application mutation callback. */\nexport async function recoverJournaledPrincipalMutation(\n input: PrincipalMutationJournalContext,\n): Promise<{\n readonly mutation: AuthoredPrincipalMutation;\n readonly response: PrincipalMutationResponse;\n} | null> {\n return getOrCreatePrincipalPolicyCoordinator(\n input.execSql,\n ).runJournalOperation(input.scope, async () => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n const row = await new PrincipalMutationJournalRepository(\n input.execSql,\n ).loadPrincipalMutationJournal(\n await principalMutationJournalScopeId(input.scope),\n );\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!row) return null;\n const { mutation, result } = await submitSavedMutation(input, row, true);\n if (!result.ok) throw new PrincipalMutationOutcomeUnknownError();\n return { mutation, response: result.data };\n });\n}\n"]}