@yuntijs/arcadia-bff-sdk 1.0.76 → 1.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.
- package/dist/esm/errors/handler.js +3 -2
- package/dist/esm/errors/modal.js +1 -1
- package/dist/esm/errors/notification.js +5 -7
- package/dist/esm/index.js +7 -0
- package/dist/esm/useSWR.js +4 -3
- package/dist/esm/utils.d.ts +4 -0
- package/dist/esm/utils.js +6 -0
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -3
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { showInvalidTokenModal } from "./modal";
|
|
2
2
|
import { showForbiddenNotification } from "./notification";
|
|
3
|
+
import { isBrowser } from "../utils";
|
|
3
4
|
export var errorsHandler = function errorsHandler(errors) {
|
|
4
5
|
var gqlErrors = errors.filter(function (e) {
|
|
5
6
|
var _e$extensions;
|
|
6
7
|
return typeof ((_e$extensions = e.extensions) === null || _e$extensions === void 0 ? void 0 : _e$extensions.code) !== "undefined";
|
|
7
8
|
});
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
console.warn("gql errors =>", errors);
|
|
10
|
+
if (gqlErrors.length === 0 || !isBrowser()) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
gqlErrors.forEach(function (e) {
|
package/dist/esm/errors/modal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-ignore
|
|
3
|
-
import
|
|
3
|
+
import notification from "antd/es/notification";
|
|
4
4
|
var VERBS_MAP = {
|
|
5
5
|
create: "创建",
|
|
6
6
|
delete: "删除",
|
|
@@ -25,18 +25,16 @@ export var showForbiddenNotification = function showForbiddenNotification(error)
|
|
|
25
25
|
if (name) {
|
|
26
26
|
description += " ".concat(name);
|
|
27
27
|
}
|
|
28
|
-
notification.
|
|
28
|
+
notification.warning({
|
|
29
29
|
message: "当前操作未被授权",
|
|
30
|
-
description: description
|
|
31
|
-
detail: error
|
|
30
|
+
description: description
|
|
32
31
|
});
|
|
33
32
|
};
|
|
34
33
|
export var showGlobalErrorNotification = function showGlobalErrorNotification(error) {
|
|
35
34
|
var _ref2 = error || {},
|
|
36
35
|
message = _ref2.message;
|
|
37
|
-
notification.
|
|
36
|
+
notification.warning({
|
|
38
37
|
message: "请求错误",
|
|
39
|
-
description: message
|
|
40
|
-
detail: error
|
|
38
|
+
description: message
|
|
41
39
|
});
|
|
42
40
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -21,11 +21,15 @@ import qs from "query-string";
|
|
|
21
21
|
import { useMemo } from "react";
|
|
22
22
|
import { errorsHandler } from "./errors";
|
|
23
23
|
import { getSdk, getSdkWithHooks } from "./sdk";
|
|
24
|
+
import { isBrowser } from "./utils";
|
|
24
25
|
export * from "graphql-request";
|
|
25
26
|
export * from "./errors";
|
|
26
27
|
export * from "./sdk";
|
|
27
28
|
var AUTH_DATA = "authData";
|
|
28
29
|
var getAuthData = function getAuthData() {
|
|
30
|
+
if (!isBrowser()) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
29
33
|
try {
|
|
30
34
|
var authData = JSON.parse(window.localStorage.getItem(AUTH_DATA) || "{}");
|
|
31
35
|
return authData;
|
|
@@ -70,6 +74,9 @@ export var responseMiddleware = function responseMiddleware(response) {
|
|
|
70
74
|
}
|
|
71
75
|
};
|
|
72
76
|
var endpoint = "/kubeagi-apis/bff";
|
|
77
|
+
if (!isBrowser()) {
|
|
78
|
+
endpoint = (process.env.BFF_SERVER_ORIGIN || "") + endpoint;
|
|
79
|
+
}
|
|
73
80
|
export var client = new GraphQLClient(endpoint, {
|
|
74
81
|
requestMiddleware: requestMiddleware,
|
|
75
82
|
responseMiddleware: responseMiddleware
|
package/dist/esm/useSWR.js
CHANGED
|
@@ -11,13 +11,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
11
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
12
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
13
|
import __useSWR from "swr";
|
|
14
|
+
import { isBrowser } from "./utils";
|
|
14
15
|
var SWR_ONFOCUS = "swr_revalidateOnFocus"; // 聚焦时重新请求
|
|
15
16
|
var SWR_IFSTALE = "swr_revalidateIfStale"; // 控制SWR在挂载并且存在陈旧数据时重新请求
|
|
16
17
|
var SWR_ONRECONNECT = "swr_revalidateOnReconnect"; // 重新连接时重新请求
|
|
17
18
|
var defaultConfig = {
|
|
18
|
-
revalidateOnFocus: window.localStorage.getItem(SWR_ONFOCUS) !== "false",
|
|
19
|
-
revalidateIfStale: window.localStorage.getItem(SWR_IFSTALE) !== "false",
|
|
20
|
-
revalidateOnReconnect: window.localStorage.getItem(SWR_ONRECONNECT) !== "false"
|
|
19
|
+
revalidateOnFocus: isBrowser() ? window.localStorage.getItem(SWR_ONFOCUS) !== "false" : true,
|
|
20
|
+
revalidateIfStale: isBrowser() ? window.localStorage.getItem(SWR_IFSTALE) !== "false" : true,
|
|
21
|
+
revalidateOnReconnect: isBrowser() ? window.localStorage.getItem(SWR_ONRECONNECT) !== "false" : true
|
|
21
22
|
};
|
|
22
23
|
export var useSWR = function useSWR(key, fetcher, config) {
|
|
23
24
|
var _response;
|