autumn-js 0.0.80 → 0.0.81

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 (155) hide show
  1. package/dist/libraries/backend/express.d.mts +1 -1
  2. package/dist/libraries/backend/express.d.ts +1 -1
  3. package/dist/libraries/backend/{referralTypes-3L_pJkT7.d.ts → referralTypes-BZ4WOVK5.d.ts} +2 -0
  4. package/dist/libraries/backend/{referralTypes-BOtccenE.d.mts → referralTypes-C6ao6j-_.d.mts} +2 -0
  5. package/dist/libraries/backend/utils/withAuth.d.mts +1 -1
  6. package/dist/libraries/backend/utils/withAuth.d.ts +1 -1
  7. package/dist/libraries/react/AutumnContext.d.mts +4 -4
  8. package/dist/libraries/react/AutumnContext.d.ts +4 -4
  9. package/dist/libraries/react/AutumnContext.mjs +4 -4
  10. package/dist/libraries/react/BaseAutumnProvider.d.mts +4 -4
  11. package/dist/libraries/react/BaseAutumnProvider.d.ts +4 -4
  12. package/dist/libraries/react/BaseAutumnProvider.js +169 -5690
  13. package/dist/libraries/react/BaseAutumnProvider.mjs +9 -19
  14. package/dist/libraries/react/{ReactAutumnClient-BUIEn-KV.d.ts → ReactAutumnClient-CD6wjJoS.d.ts} +3 -3
  15. package/dist/libraries/react/{ReactAutumnClient-B-g4zQsF.d.mts → ReactAutumnClient-DglSetDZ.d.mts} +3 -3
  16. package/dist/libraries/react/ReactAutumnProvider.d.mts +1 -1
  17. package/dist/libraries/react/ReactAutumnProvider.d.ts +1 -1
  18. package/dist/libraries/react/ReactAutumnProvider.js +173 -5690
  19. package/dist/libraries/react/ReactAutumnProvider.mjs +10 -19
  20. package/dist/libraries/react/chunk-4DZUJMZF.mjs +170 -0
  21. package/dist/libraries/react/chunk-6XKT4CR3.mjs +20 -0
  22. package/dist/libraries/react/{chunk-WYADGMAH.mjs → chunk-DFKCNRXM.mjs} +1 -1
  23. package/dist/libraries/react/chunk-DSHLYZWS.mjs +83 -0
  24. package/dist/libraries/react/chunk-EI2TXOE2.mjs +569 -0
  25. package/dist/libraries/react/chunk-ELPGPLUJ.mjs +77 -0
  26. package/dist/libraries/react/chunk-I2TAKPWB.mjs +53 -0
  27. package/dist/libraries/react/chunk-KOX2RKIK.mjs +17 -0
  28. package/dist/libraries/react/{chunk-3OBQBUE2.mjs → chunk-LLOLCHBX.mjs} +2 -2
  29. package/dist/libraries/react/chunk-QEYI3IGZ.mjs +17 -0
  30. package/dist/libraries/react/{chunk-JYOLY75Q.mjs → chunk-XNJDRLWX.mjs} +1 -1
  31. package/dist/libraries/react/chunk-ZLYUPJN5.mjs +85 -0
  32. package/dist/libraries/react/client/ReactAutumnClient.d.mts +4 -4
  33. package/dist/libraries/react/client/ReactAutumnClient.d.ts +4 -4
  34. package/dist/libraries/react/client/ReactAutumnClient.mjs +3 -3
  35. package/dist/libraries/react/client/clientCompMethods.d.mts +4 -4
  36. package/dist/libraries/react/client/clientCompMethods.d.ts +4 -4
  37. package/dist/libraries/react/client/clientCusMethods.d.mts +4 -4
  38. package/dist/libraries/react/client/clientCusMethods.d.ts +4 -4
  39. package/dist/libraries/react/client/clientEntityMethods.d.mts +4 -4
  40. package/dist/libraries/react/client/clientEntityMethods.d.ts +4 -4
  41. package/dist/libraries/react/client/clientGenMethods.d.mts +4 -4
  42. package/dist/libraries/react/client/clientGenMethods.d.ts +4 -4
  43. package/dist/libraries/react/client/clientProdMethods.d.mts +4 -4
  44. package/dist/libraries/react/client/clientProdMethods.d.ts +4 -4
  45. package/dist/libraries/react/client/clientReferralMethods.d.mts +4 -4
  46. package/dist/libraries/react/client/clientReferralMethods.d.ts +4 -4
  47. package/dist/libraries/react/components/attach-dialog/attach-dialog-synced.d.mts +1 -1
  48. package/dist/libraries/react/components/attach-dialog/attach-dialog-synced.d.ts +1 -1
  49. package/dist/libraries/react/components/attach-dialog/attach-dialog-synced.js +1 -1
  50. package/dist/libraries/react/components/attach-dialog/attach-dialog-synced.mjs +18 -10
  51. package/dist/libraries/react/components/attach-dialog/lib/attach-content.d.mts +1 -1
  52. package/dist/libraries/react/components/attach-dialog/lib/attach-content.d.ts +1 -1
  53. package/dist/libraries/react/components/check-dialog/check-dialog-synced.d.mts +1 -1
  54. package/dist/libraries/react/components/check-dialog/check-dialog-synced.d.ts +1 -1
  55. package/dist/libraries/react/components/check-dialog/lib/check-content.d.mts +1 -1
  56. package/dist/libraries/react/components/check-dialog/lib/check-content.d.ts +1 -1
  57. package/dist/libraries/react/components/pricing-table/pricing-table-synced.d.mts +1 -1
  58. package/dist/libraries/react/components/pricing-table/pricing-table-synced.d.ts +1 -1
  59. package/dist/libraries/react/components/pricing-table/pricing-table-synced.js +2897 -2897
  60. package/dist/libraries/react/components/pricing-table/pricing-table-synced.mjs +18 -10
  61. package/dist/libraries/react/components/ui/button.d.mts +1 -1
  62. package/dist/libraries/react/components/ui/button.d.ts +1 -1
  63. package/dist/libraries/react/{cusTypes-DSlkhuov.d.mts → cusTypes-JFEvVZLp.d.mts} +3 -1
  64. package/dist/libraries/react/{cusTypes-DSlkhuov.d.ts → cusTypes-JFEvVZLp.d.ts} +3 -1
  65. package/dist/libraries/react/{entTypes-Rpnetevb.d.mts → entTypes-CIemXnyX.d.mts} +1 -1
  66. package/dist/libraries/react/{entTypes-CcB_hEh5.d.ts → entTypes-CJ3jqOWR.d.ts} +1 -1
  67. package/dist/libraries/react/hooks/handleAllowed.d.mts +2 -2
  68. package/dist/libraries/react/hooks/handleAllowed.d.ts +2 -2
  69. package/dist/libraries/react/hooks/useAutumn.d.mts +2 -2
  70. package/dist/libraries/react/hooks/useAutumn.d.ts +2 -2
  71. package/dist/libraries/react/hooks/useAutumn.js +1 -5639
  72. package/dist/libraries/react/hooks/useAutumn.mjs +7 -20
  73. package/dist/libraries/react/hooks/useAutumnBase.d.mts +4 -4
  74. package/dist/libraries/react/hooks/useAutumnBase.d.ts +4 -4
  75. package/dist/libraries/react/hooks/useAutumnBase.js +1 -5639
  76. package/dist/libraries/react/hooks/useAutumnBase.mjs +6 -20
  77. package/dist/libraries/react/hooks/useCustomer.d.mts +4 -4
  78. package/dist/libraries/react/hooks/useCustomer.d.ts +4 -4
  79. package/dist/libraries/react/hooks/useCustomer.js +208 -5730
  80. package/dist/libraries/react/hooks/useCustomer.mjs +9 -20
  81. package/dist/libraries/react/hooks/useCustomerBase.d.mts +4 -4
  82. package/dist/libraries/react/hooks/useCustomerBase.d.ts +4 -4
  83. package/dist/libraries/react/hooks/useCustomerBase.js +163 -5693
  84. package/dist/libraries/react/hooks/useCustomerBase.mjs +8 -20
  85. package/dist/libraries/react/hooks/useEntity.d.mts +3 -3
  86. package/dist/libraries/react/hooks/useEntity.d.ts +3 -3
  87. package/dist/libraries/react/hooks/useEntity.js +199 -5787
  88. package/dist/libraries/react/hooks/useEntity.mjs +9 -20
  89. package/dist/libraries/react/hooks/useEntityBase.d.mts +4 -4
  90. package/dist/libraries/react/hooks/useEntityBase.d.ts +4 -4
  91. package/dist/libraries/react/hooks/useEntityBase.js +160 -5748
  92. package/dist/libraries/react/hooks/useEntityBase.mjs +8 -20
  93. package/dist/libraries/react/hooks/usePricingTable.d.mts +1 -1
  94. package/dist/libraries/react/hooks/usePricingTable.d.ts +1 -1
  95. package/dist/libraries/react/hooks/usePricingTable.mjs +6 -6
  96. package/dist/libraries/react/hooks/usePricingTableBase.d.mts +4 -4
  97. package/dist/libraries/react/hooks/usePricingTableBase.d.ts +4 -4
  98. package/dist/libraries/react/hooks/usePricingTableBase.mjs +5 -5
  99. package/dist/libraries/react/hooks/useProductsBase.mjs +4 -4
  100. package/dist/libraries/react/index.d.ts +2 -0
  101. package/dist/libraries/react/index.js +5442 -5442
  102. package/dist/libraries/react/index.mjs +5448 -5448
  103. package/dist/libraries/react/{response-BKKi_PDD.d.ts → response-BIBRaj58.d.ts} +1 -1
  104. package/dist/libraries/react/{response-CTqlSAVK.d.mts → response-CCcWrbaE.d.mts} +1 -1
  105. package/dist/next/{AutumnProvider-CGdXoZNQ.d.mts → AutumnProvider-DPcEuE_Q.d.mts} +2 -0
  106. package/dist/next/{AutumnProvider-CGdXoZNQ.d.ts → AutumnProvider-DPcEuE_Q.d.ts} +2 -0
  107. package/dist/next/AutumnProvider.d.mts +1 -1
  108. package/dist/next/AutumnProvider.d.ts +1 -1
  109. package/dist/next/client/NextAutumnClient.d.mts +3 -3
  110. package/dist/next/client/NextAutumnClient.d.ts +3 -3
  111. package/dist/next/client/NextAutumnProvider.d.mts +1 -1
  112. package/dist/next/client/NextAutumnProvider.d.ts +1 -1
  113. package/dist/next/client/{clientGenTypes-HDbUC8f6.d.ts → clientGenTypes-CAv4hwb4.d.ts} +1 -1
  114. package/dist/next/client/{clientGenTypes-BHrxzZi_.d.mts → clientGenTypes-Dlpw9wy_.d.mts} +1 -1
  115. package/dist/next/client/clientUtils.d.mts +2 -2
  116. package/dist/next/client/clientUtils.d.ts +2 -2
  117. package/dist/next/client/{cusTypes-CSbB7Wu9.d.mts → cusTypes-CJI8rdlY.d.mts} +2 -0
  118. package/dist/next/client/{cusTypes-CSbB7Wu9.d.ts → cusTypes-CJI8rdlY.d.ts} +2 -0
  119. package/dist/next/client/{entTypes-B3R2yjLW.d.ts → entTypes-CqHWTcCX.d.ts} +1 -1
  120. package/dist/next/client/{entTypes-6xEkbn32.d.mts → entTypes-okM0aeOM.d.mts} +1 -1
  121. package/dist/next/client/hooks/useAutumn.d.mts +3 -3
  122. package/dist/next/client/hooks/useAutumn.d.ts +3 -3
  123. package/dist/next/client/hooks/useCustomer.d.mts +3 -3
  124. package/dist/next/client/hooks/useCustomer.d.ts +3 -3
  125. package/dist/next/client/hooks/useEntity.d.mts +4 -4
  126. package/dist/next/client/hooks/useEntity.d.ts +4 -4
  127. package/dist/next/client/hooks/usePricingTable.d.mts +1 -1
  128. package/dist/next/client/hooks/usePricingTable.d.ts +1 -1
  129. package/dist/next/client/types.d.mts +2 -2
  130. package/dist/next/client/types.d.ts +2 -2
  131. package/dist/next/index.d.mts +2 -2
  132. package/dist/next/index.d.ts +2 -2
  133. package/dist/next/server/auth/withNextAuth.d.mts +1 -1
  134. package/dist/next/server/auth/withNextAuth.d.ts +1 -1
  135. package/dist/next/server/componentActions.d.mts +1 -1
  136. package/dist/next/server/componentActions.d.ts +1 -1
  137. package/dist/next/server/cusActions.d.mts +1 -1
  138. package/dist/next/server/cusActions.d.ts +1 -1
  139. package/dist/next/server/{cusTypes-ASrCF4fa.d.mts → cusTypes-DuSwXVmp.d.mts} +2 -0
  140. package/dist/next/server/{cusTypes-ASrCF4fa.d.ts → cusTypes-DuSwXVmp.d.ts} +2 -0
  141. package/dist/next/server/genActions.d.mts +1 -1
  142. package/dist/next/server/genActions.d.ts +1 -1
  143. package/dist/sdk/index.d.mts +2 -0
  144. package/dist/sdk/index.d.ts +2 -0
  145. package/package.json +1 -1
  146. package/dist/libraries/react/BaseAutumnProvider.css +0 -1264
  147. package/dist/libraries/react/ReactAutumnProvider.css +0 -1264
  148. package/dist/libraries/react/chunk-XPGX7SQG.mjs +0 -1014
  149. package/dist/libraries/react/hooks/useAutumn.css +0 -1264
  150. package/dist/libraries/react/hooks/useAutumnBase.css +0 -1264
  151. package/dist/libraries/react/hooks/useCustomer.css +0 -1264
  152. package/dist/libraries/react/hooks/useCustomerBase.css +0 -1264
  153. package/dist/libraries/react/hooks/useEntity.css +0 -1264
  154. package/dist/libraries/react/hooks/useEntityBase.css +0 -1264
  155. package/dist/libraries/react/{chunk-Y6UVL46W.mjs → chunk-ET534E5H.mjs} +6 -6
