@xingm/http-request-sdk 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-request-sdk.d.ts.map +1 -1
- package/dist/default-sdk-BiMIVw3K.cjs +3 -0
- package/dist/default-sdk-Cm6i-5y_.js +1130 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.js +1 -1
- package/package.json +1 -1
- package/dist/default-sdk-B-tDQ_AC.js +0 -502
- package/dist/default-sdk-DQ7BcjdA.cjs +0 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./default-sdk-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./default-sdk-BiMIVw3K.cjs"),t=require("./adapters/storage-token.cjs");exports.AUTHORIZATION_EXPIRED_EVENT=e.AUTHORIZATION_EXPIRED_EVENT;exports.buildAuthHeaderValue=e.buildAuthHeaderValue;exports.createRequestSdk=e.createRequestSdk;exports.extractI18nParams=e.extractI18nParams;exports.getBizErrorMsg=e.getBizErrorMsg;exports.getDefaultRequestSdk=e.getDefaultRequestSdk;exports.http=e.http;exports.isSuccessCode=e.isSuccessCode;exports.request=e.request;exports.setDefaultRequestSdk=e.setDefaultRequestSdk;exports.setupRequestSdk=e.setupRequestSdk;exports.createStorageTokenAdapter=t.createStorageTokenAdapter;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as a, b as t, c as r, e as u, g as d, a as o, h as c, i as R, r as S, s as g, d as k } from "./default-sdk-
|
|
1
|
+
import { A as a, b as t, c as r, e as u, g as d, a as o, h as c, i as R, r as S, s as g, d as k } from "./default-sdk-Cm6i-5y_.js";
|
|
2
2
|
import { createStorageTokenAdapter as q } from "./adapters/storage-token.js";
|
|
3
3
|
export {
|
|
4
4
|
a as AUTHORIZATION_EXPIRED_EVENT,
|
package/dist/vue/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),s=require("../default-sdk-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),s=require("../default-sdk-BiMIVw3K.cjs"),u=Symbol("requestSdk"),l=r=>{const e=s.createRequestSdk(r);return{sdk:e,install(t){s.setDefaultRequestSdk(e),t.provide(u,e),t.config.globalProperties.$request=e.request,t.config.globalProperties.$http=e.service}}},n=()=>o.inject(u,null)??s.getDefaultRequestSdk();exports.createRequestSdkPlugin=l;exports.requestSdkKey=u;exports.useRequestSdk=n;
|
package/dist/vue/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,502 +0,0 @@
|
|
|
1
|
-
import L from "axios";
|
|
2
|
-
const I = [0, 200], H = {
|
|
3
|
-
"api.accountExpired": "Your account has expired. Please log in again.",
|
|
4
|
-
"api.permissionExpiredTitle": "Permission expired",
|
|
5
|
-
"api.permissionExpiredContent": "Your account has expired. Please log in again.",
|
|
6
|
-
"api.permissionExpiredOkText": "OK",
|
|
7
|
-
"api.networkExceptionMsg": "Network connection error",
|
|
8
|
-
"api.systemException": "System error",
|
|
9
|
-
"api.noPermissionOperation": "No permission to perform this operation",
|
|
10
|
-
"api.exportFailed": "Export failed",
|
|
11
|
-
"api.tokenExpired": "Your account has expired. Please log in again."
|
|
12
|
-
}, C = (e, t, n) => F(n) ? H[e] ?? t ?? e : t ?? e, F = (e) => typeof e == "string" && e.toLowerCase().startsWith("en"), $ = (e) => {
|
|
13
|
-
var o, g, u;
|
|
14
|
-
if (typeof e != "string") return;
|
|
15
|
-
const t = ((o = e.match(/【([^】]+)】/)) == null ? void 0 : o[1]) || ((g = e.match(/\(([^)]+)\)/)) == null ? void 0 : g[1]), n = (u = e.match(/原因[::]\s*(.+)$/)) == null ? void 0 : u[1], i = {};
|
|
16
|
-
return t && (i.value = t), n && (i.reason = n), Object.keys(i).length ? i : void 0;
|
|
17
|
-
}, V = (e, t) => (n, i, o) => {
|
|
18
|
-
var u;
|
|
19
|
-
const g = (u = e == null ? void 0 : e.translate) == null ? void 0 : u.call(e, n, i, o);
|
|
20
|
-
return g && g !== n ? g : C(n, i, t);
|
|
21
|
-
}, j = (e, t, n, i) => {
|
|
22
|
-
var x, T;
|
|
23
|
-
const g = `api.errMsg${String(e ?? "")}`, u = (x = n == null ? void 0 : n.translate) == null ? void 0 : x.call(n, g, void 0, $(t));
|
|
24
|
-
return u && u !== g ? u : typeof t == "string" && t || ((T = n == null ? void 0 : n.translate) == null ? void 0 : T.call(n, "api.systemException", "系统异常")) || C("api.systemException", "系统异常", i);
|
|
25
|
-
}, W = (e, t, n = "/admin-api") => typeof e == "function" ? e(t) : e ?? `${n}/system/auth/refresh-token?refreshToken=${t ?? ""}`, G = (e) => typeof e == "function" ? e() : e ?? "/login", D = (e, t = I) => t.some((n) => String(n) === String(e)), Y = (e, t = "Bearer") => typeof t == "function" ? t(e) : t ? `${t} ${e}` : e, z = () => typeof window < "u" && typeof document < "u", K = "http-request-sdk:authorization-expired", J = (e = {}) => {
|
|
26
|
-
const t = V(e.locale, e.lang);
|
|
27
|
-
let n = !1, i = null;
|
|
28
|
-
const o = L.create({
|
|
29
|
-
baseURL: e.baseURL ?? "/admin-api",
|
|
30
|
-
timeout: e.timeout ?? 3e4,
|
|
31
|
-
validateStatus: (s) => s >= 200 && s < 300 || s === 400,
|
|
32
|
-
headers: {
|
|
33
|
-
"Content-Type": "application/json;charset=UTF-8"
|
|
34
|
-
},
|
|
35
|
-
...e.axiosConfig
|
|
36
|
-
}), g = () => {
|
|
37
|
-
var h, m, d, l;
|
|
38
|
-
const s = typeof e.getAccessToken == "function", r = typeof ((h = e.token) == null ? void 0 : h.getAccessToken) == "function", a = ((m = e.getAccessToken) == null ? void 0 : m.call(e)) ?? ((l = (d = e.token) == null ? void 0 : d.getAccessToken) == null ? void 0 : l.call(d));
|
|
39
|
-
return console.info("[http-request-sdk][token]", "access-token:resolve", {
|
|
40
|
-
hasGetAccessToken: s,
|
|
41
|
-
hasTokenGetAccessToken: r,
|
|
42
|
-
hasToken: !!a,
|
|
43
|
-
tokenLength: (a == null ? void 0 : a.length) ?? 0
|
|
44
|
-
}), a;
|
|
45
|
-
}, u = (s, r) => {
|
|
46
|
-
console.info("[http-request-sdk][token]", s, {
|
|
47
|
-
hasToken: !!r,
|
|
48
|
-
tokenLength: (r == null ? void 0 : r.length) ?? 0
|
|
49
|
-
});
|
|
50
|
-
}, x = () => {
|
|
51
|
-
var s, r, a;
|
|
52
|
-
return ((s = e.getLocale) == null ? void 0 : s.call(e)) ?? ((a = (r = e.locale) == null ? void 0 : r.getLocale) == null ? void 0 : a.call(r));
|
|
53
|
-
}, T = (s) => {
|
|
54
|
-
var r;
|
|
55
|
-
(r = e.onBusinessError) == null || r.call(e, s);
|
|
56
|
-
}, k = (s) => {
|
|
57
|
-
var r;
|
|
58
|
-
(r = e.onHttpError) == null || r.call(e, s);
|
|
59
|
-
}, y = (s) => {
|
|
60
|
-
var r, a;
|
|
61
|
-
(a = (r = e.ui) == null ? void 0 : r.error) == null || a.call(r, s);
|
|
62
|
-
}, R = (s) => {
|
|
63
|
-
var r, a;
|
|
64
|
-
(a = (r = e.ui) == null ? void 0 : r.warning) == null || a.call(r, s);
|
|
65
|
-
}, f = (s, r) => {
|
|
66
|
-
console.info("[http-request-sdk][permission-expired]", s, r ?? {});
|
|
67
|
-
}, S = () => t("api.accountExpired", "您的账号已失效,请重新登录"), A = async (s) => {
|
|
68
|
-
var m, d;
|
|
69
|
-
const r = {
|
|
70
|
-
...s,
|
|
71
|
-
message: S()
|
|
72
|
-
};
|
|
73
|
-
if (f("triggerTokenExpired:start", {
|
|
74
|
-
code: r.code,
|
|
75
|
-
message: r.message,
|
|
76
|
-
hasShowPermissionExpired: !!((m = e.ui) != null && m.showPermissionExpired),
|
|
77
|
-
modalVisible: n
|
|
78
|
-
}), n) {
|
|
79
|
-
f("triggerTokenExpired:skip-visible", {
|
|
80
|
-
code: r.code
|
|
81
|
-
});
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const a = () => {
|
|
85
|
-
n = !1, f("modal:visible-reset", {
|
|
86
|
-
code: r.code
|
|
87
|
-
});
|
|
88
|
-
}, h = async () => {
|
|
89
|
-
var l, w, c, p;
|
|
90
|
-
f("modal:onOk:start", {
|
|
91
|
-
code: r.code,
|
|
92
|
-
hasOnTokenExpired: !!e.onTokenExpired
|
|
93
|
-
});
|
|
94
|
-
try {
|
|
95
|
-
e.onTokenExpired ? await e.onTokenExpired(r) : (await ((w = (l = e.token) == null ? void 0 : l.logout) == null ? void 0 : w.call(l)), (p = (c = e.token) == null ? void 0 : c.clearToken) == null || p.call(c), z() && (window.location.href = G(e.loginUrl))), a(), f("modal:onOk:success", {
|
|
96
|
-
code: r.code
|
|
97
|
-
});
|
|
98
|
-
} catch (b) {
|
|
99
|
-
f("modal:onOk:error", {
|
|
100
|
-
code: r.code,
|
|
101
|
-
error: b
|
|
102
|
-
}), a();
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
if (n = !0, f("modal:visible-set", {
|
|
106
|
-
code: r.code
|
|
107
|
-
}), (d = e.ui) != null && d.showPermissionExpired) {
|
|
108
|
-
f("modal:showPermissionExpired:call", {
|
|
109
|
-
code: r.code
|
|
110
|
-
}), e.ui.showPermissionExpired({
|
|
111
|
-
title: t("api.permissionExpiredTitle", "权限失效提醒"),
|
|
112
|
-
content: r.message,
|
|
113
|
-
okText: t("api.permissionExpiredOkText", "我知道了"),
|
|
114
|
-
onOk: h,
|
|
115
|
-
onCancel: a
|
|
116
|
-
});
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (z()) {
|
|
120
|
-
f("modal:adapter-missing:native-alert", {
|
|
121
|
-
code: r.code
|
|
122
|
-
}), window.alert(
|
|
123
|
-
`${t("api.permissionExpiredTitle", "权限失效提醒")}
|
|
124
|
-
|
|
125
|
-
${r.message}`
|
|
126
|
-
), await h();
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
f("modal:adapter-missing:run-onOk-without-browser", {
|
|
130
|
-
code: r.code
|
|
131
|
-
}), await h();
|
|
132
|
-
}, E = (s) => {
|
|
133
|
-
var r, a, h, m, d;
|
|
134
|
-
if (s)
|
|
135
|
-
return s.accessToken && ((a = (r = e.token) == null ? void 0 : r.setToken) == null || a.call(r, s.accessToken)), s.refreshToken && ((m = (h = e.token) == null ? void 0 : h.setRefreshToken) == null || m.call(h, s.refreshToken)), (d = e.onRefreshTokenSuccess) == null || d.call(e, s), s.loginInfo;
|
|
136
|
-
}, q = async () => {
|
|
137
|
-
var h, m, d, l, w, c;
|
|
138
|
-
if (e.refreshAccessToken) {
|
|
139
|
-
const p = (m = (h = e.token) == null ? void 0 : h.getRefreshToken) == null ? void 0 : m.call(h);
|
|
140
|
-
u("refresh-token:custom-get-refresh-token", p);
|
|
141
|
-
const b = await e.refreshAccessToken({
|
|
142
|
-
refreshToken: p,
|
|
143
|
-
service: o
|
|
144
|
-
});
|
|
145
|
-
return E(b);
|
|
146
|
-
}
|
|
147
|
-
const s = (l = (d = e.token) == null ? void 0 : d.getRefreshToken) == null ? void 0 : l.call(d);
|
|
148
|
-
u("refresh-token:get-refresh-token", s);
|
|
149
|
-
const r = await L.post(
|
|
150
|
-
W(
|
|
151
|
-
e.refreshTokenUrl,
|
|
152
|
-
s,
|
|
153
|
-
e.baseURL ?? "/admin-api"
|
|
154
|
-
),
|
|
155
|
-
void 0,
|
|
156
|
-
{
|
|
157
|
-
headers: se(e.headers)
|
|
158
|
-
}
|
|
159
|
-
), a = ((c = (w = e.token) == null ? void 0 : w.normalizeRefreshResponse) == null ? void 0 : c.call(w, r)) ?? X(r);
|
|
160
|
-
if (a.code === 401 || a.code === 400)
|
|
161
|
-
throw new Error(S());
|
|
162
|
-
return E(a);
|
|
163
|
-
}, N = () => (i || (i = q().finally(() => {
|
|
164
|
-
i = null;
|
|
165
|
-
})), i);
|
|
166
|
-
o.interceptors.request.use(
|
|
167
|
-
(s) => {
|
|
168
|
-
const r = g();
|
|
169
|
-
u("request:get-access-token", r);
|
|
170
|
-
const a = x();
|
|
171
|
-
return r && M(
|
|
172
|
-
s,
|
|
173
|
-
e.authHeaderName ?? "Authorization",
|
|
174
|
-
Y(r, e.authScheme)
|
|
175
|
-
), a && M(s, e.localeHeaderName ?? "Accept-Language", a), te(s, e.headers), s;
|
|
176
|
-
},
|
|
177
|
-
(s) => {
|
|
178
|
-
var r;
|
|
179
|
-
return (r = e.onRequestError) == null || r.call(e, s), Promise.reject(s);
|
|
180
|
-
}
|
|
181
|
-
);
|
|
182
|
-
const U = (async (s) => {
|
|
183
|
-
var w;
|
|
184
|
-
if (s.config.responseType === "blob")
|
|
185
|
-
return Q(s, e, t);
|
|
186
|
-
if (s.status !== 200 && s.status !== 400) {
|
|
187
|
-
const c = t("api.networkExceptionMsg", "网络连接异常");
|
|
188
|
-
return y(c), k({ message: c, response: s }), Promise.reject(new Error(((w = s.data) == null ? void 0 : w.message) || "Error"));
|
|
189
|
-
}
|
|
190
|
-
const { code: r, msg: a, message: h, data: m } = s.data, l = a || h || t("api.systemException", "系统异常");
|
|
191
|
-
if (Number(r) === 400) {
|
|
192
|
-
const c = S();
|
|
193
|
-
return f("response:code-400:show-modal", {
|
|
194
|
-
httpStatus: s.status,
|
|
195
|
-
code: r,
|
|
196
|
-
message: c,
|
|
197
|
-
url: s.config.url
|
|
198
|
-
}), await A({ code: r, message: c, response: s }), T({ code: r, message: c, response: s }), Promise.reject(new Error(c));
|
|
199
|
-
}
|
|
200
|
-
if (ne(s, e)) {
|
|
201
|
-
f("response:should-refresh-token", {
|
|
202
|
-
httpStatus: s.status,
|
|
203
|
-
code: r,
|
|
204
|
-
message: l,
|
|
205
|
-
url: s.config.url
|
|
206
|
-
});
|
|
207
|
-
const c = s.config;
|
|
208
|
-
if (c._retry) {
|
|
209
|
-
const p = S();
|
|
210
|
-
return f("response:retry-already-used", {
|
|
211
|
-
code: r,
|
|
212
|
-
url: s.config.url
|
|
213
|
-
}), await A({ code: r, message: p, response: s }), Promise.reject(new Error(p));
|
|
214
|
-
}
|
|
215
|
-
c._retry = !0;
|
|
216
|
-
try {
|
|
217
|
-
return f("refresh-token:start", {
|
|
218
|
-
code: r,
|
|
219
|
-
url: s.config.url
|
|
220
|
-
}), await N(), f("refresh-token:success:retry-request", {
|
|
221
|
-
code: r,
|
|
222
|
-
url: s.config.url
|
|
223
|
-
}), o.request(c);
|
|
224
|
-
} catch (p) {
|
|
225
|
-
const b = S();
|
|
226
|
-
return f("refresh-token:error:trigger-modal", {
|
|
227
|
-
code: r,
|
|
228
|
-
url: s.config.url,
|
|
229
|
-
error: p
|
|
230
|
-
}), await A({
|
|
231
|
-
code: r,
|
|
232
|
-
message: b,
|
|
233
|
-
response: s,
|
|
234
|
-
error: p
|
|
235
|
-
}), Promise.reject(new Error(b));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (Number(r) === 403) {
|
|
239
|
-
const c = t("api.noPermissionOperation", "暂无操作权限");
|
|
240
|
-
return R(c), T({ code: r, message: c, response: s }), Promise.reject(new Error(c));
|
|
241
|
-
}
|
|
242
|
-
if (Number(r) === 510) {
|
|
243
|
-
const c = {
|
|
244
|
-
machineCode: B(m, "machineCode"),
|
|
245
|
-
expireTime: B(m, "expireTime"),
|
|
246
|
-
rawData: m
|
|
247
|
-
};
|
|
248
|
-
Z(c, s, e);
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if (Number(r) === 1002031003)
|
|
252
|
-
return T({ code: r, message: l, response: s }), Promise.reject(new Error(l));
|
|
253
|
-
if (!D(r, e.successCodes)) {
|
|
254
|
-
const c = j(
|
|
255
|
-
r,
|
|
256
|
-
l,
|
|
257
|
-
e.locale,
|
|
258
|
-
e.lang
|
|
259
|
-
);
|
|
260
|
-
return y(c), T({ code: r, message: c, response: s }), Promise.reject(new Error(c));
|
|
261
|
-
}
|
|
262
|
-
return e.transformResponse ? e.transformResponse(s.data) : e.unwrapData ? s.data.data : s.data;
|
|
263
|
-
});
|
|
264
|
-
return o.interceptors.response.use(U, (s) => {
|
|
265
|
-
var a, h;
|
|
266
|
-
const { response: r } = s;
|
|
267
|
-
if (r && ((a = r.config) == null ? void 0 : a.responseType) === "blob" && typeof Blob < "u" && r.data instanceof Blob)
|
|
268
|
-
r.data.text().then((m) => {
|
|
269
|
-
try {
|
|
270
|
-
const d = JSON.parse(m), l = j(
|
|
271
|
-
d.code,
|
|
272
|
-
d.msg || d.message,
|
|
273
|
-
e.locale,
|
|
274
|
-
e.lang
|
|
275
|
-
);
|
|
276
|
-
Number(d.code) === 403 ? R(t("api.noPermissionOperation", "暂无操作权限")) : y(l || t("api.exportFailed", "导出失败")), k({
|
|
277
|
-
code: d.code,
|
|
278
|
-
message: l || t("api.exportFailed", "导出失败"),
|
|
279
|
-
response: r,
|
|
280
|
-
error: s
|
|
281
|
-
});
|
|
282
|
-
} catch {
|
|
283
|
-
const d = t("api.exportFailed", "导出失败");
|
|
284
|
-
y(d), k({ message: d, response: r, error: s });
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
else if ((r == null ? void 0 : r.status) === 403) {
|
|
288
|
-
const m = t("api.noPermissionOperation", "暂无操作权限");
|
|
289
|
-
R(m), k({ code: 403, message: m, response: r, error: s });
|
|
290
|
-
} else if ((r == null ? void 0 : r.status) !== 404) {
|
|
291
|
-
const m = t("api.networkExceptionMsg", "网络连接异常");
|
|
292
|
-
y(m), k({ code: r == null ? void 0 : r.status, message: m, response: r, error: s });
|
|
293
|
-
}
|
|
294
|
-
return (h = e.onResponseError) == null || h.call(e, s), Promise.reject(s);
|
|
295
|
-
}), {
|
|
296
|
-
service: o,
|
|
297
|
-
refreshToken: q,
|
|
298
|
-
request: {
|
|
299
|
-
request: (s) => o.request(s),
|
|
300
|
-
get: (s, r = {}) => typeof s == "string" ? o.get(
|
|
301
|
-
s,
|
|
302
|
-
O(r)
|
|
303
|
-
) : o.request({
|
|
304
|
-
...s,
|
|
305
|
-
method: "get"
|
|
306
|
-
}),
|
|
307
|
-
post: (s, r, a = {}) => typeof s == "string" ? o.post(s, r, a) : o.request(
|
|
308
|
-
v(s, "post", r, a)
|
|
309
|
-
),
|
|
310
|
-
put: (s, r, a = {}) => typeof s == "string" ? o.put(s, r, a) : o.request(
|
|
311
|
-
v(s, "put", r, a)
|
|
312
|
-
),
|
|
313
|
-
patch: (s, r, a = {}) => typeof s == "string" ? o.patch(s, r, a) : o.request(
|
|
314
|
-
v(s, "patch", r, a)
|
|
315
|
-
),
|
|
316
|
-
delete: (s, r = {}) => typeof s == "string" ? o.delete(
|
|
317
|
-
s,
|
|
318
|
-
O(r)
|
|
319
|
-
) : o.request({
|
|
320
|
-
...s,
|
|
321
|
-
method: "delete"
|
|
322
|
-
})
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
}, X = (e) => {
|
|
326
|
-
const t = e.data.data, n = e.data;
|
|
327
|
-
return {
|
|
328
|
-
code: e.data.code,
|
|
329
|
-
accessToken: (t == null ? void 0 : t.accessToken) ?? n.accessToken,
|
|
330
|
-
refreshToken: (t == null ? void 0 : t.refreshToken) ?? n.refreshToken,
|
|
331
|
-
loginInfo: t
|
|
332
|
-
};
|
|
333
|
-
}, Q = async (e, t, n) => {
|
|
334
|
-
var g, u, x, T, k, y, R, f, S, A;
|
|
335
|
-
const i = ((g = e.headers) == null ? void 0 : g["content-type"]) || "";
|
|
336
|
-
if (!String(i).includes("application/json"))
|
|
337
|
-
return e.data;
|
|
338
|
-
const o = await e.data.text();
|
|
339
|
-
try {
|
|
340
|
-
const E = JSON.parse(o);
|
|
341
|
-
if (Number(E.code) === 403) {
|
|
342
|
-
const N = n("api.noPermissionOperation", "暂无操作权限");
|
|
343
|
-
return (x = (u = t.ui) == null ? void 0 : u.warning) == null || x.call(u, N), (T = t.onBusinessError) == null || T.call(t, { code: E.code, message: N, response: e }), Promise.reject(new Error(N));
|
|
344
|
-
}
|
|
345
|
-
if (D(E.code, t.successCodes)) return e.data;
|
|
346
|
-
const q = j(
|
|
347
|
-
E.code,
|
|
348
|
-
E.msg || E.message,
|
|
349
|
-
t.locale,
|
|
350
|
-
t.lang
|
|
351
|
-
);
|
|
352
|
-
return (y = (k = t.ui) == null ? void 0 : k.error) == null || y.call(k, q), (R = t.onBusinessError) == null || R.call(t, { code: E.code, message: q, response: e }), Promise.reject(new Error(q));
|
|
353
|
-
} catch {
|
|
354
|
-
const E = n("api.exportFailed", "导出失败");
|
|
355
|
-
return (S = (f = t.ui) == null ? void 0 : f.error) == null || S.call(f, E), (A = t.onHttpError) == null || A.call(t, { message: E, response: e }), Promise.reject(new Error(E));
|
|
356
|
-
}
|
|
357
|
-
}, Z = (e, t, n) => {
|
|
358
|
-
var i, o, g, u, x;
|
|
359
|
-
if ((i = n.onAuthorizationExpired) == null || i.call(n, { payload: e, response: t }), ee(n)) {
|
|
360
|
-
re(e, n);
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
e.expireTime ? (g = (o = n.authorization) == null ? void 0 : o.openExpired) == null || g.call(o, e) : (x = (u = n.authorization) == null ? void 0 : u.open) == null || x.call(u, e);
|
|
364
|
-
}, ee = (e) => {
|
|
365
|
-
var n;
|
|
366
|
-
if ((n = e.authorization) != null && n.isInMicroApp)
|
|
367
|
-
return e.authorization.isInMicroApp();
|
|
368
|
-
if (!z()) return !1;
|
|
369
|
-
const t = window;
|
|
370
|
-
return !!(t.__MICRO_APP_ENVIRONMENT__ || t.__MICRO_APP_BASE_APPLICATION__);
|
|
371
|
-
}, re = (e, t) => {
|
|
372
|
-
var o, g, u, x;
|
|
373
|
-
if ((o = t.authorization) != null && o.dispatchMicroAppEvent) {
|
|
374
|
-
t.authorization.dispatchMicroAppEvent(e);
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
if (!z()) return;
|
|
378
|
-
const n = {
|
|
379
|
-
type: "authorization_expired",
|
|
380
|
-
machineCode: e.machineCode,
|
|
381
|
-
expireTime: e.expireTime
|
|
382
|
-
}, i = (g = t.authorization) == null ? void 0 : g.eventCenterName;
|
|
383
|
-
if (i) {
|
|
384
|
-
const k = window[i];
|
|
385
|
-
if (typeof (k == null ? void 0 : k.dispatch) == "function") {
|
|
386
|
-
k.dispatch({
|
|
387
|
-
myname: ((u = t.authorization) == null ? void 0 : u.microAppName) ?? i,
|
|
388
|
-
data: n
|
|
389
|
-
});
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
window.dispatchEvent(
|
|
394
|
-
new CustomEvent(((x = t.authorization) == null ? void 0 : x.eventName) ?? K, {
|
|
395
|
-
detail: n
|
|
396
|
-
})
|
|
397
|
-
);
|
|
398
|
-
}, B = (e, t) => {
|
|
399
|
-
if (!e || typeof e != "object") return;
|
|
400
|
-
const n = e;
|
|
401
|
-
return typeof n[t] == "string" ? n[t] : void 0;
|
|
402
|
-
}, M = (e, t, n) => {
|
|
403
|
-
const i = e.headers;
|
|
404
|
-
if (i && typeof i.set == "function") {
|
|
405
|
-
i.set(t, String(n));
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
e.headers[t] = String(n);
|
|
409
|
-
}, te = (e, t) => {
|
|
410
|
-
Object.entries(t ?? {}).forEach(([n, i]) => {
|
|
411
|
-
i != null && M(e, n, i);
|
|
412
|
-
});
|
|
413
|
-
}, se = (e) => Object.entries(e ?? {}).reduce(
|
|
414
|
-
(t, [n, i]) => (i == null || (t[n] = String(i)), t),
|
|
415
|
-
{}
|
|
416
|
-
), ne = (e, t) => {
|
|
417
|
-
var n;
|
|
418
|
-
return t.shouldRefreshToken ? t.shouldRefreshToken(e) : Number((n = e.data) == null ? void 0 : n.code) === 401;
|
|
419
|
-
}, v = (e, t, n, i = {}) => ({
|
|
420
|
-
...i,
|
|
421
|
-
...e,
|
|
422
|
-
method: t,
|
|
423
|
-
data: e.data ?? n ?? i.data
|
|
424
|
-
}), O = (e) => e ? ie(e) ? e : {
|
|
425
|
-
params: e
|
|
426
|
-
} : {}, ae = /* @__PURE__ */ new Set([
|
|
427
|
-
"adapter",
|
|
428
|
-
"auth",
|
|
429
|
-
"baseURL",
|
|
430
|
-
"cancelToken",
|
|
431
|
-
"data",
|
|
432
|
-
"decompress",
|
|
433
|
-
"headers",
|
|
434
|
-
"httpAgent",
|
|
435
|
-
"httpsAgent",
|
|
436
|
-
"maxBodyLength",
|
|
437
|
-
"maxContentLength",
|
|
438
|
-
"method",
|
|
439
|
-
"onDownloadProgress",
|
|
440
|
-
"onUploadProgress",
|
|
441
|
-
"params",
|
|
442
|
-
"paramsSerializer",
|
|
443
|
-
"proxy",
|
|
444
|
-
"responseEncoding",
|
|
445
|
-
"responseType",
|
|
446
|
-
"signal",
|
|
447
|
-
"socketPath",
|
|
448
|
-
"timeout",
|
|
449
|
-
"timeoutErrorMessage",
|
|
450
|
-
"transformRequest",
|
|
451
|
-
"transformResponse",
|
|
452
|
-
"transitional",
|
|
453
|
-
"url",
|
|
454
|
-
"validateStatus",
|
|
455
|
-
"withCredentials",
|
|
456
|
-
"xsrfCookieName",
|
|
457
|
-
"xsrfHeaderName"
|
|
458
|
-
]), ie = (e) => !e || typeof e != "object" || typeof URLSearchParams < "u" && e instanceof URLSearchParams ? !1 : Object.keys(e).some((t) => ae.has(t));
|
|
459
|
-
let _ = null;
|
|
460
|
-
const ce = (e) => {
|
|
461
|
-
const t = J(e);
|
|
462
|
-
return _ = t, t;
|
|
463
|
-
}, ue = (e) => (_ = e, e), P = () => {
|
|
464
|
-
if (!_)
|
|
465
|
-
throw new Error(
|
|
466
|
-
"Request SDK is not initialized. Call setupRequestSdk(...) or install the Vue plugin first."
|
|
467
|
-
);
|
|
468
|
-
return _;
|
|
469
|
-
}, de = {
|
|
470
|
-
request: (e) => P().request.request(e),
|
|
471
|
-
get: (e, t) => P().request.get(
|
|
472
|
-
e,
|
|
473
|
-
t
|
|
474
|
-
),
|
|
475
|
-
post: (e, t, n) => P().request.post(e, t, n),
|
|
476
|
-
put: (e, t, n) => P().request.put(e, t, n),
|
|
477
|
-
patch: (e, t, n) => P().request.patch(e, t, n),
|
|
478
|
-
delete: (e, t) => P().request.delete(
|
|
479
|
-
e,
|
|
480
|
-
t
|
|
481
|
-
)
|
|
482
|
-
}, me = new Proxy(
|
|
483
|
-
{},
|
|
484
|
-
{
|
|
485
|
-
get(e, t) {
|
|
486
|
-
return Reflect.get(P().service, t);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
);
|
|
490
|
-
export {
|
|
491
|
-
K as A,
|
|
492
|
-
P as a,
|
|
493
|
-
Y as b,
|
|
494
|
-
J as c,
|
|
495
|
-
ce as d,
|
|
496
|
-
$ as e,
|
|
497
|
-
j as g,
|
|
498
|
-
me as h,
|
|
499
|
-
D as i,
|
|
500
|
-
de as r,
|
|
501
|
-
ue as s
|
|
502
|
-
};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";const O=require("axios"),$=[0,200],W={"api.accountExpired":"Your account has expired. Please log in again.","api.permissionExpiredTitle":"Permission expired","api.permissionExpiredContent":"Your account has expired. Please log in again.","api.permissionExpiredOkText":"OK","api.networkExceptionMsg":"Network connection error","api.systemException":"System error","api.noPermissionOperation":"No permission to perform this operation","api.exportFailed":"Export failed","api.tokenExpired":"Your account has expired. Please log in again."},C=(e,t,n)=>G(n)?W[e]??t??e:t??e,G=e=>typeof e=="string"&&e.toLowerCase().startsWith("en"),I=e=>{var c,g,u;if(typeof e!="string")return;const t=((c=e.match(/【([^】]+)】/))==null?void 0:c[1])||((g=e.match(/\(([^)]+)\)/))==null?void 0:g[1]),n=(u=e.match(/原因[::]\s*(.+)$/))==null?void 0:u[1],i={};return t&&(i.value=t),n&&(i.reason=n),Object.keys(i).length?i:void 0},Y=(e,t)=>(n,i,c)=>{var u;const g=(u=e==null?void 0:e.translate)==null?void 0:u.call(e,n,i,c);return g&&g!==n?g:C(n,i,t)},_=(e,t,n,i)=>{var T,x;const g=`api.errMsg${String(e??"")}`,u=(T=n==null?void 0:n.translate)==null?void 0:T.call(n,g,void 0,I(t));return u&&u!==g?u:typeof t=="string"&&t||((x=n==null?void 0:n.translate)==null?void 0:x.call(n,"api.systemException","系统异常"))||C("api.systemException","系统异常",i)},K=(e,t,n="/admin-api")=>typeof e=="function"?e(t):e??`${n}/system/auth/refresh-token?refreshToken=${t??""}`,X=e=>typeof e=="function"?e():e??"/login",L=(e,t=$)=>t.some(n=>String(n)===String(e)),U=(e,t="Bearer")=>typeof t=="function"?t(e):t?`${t} ${e}`:e,z=()=>typeof window<"u"&&typeof document<"u",H="http-request-sdk:authorization-expired",V=(e={})=>{const t=Y(e.locale,e.lang);let n=!1,i=null;const c=O.create({baseURL:e.baseURL??"/admin-api",timeout:e.timeout??3e4,validateStatus:s=>s>=200&&s<300||s===400,headers:{"Content-Type":"application/json;charset=UTF-8"},...e.axiosConfig}),g=()=>{var h,f,d,l;const s=typeof e.getAccessToken=="function",r=typeof((h=e.token)==null?void 0:h.getAccessToken)=="function",a=((f=e.getAccessToken)==null?void 0:f.call(e))??((l=(d=e.token)==null?void 0:d.getAccessToken)==null?void 0:l.call(d));return console.info("[http-request-sdk][token]","access-token:resolve",{hasGetAccessToken:s,hasTokenGetAccessToken:r,hasToken:!!a,tokenLength:(a==null?void 0:a.length)??0}),a},u=(s,r)=>{console.info("[http-request-sdk][token]",s,{hasToken:!!r,tokenLength:(r==null?void 0:r.length)??0})},T=()=>{var s,r,a;return((s=e.getLocale)==null?void 0:s.call(e))??((a=(r=e.locale)==null?void 0:r.getLocale)==null?void 0:a.call(r))},x=s=>{var r;(r=e.onBusinessError)==null||r.call(e,s)},k=s=>{var r;(r=e.onHttpError)==null||r.call(e,s)},y=s=>{var r,a;(a=(r=e.ui)==null?void 0:r.error)==null||a.call(r,s)},P=s=>{var r,a;(a=(r=e.ui)==null?void 0:r.warning)==null||a.call(r,s)},m=(s,r)=>{console.info("[http-request-sdk][permission-expired]",s,r??{})},S=()=>t("api.accountExpired","您的账号已失效,请重新登录"),q=async s=>{var f,d;const r={...s,message:S()};if(m("triggerTokenExpired:start",{code:r.code,message:r.message,hasShowPermissionExpired:!!((f=e.ui)!=null&&f.showPermissionExpired),modalVisible:n}),n){m("triggerTokenExpired:skip-visible",{code:r.code});return}const a=()=>{n=!1,m("modal:visible-reset",{code:r.code})},h=async()=>{var l,w,o,p;m("modal:onOk:start",{code:r.code,hasOnTokenExpired:!!e.onTokenExpired});try{e.onTokenExpired?await e.onTokenExpired(r):(await((w=(l=e.token)==null?void 0:l.logout)==null?void 0:w.call(l)),(p=(o=e.token)==null?void 0:o.clearToken)==null||p.call(o),z()&&(window.location.href=X(e.loginUrl))),a(),m("modal:onOk:success",{code:r.code})}catch(b){m("modal:onOk:error",{code:r.code,error:b}),a()}};if(n=!0,m("modal:visible-set",{code:r.code}),(d=e.ui)!=null&&d.showPermissionExpired){m("modal:showPermissionExpired:call",{code:r.code}),e.ui.showPermissionExpired({title:t("api.permissionExpiredTitle","权限失效提醒"),content:r.message,okText:t("api.permissionExpiredOkText","我知道了"),onOk:h,onCancel:a});return}if(z()){m("modal:adapter-missing:native-alert",{code:r.code}),window.alert(`${t("api.permissionExpiredTitle","权限失效提醒")}
|
|
2
|
-
|
|
3
|
-
${r.message}`),await h();return}m("modal:adapter-missing:run-onOk-without-browser",{code:r.code}),await h()},E=s=>{var r,a,h,f,d;if(s)return s.accessToken&&((a=(r=e.token)==null?void 0:r.setToken)==null||a.call(r,s.accessToken)),s.refreshToken&&((f=(h=e.token)==null?void 0:h.setRefreshToken)==null||f.call(h,s.refreshToken)),(d=e.onRefreshTokenSuccess)==null||d.call(e,s),s.loginInfo},A=async()=>{var h,f,d,l,w,o;if(e.refreshAccessToken){const p=(f=(h=e.token)==null?void 0:h.getRefreshToken)==null?void 0:f.call(h);u("refresh-token:custom-get-refresh-token",p);const b=await e.refreshAccessToken({refreshToken:p,service:c});return E(b)}const s=(l=(d=e.token)==null?void 0:d.getRefreshToken)==null?void 0:l.call(d);u("refresh-token:get-refresh-token",s);const r=await O.post(K(e.refreshTokenUrl,s,e.baseURL??"/admin-api"),void 0,{headers:se(e.headers)}),a=((o=(w=e.token)==null?void 0:w.normalizeRefreshResponse)==null?void 0:o.call(w,r))??J(r);if(a.code===401||a.code===400)throw new Error(S());return E(a)},N=()=>(i||(i=A().finally(()=>{i=null})),i);c.interceptors.request.use(s=>{const r=g();u("request:get-access-token",r);const a=T();return r&&j(s,e.authHeaderName??"Authorization",U(r,e.authScheme)),a&&j(s,e.localeHeaderName??"Accept-Language",a),te(s,e.headers),s},s=>{var r;return(r=e.onRequestError)==null||r.call(e,s),Promise.reject(s)});const F=(async s=>{var w;if(s.config.responseType==="blob")return Z(s,e,t);if(s.status!==200&&s.status!==400){const o=t("api.networkExceptionMsg","网络连接异常");return y(o),k({message:o,response:s}),Promise.reject(new Error(((w=s.data)==null?void 0:w.message)||"Error"))}const{code:r,msg:a,message:h,data:f}=s.data,l=a||h||t("api.systemException","系统异常");if(Number(r)===400){const o=S();return m("response:code-400:show-modal",{httpStatus:s.status,code:r,message:o,url:s.config.url}),await q({code:r,message:o,response:s}),x({code:r,message:o,response:s}),Promise.reject(new Error(o))}if(ne(s,e)){m("response:should-refresh-token",{httpStatus:s.status,code:r,message:l,url:s.config.url});const o=s.config;if(o._retry){const p=S();return m("response:retry-already-used",{code:r,url:s.config.url}),await q({code:r,message:p,response:s}),Promise.reject(new Error(p))}o._retry=!0;try{return m("refresh-token:start",{code:r,url:s.config.url}),await N(),m("refresh-token:success:retry-request",{code:r,url:s.config.url}),c.request(o)}catch(p){const b=S();return m("refresh-token:error:trigger-modal",{code:r,url:s.config.url,error:p}),await q({code:r,message:b,response:s,error:p}),Promise.reject(new Error(b))}}if(Number(r)===403){const o=t("api.noPermissionOperation","暂无操作权限");return P(o),x({code:r,message:o,response:s}),Promise.reject(new Error(o))}if(Number(r)===510){const o={machineCode:B(f,"machineCode"),expireTime:B(f,"expireTime"),rawData:f};Q(o,s,e);return}if(Number(r)===1002031003)return x({code:r,message:l,response:s}),Promise.reject(new Error(l));if(!L(r,e.successCodes)){const o=_(r,l,e.locale,e.lang);return y(o),x({code:r,message:o,response:s}),Promise.reject(new Error(o))}return e.transformResponse?e.transformResponse(s.data):e.unwrapData?s.data.data:s.data});return c.interceptors.response.use(F,s=>{var a,h;const{response:r}=s;if(r&&((a=r.config)==null?void 0:a.responseType)==="blob"&&typeof Blob<"u"&&r.data instanceof Blob)r.data.text().then(f=>{try{const d=JSON.parse(f),l=_(d.code,d.msg||d.message,e.locale,e.lang);Number(d.code)===403?P(t("api.noPermissionOperation","暂无操作权限")):y(l||t("api.exportFailed","导出失败")),k({code:d.code,message:l||t("api.exportFailed","导出失败"),response:r,error:s})}catch{const d=t("api.exportFailed","导出失败");y(d),k({message:d,response:r,error:s})}});else if((r==null?void 0:r.status)===403){const f=t("api.noPermissionOperation","暂无操作权限");P(f),k({code:403,message:f,response:r,error:s})}else if((r==null?void 0:r.status)!==404){const f=t("api.networkExceptionMsg","网络连接异常");y(f),k({code:r==null?void 0:r.status,message:f,response:r,error:s})}return(h=e.onResponseError)==null||h.call(e,s),Promise.reject(s)}),{service:c,refreshToken:A,request:{request:s=>c.request(s),get:(s,r={})=>typeof s=="string"?c.get(s,D(r)):c.request({...s,method:"get"}),post:(s,r,a={})=>typeof s=="string"?c.post(s,r,a):c.request(M(s,"post",r,a)),put:(s,r,a={})=>typeof s=="string"?c.put(s,r,a):c.request(M(s,"put",r,a)),patch:(s,r,a={})=>typeof s=="string"?c.patch(s,r,a):c.request(M(s,"patch",r,a)),delete:(s,r={})=>typeof s=="string"?c.delete(s,D(r)):c.request({...s,method:"delete"})}}},J=e=>{const t=e.data.data,n=e.data;return{code:e.data.code,accessToken:(t==null?void 0:t.accessToken)??n.accessToken,refreshToken:(t==null?void 0:t.refreshToken)??n.refreshToken,loginInfo:t}},Z=async(e,t,n)=>{var g,u,T,x,k,y,P,m,S,q;const i=((g=e.headers)==null?void 0:g["content-type"])||"";if(!String(i).includes("application/json"))return e.data;const c=await e.data.text();try{const E=JSON.parse(c);if(Number(E.code)===403){const N=n("api.noPermissionOperation","暂无操作权限");return(T=(u=t.ui)==null?void 0:u.warning)==null||T.call(u,N),(x=t.onBusinessError)==null||x.call(t,{code:E.code,message:N,response:e}),Promise.reject(new Error(N))}if(L(E.code,t.successCodes))return e.data;const A=_(E.code,E.msg||E.message,t.locale,t.lang);return(y=(k=t.ui)==null?void 0:k.error)==null||y.call(k,A),(P=t.onBusinessError)==null||P.call(t,{code:E.code,message:A,response:e}),Promise.reject(new Error(A))}catch{const E=n("api.exportFailed","导出失败");return(S=(m=t.ui)==null?void 0:m.error)==null||S.call(m,E),(q=t.onHttpError)==null||q.call(t,{message:E,response:e}),Promise.reject(new Error(E))}},Q=(e,t,n)=>{var i,c,g,u,T;if((i=n.onAuthorizationExpired)==null||i.call(n,{payload:e,response:t}),ee(n)){re(e,n);return}e.expireTime?(g=(c=n.authorization)==null?void 0:c.openExpired)==null||g.call(c,e):(T=(u=n.authorization)==null?void 0:u.open)==null||T.call(u,e)},ee=e=>{var n;if((n=e.authorization)!=null&&n.isInMicroApp)return e.authorization.isInMicroApp();if(!z())return!1;const t=window;return!!(t.__MICRO_APP_ENVIRONMENT__||t.__MICRO_APP_BASE_APPLICATION__)},re=(e,t)=>{var c,g,u,T;if((c=t.authorization)!=null&&c.dispatchMicroAppEvent){t.authorization.dispatchMicroAppEvent(e);return}if(!z())return;const n={type:"authorization_expired",machineCode:e.machineCode,expireTime:e.expireTime},i=(g=t.authorization)==null?void 0:g.eventCenterName;if(i){const k=window[i];if(typeof(k==null?void 0:k.dispatch)=="function"){k.dispatch({myname:((u=t.authorization)==null?void 0:u.microAppName)??i,data:n});return}}window.dispatchEvent(new CustomEvent(((T=t.authorization)==null?void 0:T.eventName)??H,{detail:n}))},B=(e,t)=>{if(!e||typeof e!="object")return;const n=e;return typeof n[t]=="string"?n[t]:void 0},j=(e,t,n)=>{const i=e.headers;if(i&&typeof i.set=="function"){i.set(t,String(n));return}e.headers[t]=String(n)},te=(e,t)=>{Object.entries(t??{}).forEach(([n,i])=>{i!=null&&j(e,n,i)})},se=e=>Object.entries(e??{}).reduce((t,[n,i])=>(i==null||(t[n]=String(i)),t),{}),ne=(e,t)=>{var n;return t.shouldRefreshToken?t.shouldRefreshToken(e):Number((n=e.data)==null?void 0:n.code)===401},M=(e,t,n,i={})=>({...i,...e,method:t,data:e.data??n??i.data}),D=e=>e?ie(e)?e:{params:e}:{},ae=new Set(["adapter","auth","baseURL","cancelToken","data","decompress","headers","httpAgent","httpsAgent","maxBodyLength","maxContentLength","method","onDownloadProgress","onUploadProgress","params","paramsSerializer","proxy","responseEncoding","responseType","signal","socketPath","timeout","timeoutErrorMessage","transformRequest","transformResponse","transitional","url","validateStatus","withCredentials","xsrfCookieName","xsrfHeaderName"]),ie=e=>!e||typeof e!="object"||typeof URLSearchParams<"u"&&e instanceof URLSearchParams?!1:Object.keys(e).some(t=>ae.has(t));let v=null;const ce=e=>{const t=V(e);return v=t,t},oe=e=>(v=e,e),R=()=>{if(!v)throw new Error("Request SDK is not initialized. Call setupRequestSdk(...) or install the Vue plugin first.");return v},ue={request:e=>R().request.request(e),get:(e,t)=>R().request.get(e,t),post:(e,t,n)=>R().request.post(e,t,n),put:(e,t,n)=>R().request.put(e,t,n),patch:(e,t,n)=>R().request.patch(e,t,n),delete:(e,t)=>R().request.delete(e,t)},de=new Proxy({},{get(e,t){return Reflect.get(R().service,t)}});exports.AUTHORIZATION_EXPIRED_EVENT=H;exports.buildAuthHeaderValue=U;exports.createRequestSdk=V;exports.extractI18nParams=I;exports.getBizErrorMsg=_;exports.getDefaultRequestSdk=R;exports.http=de;exports.isSuccessCode=L;exports.request=ue;exports.setDefaultRequestSdk=oe;exports.setupRequestSdk=ce;
|