autumn-js 0.0.22 → 0.0.24
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/client/AutumnContext.d.mts +4 -2
- package/dist/next/client/AutumnContext.d.ts +4 -2
- package/dist/next/client/AutumnContext.js +16 -2
- package/dist/next/client/AutumnContext.mjs +16 -2
- package/dist/next/client/AutumnProvider.d.mts +1 -1
- package/dist/next/client/AutumnProvider.d.ts +1 -1
- package/dist/next/client/AutumnProvider.js +4 -1
- package/dist/next/client/AutumnProvider.mjs +4 -1
- package/dist/next/client/clientUtils.d.mts +15 -0
- package/dist/next/client/clientUtils.d.ts +15 -0
- package/dist/next/client/clientUtils.js +57 -0
- package/dist/next/client/clientUtils.mjs +57 -0
- package/dist/next/client/{cusTypes-BUiIMwvu.d.mts → cusTypes-sGWmB2Vf.d.mts} +16 -9
- package/dist/next/client/{cusTypes-BUiIMwvu.d.ts → cusTypes-sGWmB2Vf.d.ts} +16 -9
- package/dist/next/client/hooks/useAutumn.d.mts +2 -1
- package/dist/next/client/hooks/useAutumn.d.ts +2 -1
- package/dist/next/client/hooks/useAutumn.js +47 -29
- package/dist/next/client/hooks/useAutumn.mjs +47 -29
- package/dist/next/client/hooks/useCheck.d.mts +2 -0
- package/dist/next/client/hooks/useCheck.d.ts +2 -0
- package/dist/next/client/hooks/useCheck.js +2 -0
- package/dist/next/client/hooks/useCheck.mjs +2 -0
- package/dist/next/client/hooks/useCustomer.d.mts +2 -1
- package/dist/next/client/hooks/useCustomer.d.ts +2 -1
- package/dist/next/client/hooks/usePricingTable.d.mts +5 -22
- package/dist/next/client/hooks/usePricingTable.d.ts +5 -22
- package/dist/next/client/hooks/usePricingTable.js +12 -21
- package/dist/next/client/hooks/usePricingTable.mjs +12 -21
- package/dist/next/client/types.d.mts +39 -6
- package/dist/next/client/types.d.ts +39 -6
- package/dist/next/client/types.js +3 -4
- package/dist/next/client/types.mjs +3 -4
- package/dist/next/index.d.mts +89 -13
- package/dist/next/index.d.ts +89 -13
- package/dist/next/server/auth/withAuth.d.mts +1 -1
- package/dist/next/server/auth/withAuth.d.ts +1 -1
- package/dist/next/server/auth/withAuth.js +1 -1
- package/dist/next/server/auth/withAuth.mjs +1 -1
- package/dist/next/server/componentActions.d.mts +1 -1
- package/dist/next/server/componentActions.d.ts +1 -1
- package/dist/next/server/cusActions.d.mts +2 -2
- package/dist/next/server/cusActions.d.ts +2 -2
- package/dist/next/server/{cusTypes-B9N9G7Vr.d.mts → cusTypes-DtlCmw72.d.mts} +17 -10
- package/dist/next/server/{cusTypes-B9N9G7Vr.d.ts → cusTypes-DtlCmw72.d.ts} +17 -10
- package/dist/next/server/genActions.d.mts +2 -2
- package/dist/next/server/genActions.d.ts +2 -2
- package/dist/next/server/{genTypes-BDibiu0E.d.ts → genTypes-B8lkg6J-.d.ts} +1 -1
- package/dist/next/server/{genTypes-DDkwFU_V.d.mts → genTypes-CmWo5C2C.d.mts} +1 -1
- package/dist/sdk/cusTypes-BIzuiqvx.d.mts +74 -0
- package/dist/sdk/cusTypes-HqJzG9Vv.d.ts +74 -0
- package/dist/sdk/customers.d.mts +2 -2
- package/dist/sdk/customers.d.ts +2 -2
- package/dist/sdk/general.d.mts +2 -2
- package/dist/sdk/general.d.ts +2 -2
- package/dist/sdk/index.d.mts +4 -5
- package/dist/sdk/index.d.ts +4 -5
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/index.mjs +1 -0
- package/dist/sdk/prodEnums-CuZfnjiK.d.mts +27 -0
- package/dist/sdk/prodEnums-CuZfnjiK.d.ts +27 -0
- package/dist/sdk/products.d.mts +1 -1
- package/dist/sdk/products.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import { AutumnContextParams } from './types.mjs';
|
|
3
|
+
import './cusTypes-sGWmB2Vf.mjs';
|
|
2
4
|
|
|
3
|
-
declare const AutumnContext: react.Context<
|
|
4
|
-
declare const useAutumnContext: () =>
|
|
5
|
+
declare const AutumnContext: react.Context<AutumnContextParams>;
|
|
6
|
+
declare const useAutumnContext: () => AutumnContextParams;
|
|
5
7
|
|
|
6
8
|
export { AutumnContext, useAutumnContext };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
+
import { AutumnContextParams } from './types.js';
|
|
3
|
+
import './cusTypes-sGWmB2Vf.js';
|
|
2
4
|
|
|
3
|
-
declare const AutumnContext: react.Context<
|
|
4
|
-
declare const useAutumnContext: () =>
|
|
5
|
+
declare const AutumnContext: react.Context<AutumnContextParams>;
|
|
6
|
+
declare const useAutumnContext: () => AutumnContextParams;
|
|
5
7
|
|
|
6
8
|
export { AutumnContext, useAutumnContext };
|
|
@@ -8,8 +8,22 @@ const AutumnContext = createContext({
|
|
|
8
8
|
customer: null,
|
|
9
9
|
setCustomer: () => {
|
|
10
10
|
},
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
prodChangeDialog: {
|
|
12
|
+
found: false,
|
|
13
|
+
setProps: () => {
|
|
14
|
+
},
|
|
15
|
+
setOpen: () => {
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
paywallDialog: {
|
|
19
|
+
found: false,
|
|
20
|
+
setProps: () => {
|
|
21
|
+
},
|
|
22
|
+
setOpen: () => {
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
pricingTableProducts: null,
|
|
26
|
+
setPricingTableProducts: () => {
|
|
13
27
|
}
|
|
14
28
|
});
|
|
15
29
|
const useAutumnContext = () => {
|
|
@@ -8,8 +8,22 @@ const AutumnContext = createContext({
|
|
|
8
8
|
customer: null,
|
|
9
9
|
setCustomer: () => {
|
|
10
10
|
},
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
prodChangeDialog: {
|
|
12
|
+
found: false,
|
|
13
|
+
setProps: () => {
|
|
14
|
+
},
|
|
15
|
+
setOpen: () => {
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
paywallDialog: {
|
|
19
|
+
found: false,
|
|
20
|
+
setProps: () => {
|
|
21
|
+
},
|
|
22
|
+
setOpen: () => {
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
pricingTableProducts: null,
|
|
26
|
+
setPricingTableProducts: () => {
|
|
13
27
|
}
|
|
14
28
|
});
|
|
15
29
|
const useAutumnContext = () => {
|
|
@@ -38,6 +38,7 @@ const AutumnClientProvider = ({
|
|
|
38
38
|
components
|
|
39
39
|
}) => {
|
|
40
40
|
let [customer, setCustomer] = useState(null);
|
|
41
|
+
let [pricingTableProducts, setPricingTableProducts] = useState(null);
|
|
41
42
|
const [
|
|
42
43
|
prodChangeDialogFound,
|
|
43
44
|
prodChangeDialogProps,
|
|
@@ -69,7 +70,9 @@ const AutumnClientProvider = ({
|
|
|
69
70
|
found: paywallFound,
|
|
70
71
|
setProps: setPaywallProps,
|
|
71
72
|
setOpen: setPaywallOpen
|
|
72
|
-
}
|
|
73
|
+
},
|
|
74
|
+
pricingTableProducts,
|
|
75
|
+
setPricingTableProducts
|
|
73
76
|
},
|
|
74
77
|
children: [
|
|
75
78
|
components?.productChangeDialog && /* @__PURE__ */ jsx(
|
|
@@ -38,6 +38,7 @@ const AutumnClientProvider = ({
|
|
|
38
38
|
components
|
|
39
39
|
}) => {
|
|
40
40
|
let [customer, setCustomer] = useState(null);
|
|
41
|
+
let [pricingTableProducts, setPricingTableProducts] = useState(null);
|
|
41
42
|
const [
|
|
42
43
|
prodChangeDialogFound,
|
|
43
44
|
prodChangeDialogProps,
|
|
@@ -69,7 +70,9 @@ const AutumnClientProvider = ({
|
|
|
69
70
|
found: paywallFound,
|
|
70
71
|
setProps: setPaywallProps,
|
|
71
72
|
setOpen: setPaywallOpen
|
|
72
|
-
}
|
|
73
|
+
},
|
|
74
|
+
pricingTableProducts,
|
|
75
|
+
setPricingTableProducts
|
|
73
76
|
},
|
|
74
77
|
children: [
|
|
75
78
|
components?.productChangeDialog && /* @__PURE__ */ jsx(
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AutumnClientError, PricingTableProduct } from './types.mjs';
|
|
2
|
+
import './cusTypes-sGWmB2Vf.mjs';
|
|
3
|
+
|
|
4
|
+
declare const toClientErrorResponse: (error: any) => {
|
|
5
|
+
data: null;
|
|
6
|
+
error: AutumnClientError;
|
|
7
|
+
};
|
|
8
|
+
declare const fetchPricingTableData: ({ setIsLoading, setError, setProducts, encryptedCustomerId, }: {
|
|
9
|
+
setIsLoading?: (isLoading: boolean) => void;
|
|
10
|
+
setError?: (error: any) => void;
|
|
11
|
+
setProducts: (products: PricingTableProduct[]) => void;
|
|
12
|
+
encryptedCustomerId?: string;
|
|
13
|
+
}) => Promise<any>;
|
|
14
|
+
|
|
15
|
+
export { fetchPricingTableData, toClientErrorResponse };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AutumnClientError, PricingTableProduct } from './types.js';
|
|
2
|
+
import './cusTypes-sGWmB2Vf.js';
|
|
3
|
+
|
|
4
|
+
declare const toClientErrorResponse: (error: any) => {
|
|
5
|
+
data: null;
|
|
6
|
+
error: AutumnClientError;
|
|
7
|
+
};
|
|
8
|
+
declare const fetchPricingTableData: ({ setIsLoading, setError, setProducts, encryptedCustomerId, }: {
|
|
9
|
+
setIsLoading?: (isLoading: boolean) => void;
|
|
10
|
+
setError?: (error: any) => void;
|
|
11
|
+
setProducts: (products: PricingTableProduct[]) => void;
|
|
12
|
+
encryptedCustomerId?: string;
|
|
13
|
+
}) => Promise<any>;
|
|
14
|
+
|
|
15
|
+
export { fetchPricingTableData, toClientErrorResponse };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { getPricingTableAction } from "../server/componentActions";
|
|
4
|
+
import { AutumnClientError } from "./types";
|
|
5
|
+
const toClientErrorResponse = (error) => {
|
|
6
|
+
let msg = "Unknown error";
|
|
7
|
+
let code = "unknown";
|
|
8
|
+
if (error?.message) {
|
|
9
|
+
msg = error.message;
|
|
10
|
+
}
|
|
11
|
+
if (error?.code) {
|
|
12
|
+
code = error.code;
|
|
13
|
+
}
|
|
14
|
+
console.error("Autumn Error: ", msg);
|
|
15
|
+
return {
|
|
16
|
+
data: null,
|
|
17
|
+
error: new AutumnClientError({ message: msg, code })
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const fetchPricingTableData = async ({
|
|
21
|
+
setIsLoading,
|
|
22
|
+
setError,
|
|
23
|
+
setProducts,
|
|
24
|
+
encryptedCustomerId
|
|
25
|
+
}) => {
|
|
26
|
+
let returnData = null;
|
|
27
|
+
try {
|
|
28
|
+
if (setIsLoading) {
|
|
29
|
+
setIsLoading(true);
|
|
30
|
+
}
|
|
31
|
+
const res = await getPricingTableAction({
|
|
32
|
+
encryptedCustomerId
|
|
33
|
+
});
|
|
34
|
+
if (res.error) {
|
|
35
|
+
if (setError) {
|
|
36
|
+
setError(res.error);
|
|
37
|
+
}
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
let products = res.data.list;
|
|
41
|
+
setProducts(products);
|
|
42
|
+
returnData = products;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (setError) {
|
|
45
|
+
setError(error);
|
|
46
|
+
}
|
|
47
|
+
} finally {
|
|
48
|
+
if (setIsLoading) {
|
|
49
|
+
setIsLoading(false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return returnData;
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
fetchPricingTableData,
|
|
56
|
+
toClientErrorResponse
|
|
57
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { getPricingTableAction } from "../server/componentActions";
|
|
4
|
+
import { AutumnClientError } from "./types";
|
|
5
|
+
const toClientErrorResponse = (error) => {
|
|
6
|
+
let msg = "Unknown error";
|
|
7
|
+
let code = "unknown";
|
|
8
|
+
if (error?.message) {
|
|
9
|
+
msg = error.message;
|
|
10
|
+
}
|
|
11
|
+
if (error?.code) {
|
|
12
|
+
code = error.code;
|
|
13
|
+
}
|
|
14
|
+
console.error("Autumn Error: ", msg);
|
|
15
|
+
return {
|
|
16
|
+
data: null,
|
|
17
|
+
error: new AutumnClientError({ message: msg, code })
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const fetchPricingTableData = async ({
|
|
21
|
+
setIsLoading,
|
|
22
|
+
setError,
|
|
23
|
+
setProducts,
|
|
24
|
+
encryptedCustomerId
|
|
25
|
+
}) => {
|
|
26
|
+
let returnData = null;
|
|
27
|
+
try {
|
|
28
|
+
if (setIsLoading) {
|
|
29
|
+
setIsLoading(true);
|
|
30
|
+
}
|
|
31
|
+
const res = await getPricingTableAction({
|
|
32
|
+
encryptedCustomerId
|
|
33
|
+
});
|
|
34
|
+
if (res.error) {
|
|
35
|
+
if (setError) {
|
|
36
|
+
setError(res.error);
|
|
37
|
+
}
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
let products = res.data.list;
|
|
41
|
+
setProducts(products);
|
|
42
|
+
returnData = products;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (setError) {
|
|
45
|
+
setError(error);
|
|
46
|
+
}
|
|
47
|
+
} finally {
|
|
48
|
+
if (setIsLoading) {
|
|
49
|
+
setIsLoading(false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return returnData;
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
fetchPricingTableData,
|
|
56
|
+
toClientErrorResponse
|
|
57
|
+
};
|
|
@@ -11,7 +11,8 @@ declare enum ProductItemInterval {
|
|
|
11
11
|
Month = "month",
|
|
12
12
|
Quarter = "quarter",
|
|
13
13
|
SemiAnnual = "semi_annual",
|
|
14
|
-
Year = "year"
|
|
14
|
+
Year = "year",
|
|
15
|
+
Multiple = "multiple"
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
declare enum ProductStatus {
|
|
@@ -22,13 +23,21 @@ declare enum ProductStatus {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
interface CustomerFeature {
|
|
25
|
-
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
26
28
|
unlimited?: boolean;
|
|
27
29
|
interval?: ProductItemInterval | null;
|
|
28
30
|
balance?: number;
|
|
29
31
|
usage?: number;
|
|
30
32
|
included_usage?: number;
|
|
31
|
-
next_reset_at?: number;
|
|
33
|
+
next_reset_at?: number | null;
|
|
34
|
+
breakdown?: {
|
|
35
|
+
interval: ProductItemInterval;
|
|
36
|
+
balance?: number;
|
|
37
|
+
usage?: number;
|
|
38
|
+
included_usage?: number;
|
|
39
|
+
next_reset_at?: number;
|
|
40
|
+
}[];
|
|
32
41
|
}
|
|
33
42
|
interface CustomerProduct {
|
|
34
43
|
id: string;
|
|
@@ -42,17 +51,15 @@ interface CustomerProduct {
|
|
|
42
51
|
current_period_end?: number | null;
|
|
43
52
|
}
|
|
44
53
|
interface Customer {
|
|
45
|
-
autumn_id: string;
|
|
46
|
-
created_at: number;
|
|
47
|
-
env: AppEnv;
|
|
48
54
|
id: string | null;
|
|
55
|
+
created_at: number;
|
|
49
56
|
name: string | null;
|
|
50
57
|
email: string | null;
|
|
51
58
|
fingerprint: string | null;
|
|
52
59
|
stripe_id: string | null;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
features: CustomerFeature
|
|
60
|
+
env: AppEnv;
|
|
61
|
+
products: Record<string, CustomerProduct>;
|
|
62
|
+
features: Record<string, CustomerFeature>;
|
|
56
63
|
}
|
|
57
64
|
interface CustomerData {
|
|
58
65
|
name?: string;
|
|
@@ -11,7 +11,8 @@ declare enum ProductItemInterval {
|
|
|
11
11
|
Month = "month",
|
|
12
12
|
Quarter = "quarter",
|
|
13
13
|
SemiAnnual = "semi_annual",
|
|
14
|
-
Year = "year"
|
|
14
|
+
Year = "year",
|
|
15
|
+
Multiple = "multiple"
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
declare enum ProductStatus {
|
|
@@ -22,13 +23,21 @@ declare enum ProductStatus {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
interface CustomerFeature {
|
|
25
|
-
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
26
28
|
unlimited?: boolean;
|
|
27
29
|
interval?: ProductItemInterval | null;
|
|
28
30
|
balance?: number;
|
|
29
31
|
usage?: number;
|
|
30
32
|
included_usage?: number;
|
|
31
|
-
next_reset_at?: number;
|
|
33
|
+
next_reset_at?: number | null;
|
|
34
|
+
breakdown?: {
|
|
35
|
+
interval: ProductItemInterval;
|
|
36
|
+
balance?: number;
|
|
37
|
+
usage?: number;
|
|
38
|
+
included_usage?: number;
|
|
39
|
+
next_reset_at?: number;
|
|
40
|
+
}[];
|
|
32
41
|
}
|
|
33
42
|
interface CustomerProduct {
|
|
34
43
|
id: string;
|
|
@@ -42,17 +51,15 @@ interface CustomerProduct {
|
|
|
42
51
|
current_period_end?: number | null;
|
|
43
52
|
}
|
|
44
53
|
interface Customer {
|
|
45
|
-
autumn_id: string;
|
|
46
|
-
created_at: number;
|
|
47
|
-
env: AppEnv;
|
|
48
54
|
id: string | null;
|
|
55
|
+
created_at: number;
|
|
49
56
|
name: string | null;
|
|
50
57
|
email: string | null;
|
|
51
58
|
fingerprint: string | null;
|
|
52
59
|
stripe_id: string | null;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
features: CustomerFeature
|
|
60
|
+
env: AppEnv;
|
|
61
|
+
products: Record<string, CustomerProduct>;
|
|
62
|
+
features: Record<string, CustomerFeature>;
|
|
56
63
|
}
|
|
57
64
|
interface CustomerData {
|
|
58
65
|
name?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { A as AutumnError } from '../error-CG2LXoa7.mjs';
|
|
2
|
+
import { a as Customer } from '../cusTypes-sGWmB2Vf.mjs';
|
|
2
3
|
import { AttachParams } from './types.mjs';
|
|
3
4
|
|
|
4
5
|
declare const useAutumn: () => {
|
|
@@ -36,7 +37,7 @@ declare const useAutumn: () => {
|
|
|
36
37
|
* @deprecated Use the useCustomer() hook instead.
|
|
37
38
|
* This property is deprecated and will be removed in a future version.
|
|
38
39
|
*/
|
|
39
|
-
customer:
|
|
40
|
+
customer: Customer | null;
|
|
40
41
|
/**
|
|
41
42
|
* @deprecated Use the useCustomer() hook instead.
|
|
42
43
|
* This property is deprecated and will be removed in a future version.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { A as AutumnError } from '../error-CG2LXoa7.js';
|
|
2
|
+
import { a as Customer } from '../cusTypes-sGWmB2Vf.js';
|
|
2
3
|
import { AttachParams } from './types.js';
|
|
3
4
|
|
|
4
5
|
declare const useAutumn: () => {
|
|
@@ -36,7 +37,7 @@ declare const useAutumn: () => {
|
|
|
36
37
|
* @deprecated Use the useCustomer() hook instead.
|
|
37
38
|
* This property is deprecated and will be removed in a future version.
|
|
38
39
|
*/
|
|
39
|
-
customer:
|
|
40
|
+
customer: Customer | null;
|
|
40
41
|
/**
|
|
41
42
|
* @deprecated Use the useCustomer() hook instead.
|
|
42
43
|
* This property is deprecated and will be removed in a future version.
|
|
@@ -10,8 +10,15 @@ import {
|
|
|
10
10
|
} from "../../server/genActions";
|
|
11
11
|
import { useAutumnContext } from "../AutumnContext";
|
|
12
12
|
import { useCustomer } from "./useCustomer";
|
|
13
|
+
import { fetchPricingTableData, toClientErrorResponse } from "../clientUtils";
|
|
13
14
|
const useAutumn = () => {
|
|
14
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
encryptedCustomerId,
|
|
17
|
+
prodChangeDialog,
|
|
18
|
+
paywallDialog,
|
|
19
|
+
pricingTableProducts,
|
|
20
|
+
setPricingTableProducts
|
|
21
|
+
} = useAutumnContext();
|
|
15
22
|
const { customer, isLoading: loading, error, refetch } = useCustomer();
|
|
16
23
|
let {
|
|
17
24
|
found: prodChangeFound,
|
|
@@ -41,7 +48,7 @@ const useAutumn = () => {
|
|
|
41
48
|
metadata
|
|
42
49
|
});
|
|
43
50
|
} catch (error3) {
|
|
44
|
-
|
|
51
|
+
return toClientErrorResponse(error3);
|
|
45
52
|
} finally {
|
|
46
53
|
await callback?.();
|
|
47
54
|
}
|
|
@@ -52,24 +59,26 @@ const useAutumn = () => {
|
|
|
52
59
|
withPreview: "formatted"
|
|
53
60
|
});
|
|
54
61
|
if (error2) {
|
|
55
|
-
|
|
62
|
+
return toClientErrorResponse(error2);
|
|
56
63
|
}
|
|
57
64
|
let preview = data.preview;
|
|
58
65
|
if (!preview) {
|
|
59
|
-
await attachWithoutDialog();
|
|
66
|
+
return await attachWithoutDialog();
|
|
60
67
|
} else {
|
|
61
68
|
setProdChangeDialogProps({
|
|
62
69
|
title: preview.title,
|
|
63
70
|
message: preview.message,
|
|
64
71
|
items: preview.items,
|
|
72
|
+
dueToday: preview.due_today,
|
|
73
|
+
dueNextCycle: preview.due_next_cycle,
|
|
65
74
|
options: preview.options?.map((option) => ({
|
|
66
75
|
featureId: option.feature_id,
|
|
67
76
|
featureName: option.feature_name,
|
|
68
77
|
billingUnits: option.billing_units,
|
|
69
|
-
usageModel: option.usage_model
|
|
78
|
+
usageModel: option.usage_model,
|
|
79
|
+
price: option.price,
|
|
80
|
+
tiers: option.tiers
|
|
70
81
|
})),
|
|
71
|
-
dueToday: preview.due_today,
|
|
72
|
-
dueNextCycle: preview.due_next_cycle,
|
|
73
82
|
onClick: async (options) => {
|
|
74
83
|
if (!preview.error_on_attach) {
|
|
75
84
|
await attachWithoutDialog(options);
|
|
@@ -78,6 +87,7 @@ const useAutumn = () => {
|
|
|
78
87
|
}
|
|
79
88
|
});
|
|
80
89
|
}
|
|
90
|
+
return { data: null, error: null };
|
|
81
91
|
};
|
|
82
92
|
const attach = async ({
|
|
83
93
|
dialog = prodChangeFound || false,
|
|
@@ -89,14 +99,13 @@ const useAutumn = () => {
|
|
|
89
99
|
callback
|
|
90
100
|
}) => {
|
|
91
101
|
if (dialog) {
|
|
92
|
-
await attachWithDialog({
|
|
102
|
+
return await attachWithDialog({
|
|
93
103
|
productId,
|
|
94
104
|
successUrl,
|
|
95
105
|
forceCheckout,
|
|
96
106
|
metadata,
|
|
97
107
|
callback
|
|
98
108
|
});
|
|
99
|
-
return;
|
|
100
109
|
}
|
|
101
110
|
let snakeOptions = options?.map((option) => ({
|
|
102
111
|
feature_id: option.featureId,
|
|
@@ -111,7 +120,7 @@ const useAutumn = () => {
|
|
|
111
120
|
metadata
|
|
112
121
|
});
|
|
113
122
|
if (result.error) {
|
|
114
|
-
|
|
123
|
+
return toClientErrorResponse(result.error);
|
|
115
124
|
}
|
|
116
125
|
let data = result.data;
|
|
117
126
|
if (data?.checkout_url && typeof window !== "undefined") {
|
|
@@ -120,9 +129,20 @@ const useAutumn = () => {
|
|
|
120
129
|
try {
|
|
121
130
|
await callback?.();
|
|
122
131
|
} catch (error2) {
|
|
123
|
-
|
|
132
|
+
return toClientErrorResponse(error2);
|
|
124
133
|
}
|
|
125
|
-
|
|
134
|
+
if (pricingTableProducts) {
|
|
135
|
+
try {
|
|
136
|
+
await fetchPricingTableData({
|
|
137
|
+
setProducts: setPricingTableProducts,
|
|
138
|
+
encryptedCustomerId
|
|
139
|
+
});
|
|
140
|
+
} catch (error2) {
|
|
141
|
+
console.warn("Failed to fetch pricing table data");
|
|
142
|
+
console.warn(error2);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
126
146
|
};
|
|
127
147
|
const check = async ({
|
|
128
148
|
dialog = paywallFound || false,
|
|
@@ -140,8 +160,7 @@ const useAutumn = () => {
|
|
|
140
160
|
withPreview: dialog ? "formatted" : void 0
|
|
141
161
|
});
|
|
142
162
|
if (res.error) {
|
|
143
|
-
|
|
144
|
-
return res;
|
|
163
|
+
return toClientErrorResponse(res.error);
|
|
145
164
|
}
|
|
146
165
|
let data = res.data;
|
|
147
166
|
if (data && data.preview) {
|
|
@@ -150,10 +169,12 @@ const useAutumn = () => {
|
|
|
150
169
|
if (preview.upgrade_product_id) {
|
|
151
170
|
nextActionData = {
|
|
152
171
|
onClick: async () => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
172
|
+
if (preview.upgrade_product_id) {
|
|
173
|
+
await attach({
|
|
174
|
+
dialog: true,
|
|
175
|
+
productId: preview.upgrade_product_id
|
|
176
|
+
});
|
|
177
|
+
}
|
|
157
178
|
setPaywallDialogOpen(false);
|
|
158
179
|
},
|
|
159
180
|
buttonText: preview.button_text
|
|
@@ -173,10 +194,9 @@ const useAutumn = () => {
|
|
|
173
194
|
featureId
|
|
174
195
|
});
|
|
175
196
|
if (res.error) {
|
|
176
|
-
|
|
177
|
-
return res;
|
|
197
|
+
return toClientErrorResponse(res.error);
|
|
178
198
|
}
|
|
179
|
-
return res
|
|
199
|
+
return res;
|
|
180
200
|
};
|
|
181
201
|
const track = async ({
|
|
182
202
|
featureId,
|
|
@@ -188,10 +208,9 @@ const useAutumn = () => {
|
|
|
188
208
|
value
|
|
189
209
|
});
|
|
190
210
|
if (res.error) {
|
|
191
|
-
|
|
192
|
-
return res;
|
|
211
|
+
return toClientErrorResponse(res.error);
|
|
193
212
|
}
|
|
194
|
-
return res
|
|
213
|
+
return res;
|
|
195
214
|
};
|
|
196
215
|
const event = async ({
|
|
197
216
|
featureId,
|
|
@@ -203,7 +222,7 @@ const useAutumn = () => {
|
|
|
203
222
|
value
|
|
204
223
|
});
|
|
205
224
|
if (error2) {
|
|
206
|
-
|
|
225
|
+
return toClientErrorResponse(error2);
|
|
207
226
|
}
|
|
208
227
|
return data;
|
|
209
228
|
};
|
|
@@ -215,15 +234,14 @@ const useAutumn = () => {
|
|
|
215
234
|
}
|
|
216
235
|
});
|
|
217
236
|
if (result.error) {
|
|
218
|
-
|
|
219
|
-
return result;
|
|
237
|
+
return toClientErrorResponse(result.error);
|
|
220
238
|
}
|
|
221
239
|
let data = result.data;
|
|
222
240
|
if (data?.url && typeof window !== "undefined") {
|
|
223
241
|
window.open(data.url, "_blank");
|
|
224
|
-
return
|
|
242
|
+
return result;
|
|
225
243
|
} else {
|
|
226
|
-
return
|
|
244
|
+
return result;
|
|
227
245
|
}
|
|
228
246
|
};
|
|
229
247
|
return {
|