@yuntijs/arcadia-bff-sdk 1.2.4 → 1.2.6
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.d.ts +1 -1
- package/dist/esm/errors/handler.js +5 -6
- package/dist/esm/errors/index.d.ts +1 -1
- package/dist/esm/errors/modal.d.ts +1 -1
- package/dist/esm/errors/modal.js +4 -4
- package/dist/esm/errors/notification.d.ts +1 -1
- package/dist/esm/errors/notification.js +19 -17
- package/dist/esm/index.d.ts +27 -6
- package/dist/esm/index.js +10 -17
- package/dist/esm/sdk.d.ts +126 -0
- package/dist/esm/sdk.js +60 -47
- package/dist/esm/useSWR.d.ts +2 -2
- package/dist/esm/useSWR.js +8 -9
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +3 -5
- package/dist/esm/errors-taro/handler.d.ts +0 -3
- package/dist/esm/errors-taro/handler.js +0 -65
- package/dist/esm/errors-taro/index.d.ts +0 -1
- package/dist/esm/errors-taro/index.js +0 -1
- package/dist/esm/taro.d.ts +0 -981
- package/dist/esm/taro.js +0 -231
- package/dist/esm/utils.d.ts +0 -4
- package/dist/esm/utils.js +0 -6
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { showInvalidTokenModal } from "./modal";
|
|
2
2
|
import { showForbiddenNotification } from "./notification";
|
|
3
|
-
import { isBrowser } from "../utils";
|
|
4
3
|
export var errorsHandler = function errorsHandler(errors) {
|
|
5
4
|
var gqlErrors = errors.filter(function (e) {
|
|
6
5
|
var _e$extensions;
|
|
7
|
-
return typeof ((_e$extensions = e.extensions) === null || _e$extensions === void 0 ? void 0 : _e$extensions.code) !==
|
|
6
|
+
return typeof ((_e$extensions = e.extensions) === null || _e$extensions === void 0 ? void 0 : _e$extensions.code) !== "undefined";
|
|
8
7
|
});
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if (gqlErrors.length === 0) {
|
|
9
|
+
console.warn("uncaught errors", errors);
|
|
11
10
|
return;
|
|
12
11
|
}
|
|
13
12
|
gqlErrors.forEach(function (e) {
|
|
14
13
|
switch (e.extensions.code) {
|
|
15
|
-
case
|
|
14
|
+
case "InvalidToken":
|
|
16
15
|
showInvalidTokenModal(e);
|
|
17
16
|
break;
|
|
18
|
-
case
|
|
17
|
+
case "Forbidden":
|
|
19
18
|
showForbiddenNotification(e);
|
|
20
19
|
break;
|
|
21
20
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./handler";
|
package/dist/esm/errors/modal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Modal from
|
|
1
|
+
import { Modal } from "antd";
|
|
2
2
|
export var logout = function logout() {
|
|
3
|
-
window.location.href =
|
|
3
|
+
window.location.href = "/logout";
|
|
4
4
|
};
|
|
5
5
|
var InvalidTokenModal;
|
|
6
6
|
var onInvalidTokenModalCancel = function onInvalidTokenModalCancel() {
|
|
@@ -13,8 +13,8 @@ export var showInvalidTokenModal = function showInvalidTokenModal(error) {
|
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
InvalidTokenModal = Modal.warn({
|
|
16
|
-
okText:
|
|
17
|
-
content:
|
|
16
|
+
okText: "确定",
|
|
17
|
+
content: "用户凭证可能已失效,点击确定重新登录",
|
|
18
18
|
onOk: logout,
|
|
19
19
|
onCancel: onInvalidTokenModalCancel
|
|
20
20
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { GraphQLError } from
|
|
1
|
+
import { GraphQLError } from "graphql-request/src/types";
|
|
2
2
|
export declare const showForbiddenNotification: (error: GraphQLError) => void;
|
|
3
3
|
export declare const showGlobalErrorNotification: (error: GraphQLError) => void;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-ignore
|
|
3
|
-
import notification from
|
|
3
|
+
import { notification } from "@tenx-ui/materials";
|
|
4
4
|
var VERBS_MAP = {
|
|
5
|
-
create:
|
|
6
|
-
delete:
|
|
7
|
-
update:
|
|
8
|
-
patch:
|
|
9
|
-
get:
|
|
10
|
-
list:
|
|
11
|
-
watch:
|
|
5
|
+
create: "创建",
|
|
6
|
+
delete: "删除",
|
|
7
|
+
update: "更新",
|
|
8
|
+
patch: "更新",
|
|
9
|
+
get: "获取",
|
|
10
|
+
list: "列取",
|
|
11
|
+
watch: "监听"
|
|
12
12
|
};
|
|
13
13
|
export var showForbiddenNotification = function showForbiddenNotification(error) {
|
|
14
14
|
var _error$extensions;
|
|
@@ -16,25 +16,27 @@ export var showForbiddenNotification = function showForbiddenNotification(error)
|
|
|
16
16
|
name = _ref.name,
|
|
17
17
|
kind = _ref.kind,
|
|
18
18
|
_ref$verb = _ref.verb,
|
|
19
|
-
verb = _ref$verb === void 0 ?
|
|
20
|
-
var description =
|
|
21
|
-
description += "".concat(VERBS_MAP[verb] ||
|
|
19
|
+
verb = _ref$verb === void 0 ? "" : _ref$verb;
|
|
20
|
+
var description = "当前用户没有权限";
|
|
21
|
+
description += "".concat(VERBS_MAP[verb] || "操作");
|
|
22
22
|
if (kind) {
|
|
23
23
|
description += " ".concat(kind);
|
|
24
24
|
}
|
|
25
25
|
if (name) {
|
|
26
26
|
description += " ".concat(name);
|
|
27
27
|
}
|
|
28
|
-
notification.
|
|
29
|
-
message:
|
|
30
|
-
description: description
|
|
28
|
+
notification.warn({
|
|
29
|
+
message: "当前操作未被授权",
|
|
30
|
+
description: description,
|
|
31
|
+
detail: error
|
|
31
32
|
});
|
|
32
33
|
};
|
|
33
34
|
export var showGlobalErrorNotification = function showGlobalErrorNotification(error) {
|
|
34
35
|
var _ref2 = error || {},
|
|
35
36
|
message = _ref2.message;
|
|
36
|
-
notification.
|
|
37
|
-
message:
|
|
38
|
-
description: message
|
|
37
|
+
notification.warn({
|
|
38
|
+
message: "请求错误",
|
|
39
|
+
description: message,
|
|
40
|
+
detail: error
|
|
39
41
|
});
|
|
40
42
|
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { GraphQLClient } from
|
|
2
|
-
import type { RequestConfig, RequestMiddleware, Response } from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
import { GraphQLClient } from "graphql-request";
|
|
2
|
+
import type { RequestConfig, RequestMiddleware, Response } from "graphql-request/src/types";
|
|
3
|
+
export * from "graphql-request";
|
|
4
|
+
export * from "./errors";
|
|
5
|
+
export * from "./sdk";
|
|
6
6
|
export interface RequestOptions extends RequestInit {
|
|
7
7
|
url: string;
|
|
8
8
|
}
|
|
@@ -75,6 +75,9 @@ export declare const sdk: {
|
|
|
75
75
|
useListGpTs(variables: import("./sdk").Exact<{
|
|
76
76
|
input: import("./sdk").ListGptInput;
|
|
77
77
|
}>, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListGpTsQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListGpTsQuery, import("graphql-request/src/types").ClientError>;
|
|
78
|
+
useListGptCategory(variables?: import("./sdk").Exact<{
|
|
79
|
+
[key: string]: never;
|
|
80
|
+
}> | undefined, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListGptCategoryQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListGptCategoryQuery, import("graphql-request/src/types").ClientError>;
|
|
78
81
|
useListKnowledgeBases(variables: import("./sdk").Exact<{
|
|
79
82
|
input: import("./sdk").ListKnowledgeBaseInput;
|
|
80
83
|
}>, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListKnowledgeBasesQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListKnowledgeBasesQuery, import("graphql-request/src/types").ClientError>;
|
|
@@ -247,6 +250,9 @@ export declare const sdk: {
|
|
|
247
250
|
listGPTs(variables: import("./sdk").Exact<{
|
|
248
251
|
input: import("./sdk").ListGptInput;
|
|
249
252
|
}>, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListGpTsQuery>;
|
|
253
|
+
listGPTCategory(variables?: import("./sdk").Exact<{
|
|
254
|
+
[key: string]: never;
|
|
255
|
+
}> | undefined, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListGptCategoryQuery>;
|
|
250
256
|
listKnowledgeBases(variables: import("./sdk").Exact<{
|
|
251
257
|
input: import("./sdk").ListKnowledgeBaseInput;
|
|
252
258
|
}>, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListKnowledgeBasesQuery>;
|
|
@@ -373,7 +379,7 @@ interface SdkBaseOptions {
|
|
|
373
379
|
/** 请求配置项 */
|
|
374
380
|
requestConfig?: RequestConfig;
|
|
375
381
|
}
|
|
376
|
-
export type SdkOptions = Pick<SdkBaseOptions,
|
|
382
|
+
export type SdkOptions = Pick<SdkBaseOptions, "url" | "requestConfig">;
|
|
377
383
|
/**
|
|
378
384
|
* 初始化 GraphQL client 实例
|
|
379
385
|
*
|
|
@@ -498,6 +504,9 @@ export declare const initSdk: (options?: SdkOptions) => {
|
|
|
498
504
|
listGPTs(variables: import("./sdk").Exact<{
|
|
499
505
|
input: import("./sdk").ListGptInput;
|
|
500
506
|
}>, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListGpTsQuery>;
|
|
507
|
+
listGPTCategory(variables?: import("./sdk").Exact<{
|
|
508
|
+
[key: string]: never;
|
|
509
|
+
}> | undefined, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListGptCategoryQuery>;
|
|
501
510
|
listKnowledgeBases(variables: import("./sdk").Exact<{
|
|
502
511
|
input: import("./sdk").ListKnowledgeBaseInput;
|
|
503
512
|
}>, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListKnowledgeBasesQuery>;
|
|
@@ -686,6 +695,9 @@ export declare const initSdkWithHooks: (options?: SdkOptions) => {
|
|
|
686
695
|
useListGpTs(variables: import("./sdk").Exact<{
|
|
687
696
|
input: import("./sdk").ListGptInput;
|
|
688
697
|
}>, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListGpTsQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListGpTsQuery, import("graphql-request/src/types").ClientError>;
|
|
698
|
+
useListGptCategory(variables?: import("./sdk").Exact<{
|
|
699
|
+
[key: string]: never;
|
|
700
|
+
}> | undefined, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListGptCategoryQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListGptCategoryQuery, import("graphql-request/src/types").ClientError>;
|
|
689
701
|
useListKnowledgeBases(variables: import("./sdk").Exact<{
|
|
690
702
|
input: import("./sdk").ListKnowledgeBaseInput;
|
|
691
703
|
}>, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListKnowledgeBasesQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListKnowledgeBasesQuery, import("graphql-request/src/types").ClientError>;
|
|
@@ -858,6 +870,9 @@ export declare const initSdkWithHooks: (options?: SdkOptions) => {
|
|
|
858
870
|
listGPTs(variables: import("./sdk").Exact<{
|
|
859
871
|
input: import("./sdk").ListGptInput;
|
|
860
872
|
}>, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListGpTsQuery>;
|
|
873
|
+
listGPTCategory(variables?: import("./sdk").Exact<{
|
|
874
|
+
[key: string]: never;
|
|
875
|
+
}> | undefined, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListGptCategoryQuery>;
|
|
861
876
|
listKnowledgeBases(variables: import("./sdk").Exact<{
|
|
862
877
|
input: import("./sdk").ListKnowledgeBaseInput;
|
|
863
878
|
}>, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListKnowledgeBasesQuery>;
|
|
@@ -1046,6 +1061,9 @@ export declare const useSdk: (options?: SdkOptions) => {
|
|
|
1046
1061
|
useListGpTs(variables: import("./sdk").Exact<{
|
|
1047
1062
|
input: import("./sdk").ListGptInput;
|
|
1048
1063
|
}>, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListGpTsQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListGpTsQuery, import("graphql-request/src/types").ClientError>;
|
|
1064
|
+
useListGptCategory(variables?: import("./sdk").Exact<{
|
|
1065
|
+
[key: string]: never;
|
|
1066
|
+
}> | undefined, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListGptCategoryQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListGptCategoryQuery, import("graphql-request/src/types").ClientError>;
|
|
1049
1067
|
useListKnowledgeBases(variables: import("./sdk").Exact<{
|
|
1050
1068
|
input: import("./sdk").ListKnowledgeBaseInput;
|
|
1051
1069
|
}>, config?: Partial<import("swr/_internal").PublicConfiguration<import("./sdk").ListKnowledgeBasesQuery, import("graphql-request/src/types").ClientError, import("swr/_internal").BareFetcher<any>>> | undefined): import("./useSWR").SWRResponsePro<import("./sdk").ListKnowledgeBasesQuery, import("graphql-request/src/types").ClientError>;
|
|
@@ -1218,6 +1236,9 @@ export declare const useSdk: (options?: SdkOptions) => {
|
|
|
1218
1236
|
listGPTs(variables: import("./sdk").Exact<{
|
|
1219
1237
|
input: import("./sdk").ListGptInput;
|
|
1220
1238
|
}>, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListGpTsQuery>;
|
|
1239
|
+
listGPTCategory(variables?: import("./sdk").Exact<{
|
|
1240
|
+
[key: string]: never;
|
|
1241
|
+
}> | undefined, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListGptCategoryQuery>;
|
|
1221
1242
|
listKnowledgeBases(variables: import("./sdk").Exact<{
|
|
1222
1243
|
input: import("./sdk").ListKnowledgeBaseInput;
|
|
1223
1244
|
}>, requestHeaders?: import("graphql-request/src/types").MaybeFunction<(import("graphql-request/src/types.dom").Headers | Record<string, string> | string[][]) | undefined>): Promise<import("./sdk").ListKnowledgeBasesQuery>;
|
package/dist/esm/index.js
CHANGED
|
@@ -16,25 +16,21 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
16
16
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
17
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
18
18
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
19
|
-
import { GraphQLClient } from
|
|
20
|
-
import qs from
|
|
21
|
-
import { useMemo } from
|
|
19
|
+
import { GraphQLClient } from "graphql-request";
|
|
20
|
+
import qs from "query-string";
|
|
21
|
+
import { useMemo } from "react";
|
|
22
22
|
import { errorsHandler } from "./errors";
|
|
23
23
|
import { getSdk, getSdkWithHooks } from "./sdk";
|
|
24
|
-
|
|
25
|
-
export * from 'graphql-request';
|
|
24
|
+
export * from "graphql-request";
|
|
26
25
|
export * from "./errors";
|
|
27
26
|
export * from "./sdk";
|
|
28
|
-
var AUTH_DATA =
|
|
27
|
+
var AUTH_DATA = "authData";
|
|
29
28
|
var getAuthData = function getAuthData() {
|
|
30
|
-
if (!isBrowser()) {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
29
|
try {
|
|
34
|
-
var authData = JSON.parse(window.localStorage.getItem(AUTH_DATA) ||
|
|
30
|
+
var authData = JSON.parse(window.localStorage.getItem(AUTH_DATA) || "{}");
|
|
35
31
|
return authData;
|
|
36
32
|
} catch (error) {
|
|
37
|
-
console.warn(
|
|
33
|
+
console.warn("getAuthData failed", error);
|
|
38
34
|
return {};
|
|
39
35
|
}
|
|
40
36
|
};
|
|
@@ -42,7 +38,7 @@ export var requestMiddleware = function requestMiddleware(request) {
|
|
|
42
38
|
var url = request.url,
|
|
43
39
|
operationName = request.operationName,
|
|
44
40
|
otherRequest = _objectWithoutProperties(request, _excluded);
|
|
45
|
-
var _url$split = url.split(
|
|
41
|
+
var _url$split = url.split("?"),
|
|
46
42
|
_url$split2 = _slicedToArray(_url$split, 2),
|
|
47
43
|
host = _url$split2[0],
|
|
48
44
|
search = _url$split2[1];
|
|
@@ -59,7 +55,7 @@ export var requestMiddleware = function requestMiddleware(request) {
|
|
|
59
55
|
return _objectSpread(_objectSpread({
|
|
60
56
|
url: "".concat(host, "?").concat(qs.stringify(query)),
|
|
61
57
|
operationName: operationName,
|
|
62
|
-
credentials:
|
|
58
|
+
credentials: "include"
|
|
63
59
|
}, otherRequest), {}, {
|
|
64
60
|
headers: Authorization ? _objectSpread(_objectSpread({}, request.headers), {}, {
|
|
65
61
|
Authorization: Authorization
|
|
@@ -73,10 +69,7 @@ export var responseMiddleware = function responseMiddleware(response) {
|
|
|
73
69
|
errorsHandler(errors);
|
|
74
70
|
}
|
|
75
71
|
};
|
|
76
|
-
var endpoint =
|
|
77
|
-
if (!isBrowser()) {
|
|
78
|
-
endpoint = (process.env.BFF_SERVER_ORIGIN || '') + endpoint;
|
|
79
|
-
}
|
|
72
|
+
var endpoint = "/kubeagi-apis/bff";
|
|
80
73
|
export var client = new GraphQLClient(endpoint, {
|
|
81
74
|
requestMiddleware: requestMiddleware,
|
|
82
75
|
responseMiddleware: responseMiddleware
|