Skip to content

Commit 55761dd

Browse files
authored
feat!: remove useFcmV1 option (#261)
* feat!: remove useFcmV1 option * simplify requestAsync
1 parent c725826 commit 55761dd

File tree

2 files changed

+10
-48
lines changed

2 files changed

+10
-48
lines changed

src/ExpoClient.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export class Expo {
2828
private httpAgent: Dispatcher | undefined;
2929
private limitConcurrentRequests: <T>(thunk: () => Promise<T>) => Promise<T>;
3030
private accessToken: string | undefined;
31-
private useFcmV1: boolean | undefined;
3231
private retryMinTimeout: number;
3332

3433
constructor(options: Partial<ExpoClientOptions> = {}) {
@@ -38,7 +37,6 @@ export class Expo {
3837
);
3938
this.retryMinTimeout = options.retryMinTimeout ?? requestRetryMinTimeout;
4039
this.accessToken = options.accessToken;
41-
this.useFcmV1 = options.useFcmV1;
4240
}
4341

4442
/**
@@ -66,10 +64,6 @@ export class Expo {
6664
*/
6765
async sendPushNotificationsAsync(messages: ExpoPushMessage[]): Promise<ExpoPushTicket[]> {
6866
const url = new URL(sendApiUrl);
69-
// Only append the useFcmV1 option if the option is set to false
70-
if (this.useFcmV1 === false) {
71-
url.searchParams.append('useFcmV1', String(this.useFcmV1));
72-
}
7367
const actualMessagesCount = Expo._getActualMessageCount(messages);
7468
const data = await this.limitConcurrentRequests(async () => {
7569
return await promiseRetry(
@@ -202,11 +196,15 @@ export class Expo {
202196
}
203197

204198
private async requestAsync(url: string, options: RequestOptions): Promise<any> {
199+
const json = JSON.stringify(options.body);
200+
assert(json != null, `JSON request body must not be null`);
201+
205202
const sdkVersion = require('../package.json').version;
206203
const requestHeaders = new Headers({
207204
Accept: 'application/json',
208205
'Accept-Encoding': 'gzip, deflate',
209206
'User-Agent': `expo-server-sdk-node/${sdkVersion}`,
207+
'Content-Type': 'application/json',
210208
});
211209
if (this.accessToken) {
212210
requestHeaders.set('Authorization', `Bearer ${this.accessToken}`);
@@ -217,17 +215,11 @@ export class Expo {
217215
headers: requestHeaders,
218216
};
219217

220-
if (options.body != null) {
221-
const json = JSON.stringify(options.body);
222-
assert(json != null, `JSON request body must not be null`);
223-
if (options.shouldCompress(json)) {
224-
fetchOptions.body = gzipSync(Buffer.from(json));
225-
requestHeaders.set('Content-Encoding', 'gzip');
226-
} else {
227-
fetchOptions.body = json;
228-
}
229-
230-
requestHeaders.set('Content-Type', 'application/json');
218+
if (options.shouldCompress(json)) {
219+
fetchOptions.body = gzipSync(Buffer.from(json));
220+
requestHeaders.set('Content-Encoding', 'gzip');
221+
} else {
222+
fetchOptions.body = json;
231223
}
232224

233225
if (this.httpAgent) {
@@ -340,7 +332,6 @@ export type ExpoClientOptions = {
340332
maxConcurrentRequests: number;
341333
retryMinTimeout: number;
342334
accessToken: string;
343-
useFcmV1: boolean;
344335
};
345336

346337
export type ExpoPushToken = string;
@@ -415,7 +406,7 @@ export type ExpoPushReceipt = ExpoPushSuccessReceipt | ExpoPushErrorReceipt;
415406

416407
type RequestOptions = {
417408
httpMethod: 'get' | 'post';
418-
body?: ExpoPushMessage[] | { ids: string[] };
409+
body: ExpoPushMessage[] | { ids: string[] };
419410
shouldCompress: (body: string) => boolean;
420411
};
421412

src/__tests__/ExpoClient-test.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ const apiBaseUrl = 'https://exp.host';
1111
const accessToken = 'foobar';
1212
const mockTickets = [{ status: 'ok', id: randomUUID() }];
1313
const mockReceipts = {};
14-
const validationError = {
15-
body: { errors: [{ code: 'VALIDATION_ERROR' }] },
16-
statusCode: 400,
17-
};
1814

1915
let mockAgent: MockAgent;
2016

@@ -49,31 +45,6 @@ describe('sending push notification messages', () => {
4945
);
5046
});
5147

52-
describe('the useFcmV1 option', () => {
53-
test('omits the parameter when set to true', async () => {
54-
const mockPool = mockAgent.get(apiBaseUrl);
55-
mockPool.intercept({ path: sendApiUrl, method: 'POST' }).reply(200, (opts) => {
56-
const url = new URL(opts.path, apiBaseUrl);
57-
expect(url.searchParams.has('useFcmV1')).toBe(false);
58-
return { data: mockTickets };
59-
});
60-
61-
await expect(
62-
client({ useFcmV1: true }).sendPushNotificationsAsync([{ to: '' }]),
63-
).resolves.toEqual(mockTickets);
64-
});
65-
66-
test('throws an error when set to false', async () => {
67-
const mockPool = mockAgent.get(apiBaseUrl);
68-
mockPool
69-
.intercept({ path: sendApiUrl, method: 'POST', query: { useFcmV1: 'false' } })
70-
.reply(validationError.statusCode, validationError.body);
71-
await expect(
72-
client({ useFcmV1: false }).sendPushNotificationsAsync([{ to: '' }]),
73-
).rejects.toThrow();
74-
});
75-
});
76-
7748
test('compresses request bodies over 1 KiB', async () => {
7849
const messages = [{ to: 'a', body: new Array(1500).join('?') }];
7950
const messageLength = JSON.stringify(messages).length;

0 commit comments

Comments
 (0)