@fantastic.dev/better-stripe 0.7.0 → 0.8.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 (343) hide show
  1. package/CHANGELOG.md +23 -18
  2. package/README.md +122 -90
  3. package/dist/client/billing/checkout.d.ts +1 -1
  4. package/dist/client/billing/checkout.d.ts.map +1 -1
  5. package/dist/client/billing/checkout.js +7 -2
  6. package/dist/client/billing/checkout.js.map +1 -1
  7. package/dist/client/connect/paymentMethods.d.ts.map +1 -1
  8. package/dist/client/connect/paymentMethods.js.map +1 -1
  9. package/dist/client/connect/refundActor.d.ts.map +1 -1
  10. package/dist/client/connect/refundActor.js.map +1 -1
  11. package/dist/client/connect/refunds.d.ts.map +1 -1
  12. package/dist/client/connect/refunds.js.map +1 -1
  13. package/dist/client/connect/transfers.d.ts.map +1 -1
  14. package/dist/client/connect/transfers.js +15 -4
  15. package/dist/client/connect/transfers.js.map +1 -1
  16. package/dist/client/core/accountDefaults.d.ts +6 -0
  17. package/dist/client/core/accountDefaults.d.ts.map +1 -0
  18. package/dist/client/core/accountDefaults.js +15 -0
  19. package/dist/client/core/accountDefaults.js.map +1 -0
  20. package/dist/client/core/accounts.d.ts +1 -5
  21. package/dist/client/core/accounts.d.ts.map +1 -1
  22. package/dist/client/core/accounts.js +2 -14
  23. package/dist/client/core/accounts.js.map +1 -1
  24. package/dist/client/core/fees.d.ts.map +1 -1
  25. package/dist/client/core/fees.js +7 -2
  26. package/dist/client/core/fees.js.map +1 -1
  27. package/dist/client/index.d.ts +1 -1
  28. package/dist/client/index.d.ts.map +1 -1
  29. package/dist/client/products/prices.d.ts.map +1 -1
  30. package/dist/client/products/prices.js.map +1 -1
  31. package/dist/client/products/products.d.ts.map +1 -1
  32. package/dist/client/products/products.js +3 -1
  33. package/dist/client/products/products.js.map +1 -1
  34. package/dist/client/utils/owner.d.ts.map +1 -1
  35. package/dist/client/utils/owner.js +3 -1
  36. package/dist/client/utils/owner.js.map +1 -1
  37. package/dist/client/utils/stripeDashboardUrl.d.ts.map +1 -1
  38. package/dist/client/utils/stripeDashboardUrl.js.map +1 -1
  39. package/dist/client/webhooks/helpers.d.ts +10 -0
  40. package/dist/client/webhooks/helpers.d.ts.map +1 -1
  41. package/dist/client/webhooks/helpers.js +18 -0
  42. package/dist/client/webhooks/helpers.js.map +1 -1
  43. package/dist/client/webhooks/processors.d.ts.map +1 -1
  44. package/dist/client/webhooks/processors.js +1 -19
  45. package/dist/client/webhooks/processors.js.map +1 -1
  46. package/dist/component/connect/mutations.d.ts.map +1 -1
  47. package/dist/component/connect/mutations.js +4 -33
  48. package/dist/component/connect/mutations.js.map +1 -1
  49. package/dist/component/connect/schema.d.ts.map +1 -1
  50. package/dist/component/connect/schema.js.map +1 -1
  51. package/dist/component/lib/paymentSeller.d.ts +3 -0
  52. package/dist/component/lib/paymentSeller.d.ts.map +1 -0
  53. package/dist/component/lib/paymentSeller.js +10 -0
  54. package/dist/component/lib/paymentSeller.js.map +1 -0
  55. package/dist/component/lib/reversals.d.ts +10 -0
  56. package/dist/component/lib/reversals.d.ts.map +1 -1
  57. package/dist/component/lib/reversals.js +17 -0
  58. package/dist/component/lib/reversals.js.map +1 -1
  59. package/dist/react/components/ConnectProvider.d.ts +1 -1
  60. package/dist/react/components/ConnectProvider.d.ts.map +1 -1
  61. package/dist/react/components/ConnectProvider.js +18 -4
  62. package/dist/react/components/ConnectProvider.js.map +1 -1
  63. package/dist/react/components/ConnectStatusBadge.d.ts.map +1 -1
  64. package/dist/react/components/ConnectStatusBadge.js.map +1 -1
  65. package/dist/react/components/EmbeddedDisputes.d.ts +1 -1
  66. package/dist/react/components/EmbeddedDisputes.d.ts.map +1 -1
  67. package/dist/react/components/EmbeddedDisputes.js +1 -1
  68. package/dist/react/components/EmbeddedDisputes.js.map +1 -1
  69. package/dist/react/components/SplitBreakdown.d.ts.map +1 -1
  70. package/dist/react/components/SplitBreakdown.js +12 -2
  71. package/dist/react/components/SplitBreakdown.js.map +1 -1
  72. package/dist/react/hooks/useCheckoutSession.d.ts.map +1 -1
  73. package/dist/react/hooks/useCheckoutSession.js.map +1 -1
  74. package/dist/react/hooks/useConfirmPayment.d.ts.map +1 -1
  75. package/dist/react/hooks/useConfirmPayment.js.map +1 -1
  76. package/dist/react/index.d.ts +1 -0
  77. package/dist/react/index.d.ts.map +1 -1
  78. package/dist/react/index.js +2 -0
  79. package/dist/react/index.js.map +1 -1
  80. package/dist/react/workflows/Account.d.ts +67 -0
  81. package/dist/react/workflows/Account.d.ts.map +1 -0
  82. package/dist/react/workflows/Account.js +74 -0
  83. package/dist/react/workflows/Account.js.map +1 -0
  84. package/dist/react/workflows/Billing.d.ts +60 -0
  85. package/dist/react/workflows/Billing.d.ts.map +1 -0
  86. package/dist/react/workflows/Billing.js +84 -0
  87. package/dist/react/workflows/Billing.js.map +1 -0
  88. package/dist/react/workflows/BillingPlans.d.ts +45 -0
  89. package/dist/react/workflows/BillingPlans.d.ts.map +1 -0
  90. package/dist/react/workflows/BillingPlans.js +51 -0
  91. package/dist/react/workflows/BillingPlans.js.map +1 -0
  92. package/dist/react/workflows/Checkout.d.ts +46 -0
  93. package/dist/react/workflows/Checkout.d.ts.map +1 -0
  94. package/dist/react/workflows/Checkout.js +61 -0
  95. package/dist/react/workflows/Checkout.js.map +1 -0
  96. package/dist/react/workflows/CheckoutChooser.d.ts +20 -0
  97. package/dist/react/workflows/CheckoutChooser.d.ts.map +1 -0
  98. package/dist/react/workflows/CheckoutChooser.js +24 -0
  99. package/dist/react/workflows/CheckoutChooser.js.map +1 -0
  100. package/dist/react/workflows/CheckoutForms.d.ts +26 -0
  101. package/dist/react/workflows/CheckoutForms.d.ts.map +1 -0
  102. package/dist/react/workflows/CheckoutForms.js +126 -0
  103. package/dist/react/workflows/CheckoutForms.js.map +1 -0
  104. package/dist/react/workflows/ClipboardButton.d.ts +17 -0
  105. package/dist/react/workflows/ClipboardButton.d.ts.map +1 -0
  106. package/dist/react/workflows/ClipboardButton.js +35 -0
  107. package/dist/react/workflows/ClipboardButton.js.map +1 -0
  108. package/dist/react/workflows/Collection.d.ts +30 -0
  109. package/dist/react/workflows/Collection.d.ts.map +1 -0
  110. package/dist/react/workflows/Collection.js +25 -0
  111. package/dist/react/workflows/Collection.js.map +1 -0
  112. package/dist/react/workflows/Collections.d.ts +56 -0
  113. package/dist/react/workflows/Collections.d.ts.map +1 -0
  114. package/dist/react/workflows/Collections.js +111 -0
  115. package/dist/react/workflows/Collections.js.map +1 -0
  116. package/dist/react/workflows/Connect.d.ts +19 -0
  117. package/dist/react/workflows/Connect.d.ts.map +1 -0
  118. package/dist/react/workflows/Connect.js +43 -0
  119. package/dist/react/workflows/Connect.js.map +1 -0
  120. package/dist/react/workflows/Costs.d.ts +48 -0
  121. package/dist/react/workflows/Costs.d.ts.map +1 -0
  122. package/dist/react/workflows/Costs.js +66 -0
  123. package/dist/react/workflows/Costs.js.map +1 -0
  124. package/dist/react/workflows/Disputes.d.ts +36 -0
  125. package/dist/react/workflows/Disputes.d.ts.map +1 -0
  126. package/dist/react/workflows/Disputes.js +74 -0
  127. package/dist/react/workflows/Disputes.js.map +1 -0
  128. package/dist/react/workflows/Earnings.d.ts +42 -0
  129. package/dist/react/workflows/Earnings.d.ts.map +1 -0
  130. package/dist/react/workflows/Earnings.js +38 -0
  131. package/dist/react/workflows/Earnings.js.map +1 -0
  132. package/dist/react/workflows/Financials.d.ts +43 -0
  133. package/dist/react/workflows/Financials.d.ts.map +1 -0
  134. package/dist/react/workflows/Financials.js +57 -0
  135. package/dist/react/workflows/Financials.js.map +1 -0
  136. package/dist/react/workflows/IntegrationSwitch.d.ts +23 -0
  137. package/dist/react/workflows/IntegrationSwitch.d.ts.map +1 -0
  138. package/dist/react/workflows/IntegrationSwitch.js +31 -0
  139. package/dist/react/workflows/IntegrationSwitch.js.map +1 -0
  140. package/dist/react/workflows/Onboarding.d.ts +56 -0
  141. package/dist/react/workflows/Onboarding.d.ts.map +1 -0
  142. package/dist/react/workflows/Onboarding.js +86 -0
  143. package/dist/react/workflows/Onboarding.js.map +1 -0
  144. package/dist/react/workflows/Overview.d.ts +51 -0
  145. package/dist/react/workflows/Overview.d.ts.map +1 -0
  146. package/dist/react/workflows/Overview.js +63 -0
  147. package/dist/react/workflows/Overview.js.map +1 -0
  148. package/dist/react/workflows/PaymentMethods.d.ts +35 -0
  149. package/dist/react/workflows/PaymentMethods.d.ts.map +1 -0
  150. package/dist/react/workflows/PaymentMethods.js +63 -0
  151. package/dist/react/workflows/PaymentMethods.js.map +1 -0
  152. package/dist/react/workflows/PaymentReceipt.d.ts +20 -0
  153. package/dist/react/workflows/PaymentReceipt.d.ts.map +1 -0
  154. package/dist/react/workflows/PaymentReceipt.js +24 -0
  155. package/dist/react/workflows/PaymentReceipt.js.map +1 -0
  156. package/dist/react/workflows/Payouts.d.ts +47 -0
  157. package/dist/react/workflows/Payouts.d.ts.map +1 -0
  158. package/dist/react/workflows/Payouts.js +87 -0
  159. package/dist/react/workflows/Payouts.js.map +1 -0
  160. package/dist/react/workflows/Products.d.ts +92 -0
  161. package/dist/react/workflows/Products.d.ts.map +1 -0
  162. package/dist/react/workflows/Products.js +179 -0
  163. package/dist/react/workflows/Products.js.map +1 -0
  164. package/dist/react/workflows/ReferralLinks.d.ts +26 -0
  165. package/dist/react/workflows/ReferralLinks.d.ts.map +1 -0
  166. package/dist/react/workflows/ReferralLinks.js +30 -0
  167. package/dist/react/workflows/ReferralLinks.js.map +1 -0
  168. package/dist/react/workflows/Refunds.d.ts +72 -0
  169. package/dist/react/workflows/Refunds.d.ts.map +1 -0
  170. package/dist/react/workflows/Refunds.js +95 -0
  171. package/dist/react/workflows/Refunds.js.map +1 -0
  172. package/dist/react/workflows/Setup.d.ts +50 -0
  173. package/dist/react/workflows/Setup.d.ts.map +1 -0
  174. package/dist/react/workflows/Setup.js +59 -0
  175. package/dist/react/workflows/Setup.js.map +1 -0
  176. package/dist/react/workflows/Storefront.d.ts +53 -0
  177. package/dist/react/workflows/Storefront.d.ts.map +1 -0
  178. package/dist/react/workflows/Storefront.js +44 -0
  179. package/dist/react/workflows/Storefront.js.map +1 -0
  180. package/dist/react/workflows/SubscriptionOverview.d.ts +13 -0
  181. package/dist/react/workflows/SubscriptionOverview.d.ts.map +1 -0
  182. package/dist/react/workflows/SubscriptionOverview.js +26 -0
  183. package/dist/react/workflows/SubscriptionOverview.js.map +1 -0
  184. package/dist/react/workflows/Subscriptions.d.ts +92 -0
  185. package/dist/react/workflows/Subscriptions.d.ts.map +1 -0
  186. package/dist/react/workflows/Subscriptions.js +149 -0
  187. package/dist/react/workflows/Subscriptions.js.map +1 -0
  188. package/dist/react/workflows/Tasks.d.ts +40 -0
  189. package/dist/react/workflows/Tasks.d.ts.map +1 -0
  190. package/dist/react/workflows/Tasks.js +113 -0
  191. package/dist/react/workflows/Tasks.js.map +1 -0
  192. package/dist/react/workflows/checkout-options.d.ts +37 -0
  193. package/dist/react/workflows/checkout-options.d.ts.map +1 -0
  194. package/dist/react/workflows/checkout-options.js +43 -0
  195. package/dist/react/workflows/checkout-options.js.map +1 -0
  196. package/dist/react/workflows/current-subscription.d.ts +11 -0
  197. package/dist/react/workflows/current-subscription.d.ts.map +1 -0
  198. package/dist/react/workflows/current-subscription.js +14 -0
  199. package/dist/react/workflows/current-subscription.js.map +1 -0
  200. package/dist/react/workflows/filters.d.ts +17 -0
  201. package/dist/react/workflows/filters.d.ts.map +1 -0
  202. package/dist/react/workflows/filters.js +23 -0
  203. package/dist/react/workflows/filters.js.map +1 -0
  204. package/dist/react/workflows/index.d.ts +70 -0
  205. package/dist/react/workflows/index.d.ts.map +1 -0
  206. package/dist/react/workflows/index.js +38 -0
  207. package/dist/react/workflows/index.js.map +1 -0
  208. package/dist/react/workflows/useWorkflowAction.d.ts +11 -0
  209. package/dist/react/workflows/useWorkflowAction.d.ts.map +1 -0
  210. package/dist/react/workflows/useWorkflowAction.js +68 -0
  211. package/dist/react/workflows/useWorkflowAction.js.map +1 -0
  212. package/dist/react/workflows/useWorkflowResource.d.ts +9 -0
  213. package/dist/react/workflows/useWorkflowResource.d.ts.map +1 -0
  214. package/dist/react/workflows/useWorkflowResource.js +67 -0
  215. package/dist/react/workflows/useWorkflowResource.js.map +1 -0
  216. package/docs/react-workflows-audit.md +66 -0
  217. package/docs/react-workflows.md +231 -0
  218. package/package.json +19 -3
  219. package/src/client/billing/checkout-ui-modes.test.ts +49 -0
  220. package/src/client/billing/checkout.ts +8 -3
  221. package/src/client/billing/invoices.test.ts +12 -6
  222. package/src/client/connect/paymentMethods.test.ts +3 -1
  223. package/src/client/connect/paymentMethods.ts +4 -1
  224. package/src/client/connect/refundActor.ts +1 -2
  225. package/src/client/connect/refunds.test.ts +35 -10
  226. package/src/client/connect/refunds.ts +4 -1
  227. package/src/client/connect/transfers.test.ts +66 -12
  228. package/src/client/connect/transfers.ts +32 -8
  229. package/src/client/core/accountDefaults.ts +15 -0
  230. package/src/client/core/accounts.ts +14 -17
  231. package/src/client/core/config.test.ts +2 -1
  232. package/src/client/core/descriptors.test.ts +6 -4
  233. package/src/client/core/fees.test.ts +20 -28
  234. package/src/client/core/fees.ts +9 -2
  235. package/src/client/index.test.ts +22 -22
  236. package/src/client/index.ts +1 -1
  237. package/src/client/products/prices.test.ts +8 -2
  238. package/src/client/products/prices.ts +4 -1
  239. package/src/client/products/products.test.ts +61 -20
  240. package/src/client/products/products.ts +3 -1
  241. package/src/client/utils/data.test.ts +3 -1
  242. package/src/client/utils/owner.test.ts +4 -1
  243. package/src/client/utils/owner.ts +5 -1
  244. package/src/client/utils/stripeDashboardUrl.ts +1 -4
  245. package/src/client/webhooks/handler.test.ts +16 -19
  246. package/src/client/webhooks/helpers.test.ts +26 -13
  247. package/src/client/webhooks/helpers.ts +23 -0
  248. package/src/client/webhooks/hooks.test.ts +1 -2
  249. package/src/client/webhooks/processors.test.ts +18 -34
  250. package/src/client/webhooks/processors.ts +1 -23
  251. package/src/client/webhooks.test.ts +1 -2
  252. package/src/component/_generated/api.ts +2 -0
  253. package/src/component/connect/mutations.ts +5 -46
  254. package/src/component/connect/schema.ts +4 -3
  255. package/src/component/connect.test.ts +1 -5
  256. package/src/component/lib/paymentSeller.ts +15 -0
  257. package/src/component/lib/reversals.ts +30 -2
  258. package/src/component/subscription-scoping.test.ts +5 -1
  259. package/src/component/triggers.test.ts +7 -4
  260. package/src/react/components/BuyerBillingView.render.test.tsx +7 -2
  261. package/src/react/components/ConnectProvider.live.test.tsx +61 -0
  262. package/src/react/components/ConnectProvider.tsx +18 -4
  263. package/src/react/components/ConnectStatusBadge.tsx +1 -4
  264. package/src/react/components/DisputeDetail.render.test.tsx +5 -1
  265. package/src/react/components/EarningsSummary.render.test.tsx +2 -6
  266. package/src/react/components/EmbeddedDisputes.render.test.tsx +7 -5
  267. package/src/react/components/EmbeddedDisputes.tsx +4 -1
  268. package/src/react/components/EvidenceForm.render.test.tsx +2 -8
  269. package/src/react/components/SplitBreakdown.render.test.tsx +28 -5
  270. package/src/react/components/SplitBreakdown.tsx +12 -2
  271. package/src/react/hooks/useCheckoutSession.ts +1 -2
  272. package/src/react/hooks/useConfirmPayment.ts +1 -2
  273. package/src/react/hooks/useEarnings.test.ts +43 -8
  274. package/src/react/hooks/useStripeMode.test.ts +5 -8
  275. package/src/react/index.ts +3 -0
  276. package/src/react/workflows/Account.test.tsx +31 -0
  277. package/src/react/workflows/Account.tsx +183 -0
  278. package/src/react/workflows/Billing.test.tsx +45 -0
  279. package/src/react/workflows/Billing.tsx +213 -0
  280. package/src/react/workflows/BillingPlans.test.tsx +31 -0
  281. package/src/react/workflows/BillingPlans.tsx +130 -0
  282. package/src/react/workflows/Checkout.test.tsx +118 -0
  283. package/src/react/workflows/Checkout.tsx +135 -0
  284. package/src/react/workflows/CheckoutChooser.test.tsx +44 -0
  285. package/src/react/workflows/CheckoutChooser.tsx +77 -0
  286. package/src/react/workflows/CheckoutForm.test.tsx +66 -0
  287. package/src/react/workflows/CheckoutForms.test.tsx +123 -0
  288. package/src/react/workflows/CheckoutForms.tsx +247 -0
  289. package/src/react/workflows/ClipboardButton.test.tsx +34 -0
  290. package/src/react/workflows/ClipboardButton.tsx +67 -0
  291. package/src/react/workflows/Collection.tsx +76 -0
  292. package/src/react/workflows/Collections.test.tsx +86 -0
  293. package/src/react/workflows/Collections.tsx +213 -0
  294. package/src/react/workflows/Connect.test.tsx +50 -0
  295. package/src/react/workflows/Connect.tsx +107 -0
  296. package/src/react/workflows/Costs.test.tsx +41 -0
  297. package/src/react/workflows/Costs.tsx +133 -0
  298. package/src/react/workflows/Disputes.test.tsx +25 -0
  299. package/src/react/workflows/Disputes.tsx +164 -0
  300. package/src/react/workflows/Earnings.test.ts +19 -0
  301. package/src/react/workflows/Earnings.tsx +84 -0
  302. package/src/react/workflows/Financials.test.tsx +35 -0
  303. package/src/react/workflows/Financials.tsx +117 -0
  304. package/src/react/workflows/IntegrationSwitch.test.tsx +36 -0
  305. package/src/react/workflows/IntegrationSwitch.tsx +63 -0
  306. package/src/react/workflows/Onboarding.test.tsx +75 -0
  307. package/src/react/workflows/Onboarding.tsx +171 -0
  308. package/src/react/workflows/Overview.test.tsx +57 -0
  309. package/src/react/workflows/Overview.tsx +123 -0
  310. package/src/react/workflows/PaymentMethods.test.tsx +60 -0
  311. package/src/react/workflows/PaymentMethods.tsx +117 -0
  312. package/src/react/workflows/PaymentReceipt.test.tsx +24 -0
  313. package/src/react/workflows/PaymentReceipt.tsx +46 -0
  314. package/src/react/workflows/Payouts.test.tsx +82 -0
  315. package/src/react/workflows/Payouts.tsx +212 -0
  316. package/src/react/workflows/Products.test.tsx +90 -0
  317. package/src/react/workflows/Products.tsx +377 -0
  318. package/src/react/workflows/ReferralLinks.test.tsx +39 -0
  319. package/src/react/workflows/ReferralLinks.tsx +75 -0
  320. package/src/react/workflows/Refunds.test.tsx +75 -0
  321. package/src/react/workflows/Refunds.tsx +223 -0
  322. package/src/react/workflows/Setup.test.tsx +25 -0
  323. package/src/react/workflows/Setup.tsx +166 -0
  324. package/src/react/workflows/Storefront.test.tsx +82 -0
  325. package/src/react/workflows/Storefront.tsx +138 -0
  326. package/src/react/workflows/SubscriptionOverview.test.tsx +27 -0
  327. package/src/react/workflows/SubscriptionOverview.tsx +48 -0
  328. package/src/react/workflows/Subscriptions.test.tsx +61 -0
  329. package/src/react/workflows/Subscriptions.tsx +282 -0
  330. package/src/react/workflows/Tasks.test.tsx +23 -0
  331. package/src/react/workflows/Tasks.tsx +199 -0
  332. package/src/react/workflows/checkout-options.ts +42 -0
  333. package/src/react/workflows/current-subscription.test.ts +29 -0
  334. package/src/react/workflows/current-subscription.ts +25 -0
  335. package/src/react/workflows/filters.test.ts +12 -0
  336. package/src/react/workflows/filters.ts +22 -0
  337. package/src/react/workflows/index.ts +238 -0
  338. package/src/react/workflows/native-interactions.test.tsx +73 -0
  339. package/src/react/workflows/public-workflows.test.tsx +216 -0
  340. package/src/react/workflows/useWorkflowAction.test.tsx +54 -0
  341. package/src/react/workflows/useWorkflowAction.ts +75 -0
  342. package/src/react/workflows/useWorkflowResource.test.tsx +41 -0
  343. package/src/react/workflows/useWorkflowResource.ts +78 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaymentReceipt.js","sourceRoot":"","sources":["../../../src/react/workflows/PaymentReceipt.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAmBtD,MAAM,UAAU,cAAc,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAuB;IACvE,MAAM,WAAW,GAAG,OAAO,EAAE,MAAM,KAAK,WAAW,CAAC;IACpD,MAAM,KAAK,GAAG;QACZ,OAAO;QACP,SAAS,EAAE,CAAC,OAAO;QACnB,WAAW;QACX,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,gBAAgB;QAC7D,OAAO,EAAE,CAAC,OAAO;YACf,CAAC,CAAC,0CAA0C;YAC5C,CAAC,CAAC,WAAW;gBACX,CAAC,CAAC,uCAAuC;gBACzC,CAAC,CAAC,0BAA0B,OAAO,CAAC,MAAM,EAAE;QAChD,WAAW,EAAE,OAAO;YAClB,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC;YAC/C,CAAC,CAAC,SAAS;KACd,CAAC;IACF,IAAI,QAAQ;QAAE,OAAO,4BAAG,QAAQ,CAAC,KAAK,CAAC,GAAI,CAAC;IAC5C,OAAO,CACL,yCAA4B,iBAAiB,aAC3C,uBAAK,KAAK,CAAC,KAAK,GAAM,EACtB,YAAG,IAAI,EAAC,QAAQ,YAAE,KAAK,CAAC,OAAO,GAAK,EACnC,KAAK,CAAC,WAAW,IAAI,sBAAI,KAAK,CAAC,WAAW,GAAK,IACxC,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type ReactNode } from "react";
