@gopowerteam/request 0.1.13 → 0.1.14

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.
@@ -84,7 +84,8 @@ var _AxiosAdapter = class {
84
84
  headers,
85
85
  method,
86
86
  paramsQuery,
87
- paramsBody
87
+ paramsBody,
88
+ extraParams = {}
88
89
  }) {
89
90
  const axiosInstance = this.getAxiosInstance();
90
91
  return axiosInstance.request({
@@ -93,7 +94,8 @@ var _AxiosAdapter = class {
93
94
  headers,
94
95
  params: paramsQuery,
95
96
  data: paramsBody,
96
- url: pathURL
97
+ url: pathURL,
98
+ ...extraParams
97
99
  });
98
100
  }
99
101
  /**
@@ -1,4 +1,4 @@
1
- import { c as RequestAdapter, R as RequestSetupConfig, d as RequestAdapterOptions, A as AdapterResponse } from '../request-plugin.interface-70aec02a.js';
1
+ import { c as RequestAdapter, R as RequestSetupConfig, d as RequestAdapterOptions, A as AdapterResponse } from '../request-plugin.interface-3436b618.js';
2
2
  import { AxiosResponse, AxiosError } from 'axios';
3
3
  import 'qs';
4
4
 
@@ -15,7 +15,7 @@ declare class AxiosAdapter implements RequestAdapter {
15
15
  * @param options 请求参数
16
16
  * @returns AxiosResponse
17
17
  */
18
- request({ baseURL, pathURL, headers, method, paramsQuery, paramsBody }: RequestAdapterOptions): Promise<AxiosResponse<any, any>>;
18
+ request({ baseURL, pathURL, headers, method, paramsQuery, paramsBody, extraParams }: RequestAdapterOptions): Promise<AxiosResponse<any, any>>;
19
19
  /**
20
20
  * 转换Response
21
21
  * @param response
@@ -47,7 +47,8 @@ var _AxiosAdapter = class {
47
47
  headers,
48
48
  method,
49
49
  paramsQuery,
50
- paramsBody
50
+ paramsBody,
51
+ extraParams = {}
51
52
  }) {
52
53
  const axiosInstance = this.getAxiosInstance();
53
54
  return axiosInstance.request({
@@ -56,7 +57,8 @@ var _AxiosAdapter = class {
56
57
  headers,
57
58
  params: paramsQuery,
58
59
  data: paramsBody,
59
- url: pathURL
60
+ url: pathURL,
61
+ ...extraParams
60
62
  });
61
63
  }
62
64
  /**
package/dist/index.cjs CHANGED
@@ -81,10 +81,17 @@ var _RequestService = class {
81
81
  * @param options
82
82
  */
83
83
  execRequestPlugin(plugins = [], options) {
84
+ const extraParams = {};
85
+ const appendParams = (params) => {
86
+ Object.assign(extraParams, params || {});
87
+ };
84
88
  _RequestService.config.plugins.forEach(
85
- (service) => service.before && service.before(options)
89
+ (service) => service.before && service.before(options, appendParams)
86
90
  );
87
- plugins.forEach((service) => service.before && service.before(options));
91
+ plugins.forEach(
92
+ (service) => service.before && service.before(options, appendParams)
93
+ );
94
+ return extraParams;
88
95
  }
89
96
  /**
90
97
  * 执行前置插件逻辑
@@ -123,7 +130,7 @@ var _RequestService = class {
123
130
  * @param options
124
131
  * @returns
125
132
  */
126
- startRequest(adapter, options) {
133
+ startRequest(adapter, options, extraParams) {
127
134
  return adapter.request({
128
135
  baseURL: _RequestService.config.gateway,
129
136
  pathURL: this.parseRequestPath(
@@ -134,7 +141,8 @@ var _RequestService = class {
134
141
  method: options.method,
135
142
  headers: options.headers || {},
136
143
  paramsQuery: options.paramsQuery,
137
- paramsBody: options.paramsBody
144
+ paramsBody: options.paramsBody,
145
+ extraParams
138
146
  });
139
147
  }
140
148
  /**
@@ -169,8 +177,8 @@ var _RequestService = class {
169
177
  }
170
178
  let hasException = false;
171
179
  const adapter = this.getRequestAdapter();
172
- this.execRequestPlugin(plugins, options);
173
- const response = await this.startRequest(adapter, options).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
180
+ const extraParams = this.execRequestPlugin(plugins, options);
181
+ const response = await this.startRequest(adapter, options, extraParams).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
174
182
  hasException = true;
175
183
  return adapter.transformException(exception);
176
184
  });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequestSetupConfig, a as RequestSendOptions, b as RequestPlugin } from './request-plugin.interface-70aec02a.js';
2
- export { A as AdapterResponse, e as AdapterResponseHeaders, P as PluginLifecycle, c as RequestAdapter, d as RequestAdapterOptions, f as RequestLifecycle, h as RequestMethod, i as ResponseInterceptor, g as ResponseLifecycle } from './request-plugin.interface-70aec02a.js';
1
+ import { R as RequestSetupConfig, a as RequestSendOptions, b as RequestPlugin } from './request-plugin.interface-3436b618.js';
2
+ export { A as AdapterResponse, e as AdapterResponseHeaders, P as PluginLifecycle, c as RequestAdapter, d as RequestAdapterOptions, f as RequestLifecycle, h as RequestMethod, i as ResponseInterceptor, g as ResponseLifecycle } from './request-plugin.interface-3436b618.js';
3
3
  import 'qs';
4
4
 
5
5
  declare class RequestService {
package/dist/index.js CHANGED
@@ -40,10 +40,17 @@ var _RequestService = class {
40
40
  * @param options
41
41
  */
42
42
  execRequestPlugin(plugins = [], options) {
43
+ const extraParams = {};
44
+ const appendParams = (params) => {
45
+ Object.assign(extraParams, params || {});
46
+ };
43
47
  _RequestService.config.plugins.forEach(
44
- (service) => service.before && service.before(options)
48
+ (service) => service.before && service.before(options, appendParams)
45
49
  );
46
- plugins.forEach((service) => service.before && service.before(options));
50
+ plugins.forEach(
51
+ (service) => service.before && service.before(options, appendParams)
52
+ );
53
+ return extraParams;
47
54
  }
48
55
  /**
49
56
  * 执行前置插件逻辑
@@ -82,7 +89,7 @@ var _RequestService = class {
82
89
  * @param options
83
90
  * @returns
84
91
  */
85
- startRequest(adapter, options) {
92
+ startRequest(adapter, options, extraParams) {
86
93
  return adapter.request({
87
94
  baseURL: _RequestService.config.gateway,
88
95
  pathURL: this.parseRequestPath(
@@ -93,7 +100,8 @@ var _RequestService = class {
93
100
  method: options.method,
94
101
  headers: options.headers || {},
95
102
  paramsQuery: options.paramsQuery,
96
- paramsBody: options.paramsBody
103
+ paramsBody: options.paramsBody,
104
+ extraParams
97
105
  });
98
106
  }
99
107
  /**
@@ -128,8 +136,8 @@ var _RequestService = class {
128
136
  }
129
137
  let hasException = false;
130
138
  const adapter = this.getRequestAdapter();
131
- this.execRequestPlugin(plugins, options);
132
- const response = await this.startRequest(adapter, options).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
139
+ const extraParams = this.execRequestPlugin(plugins, options);
140
+ const response = await this.startRequest(adapter, options, extraParams).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
133
141
  hasException = true;
134
142
  return adapter.transformException(exception);
135
143
  });
@@ -69,6 +69,7 @@ interface RequestAdapterOptions {
69
69
  method: RequestMethod | string;
70
70
  paramsQuery?: Record<string, any>;
71
71
  paramsBody?: any;
72
+ extraParams?: any;
72
73
  }
73
74
  interface AdapterResponse {
74
75
  data: Record<string, any>;
@@ -82,7 +83,7 @@ type AdapterResponseHeaders = Record<string, string | string[] | number | boolea
82
83
  * 请求插件
83
84
  */
84
85
  interface RequestPlugin {
85
- before?: (options: RequestSendOptions) => void;
86
+ before?: (options: RequestSendOptions, appendParams?: (params: Record<string, any>) => void) => void;
86
87
  after?: (response: AdapterResponse, options: RequestSendOptions) => void;
87
88
  catch?: (response: AdapterResponse, options: RequestSendOptions) => void;
88
89
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gopowerteam/request",
3
3
  "private": false,
4
- "version": "0.1.13",
4
+ "version": "0.1.14",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",