@hyper-fetch/core 3.3.4 → 4.0.1

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 (51) hide show
  1. package/dist/browser/index.cjs.js +1 -1
  2. package/dist/browser/index.cjs.js.map +4 -4
  3. package/dist/browser/index.esm.js +1 -1
  4. package/dist/browser/index.esm.js.map +4 -4
  5. package/dist/index.cjs.js +1 -1
  6. package/dist/index.cjs.js.map +4 -4
  7. package/dist/index.d.ts +330 -180
  8. package/dist/index.esm.js +1 -1
  9. package/dist/index.esm.js.map +4 -4
  10. package/package.json +4 -2
  11. package/src/adapter/adapter.bindings.ts +124 -35
  12. package/src/adapter/adapter.browser.ts +29 -24
  13. package/src/adapter/adapter.server.ts +81 -81
  14. package/src/adapter/adapter.ts +1 -6
  15. package/src/adapter/adapter.types.ts +100 -12
  16. package/src/adapter/adapter.utils.ts +16 -23
  17. package/src/cache/cache.events.ts +9 -6
  18. package/src/cache/cache.ts +37 -30
  19. package/src/cache/cache.types.ts +32 -15
  20. package/src/cache/cache.utils.ts +7 -9
  21. package/src/client/client.constants.ts +6 -0
  22. package/src/client/client.ts +130 -59
  23. package/src/client/client.types.ts +11 -10
  24. package/src/client/client.utils.ts +20 -6
  25. package/src/dispatcher/dispatcher.ts +20 -26
  26. package/src/dispatcher/dispatcher.types.ts +4 -4
  27. package/src/dispatcher/dispatcher.utils.ts +2 -11
  28. package/src/effect/request.effect.ts +8 -5
  29. package/src/effect/request.effect.types.ts +14 -5
  30. package/src/index.ts +1 -0
  31. package/src/managers/logger/logger.manager.ts +8 -8
  32. package/src/managers/logger/logger.manager.types.ts +5 -8
  33. package/src/managers/logger/logger.manager.utils.ts +2 -2
  34. package/src/managers/request/request.manager.events.ts +7 -7
  35. package/src/managers/request/request.manager.types.ts +0 -1
  36. package/src/mocker/index.ts +2 -0
  37. package/src/mocker/mocker.ts +96 -0
  38. package/src/mocker/mocker.types.ts +26 -0
  39. package/src/request/request.ts +227 -224
  40. package/src/request/request.types.ts +75 -35
  41. package/src/request/request.utils.ts +61 -28
  42. package/src/types/client.types.ts +4 -0
  43. package/src/types/fetch.types.ts +16 -25
  44. package/src/types/http.types.ts +1 -0
  45. package/src/types/index.ts +1 -0
  46. package/{tsconfig.node.json → tsconfig.base.json} +3 -3
  47. package/tsconfig.json +3 -4
  48. package/dist/server/index.cjs.js +0 -2
  49. package/dist/server/index.cjs.js.map +0 -7
  50. package/dist/server/index.esm.js +0 -2
  51. package/dist/server/index.esm.js.map +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/core",
3
- "version": "3.3.4",
3
+ "version": "4.0.1",
4
4
  "private": false,
5
5
  "description": "Cache, Queue and Persist your requests no matter if you are online or offline!",
6
6
  "author": "Maciej Pyrc <m.pyrc@interia.pl>",
@@ -60,7 +60,9 @@
60
60
  "dependencies": {
61
61
  "events": "^3.3.0"
62
62
  },
