autumn-js 0.0.80 → 0.0.82

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 (207) hide show
  1. package/dist/libraries/backend/better-auth.js +18 -2
  2. package/dist/libraries/backend/better-auth.mjs +7 -7
  3. package/dist/libraries/backend/{chunk-6YOFMAEQ.mjs → chunk-52OTZ4SQ.mjs} +16 -6
  4. package/dist/libraries/backend/{chunk-HDGYVYU5.mjs → chunk-A46IKTLH.mjs} +1 -1
  5. package/dist/libraries/backend/{chunk-7NHMUGUP.mjs → chunk-DG3FZZQH.mjs} +1 -1
  6. package/dist/libraries/backend/{chunk-MIWNIVVB.mjs → chunk-J3QM5KFT.mjs} +1 -1
  7. package/dist/libraries/backend/{chunk-PCYIWHGN.mjs → chunk-UJQBHXII.mjs} +1 -1
  8. package/dist/libraries/backend/{chunk-3VWJMYUQ.mjs → chunk-VCEQ3QBX.mjs} +8 -2
  9. package/dist/libraries/backend/{chunk-CPLIRBCA.mjs → chunk-WDRHQJKV.mjs} +1 -1
  10. package/dist/libraries/backend/express.d.mts +1 -1
  11. package/dist/libraries/backend/express.d.ts +1 -1
  12. package/dist/libraries/backend/express.js +18 -2
  13. package/dist/libraries/backend/express.mjs +7 -7
  14. package/dist/libraries/backend/fastify.js +18 -2
  15. package/dist/libraries/backend/fastify.mjs +7 -7
  16. package/dist/libraries/backend/hono.js +18 -2
  17. package/dist/libraries/backend/hono.mjs +7 -7
  18. package/dist/libraries/backend/next.js +18 -2
  19. package/dist/libraries/backend/next.mjs +7 -7
  20. package/dist/libraries/backend/react-router.js +18 -2
  21. package/dist/libraries/backend/react-router.mjs +7 -7
  22. package/dist/libraries/backend/{referralTypes-3L_pJkT7.d.ts → referralTypes-BZ4WOVK5.d.ts} +2 -0
  23. package/dist/libraries/backend/{referralTypes-BOtccenE.d.mts → referralTypes-C6ao6j-_.d.mts} +2 -0
  24. package/dist/libraries/backend/remix_dep.js +18 -2
  25. package/dist/libraries/backend/remix_dep.mjs +7 -7
  26. package/dist/libraries/backend/routes/backendRouter.js +18 -2
  27. package/dist/libraries/backend/routes/backendRouter.mjs +7 -7
  28. package/dist/libraries/backend/routes/entityRoutes.js +8 -2
  29. package/dist/libraries/backend/routes/entityRoutes.mjs +3 -3
  30. package/dist/libraries/backend/routes/genRoutes.js +8 -2
  31. package/dist/libraries/backend/routes/genRoutes.mjs +3 -3
  32. package/dist/libraries/backend/routes/productRoutes.js +8 -2
  33. package/dist/libraries/backend/routes/productRoutes.mjs +3 -3
  34. package/dist/libraries/backend/routes/referralRoutes.js +8 -2
  35. package/dist/libraries/backend/routes/referralRoutes.mjs +3 -3
  36. package/dist/libraries/backend/supabase.js +18 -2
  37. package/dist/libraries/backend/supabase.mjs +7 -7
  38. package/dist/libraries/backend/tanstack.js +18 -2
  39. package/dist/libraries/backend/tanstack.mjs +7 -7
  40. package/dist/libraries/backend/utils/backendRes.js +8 -2
  41. package/dist/libraries/backend/utils/backendRes.mjs +1 -1
  42. package/dist/libraries/backend/utils/withAuth.d.mts +1 -1
  43. package/dist/libraries/backend/utils/withAuth.d.ts +1 -1
  44. package/dist/libraries/backend/utils/withAuth.js +8 -2
  45. package/dist/libraries/backend/utils/withAuth.mjs +2 -2
  46. package/dist/libraries/react/AutumnContext.d.mts +4 -4
  47. package/dist/libraries/react/AutumnContext.d.ts +4 -4
  48. package/dist/libraries/react/AutumnContext.js +83 -5
  49. package/dist/libraries/react/AutumnContext.mjs +6 -6
  50. package/dist/libraries/react/BaseAutumnProvider.d.mts +4 -4
  51. package/dist/libraries/react/BaseAutumnProvider.d.ts +4 -4
  52. package/dist/libraries/react/BaseAutumnProvider.js +229 -5672
  53. package/dist/libraries/react/BaseAutumnProvider.mjs +11 -21
  54. package/dist/libraries/react/{ReactAutumnClient-B-g4zQsF.d.mts → ReactAutumnClient-Cj2h9TXJ.d.mts} +15 -5
  55. package/dist/libraries/react/{ReactAutumnClient-BUIEn-KV.d.ts → ReactAutumnClient-DS-MPWXt.d.ts} +15 -5
  56. package/dist/libraries/react/ReactAutumnProvider.d.mts +1 -1
  57. package/dist/libraries/react/ReactAutumnProvider.d.ts +1 -1
  58. package/dist/libraries/react/ReactAutumnProvider.js +232 -5678
  59. package/dist/libraries/react/ReactAutumnProvider.mjs +12 -21
  60. package/dist/libraries/react/chunk-6ULRUGQO.mjs +20 -0
  61. package/dist/libraries/react/chunk-CQMTU2M4.mjs +170 -0
  62. package/dist/libraries/react/chunk-EWMKQDQ6.mjs +17 -0
  63. package/dist/libraries/react/chunk-GEIECHWI.mjs +77 -0
  64. package/dist/libraries/react/{chunk-JYOLY75Q.mjs → chunk-JOY6LN3M.mjs} +2 -2
  65. package/dist/libraries/react/chunk-JVCOY7ZL.mjs +22 -0
  66. package/dist/libraries/react/chunk-KVGD37VB.mjs +85 -0
  67. package/dist/libraries/react/chunk-L55GLFAX.mjs +83 -0
  68. package/dist/libraries/react/{chunk-WYADGMAH.mjs → chunk-MH2YTNJL.mjs} +1 -1
  69. package/dist/libraries/react/{chunk-3OBQBUE2.mjs → chunk-S4VDT54B.mjs} +2 -2
  70. package/dist/libraries/react/chunk-SCT4E6YW.mjs +17 -0
  71. package/dist/libraries/react/{chunk-RRXCG32N.mjs → chunk-UDRQNZZS.mjs} +255 -48
  72. package/dist/libraries/react/chunk-UO2PX7P3.mjs +46 -0
  73. package/dist/libraries/react/chunk-W2ZI3EI4.mjs +569 -0
  74. package/dist/libraries/react/client/ReactAutumnClient.d.mts +4 -4
  75. package/dist/libraries/react/client/ReactAutumnClient.d.ts +4 -4
  76. package/dist/libraries/react/client/ReactAutumnClient.js +83 -5
  77. package/dist/libraries/react/client/ReactAutumnClient.mjs +5 -5
  78. package/dist/libraries/react/client/clientCompMethods.d.mts +4 -4
  79. package/dist/libraries/react/client/clientCompMethods.d.ts +4 -4
  80. package/dist/libraries/react/client/clientCusMethods.d.mts +4 -4
  81. package/dist/libraries/react/client/clientCusMethods.d.ts +4 -4
  82. package/dist/libraries/react/client/clientEntityMethods.d.mts +4 -4
  83. package/dist/libraries/react/client/clientEntityMethods.d.ts +4 -4
  84. package/dist/libraries/react/client/clientGenMethods.d.mts +4 -4
  85. package/dist/libraries/react/client/clientGenMethods.d.ts +4 -4
  86. package/dist/libraries/react/client/clientProdMethods.d.mts +4 -4
  87. package/dist/libraries/react/client/clientProdMethods.d.ts +4 -4
  88. package/dist/libraries/react/client/clientReferralMethods.d.mts +4 -4
  89. package/dist/libraries/react/client/clientReferralMethods.d.ts +4 -4
  90. package/dist/libraries/react/components/attach-dialog/attach-dialog-synced.d.mts +1 -1
  91. package/dist/libraries/react/components/attach-dialog/attach-dialog-synced.d.ts +1 -1
  92. package/dist/libraries/react/components/attach-dialog/attach-dialog-synced.js +95 -18
  93. package/dist/libraries/react/components/attach-dialog/attach-dialog-synced.mjs +20 -12
  94. package/dist/libraries/react/components/attach-dialog/lib/attach-content.d.mts +1 -1
  95. package/dist/libraries/react/components/attach-dialog/lib/attach-content.d.ts +1 -1
  96. package/dist/libraries/react/components/check-dialog/check-dialog-synced.d.mts +1 -1
  97. package/dist/libraries/react/components/check-dialog/check-dialog-synced.d.ts +1 -1
  98. package/dist/libraries/react/components/check-dialog/lib/check-content.d.mts +1 -1
  99. package/dist/libraries/react/components/check-dialog/lib/check-content.d.ts +1 -1
  100. package/dist/libraries/react/components/pricing-table/pricing-table-synced.d.mts +1 -1
  101. package/dist/libraries/react/components/pricing-table/pricing-table-synced.d.ts +1 -1
  102. package/dist/libraries/react/components/pricing-table/pricing-table-synced.js +2987 -2910
  103. package/dist/libraries/react/components/pricing-table/pricing-table-synced.mjs +20 -12
  104. package/dist/libraries/react/{cusTypes-DSlkhuov.d.ts → cusTypes-CO4FwQ_s.d.mts} +3 -1
  105. package/dist/libraries/react/{cusTypes-DSlkhuov.d.mts → cusTypes-CO4FwQ_s.d.ts} +3 -1
  106. package/dist/libraries/react/{entTypes-Rpnetevb.d.mts → entTypes-DPTZOorv.d.mts} +1 -1
  107. package/dist/libraries/react/{entTypes-CcB_hEh5.d.ts → entTypes-UxZ5bRqE.d.ts} +1 -1
  108. package/dist/libraries/react/errorUtils/logAuthError.d.mts +1 -6
  109. package/dist/libraries/react/errorUtils/logAuthError.d.ts +1 -6
  110. package/dist/libraries/react/errorUtils/logAuthError.js +10 -490
  111. package/dist/libraries/react/errorUtils/logAuthError.mjs +2 -15
  112. package/dist/libraries/react/hooks/handleAllowed.d.mts +2 -2
  113. package/dist/libraries/react/hooks/handleAllowed.d.ts +2 -2
  114. package/dist/libraries/react/hooks/useAutumn.d.mts +2 -2
  115. package/dist/libraries/react/hooks/useAutumn.d.ts +2 -2
  116. package/dist/libraries/react/hooks/useAutumn.js +219 -5779
  117. package/dist/libraries/react/hooks/useAutumn.mjs +9 -22
  118. package/dist/libraries/react/hooks/useAutumnBase.d.mts +4 -4
  119. package/dist/libraries/react/hooks/useAutumnBase.d.ts +4 -4
  120. package/dist/libraries/react/hooks/useAutumnBase.js +215 -5775
  121. package/dist/libraries/react/hooks/useAutumnBase.mjs +8 -22
  122. package/dist/libraries/react/hooks/useCustomer.d.mts +4 -4
  123. package/dist/libraries/react/hooks/useCustomer.d.ts +4 -4
  124. package/dist/libraries/react/hooks/useCustomer.js +223 -5667
  125. package/dist/libraries/react/hooks/useCustomer.mjs +11 -22
  126. package/dist/libraries/react/hooks/useCustomerBase.d.mts +4 -4
  127. package/dist/libraries/react/hooks/useCustomerBase.d.ts +4 -4
  128. package/dist/libraries/react/hooks/useCustomerBase.js +223 -5675
  129. package/dist/libraries/react/hooks/useCustomerBase.mjs +10 -22
  130. package/dist/libraries/react/hooks/useEntity.d.mts +3 -3
  131. package/dist/libraries/react/hooks/useEntity.d.ts +3 -3
  132. package/dist/libraries/react/hooks/useEntity.js +219 -5729
  133. package/dist/libraries/react/hooks/useEntity.mjs +11 -22
  134. package/dist/libraries/react/hooks/useEntityBase.d.mts +4 -4
  135. package/dist/libraries/react/hooks/useEntityBase.d.ts +4 -4
  136. package/dist/libraries/react/hooks/useEntityBase.js +219 -5729
  137. package/dist/libraries/react/hooks/useEntityBase.mjs +10 -22
  138. package/dist/libraries/react/hooks/usePricingTable.d.mts +1 -1
  139. package/dist/libraries/react/hooks/usePricingTable.d.ts +1 -1
  140. package/dist/libraries/react/hooks/usePricingTable.js +83 -5
  141. package/dist/libraries/react/hooks/usePricingTable.mjs +8 -8
  142. package/dist/libraries/react/hooks/usePricingTableBase.d.mts +4 -4
  143. package/dist/libraries/react/hooks/usePricingTableBase.d.ts +4 -4
  144. package/dist/libraries/react/hooks/usePricingTableBase.js +83 -5
  145. package/dist/libraries/react/hooks/usePricingTableBase.mjs +7 -7
  146. package/dist/libraries/react/hooks/useProductsBase.js +83 -5
  147. package/dist/libraries/react/hooks/useProductsBase.mjs +6 -6
  148. package/dist/libraries/react/index.d.ts +2 -0
  149. package/dist/libraries/react/index.js +5521 -5450
  150. package/dist/libraries/react/index.mjs +5519 -5448
  151. package/dist/libraries/react/{response-CTqlSAVK.d.mts → response-CxtkXvb4.d.mts} +2 -2
  152. package/dist/libraries/react/{response-BKKi_PDD.d.ts → response-Z4Yeokd8.d.ts} +2 -2
  153. package/dist/next/{AutumnProvider-CGdXoZNQ.d.mts → AutumnProvider-DPcEuE_Q.d.mts} +2 -0
  154. package/dist/next/{AutumnProvider-CGdXoZNQ.d.ts → AutumnProvider-DPcEuE_Q.d.ts} +2 -0
  155. package/dist/next/AutumnProvider.d.mts +1 -1
  156. package/dist/next/AutumnProvider.d.ts +1 -1
  157. package/dist/next/client/NextAutumnClient.d.mts +15 -5
  158. package/dist/next/client/NextAutumnClient.d.ts +15 -5
  159. package/dist/next/client/NextAutumnProvider.d.mts +1 -1
  160. package/dist/next/client/NextAutumnProvider.d.ts +1 -1
  161. package/dist/next/client/{clientGenTypes-HDbUC8f6.d.ts → clientGenTypes-CAv4hwb4.d.ts} +1 -1
  162. package/dist/next/client/{clientGenTypes-BHrxzZi_.d.mts → clientGenTypes-Dlpw9wy_.d.mts} +1 -1
  163. package/dist/next/client/clientUtils.d.mts +2 -2
  164. package/dist/next/client/clientUtils.d.ts +2 -2
  165. package/dist/next/client/{cusTypes-CSbB7Wu9.d.mts → cusTypes-CJI8rdlY.d.mts} +2 -0
  166. package/dist/next/client/{cusTypes-CSbB7Wu9.d.ts → cusTypes-CJI8rdlY.d.ts} +2 -0
  167. package/dist/next/client/{entTypes-B3R2yjLW.d.ts → entTypes-CqHWTcCX.d.ts} +1 -1
  168. package/dist/next/client/{entTypes-6xEkbn32.d.mts → entTypes-okM0aeOM.d.mts} +1 -1
  169. package/dist/next/client/hooks/useAutumn.d.mts +2 -2
  170. package/dist/next/client/hooks/useAutumn.d.ts +2 -2
  171. package/dist/next/client/hooks/useCustomer.d.mts +3 -3
  172. package/dist/next/client/hooks/useCustomer.d.ts +3 -3
  173. package/dist/next/client/hooks/useEntity.d.mts +3 -3
  174. package/dist/next/client/hooks/useEntity.d.ts +3 -3
  175. package/dist/next/client/hooks/usePricingTable.d.mts +1 -1
  176. package/dist/next/client/hooks/usePricingTable.d.ts +1 -1
  177. package/dist/next/client/types.d.mts +2 -2
  178. package/dist/next/client/types.d.ts +2 -2
  179. package/dist/next/index.d.mts +14 -4
  180. package/dist/next/index.d.ts +14 -4
  181. package/dist/next/server/auth/withNextAuth.d.mts +1 -1
  182. package/dist/next/server/auth/withNextAuth.d.ts +1 -1
  183. package/dist/next/server/componentActions.d.mts +1 -1
  184. package/dist/next/server/componentActions.d.ts +1 -1
  185. package/dist/next/server/cusActions.d.mts +1 -1
  186. package/dist/next/server/cusActions.d.ts +1 -1
  187. package/dist/next/server/{cusTypes-ASrCF4fa.d.mts → cusTypes-DuSwXVmp.d.mts} +2 -0
  188. package/dist/next/server/{cusTypes-ASrCF4fa.d.ts → cusTypes-DuSwXVmp.d.ts} +2 -0
  189. package/dist/next/server/genActions.d.mts +1 -1
  190. package/dist/next/server/genActions.d.ts +1 -1
  191. package/dist/sdk/index.d.mts +4 -1
  192. package/dist/sdk/index.d.ts +4 -1
  193. package/dist/sdk/index.js +8 -2
  194. package/dist/sdk/index.mjs +8 -2
  195. package/dist/utils/encryptUtils.js +8 -2
  196. package/dist/utils/encryptUtils.mjs +8 -2
  197. package/package.json +1 -1
  198. package/dist/libraries/react/BaseAutumnProvider.css +0 -1264
  199. package/dist/libraries/react/ReactAutumnProvider.css +0 -1264
  200. package/dist/libraries/react/chunk-XPGX7SQG.mjs +0 -1014
  201. package/dist/libraries/react/chunk-Y6UVL46W.mjs +0 -152
  202. package/dist/libraries/react/hooks/useAutumn.css +0 -1264
  203. package/dist/libraries/react/hooks/useAutumnBase.css +0 -1264
  204. package/dist/libraries/react/hooks/useCustomer.css +0 -1264
  205. package/dist/libraries/react/hooks/useCustomerBase.css +0 -1264
  206. package/dist/libraries/react/hooks/useEntity.css +0 -1264
  207. package/dist/libraries/react/hooks/useEntityBase.css +0 -1264
