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

Upgrade devDependencies and CI Actions #61

Merged
merged 2 commits into from
Mar 20, 2024
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [18, 20]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache Node.js modules
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.OS }}-${{ matrix.node-version}}-node_modules-${{ hashFiles('yarn.lock') }}
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"expo",
"push-notifications"
],
"author": "support@expo.io",
"author": "support@expo.dev",
"license": "MIT",
"bugs": {
"url": "https://github.com/expo/expo-server-sdk-node/issues"
Expand All @@ -44,15 +44,15 @@
"promise-retry": "^2.0.1"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node-fetch": "^2.5.12",
"@types/promise-retry": "^1.1.3",
"eslint": "^7.32.0",
"eslint-config-universe": "^7.0.1",
"@types/jest": "^29.5.12",
"@types/node-fetch": "^2.6.11",
"@types/promise-retry": "^1.1.6",
"eslint": "^8.57.0",
"eslint-config-universe": "^12.0.0",
"fetch-mock": "^9.11.0",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"ts-jest": "~27.0.5",
"typescript": "^4.3.5"
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "~29.1.2",
"typescript": "^5.4.2"
}
}
22 changes: 11 additions & 11 deletions src/ExpoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* expo-server-sdk
*
* Use this if you are running Node on your server backend when you are working with Expo
* https://expo.io
* Application Services
* https://expo.dev
*/
import assert from 'assert';
import { Agent } from 'http';
Expand Down Expand Up @@ -47,7 +48,7 @@ export class Expo {
this.limitConcurrentRequests = promiseLimit(
options.maxConcurrentRequests != null
? options.maxConcurrentRequests
: DEFAULT_CONCURRENT_REQUEST_LIMIT
: DEFAULT_CONCURRENT_REQUEST_LIMIT,
);
this.accessToken = options.accessToken;
this.useFcmV1 = options.useFcmV1;
Expand Down Expand Up @@ -77,10 +78,9 @@ export class Expo {
* sized chunks.
*/
async sendPushNotificationsAsync(messages: ExpoPushMessage[]): Promise<ExpoPushTicket[]> {
// @ts-expect-error We don't yet have type declarations for URL
const url = new URL(`${BASE_API_URL}/push/send`);
if (typeof this.useFcmV1 === 'boolean') {
url.searchParams.append('useFcmV1', this.useFcmV1);
url.searchParams.append('useFcmV1', String(this.useFcmV1));
}
const actualMessagesCount = Expo._getActualMessageCount(messages);
const data = await this.limitConcurrentRequests(async () => {
Expand All @@ -106,15 +106,15 @@ export class Expo {
retries: 2,
factor: 2,
minTimeout: requestRetryMinTimeout,
}
},
);
});

if (!Array.isArray(data) || data.length !== actualMessagesCount) {
const apiError: ExtensibleError = new Error(
`Expected Expo to respond with ${actualMessagesCount} ${
actualMessagesCount === 1 ? 'ticket' : 'tickets'
} but got ${data.length}`
} but got ${data.length}`,
);
apiError.data = data;
throw apiError;
Expand All @@ -124,7 +124,7 @@ export class Expo {
}

async getPushNotificationReceiptsAsync(
receiptIds: ExpoPushReceiptId[]
receiptIds: ExpoPushReceiptId[],
): Promise<{ [id: string]: ExpoPushReceipt }> {
const data = await this.requestAsync(`${BASE_API_URL}/push/getReceipts`, {
httpMethod: 'post',
Expand All @@ -136,7 +136,7 @@ export class Expo {

if (!data || typeof data !== 'object' || Array.isArray(data)) {
const apiError: ExtensibleError = new Error(
`Expected Expo to respond with a map from receipt IDs to receipts but received data of another type`
`Expected Expo to respond with a map from receipt IDs to receipts but received data of another type`,
);
apiError.data = data;
throw apiError;
Expand Down Expand Up @@ -256,7 +256,7 @@ export class Expo {
let result: ApiResult;
try {
result = JSON.parse(textBody);
} catch (e) {
} catch {
const apiError = await this.getTextResponseErrorAsync(response, textBody);
throw apiError;
}
Expand All @@ -274,7 +274,7 @@ export class Expo {
let result: ApiResult;
try {
result = JSON.parse(textBody);
} catch (e) {
} catch {
return await this.getTextResponseErrorAsync(response, textBody);
}

Expand All @@ -289,7 +289,7 @@ export class Expo {

private async getTextResponseErrorAsync(response: FetchResponse, text: string): Promise<Error> {
const apiError: ExtensibleError = new Error(
`Expo responded with an error with status code ${response.status}: ` + text
`Expo responded with an error with status code ${response.status}: ` + text,
);
apiError.statusCode = response.status;
apiError.errorText = text;
Expand Down
30 changes: 15 additions & 15 deletions src/__tests__/ExpoClient-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ describe('sending push notification messages', () => {
const client = new ExpoClient({ useFcmV1: true });
await client.sendPushNotificationsAsync([{ to: 'a' }]);
expect((fetch as any).called('https://exp.host/--/api/v2/push/send?useFcmV1=true')).toBe(
true
true,
);
});

test('sends requests to the Expo API server with useFcmV1=false', async () => {
const client = new ExpoClient({ useFcmV1: false });
await client.sendPushNotificationsAsync([{ to: 'a' }]);
expect((fetch as any).called('https://exp.host/--/api/v2/push/send?useFcmV1=false')).toBe(
true
true,
);
});
});
Expand Down Expand Up @@ -103,11 +103,11 @@ describe('sending push notification messages', () => {

const client = new ExpoClient();
await expect(client.sendPushNotificationsAsync([{ to: 'a' }])).rejects.toThrowError(
`Expected Expo to respond with 1 ticket but got 2`
`Expected Expo to respond with 1 ticket but got 2`,
);

await expect(
client.sendPushNotificationsAsync([{ to: 'a' }, { to: 'b' }, { to: 'c' }])
client.sendPushNotificationsAsync([{ to: 'a' }, { to: 'b' }, { to: 'c' }]),
).rejects.toThrowError(`Expected Expo to respond with 3 tickets but got 2`);
});

Expand All @@ -131,7 +131,7 @@ describe('sending push notification messages', () => {

const client = new ExpoClient();
await expect(client.sendPushNotificationsAsync([])).rejects.toThrowError(
`Expo responded with an error`
`Expo responded with an error`,
);
});

Expand All @@ -157,7 +157,7 @@ describe('sending push notification messages', () => {

const client = new ExpoClient();
await expect(client.sendPushNotificationsAsync([])).rejects.toThrowError(
`Expo responded with an error`
`Expo responded with an error`,
);
});

Expand All @@ -169,7 +169,7 @@ describe('sending push notification messages', () => {

const client = new ExpoClient();
await expect(client.sendPushNotificationsAsync([])).rejects.toThrowError(
`Expo responded with an error`
`Expo responded with an error`,
);
});

Expand Down Expand Up @@ -214,7 +214,7 @@ describe('sending push notification messages', () => {
errors: [{ code: 'RATE_LIMIT_ERROR', message: `Rate limit exceeded` }],
},
},
{ repeat: 3 }
{ repeat: 3 },
);

const client = new ExpoClient();
Expand All @@ -241,17 +241,17 @@ describe('sending push notification messages', () => {
errors: [{ code: 'RATE_LIMIT_ERROR', message: `Rate limit exceeded` }],
},
},
{ repeat: 2 }
{ repeat: 2 },
)
.mock(
'https://exp.host/--/api/v2/push/send',
{ data: mockTickets },
{ overwriteRoutes: false }
{ overwriteRoutes: false },
);

const client = new ExpoClient();
await expect(client.sendPushNotificationsAsync([{ to: 'a' }, { to: 'b' }])).resolves.toEqual(
mockTickets
mockTickets,
);

expect((fetch as any).done()).toBeTruthy();
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('retrieving push notification receipts', () => {

const client = new ExpoClient();
const rejection = expect(
client.getPushNotificationReceiptsAsync(['XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'])
client.getPushNotificationReceiptsAsync(['XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX']),
).rejects;
await rejection.toThrowError(`Expected Expo to respond with a map`);
await rejection.toMatchObject({ data: mockReceipts });
Expand Down Expand Up @@ -457,12 +457,12 @@ test('can detect an Expo push token', () => {
// FCM
expect(
ExpoClient.isExpoPushToken(
'dOKpuo4qbsM:APA91bHkSmF84ROx7Y-2eMGxc0lmpQeN33ZwDMG763dkjd8yjKK-rhPtiR1OoIWNG5ZshlL8oyxsTnQ5XtahyBNS9mJAvfeE6aHzv_mOF_Ve4vL2po4clMIYYV2-Iea_sZVJF7xFLXih4Y0y88JNYULxFfz-XXXXX'
)
'dOKpuo4qbsM:APA91bHkSmF84ROx7Y-2eMGxc0lmpQeN33ZwDMG763dkjd8yjKK-rhPtiR1OoIWNG5ZshlL8oyxsTnQ5XtahyBNS9mJAvfeE6aHzv_mOF_Ve4vL2po4clMIYYV2-Iea_sZVJF7xFLXih4Y0y88JNYULxFfz-XXXXX',
),
).toBe(false);
// APNs
expect(
ExpoClient.isExpoPushToken('5fa729c6e535eb568g18fdabd35785fc60f41c161d9d7cf4b0bbb0d92437fda0')
ExpoClient.isExpoPushToken('5fa729c6e535eb568g18fdabd35785fc60f41c161d9d7cf4b0bbb0d92437fda0'),
).toBe(false);
});

Expand Down
Loading
Loading