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.
- package/dist/next/AutumnProvider.js +55 -0
- package/dist/next/AutumnProvider.mjs +31 -0
- package/dist/next/AutumnServer.js +36 -0
- package/dist/next/AutumnServer.mjs +12 -0
- package/dist/{react → next}/client/AutumnContext.d.mts +2 -3
- package/dist/{react → next}/client/AutumnContext.d.ts +2 -3
- package/dist/{react → next}/client/AutumnContext.js +4 -1
- package/dist/{react → next}/client/AutumnContext.mjs +4 -1
- package/dist/next/client/AutumnProvider.d.mts +10 -0
- package/dist/next/client/AutumnProvider.d.ts +10 -0
- package/dist/{react → next}/client/AutumnProvider.js +5 -4
- package/dist/{react → next}/client/AutumnProvider.mjs +5 -4
- package/dist/{react/client/cusTypes-BT7wlTNj.d.mts → next/client/cusTypes-BUiIMwvu.d.mts} +1 -5
- package/dist/{react/client/cusTypes-BT7wlTNj.d.ts → next/client/cusTypes-BUiIMwvu.d.ts} +1 -5
- package/dist/next/client/hooks/useAutumn.d.mts +24 -0
- package/dist/next/client/hooks/useAutumn.d.ts +24 -0
- package/dist/{react → next}/client/hooks/useAutumn.js +38 -24
- package/dist/{react → next}/client/hooks/useAutumn.mjs +38 -24
- package/dist/{react → next}/client/hooks/useCustomer.d.mts +1 -1
- package/dist/{react → next}/client/hooks/useCustomer.d.ts +1 -1
- package/dist/{react → next}/client/hooks/useCustomer.js +7 -4
- package/dist/{react → next}/client/hooks/useCustomer.mjs +7 -4
- package/dist/next/client/types.d.mts +12 -0
- package/dist/next/client/types.d.ts +12 -0
- package/dist/next/client/types.js +2 -0
- package/dist/next/client/types.mjs +2 -0
- package/dist/next/enums.js +31 -0
- package/dist/next/enums.mjs +7 -0
- package/dist/{react → next}/index.d.mts +43 -59
- package/dist/{react → next}/index.d.ts +43 -59
- package/dist/{react → next}/index.js +7 -1
- package/dist/{react → next}/index.mjs +3 -0
- package/dist/next/server/auth/authPlugin.d.mts +13 -0
- package/dist/next/server/auth/authPlugin.d.ts +13 -0
- package/dist/next/server/auth/authPlugin.js +11 -0
- package/dist/next/server/auth/authPlugin.mjs +11 -0
- package/dist/next/server/auth/getCusIdDefault.d.mts +14 -0
- package/dist/next/server/auth/getCusIdDefault.d.ts +14 -0
- package/dist/next/server/auth/getCusIdDefault.js +27 -0
- package/dist/next/server/auth/getCusIdDefault.mjs +27 -0
- package/dist/next/server/auth/handleAuthProvider.d.mts +37 -0
- package/dist/next/server/auth/handleAuthProvider.d.ts +37 -0
- package/dist/next/server/auth/handleAuthProvider.js +132 -0
- package/dist/next/server/auth/handleAuthProvider.mjs +132 -0
- package/dist/next/server/auth/withAuth.d.mts +11 -0
- package/dist/next/server/auth/withAuth.d.ts +11 -0
- package/dist/next/server/auth/withAuth.js +38 -0
- package/dist/next/server/auth/withAuth.mjs +38 -0
- package/dist/next/server/cusActions.d.mts +248 -0
- package/dist/next/server/cusActions.d.ts +248 -0
- package/dist/next/server/cusActions.js +32 -0
- package/dist/next/server/cusActions.mjs +32 -0
- package/dist/{react/server/genTypes-RkqyS6Mn.d.mts → next/server/cusTypes-B9N9G7Vr.d.mts} +1 -62
- package/dist/{react/server/genTypes-RkqyS6Mn.d.ts → next/server/cusTypes-B9N9G7Vr.d.ts} +1 -62
- package/dist/next/server/genActions.d.mts +29 -0
- package/dist/next/server/genActions.d.ts +29 -0
- package/dist/next/server/genActions.js +51 -0
- package/dist/next/server/genActions.mjs +51 -0
- package/dist/sdk/index.d.mts +65 -16
- package/dist/sdk/index.d.ts +65 -16
- package/dist/sdk/index.js +33 -6
- package/dist/sdk/index.mjs +33 -6
- package/dist/utils/encryptUtils.d.mts +4 -0
- package/dist/utils/encryptUtils.d.ts +4 -0
- package/dist/utils/encryptUtils.js +74 -0
- package/dist/utils/encryptUtils.mjs +38 -0
- package/package.json +10 -8
- package/publish.sh +8 -0
- package/tsup.config.ts +34 -12
- package/dist/react/client/AutumnProvider.d.mts +0 -12
- package/dist/react/client/AutumnProvider.d.ts +0 -12
- package/dist/react/client/hooks/useAutumn.d.mts +0 -65
- package/dist/react/client/hooks/useAutumn.d.ts +0 -65
- package/dist/react/server/cusActions.d.mts +0 -140
- package/dist/react/server/cusActions.d.ts +0 -140
- package/dist/react/server/cusActions.js +0 -26
- package/dist/react/server/cusActions.mjs +0 -26
- package/dist/react/server/genActions.d.mts +0 -42
- package/dist/react/server/genActions.d.ts +0 -42
- package/dist/react/server/genActions.js +0 -41
- package/dist/react/server/genActions.mjs +0 -41
- /package/dist/{react → next}/client/error-TNbN4XE4.d.mts +0 -0
- /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 './
|
|
3
|
-
import '
|
|
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 './
|
|
3
|
-
import '
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
5
|
+
const AutumnClientProvider = ({
|
|
5
6
|
children,
|
|
6
|
-
|
|
7
|
+
encryptedCustomerId,
|
|
7
8
|
customerData
|
|
8
9
|
}) => {
|
|
9
10
|
return /* @__PURE__ */ jsx(
|
|
10
11
|
AutumnContext.Provider,
|
|
11
12
|
{
|
|
12
13
|
value: {
|
|
13
|
-
|
|
14
|
+
encryptedCustomerId,
|
|
14
15
|
customerData
|
|
15
16
|
},
|
|
16
17
|
children
|
|
@@ -18,5 +19,5 @@ const AutumnProvider = ({
|
|
|
18
19
|
);
|
|
19
20
|
};
|
|
20
21
|
export {
|
|
21
|
-
|
|
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
|
|
5
|
+
const AutumnClientProvider = ({
|
|
5
6
|
children,
|
|
6
|
-
|
|
7
|
+
encryptedCustomerId,
|
|
7
8
|
customerData
|
|
8
9
|
}) => {
|
|
9
10
|
return /* @__PURE__ */ jsx(
|
|
10
11
|
AutumnContext.Provider,
|
|
11
12
|
{
|
|
12
13
|
value: {
|
|
13
|
-
|
|
14
|
+
encryptedCustomerId,
|
|
14
15
|
customerData
|
|
15
16
|
},
|
|
16
17
|
children
|
|
@@ -18,5 +19,5 @@ const AutumnProvider = ({
|
|
|
18
19
|
);
|
|
19
20
|
};
|
|
20
21
|
export {
|
|
21
|
-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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
|
|
23
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
|
47
|
-
|
|
59
|
+
const result = await getBillingPortalAction({
|
|
60
|
+
encryptedCustomerId,
|
|
48
61
|
params: {
|
|
49
62
|
return_url: "https://example.com"
|
|
50
63
|
}
|
|
51
64
|
});
|
|
52
|
-
if (
|
|
53
|
-
throw
|
|
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 {
|
|
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
|
|
23
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
|
47
|
-
|
|
59
|
+
const result = await getBillingPortalAction({
|
|
60
|
+
encryptedCustomerId,
|
|
48
61
|
params: {
|
|
49
62
|
return_url: "https://example.com"
|
|
50
63
|
}
|
|
51
64
|
});
|
|
52
|
-
if (
|
|
53
|
-
throw
|
|
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-
|
|
2
|
+
import { C as CustomerData, a as Customer } from '../cusTypes-BUiIMwvu.mjs';
|
|
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 {
|
|
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
|
-
|
|
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({
|
|
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 {
|
|
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
|
-
|
|
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({
|
|
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 };
|