@dismissible/react-client 2.0.0 → 2.1.0-canary.6.0a7a428

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,59 +1,287 @@
1
- var he = Object.defineProperty, me = Object.defineProperties;
2
- var ye = Object.getOwnPropertyDescriptors;
3
- var J = Object.getOwnPropertySymbols;
4
- var te = Object.prototype.hasOwnProperty, re = Object.prototype.propertyIsEnumerable;
5
- var ee = (e, r, t) => r in e ? he(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, b = (e, r) => {
6
- for (var t in r || (r = {}))
7
- te.call(r, t) && ee(e, t, r[t]);
8
- if (J)
9
- for (var t of J(r))
10
- re.call(r, t) && ee(e, t, r[t]);
1
+ var me = Object.defineProperty, ye = Object.defineProperties;
2
+ var pe = Object.getOwnPropertyDescriptors;
3
+ var B = Object.getOwnPropertySymbols;
4
+ var re = Object.prototype.hasOwnProperty, se = Object.prototype.propertyIsEnumerable;
5
+ var V = (r, t, e) => t in r ? me(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, b = (r, t) => {
6
+ for (var e in t || (t = {}))
7
+ re.call(t, e) && V(r, e, t[e]);
8
+ if (B)
9
+ for (var e of B(t))
10
+ se.call(t, e) && V(r, e, t[e]);
11
+ return r;
12
+ }, v = (r, t) => ye(r, pe(t));
13
+ var X = (r, t) => {
14
+ var e = {};
15
+ for (var n in r)
16
+ re.call(r, n) && t.indexOf(n) < 0 && (e[n] = r[n]);
17
+ if (r != null && B)
18
+ for (var n of B(r))
19
+ t.indexOf(n) < 0 && se.call(r, n) && (e[n] = r[n]);
11
20
  return e;
12
- }, E = (e, r) => me(e, ye(r));
13
- var G = (e, r) => {
14
- var t = {};
15
- for (var n in e)
16
- te.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
17
- if (e != null && J)
18
- for (var n of J(e))
19
- r.indexOf(n) < 0 && re.call(e, n) && (t[n] = e[n]);
20
- return t;
21
21
  };
22
- var $ = (e, r, t) => new Promise((n, o) => {
23
- var s = (f) => {
22
+ var O = (r, t, e) => V(r, typeof t != "symbol" ? t + "" : t, e);
23
+ var C = (r, t, e) => new Promise((n, i) => {
24
+ var s = (u) => {
24
25
  try {
25
- c(t.next(f));
26
+ a(e.next(u));
26
27
  } catch (d) {
27
- o(d);
28
+ i(d);
28
29
  }
29
- }, i = (f) => {
30
+ }, o = (u) => {
30
31
  try {
31
- c(t.throw(f));
32
+ a(e.throw(u));
32
33
  } catch (d) {
33
- o(d);
34
+ i(d);
34
35
  }
35
- }, c = (f) => f.done ? n(f.value) : Promise.resolve(f.value).then(s, i);
36
- c((t = t.apply(e, r)).next());
36
+ }, a = (u) => u.done ? n(u.value) : Promise.resolve(u.value).then(s, o);
37
+ a((e = e.apply(r, t)).next());
37
38
  });
38
- import { jsx as U, jsxs as be } from "react/jsx-runtime";
39
- import { createContext as pe, useContext as we, useMemo as X, useRef as W, useState as z, useCallback as K, useEffect as Q } from "react";
40
- const ge = /\{[^{}]+\}/g, ve = () => {
41
- var e, r;
42
- return typeof process == "object" && Number.parseInt((r = (e = process == null ? void 0 : process.versions) == null ? void 0 : e.node) == null ? void 0 : r.substring(0, 2)) >= 18 && process.versions.undici;
39
+ import { jsx as T, jsxs as be } from "react/jsx-runtime";
40
+ import { createContext as we, useContext as ge, useRef as J, useState as k, useCallback as Y, useEffect as _, useMemo as W } from "react";
41
+ const ne = (r, t, e) => {
42
+ try {
43
+ const n = `${t}_${r}`, i = localStorage.getItem(n);
44
+ if (!i) return null;
45
+ const { data: s, timestamp: o } = JSON.parse(i);
46
+ return e && Date.now() - o > e ? (localStorage.removeItem(n), null) : s;
47
+ } catch (n) {
48
+ return null;
49
+ }
50
+ }, Z = (r, t, e) => {
51
+ try {
52
+ const n = `${e}_${r}`, i = {
53
+ data: t,
54
+ timestamp: Date.now()
55
+ };
56
+ localStorage.setItem(n, JSON.stringify(i));
57
+ } catch (n) {
58
+ console.warn("Failed to cache dismissible item:", n);
59
+ }
60
+ }, ie = (r, t) => {
61
+ try {
62
+ const e = `${t}_${r}`;
63
+ localStorage.removeItem(e);
64
+ } catch (e) {
65
+ console.warn("Failed to remove cached dismissible item:", e);
66
+ }
67
+ }, le = we(
68
+ null
69
+ ), Re = () => {
70
+ const r = ge(le);
71
+ if (!r)
72
+ throw new Error(
73
+ "useDismissibleContext must be used within a DismissibleProvider"
74
+ );
75
+ return r;
76
+ }, ve = "dismissible", Ce = (r, t = {}) => {
77
+ const {
78
+ initialData: e,
79
+ enableCache: n = !0,
80
+ cachePrefix: i = ve,
81
+ cacheExpiration: s
82
+ } = t, { userId: o, client: a, baseUrl: u, getAuthHeaders: d, batchScheduler: m } = Re(), h = `${o}-${r}`, c = J({
83
+ enableCache: n,
84
+ cachePrefix: i,
85
+ cacheExpiration: s
86
+ }), f = J(r), E = J(h), x = J(null), [F, A] = k(!1), [I, S] = k(), [q, H] = k(() => {
87
+ if (e) return e;
88
+ if (n) {
89
+ const l = ne(
90
+ h,
91
+ i,
92
+ s
93
+ );
94
+ if (l) return l;
95
+ }
96
+ }), $ = Y(() => C(null, null, function* () {
97
+ var w;
98
+ if (n) {
99
+ const y = ne(
100
+ h,
101
+ i,
102
+ s
103
+ );
104
+ if (y != null && y.dismissedAt) {
105
+ m.primeCache(y), H(y), A(!1);
106
+ return;
107
+ }
108
+ }
109
+ (w = x.current) == null || w.abort();
110
+ const l = new AbortController();
111
+ x.current = l, A(!0), S(void 0);
112
+ try {
113
+ const y = yield m.getItem(r);
114
+ if (l.signal.aborted)
115
+ return;
116
+ H(y), n && Z(h, y, i);
117
+ } catch (y) {
118
+ if (y instanceof Error && y.name === "AbortError" || l.signal.aborted)
119
+ return;
120
+ S(
121
+ y instanceof Error ? y : new Error("Unknown error occurred")
122
+ );
123
+ } finally {
124
+ l.signal.aborted || A(!1);
125
+ }
126
+ }), [
127
+ r,
128
+ h,
129
+ n,
130
+ i,
131
+ s,
132
+ m
133
+ ]);
134
+ _(() => {
135
+ const l = f.current !== r, w = E.current !== h;
136
+ l || w ? (f.current = r, E.current = h, $()) : e || $();
137
+ }, [r, h, e, $]), _(() => () => {
138
+ var l;
139
+ (l = x.current) == null || l.abort();
140
+ }, []), _(() => {
141
+ const l = c.current;
142
+ (l.enableCache !== n || l.cachePrefix !== i || l.cacheExpiration !== s) && (l.cachePrefix !== i && ie(h, l.cachePrefix), !n && l.enableCache && ie(h, l.cachePrefix), c.current = {
143
+ enableCache: n,
144
+ cachePrefix: i,
145
+ cacheExpiration: s
146
+ }, $());
147
+ }, [n, i, s, h, $]);
148
+ const K = Y(() => C(null, null, function* () {
149
+ S(void 0);
150
+ try {
151
+ const l = yield d(), w = yield a.dismiss({
152
+ userId: o,
153
+ itemId: r,
154
+ baseUrl: u,
155
+ authHeaders: l
156
+ });
157
+ H(w), m.updateCache(w), n && Z(h, w, i);
158
+ } catch (l) {
159
+ throw S(
160
+ l instanceof Error ? l : new Error("Failed to dismiss item")
161
+ ), l;
162
+ }
163
+ }), [
164
+ r,
165
+ o,
166
+ h,
167
+ n,
168
+ i,
169
+ a,
170
+ u,
171
+ d,
172
+ m
173
+ ]), U = Y(() => C(null, null, function* () {
174
+ S(void 0);
175
+ try {
176
+ const l = yield d(), w = yield a.restore({
177
+ userId: o,
178
+ itemId: r,
179
+ baseUrl: u,
180
+ authHeaders: l
181
+ });
182
+ H(w), m.updateCache(w), n && Z(h, w, i);
183
+ } catch (l) {
184
+ throw S(
185
+ l instanceof Error ? l : new Error("Failed to restore item")
186
+ ), l;
187
+ }
188
+ }), [
189
+ r,
190
+ o,
191
+ h,
192
+ n,
193
+ i,
194
+ a,
195
+ u,
196
+ d,
197
+ m
198
+ ]);
199
+ return {
200
+ dismissedAt: q == null ? void 0 : q.dismissedAt,
201
+ dismiss: K,
202
+ restore: U,
203
+ isLoading: F,
204
+ error: I,
205
+ item: q
206
+ };
207
+ }, Ee = () => /* @__PURE__ */ T("div", { className: "dismissible-loading", "aria-live": "polite", children: "Loading..." }), Se = () => /* @__PURE__ */ T("div", { className: "dismissible-error", role: "alert", children: "Unable to load content. Please try again later." }), xe = ({ onDismiss: r, ariaLabel: t }) => /* @__PURE__ */ T(
208
+ "button",
209
+ {
210
+ className: "dismissible-button",
211
+ onClick: r,
212
+ "aria-label": t,
213
+ type: "button",
214
+ children: "×"
215
+ }
216
+ ), Me = ({
217
+ itemId: r,
218
+ children: t,
219
+ onDismiss: e,
220
+ LoadingComponent: n = Ee,
221
+ ErrorComponent: i = Se,
222
+ DismissButtonComponent: s = xe,
223
+ enableCache: o,
224
+ cachePrefix: a,
225
+ cacheExpiration: u,
226
+ ignoreErrors: d = !1
227
+ }) => {
228
+ const { dismissedAt: m, isLoading: h, error: c, dismiss: f } = Ce(
229
+ r,
230
+ {
231
+ enableCache: o,
232
+ cachePrefix: a,
233
+ cacheExpiration: u
234
+ }
235
+ ), [E, x] = k(!1), [F, A] = k(r);
236
+ r !== F && (A(r), x(!1));
237
+ const I = () => C(null, null, function* () {
238
+ x(!0);
239
+ try {
240
+ yield f(), e == null || e();
241
+ } catch (S) {
242
+ x(!1);
243
+ }
244
+ });
245
+ return h && n ? /* @__PURE__ */ T(n, { itemId: r }) : h && !n ? null : c && i && !d ? /* @__PURE__ */ T(i, { itemId: r, error: c }) : m || E ? null : /* @__PURE__ */ be("div", { className: "dismissible-container", children: [
246
+ /* @__PURE__ */ T("div", { className: "dismissible-content", children: t }),
247
+ s ? /* @__PURE__ */ T(
248
+ s,
249
+ {
250
+ onDismiss: I,
251
+ ariaLabel: `Dismiss ${r}`
252
+ }
253
+ ) : null
254
+ ] });
255
+ }, Ie = (r) => C(null, null, function* () {
256
+ if (typeof r == "function")
257
+ try {
258
+ const t = r();
259
+ return yield Promise.resolve(t);
260
+ } catch (t) {
261
+ console.warn("Failed to resolve JWT from function:", t);
262
+ return;
263
+ }
264
+ return r;
265
+ }), qe = (r) => C(null, null, function* () {
266
+ const t = yield Ie(r);
267
+ return t ? { Authorization: `Bearer ${t}` } : {};
268
+ }), Ae = /\{[^{}]+\}/g, $e = () => {
269
+ var r, t;
270
+ return typeof process == "object" && Number.parseInt((t = (r = process == null ? void 0 : process.versions) == null ? void 0 : r.node) == null ? void 0 : t.substring(0, 2)) >= 18 && process.versions.undici;
43
271
  };
44
- function Ee() {
272
+ function je() {
45
273
  return Math.random().toString(36).slice(2, 11);
46
274
  }
47
- function Re(e) {
48
- let j = b({}, e), {
49
- baseUrl: r = "",
50
- Request: t = globalThis.Request,
275
+ function De(r) {
276
+ let h = b({}, r), {
277
+ baseUrl: t = "",
278
+ Request: e = globalThis.Request,
51
279
  fetch: n = globalThis.fetch,
52
- querySerializer: o,
280
+ querySerializer: i,
53
281
  bodySerializer: s,
54
- headers: i,
55
- requestInitExt: c = void 0
56
- } = j, f = G(j, [
282
+ headers: o,
283
+ requestInitExt: a = void 0
284
+ } = h, u = X(h, [
57
285
  "baseUrl",
58
286
  "Request",
59
287
  "fetch",
@@ -62,23 +290,23 @@ function Re(e) {
62
290
  "headers",
63
291
  "requestInitExt"
64
292
  ]);
65
- c = ve() ? c : void 0, r = oe(r);
293
+ a = $e() ? a : void 0, t = ce(t);
66
294
  const d = [];
67
- function g(l, a) {
68
- return $(this, null, function* () {
69
- var Z;
70
- const Y = a || {}, {
71
- baseUrl: R,
295
+ function m(c, f) {
296
+ return C(this, null, function* () {
297
+ var te;
298
+ const ee = f || {}, {
299
+ baseUrl: E,
72
300
  fetch: x = n,
73
- Request: I = t,
74
- headers: C,
75
- params: v = {},
76
- parseAs: A = "json",
77
- querySerializer: S,
78
- bodySerializer: k = s != null ? s : xe,
79
- body: F,
80
- middleware: u = []
81
- } = Y, y = G(Y, [
301
+ Request: F = e,
302
+ headers: A,
303
+ params: I = {},
304
+ parseAs: S = "json",
305
+ querySerializer: q,
306
+ bodySerializer: H = s != null ? s : He,
307
+ body: $,
308
+ middleware: K = []
309
+ } = ee, U = X(ee, [
82
310
  "baseUrl",
83
311
  "fetch",
84
312
  "Request",
@@ -90,630 +318,581 @@ function Re(e) {
90
318
  "body",
91
319
  "middleware"
92
320
  ]);
93
- let h = r;
94
- R && (h = (Z = oe(R)) != null ? Z : r);
95
- let H = typeof o == "function" ? o : ne(o);
96
- S && (H = typeof S == "function" ? S : ne(b(b({}, typeof o == "object" ? o : {}), S)));
97
- const P = F === void 0 ? void 0 : k(
98
- F,
321
+ let l = t;
322
+ E && (l = (te = ce(E)) != null ? te : t);
323
+ let w = typeof i == "function" ? i : oe(i);
324
+ q && (w = typeof q == "function" ? q : oe(b(b({}, typeof i == "object" ? i : {}), q)));
325
+ const y = $ === void 0 ? void 0 : H(
326
+ $,
99
327
  // Note: we declare mergeHeaders() both here and below because it’s a bit of a chicken-or-egg situation:
100
328
  // bodySerializer() needs all headers so we aren’t dropping ones set by the user, however,
101
329
  // the result of this ALSO sets the lowest-priority content-type header. So we re-merge below,
102
330
  // setting the content-type at the very beginning to be overwritten.
103
331
  // Lastly, based on the way headers work, it’s not a simple “present-or-not” check becauase null intentionally un-sets headers.
104
- se(i, C, v.header)
105
- ), fe = se(
332
+ ae(o, A, I.header)
333
+ ), de = ae(
106
334
  // with no body, we should not to set Content-Type
107
- P === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
108
- P instanceof FormData ? {} : {
335
+ y === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
336
+ y instanceof FormData ? {} : {
109
337
  "Content-Type": "application/json"
110
338
  },
111
- i,
112
- C,
113
- v.header
114
- ), D = [...d, ...u], de = E(b(b({
339
+ o,
340
+ A,
341
+ I.header
342
+ ), j = [...d, ...K], he = v(b(b({
115
343
  redirect: "follow"
116
- }, f), y), {
117
- body: P,
118
- headers: fe
344
+ }, u), U), {
345
+ body: y,
346
+ headers: de
119
347
  });
120
- let L, N, T = new I(
121
- Se(l, { baseUrl: h, params: v, querySerializer: H }),
122
- de
123
- ), m;
124
- for (const w in y)
125
- w in T || (T[w] = y[w]);
126
- if (D.length) {
127
- L = Ee(), N = Object.freeze({
128
- baseUrl: h,
348
+ let L, M, D = new F(
349
+ Pe(c, { baseUrl: l, params: I, querySerializer: w }),
350
+ he
351
+ ), p;
352
+ for (const R in U)
353
+ R in D || (D[R] = U[R]);
354
+ if (j.length) {
355
+ L = je(), M = Object.freeze({
356
+ baseUrl: l,
129
357
  fetch: x,
130
- parseAs: A,
131
- querySerializer: H,
132
- bodySerializer: k
358
+ parseAs: S,
359
+ querySerializer: w,
360
+ bodySerializer: H
133
361
  });
134
- for (const w of D)
135
- if (w && typeof w == "object" && typeof w.onRequest == "function") {
136
- const p = yield w.onRequest({
137
- request: T,
138
- schemaPath: l,
139
- params: v,
140
- options: N,
362
+ for (const R of j)
363
+ if (R && typeof R == "object" && typeof R.onRequest == "function") {
364
+ const g = yield R.onRequest({
365
+ request: D,
366
+ schemaPath: c,
367
+ params: I,
368
+ options: M,
141
369
  id: L
142
370
  });
143
- if (p)
144
- if (p instanceof I)
145
- T = p;
146
- else if (p instanceof Response) {
147
- m = p;
371
+ if (g)
372
+ if (g instanceof F)
373
+ D = g;
374
+ else if (g instanceof Response) {
375
+ p = g;
148
376
  break;
149
377
  } else
150
378
  throw new Error("onRequest: must return new Request() or Response() when modifying the request");
151
379
  }
152
380
  }
153
- if (!m) {
381
+ if (!p) {
154
382
  try {
155
- m = yield x(T, c);
156
- } catch (w) {
157
- let p = w;
158
- if (D.length)
159
- for (let q = D.length - 1; q >= 0; q--) {
160
- const M = D[q];
161
- if (M && typeof M == "object" && typeof M.onError == "function") {
162
- const O = yield M.onError({
163
- request: T,
164
- error: p,
165
- schemaPath: l,
166
- params: v,
167
- options: N,
383
+ p = yield x(D, a);
384
+ } catch (R) {
385
+ let g = R;
386
+ if (j.length)
387
+ for (let P = j.length - 1; P >= 0; P--) {
388
+ const N = j[P];
389
+ if (N && typeof N == "object" && typeof N.onError == "function") {
390
+ const z = yield N.onError({
391
+ request: D,
392
+ error: g,
393
+ schemaPath: c,
394
+ params: I,
395
+ options: M,
168
396
  id: L
169
397
  });
170
- if (O) {
171
- if (O instanceof Response) {
172
- p = void 0, m = O;
398
+ if (z) {
399
+ if (z instanceof Response) {
400
+ g = void 0, p = z;
173
401
  break;
174
402
  }
175
- if (O instanceof Error) {
176
- p = O;
403
+ if (z instanceof Error) {
404
+ g = z;
177
405
  continue;
178
406
  }
179
407
  throw new Error("onError: must return new Response() or instance of Error");
180
408
  }
181
409
  }
182
410
  }
183
- if (p)
184
- throw p;
411
+ if (g)
412
+ throw g;
185
413
  }
186
- if (D.length)
187
- for (let w = D.length - 1; w >= 0; w--) {
188
- const p = D[w];
189
- if (p && typeof p == "object" && typeof p.onResponse == "function") {
190
- const q = yield p.onResponse({
191
- request: T,
192
- response: m,
193
- schemaPath: l,
194
- params: v,
195
- options: N,
414
+ if (j.length)
415
+ for (let R = j.length - 1; R >= 0; R--) {
416
+ const g = j[R];
417
+ if (g && typeof g == "object" && typeof g.onResponse == "function") {
418
+ const P = yield g.onResponse({
419
+ request: D,
420
+ response: p,
421
+ schemaPath: c,
422
+ params: I,
423
+ options: M,
196
424
  id: L
197
425
  });
198
- if (q) {
199
- if (!(q instanceof Response))
426
+ if (P) {
427
+ if (!(P instanceof Response))
200
428
  throw new Error("onResponse: must return new Response() when modifying the response");
201
- m = q;
429
+ p = P;
202
430
  }
203
431
  }
204
432
  }
205
433
  }
206
- if (m.status === 204 || T.method === "HEAD" || m.headers.get("Content-Length") === "0")
207
- return m.ok ? { data: void 0, response: m } : { error: void 0, response: m };
208
- if (m.ok)
209
- return A === "stream" ? { data: m.body, response: m } : { data: yield m[A](), response: m };
210
- let B = yield m.text();
434
+ if (p.status === 204 || D.method === "HEAD" || p.headers.get("Content-Length") === "0")
435
+ return p.ok ? { data: void 0, response: p } : { error: void 0, response: p };
436
+ if (p.ok)
437
+ return S === "stream" ? { data: p.body, response: p } : { data: yield p[S](), response: p };
438
+ let Q = yield p.text();
211
439
  try {
212
- B = JSON.parse(B);
213
- } catch (w) {
440
+ Q = JSON.parse(Q);
441
+ } catch (R) {
214
442
  }
215
- return { error: B, response: m };
443
+ return { error: Q, response: p };
216
444
  });
217
445
  }
218
446
  return {
219
- request(l, a, R) {
220
- return g(a, E(b({}, R), { method: l.toUpperCase() }));
447
+ request(c, f, E) {
448
+ return m(f, v(b({}, E), { method: c.toUpperCase() }));
221
449
  },
222
450
  /** Call a GET endpoint */
223
- GET(l, a) {
224
- return g(l, E(b({}, a), { method: "GET" }));
451
+ GET(c, f) {
452
+ return m(c, v(b({}, f), { method: "GET" }));
225
453
  },
226
454
  /** Call a PUT endpoint */
227
- PUT(l, a) {
228
- return g(l, E(b({}, a), { method: "PUT" }));
455
+ PUT(c, f) {
456
+ return m(c, v(b({}, f), { method: "PUT" }));
229
457
  },
230
458
  /** Call a POST endpoint */
231
- POST(l, a) {
232
- return g(l, E(b({}, a), { method: "POST" }));
459
+ POST(c, f) {
460
+ return m(c, v(b({}, f), { method: "POST" }));
233
461
  },
234
462
  /** Call a DELETE endpoint */
235
- DELETE(l, a) {
236
- return g(l, E(b({}, a), { method: "DELETE" }));
463
+ DELETE(c, f) {
464
+ return m(c, v(b({}, f), { method: "DELETE" }));
237
465
  },
238
466
  /** Call a OPTIONS endpoint */
239
- OPTIONS(l, a) {
240
- return g(l, E(b({}, a), { method: "OPTIONS" }));
467
+ OPTIONS(c, f) {
468
+ return m(c, v(b({}, f), { method: "OPTIONS" }));
241
469
  },
242
470
  /** Call a HEAD endpoint */
243
- HEAD(l, a) {
244
- return g(l, E(b({}, a), { method: "HEAD" }));
471
+ HEAD(c, f) {
472
+ return m(c, v(b({}, f), { method: "HEAD" }));
245
473
  },
246
474
  /** Call a PATCH endpoint */
247
- PATCH(l, a) {
248
- return g(l, E(b({}, a), { method: "PATCH" }));
475
+ PATCH(c, f) {
476
+ return m(c, v(b({}, f), { method: "PATCH" }));
249
477
  },
250
478
  /** Call a TRACE endpoint */
251
- TRACE(l, a) {
252
- return g(l, E(b({}, a), { method: "TRACE" }));
479
+ TRACE(c, f) {
480
+ return m(c, v(b({}, f), { method: "TRACE" }));
253
481
  },
254
482
  /** Register middleware */
255
- use(...l) {
256
- for (const a of l)
257
- if (a) {
258
- if (typeof a != "object" || !("onRequest" in a || "onResponse" in a || "onError" in a))
483
+ use(...c) {
484
+ for (const f of c)
485
+ if (f) {
486
+ if (typeof f != "object" || !("onRequest" in f || "onResponse" in f || "onError" in f))
259
487
  throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
260
- d.push(a);
488
+ d.push(f);
261
489
  }
262
490
  },
263
491
  /** Unregister middleware */
264
- eject(...l) {
265
- for (const a of l) {
266
- const R = d.indexOf(a);
267
- R !== -1 && d.splice(R, 1);
492
+ eject(...c) {
493
+ for (const f of c) {
494
+ const E = d.indexOf(f);
495
+ E !== -1 && d.splice(E, 1);
268
496
  }
269
497
  }
270
498
  };
271
499
  }
272
- function _(e, r, t) {
273
- if (r == null)
500
+ function G(r, t, e) {
501
+ if (t == null)
274
502
  return "";
275
- if (typeof r == "object")
503
+ if (typeof t == "object")
276
504
  throw new Error(
277
505
  "Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
278
506
  );
279
- return `${e}=${(t == null ? void 0 : t.allowReserved) === !0 ? r : encodeURIComponent(r)}`;
507
+ return `${r}=${(e == null ? void 0 : e.allowReserved) === !0 ? t : encodeURIComponent(t)}`;
280
508
  }
281
- function ce(e, r, t) {
282
- if (!r || typeof r != "object")
509
+ function ue(r, t, e) {
510
+ if (!t || typeof t != "object")
283
511
  return "";
284
- const n = [], o = {
512
+ const n = [], i = {
285
513
  simple: ",",
286
514
  label: ".",
287
515
  matrix: ";"
288
- }[t.style] || "&";
289
- if (t.style !== "deepObject" && t.explode === !1) {
290
- for (const c in r)
291
- n.push(c, t.allowReserved === !0 ? r[c] : encodeURIComponent(r[c]));
292
- const i = n.join(",");
293
- switch (t.style) {
516
+ }[e.style] || "&";
517
+ if (e.style !== "deepObject" && e.explode === !1) {
518
+ for (const a in t)
519
+ n.push(a, e.allowReserved === !0 ? t[a] : encodeURIComponent(t[a]));
520
+ const o = n.join(",");
521
+ switch (e.style) {
294
522
  case "form":
295
- return `${e}=${i}`;
523
+ return `${r}=${o}`;
296
524
  case "label":
297
- return `.${i}`;
525
+ return `.${o}`;
298
526
  case "matrix":
299
- return `;${e}=${i}`;
527
+ return `;${r}=${o}`;
300
528
  default:
301
- return i;
529
+ return o;
302
530
  }
303
531
  }
304
- for (const i in r) {
305
- const c = t.style === "deepObject" ? `${e}[${i}]` : i;
306
- n.push(_(c, r[i], t));
532
+ for (const o in t) {
533
+ const a = e.style === "deepObject" ? `${r}[${o}]` : o;
534
+ n.push(G(a, t[o], e));
307
535
  }
308
- const s = n.join(o);
309
- return t.style === "label" || t.style === "matrix" ? `${o}${s}` : s;
536
+ const s = n.join(i);
537
+ return e.style === "label" || e.style === "matrix" ? `${i}${s}` : s;
310
538
  }
311
- function le(e, r, t) {
312
- if (!Array.isArray(r))
539
+ function fe(r, t, e) {
540
+ if (!Array.isArray(t))
313
541
  return "";
314
- if (t.explode === !1) {
315
- const s = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[t.style] || ",", i = (t.allowReserved === !0 ? r : r.map((c) => encodeURIComponent(c))).join(s);
316
- switch (t.style) {
542
+ if (e.explode === !1) {
543
+ const s = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", o = (e.allowReserved === !0 ? t : t.map((a) => encodeURIComponent(a))).join(s);
544
+ switch (e.style) {
317
545
  case "simple":
318
- return i;
546
+ return o;
319
547
  case "label":
320
- return `.${i}`;
548
+ return `.${o}`;
321
549
  case "matrix":
322
- return `;${e}=${i}`;
550
+ return `;${r}=${o}`;
323
551
  // case "spaceDelimited":
324
552
  // case "pipeDelimited":
325
553
  default:
326
- return `${e}=${i}`;
554
+ return `${r}=${o}`;
327
555
  }
328
556
  }
329
- const n = { simple: ",", label: ".", matrix: ";" }[t.style] || "&", o = [];
330
- for (const s of r)
331
- t.style === "simple" || t.style === "label" ? o.push(t.allowReserved === !0 ? s : encodeURIComponent(s)) : o.push(_(e, s, t));
332
- return t.style === "label" || t.style === "matrix" ? `${n}${o.join(n)}` : o.join(n);
557
+ const n = { simple: ",", label: ".", matrix: ";" }[e.style] || "&", i = [];
558
+ for (const s of t)
559
+ e.style === "simple" || e.style === "label" ? i.push(e.allowReserved === !0 ? s : encodeURIComponent(s)) : i.push(G(r, s, e));
560
+ return e.style === "label" || e.style === "matrix" ? `${n}${i.join(n)}` : i.join(n);
333
561
  }
334
- function ne(e) {
335
- return function(t) {
562
+ function oe(r) {
563
+ return function(e) {
336
564
  const n = [];
337
- if (t && typeof t == "object")
338
- for (const o in t) {
339
- const s = t[o];
565
+ if (e && typeof e == "object")
566
+ for (const i in e) {
567
+ const s = e[i];
340
568
  if (s != null) {
341
569
  if (Array.isArray(s)) {
342
570
  if (s.length === 0)
343
571
  continue;
344
572
  n.push(
345
- le(o, s, E(b({
573
+ fe(i, s, v(b({
346
574
  style: "form",
347
575
  explode: !0
348
- }, e == null ? void 0 : e.array), {
349
- allowReserved: (e == null ? void 0 : e.allowReserved) || !1
576
+ }, r == null ? void 0 : r.array), {
577
+ allowReserved: (r == null ? void 0 : r.allowReserved) || !1
350
578
  }))
351
579
  );
352
580
  continue;
353
581
  }
354
582
  if (typeof s == "object") {
355
583
  n.push(
356
- ce(o, s, E(b({
584
+ ue(i, s, v(b({
357
585
  style: "deepObject",
358
586
  explode: !0
359
- }, e == null ? void 0 : e.object), {
360
- allowReserved: (e == null ? void 0 : e.allowReserved) || !1
587
+ }, r == null ? void 0 : r.object), {
588
+ allowReserved: (r == null ? void 0 : r.allowReserved) || !1
361
589
  }))
362
590
  );
363
591
  continue;
364
592
  }
365
- n.push(_(o, s, e));
593
+ n.push(G(i, s, r));
366
594
  }
367
595
  }
368
596
  return n.join("&");
369
597
  };
370
598
  }
371
- function Ce(e, r) {
599
+ function Te(r, t) {
372
600
  var n;
373
- let t = e;
374
- for (const o of (n = e.match(ge)) != null ? n : []) {
375
- let s = o.substring(1, o.length - 1), i = !1, c = "simple";
376
- if (s.endsWith("*") && (i = !0, s = s.substring(0, s.length - 1)), s.startsWith(".") ? (c = "label", s = s.substring(1)) : s.startsWith(";") && (c = "matrix", s = s.substring(1)), !r || r[s] === void 0 || r[s] === null)
601
+ let e = r;
602
+ for (const i of (n = r.match(Ae)) != null ? n : []) {
603
+ let s = i.substring(1, i.length - 1), o = !1, a = "simple";
604
+ if (s.endsWith("*") && (o = !0, s = s.substring(0, s.length - 1)), s.startsWith(".") ? (a = "label", s = s.substring(1)) : s.startsWith(";") && (a = "matrix", s = s.substring(1)), !t || t[s] === void 0 || t[s] === null)
377
605
  continue;
378
- const f = r[s];
379
- if (Array.isArray(f)) {
380
- t = t.replace(o, le(s, f, { style: c, explode: i }));
606
+ const u = t[s];
607
+ if (Array.isArray(u)) {
608
+ e = e.replace(i, fe(s, u, { style: a, explode: o }));
381
609
  continue;
382
610
  }
383
- if (typeof f == "object") {
384
- t = t.replace(o, ce(s, f, { style: c, explode: i }));
611
+ if (typeof u == "object") {
612
+ e = e.replace(i, ue(s, u, { style: a, explode: o }));
385
613
  continue;
386
614
  }
387
- if (c === "matrix") {
388
- t = t.replace(o, `;${_(s, f)}`);
615
+ if (a === "matrix") {
616
+ e = e.replace(i, `;${G(s, u)}`);
389
617
  continue;
390
618
  }
391
- t = t.replace(o, c === "label" ? `.${encodeURIComponent(f)}` : encodeURIComponent(f));
619
+ e = e.replace(i, a === "label" ? `.${encodeURIComponent(u)}` : encodeURIComponent(u));
392
620
  }
393
- return t;
621
+ return e;
394
622
  }
395
- function xe(e, r) {
396
- var t, n;
397
- return e instanceof FormData ? e : r && (r.get instanceof Function ? (t = r.get("Content-Type")) != null ? t : r.get("content-type") : (n = r["Content-Type"]) != null ? n : r["content-type"]) === "application/x-www-form-urlencoded" ? new URLSearchParams(e).toString() : JSON.stringify(e);
623
+ function He(r, t) {
624
+ var e, n;
625
+ return r instanceof FormData ? r : t && (t.get instanceof Function ? (e = t.get("Content-Type")) != null ? e : t.get("content-type") : (n = t["Content-Type"]) != null ? n : t["content-type"]) === "application/x-www-form-urlencoded" ? new URLSearchParams(r).toString() : JSON.stringify(r);
398
626
  }
399
- function Se(e, r) {
400
- var o, s;
401
- let t = `${r.baseUrl}${e}`;
402
- (o = r.params) != null && o.path && (t = Ce(t, r.params.path));
403
- let n = r.querySerializer((s = r.params.query) != null ? s : {});
404
- return n.startsWith("?") && (n = n.substring(1)), n && (t += `?${n}`), t;
627
+ function Pe(r, t) {
628
+ var i, s;
629
+ let e = `${t.baseUrl}${r}`;
630
+ (i = t.params) != null && i.path && (e = Te(e, t.params.path));
631
+ let n = t.querySerializer((s = t.params.query) != null ? s : {});
632
+ return n.startsWith("?") && (n = n.substring(1)), n && (e += `?${n}`), e;
405
633
  }
406
- function se(...e) {
407
- const r = new Headers();
408
- for (const t of e) {
409
- if (!t || typeof t != "object")
634
+ function ae(...r) {
635
+ const t = new Headers();
636
+ for (const e of r) {
637
+ if (!e || typeof e != "object")
410
638
  continue;
411
- const n = t instanceof Headers ? t.entries() : Object.entries(t);
412
- for (const [o, s] of n)
639
+ const n = e instanceof Headers ? e.entries() : Object.entries(e);
640
+ for (const [i, s] of n)
413
641
  if (s === null)
414
- r.delete(o);
642
+ t.delete(i);
415
643
  else if (Array.isArray(s))
416
- for (const i of s)
417
- r.append(o, i);
418
- else s !== void 0 && r.set(o, s);
644
+ for (const o of s)
645
+ t.append(i, o);
646
+ else s !== void 0 && t.set(i, s);
419
647
  }
420
- return r;
648
+ return t;
421
649
  }
422
- function oe(e) {
423
- return e.endsWith("/") ? e.substring(0, e.length - 1) : e;
650
+ function ce(r) {
651
+ return r.endsWith("/") ? r.substring(0, r.length - 1) : r;
424
652
  }
425
- const ie = (e, r, t) => {
426
- try {
427
- const n = `${r}_${e}`, o = localStorage.getItem(n);
428
- if (!o) return null;
429
- const { data: s, timestamp: i } = JSON.parse(o);
430
- return t && Date.now() - i > t ? (localStorage.removeItem(n), null) : s;
431
- } catch (n) {
432
- return null;
433
- }
434
- }, V = (e, r, t) => {
435
- try {
436
- const n = `${t}_${e}`, o = {
437
- data: r,
438
- timestamp: Date.now()
439
- };
440
- localStorage.setItem(n, JSON.stringify(o));
441
- } catch (n) {
442
- console.warn("Failed to cache dismissible item:", n);
443
- }
444
- }, ae = (e, r) => {
445
- try {
446
- const t = `${r}_${e}`;
447
- localStorage.removeItem(t);
448
- } catch (t) {
449
- console.warn("Failed to remove cached dismissible item:", t);
450
- }
451
- }, ue = pe(
452
- null
453
- ), Ae = () => {
454
- const e = we(ue);
455
- if (!e)
456
- throw new Error(
457
- "useDismissibleContext must be used within a DismissibleProvider"
458
- );
459
- return e;
460
- }, $e = "dismissible", je = (e, r = {}) => {
461
- const {
462
- initialData: t,
463
- enableCache: n = !0,
464
- cachePrefix: o = $e,
465
- cacheExpiration: s
466
- } = r, i = Ae(), { userId: c } = i, f = X(() => Re({
467
- baseUrl: i.baseUrl,
653
+ const Fe = (r) => {
654
+ const t = De({
655
+ baseUrl: r,
468
656
  headers: {}
469
- }), [i.baseUrl]), d = X(() => `${c}-${e}`, [c, e]), g = W({
470
- enableCache: n,
471
- cachePrefix: o,
472
- cacheExpiration: s
473
- }), j = W(e), l = W(d), a = W(null), [R, x] = z(!1), [I, C] = z(), [v, A] = z(() => {
474
- if (t) return t;
475
- if (n) {
476
- const u = ie(
477
- d,
478
- o,
479
- s
480
- );
481
- if (u) return u;
482
- }
483
- }), S = K(() => $(null, null, function* () {
484
- var y;
485
- if (n) {
486
- const h = ie(
487
- d,
488
- o,
489
- s
490
- );
491
- if (h != null && h.dismissedAt) {
492
- A(h), x(!1);
493
- return;
494
- }
495
- }
496
- (y = a.current) == null || y.abort();
497
- const u = new AbortController();
498
- a.current = u, x(!0), C(void 0);
499
- try {
500
- const h = yield i.getAuthHeaders(), { data: H, error: P } = yield f.GET(
657
+ });
658
+ return {
659
+ getOrCreate: (e) => C(null, null, function* () {
660
+ const { userId: n, itemId: i, authHeaders: s, signal: o } = e, { data: a, error: u } = yield t.GET(
501
661
  "/v1/users/{userId}/items/{itemId}",
502
662
  {
503
663
  params: {
504
664
  path: {
505
- userId: c,
506
- itemId: e
665
+ userId: n,
666
+ itemId: i
507
667
  }
508
668
  },
509
- headers: h,
510
- signal: u.signal
669
+ headers: s,
670
+ signal: o
511
671
  }
512
672
  );
513
- if (P || !H)
673
+ if (u || !a)
514
674
  throw new Error("Failed to fetch dismissible item");
515
- A(H.data), n && V(d, H.data, o);
516
- } catch (h) {
517
- if (h instanceof Error && h.name === "AbortError")
518
- return;
519
- C(
520
- h instanceof Error ? h : new Error("Unknown error occurred")
675
+ return a.data;
676
+ }),
677
+ batchGetOrCreate: (e) => C(null, null, function* () {
678
+ const { userId: n, itemIds: i, authHeaders: s, signal: o } = e, { data: a, error: u } = yield t.POST(
679
+ "/v1/users/{userId}/items",
680
+ {
681
+ params: {
682
+ path: {
683
+ userId: n
684
+ }
685
+ },
686
+ body: {
687
+ items: i
688
+ },
689
+ headers: s,
690
+ signal: o
691
+ }
521
692
  );
522
- } finally {
523
- x(!1);
524
- }
525
- }), [
526
- e,
527
- c,
528
- d,
529
- n,
530
- o,
531
- s,
532
- f,
533
- i
534
- ]);
535
- Q(() => {
536
- const u = j.current !== e, y = l.current !== d;
537
- u || y ? (j.current = e, l.current = d, S()) : t || S();
538
- }, [e, d, t, S]), Q(() => () => {
539
- var u;
540
- (u = a.current) == null || u.abort();
541
- }, []), Q(() => {
542
- const u = g.current;
543
- (u.enableCache !== n || u.cachePrefix !== o || u.cacheExpiration !== s) && (u.cachePrefix !== o && ae(d, u.cachePrefix), !n && u.enableCache && ae(d, u.cachePrefix), g.current = {
544
- enableCache: n,
545
- cachePrefix: o,
546
- cacheExpiration: s
547
- }, S());
548
- }, [n, o, s, d, S]);
549
- const k = K(() => $(null, null, function* () {
550
- C(void 0);
551
- try {
552
- const u = yield i.getAuthHeaders(), { data: y, error: h } = yield f.DELETE(
693
+ if (u || !a)
694
+ throw new Error("Failed to batch fetch dismissible items");
695
+ return a.data;
696
+ }),
697
+ dismiss: (e) => C(null, null, function* () {
698
+ const { userId: n, itemId: i, authHeaders: s } = e, { data: o, error: a } = yield t.DELETE(
553
699
  "/v1/users/{userId}/items/{itemId}",
554
700
  {
555
701
  params: {
556
702
  path: {
557
- userId: c,
558
- itemId: e
703
+ userId: n,
704
+ itemId: i
559
705
  }
560
706
  },
561
- headers: u
707
+ headers: s
562
708
  }
563
709
  );
564
- if (h || !y)
710
+ if (a || !o)
565
711
  throw new Error("Failed to dismiss item");
566
- A(y.data), n && V(d, y.data, o);
567
- } catch (u) {
568
- throw C(
569
- u instanceof Error ? u : new Error("Failed to dismiss item")
570
- ), u;
571
- }
572
- }), [
573
- e,
574
- c,
575
- d,
576
- n,
577
- o,
578
- f,
579
- i
580
- ]), F = K(() => $(null, null, function* () {
581
- C(void 0);
582
- try {
583
- const u = yield i.getAuthHeaders(), { data: y, error: h } = yield f.POST(
712
+ return o.data;
713
+ }),
714
+ restore: (e) => C(null, null, function* () {
715
+ const { userId: n, itemId: i, authHeaders: s } = e, { data: o, error: a } = yield t.POST(
584
716
  "/v1/users/{userId}/items/{itemId}",
585
717
  {
586
718
  params: {
587
719
  path: {
588
- userId: c,
589
- itemId: e
720
+ userId: n,
721
+ itemId: i
590
722
  }
591
723
  },
592
- headers: u
724
+ headers: s
593
725
  }
594
726
  );
595
- if (h || !y)
727
+ if (a || !o)
596
728
  throw new Error("Failed to restore item");
597
- A(y.data), n && V(d, y.data, o);
598
- } catch (u) {
599
- throw C(
600
- u instanceof Error ? u : new Error("Failed to restore item")
601
- ), u;
602
- }
603
- }), [
604
- e,
605
- c,
606
- d,
607
- n,
608
- o,
609
- f,
610
- i
611
- ]);
612
- return {
613
- dismissedAt: v == null ? void 0 : v.dismissedAt,
614
- dismiss: k,
615
- restore: F,
616
- isLoading: R,
617
- error: I,
618
- item: v
729
+ return o.data;
730
+ })
619
731
  };
620
- }, De = () => /* @__PURE__ */ U("div", { className: "dismissible-loading", "aria-live": "polite", children: "Loading..." }), Te = () => /* @__PURE__ */ U("div", { className: "dismissible-error", role: "alert", children: "Unable to load content. Please try again later." }), Ue = ({ onDismiss: e, ariaLabel: r }) => /* @__PURE__ */ U(
621
- "button",
622
- {
623
- className: "dismissible-button",
624
- onClick: e,
625
- "aria-label": r,
626
- type: "button",
627
- children: "×"
628
- }
629
- ), ke = ({
630
- itemId: e,
631
- children: r,
632
- onDismiss: t,
633
- LoadingComponent: n = De,
634
- ErrorComponent: o = Te,
635
- DismissButtonComponent: s = Ue,
636
- enableCache: i,
637
- cachePrefix: c,
638
- cacheExpiration: f,
639
- ignoreErrors: d = !1
640
- }) => {
641
- const { dismissedAt: g, isLoading: j, error: l, dismiss: a } = je(
642
- e,
643
- {
644
- enableCache: i,
645
- cachePrefix: c,
646
- cacheExpiration: f
647
- }
648
- ), [R, x] = z(!1), [I, C] = z(e);
649
- e !== I && (C(e), x(!1));
650
- const v = () => $(null, null, function* () {
651
- x(!0);
652
- try {
653
- yield a(), t == null || t();
654
- } catch (A) {
655
- x(!1);
656
- }
657
- });
658
- return j && n ? /* @__PURE__ */ U(n, { itemId: e }) : j && !n ? null : l && o && !d ? /* @__PURE__ */ U(o, { itemId: e, error: l }) : g || R ? null : /* @__PURE__ */ be("div", { className: "dismissible-container", children: [
659
- /* @__PURE__ */ U("div", { className: "dismissible-content", children: r }),
660
- s ? /* @__PURE__ */ U(
661
- s,
662
- {
663
- onDismiss: v,
664
- ariaLabel: `Dismiss ${e}`
665
- }
666
- ) : null
667
- ] });
668
- }, He = (e) => $(null, null, function* () {
669
- if (typeof e == "function")
670
- try {
671
- const r = e();
672
- return yield Promise.resolve(r);
673
- } catch (r) {
674
- console.warn("Failed to resolve JWT from function:", r);
675
- return;
676
- }
677
- return e;
678
- }), qe = (e) => $(null, null, function* () {
679
- const r = yield He(e);
680
- return r ? { Authorization: `Bearer ${r}` } : {};
681
- }), Ie = (e) => {
732
+ }, Oe = (r) => {
682
733
  try {
683
- const r = new URL(e), t = r.hostname === "localhost" || r.hostname === "127.0.0.1" || r.hostname === "[::1]", n = r.protocol === "https:";
684
- return { isSecure: n || t, isLocalhost: t, isHttps: n };
685
- } catch (r) {
734
+ const t = new URL(r), e = t.hostname === "localhost" || t.hostname === "127.0.0.1" || t.hostname === "[::1]", n = t.protocol === "https:";
735
+ return { isSecure: n || e, isLocalhost: e, isHttps: n };
736
+ } catch (t) {
686
737
  return { isSecure: !1, isLocalhost: !1, isHttps: !1 };
687
738
  }
688
- }, Fe = ({
689
- userId: e,
690
- jwt: r,
691
- baseUrl: t,
692
- children: n
739
+ };
740
+ class Ue {
741
+ constructor(t) {
742
+ O(this, "config");
743
+ O(this, "pendingRequests", []);
744
+ O(this, "isScheduled", !1);
745
+ O(this, "cache", /* @__PURE__ */ new Map());
746
+ O(this, "inFlightRequests", /* @__PURE__ */ new Map());
747
+ var e;
748
+ this.config = v(b({}, t), {
749
+ maxBatchSize: (e = t.maxBatchSize) != null ? e : 50
750
+ });
751
+ }
752
+ /**
753
+ * Request a dismissible item. If called multiple times in the same
754
+ * JavaScript tick, requests will be batched into a single API call.
755
+ *
756
+ * @param itemId - The item ID to fetch
757
+ * @returns Promise resolving to the DismissibleItem
758
+ */
759
+ getItem(t) {
760
+ const e = this.cache.get(t);
761
+ if (e)
762
+ return Promise.resolve(e);
763
+ const n = this.inFlightRequests.get(t);
764
+ if (n)
765
+ return n;
766
+ let i, s;
767
+ const o = new Promise((a, u) => {
768
+ i = a, s = u;
769
+ });
770
+ return this.pendingRequests.push({
771
+ itemId: t,
772
+ resolve: i,
773
+ reject: s
774
+ }), this.inFlightRequests.set(t, o), o.catch(() => {
775
+ }).finally(() => {
776
+ this.inFlightRequests.delete(t);
777
+ }), this.isScheduled || (this.isScheduled = !0, queueMicrotask(() => this.executeBatch())), o;
778
+ }
779
+ /**
780
+ * Pre-populate the cache with items (e.g., from localStorage)
781
+ */
782
+ primeCache(t) {
783
+ this.cache.set(t.itemId, t);
784
+ }
785
+ /**
786
+ * Update an item in the cache (e.g., after dismiss/restore)
787
+ */
788
+ updateCache(t) {
789
+ this.cache.set(t.itemId, t);
790
+ }
791
+ /**
792
+ * Clear the in-memory cache
793
+ */
794
+ clearCache() {
795
+ this.cache.clear();
796
+ }
797
+ /**
798
+ * Execute the batched requests
799
+ */
800
+ executeBatch() {
801
+ return C(this, null, function* () {
802
+ this.isScheduled = !1;
803
+ const t = this.pendingRequests;
804
+ if (this.pendingRequests = [], t.length === 0)
805
+ return;
806
+ const e = /* @__PURE__ */ new Map();
807
+ for (const s of t) {
808
+ const o = e.get(s.itemId);
809
+ o ? o.push(s) : e.set(s.itemId, [s]);
810
+ }
811
+ const n = Array.from(e.keys()), i = [];
812
+ for (let s = 0; s < n.length; s += this.config.maxBatchSize)
813
+ i.push(n.slice(s, s + this.config.maxBatchSize));
814
+ try {
815
+ const s = yield this.config.getAuthHeaders(), a = (yield Promise.all(
816
+ i.map(
817
+ (d) => this.config.client.batchGetOrCreate({
818
+ userId: this.config.userId,
819
+ itemIds: d,
820
+ baseUrl: this.config.baseUrl,
821
+ authHeaders: s
822
+ })
823
+ )
824
+ )).flat(), u = /* @__PURE__ */ new Map();
825
+ for (const d of a)
826
+ u.set(d.itemId, d), this.cache.set(d.itemId, d);
827
+ for (const [d, m] of e) {
828
+ const h = u.get(d);
829
+ if (h)
830
+ for (const c of m)
831
+ c.resolve(h);
832
+ else {
833
+ const c = new Error(`Item ${d} not found in batch response`);
834
+ for (const f of m)
835
+ f.reject(c);
836
+ }
837
+ }
838
+ } catch (s) {
839
+ const o = s instanceof Error ? s : new Error("Batch request failed");
840
+ for (const a of t)
841
+ a.reject(o);
842
+ }
843
+ });
844
+ }
845
+ }
846
+ const Ne = ({
847
+ userId: r,
848
+ jwt: t,
849
+ baseUrl: e,
850
+ client: n,
851
+ children: i
693
852
  }) => {
694
- const { isSecure: o } = Ie(t);
695
- o || console.warn(
696
- `[dismissible] Insecure baseUrl "${t}". Use https:// in production (or localhost for development). JWT tokens may be exposed over insecure connections.`
697
- );
698
- const s = X(
853
+ _(() => {
854
+ const { isSecure: d } = Oe(e);
855
+ d || console.warn(
856
+ `[dismissible] Insecure baseUrl "${e}". Use https:// in production (or localhost for development). JWT tokens may be exposed over insecure connections.`
857
+ );
858
+ }, [e]);
859
+ const s = W(
860
+ () => n != null ? n : Fe(e),
861
+ [n, e]
862
+ ), o = W(
863
+ () => () => C(null, null, function* () {
864
+ return yield qe(t);
865
+ }),
866
+ [t]
867
+ ), a = W(
868
+ () => new Ue({
869
+ userId: r,
870
+ baseUrl: e,
871
+ client: s,
872
+ getAuthHeaders: o
873
+ }),
874
+ [r, e, s, o]
875
+ ), u = W(
699
876
  () => ({
700
- userId: e,
701
- jwt: r,
702
- baseUrl: t,
703
- getAuthHeaders: () => $(null, null, function* () {
704
- return yield qe(r);
705
- })
877
+ userId: r,
878
+ jwt: t,
879
+ baseUrl: e,
880
+ getAuthHeaders: o,
881
+ client: s,
882
+ batchScheduler: a
706
883
  }),
707
- [e, r, t]
884
+ [r, t, e, o, s, a]
708
885
  );
709
- return /* @__PURE__ */ U(ue.Provider, { value: s, children: n });
886
+ return /* @__PURE__ */ T(le.Provider, { value: u, children: i });
710
887
  };
711
888
  export {
712
- ke as Dismissible,
713
- ue as DismissibleContext,
714
- Fe as DismissibleProvider,
889
+ Ue as BatchScheduler,
890
+ Me as Dismissible,
891
+ le as DismissibleContext,
892
+ Ne as DismissibleProvider,
893
+ Fe as createDefaultClient,
715
894
  qe as getAuthHeaders,
716
- He as resolveJwt,
717
- Ae as useDismissibleContext,
718
- je as useDismissibleItem
895
+ Ie as resolveJwt,
896
+ Re as useDismissibleContext,
897
+ Ce as useDismissibleItem
719
898
  };