@tencentcloud/sdk-mcp 1.0.2 → 1.0.4

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.
Files changed (115) hide show
  1. package/@tencent/aegis-node-sdk/lib/packages/core/src/constant/config.d.ts +14 -14
  2. package/@tencent/aegis-node-sdk/lib/packages/core/src/constant/global.d.ts +1 -1
  3. package/@tencent/aegis-node-sdk/lib/packages/core/src/constant/index.d.ts +9 -9
  4. package/@tencent/aegis-node-sdk/lib/packages/core/src/constant/report-ignore.d.ts +2 -2
  5. package/@tencent/aegis-node-sdk/lib/packages/core/src/core.d.ts +85 -85
  6. package/@tencent/aegis-node-sdk/lib/packages/core/src/hooks/afterRequestHooks.d.ts +3 -3
  7. package/@tencent/aegis-node-sdk/lib/packages/core/src/hooks/beforeRequestHooks.d.ts +9 -9
  8. package/@tencent/aegis-node-sdk/lib/packages/core/src/hooks/modifyRequestHooks.d.ts +3 -3
  9. package/@tencent/aegis-node-sdk/lib/packages/core/src/index.d.ts +9 -9
  10. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/config.d.ts +62 -62
  11. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/env.d.ts +11 -11
  12. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/index.d.ts +4 -4
  13. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/log.d.ts +130 -130
  14. package/@tencent/aegis-node-sdk/lib/packages/core/src/interface/send.d.ts +34 -34
  15. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/format.d.ts +2 -2
  16. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/index.d.ts +18 -18
  17. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/length-limit.d.ts +8 -8
  18. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/pv.d.ts +8 -8
  19. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/remove-payload.d.ts +2 -2
  20. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/repeat-limit.d.ts +4 -4
  21. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/report.d.ts +10 -10
  22. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/sample.d.ts +3 -3
  23. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/throttle.d.ts +3 -3
  24. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/trace/index.d.ts +34 -34
  25. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/trace/jwt.d.ts +12 -12
  26. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/trace/ot-js.d.ts +14 -14
  27. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/trace/uuid.d.ts +2 -2
  28. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/whitelist.d.ts +12 -12
  29. package/@tencent/aegis-node-sdk/lib/packages/core/src/pipes/write-before.d.ts +3 -3
  30. package/@tencent/aegis-node-sdk/lib/packages/core/src/plugin.d.ts +33 -33
  31. package/@tencent/aegis-node-sdk/lib/packages/core/src/util/destroy.d.ts +2 -2
  32. package/@tencent/aegis-node-sdk/lib/packages/core/src/util/event-emitter.d.ts +18 -18
  33. package/@tencent/aegis-node-sdk/lib/packages/core/src/util/index.d.ts +60 -60
  34. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/index.d.ts +15 -15
  35. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/interface/selector.d.ts +5 -5
  36. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/pipes/batch-report-pipe.d.ts +6 -6
  37. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/protocol/protocol_base.d.ts +18 -18
  38. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/protocol/protocol_http.d.ts +12 -12
  39. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/selector/ip_selector.d.ts +10 -10
  40. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/selector/polaris_selector.d.ts +20 -20
  41. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/selector/selector_base.d.ts +27 -27
  42. package/@tencent/aegis-node-sdk/lib/packages/node-sdk/src/util/eval_require.d.ts +2 -2
  43. package/mcp-server-prompt.png +0 -0
  44. package/mcp.json +9 -9
  45. package/package.json +1 -1
  46. package/resource/doc/chatuikit/android/client_api_android.md +1377 -0
  47. package/resource/doc/chatuikit/android/integrate_tuichat_only_android.md +382 -0
  48. package/resource/doc/chatuikit/android/integrate_tuikit_android.md +612 -0
  49. package/resource/doc/chatuikit/android/ui_api_android.md +418 -0
  50. package/resource/doc/chatuikit/faq/freq_qa.md +86 -0
  51. package/resource/doc/chatuikit/faq/sdk_qa.md +117 -0
  52. package/resource/doc/chatuikit/faq/vue_qa.md +344 -0
  53. package/resource/doc/chatuikit/faq/web_qa.md +118 -0
  54. package/resource/doc/chatuikit/flutter/client_api_Flutter.md +939 -0
  55. package/resource/doc/chatuikit/flutter/integrate_tuikit_Flutter.md +1432 -0
  56. package/resource/doc/chatuikit/iOS/client_api_iOS.md +1371 -0
  57. package/resource/doc/chatuikit/iOS/integrate_tuichat_only_iOS.md +993 -0
  58. package/resource/doc/chatuikit/iOS/integrate_tuikit_iOS.md +1427 -0
  59. package/resource/doc/chatuikit/iOS/ui_api_iOS.md +526 -0
  60. package/resource/doc/chatuikit/react/integrate_tuichat_only_react.md +185 -0
  61. package/resource/doc/chatuikit/react/integrate_tuichat_react.md +212 -0
  62. package/resource/doc/chatuikit/vue/integrate_tuichat_only_vue.md +149 -0
  63. package/resource/doc/chatuikit/vue/integrate_tuichat_vue.md +248 -0
  64. package/server.js +57 -33
  65. package/server.js.map +1 -1
  66. package/@tencent/polaris/node_modules/axios/CHANGELOG.md +0 -891
  67. package/@tencent/polaris/node_modules/axios/LICENSE +0 -19
  68. package/@tencent/polaris/node_modules/axios/README.md +0 -908
  69. package/@tencent/polaris/node_modules/axios/SECURITY.md +0 -5
  70. package/@tencent/polaris/node_modules/axios/UPGRADE_GUIDE.md +0 -168
  71. package/@tencent/polaris/node_modules/axios/dist/axios.js +0 -2277
  72. package/@tencent/polaris/node_modules/axios/dist/axios.map +0 -1
  73. package/@tencent/polaris/node_modules/axios/dist/axios.min.js +0 -4
  74. package/@tencent/polaris/node_modules/axios/dist/axios.min.map +0 -1
  75. package/@tencent/polaris/node_modules/axios/index.d.ts +0 -221
  76. package/@tencent/polaris/node_modules/axios/index.js +0 -1
  77. package/@tencent/polaris/node_modules/axios/lib/adapters/README.md +0 -37
  78. package/@tencent/polaris/node_modules/axios/lib/adapters/http.js +0 -388
  79. package/@tencent/polaris/node_modules/axios/lib/adapters/xhr.js +0 -212
  80. package/@tencent/polaris/node_modules/axios/lib/axios.js +0 -57
  81. package/@tencent/polaris/node_modules/axios/lib/cancel/Cancel.js +0 -19
  82. package/@tencent/polaris/node_modules/axios/lib/cancel/CancelToken.js +0 -119
  83. package/@tencent/polaris/node_modules/axios/lib/cancel/isCancel.js +0 -5
  84. package/@tencent/polaris/node_modules/axios/lib/core/Axios.js +0 -155
  85. package/@tencent/polaris/node_modules/axios/lib/core/InterceptorManager.js +0 -54
  86. package/@tencent/polaris/node_modules/axios/lib/core/README.md +0 -8
  87. package/@tencent/polaris/node_modules/axios/lib/core/buildFullPath.js +0 -20
  88. package/@tencent/polaris/node_modules/axios/lib/core/createError.js +0 -18
  89. package/@tencent/polaris/node_modules/axios/lib/core/dispatchRequest.js +0 -87
  90. package/@tencent/polaris/node_modules/axios/lib/core/enhanceError.js +0 -43
  91. package/@tencent/polaris/node_modules/axios/lib/core/mergeConfig.js +0 -99
  92. package/@tencent/polaris/node_modules/axios/lib/core/settle.js +0 -25
  93. package/@tencent/polaris/node_modules/axios/lib/core/transformData.js +0 -22
  94. package/@tencent/polaris/node_modules/axios/lib/defaults.js +0 -134
  95. package/@tencent/polaris/node_modules/axios/lib/env/README.md +0 -3
  96. package/@tencent/polaris/node_modules/axios/lib/env/data.js +0 -3
  97. package/@tencent/polaris/node_modules/axios/lib/helpers/README.md +0 -7
  98. package/@tencent/polaris/node_modules/axios/lib/helpers/bind.js +0 -11
  99. package/@tencent/polaris/node_modules/axios/lib/helpers/buildURL.js +0 -70
  100. package/@tencent/polaris/node_modules/axios/lib/helpers/combineURLs.js +0 -14
  101. package/@tencent/polaris/node_modules/axios/lib/helpers/cookies.js +0 -53
  102. package/@tencent/polaris/node_modules/axios/lib/helpers/deprecatedMethod.js +0 -24
  103. package/@tencent/polaris/node_modules/axios/lib/helpers/isAbsoluteURL.js +0 -14
  104. package/@tencent/polaris/node_modules/axios/lib/helpers/isAxiosError.js +0 -13
  105. package/@tencent/polaris/node_modules/axios/lib/helpers/isURLSameOrigin.js +0 -68
  106. package/@tencent/polaris/node_modules/axios/lib/helpers/normalizeHeaderName.js +0 -12
  107. package/@tencent/polaris/node_modules/axios/lib/helpers/parseHeaders.js +0 -53
  108. package/@tencent/polaris/node_modules/axios/lib/helpers/spread.js +0 -27
  109. package/@tencent/polaris/node_modules/axios/lib/helpers/toFormData.js +0 -55
  110. package/@tencent/polaris/node_modules/axios/lib/helpers/validator.js +0 -82
  111. package/@tencent/polaris/node_modules/axios/lib/utils.js +0 -349
  112. package/@tencent/polaris/node_modules/axios/package.json +0 -86
  113. package/@tencent/polaris/node_modules/axios/tsconfig.json +0 -14
  114. package/@tencent/polaris/node_modules/axios/tslint.json +0 -6
  115. package/resource/doc/tuicallkit/vue/api_TUICallObserver.md +0 -926
