@tearleads/client-sdk 0.1.248 → 0.1.250

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 (178) hide show
  1. package/client/organizations/index.js +5 -3
  2. package/client/organizations/index.js.map +1 -1
  3. package/client/organizations/organizationGroupPresentation.d.ts +1 -1
  4. package/client/organizations/organizationGroupPresentation.js.map +1 -1
  5. package/client/organizations/organizationLeaveRequestVerifier.js +21 -0
  6. package/client/organizations/organizationLeaveRequestVerifier.js.map +1 -0
  7. package/client/organizations/{organizationReadModels.d.ts → organizationReadModelCoordinator.d.ts} +18 -16
  8. package/client/organizations/organizationReadModelCoordinator.js +2 -0
  9. package/client/organizations/organizationReadModelCoordinator.js.map +1 -0
  10. package/client/organizations/organizationReadModelPresentation.js +51 -0
  11. package/client/organizations/organizationReadModelPresentation.js.map +1 -0
  12. package/client/organizations/organizationReadModelScopes.js +37 -0
  13. package/client/organizations/organizationReadModelScopes.js.map +1 -0
  14. package/client/organizations/organizationReadModels.js +131 -88
  15. package/client/organizations/organizationReadModels.js.map +1 -1
  16. package/client/organizations/organizationsTypes.d.ts +13 -5
  17. package/client/organizations/organizationsTypes.js.map +1 -1
  18. package/client/organizations/principalMutations.d.ts +18 -2
  19. package/client/organizations/principalMutations.js +29 -15
  20. package/client/organizations/principalMutations.js.map +1 -1
  21. package/client/runtime/principalMutationApi.d.ts +2 -0
  22. package/client/runtime/principalMutationApi.js +2 -0
  23. package/client/runtime/principalMutationApi.js.map +1 -1
  24. package/client/runtime/principalMutationDispatch.js +47 -10
  25. package/client/runtime/principalMutationDispatch.js.map +1 -1
  26. package/client/runtime/workflowRuntime.js +5 -4
  27. package/client/runtime/workflowRuntime.js.map +1 -1
  28. package/data/containers/shared/mutationRequestOptions.d.ts +2 -0
  29. package/data/containers/shared/mutationRequestOptions.js.map +1 -1
  30. package/data/containers/shared/types.d.ts +12 -2
  31. package/data/containers/shared/types.js.map +1 -1
  32. package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js +1 -4
  33. package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js.map +1 -1
  34. package/data/persistence/organizations/organizationReadModelRepository.js +20 -2
  35. package/data/persistence/organizations/organizationReadModelRepository.js.map +1 -1
  36. package/data/persistence/principalPolicy/heldOrganizationDirectories.js +6 -1
  37. package/data/persistence/principalPolicy/heldOrganizationDirectories.js.map +1 -1
  38. package/data/persistence/principalPolicy/principalPolicyBundleIntegrity.js +1 -1
  39. package/data/persistence/principalPolicy/principalPolicyBundleIntegrity.js.map +1 -1
  40. package/data/persistence/principalPolicy/verifiedPrincipalPolicyCurrent.js +1 -5
  41. package/data/persistence/principalPolicy/verifiedPrincipalPolicyCurrent.js.map +1 -1
  42. package/data/principals/organizationGroupDirectoryRequest.js +0 -2
  43. package/data/principals/organizationGroupDirectoryRequest.js.map +1 -1
  44. package/data/principals/organizationPolicyRequest.js +0 -2
  45. package/data/principals/organizationPolicyRequest.js.map +1 -1
  46. package/data/principals/principalPolicyRequest.js +0 -2
  47. package/data/principals/principalPolicyRequest.js.map +1 -1
  48. package/internal/api-client/ApiClient.d.ts +4 -59
  49. package/internal/api-client/client/apiClientContext.d.ts +0 -30
  50. package/internal/api-client/client/containerMutations.d.ts +2 -2
  51. package/internal/api-client/client/containerMutations.js +2 -1
  52. package/internal/api-client/client/containerMutations.js.map +1 -1
  53. package/internal/api-client/client/documents.d.ts +0 -12
  54. package/internal/api-client/client/principalPolicies.d.ts +3 -18
  55. package/internal/api-client/client/writerProjections.d.ts +0 -12
  56. package/internal/api-client/heldDirectoryCitations.d.ts +8 -4
  57. package/internal/api-client/heldDirectoryCitations.js +6 -10
  58. package/internal/api-client/heldDirectoryCitations.js.map +1 -1
  59. package/internal/api-client/organizationPolicyHistory.d.ts +0 -6
  60. package/internal/api-client/principalPolicyRequests.d.ts +2 -18
  61. package/internal/api-client/principalPolicyRequests.js +6 -4
  62. package/internal/api-client/principalPolicyRequests.js.map +1 -1
  63. package/internal/api-client/routes/containers/mutations.js +3 -3
  64. package/internal/api-client/routes/containers/mutations.js.map +1 -1
  65. package/internal/api-client/routes/organizations/createGroup.js +3 -5
  66. package/internal/api-client/routes/organizations/createGroup.js.map +1 -1
  67. package/internal/api-client/routes/principals/policy.js +2 -5
  68. package/internal/api-client/routes/principals/policy.js.map +1 -1
  69. package/internal/api-client/types.d.ts +6 -0
  70. package/internal/api-client/types.js.map +1 -1
  71. package/internal/api-client/verifiedManifestCitations.js +3 -3
  72. package/internal/api-client/verifiedManifestCitations.js.map +1 -1
  73. package/internal/crypto/index.d.ts +1 -1
  74. package/internal/crypto/index.js.map +1 -1
  75. package/internal/crypto/keying/principalPolicyPayload.js +2 -12
  76. package/internal/crypto/keying/principalPolicyPayload.js.map +1 -1
  77. package/internal/crypto/keying/principalPolicyTypes.d.ts +5 -6
  78. package/internal/crypto/keying/principalPolicyTypes.js.map +1 -1
  79. package/internal/crypto/principalState.d.ts +1 -1
  80. package/internal/crypto/principalState.js.map +1 -1
  81. package/internal/crypto/principalStateTypes.d.ts +0 -1
  82. package/internal/crypto/principalStateTypes.js.map +1 -1
  83. package/internal/validators/operation/auth.d.ts +0 -24
  84. package/internal/validators/operation/containerMutations.d.ts +20 -3
  85. package/internal/validators/operation/containerMutations.js +18 -20
  86. package/internal/validators/operation/containerMutations.js.map +1 -1
  87. package/internal/validators/operation/documentMutations.d.ts +0 -48
  88. package/internal/validators/operation/index.d.ts +1 -1
  89. package/internal/validators/operation/index.js +1 -1
  90. package/internal/validators/operation/index.js.map +1 -1
  91. package/internal/validators/operation/organizationPolicyHistory.d.ts +0 -24
  92. package/internal/validators/operation/organizations.d.ts +17 -49
  93. package/internal/validators/operation/organizations.js +4 -2
  94. package/internal/validators/operation/organizations.js.map +1 -1
  95. package/internal/validators/operation/principals.d.ts +17 -57
  96. package/internal/validators/operation/principals.js +5 -2
  97. package/internal/validators/operation/principals.js.map +1 -1
  98. package/internal/validators/operation/writerProjections.d.ts +0 -48
  99. package/internal/validators/request/index.d.ts +1 -1
  100. package/internal/validators/request/index.js +1 -1
  101. package/internal/validators/request/index.js.map +1 -1
  102. package/internal/validators/request/organization.d.ts +15 -32
  103. package/internal/validators/request/organization.js +8 -0
  104. package/internal/validators/request/organization.js.map +1 -1
  105. package/internal/validators/request/organizationProvisioning.d.ts +0 -72
  106. package/internal/validators/request/principal.d.ts +4 -48
  107. package/internal/validators/request/principal.js +4 -2
  108. package/internal/validators/request/principal.js.map +1 -1
  109. package/internal/validators/request/registration.d.ts +0 -24
  110. package/internal/validators/response/areas/organizations.d.ts +3 -2
  111. package/internal/validators/response/areas/organizations.js +3 -2
  112. package/internal/validators/response/areas/organizations.js.map +1 -1
  113. package/internal/validators/response/areas/principals.d.ts +1 -1
  114. package/internal/validators/response/areas/principals.js +1 -1
  115. package/internal/validators/response/areas/principals.js.map +1 -1
  116. package/internal/validators/response/committedReadModel.d.ts +697 -0
  117. package/internal/validators/response/committedReadModel.js +52 -0
  118. package/internal/validators/response/committedReadModel.js.map +1 -0
  119. package/internal/validators/response/container.d.ts +52 -48
  120. package/internal/validators/response/container.js +3 -3
  121. package/internal/validators/response/container.js.map +1 -1
  122. package/internal/validators/response/documentMutation.d.ts +0 -96
  123. package/internal/validators/response/organization.d.ts +0 -191
  124. package/internal/validators/response/organization.js +0 -7
  125. package/internal/validators/response/organization.js.map +1 -1
  126. package/internal/validators/response/organizationPolicyHistory.d.ts +0 -24
  127. package/internal/validators/response/organizationReadModel.d.ts +167 -0
  128. package/internal/validators/response/organizationReadModel.js +5 -0
  129. package/internal/validators/response/organizationReadModel.js.map +1 -1
  130. package/internal/validators/response/policyEvidenceWire.d.ts +5 -3
  131. package/internal/validators/response/policyEvidenceWire.js +6 -4
  132. package/internal/validators/response/policyEvidenceWire.js.map +1 -1
  133. package/internal/validators/response/principal.d.ts +0 -451
  134. package/internal/validators/response/principal.js +0 -8
  135. package/internal/validators/response/principal.js.map +1 -1
  136. package/internal/validators/response/principalPolicyPage.d.ts +0 -48
  137. package/internal/validators/response/principalSnapshot.d.ts +4 -24
  138. package/internal/validators/response/principalSnapshot.js +4 -6
  139. package/internal/validators/response/principalSnapshot.js.map +1 -1
  140. package/internal/validators/response/projectionPolicyEvidence.d.ts +0 -48
  141. package/package.json +1 -1
  142. package/workflows/container-contents/container-state/organizationHost.d.ts +9 -0
  143. package/workflows/container-contents/container-state/organizationHost.js.map +1 -1
  144. package/workflows/container-contents/container-state/remote.js +6 -0
  145. package/workflows/container-contents/container-state/remote.js.map +1 -1
  146. package/workflows/containers/child/share/index.d.ts +4 -2
  147. package/workflows/containers/child/share/index.js +37 -20
  148. package/workflows/containers/child/share/index.js.map +1 -1
  149. package/workflows/organizations/containerContentsHost.js +20 -1
  150. package/workflows/organizations/containerContentsHost.js.map +1 -1
  151. package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js +5 -1
  152. package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js.map +1 -1
  153. package/workflows/organizations/groupPolicy/currentPolicyMutationAcknowledgement.js +1 -6
  154. package/workflows/organizations/groupPolicy/currentPolicyMutationAcknowledgement.js.map +1 -1
  155. package/workflows/organizations/groupPolicy/groupPolicyMutationAcknowledgement.js +1 -6
  156. package/workflows/organizations/groupPolicy/groupPolicyMutationAcknowledgement.js.map +1 -1
  157. package/workflows/organizations/groups/createCurrentOrganizationGroup.js +8 -1
  158. package/workflows/organizations/groups/createCurrentOrganizationGroup.js.map +1 -1
  159. package/workflows/organizations/index.d.ts +1 -0
  160. package/workflows/organizations/index.js +1 -0
  161. package/workflows/organizations/index.js.map +1 -1
  162. package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js +4 -6
  163. package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js.map +1 -1
  164. package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js +1 -7
  165. package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js.map +1 -1
  166. package/workflows/organizations/readModel/committedReadModel.d.ts +66 -0
  167. package/workflows/organizations/readModel/committedReadModel.js +150 -0
  168. package/workflows/organizations/readModel/committedReadModel.js.map +1 -0
  169. package/workflows/organizations/readModel/readModelProjection.d.ts +15 -2
  170. package/workflows/organizations/readModel/readModelProjection.js +26 -4
  171. package/workflows/organizations/readModel/readModelProjection.js.map +1 -1
  172. package/workflows/principals/policyCache/principalPolicyCacheValidation.js +0 -13
  173. package/workflows/principals/policyCache/principalPolicyCacheValidation.js.map +1 -1
  174. package/workflows/principals/publicHistory/publicProjectionDirectory.js +4 -5
  175. package/workflows/principals/publicHistory/publicProjectionDirectory.js.map +1 -1
  176. package/workflows/registration/provisioningBootstrapBuilders.d.ts +0 -6
  177. package/workflows/registration/registrationPrincipalPolicyPersistence.js +1 -7
  178. package/workflows/registration/registrationPrincipalPolicyPersistence.js.map +1 -1
