autumn-js 0.0.12 → 0.0.16

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 (83) hide show
  1. package/README.md +2 -2
  2. package/dist/next/client/AutumnContext.d.mts +2 -4
  3. package/dist/next/client/AutumnContext.d.ts +2 -4
  4. package/dist/next/client/AutumnContext.js +3 -0
  5. package/dist/next/client/AutumnContext.mjs +3 -0
  6. package/dist/next/client/AutumnProvider.js +89 -5
  7. package/dist/next/client/AutumnProvider.mjs +89 -5
  8. package/dist/next/client/hooks/types.d.mts +14 -0
  9. package/dist/next/client/hooks/types.d.ts +14 -0
  10. package/dist/next/client/hooks/types.js +2 -0
  11. package/dist/next/client/hooks/types.mjs +2 -0
  12. package/dist/next/client/hooks/useAutumn.d.mts +41 -28
  13. package/dist/next/client/hooks/useAutumn.d.ts +41 -28
  14. package/dist/next/client/hooks/useAutumn.js +178 -37
  15. package/dist/next/client/hooks/useAutumn.mjs +178 -37
  16. package/dist/next/client/hooks/useCustomer.d.mts +3 -5
  17. package/dist/next/client/hooks/useCustomer.d.ts +3 -5
  18. package/dist/next/client/hooks/useCustomer.js +10 -2
  19. package/dist/next/client/hooks/useCustomer.mjs +10 -2
  20. package/dist/next/client/hooks/usePricingTable.d.mts +23 -0
  21. package/dist/next/client/hooks/usePricingTable.d.ts +23 -0
  22. package/dist/next/client/hooks/usePricingTable.js +62 -0
  23. package/dist/next/client/hooks/usePricingTable.mjs +62 -0
  24. package/dist/next/client/types.d.mts +1 -0
  25. package/dist/next/client/types.d.ts +1 -0
  26. package/dist/next/index.d.mts +83 -96
  27. package/dist/next/index.d.ts +83 -96
  28. package/dist/next/index.js +2 -0
  29. package/dist/next/index.mjs +1 -0
  30. package/dist/next/server/auth/clerk-wrapper.d.mts +3 -0
  31. package/dist/next/server/auth/clerk-wrapper.d.ts +3 -0
  32. package/dist/next/server/auth/clerk-wrapper.js +18 -0
  33. package/dist/next/server/auth/clerk-wrapper.mjs +18 -0
  34. package/dist/next/server/auth/handleAuthProvider.d.mts +5 -23
  35. package/dist/next/server/auth/handleAuthProvider.d.ts +5 -23
  36. package/dist/next/server/auth/handleAuthProvider.js +3 -2
  37. package/dist/next/server/auth/handleAuthProvider.mjs +3 -2
  38. package/dist/next/server/auth/supabase-wrapper.js +41 -0
  39. package/dist/next/server/auth/supabase-wrapper.mjs +41 -0
  40. package/dist/next/server/auth/withAuth.d.mts +6 -2
  41. package/dist/next/server/auth/withAuth.d.ts +6 -2
  42. package/dist/next/server/auth/withAuth.js +5 -1
  43. package/dist/next/server/auth/withAuth.mjs +5 -1
  44. package/dist/next/server/componentActions.d.mts +11 -0
  45. package/dist/next/server/componentActions.d.ts +11 -0
  46. package/dist/next/server/componentActions.js +21 -0
  47. package/dist/next/server/componentActions.mjs +21 -0
  48. package/dist/next/server/cusActions.d.mts +23 -33
  49. package/dist/next/server/cusActions.d.ts +23 -33
  50. package/dist/next/server/cusActions.js +13 -10
  51. package/dist/next/server/cusActions.mjs +13 -10
  52. package/dist/next/server/{cusTypes-G4c15fDy.d.mts → cusTypes-B9N9G7Vr.d.mts} +1 -1
  53. package/dist/next/server/{cusTypes-G4c15fDy.d.ts → cusTypes-B9N9G7Vr.d.ts} +1 -1
  54. package/dist/next/server/genActions.d.mts +11 -3
  55. package/dist/next/server/genActions.d.ts +11 -3
  56. package/dist/next/server/genActions.js +49 -23
  57. package/dist/next/server/genActions.mjs +49 -23
  58. package/dist/next/server/{genTypes-CluyrKKQ.d.ts → genTypes-BDibiu0E.d.ts} +11 -9
  59. package/dist/next/server/{genTypes-DJB4XhNz.d.mts → genTypes-DDkwFU_V.d.mts} +11 -9
  60. package/dist/next/server/response-CtOCrwQ7.d.mts +26 -0
  61. package/dist/next/server/response-CtOCrwQ7.d.ts +26 -0
  62. package/dist/next/server/utils.d.mts +5 -0
  63. package/dist/next/server/utils.d.ts +5 -0
  64. package/dist/next/server/utils.js +16 -0
  65. package/dist/next/server/utils.mjs +16 -0
  66. package/dist/sdk/general.d.mts +10 -8
  67. package/dist/sdk/general.d.ts +10 -8
  68. package/dist/sdk/index.d.mts +45 -9
  69. package/dist/sdk/index.d.ts +45 -9
  70. package/dist/sdk/index.js +68 -2
  71. package/dist/sdk/index.mjs +68 -3
  72. package/dist/sdk/products.d.mts +3 -1
  73. package/dist/sdk/products.d.ts +3 -1
  74. package/package.json +10 -3
  75. package/tsup.config.ts +8 -0
  76. package/dist/next/AutumnServer.js +0 -36
  77. package/dist/next/AutumnServer.mjs +0 -12
  78. package/dist/next/server/auth/utils.js +0 -25
  79. package/dist/next/server/auth/utils.mjs +0 -25
  80. package/dist/sdk/cusTypes-BxbYGvfU.d.mts +0 -68
  81. package/dist/sdk/cusTypes-CcZ5ZhSo.d.ts +0 -68
  82. /package/dist/next/server/auth/{utils.d.mts → supabase-wrapper.d.mts} +0 -0
  83. /package/dist/next/server/auth/{utils.d.ts → supabase-wrapper.d.ts} +0 -0
package/README.md CHANGED
@@ -95,8 +95,8 @@ export default function BillingPage() {
95
95
  The `useAutumn` hook exports several useful functions:
96
96
 
97
97
  - `attach({ productId })`: Opens a checkout URL automatically when called to attach a product to the customer
98
- - `entitled({ featureId })`: Checks if the customer is entitled to use a specific feature
99
- - `event({ featureId, value })`: Records usage for a particular feature
98
+ - `check({ featureId })`: Checks if the customer is entitled to use a specific feature
99
+ - `track({ featureId, value })`: Send usage for a particular feature
100
100
  - `openBillingPortal()`: Opens Stripe's billing portal for the current customer to manage their subscription and billing settings
101
101
 
102
102
 
@@ -1,8 +1,6 @@
1
1
  import * as react from 'react';
2
- import { AutumnContextParams } from './types.mjs';
3
- import './cusTypes-BUiIMwvu.mjs';
4
2
 
5
- declare const AutumnContext: react.Context<AutumnContextParams>;
6
- declare const useAutumnContext: () => AutumnContextParams;
3
+ declare const AutumnContext: react.Context<any>;
4
+ declare const useAutumnContext: () => any;
7
5
 
8
6
  export { AutumnContext, useAutumnContext };
@@ -1,8 +1,6 @@
1
1
  import * as react from 'react';
2
- import { AutumnContextParams } from './types.js';
3
- import './cusTypes-BUiIMwvu.js';
4
2
 
5
- declare const AutumnContext: react.Context<AutumnContextParams>;
6
- declare const useAutumnContext: () => AutumnContextParams;
3
+ declare const AutumnContext: react.Context<any>;
4
+ declare const useAutumnContext: () => any;
7
5
 
8
6
  export { AutumnContext, useAutumnContext };
@@ -7,6 +7,9 @@ const AutumnContext = createContext({
7
7
  authProvider: "better-auth",
8
8
  customer: null,
9
9
  setCustomer: () => {
10
+ },
11
+ paywallOpen: false,
12
+ setPaywallOpen: () => {
10
13
  }
11
14
  });
12
15
  const useAutumnContext = () => {
@@ -7,6 +7,9 @@ const AutumnContext = createContext({
7
7
  authProvider: "better-auth",
8
8
  customer: null,
9
9
  setCustomer: () => {
10
+ },
11
+ paywallOpen: false,
12
+ setPaywallOpen: () => {
10
13
  }
11
14
  });
12
15
  const useAutumnContext = () => {
@@ -1,24 +1,108 @@
1
1
  "use client";
2
2
 
3
- import { jsx } from "react/jsx-runtime";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { AutumnContext } from "./AutumnContext";
5
- import { useState } from "react";
5
+ import { useEffect, useState } from "react";
6
+ const useDialog = (type) => {
7
+ const [dialogFound, setDialogFound] = useState(false);
8
+ const [dialogProps, setDialogProps] = useState(null);
9
+ const [dialogOpen, setDialogOpen] = useState(false);
10
+ const [DialogComponent, setDialogComponent] = useState(null);
11
+ useEffect(() => {
12
+ if (dialogProps) {
13
+ setDialogOpen(true);
14
+ }
15
+ }, [dialogProps]);
16
+ useEffect(() => {
17
+ if (!dialogOpen) {
18
+ setTimeout(() => {
19
+ setDialogProps(null);
20
+ }, 200);
21
+ }
22
+ }, [dialogOpen]);
23
+ const loadDialog = async () => {
24
+ try {
25
+ let module = await import(`@/components/pricing/${type}-dialog.tsx`);
26
+ if (module.default && typeof module.default === "function") {
27
+ setDialogComponent(() => module.default);
28
+ setDialogFound(true);
29
+ }
30
+ } catch (error) {
31
+ setDialogFound(false);
32
+ }
33
+ };
34
+ useEffect(() => {
35
+ loadDialog();
36
+ }, []);
37
+ return [
38
+ dialogFound,
39
+ dialogProps,
40
+ setDialogProps,
41
+ dialogOpen,
42
+ setDialogOpen,
43
+ DialogComponent
44
+ ];
45
+ };
6
46
  const AutumnClientProvider = ({
7
47
  children,
8
48
  encryptedCustomerId,
9
49
  customerData
10
50
  }) => {
11
51
  let [customer, setCustomer] = useState(null);
12
- return /* @__PURE__ */ jsx(
52
+ const [
53
+ prodChangeDialogFound,
54
+ prodChangeDialogProps,
55
+ setProdChangeDialogProps,
56
+ prodChangeDialogOpen,
57
+ setProdChangeDialogOpen,
58
+ ProdChangeDialogComponent
59
+ ] = useDialog("product-change");
60
+ const [
61
+ paywallFound,
62
+ paywallProps,
63
+ setPaywallProps,
64
+ paywallOpen,
65
+ setPaywallOpen,
66
+ PaywallDialogComponent
67
+ ] = useDialog("paywall");
68
+ return /* @__PURE__ */ jsxs(
13
69
  AutumnContext.Provider,
14
70
  {
15
71
  value: {
16
72
  encryptedCustomerId,
17
73
  customerData,
18
74
  customer,
19
- setCustomer
75
+ setCustomer,
76
+ prodChangeDialog: {
77
+ found: prodChangeDialogFound,
78
+ setProps: setProdChangeDialogProps,
79
+ setOpen: setProdChangeDialogOpen
80
+ },
81
+ paywallDialog: {
82
+ found: paywallFound,
83
+ setProps: setPaywallProps,
84
+ setOpen: setPaywallOpen
85
+ }
20
86
  },
21
- children
87
+ children: [
88
+ ProdChangeDialogComponent && /* @__PURE__ */ jsx(
89
+ ProdChangeDialogComponent,
90
+ {
91
+ open: prodChangeDialogOpen,
92
+ setOpen: setProdChangeDialogOpen,
93
+ ...prodChangeDialogProps
94
+ }
95
+ ),
96
+ PaywallDialogComponent && /* @__PURE__ */ jsx(
97
+ PaywallDialogComponent,
98
+ {
99
+ open: paywallOpen,
100
+ setOpen: setPaywallOpen,
101
+ ...paywallProps
102
+ }
103
+ ),
104
+ children
105
+ ]
22
106
  }
23
107
  );
24
108
  };
@@ -1,24 +1,108 @@
1
1
  "use client";
2
2
 
3
- import { jsx } from "react/jsx-runtime";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { AutumnContext } from "./AutumnContext";
5
- import { useState } from "react";
5
+ import { useEffect, useState } from "react";
6
+ const useDialog = (type) => {
7
+ const [dialogFound, setDialogFound] = useState(false);
8
+ const [dialogProps, setDialogProps] = useState(null);
9
+ const [dialogOpen, setDialogOpen] = useState(false);
10
+ const [DialogComponent, setDialogComponent] = useState(null);
11
+ useEffect(() => {
12
+ if (dialogProps) {
13
+ setDialogOpen(true);
14
+ }
15
+ }, [dialogProps]);
16
+ useEffect(() => {
17
+ if (!dialogOpen) {
18
+ setTimeout(() => {
19
+ setDialogProps(null);
20
+ }, 200);
21
+ }
22
+ }, [dialogOpen]);
23
+ const loadDialog = async () => {
24
+ try {
25
+ let module = await import(`@/components/pricing/${type}-dialog.tsx`);
26
+ if (module.default && typeof module.default === "function") {
27
+ setDialogComponent(() => module.default);
28
+ setDialogFound(true);
29
+ }
30
+ } catch (error) {
31
+ setDialogFound(false);
32
+ }
33
+ };
34
+ useEffect(() => {
35
+ loadDialog();
36
+ }, []);
37
+ return [
38
+ dialogFound,
39
+ dialogProps,
40
+ setDialogProps,
41
+ dialogOpen,
42
+ setDialogOpen,
43
+ DialogComponent
44
+ ];
45
+ };
6
46
  const AutumnClientProvider = ({
7
47
  children,
8
48
  encryptedCustomerId,
9
49
  customerData
10
50
  }) => {
11
51
  let [customer, setCustomer] = useState(null);
12
- return /* @__PURE__ */ jsx(
52
+ const [
53
+ prodChangeDialogFound,
54
+ prodChangeDialogProps,
55
+ setProdChangeDialogProps,
56
+ prodChangeDialogOpen,
57
+ setProdChangeDialogOpen,
58
+ ProdChangeDialogComponent
59
+ ] = useDialog("product-change");
60
+ const [
61
+ paywallFound,
62
+ paywallProps,
63
+ setPaywallProps,
64
+ paywallOpen,
65
+ setPaywallOpen,
66
+ PaywallDialogComponent
67
+ ] = useDialog("paywall");
68
+ return /* @__PURE__ */ jsxs(
13
69
  AutumnContext.Provider,
14
70
  {
15
71
  value: {
16
72
  encryptedCustomerId,
17
73
  customerData,
18
74
  customer,
19
- setCustomer
75
+ setCustomer,
76
+ prodChangeDialog: {
77
+ found: prodChangeDialogFound,
78
+ setProps: setProdChangeDialogProps,
79
+ setOpen: setProdChangeDialogOpen
80
+ },
81
+ paywallDialog: {
82
+ found: paywallFound,
83
+ setProps: setPaywallProps,
84
+ setOpen: setPaywallOpen
85
+ }
20
86
  },
21
- children
87
+ children: [
88
+ ProdChangeDialogComponent && /* @__PURE__ */ jsx(
89
+ ProdChangeDialogComponent,
90
+ {
91
+ open: prodChangeDialogOpen,
92
+ setOpen: setProdChangeDialogOpen,
93
+ ...prodChangeDialogProps
94
+ }
95
+ ),
96
+ PaywallDialogComponent && /* @__PURE__ */ jsx(
97
+ PaywallDialogComponent,
98
+ {
99
+ open: paywallOpen,
100
+ setOpen: setPaywallOpen,
101
+ ...paywallProps
102
+ }
103
+ ),
104
+ children
105
+ ]
22
106
  }
23
107
  );
24
108
  };
@@ -0,0 +1,14 @@
1
+ interface AttachParams {
2
+ dialog?: boolean;
3
+ productId: string;
4
+ options?: {
5
+ featureId: string;
6
+ quantity: number;
7
+ }[];
8
+ successUrl?: string;
9
+ forceCheckout?: boolean;
10
+ metadata?: Record<string, string>;
11
+ callback?: () => Promise<void>;
12
+ }
13
+
14
+ export type { AttachParams };
@@ -0,0 +1,14 @@
1
+ interface AttachParams {
2
+ dialog?: boolean;
3
+ productId: string;
4
+ options?: {
5
+ featureId: string;
6
+ quantity: number;
7
+ }[];
8
+ successUrl?: string;
9
+ forceCheckout?: boolean;
10
+ metadata?: Record<string, string>;
11
+ callback?: () => Promise<void>;
12
+ }
13
+
14
+ export type { AttachParams };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+
@@ -0,0 +1,2 @@
1
+ "use client";
2
+
@@ -1,24 +1,26 @@
1
1
  import { A as AutumnError } from '../error-BUtm1Pks.mjs';
2
- import { a as Customer } from '../cusTypes-BUiIMwvu.mjs';
2
+ import { AttachParams } from './types.mjs';
3
3
 
4
- interface UseAutumnOptions {
5
- autoCreate?: boolean;
6
- }
7
- declare const useAutumn: (options?: UseAutumnOptions) => {
8
- customer: Customer | null;
9
- loading: boolean;
10
- error: AutumnError | null;
11
- refetch: () => Promise<void>;
12
- attach: ({ productId, options, successUrl, forceCheckout, metadata, }: {
13
- productId: string;
14
- options?: {
15
- featureId: string;
16
- quantity: number;
17
- }[];
18
- successUrl?: string;
19
- forceCheckout?: boolean;
20
- metadata?: Record<string, string>;
4
+ declare const useAutumn: () => {
5
+ attach: ({ dialog, productId, options, successUrl, forceCheckout, metadata, callback, }: AttachParams) => Promise<any>;
6
+ check: ({ dialog, featureId, productId, requiredQuantity, sendEvent, }: {
7
+ dialog?: boolean;
8
+ featureId?: string;
9
+ productId?: string;
10
+ requiredQuantity?: number;
11
+ sendEvent?: boolean;
12
+ }) => Promise<any>;
13
+ track: ({ featureId, value, }: {
14
+ featureId: string;
15
+ value?: number;
21
16
  }) => Promise<any>;
17
+ openBillingPortal: (options?: {
18
+ returnUrl?: string;
19
+ }) => Promise<any>;
20
+ /**
21
+ * @deprecated Use track({featureId, value}) instead.
22
+ * This method is deprecated and will be removed in a future version.
23
+ */
22
24
  event: ({ featureId, value, }: {
23
25
  featureId: string;
24
26
  value?: number;
@@ -30,15 +32,26 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
30
32
  entitled: ({ featureId }: {
31
33
  featureId: string;
32
34
  }) => Promise<any>;
33
- check: ({ featureId, productId, requiredQuantity, sendEvent, }: {
34
- featureId?: string;
35
- productId?: string;
36
- requiredQuantity?: number;
37
- sendEvent?: boolean;
38
- }) => Promise<any>;
39
- openBillingPortal: (options?: {
40
- returnUrl?: string;
41
- }) => Promise<any>;
35
+ /**
36
+ * @deprecated Use the useCustomer() hook instead.
37
+ * This property is deprecated and will be removed in a future version.
38
+ */
39
+ customer: any;
40
+ /**
41
+ * @deprecated Use the useCustomer() hook instead.
42
+ * This property is deprecated and will be removed in a future version.
43
+ */
44
+ loading: boolean;
45
+ /**
46
+ * @deprecated Use the useCustomer() hook instead.
47
+ * This property is deprecated and will be removed in a future version.
48
+ */
49
+ error: AutumnError | null;
50
+ /**
51
+ * @deprecated Use the useCustomer() hook instead.
52
+ * This property is deprecated and will be removed in a future version.
53
+ */
54
+ refetch: () => Promise<void>;
42
55
  };
43
56
 
44
- export { type UseAutumnOptions, useAutumn };
57
+ export { useAutumn };
@@ -1,24 +1,26 @@
1
1
  import { A as AutumnError } from '../error-BUtm1Pks.js';
2
- import { a as Customer } from '../cusTypes-BUiIMwvu.js';
2
+ import { AttachParams } from './types.js';
3
3
 
4
- interface UseAutumnOptions {
5
- autoCreate?: boolean;
6
- }
7
- declare const useAutumn: (options?: UseAutumnOptions) => {
8
- customer: Customer | null;
9
- loading: boolean;
10
- error: AutumnError | null;
11
- refetch: () => Promise<void>;
12
- attach: ({ productId, options, successUrl, forceCheckout, metadata, }: {
13
- productId: string;
14
- options?: {
15
- featureId: string;
16
- quantity: number;
17
- }[];
18
- successUrl?: string;
19
- forceCheckout?: boolean;
20
- metadata?: Record<string, string>;
4
+ declare const useAutumn: () => {
5
+ attach: ({ dialog, productId, options, successUrl, forceCheckout, metadata, callback, }: AttachParams) => Promise<any>;
6
+ check: ({ dialog, featureId, productId, requiredQuantity, sendEvent, }: {
7
+ dialog?: boolean;
8
+ featureId?: string;
9
+ productId?: string;
10
+ requiredQuantity?: number;
11
+ sendEvent?: boolean;
12
+ }) => Promise<any>;
13
+ track: ({ featureId, value, }: {
14
+ featureId: string;
15
+ value?: number;
21
16
  }) => Promise<any>;
17
+ openBillingPortal: (options?: {
18
+ returnUrl?: string;
19
+ }) => Promise<any>;
20
+ /**
21
+ * @deprecated Use track({featureId, value}) instead.
22
+ * This method is deprecated and will be removed in a future version.
23
+ */
22
24
  event: ({ featureId, value, }: {
23
25
  featureId: string;
24
26
  value?: number;
@@ -30,15 +32,26 @@ declare const useAutumn: (options?: UseAutumnOptions) => {
30
32
  entitled: ({ featureId }: {
31
33
  featureId: string;
32
34
  }) => Promise<any>;
33
- check: ({ featureId, productId, requiredQuantity, sendEvent, }: {
34
- featureId?: string;
35
- productId?: string;
36
- requiredQuantity?: number;
37
- sendEvent?: boolean;
38
- }) => Promise<any>;
39
- openBillingPortal: (options?: {
40
- returnUrl?: string;
41
- }) => Promise<any>;
35
+ /**
36
+ * @deprecated Use the useCustomer() hook instead.
37
+ * This property is deprecated and will be removed in a future version.
38
+ */
39
+ customer: any;
40
+ /**
41
+ * @deprecated Use the useCustomer() hook instead.
42
+ * This property is deprecated and will be removed in a future version.
43
+ */
44
+ loading: boolean;
45
+ /**
46
+ * @deprecated Use the useCustomer() hook instead.
47
+ * This property is deprecated and will be removed in a future version.
48
+ */
49
+ error: AutumnError | null;
50
+ /**
51
+ * @deprecated Use the useCustomer() hook instead.
52
+ * This property is deprecated and will be removed in a future version.
53
+ */
54
+ refetch: () => Promise<void>;
42
55
  };
43
56
 
44
- export { type UseAutumnOptions, useAutumn };
57
+ export { useAutumn };