@fantastic.dev/better-stripe 0.97.1 → 0.99.0

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 (111) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +11 -0
  4. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +39 -1
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts +22 -0
  8. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js +13 -5
  10. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts +17 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js +140 -0
  14. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +61 -9
  16. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +41 -411
  18. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts +21 -0
  20. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js +36 -0
  22. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js.map +1 -0
  23. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +141 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +132 -182
  26. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
  27. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +1 -0
  28. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -1
  29. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +17 -5
  30. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -1
  31. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts +35 -0
  32. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js +46 -0
  34. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts +63 -0
  36. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js +380 -0
  38. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js.map +1 -0
  39. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +8 -0
  40. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
  41. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +25 -0
  42. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
  43. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +56 -0
  44. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts.map +1 -0
  45. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js +49 -0
  46. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js.map +1 -0
  47. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
  48. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
  49. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +3 -0
  50. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
  51. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +65 -0
  52. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -0
  53. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +162 -0
  54. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
  55. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts +4 -0
  56. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -0
  57. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +87 -0
  58. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -0
  59. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts +368 -0
  60. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts.map +1 -0
  61. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js +106 -0
  62. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js.map +1 -0
  63. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +4 -0
  64. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -1
  65. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +24 -3
  66. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -1
  67. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +1 -0
  68. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -1
  69. package/dist/client/billing/renewalAttach/internal/recovery/output.js +22 -8
  70. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -1
  71. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +1 -0
  72. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -1
  73. package/dist/client/billing/renewalAttach/internal/recovery/record.js +10 -2
  74. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -1
  75. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +3 -0
  76. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
  77. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +69 -156
  78. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
  79. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +18 -0
  80. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -1
  81. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +15 -1
  82. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -1
  83. package/docs/renewal-context-reads.md +69 -8
  84. package/package.json +1 -1
  85. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +45 -3
  86. package/src/client/billing/renewalAttach/internal/c10/attachEvents.ts +17 -5
  87. package/src/client/billing/renewalAttach/internal/operations/actorFailureControl.ts +165 -0
  88. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +48 -535
  89. package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
  90. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +168 -209
  91. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +23 -5
  92. package/src/client/billing/renewalAttach/internal/operations/transportCapture.ts +60 -0
  93. package/src/client/billing/renewalAttach/internal/operations/transportKernel.ts +500 -0
  94. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +28 -0
  95. package/src/client/billing/renewalAttach/internal/producer/journalWorkFactory.ts +54 -0
  96. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
  97. package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +176 -0
  98. package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts +240 -0
  99. package/src/client/billing/renewalAttach/internal/producer/producerActor.integration.test.ts +526 -0
  100. package/src/client/billing/renewalAttach/internal/producer/producerRecovery.integration.test.ts +394 -0
  101. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryControls.integration.test.ts +437 -0
  102. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryIsolation.integration.test.ts +332 -0
  103. package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
  104. package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +109 -0
  105. package/src/client/billing/renewalAttach/internal/producer/recoveryFactory.ts +135 -0
  106. package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
  107. package/src/client/billing/renewalAttach/internal/recovery/output.ts +34 -8
  108. package/src/client/billing/renewalAttach/internal/recovery/record.ts +16 -2
  109. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +107 -188
  110. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +17 -1
  111. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +82 -11
@@ -3,21 +3,45 @@ import { readInitialLineage } from "./lineageAuthority.js";
3
3
  import { ownerForInitialLineage } from "./ownerFactory.js";
4
4
  import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
5
5
 
