@fantastic.dev/better-stripe 0.97.0 → 0.98.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 (74) 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 +5 -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 +38 -0
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/material/classifiers.d.ts +11 -0
  8. package/dist/client/billing/renewalAttach/internal/material/classifiers.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/material/classifiers.js +57 -22
  10. package/dist/client/billing/renewalAttach/internal/material/classifiers.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +54 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +44 -37
  14. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts +21 -0
  16. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts.map +1 -0
  17. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js +36 -0
  18. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js.map +1 -0
  19. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +3 -0
  20. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +71 -46
  22. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +1 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +17 -5
  26. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -1
  27. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts +35 -0
  28. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js +46 -0
  30. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js.map +1 -0
  31. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +8 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
  33. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +21 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
  35. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
  36. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
  37. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +3 -0
  38. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
  39. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +65 -0
  40. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -0
  41. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +161 -0
  42. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
  43. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +4 -0
  44. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -1
  45. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +24 -3
  46. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -1
  47. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  48. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  49. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  50. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  51. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  52. package/dist/component/earnings/triggers.d.ts +16 -16
  53. package/dist/component/payoutRelease/queries.d.ts +2 -2
  54. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  55. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  56. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  57. package/docs/renewal-context-reads.md +35 -4
  58. package/package.json +1 -1
  59. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +42 -0
  60. package/src/client/billing/renewalAttach/internal/material/classifiers.ts +64 -22
  61. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +55 -48
  62. package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
  63. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +91 -55
  64. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +23 -5
  65. package/src/client/billing/renewalAttach/internal/operations/transportCapture.ts +60 -0
  66. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +25 -0
  67. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
  68. package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +175 -0
  69. package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts +240 -0
  70. package/src/client/billing/renewalAttach/internal/producer/producerActor.integration.test.ts +526 -0
  71. package/src/client/billing/renewalAttach/internal/producer/producerMaterial.integration.test.ts +251 -0
  72. package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
  73. package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
  74. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +100 -11
@@ -372,14 +372,6 @@ export declare const mutation: import("convex-helpers/server/customFunctions").C
372
372
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
373
373
  requestKey: string;
