@tearleads/client-sdk 0.1.103 → 0.1.104

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 (20) hide show
  1. package/internal/validators/operation/containerMutations.d.ts +16 -16
  2. package/internal/validators/operation/principals.d.ts +24 -0
  3. package/internal/validators/response/containerMutationError.d.ts +3 -3
  4. package/internal/validators/response/containerMutationError.js +2 -1
  5. package/internal/validators/response/containerMutationError.js.map +1 -1
  6. package/internal/validators/response/containerMutationStateStaleError.js +3 -0
  7. package/internal/validators/response/containerMutationStateStaleError.js.map +1 -0
  8. package/internal/validators/response/principal.d.ts +12 -0
  9. package/internal/validators/response/principal.js +5 -0
  10. package/internal/validators/response/principal.js.map +1 -1
  11. package/package.json +1 -1
  12. package/workflows/containers/rematerialization/acknowledgePrincipalContainerRematerialization.js +45 -0
  13. package/workflows/containers/rematerialization/acknowledgePrincipalContainerRematerialization.js.map +1 -0
  14. package/workflows/containers/rematerialization/principalContainerRematerialization.js +17 -47
  15. package/workflows/containers/rematerialization/principalContainerRematerialization.js.map +1 -1
  16. package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js +3 -0
  17. package/workflows/organizations/groupPolicy/commitCurrentGroupPolicyMutation.js.map +1 -1
  18. package/workflows/organizations/groupPolicy/submitGroupPolicyCommit.d.ts +6 -11
  19. package/workflows/organizations/groupPolicy/submitGroupPolicyCommit.js +58 -45
  20. package/workflows/organizations/groupPolicy/submitGroupPolicyCommit.js.map +1 -1
@@ -215,7 +215,7 @@ export declare const createContainerOperation: Omit<{
215
215
  error: string;
216
216
  }>>;
217
217
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
218
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
218
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
219
219
  error: z.ZodString;
