Skip to content

Commit b553741

Browse files
committed
refactor: Use TS dom lib instead of @types/node-fetch
1 parent 8809bf3 commit b553741

5 files changed

+6
-32
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"@types/isomorphic-fetch": "^0.0.35",
2525
"@types/jest": "^26.0.9",
2626
"@types/node": "^14.0.27",
27-
"@types/node-fetch": "^2.5.7",
2827
"@typescript-eslint/eslint-plugin": "^3.9.0",
2928
"@typescript-eslint/parser": "^3.9.0",
3029
"@zerollup/ts-transform-paths": "^1.7.18",

src/HttpResponseError.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type {Response} from "node-fetch";
2-
31
import {CustomError} from "@mgtitimoli/utils-error";
42

53
import * as withHttpStatusCode from "./httpStatusCode";

src/httpRequest.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
import fetch from "isomorphic-fetch";
22

3-
import type {RequestInfo, RequestInit, Response} from "node-fetch";
4-
53
import HttpResponseError from "./HttpResponseError";
64

7-
type FetchOptionsMode = "cors" | "no-cors" | "same-origin" | "navigate";
8-
9-
type FetchOptions = RequestInit & {mode?: FetchOptionsMode};
10-
11-
type PostJsonOptions = Omit<FetchOptions, "body" | "method"> & {data?: unknown};
5+
type PostJsonOptions = Omit<RequestInit, "body" | "method"> & {data?: unknown};
126

13-
type GetJsonOptions = Omit<FetchOptions, "body" | "method">;
7+
type GetJsonOptions = Omit<RequestInit, "body" | "method">;
148

159
const responseToJson = (response: Response) => response.json();
1610

1711
const ensureResponseIsSucceeded = (response: Response) =>
1812
response.ok ? response : Promise.reject(new HttpResponseError(response));
1913

20-
const safeFetch = (url: RequestInfo, options?: FetchOptions) =>
14+
const safeFetch = (url: RequestInfo, options?: RequestInit) =>
2115
fetch(url, options).then(ensureResponseIsSucceeded);
2216

2317
const postJsonHeaders = {"Content-Type": "application/json"};

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"esModuleInterop": true,
77
"importHelpers": true,
88
"isolatedModules": true,
9-
"lib": ["es2020"],
9+
"lib": ["dom", "es2020"],
1010
"moduleResolution": "node",
1111
"noEmitOnError": true,
1212
"outDir": "./dist",
@@ -19,7 +19,7 @@
1919
"resolveJsonModule": true,
2020
"skipLibCheck": true,
2121
"strict": true,
22-
"target": "ES2020",
22+
"target": "es5",
2323
"typeRoots": ["./typings", "./node_modules/@types"],
2424
},
2525
"exclude": ["node_modules"],

yarn.lock

+1-18
Original file line numberDiff line numberDiff line change
@@ -881,14 +881,6 @@
881881
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
882882
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=
883883

884-
"@types/node-fetch@^2.5.7":
885-
version "2.5.7"
886-
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
887-
integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
888-
dependencies:
889-
"@types/node" "*"
890-
form-data "^3.0.0"
891-
892884
"@types/node@*":
893885
version "14.0.23"
894886
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.23.tgz#676fa0883450ed9da0bb24156213636290892806"
@@ -2041,7 +2033,7 @@ columnify@~1.5.4:
20412033
strip-ansi "^3.0.0"
20422034
wcwidth "^1.0.0"
20432035

2044-
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
2036+
combined-stream@^1.0.6, combined-stream@~1.0.6:
20452037
version "1.0.8"
20462038
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
20472039
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
@@ -3296,15 +3288,6 @@ forever-agent@~0.6.1:
32963288
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
32973289
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=
32983290

3299-
form-data@^3.0.0:
3300-
version "3.0.0"
3301-
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682"
3302-
integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==
3303-
dependencies:
3304-
asynckit "^0.4.0"
3305-
combined-stream "^1.0.8"
3306-
mime-types "^2.1.12"
3307-
33083291
form-data@~2.3.2:
33093292
version "2.3.3"
33103293
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"

0 commit comments

Comments
 (0)