@@ -1,221 +0,0 @@
1
- // TypeScript Version: 3.0
2
-
3
- export type AxiosRequestHeaders = Record<string, string | number | boolean>;
4
-
5
- export type AxiosResponseHeaders = Record<string, string> & {
6
- "set-cookie"?: string[]
7
- };
8
-
9
- export interface AxiosRequestTransformer {
10
- (data: any, headers?: AxiosRequestHeaders): any;
11
- }
12
-
13
- export interface AxiosResponseTransformer {
14
- (data: any, headers?: AxiosResponseHeaders): any;
15
- }
16
-
17
- export interface AxiosAdapter {
18
- (config: AxiosRequestConfig): AxiosPromise;
19
- }
20
-
21
- export interface AxiosBasicCredentials {
22
- username: string;
23
- password: string;
24
- }
25
-
26
- export interface AxiosProxyConfig {
27
- host: string;
28
- port: number;
29
- auth?: {
30
- username: string;
31
- password: string;
32
- };
33
- protocol?: string;
34
- }
35
-
36
- export type Method =
37
- | 'get' | 'GET'
38
- | 'delete' | 'DELETE'
39
- | 'head' | 'HEAD'
40
- | 'options' | 'OPTIONS'
41
- | 'post' | 'POST'
42
- | 'put' | 'PUT'
43
- | 'patch' | 'PATCH'
44
- | 'purge' | 'PURGE'
45
- | 'link' | 'LINK'
46
- | 'unlink' | 'UNLINK';
47
-
48
- export type ResponseType =
49
- | 'arraybuffer'
50
- | 'blob'
51
- | 'document'
52
- | 'json'
53
- | 'text'
54
- | 'stream';
55
-
56
- export type responseEncoding =
57
- | 'ascii' | 'ASCII'
58
- | 'ansi' | 'ANSI'
59
- | 'binary' | 'BINARY'
60
- | 'base64' | 'BASE64'
61
- | 'base64url' | 'BASE64URL'
62
- | 'hex' | 'HEX'
63
- | 'latin1' | 'LATIN1'
64
- | 'ucs-2' | 'UCS-2'
65
- | 'ucs2' | 'UCS2'
66
- | 'utf-8' | 'UTF-8'
67
- | 'utf8' | 'UTF8'
68
- | 'utf16le' | 'UTF16LE';
69
-
70
- export interface TransitionalOptions {
71
- silentJSONParsing?: boolean;
72
- forcedJSONParsing?: boolean;
73
- clarifyTimeoutError?: boolean;
74
- }
75
-
76
- export interface AxiosRequestConfig<D = any> {
77
- url?: string;
78
- method?: Method;
79
- baseURL?: string;
80
- transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
81
- transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
82
- headers?: AxiosRequestHeaders;
83
- params?: any;
84
- paramsSerializer?: (params: any) => string;
85
- data?: D;
86
- timeout?: number;
87
- timeoutErrorMessage?: string;
88
- withCredentials?: boolean;
89
- adapter?: AxiosAdapter;
90
- auth?: AxiosBasicCredentials;
91
- responseType?: ResponseType;
92
- responseEncoding?: responseEncoding | string;
93
- xsrfCookieName?: string;
94
- xsrfHeaderName?: string;
95
- onUploadProgress?: (progressEvent: any) => void;
96
- onDownloadProgress?: (progressEvent: any) => void;
97
- maxContentLength?: number;
98
- validateStatus?: ((status: number) => boolean) | null;
99
- maxBodyLength?: number;
100
- maxRedirects?: number;
101
- socketPath?: string | null;
102
- httpAgent?: any;
103
- httpsAgent?: any;
104
- proxy?: AxiosProxyConfig | false;
105
- cancelToken?: CancelToken;
106
- decompress?: boolean;
107
- transitional?: TransitionalOptions;
108
- signal?: AbortSignal;
109
- insecureHTTPParser?: boolean;
110
- }
111
-
112
- export interface HeadersDefaults {
113
- common: AxiosRequestHeaders;
114
- delete: AxiosRequestHeaders;
115
- get: AxiosRequestHeaders;
116
- head: AxiosRequestHeaders;
117
- post: AxiosRequestHeaders;
118
- put: AxiosRequestHeaders;
119
- patch: AxiosRequestHeaders;
120
- options?: AxiosRequestHeaders;
121
- purge?: AxiosRequestHeaders;
122
- link?: AxiosRequestHeaders;
123
- unlink?: AxiosRequestHeaders;
124
- }
125
-
126
- export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
127
- headers: HeadersDefaults;
128
- }
129
-
130
- export interface AxiosResponse<T = any, D = any> {
131
- data: T;
132
- status: number;
133
- statusText: string;
134
- headers: AxiosResponseHeaders;
135
- config: AxiosRequestConfig<D>;
136
- request?: any;
137
- }
138
-
139
- export interface AxiosError<T = any, D = any> extends Error {
140
- config: AxiosRequestConfig<D>;
141
- code?: string;
142
- request?: any;
143
- response?: AxiosResponse<T, D>;
144
- isAxiosError: boolean;
145
- toJSON: () => object;
146
- }
147
-
148
- export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
149
- }
150
-
151
- export interface CancelStatic {
152
- new (message?: string): Cancel;
153
- }
154
-
155
- export interface Cancel {
156
- message: string | undefined;
157
- }
158
-
159
- export interface Canceler {
160
- (message?: string): void;
161
- }
162
-
163
- export interface CancelTokenStatic {
164
- new (executor: (cancel: Canceler) => void): CancelToken;
165
- source(): CancelTokenSource;
166
- }
167
-
168
- export interface CancelToken {
169
- promise: Promise<Cancel>;
170
- reason?: Cancel;
171
- throwIfRequested(): void;
172
- }
173
-
174
- export interface CancelTokenSource {
175
- token: CancelToken;
176
- cancel: Canceler;
177
- }
178
-
179
- export interface AxiosInterceptorManager<V> {
180
- use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any): number;
181
- eject(id: number): void;
182
- }
183
-
184
- export class Axios {
185
- constructor(config?: AxiosRequestConfig);
186
- defaults: AxiosDefaults;
187
- interceptors: {
188
- request: AxiosInterceptorManager<AxiosRequestConfig>;
189
- response: AxiosInterceptorManager<AxiosResponse>;
190
- };
191
- getUri(config?: AxiosRequestConfig): string;
192
- request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
193
- get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
194
- delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
195
- head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
196
- options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
197
- post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
198
- put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
199
- patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
200
- }
201
-
202
- export interface AxiosInstance extends Axios {
203
- (config: AxiosRequestConfig): AxiosPromise;
204
- (url: string, config?: AxiosRequestConfig): AxiosPromise;
205
- }
206
-
207
- export interface AxiosStatic extends AxiosInstance {
208
- create(config?: AxiosRequestConfig): AxiosInstance;
209
- Cancel: CancelStatic;
210
- CancelToken: CancelTokenStatic;
211
- Axios: typeof Axios;
212
- readonly VERSION: string;
213
- isCancel(value: any): boolean;
214
- all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
215
- spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
216
- isAxiosError(payload: any): payload is AxiosError;
217
- }
218
-
219
- declare const axios: AxiosStatic;
220
-
221
- export default axios;
@@ -1 +0,0 @@
1
- module.exports = require('./lib/axios');
@@ -1,37 +0,0 @@
1
- # axios // adapters
2
-
3
- The modules under `adapters/` are modules that handle dispatching a request and settling a returned `Promise` once a response is received.
4
-
5
- ## Example
6
-
7
- ```js
8
- var settle = require('./../core/settle');
9
-
10
- module.exports = function myAdapter(config) {
11
- // At this point:
12
- // - config has been merged with defaults
13
- // - request transformers have already run
14
- // - request interceptors have already run
15
-
16
- // Make the request using config provided
17
- // Upon response settle the Promise
18
-
19
- return new Promise(function(resolve, reject) {
20
-
21
- var response = {
22
- data: responseData,
23
- status: request.status,
24
- statusText: request.statusText,
25
- headers: responseHeaders,
26
- config: config,
27
- request: request
28
- };
29
-
30
- settle(resolve, reject, response);
31
-
32
- // From here:
33
- // - response transformers will run
34
- // - response interceptors will run
35
- });
36
- }
37
- ```
@@ -1,388 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('./../utils');
4
- var settle = require('./../core/settle');
5
- var buildFullPath = require('../core/buildFullPath');
6
- var buildURL = require('./../helpers/buildURL');
7
- var http = require('http');
8
- var https = require('https');
9
- var httpFollow = require('follow-redirects').http;
10
- var httpsFollow = require('follow-redirects').https;
11
- var url = require('url');
12
- var zlib = require('zlib');
13
- var VERSION = require('./../env/data').version;
14
- var createError = require('../core/createError');
15
- var enhanceError = require('../core/enhanceError');
16
- var defaults = require('../defaults');
17
- var Cancel = require('../cancel/Cancel');
18
-
19
- var isHttps = /https:?/;
20
-
21
- /**
22
- *
23
- * @param {http.ClientRequestArgs} options
24
- * @param {AxiosProxyConfig} proxy
25
- * @param {string} location
26
- */
27
- function setProxy(options, proxy, location) {
28
- options.hostname = proxy.host;
29
- options.host = proxy.host;
30
- options.port = proxy.port;
31
- options.path = location;
32
-
33
- // Basic proxy authorization
34
- if (proxy.auth) {
35
- var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
36
- options.headers['Proxy-Authorization'] = 'Basic ' + base64;
37
- }
38
-
39
- // If a proxy is used, any redirects must also pass through the proxy
40
- options.beforeRedirect = function beforeRedirect(redirection) {
41
- redirection.headers.host = redirection.host;
42
- setProxy(redirection, proxy, redirection.href);
43
- };
44
- }
45
-
46
- /*eslint consistent-return:0*/
47
- module.exports = function httpAdapter(config) {
48
- return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
49
- var onCanceled;
50
- function done() {
51
- if (config.cancelToken) {
52
- config.cancelToken.unsubscribe(onCanceled);
53
- }
54
-
55
- if (config.signal) {
56
- config.signal.removeEventListener('abort', onCanceled);
57
- }
58
- }
59
- var resolve = function resolve(value) {
60
- done();
61
- resolvePromise(value);
62
- };
63
- var rejected = false;
64
- var reject = function reject(value) {
65
- done();
66
- rejected = true;
67
- rejectPromise(value);
68
- };
69
- var data = config.data;
70
- var headers = config.headers;
71
- var headerNames = {};
72
-
73
- Object.keys(headers).forEach(function storeLowerName(name) {
74
- headerNames[name.toLowerCase()] = name;
75
- });
76
-
77
- // Set User-Agent (required by some servers)
78
- // See https://github.com/axios/axios/issues/69
79
- if ('user-agent' in headerNames) {
80
- // User-Agent is specified; handle case where no UA header is desired
81
- if (!headers[headerNames['user-agent']]) {
82
- delete headers[headerNames['user-agent']];
83
- }
84
- // Otherwise, use specified value
85
- } else {
86
- // Only set header if it hasn't been set in config
87
- headers['User-Agent'] = 'axios/' + VERSION;
88
- }
89
-
90
- if (data && !utils.isStream(data)) {
91
- if (Buffer.isBuffer(data)) {
92
- // Nothing to do...
93
- } else if (utils.isArrayBuffer(data)) {
94
- data = Buffer.from(new Uint8Array(data));
95
- } else if (utils.isString(data)) {
96
- data = Buffer.from(data, 'utf-8');
97
- } else {
98
- return reject(createError(
99
- 'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
100
- config
101
- ));
102
- }
103
-
104
- if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
105
- return reject(createError('Request body larger than maxBodyLength limit', config));
106
- }
107
-
108
- // Add Content-Length header if data exists
109
- if (!headerNames['content-length']) {
110
- headers['Content-Length'] = data.length;
111
- }
112
- }
113
-
114
- // HTTP basic authentication
115
- var auth = undefined;
116
- if (config.auth) {
117
- var username = config.auth.username || '';
118
- var password = config.auth.password || '';
119
- auth = username + ':' + password;
120
- }
121
-
122
- // Parse url
123
- var fullPath = buildFullPath(config.baseURL, config.url);
124
- var parsed = url.parse(fullPath);
125
- var protocol = parsed.protocol || 'http:';
126
-
127
- if (!auth && parsed.auth) {
128
- var urlAuth = parsed.auth.split(':');
129
- var urlUsername = urlAuth[0] || '';
130
- var urlPassword = urlAuth[1] || '';
131
- auth = urlUsername + ':' + urlPassword;
132
- }
133
-
134
- if (auth && headerNames.authorization) {
135
- delete headers[headerNames.authorization];
136
- }
137
-
138
- var isHttpsRequest = isHttps.test(protocol);
139
- var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
140
-
141
- var options = {
142
- path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
143
- method: config.method.toUpperCase(),
144
- headers: headers,
145
- agent: agent,
146
- agents: { http: config.httpAgent, https: config.httpsAgent },
147
- auth: auth
148
- };
149
-
150
- if (config.socketPath) {
151
- options.socketPath = config.socketPath;
152
- } else {
153
- options.hostname = parsed.hostname;
154
- options.port = parsed.port;
155
- }
156
-
157
- var proxy = config.proxy;
158
- if (!proxy && proxy !== false) {
159
- var proxyEnv = protocol.slice(0, -1) + '_proxy';
160
- var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
161
- if (proxyUrl) {
162
- var parsedProxyUrl = url.parse(proxyUrl);
163
- var noProxyEnv = process.env.no_proxy || process.env.NO_PROXY;
164
- var shouldProxy = true;
165
-
166
- if (noProxyEnv) {
167
- var noProxy = noProxyEnv.split(',').map(function trim(s) {
168
- return s.trim();
169
- });
170
-
171
- shouldProxy = !noProxy.some(function proxyMatch(proxyElement) {
172
- if (!proxyElement) {
173
- return false;
174
- }
175
- if (proxyElement === '*') {
176
- return true;
177
- }
178
- if (proxyElement[0] === '.' &&
179
- parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement) {
180
- return true;
181
- }
182
-
183
- return parsed.hostname === proxyElement;
184
- });
185
- }
186
-
187
- if (shouldProxy) {
188
- proxy = {
189
- host: parsedProxyUrl.hostname,
190
- port: parsedProxyUrl.port,
191
- protocol: parsedProxyUrl.protocol
192
- };
193
-
194
- if (parsedProxyUrl.auth) {
195
- var proxyUrlAuth = parsedProxyUrl.auth.split(':');
196
- proxy.auth = {
197
- username: proxyUrlAuth[0],
198
- password: proxyUrlAuth[1]
199
- };
200
- }
201
- }
202
- }
203
- }
204
-
205
- if (proxy) {
206
- options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : '');
207
- setProxy(options, proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
208
- }
209
-
210
- var transport;
211
- var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true);
212
- if (config.transport) {
213
- transport = config.transport;
214
- } else if (config.maxRedirects === 0) {
215
- transport = isHttpsProxy ? https : http;
216
- } else {
217
- if (config.maxRedirects) {
218
- options.maxRedirects = config.maxRedirects;
219
- }
220
- transport = isHttpsProxy ? httpsFollow : httpFollow;
221
- }
222
-
223
- if (config.maxBodyLength > -1) {
224
- options.maxBodyLength = config.maxBodyLength;
225
- }
226
-
227
- if (config.insecureHTTPParser) {
228
- options.insecureHTTPParser = config.insecureHTTPParser;
229
- }
230
-
231
- // Create the request
232
- var req = transport.request(options, function handleResponse(res) {
233
- if (req.aborted) return;
234
-
235
- // uncompress the response body transparently if required
236
- var stream = res;
237
-
238
- // return the last request in case of redirects
239
- var lastRequest = res.req || req;
240
-
241
-
242
- // if no content, is HEAD request or decompress disabled we should not decompress
243
- if (res.statusCode !== 204 && lastRequest.method !== 'HEAD' && config.decompress !== false) {
244
- switch (res.headers['content-encoding']) {
245
- /*eslint default-case:0*/
246
- case 'gzip':
247
- case 'compress':
248
- case 'deflate':
249
- // add the unzipper to the body stream processing pipeline
250
- stream = stream.pipe(zlib.createUnzip());
251
-
252
- // remove the content-encoding in order to not confuse downstream operations
253
- delete res.headers['content-encoding'];
254
- break;
255
- }
256
- }
257
-
258
- var response = {
259
- status: res.statusCode,
260
- statusText: res.statusMessage,
261
- headers: res.headers,
262
- config: config,
263
- request: lastRequest
264
- };
265
-
266
- if (config.responseType === 'stream') {
267
- response.data = stream;
268
- settle(resolve, reject, response);
269
- } else {
270
- var responseBuffer = [];
271
- var totalResponseBytes = 0;
272
- stream.on('data', function handleStreamData(chunk) {
273
- responseBuffer.push(chunk);
274
- totalResponseBytes += chunk.length;
275
-
276
- // make sure the content length is not over the maxContentLength if specified
277
- if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) {
278
- // stream.destoy() emit aborted event before calling reject() on Node.js v16
279
- rejected = true;
280
- stream.destroy();
281
- reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
282
- config, null, lastRequest));
283
- }
284
- });
285
-
286
- stream.on('aborted', function handlerStreamAborted() {
287
- if (rejected) {
288
- return;
289
- }
290
- stream.destroy();
291
- reject(createError('error request aborted', config, 'ERR_REQUEST_ABORTED', lastRequest));
292
- });
293
-
294
- stream.on('error', function handleStreamError(err) {
295
- if (req.aborted) return;
296
- reject(enhanceError(err, config, null, lastRequest));
297
- });
298
-
299
- stream.on('end', function handleStreamEnd() {
300
- try {
301
- var responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
302
- if (config.responseType !== 'arraybuffer') {
303
- responseData = responseData.toString(config.responseEncoding);
304
- if (!config.responseEncoding || config.responseEncoding === 'utf8') {
305
- responseData = utils.stripBOM(responseData);
306
- }
307
- }
308
- response.data = responseData;
309
- } catch (err) {
310
- reject(enhanceError(err, config, err.code, response.request, response));
311
- }
312
- settle(resolve, reject, response);
313
- });
314
- }
315
- });
316
-
317
- // Handle errors
318
- req.on('error', function handleRequestError(err) {
319
- if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') return;
320
- reject(enhanceError(err, config, null, req));
321
- });
322
-
323
- // set tcp keep alive to prevent drop connection by peer
324
- req.on('socket', function handleRequestSocket(socket) {
325
- // default interval of sending ack packet is 1 minute
326
- socket.setKeepAlive(true, 1000 * 60);
327
- });
328
-
329
- // Handle request timeout
330
- if (config.timeout) {
331
- // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
332
- var timeout = parseInt(config.timeout, 10);
333
-
334
- if (isNaN(timeout)) {
335
- reject(createError(
336
- 'error trying to parse `config.timeout` to int',
337
- config,
338
- 'ERR_PARSE_TIMEOUT',
339
- req
340
- ));
341
-
342
- return;
343
- }
344
-
345
- // Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
346
- // And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
347
- // At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
348
- // And then these socket which be hang up will devoring CPU little by little.
349
- // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
350
- req.setTimeout(timeout, function handleRequestTimeout() {
351
- req.abort();
352
- var transitional = config.transitional || defaults.transitional;
353
- reject(createError(
354
- 'timeout of ' + timeout + 'ms exceeded',
355
- config,
356
- transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
357
- req
358
- ));
359
- });
360
- }
361
-
362
- if (config.cancelToken || config.signal) {
363
- // Handle cancellation
364
- // eslint-disable-next-line func-names
365
- onCanceled = function(cancel) {
366
- if (req.aborted) return;
367
-
368
- req.abort();
369
- reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
370
- };
371
-
372
- config.cancelToken && config.cancelToken.subscribe(onCanceled);
373
- if (config.signal) {
374
- config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
375
- }
376
- }
377
-
378
-
379
- // Send the request
380
- if (utils.isStream(data)) {
381
- data.on('error', function handleStreamError(err) {
382
- reject(enhanceError(err, config, null, req));
383
- }).pipe(req);
384
- } else {
385
- req.end(data);
386
- }
387
- });
388
- };