-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix: Prevent overwriting with fallbacks when updating endpoint #13330
Conversation
d904325
to
612cd84
Compare
612cd84
to
d180cba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Chris! Good catch.
Had one nit and one question but LGTM!
// only automatically populate the endpoint with client info and identity id upon endpoint creation to | ||
// avoid overwriting the endpoint with these values every time the endpoint is updated | ||
const demographicsFromClientInfo: UserProfile['demographic'] = {}; | ||
const resolvedUserId = createdEndpointId ? userId ?? identityId : userId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Did we decide that ||
is better to use than ??
const resolvedUserId = createdEndpointId ? userId ?? identityId : userId; | |
const resolvedUserId = createdEndpointId ? userId || identityId : userId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure I understand: the identityId
property is always a default value and userId
is always customer provided or empty, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this call creates an endpoint
- use
userId
if provided, otherwise fall back toidentityId
If this call updates an endpoint
- use
userId
if provided but don't fall back to anything
To make sure I understand: the identityId property is always a default value and userId is always customer provided or empty, correct?
identityId
is always only a default/fallback value but is only set during endpoint creation. userId
is always customer provided or empty, yes.
Nit: Did we decide that || is better to use than ??
Generally speaking, ??
is almost always what we intend unless we explicitly want falsy values like 0
or ''
to qualify as "empty"
Description of changes
When calling
initializePushNotifications
, the library calls an internalupdateEndpoint
API. AnytimeupdateEndpoint
is called, it automatically populates thedemographic
property with client info and theuserId
with the identity id. When callingidentifyUser
, these values can be provided explicitly but will always be pre-populated. This can have unexpected consequences sinceinitializePushNotifications
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
#13174
Description of how you validated changes
yarn test
demographic
anduserId
are only on the network request when an endpoint has yet to be cached (endpoint creation) and subsequent calls do not.Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.