@fantastic.dev/better-stripe 0.4.0-bootstrap.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 (762) hide show
  1. package/CHANGELOG.md +318 -0
  2. package/README.md +1117 -0
  3. package/dist/client/billing/checkout.d.ts +75 -0
  4. package/dist/client/billing/checkout.d.ts.map +1 -0
  5. package/dist/client/billing/checkout.js +260 -0
  6. package/dist/client/billing/checkout.js.map +1 -0
  7. package/dist/client/billing/invoices.d.ts +37 -0
  8. package/dist/client/billing/invoices.d.ts.map +1 -0
  9. package/dist/client/billing/invoices.js +29 -0
  10. package/dist/client/billing/invoices.js.map +1 -0
  11. package/dist/client/billing/subscriptions.d.ts +179 -0
  12. package/dist/client/billing/subscriptions.d.ts.map +1 -0
  13. package/dist/client/billing/subscriptions.js +346 -0
  14. package/dist/client/billing/subscriptions.js.map +1 -0
  15. package/dist/client/connect/disputes.d.ts +112 -0
  16. package/dist/client/connect/disputes.d.ts.map +1 -0
  17. package/dist/client/connect/disputes.js +186 -0
  18. package/dist/client/connect/disputes.js.map +1 -0
  19. package/dist/client/connect/paymentMethodUtils.d.ts +17 -0
  20. package/dist/client/connect/paymentMethodUtils.d.ts.map +1 -0
  21. package/dist/client/connect/paymentMethodUtils.js +24 -0
  22. package/dist/client/connect/paymentMethodUtils.js.map +1 -0
  23. package/dist/client/connect/paymentMethods.d.ts +23 -0
  24. package/dist/client/connect/paymentMethods.d.ts.map +1 -0
  25. package/dist/client/connect/paymentMethods.js +27 -0
  26. package/dist/client/connect/paymentMethods.js.map +1 -0
  27. package/dist/client/connect/payouts.d.ts +47 -0
  28. package/dist/client/connect/payouts.d.ts.map +1 -0
  29. package/dist/client/connect/payouts.js +52 -0
  30. package/dist/client/connect/payouts.js.map +1 -0
  31. package/dist/client/connect/refundActor.d.ts +50 -0
  32. package/dist/client/connect/refundActor.d.ts.map +1 -0
  33. package/dist/client/connect/refundActor.js +17 -0
  34. package/dist/client/connect/refundActor.js.map +1 -0
  35. package/dist/client/connect/refunds.d.ts +75 -0
  36. package/dist/client/connect/refunds.d.ts.map +1 -0
  37. package/dist/client/connect/refunds.js +141 -0
  38. package/dist/client/connect/refunds.js.map +1 -0
  39. package/dist/client/connect/transfers.d.ts +189 -0
  40. package/dist/client/connect/transfers.d.ts.map +1 -0
  41. package/dist/client/connect/transfers.js +347 -0
  42. package/dist/client/connect/transfers.js.map +1 -0
  43. package/dist/client/constants.d.ts +15 -0
  44. package/dist/client/constants.d.ts.map +1 -0
  45. package/dist/client/constants.js +14 -0
  46. package/dist/client/constants.js.map +1 -0
  47. package/dist/client/core/accountLinks.d.ts +68 -0
  48. package/dist/client/core/accountLinks.d.ts.map +1 -0
  49. package/dist/client/core/accountLinks.js +131 -0
  50. package/dist/client/core/accountLinks.js.map +1 -0
  51. package/dist/client/core/accountStatus.d.ts +12 -0
  52. package/dist/client/core/accountStatus.d.ts.map +1 -0
  53. package/dist/client/core/accountStatus.js +56 -0
  54. package/dist/client/core/accountStatus.js.map +1 -0
  55. package/dist/client/core/accounts.d.ts +181 -0
  56. package/dist/client/core/accounts.d.ts.map +1 -0
  57. package/dist/client/core/accounts.js +359 -0
  58. package/dist/client/core/accounts.js.map +1 -0
  59. package/dist/client/core/config.d.ts +5 -0
  60. package/dist/client/core/config.d.ts.map +1 -0
  61. package/dist/client/core/config.js +11 -0
  62. package/dist/client/core/config.js.map +1 -0
  63. package/dist/client/core/descriptors.d.ts +24 -0
  64. package/dist/client/core/descriptors.d.ts.map +1 -0
  65. package/dist/client/core/descriptors.js +43 -0
  66. package/dist/client/core/descriptors.js.map +1 -0
  67. package/dist/client/core/fees.d.ts +83 -0
  68. package/dist/client/core/fees.d.ts.map +1 -0
  69. package/dist/client/core/fees.js +178 -0
  70. package/dist/client/core/fees.js.map +1 -0
  71. package/dist/client/errors.d.ts +20 -0
  72. package/dist/client/errors.d.ts.map +1 -0
  73. package/dist/client/errors.js +31 -0
  74. package/dist/client/errors.js.map +1 -0
  75. package/dist/client/helpers.d.ts +20 -0
  76. package/dist/client/helpers.d.ts.map +1 -0
  77. package/dist/client/helpers.js +46 -0
  78. package/dist/client/helpers.js.map +1 -0
  79. package/dist/client/index.d.ts +880 -0
  80. package/dist/client/index.d.ts.map +1 -0
  81. package/dist/client/index.js +791 -0
  82. package/dist/client/index.js.map +1 -0
  83. package/dist/client/products/prices.d.ts +61 -0
  84. package/dist/client/products/prices.d.ts.map +1 -0
  85. package/dist/client/products/prices.js +92 -0
  86. package/dist/client/products/prices.js.map +1 -0
  87. package/dist/client/products/products.d.ts +65 -0
  88. package/dist/client/products/products.d.ts.map +1 -0
  89. package/dist/client/products/products.js +186 -0
  90. package/dist/client/products/products.js.map +1 -0
  91. package/dist/client/stripe-types.d.ts +44 -0
  92. package/dist/client/stripe-types.d.ts.map +1 -0
  93. package/dist/client/stripe-types.js +2 -0
  94. package/dist/client/stripe-types.js.map +1 -0
  95. package/dist/client/types/documents.d.ts +195 -0
  96. package/dist/client/types/documents.d.ts.map +1 -0
  97. package/dist/client/types/documents.js +2 -0
  98. package/dist/client/types/documents.js.map +1 -0
  99. package/dist/client/types/events.d.ts +43 -0
  100. package/dist/client/types/events.d.ts.map +1 -0
  101. package/dist/client/types/events.js +2 -0
  102. package/dist/client/types/events.js.map +1 -0
  103. package/dist/client/types/index.d.ts +5 -0
  104. package/dist/client/types/index.d.ts.map +1 -0
  105. package/dist/client/types/index.js +2 -0
  106. package/dist/client/types/index.js.map +1 -0
  107. package/dist/client/types/options.d.ts +79 -0
  108. package/dist/client/types/options.d.ts.map +1 -0
  109. package/dist/client/types/options.js +2 -0
  110. package/dist/client/types/options.js.map +1 -0
  111. package/dist/client/types/triggers.d.ts +101 -0
  112. package/dist/client/types/triggers.d.ts.map +1 -0
  113. package/dist/client/types/triggers.js +2 -0
  114. package/dist/client/types/triggers.js.map +1 -0
  115. package/dist/client/types.d.ts +2 -0
  116. package/dist/client/types.d.ts.map +1 -0
  117. package/dist/client/types.js +2 -0
  118. package/dist/client/types.js.map +1 -0
  119. package/dist/client/utils/data.d.ts +10 -0
  120. package/dist/client/utils/data.d.ts.map +1 -0
  121. package/dist/client/utils/data.js +13 -0
  122. package/dist/client/utils/data.js.map +1 -0
  123. package/dist/client/utils/owner.d.ts +22 -0
  124. package/dist/client/utils/owner.d.ts.map +1 -0
  125. package/dist/client/utils/owner.js +20 -0
  126. package/dist/client/utils/owner.js.map +1 -0
  127. package/dist/client/utils/stripeDashboardUrl.d.ts +12 -0
  128. package/dist/client/utils/stripeDashboardUrl.d.ts.map +1 -0
  129. package/dist/client/utils/stripeDashboardUrl.js +39 -0
  130. package/dist/client/utils/stripeDashboardUrl.js.map +1 -0
  131. package/dist/client/utils/webhookEndpoints.d.ts +83 -0
  132. package/dist/client/utils/webhookEndpoints.d.ts.map +1 -0
  133. package/dist/client/utils/webhookEndpoints.js +185 -0
  134. package/dist/client/utils/webhookEndpoints.js.map +1 -0
  135. package/dist/client/webhooks/handler.d.ts +4 -0
  136. package/dist/client/webhooks/handler.d.ts.map +1 -0
  137. package/dist/client/webhooks/handler.js +170 -0
  138. package/dist/client/webhooks/handler.js.map +1 -0
  139. package/dist/client/webhooks/helpers.d.ts +56 -0
  140. package/dist/client/webhooks/helpers.d.ts.map +1 -0
  141. package/dist/client/webhooks/helpers.js +229 -0
  142. package/dist/client/webhooks/helpers.js.map +1 -0
  143. package/dist/client/webhooks/hooks.d.ts +11 -0
  144. package/dist/client/webhooks/hooks.d.ts.map +1 -0
  145. package/dist/client/webhooks/hooks.js +134 -0
  146. package/dist/client/webhooks/hooks.js.map +1 -0
  147. package/dist/client/webhooks/index.d.ts +23 -0
  148. package/dist/client/webhooks/index.d.ts.map +1 -0
  149. package/dist/client/webhooks/index.js +35 -0
  150. package/dist/client/webhooks/index.js.map +1 -0
  151. package/dist/client/webhooks/processors.d.ts +4 -0
  152. package/dist/client/webhooks/processors.d.ts.map +1 -0
  153. package/dist/client/webhooks/processors.js +932 -0
  154. package/dist/client/webhooks/processors.js.map +1 -0
  155. package/dist/client/webhooks/v2.d.ts +11 -0
  156. package/dist/client/webhooks/v2.d.ts.map +1 -0
  157. package/dist/client/webhooks/v2.js +94 -0
  158. package/dist/client/webhooks/v2.js.map +1 -0
  159. package/dist/client/webhooks.d.ts +2 -0
  160. package/dist/client/webhooks.d.ts.map +1 -0
  161. package/dist/client/webhooks.js +4 -0
  162. package/dist/client/webhooks.js.map +1 -0
  163. package/dist/component/_generated/component.d.ts +1262 -0
  164. package/dist/component/_generated/component.d.ts.map +1 -0
  165. package/dist/component/_generated/component.js +11 -0
  166. package/dist/component/_generated/component.js.map +1 -0
  167. package/dist/component/_generated/dataModel.d.ts +46 -0
  168. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  169. package/dist/component/_generated/dataModel.js +11 -0
  170. package/dist/component/_generated/dataModel.js.map +1 -0
  171. package/dist/component/_generated/server.d.ts +129 -0
  172. package/dist/component/_generated/server.d.ts.map +1 -0
  173. package/dist/component/_generated/server.js +79 -0
  174. package/dist/component/_generated/server.js.map +1 -0
  175. package/dist/component/billing/mutations.d.ts +86 -0
  176. package/dist/component/billing/mutations.d.ts.map +1 -0
  177. package/dist/component/billing/mutations.js +131 -0
  178. package/dist/component/billing/mutations.js.map +1 -0
  179. package/dist/component/billing/queries.d.ts +425 -0
  180. package/dist/component/billing/queries.d.ts.map +1 -0
  181. package/dist/component/billing/queries.js +304 -0
  182. package/dist/component/billing/queries.js.map +1 -0
  183. package/dist/component/billing/schema.d.ts +228 -0
  184. package/dist/component/billing/schema.d.ts.map +1 -0
  185. package/dist/component/billing/schema.js +33 -0
  186. package/dist/component/billing/schema.js.map +1 -0
  187. package/dist/component/billing/validators.d.ts +364 -0
  188. package/dist/component/billing/validators.d.ts.map +1 -0
  189. package/dist/component/billing/validators.js +98 -0
  190. package/dist/component/billing/validators.js.map +1 -0
  191. package/dist/component/connect/mutations.d.ts +182 -0
  192. package/dist/component/connect/mutations.d.ts.map +1 -0
  193. package/dist/component/connect/mutations.js +480 -0
  194. package/dist/component/connect/mutations.js.map +1 -0
  195. package/dist/component/connect/queries.d.ts +347 -0
  196. package/dist/component/connect/queries.d.ts.map +1 -0
  197. package/dist/component/connect/queries.js +449 -0
  198. package/dist/component/connect/queries.js.map +1 -0
  199. package/dist/component/connect/schema.d.ts +258 -0
  200. package/dist/component/connect/schema.d.ts.map +1 -0
  201. package/dist/component/connect/schema.js +70 -0
  202. package/dist/component/connect/schema.js.map +1 -0
  203. package/dist/component/connect/validators.d.ts +468 -0
  204. package/dist/component/connect/validators.d.ts.map +1 -0
  205. package/dist/component/connect/validators.js +250 -0
  206. package/dist/component/connect/validators.js.map +1 -0
  207. package/dist/component/convex.config.d.ts +5 -0
  208. package/dist/component/convex.config.d.ts.map +1 -0
  209. package/dist/component/convex.config.js +17 -0
  210. package/dist/component/convex.config.js.map +1 -0
  211. package/dist/component/core/mutations.d.ts +52 -0
  212. package/dist/component/core/mutations.d.ts.map +1 -0
  213. package/dist/component/core/mutations.js +153 -0
  214. package/dist/component/core/mutations.js.map +1 -0
  215. package/dist/component/core/queries.d.ts +95 -0
  216. package/dist/component/core/queries.d.ts.map +1 -0
  217. package/dist/component/core/queries.js +86 -0
  218. package/dist/component/core/queries.js.map +1 -0
  219. package/dist/component/core/schema.d.ts +41 -0
  220. package/dist/component/core/schema.d.ts.map +1 -0
  221. package/dist/component/core/schema.js +12 -0
  222. package/dist/component/core/schema.js.map +1 -0
  223. package/dist/component/core/validators.d.ts +65 -0
  224. package/dist/component/core/validators.d.ts.map +1 -0
  225. package/dist/component/core/validators.js +35 -0
  226. package/dist/component/core/validators.js.map +1 -0
  227. package/dist/component/lib/fees.d.ts +74 -0
  228. package/dist/component/lib/fees.d.ts.map +1 -0
  229. package/dist/component/lib/fees.js +51 -0
  230. package/dist/component/lib/fees.js.map +1 -0
  231. package/dist/component/lib/idempotency.d.ts +9 -0
  232. package/dist/component/lib/idempotency.d.ts.map +1 -0
  233. package/dist/component/lib/idempotency.js +18 -0
  234. package/dist/component/lib/idempotency.js.map +1 -0
  235. package/dist/component/lib/reversals.d.ts +48 -0
  236. package/dist/component/lib/reversals.d.ts.map +1 -0
  237. package/dist/component/lib/reversals.js +79 -0
  238. package/dist/component/lib/reversals.js.map +1 -0
  239. package/dist/component/lib/stripeFactory.d.ts +7 -0
  240. package/dist/component/lib/stripeFactory.d.ts.map +1 -0
  241. package/dist/component/lib/stripeFactory.js +28 -0
  242. package/dist/component/lib/stripeFactory.js.map +1 -0
  243. package/dist/component/products/mutations.d.ts +22 -0
  244. package/dist/component/products/mutations.d.ts.map +1 -0
  245. package/dist/component/products/mutations.js +63 -0
  246. package/dist/component/products/mutations.js.map +1 -0
  247. package/dist/component/products/queries.d.ts +109 -0
  248. package/dist/component/products/queries.d.ts.map +1 -0
  249. package/dist/component/products/queries.js +122 -0
  250. package/dist/component/products/queries.js.map +1 -0
  251. package/dist/component/products/schema.d.ts +58 -0
  252. package/dist/component/products/schema.d.ts.map +1 -0
  253. package/dist/component/products/schema.js +20 -0
  254. package/dist/component/products/schema.js.map +1 -0
  255. package/dist/component/products/validators.d.ts +86 -0
  256. package/dist/component/products/validators.d.ts.map +1 -0
  257. package/dist/component/products/validators.js +47 -0
  258. package/dist/component/products/validators.js.map +1 -0
  259. package/dist/component/schema.d.ts +555 -0
  260. package/dist/component/schema.d.ts.map +1 -0
  261. package/dist/component/schema.js +28 -0
  262. package/dist/component/schema.js.map +1 -0
  263. package/dist/component/webhooks/mutations.d.ts +30 -0
  264. package/dist/component/webhooks/mutations.d.ts.map +1 -0
  265. package/dist/component/webhooks/mutations.js +124 -0
  266. package/dist/component/webhooks/mutations.js.map +1 -0
  267. package/dist/component/webhooks/queries.d.ts +35 -0
  268. package/dist/component/webhooks/queries.d.ts.map +1 -0
  269. package/dist/component/webhooks/queries.js +41 -0
  270. package/dist/component/webhooks/queries.js.map +1 -0
  271. package/dist/component/webhooks/schema.d.ts +22 -0
  272. package/dist/component/webhooks/schema.d.ts.map +1 -0
  273. package/dist/component/webhooks/schema.js +9 -0
  274. package/dist/component/webhooks/schema.js.map +1 -0
  275. package/dist/component/webhooks/validators.d.ts +37 -0
  276. package/dist/component/webhooks/validators.d.ts.map +1 -0
  277. package/dist/component/webhooks/validators.js +22 -0
  278. package/dist/component/webhooks/validators.js.map +1 -0
  279. package/dist/react/components/AccountCloseButton.d.ts +42 -0
  280. package/dist/react/components/AccountCloseButton.d.ts.map +1 -0
  281. package/dist/react/components/AccountCloseButton.js +33 -0
  282. package/dist/react/components/AccountCloseButton.js.map +1 -0
  283. package/dist/react/components/AccountCloseCard.d.ts +31 -0
  284. package/dist/react/components/AccountCloseCard.d.ts.map +1 -0
  285. package/dist/react/components/AccountCloseCard.js +22 -0
  286. package/dist/react/components/AccountCloseCard.js.map +1 -0
  287. package/dist/react/components/AccountCreateButton.d.ts +37 -0
  288. package/dist/react/components/AccountCreateButton.d.ts.map +1 -0
  289. package/dist/react/components/AccountCreateButton.js +30 -0
  290. package/dist/react/components/AccountCreateButton.js.map +1 -0
  291. package/dist/react/components/AccountCreateCard.d.ts +48 -0
  292. package/dist/react/components/AccountCreateCard.d.ts.map +1 -0
  293. package/dist/react/components/AccountCreateCard.js +29 -0
  294. package/dist/react/components/AccountCreateCard.js.map +1 -0
  295. package/dist/react/components/AccountLoginButton.d.ts +31 -0
  296. package/dist/react/components/AccountLoginButton.d.ts.map +1 -0
  297. package/dist/react/components/AccountLoginButton.js +31 -0
  298. package/dist/react/components/AccountLoginButton.js.map +1 -0
  299. package/dist/react/components/AccountLoginCard.d.ts +33 -0
  300. package/dist/react/components/AccountLoginCard.d.ts.map +1 -0
  301. package/dist/react/components/AccountLoginCard.js +19 -0
  302. package/dist/react/components/AccountLoginCard.js.map +1 -0
  303. package/dist/react/components/AccountOnboardingButton.d.ts +37 -0
  304. package/dist/react/components/AccountOnboardingButton.d.ts.map +1 -0
  305. package/dist/react/components/AccountOnboardingButton.js +30 -0
  306. package/dist/react/components/AccountOnboardingButton.js.map +1 -0
  307. package/dist/react/components/AccountOnboardingCard.d.ts +56 -0
  308. package/dist/react/components/AccountOnboardingCard.d.ts.map +1 -0
  309. package/dist/react/components/AccountOnboardingCard.js +36 -0
  310. package/dist/react/components/AccountOnboardingCard.js.map +1 -0
  311. package/dist/react/components/AddCardForm.d.ts +18 -0
  312. package/dist/react/components/AddCardForm.d.ts.map +1 -0
  313. package/dist/react/components/AddCardForm.js +49 -0
  314. package/dist/react/components/AddCardForm.js.map +1 -0
  315. package/dist/react/components/BillingPortalLink.d.ts +23 -0
  316. package/dist/react/components/BillingPortalLink.d.ts.map +1 -0
  317. package/dist/react/components/BillingPortalLink.js +55 -0
  318. package/dist/react/components/BillingPortalLink.js.map +1 -0
  319. package/dist/react/components/BuyerBillingView.d.ts +80 -0
  320. package/dist/react/components/BuyerBillingView.d.ts.map +1 -0
  321. package/dist/react/components/BuyerBillingView.js +44 -0
  322. package/dist/react/components/BuyerBillingView.js.map +1 -0
  323. package/dist/react/components/CheckoutSessionProvider.d.ts +34 -0
  324. package/dist/react/components/CheckoutSessionProvider.d.ts.map +1 -0
  325. package/dist/react/components/CheckoutSessionProvider.js +38 -0
  326. package/dist/react/components/CheckoutSessionProvider.js.map +1 -0
  327. package/dist/react/components/CheckoutSessionProviderWithKey.d.ts +36 -0
  328. package/dist/react/components/CheckoutSessionProviderWithKey.d.ts.map +1 -0
  329. package/dist/react/components/CheckoutSessionProviderWithKey.js +36 -0
  330. package/dist/react/components/CheckoutSessionProviderWithKey.js.map +1 -0
  331. package/dist/react/components/CheckoutStatus.d.ts +25 -0
  332. package/dist/react/components/CheckoutStatus.d.ts.map +1 -0
  333. package/dist/react/components/CheckoutStatus.js +22 -0
  334. package/dist/react/components/CheckoutStatus.js.map +1 -0
  335. package/dist/react/components/ConnectProvider.d.ts +29 -0
  336. package/dist/react/components/ConnectProvider.d.ts.map +1 -0
  337. package/dist/react/components/ConnectProvider.js +25 -0
  338. package/dist/react/components/ConnectProvider.js.map +1 -0
  339. package/dist/react/components/ConnectRequirements.d.ts +55 -0
  340. package/dist/react/components/ConnectRequirements.d.ts.map +1 -0
  341. package/dist/react/components/ConnectRequirements.js +58 -0
  342. package/dist/react/components/ConnectRequirements.js.map +1 -0
  343. package/dist/react/components/ConnectStatusBadge.d.ts +26 -0
  344. package/dist/react/components/ConnectStatusBadge.d.ts.map +1 -0
  345. package/dist/react/components/ConnectStatusBadge.js +20 -0
  346. package/dist/react/components/ConnectStatusBadge.js.map +1 -0
  347. package/dist/react/components/DeletePaymentMethodDialog.d.ts +25 -0
  348. package/dist/react/components/DeletePaymentMethodDialog.d.ts.map +1 -0
  349. package/dist/react/components/DeletePaymentMethodDialog.js +16 -0
  350. package/dist/react/components/DeletePaymentMethodDialog.js.map +1 -0
  351. package/dist/react/components/DisputeDetail.d.ts +42 -0
  352. package/dist/react/components/DisputeDetail.d.ts.map +1 -0
  353. package/dist/react/components/DisputeDetail.js +34 -0
  354. package/dist/react/components/DisputeDetail.js.map +1 -0
  355. package/dist/react/components/DisputesList.d.ts +42 -0
  356. package/dist/react/components/DisputesList.d.ts.map +1 -0
  357. package/dist/react/components/DisputesList.js +47 -0
  358. package/dist/react/components/DisputesList.js.map +1 -0
  359. package/dist/react/components/EarningsSummary.d.ts +53 -0
  360. package/dist/react/components/EarningsSummary.d.ts.map +1 -0
  361. package/dist/react/components/EarningsSummary.js +37 -0
  362. package/dist/react/components/EarningsSummary.js.map +1 -0
  363. package/dist/react/components/EmbeddedCheckout.d.ts +18 -0
  364. package/dist/react/components/EmbeddedCheckout.d.ts.map +1 -0
  365. package/dist/react/components/EmbeddedCheckout.js +17 -0
  366. package/dist/react/components/EmbeddedCheckout.js.map +1 -0
  367. package/dist/react/components/EmbeddedDisputes.d.ts +21 -0
  368. package/dist/react/components/EmbeddedDisputes.d.ts.map +1 -0
  369. package/dist/react/components/EmbeddedDisputes.js +17 -0
  370. package/dist/react/components/EmbeddedDisputes.js.map +1 -0
  371. package/dist/react/components/EvidenceForm.d.ts +63 -0
  372. package/dist/react/components/EvidenceForm.d.ts.map +1 -0
  373. package/dist/react/components/EvidenceForm.js +79 -0
  374. package/dist/react/components/EvidenceForm.js.map +1 -0
  375. package/dist/react/components/IntervalSelector.d.ts +20 -0
  376. package/dist/react/components/IntervalSelector.d.ts.map +1 -0
  377. package/dist/react/components/IntervalSelector.js +15 -0
  378. package/dist/react/components/IntervalSelector.js.map +1 -0
  379. package/dist/react/components/PaymentMethodActions.d.ts +27 -0
  380. package/dist/react/components/PaymentMethodActions.d.ts.map +1 -0
  381. package/dist/react/components/PaymentMethodActions.js +23 -0
  382. package/dist/react/components/PaymentMethodActions.js.map +1 -0
  383. package/dist/react/components/PaymentMethodsList.d.ts +32 -0
  384. package/dist/react/components/PaymentMethodsList.d.ts.map +1 -0
  385. package/dist/react/components/PaymentMethodsList.js +18 -0
  386. package/dist/react/components/PaymentMethodsList.js.map +1 -0
  387. package/dist/react/components/PayoutSchedule.d.ts +55 -0
  388. package/dist/react/components/PayoutSchedule.d.ts.map +1 -0
  389. package/dist/react/components/PayoutSchedule.js +51 -0
  390. package/dist/react/components/PayoutSchedule.js.map +1 -0
  391. package/dist/react/components/PriceBadge.d.ts +19 -0
  392. package/dist/react/components/PriceBadge.d.ts.map +1 -0
  393. package/dist/react/components/PriceBadge.js +25 -0
  394. package/dist/react/components/PriceBadge.js.map +1 -0
  395. package/dist/react/components/PriceCard.d.ts +34 -0
  396. package/dist/react/components/PriceCard.d.ts.map +1 -0
  397. package/dist/react/components/PriceCard.js +20 -0
  398. package/dist/react/components/PriceCard.js.map +1 -0
  399. package/dist/react/components/PricePicker.d.ts +28 -0
  400. package/dist/react/components/PricePicker.d.ts.map +1 -0
  401. package/dist/react/components/PricePicker.js +32 -0
  402. package/dist/react/components/PricePicker.js.map +1 -0
  403. package/dist/react/components/SplitBreakdown.d.ts +45 -0
  404. package/dist/react/components/SplitBreakdown.d.ts.map +1 -0
  405. package/dist/react/components/SplitBreakdown.js +48 -0
  406. package/dist/react/components/SplitBreakdown.js.map +1 -0
  407. package/dist/react/components/StripeProvider.d.ts +30 -0
  408. package/dist/react/components/StripeProvider.d.ts.map +1 -0
  409. package/dist/react/components/StripeProvider.js +38 -0
  410. package/dist/react/components/StripeProvider.js.map +1 -0
  411. package/dist/react/components/StripeProviderWithKey.d.ts +33 -0
  412. package/dist/react/components/StripeProviderWithKey.d.ts.map +1 -0
  413. package/dist/react/components/StripeProviderWithKey.js +44 -0
  414. package/dist/react/components/StripeProviderWithKey.js.map +1 -0
  415. package/dist/react/components/SubscriptionActions.d.ts +31 -0
  416. package/dist/react/components/SubscriptionActions.d.ts.map +1 -0
  417. package/dist/react/components/SubscriptionActions.js +30 -0
  418. package/dist/react/components/SubscriptionActions.js.map +1 -0
  419. package/dist/react/components/SubscriptionCard.d.ts +41 -0
  420. package/dist/react/components/SubscriptionCard.d.ts.map +1 -0
  421. package/dist/react/components/SubscriptionCard.js +18 -0
  422. package/dist/react/components/SubscriptionCard.js.map +1 -0
  423. package/dist/react/components/SubscriptionLineItems.d.ts +23 -0
  424. package/dist/react/components/SubscriptionLineItems.d.ts.map +1 -0
  425. package/dist/react/components/SubscriptionLineItems.js +20 -0
  426. package/dist/react/components/SubscriptionLineItems.js.map +1 -0
  427. package/dist/react/components/TrialAlert.d.ts +19 -0
  428. package/dist/react/components/TrialAlert.d.ts.map +1 -0
  429. package/dist/react/components/TrialAlert.js +16 -0
  430. package/dist/react/components/TrialAlert.js.map +1 -0
  431. package/dist/react/hooks/useAccount.d.ts +14 -0
  432. package/dist/react/hooks/useAccount.d.ts.map +1 -0
  433. package/dist/react/hooks/useAccount.js +18 -0
  434. package/dist/react/hooks/useAccount.js.map +1 -0
  435. package/dist/react/hooks/useAccountOnboarding.d.ts +15 -0
  436. package/dist/react/hooks/useAccountOnboarding.d.ts.map +1 -0
  437. package/dist/react/hooks/useAccountOnboarding.js +19 -0
  438. package/dist/react/hooks/useAccountOnboarding.js.map +1 -0
  439. package/dist/react/hooks/useCheckout.d.ts +14 -0
  440. package/dist/react/hooks/useCheckout.d.ts.map +1 -0
  441. package/dist/react/hooks/useCheckout.js +18 -0
  442. package/dist/react/hooks/useCheckout.js.map +1 -0
  443. package/dist/react/hooks/useCheckoutSession.d.ts +62 -0
  444. package/dist/react/hooks/useCheckoutSession.d.ts.map +1 -0
  445. package/dist/react/hooks/useCheckoutSession.js +68 -0
  446. package/dist/react/hooks/useCheckoutSession.js.map +1 -0
  447. package/dist/react/hooks/useConfirmPayment.d.ts +38 -0
  448. package/dist/react/hooks/useConfirmPayment.d.ts.map +1 -0
  449. package/dist/react/hooks/useConfirmPayment.js +91 -0
  450. package/dist/react/hooks/useConfirmPayment.js.map +1 -0
  451. package/dist/react/hooks/useDisputeWithCountdown.d.ts +25 -0
  452. package/dist/react/hooks/useDisputeWithCountdown.d.ts.map +1 -0
  453. package/dist/react/hooks/useDisputeWithCountdown.js +19 -0
  454. package/dist/react/hooks/useDisputeWithCountdown.js.map +1 -0
  455. package/dist/react/hooks/useDisputes.d.ts +14 -0
  456. package/dist/react/hooks/useDisputes.d.ts.map +1 -0
  457. package/dist/react/hooks/useDisputes.js +15 -0
  458. package/dist/react/hooks/useDisputes.js.map +1 -0
  459. package/dist/react/hooks/useEarnings.d.ts +92 -0
  460. package/dist/react/hooks/useEarnings.d.ts.map +1 -0
  461. package/dist/react/hooks/useEarnings.js +35 -0
  462. package/dist/react/hooks/useEarnings.js.map +1 -0
  463. package/dist/react/hooks/useInvoices.d.ts +11 -0
  464. package/dist/react/hooks/useInvoices.d.ts.map +1 -0
  465. package/dist/react/hooks/useInvoices.js +11 -0
  466. package/dist/react/hooks/useInvoices.js.map +1 -0
  467. package/dist/react/hooks/usePaymentMethodActions.d.ts +74 -0
  468. package/dist/react/hooks/usePaymentMethodActions.d.ts.map +1 -0
  469. package/dist/react/hooks/usePaymentMethodActions.js +156 -0
  470. package/dist/react/hooks/usePaymentMethodActions.js.map +1 -0
  471. package/dist/react/hooks/usePaymentMethods.d.ts +23 -0
  472. package/dist/react/hooks/usePaymentMethods.d.ts.map +1 -0
  473. package/dist/react/hooks/usePaymentMethods.js +18 -0
  474. package/dist/react/hooks/usePaymentMethods.js.map +1 -0
  475. package/dist/react/hooks/usePrices.d.ts +12 -0
  476. package/dist/react/hooks/usePrices.d.ts.map +1 -0
  477. package/dist/react/hooks/usePrices.js +16 -0
  478. package/dist/react/hooks/usePrices.js.map +1 -0
  479. package/dist/react/hooks/useProducts.d.ts +10 -0
  480. package/dist/react/hooks/useProducts.d.ts.map +1 -0
  481. package/dist/react/hooks/useProducts.js +11 -0
  482. package/dist/react/hooks/useProducts.js.map +1 -0
  483. package/dist/react/hooks/useSplitBreakdown.d.ts +58 -0
  484. package/dist/react/hooks/useSplitBreakdown.d.ts.map +1 -0
  485. package/dist/react/hooks/useSplitBreakdown.js +59 -0
  486. package/dist/react/hooks/useSplitBreakdown.js.map +1 -0
  487. package/dist/react/hooks/useStripeConfig.d.ts +14 -0
  488. package/dist/react/hooks/useStripeConfig.d.ts.map +1 -0
  489. package/dist/react/hooks/useStripeConfig.js +21 -0
  490. package/dist/react/hooks/useStripeConfig.js.map +1 -0
  491. package/dist/react/hooks/useStripeMode.d.ts +3 -0
  492. package/dist/react/hooks/useStripeMode.d.ts.map +1 -0
  493. package/dist/react/hooks/useStripeMode.js +6 -0
  494. package/dist/react/hooks/useStripeMode.js.map +1 -0
  495. package/dist/react/hooks/useStripePublishableKey.d.ts +2 -0
  496. package/dist/react/hooks/useStripePublishableKey.d.ts.map +1 -0
  497. package/dist/react/hooks/useStripePublishableKey.js +6 -0
  498. package/dist/react/hooks/useStripePublishableKey.js.map +1 -0
  499. package/dist/react/hooks/useSubscription.d.ts +17 -0
  500. package/dist/react/hooks/useSubscription.d.ts.map +1 -0
  501. package/dist/react/hooks/useSubscription.js +30 -0
  502. package/dist/react/hooks/useSubscription.js.map +1 -0
  503. package/dist/react/hooks/useSubscriptions.d.ts +11 -0
  504. package/dist/react/hooks/useSubscriptions.d.ts.map +1 -0
  505. package/dist/react/hooks/useSubscriptions.js +13 -0
  506. package/dist/react/hooks/useSubscriptions.js.map +1 -0
  507. package/dist/react/index.d.ts +108 -0
  508. package/dist/react/index.d.ts.map +1 -0
  509. package/dist/react/index.js +87 -0
  510. package/dist/react/index.js.map +1 -0
  511. package/dist/react/lib/connect-requirement-keys.d.ts +14 -0
  512. package/dist/react/lib/connect-requirement-keys.d.ts.map +1 -0
  513. package/dist/react/lib/connect-requirement-keys.js +57 -0
  514. package/dist/react/lib/connect-requirement-keys.js.map +1 -0
  515. package/dist/react/lib/price-helpers.d.ts +31 -0
  516. package/dist/react/lib/price-helpers.d.ts.map +1 -0
  517. package/dist/react/lib/price-helpers.js +46 -0
  518. package/dist/react/lib/price-helpers.js.map +1 -0
  519. package/dist/react/lib/stripe-element-styles.d.ts +91 -0
  520. package/dist/react/lib/stripe-element-styles.d.ts.map +1 -0
  521. package/dist/react/lib/stripe-element-styles.js +131 -0
  522. package/dist/react/lib/stripe-element-styles.js.map +1 -0
  523. package/dist/react/lib/subscription-helpers.d.ts +33 -0
  524. package/dist/react/lib/subscription-helpers.d.ts.map +1 -0
  525. package/dist/react/lib/subscription-helpers.js +47 -0
  526. package/dist/react/lib/subscription-helpers.js.map +1 -0
  527. package/dist/react/types.d.ts +20 -0
  528. package/dist/react/types.d.ts.map +1 -0
  529. package/dist/react/types.js +2 -0
  530. package/dist/react/types.js.map +1 -0
  531. package/dist/testing/assert-test-env.d.ts +6 -0
  532. package/dist/testing/assert-test-env.d.ts.map +1 -0
  533. package/dist/testing/assert-test-env.js +15 -0
  534. package/dist/testing/assert-test-env.js.map +1 -0
  535. package/dist/testing/fixtures.d.ts +38 -0
  536. package/dist/testing/fixtures.d.ts.map +1 -0
  537. package/dist/testing/fixtures.js +54 -0
  538. package/dist/testing/fixtures.js.map +1 -0
  539. package/dist/testing/index.d.ts +4 -0
  540. package/dist/testing/index.d.ts.map +1 -0
  541. package/dist/testing/index.js +4 -0
  542. package/dist/testing/index.js.map +1 -0
  543. package/dist/testing/mock-webhooks.d.ts +19 -0
  544. package/dist/testing/mock-webhooks.d.ts.map +1 -0
  545. package/dist/testing/mock-webhooks.js +81 -0
  546. package/dist/testing/mock-webhooks.js.map +1 -0
  547. package/package.json +131 -0
  548. package/src/client/billing/checkout.test.ts +1234 -0
  549. package/src/client/billing/checkout.ts +416 -0
  550. package/src/client/billing/invoices.test.ts +237 -0
  551. package/src/client/billing/invoices.ts +93 -0
  552. package/src/client/billing/subscriptions.test.ts +987 -0
  553. package/src/client/billing/subscriptions.ts +604 -0
  554. package/src/client/component-api-types.test.ts +137 -0
  555. package/src/client/connect/disputes.test.ts +487 -0
  556. package/src/client/connect/disputes.ts +302 -0
  557. package/src/client/connect/paymentMethodUtils.test.ts +83 -0
  558. package/src/client/connect/paymentMethodUtils.ts +28 -0
  559. package/src/client/connect/paymentMethods.test.ts +66 -0
  560. package/src/client/connect/paymentMethods.ts +55 -0
  561. package/src/client/connect/payouts.test.ts +132 -0
  562. package/src/client/connect/payouts.ts +105 -0
  563. package/src/client/connect/refundActor.test.ts +121 -0
  564. package/src/client/connect/refundActor.ts +60 -0
  565. package/src/client/connect/refunds.test.ts +341 -0
  566. package/src/client/connect/refunds.ts +256 -0
  567. package/src/client/connect/transfers.test.ts +492 -0
  568. package/src/client/connect/transfers.ts +572 -0
  569. package/src/client/constants.ts +15 -0
  570. package/src/client/core/accountLinks.test.ts +378 -0
  571. package/src/client/core/accountLinks.ts +211 -0
  572. package/src/client/core/accountStatus.test.ts +102 -0
  573. package/src/client/core/accountStatus.ts +91 -0
  574. package/src/client/core/accounts.test.ts +1496 -0
  575. package/src/client/core/accounts.ts +667 -0
  576. package/src/client/core/config.test.ts +68 -0
  577. package/src/client/core/config.ts +27 -0
  578. package/src/client/core/descriptors.test.ts +68 -0
  579. package/src/client/core/descriptors.ts +46 -0
  580. package/src/client/core/fees.test.ts +377 -0
  581. package/src/client/core/fees.ts +268 -0
  582. package/src/client/errors.test.ts +66 -0
  583. package/src/client/errors.ts +70 -0
  584. package/src/client/helpers.test.ts +74 -0
  585. package/src/client/helpers.ts +94 -0
  586. package/src/client/index.test.ts +1848 -0
  587. package/src/client/index.ts +1872 -0
  588. package/src/client/products/prices.test.ts +345 -0
  589. package/src/client/products/prices.ts +194 -0
  590. package/src/client/products/products.test.ts +476 -0
  591. package/src/client/products/products.ts +335 -0
  592. package/src/client/setup.test.ts +47 -0
  593. package/src/client/stripe-types.ts +108 -0
  594. package/src/client/types/documents.ts +245 -0
  595. package/src/client/types/events.ts +72 -0
  596. package/src/client/types/index.ts +43 -0
  597. package/src/client/types/options.ts +103 -0
  598. package/src/client/types/triggers.ts +293 -0
  599. package/src/client/types.ts +35 -0
  600. package/src/client/utils/data.test.ts +59 -0
  601. package/src/client/utils/data.ts +22 -0
  602. package/src/client/utils/owner.test.ts +35 -0
  603. package/src/client/utils/owner.ts +27 -0
  604. package/src/client/utils/stripeDashboardUrl.test.ts +71 -0
  605. package/src/client/utils/stripeDashboardUrl.ts +71 -0
  606. package/src/client/utils/webhookEndpoints.test.ts +454 -0
  607. package/src/client/utils/webhookEndpoints.ts +271 -0
  608. package/src/client/webhook-handlers.test.ts +603 -0
  609. package/src/client/webhooks/handler.test.ts +604 -0
  610. package/src/client/webhooks/handler.ts +256 -0
  611. package/src/client/webhooks/helpers.test.ts +330 -0
  612. package/src/client/webhooks/helpers.ts +277 -0
  613. package/src/client/webhooks/hooks.test.ts +111 -0
  614. package/src/client/webhooks/hooks.ts +177 -0
  615. package/src/client/webhooks/index.ts +51 -0
  616. package/src/client/webhooks/processors.test.ts +2392 -0
  617. package/src/client/webhooks/processors.ts +1166 -0
  618. package/src/client/webhooks/v2.test.ts +396 -0
  619. package/src/client/webhooks/v2.ts +124 -0
  620. package/src/client/webhooks.test.ts +1689 -0
  621. package/src/client/webhooks.ts +3 -0
  622. package/src/component/_generated/api.ts +86 -0
  623. package/src/component/_generated/component.ts +1758 -0
  624. package/src/component/_generated/dataModel.ts +60 -0
  625. package/src/component/_generated/server.ts +164 -0
  626. package/src/component/billing/mutations.ts +155 -0
  627. package/src/component/billing/queries.ts +378 -0
  628. package/src/component/billing/schema.ts +40 -0
  629. package/src/component/billing/validators.ts +137 -0
  630. package/src/component/config-queries.test.ts +47 -0
  631. package/src/component/connect/mutations.ts +624 -0
  632. package/src/component/connect/queries.ts +537 -0
  633. package/src/component/connect/schema.ts +90 -0
  634. package/src/component/connect/validators.ts +333 -0
  635. package/src/component/connect.test.ts +721 -0
  636. package/src/component/convex.config.ts +17 -0
  637. package/src/component/core/mutations.ts +182 -0
  638. package/src/component/core/queries.ts +100 -0
  639. package/src/component/core/schema.ts +13 -0
  640. package/src/component/core/validators.ts +55 -0
  641. package/src/component/earnings-totals.test.ts +196 -0
  642. package/src/component/fee-routing.test.ts +124 -0
  643. package/src/component/lib/fees.ts +64 -0
  644. package/src/component/lib/idempotency.test.ts +37 -0
  645. package/src/component/lib/idempotency.ts +20 -0
  646. package/src/component/lib/reversals.ts +113 -0
  647. package/src/component/lib/stripeFactory.ts +30 -0
  648. package/src/component/products/mutations.ts +73 -0
  649. package/src/component/products/queries.ts +149 -0
  650. package/src/component/products/schema.ts +22 -0
  651. package/src/component/products/validators.ts +63 -0
  652. package/src/component/public.test.ts +1858 -0
  653. package/src/component/reversal-races.test.ts +920 -0
  654. package/src/component/schema.ts +45 -0
  655. package/src/component/subscription-scoping.test.ts +118 -0
  656. package/src/component/transfers.test.ts +402 -0
  657. package/src/component/triggers.test.ts +359 -0
  658. package/src/component/webhooks/mutations.ts +151 -0
  659. package/src/component/webhooks/queries.ts +44 -0
  660. package/src/component/webhooks/schema.ts +10 -0
  661. package/src/component/webhooks/validators.ts +30 -0
  662. package/src/react/components/AccountCloseButton.tsx +91 -0
  663. package/src/react/components/AccountCloseCard.tsx +84 -0
  664. package/src/react/components/AccountCreateButton.tsx +83 -0
  665. package/src/react/components/AccountCreateCard.tsx +123 -0
  666. package/src/react/components/AccountLoginButton.tsx +69 -0
  667. package/src/react/components/AccountLoginCard.tsx +99 -0
  668. package/src/react/components/AccountOnboardingButton.tsx +83 -0
  669. package/src/react/components/AccountOnboardingCard.test.ts +27 -0
  670. package/src/react/components/AccountOnboardingCard.tsx +152 -0
  671. package/src/react/components/AddCardForm.tsx +80 -0
  672. package/src/react/components/BillingPortalLink.tsx +93 -0
  673. package/src/react/components/BuyerBillingView.render.test.tsx +207 -0
  674. package/src/react/components/BuyerBillingView.tsx +193 -0
  675. package/src/react/components/CheckoutSessionProvider.tsx +70 -0
  676. package/src/react/components/CheckoutSessionProviderWithKey.tsx +99 -0
  677. package/src/react/components/CheckoutStatus.tsx +71 -0
  678. package/src/react/components/ConnectProvider.tsx +58 -0
  679. package/src/react/components/ConnectRequirements.tsx +159 -0
  680. package/src/react/components/ConnectStatusBadge.tsx +60 -0
  681. package/src/react/components/DeletePaymentMethodDialog.tsx +61 -0
  682. package/src/react/components/DisputeDetail.render.test.tsx +143 -0
  683. package/src/react/components/DisputeDetail.tsx +111 -0
  684. package/src/react/components/DisputesList.render.test.tsx +244 -0
  685. package/src/react/components/DisputesList.tsx +120 -0
  686. package/src/react/components/EarningsSummary.render.test.tsx +153 -0
  687. package/src/react/components/EarningsSummary.tsx +131 -0
  688. package/src/react/components/EmbeddedCheckout.test.ts +25 -0
  689. package/src/react/components/EmbeddedCheckout.tsx +54 -0
  690. package/src/react/components/EmbeddedDisputes.render.test.tsx +142 -0
  691. package/src/react/components/EmbeddedDisputes.tsx +38 -0
  692. package/src/react/components/EvidenceForm.render.test.tsx +215 -0
  693. package/src/react/components/EvidenceForm.tsx +176 -0
  694. package/src/react/components/IntervalSelector.tsx +58 -0
  695. package/src/react/components/PaymentMethodActions.tsx +68 -0
  696. package/src/react/components/PaymentMethodsList.tsx +81 -0
  697. package/src/react/components/PayoutSchedule.render.test.tsx +178 -0
  698. package/src/react/components/PayoutSchedule.tsx +148 -0
  699. package/src/react/components/PriceBadge.render.test.tsx +134 -0
  700. package/src/react/components/PriceBadge.tsx +49 -0
  701. package/src/react/components/PriceCard.render.test.tsx +135 -0
  702. package/src/react/components/PriceCard.tsx +83 -0
  703. package/src/react/components/PricePicker.tsx +95 -0
  704. package/src/react/components/SplitBreakdown.render.test.tsx +168 -0
  705. package/src/react/components/SplitBreakdown.tsx +121 -0
  706. package/src/react/components/StripeProvider.test.ts +45 -0
  707. package/src/react/components/StripeProvider.tsx +80 -0
  708. package/src/react/components/StripeProviderWithKey.tsx +95 -0
  709. package/src/react/components/SubscriptionActions.tsx +79 -0
  710. package/src/react/components/SubscriptionCard.tsx +92 -0
  711. package/src/react/components/SubscriptionLineItems.tsx +62 -0
  712. package/src/react/components/TrialAlert.render.test.tsx +132 -0
  713. package/src/react/components/TrialAlert.tsx +44 -0
  714. package/src/react/hooks/skipSentinel.test.ts +85 -0
  715. package/src/react/hooks/useAccount.ts +28 -0
  716. package/src/react/hooks/useAccountOnboarding.test.ts +75 -0
  717. package/src/react/hooks/useAccountOnboarding.ts +35 -0
  718. package/src/react/hooks/useCheckout.ts +33 -0
  719. package/src/react/hooks/useCheckoutSession.ts +110 -0
  720. package/src/react/hooks/useConfirmPayment.ts +117 -0
  721. package/src/react/hooks/useDisputeWithCountdown.test.ts +90 -0
  722. package/src/react/hooks/useDisputeWithCountdown.ts +48 -0
  723. package/src/react/hooks/useDisputes.test.ts +75 -0
  724. package/src/react/hooks/useDisputes.ts +28 -0
  725. package/src/react/hooks/useEarnings.test.ts +159 -0
  726. package/src/react/hooks/useEarnings.ts +132 -0
  727. package/src/react/hooks/useInvoices.test.ts +79 -0
  728. package/src/react/hooks/useInvoices.ts +25 -0
  729. package/src/react/hooks/usePaymentMethodActions.ts +206 -0
  730. package/src/react/hooks/usePaymentMethods.ts +44 -0
  731. package/src/react/hooks/usePrices.ts +26 -0
  732. package/src/react/hooks/useProducts.test.ts +75 -0
  733. package/src/react/hooks/useProducts.ts +24 -0
  734. package/src/react/hooks/useSplitBreakdown.test.ts +151 -0
  735. package/src/react/hooks/useSplitBreakdown.ts +118 -0
  736. package/src/react/hooks/useStripeConfig.ts +31 -0
  737. package/src/react/hooks/useStripeMode.test.ts +49 -0
  738. package/src/react/hooks/useStripeMode.ts +9 -0
  739. package/src/react/hooks/useStripePublishableKey.test.ts +35 -0
  740. package/src/react/hooks/useStripePublishableKey.ts +9 -0
  741. package/src/react/hooks/useSubscription.ts +52 -0
  742. package/src/react/hooks/useSubscriptions.ts +33 -0
  743. package/src/react/index.payment-element.test.ts +41 -0
  744. package/src/react/index.test.ts +167 -0
  745. package/src/react/index.ts +279 -0
  746. package/src/react/lib/connect-requirement-keys.test.ts +73 -0
  747. package/src/react/lib/connect-requirement-keys.ts +66 -0
  748. package/src/react/lib/price-helpers.test.ts +199 -0
  749. package/src/react/lib/price-helpers.ts +68 -0
  750. package/src/react/lib/stripe-element-styles.test.ts +94 -0
  751. package/src/react/lib/stripe-element-styles.ts +178 -0
  752. package/src/react/lib/subscription-helpers.test.ts +127 -0
  753. package/src/react/lib/subscription-helpers.ts +64 -0
  754. package/src/react/types.ts +32 -0
  755. package/src/test.ts +5 -0
  756. package/src/testing/assert-test-env.test.ts +33 -0
  757. package/src/testing/assert-test-env.ts +20 -0
  758. package/src/testing/fixtures.ts +95 -0
  759. package/src/testing/index.ts +13 -0
  760. package/src/testing/mock-webhooks.test.ts +97 -0
  761. package/src/testing/mock-webhooks.ts +101 -0
  762. package/src/vite-env.d.ts +4 -0
