@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,344 @@
1
+ // TEST-only fixed raw baseline from immutable 0.90 Source. No SDK/V1 claims or provider evidence.
2
+ const API_VERSION = "2026-09-30.endive",
3
+ START = 1768435200,
4
+ END = 1771113600,
5
+ OBSERVED = 1768867200;
6
+ function price(id: string, product: string, interval: "month", count: number) {
7
+ return {
8
+ id,
9
+ object: "price",
10
+ product,
11
+ active: true,
12
+ livemode: false,
13
+ type: "recurring",
14
+ currency: "usd",
15
+ billing_scheme: "per_unit",
16
+ created: START - 1000,
17
+ metadata: { catalog: "retained" },
18
+ nickname: id,
19
+ unit_amount: id === "price_target" ? 2000 : 1000,
20
+ unit_amount_decimal: id === "price_target" ? "2000" : "1000",
21
+ tiers_mode: null,
22
+ transform_quantity: null,
23
+ recurring: {
24
+ interval,
25
+ interval_count: count,
26
+ usage_type: "licensed",
27
+ meter: null,
28
+ trial_period_days: null,
29
+ },
30
+ };
31
+ }
32
+
33
+ function nativePlanForPrice(p: ReturnType<typeof price>) {
34
+ return {
35
+ id: p.id,
36
+ object: "plan",
37
+ active: p.active,
38
+ amount: p.unit_amount,
39
+ amount_decimal: p.unit_amount_decimal,
40
+ billing_scheme: "per_unit",
41
+ created: p.created,
42
+ currency: p.currency,
43
+ interval: p.recurring.interval,
44
+ interval_count: p.recurring.interval_count,
45
+ livemode: p.livemode,
46
+ metadata: p.metadata,
47
+ meter: p.recurring.meter,
48
+ nickname: p.nickname,
49
+ product: p.product,
50
+ tiers_mode: null,
51
+ transform_usage: null,
52
+ trial_period_days: p.recurring.trial_period_days,
53
+ usage_type: "licensed",
54
+ };
55
+ }
56
+
57
+ function discount(level: "subscription" | "item", start: number) {
58
+ return {
59
+ id: `di_${level}`,
60
+ object: "discount",
61
+ customer: "cus_buyer",
62
+ customer_account: "acct_buyer",
63
+ start: start - 100,
64
+ end: null,
65
+ subscription: level === "subscription" ? "sub_original" : null,
66
+ subscription_item: level === "item" ? "si_original" : null,
67
+ source: {
68
+ type: "coupon",
69
+ coupon: {
70
+ id: `custom-${level}-offer`,
71
+ object: "coupon",
72
+ livemode: false,
73
+ duration: "forever",
74
+ duration_in_months: null,
75
+ amount_off: null,
76
+ currency: null,
77
+ percent_off: level === "subscription" ? 10 : 5,
78
+ max_redemptions: null,
79
+ redeem_by: null,
80
+ times_redeemed: 2,
81
+ created: start - 1000,
82
+ name: null,
83
+ metadata: { keep: "coupon" },
84
+ valid: true,
85
+ applies_to: { products: ["custom-original", "custom-target"] },
86
+ },
87
+ },
88
+ };
89
+ }
90
+
91
+ const invoiceSettings = () => ({
92
+ account_tax_ids: null,
93
+ custom_fields: null,
94
+ days_until_due: null,
95
+ description: null,
96
+ footer: null,
97
+ issuer: { type: "self" },
98
+ });
99
+
100
+ export function makeConfigureReadNativeBaseline() {
101
+ const start = START;
102
+ const end = END;
103
+ const observedAt = OBSERVED;
104
+ const currentPrice = price("price_original", "custom-original", "month", 1);
105
+ const targetPrice = {
106
+ ...price("price_target", "custom-target", "month", 1),
107
+ };
108
+ const originalItem = {
109
+ id: "si_original",
110
+ object: "subscription_item",
111
+ subscription: "sub_original",
112
+ current_period_start: start,
113
+ current_period_end: end,
114
+ quantity: 3,
115
+ price: currentPrice,
116
+ plan: nativePlanForPrice(currentPrice),
117
+ billing_thresholds: null,
118
+ current_trial: null,
119
+ tax_rates: [],
120
+ discounts: [discount("item", start)],
121
+ metadata: { seat: "retained" },
122
+ };
123
+ const subscription = {
124
+ id: "sub_original",
125
+ object: "subscription",
126
+ customer: "cus_buyer",
127
+ customer_account: "acct_buyer",
128
+ livemode: false,
129
+ status: "active",
130
+ latest_invoice: "in_original",
131
+ currency: "usd",
132
+ schedule: null,
133
+ cancel_at: null,
134
+ cancel_at_period_end: false,
135
+ canceled_at: null,
136
+ ended_at: null,
137
+ pause_collection: null,
138
+ pending_update: null,
139
+ pending_setup_intent: null,
140
+ pending_invoice_item_interval: null,
141
+ next_pending_invoice_item_invoice: null,
142
+ managed_payments: null,
143
+ billing_schedules: [],
144
+ billing_thresholds: null,
145
+ billing_mode: { type: "classic", flexible: null },
146
+ billing_cycle_anchor: start,
147
+ billing_cycle_anchor_config: null,
148
+ default_source: null,
149
+ default_payment_method: null,
150
+ application_fee_percent: null,
151
+ payment_settings: {
152
+ payment_method_options: null,
153
+ payment_method_types: null,
154
+ save_default_payment_method: "off",
155
+ },
156
+ collection_method: "charge_automatically",
157
+ days_until_due: null,
158
+ automatic_tax: { enabled: false, liability: null, disabled_reason: null },
159
+ default_tax_rates: [],
160
+ description: null,
161
+ invoice_settings: {
162
+ account_tax_ids: null,
163
+ custom_fields: null,
164
+ description: null,
165
+ footer: null,
166
+ issuer: { type: "self" },
167
+ },
168
+ on_behalf_of: null,
169
+ transfer_data: null,
170
+ discounts: [discount("subscription", start)],
171
+ metadata: { keep: "original" },
172
+ trial_start: start - 100_000,
173
+ trial_end: start - 90_000,
174
+ trial_settings: null,
175
+ items: { object: "list", has_more: false, data: [originalItem] },
176
+ };
177
+ const billingCustomer = {
178
+ id: "cus_buyer",
179
+ object: "customer",
180
+ customer_account: "acct_buyer",
181
+ livemode: false,
182
+ discount: null,
183
+ next_invoice_sequence: 3,
184
+ metadata: { keep: "customer" },
185
+ };
186
+ const expected = {
187
+ customerAccountId: "acct_buyer",
188
+ subscriptionId: "sub_original",
189
+ itemId: "si_original",
190
+ currentPriceId: "price_original",
191
+ currentProductId: "custom-original",
192
+ targetPriceId: "price_target",
193
+ targetProductId: "custom-target",
194
+ periodStart: start,
195
+ periodEnd: end,
196
+ livemode: false,
197
+ };
198
+ const phaseItem = {
199
+ price: "price_original",
200
+ plan: "price_original",
201
+ quantity: 3,
202
+ billing_thresholds: null,
203
+ tax_rates: [],
204
+ metadata: {},
205
+ discounts: [
206
+ {
207
+ discount: "di_item",
208
+ coupon: "custom-item-offer",
209
+ promotion_code: null,
210
+ },
211
+ ],
212
+ };
213
+ const defaults = {
214
+ application_fee_percent: null,
215
+ automatic_tax: { enabled: false, liability: null, disabled_reason: null },
216
+ billing_cycle_anchor: "automatic",
217
+ billing_thresholds: null,
218
+ collection_method: "charge_automatically",
219
+ default_payment_method: null,
220
+ description: null,
221
+ invoice_settings: invoiceSettings(),
222
+ on_behalf_of: null,
223
+ transfer_data: null,
224
+ };
225
+ const phase = {
226
+ start_date: start,
227
+ end_date: end,
228
+ currency: "usd",
229
+ items: [phaseItem],
230
+ add_invoice_items: [],
231
+ application_fee_percent: null,
232
+ billing_cycle_anchor: null,
233
+ billing_thresholds: null,
234
+ collection_method: null,
235
+ default_payment_method: null,
236
+ default_tax_rates: [],
237
+ description: null,
238
+ invoice_settings: null,
239
+ metadata: {},
240
+ on_behalf_of: null,
241
+ transfer_data: null,
242
+ proration_behavior: "create_prorations",
243
+ trial: false,
244
+ trial_end: null,
245
+ discounts: [
246
+ {
247
+ discount: "di_subscription",
248
+ coupon: "custom-subscription-offer",
249
+ promotion_code: null,
250
+ },
251
+ ],
252
+ };
253
+ const schedule = {
254
+ id: "sub_sched_owned",
255
+ object: "subscription_schedule",
256
+ application: null,
257
+ customer: "cus_buyer",
258
+ customer_account: "acct_buyer",
259
+ livemode: false,
260
+ subscription: "sub_original",
261
+ status: "active",
262
+ end_behavior: "release",
263
+ created: observedAt - 60,
264
+ canceled_at: null,
265
+ completed_at: null,
266
+ released_at: null,
267
+ released_subscription: null,
268
+ metadata: {},
269
+ test_clock: null,
270
+ billing_mode: subscription.billing_mode,
271
+ pause_schedules: [],
272
+ current_phase: { start_date: start, end_date: end },
273
+ default_settings: defaults,
274
+ phases: [phase],
275
+ };
276
+
277
+ const preparation = {
278
+ subscription,
279
+ targetPrice,
280
+ billingCustomer,
281
+ expected,
282
+ key: "renewal:logical-original",
283
+ };
284
+ const attachRequest = {
285
+ preparation,
286
+ apiVersion: API_VERSION,
287
+ attachKey: "renewal:attach-original",
288
+ firstDispatchedAt: observedAt - 60,
289
+ };
290
+ const subCoupon = structuredClone(subscription.discounts[0].source.coupon),
291
+ itemCoupon = structuredClone(originalItem.discounts[0].source.coupon);
292
+ const couponReads = [
293
+ {
294
+ couponId: subCoupon.id,
295
+ wireCoupon: subCoupon,
296
+ association: { resource: "coupon", ordinal: 4 },
297
+ },
298
+ {
299
+ couponId: itemCoupon.id,
300
+ wireCoupon: itemCoupon,
301
+ association: { resource: "coupon", ordinal: 5 },
302
+ },
303
+ ];
304
+ const derivedCouponJoins = {
305
+ subscription: [
306
+ {
307
+ index: 0,
308
+ discountId: "di_subscription",
309
+ originalCouponReference: structuredClone(subCoupon),
310
+ couponReadIndex: 0,
311
+ joinedDiscount: structuredClone(subscription.discounts[0]),
312
+ },
313
+ ],
314
+ item: [
315
+ {
316
+ index: 0,
317
+ discountId: "di_item",
318
+ originalCouponReference: structuredClone(itemCoupon),
319
+ couponReadIndex: 1,
320
+ joinedDiscount: structuredClone(originalItem.discounts[0]),
321
+ },
322
+ ],
323
+ };
324
+ const originalBundle = {
325
+ wireSubscription: structuredClone(subscription),
326
+ wireTargetPrice: structuredClone(targetPrice),
327
+ wireBillingCustomer: structuredClone(billingCustomer),
328
+ couponReads,
329
+ derivedCouponJoins,
330
+ };
331
+ return {
332
+ original: { attachRequest, originalBundle },
333
+ schedule,
334
+ configurationTime: observedAt,
335
+ configureKey: "renewal:configure-original",
336
+ apiVersion: API_VERSION,
337
+ clockPlan: Object.freeze({
338
+ attachSeconds: observedAt - 60,
339
+ observationSeconds: observedAt,
340
+ workSeconds: 180,
341
+ endSeconds: 210,
342
+ }),
343
+ };
344
+ }
@@ -0,0 +1,278 @@
1
+ import { expect, vi } from "vitest";
2
+ import type { RawReadTransport } from "../acquisition/rawWireSource.js";
3
+ import { makeConfigureReadNativeBaseline } from "./configureReadNativeBaseline.js";
4
+
5
+ type TraceEvent = { kind: string; child?: number; path?: string; at?: number };
6
+
7
+ /** All response bodies and test-clock cues are declared before subject constructors. */
8
+ export async function configureReadOperationFixture() {
9
+ const baseline = makeConfigureReadNativeBaseline();
10
+ const preparation = structuredClone(
11
+ baseline.original.attachRequest.preparation,
12
+ );
13
+ const schedule = structuredClone(baseline.schedule);
14
+ const currentSubscription = {
15
+ ...structuredClone(preparation.subscription),
16
+ schedule: schedule.id,
17
+ };
18
+ const expectedBundle = {
19
+ ...structuredClone(baseline.original.originalBundle),
20
+ wireSubscription: structuredClone(currentSubscription),
21
+ };
22
+ const query = String(
23
+ new URLSearchParams(
24
+ ["discounts", "items.data.discounts", "items.data.price"].map((x, i) => [
25
+ "expand[" + i + "]",
26
+ x,
27
+ ]),
28
+ ),
29
+ );
30
+ const paths = [
31
+ "/v1/subscriptions/" + preparation.expected.subscriptionId + "?" + query,
32
+ "/v1/prices/" + preparation.expected.targetPriceId,
33
+ "/v1/customers/" + preparation.billingCustomer.id,
34
+ ...expectedBundle.couponReads.map(
35
+ (row) => "/v1/coupons/" + encodeURIComponent(row.couponId),
36
+ ),
37
+ "/v1/subscription_schedules/" + schedule.id,
38
+ ];
39
+ const rows = [
40
+ { path: paths[0]!, body: currentSubscription },
41
+ { path: paths[1]!, body: preparation.targetPrice },
42
+ { path: paths[2]!, body: preparation.billingCustomer },
43
+ ...expectedBundle.couponReads.map((row, i) => ({
44
+ path: paths[3 + i]!,
45
+ body: row.wireCoupon,
46
+ })),
47
+ { path: paths[paths.length - 1]!, body: schedule },
48
+ ];
49
+ const first = baseline.clockPlan.attachSeconds;
50
+ const baseAt = baseline.clockPlan.observationSeconds * 1000 + 1001;
51
+ const scheduleAt = baseline.clockPlan.observationSeconds * 1000 + 2001;
52
+ const laterAt = baseline.clockPlan.observationSeconds * 1000 + 3001;
53
+ const basis = Object.freeze({
54
+ startWallMs: first * 1000,
55
+ startNs: BigInt(first) * 1000000000n,
56
+ workEndWallMs: (first + baseline.clockPlan.workSeconds) * 1000,
57
+ workEndNs: BigInt(first + baseline.clockPlan.workSeconds) * 1000000000n,
58
+ endWallMs: (first + baseline.clockPlan.endSeconds) * 1000,
59
+ endNs: BigInt(first + baseline.clockPlan.endSeconds) * 1000000000n,
60
+ });
61
+ let now = baseAt;
62
+ const events: TraceEvent[] = [];
63
+ const clock = Object.freeze({
64
+ basis,
65
+ sample: () => ({ wallMs: now, ns: BigInt(now) * 1000000n }),
66
+ subscribeRetirement: (_callback: () => void) => () => {},
67
+ });
68
+ const advance = (next: number) => {
69
+ expect(next).toBeGreaterThanOrEqual(now);
70
+ expect(next).toBeLessThan(basis.workEndWallMs);
71
+ now = next;
72
+ };
73
+ const httpCalls: {
74
+ url: string;
75
+ method: string | undefined;
76
+ redirect: RequestRedirect | undefined;
77
+ }[] = [];
78
+ const mechanics: {
79
+ method: string;
80
+ path: string;
81
+ body: unknown;
82
+ options: unknown;
83
+ }[] = [];
84
+ let children = 0;
85
+ let begins = 0;
86
+ let finishes = 0;
87
+ let failures = 0;
88
+
89
+ // Generated C1/C2/C3 DATA comes only from the actual maintained constructors.
90
+ const api = await import("../../../renewalV2/index.js");
91
+ const prepared = await api.prepareRenewalPriceReplacementV2(preparation);
92
+ const request = await api.prepareRenewalScheduleAttachmentV2({
93
+ prepared,
94
+ apiVersion: baseline.apiVersion,
95
+ attachKey: baseline.original.attachRequest.attachKey,
96
+ firstDispatchedAt: first,
97
+ });
98
+ const receipt = await api.constructRenewalScheduleAttachmentReceiptV2({
99
+ attachRequest: {
100
+ ...structuredClone(baseline.original.attachRequest),
101
+ preparation,
102
+ },
103
+ actualDispatch: {
104
+ scope: request.scope,
105
+ apiVersion: request.apiVersion,
106
+ method: request.method,
107
+ path: request.path,
108
+ payload: request.payload,
109
+ key: request.key,
110
+ firstDispatchedAt: request.firstDispatchedAt,
111
+ },
112
+ providerSnapshot: structuredClone(schedule),
113
+ });
114
+ expect(receipt.scheduleId).toBe(schedule.id);
115
+ expect(receipt.request).toEqual(request);
116
+ expect(receipt.providerSnapshot).toEqual(schedule);
117
+ // This receipt is pure constructor DATA. No POST, C10 ACK or Source custody exists here.
118
+
119
+ vi.stubGlobal(
120
+ "fetch",
121
+ async (input: RequestInfo | URL, init?: RequestInit) => {
122
+ const url = String(input);
123
+ expect(init?.method).toBe("GET");
124
+ expect(init?.redirect).toBe("error");
125
+ expect(new Headers(init?.headers).get("stripe-version")).toBe(
126
+ baseline.apiVersion,
127
+ );
128
+ const index = httpCalls.length;
129
+ const row = rows[index];
130
+ expect(row).toBeDefined();
131
+ if (!row) throw Error("UNDECLARED_CONFIGURE_READ");
132
+ expect(url).toBe("https://api.stripe.com" + row.path);
133
+ httpCalls.push({ url, method: init?.method, redirect: init?.redirect });
134
+ events.push({
135
+ kind: "request",
136
+ child: children,
137
+ path: row.path,
138
+ at: now,
139
+ });
140
+ if (row.path === paths[paths.length - 1]) advance(scheduleAt);
141
+ const response = new Response(JSON.stringify(row.body), {
142
+ status: 200,
143
+ headers: {
144
+ "content-type": "application/json",
145
+ "request-id": "req_SYNTHETIC_303_READONLY",
146
+ },
147
+ });
148
+ events.push({ kind: "reply", child: children, path: row.path, at: now });
149
+ return response;
150
+ },
151
+ );
152
+ const { getStripeClient } = await import("../../../../helpers.js");
153
+ const client = getStripeClient(
154
+ "sk_test_SYNTHETIC_303_READONLY_NO_CREDENTIAL",
155
+ baseline.apiVersion,
156
+ { singleAttempt: true },
157
+ );
158
+ vi.doMock("../sourceBindings.js", () => ({
159
+ loadOwnedOriginalSource: () => ({
160
+ clock,
161
+ originalPolicy: {
162
+ firstDispatchedAt: first,
163
+ periodStart: preparation.expected.periodStart,
164
+ periodEnd: preparation.expected.periodEnd,
165
+ },
166
+ originAssociation: Object.freeze({}),
167
+ }),
168
+ loadFixedStockClient: () => client,
169
+ }));
170
+ vi.doMock("../acquisition/readLifetime.js", async () => {
171
+ const actual = await vi.importActual<
172
+ typeof import("../acquisition/readLifetime.js")
173
+ >("../acquisition/readLifetime.js");
174
+ return {
175
+ ...actual,
176
+ createReadLifetime(
177
+ owner: Parameters<typeof actual.createReadLifetime>[0],
178
+ ) {
179
+ expect(owner).toBe(OWNER);
180
+ const createActual = actual.createReadLifetime;
181
+ const child = createActual(owner);
182
+ const id = ++children;
183
+ events.push({ kind: "create", child: id, at: now });
184
+ const begin = child.begin,
185
+ check = child.check,
186
+ finish = child.finish,
187
+ fail = child.fail;
188
+ return Object.freeze({
189
+ begin(...args: Parameters<typeof begin>) {
190
+ begins++;
191
+ events.push({ kind: "begin", child: id, at: now });
192
+ return Reflect.apply(begin, child, args) as ReturnType<
193
+ typeof begin
194
+ >;
195
+ },
196
+ check(...args: Parameters<typeof check>) {
197
+ return Reflect.apply(check, child, args) as ReturnType<
198
+ typeof check
199
+ >;
200
+ },
201
+ finish(...args: Parameters<typeof finish>) {
202
+ const result = Reflect.apply(finish, child, args) as ReturnType<
203
+ typeof finish
204
+ >;
205
+ finishes++;
206
+ events.push({ kind: "finish", child: id, at: result.wallMs });
207
+ advance(laterAt);
208
+ return result;
209
+ },
210
+ fail(...args: Parameters<typeof fail>) {
211
+ failures++;
212
+ events.push({ kind: "fail", child: id, at: now });
213
+ return Reflect.apply(fail, child, args) as ReturnType<typeof fail>;
214
+ },
215
+ });
216
+ },
217
+ };
218
+ });
219
+ const { OWNER } = await import("../originalOwner.js");
220
+ const { createSourceStockRawDelegate } =
221
+ await import("../stockRawDelegate.js");
222
+ const stock = createSourceStockRawDelegate();
223
+ const rawRequest = stock.rawRequest;
224
+ const transport: RawReadTransport = Object.freeze({
225
+ rawRequest(...args: Parameters<RawReadTransport["rawRequest"]>) {
226
+ const [method, path, body, options] = args;
227
+ mechanics.push({ method, path, body, options: structuredClone(options) });
228
+ return Reflect.apply(rawRequest, stock, args) as ReturnType<
229
+ RawReadTransport["rawRequest"]
230
+ >;
231
+ },
232
+ });
233
+ const scope = Object.freeze({
234
+ expected: Object.freeze(structuredClone(preparation.expected)),
235
+ scheduleId: receipt.scheduleId,
236
+ });
237
+ return {
238
+ OWNER,
239
+ transport,
240
+ scope,
241
+ receipt,
242
+ schedule,
243
+ expectedBundle,
244
+ paths,
245
+ httpCalls,
246
+ mechanics,
247
+ events,
248
+ baseAt,
249
+ scheduleAt,
250
+ laterAt,
251
+ basis,
252
+ counts: () => ({ children, begins, finishes, failures }),
253
+ };
254
+ }
255
+
256
+ export function configureReadMetrics(value: unknown) {
257
+ let nodes = 0,
258
+ depth = 0;
259
+ const active = new Set<object>();
260
+ const walk = (x: unknown, d: number) => {
261
+ nodes++;
262
+ depth = Math.max(depth, d);
263
+ if (x && typeof x === "object") {
264
+ if (active.has(x)) throw Error("TEST_CYCLE");
265
+ active.add(x);
266
+ for (const y of Object.values(x)) walk(y, d + 1);
267
+ active.delete(x);
268
+ }
269
+ };
270
+ walk(value, 0);
271
+ const text = JSON.stringify(value);
272
+ return {
273
+ chars: text.length,
274
+ bytes: new TextEncoder().encode(text).length,
275
+ nodes,
276
+ depth,
277
+ };
278
+ }
@@ -0,0 +1,17 @@
1
+ import type { OWNER } from "../originalOwner.js";
2
+ import type { RawReadTransport } from "../acquisition/rawWireSource.js";
3
+ import { bindRawAcquisitionFromSource } from "../acquisition/ownedAcquisition.js";
4
+
5
+ /** TEST-only missing-Schedule baseline. No result fields or statuses are invented. */
6
+ export function bindConfigureReadAcquisitionFromSource(
7
+ owner: typeof OWNER,
8
+ transport: RawReadTransport,
9
+ fixedScope: Readonly<{ expected: unknown; scheduleId: string }>,
10
+ ) {
11
+ const actualReader = bindRawAcquisitionFromSource(owner, transport);
12
+ return Object.freeze({
13
+ acquire() {
14
+ return actualReader.acquire(fixedScope.expected);
15
+ },
16
+ });
17
+ }