Skip to content

feat: Add payloadFilter option to request a filtered environment - #548

Draft
abelonogov-ld wants to merge 1 commit into
v11from
andrey/payload-filter
Draft

abelonogov-ld wants to merge 1 commit into
v11from
andrey/payload-filter

Conversation

@abelonogov-ld

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Mirrors payloadFilterKey in 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 (and ObjcLDConfig.payloadFilter). When set, the SDK adds filter=<key> to every flag data request:

  • streaming (/meval, GET and REPORT)
  • polling (/msdk/evalx, GET and REPORT)

DarklyService validates 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-strict behavior).

shouldGetReasons(url:) used to overwrite the URL's query items with withReasons=true. It's replaced by addingQueryItems(to:), which builds withReasons and filter together, so both are sent when both are configured.

The contract-test service now maps the harness's streaming.filter / polling.filter to the new option and declares the filtering and filtering-strict capabilities.

Describe alternatives you've considered

  • Validating in a property setter. logger may be assigned after payloadFilter, so the error would go to the default logger; validating in DarklyService uses the final config.
  • Sending invalid keys as-is (React Native's current behavior). Rejected in favor of the spec.

Additional context

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:

  • Polling (/msdk/evalx): the streamer drops the query string before it reaches the origin, so these responses are unfiltered.
  • Streaming (/meval): the filter is forwarded and applied to the initial put when the payload-filter-gonfalon-sdk-endpoints flag is on. Live updates are only routed by filter when payload-filter-streamer-updates is 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 718 tests pass under swift test.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
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.

1 participant