@fantastic.dev/better-stripe 0.90.0 → 0.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +41 -0
  4. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +187 -0
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts +2 -23
  8. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js +1 -112
  10. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts +8 -3
  12. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js +1 -0
  14. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/acquisition/test-fixtures/sourcePort.d.mts +1 -1
  16. package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts +8 -0
  17. package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -0
  18. package/dist/client/billing/renewalAttach/internal/configure/actor.js +454 -0
  19. package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -0
  20. package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts +12 -0
  21. package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts.map +1 -0
  22. package/dist/client/billing/renewalAttach/internal/configure/capture.js +99 -0
  23. package/dist/client/billing/renewalAttach/internal/configure/capture.js.map +1 -0
  24. package/dist/client/billing/renewalAttach/internal/configure/output.d.ts +16 -0
  25. package/dist/client/billing/renewalAttach/internal/configure/output.d.ts.map +1 -0
  26. package/dist/client/billing/renewalAttach/internal/configure/output.js +274 -0
  27. package/dist/client/billing/renewalAttach/internal/configure/output.js.map +1 -0
  28. package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts +3 -0
  29. package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts.map +1 -0
  30. package/dist/client/billing/renewalAttach/internal/configure/replay.js +9 -0
  31. package/dist/client/billing/renewalAttach/internal/configure/replay.js.map +1 -0
  32. package/dist/client/billing/renewalAttach/internal/configure/request.d.ts +39 -0
  33. package/dist/client/billing/renewalAttach/internal/configure/request.d.ts.map +1 -0
  34. package/dist/client/billing/renewalAttach/internal/configure/request.js +245 -0
  35. package/dist/client/billing/renewalAttach/internal/configure/request.js.map +1 -0
  36. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +88 -0
  37. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -0
  38. package/dist/client/billing/renewalAttach/internal/configure/transport.js +289 -0
  39. package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -0
  40. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts +16 -0
  41. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -0
  42. package/dist/client/billing/renewalAttach/internal/observation/actor.js +362 -0
  43. package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -0
  44. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts +9 -0
  45. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -0
  46. package/dist/client/billing/renewalAttach/internal/observation/capture.js +215 -0
  47. package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -0
  48. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +7 -0
  49. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -0
  50. package/dist/client/billing/renewalAttach/internal/observation/profile.js +190 -0
  51. package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -0
  52. package/dist/client/billing/renewalAttach/internal/observation/record.d.ts +5 -0
  53. package/dist/client/billing/renewalAttach/internal/observation/record.d.ts.map +1 -0
  54. package/dist/client/billing/renewalAttach/internal/observation/record.js +317 -0
  55. package/dist/client/billing/renewalAttach/internal/observation/record.js.map +1 -0
  56. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +79 -0
  57. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -0
  58. package/dist/client/billing/renewalAttach/internal/observation/types.js +27 -0
  59. package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -0
  60. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +18 -0
  61. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -0
  62. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +229 -0
  63. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -0
  64. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +163 -0
  65. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -0
  66. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +443 -0
  67. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -0
  68. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +8 -0
  69. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -0
  70. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +467 -0
  71. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -0
  72. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +6 -0
  73. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -0
  74. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +59 -0
  75. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -0
  76. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts +10 -0
  77. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts.map +1 -0
  78. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js +48 -0
  79. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js.map +1 -0
  80. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +20 -0
  81. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -0
  82. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +44 -0
  83. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -0
  84. package/dist/client/billing/renewalAttach/internal/operations/types.d.ts +42 -0
  85. package/dist/client/billing/renewalAttach/internal/operations/types.d.ts.map +1 -0
  86. package/dist/client/billing/renewalAttach/internal/operations/types.js +158 -0
  87. package/dist/client/billing/renewalAttach/internal/operations/types.js.map +1 -0
  88. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts +5 -0
  89. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts.map +1 -0
  90. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js +214 -0
  91. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js.map +1 -0
  92. package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts +33 -0
  93. package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts.map +1 -0
  94. package/dist/client/billing/renewalAttach/internal/preflight/grammar.js +208 -0
  95. package/dist/client/billing/renewalAttach/internal/preflight/grammar.js.map +1 -0
  96. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +4 -0
  97. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -0
  98. package/dist/client/billing/renewalAttach/internal/preflight/output.js +25 -0
  99. package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -0
  100. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +16 -0
  101. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -0
  102. package/dist/client/billing/renewalAttach/internal/preflight/record.js +93 -0
  103. package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -0
  104. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +7 -0
  105. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -0
  106. package/dist/client/billing/renewalAttach/internal/preflight/relations.js +153 -0
  107. package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -0
  108. package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts +22 -0
  109. package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts.map +1 -0
  110. package/dist/client/billing/renewalAttach/internal/recovery/material.js +221 -0
  111. package/dist/client/billing/renewalAttach/internal/recovery/material.js.map +1 -0
  112. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +8 -0
  113. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -0
  114. package/dist/client/billing/renewalAttach/internal/recovery/output.js +101 -0
  115. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -0
  116. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +12 -0
  117. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -0
  118. package/dist/client/billing/renewalAttach/internal/recovery/record.js +186 -0
  119. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -0
  120. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +5 -0
  121. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -0
  122. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +498 -0
  123. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -0
  124. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +21 -0
  125. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -0
  126. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +119 -0
  127. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -0
  128. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  129. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  130. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  131. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  132. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  133. package/dist/component/payoutRelease/queries.d.ts +2 -2
  134. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  135. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  136. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  137. package/docs/renewal-context-reads.md +26 -8
  138. package/docs/renewal-material-observation.md +37 -0
  139. package/docs/renewal-phase-assembly.md +68 -0
  140. package/docs/renewal-raw-acquisition.md +19 -5
  141. package/package.json +1 -1
  142. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +304 -0
  143. package/src/client/billing/renewalAttach/internal/acquisition/rawAcquisition.ts +2 -160
  144. package/src/client/billing/renewalAttach/internal/acquisition/rawWireSource.ts +15 -3
  145. package/src/client/billing/renewalAttach/internal/configure/actor.ts +575 -0
  146. package/src/client/billing/renewalAttach/internal/configure/capture.ts +117 -0
  147. package/src/client/billing/renewalAttach/internal/configure/dispatch.integration.test.ts +32 -0
  148. package/src/client/billing/renewalAttach/internal/configure/limits.test.ts +510 -0
  149. package/src/client/billing/renewalAttach/internal/configure/order.integration.test.ts +207 -0
  150. package/src/client/billing/renewalAttach/internal/configure/output.ts +372 -0
  151. package/src/client/billing/renewalAttach/internal/configure/ownership.integration.test.ts +148 -0
  152. package/src/client/billing/renewalAttach/internal/configure/replay.integration.test.ts +173 -0
  153. package/src/client/billing/renewalAttach/internal/configure/replay.ts +13 -0
  154. package/src/client/billing/renewalAttach/internal/configure/request.ts +312 -0
  155. package/src/client/billing/renewalAttach/internal/configure/transport.integration.test.ts +507 -0
  156. package/src/client/billing/renewalAttach/internal/configure/transport.ts +348 -0
  157. package/src/client/billing/renewalAttach/internal/observation/actor.ts +444 -0
  158. package/src/client/billing/renewalAttach/internal/observation/capture.ts +250 -0
  159. package/src/client/billing/renewalAttach/internal/observation/observation.integration.test.ts +220 -0
  160. package/src/client/billing/renewalAttach/internal/observation/observationRetirement.integration.test.ts +60 -0
  161. package/src/client/billing/renewalAttach/internal/observation/profile.ts +264 -0
  162. package/src/client/billing/renewalAttach/internal/observation/record.ts +408 -0
  163. package/src/client/billing/renewalAttach/internal/observation/types.ts +102 -0
  164. package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +285 -0
  165. package/src/client/billing/renewalAttach/internal/operations/defaultBindings.test.ts +69 -0
  166. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +574 -0
  167. package/src/client/billing/renewalAttach/internal/operations/initialAttach.integration.test.ts +34 -0
  168. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +535 -0
  169. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +63 -0
  170. package/src/client/billing/renewalAttach/internal/operations/providerFailure.integration.test.ts +61 -0
  171. package/src/client/billing/renewalAttach/internal/operations/providerFailure.ts +66 -0
  172. package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +50 -0
  173. package/src/client/billing/renewalAttach/internal/operations/transport.integration.test.ts +116 -0
  174. package/src/client/billing/renewalAttach/internal/operations/types.ts +223 -0
  175. package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.integration.test.ts +285 -0
  176. package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.ts +258 -0
  177. package/src/client/billing/renewalAttach/internal/preflight/configureReads.integration.test.ts +139 -0
  178. package/src/client/billing/renewalAttach/internal/preflight/grammar.ts +257 -0
  179. package/src/client/billing/renewalAttach/internal/preflight/output.ts +42 -0
  180. package/src/client/billing/renewalAttach/internal/preflight/owner.integration.test.ts +82 -0
  181. package/src/client/billing/renewalAttach/internal/preflight/preflight.integration.test.ts +354 -0
  182. package/src/client/billing/renewalAttach/internal/preflight/record.ts +127 -0
  183. package/src/client/billing/renewalAttach/internal/preflight/relations.ts +209 -0
  184. package/src/client/billing/renewalAttach/internal/recovery/material.ts +311 -0
  185. package/src/client/billing/renewalAttach/internal/recovery/output.ts +136 -0
  186. package/src/client/billing/renewalAttach/internal/recovery/record.ts +230 -0
  187. package/src/client/billing/renewalAttach/internal/recovery/recovery.integration.test.ts +463 -0
  188. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +599 -0
  189. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +175 -0
  190. package/src/client/billing/renewalAttach/internal/test-fixtures/attachEntries.ts +217 -0
  191. package/src/client/billing/renewalAttach/internal/test-fixtures/attachObservations.ts +226 -0
  192. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenario.ts +556 -0
  193. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioAssertions.ts +180 -0
  194. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioBarriers.ts +144 -0
  195. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightAssertions.ts +122 -0
  196. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightBarriers.ts +330 -0
  197. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightControls.ts +139 -0
  198. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightOperation.ts +513 -0
  199. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadNativeBaseline.ts +344 -0
  200. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadOperation.ts +278 -0
  201. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadPort.ts +17 -0
  202. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +533 -0
  203. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteBarriers.ts +125 -0
  204. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +314 -0
  205. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +463 -0
  206. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteObservations.ts +515 -0
  207. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +600 -0
  208. package/src/client/billing/renewalAttach/internal/test-fixtures/observationAssertions.ts +211 -0
  209. package/src/client/billing/renewalAttach/internal/test-fixtures/observationDeclarations.ts +192 -0
  210. package/src/client/billing/renewalAttach/internal/test-fixtures/observationHTTP.ts +197 -0
  211. package/src/client/billing/renewalAttach/internal/test-fixtures/observationObservations.ts +269 -0
  212. package/src/client/billing/renewalAttach/internal/test-fixtures/observationOperation.ts +262 -0
  213. package/src/client/billing/renewalAttach/internal/test-fixtures/observationProbe.ts +319 -0
  214. package/src/client/billing/renewalAttach/internal/test-fixtures/ownedOperations.ts +94 -0
  215. package/src/client/billing/renewalAttach/internal/test-fixtures/sourceOperationPort.ts +16 -0
  216. package/src/client/billing/renewalAttach/internal/test-fixtures/stockHttp.ts +21 -0