2
+ import { type ConnectProps } from "./Connect.js";
3
+ import { type CollectionProps, type WorkflowColumn } from "./Collection.js";
4
+ export type PayoutRow = {
5
+ id: string;
6
+ amount: number;
7
+ currency: string;
8
+ status: string;
9
+ /** Unix milliseconds. */ arrivalDate: number | null;
10
+ created: number;
11
+ };
12
+ export type PayoutSnapshot = {
13
+ balances: {
14
+ currency: string;
15
+ available: number;
16
+ pending: number;
17
+ }[];
18
+ payouts: PayoutRow[];
19
+ upcoming: PayoutRow[];
20
+ nextCursor: string | null;
21
+ };
22
+ export type PayoutsRenderProps = {
23
+ data: PayoutSnapshot | undefined;
24
+ error: string | null;
25
+ isLoading: boolean;
26
+ isPending: boolean;
27
+ nextPayout: PayoutRow | undefined;
28
+ previousPayouts: PayoutRow[];
29
+ refresh: () => void;
30
+ loadMore: () => Promise<void>;
31
+ };
32
+ export type HeadlessPayoutsProps = {
33
+ presentation?: "headless";
34
+ scopeKey: string;
35
+ load: (cursor?: string) => Promise<PayoutSnapshot>;
36
+ children?: (state: PayoutsRenderProps) => ReactNode;
37
+ };
38
+ export type PayoutsProps = HeadlessPayoutsProps | (Omit<ConnectProps, "component"> & {
39
+ presentation: "embedded";
40
+ });
41
+ export declare function Payouts(props: PayoutsProps): import("react").JSX.Element;
42
+ export type PayoutHistoryRow = Pick<PayoutRow, "id" | "amount" | "currency" | "status" | "arrivalDate">;
43
+ export type PayoutHistoryProps<Row extends PayoutHistoryRow = PayoutHistoryRow> = Omit<CollectionProps<Row>, "columns" | "getKey"> & {
44
+ columns?: WorkflowColumn<Row>[];
45
+ };
46
+ export declare function PayoutHistory<Row extends PayoutHistoryRow>(props: PayoutHistoryProps<Row>): import("react").JSX.Element;
47
+ //# sourceMappingURL=Payouts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Payouts.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Payouts.tsx"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAG1D,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrE,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AACF,MAAM,MAAM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G,CAAC,+BAyB/B"}
@@ -0,0 +1,87 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { Connect } from "./Connect.js";
5
+ import { useWorkflowAction } from "./useWorkflowAction.js";
6
+ import { useWorkflowResource } from "./useWorkflowResource.js";
7
+ import { Collection, } from "./Collection.js";
8
+ import { formatPrice } from "../lib/price-helpers.js";
9
+ const upcoming = (row) => row.status === "pending" || row.status === "in_transit";
10
+ export function Payouts(props) {
11
+ return props.presentation === "embedded" ? (_jsx(Connect, { ...props, component: "payouts" })) : (_jsx(PayoutsBody, { ...props }, props.scopeKey));
12
+ }
13
+ function PayoutsBody({ load, scopeKey, children }) {
14
+ const resource = useWorkflowResource(() => load(), scopeKey);
15
+ const more = useWorkflowAction((cursor) => load(cursor), `${scopeKey}:${resource.revision}`);
16
+ const [pages, setPages] = useState({ base: undefined, rows: [], cursor: undefined });
17
+ if (pages.base !== resource.data)
18
+ setPages({ base: resource.data, rows: [], cursor: undefined });
19
+ const base = resource.data;
20
+ const nextCursor = pages.cursor === undefined ? (base?.nextCursor ?? null) : pages.cursor;
21
+ const data = base
22
+ ? {
23
+ ...base,
24
+ nextCursor,
25
+ payouts: [
26
+ ...new Map([...base.payouts, ...pages.rows].map((row) => [row.id, row])).values(),
27
+ ],
28
+ }
29
+ : undefined;
30
+ const loadMore = async () => {
31
+ if (!nextCursor || resource.isLoading)
32
+ return;
33
+ const next = await more.run(nextCursor);
34
+ if (next)
35
+ setPages((previous) => ({
36
+ ...previous,
37
+ rows: [...previous.rows, ...next.payouts],
38
+ cursor: next.nextCursor,
39
+ }));
40
+ };
41
+ const sortedUpcoming = data?.upcoming
42
+ .filter(upcoming)
43
+ .slice()
44
+ .sort((a, b) => (a.arrivalDate ?? Infinity) - (b.arrivalDate ?? Infinity)) ?? [];
45
+ const state = {
46
+ data,
47
+ isLoading: resource.isLoading,
48
+ isPending: resource.isLoading || more.isPending,
49
+ error: resource.error ?? more.error,
50
+ nextPayout: sortedUpcoming[0],
51
+ previousPayouts: data?.payouts.filter((row) => !upcoming(row)) ?? [],
52
+ refresh: resource.refresh,
53
+ loadMore,
54
+ };
55
+ return _jsx(_Fragment, { children: children ? children(state) : _jsx(NativePayouts, { ...state }) });
56
+ }
57
+ function date(value) {
58
+ return value === null
59
+ ? "Not supplied by Stripe"
60
+ : new Date(value).toLocaleDateString(undefined, { timeZone: "UTC" });
61
+ }
62
+ export function PayoutHistory(props) {
63
+ const columns = [
64
+ { id: "id", label: "Payout ID", cell: (row) => row.id },
65
+ {
66
+ id: "amount",
67
+ label: "Amount",
68
+ align: "end",
69
+ cell: (row) => formatPrice(row.amount, row.currency),
70
+ },
71
+ { id: "status", label: "Status", cell: (row) => row.status },
72
+ {
73
+ id: "arrival",
74
+ label: "Arrival date",
75
+ cell: (row) => date(row.arrivalDate),
76
+ },
77
+ ];
78
+ return (_jsx(Collection, { emptyLabel: "No payouts yet.", ...props, getKey: (row) => row.id, columns: props.columns ?? columns }));
79
+ }
80
+ function NativePayouts({ data, isLoading, isPending, error, nextPayout, previousPayouts, refresh, loadMore, }) {
81
+ return (_jsxs("section", { "data-better-stripe": "payouts", "aria-busy": isPending, children: [_jsx("h2", { children: "Payouts" }), _jsx("button", { type: "button", disabled: isPending, onClick: refresh, children: isPending ? "Refreshing…" : "Refresh" }), error && _jsx("p", { role: "alert", children: error }), isLoading && !data && _jsx("p", { role: "status", children: "Loading payouts\u2026" }), data && (_jsxs(_Fragment, { children: [_jsxs("dl", { children: [data.balances.map((balance) => (_jsxs("div", { children: [_jsx("dt", { children: "Available" }), _jsx("dd", { children: formatPrice(balance.available, balance.currency) }), _jsx("dt", { children: "Pending" }), _jsx("dd", { children: formatPrice(balance.pending, balance.currency) })] }, balance.currency))), _jsx("dt", { children: "Next payout" }), _jsx("dd", { children: nextPayout
82
+ ? `${formatPrice(nextPayout.amount, nextPayout.currency)} · ${date(nextPayout.arrivalDate)}`
83
+ : "Not scheduled" })] }), _jsx("h3", { children: "Upcoming payouts" }), _jsx(PayoutHistory, { rows: data.upcoming, emptyLabel: "No upcoming payouts scheduled." }), _jsx("h3", { children: "Previous payouts" }), _jsx(PayoutHistory, { rows: previousPayouts, emptyLabel: "No previous payouts yet." }), data.nextCursor && (_jsx("button", { type: "button", disabled: isPending, onClick: () => {
84
+ void loadMore();
85
+ }, children: isPending ? "Loading…" : "Load more payouts" }))] }))] }));
86
+ }
87
+ //# sourceMappingURL=Payouts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Payouts.js","sourceRoot":"","sources":["../../../src/react/workflows/Payouts.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACL,UAAU,GAGX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAkCtD,MAAM,QAAQ,GAAG,CAAC,GAAc,EAAE,EAAE,CAClC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,YAAY,CAAC;AAC1D,MAAM,UAAU,OAAO,CAAC,KAAmB;IACzC,OAAO,KAAK,CAAC,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,CACzC,KAAC,OAAO,OAAK,KAAK,EAAE,SAAS,EAAC,SAAS,GAAG,CAC3C,CAAC,CAAC,CAAC,CACF,KAAC,WAAW,OAA0B,KAAK,IAAzB,KAAK,CAAC,QAAQ,CAAe,CAChD,CAAC;AACJ,CAAC;AACD,SAAS,WAAW,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAwB;IACrE,MAAM,QAAQ,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CACJ,IACO,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,92 @@
1
+ import { type ReactNode } from "react";
2
+ import { type PriceCardPrice } from "../components/PriceCard.js";
3
+ export type ProductInput = {
4
+ name: string;
5
+ description?: string;
6
+ };
7
+ export type PriceInput = {
8
+ stripeProductId: string;
9
+ unitAmount: number;
10
+ currency: string;
11
+ type: "one_time" | "recurring";
12
+ interval?: "month" | "year" | "week" | "day";
13
+ };
14
+ export type ProductActions = {
15
+ scopeKey: string;
16
+ createProduct: (args: ProductInput) => Promise<unknown>;
17
+ createPrice: (args: PriceInput) => Promise<unknown>;
18
+ updateProduct?: (args: ProductInput & {
19
+ stripeProductId: string;
20
+ }) => Promise<unknown>;
21
+ deactivateProduct?: (args: {
22
+ stripeProductId: string;
23
+ }) => Promise<unknown>;
24
+ deactivatePrice?: (args: {
25
+ stripePriceId: string;
26
+ }) => Promise<unknown>;
27
+ };
28
+ export type ProductEdit = {
29
+ stripeProductId: string;
30
+ name: string;
31
+ description: string;
32
+ };
33
+ export declare function useProductManager(props: ProductActions): {
34
+ scope: string;
35
+ expandedProduct: string | null;
36
+ showCreateDialog: boolean;
37
+ showAddPriceFor: string | null;
38
+ newProduct: {
39
+ name: string;
40
+ description: string;
41
+ };
42
+ newPrice: {
43
+ amount: string;
44
+ currency: string;
45
+ interval: string;
46
+ };
47
+ editingProduct: ProductEdit | null;
48
+ error: string | null;
49
+ clearError: () => void;
50
+ isPending: boolean;
51
+ isCreatingProduct: boolean;
52
+ isCreatingPrice: boolean;
53
+ isSavingEdit: boolean;
54
+ deactivatingId: string | null | undefined;
55
+ deactivatingPriceId: string | null | undefined;
56
+ setExpandedProduct: (value: string | null) => void;
57
+ setShowCreateDialog: (value: boolean) => void;
58
+ setShowAddPriceFor: (value: string | null) => void;
59
+ setNewProduct: (value: {
60
+ name: string;
61
+ description: string;
62
+ }) => void;
63
+ setNewPrice: (value: {
64
+ amount: string;
65
+ currency: string;
66
+ interval: string;
67
+ }) => void;
68
+ setEditingProduct: (value: ProductEdit | null) => void;
69
+ handleCreateProduct: () => Promise<void>;
70
+ handleAddPrice: (id: string) => Promise<void>;
71
+ handleSaveEdit: () => Promise<void>;
72
+ handleDeactivate: (id: string) => Promise<boolean | undefined>;
73
+ handleDeactivatePrice: (id: string) => Promise<boolean | undefined>;
74
+ };
75
+ export type CatalogProduct = {
76
+ stripeProductId: string;
77
+ name: string;
78
+ description?: string;
79
+ active: boolean;
80
+ prices: PriceCardPrice[];
81
+ };
82
+ export type ProductsRenderProps = ReturnType<typeof useProductManager> & {
83
+ products: CatalogProduct[];
84
+ isLoading: boolean;
85
+ };
86
+ export type ProductsProps = ProductActions & {
87
+ products: CatalogProduct[] | undefined;
88
+ children?: (state: ProductsRenderProps) => ReactNode;
89
+ };
90
+ /** Complete catalog creation/editing/archiving controller, with optional custom rendering. Amount inputs use minor units. */
91
+ export declare function Products(props: ProductsProps): import("react").JSX.Element;
92
+ //# sourceMappingURL=Products.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Products.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Products.tsx"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5E,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAC/B,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;CAC9C,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,MAAM,CAA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BAAmB,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,GAAG;IACvE,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG;IAC3C,QAAQ,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,SAAS,CAAC;CACtD,CAAC;AACF,6HAA6H;AAC7H,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,+BAE5C"}
@@ -0,0 +1,179 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId, useState } from "react";
4
+ import { useWorkflowAction } from "./useWorkflowAction.js";
5
+ import { PriceCard } from "../components/PriceCard.js";
6
+ export function useProductManager(props) {
7
+ const initial = {
8
+ scope: props.scopeKey,
9
+ expandedProduct: null,
10
+ showCreateDialog: false,
11
+ showAddPriceFor: null,
12
+ newProduct: { name: "", description: "" },
13
+ newPrice: { amount: "", currency: "usd", interval: "month" },
14
+ editingProduct: null,
15
+ };
16
+ const [fields, setFields] = useState(initial);
17
+ if (fields.scope !== props.scopeKey)
18
+ setFields(initial);
19
+ const [command, setCommand] = useState(null);
20
+ const action = useWorkflowAction(async (command) => {
21
+ setCommand(command);
22
+ switch (command.type) {
23
+ case "create": {
24
+ if (!fields.newProduct.name.trim())
25
+ throw new Error("Enter a product name.");
26
+ await props.createProduct({
27
+ name: fields.newProduct.name.trim(),
28
+ description: fields.newProduct.description.trim() || undefined,
29
+ });
30
+ break;
31
+ }
32
+ case "price": {
33
+ const unitAmount = Number(fields.newPrice.amount);
34
+ if (!/^\d+$/.test(fields.newPrice.amount) ||
35
+ !Number.isSafeInteger(unitAmount) ||
36
+ unitAmount <= 0)
37
+ throw new Error("Enter a positive integer price in minor units.");
38
+ if (!/^[a-zA-Z]{3}$/.test(fields.newPrice.currency))
39
+ throw new Error("Enter a three-letter currency code.");
40
+ const interval = fields.newPrice.interval;
41
+ if (!["one_time", "month", "year", "week", "day"].includes(interval))
42
+ throw new Error("Choose a supported price interval.");
43
+ await props.createPrice({
44
+ stripeProductId: command.id,
45
+ unitAmount,
46
+ currency: fields.newPrice.currency.toLowerCase(),
47
+ type: interval === "one_time" ? "one_time" : "recurring",
48
+ interval: interval === "one_time"
49
+ ? undefined
50
+ : interval,
51
+ });
52
+ break;
53
+ }
54
+ case "edit": {
55
+ if (!props.updateProduct || !fields.editingProduct)
56
+ throw new Error("Product editing is not configured.");
57
+ if (!fields.editingProduct.name.trim())
58
+ throw new Error("Enter a product name.");
59
+ await props.updateProduct({
60
+ stripeProductId: fields.editingProduct.stripeProductId,
61
+ name: fields.editingProduct.name.trim(),
62
+ description: fields.editingProduct.description.trim() || undefined,
63
+ });
64
+ break;
65
+ }
66
+ case "archiveProduct":
67
+ if (!props.deactivateProduct)
68
+ throw new Error("Product archiving is not configured.");
69
+ else
70
+ await props.deactivateProduct({ stripeProductId: command.id });
71
+ break;
72
+ case "archivePrice":
73
+ if (!props.deactivatePrice)
74
+ throw new Error("Price archiving is not configured.");
75
+ else
76
+ await props.deactivatePrice({ stripePriceId: command.id });
77
+ break;
78
+ }
79
+ return true;
80
+ }, props.scopeKey);
81
+ const run = action.run;
82
+ const set = (key, value) => setFields((previous) => ({ ...previous, [key]: value }));
83
+ return {
84
+ ...fields,
85
+ error: action.error,
86
+ clearError: action.reset,
87
+ isPending: action.isPending,
88
+ isCreatingProduct: action.isPending && command?.type === "create",
89
+ isCreatingPrice: action.isPending && command?.type === "price",
90
+ isSavingEdit: action.isPending && command?.type === "edit",
91
+ deactivatingId: action.isPending && command?.type === "archiveProduct"
92
+ ? command.id
93
+ : null,
94
+ deactivatingPriceId: action.isPending && command?.type === "archivePrice" ? command.id : null,
95
+ setExpandedProduct: (value) => set("expandedProduct", value),
96
+ setShowCreateDialog: (value) => set("showCreateDialog", value),
97
+ setShowAddPriceFor: (value) => set("showAddPriceFor", value),
98
+ setNewProduct: (value) => set("newProduct", value),
99
+ setNewPrice: (value) => set("newPrice", value),
100
+ setEditingProduct: (value) => set("editingProduct", value),
101
+ handleCreateProduct: async () => {
102
+ if (await run({ type: "create" }))
103
+ setFields((previous) => ({
104
+ ...previous,
105
+ newProduct: initial.newProduct,
106
+ showCreateDialog: false,
107
+ }));
108
+ },
109
+ handleAddPrice: async (id) => {
110
+ if (await run({ type: "price", id }))
111
+ setFields((previous) => ({
112
+ ...previous,
113
+ newPrice: initial.newPrice,
114
+ showAddPriceFor: null,
115
+ }));
116
+ },
117
+ handleSaveEdit: async () => {
118
+ if (await run({ type: "edit" }))
119
+ set("editingProduct", null);
120
+ },
121
+ handleDeactivate: (id) => run({ type: "archiveProduct", id }),
122
+ handleDeactivatePrice: (id) => run({ type: "archivePrice", id }),
123
+ };
124
+ }
125
+ /** Complete catalog creation/editing/archiving controller, with optional custom rendering. Amount inputs use minor units. */
126
+ export function Products(props) {
127
+ return _jsx(ProductsBody, { ...props }, props.scopeKey);
128
+ }
129
+ function ProductsBody(props) {
130
+ const state = useProductManager(props);
131
+ const id = useId();
132
+ const result = {
133
+ ...state,
134
+ products: props.products ?? [],
135
+ isLoading: props.products === undefined,
136
+ };
137
+ if (props.children)
138
+ return _jsx(_Fragment, { children: props.children(result) });
139
+ return (_jsxs("section", { "data-better-stripe": "products", "aria-busy": state.isPending, children: [_jsx("h2", { children: "Products" }), state.error && _jsx("p", { role: "alert", children: state.error }), _jsxs("form", { onSubmit: (event) => {
140
+ event.preventDefault();
141
+ void state.handleCreateProduct();
142
+ }, children: [_jsx("label", { htmlFor: `${id}-name`, children: "Product name" }), _jsx("input", { id: `${id}-name`, required: true, value: state.newProduct.name, onChange: (event) => state.setNewProduct({
143
+ ...state.newProduct,
144
+ name: event.target.value,
145
+ }) }), _jsx("label", { htmlFor: `${id}-description`, children: "Description" }), _jsx("input", { id: `${id}-description`, value: state.newProduct.description, onChange: (event) => state.setNewProduct({
146
+ ...state.newProduct,
147
+ description: event.target.value,
148
+ }) }), _jsx("button", { type: "submit", disabled: state.isPending, children: state.isCreatingProduct ? "Creating…" : "Create product" })] }), result.isLoading ? (_jsx("p", { role: "status", children: "Loading products\u2026" })) : !result.products.length ? (_jsx("p", { children: "No products yet." })) : (result.products.map((product) => (_jsxs("article", { children: [_jsx("h3", { children: product.name }), _jsx("p", { children: product.description }), product.prices.map((price) => (_jsxs("div", { children: [_jsx(PriceCard, { price: price, children: ({ formattedPrice }) => _jsx("p", { children: formattedPrice }) }), props.deactivatePrice && price.active && (_jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
149
+ void state.handleDeactivatePrice(price.stripePriceId);
150
+ }, children: "Archive price" }))] }, price.stripePriceId))), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => state.setShowAddPriceFor(product.stripeProductId), children: "Add price" }), props.updateProduct && (_jsx("button", { type: "button", onClick: () => state.setEditingProduct({
151
+ stripeProductId: product.stripeProductId,
152
+ name: product.name,
153
+ description: product.description ?? "",
154
+ }), children: "Edit product" })), props.deactivateProduct && (_jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
155
+ void state.handleDeactivate(product.stripeProductId);
156
+ }, children: "Archive product" }))] }, product.stripeProductId)))), state.showAddPriceFor && (_jsxs("form", { onSubmit: (event) => {
157
+ event.preventDefault();
158
+ void state.handleAddPrice(state.showAddPriceFor);
159
+ }, children: [_jsx("label", { htmlFor: `${id}-amount`, children: "Price in minor units" }), _jsx("input", { id: `${id}-amount`, type: "number", required: true, min: "1", step: "1", value: state.newPrice.amount, onChange: (event) => state.setNewPrice({
160
+ ...state.newPrice,
161
+ amount: event.target.value,
162
+ }) }), _jsx("label", { htmlFor: `${id}-currency`, children: "Currency" }), _jsx("input", { id: `${id}-currency`, required: true, minLength: 3, maxLength: 3, value: state.newPrice.currency, onChange: (event) => state.setNewPrice({
163
+ ...state.newPrice,
164
+ currency: event.target.value,
165
+ }) }), _jsx("label", { htmlFor: `${id}-interval`, children: "Interval" }), _jsx("select", { id: `${id}-interval`, value: state.newPrice.interval, onChange: (event) => state.setNewPrice({
166
+ ...state.newPrice,
167
+ interval: event.target.value,
168
+ }), children: ["one_time", "month", "year", "week", "day"].map((value) => (_jsx("option", { children: value }, value))) }), _jsx("button", { type: "submit", disabled: state.isPending, children: state.isCreatingPrice ? "Creating…" : "Create price" })] })), state.editingProduct && (_jsxs("form", { onSubmit: (event) => {
169
+ event.preventDefault();
170
+ void state.handleSaveEdit();
171
+ }, children: [_jsx("label", { htmlFor: `${id}-edit-name`, children: "Product name" }), _jsx("input", { id: `${id}-edit-name`, required: true, value: state.editingProduct.name, onChange: (event) => state.setEditingProduct({
172
+ ...state.editingProduct,
173
+ name: event.target.value,
174
+ }) }), _jsx("label", { htmlFor: `${id}-edit-description`, children: "Description" }), _jsx("input", { id: `${id}-edit-description`, value: state.editingProduct.description, onChange: (event) => state.setEditingProduct({
175
+ ...state.editingProduct,
176
+ description: event.target.value,
177
+ }) }), _jsx("button", { type: "submit", disabled: state.isPending, children: state.isSavingEdit ? "Saving…" : "Save product" })] }))] }));
178
+ }
179
+ //# sourceMappingURL=Products.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Products.js","sourceRoot":"","sources":["../../../src/react/workflows/Products.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAuB,MAAM,4BAA4B,CAAC;AAwB5E,MAAM,UAAU,iBAAiB,CAAC,KAAqB;IACrD,MAAM,OAAO,GAAG;QACd,KAAK,EAAE,KAAK,CAAC,QAAQ;QACrB,eAAe,EAAE,IAAqB;QACtC,gBAAgB,EAAE,KAAK;QACvB,eAAe,EAAE,IAAqB;QACtC,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE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CAAC,KAAK;yBAChC,CAAC,GAEJ,EACF,iBAAQ,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,YAC5C,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,GACzC,IACJ,CACR,IACO,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { ReactNode } from "react";
2
+ export type ReferralLink = {
3
+ id: string;
4
+ label: string;
5
+ url: string;
6
+ };
7
+ export declare function useReferralLinks({ scopeKey, writeText, }?: {
8
+ scopeKey?: string;
9
+ writeText?: (text: string) => Promise<void>;
10
+ }): {
11
+ copy: (url: string) => Promise<string | undefined>;
12
+ copiedUrl: string | undefined;
13
+ error: string | null;
14
+ isPending: boolean;
15
+ };
16
+ export type ReferralLinksProps = {
17
+ links: ReferralLink[] | undefined;
18
+ scopeKey?: string;
19
+ writeText?: (text: string) => Promise<void>;
20
+ children?: (state: ReturnType<typeof useReferralLinks> & {
21
+ links: ReferralLink[];
22
+ isLoading: boolean;
23
+ }) => ReactNode;
24
+ };
25
+ export declare function ReferralLinks(props: ReferralLinksProps): import("react").JSX.Element;
26
+ //# sourceMappingURL=ReferralLinks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralLinks.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/ReferralLinks.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,YAAY,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AACtE,wBAAgB,gBAAgB,CAAC,EAC/B,QAA2B,EAC3B,SAAiE,GAClE,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAO;IAOtE,IAAI;IACJ,SAAS;IACT,KAAK;IACL,SAAS;EAEZ;AACD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GAAG;QAC3C,KAAK,EAAE,YAAY,EAAE,CAAC;QACtB,SAAS,EAAE,OAAO,CAAC;KACpB,KACE,SAAS,CAAC;CAChB,CAAC;AACF,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BA2CtD"}
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useWorkflowAction } from "./useWorkflowAction.js";
4
+ export function useReferralLinks({ scopeKey = "referral-links", writeText = (text) => navigator.clipboard.writeText(text), } = {}) {
5
+ const action = useWorkflowAction(async (url) => {
6
+ if (!url.trim())
7
+ throw new Error("A referral URL is required.");
8
+ await writeText(url);
9
+ return url;
10
+ }, scopeKey);
11
+ return {
12
+ copy: action.run,
13
+ copiedUrl: action.result,
14
+ error: action.error,
15
+ isPending: action.isPending,
16
+ };
17
+ }
18
+ export function ReferralLinks(props) {
19
+ const state = useReferralLinks(props);
20
+ if (props.children)
21
+ return (_jsx(_Fragment, { children: props.children({
22
+ ...state,
23
+ links: props.links ?? [],
24
+ isLoading: props.links === undefined,
25
+ }) }));
26
+ return (_jsxs("section", { "data-better-stripe": "referral-links", children: [_jsx("h2", { children: "Referral links" }), state.error && _jsx("p", { role: "alert", children: state.error }), state.copiedUrl && _jsx("p", { role: "status", children: "Referral link copied" }), props.links === undefined ? (_jsx("p", { role: "status", children: "Loading referral links\u2026" })) : !props.links.length ? (_jsx("p", { children: "No referral links yet." })) : (_jsx("ul", { children: props.links.map((link) => (_jsxs("li", { children: [_jsx("a", { href: link.url, children: link.label }), _jsx("p", { children: link.url }), _jsx("button", { type: "button", disabled: state.isPending, "aria-label": `Copy referral link for ${link.label}`, onClick: () => {
27
+ void state.copy(link.url);
28
+ }, children: state.isPending ? "Copying…" : "Copy link" })] }, link.id))) }))] }));
29
+ }
30
+ //# sourceMappingURL=ReferralLinks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReferralLinks.js","sourceRoot":"","sources":["../../../src/react/workflows/ReferralLinks.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,UAAU,gBAAgB,CAAC,EAC/B,QAAQ,GAAG,gBAAgB,EAC3B,SAAS,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,GAClE,GAAuE,EAAE;IACxE,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,GAAW,EAAE,EAAE;QACrD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAChE,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,QAAQ,CAAC,CAAC;IACb,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,GAAG;QAChB,SAAS,EAAE,MAAM,CAAC,MAAM;QACxB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC;AACJ,CAAC;AAYD,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,QAAQ;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from "./Connect.js";
3
+ export type RefundRequest = {
4
+ stripePaymentIntentId: string;
5
+ amountCents?: number;
6
+ reason: "requested_by_customer";
7
+ };
8
+ export type ReversalRequest = {
9
+ sourceChargeId: string;
10
+ amountCents?: number;
11
+ };
12
+ export type RefundResult = {
13
+ stripeRefundId: string;
14
+ };
15
+ export type ReversalResult = {
16
+ reversals: {
17
+ stripeTransferId: string;
18
+ amount: number;
19
+ }[];
20
+ summary: {
21
+ reversalCount: number;
22
+ totalReversed: number;
23
+ };
24
+ };
25
+ export type RefundActionsProps = {
26
+ scopeKey: string;
27
+ paymentIntentId?: string;
28
+ sourceChargeId?: string;
29
+ issueRefund: (args: RefundRequest) => Promise<RefundResult>;
30
+ reverseTransfers?: (args: ReversalRequest) => Promise<ReversalResult>;
31
+ };
32
+ /** Currency input expressed in two decimal minor units. Rejects rounding and scientific notation. */
33
+ export declare function parseAmountCents(value: string): number | null;
34
+ export declare function useRefunds(props: RefundActionsProps): {
35
+ scope: string;
36
+ paymentIntentId: string;
37
+ sourceChargeId: string;
38
+ refundAmount: string;
39
+ reversalAmount: string;
40
+ setPaymentIntentId: (value: string) => void;
41
+ setSourceChargeId: (value: string) => void;
42
+ setRefundAmount: (value: string) => void;
43
+ setReversalAmount: (value: string) => void;
44
+ error: string | null;
45
+ isPending: boolean;
46
+ busy: "refund" | "reversal" | null;
47
+ refundResult: RefundResult | null;
48
+ reversalResult: ReversalResult | null;
49
+ submitRefund: (kind: "full" | "partial") => Promise<{
50
+ type: "refund";
51
+ value: RefundResult;
52
+ } | {
53
+ type: "reversal";
54
+ value: ReversalResult;
55
+ } | undefined>;
56
+ submitReversal: (kind: "full" | "partial") => Promise<{
57
+ type: "refund";
58
+ value: RefundResult;
59
+ } | {
60
+ type: "reversal";
61
+ value: ReversalResult;
62
+ } | undefined>;
63
+ };
64
+ export type RefundsRenderProps = ReturnType<typeof useRefunds>;
65
+ export type RefundsProps = (RefundActionsProps & {
66
+ presentation?: "headless";
67
+ children?: (state: RefundsRenderProps) => ReactNode;
68
+ }) | (Omit<ConnectProps, "component"> & {
69
+ presentation: "embedded";
70
+ });
71
+ export declare function Refunds(props: RefundsProps): import("react").JSX.Element;
72
+ //# sourceMappingURL=Refunds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Refunds.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Refunds.tsx"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAExD,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,uBAAuB,CAAC;CACjC,CAAC;AACF,MAAM,MAAM,eAAe,GAAG;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC/E,MAAM,MAAM,YAAY,GAAG;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1D,OAAO,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3D,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5D,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;CACvE,CAAC;A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