Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 89a522e

Browse files
committed
chore(service): reexport fetcher from console-fetcher
feat(service): support noRisk option
1 parent 66d8d32 commit 89a522e

File tree

8 files changed

+62
-56
lines changed

8 files changed

+62
-56
lines changed

‎packages/console-utils/xconsole-service/package.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/xconsole-service",
3-
"version": "2.6.2",
3+
"version": "2.6.3",
44
"main": "lib/index.js",
55
"module": "es/index.js",
66
"types": "lib/index.d.ts",
@@ -59,8 +59,5 @@
5959
"qs": "^6.10.2",
6060
"swr": "^0.2.3",
6161
"tslib": "^2.0.0"
62-
},
63-
"resolutions": {
64-
"jest-environment-jsdom": "^26.0.1"
6562
}
6663
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export * from '@alicloud/console-fetcher';
2+
export { default as fetcher } from '@alicloud/console-fetcher';
23

34
export type { ApiType, IOptions as ServiceOptions } from './types';
45

56
export * from './hooks/useService';
67
export * from './oss/index';
7-
export { default as useService } from './hooks/useService';
88
export { default as createService, request as defaultAxiosRequest } from './service';
99
export { setGetRegionIdFn } from './utils/index';
1010
export { default as createError } from './utils/createError';
1111
export { default as globalConfig } from './configuration/config';
12-
export { default as createRequest } from './request'
12+
export { default as createRequest } from './request';

‎packages/console-utils/xconsole-service/src/interceptors/consoleInterceptor/request.ts‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
getActiveRegionId,
66
} from '../../utils/index';
77
import { IOptions, IOptionsData } from '../../types';
8-
import { ApiType } from '../../const/index';
9-
import { API_URL } from '../../const';
8+
import { ApiType, API_URL } from '../../const/index';
109

