remove node-fetch as runtime dependency

This commit is contained in:
mrjvs
2023-09-27 19:10:32 +02:00
parent de63979e4d
commit 9e2bfedb79
4 changed files with 29 additions and 9 deletions

View File

@@ -61,12 +61,12 @@
"vite": "^4.0.0",
"vite-plugin-dts": "^3.5.3",
"vite-plugin-eslint": "^1.8.1",
"vitest": "^0.32.2"
"vitest": "^0.32.2",
"node-fetch": "^3.3.2"
},
"dependencies": {
"cheerio": "^1.0.0-rc.12",
"crypto-js": "^4.1.1",
"form-data": "^4.0.0",
"node-fetch": "^3.3.2"
"form-data": "^4.0.0"
}
}

22
src/fetchers/fetch.ts Normal file
View File

@@ -0,0 +1,22 @@
/**
* This file is a very relaxed definition of the fetch api
* Only containing what we need for it to function.
*/
export type FetchOps = {
headers: Record<string, string>;
method: string;
body: any;
};
export type FetchHeaders = {
get(key: string): string | undefined;
};
export type FetchReply = {
text(): Promise<string>;
json(): Promise<any>;
headers: FetchHeaders;
};
export type FetchType = (url: string, ops?: FetchOps) => Promise<FetchReply>;

View File

@@ -1,6 +1,5 @@
import fetch from 'node-fetch';
import { makeFullUrl } from '@/fetchers/common';
import { FetchType } from '@/fetchers/fetch';
import { makeStandardFetcher } from '@/fetchers/standardFetch';
import { Fetcher } from '@/fetchers/types';
@@ -10,7 +9,7 @@ const headerMap: Record<string, string> = {
origin: 'X-Origin',
};
export function makeSimpleProxyFetcher(proxyUrl: string, f: typeof fetch): Fetcher {
export function makeSimpleProxyFetcher(proxyUrl: string, f: FetchType): Fetcher {
const fetcher = makeStandardFetcher(f);
const proxiedFetch: Fetcher = async (url, ops) => {
const fullUrl = makeFullUrl(url, ops);

View File

@@ -1,10 +1,9 @@
import fetch from 'node-fetch';
import { serializeBody } from '@/fetchers/body';
import { makeFullUrl } from '@/fetchers/common';
import { FetchType } from '@/fetchers/fetch';
import { Fetcher } from '@/fetchers/types';
export function makeStandardFetcher(f: typeof fetch): Fetcher {
export function makeStandardFetcher(f: FetchType): Fetcher {
const normalFetch: Fetcher = async (url, ops) => {
const fullUrl = makeFullUrl(url, ops);
const seralizedBody = serializeBody(ops.body);