@kelviq/react-sdk 2.0.0-beta → 2.0.2-beta
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/contexts/KelviqContext.d.ts +9 -0
- package/dist/hooks/useCustomer.d.ts +9 -0
- package/dist/hooks/useSubscriptions.d.ts +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/kelviq-react-sdk.js +488 -297
- package/dist/kelviq-react-sdk.umd.cjs +1 -1
- package/dist/types/api.types.d.ts +63 -2
- package/dist/types/sdk.types.d.ts +10 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Entitlement, EntitlementMap, EntitlementsResponse } from '../types/sdk.types';
|
|
2
2
|
import { AsyncState } from '../types';
|
|
3
|
+
import { RawSubscriptionData, RawCustomerApiResponse } from '../types/api.types';
|
|
3
4
|
/** Defines the shape of the context value provided by KelviqProvider. */
|
|
4
5
|
export interface KelviqContextValue {
|
|
5
6
|
allEntitlements: AsyncState<EntitlementMap | null>;
|
|
@@ -14,6 +15,14 @@ export interface KelviqContextValue {
|
|
|
14
15
|
getRawEntitlement: (featureId: string) => EntitlementsResponse | null;
|
|
15
16
|
hasAccess: (featureId: string) => boolean;
|
|
16
17
|
updateEntitlement: (featureId: string, data: Partial<Omit<Entitlement, 'featureId' | 'featureType' | 'items'>>) => void;
|
|
18
|
+
/** Subscription data for the customer. Only populated when fetchSubscriptionsOnMount is true. */
|
|
19
|
+
subscriptions: AsyncState<RawSubscriptionData[] | null>;
|
|
20
|
+
/** Manually refresh subscriptions data. */
|
|
21
|
+
refreshSubscriptions: () => Promise<void>;
|
|
22
|
+
/** Customer data. Only populated when fetchCustomerOnMount is true. */
|
|
23
|
+
customer: AsyncState<RawCustomerApiResponse | null>;
|
|
24
|
+
/** Manually refresh customer data. */
|
|
25
|
+
refreshCustomer: () => Promise<void>;
|
|
17
26
|
isLoading: boolean;
|
|
18
27
|
error: Error | null;
|
|
19
28
|
customerId: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncState } from '../types';
|
|
2
|
+
import { RawCustomerApiResponse } from '../types/api.types';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get customer data.
|
|
5
|
+
* Only populated when `fetchCustomerOnMount` is enabled in the provider config,
|
|
6
|
+
* or after calling `refreshCustomer()` from `useKelviq()`.
|
|
7
|
+
* @returns AsyncState containing the customer data or null.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useCustomer: () => AsyncState<RawCustomerApiResponse | null>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncState } from '../types';
|
|
2
|
+
import { RawSubscriptionData } from '../types/api.types';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get the customer's subscription data.
|
|
5
|
+
* Only populated when `fetchSubscriptionsOnMount` is enabled in the provider config,
|
|
6
|
+
* or after calling `refreshSubscriptions()` from `useKelviq()`.
|
|
7
|
+
* @returns AsyncState containing the array of subscriptions or null.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useSubscriptions: () => AsyncState<RawSubscriptionData[] | null>;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,3 +9,5 @@ export * from './hooks/useAllEntitlements';
|
|
|
9
9
|
export * from './hooks/useBooleanEntitlement';
|
|
10
10
|
export * from './hooks/useCustomizableEntitlement';
|
|
11
11
|
export * from './hooks/useMeteredEntitlement';
|
|
12
|
+
export * from './hooks/useSubscriptions';
|
|
13
|
+
export * from './hooks/useCustomer';
|
package/dist/kelviq-react-sdk.js
CHANGED
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
1
|
+
import { jsx as S, Fragment as M } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as Q, useState as $, useCallback as w, useEffect as ee, useMemo as te, useContext as re } from "react";
|
|
3
|
+
const ne = "GET", se = 5e3, oe = 3, ie = 1e3;
|
|
4
|
+
function O(n) {
|
|
5
5
|
const {
|
|
6
|
-
method:
|
|
7
|
-
headers:
|
|
6
|
+
method: s = ne,
|
|
7
|
+
headers: o = {},
|
|
8
8
|
// Renamed to avoid conflict with internal 'headers' variable
|
|
9
|
-
body:
|
|
10
|
-
timeout: E =
|
|
11
|
-
maxRetries:
|
|
12
|
-
backoffBaseDelay:
|
|
13
|
-
queryParams:
|
|
14
|
-
accessToken:
|
|
9
|
+
body: t,
|
|
10
|
+
timeout: E = se,
|
|
11
|
+
maxRetries: g = oe,
|
|
12
|
+
backoffBaseDelay: v = ie,
|
|
13
|
+
queryParams: A,
|
|
14
|
+
accessToken: l
|
|
15
15
|
// Use the direct accessToken
|
|
16
|
-
} =
|
|
17
|
-
let { url:
|
|
18
|
-
return new Promise((
|
|
19
|
-
if (
|
|
20
|
-
const
|
|
21
|
-
for (const
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
} = n;
|
|
17
|
+
let { url: d } = n, L = 0;
|
|
18
|
+
return new Promise((R, P) => {
|
|
19
|
+
if (A) {
|
|
20
|
+
const a = new URLSearchParams();
|
|
21
|
+
for (const m in A)
|
|
22
|
+
A[m] !== void 0 && a.append(m, String(A[m]));
|
|
23
|
+
a.toString() && (d += (d.includes("?") ? "&" : "?") + a.toString());
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
25
|
+
function C() {
|
|
26
|
+
const a = new XMLHttpRequest();
|
|
27
|
+
a.open(s, d, !0), a.timeout = E;
|
|
28
|
+
const m = {
|
|
29
29
|
Accept: "application/json",
|
|
30
30
|
"X-Requested-With": "XMLHttpRequest",
|
|
31
|
-
...
|
|
31
|
+
...o
|
|
32
32
|
// Apply custom headers, allowing them to override defaults
|
|
33
33
|
};
|
|
34
|
-
|
|
35
|
-
for (const [i,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const { status: i, statusText:
|
|
34
|
+
s !== "GET" && t && typeof t == "object" && !(t instanceof FormData) && (m["Content-Type"] || (m["Content-Type"] = "application/json")), l && (m.Authorization = `Bearer ${l}`);
|
|
35
|
+
for (const [i, f] of Object.entries(m))
|
|
36
|
+
a.setRequestHeader(i, f);
|
|
37
|
+
a.onload = function() {
|
|
38
|
+
const { status: i, statusText: f, responseText: T } = a;
|
|
39
39
|
if (i >= 200 && i < 300)
|
|
40
40
|
try {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
} catch (
|
|
44
|
-
const
|
|
41
|
+
const b = T ? JSON.parse(T) : {};
|
|
42
|
+
R({ status: i, statusText: f, data: b });
|
|
43
|
+
} catch (b) {
|
|
44
|
+
const q = b instanceof Error ? b : new Error(String(b));
|
|
45
45
|
console.error(
|
|
46
|
-
`Kelviq SDK (apiRequest): Invalid JSON response for URL ${
|
|
47
|
-
),
|
|
46
|
+
`Kelviq SDK (apiRequest): Invalid JSON response for URL ${d}. Error: ${q.message}. Response: ${T}`
|
|
47
|
+
), P(
|
|
48
48
|
new Error(
|
|
49
|
-
`Invalid JSON response: ${
|
|
49
|
+
`Invalid JSON response: ${q.message}`
|
|
50
50
|
)
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
else
|
|
54
|
-
|
|
55
|
-
`Request to ${
|
|
54
|
+
p(
|
|
55
|
+
`Request to ${d} failed with status ${i} ${f}. Response: ${T}`
|
|
56
56
|
);
|
|
57
|
-
},
|
|
58
|
-
`Network error for URL ${
|
|
59
|
-
),
|
|
60
|
-
function
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
57
|
+
}, a.onerror = () => p(
|
|
58
|
+
`Network error for URL ${d}. The request could not be completed.`
|
|
59
|
+
), a.ontimeout = () => p(`Request to ${d} timed out.`);
|
|
60
|
+
function p(i) {
|
|
61
|
+
if (L < g) {
|
|
62
|
+
L++;
|
|
63
|
+
const f = Math.min(
|
|
64
|
+
v * Math.pow(2, L - 1),
|
|
65
65
|
3e4
|
|
66
66
|
// Cap retry delay at 30 seconds
|
|
67
67
|
);
|
|
68
68
|
console.warn(
|
|
69
|
-
`Kelviq SDK (apiRequest): Retrying request to ${
|
|
70
|
-
), setTimeout(
|
|
69
|
+
`Kelviq SDK (apiRequest): Retrying request to ${d}. Attempt ${L}/${g}. Error: ${i}. Retrying in ${f}ms.`
|
|
70
|
+
), setTimeout(C, f);
|
|
71
71
|
} else
|
|
72
|
-
|
|
72
|
+
P(
|
|
73
73
|
new Error(
|
|
74
|
-
`${i} (Max retries ${
|
|
74
|
+
`${i} (Max retries ${g} reached)`
|
|
75
75
|
)
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
try {
|
|
79
|
-
let i =
|
|
80
|
-
|
|
79
|
+
let i = t;
|
|
80
|
+
t && typeof t == "object" && !(t instanceof FormData) && m["Content-Type"] === "application/json" && (i = JSON.stringify(t)), a.send(i);
|
|
81
81
|
} catch (i) {
|
|
82
|
-
const
|
|
82
|
+
const f = i instanceof Error ? i : new Error(String(i));
|
|
83
83
|
console.error(
|
|
84
|
-
`Kelviq SDK (apiRequest): Error sending request to ${
|
|
85
|
-
|
|
86
|
-
),
|
|
84
|
+
`Kelviq SDK (apiRequest): Error sending request to ${d}.`,
|
|
85
|
+
f
|
|
86
|
+
), P(new Error(`Failed to send request: ${f.message}`));
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
C();
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
let
|
|
96
|
-
for (const
|
|
97
|
-
const
|
|
98
|
-
|
|
92
|
+
function ae(n, s) {
|
|
93
|
+
const o = s[0].featureType;
|
|
94
|
+
if (o === "METER") {
|
|
95
|
+
let t = 0, E = 0, g = !1;
|
|
96
|
+
for (const A of s) {
|
|
97
|
+
const l = A, d = typeof l.usageLimit == "number" ? l.usageLimit : null, L = typeof l.currentUsage == "number" ? l.currentUsage : 0;
|
|
98
|
+
d === null && (t = null), t !== null && (t += d), E += L, l.hardLimit && (g = !0);
|
|
99
99
|
}
|
|
100
|
-
const
|
|
100
|
+
const v = t !== null ? t - E : null;
|
|
101
101
|
return {
|
|
102
|
-
featureId:
|
|
103
|
-
featureType:
|
|
104
|
-
hasAccess:
|
|
102
|
+
featureId: n,
|
|
103
|
+
featureType: o,
|
|
104
|
+
hasAccess: v === null || v > 0,
|
|
105
105
|
currentUsage: E,
|
|
106
|
-
usageLimit:
|
|
107
|
-
remaining:
|
|
108
|
-
hardLimit:
|
|
109
|
-
items:
|
|
106
|
+
usageLimit: t,
|
|
107
|
+
remaining: v,
|
|
108
|
+
hardLimit: g,
|
|
109
|
+
items: s
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
if (
|
|
113
|
-
const
|
|
112
|
+
if (o === "CUSTOMIZABLE") {
|
|
113
|
+
const t = s[0];
|
|
114
114
|
return {
|
|
115
|
-
featureId:
|
|
116
|
-
featureType:
|
|
117
|
-
hasAccess:
|
|
118
|
-
currentUsage: typeof
|
|
119
|
-
usageLimit: typeof
|
|
120
|
-
remaining: typeof
|
|
121
|
-
hardLimit:
|
|
122
|
-
items:
|
|
115
|
+
featureId: n,
|
|
116
|
+
featureType: o,
|
|
117
|
+
hasAccess: s.some((E) => E.hasAccess),
|
|
118
|
+
currentUsage: typeof t.currentUsage == "number" ? t.currentUsage : 0,
|
|
119
|
+
usageLimit: typeof t.usageLimit == "number" ? t.usageLimit : null,
|
|
120
|
+
remaining: typeof t.remaining == "number" ? t.remaining : null,
|
|
121
|
+
hardLimit: t.hardLimit === !0,
|
|
122
|
+
items: s
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
return {
|
|
126
|
-
featureId:
|
|
127
|
-
featureType:
|
|
128
|
-
hasAccess:
|
|
126
|
+
featureId: n,
|
|
127
|
+
featureType: o,
|
|
128
|
+
hasAccess: s.some((t) => t.hasAccess),
|
|
129
129
|
currentUsage: 0,
|
|
130
130
|
usageLimit: null,
|
|
131
131
|
remaining: null,
|
|
132
132
|
hardLimit: !1,
|
|
133
|
-
items:
|
|
133
|
+
items: s
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
|
-
function
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
136
|
+
function le(n) {
|
|
137
|
+
const s = {};
|
|
138
|
+
if (!n || !Array.isArray(n.entitlements))
|
|
139
139
|
return console.warn(
|
|
140
140
|
"Kelviq SDK: Invalid or empty entitlements array in API response.",
|
|
141
|
-
|
|
142
|
-
),
|
|
143
|
-
const
|
|
144
|
-
for (const
|
|
145
|
-
if (!
|
|
141
|
+
n
|
|
142
|
+
), s;
|
|
143
|
+
const o = {};
|
|
144
|
+
for (const t of n.entitlements) {
|
|
145
|
+
if (!t || typeof t.featureId != "string" || typeof t.featureType != "string") {
|
|
146
146
|
console.warn(
|
|
147
147
|
"Kelviq SDK: Skipping invalid raw entitlement object:",
|
|
148
|
-
|
|
148
|
+
t
|
|
149
149
|
);
|
|
150
150
|
continue;
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
o[t.featureId] || (o[t.featureId] = []), o[t.featureId].push(t);
|
|
153
153
|
}
|
|
154
|
-
for (const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
for (const t in o)
|
|
155
|
+
s[t] = ae(
|
|
156
|
+
t,
|
|
157
|
+
o[t]
|
|
158
158
|
);
|
|
159
|
-
return
|
|
159
|
+
return s;
|
|
160
160
|
}
|
|
161
|
-
const
|
|
161
|
+
const V = {
|
|
162
162
|
allEntitlements: {
|
|
163
163
|
data: null,
|
|
164
164
|
isLoading: !0,
|
|
@@ -177,281 +177,472 @@ const B = {
|
|
|
177
177
|
"updateEntitlement called on default KelviqContext. Ensure KelviqProvider is properly set up."
|
|
178
178
|
);
|
|
179
179
|
},
|
|
180
|
+
subscriptions: {
|
|
181
|
+
data: null,
|
|
182
|
+
isLoading: !1,
|
|
183
|
+
error: null
|
|
184
|
+
},
|
|
185
|
+
refreshSubscriptions: () => (console.warn(
|
|
186
|
+
"refreshSubscriptions called on default KelviqContext. Ensure KelviqProvider is properly set up."
|
|
187
|
+
), Promise.resolve()),
|
|
188
|
+
customer: {
|
|
189
|
+
data: null,
|
|
190
|
+
isLoading: !1,
|
|
191
|
+
error: null
|
|
192
|
+
},
|
|
193
|
+
refreshCustomer: () => (console.warn(
|
|
194
|
+
"refreshCustomer called on default KelviqContext. Ensure KelviqProvider is properly set up."
|
|
195
|
+
), Promise.resolve()),
|
|
180
196
|
isLoading: !0,
|
|
181
197
|
error: null,
|
|
182
198
|
apiUrl: "",
|
|
183
199
|
environment: "production",
|
|
184
200
|
entitlementsPath: "",
|
|
185
201
|
customerId: ""
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
),
|
|
189
|
-
children:
|
|
190
|
-
apiUrl:
|
|
191
|
-
entitlementsPath:
|
|
192
|
-
customerId:
|
|
202
|
+
}, Y = Q(
|
|
203
|
+
V
|
|
204
|
+
), ue = "https://edge.api.kelviq.com/api/v1/", ce = "https://edge.sandboxapi.kelviq.com/api/v1/", de = "https://api.kelviq.com/api/v1/", fe = "https://sandboxapi.kelviq.com/api/v1/", me = "entitlements/", pe = ({
|
|
205
|
+
children: n,
|
|
206
|
+
apiUrl: s,
|
|
207
|
+
entitlementsPath: o = me,
|
|
208
|
+
customerId: t,
|
|
193
209
|
environment: E = "production",
|
|
194
|
-
accessToken:
|
|
195
|
-
config:
|
|
210
|
+
accessToken: g,
|
|
211
|
+
config: v = {}
|
|
196
212
|
}) => {
|
|
197
213
|
const {
|
|
198
|
-
onError:
|
|
199
|
-
maxRetries:
|
|
200
|
-
timeout:
|
|
201
|
-
backoffBaseDelay:
|
|
202
|
-
fetchEntitlementsOnMount:
|
|
203
|
-
|
|
214
|
+
onError: A,
|
|
215
|
+
maxRetries: l,
|
|
216
|
+
timeout: d,
|
|
217
|
+
backoffBaseDelay: L,
|
|
218
|
+
fetchEntitlementsOnMount: R = !0,
|
|
219
|
+
fetchSubscriptionsOnMount: P = !1,
|
|
220
|
+
fetchCustomerOnMount: C = !1
|
|
221
|
+
} = v, a = s || (E === "sandbox" ? ce : ue), m = E === "sandbox" ? fe : de, [p, i] = $({
|
|
222
|
+
data: null,
|
|
223
|
+
isLoading: !!a && R,
|
|
224
|
+
error: null
|
|
225
|
+
}), [f, T] = $(null), [b, q] = $({
|
|
226
|
+
data: null,
|
|
227
|
+
isLoading: !!a && P,
|
|
228
|
+
error: null
|
|
229
|
+
}), [N, I] = $({
|
|
204
230
|
data: null,
|
|
205
|
-
isLoading: !!
|
|
231
|
+
isLoading: !!a && C,
|
|
206
232
|
error: null
|
|
207
|
-
}), [
|
|
208
|
-
!!
|
|
209
|
-
), [
|
|
210
|
-
(
|
|
211
|
-
const
|
|
212
|
-
`Kelviq SDK (${
|
|
233
|
+
}), [D, U] = $(
|
|
234
|
+
!!a && R
|
|
235
|
+
), [k, x] = $(null), h = w(
|
|
236
|
+
(u, e, r) => {
|
|
237
|
+
const c = new Error(
|
|
238
|
+
`Kelviq SDK (${e}): ${u}`
|
|
213
239
|
);
|
|
214
|
-
console.error(
|
|
240
|
+
console.error(c.message, r || ""), x((y) => y || c), A && A(c);
|
|
215
241
|
},
|
|
216
|
-
[
|
|
217
|
-
),
|
|
218
|
-
if (!
|
|
219
|
-
const
|
|
220
|
-
return
|
|
242
|
+
[A]
|
|
243
|
+
), _ = w(() => {
|
|
244
|
+
if (!a) {
|
|
245
|
+
const r = "API URL not configured. Cannot fetch entitlements.";
|
|
246
|
+
return i({
|
|
221
247
|
data: null,
|
|
222
248
|
isLoading: !1,
|
|
223
|
-
error: new Error(
|
|
224
|
-
}),
|
|
249
|
+
error: new Error(r)
|
|
250
|
+
}), h(r, "fetchAllEntitlements"), U(!1), Promise.reject(new Error(r));
|
|
225
251
|
}
|
|
226
|
-
if (!
|
|
227
|
-
const
|
|
228
|
-
return
|
|
252
|
+
if (!t) {
|
|
253
|
+
const r = "CustomerId must be provided as props to KelviqProvider.";
|
|
254
|
+
return i(() => ({
|
|
229
255
|
data: null,
|
|
230
256
|
isLoading: !1,
|
|
231
|
-
error: new Error(
|
|
232
|
-
})),
|
|
257
|
+
error: new Error(r)
|
|
258
|
+
})), h(r, "fetchAllEntitlements"), U(!1), Promise.reject(new Error(r));
|
|
233
259
|
}
|
|
234
|
-
|
|
235
|
-
...
|
|
260
|
+
i((r) => ({
|
|
261
|
+
...r,
|
|
236
262
|
isLoading: !0,
|
|
237
263
|
error: null
|
|
238
|
-
})),
|
|
239
|
-
const
|
|
240
|
-
return
|
|
241
|
-
url:
|
|
264
|
+
})), U(!0), x(null);
|
|
265
|
+
const u = `${a.replace(/\/$/, "")}/${o.replace(/^\//, "")}`;
|
|
266
|
+
return O({
|
|
267
|
+
url: u,
|
|
242
268
|
method: "GET",
|
|
243
|
-
timeout:
|
|
244
|
-
maxRetries:
|
|
245
|
-
backoffBaseDelay:
|
|
246
|
-
accessToken:
|
|
269
|
+
timeout: d,
|
|
270
|
+
maxRetries: l,
|
|
271
|
+
backoffBaseDelay: L,
|
|
272
|
+
accessToken: g,
|
|
247
273
|
queryParams: {
|
|
248
|
-
customer_id:
|
|
274
|
+
customer_id: t
|
|
249
275
|
}
|
|
250
|
-
}).then((
|
|
251
|
-
if (
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
|
|
276
|
+
}).then((r) => {
|
|
277
|
+
if (r && r.data && Array.isArray(r.data.entitlements)) {
|
|
278
|
+
T(r.data);
|
|
279
|
+
const c = le(
|
|
280
|
+
r.data
|
|
255
281
|
);
|
|
256
|
-
|
|
257
|
-
data:
|
|
282
|
+
i({
|
|
283
|
+
data: c,
|
|
258
284
|
isLoading: !1,
|
|
259
285
|
error: null
|
|
260
286
|
});
|
|
261
287
|
} else {
|
|
262
|
-
const
|
|
288
|
+
const c = new Error(
|
|
263
289
|
"Received empty, malformed, or invalid data structure from entitlements API."
|
|
264
290
|
);
|
|
265
|
-
throw
|
|
291
|
+
throw i({
|
|
266
292
|
data: null,
|
|
267
293
|
isLoading: !1,
|
|
268
|
-
error:
|
|
269
|
-
}),
|
|
270
|
-
|
|
294
|
+
error: c
|
|
295
|
+
}), h(
|
|
296
|
+
c.message,
|
|
271
297
|
"fetchAllEntitlements",
|
|
272
|
-
|
|
273
|
-
),
|
|
298
|
+
r
|
|
299
|
+
), c;
|
|
274
300
|
}
|
|
275
|
-
}).catch((
|
|
276
|
-
const
|
|
277
|
-
return
|
|
278
|
-
...
|
|
301
|
+
}).catch((r) => {
|
|
302
|
+
const c = r instanceof Error ? r : new Error(String(r));
|
|
303
|
+
return i((y) => ({
|
|
304
|
+
...y,
|
|
279
305
|
isLoading: !1,
|
|
280
|
-
error:
|
|
281
|
-
})),
|
|
306
|
+
error: c
|
|
307
|
+
})), h(c.message, "fetchAllEntitlements", r), Promise.reject(c);
|
|
282
308
|
}).finally(() => {
|
|
283
|
-
|
|
309
|
+
U(!1);
|
|
284
310
|
});
|
|
285
311
|
}, [
|
|
286
|
-
p,
|
|
287
|
-
e,
|
|
288
|
-
s,
|
|
289
|
-
f,
|
|
290
312
|
a,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
313
|
+
t,
|
|
314
|
+
o,
|
|
315
|
+
d,
|
|
316
|
+
l,
|
|
317
|
+
L,
|
|
318
|
+
g,
|
|
319
|
+
h
|
|
320
|
+
]), j = w(() => {
|
|
321
|
+
if (!m) {
|
|
322
|
+
const e = "Main API URL not configured. Cannot fetch subscriptions.";
|
|
323
|
+
return q({
|
|
324
|
+
data: null,
|
|
325
|
+
isLoading: !1,
|
|
326
|
+
error: new Error(e)
|
|
327
|
+
}), h(e, "fetchSubscriptions"), Promise.reject(new Error(e));
|
|
328
|
+
}
|
|
329
|
+
if (!t) {
|
|
330
|
+
const e = "CustomerId must be provided as props to KelviqProvider.";
|
|
331
|
+
return q({
|
|
332
|
+
data: null,
|
|
333
|
+
isLoading: !1,
|
|
334
|
+
error: new Error(e)
|
|
335
|
+
}), h(e, "fetchSubscriptions"), Promise.reject(new Error(e));
|
|
336
|
+
}
|
|
337
|
+
q((e) => ({
|
|
338
|
+
...e,
|
|
339
|
+
isLoading: !0,
|
|
340
|
+
error: null
|
|
341
|
+
}));
|
|
342
|
+
const u = `${m.replace(/\/$/, "")}/subscriptions/`;
|
|
343
|
+
return O({
|
|
344
|
+
url: u,
|
|
345
|
+
method: "GET",
|
|
346
|
+
timeout: d,
|
|
347
|
+
maxRetries: l,
|
|
348
|
+
backoffBaseDelay: L,
|
|
349
|
+
accessToken: g,
|
|
350
|
+
queryParams: { customer_id: t }
|
|
351
|
+
}).then((e) => {
|
|
352
|
+
if (e && e.data && Array.isArray(e.data.results))
|
|
353
|
+
q({
|
|
354
|
+
data: e.data.results,
|
|
355
|
+
isLoading: !1,
|
|
356
|
+
error: null
|
|
357
|
+
});
|
|
358
|
+
else {
|
|
359
|
+
const r = new Error(
|
|
360
|
+
"Received empty, malformed, or invalid data structure from subscriptions API."
|
|
361
|
+
);
|
|
362
|
+
throw q({
|
|
363
|
+
data: null,
|
|
364
|
+
isLoading: !1,
|
|
365
|
+
error: r
|
|
366
|
+
}), h(
|
|
367
|
+
r.message,
|
|
368
|
+
"fetchSubscriptions",
|
|
369
|
+
e
|
|
370
|
+
), r;
|
|
371
|
+
}
|
|
372
|
+
}).catch((e) => {
|
|
373
|
+
const r = e instanceof Error ? e : new Error(String(e));
|
|
374
|
+
return q((c) => ({
|
|
375
|
+
...c,
|
|
376
|
+
isLoading: !1,
|
|
377
|
+
error: r
|
|
378
|
+
})), h(
|
|
379
|
+
r.message,
|
|
380
|
+
"fetchSubscriptions",
|
|
381
|
+
e
|
|
382
|
+
), Promise.reject(r);
|
|
383
|
+
});
|
|
384
|
+
}, [
|
|
385
|
+
m,
|
|
386
|
+
t,
|
|
387
|
+
d,
|
|
388
|
+
l,
|
|
389
|
+
L,
|
|
390
|
+
g,
|
|
391
|
+
h
|
|
392
|
+
]), F = w(() => {
|
|
393
|
+
if (!m) {
|
|
394
|
+
const e = "Main API URL not configured. Cannot fetch customer.";
|
|
395
|
+
return I({
|
|
396
|
+
data: null,
|
|
397
|
+
isLoading: !1,
|
|
398
|
+
error: new Error(e)
|
|
399
|
+
}), h(e, "fetchCustomer"), Promise.reject(new Error(e));
|
|
400
|
+
}
|
|
401
|
+
if (!t) {
|
|
402
|
+
const e = "CustomerId must be provided as props to KelviqProvider.";
|
|
403
|
+
return I({
|
|
404
|
+
data: null,
|
|
405
|
+
isLoading: !1,
|
|
406
|
+
error: new Error(e)
|
|
407
|
+
}), h(e, "fetchCustomer"), Promise.reject(new Error(e));
|
|
408
|
+
}
|
|
409
|
+
I((e) => ({
|
|
410
|
+
...e,
|
|
411
|
+
isLoading: !0,
|
|
412
|
+
error: null
|
|
413
|
+
}));
|
|
414
|
+
const u = `${m.replace(/\/$/, "")}/customers/${t}/`;
|
|
415
|
+
return O({
|
|
416
|
+
url: u,
|
|
417
|
+
method: "GET",
|
|
418
|
+
timeout: d,
|
|
419
|
+
maxRetries: l,
|
|
420
|
+
backoffBaseDelay: L,
|
|
421
|
+
accessToken: g
|
|
422
|
+
}).then((e) => {
|
|
423
|
+
if (e && e.data)
|
|
424
|
+
I({
|
|
425
|
+
data: e.data,
|
|
426
|
+
isLoading: !1,
|
|
427
|
+
error: null
|
|
428
|
+
});
|
|
429
|
+
else {
|
|
430
|
+
const r = new Error(
|
|
431
|
+
"Received empty or invalid data from customer API."
|
|
432
|
+
);
|
|
433
|
+
throw I({
|
|
434
|
+
data: null,
|
|
435
|
+
isLoading: !1,
|
|
436
|
+
error: r
|
|
437
|
+
}), h(
|
|
438
|
+
r.message,
|
|
439
|
+
"fetchCustomer",
|
|
440
|
+
e
|
|
441
|
+
), r;
|
|
442
|
+
}
|
|
443
|
+
}).catch((e) => {
|
|
444
|
+
const r = e instanceof Error ? e : new Error(String(e));
|
|
445
|
+
return I((c) => ({
|
|
446
|
+
...c,
|
|
447
|
+
isLoading: !1,
|
|
448
|
+
error: r
|
|
449
|
+
})), h(r.message, "fetchCustomer", e), Promise.reject(r);
|
|
450
|
+
});
|
|
451
|
+
}, [
|
|
452
|
+
m,
|
|
453
|
+
t,
|
|
454
|
+
d,
|
|
455
|
+
l,
|
|
456
|
+
L,
|
|
457
|
+
g,
|
|
458
|
+
h
|
|
294
459
|
]);
|
|
295
|
-
|
|
296
|
-
let
|
|
297
|
-
if (!
|
|
298
|
-
if (
|
|
299
|
-
const
|
|
460
|
+
ee(() => {
|
|
461
|
+
let u = !0;
|
|
462
|
+
if (!a) {
|
|
463
|
+
if (u) {
|
|
464
|
+
const e = new Error(
|
|
300
465
|
"KelviqProvider: `apiBaseUrl` must be provided in config."
|
|
301
466
|
);
|
|
302
|
-
|
|
303
|
-
...
|
|
467
|
+
x(e), U(!1), i((r) => ({
|
|
468
|
+
...r,
|
|
304
469
|
isLoading: !1,
|
|
305
|
-
error:
|
|
306
|
-
})),
|
|
470
|
+
error: e
|
|
471
|
+
})), v.onError && v.onError(e);
|
|
307
472
|
}
|
|
308
473
|
return;
|
|
309
474
|
}
|
|
310
|
-
return
|
|
311
|
-
|
|
475
|
+
return R ? _().catch((e) => {
|
|
476
|
+
u && D && U(!1), console.error(
|
|
312
477
|
"Kelviq SDK: Initial entitlement fetch failed.",
|
|
313
|
-
|
|
478
|
+
e
|
|
314
479
|
);
|
|
315
|
-
}) :
|
|
316
|
-
...
|
|
480
|
+
}) : u && (i((e) => ({
|
|
481
|
+
...e,
|
|
317
482
|
isLoading: !1,
|
|
318
483
|
data: null,
|
|
319
484
|
error: null
|
|
320
|
-
})),
|
|
321
|
-
|
|
485
|
+
})), U(!1)), P && j().catch((e) => {
|
|
486
|
+
console.error(
|
|
487
|
+
"Kelviq SDK: Initial subscriptions fetch failed.",
|
|
488
|
+
e
|
|
489
|
+
);
|
|
490
|
+
}), C && F().catch((e) => {
|
|
491
|
+
console.error(
|
|
492
|
+
"Kelviq SDK: Initial customer fetch failed.",
|
|
493
|
+
e
|
|
494
|
+
);
|
|
495
|
+
}), () => {
|
|
496
|
+
u = !1;
|
|
322
497
|
};
|
|
323
|
-
}, [
|
|
324
|
-
const
|
|
325
|
-
() =>
|
|
326
|
-
[
|
|
327
|
-
),
|
|
328
|
-
() =>
|
|
329
|
-
customerId:
|
|
330
|
-
entitlements:
|
|
498
|
+
}, [a, R, P, C, v.onError]);
|
|
499
|
+
const G = w(
|
|
500
|
+
() => p.data ? p.data : {},
|
|
501
|
+
[p.data]
|
|
502
|
+
), H = w(
|
|
503
|
+
() => f ? {
|
|
504
|
+
customerId: f.customerId,
|
|
505
|
+
entitlements: f.entitlements
|
|
331
506
|
} : null,
|
|
332
|
-
[
|
|
333
|
-
),
|
|
334
|
-
(
|
|
335
|
-
customerId:
|
|
336
|
-
entitlements:
|
|
337
|
-
(
|
|
507
|
+
[f]
|
|
508
|
+
), X = w(
|
|
509
|
+
(u) => f ? {
|
|
510
|
+
customerId: f.customerId,
|
|
511
|
+
entitlements: f.entitlements.filter(
|
|
512
|
+
(e) => e.featureId === u
|
|
338
513
|
)
|
|
339
514
|
} : null,
|
|
340
|
-
[
|
|
341
|
-
),
|
|
342
|
-
(
|
|
343
|
-
[
|
|
344
|
-
),
|
|
345
|
-
(
|
|
346
|
-
|
|
347
|
-
if (!
|
|
348
|
-
const
|
|
349
|
-
if (!
|
|
350
|
-
const
|
|
351
|
-
return ("usageLimit" in
|
|
352
|
-
...
|
|
515
|
+
[f]
|
|
516
|
+
), W = w(
|
|
517
|
+
(u) => p.data ? p.data[u] ?? null : null,
|
|
518
|
+
[p.data]
|
|
519
|
+
), z = w(
|
|
520
|
+
(u, e) => {
|
|
521
|
+
i((r) => {
|
|
522
|
+
if (!r.data) return r;
|
|
523
|
+
const c = r.data[u];
|
|
524
|
+
if (!c) return r;
|
|
525
|
+
const y = { ...c, ...e };
|
|
526
|
+
return ("usageLimit" in e || "currentUsage" in e) && (y.remaining = y.usageLimit !== null ? y.usageLimit - y.currentUsage : null), {
|
|
527
|
+
...r,
|
|
353
528
|
data: {
|
|
354
|
-
...
|
|
355
|
-
[
|
|
529
|
+
...r.data,
|
|
530
|
+
[u]: y
|
|
356
531
|
}
|
|
357
532
|
};
|
|
358
533
|
});
|
|
359
534
|
},
|
|
360
535
|
[]
|
|
361
|
-
),
|
|
362
|
-
(
|
|
363
|
-
if (!
|
|
364
|
-
const
|
|
365
|
-
return
|
|
536
|
+
), J = w(
|
|
537
|
+
(u) => {
|
|
538
|
+
if (!p.data) return !1;
|
|
539
|
+
const e = p.data[u];
|
|
540
|
+
return e ? e.hasAccess : !1;
|
|
366
541
|
},
|
|
367
|
-
[
|
|
368
|
-
),
|
|
542
|
+
[p.data]
|
|
543
|
+
), Z = te(
|
|
369
544
|
() => ({
|
|
370
|
-
allEntitlements:
|
|
371
|
-
refreshAllEntitlements:
|
|
372
|
-
getEntitlements:
|
|
373
|
-
getEntitlement:
|
|
374
|
-
getRawEntitlements:
|
|
375
|
-
getRawEntitlement:
|
|
376
|
-
hasAccess:
|
|
377
|
-
updateEntitlement:
|
|
378
|
-
|
|
379
|
-
|
|
545
|
+
allEntitlements: p,
|
|
546
|
+
refreshAllEntitlements: _,
|
|
547
|
+
getEntitlements: G,
|
|
548
|
+
getEntitlement: W,
|
|
549
|
+
getRawEntitlements: H,
|
|
550
|
+
getRawEntitlement: X,
|
|
551
|
+
hasAccess: J,
|
|
552
|
+
updateEntitlement: z,
|
|
553
|
+
subscriptions: b,
|
|
554
|
+
refreshSubscriptions: j,
|
|
555
|
+
customer: N,
|
|
556
|
+
refreshCustomer: F,
|
|
557
|
+
isLoading: D,
|
|
558
|
+
error: k,
|
|
380
559
|
environment: E,
|
|
381
|
-
apiUrl:
|
|
382
|
-
entitlementsPath:
|
|
383
|
-
customerId:
|
|
560
|
+
apiUrl: a,
|
|
561
|
+
entitlementsPath: o,
|
|
562
|
+
customerId: t
|
|
384
563
|
}),
|
|
385
564
|
[
|
|
386
|
-
|
|
387
|
-
b,
|
|
388
|
-
x,
|
|
565
|
+
p,
|
|
389
566
|
_,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
567
|
+
G,
|
|
568
|
+
W,
|
|
569
|
+
H,
|
|
570
|
+
X,
|
|
571
|
+
J,
|
|
572
|
+
z,
|
|
573
|
+
b,
|
|
574
|
+
j,
|
|
575
|
+
N,
|
|
393
576
|
F,
|
|
394
|
-
|
|
395
|
-
|
|
577
|
+
D,
|
|
578
|
+
k,
|
|
396
579
|
E,
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
580
|
+
a,
|
|
581
|
+
o,
|
|
582
|
+
t
|
|
400
583
|
]
|
|
401
584
|
);
|
|
402
|
-
return /* @__PURE__ */
|
|
403
|
-
},
|
|
404
|
-
const
|
|
405
|
-
if (
|
|
585
|
+
return /* @__PURE__ */ S(Y.Provider, { value: Z, children: n });
|
|
586
|
+
}, K = () => {
|
|
587
|
+
const n = re(Y);
|
|
588
|
+
if (n === void 0 || n === V)
|
|
406
589
|
throw new Error(
|
|
407
590
|
"useKelviq must be used within an initialized KelviqProvider."
|
|
408
591
|
);
|
|
409
|
-
return
|
|
410
|
-
},
|
|
411
|
-
featureId:
|
|
412
|
-
children:
|
|
413
|
-
fallback:
|
|
414
|
-
loadingComponent:
|
|
592
|
+
return n;
|
|
593
|
+
}, B = ({
|
|
594
|
+
featureId: n,
|
|
595
|
+
children: s,
|
|
596
|
+
fallback: o = null,
|
|
597
|
+
loadingComponent: t,
|
|
415
598
|
condition: E
|
|
416
599
|
}) => {
|
|
417
600
|
const {
|
|
418
|
-
getEntitlement:
|
|
419
|
-
isLoading:
|
|
420
|
-
error:
|
|
421
|
-
} =
|
|
422
|
-
return
|
|
423
|
-
},
|
|
424
|
-
const
|
|
425
|
-
return /* @__PURE__ */
|
|
426
|
-
|
|
601
|
+
getEntitlement: g,
|
|
602
|
+
isLoading: v,
|
|
603
|
+
error: A
|
|
604
|
+
} = K(), l = g(n);
|
|
605
|
+
return v && !l ? /* @__PURE__ */ S(M, { children: t !== void 0 ? t : o }) : A && !l ? /* @__PURE__ */ S(M, { children: o }) : !l || !l.hasAccess || E && !E(l) ? /* @__PURE__ */ S(M, { children: o }) : typeof s == "function" ? /* @__PURE__ */ S(M, { children: s(l) }) : /* @__PURE__ */ S(M, { children: s });
|
|
606
|
+
}, he = (n) => /* @__PURE__ */ S(B, { ...n }), Le = (n) => {
|
|
607
|
+
const s = (o) => o.hasAccess && (o.remaining === null || o.remaining > 0);
|
|
608
|
+
return /* @__PURE__ */ S(
|
|
609
|
+
B,
|
|
427
610
|
{
|
|
428
|
-
...
|
|
429
|
-
condition:
|
|
611
|
+
...n,
|
|
612
|
+
condition: n.condition || s
|
|
430
613
|
}
|
|
431
614
|
);
|
|
432
|
-
},
|
|
433
|
-
const { allEntitlements:
|
|
434
|
-
return
|
|
435
|
-
},
|
|
436
|
-
const { getEntitlement:
|
|
437
|
-
return
|
|
438
|
-
},
|
|
439
|
-
const { getEntitlement:
|
|
440
|
-
return
|
|
441
|
-
},
|
|
442
|
-
const { getEntitlement:
|
|
443
|
-
return
|
|
615
|
+
}, ve = (n) => /* @__PURE__ */ S(B, { ...n }), Ae = () => {
|
|
616
|
+
const { allEntitlements: n } = K();
|
|
617
|
+
return n;
|
|
618
|
+
}, we = (n) => {
|
|
619
|
+
const { getEntitlement: s } = K();
|
|
620
|
+
return s(n);
|
|
621
|
+
}, qe = (n) => {
|
|
622
|
+
const { getEntitlement: s } = K();
|
|
623
|
+
return s(n);
|
|
624
|
+
}, ye = (n) => {
|
|
625
|
+
const { getEntitlement: s } = K();
|
|
626
|
+
return s(n);
|
|
627
|
+
}, Se = () => {
|
|
628
|
+
const { subscriptions: n } = K();
|
|
629
|
+
return n;
|
|
630
|
+
}, be = () => {
|
|
631
|
+
const { customer: n } = K();
|
|
632
|
+
return n;
|
|
444
633
|
};
|
|
445
634
|
export {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
635
|
+
Y as KelviqContext,
|
|
636
|
+
pe as KelviqProvider,
|
|
637
|
+
ve as ShowWhenBooleanEntitled,
|
|
638
|
+
he as ShowWhenCustomizableEntitled,
|
|
639
|
+
Le as ShowWhenMeteredEntitled,
|
|
640
|
+
V as defaultKelviqContextValue,
|
|
641
|
+
Ae as useAllEntitlements,
|
|
642
|
+
we as useBooleanEntitlement,
|
|
643
|
+
be as useCustomer,
|
|
644
|
+
qe as useCustomizableEntitlement,
|
|
645
|
+
K as useKelviq,
|
|
646
|
+
ye as useMeteredEntitlement,
|
|
647
|
+
Se as useSubscriptions
|
|
457
648
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.KelviqReactSDK={},a.jsxRuntime,a.React))})(this,function(a,u,E){"use strict";const x="GET";function j(t){const{method:r=x,headers:s={},body:e,timeout:p=5e3,maxRetries:v=3,backoffBaseDelay:y=1e3,queryParams:q,accessToken:c}=t;let{url:h}=t,w=0;return new Promise((C,L)=>{if(q){const i=new URLSearchParams;for(const d in q)q[d]!==void 0&&i.append(d,String(q[d]));i.toString()&&(h+=(h.includes("?")?"&":"?")+i.toString())}function A(){const i=new XMLHttpRequest;i.open(r,h,!0),i.timeout=p;const d={Accept:"application/json","X-Requested-With":"XMLHttpRequest",...s};r!=="GET"&&e&&typeof e=="object"&&!(e instanceof FormData)&&(d["Content-Type"]||(d["Content-Type"]="application/json")),c&&(d.Authorization=`Bearer ${c}`);for(const[o,f]of Object.entries(d))i.setRequestHeader(o,f);i.onload=function(){const{status:o,statusText:f,responseText:K}=i;if(o>=200&&o<300)try{const T=K?JSON.parse(K):{};C({status:o,statusText:f,data:T})}catch(T){const U=T instanceof Error?T:new Error(String(T));console.error(`Kelviq SDK (apiRequest): Invalid JSON response for URL ${h}. Error: ${U.message}. Response: ${K}`),L(new Error(`Invalid JSON response: ${U.message}`))}else D(`Request to ${h} failed with status ${o} ${f}. Response: ${K}`)},i.onerror=()=>D(`Network error for URL ${h}. The request could not be completed.`),i.ontimeout=()=>D(`Request to ${h} timed out.`);function D(o){if(w<v){w++;const f=Math.min(y*Math.pow(2,w-1),3e4);console.warn(`Kelviq SDK (apiRequest): Retrying request to ${h}. Attempt ${w}/${v}. Error: ${o}. Retrying in ${f}ms.`),setTimeout(A,f)}else L(new Error(`${o} (Max retries ${v} reached)`))}try{let o=e;e&&typeof e=="object"&&!(e instanceof FormData)&&d["Content-Type"]==="application/json"&&(o=JSON.stringify(e)),i.send(o)}catch(o){const f=o instanceof Error?o:new Error(String(o));console.error(`Kelviq SDK (apiRequest): Error sending request to ${h}.`,f),L(new Error(`Failed to send request: ${f.message}`))}}A()})}function N(t,r){const s=r[0].featureType;if(s==="METER"){let e=0,p=0,v=!1;for(const q of r){const c=q,h=typeof c.usageLimit=="number"?c.usageLimit:null,w=typeof c.currentUsage=="number"?c.currentUsage:0;h===null&&(e=null),e!==null&&(e+=h),p+=w,c.hardLimit&&(v=!0)}const y=e!==null?e-p:null;return{featureId:t,featureType:s,hasAccess:y===null||y>0,currentUsage:p,usageLimit:e,remaining:y,hardLimit:v,items:r}}if(s==="CUSTOMIZABLE"){const e=r[0];return{featureId:t,featureType:s,hasAccess:r.some(p=>p.hasAccess),currentUsage:typeof e.currentUsage=="number"?e.currentUsage:0,usageLimit:typeof e.usageLimit=="number"?e.usageLimit:null,remaining:typeof e.remaining=="number"?e.remaining:null,hardLimit:e.hardLimit===!0,items:r}}return{featureId:t,featureType:s,hasAccess:r.some(e=>e.hasAccess),currentUsage:0,usageLimit:null,remaining:null,hardLimit:!1,items:r}}function W(t){const r={};if(!t||!Array.isArray(t.entitlements))return console.warn("Kelviq SDK: Invalid or empty entitlements array in API response.",t),r;const s={};for(const e of t.entitlements){if(!e||typeof e.featureId!="string"||typeof e.featureType!="string"){console.warn("Kelviq SDK: Skipping invalid raw entitlement object:",e);continue}s[e.featureId]||(s[e.featureId]=[]),s[e.featureId].push(e)}for(const e in s)r[e]=N(e,s[e]);return r}const $={allEntitlements:{data:null,isLoading:!0,error:null},refreshAllEntitlements:()=>(console.warn("refreshAllEntitlements called on default KelviqContext. Ensure KelviqProvider is properly set up."),Promise.resolve()),getEntitlements:()=>({}),getEntitlement:()=>null,getRawEntitlements:()=>null,getRawEntitlement:()=>null,hasAccess:()=>!1,updateEntitlement:()=>{console.warn("updateEntitlement called on default KelviqContext. Ensure KelviqProvider is properly set up.")},isLoading:!0,error:null,apiUrl:"",environment:"production",entitlementsPath:"",customerId:""},M=E.createContext($),H="https://edge.api.kelviq.com/api/v1/",z="https://edge.sandboxapi.kelviq.com/api/v1/",X="entitlements/",G=({children:t,apiUrl:r,entitlementsPath:s=X,customerId:e,environment:p="production",accessToken:v,config:y={}})=>{const{onError:q,maxRetries:c,timeout:h,backoffBaseDelay:w,fetchEntitlementsOnMount:C=!0}=y,L=r||(p==="sandbox"?z:H),[A,i]=E.useState({data:null,isLoading:!!L&&C,error:null}),[d,D]=E.useState(null),[o,f]=E.useState(!!L&&C),[K,T]=E.useState(null),U=E.useCallback((m,l,n)=>{const g=new Error(`Kelviq SDK (${l}): ${m}`);console.error(g.message,n||""),T(S=>S||g),q&&q(g)},[q]),R=E.useCallback(()=>{if(!L){const n="API URL not configured. Cannot fetch entitlements.";return i({data:null,isLoading:!1,error:new Error(n)}),U(n,"fetchAllEntitlements"),f(!1),Promise.reject(new Error(n))}if(!e){const n="CustomerId must be provided as props to KelviqProvider.";return i(()=>({data:null,isLoading:!1,error:new Error(n)})),U(n,"fetchAllEntitlements"),f(!1),Promise.reject(new Error(n))}i(n=>({...n,isLoading:!0,error:null})),f(!0),T(null);const m=`${L.replace(/\/$/,"")}/${s.replace(/^\//,"")}`;return j({url:m,method:"GET",timeout:h,maxRetries:c,backoffBaseDelay:w,accessToken:v,queryParams:{customer_id:e}}).then(n=>{if(n&&n.data&&Array.isArray(n.data.entitlements)){D(n.data);const g=W(n.data);i({data:g,isLoading:!1,error:null})}else{const g=new Error("Received empty, malformed, or invalid data structure from entitlements API.");throw i({data:null,isLoading:!1,error:g}),U(g.message,"fetchAllEntitlements",n),g}}).catch(n=>{const g=n instanceof Error?n:new Error(String(n));return i(S=>({...S,isLoading:!1,error:g})),U(g.message,"fetchAllEntitlements",n),Promise.reject(g)}).finally(()=>{f(!1)})},[L,e,s,h,c,w,v,U]);E.useEffect(()=>{let m=!0;if(!L){if(m){const l=new Error("KelviqProvider: `apiBaseUrl` must be provided in config.");T(l),f(!1),i(n=>({...n,isLoading:!1,error:l})),y.onError&&y.onError(l)}return}return C?R().catch(l=>{m&&o&&f(!1),console.error("Kelviq SDK: Initial entitlement fetch failed.",l)}):m&&(i(l=>({...l,isLoading:!1,data:null,error:null})),f(!1)),()=>{m=!1}},[L,C,y.onError]);const _=E.useCallback(()=>A.data?A.data:{},[A.data]),F=E.useCallback(()=>d?{customerId:d.customer_id,entitlements:d.entitlements}:null,[d]),I=E.useCallback(m=>d?{customerId:d.customer_id,entitlements:d.entitlements.filter(l=>l.featureId===m)}:null,[d]),k=E.useCallback(m=>A.data?A.data[m]??null:null,[A.data]),B=E.useCallback((m,l)=>{i(n=>{if(!n.data)return n;const g=n.data[m];if(!g)return n;const S={...g,...l};return("usageLimit"in l||"currentUsage"in l)&&(S.remaining=S.usageLimit!==null?S.usageLimit-S.currentUsage:null),{...n,data:{...n.data,[m]:S}}})},[]),O=E.useCallback(m=>{if(!A.data)return!1;const l=A.data[m];return l?l.hasAccess:!1},[A.data]),ne=E.useMemo(()=>({allEntitlements:A,refreshAllEntitlements:R,getEntitlements:_,getEntitlement:k,getRawEntitlements:F,getRawEntitlement:I,hasAccess:O,updateEntitlement:B,isLoading:o,error:K,environment:p,apiUrl:L,entitlementsPath:s,customerId:e}),[A,R,_,k,F,I,O,B,o,K,p,L,s,e]);return u.jsx(M.Provider,{value:ne,children:t})},b=()=>{const t=E.useContext(M);if(t===void 0||t===$)throw new Error("useKelviq must be used within an initialized KelviqProvider.");return t},P=({featureId:t,children:r,fallback:s=null,loadingComponent:e,condition:p})=>{const{getEntitlement:v,isLoading:y,error:q}=b(),c=v(t);return y&&!c?u.jsx(u.Fragment,{children:e!==void 0?e:s}):q&&!c?u.jsx(u.Fragment,{children:s}):!c||!c.hasAccess||p&&!p(c)?u.jsx(u.Fragment,{children:s}):typeof r=="function"?u.jsx(u.Fragment,{children:r(c)}):u.jsx(u.Fragment,{children:r})},J=t=>u.jsx(P,{...t}),V=t=>{const r=s=>s.hasAccess&&(s.remaining===null||s.remaining>0);return u.jsx(P,{...t,condition:t.condition||r})},Y=t=>u.jsx(P,{...t}),Z=()=>{const{allEntitlements:t}=b();return t},Q=t=>{const{getEntitlement:r}=b();return r(t)},ee=t=>{const{getEntitlement:r}=b();return r(t)},te=t=>{const{getEntitlement:r}=b();return r(t)};a.KelviqContext=M,a.KelviqProvider=G,a.ShowWhenBooleanEntitled=Y,a.ShowWhenCustomizableEntitled=J,a.ShowWhenMeteredEntitled=V,a.defaultKelviqContextValue=$,a.useAllEntitlements=Z,a.useBooleanEntitlement=Q,a.useCustomizableEntitlement=ee,a.useKelviq=b,a.useMeteredEntitlement=te,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(c,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],g):(c=typeof globalThis<"u"?globalThis:c||self,g(c.KelviqReactSDK={},c.jsxRuntime,c.React))})(this,function(c,g,d){"use strict";const Y="GET";function $(n){const{method:s=Y,headers:o={},body:t,timeout:p=5e3,maxRetries:L=3,backoffBaseDelay:q=1e3,queryParams:S,accessToken:a}=n;let{url:m}=n,w=0;return new Promise((T,U)=>{if(S){const l=new URLSearchParams;for(const h in S)S[h]!==void 0&&l.append(h,String(S[h]));l.toString()&&(m+=(m.includes("?")?"&":"?")+l.toString())}function M(){const l=new XMLHttpRequest;l.open(s,m,!0),l.timeout=p;const h={Accept:"application/json","X-Requested-With":"XMLHttpRequest",...o};s!=="GET"&&t&&typeof t=="object"&&!(t instanceof FormData)&&(h["Content-Type"]||(h["Content-Type"]="application/json")),a&&(h.Authorization=`Bearer ${a}`);for(const[i,E]of Object.entries(h))l.setRequestHeader(i,E);l.onload=function(){const{status:i,statusText:E,responseText:D}=l;if(i>=200&&i<300)try{const K=D?JSON.parse(D):{};T({status:i,statusText:E,data:K})}catch(K){const b=K instanceof Error?K:new Error(String(K));console.error(`Kelviq SDK (apiRequest): Invalid JSON response for URL ${m}. Error: ${b.message}. Response: ${D}`),U(new Error(`Invalid JSON response: ${b.message}`))}else v(`Request to ${m} failed with status ${i} ${E}. Response: ${D}`)},l.onerror=()=>v(`Network error for URL ${m}. The request could not be completed.`),l.ontimeout=()=>v(`Request to ${m} timed out.`);function v(i){if(w<L){w++;const E=Math.min(q*Math.pow(2,w-1),3e4);console.warn(`Kelviq SDK (apiRequest): Retrying request to ${m}. Attempt ${w}/${L}. Error: ${i}. Retrying in ${E}ms.`),setTimeout(M,E)}else U(new Error(`${i} (Max retries ${L} reached)`))}try{let i=t;t&&typeof t=="object"&&!(t instanceof FormData)&&h["Content-Type"]==="application/json"&&(i=JSON.stringify(t)),l.send(i)}catch(i){const E=i instanceof Error?i:new Error(String(i));console.error(`Kelviq SDK (apiRequest): Error sending request to ${m}.`,E),U(new Error(`Failed to send request: ${E.message}`))}}M()})}function Z(n,s){const o=s[0].featureType;if(o==="METER"){let t=0,p=0,L=!1;for(const S of s){const a=S,m=typeof a.usageLimit=="number"?a.usageLimit:null,w=typeof a.currentUsage=="number"?a.currentUsage:0;m===null&&(t=null),t!==null&&(t+=m),p+=w,a.hardLimit&&(L=!0)}const q=t!==null?t-p:null;return{featureId:n,featureType:o,hasAccess:q===null||q>0,currentUsage:p,usageLimit:t,remaining:q,hardLimit:L,items:s}}if(o==="CUSTOMIZABLE"){const t=s[0];return{featureId:n,featureType:o,hasAccess:s.some(p=>p.hasAccess),currentUsage:typeof t.currentUsage=="number"?t.currentUsage:0,usageLimit:typeof t.usageLimit=="number"?t.usageLimit:null,remaining:typeof t.remaining=="number"?t.remaining:null,hardLimit:t.hardLimit===!0,items:s}}return{featureId:n,featureType:o,hasAccess:s.some(t=>t.hasAccess),currentUsage:0,usageLimit:null,remaining:null,hardLimit:!1,items:s}}function Q(n){const s={};if(!n||!Array.isArray(n.entitlements))return console.warn("Kelviq SDK: Invalid or empty entitlements array in API response.",n),s;const o={};for(const t of n.entitlements){if(!t||typeof t.featureId!="string"||typeof t.featureType!="string"){console.warn("Kelviq SDK: Skipping invalid raw entitlement object:",t);continue}o[t.featureId]||(o[t.featureId]=[]),o[t.featureId].push(t)}for(const t in o)s[t]=Z(t,o[t]);return s}const R={allEntitlements:{data:null,isLoading:!0,error:null},refreshAllEntitlements:()=>(console.warn("refreshAllEntitlements called on default KelviqContext. Ensure KelviqProvider is properly set up."),Promise.resolve()),getEntitlements:()=>({}),getEntitlement:()=>null,getRawEntitlements:()=>null,getRawEntitlement:()=>null,hasAccess:()=>!1,updateEntitlement:()=>{console.warn("updateEntitlement called on default KelviqContext. Ensure KelviqProvider is properly set up.")},subscriptions:{data:null,isLoading:!1,error:null},refreshSubscriptions:()=>(console.warn("refreshSubscriptions called on default KelviqContext. Ensure KelviqProvider is properly set up."),Promise.resolve()),customer:{data:null,isLoading:!1,error:null},refreshCustomer:()=>(console.warn("refreshCustomer called on default KelviqContext. Ensure KelviqProvider is properly set up."),Promise.resolve()),isLoading:!0,error:null,apiUrl:"",environment:"production",entitlementsPath:"",customerId:""},_=d.createContext(R),ee="https://edge.api.kelviq.com/api/v1/",te="https://edge.sandboxapi.kelviq.com/api/v1/",re="https://api.kelviq.com/api/v1/",ne="https://sandboxapi.kelviq.com/api/v1/",se="entitlements/",oe=({children:n,apiUrl:s,entitlementsPath:o=se,customerId:t,environment:p="production",accessToken:L,config:q={}})=>{const{onError:S,maxRetries:a,timeout:m,backoffBaseDelay:w,fetchEntitlementsOnMount:T=!0,fetchSubscriptionsOnMount:U=!1,fetchCustomerOnMount:M=!1}=q,l=s||(p==="sandbox"?te:ee),h=p==="sandbox"?ne:re,[v,i]=d.useState({data:null,isLoading:!!l&&T,error:null}),[E,D]=d.useState(null),[K,b]=d.useState({data:null,isLoading:!!l&&U,error:null}),[N,I]=d.useState({data:null,isLoading:!!l&&M,error:null}),[k,P]=d.useState(!!l&&T),[W,B]=d.useState(null),A=d.useCallback((u,e,r)=>{const f=new Error(`Kelviq SDK (${e}): ${u}`);console.error(f.message,r||""),B(y=>y||f),S&&S(f)},[S]),O=d.useCallback(()=>{if(!l){const r="API URL not configured. Cannot fetch entitlements.";return i({data:null,isLoading:!1,error:new Error(r)}),A(r,"fetchAllEntitlements"),P(!1),Promise.reject(new Error(r))}if(!t){const r="CustomerId must be provided as props to KelviqProvider.";return i(()=>({data:null,isLoading:!1,error:new Error(r)})),A(r,"fetchAllEntitlements"),P(!1),Promise.reject(new Error(r))}i(r=>({...r,isLoading:!0,error:null})),P(!0),B(null);const u=`${l.replace(/\/$/,"")}/${o.replace(/^\//,"")}`;return $({url:u,method:"GET",timeout:m,maxRetries:a,backoffBaseDelay:w,accessToken:L,queryParams:{customer_id:t}}).then(r=>{if(r&&r.data&&Array.isArray(r.data.entitlements)){D(r.data);const f=Q(r.data);i({data:f,isLoading:!1,error:null})}else{const f=new Error("Received empty, malformed, or invalid data structure from entitlements API.");throw i({data:null,isLoading:!1,error:f}),A(f.message,"fetchAllEntitlements",r),f}}).catch(r=>{const f=r instanceof Error?r:new Error(String(r));return i(y=>({...y,isLoading:!1,error:f})),A(f.message,"fetchAllEntitlements",r),Promise.reject(f)}).finally(()=>{P(!1)})},[l,t,o,m,a,w,L,A]),j=d.useCallback(()=>{if(!h){const e="Main API URL not configured. Cannot fetch subscriptions.";return b({data:null,isLoading:!1,error:new Error(e)}),A(e,"fetchSubscriptions"),Promise.reject(new Error(e))}if(!t){const e="CustomerId must be provided as props to KelviqProvider.";return b({data:null,isLoading:!1,error:new Error(e)}),A(e,"fetchSubscriptions"),Promise.reject(new Error(e))}b(e=>({...e,isLoading:!0,error:null}));const u=`${h.replace(/\/$/,"")}/subscriptions/`;return $({url:u,method:"GET",timeout:m,maxRetries:a,backoffBaseDelay:w,accessToken:L,queryParams:{customer_id:t}}).then(e=>{if(e&&e.data&&Array.isArray(e.data.results))b({data:e.data.results,isLoading:!1,error:null});else{const r=new Error("Received empty, malformed, or invalid data structure from subscriptions API.");throw b({data:null,isLoading:!1,error:r}),A(r.message,"fetchSubscriptions",e),r}}).catch(e=>{const r=e instanceof Error?e:new Error(String(e));return b(f=>({...f,isLoading:!1,error:r})),A(r.message,"fetchSubscriptions",e),Promise.reject(r)})},[h,t,m,a,w,L,A]),x=d.useCallback(()=>{if(!h){const e="Main API URL not configured. Cannot fetch customer.";return I({data:null,isLoading:!1,error:new Error(e)}),A(e,"fetchCustomer"),Promise.reject(new Error(e))}if(!t){const e="CustomerId must be provided as props to KelviqProvider.";return I({data:null,isLoading:!1,error:new Error(e)}),A(e,"fetchCustomer"),Promise.reject(new Error(e))}I(e=>({...e,isLoading:!0,error:null}));const u=`${h.replace(/\/$/,"")}/customers/${t}/`;return $({url:u,method:"GET",timeout:m,maxRetries:a,backoffBaseDelay:w,accessToken:L}).then(e=>{if(e&&e.data)I({data:e.data,isLoading:!1,error:null});else{const r=new Error("Received empty or invalid data from customer API.");throw I({data:null,isLoading:!1,error:r}),A(r.message,"fetchCustomer",e),r}}).catch(e=>{const r=e instanceof Error?e:new Error(String(e));return I(f=>({...f,isLoading:!1,error:r})),A(r.message,"fetchCustomer",e),Promise.reject(r)})},[h,t,m,a,w,L,A]);d.useEffect(()=>{let u=!0;if(!l){if(u){const e=new Error("KelviqProvider: `apiBaseUrl` must be provided in config.");B(e),P(!1),i(r=>({...r,isLoading:!1,error:e})),q.onError&&q.onError(e)}return}return T?O().catch(e=>{u&&k&&P(!1),console.error("Kelviq SDK: Initial entitlement fetch failed.",e)}):u&&(i(e=>({...e,isLoading:!1,data:null,error:null})),P(!1)),U&&j().catch(e=>{console.error("Kelviq SDK: Initial subscriptions fetch failed.",e)}),M&&x().catch(e=>{console.error("Kelviq SDK: Initial customer fetch failed.",e)}),()=>{u=!1}},[l,T,U,M,q.onError]);const G=d.useCallback(()=>v.data?v.data:{},[v.data]),H=d.useCallback(()=>E?{customerId:E.customerId,entitlements:E.entitlements}:null,[E]),X=d.useCallback(u=>E?{customerId:E.customerId,entitlements:E.entitlements.filter(e=>e.featureId===u)}:null,[E]),z=d.useCallback(u=>v.data?v.data[u]??null:null,[v.data]),J=d.useCallback((u,e)=>{i(r=>{if(!r.data)return r;const f=r.data[u];if(!f)return r;const y={...f,...e};return("usageLimit"in e||"currentUsage"in e)&&(y.remaining=y.usageLimit!==null?y.usageLimit-y.currentUsage:null),{...r,data:{...r.data,[u]:y}}})},[]),V=d.useCallback(u=>{if(!v.data)return!1;const e=v.data[u];return e?e.hasAccess:!1},[v.data]),ge=d.useMemo(()=>({allEntitlements:v,refreshAllEntitlements:O,getEntitlements:G,getEntitlement:z,getRawEntitlements:H,getRawEntitlement:X,hasAccess:V,updateEntitlement:J,subscriptions:K,refreshSubscriptions:j,customer:N,refreshCustomer:x,isLoading:k,error:W,environment:p,apiUrl:l,entitlementsPath:o,customerId:t}),[v,O,G,z,H,X,V,J,K,j,N,x,k,W,p,l,o,t]);return g.jsx(_.Provider,{value:ge,children:n})},C=()=>{const n=d.useContext(_);if(n===void 0||n===R)throw new Error("useKelviq must be used within an initialized KelviqProvider.");return n},F=({featureId:n,children:s,fallback:o=null,loadingComponent:t,condition:p})=>{const{getEntitlement:L,isLoading:q,error:S}=C(),a=L(n);return q&&!a?g.jsx(g.Fragment,{children:t!==void 0?t:o}):S&&!a?g.jsx(g.Fragment,{children:o}):!a||!a.hasAccess||p&&!p(a)?g.jsx(g.Fragment,{children:o}):typeof s=="function"?g.jsx(g.Fragment,{children:s(a)}):g.jsx(g.Fragment,{children:s})},ie=n=>g.jsx(F,{...n}),le=n=>{const s=o=>o.hasAccess&&(o.remaining===null||o.remaining>0);return g.jsx(F,{...n,condition:n.condition||s})},ae=n=>g.jsx(F,{...n}),ue=()=>{const{allEntitlements:n}=C();return n},ce=n=>{const{getEntitlement:s}=C();return s(n)},de=n=>{const{getEntitlement:s}=C();return s(n)},fe=n=>{const{getEntitlement:s}=C();return s(n)},me=()=>{const{subscriptions:n}=C();return n},Ee=()=>{const{customer:n}=C();return n};c.KelviqContext=_,c.KelviqProvider=oe,c.ShowWhenBooleanEntitled=ae,c.ShowWhenCustomizableEntitled=ie,c.ShowWhenMeteredEntitled=le,c.defaultKelviqContextValue=R,c.useAllEntitlements=ue,c.useBooleanEntitlement=ce,c.useCustomer=Ee,c.useCustomizableEntitlement=de,c.useKelviq=C,c.useMeteredEntitlement=fe,c.useSubscriptions=me,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -40,10 +40,71 @@ export interface RawMeteredEntitlementData extends RawEntitlement {
|
|
|
40
40
|
export type AnyRawEntitlementData = RawBooleanEntitlementData | RawCustomizableEntitlementData | RawMeteredEntitlementData;
|
|
41
41
|
/**
|
|
42
42
|
* Represents the expected raw API response structure when fetching all entitlements.
|
|
43
|
-
* Example: { "
|
|
43
|
+
* Example: { "customerId": "128", "entitlements": [...] }
|
|
44
44
|
*/
|
|
45
45
|
export interface RawEntitlementsApiResponse {
|
|
46
|
-
|
|
46
|
+
customerId: string;
|
|
47
47
|
entitlements: AnyRawEntitlementData[];
|
|
48
48
|
}
|
|
49
|
+
export interface RawSubscriptionFeature {
|
|
50
|
+
featureId: string;
|
|
51
|
+
featureType: string;
|
|
52
|
+
hasAccess: boolean;
|
|
53
|
+
usageLimit: number | null;
|
|
54
|
+
currentUsage: number;
|
|
55
|
+
remaining: number | null;
|
|
56
|
+
}
|
|
57
|
+
export interface RawSubscriptionPlan {
|
|
58
|
+
name: string;
|
|
59
|
+
identifier: string;
|
|
60
|
+
}
|
|
61
|
+
export interface RawSubscriptionProduct {
|
|
62
|
+
name: string;
|
|
63
|
+
identifier: string;
|
|
64
|
+
}
|
|
65
|
+
/** A single subscription object as returned by the subscriptions API. */
|
|
66
|
+
export interface RawSubscriptionData {
|
|
67
|
+
id: string;
|
|
68
|
+
externalSubscriptionId: string;
|
|
69
|
+
startDate: string;
|
|
70
|
+
endDate: string | null;
|
|
71
|
+
billingPeriodStartTime: string;
|
|
72
|
+
billingPeriodEndTime: string;
|
|
73
|
+
amount: string;
|
|
74
|
+
recurrence: string;
|
|
75
|
+
currency: string;
|
|
76
|
+
status: string;
|
|
77
|
+
product: RawSubscriptionProduct;
|
|
78
|
+
plan: RawSubscriptionPlan;
|
|
79
|
+
features: RawSubscriptionFeature[];
|
|
80
|
+
trialDaysRemaining: number | null;
|
|
81
|
+
customerId: string;
|
|
82
|
+
}
|
|
83
|
+
/** Paginated response from the subscriptions list endpoint. */
|
|
84
|
+
export interface RawSubscriptionsApiResponse {
|
|
85
|
+
count: number;
|
|
86
|
+
next: string | null;
|
|
87
|
+
previous: string | null;
|
|
88
|
+
results: RawSubscriptionData[];
|
|
89
|
+
}
|
|
90
|
+
export interface RawBillingAddress {
|
|
91
|
+
country: string;
|
|
92
|
+
line1: string;
|
|
93
|
+
line2: string;
|
|
94
|
+
postalCode: string;
|
|
95
|
+
city: string;
|
|
96
|
+
state: string;
|
|
97
|
+
}
|
|
98
|
+
/** Raw customer data as returned by the customer API. */
|
|
99
|
+
export interface RawCustomerApiResponse {
|
|
100
|
+
id: string;
|
|
101
|
+
customerId: string;
|
|
102
|
+
name: string;
|
|
103
|
+
email: string;
|
|
104
|
+
details: Record<string, unknown>;
|
|
105
|
+
metadata: Record<string, unknown>;
|
|
106
|
+
billingAddress: RawBillingAddress | null;
|
|
107
|
+
createdOn: string;
|
|
108
|
+
modifiedOn: string;
|
|
109
|
+
}
|
|
49
110
|
export {};
|
|
@@ -63,4 +63,14 @@ export interface KelviqApiBehaviorOptions {
|
|
|
63
63
|
* If not provided, the `apiRequest` service's default will be used.
|
|
64
64
|
*/
|
|
65
65
|
backoffBaseDelay?: number;
|
|
66
|
+
/**
|
|
67
|
+
* If true, fetches the customer's subscriptions when the provider mounts.
|
|
68
|
+
* Defaults to false. When enabled, data is available via `useSubscriptions()`.
|
|
69
|
+
*/
|
|
70
|
+
fetchSubscriptionsOnMount?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* If true, fetches customer data when the provider mounts.
|
|
73
|
+
* Defaults to false. When enabled, data is available via `useCustomer()`.
|
|
74
|
+
*/
|
|
75
|
+
fetchCustomerOnMount?: boolean;
|
|
66
76
|
}
|