@@ -64,13 +64,7 @@ export declare const PrincipalPolicyPageResponseSchema: z.ZodType<{
64
64
  stateHash: string;
65
65
  };
66
66
  currentPayload: {
67
- cipherSuite: "aes-256-gcm";
68
67
  ciphertext: string;
69
- ciphertextHash: string;
70
- createdAt: string;
71
- principalId: string;
72
- principalType: "group" | "organization";
73
- stateHash: string;
74
68
  };
75
69
  currentProjection: {
76
70
  identityBundleFingerprint: string;
@@ -172,13 +166,7 @@ export declare const PrincipalPolicyPageResponseSchema: z.ZodType<{
172
166
  stateHash: string;
173
167
  };
174
168
  currentPayload: {
175
- cipherSuite: "aes-256-gcm";
176
169
  ciphertext: string;
177
- ciphertextHash: string;
178
- createdAt: string;
179
- principalId: string;
180
- principalType: "group" | "organization";
181
- stateHash: string;
182
170
  };
183
171
  currentProjection: {
184
172
  identityBundleFingerprint: string;
@@ -280,13 +268,7 @@ export declare const PrincipalPolicyPageResponseSchema: z.ZodType<{
280
268
  stateHash: string;
281
269
  };
282
270
  currentPayload: {
283
- cipherSuite: "aes-256-gcm";
284
271
  ciphertext: string;
285
- ciphertextHash: string;
286
- createdAt: string;
287
- principalId: string;
288
- principalType: "group" | "organization";
289
- stateHash: string;
290
272
  };
291
273
  currentProjection: {
292
274
  identityBundleFingerprint: string;
@@ -388,13 +370,7 @@ export declare const PrincipalPolicyPageResponseSchema: z.ZodType<{
388
370
  stateHash: string;
389
371
  };
390
372
  currentPayload: {
391
- cipherSuite: "aes-256-gcm";
392
373
  ciphertext: string;
393
- ciphertextHash: string;
394
- createdAt: string;
395
- principalId: string;
396
- principalType: "group" | "organization";
397
- stateHash: string;
398
374
  };
399
375
  currentProjection: {
400
376
  identityBundleFingerprint: string;
@@ -537,13 +513,7 @@ export declare const PrincipalPolicyReadResponseSchema: z.ZodUnion<readonly [z.Z
537
513
  stateHash: string;
538
514
  };
539
515
  currentPayload: {
540
- cipherSuite: "aes-256-gcm";
541
516
  ciphertext: string;
542
- ciphertextHash: string;
543
- createdAt: string;
544
- principalId: string;
545
- principalType: "group" | "organization";
546
- stateHash: string;
547
517
  };
548
518
  currentProjection: {
549
519
  identityBundleFingerprint: string;
@@ -645,13 +615,7 @@ export declare const PrincipalPolicyReadResponseSchema: z.ZodUnion<readonly [z.Z
645
615
  stateHash: string;
646
616
  };
647
617
  currentPayload: {
648
- cipherSuite: "aes-256-gcm";
649
618
  ciphertext: string;
650
- ciphertextHash: string;
651
- createdAt: string;
652
- principalId: string;
653
- principalType: "group" | "organization";
654
- stateHash: string;
655
619
  };
656
620
  currentProjection: {
657
621
  identityBundleFingerprint: string;
@@ -753,13 +717,7 @@ export declare const PrincipalPolicyReadResponseSchema: z.ZodUnion<readonly [z.Z
753
717
  stateHash: string;
754
718
  };
755
719
  currentPayload: {
756
- cipherSuite: "aes-256-gcm";
757
720
  ciphertext: string;
758
- ciphertextHash: string;
759
- createdAt: string;
760
- principalId: string;
761
- principalType: "group" | "organization";
762
- stateHash: string;
763
721
  };
764
722
  currentProjection: {
765
723
  identityBundleFingerprint: string;
@@ -861,13 +819,7 @@ export declare const PrincipalPolicyReadResponseSchema: z.ZodUnion<readonly [z.Z
861
819
  stateHash: string;
862
820
  };
863
821
  currentPayload: {
864
- cipherSuite: "aes-256-gcm";
865
822
  ciphertext: string;
866
- ciphertextHash: string;
867
- createdAt: string;
868
- principalId: string;
869
- principalType: "group" | "organization";
870
- stateHash: string;
871
823
  };
872
824
  currentProjection: {
873
825
  identityBundleFingerprint: string;
@@ -183,38 +183,18 @@ export declare const PrincipalContainerGrantResponseSchema: z.ZodType<{
183
183
  containerId: string;
184
184
  }>>;
185
185
  export type PrincipalContainerGrantResponse = z.infer<typeof PrincipalContainerGrantResponseSchema>;
186
+ /**
187
+ * A payload beside its state: only the ciphertext, which the reader checks
188
+ * against the state's signed `payloadCiphertextHash` (#2903 P23).
189
+ */
186
190
  export declare const PrincipalStatePayloadResponseSchema: z.ZodType<{
187
- cipherSuite: "aes-256-gcm";
188
191
  ciphertext: string;
189
- ciphertextHash: string;
190
- createdAt: string;
191
- principalId: string;
192
- principalType: "group" | "organization";
193
- stateHash: string;
194
192
  }, {
195
- cipherSuite: "aes-256-gcm";
196
193
  ciphertext: string;
197
- ciphertextHash: string;
198
- createdAt: string;
199
- principalId: string;
200
- principalType: "group" | "organization";
201
- stateHash: string;
202
194
  }, z.core.$ZodTypeInternals<{
203
- cipherSuite: "aes-256-gcm";
204
195
  ciphertext: string;
205
- ciphertextHash: string;
206
- createdAt: string;
207
- principalId: string;
208
- principalType: "group" | "organization";
209
- stateHash: string;
210
196
  }, {
211
- cipherSuite: "aes-256-gcm";
212
197
  ciphertext: string;
213
- ciphertextHash: string;
214
- createdAt: string;
215
- principalId: string;
216
- principalType: "group" | "organization";
217
- stateHash: string;
218
198
  }>>;
219
199
  export type PrincipalStatePayloadResponse = z.infer<typeof PrincipalStatePayloadResponseSchema>;
220
200
  export declare const PrincipalMemberEnvelopeResponseSchema: z.ZodType<{
@@ -41,14 +41,12 @@ export const PrincipalContainerGrantResponseSchema = loosePlainObject({
41
41
  accessLevel: z.literal(["admin", "read", "write"]),
42
42
  containerId: z.string(),
43
43
  });
44
+ /**
45
+ * A payload beside its state: only the ciphertext, which the reader checks
46
+ * against the state's signed `payloadCiphertextHash` (#2903 P23).
47
+ */
44
48
  export const PrincipalStatePayloadResponseSchema = loosePlainObject({
45
- cipherSuite: z.literal("aes-256-gcm"),
46
49
  ciphertext: z.string(),
47
- ciphertextHash: z.string(),
48
- createdAt: z.string(),
49
- principalId: z.string(),
50
- principalType: z.literal(["group", "organization"]),
51
- stateHash: z.string(),
52
50
  });
53
51
  export const PrincipalMemberEnvelopeResponseSchema = loosePlainObject({
54
52
  kemCipherText: z.string(),
@@ -1 +1 @@
1
- {"version":3,"file":"principalSnapshot.js","sourceRoot":"","sources":["principalSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,4BAA4B,EAC5B,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAEnB,MAAM,CAAC,MAAM,6CAA6C,GAAG,gBAAgB,CAAC;IAC5E,QAAQ,EAAE,4BAA4B,CAAC,MAAM,CAAC,gBAAgB,CAAC;IAC/D,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACjC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,OAAO,EAAE,4BAA4B,CAAC,MAAM,CAAC,gBAAgB,CAAC;CAC/D,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;IAC3D,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,sBAAsB,EAAE,CAAC,CAAC,MAAM,EAAE;IAClC,iBAAiB,EAAE,6CAA6C,CAAC,QAAQ,EAAE;IAC3E,UAAU,EAAE,wBAAwB;IACpC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,QAAQ,EAAE,4BAA4B,CAAC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AC;IACpE,aAAa,EAAE,WAAW,CAAC,qCAAqC,CAAC;IACjE,iBAAiB,EAAE,WAAW,CAAC,uCAAuC,CAAC;IACvE,YAAY,EAAE,4BAA4B;IAC1C,cAAc,EAAE,WAAW,CAAC,4CAA4C,CAAC;CAC1E,CAAC,CAAC;AAMH,MAAM,UAAU,wBAAwB,CACtC,KAAc;IAEd,OAAO,4BAA4B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,KAAc;IAEd,OAAO,mCAAmC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,yCAAyC,CACvD,KAAc;IAEd,OAAO,6CAA6C,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,wCAAwC,CACtD,KAAc;IAEd,OAAO,4CAA4C,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC/E,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n arraySchema,\n boundedPositiveIntegerSchema,\n loosePlainObject,\n nonNegativeIntegerSchema,\n sha256HexStringSchema,\n} from \"../schema\";\n\nexport const PrincipalStateExternalAuthorityResponseSchema = loosePlainObject({\n keyEpoch: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n keyFingerprint: z.string(),\n principalId: z.string(),\n principalType: z.literal(\"group\"),\n stateHash: z.string(),\n version: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n});\n\nexport type PrincipalStateExternalAuthorityResponse = z.infer<\n typeof PrincipalStateExternalAuthorityResponseSchema\n>;\n\nexport const PrincipalStateResponseSchema = loosePlainObject({\n createdAt: z.string(),\n encapsulationPublicKey: z.string(),\n externalAuthority: PrincipalStateExternalAuthorityResponseSchema.nullable(),\n grantCount: nonNegativeIntegerSchema,\n grantRoot: z.string(),\n keyEpoch: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n keyFingerprint: z.string(),\n memberCount: nonNegativeIntegerSchema,\n memberEnvelopesRoot: z.string(),\n membershipMode: z.literal(\"projection\"),\n membershipRoot: z.string(),\n payloadCiphertextHash: z.string(),\n prevStateHash: z.string().nullable(),\n principalId: z.string(),\n principalType: z.literal([\"group\", \"organization\"]),\n projectionRoot: z.string(),\n signature: z.string(),\n signedAt: z.string(),\n signerUserId: z.string(),\n signerUserKeyFingerprint: z.string(),\n stateHash: z.string(),\n version: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n});\n\nexport type PrincipalStateResponse = z.infer<\n typeof PrincipalStateResponseSchema\n>;\n\nexport const PrincipalProjectionMemberResponseSchema = loosePlainObject({\n identityBundleFingerprint: sha256HexStringSchema,\n role: z.literal([\"member\", \"admin\"]),\n userId: z.string(),\n});\n\nexport type PrincipalProjectionMemberResponse = z.infer<\n typeof PrincipalProjectionMemberResponseSchema\n>;\n\nexport const PrincipalContainerGrantResponseSchema = loosePlainObject({\n accessLevel: z.literal([\"admin\", \"read\", \"write\"]),\n containerId: z.string(),\n});\n\nexport type PrincipalContainerGrantResponse = z.infer<\n typeof PrincipalContainerGrantResponseSchema\n>;\n\nexport const PrincipalStatePayloadResponseSchema = loosePlainObject({\n cipherSuite: z.literal(\"aes-256-gcm\"),\n ciphertext: z.string(),\n ciphertextHash: z.string(),\n createdAt: z.string(),\n principalId: z.string(),\n principalType: z.literal([\"group\", \"organization\"]),\n stateHash: z.string(),\n});\n\nexport type PrincipalStatePayloadResponse = z.infer<\n typeof PrincipalStatePayloadResponseSchema\n>;\n\nexport const PrincipalMemberEnvelopeResponseSchema = loosePlainObject({\n kemCipherText: z.string(),\n memberKeyFingerprint: z.string(),\n userId: z.string(),\n wrappedKey: z.string(),\n});\n\nexport type PrincipalMemberEnvelopeResponse = z.infer<\n typeof PrincipalMemberEnvelopeResponseSchema\n>;\n\nexport const CurrentPrincipalMemberEnvelopesResponseSchema = loosePlainObject({\n envelopes: arraySchema(PrincipalMemberEnvelopeResponseSchema),\n epoch: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n principalId: z.string(),\n principalType: z.literal([\"group\", \"organization\"]),\n stateHash: z.string(),\n});\n\nexport type CurrentPrincipalMemberEnvelopesResponse = z.infer<\n typeof CurrentPrincipalMemberEnvelopesResponseSchema\n>;\n\nexport const PrincipalPolicyStateChainEntryResponseSchema = loosePlainObject({\n grants: arraySchema(PrincipalContainerGrantResponseSchema),\n projection: arraySchema(PrincipalProjectionMemberResponseSchema),\n state: PrincipalStateResponseSchema,\n});\n\nexport type PrincipalPolicyStateChainEntryResponse = z.infer<\n typeof PrincipalPolicyStateChainEntryResponseSchema\n>;\n\nexport const PrincipalPolicySnapshotResponseSchema = loosePlainObject({\n currentGrants: arraySchema(PrincipalContainerGrantResponseSchema),\n currentProjection: arraySchema(PrincipalProjectionMemberResponseSchema),\n currentState: PrincipalStateResponseSchema,\n previousStates: arraySchema(PrincipalPolicyStateChainEntryResponseSchema),\n});\n\nexport type PrincipalPolicySnapshotResponse = z.infer<\n typeof PrincipalPolicySnapshotResponseSchema\n>;\n\nexport function isPrincipalStateResponse(\n value: unknown,\n): value is PrincipalStateResponse {\n return PrincipalStateResponseSchema.safeParse(value).success;\n}\n\nexport function isPrincipalStatePayloadResponse(\n value: unknown,\n): value is PrincipalStatePayloadResponse {\n return PrincipalStatePayloadResponseSchema.safeParse(value).success;\n}\n\nexport function isCurrentPrincipalMemberEnvelopesResponse(\n value: unknown,\n): value is CurrentPrincipalMemberEnvelopesResponse {\n return CurrentPrincipalMemberEnvelopesResponseSchema.safeParse(value).success;\n}\n\nexport function isPrincipalPolicyStateChainEntryResponse(\n value: unknown,\n): value is PrincipalPolicyStateChainEntryResponse {\n return PrincipalPolicyStateChainEntryResponseSchema.safeParse(value).success;\n}\n"]}
1
+ {"version":3,"file":"principalSnapshot.js","sourceRoot":"","sources":["principalSnapshot.ts"],"names":[],"mappings":"A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\n boundedPositiveIntegerSchema,\n loosePlainObject,\n nonNegativeIntegerSchema,\n sha256HexStringSchema,\n} from \"../schema\";\n\nexport const PrincipalStateExternalAuthorityResponseSchema = loosePlainObject({\n keyEpoch: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n keyFingerprint: z.string(),\n principalId: z.string(),\n principalType: z.literal(\"group\"),\n stateHash: z.string(),\n version: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n});\n\nexport type PrincipalStateExternalAuthorityResponse = z.infer<\n typeof PrincipalStateExternalAuthorityResponseSchema\n>;\n\nexport const PrincipalStateResponseSchema = loosePlainObject({\n createdAt: z.string(),\n encapsulationPublicKey: z.string(),\n externalAuthority: PrincipalStateExternalAuthorityResponseSchema.nullable(),\n grantCount: nonNegativeIntegerSchema,\n grantRoot: z.string(),\n keyEpoch: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n keyFingerprint: z.string(),\n memberCount: nonNegativeIntegerSchema,\n memberEnvelopesRoot: z.string(),\n membershipMode: z.literal(\"projection\"),\n membershipRoot: z.string(),\n payloadCiphertextHash: z.string(),\n prevStateHash: z.string().nullable(),\n principalId: z.string(),\n principalType: z.literal([\"group\", \"organization\"]),\n projectionRoot: z.string(),\n signature: z.string(),\n signedAt: z.string(),\n signerUserId: z.string(),\n signerUserKeyFingerprint: z.string(),\n stateHash: z.string(),\n version: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n});\n\nexport type PrincipalStateResponse = z.infer<\n typeof PrincipalStateResponseSchema\n>;\n\nexport const PrincipalProjectionMemberResponseSchema = loosePlainObject({\n identityBundleFingerprint: sha256HexStringSchema,\n role: z.literal([\"member\", \"admin\"]),\n userId: z.string(),\n});\n\nexport type PrincipalProjectionMemberResponse = z.infer<\n typeof PrincipalProjectionMemberResponseSchema\n>;\n\nexport const PrincipalContainerGrantResponseSchema = loosePlainObject({\n accessLevel: z.literal([\"admin\", \"read\", \"write\"]),\n containerId: z.string(),\n});\n\nexport type PrincipalContainerGrantResponse = z.infer<\n typeof PrincipalContainerGrantResponseSchema\n>;\n\n/**\n * A payload beside its state: only the ciphertext, which the reader checks\n * against the state's signed `payloadCiphertextHash` (#2903 P23).\n */\nexport const PrincipalStatePayloadResponseSchema = loosePlainObject({\n ciphertext: z.string(),\n});\n\nexport type PrincipalStatePayloadResponse = z.infer<\n typeof PrincipalStatePayloadResponseSchema\n>;\n\nexport const PrincipalMemberEnvelopeResponseSchema = loosePlainObject({\n kemCipherText: z.string(),\n memberKeyFingerprint: z.string(),\n userId: z.string(),\n wrappedKey: z.string(),\n});\n\nexport type PrincipalMemberEnvelopeResponse = z.infer<\n typeof PrincipalMemberEnvelopeResponseSchema\n>;\n\nexport const CurrentPrincipalMemberEnvelopesResponseSchema = loosePlainObject({\n envelopes: arraySchema(PrincipalMemberEnvelopeResponseSchema),\n epoch: boundedPositiveIntegerSchema(Number.MAX_SAFE_INTEGER),\n principalId: z.string(),\n principalType: z.literal([\"group\", \"organization\"]),\n stateHash: z.string(),\n});\n\nexport type CurrentPrincipalMemberEnvelopesResponse = z.infer<\n typeof CurrentPrincipalMemberEnvelopesResponseSchema\n>;\n\nexport const PrincipalPolicyStateChainEntryResponseSchema = loosePlainObject({\n grants: arraySchema(PrincipalContainerGrantResponseSchema),\n projection: arraySchema(PrincipalProjectionMemberResponseSchema),\n state: PrincipalStateResponseSchema,\n});\n\nexport type PrincipalPolicyStateChainEntryResponse = z.infer<\n typeof PrincipalPolicyStateChainEntryResponseSchema\n>;\n\nexport const PrincipalPolicySnapshotResponseSchema = loosePlainObject({\n currentGrants: arraySchema(PrincipalContainerGrantResponseSchema),\n currentProjection: arraySchema(PrincipalProjectionMemberResponseSchema),\n currentState: PrincipalStateResponseSchema,\n previousStates: arraySchema(PrincipalPolicyStateChainEntryResponseSchema),\n});\n\nexport type PrincipalPolicySnapshotResponse = z.infer<\n typeof PrincipalPolicySnapshotResponseSchema\n>;\n\nexport function isPrincipalStateResponse(\n value: unknown,\n): value is PrincipalStateResponse {\n return PrincipalStateResponseSchema.safeParse(value).success;\n}\n\nexport function isPrincipalStatePayloadResponse(\n value: unknown,\n): value is PrincipalStatePayloadResponse {\n return PrincipalStatePayloadResponseSchema.safeParse(value).success;\n}\n\nexport function isCurrentPrincipalMemberEnvelopesResponse(\n value: unknown,\n): value is CurrentPrincipalMemberEnvelopesResponse {\n return CurrentPrincipalMemberEnvelopesResponseSchema.safeParse(value).success;\n}\n\nexport function isPrincipalPolicyStateChainEntryResponse(\n value: unknown,\n): value is PrincipalPolicyStateChainEntryResponse {\n return PrincipalPolicyStateChainEntryResponseSchema.safeParse(value).success;\n}\n"]}
@@ -22,13 +22,7 @@ export declare const ProjectionPolicyEvidenceResponseSchema: z.ZodType<{
22
22
  version: number;
23
23
  };
24
24
  payload: {
25
- cipherSuite: "aes-256-gcm";
26
25
  ciphertext: string;
27
- ciphertextHash: string;
28
- createdAt: string;
29
- principalId: string;
30
- principalType: "group" | "organization";
31
- stateHash: string;
32
26
  };
33
27
  }[];
34
28
  groups: {
@@ -64,13 +58,7 @@ export declare const ProjectionPolicyEvidenceResponseSchema: z.ZodType<{
64
58
  version: number;
65
59
  };
66
60
  payload: {
67
- cipherSuite: "aes-256-gcm";
68
61
  ciphertext: string;
69
- ciphertextHash: string;
70
- createdAt: string;
71
- principalId: string;
72
- principalType: "group" | "organization";
73
- stateHash: string;
74
62
  };
75
63
  }[];
76
64
  groups: {
@@ -106,13 +94,7 @@ export declare const ProjectionPolicyEvidenceResponseSchema: z.ZodType<{
106
94
  version: number;
107
95
  };
108
96
  payload: {
109
- cipherSuite: "aes-256-gcm";
110
97
  ciphertext: string;
111
- ciphertextHash: string;
112
- createdAt: string;
113
- principalId: string;
114
- principalType: "group" | "organization";
115
- stateHash: string;
116
98
  };
117
99
  }[];
118
100
  groups: {
@@ -148,13 +130,7 @@ export declare const ProjectionPolicyEvidenceResponseSchema: z.ZodType<{
148
130
  version: number;
149
131
  };
150
132
  payload: {
151
- cipherSuite: "aes-256-gcm";
152
133
  ciphertext: string;
153
- ciphertextHash: string;
154
- createdAt: string;
155
- principalId: string;
156
- principalType: "group" | "organization";
157
- stateHash: string;
158
134
  };
159
135
  }[];
160
136
  groups: {
@@ -197,13 +173,7 @@ export declare const ProjectionPolicyEvidenceWireResponseSchema: z.ZodType<{
197
173
  version: number;
198
174
  };
199
175
  payload: {
200
- cipherSuite: "aes-256-gcm";
201
176
  ciphertext: string;
202
- ciphertextHash: string;
203
- createdAt: string;
204
- principalId: string;
205
- principalType: "group" | "organization";
206
- stateHash: string;
207
177
  } | null;
208
178
  }[];
209
179
  groups: {
@@ -239,13 +209,7 @@ export declare const ProjectionPolicyEvidenceWireResponseSchema: z.ZodType<{
239
209
  version: number;
240
210
  };
241
211
  payload: {
242
- cipherSuite: "aes-256-gcm";
243
212
  ciphertext: string;
244
- ciphertextHash: string;
245
- createdAt: string;
246
- principalId: string;
247
- principalType: "group" | "organization";
248
- stateHash: string;
249
213
  } | null;
250
214
  }[];
251
215
  groups: {
@@ -281,13 +245,7 @@ export declare const ProjectionPolicyEvidenceWireResponseSchema: z.ZodType<{
281
245
  version: number;
282
246
  };
283
247
  payload: {
284
- cipherSuite: "aes-256-gcm";
285
248
  ciphertext: string;
286
- ciphertextHash: string;
287
- createdAt: string;
288
- principalId: string;
289
- principalType: "group" | "organization";
290
- stateHash: string;
291
249
  } | null;
292
250
  }[];
293
251
  groups: {
@@ -323,13 +281,7 @@ export declare const ProjectionPolicyEvidenceWireResponseSchema: z.ZodType<{
323
281
  version: number;
324
282
  };
325
283
  payload: {
326
- cipherSuite: "aes-256-gcm";
327
284
  ciphertext: string;
328
- ciphertextHash: string;
329
- createdAt: string;
330
- principalId: string;
331
- principalType: "group" | "organization";
332
- stateHash: string;
333
285
  } | null;
334
286
  }[];
335
287
  groups: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/client-sdk",
3
- "version": "0.1.248",
3
+ "version": "0.1.250",
4
4
  "description": "React-free Tearleads client runtime: local SQLite persistence, keys, sync, encrypted blobs, and domain workflows.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -1,5 +1,7 @@
1
1
  import type { ContainerAccessManifestState, ReferencedPrincipalHead } from "../../../internal/crypto/index.js";
2
+ import type { ContainerShareCommittedReadModel } from "../../../data/containers/shared/types.js";
2
3
  import type { PrincipalPolicyCurrentEvidence } from "../../../data/principalContracts/principalPolicyEvidence.js";
4
+ import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
3
5
  import type { createRuntimeCurrentGroupShare, shareRemoteContainerWithGroup } from "../../organizations/groupShare/index.js";
4
6
  import type { PrincipalPolicyRuntime } from "../../principals/principalPolicyService.js";
5
7
  type GroupShare = typeof shareRemoteContainerWithGroup;
@@ -31,6 +33,13 @@ export type ContainerContentsCurrentGroupPolicyReader = <Result>(input: {
31
33
  * them.
32
34
  */
33
35
  export interface ContainerContentsOrganizationHost {
36
+ /** Sends a share's held read-model cursor and keeps the delta it carries. */
37
+ readonly committedReadModel: (scope: {
38
+ readonly domainScope: object;
39
+ readonly execSql: ExecSql;
40
+ readonly organizationId: string;
41
+ readonly userId: string;
42
+ }) => ContainerShareCommittedReadModel;
34
43
  /** Shares with a group on current evidence; `undefined` without private paged recovery. */
35
44
  readonly createCurrentGroupShare: (runtime: GroupShareRuntime) => GroupShare | undefined;
36
45
  /** Reads current group policy; `undefined` without private paged recovery. */
@@ -1 +1 @@
1
- {"version":3,"file":"organizationHost.js","sourceRoot":"","sources":["organizationHost.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ContainerAccessManifestState,\n ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principalContracts/principalPolicyEvidence\";\nimport type {\n createRuntimeCurrentGroupShare,\n shareRemoteContainerWithGroup,\n} from \"../../organizations/groupShare\";\nimport type { PrincipalPolicyRuntime } from \"../../principals/principalPolicyService\";\n\ntype GroupShare = typeof shareRemoteContainerWithGroup;\n\n/** What the group operations read from a container contents runtime. */\ntype GroupShareRuntime = Parameters<typeof createRuntimeCurrentGroupShare>[0];\n\n/** The verified current group a share or rewrap acts on. */\nexport interface ContainerContentsCurrentGroupPolicy {\n readonly policy: PrincipalPolicyCurrentEvidence;\n /** The group policy and its dependencies, as checkpointed for this read. */\n readonly checkpointPolicies: readonly PrincipalPolicyCurrentEvidence[];\n readonly stillCurrent: () => boolean;\n}\n\n/**\n * Runs `work` on the group's current policy under a current principal\n * mutation lease, after the group's name and expected head are checked.\n */\nexport type ContainerContentsCurrentGroupPolicyReader = <Result>(\n input: {\n readonly expectedGroupHead?: ReferencedPrincipalHead | undefined;\n readonly expectedGroupName?: string | undefined;\n readonly groupId: string;\n readonly organizationId: string;\n readonly stillCurrent: () => boolean;\n },\n work: (current: ContainerContentsCurrentGroupPolicy) => Promise<Result>,\n) => Promise<Result>;\n\n/**\n * The Organization Read Models operations container contents runs. Group\n * shares, group metadata, and the organization directory belong to the\n * organization workflows, which sit above container contents; the composition\n * root binds their implementations here so container contents never imports\n * them.\n */\nexport interface ContainerContentsOrganizationHost {\n /** Shares with a group on current evidence; `undefined` without private paged recovery. */\n readonly createCurrentGroupShare: (\n runtime: GroupShareRuntime,\n ) => GroupShare | undefined;\n /** Reads current group policy; `undefined` without private paged recovery. */\n readonly createCurrentGroupPolicyReader: (\n runtime: GroupShareRuntime,\n ) => ContainerContentsCurrentGroupPolicyReader | undefined;\n /** Decrypts a group's name from the organization's signed metadata container. */\n readonly groupMetadataNameReader: (\n runtime: GroupShareRuntime,\n organizationId: string,\n stillCurrent: (() => boolean) | undefined,\n ) => NonNullable<Parameters<GroupShare>[0][\"readEncryptedName\"]>;\n /** Checks a metadata root destination against the current organization authority. */\n readonly verifyGroupMetadataAuthority: (input: {\n readonly runtime: PrincipalPolicyRuntime;\n readonly organizationId: string;\n readonly state: ContainerAccessManifestState;\n readonly organizationReference?: ReferencedPrincipalHead | undefined;\n readonly stillCurrent: () => boolean;\n }) => Promise<void>;\n /**\n * Runs `load` again once, after `evictRoot`, when the metadata root it read\n * was behind the signed directory; a root still behind is an incident.\n */\n readonly withMetadataRootReload: <Result>(\n load: (reread: boolean) => Promise<Result>,\n evictRoot: () => void,\n ) => Promise<Result>;\n}\n"]}
1
+ {"version":3,"file":"organizationHost.js","sourceRoot":"","sources":["organizationHost.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ContainerAccessManifestState,\n ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport type { ContainerShareCommittedReadModel } from \"../../../data/containers/shared/types\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principalContracts/principalPolicyEvidence\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type {\n createRuntimeCurrentGroupShare,\n shareRemoteContainerWithGroup,\n} from \"../../organizations/groupShare\";\nimport type { PrincipalPolicyRuntime } from \"../../principals/principalPolicyService\";\n\ntype GroupShare = typeof shareRemoteContainerWithGroup;\n\n/** What the group operations read from a container contents runtime. */\ntype GroupShareRuntime = Parameters<typeof createRuntimeCurrentGroupShare>[0];\n\n/** The verified current group a share or rewrap acts on. */\nexport interface ContainerContentsCurrentGroupPolicy {\n readonly policy: PrincipalPolicyCurrentEvidence;\n /** The group policy and its dependencies, as checkpointed for this read. */\n readonly checkpointPolicies: readonly PrincipalPolicyCurrentEvidence[];\n readonly stillCurrent: () => boolean;\n}\n\n/**\n * Runs `work` on the group's current policy under a current principal\n * mutation lease, after the group's name and expected head are checked.\n */\nexport type ContainerContentsCurrentGroupPolicyReader = <Result>(\n input: {\n readonly expectedGroupHead?: ReferencedPrincipalHead | undefined;\n readonly expectedGroupName?: string | undefined;\n readonly groupId: string;\n readonly organizationId: string;\n readonly stillCurrent: () => boolean;\n },\n work: (current: ContainerContentsCurrentGroupPolicy) => Promise<Result>,\n) => Promise<Result>;\n\n/**\n * The Organization Read Models operations container contents runs. Group\n * shares, group metadata, and the organization directory belong to the\n * organization workflows, which sit above container contents; the composition\n * root binds their implementations here so container contents never imports\n * them.\n */\nexport interface ContainerContentsOrganizationHost {\n /** Sends a share's held read-model cursor and keeps the delta it carries. */\n readonly committedReadModel: (scope: {\n readonly domainScope: object;\n readonly execSql: ExecSql;\n readonly organizationId: string;\n readonly userId: string;\n }) => ContainerShareCommittedReadModel;\n /** Shares with a group on current evidence; `undefined` without private paged recovery. */\n readonly createCurrentGroupShare: (\n runtime: GroupShareRuntime,\n ) => GroupShare | undefined;\n /** Reads current group policy; `undefined` without private paged recovery. */\n readonly createCurrentGroupPolicyReader: (\n runtime: GroupShareRuntime,\n ) => ContainerContentsCurrentGroupPolicyReader | undefined;\n /** Decrypts a group's name from the organization's signed metadata container. */\n readonly groupMetadataNameReader: (\n runtime: GroupShareRuntime,\n organizationId: string,\n stillCurrent: (() => boolean) | undefined,\n ) => NonNullable<Parameters<GroupShare>[0][\"readEncryptedName\"]>;\n /** Checks a metadata root destination against the current organization authority. */\n readonly verifyGroupMetadataAuthority: (input: {\n readonly runtime: PrincipalPolicyRuntime;\n readonly organizationId: string;\n readonly state: ContainerAccessManifestState;\n readonly organizationReference?: ReferencedPrincipalHead | undefined;\n readonly stillCurrent: () => boolean;\n }) => Promise<void>;\n /**\n * Runs `load` again once, after `evictRoot`, when the metadata root it read\n * was behind the signed directory; a root still behind is an incident.\n */\n readonly withMetadataRootReload: <Result>(\n load: (reread: boolean) => Promise<Result>,\n evictRoot: () => void,\n ) => Promise<Result>;\n}\n"]}
@@ -57,6 +57,12 @@ export async function shareRemoteContainer(input) {
57
57
  const shared = await writer.containers.shareRemoteContainer({
58
58
  accessLevel: input.accessLevel,
59
59
  author: writer.author,
60
+ committedReadModel: input.runtime.organizations.committedReadModel({
61
+ domainScope: input.runtime.state.domainScope,
62
+ execSql: input.runtime.infra.execSql,
63
+ organizationId: writer.author.organizationId,
64
+ userId: writer.author.signerUserId,
65
+ }),
60
66
  containerId: input.containerId,
61
67
  previousProjection: input.previousProjection,
62
68
  recipientUserId: input.recipientU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A2E;AAC3E,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAAC,KAIpD;IACC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IACD,MAAM,cAAc,GAAG,MAAM,qBAAqB,CAAC;QACjD,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW;QACtC,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,cAAc;QAC5C,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;KAC7B,CAAC,CAAC,IAAI,CACL,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,gCAAgC,CAAC,EAChE,CAAC,KAAc,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CACxC,CAAC;IACF,IAAI,KAAK,CAAC,SAAS,EAAE,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;QACjD,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAC1B,mEAAmE,KAAK,CAAC,OAAO,CAAC,WAAW,wBAAwB,cAAc,EAAE,CACrI,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type { ContainerAccessManifestState } from \"@tearleads/crypto\";\nimport { emptyVersionVector } from \"@tearleads/loro\";\nimport type { ContainerSystemSlot } from \"@tearleads/validators/containerSystemSlot\";\nimport type {\n ContainerMutationResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { isContainerNotFoundFailure } from \"../../../data/containers/shared/mutationFailures\";\nimport type { ProjectionUserKeyResolver } from \"../../../data/keyingProjectionVerification\";\nimport { ProjectionDependencyUnavailableError } from \"../../../data/shared/dependencyUnavailable\";\nimport { errorMessage } from \"../../../data/shared/errorMessage\";\nimport {\n type AppliedContainerMove,\n type ContainerMutationCollaborators,\n ContainerMutationService,\n signedContainerMetadataDocumentId,\n signedContainerReferencedPrincipalHeads,\n} from \"../../containers\";\nimport { resolveDocumentCreateAuthor } from \"../../documents\";\n\nimport {\n type ContainerAlreadyCommitted,\n createRemoteContainerWithMetadataDocument,\n} from \"./create/createWithMetadata\";\nimport type {\n ContainerCreateIntentSyncState,\n ContainerWorkflowRuntime,\n CreatedRemoteContainerState,\n RemoteContainer,\n SharedRemoteContainerState,\n} from \"./types\";\n\n/**\n * Resolve the author and the runtime snapshot's container mutation\n * collaborators, with a service bound to them, logging a skip for the given\n * operation when the writer context is unavailable.\n */\nfunction resolveContainerWriterContext(\n runtime: ContainerWorkflowRuntime,\n operation:\n | \"container create\"\n | \"container group share\"\n | \"container move\"\n | \"container share\",\n) {\n const author = resolveDocumentCreateAuthor(runtime);\n const secretKey = runtime.crypto.encapsulationKeyPair?.secretKey;\n if (!author || !secretKey) {\n runtime.util.log(\n `Container contents: skipped ${operation} because the writer context is unavailable.`,\n );\n return null;\n }\n\n const collaborators: ContainerMutationCollaborators<\n ContainerWorkflowRuntime[\"apiClient\"]\n > = {\n api: runtime.apiClient,\n encapsulationSecretKey: secretKey,\n execSql: runtime.infra.execSql,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n };\n return {\n author,\n collaborators,\n containers: new ContainerMutationService(collaborators),\n };\n}\n\nexport async function createRemoteContainer(input: {\n systemSlot?: ContainerSystemSlot | null | undefined;\n containerId: string;\n metadataSeedUpdate?: Parameters<\n typeof createRemoteContainerWithMetadataDocument\n >[0][\"metadataSeedUpdate\"];\n parentContainerId: string;\n parentProjection?: ContainerWriterProjectionResponse | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<CreatedRemoteContainerState | ContainerAlreadyCommitted | null> {\n return createRemoteContainerWithMetadataDocument(input);\n}\n\n/** An acknowledged mutation: the server's commitments and the signed plan. */\ninterface AcknowledgedContainerMutation {\n readonly plan: { readonly state: ContainerAccessManifestState };\n readonly response: ContainerMutationResponse;\n}\n\nfunction sharedRemoteContainerStateFromMutation(\n previousProjection: ContainerWriterProjectionResponse,\n { plan, response }: AcknowledgedContainerMutation,\n): SharedRemoteContainerState {\n if (\n response.containerId !== previousProjection.containerId ||\n response.organizationId !== previousProjection.organizationId\n )\n throw new Error(\"Container mutation response projection mismatch\");\n return {\n accessManifestHash: response.manifestHead.manifestHash,\n accessEpoch: response.manifestHead.epoch,\n createdAt: response.createdAt,\n metadataDocumentId: signedContainerMetadataDocumentId(plan),\n referencedPrincipalHeads: signedContainerReferencedPrincipalHeads(plan),\n updatedAt: response.updatedAt,\n // The next read obtains the post-commit proof. A failed read cannot undo\n // acknowledgement of this successful mutation.\n writerProjection: null,\n };\n}\n\nexport async function shareRemoteContainer(input: {\n accessLevel: \"read\" | \"write\" | \"admin\";\n containerId: string;\n previousProjection: ContainerWriterProjectionResponse;\n recipientUserId: string;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<SharedRemoteContainerState | null> {\n const writer = resolveContainerWriterContext(\n input.runtime,\n \"container share\",\n );\n if (!writer) {\n return null;\n }\n const shared = await writer.containers.shareRemoteContainer({\n accessLevel: input.accessLevel,\n author: writer.author,\n containerId: input.containerId,\n previousProjection: input.previousProjection,\n recipientUserId: input.recipientUserId,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies:\n input.runtime.principalPolicies.createWarmer(),\n });\n if (!shared) {\n return null;\n }\n\n return sharedRemoteContainerStateFromMutation(\n input.previousProjection,\n shared,\n );\n}\n\nexport async function shareRemoteContainerWithGroup(input: {\n accessLevel: \"read\" | \"write\" | \"admin\";\n containerId: string;\n expectedGroupName?: string | undefined;\n knownContainerKeks?: ReadonlyMap<string, Uint8Array> | undefined;\n previousProjection: ContainerWriterProjectionResponse;\n recipientGroupId: string;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<SharedRemoteContainerState | null> {\n const writer = resolveContainerWriterContext(\n input.runtime,\n \"container group share\",\n );\n if (!writer) {\n return null;\n }\n const { author, collaborators } = writer;\n\n const shareWithGroup = input.runtime.organizations.createCurrentGroupShare(\n input.runtime,\n );\n if (!shareWithGroup)\n throw new ProjectionDependencyUnavailableError(\n \"Group sharing requires private paged recovery\",\n );\n const shared = await shareWithGroup({\n reportSecurityIncident: collaborators.reportSecurityIncident,\n accessLevel: input.accessLevel,\n apiClient: collaborators.api,\n author,\n containerId: input.containerId,\n execSql: collaborators.execSql,\n expectedGroupName: input.expectedGroupName ?? null,\n readEncryptedName: (bundle) =>\n input.runtime.organizations.groupMetadataNameReader(\n input.runtime,\n author.organizationId,\n input.stillCurrent,\n )(bundle),\n knownContainerKeks: input.knownContainerKeks,\n previousProjection: input.previousProjection,\n recipientGroupId: input.recipientGroupId,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n resolveTrustedUserIdentity: collaborators.resolveTrustedUserIdentity,\n signingKeyPair: input.runtime.crypto.signingKeyPair,\n stillCurrent: input.stillCurrent,\n targetSecretKey: collaborators.encapsulationSecretKey,\n warmReferencedPrincipalPolicies:\n input.runtime.principalPolicies.createWarmer(),\n });\n if (!shared) {\n return null;\n }\n\n return sharedRemoteContainerStateFromMutation(\n input.previousProjection,\n shared,\n );\n}\n\n/**\n * Replays a queued move. `applied` carries the verified head when the server\n * already holds the container under the destination, so nothing is posted.\n */\nexport async function moveRemoteContainer(input: {\n containerId: string;\n onAccepted?: (() => void) | undefined;\n parentContainerId: string;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<\n { applied: AppliedContainerMove } | { moved: RemoteContainer } | null\n> {\n const writer = resolveContainerWriterContext(input.runtime, \"container move\");\n if (!writer) {\n return null;\n }\n const replayed = await writer.containers.replayRemoteContainerMove({\n author: writer.author,\n containerId: input.containerId,\n destinationParentContainerId: input.parentContainerId,\n onAccepted: input.onAccepted,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies:\n input.runtime.principalPolicies.createWarmer(),\n });\n if (!replayed || \"applied\" in replayed) {\n return replayed;\n }\n\n const { plan, response } = replayed;\n return {\n moved: {\n createdAt: response.createdAt,\n effectiveAccessLevel: \"admin\",\n id: response.containerId,\n organizationId: response.organizationId,\n parentId: response.parentId,\n metadataDocumentId: signedContainerMetadataDocumentId(plan),\n metadataAccessEpoch: response.manifestHead.epoch,\n metadataAccessStateHash: response.manifestHead.manifestHash,\n metadataReferencedPrincipals:\n signedContainerReferencedPrincipalHeads(plan),\n // A move says nothing about the metadata document's version.\n metadataVersionVector: emptyVersionVector(),\n updatedAt: response.updatedAt,\n },\n };\n}\n\nexport async function deleteRemoteContainer(input: {\n containerId: string;\n organizationId: string;\n requiredAncestorId?: string | undefined;\n runtime: ContainerWorkflowRuntime;\n}): Promise<{ deletedAt: string } | null> {\n const deleteResult = await input.runtime.apiClient.deleteContainerResult(\n input.containerId,\n {\n expectedPaymentRequiredOrganizationId: input.organizationId,\n reportErrors: false,\n requiredAncestorId: input.requiredAncestorId,\n },\n );\n if (!deleteResult.ok && !isContainerNotFoundFailure(deleteResult)) {\n deleteResult.report();\n return null;\n }\n\n if (!deleteResult.ok) {\n // A 404 proves this immutable id is permanently absent, but it does not\n // carry the server deletion time. A maximal fence prevents an older\n // in-flight listing page from resurrecting it.\n return { deletedAt: \"9999-12-31T23:59:59.999Z\" };\n }\n\n return { deletedAt: deleteResult.data.deletedAt };\n}\n\n/** Best-effort delete of a remote container whose local folder is gone. */\nexport async function discardOrphanedRemoteContainer(input: {\n created: CreatedRemoteContainerState;\n isCurrent: () => boolean;\n state: Pick<ContainerCreateIntentSyncState, \"runtime\">;\n}): Promise<void> {\n if (!input.isCurrent()) {\n return;\n }\n const discardFailure = await deleteRemoteContainer({\n containerId: input.created.containerId,\n organizationId: input.created.organizationId,\n runtime: input.state.runtime,\n }).then(\n (deleted) => (deleted ? null : \"the server rejected the delete\"),\n (error: unknown) => errorMessage(error),\n );\n if (input.isCurrent() && discardFailure !== null) {\n input.state.runtime.util.log(\n `Container contents: failed to discard orphaned remote container ${input.created.containerId} after local delete: ${discardFailure}`,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["remote.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAMrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,kDAAkD,CAAC;AAE9F,OAAO,EAAE,oCAAoC,EAAE,MAAM,4CAA4C,CAAC;AAClG,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAGL,wBAAwB,EACxB,iCAAiC,EACjC,uCAAuC,GACxC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAEL,yCAAyC,GAC1C,MAAM,6BAA6B,CAAC;AASrC;;;;GAIG;AACH,SAAS,6BAA6B,CACpC,OAAiC,EACjC,SAIqB;IAErB,MAAM,MAAM,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,SAAS,CAAC;IACjE,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,GAAG,CACd,+BAA+B,SAAS,6CAA6C,CACtF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,aAAa,GAEf;QACF,GAAG,EAAE,OAAO,CAAC,SAAS;QACtB,sBAAsB,EAAE,SAAS;QACjC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;QA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AAK,CAAC,OAAO,CAAC,WAAW,wBAAwB,cAAc,EAAE,CACrI,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type { ContainerAccessManifestState } from \"@tearleads/crypto\";\nimport { emptyVersionVector } from \"@tearleads/loro\";\nimport type { ContainerSystemSlot } from \"@tearleads/validators/containerSystemSlot\";\nimport type {\n ContainerMutationResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { isContainerNotFoundFailure } from \"../../../data/containers/shared/mutationFailures\";\nimport type { ProjectionUserKeyResolver } from \"../../../data/keyingProjectionVerification\";\nimport { ProjectionDependencyUnavailableError } from \"../../../data/shared/dependencyUnavailable\";\nimport { errorMessage } from \"../../../data/shared/errorMessage\";\nimport {\n type AppliedContainerMove,\n type ContainerMutationCollaborators,\n ContainerMutationService,\n signedContainerMetadataDocumentId,\n signedContainerReferencedPrincipalHeads,\n} from \"../../containers\";\nimport { resolveDocumentCreateAuthor } from \"../../documents\";\n\nimport {\n type ContainerAlreadyCommitted,\n createRemoteContainerWithMetadataDocument,\n} from \"./create/createWithMetadata\";\nimport type {\n ContainerCreateIntentSyncState,\n ContainerWorkflowRuntime,\n CreatedRemoteContainerState,\n RemoteContainer,\n SharedRemoteContainerState,\n} from \"./types\";\n\n/**\n * Resolve the author and the runtime snapshot's container mutation\n * collaborators, with a service bound to them, logging a skip for the given\n * operation when the writer context is unavailable.\n */\nfunction resolveContainerWriterContext(\n runtime: ContainerWorkflowRuntime,\n operation:\n | \"container create\"\n | \"container group share\"\n | \"container move\"\n | \"container share\",\n) {\n const author = resolveDocumentCreateAuthor(runtime);\n const secretKey = runtime.crypto.encapsulationKeyPair?.secretKey;\n if (!author || !secretKey) {\n runtime.util.log(\n `Container contents: skipped ${operation} because the writer context is unavailable.`,\n );\n return null;\n }\n\n const collaborators: ContainerMutationCollaborators<\n ContainerWorkflowRuntime[\"apiClient\"]\n > = {\n api: runtime.apiClient,\n encapsulationSecretKey: secretKey,\n execSql: runtime.infra.execSql,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n };\n return {\n author,\n collaborators,\n containers: new ContainerMutationService(collaborators),\n };\n}\n\nexport async function createRemoteContainer(input: {\n systemSlot?: ContainerSystemSlot | null | undefined;\n containerId: string;\n metadataSeedUpdate?: Parameters<\n typeof createRemoteContainerWithMetadataDocument\n >[0][\"metadataSeedUpdate\"];\n parentContainerId: string;\n parentProjection?: ContainerWriterProjectionResponse | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<CreatedRemoteContainerState | ContainerAlreadyCommitted | null> {\n return createRemoteContainerWithMetadataDocument(input);\n}\n\n/** An acknowledged mutation: the server's commitments and the signed plan. */\ninterface AcknowledgedContainerMutation {\n readonly plan: { readonly state: ContainerAccessManifestState };\n readonly response: ContainerMutationResponse;\n}\n\nfunction sharedRemoteContainerStateFromMutation(\n previousProjection: ContainerWriterProjectionResponse,\n { plan, response }: AcknowledgedContainerMutation,\n): SharedRemoteContainerState {\n if (\n response.containerId !== previousProjection.containerId ||\n response.organizationId !== previousProjection.organizationId\n )\n throw new Error(\"Container mutation response projection mismatch\");\n return {\n accessManifestHash: response.manifestHead.manifestHash,\n accessEpoch: response.manifestHead.epoch,\n createdAt: response.createdAt,\n metadataDocumentId: signedContainerMetadataDocumentId(plan),\n referencedPrincipalHeads: signedContainerReferencedPrincipalHeads(plan),\n updatedAt: response.updatedAt,\n // The next read obtains the post-commit proof. A failed read cannot undo\n // acknowledgement of this successful mutation.\n writerProjection: null,\n };\n}\n\nexport async function shareRemoteContainer(input: {\n accessLevel: \"read\" | \"write\" | \"admin\";\n containerId: string;\n previousProjection: ContainerWriterProjectionResponse;\n recipientUserId: string;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<SharedRemoteContainerState | null> {\n const writer = resolveContainerWriterContext(\n input.runtime,\n \"container share\",\n );\n if (!writer) {\n return null;\n }\n const shared = await writer.containers.shareRemoteContainer({\n accessLevel: input.accessLevel,\n author: writer.author,\n committedReadModel: input.runtime.organizations.committedReadModel({\n domainScope: input.runtime.state.domainScope,\n execSql: input.runtime.infra.execSql,\n organizationId: writer.author.organizationId,\n userId: writer.author.signerUserId,\n }),\n containerId: input.containerId,\n previousProjection: input.previousProjection,\n recipientUserId: input.recipientUserId,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies:\n input.runtime.principalPolicies.createWarmer(),\n });\n if (!shared) {\n return null;\n }\n\n return sharedRemoteContainerStateFromMutation(\n input.previousProjection,\n shared,\n );\n}\n\nexport async function shareRemoteContainerWithGroup(input: {\n accessLevel: \"read\" | \"write\" | \"admin\";\n containerId: string;\n expectedGroupName?: string | undefined;\n knownContainerKeks?: ReadonlyMap<string, Uint8Array> | undefined;\n previousProjection: ContainerWriterProjectionResponse;\n recipientGroupId: string;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<SharedRemoteContainerState | null> {\n const writer = resolveContainerWriterContext(\n input.runtime,\n \"container group share\",\n );\n if (!writer) {\n return null;\n }\n const { author, collaborators } = writer;\n\n const shareWithGroup = input.runtime.organizations.createCurrentGroupShare(\n input.runtime,\n );\n if (!shareWithGroup)\n throw new ProjectionDependencyUnavailableError(\n \"Group sharing requires private paged recovery\",\n );\n const shared = await shareWithGroup({\n reportSecurityIncident: collaborators.reportSecurityIncident,\n accessLevel: input.accessLevel,\n apiClient: collaborators.api,\n author,\n containerId: input.containerId,\n execSql: collaborators.execSql,\n expectedGroupName: input.expectedGroupName ?? null,\n readEncryptedName: (bundle) =>\n input.runtime.organizations.groupMetadataNameReader(\n input.runtime,\n author.organizationId,\n input.stillCurrent,\n )(bundle),\n knownContainerKeks: input.knownContainerKeks,\n previousProjection: input.previousProjection,\n recipientGroupId: input.recipientGroupId,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n resolveTrustedUserIdentity: collaborators.resolveTrustedUserIdentity,\n signingKeyPair: input.runtime.crypto.signingKeyPair,\n stillCurrent: input.stillCurrent,\n targetSecretKey: collaborators.encapsulationSecretKey,\n warmReferencedPrincipalPolicies:\n input.runtime.principalPolicies.createWarmer(),\n });\n if (!shared) {\n return null;\n }\n\n return sharedRemoteContainerStateFromMutation(\n input.previousProjection,\n shared,\n );\n}\n\n/**\n * Replays a queued move. `applied` carries the verified head when the server\n * already holds the container under the destination, so nothing is posted.\n */\nexport async function moveRemoteContainer(input: {\n containerId: string;\n onAccepted?: (() => void) | undefined;\n parentContainerId: string;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<\n { applied: AppliedContainerMove } | { moved: RemoteContainer } | null\n> {\n const writer = resolveContainerWriterContext(input.runtime, \"container move\");\n if (!writer) {\n return null;\n }\n const replayed = await writer.containers.replayRemoteContainerMove({\n author: writer.author,\n containerId: input.containerId,\n destinationParentContainerId: input.parentContainerId,\n onAccepted: input.onAccepted,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies:\n input.runtime.principalPolicies.createWarmer(),\n });\n if (!replayed || \"applied\" in replayed) {\n return replayed;\n }\n\n const { plan, response } = replayed;\n return {\n moved: {\n createdAt: response.createdAt,\n effectiveAccessLevel: \"admin\",\n id: response.containerId,\n organizationId: response.organizationId,\n parentId: response.parentId,\n metadataDocumentId: signedContainerMetadataDocumentId(plan),\n metadataAccessEpoch: response.manifestHead.epoch,\n metadataAccessStateHash: response.manifestHead.manifestHash,\n metadataReferencedPrincipals:\n signedContainerReferencedPrincipalHeads(plan),\n // A move says nothing about the metadata document's version.\n metadataVersionVector: emptyVersionVector(),\n updatedAt: response.updatedAt,\n },\n };\n}\n\nexport async function deleteRemoteContainer(input: {\n containerId: string;\n organizationId: string;\n requiredAncestorId?: string | undefined;\n runtime: ContainerWorkflowRuntime;\n}): Promise<{ deletedAt: string } | null> {\n const deleteResult = await input.runtime.apiClient.deleteContainerResult(\n input.containerId,\n {\n expectedPaymentRequiredOrganizationId: input.organizationId,\n reportErrors: false,\n requiredAncestorId: input.requiredAncestorId,\n },\n );\n if (!deleteResult.ok && !isContainerNotFoundFailure(deleteResult)) {\n deleteResult.report();\n return null;\n }\n\n if (!deleteResult.ok) {\n // A 404 proves this immutable id is permanently absent, but it does not\n // carry the server deletion time. A maximal fence prevents an older\n // in-flight listing page from resurrecting it.\n return { deletedAt: \"9999-12-31T23:59:59.999Z\" };\n }\n\n return { deletedAt: deleteResult.data.deletedAt };\n}\n\n/** Best-effort delete of a remote container whose local folder is gone. */\nexport async function discardOrphanedRemoteContainer(input: {\n created: CreatedRemoteContainerState;\n isCurrent: () => boolean;\n state: Pick<ContainerCreateIntentSyncState, \"runtime\">;\n}): Promise<void> {\n if (!input.isCurrent()) {\n return;\n }\n const discardFailure = await deleteRemoteContainer({\n containerId: input.created.containerId,\n organizationId: input.created.organizationId,\n runtime: input.state.runtime,\n }).then(\n (deleted) => (deleted ? null : \"the server rejected the delete\"),\n (error: unknown) => errorMessage(error),\n );\n if (input.isCurrent() && discardFailure !== null) {\n input.state.runtime.util.log(\n `Container contents: failed to discard orphaned remote container ${input.created.containerId} after local delete: ${discardFailure}`,\n );\n }\n}\n"]}
@@ -1,11 +1,13 @@
1
1
  import { type ContainerAccessLevel } from "../../../../internal/crypto/index.js";
2
- import type { ContainerMutationResponse, ContainerWriterProjectionResponse } from "../../../../internal/validators/response/index.js";
3
- import type { ContainerMutationAuthor, ContainerShareApi, ContainerSharePlan } from "../../../../data/containers/shared/types.js";
2
+ import { type ContainerMutationResponse, type ContainerWriterProjectionResponse } from "../../../../internal/validators/response/index.js";
3
+ import type { ContainerMutationAuthor, ContainerShareApi, ContainerShareCommittedReadModel, ContainerSharePlan } from "../../../../data/containers/shared/types.js";
4
4
  import { type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../../data/keyingProjectionVerification/index.js";
5
5
  import { type ContainerMutationCollaborators } from "../../containerMutationCollaborators.js";
6
6
  export interface ShareRemoteContainerRequest {
7
7
  accessLevel: ContainerAccessLevel;
8
8
  author: ContainerMutationAuthor;
9
+ /** Sends the read-model cursor the sharer holds; none without it. */
10
+ committedReadModel?: ContainerShareCommittedReadModel | undefined;
9
11
  containerId: string;
10
12
  eventId?: string | undefined;
11
13
  previousProjection?: ContainerWriterProjectionResponse | undefined;
@@ -1,4 +1,5 @@
1
1
  import { KeyingVerificationError, } from "../../../../internal/crypto/index.js";
2
+ import { committedReadModelDelta, } from "../../../../internal/validators/response/index.js";
2
3
  import { isStaleParentContainerPathFailure } from "../../../../data/containers/shared/mutationFailures.js";
3
4
  import { nullOnProjectionVerificationCancellation, requireProjectionUserKeyResolver, } from "../../../../data/keyingProjectionVerification/index.js";
4
5
  import { ProjectionDependencyUnavailableError } from "../../../../data/shared/dependencyUnavailable.js";
@@ -17,7 +18,7 @@ const STALE_PATH = Symbol("stale-path");
17
18
  * refusal that ends the share is reported once submission settles, as the
18
19
  * plain endpoint's would be; a stale path the share plans again is not.
19
20
  */
20
- async function submitShare(input, request, retriesStalePath) {
21
+ async function submitShare(input, request, retriesStalePath, readModelCursor) {
21
22
  const options = {
22
23
  expectedPaymentRequiredOrganizationId: input.author.organizationId,
23
24
  };
@@ -25,7 +26,11 @@ async function submitShare(input, request, retriesStalePath) {
25
26
  if (!shareContainerResult) {
26
27
  return submitPlainContainerMutation(() => input.apiClient.shareContainer(input.containerId, request, options));
27
28
  }
28
- const result = await shareContainerResult.call(input.apiClient, input.containerId, request, { ...options, reportErrors: false });
29
+ const result = await shareContainerResult.call(input.apiClient, input.containerId, request, {
30
+ ...options,
31
+ ...(readModelCursor ? { readModelCursor } : {}),
32
+ reportErrors: false,
33
+ });
29
34
  if (result.ok)
30
35
  return { ok: true, data: result.data };
31
36
  return retriesStalePath && isStaleParentContainerPathFailure(result)
@@ -74,24 +79,36 @@ async function shareRemoteContainerOnce(input, recipientEncapsulationPublicKey,
74
79
  if (!materializedPlan)
75
80
  return null;
76
81
  let stalePath = false;
77
- const shared = await submitAcknowledgedContainerMutation({
78
- reportSecurityIncident: input.reportSecurityIncident,
79
- recitationPolicies: [],
80
- apiClient: input.apiClient,
81
- author: input.author,
82
- containerKey: materializedPlan.containerKey,
83
- execSql: input.execSql,
84
- plan: materializedPlan.plan,
85
- stillCurrent: input.stillCurrent,
86
- submit: async () => {
87
- const result = await submitShare(input, materializedPlan.plan.request, retriesStalePath);
88
- stalePath =
89
- !result.ok &&
90
- retriesStalePath &&
91
- isStaleParentContainerPathFailure(result);
92
- return result;
93
- },
94
- });
82
+ // The acknowledged submit rechecks currency after this lookup, and the
83
+ // delta is offered only once the share's acknowledgement verified.
84
+ const lease = await input.committedReadModel?.begin();
85
+ let delta;
86
+ let shared = null;
87
+ try {
88
+ shared = await submitAcknowledgedContainerMutation({
89
+ reportSecurityIncident: input.reportSecurityIncident,
90
+ recitationPolicies: [],
91
+ apiClient: input.apiClient,
92
+ author: input.author,
93
+ containerKey: materializedPlan.containerKey,
94
+ execSql: input.execSql,
95
+ plan: materializedPlan.plan,
96
+ stillCurrent: input.stillCurrent,
97
+ submit: async () => {
98
+ const result = await submitShare(input, materializedPlan.plan.request, retriesStalePath, lease?.heldCursor);
99
+ if (result.ok)
100
+ delta = committedReadModelDelta(result.data.readModel, input.author.organizationId);
101
+ stalePath =
102
+ !result.ok &&
103
+ retriesStalePath &&
104
+ isStaleParentContainerPathFailure(result);
105
+ return result;
106
+ },
107
+ });
108
+ }
109
+ finally {
110
+ lease?.settle(shared ? delta : undefined);
111
+ }
95
112
  return shared ?? (stalePath ? STALE_PATH : null);
96
113
  }
97
114
  /**