@dismissible/react-client 0.3.2-canary.4.578bcba → 0.3.2-canary.5.88e2777

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.
package/README.md CHANGED
@@ -203,7 +203,6 @@ The main component for creating dismissible content.
203
203
  | `enableCache` | `boolean` | ❌ | Enable localStorage caching (default: true) |
204
204
  | `cachePrefix` | `string` | ❌ | Cache key prefix (default: 'dismissible') |
205
205
  | `cacheExpiration` | `number` | ❌ | Cache expiration time in milliseconds |
206
- | `metadata` | `string[]` | ❌ | Optional metadata as key:value pairs (can be repeated) |
207
206
 
208
207
  #### Example
209
208
 
@@ -219,25 +218,6 @@ The main component for creating dismissible content.
219
218
  </Dismissible>
220
219
  ```
221
220
 
222
- #### Example with Metadata
223
-
224
- ```tsx
225
- <Dismissible
226
- itemId="promo-banner"
227
- metadata={{
228
- version: 2,
229
- category: "promotional",
230
- campaign: "summer-sale"
231
- }}
232
- onDismiss={() => console.log('Banner dismissed')}
233
- >
234
- <div className="promo">
235
- <h3>Special Offer!</h3>
236
- <p>Get 50% off your first order</p>
237
- </div>
238
- </Dismissible>
239
- ```
240
-
241
221
  ### `useDismissibleItem` Hook
242
222
 
243
223
  For custom implementations and advanced use cases.
@@ -256,7 +236,6 @@ For custom implementations and advanced use cases.
256
236
  | `enableCache` | `boolean` | ❌ | Enable localStorage caching (default: true) |
257
237
  | `cachePrefix` | `string` | ❌ | Cache key prefix (default: 'dismissible') |
258
238
  | `cacheExpiration` | `number` | ❌ | Cache expiration time in milliseconds |
259
- | `metadata` | `IMetadata` | ❌ | Optional metadata object (`{ [key: string]: string \| number }`) |
260
239
  | `initialData` | `IDismissibleItem` | ❌ | Initial data for the dismissible item |
261
240
 
262
241
  #### Returns
@@ -598,56 +577,6 @@ function SmartNotification({ itemId, message, type = 'info' }) {
598
577
  }
599
578
  ```
600
579
 
601
- ### Using Metadata with Dismissible Items
602
-
603
- Metadata allows you to attach additional information to dismissible items, which can be useful for analytics, filtering, or conditional logic:
604
-
605
- ```tsx
606
- import { Dismissible, useDismissibleItem } from '@dismissible/react-client';
607
-
608
- // Using metadata with the Dismissible component (object format)
609
- function PromotionalBanner({ campaignId, version }) {
610
- return (
611
- <Dismissible
612
- itemId={`promo-${campaignId}`}
613
- metadata={{
614
- version: version,
615
- category: "promotional",
616
- campaign: campaignId,
617
- }}
618
- >
619
- <div className="promo-banner">
620
- <h3>Special Offer!</h3>
621
- <p>Limited time promotion</p>
622
- </div>
623
- </Dismissible>
624
- );
625
- }
626
-
627
- // Using metadata with the hook (same object format)
628
- function CustomNotification({ itemId, category, priority }) {
629
- const { dismissedOn, dismiss, isLoading } = useDismissibleItem(itemId, {
630
- metadata: {
631
- category,
632
- priority,
633
- },
634
- });
635
-
636
- if (dismissedOn) {
637
- return null;
638
- }
639
-
640
- return (
641
- <div className={`notification notification-${category}`}>
642
- <span>Notification content</span>
643
- <button onClick={dismiss} disabled={isLoading}>
644
- Dismiss
645
- </button>
646
- </div>
647
- );
648
- }
649
- ```
650
-
651
580
  ### Restoring Dismissed Items
652
581
 
653
582
  Use the `restore` function to bring back previously dismissed content:
@@ -758,7 +687,6 @@ import type {
758
687
  DismissibleProps,
759
688
  DismissibleProviderProps,
760
689
  JwtToken,
761
- IMetadata,
762
690
  } from '@dismissible/react-client';
763
691
 
764
692
  // Custom provider wrapper
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
- import { IMetadata } from '../hooks/useDismissibleItem';
3
2
  /**
4
3
  * Props for the Dismissible component
5
4
  */
@@ -32,8 +31,6 @@ export interface DismissibleProps {
32
31
  cacheExpiration?: number;
33
32
  /** Ignore errors and display the component anyway (default: false) */
34
33
  ignoreErrors?: boolean;
35
- /** Optional metadata object that will be converted to key:value string pairs */
36
- metadata?: IMetadata;
37
34
  }
38
35
  /**
39
36
  * A wrapper component that can be dismissed and hidden by users
@@ -49,7 +46,6 @@ export interface DismissibleProps {
49
46
  * @param cachePrefix - Cache key prefix
50
47
  * @param cacheExpiration - Cache expiration time in milliseconds
51
48
  * @param ignoreErrors - Ignore errors and display the component anyway
52
- * @param metadata - Optional metadata object that will be converted to key:value string pairs
53
49
  * @returns JSX element or null if dismissed
54
50
  */
55
51
  export declare const Dismissible: React.FC<DismissibleProps>;
@@ -1,59 +1,59 @@
1
1
  var he = Object.defineProperty, me = Object.defineProperties;
2
2
  var ye = Object.getOwnPropertyDescriptors;
3
3
  var M = Object.getOwnPropertySymbols;
