autumn-js 0.1.8 → 0.1.9

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 (210) hide show
  1. package/dist/libraries/backend/better-auth.d.mts +4 -0
  2. package/dist/libraries/backend/better-auth.d.ts +4 -0
  3. package/dist/libraries/backend/better-auth.js +10 -2
  4. package/dist/libraries/backend/better-auth.mjs +7 -7
  5. package/dist/libraries/backend/{chunk-33ET4N4V.mjs → chunk-274BIVOC.mjs} +1 -1
  6. package/dist/libraries/backend/{chunk-BRZHNRU5.mjs → chunk-7WWKVE4J.mjs} +10 -10
  7. package/dist/libraries/backend/{chunk-GO7TVFSN.mjs → chunk-EJBD5GH7.mjs} +1 -1
  8. package/dist/libraries/backend/{chunk-TFYLV3GN.mjs → chunk-I43OU64D.mjs} +1 -1
  9. package/dist/libraries/backend/{chunk-VBHBF3GP.mjs → chunk-JN4ULI5R.mjs} +1 -1
  10. package/dist/libraries/backend/{chunk-AREWK25J.mjs → chunk-KY3RLTE7.mjs} +10 -2
  11. package/dist/libraries/backend/{chunk-LL53FE2Z.mjs → chunk-YN334O74.mjs} +1 -1
  12. package/dist/libraries/backend/convex.js +10 -2
  13. package/dist/libraries/backend/convex.mjs +7 -7
  14. package/dist/libraries/backend/elysia.js +10 -2
  15. package/dist/libraries/backend/elysia.mjs +7 -7
  16. package/dist/libraries/backend/express.d.mts +1 -1
  17. package/dist/libraries/backend/express.d.ts +1 -1
  18. package/dist/libraries/backend/express.js +10 -2
  19. package/dist/libraries/backend/express.mjs +7 -7
  20. package/dist/libraries/backend/fastify.js +10 -2
  21. package/dist/libraries/backend/fastify.mjs +7 -7
  22. package/dist/libraries/backend/hono.js +10 -2
  23. package/dist/libraries/backend/hono.mjs +7 -7
  24. package/dist/libraries/backend/index.d.mts +1 -1
  25. package/dist/libraries/backend/index.d.ts +1 -1
  26. package/dist/libraries/backend/index.js +10 -2
  27. package/dist/libraries/backend/index.mjs +7 -7
  28. package/dist/libraries/backend/next.js +10 -2
  29. package/dist/libraries/backend/next.mjs +7 -7
  30. package/dist/libraries/backend/react-router.js +10 -2
  31. package/dist/libraries/backend/react-router.mjs +7 -7
  32. package/dist/libraries/backend/{referralTypes-DyuV6oJo.d.mts → referralTypes-BEcapeWf.d.mts} +17 -0
  33. package/dist/libraries/backend/{referralTypes-zcdPSX-p.d.ts → referralTypes-DuAlUwev.d.ts} +17 -0
  34. package/dist/libraries/backend/remix_dep.js +10 -2
  35. package/dist/libraries/backend/remix_dep.mjs +7 -7
  36. package/dist/libraries/backend/routes/backendRouter.js +10 -2
  37. package/dist/libraries/backend/routes/backendRouter.mjs +7 -7
  38. package/dist/libraries/backend/routes/entityRoutes.js +10 -2
  39. package/dist/libraries/backend/routes/entityRoutes.mjs +3 -3
  40. package/dist/libraries/backend/routes/genRoutes.js +10 -2
  41. package/dist/libraries/backend/routes/genRoutes.mjs +3 -3
  42. package/dist/libraries/backend/routes/productRoutes.js +10 -2
  43. package/dist/libraries/backend/routes/productRoutes.mjs +3 -3
  44. package/dist/libraries/backend/routes/referralRoutes.js +10 -2
  45. package/dist/libraries/backend/routes/referralRoutes.mjs +3 -3
  46. package/dist/libraries/backend/supabase.js +10 -2
  47. package/dist/libraries/backend/supabase.mjs +7 -7
  48. package/dist/libraries/backend/tanstack.js +10 -2
  49. package/dist/libraries/backend/tanstack.mjs +7 -7
  50. package/dist/libraries/backend/utils/backendRes.js +10 -2
  51. package/dist/libraries/backend/utils/backendRes.mjs +1 -1
  52. package/dist/libraries/backend/utils/withAuth.d.mts +1 -1
  53. package/dist/libraries/backend/utils/withAuth.d.ts +1 -1
  54. package/dist/libraries/backend/utils/withAuth.js +10 -2
  55. package/dist/libraries/backend/utils/withAuth.mjs +2 -2
  56. package/dist/libraries/react/AutumnContext.d.mts +4 -4
  57. package/dist/libraries/react/AutumnContext.d.ts +4 -4
  58. package/dist/libraries/react/AutumnContext.js +10 -2
  59. package/dist/libraries/react/AutumnContext.mjs +3 -3
  60. package/dist/libraries/react/BaseAutumnProvider.d.mts +4 -4
  61. package/dist/libraries/react/BaseAutumnProvider.d.ts +4 -4
  62. package/dist/libraries/react/BaseAutumnProvider.js +10 -2
  63. package/dist/libraries/react/BaseAutumnProvider.mjs +8 -8
  64. package/dist/libraries/react/{ReactAutumnClient-BUq9E84_.d.ts → ReactAutumnClient-DCMQEadM.d.ts} +10 -3
  65. package/dist/libraries/react/{ReactAutumnClient-CpAGyyur.d.mts → ReactAutumnClient-Dm14G99_.d.mts} +10 -3
  66. package/dist/libraries/react/ReactAutumnProvider.d.mts +1 -1
  67. package/dist/libraries/react/ReactAutumnProvider.d.ts +1 -1
  68. package/dist/libraries/react/ReactAutumnProvider.js +10 -2
  69. package/dist/libraries/react/ReactAutumnProvider.mjs +9 -9
  70. package/dist/libraries/react/{attachTypes-CcB6xjSF.d.ts → attachTypes-QTf_JXj7.d.ts} +33 -0
  71. package/dist/libraries/react/{attachTypes-DqUN3q8s.d.mts → attachTypes-Sv_paJZ2.d.mts} +33 -0
  72. package/dist/libraries/react/{chunk-WEKDMT3Y.mjs → chunk-3YIV3N5Y.mjs} +1 -1
  73. package/dist/libraries/react/{chunk-OUWRRLOI.mjs → chunk-4UPD6W4L.mjs} +463 -465
  74. package/dist/libraries/react/{chunk-WH5MYLSM.mjs → chunk-7LOW3KZ3.mjs} +2 -2
  75. package/dist/libraries/react/{chunk-HUKIJ7DB.mjs → chunk-CPN2LD2I.mjs} +2 -2
  76. package/dist/libraries/react/{chunk-TM6QWQLU.mjs → chunk-DRUVAAUW.mjs} +3 -3
  77. package/dist/libraries/react/{chunk-T3B4TVD4.mjs → chunk-E2BEY4ZP.mjs} +1 -1
  78. package/dist/libraries/react/{chunk-5K2M3CQZ.mjs → chunk-FEISQQNM.mjs} +1 -1
  79. package/dist/libraries/react/{chunk-BXMZYHE7.mjs → chunk-FJWZPMWU.mjs} +3 -3
  80. package/dist/libraries/react/{chunk-WT5K3J2K.mjs → chunk-I2A7PK2L.mjs} +17 -17
  81. package/dist/libraries/react/{chunk-JK2TFCOG.mjs → chunk-IRTAGYDD.mjs} +2 -2
  82. package/dist/libraries/react/{chunk-YCDNQZT5.mjs → chunk-JGDTNJTR.mjs} +2 -2
  83. package/dist/libraries/react/{chunk-WQXUZO6K.mjs → chunk-JIWMNR2E.mjs} +10 -2
  84. package/dist/libraries/react/{chunk-6I7KWRND.mjs → chunk-JJVQIA5V.mjs} +1 -1
  85. package/dist/libraries/react/{chunk-IDSAD3KF.mjs → chunk-KG2NPWAE.mjs} +1 -1
  86. package/dist/libraries/react/{chunk-M7SUFZ42.mjs → chunk-KUS3X33V.mjs} +1 -1
  87. package/dist/libraries/react/{chunk-JNR7QAPG.mjs → chunk-MKP43WD6.mjs} +1 -1
  88. package/dist/libraries/react/{chunk-2TQBFCWM.mjs → chunk-OTZ65PCT.mjs} +4 -4
  89. package/dist/libraries/react/{chunk-I6BTXKGK.mjs → chunk-QZPMYB2V.mjs} +2 -2
  90. package/dist/libraries/react/{chunk-UOJ6NIVD.mjs → chunk-TBRYCVBL.mjs} +3 -3
  91. package/dist/libraries/react/{chunk-A5YPS4K4.mjs → chunk-UQ5HI732.mjs} +3 -3
  92. package/dist/libraries/react/{chunk-5OJIHAX7.mjs → chunk-URFTKUL2.mjs} +1 -1
  93. package/dist/libraries/react/{chunk-MW2FSYG3.mjs → chunk-XTONWQ65.mjs} +1 -1
  94. package/dist/libraries/react/{chunk-NHDZWWMZ.mjs → chunk-YWQTQ72B.mjs} +2 -2
  95. package/dist/libraries/react/client/ReactAutumnClient.d.mts +4 -4
  96. package/dist/libraries/react/client/ReactAutumnClient.d.ts +4 -4
  97. package/dist/libraries/react/client/ReactAutumnClient.js +10 -2
  98. package/dist/libraries/react/client/ReactAutumnClient.mjs +2 -2
  99. package/dist/libraries/react/client/clientCompMethods.d.mts +4 -4
  100. package/dist/libraries/react/client/clientCompMethods.d.ts +4 -4
  101. package/dist/libraries/react/client/clientCusMethods.d.mts +4 -4
  102. package/dist/libraries/react/client/clientCusMethods.d.ts +4 -4
  103. package/dist/libraries/react/client/clientEntityMethods.d.mts +4 -4
  104. package/dist/libraries/react/client/clientEntityMethods.d.ts +4 -4
  105. package/dist/libraries/react/client/clientGenMethods.d.mts +4 -4
  106. package/dist/libraries/react/client/clientGenMethods.d.ts +4 -4
  107. package/dist/libraries/react/client/clientProdMethods.d.mts +4 -4
  108. package/dist/libraries/react/client/clientProdMethods.d.ts +4 -4
  109. package/dist/libraries/react/client/clientReferralMethods.d.mts +4 -4
  110. package/dist/libraries/react/client/clientReferralMethods.d.ts +4 -4
  111. package/dist/libraries/react/client/types/clientGenTypes.js +10 -2
  112. package/dist/libraries/react/client/types/clientGenTypes.mjs +1 -1
  113. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.d.mts +1 -1
  114. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.d.ts +1 -1
  115. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.js +10 -2
  116. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.mjs +25 -25
  117. package/dist/libraries/react/components/checkout-dialog/lib/checkout-content.d.mts +1 -1
  118. package/dist/libraries/react/components/checkout-dialog/lib/checkout-content.d.ts +1 -1
  119. package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.js +10 -2
  120. package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.mjs +25 -25
  121. package/dist/libraries/react/components/pricing-table/pricing-table-synced.js +10 -2
  122. package/dist/libraries/react/components/pricing-table/pricing-table-synced.mjs +25 -25
  123. package/dist/libraries/react/components/ui/accordion.mjs +3 -3
  124. package/dist/libraries/react/components/ui/dialog.mjs +4 -4
  125. package/dist/libraries/react/components/ui/popover.mjs +5 -5
  126. package/dist/libraries/react/components/ui/switch.mjs +3 -3
  127. package/dist/libraries/react/{entTypes-CoF9enrR.d.ts → entTypes-0CBBecul.d.ts} +1 -1
  128. package/dist/libraries/react/{entTypes-S4hkh1RG.d.mts → entTypes-kVUQcah5.d.mts} +1 -1
  129. package/dist/libraries/react/hooks/helpers/handleCheck.d.mts +4 -4
  130. package/dist/libraries/react/hooks/helpers/handleCheck.d.ts +4 -4
  131. package/dist/libraries/react/hooks/helpers/handleCheck.js +10 -2
  132. package/dist/libraries/react/hooks/helpers/handleCheck.mjs +2 -2
  133. package/dist/libraries/react/hooks/helpers/useAutumnBase.d.mts +11 -4
  134. package/dist/libraries/react/hooks/helpers/useAutumnBase.d.ts +11 -4
  135. package/dist/libraries/react/hooks/helpers/useAutumnBase.js +10 -2
  136. package/dist/libraries/react/hooks/helpers/useAutumnBase.mjs +3 -3
  137. package/dist/libraries/react/hooks/useAnalytics.js +10 -2
  138. package/dist/libraries/react/hooks/useAnalytics.mjs +4 -4
  139. package/dist/libraries/react/hooks/useCustomer.d.mts +4 -4
  140. package/dist/libraries/react/hooks/useCustomer.d.ts +4 -4
  141. package/dist/libraries/react/hooks/useCustomer.js +10 -2
  142. package/dist/libraries/react/hooks/useCustomer.mjs +8 -8
  143. package/dist/libraries/react/hooks/useCustomerBase.d.mts +4 -4
  144. package/dist/libraries/react/hooks/useCustomerBase.d.ts +4 -4
  145. package/dist/libraries/react/hooks/useCustomerBase.js +10 -2
  146. package/dist/libraries/react/hooks/useCustomerBase.mjs +7 -7
  147. package/dist/libraries/react/hooks/useEntity.d.mts +11 -4
  148. package/dist/libraries/react/hooks/useEntity.d.ts +11 -4
  149. package/dist/libraries/react/hooks/useEntity.js +10 -2
  150. package/dist/libraries/react/hooks/useEntity.mjs +8 -8
  151. package/dist/libraries/react/hooks/useEntityBase.d.mts +13 -6
  152. package/dist/libraries/react/hooks/useEntityBase.d.ts +13 -6
  153. package/dist/libraries/react/hooks/useEntityBase.js +10 -2
  154. package/dist/libraries/react/hooks/useEntityBase.mjs +7 -7
  155. package/dist/libraries/react/hooks/usePaywall.js +10 -2
  156. package/dist/libraries/react/hooks/usePaywall.mjs +4 -4
  157. package/dist/libraries/react/hooks/usePricingTable.js +10 -2
  158. package/dist/libraries/react/hooks/usePricingTable.mjs +5 -5
  159. package/dist/libraries/react/hooks/usePricingTableBase.d.mts +4 -4
  160. package/dist/libraries/react/hooks/usePricingTableBase.d.ts +4 -4
  161. package/dist/libraries/react/hooks/usePricingTableBase.js +10 -2
  162. package/dist/libraries/react/hooks/usePricingTableBase.mjs +2 -2
  163. package/dist/libraries/react/hooks/useProductsBase.d.mts +4 -4
  164. package/dist/libraries/react/hooks/useProductsBase.d.ts +4 -4
  165. package/dist/libraries/react/index.d.mts +40 -0
  166. package/dist/libraries/react/index.d.ts +40 -0
  167. package/dist/libraries/react/index.js +10 -2
  168. package/dist/libraries/react/index.mjs +10 -2
  169. package/dist/next/client/NextAutumnClient.d.mts +13 -6
  170. package/dist/next/client/NextAutumnClient.d.ts +13 -6
  171. package/dist/next/client/NextAutumnProvider.d.mts +1 -1
  172. package/dist/next/client/NextAutumnProvider.d.ts +1 -1
  173. package/dist/next/client/{attachTypes-DxJ0LCjT.d.ts → attachTypes-CReq8zJ_.d.ts} +35 -2
  174. package/dist/next/client/{attachTypes-DZFtFEmv.d.mts → attachTypes-DUUIHTBt.d.mts} +35 -2
  175. package/dist/next/client/clientUtils.d.mts +2 -2
  176. package/dist/next/client/clientUtils.d.ts +2 -2
  177. package/dist/next/client/{entTypes-vjIG3B1G.d.ts → entTypes-BAD1NMvb.d.ts} +1 -1
  178. package/dist/next/client/{entTypes-CHHBdhBK.d.mts → entTypes-mOI7WnPZ.d.mts} +1 -1
  179. package/dist/next/client/hooks/useAutumn.d.mts +10 -3
  180. package/dist/next/client/hooks/useAutumn.d.ts +10 -3
  181. package/dist/next/client/hooks/useCustomer.d.mts +4 -4
  182. package/dist/next/client/hooks/useCustomer.d.ts +4 -4
  183. package/dist/next/client/hooks/useEntity.d.mts +12 -5
  184. package/dist/next/client/hooks/useEntity.d.ts +12 -5
  185. package/dist/next/client/types.d.mts +2 -2
  186. package/dist/next/client/types.d.ts +2 -2
  187. package/dist/next/server/auth/withNextAuth.d.mts +1 -1
  188. package/dist/next/server/auth/withNextAuth.d.ts +1 -1
  189. package/dist/next/server/componentActions.d.mts +1 -1
  190. package/dist/next/server/componentActions.d.ts +1 -1
  191. package/dist/next/server/cusActions.d.mts +34 -17
  192. package/dist/next/server/cusActions.d.ts +34 -17
  193. package/dist/next/server/genActions.d.mts +1 -1
  194. package/dist/next/server/genActions.d.ts +1 -1
  195. package/dist/sdk/index.d.mts +50 -0
  196. package/dist/sdk/index.d.ts +50 -0
  197. package/dist/sdk/index.js +10 -2
  198. package/dist/sdk/index.mjs +10 -2
  199. package/dist/utils/encryptUtils.js +10 -2
  200. package/dist/utils/encryptUtils.mjs +10 -2
  201. package/package.json +1 -1
  202. package/dist/libraries/react/{chunk-KWNH6C27.mjs → chunk-7TYAAD2T.mjs} +11 -11
  203. package/dist/libraries/react/{cusTypes-DHjT-9rV.d.ts → cusTypes-BeSXIQ6P.d.ts} +2 -2
  204. package/dist/libraries/react/{cusTypes-CSmAk5io.d.mts → cusTypes-DbCQV8Sj.d.mts} +2 -2
  205. package/dist/next/client/{clientAttachTypes-qsdoMt_B.d.mts → clientAttachTypes-BzsPgggN.d.mts} +2 -2
  206. package/dist/next/client/{clientAttachTypes-BXtfXB4v.d.ts → clientAttachTypes-umadXlvp.d.ts} +2 -2
  207. package/dist/next/client/{cusTypes-Q54uLNO5.d.mts → cusTypes-CIGvysWL.d.mts} +2 -2
  208. package/dist/next/client/{cusTypes-BHYpk8bK.d.ts → cusTypes-CYojUJSJ.d.ts} +2 -2
  209. package/dist/next/server/{cusTypes-DgoOZMIt.d.ts → cusTypes-CwopPHB0.d.mts} +8 -8
  210. package/dist/next/server/{cusTypes-DgoOZMIt.d.mts → cusTypes-CwopPHB0.d.ts} +8 -8
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
 
