Skip to content
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

feat(browser-sdk,react-sdk): extend the web SDKs to support the new config option. #285

Merged
merged 32 commits into from
Jan 29, 2025

Conversation

pavkam
Copy link
Contributor

@pavkam pavkam commented Jan 13, 2025

This PR introduces the config, which is an user-supplied JSON value that matches a given feature context (similar to targeting). The resolved configuration variant is then passed down to the client SDKs for use.

This update introduces a new `config` property for features, allowing optional, user-defined configuration payloads. The change includes implementation within SDKs, unit tests, and updates to version numbers. It maintains backward compatibility while enabling new configuration flexibility.
Simplified flag evaluation by introducing a generic `resolveFeature` method for type consistency and streamlined logic. Added extensive test cases for different flag types and scenarios. Updated `@bucketco/browser-sdk` dependency to version 2.6.0 for compatibility.
Introduced support for feature-specific configurations, enabling dynamic payloads for features based on user-defined rules. Enhanced fallback features to accept both string arrays and object records, providing more flexibility for feature initialization. Updated documentation and tests to reflect the new configuration capabilities and backwards-compatible fallback behavior.
@pavkam pavkam self-assigned this Jan 13, 2025
…eb-sdks-to-expose-the-config

# Conflicts:
#	packages/browser-sdk/src/client.ts
#	packages/browser-sdk/src/feature/features.ts
@pavkam pavkam marked this pull request as ready for review January 13, 2025 16:42
@pavkam pavkam changed the title buc-3198-extend-the-web-sdks-to-expose-the-config WIP: Extend the web SDKs to support the new config option. Jan 13, 2025
Update package version to 0.4.0 to reflect changes and improvements made in the OpenFeature browser provider. This helps signify a new iteration with potential new features or fixes.
Copy link
Contributor

@roncohen roncohen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

started reviewing this, but since we still need to get the key stuff in I'll pause for now and revisit once that's updated. Looks like a good start though!

packages/browser-sdk/README.md Outdated Show resolved Hide resolved
packages/browser-sdk/README.md Outdated Show resolved Hide resolved
packages/browser-sdk/README.md Outdated Show resolved Hide resolved
…enhance feature handling

- Added a new "format" script to package.json for consistent code formatting.
- Improved formatting in README.md files across browser-sdk, react-sdk, and openfeature-browser-provider for better readability.
- Updated feature handling in features.ts and mocks/handlers.ts to ensure proper type usage and maintainability.
- Adjusted test cases to reflect changes in feature access patterns.

These changes enhance the developer experience and maintain code quality.
…documentation

- Renamed "Feature toggles" section to "Remote config" in README.md for clarity.
- Introduced a new type, `FeatureDynamicConfig`, to better represent dynamic feature configurations in client.ts.
- Updated the `Feature` interface to use `FeatureDynamicConfig` instead of a generic `any` type for the `config` property.
- Adjusted the handling of feature configurations in the `BucketClient` class to utilize a default `missingConfig`.
- Enhanced the `FetchedFeature` type in features.ts to reflect the new configuration structure.
- Updated test cases to align with the new configuration model, ensuring accurate feature representation.

These changes enhance type safety and improve the overall developer experience when working with feature configurations.
- Introduced a new EMPTY_FEATURE_CONFIG constant to provide a default configuration for features.
- Updated the useFeature hook to return a more structured Feature type, including isEnabled, isLoading, and config properties.
- Modified requestFeedback function to use a more specific RequestFeedbackOptions type.
- Adjusted test cases to validate the new feature configuration structure and ensure correct default values are returned.

These changes improve type safety and enhance the developer experience when working with feature flags.
…e configuration handling and improve documentation

- Updated feature configuration structure across browser-sdk and react-sdk to use `targetingVersion` and `value` instead of `version` and `payload`.
- Refactored related types and interfaces to improve type safety and clarity in feature handling.
- Enhanced README documentation to reflect changes in feature configuration and usage examples.
- Adjusted test cases to validate the new configuration structure and ensure accurate feature representation.

These changes improve the developer experience and maintainability of the SDKs.
@pavkam pavkam changed the title WIP: Extend the web SDKs to support the new config option. Extend the web SDKs to support the new config option. Jan 22, 2025
@pavkam pavkam requested a review from roncohen January 22, 2025 16:34
Copy link
Contributor

@roncohen roncohen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good stuff! I will take this for a spin and try it in an application.

packages/browser-sdk/README.md Outdated Show resolved Hide resolved
packages/browser-sdk/README.md Outdated Show resolved Hide resolved
packages/browser-sdk/README.md Outdated Show resolved Hide resolved
packages/browser-sdk/README.md Outdated Show resolved Hide resolved
packages/browser-sdk/src/client.ts Outdated Show resolved Hide resolved
packages/react-sdk/src/index.tsx Outdated Show resolved Hide resolved
packages/react-sdk/src/index.tsx Outdated Show resolved Hide resolved
packages/react-sdk/README.md Show resolved Hide resolved
packages/openfeature-browser-provider/src/index.ts Outdated Show resolved Hide resolved
packages/openfeature-browser-provider/src/index.ts Outdated Show resolved Hide resolved
…ration

- Changed the reference from `value` to `payload` in the README documentation to accurately describe the updated feature configuration structure.
- Ensured that the example usage aligns with the latest implementation for better clarity and understanding.

These updates improve the documentation and help developers understand the new configuration handling.
@pavkam pavkam requested a review from roncohen January 24, 2025 10:52
packages/browser-sdk/src/client.ts Outdated Show resolved Hide resolved
packages/browser-sdk/src/client.ts Outdated Show resolved Hide resolved
packages/browser-sdk/test/mocks/handlers.ts Show resolved Hide resolved
packages/node-sdk/src/client.ts Show resolved Hide resolved
Simplified the feature remote config type by removing unnecessary properties and aligning with recent configuration changes. Minor refactoring of sendCheckEvent method to use shorthand property syntax.
@pavkam pavkam changed the title Extend the web SDKs to support the new config option. feat(browser-sdk,react-sdk): extend the web SDKs to support the new config option. Jan 27, 2025
Cleaned up an unnecessary import of Features from a development-specific path in the main index file.
Update FallbackFeatureConfig type to support boolean and object overrides, allowing more flexible feature flag configuration. Modify feature fallback logic to handle both simple boolean flags and complex feature configurations.
Remove the .only modifier from the "caches response" test to ensure all tests are run during test execution.
Modify test assertions to reflect changes in feature configuration handling, including expected feature state and override behavior.
Update useFeature hook to create a reduced configuration object with only key and payload, streamlining config retrieval and aligning with recent configuration changes in the SDK.
@pavkam pavkam requested a review from Swiftwork January 28, 2025 11:32
Update README files for browser and react SDKs to provide more detailed explanations of remote configuration handling, including:
- Clarifying optional payload behavior
- Adding guidance on handling undefined config
- Improving code examples for remote config usage
…expose-the-config' into buc-3198-extend-the-web-sdks-to-expose-the-config
Add FallbackFeatureOverride to the exported types, extending the SDK's type exports for feature configuration
Update package versions and lock file to reflect the new alpha release, ensuring consistent versioning across SDKs
Copy link
Contributor

@roncohen roncohen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apart from the EmptyFeatureConfig stuff, this all look good 👍

@pavkam pavkam merged commit 78ba573 into main Jan 29, 2025
5 checks passed
@pavkam pavkam deleted the buc-3198-extend-the-web-sdks-to-expose-the-config branch January 29, 2025 12:06
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.

3 participants