@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,574 @@
1
+ import { types } from "node:util";
2
+ import { requiredJSONSnapshot } from "../material/requiredJson.js";
3
+ import { rejectProxyJSON } from "../acquisition/rawWireSource.js";
4
+ import {
5
+ closed,
6
+ captureRequestAndReads,
7
+ need,
8
+ stop,
9
+ freezeJSON,
10
+ type AttachRequest,
11
+ type ReadRow,
12
+ type SourceMethod,
13
+ } from "./types.js";
14
+ import {
15
+ safeDiagnostics,
16
+ opaqueRecord,
17
+ type Diagnostics,
18
+ } from "./providerFailure.js";
19
+ import { equal } from "../../../renewalAggregate/shared.js";
20
+ import {
21
+ loadInitialOwnedTransportSource,
22
+ loadRecoveryOwnedTransportSource,
23
+ loadOwnedTransportSource,
24
+ } from "./sourceOperations.js";
25
+ import { OWNER } from "../originalOwner.js";
26
+
27
+ function sourceFunction(
28
+ service: unknown,
29
+ name: string,
30
+ ): { receiver: object; method: SourceMethod } {
31
+ need(service && typeof service === "object" && !types.isProxy(service));
32
+ const d = Object.getOwnPropertyDescriptor(service, name);
33
+ need(d && "value" in d && typeof d.value === "function");
34
+ // The function is selected once from validated own data, preserving its receiver.
35
+ return { receiver: service, method: d.value as SourceMethod };
36
+ }
37
+
38
+ /** Internal fixed attach profile: 43 reads and one POST, never a 44-GET profile. */
39
+ function captureSource(raw: unknown) {
40
+ const b = closed(raw, ["owner", "request", "readPlan", "delegate"]);
41
+ need(b.owner === OWNER);
42
+ const owner = sourceFunction(b.owner, "check"),
43
+ delegate = sourceFunction(b.delegate, "rawRequest");
44
+ const { request, plan } = captureRequestAndReads(b.request, b.readPlan);
45
+ return Object.freeze({
46
+ owner: owner.receiver,
47
+ check: owner.method,
48
+ delegate: delegate.receiver,
49
+ send: delegate.method,
50
+ request,
51
+ plan: Object.freeze(plan),
52
+ });
53
+ }
54
+
55
+ function validRead(
56
+ row: ReadRow,
57
+ method: unknown,
58
+ path: unknown,
59
+ body: unknown,
60
+ options: unknown,
61
+ ) {
62
+ need(row && method === row.method && path === row.path && body === undefined);
63
+ const value = closed(options, ["apiVersion", "maxNetworkRetries"]);
64
+ need(
65
+ value.apiVersion === row.options.apiVersion &&
66
+ value.maxNetworkRetries === 0,
67
+ );
68
+ }
69
+
70
+ function checkOwnerResult(value: unknown) {
71
+ const x = closed(value, ["wallMs", "ns", "nowSeconds", "retired"]);
72
+ need(
73
+ typeof x.wallMs === "number" &&
74
+ Number.isSafeInteger(x.wallMs) &&
75
+ x.wallMs >= 0 &&
76
+ typeof x.ns === "bigint" &&
77
+ x.ns >= 0n &&
78
+ x.ns <= 18446744073709551615n &&
79
+ typeof x.nowSeconds === "number" &&
80
+ Number.isSafeInteger(x.nowSeconds) &&
81
+ x.nowSeconds === Math.floor(x.wallMs / 1000) &&
82
+ x.retired === false,
83
+ );
84
+ }
85
+
86
+ export type PostDisposition =
87
+ | "NOT_STARTED"
88
+ | "PENDING"
89
+ | "REJECTED"
90
+ | "FULFILLED_UNVERIFIED"
91
+ | "FULFILLED_SAFE";
92
+ type Attempt = Readonly<{
93
+ generation: object;
94
+ ordinal: number;
95
+ kind: "read" | "post";
96
+ resource: string;
97
+ method: string;
98
+ path: string;
99
+ id: string;
100
+ }>;
101
+ export type Quarantine = Readonly<object>;
102
+ type Rejection = Readonly<{
103
+ phase: "read";
104
+ ordinal: number;
105
+ diagnostics: Diagnostics;
106
+ }>;
107
+ const notStarted = (reason: string) =>
108
+ Object.freeze({ outcome: "not_started" as const, reason });
109
+ const nativeResponsePrototype = Response.prototype,
110
+ nativeStatusGetter = Object.getOwnPropertyDescriptor(
111
+ nativeResponsePrototype,
112
+ "status",
113
+ )!.get!,
114
+ apply = Reflect.apply;
115
+
116
+ function capturePostReply(reply: unknown) {
117
+ rejectProxyJSON(reply, true);
118
+ need(reply !== null && typeof reply === "object" && !Array.isArray(reply));
119
+ const proto = Object.getPrototypeOf(reply);
120
+ need(proto === Object.prototype || proto === null);
121
+ const meta = Object.getOwnPropertyDescriptor(reply, "lastResponse");
122
+ need(
123
+ meta &&
124
+ !meta.enumerable &&
125
+ "value" in meta &&
126
+ meta.value !== null &&
127
+ typeof meta.value === "object",
128
+ );
129
+ const metadata: object = meta.value;
130
+ need(!types.isProxy(metadata));
131
+ const codes: unknown[] = [];
132
+ for (const key of ["status", "statusCode"]) {
133
+ const d = Object.getOwnPropertyDescriptor(metadata, key);
134
+ if (!d) continue;
135
+ need("value" in d);
136
+ if (d.value !== undefined) codes.push(d.value);
137
+ }
138
+ if (Object.getPrototypeOf(metadata) === nativeResponsePrototype)
139
+ codes.push(apply(nativeStatusGetter, metadata, []));
140
+ need(
141
+ codes.length > 0 &&
142
+ codes.every(
143
+ (x) =>
144
+ typeof x === "number" &&
145
+ Number.isInteger(x) &&
146
+ x >= 200 &&
147
+ x < 300 &&
148
+ x === codes[0],
149
+ ),
150
+ );
151
+ const statusCode = codes[0];
152
+ need(typeof statusCode === "number");
153
+ const entries: [string, unknown][] = [];
154
+ for (const key of Reflect.ownKeys(reply)) {
155
+ need(typeof key === "string");
156
+ if (key === "lastResponse") continue;
157
+ const d = Object.getOwnPropertyDescriptor(reply, key);
158
+ need(d && d.enumerable && "value" in d);
159
+ entries.push([key, d.value]);
160
+ }
161
+ return Object.freeze({
162
+ body: requiredJSONSnapshot(Object.fromEntries(entries)),
163
+ statusCode,
164
+ });
165
+ }
166
+
167
+ type Association = Readonly<{
168
+ operation: unknown;
169
+ readPlan: unknown;
170
+ delegate: unknown;
171
+ }>;
172
+ function build(source: unknown, association?: Association) {
173
+ const b = captureSource(source),
174
+ generation = Object.freeze({});
175
+ let ordinal = 0,
176
+ index = 0,
177
+ pending: Attempt | null = null,
178
+ failedRead = false,
179
+ consumedPost = false;
180
+ let postState: PostDisposition = "NOT_STARTED",
181
+ postAttempt: Attempt | null = null,
182
+ rejectionSlot: { attempt: Attempt; record: Rejection } | null = null,
183
+ lastFailedRead: Attempt | null = null,
184
+ closedOwner = false,
185
+ checking = false;
186
+ function ownerGate() {
187
+ if (closedOwner || checking) {
188
+ closedOwner = true;
189
+ stop();
190
+ }
191
+ checking = true;
192
+ try {
193
+ checkOwnerResult(Reflect.apply(b.check, b.owner, []));
194
+ if (closedOwner) stop();
195
+ } catch {
196
+ closedOwner = true;
197
+ stop();
198
+ } finally {
199
+ checking = false;
200
+ }
201
+ }
202
+ function attempt(
203
+ kind: "read" | "post",
204
+ row: ReadRow | AttachRequest,
205
+ ): Attempt {
206
+ need(!pending && ordinal < 44);
207
+ const value = Object.freeze({
208
+ generation,
209
+ ordinal: ++ordinal,
210
+ kind,
211
+ resource: kind === "read" && "resource" in row ? row.resource : "post",
212
+ method: row.method,
213
+ path: row.path,
214
+ id: "id" in row ? row.id : b.request.payload.from_subscription,
215
+ });
216
+ pending = value;
217
+ return value;
218
+ }
219
+ const own = (a: Attempt) => pending === a && a.generation === generation;
220
+ const postCatchRecords = new WeakMap<
221
+ object,
222
+ Readonly<{ attempt: Attempt; diagnostics: Diagnostics }>
223
+ >();
224
+ let reservation = "unused",
225
+ fulfilledSlot: Readonly<{
226
+ attempt: Attempt;
227
+ generation: object;
228
+ quarantine: Quarantine;
229
+ }> | null = null;
230
+ async function rawRequest(
231
+ method: unknown,
232
+ path: unknown,
233
+ body: unknown,
234
+ options: unknown,
235
+ ): Promise<unknown> {
236
+ need(!failedRead && !consumedPost && !pending && index < b.plan.length);
237
+ ownerGate();
238
+ const row = b.plan[index];
239
+ validRead(row, method, path, body, options);
240
+ const a = attempt("read", row);
241
+ let reply: unknown;
242
+ try {
243
+ reply = await Reflect.apply(b.send, b.delegate, [
244
+ method,
245
+ path,
246
+ body,
247
+ row.options,
248
+ ]);
249
+ } catch (error) {
250
+ need(own(a));
251
+ failedRead = true;
252
+ lastFailedRead = a;
253
+ let live = false;
254
+ try {
255
+ ownerGate();
256
+ live = true;
257
+ } catch {
258
+ /* Retired errors are opaque. */
259
+ }
260
+ if (live && own(a))
261
+ rejectionSlot = {
262
+ attempt: a,
263
+ record: opaqueRecord(
264
+ {
265
+ phase: "read",
266
+ ordinal: a.ordinal,
267
+ diagnostics: safeDiagnostics(error),
268
+ } as const,
269
+ "rawError",
270
+ error,
271
+ ),
272
+ };
273
+ pending = null;
274
+ if (live) throw error;
275
+ stop();
276
+ }
277
+ try {
278
+ ownerGate();
279
+ need(own(a));
280
+ } catch {
281
+ failedRead = true;
282
+ pending = null;
283
+ stop();
284
+ }
285
+ pending = null;
286
+ index++;
287
+ return reply;
288
+ }
289
+ async function postAttach(...args: unknown[]) {
290
+ if (
291
+ args.length ||
292
+ consumedPost ||
293
+ pending ||
294
+ failedRead ||
295
+ index !== b.plan.length
296
+ )
297
+ return notStarted("not_ready");
298
+ try {
299
+ ownerGate();
300
+ } catch {
301
+ return notStarted("owner_closed");
302
+ }
303
+ consumedPost = true;
304
+ const request = b.request,
305
+ a = attempt("post", request);
306
+ postAttempt = a;
307
+ postState = "PENDING";
308
+ let reply: unknown;
309
+ try {
310
+ reply = await Reflect.apply(b.send, b.delegate, [
311
+ request.method,
312
+ request.path,
313
+ request.payload,
314
+ {
315
+ apiVersion: request.apiVersion,
316
+ idempotencyKey: request.key,
317
+ maxNetworkRetries: 0,
318
+ },
319
+ ]);
320
+ } catch (error) {
321
+ postState = "REJECTED";
322
+ let live = false;
323
+ try {
324
+ ownerGate();
325
+ live = true;
326
+ } catch {
327
+ /* No late error reflection. */
328
+ }
329
+ const valid = own(a) && postAttempt === a,
330
+ diagnostics =
331
+ live && valid ? safeDiagnostics(error) : Object.freeze({});
332
+ const record = opaqueRecord(
333
+ {
334
+ outcome: "provider_rejected",
335
+ phase: "post",
336
+ ordinal: a.ordinal,
337
+ diagnostics,
338
+ } as const,
339
+ "rawError",
340
+ error,
341
+ );
342
+ if (valid)
343
+ postCatchRecords.set(
344
+ record,
345
+ Object.freeze({ attempt: a, diagnostics }),
346
+ );
347
+ pending = null;
348
+ return record;
349
+ }
350
+ if (own(a) && postAttempt === a && a.generation === generation) {
351
+ const q: object = Object.create(null);
352
+ Object.defineProperty(q, "raw", {
353
+ value: reply,
354
+ enumerable: false,
355
+ writable: false,
356
+ configurable: false,
357
+ });
358
+ Object.freeze(q);
359
+ fulfilledSlot = Object.freeze({ attempt: a, generation, quarantine: q });
360
+ }
361
+ postState = "FULFILLED_UNVERIFIED";
362
+ try {
363
+ ownerGate();
364
+ need(own(a) && postAttempt === a);
365
+ const admitted = capturePostReply(reply);
366
+ ownerGate();
367
+ pending = null;
368
+ postState = "FULFILLED_SAFE";
369
+ return Object.freeze({
370
+ outcome: "fulfilled_safe" as const,
371
+ body: freezeJSON(admitted.body),
372
+ statusCode: admitted.statusCode,
373
+ });
374
+ } catch {
375
+ pending = null;
376
+ return opaqueRecord(
377
+ { outcome: "fulfilled_unverified" as const },
378
+ "rawResponse",
379
+ reply,
380
+ );
381
+ }
382
+ }
383
+ const transport = Object.freeze({
384
+ readTransport: Object.freeze({ rawRequest }),
385
+ postAttach,
386
+ takeReadRejection(...args: unknown[]) {
387
+ need(args.length === 0);
388
+ const slot = rejectionSlot;
389
+ rejectionSlot = null;
390
+ if (
391
+ !slot ||
392
+ slot.attempt !== lastFailedRead ||
393
+ slot.attempt.generation !== generation ||
394
+ slot.attempt.kind !== "read"
395
+ )
396
+ return null;
397
+ return slot.record;
398
+ },
399
+ postDisposition(...args: unknown[]): PostDisposition {
400
+ need(args.length === 0);
401
+ return postState;
402
+ },
403
+ });
404
+ const capability = Object.freeze({
405
+ assertSourceOperationBinding(
406
+ operation: unknown,
407
+ request: unknown,
408
+ readPlan: unknown,
409
+ delegate: unknown,
410
+ ) {
411
+ ownerGate();
412
+ if (
413
+ !association ||
414
+ association.operation !== operation ||
415
+ association.readPlan !== readPlan ||
416
+ association.delegate !== delegate
417
+ )
418
+ return false;
419
+ const current = captureRequestAndReads(request, readPlan);
420
+ const matches =
421
+ equal(current.request, b.request) &&
422
+ current.plan.length === b.plan.length &&
423
+ current.plan.every((row, index) => {
424
+ const captured = b.plan[index];
425
+ return (
426
+ row.resource === captured.resource &&
427
+ row.ordinal === captured.ordinal &&
428
+ row.method === captured.method &&
429
+ row.path === captured.path &&
430
+ row.body === captured.body &&
431
+ row.id === captured.id &&
432
+ row.options.apiVersion === captured.options.apiVersion &&
433
+ row.options.maxNetworkRetries === captured.options.maxNetworkRetries
434
+ );
435
+ });
436
+ ownerGate();
437
+ return matches;
438
+ },
439
+ takeFulfilledQuarantine(...args: unknown[]) {
440
+ if (
441
+ args.length !== 0 ||
442
+ pending !== null ||
443
+ fulfilledSlot === null ||
444
+ fulfilledSlot.attempt !== postAttempt ||
445
+ fulfilledSlot.generation !== generation ||
446
+ postAttempt === null ||
447
+ postAttempt.generation !== generation ||
448
+ postAttempt.kind !== "post" ||
449
+ (postState !== "FULFILLED_SAFE" && postState !== "FULFILLED_UNVERIFIED")
450
+ )
451
+ return null;
452
+ const q = fulfilledSlot.quarantine;
453
+ fulfilledSlot = null;
454
+ return q;
455
+ },
456
+ assertVirginAcquisition(...args: unknown[]) {
457
+ need(args.length === 0);
458
+ try {
459
+ ownerGate();
460
+ } catch {
461
+ return false;
462
+ }
463
+ if (
464
+ reservation !== "unused" ||
465
+ ordinal !== 0 ||
466
+ index !== 0 ||
467
+ pending ||
468
+ failedRead ||
469
+ lastFailedRead ||
470
+ rejectionSlot ||
471
+ consumedPost ||
472
+ postAttempt ||
473
+ postState !== "NOT_STARTED"
474
+ ) {
475
+ reservation = "invalid";
476
+ return false;
477
+ }
478
+ reservation = "reserved";
479
+ return true;
480
+ },
481
+ consumeReadCatch(...args: unknown[]) {
482
+ need(args.length === 0);
483
+ try {
484
+ ownerGate();
485
+ } catch {
486
+ return null;
487
+ }
488
+ const slot = rejectionSlot;
489
+ if (
490
+ reservation !== "reserved" ||
491
+ !failedRead ||
492
+ pending ||
493
+ !slot ||
494
+ slot.attempt !== lastFailedRead ||
495
+ slot.attempt.generation !== generation ||
496
+ slot.attempt.kind !== "read" ||
497
+ slot.attempt.ordinal > 43
498
+ )
499
+ return null;
500
+ rejectionSlot = null;
501
+ return Object.freeze({
502
+ phase: "read" as const,
503
+ ordinal: slot.attempt.ordinal,
504
+ diagnostics: slot.record.diagnostics,
505
+ });
506
+ },
507
+ consumePostCatch(actualReply: unknown) {
508
+ need(arguments.length === 1);
509
+ try {
510
+ ownerGate();
511
+ } catch {
512
+ return null;
513
+ }
514
+ const stored =
515
+ actualReply !== null &&
516
+ (typeof actualReply === "object" || typeof actualReply === "function")
517
+ ? postCatchRecords.get(actualReply)
518
+ : undefined;
519
+ if (
520
+ reservation !== "reserved" ||
521
+ !stored ||
522
+ stored.attempt !== postAttempt ||
523
+ stored.attempt.generation !== generation ||
524
+ stored.attempt.kind !== "post" ||
525
+ postState !== "REJECTED" ||
526
+ pending ||
527
+ stored.attempt.ordinal > 44
528
+ )
529
+ return null;
530
+ postCatchRecords.delete(actualReply as object);
531
+ return Object.freeze({
532
+ phase: "post" as const,
533
+ ordinal: stored.attempt.ordinal,
534
+ diagnostics: stored.diagnostics,
535
+ });
536
+ },
537
+ });
538
+ return Object.freeze({ transport, capability });
539
+ }
540
+
541
+ export function createOwnedTransportWithAttemptCapability() {
542
+ need(arguments.length === 0);
543
+ OWNER.check();
544
+ const source = loadOwnedTransportSource();
545
+ OWNER.check();
546
+ return build(source);
547
+ }
548
+
549
+ function createAssociatedPair(load: () => unknown) {
550
+ OWNER.check();
551
+ const raw = load();
552
+ OWNER.check();
553
+ const frame = closed(raw, [
554
+ "owner",
555
+ "operation",
556
+ "request",
557
+ "readPlan",
558
+ "delegate",
559
+ ]);
560
+ need(frame.owner === OWNER);
561
+ const { operation, readPlan, delegate } = frame;
562
+ return build(
563
+ { owner: OWNER, request: frame.request, readPlan, delegate },
564
+ Object.freeze({ operation, readPlan, delegate }),
565
+ );
566
+ }
567
+ export function createInitialOwnedTransportWithAttemptCapability() {
568
+ need(arguments.length === 0);
569
+ return createAssociatedPair(loadInitialOwnedTransportSource);
570
+ }
571
+ export function createRecoveryOwnedTransportWithAttemptCapability() {
572
+ need(arguments.length === 0);
573
+ return createAssociatedPair(loadRecoveryOwnedTransportSource);
574
+ }
@@ -0,0 +1,34 @@
1
+ import assert from "node:assert/strict";
2
+ import { data } from "../test-fixtures/attachScenarioBarriers.js";
3
+ import { it } from "vitest";
4
+ import { scenario } from "../test-fixtures/attachScenario.js";
5
+ it("actual owned initial attach ACK positive", async () => {
6
+ const h = await scenario("INITIAL-ACK");
7
+ try {
8
+ const out = await h.runInitial();
9
+ h.assertInitialAcknowledged(out);
10
+ } finally {
11
+ await h.cleanup();
12
+ }
13
+ h.health();
14
+ });
15
+
16
+ it("actual initial retained predicate truthy nonboolean refuses before HTTP", async () => {
17
+ const h = await scenario("INITIAL-TRUTHY");
18
+ try {
19
+ const out = data(await h.invokeInitial());
20
+ assert.equal(out.status, "not_dispatched");
21
+ assert.equal(out.reason, "retained_class_not_unique");
22
+ assert.equal(out.operationalAuthority, false);
23
+ const predicate = h.retainedPredicateState();
24
+ assert.equal(predicate.retainedCalls, 1);
25
+ assert.equal(predicate.retainedMatches, 1);
26
+ assert.equal(predicate.lastRetainedResult, 1);
27
+ assert.equal(h.effectCounts().GET, 0);
28
+ assert.equal(h.effectCounts().POST, 0);
29
+ assert.equal(h.aRecords().length, 0);
30
+ } finally {
31
+ await h.cleanup();
32
+ }
33
+ h.health();
34
+ });