1110
// 默认请求路径
1211
const BASE_URL = '/';
@@ -56,7 +55,7 @@ function getRegion(data: any): string {
5655
} else {
5756
const { actions } = data;
5857
const action = actions.find(
59-
({ params }: { params: any }) => (params || {}).RegionId
58+
({ params }: { params: any }) => (params || {}).RegionId,
6059
);
6160

6261
if (action && action.params.RegionId) return action.params.RegionId;
@@ -66,7 +65,6 @@ function getRegion(data: any): string {
6665

6766
// 必填缺省参数补全并格式化部分参数
6867
const utilsMap: { [key: string]: (data?: any) => any } = {
69-
// eslint-disable-next-line @typescript-eslint/camelcase
7068
sec_token: getSecToken,
7169
collina: getCollina,
7270
umid: getUmid,
@@ -75,7 +73,7 @@ const utilsMap: { [key: string]: (data?: any) => any } = {
7573

7674
function processData(
7775
data: IOptions['data'] = {},
78-
keys: string[] = []
76+
keys: string[] = [],
7977
): {
8078
[key: string]: any;
8179
params?: string;
@@ -124,7 +122,7 @@ function checkArgumentsForMultiApi({ product, actions }: IOptionsData): void {
124122
throw new Error(
125123
`You must specify which api you want to call.
126124
If you see this log, it's likely that you've forgot to specify an action
127-
property in your actions argument. Go for a double check.`
125+
property in your actions argument. Go for a double check.`,
128126
);
129127
}
130128
});
@@ -145,7 +143,7 @@ function checkArguments(data: IOptionsData, multi: boolean): void {
145143
* @param {*} config
146144
*/
147145
function consoleRequestInterceptor(config: IOptions): IOptions {
148-
const { url = '', apiType, data = {}, useCors } = config;
146+
const { url = '', apiType, noRisk,data = {}, useCors } = config;
149147
// 补全缺省必填参数并修正参数格式
150148
// params 与 actions 需要 JSON.stringify
151149
const nextData = processData(data, [
@@ -172,13 +170,27 @@ function consoleRequestInterceptor(config: IOptions): IOptions {
172170
// 检查参数格式是否正确
173171
checkArguments(data, multi);
174172

173+
const qs = [];
174+
175+
if (nextData.action) {
176+
qs.push(`action=${nextData.action}`);
177+
}
178+
179+
if (nextData.product) {
180+
qs.push(`product=${nextData.product}`);
181+
}
182+
183+
if (noRisk) {
184+
qs.push('noRisk=true');
185+
}
186+
187+
const search = qs.length > 0 ? `?${qs.join('&')}` : '';
188+
175189
// 返回新的 config 对象
176190
return {
177191
...config,
178192
method: 'post',
179-
url: `${getURL(apiType, multi)}?action=${nextData.action}&product=${
180-
nextData.product
181-
}`, // 获取请求 URL
193+
url: `${getURL(apiType, multi)}${search}`,
182194
baseURL: BASE_URL,
183195
withCredentials: !!useCors,
184196
data: nextData,

‎packages/console-utils/xconsole-service/src/interceptors/consoleInterceptor/response.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const injectErrorPromptAdaptor = (error: IError, response: AxiosResponse) => {
88
let body = {};
99

1010
try {
11-
body = qs.parse(response?.config?.data)
12-
} catch (e){
11+
body = qs.parse(response?.config?.data);
12+
} catch (e){
1313
// nothing
1414
}
1515

@@ -19,8 +19,8 @@ const injectErrorPromptAdaptor = (error: IError, response: AxiosResponse) => {
1919
error.message = response.data?.message;
2020
error.details = {
2121
url: response?.config?.url,
22-
body: body,
23-
method: response?.config?.method
22+
body,
23+
method: response?.config?.method,
2424
};
2525

2626
const accessDeniedDetail = response.data?.accessDeniedDetail;
@@ -45,13 +45,13 @@ const injectErrorPromptAdaptor = (error: IError, response: AxiosResponse) => {
4545
userId,
4646
policyType,
4747
type,
48-
diagnosisInfo
48+
diagnosisInfo,
4949
};
5050
}
5151
};
5252

5353
function consoleResponseInterceptor(
54-
response: IResponse<IResponseData>
54+
response: IResponse<IResponseData>,
5555
): IResponse<IResponseData> {
5656
const {
5757
data: apiResponseData,
@@ -62,7 +62,7 @@ function consoleResponseInterceptor(
6262

6363
// Single api succeeded -> code 200, withFailedRequest undefined
6464
// Multi api succeeded -> code 200, withFailedRequest false
65-
if (apiResponseData.code === '200' && apiResponseData.withFailedRequest !== true) {
65+
if (apiResponseData.code === '200' && apiResponseData.withFailedRequest !== true) {
6666
return response;
6767
}
6868

@@ -74,8 +74,8 @@ function consoleResponseInterceptor(
7474

7575
let error: IError = new Error('OpenAPI failed without a message.');
7676

77-
// Multi api with failed request
78-
if (apiResponseData.code === '200' && apiResponseData.withFailedRequest === true) {
77+
// Multi api with failed request
78+
if (apiResponseData.code === '200' && apiResponseData.withFailedRequest === true) {
7979
error = new Error('Multi OpenAPI calls with failed request.');
8080
}
8181

‎packages/console-utils/xconsole-service/src/interceptors/paramsInterceptor/index.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ function searchParamsInterceptor(config: IOptions): IOptions {
1818
...config,
1919
headers: {
2020
...(config.headers || {}),
21-
'content-type': 'application/x-www-form-urlencoded'
21+
'content-type': 'application/x-www-form-urlencoded',
2222
},
2323
params: paramsSearchParams,
24-
//@ts-ignore
2524
data: dataSearchParams,
2625
originParams: params,
2726
originData: data,

‎packages/console-utils/xconsole-service/src/request.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import axios, { AxiosInstance } from 'axios';
2+
23
import searchParamsInterceptor from './interceptors/paramsInterceptor/index';
34
import consoleMockInterceptor from './interceptors/mockInterceptor/index';
45
import fastLoginInterceptor from './interceptors/fastloginInterceptor';
56
import {
67
consoleRequestInterceptor,
78
consoleResponseInterceptor,
8-
roaRequestInterceptor
9+
roaRequestInterceptor,
910
} from './interceptors/consoleInterceptor/index';
1011
import consoleRiskInterceptor from './interceptors/riskInterceptor/index';
1112
import {
1213
armsRequestInterceptor,
1314
armsResponseInterceptor,
1415
} from './interceptors/armsInterceptor/index';
15-
import { RequestInterceptor, ResponseInterceptor } from './types';
16+
import type{ RequestInterceptor, ResponseInterceptor } from './types';
1617

1718
interface IInterceptors {
1819
request?: RequestInterceptor[];
@@ -21,7 +22,7 @@ interface IInterceptors {
2122

2223
export default function createRequest(
2324
interceptors: IInterceptors = {},
24-
override?: boolean
25+
override?: boolean,
2526
): AxiosInstance {
2627
const instance = axios.create();
2728
const {

‎packages/console-utils/xconsole-service/src/service.ts‎

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
1+
import { AxiosInstance, AxiosResponse } from 'axios';
2+
import chunk from 'lodash/chunk';
3+
24
import createRequest from './request';
3-
import chunk from 'lodash/chunk'
4-
import { DEFAULT_RISK_OPTION } from './const'
5+
import { DEFAULT_RISK_OPTION } from './const';
56
import { IOptions, IResponseData, Service, Actions } from './types';
67

78
export const request = createRequest();
89

9-
const makeOption = (product: string, actions: Actions, opts: IOptions): AxiosRequestConfig => {
10+
const makeOption = (product: string, actions: Actions, opts: IOptions): IOptions => {
1011
return {
1112
...opts,
1213
data: opts.data
@@ -15,27 +16,23 @@ const makeOption = (product: string, actions: Actions, opts: IOptions): AxiosReq
1516
product,
1617
actions,
1718
},
18-
apiType: opts.apiType,
19-
ignoreError: opts.ignoreError,
20-
description: opts.description,
21-
risk: opts.risk,
22-
} as AxiosRequestConfig;
23-
}
19+
};
20+
};
2421

25-
const splitActions = (actions: Actions) => chunk(actions, 20)
22+
const splitActions = (actions: Actions) => chunk(actions, 20);
2623

27-
const createMultiService = <R,P>(requestInstance: AxiosInstance, product: string, opts: IOptions) => {
24+
const createMultiService = <R>(requestInstance: AxiosInstance, product: string, opts: IOptions) => {
2825
return async (actions: Actions): Promise<R> => {
2926
/* eslint-disable no-undef */
3027
return Promise.all(splitActions(actions).map((splitAction) => {
3128
return requestInstance.request<IResponseData<R>, AxiosResponse<IResponseData<R>>>(
32-
makeOption(product, splitAction, opts)
29+
makeOption(product, splitAction, opts),
3330
);
3431
})).then((data) => {
35-
return data.reduce((pre, d) => ({...pre, ...(d.data.data)}), {} as R)
32+
return data.reduce((pre, d) => ({...pre, ...(d.data.data)}), {} as unknownasR);
3633
});
3734
};
38-
}
35+
};
3936

4037
const createDefaultService = <R, P>(requestInstance: AxiosInstance, product: string, action: string, opts: IOptions) => {
4138
return async (params: P, overlap = false) => {
@@ -65,31 +62,29 @@ const createDefaultService = <R, P>(requestInstance: AxiosInstance, product: str
6562
if (opts.extraData) {
6663
data = {
6764
...data,
68-
...opts.extraData
69-
}
65+
...opts.extraData,
66+
};
7067
}
7168

7269
const res = await requestInstance.request<IResponseData<R>, AxiosResponse<IResponseData<R>>>({
7370
...opts,
7471
data,
75-
apiType: opts.apiType, // one-console 对应的接口类型
76-
ignoreError: opts.ignoreError, // 是否忽略 api 异常
72+
// @ts-ignore AxiosRequestConfig 类型无法扩展
7773
description: opts.description || action, // 当前请求的描述
7874
useCors: false,
79-
risk: opts.risk,
80-
} as AxiosRequestConfig);
75+
});
8176

82-
//@ts-ignore
77+
//@ts-ignore AxiosRequestConfig 类型无法扩展
8378
return res.config.rawResponseData ? res.data : res.data.data;
8479
};
85-
}
80+
};
8681

8782

8883
const createService = <R = any, P = any>(
8984
product: string,
9085
action?: string,
9186
options: IOptions = {},
92-
instance?: AxiosInstance
87+
instance?: AxiosInstance,
9388
): Service<R, P> => {
9489
const requestInstance = instance || request;
9590
const opts: IOptions = {
@@ -103,7 +98,7 @@ const createService = <R = any, P = any>(
10398
}
10499

105100
// @ts-ignore
106-
return createDefaultService(requestInstance, product, action, opts)
107-
}
101+
return createDefaultService(requestInstance, product, action, opts);
102+
};
108103

109104
export default createService;

‎packages/console-utils/xconsole-service/src/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface IOptions extends AxiosRequestConfig {
5555
mock?: boolean;
5656
// oneapi _tag
5757
mockTag?: string;
58+
// 关闭 oneConsole 风控
59+
noRisk?: boolean;
5860
}
5961

6062
export interface IResponseData<D = any> {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /