autumn-js 0.0.1 → 0.0.2

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/dist/next/AutumnProvider.js +55 -0
  2. package/dist/next/AutumnProvider.mjs +31 -0
  3. package/dist/next/AutumnServer.js +36 -0
  4. package/dist/next/AutumnServer.mjs +12 -0
  5. package/dist/{react → next}/client/AutumnContext.d.mts +2 -3
  6. package/dist/{react → next}/client/AutumnContext.d.ts +2 -3
  7. package/dist/{react → next}/client/AutumnContext.js +4 -1
  8. package/dist/{react → next}/client/AutumnContext.mjs +4 -1
  9. package/dist/next/client/AutumnProvider.d.mts +10 -0
  10. package/dist/next/client/AutumnProvider.d.ts +10 -0
  11. package/dist/{react → next}/client/AutumnProvider.js +5 -4
  12. package/dist/{react → next}/client/AutumnProvider.mjs +5 -4
  13. package/dist/{react/client/cusTypes-BT7wlTNj.d.mts → next/client/cusTypes-BUiIMwvu.d.mts} +1 -5
  14. package/dist/{react/client/cusTypes-BT7wlTNj.d.ts → next/client/cusTypes-BUiIMwvu.d.ts} +1 -5
  15. package/dist/next/client/hooks/useAutumn.d.mts +24 -0
  16. package/dist/next/client/hooks/useAutumn.d.ts +24 -0
  17. package/dist/{react → next}/client/hooks/useAutumn.js +38 -24
  18. package/dist/{react → next}/client/hooks/useAutumn.mjs +38 -24
  19. package/dist/{react → next}/client/hooks/useCustomer.d.mts +1 -1
  20. package/dist/{react → next}/client/hooks/useCustomer.d.ts +1 -1
  21. package/dist/{react → next}/client/hooks/useCustomer.js +7 -4
  22. package/dist/{react → next}/client/hooks/useCustomer.mjs +7 -4
  23. package/dist/next/client/types.d.mts +12 -0
  24. package/dist/next/client/types.d.ts +12 -0
  25. package/dist/next/client/types.js +2 -0
  26. package/dist/next/client/types.mjs +2 -0
  27. package/dist/next/enums.js +31 -0
  28. package/dist/next/enums.mjs +7 -0
  29. package/dist/{react → next}/index.d.mts +43 -59
  30. package/dist/{react → next}/index.d.ts +43 -59
  31. package/dist/{react → next}/index.js +7 -1
  32. package/dist/{react → next}/index.mjs +3 -0
  33. package/dist/next/server/auth/authPlugin.d.mts +13 -0
  34. package/dist/next/server/auth/authPlugin.d.ts +13 -0
  35. package/dist/next/server/auth/authPlugin.js +11 -0
  36. package/dist/next/server/auth/authPlugin.mjs +11 -0
  37. package/dist/next/server/auth/getCusIdDefault.d.mts +14 -0
  38. package/dist/next/server/auth/getCusIdDefault.d.ts +14 -0
  39. package/dist/next/server/auth/getCusIdDefault.js +27 -0
  40. package/dist/next/server/auth/getCusIdDefault.mjs +27 -0
  41. package/dist/next/server/auth/handleAuthProvider.d.mts +37 -0
  42. package/dist/next/server/auth/handleAuthProvider.d.ts +37 -0
  43. package/dist/next/server/auth/handleAuthProvider.js +132 -0
  44. package/dist/next/server/auth/handleAuthProvider.mjs +132 -0
  45. package/dist/next/server/auth/withAuth.d.mts +11 -0
  46. package/dist/next/server/auth/withAuth.d.ts +11 -0
  47. package/dist/next/server/auth/withAuth.js +38 -0
  48. package/dist/next/server/auth/withAuth.mjs +38 -0
  49. package/dist/next/server/cusActions.d.mts +248 -0
  50. package/dist/next/server/cusActions.d.ts +248 -0
  51. package/dist/next/server/cusActions.js +32 -0
  52. package/dist/next/server/cusActions.mjs +32 -0
  53. package/dist/{react/server/genTypes-RkqyS6Mn.d.mts → next/server/cusTypes-B9N9G7Vr.d.mts} +1 -62
  54. package/dist/{react/server/genTypes-RkqyS6Mn.d.ts → next/server/cusTypes-B9N9G7Vr.d.ts} +1 -62
  55. package/dist/next/server/genActions.d.mts +29 -0
  56. package/dist/next/server/genActions.d.ts +29 -0
  57. package/dist/next/server/genActions.js +51 -0
  58. package/dist/next/server/genActions.mjs +51 -0
  59. package/dist/sdk/index.d.mts +65 -16
  60. package/dist/sdk/index.d.ts +65 -16
  61. package/dist/sdk/index.js +33 -6
  62. package/dist/sdk/index.mjs +33 -6
  63. package/dist/utils/encryptUtils.d.mts +4 -0
  64. package/dist/utils/encryptUtils.d.ts +4 -0
  65. package/dist/utils/encryptUtils.js +74 -0
  66. package/dist/utils/encryptUtils.mjs +38 -0
  67. package/package.json +10 -8
  68. package/publish.sh +8 -0
  69. package/tsup.config.ts +34 -12
  70. package/dist/react/client/AutumnProvider.d.mts +0 -12
  71. package/dist/react/client/AutumnProvider.d.ts +0 -12
  72. package/dist/react/client/hooks/useAutumn.d.mts +0 -65
  73. package/dist/react/client/hooks/useAutumn.d.ts +0 -65
  74. package/dist/react/server/cusActions.d.mts +0 -140
  75. package/dist/react/server/cusActions.d.ts +0 -140
  76. package/dist/react/server/cusActions.js +0 -26
  77. package/dist/react/server/cusActions.mjs +0 -26
  78. package/dist/react/server/genActions.d.mts +0 -42
  79. package/dist/react/server/genActions.d.ts +0 -42
  80. package/dist/react/server/genActions.js +0 -41
  81. package/dist/react/server/genActions.mjs +0 -41
  82. /package/dist/{react → next}/client/error-TNbN4XE4.d.mts +0 -0
  83. /package/dist/{react → next}/client/error-TNbN4XE4.d.ts +0 -0
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var AutumnProvider_exports = {};
20
+ __export(AutumnProvider_exports, {
21
+ AutumnProvider: () => AutumnProvider
22
+ });
23
+ module.exports = __toCommonJS(AutumnProvider_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_AutumnProvider = require("./client/AutumnProvider");
26
+ var import_encryptUtils = require("../utils/encryptUtils");
27
+ var import_authPlugin = require("./server/auth/authPlugin");
28
+ const AutumnProvider = ({
29
+ customerId,
30
+ customerData,
31
+ authPlugin,
32
+ children
33
+ }) => {
34
+ if (typeof window !== "undefined") {
35
+ throw new Error(
36
+ "AutumnProvider must be used in a server component. It cannot be used in client components."
37
+ );
38
+ }
39
+ let encryptedCustomerId = customerId ? (0, import_encryptUtils.encryptData)(customerId) : void 0;
40
+ if (authPlugin) {
41
+ (0, import_authPlugin.setupAuthPlugin)(authPlugin);
42
+ }
43
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
44
+ import_AutumnProvider.AutumnClientProvider,
45
+ {
46
+ encryptedCustomerId,
47
+ customerData,
48
+ children
49
+ }
50
+ );
51
+ };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ AutumnProvider
55
+ });
@@ -0,0 +1,31 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { AutumnClientProvider } from "./client/AutumnProvider";
3
+ import { encryptData } from "../utils/encryptUtils";
4
+ import { setupAuthPlugin } from "./server/auth/authPlugin";
5
+ const AutumnProvider = ({
6
+ customerId,
7
+ customerData,
8
+ authPlugin,
9
+ children
10
+ }) => {
11
+ if (typeof window !== "undefined") {
12
+ throw new Error(
13
+ "AutumnProvider must be used in a server component. It cannot be used in client components."
14
+ );
15
+ }
16
+ let encryptedCustomerId = customerId ? encryptData(customerId) : void 0;
17
+ if (authPlugin) {
18
+ setupAuthPlugin(authPlugin);
19
+ }
20
+ return /* @__PURE__ */ jsx(
21
+ AutumnClientProvider,
22
+ {
23
+ encryptedCustomerId,
24
+ customerData,
25
+ children
26
+ }
27
+ );
28
+ };
29
+ export {
30
+ AutumnProvider
31
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var AutumnServer_exports = {};
20
+ __export(AutumnServer_exports, {
21
+ AutumnProvider: () => AutumnProvider
22
+ });
23
+ module.exports = __toCommonJS(AutumnServer_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ const AutumnProvider = ({ children }) => {
26
+ if (typeof window !== "undefined") {
27
+ throw new Error(
28
+ "AutumnServer must be used in a server component. It cannot be used in client components (those marked with 'use client')."
29
+ );
30
+ }
31
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children });
32
+ };
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ AutumnProvider
36
+ });
@@ -0,0 +1,12 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ const AutumnProvider = ({ children }) => {
3
+ if (typeof window !== "undefined") {
4
+ throw new Error(
5
+ "AutumnServer must be used in a server component. It cannot be used in client components (those marked with 'use client')."
6
+ );
7
+ }
8
+ return /* @__PURE__ */ jsx("div", { children });
9
+ };
10
+ export {
11
+ AutumnProvider
12
+ };
@@ -1,7 +1,6 @@
1
1
  import * as react from 'react';
