@@ -22,20 +22,14 @@ import {
2222 AuthorizedHttp2Client , Http2SessionHandler , Http2RequestConfig ,
2323} from '../utils/api-request' ;
2424import { createFirebaseError , getErrorCode } from './messaging-errors-internal' ;
25- import { SubRequest , BatchRequestClient } from './batch-request-internal' ;
2625import { getSdkVersion } from '../utils/index' ;
27- import { SendResponse , BatchResponse } from './messaging-api' ;
26+ import { SendResponse } from './messaging-api' ;
2827
2928
3029// FCM backend constants
3130const FIREBASE_MESSAGING_TIMEOUT = 15000 ;
32- const FIREBASE_MESSAGING_BATCH_URL = 'https://fcm.googleapis.com/batch' ;
3331const FIREBASE_MESSAGING_HTTP_METHOD : HttpMethod = 'POST' ;
3432const FIREBASE_MESSAGING_HEADERS = {
35- 'X-Firebase-Client' : `fire-admin-node/${ getSdkVersion ( ) } ` ,
36- 'X-Goog-Api-Client' : `gl-node/${ process . versions . node } fire-admin/${ getSdkVersion ( ) } `
37- } ;
38- const LEGACY_FIREBASE_MESSAGING_HEADERS = {
3933 'X-Firebase-Client' : `fire-admin-node/${ getSdkVersion ( ) } ` ,
4034 'X-Goog-Api-Client' : `gl-node/${ process . versions . node } fire-admin/${ getSdkVersion ( ) } ` ,
4135 'access_token_auth' : 'true' ,
@@ -48,7 +42,6 @@ const LEGACY_FIREBASE_MESSAGING_HEADERS = {
4842export class FirebaseMessagingRequestHandler {
4943 private readonly httpClient : AuthorizedHttpClient ;
5044 private readonly http2Client : AuthorizedHttp2Client ;
51- private readonly batchClient : BatchRequestClient ;
5245
5346 /**
5447 * @param app - The app used to fetch access tokens to sign API requests.
@@ -57,8 +50,6 @@ export class FirebaseMessagingRequestHandler {
5750 constructor ( app : App ) {
5851 this . httpClient = new AuthorizedHttpClient ( app as FirebaseApp ) ;
5952 this . http2Client = new AuthorizedHttp2Client ( app as FirebaseApp ) ;
60- this . batchClient = new BatchRequestClient (
61- this . httpClient , FIREBASE_MESSAGING_BATCH_URL , FIREBASE_MESSAGING_HEADERS ) ;
6253 }
6354
6455 /**
@@ -74,7 +65,7 @@ export class FirebaseMessagingRequestHandler {
7465 method : FIREBASE_MESSAGING_HTTP_METHOD ,
7566 url : `https://${ host } ${ path } ` ,
7667 data : requestData ,
77- headers : LEGACY_FIREBASE_MESSAGING_HEADERS ,
68+ headers : FIREBASE_MESSAGING_HEADERS ,
7869 timeout : FIREBASE_MESSAGING_TIMEOUT ,
7970 } ;
8071 return this . httpClient . send ( request ) . then ( ( response ) => {
@@ -116,7 +107,7 @@ export class FirebaseMessagingRequestHandler {
116107 method : FIREBASE_MESSAGING_HTTP_METHOD ,
117108 url : `https://${ host } ${ path } ` ,
118109 data : requestData ,
119- headers : LEGACY_FIREBASE_MESSAGING_HEADERS ,
110+ headers : FIREBASE_MESSAGING_HEADERS ,
120111 timeout : FIREBASE_MESSAGING_TIMEOUT ,
121112 } ;
122113 return this . httpClient . send ( request ) . then ( ( response ) => {
@@ -146,7 +137,7 @@ export class FirebaseMessagingRequestHandler {
146137 method : FIREBASE_MESSAGING_HTTP_METHOD ,
147138 url : `https://${ host } ${ path } ` ,
148139 data : requestData ,
149- headers : LEGACY_FIREBASE_MESSAGING_HEADERS ,
140+ headers : FIREBASE_MESSAGING_HEADERS ,
150141 timeout : FIREBASE_MESSAGING_TIMEOUT ,
151142 http2SessionHandler : http2SessionHandler
152143 } ;
@@ -162,35 +153,6 @@ export class FirebaseMessagingRequestHandler {
162153 } ) ;
163154 }
164155
165- /**
166- * Sends the given array of sub requests as a single batch to FCM, and parses the result into
167- * a `BatchResponse` object.
168- *
169- * @param requests - An array of sub requests to send.
170- * @returns A promise that resolves when the send operation is complete.
171- */
172- public sendBatchRequest ( requests : SubRequest [ ] ) : Promise < BatchResponse > {
173- return this . batchClient . send ( requests )
174- . then ( ( responses : RequestResponse [ ] ) => {
175- return responses . map ( ( part : RequestResponse ) => {
176- return this . buildSendResponse ( part ) ;
177- } ) ;
178- } ) . then ( ( responses : SendResponse [ ] ) => {
179- const successCount : number = responses . filter ( ( resp ) => resp . success ) . length ;
180- return {
181- responses,
182- successCount,
183- failureCount : responses . length - successCount ,
184- } ;
185- } ) . catch ( ( err ) => {
186- if ( err instanceof RequestResponseError ) {
187- throw createFirebaseError ( err ) ;
188- }
189- // Re-throw the error if it already has the proper format.
190- throw err ;
191- } ) ;
192- }
193-
194156 private buildSendResponse ( response : RequestResponse ) : SendResponse {
195157 const result : SendResponse = {
196158 success : response . status === 200 ,
0 commit comments