@dismissible/react-client 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Dismissible.d.ts +3 -0
- package/dist/contexts/DismissibleProvider.d.ts +9 -1
- package/dist/dismissible-client.es.js +438 -376
- package/dist/dismissible-client.umd.js +1 -1
- package/dist/root.d.ts +1 -1
- package/dist/types/dismissible.types.d.ts +3 -3
- package/dist/utils/auth.utils.d.ts +7 -7
- package/package.json +9 -5
|
@@ -30,6 +30,8 @@ export interface DismissibleProps {
|
|
|
30
30
|
cachePrefix?: string;
|
|
31
31
|
/** Cache expiration time in milliseconds (default: never expires) */
|
|
32
32
|
cacheExpiration?: number;
|
|
33
|
+
/** Ignore errors and display the component anyway (default: false) */
|
|
34
|
+
ignoreErrors?: boolean;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* A wrapper component that can be dismissed and hidden by users
|
|
@@ -44,6 +46,7 @@ export interface DismissibleProps {
|
|
|
44
46
|
* @param enableCache - Enable localStorage caching
|
|
45
47
|
* @param cachePrefix - Cache key prefix
|
|
46
48
|
* @param cacheExpiration - Cache expiration time in milliseconds
|
|
49
|
+
* @param ignoreErrors - Ignore errors and display the component anyway
|
|
47
50
|
* @returns JSX element or null if dismissed
|
|
48
51
|
*/
|
|
49
52
|
export declare const Dismissible: React.FC<DismissibleProps>;
|
|
@@ -10,13 +10,21 @@ import { DismissibleProviderProps } from '../types/dismissible.types';
|
|
|
10
10
|
* <App />
|
|
11
11
|
* </DismissibleProvider>
|
|
12
12
|
*
|
|
13
|
-
* // With
|
|
13
|
+
* // With synchronous JWT function
|
|
14
14
|
* <DismissibleProvider
|
|
15
15
|
* jwt={() => getAccessToken()}
|
|
16
16
|
* baseUrl="https://api.dismissible.io"
|
|
17
17
|
* >
|
|
18
18
|
* <App />
|
|
19
19
|
* </DismissibleProvider>
|
|
20
|
+
*
|
|
21
|
+
* // With asynchronous JWT function
|
|
22
|
+
* <DismissibleProvider
|
|
23
|
+
* jwt={async () => await fetchAccessToken()}
|
|
24
|
+
* baseUrl="https://api.dismissible.io"
|
|
25
|
+
* >
|
|
26
|
+
* <App />
|
|
27
|
+
* </DismissibleProvider>
|
|
20
28
|
* ```
|
|
21
29
|
*/
|
|
22
30
|
export declare const DismissibleProvider: React.FC<DismissibleProviderProps>;
|
|
@@ -1,221 +1,273 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var de = Object.defineProperty, he = Object.defineProperties;
|
|
2
|
+
var me = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var k = Object.getOwnPropertySymbols;
|
|
4
|
+
var V = Object.prototype.hasOwnProperty, X = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var Q = (e, r, t) => r in e ? de(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, y = (e, r) => {
|
|
6
|
+
for (var t in r || (r = {}))
|
|
7
|
+
V.call(r, t) && Q(e, t, r[t]);
|
|
8
|
+
if (k)
|
|
9
|
+
for (var t of k(r))
|
|
10
|
+
X.call(r, t) && Q(e, t, r[t]);
|
|
11
|
+
return e;
|
|
12
|
+
}, R = (e, r) => he(e, me(r));
|
|
13
|
+
var W = (e, r) => {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var n in e)
|
|
16
|
+
V.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
|
|
17
|
+
if (e != null && k)
|
|
18
|
+
for (var n of k(e))
|
|
19
|
+
r.indexOf(n) < 0 && X.call(e, n) && (t[n] = e[n]);
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var S = (e, r, t) => new Promise((n, i) => {
|
|
23
|
+
var s = (c) => {
|
|
24
|
+
try {
|
|
25
|
+
u(t.next(c));
|
|
26
|
+
} catch (h) {
|
|
27
|
+
i(h);
|
|
28
|
+
}
|
|
29
|
+
}, o = (c) => {
|
|
30
|
+
try {
|
|
31
|
+
u(t.throw(c));
|
|
32
|
+
} catch (h) {
|
|
33
|
+
i(h);
|
|
34
|
+
}
|
|
35
|
+
}, u = (c) => c.done ? n(c.value) : Promise.resolve(c.value).then(s, o);
|
|
36
|
+
u((t = t.apply(e, r)).next());
|
|
37
|
+
});
|
|
38
|
+
import { jsx as x, jsxs as oe } from "react/jsx-runtime";
|
|
39
|
+
import { createContext as ye, useContext as be, useMemo as B, useRef as M, useState as F, useCallback as Y, useEffect as Z } from "react";
|
|
40
|
+
const pe = /\{[^{}]+\}/g, ge = () => {
|
|
4
41
|
var e, r;
|
|
5
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;
|
|
6
43
|
};
|
|
7
|
-
function
|
|
44
|
+
function we() {
|
|
8
45
|
return Math.random().toString(36).slice(2, 11);
|
|
9
46
|
}
|
|
10
|
-
function
|
|
11
|
-
let {
|
|
47
|
+
function Re(e) {
|
|
48
|
+
let j = y({}, e), {
|
|
12
49
|
baseUrl: r = "",
|
|
13
50
|
Request: t = globalThis.Request,
|
|
14
|
-
fetch:
|
|
15
|
-
querySerializer:
|
|
16
|
-
bodySerializer:
|
|
17
|
-
headers:
|
|
18
|
-
requestInitExt: u = void 0
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
i,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
51
|
+
fetch: n = globalThis.fetch,
|
|
52
|
+
querySerializer: i,
|
|
53
|
+
bodySerializer: s,
|
|
54
|
+
headers: o,
|
|
55
|
+
requestInitExt: u = void 0
|
|
56
|
+
} = j, c = W(j, [
|
|
57
|
+
"baseUrl",
|
|
58
|
+
"Request",
|
|
59
|
+
"fetch",
|
|
60
|
+
"querySerializer",
|
|
61
|
+
"bodySerializer",
|
|
62
|
+
"headers",
|
|
63
|
+
"requestInitExt"
|
|
64
|
+
]);
|
|
65
|
+
u = ge() ? u : void 0, r = re(r);
|
|
66
|
+
const h = [];
|
|
67
|
+
function g(l, a) {
|
|
68
|
+
return S(this, null, function* () {
|
|
69
|
+
var K;
|
|
70
|
+
const G = a || {}, {
|
|
71
|
+
baseUrl: E,
|
|
72
|
+
fetch: C = n,
|
|
73
|
+
Request: $ = t,
|
|
74
|
+
headers: D,
|
|
75
|
+
params: A = {},
|
|
76
|
+
parseAs: q = "json",
|
|
77
|
+
querySerializer: U,
|
|
78
|
+
bodySerializer: f = s != null ? s : Ee,
|
|
79
|
+
body: d
|
|
80
|
+
} = G, v = W(G, [
|
|
81
|
+
"baseUrl",
|
|
82
|
+
"fetch",
|
|
83
|
+
"Request",
|
|
84
|
+
"headers",
|
|
85
|
+
"params",
|
|
86
|
+
"parseAs",
|
|
87
|
+
"querySerializer",
|
|
88
|
+
"bodySerializer",
|
|
89
|
+
"body"
|
|
90
|
+
]);
|
|
91
|
+
let w = r;
|
|
92
|
+
E && (w = (K = re(E)) != null ? K : r);
|
|
93
|
+
let L = typeof i == "function" ? i : ee(i);
|
|
94
|
+
U && (L = typeof U == "function" ? U : ee(y(y({}, typeof i == "object" ? i : {}), U)));
|
|
95
|
+
const J = d === void 0 ? void 0 : f(
|
|
96
|
+
d,
|
|
97
|
+
// Note: we declare mergeHeaders() both here and below because it’s a bit of a chicken-or-egg situation:
|
|
98
|
+
// bodySerializer() needs all headers so we aren’t dropping ones set by the user, however,
|
|
99
|
+
// the result of this ALSO sets the lowest-priority content-type header. So we re-merge below,
|
|
100
|
+
// setting the content-type at the very beginning to be overwritten.
|
|
101
|
+
// Lastly, based on the way headers work, it’s not a simple “present-or-not” check becauase null intentionally un-sets headers.
|
|
102
|
+
te(o, D, A.header)
|
|
103
|
+
), ue = te(
|
|
104
|
+
// with no body, we should not to set Content-Type
|
|
105
|
+
J === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
|
|
106
|
+
J instanceof FormData ? {} : {
|
|
107
|
+
"Content-Type": "application/json"
|
|
108
|
+
},
|
|
109
|
+
o,
|
|
110
|
+
D,
|
|
111
|
+
A.header
|
|
112
|
+
), fe = R(y(y({
|
|
113
|
+
redirect: "follow"
|
|
114
|
+
}, c), v), {
|
|
115
|
+
body: J,
|
|
116
|
+
headers: ue
|
|
80
117
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
118
|
+
let O, z, I = new t(
|
|
119
|
+
Ce(l, { baseUrl: w, params: A, querySerializer: L }),
|
|
120
|
+
fe
|
|
121
|
+
), m;
|
|
122
|
+
for (const p in v)
|
|
123
|
+
p in I || (I[p] = v[p]);
|
|
124
|
+
if (h.length) {
|
|
125
|
+
O = we(), z = Object.freeze({
|
|
126
|
+
baseUrl: w,
|
|
127
|
+
fetch: C,
|
|
128
|
+
parseAs: q,
|
|
129
|
+
querySerializer: L,
|
|
130
|
+
bodySerializer: f
|
|
131
|
+
});
|
|
132
|
+
for (const p of h)
|
|
133
|
+
if (p && typeof p == "object" && typeof p.onRequest == "function") {
|
|
134
|
+
const b = yield p.onRequest({
|
|
135
|
+
request: I,
|
|
136
|
+
schemaPath: l,
|
|
137
|
+
params: A,
|
|
138
|
+
options: z,
|
|
139
|
+
id: O
|
|
140
|
+
});
|
|
141
|
+
if (b)
|
|
142
|
+
if (b instanceof t)
|
|
143
|
+
I = b;
|
|
144
|
+
else if (b instanceof Response) {
|
|
145
|
+
m = b;
|
|
146
|
+
break;
|
|
147
|
+
} else
|
|
148
|
+
throw new Error("onRequest: must return new Request() or Response() when modifying the request");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!m) {
|
|
152
|
+
try {
|
|
153
|
+
m = yield C(I, u);
|
|
154
|
+
} catch (p) {
|
|
155
|
+
let b = p;
|
|
156
|
+
if (h.length)
|
|
157
|
+
for (let T = h.length - 1; T >= 0; T--) {
|
|
158
|
+
const P = h[T];
|
|
159
|
+
if (P && typeof P == "object" && typeof P.onError == "function") {
|
|
160
|
+
const H = yield P.onError({
|
|
161
|
+
request: I,
|
|
162
|
+
error: b,
|
|
163
|
+
schemaPath: l,
|
|
164
|
+
params: A,
|
|
165
|
+
options: z,
|
|
166
|
+
id: O
|
|
167
|
+
});
|
|
168
|
+
if (H) {
|
|
169
|
+
if (H instanceof Response) {
|
|
170
|
+
b = void 0, m = H;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
if (H instanceof Error) {
|
|
174
|
+
b = H;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
throw new Error("onError: must return new Response() or instance of Error");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (b)
|
|
182
|
+
throw b;
|
|
98
183
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
request: R,
|
|
111
|
-
error: h,
|
|
112
|
-
schemaPath: c,
|
|
113
|
-
params: w,
|
|
114
|
-
options: T,
|
|
115
|
-
id: U
|
|
184
|
+
if (h.length)
|
|
185
|
+
for (let p = h.length - 1; p >= 0; p--) {
|
|
186
|
+
const b = h[p];
|
|
187
|
+
if (b && typeof b == "object" && typeof b.onResponse == "function") {
|
|
188
|
+
const T = yield b.onResponse({
|
|
189
|
+
request: I,
|
|
190
|
+
response: m,
|
|
191
|
+
schemaPath: l,
|
|
192
|
+
params: A,
|
|
193
|
+
options: z,
|
|
194
|
+
id: O
|
|
116
195
|
});
|
|
117
|
-
if (
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
if (D instanceof Error) {
|
|
123
|
-
h = D;
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
throw new Error("onError: must return new Response() or instance of Error");
|
|
196
|
+
if (T) {
|
|
197
|
+
if (!(T instanceof Response))
|
|
198
|
+
throw new Error("onResponse: must return new Response() when modifying the response");
|
|
199
|
+
m = T;
|
|
127
200
|
}
|
|
128
201
|
}
|
|
129
202
|
}
|
|
130
|
-
if (h)
|
|
131
|
-
throw h;
|
|
132
203
|
}
|
|
133
|
-
if (m.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
145
|
-
if (j) {
|
|
146
|
-
if (!(j instanceof Response))
|
|
147
|
-
throw new Error("onResponse: must return new Response() when modifying the response");
|
|
148
|
-
f = j;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (f.status === 204 || R.method === "HEAD" || f.headers.get("Content-Length") === "0")
|
|
154
|
-
return f.ok ? { data: void 0, response: f } : { error: void 0, response: f };
|
|
155
|
-
if (f.ok)
|
|
156
|
-
return S === "stream" ? { data: f.body, response: f } : { data: await f[S](), response: f };
|
|
157
|
-
let F = await f.text();
|
|
158
|
-
try {
|
|
159
|
-
F = JSON.parse(F);
|
|
160
|
-
} catch {
|
|
161
|
-
}
|
|
162
|
-
return { error: F, response: f };
|
|
204
|
+
if (m.status === 204 || I.method === "HEAD" || m.headers.get("Content-Length") === "0")
|
|
205
|
+
return m.ok ? { data: void 0, response: m } : { error: void 0, response: m };
|
|
206
|
+
if (m.ok)
|
|
207
|
+
return q === "stream" ? { data: m.body, response: m } : { data: yield m[q](), response: m };
|
|
208
|
+
let _ = yield m.text();
|
|
209
|
+
try {
|
|
210
|
+
_ = JSON.parse(_);
|
|
211
|
+
} catch (p) {
|
|
212
|
+
}
|
|
213
|
+
return { error: _, response: m };
|
|
214
|
+
});
|
|
163
215
|
}
|
|
164
216
|
return {
|
|
165
|
-
request(
|
|
166
|
-
return
|
|
217
|
+
request(l, a, E) {
|
|
218
|
+
return g(a, R(y({}, E), { method: l.toUpperCase() }));
|
|
167
219
|
},
|
|
168
220
|
/** Call a GET endpoint */
|
|
169
|
-
GET(
|
|
170
|
-
return
|
|
221
|
+
GET(l, a) {
|
|
222
|
+
return g(l, R(y({}, a), { method: "GET" }));
|
|
171
223
|
},
|
|
172
224
|
/** Call a PUT endpoint */
|
|
173
|
-
PUT(
|
|
174
|
-
return
|
|
225
|
+
PUT(l, a) {
|
|
226
|
+
return g(l, R(y({}, a), { method: "PUT" }));
|
|
175
227
|
},
|
|
176
228
|
/** Call a POST endpoint */
|
|
177
|
-
POST(
|
|
178
|
-
return
|
|
229
|
+
POST(l, a) {
|
|
230
|
+
return g(l, R(y({}, a), { method: "POST" }));
|
|
179
231
|
},
|
|
180
232
|
/** Call a DELETE endpoint */
|
|
181
|
-
DELETE(
|
|
182
|
-
return
|
|
233
|
+
DELETE(l, a) {
|
|
234
|
+
return g(l, R(y({}, a), { method: "DELETE" }));
|
|
183
235
|
},
|
|
184
236
|
/** Call a OPTIONS endpoint */
|
|
185
|
-
OPTIONS(
|
|
186
|
-
return
|
|
237
|
+
OPTIONS(l, a) {
|
|
238
|
+
return g(l, R(y({}, a), { method: "OPTIONS" }));
|
|
187
239
|
},
|
|
188
240
|
/** Call a HEAD endpoint */
|
|
189
|
-
HEAD(
|
|
190
|
-
return
|
|
241
|
+
HEAD(l, a) {
|
|
242
|
+
return g(l, R(y({}, a), { method: "HEAD" }));
|
|
191
243
|
},
|
|
192
244
|
/** Call a PATCH endpoint */
|
|
193
|
-
PATCH(
|
|
194
|
-
return
|
|
245
|
+
PATCH(l, a) {
|
|
246
|
+
return g(l, R(y({}, a), { method: "PATCH" }));
|
|
195
247
|
},
|
|
196
248
|
/** Call a TRACE endpoint */
|
|
197
|
-
TRACE(
|
|
198
|
-
return
|
|
249
|
+
TRACE(l, a) {
|
|
250
|
+
return g(l, R(y({}, a), { method: "TRACE" }));
|
|
199
251
|
},
|
|
200
252
|
/** Register middleware */
|
|
201
|
-
use(...
|
|
202
|
-
for (const
|
|
203
|
-
if (
|
|
204
|
-
if (typeof
|
|
253
|
+
use(...l) {
|
|
254
|
+
for (const a of l)
|
|
255
|
+
if (a) {
|
|
256
|
+
if (typeof a != "object" || !("onRequest" in a || "onResponse" in a || "onError" in a))
|
|
205
257
|
throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
|
|
206
|
-
|
|
258
|
+
h.push(a);
|
|
207
259
|
}
|
|
208
260
|
},
|
|
209
261
|
/** Unregister middleware */
|
|
210
|
-
eject(...
|
|
211
|
-
for (const
|
|
212
|
-
const
|
|
213
|
-
|
|
262
|
+
eject(...l) {
|
|
263
|
+
for (const a of l) {
|
|
264
|
+
const E = h.indexOf(a);
|
|
265
|
+
E !== -1 && h.splice(E, 1);
|
|
214
266
|
}
|
|
215
267
|
}
|
|
216
268
|
};
|
|
217
269
|
}
|
|
218
|
-
function
|
|
270
|
+
function N(e, r, t) {
|
|
219
271
|
if (r == null)
|
|
220
272
|
return "";
|
|
221
273
|
if (typeof r == "object")
|
|
@@ -224,149 +276,151 @@ function O(e, r, t) {
|
|
|
224
276
|
);
|
|
225
277
|
return `${e}=${(t == null ? void 0 : t.allowReserved) === !0 ? r : encodeURIComponent(r)}`;
|
|
226
278
|
}
|
|
227
|
-
function
|
|
279
|
+
function ae(e, r, t) {
|
|
228
280
|
if (!r || typeof r != "object")
|
|
229
281
|
return "";
|
|
230
|
-
const
|
|
282
|
+
const n = [], i = {
|
|
231
283
|
simple: ",",
|
|
232
284
|
label: ".",
|
|
233
285
|
matrix: ";"
|
|
234
286
|
}[t.style] || "&";
|
|
235
287
|
if (t.style !== "deepObject" && t.explode === !1) {
|
|
236
288
|
for (const u in r)
|
|
237
|
-
|
|
238
|
-
const
|
|
289
|
+
n.push(u, t.allowReserved === !0 ? r[u] : encodeURIComponent(r[u]));
|
|
290
|
+
const o = n.join(",");
|
|
239
291
|
switch (t.style) {
|
|
240
292
|
case "form":
|
|
241
|
-
return `${e}=${
|
|
293
|
+
return `${e}=${o}`;
|
|
242
294
|
case "label":
|
|
243
|
-
return `.${
|
|
295
|
+
return `.${o}`;
|
|
244
296
|
case "matrix":
|
|
245
|
-
return `;${e}=${
|
|
297
|
+
return `;${e}=${o}`;
|
|
246
298
|
default:
|
|
247
|
-
return
|
|
299
|
+
return o;
|
|
248
300
|
}
|
|
249
301
|
}
|
|
250
|
-
for (const
|
|
251
|
-
const u = t.style === "deepObject" ? `${e}[${
|
|
252
|
-
|
|
302
|
+
for (const o in r) {
|
|
303
|
+
const u = t.style === "deepObject" ? `${e}[${o}]` : o;
|
|
304
|
+
n.push(N(u, r[o], t));
|
|
253
305
|
}
|
|
254
|
-
const
|
|
255
|
-
return t.style === "label" || t.style === "matrix" ? `${
|
|
306
|
+
const s = n.join(i);
|
|
307
|
+
return t.style === "label" || t.style === "matrix" ? `${i}${s}` : s;
|
|
256
308
|
}
|
|
257
|
-
function
|
|
309
|
+
function ce(e, r, t) {
|
|
258
310
|
if (!Array.isArray(r))
|
|
259
311
|
return "";
|
|
260
312
|
if (t.explode === !1) {
|
|
261
|
-
const
|
|
313
|
+
const s = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[t.style] || ",", o = (t.allowReserved === !0 ? r : r.map((u) => encodeURIComponent(u))).join(s);
|
|
262
314
|
switch (t.style) {
|
|
263
315
|
case "simple":
|
|
264
|
-
return
|
|
316
|
+
return o;
|
|
265
317
|
case "label":
|
|
266
|
-
return `.${
|
|
318
|
+
return `.${o}`;
|
|
267
319
|
case "matrix":
|
|
268
|
-
return `;${e}=${
|
|
320
|
+
return `;${e}=${o}`;
|
|
269
321
|
default:
|
|
270
|
-
return `${e}=${
|
|
322
|
+
return `${e}=${o}`;
|
|
271
323
|
}
|
|
272
324
|
}
|
|
273
|
-
const
|
|
274
|
-
for (const
|
|
275
|
-
t.style === "simple" || t.style === "label" ?
|
|
276
|
-
return t.style === "label" || t.style === "matrix" ? `${
|
|
325
|
+
const n = { simple: ",", label: ".", matrix: ";" }[t.style] || "&", i = [];
|
|
326
|
+
for (const s of r)
|
|
327
|
+
t.style === "simple" || t.style === "label" ? i.push(t.allowReserved === !0 ? s : encodeURIComponent(s)) : i.push(N(e, s, t));
|
|
328
|
+
return t.style === "label" || t.style === "matrix" ? `${n}${i.join(n)}` : i.join(n);
|
|
277
329
|
}
|
|
278
|
-
function
|
|
330
|
+
function ee(e) {
|
|
279
331
|
return function(t) {
|
|
280
|
-
const
|
|
332
|
+
const n = [];
|
|
281
333
|
if (t && typeof t == "object")
|
|
282
|
-
for (const
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
if (Array.isArray(
|
|
286
|
-
if (
|
|
334
|
+
for (const i in t) {
|
|
335
|
+
const s = t[i];
|
|
336
|
+
if (s != null) {
|
|
337
|
+
if (Array.isArray(s)) {
|
|
338
|
+
if (s.length === 0)
|
|
287
339
|
continue;
|
|
288
|
-
|
|
289
|
-
|
|
340
|
+
n.push(
|
|
341
|
+
ce(i, s, R(y({
|
|
290
342
|
style: "form",
|
|
291
|
-
explode: !0
|
|
292
|
-
|
|
343
|
+
explode: !0
|
|
344
|
+
}, e == null ? void 0 : e.array), {
|
|
293
345
|
allowReserved: (e == null ? void 0 : e.allowReserved) || !1
|
|
294
|
-
})
|
|
346
|
+
}))
|
|
295
347
|
);
|
|
296
348
|
continue;
|
|
297
349
|
}
|
|
298
|
-
if (typeof
|
|
299
|
-
|
|
300
|
-
|
|
350
|
+
if (typeof s == "object") {
|
|
351
|
+
n.push(
|
|
352
|
+
ae(i, s, R(y({
|
|
301
353
|
style: "deepObject",
|
|
302
|
-
explode: !0
|
|
303
|
-
|
|
354
|
+
explode: !0
|
|
355
|
+
}, e == null ? void 0 : e.object), {
|
|
304
356
|
allowReserved: (e == null ? void 0 : e.allowReserved) || !1
|
|
305
|
-
})
|
|
357
|
+
}))
|
|
306
358
|
);
|
|
307
359
|
continue;
|
|
308
360
|
}
|
|
309
|
-
|
|
361
|
+
n.push(N(i, s, e));
|
|
310
362
|
}
|
|
311
363
|
}
|
|
312
|
-
return
|
|
364
|
+
return n.join("&");
|
|
313
365
|
};
|
|
314
366
|
}
|
|
315
|
-
function
|
|
367
|
+
function ve(e, r) {
|
|
368
|
+
var n;
|
|
316
369
|
let t = e;
|
|
317
|
-
for (const
|
|
318
|
-
let
|
|
319
|
-
if (
|
|
370
|
+
for (const i of (n = e.match(pe)) != null ? n : []) {
|
|
371
|
+
let s = i.substring(1, i.length - 1), o = !1, u = "simple";
|
|
372
|
+
if (s.endsWith("*") && (o = !0, s = s.substring(0, s.length - 1)), s.startsWith(".") ? (u = "label", s = s.substring(1)) : s.startsWith(";") && (u = "matrix", s = s.substring(1)), !r || r[s] === void 0 || r[s] === null)
|
|
320
373
|
continue;
|
|
321
|
-
const
|
|
322
|
-
if (Array.isArray(
|
|
323
|
-
t = t.replace(
|
|
374
|
+
const c = r[s];
|
|
375
|
+
if (Array.isArray(c)) {
|
|
376
|
+
t = t.replace(i, ce(s, c, { style: u, explode: o }));
|
|
324
377
|
continue;
|
|
325
378
|
}
|
|
326
|
-
if (typeof
|
|
327
|
-
t = t.replace(
|
|
379
|
+
if (typeof c == "object") {
|
|
380
|
+
t = t.replace(i, ae(s, c, { style: u, explode: o }));
|
|
328
381
|
continue;
|
|
329
382
|
}
|
|
330
|
-
if (
|
|
331
|
-
t = t.replace(
|
|
383
|
+
if (u === "matrix") {
|
|
384
|
+
t = t.replace(i, `;${N(s, c)}`);
|
|
332
385
|
continue;
|
|
333
386
|
}
|
|
334
|
-
t = t.replace(
|
|
387
|
+
t = t.replace(i, u === "label" ? `.${encodeURIComponent(c)}` : encodeURIComponent(c));
|
|
335
388
|
}
|
|
336
389
|
return t;
|
|
337
390
|
}
|
|
338
|
-
function
|
|
339
|
-
|
|
391
|
+
function Ee(e, r) {
|
|
392
|
+
var t, n;
|
|
393
|
+
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);
|
|
340
394
|
}
|
|
341
|
-
function
|
|
342
|
-
var
|
|
395
|
+
function Ce(e, r) {
|
|
396
|
+
var i, s;
|
|
343
397
|
let t = `${r.baseUrl}${e}`;
|
|
344
|
-
(
|
|
345
|
-
let
|
|
346
|
-
return
|
|
398
|
+
(i = r.params) != null && i.path && (t = ve(t, r.params.path));
|
|
399
|
+
let n = r.querySerializer((s = r.params.query) != null ? s : {});
|
|
400
|
+
return n.startsWith("?") && (n = n.substring(1)), n && (t += `?${n}`), t;
|
|
347
401
|
}
|
|
348
|
-
function
|
|
402
|
+
function te(...e) {
|
|
349
403
|
const r = new Headers();
|
|
350
404
|
for (const t of e) {
|
|
351
405
|
if (!t || typeof t != "object")
|
|
352
406
|
continue;
|
|
353
|
-
const
|
|
354
|
-
for (const [
|
|
355
|
-
if (
|
|
356
|
-
r.delete(
|
|
357
|
-
else if (Array.isArray(
|
|
358
|
-
for (const
|
|
359
|
-
r.append(
|
|
360
|
-
else
|
|
407
|
+
const n = t instanceof Headers ? t.entries() : Object.entries(t);
|
|
408
|
+
for (const [i, s] of n)
|
|
409
|
+
if (s === null)
|
|
410
|
+
r.delete(i);
|
|
411
|
+
else if (Array.isArray(s))
|
|
412
|
+
for (const o of s)
|
|
413
|
+
r.append(i, o);
|
|
414
|
+
else s !== void 0 && r.set(i, s);
|
|
361
415
|
}
|
|
362
416
|
return r;
|
|
363
417
|
}
|
|
364
|
-
function
|
|
418
|
+
function re(e) {
|
|
365
419
|
return e.endsWith("/") ? e.substring(0, e.length - 1) : e;
|
|
366
420
|
}
|
|
367
|
-
const
|
|
421
|
+
const Ae = {
|
|
368
422
|
baseUrl: "http://localhost:3200"
|
|
369
|
-
},
|
|
423
|
+
}, je = {
|
|
370
424
|
development: {
|
|
371
425
|
baseUrl: "http://localhost:3200"
|
|
372
426
|
},
|
|
@@ -378,152 +432,156 @@ const ue = {
|
|
|
378
432
|
// baseUrl: import.meta.env.VITE_API_BASE_URL || "https://api.dismissible.io",
|
|
379
433
|
baseUrl: "https://api.dismissible.io"
|
|
380
434
|
}
|
|
381
|
-
},
|
|
435
|
+
}, Ie = () => je["production"] || Ae, ne = (e, r, t) => {
|
|
382
436
|
try {
|
|
383
|
-
const
|
|
384
|
-
if (!
|
|
385
|
-
const { data:
|
|
386
|
-
return t && Date.now() -
|
|
387
|
-
} catch {
|
|
437
|
+
const n = `${r}_${e}`, i = localStorage.getItem(n);
|
|
438
|
+
if (!i) return null;
|
|
439
|
+
const { data: s, timestamp: o } = JSON.parse(i);
|
|
440
|
+
return t && Date.now() - o > t ? (localStorage.removeItem(n), null) : s;
|
|
441
|
+
} catch (n) {
|
|
388
442
|
return null;
|
|
389
443
|
}
|
|
390
|
-
},
|
|
444
|
+
}, se = (e, r, t) => {
|
|
391
445
|
try {
|
|
392
|
-
const
|
|
446
|
+
const n = `${t}_${e}`, i = {
|
|
393
447
|
data: r,
|
|
394
448
|
timestamp: Date.now()
|
|
395
449
|
};
|
|
396
|
-
localStorage.setItem(
|
|
397
|
-
} catch (
|
|
398
|
-
console.warn("Failed to cache dismissible item:",
|
|
450
|
+
localStorage.setItem(n, JSON.stringify(i));
|
|
451
|
+
} catch (n) {
|
|
452
|
+
console.warn("Failed to cache dismissible item:", n);
|
|
399
453
|
}
|
|
400
|
-
},
|
|
454
|
+
}, ie = (e, r) => {
|
|
401
455
|
try {
|
|
402
456
|
const t = `${r}_${e}`;
|
|
403
457
|
localStorage.removeItem(t);
|
|
404
458
|
} catch (t) {
|
|
405
459
|
console.warn("Failed to remove cached dismissible item:", t);
|
|
406
460
|
}
|
|
407
|
-
},
|
|
461
|
+
}, le = ye(
|
|
408
462
|
null
|
|
409
|
-
),
|
|
463
|
+
), Se = () => be(le), $e = "dismissible", De = (e, r = {}) => {
|
|
464
|
+
var U;
|
|
410
465
|
const {
|
|
411
466
|
initialData: t,
|
|
412
|
-
enableCache:
|
|
413
|
-
cachePrefix:
|
|
414
|
-
cacheExpiration:
|
|
415
|
-
} = r,
|
|
416
|
-
const
|
|
417
|
-
return
|
|
418
|
-
baseUrl:
|
|
419
|
-
headers: {
|
|
420
|
-
...$
|
|
421
|
-
}
|
|
467
|
+
enableCache: n = !0,
|
|
468
|
+
cachePrefix: i = $e,
|
|
469
|
+
cacheExpiration: s
|
|
470
|
+
} = r, o = Se(), u = B(() => {
|
|
471
|
+
const f = Ie(), d = (o == null ? void 0 : o.baseUrl) || f.baseUrl;
|
|
472
|
+
return Re({
|
|
473
|
+
baseUrl: d,
|
|
474
|
+
headers: {}
|
|
422
475
|
});
|
|
423
|
-
}, [
|
|
424
|
-
enableCache:
|
|
425
|
-
cachePrefix:
|
|
426
|
-
cacheExpiration:
|
|
427
|
-
}),
|
|
476
|
+
}, [o]), c = B(() => !!(o != null && o.jwt) ? `${e}-auth` : e, [e, o == null ? void 0 : o.jwt]), h = M({
|
|
477
|
+
enableCache: n,
|
|
478
|
+
cachePrefix: i,
|
|
479
|
+
cacheExpiration: s
|
|
480
|
+
}), g = M(e), j = M(c), [l, a] = F(!1), [E, C] = F(null), [$, D] = F(() => {
|
|
428
481
|
if (t) return t;
|
|
429
|
-
if (
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
482
|
+
if (n) {
|
|
483
|
+
const f = ne(
|
|
484
|
+
c,
|
|
485
|
+
i,
|
|
486
|
+
s
|
|
434
487
|
);
|
|
435
|
-
if (
|
|
488
|
+
if (f) return f;
|
|
436
489
|
}
|
|
437
|
-
}),
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
490
|
+
}), A = Y(() => S(void 0, null, function* () {
|
|
491
|
+
var f;
|
|
492
|
+
if (n) {
|
|
493
|
+
const d = ne(
|
|
494
|
+
c,
|
|
495
|
+
i,
|
|
496
|
+
s
|
|
443
497
|
);
|
|
444
|
-
if (
|
|
445
|
-
|
|
498
|
+
if (d != null && d.dismissedAt) {
|
|
499
|
+
D(d), a(!1);
|
|
446
500
|
return;
|
|
447
501
|
}
|
|
448
502
|
}
|
|
449
|
-
|
|
503
|
+
a(!0), C(null);
|
|
450
504
|
try {
|
|
451
|
-
const { data:
|
|
505
|
+
const d = o != null && o.getAuthHeaders ? yield o.getAuthHeaders() : {}, { data: v, error: w } = yield u.GET(
|
|
452
506
|
"/v1/dismissible/{itemId}",
|
|
453
507
|
{
|
|
454
508
|
params: {
|
|
455
509
|
path: {
|
|
456
510
|
itemId: e
|
|
457
511
|
}
|
|
458
|
-
}
|
|
512
|
+
},
|
|
513
|
+
headers: d
|
|
459
514
|
}
|
|
460
515
|
);
|
|
461
|
-
if (
|
|
516
|
+
if (w)
|
|
462
517
|
throw new Error(
|
|
463
|
-
|
|
518
|
+
((f = w == null ? void 0 : w.error) == null ? void 0 : f.message) || "Failed to fetch dismissible item"
|
|
464
519
|
);
|
|
465
|
-
|
|
466
|
-
} catch (
|
|
467
|
-
|
|
468
|
-
|
|
520
|
+
D(v.data), n && v.data && se(c, v.data, i);
|
|
521
|
+
} catch (d) {
|
|
522
|
+
C(
|
|
523
|
+
d instanceof Error ? d : new Error("Unknown error occurred")
|
|
469
524
|
);
|
|
470
525
|
} finally {
|
|
471
|
-
|
|
526
|
+
a(!1);
|
|
472
527
|
}
|
|
473
|
-
}, [
|
|
528
|
+
}), [
|
|
474
529
|
e,
|
|
475
|
-
|
|
476
|
-
s,
|
|
530
|
+
c,
|
|
477
531
|
n,
|
|
478
|
-
|
|
479
|
-
|
|
532
|
+
i,
|
|
533
|
+
s,
|
|
534
|
+
u,
|
|
535
|
+
o
|
|
480
536
|
]);
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
}, [e,
|
|
485
|
-
const
|
|
486
|
-
(
|
|
487
|
-
enableCache:
|
|
488
|
-
cachePrefix:
|
|
489
|
-
cacheExpiration:
|
|
490
|
-
},
|
|
491
|
-
}, [
|
|
492
|
-
const
|
|
493
|
-
|
|
537
|
+
Z(() => {
|
|
538
|
+
const f = g.current !== e, d = j.current !== c;
|
|
539
|
+
f || d ? (g.current = e, j.current = c, A()) : t || A();
|
|
540
|
+
}, [e, c, t]), Z(() => {
|
|
541
|
+
const f = h.current;
|
|
542
|
+
(f.enableCache !== n || f.cachePrefix !== i || f.cacheExpiration !== s) && (f.cachePrefix !== i && ie(c, f.cachePrefix), !n && f.enableCache && ie(c, i), h.current = {
|
|
543
|
+
enableCache: n,
|
|
544
|
+
cachePrefix: i,
|
|
545
|
+
cacheExpiration: s
|
|
546
|
+
}, A());
|
|
547
|
+
}, [n, i, s, c]);
|
|
548
|
+
const q = Y(() => S(void 0, null, function* () {
|
|
549
|
+
var f;
|
|
550
|
+
C(null);
|
|
494
551
|
try {
|
|
495
|
-
const { data:
|
|
552
|
+
const d = o != null && o.getAuthHeaders ? yield o.getAuthHeaders() : {}, { data: v, error: w } = yield u.DELETE(
|
|
496
553
|
"/v1/dismissible/{itemId}",
|
|
497
554
|
{
|
|
498
555
|
params: {
|
|
499
556
|
path: {
|
|
500
557
|
itemId: e
|
|
501
558
|
}
|
|
502
|
-
}
|
|
559
|
+
},
|
|
560
|
+
headers: d
|
|
503
561
|
}
|
|
504
562
|
);
|
|
505
|
-
if (
|
|
506
|
-
throw new Error(
|
|
507
|
-
|
|
508
|
-
} catch (
|
|
509
|
-
throw
|
|
510
|
-
|
|
511
|
-
),
|
|
563
|
+
if (w)
|
|
564
|
+
throw new Error(((f = w == null ? void 0 : w.error) == null ? void 0 : f.message) || "Failed to dismiss item");
|
|
565
|
+
D(v.data), n && v.data && se(c, v.data, i);
|
|
566
|
+
} catch (d) {
|
|
567
|
+
throw C(
|
|
568
|
+
d instanceof Error ? d : new Error("Failed to dismiss item")
|
|
569
|
+
), d;
|
|
512
570
|
}
|
|
513
|
-
}, [
|
|
571
|
+
}), [c, n, i, u, o]);
|
|
514
572
|
return {
|
|
515
|
-
dismissedOn: (
|
|
516
|
-
dismiss:
|
|
573
|
+
dismissedOn: (U = $ == null ? void 0 : $.dismissedAt) != null ? U : null,
|
|
574
|
+
dismiss: q,
|
|
517
575
|
isLoading: l,
|
|
518
576
|
error: E,
|
|
519
|
-
item:
|
|
577
|
+
item: $
|
|
520
578
|
};
|
|
521
|
-
},
|
|
579
|
+
}, Ue = () => /* @__PURE__ */ x("div", { className: "dismissible-loading", "aria-live": "polite", children: "Loading..." }), Te = ({
|
|
522
580
|
error: e
|
|
523
|
-
}) => /* @__PURE__ */
|
|
581
|
+
}) => /* @__PURE__ */ oe("div", { className: "dismissible-error", role: "alert", children: [
|
|
524
582
|
"Error loading dismissible item: ",
|
|
525
583
|
e.message
|
|
526
|
-
] }),
|
|
584
|
+
] }), xe = ({ id: e, onDismiss: r, ariaLabel: t }) => /* @__PURE__ */ x(
|
|
527
585
|
"button",
|
|
528
586
|
{
|
|
529
587
|
id: e,
|
|
@@ -533,78 +591,82 @@ const ue = {
|
|
|
533
591
|
type: "button",
|
|
534
592
|
children: "×"
|
|
535
593
|
}
|
|
536
|
-
),
|
|
594
|
+
), ke = ({
|
|
537
595
|
id: e,
|
|
538
596
|
children: r,
|
|
539
597
|
onDismiss: t,
|
|
540
|
-
LoadingComponent:
|
|
541
|
-
ErrorComponent:
|
|
542
|
-
DismissButtonComponent:
|
|
543
|
-
enableCache:
|
|
598
|
+
LoadingComponent: n = Ue,
|
|
599
|
+
ErrorComponent: i = Te,
|
|
600
|
+
DismissButtonComponent: s = xe,
|
|
601
|
+
enableCache: o,
|
|
544
602
|
cachePrefix: u,
|
|
545
|
-
cacheExpiration:
|
|
603
|
+
cacheExpiration: c,
|
|
604
|
+
ignoreErrors: h = !1
|
|
546
605
|
}) => {
|
|
547
|
-
const { dismissedOn:
|
|
548
|
-
enableCache:
|
|
606
|
+
const { dismissedOn: g, isLoading: j, error: l, dismiss: a } = De(e, {
|
|
607
|
+
enableCache: o,
|
|
549
608
|
cachePrefix: u,
|
|
550
|
-
cacheExpiration:
|
|
551
|
-
}), [
|
|
552
|
-
|
|
609
|
+
cacheExpiration: c
|
|
610
|
+
}), [E, C] = F(!1), $ = () => S(void 0, null, function* () {
|
|
611
|
+
C(!0);
|
|
553
612
|
try {
|
|
554
|
-
|
|
555
|
-
} catch {
|
|
556
|
-
|
|
613
|
+
yield a(), t == null || t();
|
|
614
|
+
} catch (D) {
|
|
615
|
+
C(!1);
|
|
557
616
|
}
|
|
558
|
-
};
|
|
559
|
-
return
|
|
560
|
-
/* @__PURE__ */
|
|
561
|
-
|
|
562
|
-
|
|
617
|
+
});
|
|
618
|
+
return j && n ? /* @__PURE__ */ x(n, { id: e }) : j && !n ? null : l && i && !h ? /* @__PURE__ */ x(i, { id: e, error: l }) : g || E ? null : /* @__PURE__ */ oe("div", { className: "dismissible-container", children: [
|
|
619
|
+
/* @__PURE__ */ x("div", { className: "dismissible-content", children: r }),
|
|
620
|
+
s ? /* @__PURE__ */ x(
|
|
621
|
+
s,
|
|
563
622
|
{
|
|
564
623
|
id: e,
|
|
565
|
-
onDismiss:
|
|
624
|
+
onDismiss: $,
|
|
566
625
|
ariaLabel: `Dismiss ${e}`
|
|
567
626
|
}
|
|
568
627
|
) : null
|
|
569
628
|
] });
|
|
570
|
-
},
|
|
629
|
+
}, qe = (e) => S(void 0, null, function* () {
|
|
571
630
|
if (typeof e == "function")
|
|
572
631
|
try {
|
|
573
|
-
|
|
632
|
+
const r = e();
|
|
633
|
+
return yield Promise.resolve(r);
|
|
574
634
|
} catch (r) {
|
|
575
635
|
console.warn("Failed to resolve JWT from function:", r);
|
|
576
636
|
return;
|
|
577
637
|
}
|
|
578
638
|
return e;
|
|
579
|
-
},
|
|
580
|
-
const r =
|
|
639
|
+
}), He = (e) => S(void 0, null, function* () {
|
|
640
|
+
const r = yield qe(e);
|
|
581
641
|
return r ? { Authorization: `Bearer ${r}` } : {};
|
|
582
|
-
},
|
|
642
|
+
}), Fe = (e) => {
|
|
583
643
|
const r = e.split(".");
|
|
584
644
|
return r.length === 3 && r.every((t) => t.length > 0);
|
|
585
|
-
},
|
|
645
|
+
}, Ne = ({
|
|
586
646
|
jwt: e,
|
|
587
647
|
baseUrl: r,
|
|
588
648
|
children: t
|
|
589
649
|
}) => {
|
|
590
|
-
const
|
|
650
|
+
const n = B(
|
|
591
651
|
() => ({
|
|
592
652
|
jwt: e,
|
|
593
653
|
baseUrl: r,
|
|
594
|
-
getAuthHeaders: () =>
|
|
654
|
+
getAuthHeaders: () => S(void 0, null, function* () {
|
|
655
|
+
return yield He(e);
|
|
656
|
+
})
|
|
595
657
|
}),
|
|
596
658
|
[e, r]
|
|
597
659
|
);
|
|
598
|
-
return /* @__PURE__ */
|
|
599
|
-
},
|
|
660
|
+
return /* @__PURE__ */ x(le.Provider, { value: n, children: t });
|
|
661
|
+
}, Le = "0.3.0";
|
|
600
662
|
export {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
663
|
+
ke as Dismissible,
|
|
664
|
+
le as DismissibleContext,
|
|
665
|
+
Ne as DismissibleProvider,
|
|
666
|
+
Le as VERSION,
|
|
667
|
+
He as getAuthHeaders,
|
|
668
|
+
Fe as isValidJwtFormat,
|
|
669
|
+
qe as resolveJwt,
|
|
670
|
+
Se as useDismissibleContext,
|
|
671
|
+
De as useDismissibleItem
|
|
610
672
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(m,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],w):(m=typeof globalThis<"u"?globalThis:m||self,w(m.DismissibleClient={},m.React.jsxRuntime,m.React))})(this,function(m,w,h){"use strict";const Z=/\{[^{}]+\}/g,ee=()=>{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 te(){return Math.random().toString(36).slice(2,11)}function re(e){let{baseUrl:r="",Request:t=globalThis.Request,fetch:n=globalThis.fetch,querySerializer:s,bodySerializer:o,headers:i,requestInitExt:u=void 0,...d}={...e};u=ee()?u:void 0,r=B(r);const b=[];async function p(l,c){const{baseUrl:v,fetch:S=n,Request:j=t,headers:I,params:C={},parseAs:D="json",querySerializer:$,bodySerializer:a=o??ne,body:E,...T}=c||{};let P=r;v&&(P=B(v)??r);let k=typeof s=="function"?s:M(s);$&&(k=typeof $=="function"?$:M({...typeof s=="object"?s:{},...$}));const F=E===void 0?void 0:a(E,_(i,I,C.header)),pe=_(F===void 0||F instanceof FormData?{}:{"Content-Type":"application/json"},i,I,C.header),ge={redirect:"follow",...d,...T,body:F,headers:pe};let O,x,R=new t(ie(l,{baseUrl:P,params:C,querySerializer:k}),ge),f;for(const g in T)g in R||(R[g]=T[g]);if(b.length){O=te(),x=Object.freeze({baseUrl:P,fetch:S,parseAs:D,querySerializer:k,bodySerializer:a});for(const g of b)if(g&&typeof g=="object"&&typeof g.onRequest=="function"){const y=await g.onRequest({request:R,schemaPath:l,params:C,options:x,id:O});if(y)if(y instanceof t)R=y;else if(y instanceof Response){f=y;break}else throw new Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!f){try{f=await S(R,u)}catch(g){let y=g;if(b.length)for(let A=b.length-1;A>=0;A--){const z=b[A];if(z&&typeof z=="object"&&typeof z.onError=="function"){const U=await z.onError({request:R,error:y,schemaPath:l,params:C,options:x,id:O});if(U){if(U instanceof Response){y=void 0,f=U;break}if(U instanceof Error){y=U;continue}throw new Error("onError: must return new Response() or instance of Error")}}}if(y)throw y}if(b.length)for(let g=b.length-1;g>=0;g--){const y=b[g];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){const A=await y.onResponse({request:R,response:f,schemaPath:l,params:C,options:x,id:O});if(A){if(!(A instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");f=A}}}}if(f.status===204||R.method==="HEAD"||f.headers.get("Content-Length")==="0")return f.ok?{data:void 0,response:f}:{error:void 0,response:f};if(f.ok)return D==="stream"?{data:f.body,response:f}:{data:await f[D](),response:f};let N=await f.text();try{N=JSON.parse(N)}catch{}return{error:N,response:f}}return{request(l,c,v){return p(c,{...v,method:l.toUpperCase()})},GET(l,c){return p(l,{...c,method:"GET"})},PUT(l,c){return p(l,{...c,method:"PUT"})},POST(l,c){return p(l,{...c,method:"POST"})},DELETE(l,c){return p(l,{...c,method:"DELETE"})},OPTIONS(l,c){return p(l,{...c,method:"OPTIONS"})},HEAD(l,c){return p(l,{...c,method:"HEAD"})},PATCH(l,c){return p(l,{...c,method:"PATCH"})},TRACE(l,c){return p(l,{...c,method:"TRACE"})},use(...l){for(const c of l)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()`");b.push(c)}},eject(...l){for(const c of l){const v=b.indexOf(c);v!==-1&&b.splice(v,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 L(e,r,t){if(!r||typeof r!="object")return"";const n=[],s={simple:",",label:".",matrix:";"}[t.style]||"&";if(t.style!=="deepObject"&&t.explode===!1){for(const u in r)n.push(u,t.allowReserved===!0?r[u]:encodeURIComponent(r[u]));const i=n.join(",");switch(t.style){case"form":return`${e}=${i}`;case"label":return`.${i}`;case"matrix":return`;${e}=${i}`;default:return i}}for(const i in r){const u=t.style==="deepObject"?`${e}[${i}]`:i;n.push(q(u,r[i],t))}const o=n.join(s);return t.style==="label"||t.style==="matrix"?`${s}${o}`:o}function J(e,r,t){if(!Array.isArray(r))return"";if(t.explode===!1){const o={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",i=(t.allowReserved===!0?r:r.map(u=>encodeURIComponent(u))).join(o);switch(t.style){case"simple":return i;case"label":return`.${i}`;case"matrix":return`;${e}=${i}`;default:return`${e}=${i}`}}const n={simple:",",label:".",matrix:";"}[t.style]||"&",s=[];for(const o of r)t.style==="simple"||t.style==="label"?s.push(t.allowReserved===!0?o:encodeURIComponent(o)):s.push(q(e,o,t));return t.style==="label"||t.style==="matrix"?`${n}${s.join(n)}`:s.join(n)}function M(e){return function(t){const n=[];if(t&&typeof t=="object")for(const s in t){const o=t[s];if(o!=null){if(Array.isArray(o)){if(o.length===0)continue;n.push(J(s,o,{style:"form",explode:!0,...e==null?void 0:e.array,allowReserved:(e==null?void 0:e.allowReserved)||!1}));continue}if(typeof o=="object"){n.push(L(s,o,{style:"deepObject",explode:!0,...e==null?void 0:e.object,allowReserved:(e==null?void 0:e.allowReserved)||!1}));continue}n.push(q(s,o,e))}}return n.join("&")}}function se(e,r){let t=e;for(const n of e.match(Z)??[]){let s=n.substring(1,n.length-1),o=!1,i="simple";if(s.endsWith("*")&&(o=!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)continue;const u=r[s];if(Array.isArray(u)){t=t.replace(n,J(s,u,{style:i,explode:o}));continue}if(typeof u=="object"){t=t.replace(n,L(s,u,{style:i,explode:o}));continue}if(i==="matrix"){t=t.replace(n,`;${q(s,u)}`);continue}t=t.replace(n,i==="label"?`.${encodeURIComponent(u)}`:encodeURIComponent(u))}return t}function ne(e,r){return e instanceof FormData?e:r&&(r.get instanceof Function?r.get("Content-Type")??r.get("content-type"):r["Content-Type"]??r["content-type"])==="application/x-www-form-urlencoded"?new URLSearchParams(e).toString():JSON.stringify(e)}function ie(e,r){var s;let t=`${r.baseUrl}${e}`;(s=r.params)!=null&&s.path&&(t=se(t,r.params.path));let n=r.querySerializer(r.params.query??{});return n.startsWith("?")&&(n=n.substring(1)),n&&(t+=`?${n}`),t}function _(...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[s,o]of n)if(o===null)r.delete(s);else if(Array.isArray(o))for(const i of o)r.append(s,i);else o!==void 0&&r.set(s,o)}return r}function B(e){return e.endsWith("/")?e.substring(0,e.length-1):e}const oe={baseUrl:"http://localhost:3200"},ae={development:{baseUrl:"http://localhost:3200"},staging:{baseUrl:"https://api.staging.dismissible.io"},production:{baseUrl:"https://api.dismissible.io"}},le=()=>ae["production"]||oe,W=(e,r,t)=>{try{const n=`${r}_${e}`,s=localStorage.getItem(n);if(!s)return null;const{data:o,timestamp:i}=JSON.parse(s);return t&&Date.now()-i>t?(localStorage.removeItem(n),null):o}catch{return null}},V=(e,r,t)=>{try{const n=`${t}_${e}`,s={data:r,timestamp:Date.now()};localStorage.setItem(n,JSON.stringify(s))}catch(n){console.warn("Failed to cache dismissible item:",n)}},G=(e,r)=>{try{const t=`${r}_${e}`;localStorage.removeItem(t)}catch(t){console.warn("Failed to remove cached dismissible item:",t)}},H=h.createContext(null),K=()=>h.useContext(H),ce="dismissible",Q=(e,r={})=>{const{initialData:t,enableCache:n=!0,cachePrefix:s=ce,cacheExpiration:o}=r,i=K(),u=h.useMemo(()=>{const a=le(),E=(i==null?void 0:i.baseUrl)||a.baseUrl,T=(i==null?void 0:i.getAuthHeaders())||{};return re({baseUrl:E,headers:{...T}})},[i]),d=h.useMemo(()=>!!(i!=null&&i.jwt)?`${e}-auth`:e,[e,i==null?void 0:i.jwt]),b=h.useRef({enableCache:n,cachePrefix:s,cacheExpiration:o}),p=h.useRef(e),l=h.useRef(d),[c,v]=h.useState(!1),[S,j]=h.useState(null),[I,C]=h.useState(()=>{if(t)return t;if(n){const a=W(d,s,o);if(a)return a}}),D=h.useCallback(async()=>{if(n){const a=W(d,s,o);if(a!=null&&a.dismissedAt){C(a),v(!1);return}}v(!0),j(null);try{const{data:a,error:E}=await u.GET("/v1/dismissible/{itemId}",{params:{path:{itemId:e}}});if(E)throw new Error(E.error.message||"Failed to fetch dismissible item");C(a.data),n&&a.data&&V(d,a.data,s)}catch(a){j(a instanceof Error?a:new Error("Unknown error occurred"))}finally{v(!1)}},[e,d,n,s,o,u]);h.useEffect(()=>{const a=p.current!==e,E=l.current!==d;a||E?(p.current=e,l.current=d,D()):t||D()},[e,d,t]),h.useEffect(()=>{const a=b.current;(a.enableCache!==n||a.cachePrefix!==s||a.cacheExpiration!==o)&&(a.cachePrefix!==s&&G(d,a.cachePrefix),!n&&a.enableCache&&G(d,s),b.current={enableCache:n,cachePrefix:s,cacheExpiration:o},D())},[n,s,o,d]);const $=h.useCallback(async()=>{j(null);try{const{data:a,error:E}=await u.DELETE("/v1/dismissible/{itemId}",{params:{path:{itemId:e}}});if(E)throw new Error(E.error.message||"Failed to dismiss item");C(a.data),n&&a.data&&V(d,a.data,s)}catch(a){throw j(a instanceof Error?a:new Error("Failed to dismiss item")),a}},[d,n,s,u]);return{dismissedOn:(I==null?void 0:I.dismissedAt)??null,dismiss:$,isLoading:c,error:S,item:I}},ue=()=>w.jsx("div",{className:"dismissible-loading","aria-live":"polite",children:"Loading..."}),fe=({error:e})=>w.jsxs("div",{className:"dismissible-error",role:"alert",children:["Error loading dismissible item: ",e.message]}),de=({id:e,onDismiss:r,ariaLabel:t})=>w.jsx("button",{id:e,className:"dismissible-button",onClick:r,"aria-label":t,type:"button",children:"×"}),me=({id:e,children:r,onDismiss:t,LoadingComponent:n=ue,ErrorComponent:s=fe,DismissButtonComponent:o=de,enableCache:i,cachePrefix:u,cacheExpiration:d})=>{const{dismissedOn:b,isLoading:p,error:l,dismiss:c}=Q(e,{enableCache:i,cachePrefix:u,cacheExpiration:d}),[v,S]=h.useState(!1),j=async()=>{S(!0);try{await c(),t==null||t()}catch{S(!1)}};return p&&n?w.jsx(n,{id:e}):p&&!n?null:l&&s?w.jsx(s,{id:e,error:l}):b||v?null:w.jsxs("div",{className:"dismissible-container",children:[w.jsx("div",{className:"dismissible-content",children:r}),o?w.jsx(o,{id:e,onDismiss:j,ariaLabel:`Dismiss ${e}`}):null]})},X=e=>{if(typeof e=="function")try{return e()}catch(r){console.warn("Failed to resolve JWT from function:",r);return}return e},Y=e=>{const r=X(e);return r?{Authorization:`Bearer ${r}`}:{}},he=e=>{const r=e.split(".");return r.length===3&&r.every(t=>t.length>0)},be=({jwt:e,baseUrl:r,children:t})=>{const n=h.useMemo(()=>({jwt:e,baseUrl:r,getAuthHeaders:()=>Y(e)}),[e,r]);return w.jsx(H.Provider,{value:n,children:t})},ye="0.1.0";m.Dismissible=me,m.DismissibleContext=H,m.DismissibleProvider=be,m.VERSION=ye,m.getAuthHeaders=Y,m.isValidJwtFormat=he,m.resolveJwt=X,m.useDismissibleContext=K,m.useDismissibleItem=Q,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
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"})});
|
package/dist/root.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* TypeScript types for the Dismissible Provider system
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* JWT token can be either a static string
|
|
5
|
+
* JWT token can be either a static string, a function that returns a string, or an async function that returns a string
|
|
6
6
|
*/
|
|
7
|
-
export type JwtToken = string | (() => string);
|
|
7
|
+
export type JwtToken = string | (() => string) | (() => Promise<string>);
|
|
8
8
|
/**
|
|
9
9
|
* Configuration options for the DismissibleProvider
|
|
10
10
|
*/
|
|
@@ -25,7 +25,7 @@ export interface DismissibleContextValue {
|
|
|
25
25
|
/** Base URL for API requests */
|
|
26
26
|
baseUrl?: string;
|
|
27
27
|
/** Helper function to get authentication headers */
|
|
28
|
-
getAuthHeaders: () => AuthHeaders
|
|
28
|
+
getAuthHeaders: () => Promise<AuthHeaders>;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Authentication headers type
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { JwtToken, AuthHeaders } from '../types/dismissible.types';
|
|
2
2
|
/**
|
|
3
|
-
* Resolves a JWT token from either a static string or
|
|
4
|
-
* @param jwt - The JWT token (string or function)
|
|
5
|
-
* @returns
|
|
3
|
+
* Resolves a JWT token from either a static string, sync function, or async function
|
|
4
|
+
* @param jwt - The JWT token (string, sync function, or async function)
|
|
5
|
+
* @returns Promise that resolves to the JWT token or undefined
|
|
6
6
|
*/
|
|
7
|
-
export declare const resolveJwt: (jwt: JwtToken | undefined) => string | undefined
|
|
7
|
+
export declare const resolveJwt: (jwt: JwtToken | undefined) => Promise<string | undefined>;
|
|
8
8
|
/**
|
|
9
9
|
* Creates authentication headers from a JWT token
|
|
10
|
-
* @param jwt - The JWT token (string or function)
|
|
11
|
-
* @returns
|
|
10
|
+
* @param jwt - The JWT token (string, sync function, or async function)
|
|
11
|
+
* @returns Promise that resolves to headers object with Authorization header if JWT is available
|
|
12
12
|
*/
|
|
13
|
-
export declare const getAuthHeaders: (jwt?: JwtToken) => AuthHeaders
|
|
13
|
+
export declare const getAuthHeaders: (jwt?: JwtToken) => Promise<AuthHeaders>;
|
|
14
14
|
/**
|
|
15
15
|
* Validates that a JWT token is properly formatted
|
|
16
16
|
* @param token - The JWT token to validate
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dismissible/react-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -39,17 +39,21 @@
|
|
|
39
39
|
"react-dom": ">=18.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
+
"@babel/core": "^7.28.0",
|
|
43
|
+
"@babel/preset-env": "^7.28.0",
|
|
44
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
42
45
|
"@storybook/addon-a11y": "^9.0.15",
|
|
43
46
|
"@storybook/addon-docs": "^9.0.15",
|
|
44
47
|
"@storybook/react-vite": "^9.0.15",
|
|
45
48
|
"@testing-library/jest-dom": "^6.6.3",
|
|
46
49
|
"@testing-library/react": "^16.3.0",
|
|
47
50
|
"@types/node": "^24.0.10",
|
|
48
|
-
"@types/react": "^
|
|
49
|
-
"@types/react-dom": "^
|
|
51
|
+
"@types/react": "^18.3.23",
|
|
52
|
+
"@types/react-dom": "^18.3.7",
|
|
50
53
|
"@typescript-eslint/eslint-plugin": "^8.36.0",
|
|
51
54
|
"@typescript-eslint/parser": "^8.36.0",
|
|
52
55
|
"@vitejs/plugin-react": "^4.0.3",
|
|
56
|
+
"core-js": "^3.44.0",
|
|
53
57
|
"eslint": "^8.45.0",
|
|
54
58
|
"eslint-plugin-react": "^7.37.5",
|
|
55
59
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
@@ -59,8 +63,8 @@
|
|
|
59
63
|
"msw-storybook-addon": "^2.0.5",
|
|
60
64
|
"openapi-typescript": "^7.8.0",
|
|
61
65
|
"prettier": "^3.0.0",
|
|
62
|
-
"react": "^
|
|
63
|
-
"react-dom": "^
|
|
66
|
+
"react": "^18.3.1",
|
|
67
|
+
"react-dom": "^18.3.1",
|
|
64
68
|
"storybook": "^9.0.15",
|
|
65
69
|
"ts-node": "^10.9.2",
|
|
66
70
|
"typescript": "^5.8.3",
|