6
+ function stockCall(token: object) {
7
+ const lineage = readInitialLineage(token);
8
+ const owner = ownerForInitialLineage(token);
9
+ return Object.freeze({
10
+ owner,
11
+ call(args: Parameters<Stripe["rawRequest"]>) {
12
+ return Reflect.apply(lineage.method, lineage.client, args) as ReturnType<
13
+ Stripe["rawRequest"]
14
+ >;
15
+ },
16
+ });
17
+ }
18
+
19
+ /** Transport kernels keep the original SDK promise and guard their continuation. */
20
+ export function captureInitialStockRawDelegate(
21
+ token: object,
22
+ ): Readonly<{ rawRequest: Stripe["rawRequest"] }> {
23
+ if (arguments.length !== 1) throw Error("INITIAL_OPERATION_UNBOUND");
24
+ const binding = stockCall(token);
25
+ return Object.freeze({
26
+ rawRequest(...args: Parameters<Stripe["rawRequest"]>) {
27
+ binding.owner.check();
28
+ return binding.call(args);
29
+ },
30
+ });
31
+ }
32
+
6
33
  /** Fixed selected client and original receiver; no replacement-client parameter. */
7
34
  export function stockDelegateForInitialLineage(token: object): Readonly<{
8
35
  rawRequest: Stripe["rawRequest"];
9
36
  }> {
10
- const lineage = readInitialLineage(token);
11
- const owner = ownerForInitialLineage(token);
37
+ const { owner, call } = stockCall(token);
12
38
  const owned = ownedAwaitForInitialLineage(token);
13
39
  return Object.freeze({
14
40
  rawRequest(
15
41
  ...args: Parameters<Stripe["rawRequest"]>
16
42
  ): ReturnType<Stripe["rawRequest"]> {
17
43
  owner.check();
18
- return owned(() =>
19
- Reflect.apply(lineage.method, lineage.client, args),
20
- ) as ReturnType<Stripe["rawRequest"]>;
44
+ return owned(() => call(args)) as ReturnType<Stripe["rawRequest"]>;
21
45
  },
22
46
  });
23
47
  }
@@ -1,4 +1,5 @@
1
1
  import { types } from "node:util";
2
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
2
3
  import { requiredJSONSnapshot } from "../material/requiredJson.js";
