File size: 1,890 Bytes
4a2ab42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from typing import Any

from core.plugin_system import PluginContext, PluginInterface, PluginMetadata


class FraudMetricsWidgetPlugin(PluginInterface):
    """
    Returns configuration for rendering a Fraud Metrics widget on the frontend.
    """

    @property
    def metadata(self) -> PluginMetadata:
        return PluginMetadata(  # Metadata is defined in json usually but interface requires property
            name="fraud_metrics_widget",
            version="1.0.0",
            namespace="zenith/ui/fraud_metrics_widget",
            author="Zenith Team",
            description="Dashboard widget configuration for displaying fraud trends",
            dependencies={},
            capabilities=["ui_widget", "dashboard"],
            security_level="official",
            api_version="v1",
        )

    async def initialize(self, context: PluginContext) -> bool:
        self.context = context
        self.config = context.config or {"refresh_interval": 300, "chart_type": "line"}
        return True

    async def execute(self, inputs: dict[str, Any]) -> dict[str, Any]:
        """
        Returns the Widget Definition JSON.
        Inputs: {"user_role": "admin", ...}
        """
        # We could customize the widget based on user role here

        return {
            "widget_id": "fraud_trends_v1",
            "title": "Fraud Detection Trends",
            "type": self.config.get("chart_type", "line"),
            "data_source": "/api/metrics/fraud",
            "layout": {"w": 6, "h": 4, "min_w": 3, "min_h": 3},
            "props": {
                "color": "#FF4444",
                "legend": True,
                "refresh_interval_ms": self.config.get("refresh_interval", 300) * 1000,
            },
        }

    async def cleanup(self) -> None:
        pass

    def validate_config(self, config: dict[str, Any]) -> list[str]:
        return []