aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.36k stars 2.1k forks source link

fix: Prevent overwriting with fallbacks when updating endpoint #13330

Closed cshfang closed 1 week ago

cshfang commented 2 weeks ago

Description of changes

When calling initializePushNotifications, the library calls an internal updateEndpoint API. Anytime updateEndpoint is called, it automatically populates the demographic property with client info and the userId with the identity id. When calling identifyUser, these values can be provided explicitly but will always be pre-populated. This can have unexpected consequences since initializePushNotifications is typically called on every app launch - and it will opaquely overwrite existing values previously set on the endpoint.

This PR updates the updateEndpoint API to only pre-populate these fields when creating an endpoint to avoid repeatedly overwriting the endpoint with the default/fallback values.

Issue #, if available

https://github.com/aws-amplify/amplify-js/issues/13174

Description of how you validated changes

// Endpoint creation
{
  "RequestId": "8808844f-5e12-440b-a914-d3ae7191b0f8",
  "EffectiveDate": "2024-05-02T19:55:22.795Z",
  "ChannelType": "APNS_SANDBOX",
  "Address": "<apns-token>",
  "Demographic": {
    "AppVersion": "ios/17.0",
    "Make": null,
    "Model": null,
    "ModelVersion": "17.0",
    "Platform": "ios"
  },
  "User": { "UserId": "<cognito-identity-id>" }
}
// Endpoint update
{
  "RequestId": "8178652f-5842-44b6-a02c-27616f4d6cb9",
  "EffectiveDate": "2024-05-02T19:57:28.751Z",
  "ChannelType": "APNS_SANDBOX",
  "Address": "<apns-token>",
}

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.