Skip to content

change(fcm): Remove deprecated FCM APIs #2759

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

Merged
merged 1 commit into from
Nov 5, 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
10 changes: 0 additions & 10 deletions etc/firebase-admin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,12 @@ export namespace messaging {
export type Message = Message;
// Warning: (ae-forgotten-export) The symbol "Messaging" needs to be exported by the entry point default-namespace.d.ts
export type Messaging = Messaging;
// Warning: (ae-forgotten-export) The symbol "MessagingConditionResponse" needs to be exported by the entry point default-namespace.d.ts
export type MessagingConditionResponse = MessagingConditionResponse;
// Warning: (ae-forgotten-export) The symbol "MessagingDeviceGroupResponse" needs to be exported by the entry point default-namespace.d.ts
export type MessagingDeviceGroupResponse = MessagingDeviceGroupResponse;
// Warning: (ae-forgotten-export) The symbol "MessagingDeviceResult" needs to be exported by the entry point default-namespace.d.ts
export type MessagingDeviceResult = MessagingDeviceResult;
// Warning: (ae-forgotten-export) The symbol "MessagingDevicesResponse" needs to be exported by the entry point default-namespace.d.ts
export type MessagingDevicesResponse = MessagingDevicesResponse;
// Warning: (ae-forgotten-export) The symbol "MessagingOptions" needs to be exported by the entry point default-namespace.d.ts
export type MessagingOptions = MessagingOptions;
// Warning: (ae-forgotten-export) The symbol "MessagingPayload" needs to be exported by the entry point default-namespace.d.ts
export type MessagingPayload = MessagingPayload;
// Warning: (ae-forgotten-export) The symbol "MessagingTopicManagementResponse" needs to be exported by the entry point default-namespace.d.ts
export type MessagingTopicManagementResponse = MessagingTopicManagementResponse;
// Warning: (ae-forgotten-export) The symbol "MessagingTopicResponse" needs to be exported by the entry point default-namespace.d.ts
export type MessagingTopicResponse = MessagingTopicResponse;
// Warning: (ae-forgotten-export) The symbol "MulticastMessage" needs to be exported by the entry point default-namespace.d.ts
export type MulticastMessage = MulticastMessage;
// Warning: (ae-forgotten-export) The symbol "Notification" needs to be exported by the entry point default-namespace.d.ts
Expand Down
52 changes: 1 addition & 51 deletions etc/firebase-admin.messaging.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,8 @@ export class Messaging {
// @deprecated
enableLegacyHttpTransport(): void;
send(message: Message, dryRun?: boolean): Promise<string>;
// @deprecated
sendAll(messages: Message[], dryRun?: boolean): Promise<BatchResponse>;
sendEach(messages: Message[], dryRun?: boolean): Promise<BatchResponse>;
sendEachForMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse>;
// @deprecated
sendMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse>;
// @deprecated
sendToCondition(condition: string, payload: MessagingPayload, options?: MessagingOptions): Promise<MessagingConditionResponse>;
// @deprecated
sendToDevice(registrationTokenOrTokens: string | string[], payload: MessagingPayload, options?: MessagingOptions): Promise<MessagingDevicesResponse>;
// @deprecated
sendToDeviceGroup(notificationKey: string, payload: MessagingPayload, options?: MessagingOptions): Promise<MessagingDeviceGroupResponse>;
// @deprecated
sendToTopic(topic: string, payload: MessagingPayload, options?: MessagingOptions): Promise<MessagingTopicResponse>;
subscribeToTopic(registrationTokenOrTokens: string | string[], topic: string): Promise<MessagingTopicManagementResponse>;
unsubscribeFromTopic(registrationTokenOrTokens: string | string[], topic: string): Promise<MessagingTopicManagementResponse>;
}
Expand Down Expand Up @@ -308,40 +296,6 @@ export class MessagingClientErrorCode {
};
}

// @public
export interface MessagingConditionResponse {
messageId: number;
}

// @public @deprecated
export interface MessagingDeviceGroupResponse {
failedRegistrationTokens: string[];
failureCount: number;
successCount: number;
}

// @public @deprecated
export interface MessagingDeviceResult {
canonicalRegistrationToken?: string;
// Warning: (ae-forgotten-export) The symbol "FirebaseError" needs to be exported by the entry point index.d.ts
error?: FirebaseError;
messageId?: string;
}

// @public @deprecated
export interface MessagingDevicesResponse {
// (undocumented)
canonicalRegistrationTokenCount: number;
// (undocumented)
failureCount: number;
// (undocumented)
multicastId: number;
// (undocumented)
results: MessagingDeviceResult[];
// (undocumented)
successCount: number;
}

