@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,330 @@
1
+ import assert from "node:assert/strict";
2
+ import { webcrypto } from "node:crypto";
3
+ import { vi } from "vitest";
4
+ import { data, type PreflightCase } from "./configurePreflightControls.js";
5
+
6
+ export function deferred() {
7
+ let resolve!: () => void;
8
+ const promise = new Promise<void>((done) => {
9
+ resolve = done;
10
+ });
11
+ return { promise, resolve };
12
+ }
13
+
14
+ export function preflightBarriers(name: PreflightCase) {
15
+ const entered = deferred(),
16
+ released = deferred();
17
+ const pending: Promise<unknown>[] = [];
18
+ let held = false;
19
+ return {
20
+ pending,
21
+ entered: entered.promise,
22
+ release: released.resolve,
23
+ async hold(kind: string) {
24
+ if (held || name !== "hold-" + kind) return;
25
+ held = true;
26
+ entered.resolve();
27
+ await released.promise;
28
+ },
29
+ async enterOrSettled(operation: Promise<unknown>) {
30
+ const observed = operation.then(
31
+ () => false,
32
+ () => false,
33
+ );
34
+ assert.equal(
35
+ await Promise.race([entered.promise.then(() => true), observed]),
36
+ true,
37
+ "TEST_PREREQUISITE_SETTLED_BEFORE_BARRIER",
38
+ );
39
+ },
40
+ async cleanup() {
41
+ released.resolve();
42
+ await Promise.allSettled(pending);
43
+ },
44
+ };
45
+ }
46
+
47
+ export function installPreflightDigestBarrier(
48
+ barriers: ReturnType<typeof preflightBarriers>,
49
+ phase: () => string,
50
+ ) {
51
+ vi.stubGlobal("crypto", {
52
+ subtle: {
53
+ digest(
54
+ algorithm: Parameters<typeof webcrypto.subtle.digest>[0],
55
+ input: Parameters<typeof webcrypto.subtle.digest>[1],
56
+ ) {
57
+ const actual = webcrypto.subtle.digest(algorithm, input);
58
+ const observed = actual.then(async (result) => {
59
+ if (ArrayBuffer.isView(input)) {
60
+ const tuple: unknown = JSON.parse(
61
+ new TextDecoder().decode(
62
+ new Uint8Array(
63
+ input.buffer,
64
+ input.byteOffset,
65
+ input.byteLength,
66
+ ),
67
+ ),
68
+ );
69
+ if (Array.isArray(tuple) && tuple[2] === "renewal-configure")
70
+ await barriers.hold(phase());
71
+ }
72
+ return result;
73
+ });
74
+ barriers.pending.push(observed.catch(() => {}));
75
+ return observed;
76
+ },
77
+ },
78
+ });
79
+ }
80
+
81
+ export function cleanPreflightMocks() {
82
+ for (const path of [
83
+ "../sourceBindings.js",
84
+ "../operations/sourceOperations.js",
85
+ "../../../renewalV2/index.js",
86
+ "../preflight/output.js",
87
+ "../acquisition/readLifetime.js",
88
+ "../acquisition/ownedAcquisition.js",
89
+ "../operations/configureReadTransport.js",
90
+ "../originalOwner.js",
91
+ "../preflight/record.js",
92
+ ])
93
+ vi.doUnmock(path);
94
+ vi.unstubAllGlobals();
95
+ vi.restoreAllMocks();
96
+ vi.resetModules();
97
+ }
98
+
99
+ export function preflightObservationState() {
100
+ return {
101
+ phase: "setup",
102
+ c6: 0,
103
+ c3: 0,
104
+ releaseEntries: 0,
105
+ coverage: 0,
106
+ pairLoads: 0,
107
+ operationLoads: 0,
108
+ samples: 0,
109
+ tupleTraps: 0,
110
+ readonlyCalls: 0,
111
+ methodRetargets: 0,
112
+ initialFinished: false,
113
+ pair: null as unknown,
114
+ pairCreations: 0,
115
+ readerBindings: 0,
116
+ children: 0,
117
+ finishes: 0,
118
+ finishAt: null as number | null,
119
+ scheduleReplies: 0,
120
+ c6Results: [] as unknown[],
121
+ records: [] as Record<string, unknown>[],
122
+ calls: [] as { method: string; path: string }[],
123
+ };
124
+ }
125
+
126
+ export type PreflightObservationState = ReturnType<
127
+ typeof preflightObservationState
128
+ >;
129
+
130
+ export async function installPreflightObservers(
131
+ state: PreflightObservationState,
132
+ OWNER: typeof import("../originalOwner.js").OWNER,
133
+ name: PreflightCase,
134
+ gates: ReturnType<typeof preflightBarriers>,
135
+ advanceLater: () => void,
136
+ retargetReadMethod: () => void,
137
+ ) {
138
+ const actual = await vi.importActual<
139
+ typeof import("../../../renewalV2/index.js")
140
+ >("../../../renewalV2/index.js");
141
+ vi.doMock("../../../renewalV2/index.js", () => ({
142
+ ...actual,
143
+ projectRenewalConfigurationV2(
144
+ ...args: Parameters<typeof actual.projectRenewalConfigurationV2>
145
+ ) {
146
+ if (state.initialFinished) {
147
+ state.phase = state.c6++ === 0 ? "original" : "fresh";
148
+ if (state.phase === "fresh" && name === "later-sample") advanceLater();
149
+ }
150
+ const promise = actual.projectRenewalConfigurationV2(...args);
151
+ gates.pending.push(
152
+ promise.then(
153
+ (value) => {
154
+ state.c6Results.push(value);
155
+ if (state.phase === "original" && name === "method-retarget")
156
+ retargetReadMethod();
157
+ },
158
+ () => {},
159
+ ),
160
+ );
161
+ return promise;
162
+ },
163
+ constructRenewalScheduleAttachmentReceiptV2(
164
+ ...args: Parameters<
165
+ typeof actual.constructRenewalScheduleAttachmentReceiptV2
166
+ >
167
+ ) {
168
+ if (state.initialFinished) state.c3++;
169
+ return actual.constructRenewalScheduleAttachmentReceiptV2(...args);
170
+ },
171
+ }));
172
+ vi.doMock("../preflight/output.js", async () => {
173
+ const real = await vi.importActual<typeof import("../preflight/output.js")>(
174
+ "../preflight/output.js",
175
+ );
176
+ return {
177
+ ...real,
178
+ releasePreflight(...args: Parameters<typeof real.releasePreflight>) {
179
+ state.releaseEntries++;
180
+ return real.releasePreflight(...args);
181
+ },
182
+ };
183
+ });
184
+ vi.doMock("../operations/configureReadTransport.js", async () => {
185
+ const real = await vi.importActual<
186
+ typeof import("../operations/configureReadTransport.js")
187
+ >("../operations/configureReadTransport.js");
188
+ return {
189
+ ...real,
190
+ createConfigureOwnedReadTransport(
191
+ ...args: Parameters<typeof real.createConfigureOwnedReadTransport>
192
+ ) {
193
+ const pair = real.createConfigureOwnedReadTransport(...args);
194
+ state.pair = pair;
195
+ state.pairCreations++;
196
+ return pair;
197
+ },
198
+ };
199
+ });
200
+ vi.doMock("../acquisition/ownedAcquisition.js", async () => {
201
+ const real = await vi.importActual<
202
+ typeof import("../acquisition/ownedAcquisition.js")
203
+ >("../acquisition/ownedAcquisition.js");
204
+ return {
205
+ ...real,
206
+ bindConfigureReadAcquisitionFromSource(
207
+ ...args: Parameters<typeof real.bindConfigureReadAcquisitionFromSource>
208
+ ) {
209
+ state.readerBindings++;
210
+ assert.equal(args[0], OWNER);
211
+ assert.equal(args[1], data(data(state.pair).transport).readTransport);
212
+ return real.bindConfigureReadAcquisitionFromSource(...args);
213
+ },
214
+ };
215
+ });
216
+ vi.doMock("../acquisition/readLifetime.js", async () => {
217
+ const real = await vi.importActual<
218
+ typeof import("../acquisition/readLifetime.js")
219
+ >("../acquisition/readLifetime.js");
220
+ return {
221
+ ...real,
222
+ createReadLifetime(...args: Parameters<typeof real.createReadLifetime>) {
223
+ const child = real.createReadLifetime(...args);
224
+ if (!state.initialFinished) return child;
225
+ assert.equal(args[0], OWNER);
226
+ state.children++;
227
+ return Object.freeze({
228
+ begin: (...xs: Parameters<typeof child.begin>) =>
229
+ Reflect.apply(child.begin, child, xs) as ReturnType<
230
+ typeof child.begin
231
+ >,
232
+ check: (...xs: Parameters<typeof child.check>) =>
233
+ Reflect.apply(child.check, child, xs) as ReturnType<
234
+ typeof child.check
235
+ >,
236
+ fail: (...xs: Parameters<typeof child.fail>) =>
237
+ Reflect.apply(child.fail, child, xs) as ReturnType<
238
+ typeof child.fail
239
+ >,
240
+ finish(...xs: Parameters<typeof child.finish>) {
241
+ const value = Reflect.apply(child.finish, child, xs) as ReturnType<
242
+ typeof child.finish
243
+ >;
244
+ assert.equal(state.scheduleReplies, 1);
245
+ state.finishes++;
246
+ state.finishAt = value.wallMs;
247
+ return value;
248
+ },
249
+ });
250
+ },
251
+ };
252
+ });
253
+ return actual;
254
+ }
255
+
256
+ /** EMPTY-only counter aliases; this fake Owner supplies no canonical/custody proof. */
257
+ export function installEmptyPreflightSpies() {
258
+ const counts = {
259
+ Source: 0,
260
+ Owner: 0,
261
+ check: 0,
262
+ sample: 0,
263
+ client: 0,
264
+ capture: 0,
265
+ api: 0,
266
+ read: 0,
267
+ };
268
+ const effect = (key: keyof typeof counts): never => {
269
+ counts[key]++;
270
+ throw Error("EMPTY_EFFECT_" + key);
271
+ };
272
+ const owner = Object.freeze({
273
+ check: () => effect("check"),
274
+ sample: () => effect("sample"),
275
+ });
276
+ const counterOwner = new Proxy(owner, {
277
+ get(target, key, receiver) {
278
+ counts.Owner++;
279
+ return Reflect.get(target, key, receiver);
280
+ },
281
+ });
282
+ vi.doMock("../originalOwner.js", () => ({ OWNER: counterOwner }));
283
+ vi.doMock("../sourceBindings.js", () => ({
284
+ loadOwnedOriginalSource: () => effect("Source"),
285
+ loadFixedStockClient: () => effect("client"),
286
+ }));
287
+ vi.doMock("../operations/sourceOperations.js", async () => {
288
+ const real = await vi.importActual<
289
+ typeof import("../operations/sourceOperations.js")
290
+ >("../operations/sourceOperations.js");
291
+ assert.deepEqual(real.COMPILED_PREFLIGHT_ENTRIES, []);
292
+ return {
293
+ ...real,
294
+ loadOwnedConfigureOperation: () => effect("Source"),
295
+ loadConfigureOwnedReadTransportSource: () => effect("Source"),
296
+ };
297
+ });
298
+ vi.doMock("../../../renewalV2/index.js", async () => {
299
+ const real = await vi.importActual<
300
+ typeof import("../../../renewalV2/index.js")
301
+ >("../../../renewalV2/index.js");
302
+ return {
303
+ ...real,
304
+ projectRenewalConfigurationV2: () => effect("api"),
305
+ constructRenewalScheduleAttachmentReceiptV2: () => effect("api"),
306
+ };
307
+ });
308
+ vi.doMock("../preflight/record.js", async () => {
309
+ const real = await vi.importActual<typeof import("../preflight/record.js")>(
310
+ "../preflight/record.js",
311
+ );
312
+ return { ...real, capturePreflightRecord: () => effect("capture") };
313
+ });
314
+ vi.doMock("../operations/configureReadTransport.js", async () => {
315
+ const real = await vi.importActual<
316
+ typeof import("../operations/configureReadTransport.js")
317
+ >("../operations/configureReadTransport.js");
318
+ return { ...real, createConfigureOwnedReadTransport: () => effect("read") };
319
+ });
320
+ vi.doMock("../acquisition/ownedAcquisition.js", async () => {
321
+ const real = await vi.importActual<
322
+ typeof import("../acquisition/ownedAcquisition.js")
323
+ >("../acquisition/ownedAcquisition.js");
324
+ return {
325
+ ...real,
326
+ bindConfigureReadAcquisitionFromSource: () => effect("read"),
327
+ };
328
+ });
329
+ return counts;
330
+ }
@@ -0,0 +1,139 @@
1
+ import { makeConfigureReadNativeBaseline } from "./configureReadNativeBaseline.js";
2
+
3
+ export type PreflightCase =
4
+ | "positive"
5
+ | "foreign-owner"
6
+ | "foreign-origin"
7
+ | "foreign-entry"
8
+ | "foreign-preflight-entry"
9
+ | "foreign-delegate"
10
+ | "method-retarget"
11
+ | "foreign-ack"
12
+ | "foreign-pair"
13
+ | "retired-capture"
14
+ | "retired-proxy"
15
+ | "original-failure"
16
+ | "record-token"
17
+ | "subscription-drift"
18
+ | "price-drift"
19
+ | "customer-drift"
20
+ | "coupon-drift"
21
+ | "reference-drift"
22
+ | "schedule-opaque"
23
+ | "schedule-default"
24
+ | "schedule-phase"
25
+ | "hold-schedule"
26
+ | "hold-original"
27
+ | "hold-fresh"
28
+ | "later-sample"
29
+ | "output-overflow";
30
+
31
+ export function data(value: unknown): Record<string, unknown> {
32
+ if (value === null || typeof value !== "object" || Array.isArray(value))
33
+ throw Error("TEST_DATA_PREREQUISITE");
34
+ return value as Record<string, unknown>;
35
+ }
36
+
37
+ export function deepFreeze<T>(value: T): T {
38
+ if (value && typeof value === "object") {
39
+ for (const descriptor of Object.values(
40
+ Object.getOwnPropertyDescriptors(value),
41
+ ))
42
+ if ("value" in descriptor) deepFreeze(descriptor.value);
43
+ Object.freeze(value);
44
+ }
45
+ return value;
46
+ }
47
+
48
+ /** Every raw counterexample and sample cue is declared before any constructor. */
49
+ export function declarePreflightCase(name: PreflightCase) {
50
+ const baseline = makeConfigureReadNativeBaseline();
51
+ const original = structuredClone(baseline.original);
52
+ const schedule = structuredClone(baseline.schedule);
53
+ if (name === "output-overflow")
54
+ Object.assign(schedule.metadata, { opaque: "x".repeat(135000) });
55
+ const baselineBundle = {
56
+ ...structuredClone(original.originalBundle),
57
+ wireSubscription: {
58
+ ...structuredClone(original.originalBundle.wireSubscription),
59
+ schedule: schedule.id,
60
+ },
61
+ };
62
+ const currentBundle = structuredClone(baselineBundle);
63
+ const currentSchedule = structuredClone(schedule);
64
+ if (name === "subscription-drift")
65
+ Object.assign(currentBundle.wireSubscription.metadata, { drift: "Sub" });
66
+ if (name === "price-drift")
67
+ Object.assign(currentBundle.wireTargetPrice.metadata, { drift: "Price" });
68
+ if (name === "customer-drift")
69
+ Object.assign(currentBundle.wireBillingCustomer.metadata, {
70
+ drift: "Customer",
71
+ });
72
+ if (name === "coupon-drift")
73
+ currentBundle.couponReads[0]!.wireCoupon.times_redeemed++;
74
+ if (name === "reference-drift") {
75
+ const source = currentBundle.wireSubscription.discounts[0]!.source;
76
+ Object.defineProperty(source, "coupon", {
77
+ value: source.coupon.id,
78
+ enumerable: true,
79
+ writable: true,
80
+ configurable: true,
81
+ });
82
+ }
83
+ if (name === "schedule-opaque")
84
+ Object.assign(currentSchedule.metadata, { drift: "Schedule" });
85
+ if (name === "schedule-default")
86
+ Object.assign(currentSchedule.default_settings, {
87
+ description: "different",
88
+ });
89
+ if (name === "schedule-phase")
90
+ currentSchedule.phases[0]!.metadata = { drift: "phase" };
91
+ return deepFreeze({
92
+ name,
93
+ original,
94
+ schedule,
95
+ baselineBundle,
96
+ currentBundle,
97
+ currentSchedule,
98
+ apiVersion: baseline.apiVersion,
99
+ configureKey: baseline.configureKey,
100
+ configureAt: baseline.configurationTime,
101
+ originalAPI:
102
+ name === "original-failure"
103
+ ? "unsupported-preflight-api"
104
+ : baseline.apiVersion,
105
+ badRecordBinding: "renewal:v2:sha256:" + "a".repeat(64),
106
+ firstAt: baseline.clockPlan.attachSeconds * 1000 + 1,
107
+ baseAt: baseline.clockPlan.observationSeconds * 1000 + 1001,
108
+ scheduleAt: baseline.clockPlan.observationSeconds * 1000 + 2001,
109
+ laterAt: baseline.clockPlan.observationSeconds * 1000 + 3001,
110
+ workSeconds: baseline.clockPlan.workSeconds,
111
+ endSeconds: baseline.clockPlan.endSeconds,
112
+ });
113
+ }
114
+
115
+ export const preflightRecordTokenPaths = [
116
+ ["request", "logicalBinding"],
117
+ ["request", "attachReceiptBinding"],
118
+ ["request", "baselineBinding"],
119
+ ["request", "defaultSettingsBinding"],
120
+ ["request", "requestIdentity", "binding"],
121
+ ["attachReceipt", "logicalBinding"],
122
+ ["attachReceipt", "request", "logicalBinding"],
123
+ ["attachReceipt", "request", "requestIdentity", "binding"],
124
+ ["attachReceipt", "binding"],
125
+ ] as const;
126
+
127
+ /** Fixed TEST mutation recipe, never a production path/family selector. */
128
+ export function replaceRecordToken(record: unknown, index: number) {
129
+ const path = preflightRecordTokenPaths[index];
130
+ if (!path) throw Error("TEST_TOKEN_INDEX");
131
+ const copy = structuredClone(record);
132
+ let node = data(copy);
133
+ for (const key of path.slice(0, -1)) node = data(node[key]);
134
+ const key = path[path.length - 1]!;
135
+ const old = node[key];
136
+ if (typeof old !== "string") throw Error("TEST_TOKEN_PREREQUISITE");
137
+ node[key] = old.slice(0, old.length - 64) + "b".repeat(64);
138
+ return copy;
139
+ }