Skip to content

Commit

Permalink
Drop node-fetch and only use native fetch (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck authored Aug 16, 2023
1 parent 691fc73 commit 5c387f0
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 147 deletions.
173 changes: 68 additions & 105 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"homepage": "https://github.com/auth0/node-auth0",
"dependencies": {
"jose": "^4.13.2",
"node-fetch": "^3.3.1",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand All @@ -72,6 +71,7 @@
"husky": "^3.0.1",
"jest": "^29.5.0",
"nock": "^13.2.7",
"node-fetch": "^3.3.1",
"prettier": "^2.8.7",
"pretty-quick": "^1.11.1",
"ts-jest": "^29.1.0",
Expand Down
20 changes: 0 additions & 20 deletions src/lib/fetch.ts

This file was deleted.

12 changes: 2 additions & 10 deletions src/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {
Middleware,
FetchAPI,
} from './models.js';
import { fetch as fetchApi, getFormDataCls, getBlobCls } from './fetch.js';

export * from './models.js';
export { getFormDataCls };

/**
* @private
Expand All @@ -33,7 +31,7 @@ export class BaseAPI {
}

this.middleware = configuration.middleware || [];
this.fetchApi = configuration.fetchApi || fetchApi;
this.fetchApi = configuration.fetchApi || fetch;
this.parseError = configuration.parseError;
this.timeoutDuration =
typeof configuration.timeoutDuration === 'number' ? configuration.timeoutDuration : 10000;
Expand Down Expand Up @@ -86,11 +84,10 @@ export class BaseAPI {
})),
};

const Blob = await getBlobCls();
const init: RequestInit = {
...overriddenInit,
body:
(await isFormData(overriddenInit.body)) ||
overriddenInit.body instanceof FormData ||
overriddenInit.body instanceof URLSearchParams ||
overriddenInit.body instanceof Blob
? overriddenInit.body
Expand Down Expand Up @@ -174,11 +171,6 @@ export class BaseAPI {
};
}

async function isFormData(value: unknown): Promise<boolean> {
const FormData = await getFormDataCls();
return typeof FormData !== 'undefined' && value instanceof FormData;
}

/**
* @private
*/
Expand Down
2 changes: 1 addition & 1 deletion src/management/__generated/managers/jobs-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class JobsManager extends BaseAPI {
bodyParameters: PostUsersImportsData,
initOverrides?: InitOverride
): Promise<ApiResponse<Job>> {
const formParams = new (await runtime.getFormDataCls())();
const formParams = new FormData();

if (bodyParameters.users !== undefined) {
formParams.append('users', await runtime.parseFormParam(bodyParameters.users));
Expand Down
5 changes: 2 additions & 3 deletions test/lib/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '../../src/index.js';
import { InitOverrideFunction, RequestOpts } from '../../src/lib/models.js';
import { BaseAPI, applyQueryParams } from '../../src/lib/runtime.js';
import { Response as NodeResponse } from 'node-fetch';

import * as utils from '../../src/utils.js';
import { base64url } from 'jose';
Expand Down Expand Up @@ -296,7 +295,7 @@ describe('Runtime', () => {
middleware: [
{
onError() {
return new NodeResponse(undefined, { status: 418 }) as Response;
return new Response(undefined, { status: 418 }) as Response;
},
},
],
Expand All @@ -320,7 +319,7 @@ describe('Runtime', () => {
middleware: [
{
post() {
return new NodeResponse(JSON.stringify({ bar: 'foo' }), {
return new Response(JSON.stringify({ bar: 'foo' }), {
status: 200,
}) as Response;
},
Expand Down
Loading

0 comments on commit 5c387f0

Please sign in to comment.