3
4
  import {
4
5
  objectNode,
@@ -25,16 +26,41 @@ export function admitRecoveryOutput(
25
26
  observed: unknown,
26
27
  prepared: Prepared,
27
28
  request: AttachRequest,
29
+ ) {
30
+ return admitOutput(receipt, observed, prepared, request, false);
31
+ }
32
+ export function admitRecoveryOutputForLineage(
33
+ token: object,
34
+ receipt: Receipt,
35
+ observed: unknown,
36
+ prepared: Prepared,
37
+ request: AttachRequest,
38
+ ) {
39
+ need(arguments.length === 5);
40
+ const owner = ownerForInitialLineage(token);
41
+ owner.check();
42
+ const result = admitOutput(receipt, observed, prepared, request, true);
43
+ owner.check();
44
+ return result;
45
+ }
46
+ function admitOutput(
47
+ receipt: Receipt,
48
+ observed: unknown,
49
+ prepared: Prepared,
50
+ request: AttachRequest,
51
+ allowNull: boolean,
28
52
  ) {
29
53
  need(!types.isProxy(observed));
30
54
  const observedID =
31
- typeof observed === "string"
32
- ? observed
33
- : (() => {
34
- need(observed !== null && typeof observed === "object");
35
- return Object.getOwnPropertyDescriptor(observed, "id")
36
- ?.value as unknown;
37
- })();
55
+ allowNull && observed === null
56
+ ? null
57
+ : typeof observed === "string"
58
+ ? observed
59
+ : (() => {
60
+ need(observed !== null && typeof observed === "object");
61
+ return Object.getOwnPropertyDescriptor(observed, "id")
62
+ ?.value as unknown;
63
+ })();
38
64
  const output = {
39
65
  kind: "EXPLICIT_ATTACH_RECOVERY_V2_DATA_ONLY",
40
66
  status: "attach_acknowledged",
@@ -42,7 +68,7 @@ export function admitRecoveryOutput(
42
68
  receipt,
43
69
  observation: {
44
70
  schedule: observed,
45
- conflict: observedID !== receipt.scheduleId,
71
+ conflict: observedID !== null && observedID !== receipt.scheduleId,
46
72
  authority: "unowned_prepost_observation_only",
47
73
  },
48
74
  };
@@ -1,5 +1,6 @@
1
1
  import { types } from "node:util";
2
2
  import { OWNER } from "../originalOwner.js";
3
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
3
4
  import { requiredJSONSnapshot } from "../material/requiredJson.js";
4
5
  import {
5
6
  closed,
@@ -78,7 +79,20 @@ export type CapturedRecord = Readonly<{
78
79
 
79
80
  /** Detached unverified data only. The actor retains and proves its own record. */
80
81
  export function captureRecoveryRecord(live: unknown): CapturedRecord {
81
- OWNER.check();
82
+ return captureRecord(live, OWNER);
83
+ }
84
+ export function captureRecoveryRecordForLineage(
85
+ token: object,
86
+ live: unknown,
87
+ ): CapturedRecord {
88
+ need(arguments.length === 2);
89
+ return captureRecord(live, ownerForInitialLineage(token));
90
+ }
91
+ function captureRecord(
92
+ live: unknown,
93
+ owner: { check(): unknown },
94
+ ): CapturedRecord {
95
+ owner.check();
82
96
  const slots = new Map<string, string>(),
83
97
  active = new Set<object>();
84
98
  let nodes = 0,
@@ -189,7 +203,7 @@ export function captureRecoveryRecord(live: unknown): CapturedRecord {
189
203
  const node = walk(live, "", 0);
190
204
  need(slots.size === 6 && rawNode);
191
205
  encode(node);
192
- OWNER.check();
206
+ owner.check();
193
207
  return Object.freeze({
194
208
  node,
195
209
  slots,
@@ -1,6 +1,16 @@
1
1
  import { sevenWire } from "../c10/ownData.js";
2
2
  import { types } from "node:util";
3
- import { OWNER } from "../originalOwner.js";
3
+ import { OWNER as LEGACY_OWNER } from "../originalOwner.js";
4
+ import { readInitialLineage } from "../producer/lineageAuthority.js";
5
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
6
+ import { ownedForInitialLineage } from "../operations/ownedAwait.js";
7
+ import { createInitialMaterialClassifiers } from "../material/classifiers.js";
8
+ import {
9
+ recoveryOperationForLineage,
10
+ assertReplayFrontierForLineage,
11
+ } from "../producer/recoveryFactory.js";
12
+ import { createRecoveryAttachEventCompiler } from "../c10/attachEvents.js";
13
+ import { retainInitialReceiptForLineage } from "../producer/operationFactory.js";
4
14
  import {
5
15
  prepareRenewalPriceReplacementV2 as c1,
6
16
  prepareRenewalScheduleAttachmentV2 as c2,
@@ -14,13 +24,12 @@ import {
14
24
  import { validateOwnedReadMaterial } from "../material/readMaterial.js";
15
25
  import {
16
26
  closed,
17
- type AttachRequest,
18
27
  type SourceMethod,
19
28
  type FailureControl,
20
29
  } from "../operations/types.js";
21
30
  import { equal } from "../../../renewalAggregate/shared.js";
22
- import { owned } from "../operations/ownedAwait.js";
23
- import type { Diagnostics } from "../operations/providerFailure.js";
31
+ import { owned as legacyOwned } from "../operations/ownedAwait.js";
32
+ import { captureActorFailureControl } from "../operations/actorFailureControl.js";
24
33
  import { bindRawAcquisitionFromSource } from "../acquisition/ownedAcquisition.js";
25
34
  import { createAttachEventCompiler } from "../c10/attachEvents.js";
26
35
  import {
@@ -29,9 +38,19 @@ import {
29
38
  ORIGINAL_ORIGIN_ASSOCIATION,
30
39
  } from "../operations/sourceOperations.js";
31
40
  import { createRecoveryOwnedTransportWithAttemptCapability as createPair } from "../operations/fixedTransport.js";
32
- import { captureRecoveryRecord, verifyRecoveryRecord } from "./record.js";
33
- import { replayCouponEligibility } from "./relation.js";
34
- import { admitRecoveryOutput } from "./output.js";
41
+ import {
42
+ captureRecoveryRecord,
43
+ captureRecoveryRecordForLineage,
44
+ verifyRecoveryRecord,
45
+ } from "./record.js";
46
+ import {
47
+ replayCouponEligibility,
48
+ replayCouponEligibilityForLineage,
49
+ } from "./relation.js";
50
+ import {
51
+ admitRecoveryOutput,
52
+ admitRecoveryOutputForLineage,
53
+ } from "./output.js";
35
54
  import { admitReplayMaterial, assertReplayMaterial } from "./material.js";
36
55
 
37
56
  type Pair = ReturnType<typeof createPair>;
@@ -66,6 +85,14 @@ const refuse = (reason: string) =>
66
85
  /** Explicit recovery retains one record and class relation; it never replaces the initial pair. */
67
86
  export function captureOwnedExplicitAttachRecoveryV2() {
68
87
  need(arguments.length === 0);
88
+ return recoveryKernel(null);
89
+ }
90
+ export function captureExplicitAttachRecoveryForLineage(token: object) {
91
+ need(arguments.length === 1);
92
+ readInitialLineage(token);
93
+ return recoveryKernel(token);
94
+ }
95
+ function recoveryKernel(token: object | null) {
69
96
  let consumed = false;
70
97
  return Object.freeze({
71
98
  async invoke() {
@@ -74,6 +101,15 @@ export function captureOwnedExplicitAttachRecoveryV2() {
74
101
  consumed = true;
75
102
  need(!types.isProxy(ENTRIES) && Array.isArray(ENTRIES));
76
103
  if (ENTRIES.length === 0) return refuse("no_qualified_recovery_class");
104
+ const OWNER =
105
+ token === null ? LEGACY_OWNER : ownerForInitialLineage(token);
106
+ const owned =
107
+ token === null ? legacyOwned : ownedForInitialLineage(token);
108
+ const classifyRetained =
109
+ token === null
110
+ ? classifyOwnedRetainedInitialAttachment
111
+ : (_raw: unknown) =>
112
+ createInitialMaterialClassifiers(token).retained();
77
113
  let pair: Pair | null = null,
78
114
  failureControl: FailureControl | null = null,
79
115
  postEligible = false;
@@ -92,7 +128,14 @@ export function captureOwnedExplicitAttachRecoveryV2() {
92
128
  };
93
129
  try {
94
130
  OWNER.check();
95
- const live = loadFixedExplicitRecoveryOperation();
131
+ const frame =
132
+ token === null
133
+ ? null
134
+ : await owned(() => recoveryOperationForLineage(token));
135
+ const live =
136
+ token === null
137
+ ? loadFixedExplicitRecoveryOperation()
138
+ : frame?.operation;
96
139
  OWNER.check();
97
140
  if (live === null) return refuse("recovery_source_unbound");
98
141
  const op = closed(live, [
@@ -110,7 +153,10 @@ export function captureOwnedExplicitAttachRecoveryV2() {
110
153
  op.originAssociation !== null &&
111
154
  typeof op.originAssociation === "object" &&
112
155
  !types.isProxy(op.originAssociation) &&
113
- op.originAssociation === ORIGINAL_ORIGIN_ASSOCIATION,
156
+ op.originAssociation ===
157
+ (token === null
158
+ ? ORIGINAL_ORIGIN_ASSOCIATION
159
+ : readInitialLineage(token).originAssociation),
114
160
  );
115
161
  const reserve = sourceMethod(live, "reserve"),
116
162
  retainedPredicate = sourceMethod(op.originalEntry, "coversRetained");
@@ -140,7 +186,10 @@ export function captureOwnedExplicitAttachRecoveryV2() {
140
186
  !types.isProxy(reservation),
141
187
  );
142
188
  // The cached record, reconstructed values and replay classifier remain invocation-local.
143
- const capturedRecord = captureRecoveryRecord(op.originalRecord);
189
+ const capturedRecord =
190
+ token === null
191
+ ? captureRecoveryRecord(op.originalRecord)
192
+ : captureRecoveryRecordForLineage(token, op.originalRecord);
144
193
  OWNER.check();
145
194
  const original = captureRetainedInput(capturedRecord.originalRaw),
146
195
  raw = original.attachRequest;
@@ -156,9 +205,7 @@ export function captureOwnedExplicitAttachRecoveryV2() {
156
205
  }),
157
206
  );
158
207
  OWNER.check();
159
- const retained = await owned(() =>
160
- classifyOwnedRetainedInitialAttachment(original),
161
- );
208
+ const retained = await owned(() => classifyRetained(original));
162
209
  OWNER.check();
163
210
  if (retained.status !== "classified")
164
211
  return refuse("replay_material_unsupported");
@@ -178,7 +225,8 @@ export function captureOwnedExplicitAttachRecoveryV2() {
178
225
  OWNER.check();
179
226
  if (coveredRetained !== true) return refuse("replay_coverage_missing");
180
227
  OWNER.check();
181
- pair = createPair();
228
+ pair = token === null ? createPair() : (frame?.pair ?? null);
229
+ need(pair);
182
230
  OWNER.check();
183
231
  need(
184
232
  pair.capability.assertSourceOperationBinding(
@@ -192,169 +240,21 @@ export function captureOwnedExplicitAttachRecoveryV2() {
192
240
  const activePair = pair;
193
241
 
194
242
  // Only this invocation's pair and actual locally rebuilt C2 enter this capsule.
195
- const control = (() => {
196
- const capability = activePair.capability,
197
- takeQuarantine = capability.takeFulfilledQuarantine;
198
- Object.freeze(request.payload);
199
- Object.freeze(request.requestIdentity);
200
- Object.freeze(request);
201
- OWNER.check();
202
- type Token = {
203
- invocation: object;
204
- phase: "read" | "post";
205
- ordinal: number;
206
- request: AttachRequest;
207
- diagnostics: Diagnostics;
208
- };
209
- const tokens = new WeakMap<object, Token>(),
210
- invocation = Object.freeze({});
211
- let phase = "unused";
212
- const tokenValue = (error: unknown) =>
213
- error !== null &&
214
- (typeof error === "object" || typeof error === "function")
215
- ? tokens.get(error)
216
- : undefined;
217
- function consume(error: unknown, kind: "read" | "post") {
218
- OWNER.check();
219
- const value = tokenValue(error);
220
- if (
221
- error !== null &&
222
- (typeof error === "object" || typeof error === "function")
223
- )
224
- tokens.delete(error);
225
- if (
226
- !value ||
227
- value.invocation !== invocation ||
228
- value.phase !== kind ||
229
- phase !== (kind === "read" ? "failed" : "failed_post")
230
- )
231
- return null;
232
- phase = kind === "read" ? "consumed" : "consumed_post";
233
- const failure = Object.freeze({
234
- category: "provider_rejected",
235
- phase: kind,
236
- ordinal: value.ordinal,
237
- request: value.request,
238
- diagnostics: value.diagnostics,
239
- outcome: "unknown",
240
- operationalAuthority: false,
241
- });
242
- const out = Error("INITIAL_PROVIDER_REJECTED");
243
- Object.defineProperty(out, "failure", {
244
- value: failure,
245
- enumerable: false,
246
- writable: false,
247
- configurable: false,
248
- });
249
- return out;
250
- }
251
- return Object.freeze({
252
- takePostQuarantine(...args: unknown[]) {
253
- if (args.length !== 0) return null;
254
- return Reflect.apply(takeQuarantine, capability, []) as
255
- object | null;
256
- },
257
- begin() {
258
- OWNER.check();
259
- if (phase !== "unused") stop();
260
- if (capability.assertVirginAcquisition() !== true) {
261
- phase = "closed";
262
- stop();
263
- }
264
- OWNER.check();
265
- phase = "acquiring";
266
- },
267
- complete() {
268
- OWNER.check();
269
- if (phase !== "acquiring") stop();
270
- phase = "complete";
271
- },
272
- takeReadFailure() {
273
- OWNER.check();
274
- if (phase !== "acquiring") stop();
275
- const record = capability.consumeReadCatch();
276
- OWNER.check();
277
- if (record === null) {
278
- phase = "unsupported";
279
- return null;
280
- }
281
- need(
282
- record.phase === "read" &&
283
- Number.isSafeInteger(record.ordinal) &&
284
- record.ordinal >= 1 &&
285
- record.ordinal <= 43,
286
- );
287
- const token = Object.freeze(Object.create(null)) as object;
288
- tokens.set(
289
- token,
290
- Object.freeze({
291
- invocation,
292
- phase: "read",
293
- ordinal: record.ordinal,
294
- request,
295
- diagnostics: record.diagnostics,
296
- }),
297
- );
298
- phase = "failed";
299
- return token;
300
- },
301
- beginPost() {
302
- OWNER.check();
303
- if (phase !== "complete") stop();
304
- phase = "posting";
305
- },
306
- takePostFailure(actualReply: unknown) {
307
- OWNER.check();
308
- if (phase !== "posting") stop();
309
- const record = capability.consumePostCatch(actualReply);
310
- OWNER.check();
311
- if (record === null) {
312
- phase = "post_without_token";
313
- return null;
314
- }
315
- need(
316
- record.phase === "post" &&
317
- Number.isSafeInteger(record.ordinal) &&
318
- record.ordinal >= 1 &&
319
- record.ordinal <= 44,
320
- );
321
- const token = Object.freeze(Object.create(null)) as object;
322
- tokens.set(
323
- token,
324
- Object.freeze({
325
- invocation,
326
- phase: "post",
327
- ordinal: record.ordinal,
328
- request,
329
- diagnostics: record.diagnostics,
330
- }),
331
- );
332
- phase = "failed_post";
333
- return token;
334
- },
335
- forward(error: unknown) {
336
- OWNER.check();
337
- const value = tokenValue(error);
338
- return value &&
339
- value.invocation === invocation &&
340
- (phase === "failed" || phase === "failed_post")
341
- ? (error as object)
342
- : null;
343
- },
344
- consume(error: unknown) {
345
- return consume(error, "read");
346
- },
347
- consumePost(error: unknown) {
348
- return consume(error, "post");
349
- },
350
- });
351
- })();
243
+ const control = captureActorFailureControl(OWNER, activePair, request);
352
244
  OWNER.check();
353
245
  failureControl = control;
354
- const reader = bindRawAcquisitionFromSource(
355
- OWNER,
356
- activePair.transport.readTransport,
357
- );
246
+ const reader =
247
+ token === null
248
+ ? bindRawAcquisitionFromSource(
249
+ OWNER,
250
+ activePair.transport.readTransport,
251
+ )
252
+ : {
253
+ async acquire(_expected: unknown) {
254
+ need(frame?.reader);
255
+ return frame.reader.acquire();
256
+ },
257
+ };
358
258
  OWNER.check();
359
259
  let acquiredOnce = false;
360
260
  const acquire = async () => {
@@ -402,8 +302,7 @@ export function captureOwnedExplicitAttachRecoveryV2() {
402
302
  firstDispatchedAt: raw.firstDispatchedAt,
403
303
  });
404
304
  OWNER.check();
405
- const replayRetained =
406
- await classifyOwnedRetainedInitialAttachment(original);
305
+ const replayRetained = await classifyRetained(original);
407
306
  OWNER.check();
408
307
  need(replayRetained.status === "classified");
409
308
  verifyRecoveryRecord(
@@ -414,7 +313,10 @@ export function captureOwnedExplicitAttachRecoveryV2() {
414
313
  original,
415
314
  );
416
315
  OWNER.check();
417
- const discounts = replayCouponEligibility(value),
316
+ const discounts =
317
+ token === null
318
+ ? replayCouponEligibility(value)
319
+ : replayCouponEligibilityForLineage(token, value),
418
320
  current = value.currentBundle,
419
321
  observedAt = value.observedAt;
420
322
  // Historical original eligibility; never fabricate a current-null subscription.
@@ -501,15 +403,21 @@ export function captureOwnedExplicitAttachRecoveryV2() {
501
403
  OWNER.check();
502
404
  return Reflect.apply(send, op.sink, [record, ack]);
503
405
  };
504
- const compiler = createAttachEventCompiler(raw, {
505
- send: sourceSend,
506
- timeoutMs: 5000,
507
- });
406
+ const compiler =
407
+ token === null
408
+ ? createAttachEventCompiler(raw, {
409
+ send: sourceSend,
410
+ timeoutMs: 5000,
411
+ })
412
+ : createRecoveryAttachEventCompiler(token);
508
413
  OWNER.check();
509
414
  await owned(() =>
510
415
  compiler.dispatch({ event: "dispatch", stage: "attach", request }),
511
416
  );
512
417
  OWNER.check();
418
+ if (token !== null)
419
+ await owned(() => assertReplayFrontierForLineage(token));
420
+ OWNER.check();
513
421
  postEligible = true;
514
422
  let postedOnce = false;
515
423
  const post = async () => {
@@ -549,6 +457,8 @@ export function captureOwnedExplicitAttachRecoveryV2() {
549
457
  }),
550
458
  );
551
459
  OWNER.check();
460
+ if (token !== null)
461
+ await owned(() => retainInitialReceiptForLineage(token, receipt));
552
462
  await owned(() =>
553
463
  compiler.receipt({
554
464
  event: "receipt",
@@ -558,12 +468,21 @@ export function captureOwnedExplicitAttachRecoveryV2() {
558
468
  }),
559
469
  );
560
470
  OWNER.check();
561
- const result = admitRecoveryOutput(
562
- receipt,
563
- acquired.bundle.wireSubscription.schedule,
564
- prepared,
565
- request,
566
- );
471
+ const result =
472
+ token === null
473
+ ? admitRecoveryOutput(
474
+ receipt,
475
+ acquired.bundle.wireSubscription.schedule,
476
+ prepared,
477
+ request,
478
+ )
479
+ : admitRecoveryOutputForLineage(
480
+ token,
481
+ receipt,
482
+ acquired.bundle.wireSubscription.schedule,
483
+ prepared,
484
+ request,
485
+ );
567
486
  OWNER.check();
568
487
  control.takePostQuarantine();
569
488
  return result;
@@ -1,3 +1,4 @@
1
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
1
2
  import { need, closed, freeze } from "../material/nodeKernel.js";
2
3
  import { equal, referenceId } from "../../../renewalAggregate/shared.js";
3
4
  import type { Bundle, FreshInput } from "../material/capture.js";
@@ -79,6 +80,20 @@ function rebuild(b: Bundle) {
79
80
 
80
81
  /** One explicit root schedule association transition, with all residual material equal. */
81
82
  export function replayCouponEligibility(value: FreshInput) {
83
+ return replayEligibility(value, false);
84
+ }
85
+ export function replayCouponEligibilityForLineage(
86
+ token: object,
87
+ value: FreshInput,
88
+ ) {
89
+ need(arguments.length === 2);
90
+ const owner = ownerForInitialLineage(token);
91
+ owner.check();
92
+ const result = replayEligibility(value, true);
93
+ owner.check();
94
+ return result;
95
+ }
96
+ function replayEligibility(value: FreshInput, allowUnchanged: boolean) {
82
97
  const p = value.attachRequest.preparation,
83
98
  original = value.originalBundle,
84
99
  current = value.currentBundle;
@@ -92,7 +107,7 @@ export function replayCouponEligibility(value: FreshInput) {
92
107
  current.wireSubscription,
93
108
  "schedule",
94
109
  ) &&
95
- current.wireSubscription.schedule !== null,
110
+ (allowUnchanged || current.wireSubscription.schedule !== null),
96
111
  );
97
112
  const { schedule: oldAssociation, ...oldResidual } =
98
113
  original.wireSubscription,
@@ -111,6 +126,7 @@ export function replayCouponEligibility(value: FreshInput) {
111
126
  rebuild(original);
112
127
  const joined = rebuild(current);
113
128
  need(equal(original.couponReads, current.couponReads));
129
+ if (allowUnchanged && currentAssociation === null) return freeze(joined);
114
130
  const expected = p.expected,
115
131
  context = {
116
132
  customerAccountId: expected.customerAccountId,