@kelviq/react-sdk 0.0.1-beta → 2.0.0-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/README.md +18 -364
- package/dist/components/ShowWhenBooleanEntitled.d.ts +1 -2
- package/dist/components/ShowWhenCustomizableEntitled.d.ts +9 -0
- package/dist/components/ShowWhenEntitledInternal.d.ts +6 -8
- package/dist/components/ShowWhenMeteredEntitled.d.ts +4 -5
- package/dist/contexts/KelviqContext.d.ts +11 -3
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/useBooleanEntitlement.d.ts +5 -6
- package/dist/hooks/useCustomizableEntitlement.d.ts +7 -0
- package/dist/hooks/useMeteredEntitlement.d.ts +5 -6
- package/dist/index.d.ts +2 -2
- package/dist/kelviq-react-sdk.js +337 -341
- package/dist/kelviq-react-sdk.umd.cjs +1 -1
- package/dist/services/makeRequest.service.d.ts +2 -2
- package/dist/types/api.types.d.ts +14 -4
- package/dist/types/sdk.types.d.ts +32 -34
- package/dist/utils/transformations.d.ts +4 -4
- package/package.json +4 -2
- package/dist/components/ShowWhenConfigEntitled.d.ts +0 -14
- package/dist/hooks/useConfigEntitlement.d.ts +0 -8
package/dist/kelviq-react-sdk.js
CHANGED
|
@@ -1,165 +1,164 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
1
|
+
import { jsx as v, Fragment as $ } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as N, useState as P, useCallback as T, useEffect as H, useMemo as G, useContext as W } from "react";
|
|
3
|
+
const X = "GET", z = 5e3, J = 3, V = 1e3;
|
|
4
|
+
function Y(t) {
|
|
5
5
|
const {
|
|
6
|
-
method:
|
|
7
|
-
headers:
|
|
6
|
+
method: r = X,
|
|
7
|
+
headers: s = {},
|
|
8
8
|
// Renamed to avoid conflict with internal 'headers' variable
|
|
9
|
-
body:
|
|
10
|
-
timeout:
|
|
11
|
-
maxRetries:
|
|
12
|
-
backoffBaseDelay:
|
|
13
|
-
queryParams:
|
|
14
|
-
accessToken:
|
|
9
|
+
body: e,
|
|
10
|
+
timeout: E = z,
|
|
11
|
+
maxRetries: A = J,
|
|
12
|
+
backoffBaseDelay: h = V,
|
|
13
|
+
queryParams: L,
|
|
14
|
+
accessToken: a
|
|
15
15
|
// Use the direct accessToken
|
|
16
|
-
} =
|
|
17
|
-
let { url: f } =
|
|
18
|
-
return new Promise((
|
|
19
|
-
if (
|
|
20
|
-
const
|
|
21
|
-
for (const
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
} = t;
|
|
17
|
+
let { url: f } = t, y = 0;
|
|
18
|
+
return new Promise((K, p) => {
|
|
19
|
+
if (L) {
|
|
20
|
+
const o = new URLSearchParams();
|
|
21
|
+
for (const u in L)
|
|
22
|
+
L[u] !== void 0 && o.append(u, String(L[u]));
|
|
23
|
+
o.toString() && (f += (f.includes("?") ? "&" : "?") + o.toString());
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
25
|
+
function g() {
|
|
26
|
+
const o = new XMLHttpRequest();
|
|
27
|
+
o.open(r, f, !0), o.timeout = E;
|
|
28
|
+
const u = {
|
|
29
29
|
Accept: "application/json",
|
|
30
30
|
"X-Requested-With": "XMLHttpRequest",
|
|
31
|
-
...
|
|
31
|
+
...s
|
|
32
32
|
// Apply custom headers, allowing them to override defaults
|
|
33
33
|
};
|
|
34
|
-
|
|
35
|
-
for (const [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const { status:
|
|
39
|
-
if (
|
|
34
|
+
r !== "GET" && e && typeof e == "object" && !(e instanceof FormData) && (u["Content-Type"] || (u["Content-Type"] = "application/json")), a && (u.Authorization = `Bearer ${a}`);
|
|
35
|
+
for (const [i, c] of Object.entries(u))
|
|
36
|
+
o.setRequestHeader(i, c);
|
|
37
|
+
o.onload = function() {
|
|
38
|
+
const { status: i, statusText: c, responseText: U } = o;
|
|
39
|
+
if (i >= 200 && i < 300)
|
|
40
40
|
try {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
} catch (
|
|
44
|
-
const
|
|
41
|
+
const w = U ? JSON.parse(U) : {};
|
|
42
|
+
K({ status: i, statusText: c, data: w });
|
|
43
|
+
} catch (w) {
|
|
44
|
+
const R = w instanceof Error ? w : new Error(String(w));
|
|
45
45
|
console.error(
|
|
46
|
-
`Kelviq SDK (apiRequest): Invalid JSON response for URL ${f}. Error: ${
|
|
47
|
-
),
|
|
46
|
+
`Kelviq SDK (apiRequest): Invalid JSON response for URL ${f}. Error: ${R.message}. Response: ${U}`
|
|
47
|
+
), p(
|
|
48
48
|
new Error(
|
|
49
|
-
`Invalid JSON response: ${
|
|
49
|
+
`Invalid JSON response: ${R.message}`
|
|
50
50
|
)
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
else
|
|
54
|
-
|
|
55
|
-
`Request to ${f} failed with status ${
|
|
54
|
+
S(
|
|
55
|
+
`Request to ${f} failed with status ${i} ${c}. Response: ${U}`
|
|
56
56
|
);
|
|
57
|
-
},
|
|
57
|
+
}, o.onerror = () => S(
|
|
58
58
|
`Network error for URL ${f}. The request could not be completed.`
|
|
59
|
-
),
|
|
60
|
-
function
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
59
|
+
), o.ontimeout = () => S(`Request to ${f} timed out.`);
|
|
60
|
+
function S(i) {
|
|
61
|
+
if (y < A) {
|
|
62
|
+
y++;
|
|
63
|
+
const c = Math.min(
|
|
64
|
+
h * Math.pow(2, y - 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 ${f}. Attempt ${
|
|
70
|
-
), setTimeout(
|
|
69
|
+
`Kelviq SDK (apiRequest): Retrying request to ${f}. Attempt ${y}/${A}. Error: ${i}. Retrying in ${c}ms.`
|
|
70
|
+
), setTimeout(g, c);
|
|
71
71
|
} else
|
|
72
|
-
|
|
72
|
+
p(
|
|
73
73
|
new Error(
|
|
74
|
-
`${
|
|
74
|
+
`${i} (Max retries ${A} reached)`
|
|
75
75
|
)
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
try {
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
} catch (
|
|
82
|
-
const
|
|
79
|
+
let i = e;
|
|
80
|
+
e && typeof e == "object" && !(e instanceof FormData) && u["Content-Type"] === "application/json" && (i = JSON.stringify(e)), o.send(i);
|
|
81
|
+
} catch (i) {
|
|
82
|
+
const c = i instanceof Error ? i : new Error(String(i));
|
|
83
83
|
console.error(
|
|
84
84
|
`Kelviq SDK (apiRequest): Error sending request to ${f}.`,
|
|
85
|
-
|
|
86
|
-
),
|
|
85
|
+
c
|
|
86
|
+
), p(new Error(`Failed to send request: ${c.message}`));
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
g();
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
function Z(t, r) {
|
|
93
|
+
const s = r[0].featureType;
|
|
94
|
+
if (s === "METER") {
|
|
95
|
+
let e = 0, E = 0, A = !1;
|
|
96
|
+
for (const L of r) {
|
|
97
|
+
const a = L, f = typeof a.usageLimit == "number" ? a.usageLimit : null, y = typeof a.currentUsage == "number" ? a.currentUsage : 0;
|
|
98
|
+
f === null && (e = null), e !== null && (e += f), E += y, a.hardLimit && (A = !0);
|
|
99
|
+
}
|
|
100
|
+
const h = e !== null ? e - E : null;
|
|
101
|
+
return {
|
|
102
|
+
featureId: t,
|
|
103
|
+
featureType: s,
|
|
104
|
+
hasAccess: h === null || h > 0,
|
|
105
|
+
currentUsage: E,
|
|
106
|
+
usageLimit: e,
|
|
107
|
+
remaining: h,
|
|
108
|
+
hardLimit: A,
|
|
109
|
+
items: r
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (s === "CUSTOMIZABLE") {
|
|
113
|
+
const e = r[0];
|
|
114
|
+
return {
|
|
115
|
+
featureId: t,
|
|
116
|
+
featureType: s,
|
|
117
|
+
hasAccess: r.some((E) => E.hasAccess),
|
|
118
|
+
currentUsage: typeof e.currentUsage == "number" ? e.currentUsage : 0,
|
|
119
|
+
usageLimit: typeof e.usageLimit == "number" ? e.usageLimit : null,
|
|
120
|
+
remaining: typeof e.remaining == "number" ? e.remaining : null,
|
|
121
|
+
hardLimit: e.hardLimit === !0,
|
|
122
|
+
items: r
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
featureId: t,
|
|
127
|
+
featureType: s,
|
|
128
|
+
hasAccess: r.some((e) => e.hasAccess),
|
|
129
|
+
currentUsage: 0,
|
|
130
|
+
usageLimit: null,
|
|
131
|
+
remaining: null,
|
|
132
|
+
hardLimit: !1,
|
|
133
|
+
items: r
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function Q(t) {
|
|
137
|
+
const r = {};
|
|
138
|
+
if (!t || !Array.isArray(t.entitlements))
|
|
139
|
+
return console.warn(
|
|
140
|
+
"Kelviq SDK: Invalid or empty entitlements array in API response.",
|
|
141
|
+
t
|
|
142
|
+
), r;
|
|
143
|
+
const s = {};
|
|
144
|
+
for (const e of t.entitlements) {
|
|
145
|
+
if (!e || typeof e.featureId != "string" || typeof e.featureType != "string") {
|
|
99
146
|
console.warn(
|
|
100
147
|
"Kelviq SDK: Skipping invalid raw entitlement object:",
|
|
101
|
-
|
|
148
|
+
e
|
|
102
149
|
);
|
|
103
|
-
|
|
150
|
+
continue;
|
|
104
151
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
n = {
|
|
114
|
-
...v,
|
|
115
|
-
type: "boolean"
|
|
116
|
-
};
|
|
117
|
-
break;
|
|
118
|
-
case "CUSTOMIZABLE": {
|
|
119
|
-
const o = t;
|
|
120
|
-
n = {
|
|
121
|
-
...v,
|
|
122
|
-
type: "customizable",
|
|
123
|
-
configuration: typeof o.value == "number" ? o.value : null
|
|
124
|
-
};
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
case "METER": {
|
|
128
|
-
const o = t, y = typeof o.usageLimit == "number" ? o.usageLimit : null, p = typeof o.currentUsage == "number" ? o.currentUsage : 0;
|
|
129
|
-
n = {
|
|
130
|
-
...v,
|
|
131
|
-
type: "metered",
|
|
132
|
-
limit: y,
|
|
133
|
-
used: p,
|
|
134
|
-
remaining: y !== null ? y - p : null,
|
|
135
|
-
// If limit is null (unlimited), remaining is also null
|
|
136
|
-
resetAt: o.resetAt,
|
|
137
|
-
hardLimit: o.hardLimit
|
|
138
|
-
};
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
default: {
|
|
142
|
-
const o = t;
|
|
143
|
-
console.warn(
|
|
144
|
-
`Kelviq SDK: Encountered unknown or unhandled entitlement featureType: '${String(
|
|
145
|
-
o.featureType
|
|
146
|
-
)}' for feature '${String(
|
|
147
|
-
o.featureId
|
|
148
|
-
)}'. This entitlement will be ignored.`
|
|
149
|
-
);
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
n && (i[n.featureKey] = n);
|
|
154
|
-
}), i);
|
|
152
|
+
s[e.featureId] || (s[e.featureId] = []), s[e.featureId].push(e);
|
|
153
|
+
}
|
|
154
|
+
for (const e in s)
|
|
155
|
+
r[e] = Z(
|
|
156
|
+
e,
|
|
157
|
+
s[e]
|
|
158
|
+
);
|
|
159
|
+
return r;
|
|
155
160
|
}
|
|
156
|
-
const
|
|
157
|
-
data: null,
|
|
158
|
-
isLoading: !1,
|
|
159
|
-
error: new Error(
|
|
160
|
-
"KelviqContext not fully initialized or entitlements not fetched."
|
|
161
|
-
)
|
|
162
|
-
}), I = {
|
|
161
|
+
const B = {
|
|
163
162
|
allEntitlements: {
|
|
164
163
|
data: null,
|
|
165
164
|
isLoading: !0,
|
|
@@ -168,8 +167,15 @@ const W = () => ({
|
|
|
168
167
|
refreshAllEntitlements: () => (console.warn(
|
|
169
168
|
"refreshAllEntitlements called on default KelviqContext. Ensure KelviqProvider is properly set up."
|
|
170
169
|
), Promise.resolve()),
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
getEntitlements: () => ({}),
|
|
171
|
+
getEntitlement: () => null,
|
|
172
|
+
getRawEntitlements: () => null,
|
|
173
|
+
getRawEntitlement: () => null,
|
|
174
|
+
hasAccess: () => !1,
|
|
175
|
+
updateEntitlement: () => {
|
|
176
|
+
console.warn(
|
|
177
|
+
"updateEntitlement called on default KelviqContext. Ensure KelviqProvider is properly set up."
|
|
178
|
+
);
|
|
173
179
|
},
|
|
174
180
|
isLoading: !0,
|
|
175
181
|
error: null,
|
|
@@ -177,285 +183,275 @@ const W = () => ({
|
|
|
177
183
|
environment: "production",
|
|
178
184
|
entitlementsPath: "",
|
|
179
185
|
customerId: ""
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
),
|
|
183
|
-
children:
|
|
184
|
-
apiUrl:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
environment: v = "production",
|
|
191
|
-
accessToken: o,
|
|
192
|
-
// Direct prop
|
|
193
|
-
config: y = {}
|
|
194
|
-
// Optional config object with defaults
|
|
186
|
+
}, O = N(
|
|
187
|
+
B
|
|
188
|
+
), ee = "https://edge.api.kelviq.com/api/v1/", te = "https://edge.sandboxapi.kelviq.com/api/v1/", ne = "entitlements/", oe = ({
|
|
189
|
+
children: t,
|
|
190
|
+
apiUrl: r,
|
|
191
|
+
entitlementsPath: s = ne,
|
|
192
|
+
customerId: e,
|
|
193
|
+
environment: E = "production",
|
|
194
|
+
accessToken: A,
|
|
195
|
+
config: h = {}
|
|
195
196
|
}) => {
|
|
196
197
|
const {
|
|
197
|
-
onError:
|
|
198
|
-
maxRetries:
|
|
198
|
+
onError: L,
|
|
199
|
+
maxRetries: a,
|
|
199
200
|
timeout: f,
|
|
200
|
-
backoffBaseDelay:
|
|
201
|
-
fetchEntitlementsOnMount:
|
|
202
|
-
|
|
203
|
-
} = y, m = i || (v === "sandbox" ? J : X), [a, s] = U({
|
|
201
|
+
backoffBaseDelay: y,
|
|
202
|
+
fetchEntitlementsOnMount: K = !0
|
|
203
|
+
} = h, p = r || (E === "sandbox" ? te : ee), [g, o] = P({
|
|
204
204
|
data: null,
|
|
205
|
-
isLoading: !!
|
|
206
|
-
// Only loading if apiBaseUrl is present and fetchOnMount is true
|
|
205
|
+
isLoading: !!p && K,
|
|
207
206
|
error: null
|
|
208
|
-
}), [
|
|
209
|
-
!!
|
|
210
|
-
), [
|
|
211
|
-
(
|
|
212
|
-
const
|
|
213
|
-
`Kelviq SDK (${
|
|
207
|
+
}), [u, S] = P(null), [i, c] = P(
|
|
208
|
+
!!p && K
|
|
209
|
+
), [U, w] = P(null), R = T(
|
|
210
|
+
(d, l, n) => {
|
|
211
|
+
const m = new Error(
|
|
212
|
+
`Kelviq SDK (${l}): ${d}`
|
|
214
213
|
);
|
|
215
|
-
console.error(
|
|
214
|
+
console.error(m.message, n || ""), w((q) => q || m), L && L(m);
|
|
216
215
|
},
|
|
217
|
-
[
|
|
218
|
-
),
|
|
219
|
-
if (!
|
|
220
|
-
const
|
|
221
|
-
return
|
|
216
|
+
[L]
|
|
217
|
+
), b = T(() => {
|
|
218
|
+
if (!p) {
|
|
219
|
+
const n = "API URL not configured. Cannot fetch entitlements.";
|
|
220
|
+
return o({
|
|
222
221
|
data: null,
|
|
223
222
|
isLoading: !1,
|
|
224
|
-
error: new Error(
|
|
225
|
-
}),
|
|
223
|
+
error: new Error(n)
|
|
224
|
+
}), R(n, "fetchAllEntitlements"), c(!1), Promise.reject(new Error(n));
|
|
226
225
|
}
|
|
227
|
-
if (!
|
|
228
|
-
const
|
|
229
|
-
return
|
|
226
|
+
if (!e) {
|
|
227
|
+
const n = "CustomerId must be provided as props to KelviqProvider.";
|
|
228
|
+
return o(() => ({
|
|
230
229
|
data: null,
|
|
231
230
|
isLoading: !1,
|
|
232
|
-
error: new Error(
|
|
233
|
-
})),
|
|
231
|
+
error: new Error(n)
|
|
232
|
+
})), R(n, "fetchAllEntitlements"), c(!1), Promise.reject(new Error(n));
|
|
234
233
|
}
|
|
235
|
-
|
|
236
|
-
...
|
|
234
|
+
o((n) => ({
|
|
235
|
+
...n,
|
|
237
236
|
isLoading: !0,
|
|
238
237
|
error: null
|
|
239
|
-
})),
|
|
240
|
-
const
|
|
241
|
-
return
|
|
242
|
-
url:
|
|
238
|
+
})), c(!0), w(null);
|
|
239
|
+
const d = `${p.replace(/\/$/, "")}/${s.replace(/^\//, "")}`;
|
|
240
|
+
return Y({
|
|
241
|
+
url: d,
|
|
243
242
|
method: "GET",
|
|
244
243
|
timeout: f,
|
|
245
|
-
maxRetries:
|
|
246
|
-
backoffBaseDelay:
|
|
247
|
-
|
|
248
|
-
accessToken: o,
|
|
244
|
+
maxRetries: a,
|
|
245
|
+
backoffBaseDelay: y,
|
|
246
|
+
accessToken: A,
|
|
249
247
|
queryParams: {
|
|
250
|
-
customer_id:
|
|
248
|
+
customer_id: e
|
|
251
249
|
}
|
|
252
|
-
}).then((
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
|
|
250
|
+
}).then((n) => {
|
|
251
|
+
if (n && n.data && Array.isArray(n.data.entitlements)) {
|
|
252
|
+
S(n.data);
|
|
253
|
+
const m = Q(
|
|
254
|
+
n.data
|
|
256
255
|
);
|
|
257
|
-
|
|
258
|
-
data:
|
|
256
|
+
o({
|
|
257
|
+
data: m,
|
|
259
258
|
isLoading: !1,
|
|
260
259
|
error: null
|
|
261
260
|
});
|
|
262
261
|
} else {
|
|
263
|
-
const
|
|
262
|
+
const m = new Error(
|
|
264
263
|
"Received empty, malformed, or invalid data structure from entitlements API."
|
|
265
264
|
);
|
|
266
|
-
throw
|
|
265
|
+
throw o({
|
|
267
266
|
data: null,
|
|
268
267
|
isLoading: !1,
|
|
269
|
-
error:
|
|
270
|
-
}),
|
|
271
|
-
|
|
268
|
+
error: m
|
|
269
|
+
}), R(
|
|
270
|
+
m.message,
|
|
272
271
|
"fetchAllEntitlements",
|
|
273
|
-
|
|
274
|
-
),
|
|
272
|
+
n
|
|
273
|
+
), m;
|
|
275
274
|
}
|
|
276
|
-
}).catch((
|
|
277
|
-
const
|
|
278
|
-
return
|
|
279
|
-
...
|
|
275
|
+
}).catch((n) => {
|
|
276
|
+
const m = n instanceof Error ? n : new Error(String(n));
|
|
277
|
+
return o((q) => ({
|
|
278
|
+
...q,
|
|
280
279
|
isLoading: !1,
|
|
281
|
-
error:
|
|
282
|
-
})),
|
|
280
|
+
error: m
|
|
281
|
+
})), R(m.message, "fetchAllEntitlements", n), Promise.reject(m);
|
|
283
282
|
}).finally(() => {
|
|
284
|
-
|
|
283
|
+
c(!1);
|
|
285
284
|
});
|
|
286
285
|
}, [
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
286
|
+
p,
|
|
287
|
+
e,
|
|
288
|
+
s,
|
|
290
289
|
f,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
290
|
+
a,
|
|
291
|
+
y,
|
|
292
|
+
A,
|
|
293
|
+
R
|
|
295
294
|
]);
|
|
296
|
-
|
|
297
|
-
let
|
|
298
|
-
if (!
|
|
299
|
-
if (
|
|
300
|
-
const
|
|
295
|
+
H(() => {
|
|
296
|
+
let d = !0;
|
|
297
|
+
if (!p) {
|
|
298
|
+
if (d) {
|
|
299
|
+
const l = new Error(
|
|
301
300
|
"KelviqProvider: `apiBaseUrl` must be provided in config."
|
|
302
301
|
);
|
|
303
|
-
|
|
304
|
-
...
|
|
302
|
+
w(l), c(!1), o((n) => ({
|
|
303
|
+
...n,
|
|
305
304
|
isLoading: !1,
|
|
306
|
-
error:
|
|
307
|
-
})),
|
|
305
|
+
error: l
|
|
306
|
+
})), h.onError && h.onError(l);
|
|
308
307
|
}
|
|
309
308
|
return;
|
|
310
309
|
}
|
|
311
|
-
return
|
|
312
|
-
|
|
310
|
+
return K ? b().catch((l) => {
|
|
311
|
+
d && i && c(!1), console.error(
|
|
313
312
|
"Kelviq SDK: Initial entitlement fetch failed.",
|
|
314
|
-
|
|
313
|
+
l
|
|
315
314
|
);
|
|
316
|
-
}) :
|
|
317
|
-
...
|
|
315
|
+
}) : d && (o((l) => ({
|
|
316
|
+
...l,
|
|
318
317
|
isLoading: !1,
|
|
319
318
|
data: null,
|
|
320
319
|
error: null
|
|
321
|
-
})),
|
|
322
|
-
|
|
320
|
+
})), c(!1)), () => {
|
|
321
|
+
d = !1;
|
|
323
322
|
};
|
|
324
|
-
}, [
|
|
325
|
-
const
|
|
326
|
-
(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
323
|
+
}, [p, K, h.onError]);
|
|
324
|
+
const x = T(
|
|
325
|
+
() => g.data ? g.data : {},
|
|
326
|
+
[g.data]
|
|
327
|
+
), M = T(
|
|
328
|
+
() => u ? {
|
|
329
|
+
customerId: u.customer_id,
|
|
330
|
+
entitlements: u.entitlements
|
|
331
|
+
} : null,
|
|
332
|
+
[u]
|
|
333
|
+
), C = T(
|
|
334
|
+
(d) => u ? {
|
|
335
|
+
customerId: u.customer_id,
|
|
336
|
+
entitlements: u.entitlements.filter(
|
|
337
|
+
(l) => l.featureId === d
|
|
338
|
+
)
|
|
339
|
+
} : null,
|
|
340
|
+
[u]
|
|
341
|
+
), _ = T(
|
|
342
|
+
(d) => g.data ? g.data[d] ?? null : null,
|
|
343
|
+
[g.data]
|
|
344
|
+
), F = T(
|
|
345
|
+
(d, l) => {
|
|
346
|
+
o((n) => {
|
|
347
|
+
if (!n.data) return n;
|
|
348
|
+
const m = n.data[d];
|
|
349
|
+
if (!m) return n;
|
|
350
|
+
const q = { ...m, ...l };
|
|
351
|
+
return ("usageLimit" in l || "currentUsage" in l) && (q.remaining = q.usageLimit !== null ? q.usageLimit - q.currentUsage : null), {
|
|
352
|
+
...n,
|
|
353
|
+
data: {
|
|
354
|
+
...n.data,
|
|
355
|
+
[d]: q
|
|
356
|
+
}
|
|
334
357
|
};
|
|
335
|
-
|
|
336
|
-
const u = a.data[g];
|
|
337
|
-
return u ? u.type === d ? {
|
|
338
|
-
data: u,
|
|
339
|
-
isLoading: !1,
|
|
340
|
-
error: null
|
|
341
|
-
} : {
|
|
342
|
-
data: null,
|
|
343
|
-
isLoading: !1,
|
|
344
|
-
error: new Error(
|
|
345
|
-
`Entitlement type mismatch for ${g}. Expected ${d}, got ${u.type}`
|
|
346
|
-
)
|
|
347
|
-
} : { data: null, isLoading: !1, error: null };
|
|
348
|
-
}
|
|
349
|
-
const r = m ? `Entitlements not yet fetched for ${g}. Call refreshAllEntitlements or ensure fetchEntitlementsOnMount is true.` : "API URL not configured. Check KelviqProvider configuration.";
|
|
350
|
-
return {
|
|
351
|
-
data: null,
|
|
352
|
-
isLoading: !1,
|
|
353
|
-
error: new Error(r)
|
|
354
|
-
};
|
|
358
|
+
});
|
|
355
359
|
},
|
|
356
|
-
[
|
|
357
|
-
),
|
|
358
|
-
(
|
|
359
|
-
if (
|
|
360
|
-
const
|
|
361
|
-
return
|
|
360
|
+
[]
|
|
361
|
+
), k = T(
|
|
362
|
+
(d) => {
|
|
363
|
+
if (!g.data) return !1;
|
|
364
|
+
const l = g.data[d];
|
|
365
|
+
return l ? l.hasAccess : !1;
|
|
362
366
|
},
|
|
363
|
-
[
|
|
364
|
-
),
|
|
367
|
+
[g.data]
|
|
368
|
+
), j = G(
|
|
365
369
|
() => ({
|
|
366
|
-
allEntitlements:
|
|
367
|
-
refreshAllEntitlements:
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
370
|
+
allEntitlements: g,
|
|
371
|
+
refreshAllEntitlements: b,
|
|
372
|
+
getEntitlements: x,
|
|
373
|
+
getEntitlement: _,
|
|
374
|
+
getRawEntitlements: M,
|
|
375
|
+
getRawEntitlement: C,
|
|
376
|
+
hasAccess: k,
|
|
377
|
+
updateEntitlement: F,
|
|
378
|
+
isLoading: i,
|
|
379
|
+
error: U,
|
|
380
|
+
environment: E,
|
|
381
|
+
apiUrl: p,
|
|
382
|
+
entitlementsPath: s,
|
|
383
|
+
customerId: e
|
|
376
384
|
}),
|
|
377
385
|
[
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
386
|
+
g,
|
|
387
|
+
b,
|
|
388
|
+
x,
|
|
389
|
+
_,
|
|
390
|
+
M,
|
|
391
|
+
C,
|
|
392
|
+
k,
|
|
393
|
+
F,
|
|
394
|
+
i,
|
|
395
|
+
U,
|
|
396
|
+
E,
|
|
397
|
+
p,
|
|
398
|
+
s,
|
|
399
|
+
e
|
|
388
400
|
]
|
|
389
401
|
);
|
|
390
|
-
return /* @__PURE__ */
|
|
391
|
-
},
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
402
|
+
return /* @__PURE__ */ v(O.Provider, { value: j, children: t });
|
|
403
|
+
}, D = () => {
|
|
404
|
+
const t = W(O);
|
|
405
|
+
if (t === void 0 || t === B)
|
|
394
406
|
throw new Error(
|
|
395
407
|
"useKelviq must be used within an initialized KelviqProvider."
|
|
396
408
|
);
|
|
397
|
-
return
|
|
398
|
-
},
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
condition: o
|
|
409
|
+
return t;
|
|
410
|
+
}, I = ({
|
|
411
|
+
featureId: t,
|
|
412
|
+
children: r,
|
|
413
|
+
fallback: s = null,
|
|
414
|
+
loadingComponent: e,
|
|
415
|
+
condition: E
|
|
405
416
|
}) => {
|
|
406
417
|
const {
|
|
407
|
-
getEntitlement:
|
|
408
|
-
isLoading:
|
|
409
|
-
error:
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
...i,
|
|
417
|
-
type: "customizable",
|
|
418
|
-
children: (t) => t.hasAccess && t.configuration !== null && typeof t.configuration == "number" ? e(t.configuration) : /* @__PURE__ */ q(b, { children: i.fallback || null })
|
|
419
|
-
}
|
|
420
|
-
), te = (e) => {
|
|
421
|
-
const i = (t) => t.hasAccess && (t.remaining === null || t.remaining > 0);
|
|
422
|
-
return /* @__PURE__ */ q(
|
|
423
|
-
k,
|
|
418
|
+
getEntitlement: A,
|
|
419
|
+
isLoading: h,
|
|
420
|
+
error: L
|
|
421
|
+
} = D(), a = A(t);
|
|
422
|
+
return h && !a ? /* @__PURE__ */ v($, { children: e !== void 0 ? e : s }) : L && !a ? /* @__PURE__ */ v($, { children: s }) : !a || !a.hasAccess || E && !E(a) ? /* @__PURE__ */ v($, { children: s }) : typeof r == "function" ? /* @__PURE__ */ v($, { children: r(a) }) : /* @__PURE__ */ v($, { children: r });
|
|
423
|
+
}, ie = (t) => /* @__PURE__ */ v(I, { ...t }), le = (t) => {
|
|
424
|
+
const r = (s) => s.hasAccess && (s.remaining === null || s.remaining > 0);
|
|
425
|
+
return /* @__PURE__ */ v(
|
|
426
|
+
I,
|
|
424
427
|
{
|
|
425
|
-
...
|
|
426
|
-
|
|
427
|
-
condition: e.condition || i
|
|
428
|
+
...t,
|
|
429
|
+
condition: t.condition || r
|
|
428
430
|
}
|
|
429
431
|
);
|
|
430
|
-
},
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const {
|
|
438
|
-
return
|
|
439
|
-
},
|
|
440
|
-
const { getEntitlement:
|
|
441
|
-
return
|
|
442
|
-
}, ie = (e) => {
|
|
443
|
-
const { getEntitlement: i } = K();
|
|
444
|
-
return i(e, "customizable");
|
|
445
|
-
}, se = (e) => {
|
|
446
|
-
const { getEntitlement: i } = K();
|
|
447
|
-
return i(e, "metered");
|
|
432
|
+
}, ae = (t) => /* @__PURE__ */ v(I, { ...t }), ue = () => {
|
|
433
|
+
const { allEntitlements: t } = D();
|
|
434
|
+
return t;
|
|
435
|
+
}, ce = (t) => {
|
|
436
|
+
const { getEntitlement: r } = D();
|
|
437
|
+
return r(t);
|
|
438
|
+
}, de = (t) => {
|
|
439
|
+
const { getEntitlement: r } = D();
|
|
440
|
+
return r(t);
|
|
441
|
+
}, me = (t) => {
|
|
442
|
+
const { getEntitlement: r } = D();
|
|
443
|
+
return r(t);
|
|
448
444
|
};
|
|
449
445
|
export {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
446
|
+
O as KelviqContext,
|
|
447
|
+
oe as KelviqProvider,
|
|
448
|
+
ae as ShowWhenBooleanEntitled,
|
|
449
|
+
ie as ShowWhenCustomizableEntitled,
|
|
450
|
+
le as ShowWhenMeteredEntitled,
|
|
451
|
+
B as defaultKelviqContextValue,
|
|
452
|
+
ue as useAllEntitlements,
|
|
453
|
+
ce as useBooleanEntitlement,
|
|
454
|
+
de as useCustomizableEntitlement,
|
|
455
|
+
D as useKelviq,
|
|
456
|
+
me as useMeteredEntitlement
|
|
461
457
|
};
|