@hyper-fetch/core 3.0.0 → 3.1.0

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.
@@ -23,7 +23,7 @@ export declare class AppManager {
23
23
  onOnline: (callback: () => void) => VoidFunction;
24
24
  onOffline: (callback: () => void) => VoidFunction;
25
25
  };
26
- isNodeJs: boolean;
26
+ isBrowser: boolean;
27
27
  isOnline: boolean;
28
28
  isFocused: boolean;
29
29
  constructor(options?: AppManagerOptionsType);
@@ -10,7 +10,7 @@ import { HttpMethodsType, NegativeTypes } from "types";
10
10
  * :::
11
11
  *
12
12
  * @attention
13
- * The most important thing about the request is that it keeps data in the format that can be dumped. This is necessary for the persistance and different dispatcher storage types.
13
+ * The most important thing about the request is that it keeps data in the format that can be dumped. This is necessary for the persistence and different dispatcher storage types.
14
14
  * This class doesn't have any callback methods by design and communicate with dispatcher and cache by events.
15
15
  */
16
16
  export declare class Request<Response, Payload, QueryParams extends QueryParamsType | string, GlobalError, // Global Error Type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/core",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
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>",
@@ -21,7 +21,7 @@
21
21
  "lint": "eslint . --ext .js,.jsx,.tsx,.ts --fix",
22
22
  "format": "prettier --write .",
23
23
  "typecheck": "tsc --noEmit --emitDeclarationOnly false",
24
- "precommit": "yarn lint-staged",
24
+ "tests": "yarn lint-staged",
25
25
  "release": "yarn semantic-release --extends ./release.config.js -t 'hyper-fetch-v${version}'"
26
26
  },
27
27
  "publishConfig": {
@@ -1,10 +1,15 @@
1
- import http from "http";
2
- import stream from "stream";
3
-
4
1
  import { getAdapterBindings, defaultTimeout, ResponseType, AdapterType, AdapterOptionsType } from "adapter";
5
2
  import { parseErrorResponse, parseResponse, getUploadSize, getStreamPayload } from "./adapter.utils";
6
3
 
7
4
  export const serverAdapter: AdapterType = async (request, requestId) => {
5
+ /**
6
+ * Prevent issues related to the missing Node.js polyfills
7
+ */
8
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
9
+ const http = require("http");
10
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
11
+ const stream = require("stream");
12
+
8
13
  const {
9
14
  fullUrl,
10
15
  headers,
@@ -22,15 +27,14 @@ export const serverAdapter: AdapterType = async (request, requestId) => {
22
27
  onError,
23
28
  onResponseEnd,
24
29
  } = await getAdapterBindings<AdapterOptionsType>(request, requestId);
25
-
26
30
  const { method } = request;
27
31
 
28
32
  return new Promise<ResponseType<unknown, unknown>>((resolve) => {
29
33
  const execute = async () => {
30
- const options: http.RequestOptions = {
34
+ const options = {
31
35
  path: fullUrl,
32
36
  method,
33
- headers: headers as http.RequestOptions["headers"],
37
+ headers,
34
38
  timeout: defaultTimeout,
35
39
  };
36
40
 
@@ -1,7 +1,7 @@
1
1
  import { browserAdapter, serverAdapter, AdapterType } from "adapter";
2
2
 
3
3
  export const adapter: AdapterType = async (request, requestId) => {
4
- if (request.client.appManager.isNodeJs || !window?.XMLHttpRequest) {
4
+ if (!window?.XMLHttpRequest) {
5
5
  return serverAdapter(request, requestId);
6
6
  }
7
7
  return browserAdapter(request, requestId);
@@ -15,7 +15,7 @@ export class AppManager {
15
15
  emitter = new EventEmitter();
16
16
  events = getAppManagerEvents(this.emitter);
17
17
 
18
- isNodeJs: boolean;
18
+ isBrowser: boolean;
19
19
  isOnline: boolean;
20
20
  isFocused: boolean;
21
21
 
@@ -33,7 +33,7 @@ export class AppManager {
33
33
  focusEvent(this.setFocused);
34
34
  onlineEvent(this.setOnline);
35
35
 
36
- this.isNodeJs = !hasDocument();
36
+ this.isBrowser = hasDocument();
37
37
  }
38
38
 
39
39
  private setInitialFocus = async (initValue: Exclude<AppManagerOptionsType["initiallyFocused"], undefined>) => {
@@ -5,6 +5,7 @@ export const hasWindow = () => {
5
5
  return false;
6
6
  }
7
7
  };
8
+
8
9
  export const hasDocument = () => {
9
10
  try {
10
11
  return Boolean(hasWindow() && window.document && window.document.addEventListener);
@@ -27,7 +27,7 @@ import { HttpMethodsEnum } from "constants/http.constants";
27
27
  * :::
28
28
  *
29
29
  * @attention
30
- * The most important thing about the request is that it keeps data in the format that can be dumped. This is necessary for the persistance and different dispatcher storage types.
30
+ * The most important thing about the request is that it keeps data in the format that can be dumped. This is necessary for the persistence and different dispatcher storage types.
31
31
  * This class doesn't have any callback methods by design and communicate with dispatcher and cache by events.
32
32
  */
33
33
  export class Request<