Add Remote Feature Flag Params to Dashboard Cards endpoint - #674
Conversation
…e RemoteFeatureFlagsEndpointParams Add a new getRemoteFeatureFlags variant that accepts an object of type RemoteFeatureFlagsEndpointParams
7239eef to
1f7ab13
Compare
34cdcad to
91b6e05
Compare
91b6e05 to
accfc22
Compare
hassaanelgarem
left a comment
There was a problem hiding this comment.
Looks good to me! 🚀
Kudos on adding tests!
Only left a few code improvement suggestions.
| "cards": cards.joined(separator: ",") as NSString | ||
| ] | ||
| let featureFlagParams = try { | ||
| let params = FeatureFlagRemote.RemoteFeatureFlagsEndpointParams(deviceId: deviceId) |
There was a problem hiding this comment.
I wonder if this struct should still live inside FeatureFlagRemote now that it's shared with an unrelated class.
There was a problem hiding this comment.
That was the plan initially, but couldn't figure out a name for that type. 😅
Co-authored-by: hassaanelgarem <hassaanelgarem@gmail.com>
…ithub.com:wordpress-mobile/WordPressKit-iOS into task/22315-backend-driven-dynamic-cards-filtering
| } | ||
|
|
||
| public struct RemoteFeatureFlagsEndpointParams { | ||
| public struct FetchAllEndpointParams { |
There was a problem hiding this comment.
@salimbraksa FetchAllEndpointParams feels a bit confusing. How about SessionDetails?
Also, can we move it outside of the FeatureFlagRemote scope? Referencing it by FeatureFlagRemote.FetchAllEndpointParams hurts the readability as it implies it is tighly coupled with feature flags while it's not. This is what I meant here #674 (comment)
There was a problem hiding this comment.
My concern with global scope is the following:
- Let's say another developer added a valid "session" attribute in
SessionDetails. - The new attribute is encoded and returned in the dictionary representation.
- Now that attribute will be sent in all other endpoints, and I'm not sure how endpoints handle extra attributes that don't need.
This is why I kept that type tightly related to Feature Flags, and if you think about it, the new params added in Dashboard Cards are for the Feature Flags mechanism.
There was a problem hiding this comment.
Now that attribute will be sent in all other endpoints, and I'm not sure how endpoints handle extra attribute that don't need.
We can assume that developers will seek to understand what this type is used for before changing it.
However, extra params won't cause an issue either way.
There was a problem hiding this comment.
We can assume that developers will seek to understand what this type is used for before changing it.
I agree, but my concern is that if we expand the SessionDetails with new 'session' attributes in the future, we need to ensure they are not inadvertently included in the Feature Flags and Dashboard Cards endpoint query params.
If we rename that type to SessionDetails, I think the Feature Flag Remote and Dashboard Cards service should select only the params they need.
Also, while I'm sure developers double check API usage before making changes, I think it's also important to write resilient code that mitigates the risks associated with human error.
There was a problem hiding this comment.
I'll rename the type to SessionsDetails and update the Unit Tests to ensure only the the params required by the endpoint are sent.
There was a problem hiding this comment.
However, extra params won't cause an issue either way.
Given this, I think we would be over-engineering to avoid something that's not critical.
There was a problem hiding this comment.
Resolved in 28cc006
However, extra params won't cause an issue either way.
Passing extra params to endpoints is a code smell in my opinion. Moreover, some backend APIs may reject the request if it includes additional parameters as a security measure.
I agree that we shouldn't spend time on imaginary problems. For now, it's enough to have Unit Tests to check for this. I looked at the tests we already have, and they'll fail if extra params are sent to Feature Flags and Dashboard Cards endpoints.
|
Thank you for working on this @salimbraksa and for adding tests. I also appreciate the helper functions, which enable writing othre tests in the future 🎉 I landed here while preparing the library for Jetpack and WordPress iOS 24.0. I noticed this PR introduce a breaking change, which is something we should be careful with because of the downstream implication in https://github.com/wordpress-mobile/WordPressAuthenticator-iOS which depends on WordPressKit. Given the app PR that uses this logic, wordpress-mobile/WordPress-iOS#22320, has not been merged at this time and won't be part of 24.0, I will not ship a new release with this breaking change just yet. Ideally, we'd want to provide a non-breaking API. If that's not possible, given we'll need to go through the effort of shipping the breaking change, we might as well look for other breaking low hanging fruits to slot in. Cheers (and Happy New Year!) |
|
Hey @mokagio, the other PR was supposed to be merged on Friday, but I just realized it didn't because of a flaky unit test unrelated to my PR. The PR was already been reviewed and approved, so I’ll work on fixing the failing test and aim to merge it into release/24.0. |
The parameter was [initially designed to be non-optional][PR-1]. Later it's later [changed to be optional][PR-2], under [this proposal][comment-1]. This commit simply reverts the parameter to be non-optional, to ship it along with other breaking changes. [PR-1]: #674 [PR-2]: #676 [comment-1]: wordpress-mobile/WordPress-iOS#22320 (comment)
Description
Part of wordpress-mobile/WordPress-iOS#22315
This PR passes the following params to the dashboard cards endpoint:
device_idplatformbuild_numbermarketing_versionidentifierTesting Details
See wordpress-mobile/WordPress-iOS#22320
Note
Please remove the
[Status] DO NOT MERGElabel and merge after:trunkCHANGELOG.mdif necessary.