@dismissible/react-client 0.3.0 → 0.3.2-canary.2.38782c4

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