@fantastic.dev/better-stripe 0.90.0 → 0.91.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 (216) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +41 -0
  4. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +187 -0
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts +2 -23
  8. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js +1 -112
  10. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts +8 -3
  12. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js +1 -0
  14. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/acquisition/test-fixtures/sourcePort.d.mts +1 -1
  16. package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts +8 -0
  17. package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -0
  18. package/dist/client/billing/renewalAttach/internal/configure/actor.js +454 -0
  19. package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -0
  20. package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts +12 -0
  21. package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts.map +1 -0
  22. package/dist/client/billing/renewalAttach/internal/configure/capture.js +99 -0
  23. package/dist/client/billing/renewalAttach/internal/configure/capture.js.map +1 -0
  24. package/dist/client/billing/renewalAttach/internal/configure/output.d.ts +16 -0
  25. package/dist/client/billing/renewalAttach/internal/configure/output.d.ts.map +1 -0
  26. package/dist/client/billing/renewalAttach/internal/configure/output.js +274 -0
  27. package/dist/client/billing/renewalAttach/internal/configure/output.js.map +1 -0
  28. package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts +3 -0
  29. package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts.map +1 -0
  30. package/dist/client/billing/renewalAttach/internal/configure/replay.js +9 -0
  31. package/dist/client/billing/renewalAttach/internal/configure/replay.js.map +1 -0
  32. package/dist/client/billing/renewalAttach/internal/configure/request.d.ts +39 -0
  33. package/dist/client/billing/renewalAttach/internal/configure/request.d.ts.map +1 -0
  34. package/dist/client/billing/renewalAttach/internal/configure/request.js +245 -0
  35. package/dist/client/billing/renewalAttach/internal/configure/request.js.map +1 -0
  36. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +88 -0
  37. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -0
  38. package/dist/client/billing/renewalAttach/internal/configure/transport.js +289 -0
  39. package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -0
  40. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts +16 -0
  41. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -0
  42. package/dist/client/billing/renewalAttach/internal/observation/actor.js +362 -0
  43. package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -0
  44. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts +9 -0
  45. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -0
  46. package/dist/client/billing/renewalAttach/internal/observation/capture.js +215 -0
  47. package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -0
  48. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +7 -0
  49. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -0
  50. package/dist/client/billing/renewalAttach/internal/observation/profile.js +190 -0
  51. package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -0
  52. package/dist/client/billing/renewalAttach/internal/observation/record.d.ts +5 -0
  53. package/dist/client/billing/renewalAttach/internal/observation/record.d.ts.map +1 -0
  54. package/dist/client/billing/renewalAttach/internal/observation/record.js +317 -0
  55. package/dist/client/billing/renewalAttach/internal/observation/record.js.map +1 -0
  56. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +79 -0
  57. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -0
  58. package/dist/client/billing/renewalAttach/internal/observation/types.js +27 -0
  59. package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -0
  60. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +18 -0
  61. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -0
  62. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +229 -0
  63. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -0
  64. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +163 -0
  65. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -0
  66. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +443 -0
  67. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -0
  68. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +8 -0
  69. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -0
  70. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +467 -0
  71. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -0
  72. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +6 -0
  73. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -0
  74. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +59 -0
  75. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -0
  76. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts +10 -0
  77. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts.map +1 -0
  78. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js +48 -0
  79. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js.map +1 -0
  80. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +20 -0
  81. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -0
  82. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +44 -0
  83. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -0
  84. package/dist/client/billing/renewalAttach/internal/operations/types.d.ts +42 -0
  85. package/dist/client/billing/renewalAttach/internal/operations/types.d.ts.map +1 -0
  86. package/dist/client/billing/renewalAttach/internal/operations/types.js +158 -0
  87. package/dist/client/billing/renewalAttach/internal/operations/types.js.map +1 -0
  88. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts +5 -0
  89. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts.map +1 -0
  90. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js +214 -0
  91. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js.map +1 -0
  92. package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts +33 -0
  93. package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts.map +1 -0
  94. package/dist/client/billing/renewalAttach/internal/preflight/grammar.js +208 -0
  95. package/dist/client/billing/renewalAttach/internal/preflight/grammar.js.map +1 -0
  96. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +4 -0
  97. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -0
  98. package/dist/client/billing/renewalAttach/internal/preflight/output.js +25 -0
  99. package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -0
  100. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +16 -0
  101. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -0
  102. package/dist/client/billing/renewalAttach/internal/preflight/record.js +93 -0
  103. package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -0
  104. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +7 -0
  105. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -0
  106. package/dist/client/billing/renewalAttach/internal/preflight/relations.js +153 -0
  107. package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -0
  108. package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts +22 -0
  109. package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts.map +1 -0
  110. package/dist/client/billing/renewalAttach/internal/recovery/material.js +221 -0
  111. package/dist/client/billing/renewalAttach/internal/recovery/material.js.map +1 -0
  112. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +8 -0
  113. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -0
  114. package/dist/client/billing/renewalAttach/internal/recovery/output.js +101 -0
  115. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -0
  116. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +12 -0
  117. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -0
  118. package/dist/client/billing/renewalAttach/internal/recovery/record.js +186 -0
  119. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -0
  120. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +5 -0
  121. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -0
  122. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +498 -0
  123. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -0
  124. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +21 -0
  125. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -0
  126. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +119 -0
  127. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -0
  128. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  129. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  130. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  131. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  132. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  133. package/dist/component/payoutRelease/queries.d.ts +2 -2
  134. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  135. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  136. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  137. package/docs/renewal-context-reads.md +26 -8
  138. package/docs/renewal-material-observation.md +37 -0
  139. package/docs/renewal-phase-assembly.md +68 -0
  140. package/docs/renewal-raw-acquisition.md +19 -5
  141. package/package.json +1 -1
  142. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +304 -0
  143. package/src/client/billing/renewalAttach/internal/acquisition/rawAcquisition.ts +2 -160
  144. package/src/client/billing/renewalAttach/internal/acquisition/rawWireSource.ts +15 -3
  145. package/src/client/billing/renewalAttach/internal/configure/actor.ts +575 -0
  146. package/src/client/billing/renewalAttach/internal/configure/capture.ts +117 -0
  147. package/src/client/billing/renewalAttach/internal/configure/dispatch.integration.test.ts +32 -0
  148. package/src/client/billing/renewalAttach/internal/configure/limits.test.ts +510 -0
  149. package/src/client/billing/renewalAttach/internal/configure/order.integration.test.ts +207 -0
  150. package/src/client/billing/renewalAttach/internal/configure/output.ts +372 -0
  151. package/src/client/billing/renewalAttach/internal/configure/ownership.integration.test.ts +148 -0
  152. package/src/client/billing/renewalAttach/internal/configure/replay.integration.test.ts +173 -0
  153. package/src/client/billing/renewalAttach/internal/configure/replay.ts +13 -0
  154. package/src/client/billing/renewalAttach/internal/configure/request.ts +312 -0
  155. package/src/client/billing/renewalAttach/internal/configure/transport.integration.test.ts +507 -0
  156. package/src/client/billing/renewalAttach/internal/configure/transport.ts +348 -0
  157. package/src/client/billing/renewalAttach/internal/observation/actor.ts +444 -0
  158. package/src/client/billing/renewalAttach/internal/observation/capture.ts +250 -0
  159. package/src/client/billing/renewalAttach/internal/observation/observation.integration.test.ts +220 -0
  160. package/src/client/billing/renewalAttach/internal/observation/observationRetirement.integration.test.ts +60 -0
  161. package/src/client/billing/renewalAttach/internal/observation/profile.ts +264 -0
  162. package/src/client/billing/renewalAttach/internal/observation/record.ts +408 -0
  163. package/src/client/billing/renewalAttach/internal/observation/types.ts +102 -0
  164. package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +285 -0
  165. package/src/client/billing/renewalAttach/internal/operations/defaultBindings.test.ts +69 -0
  166. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +574 -0
  167. package/src/client/billing/renewalAttach/internal/operations/initialAttach.integration.test.ts +34 -0
  168. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +535 -0
  169. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +63 -0
  170. package/src/client/billing/renewalAttach/internal/operations/providerFailure.integration.test.ts +61 -0
  171. package/src/client/billing/renewalAttach/internal/operations/providerFailure.ts +66 -0
  172. package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +50 -0
  173. package/src/client/billing/renewalAttach/internal/operations/transport.integration.test.ts +116 -0
  174. package/src/client/billing/renewalAttach/internal/operations/types.ts +223 -0
  175. package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.integration.test.ts +285 -0
  176. package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.ts +258 -0
  177. package/src/client/billing/renewalAttach/internal/preflight/configureReads.integration.test.ts +139 -0
  178. package/src/client/billing/renewalAttach/internal/preflight/grammar.ts +257 -0
  179. package/src/client/billing/renewalAttach/internal/preflight/output.ts +42 -0
  180. package/src/client/billing/renewalAttach/internal/preflight/owner.integration.test.ts +82 -0
  181. package/src/client/billing/renewalAttach/internal/preflight/preflight.integration.test.ts +354 -0
  182. package/src/client/billing/renewalAttach/internal/preflight/record.ts +127 -0
  183. package/src/client/billing/renewalAttach/internal/preflight/relations.ts +209 -0
  184. package/src/client/billing/renewalAttach/internal/recovery/material.ts +311 -0
  185. package/src/client/billing/renewalAttach/internal/recovery/output.ts +136 -0
  186. package/src/client/billing/renewalAttach/internal/recovery/record.ts +230 -0
  187. package/src/client/billing/renewalAttach/internal/recovery/recovery.integration.test.ts +463 -0
  188. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +599 -0
  189. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +175 -0
  190. package/src/client/billing/renewalAttach/internal/test-fixtures/attachEntries.ts +217 -0
  191. package/src/client/billing/renewalAttach/internal/test-fixtures/attachObservations.ts +226 -0
  192. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenario.ts +556 -0
  193. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioAssertions.ts +180 -0
  194. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioBarriers.ts +144 -0
  195. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightAssertions.ts +122 -0
  196. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightBarriers.ts +330 -0
  197. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightControls.ts +139 -0
  198. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightOperation.ts +513 -0
  199. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadNativeBaseline.ts +344 -0
  200. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadOperation.ts +278 -0
  201. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadPort.ts +17 -0
  202. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +533 -0
  203. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteBarriers.ts +125 -0
  204. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +314 -0
  205. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +463 -0
  206. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteObservations.ts +515 -0
  207. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +600 -0
  208. package/src/client/billing/renewalAttach/internal/test-fixtures/observationAssertions.ts +211 -0
  209. package/src/client/billing/renewalAttach/internal/test-fixtures/observationDeclarations.ts +192 -0
  210. package/src/client/billing/renewalAttach/internal/test-fixtures/observationHTTP.ts +197 -0
  211. package/src/client/billing/renewalAttach/internal/test-fixtures/observationObservations.ts +269 -0
  212. package/src/client/billing/renewalAttach/internal/test-fixtures/observationOperation.ts +262 -0
  213. package/src/client/billing/renewalAttach/internal/test-fixtures/observationProbe.ts +319 -0
  214. package/src/client/billing/renewalAttach/internal/test-fixtures/ownedOperations.ts +94 -0
  215. package/src/client/billing/renewalAttach/internal/test-fixtures/sourceOperationPort.ts +16 -0
  216. package/src/client/billing/renewalAttach/internal/test-fixtures/stockHttp.ts +21 -0