3
- import {
4
- getCheckoutContent
5
- } from "./chunk-BLM4DAAR.mjs";
6
3
  import {
7
4
  getPaywallContent
8
5
  } from "./chunk-I5ZGIAIX.mjs";
6
+ import {
7
+ getCheckoutContent
8
+ } from "./chunk-BLM4DAAR.mjs";
9
9
  import {
10
10
  getPricingTableContent
11
11
  } from "./chunk-URQMBRFZ.mjs";
@@ -13,10 +13,10 @@ import {
13
13
  Popover,
14
14
  PopoverContent,
15
15
  PopoverTrigger
16
- } from "./chunk-2TQBFCWM.mjs";
16
+ } from "./chunk-OTZ65PCT.mjs";
17
17
  import {
18
18
  Switch
19
- } from "./chunk-NHDZWWMZ.mjs";
19
+ } from "./chunk-YWQTQ72B.mjs";
20
20
  import {
21
21
  loadingStyles,
22
22
  spinnerStyles
@@ -27,7 +27,7 @@ import {
27
27
  AccordionItem,
28
28
  Header,
29
29
  Trigger2
30
- } from "./chunk-YCDNQZT5.mjs";
30
+ } from "./chunk-JGDTNJTR.mjs";
31
31
  import {
32
32
  Button
33
33
  } from "./chunk-EV5RNY5U.mjs";
