@dismissible/react-client 0.3.0 β†’ 0.3.2

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
@@ -1,6 +1,10 @@
1
1
  # @dismissible/react-client
2
2
 
3
- A React component library for creating dismissible UI elements with persistent state management.
3
+ A React component library for creating dismissible UI elements with persistent state management.
4
+
5
+ Use this in combination with [dismissible.io](https://dismissible.io). Get your free account now!
6
+
7
+ 🌐 **[dismissible.io](https://dismissible.io)** | πŸ’° **[View Pricing](https://dismissible.io/pricing)** | πŸ“– **[Documentation](https://docs.dismissible.io)**
4
8
 
5
9
  [![npm version](https://badge.fury.io/js/@dismissible%2Freact-client.svg)](https://badge.fury.io/js/@dismissible%2Freact-client)
6
10
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -9,7 +13,7 @@ A React component library for creating dismissible UI elements with persistent s
9
13
 
10
14
  - 🎯 **Easy to use** - Simple component API for dismissible content
11
15
  - πŸ’Ύ **Persistent state** - Dismissal state is saved and restored across sessions
12
- - πŸ” **JWT Authentication** - Built-in support for JWT-based user authentication
16
+ - πŸ” **JWT Authentication** - Built-in support for JWT-based user authentication (Enterprise only)
13
17
  - 🎨 **Customizable** - Custom loading, error, and dismiss button components
14
18
  - β™Ώ **Accessible** - Built with accessibility best practices
15
19
  - πŸͺ **Hook-based** - Includes `useDismissibleItem` hook for custom implementations
@@ -54,11 +58,13 @@ function App() {
54
58
 
55
59
  Context provider for JWT authentication and configuration. Wrap your app or components that need JWT authentication.
56
60
 
61
+ > **Note:** JWT authentication is only available for **Enterprise customers**. For standard usage, you can use the `<Dismissible>` component directly without a provider. [View pricing β†’](https://dismissible.io/pricing)
62
+
57
63
  #### Props
58
64
 
59
65
  | Prop | Type | Required | Description |
60
66
  |------|------|----------|-------------|
61
- | `jwt` | `string \| (() => string)` | ❌ | JWT token (static string or function) |
67
+ | `jwt` | `string \| (() => string) \| (() => Promise<string>)` | ❌ | JWT token for user-specific dismissals (**Enterprise only**) |
62
68
  | `baseUrl` | `string` | ❌ | Custom API base URL override |
63
69
  | `children` | `ReactNode` | βœ… | Components that will use the dismissible functionality |
64
70
 
@@ -85,6 +91,15 @@ function AppWithDynamicAuth() {
85
91
  );
86
92
  }
87
93
 
94
+ // With async JWT function
95
+ function AppWithAsyncAuth() {
96
+ return (
97
+ <DismissibleProvider jwt={async () => await fetchAccessToken()}>
98
+ <YourApp />
99
+ </DismissibleProvider>
100
+ );
101
+ }
102
+
88
103
  // Without JWT (anonymous/backwards compatible)
89
104
  function AppWithoutAuth() {
90
105
  return (
@@ -109,6 +124,7 @@ The main component for creating dismissible content.
109
124
  | `LoadingComponent` | `ComponentType<{id: string}>` | ❌ | Custom loading component |
110
125
  | `ErrorComponent` | `ComponentType<{id: string, error: Error}>` | ❌ | Custom error component |
111
126
  | `DismissButtonComponent` | `ComponentType<{id: string, onDismiss: () => Promise<void>, ariaLabel: string}>` | ❌ | Custom dismiss button |
127
+ | `ignoreErrors` | `boolean` | ❌ | Ignore errors and display component anyway (default: false) |
112
128
 
113
129
  #### Example
114
130
 
@@ -177,7 +193,9 @@ function CustomDismissible({ id, children }) {
177
193
 
178
194
  ## Usage Examples
179
195
 
180
- ### JWT Authentication Setup
196
+ ### JWT Authentication Setup (Enterprise Only)
197
+
198
+ > **Enterprise Feature:** JWT authentication allows user-specific dismissible state management. This feature requires an Enterprise subscription. [Learn more about Enterprise features β†’](https://dismissible.io/pricing)
181
199
 
182
200
  For enterprise accounts that require user-specific dismissible state, wrap your app with the `DismissibleProvider`:
183
201
 
@@ -216,6 +234,7 @@ function Dashboard() {
216
234
  import { DismissibleProvider } from '@dismissible/react-client';
217
235
  import { useAuth } from './auth'; // Your auth context
218
236
 
237
+ // Synchronous JWT function
219
238
  function App() {
220
239
  const { getAccessToken } = useAuth();
221
240
 
@@ -225,6 +244,17 @@ function App() {
225
244
  </DismissibleProvider>
226
245
  );
227
246
  }
247
+
248
+ // Asynchronous JWT function
249
+ function AppWithAsyncAuth() {
250
+ const { refreshAndGetToken } = useAuth();
251
+
252
+ return (
253
+ <DismissibleProvider jwt={async () => await refreshAndGetToken()}>
254
+ <YourApp />
255
+ </DismissibleProvider>
256
+ );
257
+ }
228
258
  ```
229
259
 
230
260
  ### Basic Dismissible Banner
@@ -341,36 +371,12 @@ function Dashboard() {
341
371
  }
342
372
  ```
343
373
 
344
- ### Conditional Dismissible Content
345
-
346
- ```tsx
347
- import { Dismissible } from '@dismissible/react-client';
348
-
349
- function ConditionalBanner({ user }) {
350
- // Only show to new users
351
- if (user.isReturning) {
352
- return null;
353
- }
354
-
355
- return (
356
- <Dismissible id={`onboarding-${user.id}`}>
357
- <div className="onboarding-tips">
358
- <h3>Getting Started</h3>
359
- <ul>
360
- <li>Complete your profile</li>
361
- <li>Connect with friends</li>
362
- <li>Explore our features</li>
363
- </ul>
364
- </div>
365
- </Dismissible>
366
- );
367
- }
368
- ```
369
-
370
374
  ### User-Specific vs Anonymous Dismissible Items
371
375
 
372
376
  The behavior changes based on whether JWT authentication is configured:
373
377
 
378
+ > **Enterprise vs Standard:** JWT authentication for user-specific dismissals is an Enterprise feature. Standard accounts use anonymous (account-level) dismissals. [Compare plans β†’](https://dismissible.io/pricing)
379
+
374
380
  ```tsx
375
381
  import { DismissibleProvider, Dismissible } from '@dismissible/react-client';
376
382
 
@@ -392,16 +398,82 @@ function AuthenticatedApp() {
392
398
  </DismissibleProvider>
393
399
  );
394
400
  }
401
+ ```
402
+
403
+ ### Error Handling with ignoreErrors
404
+
405
+ ```tsx
406
+ import { Dismissible } from '@dismissible/react-client';
395
407
 
396
- // Without JWT - dismissible state is account-level (anonymous)
397
- function AnonymousApp() {
408
+ // Show content even if API fails
409
+ function RobustBanner() {
398
410
  return (
399
- <div>
400
- {/* These will be dismissed for all users of this account */}
401
- <Dismissible id="general-announcement">
402
- <div>Site maintenance scheduled</div>
403
- </Dismissible>
404
- </div>
411
+ <Dismissible
412
+ id="important-announcement"
413
+ ignoreErrors={true}
414
+ >
415
+ <div className="important-banner">
416
+ <h3>Critical System Update</h3>
417
+ <p>System maintenance scheduled for tonight. Please save your work.</p>
418
+ </div>
419
+ </Dismissible>
420
+ );
421
+ }
422
+ ```
423
+
424
+ ### Async JWT Authentication Examples
425
+
426
+ ```tsx
427
+ import { DismissibleProvider } from '@dismissible/react-client';
428
+
429
+ // With token refresh logic
430
+ function AppWithTokenRefresh() {
431
+ return (
432
+ <DismissibleProvider
433
+ jwt={async () => {
434
+ try {
435
+ const token = await fetch('/api/auth/refresh', {
436
+ method: 'POST',
437
+ credentials: 'include'
438
+ });
439
+ const { accessToken } = await token.json();
440
+ return accessToken;
441
+ } catch (error) {
442
+ console.error('Failed to refresh token:', error);
443
+ throw error;
444
+ }
445
+ }}
446
+ >
447
+ <YourApp />
448
+ </DismissibleProvider>
449
+ );
450
+ }
451
+
452
+ // With Firebase Auth
453
+ function AppWithFirebase() {
454
+ return (
455
+ <DismissibleProvider
456
+ jwt={async () => {
457
+ const user = firebase.auth().currentUser;
458
+ if (user) {
459
+ return await user.getIdToken();
460
+ }
461
+ throw new Error('User not authenticated');
462
+ }}
463
+ >
464
+ <YourApp />
465
+ </DismissibleProvider>
466
+ );
467
+ }
468
+
469
+ // With Auth0
470
+ function AppWithAuth0() {
471
+ const { getAccessTokenSilently } = useAuth0();
472
+
473
+ return (
474
+ <DismissibleProvider jwt={async () => await getAccessTokenSilently()}>
475
+ <YourApp />
476
+ </DismissibleProvider>
405
477
  );
406
478
  }
407
479
  ```
@@ -446,10 +518,10 @@ function SmartNotification({ id, message, type = 'info' }) {
446
518
  );
447
519
  }
448
520
 
449
- // Usage with authentication
521
+ // Usage with async authentication
450
522
  function App() {
451
523
  return (
452
- <DismissibleProvider jwt={() => getUserToken()}>
524
+ <DismissibleProvider jwt={async () => await getUserToken()}>
453
525
  <SmartNotification
454
526
  id="user-specific-notification"
455
527
  message="Welcome back!"
@@ -510,79 +582,6 @@ const AuthProvider: React.FC<DismissibleProviderProps> = ({ children, jwt }) =>
510
582
  };
511
583
  ```
512
584
 
513
- ## Development
514
-
515
- ### Prerequisites
516
-
517
- - Node.js 18+
518
- - npm or yarn
519
-
520
- ### Setup
521
-
522
- ```bash
523
- # Clone the repository
524
- git clone https://github.com/your-org/dismissible.git
525
- cd dismissible/react-client
526
-
527
- # Install dependencies
528
- npm install
529
-
530
- # Start development server
531
- npm run dev
532
- ```
533
-
534
- ### Available Scripts
535
-
536
- - `npm run dev` - Start development server with Vite
537
- - `npm run build` - Build the library for production
538
- - `npm run test` - Run tests with Vitest
539
- - `npm run test:watch` - Run tests in watch mode
540
- - `npm run lint` - Run ESLint
541
- - `npm run format` - Format code with Prettier
542
- - `npm run storybook` - Start Storybook development server
543
- - `npm run build-storybook` - Build Storybook for production
544
-
545
- ### Testing
546
-
547
- ```bash
548
- # Run all tests
549
- npm run test
550
-
551
- # Run tests in watch mode
552
- npm run test:watch
553
-
554
- # Run tests with coverage
555
- npm run test -- --coverage
556
- ```
557
-
558
- ### Storybook
559
-
560
- The library includes Storybook for component development and documentation:
561
-
562
- ```bash
563
- npm run storybook
564
- ```
565
-
566
- ## Contributing
567
-
568
- We welcome contributions! Please see our [Contributing Guide](../CONTRIBUTING.md) for details.
569
-
570
- ### Development Workflow
571
-
572
- 1. Fork the repository
573
- 2. Create a feature branch: `git checkout -b feature/my-new-feature`
574
- 3. Make your changes
575
- 4. Add tests for new functionality
576
- 5. Run tests: `npm run test`
577
- 6. Run linting: `npm run lint`
578
- 7. Commit your changes: `git commit -am 'Add new feature'`
579
- 8. Push to the branch: `git push origin feature/my-new-feature`
580
- 9. Submit a pull request
581
-
582
- ## License
583
-
584
- MIT Β© [Dismissible](https://github.com/joshystuart)
585
-
586
585
  ## Support
587
586
 
588
587
  - πŸ“– [Documentation](https://docs.dismissible.io)
@@ -1,22 +1,22 @@
1
1
  var de = Object.defineProperty, he = Object.defineProperties;
2
2
  var me = Object.getOwnPropertyDescriptors;
3
3
  var k = Object.getOwnPropertySymbols;
4
- var V = Object.prototype.hasOwnProperty, X = Object.prototype.propertyIsEnumerable;
5
- var Q = (e, r, t) => r in e ? de(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, y = (e, r) => {
4
+ var X = Object.prototype.hasOwnProperty, Y = Object.prototype.propertyIsEnumerable;
5
+ var V = (e, r, t) => r in e ? de(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, y = (e, r) => {
6
6
  for (var t in r || (r = {}))
7
- V.call(r, t) && Q(e, t, r[t]);
7
+ X.call(r, t) && V(e, t, r[t]);
8
8
  if (k)
9
9
  for (var t of k(r))
10
- X.call(r, t) && Q(e, t, r[t]);
10
+ Y.call(r, t) && V(e, t, r[t]);
11
11
  return e;
12
12
  }, R = (e, r) => he(e, me(r));
13
13
  var W = (e, r) => {
14
14
  var t = {};
15
15
  for (var n in e)
16
- V.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
16
+ X.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
17
17
  if (e != null && k)
18
18
  for (var n of k(e))
19
- r.indexOf(n) < 0 && X.call(e, n) && (t[n] = e[n]);
19
+ r.indexOf(n) < 0 && Y.call(e, n) && (t[n] = e[n]);
20
20
  return t;
21
21
  };
22
22
  var S = (e, r, t) => new Promise((n, i) => {
@@ -36,7 +36,7 @@ var S = (e, r, t) => new Promise((n, i) => {
36
36
  u((t = t.apply(e, r)).next());
37
37
  });
38
38
  import { jsx as x, jsxs as oe } from "react/jsx-runtime";
39
- import { createContext as ye, useContext as be, useMemo as B, useRef as M, useState as F, useCallback as Y, useEffect as Z } from "react";
39
+ import { createContext as ye, useContext as be, useMemo as B, useRef as M, useState as F, useCallback as Z, useEffect as G } from "react";
40
40
  const pe = /\{[^{}]+\}/g, ge = () => {
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;
@@ -66,8 +66,8 @@ function Re(e) {
66
66
  const h = [];
67
67
  function g(l, a) {
68
68
  return S(this, null, function* () {
69
- var K;
70
- const G = a || {}, {
69
+ var Q;
70
+ const K = a || {}, {
71
71
  baseUrl: E,
72
72
  fetch: C = n,
73
73
  Request: $ = t,
@@ -77,7 +77,7 @@ function Re(e) {
77
77
  querySerializer: U,
78
78
  bodySerializer: f = s != null ? s : Ee,
79
79
  body: d
80
- } = G, v = W(G, [
80
+ } = K, v = W(K, [
81
81
  "baseUrl",
82
82
  "fetch",
83
83
  "Request",
@@ -89,7 +89,7 @@ function Re(e) {
89
89
  "body"
90
90
  ]);
91
91
  let w = r;
92
- E && (w = (K = re(E)) != null ? K : r);
92
+ E && (w = (Q = re(E)) != null ? Q : r);
93
93
  let L = typeof i == "function" ? i : ee(i);
94
94
  U && (L = typeof U == "function" ? U : ee(y(y({}, typeof i == "object" ? i : {}), U)));
95
95
  const J = d === void 0 ? void 0 : f(
@@ -487,7 +487,7 @@ const Ae = {
487
487
  );
488
488
  if (f) return f;
489
489
  }
490
- }), A = Y(() => S(void 0, null, function* () {
490
+ }), A = Z(() => S(void 0, null, function* () {
491
491
  var f;
492
492
  if (n) {
493
493
  const d = ne(
@@ -534,10 +534,10 @@ const Ae = {
534
534
  u,
535
535
  o
536
536
  ]);
537
- Z(() => {
537
+ G(() => {
538
538
  const f = g.current !== e, d = j.current !== c;
539
539
  f || d ? (g.current = e, j.current = c, A()) : t || A();
540
- }, [e, c, t]), Z(() => {
540
+ }, [e, c, t]), G(() => {
541
541
  const f = h.current;
542
542
  (f.enableCache !== n || f.cachePrefix !== i || f.cacheExpiration !== s) && (f.cachePrefix !== i && ie(c, f.cachePrefix), !n && f.enableCache && ie(c, i), h.current = {
543
543
  enableCache: n,
@@ -545,7 +545,7 @@ const Ae = {
545
545
  cacheExpiration: s
546
546
  }, A());
547
547
  }, [n, i, s, c]);
548
- const q = Y(() => S(void 0, null, function* () {
548
+ const q = Z(() => S(void 0, null, function* () {
549
549
  var f;
550
550
  C(null);
551
551
  try {
@@ -607,7 +607,11 @@ const Ae = {
607
607
  enableCache: o,
608
608
  cachePrefix: u,
609
609
  cacheExpiration: c
610
- }), [E, C] = F(!1), $ = () => S(void 0, null, function* () {
610
+ }), [E, C] = F(!1);
611
+ G(() => {
612
+ C(!1);
613
+ }, [e]);
614
+ const $ = () => S(void 0, null, function* () {
611
615
  C(!0);
612
616
  try {
613
617
  yield a(), t == null || t();
@@ -658,7 +662,7 @@ const Ae = {
658
662
  [e, r]
659
663
  );
660
664
  return /* @__PURE__ */ x(le.Provider, { value: n, children: t });
661
- }, Le = "0.3.0";
665
+ }, Le = "0.3.1";
662
666
  export {
663
667
  ke as Dismissible,
664
668
  le as DismissibleContext,
@@ -1 +1 @@
1
- (function(a,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],u):(a=typeof globalThis!="undefined"?globalThis:a||self,u(a.DismissibleClient={},a.React.jsxRuntime,a.React))})(this,function(a,u,l){"use strict";var Te=Object.defineProperty,Ue=Object.defineProperties;var qe=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var fe=(a,u,l)=>u in a?Te(a,u,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[u]=l,p=(a,u)=>{for(var l in u||(u={}))de.call(u,l)&&fe(a,l,u[l]);if(W)for(var l of W(u))he.call(u,l)&&fe(a,l,u[l]);return a},S=(a,u)=>Ue(a,qe(u));var Y=(a,u)=>{var l={};for(var C in a)de.call(a,C)&&u.indexOf(C)<0&&(l[C]=a[C]);if(a!=null&&W)for(var C of W(a))u.indexOf(C)<0&&he.call(a,C)&&(l[C]=a[C]);return l};var O=(a,u,l)=>new Promise((C,L)=>{var V=I=>{try{T(l.next(I))}catch(k){L(k)}},B=I=>{try{T(l.throw(I))}catch(k){L(k)}},T=I=>I.done?C(I.value):Promise.resolve(I.value).then(V,B);T((l=l.apply(a,u)).next())});const C=/\{[^{}]+\}/g,L=()=>{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 B(e){let U=p({},e),{baseUrl:r="",Request:t=globalThis.Request,fetch:n=globalThis.fetch,querySerializer:i,bodySerializer:s,headers:o,requestInitExt:d=void 0}=U,h=Y(U,["baseUrl","Request","fetch","querySerializer","bodySerializer","headers","requestInitExt"]);d=L()?d:void 0,r=te(r);const g=[];function E(f,c){return O(this,null,function*(){var ue;const ce=c||{},{baseUrl:A,fetch:D=n,Request:H=t,headers:x,params:$={},parseAs:F="json",querySerializer:z,bodySerializer:m=s!=null?s:ye,body:y}=ce,j=Y(ce,["baseUrl","fetch","Request","headers","params","parseAs","querySerializer","bodySerializer","body"]);let R=r;A&&(R=(ue=te(A))!=null?ue:r);let K=typeof i=="function"?i:Z(i);z&&(K=typeof z=="function"?z:Z(p(p({},typeof i=="object"?i:{}),z)));const Q=y===void 0?void 0:m(y,ee(o,x,$.header)),De=ee(Q===void 0||Q instanceof FormData?{}:{"Content-Type":"application/json"},o,x,$.header),$e=S(p(p({redirect:"follow"},h),j),{body:Q,headers:De});let J,M,q=new t(be(f,{baseUrl:R,params:$,querySerializer:K}),$e),b;for(const v in j)v in q||(q[v]=j[v]);if(g.length){J=V(),M=Object.freeze({baseUrl:R,fetch:D,parseAs:F,querySerializer:K,bodySerializer:m});for(const v of g)if(v&&typeof v=="object"&&typeof v.onRequest=="function"){const w=yield v.onRequest({request:q,schemaPath:f,params:$,options:M,id:J});if(w)if(w instanceof t)q=w;else if(w instanceof Response){b=w;break}else throw new Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!b){try{b=yield D(q,d)}catch(v){let w=v;if(g.length)for(let P=g.length-1;P>=0;P--){const _=g[P];if(_&&typeof _=="object"&&typeof _.onError=="function"){const N=yield _.onError({request:q,error:w,schemaPath:f,params:$,options:M,id:J});if(N){if(N instanceof Response){w=void 0,b=N;break}if(N instanceof Error){w=N;continue}throw new Error("onError: must return new Response() or instance of Error")}}}if(w)throw w}if(g.length)for(let v=g.length-1;v>=0;v--){const w=g[v];if(w&&typeof w=="object"&&typeof w.onResponse=="function"){const P=yield w.onResponse({request:q,response:b,schemaPath:f,params:$,options:M,id:J});if(P){if(!(P instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");b=P}}}}if(b.status===204||q.method==="HEAD"||b.headers.get("Content-Length")==="0")return b.ok?{data:void 0,response:b}:{error:void 0,response:b};if(b.ok)return F==="stream"?{data:b.body,response:b}:{data:yield b[F](),response:b};let X=yield b.text();try{X=JSON.parse(X)}catch(v){}return{error:X,response:b}})}return{request(f,c,A){return E(c,S(p({},A),{method:f.toUpperCase()}))},GET(f,c){return E(f,S(p({},c),{method:"GET"}))},PUT(f,c){return E(f,S(p({},c),{method:"PUT"}))},POST(f,c){return E(f,S(p({},c),{method:"POST"}))},DELETE(f,c){return E(f,S(p({},c),{method:"DELETE"}))},OPTIONS(f,c){return E(f,S(p({},c),{method:"OPTIONS"}))},HEAD(f,c){return E(f,S(p({},c),{method:"HEAD"}))},PATCH(f,c){return E(f,S(p({},c),{method:"PATCH"}))},TRACE(f,c){return E(f,S(p({},c),{method:"TRACE"}))},use(...f){for(const c of f)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()`");g.push(c)}},eject(...f){for(const c of f){const A=g.indexOf(c);A!==-1&&g.splice(A,1)}}}}function T(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 I(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 o=n.join(",");switch(t.style){case"form":return`${e}=${o}`;case"label":return`.${o}`;case"matrix":return`;${e}=${o}`;default:return o}}for(const o in r){const d=t.style==="deepObject"?`${e}[${o}]`:o;n.push(T(d,r[o],t))}const s=n.join(i);return t.style==="label"||t.style==="matrix"?`${i}${s}`:s}function k(e,r,t){if(!Array.isArray(r))return"";if(t.explode===!1){const s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",o=(t.allowReserved===!0?r:r.map(d=>encodeURIComponent(d))).join(s);switch(t.style){case"simple":return o;case"label":return`.${o}`;case"matrix":return`;${e}=${o}`;default:return`${e}=${o}`}}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(T(e,s,t));return t.style==="label"||t.style==="matrix"?`${n}${i.join(n)}`:i.join(n)}function Z(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(k(i,s,S(p({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(I(i,s,S(p({style:"deepObject",explode:!0},e==null?void 0:e.object),{allowReserved:(e==null?void 0:e.allowReserved)||!1})));continue}n.push(T(i,s,e))}}return n.join("&")}}function me(e,r){var n;let t=e;for(const i of(n=e.match(C))!=null?n:[]){let s=i.substring(1,i.length-1),o=!1,d="simple";if(s.endsWith("*")&&(o=!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 h=r[s];if(Array.isArray(h)){t=t.replace(i,k(s,h,{style:d,explode:o}));continue}if(typeof h=="object"){t=t.replace(i,I(s,h,{style:d,explode:o}));continue}if(d==="matrix"){t=t.replace(i,`;${T(s,h)}`);continue}t=t.replace(i,d==="label"?`.${encodeURIComponent(h)}`:encodeURIComponent(h))}return t}function ye(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 be(e,r){var i,s;let t=`${r.baseUrl}${e}`;(i=r.params)!=null&&i.path&&(t=me(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 ee(...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 o of s)r.append(i,o);else s!==void 0&&r.set(i,s)}return r}function te(e){return e.endsWith("/")?e.substring(0,e.length-1):e}const pe={baseUrl:"http://localhost:3200"},ge={development:{baseUrl:"http://localhost:3200"},staging:{baseUrl:"https://api.staging.dismissible.io"},production:{baseUrl:"https://api.dismissible.io"}},we=()=>ge["production"]||pe,re=(e,r,t)=>{try{const n=`${r}_${e}`,i=localStorage.getItem(n);if(!i)return null;const{data:s,timestamp:o}=JSON.parse(i);return t&&Date.now()-o>t?(localStorage.removeItem(n),null):s}catch(n){return null}},se=(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)}},ne=(e,r)=>{try{const t=`${r}_${e}`;localStorage.removeItem(t)}catch(t){console.warn("Failed to remove cached dismissible item:",t)}},G=l.createContext(null),ie=()=>l.useContext(G),ve="dismissible",oe=(e,r={})=>{var z;const{initialData:t,enableCache:n=!0,cachePrefix:i=ve,cacheExpiration:s}=r,o=ie(),d=l.useMemo(()=>{const m=we(),y=(o==null?void 0:o.baseUrl)||m.baseUrl;return B({baseUrl:y,headers:{}})},[o]),h=l.useMemo(()=>!!(o!=null&&o.jwt)?`${e}-auth`:e,[e,o==null?void 0:o.jwt]),g=l.useRef({enableCache:n,cachePrefix:i,cacheExpiration:s}),E=l.useRef(e),U=l.useRef(h),[f,c]=l.useState(!1),[A,D]=l.useState(null),[H,x]=l.useState(()=>{if(t)return t;if(n){const m=re(h,i,s);if(m)return m}}),$=l.useCallback(()=>O(this,null,function*(){var m;if(n){const y=re(h,i,s);if(y!=null&&y.dismissedAt){x(y),c(!1);return}}c(!0),D(null);try{const y=o!=null&&o.getAuthHeaders?yield o.getAuthHeaders():{},{data:j,error:R}=yield d.GET("/v1/dismissible/{itemId}",{params:{path:{itemId:e}},headers:y});if(R)throw new Error(((m=R==null?void 0:R.error)==null?void 0:m.message)||"Failed to fetch dismissible item");x(j.data),n&&j.data&&se(h,j.data,i)}catch(y){D(y instanceof Error?y:new Error("Unknown error occurred"))}finally{c(!1)}}),[e,h,n,i,s,d,o]);l.useEffect(()=>{const m=E.current!==e,y=U.current!==h;m||y?(E.current=e,U.current=h,$()):t||$()},[e,h,t]),l.useEffect(()=>{const m=g.current;(m.enableCache!==n||m.cachePrefix!==i||m.cacheExpiration!==s)&&(m.cachePrefix!==i&&ne(h,m.cachePrefix),!n&&m.enableCache&&ne(h,i),g.current={enableCache:n,cachePrefix:i,cacheExpiration:s},$())},[n,i,s,h]);const F=l.useCallback(()=>O(this,null,function*(){var m;D(null);try{const y=o!=null&&o.getAuthHeaders?yield o.getAuthHeaders():{},{data:j,error:R}=yield d.DELETE("/v1/dismissible/{itemId}",{params:{path:{itemId:e}},headers:y});if(R)throw new Error(((m=R==null?void 0:R.error)==null?void 0:m.message)||"Failed to dismiss item");x(j.data),n&&j.data&&se(h,j.data,i)}catch(y){throw D(y instanceof Error?y:new Error("Failed to dismiss item")),y}}),[h,n,i,d,o]);return{dismissedOn:(z=H==null?void 0:H.dismissedAt)!=null?z:null,dismiss:F,isLoading:f,error:A,item:H}},Ee=()=>u.jsx("div",{className:"dismissible-loading","aria-live":"polite",children:"Loading..."}),Ce=({error:e})=>u.jsxs("div",{className:"dismissible-error",role:"alert",children:["Error loading dismissible item: ",e.message]}),Re=({id:e,onDismiss:r,ariaLabel:t})=>u.jsx("button",{id:e,className:"dismissible-button",onClick:r,"aria-label":t,type:"button",children:"Γ—"}),Se=({id:e,children:r,onDismiss:t,LoadingComponent:n=Ee,ErrorComponent:i=Ce,DismissButtonComponent:s=Re,enableCache:o,cachePrefix:d,cacheExpiration:h,ignoreErrors:g=!1})=>{const{dismissedOn:E,isLoading:U,error:f,dismiss:c}=oe(e,{enableCache:o,cachePrefix:d,cacheExpiration:h}),[A,D]=l.useState(!1),H=()=>O(this,null,function*(){D(!0);try{yield c(),t==null||t()}catch(x){D(!1)}});return U&&n?u.jsx(n,{id:e}):U&&!n?null:f&&i&&!g?u.jsx(i,{id:e,error:f}):E||A?null:u.jsxs("div",{className:"dismissible-container",children:[u.jsx("div",{className:"dismissible-content",children:r}),s?u.jsx(s,{id:e,onDismiss:H,ariaLabel:`Dismiss ${e}`}):null]})},ae=e=>O(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}),le=e=>O(this,null,function*(){const r=yield ae(e);return r?{Authorization:`Bearer ${r}`}:{}}),je=e=>{const r=e.split(".");return r.length===3&&r.every(t=>t.length>0)},Ae=({jwt:e,baseUrl:r,children:t})=>{const n=l.useMemo(()=>({jwt:e,baseUrl:r,getAuthHeaders:()=>O(this,null,function*(){return yield le(e)})}),[e,r]);return u.jsx(G.Provider,{value:n,children:t})},Ie="0.3.0";a.Dismissible=Se,a.DismissibleContext=G,a.DismissibleProvider=Ae,a.VERSION=Ie,a.getAuthHeaders=le,a.isValidJwtFormat=je,a.resolveJwt=ae,a.useDismissibleContext=ie,a.useDismissibleItem=oe,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],u):(l=typeof globalThis!="undefined"?globalThis:l||self,u(l.DismissibleClient={},l.React.jsxRuntime,l.React))})(this,function(l,u,a){"use strict";var Te=Object.defineProperty,Ue=Object.defineProperties;var qe=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var fe=(l,u,a)=>u in l?Te(l,u,{enumerable:!0,configurable:!0,writable:!0,value:a}):l[u]=a,p=(l,u)=>{for(var a in u||(u={}))de.call(u,a)&&fe(l,a,u[a]);if(W)for(var a of W(u))he.call(u,a)&&fe(l,a,u[a]);return l},S=(l,u)=>Ue(l,qe(u));var Y=(l,u)=>{var a={};for(var C in l)de.call(l,C)&&u.indexOf(C)<0&&(a[C]=l[C]);if(l!=null&&W)for(var C of W(l))u.indexOf(C)<0&&he.call(l,C)&&(a[C]=l[C]);return a};var O=(l,u,a)=>new Promise((C,L)=>{var V=D=>{try{T(a.next(D))}catch(k){L(k)}},B=D=>{try{T(a.throw(D))}catch(k){L(k)}},T=D=>D.done?C(D.value):Promise.resolve(D.value).then(V,B);T((a=a.apply(l,u)).next())});const C=/\{[^{}]+\}/g,L=()=>{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 B(e){let U=p({},e),{baseUrl:r="",Request:t=globalThis.Request,fetch:n=globalThis.fetch,querySerializer:i,bodySerializer:s,headers:o,requestInitExt:d=void 0}=U,h=Y(U,["baseUrl","Request","fetch","querySerializer","bodySerializer","headers","requestInitExt"]);d=L()?d:void 0,r=te(r);const g=[];function E(f,c){return O(this,null,function*(){var ue;const ce=c||{},{baseUrl:A,fetch:I=n,Request:H=t,headers:x,params:$={},parseAs:F="json",querySerializer:z,bodySerializer:m=s!=null?s:ye,body:y}=ce,j=Y(ce,["baseUrl","fetch","Request","headers","params","parseAs","querySerializer","bodySerializer","body"]);let R=r;A&&(R=(ue=te(A))!=null?ue:r);let K=typeof i=="function"?i:Z(i);z&&(K=typeof z=="function"?z:Z(p(p({},typeof i=="object"?i:{}),z)));const Q=y===void 0?void 0:m(y,ee(o,x,$.header)),De=ee(Q===void 0||Q instanceof FormData?{}:{"Content-Type":"application/json"},o,x,$.header),$e=S(p(p({redirect:"follow"},h),j),{body:Q,headers:De});let J,M,q=new t(be(f,{baseUrl:R,params:$,querySerializer:K}),$e),b;for(const v in j)v in q||(q[v]=j[v]);if(g.length){J=V(),M=Object.freeze({baseUrl:R,fetch:I,parseAs:F,querySerializer:K,bodySerializer:m});for(const v of g)if(v&&typeof v=="object"&&typeof v.onRequest=="function"){const w=yield v.onRequest({request:q,schemaPath:f,params:$,options:M,id:J});if(w)if(w instanceof t)q=w;else if(w instanceof Response){b=w;break}else throw new Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!b){try{b=yield I(q,d)}catch(v){let w=v;if(g.length)for(let P=g.length-1;P>=0;P--){const _=g[P];if(_&&typeof _=="object"&&typeof _.onError=="function"){const N=yield _.onError({request:q,error:w,schemaPath:f,params:$,options:M,id:J});if(N){if(N instanceof Response){w=void 0,b=N;break}if(N instanceof Error){w=N;continue}throw new Error("onError: must return new Response() or instance of Error")}}}if(w)throw w}if(g.length)for(let v=g.length-1;v>=0;v--){const w=g[v];if(w&&typeof w=="object"&&typeof w.onResponse=="function"){const P=yield w.onResponse({request:q,response:b,schemaPath:f,params:$,options:M,id:J});if(P){if(!(P instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");b=P}}}}if(b.status===204||q.method==="HEAD"||b.headers.get("Content-Length")==="0")return b.ok?{data:void 0,response:b}:{error:void 0,response:b};if(b.ok)return F==="stream"?{data:b.body,response:b}:{data:yield b[F](),response:b};let X=yield b.text();try{X=JSON.parse(X)}catch(v){}return{error:X,response:b}})}return{request(f,c,A){return E(c,S(p({},A),{method:f.toUpperCase()}))},GET(f,c){return E(f,S(p({},c),{method:"GET"}))},PUT(f,c){return E(f,S(p({},c),{method:"PUT"}))},POST(f,c){return E(f,S(p({},c),{method:"POST"}))},DELETE(f,c){return E(f,S(p({},c),{method:"DELETE"}))},OPTIONS(f,c){return E(f,S(p({},c),{method:"OPTIONS"}))},HEAD(f,c){return E(f,S(p({},c),{method:"HEAD"}))},PATCH(f,c){return E(f,S(p({},c),{method:"PATCH"}))},TRACE(f,c){return E(f,S(p({},c),{method:"TRACE"}))},use(...f){for(const c of f)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()`");g.push(c)}},eject(...f){for(const c of f){const A=g.indexOf(c);A!==-1&&g.splice(A,1)}}}}function T(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 o=n.join(",");switch(t.style){case"form":return`${e}=${o}`;case"label":return`.${o}`;case"matrix":return`;${e}=${o}`;default:return o}}for(const o in r){const d=t.style==="deepObject"?`${e}[${o}]`:o;n.push(T(d,r[o],t))}const s=n.join(i);return t.style==="label"||t.style==="matrix"?`${i}${s}`:s}function k(e,r,t){if(!Array.isArray(r))return"";if(t.explode===!1){const s={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",o=(t.allowReserved===!0?r:r.map(d=>encodeURIComponent(d))).join(s);switch(t.style){case"simple":return o;case"label":return`.${o}`;case"matrix":return`;${e}=${o}`;default:return`${e}=${o}`}}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(T(e,s,t));return t.style==="label"||t.style==="matrix"?`${n}${i.join(n)}`:i.join(n)}function Z(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(k(i,s,S(p({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,S(p({style:"deepObject",explode:!0},e==null?void 0:e.object),{allowReserved:(e==null?void 0:e.allowReserved)||!1})));continue}n.push(T(i,s,e))}}return n.join("&")}}function me(e,r){var n;let t=e;for(const i of(n=e.match(C))!=null?n:[]){let s=i.substring(1,i.length-1),o=!1,d="simple";if(s.endsWith("*")&&(o=!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 h=r[s];if(Array.isArray(h)){t=t.replace(i,k(s,h,{style:d,explode:o}));continue}if(typeof h=="object"){t=t.replace(i,D(s,h,{style:d,explode:o}));continue}if(d==="matrix"){t=t.replace(i,`;${T(s,h)}`);continue}t=t.replace(i,d==="label"?`.${encodeURIComponent(h)}`:encodeURIComponent(h))}return t}function ye(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 be(e,r){var i,s;let t=`${r.baseUrl}${e}`;(i=r.params)!=null&&i.path&&(t=me(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 ee(...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 o of s)r.append(i,o);else s!==void 0&&r.set(i,s)}return r}function te(e){return e.endsWith("/")?e.substring(0,e.length-1):e}const pe={baseUrl:"http://localhost:3200"},ge={development:{baseUrl:"http://localhost:3200"},staging:{baseUrl:"https://api.staging.dismissible.io"},production:{baseUrl:"https://api.dismissible.io"}},we=()=>ge["production"]||pe,re=(e,r,t)=>{try{const n=`${r}_${e}`,i=localStorage.getItem(n);if(!i)return null;const{data:s,timestamp:o}=JSON.parse(i);return t&&Date.now()-o>t?(localStorage.removeItem(n),null):s}catch(n){return null}},se=(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)}},ne=(e,r)=>{try{const t=`${r}_${e}`;localStorage.removeItem(t)}catch(t){console.warn("Failed to remove cached dismissible item:",t)}},G=a.createContext(null),ie=()=>a.useContext(G),ve="dismissible",oe=(e,r={})=>{var z;const{initialData:t,enableCache:n=!0,cachePrefix:i=ve,cacheExpiration:s}=r,o=ie(),d=a.useMemo(()=>{const m=we(),y=(o==null?void 0:o.baseUrl)||m.baseUrl;return B({baseUrl:y,headers:{}})},[o]),h=a.useMemo(()=>!!(o!=null&&o.jwt)?`${e}-auth`:e,[e,o==null?void 0:o.jwt]),g=a.useRef({enableCache:n,cachePrefix:i,cacheExpiration:s}),E=a.useRef(e),U=a.useRef(h),[f,c]=a.useState(!1),[A,I]=a.useState(null),[H,x]=a.useState(()=>{if(t)return t;if(n){const m=re(h,i,s);if(m)return m}}),$=a.useCallback(()=>O(this,null,function*(){var m;if(n){const y=re(h,i,s);if(y!=null&&y.dismissedAt){x(y),c(!1);return}}c(!0),I(null);try{const y=o!=null&&o.getAuthHeaders?yield o.getAuthHeaders():{},{data:j,error:R}=yield d.GET("/v1/dismissible/{itemId}",{params:{path:{itemId:e}},headers:y});if(R)throw new Error(((m=R==null?void 0:R.error)==null?void 0:m.message)||"Failed to fetch dismissible item");x(j.data),n&&j.data&&se(h,j.data,i)}catch(y){I(y instanceof Error?y:new Error("Unknown error occurred"))}finally{c(!1)}}),[e,h,n,i,s,d,o]);a.useEffect(()=>{const m=E.current!==e,y=U.current!==h;m||y?(E.current=e,U.current=h,$()):t||$()},[e,h,t]),a.useEffect(()=>{const m=g.current;(m.enableCache!==n||m.cachePrefix!==i||m.cacheExpiration!==s)&&(m.cachePrefix!==i&&ne(h,m.cachePrefix),!n&&m.enableCache&&ne(h,i),g.current={enableCache:n,cachePrefix:i,cacheExpiration:s},$())},[n,i,s,h]);const F=a.useCallback(()=>O(this,null,function*(){var m;I(null);try{const y=o!=null&&o.getAuthHeaders?yield o.getAuthHeaders():{},{data:j,error:R}=yield d.DELETE("/v1/dismissible/{itemId}",{params:{path:{itemId:e}},headers:y});if(R)throw new Error(((m=R==null?void 0:R.error)==null?void 0:m.message)||"Failed to dismiss item");x(j.data),n&&j.data&&se(h,j.data,i)}catch(y){throw I(y instanceof Error?y:new Error("Failed to dismiss item")),y}}),[h,n,i,d,o]);return{dismissedOn:(z=H==null?void 0:H.dismissedAt)!=null?z:null,dismiss:F,isLoading:f,error:A,item:H}},Ee=()=>u.jsx("div",{className:"dismissible-loading","aria-live":"polite",children:"Loading..."}),Ce=({error:e})=>u.jsxs("div",{className:"dismissible-error",role:"alert",children:["Error loading dismissible item: ",e.message]}),Re=({id:e,onDismiss:r,ariaLabel:t})=>u.jsx("button",{id:e,className:"dismissible-button",onClick:r,"aria-label":t,type:"button",children:"Γ—"}),Se=({id:e,children:r,onDismiss:t,LoadingComponent:n=Ee,ErrorComponent:i=Ce,DismissButtonComponent:s=Re,enableCache:o,cachePrefix:d,cacheExpiration:h,ignoreErrors:g=!1})=>{const{dismissedOn:E,isLoading:U,error:f,dismiss:c}=oe(e,{enableCache:o,cachePrefix:d,cacheExpiration:h}),[A,I]=a.useState(!1);a.useEffect(()=>{I(!1)},[e]);const H=()=>O(this,null,function*(){I(!0);try{yield c(),t==null||t()}catch(x){I(!1)}});return U&&n?u.jsx(n,{id:e}):U&&!n?null:f&&i&&!g?u.jsx(i,{id:e,error:f}):E||A?null:u.jsxs("div",{className:"dismissible-container",children:[u.jsx("div",{className:"dismissible-content",children:r}),s?u.jsx(s,{id:e,onDismiss:H,ariaLabel:`Dismiss ${e}`}):null]})},ae=e=>O(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}),le=e=>O(this,null,function*(){const r=yield ae(e);return r?{Authorization:`Bearer ${r}`}:{}}),je=e=>{const r=e.split(".");return r.length===3&&r.every(t=>t.length>0)},Ae=({jwt:e,baseUrl:r,children:t})=>{const n=a.useMemo(()=>({jwt:e,baseUrl:r,getAuthHeaders:()=>O(this,null,function*(){return yield le(e)})}),[e,r]);return u.jsx(G.Provider,{value:n,children:t})},Ie="0.3.1";l.Dismissible=Se,l.DismissibleContext=G,l.DismissibleProvider=Ae,l.VERSION=Ie,l.getAuthHeaders=le,l.isValidJwtFormat=je,l.resolveJwt=ae,l.useDismissibleContext=ie,l.useDismissibleItem=oe,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
package/dist/root.d.ts CHANGED
@@ -9,4 +9,4 @@ export * from './contexts/DismissibleContext';
9
9
  export * from './contexts/DismissibleProvider';
10
10
  export * from './types/dismissible.types';
11
11
  export * from './utils/auth.utils';
12
- export declare const VERSION = "0.3.0";
12
+ export declare const VERSION = "0.3.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dismissible/react-client",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",