@fantastic.dev/better-stripe 0.102.0 → 0.104.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 (65) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/c10/appendAck.d.ts +7 -0
  4. package/dist/client/billing/renewalAttach/internal/c10/appendAck.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/c10/appendAck.js +13 -1
  6. package/dist/client/billing/renewalAttach/internal/c10/appendAck.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts +23 -0
  8. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js +34 -2
  10. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +22 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +105 -3
  14. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +1 -0
  16. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/preflight/output.js +6 -2
  18. package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +3 -1
  20. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/preflight/record.js +8 -3
  22. package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +2 -0
  24. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/preflight/relations.js +12 -5
  26. package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -1
  27. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +3 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +25 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -0
  31. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +6 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +49 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts +16 -0
  36. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js +117 -0
  38. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js.map +1 -0
  39. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  40. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  41. package/dist/component/balanceFunding/mutations.d.ts +27 -27
  42. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  43. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  44. package/dist/component/earnings/triggers.d.ts +16 -16
  45. package/dist/component/payoutRelease/queries.d.ts +2 -2
  46. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  47. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  48. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  49. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  50. package/docs/renewal-context-reads.md +72 -4
  51. package/package.json +1 -1
  52. package/src/client/billing/renewalAttach/internal/c10/appendAck.ts +17 -0
  53. package/src/client/billing/renewalAttach/internal/c10/configureEvents.ts +45 -2
  54. package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +148 -3
  55. package/src/client/billing/renewalAttach/internal/preflight/output.ts +20 -3
  56. package/src/client/billing/renewalAttach/internal/preflight/record.ts +11 -3
  57. package/src/client/billing/renewalAttach/internal/preflight/relations.ts +20 -5
  58. package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +40 -0
  59. package/src/client/billing/renewalAttach/internal/producer/configureJournalWork.ts +53 -0
  60. package/src/client/billing/renewalAttach/internal/producer/configurePreflight.ts +170 -0
  61. package/src/client/billing/renewalAttach/internal/producer/producerConfigureChannelControls.integration.test.ts +542 -0
  62. package/src/client/billing/renewalAttach/internal/producer/producerConfigureChannels.integration.test.ts +321 -0
  63. package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflight.integration.test.ts +67 -0
  64. package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflightControls.integration.test.ts +475 -0
  65. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +89 -5
@@ -5,14 +5,6 @@ export declare function savePreparationHandler(ctx: MutationCtx, args: Infer<typ
5
5
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
6
6
  }>;
