@dismissible/react-client 2.1.0 → 3.0.0

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