@gct-paas/api 0.1.6-dev.3 → 0.1.6-dev.5
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.esm.min.js +1 -1
- package/es/service/index.mjs +0 -2
- package/es/utils/index.d.ts +0 -1
- package/es/utils/index.mjs +0 -1
- package/package.json +1 -2
- package/es/service/request.client.d.ts +0 -6
- package/es/service/request.client.mjs +0 -35
- package/es/utils/native-http/native-http.d.ts +0 -6
- package/es/utils/native-http/native-http.mjs +0 -71
package/es/service/index.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { apiConfig as aPaasConfig } from "../apaas/index.mjs";
|
|
2
2
|
import { apiConfig as platformConfig } from "../platform/index.mjs";
|
|
3
3
|
import { ApiManage } from "./api-manage.mjs";
|
|
4
|
-
import { installHttpUtil } from "./request.client.mjs";
|
|
5
4
|
export const api = {
|
|
6
5
|
apaas: new ApiManage("/gct-apaas/api", aPaasConfig),
|
|
7
6
|
platform: new ApiManage("/gct-platform/api", platformConfig)
|
|
8
7
|
};
|
|
9
|
-
installHttpUtil();
|
|
10
8
|
export {
|
|
11
9
|
ResultEnum,
|
|
12
10
|
RequestEnum,
|
package/es/utils/index.d.ts
CHANGED
package/es/utils/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/api",
|
|
3
|
-
"version": "0.1.6-dev.
|
|
3
|
+
"version": "0.1.6-dev.5",
|
|
4
4
|
"description": "paas 平台底包",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"axios": "^1.16.0",
|
|
73
|
-
"dsbridge": "^3.1.4",
|
|
74
73
|
"lodash-es": "^4.18.1",
|
|
75
74
|
"qs": "^6.15.1"
|
|
76
75
|
},
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { NativeHTTP } from "../utils/index.mjs";
|
|
2
|
-
import { HttpUtil } from "./http.util.mjs";
|
|
3
|
-
export function installHttpUtil() {
|
|
4
|
-
if (window.__GCT_ANDROID__ !== true) {
|
|
5
|
-
console.debug("\u5F53\u524D\u73AF\u5883\u975E Android\uFF0C\u5DF2\u8DF3\u8FC7 HTTP \u5DE5\u5177\u7C7B\u5B89\u88C5");
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const nativeAdapter = async (config) => {
|
|
9
|
-
const response = await NativeHTTP.request(config);
|
|
10
|
-
return response;
|
|
11
|
-
};
|
|
12
|
-
HttpUtil._instance.defaults.adapter = nativeAdapter;
|
|
13
|
-
const errorHandler = (error) => {
|
|
14
|
-
if (error?.response?.status === 401) {
|
|
15
|
-
console.log("\u767B\u5F55\u4FE1\u606F\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55");
|
|
16
|
-
} else {
|
|
17
|
-
console.log("\u7F51\u7EDC\u5F02\u5E38\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
18
|
-
}
|
|
19
|
-
return Promise.reject(error);
|
|
20
|
-
};
|
|
21
|
-
HttpUtil._instance.interceptors.request.use((config) => {
|
|
22
|
-
config.headers["App-Tag"] = "__platform__";
|
|
23
|
-
return config;
|
|
24
|
-
}, errorHandler);
|
|
25
|
-
HttpUtil._instance.interceptors.response.use((response) => {
|
|
26
|
-
if (response.data.code === 200) {
|
|
27
|
-
return response.data.data;
|
|
28
|
-
}
|
|
29
|
-
const errorMessageMode = response.config?.errorMessageMode;
|
|
30
|
-
if (errorMessageMode !== "none") {
|
|
31
|
-
console.log(response.data.message);
|
|
32
|
-
}
|
|
33
|
-
return Promise.reject(response.data);
|
|
34
|
-
}, errorHandler);
|
|
35
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import dsBridge from "dsbridge";
|
|
2
|
-
import qs from "qs";
|
|
3
|
-
export const NativeHTTP = {
|
|
4
|
-
request(querydata) {
|
|
5
|
-
const {
|
|
6
|
-
method,
|
|
7
|
-
url,
|
|
8
|
-
timeout,
|
|
9
|
-
params,
|
|
10
|
-
headers,
|
|
11
|
-
data,
|
|
12
|
-
baseURL = ""
|
|
13
|
-
} = querydata;
|
|
14
|
-
const pathParam = "?" + qs.stringify(params);
|
|
15
|
-
const allUrl = (baseURL + url).replace(/([^:])\/\//g, "$1/") + pathParam;
|
|
16
|
-
console.info(allUrl + ">>HTTP", querydata);
|
|
17
|
-
const startTime = performance.now();
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
dsBridge.call(
|
|
20
|
-
"HTTP." + method,
|
|
21
|
-
{
|
|
22
|
-
url: allUrl,
|
|
23
|
-
timeout,
|
|
24
|
-
headers,
|
|
25
|
-
data: data && typeof data === "string" ? JSON.parse(data) : data
|
|
26
|
-
},
|
|
27
|
-
function(res) {
|
|
28
|
-
const nativeData = JSON.parse(res);
|
|
29
|
-
console.info(
|
|
30
|
-
`${allUrl} >> HTTP.response - \u8017\u65F6\uFF1A${performance.now() - startTime}`,
|
|
31
|
-
nativeData
|
|
32
|
-
);
|
|
33
|
-
if (nativeData.code === 0 && nativeData.http_code === 200) {
|
|
34
|
-
resolve({ ...nativeData, config: querydata });
|
|
35
|
-
} else {
|
|
36
|
-
const response = {
|
|
37
|
-
message: nativeData.message,
|
|
38
|
-
status: nativeData.http_code
|
|
39
|
-
};
|
|
40
|
-
reject({ response, config: querydata });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
urlDecode(arg) {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
return dsBridge.call("HTTP.urlDecode", arg, function(res) {
|
|
49
|
-
if (res) {
|
|
50
|
-
const data = JSON.parse(res);
|
|
51
|
-
if (data.code === 0) {
|
|
52
|
-
resolve(data.data);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
reject();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
urlDecodeSync(arg) {
|
|
61
|
-
if (!arg) return "";
|
|
62
|
-
const res = dsBridge.call("HTTP.urlDecodeSync", arg);
|
|
63
|
-
if (res) {
|
|
64
|
-
const data = JSON.parse(res);
|
|
65
|
-
if (data.code === 0) {
|
|
66
|
-
return data.data;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return "";
|
|
70
|
-
}
|
|
71
|
-
};
|