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