@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,45 @@
1
+ import type { ReactNode } from "react";
2
+ import type { CheckoutSessionResult } from "./Checkout.js";
3
+ export type PlanBillingOptions<PlanId extends string = string> = {
4
+ scopeKey: string;
5
+ sessionId?: string | null;
6
+ confirm?: (sessionId: string) => Promise<unknown>;
7
+ createCheckout: (planId: PlanId) => Promise<CheckoutSessionResult>;
8
+ createPortal: () => Promise<string | {
9
+ url: string;
10
+ }>;
11
+ onNavigate?: (url: string) => void;
12
+ };
13
+ export declare function usePlanBilling<PlanId extends string = string>(props: PlanBillingOptions<PlanId>): {
14
+ clientSecret: string | undefined;
15
+ isPending: boolean;
16
+ error: string | null;
17
+ choose: (planId: PlanId) => Promise<{
18
+ type: "checkout";
19
+ clientSecret: string;
20
+ url?: undefined;
21
+ } | {
22
+ clientSecret?: undefined;
23
+ type: "portal";
24
+ url: string;
25
+ } | undefined>;
26
+ openPortal: () => Promise<void>;
27
+ };
28
+ export type BillingPlan<PlanId extends string = string> = {
29
+ id: PlanId;
30
+ name: string;
31
+ monthlyAmount: number;
32
+ currency: string;
33
+ description?: string;
34
+ feeDescription?: string;
35
+ };
36
+ export type BillingPlansProps<PlanId extends string = string> = PlanBillingOptions<PlanId> & {
37
+ plans: BillingPlan<PlanId>[];
38
+ publishableKey: string;
39
+ currentPlanId?: PlanId;
40
+ children?: (state: ReturnType<typeof usePlanBilling<PlanId>> & {
41
+ plans: BillingPlan<PlanId>[];
42
+ }) => ReactNode;
43
+ };
44
+ export declare function BillingPlans<PlanId extends string = string>(props: BillingPlansProps<PlanId>): import("react").JSX.Element;
45
+ //# sourceMappingURL=BillingPlans.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BillingPlans.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/BillingPlans.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3D,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACnE,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtD,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,CAAC;AACF,wBAAgB,cAAc,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC3D,KAAK,EAAE,kBAAkB,CAAC,MAAM,CAAC;IA8B/B,YAAY;IAIZ,SAAS;IACT,KAAK;IACL,MAAM,WAAW,MAAM;cAlBX,UAAU;;;;;cAOL,QAAQ;;;IAYzB,UAAU;EAQb;AACD,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,MAAM,MAAM,iBAAiB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAC1D,kBAAkB,CAAC,MAAM,CAAC,GAAG;IAC3B,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG;QACjD,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;KAC9B,KACE,SAAS,CAAC;CAChB,CAAC;AACJ,wBAAgB,YAAY,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EACzD,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,+BA+CjC"}
@@ -0,0 +1,51 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { EmbeddedCheckout } from "../components/EmbeddedCheckout.js";
4
+ import { formatPrice } from "../lib/price-helpers.js";
5
+ import { useWorkflowAction } from "./useWorkflowAction.js";
6
+ import { useWorkflowResource } from "./useWorkflowResource.js";
7
+ export function usePlanBilling(props) {
8
+ const confirmation = useWorkflowResource(() => props.sessionId && props.confirm
9
+ ? props.confirm(props.sessionId)
10
+ : Promise.resolve(null), `${props.scopeKey}:${props.sessionId ?? ""}`);
11
+ const action = useWorkflowAction(async (operation) => {
12
+ if (operation.type === "checkout") {
13
+ const session = await props.createCheckout(operation.planId);
14
+ if (!session.clientSecret)
15
+ throw new Error("Stripe did not return a checkout form.");
16
+ return {
17
+ type: "checkout",
18
+ clientSecret: session.clientSecret,
19
+ };
20
+ }
21
+ const result = await props.createPortal();
22
+ const url = typeof result === "string" ? result : result.url;
23
+ if (!url)
24
+ throw new Error("Stripe did not return a billing portal URL.");
25
+ return { type: "portal", url };
26
+ }, props.scopeKey);
27
+ return {
28
+ clientSecret: action.result?.type === "checkout"
29
+ ? action.result.clientSecret
30
+ : undefined,
31
+ isPending: action.isPending,
32
+ error: action.error ?? confirmation.error,
33
+ choose: (planId) => action.run({ type: "checkout", planId }),
34
+ openPortal: async () => {
35
+ const result = await action.run({ type: "portal" });
36
+ if (result?.type === "portal")
37
+ (props.onNavigate ?? ((url) => window.location.assign(url)))(result.url);
38
+ },
39
+ };
40
+ }
41
+ export function BillingPlans(props) {
42
+ const state = usePlanBilling(props);
43
+ if (props.children)
44
+ return _jsx(_Fragment, { children: props.children({ ...state, plans: props.plans }) });
45
+ return (_jsxs("section", { "data-better-stripe": "billing-plans", "aria-busy": state.isPending, children: [_jsx("h2", { children: "Billing" }), state.error && _jsx("p", { role: "alert", children: state.error }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
46
+ void state.openPortal();
47
+ }, children: state.isPending ? "Loading…" : "Manage billing" }), props.plans.length ? (props.plans.map((plan) => (_jsxs("article", { children: [_jsx("h3", { children: plan.name }), _jsxs("p", { children: [formatPrice(plan.monthlyAmount, plan.currency), "/month"] }), plan.description && _jsx("p", { children: plan.description }), plan.feeDescription && _jsx("p", { children: plan.feeDescription }), _jsx("button", { type: "button", disabled: state.isPending || plan.id === props.currentPlanId, onClick: () => {
48
+ void state.choose(plan.id);
49
+ }, children: plan.id === props.currentPlanId ? "Current plan" : "Choose plan" })] }, plan.id)))) : (_jsx("p", { children: "No billing plans configured." })), state.clientSecret && (_jsx(EmbeddedCheckout, { publishableKey: props.publishableKey, clientSecret: state.clientSecret }))] }));
50
+ }
51
+ //# sourceMappingURL=BillingPlans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BillingPlans.js","sourceRoot":"","sources":["../../../src/react/workflows/BillingPlans.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAU/D,MAAM,UAAU,cAAc,CAC5B,KAAiC;IAEjC,MAAM,YAAY,GAAG,mBAAmB,CACtC,GAAG,EAAE,CACH,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,OAAO;QAC9B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC;QAChC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAC3B,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,SAAS,IAAI,EAAE,EAAE,CAC7C,CAAC;IACF,MAAM,MAAM,GAAG,iBAAiB,CAC9B,KAAK,EACH,SAAoE,EACpE,EAAE;QACF,IAAI,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC7D,IAAI,CAAC,OAAO,CAAC,YAAY;gBACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC5D,OAAO;gBACL,IAAI,EAAE,UAAmB;gBACzB,YAAY,EAAE,OAAO,CAAC,YAA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,GAC1D,KAbG,IAAI,CAAC,EAAE,CAcX,CACX,CAAC,CACH,CAAC,CAAC,CAAC,CACF,uDAAmC,CACpC,EACA,KAAK,CAAC,YAAY,IAAI,CACrB,KAAC,gBAAgB,IACf,cAAc,EAAE,KAAK,CAAC,cAAc,EACpC,YAAY,EAAE,KAAK,CAAC,YAAY,GAChC,CACH,IACO,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { ReactNode } from "react";
2
+ import { type CheckoutFormOptions } from "./CheckoutForms.js";
3
+ export type CheckoutMode = "redirect" | "embedded" | "custom" | "form" | "payment-intent";
4
+ export type CheckoutSessionResult = {
5
+ stripeSessionId: string;
6
+ clientSecret?: string;
7
+ url?: string;
8
+ };
9
+ export type CheckoutIntentResult = {
10
+ paymentIntentId: string;
11
+ clientSecret: string;
12
+ };
13
+ export type CheckoutRequest = {
14
+ mode: Exclude<CheckoutMode, "payment-intent">;
15
+ requestId: string;
16
+ };
17
+ export type CheckoutRenderProps = {
18
+ content: ReactNode;
19
+ isLoading: boolean;
20
+ error: string | null;
21
+ retry: () => void;
22
+ mode: CheckoutMode;
23
+ hostedUrl?: string;
24
+ continueToCheckout?: () => void;
25
+ };
26
+ type Common = CheckoutFormOptions & {
27
+ publishableKey: string;
28
+ /** Changes when the price, signed-in customer, or referral attribution changes. */
29
+ orderKey: string;
30
+ returnUrl: string;
31
+ onNavigate?: (url: string) => void;
32
+ children?: (state: CheckoutRenderProps) => ReactNode;
33
+ };
34
+ export type CheckoutProps = Common & ({
35
+ mode: Exclude<CheckoutMode, "payment-intent">;
36
+ createSession: (request: CheckoutRequest) => Promise<CheckoutSessionResult>;
37
+ } | {
38
+ mode: "payment-intent";
39
+ createPaymentIntent: (request: {
40
+ requestId: string;
41
+ }) => Promise<CheckoutIntentResult>;
42
+ });
43
+ /** All checkout integrations share one unstyled lifecycle. Callbacks must authenticate and validate prices on the server. */
44
+ export declare function Checkout(props: CheckoutProps): import("react").JSX.Element;
45
+ export {};
46
+ //# sourceMappingURL=Checkout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Checkout.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Checkout.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAC5B,MAAM,MAAM,YAAY,GACtB,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,GAAG,gBAAgB,CAAC;AACjE,MAAM,MAAM,qBAAqB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AACF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAC9C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,SAAS,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;CACjC,CAAC;AACF,KAAK,MAAM,GAAG,mBAAmB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,mFAAmF;IACnF,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,SAAS,CAAC;CACtD,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,MAAM,GAChC,CACI;IACE,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAC9C,aAAa,EAAE,CACb,OAAO,EAAE,eAAe,KACrB,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACrC,GACD;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,mBAAmB,EAAE,CAAC,OAAO,EAAE;QAC7B,SAAS,EAAE,MAAM,CAAC;KACnB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACrC,CACJ,CAAC;AACJ,6HAA6H;AAC7H,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,+BAE5C"}
@@ -0,0 +1,61 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { EmbeddedCheckout } from "../components/EmbeddedCheckout.js";
4
+ import { useWorkflowResource } from "./useWorkflowResource.js";
5
+ import { CheckoutElementsForm, PaymentIntentForm, CheckoutForm, } from "./CheckoutForms.js";
6
+ /** All checkout integrations share one unstyled lifecycle. Callbacks must authenticate and validate prices on the server. */
7
+ export function Checkout(props) {
8
+ return _jsx(CheckoutBody, { ...props }, `${props.orderKey}:${props.mode}`);
9
+ }
10
+ function CheckoutBody(props) {
11
+ const state = useWorkflowResource(async () => {
12
+ const requestId = crypto.randomUUID();
13
+ const result = props.mode === "payment-intent"
14
+ ? await props.createPaymentIntent({ requestId })
15
+ : await props.createSession({ mode: props.mode, requestId });
16
+ if (props.mode === "redirect") {
17
+ if (!("url" in result) || !result.url)
18
+ throw new Error("Stripe did not return a checkout URL.");
19
+ }
20
+ else if (!result.clientSecret)
21
+ throw new Error("Stripe did not return a checkout client secret.");
22
+ return result;
23
+ });
24
+ const navigate = props.onNavigate ?? ((url) => window.location.assign(url));
25
+ let content;
26
+ if (state.error)
27
+ content = (_jsxs("div", { role: "alert", children: [_jsx("p", { children: state.error }), _jsx("button", { type: "button", onClick: state.refresh, children: "Retry" })] }));
28
+ else if (!state.data || state.isLoading)
29
+ content = _jsx("p", { role: "status", children: "Creating checkout\u2026" });
30
+ else if (props.mode === "redirect" && "url" in state.data) {
31
+ const url = state.data.url;
32
+ content = (_jsx("button", { type: "button", onClick: () => navigate(url), children: "Continue to Stripe Checkout" }));
33
+ }
34
+ else {
35
+ const form = {
36
+ publishableKey: props.publishableKey,
37
+ clientSecret: state.data.clientSecret,
38
+ returnUrl: props.returnUrl,
39
+ email: props.email,
40
+ appearance: props.appearance,
41
+ renderForm: props.renderForm,
42
+ onNavigate: navigate,
43
+ };
44
+ content =
45
+ props.mode === "embedded" ? (_jsx(EmbeddedCheckout, { publishableKey: form.publishableKey, clientSecret: form.clientSecret })) : props.mode === "custom" ? (_jsx(CheckoutElementsForm, { ...form })) : props.mode === "form" ? (_jsx(CheckoutForm, { ...form })) : (_jsx(PaymentIntentForm, { ...form }));
46
+ }
47
+ const hostedUrl = props.mode === "redirect" && state.data && "url" in state.data
48
+ ? state.data.url
49
+ : undefined;
50
+ const result = {
51
+ content,
52
+ isLoading: state.isLoading,
53
+ error: state.error,
54
+ retry: state.refresh,
55
+ mode: props.mode,
56
+ hostedUrl,
57
+ continueToCheckout: hostedUrl ? () => navigate(hostedUrl) : undefined,
58
+ };
59
+ return _jsx(_Fragment, { children: props.children ? props.children(result) : content });
60
+ }
61
+ //# sourceMappingURL=Checkout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Checkout.js","sourceRoot":"","sources":["../../../src/react/workflows/Checkout.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,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I,GAAI,CAChC,CAAC;IACN,CAAC;IACD,MAAM,SAAS,GACb,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI;QAC5D,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG;QAChB,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,MAAM,GAAwB;QAClC,OAAO;QACP,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAAK,EAAE,KAAK,CAAC,OAAO;QACpB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,SAAS;QACT,kBAAkB,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;KACtE,CAAC;IACF,OAAO,4BAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,GAAI,CAAC;AAClE,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type ReactNode } from "react";
2
+ import { CHECKOUT_OPTIONS } from "./checkout-options.js";
3
+ import type { CheckoutMode } from "./Checkout.js";
4
+ export type CheckoutOption = (typeof CHECKOUT_OPTIONS)[number];
5
+ export type CheckoutChooserState = {
6
+ options: typeof CHECKOUT_OPTIONS;
7
+ selected: CheckoutOption;
8
+ unsupported: boolean;
9
+ select: (mode: CheckoutMode) => void;
10
+ };
11
+ export type CheckoutChooserProps = {
12
+ value?: CheckoutMode;
13
+ defaultValue?: CheckoutMode;
14
+ onValueChange?: (mode: CheckoutMode) => void;
15
+ recurring?: boolean;
16
+ children?: (state: CheckoutChooserState) => ReactNode;
17
+ };
18
+ /** Checkout tradeoffs and mode selection, independent of routing and session creation. */
19
+ export declare function CheckoutChooser({ value, defaultValue, onValueChange, recurring, children, }: CheckoutChooserProps): import("react").JSX.Element;
20
+ //# sourceMappingURL=CheckoutChooser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckoutChooser.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/CheckoutChooser.tsx"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,gBAAgB,CAAC;IACjC,QAAQ,EAAE,cAAc,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;CACtC,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,SAAS,CAAC;CACvD,CAAC;AACF,0FAA0F;AAC1F,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,YAAyB,EACzB,aAAa,EACb,SAAiB,EACjB,QAAQ,GACT,EAAE,oBAAoB,+BAmDtB"}
@@ -0,0 +1,24 @@
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 { CHECKOUT_OPTIONS } from "./checkout-options.js";
5
+ /** Checkout tradeoffs and mode selection, independent of routing and session creation. */
6
+ export function CheckoutChooser({ value, defaultValue = "embedded", onValueChange, recurring = false, children, }) {
7
+ const [internal, setInternal] = useState(defaultValue);
8
+ const selected = CHECKOUT_OPTIONS.find((option) => option.id === (value ?? internal)) ??
9
+ CHECKOUT_OPTIONS[1];
10
+ const select = (mode) => {
11
+ setInternal(mode);
12
+ onValueChange?.(mode);
13
+ };
14
+ const state = {
15
+ options: CHECKOUT_OPTIONS,
16
+ selected,
17
+ select,
18
+ unsupported: recurring && selected.id === "payment-intent",
19
+ };
20
+ if (children)
21
+ return _jsx(_Fragment, { children: children(state) });
22
+ return (_jsxs("section", { "data-better-stripe": "checkout-chooser", children: [_jsx("h2", { children: "Choose your checkout type" }), _jsx("div", { role: "group", "aria-label": "Checkout types", children: state.options.map((option) => (_jsx("button", { type: "button", "aria-pressed": selected.id === option.id, onClick: () => select(option.id), children: option.title }, option.id))) }), _jsx("h3", { children: selected.title }), _jsx("p", { children: selected.api }), _jsxs("dl", { children: [_jsx("dt", { children: "Pros" }), _jsx("dd", { children: selected.pros }), _jsx("dt", { children: "Cons" }), _jsx("dd", { children: selected.cons })] }), _jsx("a", { href: selected.docs, target: "_blank", rel: "noreferrer", children: "Stripe documentation" }), selected.id === "form" && _jsx("p", { children: "Preview" }), state.unsupported && (_jsx("p", { role: "status", children: "Payment Intents alone do not create subscriptions. Choose a Checkout Sessions integration for a recurring product." }))] }));
23
+ }
24
+ //# sourceMappingURL=CheckoutChooser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckoutChooser.js","sourceRoot":"","sources":["../../../src/react/workflows/CheckoutChooser.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAgBzD,0FAA0F;AAC1F,MAAM,UAAU,eAAe,CAAC,EAC9B,KAAK,EACL,YAAY,GAAG,UAAU,EACzB,aAAa,EACb,SAAS,GAAG,KAAK,EACjB,QAAQ,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AAI,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAC,QAAQ,EAAC,GAAG,EAAC,YAAY,qCAEpD,EACH,QAAQ,CAAC,EAAE,KAAK,MAAM,IAAI,kCAAc,EACxC,KAAK,CAAC,WAAW,IAAI,CACpB,YAAG,IAAI,EAAC,QAAQ,mIAGZ,CACL,IACO,CACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type FormEvent, type ReactNode } from "react";
2
+ import { type Appearance } from "@stripe/stripe-js";
3
+ export type CheckoutFormState = {
4
+ email: string;
5
+ setEmail: (email: string) => void;
6
+ emailInputId: string;
7
+ isPending: boolean;
8
+ error: string | null;
9
+ paymentElement: ReactNode;
10
+ submit: (event: FormEvent<HTMLFormElement>) => void;
11
+ };
12
+ export type CheckoutFormOptions = {
13
+ email?: string;
14
+ appearance?: Appearance;
15
+ renderForm?: (state: CheckoutFormState) => ReactNode;
16
+ };
17
+ export type CheckoutFormProps = CheckoutFormOptions & {
18
+ publishableKey: string;
19
+ clientSecret: string;
20
+ returnUrl: string;
21
+ onNavigate: (url: string) => void;
22
+ };
23
+ export declare function CheckoutElementsForm(props: CheckoutFormProps): import("react").JSX.Element;
24
+ export declare function PaymentIntentForm(props: CheckoutFormProps): import("react").JSX.Element;
25
+ export declare function CheckoutForm(props: CheckoutFormProps): import("react").JSX.Element;
26
+ //# sourceMappingURL=CheckoutForms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckoutForms.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/CheckoutForms.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAgBhE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,cAAc,EAAE,SAAS,CAAC;IAC1B,MAAM,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC;CACrD,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,SAAS,CAAC;CACtD,CAAC;AACF,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG;IACpD,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,CAAC;AAkCF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,+BAU5D;AAsCD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,+BAYzD;AAiDD,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,+BAkBpD"}
@@ -0,0 +1,126 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId, useMemo, useState, } from "react";
4
+ import { loadStripe } from "@stripe/stripe-js";
5
+ import { PaymentElement as IntentElement, useElements, useStripe, } from "@stripe/react-stripe-js";
6
+ import { PaymentElement, useCheckout, CheckoutFormProvider, CheckoutForm as StripeCheckoutForm, useCheckoutForm, } from "@stripe/react-stripe-js/checkout";
7
+ import { CheckoutSessionProvider } from "../components/CheckoutSessionProvider.js";
8
+ import { StripeProvider } from "../components/StripeProvider.js";
9
+ import { useWorkflowAction } from "./useWorkflowAction.js";
10
+ function NativeForm({ email, setEmail, emailInputId, paymentElement, submit, isPending, error, }) {
11
+ return (_jsxs("form", { onSubmit: submit, "data-better-stripe": "checkout-form", "aria-busy": isPending, children: [_jsx("label", { htmlFor: emailInputId, children: "Email for your receipt" }), _jsx("input", { id: emailInputId, type: "email", name: "email", required: true, autoComplete: "email", value: email, onChange: (event) => setEmail(event.target.value) }), paymentElement, error && _jsx("p", { role: "alert", children: error }), _jsx("button", { type: "submit", disabled: isPending, children: isPending ? "Processing…" : "Pay" })] }));
12
+ }
13
+ export function CheckoutElementsForm(props) {
14
+ return (_jsx(CheckoutSessionProvider, { publishableKey: props.publishableKey, clientSecret: props.clientSecret, appearance: props.appearance, children: _jsx(SessionForm, { ...props }) }));
15
+ }
16
+ function SessionForm({ email: initialEmail = "", returnUrl, onNavigate, renderForm, }) {
17
+ const checkout = useCheckout();
18
+ const [email, setEmail] = useState(initialEmail);
19
+ const emailInputId = useId();
20
+ const action = useWorkflowAction(async () => {
21
+ if (checkout.type !== "success")
22
+ throw new Error("Checkout is not ready.");
23
+ const updated = await checkout.checkout.updateEmail(email);
24
+ if (updated.type === "error")
25
+ throw new Error(updated.error.message);
26
+ const confirmed = await checkout.checkout.confirm();
27
+ if (confirmed.type === "error")
28
+ throw new Error(confirmed.error.message);
29
+ onNavigate(returnUrl.replace("{CHECKOUT_SESSION_ID}", checkout.checkout.id));
30
+ });
31
+ if (checkout.type === "loading")
32
+ return _jsx("p", { role: "status", children: "Loading checkout\u2026" });
33
+ if (checkout.type === "error")
34
+ return _jsx("p", { role: "alert", children: checkout.error.message });
35
+ const state = {
36
+ email,
37
+ setEmail,
38
+ emailInputId,
39
+ paymentElement: _jsx(PaymentElement, {}),
40
+ error: action.error,
41
+ isPending: action.isPending,
42
+ submit: (event) => {
43
+ event.preventDefault();
44
+ void action.run();
45
+ },
46
+ };
47
+ return _jsx(_Fragment, { children: renderForm ? renderForm(state) : _jsx(NativeForm, { ...state }) });
48
+ }
49
+ export function PaymentIntentForm(props) {
50
+ return (_jsx(StripeProvider, { publishableKey: props.publishableKey, elementsOptions: {
51
+ clientSecret: props.clientSecret,
52
+ ...(props.appearance ? { appearance: props.appearance } : {}),
53
+ }, children: _jsx(IntentForm, { ...props }) }));
54
+ }
55
+ function IntentForm({ email: initialEmail = "", returnUrl, onNavigate, renderForm, }) {
56
+ const stripe = useStripe();
57
+ const elements = useElements();
58
+ const emailInputId = useId();
59
+ const [email, setEmail] = useState(initialEmail);
60
+ const action = useWorkflowAction(async () => {
61
+ if (!stripe || !elements)
62
+ throw new Error("Payment details are still loading.");
63
+ const validation = await elements.submit();
64
+ if (validation.error)
65
+ throw new Error(validation.error.message ?? "Check your payment details.");
66
+ const result = await stripe.confirmPayment({
67
+ elements,
68
+ confirmParams: {
69
+ return_url: returnUrl,
70
+ payment_method_data: { billing_details: { email } },
71
+ },
72
+ redirect: "if_required",
73
+ });
74
+ if (result.error)
75
+ throw new Error(result.error.message ?? "Payment failed.");
76
+ if (result.paymentIntent) {
77
+ const url = new URL(returnUrl, window.location.origin);
78
+ url.searchParams.set("payment_intent", result.paymentIntent.id);
79
+ onNavigate(url.toString());
80
+ }
81
+ });
82
+ const state = {
83
+ email,
84
+ setEmail,
85
+ emailInputId,
86
+ paymentElement: _jsx(IntentElement, {}),
87
+ error: action.error,
88
+ isPending: action.isPending || !stripe || !elements,
89
+ submit: (event) => {
90
+ event.preventDefault();
91
+ void action.run();
92
+ },
93
+ };
94
+ return _jsx(_Fragment, { children: renderForm ? renderForm(state) : _jsx(NativeForm, { ...state }) });
95
+ }
96
+ export function CheckoutForm(props) {
97
+ const stripe = useMemo(() => loadStripe(props.publishableKey), [props.publishableKey]);
98
+ return (_jsx(CheckoutFormProvider, { stripe: stripe, options: {
99
+ clientSecret: props.clientSecret,
100
+ ...(props.appearance
101
+ ? { elementsOptions: { appearance: props.appearance } }
102
+ : {}),
103
+ }, children: _jsx(CompactForm, { ...props }) }));
104
+ }
105
+ function CompactForm({ returnUrl, onNavigate }) {
106
+ const checkout = useCheckoutForm();
107
+ const [loadError, setLoadError] = useState(null);
108
+ const action = useWorkflowAction(async (event) => {
109
+ if (checkout.type !== "success")
110
+ throw new Error("Checkout is not ready.");
111
+ const result = await checkout.checkout.confirm({
112
+ formConfirmEvent: event,
113
+ });
114
+ if (result.type === "error")
115
+ throw new Error(result.error.message);
116
+ onNavigate(returnUrl.replace("{CHECKOUT_SESSION_ID}", checkout.checkout.id));
117
+ });
118
+ if (checkout.type === "loading")
119
+ return _jsx("p", { role: "status", children: "Loading embedded form\u2026" });
120
+ if (checkout.type === "error")
121
+ return _jsx("p", { role: "alert", children: checkout.error.message });
122
+ return (_jsxs("div", { "data-better-stripe": "checkout-form", "aria-busy": action.isPending, children: [_jsx(StripeCheckoutForm, { onLoadError: ({ error }) => setLoadError(error.message ?? "Could not load checkout."), onConfirm: async (event) => {
123
+ await action.run(event);
124
+ } }), (loadError || action.error) && (_jsx("p", { role: "alert", children: loadError || action.error }))] }));
125
+ }
126
+ //# sourceMappingURL=CheckoutForms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckoutForms.js","sourceRoot":"","sources":["../../../src/react/workflows/CheckoutForms.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EACL,KAAK,EACL,OAAO,EACP,QAAQ,GAGT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAmB,MAAM,mBAAmB,CAAC;AAChE,OAAO,EACL,cAAc,IAAI,aAAa,EAC/B,WAAW,EACX,SAAS,GACV,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,YAAY,IAAI,kBAAkB,EAClC,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAqB3D,SAAS,UAAU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,aACjE,KAAC,kBAAkB,IACjB,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CACzB,YAAY,CAAC,KAAK,CAAC,OAAO,IAAI,0BAA0B,CAAC,EAE3D,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBACzB,MAAM,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAC1B,CAAC,GACD,EACD,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAC9B,YAAG,IAAI,EAAC,OAAO,YAAE,SAAS,IAAI,MAAM,CAAC,KAAK,GAAK,CAChD,IACG,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type ReactNode } from "react";
2
+ export type ClipboardButtonProps = {
3
+ text: string;
4
+ label?: string;
5
+ copiedLabel?: string;
6
+ resetAfterMs?: number;
7
+ writeText?: (text: string) => Promise<void>;
8
+ children?: (state: {
9
+ copy: () => Promise<void>;
10
+ copied: boolean;
11
+ isPending: boolean;
12
+ error: string | null;
13
+ label: string;
14
+ }) => ReactNode;
15
+ };
16
+ export declare function ClipboardButton({ text, label, copiedLabel, resetAfterMs, writeText, children, }: ClipboardButtonProps): import("react").JSX.Element;
17
+ //# sourceMappingURL=ClipboardButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClipboardButton.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/ClipboardButton.tsx"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1D,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE;QACjB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1B,MAAM,EAAE,OAAO,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;QACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,KAAK,SAAS,CAAC;CACjB,CAAC;AACF,wBAAgB,eAAe,CAAC,EAC9B,IAAI,EACJ,KAAc,EACd,WAAuB,EACvB,YAAmB,EACnB,SAAyD,EACzD,QAAQ,GACT,EAAE,oBAAoB,+BA0CtB"}
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef } from "react";
4
+ import { useWorkflowAction } from "./useWorkflowAction.js";
5
+ export function ClipboardButton({ text, label = "Copy", copiedLabel = "Copied!", resetAfterMs = 2000, writeText = (text) => navigator.clipboard.writeText(text), children, }) {
6
+ const action = useWorkflowAction(async () => {
7
+ await writeText(text);
8
+ return text;
9
+ });
10
+ const timer = useRef(undefined);
11
+ useEffect(() => () => {
12
+ clearTimeout(timer.current);
13
+ }, []);
14
+ const copied = action.result === text;
15
+ const copy = async () => {
16
+ const result = await action.run();
17
+ if (result !== undefined) {
18
+ clearTimeout(timer.current);
19
+ timer.current = setTimeout(action.reset, resetAfterMs);
20
+ }
21
+ };
22
+ const state = {
23
+ copy,
24
+ copied,
25
+ isPending: action.isPending,
26
+ error: action.error,
27
+ label: copied ? copiedLabel : label,
28
+ };
29
+ if (children)
30
+ return _jsx(_Fragment, { children: children(state) });
31
+ return (_jsxs("span", { "data-better-stripe": "clipboard", children: [_jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
32
+ void copy();
33
+ }, children: state.label }), state.error && _jsx("span", { role: "alert", children: state.error })] }));
34
+ }
35
+ //# sourceMappingURL=ClipboardButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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E,MAAM,CAAC,KAAK;QACnB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK;KACpC,CAAC;IACF,IAAI,QAAQ;QAAE,OAAO,4BAAG,QAAQ,CAAC,KAAK,CAAC,GAAI,CAAC;IAC5C,OAAO,CACL,sCAAyB,WAAW,aAClC,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,OAAO,EAAE,GAAG,EAAE;oBACZ,KAAK,IAAI,EAAE,CAAC;gBACd,CAAC,YAEA,KAAK,CAAC,KAAK,GACL,EACR,KAAK,CAAC,KAAK,IAAI,eAAM,IAAI,EAAC,OAAO,YAAE,KAAK,CAAC,KAAK,GAAQ,IAClD,CACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { Key, ReactNode } from "react";
2
+ export type WorkflowColumn<Row> = {
3
+ id: string;
4
+ label: string;
5
+ align?: "start" | "end";
6
+ cell: (row: Row) => ReactNode;
7
+ };
8
+ export type CollectionRenderProps<Row> = {
9
+ rows: Row[];
10
+ columns: WorkflowColumn<Row>[];
11
+ getKey: (row: Row) => Key;
12
+ isLoading: boolean;
13
+ isEmpty: boolean;
14
+ error: string | null;
15
+ emptyLabel: string;
16
+ loadingLabel: string;
17
+ };
18
+ export type CollectionProps<Row> = {
19
+ rows: Row[] | null | undefined;
20
+ columns: WorkflowColumn<Row>[];
21
+ getKey: (row: Row) => Key;
22
+ isLoading?: boolean;
23
+ error?: string | null;
24
+ emptyLabel?: string;
25
+ loadingLabel?: string;
26
+ children?: (state: CollectionRenderProps<Row>) => ReactNode;
27
+ };
28
+ /** Accessible native table by default. Render props let the application supply its design-system elements. */
29
+ export declare function Collection<Row>({ rows, columns, getKey, isLoading, error, emptyLabel, loadingLabel, children, }: CollectionProps<Row>): import("react").JSX.Element;
30
+ //# sourceMappingURL=Collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Collection.d.ts","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G,EAAE,EAC9B,IAAI,EACJ,OAAO,EACP,MAAM,EACN,SAA8B,EAC9B,KAAY,EACZ,UAA8B,EAC9B,YAAyB,EACzB,QAAQ,GACT,EAAE,eAAe,CAAC,GAAG,CAAC,+BAqCtB"}
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /** Accessible native table by default. Render props let the application supply its design-system elements. */
4
+ export function Collection({ rows, columns, getKey, isLoading = rows === undefined, error = null, emptyLabel = "No records yet.", loadingLabel = "Loading…", children, }) {
5
+ const state = {
6
+ rows: rows ?? [],
7
+ columns,
8
+ getKey,
9
+ isLoading,
10
+ isEmpty: !isLoading && !rows?.length,
11
+ error,
12
+ emptyLabel,
13
+ loadingLabel,
14
+ };
15
+ if (children)
16
+ return _jsx(_Fragment, { children: children(state) });
17
+ if (error)
18
+ return _jsx("p", { role: "alert", children: error });
19
+ if (isLoading)
20
+ return _jsx("p", { role: "status", children: loadingLabel });
21
+ if (state.isEmpty)
22
+ return _jsx("p", { children: emptyLabel });
23
+ return (_jsxs("table", { "data-better-stripe": "collection", children: [_jsx("thead", { children: _jsx("tr", { children: columns.map((column) => (_jsx("th", { scope: "col", children: column.label }, column.id))) }) }), _jsx("tbody", { children: state.rows.map((row) => (_jsx("tr", { children: columns.map((column) => (_jsx("td", { children: column.cell(row) }, column.id))) }, getKey(row)))) })] }));
24
+ }
25
+ //# sourceMappingURL=Collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Collection.js","sourceRoot":"","sources":["../../../src/react/workflows/Collection.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AA4Bb,8GAA8G;AAC9G,MAAM,UAAU,UAAU,CAAM,EAC9B,IAAI,EACJ,OAAO,EACP,MAAM,EACN,SAAS,GAAG,IAAI,KAAK,SAAS,EAC9B,KAAK,GAAG,IAAI,EACZ,UAAU,GAAG,iBAAiB,EAC9B,YAAY,GAAG,UAAU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