(
feature: Feature,
environment: Environment,
enabled: bool,
value: typing.Union[str, int, bool, type(None)], # type: ignore[valid-type]
identity_id: int | str | None = None,
identity_identifier: str | None = None,
feature_segment: FeatureSegment | None = None,
multivariate_feature_state_values: list[MultivariateFeatureStateValue]
| None = None,
)
| 630 | |
| 631 | @staticmethod |
| 632 | def generate_webhook_feature_state_data( |
| 633 | feature: Feature, |
| 634 | environment: Environment, |
| 635 | enabled: bool, |
| 636 | value: typing.Union[str, int, bool, type(None)], # type: ignore[valid-type] |
| 637 | identity_id: int | str | None = None, |
| 638 | identity_identifier: str | None = None, |
| 639 | feature_segment: FeatureSegment | None = None, |
| 640 | multivariate_feature_state_values: list[MultivariateFeatureStateValue] |
| 641 | | None = None, |
| 642 | ) -> dict: # type: ignore[type-arg] |
| 643 | if (identity_id or identity_identifier) and not ( |
| 644 | identity_id and identity_identifier |
| 645 | ): |
| 646 | raise ValueError("Must provide both identity_id and identity_identifier.") |
| 647 | |
| 648 | if (identity_id and identity_identifier) and feature_segment: |
| 649 | raise ValueError("Cannot provide identity information and feature segment") |
| 650 | |
| 651 | mv_values_data = [ |
| 652 | { |
| 653 | "id": mv.id, |
| 654 | "multivariate_feature_option": { |
| 655 | "id": mv.multivariate_feature_option_id, |
| 656 | "value": mv.multivariate_feature_option.value, |
| 657 | }, |
| 658 | "percentage_allocation": mv.percentage_allocation, |
| 659 | } |
| 660 | for mv in (multivariate_feature_state_values or []) |
| 661 | ] |
| 662 | |
| 663 | # TODO: refactor to use a serializer / schema |
| 664 | data: dict[str, typing.Any] = { |
| 665 | "feature": { |
| 666 | "id": feature.id, |
| 667 | "created_date": feature.created_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ"), |
| 668 | "default_enabled": feature.default_enabled, |
| 669 | "description": feature.description, |
| 670 | "initial_value": feature.initial_value, |
| 671 | "name": feature.name, |
| 672 | "project": { |
| 673 | "id": feature.project_id, |
| 674 | "name": feature.project.name, |
| 675 | }, |
| 676 | "type": feature.type, |
| 677 | }, |
| 678 | "environment": { |
| 679 | "id": environment.id, |
| 680 | "name": environment.name, |
| 681 | }, |
| 682 | "identity": identity_id, |
| 683 | "identity_identifier": identity_identifier, |
| 684 | "feature_segment": None, |
| 685 | "enabled": enabled, |
| 686 | "feature_state_value": value, |
| 687 | "multivariate_feature_state_values": mv_values_data, |
| 688 | } |
| 689 | if feature_segment: |
no outgoing calls