Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop node-fetch and only use native fetch #908

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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

export * from './models.js';
export { getFormDataCls };
export const getFormDataCls = () => globalThis.FormData;
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved

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

this.middleware = configuration.middleware || [];
this.fetchApi = configuration.fetchApi || fetchApi;
this.fetchApi = configuration.fetchApi || globalThis.fetch;
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
this.parseError = configuration.parseError;
this.timeoutDuration =
typeof configuration.timeoutDuration === 'number' ? configuration.timeoutDuration : 10000;
Expand Down Expand Up @@ -86,7 +85,7 @@ export class BaseAPI {
})),
};

const Blob = await getBlobCls();
const Blob = globalThis.Blob;
const init: RequestInit = {
...overriddenInit,
body:
Expand Down Expand Up @@ -175,7 +174,7 @@ export class BaseAPI {
}

async function isFormData(value: unknown): Promise<boolean> {
const FormData = await getFormDataCls();
const FormData = globalThis.FormData;
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
return typeof FormData !== 'undefined' && value instanceof FormData;
}

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
7 changes: 3 additions & 4 deletions test/management/jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from '../../src/index.js';
import { extractParts } from '../utils/index.js';
import { fileURLToPath } from 'url';
import { getBlobCls } from '../../src/lib/fetch.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -176,7 +175,7 @@ describe('JobsManager', () => {
let request: nock.Scope;

beforeEach(async () => {
const Blob = await getBlobCls();
const Blob = globalThis.Blob;
data = {
users: new Blob([fs.readFileSync(usersFilePath)], { type: 'application/json' }),
connection_id: 'con_test',
Expand Down Expand Up @@ -387,7 +386,7 @@ describe('JobsManager', () => {
let data: PostUsersImportsData;

beforeEach(async () => {
const Blob = await getBlobCls();
const Blob = globalThis.Blob;
data = {
users: new Blob([fs.readFileSync(usersFilePath)], { type: 'application/json' }),
connection_id: 'con_test',
Expand Down Expand Up @@ -450,7 +449,7 @@ describe('JobsManager', () => {
})
.reply(200, {});

const Blob = await getBlobCls();
const Blob = globalThis.Blob;
await jobs
.importUsers({
...data,
Expand Down
Loading