@acrool/react-fetcher 0.0.2-alpha.0 → 0.0.2-alpha.1
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.
|
@@ -13,8 +13,8 @@ interface AuthStateProviderProps {
|
|
|
13
13
|
children: ReactNode;
|
|
14
14
|
onSetTokens: TOnSetTokens;
|
|
15
15
|
onGetTokens: TOnGetTokens;
|
|
16
|
-
onRefreshTokens
|
|
17
|
-
onForceLogout
|
|
16
|
+
onRefreshTokens?: TOnRefreshToken;
|
|
17
|
+
onForceLogout?: TOnForceLogout;
|
|
18
18
|
}
|
|
19
19
|
declare const AuthStateProvider: ({ children, onGetTokens, onSetTokens, onRefreshTokens, onForceLogout }: AuthStateProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
20
20
|
export default AuthStateProvider;
|
|
@@ -7,14 +7,14 @@ function ft(e, t) {
|
|
|
7
7
|
return e.apply(t, arguments);
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
-
const { toString: Yt } = Object.prototype, { getPrototypeOf:
|
|
10
|
+
const { toString: Yt } = Object.prototype, { getPrototypeOf: Ue } = Object, { iterator: pe, toStringTag: dt } = Symbol, he = /* @__PURE__ */ ((e) => (t) => {
|
|
11
11
|
const n = Yt.call(t);
|
|
12
12
|
return e[n] || (e[n] = n.slice(8, -1).toLowerCase());
|
|
13
|
-
})(/* @__PURE__ */ Object.create(null)),
|
|
13
|
+
})(/* @__PURE__ */ Object.create(null)), L = (e) => (e = e.toLowerCase(), (t) => he(t) === e), me = (e) => (t) => typeof t === e, { isArray: V } = Array, ee = me("undefined");
|
|
14
14
|
function Kt(e) {
|
|
15
15
|
return e !== null && !ee(e) && e.constructor !== null && !ee(e.constructor) && k(e.constructor.isBuffer) && e.constructor.isBuffer(e);
|
|
16
16
|
}
|
|
17
|
-
const pt =
|
|
17
|
+
const pt = L("ArrayBuffer");
|
|
18
18
|
function Xt(e) {
|
|
19
19
|
let t;
|
|
20
20
|
return typeof ArrayBuffer < "u" && ArrayBuffer.isView ? t = ArrayBuffer.isView(e) : t = e && e.buffer && pt(e.buffer), t;
|
|
@@ -22,13 +22,13 @@ function Xt(e) {
|
|
|
22
22
|
const Zt = me("string"), k = me("function"), ht = me("number"), Re = (e) => e !== null && typeof e == "object", Gt = (e) => e === !0 || e === !1, ce = (e) => {
|
|
23
23
|
if (he(e) !== "object")
|
|
24
24
|
return !1;
|
|
25
|
-
const t =
|
|
25
|
+
const t = Ue(e);
|
|
26
26
|
return (t === null || t === Object.prototype || Object.getPrototypeOf(t) === null) && !(dt in e) && !(pe in e);
|
|
27
|
-
}, Qt =
|
|
27
|
+
}, Qt = L("Date"), en = L("File"), tn = L("Blob"), nn = L("FileList"), rn = (e) => Re(e) && k(e.pipe), sn = (e) => {
|
|
28
28
|
let t;
|
|
29
29
|
return e && (typeof FormData == "function" && e instanceof FormData || k(e.append) && ((t = he(e)) === "formdata" || // detect form-data instance
|
|
30
30
|
t === "object" && k(e.toString) && e.toString() === "[object FormData]"));
|
|
31
|
-
}, on =
|
|
31
|
+
}, on = L("URLSearchParams"), [an, cn, un, ln] = ["ReadableStream", "Request", "Response", "Headers"].map(L), fn = (e) => e.trim ? e.trim() : e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
|
|
32
32
|
function te(e, t, { allOwnKeys: n = !1 } = {}) {
|
|
33
33
|
if (e === null || typeof e > "u")
|
|
34
34
|
return;
|
|
@@ -75,7 +75,7 @@ const dn = (e, t, n, { allOwnKeys: r } = {}) => (te(t, (s, o) => {
|
|
|
75
75
|
do {
|
|
76
76
|
for (s = Object.getOwnPropertyNames(e), o = s.length; o-- > 0; )
|
|
77
77
|
i = s[o], (!r || r(i, e, t)) && !c[i] && (t[i] = e[i], c[i] = !0);
|
|
78
|
-
e = n !== !1 &&
|
|
78
|
+
e = n !== !1 && Ue(e);
|
|
79
79
|
} while (e && (!n || n(e, t)) && e !== Object.prototype);
|
|
80
80
|
return t;
|
|
81
81
|
}, Rn = (e, t, n) => {
|
|
@@ -91,7 +91,7 @@ const dn = (e, t, n, { allOwnKeys: r } = {}) => (te(t, (s, o) => {
|
|
|
91
91
|
for (; t-- > 0; )
|
|
92
92
|
n[t] = e[t];
|
|
93
93
|
return n;
|
|
94
|
-
}, bn = /* @__PURE__ */ ((e) => (t) => e && t instanceof e)(typeof Uint8Array < "u" &&
|
|
94
|
+
}, bn = /* @__PURE__ */ ((e) => (t) => e && t instanceof e)(typeof Uint8Array < "u" && Ue(Uint8Array)), yn = (e, t) => {
|
|
95
95
|
const r = (e && e[pe]).call(e);
|
|
96
96
|
let s;
|
|
97
97
|
for (; (s = r.next()) && !s.done; ) {
|
|
@@ -104,12 +104,12 @@ const dn = (e, t, n, { allOwnKeys: r } = {}) => (te(t, (s, o) => {
|
|
|
104
104
|
for (; (n = e.exec(t)) !== null; )
|
|
105
105
|
r.push(n);
|
|
106
106
|
return r;
|
|
107
|
-
}, gn =
|
|
107
|
+
}, gn = L("HTMLFormElement"), Tn = (e) => e.toLowerCase().replace(
|
|
108
108
|
/[-_\s]([a-z\d])(\w*)/g,
|
|
109
109
|
function(n, r, s) {
|
|
110
110
|
return r.toUpperCase() + s;
|
|
111
111
|
}
|
|
112
|
-
), We = (({ hasOwnProperty: e }) => (t, n) => e.call(t, n))(Object.prototype), Sn =
|
|
112
|
+
), We = (({ hasOwnProperty: e }) => (t, n) => e.call(t, n))(Object.prototype), Sn = L("RegExp"), Et = (e, t) => {
|
|
113
113
|
const n = Object.getOwnPropertyDescriptors(e), r = {};
|
|
114
114
|
te(n, (s, o) => {
|
|
115
115
|
let i;
|
|
@@ -159,7 +159,7 @@ const Cn = (e) => {
|
|
|
159
159
|
return r;
|
|
160
160
|
};
|
|
161
161
|
return n(e, 0);
|
|
162
|
-
}, Pn =
|
|
162
|
+
}, Pn = L("AsyncFunction"), kn = (e) => e && (Re(e) || k(e)) && k(e.then) && k(e.catch), bt = ((e, t) => e ? setImmediate : t ? ((n, r) => (H.addEventListener("message", ({ source: s, data: o }) => {
|
|
163
163
|
s === H && o === n && r.length && r.shift()();
|
|
164
164
|
}, !1), (s) => {
|
|
165
165
|
r.push(s), H.postMessage(n, "*");
|
|
@@ -199,7 +199,7 @@ const Cn = (e) => {
|
|
|
199
199
|
inherits: hn,
|
|
200
200
|
toFlatObject: mn,
|
|
201
201
|
kindOf: he,
|
|
202
|
-
kindOfTest:
|
|
202
|
+
kindOfTest: L,
|
|
203
203
|
endsWith: Rn,
|
|
204
204
|
toArray: En,
|
|
205
205
|
forEachEntry: yn,
|
|
@@ -287,10 +287,10 @@ function Ve(e, t, n) {
|
|
|
287
287
|
return s = gt(s), !n && o ? "[" + s + "]" : s;
|
|
288
288
|
}).join(n ? "." : "") : t;
|
|
289
289
|
}
|
|
290
|
-
function
|
|
290
|
+
function Un(e) {
|
|
291
291
|
return a.isArray(e) && !e.some(Pe);
|
|
292
292
|
}
|
|
293
|
-
const
|
|
293
|
+
const Ln = a.toFlatObject(a, {}, null, function(t) {
|
|
294
294
|
return /^is[A-Z]/.test(t);
|
|
295
295
|
});
|
|
296
296
|
function Ee(e, t, n) {
|
|
@@ -319,7 +319,7 @@ function Ee(e, t, n) {
|
|
|
319
319
|
if (m && !d && typeof m == "object") {
|
|
320
320
|
if (a.endsWith(p, "{}"))
|
|
321
321
|
p = r ? p : p.slice(0, -2), m = JSON.stringify(m);
|
|
322
|
-
else if (a.isArray(m) &&
|
|
322
|
+
else if (a.isArray(m) && Un(m) || (a.isFileList(m) || a.endsWith(p, "[]")) && (w = a.toArray(m)))
|
|
323
323
|
return p = gt(p), w.forEach(function(S, _) {
|
|
324
324
|
!(a.isUndefined(S) || S === null) && t.append(
|
|
325
325
|
// eslint-disable-next-line no-nested-ternary
|
|
@@ -330,7 +330,7 @@ function Ee(e, t, n) {
|
|
|
330
330
|
}
|
|
331
331
|
return Pe(m) ? !0 : (t.append(Ve(d, p, o), l(m)), !1);
|
|
332
332
|
}
|
|
333
|
-
const R = [], E = Object.assign(
|
|
333
|
+
const R = [], E = Object.assign(Ln, {
|
|
334
334
|
defaultVisitor: u,
|
|
335
335
|
convertValue: l,
|
|
336
336
|
isVisitable: Pe
|
|
@@ -368,10 +368,10 @@ function Ye(e) {
|
|
|
368
368
|
return t[r];
|
|
369
369
|
});
|
|
370
370
|
}
|
|
371
|
-
function
|
|
371
|
+
function Le(e, t) {
|
|
372
372
|
this._pairs = [], e && Ee(e, this, t);
|
|
373
373
|
}
|
|
374
|
-
const Tt =
|
|
374
|
+
const Tt = Le.prototype;
|
|
375
375
|
Tt.append = function(t, n) {
|
|
376
376
|
this._pairs.push([t, n]);
|
|
377
377
|
};
|
|
@@ -395,7 +395,7 @@ function St(e, t, n) {
|
|
|
395
395
|
});
|
|
396
396
|
const s = n && n.serialize;
|
|
397
397
|
let o;
|
|
398
|
-
if (s ? o = s(t, n) : o = a.isURLSearchParams(t) ? t.toString() : new
|
|
398
|
+
if (s ? o = s(t, n) : o = a.isURLSearchParams(t) ? t.toString() : new Le(t, n).toString(r), o) {
|
|
399
399
|
const i = e.indexOf("#");
|
|
400
400
|
i !== -1 && (e = e.slice(0, i)), e += (e.indexOf("?") === -1 ? "?" : "&") + o;
|
|
401
401
|
}
|
|
@@ -459,7 +459,7 @@ const Ot = {
|
|
|
459
459
|
silentJSONParsing: !0,
|
|
460
460
|
forcedJSONParsing: !0,
|
|
461
461
|
clarifyTimeoutError: !1
|
|
462
|
-
}, Bn = typeof URLSearchParams < "u" ? URLSearchParams :
|
|
462
|
+
}, Bn = typeof URLSearchParams < "u" ? URLSearchParams : Le, qn = typeof FormData < "u" ? FormData : null, In = typeof Blob < "u" ? Blob : null, Mn = {
|
|
463
463
|
isBrowser: !0,
|
|
464
464
|
classes: {
|
|
465
465
|
URLSearchParams: Bn,
|
|
@@ -1657,13 +1657,13 @@ const je = {
|
|
|
1657
1657
|
Object.entries(je).forEach(([e, t]) => {
|
|
1658
1658
|
je[t] = e;
|
|
1659
1659
|
});
|
|
1660
|
-
function
|
|
1660
|
+
function Ut(e) {
|
|
1661
1661
|
const t = new z(e), n = ft(z.prototype.request, t);
|
|
1662
1662
|
return a.extend(n, z.prototype, t, { allOwnKeys: !0 }), a.extend(n, t, null, { allOwnKeys: !0 }), n.create = function(s) {
|
|
1663
|
-
return
|
|
1663
|
+
return Ut(J(e, s));
|
|
1664
1664
|
}, n;
|
|
1665
1665
|
}
|
|
1666
|
-
const x =
|
|
1666
|
+
const x = Ut(ne);
|
|
1667
1667
|
x.Axios = z;
|
|
1668
1668
|
x.CanceledError = Y;
|
|
1669
1669
|
x.CancelToken = Tr;
|
|
@@ -1752,7 +1752,7 @@ const {
|
|
|
1752
1752
|
SERVER_ERROR: "任意500系列错误",
|
|
1753
1753
|
TIMEOUT_ERROR: "服务器已超过 {sec} 秒未响应。请确认您的网络连接状态或联系客服"
|
|
1754
1754
|
}
|
|
1755
|
-
}, Ar = (e) => "File" in window && e instanceof File, xr = (e) => "Blob" in window && e instanceof Blob,
|
|
1755
|
+
}, Ar = (e) => "File" in window && e instanceof File, xr = (e) => "Blob" in window && e instanceof Blob, Lt = (e, t = ["variables"]) => e && Object.keys(e).reduce((n, r) => {
|
|
1756
1756
|
const s = e[r];
|
|
1757
1757
|
if (Ar(s) || xr(s)) {
|
|
1758
1758
|
const o = s;
|
|
@@ -1762,7 +1762,7 @@ const {
|
|
|
1762
1762
|
values: [...n.values, o]
|
|
1763
1763
|
};
|
|
1764
1764
|
} else if (s && typeof s == "object") {
|
|
1765
|
-
const o =
|
|
1765
|
+
const o = Lt(s, t.concat(r));
|
|
1766
1766
|
return {
|
|
1767
1767
|
variables: { ...n.variables, [r]: o.variables },
|
|
1768
1768
|
map: [...n.map, ...o.map],
|
|
@@ -1783,7 +1783,7 @@ const {
|
|
|
1783
1783
|
const s = t == null ? void 0 : t.fetchOptions, o = t == null ? void 0 : t.variables;
|
|
1784
1784
|
let i = !1;
|
|
1785
1785
|
if (o) {
|
|
1786
|
-
const u =
|
|
1786
|
+
const u = Lt(o);
|
|
1787
1787
|
if (i = u.values.length > 0, i) {
|
|
1788
1788
|
r = "multipart/form-data";
|
|
1789
1789
|
const R = JSON.stringify({
|
|
@@ -2135,18 +2135,18 @@ function jr(e, ...t) {
|
|
|
2135
2135
|
]).join(";");
|
|
2136
2136
|
oe(e, n, ...t);
|
|
2137
2137
|
}
|
|
2138
|
-
function
|
|
2138
|
+
function Ur(e, ...t) {
|
|
2139
2139
|
const n = re.concat([
|
|
2140
2140
|
`background-color: ${se.danger}`
|
|
2141
2141
|
]).join(";");
|
|
2142
2142
|
oe(e, n, ...t);
|
|
2143
2143
|
}
|
|
2144
|
-
const
|
|
2144
|
+
const U = {
|
|
2145
2145
|
primary: kr,
|
|
2146
2146
|
success: Fr,
|
|
2147
2147
|
info: vr,
|
|
2148
2148
|
warning: jr,
|
|
2149
|
-
danger:
|
|
2149
|
+
danger: Ur
|
|
2150
2150
|
};
|
|
2151
2151
|
function Be(e, t) {
|
|
2152
2152
|
const n = {
|
|
@@ -2185,13 +2185,13 @@ class Q extends Error {
|
|
|
2185
2185
|
const Bt = lt({
|
|
2186
2186
|
lastUpdateTimestamp: 0,
|
|
2187
2187
|
isAuth: !1,
|
|
2188
|
-
getTokens: () => (
|
|
2189
|
-
updateTokens: () =>
|
|
2190
|
-
forceLogout: () =>
|
|
2188
|
+
getTokens: () => (U.warning("AuthStateContext", "getTokens not yet ready"), null),
|
|
2189
|
+
updateTokens: () => U.warning("AuthStateContext", "updateTokens not yet ready"),
|
|
2190
|
+
forceLogout: () => U.warning("AuthStateContext", "forceLogout not yet ready"),
|
|
2191
2191
|
refreshTokens: async () => {
|
|
2192
|
-
|
|
2192
|
+
U.warning("AuthStateContext", "refreshToken not yet ready");
|
|
2193
2193
|
}
|
|
2194
|
-
}),
|
|
2194
|
+
}), Lr = () => Jt(Bt), as = ({
|
|
2195
2195
|
children: e,
|
|
2196
2196
|
onGetTokens: t,
|
|
2197
2197
|
onSetTokens: n,
|
|
@@ -2204,13 +2204,13 @@ const Bt = lt({
|
|
|
2204
2204
|
}, []);
|
|
2205
2205
|
const l = (E) => {
|
|
2206
2206
|
let g;
|
|
2207
|
-
typeof E == "function" ? g = E(t()) : g = E,
|
|
2207
|
+
typeof E == "function" ? g = E(t()) : g = E, U.danger("更新Token", g), n(g), h(ut(g)), i(Date.now());
|
|
2208
2208
|
}, u = () => {
|
|
2209
|
-
l(null), s();
|
|
2209
|
+
l(null), s && s();
|
|
2210
2210
|
}, R = async () => {
|
|
2211
2211
|
var g;
|
|
2212
2212
|
const E = (g = t()) == null ? void 0 : g.refreshToken;
|
|
2213
|
-
if (E)
|
|
2213
|
+
if (!(!E || !r))
|
|
2214
2214
|
try {
|
|
2215
2215
|
const m = await r(E);
|
|
2216
2216
|
if (Be(m))
|
|
@@ -2271,7 +2271,7 @@ const qr = lt(M), cs = ({
|
|
|
2271
2271
|
updateTokens: i,
|
|
2272
2272
|
refreshTokens: c,
|
|
2273
2273
|
forceLogout: h
|
|
2274
|
-
} =
|
|
2274
|
+
} = Lr();
|
|
2275
2275
|
Vt(() => {
|
|
2276
2276
|
const p = M.interceptors.request.use(R), d = M.interceptors.response.use(E, m);
|
|
2277
2277
|
return () => {
|
|
@@ -2279,7 +2279,7 @@ const qr = lt(M), cs = ({
|
|
|
2279
2279
|
};
|
|
2280
2280
|
}, [o, c, i, h]);
|
|
2281
2281
|
const l = (p) => {
|
|
2282
|
-
|
|
2282
|
+
U.warning("runPendingRequest"), G = !1;
|
|
2283
2283
|
for (const d of Ne)
|
|
2284
2284
|
d(p);
|
|
2285
2285
|
Ne = [];
|
|
@@ -2293,7 +2293,7 @@ const qr = lt(M), cs = ({
|
|
|
2293
2293
|
});
|
|
2294
2294
|
}, R = (p) => new Promise((d, w) => {
|
|
2295
2295
|
var _;
|
|
2296
|
-
|
|
2296
|
+
U.warning("interceptorsRequest"), p.headers["Accept-Language"] = t();
|
|
2297
2297
|
const T = (_ = o()) == null ? void 0 : _.accessToken;
|
|
2298
2298
|
if (T && (p.headers.Authorization = `Bearer ${T}`), !(p && s ? s(p) : !1) && G) {
|
|
2299
2299
|
u(d, w)(p), w(new Dr({ message: "Token refreshing, so request save queues not send", code: "REFRESH_TOKEN" }));
|
|
@@ -2305,12 +2305,12 @@ const qr = lt(M), cs = ({
|
|
|
2305
2305
|
return (w == null ? void 0 : w[p]) || `Error: ${p}`;
|
|
2306
2306
|
}, m = (p) => {
|
|
2307
2307
|
const d = p.response, w = p.config, T = p.status, S = Br(d);
|
|
2308
|
-
|
|
2308
|
+
U.warning("interceptorsResponseError"), n && n(S);
|
|
2309
2309
|
const _ = w && s ? s(w) : !1;
|
|
2310
2310
|
if (d && w && (T === 401 || S.code === "UNAUTHENTICATED")) {
|
|
2311
2311
|
const O = o();
|
|
2312
|
-
return
|
|
2313
|
-
|
|
2312
|
+
return U.warning("401OrUNAUTHENTICATED", O == null ? void 0 : O.refreshToken), Be(O == null ? void 0 : O.refreshToken) || _ ? (G = !1, h(), Promise.reject(new Q(S))) : (G || (G = !0, U.warning("postRefreshToken"), c().then(() => l(!0)).catch(() => {
|
|
2313
|
+
U.danger("refreshTokens fail"), l(!1);
|
|
2314
2314
|
})), new Promise((v, j) => {
|
|
2315
2315
|
u(v, j)(w);
|
|
2316
2316
|
}));
|
|
@@ -2323,5 +2323,5 @@ export {
|
|
|
2323
2323
|
as as AuthStateProvider,
|
|
2324
2324
|
cs as FetcherProvider,
|
|
2325
2325
|
is as graphqlFetcher,
|
|
2326
|
-
|
|
2326
|
+
Lr as useAuthState
|
|
2327
2327
|
};
|