@whitesev/utils 1.5.8 → 1.5.9
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/index.amd.js +38 -16
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +38 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +38 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +38 -16
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +38 -16
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +38 -16
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +14 -0
- package/dist/src/Utils.d.ts +1 -1
- package/dist/src/UtilsCommon.d.ts +4 -0
- package/package.json +1 -1
- package/src/Httpx.ts +38 -8
- package/src/Utils.ts +2 -15
- package/src/UtilsCommon.ts +20 -0
package/dist/src/Httpx.d.ts
CHANGED
|
@@ -902,6 +902,15 @@ export declare interface HttpxRequestInit extends RequestInit {
|
|
|
902
902
|
*/
|
|
903
903
|
window?: null;
|
|
904
904
|
}
|
|
905
|
+
/** 允许拦截配置 */
|
|
906
|
+
export declare interface HttpxAllowInterceptConfig {
|
|
907
|
+
/** 允许 beforeRequest */
|
|
908
|
+
beforeRequest: boolean;
|
|
909
|
+
/** 允许 afterResponse 的success回调 */
|
|
910
|
+
afterResponseSuccess: boolean;
|
|
911
|
+
/** 允许 afterResponse 的error回调 */
|
|
912
|
+
afterResponseError: boolean;
|
|
913
|
+
}
|
|
905
914
|
/**
|
|
906
915
|
* 请求的配置
|
|
907
916
|
*/
|
|
@@ -972,6 +981,11 @@ export declare interface HttpxDetails {
|
|
|
972
981
|
* 使用fetch请求的配置
|
|
973
982
|
*/
|
|
974
983
|
fetchInit?: HttpxRequestInit;
|
|
984
|
+
/**
|
|
985
|
+
* 拒绝拦截配置
|
|
986
|
+
* 如果设置了相关配置,那么intercept将不会生效
|
|
987
|
+
*/
|
|
988
|
+
allowInterceptConfig?: Partial<HttpxAllowInterceptConfig>;
|
|
975
989
|
/**
|
|
976
990
|
* 身份验证的用户名
|
|
977
991
|
*/
|
package/dist/src/Utils.d.ts
CHANGED
package/package.json
CHANGED
package/src/Httpx.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AnyObject, Utils } from "./Utils";
|
|
2
|
+
import { GenerateUUID } from "./UtilsCommon";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 状态码
|
|
@@ -998,6 +999,15 @@ export declare interface HttpxRequestInit extends RequestInit {
|
|
|
998
999
|
*/
|
|
999
1000
|
window?: null;
|
|
1000
1001
|
}
|
|
1002
|
+
/** 允许拦截配置 */
|
|
1003
|
+
export declare interface HttpxAllowInterceptConfig {
|
|
1004
|
+
/** 允许 beforeRequest */
|
|
1005
|
+
beforeRequest: boolean;
|
|
1006
|
+
/** 允许 afterResponse 的success回调 */
|
|
1007
|
+
afterResponseSuccess: boolean;
|
|
1008
|
+
/** 允许 afterResponse 的error回调 */
|
|
1009
|
+
afterResponseError: boolean;
|
|
1010
|
+
}
|
|
1001
1011
|
/**
|
|
1002
1012
|
* 请求的配置
|
|
1003
1013
|
*/
|
|
@@ -1068,6 +1078,11 @@ export declare interface HttpxDetails {
|
|
|
1068
1078
|
* 使用fetch请求的配置
|
|
1069
1079
|
*/
|
|
1070
1080
|
fetchInit?: HttpxRequestInit;
|
|
1081
|
+
/**
|
|
1082
|
+
* 拒绝拦截配置
|
|
1083
|
+
* 如果设置了相关配置,那么intercept将不会生效
|
|
1084
|
+
*/
|
|
1085
|
+
allowInterceptConfig?: Partial<HttpxAllowInterceptConfig>;
|
|
1071
1086
|
/**
|
|
1072
1087
|
* 身份验证的用户名
|
|
1073
1088
|
*/
|
|
@@ -1208,14 +1223,6 @@ export declare interface HttpxHookErrorData {
|
|
|
1208
1223
|
response: any;
|
|
1209
1224
|
}
|
|
1210
1225
|
|
|
1211
|
-
const GenerateUUID = () => {
|
|
1212
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
1213
|
-
var r = (Math.random() * 16) | 0,
|
|
1214
|
-
v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
1215
|
-
return v.toString(16);
|
|
1216
|
-
});
|
|
1217
|
-
};
|
|
1218
|
-
|
|
1219
1226
|
class Httpx {
|
|
1220
1227
|
private GM_Api = {
|
|
1221
1228
|
xmlHttpRequest: null as any,
|
|
@@ -1239,6 +1246,12 @@ class Httpx {
|
|
|
1239
1246
|
* @private
|
|
1240
1247
|
*/
|
|
1241
1248
|
beforeRequestCallBack(details: HttpxDetails) {
|
|
1249
|
+
if (!details.allowInterceptConfig) {
|
|
1250
|
+
return details;
|
|
1251
|
+
}
|
|
1252
|
+
if (!details.allowInterceptConfig.beforeRequest) {
|
|
1253
|
+
return details;
|
|
1254
|
+
}
|
|
1242
1255
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1243
1256
|
let item = this.$config.configList[index];
|
|
1244
1257
|
if (typeof item.fn === "function") {
|
|
@@ -1312,6 +1325,12 @@ class Httpx {
|
|
|
1312
1325
|
response: HttpxAsyncResultData,
|
|
1313
1326
|
details: HttpxDetails
|
|
1314
1327
|
) {
|
|
1328
|
+
if (!details.allowInterceptConfig) {
|
|
1329
|
+
return details;
|
|
1330
|
+
}
|
|
1331
|
+
if (!details.allowInterceptConfig.afterResponseSuccess) {
|
|
1332
|
+
return details;
|
|
1333
|
+
}
|
|
1315
1334
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1316
1335
|
let item = this.$config.configList[index];
|
|
1317
1336
|
if (typeof item.successFn === "function") {
|
|
@@ -1332,6 +1351,12 @@ class Httpx {
|
|
|
1332
1351
|
response: any;
|
|
1333
1352
|
details: HttpxDetails;
|
|
1334
1353
|
}) {
|
|
1354
|
+
if (!data.details.allowInterceptConfig) {
|
|
1355
|
+
return data;
|
|
1356
|
+
}
|
|
1357
|
+
if (!data.details.allowInterceptConfig.afterResponseError) {
|
|
1358
|
+
return data;
|
|
1359
|
+
}
|
|
1335
1360
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1336
1361
|
let item = this.$config.configList[index];
|
|
1337
1362
|
if (typeof item.errorFn === "function") {
|
|
@@ -2037,6 +2062,11 @@ class Httpx {
|
|
|
2037
2062
|
anonymous: void 0,
|
|
2038
2063
|
fetch: void 0,
|
|
2039
2064
|
fetchInit: void 0,
|
|
2065
|
+
allowInterceptConfig: {
|
|
2066
|
+
beforeRequest: true,
|
|
2067
|
+
afterResponseSuccess: true,
|
|
2068
|
+
afterResponseError: true,
|
|
2069
|
+
},
|
|
2040
2070
|
user: void 0,
|
|
2041
2071
|
password: void 0,
|
|
2042
2072
|
onabort() {},
|
package/src/Utils.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { DOMUtils_EventType } from "./Event";
|
|
|
16
16
|
import type { UtilsCoreOption } from "./UtilsCore";
|
|
17
17
|
import type { Vue2Object } from "./VueObject";
|
|
18
18
|
import type { UtilsAjaxHookResult } from "./AjaxHookerType";
|
|
19
|
+
import { GenerateUUID } from "./UtilsCommon";
|
|
19
20
|
|
|
20
21
|
export declare var unsafeWindow: Window & typeof globalThis;
|
|
21
22
|
|
|
@@ -4900,21 +4901,7 @@ class Utils {
|
|
|
4900
4901
|
* @example
|
|
4901
4902
|
* Utils.generateUUID()
|
|
4902
4903
|
*/
|
|
4903
|
-
generateUUID
|
|
4904
|
-
if (typeof globalThis?.crypto?.randomUUID === "function") {
|
|
4905
|
-
return globalThis.crypto.randomUUID();
|
|
4906
|
-
} else {
|
|
4907
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
4908
|
-
/[xy]/g,
|
|
4909
|
-
function (charStr) {
|
|
4910
|
-
var randomValue = (Math.random() * 16) | 0,
|
|
4911
|
-
randomCharValue =
|
|
4912
|
-
charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
4913
|
-
return randomCharValue.toString(16);
|
|
4914
|
-
}
|
|
4915
|
-
);
|
|
4916
|
-
}
|
|
4917
|
-
}
|
|
4904
|
+
generateUUID = GenerateUUID;
|
|
4918
4905
|
}
|
|
4919
4906
|
|
|
4920
4907
|
let utils = new Utils();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { UtilsCore } from "./UtilsCore";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 生成uuid
|
|
5
|
+
*/
|
|
6
|
+
export const GenerateUUID = function () {
|
|
7
|
+
if (typeof UtilsCore.globalThis?.crypto?.randomUUID === "function") {
|
|
8
|
+
return UtilsCore.globalThis.crypto.randomUUID();
|
|
9
|
+
} else {
|
|
10
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
11
|
+
/[xy]/g,
|
|
12
|
+
function (charStr) {
|
|
13
|
+
var randomValue = (Math.random() * 16) | 0,
|
|
14
|
+
randomCharValue =
|
|
15
|
+
charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
16
|
+
return randomCharValue.toString(16);
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
};
|