63
- "devDependencies": {},
63
+ "devDependencies": {
64
+ "abortcontroller-polyfill": "^1.7.5"
65
+ },
64
66
  "lint-staged": {
65
67
  "*.{js,jsx,ts,tsx}": [
66
68
  "yarn jest --passWithNoTests"
@@ -1,15 +1,34 @@
1
- import { getErrorMessage, ResponseSuccessType, ResponseErrorType, ProgressDataType } from "adapter";
1
+ import {
2
+ getErrorMessage,
3
+ ResponseReturnSuccessType,
4
+ ResponseReturnErrorType,
5
+ ProgressDataType,
6
+ ExtractAdapterOptionsType,
7
+ ExtractAdapterStatusType,
8
+ ExtractAdapterExtraType,
9
+ AdapterType,
10
+ AdapterInstance,
11
+ ResponseReturnType,
12
+ } from "adapter";
2
13
  import { RequestInstance, getProgressData, AdapterProgressEventType } from "request";
3
- import { ExtractResponseType, ExtractErrorType } from "types";
14
+ import { ExtractResponseType, ExtractErrorType, ExtractPayloadType } from "types";
15
+ import { mocker } from "mocker";
4
16
 
5
- export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance, requestId: string) => {
6
- const { url, requestManager, loggerManager, headerMapper, payloadMapper } = cmd.client;
17
+ export const getAdapterBindings = async <T extends AdapterInstance = AdapterType>(
18
+ req: RequestInstance,
19
+ requestId: string,
20
+ systemErrorStatus: ExtractAdapterStatusType<T>,
21
+ systemErrorExtra: ExtractAdapterExtraType<T>,
22
+ ) => {
23
+ const { url, requestManager, loggerManager, headerMapper, payloadMapper } = req.client;
7
24
 
8
25
  const logger = loggerManager.init("Adapter");
9
26
 
27
+ let processingError = null;
28
+
10
29
  let requestStartTimestamp: null | number = null;
11
30
  let responseStartTimestamp: null | number = null;
12
- let request = cmd;
31
+ let request = req;
13
32
 
14
33
  // Progress
15
34
  let requestTotal = 1;
@@ -20,10 +39,18 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
20
39
  // Pre request modifications
21
40
  logger.debug(`Starting request middleware callbacks`);
22
41
 
23
- request = await request.client.__modifyRequest(cmd);
42
+ try {
43
+ request = await request.client.__modifyRequest(req);
44
+
45
+ if (request.auth) {
46
+ request = await request.client.__modifyAuth(req);
47
+ }
24
48
 
25
- if (request.auth) {
26
- request = await request.client.__modifyAuth(cmd);
49
+ if (request.requestMapper) {
50
+ request = await request.requestMapper(request, requestId);
51
+ }
52
+ } catch (err) {
53
+ processingError = err;
27
54
  }
28
55
 
29
56
  // Request Setup
@@ -32,8 +59,20 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
32
59
  const fullUrl = url + endpoint;
33
60
  const effects = client.effects.filter((effect) => request.effectKey === effect.getEffectKey());
34
61
  const headers = headerMapper(request);
35
- const payload = payloadMapper(data);
36
- const config: ConfigType = { ...request.requestOptions.options };
62
+ let payload = data;
63
+
64
+ try {
65
+ payload = payloadMapper(data);
66
+ if (request.dataMapper) {
67
+ payload = await request.dataMapper<ExtractPayloadType<RequestInstance>>(data);
68
+ }
69
+ } catch (err) {
70
+ processingError = err;
71
+ }
72
+
73
+ const config: ExtractAdapterOptionsType<T> = {
74
+ ...request.options,
75
+ } as ExtractAdapterOptionsType<T>;
37
76
 
38
77
  const getRequestStartTimestamp = () => {
39
78
  return requestStartTimestamp;
@@ -178,12 +217,19 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
178
217
 
179
218
  // Success
180
219
 
181
- const onSuccess = async <T extends RequestInstance>(
182
- responseData: unknown,
183
- status: number,
184
- resolve: (value: ResponseErrorType<ExtractErrorType<T>>) => void,
185
- ): Promise<ResponseSuccessType<ExtractResponseType<T>>> => {
186
- let response = [responseData, null, status] as ResponseSuccessType<ExtractResponseType<T>>;
220
+ const onSuccess = async (
221
+ responseData: any,
222
+ status: ExtractAdapterStatusType<T>,
223
+ extra: ExtractAdapterExtraType<T>,
224
+ resolve: (value: ResponseReturnErrorType<any, T>) => void,
225
+ ): Promise<ResponseReturnSuccessType<ExtractResponseType<T>, T>> => {
226
+ let response = {
227
+ data: responseData,
228
+ error: null,
229
+ success: true,
230
+ status,
231
+ extra,
232
+ };
187
233
  response = await request.client.__modifyResponse(response, request);
188
234
  response = await request.client.__modifySuccessResponse(response, request);
189
235
 
@@ -197,12 +243,19 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
197
243
 
198
244
  // Errors
199
245
 
200
- const onError = async <T extends RequestInstance>(
201
- error: Error | ExtractErrorType<T>,
202
- status: number,
203
- resolve: (value: ResponseErrorType<ExtractErrorType<T>>) => void,
204
- ): Promise<ResponseErrorType<ExtractErrorType<T>>> => {
205
- let responseData = [null, error, status] as ResponseErrorType<ExtractErrorType<T>>;
246
+ const onError = async (
247
+ error: any,
248
+ status: ExtractAdapterStatusType<T>,
249
+ extra: ExtractAdapterExtraType<T>,
250
+ resolve: (value: ResponseReturnErrorType<any, T>) => void,
251
+ ): Promise<ResponseReturnErrorType<any, T>> => {
252
+ let responseData = {
253
+ data: null,
254
+ status,
255
+ error,
256
+ success: false,
257
+ extra,
258
+ } as ResponseReturnErrorType<any, T>;
206
259
 
207
260
  responseData = await request.client.__modifyResponse(responseData, request);
208
261
  responseData = await request.client.__modifyErrorResponse(responseData, request);
@@ -215,25 +268,31 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
215
268
  return responseData;
216
269
  };
217
270
 
218
- const onAbortError = <T extends RequestInstance>(
219
- resolve: (value: ResponseErrorType<ExtractErrorType<T>>) => void,
271
+ const onAbortError = (
272
+ status: ExtractAdapterStatusType<T>,
273
+ extra: ExtractAdapterExtraType<T>,
274
+ resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void,
220
275
  ) => {
221
276
  const error = getErrorMessage("abort");
222
- return onError(error, 0, resolve);
277
+ return onError(error, status, extra, resolve);
223
278
  };
224
279
 
225
- const onTimeoutError = <T extends RequestInstance>(
226
- resolve: (value: ResponseErrorType<ExtractErrorType<T>>) => void,
280
+ const onTimeoutError = (
281
+ status: ExtractAdapterStatusType<T>,
282
+ extra: ExtractAdapterExtraType<T>,
283
+ resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void,
227
284
  ) => {
228
285
  const error = getErrorMessage("timeout");
229
- return onError(error, 0, resolve);
286
+ return onError(error, status, extra, resolve);
230
287
  };
231
288
 
232
- const onUnexpectedError = <T extends RequestInstance>(
233
- resolve: (value: ResponseErrorType<ExtractErrorType<T>>) => void,
289
+ const onUnexpectedError = (
290
+ status: ExtractAdapterStatusType<T>,
291
+ extra: ExtractAdapterExtraType<T>,
292
+ resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void,
234
293
  ) => {
235
294
  const error = getErrorMessage();
236
- return onError(error, 0, resolve);
295
+ return onError(error, status, extra, resolve);
237
296
  };
238
297
 
239
298
  // Abort
@@ -242,9 +301,11 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
242
301
  return requestManager.getAbortController(abortKey, requestId);
243
302
  };
244
303
 
245
- const createAbortListener = <T extends RequestInstance>(
304
+ const createAbortListener = (
305
+ status: ExtractAdapterStatusType<T>,
306
+ abortExtra: ExtractAdapterExtraType<T>,
246
307
  callback: () => void,
247
- resolve: (value: ResponseErrorType<ExtractErrorType<T>>) => void,
308
+ resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void,
248
309
  ) => {
249
310
  const controller = getAbortController();
250
311
  if (!controller) {
@@ -252,12 +313,12 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
252
313
  }
253
314
 
254
315
  const fn = () => {
255
- onAbortError(resolve);
316
+ onAbortError(status, abortExtra, resolve);
256
317
  callback();
257
318
  requestManager.events.emitAbort(abortKey, requestId, request);
258
319
  };
259
320
 
260
- // Instant abort when we stack many requests triggered at once and we receive aborted controller
321
+ // Instant abort when we stack many requests triggered at once, and we receive aborted controller
261
322
  if (controller.signal.aborted) {
262
323
  fn();
263
324
  }
@@ -268,8 +329,35 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
268
329
  return () => controller.signal.removeEventListener("abort", fn);
269
330
  };
270
331
 
332
+ const makeRequest = (
333
+ apiCall: (
334
+ resolve: (value: ResponseReturnType<any, any, T> | PromiseLike<ResponseReturnType<any, any, T>>) => void,
335
+ ) => void,
336
+ ): Promise<ResponseReturnType<any, any, T>> => {
337
+ if (processingError) {
338
+ return onError(processingError, systemErrorStatus, systemErrorExtra, () => null);
339
+ }
340
+ if (req.mock) {
341
+ return mocker(request, {
342
+ onError,
343
+ onResponseEnd,
344
+ onTimeoutError,
345
+ onRequestEnd,
346
+ createAbortListener,
347
+ onResponseProgress,
348
+ onRequestProgress,
349
+ onResponseStart,
350
+ onBeforeRequest,
351
+ onRequestStart,
352
+ onSuccess,
353
+ });
354
+ }
355
+ return new Promise(apiCall);
356
+ };
357
+
271
358
  return {
272
359
  fullUrl,
360
+ data,
273
361
  headers,
274
362
  payload,
275
363
  config,
@@ -289,5 +377,6 @@ export const getAdapterBindings = async <ConfigType = any>(cmd: RequestInstance,
289
377
  onTimeoutError,
290
378
  onUnexpectedError,
291
379
  onError,
380
+ makeRequest,
292
381
  };
293
382
  };
@@ -1,33 +1,37 @@
1
- import { getAdapterBindings, defaultTimeout, ResponseType, AdapterType } from "adapter";
2
- import { parseErrorResponse, parseResponse } from "./adapter.utils";
1
+ import { getAdapterBindings, AdapterType, getResponseHeaders, parseResponse, parseErrorResponse } from "adapter";
2
+ import { xhrExtra } from "client";
3
+ import { defaultTimeout } from "./adapter.constants";
3
4
 
4
5
  export const adapter: AdapterType = async (request, requestId) => {
5
6
  const {
7
+ makeRequest,
6
8
  fullUrl,
7
- headers,
8
- payload,
9
9
  config,
10
+ payload,
11
+ headers,
12
+ onError,
13
+ onResponseEnd,
14
+ onTimeoutError,
15
+ onRequestEnd,
10
16
  createAbortListener,
11
- onBeforeRequest,
12
- onRequestStart,
17
+ onResponseProgress,
13
18
  onRequestProgress,
14
- onRequestEnd,
15
19
  onResponseStart,
16
- onResponseProgress,
20
+ onBeforeRequest,
21
+ onRequestStart,
17
22
  onSuccess,
18
- onError,
19
- onResponseEnd,
20
- onTimeoutError,
21
- } = await getAdapterBindings(request, requestId);
23
+ } = await getAdapterBindings<AdapterType>(request, requestId, 0, {
24
+ headers: {},
25
+ });
22
26
 
23
- const { method } = request;
27
+ const { method = "GET" } = request;
24
28
 
25
- const xhr = new XMLHttpRequest();
26
- xhr.timeout = defaultTimeout;
29
+ return makeRequest((resolve) => {
30
+ const xhr = new XMLHttpRequest();
31
+ xhr.timeout = defaultTimeout;
27
32
 
28
- const abort = () => xhr.abort();
33
+ const abort = () => xhr.abort();
29
34
 
30
- return new Promise<ResponseType<unknown, unknown>>((resolve) => {
31
35
  // Inject xhr options
32
36
  Object.entries(config).forEach(([name, value]) => {
33
37
  xhr[name] = value;
@@ -37,10 +41,10 @@ export const adapter: AdapterType = async (request, requestId) => {
37
41
  xhr.open(method, fullUrl, true);
38
42
 
39
43
  // Set Headers
40
- Object.entries(headers).forEach(([name, value]) => xhr.setRequestHeader(name, value));
44
+ Object.entries(headers).forEach(([name, value]) => xhr.setRequestHeader(name, value as string));
41
45
 
42
46
  // Listen to abort signal
43
- const unmountListener = createAbortListener(abort, resolve);
47
+ const unmountListener = createAbortListener(0, xhrExtra, abort, resolve);
44
48
 
45
49
  // Request handlers
46
50
  xhr.upload.onprogress = onRequestProgress;
@@ -58,7 +62,7 @@ export const adapter: AdapterType = async (request, requestId) => {
58
62
  unmountListener();
59
63
  };
60
64
 
61
- xhr.ontimeout = () => onTimeoutError;
65
+ xhr.ontimeout = () => onTimeoutError(0, xhrExtra, resolve);
62
66
 
63
67
  // Data handler
64
68
  xhr.onreadystatechange = (e: Event) => {
@@ -67,15 +71,16 @@ export const adapter: AdapterType = async (request, requestId) => {
67
71
 
68
72
  if (event.target && event.target.readyState === finishedState) {
69
73
  const { status } = event.target;
70
- const isSuccess = String(status).startsWith("2") || String(status).startsWith("3");
74
+ const success = String(status).startsWith("2") || String(status).startsWith("3");
75
+ const responseHeaders = getResponseHeaders(xhr.getAllResponseHeaders());
71
76
 
72
- if (isSuccess) {
77
+ if (success) {
73
78
  const data = parseResponse(event.target.response);
74
- onSuccess(data, status, resolve);
79
+ onSuccess(data, status, { headers: responseHeaders }, resolve);
75
80
  } else {
76
81
  // delay to finish after onabort/ontimeout
77
82
  const data = parseErrorResponse(event.target.response);
78
- onError(data, status, resolve);
83
+ onError(data, status, { headers: responseHeaders }, resolve);
79
84
  }
80
85
  }
81
86
  };
@@ -1,106 +1,106 @@
1
1
  import http, { OutgoingHttpHeaders } from "http";
2
- import https from "https";
3
2
  import stream from "stream";
3
+ import https from "https";
4
4
 
5
- import { getAdapterBindings, defaultTimeout, ResponseType, AdapterType, AdapterOptionsType } from "adapter";
6
- import { parseErrorResponse, parseResponse, getUploadSize, getStreamPayload } from "./adapter.utils";
5
+ import { getAdapterBindings } from "./adapter.bindings";
6
+ import { AdapterType } from "./adapter.types";
7
+ import { defaultTimeout } from "./adapter.constants";
8
+ import { getStreamPayload, getUploadSize, parseErrorResponse, parseResponse } from "./adapter.utils";
9
+ import { HttpMethodsEnum } from "../constants/http.constants";
10
+ import { xhrExtra } from "client";
7
11
 
8
12
  export const adapter: AdapterType = async (request, requestId) => {
9
13
  const {
14
+ makeRequest,
10
15
  fullUrl,
16
+ config,
11
17
  headers,
12
18
  payload,
13
- config,
19
+ onError,
20
+ onResponseEnd,
21
+ onTimeoutError,
22
+ onRequestEnd,
14
23
  createAbortListener,
15
- onBeforeRequest,
16
- onRequestStart,
24
+ onResponseProgress,
17
25
  onRequestProgress,
18
- onRequestEnd,
19
26
  onResponseStart,
20
- onResponseProgress,
27
+ onBeforeRequest,
28
+ onRequestStart,
21
29
  onSuccess,
22
- onTimeoutError,
23
- onError,
24
- onResponseEnd,
25
- } = await getAdapterBindings<AdapterOptionsType>(request, requestId);
26
- const { method, client } = request;
27
- const httpClient = client.url.includes("https://") ? https : http;
30
+ } = await getAdapterBindings<AdapterType>(request, requestId, 0, xhrExtra);
28
31
 
29
- return new Promise<ResponseType<unknown, unknown>>((resolve) => {
30
- const execute = async () => {
31
- const options = {
32
- path: fullUrl,
33
- method,
34
- headers: headers as OutgoingHttpHeaders,
35
- timeout: defaultTimeout,
36
- };
37
-
38
- // Inject xhr options
39
- Object.entries(config).forEach(([name, value]) => {
40
- options[name] = value;
41
- });
32
+ const { method = HttpMethodsEnum.get, client } = request;
33
+ const httpClient = client.url.includes("https://") ? https : http;
34
+ const options = {
35
+ path: fullUrl,
36
+ method,
37
+ headers: headers as OutgoingHttpHeaders,
38
+ timeout: defaultTimeout,
39
+ };
40
+
41
+ Object.entries(config).forEach(([name, value]) => {
42
+ options[name] = value;
43
+ });
42
44
 
43
- let unmountListener = () => null;
44
- onBeforeRequest();
45
+ let unmountListener = () => null;
46
+ onBeforeRequest();
45
47
 
46
- const totalUploadBytes = payload ? Number(getUploadSize(payload)) : 0;
47
- let uploadedBytes = 0;
48
+ const totalUploadBytes = payload ? Number(getUploadSize(payload)) : 0;
49
+ let uploadedBytes = 0;
48
50
 
49
- const payloadChunks = await getStreamPayload(payload);
51
+ const payloadChunks = await getStreamPayload(payload);
50
52
 
51
- const httpRequest = httpClient.request(options, (response) => {
52
- response.setEncoding("utf8");
53
+ return makeRequest((resolve) => {
54
+ const httpRequest = httpClient.request(options, (response) => {
55
+ response.setEncoding("utf8");
56
+ unmountListener = createAbortListener(0, xhrExtra, response.destroy, resolve);
53
57
 
54
- let chunks = "";
55
- const totalDownloadBytes = Number(response.headers["content-length"]);
56
- let downloadedBytes = 0;
58
+ let chunks = "";
59
+ const totalDownloadBytes = Number(response.headers["content-length"]);
60
+ let downloadedBytes = 0;
57
61
 
58
- response.on("data", (chunk) => {
59
- if (!chunks) onResponseStart();
60
- downloadedBytes += chunk.length;
61
- chunks += chunk;
62
- onResponseProgress({ total: totalDownloadBytes, loaded: downloadedBytes });
63
- });
62
+ response.on("data", (chunk) => {
63
+ if (!chunks) onResponseStart();
64
+ downloadedBytes += chunk.length;
65
+ chunks += chunk;
66
+ onResponseProgress({ total: totalDownloadBytes, loaded: downloadedBytes });
67
+ });
64
68
 
65
- response.on("end", () => {
66
- const { statusCode } = response;
67
- const isSuccess = String(statusCode).startsWith("2") || String(statusCode).startsWith("3");
68
-
69
- if (isSuccess) {
70
- const data = parseResponse(chunks);
71
- onSuccess(data, statusCode, resolve);
72
- } else {
73
- // delay to finish after onabort/ontimeout
74
- const data = parseErrorResponse(chunks);
75
- onError(data, statusCode, resolve);
76
- }
77
-
78
- unmountListener();
79
- onResponseEnd();
80
- });
69
+ response.on("end", () => {
70
+ const { statusCode } = response;
71
+ const success = String(statusCode).startsWith("2") || String(statusCode).startsWith("3");
72
+
73
+ if (success) {
74
+ const data = parseResponse(chunks);
75
+ onSuccess(data, statusCode, { headers: response.headers as Record<string, string> }, resolve);
76
+ } else {
77
+ // delay to finish after onabort/ontimeout
78
+ const data = parseErrorResponse(chunks);
79
+ onError(data, statusCode, { headers: response.headers as Record<string, string> }, resolve);
80
+ }
81
+
82
+ unmountListener();
83
+ onResponseEnd();
81
84
  });
85
+ });
86
+
87
+ httpRequest.on("timeout", () => onTimeoutError(0, xhrExtra, resolve));
88
+ httpRequest.on("error", (error) => onError(error, 0, xhrExtra, resolve));
89
+
90
+ if (payloadChunks) {
91
+ const readableStream = stream.Readable.from(payloadChunks, { objectMode: false })
92
+ .on("data", (chunk) => {
93
+ if (!uploadedBytes) onRequestStart();
94
+ uploadedBytes += chunk.length;
95
+ onRequestProgress({ total: totalUploadBytes, loaded: uploadedBytes });
96
+ })
97
+ .on("end", () => {
98
+ onRequestEnd();
99
+ });
82
100
 
83
- unmountListener = createAbortListener(httpRequest.destroy, resolve);
84
-
85
- httpRequest.on("timeout", () => onTimeoutError(resolve));
86
- httpRequest.on("error", (error) => onError(error, 0, resolve));
87
-
88
- if (payloadChunks) {
89
- const readableStream = stream.Readable.from(payloadChunks, { objectMode: false })
90
- .on("data", (chunk) => {
91
- if (!uploadedBytes) onRequestStart();
92
- uploadedBytes += chunk.length;
93
- onRequestProgress({ total: totalUploadBytes, loaded: uploadedBytes });
94
- })
95
- .on("end", () => {
96
- onRequestEnd();
97
- });
98
-
99
- readableStream.pipe(httpRequest);
100
- } else {
101
- httpRequest.end();
102
- }
103
- };
104
- execute();
101
+ readableStream.pipe(httpRequest);
102
+ } else {
103
+ httpRequest.end();
104
+ }
105
105
  });
106
106
  };
@@ -7,10 +7,5 @@ export const adapter: AdapterType = async (request, requestId) => {
7
7
  if (typeof XMLHttpRequest !== "undefined") {
8
8
  return browser.adapter(request, requestId);
9
9
  }
10
- if (typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]") {
11
- return server.adapter(request, requestId);
12
- }
13
- return (() => {
14
- return [null, new Error("Cannot find the right environment for http adapter"), 0];
15
- }) as unknown as ReturnType<AdapterType>;
10
+ return server.adapter(request, requestId);
16
11
  };