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

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