Repository navigation
feat: Add payloadFilter option to request a filtered environment - #548
abelonogov-ld wants to merge 7 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # LaunchDarkly/LaunchDarkly/Networking/DarklyService.swift # LaunchDarkly/LaunchDarkly/ObjectiveC/ObjcLDConfig.swift # LaunchDarkly/LaunchDarklyTests/Networking/DarklyServiceSpec.swift
There was a problem hiding this comment.
Stale comment
Risk: low.
Automated risk review (dry run): Low
This PR would be automatically approved.
Why: Adds opt-in
LDConfig.payloadFilter(and the ObjC wrapper) soDarklyServicecan append a validatedfilterquery parameter on streaming and polling requests; default nil behavior is unchanged, and unit plus contract tests cover validation and URL construction.If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.
Sent by Cursor Approval Agent: Dry-Run PR Approver
There was a problem hiding this comment.
Stale comment
Risk: medium. Cursor Bugbot completed with no findings, but Rule 2 (allowed PR authors) blocks approval because the author is not on the SDK allowlist, and the change is a new public SDK option that alters flag-request URLs. Human review is needed and no reviewers were assigned.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver
…ry environment payloadFilter stays the filter for the primary environment and the default for every secondary environment. A secondary environment named in secondaryPayloadFilters uses its own key instead, or requests the full environment if the key is empty. Names that are not secondary environments are logged when the SDK starts and ignored. Co-authored-by: Cursor <cursoragent@cursor.com>
…mobileKey:payloadFilter:) A secondary environment's payload filter is now given together with its mobile key, so it can't name an unknown environment or drift from the keys. payloadFilter applies only to the primary environment; secondary environments are unfiltered unless added with a filter. addSecondaryEnvironment throws on the same name and key conflicts as setSecondaryMobileKeys. setSecondaryMobileKeys is unchanged apart from clearing filters of environments it replaces. Co-authored-by: Cursor <cursoragent@cursor.com>
…ys need FDv2 Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Risk: medium.
Automated risk review (dry run): Medium
This PR would not be automatically approved. Human approval required. The earlier dry-run Low / would-approve decision no longer applies.
Why: Later commits add public Swift and ObjC APIs (payloadFilter, addSecondaryEnvironment, per-environment filters on LDConfig / ObjcLDConfig / LDClient) that change which flag payloads streaming and polling requests receive, which is a meaningful SDK behavior change above Low.
If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.
Sent by Cursor Approval Agent: Dry-Run PR Approver
… lists with the same key Reading the keys with getSecondaryMobileKeys, adding one and setting them back dropped every filter given to addSecondaryEnvironment, silently. setSecondaryMobileKeys now keeps the filter of each environment it lists again under the same name and mobile key; a new name, or a name given a different key, has none. A call that throws changes nothing. LDConfig equality now compares the secondary mobile keys and their filters, which it did not compare at all, so ObjcLDConfig.isEqual tells such configs apart too. Co-authored-by: Cursor <cursoragent@cursor.com>


Requirements
Related issues
Mirrors
payloadFilterKeyin the React Native and browser SDKs (js-core#551) and follows the filtered environments SDK spec. Android counterpart: android-client-sdk#422.Describe the solution you've provided
Adds
LDConfig.payloadFilter(andObjcLDConfig.payloadFilter). When set, the SDK addsfilter=<key>to every flag data request:/meval, GET and REPORT)/msdk/evalx, GET and REPORT)DarklyServicevalidates the key once when it's created. A nil or empty key means no filter. A key that doesn't match^[a-zA-Z0-9][._\-a-zA-Z0-9]*$is dropped with an error log, and the full environment is requested, as the spec requires (filtering-strictbehavior).shouldGetReasons(url:)used to overwrite the URL's query items withwithReasons=true. It's replaced byaddingQueryItems(to:), which buildswithReasonsandfiltertogether, so both are sent when both are configured.Payload filters belong to a project, and secondary mobile keys may be in other projects, so a secondary environment's filter is given together with its mobile key:
payloadFilterapplies only to the primary environment.addSecondaryEnvironment(_:mobileKey:payloadFilter:)adds a secondary environment, with an optional filter (nil means none). It throwsLDInvalidArgumentErroron the same name and key conflicts assetSecondaryMobileKeys(_:).payloadFilter(forEnvironment:)returns an environment's filter, or nil for an unknown name.addSecondaryEnvironment:mobileKey:payloadFilter:error:andpayloadFilterForEnvironment:.Apps that don't use filters are unaffected:
setSecondaryMobileKeys(_:)is unchanged and its environments have no filter. Calling it replaces every secondary environment, including ones added with a filter.LDClient.startsets each environment's filter on that environment's copy of the config, so the rest of the SDK is unchanged.The contract-test service now maps the harness's
streaming.filter/polling.filterto the new option and declares thefilteringandfiltering-strictcapabilities.Describe alternatives you've considered
loggermay be assigned afterpayloadFilter, so the error would go to the default logger; validating inDarklyServiceuses the final config.[String: String]map of filters by environment name next tosetSecondaryMobileKeys(_:), withpayloadFilteras the default. The two maps can drift apart, a mistyped name silently falls back to another project's filter, and an empty string is needed to mean "no filter".Additional context
Payload filters are an FDv1 feature, and this SDK uses only FDv1. With FDv2, LaunchDarkly filters flag data by the views linked to the mobile key ("custom payload") instead, and the FDv2 payload filter is being removed across SDKs (sdk-test-harness#431, go-server-sdk#440). A mobile key with a custom payload can't be used with this SDK yet: LaunchDarkly rejects FDv1 requests made with it with
422(FDV2REL 1.1.1.3). The docs forpayloadFilterandaddSecondaryEnvironmentsay so. When the SDK gets FDv2, such a key will need no new API: it goes inmobileKey, with nopayloadFilter.This PR only sends the parameter; the SDK does no filtering of its own and doesn't change how it picks streaming or polling. The server doesn't currently apply the filter on every mobile endpoint:
/msdk/evalx): the streamer drops the query string before it reaches the origin, so these responses are unfiltered./meval): the filter is forwarded and applied to the initialputwhen thepayload-filter-gonfalon-sdk-endpointsflag is on. Live updates are only routed by filter whenpayload-filter-streamer-updatesis on.So an app that falls back to polling (or runs in the background, where iOS polls) may see the full flag set. The React Native SDK has the same limitation today.
I haven't run the contract test harness against this branch locally; the contract-test service builds. All 730 tests pass under
swift test.Note
Overview
Adds
payloadFilteronLDConfig/ObjcLDConfigso flag streaming and polling requests can include a LaunchDarklyfilter=query parameter.DarklyServicevalidates keys against the spec regex (filtering-strict: invalid keys are dropped with an error log and the full environment is fetched) and builds query strings viaaddingQueryItems, combiningwithReasonsandfilterwhere both apply.Secondary environments gain
addSecondaryEnvironment(_:mobileKey:payloadFilter:),payloadFilter(forEnvironment:), andsetSecondaryMobileKeysbehavior that preserves per-environment filters when name and mobile key are unchanged.LDClient.startassigns each instance its environment-specific filter. Contract tests declarefiltering/filtering-strictand pass harnessstreaming.filter/polling.filterthrough.Reviewed by Cursor Bugbot for commit 49b779b. Bugbot is set up for automated code reviews on this repo. Configure here.