374
374
  result?: {
375
- reason: "identity_changed" | "revision_changed" | "scope_busy";
376
- retryable: false;
377
- status: "conflict";
378
- } | {
379
- reason: "policy_invalid";
380
- retryable: false;
381
- status: "rejected";
382
- } | {
383
375
  operation: {
384
376
  accountId: string;
385
377
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -390,6 +382,14 @@ export declare const mutation: import("convex-helpers/server/customFunctions").C
390
382
  } | {
391
383
  enabled: boolean;
392
384
  status: "unchanged";
385
+ } | {
386
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
387
+ retryable: false;
388
+ status: "conflict";
389
+ } | {
390
+ reason: "policy_invalid";
391
+ retryable: false;
392
+ status: "rejected";
393
393
  } | {
394
394
  reason: "provider_pending";
395
395
  retryable: true;
@@ -3417,14 +3417,6 @@ export declare const mutation: import("convex-helpers/server/customFunctions").C
3417
3417
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
3418
3418
  requestKey: string;
3419
3419
  result?: {
3420
- reason: "identity_changed" | "revision_changed" | "scope_busy";
3421
- retryable: false;
3422
- status: "conflict";
3423
- } | {
3424
- reason: "policy_invalid";
3425
- retryable: false;
3426
- status: "rejected";
3427
- } | {
3428
3420
  operation: {
3429
3421
  accountId: string;
3430
3422
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -3435,6 +3427,14 @@ export declare const mutation: import("convex-helpers/server/customFunctions").C
3435
3427
  } | {
3436
3428
  enabled: boolean;
3437
3429
  status: "unchanged";
3430
+ } | {
3431
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
3432
+ retryable: false;
3433
+ status: "conflict";
3434
+ } | {
3435
+ reason: "policy_invalid";
3436
+ retryable: false;
3437
+ status: "rejected";
3438
3438
  } | {
3439
3439
  reason: "provider_pending";
3440
3440
  retryable: true;
@@ -163,10 +163,10 @@ export declare const snapshot: import("convex/server").RegisteredQuery<"public",
163
163
  accountId: string;
164
164
  ownerKey: string;
165
165
  }, Promise<{
166
- status: "held";
167
- reason: "snapshot_limit";
168
166
  transfers?: undefined;
169
167
  claims?: undefined;
168
+ status: "held";
169
+ reason: "snapshot_limit";
170
170
  } | {
171
171
  reason?: undefined;
172
172
  status: "ready";
@@ -1 +1 @@
1
- {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/payoutRelease/queries.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIlB,CAAC;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAiBd,CAAC;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BlB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;;;;GAQf,CAAC;AAEH,4FAA4F;AAC5F,eAAO,MAAM,QAAQ;;;;YAsBE,MAAM;YAAmB,gBAAgB;;;;;YAS3C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE1B,CAAC"}
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/payoutRelease/queries.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIlB,CAAC;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAiBd,CAAC;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BlB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;;;;GAQf,CAAC;AAEH,4FAA4F;AAC5F,eAAO,MAAM,QAAQ;;;;;;YAsBE,MAAM;YAAmB,gBAAgB;;;YAS3C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE1B,CAAC"}
@@ -14,7 +14,7 @@ export declare function checkRollback(ctx: MutationCtx, op: Doc<"processingCostR
14
14
  readonly bindFunding?: undefined;
15
15
  } | {
16
16
  reason?: undefined;
17
- readonly retryable?: undefined;
17
+ retryable?: undefined;
18
18
  readonly status: "ready";
19
19
  readonly bindFunding: boolean;
20
20
  }>;
@@ -2632,6 +2632,14 @@ export declare function setupAllowance(): Promise<{
2632
2632
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
2633
2633
  requestKey: string;
2634
2634
  result?: {
2635
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2636
+ retryable: false;
2637
+ status: "conflict";
2638
+ } | {
2639
+ reason: "policy_invalid";
2640
+ retryable: false;
2641
+ status: "rejected";
2642
+ } | {
2635
2643
  operation: {
2636
2644
  accountId: string;
2637
2645
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2642,14 +2650,6 @@ export declare function setupAllowance(): Promise<{
2642
2650
  } | {
2643
2651
  enabled: boolean;
2644
2652
  status: "unchanged";
2645
- } | {
2646
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2647
- retryable: false;
2648
- status: "conflict";
2649
- } | {
2650
- reason: "policy_invalid";
2651
- retryable: false;
2652
- status: "rejected";
2653
2653
  } | {
2654
2654
  reason: "provider_pending";
2655
2655
  retryable: true;
@@ -2660,6 +2660,14 @@ export declare function setupAllowance(): Promise<{
2660
2660
  payload: import("convex/values").VString<string, "required">;
2661
2661
  preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
2662
2662
  result: import("convex/values").VUnion<{
2663
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2664
+ retryable: false;
2665
+ status: "conflict";
2666
+ } | {
2667
+ reason: "policy_invalid";
2668
+ retryable: false;
2669
+ status: "rejected";
2670
+ } | {
2663
2671
  operation: {
2664
2672
  accountId: string;
2665
2673
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2670,14 +2678,6 @@ export declare function setupAllowance(): Promise<{
2670
2678
  } | {
2671
2679
  enabled: boolean;
2672
2680
  status: "unchanged";
2673
- } | {
2674
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2675
- retryable: false;
2676
- status: "conflict";
2677
- } | {
2678
- reason: "policy_invalid";
2679
- retryable: false;
2680
- status: "rejected";
2681
2681
  } | {
2682
2682
  reason: "provider_pending";
2683
2683
  retryable: true;
@@ -113,8 +113,7 @@ Each callback rechecks both clocks and the original policy before rearming. The
113
113
  later final deadline is not a timer span limit. Event-loop suspension can delay
114
114
  callbacks. Every continuation therefore checks both clocks before
115
115
  returning a value. Retirement is irreversible and never extends either original
116
- cutoff. Legacy actors still use their separate dormant identity; extracting and
117
- wiring their per-invocation kernels remains required before runtime activation.
116
+ cutoff. Legacy actors retain their separate dormant identity and behavior.
118
117
 
119
118
  The private initial core can capture one attach-stage C10 compiler for its own
120
119
  lineage. This compiler takes the original raw source and actual acquired
@@ -127,8 +126,40 @@ Retiring one invocation rejects its pending channel without retiring another
127
126
  invocation's channel or removing already committed DATA. Stored events and C10
128
127
  append acknowledgements do not establish provider custody or a returned public
129
128
  operation acknowledgement. Legacy stage-channel facades retain their existing
130
- lazy Owner and behavior. Initial actor, classifier, acquisition and transport
131
- factory wiring remains required.
129
+ lazy Owner and behavior.
130
+
131
+ The core's private material classifiers also retain the original journal source
132
+ and canonical Owner. Retained classification accepts no replacement source.
133
+ Fresh classification accepts read DATA and its observed timestamp, then uses the
134
+ existing raw Coupon join checks and actual C1/C2 reconstruction against the
135
+ original source. Both paths keep the existing DATA-consistency-only result and
136
+ bounded snapshots. They do not qualify acquisition or provider custody. Pending
137
+ reconstruction is owned by that invocation; retirement rejects its continuation
138
+ without closing another invocation's classifier. Legacy classifier exports keep
139
+ their lazy Owner and existing refusal behavior.
140
+
141
+ The private initial actor now uses those classifiers, the canonical transport and
142
+ one acquisition reader for its lineage. Its operation retains one private origin
143
+ association and a single-use source slot. The transport captures the selected
144
+ SDK's original raw-request method and receiver, and receives the actual SDK
145
+ promise. Its fixed read plan permits the original subscription, target price,
146
+ billing customer and at most 40 original Coupon reads. It permits one attachment
147
+ POST. Callers cannot supply a replacement client, source, plan, Owner or journal
148
+ sink through the invocation core.
149
+
150
+ The actor retains the complete captured C3 receipt in the component journal at
151
+ sequence 2 before appending receipt event 3 or returning an acknowledgement.
152
+ Receipt retention alone is DATA. If the Owner retires while a committed retention
153
+ reply is pending, that DATA remains, but the actor refuses its acknowledgement.
154
+ Another invocation keeps its own client, Owner, journal and continuation.
155
+
156
+ Production Source class arrays remain empty. Empty admission returns before
157
+ constructing an Owner, loading Source data, invoking a client method or sampling
158
+ a clock, including when the
159
+ private actor is captured from a lineage that has no Owner yet. Tests admit
160
+ synthetic profiles in ordinary Node and Convex-test with controlled HTTP. They
161
+ do not qualify native execution or provider custody. Public scheduling, native
162
+ profile qualification, recovery and later operation stages remain separate work.
132
163
 
133
164
  ## Component operation journal
134
165
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fantastic.dev/better-stripe",
3
- "version": "0.97.0",
3
+ "version": "0.98.0",
4
4
  "description": "Convex component for Stripe Accounts v2, subscriptions, metered billing and Connect marketplaces, with React workflows.",
5
5
  "keywords": [
6
6
  "stripe",
@@ -22,6 +22,10 @@ import {
22
22
  type RawReadTransport,
23
23
  } from "./rawWireSource.js";
24
24
  import { acquireCouponJoins } from "./rawCouponJoins.js";
25
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
26
+ import { ownedAwaitForInitialLineage } from "../producer/ownedAwaitFactory.js";
27
+ import { operationForInitialLineage } from "../producer/operationFactory.js";
28
+ import { createInitialTransportForLineage } from "../operations/fixedTransport.js";
25
29
  const need: (x: unknown) => asserts x = (x) => {
26
30
  if (!x) throw Error("RAW_ACQUISITION_STOP");
27
31
  };
@@ -47,6 +51,44 @@ type RawSuccess = Readonly<{
47
51
  export type RawAcquisitionResult = typeof STOP | RawSuccess;
48
52
  export type RawConfigureAcquisitionResult =
49
53
  typeof STOP | (RawSuccess & Readonly<{ schedule: Record<string, unknown> }>);
54
+ type InitialReader = Readonly<{ acquire(): Promise<RawAcquisitionResult> }>;
55
+ const initialReaders = new WeakMap<object, Promise<InitialReader>>();
56
+
57
+ /** Fixed source, transport and expected material; no replacement inputs. */
58
+ export function acquisitionForInitialLineage(
59
+ token: object,
60
+ ): Promise<InitialReader> {
61
+ if (arguments.length !== 1) throw Error("RAW_ACQUISITION_STOP");
62
+ const owner = ownerForInitialLineage(token);
63
+ owner.check();
64
+ const owned = ownedAwaitForInitialLineage(token);
65
+ let pending = initialReaders.get(token);
66
+ if (!pending) {
67
+ pending = owned(async () => {
68
+ try {
69
+ const frame = await operationForInitialLineage(token);
70
+ const pair = await createInitialTransportForLineage(token);
71
+ owner.check();
72
+ const reader = createSelectedRawAcquisition(
73
+ owner,
74
+ captureTransport(pair.transport.readTransport),
75
+ );
76
+ return Object.freeze({
77
+ acquire() {
78
+ if (arguments.length !== 0) throw Error("RAW_ACQUISITION_STOP");
79
+ return owned(() => reader.acquire(frame.expected));
80
+ },
81
+ });
82
+ } catch (error) {
83
+ owner.retire();
84
+ throw error;
85
+ }
86
+ });
87
+ initialReaders.set(token, pending);
88
+ }
89
+ const captured = pending;
90
+ return owned(() => captured);
91
+ }
50
92
  const observed = z.union([
51
93
  z.null(),
52
94
  resourceId("sub_sched"),
@@ -1,4 +1,8 @@
1
1
  import { OWNER } from "../originalOwner.js";
2
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
3
+ import { readInitialLineage } from "../producer/lineageAuthority.js";
4
+ import { ownedAwaitForInitialLineage } from "../producer/ownedAwaitFactory.js";
5
+ type MaterialOwner = Pick<typeof OWNER, "check">;
2
6
  import {
3
7
  prepareRenewalPriceReplacementV2 as c1,
4
8
  prepareRenewalScheduleAttachmentV2 as c2,
@@ -190,19 +194,19 @@ function release(
190
194
  encode(node);
191
195
  return freeze(materialize(node)) as Classified;
192
196
  }
193
- async function retained(value: RetainedInput) {
197
+ async function retained(owner: MaterialOwner, value: RetainedInput) {
194
198
  const raw = value.attachRequest;
195
- OWNER.check();
199
+ owner.check();
196
200
  const prepared = await c1(raw.preparation);
197
- OWNER.check();
198
- OWNER.check();
201
+ owner.check();
202
+ owner.check();
199
203
  const request = await c2({
200
204
  prepared,
201
205
  apiVersion: raw.apiVersion,
202
206
  attachKey: raw.attachKey,
203
207
  firstDispatchedAt: raw.firstDispatchedAt,
204
208
  });
205
- OWNER.check();
209
+ owner.check();
206
210
  const discounts = ownedRetainedEligibility(value),
207
211
  args = { attachRequest: raw, intent: "initial" as const };
208
212
  const reads = validateOwnedReadMaterial(
@@ -217,7 +221,7 @@ async function retained(value: RetainedInput) {
217
221
  undefined,
218
222
  discounts,
219
223
  );
220
- OWNER.check();
224
+ owner.check();
221
225
  const result = release(
222
226
  material(args, false, prepared, request, reads, {
223
227
  actualFreshSubscription: raw.preparation.subscription,
@@ -225,22 +229,22 @@ async function retained(value: RetainedInput) {
225
229
  prepared,
226
230
  request,
227
231
  );
228
- OWNER.check();
232
+ owner.check();
229
233
  return result;
230
234
  }
231
- async function fresh(value: FreshInput) {
235
+ async function fresh(owner: MaterialOwner, value: FreshInput) {
232
236
  const raw = value.attachRequest;
233
- OWNER.check();
237
+ owner.check();
234
238
  const prepared = await c1(raw.preparation);
235
- OWNER.check();
236
- OWNER.check();
239
+ owner.check();
240
+ owner.check();
237
241
  const request = await c2({
238
242
  prepared,
239
243
  apiVersion: raw.apiVersion,
240
244
  attachKey: raw.attachKey,
241
245
  firstDispatchedAt: raw.firstDispatchedAt,
242
246
  });
243
- OWNER.check();
247
+ owner.check();
244
248
  const discounts = ownedCouponEligibility(value),
245
249
  b = value.currentBundle;
246
250
  const args = {
@@ -263,7 +267,7 @@ async function fresh(value: FreshInput) {
263
267
  undefined,
264
268
  discounts,
265
269
  );
266
- OWNER.check();
270
+ owner.check();
267
271
  const result = release(
268
272
  material(args, true, prepared, request, reads, {
269
273
  actualFreshSubscription: b.wireSubscription,
@@ -271,43 +275,81 @@ async function fresh(value: FreshInput) {
271
275
  prepared,
272
276
  request,
273
277
  );
274
- OWNER.check();
278
+ owner.check();
275
279
  return result;
276
280
  }
277
281
  /** Internal DATA consistency only; Source owner and acquisition provenance remain unbound. */
278
282
  export function classifyOwnedRetainedInitialAttachment(
279
283
  raw: unknown,
284
+ ): Promise<Classified | typeof RETAINED_STOP> {
285
+ return classifyRetained(OWNER, raw);
286
+ }
287
+ function classifyRetained(
288
+ owner: MaterialOwner,
289
+ raw: unknown,
280
290
  ): Promise<Classified | typeof RETAINED_STOP> {
281
291
  let value;
282
292
  try {
283
- OWNER.check();
293
+ owner.check();
284
294
  value = captureRetainedInput(raw);
285
- OWNER.check();
295
+ owner.check();
286
296
  } catch {
287
297
  return Promise.resolve(RETAINED_STOP);
288
298
  }
289
- return retained(value).catch(() => {
299
+ return retained(owner, value).catch(() => {
290
300
  try {
291
- OWNER.check();
301
+ owner.check();
292
302
  } catch {}
293
303
  return RETAINED_STOP;
294
304
  });
295
305
  }
296
306
  export function classifyOwnedInitialAttachment(
297
307
  raw: unknown,
308
+ ): Promise<Classified | typeof FRESH_STOP> {
309
+ return classifyFresh(OWNER, raw);
310
+ }
311
+ function classifyFresh(
312
+ owner: MaterialOwner,
313
+ raw: unknown,
298
314
  ): Promise<Classified | typeof FRESH_STOP> {
299
315
  let value;
300
316
  try {
301
- OWNER.check();
317
+ owner.check();
302
318
  value = captureOwnedInput(raw);
303
- OWNER.check();
319
+ owner.check();
304
320
  } catch {
305
321
  return Promise.resolve(FRESH_STOP);
306
322
  }
307
- return fresh(value).catch(() => {
323
+ return fresh(owner, value).catch(() => {
308
324
  try {
309
- OWNER.check();
325
+ owner.check();
310
326
  } catch {}
311
327
  return FRESH_STOP;
312
328
  });
313
329
  }
330
+
331
+ /** Private original-call classifier factory. Inputs and outputs remain unsigned DATA. */
332
+ export function createInitialMaterialClassifiers(token: object) {
333
+ if (arguments.length !== 1) throw Error("INITIAL_MATERIAL_UNBOUND");
334
+ const owner = ownerForInitialLineage(token);
335
+ owner.check();
336
+ const lineage = readInitialLineage(token);
337
+ const source = JSON.parse(lineage.reservation.recordJSON);
338
+ const original = {
339
+ attachRequest: source.attachRequest,
340
+ originalBundle: source.originalBundle,
341
+ };
342
+ const owned = ownedAwaitForInitialLineage(token);
343
+ return Object.freeze({
344
+ retained() {
345
+ if (arguments.length !== 0) throw Error("INITIAL_MATERIAL_UNBOUND");
346
+ return owned(() => classifyRetained(owner, original));
347
+ },
348
+ fresh(currentBundle: unknown, observedAt: unknown) {
349
+ if (arguments.length !== 2) throw Error("INITIAL_MATERIAL_UNBOUND");
350
+ return owned(() =>
351
+ classifyFresh(owner, { ...original, currentBundle, observedAt }),
352
+ );
353
+ },
354
+ });
355
+ }
@@ -9,7 +9,6 @@ import {
9
9
  freezeJSON,
10
10
  type AttachRequest,
11
11
  type ReadRow,
12
- type SourceMethod,
13
12
  } from "./types.js";
14
13
  import {
15
14
  safeDiagnostics,
@@ -23,34 +22,14 @@ import {
23
22
  loadOwnedTransportSource,
24
23
  } from "./sourceOperations.js";
25
24
  import { OWNER } from "../originalOwner.js";
26
-
27
- function sourceFunction(
28
- service: unknown,
29
- name: string,
30
- ): { receiver: object; method: SourceMethod } {
31
- need(service && typeof service === "object" && !types.isProxy(service));
32
- const d = Object.getOwnPropertyDescriptor(service, name);
33
- need(d && "value" in d && typeof d.value === "function");
34
- // The function is selected once from validated own data, preserving its receiver.
35
- return { receiver: service, method: d.value as SourceMethod };
36
- }
37
-
38
- /** Internal fixed attach profile: 43 reads and one POST, never a 44-GET profile. */
39
- function captureSource(raw: unknown) {
40
- const b = closed(raw, ["owner", "request", "readPlan", "delegate"]);
41
- need(b.owner === OWNER);
42
- const owner = sourceFunction(b.owner, "check"),
43
- delegate = sourceFunction(b.delegate, "rawRequest");
44
- const { request, plan } = captureRequestAndReads(b.request, b.readPlan);
45
- return Object.freeze({
46
- owner: owner.receiver,
47
- check: owner.method,
48
- delegate: delegate.receiver,
49
- send: delegate.method,
50
- request,
51
- plan: Object.freeze(plan),
52
- });
53
- }
25
+ import {
26
+ captureLegacyTransportSource,
27
+ captureInitialTransportSource,
28
+ checkTransportOwnerResult as checkOwnerResult,
29
+ } from "./transportCapture.js";
30
+ import { ownerForInitialLineage } from "../producer/ownerFactory.js";
31
+ import { ownedAwaitForInitialLineage } from "../producer/ownedAwaitFactory.js";
32
+ import { operationForInitialLineage } from "../producer/operationFactory.js";
54
33
 
55
34
  function validRead(
56
35
  row: ReadRow,
@@ -67,22 +46,6 @@ function validRead(
67
46
  );
68
47
  }
69
48
 
70
- function checkOwnerResult(value: unknown) {
71
- const x = closed(value, ["wallMs", "ns", "nowSeconds", "retired"]);
72
- need(
73
- typeof x.wallMs === "number" &&
74
- Number.isSafeInteger(x.wallMs) &&
75
- x.wallMs >= 0 &&
76
- typeof x.ns === "bigint" &&
77
- x.ns >= 0n &&
78
- x.ns <= 18446744073709551615n &&
79
- typeof x.nowSeconds === "number" &&
80
- Number.isSafeInteger(x.nowSeconds) &&
81
- x.nowSeconds === Math.floor(x.wallMs / 1000) &&
82
- x.retired === false,
83
- );
84
- }
85
-
86
49
  export type PostDisposition =
87
50
  | "NOT_STARTED"
88
51
  | "PENDING"
@@ -169,9 +132,12 @@ type Association = Readonly<{
169
132
  readPlan: unknown;
170
133
  delegate: unknown;
171
134
  }>;
172
- function build(source: unknown, association?: Association) {
173
- const b = captureSource(source),
174
- generation = Object.freeze({});
135
+ function build(source: unknown, association?: Association, token?: object) {
136
+ const b =
137
+ token === undefined
138
+ ? captureLegacyTransportSource(source)
139
+ : captureInitialTransportSource(token, source);
140
+ const generation = Object.freeze({});
175
141
  let ordinal = 0,
176
142
  index = 0,
177
143
  pending: Attempt | null = null,
@@ -572,3 +538,44 @@ export function createRecoveryOwnedTransportWithAttemptCapability() {
572
538
  need(arguments.length === 0);
573
539
  return createAssociatedPair(loadRecoveryOwnedTransportSource);
574
540
  }
541
+
542
+ const initialTransports = new WeakMap<
543
+ object,
544
+ Promise<ReturnType<typeof build>>
545
+ >();
546
+ /** Canonical private transport, constructed only from the original lineage. */
547
+ export function createInitialTransportForLineage(token: object) {
548
+ if (arguments.length !== 1) throw Error("INITIAL_OPERATION_UNBOUND");
549
+ const owner = ownerForInitialLineage(token);
550
+ owner.check();
551
+ const owned = ownedAwaitForInitialLineage(token);
552
+ let pending = initialTransports.get(token);
553
+ if (!pending) {
554
+ pending = owned(async () => {
555
+ try {
556
+ const frame = await operationForInitialLineage(token);
557
+ owner.check();
558
+ return build(
559
+ {
560
+ owner,
561
+ request: frame.request,
562
+ readPlan: frame.operation.readPlan,
563
+ delegate: frame.operation.delegate,
564
+ },
565
+ {
566
+ operation: frame.operation,
567
+ readPlan: frame.operation.readPlan,
568
+ delegate: frame.operation.delegate,
569
+ },
570
+ token,
571
+ );
572
+ } catch (error) {
573
+ owner.retire();
574
+ throw error;
575
+ }
576
+ });
577
+ initialTransports.set(token, pending);
578
+ }
579
+ const captured = pending;
580
+ return owned(() => captured);
581
+ }
@@ -0,0 +1,41 @@
1
+ import { types } from "node:util";
2
+ import type { AttachRequest, SourceMethod } from "./types.js";
3
+
4
+ export function sourceMethod(object: unknown, name: string): SourceMethod {
5
+ need(object !== null && typeof object === "object" && !types.isProxy(object));
6
+ const d = Object.getOwnPropertyDescriptor(object, name);
7
+ need(
8
+ d &&
9
+ d.enumerable &&
10
+ "value" in d &&
11
+ typeof d.value === "function" &&
12
+ !types.isProxy(d.value),
13
+ );
14
+ return d.value as SourceMethod;
15
+ }
16
+ export const stop = (): never => {
17
+ throw Error("INITIAL_ACTOR_STOP");
18
+ };
19
+ export function need(value: unknown): asserts value {
20
+ if (!value) stop();
21
+ }
22
+ export function seven(request: AttachRequest) {
23
+ const { scope, apiVersion, method, path, payload, key, firstDispatchedAt } =
24
+ request;
25
+ return Object.freeze({
26
+ scope,
27
+ apiVersion,
28
+ method,
29
+ path,
30
+ payload,
31
+ key,
32
+ firstDispatchedAt,
33
+ });
34
+ }
35
+
36
+ export const refuse = (reason: string) =>
37
+ Object.freeze({
38
+ status: "not_dispatched",
39
+ reason,
40
+ operationalAuthority: false,
41
+ });