220
220
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
221
221
  }, z.core.$loose>, z.ZodType<{
@@ -581,7 +581,7 @@ export declare const createContainerOperation: Omit<{
581
581
  error: string;
582
582
  }>>;
583
583
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
584
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
584
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
585
585
  error: z.ZodString;
586
586
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
587
587
  }, z.core.$loose>, z.ZodType<{
@@ -1442,7 +1442,7 @@ export declare const createContainerWithMetadataDocumentOperation: Omit<{
1442
1442
  error: string;
1443
1443
  }>>;
1444
1444
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
1445
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
1445
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
1446
1446
  error: z.ZodString;
1447
1447
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
1448
1448
  }, z.core.$loose>, z.ZodType<{
@@ -2016,7 +2016,7 @@ export declare const createContainerWithMetadataDocumentOperation: Omit<{
2016
2016
  error: string;
2017
2017
  }>>;
2018
2018
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
2019
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
2019
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
2020
2020
  error: z.ZodString;
2021
2021
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
2022
2022
  }, z.core.$loose>, z.ZodType<{
@@ -2288,7 +2288,7 @@ export declare const shareContainerOperation: Omit<{
2288
2288
  error: string;
2289
2289
  }>>;
2290
2290
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
2291
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
2291
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
2292
2292
  error: z.ZodString;
2293
2293
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
2294
2294
  }, z.core.$loose>, z.ZodType<{
@@ -2656,7 +2656,7 @@ export declare const shareContainerOperation: Omit<{
2656
2656
  error: string;
2657
2657
  }>>;
2658
2658
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
2659
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
2659
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
2660
2660
  error: z.ZodString;
2661
2661
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
2662
2662
  }, z.core.$loose>, z.ZodType<{
@@ -2856,7 +2856,7 @@ export declare const reciteContainerOperation: Omit<{
2856
2856
  error: string;
2857
2857
  }>>;
2858
2858
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
2859
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
2859
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
2860
2860
  error: z.ZodString;
2861
2861
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
2862
2862
  }, z.core.$loose>, z.ZodType<{
@@ -3100,7 +3100,7 @@ export declare const reciteContainerOperation: Omit<{
3100
3100
  error: string;
3101
3101
  }>>;
3102
3102
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
3103
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
3103
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
3104
3104
  error: z.ZodString;
3105
3105
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
3106
3106
  }, z.core.$loose>, z.ZodType<{
@@ -3524,7 +3524,7 @@ export declare const revokeContainerOperation: Omit<{
3524
3524
  error: string;
3525
3525
  }>>;
3526
3526
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
3527
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
3527
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
3528
3528
  error: z.ZodString;
3529
3529
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
3530
3530
  }, z.core.$loose>, z.ZodType<{
@@ -4132,7 +4132,7 @@ export declare const revokeContainerOperation: Omit<{
4132
4132
  error: string;
4133
4133
  }>>;
4134
4134
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
4135
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
4135
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
4136
4136
  error: z.ZodString;
4137
4137
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
4138
4138
  }, z.core.$loose>, z.ZodType<{
@@ -4556,7 +4556,7 @@ export declare const rekeyContainerOperation: Omit<{
4556
4556
  error: string;
4557
4557
  }>>;
4558
4558
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
4559
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
4559
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
4560
4560
  error: z.ZodString;
4561
4561
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
4562
4562
  }, z.core.$loose>, z.ZodType<{
@@ -5164,7 +5164,7 @@ export declare const rekeyContainerOperation: Omit<{
5164
5164
  error: string;
5165
5165
  }>>;
5166
5166
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
5167
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
5167
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
5168
5168
  error: z.ZodString;
5169
5169
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
5170
5170
  }, z.core.$loose>, z.ZodType<{
@@ -5588,7 +5588,7 @@ export declare const moveContainerOperation: Omit<{
5588
5588
  error: string;
5589
5589
  }>>;
5590
5590
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
5591
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
5591
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
5592
5592
  error: z.ZodString;
5593
5593
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
5594
5594
  }, z.core.$loose>, z.ZodType<{
@@ -6196,7 +6196,7 @@ export declare const moveContainerOperation: Omit<{
6196
6196
  error: string;
6197
6197
  }>>;
6198
6198
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
6199
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
6199
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
6200
6200
  error: z.ZodString;
6201
6201
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
6202
6202
  }, z.core.$loose>, z.ZodType<{
@@ -6314,7 +6314,7 @@ export declare const deleteContainerOperation: Omit<{
6314
6314
  error: string;
6315
6315
  }>>;
6316
6316
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
6317
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
6317
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
6318
6318
  error: z.ZodString;
6319
6319
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
6320
6320
  }, z.core.$loose>, z.ZodType<{
@@ -6452,7 +6452,7 @@ export declare const deleteContainerOperation: Omit<{
6452
6452
  error: string;
6453
6453
  }>>;
6454
6454
  readonly 409: z.ZodUnion<readonly [z.ZodObject<{
6455
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
6455
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
6456
6456
  error: z.ZodString;
6457
6457
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
6458
6458
  }, z.core.$loose>, z.ZodType<{
@@ -2814,6 +2814,18 @@ export declare const commitOrganizationGroupPolicyOperation: Omit<{
2814
2814
  code: "container_descendant_rekeys_required";
2815
2815
  error: string;
2816
2816
  requiredContainerIds: string[];
2817
+ }>>, z.ZodType<{
2818
+ code: "container_mutation_state_stale";
2819
+ error: string;
2820
+ }, {
2821
+ code: "container_mutation_state_stale";
2822
+ error: string;
2823
+ }, z.core.$ZodTypeInternals<{
2824
+ code: "container_mutation_state_stale";
2825
+ error: string;
2826
+ }, {
2827
+ code: "container_mutation_state_stale";
2828
+ error: string;
2817
2829
  }>>]>;
2818
2830
  readonly 500: z.ZodType<{
2819
2831
  error: string;
@@ -4435,6 +4447,18 @@ export declare const commitOrganizationGroupPolicyOperation: Omit<{
4435
4447
  code: "container_descendant_rekeys_required";
4436
4448
  error: string;
4437
4449
  requiredContainerIds: string[];
4450
+ }>>, z.ZodType<{
4451
+ code: "container_mutation_state_stale";
4452
+ error: string;
4453
+ }, {
4454
+ code: "container_mutation_state_stale";
4455
+ error: string;
4456
+ }, z.core.$ZodTypeInternals<{
4457
+ code: "container_mutation_state_stale";
4458
+ error: string;
4459
+ }, {
4460
+ code: "container_mutation_state_stale";
4461
+ error: string;
4438
4462
  }>>]>;
4439
4463
  readonly 500: z.ZodType<{
4440
4464
  error: string;
@@ -8,11 +8,11 @@ export declare const CONTAINER_MUTATION_ERROR_CODES: {
8
8
  readonly pathTooDeep: "container_path_too_deep";
9
9
  readonly stateStale: "container_mutation_state_stale";
10
10
  };
11
- export declare const ContainerMutationBehaviorErrorCodeSchema: z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">;
12
- export declare const ContainerMutationErrorCodeSchema: z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>;
11
+ export declare const ContainerMutationBehaviorErrorCodeSchema: z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">;
12
+ export declare const ContainerMutationErrorCodeSchema: z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>;
13
13
  export type ContainerMutationErrorCode = z.infer<typeof ContainerMutationErrorCodeSchema>;
14
14
  export declare const ContainerMutationFailureResponseSchema: z.ZodUnion<readonly [z.ZodObject<{
15
- code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep" | "container_mutation_state_stale">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
15
+ code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">]>]>>;
16
16
  error: z.ZodString;
17
17
  requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
18
18
  }, z.core.$loose>, z.ZodType<{
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { arraySchema, nonEmptyStringSchema } from "../schema.js";
3
3
  import { MAX_ROTATION_CONTAINER_REKEYS } from "../util/index.js";
4
+ import { CONTAINER_MUTATION_STATE_STALE_ERROR_CODE } from "./containerMutationStateStaleError.js";
4
5
  import { CONTAINER_UNAVAILABLE_ERROR_CODE } from "./containerUnavailableError.js";
5
6
  import { CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE } from "./descendantRekeysRequiredError.js";
6
7
  import { DocumentMutationErrorCodeSchema } from "./documentMutationError.js";
@@ -25,7 +26,7 @@ export const CONTAINER_MUTATION_ERROR_CODES = {
25
26
  // request never succeeds: a queued move is abandoned, while a queued create
26
27
  // keeps its intent (a later local move can re-arm it).
27
28
  pathTooDeep: "container_path_too_deep",
28
- stateStale: "container_mutation_state_stale",
29
+ stateStale: CONTAINER_MUTATION_STATE_STALE_ERROR_CODE,
29
30
  };
30
31
  export const ContainerMutationBehaviorErrorCodeSchema = z.literal([
31
32
  CONTAINER_MUTATION_ERROR_CODES.ancestorRekeysRequired,
@@ -1 +1 @@
1
- {"version":3,"file":"containerMutationError.js","sourceRoot":"","sources":["containerMutationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,+CAA+C,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,uCAAuC,EAAE,MAAM,aAA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port { arraySchema, nonEmptyStringSchema } from \"../schema\";\nimport { MAX_ROTATION_CONTAINER_REKEYS } from \"../util\";\nimport { CONTAINER_UNAVAILABLE_ERROR_CODE } from \"./containerUnavailableError\";\nimport { CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE } from \"./descendantRekeysRequiredError\";\nimport { DocumentMutationErrorCodeSchema } from \"./documentMutationError\";\nimport { PrincipalPolicyStaleErrorResponseSchema } from \"./principal\";\n\nexport const CONTAINER_MUTATION_ERROR_CODES = {\n // Same literal as DOCUMENT_MUTATION_ERROR_CODES.containerUnavailable; the\n // envelope schema below already admits it through the document union.\n // A first direct grant sits below a chain pinned to a retired epoch, which\n // its grantee could never re-key. Not `stateStale`: refetching will not help,\n // the sharer must re-key that chain first.\n ancestorRekeysRequired: \"container_ancestor_rekeys_required\",\n containerUnavailable: CONTAINER_UNAVAILABLE_ERROR_CODE,\n // A rotation left a descendant above a granted container pinned to a retired\n // epoch. Not `stateStale`: refetching will not help, the client must sign and\n // carry the re-keys `requiredContainerIds` names.\n descendantRekeysRequired: CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE,\n // The revoke removes the caller's write access on owed descendants. Another\n // authorized member must perform it; retrying with carried rekeys cannot help.\n descendantRekeysInaccessible: \"container_descendant_rekeys_inaccessible\",\n manifestAlreadyExists: \"container_manifest_already_exists\",\n // A create or move would leave a path longer than readers accept. The same\n // request never succeeds: a queued move is abandoned, while a queued create\n // keeps its intent (a later local move can re-arm it).\n pathTooDeep: \"container_path_too_deep\",\n stateStale: \"container_mutation_state_stale\",\n} as const;\n\nexport const ContainerMutationBehaviorErrorCodeSchema = z.literal([\n CONTAINER_MUTATION_ERROR_CODES.ancestorRekeysRequired,\n CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired,\n CONTAINER_MUTATION_ERROR_CODES.descendantRekeysInaccessible,\n CONTAINER_MUTATION_ERROR_CODES.manifestAlreadyExists,\n CONTAINER_MUTATION_ERROR_CODES.pathTooDeep,\n CONTAINER_MUTATION_ERROR_CODES.stateStale,\n]);\n\nexport const ContainerMutationErrorCodeSchema = z.union([\n ContainerMutationBehaviorErrorCodeSchema,\n // The compound container-plus-metadata-document create can fail in either\n // half of its transaction, so its envelope preserves document-domain tags.\n DocumentMutationErrorCodeSchema,\n]);\n\nexport type ContainerMutationErrorCode = z.infer<\n typeof ContainerMutationErrorCodeSchema\n>;\n\nexport const ContainerMutationFailureResponseSchema = z.union([\n z.looseObject({\n code: ContainerMutationErrorCodeSchema.optional(),\n error: z.string().min(1),\n /** Parent-first; owed levels, or the inaccessible subset on a refused revoke. */\n requiredContainerIds: arraySchema(\n nonEmptyStringSchema,\n MAX_ROTATION_CONTAINER_REKEYS,\n ).optional(),\n }),\n PrincipalPolicyStaleErrorResponseSchema,\n]);\n\nexport type ContainerMutationFailureResponse = z.infer<\n typeof ContainerMutationFailureResponseSchema\n>;\n"]}
1
+ {"version":3,"file":"containerMutationError.js","sourceRoot":"","sources":["containerMutationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,yCAAyC,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,+CAA+C,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,uCAAuC,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,0EAA0E;IAC1E,sEAAsE;IACtE,2EAA2E;IAC3E,8EAA8E;IAC9E,2CAA2C;IAC3C,sBAAsB,EAAE,oCAAoC;IAC5D,oBAAoB,EAAE,gCAAgC;IACtD,6EAA6E;IAC7E,8EAA8E;IAC9E,kDAAkD;IAClD,wBAAwB,EAAE,+CAA+C;IACzE,4EAA4E;IAC5E,+EAA+E;IAC/E,4BAA4B,EAAE,0CAA0C;IACxE,qBAAqB,EAAE,mCAAmC;IAC1D,2EAA2E;IAC3E,4EAA4E;IAC5E,uDAAuD;IACvD,WAAW,EAAE,yBAAyB;IACtC,UAAU,EAAE,yCAAyC;CAC7C,CAAC;AAEX,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,CAAC,OAAO,CAAC;IAChE,8BAA8B,CAAC,sBAAsB;IACrD,8BAA8B,CAAC,wBAAwB;IACvD,8BAA8B,CAAC,4BAA4B;IAC3D,8BAA8B,CAAC,qBAAqB;IACpD,8BAA8B,CAAC,WAAW;IAC1C,8BAA8B,CAAC,UAAU;CAC1C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CAAC;IACtD,wCAAwC;IACxC,0EAA0E;IAC1E,2EAA2E;IAC3E,+BAA+B;CAChC,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,CAAC,KAAK,CAAC;IAC5D,CAAC,CAAC,WAAW,CAAC;QACZ,IAAI,EAAE,gCAAgC,CAAC,QAAQ,EAAE;QACjD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACxB,iFAAiF;QACjF,oBAAoB,EAAE,WAAW,CAC/B,oBAAoB,EACpB,6BAA6B,CAC9B,CAAC,QAAQ,EAAE;KACb,CAAC;IACF,uCAAuC;CACxC,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { arraySchema, nonEmptyStringSchema } from \"../schema\";\nimport { MAX_ROTATION_CONTAINER_REKEYS } from \"../util\";\nimport { CONTAINER_MUTATION_STATE_STALE_ERROR_CODE } from \"./containerMutationStateStaleError\";\nimport { CONTAINER_UNAVAILABLE_ERROR_CODE } from \"./containerUnavailableError\";\nimport { CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE } from \"./descendantRekeysRequiredError\";\nimport { DocumentMutationErrorCodeSchema } from \"./documentMutationError\";\nimport { PrincipalPolicyStaleErrorResponseSchema } from \"./principal\";\n\nexport const CONTAINER_MUTATION_ERROR_CODES = {\n // Same literal as DOCUMENT_MUTATION_ERROR_CODES.containerUnavailable; the\n // envelope schema below already admits it through the document union.\n // A first direct grant sits below a chain pinned to a retired epoch, which\n // its grantee could never re-key. Not `stateStale`: refetching will not help,\n // the sharer must re-key that chain first.\n ancestorRekeysRequired: \"container_ancestor_rekeys_required\",\n containerUnavailable: CONTAINER_UNAVAILABLE_ERROR_CODE,\n // A rotation left a descendant above a granted container pinned to a retired\n // epoch. Not `stateStale`: refetching will not help, the client must sign and\n // carry the re-keys `requiredContainerIds` names.\n descendantRekeysRequired: CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE,\n // The revoke removes the caller's write access on owed descendants. Another\n // authorized member must perform it; retrying with carried rekeys cannot help.\n descendantRekeysInaccessible: \"container_descendant_rekeys_inaccessible\",\n manifestAlreadyExists: \"container_manifest_already_exists\",\n // A create or move would leave a path longer than readers accept. The same\n // request never succeeds: a queued move is abandoned, while a queued create\n // keeps its intent (a later local move can re-arm it).\n pathTooDeep: \"container_path_too_deep\",\n stateStale: CONTAINER_MUTATION_STATE_STALE_ERROR_CODE,\n} as const;\n\nexport const ContainerMutationBehaviorErrorCodeSchema = z.literal([\n CONTAINER_MUTATION_ERROR_CODES.ancestorRekeysRequired,\n CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired,\n CONTAINER_MUTATION_ERROR_CODES.descendantRekeysInaccessible,\n CONTAINER_MUTATION_ERROR_CODES.manifestAlreadyExists,\n CONTAINER_MUTATION_ERROR_CODES.pathTooDeep,\n CONTAINER_MUTATION_ERROR_CODES.stateStale,\n]);\n\nexport const ContainerMutationErrorCodeSchema = z.union([\n ContainerMutationBehaviorErrorCodeSchema,\n // The compound container-plus-metadata-document create can fail in either\n // half of its transaction, so its envelope preserves document-domain tags.\n DocumentMutationErrorCodeSchema,\n]);\n\nexport type ContainerMutationErrorCode = z.infer<\n typeof ContainerMutationErrorCodeSchema\n>;\n\nexport const ContainerMutationFailureResponseSchema = z.union([\n z.looseObject({\n code: ContainerMutationErrorCodeSchema.optional(),\n error: z.string().min(1),\n /** Parent-first; owed levels, or the inaccessible subset on a refused revoke. */\n requiredContainerIds: arraySchema(\n nonEmptyStringSchema,\n MAX_ROTATION_CONTAINER_REKEYS,\n ).optional(),\n }),\n PrincipalPolicyStaleErrorResponseSchema,\n]);\n\nexport type ContainerMutationFailureResponse = z.infer<\n typeof ContainerMutationFailureResponseSchema\n>;\n"]}
@@ -0,0 +1,3 @@
1
+ /** A refused container mutation can be replanned against fresh served heads. */
2
+ export const CONTAINER_MUTATION_STATE_STALE_ERROR_CODE = "container_mutation_state_stale";
3
+ //# sourceMappingURL=containerMutationStateStaleError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containerMutationStateStaleError.js","sourceRoot":"","sources":["containerMutationStateStaleError.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,CAAC,MAAM,yCAAyC,GACpD,gCAAgC,CAAC","sourcesContent":["/** A refused container mutation can be replanned against fresh served heads. */\nexport const CONTAINER_MUTATION_STATE_STALE_ERROR_CODE =\n \"container_mutation_state_stale\";\n"]}
@@ -2628,6 +2628,18 @@ export declare const CommitOrganizationGroupPolicyConflictResponseSchema: z.ZodU
2628
2628
  code: "container_descendant_rekeys_required";
2629
2629
  error: string;
2630
2630
  requiredContainerIds: string[];
2631
+ }>>, z.ZodType<{
2632
+ code: "container_mutation_state_stale";
2633
+ error: string;
2634
+ }, {
2635
+ code: "container_mutation_state_stale";
2636
+ error: string;
2637
+ }, z.core.$ZodTypeInternals<{
2638
+ code: "container_mutation_state_stale";
2639
+ error: string;
2640
+ }, {
2641
+ code: "container_mutation_state_stale";
2642
+ error: string;
2631
2643
  }>>]>;
2632
2644
  export declare const PrincipalPolicyStaleErrorResponseSchema: z.ZodType<{
2633
2645
  code: "principal_policy_stale";
@@ -3,6 +3,7 @@ import { arraySchema, loosePlainObject, nonEmptyStringSchema } from "../schema.j
3
3
  import { MAX_ROTATION_CONTAINER_REKEYS } from "../util/index.js";
4
4
  import { PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT } from "../util/principalHistoryWire.js";
5
5
  import { ContainerMutationResponseSchema } from "./container.js";
6
+ import { CONTAINER_MUTATION_STATE_STALE_ERROR_CODE } from "./containerMutationStateStaleError.js";
6
7
  import { CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE } from "./descendantRekeysRequiredError.js";
7
8
  import { BillingErrorResponseSchema } from "./organizationBilling.js";
8
9
  import { ReferencedPrincipalStateResponseSchema } from "./principalReference.js";
@@ -48,6 +49,10 @@ const PrincipalPolicyDescendantRekeysRequiredResponseSchema = loosePlainObject({
48
49
  export const CommitOrganizationGroupPolicyConflictResponseSchema = z.union([
49
50
  PrincipalPolicyErrorResponseSchema,
50
51
  PrincipalPolicyDescendantRekeysRequiredResponseSchema,
52
+ loosePlainObject({
53
+ code: z.literal(CONTAINER_MUTATION_STATE_STALE_ERROR_CODE),
54
+ error: z.string().min(1),
55
+ }),
51
56
  ]);
52
57
  export const PrincipalPolicyStaleErrorResponseSchema = loosePlainObject({
53
58
  code: z.literal("principal_policy_stale"),
@@ -1 +1 @@
1
- {"version":3,"file":"principal.js","sourceRoot":"","sources":["principal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM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";\nimport { MAX_ROTATION_CONTAINER_REKEYS } from \"../util\";\nimport { PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT } from \"../util/principalHistoryWire\";\nimport { ContainerMutationResponseSchema } from \"./container\";\nimport { CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE } from \"./descendantRekeysRequiredError\";\nimport { BillingErrorResponseSchema } from \"./organizationBilling\";\nimport { ReferencedPrincipalStateResponseSchema } from \"./principalReference\";\n\nimport {\n CurrentPrincipalMemberEnvelopesResponseSchema,\n PrincipalContainerGrantResponseSchema,\n PrincipalPolicyStateChainEntryResponseSchema,\n PrincipalProjectionMemberResponseSchema,\n PrincipalStatePayloadResponseSchema,\n PrincipalStateResponseSchema,\n} from \"./principalSnapshot\";\n\nexport {\n type CurrentPrincipalMemberEnvelopesResponse,\n CurrentPrincipalMemberEnvelopesResponseSchema,\n isCurrentPrincipalMemberEnvelopesResponse,\n isPrincipalPolicyStateChainEntryResponse,\n isPrincipalStatePayloadResponse,\n isPrincipalStateResponse,\n type PrincipalContainerGrantResponse,\n PrincipalContainerGrantResponseSchema,\n type PrincipalMemberEnvelopeResponse,\n PrincipalMemberEnvelopeResponseSchema,\n type PrincipalPolicySnapshotResponse,\n PrincipalPolicySnapshotResponseSchema,\n type PrincipalPolicyStateChainEntryResponse,\n PrincipalPolicyStateChainEntryResponseSchema,\n type PrincipalProjectionMemberResponse,\n PrincipalProjectionMemberResponseSchema,\n type PrincipalStateExternalAuthorityResponse,\n PrincipalStateExternalAuthorityResponseSchema,\n type PrincipalStatePayloadResponse,\n PrincipalStatePayloadResponseSchema,\n type PrincipalStateResponse,\n PrincipalStateResponseSchema,\n} from \"./principalSnapshot\";\n\nexport const principalPolicyCurrentResponseShape = {\n currentGrants: arraySchema(PrincipalContainerGrantResponseSchema),\n currentMemberEnvelopes: CurrentPrincipalMemberEnvelopesResponseSchema,\n currentPayload: PrincipalStatePayloadResponseSchema,\n currentProjection: arraySchema(PrincipalProjectionMemberResponseSchema),\n currentState: PrincipalStateResponseSchema,\n};\n\nexport const PrincipalPolicyBundleResponseSchema = loosePlainObject({\n ...principalPolicyCurrentResponseShape,\n previousStates: arraySchema(PrincipalPolicyStateChainEntryResponseSchema),\n});\n\nexport type PrincipalPolicyBundleResponse = z.infer<\n typeof PrincipalPolicyBundleResponseSchema\n>;\n\nexport const PrincipalPolicyMutationResponseSchema = loosePlainObject({\n ...principalPolicyCurrentResponseShape,\n containerMutations: arraySchema(ContainerMutationResponseSchema),\n});\n\nexport type PrincipalPolicyMutationResponse = z.infer<\n typeof PrincipalPolicyMutationResponseSchema\n>;\n\nexport const CommitOrganizationGroupPolicyResponseSchema = loosePlainObject({\n groupPolicy: PrincipalPolicyMutationResponseSchema,\n memberPolicy: PrincipalPolicyMutationResponseSchema.optional(),\n organizationPolicy: PrincipalPolicyMutationResponseSchema,\n});\n\nexport type CommitOrganizationGroupPolicyResponse = z.infer<\n typeof CommitOrganizationGroupPolicyResponseSchema\n>;\n\nexport const PrincipalPolicyErrorResponseSchema = BillingErrorResponseSchema;\n\nexport type PrincipalPolicyErrorResponse = z.infer<\n typeof PrincipalPolicyErrorResponseSchema\n>;\n\n/**\n * A group policy change rematerializes its granted containers, and a rekey or\n * revoke among them is a rotation like any other: one that would leave a level\n * above a directly granted container pinned to a retired epoch is refused, and\n * this names the descendant rekeys the batch must carry, parent-first.\n */\nconst PrincipalPolicyDescendantRekeysRequiredResponseSchema = loosePlainObject({\n code: z.literal(CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE),\n error: z.string().min(1),\n requiredContainerIds: arraySchema(\n nonEmptyStringSchema,\n MAX_ROTATION_CONTAINER_REKEYS,\n ),\n});\n\n/**\n * The commit's conflict envelope alone: only a group commit carries container\n * mutations, so only it can be refused for what they strand. The principal\n * policy read and the organization policy write keep the plain envelope.\n */\nexport const CommitOrganizationGroupPolicyConflictResponseSchema = z.union([\n PrincipalPolicyErrorResponseSchema,\n PrincipalPolicyDescendantRekeysRequiredResponseSchema,\n]);\n\nexport const PrincipalPolicyStaleErrorResponseSchema = loosePlainObject({\n code: z.literal(\"principal_policy_stale\"),\n error: z.string().min(1),\n principalHeads: arraySchema(\n ReferencedPrincipalStateResponseSchema,\n PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT,\n ),\n});\n\nexport type PrincipalPolicyStaleErrorResponse = z.infer<\n typeof PrincipalPolicyStaleErrorResponseSchema\n>;\n\nexport function isPrincipalPolicyBundleResponse(\n value: unknown,\n): value is PrincipalPolicyBundleResponse {\n return PrincipalPolicyBundleResponseSchema.safeParse(value).success;\n}\n\nexport function isPrincipalPolicyMutationResponse(\n value: unknown,\n): value is PrincipalPolicyMutationResponse {\n return PrincipalPolicyMutationResponseSchema.safeParse(value).success;\n}\n\nexport function isCommitOrganizationGroupPolicyResponse(\n value: unknown,\n): value is CommitOrganizationGroupPolicyResponse {\n return CommitOrganizationGroupPolicyResponseSchema.safeParse(value).success;\n}\n\nexport function isPrincipalPolicyStaleErrorResponse(\n value: unknown,\n): value is PrincipalPolicyStaleErrorResponse {\n return PrincipalPolicyStaleErrorResponseSchema.safeParse(value).success;\n}\n"]}
1
+ {"version":3,"file":"principal.js","sourceRoot":"","sources":["principal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,yCAAyC,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,+CAA+C,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,sCAAsC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ringSchema } from \"../schema\";\nimport { MAX_ROTATION_CONTAINER_REKEYS } from \"../util\";\nimport { PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT } from \"../util/principalHistoryWire\";\nimport { ContainerMutationResponseSchema } from \"./container\";\nimport { CONTAINER_MUTATION_STATE_STALE_ERROR_CODE } from \"./containerMutationStateStaleError\";\nimport { CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE } from \"./descendantRekeysRequiredError\";\nimport { BillingErrorResponseSchema } from \"./organizationBilling\";\nimport { ReferencedPrincipalStateResponseSchema } from \"./principalReference\";\n\nimport {\n CurrentPrincipalMemberEnvelopesResponseSchema,\n PrincipalContainerGrantResponseSchema,\n PrincipalPolicyStateChainEntryResponseSchema,\n PrincipalProjectionMemberResponseSchema,\n PrincipalStatePayloadResponseSchema,\n PrincipalStateResponseSchema,\n} from \"./principalSnapshot\";\n\nexport {\n type CurrentPrincipalMemberEnvelopesResponse,\n CurrentPrincipalMemberEnvelopesResponseSchema,\n isCurrentPrincipalMemberEnvelopesResponse,\n isPrincipalPolicyStateChainEntryResponse,\n isPrincipalStatePayloadResponse,\n isPrincipalStateResponse,\n type PrincipalContainerGrantResponse,\n PrincipalContainerGrantResponseSchema,\n type PrincipalMemberEnvelopeResponse,\n PrincipalMemberEnvelopeResponseSchema,\n type PrincipalPolicySnapshotResponse,\n PrincipalPolicySnapshotResponseSchema,\n type PrincipalPolicyStateChainEntryResponse,\n PrincipalPolicyStateChainEntryResponseSchema,\n type PrincipalProjectionMemberResponse,\n PrincipalProjectionMemberResponseSchema,\n type PrincipalStateExternalAuthorityResponse,\n PrincipalStateExternalAuthorityResponseSchema,\n type PrincipalStatePayloadResponse,\n PrincipalStatePayloadResponseSchema,\n type PrincipalStateResponse,\n PrincipalStateResponseSchema,\n} from \"./principalSnapshot\";\n\nexport const principalPolicyCurrentResponseShape = {\n currentGrants: arraySchema(PrincipalContainerGrantResponseSchema),\n currentMemberEnvelopes: CurrentPrincipalMemberEnvelopesResponseSchema,\n currentPayload: PrincipalStatePayloadResponseSchema,\n currentProjection: arraySchema(PrincipalProjectionMemberResponseSchema),\n currentState: PrincipalStateResponseSchema,\n};\n\nexport const PrincipalPolicyBundleResponseSchema = loosePlainObject({\n ...principalPolicyCurrentResponseShape,\n previousStates: arraySchema(PrincipalPolicyStateChainEntryResponseSchema),\n});\n\nexport type PrincipalPolicyBundleResponse = z.infer<\n typeof PrincipalPolicyBundleResponseSchema\n>;\n\nexport const PrincipalPolicyMutationResponseSchema = loosePlainObject({\n ...principalPolicyCurrentResponseShape,\n containerMutations: arraySchema(ContainerMutationResponseSchema),\n});\n\nexport type PrincipalPolicyMutationResponse = z.infer<\n typeof PrincipalPolicyMutationResponseSchema\n>;\n\nexport const CommitOrganizationGroupPolicyResponseSchema = loosePlainObject({\n groupPolicy: PrincipalPolicyMutationResponseSchema,\n memberPolicy: PrincipalPolicyMutationResponseSchema.optional(),\n organizationPolicy: PrincipalPolicyMutationResponseSchema,\n});\n\nexport type CommitOrganizationGroupPolicyResponse = z.infer<\n typeof CommitOrganizationGroupPolicyResponseSchema\n>;\n\nexport const PrincipalPolicyErrorResponseSchema = BillingErrorResponseSchema;\n\nexport type PrincipalPolicyErrorResponse = z.infer<\n typeof PrincipalPolicyErrorResponseSchema\n>;\n\n/**\n * A group policy change rematerializes its granted containers, and a rekey or\n * revoke among them is a rotation like any other: one that would leave a level\n * above a directly granted container pinned to a retired epoch is refused, and\n * this names the descendant rekeys the batch must carry, parent-first.\n */\nconst PrincipalPolicyDescendantRekeysRequiredResponseSchema = loosePlainObject({\n code: z.literal(CONTAINER_DESCENDANT_REKEYS_REQUIRED_ERROR_CODE),\n error: z.string().min(1),\n requiredContainerIds: arraySchema(\n nonEmptyStringSchema,\n MAX_ROTATION_CONTAINER_REKEYS,\n ),\n});\n\n/**\n * The commit's conflict envelope alone: only a group commit carries container\n * mutations, so only it can be refused for what they strand. The principal\n * policy read and the organization policy write keep the plain envelope.\n */\nexport const CommitOrganizationGroupPolicyConflictResponseSchema = z.union([\n PrincipalPolicyErrorResponseSchema,\n PrincipalPolicyDescendantRekeysRequiredResponseSchema,\n loosePlainObject({\n code: z.literal(CONTAINER_MUTATION_STATE_STALE_ERROR_CODE),\n error: z.string().min(1),\n }),\n]);\n\nexport const PrincipalPolicyStaleErrorResponseSchema = loosePlainObject({\n code: z.literal(\"principal_policy_stale\"),\n error: z.string().min(1),\n principalHeads: arraySchema(\n ReferencedPrincipalStateResponseSchema,\n PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT,\n ),\n});\n\nexport type PrincipalPolicyStaleErrorResponse = z.infer<\n typeof PrincipalPolicyStaleErrorResponseSchema\n>;\n\nexport function isPrincipalPolicyBundleResponse(\n value: unknown,\n): value is PrincipalPolicyBundleResponse {\n return PrincipalPolicyBundleResponseSchema.safeParse(value).success;\n}\n\nexport function isPrincipalPolicyMutationResponse(\n value: unknown,\n): value is PrincipalPolicyMutationResponse {\n return PrincipalPolicyMutationResponseSchema.safeParse(value).success;\n}\n\nexport function isCommitOrganizationGroupPolicyResponse(\n value: unknown,\n): value is CommitOrganizationGroupPolicyResponse {\n return CommitOrganizationGroupPolicyResponseSchema.safeParse(value).success;\n}\n\nexport function isPrincipalPolicyStaleErrorResponse(\n value: unknown,\n): value is PrincipalPolicyStaleErrorResponse {\n return PrincipalPolicyStaleErrorResponseSchema.safeParse(value).success;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/client-sdk",
3
- "version": "0.1.103",
3
+ "version": "0.1.104",
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": {
@@ -0,0 +1,45 @@
1
+ import { rememberVerifiedContainerHeads } from "../../../data/containers/shared/heldContainerHeads.js";
2
+ import { acknowledgeContainerMutationBatch } from "../../../data/containers/shared/mutationAcknowledgement.js";
3
+ import { scheduleHeldDescendantRecitations } from "../child/recite.js";
4
+ export async function acknowledgePrincipalContainerRematerialization(input, entries, responses, stillCurrent) {
5
+ const isCurrent = () => input.stillCurrent?.() !== false && stillCurrent?.() !== false;
6
+ const heads = entries.map((entry) => entry.planned.plan);
7
+ const acknowledged = await acknowledgeContainerMutationBatch({
8
+ execSql: input.execSql,
9
+ plans: heads,
10
+ responses,
11
+ stillCurrent: isCurrent,
12
+ });
13
+ if (!acknowledged || !isCurrent())
14
+ return;
15
+ const plansByOrganization = new Map();
16
+ for (const head of heads) {
17
+ const organizationId = head.state.organizationId;
18
+ const group = plansByOrganization.get(organizationId) ?? [];
19
+ group.push(head);
20
+ plansByOrganization.set(organizationId, group);
21
+ }
22
+ for (const [organizationId, organizationPlans] of plansByOrganization) {
23
+ try {
24
+ rememberVerifiedContainerHeads({
25
+ organizationId,
26
+ execSql: input.execSql,
27
+ heads: [],
28
+ policies: [input.nextPolicy],
29
+ });
30
+ }
31
+ catch {
32
+ // Cache failure must not invalidate the durably acknowledged batch.
33
+ continue;
34
+ }
35
+ scheduleHeldDescendantRecitations({
36
+ apiClient: input.apiClient,
37
+ author: { ...input.author, organizationId },
38
+ execSql: input.execSql,
39
+ plans: organizationPlans,
40
+ stillCurrent: input.recitationStillCurrent ?? isCurrent,
41
+ reportSecurityIncident: input.reportSecurityIncident,
42
+ });
43
+ }
44
+ }
45
+ //# sourceMappingURL=acknowledgePrincipalContainerRematerialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acknowledgePrincipalContainerRematerialization.js","sourceRoot":"","sources":["acknowledgePrincipalContainerRematerialization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,oDAAoD,CAAC;AAEpG,OAAO,EAAE,iCAAiC,EAAE,MAAM,yDAAyD,CAAC;AAC5G,OAAO,EAAE,iCAAiC,EAAE,MAAM,iBAAiB,CAAC;AAIpE,MAAM,CAAC,KAAK,UAAU,8CAA8C,CAClE,KAA+C,EAC/C,OAA4C,EAC5C,SAA+C,EA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M,EAAE,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE;YAC3C,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,KAAK,EAAE,iBAAiB;YACxB,YAAY,EAAE,KAAK,CAAC,sBAAsB,IAAI,SAAS;YACvD,sBAAsB,EAAE,KAAK,CAAC,sBAAsB;SACrD,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type { ContainerMutationResponse } from \"@tearleads/validators/response\";\nimport { rememberVerifiedContainerHeads } from \"../../../data/containers/shared/heldContainerHeads\";\nimport type { AuthoredContainerMutationHead } from \"../../../data/containers/shared/mutationAcknowledgement\";\nimport { acknowledgeContainerMutationBatch } from \"../../../data/containers/shared/mutationAcknowledgement\";\nimport { scheduleHeldDescendantRecitations } from \"../child/recite\";\nimport type { PrincipalContainerRematerializationInput } from \"./principalContainerRematerializationPlanning\";\nimport type { PlannedRematerialization } from \"./principalContainerRematerializationTargets\";\n\nexport async function acknowledgePrincipalContainerRematerialization(\n input: PrincipalContainerRematerializationInput,\n entries: readonly PlannedRematerialization[],\n responses: readonly ContainerMutationResponse[],\n stillCurrent?: (() => boolean) | undefined,\n): Promise<void> {\n const isCurrent = () =>\n input.stillCurrent?.() !== false && stillCurrent?.() !== false;\n const heads = entries.map((entry) => entry.planned.plan);\n const acknowledged = await acknowledgeContainerMutationBatch({\n execSql: input.execSql,\n plans: heads,\n responses,\n stillCurrent: isCurrent,\n });\n if (!acknowledged || !isCurrent()) return;\n const plansByOrganization = new Map<\n string,\n AuthoredContainerMutationHead[]\n >();\n for (const head of heads) {\n const organizationId = head.state.organizationId;\n const group = plansByOrganization.get(organizationId) ?? [];\n group.push(head);\n plansByOrganization.set(organizationId, group);\n }\n for (const [organizationId, organizationPlans] of plansByOrganization) {\n try {\n rememberVerifiedContainerHeads({\n organizationId,\n execSql: input.execSql,\n heads: [],\n policies: [input.nextPolicy],\n });\n } catch {\n // Cache failure must not invalidate the durably acknowledged batch.\n continue;\n }\n scheduleHeldDescendantRecitations({\n apiClient: input.apiClient,\n author: { ...input.author, organizationId },\n execSql: input.execSql,\n plans: organizationPlans,\n stillCurrent: input.recitationStillCurrent ?? isCurrent,\n reportSecurityIncident: input.reportSecurityIncident,\n });\n }\n}\n"]}
@@ -1,15 +1,14 @@
1
- import { rememberVerifiedContainerHeads } from "../../../data/containers/shared/heldContainerHeads.js";
2
- import { acknowledgeContainerMutationBatch } from "../../../data/containers/shared/mutationAcknowledgement.js";
3
1
  import { getTargetContainerContext, readContainerState, } from "../../../data/containers/shared/projection.js";
4
2
  import { verifyContainerWriterProjection, } from "../../../data/keyingProjectionVerification/index.js";
3
+ import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
5
4
  import { createProjectionUserKeyResolver } from "../../../data/keyingProjectionVerification/userKeyResolver.js";
6
- import { scheduleHeldDescendantRecitations } from "../child/recite.js";
7
5
  import { buildMaterializedContainerRekeyPlan } from "../child/rekey/index.js";
8
6
  import { rebaseOnDeepestAncestor } from "../child/rekey/carriedDescendantRekeys.js";
9
7
  import { containerWriterProjectionFromRotationPlan, containerWriterProjectionFromSharePlan, isSpeculativeContainerWriterProjection, } from "../child/rekey/rekeyProjection.js";
10
8
  import { buildMaterializedContainerRevokePlan } from "../child/revoke.js";
11
9
  import { selectReplacementPrincipalPolicyReferences } from "../child/rotation/replacementPrincipalPolicyReferences.js";
12
10
  import { buildMaterializedContainerSharePlan } from "../child/share/shareMaterialization.js";
11
+ import { acknowledgePrincipalContainerRematerialization } from "./acknowledgePrincipalContainerRematerialization.js";
13
12
  import { withPrecedingRematerialization } from "./precedingPrincipalRematerialization.js";
14
13
  import { addPlan, assertNamedContainersRotated, carryLevel, planOnceMoreAfterRollback, rerootOnAuthoredPaths, staleLevelsAbove, } from "./principalContainerRematerializationPlanning.js";
15
14
  import { loadRematerializationTargets, loadServedProjection, seededPrincipalPolicyCache, } from "./principalContainerRematerializationTargets.js";
@@ -57,9 +56,6 @@ async function loadGrantedContainerContext(input, grantRow, projection, principa
57
56
  export async function buildPrincipalContainerRematerializationBatch(input) {
58
57
  return (await buildPrincipalContainerRematerializationPlans(input)).entries.map((entry) => entry.planned.plan.request);
59
58
  }
60
- function authoredMutationHead(planned) {
61
- return planned.plan;
62
- }
63
59
  async function buildPrincipalContainerRematerializationPlan(input) {
64
60
  const { grantRow } = input;
65
61
  const rematerialization = {
@@ -249,6 +245,20 @@ export async function preparePrincipalContainerRematerializationBatch(input) {
249
245
  get requests() {
250
246
  return requests();
251
247
  },
248
+ refreshAfterConflict: async () => {
249
+ assertProjectionVerificationCurrent(input.stillCurrent);
250
+ for (const containerId of new Set([
251
+ ...input.grants.map((grant) => grant.containerId),
252
+ ...entries.map((entry) => entry.planned.plan.containerId),
253
+ ])) {
254
+ input.apiClient.evictContainerWriterProjection?.(containerId);
255
+ }
256
+ const replanned = await buildPrincipalContainerRematerializationPlans(input);
257
+ entries = replanned.entries;
258
+ retiredContainerIds = replanned.retiredContainerIds;
259
+ preceding = replanned.preceding;
260
+ return requests();
261
+ },
252
262
  carry: async (requiredContainerIds) => {
253
263
  // The refused attempt rolled back whole, so every served head still
254
264
  // stands; the batch is signed again from them with the named levels in.
@@ -259,47 +269,7 @@ export async function preparePrincipalContainerRematerializationBatch(input) {
259
269
  preceding = replanned.preceding;
260
270
  return requests();
261
271
  },
262
- acknowledge: async (responses, stillCurrent) => {
263
- const isCurrent = () => input.stillCurrent?.() !== false && stillCurrent?.() !== false;
264
- const heads = entries.map((entry) => authoredMutationHead(entry.planned));
265
- const acknowledged = await acknowledgeContainerMutationBatch({
266
- execSql: input.execSql,
267
- plans: heads,
268
- responses,
269
- stillCurrent: isCurrent,
270
- });
271
- if (!acknowledged || !isCurrent())
272
- return;
273
- const plansByOrganization = new Map();
274
- for (const head of heads) {
275
- const organizationId = head.state.organizationId;
276
- const group = plansByOrganization.get(organizationId) ?? [];
277
- group.push(head);
278
- plansByOrganization.set(organizationId, group);
279
- }
280
- for (const [organizationId, organizationPlans] of plansByOrganization) {
281
- try {
282
- rememberVerifiedContainerHeads({
283
- organizationId,
284
- execSql: input.execSql,
285
- heads: [],
286
- policies: [input.nextPolicy],
287
- });
288
- }
289
- catch {
290
- // Cache failure must not invalidate the durably acknowledged batch.
291
- continue;
292
- }
293
- scheduleHeldDescendantRecitations({
294
- apiClient: input.apiClient,
295
- author: { ...input.author, organizationId },
296
- execSql: input.execSql,
297
- plans: organizationPlans,
298
- stillCurrent: input.recitationStillCurrent ?? isCurrent,
299
- reportSecurityIncident: input.reportSecurityIncident,
300
- });
301
- }
302
- },
272
+ acknowledge: (responses, stillCurrent) => acknowledgePrincipalContainerRematerialization(input, entries, responses, stillCurrent),
303
273
  };
304
274
  }
305
275
  //# sourceMappingURL=principalContainerRematerialization.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"principalContainerRematerialization.js","sourceRoot":"","sources":["principalContainerRematerialization.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,8BAA8B,EAAE,MAAM,oDAAoD,CAAC;AAEpG,OAAO,EAAE,iCAAiC,EAAE,MAAM,yDAAyD,CAAC;AAC5G,OAAO,EACL,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEL,+BAA+B,GAChC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,4DAA4D,CAAC;AAC7G,OAAO,EAAE,iCAAiC,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EACL,yCAAyC,EACzC,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,0CAA0C,EAAE,MAAM,wDAAwD,CAAC;AACpH,OAAO,EAAE,mCAAmC,EAAE,MAAM,qC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AE;oBAC3C,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,KAAK,EAAE,iBAAiB;oBACxB,YAAY,EAAE,KAAK,CAAC,sBAAsB,IAAI,SAAS;oBACvD,sBAAsB,EAAE,KAAK,CAAC,sBAAsB;iBACrD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ContainerDirectGrant,\n PrincipalContainerGrant,\n} from \"@tearleads/crypto\";\nimport type { ContainerMutationRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerMutationResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { rememberVerifiedContainerHeads } from \"../../../data/containers/shared/heldContainerHeads\";\nimport type { AuthoredContainerMutationHead } from \"../../../data/containers/shared/mutationAcknowledgement\";\nimport { acknowledgeContainerMutationBatch } from \"../../../data/containers/shared/mutationAcknowledgement\";\nimport {\n getTargetContainerContext,\n readContainerState,\n} from \"../../../data/containers/shared/projection\";\nimport {\n type PrincipalPolicyCache,\n verifyContainerWriterProjection,\n} from \"../../../data/keyingProjectionVerification\";\nimport { createProjectionUserKeyResolver } from \"../../../data/keyingProjectionVerification/userKeyResolver\";\nimport { scheduleHeldDescendantRecitations } from \"../child/recite\";\nimport { buildMaterializedContainerRekeyPlan } from \"../child/rekey\";\nimport { rebaseOnDeepestAncestor } from \"../child/rekey/carriedDescendantRekeys\";\nimport {\n containerWriterProjectionFromRotationPlan,\n containerWriterProjectionFromSharePlan,\n isSpeculativeContainerWriterProjection,\n} from \"../child/rekey/rekeyProjection\";\nimport { buildMaterializedContainerRevokePlan } from \"../child/revoke\";\nimport { selectReplacementPrincipalPolicyReferences } from \"../child/rotation/replacementPrincipalPolicyReferences\";\nimport { buildMaterializedContainerSharePlan } from \"../child/share/shareMaterialization\";\nimport { withPrecedingRematerialization } from \"./precedingPrincipalRematerialization\";\nimport {\n addPlan,\n assertNamedContainersRotated,\n type BatchPlanning,\n carryLevel,\n type PrincipalContainerRematerializationInput,\n type PrincipalRematerializationPredecessor,\n planOnceMoreAfterRollback,\n rerootOnAuthoredPaths,\n staleLevelsAbove,\n} from \"./principalContainerRematerializationPlanning\";\nimport {\n loadRematerializationTargets,\n loadServedProjection,\n type MaterializedPrincipalContainerMutationPlan,\n type PlannedRematerialization,\n type RematerializationTarget,\n seededPrincipalPolicyCache,\n} from \"./principalContainerRematerializationTargets\";\n\nfunction matchingGroupGrant(input: {\n readonly directGrants: readonly ContainerDirectGrant[];\n readonly groupId: string;\n}): ContainerDirectGrant | null {\n return (\n input.directGrants.find(\n (grant) =>\n grant.subjectType === \"group\" && grant.subjectId === input.groupId,\n ) ?? null\n );\n}\n\nfunction referencedGroupKeyEpoch(input: {\n readonly groupId: string;\n readonly referencedPrincipalHeads: ReturnType<\n typeof readContainerState\n >[\"referencedPrincipalHeads\"];\n}): number | null {\n return (\n input.referencedPrincipalHeads.find(\n (head) =>\n head.principalType === \"group\" && head.principalId === input.groupId,\n )?.keyEpoch ?? null\n );\n}\n\nasync function loadGrantedContainerContext(\n input: PrincipalContainerRematerializationInput,\n grantRow: PrincipalContainerGrant,\n projection: ContainerWriterProjectionResponse,\n principalPolicyCache: PrincipalPolicyCache,\n) {\n // A projection re-rooted on a rotation this batch has yet to commit must\n // not pin anything: its heads are speculative until acknowledged, and a\n // pin past the group's served head would refuse the other served paths.\n await verifyContainerWriterProjection({\n execSql: input.execSql,\n persistVerificationCheckpoints:\n !isSpeculativeContainerWriterProjection(projection),\n principalPolicyCache,\n projection,\n resolveUserKey: createProjectionUserKeyResolver({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n }),\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n const state = readContainerState(\n getTargetContainerContext(projection).manifest,\n );\n const grant = matchingGroupGrant({\n directGrants: state.directGrants,\n groupId: input.groupId,\n });\n if (grant && grant.accessLevel !== grantRow.accessLevel) {\n const nextGrant = input.nextPolicy.grants.find(\n (candidate) => candidate.containerId === grantRow.containerId,\n );\n if (!nextGrant || nextGrant.accessLevel !== grantRow.accessLevel) {\n throw new Error(\n `Container ${grantRow.containerId} does not contain the expected group grant`,\n );\n }\n }\n const referencedKeyEpoch = referencedGroupKeyEpoch({\n groupId: input.groupId,\n referencedPrincipalHeads: state.referencedPrincipalHeads,\n });\n if (grant && referencedKeyEpoch === null) {\n throw new Error(\n `Container ${grantRow.containerId} is missing its group reference`,\n );\n }\n return { grant, projection, referencedKeyEpoch };\n}\n\nexport async function buildPrincipalContainerRematerializationBatch(\n input: PrincipalContainerRematerializationInput,\n): Promise<ContainerMutationRequest[]> {\n return (\n await buildPrincipalContainerRematerializationPlans(input)\n ).entries.map((entry) => entry.planned.plan.request);\n}\n\nexport interface PreparedPrincipalContainerRematerializationBatch {\n readonly preceding?: PrincipalRematerializationPredecessor | undefined;\n readonly retiredContainerIds: readonly string[];\n readonly acknowledge: (\n responses: readonly ContainerMutationResponse[],\n stillCurrent?: (() => boolean) | undefined,\n ) => Promise<void>;\n /**\n * Re-sign the batch with the descendant rekeys the server named for its\n * rotations woven in, parent-first, each against the path the batch will\n * leave behind. A named container the batch already rotates is re-planned\n * under what is carried above it, so no container rotates twice. Returns the\n * whole request list, which replaces `requests`; `acknowledge` then expects\n * the responses in that order.\n */\n readonly carry: (\n requiredContainerIds: readonly string[],\n ) => Promise<readonly ContainerMutationRequest[]>;\n readonly plans: readonly MaterializedPrincipalContainerMutationPlan[];\n readonly requests: readonly ContainerMutationRequest[];\n}\n\nfunction authoredMutationHead(\n planned: MaterializedPrincipalContainerMutationPlan,\n): AuthoredContainerMutationHead {\n return planned.plan;\n}\n\nasync function buildPrincipalContainerRematerializationPlan(input: {\n readonly grantRow: PrincipalContainerGrant;\n /** Keys the batch minted above this container; see `BatchPlanning`. */\n readonly knownContainerKeks: ReadonlyMap<string, Uint8Array>;\n /** Holds the policy this batch commits, which rebased paths already cite. */\n readonly principalPolicyCache: PrincipalPolicyCache;\n /** The served projection, re-rooted on any rotation planned above it. */\n readonly projection: ContainerWriterProjectionResponse;\n readonly rematerialization: PrincipalContainerRematerializationInput;\n readonly resolveProjectionUserKey: ReturnType<\n typeof createProjectionUserKeyResolver\n >;\n}): Promise<MaterializedPrincipalContainerMutationPlan> {\n const { grantRow } = input;\n const rematerialization = {\n ...input.rematerialization,\n nextPolicy: await selectReplacementPrincipalPolicyReferences({\n policy: input.rematerialization.nextPolicy,\n projection: input.projection,\n principalPolicyCache: input.principalPolicyCache,\n resolveAuthoredPolicyReferences:\n input.rematerialization.resolveAuthoredPolicyReferences,\n }),\n };\n const { grant, projection, referencedKeyEpoch } =\n await loadGrantedContainerContext(\n rematerialization,\n grantRow,\n input.projection,\n input.principalPolicyCache,\n );\n const nextGrant = rematerialization.nextPolicy.grants.find(\n (candidate) => candidate.containerId === grantRow.containerId,\n );\n const author = {\n ...rematerialization.author,\n organizationId: projection.organizationId,\n };\n const sharedInput = {\n author,\n execSql: rematerialization.execSql,\n knownContainerKeks: input.knownContainerKeks,\n // Planning against a path this batch has yet to commit pins nothing; the\n // acknowledgement advances every head at once. The rekey planner applies\n // this rule itself; revoke and grant planning take it from here.\n persistVerificationCheckpoints:\n !isSpeculativeContainerWriterProjection(projection),\n previousProjection: projection,\n principalPolicyCache: input.principalPolicyCache,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: rematerialization.stillCurrent,\n targetSecretKey: rematerialization.targetSecretKey,\n warmReferencedPrincipalPolicies:\n rematerialization.warmReferencedPrincipalPolicies,\n };\n if (grantRow.containerId === rematerialization.revokedContainerId) {\n if (!grant) {\n throw new Error(\n `Container ${grantRow.containerId} does not contain the revoked group grant`,\n );\n }\n return buildMaterializedContainerRevokePlan({\n ...sharedInput,\n replacementPrincipalPolicy: rematerialization.nextPolicy,\n revokedSubject: {\n subjectId: rematerialization.groupId,\n subjectType: \"group\",\n },\n });\n }\n if (!grant || grant.accessLevel !== nextGrant?.accessLevel) {\n if (!nextGrant) {\n throw new Error(\n `Container ${grantRow.containerId} is absent from the next group grant set`,\n );\n }\n return buildMaterializedContainerSharePlan({\n ...sharedInput,\n accessLevel: nextGrant.accessLevel,\n recipient: {\n principalPolicy: rematerialization.nextPolicy,\n subjectId: rematerialization.groupId,\n subjectType: \"group\",\n },\n });\n }\n if (referencedKeyEpoch === rematerialization.nextPolicy.keyEpoch) {\n return buildMaterializedContainerSharePlan({\n ...sharedInput,\n accessLevel: grant.accessLevel,\n recipient: {\n principalPolicy: rematerialization.nextPolicy,\n subjectId: rematerialization.groupId,\n subjectType: \"group\",\n },\n });\n }\n return buildMaterializedContainerRekeyPlan({\n ...sharedInput,\n replacementPrincipalPolicy: rematerialization.nextPolicy,\n });\n}\n\n/**\n * Plan one target against the paths already planned above it. A grant's\n * rematerialization extends the served head; a rotation's, and every carried\n * rekey, extends the epoch the batch mints above it.\n */\nasync function planRematerializationTarget(\n batch: BatchPlanning,\n target: RematerializationTarget,\n): Promise<void> {\n const { rematerialization } = batch;\n const rebased = rebaseOnDeepestAncestor(\n target.projection,\n batch.rotatedAbove,\n );\n const stale = rebased\n ? staleLevelsAbove(\n rebased.projection,\n rebased.ancestor.containerKeks.at(-1)?.containerId ?? \"\",\n )\n : [];\n for (const containerId of stale) {\n await carryLevel(\n batch,\n await loadServedProjection(rematerialization.apiClient, containerId),\n );\n }\n if (!target.grantRow) {\n await carryLevel(batch, target.projection);\n return;\n }\n // Each level carried above re-roots the target one step deeper.\n const previousProjection = await rerootOnAuthoredPaths(\n batch,\n target.projection,\n );\n const planned = await buildPrincipalContainerRematerializationPlan({\n grantRow: target.grantRow,\n knownContainerKeks: batch.knownContainerKeks,\n principalPolicyCache: batch.principalPolicyCache,\n projection: previousProjection,\n rematerialization,\n resolveProjectionUserKey: batch.resolveProjectionUserKey,\n });\n const nextProjection =\n \"keyring\" in planned.plan\n ? await containerWriterProjectionFromRotationPlan({\n plan: planned.plan,\n previousProjection,\n })\n : await containerWriterProjectionFromSharePlan({\n plan: planned.plan,\n previousProjection,\n });\n addPlan(batch, {\n carried: false,\n planned,\n rotated: \"keyring\" in planned.plan ? nextProjection : null,\n nextProjection,\n });\n}\n\n/**\n * Sign the batch parent-first. `carriedContainerIds` are the descendant rekeys\n * a refused attempt was told to carry; woven in by depth, each sits under the\n * rotation it rides, and a named container the batch rematerializes anyway is\n * re-planned there rather than rotated twice.\n */\nfunction buildPrincipalContainerRematerializationPlans(\n input: PrincipalContainerRematerializationInput,\n carriedContainerIds: readonly string[] = [],\n) {\n return planOnceMoreAfterRollback(\n input.apiClient,\n [...input.grants.map((grant) => grant.containerId), ...carriedContainerIds],\n () => planRematerializationBatch(input, carriedContainerIds),\n );\n}\n\nasync function planRematerializationBatch(\n input: PrincipalContainerRematerializationInput,\n carriedContainerIds: readonly string[],\n): Promise<{\n entries: PlannedRematerialization[];\n retiredContainerIds: readonly string[];\n preceding: PrincipalRematerializationPredecessor;\n}> {\n input = withPrecedingRematerialization(input);\n if (\n input.revokedContainerId &&\n !input.grants.some(\n (grant) => grant.containerId === input.revokedContainerId,\n )\n ) {\n throw new Error(\"Revoked container is not granted to the group\");\n }\n const { targets, retiredContainerIds } = await loadRematerializationTargets({\n apiClient: input.apiClient,\n carriedContainerIds,\n grants: input.grants,\n });\n const batch: BatchPlanning = {\n knownContainerKeks: new Map(input.preceding?.knownContainerKeks),\n plans: [],\n // A rotation planned above cites the group at the head this batch commits,\n // which no store holds yet; the cache is what lets a rebased path verify.\n principalPolicyCache: new Map([\n ...(input.preceding?.policies ?? []).flatMap((policy) => [\n ...seededPrincipalPolicyCache(policy),\n ]),\n ...seededPrincipalPolicyCache(input.nextPolicy),\n ]),\n rematerialization: input,\n resolveProjectionUserKey: createProjectionUserKeyResolver({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n }),\n rotatedAbove: [],\n authoredAbove: [],\n };\n for (const target of targets) {\n await planRematerializationTarget(batch, target);\n }\n return {\n entries: batch.plans,\n retiredContainerIds,\n preceding: {\n policies: [...(input.preceding?.policies ?? []), input.nextPolicy],\n projections: [\n ...(input.preceding?.projections ?? []),\n ...batch.plans.flatMap((entry) =>\n entry.nextProjection ? [entry.nextProjection] : [],\n ),\n ],\n knownContainerKeks: batch.knownContainerKeks,\n },\n };\n}\n\nexport async function preparePrincipalContainerRematerializationBatch(\n input: PrincipalContainerRematerializationInput,\n): Promise<PreparedPrincipalContainerRematerializationBatch> {\n let { entries, retiredContainerIds, preceding } =\n await buildPrincipalContainerRematerializationPlans(input);\n const requests = () => entries.map((entry) => entry.planned.plan.request);\n return {\n get preceding() {\n return preceding;\n },\n get retiredContainerIds() {\n return retiredContainerIds;\n },\n get plans() {\n return entries.map((entry) => entry.planned);\n },\n get requests() {\n return requests();\n },\n carry: async (requiredContainerIds) => {\n // The refused attempt rolled back whole, so every served head still\n // stands; the batch is signed again from them with the named levels in.\n const replanned = await buildPrincipalContainerRematerializationPlans(\n input,\n requiredContainerIds,\n );\n assertNamedContainersRotated(replanned.entries, requiredContainerIds);\n entries = replanned.entries;\n retiredContainerIds = replanned.retiredContainerIds;\n preceding = replanned.preceding;\n return requests();\n },\n acknowledge: async (responses, stillCurrent) => {\n const isCurrent = () =>\n input.stillCurrent?.() !== false && stillCurrent?.() !== false;\n const heads = entries.map((entry) => authoredMutationHead(entry.planned));\n const acknowledged = await acknowledgeContainerMutationBatch({\n execSql: input.execSql,\n plans: heads,\n responses,\n stillCurrent: isCurrent,\n });\n if (!acknowledged || !isCurrent()) return;\n const plansByOrganization = new Map<\n string,\n AuthoredContainerMutationHead[]\n >();\n for (const head of heads) {\n const organizationId = head.state.organizationId;\n const group = plansByOrganization.get(organizationId) ?? [];\n group.push(head);\n plansByOrganization.set(organizationId, group);\n }\n for (const [organizationId, organizationPlans] of plansByOrganization) {\n try {\n rememberVerifiedContainerHeads({\n organizationId,\n execSql: input.execSql,\n heads: [],\n policies: [input.nextPolicy],\n });\n } catch {\n // Cache failure must not invalidate the durably acknowledged batch.\n continue;\n }\n scheduleHeldDescendantRecitations({\n apiClient: input.apiClient,\n author: { ...input.author, organizationId },\n execSql: input.execSql,\n plans: organizationPlans,\n stillCurrent: input.recitationStillCurrent ?? isCurrent,\n reportSecurityIncident: input.reportSecurityIncident,\n });\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"principalContainerRematerialization.js","sourceRoot":"","sources":["principalContainerRematerialization.ts"],"names":[],"mappings":"AASA,OAAO,EACL,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEL,+BAA+B,GAChC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,+BAA+B,EAAE,MAAM,4DAA4D,CAAC;AAC7G,OAAO,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EACL,yCAAyC,EACzC,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,0CAA0C,EAAE,MAAM,wDAAwD,CAAC;AACpH,OAAO,EAAE,mCAAmC,EAAE,MAAM,qCAAqC,CAAC;AAC1F,OAAO,EAAE,8CAA8C,EAAE,MAAM,kDAAkD,CAAC;AAClH,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,EACL,OAAO,EACP,4BAA4B,EAE5B,UAAU,EAGV,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,EAIpB,0BAA0B,GAC3B,MAAM,8CAA8C,CAAC;AAEtD,SAAS,kBAAkB,CAAC,KAG3B;IACC,OAAO,CACL,KAAK,CAAC,YAAY,CAAC,IAAI,CACrB,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAA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C;YACpD,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;YAChC,OAAO,QAAQ,EAAE,CAAC;QACpB,CAAC;QACD,WAAW,EAAE,CAAC,SAAS,EAAE,YAAY,EAAE,EAAE,CACvC,8CAA8C,CAC5C,KAAK,EACL,OAAO,EACP,SAAS,EACT,YAAY,CACb;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ContainerDirectGrant,\n PrincipalContainerGrant,\n} from \"@tearleads/crypto\";\nimport type { ContainerMutationRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerMutationResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport {\n getTargetContainerContext,\n readContainerState,\n} from \"../../../data/containers/shared/projection\";\nimport {\n type PrincipalPolicyCache,\n verifyContainerWriterProjection,\n} from \"../../../data/keyingProjectionVerification\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { createProjectionUserKeyResolver } from \"../../../data/keyingProjectionVerification/userKeyResolver\";\nimport { buildMaterializedContainerRekeyPlan } from \"../child/rekey\";\nimport { rebaseOnDeepestAncestor } from \"../child/rekey/carriedDescendantRekeys\";\nimport {\n containerWriterProjectionFromRotationPlan,\n containerWriterProjectionFromSharePlan,\n isSpeculativeContainerWriterProjection,\n} from \"../child/rekey/rekeyProjection\";\nimport { buildMaterializedContainerRevokePlan } from \"../child/revoke\";\nimport { selectReplacementPrincipalPolicyReferences } from \"../child/rotation/replacementPrincipalPolicyReferences\";\nimport { buildMaterializedContainerSharePlan } from \"../child/share/shareMaterialization\";\nimport { acknowledgePrincipalContainerRematerialization } from \"./acknowledgePrincipalContainerRematerialization\";\nimport { withPrecedingRematerialization } from \"./precedingPrincipalRematerialization\";\nimport {\n addPlan,\n assertNamedContainersRotated,\n type BatchPlanning,\n carryLevel,\n type PrincipalContainerRematerializationInput,\n type PrincipalRematerializationPredecessor,\n planOnceMoreAfterRollback,\n rerootOnAuthoredPaths,\n staleLevelsAbove,\n} from \"./principalContainerRematerializationPlanning\";\nimport {\n loadRematerializationTargets,\n loadServedProjection,\n type MaterializedPrincipalContainerMutationPlan,\n type PlannedRematerialization,\n type RematerializationTarget,\n seededPrincipalPolicyCache,\n} from \"./principalContainerRematerializationTargets\";\n\nfunction matchingGroupGrant(input: {\n readonly directGrants: readonly ContainerDirectGrant[];\n readonly groupId: string;\n}): ContainerDirectGrant | null {\n return (\n input.directGrants.find(\n (grant) =>\n grant.subjectType === \"group\" && grant.subjectId === input.groupId,\n ) ?? null\n );\n}\n\nfunction referencedGroupKeyEpoch(input: {\n readonly groupId: string;\n readonly referencedPrincipalHeads: ReturnType<\n typeof readContainerState\n >[\"referencedPrincipalHeads\"];\n}): number | null {\n return (\n input.referencedPrincipalHeads.find(\n (head) =>\n head.principalType === \"group\" && head.principalId === input.groupId,\n )?.keyEpoch ?? null\n );\n}\n\nasync function loadGrantedContainerContext(\n input: PrincipalContainerRematerializationInput,\n grantRow: PrincipalContainerGrant,\n projection: ContainerWriterProjectionResponse,\n principalPolicyCache: PrincipalPolicyCache,\n) {\n // A projection re-rooted on a rotation this batch has yet to commit must\n // not pin anything: its heads are speculative until acknowledged, and a\n // pin past the group's served head would refuse the other served paths.\n await verifyContainerWriterProjection({\n execSql: input.execSql,\n persistVerificationCheckpoints:\n !isSpeculativeContainerWriterProjection(projection),\n principalPolicyCache,\n projection,\n resolveUserKey: createProjectionUserKeyResolver({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n }),\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n const state = readContainerState(\n getTargetContainerContext(projection).manifest,\n );\n const grant = matchingGroupGrant({\n directGrants: state.directGrants,\n groupId: input.groupId,\n });\n if (grant && grant.accessLevel !== grantRow.accessLevel) {\n const nextGrant = input.nextPolicy.grants.find(\n (candidate) => candidate.containerId === grantRow.containerId,\n );\n if (!nextGrant || nextGrant.accessLevel !== grantRow.accessLevel) {\n throw new Error(\n `Container ${grantRow.containerId} does not contain the expected group grant`,\n );\n }\n }\n const referencedKeyEpoch = referencedGroupKeyEpoch({\n groupId: input.groupId,\n referencedPrincipalHeads: state.referencedPrincipalHeads,\n });\n if (grant && referencedKeyEpoch === null) {\n throw new Error(\n `Container ${grantRow.containerId} is missing its group reference`,\n );\n }\n return { grant, projection, referencedKeyEpoch };\n}\n\nexport async function buildPrincipalContainerRematerializationBatch(\n input: PrincipalContainerRematerializationInput,\n): Promise<ContainerMutationRequest[]> {\n return (\n await buildPrincipalContainerRematerializationPlans(input)\n ).entries.map((entry) => entry.planned.plan.request);\n}\n\nexport interface PreparedPrincipalContainerRematerializationBatch {\n readonly preceding?: PrincipalRematerializationPredecessor | undefined;\n readonly retiredContainerIds: readonly string[];\n readonly acknowledge: (\n responses: readonly ContainerMutationResponse[],\n stillCurrent?: (() => boolean) | undefined,\n ) => Promise<void>;\n /**\n * Re-sign the batch with the descendant rekeys the server named for its\n * rotations woven in, parent-first, each against the path the batch will\n * leave behind. A named container the batch already rotates is re-planned\n * under what is carried above it, so no container rotates twice. Returns the\n * whole request list, which replaces `requests`; `acknowledge` then expects\n * the responses in that order.\n */\n readonly carry: (\n requiredContainerIds: readonly string[],\n ) => Promise<readonly ContainerMutationRequest[]>;\n readonly plans: readonly MaterializedPrincipalContainerMutationPlan[];\n readonly requests: readonly ContainerMutationRequest[];\n /** Rebuild a refused batch against fresh served container heads. */\n readonly refreshAfterConflict?:\n | (() => Promise<readonly ContainerMutationRequest[]>)\n | undefined;\n}\n\nasync function buildPrincipalContainerRematerializationPlan(input: {\n readonly grantRow: PrincipalContainerGrant;\n /** Keys the batch minted above this container; see `BatchPlanning`. */\n readonly knownContainerKeks: ReadonlyMap<string, Uint8Array>;\n /** Holds the policy this batch commits, which rebased paths already cite. */\n readonly principalPolicyCache: PrincipalPolicyCache;\n /** The served projection, re-rooted on any rotation planned above it. */\n readonly projection: ContainerWriterProjectionResponse;\n readonly rematerialization: PrincipalContainerRematerializationInput;\n readonly resolveProjectionUserKey: ReturnType<\n typeof createProjectionUserKeyResolver\n >;\n}): Promise<MaterializedPrincipalContainerMutationPlan> {\n const { grantRow } = input;\n const rematerialization = {\n ...input.rematerialization,\n nextPolicy: await selectReplacementPrincipalPolicyReferences({\n policy: input.rematerialization.nextPolicy,\n projection: input.projection,\n principalPolicyCache: input.principalPolicyCache,\n resolveAuthoredPolicyReferences:\n input.rematerialization.resolveAuthoredPolicyReferences,\n }),\n };\n const { grant, projection, referencedKeyEpoch } =\n await loadGrantedContainerContext(\n rematerialization,\n grantRow,\n input.projection,\n input.principalPolicyCache,\n );\n const nextGrant = rematerialization.nextPolicy.grants.find(\n (candidate) => candidate.containerId === grantRow.containerId,\n );\n const author = {\n ...rematerialization.author,\n organizationId: projection.organizationId,\n };\n const sharedInput = {\n author,\n execSql: rematerialization.execSql,\n knownContainerKeks: input.knownContainerKeks,\n // Planning against a path this batch has yet to commit pins nothing; the\n // acknowledgement advances every head at once. The rekey planner applies\n // this rule itself; revoke and grant planning take it from here.\n persistVerificationCheckpoints:\n !isSpeculativeContainerWriterProjection(projection),\n previousProjection: projection,\n principalPolicyCache: input.principalPolicyCache,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: rematerialization.stillCurrent,\n targetSecretKey: rematerialization.targetSecretKey,\n warmReferencedPrincipalPolicies:\n rematerialization.warmReferencedPrincipalPolicies,\n };\n if (grantRow.containerId === rematerialization.revokedContainerId) {\n if (!grant) {\n throw new Error(\n `Container ${grantRow.containerId} does not contain the revoked group grant`,\n );\n }\n return buildMaterializedContainerRevokePlan({\n ...sharedInput,\n replacementPrincipalPolicy: rematerialization.nextPolicy,\n revokedSubject: {\n subjectId: rematerialization.groupId,\n subjectType: \"group\",\n },\n });\n }\n if (!grant || grant.accessLevel !== nextGrant?.accessLevel) {\n if (!nextGrant) {\n throw new Error(\n `Container ${grantRow.containerId} is absent from the next group grant set`,\n );\n }\n return buildMaterializedContainerSharePlan({\n ...sharedInput,\n accessLevel: nextGrant.accessLevel,\n recipient: {\n principalPolicy: rematerialization.nextPolicy,\n subjectId: rematerialization.groupId,\n subjectType: \"group\",\n },\n });\n }\n if (referencedKeyEpoch === rematerialization.nextPolicy.keyEpoch) {\n return buildMaterializedContainerSharePlan({\n ...sharedInput,\n accessLevel: grant.accessLevel,\n recipient: {\n principalPolicy: rematerialization.nextPolicy,\n subjectId: rematerialization.groupId,\n subjectType: \"group\",\n },\n });\n }\n return buildMaterializedContainerRekeyPlan({\n ...sharedInput,\n replacementPrincipalPolicy: rematerialization.nextPolicy,\n });\n}\n\n/**\n * Plan one target against the paths already planned above it. A grant's\n * rematerialization extends the served head; a rotation's, and every carried\n * rekey, extends the epoch the batch mints above it.\n */\nasync function planRematerializationTarget(\n batch: BatchPlanning,\n target: RematerializationTarget,\n): Promise<void> {\n const { rematerialization } = batch;\n const rebased = rebaseOnDeepestAncestor(\n target.projection,\n batch.rotatedAbove,\n );\n const stale = rebased\n ? staleLevelsAbove(\n rebased.projection,\n rebased.ancestor.containerKeks.at(-1)?.containerId ?? \"\",\n )\n : [];\n for (const containerId of stale) {\n await carryLevel(\n batch,\n await loadServedProjection(rematerialization.apiClient, containerId),\n );\n }\n if (!target.grantRow) {\n await carryLevel(batch, target.projection);\n return;\n }\n // Each level carried above re-roots the target one step deeper.\n const previousProjection = await rerootOnAuthoredPaths(\n batch,\n target.projection,\n );\n const planned = await buildPrincipalContainerRematerializationPlan({\n grantRow: target.grantRow,\n knownContainerKeks: batch.knownContainerKeks,\n principalPolicyCache: batch.principalPolicyCache,\n projection: previousProjection,\n rematerialization,\n resolveProjectionUserKey: batch.resolveProjectionUserKey,\n });\n const nextProjection =\n \"keyring\" in planned.plan\n ? await containerWriterProjectionFromRotationPlan({\n plan: planned.plan,\n previousProjection,\n })\n : await containerWriterProjectionFromSharePlan({\n plan: planned.plan,\n previousProjection,\n });\n addPlan(batch, {\n carried: false,\n planned,\n rotated: \"keyring\" in planned.plan ? nextProjection : null,\n nextProjection,\n });\n}\n\n/**\n * Sign the batch parent-first. `carriedContainerIds` are the descendant rekeys\n * a refused attempt was told to carry; woven in by depth, each sits under the\n * rotation it rides, and a named container the batch rematerializes anyway is\n * re-planned there rather than rotated twice.\n */\nfunction buildPrincipalContainerRematerializationPlans(\n input: PrincipalContainerRematerializationInput,\n carriedContainerIds: readonly string[] = [],\n) {\n return planOnceMoreAfterRollback(\n input.apiClient,\n [...input.grants.map((grant) => grant.containerId), ...carriedContainerIds],\n () => planRematerializationBatch(input, carriedContainerIds),\n );\n}\n\nasync function planRematerializationBatch(\n input: PrincipalContainerRematerializationInput,\n carriedContainerIds: readonly string[],\n): Promise<{\n entries: PlannedRematerialization[];\n retiredContainerIds: readonly string[];\n preceding: PrincipalRematerializationPredecessor;\n}> {\n input = withPrecedingRematerialization(input);\n if (\n input.revokedContainerId &&\n !input.grants.some(\n (grant) => grant.containerId === input.revokedContainerId,\n )\n ) {\n throw new Error(\"Revoked container is not granted to the group\");\n }\n const { targets, retiredContainerIds } = await loadRematerializationTargets({\n apiClient: input.apiClient,\n carriedContainerIds,\n grants: input.grants,\n });\n const batch: BatchPlanning = {\n knownContainerKeks: new Map(input.preceding?.knownContainerKeks),\n plans: [],\n // A rotation planned above cites the group at the head this batch commits,\n // which no store holds yet; the cache is what lets a rebased path verify.\n principalPolicyCache: new Map([\n ...(input.preceding?.policies ?? []).flatMap((policy) => [\n ...seededPrincipalPolicyCache(policy),\n ]),\n ...seededPrincipalPolicyCache(input.nextPolicy),\n ]),\n rematerialization: input,\n resolveProjectionUserKey: createProjectionUserKeyResolver({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n }),\n rotatedAbove: [],\n authoredAbove: [],\n };\n for (const target of targets) {\n await planRematerializationTarget(batch, target);\n }\n return {\n entries: batch.plans,\n retiredContainerIds,\n preceding: {\n policies: [...(input.preceding?.policies ?? []), input.nextPolicy],\n projections: [\n ...(input.preceding?.projections ?? []),\n ...batch.plans.flatMap((entry) =>\n entry.nextProjection ? [entry.nextProjection] : [],\n ),\n ],\n knownContainerKeks: batch.knownContainerKeks,\n },\n };\n}\n\nexport async function preparePrincipalContainerRematerializationBatch(\n input: PrincipalContainerRematerializationInput,\n): Promise<PreparedPrincipalContainerRematerializationBatch> {\n let { entries, retiredContainerIds, preceding } =\n await buildPrincipalContainerRematerializationPlans(input);\n const requests = () => entries.map((entry) => entry.planned.plan.request);\n return {\n get preceding() {\n return preceding;\n },\n get retiredContainerIds() {\n return retiredContainerIds;\n },\n get plans() {\n return entries.map((entry) => entry.planned);\n },\n get requests() {\n return requests();\n },\n refreshAfterConflict: async () => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n for (const containerId of new Set([\n ...input.grants.map((grant) => grant.containerId),\n ...entries.map((entry) => entry.planned.plan.containerId),\n ])) {\n input.apiClient.evictContainerWriterProjection?.(containerId);\n }\n const replanned =\n await buildPrincipalContainerRematerializationPlans(input);\n entries = replanned.entries;\n retiredContainerIds = replanned.retiredContainerIds;\n preceding = replanned.preceding;\n return requests();\n },\n carry: async (requiredContainerIds) => {\n // The refused attempt rolled back whole, so every served head still\n // stands; the batch is signed again from them with the named levels in.\n const replanned = await buildPrincipalContainerRematerializationPlans(\n input,\n requiredContainerIds,\n );\n assertNamedContainersRotated(replanned.entries, requiredContainerIds);\n entries = replanned.entries;\n retiredContainerIds = replanned.retiredContainerIds;\n preceding = replanned.preceding;\n return requests();\n },\n acknowledge: (responses, stillCurrent) =>\n acknowledgePrincipalContainerRematerialization(\n input,\n entries,\n responses,\n stillCurrent,\n ),\n };\n}\n"]}
@@ -32,6 +32,9 @@ export async function commitCurrentGroupPolicyMutation(input) {
32
32
  // Refuse the whole transaction if a damaged-key repair needs extra rekeys;
33
33
  // ordinary adds preserve key epochs and need no descendant carry retry.
34
34
  carryDescendantRekeys: member ? undefined : prepared.carry,
35
+ refreshContainerMutations: member
36
+ ? undefined
37
+ : prepared.refreshAfterConflict,
35
38
  stillCurrent: context.stillCurrent,
36
39
  });
37
40
  if (!response)
@@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CACnE,CAAC;IACJ,IAAI,UAAU,GAAG,4BAA4B,CAAC;QAC5C,UAAU,EAAE,OAAO,CAAC,sBAAsB;QAC1C,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC;IACH,IAAI,UAAU;QACZ,UAAU,GAAG,4BAA4B,CAAC;YACxC,UAAU,EAAE,EAAE,GAAG,OAAO,CAAC,sBAAsB,EAAE,UAAU,EAAE;YAC7D,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;IACL,MAAM,eAAe,GAAG,OAAO,CAAC,yBAAyB;QACvD,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU;QAC1B,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC;IACnD,MAAM,UAAU,GAAG,MAAM,6BAA6B,CAAC;QACrD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;QAC5D,OAAO,EAAE,iBAAiB,CAAC,eAAe,CAAC;KAC5C,CAAC,CAAC;IACH,OAAO,4CAA4C,CAAC;QAClD,eAAe;QACf,UAAU;QACV,aAAa,EAAE,OAAO,CAAC,mBAAmB,CAAC,OAAO;QAClD,UAAU,EAAE,OAAO,CAAC,sBAAsB;QAC1C,UAAU;QACV,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n SigningKeyPair,\n VerifiedPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport type {\n PreparedPrincipalContainerRematerializationBatch,\n PrincipalRematerializationPredecessor,\n} from \"../../containers/rematerialization\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n replaceOrganizationGroupHead,\n} from \"../groups/organizationGroupDirectory\";\nimport { assertAuthoredPrincipalMutationReceipt } from \"../principalMutations/principalMutationReceipt\";\nimport type { RuntimeCurrentGroupMutationContext } from \"../principalMutations/runtimeCurrentGroupMutation\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"../trustedOrganizationUsers\";\nimport { prepareAuthoredGroupPolicy } from \"./groupPolicyMutationAcknowledgement\";\nimport {\n type PrincipalPolicyReadWriteApi,\n submitGroupPolicyCommit,\n} from \"./groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"./groupPolicyMutationHead\";\n\ninterface GroupPolicyChange {\n readonly context: RuntimeCurrentGroupMutationContext;\n readonly request: PutPrincipalPolicyRequest;\n readonly prepareContainerMutations: (\n nextPolicy: VerifiedPrincipalPolicyCurrent,\n preceding?: PrincipalRematerializationPredecessor | undefined,\n ) => Promise<PreparedPrincipalContainerRematerializationBatch>;\n}\n\ninterface CommitInput extends GroupPolicyChange {\n readonly member?: GroupPolicyChange | undefined;\n readonly apiClient: PrincipalPolicyReadWriteApi;\n readonly groupId: string;\n readonly organizationId: string;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\n/** Commit and retain the group, optional roster enrollment and directory together. */\nexport async function commitCurrentGroupPolicyMutation(\n input: CommitInput,\n): Promise<PrincipalPolicyMutationResponse> {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const [signer] = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: [input.signerUserId],\n });\n if (!signer) throw new Error(\"Group policy signer is unavailable\");\n const member = input.member\n ? await prepareChange(input.member, signer)\n : null;\n const { expectedHead, prepared } = await prepareChange(\n input,\n signer,\n member?.preceding,\n );\n const organizationRequest = await prepareDirectory(\n input,\n expectedHead,\n member?.expectedHead,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n const response = await submitGroupPolicyCommit({\n apiClient: input.apiClient,\n groupId: input.groupId,\n organizationId: input.organizationId,\n request: input.request,\n organizationRequest,\n memberRequest: input.member?.request,\n // A compound retry must rebuild both batches' shared speculative heads.\n // Refuse the whole transaction if a damaged-key repair needs extra rekeys;\n // ordinary adds preserve key epochs and need no descendant carry retry.\n carryDescendantRekeys: member ? undefined : prepared.carry,\n stillCurrent: context.stillCurrent,\n });\n if (!response) throw new Error(\"Group policy update failed\");\n assertProjectionVerificationCurrent(context.stillCurrent);\n await assertAuthoredPrincipalMutationReceipt(\n {\n groupPolicy: input.request,\n organizationPolicy: organizationRequest,\n ...(input.member ? { memberPolicy: input.member.request } : {}),\n },\n response,\n );\n await context.retainAcknowledged({\n additionalGroups:\n input.member && response.memberPolicy\n ? [\n {\n ...input.member.context.groupRetention,\n request: input.member.request,\n response: response.memberPolicy,\n retiredContainerIds: member?.prepared.retiredContainerIds,\n },\n ]\n : [],\n request: input.request,\n organizationRequest,\n response,\n retiredContainerIds: prepared.retiredContainerIds,\n });\n if (member && response.memberPolicy) {\n await member.prepared.acknowledge(\n response.memberPolicy.containerMutations,\n context.stillCurrent,\n );\n }\n await prepared.acknowledge(\n response.groupPolicy.containerMutations,\n context.stillCurrent,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n return response.groupPolicy;\n}\n\nasync function prepareChange(\n change: GroupPolicyChange,\n signer: Awaited<ReturnType<typeof resolveRequiredUserIdentities>>[number],\n preceding?: PrincipalRematerializationPredecessor,\n) {\n const expectedHead = await groupPolicyMutationHead(change.request);\n const nextPolicy = await prepareAuthoredGroupPolicy({\n verifiedCurrentPolicy: change.context.verifiedCurrentPolicy,\n expectedHead,\n request: change.request,\n signerPublicKeys: [signer],\n externalAuthority: change.context.externalAuthority,\n localPolicyCheckpoint: change.context.localPolicyCheckpoint,\n stillCurrent: change.context.stillCurrent,\n });\n const authored = [\n ...(preceding?.authored ?? []),\n {\n organizationId: change.context.organizationDescriptor.organizationId,\n policy: nextPolicy,\n dependencies: [\n change.context.organizationCurrent.policy,\n change.context.adminCurrent.policy,\n ],\n stillCurrent: change.context.stillCurrent,\n },\n ];\n // A level the batch plans under its own rotation cites this successor\n // before the transaction commits, so the batch resolves it as authored,\n // exactly as the next group in a compound transaction does (#2646).\n const prepared = await change.prepareContainerMutations(nextPolicy, {\n policies: preceding?.policies ?? [],\n projections: preceding?.projections ?? [],\n knownContainerKeks: preceding?.knownContainerKeks ?? new Map(),\n authored,\n });\n change.request.containerMutations = [...prepared.requests];\n return {\n expectedHead,\n prepared,\n preceding: prepared.preceding\n ? { ...prepared.preceding, authored }\n : undefined,\n };\n}\n\nasync function prepareDirectory(\n input: CommitInput,\n expectedHead: Awaited<ReturnType<typeof groupPolicyMutationHead>>,\n memberHead: Awaited<ReturnType<typeof groupPolicyMutationHead>> | undefined,\n) {\n const { context } = input;\n if (\n input.member &&\n (input.member.context.currentPolicy.currentState.principalId !==\n context.memberGroupId ||\n input.member.context.organizationCurrent.current.currentState\n .stateHash !==\n context.organizationCurrent.current.currentState.stateHash)\n )\n throw new Error(\n \"Roster and group changes must share the same organization policy\",\n );\n let groupHeads = replaceOrganizationGroupHead({\n descriptor: context.organizationDescriptor,\n nextHead: expectedHead,\n });\n if (memberHead)\n groupHeads = replaceOrganizationGroupHead({\n descriptor: { ...context.organizationDescriptor, groupHeads },\n nextHead: memberHead,\n });\n const adminProjection = context.isOrganizationAdminsGroup\n ? input.request.projection\n : context.adminCurrent.current.currentProjection;\n const adminUsers = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n });\n return buildOrganizationGroupDirectoryPolicyRequest({\n adminProjection,\n adminUsers,\n currentPolicy: context.organizationCurrent.current,\n descriptor: context.organizationDescriptor,\n groupHeads,\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n}\n"]}
1
+ {"version":3,"file":"commitCurrentGroupPolicyMutation.js","sourceRoot":"","sources":["commitCurrentGroupPolicyMutation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AAMvG,OAAO,EACL,4CAA4C,EAC5C,4BAA4B,GAC7B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,sCAAsC,EAAE,MAAM,gDAAgD,CAAC;AAExG,OAAO,EACL,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAEL,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAsBpE,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,KAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,6BAA6B,CAAC;QACnD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;QAC5D,OAAO,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC;KAC9B,CAAC,CAAC;IACH,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM;QACzB,CAAC,CAAC,MAAM,aAAa,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;QAC3C,CAAC,CAAC,IAAI,CAAC;IACT,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,MAAM,aAAa,CACpD,KAAK,EACL,MAAM,EACN,MAAM,EAAE,SAAS,CAClB,CAAC;IACF,MAAM,mBAAmB,GAAG,MAAM,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AS;gBACV,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC;QAE/D,MAAM,IAAI,KAAK,CACb,kEAAkE,CACnE,CAAC;IACJ,IAAI,UAAU,GAAG,4BAA4B,CAAC;QAC5C,UAAU,EAAE,OAAO,CAAC,sBAAsB;QAC1C,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC;IACH,IAAI,UAAU;QACZ,UAAU,GAAG,4BAA4B,CAAC;YACxC,UAAU,EAAE,EAAE,GAAG,OAAO,CAAC,sBAAsB,EAAE,UAAU,EAAE;YAC7D,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;IACL,MAAM,eAAe,GAAG,OAAO,CAAC,yBAAyB;QACvD,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU;QAC1B,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC;IACnD,MAAM,UAAU,GAAG,MAAM,6BAA6B,CAAC;QACrD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;QAC5D,OAAO,EAAE,iBAAiB,CAAC,eAAe,CAAC;KAC5C,CAAC,CAAC;IACH,OAAO,4CAA4C,CAAC;QAClD,eAAe;QACf,UAAU;QACV,aAAa,EAAE,OAAO,CAAC,mBAAmB,CAAC,OAAO;QAClD,UAAU,EAAE,OAAO,CAAC,sBAAsB;QAC1C,UAAU;QACV,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n SigningKeyPair,\n VerifiedPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport type {\n PreparedPrincipalContainerRematerializationBatch,\n PrincipalRematerializationPredecessor,\n} from \"../../containers/rematerialization\";\nimport {\n buildOrganizationGroupDirectoryPolicyRequest,\n replaceOrganizationGroupHead,\n} from \"../groups/organizationGroupDirectory\";\nimport { assertAuthoredPrincipalMutationReceipt } from \"../principalMutations/principalMutationReceipt\";\nimport type { RuntimeCurrentGroupMutationContext } from \"../principalMutations/runtimeCurrentGroupMutation\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"../trustedOrganizationUsers\";\nimport { prepareAuthoredGroupPolicy } from \"./groupPolicyMutationAcknowledgement\";\nimport {\n type PrincipalPolicyReadWriteApi,\n submitGroupPolicyCommit,\n} from \"./groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"./groupPolicyMutationHead\";\n\ninterface GroupPolicyChange {\n readonly context: RuntimeCurrentGroupMutationContext;\n readonly request: PutPrincipalPolicyRequest;\n readonly prepareContainerMutations: (\n nextPolicy: VerifiedPrincipalPolicyCurrent,\n preceding?: PrincipalRematerializationPredecessor | undefined,\n ) => Promise<PreparedPrincipalContainerRematerializationBatch>;\n}\n\ninterface CommitInput extends GroupPolicyChange {\n readonly member?: GroupPolicyChange | undefined;\n readonly apiClient: PrincipalPolicyReadWriteApi;\n readonly groupId: string;\n readonly organizationId: string;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\n/** Commit and retain the group, optional roster enrollment and directory together. */\nexport async function commitCurrentGroupPolicyMutation(\n input: CommitInput,\n): Promise<PrincipalPolicyMutationResponse> {\n const { context } = input;\n assertProjectionVerificationCurrent(context.stillCurrent);\n const [signer] = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: [input.signerUserId],\n });\n if (!signer) throw new Error(\"Group policy signer is unavailable\");\n const member = input.member\n ? await prepareChange(input.member, signer)\n : null;\n const { expectedHead, prepared } = await prepareChange(\n input,\n signer,\n member?.preceding,\n );\n const organizationRequest = await prepareDirectory(\n input,\n expectedHead,\n member?.expectedHead,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n const response = await submitGroupPolicyCommit({\n apiClient: input.apiClient,\n groupId: input.groupId,\n organizationId: input.organizationId,\n request: input.request,\n organizationRequest,\n memberRequest: input.member?.request,\n // A compound retry must rebuild both batches' shared speculative heads.\n // Refuse the whole transaction if a damaged-key repair needs extra rekeys;\n // ordinary adds preserve key epochs and need no descendant carry retry.\n carryDescendantRekeys: member ? undefined : prepared.carry,\n refreshContainerMutations: member\n ? undefined\n : prepared.refreshAfterConflict,\n stillCurrent: context.stillCurrent,\n });\n if (!response) throw new Error(\"Group policy update failed\");\n assertProjectionVerificationCurrent(context.stillCurrent);\n await assertAuthoredPrincipalMutationReceipt(\n {\n groupPolicy: input.request,\n organizationPolicy: organizationRequest,\n ...(input.member ? { memberPolicy: input.member.request } : {}),\n },\n response,\n );\n await context.retainAcknowledged({\n additionalGroups:\n input.member && response.memberPolicy\n ? [\n {\n ...input.member.context.groupRetention,\n request: input.member.request,\n response: response.memberPolicy,\n retiredContainerIds: member?.prepared.retiredContainerIds,\n },\n ]\n : [],\n request: input.request,\n organizationRequest,\n response,\n retiredContainerIds: prepared.retiredContainerIds,\n });\n if (member && response.memberPolicy) {\n await member.prepared.acknowledge(\n response.memberPolicy.containerMutations,\n context.stillCurrent,\n );\n }\n await prepared.acknowledge(\n response.groupPolicy.containerMutations,\n context.stillCurrent,\n );\n assertProjectionVerificationCurrent(context.stillCurrent);\n return response.groupPolicy;\n}\n\nasync function prepareChange(\n change: GroupPolicyChange,\n signer: Awaited<ReturnType<typeof resolveRequiredUserIdentities>>[number],\n preceding?: PrincipalRematerializationPredecessor,\n) {\n const expectedHead = await groupPolicyMutationHead(change.request);\n const nextPolicy = await prepareAuthoredGroupPolicy({\n verifiedCurrentPolicy: change.context.verifiedCurrentPolicy,\n expectedHead,\n request: change.request,\n signerPublicKeys: [signer],\n externalAuthority: change.context.externalAuthority,\n localPolicyCheckpoint: change.context.localPolicyCheckpoint,\n stillCurrent: change.context.stillCurrent,\n });\n const authored = [\n ...(preceding?.authored ?? []),\n {\n organizationId: change.context.organizationDescriptor.organizationId,\n policy: nextPolicy,\n dependencies: [\n change.context.organizationCurrent.policy,\n change.context.adminCurrent.policy,\n ],\n stillCurrent: change.context.stillCurrent,\n },\n ];\n // A level the batch plans under its own rotation cites this successor\n // before the transaction commits, so the batch resolves it as authored,\n // exactly as the next group in a compound transaction does (#2646).\n const prepared = await change.prepareContainerMutations(nextPolicy, {\n policies: preceding?.policies ?? [],\n projections: preceding?.projections ?? [],\n knownContainerKeks: preceding?.knownContainerKeks ?? new Map(),\n authored,\n });\n change.request.containerMutations = [...prepared.requests];\n return {\n expectedHead,\n prepared,\n preceding: prepared.preceding\n ? { ...prepared.preceding, authored }\n : undefined,\n };\n}\n\nasync function prepareDirectory(\n input: CommitInput,\n expectedHead: Awaited<ReturnType<typeof groupPolicyMutationHead>>,\n memberHead: Awaited<ReturnType<typeof groupPolicyMutationHead>> | undefined,\n) {\n const { context } = input;\n if (\n input.member &&\n (input.member.context.currentPolicy.currentState.principalId !==\n context.memberGroupId ||\n input.member.context.organizationCurrent.current.currentState\n .stateHash !==\n context.organizationCurrent.current.currentState.stateHash)\n )\n throw new Error(\n \"Roster and group changes must share the same organization policy\",\n );\n let groupHeads = replaceOrganizationGroupHead({\n descriptor: context.organizationDescriptor,\n nextHead: expectedHead,\n });\n if (memberHead)\n groupHeads = replaceOrganizationGroupHead({\n descriptor: { ...context.organizationDescriptor, groupHeads },\n nextHead: memberHead,\n });\n const adminProjection = context.isOrganizationAdminsGroup\n ? input.request.projection\n : context.adminCurrent.current.currentProjection;\n const adminUsers = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n });\n return buildOrganizationGroupDirectoryPolicyRequest({\n adminProjection,\n adminUsers,\n currentPolicy: context.organizationCurrent.current,\n descriptor: context.organizationDescriptor,\n groupHeads,\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n}\n"]}
@@ -1,22 +1,17 @@
1
1
  import type { ContainerMutationRequest, PutPrincipalPolicyRequest } from "../../../internal/validators/request/index.js";
2
2
  import { type CommitOrganizationGroupPolicyResponse } from "../../../internal/validators/response/index.js";
3
3
  import type { PrincipalPolicyReadWriteApi } from "../principalPolicy/principalPolicyApi.js";
4
- /**
5
- * Commit, answering one refusal: a rematerialized rekey or revoke that would
6
- * strand a level above a directly granted container is refused with the
7
- * descendant rekeys it must carry. The refused attempt rolled back whole, so
8
- * the served heads still stand; the batch is signed again with the named
9
- * levels woven in, replaces the container mutations, and the commit is retried
10
- * once. A second refusal means the tree moved underneath, and the caller's own
11
- * retry starts from a fresh policy.
12
- */
13
- export declare function submitGroupPolicyCommit(input: {
4
+ interface CommitInput {
14
5
  readonly apiClient: PrincipalPolicyReadWriteApi;
15
6
  readonly carryDescendantRekeys?: ((requiredContainerIds: readonly string[]) => Promise<readonly ContainerMutationRequest[]>) | undefined;
7
+ readonly refreshContainerMutations?: (() => Promise<readonly ContainerMutationRequest[]>) | undefined;
16
8
  readonly groupId: string;
17
9
  readonly organizationId: string;
18
10
  readonly organizationRequest: PutPrincipalPolicyRequest;
19
11
  readonly memberRequest?: PutPrincipalPolicyRequest | undefined;
20
12
  readonly request: PutPrincipalPolicyRequest;
21
13
  readonly stillCurrent?: (() => boolean) | undefined;
22
- }): Promise<CommitOrganizationGroupPolicyResponse | null>;
14
+ }
15
+ /** Answer one explicit transactional refusal, preserving uncertain outcomes. */
16
+ export declare function submitGroupPolicyCommit(input: CommitInput): Promise<CommitOrganizationGroupPolicyResponse | null>;
17
+ export {};
@@ -1,14 +1,8 @@
1
1
  import { CONTAINER_MUTATION_ERROR_CODES, } from "../../../internal/validators/response/index.js";
2
- /**
3
- * Commit, answering one refusal: a rematerialized rekey or revoke that would
4
- * strand a level above a directly granted container is refused with the
5
- * descendant rekeys it must carry. The refused attempt rolled back whole, so
6
- * the served heads still stand; the batch is signed again with the named
7
- * levels woven in, replaces the container mutations, and the commit is retried
8
- * once. A second refusal means the tree moved underneath, and the caller's own
9
- * retry starts from a fresh policy.
10
- */
2
+ /** Answer one explicit transactional refusal, preserving uncertain outcomes. */
11
3
  export async function submitGroupPolicyCommit(input) {
4
+ if (input.stillCurrent?.() === false)
5
+ return null;
12
6
  const body = () => ({
13
7
  groupPolicy: input.request,
14
8
  ...(input.memberRequest ? { memberPolicy: input.memberRequest } : {}),
@@ -18,54 +12,73 @@ export async function submitGroupPolicyCommit(input) {
18
12
  if (!commitOrganizationGroupPolicyResult) {
19
13
  return input.apiClient.commitOrganizationGroupPolicy(input.organizationId, input.groupId, body());
20
14
  }
21
- const first = await commitOrganizationGroupPolicyResult.call(input.apiClient, input.organizationId, input.groupId, body(), { reportErrors: false });
15
+ const submit = () => commitOrganizationGroupPolicyResult.call(input.apiClient, input.organizationId, input.groupId, body(), { reportErrors: false });
16
+ const first = await submit();
22
17
  if (first.ok)
23
18
  return first.data;
24
- if (first.kind === "cancelled")
19
+ if (!isRefused(first) || input.stillCurrent?.() === false)
25
20
  return null;
26
- if (first.kind === "outcome-unknown")
27
- throw new Error(first.message ??
28
- "Policy request may have committed; refresh before retrying");
29
- if (input.memberRequest &&
30
- first.code === CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired) {
31
- throw new Error("Repair the affected container keys before retrying enrollment; no memberships were changed");
32
- }
33
- if (!input.carryDescendantRekeys ||
34
- first.code !== CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired ||
35
- !first.requiredContainerIds?.length) {
36
- first.report?.();
21
+ if (!(await answerRefusal(input, first)))
37
22
  return null;
23
+ if (input.stillCurrent?.() === false)
24
+ return null;
25
+ const second = await submit();
26
+ if (second.ok)
27
+ return second.data;
28
+ if (isRefused(second) && input.stillCurrent?.() !== false)
29
+ second.report?.();
30
+ return null;
31
+ }
32
+ function isRefused(failure) {
33
+ if (failure.kind === "outcome-unknown")
34
+ throw new Error(failure.message ??
35
+ "Policy request may have committed; refresh before retrying");
36
+ return failure.kind !== "cancelled";
37
+ }
38
+ async function answerRefusal(input, failure) {
39
+ const retry = selectRetry(input, failure);
40
+ if (!retry) {
41
+ failure.report?.();
42
+ return false;
38
43
  }
39
- let carried;
40
44
  try {
41
- carried = await input.carryDescendantRekeys(first.requiredContainerIds);
45
+ const requests = await retry.prepare();
46
+ if (input.stillCurrent?.() === false)
47
+ return false;
48
+ if (retry.requireNonempty && requests.length === 0) {
49
+ failure.report?.();
50
+ return false;
51
+ }
52
+ input.request.containerMutations = [...requests];
53
+ return true;
42
54
  }
43
55
  catch (error) {
44
- // The refusal was answerable, and the answer failed: surface both. Once
45
- // the generation that owned the attempt is gone, only the failure is
46
- // surfaced; a superseded refusal is not an error.
47
56
  if (input.stillCurrent?.() !== false)
48
- first.report?.();
57
+ failure.report?.();
49
58
  throw error;
50
59
  }
51
- if (input.stillCurrent?.() === false)
52
- return null;
53
- // Nothing signed means the same refusal again; report the one already had.
54
- if (carried.length === 0) {
55
- first.report?.();
56
- return null;
57
- }
58
- input.request.containerMutations = [...carried];
59
- const second = await commitOrganizationGroupPolicyResult.call(input.apiClient, input.organizationId, input.groupId, body(), { reportErrors: false });
60
- if (!second.ok) {
61
- if (second.kind === "cancelled")
62
- return null;
63
- if (second.kind === "outcome-unknown")
64
- throw new Error(second.message ??
65
- "Policy request may have committed; refresh before retrying");
66
- second.report?.();
60
+ }
61
+ function selectRetry(input, failure) {
62
+ if (failure.status !== 409)
67
63
  return null;
64
+ if (failure.code === CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired) {
65
+ if (input.memberRequest)
66
+ throw new Error("Repair the affected container keys before retrying enrollment; no memberships were changed");
67
+ const { carryDescendantRekeys } = input;
68
+ const { requiredContainerIds } = failure;
69
+ return carryDescendantRekeys && requiredContainerIds?.length
70
+ ? {
71
+ prepare: () => carryDescendantRekeys(requiredContainerIds),
72
+ requireNonempty: true,
73
+ }
74
+ : null;
68
75
  }
69
- return second.data;
76
+ // A compound retry must rebuild both batches' shared speculative paths.
77
+ // Until it can do that, refuse atomically instead of reusing either batch.
78
+ if (!input.memberRequest &&
79
+ failure.code === CONTAINER_MUTATION_ERROR_CODES.stateStale &&
80
+ input.refreshContainerMutations)
81
+ return { prepare: input.refreshContainerMutations, requireNonempty: false };
82
+ return null;
70
83
  }
71
84
  //# sourceMappingURL=submitGroupPolicyCommit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"submitGroupPolicyCommit.js","sourceRoot":"","sources":["submitGroupPolicyCommit.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,8BAA8B,GAE/B,MAAM,gCAAgC,CAAC;AAGxC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,KAa7C;IACC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;QAClB,WAAW,EAAE,KAAK,CAAC,OAAO;QAC1B,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,kBAAkB,EAAE,KAAK,CAAC,mBAAmB;KAC9C,CAAC,CAAC;IACH,MAAM,EAAE,mCAAmC,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;IAChE,IAAI,CAAC,mCAAmC,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,SAAS,CAAC,6BAA6B,CAClD,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,IAAI,EAAE,CACP,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,mCAAmC,CAAC,IAAI,CAC1D,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,O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OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,kBAAkB,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,mCAAmC,CAAC,IAAI,CAC3D,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,IAAI,EAAE,EACN,EAAE,YAAY,EAAE,KAAK,EAAE,CACxB,CAAC;IACF,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,iBAAiB;YACnC,MAAM,IAAI,KAAK,CACb,MAAM,CAAC,OAAO;gBACZ,4DAA4D,CAC/D,CAAC;QACJ,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["import type {\n ContainerMutationRequest,\n PutPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport {\n CONTAINER_MUTATION_ERROR_CODES,\n type CommitOrganizationGroupPolicyResponse,\n} from \"@tearleads/validators/response\";\nimport type { PrincipalPolicyReadWriteApi } from \"../principalPolicy/principalPolicyApi\";\n\n/**\n * Commit, answering one refusal: a rematerialized rekey or revoke that would\n * strand a level above a directly granted container is refused with the\n * descendant rekeys it must carry. The refused attempt rolled back whole, so\n * the served heads still stand; the batch is signed again with the named\n * levels woven in, replaces the container mutations, and the commit is retried\n * once. A second refusal means the tree moved underneath, and the caller's own\n * retry starts from a fresh policy.\n */\nexport async function submitGroupPolicyCommit(input: {\n readonly apiClient: PrincipalPolicyReadWriteApi;\n readonly carryDescendantRekeys?:\n | ((\n requiredContainerIds: readonly string[],\n ) => Promise<readonly ContainerMutationRequest[]>)\n | undefined;\n readonly groupId: string;\n readonly organizationId: string;\n readonly organizationRequest: PutPrincipalPolicyRequest;\n readonly memberRequest?: PutPrincipalPolicyRequest | undefined;\n readonly request: PutPrincipalPolicyRequest;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<CommitOrganizationGroupPolicyResponse | null> {\n const body = () => ({\n groupPolicy: input.request,\n ...(input.memberRequest ? { memberPolicy: input.memberRequest } : {}),\n organizationPolicy: input.organizationRequest,\n });\n const { commitOrganizationGroupPolicyResult } = input.apiClient;\n if (!commitOrganizationGroupPolicyResult) {\n return input.apiClient.commitOrganizationGroupPolicy(\n input.organizationId,\n input.groupId,\n body(),\n );\n }\n const first = await commitOrganizationGroupPolicyResult.call(\n input.apiClient,\n input.organizationId,\n input.groupId,\n body(),\n { reportErrors: false },\n );\n if (first.ok) return first.data;\n if (first.kind === \"cancelled\") return null;\n if (first.kind === \"outcome-unknown\")\n throw new Error(\n first.message ??\n \"Policy request may have committed; refresh before retrying\",\n );\n if (\n input.memberRequest &&\n first.code === CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired\n ) {\n throw new Error(\n \"Repair the affected container keys before retrying enrollment; no memberships were changed\",\n );\n }\n if (\n !input.carryDescendantRekeys ||\n first.code !== CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired ||\n !first.requiredContainerIds?.length\n ) {\n first.report?.();\n return null;\n }\n let carried: readonly ContainerMutationRequest[];\n try {\n carried = await input.carryDescendantRekeys(first.requiredContainerIds);\n } catch (error) {\n // The refusal was answerable, and the answer failed: surface both. Once\n // the generation that owned the attempt is gone, only the failure is\n // surfaced; a superseded refusal is not an error.\n if (input.stillCurrent?.() !== false) first.report?.();\n throw error;\n }\n if (input.stillCurrent?.() === false) return null;\n // Nothing signed means the same refusal again; report the one already had.\n if (carried.length === 0) {\n first.report?.();\n return null;\n }\n input.request.containerMutations = [...carried];\n const second = await commitOrganizationGroupPolicyResult.call(\n input.apiClient,\n input.organizationId,\n input.groupId,\n body(),\n { reportErrors: false },\n );\n if (!second.ok) {\n if (second.kind === \"cancelled\") return null;\n if (second.kind === \"outcome-unknown\")\n throw new Error(\n second.message ??\n \"Policy request may have committed; refresh before retrying\",\n );\n second.report?.();\n return null;\n }\n return second.data;\n}\n"]}
1
+ {"version":3,"file":"submitGroupPolicyCommit.js","sourceRoot":"","sources":["submitGroupPolicyCommit.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,8BAA8B,GAE/B,MAAM,gCAAgC,CAAC;AA+BxC,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAkB;IAElB,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;QAClB,WAAW,EAAE,KAAK,CAAC,OAAO;QAC1B,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,kBAAkB,EAAE,KAAK,CAAC,mBAAmB;KAC9C,CAAC,CAAC;IACH,MAAM,EAAE,mCAAmC,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;IAChE,IAAI,CAAC,mCAAmC,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,SAAS,CAAC,6BAA6B,CAClD,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,IAAI,EAAE,CACP,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,GAAG,EAAE,CAClB,mCAAmC,CAAC,IAAI,CACtC,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,OAAO,EACb,IAAI,EAAE,EACN,EAAE,YAAY,EAAE,KAAK,EAAE,CACxB,CAAC;IACJ,MAAM,KAAK,GAAG,MAAM,MAAM,EAAE,CAAC;IAC7B,IAAI,KAAK,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC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rincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport {\n CONTAINER_MUTATION_ERROR_CODES,\n type CommitOrganizationGroupPolicyResponse,\n} from \"@tearleads/validators/response\";\nimport type { PrincipalPolicyReadWriteApi } from \"../principalPolicy/principalPolicyApi\";\n\ntype CommitFailure = Extract<\n Awaited<\n ReturnType<\n NonNullable<\n PrincipalPolicyReadWriteApi[\"commitOrganizationGroupPolicyResult\"]\n >\n >\n >,\n { ok: false }\n>;\ninterface CommitInput {\n readonly apiClient: PrincipalPolicyReadWriteApi;\n readonly carryDescendantRekeys?:\n | ((\n requiredContainerIds: readonly string[],\n ) => Promise<readonly ContainerMutationRequest[]>)\n | undefined;\n readonly refreshContainerMutations?:\n | (() => Promise<readonly ContainerMutationRequest[]>)\n | undefined;\n readonly groupId: string;\n readonly organizationId: string;\n readonly organizationRequest: PutPrincipalPolicyRequest;\n readonly memberRequest?: PutPrincipalPolicyRequest | undefined;\n readonly request: PutPrincipalPolicyRequest;\n readonly stillCurrent?: (() => boolean) | undefined;\n}\n\n/** Answer one explicit transactional refusal, preserving uncertain outcomes. */\nexport async function submitGroupPolicyCommit(\n input: CommitInput,\n): Promise<CommitOrganizationGroupPolicyResponse | null> {\n if (input.stillCurrent?.() === false) return null;\n const body = () => ({\n groupPolicy: input.request,\n ...(input.memberRequest ? { memberPolicy: input.memberRequest } : {}),\n organizationPolicy: input.organizationRequest,\n });\n const { commitOrganizationGroupPolicyResult } = input.apiClient;\n if (!commitOrganizationGroupPolicyResult) {\n return input.apiClient.commitOrganizationGroupPolicy(\n input.organizationId,\n input.groupId,\n body(),\n );\n }\n const submit = () =>\n commitOrganizationGroupPolicyResult.call(\n input.apiClient,\n input.organizationId,\n input.groupId,\n body(),\n { reportErrors: false },\n );\n const first = await submit();\n if (first.ok) return first.data;\n if (!isRefused(first) || input.stillCurrent?.() === false) return null;\n if (!(await answerRefusal(input, first))) return null;\n if (input.stillCurrent?.() === false) return null;\n const second = await submit();\n if (second.ok) return second.data;\n if (isRefused(second) && input.stillCurrent?.() !== false) second.report?.();\n return null;\n}\n\nfunction isRefused(failure: CommitFailure): boolean {\n if (failure.kind === \"outcome-unknown\")\n throw new Error(\n failure.message ??\n \"Policy request may have committed; refresh before retrying\",\n );\n return failure.kind !== \"cancelled\";\n}\n\nasync function answerRefusal(\n input: CommitInput,\n failure: CommitFailure,\n): Promise<boolean> {\n const retry = selectRetry(input, failure);\n if (!retry) {\n failure.report?.();\n return false;\n }\n try {\n const requests = await retry.prepare();\n if (input.stillCurrent?.() === false) return false;\n if (retry.requireNonempty && requests.length === 0) {\n failure.report?.();\n return false;\n }\n input.request.containerMutations = [...requests];\n return true;\n } catch (error) {\n if (input.stillCurrent?.() !== false) failure.report?.();\n throw error;\n }\n}\n\nfunction selectRetry(input: CommitInput, failure: CommitFailure) {\n if (failure.status !== 409) return null;\n if (\n failure.code === CONTAINER_MUTATION_ERROR_CODES.descendantRekeysRequired\n ) {\n if (input.memberRequest)\n throw new Error(\n \"Repair the affected container keys before retrying enrollment; no memberships were changed\",\n );\n const { carryDescendantRekeys } = input;\n const { requiredContainerIds } = failure;\n return carryDescendantRekeys && requiredContainerIds?.length\n ? {\n prepare: () => carryDescendantRekeys(requiredContainerIds),\n requireNonempty: true,\n }\n : null;\n }\n // A compound retry must rebuild both batches' shared speculative paths.\n // Until it can do that, refuse atomically instead of reusing either batch.\n if (\n !input.memberRequest &&\n failure.code === CONTAINER_MUTATION_ERROR_CODES.stateStale &&\n input.refreshContainerMutations\n )\n return { prepare: input.refreshContainerMutations, requireNonempty: false };\n return null;\n}\n"]}