@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.
@@ -1,165 +1,164 @@
1
- import { jsx as q, Fragment as b } from "react/jsx-runtime";
2
- import { createContext as C, useState as U, useCallback as R, useEffect as _, useMemo as F, useContext as O } from "react";
3
- const B = "GET", j = 5e3, N = 3, z = 1e3;
4
- function G(e) {
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: i = B,
7
- headers: t = {},
6
+ method: r = X,
7
+ headers: s = {},
8
8
  // Renamed to avoid conflict with internal 'headers' variable
9
- body: n,
10
- timeout: v = j,
11
- maxRetries: o = N,
12
- backoffBaseDelay: y = z,
13
- queryParams: p,
14
- accessToken: w
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
- } = e;
17
- let { url: f } = e, c = 0;
18
- return new Promise((T, m) => {
19
- if (p) {
20
- const s = new URLSearchParams();
21
- for (const h in p)
22
- p[h] !== void 0 && s.append(h, String(p[h]));
23
- s.toString() && (f += (f.includes("?") ? "&" : "?") + s.toString());
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 a() {
26
- const s = new XMLHttpRequest();
27
- s.open(i, f, !0), s.timeout = v;
28
- const h = {
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
- ...t
31
+ ...s
32
32
  // Apply custom headers, allowing them to override defaults
33
33
  };
34
- i !== "GET" && n && typeof n == "object" && !(n instanceof FormData) && (h["Content-Type"] || (h["Content-Type"] = "application/json")), w && (h.Authorization = `Bearer ${w}`);
35
- for (const [l, E] of Object.entries(h))
36
- s.setRequestHeader(l, E);
37
- s.onload = function() {
38
- const { status: l, statusText: E, responseText: A } = s;
39
- if (l >= 200 && l < 300)
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 S = A ? JSON.parse(A) : {};
42
- T({ status: l, statusText: E, data: S });
43
- } catch (S) {
44
- const $ = S instanceof Error ? S : new Error(String(S));
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: ${$.message}. Response: ${A}`
47
- ), m(
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: ${$.message}`
49
+ `Invalid JSON response: ${R.message}`
50
50
  )
51
51
  );
52
52
  }
53
53
  else
54
- L(
55
- `Request to ${f} failed with status ${l} ${E}. Response: ${A}`
54
+ S(
55
+ `Request to ${f} failed with status ${i} ${c}. Response: ${U}`
56
56
  );
57
- }, s.onerror = () => L(
57
+ }, o.onerror = () => S(
58
58
  `Network error for URL ${f}. The request could not be completed.`
59
- ), s.ontimeout = () => L(`Request to ${f} timed out.`);
60
- function L(l) {
61
- if (c < o) {
62
- c++;
63
- const E = Math.min(
64
- y * Math.pow(2, c - 1),
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 ${c}/${o}. Error: ${l}. Retrying in ${E}ms.`
70
- ), setTimeout(a, E);
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
- m(
72
+ p(
73
73
  new Error(
74
- `${l} (Max retries ${o} reached)`
74
+ `${i} (Max retries ${A} reached)`
75
75
  )
76
76
  );
77
77
  }
78
78
  try {
79
- let l = n;
80
- n && typeof n == "object" && !(n instanceof FormData) && h["Content-Type"] === "application/json" && (l = JSON.stringify(n)), s.send(l);
81
- } catch (l) {
82
- const E = l instanceof Error ? l : new Error(String(l));
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
- E
86
- ), m(new Error(`Failed to send request: ${E.message}`));
85
+ c
86
+ ), p(new Error(`Failed to send request: ${c.message}`));
87
87
  }
88
88
  }
89
- a();
89
+ g();
90
90
  });
91
91
  }
92
- function H(e) {
93
- const i = {};
94
- return !e || !Array.isArray(e.entitlements) ? (console.warn(
95
- "Kelviq SDK: Invalid or empty entitlements array in API response.",
96
- e
97
- ), i) : (e.entitlements.forEach((t) => {
98
- if (!t || typeof t.featureId != "string" || typeof t.featureType != "string") {
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
- t
148
+ e
102
149
  );
103
- return;
150
+ continue;
104
151
  }
105
- let n = null;
106
- const v = {
107
- // Omit type as it's added in switch
108
- featureKey: t.featureId,
109
- hasAccess: t.hasAccess
110
- };
111
- switch (t.featureType) {
112
- case "BOOLEAN":
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 W = () => ({
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
- getEntitlement: W,
172
- hasAccess: () => {
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
- }, M = C(
181
- I
182
- ), X = "https://edge.api.kelviq.com/api/v1/", J = "https://edge.sandboxapi.kelviq.com/api/v1/", V = "entitlements/", Q = ({
183
- children: e,
184
- apiUrl: i,
185
- // Direct prop
186
- entitlementsPath: t = V,
187
- // Direct prop
188
- customerId: n,
189
- // Direct prop
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: p,
198
- maxRetries: w,
198
+ onError: L,
199
+ maxRetries: a,
199
200
  timeout: f,
200
- backoffBaseDelay: c,
201
- fetchEntitlementsOnMount: T = !0
202
- // Default within config
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: !!m && T,
206
- // Only loading if apiBaseUrl is present and fetchOnMount is true
205
+ isLoading: !!p && K,
207
206
  error: null
208
- }), [h, L] = U(
209
- !!m && T
210
- ), [l, E] = U(null), A = R(
211
- (g, d, r) => {
212
- const u = new Error(
213
- `Kelviq SDK (${d}): ${g}`
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(u.message, r || ""), E((P) => P || u), p && p(u);
214
+ console.error(m.message, n || ""), w((q) => q || m), L && L(m);
216
215
  },
217
- [p]
218
- ), S = R(() => {
219
- if (!m) {
220
- const r = "API URL not configured. Cannot fetch entitlements.";
221
- return s({
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(r)
225
- }), A(r, "fetchAllEntitlements"), L(!1), Promise.reject(new Error(r));
223
+ error: new Error(n)
224
+ }), R(n, "fetchAllEntitlements"), c(!1), Promise.reject(new Error(n));
226
225
  }
227
- if (!n) {
228
- const r = "CustomerId must be provided as props to KelviqProvider.";
229
- return s(() => ({
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(r)
233
- })), A(r, "fetchAllEntitlements"), L(!1), Promise.reject(new Error(r));
231
+ error: new Error(n)
232
+ })), R(n, "fetchAllEntitlements"), c(!1), Promise.reject(new Error(n));
234
233
  }
235
- s((r) => ({
236
- ...r,
234
+ o((n) => ({
235
+ ...n,
237
236
  isLoading: !0,
238
237
  error: null
239
- })), L(!0), E(null);
240
- const g = `${m.replace(/\/$/, "")}/${t.replace(/^\//, "")}`;
241
- return G({
242
- url: g,
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: w,
246
- backoffBaseDelay: c,
247
- // Pass this to apiRequest
248
- accessToken: o,
244
+ maxRetries: a,
245
+ backoffBaseDelay: y,
246
+ accessToken: A,
249
247
  queryParams: {
250
- customer_id: n
248
+ customer_id: e
251
249
  }
252
- }).then((r) => {
253
- if (r && r.data && Array.isArray(r.data.entitlements)) {
254
- const u = H(
255
- r.data
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
- s({
258
- data: u,
256
+ o({
257
+ data: m,
259
258
  isLoading: !1,
260
259
  error: null
261
260
  });
262
261
  } else {
263
- const u = new Error(
262
+ const m = new Error(
264
263
  "Received empty, malformed, or invalid data structure from entitlements API."
265
264
  );
266
- throw s({
265
+ throw o({
267
266
  data: null,
268
267
  isLoading: !1,
269
- error: u
270
- }), A(
271
- u.message,
268
+ error: m
269
+ }), R(
270
+ m.message,
272
271
  "fetchAllEntitlements",
273
- r
274
- ), u;
272
+ n
273
+ ), m;
275
274
  }
276
- }).catch((r) => {
277
- const u = r instanceof Error ? r : new Error(String(r));
278
- return s((P) => ({
279
- ...P,
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: u
282
- })), A(u.message, "fetchAllEntitlements", r), Promise.reject(u);
280
+ error: m
281
+ })), R(m.message, "fetchAllEntitlements", n), Promise.reject(m);
283
282
  }).finally(() => {
284
- L(!1);
283
+ c(!1);
285
284
  });
286
285
  }, [
287
- m,
288
- n,
289
- t,
286
+ p,
287
+ e,
288
+ s,
290
289
  f,
291
- w,
292
- c,
293
- o,
294
- A
290
+ a,
291
+ y,
292
+ A,
293
+ R
295
294
  ]);
296
- _(() => {
297
- let g = !0;
298
- if (!m) {
299
- if (g) {
300
- const d = new Error(
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
- E(d), L(!1), s((r) => ({
304
- ...r,
302
+ w(l), c(!1), o((n) => ({
303
+ ...n,
305
304
  isLoading: !1,
306
- error: d
307
- })), y.onError && y.onError(d);
305
+ error: l
306
+ })), h.onError && h.onError(l);
308
307
  }
309
308
  return;
310
309
  }
311
- return T ? S().catch((d) => {
312
- g && h && L(!1), console.error(
310
+ return K ? b().catch((l) => {
311
+ d && i && c(!1), console.error(
313
312
  "Kelviq SDK: Initial entitlement fetch failed.",
314
- d
313
+ l
315
314
  );
316
- }) : g && (s((d) => ({
317
- ...d,
315
+ }) : d && (o((l) => ({
316
+ ...l,
318
317
  isLoading: !1,
319
318
  data: null,
320
319
  error: null
321
- })), L(!1)), () => {
322
- g = !1;
320
+ })), c(!1)), () => {
321
+ d = !1;
323
322
  };
324
- }, [m, T, y.onError]);
325
- const $ = R(
326
- (g, d) => {
327
- if (a.isLoading)
328
- return { data: null, isLoading: !0, error: null };
329
- if (a.error && !a.data)
330
- return {
331
- data: null,
332
- isLoading: !1,
333
- error: a.error
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
- if (a.data) {
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
- [a, m]
357
- ), D = R(
358
- (g) => {
359
- if (a.isLoading && !a.data || a.error && !a.data || !a.data) return;
360
- const d = a.data[g];
361
- return d ? d.hasAccess : !1;
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
- [a]
364
- ), x = F(
367
+ [g.data]
368
+ ), j = G(
365
369
  () => ({
366
- allEntitlements: a,
367
- refreshAllEntitlements: S,
368
- getEntitlement: $,
369
- hasAccess: D,
370
- isLoading: h,
371
- error: l,
372
- environment: v,
373
- apiUrl: m,
374
- entitlementsPath: t,
375
- customerId: n
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
- a,
379
- S,
380
- $,
381
- D,
382
- h,
383
- l,
384
- v,
385
- m,
386
- t,
387
- n
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__ */ q(M.Provider, { value: x, children: e });
391
- }, K = () => {
392
- const e = O(M);
393
- if (e === void 0 || e === I)
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 e;
398
- }, k = ({
399
- featureKey: e,
400
- type: i,
401
- children: t,
402
- fallback: n = null,
403
- loadingComponent: v,
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: y,
408
- isLoading: p,
409
- error: w,
410
- allEntitlements: f
411
- } = K(), c = y(e, i);
412
- return c.isLoading || p && !c.data && !c.error && !f.data && !f.error ? /* @__PURE__ */ q(b, { children: v !== void 0 ? v : n }) : c.error || w && !c.data ? /* @__PURE__ */ q(b, { children: n }) : !c.data || !c.data.hasAccess || o && !o(c.data) ? /* @__PURE__ */ q(b, { children: n }) : typeof t == "function" ? /* @__PURE__ */ q(b, { children: t(c.data) }) : /* @__PURE__ */ q(b, { children: t });
413
- }, ee = ({ children: e, ...i }) => /* @__PURE__ */ q(
414
- k,
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
- ...e,
426
- type: "metered",
427
- condition: e.condition || i
428
+ ...t,
429
+ condition: t.condition || r
428
430
  }
429
431
  );
430
- }, re = (e) => /* @__PURE__ */ q(
431
- k,
432
- {
433
- ...e,
434
- type: "boolean"
435
- }
436
- ), ne = () => {
437
- const { allEntitlements: e } = K();
438
- return e;
439
- }, oe = (e) => {
440
- const { getEntitlement: i } = K();
441
- return i(e, "boolean");
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
- M as KelviqContext,
451
- Q as KelviqProvider,
452
- re as ShowWhenBooleanEntitled,
453
- ee as ShowWhenConfigEntitled,
454
- te as ShowWhenMeteredEntitled,
455
- I as defaultKelviqContextValue,
456
- ne as useAllEntitlements,
457
- oe as useBooleanEntitlement,
458
- ie as useConfigEntitlement,
459
- K as useKelviq,
460
- se as useMeteredEntitlement
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
  };