7
7
  export declare function beginHandler(ctx: MutationCtx, args: Infer<typeof beginArgs>): Promise<{
8
- reason: "identity_changed" | "revision_changed" | "scope_busy";
9
- retryable: false;
10
- status: "conflict";
11
- } | {
12
- reason: "policy_invalid";
13
- retryable: false;
14
- status: "rejected";
15
- } | {
16
8
  operation: {
17
9
  accountId: string;
18
10
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -23,6 +15,14 @@ export declare function beginHandler(ctx: MutationCtx, args: Infer<typeof beginA
23
15
  } | {
24
16
  enabled: boolean;
25
17
  status: "unchanged";
18
+ } | {
19
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
20
+ retryable: false;
21
+ status: "conflict";
22
+ } | {
23
+ reason: "policy_invalid";
24
+ retryable: false;
25
+ status: "rejected";
26
26
  } | {
27
27
  reason: "provider_pending";
28
28
  retryable: true;
@@ -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,14 +2632,6 @@ 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
- } | {
2643
2635
  operation: {
2644
2636
  accountId: string;
2645
2637
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2650,6 +2642,14 @@ export declare function setupAllowance(): Promise<{
2650
2642
  } | {
2651
2643
  enabled: boolean;
2652
2644
  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,14 +2660,6 @@ 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
- } | {
2671
2663
  operation: {
2672
2664
  accountId: string;
2673
2665
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2678,6 +2670,14 @@ export declare function setupAllowance(): Promise<{
2678
2670
  } | {
2679
2671
  enabled: boolean;
2680
2672
  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;
@@ -2632,6 +2632,14 @@ export declare function setupCredits(): 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 setupCredits(): 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 setupCredits(): 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 setupCredits(): 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;
@@ -262,10 +262,78 @@ committed; retained DATA and failed or lost replies cannot remint the consumed
262
262
  call.
263
263
 
264
264
  The result is an opaque private view containing `owner`, `basisJSON` and
265
- `operationalAuthority: false`. It supplies no configure transport, C10 channel,
266
- preflight/write actor or public scheduling API. Those integrations remain
267
- required, as do genuine generation and operational qualification. Production
268
- Source profile arrays remain empty.
265
+ `operationalAuthority: false`. The separate private C10 factory below can use
266
+ that identity. Configure write transport, write actors and public scheduling
267
+ remain required, as do genuine generation and operational qualification.
268
+ Production Source profile arrays remain empty.
269
+
270
+ ## Private configure C10 channel
271
+
272
+ `createAdmittedConfigureEventCompiler(token)` accepts only the actual admitted
273
+ child identity. It captures one configure channel, including when capture fails;
274
+ callers cannot replace its source, sender, Owner or options. Copied views and
275
+ proxy identities cannot create another channel. The retained raw C6 configuration
276
+ supplies its source. The compiler reconstructs C7 dispatch and complete C9 receipt
277
+ DATA and compares each event before appending sequences 1 through 3 to the child
278
+ attempt. The parent attachment history remains separate.
279
+
280
+ The channel derives the canonical Owner from the original parent token. A fixed
281
+ synchronous child guard adds binding and custody checks at every channel gate,
282
+ including after hashing and around append/ACK handling and awaits. The guard
283
+ must return undefined; asynchronous or other non-void results refuse. It cannot
284
+ replace the Owner checks or retirement subscription. The guarded parent kernel
285
+ stays independent of configure lineage code, preserving the existing legacy
286
+ compiler and avoiding an import cycle.
287
+
288
+ The sender receives the exact original reservation object from the actual child
289
+ CAS and uses its original class-bound journal. A captured DATA copy is
290
+ insufficient. The actual component append must commit and return its matching
291
+ complete reply before C10 acknowledgement. Per-child work tracking follows the
292
+ actual append RPC promise independently of a channel timeout. A timed-out channel
293
+ can remain closed while a committed mutation reply is still pending. Late replies
294
+ cannot reopen it. Separate child and SDK-root channels retain their own sequence,
295
+ work and retirement state.
296
+
297
+ C10 append acknowledgement establishes DATA consistency only. Dispatch intent,
298
+ a committed response or receipt event, and a retained C9 do not establish provider
299
+ custody, returned configure ACK custody, pending/effective replacement or fresh
300
+ dispatch permission. Receipt retention remains a separate operation; a future
301
+ configure completion pipeline must retain the complete C9 before publishing
302
+ receipt event 3 and returning its actual acknowledgement. Future execution also
303
+ requires its own frontier checks. This channel factory supplies no provider
304
+ transport or write actor and activates no operational Source profile.
305
+
306
+ ## Private admitted configure preflight
307
+
308
+ `captureAdmittedConfigurePreflight(token)` captures one readonly actor for the
309
+ actual admitted child. Capture and invocation are each spent once, including
310
+ failed calls and invalid extra arguments. The factory requires a unique compiled
311
+ preflight entry linked to the actual returned parent ACK entry and retains its
312
+ predicate identity. Production profile arrays remain empty, so this private path
313
+ still refuses without a qualified Source profile.
314
+
315
+ The actor uses the original parent Owner, SDK client, stock delegate promise and
316
+ class-bound child journal. It never loads the legacy singleton Owner or transport
317
+ source. The fixed plan reads the subscription with its existing expansions,
318
+ price, customer, original coupons in order and attached schedule last. Its 4–44
319
+ requests are GETs with explicit undefined bodies, API version
320
+ `2026-09-30.endive` and zero network retries. No caller can substitute a plan,
321
+ transport, source, clock, predicate or output.
322
+
323
+ The actor reconstructs retained C6 and C3 DATA, compares complete current reads,
324
+ reprojects the immutable C7 request and checks the compiled preflight predicate.
325
+ Observation time comes from the original Owner. Reconstruction preserves the
326
+ original first-dispatch time, key and deadlines. Complete operation, basis,
327
+ head-zero and ACK-null journal checks fence acquisition and output release.
328
+ ACK-null precedes the final head read. These bounded reads do not lock the journal
329
+ against a later concurrent write.
330
+
331
+ Successful completion privately retains the actual output identity, parent ACK
332
+ view and compiled entry pointers. Pending reads, copied output or copied tokens
333
+ cannot register completion. Owner retirement and observed custody changes close
334
+ the actor. The legacy preflight functions retain their original Owner checks
335
+ around shared DATA kernels. This readonly consistency result grants no configure
336
+ POST permission, returned configure ACK custody or public scheduling support.
269
337
 
270
338
  ## Component operation journal
271
339
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fantastic.dev/better-stripe",
3
- "version": "0.102.0",
3
+ "version": "0.104.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",
@@ -1,4 +1,5 @@
1
1
  /** Stage and append share one irreversible latch and the same original owner. */
2
+ import { types } from "node:util";
2
3
  import { SOURCE_OWNER } from "./ownerBinding.js";
3
4
  import { ownerForInitialLineage } from "../producer/ownerFactory.js";
4
5
  import {
@@ -24,9 +25,23 @@ export function createStageChannel(raw: unknown) {
24
25
  export function createInitialStageChannel(token: object, raw: unknown) {
25
26
  return stageChannel(raw, ownerForInitialLineage(token));
26
27
  }
28
+ /** A fixed internal guard can add checks, never replace the canonical Owner. */
29
+ export function createGuardedInitialStageChannel(
30
+ token: object,
31
+ raw: unknown,
32
+ guard: () => unknown,
33
+ ) {
34
+ need(
35
+ arguments.length === 3 &&
36
+ typeof guard === "function" &&
37
+ !types.isProxy(guard),
38
+ );
39
+ return stageChannel(raw, ownerForInitialLineage(token), guard);
40
+ }
27
41
  function stageChannel(
28
42
  raw: unknown,
29
43
  owner: Pick<typeof SOURCE_OWNER, "basis" | "check" | "subscribe">,
44
+ guard?: () => unknown,
30
45
  ) {
31
46
  let closedChannel = false,
32
47
  unsubscribe = () => {},
@@ -44,7 +59,9 @@ function stageChannel(
44
59
  const gate = (): Time => {
45
60
  try {
46
61
  need(!closedChannel);
62
+ if (guard) need(guard() === undefined);
47
63
  const t = owner.check();
64
+ if (guard) need(guard() === undefined);
48
65
  need(
49
66
  basis &&
50
67
  Number.isSafeInteger(basis.startWallMs) &&
@@ -12,13 +12,56 @@ import {
12
12
  captureConfigureReceipt,
13
13
  } from "./eventCapture.js";
14
14
  import { materialize } from "./eventCodec.js";
15
- import { createStageChannel } from "./appendAck.js";
15
+ import {
16
+ createStageChannel,
17
+ createGuardedInitialStageChannel,
18
+ } from "./appendAck.js";
19
+ import { readConfigureLineage } from "../producer/configureLineage.js";
20
+ import { journalWorkForConfigureLineage } from "../producer/configureJournalWork.js";
16
21
  import {
17
22
  projectRenewalConfigurationV2,
18
23
  constructRenewalConfigurationReceiptV2,
19
24
  } from "./publicApi.js";
20
25
  export function createConfigureEventCompiler(raw: unknown, options: unknown) {
21
- const channel = createStageChannel(options);
26
+ return configureEventCompiler(raw, createStageChannel(options));
27
+ }
28
+ const admittedChannels = new WeakSet<object>();
29
+ /** One exact admitted child, without replacement source, sender or Owner inputs. */
30
+ export function createAdmittedConfigureEventCompiler(token: object) {
31
+ if (typeof token !== "object" || token === null)
32
+ throw Error("CONFIGURE_CHANNEL_UNBOUND");
33
+ if (admittedChannels.has(token)) throw Error("CONFIGURE_CHANNEL_CONSUMED");
34
+ admittedChannels.add(token);
35
+ if (arguments.length !== 1) throw Error("CONFIGURE_CHANNEL_UNBOUND");
36
+ const lineage = readConfigureLineage(token);
37
+ const send = journalWorkForConfigureLineage(token).captureSend();
38
+ const guard = () => {
39
+ readConfigureLineage(token);
40
+ };
41
+ const channel = createGuardedInitialStageChannel(
42
+ lineage.parentToken,
43
+ {
44
+ timeoutMs: 5000,
45
+ send(
46
+ record: Parameters<typeof send>[0],
47
+ ack: Parameters<typeof send>[1],
48
+ ) {
49
+ guard();
50
+ return send(record, (value) => {
51
+ guard();
52
+ ack(value);
53
+ guard();
54
+ });
55
+ },
56
+ },
57
+ guard,
58
+ );
59
+ return configureEventCompiler(lineage.configuration, channel);
60
+ }
61
+ function configureEventCompiler(
62
+ raw: unknown,
63
+ channel: ReturnType<typeof createStageChannel>,
64
+ ) {
22
65
  let source: ReturnType<typeof captureConfigureSource>;
23
66
  try {
24
67
  channel.gate();
@@ -3,7 +3,15 @@ import { OWNER } from "../originalOwner.js";
3
3
  import { closed, need, stop, type SourceMethod } from "./types.js";
4
4
  import { requiredJSONSnapshot } from "../material/requiredJson.js";
5
5
  import { resourceId } from "../../../renewalAggregate/shared.js";
6
- import { loadConfigureOwnedReadTransportSource } from "./sourceOperations.js";
6
+ import {
7
+ loadConfigureOwnedReadTransportSource,
8
+ COMPILED_PREFLIGHT_ENTRIES,
9
+ } from "./sourceOperations.js";
10
+ import { readConfigureLineage } from "../producer/configureLineage.js";
11
+ import { readAttachAcknowledgementForLineage } from "../producer/attachAcknowledgement.js";
12
+ import { captureInitialStockRawDelegate } from "../producer/stockDelegateFactory.js";
13
+ import { capturePreflightRecordDATA } from "../preflight/record.js";
14
+ import { object } from "../producer/configureJournalData.js";
7
15
 
8
16
  const API = "2026-09-30.endive";
9
17
  type Resource = "subscription" | "price" | "customer" | "coupon" | "schedule";
@@ -159,8 +167,15 @@ export function createConfigureOwnedReadTransport() {
159
167
  OWNER.check();
160
168
  const source = loadConfigureOwnedReadTransportSource();
161
169
  OWNER.check();
170
+ return configureReadKernel(source, OWNER);
171
+ }
172
+ function configureReadKernel(
173
+ source: unknown,
174
+ owner: typeof OWNER,
175
+ guard?: () => void,
176
+ ) {
162
177
  const frame = closed(source, ["owner", "operation", "readPlan", "delegate"]);
163
- need(frame.owner === OWNER);
178
+ need(frame.owner === owner);
164
179
  const operation = frame.operation,
165
180
  delegate = frame.delegate,
166
181
  readPlanReference = frame.readPlan,
@@ -179,7 +194,9 @@ export function createConfigureOwnedReadTransport() {
179
194
  }
180
195
  checking = true;
181
196
  try {
182
- OWNER.check();
197
+ guard?.();
198
+ owner.check();
199
+ guard?.();
183
200
  if (closedOwner) stop();
184
201
  } catch {
185
202
  closedOwner = true;
@@ -283,3 +300,131 @@ export function createConfigureOwnedReadTransport() {
283
300
  capability,
284
301
  });
285
302
  }
303
+
304
+ const admittedReads = new WeakSet<object>();
305
+ /** Fixed, qualified readonly plan and actual stock promise; no caller frame. */
306
+ export function createAdmittedConfigureReadTransport(token: object) {
307
+ need(
308
+ typeof token === "object" && token !== null && !admittedReads.has(token),
309
+ );
310
+ admittedReads.add(token);
311
+ need(arguments.length === 1);
312
+ need(
313
+ !types.isProxy(COMPILED_PREFLIGHT_ENTRIES) &&
314
+ Array.isArray(COMPILED_PREFLIGHT_ENTRIES) &&
315
+ COMPILED_PREFLIGHT_ENTRIES.length > 0,
316
+ );
317
+ const lineage = readConfigureLineage(token);
318
+ const acknowledgement = readAttachAcknowledgementForLineage(
319
+ lineage.parentToken,
320
+ );
321
+ const candidates = COMPILED_PREFLIGHT_ENTRIES.filter((entry) => {
322
+ const fields = closed(entry, ["originalEntry", "coversPreflight"]);
323
+ need(
324
+ typeof fields.coversPreflight === "function" &&
325
+ !types.isProxy(fields.coversPreflight),
326
+ );
327
+ return fields.originalEntry === acknowledgement.originalEntry;
328
+ });
329
+ need(candidates.length === 1);
330
+ const entry = candidates[0],
331
+ fields = closed(entry, ["originalEntry", "coversPreflight"]),
332
+ covers = fields.coversPreflight;
333
+ need(typeof covers === "function");
334
+ function guard() {
335
+ const current = readConfigureLineage(token);
336
+ need(
337
+ current.originalReservation === lineage.originalReservation &&
338
+ current.journal === lineage.journal &&
339
+ current.owner === lineage.owner,
340
+ );
341
+ need(
342
+ !types.isProxy(COMPILED_PREFLIGHT_ENTRIES) &&
343
+ Array.isArray(COMPILED_PREFLIGHT_ENTRIES) &&
344
+ COMPILED_PREFLIGHT_ENTRIES.includes(entry),
345
+ );
346
+ const now = closed(entry, ["originalEntry", "coversPreflight"]);
347
+ need(
348
+ now.originalEntry === acknowledgement.originalEntry &&
349
+ now.coversPreflight === covers &&
350
+ !types.isProxy(covers),
351
+ );
352
+ need(
353
+ readAttachAcknowledgementForLineage(lineage.parentToken) ===
354
+ acknowledgement,
355
+ );
356
+ }
357
+ guard();
358
+ const full = object(JSON.parse(lineage.reservation.recordJSON));
359
+ const retained = capturePreflightRecordDATA(full.configureRecord);
360
+ const expected = retained.configuration.preparation.expected;
361
+ const customer = retained.originalBundle.wireBillingCustomer.id;
362
+ need(typeof customer === "string");
363
+ const receipt = object(acknowledgement.receipt),
364
+ scheduleId = receipt.scheduleId;
365
+ need(typeof scheduleId === "string");
366
+ const rows = [
367
+ {
368
+ resource: "subscription",
369
+ path:
370
+ "/v1/subscriptions/" +
371
+ encodeURIComponent(expected.subscriptionId) +
372
+ query,
373
+ },
374
+ {
375
+ resource: "price",
376
+ path: "/v1/prices/" + encodeURIComponent(expected.targetPriceId),
377
+ },
378
+ {
379
+ resource: "customer",
380
+ path: "/v1/customers/" + encodeURIComponent(customer),
381
+ },
382
+ ...retained.originalBundle.couponReads.map((row) => {
383
+ need(typeof row.couponId === "string");
384
+ return {
385
+ resource: "coupon",
386
+ path: "/v1/coupons/" + encodeURIComponent(row.couponId),
387
+ };
388
+ }),
389
+ {
390
+ resource: "schedule",
391
+ path: "/v1/subscription_schedules/" + encodeURIComponent(scheduleId),
392
+ },
393
+ ];
394
+ const readPlan = Object.freeze(
395
+ rows.map((row, index) =>
396
+ Object.freeze({
397
+ ...row,
398
+ ordinal: index + 1,
399
+ method: "GET",
400
+ body: undefined,
401
+ options: Object.freeze({ apiVersion: API, maxNetworkRetries: 0 }),
402
+ }),
403
+ ),
404
+ );
405
+ const delegate = captureInitialStockRawDelegate(lineage.parentToken);
406
+ const pair = configureReadKernel(
407
+ { owner: lineage.owner, operation: token, readPlan, delegate },
408
+ lineage.owner,
409
+ guard,
410
+ );
411
+ need(
412
+ pair.capability.assertSourceOperationBinding(
413
+ token,
414
+ readPlan,
415
+ delegate,
416
+ delegate.rawRequest,
417
+ ),
418
+ );
419
+ need(pair.capability.reserveAcquisition());
420
+ guard();
421
+ return Object.freeze({
422
+ readTransport: pair.transport.readTransport,
423
+ guard,
424
+ entry,
425
+ covers,
426
+ acknowledgement,
427
+ retained,
428
+ scheduleId,
429
+ });
430
+ }
@@ -12,14 +12,13 @@ import type {
12
12
  ProjectedRenewalConfigurationV2,
13
13
  RenewalScheduleAttachmentReceiptV2,
14
14
  } from "../../../renewalV2/index.js";
15
- export function releasePreflight(
15
+ export function releasePreflightDATA(
16
16
  record: PreflightRecord,
17
17
  currentEvidence: CurrentEvidence,
18
18
  request: ProjectedRenewalConfigurationV2,
19
19
  originalC6: ProjectedRenewalConfigurationV2,
20
20
  ackC3: RenewalScheduleAttachmentReceiptV2,
21
21
  ): PreflightOutput {
22
- OWNER.check();
23
22
  need(
24
23
  equal(record.request, originalC6) &&
25
24
  equal(request, originalC6) &&
@@ -37,6 +36,24 @@ export function releasePreflight(
37
36
  for (const [path, value] of Object.entries(expected))
38
37
  need(captured.slots.get(path) === value);
39
38
  const output = freeze(materialize(captured.node));
40
- OWNER.check();
41
39
  return output as PreflightOutput;
42
40
  }
41
+
42
+ export function releasePreflight(
43
+ record: PreflightRecord,
44
+ currentEvidence: CurrentEvidence,
45
+ request: ProjectedRenewalConfigurationV2,
46
+ originalC6: ProjectedRenewalConfigurationV2,
47
+ ackC3: RenewalScheduleAttachmentReceiptV2,
48
+ ): PreflightOutput {
49
+ OWNER.check();
50
+ const output = releasePreflightDATA(
51
+ record,
52
+ currentEvidence,
53
+ request,
54
+ originalC6,
55
+ ackC3,
56
+ );
57
+ OWNER.check();
58
+ return output;
59
+ }