@fantastic.dev/better-stripe 0.90.0 → 0.92.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 (239) 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 +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 +14 -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 +444 -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/ownedContinuation.d.ts +3 -0
  29. package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts.map +1 -0
  30. package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js +61 -0
  31. package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js.map +1 -0
  32. package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts +3 -0
  33. package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts.map +1 -0
  34. package/dist/client/billing/renewalAttach/internal/configure/replay.js +9 -0
  35. package/dist/client/billing/renewalAttach/internal/configure/replay.js.map +1 -0
  36. package/dist/client/billing/renewalAttach/internal/configure/request.d.ts +39 -0
  37. package/dist/client/billing/renewalAttach/internal/configure/request.d.ts.map +1 -0
  38. package/dist/client/billing/renewalAttach/internal/configure/request.js +245 -0
  39. package/dist/client/billing/renewalAttach/internal/configure/request.js.map +1 -0
  40. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +88 -0
  41. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -0
  42. package/dist/client/billing/renewalAttach/internal/configure/transport.js +289 -0
  43. package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -0
  44. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts +16 -0
  45. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -0
  46. package/dist/client/billing/renewalAttach/internal/observation/actor.js +383 -0
  47. package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -0
  48. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts +9 -0
  49. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -0
  50. package/dist/client/billing/renewalAttach/internal/observation/capture.js +216 -0
  51. package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -0
  52. package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts +5 -0
  53. package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts.map +1 -0
  54. package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js +11 -0
  55. package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js.map +1 -0
  56. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +7 -0
  57. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -0
  58. package/dist/client/billing/renewalAttach/internal/observation/profile.js +190 -0
  59. package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -0
  60. package/dist/client/billing/renewalAttach/internal/observation/record.d.ts +5 -0
  61. package/dist/client/billing/renewalAttach/internal/observation/record.d.ts.map +1 -0
  62. package/dist/client/billing/renewalAttach/internal/observation/record.js +317 -0
  63. package/dist/client/billing/renewalAttach/internal/observation/record.js.map +1 -0
  64. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +84 -0
  65. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -0
  66. package/dist/client/billing/renewalAttach/internal/observation/types.js +27 -0
  67. package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -0
  68. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +18 -0
  69. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -0
  70. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +229 -0
  71. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -0
  72. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +163 -0
  73. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -0
  74. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +443 -0
  75. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -0
  76. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +8 -0
  77. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -0
  78. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +467 -0
  79. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -0
  80. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +6 -0
  81. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -0
  82. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +59 -0
  83. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -0
  84. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts +10 -0
  85. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts.map +1 -0
  86. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js +48 -0
  87. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js.map +1 -0
  88. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +20 -0
  89. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -0
  90. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +44 -0
  91. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -0
  92. package/dist/client/billing/renewalAttach/internal/operations/types.d.ts +42 -0
  93. package/dist/client/billing/renewalAttach/internal/operations/types.d.ts.map +1 -0
  94. package/dist/client/billing/renewalAttach/internal/operations/types.js +158 -0
  95. package/dist/client/billing/renewalAttach/internal/operations/types.js.map +1 -0
  96. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts +5 -0
  97. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts.map +1 -0
  98. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js +214 -0
  99. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js.map +1 -0
  100. package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts +33 -0
  101. package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts.map +1 -0
  102. package/dist/client/billing/renewalAttach/internal/preflight/grammar.js +208 -0
  103. package/dist/client/billing/renewalAttach/internal/preflight/grammar.js.map +1 -0
  104. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +4 -0
  105. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -0
  106. package/dist/client/billing/renewalAttach/internal/preflight/output.js +25 -0
  107. package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -0
  108. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +16 -0
  109. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -0
  110. package/dist/client/billing/renewalAttach/internal/preflight/record.js +93 -0
  111. package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -0
  112. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +7 -0
  113. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -0
  114. package/dist/client/billing/renewalAttach/internal/preflight/relations.js +153 -0
  115. package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -0
  116. package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts +22 -0
  117. package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts.map +1 -0
  118. package/dist/client/billing/renewalAttach/internal/recovery/material.js +221 -0
  119. package/dist/client/billing/renewalAttach/internal/recovery/material.js.map +1 -0
  120. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +8 -0
  121. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -0
  122. package/dist/client/billing/renewalAttach/internal/recovery/output.js +101 -0
  123. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -0
  124. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +12 -0
  125. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -0
  126. package/dist/client/billing/renewalAttach/internal/recovery/record.js +186 -0
  127. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -0
  128. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +5 -0
  129. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -0
  130. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +498 -0
  131. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -0
  132. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +21 -0
  133. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -0
  134. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +119 -0
  135. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -0
  136. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  137. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
  138. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  139. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  140. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  141. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  142. package/docs/renewal-context-reads.md +26 -8
  143. package/docs/renewal-material-observation.md +58 -0
  144. package/docs/renewal-phase-assembly.md +68 -0
  145. package/docs/renewal-raw-acquisition.md +19 -5
  146. package/package.json +1 -1
  147. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +304 -0
  148. package/src/client/billing/renewalAttach/internal/acquisition/rawAcquisition.ts +2 -160
  149. package/src/client/billing/renewalAttach/internal/acquisition/rawWireSource.ts +15 -3
  150. package/src/client/billing/renewalAttach/internal/configure/actor.ts +586 -0
  151. package/src/client/billing/renewalAttach/internal/configure/capture.ts +117 -0
  152. package/src/client/billing/renewalAttach/internal/configure/dispatch.integration.test.ts +32 -0
  153. package/src/client/billing/renewalAttach/internal/configure/limits.test.ts +510 -0
  154. package/src/client/billing/renewalAttach/internal/configure/order.integration.test.ts +207 -0
  155. package/src/client/billing/renewalAttach/internal/configure/output.ts +372 -0
  156. package/src/client/billing/renewalAttach/internal/configure/ownedContinuation.ts +56 -0
  157. package/src/client/billing/renewalAttach/internal/configure/ownership.integration.test.ts +148 -0
  158. package/src/client/billing/renewalAttach/internal/configure/replay.integration.test.ts +173 -0
  159. package/src/client/billing/renewalAttach/internal/configure/replay.ts +13 -0
  160. package/src/client/billing/renewalAttach/internal/configure/request.ts +312 -0
  161. package/src/client/billing/renewalAttach/internal/configure/transport.integration.test.ts +507 -0
  162. package/src/client/billing/renewalAttach/internal/configure/transport.ts +348 -0
  163. package/src/client/billing/renewalAttach/internal/observation/actor.ts +487 -0
  164. package/src/client/billing/renewalAttach/internal/observation/capture.ts +251 -0
  165. package/src/client/billing/renewalAttach/internal/observation/configureAcknowledgement.ts +20 -0
  166. package/src/client/billing/renewalAttach/internal/observation/observation.integration.test.ts +220 -0
  167. package/src/client/billing/renewalAttach/internal/observation/observationConfigureACK.integration.test.ts +36 -0
  168. package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKControls.integration.test.ts +48 -0
  169. package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKLifecycle.integration.test.ts +44 -0
  170. package/src/client/billing/renewalAttach/internal/observation/observationConfiguredHistory.integration.test.ts +34 -0
  171. package/src/client/billing/renewalAttach/internal/observation/observationRetirement.integration.test.ts +60 -0
  172. package/src/client/billing/renewalAttach/internal/observation/profile.ts +264 -0
  173. package/src/client/billing/renewalAttach/internal/observation/record.ts +408 -0
  174. package/src/client/billing/renewalAttach/internal/observation/types.ts +107 -0
  175. package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +285 -0
  176. package/src/client/billing/renewalAttach/internal/operations/defaultBindings.test.ts +69 -0
  177. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +574 -0
  178. package/src/client/billing/renewalAttach/internal/operations/initialAttach.integration.test.ts +34 -0
  179. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +535 -0
  180. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +63 -0
  181. package/src/client/billing/renewalAttach/internal/operations/providerFailure.integration.test.ts +61 -0
  182. package/src/client/billing/renewalAttach/internal/operations/providerFailure.ts +66 -0
  183. package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +50 -0
  184. package/src/client/billing/renewalAttach/internal/operations/transport.integration.test.ts +116 -0
  185. package/src/client/billing/renewalAttach/internal/operations/types.ts +223 -0
  186. package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.integration.test.ts +285 -0
  187. package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.ts +258 -0
  188. package/src/client/billing/renewalAttach/internal/preflight/configureReads.integration.test.ts +139 -0
  189. package/src/client/billing/renewalAttach/internal/preflight/grammar.ts +257 -0
  190. package/src/client/billing/renewalAttach/internal/preflight/output.ts +42 -0
  191. package/src/client/billing/renewalAttach/internal/preflight/owner.integration.test.ts +82 -0
  192. package/src/client/billing/renewalAttach/internal/preflight/preflight.integration.test.ts +354 -0
  193. package/src/client/billing/renewalAttach/internal/preflight/record.ts +127 -0
  194. package/src/client/billing/renewalAttach/internal/preflight/relations.ts +209 -0
  195. package/src/client/billing/renewalAttach/internal/recovery/material.ts +311 -0
  196. package/src/client/billing/renewalAttach/internal/recovery/output.ts +136 -0
  197. package/src/client/billing/renewalAttach/internal/recovery/record.ts +230 -0
  198. package/src/client/billing/renewalAttach/internal/recovery/recovery.integration.test.ts +463 -0
  199. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +599 -0
  200. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +175 -0
  201. package/src/client/billing/renewalAttach/internal/test-fixtures/attachEntries.ts +217 -0
  202. package/src/client/billing/renewalAttach/internal/test-fixtures/attachObservations.ts +226 -0
  203. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenario.ts +556 -0
  204. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioAssertions.ts +180 -0
  205. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioBarriers.ts +144 -0
  206. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightAssertions.ts +122 -0
  207. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightBarriers.ts +330 -0
  208. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightControls.ts +139 -0
  209. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightOperation.ts +513 -0
  210. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadNativeBaseline.ts +344 -0
  211. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadOperation.ts +278 -0
  212. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadPort.ts +17 -0
  213. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +537 -0
  214. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteBarriers.ts +125 -0
  215. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +325 -0
  216. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDelegate.ts +38 -0
  217. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +471 -0
  218. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteObservations.ts +515 -0
  219. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +587 -0
  220. package/src/client/billing/renewalAttach/internal/test-fixtures/observationAssertions.ts +211 -0
  221. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKAssertions.ts +115 -0
  222. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKDeclarations.ts +141 -0
  223. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleAssertions.ts +74 -0
  224. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleDeclarations.ts +79 -0
  225. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleInstrumentation.ts +207 -0
  226. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleOperation.ts +494 -0
  227. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKOperation.ts +452 -0
  228. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryAssertions.ts +88 -0
  229. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryDeclarations.ts +170 -0
  230. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryNative.ts +99 -0
  231. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryOperation.ts +411 -0
  232. package/src/client/billing/renewalAttach/internal/test-fixtures/observationDeclarations.ts +192 -0
  233. package/src/client/billing/renewalAttach/internal/test-fixtures/observationHTTP.ts +197 -0
  234. package/src/client/billing/renewalAttach/internal/test-fixtures/observationObservations.ts +269 -0
  235. package/src/client/billing/renewalAttach/internal/test-fixtures/observationOperation.ts +262 -0
  236. package/src/client/billing/renewalAttach/internal/test-fixtures/observationProbe.ts +319 -0
  237. package/src/client/billing/renewalAttach/internal/test-fixtures/ownedOperations.ts +94 -0
  238. package/src/client/billing/renewalAttach/internal/test-fixtures/sourceOperationPort.ts +16 -0
  239. package/src/client/billing/renewalAttach/internal/test-fixtures/stockHttp.ts +21 -0