@@ -0,0 +1,600 @@
1
+ import assert from "node:assert/strict";
2
+ import { vi } from "vitest";
3
+ import { declaredEntries } from "./attachEntries.js";
4
+ import {
5
+ declarePreflightCase,
6
+ deepFreeze,
7
+ data,
8
+ } from "./configurePreflightControls.js";
9
+ import {
10
+ preflightBarriers,
11
+ installPreflightDigestBarrier,
12
+ cleanPreflightMocks,
13
+ preflightObservationState,
14
+ installPreflightObservers,
15
+ } from "./configurePreflightBarriers.js";
16
+ import {
17
+ declareConfigureWriteFamily,
18
+ type WriteCase,
19
+ } from "./configureWriteDeclarations.js";
20
+ import {
21
+ writeObservationState,
22
+ installWriteAPIObservers,
23
+ } from "./configureWriteObservations.js";
24
+ import {
25
+ configureWriteBarriers,
26
+ installWriteDigestAccounting,
27
+ } from "./configureWriteBarriers.js";
28
+ import {
29
+ declareExpectedReplay,
30
+ configureWriteTestFamily,
31
+ type ConfiguredWriteTestFamily,
32
+ } from "./configureWriteHistory.js";
33
+ import {
34
+ assertFit,
35
+ assertPreflightPositive,
36
+ } from "./configurePreflightAssertions.js";
37
+ import {
38
+ establishWriteOracle,
39
+ assertWriteTokenPreimages,
40
+ logWritePrerequisites,
41
+ } from "./configureWriteAssertions.js";
42
+
43
+ /** Closed TEST Source. Real initial ACK is a prerequisite, never a fabricated receipt. */
44
+ export async function configureWriteFixture(mode: WriteCase = "ack") {
45
+ const name = "positive" as const;
46
+ const declarations = declareConfigureWriteFamily(mode);
47
+ const write = declarations.control;
48
+ const writeState = writeObservationState();
49
+ const writeGates = configureWriteBarriers();
50
+ vi.resetModules();
51
+ const declared = declarePreflightCase(name);
52
+ const gates = preflightBarriers(name);
53
+ try {
54
+ const state = preflightObservationState();
55
+ let now = declared.firstAt;
56
+ const start = declared.original.attachRequest.firstDispatchedAt * 1000;
57
+ const basis = Object.freeze({
58
+ startWallMs: start,
59
+ startNs: BigInt(start) * 1000000n,
60
+ workEndWallMs: start + declared.workSeconds * 1000,
61
+ workEndNs: BigInt(start + declared.workSeconds * 1000) * 1000000n,
62
+ endWallMs: start + declared.endSeconds * 1000,
63
+ endNs: BigInt(start + declared.endSeconds * 1000) * 1000000n,
64
+ });
65
+ const advance = (next: number) => {
66
+ assert(next >= now && next < basis.workEndWallMs);
67
+ now = next;
68
+ };
69
+ const listeners = new Set<() => void>(),
70
+ origin = Object.freeze({});
71
+ const source = Object.freeze({
72
+ clock: Object.freeze({
73
+ basis,
74
+ sample: () => {
75
+ state.samples++;
76
+ return { wallMs: now, ns: BigInt(now) * 1000000n };
77
+ },
78
+ subscribeRetirement(fn: () => void) {
79
+ listeners.add(fn);
80
+ return () => listeners.delete(fn);
81
+ },
82
+ }),
83
+ originalPolicy: {
84
+ firstDispatchedAt: declared.original.attachRequest.firstDispatchedAt,
85
+ periodStart:
86
+ declared.original.attachRequest.preparation.expected.periodStart,
87
+ periodEnd:
88
+ declared.original.attachRequest.preparation.expected.periodEnd,
89
+ },
90
+ originAssociation: origin,
91
+ });
92
+ const NativeDate = Date;
93
+ vi.stubGlobal(
94
+ "Date",
95
+ class extends NativeDate {
96
+ constructor(value?: string | number) {
97
+ super(value ?? now);
98
+ }
99
+ static now() {
100
+ return now;
101
+ }
102
+ },
103
+ );
104
+ installPreflightDigestBarrier(gates, () => state.phase);
105
+ vi.doMock("../sourceBindings.js", () => ({
106
+ loadOwnedOriginalSource: () => source,
107
+ }));
108
+ const { OWNER } = await import("../originalOwner.js");
109
+ const originalBasis = OWNER.basis;
110
+ const actual = await installPreflightObservers(
111
+ state,
112
+ OWNER,
113
+ name,
114
+ gates,
115
+ () => advance(declared.laterAt),
116
+ () => {
117
+ throw Error("NO_RETARGET_IN_WRITER_PREREQUISITE");
118
+ },
119
+ );
120
+ const { captureRetainedInput, ownedRetainedEligibility } =
121
+ await import("../material/capture.js");
122
+ const original = captureRetainedInput(declared.original);
123
+ const prepared = await actual.prepareRenewalPriceReplacementV2(
124
+ original.attachRequest.preparation,
125
+ );
126
+ OWNER.check();
127
+ const request = await actual.prepareRenewalScheduleAttachmentV2({
128
+ prepared,
129
+ apiVersion: original.attachRequest.apiVersion,
130
+ attachKey: original.attachRequest.attachKey,
131
+ firstDispatchedAt: original.attachRequest.firstDispatchedAt,
132
+ });
133
+ OWNER.check();
134
+ const { validateOwnedReadMaterial } =
135
+ await import("../material/readMaterial.js");
136
+ const reads = validateOwnedReadMaterial(
137
+ {
138
+ apiVersion: declared.apiVersion,
139
+ observedAt: original.attachRequest.firstDispatchedAt,
140
+ freshSubscription: original.originalBundle.wireSubscription,
141
+ targetPrice: original.originalBundle.wireTargetPrice,
142
+ billingCustomer: original.originalBundle.wireBillingCustomer,
143
+ },
144
+ prepared,
145
+ undefined,
146
+ ownedRetainedEligibility(original),
147
+ );
148
+ const entries = declaredEntries(
149
+ original,
150
+ prepared,
151
+ request,
152
+ reads,
153
+ original.originalBundle,
154
+ );
155
+ const query = String(
156
+ new URLSearchParams(
157
+ ["discounts", "items.data.discounts", "items.data.price"].map(
158
+ (value, i) => ["expand[" + i + "]", value],
159
+ ),
160
+ ),
161
+ );
162
+ const paths = [
163
+ "/v1/subscriptions/" + prepared.expected.subscriptionId + "?" + query,
164
+ "/v1/prices/" + prepared.expected.targetPriceId,
165
+ "/v1/customers/" + original.originalBundle.wireBillingCustomer.id,
166
+ ...original.originalBundle.couponReads.map((row) => {
167
+ assert(typeof row.couponId === "string");
168
+ return "/v1/coupons/" + encodeURIComponent(row.couponId);
169
+ }),
170
+ ];
171
+ const row = (path: string, i: number) =>
172
+ deepFreeze({
173
+ resource:
174
+ i === 0
175
+ ? "subscription"
176
+ : i === 1
177
+ ? "price"
178
+ : i === 2
179
+ ? "customer"
180
+ : "coupon",
181
+ ordinal: i + 1,
182
+ method: "GET",
183
+ path,
184
+ body: undefined,
185
+ options: { apiVersion: declared.apiVersion, maxNetworkRetries: 0 },
186
+ });
187
+ const initialPlan = Object.freeze(paths.map(row));
188
+ const schedulePath = "/v1/subscription_schedules/" + declared.schedule.id;
189
+ const configurePlan = Object.freeze([
190
+ ...initialPlan,
191
+ deepFreeze({ ...row(schedulePath, paths.length), resource: "schedule" }),
192
+ ]);
193
+ const originalBodies = [
194
+ original.originalBundle.wireSubscription,
195
+ original.originalBundle.wireTargetPrice,
196
+ original.originalBundle.wireBillingCustomer,
197
+ ...original.originalBundle.couponReads.map((value) => value.wireCoupon),
198
+ ];
199
+ const currentBodies = [
200
+ declared.currentBundle.wireSubscription,
201
+ declared.currentBundle.wireTargetPrice,
202
+ declared.currentBundle.wireBillingCustomer,
203
+ ...declared.currentBundle.couponReads.map((value) => value.wireCoupon),
204
+ ];
205
+ const table = deepFreeze([
206
+ ...paths.map((path, i) => ({
207
+ method: "GET",
208
+ path,
209
+ body: originalBodies[i],
210
+ schedule: false,
211
+ })),
212
+ {
213
+ method: "POST",
214
+ path: "/v1/subscription_schedules",
215
+ body: declared.schedule,
216
+ schedule: false,
217
+ },
218
+ ...paths.map((path, i) => ({
219
+ method: "GET",
220
+ path,
221
+ body: currentBodies[i],
222
+ schedule: false,
223
+ })),
224
+ {
225
+ method: "GET",
226
+ path: schedulePath,
227
+ body: declared.currentSchedule,
228
+ schedule: true,
229
+ },
230
+ ]);
231
+ vi.stubGlobal("fetch", async (input: unknown, init: RequestInit) => {
232
+ const next = table[state.calls.length],
233
+ url = new URL(String(input));
234
+ assert(next, "UNDECLARED_PREFLIGHT_HTTP");
235
+ assert.equal(url.origin, "https://api.stripe.com");
236
+ assert.equal(url.pathname + url.search, next.path);
237
+ assert.equal(init.method, next.method);
238
+ assert.equal(init.redirect, "error");
239
+ assert.equal(
240
+ new Headers(init.headers).get("stripe-version"),
241
+ declared.apiVersion,
242
+ );
243
+ state.calls.push({ method: String(init.method), path: next.path });
244
+ if (next.schedule) {
245
+ await gates.hold("schedule");
246
+ advance(declared.scheduleAt);
247
+ state.scheduleReplies++;
248
+ }
249
+ return new Response(JSON.stringify(next.body), {
250
+ status: 200,
251
+ headers: {
252
+ "content-type": "application/json",
253
+ "request-id": "req_SYNTHETIC_PREFLIGHT",
254
+ },
255
+ });
256
+ });
257
+ const { getStripeClient } = await import("../../../../helpers.js");
258
+ const client = getStripeClient(
259
+ "sk_test_SYNTHETIC_PREFLIGHT_NO_CREDENTIAL",
260
+ declared.apiVersion,
261
+ { singleAttempt: true },
262
+ );
263
+ const method = client.rawRequest;
264
+ const delegate = Object.freeze({
265
+ rawRequest(...args: unknown[]) {
266
+ return Reflect.apply(method, client, args) as Promise<unknown>;
267
+ },
268
+ });
269
+ const readonlyDelegate = Object.freeze({
270
+ rawRequest(...args: unknown[]) {
271
+ state.readonlyCalls++;
272
+ assert.equal(args[0], "GET");
273
+ return Reflect.apply(method, client, args) as Promise<unknown>;
274
+ },
275
+ });
276
+ const sink = Object.freeze({
277
+ send(value: unknown, acknowledge: (value: unknown) => void) {
278
+ OWNER.check();
279
+ const record = data(value);
280
+ state.records.push(record);
281
+ acknowledge({ sequence: record.sequence, binding: record.binding });
282
+ },
283
+ });
284
+ let slotTakes = 0;
285
+ const initialOperation = Object.freeze({
286
+ owner: OWNER,
287
+ originAssociation: origin,
288
+ slot: Object.freeze({
289
+ takeOnce(owner: unknown) {
290
+ assert.equal(owner, OWNER);
291
+ assert.equal(++slotTakes, 1);
292
+ return {
293
+ rawAttachRequest: original.attachRequest,
294
+ originalBundle: original.originalBundle,
295
+ };
296
+ },
297
+ }),
298
+ readPlan: initialPlan,
299
+ delegate,
300
+ sink,
301
+ });
302
+ const initialFrame = Object.freeze({
303
+ owner: OWNER,
304
+ operation: initialOperation,
305
+ request,
306
+ readPlan: initialPlan,
307
+ delegate,
308
+ });
309
+ // Each TEST Source cell is filled once after actual initial terminal ACK, then read unchanged.
310
+ let operation: object | null = null,
311
+ configureFrame: object | null = null;
312
+ let family: ConfiguredWriteTestFamily | null = null;
313
+ const writeCoverage = Object.freeze({
314
+ originalEntry: entries.entry,
315
+ coversConfigure(record: unknown, evidence: unknown, fresh: unknown) {
316
+ assert(family);
317
+ return family.covers(record, evidence, fresh, expectedEvidence);
318
+ },
319
+ });
320
+ const coverage = Object.freeze({
321
+ originalEntry: entries.entry,
322
+ coversPreflight(record: unknown, evidence: unknown, fresh: unknown) {
323
+ state.coverage++;
324
+ assert.deepEqual(record, expectedRecord);
325
+ assert.deepEqual(evidence, expectedEvidence);
326
+ assert.deepEqual(fresh, projected);
327
+ return true;
328
+ },
329
+ });
330
+ vi.doMock("../operations/sourceOperations.js", () => ({
331
+ COMPILED_INITIAL_ENTRIES: Object.freeze([entries.entry]),
332
+ COMPILED_RECOVERY_ENTRIES: Object.freeze([]),
333
+ COMPILED_PREFLIGHT_ENTRIES: Object.freeze([coverage]),
334
+ COMPILED_CONFIGURE_WRITE_ENTRIES: Object.freeze(
335
+ mode === "empty" ? [] : [writeCoverage],
336
+ ),
337
+ loadFixedConfigureWriteOperation() {
338
+ assert(family);
339
+ return family.initialOperation();
340
+ },
341
+ loadConfigureWriteTransportSource() {
342
+ assert(family);
343
+ return family.initialFrame();
344
+ },
345
+ loadFixedConfigureReplayOperation() {
346
+ assert(family);
347
+ return family.replayOperation();
348
+ },
349
+ loadConfigureReplayTransportSource() {
350
+ assert(family);
351
+ return family.replayFrame();
352
+ },
353
+ ORIGINAL_ORIGIN_ASSOCIATION: origin,
354
+ loadFixedInitialOperation: () => initialOperation,
355
+ loadInitialOwnedTransportSource: () => initialFrame,
356
+ loadOwnedConfigureOperation() {
357
+ state.operationLoads++;
358
+ assert(operation);
359
+ return operation;
360
+ },
361
+ loadConfigureOwnedReadTransportSource() {
362
+ state.pairLoads++;
363
+ assert(configureFrame);
364
+ return configureFrame;
365
+ },
366
+ }));
367
+ const { captureOwnedInitialAttachV2 } =
368
+ await import("../operations/initialAttach.js");
369
+ const initialOutput = data(await captureOwnedInitialAttachV2().invoke());
370
+ assert.equal(
371
+ initialOutput.status,
372
+ "attach_acknowledged",
373
+ "ACTUAL_INITIAL_ACK_PREREQUISITE",
374
+ );
375
+ assert.equal(state.records.length, 3);
376
+ assert.equal(
377
+ state.calls.filter((value) => value.method === "POST").length,
378
+ 1,
379
+ );
380
+ const acknowledgement = initialOutput.receipt;
381
+ assert(acknowledgement && typeof acknowledgement === "object");
382
+ assert.deepEqual(data(acknowledgement).providerSnapshot, declared.schedule);
383
+ assert.deepEqual(data(acknowledgement).request, request);
384
+ assert.deepEqual(data(state.records[2]!.data).receipt, acknowledgement);
385
+ advance(declared.baseAt);
386
+ const goodConfiguration = {
387
+ preparation: original.attachRequest.preparation,
388
+ attachReceipt: {
389
+ attachRequest: original.attachRequest,
390
+ actualDispatch: {
391
+ scope: request.scope,
392
+ apiVersion: request.apiVersion,
393
+ method: request.method,
394
+ path: request.path,
395
+ payload: request.payload,
396
+ key: request.key,
397
+ firstDispatchedAt: request.firstDispatchedAt,
398
+ },
399
+ providerSnapshot: declared.schedule,
400
+ },
401
+ freshSubscription: declared.baselineBundle.wireSubscription,
402
+ targetPrice: declared.baselineBundle.wireTargetPrice,
403
+ billingCustomer: declared.baselineBundle.wireBillingCustomer,
404
+ schedule: declared.schedule,
405
+ apiVersion: declared.apiVersion,
406
+ observedAt: declared.configureAt,
407
+ firstDispatchedAt: declared.configureAt,
408
+ configureKey: declared.configureKey,
409
+ };
410
+ const projected =
411
+ await actual.projectRenewalConfigurationV2(goodConfiguration);
412
+ OWNER.check();
413
+ assert.equal(
414
+ projected.status,
415
+ "projected_configure_request",
416
+ "EXPANDED_NATIVE_C6_PREREQUISITE",
417
+ );
418
+ if (projected.status !== "projected_configure_request")
419
+ throw Error("EXPANDED_NATIVE_C6_PREREQUISITE");
420
+ const expectedRecord = deepFreeze({
421
+ configuration: goodConfiguration,
422
+ request: projected,
423
+ attachReceipt: acknowledgement,
424
+ originalBundle: original.originalBundle,
425
+ });
426
+ const expectedEvidence = deepFreeze({
427
+ bundle: declared.baselineBundle,
428
+ schedule: declared.schedule,
429
+ observedAt: Math.floor(declared.scheduleAt / 1000),
430
+ });
431
+ const boundRecord = expectedRecord;
432
+ operation = Object.freeze({
433
+ owner: OWNER,
434
+ originAssociation: origin,
435
+ originalEntry: entries.entry,
436
+ preflightEntry: coverage,
437
+ actualAcknowledgement: acknowledgement,
438
+ record: boundRecord,
439
+ readTransport: readonlyDelegate,
440
+ });
441
+ configureFrame = Object.freeze({
442
+ owner: OWNER,
443
+ operation,
444
+ readPlan: configurePlan,
445
+ delegate: readonlyDelegate,
446
+ });
447
+ const before = {
448
+ GET: state.calls.filter((value) => value.method === "GET").length,
449
+ POST: state.calls.filter((value) => value.method === "POST").length,
450
+ records: state.records.length,
451
+ };
452
+ state.initialFinished = true;
453
+ const beforeCapture = Object.freeze({
454
+ samples: state.samples,
455
+ operationLoads: state.operationLoads,
456
+ });
457
+ // Load the actual actor only after real initial ACK and expanded C6 prerequisites.
458
+ const subject = await import("../preflight/configurePreflight.js");
459
+ const prerequisite = {
460
+ OWNER,
461
+ declared,
462
+ state,
463
+ basis: originalBasis,
464
+ expectedRecord,
465
+ expectedEvidence,
466
+ projected,
467
+ initialOutput,
468
+ acknowledgement,
469
+ boundRecord,
470
+ directOriginal: () =>
471
+ actual.projectRenewalConfigurationV2(goodConfiguration),
472
+ beforeCapture,
473
+ capture: subject.captureOwnedConfigurePreflightV2,
474
+ gates,
475
+ deltas: () => ({
476
+ GET:
477
+ state.calls.filter((value) => value.method === "GET").length -
478
+ before.GET,
479
+ POST:
480
+ state.calls.filter((value) => value.method === "POST").length -
481
+ before.POST,
482
+ records: state.records.length - before.records,
483
+ }),
484
+ async cleanup() {
485
+ await writeGates.cleanup();
486
+ await gates.cleanup();
487
+ vi.doUnmock("../c10/publicApi.js");
488
+ cleanPreflightMocks();
489
+ },
490
+ };
491
+ const preflightOutput = await prerequisite.capture().invoke();
492
+ assertPreflightPositive(prerequisite, preflightOutput);
493
+ assert.deepEqual(declared, write.baseline, "DECLARED_INPUT_PARITY");
494
+ assertFit(expectedRecord);
495
+ assertFit(preflightOutput);
496
+ const beforeWrite = {
497
+ calls: state.calls.length,
498
+ records: state.records.length,
499
+ };
500
+ const active = await installWriteAPIObservers(
501
+ () => family?.currentObservations() ?? writeState,
502
+ writeGates,
503
+ );
504
+ installWriteDigestAccounting(writeGates);
505
+ const writeDelegate = Object.freeze({
506
+ rawRequest(...args: unknown[]) {
507
+ const state = family?.currentObservations() ?? writeState;
508
+ state.trace.push("delegate:" + String(args[0]));
509
+ state.delegateArgs.push(args);
510
+ const options = data(args[3]);
511
+ assert.equal(options.apiVersion, write.baseline.apiVersion);
512
+ assert.equal(options.maxNetworkRetries, 0);
513
+ assert.equal(
514
+ Object.prototype.hasOwnProperty.call(options, "stripeAccount"),
515
+ false,
516
+ );
517
+ const promise = Reflect.apply(method, client, args) as Promise<unknown>;
518
+ state.originalPromises.push(promise);
519
+ writeGates.pending.push(
520
+ promise.then(
521
+ () => {},
522
+ () => {},
523
+ ),
524
+ );
525
+ return promise;
526
+ },
527
+ });
528
+ family = await configureWriteTestFamily({
529
+ declared: write,
530
+ declarations,
531
+ owner: OWNER,
532
+ origin,
533
+ entry: entries.entry,
534
+ coverage: writeCoverage,
535
+ record: expectedRecord,
536
+ configuration: goodConfiguration,
537
+ preflightOutput,
538
+ acknowledgement,
539
+ plan: configurePlan,
540
+ delegate: writeDelegate,
541
+ request: projected,
542
+ firstState: writeState,
543
+ gates: writeGates,
544
+ advance,
545
+ });
546
+ const { rawReceipt, expectedReceipt, expectedACK } =
547
+ await establishWriteOracle(
548
+ active,
549
+ OWNER,
550
+ goodConfiguration,
551
+ projected,
552
+ write,
553
+ expectedRecord,
554
+ );
555
+ assert.deepEqual(
556
+ projected.payload,
557
+ write.expectedPayload,
558
+ "INDEPENDENT_COMPLETE_PAYLOAD_PREREQUISITE",
559
+ );
560
+ assertWriteTokenPreimages(prepared, expectedRecord, expectedReceipt);
561
+ assert.equal(writeGates.activeDigests.size, 0);
562
+ assert.equal(OWNER.basis, originalBasis);
563
+ logWritePrerequisites({
564
+ initialOutput,
565
+ preflightOutput,
566
+ expectedRecord,
567
+ rawReceipt,
568
+ expectedReceipt,
569
+ expectedACK,
570
+ request: projected,
571
+ state: writeState,
572
+ });
573
+ writeState.phase = "writer";
574
+ return {
575
+ ...prerequisite,
576
+ write,
577
+ writeState,
578
+ writeGates,
579
+ beforeWrite,
580
+ rawReceipt,
581
+ expectedReceipt,
582
+ expectedACK,
583
+ replayDeclaration: declareExpectedReplay(projected),
584
+ captureWriter: family.captureA,
585
+ captureReplayB: family.captureB,
586
+ captureReplayC: family.captureC,
587
+ replayStates: Object.freeze({ B: family.states.B, C: family.states.C }),
588
+ };
589
+ } catch (error) {
590
+ await writeGates.cleanup();
591
+ await gates.cleanup();
592
+ vi.doUnmock("../c10/publicApi.js");
593
+ cleanPreflightMocks();
594
+ throw error;
595
+ }
596
+ }
597
+
598
+ export type ConfigureWriteFixture = Awaited<
599
+ ReturnType<typeof configureWriteFixture>
600
+ >;