@@ -36,7 +36,7 @@ import {
36
36
  DialogContent,
37
37
  DialogFooter,
38
38
  DialogTitle
39
- } from "./chunk-BXMZYHE7.mjs";
39
+ } from "./chunk-FJWZPMWU.mjs";
40
40
  import {
41
41
  ArrowRight,
42
42
  ChevronDown,
@@ -47,164 +47,473 @@ import {
47
47
  } from "./chunk-GUM4HIGI.mjs";
48
48
  import {
49
49
  usePaywall
50
- } from "./chunk-6I7KWRND.mjs";
50
+ } from "./chunk-JJVQIA5V.mjs";
51
51
  import {
52
52
  usePricingTable
53
- } from "./chunk-I6BTXKGK.mjs";
53
+ } from "./chunk-QZPMYB2V.mjs";
54
54
  import {
55
55
  cn
56
56
  } from "./chunk-4J6OC4ZQ.mjs";
57
57
  import {
58
58
  useCustomer
59
- } from "./chunk-HUKIJ7DB.mjs";
59
+ } from "./chunk-CPN2LD2I.mjs";
60
60
 
61
61
  // src/libraries/react/components/checkout-dialog/checkout-dialog-synced.tsx
62
- import { useEffect, useState as useState2 } from "react";
63
-
64
- // src/libraries/react/components/paywall-dialog/paywall-dialog-synced.tsx
62
+ import { useEffect, useState } from "react";
65
63
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
66
- function PaywallDialog(params) {
67
- const { data: preview } = usePaywall({
68
- featureId: params?.featureId,
69
- entityId: params?.entityId
70
- });
71
- if (!params || !preview) {
64
+ var formatCurrency = ({
65
+ amount,
66
+ currency
67
+ }) => {
68
+ return new Intl.NumberFormat("en-US", {
69
+ style: "currency",
70
+ currency
71
+ }).format(amount);
72
+ };
73
+ function CheckoutDialog(params) {
74
+ const { attach } = useCustomer();
75
+ const [checkoutResult, setCheckoutResult] = useState(params?.checkoutResult);
76
+ useEffect(() => {
77
+ if (params.checkoutResult) {
78
+ setCheckoutResult(params.checkoutResult);
79
+ }
80
+ }, [params.checkoutResult]);
81
+ const [loading, setLoading] = useState(false);
82
+ if (!checkoutResult) {
72
83
  return /* @__PURE__ */ jsx(Fragment, {});
73
84
  }
74
85
  const { open, setOpen } = params;
75
- const { title, message } = getPaywallContent(preview);
76
- return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { className: "au-p-0 au-pt-4 au-gap-0 au-text-foreground au-overflow-hidden au-text-sm", children: [
77
- /* @__PURE__ */ jsx(DialogTitle, { className: cn("au-font-bold au-text-xl au-px-6"), children: title }),
78
- /* @__PURE__ */ jsx("div", { className: "au-px-6 au-my-2", children: message }),
79
- /* @__PURE__ */ jsx(DialogFooter, { className: "au-flex au-flex-col sm:au-flex-row au-justify-between au-gap-x-4 au-py-2 au-mt-4 au-pl-6 au-pr-3 au-bg-secondary au-border-t", children: /* @__PURE__ */ jsx(
86
+ const { title, message } = getCheckoutContent(checkoutResult);
87
+ const isFree = checkoutResult?.product.properties?.is_free;
88
+ const isPaid = isFree === false;
89
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { className: "au-p-0 au-pt-4 au-gap-0 au-text-foreground au-text-sm", children: [
90
+ /* @__PURE__ */ jsx(DialogTitle, { className: "au-px-6 au-mb-1", children: title }),
91
+ /* @__PURE__ */ jsx("div", { className: "au-px-6 au-mt-1 au-mb-4 au-text-muted-foreground", children: message }),
92
+ isPaid && checkoutResult && /* @__PURE__ */ jsx(
93
+ PriceInformation,
94
+ {
95
+ checkoutResult,
96
+ setCheckoutResult
97
+ }
98
+ ),
99
+ /* @__PURE__ */ jsx(DialogFooter, { className: "au-flex au-flex-col sm:au-flex-row au-justify-between au-gap-x-4 au-py-2 au-pl-6 au-pr-3 au-bg-secondary au-border-t au-shadow-inner", children: /* @__PURE__ */ jsx(
80
100
  Button,
81
101
  {
82
102
  size: "sm",
83
- className: "au-font-medium au-shadow au-transition au-min-w-20",
84
103
  onClick: async () => {
104
+ setLoading(true);
105
+ const options = checkoutResult.options.map((option) => {
106
+ return {
107
+ featureId: option.feature_id,
108
+ quantity: option.quantity
109
+ };
110
+ });
111
+ await attach({
112
+ productId: checkoutResult.product.id,
113
+ options
114
+ });
85
115
  setOpen(false);
116
+ setLoading(false);
86
117
  },
87
- children: "Confirm"
118
+ disabled: loading,
119
+ className: "au-min-w-16 au-flex au-items-center au-gap-2",
120
+ children: loading ? /* @__PURE__ */ jsx(LoaderCircle, { className: "au-w-4 au-h-4 au-animate-spin" }) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("span", { className: "au-whitespace-nowrap au-flex au-gap-1", children: "Confirm" }) })
88
121
  }
89
122
  ) })
90
123
  ] }) });
91
124
  }
92
-
93
- // src/libraries/react/components/pricing-table/pricing-table-synced.tsx
94
- import React from "react";
95
- import { createContext, useContext, useState } from "react";
96
- import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
97
- function PricingTable({
98
- productDetails
125
+ function PriceInformation({
126
+ checkoutResult,
127
+ setCheckoutResult
99
128
  }) {
100
- const { customer, checkout } = useCustomer({ errorOnNotFound: false });
101
- const [isAnnual, setIsAnnual] = useState(false);
102
- const { products, isLoading, error } = usePricingTable({ productDetails });
103
- if (isLoading) {
104
- return /* @__PURE__ */ jsx2("div", { style: loadingStyles, children: /* @__PURE__ */ jsx2(LoaderCircle, { style: spinnerStyles }) });
105
- }
106
- if (error) {
107
- return /* @__PURE__ */ jsx2("div", { children: " Something went wrong..." });
108
- }
109
- const intervals = Array.from(
110
- new Set(
111
- products?.map((p) => p.properties?.interval_group).filter((i) => !!i)
112
- )
129
+ return /* @__PURE__ */ jsxs("div", { className: "au-px-6 au-mb-4 au-flex au-flex-col au-gap-4", children: [
130
+ /* @__PURE__ */ jsx(
131
+ ProductItems,
132
+ {
133
+ checkoutResult,
134
+ setCheckoutResult
135
+ }
136
+ ),
137
+ /* @__PURE__ */ jsxs("div", { className: "au-flex au-flex-col au-gap-2", children: [
138
+ checkoutResult?.has_prorations && checkoutResult.lines.length > 0 && /* @__PURE__ */ jsx(CheckoutLines, { checkoutResult }),
139
+ /* @__PURE__ */ jsx(DueAmounts, { checkoutResult })
140
+ ] })
141
+ ] });
142
+ }
143
+ function DueAmounts({ checkoutResult }) {
144
+ const { next_cycle, product } = checkoutResult;
145
+ const nextCycleAtStr = next_cycle ? new Date(next_cycle.starts_at).toLocaleDateString() : void 0;
146
+ const hasUsagePrice = product.items.some(
147
+ (item) => item.usage_model === "pay_per_use"
113
148
  );
114
- const multiInterval = intervals.length > 1;
115
- const intervalFilter = (product) => {
116
- if (!product.properties?.interval_group) {
117
- return true;
118
- }
119
- if (multiInterval) {
120
- if (isAnnual) {
121
- return product.properties?.interval_group === "year";
122
- } else {
123
- return product.properties?.interval_group === "month";
149
+ const showNextCycle = next_cycle && next_cycle.total !== checkoutResult.total;
150
+ return /* @__PURE__ */ jsxs("div", { className: "au-flex au-flex-col au-gap-1", children: [
151
+ /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between", children: [
152
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("p", { className: "au-font-medium au-text-md", children: "Total due today" }) }),
153
+ /* @__PURE__ */ jsx("p", { className: "au-font-medium au-text-md", children: formatCurrency({
154
+ amount: checkoutResult?.total,
155
+ currency: checkoutResult?.currency
156
+ }) })
157
+ ] }),
158
+ showNextCycle && /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between au-text-muted-foreground", children: [
159
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("p", { className: "au-text-md", children: [
160
+ "Due next cycle (",
161
+ nextCycleAtStr,
162
+ ")"
163
+ ] }) }),
164
+ /* @__PURE__ */ jsxs("p", { className: "au-text-md", children: [
165
+ formatCurrency({
166
+ amount: next_cycle.total,
167
+ currency: checkoutResult?.currency
168
+ }),
169
+ hasUsagePrice && /* @__PURE__ */ jsx("span", { children: " + usage prices" })
170
+ ] })
171
+ ] })
172
+ ] });
173
+ }
174
+ function ProductItems({
175
+ checkoutResult,
176
+ setCheckoutResult
177
+ }) {
178
+ const isUpdateQuantity = checkoutResult?.product.scenario === "active" && checkoutResult.product.properties.updateable;
179
+ const isOneOff = checkoutResult?.product.properties.is_one_off;
180
+ return /* @__PURE__ */ jsxs("div", { className: "au-flex au-flex-col au-gap-2", children: [
181
+ /* @__PURE__ */ jsx("p", { className: "au-text-sm au-font-medium", children: "Price" }),
182
+ checkoutResult?.product.items.filter((item) => item.type !== "feature").map((item, index) => {
183
+ if (item.usage_model == "prepaid") {
184
+ return /* @__PURE__ */ jsx(
185
+ PrepaidItem,
186
+ {
187
+ item,
188
+ checkoutResult,
189
+ setCheckoutResult
190
+ },
191
+ index
192
+ );
124
193
  }
125
- }
126
- return true;
127
- };
128
- return /* @__PURE__ */ jsx2("div", { className: cn("au-root"), children: products && /* @__PURE__ */ jsx2(
129
- PricingTableContainer,
130
- {
131
- products,
132
- isAnnualToggle: isAnnual,
133
- setIsAnnualToggle: setIsAnnual,
134
- multiInterval,
135
- children: products.filter(intervalFilter).map((product, index) => /* @__PURE__ */ jsx2(
136
- PricingCard,
194
+ if (isUpdateQuantity) {
195
+ return null;
196
+ }
197
+ return /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between", children: [
198
+ /* @__PURE__ */ jsx("p", { className: "au-text-muted-foreground", children: item.feature ? item.feature.name : isOneOff ? "Price" : "Subscription" }),
199
+ /* @__PURE__ */ jsxs("p", { children: [
200
+ item.display?.primary_text,
201
+ " ",
202
+ item.display?.secondary_text
203
+ ] })
204
+ ] }, index);
205
+ })
206
+ ] });
207
+ }
208
+ function CheckoutLines({ checkoutResult }) {
209
+ return /* @__PURE__ */ jsx(Accordion, { type: "single", collapsible: true, children: /* @__PURE__ */ jsxs(AccordionItem, { value: "total", className: "au-border-b-0", children: [
210
+ /* @__PURE__ */ jsx(CustomAccordionTrigger, { className: "au-justify-between au-w-full au-my-0 au-py-0 au-border-none", children: /* @__PURE__ */ jsxs("div", { className: "au-cursor-pointer au-flex au-items-center au-gap-1 au-w-full au-justify-end", children: [
211
+ /* @__PURE__ */ jsx("p", { className: "au-font-light au-text-muted-foreground", children: "View details" }),
212
+ /* @__PURE__ */ jsx(
213
+ ChevronDown,
137
214
  {
138
- productId: product.id,
139
- buttonProps: {
140
- disabled: product.scenario === "active" && !product.properties.updateable || product.scenario === "scheduled",
141
- onClick: async () => {
142
- if (product.id && customer) {
143
- await checkout({
144
- productId: product.id,
145
- dialog: CheckoutDialog
146
- });
147
- } else if (product.display?.button_url) {
148
- window.open(product.display?.button_url, "_blank");
149
- }
150
- }
151
- }
152
- },
153
- index
154
- ))
215
+ className: "au-text-muted-foreground au-mt-0.5 au-rotate-90 au-transition-transform au-duration-200 au-ease-in-out",
216
+ size: 14
217
+ }
218
+ )
219
+ ] }) }),
220
+ /* @__PURE__ */ jsx(AccordionContent, { className: "au-mt-2 au-mb-0 au-pb-2 au-flex au-flex-col au-gap-2", children: checkoutResult?.lines.filter((line) => line.amount != 0).map((line, index) => {
221
+ return /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between", children: [
222
+ /* @__PURE__ */ jsx("p", { className: "au-text-muted-foreground", children: line.description }),
223
+ /* @__PURE__ */ jsx("p", { className: "au-text-muted-foreground", children: new Intl.NumberFormat("en-US", {
224
+ style: "currency",
225
+ currency: checkoutResult?.currency
226
+ }).format(line.amount) })
227
+ ] }, index);
228
+ }) })
229
+ ] }) });
230
+ }
231
+ function CustomAccordionTrigger({
232
+ className,
233
+ children,
234
+ ...props
235
+ }) {
236
+ return /* @__PURE__ */ jsx(Header, { className: "au-flex", children: /* @__PURE__ */ jsx(
237
+ Trigger2,
238
+ {
239
+ "data-slot": "accordion-trigger",
240
+ className: cn(
241
+ "focus-visible:au-border-ring focus-visible:au-ring-ring/50 au-flex au-flex-1 au-items-start au-justify-between au-gap-4 au-rounded-md au-py-4 au-text-left au-text-sm au-font-medium au-transition-all au-outline-none focus-visible:au-ring-[3px] disabled:au-pointer-events-none disabled:au-opacity-50 [&[data-state=open]_svg]:au-rotate-0",
242
+ className
243
+ ),
244
+ ...props,
245
+ children
155
246
  }
156
247
  ) });
157
248
  }
