Skip to content

Feat/messaging request response#9866

Open
zwu52 wants to merge 4 commits intofeat/messaging-api-seriesfrom
feat/messaging-request-response
Open

Feat/messaging request response#9866
zwu52 wants to merge 4 commits intofeat/messaging-api-seriesfrom
feat/messaging-request-response

Conversation

@zwu52
Copy link
Copy Markdown
Member

@zwu52 zwu52 commented Apr 20, 2026

  • add sdk version & origin in the request
  • fix response parsing

zwu52 added 3 commits March 31, 2026 10:40
- Persist the last successful FID registration time in IndexedDB and refresh backend registration on a 7-day cadence even when the FID is unchanged
- Fall back to opening DB v1 when opening/upgrading to v2 fails, so existing token data remains readable (guarded by a unit test)
- Extend register() tests to cover weekly refresh without re-firing onRegistered

Made-with: Cursor
Add top-level origin to registration API payloads (host from SW scope URL,
or app name fallback). Export getRegistrationOrigin for tests. Clarify
CreateRegistration name field in register-fid comment.

Made-with: Cursor
@zwu52 zwu52 requested a review from a team as a code owner April 20, 2026 21:40
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 20, 2026

⚠️ No Changeset found

Latest commit: 1511052

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@zwu52 zwu52 requested review from Doris-Ge and removed request for a team April 20, 2026 21:40
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 updates the FCM messaging package to include the SDK version and origin in registration requests and adds support for parsing the Firebase Installation ID (FID) from both legacy plain strings and new resource name formats. Key changes include the implementation of getRegistrationOrigin to derive the client's host from the service worker scope and updates to the request body interfaces. Feedback highlights an improvement opportunity to avoid circular dependencies in tests by using hardcoded expected values and suggests using a more robust regex-based approach for parsing FIDs from resource names.

I am having trouble creating individual review comments. Click here to see my feedback.

packages/messaging/src/internals/requests.test.ts (72-75)

medium

The test uses the implementation function getRegistrationOrigin to define the expected value for the origin field. This creates a circular dependency in the test logic, meaning that if getRegistrationOrigin has a bug, the test might still pass because both the code and the test use the same faulty logic. It is better to use a hardcoded string (e.g., 'example.org') that represents the expected output for the specific input used in the test.

        origin: 'example.org',

packages/messaging/src/internals/requests.test.ts (272-275)

medium

Similar to the getToken test, this test uses the implementation function getRegistrationOrigin to define the expected value. To ensure the test is robust and independent of the implementation logic, please use a hardcoded expected value.

        origin: 'example.org',

packages/messaging/src/internals/requests.ts (204-210)

medium

The logic for extracting the FID from the resource name using indexOf and slice is somewhat fragile. It assumes that the FID is always the remainder of the string after the first occurrence of /registrations/. A more robust approach would be to use a regular expression that specifically matches the expected resource name pattern (e.g., projects/*/registrations/*) and extracts the final segment. This would better handle potential edge cases or future changes in the resource name format.

* - Use the FIS auth token produced by the installations instance (implicitly associated with FID).
* - CreateRegistration must echo a non-empty FID in `name`; it must match `expectedFid` from
* - CreateRegistration must echo the installation in `name` (e.g.
* `projects/{projectId}/registrations/{fid}`) or a legacy plain FID; it must match `expectedFid` from
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure about what legacy plain FID means. I think it's either name or token for backend. However for this method, it should always expect name from backend.

): ApiRequestBody {
const body: ApiRequestBody = {
// eslint-disable-next-line camelcase
fcm_sdk_version: fcmSdkVersion,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we set fcm_sdk_version here, does it guarantee that the token creation is not affected? Since backend will use this parameter to differentiate whether to create a FID-based or a token-based registration, so we should only pass fcm_sdk_version for FID registration requests.

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.

2 participants