@@ -0,0 +1,575 @@
1
+ import { types } from "node:util";
2
+ import { OWNER } from "../originalOwner.js";
3
+ import {
4
+ COMPILED_CONFIGURE_WRITE_ENTRIES as ENTRIES,
5
+ COMPILED_INITIAL_ENTRIES,
6
+ ORIGINAL_ORIGIN_ASSOCIATION,
7
+ loadFixedConfigureWriteOperation,
8
+ loadFixedConfigureReplayOperation,
9
+ } from "../operations/sourceOperations.js";
10
+ import { closed } from "../operations/types.js";
11
+ import {
12
+ projectRenewalConfigurationV2 as c6,
13
+ constructRenewalScheduleAttachmentReceiptV2 as c3,
14
+ constructRenewalConfigurationReceiptV2 as c9,
15
+ } from "../../../renewalV2/index.js";
16
+ import { equal } from "../../../renewalAggregate/shared.js";
17
+ import { capturePreflightRecord } from "../preflight/record.js";
18
+ import {
19
+ verifyPreflightRecord,
20
+ verifyCurrentPreflight,
21
+ } from "../preflight/relations.js";
22
+ import { releasePreflight } from "../preflight/output.js";
23
+ import { classifyOwnedRetainedInitialAttachment } from "../material/classifiers.js";
24
+ import { bindConfigureReadAcquisitionFromSource } from "../acquisition/ownedAcquisition.js";
25
+ import { createConfigureEventCompiler } from "../c10/configureEvents.js";
26
+ import {
27
+ createConfigureWriteTransport,
28
+ createConfigureReplayTransport,
29
+ } from "./transport.js";
30
+ import { ownMethod, need, stop, expectedPlan, seven } from "./request.js";
31
+ import {
32
+ admitConfigureACK,
33
+ admitConfigureFailure,
34
+ configureControl,
35
+ } from "./output.js";
36
+ import { withinConfigureRetention } from "./replay.js";
37
+ import type { PreflightRecord } from "../preflight/grammar.js";
38
+ import type { Bundle } from "../material/capture.js";
39
+
40
+ type Pair = ReturnType<typeof createConfigureWriteTransport>;
41
+ type Lineage = {
42
+ receiptKnown: boolean;
43
+ receiptPending: boolean;
44
+ busy: boolean;
45
+ };
46
+ type History = {
47
+ record: PreflightRecord;
48
+ owner: typeof OWNER;
49
+ basis: typeof OWNER.basis;
50
+ origin: unknown;
51
+ entry: unknown;
52
+ configureEntry: unknown;
53
+ actualAttachAcknowledgement: unknown;
54
+ lineage: Lineage;
55
+ state:
56
+ | "not_started"
57
+ | "post_pending"
58
+ | "post_unknown"
59
+ | "receipt_prepared"
60
+ | "receipt_recorded";
61
+ pair: Pair | null;
62
+ receipt?: unknown;
63
+ output?: unknown;
64
+ };
65
+ // Local actual Source identities only. JSON and public preflight output never enter this map.
66
+ const attempts = new WeakMap<object, History>(),
67
+ reserved = new WeakSet<object>();
68
+ function historyFor(value: unknown) {
69
+ return value !== null && typeof value === "object" && !types.isProxy(value)
70
+ ? attempts.get(value)
71
+ : undefined;
72
+ }
73
+ function isCurrentBundle(
74
+ value: unknown,
75
+ record: PreflightRecord,
76
+ ): value is Bundle {
77
+ return equal(value, {
78
+ ...record.originalBundle,
79
+ wireSubscription: record.configuration.freshSubscription,
80
+ });
81
+ }
82
+ /** Same original Owner subscription, with FIRST continuation guards on both outcomes. */
83
+ function owned<T>(work: () => T | PromiseLike<T>): Promise<T> {
84
+ OWNER.check();
85
+ return new Promise((resolve, reject) => {
86
+ let done = false,
87
+ remove: (() => void) | null = null;
88
+ const finish = (ok: boolean, value: unknown) => {
89
+ if (done) return;
90
+ done = true;
91
+ remove?.();
92
+ if (ok) resolve(value as T);
93
+ else reject(value);
94
+ };
95
+ const retire = () => finish(false, Error("CONFIGURE_WRITE_STOP"));
96
+ remove = OWNER.subscribe(retire);
97
+ if (done) {
98
+ remove();
99
+ return;
100
+ }
101
+ let pending: T | PromiseLike<T>;
102
+ try {
103
+ OWNER.check();
104
+ pending = work();
105
+ } catch (error) {
106
+ try {
107
+ OWNER.check();
108
+ finish(false, error);
109
+ } catch {
110
+ retire();
111
+ }
112
+ return;
113
+ }
114
+ void Promise.resolve(pending).then(
115
+ (value) => {
116
+ if (done) return;
117
+ try {
118
+ OWNER.check();
119
+ finish(true, value);
120
+ } catch {
121
+ retire();
122
+ }
123
+ },
124
+ (error) => {
125
+ if (done) return;
126
+ try {
127
+ OWNER.check();
128
+ finish(false, error);
129
+ } catch {
130
+ retire();
131
+ }
132
+ },
133
+ );
134
+ });
135
+ }
136
+ function capture(replay: boolean) {
137
+ let consumed = false;
138
+ return Object.freeze({
139
+ async invoke() {
140
+ need(arguments.length === 0 && !consumed);
141
+ consumed = true;
142
+ need(!types.isProxy(ENTRIES) && Array.isArray(ENTRIES));
143
+ if (ENTRIES.length === 0)
144
+ return configureControl(
145
+ "not_dispatched",
146
+ "no_qualified_configure_class",
147
+ );
148
+ let pair: Pair | null = null,
149
+ row: History | null = null,
150
+ actualError: Error | null = null,
151
+ dispatchEntered = false,
152
+ structuralError: unknown,
153
+ hasStructuralError = false;
154
+ const control = (
155
+ status: "not_dispatched" | "configure_unknown",
156
+ reason: string,
157
+ ) => {
158
+ if (row) row.lineage.busy = false;
159
+ return configureControl(status, reason);
160
+ };
161
+ try {
162
+ OWNER.check();
163
+ const live = replay
164
+ ? loadFixedConfigureReplayOperation()
165
+ : loadFixedConfigureWriteOperation();
166
+ OWNER.check();
167
+ need(live !== null && typeof live === "object" && !types.isProxy(live));
168
+ const op = closed(
169
+ live,
170
+ replay
171
+ ? [
172
+ "owner",
173
+ "originAssociation",
174
+ "originalEntry",
175
+ "configureEntry",
176
+ "previousOperation",
177
+ "readPlan",
178
+ "delegate",
179
+ "sink",
180
+ "reserve",
181
+ ]
182
+ : [
183
+ "owner",
184
+ "originAssociation",
185
+ "originalEntry",
186
+ "configureEntry",
187
+ "originalRecord",
188
+ "actualAttachAcknowledgement",
189
+ "readPlan",
190
+ "delegate",
191
+ "sink",
192
+ "reserve",
193
+ ],
194
+ );
195
+ need(
196
+ op.owner === OWNER &&
197
+ op.originAssociation !== null &&
198
+ typeof op.originAssociation === "object" &&
199
+ !types.isProxy(op.originAssociation) &&
200
+ op.originAssociation === ORIGINAL_ORIGIN_ASSOCIATION,
201
+ );
202
+ need(
203
+ !types.isProxy(COMPILED_INITIAL_ENTRIES) &&
204
+ Array.isArray(COMPILED_INITIAL_ENTRIES) &&
205
+ COMPILED_INITIAL_ENTRIES.includes(op.originalEntry),
206
+ );
207
+ need(
208
+ ENTRIES.includes(op.configureEntry) &&
209
+ !types.isProxy(op.configureEntry),
210
+ );
211
+ const coverage = closed(op.configureEntry, [
212
+ "originalEntry",
213
+ "coversConfigure",
214
+ ]);
215
+ need(coverage.originalEntry === op.originalEntry);
216
+ const covers = ownMethod(op.configureEntry, "coversConfigure"),
217
+ retainedPredicate = ownMethod(op.originalEntry, "coversRetained"),
218
+ rawMethod = ownMethod(op.delegate, "rawRequest"),
219
+ reserve = ownMethod(live, "reserve"),
220
+ send = ownMethod(op.sink, "send");
221
+ const prior = replay ? historyFor(op.previousOperation) : undefined;
222
+ if (replay && !prior)
223
+ return control("not_dispatched", "prior_attempt_unavailable");
224
+ const sourceRecord = prior ? prior.record : op.originalRecord;
225
+ need(!types.isProxy(sourceRecord));
226
+ const raw = closed(sourceRecord, [
227
+ "configuration",
228
+ "request",
229
+ "attachReceipt",
230
+ "originalBundle",
231
+ ]);
232
+ const actualAttachAcknowledgement = prior
233
+ ? prior.actualAttachAcknowledgement
234
+ : op.actualAttachAcknowledgement;
235
+ // Detached prior record was originally proved against this actual pointer; it is not rehydrated.
236
+ if (!prior) need(raw.attachReceipt === actualAttachAcknowledgement);
237
+ const retained = capturePreflightRecord(sourceRecord);
238
+ OWNER.check();
239
+ let original: Awaited<ReturnType<typeof c6>>;
240
+ try {
241
+ original = await owned(() => c6(retained.configuration));
242
+ } catch (error) {
243
+ OWNER.check();
244
+ structuralError = error;
245
+ hasStructuralError = true;
246
+ throw error;
247
+ }
248
+ OWNER.check();
249
+ if (original.status !== "projected_configure_request") return original;
250
+ const ack = await owned(() => c3(retained.configuration.attachReceipt));
251
+ OWNER.check();
252
+ const record = verifyPreflightRecord(retained, original, ack);
253
+ const classification = await owned(() =>
254
+ classifyOwnedRetainedInitialAttachment({
255
+ attachRequest: record.configuration.attachReceipt.attachRequest,
256
+ originalBundle: record.originalBundle,
257
+ }),
258
+ );
259
+ OWNER.check();
260
+ need(classification.status === "classified");
261
+ need(
262
+ Reflect.apply(retainedPredicate, op.originalEntry, [
263
+ classification.material,
264
+ record.originalBundle,
265
+ ]) === true,
266
+ );
267
+ OWNER.check();
268
+ const basis = OWNER.basis;
269
+ if (prior) {
270
+ need(
271
+ prior.owner === OWNER &&
272
+ prior.basis === basis &&
273
+ prior.origin === op.originAssociation &&
274
+ prior.entry === op.originalEntry &&
275
+ prior.configureEntry === op.configureEntry &&
276
+ equal(prior.record, record),
277
+ );
278
+ if (
279
+ prior.state !== "post_unknown" ||
280
+ prior.lineage.receiptKnown ||
281
+ prior.lineage.receiptPending ||
282
+ prior.lineage.busy
283
+ )
284
+ return control("not_dispatched", "prior_attempt_not_replayable");
285
+ if (
286
+ !withinConfigureRetention(
287
+ OWNER.check().nowSeconds,
288
+ record.request.firstDispatchedAt,
289
+ )
290
+ )
291
+ return control("not_dispatched", "retention_expired");
292
+ }
293
+ need(!reserved.has(live));
294
+ OWNER.check();
295
+ need(Reflect.apply(reserve, live, []) === true);
296
+ OWNER.check();
297
+ reserved.add(live);
298
+ pair = replay
299
+ ? createConfigureReplayTransport()
300
+ : createConfigureWriteTransport();
301
+ OWNER.check();
302
+ need(
303
+ pair.capability.assertSourceOperationBinding(
304
+ live,
305
+ original,
306
+ op.readPlan,
307
+ op.delegate,
308
+ rawMethod,
309
+ expectedPlan(record),
310
+ ),
311
+ );
312
+ OWNER.check();
313
+ need(pair.capability.reserveAcquisition());
314
+ OWNER.check();
315
+ const lineage = prior
316
+ ? prior.lineage
317
+ : { receiptKnown: false, receiptPending: false, busy: false };
318
+ need(!lineage.busy && !lineage.receiptKnown && !lineage.receiptPending);
319
+ lineage.busy = true;
320
+ row = {
321
+ record,
322
+ owner: OWNER,
323
+ basis,
324
+ origin: op.originAssociation,
325
+ entry: op.originalEntry,
326
+ configureEntry: op.configureEntry,
327
+ actualAttachAcknowledgement,
328
+ lineage,
329
+ state: "not_started",
330
+ pair,
331
+ };
332
+ attempts.set(live, row);
333
+ const reader = bindConfigureReadAcquisitionFromSource(
334
+ OWNER,
335
+ pair.transport.readTransport,
336
+ Object.freeze({
337
+ expected: record.configuration.preparation.expected,
338
+ scheduleId: ack.scheduleId,
339
+ }),
340
+ );
341
+ OWNER.check();
342
+ let acquired: Awaited<ReturnType<typeof reader.acquire>>;
343
+ try {
344
+ acquired = await owned(() => reader.acquire());
345
+ } catch {
346
+ OWNER.check();
347
+ const fact = pair.capability.consumeReadCatch();
348
+ if (fact) {
349
+ const failure = admitConfigureFailure(
350
+ fact.phase,
351
+ fact.resource,
352
+ fact.ordinal,
353
+ original,
354
+ fact.diagnostics,
355
+ );
356
+ actualError = Error("OWNED_CONFIGURE_PROVIDER_REJECTED");
357
+ Object.defineProperty(actualError, "failure", {
358
+ value: failure,
359
+ enumerable: false,
360
+ writable: false,
361
+ configurable: false,
362
+ });
363
+ throw actualError;
364
+ }
365
+ return stop();
366
+ }
367
+ OWNER.check();
368
+ if (!acquired.ok) {
369
+ const fact = pair.capability.consumeReadCatch();
370
+ if (fact) {
371
+ const failure = admitConfigureFailure(
372
+ fact.phase,
373
+ fact.resource,
374
+ fact.ordinal,
375
+ original,
376
+ fact.diagnostics,
377
+ );
378
+ actualError = Error("OWNED_CONFIGURE_PROVIDER_REJECTED");
379
+ Object.defineProperty(actualError, "failure", {
380
+ value: failure,
381
+ enumerable: false,
382
+ writable: false,
383
+ configurable: false,
384
+ });
385
+ throw actualError;
386
+ }
387
+ return stop();
388
+ }
389
+ if (!isCurrentBundle(acquired.bundle, record))
390
+ return control("not_dispatched", "preconfigure_baseline_changed");
391
+ const evidence = Object.freeze({
392
+ bundle: acquired.bundle,
393
+ schedule: acquired.schedule,
394
+ observedAt: acquired.observedAt,
395
+ });
396
+ try {
397
+ verifyCurrentPreflight(record, evidence);
398
+ } catch {
399
+ OWNER.check();
400
+ return control("not_dispatched", "preconfigure_baseline_changed");
401
+ }
402
+ OWNER.check();
403
+ const configuration = {
404
+ ...record.configuration,
405
+ freshSubscription: evidence.bundle.wireSubscription,
406
+ targetPrice: evidence.bundle.wireTargetPrice,
407
+ ...(Object.prototype.hasOwnProperty.call(
408
+ record.configuration,
409
+ "billingCustomer",
410
+ )
411
+ ? { billingCustomer: evidence.bundle.wireBillingCustomer }
412
+ : {}),
413
+ schedule: evidence.schedule,
414
+ observedAt: evidence.observedAt,
415
+ };
416
+ const fresh = await owned(() => c6(configuration));
417
+ OWNER.check();
418
+ if (fresh.status !== "projected_configure_request") {
419
+ row.lineage.busy = false;
420
+ return fresh;
421
+ }
422
+ need(equal(fresh, original) && equal(fresh, record.request));
423
+ need(
424
+ Reflect.apply(covers, op.configureEntry, [
425
+ record,
426
+ evidence,
427
+ fresh,
428
+ ]) === true,
429
+ );
430
+ OWNER.check();
431
+ releasePreflight(record, evidence, fresh, original, ack);
432
+ OWNER.check();
433
+ const compiler = createConfigureEventCompiler(record.configuration, {
434
+ timeoutMs: 5000,
435
+ send(event: unknown, acknowledge: unknown) {
436
+ OWNER.check();
437
+ return Reflect.apply(send, op.sink, [event, acknowledge]);
438
+ },
439
+ });
440
+ OWNER.check();
441
+ dispatchEntered = true;
442
+ await owned(() =>
443
+ compiler.dispatch({
444
+ event: "dispatch",
445
+ stage: "configure",
446
+ request: original,
447
+ }),
448
+ );
449
+ OWNER.check();
450
+ row.state = "post_pending";
451
+ const activePair = pair;
452
+ const reply = await owned(() => activePair.transport.postConfigure());
453
+ OWNER.check();
454
+ if (activePair.capability.consumeNotStarted(reply)) {
455
+ row.state = "not_started";
456
+ return control("not_dispatched", "post_not_started");
457
+ }
458
+ const disposition = activePair.transport.postDisposition();
459
+ if (
460
+ disposition !== "REJECTED" &&
461
+ disposition !== "FULFILLED_UNVERIFIED" &&
462
+ disposition !== "FULFILLED_SAFE"
463
+ )
464
+ return control("configure_unknown", "post_unverified");
465
+ row.state = "post_unknown";
466
+ const fact = activePair.capability.consumePostCatch(reply);
467
+ OWNER.check();
468
+ if (fact) {
469
+ const failure = admitConfigureFailure(
470
+ fact.phase,
471
+ fact.resource,
472
+ fact.ordinal,
473
+ original,
474
+ fact.diagnostics,
475
+ );
476
+ actualError = Error("OWNED_CONFIGURE_PROVIDER_REJECTED");
477
+ Object.defineProperty(actualError, "failure", {
478
+ value: failure,
479
+ enumerable: false,
480
+ writable: false,
481
+ configurable: false,
482
+ });
483
+ throw actualError;
484
+ }
485
+ if (reply.outcome !== "fulfilled_safe")
486
+ return control("configure_unknown", "post_unverified");
487
+ await owned(() =>
488
+ compiler.response({
489
+ event: "response",
490
+ stage: "configure",
491
+ request: original,
492
+ body: reply.body,
493
+ transport: reply.transport,
494
+ }),
495
+ );
496
+ OWNER.check();
497
+ const rawReceipt = Object.freeze({
498
+ configuration: record.configuration,
499
+ actualDispatch: seven(original),
500
+ providerSnapshot: reply.body,
501
+ transport: reply.transport,
502
+ });
503
+ const receipt = await owned(() => c9(rawReceipt));
504
+ OWNER.check();
505
+ // Actual C9 success is retained before output admission or receipt-event publication.
506
+ // This closes the whole lineage even if either later admission/publication fails.
507
+ row.receipt = receipt;
508
+ row.state = "receipt_prepared";
509
+ lineage.receiptKnown = true;
510
+ const output = admitConfigureACK(record, rawReceipt, receipt);
511
+ OWNER.check();
512
+ row.output = output;
513
+ lineage.receiptPending = true;
514
+ await owned(() =>
515
+ compiler.receipt({
516
+ event: "receipt",
517
+ stage: "configure",
518
+ request: original,
519
+ receipt,
520
+ }),
521
+ );
522
+ row.state = "receipt_recorded";
523
+ lineage.busy = false;
524
+ OWNER.check();
525
+ activePair.capability.discardFulfilledQuarantine();
526
+ return output;
527
+ } catch (error) {
528
+ let live = false;
529
+ try {
530
+ OWNER.check();
531
+ live = true;
532
+ } catch {
533
+ /* Closed Owner permits no provider reflection. */
534
+ }
535
+ if (row) {
536
+ row.lineage.busy = false;
537
+ if (live && !row.lineage.receiptKnown)
538
+ row.lineage.receiptPending = false;
539
+ }
540
+ if (live && hasStructuralError && error === structuralError)
541
+ throw error;
542
+ if (live && actualError !== null && error === actualError) throw error;
543
+ if (pair && dispatchEntered) {
544
+ const disposition = pair.transport.postDisposition();
545
+ if (disposition === "NOT_STARTED") {
546
+ if (!live) return stop();
547
+ if (row) row.state = "not_started";
548
+ return control("not_dispatched", "post_not_started");
549
+ }
550
+ if (
551
+ row &&
552
+ disposition !== "PENDING" &&
553
+ row.state !== "receipt_prepared" &&
554
+ row.state !== "receipt_recorded"
555
+ )
556
+ row.state = "post_unknown";
557
+ return control(
558
+ "configure_unknown",
559
+ live ? "post_unverified" : "owner_closed_after_post",
560
+ );
561
+ }
562
+ return stop();
563
+ }
564
+ },
565
+ });
566
+ }
567
+ /** Internal fixed zeroarg entrypoints. Normal Source registries stay EMPTY. */
568
+ export function captureOwnedConfigureV2() {
569
+ need(arguments.length === 0);
570
+ return capture(false);
571
+ }
572
+ export function captureOwnedConfigureReplayV2() {
573
+ need(arguments.length === 0);
574
+ return capture(true);
575
+ }
@@ -0,0 +1,117 @@
1
+ import { types } from "node:util";
2
+ import { rejectProxyJSON } from "../acquisition/rawWireSource.js";
3
+ import { requiredJSONSnapshot } from "../material/requiredJson.js";
4
+ import { freeze } from "../material/nodeKernel.js";
5
+ import { need } from "./request.js";
6
+ import type { Diagnostics } from "../operations/providerFailure.js";
7
+ const responsePrototype = Response.prototype;
8
+ const statusGetter = Object.getOwnPropertyDescriptor(
9
+ responsePrototype,
10
+ "status",
11
+ )!.get!;
12
+
13
+ /** Owner gating is supplied by the actual pair before this DATA capture. */
14
+ export function captureConfigureReply(raw: unknown) {
15
+ rejectProxyJSON(raw, true);
16
+ need(raw !== null && typeof raw === "object" && !Array.isArray(raw));
17
+ const proto = Object.getPrototypeOf(raw);
18
+ need(proto === Object.prototype || proto === null);
19
+ const descriptor = Object.getOwnPropertyDescriptor(raw, "lastResponse");
20
+ need(
21
+ descriptor &&
22
+ !descriptor.enumerable &&
23
+ "value" in descriptor &&
24
+ descriptor.value !== null &&
25
+ typeof descriptor.value === "object" &&
26
+ !types.isProxy(descriptor.value),
27
+ );
28
+ const meta: object = descriptor.value,
29
+ codes: unknown[] = [];
30
+ for (const key of ["status", "statusCode"]) {
31
+ const d = Object.getOwnPropertyDescriptor(meta, key);
32
+ if (d) {
33
+ need("value" in d);
34
+ if (d.value !== undefined) codes.push(d.value);
35
+ }
36
+ }
37
+ if (Object.getPrototypeOf(meta) === responsePrototype)
38
+ codes.push(Reflect.apply(statusGetter, meta, []));
39
+ need(
40
+ codes.length > 0 &&
41
+ codes.every(
42
+ (x) =>
43
+ typeof x === "number" &&
44
+ Number.isInteger(x) &&
45
+ x >= 200 &&
46
+ x < 300 &&
47
+ x === codes[0],
48
+ ),
49
+ );
50
+ const status = codes[0];
51
+ need(typeof status === "number");
52
+ const entries: [string, unknown][] = [];
53
+ for (const key of Reflect.ownKeys(raw)) {
54
+ need(typeof key === "string");
55
+ if (key === "lastResponse") continue;
56
+ const d = Object.getOwnPropertyDescriptor(raw, key);
57
+ need(d && d.enumerable && "value" in d);
58
+ entries.push([key, d.value]);
59
+ }
60
+ const body = requiredJSONSnapshot(Object.fromEntries(entries));
61
+ need(body !== null && typeof body === "object" && !Array.isArray(body));
62
+ const d = Object.getOwnPropertyDescriptor(meta, "requestId");
63
+ let requestId: string | undefined;
64
+ if (d) {
65
+ need("value" in d);
66
+ if (d.value !== undefined) {
67
+ need(
68
+ typeof d.value === "string" &&
69
+ d.value.length >= 1 &&
70
+ d.value.length <= 255,
71
+ );
72
+ requiredJSONSnapshot(d.value);
73
+ requestId = d.value;
74
+ }
75
+ }
76
+ return freeze({
77
+ body: body as Record<string, unknown>,
78
+ transport: { status, ...(requestId === undefined ? {} : { requestId }) },
79
+ });
80
+ }
81
+ /** Read own DATA only after actual live catch. Unsafe optional diagnostics are omitted. */
82
+ export function configureDiagnostics(raw: unknown): Diagnostics {
83
+ const result: {
84
+ type?: string;
85
+ code?: string;
86
+ statusCode?: number;
87
+ requestId?: string;
88
+ } = {};
89
+ if (raw === null || typeof raw !== "object" || types.isProxy(raw))
90
+ return Object.freeze(result);
91
+ for (const key of ["type", "code", "statusCode", "requestId"] as const) {
92
+ const d = Object.getOwnPropertyDescriptor(raw, key);
93
+ if (!d || !("value" in d)) continue;
94
+ const value: unknown = d.value;
95
+ if (key === "statusCode") {
96
+ if (
97
+ typeof value === "number" &&
98
+ Number.isInteger(value) &&
99
+ value >= 100 &&
100
+ value <= 599
101
+ )
102
+ result[key] = value;
103
+ } else if (
104
+ typeof value === "string" &&
105
+ value.length >= 1 &&
106
+ value.length <= 255
107
+ ) {
108
+ try {
109
+ requiredJSONSnapshot(value);
110
+ result[key] = value;
111
+ } catch {
112
+ /* Unsafe diagnostics do not change actual catch identity. */
113
+ }
114
+ }
115
+ }
116
+ return Object.freeze(result);
117
+ }