@@ -2,33 +2,24 @@
2
2
 
3
3
  import {
4
4
  ReactAutumnProvider
5
- } from "./chunk-XPGX7SQG.mjs";
6
- import "./chunk-BCMBFJ7E.mjs";
7
- import "./chunk-QBBE72EF.mjs";
8
- import "./chunk-CMO5LYYU.mjs";
9
- import "./chunk-OWFX3JFF.mjs";
10
- import "./chunk-27OTS3Q5.mjs";
11
- import "./chunk-MY2ODATB.mjs";
12
- import "./chunk-P2O4LZFD.mjs";
13
- import "./chunk-5FZ7IV6P.mjs";
14
- import "./chunk-FPI3PLEL.mjs";
15
- import "./chunk-FEFGYFXQ.mjs";
16
- import "./chunk-4J6OC4ZQ.mjs";
5
+ } from "./chunk-UO2PX7P3.mjs";
6
+ import "./chunk-KVGD37VB.mjs";
17
7
  import "./chunk-4QPHNIQ7.mjs";
18
- import "./chunk-3OBQBUE2.mjs";
19
- import "./chunk-JYOLY75Q.mjs";
20
- import "./chunk-WYADGMAH.mjs";
21
- import "./chunk-Y6UVL46W.mjs";
8
+ import "./chunk-GEIECHWI.mjs";
9
+ import "./chunk-JFXBUWKA.mjs";
10
+ import "./chunk-CQMTU2M4.mjs";
11
+ import "./chunk-JOY6LN3M.mjs";
12
+ import "./chunk-MH2YTNJL.mjs";
13
+ import "./chunk-UDRQNZZS.mjs";
14
+ import "./chunk-YUV2Y2RW.mjs";
15
+ import "./chunk-3EYF7OI5.mjs";
16
+ import "./chunk-JVCOY7ZL.mjs";
17
+ import "./chunk-CIBQ4BJU.mjs";
22
18
  import "./chunk-NZ5PEXT2.mjs";
