Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
7 changes: 3 additions & 4 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 All @@ -64,5 +63,5 @@
"ts-jest": "~29.2.5",
"typescript": "^5.4.2"
},
"packageManager": "yarn@4.6.0"
"packageManager": "yarn@4.5.3"
}
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.

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