4
- var ne = Object.prototype.hasOwnProperty, se = Object.prototype.propertyIsEnumerable;
5
- var re = (e, r, t) => r in e ? he(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, p = (e, r) => {
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
- ne.call(r, t) && re(e, t, r[t]);
7
+ re.call(r, t) && te(e, t, r[t]);
8
8
  if (M)
9
9
  for (var t of M(r))
10
- se.call(r, t) && re(e, t, r[t]);
10
+ ne.call(r, t) && te(e, t, r[t]);
11
11
  return e;
12
- }, R = (e, r) => me(e, ye(r));
13
- var V = (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
- ne.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
16
+ re.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
17
17
  if (e != null && M)
18
18
  for (var n of M(e))
19
- r.indexOf(n) < 0 && se.call(e, n) && (t[n] = e[n]);
19
+ r.indexOf(n) < 0 && ne.call(e, n) && (t[n] = e[n]);
20
20
  return t;
21
21
  };
22
22
  var $ = (e, r, t) => new Promise((n, o) => {
23
23
  var s = (f) => {
24
24
  try {
25
- i(t.next(f));
26
- } catch (y) {
27
- o(y);
25
+ l(t.next(f));
26
+ } catch (d) {
27
+ o(d);
28
28
  }
29
- }, u = (f) => {
29
+ }, i = (f) => {
30
30
  try {
31
- i(t.throw(f));
32
- } catch (y) {
33
- o(y);
31
+ l(t.throw(f));
32
+ } catch (d) {
33
+ o(d);
34
34
  }
35
- }, i = (f) => f.done ? n(f.value) : Promise.resolve(f.value).then(s, u);
36
- i((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 be } from "react/jsx-runtime";
39
- import { createContext as pe, useContext as we, useMemo as Z, useRef as J, useState as W, useCallback as X, useEffect as _ } from "react";
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
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 ve() {
44
+ function Re() {
45
45
  return Math.random().toString(36).slice(2, 11);
46
46
  }
47
- function Re(e) {
48
- let U = p({}, 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
52
  querySerializer: o,
53
53
  bodySerializer: s,
54
- headers: u,
55
- requestInitExt: i = void 0
56
- } = U, f = V(U, [
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
- i = Ee() ? i : void 0, r = ae(r);
66
- const y = [];
67
- function d(l, a) {
65
+ l = Ee() ? l : void 0, r = ie(r);
66
+ const d = [];
67
+ function g(u, a) {
68
68
  return $(this, null, function* () {
69
- var te;
70
- const ee = a || {}, {
71
- baseUrl: v,
72
- fetch: H = n,
73
- Request: x = t,
74
- headers: O,
75
- params: E = {},
76
- parseAs: A = "json",
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
77
  querySerializer: S,
78
- bodySerializer: j = s != null ? s : xe,
78
+ bodySerializer: P = s != null ? s : xe,
79
79
  body: z,
80
- middleware: G = []
81
- } = ee, I = V(ee, [
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 c = r;
94
- v && (c = (te = ae(v)) != null ? te : r);
95
- let b = typeof o == "function" ? o : oe(o);
96
- S && (b = typeof S == "function" ? S : oe(p(p({}, typeof o == "object" ? o : {}), S)));
97
- const h = z === void 0 ? void 0 : j(
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
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
- ie(u, O, E.header)
105
- ), k = ie(
104
+ oe(i, x, v.header)
105
+ ), G = oe(
106
106
  // with no body, we should not to set Content-Type
107
- h === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
108
- h 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
- u,
112
- O,
113
- E.header
114
- ), C = [...y, ...G], K = R(p(p({
111
+ i,
112
+ x,
113
+ v.header
114
+ ), D = [...d, ...k], de = E(b(b({
115
115
  redirect: "follow"
116
- }, f), I), {
117
- body: h,
118
- headers: k
116
+ }, f), c), {
117
+ body: H,
118
+ headers: G
119
119
  });
120
- let F, L, D = new x(
121
- Se(l, { baseUrl: c, params: E, querySerializer: b }),
122
- K
120
+ let F, L, T = new O(
121
+ Se(u, { baseUrl: y, params: v, querySerializer: h }),
122
+ de
123
123
  ), m;
124
- for (const g in I)
125
- g in D || (D[g] = I[g]);
126
- if (C.length) {
127
- F = ve(), L = Object.freeze({
128
- baseUrl: c,
129
- fetch: H,
130
- parseAs: A,
131
- querySerializer: b,
132
- bodySerializer: j
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 g of C)
135
- if (g && typeof g == "object" && typeof g.onRequest == "function") {
136
- const w = yield g.onRequest({
137
- request: D,
138
- schemaPath: l,
139
- params: E,
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
140
  options: L,
141
141
  id: F
142
142
  });
143
- if (w)
144
- if (w instanceof x)
145
- D = w;
146
- else if (w instanceof Response) {
147
- m = w;
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,46 +152,46 @@ function Re(e) {
152
152
  }
153
153
  if (!m) {
154
154
  try {
155
- m = yield H(D, i);
156
- } catch (g) {
157
- let w = g;
158
- if (C.length)
159
- for (let q = C.length - 1; q >= 0; q--) {
160
- const N = C[q];
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
161
  if (N && typeof N == "object" && typeof N.onError == "function") {
162
- const P = yield N.onError({
163
- request: D,
164
- error: w,
165
- schemaPath: l,
166
- params: E,
162
+ const I = yield N.onError({
163
+ request: T,
164
+ error: p,
165
+ schemaPath: u,
166
+ params: v,
167
167
  options: L,
168
168
  id: F
169
169
  });
170
- if (P) {
171
- if (P instanceof Response) {
172
- w = void 0, m = P;
170
+ if (I) {
171
+ if (I instanceof Response) {
172
+ p = void 0, m = I;
173
173
  break;
174
174
  }
175
- if (P instanceof Error) {
176
- w = P;
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 (w)
184
- throw w;
183
+ if (p)
184
+ throw p;
185
185
  }
186
- if (C.length)
187
- for (let g = C.length - 1; g >= 0; g--) {
188
- const w = C[g];
189
- if (w && typeof w == "object" && typeof w.onResponse == "function") {
190
- const q = yield w.onResponse({
191
- request: D,
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: l,
194
- params: E,
193
+ schemaPath: u,
194
+ params: v,
195
195
  options: L,
196
196
  id: F
197
197
  });
@@ -203,68 +203,68 @@ function Re(e) {
203
203
  }
204
204
  }
205
205
  }
206
- if (m.status === 204 || D.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 A === "stream" ? { data: m.body, response: m } : { data: yield m[A](), response: m };
210
- let Q = 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
- Q = JSON.parse(Q);
213
- } catch (g) {
212
+ K = JSON.parse(K);
213
+ } catch (w) {
214
214
  }
215
- return { error: Q, response: m };
215
+ return { error: K, response: m };
216
216
  });
217
217
  }
218
218
  return {
219
- request(l, a, v) {
220
- return d(a, R(p({}, v), { method: l.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(l, a) {
224
- return d(l, R(p({}, a), { 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(l, a) {
228
- return d(l, R(p({}, a), { 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(l, a) {
232
- return d(l, R(p({}, a), { 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(l, a) {
236
- return d(l, R(p({}, a), { 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(l, a) {
240
- return d(l, R(p({}, a), { 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(l, a) {
244
- return d(l, R(p({}, a), { 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(l, a) {
248
- return d(l, R(p({}, a), { 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(l, a) {
252
- return d(l, R(p({}, a), { method: "TRACE" }));
251
+ TRACE(u, a) {
252
+ return g(u, E(b({}, a), { method: "TRACE" }));
253
253
  },
254
254
  /** Register middleware */
255
- use(...l) {
256
- for (const a of l)
255
+ use(...u) {
256
+ for (const a of u)
257
257
  if (a) {
258
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
- y.push(a);
260
+ d.push(a);
261
261
  }
262
262
  },
263
263
  /** Unregister middleware */
264
- eject(...l) {
265
- for (const a of l) {
266
- const v = y.indexOf(a);
267
- v !== -1 && y.splice(v, 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
  };
@@ -278,7 +278,7 @@ function B(e, r, t) {
278
278
  );
279
279
  return `${e}=${(t == null ? void 0 : t.allowReserved) === !0 ? r : encodeURIComponent(r)}`;
280
280
  }
281
- function ue(e, r, t) {
281
+ function le(e, r, t) {
282
282
  if (!r || typeof r != "object")
283
283
  return "";
284
284
  const n = [], o = {
@@ -287,41 +287,43 @@ function ue(e, r, t) {
287
287
  matrix: ";"
288
288
  }[t.style] || "&";
289
289
  if (t.style !== "deepObject" && t.explode === !1) {
290
- for (const i in r)
291
- n.push(i, t.allowReserved === !0 ? r[i] : encodeURIComponent(r[i]));
292
- const u = 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}=${u}`;
295
+ return `${e}=${i}`;
296
296
  case "label":
297
- return `.${u}`;
297
+ return `.${i}`;
298
298
  case "matrix":
299
- return `;${e}=${u}`;
299
+ return `;${e}=${i}`;
300
300
  default:
301
- return u;
301
+ return i;
302
302
  }
303
303
  }
304
- for (const u in r) {
305
- const i = t.style === "deepObject" ? `${e}[${u}]` : u;
306
- n.push(B(i, r[u], 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
308
  const s = n.join(o);
309
309
  return t.style === "label" || t.style === "matrix" ? `${o}${s}` : s;
310
310
  }
311
- function fe(e, r, t) {
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] || ",", u = (t.allowReserved === !0 ? r : r.map((i) => encodeURIComponent(i))).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 u;
318
+ return i;
319
319
  case "label":
320
- return `.${u}`;
320
+ return `.${i}`;
321
321
  case "matrix":
322
- return `;${e}=${u}`;
322
+ return `;${e}=${i}`;
323
+ // case "spaceDelimited":
324
+ // case "pipeDelimited":
323
325
  default:
324
- return `${e}=${u}`;
326
+ return `${e}=${i}`;
325
327
  }
326
328
  }
327
329
  const n = { simple: ",", label: ".", matrix: ";" }[t.style] || "&", o = [];
@@ -329,7 +331,7 @@ function fe(e, r, t) {
329
331
  t.style === "simple" || t.style === "label" ? o.push(t.allowReserved === !0 ? s : encodeURIComponent(s)) : o.push(B(e, s, t));
330
332
  return t.style === "label" || t.style === "matrix" ? `${n}${o.join(n)}` : o.join(n);
331
333
  }
332
- function oe(e) {
334
+ function se(e) {
333
335
  return function(t) {
334
336
  const n = [];
335
337
  if (t && typeof t == "object")
@@ -340,7 +342,7 @@ function oe(e) {
340
342
  if (s.length === 0)
341
343
  continue;
342
344
  n.push(
343
- fe(o, s, R(p({
345
+ ue(o, s, E(b({
344
346
  style: "form",
345
347
  explode: !0
346
348
  }, e == null ? void 0 : e.array), {
@@ -351,7 +353,7 @@ function oe(e) {
351
353
  }
352
354
  if (typeof s == "object") {
353
355
  n.push(
354
- ue(o, s, R(p({
356
+ le(o, s, E(b({
355
357
  style: "deepObject",
356
358
  explode: !0
357
359
  }, e == null ? void 0 : e.object), {
@@ -370,23 +372,23 @@ function Ce(e, r) {
370
372
  var n;
371
373
  let t = e;
372
374
  for (const o of (n = e.match(ge)) != null ? n : []) {
373
- let s = o.substring(1, o.length - 1), u = !1, i = "simple";
374
- if (s.endsWith("*") && (u = !0, s = s.substring(0, s.length - 1)), s.startsWith(".") ? (i = "label", s = s.substring(1)) : s.startsWith(";") && (i = "matrix", s = s.substring(1)), !r || r[s] === void 0 || r[s] === null)
375
+ let s = o.substring(1, o.length - 1), i = !1, l = "simple";
376
+ 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
377
  continue;
376
378
  const f = r[s];
377
379
  if (Array.isArray(f)) {
378
- t = t.replace(o, fe(s, f, { style: i, explode: u }));
380
+ t = t.replace(o, ue(s, f, { style: l, explode: i }));
379
381
  continue;
380
382
  }
381
383
  if (typeof f == "object") {
382
- t = t.replace(o, ue(s, f, { style: i, explode: u }));
384
+ t = t.replace(o, le(s, f, { style: l, explode: i }));
383
385
  continue;
384
386
  }
385
- if (i === "matrix") {
387
+ if (l === "matrix") {
386
388
  t = t.replace(o, `;${B(s, f)}`);
387
389
  continue;
388
390
  }
389
- t = t.replace(o, i === "label" ? `.${encodeURIComponent(f)}` : encodeURIComponent(f));
391
+ t = t.replace(o, l === "label" ? `.${encodeURIComponent(f)}` : encodeURIComponent(f));
390
392
  }
391
393
  return t;
392
394
  }
@@ -401,7 +403,7 @@ function Se(e, r) {
401
403
  let n = r.querySerializer((s = r.params.query) != null ? s : {});
402
404
  return n.startsWith("?") && (n = n.substring(1)), n && (t += `?${n}`), t;
403
405
  }
404
- function ie(...e) {
406
+ function oe(...e) {
405
407
  const r = new Headers();
406
408
  for (const t of e) {
407
409
  if (!t || typeof t != "object")
@@ -411,25 +413,25 @@ function ie(...e) {
411
413
  if (s === null)
412
414
  r.delete(o);
413
415
  else if (Array.isArray(s))
414
- for (const u of s)
415
- r.append(o, u);
416
+ for (const i of s)
417
+ r.append(o, i);
416
418
  else s !== void 0 && r.set(o, s);
417
419
  }
418
420
  return r;
419
421
  }
420
- function ae(e) {
422
+ function ie(e) {
421
423
  return e.endsWith("/") ? e.substring(0, e.length - 1) : e;
422
424
  }
423
- const ce = (e, r, t) => {
425
+ const ae = (e, r, t) => {
424
426
  try {
425
427
  const n = `${r}_${e}`, o = localStorage.getItem(n);
426
428
  if (!o) return null;
427
- const { data: s, timestamp: u } = JSON.parse(o);
428
- return t && Date.now() - u > t ? (localStorage.removeItem(n), null) : s;
429
+ const { data: s, timestamp: i } = JSON.parse(o);
430
+ return t && Date.now() - i > t ? (localStorage.removeItem(n), null) : s;
429
431
  } catch (n) {
430
432
  return null;
431
433
  }
432
- }, Y = (e, r, t) => {
434
+ }, X = (e, r, t) => {
433
435
  try {
434
436
  const n = `${t}_${e}`, o = {
435
437
  data: r,
@@ -439,190 +441,184 @@ const ce = (e, r, t) => {
439
441
  } catch (n) {
440
442
  console.warn("Failed to cache dismissible item:", n);
441
443
  }
442
- }, le = (e, r) => {
444
+ }, ce = (e, r) => {
443
445
  try {
444
446
  const t = `${r}_${e}`;
445
447
  localStorage.removeItem(t);
446
448
  } catch (t) {
447
449
  console.warn("Failed to remove cached dismissible item:", t);
448
450
  }
449
- }, de = pe(
451
+ }, fe = pe(
450
452
  null
451
453
  ), $e = () => {
452
- const e = we(de);
454
+ const e = we(fe);
453
455
  if (!e)
454
456
  throw new Error(
455
457
  "useDismissibleContext must be used within a DismissibleProvider"
456
458
  );
457
459
  return e;
458
- }, Ae = (e) => {
459
- if (e)
460
- return Object.entries(e).map(([r, t]) => `${r}:${t}`);
461
- }, je = "dismissible", De = (e, r = {}) => {
462
- var I;
460
+ }, Ae = "dismissible", je = (e, r = {}) => {
461
+ var k;
463
462
  const {
464
463
  initialData: t,
465
464
  enableCache: n = !0,
466
- cachePrefix: o = je,
467
- cacheExpiration: s,
468
- metadata: u
469
- } = r, i = $e(), { userId: f } = i, y = Z(() => Re({
465
+ cachePrefix: o = Ae,
466
+ cacheExpiration: s
467
+ } = r, i = $e(), { userId: l } = i, f = Y(() => ve({
470
468
  baseUrl: i.baseUrl,
471
469
  headers: {}
472
- }), [i.baseUrl]), d = Z(() => `${f}-${e}`, [f, e]), U = J({
470
+ }), [i.baseUrl]), d = Y(() => `${l}-${e}`, [l, e]), g = J({
473
471
  enableCache: n,
474
472
  cachePrefix: o,
475
473
  cacheExpiration: s
476
- }), l = J(e), a = J(d), v = J(null), [H, x] = W(!1), [O, E] = W(null), [A, S] = W(() => {
474
+ }), A = J(e), u = J(d), a = J(null), [R, C] = W(!1), [O, x] = W(null), [v, j] = W(() => {
477
475
  if (t) return t;
478
476
  if (n) {
479
- const c = ce(
477
+ const c = ae(
480
478
  d,
481
479
  o,
482
480
  s
483
481
  );
484
482
  if (c) return c;
485
483
  }
486
- }), j = X(() => $(void 0, null, function* () {
487
- var b;
484
+ }), S = V(() => $(null, null, function* () {
485
+ var y;
488
486
  if (n) {
489
- const h = ce(
487
+ const h = ae(
490
488
  d,
491
489
  o,
492
490
  s
493
491
  );
494
492
  if (h != null && h.dismissedAt) {
495
- S(h), x(!1);
493
+ j(h), C(!1);
496
494
  return;
497
495
  }
498
496
  }
499
- (b = v.current) == null || b.abort();
497
+ (y = a.current) == null || y.abort();
500
498
  const c = new AbortController();
501
- v.current = c, x(!0), E(null);
499
+ a.current = c, C(!0), x(null);
502
500
  try {
503
- const h = yield i.getAuthHeaders(), k = Ae(u), { data: C, error: K } = yield y.GET(
501
+ const h = yield i.getAuthHeaders(), { data: H, error: G } = yield f.GET(
504
502
  "/v1/users/{userId}/items/{itemId}",
505
503
  {
506
504
  params: {
507
505
  path: {
508
- userId: f,
506
+ userId: l,
509
507
  itemId: e
510
- },
511
- query: k ? { metadata: k } : void 0
508
+ }
512
509
  },
513
510
  headers: h,
514
511
  signal: c.signal
515
512
  }
516
513
  );
517
- if (K || !C)
514
+ if (G || !H)
518
515
  throw new Error("Failed to fetch dismissible item");
519
- S(C.data), n && Y(d, C.data, o);
516
+ j(H.data), n && X(d, H.data, o);
520
517
  } catch (h) {
521
518
  if (h instanceof Error && h.name === "AbortError")
522
519
  return;
523
- E(
520
+ x(
524
521
  h instanceof Error ? h : new Error("Unknown error occurred")
525
522
  );
526
523
  } finally {
527
- x(!1);
524
+ C(!1);
528
525
  }
529
526
  }), [
530
527
  e,
531
- f,
528
+ l,
532
529
  d,
533
530
  n,
534
531
  o,
535
532
  s,
536
- u,
537
- y,
533
+ f,
538
534
  i
539
535
  ]);
540
536
  _(() => {
541
- const c = l.current !== e, b = a.current !== d;
542
- c || b ? (l.current = e, a.current = d, j()) : t || j();
543
- }, [e, d, t, j]), _(() => () => {
537
+ const c = A.current !== e, y = u.current !== d;
538
+ c || y ? (A.current = e, u.current = d, S()) : t || S();
539
+ }, [e, d, t, S]), _(() => () => {
544
540
  var c;
545
- (c = v.current) == null || c.abort();
541
+ (c = a.current) == null || c.abort();
546
542
  }, []), _(() => {
547
- const c = U.current;
548
- (c.enableCache !== n || c.cachePrefix !== o || c.cacheExpiration !== s) && (c.cachePrefix !== o && le(d, c.cachePrefix), !n && c.enableCache && le(d, c.cachePrefix), U.current = {
543
+ const c = g.current;
544
+ (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 = {
549
545
  enableCache: n,
550
546
  cachePrefix: o,
551
547
  cacheExpiration: s
552
- }, j());
553
- }, [n, o, s, d, j]);
554
- const z = X(() => $(void 0, null, function* () {
555
- E(null);
548
+ }, S());
549
+ }, [n, o, s, d, S]);
550
+ const P = V(() => $(null, null, function* () {
551
+ x(null);
556
552
  try {
557
- const c = yield i.getAuthHeaders(), { data: b, error: h } = yield y.DELETE(
553
+ const c = yield i.getAuthHeaders(), { data: y, error: h } = yield f.DELETE(
558
554
  "/v1/users/{userId}/items/{itemId}",
559
555
  {
560
556
  params: {
561
557
  path: {
562
- userId: f,
558
+ userId: l,
563
559
  itemId: e
564
560
  }
565
561
  },
566
562
  headers: c
567
563
  }
568
564
  );
569
- if (h || !b)
565
+ if (h || !y)
570
566
  throw new Error("Failed to dismiss item");
571
- S(b.data), n && Y(d, b.data, o);
567
+ j(y.data), n && X(d, y.data, o);
572
568
  } catch (c) {
573
- throw E(
569
+ throw x(
574
570
  c instanceof Error ? c : new Error("Failed to dismiss item")
575
571
  ), c;
576
572
  }
577
573
  }), [
578
574
  e,
579
- f,
575
+ l,
580
576
  d,
581
577
  n,
582
578
  o,
583
- y,
579
+ f,
584
580
  i
585
- ]), G = X(() => $(void 0, null, function* () {
586
- E(null);
581
+ ]), z = V(() => $(null, null, function* () {
582
+ x(null);
587
583
  try {
588
- const c = yield i.getAuthHeaders(), { data: b, error: h } = yield y.POST(
584
+ const c = yield i.getAuthHeaders(), { data: y, error: h } = yield f.POST(
589
585
  "/v1/users/{userId}/items/{itemId}",
590
586
  {
591
587
  params: {
592
588
  path: {
593
- userId: f,
589
+ userId: l,
594
590
  itemId: e
595
591
  }
596
592
  },
597
593
  headers: c
598
594
  }
599
595
  );
600
- if (h || !b)
596
+ if (h || !y)
601
597
  throw new Error("Failed to restore item");
602
- S(b.data), n && Y(d, b.data, o);
598
+ j(y.data), n && X(d, y.data, o);
603
599
  } catch (c) {
604
- throw E(
600
+ throw x(
605
601
  c instanceof Error ? c : new Error("Failed to restore item")
606
602
  ), c;
607
603
  }
608
604
  }), [
609
605
  e,
610
- f,
606
+ l,
611
607
  d,
612
608
  n,
613
609
  o,
614
- y,
610
+ f,
615
611
  i
616
612
  ]);
617
613
  return {
618
- dismissedOn: (I = A == null ? void 0 : A.dismissedAt) != null ? I : null,
619
- dismiss: z,
620
- restore: G,
621
- isLoading: H,
614
+ dismissedOn: (k = v == null ? void 0 : v.dismissedAt) != null ? k : null,
615
+ dismiss: P,
616
+ restore: z,
617
+ isLoading: R,
622
618
  error: O,
623
- item: A
619
+ item: v
624
620
  };
625
- }, Te = () => /* @__PURE__ */ T("div", { className: "dismissible-loading", "aria-live": "polite", children: "Loading..." }), Ue = () => /* @__PURE__ */ T("div", { className: "dismissible-error", role: "alert", children: "Unable to load content. Please try again later." }), qe = ({ onDismiss: e, ariaLabel: r }) => /* @__PURE__ */ T(
621
+ }, 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(
626
622
  "button",
627
623
  {
628
624
  className: "dismissible-button",
@@ -631,42 +627,40 @@ const ce = (e, r, t) => {
631
627
  type: "button",
632
628
  children: "×"
633
629
  }
634
- ), Fe = ({
630
+ ), ke = ({
635
631
  itemId: e,
636
632
  children: r,
637
633
  onDismiss: t,
638
- LoadingComponent: n = Te,
639
- ErrorComponent: o = Ue,
640
- DismissButtonComponent: s = qe,
641
- enableCache: u,
642
- cachePrefix: i,
634
+ LoadingComponent: n = De,
635
+ ErrorComponent: o = Te,
636
+ DismissButtonComponent: s = Ue,
637
+ enableCache: i,
638
+ cachePrefix: l,
643
639
  cacheExpiration: f,
644
- ignoreErrors: y = !1,
645
- metadata: d
640
+ ignoreErrors: d = !1
646
641
  }) => {
647
- const { dismissedOn: U, isLoading: l, error: a, dismiss: v } = De(
642
+ const { dismissedOn: g, isLoading: A, error: u, dismiss: a } = je(
648
643
  e,
649
644
  {
650
- enableCache: u,
651
- cachePrefix: i,
652
- cacheExpiration: f,
653
- metadata: d
645
+ enableCache: i,
646
+ cachePrefix: l,
647
+ cacheExpiration: f
654
648
  }
655
- ), [H, x] = W(!1);
649
+ ), [R, C] = W(!1);
656
650
  _(() => {
657
- x(!1);
651
+ C(!1);
658
652
  }, [e]);
659
- const O = () => $(void 0, null, function* () {
660
- x(!0);
653
+ const O = () => $(null, null, function* () {
654
+ C(!0);
661
655
  try {
662
- yield v(), t == null || t();
663
- } catch (E) {
664
- x(!1);
656
+ yield a(), t == null || t();
657
+ } catch (x) {
658
+ C(!1);
665
659
  }
666
660
  });
667
- return l && n ? /* @__PURE__ */ T(n, { itemId: e }) : l && !n ? null : a && o && !y ? /* @__PURE__ */ T(o, { itemId: e, error: a }) : U || H ? null : /* @__PURE__ */ be("div", { className: "dismissible-container", children: [
668
- /* @__PURE__ */ T("div", { className: "dismissible-content", children: r }),
669
- s ? /* @__PURE__ */ T(
661
+ 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: [
662
+ /* @__PURE__ */ U("div", { className: "dismissible-content", children: r }),
663
+ s ? /* @__PURE__ */ U(
670
664
  s,
671
665
  {
672
666
  onDismiss: O,
@@ -674,7 +668,7 @@ const ce = (e, r, t) => {
674
668
  }
675
669
  ) : null
676
670
  ] });
677
- }, He = (e) => $(void 0, null, function* () {
671
+ }, He = (e) => $(null, null, function* () {
678
672
  if (typeof e == "function")
679
673
  try {
680
674
  const r = e();
@@ -684,45 +678,45 @@ const ce = (e, r, t) => {
684
678
  return;
685
679
  }
686
680
  return e;
687
- }), Oe = (e) => $(void 0, null, function* () {
681
+ }), qe = (e) => $(null, null, function* () {
688
682
  const r = yield He(e);
689
683
  return r ? { Authorization: `Bearer ${r}` } : {};
690
- }), Ie = (e) => {
684
+ }), Oe = (e) => {
691
685
  try {
692
686
  const r = new URL(e), t = r.hostname === "localhost" || r.hostname === "127.0.0.1" || r.hostname === "[::1]", n = r.protocol === "https:";
693
687
  return { isSecure: n || t, isLocalhost: t, isHttps: n };
694
688
  } catch (r) {
695
689
  return { isSecure: !1, isLocalhost: !1, isHttps: !1 };
696
690
  }
697
- }, Le = ({
691
+ }, Fe = ({
698
692
  userId: e,
699
693
  jwt: r,
700
694
  baseUrl: t,
701
695
  children: n
702
696
  }) => {
703
- const { isSecure: o } = Ie(t);
697
+ const { isSecure: o } = Oe(t);
704
698
  o || console.warn(
705
699
  `[dismissible] Insecure baseUrl "${t}". Use https:// in production (or localhost for development). JWT tokens may be exposed over insecure connections.`
706
700
  );
707
- const s = Z(
701
+ const s = Y(
708
702
  () => ({
709
703
  userId: e,
710
704
  jwt: r,
711
705
  baseUrl: t,
712
- getAuthHeaders: () => $(void 0, null, function* () {
713
- return yield Oe(r);
706
+ getAuthHeaders: () => $(null, null, function* () {
707
+ return yield qe(r);
714
708
  })
715
709
  }),
716
710
  [e, r, t]
717
711
  );
718
- return /* @__PURE__ */ T(de.Provider, { value: s, children: n });
712
+ return /* @__PURE__ */ U(fe.Provider, { value: s, children: n });
719
713
  };
720
714
  export {
721
- Fe as Dismissible,
722
- de as DismissibleContext,
723
- Le as DismissibleProvider,
724
- Oe as getAuthHeaders,
715
+ ke as Dismissible,
716
+ fe as DismissibleContext,
717
+ Fe as DismissibleProvider,
718
+ qe as getAuthHeaders,
725
719
  He as resolveJwt,
726
720
  $e as useDismissibleContext,
727
- De as useDismissibleItem
721
+ je as useDismissibleItem
728
722
  };
@@ -1 +1 @@
1
- (function(a,f){typeof exports=="object"&&typeof module!="undefined"?f(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],f):(a=typeof globalThis!="undefined"?globalThis:a||self,f(a.DismissibleClient={},a.React.jsxRuntime,a.React))})(this,function(a,f,o){"use strict";var $e=Object.defineProperty,Te=Object.defineProperties;var Ue=Object.getOwnPropertyDescriptors;var Q=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable;var ye=(a,f,o)=>f in a?$e(a,f,{enumerable:!0,configurable:!0,writable:!0,value:o}):a[f]=o,g=(a,f)=>{for(var o in f||(f={}))be.call(f,o)&&ye(a,o,f[o]);if(Q)for(var o of Q(f))we.call(f,o)&&ye(a,o,f[o]);return a},x=(a,f)=>Te(a,Ue(f));var se=(a,f)=>{var o={};for(var R in a)be.call(a,R)&&f.indexOf(R)<0&&(o[R]=a[R]);if(a!=null&&Q)for(var R of Q(a))f.indexOf(R)<0&&we.call(a,R)&&(o[R]=a[R]);return o};var U=(a,f,o)=>new Promise((R,J)=>{var V=D=>{try{q(o.next(D))}catch(z){J(z)}},X=D=>{try{q(o.throw(D))}catch(z){J(z)}},q=D=>D.done?R(D.value):Promise.resolve(D.value).then(V,X);q((o=o.apply(a,f)).next())});const R=/\{[^{}]+\}/g,J=()=>{var e,r;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};function V(){return Math.random().toString(36).slice(2,11)}function X(e){let I=g({},e),{baseUrl:r="",Request:t=globalThis.Request,fetch:n=globalThis.fetch,querySerializer:i,bodySerializer:s,headers:h,requestInitExt:d=void 0}=I,y=se(I,["baseUrl","Request","fetch","querySerializer","bodySerializer","headers","requestInitExt"]);d=J()?d:void 0,r=oe(r);const S=[];function m(u,c){return U(this,null,function*(){var me;const he=c||{},{baseUrl:j,fetch:F=n,Request:$=t,headers:L,params:C={},parseAs:H="json",querySerializer:T,bodySerializer:O=s!=null?s:ge,body:W,middleware:ee=[]}=he,N=se(he,["baseUrl","fetch","Request","headers","params","parseAs","querySerializer","bodySerializer","body","middleware"]);let l=r;j&&(l=(me=oe(j))!=null?me:r);let p=typeof i=="function"?i:ne(i);T&&(p=typeof T=="function"?T:ne(g(g({},typeof i=="object"?i:{}),T)));const b=W===void 0?void 0:O(W,ie(h,L,C.header)),_=ie(b===void 0||b instanceof FormData?{}:{"Content-Type":"application/json"},h,L,C.header),A=[...S,...ee],te=x(g(g({redirect:"follow"},y),N),{body:b,headers:_});let B,G,P=new $(Ee(u,{baseUrl:l,params:C,querySerializer:p}),te),w;for(const v in N)v in P||(P[v]=N[v]);if(A.length){B=V(),G=Object.freeze({baseUrl:l,fetch:F,parseAs:H,querySerializer:p,bodySerializer:O});for(const v of A)if(v&&typeof v=="object"&&typeof v.onRequest=="function"){const E=yield v.onRequest({request:P,schemaPath:u,params:C,options:G,id:B});if(E)if(E instanceof $)P=E;else if(E instanceof Response){w=E;break}else throw new Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!w){try{w=yield F(P,d)}catch(v){let E=v;if(A.length)for(let k=A.length-1;k>=0;k--){const K=A[k];if(K&&typeof K=="object"&&typeof K.onError=="function"){const M=yield K.onError({request:P,error:E,schemaPath:u,params:C,options:G,id:B});if(M){if(M instanceof Response){E=void 0,w=M;break}if(M instanceof Error){E=M;continue}throw new Error("onError: must return new Response() or instance of Error")}}}if(E)throw E}if(A.length)for(let v=A.length-1;v>=0;v--){const E=A[v];if(E&&typeof E=="object"&&typeof E.onResponse=="function"){const k=yield E.onResponse({request:P,response:w,schemaPath:u,params:C,options:G,id:B});if(k){if(!(k instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");w=k}}}}if(w.status===204||P.method==="HEAD"||w.headers.get("Content-Length")==="0")return w.ok?{data:void 0,response:w}:{error:void 0,response:w};if(w.ok)return H==="stream"?{data:w.body,response:w}:{data:yield w[H](),response:w};let re=yield w.text();try{re=JSON.parse(re)}catch(v){}return{error:re,response:w}})}return{request(u,c,j){return m(c,x(g({},j),{method:u.toUpperCase()}))},GET(u,c){return m(u,x(g({},c),{method:"GET"}))},PUT(u,c){return m(u,x(g({},c),{method:"PUT"}))},POST(u,c){return m(u,x(g({},c),{method:"POST"}))},DELETE(u,c){return m(u,x(g({},c),{method:"DELETE"}))},OPTIONS(u,c){return m(u,x(g({},c),{method:"OPTIONS"}))},HEAD(u,c){return m(u,x(g({},c),{method:"HEAD"}))},PATCH(u,c){return m(u,x(g({},c),{method:"PATCH"}))},TRACE(u,c){return m(u,x(g({},c),{method:"TRACE"}))},use(...u){for(const c of u)if(c){if(typeof c!="object"||!("onRequest"in c||"onResponse"in c||"onError"in c))throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");S.push(c)}},eject(...u){for(const c of u){const j=S.indexOf(c);j!==-1&&S.splice(j,1)}}}}function q(e,r,t){if(r==null)return"";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${(t==null?void 0:t.allowReserved)===!0?r:encodeURIComponent(r)}`}function D(e,r,t){if(!r||typeof r!="object")return"";const n=[],i={simple:",",label:".",matrix:";"}[t.style]||"&";if(t.style!=="deepObject"&&t.explode===!1){for(const d in r)n.push(d,t.allowReserved===!0?r[d]:encodeURIComponent(r[d]));const h=n.join(",");switch(t.style){case"form":return`${e}=${h}`;case"label":return`.${h}`;case"matrix":return`;${e}=${h}`;default:return h}}for(const h in r){const d=t.style==="deepObject"?`${e}[${h}]`:h;n.push(q(d,r[h],t))}const s=n.join(i);return t.style==="label"||t.style==="matrix"?`${i}${s}`:s}function z(e,r,t){if(!Array.isArray(r))return"";if(t.explode===!1){const s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",h=(t.allowReserved===!0?r:r.map(d=>encodeURIComponent(d))).join(s);switch(t.style){case"simple":return h;case"label":return`.${h}`;case"matrix":return`;${e}=${h}`;default:return`${e}=${h}`}}const n={simple:",",label:".",matrix:";"}[t.style]||"&",i=[];for(const s of r)t.style==="simple"||t.style==="label"?i.push(t.allowReserved===!0?s:encodeURIComponent(s)):i.push(q(e,s,t));return t.style==="label"||t.style==="matrix"?`${n}${i.join(n)}`:i.join(n)}function ne(e){return function(t){const n=[];if(t&&typeof t=="object")for(const i in t){const s=t[i];if(s!=null){if(Array.isArray(s)){if(s.length===0)continue;n.push(z(i,s,x(g({style:"form",explode:!0},e==null?void 0:e.array),{allowReserved:(e==null?void 0:e.allowReserved)||!1})));continue}if(typeof s=="object"){n.push(D(i,s,x(g({style:"deepObject",explode:!0},e==null?void 0:e.object),{allowReserved:(e==null?void 0:e.allowReserved)||!1})));continue}n.push(q(i,s,e))}}return n.join("&")}}function pe(e,r){var n;let t=e;for(const i of(n=e.match(R))!=null?n:[]){let s=i.substring(1,i.length-1),h=!1,d="simple";if(s.endsWith("*")&&(h=!0,s=s.substring(0,s.length-1)),s.startsWith(".")?(d="label",s=s.substring(1)):s.startsWith(";")&&(d="matrix",s=s.substring(1)),!r||r[s]===void 0||r[s]===null)continue;const y=r[s];if(Array.isArray(y)){t=t.replace(i,z(s,y,{style:d,explode:h}));continue}if(typeof y=="object"){t=t.replace(i,D(s,y,{style:d,explode:h}));continue}if(d==="matrix"){t=t.replace(i,`;${q(s,y)}`);continue}t=t.replace(i,d==="label"?`.${encodeURIComponent(y)}`:encodeURIComponent(y))}return t}function ge(e,r){var t,n;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)}function Ee(e,r){var i,s;let t=`${r.baseUrl}${e}`;(i=r.params)!=null&&i.path&&(t=pe(t,r.params.path));let n=r.querySerializer((s=r.params.query)!=null?s:{});return n.startsWith("?")&&(n=n.substring(1)),n&&(t+=`?${n}`),t}function ie(...e){const r=new Headers;for(const t of e){if(!t||typeof t!="object")continue;const n=t instanceof Headers?t.entries():Object.entries(t);for(const[i,s]of n)if(s===null)r.delete(i);else if(Array.isArray(s))for(const h of s)r.append(i,h);else s!==void 0&&r.set(i,s)}return r}function oe(e){return e.endsWith("/")?e.substring(0,e.length-1):e}const ae=(e,r,t)=>{try{const n=`${r}_${e}`,i=localStorage.getItem(n);if(!i)return null;const{data:s,timestamp:h}=JSON.parse(i);return t&&Date.now()-h>t?(localStorage.removeItem(n),null):s}catch(n){return null}},Y=(e,r,t)=>{try{const n=`${t}_${e}`,i={data:r,timestamp:Date.now()};localStorage.setItem(n,JSON.stringify(i))}catch(n){console.warn("Failed to cache dismissible item:",n)}},ce=(e,r)=>{try{const t=`${r}_${e}`;localStorage.removeItem(t)}catch(t){console.warn("Failed to remove cached dismissible item:",t)}},Z=o.createContext(null),le=()=>{const e=o.useContext(Z);if(!e)throw new Error("useDismissibleContext must be used within a DismissibleProvider");return e},ve=e=>{if(e)return Object.entries(e).map(([r,t])=>`${r}:${t}`)},Ce="dismissible",ue=(e,r={})=>{var N;const{initialData:t,enableCache:n=!0,cachePrefix:i=Ce,cacheExpiration:s,metadata:h}=r,d=le(),{userId:y}=d,S=o.useMemo(()=>X({baseUrl:d.baseUrl,headers:{}}),[d.baseUrl]),m=o.useMemo(()=>`${y}-${e}`,[y,e]),I=o.useRef({enableCache:n,cachePrefix:i,cacheExpiration:s}),u=o.useRef(e),c=o.useRef(m),j=o.useRef(null),[F,$]=o.useState(!1),[L,C]=o.useState(null),[H,T]=o.useState(()=>{if(t)return t;if(n){const l=ae(m,i,s);if(l)return l}}),O=o.useCallback(()=>U(this,null,function*(){var p;if(n){const b=ae(m,i,s);if(b!=null&&b.dismissedAt){T(b),$(!1);return}}(p=j.current)==null||p.abort();const l=new AbortController;j.current=l,$(!0),C(null);try{const b=yield d.getAuthHeaders(),_=ve(h),{data:A,error:te}=yield S.GET("/v1/users/{userId}/items/{itemId}",{params:{path:{userId:y,itemId:e},query:_?{metadata:_}:void 0},headers:b,signal:l.signal});if(te||!A)throw new Error("Failed to fetch dismissible item");T(A.data),n&&Y(m,A.data,i)}catch(b){if(b instanceof Error&&b.name==="AbortError")return;C(b instanceof Error?b:new Error("Unknown error occurred"))}finally{$(!1)}}),[e,y,m,n,i,s,h,S,d]);o.useEffect(()=>{const l=u.current!==e,p=c.current!==m;l||p?(u.current=e,c.current=m,O()):t||O()},[e,m,t,O]),o.useEffect(()=>()=>{var l;(l=j.current)==null||l.abort()},[]),o.useEffect(()=>{const l=I.current;(l.enableCache!==n||l.cachePrefix!==i||l.cacheExpiration!==s)&&(l.cachePrefix!==i&&ce(m,l.cachePrefix),!n&&l.enableCache&&ce(m,l.cachePrefix),I.current={enableCache:n,cachePrefix:i,cacheExpiration:s},O())},[n,i,s,m,O]);const W=o.useCallback(()=>U(this,null,function*(){C(null);try{const l=yield d.getAuthHeaders(),{data:p,error:b}=yield S.DELETE("/v1/users/{userId}/items/{itemId}",{params:{path:{userId:y,itemId:e}},headers:l});if(b||!p)throw new Error("Failed to dismiss item");T(p.data),n&&Y(m,p.data,i)}catch(l){throw C(l instanceof Error?l:new Error("Failed to dismiss item")),l}}),[e,y,m,n,i,S,d]),ee=o.useCallback(()=>U(this,null,function*(){C(null);try{const l=yield d.getAuthHeaders(),{data:p,error:b}=yield S.POST("/v1/users/{userId}/items/{itemId}",{params:{path:{userId:y,itemId:e}},headers:l});if(b||!p)throw new Error("Failed to restore item");T(p.data),n&&Y(m,p.data,i)}catch(l){throw C(l instanceof Error?l:new Error("Failed to restore item")),l}}),[e,y,m,n,i,S,d]);return{dismissedOn:(N=H==null?void 0:H.dismissedAt)!=null?N:null,dismiss:W,restore:ee,isLoading:F,error:L,item:H}},Re=()=>f.jsx("div",{className:"dismissible-loading","aria-live":"polite",children:"Loading..."}),Se=()=>f.jsx("div",{className:"dismissible-error",role:"alert",children:"Unable to load content. Please try again later."}),je=({onDismiss:e,ariaLabel:r})=>f.jsx("button",{className:"dismissible-button",onClick:e,"aria-label":r,type:"button",children:"×"}),xe=({itemId:e,children:r,onDismiss:t,LoadingComponent:n=Re,ErrorComponent:i=Se,DismissButtonComponent:s=je,enableCache:h,cachePrefix:d,cacheExpiration:y,ignoreErrors:S=!1,metadata:m})=>{const{dismissedOn:I,isLoading:u,error:c,dismiss:j}=ue(e,{enableCache:h,cachePrefix:d,cacheExpiration:y,metadata:m}),[F,$]=o.useState(!1);o.useEffect(()=>{$(!1)},[e]);const L=()=>U(this,null,function*(){$(!0);try{yield j(),t==null||t()}catch(C){$(!1)}});return u&&n?f.jsx(n,{itemId:e}):u&&!n?null:c&&i&&!S?f.jsx(i,{itemId:e,error:c}):I||F?null:f.jsxs("div",{className:"dismissible-container",children:[f.jsx("div",{className:"dismissible-content",children:r}),s?f.jsx(s,{onDismiss:L,ariaLabel:`Dismiss ${e}`}):null]})},fe=e=>U(this,null,function*(){if(typeof e=="function")try{const r=e();return yield Promise.resolve(r)}catch(r){console.warn("Failed to resolve JWT from function:",r);return}return e}),de=e=>U(this,null,function*(){const r=yield fe(e);return r?{Authorization:`Bearer ${r}`}:{}}),Ae=e=>{try{const r=new URL(e),t=r.hostname==="localhost"||r.hostname==="127.0.0.1"||r.hostname==="[::1]",n=r.protocol==="https:";return{isSecure:n||t,isLocalhost:t,isHttps:n}}catch(r){return{isSecure:!1,isLocalhost:!1,isHttps:!1}}},De=({userId:e,jwt:r,baseUrl:t,children:n})=>{const{isSecure:i}=Ae(t);i||console.warn(`[dismissible] Insecure baseUrl "${t}". Use https:// in production (or localhost for development). JWT tokens may be exposed over insecure connections.`);const s=o.useMemo(()=>({userId:e,jwt:r,baseUrl:t,getAuthHeaders:()=>U(this,null,function*(){return yield de(r)})}),[e,r,t]);return f.jsx(Z.Provider,{value:s,children:n})};a.Dismissible=xe,a.DismissibleContext=Z,a.DismissibleProvider=De,a.getAuthHeaders=de,a.resolveJwt=fe,a.useDismissibleContext=le,a.useDismissibleItem=ue,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],d):(c=typeof globalThis!="undefined"?globalThis:c||self,d(c.DismissibleClient={},c.React.jsxRuntime,c.React))})(this,(function(c,d,o){"use strict";var Ae=Object.defineProperty,$e=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var Q=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var me=(c,d,o)=>d in c?Ae(c,d,{enumerable:!0,configurable:!0,writable:!0,value:o}):c[d]=o,g=(c,d)=>{for(var o in d||(d={}))ye.call(d,o)&&me(c,o,d[o]);if(Q)for(var o of Q(d))be.call(d,o)&&me(c,o,d[o]);return c},S=(c,d)=>$e(c,Te(d));var re=(c,d)=>{var o={};for(var R in c)ye.call(c,R)&&d.indexOf(R)<0&&(o[R]=c[R]);if(c!=null&&Q)for(var R of Q(c))d.indexOf(R)<0&&be.call(c,R)&&(o[R]=c[R]);return o};var U=(c,d,o)=>new Promise((R,M)=>{var V=j=>{try{q(o.next(j))}catch(F){M(F)}},X=j=>{try{q(o.throw(j))}catch(F){M(F)}},q=j=>j.done?R(j.value):Promise.resolve(j.value).then(V,X);q((o=o.apply(c,d)).next())});const R=/\{[^{}]+\}/g,M=()=>{var e,r;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};function V(){return Math.random().toString(36).slice(2,11)}function X(e){let H=g({},e),{baseUrl:r="",Request:t=globalThis.Request,fetch:n=globalThis.fetch,querySerializer:i,bodySerializer:s,headers:a,requestInitExt:h=void 0}=H,b=re(H,["baseUrl","Request","fetch","querySerializer","bodySerializer","headers","requestInitExt"]);h=M()?h:void 0,r=ie(r);const m=[];function C(f,l){return U(this,null,function*(){var he;const de=l||{},{baseUrl:x,fetch:A=n,Request:L=t,headers:$,params:D={},parseAs:O="json",querySerializer:T,bodySerializer:J=s!=null?s:pe,body:W,middleware:_=[]}=de,u=re(de,["baseUrl","fetch","Request","headers","params","parseAs","querySerializer","bodySerializer","body","middleware"]);let p=r;x&&(p=(he=ie(x))!=null?he:r);let y=typeof i=="function"?i:se(i);T&&(y=typeof T=="function"?T:se(g(g({},typeof i=="object"?i:{}),T)));const k=W===void 0?void 0:J(W,ne(a,$,D.header)),ee=ne(k===void 0||k instanceof FormData?{}:{"Content-Type":"application/json"},a,$,D.header),P=[...m,..._],je=S(g(g({redirect:"follow"},b),u),{body:k,headers:ee});let B,G,I=new L(ge(f,{baseUrl:p,params:D,querySerializer:y}),je),w;for(const v in u)v in I||(I[v]=u[v]);if(P.length){B=V(),G=Object.freeze({baseUrl:p,fetch:A,parseAs:O,querySerializer:y,bodySerializer:J});for(const v of P)if(v&&typeof v=="object"&&typeof v.onRequest=="function"){const E=yield v.onRequest({request:I,schemaPath:f,params:D,options:G,id:B});if(E)if(E instanceof L)I=E;else if(E instanceof Response){w=E;break}else throw new Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!w){try{w=yield A(I,h)}catch(v){let E=v;if(P.length)for(let z=P.length-1;z>=0;z--){const K=P[z];if(K&&typeof K=="object"&&typeof K.onError=="function"){const N=yield K.onError({request:I,error:E,schemaPath:f,params:D,options:G,id:B});if(N){if(N instanceof Response){E=void 0,w=N;break}if(N instanceof Error){E=N;continue}throw new Error("onError: must return new Response() or instance of Error")}}}if(E)throw E}if(P.length)for(let v=P.length-1;v>=0;v--){const E=P[v];if(E&&typeof E=="object"&&typeof E.onResponse=="function"){const z=yield E.onResponse({request:I,response:w,schemaPath:f,params:D,options:G,id:B});if(z){if(!(z instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");w=z}}}}if(w.status===204||I.method==="HEAD"||w.headers.get("Content-Length")==="0")return w.ok?{data:void 0,response:w}:{error:void 0,response:w};if(w.ok)return O==="stream"?{data:w.body,response:w}:{data:yield w[O](),response:w};let te=yield w.text();try{te=JSON.parse(te)}catch(v){}return{error:te,response:w}})}return{request(f,l,x){return C(l,S(g({},x),{method:f.toUpperCase()}))},GET(f,l){return C(f,S(g({},l),{method:"GET"}))},PUT(f,l){return C(f,S(g({},l),{method:"PUT"}))},POST(f,l){return C(f,S(g({},l),{method:"POST"}))},DELETE(f,l){return C(f,S(g({},l),{method:"DELETE"}))},OPTIONS(f,l){return C(f,S(g({},l),{method:"OPTIONS"}))},HEAD(f,l){return C(f,S(g({},l),{method:"HEAD"}))},PATCH(f,l){return C(f,S(g({},l),{method:"PATCH"}))},TRACE(f,l){return C(f,S(g({},l),{method:"TRACE"}))},use(...f){for(const l of f)if(l){if(typeof l!="object"||!("onRequest"in l||"onResponse"in l||"onError"in l))throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");m.push(l)}},eject(...f){for(const l of f){const x=m.indexOf(l);x!==-1&&m.splice(x,1)}}}}function q(e,r,t){if(r==null)return"";if(typeof r=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${(t==null?void 0:t.allowReserved)===!0?r:encodeURIComponent(r)}`}function j(e,r,t){if(!r||typeof r!="object")return"";const n=[],i={simple:",",label:".",matrix:";"}[t.style]||"&";if(t.style!=="deepObject"&&t.explode===!1){for(const h in r)n.push(h,t.allowReserved===!0?r[h]:encodeURIComponent(r[h]));const a=n.join(",");switch(t.style){case"form":return`${e}=${a}`;case"label":return`.${a}`;case"matrix":return`;${e}=${a}`;default:return a}}for(const a in r){const h=t.style==="deepObject"?`${e}[${a}]`:a;n.push(q(h,r[a],t))}const s=n.join(i);return t.style==="label"||t.style==="matrix"?`${i}${s}`:s}function F(e,r,t){if(!Array.isArray(r))return"";if(t.explode===!1){const s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",a=(t.allowReserved===!0?r:r.map(h=>encodeURIComponent(h))).join(s);switch(t.style){case"simple":return a;case"label":return`.${a}`;case"matrix":return`;${e}=${a}`;default:return`${e}=${a}`}}const n={simple:",",label:".",matrix:";"}[t.style]||"&",i=[];for(const s of r)t.style==="simple"||t.style==="label"?i.push(t.allowReserved===!0?s:encodeURIComponent(s)):i.push(q(e,s,t));return t.style==="label"||t.style==="matrix"?`${n}${i.join(n)}`:i.join(n)}function se(e){return function(t){const n=[];if(t&&typeof t=="object")for(const i in t){const s=t[i];if(s!=null){if(Array.isArray(s)){if(s.length===0)continue;n.push(F(i,s,S(g({style:"form",explode:!0},e==null?void 0:e.array),{allowReserved:(e==null?void 0:e.allowReserved)||!1})));continue}if(typeof s=="object"){n.push(j(i,s,S(g({style:"deepObject",explode:!0},e==null?void 0:e.object),{allowReserved:(e==null?void 0:e.allowReserved)||!1})));continue}n.push(q(i,s,e))}}return n.join("&")}}function we(e,r){var n;let t=e;for(const i of(n=e.match(R))!=null?n:[]){let s=i.substring(1,i.length-1),a=!1,h="simple";if(s.endsWith("*")&&(a=!0,s=s.substring(0,s.length-1)),s.startsWith(".")?(h="label",s=s.substring(1)):s.startsWith(";")&&(h="matrix",s=s.substring(1)),!r||r[s]===void 0||r[s]===null)continue;const b=r[s];if(Array.isArray(b)){t=t.replace(i,F(s,b,{style:h,explode:a}));continue}if(typeof b=="object"){t=t.replace(i,j(s,b,{style:h,explode:a}));continue}if(h==="matrix"){t=t.replace(i,`;${q(s,b)}`);continue}t=t.replace(i,h==="label"?`.${encodeURIComponent(b)}`:encodeURIComponent(b))}return t}function pe(e,r){var t,n;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)}function ge(e,r){var i,s;let t=`${r.baseUrl}${e}`;(i=r.params)!=null&&i.path&&(t=we(t,r.params.path));let n=r.querySerializer((s=r.params.query)!=null?s:{});return n.startsWith("?")&&(n=n.substring(1)),n&&(t+=`?${n}`),t}function ne(...e){const r=new Headers;for(const t of e){if(!t||typeof t!="object")continue;const n=t instanceof Headers?t.entries():Object.entries(t);for(const[i,s]of n)if(s===null)r.delete(i);else if(Array.isArray(s))for(const a of s)r.append(i,a);else s!==void 0&&r.set(i,s)}return r}function ie(e){return e.endsWith("/")?e.substring(0,e.length-1):e}const oe=(e,r,t)=>{try{const n=`${r}_${e}`,i=localStorage.getItem(n);if(!i)return null;const{data:s,timestamp:a}=JSON.parse(i);return t&&Date.now()-a>t?(localStorage.removeItem(n),null):s}catch(n){return null}},Y=(e,r,t)=>{try{const n=`${t}_${e}`,i={data:r,timestamp:Date.now()};localStorage.setItem(n,JSON.stringify(i))}catch(n){console.warn("Failed to cache dismissible item:",n)}},ae=(e,r)=>{try{const t=`${r}_${e}`;localStorage.removeItem(t)}catch(t){console.warn("Failed to remove cached dismissible item:",t)}},Z=o.createContext(null),ce=()=>{const e=o.useContext(Z);if(!e)throw new Error("useDismissibleContext must be used within a DismissibleProvider");return e},Ee="dismissible",le=(e,r={})=>{var _;const{initialData:t,enableCache:n=!0,cachePrefix:i=Ee,cacheExpiration:s}=r,a=ce(),{userId:h}=a,b=o.useMemo(()=>X({baseUrl:a.baseUrl,headers:{}}),[a.baseUrl]),m=o.useMemo(()=>`${h}-${e}`,[h,e]),C=o.useRef({enableCache:n,cachePrefix:i,cacheExpiration:s}),H=o.useRef(e),f=o.useRef(m),l=o.useRef(null),[x,A]=o.useState(!1),[L,$]=o.useState(null),[D,O]=o.useState(()=>{if(t)return t;if(n){const u=oe(m,i,s);if(u)return u}}),T=o.useCallback(()=>U(null,null,function*(){var p;if(n){const y=oe(m,i,s);if(y!=null&&y.dismissedAt){O(y),A(!1);return}}(p=l.current)==null||p.abort();const u=new AbortController;l.current=u,A(!0),$(null);try{const y=yield a.getAuthHeaders(),{data:k,error:ee}=yield b.GET("/v1/users/{userId}/items/{itemId}",{params:{path:{userId:h,itemId:e}},headers:y,signal:u.signal});if(ee||!k)throw new Error("Failed to fetch dismissible item");O(k.data),n&&Y(m,k.data,i)}catch(y){if(y instanceof Error&&y.name==="AbortError")return;$(y instanceof Error?y:new Error("Unknown error occurred"))}finally{A(!1)}}),[e,h,m,n,i,s,b,a]);o.useEffect(()=>{const u=H.current!==e,p=f.current!==m;u||p?(H.current=e,f.current=m,T()):t||T()},[e,m,t,T]),o.useEffect(()=>()=>{var u;(u=l.current)==null||u.abort()},[]),o.useEffect(()=>{const u=C.current;(u.enableCache!==n||u.cachePrefix!==i||u.cacheExpiration!==s)&&(u.cachePrefix!==i&&ae(m,u.cachePrefix),!n&&u.enableCache&&ae(m,u.cachePrefix),C.current={enableCache:n,cachePrefix:i,cacheExpiration:s},T())},[n,i,s,m,T]);const J=o.useCallback(()=>U(null,null,function*(){$(null);try{const u=yield a.getAuthHeaders(),{data:p,error:y}=yield b.DELETE("/v1/users/{userId}/items/{itemId}",{params:{path:{userId:h,itemId:e}},headers:u});if(y||!p)throw new Error("Failed to dismiss item");O(p.data),n&&Y(m,p.data,i)}catch(u){throw $(u instanceof Error?u:new Error("Failed to dismiss item")),u}}),[e,h,m,n,i,b,a]),W=o.useCallback(()=>U(null,null,function*(){$(null);try{const u=yield a.getAuthHeaders(),{data:p,error:y}=yield b.POST("/v1/users/{userId}/items/{itemId}",{params:{path:{userId:h,itemId:e}},headers:u});if(y||!p)throw new Error("Failed to restore item");O(p.data),n&&Y(m,p.data,i)}catch(u){throw $(u instanceof Error?u:new Error("Failed to restore item")),u}}),[e,h,m,n,i,b,a]);return{dismissedOn:(_=D==null?void 0:D.dismissedAt)!=null?_:null,dismiss:J,restore:W,isLoading:x,error:L,item:D}},ve=()=>d.jsx("div",{className:"dismissible-loading","aria-live":"polite",children:"Loading..."}),Ce=()=>d.jsx("div",{className:"dismissible-error",role:"alert",children:"Unable to load content. Please try again later."}),Re=({onDismiss:e,ariaLabel:r})=>d.jsx("button",{className:"dismissible-button",onClick:e,"aria-label":r,type:"button",children:"×"}),Se=({itemId:e,children:r,onDismiss:t,LoadingComponent:n=ve,ErrorComponent:i=Ce,DismissButtonComponent:s=Re,enableCache:a,cachePrefix:h,cacheExpiration:b,ignoreErrors:m=!1})=>{const{dismissedOn:C,isLoading:H,error:f,dismiss:l}=le(e,{enableCache:a,cachePrefix:h,cacheExpiration:b}),[x,A]=o.useState(!1);o.useEffect(()=>{A(!1)},[e]);const L=()=>U(null,null,function*(){A(!0);try{yield l(),t==null||t()}catch($){A(!1)}});return H&&n?d.jsx(n,{itemId:e}):H&&!n?null:f&&i&&!m?d.jsx(i,{itemId:e,error:f}):C||x?null:d.jsxs("div",{className:"dismissible-container",children:[d.jsx("div",{className:"dismissible-content",children:r}),s?d.jsx(s,{onDismiss:L,ariaLabel:`Dismiss ${e}`}):null]})},ue=e=>U(null,null,function*(){if(typeof e=="function")try{const r=e();return yield Promise.resolve(r)}catch(r){console.warn("Failed to resolve JWT from function:",r);return}return e}),fe=e=>U(null,null,function*(){const r=yield ue(e);return r?{Authorization:`Bearer ${r}`}:{}}),xe=e=>{try{const r=new URL(e),t=r.hostname==="localhost"||r.hostname==="127.0.0.1"||r.hostname==="[::1]",n=r.protocol==="https:";return{isSecure:n||t,isLocalhost:t,isHttps:n}}catch(r){return{isSecure:!1,isLocalhost:!1,isHttps:!1}}},De=({userId:e,jwt:r,baseUrl:t,children:n})=>{const{isSecure:i}=xe(t);i||console.warn(`[dismissible] Insecure baseUrl "${t}". Use https:// in production (or localhost for development). JWT tokens may be exposed over insecure connections.`);const s=o.useMemo(()=>({userId:e,jwt:r,baseUrl:t,getAuthHeaders:()=>U(null,null,function*(){return yield fe(r)})}),[e,r,t]);return d.jsx(Z.Provider,{value:s,children:n})};c.Dismissible=Se,c.DismissibleContext=Z,c.DismissibleProvider=De,c.getAuthHeaders=fe,c.resolveJwt=ue,c.useDismissibleContext=ce,c.useDismissibleItem=le,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
@@ -1,10 +1,6 @@
1
1
  import { components } from '../generated/contract';
2
2
  type DismissibleItem = components["schemas"]["DismissibleItemResponseDto"];
3
3
  export type IDismissibleItem = DismissibleItem;
4
- /** Metadata object with string or number values */
5
- export type IMetadata = {
6
- [key: string]: string | number;
7
- };
8
4
  export interface UseDismissibleItemOptions {
9
5
  /** Initial data for the dismissible item */
10
6
  initialData?: IDismissibleItem;
@@ -14,8 +10,6 @@ export interface UseDismissibleItemOptions {
14
10
  cachePrefix?: string;
15
11
  /** Cache expiration time in milliseconds (default: never expires) */
16
12
  cacheExpiration?: number;
17
- /** Optional metadata object that will be converted to key:value string pairs */
18
- metadata?: IMetadata;
19
13
  }
20
14
  /**
21
15
  * Hook for managing dismissible items
@@ -34,9 +28,6 @@ export declare const useDismissibleItem: (itemId: string, options?: UseDismissib
34
28
  userId: string;
35
29
  createdAt: string;
36
30
  dismissedAt?: string;
37
- metadata?: {
38
- [key: string]: unknown;
39
- };
40
31
  } | undefined;
41
32
  };
42
33
  export {};
@@ -1 +1 @@
1
- .dismissible-container{position:relative;display:inline-block;width:100%}.dismissible-content{width:100%}.dismissible-button{position:absolute;top:8px;right:8px;background:#0000001a;border:none;border-radius:50%;width:24px;height:24px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:16px;line-height:1;color:#666;transition:all .2s ease}.dismissible-button:hover{background:#0003;color:#333}.dismissible-button:focus{outline:2px solid #007bff;outline-offset:2px}.dismissible-button:active{transform:scale(.95)}.dismissible-loading{padding:16px;text-align:center;color:#666;font-style:italic}.dismissible-error{padding:16px;background:#fee;border:1px solid #fcc;border-radius:4px;color:#c33;font-size:14px}@media (max-width: 768px){.dismissible-button{width:32px;height:32px;font-size:18px}}
1
+ .dismissible-container{position:relative;display:inline-block;width:100%}.dismissible-content{width:100%}.dismissible-button{position:absolute;top:8px;right:8px;background:#0000001a;border:none;border-radius:50%;width:24px;height:24px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:16px;line-height:1;color:#666;transition:all .2s ease}.dismissible-button:hover{background:#0003;color:#333}.dismissible-button:focus{outline:2px solid #007bff;outline-offset:2px}.dismissible-button:active{transform:scale(.95)}.dismissible-loading{padding:16px;text-align:center;color:#666;font-style:italic}.dismissible-error{padding:16px;background:#fee;border:1px solid #fcc;border-radius:4px;color:#c33;font-size:14px}@media(max-width:768px){.dismissible-button{width:32px;height:32px;font-size:18px}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dismissible/react-client",
3
- "version": "0.3.2-canary.4.578bcba",
3
+ "version": "0.3.2-canary.5.88e2777",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -48,44 +48,44 @@
48
48
  "@babel/core": "^7.28.5",
49
49
  "@babel/preset-env": "^7.28.5",
50
50
  "@babel/preset-typescript": "^7.28.5",
51
- "@commitlint/cli": "^19.8.1",
52
- "@commitlint/config-conventional": "^19.8.1",
51
+ "@commitlint/cli": "^20.2.0",
52
+ "@commitlint/config-conventional": "^20.2.0",
53
53
  "@semantic-release/changelog": "^6.0.3",
54
54
  "@semantic-release/git": "^10.0.1",
55
- "@semantic-release/github": "^10.3.5",
56
- "@semantic-release/npm": "^12.0.2",
57
- "@storybook/addon-a11y": "^9.1.16",
58
- "@storybook/addon-docs": "^9.1.16",
59
- "@storybook/react-vite": "^9.1.16",
55
+ "@semantic-release/github": "^12.0.2",
56
+ "@semantic-release/npm": "^13.1.3",
57
+ "@storybook/addon-a11y": "^10.1.10",
58
+ "@storybook/addon-docs": "^10.1.10",
59
+ "@storybook/react-vite": "^10.1.10",
60
60
  "@testing-library/jest-dom": "^6.9.1",
61
- "@testing-library/react": "^16.3.0",
62
- "@types/node": "^25.0.2",
61
+ "@testing-library/react": "^16.3.1",
62
+ "@types/node": "^25.0.3",
63
63
  "@types/react": "^19.2.7",
64
64
  "@types/react-dom": "^19.2.3",
65
- "@typescript-eslint/eslint-plugin": "^8.49.0",
66
- "@typescript-eslint/parser": "^8.49.0",
67
- "@vitejs/plugin-react": "^4.7.0",
65
+ "@typescript-eslint/eslint-plugin": "^8.50.0",
66
+ "@typescript-eslint/parser": "^8.50.0",
67
+ "@vitejs/plugin-react": "^5.1.2",
68
68
  "commitizen": "^4.3.1",
69
69
  "core-js": "^3.47.0",
70
70
  "cz-conventional-changelog": "^3.3.0",
71
- "eslint": "^8.57.1",
71
+ "eslint": "^9.39.2",
72
72
  "eslint-plugin-react": "^7.37.5",
73
- "eslint-plugin-react-hooks": "^5.2.0",
74
- "eslint-plugin-storybook": "^9.1.16",
75
- "happy-dom": "^18.0.1",
73
+ "eslint-plugin-react-hooks": "^7.0.1",
74
+ "eslint-plugin-storybook": "^10.1.10",
75
+ "happy-dom": "^20.0.11",
76
76
  "msw": "^2.12.4",
77
77
  "msw-storybook-addon": "^2.0.6",
78
78
  "openapi-typescript": "^7.10.1",
79
79
  "prettier": "^3.7.4",
80
80
  "react": "^19.2.3",
81
81
  "react-dom": "^19.2.3",
82
- "semantic-release": "^24.2.7",
83
- "storybook": "^9.1.16",
82
+ "semantic-release": "^25.0.2",
83
+ "storybook": "^10.1.10",
84
84
  "ts-node": "^10.9.2",
85
85
  "typescript": "^5.9.3",
86
- "vite": "^5.4.21",
86
+ "vite": "^7.3.0",
87
87
  "vite-plugin-dts": "^4.5.4",
88
- "vitest": "^3.2.4"
88
+ "vitest": "^4.0.16"
89
89
  },
90
90
  "config": {
91
91
  "commitizen": {