23
19
  import "./chunk-TGX6UKKS.mjs";
24
20
  import "./chunk-V5PKOA5A.mjs";
25
21
  import "./chunk-JNM4BLTM.mjs";
26
- import "./chunk-YUV2Y2RW.mjs";
27
- import "./chunk-3EYF7OI5.mjs";
28
22
  import "./chunk-KQT5G3HT.mjs";
29
- import "./chunk-RRXCG32N.mjs";
30
- import "./chunk-CIBQ4BJU.mjs";
31
- import "./chunk-JFXBUWKA.mjs";
32
23
  export {
33
24
  ReactAutumnProvider
34
25
  };
@@ -0,0 +1,20 @@
1
+ "use client";
2
+
3
+ import {
4
+ useCustomerBase
5
+ } from "./chunk-GEIECHWI.mjs";
6
+ import {
7
+ AutumnContext
8
+ } from "./chunk-MH2YTNJL.mjs";
9
+
10
+ // src/libraries/react/hooks/useCustomer.tsx
11
+ var useCustomer = (params) => {
12
+ return useCustomerBase({
13
+ params,
14
+ AutumnContext
15
+ });
16
+ };
17
+
18
+ export {
19
+ useCustomer
20
+ };
@@ -0,0 +1,170 @@
1
+ "use client";
2
+
3
+ import {
4
+ usePricingTableBase
5
+ } from "./chunk-JOY6LN3M.mjs";
6
+ import {
7
+ useAutumnContext
8
+ } from "./chunk-MH2YTNJL.mjs";
9
+
10
+ // src/libraries/react/hooks/useAutumnBase.tsx
11
+ var useAutumnBase = ({
12
+ AutumnContext
13
+ }) => {
14
+ const context = useAutumnContext({ AutumnContext, name: "useAutumn" });
15
+ const { attachDialog, paywallDialog } = context;
16
+ const client = context.client;
17
+ const { refetch: refetchPricingTable } = usePricingTableBase({
18
+ AutumnContext
19
+ });
20
+ let {
21
+ open: attachOpen,
22
+ setProps: setAttachProps,
23
+ setOpen: setAttachOpen,
24
+ setComponent: setAttachComponent
25
+ } = attachDialog;
26
+ let {
27
+ setProps: setCheckProps,
28
+ setOpen: setCheckOpen,
29
+ setComponent: setPaywallComponent
30
+ } = paywallDialog;
31
+ const attachWithoutDialog = async (params) => {
32
+ const result = await client.attach(params);
33
+ if (result.error) {
34
+ return result;
35
+ }
36
+ let data = result.data;
37
+ if (data?.checkout_url && typeof window !== "undefined") {
38
+ if (params.openInNewTab) {
39
+ window.open(data.checkout_url, "_blank");
40
+ } else {
41
+ window.location.href = data.checkout_url;
42
+ }
43
+ }
44
+ await refetchPricingTable();
45
+ if (setAttachOpen) {
46
+ setAttachOpen(false);
47
+ }
48
+ return result;
49
+ };
50
+ const attachWithDialog = async (params) => {
51
+ let { dialog, ...rest } = params;
52
+ const { productId, entityId, entityData } = params;
53
+ const checkRes = await client.check({
54
+ productId,
55
+ entityId,
56
+ entityData,
57
+ withPreview: true
58
+ });
59
+ if (checkRes.error) {
60
+ return checkRes;
61
+ }
62
+ let preview = checkRes.data.preview;
63
+ if (!preview) {
64
+ return await attachWithoutDialog(rest);
65
+ } else {
66
+ setAttachProps({ preview, attachParams: rest });
67
+ setAttachOpen(true);
68
+ }
69
+ return checkRes;
70
+ };
71
+ const attach = async (params) => {
72
+ const { dialog, openInNewTab } = params;
73
+ let finalDialog = dialog;
74
+ if (finalDialog && !attachOpen) {
75
+ setAttachComponent(finalDialog);
76
+ return await attachWithDialog(params);
77
+ }
78
+ return await attachWithoutDialog(params);
79
+ };
80
+ const cancel = async (params) => {
81
+ const res = await client.cancel(params);
82
+ if (res.error) {
83
+ return res;
84
+ }
85
+ return res;
86
+ };
87
+ const check = async (params) => {
88
+ let { dialog, withPreview } = params;
89
+ if (dialog) {
90
+ setPaywallComponent(dialog);
91
+ }
92
+ const res = await client.check({
93
+ ...params,
94
+ withPreview: withPreview || dialog ? true : false
95
+ });
96
+ if (res.error) {
97
+ return res;
98
+ }
99
+ let data = res.data;
100
+ if (data && data.preview && dialog) {
101
+ let preview = data.preview;
102
+ setCheckProps({ preview });
103
+ setCheckOpen(true);
104
+ }
105
+ return res;
106
+ };
107
+ const track = async (params) => {
108
+ const res = await client.track(params);
109
+ if (res.error) {
110
+ return res;
111
+ }
112
+ return res;
113
+ };
114
+ const openBillingPortal = async (params) => {
115
+ let defaultParams = {
116
+ openInNewTab: false
117
+ };
118
+ let finalParams = {
119
+ ...defaultParams,
120
+ ...params
121
+ };
122
+ const res = await client.openBillingPortal(finalParams);
123
+ if (res.error) {
124
+ return res;
125
+ }
126
+ let data = res.data;
127
+ if (data?.url && typeof window !== "undefined") {
128
+ if (finalParams.openInNewTab) {
129
+ window.open(data.url, "_blank");
130
+ } else {
131
+ window.open(data.url, "_self");
132
+ }
133
+ return res;
134
+ } else {
135
+ return res;
136
+ }
137
+ };
138
+ const setupPayment = async (params) => {
139
+ let defaultParams = {
140
+ openInNewTab: false
141
+ };
142
+ let finalParams = {
143
+ ...defaultParams,
144
+ ...params || {}
145
+ };
146
+ const res = await client.setupPayment(finalParams);
147
+ if (res.data?.url && typeof window !== "undefined") {
148
+ if (finalParams.openInNewTab) {
149
+ window.open(res.data.url, "_blank");
150
+ } else {
151
+ window.open(res.data.url, "_self");
152
+ }
153
+ return res;
154
+ } else {
155
+ return res;
156
+ }
157
+ };
158
+ return {
159
+ attach,
160
+ check,
161
+ track,
162
+ cancel,
163
+ openBillingPortal,
164
+ setupPayment
165
+ };
166
+ };
167
+
168
+ export {
169
+ useAutumnBase
170
+ };
@@ -0,0 +1,17 @@
1
+ "use client";
2
+
3
+ import {
4
+ useAutumnBase
5
+ } from "./chunk-CQMTU2M4.mjs";
6
+ import {
7
+ AutumnContext
8
+ } from "./chunk-MH2YTNJL.mjs";
9
+
10
+ // src/libraries/react/hooks/useAutumn.tsx
11
+ var useAutumn = () => {
12
+ return useAutumnBase({ AutumnContext });
13
+ };
14
+
15
+ export {
16
+ useAutumn
17
+ };
@@ -0,0 +1,77 @@
1
+ "use client";
2
+
3
+ import {
4
+ handleAllowed
5
+ } from "./chunk-JFXBUWKA.mjs";
6
+ import {
7
+ useAutumnBase
8
+ } from "./chunk-CQMTU2M4.mjs";
9
+ import {
10
+ useAutumnContext
11
+ } from "./chunk-MH2YTNJL.mjs";
12
+
13
+ // src/libraries/react/hooks/useCustomerBase.tsx
14
+ import useSWR from "swr";
15
+ var emptyDefaultFunctions = {
16
+ attach: "",
17
+ check: "",
18
+ track: "",
19
+ cancel: "",
20
+ openBillingPortal: "",
21
+ setupPayment: ""
22
+ };
23
+ var useCustomerBase = ({
24
+ params,
25
+ AutumnContext,
26
+ client
27
+ }) => {
28
+ const queryKey = ["customer", params?.expand];
29
+ let context;
30
+ if (AutumnContext) {
31
+ context = useAutumnContext({ AutumnContext, name: "useCustomer" });
32
+ }
33
+ if (!client) {
34
+ client = context.client;
35
+ }
36
+ const fetchCustomer = async () => {
37
+ const { data, error: error2 } = await client.createCustomer({
38
+ errorOnNotFound: params?.errorOnNotFound,
39
+ expand: params?.expand
40
+ });
41
+ if (error2) {
42
+ throw error2;
43
+ }
44
+ if (!data) {
45
+ return null;
46
+ }
47
+ return data;
48
+ };
49
+ const { data: customer, error, isLoading, mutate } = useSWR(queryKey, fetchCustomer, {
50
+ fallbackData: null,
51
+ onErrorRetry: (error2, key, config) => {
52
+ if (error2.code == "entity_not_found") {
53
+ return false;
54
+ }
55
+ return true;
56
+ }
57
+ });
58
+ let autumnFunctions = emptyDefaultFunctions;
59
+ if (AutumnContext) {
60
+ autumnFunctions = useAutumnBase({ AutumnContext });
61
+ }
62
+ return {
63
+ customer: error ? null : customer,
64
+ isLoading,
65
+ error,
66
+ refetch: mutate,
67
+ ...autumnFunctions,
68
+ createEntity: client.entities.create,
69
+ createReferralCode: client.referrals.createCode,
70
+ redeemReferralCode: client.referrals.redeemCode,
71
+ allowed: (params2) => handleAllowed({ customer, params: params2 })
72
+ };
73
+ };
74
+
75
+ export {
76
+ useCustomerBase
77
+ };
@@ -2,10 +2,10 @@
2
2
 
