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

Remove node-fetch #116

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
},
"homepage": "https://github.com/expo/expo-server-sdk-node#readme",
"dependencies": {
"node-fetch": "^2.6.0",
"promise-limit": "^2.7.0",
"promise-retry": "^2.0.1"
"promise-retry": "^2.0.1",
"undici": "^7.2.0"
},
"devDependencies": {
"@tsconfig/node-lts": "^22.0.0",
"@tsconfig/strictest": "^2.0.5",
"@types/node-fetch": "^2.6.11",
"@types/promise-retry": "^1.1.6",
"eslint": "^8.57.0",
"eslint-config-universe": "^14.0.0",
Expand Down
30 changes: 21 additions & 9 deletions src/ExpoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
* Application Services
* https://expo.dev
*/
import fetch, { Headers, Response as FetchResponse } from 'node-fetch';
import assert from 'node:assert';
import { Agent } from 'node:http';
import { gzipSync } from 'node:zlib';
import promiseLimit from 'promise-limit';
import promiseRetry from 'promise-retry';
import { fetch, Agent, Response } from 'undici';

import {
defaultConcurrentRequestLimit,
Expand Down Expand Up @@ -227,12 +226,25 @@
requestHeaders.set('Content-Type', 'application/json');
}

const response = await fetch(url, {
const fetchOptions: {
method: 'get' | 'post';
headers: Headers;
body?: string | Buffer;
dispatcher?: Agent;
} = {
method: options.httpMethod,
body: requestBody,
headers: requestHeaders,
agent: this.httpAgent,
});
};

if (requestBody) {
fetchOptions.body = requestBody;
}

if (this.httpAgent) {
fetchOptions.dispatcher = this.httpAgent;
}

const response = await fetch(url, fetchOptions);

Check failure on line 247 in src/ExpoClient.ts

View workflow job for this annotation

GitHub Actions / build (18)

Argument of type '{ method: "post" | "get"; headers: Headers; body?: string | Buffer<ArrayBufferLike>; dispatcher?: Agent; }' is not assignable to parameter of type 'RequestInit' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing a TS type check failure here


if (response.status !== 200) {
const apiError = await this.parseErrorResponseAsync(response);
Expand All @@ -257,7 +269,7 @@
return result.data;
}

private async parseErrorResponseAsync(response: FetchResponse): Promise<Error> {
private async parseErrorResponseAsync(response: Response): Promise<Error> {
const textBody = await response.text();
let result: ApiResult;
try {
Expand All @@ -275,7 +287,7 @@
return this.getErrorFromResult(response, result);
}

private async getTextResponseErrorAsync(response: FetchResponse, text: string): Promise<Error> {
private async getTextResponseErrorAsync(response: Response, text: string): Promise<Error> {
const apiError: ExtensibleError = new Error(
`Expo responded with an error with status code ${response.status}: ` + text,
);
Expand All @@ -288,7 +300,7 @@
* Returns an error for the first API error in the result, with an optional `others` field that
* contains any other errors.
*/
private getErrorFromResult(response: FetchResponse, result: ApiResult): Error {
private getErrorFromResult(response: Response, result: ApiResult): Error {
const noErrorsMessage = `Expected at least one error from Expo`;
assert(result.errors, noErrorsMessage);
const [errorData, ...otherErrorData] = result.errors;
Expand Down
Loading
Loading