@@ -0,0 +1,569 @@
1
+ "use client";
2
+
3
+ import {
4
+ Switch
5
+ } from "./chunk-CMO5LYYU.mjs";
6
+ import {
7
+ getAttachContent
8
+ } from "./chunk-BCMBFJ7E.mjs";
9
+ import {
10
+ getPricingTableContent
11
+ } from "./chunk-QBBE72EF.mjs";
12
+ import {
13
+ Button
14
+ } from "./chunk-P2O4LZFD.mjs";
15
+ import {
16
+ ArrowRight,
17
+ Check,
18
+ Dialog,
19
+ DialogContent,
20
+ DialogFooter,
21
+ DialogTitle,
22
+ LoaderCircle
23
+ } from "./chunk-5FZ7IV6P.mjs";
24
+ import {
25
+ cn
26
+ } from "./chunk-4J6OC4ZQ.mjs";
27
+ import {
28
+ loadingStyles,
29
+ spinnerStyles
30
+ } from "./chunk-OWFX3JFF.mjs";
31
+ import {
32
+ useCustomer
33
+ } from "./chunk-6XKT4CR3.mjs";
34
+ import {
35
+ usePricingTable
36
+ } from "./chunk-LLOLCHBX.mjs";
37
+
38
+ // src/libraries/react/components/pricing-table/pricing-table-synced.tsx
39
+ import React2 from "react";
40
+
41
+ // src/libraries/react/components/attach-dialog/attach-dialog-synced.tsx
42
+ import { useEffect, useState } from "react";
43
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
44
+ function AttachDialog(params) {
45
+ const { attach } = useCustomer();
46
+ const [loading, setLoading] = useState(false);
47
+ const [optionsInput, setOptionsInput] = useState(
48
+ params?.preview?.options || []
49
+ );
50
+ const getTotalPrice = () => {
51
+ let sum = due_today?.price || 0;
52
+ optionsInput.forEach((option) => {
53
+ if (option.price && option.quantity) {
54
+ sum += option.price * (option.quantity / option.billing_units);
55
+ }
56
+ });
57
+ return sum;
58
+ };
59
+ useEffect(() => {
60
+ setOptionsInput(params?.preview?.options || []);
61
+ }, [params?.preview?.options]);
62
+ if (!params || !params.preview) {
63
+ return /* @__PURE__ */ jsx(Fragment, {});
64
+ }
65
+ const { open, setOpen, preview } = params;
66
+ const { items, due_today } = preview;
67
+ const { title, message } = getAttachContent(preview);
68
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(
69
+ DialogContent,
70
+ {
71
+ className: cn(
72
+ "au-p-0 au-pt-4 au-gap-0 au-text-foreground au-overflow-hidden au-text-sm"
73
+ ),
74
+ children: [
75
+ /* @__PURE__ */ jsx(DialogTitle, { className: cn("au-px-6 au-mb-1 "), children: title }),
76
+ /* @__PURE__ */ jsx("div", { className: cn("au-px-6 au-mt-1 au-mb-4 au-text-muted-foreground"), children: message }),
77
+ (items || optionsInput.length > 0) && /* @__PURE__ */ jsxs("div", { className: "au-mb-6 au-px-6", children: [
78
+ items?.map((item) => /* @__PURE__ */ jsxs(PriceItem, { children: [
79
+ /* @__PURE__ */ jsx("span", { className: "au-truncate au-flex-1", children: item.description }),
80
+ /* @__PURE__ */ jsx("span", { children: item.price })
81
+ ] }, item.description)),
82
+ optionsInput?.map((option, index) => {
83
+ return /* @__PURE__ */ jsx(
84
+ OptionsInput,
85
+ {
86
+ option,
87
+ optionsInput,
88
+ setOptionsInput,
89
+ index
90
+ },
91
+ option.feature_name
92
+ );
93
+ })
94
+ ] }),
95
+ /* @__PURE__ */ jsxs(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: [
96
+ due_today && /* @__PURE__ */ jsxs(TotalPrice, { children: [
97
+ /* @__PURE__ */ jsx("span", { children: "Due Today" }),
98
+ /* @__PURE__ */ jsx("span", { children: new Intl.NumberFormat("en-US", {
99
+ style: "currency",
100
+ currency: due_today.currency
101
+ }).format(getTotalPrice()) })
102
+ ] }),
103
+ /* @__PURE__ */ jsx(
104
+ Button,
105
+ {
106
+ size: "sm",
107
+ onClick: async () => {
108
+ setLoading(true);
109
+ await attach({
110
+ productId: preview.product_id,
111
+ options: optionsInput.map((option) => ({
112
+ featureId: option.feature_id,
113
+ quantity: option.quantity || 0
114
+ }))
115
+ });
116
+ setOpen(false);
117
+ setLoading(false);
118
+ },
119
+ disabled: loading,
120
+ className: "au-min-w-16 au-flex au-items-center au-gap-2",
121
+ 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" }) })
122
+ }
123
+ )
124
+ ] })
125
+ ]
126
+ }
127
+ ) });
128
+ }
129
+ var PriceItem = ({
130
+ children,
131
+ className,
132
+ ...props
133
+ }) => {
134
+ return /* @__PURE__ */ jsx(
135
+ "div",
136
+ {
137
+ className: cn(
138
+ "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",
139
+ className
140
+ ),
141
+ ...props,
142
+ children
143
+ }
144
+ );
145
+ };
146
+ var OptionsInput = ({
147
+ className,
148
+ option,
149
+ optionsInput,
150
+ setOptionsInput,
151
+ index,
152
+ ...props
153
+ }) => {
154
+ const { feature_name, billing_units, quantity, price } = option;
155
+ return /* @__PURE__ */ jsxs(PriceItem, { children: [
156
+ /* @__PURE__ */ jsx("span", { children: feature_name }),
157
+ /* @__PURE__ */ jsx(
158
+ QuantityInput,
159
+ {
160
+ value: quantity ? quantity / billing_units : "",
161
+ onChange: (e) => {
162
+ const newOptions = [...optionsInput];
163
+ newOptions[index].quantity = parseInt(e.target.value) * billing_units;
164
+ setOptionsInput(newOptions);
165
+ },
166
+ children: /* @__PURE__ */ jsxs("span", { className: "", children: [
167
+ "\xD7 $",
168
+ price,
169
+ " per ",
170
+ billing_units === 1 ? " " : billing_units,
171
+ " ",
172
+ feature_name
173
+ ] })
174
+ },
175
+ feature_name
176
+ )
177
+ ] }, feature_name);
178
+ };
179
+ var QuantityInput = ({
180
+ children,
181
+ onChange,
182
+ value,
183
+ className,
184
+ ...props
185
+ }) => {
186
+ const currentValue = Number(value) || 0;
187
+ const handleValueChange = (newValue) => {
188
+ const syntheticEvent = {
189
+ target: { value: String(newValue) }
190
+ };
191
+ onChange(syntheticEvent);
192
+ };
193
+ return /* @__PURE__ */ jsxs(
194
+ "div",
195
+ {
196
+ className: cn(className, "au-flex au-flex-row au-items-center au-gap-4"),
197
+ ...props,
198
+ children: [
199
+ /* @__PURE__ */ jsxs("div", { className: "au-flex au-items-center au-gap-1", children: [
200
+ /* @__PURE__ */ jsx(
201
+ Button,
202
+ {
203
+ variant: "outline",
204
+ size: "icon",
205
+ onClick: () => currentValue > 0 && handleValueChange(currentValue - 1),
206
+ disabled: currentValue <= 0,
207
+ className: "au-h-6 au-w-6 au-pb-0.5",
208
+ children: "-"
209
+ }
210
+ ),
211
+ /* @__PURE__ */ jsx("span", { className: "au-w-8 au-text-center au-text-foreground", children: currentValue }),
212
+ /* @__PURE__ */ jsx(
213
+ Button,
214
+ {
215
+ variant: "outline",
216
+ size: "icon",
217
+ onClick: () => handleValueChange(currentValue + 1),
218
+ className: "au-h-6 au-w-6 au-pb-0.5",
219
+ children: "+"
220
+ }
221
+ )
222
+ ] }),
223
+ children
224
+ ]
225
+ }
226
+ );
227
+ };
228
+ var TotalPrice = ({ children }) => {
229
+ return /* @__PURE__ */ jsx("div", { className: "au-w-full au-font-semibold au-flex au-justify-between au-items-center", children });
230
+ };
231
+ var PricingDialogButton = ({
232
+ children,
233
+ size,
234
+ onClick,
235
+ disabled,
236
+ className
237
+ }) => {
238
+ return /* @__PURE__ */ jsxs(
239
+ Button,
240
+ {
241
+ onClick,
242
+ disabled,
243
+ size,
244
+ className: cn(className, "au-shadow-sm au-shadow-stone-400"),
245
+ children: [
246
+ children,
247
+ /* @__PURE__ */ jsx(ArrowRight, { className: "!au-h-3" })
248
+ ]
249
+ }
250
+ );
251
+ };
252
+
253
+ // src/libraries/react/components/pricing-table/pricing-table-synced.tsx
254
+ import { createContext, useContext, useState as useState2 } from "react";
255
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
256
+ function PricingTable({
257
+ productDetails
258
+ }) {
259
+ const { attach } = useCustomer();
260
+ const [isAnnual, setIsAnnual] = useState2(false);
261
+ const { products, isLoading, error } = usePricingTable({ productDetails });
262
+ if (isLoading) {
263
+ return /* @__PURE__ */ jsx2("div", { style: loadingStyles, children: /* @__PURE__ */ jsx2(LoaderCircle, { style: spinnerStyles }) });
264
+ }
265
+ if (error) {
266
+ return /* @__PURE__ */ jsx2("div", { children: " Something went wrong..." });
267
+ }
268
+ const intervals = Array.from(
269
+ new Set(
270
+ products?.map((p) => p.properties?.interval_group).filter((i) => !!i)
271
+ )
272
+ );
273
+ const multiInterval = intervals.length > 1;
274
+ const intervalFilter = (product) => {
275
+ if (!product.properties?.interval_group) {
276
+ return true;
277
+ }
278
+ if (multiInterval) {
279
+ if (isAnnual) {
280
+ return product.properties?.interval_group === "year";
281
+ } else {
282
+ return product.properties?.interval_group === "month";
283
+ }
284
+ }
285
+ return true;
286
+ };
287
+ return /* @__PURE__ */ jsx2("div", { className: cn("au-root"), children: products && /* @__PURE__ */ jsx2(
288
+ PricingTableContainer,
289
+ {
290
+ products,
291
+ isAnnualToggle: isAnnual,
292
+ setIsAnnualToggle: setIsAnnual,
293
+ multiInterval,
294
+ children: products.filter(intervalFilter).map((product, index) => /* @__PURE__ */ jsx2(
295
+ PricingCard,
296
+ {
297
+ productId: product.id,
298
+ buttonProps: {
299
+ disabled: product.scenario === "active" || product.scenario === "scheduled",
300
+ onClick: async () => {
301
+ if (product.id) {
302
+ await attach({
303
+ productId: product.id,
304
+ dialog: AttachDialog
305
+ });
306
+ } else if (product.display?.button_url) {
307
+ window.open(product.display?.button_url, "_blank");
308
+ }
309
+ }
310
+ }
311
+ },
312
+ index
313
+ ))
314
+ }
315
+ ) });
316
+ }
317
+ var PricingTableContext = createContext({
318
+ isAnnualToggle: false,
319
+ setIsAnnualToggle: () => {
320
+ },
321
+ products: [],
322
+ showFeatures: true
323
+ });
324
+ var usePricingTableContext = (componentName) => {
325
+ const context = useContext(PricingTableContext);
326
+ if (context === void 0) {
327
+ throw new Error(`${componentName} must be used within <PricingTable />`);
328
+ }
329
+ return context;
330
+ };
331
+ var PricingTableContainer = ({
332
+ children,
333
+ products,
334
+ showFeatures = true,
335
+ className,
336
+ isAnnualToggle,
337
+ setIsAnnualToggle,
338
+ multiInterval
339
+ }) => {
340
+ if (!products) {
341
+ throw new Error("products is required in <PricingTable />");
342
+ }
343
+ if (products.length === 0) {
344
+ return /* @__PURE__ */ jsx2(Fragment2, {});
345
+ }
346
+ const hasRecommended = products?.some((p) => p.display?.recommend_text);
347
+ return /* @__PURE__ */ jsx2(
348
+ PricingTableContext.Provider,
349
+ {
350
+ value: { isAnnualToggle, setIsAnnualToggle, products, showFeatures },
351
+ children: /* @__PURE__ */ jsxs2(
352
+ "div",
353
+ {
354
+ className: cn(
355
+ "au-flex au-items-center au-flex-col",
356
+ hasRecommended && "!au-py-10"
357
+ ),
358
+ children: [
359
+ multiInterval && /* @__PURE__ */ jsx2(
360
+ "div",
361
+ {
362
+ className: cn(
363
+ products.some((p) => p.display?.recommend_text) && "au-mb-8"
364
+ ),
365
+ children: /* @__PURE__ */ jsx2(
366
+ AnnualSwitch,
367
+ {
368
+ isAnnualToggle,
369
+ setIsAnnualToggle
370
+ }
371
+ )
372
+ }
373
+ ),
374
+ /* @__PURE__ */ jsx2(
375
+ "div",
376
+ {
377
+ className: cn(
378
+ "au-grid au-grid-cols-1 sm:au-grid-cols-2 lg:au-grid-cols-[repeat(auto-fit,minmax(200px,1fr))] au-w-full au-gap-2",
379
+ className
380
+ ),
381
+ children
382
+ }
383
+ )
384
+ ]
385
+ }
386
+ )
387
+ }
388
+ );
389
+ };
390
+ var PricingCard = ({
391
+ productId,
392
+ className,
393
+ buttonProps
394
+ }) => {
395
+ const { products, showFeatures } = usePricingTableContext("PricingCard");
396
+ const product = products.find((p) => p.id === productId);
397
+ if (!product) {
398
+ throw new Error(`Product with id ${productId} not found`);
399
+ }
400
+ const { name, display: productDisplay, items } = product;
401
+ const { buttonText } = getPricingTableContent(product);
402
+ const isRecommended = productDisplay?.recommend_text ? true : false;
403
+ const mainPriceDisplay = product.properties?.is_free ? {
404
+ primary_text: "Free"
405
+ } : product.items[0].display;
406
+ const featureItems = product.properties?.is_free ? product.items : product.items.slice(1);
407
+ return /* @__PURE__ */ jsxs2(
408
+ "div",
409
+ {
410
+ className: cn(
411
+ " au-w-full au-h-full au-py-6 au-text-foreground au-border au-rounded-lg au-shadow-sm au-max-w-xl",
412
+ isRecommended && "lg:au--translate-y-6 lg:au-shadow-lg dark:au-shadow-zinc-800/80 lg:au-h-[calc(100%+48px)] au-bg-secondary/40",
413
+ className
414
+ ),
415
+ children: [
416
+ productDisplay?.recommend_text && /* @__PURE__ */ jsx2(RecommendedBadge, { recommended: productDisplay?.recommend_text }),
417
+ /* @__PURE__ */ jsxs2(
418
+ "div",
419
+ {
420
+ className: cn(
421
+ "au-flex au-flex-col au-h-full au-flex-grow",
422
+ isRecommended && "lg:au-translate-y-6"
423
+ ),
424
+ children: [
425
+ /* @__PURE__ */ jsxs2("div", { className: "au-h-full", children: [
426
+ /* @__PURE__ */ jsxs2("div", { className: "au-flex au-flex-col", children: [
427
+ /* @__PURE__ */ jsxs2("div", { className: "au-pb-4", children: [
428
+ /* @__PURE__ */ jsx2("h2", { className: "au-text-2xl au-font-semibold au-px-6 au-truncate", children: productDisplay?.name || name }),
429
+ productDisplay?.description && /* @__PURE__ */ jsx2("div", { className: "au-text-sm au-text-muted-foreground au-px-6 au-h-8", children: /* @__PURE__ */ jsx2("p", { className: "au-line-clamp-2", children: productDisplay?.description }) })
430
+ ] }),
431
+ /* @__PURE__ */ jsx2("div", { className: "au-mb-2", children: /* @__PURE__ */ jsx2("h3", { className: "au-font-semibold au-h-16 au-flex au-px-6 au-items-center au-border-y au-mb-4 au-bg-secondary/40", children: /* @__PURE__ */ jsxs2("div", { className: "au-line-clamp-2", children: [
432
+ mainPriceDisplay?.primary_text,
433
+ " ",
434
+ mainPriceDisplay?.secondary_text && /* @__PURE__ */ jsx2("span", { className: "au-font-normal au-text-muted-foreground au-mt-1", children: mainPriceDisplay?.secondary_text })
435
+ ] }) }) })
436
+ ] }),
437
+ showFeatures && featureItems.length > 0 && /* @__PURE__ */ jsx2("div", { className: "au-flex-grow au-px-6 au-mb-6", children: /* @__PURE__ */ jsx2(
438
+ PricingFeatureList,
439
+ {
440
+ items: featureItems,
441
+ showIcon: true,
442
+ everythingFrom: product.display?.everything_from
443
+ }
444
+ ) })
445
+ ] }),
446
+ /* @__PURE__ */ jsx2(
447
+ "div",
448
+ {
449
+ className: cn(" au-px-6 ", isRecommended && "lg:au--translate-y-12"),
450
+ children: /* @__PURE__ */ jsx2(
451
+ PricingCardButton,
452
+ {
453
+ recommended: productDisplay?.recommend_text ? true : false,
454
+ ...buttonProps,
455
+ children: buttonText
456
+ }
457
+ )
458
+ }
459
+ )
460
+ ]
461
+ }
462
+ )
463
+ ]
464
+ }
465
+ );
466
+ };
467
+ var PricingFeatureList = ({
468
+ items,
469
+ showIcon = true,
470
+ everythingFrom,
471
+ className
472
+ }) => {
473
+ return /* @__PURE__ */ jsxs2("div", { className: cn("au-flex-grow", className), children: [
474
+ everythingFrom && /* @__PURE__ */ jsxs2("p", { className: "au-text-sm au-mb-4", children: [
475
+ "Everything from ",
476
+ everythingFrom,
477
+ ", plus:"
478
+ ] }),
479
+ /* @__PURE__ */ jsx2("div", { className: "au-space-y-3", children: items.map((item, index) => /* @__PURE__ */ jsxs2(
480
+ "div",
481
+ {
482
+ className: "au-flex au-items-start au-gap-2 au-text-sm",
483
+ children: [
484
+ showIcon && /* @__PURE__ */ jsx2(Check, { className: "au-h-4 au-w-4 au-text-primary au-flex-shrink-0 au-mt-0.5" }),
485
+ /* @__PURE__ */ jsxs2("div", { className: "au-flex au-flex-col", children: [
486
+ /* @__PURE__ */ jsx2("span", { children: item.display?.primary_text }),
487
+ item.display?.secondary_text && /* @__PURE__ */ jsx2("span", { className: "au-text-sm au-text-muted-foreground", children: item.display?.secondary_text })
488
+ ] })
489
+ ]
490
+ },
491
+ index
492
+ )) })
493
+ ] });
494
+ };
495
+ var PricingCardButton = React2.forwardRef(({ recommended, children, className, onClick, ...props }, ref) => {
496
+ const [loading, setLoading] = useState2(false);
497
+ const handleClick = async (e) => {
498
+ setLoading(true);
499
+ try {
500
+ await onClick?.(e);
501
+ } catch (error) {
502
+ console.error(error);
503
+ } finally {
504
+ setLoading(false);
505
+ }
506
+ };
507
+ return /* @__PURE__ */ jsx2(
508
+ Button,
509
+ {
510
+ className: cn(
511
+ "au-w-full au-py-3 au-px-4 au-group au-overflow-hidden au-relative au-transition-all au-duration-300 hover:au-brightness-90 au-border au-rounded-lg",
512
+ className
513
+ ),
514
+ ...props,
515
+ variant: recommended ? "default" : "secondary",
516
+ ref,
517
+ disabled: loading || props.disabled,
518
+ onClick: handleClick,
519
+ children: loading ? /* @__PURE__ */ jsx2(LoaderCircle, { className: "au-h-4 au-w-4 au-animate-spin" }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
520
+ /* @__PURE__ */ jsxs2("div", { className: "au-flex au-items-center au-justify-between au-w-full au-transition-transform au-duration-300 group-hover:au-translate-y-[-130%]", children: [
521
+ /* @__PURE__ */ jsx2("span", { children }),
522
+ /* @__PURE__ */ jsx2("span", { className: "au-text-sm", children: "\u2192" })
523
+ ] }),
524
+ /* @__PURE__ */ jsxs2("div", { className: "au-flex au-items-center au-justify-between au-w-full au-absolute au-px-4 au-translate-y-[130%] au-transition-transform au-duration-300 group-hover:au-translate-y-0 au-mt-2 group-hover:au-mt-0", children: [
525
+ /* @__PURE__ */ jsx2("span", { children }),
526
+ /* @__PURE__ */ jsx2("span", { className: "au-text-sm", children: "\u2192" })
527
+ ] })
528
+ ] })
529
+ }
530
+ );
531
+ });
532
+ PricingCardButton.displayName = "PricingCardButton";
533
+ var AnnualSwitch = ({
534
+ isAnnualToggle,
535
+ setIsAnnualToggle
536
+ }) => {
537
+ return /* @__PURE__ */ jsxs2("div", { className: "au-flex au-items-center au-space-x-2 au-mb-4", children: [
538
+ /* @__PURE__ */ jsx2("span", { className: "au-text-sm au-text-muted-foreground", children: "Monthly" }),
539
+ /* @__PURE__ */ jsx2(
540
+ Switch,
541
+ {
542
+ id: "annual-billing",
543
+ checked: isAnnualToggle,
544
+ onCheckedChange: setIsAnnualToggle
545
+ }
546
+ ),
547
+ /* @__PURE__ */ jsx2("span", { className: "au-text-sm au-text-muted-foreground", children: "Annual" })
548
+ ] });
549
+ };
550
+ var RecommendedBadge = ({ recommended }) => {
551
+ 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 });
552
+ };
553
+
554
+ export {
555
+ PricingTable,
556
+ usePricingTableContext,
557
+ PricingTableContainer,
558
+ PricingCard,
559
+ PricingFeatureList,
560
+ PricingCardButton,
561
+ AnnualSwitch,
562
+ RecommendedBadge,
563
+ AttachDialog,
564
+ PriceItem,
565
+ OptionsInput,
566
+ QuantityInput,
567
+ TotalPrice,
568
+ PricingDialogButton
569
+ };
@@ -0,0 +1,77 @@
1
+ "use client";
2
+
3
+ import {
4
+ handleAllowed
5
+ } from "./chunk-JFXBUWKA.mjs";
6
+ import {
7
+ useAutumnBase
8
+ } from "./chunk-4DZUJMZF.mjs";
9
+ import {
10
+ useAutumnContext
11
+ } from "./chunk-DFKCNRXM.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
+ };
@@ -0,0 +1,53 @@
1
+ "use client";
2
+
3
+ import {
4
+ BaseAutumnProvider
5
+ } from "./chunk-ZLYUPJN5.mjs";
6
+ import {
7
+ AutumnContext
8
+ } from "./chunk-DFKCNRXM.mjs";
9
+ import {
10
+ AutumnClient
11
+ } from "./chunk-ET534E5H.mjs";
12
+
13
+ // src/libraries/react/ReactAutumnProvider.tsx
14
+ import { useEffect } from "react";
15
+ import { jsx } from "react/jsx-runtime";
16
+ var ReactAutumnProvider = ({
17
+ children,
18
+ getBearerToken,
19
+ backendUrl,
20
+ customerData,
21
+ includeCredentials = true,
22
+ disableDialogs = false,
23
+ authClient
24
+ }) => {
25
+ if (backendUrl && !backendUrl.startsWith("http")) {
26
+ console.warn(`backendUrl is not a valid URL: ${backendUrl}`);
27
+ }
28
+ let client = new AutumnClient({
29
+ backendUrl: backendUrl || "",
30
+ getBearerToken,
31
+ customerData,
32
+ includeCredentials
33
+ });
34
+ const analyseAuthClient = async () => {
35
+ console.log("Auth client:", authClient);
36
+ };
37
+ useEffect(() => {
38
+ analyseAuthClient();
39
+ }, [authClient]);
40
+ return /* @__PURE__ */ jsx(
41
+ BaseAutumnProvider,
42
+ {
43
+ client,
44
+ AutumnContext,
45
+ disableDialogs,
46
+ children
47
+ }
48
+ );
49
+ };
50
+
51
+ export {
52
+ ReactAutumnProvider
53
+ };