@@ -0,0 +1,599 @@
1
+ import { sevenWire } from "../c10/ownData.js";
2
+ import { types } from "node:util";
3
+ import { OWNER } from "../originalOwner.js";
4
+ import {
5
+ prepareRenewalPriceReplacementV2 as c1,
6
+ prepareRenewalScheduleAttachmentV2 as c2,
7
+ constructRenewalScheduleAttachmentReceiptV2 as c3,
8
+ } from "../../../renewalV2/index.js";
9
+ import { classifyOwnedRetainedInitialAttachment } from "../material/classifiers.js";
10
+ import {
11
+ captureRetainedInput,
12
+ captureOwnedInput,
13
+ } from "../material/capture.js";
14
+ import { validateOwnedReadMaterial } from "../material/readMaterial.js";
15
+ import {
16
+ closed,
17
+ type AttachRequest,
18
+ type SourceMethod,
19
+ type FailureControl,
20
+ } from "../operations/types.js";
21
+ import { equal } from "../../../renewalAggregate/shared.js";
22
+ import { owned } from "../operations/ownedAwait.js";
23
+ import type { Diagnostics } from "../operations/providerFailure.js";
24
+ import { bindRawAcquisitionFromSource } from "../acquisition/ownedAcquisition.js";
25
+ import { createAttachEventCompiler } from "../c10/attachEvents.js";
26
+ import {
27
+ COMPILED_RECOVERY_ENTRIES as ENTRIES,
28
+ loadFixedExplicitRecoveryOperation,
29
+ ORIGINAL_ORIGIN_ASSOCIATION,
30
+ } from "../operations/sourceOperations.js";
31
+ import { createRecoveryOwnedTransportWithAttemptCapability as createPair } from "../operations/fixedTransport.js";
32
+ import { captureRecoveryRecord, verifyRecoveryRecord } from "./record.js";
33
+ import { replayCouponEligibility } from "./relation.js";
34
+ import { admitRecoveryOutput } from "./output.js";
35
+ import { admitReplayMaterial, assertReplayMaterial } from "./material.js";
36
+
37
+ type Pair = ReturnType<typeof createPair>;
38
+
39
+ function sourceMethod(object: unknown, name: string): SourceMethod {
40
+ need(object !== null && typeof object === "object" && !types.isProxy(object));
41
+ const d = Object.getOwnPropertyDescriptor(object, name);
42
+ need(
43
+ d &&
44
+ d.enumerable &&
45
+ "value" in d &&
46
+ typeof d.value === "function" &&
47
+ !types.isProxy(d.value),
48
+ );
49
+ return d.value as SourceMethod;
50
+ }
51
+ const stop = (): never => {
52
+ throw Error("INITIAL_ACTOR_STOP");
53
+ };
54
+ function need(value: unknown): asserts value {
55
+ if (!value) stop();
56
+ }
57
+
58
+ const kind = "EXPLICIT_ATTACH_RECOVERY_V2_DATA_ONLY";
59
+ const refuse = (reason: string) =>
60
+ Object.freeze({
61
+ kind,
62
+ status: "not_dispatched",
63
+ reason,
64
+ operationalAuthority: false,
65
+ });
66
+ /** Explicit recovery retains one record and class relation; it never replaces the initial pair. */
67
+ export function captureOwnedExplicitAttachRecoveryV2() {
68
+ need(arguments.length === 0);
69
+ let consumed = false;
70
+ return Object.freeze({
71
+ async invoke() {
72
+ need(arguments.length === 0);
73
+ if (consumed) return refuse("invocation_consumed");
74
+ consumed = true;
75
+ need(!types.isProxy(ENTRIES) && Array.isArray(ENTRIES));
76
+ if (ENTRIES.length === 0) return refuse("no_qualified_recovery_class");
77
+ let pair: Pair | null = null,
78
+ failureControl: FailureControl | null = null,
79
+ postEligible = false;
80
+ const uncertain = () => {
81
+ need(pair);
82
+ const state = pair.transport.postDisposition();
83
+ need(state === "FULFILLED_SAFE" || state === "FULFILLED_UNVERIFIED");
84
+ const q =
85
+ failureControl === null ? null : failureControl.takePostQuarantine();
86
+ return Object.freeze({
87
+ kind,
88
+ status: "fulfilled_unverified",
89
+ operationalAuthority: false,
90
+ ...(q === null ? {} : { quarantine: q }),
91
+ });
92
+ };
93
+ try {
94
+ OWNER.check();
95
+ const live = loadFixedExplicitRecoveryOperation();
96
+ OWNER.check();
97
+ if (live === null) return refuse("recovery_source_unbound");
98
+ const op = closed(live, [
99
+ "owner",
100
+ "originAssociation",
101
+ "originalEntry",
102
+ "originalRecord",
103
+ "readPlan",
104
+ "delegate",
105
+ "sink",
106
+ "reserve",
107
+ ]);
108
+ need(
109
+ op.owner === OWNER &&
110
+ op.originAssociation !== null &&
111
+ typeof op.originAssociation === "object" &&
112
+ !types.isProxy(op.originAssociation) &&
113
+ op.originAssociation === ORIGINAL_ORIGIN_ASSOCIATION,
114
+ );
115
+ const reserve = sourceMethod(live, "reserve"),
116
+ retainedPredicate = sourceMethod(op.originalEntry, "coversRetained");
117
+ const relations: { raw: unknown; predicate: SourceMethod }[] = [];
118
+ for (const candidate of ENTRIES) {
119
+ OWNER.check();
120
+ const r = closed(candidate, ["originalEntry", "coversReplay"]);
121
+ if (r.originalEntry === op.originalEntry)
122
+ relations.push({
123
+ raw: candidate,
124
+ predicate: sourceMethod(candidate, "coversReplay"),
125
+ });
126
+ OWNER.check();
127
+ }
128
+ if (relations.length !== 1) return refuse("replay_coverage_missing");
129
+ const relation = relations[0];
130
+ OWNER.check();
131
+ const reservation = Reflect.apply(reserve, live, [
132
+ OWNER,
133
+ op.originAssociation,
134
+ op.originalEntry,
135
+ ]);
136
+ OWNER.check();
137
+ need(
138
+ reservation !== null &&
139
+ typeof reservation === "object" &&
140
+ !types.isProxy(reservation),
141
+ );
142
+ // The cached record, reconstructed values and replay classifier remain invocation-local.
143
+ const capturedRecord = captureRecoveryRecord(op.originalRecord);
144
+ OWNER.check();
145
+ const original = captureRetainedInput(capturedRecord.originalRaw),
146
+ raw = original.attachRequest;
147
+ OWNER.check();
148
+ const prepared = await owned(() => c1(raw.preparation));
149
+ OWNER.check();
150
+ const request = await owned(() =>
151
+ c2({
152
+ prepared,
153
+ apiVersion: raw.apiVersion,
154
+ attachKey: raw.attachKey,
155
+ firstDispatchedAt: raw.firstDispatchedAt,
156
+ }),
157
+ );
158
+ OWNER.check();
159
+ const retained = await owned(() =>
160
+ classifyOwnedRetainedInitialAttachment(original),
161
+ );
162
+ OWNER.check();
163
+ if (retained.status !== "classified")
164
+ return refuse("replay_material_unsupported");
165
+ verifyRecoveryRecord(
166
+ capturedRecord,
167
+ prepared,
168
+ request,
169
+ retained.material,
170
+ original,
171
+ );
172
+ OWNER.check();
173
+ const coveredRetained = Reflect.apply(
174
+ retainedPredicate,
175
+ op.originalEntry,
176
+ [retained.material, original.originalBundle],
177
+ );
178
+ OWNER.check();
179
+ if (coveredRetained !== true) return refuse("replay_coverage_missing");
180
+ OWNER.check();
181
+ pair = createPair();
182
+ OWNER.check();
183
+ need(
184
+ pair.capability.assertSourceOperationBinding(
185
+ live,
186
+ request,
187
+ op.readPlan,
188
+ op.delegate,
189
+ ),
190
+ );
191
+ OWNER.check();
192
+ const activePair = pair;
193
+
194
+ // Only this invocation's pair and actual locally rebuilt C2 enter this capsule.
195
+ const control = (() => {
196
+ const capability = activePair.capability,
197
+ takeQuarantine = capability.takeFulfilledQuarantine;
198
+ Object.freeze(request.payload);
199
+ Object.freeze(request.requestIdentity);
200
+ Object.freeze(request);
201
+ OWNER.check();
202
+ type Token = {
203
+ invocation: object;
204
+ phase: "read" | "post";
205
+ ordinal: number;
206
+ request: AttachRequest;
207
+ diagnostics: Diagnostics;
208
+ };
209
+ const tokens = new WeakMap<object, Token>(),
210
+ invocation = Object.freeze({});
211
+ let phase = "unused";
212
+ const tokenValue = (error: unknown) =>
213
+ error !== null &&
214
+ (typeof error === "object" || typeof error === "function")
215
+ ? tokens.get(error)
216
+ : undefined;
217
+ function consume(error: unknown, kind: "read" | "post") {
218
+ OWNER.check();
219
+ const value = tokenValue(error);
220
+ if (
221
+ error !== null &&
222
+ (typeof error === "object" || typeof error === "function")
223
+ )
224
+ tokens.delete(error);
225
+ if (
226
+ !value ||
227
+ value.invocation !== invocation ||
228
+ value.phase !== kind ||
229
+ phase !== (kind === "read" ? "failed" : "failed_post")
230
+ )
231
+ return null;
232
+ phase = kind === "read" ? "consumed" : "consumed_post";
233
+ const failure = Object.freeze({
234
+ category: "provider_rejected",
235
+ phase: kind,
236
+ ordinal: value.ordinal,
237
+ request: value.request,
238
+ diagnostics: value.diagnostics,
239
+ outcome: "unknown",
240
+ operationalAuthority: false,
241
+ });
242
+ const out = Error("INITIAL_PROVIDER_REJECTED");
243
+ Object.defineProperty(out, "failure", {
244
+ value: failure,
245
+ enumerable: false,
246
+ writable: false,
247
+ configurable: false,
248
+ });
249
+ return out;
250
+ }
251
+ return Object.freeze({
252
+ takePostQuarantine(...args: unknown[]) {
253
+ if (args.length !== 0) return null;
254
+ return Reflect.apply(takeQuarantine, capability, []) as
255
+ object | null;
256
+ },
257
+ begin() {
258
+ OWNER.check();
259
+ if (phase !== "unused") stop();
260
+ if (capability.assertVirginAcquisition() !== true) {
261
+ phase = "closed";
262
+ stop();
263
+ }
264
+ OWNER.check();
265
+ phase = "acquiring";
266
+ },
267
+ complete() {
268
+ OWNER.check();
269
+ if (phase !== "acquiring") stop();
270
+ phase = "complete";
271
+ },
272
+ takeReadFailure() {
273
+ OWNER.check();
274
+ if (phase !== "acquiring") stop();
275
+ const record = capability.consumeReadCatch();
276
+ OWNER.check();
277
+ if (record === null) {
278
+ phase = "unsupported";
279
+ return null;
280
+ }
281
+ need(
282
+ record.phase === "read" &&
283
+ Number.isSafeInteger(record.ordinal) &&
284
+ record.ordinal >= 1 &&
285
+ record.ordinal <= 43,
286
+ );
287
+ const token = Object.freeze(Object.create(null)) as object;
288
+ tokens.set(
289
+ token,
290
+ Object.freeze({
291
+ invocation,
292
+ phase: "read",
293
+ ordinal: record.ordinal,
294
+ request,
295
+ diagnostics: record.diagnostics,
296
+ }),
297
+ );
298
+ phase = "failed";
299
+ return token;
300
+ },
301
+ beginPost() {
302
+ OWNER.check();
303
+ if (phase !== "complete") stop();
304
+ phase = "posting";
305
+ },
306
+ takePostFailure(actualReply: unknown) {
307
+ OWNER.check();
308
+ if (phase !== "posting") stop();
309
+ const record = capability.consumePostCatch(actualReply);
310
+ OWNER.check();
311
+ if (record === null) {
312
+ phase = "post_without_token";
313
+ return null;
314
+ }
315
+ need(
316
+ record.phase === "post" &&
317
+ Number.isSafeInteger(record.ordinal) &&
318
+ record.ordinal >= 1 &&
319
+ record.ordinal <= 44,
320
+ );
321
+ const token = Object.freeze(Object.create(null)) as object;
322
+ tokens.set(
323
+ token,
324
+ Object.freeze({
325
+ invocation,
326
+ phase: "post",
327
+ ordinal: record.ordinal,
328
+ request,
329
+ diagnostics: record.diagnostics,
330
+ }),
331
+ );
332
+ phase = "failed_post";
333
+ return token;
334
+ },
335
+ forward(error: unknown) {
336
+ OWNER.check();
337
+ const value = tokenValue(error);
338
+ return value &&
339
+ value.invocation === invocation &&
340
+ (phase === "failed" || phase === "failed_post")
341
+ ? (error as object)
342
+ : null;
343
+ },
344
+ consume(error: unknown) {
345
+ return consume(error, "read");
346
+ },
347
+ consumePost(error: unknown) {
348
+ return consume(error, "post");
349
+ },
350
+ });
351
+ })();
352
+ OWNER.check();
353
+ failureControl = control;
354
+ const reader = bindRawAcquisitionFromSource(
355
+ OWNER,
356
+ activePair.transport.readTransport,
357
+ );
358
+ OWNER.check();
359
+ let acquiredOnce = false;
360
+ const acquire = async () => {
361
+ OWNER.check();
362
+ if (acquiredOnce) stop();
363
+ acquiredOnce = true;
364
+ control.begin();
365
+ OWNER.check();
366
+ const result = await reader.acquire(prepared.expected);
367
+ OWNER.check();
368
+ if (result.ok) {
369
+ control.complete();
370
+ return result;
371
+ }
372
+ const token = control.takeReadFailure();
373
+ OWNER.check();
374
+ if (token !== null) throw token;
375
+ return result;
376
+ };
377
+ const acquired = await owned(acquire, control);
378
+ OWNER.check();
379
+ if (!acquired.ok) return refuse("current_read_unsupported");
380
+
381
+ const classifyReplay = async () => {
382
+ OWNER.check();
383
+ const value = captureOwnedInput({
384
+ attachRequest: raw,
385
+ originalBundle: original.originalBundle,
386
+ currentBundle: acquired.bundle,
387
+ observedAt: acquired.observedAt,
388
+ });
389
+ OWNER.check();
390
+ need(
391
+ equal(capturedRecord.originalRaw, {
392
+ attachRequest: value.attachRequest,
393
+ originalBundle: value.originalBundle,
394
+ }),
395
+ );
396
+ const replayPrepared = await c1(value.attachRequest.preparation);
397
+ OWNER.check();
398
+ const replayRequest = await c2({
399
+ prepared: replayPrepared,
400
+ apiVersion: raw.apiVersion,
401
+ attachKey: raw.attachKey,
402
+ firstDispatchedAt: raw.firstDispatchedAt,
403
+ });
404
+ OWNER.check();
405
+ const replayRetained =
406
+ await classifyOwnedRetainedInitialAttachment(original);
407
+ OWNER.check();
408
+ need(replayRetained.status === "classified");
409
+ verifyRecoveryRecord(
410
+ capturedRecord,
411
+ replayPrepared,
412
+ replayRequest,
413
+ replayRetained.material,
414
+ original,
415
+ );
416
+ OWNER.check();
417
+ const discounts = replayCouponEligibility(value),
418
+ current = value.currentBundle,
419
+ observedAt = value.observedAt;
420
+ // Historical original eligibility; never fabricate a current-null subscription.
421
+ const reads = validateOwnedReadMaterial(
422
+ {
423
+ apiVersion: raw.apiVersion,
424
+ observedAt,
425
+ freshSubscription: value.originalBundle.wireSubscription,
426
+ targetPrice: current.wireTargetPrice,
427
+ billingCustomer: current.wireBillingCustomer,
428
+ },
429
+ replayPrepared,
430
+ undefined,
431
+ discounts,
432
+ );
433
+ OWNER.check();
434
+ const item = current.wireSubscription.items.data[0];
435
+ const material = {
436
+ classificationRevision: "renewal-material-v2",
437
+ protocolRevision: "renewal-stage-protocol-v1",
438
+ stage: "attach",
439
+ intent: "replay_unknown",
440
+ scope: replayRequest.scope,
441
+ apiVersion: replayRequest.apiVersion,
442
+ profile: reads.profile,
443
+ quantity: replayPrepared.quantity,
444
+ currentPrice: reads.item.price,
445
+ targetPrice: current.wireTargetPrice,
446
+ source: current.wireSubscription,
447
+ nativeItem: item,
448
+ billingCustomer: current.wireBillingCustomer,
449
+ subscriptionDiscounts: reads.discounts,
450
+ itemDiscounts: reads.itemDiscounts,
451
+ settings: reads.originalSettings,
452
+ originalPrepared: replayPrepared,
453
+ completeRequest: replayRequest,
454
+ stageEvidence: {
455
+ actualFreshSubscription: current.wireSubscription,
456
+ historicalOriginalSubscription:
457
+ value.originalBundle.wireSubscription,
458
+ },
459
+ rawSources: {
460
+ attachRequest: raw,
461
+ intent: "replay_unknown",
462
+ freshSubscription: current.wireSubscription,
463
+ targetPrice: current.wireTargetPrice,
464
+ billingCustomer: current.wireBillingCustomer,
465
+ observedAt,
466
+ },
467
+ freshness: "fresh",
468
+ };
469
+ OWNER.check();
470
+ const result = admitReplayMaterial(
471
+ material,
472
+ replayPrepared,
473
+ replayRequest,
474
+ );
475
+ OWNER.check();
476
+ return result;
477
+ };
478
+ const replay = await owned(() => classifyReplay().catch(() => null));
479
+ OWNER.check();
480
+ if (replay === null) return refuse("replay_material_unsupported");
481
+ const covered = Reflect.apply(relation.predicate, relation.raw, [
482
+ replay.material,
483
+ original.originalBundle,
484
+ acquired.bundle,
485
+ ]);
486
+ OWNER.check();
487
+ if (covered !== true) return refuse("replay_coverage_missing");
488
+ assertReplayMaterial(
489
+ replay.material,
490
+ prepared,
491
+ request,
492
+ raw,
493
+ acquired.bundle,
494
+ original.originalBundle.wireSubscription,
495
+ acquired.observedAt,
496
+ );
497
+ OWNER.check();
498
+ closed(op.sink, ["send"]);
499
+ const send = sourceMethod(op.sink, "send");
500
+ const sourceSend = (record: unknown, ack: unknown) => {
501
+ OWNER.check();
502
+ return Reflect.apply(send, op.sink, [record, ack]);
503
+ };
504
+ const compiler = createAttachEventCompiler(raw, {
505
+ send: sourceSend,
506
+ timeoutMs: 5000,
507
+ });
508
+ OWNER.check();
509
+ await owned(() =>
510
+ compiler.dispatch({ event: "dispatch", stage: "attach", request }),
511
+ );
512
+ OWNER.check();
513
+ postEligible = true;
514
+ let postedOnce = false;
515
+ const post = async () => {
516
+ OWNER.check();
517
+ if (postedOnce) stop();
518
+ postedOnce = true;
519
+ control.beginPost();
520
+ OWNER.check();
521
+ const reply = await activePair.transport.postAttach();
522
+ OWNER.check();
523
+ const token = control.takePostFailure(reply);
524
+ OWNER.check();
525
+ if (token !== null) throw token;
526
+ return reply;
527
+ };
528
+ const reply = await owned(post, control);
529
+ OWNER.check();
530
+ if (reply.outcome === "not_started") return refuse("post_not_started");
531
+ if (reply.outcome === "provider_rejected") stop();
532
+ if (reply.outcome !== "fulfilled_safe") return uncertain();
533
+ const body = reply.body;
534
+ await owned(() =>
535
+ compiler.response({
536
+ event: "response",
537
+ stage: "attach",
538
+ request,
539
+ body,
540
+ status: reply.statusCode,
541
+ }),
542
+ );
543
+ OWNER.check();
544
+ const receipt = await owned(() =>
545
+ c3({
546
+ attachRequest: raw,
547
+ actualDispatch: Object.freeze(sevenWire(request)),
548
+ providerSnapshot: body as Record<string, unknown>,
549
+ }),
550
+ );
551
+ OWNER.check();
552
+ await owned(() =>
553
+ compiler.receipt({
554
+ event: "receipt",
555
+ stage: "attach",
556
+ request,
557
+ receipt,
558
+ }),
559
+ );
560
+ OWNER.check();
561
+ const result = admitRecoveryOutput(
562
+ receipt,
563
+ acquired.bundle.wireSubscription.schedule,
564
+ prepared,
565
+ request,
566
+ );
567
+ OWNER.check();
568
+ control.takePostQuarantine();
569
+ return result;
570
+ } catch (error) {
571
+ let live = false;
572
+ try {
573
+ OWNER.check();
574
+ live = true;
575
+ } catch {}
576
+ if (live && !postEligible && failureControl) {
577
+ const failure = failureControl.consume(error);
578
+ if (failure !== null) throw failure;
579
+ }
580
+ if (
581
+ live &&
582
+ postEligible &&
583
+ pair &&
584
+ failureControl &&
585
+ pair.transport.postDisposition() === "REJECTED"
586
+ ) {
587
+ const failure = failureControl.consumePost(error);
588
+ if (failure !== null) throw failure;
589
+ }
590
+ if (postEligible && pair) {
591
+ const state = pair.transport.postDisposition();
592
+ if (state === "FULFILLED_SAFE" || state === "FULFILLED_UNVERIFIED")
593
+ return uncertain();
594
+ }
595
+ return stop();
596
+ }
597
+ },
598
+ });
599
+ }