@@ -0,0 +1,1858 @@
1
+ // @vitest-environment edge-runtime
2
+ import { convexTest } from "convex-test";
3
+ import { describe, expect, it } from "vitest";
4
+
5
+ import type { TableNames } from "./_generated/dataModel";
6
+ import { api } from "./_generated/api.js";
7
+ import schema from "./schema.js";
8
+
9
+ const modules = import.meta.glob("./**/*.*s");
10
+
11
+ describe("core — account mutations and queries", () => {
12
+ it("upsertAccount: inserts new account", async () => {
13
+ const t = convexTest(schema, modules);
14
+
15
+ await t.mutation(api.core.mutations.upsertAccount, {
16
+ stripeAccountId: "acct_001",
17
+ userId: "user_001",
18
+ name: "Test Account",
19
+ email: "test@example.com",
20
+ });
21
+
22
+ const account = await t.query(api.core.queries.getAccountByUserId, {
23
+ userId: "user_001",
24
+ });
25
+
26
+ expect(account).not.toBeNull();
27
+ expect(account!.stripeAccountId).toBe("acct_001");
28
+ expect(account!.userId).toBe("user_001");
29
+ expect(account!.name).toBe("Test Account");
30
+ expect(account!.onboardingStatus).toBe("pending");
31
+ });
32
+
33
+ it("upsertAccount: updates existing account by stripeAccountId", async () => {
34
+ const t = convexTest(schema, modules);
35
+
36
+ await t.mutation(api.core.mutations.upsertAccount, {
37
+ stripeAccountId: "acct_002",
38
+ userId: "user_002",
39
+ name: "Original Name",
40
+ });
41
+
42
+ await t.mutation(api.core.mutations.upsertAccount, {
43
+ stripeAccountId: "acct_002",
44
+ userId: "user_002",
45
+ name: "Updated Name",
46
+ });
47
+
48
+ const account = await t.query(api.core.queries.getAccountByUserId, {
49
+ userId: "user_002",
50
+ });
51
+
52
+ expect(account).not.toBeNull();
53
+ expect(account!.name).toBe("Updated Name");
54
+ });
55
+
56
+ it("getAccountByUserId: returns matching account", async () => {
57
+ const t = convexTest(schema, modules);
58
+
59
+ await t.mutation(api.core.mutations.upsertAccount, {
60
+ stripeAccountId: "acct_003",
61
+ userId: "user_003",
62
+ email: "found@example.com",
63
+ });
64
+
65
+ const account = await t.query(api.core.queries.getAccountByUserId, {
66
+ userId: "user_003",
67
+ });
68
+
69
+ expect(account).not.toBeNull();
70
+ expect(account!.userId).toBe("user_003");
71
+ expect(account!.email).toBe("found@example.com");
72
+ });
73
+
74
+ it("getAccountByUserId: returns null for unknown user", async () => {
75
+ const t = convexTest(schema, modules);
76
+
77
+ const account = await t.query(api.core.queries.getAccountByUserId, {
78
+ userId: "user_nonexistent",
79
+ });
80
+
81
+ expect(account).toBeNull();
82
+ });
83
+
84
+ it("getAccountOnboardingStatus reflects missingRequirements and readiness", async () => {
85
+ const t = convexTest(schema, modules);
86
+
87
+ await t.mutation(api.core.mutations.upsertAccount, {
88
+ stripeAccountId: "acct_004",
89
+ userId: "user_004",
90
+ onboardingStatus: "complete",
91
+ });
92
+
93
+ const account = await t.query(api.core.queries.getAccountByStripeId, {
94
+ stripeAccountId: "acct_004",
95
+ });
96
+
97
+ const status = await t.query(api.core.queries.getAccountOnboardingStatus, {
98
+ accountId: account!._id,
99
+ });
100
+
101
+ expect(status).not.toBeNull();
102
+ expect(status!.isReady).toBe(true);
103
+ expect(status!.onboardingStatus).toBe("complete");
104
+ expect(status!.missingRequirements).toEqual([]);
105
+ });
106
+ });
107
+
108
+ describe("products — product and price mutations and queries", () => {
109
+ it("upsertProduct + getProductByStripeId round trip", async () => {
110
+ const t = convexTest(schema, modules);
111
+
112
+ await t.mutation(api.products.mutations.upsertProduct, {
113
+ stripeProductId: "prod_001",
114
+ name: "Pro Plan",
115
+ active: true,
116
+ });
117
+
118
+ const product = await t.query(api.products.queries.getProductByStripeId, {
119
+ stripeProductId: "prod_001",
120
+ });
121
+
122
+ expect(product).not.toBeNull();
123
+ expect(product!.name).toBe("Pro Plan");
124
+ expect(product!.active).toBe(true);
125
+ });
126
+
127
+ it("upsertPrice + listPricesByProduct", async () => {
128
+ const t = convexTest(schema, modules);
129
+
130
+ await t.mutation(api.products.mutations.upsertProduct, {
131
+ stripeProductId: "prod_002",
132
+ name: "Starter Plan",
133
+ active: true,
134
+ });
135
+
136
+ await t.mutation(api.products.mutations.upsertPrice, {
137
+ stripePriceId: "price_001",
138
+ productId: "internal_prod_002",
139
+ stripeProductId: "prod_002",
140
+ unitAmount: 1000,
141
+ currency: "usd",
142
+ active: true,
143
+ type: "recurring",
144
+ interval: "month",
145
+ });
146
+
147
+ await t.mutation(api.products.mutations.upsertPrice, {
148
+ stripePriceId: "price_002",
149
+ productId: "internal_prod_002",
150
+ stripeProductId: "prod_002",
151
+ unitAmount: 10000,
152
+ currency: "usd",
153
+ active: true,
154
+ type: "recurring",
155
+ interval: "year",
156
+ });
157
+
158
+ const prices = await t.query(api.products.queries.listPricesByProduct, {
159
+ stripeProductId: "prod_002",
160
+ });
161
+
162
+ expect(prices).toHaveLength(2);
163
+ });
164
+ });
165
+
166
+ describe("billing — subscription mutations and queries", () => {
167
+ it("upsertSubscription + getActiveSubscription", async () => {
168
+ const t = convexTest(schema, modules);
169
+
170
+ await t.mutation(api.billing.mutations.upsertSubscription, {
171
+ stripeSubscriptionId: "sub_001",
172
+ userId: "user_010",
173
+ status: "active",
174
+ cancelAtPeriodEnd: false,
175
+ isTrialing: false,
176
+ });
177
+
178
+ const sub = await t.query(api.billing.queries.getActiveSubscription, {
179
+ userId: "user_010",
180
+ });
181
+
182
+ expect(sub).not.toBeNull();
183
+ expect(sub!.stripeSubscriptionId).toBe("sub_001");
184
+ expect(sub!.status).toBe("active");
185
+ });
186
+
187
+ it("getTrialStatus: returns trial days remaining", async () => {
188
+ const t = convexTest(schema, modules);
189
+
190
+ const trialStart = "2030-01-01T00:00:00.000Z";
191
+ const trialEnd = "2030-01-08T00:00:00.000Z";
192
+
193
+ await t.mutation(api.billing.mutations.upsertSubscription, {
194
+ stripeSubscriptionId: "sub_trial_001",
195
+ userId: "user_trial",
196
+ status: "trialing",
197
+ cancelAtPeriodEnd: false,
198
+ isTrialing: true,
199
+ trialStart,
200
+ trialEnd,
201
+ });
202
+
203
+ const doc = await t.query(api.billing.queries.getSubscriptionByStripeId, {
204
+ stripeSubscriptionId: "sub_trial_001",
205
+ });
206
+
207
+ const trialStatus = await t.query(api.billing.queries.getTrialStatus, {
208
+ subscriptionId: doc!._id,
209
+ });
210
+
211
+ expect(trialStatus).not.toBeNull();
212
+ expect(trialStatus!.isTrialing).toBe(true);
213
+ expect(trialStatus!.daysRemaining).toBeGreaterThanOrEqual(6);
214
+ expect(trialStatus!.status).toBe("trialing");
215
+ });
216
+
217
+ // BTS-33: dunning tracks the delinquent subscription lifecycle. Stripe moves a
218
+ // subscription to `past_due` on the first failed recurring charge and to
219
+ // `unpaid` once smart retries are exhausted — both must round-trip the table.
220
+ it.each(["past_due", "unpaid"] as const)(
221
+ "persists the delinquent subscription status %s",
222
+ async (status) => {
223
+ const t = convexTest(schema, modules);
224
+
225
+ await t.mutation(api.billing.mutations.upsertSubscription, {
226
+ stripeSubscriptionId: `sub_${status}`,
227
+ userId: "user_dunning",
228
+ status,
229
+ cancelAtPeriodEnd: false,
230
+ isTrialing: false,
231
+ });
232
+
233
+ const doc = await t.query(api.billing.queries.getSubscriptionByStripeId, {
234
+ stripeSubscriptionId: `sub_${status}`,
235
+ });
236
+ expect(doc!.status).toBe(status);
237
+ },
238
+ );
239
+ });
240
+
241
+ describe("billing — checkout session mutations and queries", () => {
242
+ it("upsertCheckoutSession + getCheckoutSessionByStripeId", async () => {
243
+ const t = convexTest(schema, modules);
244
+
245
+ await t.mutation(api.billing.mutations.upsertCheckoutSession, {
246
+ stripeSessionId: "cs_001",
247
+ userId: "user_020",
248
+ mode: "subscription",
249
+ status: "open",
250
+ });
251
+
252
+ const session = await t.query(
253
+ api.billing.queries.getCheckoutSessionByStripeId,
254
+ {
255
+ stripeSessionId: "cs_001",
256
+ },
257
+ );
258
+
259
+ expect(session).not.toBeNull();
260
+ expect(session!.mode).toBe("subscription");
261
+ expect(session!.status).toBe("open");
262
+ });
263
+ });
264
+
265
+ describe("billing — invoice mutations and queries", () => {
266
+ it("rejects an invalid invoice status with a validation error", async () => {
267
+ const t = convexTest(schema, modules);
268
+
269
+ await expect(
270
+ t.mutation(api.billing.mutations.upsertInvoice, {
271
+ stripeInvoiceId: "inv_bad_status",
272
+ userId: "user_030",
273
+ // @ts-expect-error — invalid status must be rejected by the validator
274
+ status: "not_a_real_status",
275
+ currency: "usd",
276
+ amountDue: 1000,
277
+ amountPaid: 0,
278
+ }),
279
+ ).rejects.toThrow(/Validator error/);
280
+ });
281
+
282
+ it("upsertInvoice + listInvoices", async () => {
283
+ const t = convexTest(schema, modules);
284
+
285
+ await t.mutation(api.billing.mutations.upsertInvoice, {
286
+ stripeInvoiceId: "inv_001",
287
+ userId: "user_030",
288
+ status: "paid",
289
+ currency: "usd",
290
+ amountDue: 2000,
291
+ amountPaid: 2000,
292
+ });
293
+
294
+ await t.mutation(api.billing.mutations.upsertInvoice, {
295
+ stripeInvoiceId: "inv_002",
296
+ userId: "user_030",
297
+ status: "open",
298
+ currency: "usd",
299
+ amountDue: 5000,
300
+ amountPaid: 0,
301
+ });
302
+
303
+ const invoices = await t.query(api.billing.queries.listInvoices, {
304
+ userId: "user_030",
305
+ });
306
+
307
+ expect(invoices).toHaveLength(2);
308
+ });
309
+
310
+ it("getInvoiceByStripeId: returns matching invoice", async () => {
311
+ const t = convexTest(schema, modules);
312
+
313
+ await t.mutation(api.billing.mutations.upsertInvoice, {
314
+ stripeInvoiceId: "inv_by_stripe_001",
315
+ userId: "user_031",
316
+ status: "paid",
317
+ currency: "usd",
318
+ amountDue: 1500,
319
+ amountPaid: 1500,
320
+ });
321
+
322
+ const invoice = await t.query(api.billing.queries.getInvoiceByStripeId, {
323
+ stripeInvoiceId: "inv_by_stripe_001",
324
+ });
325
+
326
+ expect(invoice).not.toBeNull();
327
+ expect(invoice!.stripeInvoiceId).toBe("inv_by_stripe_001");
328
+ expect(invoice!.userId).toBe("user_031");
329
+ expect(invoice!.amountDue).toBe(1500);
330
+ });
331
+
332
+ // BTS-33: a failed subscription invoice carries the smart-retry schedule
333
+ // (`next_payment_attempt`) and attempt count so a dunning hook can tell the
334
+ // buyer when Stripe will retry. Both persist as optional invoice fields.
335
+ it("persists smart-retry metadata (nextPaymentAttempt + attemptCount)", async () => {
336
+ const t = convexTest(schema, modules);
337
+
338
+ await t.mutation(api.billing.mutations.upsertInvoice, {
339
+ stripeInvoiceId: "inv_retry_001",
340
+ userId: "user_dunning",
341
+ status: "open",
342
+ currency: "usd",
343
+ amountDue: 5000,
344
+ amountPaid: 0,
345
+ nextPaymentAttempt: "2030-02-01T00:00:00.000Z",
346
+ attemptCount: 1,
347
+ });
348
+
349
+ const invoice = await t.query(api.billing.queries.getInvoiceByStripeId, {
350
+ stripeInvoiceId: "inv_retry_001",
351
+ });
352
+ expect(invoice!.status).toBe("open");
353
+ expect(invoice!.nextPaymentAttempt).toBe("2030-02-01T00:00:00.000Z");
354
+ expect(invoice!.attemptCount).toBe(1);
355
+ });
356
+
357
+ it("getInvoiceByStripeId: returns null for unknown id", async () => {
358
+ const t = convexTest(schema, modules);
359
+
360
+ const invoice = await t.query(api.billing.queries.getInvoiceByStripeId, {
361
+ stripeInvoiceId: "inv_does_not_exist",
362
+ });
363
+
364
+ expect(invoice).toBeNull();
365
+ });
366
+ });
367
+
368
+ describe("core — clearAllTables", () => {
369
+ it("clearAllTables: removes all records from every table", async () => {
370
+ const t = convexTest(schema, modules);
371
+
372
+ // Seed one row in every schema table so a drifted clear list is caught.
373
+ await t.mutation(api.core.mutations.upsertAccount, {
374
+ stripeAccountId: "acct_clear",
375
+ userId: "user_clear",
376
+ });
377
+
378
+ await t.mutation(api.products.mutations.upsertProduct, {
379
+ stripeProductId: "prod_clear",
380
+ name: "To Be Cleared",
381
+ active: true,
382
+ });
383
+
384
+ await t.mutation(api.products.mutations.upsertPrice, {
385
+ stripePriceId: "price_clear",
386
+ productId: "internal_prod_clear",
387
+ stripeProductId: "prod_clear",
388
+ unitAmount: 1000,
389
+ currency: "usd",
390
+ active: true,
391
+ type: "one_time",
392
+ });
393
+
394
+ await t.mutation(api.billing.mutations.upsertSubscription, {
395
+ stripeSubscriptionId: "sub_clear",
396
+ userId: "user_clear",
397
+ status: "active",
398
+ cancelAtPeriodEnd: false,
399
+ isTrialing: false,
400
+ });
401
+
402
+ await t.mutation(api.billing.mutations.upsertCheckoutSession, {
403
+ stripeSessionId: "cs_clear",
404
+ userId: "user_clear",
405
+ mode: "subscription",
406
+ status: "open",
407
+ });
408
+
409
+ await t.mutation(api.billing.mutations.upsertInvoice, {
410
+ stripeInvoiceId: "inv_clear",
411
+ userId: "user_clear",
412
+ status: "paid",
413
+ currency: "usd",
414
+ amountDue: 1000,
415
+ amountPaid: 1000,
416
+ });
417
+
418
+ await t.mutation(api.connect.mutations.upsertPayment, {
419
+ stripePaymentIntentId: "pi_clear",
420
+ userId: "user_clear",
421
+ amount: 1000,
422
+ currency: "usd",
423
+ status: "succeeded",
424
+ });
425
+
426
+ await t.mutation(api.connect.mutations.upsertPayout, {
427
+ stripePayoutId: "po_clear",
428
+ accountId: "acct_clear",
429
+ amount: 1000,
430
+ currency: "usd",
431
+ status: "pending",
432
+ });
433
+
434
+ await t.mutation(api.connect.mutations.upsertRefund, {
435
+ stripeRefundId: "re_clear",
436
+ amount: 1000,
437
+ currency: "usd",
438
+ status: "succeeded",
439
+ });
440
+
441
+ await t.mutation(api.connect.mutations.upsertDispute, {
442
+ stripeDisputeId: "dp_clear",
443
+ amount: 1000,
444
+ currency: "usd",
445
+ status: "needs_response",
446
+ reason: "product_not_received",
447
+ isChargeRefundable: true,
448
+ });
449
+
450
+ await t.mutation(api.connect.mutations.upsertTransfer, {
451
+ stripeTransferId: "tr_clear",
452
+ destinationAccountId: "acct_dest_clear",
453
+ amount: 1000,
454
+ currency: "usd",
455
+ status: "paid",
456
+ });
457
+
458
+ await t.run(async (ctx) => {
459
+ await ctx.db.insert("transferReversalOps", {
460
+ operationId: "op_clear",
461
+ sourceChargeId: "ch_clear",
462
+ slices: [],
463
+ });
464
+ });
465
+
466
+ await t.mutation(api.webhooks.mutations.insertWebhookEvent, {
467
+ stripeEventId: "evt_clear",
468
+ eventType: "invoice.paid",
469
+ });
470
+
471
+ const result = await t.mutation(api.core.mutations.clearAllTables, {});
472
+ const tableCount = Object.keys(schema.tables).length;
473
+
474
+ expect(result.cleared).toBe(13);
475
+ expect(result.tables).toHaveLength(tableCount);
476
+
477
+ for (const tableName of Object.keys(schema.tables) as TableNames[]) {
478
+ const remaining = await t.run(async (ctx) =>
479
+ ctx.db.query(tableName).collect(),
480
+ );
481
+ expect(remaining).toHaveLength(0);
482
+ }
483
+ });
484
+ });
485
+
486
+ // =============================================================================
487
+ // CORE — additional account queries and mutations
488
+ // =============================================================================
489
+
490
+ describe("core — getAccountByOrgId", () => {
491
+ it("returns account matching orgId", async () => {
492
+ const t = convexTest(schema, modules);
493
+
494
+ await t.mutation(api.core.mutations.upsertAccount, {
495
+ stripeAccountId: "acct_org_001",
496
+ userId: "user_org_001",
497
+ orgId: "org_001",
498
+ name: "Org Account",
499
+ });
500
+
501
+ const account = await t.query(api.core.queries.getAccountByOrgId, {
502
+ orgId: "org_001",
503
+ });
504
+
505
+ expect(account).not.toBeNull();
506
+ expect(account!.orgId).toBe("org_001");
507
+ expect(account!.stripeAccountId).toBe("acct_org_001");
508
+ });
509
+
510
+ it("returns null for unknown orgId", async () => {
511
+ const t = convexTest(schema, modules);
512
+
513
+ const account = await t.query(api.core.queries.getAccountByOrgId, {
514
+ orgId: "org_nonexistent",
515
+ });
516
+
517
+ expect(account).toBeNull();
518
+ });
519
+ });
520
+
521
+ describe("core — deleteAccountByStripeId", () => {
522
+ it("deletes existing account and returns true", async () => {
523
+ const t = convexTest(schema, modules);
524
+
525
+ await t.mutation(api.core.mutations.upsertAccount, {
526
+ stripeAccountId: "acct_del_001",
527
+ userId: "user_del_001",
528
+ });
529
+
530
+ const result = await t.mutation(
531
+ api.core.mutations.deleteAccountByStripeId,
532
+ {
533
+ stripeAccountId: "acct_del_001",
534
+ },
535
+ );
536
+
537
+ expect(result).toBe(true);
538
+
539
+ const account = await t.query(api.core.queries.getAccountByStripeId, {
540
+ stripeAccountId: "acct_del_001",
541
+ });
542
+ expect(account).toBeNull();
543
+ });
544
+
545
+ it("returns false for nonexistent account", async () => {
546
+ const t = convexTest(schema, modules);
547
+
548
+ const result = await t.mutation(
549
+ api.core.mutations.deleteAccountByStripeId,
550
+ {
551
+ stripeAccountId: "acct_nonexistent",
552
+ },
553
+ );
554
+
555
+ expect(result).toBe(false);
556
+ });
557
+ });
558
+
559
+ describe("core — upsertAccountInternal", () => {
560
+ it("inserts account with required onboardingStatus", async () => {
561
+ const t = convexTest(schema, modules);
562
+
563
+ await t.mutation(api.core.mutations.upsertAccountInternal, {
564
+ stripeAccountId: "acct_int_001",
565
+ userId: "user_int_001",
566
+ onboardingStatus: "in_progress",
567
+ });
568
+
569
+ const account = await t.query(api.core.queries.getAccountByStripeId, {
570
+ stripeAccountId: "acct_int_001",
571
+ });
572
+
573
+ expect(account).not.toBeNull();
574
+ expect(account!.onboardingStatus).toBe("in_progress");
575
+ });
576
+
577
+ it("updates existing account onboardingStatus", async () => {
578
+ const t = convexTest(schema, modules);
579
+
580
+ await t.mutation(api.core.mutations.upsertAccountInternal, {
581
+ stripeAccountId: "acct_int_002",
582
+ userId: "user_int_002",
583
+ onboardingStatus: "pending",
584
+ });
585
+
586
+ await t.mutation(api.core.mutations.upsertAccountInternal, {
587
+ stripeAccountId: "acct_int_002",
588
+ userId: "user_int_002",
589
+ onboardingStatus: "complete",
590
+ missingRequirements: [],
591
+ });
592
+
593
+ const account = await t.query(api.core.queries.getAccountByStripeId, {
594
+ stripeAccountId: "acct_int_002",
595
+ });
596
+
597
+ expect(account!.onboardingStatus).toBe("complete");
598
+ expect(account!.missingRequirements).toEqual([]);
599
+ });
600
+ });
601
+
602
+ describe("core — onboarding status edge cases", () => {
603
+ it("getAccountOnboardingStatus returns null for nonexistent account", async () => {
604
+ const t = convexTest(schema, modules);
605
+
606
+ // Insert then delete to get a valid but missing ID
607
+ await t.mutation(api.core.mutations.upsertAccount, {
608
+ stripeAccountId: "acct_ghost",
609
+ userId: "user_ghost",
610
+ });
611
+
612
+ const account = await t.query(api.core.queries.getAccountByStripeId, {
613
+ stripeAccountId: "acct_ghost",
614
+ });
615
+
616
+ await t.mutation(api.core.mutations.deleteAccountByStripeId, {
617
+ stripeAccountId: "acct_ghost",
618
+ });
619
+
620
+ const status = await t.query(api.core.queries.getAccountOnboardingStatus, {
621
+ accountId: account!._id,
622
+ });
623
+
624
+ expect(status).toBeNull();
625
+ });
626
+
627
+ it("incomplete account has isReady false and missingRequirements", async () => {
628
+ const t = convexTest(schema, modules);
629
+
630
+ await t.mutation(api.core.mutations.upsertAccountInternal, {
631
+ stripeAccountId: "acct_incomplete",
632
+ userId: "user_incomplete",
633
+ onboardingStatus: "restricted",
634
+ missingRequirements: ["external_account", "tos_acceptance"],
635
+ });
636
+
637
+ const account = await t.query(api.core.queries.getAccountByStripeId, {
638
+ stripeAccountId: "acct_incomplete",
639
+ });
640
+
641
+ const status = await t.query(api.core.queries.getAccountOnboardingStatus, {
642
+ accountId: account!._id,
643
+ });
644
+
645
+ expect(status!.isReady).toBe(false);
646
+ expect(status!.onboardingStatus).toBe("restricted");
647
+ expect(status!.missingRequirements).toEqual([
648
+ "external_account",
649
+ "tos_acceptance",
650
+ ]);
651
+ });
652
+ });
653
+
654
+ // =============================================================================
655
+ // PRODUCTS — additional filter tests
656
+ // =============================================================================
657
+
658
+ describe("products — listProducts with filters", () => {
659
+ it("filters by active status", async () => {
660
+ const t = convexTest(schema, modules);
661
+
662
+ await t.mutation(api.products.mutations.upsertProduct, {
663
+ stripeProductId: "prod_active",
664
+ name: "Active Product",
665
+ active: true,
666
+ });
667
+
668
+ await t.mutation(api.products.mutations.upsertProduct, {
669
+ stripeProductId: "prod_inactive",
670
+ name: "Inactive Product",
671
+ active: false,
672
+ });
673
+
674
+ const activeProducts = await t.query(api.products.queries.listProducts, {
675
+ active: true,
676
+ });
677
+ const inactiveProducts = await t.query(api.products.queries.listProducts, {
678
+ active: false,
679
+ });
680
+
681
+ expect(activeProducts).toHaveLength(1);
682
+ expect(activeProducts[0].name).toBe("Active Product");
683
+ expect(inactiveProducts).toHaveLength(1);
684
+ expect(inactiveProducts[0].name).toBe("Inactive Product");
685
+ });
686
+
687
+ it("filters by accountId", async () => {
688
+ const t = convexTest(schema, modules);
689
+
690
+ await t.mutation(api.products.mutations.upsertProduct, {
691
+ stripeProductId: "prod_acct_a",
692
+ name: "Account A Product",
693
+ active: true,
694
+ accountId: "acct_a",
695
+ });
696
+
697
+ await t.mutation(api.products.mutations.upsertProduct, {
698
+ stripeProductId: "prod_acct_b",
699
+ name: "Account B Product",
700
+ active: true,
701
+ accountId: "acct_b",
702
+ });
703
+
704
+ const products = await t.query(api.products.queries.listProducts, {
705
+ accountId: "acct_a",
706
+ });
707
+
708
+ expect(products).toHaveLength(1);
709
+ expect(products[0].name).toBe("Account A Product");
710
+ });
711
+ });
712
+
713
+ describe("products — price queries", () => {
714
+ it("getPriceByStripeId round trip", async () => {
715
+ const t = convexTest(schema, modules);
716
+
717
+ await t.mutation(api.products.mutations.upsertPrice, {
718
+ stripePriceId: "price_lookup",
719
+ productId: "internal_prod",
720
+ stripeProductId: "prod_lookup",
721
+ unitAmount: 5000,
722
+ currency: "eur",
723
+ active: true,
724
+ type: "one_time",
725
+ });
726
+
727
+ const price = await t.query(api.products.queries.getPriceByStripeId, {
728
+ stripePriceId: "price_lookup",
729
+ });
730
+
731
+ expect(price).not.toBeNull();
732
+ expect(price!.unitAmount).toBe(5000);
733
+ expect(price!.currency).toBe("eur");
734
+ expect(price!.type).toBe("one_time");
735
+ });
736
+
737
+ it("listPrices filters by active", async () => {
738
+ const t = convexTest(schema, modules);
739
+
740
+ await t.mutation(api.products.mutations.upsertPrice, {
741
+ stripePriceId: "price_active",
742
+ productId: "prod_x",
743
+ stripeProductId: "prod_x",
744
+ unitAmount: 100,
745
+ currency: "usd",
746
+ active: true,
747
+ type: "one_time",
748
+ });
749
+
750
+ await t.mutation(api.products.mutations.upsertPrice, {
751
+ stripePriceId: "price_archived",
752
+ productId: "prod_x",
753
+ stripeProductId: "prod_x",
754
+ unitAmount: 200,
755
+ currency: "usd",
756
+ active: false,
757
+ type: "one_time",
758
+ });
759
+
760
+ const activePrices = await t.query(api.products.queries.listPrices, {
761
+ active: true,
762
+ });
763
+ expect(activePrices).toHaveLength(1);
764
+ expect(activePrices[0].stripePriceId).toBe("price_active");
765
+ });
766
+
767
+ it("upsertPrice updates existing price", async () => {
768
+ const t = convexTest(schema, modules);
769
+
770
+ await t.mutation(api.products.mutations.upsertPrice, {
771
+ stripePriceId: "price_upd",
772
+ productId: "prod_u",
773
+ stripeProductId: "prod_u",
774
+ unitAmount: 1000,
775
+ currency: "usd",
776
+ active: true,
777
+ type: "recurring",
778
+ interval: "month",
779
+ });
780
+
781
+ await t.mutation(api.products.mutations.upsertPrice, {
782
+ stripePriceId: "price_upd",
783
+ productId: "prod_u",
784
+ stripeProductId: "prod_u",
785
+ unitAmount: 1000,
786
+ currency: "usd",
787
+ active: false,
788
+ type: "recurring",
789
+ interval: "month",
790
+ });
791
+
792
+ const price = await t.query(api.products.queries.getPriceByStripeId, {
793
+ stripePriceId: "price_upd",
794
+ });
795
+
796
+ expect(price!.active).toBe(false);
797
+ });
798
+ });
799
+
800
+ // =============================================================================
801
+ // BILLING — additional subscription query tests
802
+ // =============================================================================
803
+
804
+ describe("billing — listSubscriptions with filters", () => {
805
+ it("filters by status", async () => {
806
+ const t = convexTest(schema, modules);
807
+
808
+ await t.mutation(api.billing.mutations.upsertSubscription, {
809
+ stripeSubscriptionId: "sub_active",
810
+ userId: "user_a",
811
+ status: "active",
812
+ cancelAtPeriodEnd: false,
813
+ isTrialing: false,
814
+ });
815
+
816
+ await t.mutation(api.billing.mutations.upsertSubscription, {
817
+ stripeSubscriptionId: "sub_canceled",
818
+ userId: "user_b",
819
+ status: "canceled",
820
+ cancelAtPeriodEnd: false,
821
+ isTrialing: false,
822
+ });
823
+
824
+ const active = await t.query(api.billing.queries.listSubscriptions, {
825
+ status: "active",
826
+ });
827
+ const canceled = await t.query(api.billing.queries.listSubscriptions, {
828
+ status: "canceled",
829
+ });
830
+
831
+ expect(active).toHaveLength(1);
832
+ expect(active[0].stripeSubscriptionId).toBe("sub_active");
833
+ expect(canceled).toHaveLength(1);
834
+ expect(canceled[0].stripeSubscriptionId).toBe("sub_canceled");
835
+ });
836
+
837
+ it("rejects an invalid status with a validation error", async () => {
838
+ const t = convexTest(schema, modules);
839
+
840
+ await expect(
841
+ t.query(api.billing.queries.listSubscriptions, {
842
+ // @ts-expect-error — invalid status must be rejected by the validator
843
+ status: "not_a_real_status",
844
+ }),
845
+ ).rejects.toThrow(/Validator error/);
846
+ });
847
+
848
+ it("respects limit", async () => {
849
+ const t = convexTest(schema, modules);
850
+
851
+ for (let i = 0; i < 5; i++) {
852
+ await t.mutation(api.billing.mutations.upsertSubscription, {
853
+ stripeSubscriptionId: `sub_limit_${i}`,
854
+ userId: `user_limit_${i}`,
855
+ status: "active",
856
+ cancelAtPeriodEnd: false,
857
+ isTrialing: false,
858
+ });
859
+ }
860
+
861
+ const limited = await t.query(api.billing.queries.listSubscriptions, {
862
+ limit: 2,
863
+ });
864
+
865
+ expect(limited).toHaveLength(2);
866
+ });
867
+
868
+ it("filters by accountId", async () => {
869
+ const t = convexTest(schema, modules);
870
+
871
+ await t.mutation(api.billing.mutations.upsertSubscription, {
872
+ stripeSubscriptionId: "sub_acct_a1",
873
+ accountId: "acct_sub_a",
874
+ userId: "user_sub_acct_a",
875
+ status: "active",
876
+ cancelAtPeriodEnd: false,
877
+ isTrialing: false,
878
+ });
879
+
880
+ await t.mutation(api.billing.mutations.upsertSubscription, {
881
+ stripeSubscriptionId: "sub_acct_a2",
882
+ accountId: "acct_sub_a",
883
+ userId: "user_sub_acct_a",
884
+ status: "canceled",
885
+ cancelAtPeriodEnd: false,
886
+ isTrialing: false,
887
+ });
888
+
889
+ await t.mutation(api.billing.mutations.upsertSubscription, {
890
+ stripeSubscriptionId: "sub_acct_b1",
891
+ accountId: "acct_sub_b",
892
+ userId: "user_sub_acct_b",
893
+ status: "active",
894
+ cancelAtPeriodEnd: false,
895
+ isTrialing: false,
896
+ });
897
+
898
+ const subs = await t.query(api.billing.queries.listSubscriptions, {
899
+ accountId: "acct_sub_a",
900
+ });
901
+
902
+ expect(subs).toHaveLength(2);
903
+ for (const sub of subs) {
904
+ expect(sub.accountId).toBe("acct_sub_a");
905
+ }
906
+
907
+ const statusFiltered = await t.query(
908
+ api.billing.queries.listSubscriptions,
909
+ {
910
+ accountId: "acct_sub_a",
911
+ status: "active",
912
+ },
913
+ );
914
+
915
+ expect(statusFiltered).toHaveLength(1);
916
+ expect(statusFiltered[0].stripeSubscriptionId).toBe("sub_acct_a1");
917
+ });
918
+ });
919
+
920
+ describe("billing — listSubscriptionsByOrg", () => {
921
+ it("returns subscriptions for the given org", async () => {
922
+ const t = convexTest(schema, modules);
923
+
924
+ await t.mutation(api.billing.mutations.upsertSubscription, {
925
+ stripeSubscriptionId: "sub_org_a",
926
+ userId: "user_org_a",
927
+ orgId: "org_a",
928
+ status: "active",
929
+ cancelAtPeriodEnd: false,
930
+ isTrialing: false,
931
+ });
932
+
933
+ await t.mutation(api.billing.mutations.upsertSubscription, {
934
+ stripeSubscriptionId: "sub_org_b",
935
+ userId: "user_org_b",
936
+ orgId: "org_b",
937
+ status: "active",
938
+ cancelAtPeriodEnd: false,
939
+ isTrialing: false,
940
+ });
941
+
942
+ const orgASubs = await t.query(api.billing.queries.listSubscriptionsByOrg, {
943
+ orgId: "org_a",
944
+ });
945
+
946
+ expect(orgASubs).toHaveLength(1);
947
+ expect(orgASubs[0].stripeSubscriptionId).toBe("sub_org_a");
948
+ });
949
+
950
+ it("filters by status within org", async () => {
951
+ const t = convexTest(schema, modules);
952
+
953
+ await t.mutation(api.billing.mutations.upsertSubscription, {
954
+ stripeSubscriptionId: "sub_org_active",
955
+ userId: "user_x",
956
+ orgId: "org_x",
957
+ status: "active",
958
+ cancelAtPeriodEnd: false,
959
+ isTrialing: false,
960
+ });
961
+
962
+ await t.mutation(api.billing.mutations.upsertSubscription, {
963
+ stripeSubscriptionId: "sub_org_canceled",
964
+ userId: "user_x",
965
+ orgId: "org_x",
966
+ status: "canceled",
967
+ cancelAtPeriodEnd: false,
968
+ isTrialing: false,
969
+ });
970
+
971
+ const active = await t.query(api.billing.queries.listSubscriptionsByOrg, {
972
+ orgId: "org_x",
973
+ status: "active",
974
+ });
975
+
976
+ expect(active).toHaveLength(1);
977
+ expect(active[0].status).toBe("active");
978
+ });
979
+ });
980
+
981
+ describe("billing — getActiveSubscription with orgId", () => {
982
+ it("finds active subscription by orgId", async () => {
983
+ const t = convexTest(schema, modules);
984
+
985
+ await t.mutation(api.billing.mutations.upsertSubscription, {
986
+ stripeSubscriptionId: "sub_org_act",
987
+ userId: "user_oa",
988
+ orgId: "org_act",
989
+ status: "active",
990
+ cancelAtPeriodEnd: false,
991
+ isTrialing: false,
992
+ });
993
+
994
+ const sub = await t.query(api.billing.queries.getActiveSubscription, {
995
+ userId: "user_oa",
996
+ orgId: "org_act",
997
+ });
998
+
999
+ expect(sub).not.toBeNull();
1000
+ expect(sub!.stripeSubscriptionId).toBe("sub_org_act");
1001
+ });
1002
+
1003
+ it("finds trialing subscription as active", async () => {
1004
+ const t = convexTest(schema, modules);
1005
+
1006
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1007
+ stripeSubscriptionId: "sub_trial_act",
1008
+ userId: "user_trial_act",
1009
+ status: "trialing",
1010
+ cancelAtPeriodEnd: false,
1011
+ isTrialing: true,
1012
+ });
1013
+
1014
+ const sub = await t.query(api.billing.queries.getActiveSubscription, {
1015
+ userId: "user_trial_act",
1016
+ });
1017
+
1018
+ expect(sub).not.toBeNull();
1019
+ expect(sub!.status).toBe("trialing");
1020
+ });
1021
+
1022
+ it("returns null when no active subscription exists", async () => {
1023
+ const t = convexTest(schema, modules);
1024
+
1025
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1026
+ stripeSubscriptionId: "sub_canceled_only",
1027
+ userId: "user_canceled",
1028
+ status: "canceled",
1029
+ cancelAtPeriodEnd: false,
1030
+ isTrialing: false,
1031
+ });
1032
+
1033
+ const sub = await t.query(api.billing.queries.getActiveSubscription, {
1034
+ userId: "user_canceled",
1035
+ });
1036
+
1037
+ expect(sub).toBeNull();
1038
+ });
1039
+ });
1040
+
1041
+ describe("billing — listCheckoutSessionsByUser", () => {
1042
+ it("lists sessions for the given user", async () => {
1043
+ const t = convexTest(schema, modules);
1044
+
1045
+ await t.mutation(api.billing.mutations.upsertCheckoutSession, {
1046
+ stripeSessionId: "cs_u1_a",
1047
+ userId: "user_cs_1",
1048
+ mode: "subscription",
1049
+ status: "complete",
1050
+ });
1051
+
1052
+ await t.mutation(api.billing.mutations.upsertCheckoutSession, {
1053
+ stripeSessionId: "cs_u1_b",
1054
+ userId: "user_cs_1",
1055
+ mode: "payment",
1056
+ status: "open",
1057
+ });
1058
+
1059
+ await t.mutation(api.billing.mutations.upsertCheckoutSession, {
1060
+ stripeSessionId: "cs_u2",
1061
+ userId: "user_cs_2",
1062
+ mode: "subscription",
1063
+ status: "open",
1064
+ });
1065
+
1066
+ const sessions = await t.query(
1067
+ api.billing.queries.listCheckoutSessionsByUser,
1068
+ { userId: "user_cs_1" },
1069
+ );
1070
+
1071
+ expect(sessions).toHaveLength(2);
1072
+ });
1073
+
1074
+ it("filters by status", async () => {
1075
+ const t = convexTest(schema, modules);
1076
+
1077
+ await t.mutation(api.billing.mutations.upsertCheckoutSession, {
1078
+ stripeSessionId: "cs_filter_open",
1079
+ userId: "user_filter",
1080
+ mode: "subscription",
1081
+ status: "open",
1082
+ });
1083
+
1084
+ await t.mutation(api.billing.mutations.upsertCheckoutSession, {
1085
+ stripeSessionId: "cs_filter_complete",
1086
+ userId: "user_filter",
1087
+ mode: "subscription",
1088
+ status: "complete",
1089
+ });
1090
+
1091
+ const open = await t.query(api.billing.queries.listCheckoutSessionsByUser, {
1092
+ userId: "user_filter",
1093
+ status: "open",
1094
+ });
1095
+
1096
+ expect(open).toHaveLength(1);
1097
+ expect(open[0].status).toBe("open");
1098
+ });
1099
+ });
1100
+
1101
+ describe("billing — listInvoices with filters", () => {
1102
+ it("filters by subscriptionId", async () => {
1103
+ const t = convexTest(schema, modules);
1104
+
1105
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1106
+ stripeInvoiceId: "inv_sub_a",
1107
+ userId: "user_inv",
1108
+ subscriptionId: "sub_inv_a",
1109
+ status: "paid",
1110
+ currency: "usd",
1111
+ amountDue: 1000,
1112
+ amountPaid: 1000,
1113
+ });
1114
+
1115
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1116
+ stripeInvoiceId: "inv_sub_b",
1117
+ userId: "user_inv",
1118
+ subscriptionId: "sub_inv_b",
1119
+ status: "paid",
1120
+ currency: "usd",
1121
+ amountDue: 2000,
1122
+ amountPaid: 2000,
1123
+ });
1124
+
1125
+ const invoices = await t.query(api.billing.queries.listInvoices, {
1126
+ subscriptionId: "sub_inv_a",
1127
+ });
1128
+
1129
+ expect(invoices).toHaveLength(1);
1130
+ expect(invoices[0].stripeInvoiceId).toBe("inv_sub_a");
1131
+ });
1132
+
1133
+ it("filters by status", async () => {
1134
+ const t = convexTest(schema, modules);
1135
+
1136
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1137
+ stripeInvoiceId: "inv_st_paid",
1138
+ userId: "user_st",
1139
+ status: "paid",
1140
+ currency: "usd",
1141
+ amountDue: 1000,
1142
+ amountPaid: 1000,
1143
+ });
1144
+
1145
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1146
+ stripeInvoiceId: "inv_st_open",
1147
+ userId: "user_st",
1148
+ status: "open",
1149
+ currency: "usd",
1150
+ amountDue: 2000,
1151
+ amountPaid: 0,
1152
+ });
1153
+
1154
+ const paidOnly = await t.query(api.billing.queries.listInvoices, {
1155
+ userId: "user_st",
1156
+ status: "paid",
1157
+ });
1158
+
1159
+ expect(paidOnly).toHaveLength(1);
1160
+ expect(paidOnly[0].status).toBe("paid");
1161
+ });
1162
+
1163
+ it("filters by accountId", async () => {
1164
+ const t = convexTest(schema, modules);
1165
+
1166
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1167
+ stripeInvoiceId: "inv_acct_a1",
1168
+ userId: "user_acct_a",
1169
+ accountId: "acct_inv_a",
1170
+ status: "paid",
1171
+ currency: "usd",
1172
+ amountDue: 1000,
1173
+ amountPaid: 1000,
1174
+ });
1175
+
1176
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1177
+ stripeInvoiceId: "inv_acct_a2",
1178
+ userId: "user_acct_a",
1179
+ accountId: "acct_inv_a",
1180
+ status: "open",
1181
+ currency: "usd",
1182
+ amountDue: 2000,
1183
+ amountPaid: 0,
1184
+ });
1185
+
1186
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1187
+ stripeInvoiceId: "inv_acct_b1",
1188
+ userId: "user_acct_b",
1189
+ accountId: "acct_inv_b",
1190
+ status: "paid",
1191
+ currency: "usd",
1192
+ amountDue: 3000,
1193
+ amountPaid: 3000,
1194
+ });
1195
+
1196
+ const invoices = await t.query(api.billing.queries.listInvoices, {
1197
+ accountId: "acct_inv_a",
1198
+ });
1199
+
1200
+ expect(invoices).toHaveLength(2);
1201
+ for (const invoice of invoices) {
1202
+ expect(invoice.accountId).toBe("acct_inv_a");
1203
+ }
1204
+
1205
+ const statusFiltered = await t.query(api.billing.queries.listInvoices, {
1206
+ accountId: "acct_inv_a",
1207
+ status: "paid",
1208
+ });
1209
+
1210
+ expect(statusFiltered).toHaveLength(1);
1211
+ expect(statusFiltered[0].stripeInvoiceId).toBe("inv_acct_a1");
1212
+ });
1213
+ });
1214
+
1215
+ describe("billing — subscription backfills orphaned invoices", () => {
1216
+ it("upsertSubscription patches orphaned invoices with userId", async () => {
1217
+ const t = convexTest(schema, modules);
1218
+
1219
+ // Insert an invoice linked to a subscription but without userId
1220
+ await t.run(async (ctx) => {
1221
+ await ctx.db.insert("invoices", {
1222
+ stripeInvoiceId: "inv_orphan",
1223
+ userId: "",
1224
+ subscriptionId: "sub_backfill",
1225
+ status: "paid",
1226
+ currency: "usd",
1227
+ amountDue: 3000,
1228
+ amountPaid: 3000,
1229
+ });
1230
+ });
1231
+
1232
+ // Now upsert the subscription — should backfill the invoice
1233
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1234
+ stripeSubscriptionId: "sub_backfill",
1235
+ userId: "user_backfill",
1236
+ status: "active",
1237
+ cancelAtPeriodEnd: false,
1238
+ isTrialing: false,
1239
+ });
1240
+
1241
+ const invoices = await t.query(api.billing.queries.listInvoices, {
1242
+ userId: "user_backfill",
1243
+ });
1244
+
1245
+ expect(invoices).toHaveLength(1);
1246
+ expect(invoices[0].stripeInvoiceId).toBe("inv_orphan");
1247
+ });
1248
+ });
1249
+
1250
+ // =============================================================================
1251
+ // CONNECT — payment and payout mutations and queries
1252
+ // =============================================================================
1253
+
1254
+ describe("connect — payment mutations and queries", () => {
1255
+ it("upsertPayment inserts new payment", async () => {
1256
+ const t = convexTest(schema, modules);
1257
+
1258
+ await t.mutation(api.connect.mutations.upsertPayment, {
1259
+ stripePaymentIntentId: "pi_001",
1260
+ userId: "user_pay_001",
1261
+ amount: 5000,
1262
+ currency: "usd",
1263
+ status: "succeeded",
1264
+ });
1265
+
1266
+ const payments = await t.run(async (ctx) => {
1267
+ return await ctx.db.query("payments").collect();
1268
+ });
1269
+
1270
+ expect(payments).toHaveLength(1);
1271
+ expect(payments[0]).toMatchObject({
1272
+ stripePaymentIntentId: "pi_001",
1273
+ amount: 5000,
1274
+ status: "succeeded",
1275
+ });
1276
+ });
1277
+
1278
+ it("upsertPayment updates existing payment by stripePaymentIntentId", async () => {
1279
+ const t = convexTest(schema, modules);
1280
+
1281
+ await t.mutation(api.connect.mutations.upsertPayment, {
1282
+ stripePaymentIntentId: "pi_002",
1283
+ userId: "user_pay_002",
1284
+ amount: 3000,
1285
+ currency: "usd",
1286
+ status: "processing",
1287
+ });
1288
+
1289
+ await t.mutation(api.connect.mutations.upsertPayment, {
1290
+ stripePaymentIntentId: "pi_002",
1291
+ userId: "user_pay_002",
1292
+ amount: 3000,
1293
+ currency: "usd",
1294
+ status: "succeeded",
1295
+ });
1296
+
1297
+ const payments = await t.run(async (ctx) => {
1298
+ return await ctx.db.query("payments").collect();
1299
+ });
1300
+
1301
+ expect(payments).toHaveLength(1);
1302
+ expect(payments[0].status).toBe("succeeded");
1303
+ });
1304
+
1305
+ it("getPaymentByStripeId: returns matching payment", async () => {
1306
+ const t = convexTest(schema, modules);
1307
+
1308
+ await t.mutation(api.connect.mutations.upsertPayment, {
1309
+ stripePaymentIntentId: "pi_by_stripe_001",
1310
+ userId: "user_pay_003",
1311
+ amount: 4200,
1312
+ currency: "usd",
1313
+ status: "succeeded",
1314
+ });
1315
+
1316
+ const payment = await t.query(api.connect.queries.getPaymentByStripeId, {
1317
+ stripePaymentIntentId: "pi_by_stripe_001",
1318
+ });
1319
+
1320
+ expect(payment).not.toBeNull();
1321
+ expect(payment!.stripePaymentIntentId).toBe("pi_by_stripe_001");
1322
+ expect(payment!.userId).toBe("user_pay_003");
1323
+ expect(payment!.amount).toBe(4200);
1324
+ });
1325
+
1326
+ it("getPaymentByStripeId: returns null for unknown id", async () => {
1327
+ const t = convexTest(schema, modules);
1328
+
1329
+ const payment = await t.query(api.connect.queries.getPaymentByStripeId, {
1330
+ stripePaymentIntentId: "pi_does_not_exist",
1331
+ });
1332
+
1333
+ expect(payment).toBeNull();
1334
+ });
1335
+ });
1336
+
1337
+ describe("connect — payout mutations and queries", () => {
1338
+ it("upsertPayout + getPayout round trip", async () => {
1339
+ const t = convexTest(schema, modules);
1340
+
1341
+ await t.mutation(api.connect.mutations.upsertPayout, {
1342
+ stripePayoutId: "po_001",
1343
+ accountId: "acct_po_001",
1344
+ amount: 10000,
1345
+ currency: "usd",
1346
+ status: "pending",
1347
+ });
1348
+
1349
+ const payouts = await t.run(async (ctx) => {
1350
+ return await ctx.db.query("payouts").collect();
1351
+ });
1352
+
1353
+ expect(payouts).toHaveLength(1);
1354
+
1355
+ const payout = await t.query(api.connect.queries.getPayout, {
1356
+ payoutId: payouts[0]._id,
1357
+ });
1358
+
1359
+ expect(payout).toMatchObject({
1360
+ stripePayoutId: "po_001",
1361
+ amount: 10000,
1362
+ status: "pending",
1363
+ });
1364
+ });
1365
+
1366
+ it("upsertPayout updates existing payout", async () => {
1367
+ const t = convexTest(schema, modules);
1368
+
1369
+ await t.mutation(api.connect.mutations.upsertPayout, {
1370
+ stripePayoutId: "po_002",
1371
+ accountId: "acct_po_002",
1372
+ amount: 7500,
1373
+ currency: "usd",
1374
+ status: "pending",
1375
+ });
1376
+
1377
+ await t.mutation(api.connect.mutations.upsertPayout, {
1378
+ stripePayoutId: "po_002",
1379
+ accountId: "acct_po_002",
1380
+ amount: 7500,
1381
+ currency: "usd",
1382
+ status: "paid",
1383
+ arrivalDate: "2030-01-15",
1384
+ });
1385
+
1386
+ const payouts = await t.run(async (ctx) => {
1387
+ return await ctx.db.query("payouts").collect();
1388
+ });
1389
+
1390
+ expect(payouts).toHaveLength(1);
1391
+ expect(payouts[0].status).toBe("paid");
1392
+ expect(payouts[0].arrivalDate).toBe("2030-01-15");
1393
+ });
1394
+
1395
+ it("listPayouts: filters by accountId", async () => {
1396
+ const t = convexTest(schema, modules);
1397
+
1398
+ await t.mutation(api.connect.mutations.upsertPayout, {
1399
+ stripePayoutId: "po_acct_a",
1400
+ accountId: "acct_a",
1401
+ amount: 1000,
1402
+ currency: "usd",
1403
+ status: "paid",
1404
+ });
1405
+
1406
+ await t.mutation(api.connect.mutations.upsertPayout, {
1407
+ stripePayoutId: "po_acct_b",
1408
+ accountId: "acct_b",
1409
+ amount: 2000,
1410
+ currency: "usd",
1411
+ status: "paid",
1412
+ });
1413
+
1414
+ const payouts = await t.query(api.connect.queries.listPayouts, {
1415
+ accountId: "acct_a",
1416
+ });
1417
+
1418
+ expect(payouts).toHaveLength(1);
1419
+ expect(payouts[0].stripePayoutId).toBe("po_acct_a");
1420
+ });
1421
+
1422
+ it("listPayouts: filters by status", async () => {
1423
+ const t = convexTest(schema, modules);
1424
+
1425
+ await t.mutation(api.connect.mutations.upsertPayout, {
1426
+ stripePayoutId: "po_pending",
1427
+ accountId: "acct_st",
1428
+ amount: 500,
1429
+ currency: "usd",
1430
+ status: "pending",
1431
+ });
1432
+
1433
+ await t.mutation(api.connect.mutations.upsertPayout, {
1434
+ stripePayoutId: "po_paid",
1435
+ accountId: "acct_st",
1436
+ amount: 1500,
1437
+ currency: "usd",
1438
+ status: "paid",
1439
+ });
1440
+
1441
+ const pending = await t.query(api.connect.queries.listPayouts, {
1442
+ status: "pending",
1443
+ });
1444
+
1445
+ expect(pending).toHaveLength(1);
1446
+ expect(pending[0].stripePayoutId).toBe("po_pending");
1447
+ });
1448
+
1449
+ it("listPayouts: returns all when no filter", async () => {
1450
+ const t = convexTest(schema, modules);
1451
+
1452
+ await t.mutation(api.connect.mutations.upsertPayout, {
1453
+ stripePayoutId: "po_all_1",
1454
+ accountId: "acct_all",
1455
+ amount: 100,
1456
+ currency: "usd",
1457
+ status: "pending",
1458
+ });
1459
+
1460
+ await t.mutation(api.connect.mutations.upsertPayout, {
1461
+ stripePayoutId: "po_all_2",
1462
+ accountId: "acct_all",
1463
+ amount: 200,
1464
+ currency: "eur",
1465
+ status: "paid",
1466
+ });
1467
+
1468
+ const all = await t.query(api.connect.queries.listPayouts, {});
1469
+
1470
+ expect(all).toHaveLength(2);
1471
+ });
1472
+
1473
+ it("getPayoutByStripeId: returns matching payout", async () => {
1474
+ const t = convexTest(schema, modules);
1475
+
1476
+ await t.mutation(api.connect.mutations.upsertPayout, {
1477
+ stripePayoutId: "po_by_stripe_001",
1478
+ accountId: "acct_po_stripe",
1479
+ amount: 8800,
1480
+ currency: "usd",
1481
+ status: "paid",
1482
+ });
1483
+
1484
+ const payout = await t.query(api.connect.queries.getPayoutByStripeId, {
1485
+ stripePayoutId: "po_by_stripe_001",
1486
+ });
1487
+
1488
+ expect(payout).not.toBeNull();
1489
+ expect(payout!.stripePayoutId).toBe("po_by_stripe_001");
1490
+ expect(payout!.accountId).toBe("acct_po_stripe");
1491
+ expect(payout!.amount).toBe(8800);
1492
+ });
1493
+
1494
+ it("getPayoutByStripeId: returns null for unknown id", async () => {
1495
+ const t = convexTest(schema, modules);
1496
+
1497
+ const payout = await t.query(api.connect.queries.getPayoutByStripeId, {
1498
+ stripePayoutId: "po_does_not_exist",
1499
+ });
1500
+
1501
+ expect(payout).toBeNull();
1502
+ });
1503
+ });
1504
+
1505
+ // =============================================================================
1506
+ // WEBHOOKS — listWebhookEvents with filters
1507
+ // =============================================================================
1508
+
1509
+ describe("webhooks — listWebhookEvents", () => {
1510
+ it("returns all events in descending order", async () => {
1511
+ const t = convexTest(schema, modules);
1512
+
1513
+ await t.run(async (ctx) => {
1514
+ await ctx.db.insert("webhookEvents", {
1515
+ stripeEventId: "evt_list_1",
1516
+ eventType: "invoice.paid",
1517
+ status: "processed",
1518
+ processedAt: Date.now() - 1000,
1519
+ });
1520
+ await ctx.db.insert("webhookEvents", {
1521
+ stripeEventId: "evt_list_2",
1522
+ eventType: "checkout.session.completed",
1523
+ status: "processed",
1524
+ processedAt: Date.now(),
1525
+ });
1526
+ });
1527
+
1528
+ const events = await t.query(api.webhooks.queries.listWebhookEvents, {});
1529
+
1530
+ expect(events).toHaveLength(2);
1531
+ // Most recent first
1532
+ expect(events[0].stripeEventId).toBe("evt_list_2");
1533
+ });
1534
+
1535
+ it("filters by eventType", async () => {
1536
+ const t = convexTest(schema, modules);
1537
+
1538
+ await t.run(async (ctx) => {
1539
+ await ctx.db.insert("webhookEvents", {
1540
+ stripeEventId: "evt_type_1",
1541
+ eventType: "invoice.paid",
1542
+ status: "processed",
1543
+ processedAt: Date.now(),
1544
+ });
1545
+ await ctx.db.insert("webhookEvents", {
1546
+ stripeEventId: "evt_type_2",
1547
+ eventType: "checkout.session.completed",
1548
+ status: "processed",
1549
+ processedAt: Date.now(),
1550
+ });
1551
+ });
1552
+
1553
+ const invoiceEvents = await t.query(
1554
+ api.webhooks.queries.listWebhookEvents,
1555
+ {
1556
+ eventType: "invoice.paid",
1557
+ },
1558
+ );
1559
+
1560
+ expect(invoiceEvents).toHaveLength(1);
1561
+ expect(invoiceEvents[0].eventType).toBe("invoice.paid");
1562
+ });
1563
+
1564
+ it("filters by status", async () => {
1565
+ const t = convexTest(schema, modules);
1566
+
1567
+ await t.run(async (ctx) => {
1568
+ await ctx.db.insert("webhookEvents", {
1569
+ stripeEventId: "evt_st_1",
1570
+ eventType: "invoice.paid",
1571
+ status: "processed",
1572
+ processedAt: Date.now(),
1573
+ });
1574
+ await ctx.db.insert("webhookEvents", {
1575
+ stripeEventId: "evt_st_2",
1576
+ eventType: "invoice.paid",
1577
+ status: "failed",
1578
+ processedAt: Date.now(),
1579
+ lastError: "Something went wrong",
1580
+ });
1581
+ });
1582
+
1583
+ const failed = await t.query(api.webhooks.queries.listWebhookEvents, {
1584
+ status: "failed",
1585
+ });
1586
+
1587
+ expect(failed).toHaveLength(1);
1588
+ expect(failed[0].stripeEventId).toBe("evt_st_2");
1589
+ });
1590
+
1591
+ it("combines eventType and status filters", async () => {
1592
+ const t = convexTest(schema, modules);
1593
+
1594
+ await t.run(async (ctx) => {
1595
+ await ctx.db.insert("webhookEvents", {
1596
+ stripeEventId: "evt_combo_1",
1597
+ eventType: "invoice.paid",
1598
+ status: "processed",
1599
+ processedAt: Date.now(),
1600
+ });
1601
+ await ctx.db.insert("webhookEvents", {
1602
+ stripeEventId: "evt_combo_2",
1603
+ eventType: "invoice.paid",
1604
+ status: "failed",
1605
+ processedAt: Date.now(),
1606
+ });
1607
+ await ctx.db.insert("webhookEvents", {
1608
+ stripeEventId: "evt_combo_3",
1609
+ eventType: "checkout.session.completed",
1610
+ status: "failed",
1611
+ processedAt: Date.now(),
1612
+ });
1613
+ });
1614
+
1615
+ const result = await t.query(api.webhooks.queries.listWebhookEvents, {
1616
+ eventType: "invoice.paid",
1617
+ status: "failed",
1618
+ });
1619
+
1620
+ expect(result).toHaveLength(1);
1621
+ expect(result[0].stripeEventId).toBe("evt_combo_2");
1622
+ });
1623
+ });
1624
+
1625
+ // =============================================================================
1626
+ // REGRESSION: filter-after-take completeness (plan 002)
1627
+ // =============================================================================
1628
+
1629
+ describe("regression — listSubscriptions returns complete results beyond limit", () => {
1630
+ it("returns all active subscriptions even when canceled ones fill the default limit", async () => {
1631
+ const t = convexTest(schema, modules);
1632
+ const accountId = "acct_regression_sub";
1633
+
1634
+ // Insert 55 canceled then 5 active subscriptions for the same accountId.
1635
+ // Old code: take(50) → JS filter → returns 0 active. New code: compound index → 5.
1636
+ for (let i = 0; i < 55; i++) {
1637
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1638
+ stripeSubscriptionId: `sub_canceled_${i}`,
1639
+ accountId,
1640
+ userId: "user_regression_sub",
1641
+ status: "canceled",
1642
+ cancelAtPeriodEnd: false,
1643
+ isTrialing: false,
1644
+ });
1645
+ }
1646
+ for (let i = 0; i < 5; i++) {
1647
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1648
+ stripeSubscriptionId: `sub_active_${i}`,
1649
+ accountId,
1650
+ userId: "user_regression_sub",
1651
+ status: "active",
1652
+ cancelAtPeriodEnd: false,
1653
+ isTrialing: false,
1654
+ });
1655
+ }
1656
+
1657
+ const result = await t.query(api.billing.queries.listSubscriptions, {
1658
+ accountId,
1659
+ status: "active",
1660
+ });
1661
+
1662
+ expect(result).toHaveLength(5);
1663
+ expect(result.every((s) => s.status === "active")).toBe(true);
1664
+ });
1665
+
1666
+ it("respects limit when filtering by status via compound index", async () => {
1667
+ const t = convexTest(schema, modules);
1668
+ const accountId = "acct_regression_sub_limit";
1669
+
1670
+ for (let i = 0; i < 60; i++) {
1671
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1672
+ stripeSubscriptionId: `sub_lim_active_${i}`,
1673
+ accountId,
1674
+ userId: "user_regression_sub_limit",
1675
+ status: "active",
1676
+ cancelAtPeriodEnd: false,
1677
+ isTrialing: false,
1678
+ });
1679
+ }
1680
+
1681
+ const result = await t.query(api.billing.queries.listSubscriptions, {
1682
+ accountId,
1683
+ status: "active",
1684
+ limit: 10,
1685
+ });
1686
+
1687
+ expect(result).toHaveLength(10);
1688
+ });
1689
+ });
1690
+
1691
+ describe("regression — listInvoices returns complete results beyond limit (userId branch)", () => {
1692
+ it("returns all paid invoices even when other statuses fill the default limit", async () => {
1693
+ const t = convexTest(schema, modules);
1694
+ const userId = "user_regression_inv";
1695
+
1696
+ // Insert 55 open then 5 paid invoices for the same userId.
1697
+ for (let i = 0; i < 55; i++) {
1698
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1699
+ stripeInvoiceId: `inv_open_${i}`,
1700
+ userId,
1701
+ status: "open",
1702
+ currency: "usd",
1703
+ amountDue: 1000,
1704
+ amountPaid: 0,
1705
+ });
1706
+ }
1707
+ for (let i = 0; i < 5; i++) {
1708
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1709
+ stripeInvoiceId: `inv_paid_${i}`,
1710
+ userId,
1711
+ status: "paid",
1712
+ currency: "usd",
1713
+ amountDue: 1000,
1714
+ amountPaid: 1000,
1715
+ });
1716
+ }
1717
+
1718
+ const result = await t.query(api.billing.queries.listInvoices, {
1719
+ userId,
1720
+ status: "paid",
1721
+ });
1722
+
1723
+ expect(result).toHaveLength(5);
1724
+ expect(result.every((i) => i.status === "paid")).toBe(true);
1725
+ });
1726
+ });
1727
+
1728
+ describe("regression — listProducts returns complete results beyond limit", () => {
1729
+ it("returns all inactive products even when active ones fill the default limit", async () => {
1730
+ const t = convexTest(schema, modules);
1731
+ const accountId = "acct_regression_prod";
1732
+
1733
+ // Insert 55 active then 5 inactive products for the same accountId.
1734
+ for (let i = 0; i < 55; i++) {
1735
+ await t.mutation(api.products.mutations.upsertProduct, {
1736
+ stripeProductId: `prod_active_${i}`,
1737
+ accountId,
1738
+ name: `Active Product ${i}`,
1739
+ active: true,
1740
+ });
1741
+ }
1742
+ for (let i = 0; i < 5; i++) {
1743
+ await t.mutation(api.products.mutations.upsertProduct, {
1744
+ stripeProductId: `prod_inactive_${i}`,
1745
+ accountId,
1746
+ name: `Inactive Product ${i}`,
1747
+ active: false,
1748
+ });
1749
+ }
1750
+
1751
+ const result = await t.query(api.products.queries.listProducts, {
1752
+ accountId,
1753
+ active: false,
1754
+ });
1755
+
1756
+ // Old code: take(50) → JS filter on active===false → returns 0. New: compound index → 5.
1757
+ expect(result).toHaveLength(5);
1758
+ expect(result.every((p) => p.active === false)).toBe(true);
1759
+ });
1760
+ });
1761
+
1762
+ describe("guard — empty userId/orgId never matches user-scoped queries", () => {
1763
+ it("getActiveSubscription({ userId: '' }) returns null even when an unattributed row exists", async () => {
1764
+ const t = convexTest(schema, modules);
1765
+
1766
+ // Insert an unattributed subscription (the sentinel row written by webhook processors).
1767
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1768
+ stripeSubscriptionId: "sub_unattr_001",
1769
+ userId: "",
1770
+ status: "active",
1771
+ cancelAtPeriodEnd: false,
1772
+ isTrialing: false,
1773
+ });
1774
+
1775
+ const result = await t.query(api.billing.queries.getActiveSubscription, {
1776
+ userId: "",
1777
+ });
1778
+
1779
+ expect(result).toBeNull();
1780
+ });
1781
+
1782
+ it("listSubscriptionsByUser({ userId: '' }) returns [] even when an unattributed row exists", async () => {
1783
+ const t = convexTest(schema, modules);
1784
+
1785
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1786
+ stripeSubscriptionId: "sub_unattr_002",
1787
+ userId: "",
1788
+ status: "active",
1789
+ cancelAtPeriodEnd: false,
1790
+ isTrialing: false,
1791
+ });
1792
+
1793
+ const result = await t.query(api.billing.queries.listSubscriptionsByUser, {
1794
+ userId: "",
1795
+ });
1796
+
1797
+ expect(result).toEqual([]);
1798
+ });
1799
+
1800
+ it("listSubscriptionsByUser({ userId: 'user_1' }) returns only the user_1 row, not the '' row", async () => {
1801
+ const t = convexTest(schema, modules);
1802
+
1803
+ // Insert one unattributed and one attributed subscription.
1804
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1805
+ stripeSubscriptionId: "sub_unattr_003",
1806
+ userId: "",
1807
+ status: "active",
1808
+ cancelAtPeriodEnd: false,
1809
+ isTrialing: false,
1810
+ });
1811
+ await t.mutation(api.billing.mutations.upsertSubscription, {
1812
+ stripeSubscriptionId: "sub_user1_001",
1813
+ userId: "user_1",
1814
+ status: "active",
1815
+ cancelAtPeriodEnd: false,
1816
+ isTrialing: false,
1817
+ });
1818
+
1819
+ const result = await t.query(api.billing.queries.listSubscriptionsByUser, {
1820
+ userId: "user_1",
1821
+ });
1822
+
1823
+ expect(result).toHaveLength(1);
1824
+ expect(result[0].stripeSubscriptionId).toBe("sub_user1_001");
1825
+ });
1826
+
1827
+ it("listInvoices({ userId: '' }) falls through to the unfiltered branch", async () => {
1828
+ const t = convexTest(schema, modules);
1829
+
1830
+ // Insert one unattributed invoice and one attributed invoice.
1831
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1832
+ stripeInvoiceId: "inv_unattr_001",
1833
+ userId: "",
1834
+ status: "paid",
1835
+ currency: "usd",
1836
+ amountDue: 1000,
1837
+ amountPaid: 1000,
1838
+ });
1839
+ await t.mutation(api.billing.mutations.upsertInvoice, {
1840
+ stripeInvoiceId: "inv_user2_001",
1841
+ userId: "user_2",
1842
+ status: "paid",
1843
+ currency: "usd",
1844
+ amountDue: 2000,
1845
+ amountPaid: 2000,
1846
+ });
1847
+
1848
+ // With userId: "" the guard causes fallthrough to the unfiltered take — both rows should appear.
1849
+ const result = await t.query(api.billing.queries.listInvoices, {
1850
+ userId: "",
1851
+ });
1852
+
1853
+ expect(result.length).toBeGreaterThanOrEqual(2);
1854
+ const ids = result.map((i) => i.stripeInvoiceId);
1855
+ expect(ids).toContain("inv_unattr_001");
1856
+ expect(ids).toContain("inv_user2_001");
1857
+ });
1858
+ });