3
3
  import {
4
4
  useAutumnContext
5
- } from "./chunk-WYADGMAH.mjs";
5
+ } from "./chunk-MH2YTNJL.mjs";
6
6
  import {
7
7
  AutumnError
8
- } from "./chunk-RRXCG32N.mjs";
8
+ } from "./chunk-UDRQNZZS.mjs";
9
9
 
10
10
  // src/libraries/react/hooks/usePricingTableBase.tsx
11
11
  import useSWR from "swr";
@@ -0,0 +1,22 @@
1
+ "use client";
2
+
3
+
4
+ // src/libraries/react/errorUtils/logAuthError.ts
5
+ var logAuthError = async (response) => {
6
+ if (response.status === 401) {
7
+ let clonedResponse = response.clone();
8
+ let data = await clonedResponse.json();
9
+ if (data.message.includes("Missing authorization header")) {
10
+ console.error(`[Autumn] Missing authorization header.
11
+
12
+ Use the getBearerToken prop in <AutumnProvider /> to set the authorization header.
13
+ https://docs.useautumn.com/quickstart/quickstart#5-set-up-autumnprovider`);
14
+ return true;
15
+ }
16
+ }
17
+ return false;
18
+ };
19
+
20
+ export {
21
+ logAuthError
22
+ };
@@ -0,0 +1,85 @@
1
+ "use client";
2
+
3
+ import {
4
+ useDialog
5
+ } from "./chunk-4QPHNIQ7.mjs";
6
+ import {
7
+ useCustomerBase
8
+ } from "./chunk-GEIECHWI.mjs";
9
+
10
+ // src/libraries/react/BaseAutumnProvider.tsx
11
+ import { useState } from "react";
12
+ import { jsx, jsxs } from "react/jsx-runtime";
13
+ function BaseAutumnProvider({
14
+ client,
15
+ children,
16
+ AutumnContext,
17
+ disableDialogs = false
18
+ }) {
19
+ const [components, setComponents] = useState({});
20
+ const [paywallProps, setPaywallProps, paywallOpen, setPaywallOpen] = useDialog(components.paywallDialog);
21
+ const [
22
+ productChangeProps,
23
+ setProductChangeProps,
24
+ productChangeOpen,
25
+ setProductChangeOpen
26
+ ] = useDialog(components.productChangeDialog);
27
+ useCustomerBase({ client, params: { errorOnNotFound: false } });
28
+ return /* @__PURE__ */ jsxs(
29
+ AutumnContext.Provider,
30
+ {
31
+ value: {
32
+ initialized: true,
33
+ client,
34
+ disableDialogs,
35
+ paywallDialog: {
36
+ props: paywallProps,
37
+ setProps: setPaywallProps,
38
+ open: paywallOpen,
39
+ setOpen: setPaywallOpen,
40
+ setComponent: (component) => {
41
+ setComponents({
42
+ ...components,
43
+ paywallDialog: component
44
+ });
45
+ }
46
+ },
47
+ attachDialog: {
48
+ props: productChangeProps,
49
+ setProps: setProductChangeProps,
50
+ open: productChangeOpen,
51
+ setOpen: setProductChangeOpen,
52
+ setComponent: (component) => {
53
+ setComponents({
54
+ ...components,
55
+ productChangeDialog: component
56
+ });
57
+ }
58
+ }
59
+ },
60
+ children: [
61
+ components.paywallDialog && /* @__PURE__ */ jsx(
62
+ components.paywallDialog,
63
+ {
64
+ open: paywallOpen,
65
+ setOpen: setPaywallOpen,
66
+ ...paywallProps
67
+ }
68
+ ),
69
+ components.productChangeDialog && /* @__PURE__ */ jsx(
70
+ components.productChangeDialog,
71
+ {
72
+ open: productChangeOpen,
73
+ setOpen: setProductChangeOpen,
74
+ ...productChangeProps
75
+ }
76
+ ),
77
+ children
78
+ ]
79
+ }
80
+ );
81
+ }
82
+
83
+ export {
84
+ BaseAutumnProvider
85
+ };
@@ -0,0 +1,83 @@
1
+ "use client";
2
+
3
+ import {
4
+ handleAllowed
5
+ } from "./chunk-JFXBUWKA.mjs";
6
+ import {
7
+ useAutumnBase
8
+ } from "./chunk-CQMTU2M4.mjs";
9
+
10
+ // src/libraries/react/hooks/useEntityBase.tsx
11
+ import useSWR from "swr";
12
+ import { useContext } from "react";
13
+ var useEntityBase = ({
14
+ entityId,
15
+ params,
16
+ AutumnContext
17
+ }) => {
18
+ const { client } = useContext(AutumnContext);
19
+ const queryKey = ["entity", entityId, params?.expand];
20
+ const fetchEntity = async () => {
21
+ if (!entityId) {
22
+ return null;
23
+ }
24
+ const { data: data2, error: error2 } = await client.entities.get(entityId, params);
25
+ if (error2) {
26
+ throw error2;
27
+ }
28
+ if (!data2) {
29
+ return null;
30
+ }
31
+ return data2;
32
+ };
33
+ const { data, error, isLoading, mutate } = useSWR(queryKey, fetchEntity, {
34
+ fallbackData: null,
35
+ onErrorRetry: (error2, key, config) => {
36
+ if (error2.code == "entity_not_found") {
37
+ return false;
38
+ }
39
+ return true;
40
+ }
41
+ });
42
+ const {
43
+ check: checkAutumn,
44
+ attach: attachAutumn,
45
+ cancel: cancelAutumn,
46
+ track: trackAutumn
47
+ } = useAutumnBase({
48
+ AutumnContext
49
+ });
50
+ const allowed = (params2) => handleAllowed({ customer: data, params: params2 });
51
+ const check = (params2) => checkAutumn({ ...params2, entityId: entityId || void 0 });
52
+ const attach = (params2) => attachAutumn({ ...params2, entityId: entityId || void 0 });
53
+ const cancel = (params2) => cancelAutumn({ ...params2, entityId: entityId || void 0 });
54
+ const track = (params2) => trackAutumn({ ...params2, entityId: entityId || void 0 });
55
+ if (!entityId) {
56
+ return {
57
+ entity: null,
58
+ isLoading: false,
59
+ error: null,
60
+ refetch: mutate,
61
+ allowed,
62
+ check,
63
+ attach,
64
+ cancel,
65
+ track
66
+ };
67
+ }
68
+ return {
69
+ entity: error ? null : data,
70
+ isLoading,
71
+ error,
72
+ refetch: mutate,
73
+ allowed,
74
+ check,
75
+ attach,
76
+ cancel,
77
+ track
78
+ };
79
+ };
80
+
81
+ export {
82
+ useEntityBase
83
+ };
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {
4
4
  AutumnClient
5
- } from "./chunk-Y6UVL46W.mjs";
5
+ } from "./chunk-UDRQNZZS.mjs";
6
6
 
7
7
  // src/libraries/react/AutumnContext.tsx
8
8
  import { createContext, useContext } from "react";
@@ -2,10 +2,10 @@
2
2
 
3
3
  import {
4
4
  usePricingTableBase
5
- } from "./chunk-JYOLY75Q.mjs";
5
+ } from "./chunk-JOY6LN3M.mjs";
6
6
  import {
7
7
  AutumnContext
8
- } from "./chunk-WYADGMAH.mjs";
8
+ } from "./chunk-MH2YTNJL.mjs";
9
9
 
10
10
  // src/libraries/react/hooks/usePricingTable.tsx
11
11
  var usePricingTable = (params) => {
@@ -0,0 +1,17 @@
1
+ "use client";
2
+
3
+ import {
4
+ useEntityBase
5
+ } from "./chunk-L55GLFAX.mjs";
6
+ import {
7
+ AutumnContext
8
+ } from "./chunk-MH2YTNJL.mjs";
9
+
10
+ // src/libraries/react/hooks/useEntity.tsx
11
+ var useEntity = (entityId, params) => {
12
+ return useEntityBase({ AutumnContext, entityId, params });
13
+ };
14
+
15
+ export {
16
+ useEntity
17
+ };