@dismissible/react-client 2.1.0-canary.6.0a7a428 → 2.1.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.
|
@@ -1,287 +1,291 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var e in
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var e of
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var
|
|
1
|
+
var he = Object.defineProperty, me = Object.defineProperties;
|
|
2
|
+
var ye = Object.getOwnPropertyDescriptors;
|
|
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]);
|
|
11
|
+
return t;
|
|
12
|
+
}, R = (t, r) => me(t, ye(r));
|
|
13
|
+
var G = (t, r) => {
|
|
14
14
|
var e = {};
|
|
15
|
-
for (var
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
for (var
|
|
19
|
-
|
|
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
20
|
return e;
|
|
21
21
|
};
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var s = (u) => {
|
|
22
|
+
var C = (t, r, e) => new Promise((s, o) => {
|
|
23
|
+
var n = (f) => {
|
|
25
24
|
try {
|
|
26
|
-
a(e.next(
|
|
27
|
-
} catch (
|
|
28
|
-
|
|
25
|
+
a(e.next(f));
|
|
26
|
+
} catch (m) {
|
|
27
|
+
o(m);
|
|
29
28
|
}
|
|
30
|
-
},
|
|
29
|
+
}, i = (f) => {
|
|
31
30
|
try {
|
|
32
|
-
a(e.throw(
|
|
33
|
-
} catch (
|
|
34
|
-
|
|
31
|
+
a(e.throw(f));
|
|
32
|
+
} catch (m) {
|
|
33
|
+
o(m);
|
|
35
34
|
}
|
|
36
|
-
}, a = (
|
|
37
|
-
a((e = e.apply(
|
|
35
|
+
}, a = (f) => f.done ? s(f.value) : Promise.resolve(f.value).then(n, i);
|
|
36
|
+
a((e = e.apply(t, r)).next());
|
|
38
37
|
});
|
|
39
|
-
import { jsx as
|
|
40
|
-
import { createContext as we, useContext as
|
|
41
|
-
const
|
|
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) => {
|
|
42
41
|
try {
|
|
43
|
-
const
|
|
44
|
-
if (!
|
|
45
|
-
const { data:
|
|
46
|
-
return e && Date.now() -
|
|
47
|
-
} catch (
|
|
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) {
|
|
48
47
|
return null;
|
|
49
48
|
}
|
|
50
|
-
},
|
|
49
|
+
}, V = (t, r, e) => {
|
|
51
50
|
try {
|
|
52
|
-
const
|
|
53
|
-
data:
|
|
51
|
+
const s = `${e}_${t}`, o = {
|
|
52
|
+
data: r,
|
|
54
53
|
timestamp: Date.now()
|
|
55
54
|
};
|
|
56
|
-
localStorage.setItem(
|
|
57
|
-
} catch (
|
|
58
|
-
console.warn("Failed to cache dismissible item:",
|
|
55
|
+
localStorage.setItem(s, JSON.stringify(o));
|
|
56
|
+
} catch (s) {
|
|
57
|
+
console.warn("Failed to cache dismissible item:", s);
|
|
59
58
|
}
|
|
60
|
-
},
|
|
59
|
+
}, ne = (t, r) => {
|
|
61
60
|
try {
|
|
62
|
-
const e = `${
|
|
61
|
+
const e = `${r}_${t}`;
|
|
63
62
|
localStorage.removeItem(e);
|
|
64
63
|
} catch (e) {
|
|
65
64
|
console.warn("Failed to remove cached dismissible item:", e);
|
|
66
65
|
}
|
|
67
|
-
},
|
|
66
|
+
}, ce = we(
|
|
68
67
|
null
|
|
69
|
-
),
|
|
70
|
-
const
|
|
71
|
-
if (!
|
|
68
|
+
), ge = () => {
|
|
69
|
+
const t = pe(ce);
|
|
70
|
+
if (!t)
|
|
72
71
|
throw new Error(
|
|
73
72
|
"useDismissibleContext must be used within a DismissibleProvider"
|
|
74
73
|
);
|
|
75
|
-
return
|
|
76
|
-
}, ve = "dismissible",
|
|
74
|
+
return t;
|
|
75
|
+
}, ve = "dismissible", Ee = (t, r = {}) => {
|
|
77
76
|
const {
|
|
78
77
|
initialData: e,
|
|
79
|
-
enableCache:
|
|
80
|
-
cachePrefix:
|
|
81
|
-
cacheExpiration:
|
|
82
|
-
} =
|
|
83
|
-
enableCache:
|
|
84
|
-
cachePrefix:
|
|
85
|
-
cacheExpiration:
|
|
86
|
-
}),
|
|
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(() => {
|
|
87
86
|
if (e) return e;
|
|
88
|
-
if (
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
if (s) {
|
|
88
|
+
const c = se(
|
|
89
|
+
d,
|
|
90
|
+
o,
|
|
91
|
+
n
|
|
93
92
|
);
|
|
94
|
-
if (
|
|
93
|
+
if (c) return c;
|
|
95
94
|
}
|
|
96
|
-
}),
|
|
97
|
-
var
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
}), D = K(() => C(null, null, function* () {
|
|
96
|
+
var g;
|
|
97
|
+
if (s) {
|
|
98
|
+
const b = se(
|
|
99
|
+
d,
|
|
100
|
+
o,
|
|
101
|
+
n
|
|
103
102
|
);
|
|
104
|
-
if (
|
|
105
|
-
|
|
103
|
+
if (b != null && b.dismissedAt) {
|
|
104
|
+
S(b), j(!1);
|
|
106
105
|
return;
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
|
-
(
|
|
110
|
-
const
|
|
111
|
-
|
|
108
|
+
(g = E.current) == null || g.abort();
|
|
109
|
+
const c = new AbortController();
|
|
110
|
+
E.current = c, j(!0), p(void 0);
|
|
112
111
|
try {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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")
|
|
119
122
|
return;
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
p(
|
|
124
|
+
b instanceof Error ? b : new Error("Unknown error occurred")
|
|
122
125
|
);
|
|
123
126
|
} finally {
|
|
124
|
-
|
|
127
|
+
j(!1);
|
|
125
128
|
}
|
|
126
129
|
}), [
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
i,
|
|
130
|
+
t,
|
|
131
|
+
a,
|
|
132
|
+
d,
|
|
131
133
|
s,
|
|
132
|
-
|
|
134
|
+
o,
|
|
135
|
+
n,
|
|
136
|
+
f,
|
|
137
|
+
m,
|
|
138
|
+
i
|
|
133
139
|
]);
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
}, [
|
|
138
|
-
var
|
|
139
|
-
(
|
|
140
|
-
}, []),
|
|
141
|
-
const
|
|
142
|
-
(
|
|
143
|
-
enableCache:
|
|
144
|
-
cachePrefix:
|
|
145
|
-
cacheExpiration:
|
|
146
|
-
},
|
|
147
|
-
}, [
|
|
148
|
-
const
|
|
149
|
-
|
|
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);
|
|
150
156
|
try {
|
|
151
|
-
const
|
|
152
|
-
userId:
|
|
153
|
-
itemId:
|
|
154
|
-
baseUrl:
|
|
155
|
-
authHeaders:
|
|
157
|
+
const c = yield i.getAuthHeaders(), g = yield f.dismiss({
|
|
158
|
+
userId: a,
|
|
159
|
+
itemId: t,
|
|
160
|
+
baseUrl: m,
|
|
161
|
+
authHeaders: c
|
|
156
162
|
});
|
|
157
|
-
|
|
158
|
-
} catch (
|
|
159
|
-
throw
|
|
160
|
-
|
|
161
|
-
),
|
|
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;
|
|
162
168
|
}
|
|
163
169
|
}), [
|
|
164
|
-
|
|
165
|
-
o,
|
|
166
|
-
h,
|
|
167
|
-
n,
|
|
168
|
-
i,
|
|
170
|
+
t,
|
|
169
171
|
a,
|
|
170
|
-
u,
|
|
171
172
|
d,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
s,
|
|
174
|
+
o,
|
|
175
|
+
f,
|
|
176
|
+
m,
|
|
177
|
+
i
|
|
178
|
+
]), _ = K(() => C(null, null, function* () {
|
|
179
|
+
p(void 0);
|
|
175
180
|
try {
|
|
176
|
-
const
|
|
177
|
-
userId:
|
|
178
|
-
itemId:
|
|
179
|
-
baseUrl:
|
|
180
|
-
authHeaders:
|
|
181
|
+
const c = yield i.getAuthHeaders(), g = yield f.restore({
|
|
182
|
+
userId: a,
|
|
183
|
+
itemId: t,
|
|
184
|
+
baseUrl: m,
|
|
185
|
+
authHeaders: c
|
|
181
186
|
});
|
|
182
|
-
|
|
183
|
-
} catch (
|
|
184
|
-
throw
|
|
185
|
-
|
|
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;
|
|
187
192
|
}
|
|
188
193
|
}), [
|
|
189
|
-
|
|
190
|
-
o,
|
|
191
|
-
h,
|
|
192
|
-
n,
|
|
193
|
-
i,
|
|
194
|
+
t,
|
|
194
195
|
a,
|
|
195
|
-
u,
|
|
196
196
|
d,
|
|
197
|
-
|
|
197
|
+
s,
|
|
198
|
+
o,
|
|
199
|
+
f,
|
|
200
|
+
m,
|
|
201
|
+
i
|
|
198
202
|
]);
|
|
199
203
|
return {
|
|
200
|
-
dismissedAt:
|
|
201
|
-
dismiss:
|
|
202
|
-
restore:
|
|
203
|
-
isLoading:
|
|
204
|
-
error:
|
|
205
|
-
item:
|
|
204
|
+
dismissedAt: x == null ? void 0 : x.dismissedAt,
|
|
205
|
+
dismiss: k,
|
|
206
|
+
restore: _,
|
|
207
|
+
isLoading: $,
|
|
208
|
+
error: q,
|
|
209
|
+
item: x
|
|
206
210
|
};
|
|
207
|
-
},
|
|
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(
|
|
208
212
|
"button",
|
|
209
213
|
{
|
|
210
214
|
className: "dismissible-button",
|
|
211
|
-
onClick:
|
|
212
|
-
"aria-label":
|
|
215
|
+
onClick: t,
|
|
216
|
+
"aria-label": r,
|
|
213
217
|
type: "button",
|
|
214
218
|
children: "×"
|
|
215
219
|
}
|
|
216
|
-
),
|
|
217
|
-
itemId:
|
|
218
|
-
children:
|
|
220
|
+
), Fe = ({
|
|
221
|
+
itemId: t,
|
|
222
|
+
children: r,
|
|
219
223
|
onDismiss: e,
|
|
220
|
-
LoadingComponent:
|
|
221
|
-
ErrorComponent:
|
|
222
|
-
DismissButtonComponent:
|
|
223
|
-
enableCache:
|
|
224
|
+
LoadingComponent: s = Re,
|
|
225
|
+
ErrorComponent: o = Ce,
|
|
226
|
+
DismissButtonComponent: n = xe,
|
|
227
|
+
enableCache: i,
|
|
224
228
|
cachePrefix: a,
|
|
225
|
-
cacheExpiration:
|
|
226
|
-
ignoreErrors:
|
|
229
|
+
cacheExpiration: f,
|
|
230
|
+
ignoreErrors: m = !1
|
|
227
231
|
}) => {
|
|
228
|
-
const { dismissedAt:
|
|
229
|
-
|
|
232
|
+
const { dismissedAt: d, isLoading: A, error: u, dismiss: l } = Ee(
|
|
233
|
+
t,
|
|
230
234
|
{
|
|
231
|
-
enableCache:
|
|
235
|
+
enableCache: i,
|
|
232
236
|
cachePrefix: a,
|
|
233
|
-
cacheExpiration:
|
|
237
|
+
cacheExpiration: f
|
|
234
238
|
}
|
|
235
|
-
), [E,
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
+
), [E, $] = z(!1), [j, q] = z(t);
|
|
240
|
+
t !== j && (q(t), $(!1));
|
|
241
|
+
const p = () => C(null, null, function* () {
|
|
242
|
+
$(!0);
|
|
239
243
|
try {
|
|
240
|
-
yield
|
|
241
|
-
} catch (
|
|
242
|
-
|
|
244
|
+
yield l(), e == null || e();
|
|
245
|
+
} catch (x) {
|
|
246
|
+
$(!1);
|
|
243
247
|
}
|
|
244
248
|
});
|
|
245
|
-
return
|
|
246
|
-
/* @__PURE__ */
|
|
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,
|
|
249
253
|
{
|
|
250
|
-
onDismiss:
|
|
251
|
-
ariaLabel: `Dismiss ${
|
|
254
|
+
onDismiss: p,
|
|
255
|
+
ariaLabel: `Dismiss ${t}`
|
|
252
256
|
}
|
|
253
257
|
) : null
|
|
254
258
|
] });
|
|
255
|
-
},
|
|
256
|
-
if (typeof
|
|
259
|
+
}, Se = (t) => C(null, null, function* () {
|
|
260
|
+
if (typeof t == "function")
|
|
257
261
|
try {
|
|
258
|
-
const
|
|
259
|
-
return yield Promise.resolve(
|
|
260
|
-
} catch (
|
|
261
|
-
console.warn("Failed to resolve JWT from function:",
|
|
262
|
+
const r = t();
|
|
263
|
+
return yield Promise.resolve(r);
|
|
264
|
+
} catch (r) {
|
|
265
|
+
console.warn("Failed to resolve JWT from function:", r);
|
|
262
266
|
return;
|
|
263
267
|
}
|
|
264
|
-
return
|
|
265
|
-
}),
|
|
266
|
-
const
|
|
267
|
-
return
|
|
268
|
-
}),
|
|
269
|
-
var
|
|
270
|
-
return typeof process == "object" && Number.parseInt((
|
|
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;
|
|
271
275
|
};
|
|
272
|
-
function
|
|
276
|
+
function De() {
|
|
273
277
|
return Math.random().toString(36).slice(2, 11);
|
|
274
278
|
}
|
|
275
|
-
function
|
|
276
|
-
let
|
|
277
|
-
baseUrl:
|
|
279
|
+
function Ie(t) {
|
|
280
|
+
let A = y({}, t), {
|
|
281
|
+
baseUrl: r = "",
|
|
278
282
|
Request: e = globalThis.Request,
|
|
279
|
-
fetch:
|
|
280
|
-
querySerializer:
|
|
281
|
-
bodySerializer:
|
|
282
|
-
headers:
|
|
283
|
+
fetch: s = globalThis.fetch,
|
|
284
|
+
querySerializer: o,
|
|
285
|
+
bodySerializer: n,
|
|
286
|
+
headers: i,
|
|
283
287
|
requestInitExt: a = void 0
|
|
284
|
-
} =
|
|
288
|
+
} = A, f = G(A, [
|
|
285
289
|
"baseUrl",
|
|
286
290
|
"Request",
|
|
287
291
|
"fetch",
|
|
@@ -290,23 +294,23 @@ function De(r) {
|
|
|
290
294
|
"headers",
|
|
291
295
|
"requestInitExt"
|
|
292
296
|
]);
|
|
293
|
-
a =
|
|
294
|
-
const
|
|
295
|
-
function
|
|
297
|
+
a = je() ? a : void 0, r = ae(r);
|
|
298
|
+
const m = [];
|
|
299
|
+
function d(u, l) {
|
|
296
300
|
return C(this, null, function* () {
|
|
297
|
-
var
|
|
298
|
-
const
|
|
301
|
+
var Y;
|
|
302
|
+
const X = l || {}, {
|
|
299
303
|
baseUrl: E,
|
|
300
|
-
fetch:
|
|
301
|
-
Request:
|
|
302
|
-
headers:
|
|
303
|
-
params:
|
|
304
|
-
parseAs:
|
|
305
|
-
querySerializer:
|
|
306
|
-
bodySerializer:
|
|
307
|
-
body:
|
|
308
|
-
middleware:
|
|
309
|
-
} =
|
|
304
|
+
fetch: $ = s,
|
|
305
|
+
Request: j = e,
|
|
306
|
+
headers: q,
|
|
307
|
+
params: p = {},
|
|
308
|
+
parseAs: x = "json",
|
|
309
|
+
querySerializer: S,
|
|
310
|
+
bodySerializer: D = n != null ? n : He,
|
|
311
|
+
body: k,
|
|
312
|
+
middleware: _ = []
|
|
313
|
+
} = X, c = G(X, [
|
|
310
314
|
"baseUrl",
|
|
311
315
|
"fetch",
|
|
312
316
|
"Request",
|
|
@@ -318,581 +322,439 @@ function De(r) {
|
|
|
318
322
|
"body",
|
|
319
323
|
"middleware"
|
|
320
324
|
]);
|
|
321
|
-
let
|
|
322
|
-
E && (
|
|
323
|
-
let
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
|
|
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,
|
|
327
331
|
// Note: we declare mergeHeaders() both here and below because it’s a bit of a chicken-or-egg situation:
|
|
328
332
|
// bodySerializer() needs all headers so we aren’t dropping ones set by the user, however,
|
|
329
333
|
// the result of this ALSO sets the lowest-priority content-type header. So we re-merge below,
|
|
330
334
|
// setting the content-type at the very beginning to be overwritten.
|
|
331
335
|
// Lastly, based on the way headers work, it’s not a simple “present-or-not” check becauase null intentionally un-sets headers.
|
|
332
|
-
|
|
333
|
-
),
|
|
336
|
+
ie(i, q, p.header)
|
|
337
|
+
), fe = ie(
|
|
334
338
|
// with no body, we should not to set Content-Type
|
|
335
|
-
|
|
336
|
-
|
|
339
|
+
O === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
|
|
340
|
+
O instanceof FormData ? {} : {
|
|
337
341
|
"Content-Type": "application/json"
|
|
338
342
|
},
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
),
|
|
343
|
+
i,
|
|
344
|
+
q,
|
|
345
|
+
p.header
|
|
346
|
+
), I = [...m, ..._], de = R(y(y({
|
|
343
347
|
redirect: "follow"
|
|
344
|
-
},
|
|
345
|
-
body:
|
|
346
|
-
headers:
|
|
348
|
+
}, f), c), {
|
|
349
|
+
body: O,
|
|
350
|
+
headers: fe
|
|
347
351
|
});
|
|
348
|
-
let
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
),
|
|
352
|
-
for (const
|
|
353
|
-
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
baseUrl:
|
|
357
|
-
fetch:
|
|
358
|
-
parseAs:
|
|
359
|
-
querySerializer:
|
|
360
|
-
bodySerializer:
|
|
352
|
+
let F, L, T = new j(
|
|
353
|
+
Ue(u, { baseUrl: g, params: p, querySerializer: b }),
|
|
354
|
+
de
|
|
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
|
|
361
365
|
});
|
|
362
|
-
for (const
|
|
363
|
-
if (
|
|
364
|
-
const
|
|
365
|
-
request:
|
|
366
|
-
schemaPath:
|
|
367
|
-
params:
|
|
368
|
-
options:
|
|
369
|
-
id:
|
|
366
|
+
for (const v of I)
|
|
367
|
+
if (v && typeof v == "object" && typeof v.onRequest == "function") {
|
|
368
|
+
const w = yield v.onRequest({
|
|
369
|
+
request: T,
|
|
370
|
+
schemaPath: u,
|
|
371
|
+
params: p,
|
|
372
|
+
options: L,
|
|
373
|
+
id: F
|
|
370
374
|
});
|
|
371
|
-
if (
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
else if (
|
|
375
|
-
|
|
375
|
+
if (w)
|
|
376
|
+
if (w instanceof j)
|
|
377
|
+
T = w;
|
|
378
|
+
else if (w instanceof Response) {
|
|
379
|
+
h = w;
|
|
376
380
|
break;
|
|
377
381
|
} else
|
|
378
382
|
throw new Error("onRequest: must return new Request() or Response() when modifying the request");
|
|
379
383
|
}
|
|
380
384
|
}
|
|
381
|
-
if (!
|
|
385
|
+
if (!h) {
|
|
382
386
|
try {
|
|
383
|
-
|
|
384
|
-
} catch (
|
|
385
|
-
let
|
|
386
|
-
if (
|
|
387
|
-
for (let
|
|
388
|
-
const N =
|
|
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];
|
|
389
393
|
if (N && typeof N == "object" && typeof N.onError == "function") {
|
|
390
|
-
const
|
|
391
|
-
request:
|
|
392
|
-
error:
|
|
393
|
-
schemaPath:
|
|
394
|
-
params:
|
|
395
|
-
options:
|
|
396
|
-
id:
|
|
394
|
+
const P = yield N.onError({
|
|
395
|
+
request: T,
|
|
396
|
+
error: w,
|
|
397
|
+
schemaPath: u,
|
|
398
|
+
params: p,
|
|
399
|
+
options: L,
|
|
400
|
+
id: F
|
|
397
401
|
});
|
|
398
|
-
if (
|
|
399
|
-
if (
|
|
400
|
-
|
|
402
|
+
if (P) {
|
|
403
|
+
if (P instanceof Response) {
|
|
404
|
+
w = void 0, h = P;
|
|
401
405
|
break;
|
|
402
406
|
}
|
|
403
|
-
if (
|
|
404
|
-
|
|
407
|
+
if (P instanceof Error) {
|
|
408
|
+
w = P;
|
|
405
409
|
continue;
|
|
406
410
|
}
|
|
407
411
|
throw new Error("onError: must return new Response() or instance of Error");
|
|
408
412
|
}
|
|
409
413
|
}
|
|
410
414
|
}
|
|
411
|
-
if (
|
|
412
|
-
throw
|
|
415
|
+
if (w)
|
|
416
|
+
throw w;
|
|
413
417
|
}
|
|
414
|
-
if (
|
|
415
|
-
for (let
|
|
416
|
-
const
|
|
417
|
-
if (
|
|
418
|
-
const
|
|
419
|
-
request:
|
|
420
|
-
response:
|
|
421
|
-
schemaPath:
|
|
422
|
-
params:
|
|
423
|
-
options:
|
|
424
|
-
id:
|
|
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({
|
|
423
|
+
request: T,
|
|
424
|
+
response: h,
|
|
425
|
+
schemaPath: u,
|
|
426
|
+
params: p,
|
|
427
|
+
options: L,
|
|
428
|
+
id: F
|
|
425
429
|
});
|
|
426
|
-
if (
|
|
427
|
-
if (!(
|
|
430
|
+
if (U) {
|
|
431
|
+
if (!(U instanceof Response))
|
|
428
432
|
throw new Error("onResponse: must return new Response() when modifying the response");
|
|
429
|
-
|
|
433
|
+
h = U;
|
|
430
434
|
}
|
|
431
435
|
}
|
|
432
436
|
}
|
|
433
437
|
}
|
|
434
|
-
if (
|
|
435
|
-
return
|
|
436
|
-
if (
|
|
437
|
-
return
|
|
438
|
-
let
|
|
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();
|
|
439
443
|
try {
|
|
440
|
-
|
|
441
|
-
} catch (
|
|
444
|
+
B = JSON.parse(B);
|
|
445
|
+
} catch (v) {
|
|
442
446
|
}
|
|
443
|
-
return { error:
|
|
447
|
+
return { error: B, response: h };
|
|
444
448
|
});
|
|
445
449
|
}
|
|
446
450
|
return {
|
|
447
|
-
request(
|
|
448
|
-
return
|
|
451
|
+
request(u, l, E) {
|
|
452
|
+
return d(l, R(y({}, E), { method: u.toUpperCase() }));
|
|
449
453
|
},
|
|
450
454
|
/** Call a GET endpoint */
|
|
451
|
-
GET(
|
|
452
|
-
return
|
|
455
|
+
GET(u, l) {
|
|
456
|
+
return d(u, R(y({}, l), { method: "GET" }));
|
|
453
457
|
},
|
|
454
458
|
/** Call a PUT endpoint */
|
|
455
|
-
PUT(
|
|
456
|
-
return
|
|
459
|
+
PUT(u, l) {
|
|
460
|
+
return d(u, R(y({}, l), { method: "PUT" }));
|
|
457
461
|
},
|
|
458
462
|
/** Call a POST endpoint */
|
|
459
|
-
POST(
|
|
460
|
-
return
|
|
463
|
+
POST(u, l) {
|
|
464
|
+
return d(u, R(y({}, l), { method: "POST" }));
|
|
461
465
|
},
|
|
462
466
|
/** Call a DELETE endpoint */
|
|
463
|
-
DELETE(
|
|
464
|
-
return
|
|
467
|
+
DELETE(u, l) {
|
|
468
|
+
return d(u, R(y({}, l), { method: "DELETE" }));
|
|
465
469
|
},
|
|
466
470
|
/** Call a OPTIONS endpoint */
|
|
467
|
-
OPTIONS(
|
|
468
|
-
return
|
|
471
|
+
OPTIONS(u, l) {
|
|
472
|
+
return d(u, R(y({}, l), { method: "OPTIONS" }));
|
|
469
473
|
},
|
|
470
474
|
/** Call a HEAD endpoint */
|
|
471
|
-
HEAD(
|
|
472
|
-
return
|
|
475
|
+
HEAD(u, l) {
|
|
476
|
+
return d(u, R(y({}, l), { method: "HEAD" }));
|
|
473
477
|
},
|
|
474
478
|
/** Call a PATCH endpoint */
|
|
475
|
-
PATCH(
|
|
476
|
-
return
|
|
479
|
+
PATCH(u, l) {
|
|
480
|
+
return d(u, R(y({}, l), { method: "PATCH" }));
|
|
477
481
|
},
|
|
478
482
|
/** Call a TRACE endpoint */
|
|
479
|
-
TRACE(
|
|
480
|
-
return
|
|
483
|
+
TRACE(u, l) {
|
|
484
|
+
return d(u, R(y({}, l), { method: "TRACE" }));
|
|
481
485
|
},
|
|
482
486
|
/** Register middleware */
|
|
483
|
-
use(...
|
|
484
|
-
for (const
|
|
485
|
-
if (
|
|
486
|
-
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))
|
|
487
491
|
throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
|
|
488
|
-
|
|
492
|
+
m.push(l);
|
|
489
493
|
}
|
|
490
494
|
},
|
|
491
495
|
/** Unregister middleware */
|
|
492
|
-
eject(...
|
|
493
|
-
for (const
|
|
494
|
-
const E =
|
|
495
|
-
E !== -1 &&
|
|
496
|
+
eject(...u) {
|
|
497
|
+
for (const l of u) {
|
|
498
|
+
const E = m.indexOf(l);
|
|
499
|
+
E !== -1 && m.splice(E, 1);
|
|
496
500
|
}
|
|
497
501
|
}
|
|
498
502
|
};
|
|
499
503
|
}
|
|
500
|
-
function
|
|
501
|
-
if (
|
|
504
|
+
function W(t, r, e) {
|
|
505
|
+
if (r == null)
|
|
502
506
|
return "";
|
|
503
|
-
if (typeof
|
|
507
|
+
if (typeof r == "object")
|
|
504
508
|
throw new Error(
|
|
505
509
|
"Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these."
|
|
506
510
|
);
|
|
507
|
-
return `${
|
|
511
|
+
return `${t}=${(e == null ? void 0 : e.allowReserved) === !0 ? r : encodeURIComponent(r)}`;
|
|
508
512
|
}
|
|
509
|
-
function
|
|
510
|
-
if (!
|
|
513
|
+
function le(t, r, e) {
|
|
514
|
+
if (!r || typeof r != "object")
|
|
511
515
|
return "";
|
|
512
|
-
const
|
|
516
|
+
const s = [], o = {
|
|
513
517
|
simple: ",",
|
|
514
518
|
label: ".",
|
|
515
519
|
matrix: ";"
|
|
516
520
|
}[e.style] || "&";
|
|
517
521
|
if (e.style !== "deepObject" && e.explode === !1) {
|
|
518
|
-
for (const a in
|
|
519
|
-
|
|
520
|
-
const
|
|
522
|
+
for (const a in r)
|
|
523
|
+
s.push(a, e.allowReserved === !0 ? r[a] : encodeURIComponent(r[a]));
|
|
524
|
+
const i = s.join(",");
|
|
521
525
|
switch (e.style) {
|
|
522
526
|
case "form":
|
|
523
|
-
return `${
|
|
527
|
+
return `${t}=${i}`;
|
|
524
528
|
case "label":
|
|
525
|
-
return `.${
|
|
529
|
+
return `.${i}`;
|
|
526
530
|
case "matrix":
|
|
527
|
-
return `;${
|
|
531
|
+
return `;${t}=${i}`;
|
|
528
532
|
default:
|
|
529
|
-
return
|
|
533
|
+
return i;
|
|
530
534
|
}
|
|
531
535
|
}
|
|
532
|
-
for (const
|
|
533
|
-
const a = e.style === "deepObject" ? `${
|
|
534
|
-
|
|
536
|
+
for (const i in r) {
|
|
537
|
+
const a = e.style === "deepObject" ? `${t}[${i}]` : i;
|
|
538
|
+
s.push(W(a, r[i], e));
|
|
535
539
|
}
|
|
536
|
-
const
|
|
537
|
-
return e.style === "label" || e.style === "matrix" ? `${
|
|
540
|
+
const n = s.join(o);
|
|
541
|
+
return e.style === "label" || e.style === "matrix" ? `${o}${n}` : n;
|
|
538
542
|
}
|
|
539
|
-
function
|
|
540
|
-
if (!Array.isArray(
|
|
543
|
+
function ue(t, r, e) {
|
|
544
|
+
if (!Array.isArray(r))
|
|
541
545
|
return "";
|
|
542
546
|
if (e.explode === !1) {
|
|
543
|
-
const
|
|
547
|
+
const n = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[e.style] || ",", i = (e.allowReserved === !0 ? r : r.map((a) => encodeURIComponent(a))).join(n);
|
|
544
548
|
switch (e.style) {
|
|
545
549
|
case "simple":
|
|
546
|
-
return
|
|
550
|
+
return i;
|
|
547
551
|
case "label":
|
|
548
|
-
return `.${
|
|
552
|
+
return `.${i}`;
|
|
549
553
|
case "matrix":
|
|
550
|
-
return `;${
|
|
554
|
+
return `;${t}=${i}`;
|
|
551
555
|
// case "spaceDelimited":
|
|
552
556
|
// case "pipeDelimited":
|
|
553
557
|
default:
|
|
554
|
-
return `${
|
|
558
|
+
return `${t}=${i}`;
|
|
555
559
|
}
|
|
556
560
|
}
|
|
557
|
-
const
|
|
558
|
-
for (const
|
|
559
|
-
e.style === "simple" || e.style === "label" ?
|
|
560
|
-
return e.style === "label" || e.style === "matrix" ? `${
|
|
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);
|
|
561
565
|
}
|
|
562
|
-
function oe(
|
|
566
|
+
function oe(t) {
|
|
563
567
|
return function(e) {
|
|
564
|
-
const
|
|
568
|
+
const s = [];
|
|
565
569
|
if (e && typeof e == "object")
|
|
566
|
-
for (const
|
|
567
|
-
const
|
|
568
|
-
if (
|
|
569
|
-
if (Array.isArray(
|
|
570
|
-
if (
|
|
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)
|
|
571
575
|
continue;
|
|
572
|
-
|
|
573
|
-
|
|
576
|
+
s.push(
|
|
577
|
+
ue(o, n, R(y({
|
|
574
578
|
style: "form",
|
|
575
579
|
explode: !0
|
|
576
|
-
},
|
|
577
|
-
allowReserved: (
|
|
580
|
+
}, t == null ? void 0 : t.array), {
|
|
581
|
+
allowReserved: (t == null ? void 0 : t.allowReserved) || !1
|
|
578
582
|
}))
|
|
579
583
|
);
|
|
580
584
|
continue;
|
|
581
585
|
}
|
|
582
|
-
if (typeof
|
|
583
|
-
|
|
584
|
-
|
|
586
|
+
if (typeof n == "object") {
|
|
587
|
+
s.push(
|
|
588
|
+
le(o, n, R(y({
|
|
585
589
|
style: "deepObject",
|
|
586
590
|
explode: !0
|
|
587
|
-
},
|
|
588
|
-
allowReserved: (
|
|
591
|
+
}, t == null ? void 0 : t.object), {
|
|
592
|
+
allowReserved: (t == null ? void 0 : t.allowReserved) || !1
|
|
589
593
|
}))
|
|
590
594
|
);
|
|
591
595
|
continue;
|
|
592
596
|
}
|
|
593
|
-
|
|
597
|
+
s.push(W(o, n, t));
|
|
594
598
|
}
|
|
595
599
|
}
|
|
596
|
-
return
|
|
600
|
+
return s.join("&");
|
|
597
601
|
};
|
|
598
602
|
}
|
|
599
|
-
function Te(
|
|
600
|
-
var
|
|
601
|
-
let e =
|
|
602
|
-
for (const
|
|
603
|
-
let
|
|
604
|
-
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)
|
|
605
609
|
continue;
|
|
606
|
-
const
|
|
607
|
-
if (Array.isArray(
|
|
608
|
-
e = e.replace(
|
|
610
|
+
const f = r[n];
|
|
611
|
+
if (Array.isArray(f)) {
|
|
612
|
+
e = e.replace(o, ue(n, f, { style: a, explode: i }));
|
|
609
613
|
continue;
|
|
610
614
|
}
|
|
611
|
-
if (typeof
|
|
612
|
-
e = e.replace(
|
|
615
|
+
if (typeof f == "object") {
|
|
616
|
+
e = e.replace(o, le(n, f, { style: a, explode: i }));
|
|
613
617
|
continue;
|
|
614
618
|
}
|
|
615
619
|
if (a === "matrix") {
|
|
616
|
-
e = e.replace(
|
|
620
|
+
e = e.replace(o, `;${W(n, f)}`);
|
|
617
621
|
continue;
|
|
618
622
|
}
|
|
619
|
-
e = e.replace(
|
|
623
|
+
e = e.replace(o, a === "label" ? `.${encodeURIComponent(f)}` : encodeURIComponent(f));
|
|
620
624
|
}
|
|
621
625
|
return e;
|
|
622
626
|
}
|
|
623
|
-
function He(
|
|
624
|
-
var e,
|
|
625
|
-
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);
|
|
626
630
|
}
|
|
627
|
-
function
|
|
628
|
-
var
|
|
629
|
-
let e = `${
|
|
630
|
-
(
|
|
631
|
-
let
|
|
632
|
-
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;
|
|
633
637
|
}
|
|
634
|
-
function
|
|
635
|
-
const
|
|
636
|
-
for (const e of
|
|
638
|
+
function ie(...t) {
|
|
639
|
+
const r = new Headers();
|
|
640
|
+
for (const e of t) {
|
|
637
641
|
if (!e || typeof e != "object")
|
|
638
642
|
continue;
|
|
639
|
-
const
|
|
640
|
-
for (const [
|
|
641
|
-
if (
|
|
642
|
-
|
|
643
|
-
else if (Array.isArray(
|
|
644
|
-
for (const
|
|
645
|
-
|
|
646
|
-
else
|
|
643
|
+
const s = e instanceof Headers ? e.entries() : Object.entries(e);
|
|
644
|
+
for (const [o, n] of s)
|
|
645
|
+
if (n === null)
|
|
646
|
+
r.delete(o);
|
|
647
|
+
else if (Array.isArray(n))
|
|
648
|
+
for (const i of n)
|
|
649
|
+
r.append(o, i);
|
|
650
|
+
else n !== void 0 && r.set(o, n);
|
|
647
651
|
}
|
|
648
|
-
return
|
|
652
|
+
return r;
|
|
649
653
|
}
|
|
650
|
-
function
|
|
651
|
-
return
|
|
654
|
+
function ae(t) {
|
|
655
|
+
return t.endsWith("/") ? t.substring(0, t.length - 1) : t;
|
|
652
656
|
}
|
|
653
|
-
const
|
|
654
|
-
const
|
|
655
|
-
baseUrl:
|
|
657
|
+
const qe = (t) => {
|
|
658
|
+
const r = Ie({
|
|
659
|
+
baseUrl: t,
|
|
656
660
|
headers: {}
|
|
657
661
|
});
|
|
658
662
|
return {
|
|
659
663
|
getOrCreate: (e) => C(null, null, function* () {
|
|
660
|
-
const { userId:
|
|
664
|
+
const { userId: s, itemId: o, authHeaders: n, signal: i } = e, { data: a, error: f } = yield r.GET(
|
|
661
665
|
"/v1/users/{userId}/items/{itemId}",
|
|
662
666
|
{
|
|
663
667
|
params: {
|
|
664
668
|
path: {
|
|
665
|
-
userId:
|
|
666
|
-
itemId:
|
|
669
|
+
userId: s,
|
|
670
|
+
itemId: o
|
|
667
671
|
}
|
|
668
672
|
},
|
|
669
|
-
headers:
|
|
670
|
-
signal:
|
|
673
|
+
headers: n,
|
|
674
|
+
signal: i
|
|
671
675
|
}
|
|
672
676
|
);
|
|
673
|
-
if (
|
|
677
|
+
if (f || !a)
|
|
674
678
|
throw new Error("Failed to fetch dismissible item");
|
|
675
679
|
return a.data;
|
|
676
680
|
}),
|
|
677
|
-
batchGetOrCreate: (e) => C(null, null, function* () {
|
|
678
|
-
const { userId: n, itemIds: i, authHeaders: s, signal: o } = e, { data: a, error: u } = yield t.POST(
|
|
679
|
-
"/v1/users/{userId}/items",
|
|
680
|
-
{
|
|
681
|
-
params: {
|
|
682
|
-
path: {
|
|
683
|
-
userId: n
|
|
684
|
-
}
|
|
685
|
-
},
|
|
686
|
-
body: {
|
|
687
|
-
items: i
|
|
688
|
-
},
|
|
689
|
-
headers: s,
|
|
690
|
-
signal: o
|
|
691
|
-
}
|
|
692
|
-
);
|
|
693
|
-
if (u || !a)
|
|
694
|
-
throw new Error("Failed to batch fetch dismissible items");
|
|
695
|
-
return a.data;
|
|
696
|
-
}),
|
|
697
681
|
dismiss: (e) => C(null, null, function* () {
|
|
698
|
-
const { userId:
|
|
682
|
+
const { userId: s, itemId: o, authHeaders: n } = e, { data: i, error: a } = yield r.DELETE(
|
|
699
683
|
"/v1/users/{userId}/items/{itemId}",
|
|
700
684
|
{
|
|
701
685
|
params: {
|
|
702
686
|
path: {
|
|
703
|
-
userId:
|
|
704
|
-
itemId:
|
|
687
|
+
userId: s,
|
|
688
|
+
itemId: o
|
|
705
689
|
}
|
|
706
690
|
},
|
|
707
|
-
headers:
|
|
691
|
+
headers: n
|
|
708
692
|
}
|
|
709
693
|
);
|
|
710
|
-
if (a || !
|
|
694
|
+
if (a || !i)
|
|
711
695
|
throw new Error("Failed to dismiss item");
|
|
712
|
-
return
|
|
696
|
+
return i.data;
|
|
713
697
|
}),
|
|
714
698
|
restore: (e) => C(null, null, function* () {
|
|
715
|
-
const { userId:
|
|
699
|
+
const { userId: s, itemId: o, authHeaders: n } = e, { data: i, error: a } = yield r.POST(
|
|
716
700
|
"/v1/users/{userId}/items/{itemId}",
|
|
717
701
|
{
|
|
718
702
|
params: {
|
|
719
703
|
path: {
|
|
720
|
-
userId:
|
|
721
|
-
itemId:
|
|
704
|
+
userId: s,
|
|
705
|
+
itemId: o
|
|
722
706
|
}
|
|
723
707
|
},
|
|
724
|
-
headers:
|
|
708
|
+
headers: n
|
|
725
709
|
}
|
|
726
710
|
);
|
|
727
|
-
if (a || !
|
|
711
|
+
if (a || !i)
|
|
728
712
|
throw new Error("Failed to restore item");
|
|
729
|
-
return
|
|
713
|
+
return i.data;
|
|
730
714
|
})
|
|
731
715
|
};
|
|
732
|
-
}, Oe = (
|
|
716
|
+
}, Oe = (t) => {
|
|
733
717
|
try {
|
|
734
|
-
const
|
|
735
|
-
return { isSecure:
|
|
736
|
-
} catch (
|
|
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 };
|
|
720
|
+
} catch (r) {
|
|
737
721
|
return { isSecure: !1, isLocalhost: !1, isHttps: !1 };
|
|
738
722
|
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
O(this, "config");
|
|
743
|
-
O(this, "pendingRequests", []);
|
|
744
|
-
O(this, "isScheduled", !1);
|
|
745
|
-
O(this, "cache", /* @__PURE__ */ new Map());
|
|
746
|
-
O(this, "inFlightRequests", /* @__PURE__ */ new Map());
|
|
747
|
-
var e;
|
|
748
|
-
this.config = v(b({}, t), {
|
|
749
|
-
maxBatchSize: (e = t.maxBatchSize) != null ? e : 50
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
* Request a dismissible item. If called multiple times in the same
|
|
754
|
-
* JavaScript tick, requests will be batched into a single API call.
|
|
755
|
-
*
|
|
756
|
-
* @param itemId - The item ID to fetch
|
|
757
|
-
* @returns Promise resolving to the DismissibleItem
|
|
758
|
-
*/
|
|
759
|
-
getItem(t) {
|
|
760
|
-
const e = this.cache.get(t);
|
|
761
|
-
if (e)
|
|
762
|
-
return Promise.resolve(e);
|
|
763
|
-
const n = this.inFlightRequests.get(t);
|
|
764
|
-
if (n)
|
|
765
|
-
return n;
|
|
766
|
-
let i, s;
|
|
767
|
-
const o = new Promise((a, u) => {
|
|
768
|
-
i = a, s = u;
|
|
769
|
-
});
|
|
770
|
-
return this.pendingRequests.push({
|
|
771
|
-
itemId: t,
|
|
772
|
-
resolve: i,
|
|
773
|
-
reject: s
|
|
774
|
-
}), this.inFlightRequests.set(t, o), o.catch(() => {
|
|
775
|
-
}).finally(() => {
|
|
776
|
-
this.inFlightRequests.delete(t);
|
|
777
|
-
}), this.isScheduled || (this.isScheduled = !0, queueMicrotask(() => this.executeBatch())), o;
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Pre-populate the cache with items (e.g., from localStorage)
|
|
781
|
-
*/
|
|
782
|
-
primeCache(t) {
|
|
783
|
-
this.cache.set(t.itemId, t);
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* Update an item in the cache (e.g., after dismiss/restore)
|
|
787
|
-
*/
|
|
788
|
-
updateCache(t) {
|
|
789
|
-
this.cache.set(t.itemId, t);
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Clear the in-memory cache
|
|
793
|
-
*/
|
|
794
|
-
clearCache() {
|
|
795
|
-
this.cache.clear();
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Execute the batched requests
|
|
799
|
-
*/
|
|
800
|
-
executeBatch() {
|
|
801
|
-
return C(this, null, function* () {
|
|
802
|
-
this.isScheduled = !1;
|
|
803
|
-
const t = this.pendingRequests;
|
|
804
|
-
if (this.pendingRequests = [], t.length === 0)
|
|
805
|
-
return;
|
|
806
|
-
const e = /* @__PURE__ */ new Map();
|
|
807
|
-
for (const s of t) {
|
|
808
|
-
const o = e.get(s.itemId);
|
|
809
|
-
o ? o.push(s) : e.set(s.itemId, [s]);
|
|
810
|
-
}
|
|
811
|
-
const n = Array.from(e.keys()), i = [];
|
|
812
|
-
for (let s = 0; s < n.length; s += this.config.maxBatchSize)
|
|
813
|
-
i.push(n.slice(s, s + this.config.maxBatchSize));
|
|
814
|
-
try {
|
|
815
|
-
const s = yield this.config.getAuthHeaders(), a = (yield Promise.all(
|
|
816
|
-
i.map(
|
|
817
|
-
(d) => this.config.client.batchGetOrCreate({
|
|
818
|
-
userId: this.config.userId,
|
|
819
|
-
itemIds: d,
|
|
820
|
-
baseUrl: this.config.baseUrl,
|
|
821
|
-
authHeaders: s
|
|
822
|
-
})
|
|
823
|
-
)
|
|
824
|
-
)).flat(), u = /* @__PURE__ */ new Map();
|
|
825
|
-
for (const d of a)
|
|
826
|
-
u.set(d.itemId, d), this.cache.set(d.itemId, d);
|
|
827
|
-
for (const [d, m] of e) {
|
|
828
|
-
const h = u.get(d);
|
|
829
|
-
if (h)
|
|
830
|
-
for (const c of m)
|
|
831
|
-
c.resolve(h);
|
|
832
|
-
else {
|
|
833
|
-
const c = new Error(`Item ${d} not found in batch response`);
|
|
834
|
-
for (const f of m)
|
|
835
|
-
f.reject(c);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
} catch (s) {
|
|
839
|
-
const o = s instanceof Error ? s : new Error("Batch request failed");
|
|
840
|
-
for (const a of t)
|
|
841
|
-
a.reject(o);
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
const Ne = ({
|
|
847
|
-
userId: r,
|
|
848
|
-
jwt: t,
|
|
723
|
+
}, Le = ({
|
|
724
|
+
userId: t,
|
|
725
|
+
jwt: r,
|
|
849
726
|
baseUrl: e,
|
|
850
|
-
client:
|
|
851
|
-
children:
|
|
727
|
+
client: s,
|
|
728
|
+
children: o
|
|
852
729
|
}) => {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
[n, e]
|
|
862
|
-
), o = W(
|
|
863
|
-
() => () => C(null, null, function* () {
|
|
864
|
-
return yield qe(t);
|
|
865
|
-
}),
|
|
866
|
-
[t]
|
|
867
|
-
), a = W(
|
|
868
|
-
() => new Ue({
|
|
869
|
-
userId: r,
|
|
870
|
-
baseUrl: e,
|
|
871
|
-
client: s,
|
|
872
|
-
getAuthHeaders: o
|
|
873
|
-
}),
|
|
874
|
-
[r, e, s, o]
|
|
875
|
-
), u = W(
|
|
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.`
|
|
733
|
+
);
|
|
734
|
+
const i = re(
|
|
735
|
+
() => s != null ? s : qe(e),
|
|
736
|
+
[s, e]
|
|
737
|
+
), a = re(
|
|
876
738
|
() => ({
|
|
877
|
-
userId:
|
|
878
|
-
jwt:
|
|
739
|
+
userId: t,
|
|
740
|
+
jwt: r,
|
|
879
741
|
baseUrl: e,
|
|
880
|
-
getAuthHeaders:
|
|
881
|
-
|
|
882
|
-
|
|
742
|
+
getAuthHeaders: () => C(null, null, function* () {
|
|
743
|
+
return yield Ae(r);
|
|
744
|
+
}),
|
|
745
|
+
client: i
|
|
883
746
|
}),
|
|
884
|
-
[
|
|
747
|
+
[t, r, e, i]
|
|
885
748
|
);
|
|
886
|
-
return /* @__PURE__ */
|
|
749
|
+
return /* @__PURE__ */ H(ce.Provider, { value: a, children: o });
|
|
887
750
|
};
|
|
888
751
|
export {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
Ce as useDismissibleItem
|
|
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
|
|
898
760
|
};
|