@jayfong/x-server 2.12.7 → 2.12.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.
File without changes
@@ -1,306 +1,26 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
3
  exports.__esModule = true;
6
- exports.RequestService = exports.RequestFormUrlencoded = exports.RequestFormStream = exports.RequestFormFile = exports.RequestFormData = void 0;
7
-
8
- var _assert = _interopRequireDefault(require("assert"));
9
-
10
- var _formData = _interopRequireDefault(require("form-data"));
11
-
12
- var _formstream = _interopRequireDefault(require("formstream"));
13
-
14
- var _fs = _interopRequireDefault(require("fs"));
15
-
16
- var _got = _interopRequireDefault(require("got"));
17
-
18
- var _vtils = require("vtils");
19
-
20
- var _proxyAgent = require("proxy-agent");
21
-
22
- var _stream = require("stream");
23
-
24
- class RequestFormUrlencoded extends URLSearchParams {}
25
-
26
- exports.RequestFormUrlencoded = RequestFormUrlencoded;
27
-
28
- class RequestFormData extends _formData.default {
29
- constructor(cbOrObject) {
30
- super();
31
-
32
- if (cbOrObject) {
33
- if (typeof cbOrObject === 'function') {
34
- cbOrObject(this);
35
- } else {
36
- Object.keys(cbOrObject).forEach(key => {
37
- const value = cbOrObject[key];
38
-
39
- if (value instanceof RequestFormFile) {
40
- var _value$options, _value$options2;
41
-
42
- this.append(key, typeof value.file === 'string' ? _fs.default.createReadStream(value.file) : value.file, {
43
- filename: (_value$options = value.options) == null ? void 0 : _value$options.name,
44
- contentType: (_value$options2 = value.options) == null ? void 0 : _value$options2.type
45
- });
46
- } else {
47
- this.append(key, value);
48
- }
49
- });
50
- }
51
- }
52
- }
53
-
54
- }
55
-
56
- exports.RequestFormData = RequestFormData;
57
-
58
- class RequestFormStream extends _formstream.default {
59
- constructor(cbOrObject) {
60
- super();
61
-
62
- if (cbOrObject) {
63
- if (typeof cbOrObject === 'function') {
64
- cbOrObject(this);
65
- } else {
66
- Object.keys(cbOrObject).forEach(key => {
67
- const value = cbOrObject[key];
68
-
69
- if (value instanceof RequestFormFile) {
70
- if (typeof value.file === 'string') {
71
- var _value$options3;
72
-
73
- this.file(key, value.file, (_value$options3 = value.options) == null ? void 0 : _value$options3.name);
74
- } else if (Buffer.isBuffer(value.file)) {
75
- this.buffer(key, value.file, value.options.name, value.options.type);
76
- } else if (value.file instanceof _stream.Readable) {
77
- this.stream(key, value.file, value.options.name, value.options.type);
78
- }
79
- } else {
80
- this.field(key, value);
81
- }
82
- });
83
- }
84
- }
85
- }
86
-
87
- }
88
-
89
- exports.RequestFormStream = RequestFormStream;
90
-
91
- class RequestFormFile {
92
- constructor(file, options) {
93
- this.file = file;
94
- this.options = options;
95
-
96
- if (Buffer.isBuffer(file) || file instanceof _stream.Readable) {
97
- (0, _assert.default)(options == null ? void 0 : options.name, 'options.name is required');
98
- }
99
- }
100
-
101
- }
102
-
103
- exports.RequestFormFile = RequestFormFile;
104
-
105
- class RequestService {
106
- static getGotOptions(options, responseType) {
107
- var _gotOptions$headers, _userAgent, _gotOptions$headers$_, _options$userAgent;
108
-
109
- const gotOptions = {
110
- url: options.url,
111
- responseType: responseType === 'stream' ? undefined : responseType,
112
- https: {
113
- rejectUnauthorized: false
114
- },
115
- isStream: responseType === 'stream'
116
- };
117
-
118
- if (options.headers) {
119
- gotOptions.headers = options.headers;
120
- }
121
-
122
- if (options.followRedirect != null) {
123
- gotOptions.followRedirect = options.followRedirect;
124
- }
125
-
126
- if (options.timeoutMs) {
127
- gotOptions.timeout = options.timeoutMs;
128
- }
129
-
130
- if (options.proxyUrl) {
131
- const proxyAgent = new _proxyAgent.ProxyAgent({
132
- getProxyForUrl: () => options.proxyUrl
133
- });
134
- gotOptions.agent = {
135
- http: proxyAgent,
136
- https: proxyAgent,
137
- http2: proxyAgent
138
- };
139
- }
140
-
141
- if (options.cookieJar) {
142
- gotOptions.cookieJar = options.cookieJar;
143
- } // 头处理
144
-
145
-
146
- gotOptions.headers = (0, _vtils.mapKeys)(gotOptions.headers || {}, (v, k) => k.toLowerCase());
147
- (_gotOptions$headers$_ = (_gotOptions$headers = gotOptions.headers)[_userAgent = 'user-agent']) != null ? _gotOptions$headers$_ : _gotOptions$headers[_userAgent] = (_options$userAgent = options.userAgent) != null ? _options$userAgent : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36';
148
-
149
- if (options.autoReferer && gotOptions.headers['referer'] == null) {
150
- gotOptions.headers['referer'] = options.url;
151
- }
152
-
153
- return gotOptions;
154
- }
155
-
156
- static getRaw(options, responseType) {
157
- let url = options.url;
158
-
159
- if (options.data) {
160
- const _url = new URL(url);
161
-
162
- Object.keys(options.data).forEach(key => {
163
- _url.searchParams.set(key, options.data[key]);
164
- });
165
- url = _url.toString();
166
- }
167
-
168
- options.url = url;
169
- const res = (0, _got.default)({
170
- method: 'GET',
171
- ...this.getGotOptions(options, responseType || 'buffer')
172
- });
173
-
174
- if (responseType === 'stream') {
175
- return res;
176
- }
177
-
178
- return res.then(res => ({
179
- status: res.statusCode,
180
- headers: res.headers,
181
- data: res.body
182
- }));
183
- }
184
-
185
- static postRaw(options, responseType) {
186
- const gotOptions = this.getGotOptions(options, responseType || 'buffer');
187
-
188
- if (responseType === 'stream' && options.data instanceof _formstream.default) {
189
- gotOptions.headers = options.data.headers(gotOptions.headers);
190
- }
191
-
192
- const res = (0, _got.default)({
193
- method: 'POST',
194
- ...(options.data == null ? {
195
- body: ''
196
- } : options.data instanceof _formData.default ? {
197
- body: options.data
198
- } : options.data instanceof URLSearchParams ? {
199
- form: options.data
200
- } : options.data instanceof _formstream.default ? {} : {
201
- json: options.data
202
- }),
203
- ...gotOptions
204
- });
205
-
206
- if (responseType === 'stream' && options.data instanceof _formstream.default) {
207
- options.data.pipe(res);
208
- }
209
-
210
- if (responseType === 'stream') {
211
- return res;
212
- }
213
-
214
- return res.then(res => ({
215
- status: res.statusCode,
216
- headers: res.headers,
217
- data: res.body
218
- }));
219
- }
220
-
221
- static async getText(options) {
222
- return this.getRaw(options, 'text');
223
- }
224
-
225
- static async postText(options) {
226
- return this.postRaw(options, 'text');
227
- }
228
-
229
- static async get(options) {
230
- return this.getRaw(options, 'json');
231
- }
232
-
233
- static async post(options) {
234
- return this.postRaw(options, 'json');
235
- }
236
-
237
- static getStream(options) {
238
- return this.getRaw(options, 'stream');
239
- }
240
-
241
- static postStream(options) {
242
- return this.postRaw(options, 'stream');
243
- }
244
-
245
- static isTimeoutError(err) {
246
- return err instanceof _got.default.TimeoutError;
247
- }
248
-
249
- constructor(options) {
250
- this.options = options;
4
+ var _exportNames = {
5
+ RequestService: true
6
+ };
7
+ exports.RequestService = void 0;
8
+
9
+ var _xRequest = require("@jayfong/x-request");
10
+
11
+ Object.keys(_xRequest).forEach(function (key) {
12
+ if (key === "default" || key === "__esModule") return;
13
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
14
+ if (key in exports && exports[key] === _xRequest[key]) return;
15
+ exports[key] = _xRequest[key];
16
+ });
17
+
18
+ class RequestService extends _xRequest.XRequest {
19
+ constructor(...args) {
20
+ super(...args);
251
21
  this.serviceName = 'request';
252
22
  }
253
23
 
254
- getRaw(options, responseType) {
255
- var _this$options;
256
-
257
- return RequestService.getRaw({ ...this.options,
258
- ...options,
259
- headers: { ...((_this$options = this.options) == null ? void 0 : _this$options.headers),
260
- ...options.headers
261
- }
262
- }, responseType);
263
- }
264
-
265
- postRaw(options, responseType) {
266
- var _this$options2;
267
-
268
- return RequestService.postRaw({ ...this.options,
269
- ...options,
270
- headers: { ...((_this$options2 = this.options) == null ? void 0 : _this$options2.headers),
271
- ...options.headers
272
- }
273
- }, responseType);
274
- }
275
-
276
- async getText(options) {
277
- return this.getRaw(options, 'text');
278
- }
279
-
280
- async postText(options) {
281
- return this.postRaw(options, 'text');
282
- }
283
-
284
- async get(options) {
285
- return this.getRaw(options, 'json');
286
- }
287
-
288
- async post(options) {
289
- return this.postRaw(options, 'json');
290
- }
291
-
292
- getStream(options) {
293
- return this.getRaw(options, 'stream');
294
- }
295
-
296
- postStream(options) {
297
- return this.postRaw(options, 'stream');
298
- }
299
-
300
- isTimeoutError(err) {
301
- return RequestService.isTimeoutError(err);
302
- }
303
-
304
24
  }
305
25
 
306
26
  exports.RequestService = RequestService;
@@ -1,135 +1,8 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import FormData from 'form-data';
4
- import FormStream from 'formstream';
5
- import Request from 'got/dist/source/core';
6
1
  import { BaseService } from './base';
7
- import { CookieJar } from 'tough-cookie';
8
- import { OmitStrict } from 'vtils/types';
9
- import { Readable } from 'stream';
10
- export interface RequestServiceOptions {
11
- /**
12
- * 请求地址
13
- */
14
- url: string;
15
- /**
16
- * 代理地址
17
- */
18
- proxyUrl?: string;
19
- /**
20
- * 超时毫秒数
21
- */
22
- timeoutMs?: number;
23
- /**
24
- * 头
25
- */
26
- headers?: Record<string, any>;
27
- /**
28
- * 是否跟随跳转
29
- *
30
- * @default true
31
- */
32
- followRedirect?: boolean;
33
- /**
34
- * COOKIE 容器
35
- */
36
- cookieJar?: CookieJar;
37
- /**
38
- * 用户代理
39
- *
40
- * @default "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
41
- */
42
- userAgent?: string;
43
- /**
44
- * 是否自动设置来源地址,设为 true 后若未手动设置来源页则将把请求地址设为来源地址
45
- *
46
- * @default false
47
- */
48
- autoReferer?: boolean;
49
- }
50
- export interface RequestServiceResponse<T> {
51
- status: number;
52
- headers: Record<string, any>;
53
- data: T;
54
- }
55
- export interface RequestServiceGetOptions extends RequestServiceOptions {
56
- data?: Record<string, any>;
57
- }
58
- export interface RequestServicePostOptions extends RequestServiceOptions {
59
- data?: Record<string, any> | FormData | URLSearchParams;
60
- }
61
- export interface RequestServiceGetStreamOptions extends RequestServiceOptions {
62
- data?: Record<string, any>;
63
- }
64
- export interface RequestServicePostStreamOptions extends RequestServiceOptions {
65
- data?: Record<string, any> | FormData | URLSearchParams | FormStream;
66
- }
67
- export declare class RequestFormUrlencoded extends URLSearchParams {
68
- }
69
- export declare class RequestFormData extends FormData {
70
- constructor(cbOrObject?: ((formData: FormData) => FormData) | Record<string, any>);
71
- }
72
- export declare class RequestFormStream extends FormStream {
73
- constructor(cbOrObject?: ((formStream: FormStream) => FormStream) | Record<string, any>);
74
- }
75
- export declare class RequestFormFile {
76
- file: any;
77
- options?: {
78
- name?: string;
79
- type?: string;
80
- };
81
- constructor(file: Buffer, options: {
82
- name: string;
83
- type?: string;
84
- });
85
- constructor(file: Readable, options: {
86
- name: string;
87
- type?: string;
88
- });
89
- constructor(file: string, options?: {
90
- name?: string;
91
- type?: string;
92
- });
93
- }
94
- export declare class RequestService implements BaseService {
95
- private options?;
2
+ import { XRequest } from '@jayfong/x-request';
3
+ export * from '@jayfong/x-request';
4
+ export declare class RequestService extends XRequest implements BaseService {
96
5
  serviceName: string;
97
- private static getGotOptions;
98
- static getRaw(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<Buffer>>;
99
- static getRaw(options: RequestServiceGetStreamOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
100
- static getRaw(options: RequestServiceGetStreamOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
101
- static getRaw<T>(options: RequestServiceGetStreamOptions, responseType: 'json'): Promise<RequestServiceResponse<T>>;
102
- static getRaw(options: RequestServiceGetStreamOptions, responseType: 'stream'): Request;
103
- static postRaw(options: RequestServicePostOptions): Promise<RequestServiceResponse<Buffer>>;
104
- static postRaw(options: RequestServicePostOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
105
- static postRaw(options: RequestServicePostOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
106
- static postRaw<T>(options: RequestServicePostOptions, responseType: 'json'): Promise<RequestServiceResponse<T>>;
107
- static postRaw(options: RequestServicePostOptions, responseType: 'stream'): Request;
108
- static getText(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<string>>;
109
- static postText(options: RequestServicePostOptions): Promise<RequestServiceResponse<string>>;
110
- static get<T>(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<T>>;
111
- static post<T>(options: RequestServicePostOptions): Promise<RequestServiceResponse<T>>;
112
- static getStream(options: RequestServiceGetOptions): Request;
113
- static postStream(options: RequestServicePostStreamOptions): Request;
114
- static isTimeoutError(err: any): boolean;
115
- constructor(options?: OmitStrict<RequestServiceOptions, 'url'>);
116
- getRaw(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<Buffer>>;
117
- getRaw(options: RequestServiceGetStreamOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
118
- getRaw(options: RequestServiceGetStreamOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
119
- getRaw<T>(options: RequestServiceGetStreamOptions, responseType: 'json'): Promise<RequestServiceResponse<T>>;
120
- getRaw(options: RequestServiceGetStreamOptions, responseType: 'stream'): Request;
121
- postRaw(options: RequestServicePostOptions): Promise<RequestServiceResponse<Buffer>>;
122
- postRaw(options: RequestServicePostOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
123
- postRaw(options: RequestServicePostOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
124
- postRaw<T>(options: RequestServicePostOptions, responseType: 'json'): Promise<RequestServiceResponse<T>>;
125
- postRaw(options: RequestServicePostOptions, responseType: 'stream'): Request;
126
- getText(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<string>>;
127
- postText(options: RequestServicePostOptions): Promise<RequestServiceResponse<string>>;
128
- get<T>(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<T>>;
129
- post<T>(options: RequestServicePostOptions): Promise<RequestServiceResponse<T>>;
130
- getStream(options: RequestServiceGetOptions): Request;
131
- postStream(options: RequestServicePostStreamOptions): Request;
132
- isTimeoutError(err: any): boolean;
133
6
  }
134
7
  declare module '../x' {
135
8
  interface X {
@@ -1,277 +1,9 @@
1
- import assert from 'assert';
2
- import FormData from 'form-data';
3
- import FormStream from 'formstream';
4
- import fs from 'fs';
5
- import got from 'got';
6
- import { mapKeys } from 'vtils';
7
- import { ProxyAgent } from 'proxy-agent';
8
- import { Readable } from 'stream';
9
- export class RequestFormUrlencoded extends URLSearchParams {}
10
- export class RequestFormData extends FormData {
11
- constructor(cbOrObject) {
12
- super();
13
-
14
- if (cbOrObject) {
15
- if (typeof cbOrObject === 'function') {
16
- cbOrObject(this);
17
- } else {
18
- Object.keys(cbOrObject).forEach(key => {
19
- const value = cbOrObject[key];
20
-
21
- if (value instanceof RequestFormFile) {
22
- var _value$options, _value$options2;
23
-
24
- this.append(key, typeof value.file === 'string' ? fs.createReadStream(value.file) : value.file, {
25
- filename: (_value$options = value.options) == null ? void 0 : _value$options.name,
26
- contentType: (_value$options2 = value.options) == null ? void 0 : _value$options2.type
27
- });
28
- } else {
29
- this.append(key, value);
30
- }
31
- });
32
- }
33
- }
34
- }
35
-
36
- }
37
- export class RequestFormStream extends FormStream {
38
- constructor(cbOrObject) {
39
- super();
40
-
41
- if (cbOrObject) {
42
- if (typeof cbOrObject === 'function') {
43
- cbOrObject(this);
44
- } else {
45
- Object.keys(cbOrObject).forEach(key => {
46
- const value = cbOrObject[key];
47
-
48
- if (value instanceof RequestFormFile) {
49
- if (typeof value.file === 'string') {
50
- var _value$options3;
51
-
52
- this.file(key, value.file, (_value$options3 = value.options) == null ? void 0 : _value$options3.name);
53
- } else if (Buffer.isBuffer(value.file)) {
54
- this.buffer(key, value.file, value.options.name, value.options.type);
55
- } else if (value.file instanceof Readable) {
56
- this.stream(key, value.file, value.options.name, value.options.type);
57
- }
58
- } else {
59
- this.field(key, value);
60
- }
61
- });
62
- }
63
- }
64
- }
65
-
66
- }
67
- export class RequestFormFile {
68
- constructor(file, options) {
69
- this.file = file;
70
- this.options = options;
71
-
72
- if (Buffer.isBuffer(file) || file instanceof Readable) {
73
- assert(options == null ? void 0 : options.name, 'options.name is required');
74
- }
75
- }
76
-
77
- }
78
- export class RequestService {
79
- static getGotOptions(options, responseType) {
80
- var _gotOptions$headers, _userAgent, _gotOptions$headers$_, _options$userAgent;
81
-
82
- const gotOptions = {
83
- url: options.url,
84
- responseType: responseType === 'stream' ? undefined : responseType,
85
- https: {
86
- rejectUnauthorized: false
87
- },
88
- isStream: responseType === 'stream'
89
- };
90
-
91
- if (options.headers) {
92
- gotOptions.headers = options.headers;
93
- }
94
-
95
- if (options.followRedirect != null) {
96
- gotOptions.followRedirect = options.followRedirect;
97
- }
98
-
99
- if (options.timeoutMs) {
100
- gotOptions.timeout = options.timeoutMs;
101
- }
102
-
103
- if (options.proxyUrl) {
104
- const proxyAgent = new ProxyAgent({
105
- getProxyForUrl: () => options.proxyUrl
106
- });
107
- gotOptions.agent = {
108
- http: proxyAgent,
109
- https: proxyAgent,
110
- http2: proxyAgent
111
- };
112
- }
113
-
114
- if (options.cookieJar) {
115
- gotOptions.cookieJar = options.cookieJar;
116
- } // 头处理
117
-
118
-
119
- gotOptions.headers = mapKeys(gotOptions.headers || {}, (v, k) => k.toLowerCase());
120
- (_gotOptions$headers$_ = (_gotOptions$headers = gotOptions.headers)[_userAgent = 'user-agent']) != null ? _gotOptions$headers$_ : _gotOptions$headers[_userAgent] = (_options$userAgent = options.userAgent) != null ? _options$userAgent : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36';
121
-
122
- if (options.autoReferer && gotOptions.headers['referer'] == null) {
123
- gotOptions.headers['referer'] = options.url;
124
- }
125
-
126
- return gotOptions;
127
- }
128
-
129
- static getRaw(options, responseType) {
130
- let url = options.url;
131
-
132
- if (options.data) {
133
- const _url = new URL(url);
134
-
135
- Object.keys(options.data).forEach(key => {
136
- _url.searchParams.set(key, options.data[key]);
137
- });
138
- url = _url.toString();
139
- }
140
-
141
- options.url = url;
142
- const res = got({
143
- method: 'GET',
144
- ...this.getGotOptions(options, responseType || 'buffer')
145
- });
146
-
147
- if (responseType === 'stream') {
148
- return res;
149
- }
150
-
151
- return res.then(res => ({
152
- status: res.statusCode,
153
- headers: res.headers,
154
- data: res.body
155
- }));
156
- }
157
-
158
- static postRaw(options, responseType) {
159
- const gotOptions = this.getGotOptions(options, responseType || 'buffer');
160
-
161
- if (responseType === 'stream' && options.data instanceof FormStream) {
162
- gotOptions.headers = options.data.headers(gotOptions.headers);
163
- }
164
-
165
- const res = got({
166
- method: 'POST',
167
- ...(options.data == null ? {
168
- body: ''
169
- } : options.data instanceof FormData ? {
170
- body: options.data
171
- } : options.data instanceof URLSearchParams ? {
172
- form: options.data
173
- } : options.data instanceof FormStream ? {} : {
174
- json: options.data
175
- }),
176
- ...gotOptions
177
- });
178
-
179
- if (responseType === 'stream' && options.data instanceof FormStream) {
180
- options.data.pipe(res);
181
- }
182
-
183
- if (responseType === 'stream') {
184
- return res;
185
- }
186
-
187
- return res.then(res => ({
188
- status: res.statusCode,
189
- headers: res.headers,
190
- data: res.body
191
- }));
192
- }
193
-
194
- static async getText(options) {
195
- return this.getRaw(options, 'text');
196
- }
197
-
198
- static async postText(options) {
199
- return this.postRaw(options, 'text');
200
- }
201
-
202
- static async get(options) {
203
- return this.getRaw(options, 'json');
204
- }
205
-
206
- static async post(options) {
207
- return this.postRaw(options, 'json');
208
- }
209
-
210
- static getStream(options) {
211
- return this.getRaw(options, 'stream');
212
- }
213
-
214
- static postStream(options) {
215
- return this.postRaw(options, 'stream');
216
- }
217
-
218
- static isTimeoutError(err) {
219
- return err instanceof got.TimeoutError;
220
- }
221
-
222
- constructor(options) {
223
- this.options = options;
1
+ import { XRequest } from '@jayfong/x-request';
2
+ export * from '@jayfong/x-request';
3
+ export class RequestService extends XRequest {
4
+ constructor(...args) {
5
+ super(...args);
224
6
  this.serviceName = 'request';
225
7
  }
226
8
 
227
- getRaw(options, responseType) {
228
- var _this$options;
229
-
230
- return RequestService.getRaw({ ...this.options,
231
- ...options,
232
- headers: { ...((_this$options = this.options) == null ? void 0 : _this$options.headers),
233
- ...options.headers
234
- }
235
- }, responseType);
236
- }
237
-
238
- postRaw(options, responseType) {
239
- var _this$options2;
240
-
241
- return RequestService.postRaw({ ...this.options,
242
- ...options,
243
- headers: { ...((_this$options2 = this.options) == null ? void 0 : _this$options2.headers),
244
- ...options.headers
245
- }
246
- }, responseType);
247
- }
248
-
249
- async getText(options) {
250
- return this.getRaw(options, 'text');
251
- }
252
-
253
- async postText(options) {
254
- return this.postRaw(options, 'text');
255
- }
256
-
257
- async get(options) {
258
- return this.getRaw(options, 'json');
259
- }
260
-
261
- async post(options) {
262
- return this.postRaw(options, 'json');
263
- }
264
-
265
- getStream(options) {
266
- return this.getRaw(options, 'stream');
267
- }
268
-
269
- postStream(options) {
270
- return this.postRaw(options, 'stream');
271
- }
272
-
273
- isTimeoutError(err) {
274
- return RequestService.isTimeoutError(err);
275
- }
276
-
277
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.12.7",
3
+ "version": "2.12.14",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -13,19 +13,10 @@
13
13
  "lib"
14
14
  ],
15
15
  "scripts": {
16
- "bootstrap": "tyn --frozen-lockfile",
17
16
  "build": "haoma compile",
18
17
  "build_test_pkg": "tyn build && rm -rf ./lib_test && mkdir -p ./lib_test && cp -r ./lib ./lib_test/lib && cp ./package.json ./lib_test/package.json && cd ./tests/app && tyn add file:../../lib_test",
19
- "dev": "rm -rf lib && tsc -w -p ./tsconfig.build.json",
20
- "release": "source proxy-use-trojan.sh && tyn test && standard-version -a && tyn build && npm publish && haoma run ./scripts/publish_client_helper_package.ts && git push --follow-tags origin master",
21
18
  "test": "tsc --noEmit -p ./tsconfig.build.json && jest \"$(pwd)/src/\"",
22
- "test_all": "tsc --noEmit -p ./tsconfig.build.json && jest",
23
- "updeps": "tnpx npm-check-updates --target minor --upgrade"
24
- },
25
- "husky": {
26
- "hooks": {
27
- "post-merge": "tyn bootstrap"
28
- }
19
+ "test_all": "tsc --noEmit -p ./tsconfig.build.json && jest"
29
20
  },
30
21
  "dependencies": {
31
22
  "@fastify/cors": "^8.3.0",
@@ -54,10 +45,7 @@
54
45
  "exit-hook": "^2.2.1",
55
46
  "fast-xml-parser": "^4.2.5",
56
47
  "fastify": "^4.19.2",
57
- "form-data": "^4.0.0",
58
- "formstream": "^1.2.0",
59
48
  "fs-extra": "^10.0.1",
60
- "get-port": "^7.0.0",
61
49
  "globby": "^11",
62
50
  "got": "^11.8.2",
63
51
  "http-errors": "^2.0.0",
@@ -71,17 +59,16 @@
71
59
  "nodemailer": "^6.7.3",
72
60
  "pino-pretty": "^10.0.1",
73
61
  "prisma": "^4.8.0",
74
- "proxy-agent": "^6.2.2",
75
62
  "select-run": "^1.1.2",
76
63
  "supports-color": "^8",
77
64
  "svg-captcha": "^1.4.0",
78
- "tough-cookie": "^4.1.3",
79
65
  "ts-morph": "^12.2.0",
80
66
  "utf-8-validate": "^5.0.9",
81
67
  "vscode-generate-index-standalone": "^1.7.1",
82
68
  "vtils": "^4.85.3",
83
69
  "yaml": "^2.3.1",
84
- "yargs": "^17.4.1"
70
+ "yargs": "^17.4.1",
71
+ "@jayfong/x-request": "^2.12.14"
85
72
  },
86
73
  "devDependencies": {
87
74
  "@types/debug": "^4.1.7",
@@ -90,20 +77,10 @@
90
77
  "@types/json-schema": "^7.0.11",
91
78
  "@types/lz-string": "^1.3.34",
92
79
  "axios": "^1.4.0",
93
- "eslint": "^7.32.0",
94
- "haoma": "^3.6.4",
95
- "husky": "^4.3.8",
96
80
  "ioredis-mock": "^8.7.0",
97
- "jest": "^27.5.1",
98
81
  "json-xml-parse": "^1.2.4",
99
- "lint-staged": "^10.5.4",
100
82
  "node-fetch": "^3.3.1",
101
- "npm-check-updates": "^12.5.9",
102
- "prettier": "^2.8.8",
103
- "proxy": "^2.1.1",
104
- "standard-version": "^9.3.2",
105
- "typescript": "^5.1.6",
106
- "typescript-snapshots-plugin": "^1.7.0"
83
+ "npm-check-updates": "^12.5.9"
107
84
  },
108
85
  "publishConfig": {
109
86
  "access": "public"
package/README.md DELETED
@@ -1,51 +0,0 @@
1
- # x-server
2
-
3
- X 服务端。
4
-
5
- ## 技术栈
6
-
7
- - [fastify v3](https://github.com/fastify/fastify)
8
- - [prisma v3](https://github.com/prisma/prisma)
9
-
10
- ## 特性
11
-
12
- - 通过 `cache` 支持 redis 缓存
13
- - 通过 `jwt` 支持用户认证
14
- - 通过 `captcha` 支持验证码
15
- - 通过 `defineHandler` 支持 POST、GET、POST、FILE、WS、XML 请求
16
- - 通过 `defineTask` 支持定时任务
17
-
18
- ## 命令
19
-
20
- ### xs dev
21
-
22
- 开始开发
23
-
24
- - `-i aaa -i bbb`: 额外需要生成的索引文件
25
- - `-npc xxx@bbbb`: npc 地址及密钥,格式:地址@密钥
26
-
27
- ### xs build
28
-
29
- 构建
30
-
31
- - `-e aaa -e bbb`: 不应该被打的包
32
-
33
- ### xs deploy
34
-
35
- 部署
36
-
37
- ### xs api
38
-
39
- 生成 API
40
-
41
- ### xs prisma
42
-
43
- prisma 代理,主要为了注入环境变量
44
-
45
- - `-p false`: 是否生产模式
46
-
47
- ### xs run
48
-
49
- 执行 package.json 里的脚本
50
-
51
- - `-p false`: 是否生产模式
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- exports.__esModule = true;
6
- exports.processXServerResponse = processXServerResponse;
7
-
8
- var _lzString = _interopRequireDefault(require("lz-string"));
9
-
10
- var _vtils = require("vtils");
11
-
12
- // _#
13
- const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
14
-
15
- function processXServerResponse(data) {
16
- // 处理混淆
17
- if (data && typeof data === 'object' && data[obfuscateKey] != null) {
18
- try {
19
- data = JSON.parse(_lzString.default.decompress(data[obfuscateKey]));
20
- } catch {}
21
- } // 处理数组打包
22
-
23
-
24
- data = _vtils.DataPacker.unpackIfNeeded(data);
25
- return data;
26
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- export declare function processXServerResponse<T>(data: any): T;
@@ -1,16 +0,0 @@
1
- import LZString from 'lz-string';
2
- import { DataPacker } from 'vtils'; // _#
3
-
4
- const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
5
- export function processXServerResponse(data) {
6
- // 处理混淆
7
- if (data && typeof data === 'object' && data[obfuscateKey] != null) {
8
- try {
9
- data = JSON.parse(LZString.decompress(data[obfuscateKey]));
10
- } catch {}
11
- } // 处理数组打包
12
-
13
-
14
- data = DataPacker.unpackIfNeeded(data);
15
- return data;
16
- }
@@ -1,49 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- declare module 'formstream' {
4
- import { Stream, Readable } from 'stream';
5
- class FormStream extends Stream {
6
- /**
7
- * Add a normal field to the form.
8
- *
9
- * @param name Name of field
10
- * @param value Value of field
11
- */
12
- field(name: string, value: string): this;
13
- /**
14
- * Add a local file to be uploaded to the form.
15
- *
16
- * @param name Name of file field
17
- * @param filepath Local path of the file to be uploaded
18
- * @param filename Name of the file (will be the base name of filepath if empty)
19
- * @param filesize Size of the file (will not generate Content-Length header if not specified)
20
- */
21
- file(name: string, filepath: string, filename?: string, filesize?: number): this;
22
- /**
23
- * Add a buffer as a file to upload.
24
- *
25
- * @param name Name of field
26
- * @param buffer The buffer to be uploaded
27
- * @param filename The file name that tells the remote server
28
- * @param contentType Content-Type (aka. MIME Type) of content (will be infered with filename if empty)
29
- */
30
- buffer(name: string, buffer: Buffer, filename: string, contentType?: string): this;
31
- /**
32
- * Add a readable stream as a file to upload. Event 'error' will be emitted if an error occured.
33
- *
34
- * @param name Name of field
35
- * @param stream A readable stream to be piped
36
- * @param filename The file name that tells the remote server
37
- * @param contentType Content-Type (aka. MIME Type) of content (will be infered with filename if empty)
38
- * @param size Size of the stream (will not generate Content-Length header if not specified)
39
- */
40
- stream(name: string, stream: Readable, filename: string, contentType?: string, size?: number): this;
41
- /**
42
- * Get headers for the request.
43
- *
44
- * @param additionalHeaders Additional headers
45
- */
46
- headers(additionalHeaders?: Record<string, any>): Record<string, any>;
47
- }
48
- export = FormStream;
49
- }
File without changes