// @public
export interface MessagingOptions {
// (undocumented)
Expand Down Expand Up @@ -369,11 +323,6 @@ export interface MessagingTopicManagementResponse {
successCount: number;
}

// @public
export interface MessagingTopicResponse {
messageId: number;
}

// @public
export interface MulticastMessage extends BaseMessage {
// (undocumented)
Expand Down Expand Up @@ -407,6 +356,7 @@ export interface NotificationMessagePayload {

// @public
export interface SendResponse {
// Warning: (ae-forgotten-export) The symbol "FirebaseError" needs to be exported by the entry point index.d.ts
error?: FirebaseError;
messageId?: string;
success: boolean;
Expand Down
141 changes: 0 additions & 141 deletions src/messaging/batch-request-internal.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/messaging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ export {

// Legacy APIs
DataMessagePayload,
MessagingConditionResponse,
MessagingDeviceGroupResponse,
MessagingDeviceResult,
MessagingDevicesResponse,
MessagingOptions,
MessagingPayload,
MessagingTopicResponse,
NotificationMessagePayload,
} from './messaging-api';

Expand Down
46 changes: 4 additions & 42 deletions src/messaging/messaging-api-request-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ import {
AuthorizedHttp2Client, Http2SessionHandler, Http2RequestConfig,
} from '../utils/api-request';
import { createFirebaseError, getErrorCode } from './messaging-errors-internal';
import { SubRequest, BatchRequestClient } from './batch-request-internal';
import { getSdkVersion } from '../utils/index';
import { SendResponse, BatchResponse } from './messaging-api';
import { SendResponse } from './messaging-api';


// FCM backend constants
const FIREBASE_MESSAGING_TIMEOUT = 15000;
const FIREBASE_MESSAGING_BATCH_URL = 'https://fcm.googleapis.com/batch';
const FIREBASE_MESSAGING_HTTP_METHOD: HttpMethod = 'POST';
const FIREBASE_MESSAGING_HEADERS = {
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'X-Goog-Api-Client': `gl-node/${process.versions.node} fire-admin/${getSdkVersion()}`
};
const LEGACY_FIREBASE_MESSAGING_HEADERS = {
'X-Firebase-Client': `fire-admin-node/${getSdkVersion()}`,
'X-Goog-Api-Client': `gl-node/${process.versions.node} fire-admin/${getSdkVersion()}`,
'access_token_auth': 'true',
Expand All @@ -48,7 +42,6 @@ const LEGACY_FIREBASE_MESSAGING_HEADERS = {
export class FirebaseMessagingRequestHandler {
private readonly httpClient: AuthorizedHttpClient;
private readonly http2Client: AuthorizedHttp2Client;
private readonly batchClient: BatchRequestClient;

/**
* @param app - The app used to fetch access tokens to sign API requests.
Expand All @@ -57,8 +50,6 @@ export class FirebaseMessagingRequestHandler {
constructor(app: App) {
this.httpClient = new AuthorizedHttpClient(app as FirebaseApp);
this.http2Client = new AuthorizedHttp2Client(app as FirebaseApp);
this.batchClient = new BatchRequestClient(
this.httpClient, FIREBASE_MESSAGING_BATCH_URL, FIREBASE_MESSAGING_HEADERS);
}

/**
Expand All @@ -74,7 +65,7 @@ export class FirebaseMessagingRequestHandler {
method: FIREBASE_MESSAGING_HTTP_METHOD,
url: `https://${host}${path}`,
data: requestData,
headers: LEGACY_FIREBASE_MESSAGING_HEADERS,
headers: FIREBASE_MESSAGING_HEADERS,
timeout: FIREBASE_MESSAGING_TIMEOUT,
};
return this.httpClient.send(request).then((response) => {
Expand Down Expand Up @@ -116,7 +107,7 @@ export class FirebaseMessagingRequestHandler {
method: FIREBASE_MESSAGING_HTTP_METHOD,
url: `https://${host}${path}`,
data: requestData,
headers: LEGACY_FIREBASE_MESSAGING_HEADERS,
headers: FIREBASE_MESSAGING_HEADERS,
timeout: FIREBASE_MESSAGING_TIMEOUT,
};
return this.httpClient.send(request).then((response) => {
Expand Down Expand Up @@ -146,7 +137,7 @@ export class FirebaseMessagingRequestHandler {
method: FIREBASE_MESSAGING_HTTP_METHOD,
url: `https://${host}${path}`,
data: requestData,
headers: LEGACY_FIREBASE_MESSAGING_HEADERS,
headers: FIREBASE_MESSAGING_HEADERS,
timeout: FIREBASE_MESSAGING_TIMEOUT,
http2SessionHandler: http2SessionHandler
};
Expand All @@ -162,35 +153,6 @@ export class FirebaseMessagingRequestHandler {
});
}

/**
* Sends the given array of sub requests as a single batch to FCM, and parses the result into
* a `BatchResponse` object.
*
* @param requests - An array of sub requests to send.
* @returns A promise that resolves when the send operation is complete.
*/
public sendBatchRequest(requests: SubRequest[]): Promise<BatchResponse> {
return this.batchClient.send(requests)
.then((responses: RequestResponse[]) => {
return responses.map((part: RequestResponse) => {
return this.buildSendResponse(part);
});
}).then((responses: SendResponse[]) => {
const successCount: number = responses.filter((resp) => resp.success).length;
return {
responses,
successCount,
failureCount: responses.length - successCount,
};
}).catch((err) => {
if (err instanceof RequestResponseError) {
throw createFirebaseError(err);
}
// Re-throw the error if it already has the proper format.
throw err;
});
}

private buildSendResponse(response: RequestResponse): SendResponse {
const result: SendResponse = {
success: response.status === 200,
Expand Down
Loading