158
- var PricingTableContext = createContext({
159
- isAnnualToggle: false,
160
- setIsAnnualToggle: () => {
161
- },
162
- products: [],
163
- showFeatures: true
164
- });
165
- var usePricingTableContext = (componentName) => {
166
- const context = useContext(PricingTableContext);
167
- if (context === void 0) {
168
- throw new Error(`${componentName} must be used within <PricingTable />`);
169
- }
170
- return context;
171
- };
172
- var PricingTableContainer = ({
173
- children,
174
- products,
175
- showFeatures = true,
176
- className,
177
- isAnnualToggle,
178
- setIsAnnualToggle,
179
- multiInterval
249
+ var PrepaidItem = ({
250
+ item,
251
+ checkoutResult,
252
+ setCheckoutResult
180
253
  }) => {
181
- if (!products) {
182
- throw new Error("products is required in <PricingTable />");
183
- }
184
- if (products.length === 0) {
185
- return /* @__PURE__ */ jsx2(Fragment2, {});
186
- }
187
- const hasRecommended = products?.some((p) => p.display?.recommend_text);
188
- return /* @__PURE__ */ jsx2(
189
- PricingTableContext.Provider,
190
- {
191
- value: { isAnnualToggle, setIsAnnualToggle, products, showFeatures },
192
- children: /* @__PURE__ */ jsxs2(
193
- "div",
194
- {
195
- className: cn(
196
- "au-flex au-items-center au-flex-col",
197
- hasRecommended && "!au-py-10"
198
- ),
199
- children: [
200
- multiInterval && /* @__PURE__ */ jsx2(
201
- "div",
202
- {
203
- className: cn(
204
- products.some((p) => p.display?.recommend_text) && "au-mb-8"
205
- ),
206
- children: /* @__PURE__ */ jsx2(
207
- AnnualSwitch,
254
+ const { quantity = 0, billing_units: billingUnits = 1 } = item;
255
+ const [quantityInput, setQuantityInput] = useState(
256
+ (quantity / billingUnits).toString()
257
+ );
258
+ const { checkout } = useCustomer();
259
+ const [loading, setLoading] = useState(false);
260
+ const [open, setOpen] = useState(false);
261
+ const scenario = checkoutResult.product.scenario;
262
+ const handleSave = async () => {
263
+ setLoading(true);
264
+ try {
265
+ const newOptions = checkoutResult.options.filter((option) => option.feature_id !== item.feature_id).map((option) => {
266
+ return {
267
+ featureId: option.feature_id,
268
+ quantity: option.quantity
269
+ };
270
+ });
271
+ newOptions.push({
272
+ featureId: item.feature_id,
273
+ quantity: Number(quantityInput) * billingUnits
274
+ });
275
+ const { data, error } = await checkout({
276
+ productId: checkoutResult.product.id,
277
+ options: newOptions,
278
+ dialog: CheckoutDialog
279
+ });
280
+ if (error) {
281
+ console.error(error);
282
+ return;
283
+ }
284
+ setCheckoutResult(data);
285
+ } catch (error) {
286
+ console.error(error);
287
+ } finally {
288
+ setLoading(false);
289
+ setOpen(false);
290
+ }
291
+ };
292
+ const disableSelection = scenario === "renew";
293
+ return /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between", children: [
294
+ /* @__PURE__ */ jsxs("div", { className: "au-flex au-gap-2", children: [
295
+ /* @__PURE__ */ jsx("p", { className: "au-text-muted-foreground", children: item.feature?.name }),
296
+ /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
297
+ /* @__PURE__ */ jsxs(
298
+ PopoverTrigger,
299
+ {
300
+ className: cn(
301
+ "au-text-muted-foreground au-text-xs au-px-1 au-py-0.5 au-rounded-md au-flex au-items-center au-gap-1 au-bg-accent/80",
302
+ disableSelection !== true && "hover:au-bg-accent hover:au-text-foreground"
303
+ ),
304
+ disabled: disableSelection,
305
+ children: [
306
+ "Qty: ",
307
+ quantity,
308
+ /* @__PURE__ */ jsx(ChevronDown, { size: 12 })
309
+ ]
310
+ }
311
+ ),
312
+ /* @__PURE__ */ jsxs(
313
+ PopoverContent,
314
+ {
315
+ align: "start",
316
+ className: "au-w-80 au-text-sm au-p-4 au-pt-3 au-flex au-flex-col au-gap-4",
317
+ children: [
318
+ /* @__PURE__ */ jsxs("div", { className: "au-flex au-flex-col au-gap-1", children: [
319
+ /* @__PURE__ */ jsx("p", { className: "au-text-sm au-font-medium", children: item.feature?.name }),
320
+ /* @__PURE__ */ jsxs("p", { className: "au-text-muted-foreground", children: [
321
+ item.display?.primary_text,
322
+ " ",
323
+ item.display?.secondary_text
324
+ ] })
325
+ ] }),
326
+ /* @__PURE__ */ jsxs("div", { className: "au-flex au-justify-between au-items-end", children: [
327
+ /* @__PURE__ */ jsxs("div", { className: "au-flex au-gap-2 au-items-center", children: [
328
+ /* @__PURE__ */ jsx(
329
+ Input,
330
+ {
331
+ className: "au-h-7 au-w-16 focus:!au-ring-2",
332
+ value: quantityInput,
333
+ onChange: (e) => setQuantityInput(e.target.value)
334
+ }
335
+ ),
336
+ /* @__PURE__ */ jsxs("p", { className: "au-text-muted-foreground", children: [
337
+ billingUnits > 1 && `x ${billingUnits} `,
338
+ item.feature?.name
339
+ ] })
340
+ ] }),
341
+ /* @__PURE__ */ jsx(
342
+ Button,
343
+ {
344
+ onClick: handleSave,
345
+ className: "au-w-14 !au-h-7 au-text-sm au-items-center au-bg-white au-text-foreground au-shadow-sm au-border au-border-zinc-200 hover:au-bg-zinc-100",
346
+ disabled: loading,
347
+ children: loading ? /* @__PURE__ */ jsx(LoaderCircle, { className: "au-text-muted-foreground au-animate-spin !au-w-4 !au-h-4" }) : "Save"
348
+ }
349
+ )
350
+ ] })
351
+ ]
352
+ }
353
+ )
354
+ ] })
355
+ ] }),
356
+ /* @__PURE__ */ jsxs("p", { children: [
357
+ item.display?.primary_text,
358
+ " ",
359
+ item.display?.secondary_text
360
+ ] })
361
+ ] });
362
+ };
363
+ var PriceItem = ({
364
+ children,
365
+ className,
366
+ ...props
367
+ }) => {
368
+ return /* @__PURE__ */ jsx(
369
+ "div",
370
+ {
371
+ className: cn(
372
+ "au-flex au-flex-col au-pb-4 sm:au-pb-0 au-gap-1 sm:au-flex-row au-justify-between sm:au-h-7 sm:au-gap-2 sm:au-items-center",
373
+ className
374
+ ),
375
+ ...props,
376
+ children
377
+ }
378
+ );
379
+ };
380
+ var PricingDialogButton = ({
381
+ children,
382
+ size,
383
+ onClick,
384
+ disabled,
385
+ className
386
+ }) => {
387
+ return /* @__PURE__ */ jsxs(
388
+ Button,
389
+ {
390
+ onClick,
391
+ disabled,
392
+ size,
393
+ className: cn(className, "au-shadow-sm au-shadow-stone-400"),
394
+ children: [
395
+ children,
396
+ /* @__PURE__ */ jsx(ArrowRight, { className: "!au-h-3" })
397
+ ]
398
+ }
399
+ );
400
+ };
401
+
402
+ // src/libraries/react/components/pricing-table/pricing-table-synced.tsx
403
+ import React2 from "react";
404
+ import { createContext, useContext, useState as useState2 } from "react";
405
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
406
+ function PricingTable({
407
+ productDetails
408
+ }) {
409
+ const { customer, checkout } = useCustomer({ errorOnNotFound: false });
410
+ const [isAnnual, setIsAnnual] = useState2(false);
411
+ const { products, isLoading, error } = usePricingTable({ productDetails });
412
+ if (isLoading) {
413
+ return /* @__PURE__ */ jsx2("div", { style: loadingStyles, children: /* @__PURE__ */ jsx2(LoaderCircle, { style: spinnerStyles }) });
414
+ }
415
+ if (error) {
416
+ return /* @__PURE__ */ jsx2("div", { children: " Something went wrong..." });
417
+ }
418
+ const intervals = Array.from(
419
+ new Set(
420
+ products?.map((p) => p.properties?.interval_group).filter((i) => !!i)
421
+ )
422
+ );
423
+ const multiInterval = intervals.length > 1;
424
+ const intervalFilter = (product) => {
425
+ if (!product.properties?.interval_group) {
426
+ return true;
427
+ }
428
+ if (multiInterval) {
429
+ if (isAnnual) {
430
+ return product.properties?.interval_group === "year";
431
+ } else {
432
+ return product.properties?.interval_group === "month";
433
+ }
434
+ }
435
+ return true;
436
+ };
437
+ return /* @__PURE__ */ jsx2("div", { className: cn("au-root"), children: products && /* @__PURE__ */ jsx2(
438
+ PricingTableContainer,
439
+ {
440
+ products,
441
+ isAnnualToggle: isAnnual,
442
+ setIsAnnualToggle: setIsAnnual,
443
+ multiInterval,
444
+ children: products.filter(intervalFilter).map((product, index) => /* @__PURE__ */ jsx2(
445
+ PricingCard,
446
+ {
447
+ productId: product.id,
448
+ buttonProps: {
449
+ disabled: product.scenario === "active" && !product.properties.updateable || product.scenario === "scheduled",
450
+ onClick: async () => {
451
+ if (product.id && customer) {
452
+ await checkout({
453
+ productId: product.id,
454
+ dialog: CheckoutDialog
455
+ });
456
+ } else if (product.display?.button_url) {
457
+ window.open(product.display?.button_url, "_blank");
458
+ }
459
+ }
460
+ }
461
+ },
462
+ index
463
+ ))
464
+ }
465
+ ) });
466
+ }
467
+ var PricingTableContext = createContext({
468
+ isAnnualToggle: false,
469
+ setIsAnnualToggle: () => {
470
+ },
471
+ products: [],
472
+ showFeatures: true
473
+ });
474
+ var usePricingTableContext = (componentName) => {
475
+ const context = useContext(PricingTableContext);
476
+ if (context === void 0) {
477
+ throw new Error(`${componentName} must be used within <PricingTable />`);
478
+ }
479
+ return context;
480
+ };
481
+ var PricingTableContainer = ({
482
+ children,
483
+ products,
484
+ showFeatures = true,
485
+ className,
486
+ isAnnualToggle,
487
+ setIsAnnualToggle,
488
+ multiInterval
489
+ }) => {
490
+ if (!products) {
491
+ throw new Error("products is required in <PricingTable />");
492
+ }
493
+ if (products.length === 0) {
494
+ return /* @__PURE__ */ jsx2(Fragment2, {});
495
+ }
496
+ const hasRecommended = products?.some((p) => p.display?.recommend_text);
497
+ return /* @__PURE__ */ jsx2(
498
+ PricingTableContext.Provider,
499
+ {
500
+ value: { isAnnualToggle, setIsAnnualToggle, products, showFeatures },
501
+ children: /* @__PURE__ */ jsxs2(
502
+ "div",
503
+ {
504
+ className: cn(
505
+ "au-flex au-items-center au-flex-col",
506
+ hasRecommended && "!au-py-10"
507
+ ),
508
+ children: [
509
+ multiInterval && /* @__PURE__ */ jsx2(
510
+ "div",
511
+ {
512
+ className: cn(
513
+ products.some((p) => p.display?.recommend_text) && "au-mb-8"
514
+ ),
515
+ children: /* @__PURE__ */ jsx2(
516
+ AnnualSwitch,
208
517
  {
209
518
  isAnnualToggle,
210
519
  setIsAnnualToggle
@@ -328,8 +637,8 @@ var PricingFeatureList = ({
328
637
  )) })
329
638
  ] });
330
639
  };
331
- var PricingCardButton = React.forwardRef(({ recommended, children, className, onClick, ...props }, ref) => {
332
- const [loading, setLoading] = useState(false);
640
+ var PricingCardButton = React2.forwardRef(({ recommended, children, className, onClick, ...props }, ref) => {
641
+ const [loading, setLoading] = useState2(false);
333
642
  const handleClick = async (e) => {
334
643
  setLoading(true);
335
644
  try {
@@ -387,350 +696,37 @@ var RecommendedBadge = ({ recommended }) => {
387
696
  return /* @__PURE__ */ jsx2("div", { className: "au-bg-secondary au-absolute au-border au-text-muted-foreground au-text-sm au-font-medium lg:au-rounded-full au-px-3 lg:au-py-0.5 lg:au-top-4 lg:au-right-4 au-top-[-1px] au-right-[-1px] au-rounded-bl-lg", children: recommended });
388
697
  };
389
698
 
390
- // src/libraries/react/components/checkout-dialog/checkout-dialog-synced.tsx
699
+ // src/libraries/react/components/paywall-dialog/paywall-dialog-synced.tsx
391
700
  import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
392
- var formatCurrency = ({
393
- amount,
394
- currency
395
- }) => {
396
- return new Intl.NumberFormat("en-US", {
397
- style: "currency",
398
- currency
399
- }).format(amount);
400
- };
401
- function CheckoutDialog(params) {
402
- const { attach } = useCustomer();
403
- const [checkoutResult, setCheckoutResult] = useState2(params?.checkoutResult);
404
- useEffect(() => {
405
- if (params.checkoutResult) {
406
- setCheckoutResult(params.checkoutResult);
407
- }
408
- }, [params.checkoutResult]);
409
- const [loading, setLoading] = useState2(false);
410
- if (!checkoutResult) {
701
+ function PaywallDialog(params) {
702
+ const { data: preview } = usePaywall({
703
+ featureId: params?.featureId,
704
+ entityId: params?.entityId
705
+ });
706
+ if (!params || !preview) {
411
707
  return /* @__PURE__ */ jsx3(Fragment3, {});
412
708
  }
413
709
  const { open, setOpen } = params;
414
- const { title, message } = getCheckoutContent(checkoutResult);
415
- const isFree = checkoutResult?.product.properties?.is_free;
416
- const isPaid = isFree === false;
417
- return /* @__PURE__ */ jsx3(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs3(DialogContent, { className: "au-p-0 au-pt-4 au-gap-0 au-text-foreground au-text-sm", children: [
418
- /* @__PURE__ */ jsx3(DialogTitle, { className: "au-px-6 au-mb-1", children: title }),
419
- /* @__PURE__ */ jsx3("div", { className: "au-px-6 au-mt-1 au-mb-4 au-text-muted-foreground", children: message }),
420
- isPaid && checkoutResult && /* @__PURE__ */ jsx3(
421
- PriceInformation,
422
- {
423
- checkoutResult,
424
- setCheckoutResult
425
- }
426
- ),
427
- /* @__PURE__ */ jsx3(DialogFooter, { className: "au-flex au-flex-col sm:au-flex-row au-justify-between au-gap-x-4 au-py-2 au-pl-6 au-pr-3 au-bg-secondary au-border-t au-shadow-inner", children: /* @__PURE__ */ jsx3(
710
+ const { title, message } = getPaywallContent(preview);
711
+ return /* @__PURE__ */ jsx3(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs3(DialogContent, { className: "au-p-0 au-pt-4 au-gap-0 au-text-foreground au-overflow-hidden au-text-sm", children: [
712
+ /* @__PURE__ */ jsx3(DialogTitle, { className: cn("au-font-bold au-text-xl au-px-6"), children: title }),
713
+ /* @__PURE__ */ jsx3("div", { className: "au-px-6 au-my-2", children: message }),
714
+ /* @__PURE__ */ jsx3(DialogFooter, { className: "au-flex au-flex-col sm:au-flex-row au-justify-between au-gap-x-4 au-py-2 au-mt-4 au-pl-6 au-pr-3 au-bg-secondary au-border-t", children: /* @__PURE__ */ jsx3(
428
715
  Button,
429
716
  {
430
717
  size: "sm",
718
+ className: "au-font-medium au-shadow au-transition au-min-w-20",
431
719
  onClick: async () => {
432
- setLoading(true);
433
- const options = checkoutResult.options.map((option) => {
434
- return {
435
- featureId: option.feature_id,
436
- quantity: option.quantity
437
- };
438
- });
439
- await attach({
440
- productId: checkoutResult.product.id,
441
- options
442
- });
443
720
  setOpen(false);
444
- setLoading(false);
445
721
  },
446
- disabled: loading,
447
- className: "au-min-w-16 au-flex au-items-center au-gap-2",
448
- children: loading ? /* @__PURE__ */ jsx3(LoaderCircle, { className: "au-w-4 au-h-4 au-animate-spin" }) : /* @__PURE__ */ jsx3(Fragment3, { children: /* @__PURE__ */ jsx3("span", { className: "au-whitespace-nowrap au-flex au-gap-1", children: "Confirm" }) })
722
+ children: "Confirm"
449
723
  }
450
724
  ) })
451
725
  ] }) });
452
726
  }
453
- function PriceInformation({
454
- checkoutResult,
455
- setCheckoutResult
456
- }) {
457
- return /* @__PURE__ */ jsxs3("div", { className: "au-px-6 au-mb-4 au-flex au-flex-col au-gap-4", children: [
458
- /* @__PURE__ */ jsx3(
459
- ProductItems,
460
- {
461
- checkoutResult,
462
- setCheckoutResult
463
- }
464
- ),
465
- /* @__PURE__ */ jsxs3("div", { className: "au-flex au-flex-col au-gap-2", children: [
466
- checkoutResult?.has_prorations && checkoutResult.lines.length > 0 && /* @__PURE__ */ jsx3(CheckoutLines, { checkoutResult }),
467
- /* @__PURE__ */ jsx3(DueAmounts, { checkoutResult })
468
- ] })
469
- ] });
470
- }
471
- function DueAmounts({ checkoutResult }) {
472
- const { next_cycle, product } = checkoutResult;
473
- const nextCycleAtStr = next_cycle ? new Date(next_cycle.starts_at).toLocaleDateString() : void 0;
474
- const hasUsagePrice = product.items.some(
475
- (item) => item.usage_model === "pay_per_use"
476
- );
477
- const showNextCycle = next_cycle && next_cycle.total !== checkoutResult.total;
478
- return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-flex-col au-gap-1", children: [
479
- /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between", children: [
480
- /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsx3("p", { className: "au-font-medium au-text-md", children: "Total due today" }) }),
481
- /* @__PURE__ */ jsx3("p", { className: "au-font-medium au-text-md", children: formatCurrency({
482
- amount: checkoutResult?.total,
483
- currency: checkoutResult?.currency
484
- }) })
485
- ] }),
486
- showNextCycle && /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between au-text-muted-foreground", children: [
487
- /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsxs3("p", { className: "au-text-md", children: [
488
- "Due next cycle (",
489
- nextCycleAtStr,
490
- ")"
491
- ] }) }),
492
- /* @__PURE__ */ jsxs3("p", { className: "au-text-md", children: [
493
- formatCurrency({
494
- amount: next_cycle.total,
495
- currency: checkoutResult?.currency
496
- }),
497
- hasUsagePrice && /* @__PURE__ */ jsx3("span", { children: " + usage prices" })
498
- ] })
499
- ] })
500
- ] });
501
- }
502
- function ProductItems({
503
- checkoutResult,
504
- setCheckoutResult
505
- }) {
506
- const isUpdateQuantity = checkoutResult?.product.scenario === "active" && checkoutResult.product.properties.updateable;
507
- const isOneOff = checkoutResult?.product.properties.is_one_off;
508
- return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-flex-col au-gap-2", children: [
509
- /* @__PURE__ */ jsx3("p", { className: "au-text-sm au-font-medium", children: "Price" }),
510
- checkoutResult?.product.items.filter((item) => item.type !== "feature").map((item, index) => {
511
- if (item.usage_model == "prepaid") {
512
- return /* @__PURE__ */ jsx3(
513
- PrepaidItem,
514
- {
515
- item,
516
- checkoutResult,
517
- setCheckoutResult
518
- },
519
- index
520
- );
521
- }
522
- if (isUpdateQuantity) {
523
- return null;
524
- }
525
- return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between", children: [
526
- /* @__PURE__ */ jsx3("p", { className: "au-text-muted-foreground", children: item.feature ? item.feature.name : isOneOff ? "Price" : "Subscription" }),
527
- /* @__PURE__ */ jsxs3("p", { children: [
528
- item.display?.primary_text,
529
- " ",
530
- item.display?.secondary_text
531
- ] })
532
- ] }, index);
533
- })
534
- ] });
535
- }
536
- function CheckoutLines({ checkoutResult }) {
537
- return /* @__PURE__ */ jsx3(Accordion, { type: "single", collapsible: true, children: /* @__PURE__ */ jsxs3(AccordionItem, { value: "total", className: "au-border-b-0", children: [
538
- /* @__PURE__ */ jsx3(CustomAccordionTrigger, { className: "au-justify-between au-w-full au-my-0 au-py-0 au-border-none", children: /* @__PURE__ */ jsxs3("div", { className: "au-cursor-pointer au-flex au-items-center au-gap-1 au-w-full au-justify-end", children: [
539
- /* @__PURE__ */ jsx3("p", { className: "au-font-light au-text-muted-foreground", children: "View details" }),
540
- /* @__PURE__ */ jsx3(
541
- ChevronDown,
542
- {
543
- className: "au-text-muted-foreground au-mt-0.5 au-rotate-90 au-transition-transform au-duration-200 au-ease-in-out",
544
- size: 14
545
- }
546
- )
547
- ] }) }),
548
- /* @__PURE__ */ jsx3(AccordionContent, { className: "au-mt-2 au-mb-0 au-pb-2 au-flex au-flex-col au-gap-2", children: checkoutResult?.lines.filter((line) => line.amount != 0).map((line, index) => {
549
- return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between", children: [
550
- /* @__PURE__ */ jsx3("p", { className: "au-text-muted-foreground", children: line.description }),
551
- /* @__PURE__ */ jsx3("p", { className: "au-text-muted-foreground", children: new Intl.NumberFormat("en-US", {
552
- style: "currency",
553
- currency: checkoutResult?.currency
554
- }).format(line.amount) })
555
- ] }, index);
556
- }) })
557
- ] }) });
558
- }
559
- function CustomAccordionTrigger({
560
- className,
561
- children,
562
- ...props
563
- }) {
564
- return /* @__PURE__ */ jsx3(Header, { className: "au-flex", children: /* @__PURE__ */ jsx3(
565
- Trigger2,
566
- {
567
- "data-slot": "accordion-trigger",
568
- className: cn(
569
- "focus-visible:au-border-ring focus-visible:au-ring-ring/50 au-flex au-flex-1 au-items-start au-justify-between au-gap-4 au-rounded-md au-py-4 au-text-left au-text-sm au-font-medium au-transition-all au-outline-none focus-visible:au-ring-[3px] disabled:au-pointer-events-none disabled:au-opacity-50 [&[data-state=open]_svg]:au-rotate-0",
570
- className
571
- ),
572
- ...props,
573
- children
574
- }
575
- ) });
576
- }
577
- var PrepaidItem = ({
578
- item,
579
- checkoutResult,
580
- setCheckoutResult
581
- }) => {
582
- const { quantity = 0, billing_units: billingUnits = 1 } = item;
583
- const [quantityInput, setQuantityInput] = useState2(
584
- (quantity / billingUnits).toString()
585
- );
586
- const { checkout } = useCustomer();
587
- const [loading, setLoading] = useState2(false);
588
- const [open, setOpen] = useState2(false);
589
- const scenario = checkoutResult.product.scenario;
590
- const handleSave = async () => {
591
- setLoading(true);
592
- try {
593
- const newOptions = checkoutResult.options.filter((option) => option.feature_id !== item.feature_id).map((option) => {
594
- return {
595
- featureId: option.feature_id,
596
- quantity: option.quantity
597
- };
598
- });
599
- newOptions.push({
600
- featureId: item.feature_id,
601
- quantity: Number(quantityInput) * billingUnits
602
- });
603
- const { data, error } = await checkout({
604
- productId: checkoutResult.product.id,
605
- options: newOptions,
606
- dialog: CheckoutDialog
607
- });
608
- if (error) {
609
- console.error(error);
610
- return;
611
- }
612
- setCheckoutResult(data);
613
- } catch (error) {
614
- console.error(error);
615
- } finally {
616
- setLoading(false);
617
- setOpen(false);
618
- }
619
- };
620
- const disableSelection = scenario === "renew";
621
- return /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between", children: [
622
- /* @__PURE__ */ jsxs3("div", { className: "au-flex au-gap-2", children: [
623
- /* @__PURE__ */ jsx3("p", { className: "au-text-muted-foreground", children: item.feature?.name }),
624
- /* @__PURE__ */ jsxs3(Popover, { open, onOpenChange: setOpen, children: [
625
- /* @__PURE__ */ jsxs3(
626
- PopoverTrigger,
627
- {
628
- className: cn(
629
- "au-text-muted-foreground au-text-xs au-px-1 au-py-0.5 au-rounded-md au-flex au-items-center au-gap-1 au-bg-accent/80",
630
- disableSelection !== true && "hover:au-bg-accent hover:au-text-foreground"
631
- ),
632
- disabled: disableSelection,
633
- children: [
634
- "Qty: ",
635
- quantity,
636
- /* @__PURE__ */ jsx3(ChevronDown, { size: 12 })
637
- ]
638
- }
639
- ),
640
- /* @__PURE__ */ jsxs3(
641
- PopoverContent,
642
- {
643
- align: "start",
644
- className: "au-w-80 au-text-sm au-p-4 au-pt-3 au-flex au-flex-col au-gap-4",
645
- children: [
646
- /* @__PURE__ */ jsxs3("div", { className: "au-flex au-flex-col au-gap-1", children: [
647
- /* @__PURE__ */ jsx3("p", { className: "au-text-sm au-font-medium", children: item.feature?.name }),
648
- /* @__PURE__ */ jsxs3("p", { className: "au-text-muted-foreground", children: [
649
- item.display?.primary_text,
650
- " ",
651
- item.display?.secondary_text
652
- ] })
653
- ] }),
654
- /* @__PURE__ */ jsxs3("div", { className: "au-flex au-justify-between au-items-end", children: [
655
- /* @__PURE__ */ jsxs3("div", { className: "au-flex au-gap-2 au-items-center", children: [
656
- /* @__PURE__ */ jsx3(
657
- Input,
658
- {
659
- className: "au-h-7 au-w-16 focus:!au-ring-2",
660
- value: quantityInput,
661
- onChange: (e) => setQuantityInput(e.target.value)
662
- }
663
- ),
664
- /* @__PURE__ */ jsxs3("p", { className: "au-text-muted-foreground", children: [
665
- billingUnits > 1 && `x ${billingUnits} `,
666
- item.feature?.name
667
- ] })
668
- ] }),
669
- /* @__PURE__ */ jsx3(
670
- Button,
671
- {
672
- onClick: handleSave,
673
- className: "au-w-14 !au-h-7 au-text-sm au-items-center au-bg-white au-text-foreground au-shadow-sm au-border au-border-zinc-200 hover:au-bg-zinc-100",
674
- disabled: loading,
675
- children: loading ? /* @__PURE__ */ jsx3(LoaderCircle, { className: "au-text-muted-foreground au-animate-spin !au-w-4 !au-h-4" }) : "Save"
676
- }
677
- )
678
- ] })
679
- ]
680
- }
681
- )
682
- ] })
683
- ] }),
684
- /* @__PURE__ */ jsxs3("p", { children: [
685
- item.display?.primary_text,
686
- " ",
687
- item.display?.secondary_text
688
- ] })
689
- ] });
690
- };
691
- var PriceItem = ({
692
- children,
693
- className,
694
- ...props
695
- }) => {
696
- return /* @__PURE__ */ jsx3(
697
- "div",
698
- {
699
- className: cn(
700
- "au-flex au-flex-col au-pb-4 sm:au-pb-0 au-gap-1 sm:au-flex-row au-justify-between sm:au-h-7 sm:au-gap-2 sm:au-items-center",
701
- className
702
- ),
703
- ...props,
704
- children
705
- }
706
- );
707
- };
708
- var PricingDialogButton = ({
709
- children,
710
- size,
711
- onClick,
712
- disabled,
713
- className
714
- }) => {
715
- return /* @__PURE__ */ jsxs3(
716
- Button,
717
- {
718
- onClick,
719
- disabled,
720
- size,
721
- className: cn(className, "au-shadow-sm au-shadow-stone-400"),
722
- children: [
723
- children,
724
- /* @__PURE__ */ jsx3(ArrowRight, { className: "!au-h-3" })
725
- ]
726
- }
727
- );
728
- };
729
727
 
730
728
  export {
731
- CheckoutDialog,
732
- PriceItem,
733
- PricingDialogButton,
729
+ PaywallDialog,
734
730
  PricingTable,
735
731
  usePricingTableContext,
736
732
  PricingTableContainer,
@@ -739,5 +735,7 @@ export {
739
735
  PricingCardButton,
740
736
  AnnualSwitch,
741
737
  RecommendedBadge,
742
- PaywallDialog
738
+ CheckoutDialog,
739
+ PriceItem,
740
+ PricingDialogButton
743
741
  };