2
- import { AutumnContextParams } from './AutumnProvider.mjs';
3
- import 'react/jsx-runtime';
4
- import './cusTypes-BT7wlTNj.mjs';
2
+ import { AutumnContextParams } from './types.mjs';
3
+ import './cusTypes-BUiIMwvu.mjs';
5
4
 
6
5
  declare const AutumnContext: react.Context<AutumnContextParams>;
7
6
  declare const useAutumnContext: () => AutumnContextParams;
@@ -1,7 +1,6 @@
1
1
  import * as react from 'react';
2
- import { AutumnContextParams } from './AutumnProvider.js';
3
- import 'react/jsx-runtime';
4
- import './cusTypes-BT7wlTNj.js';
2
+ import { AutumnContextParams } from './types.js';
3
+ import './cusTypes-BUiIMwvu.js';
5
4
 
6
5
  declare const AutumnContext: react.Context<AutumnContextParams>;
7
6
  declare const useAutumnContext: () => AutumnContextParams;
@@ -1,7 +1,10 @@
1
1
  "use client";
2
+
2
3
  import { createContext, useContext } from "react";
3
4
  const AutumnContext = createContext({
4
- customerId: ""
5
+ encryptedCustomerId: "",
6
+ customerData: {},
7
+ authProvider: "better-auth"
5
8
  });
