@yuntijs/arcadia-bff-sdk 1.0.75 → 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.
@@ -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
- if (gqlErrors.length === 0) {
9
- console.warn("uncaught errors", errors);
9
+ console.warn("gql errors =>", errors);
10
+ if (gqlErrors.length === 0 || !isBrowser()) {
10
11
  return;
11
12
  }
12
13
  gqlErrors.forEach(function (e) {
@@ -1,4 +1,4 @@
1
- import { Modal } from "antd";
1
+ import Modal from "antd/es/modal";
2
2
  export var logout = function logout() {
3
3
  window.location.href = "/logout";
4
4
  };
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
2
  // @ts-ignore
3
- import { notification } from "@tenx-ui/materials";
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.warn({
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.warn({
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/sdk.d.ts CHANGED
@@ -1002,7 +1002,7 @@ export type Gpt = {
1002
1002
  /** displayName: 展示名称 */
1003
1003
  displayName?: Maybe<Scalars['String']['output']>;
1004
1004
  /** hot: 热度 */
1005
- hot?: Maybe<Scalars['Int']['output']>;
1005
+ hot?: Maybe<Scalars['Int64']['output']>;
1006
1006
  /** icon: base64的图标 */
1007
1007
  icon?: Maybe<Scalars['String']['output']>;
1008
1008
  /** name: 集群内唯一名称,实际是app的 namespace/name */
@@ -3429,7 +3429,7 @@ export type GetGptQuery = {
3429
3429
  name?: string | null;
3430
3430
  displayName?: string | null;
3431
3431
  description?: string | null;
3432
- hot?: number | null;
3432
+ hot?: any | null;
3433
3433
  creator?: string | null;
3434
3434
  category?: Array<string | null> | null;
3435
3435
  icon?: string | null;
@@ -3465,7 +3465,7 @@ export type ListGpTsQuery = {
3465
3465
  name?: string | null;
3466
3466
  displayName?: string | null;
3467
3467
  description?: string | null;
3468
- hot?: number | null;
3468
+ hot?: any | null;
3469
3469
  creator?: string | null;
3470
3470
  category?: Array<string | null> | null;
3471
3471
  icon?: string | null;
@@ -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;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * whether in browser env
3
+ */
4
+ export declare const isBrowser: () => boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * whether in browser env
3
+ */
4
+ export var isBrowser = function isBrowser() {
5
+ return typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
6
+ };