@jayfong/x-server 2.12.3 → 2.12.5

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.
@@ -87,6 +87,8 @@ class RequestService {
87
87
  gotOptions.cookieJar = options.cookieJar;
88
88
  }
89
89
 
90
+ gotOptions.headers = gotOptions.headers || {};
91
+ gotOptions.headers['User-Agent'] = 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';
90
92
  return gotOptions;
91
93
  }
92
94
 
@@ -180,15 +182,29 @@ class RequestService {
180
182
  return this.postRaw(options, 'stream');
181
183
  }
182
184
 
185
+ static isTimeoutError(err) {
186
+ return err instanceof _got.default.TimeoutError;
187
+ }
188
+
183
189
  getRaw(options, responseType) {
190
+ var _this$options;
191
+
184
192
  return RequestService.getRaw({ ...this.options,
185
- ...options
193
+ ...options,
194
+ headers: { ...((_this$options = this.options) == null ? void 0 : _this$options.headers),
195
+ ...options.headers
196
+ }
186
197
  }, responseType);
187
198
  }
188
199
 
189
200
  postRaw(options, responseType) {
201
+ var _this$options2;
202
+
190
203
  return RequestService.postRaw({ ...this.options,
191
- ...options
204
+ ...options,
205
+ headers: { ...((_this$options2 = this.options) == null ? void 0 : _this$options2.headers),
206
+ ...options.headers
207
+ }
192
208
  }, responseType);
193
209
  }
194
210
 
@@ -216,6 +232,10 @@ class RequestService {
216
232
  return this.postRaw(options, 'stream');
217
233
  }
218
234
 
235
+ isTimeoutError(err) {
236
+ return RequestService.isTimeoutError(err);
237
+ }
238
+
219
239
  }
220
240
 
221
241
  exports.RequestService = RequestService;
@@ -17,6 +17,10 @@ export interface RequestServiceOptions {
17
17
  */
18
18
  encoding?: BufferEncoding;
19
19
  cookieJar?: CookieJar;
20
+ /**
21
+ * @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"
22
+ */
23
+ userAgent?: string;
20
24
  }
21
25
  export interface RequestServiceResponse<T> {
22
26
  status: number;
@@ -68,6 +72,7 @@ export declare class RequestService implements BaseService {
68
72
  static post<T>(options: RequestServicePostOptions): Promise<RequestServiceResponse<T>>;
69
73
  static getStream(options: RequestServiceGetOptions): Request;
70
74
  static postStream(options: RequestServicePostStreamOptions): Request;
75
+ static isTimeoutError(err: any): boolean;
71
76
  getRaw(options: RequestServiceGetStreamOptions): Promise<RequestServiceResponse<Buffer>>;
72
77
  getRaw(options: RequestServiceGetStreamOptions, responseType: 'buffer'): Promise<RequestServiceResponse<Buffer>>;
73
78
  getRaw(options: RequestServiceGetStreamOptions, responseType: 'text'): Promise<RequestServiceResponse<string>>;
@@ -84,6 +89,7 @@ export declare class RequestService implements BaseService {
84
89
  post<T>(options: RequestServicePostOptions): Promise<RequestServiceResponse<T>>;
85
90
  getStream(options: RequestServiceGetOptions): Request;
86
91
  postStream(options: RequestServicePostStreamOptions): Request;
92
+ isTimeoutError(err: any): boolean;
87
93
  }
88
94
  declare module '../x' {
89
95
  interface X {
@@ -67,6 +67,8 @@ export class RequestService {
67
67
  gotOptions.cookieJar = options.cookieJar;
68
68
  }
69
69
 
70
+ gotOptions.headers = gotOptions.headers || {};
71
+ gotOptions.headers['User-Agent'] = 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';
70
72
  return gotOptions;
71
73
  }
72
74
 
@@ -160,15 +162,29 @@ export class RequestService {
160
162
  return this.postRaw(options, 'stream');
161
163
  }
162
164
 
165
+ static isTimeoutError(err) {
166
+ return err instanceof got.TimeoutError;
167
+ }
168
+
163
169
  getRaw(options, responseType) {
170
+ var _this$options;
171
+
164
172
  return RequestService.getRaw({ ...this.options,
165
- ...options
173
+ ...options,
174
+ headers: { ...((_this$options = this.options) == null ? void 0 : _this$options.headers),
175
+ ...options.headers
176
+ }
166
177
  }, responseType);
167
178
  }
168
179
 
169
180
  postRaw(options, responseType) {
181
+ var _this$options2;
182
+
170
183
  return RequestService.postRaw({ ...this.options,
171
- ...options
184
+ ...options,
185
+ headers: { ...((_this$options2 = this.options) == null ? void 0 : _this$options2.headers),
186
+ ...options.headers
187
+ }
172
188
  }, responseType);
173
189
  }
174
190
 
@@ -196,4 +212,8 @@ export class RequestService {
196
212
  return this.postRaw(options, 'stream');
197
213
  }
198
214
 
215
+ isTimeoutError(err) {
216
+ return RequestService.isTimeoutError(err);
217
+ }
218
+
199
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.12.3",
3
+ "version": "2.12.5",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",