xshell 0.0.9 → 0.0.13

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/net.d.ts CHANGED
@@ -11,10 +11,10 @@ declare module 'tough-cookie' {
11
11
  import './prototype';
12
12
  import type { Encoding } from './file';
13
13
  export declare enum MyProxy {
14
- HTTP1080 = "http://127.0.0.1:1080",
15
- whistle = "http://127.0.0.1:8899"
14
+ socks5 = "http://localhost:10080",
15
+ whistle = "http://localhost:8899"
16
16
  }
17
- export declare const Cookies: {
17
+ export declare const cookies: {
18
18
  store: MemoryCookieStore;
19
19
  jar: request_lib.CookieJar;
20
20
  get(domain_or_url: string, str?: boolean): string | Cookie[];
@@ -23,49 +23,58 @@ export { Cookie };
23
23
  export declare const _request: request_lib.RequestAPI<request_promise.RequestPromise<any>, request_promise.RequestPromiseOptions, request_lib.RequiredUriUrl>;
24
24
  export declare function request_retry(retries: number, request_options: request_promise.OptionsWithUrl): Promise<request_lib.Response>;
25
25
  export interface RequestOptions {
26
+ method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch';
26
27
  queries?: Record<string, any>;
27
- /** HTTP request body data */
28
+ headers?: Record<string, string>;
28
29
  body?: string | Record<string, any>;
29
- /** is JSON format */
30
- json?: boolean;
31
- /** form (x-www-form-urlencoded or multipart) format */
32
- form?: boolean | 'application/x-www-form-urlencoded' | 'multipart/form-data';
33
- /** `false` when proxy is true then use MyProxy.whistle */
30
+ type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data';
34
31
  proxy?: boolean | MyProxy | string;
35
- method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'PATCH';
36
- headers?: Record<string, string>;
37
- /** `(webpage content-type: charset=gb18030) || 'UTF-8'` */
38
32
  encoding?: Encoding;
39
- /** `false` */
40
- retries?: boolean | number;
41
- /** `20 * 1000` */
33
+ retries?: true | number;
42
34
  timeout?: number;
43
35
  auth?: {
44
36
  username: string;
45
37
  password: string;
46
38
  };
47
- /** `raw -> false; else -> true` */
48
39
  gzip?: boolean;
49
40
  cookies?: Record<string, string>;
50
41
  }
51
42
  export interface RequestRawOptions extends RequestOptions {
52
43
  raw: true;
53
44
  }
45
+ /**
46
+ - url: must be full url
47
+ - options:
48
+ - raw: `false` 传入后返回整个 response
49
+ - encoding: `(response content-type: charset=gb18030) || 'utf-8'` when 'binary' then return buffer
50
+ - type: `'application/json'` request content-type header (if has body)
51
+ - proxy: `false` proxy === true then use MyProxy.whistle
52
+ - retries: `false` could be true (default 3 times) or retry times
53
+ - timeout: `20 * 1000`
54
+ - gzip: `raw -> false; else -> true`
55
+ */
54
56
  export declare function request(url: string | URL): Promise<string>;
55
57
  export declare function request(url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>;
56
58
  export declare function request(url: string | URL, options: RequestOptions & {
57
- encoding: 'BINARY';
59
+ encoding: 'binary';
58
60
  }): Promise<Buffer>;
59
61
  export declare function request(url: string | URL, options: RequestOptions): Promise<string>;
62
+ /** make http request and parse body as json */
60
63
  export declare function request_json<T = any>(url: string | URL, options?: RequestOptions): Promise<T>;
61
64
  /** use $.html(cheerio_element) to get outer html */
62
65
  export declare function parse_html(html: string): cheerio.Root;
63
66
  /** use $.html(cheerio_element) to get outer html */
64
67
  export declare function request_page(url: string | URL, options?: RequestOptions): Promise<cheerio.Root>;
65
- export declare function to_curl(url: string | URL, { queries, headers, method, body, json, proxy, exe }?: RequestOptions & {
68
+ export declare function to_curl(url: string | URL, { queries, headers, method, body, proxy, exe }?: RequestOptions & {
66
69
  exe?: boolean;
67
70
  }): string;
68
- /** POST JSON to http://127.0.0.1:8421/api/rpc */
71
+ /** post json to http://localhost:8421/api/rpc
72
+ - func: function name
73
+ - args?: argument array
74
+ - options?:
75
+ - ignore?: `false` wait for execution but do not serialize result to response
76
+ - async?: `false` do not wait for exec
77
+ */
69
78
  export declare function rpc(func: string, args?: any[], { url, async: _async, ignore }?: {
70
79
  url?: string;
71
80
  async?: boolean;
package/net.js CHANGED
@@ -1,26 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rpc_curl = exports.rpc = exports.to_curl = exports.request_page = exports.parse_html = exports.request_json = exports.request = exports.request_retry = exports._request = exports.Cookie = exports.Cookies = exports.MyProxy = void 0;
3
+ exports.rpc_curl = exports.rpc = exports.to_curl = exports.request_page = exports.parse_html = exports.request_json = exports.request = exports.request_retry = exports._request = exports.Cookie = exports.cookies = exports.MyProxy = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const request_promise_native_1 = tslib_1.__importDefault(require("request-promise-native"));
5
+ const request_promise_native_1 = (0, tslib_1.__importDefault)(require("request-promise-native"));
6
6
  const errors_1 = require("request-promise-native/errors");
7
- const promise_retry_1 = tslib_1.__importDefault(require("promise-retry"));
8
- const iconv_lite_1 = tslib_1.__importDefault(require("iconv-lite"));
9
- const cheerio_1 = tslib_1.__importDefault(require("cheerio"));
10
- const qs_1 = tslib_1.__importDefault(require("qs"));
7
+ const promise_retry_1 = (0, tslib_1.__importDefault)(require("promise-retry"));
8
+ const iconv_lite_1 = (0, tslib_1.__importDefault)(require("iconv-lite"));
9
+ const cheerio_1 = (0, tslib_1.__importDefault)(require("cheerio"));
10
+ const qs_1 = (0, tslib_1.__importDefault)(require("qs"));
11
11
  const tough_cookie_1 = require("tough-cookie");
12
12
  Object.defineProperty(exports, "Cookie", { enumerable: true, get: function () { return tough_cookie_1.Cookie; } });
13
13
  require("./prototype");
14
14
  const utils_1 = require("./utils");
15
15
  var MyProxy;
16
16
  (function (MyProxy) {
17
- MyProxy["HTTP1080"] = "http://127.0.0.1:1080";
18
- MyProxy["whistle"] = "http://127.0.0.1:8899";
17
+ MyProxy["socks5"] = "http://localhost:10080";
18
+ MyProxy["whistle"] = "http://localhost:8899";
19
19
  })(MyProxy = exports.MyProxy || (exports.MyProxy = {}));
20
20
  // ------------------------------------ Fetch, Request
21
- const DEFAULT_RETRIES = 3;
22
21
  const cookie_store = new tough_cookie_1.MemoryCookieStore();
23
- exports.Cookies = {
22
+ exports.cookies = {
24
23
  store: cookie_store,
25
24
  jar: request_promise_native_1.default.jar(cookie_store),
26
25
  get(domain_or_url, str = false) {
@@ -43,10 +42,10 @@ exports._request = request_promise_native_1.default.defaults({
43
42
  gzip: true,
44
43
  /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */
45
44
  simple: false,
46
- jar: exports.Cookies.jar
45
+ jar: exports.cookies.jar
47
46
  });
48
47
  async function request_retry(retries, request_options) {
49
- return promise_retry_1.default({
48
+ return (0, promise_retry_1.default)({
50
49
  retries,
51
50
  minTimeout: 1000,
52
51
  maxTimeout: Infinity,
@@ -54,7 +53,7 @@ async function request_retry(retries, request_options) {
54
53
  }, async (retry, count) => {
55
54
  var _a;
56
55
  try {
57
- return await exports._request(request_options);
56
+ return await (0, exports._request)(request_options);
58
57
  }
59
58
  catch (error) {
60
59
  if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes((_a = error.cause) === null || _a === void 0 ? void 0 : _a.code))
@@ -66,20 +65,16 @@ async function request_retry(retries, request_options) {
66
65
  });
67
66
  }
68
67
  exports.request_retry = request_retry;
69
- async function request(url, { queries, body, json, form, proxy, method, headers, encoding, raw = false, retries = false, timeout = 20 * 1000, auth, gzip, cookies, } = {}) {
68
+ async function request(url, { queries, body, type = 'application/json', proxy, method, headers, encoding, raw = false, retries, timeout = 20 * 1000, auth, gzip, cookies, } = {}) {
70
69
  var _a;
71
70
  url = url.toString();
72
71
  if (!url.startsWith('http'))
73
72
  url = 'http://' + url;
73
+ const _body = body; // for error log
74
74
  if (body && !method)
75
- method = 'POST';
76
- if (form) {
77
- // pass
78
- }
79
- else if (typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body))) {
80
- json = true;
75
+ method = 'post';
76
+ if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))
81
77
  body = JSON.stringify(body);
82
- }
83
78
  // --- proxy
84
79
  if (proxy) {
85
80
  if (proxy === true)
@@ -92,22 +87,32 @@ async function request(url, { queries, body, json, form, proxy, method, headers,
92
87
  gzip = !raw;
93
88
  const options = {
94
89
  url,
95
- method,
90
+ ...method ? { method: method.toUpperCase() } : {},
96
91
  proxy,
97
92
  gzip,
98
93
  encoding: null,
99
94
  resolveWithFullResponse: true,
100
95
  headers: {
101
96
  'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',
102
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',
103
- ...json && !form ? { 'content-type': 'application/json' } : {},
104
- ...cookies ? { cookie: Object.entries(cookies).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('; ') } : {},
97
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',
98
+ ...body ? { 'content-type': type } : {},
99
+ ...cookies ? {
100
+ cookie: Object.entries(cookies)
101
+ .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('; ')
102
+ } : {},
105
103
  ...headers
106
104
  },
107
105
  ...queries ? { qs: queries } : {},
108
- ...(!form && body) ? { body } : {},
109
- ...(form === true || form === 'application/x-www-form-urlencoded') ? { form: body } : {},
110
- ...(form === 'multipart/form-data') ? { formData: body } : {},
106
+ // --- body
107
+ ...(() => {
108
+ if (!body)
109
+ return {};
110
+ if (type === 'application/x-www-form-urlencoded')
111
+ return { form: body };
112
+ if (type === 'multipart/form-data')
113
+ return { formData: body };
114
+ return { body };
115
+ })(),
111
116
  ...timeout ? { timeout } : {},
112
117
  ...auth ? { auth } : {},
113
118
  };
@@ -115,61 +120,62 @@ async function request(url, { queries, body, json, form, proxy, method, headers,
115
120
  try {
116
121
  if (retries) {
117
122
  if (retries === true)
118
- retries = DEFAULT_RETRIES;
123
+ retries = 3;
119
124
  resp = await request_retry(retries, options);
120
125
  }
121
126
  else
122
- resp = await exports._request(options);
127
+ resp = await (0, exports._request)(options);
123
128
  if (!(200 <= resp.statusCode && resp.statusCode <= 299))
124
129
  throw new errors_1.StatusCodeError(resp.statusCode, resp.body, options, resp);
125
130
  }
126
131
  catch (error) {
127
- const { name, options: { method, url, uri, qs, body }, response, } = error;
132
+ const { name, options: { method, url, uri, qs }, response, } = error;
128
133
  error[utils_1.inspect.custom] = () => {
129
- let s = '─'.repeat(global.WIDTH / 2) + '\n' +
130
- `${name.red} ${(method || 'GET').blue} ${String(url || uri).blue.underline}\n`;
134
+ let s = '─'.repeat(utils_1.output_width / 2) + '\n' +
135
+ `${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\n`;
131
136
  if (qs)
132
- s += `\n${'Request Query:'.blue}\n` +
133
- utils_1.inspect(qs) + '\n';
134
- if (body)
135
- s += `\n${'Request Body:'.blue}\n` +
136
- utils_1.inspect(body) + '\n';
137
+ s += `\n${'request.query:'.blue}\n` +
138
+ (0, utils_1.inspect)(qs) + '\n';
139
+ if (_body)
140
+ s += `\n${'request.body:'.blue}\n` +
141
+ (0, utils_1.inspect)(body) + '\n';
137
142
  if (name === 'StatusCodeError')
138
- s += `\n${'Status Code:'.yellow} ${String(error.statusCode).red}\n`;
143
+ s += `\n${'response.status:'.yellow} ${String(error.statusCode).red}\n`;
139
144
  else if (error instanceof errors_1.RequestError)
140
- s += `\n${'Cause:'.yellow}\n` +
141
- `${utils_1.inspect(error.cause)}\n`;
145
+ s += `\n${'response.cause:'.yellow}\n` +
146
+ `${(0, utils_1.inspect)(error.cause)}\n`;
142
147
  else
143
- s += `\n${utils_1.inspect(error)}\n`;
148
+ s += `\n${(0, utils_1.inspect)(error)}\n`;
144
149
  if (response) {
145
- s += `\n${'Response Headers:'.yellow}\n` +
146
- `${utils_1.inspect(response.headers)}\n`;
150
+ s += `\n${'response.headers:'.yellow}\n` +
151
+ `${(0, utils_1.inspect)(response.headers)}\n`;
147
152
  if (response.body)
148
- s += `\n${'Response Body:'.yellow}\n` +
149
- `${utils_1.inspect(response.body.toString())}\n`;
153
+ s += `\n${'response.body:'.yellow}\n` +
154
+ `${(0, utils_1.inspect)(response.body.toString())}\n`;
150
155
  }
151
- s += `\n${'Stack:'.yellow}\n` +
156
+ s += `\n${'stack:'.yellow}\n` +
152
157
  `${new Error().stack}\n` +
153
- '─'.repeat(global.WIDTH / 2);
158
+ '─'.repeat(utils_1.output_width / 2);
154
159
  return s;
155
160
  };
156
161
  throw error;
157
162
  }
158
- if (encoding === 'BINARY')
159
- return resp.body;
160
- encoding = (encoding || ((_a = /charset=(.*)/.exec(resp.headers['content-type'])) === null || _a === void 0 ? void 0 : _a[1]) || 'UTF-8');
161
163
  if (raw)
162
164
  return resp;
163
165
  if (!resp.body)
164
166
  return resp.body;
167
+ // --- decode body
168
+ if (encoding === 'binary')
169
+ return resp.body;
170
+ encoding || (encoding = ((_a = /charset=(.*)/.exec(resp.headers['content-type'])) === null || _a === void 0 ? void 0 : _a[1]) || 'utf-8');
171
+ if (/utf-?8/i.test(encoding))
172
+ return resp.body.toString('utf-8');
165
173
  return iconv_lite_1.default.decode(resp.body, encoding);
166
174
  }
167
175
  exports.request = request;
176
+ /** make http request and parse body as json */
168
177
  async function request_json(url, options) {
169
- const resp = await request(url, {
170
- json: true,
171
- ...options
172
- });
178
+ const resp = await request(url, options);
173
179
  if (!resp)
174
180
  return;
175
181
  try {
@@ -212,7 +218,7 @@ async function request_page(url, options) {
212
218
  return parse_html(await request(url, options));
213
219
  }
214
220
  exports.request_page = request_page;
215
- function to_curl(url, { queries, headers, method, body, json, proxy, exe = true } = {}) {
221
+ function to_curl(url, { queries, headers, method, body, proxy, exe = true } = {}) {
216
222
  if (proxy === true)
217
223
  proxy = process.env.http_proxy;
218
224
  url = url.toString();
@@ -226,34 +232,38 @@ function to_curl(url, { queries, headers, method, body, json, proxy, exe = true
226
232
  // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())
227
233
  // ) +
228
234
  (proxy ? ` --proxy ${proxy.quote()}` : '') +
229
- (method && method !== 'GET' ? ` -X ${method}` : '') +
235
+ (method && method !== 'get' ? ` -X ${method}` : '') +
230
236
  (headers ? Object.entries(headers).map(([key, value]) => ' -H ' + `${key}: ${value}`.quote()).join('') : '') +
231
- (json ? ' -H ' + 'content-type: application/json'.quote() : '') +
237
+ (body ? ' -H ' + 'content-type: application/json'.quote() : '') +
232
238
  (body ? ' --data ' + JSON.stringify(body).quote() : '');
233
239
  }
234
240
  exports.to_curl = to_curl;
235
- // ------------------------------------ RPC Client
236
- /** POST JSON to http://127.0.0.1:8421/api/rpc */
237
- async function rpc(func, args, { url = 'http://127.0.0.1:8421/api/rpc', async: _async = false, ignore = false } = {}) {
238
- if (!func) {
239
- console.error('RPC Client Error: NO FUNC');
240
- throw new Error('RPC Client Error: NO FUNC');
241
- }
241
+ // ------------------------------------ rpc client
242
+ /** post json to http://localhost:8421/api/rpc
243
+ - func: function name
244
+ - args?: argument array
245
+ - options?:
246
+ - ignore?: `false` wait for execution but do not serialize result to response
247
+ - async?: `false` do not wait for exec
248
+ */
249
+ async function rpc(func, args, { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false } = {}) {
250
+ if (!func)
251
+ throw new Error('rpc argument error: no func');
242
252
  return request_json(url, {
243
253
  body: {
244
254
  func,
245
- ...(args === null || args === void 0 ? void 0 : args.length) ? { args } : {},
246
- ..._async ? { async: _async } : {},
247
- ...ignore ? { ignore } : {},
255
+ args,
256
+ async: _async,
257
+ ignore,
248
258
  }
249
259
  });
250
260
  }
251
261
  exports.rpc = rpc;
252
262
  function rpc_curl(func, args) {
253
263
  const cmd = args.find(arg => typeof arg === 'object') ?
254
- to_curl('http://127.0.0.1:8421/api/rpc', { body: { func, args } })
264
+ to_curl('http://localhost:8421/api/rpc', { body: { func, args } })
255
265
  :
256
- to_curl('http://127.0.0.1:8421/api/rpc', { queries: { func, args } });
266
+ to_curl('http://localhost:8421/api/rpc', { queries: { func, args } });
257
267
  return cmd;
258
268
  }
259
269
  exports.rpc_curl = rpc_curl;
package/net.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAGA,4FAAoD;AAEpD,0DAA6E;AAE7E,0EAAyC;AAEzC,oEAA8B;AAC9B,8DAA6B;AAC7B,oDAAmB;AACnB,+CAAwD;AA6C/C,uFA7CA,qBAAM,OA6CA;AApCf,uBAAoB;AAEpB,mCAAiC;AAEjC,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,6CAAkC,CAAA;IAClC,4CAAiC,CAAA;AACrC,CAAC,EAHW,OAAO,GAAP,eAAO,KAAP,eAAO,QAGlB;AAGD,sDAAsD;AACtD,MAAM,eAAe,GAAG,CAAC,CAAA;AAEzB,MAAM,YAAY,GAAG,IAAI,gCAAiB,EAAE,CAAA;AAE/B,QAAA,OAAO,GAAG;IACnB,KAAK,EAAE,YAAY;IAEnB,GAAG,EAAE,gCAAe,CAAC,GAAG,CAAC,YAAY,CAAC;IAEtC,GAAG,CAAE,aAAqB,EAAE,GAAG,GAAG,KAAK;QACnC,IAAI,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC;YAChC,IAAI,GAAG;gBACH,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;;gBAE9C,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;QAEjD,IAAI,OAAiB,CAAA;QACrB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YAClE,IAAI,KAAK;gBAAE,MAAM,KAAK,CAAA;YACtB,OAAO,GAAG,QAAQ,CAAA;QACtB,CAAC,CA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_lib from 'request'\nimport type { OptionsWithUri, OptionsWithUrl } from 'request'\n\nimport request_promise from 'request-promise-native'\nimport type { FullResponse } from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors'\n\nimport promise_retry from 'promise-retry'\n\nimport iconv from 'iconv-lite'\nimport cheerio from 'cheerio'\nimport qs from 'qs'\nimport { Cookie, MemoryCookieStore } from 'tough-cookie'\n\ndeclare module 'tough-cookie' {\n interface MemoryCookieStore {\n idx: Record<string, any>\n }\n}\n\n\nimport './prototype'\nimport type { Encoding } from './file'\nimport { inspect } from './utils'\n\nexport enum MyProxy {\n HTTP1080 = 'http://127.0.0.1:1080',\n whistle = 'http://127.0.0.1:8899',\n}\n\n\n// ------------------------------------ Fetch, Request\nconst DEFAULT_RETRIES = 3\n\nconst cookie_store = new MemoryCookieStore()\n\nexport const Cookies = {\n store: cookie_store,\n \n jar: request_promise.jar(cookie_store),\n \n get (domain_or_url: string, str = false) {\n if (domain_or_url.startsWith('http'))\n if (str)\n return this.jar.getCookieString(domain_or_url)\n else\n return this.jar.getCookies(domain_or_url)\n \n let cookies: Cookie[]\n this.store.findCookies(domain_or_url, null, true, (error, _cookies) => {\n if (error) throw error\n cookies = _cookies\n })\n return cookies\n },\n}\n\nexport { Cookie }\n\n\nexport const _request = request_promise.defaults({\n rejectUnauthorized: false,\n gzip: true,\n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: Cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n queries?: Record<string, any>\n \n /** HTTP request body data */\n body?: string | Record<string, any>\n \n /** is JSON format */\n json?: boolean\n \n /** form (x-www-form-urlencoded or multipart) format */\n form?: boolean | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n /** `false` when proxy is true then use MyProxy.whistle */\n proxy?: boolean | MyProxy | string\n \n method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'PATCH'\n \n headers?: Record<string, string>\n \n /** `(webpage content-type: charset=gb18030) || 'UTF-8'` */\n encoding?: Encoding\n \n /** `false` */\n retries?: boolean | number\n \n /** `20 * 1000` */\n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n /** `raw -> false; else -> true` */\n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'BINARY' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n json,\n \n form,\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries = false,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n if (!url.startsWith('http'))\n url = 'http://' + url\n \n if (body && !method)\n method = 'POST'\n \n if (form) {\n // pass\n } else if (typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body))) {\n json = true\n body = JSON.stringify(body)\n }\n \n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n method,\n proxy,\n gzip,\n encoding: null,\n resolveWithFullResponse: true,\n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',\n ... json && !form ? { 'content-type': 'application/json' } : { }, \n ... cookies ? { cookie: Object.entries(cookies).map( ([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('; ') } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n ... (!form && body) ? { body } : { },\n ... (form === true || form === 'application/x-www-form-urlencoded') ? { form: body } : { },\n ... (form === 'multipart/form-data') ? { formData: body as Record<string, any> } : { },\n ... timeout ? { timeout } : { },\n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = DEFAULT_RETRIES\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs, body }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(global.WIDTH / 2) + '\\n' +\n `${name.red} ${(method || 'GET').blue} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'Request Query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (body)\n s += `\\n${'Request Body:'.blue}\\n` +\n inspect(body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'Status Code:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'Cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'Response Headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'Response Body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'Stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(global.WIDTH / 2)\n \n return s\n }\n \n throw error\n }\n \n if (encoding === 'BINARY')\n return resp.body\n \n encoding = (encoding || /charset=(.*)/.exec(resp.headers['content-type'])?.[1] || 'UTF-8') as Encoding\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, {\n json: true,\n ... options\n })\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html( await request(url, options) )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, json, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'GET' ? ` -X ${method}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( json ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ RPC Client\n/** POST JSON to http://127.0.0.1:8421/api/rpc */\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://127.0.0.1:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) {\n console.error('RPC Client Error: NO FUNC')\n throw new Error('RPC Client Error: NO FUNC')\n }\n return request_json(url, {\n body: {\n func,\n ... args?.length ? { args } : { },\n ... _async ? { async: _async } : { },\n ... ignore ? { ignore } : { },\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://127.0.0.1:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://127.0.0.1:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n"]}
1
+ {"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAGA,iGAAoD;AAEpD,0DAA6E;AAE7E,+EAAyC;AAEzC,yEAA8B;AAC9B,mEAA6B;AAC7B,yDAAmB;AACnB,+CAAwD;AA2C/C,uFA3CA,qBAAM,OA2CA;AAlCf,uBAAoB;AAEpB,mCAA+C;AAE/C,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,4CAAiC,CAAA;IACjC,4CAAiC,CAAA;AACrC,CAAC,EAHW,OAAO,GAAP,eAAO,KAAP,eAAO,QAGlB;AAGD,sDAAsD;AACtD,MAAM,YAAY,GAAG,IAAI,gCAAiB,EAAE,CAAA;AAE/B,QAAA,OAAO,GAAG;IACnB,KAAK,EAAE,YAAY;IAEnB,GAA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E,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;QAChD,OAAO,CAAC,+BAA+B,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;QACtE,CAAC;YACG,OAAO,CAAC,+BAA+B,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IAC7E,OAAO,GAAG,CAAA;AACd,CAAC;AAND,4BAMC","sourcesContent":["import request_lib from 'request'\nimport type { OptionsWithUri, OptionsWithUrl } from 'request'\n\nimport request_promise from 'request-promise-native'\nimport type { FullResponse } from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors'\n\nimport promise_retry from 'promise-retry'\n\nimport iconv from 'iconv-lite'\nimport cheerio from 'cheerio'\nimport qs from 'qs'\nimport { Cookie, MemoryCookieStore } from 'tough-cookie'\n\ndeclare module 'tough-cookie' {\n interface MemoryCookieStore {\n idx: Record<string, any>\n }\n}\n\n\nimport './prototype'\nimport type { Encoding } from './file'\nimport { inspect, output_width } from './utils'\n\nexport enum MyProxy {\n socks5 = 'http://localhost:10080',\n whistle = 'http://localhost:8899',\n}\n\n\n// ------------------------------------ Fetch, Request\nconst cookie_store = new MemoryCookieStore()\n\nexport const cookies = {\n store: cookie_store,\n \n jar: request_promise.jar(cookie_store),\n \n get (domain_or_url: string, str = false) {\n if (domain_or_url.startsWith('http'))\n if (str)\n return this.jar.getCookieString(domain_or_url)\n else\n return this.jar.getCookies(domain_or_url)\n \n let cookies: Cookie[]\n this.store.findCookies(domain_or_url, null, true, (error, _cookies) => {\n if (error) throw error\n cookies = _cookies\n })\n return cookies\n },\n}\n\nexport { Cookie }\n\n\nexport const _request = request_promise.defaults({\n rejectUnauthorized: false,\n gzip: true,\n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | Record<string, any>\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n \n proxy?: boolean | MyProxy | string\n \n encoding?: Encoding\n \n retries?: true | number\n \n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/** \n - url: must be full url\n - options:\n - raw: `false` 传入后返回整个 response\n - encoding: `(response content-type: charset=gb18030) || 'utf-8'` when 'binary' then return buffer\n - type: `'application/json'` request content-type header (if has body)\n - proxy: `false` proxy === true then use MyProxy.whistle\n - retries: `false` could be true (default 3 times) or retry times\n - timeout: `20 * 1000`\n - gzip: `raw -> false; else -> true`\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'binary' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n type = 'application/json',\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n if (!url.startsWith('http'))\n url = 'http://' + url\n \n const _body = body // for error log\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))\n body = JSON.stringify(body)\n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n \n ... method ? { method: method.toUpperCase() } : { },\n \n proxy,\n \n gzip,\n \n encoding: null,\n \n resolveWithFullResponse: true,\n \n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',\n ... body ? { 'content-type': type } : { }, \n ... cookies ? {\n cookie: Object.entries(cookies)\n .map(([key, value]) => \n `${encodeURIComponent(key)}=${encodeURIComponent(value)}`\n ).join('; ')\n } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n \n // --- body\n ... (() => {\n if (!body) return { }\n if (type === 'application/x-www-form-urlencoded') return { form: body }\n if (type === 'multipart/form-data') return { formData: body as Record<string, any> }\n return { body }\n })(),\n \n ... timeout ? { timeout } : { },\n \n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = 3\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n \n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(output_width / 2) + '\\n' +\n `${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'request.query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (_body)\n s += `\\n${'request.body:'.blue}\\n` +\n inspect(body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'response.status:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'response.cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'response.headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'response.body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(output_width / 2)\n \n return s\n }\n \n throw error\n }\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n // --- decode body\n if (encoding === 'binary')\n return resp.body\n \n encoding ||= /charset=(.*)/.exec(resp.headers['content-type'])?.[1] as Encoding || 'utf-8'\n \n if (/utf-?8/i.test(encoding))\n return (resp.body as Buffer).toString('utf-8')\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\n/** make http request and parse body as json */\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html(\n await request(url, options)\n )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'get' ? ` -X ${method}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( body ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ rpc client\n/** post json to http://localhost:8421/api/rpc\n - func: function name\n - args?: argument array\n - options?:\n - ignore?: `false` wait for execution but do not serialize result to response\n - async?: `false` do not wait for exec\n*/\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) throw new Error('rpc argument error: no func')\n \n return request_json(url, {\n body: {\n func,\n args,\n async: _async,\n ignore,\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://localhost:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://localhost:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "0.0.9",
3
+ "version": "0.0.13",
4
4
  "main": "./index.js",
5
5
  "bin": {
6
6
  "xshell": "./xshell.js"
@@ -15,7 +15,7 @@
15
15
  "type": "commonjs",
16
16
  "engines": {
17
17
  "node": ">=16.0.0",
18
- "vscode": ">=1.56.0"
18
+ "vscode": ">=1.62.0"
19
19
  },
20
20
  "scripts": {
21
21
  "start": "node --title=xshell --inspect=0.0.0.0:8420 ./xshell.js",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "author": {
29
29
  "name": "ShenHongFei",
30
- "email": "shf19961008@gmail.com",
30
+ "email": "shen.hongfei@outlook.com",
31
31
  "url": "https://github.com/ShenHongFei"
32
32
  },
33
33
  "publisher": "ShenHongFei",
@@ -64,22 +64,20 @@
64
64
  },
65
65
  "dependencies": {
66
66
  "@koa/cors": "^3.1.0",
67
- "byte-size": "^8.0.0",
68
- "chardet": "^1.3.0",
67
+ "byte-size": "^8.1.0",
68
+ "chalk": "^4.1.2",
69
+ "chardet": "^1.4.0",
69
70
  "cheerio": "^1.0.0-rc.10",
70
- "colors": "^1.4.0",
71
- "emoji-regex": "^9.2.2",
71
+ "emoji-regex": "^10.0.0",
72
72
  "fs-extra": "^10.0.0",
73
73
  "fs-monkey": "^1.0.3",
74
74
  "iconv-lite": "^0.6.3",
75
- "koa": "^2.13.1",
76
- "koa-compress": "^5.0.1",
75
+ "koa": "^2.13.4",
76
+ "koa-compress": "^5.1.0",
77
77
  "koa-useragent": "^4.0.0",
78
78
  "lodash": "^4.17.21",
79
- "memfs": "^3.2.2",
80
- "parse-multipart-data": "^1.2.0",
79
+ "memfs": "^3.4.0",
81
80
  "promise-retry": "^2.0.1",
82
- "puppeteer-core": "^10.2.0",
83
81
  "qs": "^6.10.1",
84
82
  "readdir-enhanced": "^6.0.4",
85
83
  "request": "^2.88.2",
@@ -88,28 +86,24 @@
88
86
  "stream-buffers": "^3.0.2",
89
87
  "strip-ansi": "=6.0.0",
90
88
  "tough-cookie": "^4.0.0",
91
- "trash": "^7.2.0",
92
- "tslib": "^2.3.0",
93
- "typescript": "^4.3.5",
94
- "upath": "^2.0.1",
95
- "utf-8-validate": "^5.0.5"
89
+ "tslib": "^2.3.1",
90
+ "typescript": "^4.5.2",
91
+ "upath": "^2.0.1"
96
92
  },
97
93
  "devDependencies": {
98
94
  "@types/chardet": "^0.8.1",
99
95
  "@types/cheerio": "^0.22.30",
100
- "@types/fs-extra": "^9.0.12",
96
+ "@types/fs-extra": "^9.0.13",
101
97
  "@types/koa": "^2.13.4",
102
98
  "@types/koa-compress": "^4.0.3",
103
- "@types/lodash": "^4.14.172",
104
- "@types/node": "^16.4.13",
105
- "@types/node-schedule": "^1.3.2",
99
+ "@types/lodash": "^4.14.177",
100
+ "@types/node": "^16.11.10",
106
101
  "@types/promise-retry": "^1.1.3",
107
102
  "@types/qs": "^6.9.7",
108
103
  "@types/request": "^2.48.7",
109
104
  "@types/request-promise-native": "^1.0.18",
110
- "@types/rimraf": "^3.0.1",
111
- "@types/shortid": "^0.0.29",
105
+ "@types/rimraf": "^3.0.2",
112
106
  "@types/stream-buffers": "^3.0.4",
113
- "@types/vscode": "^1.56.0"
107
+ "@types/vscode": "^1.62.0"
114
108
  }
115
109
  }