6
9
  const useAutumnContext = () => {
7
10
  const context = useContext(AutumnContext);
@@ -1,7 +1,10 @@
1
1
  "use client";
2
+
2
3
  import { createContext, useContext } from "react";
3
4
  const AutumnContext = createContext({
4
- customerId: ""
5
+ encryptedCustomerId: "",
6
+ customerData: {},
7
+ authProvider: "better-auth"
5
8
  });
6
9
  const useAutumnContext = () => {
7
10
  const context = useContext(AutumnContext);
@@ -0,0 +1,10 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { AutumnContextParams } from './types.mjs';
3
+ import './cusTypes-BUiIMwvu.mjs';
4
+
5
+ interface AutumnProviderProps extends AutumnContextParams {
6
+ children?: React.ReactNode;
7
+ }
8
+ declare const AutumnClientProvider: ({ children, encryptedCustomerId, customerData, }: AutumnProviderProps) => react_jsx_runtime.JSX.Element;
9
+
10
+ export { AutumnClientProvider, type AutumnProviderProps };
@@ -0,0 +1,10 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { AutumnContextParams } from './types.js';
3
+ import './cusTypes-BUiIMwvu.js';
4
+
5
+ interface AutumnProviderProps extends AutumnContextParams {
6
+ children?: React.ReactNode;
7
+ }
8
+ declare const AutumnClientProvider: ({ children, encryptedCustomerId, customerData, }: AutumnProviderProps) => react_jsx_runtime.JSX.Element;
9
+
10
+ export { AutumnClientProvider, type AutumnProviderProps };
@@ -1,16 +1,17 @@
1
1
  "use client";
2
+
2
3
  import { jsx } from "react/jsx-runtime";
3
4
  import { AutumnContext } from "./AutumnContext";
4
- const AutumnProvider = ({
5
+ const AutumnClientProvider = ({
5
6
  children,
6
- customerId,
7
+ encryptedCustomerId,
7
8
  customerData
8
9
  }) => {
9
10
  return /* @__PURE__ */ jsx(
10
11
  AutumnContext.Provider,
11
12
  {
12
13
  value: {
13
- customerId,
14
+ encryptedCustomerId,
14
15
  customerData
15
16
  },
16
17
  children
@@ -18,5 +19,5 @@ const AutumnProvider = ({
18
19
  );
19
20
  };
20
21
  export {
21
- AutumnProvider
22
+ AutumnClientProvider
22
23
  };
@@ -1,16 +1,17 @@
1
1
  "use client";
2
+
2
3
  import { jsx } from "react/jsx-runtime";
3
4
  import { AutumnContext } from "./AutumnContext";
4
- const AutumnProvider = ({
5
+ const AutumnClientProvider = ({
5
6
  children,
6
- customerId,
7
+ encryptedCustomerId,
7
8
  customerData
8
9
  }) => {
9
10
  return /* @__PURE__ */ jsx(
10
11
  AutumnContext.Provider,
11
12
  {
12
13
  value: {
13
- customerId,
14
+ encryptedCustomerId,
14
15
  customerData
15
16
  },
16
17
  children
@@ -18,5 +19,5 @@ const AutumnProvider = ({
18
19
  );
19
20
  };
20
21
  export {
21
- AutumnProvider
22
+ AutumnClientProvider
22
23
  };
@@ -59,9 +59,5 @@ interface CustomerData {
59
59
  email?: string;
60
60
  fingerprint?: string;
61
61
  }
62
- interface BillingPortalResponse {
63
- customer_id: string;
64
- url: string;
65
- }
66
62
 
67
- export type { BillingPortalResponse as B, CustomerData as C, Customer as a };
63
+ export type { CustomerData as C, Customer as a };
@@ -59,9 +59,5 @@ interface CustomerData {
59
59
  email?: string;
60
60
  fingerprint?: string;
61
61
  }
62
- interface BillingPortalResponse {
63
- customer_id: string;
64
- url: string;
65
- }
66
62
 
67
- export type { BillingPortalResponse as B, CustomerData as C, Customer as a };
63
+ export type { CustomerData as C, Customer as a };
@@ -0,0 +1,24 @@
1
+ import { A as AutumnError } from '../error-TNbN4XE4.mjs';
2
+ import { a as Customer } from '../cusTypes-BUiIMwvu.mjs';
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
+ attach: ({ productId }: {
12
+ productId: string;
13
+ }) => Promise<any>;
14
+ sendEvent: ({ featureId, value, }: {
15
+ featureId: string;
16
+ value: number;
17
+ }) => Promise<any>;
18
+ entitled: ({ featureId }: {
19
+ featureId: string;
20
+ }) => Promise<any>;
21
+ openBillingPortal: () => Promise<any>;
22
+ };
23
+
24
+ export { type UseAutumnOptions, useAutumn };
@@ -0,0 +1,24 @@
1
+ import { A as AutumnError } from '../error-TNbN4XE4.js';
2
+ import { a as Customer } from '../cusTypes-BUiIMwvu.js';
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
+ attach: ({ productId }: {
12
+ productId: string;
13
+ }) => Promise<any>;
14
+ sendEvent: ({ featureId, value, }: {
15
+ featureId: string;
16
+ value: number;
17
+ }) => Promise<any>;
18
+ entitled: ({ featureId }: {
19
+ featureId: string;
20
+ }) => Promise<any>;
21
+ openBillingPortal: () => Promise<any>;
22
+ };
23
+
24
+ export { type UseAutumnOptions, useAutumn };
@@ -1,17 +1,15 @@
1
1
  "use client";
2
+
2
3
  import {
3
4
  attachAction,
4
5
  entitledAction,
5
- getBillingPortalAction
6
+ getBillingPortalAction,
7
+ sendEventAction
6
8
  } from "../../server/genActions";
7
- import { sendEventAction } from "../../server/genActions";
8
9
  import { useAutumnContext } from "../AutumnContext";
9
10
  import { useCustomer } from "./useCustomer";
10
11
  const useAutumn = (options) => {
11
- const { customerId } = useAutumnContext();
12
- if (!customerId) {
13
- throw new Error("Customer ID is required");
14
- }
12
+ const { encryptedCustomerId } = useAutumnContext();
15
13
  const {
16
14
  customer,
17
15
  isLoading: loading,
@@ -19,39 +17,55 @@ const useAutumn = (options) => {
19
17
  } = useCustomer({
20
18
  autoCreate: options?.autoCreate
21
19
  });
22
- const entitled = ({ featureId }) => {
23
- return entitledAction({ customerId, featureId });
20
+ const attach = async ({ productId }) => {
21
+ const result = await attachAction({
22
+ encryptedCustomerId,
23
+ productId
24
+ });
25
+ if (result.error) {
26
+ throw result.error;
27
+ }
28
+ let data = result.data;
29
+ if (data?.checkout_url && typeof window !== "undefined") {
30
+ window.open(data.checkout_url, "_blank");
31
+ }
32
+ return result;
33
+ };
34
+ const entitled = async ({ featureId }) => {
35
+ const { data, error: error2 } = await entitledAction({
36
+ encryptedCustomerId,
37
+ featureId
38
+ });
39
+ if (error2) {
40
+ throw error2;
41
+ }
42
+ return data;
24
43
  };
25
- const sendEvent = ({
44
+ const sendEvent = async ({
26
45
  featureId,
27
46
  value
28
47
  }) => {
29
- return sendEventAction({ customerId, featureId, value });
30
- };
31
- const attach = async ({ productId }) => {
32
- const { data, error: error2 } = await attachAction({
33
- customerId,
34
- productId
48
+ const { data, error: error2 } = await sendEventAction({
49
+ encryptedCustomerId,
50
+ featureId,
51
+ value
35
52
  });
36
53
  if (error2) {
37
54
  throw error2;
38
55
  }
39
- if (data?.checkout_url && typeof window !== "undefined") {
40
- window.open(data.checkout_url, "_blank");
41
- } else {
42
- return data;
43
- }
56
+ return data;
44
57
  };
45
58
  const openBillingPortal = async () => {
46
- const { data, error: error2 } = await getBillingPortalAction({
47
- customerId,
59
+ const result = await getBillingPortalAction({
60
+ encryptedCustomerId,
48
61
  params: {
49
62
  return_url: "https://example.com"
50
63
  }
51
64
  });
52
- if (error2) {
53
- throw error2;
65
+ if (result.error) {
66
+ throw result.error;
54
67
  }
68
+ let data = result.data;
55
69
  if (data?.url && typeof window !== "undefined") {
56
70
  window.open(data.url, "_blank");
57
71
  return data;
@@ -1,17 +1,15 @@
1
1
  "use client";
2
+
2
3
  import {
3
4
  attachAction,
4
5
  entitledAction,
5
- getBillingPortalAction
6
+ getBillingPortalAction,
7
+ sendEventAction
6
8
  } from "../../server/genActions";
7
- import { sendEventAction } from "../../server/genActions";
8
9
  import { useAutumnContext } from "../AutumnContext";
9
10
  import { useCustomer } from "./useCustomer";
10
11
  const useAutumn = (options) => {
11
- const { customerId } = useAutumnContext();
12
- if (!customerId) {
13
- throw new Error("Customer ID is required");
14
- }
12
+ const { encryptedCustomerId } = useAutumnContext();
15
13
  const {
16
14
  customer,
17
15
  isLoading: loading,
@@ -19,39 +17,55 @@ const useAutumn = (options) => {
19
17
  } = useCustomer({
20
18
  autoCreate: options?.autoCreate
21
19
  });
22
- const entitled = ({ featureId }) => {
23
- return entitledAction({ customerId, featureId });
20
+ const attach = async ({ productId }) => {
21
+ const result = await attachAction({
22
+ encryptedCustomerId,
23
+ productId
24
+ });
25
+ if (result.error) {
26
+ throw result.error;
27
+ }
28
+ let data = result.data;
29
+ if (data?.checkout_url && typeof window !== "undefined") {
30
+ window.open(data.checkout_url, "_blank");
31
+ }
32
+ return result;
33
+ };
34
+ const entitled = async ({ featureId }) => {
35
+ const { data, error: error2 } = await entitledAction({
36
+ encryptedCustomerId,
37
+ featureId
38
+ });
39
+ if (error2) {
40
+ throw error2;
41
+ }
42
+ return data;
24
43
  };
25
- const sendEvent = ({
44
+ const sendEvent = async ({
26
45
  featureId,
27
46
  value
28
47
  }) => {
29
- return sendEventAction({ customerId, featureId, value });
30
- };
31
- const attach = async ({ productId }) => {
32
- const { data, error: error2 } = await attachAction({
33
- customerId,
34
- productId
48
+ const { data, error: error2 } = await sendEventAction({
49
+ encryptedCustomerId,
50
+ featureId,
51
+ value
35
52
  });
36
53
  if (error2) {
37
54
  throw error2;
38
55
  }
39
- if (data?.checkout_url && typeof window !== "undefined") {
40
- window.open(data.checkout_url, "_blank");
41
- } else {
42
- return data;
43
- }
56
+ return data;
44
57
  };
45
58
  const openBillingPortal = async () => {
46
- const { data, error: error2 } = await getBillingPortalAction({
47
- customerId,
59
+ const result = await getBillingPortalAction({
60
+ encryptedCustomerId,
48
61
  params: {
49
62
  return_url: "https://example.com"
50
63
  }
51
64
  });
52
- if (error2) {
53
- throw error2;
65
+ if (result.error) {
66
+ throw result.error;
54
67
  }
68
+ let data = result.data;
55
69
  if (data?.url && typeof window !== "undefined") {
56
70
  window.open(data.url, "_blank");
57
71
  return data;
@@ -1,5 +1,5 @@
1
1
  import { A as AutumnError } from '../error-TNbN4XE4.mjs';
2
- import { C as CustomerData, a as Customer } from '../cusTypes-BT7wlTNj.mjs';
2
+ import { C as CustomerData, a as Customer } from '../cusTypes-BUiIMwvu.mjs';
3
3
 
4
4
  interface UseCustomerProps {
5
5
  autoCreate?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { A as AutumnError } from '../error-TNbN4XE4.js';
2
- import { C as CustomerData, a as Customer } from '../cusTypes-BT7wlTNj.js';
2
+ import { C as CustomerData, a as Customer } from '../cusTypes-BUiIMwvu.js';
3
3
 
4
4
  interface UseCustomerProps {
5
5
  autoCreate?: boolean;
@@ -1,9 +1,10 @@
1
1
  "use client";
2
+
2
3
  import { useEffect, useState } from "react";
3
4
  import { useAutumnContext } from "../AutumnContext";
4
5
  import { getOrCreateCustomer, getCustomer } from "../../server/cusActions";
5
6
  const useCustomer = ({ autoCreate = true }) => {
6
- const { customerId, customerData } = useAutumnContext();
7
+ const { encryptedCustomerId, customerData } = useAutumnContext();
7
8
  const [customer, setCustomer] = useState(null);
8
9
  const [error, setError] = useState(null);
9
10
  const [isLoading, setIsLoading] = useState(false);
@@ -14,29 +15,31 @@ const useCustomer = ({ autoCreate = true }) => {
14
15
  let error2 = null;
15
16
  if (autoCreate) {
16
17
  const result = await getOrCreateCustomer({
17
- customerId,
18
+ encryptedCustomerId,
18
19
  customerData
19
20
  });
20
21
  data = result.data;
21
22
  error2 = result.error;
22
23
  } else {
23
- const result = await getCustomer({ customerId });
24
+ const result = await getCustomer({ encryptedCustomerId });
24
25
  data = result.data;
25
26
  error2 = result.error;
26
27
  }
27
28
  if (error2) {
29
+ console.log("(Autumn) Error fetching customer:", error2);
28
30
  setError(error2);
29
31
  } else {
30
32
  setCustomer(data);
31
33
  }
32
34
  } catch (error2) {
35
+ console.log("Fetch customer error", error2);
33
36
  setError(error2);
34
37
  }
35
38
  setIsLoading(false);
36
39
  };
37
40
  useEffect(() => {
38
41
  fetchCustomer();
39
- }, []);
42
+ }, [encryptedCustomerId]);
40
43
  return { customer, error, isLoading };
41
44
  };
42
45
  export {
@@ -1,9 +1,10 @@
1
1
  "use client";
2
+
2
3
  import { useEffect, useState } from "react";
3
4
  import { useAutumnContext } from "../AutumnContext";
4
5
  import { getOrCreateCustomer, getCustomer } from "../../server/cusActions";
5
6
  const useCustomer = ({ autoCreate = true }) => {
6
- const { customerId, customerData } = useAutumnContext();
7
+ const { encryptedCustomerId, customerData } = useAutumnContext();
7
8
  const [customer, setCustomer] = useState(null);
8
9
  const [error, setError] = useState(null);
9
10
  const [isLoading, setIsLoading] = useState(false);
@@ -14,29 +15,31 @@ const useCustomer = ({ autoCreate = true }) => {
14
15
  let error2 = null;
15
16
  if (autoCreate) {
16
17
  const result = await getOrCreateCustomer({
17
- customerId,
18
+ encryptedCustomerId,
18
19
  customerData
19
20
  });
20
21
  data = result.data;
21
22
  error2 = result.error;
22
23
  } else {
23
- const result = await getCustomer({ customerId });
24
+ const result = await getCustomer({ encryptedCustomerId });
24
25
  data = result.data;
25
26
  error2 = result.error;
26
27
  }
27
28
  if (error2) {
29
+ console.log("(Autumn) Error fetching customer:", error2);
28
30
  setError(error2);
29
31
  } else {
30
32
  setCustomer(data);
31
33
  }
32
34
  } catch (error2) {
35
+ console.log("Fetch customer error", error2);
33
36
  setError(error2);
34
37
  }
35
38
  setIsLoading(false);
36
39
  };
37
40
  useEffect(() => {
38
41
  fetchCustomer();
39
- }, []);
42
+ }, [encryptedCustomerId]);
40
43
  return { customer, error, isLoading };
41
44
  };
42
45
  export {
@@ -0,0 +1,12 @@
1
+ import { C as CustomerData } from './cusTypes-BUiIMwvu.mjs';
2
+
3
+ interface AutumnContextParams {
4
+ encryptedCustomerId?: string;
5
+ customerData?: CustomerData;
6
+ authProvider?: "clerk" | "better-auth";
7
+ }
8
+ interface AutumnProviderProps extends AutumnContextParams {
9
+ children?: React.ReactNode;
10
+ }
11
+
12
+ export type { AutumnContextParams, AutumnProviderProps };
@@ -0,0 +1,12 @@
1
+ import { C as CustomerData } from './cusTypes-BUiIMwvu.js';
2
+
3
+ interface AutumnContextParams {
4
+ encryptedCustomerId?: string;
5
+ customerData?: CustomerData;
6
+ authProvider?: "clerk" | "better-auth";
7
+ }
8
+ interface AutumnProviderProps extends AutumnContextParams {
9
+ children?: React.ReactNode;
10
+ }
11
+
12
+ export type { AutumnContextParams, AutumnProviderProps };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+