Skip to content

feat(fcm): Enable fid and deprecate token for Send API#3145

Open
yvonnep165 wants to merge 5 commits into
mainfrom
yp-add-fid-arg
Open

feat(fcm): Enable fid and deprecate token for Send API#3145
yvonnep165 wants to merge 5 commits into
mainfrom
yp-add-fid-arg

Conversation

@yvonnep165
Copy link
Copy Markdown

@yvonnep165 yvonnep165 commented May 13, 2026

This change deprecates TokenMessage interface and the tokens field in MulticastMessage interface as message targets, transitioning support to FidMessage interface and fids in MulticastMessage as the primary targets instead.

The multicast helper function sendEachForMulticast is updated to support both target types concurrently up to a combined total of 500.

Question: There were no docstrings for TopicMessage and ConditionMessage interfaces previously. Should I add docstring for the new FidMessage interface or I just stay consistent with the old interfaces?

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Firebase Installation IDs (FIDs) in the messaging service by adding the FidMessage interface and updating the Message union type. The MulticastMessage interface now supports targeting via fids, and the tokens field has been deprecated and made optional. Feedback includes suggestions to add documentation for the new FidMessage interface, refactor the message construction logic using object destructuring for better maintainability, and improve the grammar of validation error messages. Additionally, the reviewer noted that making tokens optional is a breaking change for TypeScript consumers that should be highlighted in release notes.

Comment on lines +29 to +31
export interface FidMessage extends BaseMessage {
fid: string;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To address your question in the PR description, it is highly recommended to add docstrings for the new FidMessage interface and its fields. This ensures consistency with other public interfaces and improves the developer experience for users of the SDK.

/**
 * Interface representing a message targeted at a Firebase Installation ID (FID).
 */
export interface FidMessage extends BaseMessage {
  /**
   * The Firebase Installation ID (FID) to which the message should be sent.
   */
  fid: string;
}

Comment on lines 58 to 70
export interface MulticastMessage extends BaseMessage {
tokens: string[];
/**
* A list of Firebase Installation IDs (FIDs) to target.
*/
fids?: string[];

/**
* A list of registration tokens to target.
*
* @deprecated Use {@link MulticastMessage.fids} instead.
*/
tokens?: string[];
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Changing tokens from a required field (tokens: string[]) to an optional one (tokens?: string[]) in the MulticastMessage interface is a breaking change for TypeScript consumers who might be relying on the property's presence (e.g., accessing .length without a null check). While necessary for the migration to fids, this should be clearly highlighted in the release notes.

throw new FirebaseMessagingError(
MessagingClientErrorCode.INVALID_ARGUMENT,
`tokens list must not contain more than ${FCM_MAX_BATCH_SIZE} items`);
`tokens and fids list must not contain more than ${FCM_MAX_BATCH_SIZE} items in total`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error message grammar can be improved for better clarity.

Suggested change
`tokens and fids list must not contain more than ${FCM_MAX_BATCH_SIZE} items in total`);
`The total number of tokens and fids must not exceed ${FCM_MAX_BATCH_SIZE}.`);

Comment on lines +324 to +346
const messages: Message[] = [];
tokens.forEach((token) => {
messages.push({
token,
android: copy.android,
apns: copy.apns,
data: copy.data,
notification: copy.notification,
webpush: copy.webpush,
fcmOptions: copy.fcmOptions,
};
});
});
fids.forEach((fid) => {
messages.push({
fid,
android: copy.android,
apns: copy.apns,
data: copy.data,
notification: copy.notification,
webpush: copy.webpush,
fcmOptions: copy.fcmOptions,
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for constructing the messages array can be refactored to be more concise and future-proof by using object destructuring and the spread operator. This avoids manually listing every property of BaseMessage and automatically handles any future additions to the base type.

    const { tokens: _, fids: __, ...baseMessage } = copy;
    const messages: Message[] = [
      ...tokens.map((token) => ({ ...baseMessage, token } as Message)),
      ...fids.map((fid) => ({ ...baseMessage, fid } as Message)),
    ];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant