edgee_components_runtime/
config.rs

1use crate::{
2    data_collection::versions::DataCollectionWitVersion,
3    edge_function::versions::EdgeFunctionWitVersion,
4};
5use std::{collections::HashMap, path::PathBuf};
6
7use serde::Deserialize;
8
9#[derive(Deserialize, Debug, Default, Clone)]
10pub struct ComponentsConfiguration {
11    #[serde(default)]
12    pub data_collection: Vec<DataCollectionComponents>,
13    // NOTE: add other version here
14    #[serde(default)]
15    pub edge_function: Vec<EdgeFunctionComponents>,
16
17    pub cache: Option<PathBuf>,
18}
19
20#[derive(Deserialize, Debug, Clone, Default)]
21pub struct DataCollectionComponents {
22    #[serde(skip_deserializing)]
23    pub project_component_id: String,
24    #[serde(skip_deserializing)]
25    pub slug: String,
26    pub id: String, // could be a slug (edgee/amplitude) or an alias (amplitude)
27    pub file: String,
28    #[serde(default)]
29    pub settings: DataCollectionComponentSettings,
30    pub wit_version: DataCollectionWitVersion,
31    #[serde(default)]
32    pub event_filtering_rules: Vec<ComponentEventFilteringRule>,
33    #[serde(default)]
34    pub data_manipulation_rules: Vec<ComponentDataManipulationRule>,
35}
36
37#[derive(Deserialize, Debug, Clone)]
38#[serde(default)]
39pub struct DataCollectionComponentSettings {
40    pub edgee_anonymization: bool,
41    pub edgee_default_consent: String,
42    pub edgee_track_event_enabled: bool,
43    pub edgee_user_event_enabled: bool,
44    pub edgee_page_event_enabled: bool,
45    #[serde(flatten)]
46    pub additional_settings: HashMap<String, String>,
47}
48
49impl Default for DataCollectionComponentSettings {
50    fn default() -> Self {
51        DataCollectionComponentSettings {
52            edgee_anonymization: true,
53            edgee_default_consent: "pending".to_string(),
54            edgee_track_event_enabled: true,
55            edgee_user_event_enabled: true,
56            edgee_page_event_enabled: true,
57            additional_settings: HashMap::new(),
58        }
59    }
60}
61
62#[derive(Deserialize, Debug, Default, Clone)]
63pub struct EdgeFunctionComponents {
64    #[serde(skip_deserializing)]
65    pub project_component_id: String,
66    #[serde(skip_deserializing)]
67    pub slug: String,
68    pub id: String, // could be a slug (edgee/amplitude) or an alias (amplitude)
69    pub file: String,
70    pub serialized_file: Option<String>,
71    #[serde(default)]
72    pub wit_version: EdgeFunctionWitVersion,
73    #[serde(default)]
74    pub settings: HashMap<String, String>,
75}
76
77#[derive(Deserialize, Debug, Clone)]
78pub struct ComponentEventFilteringRule {
79    pub name: String,
80    pub event_types: Vec<String>,
81    pub conditions: Vec<ComponentEventFilteringRuleCondition>,
82}
83
84#[derive(Deserialize, Debug, Clone)]
85pub struct ComponentEventFilteringRuleCondition {
86    pub field: String,
87    pub operator: String,
88    pub value: String,
89}
90
91impl Default for ComponentEventFilteringRule {
92    fn default() -> Self {
93        ComponentEventFilteringRule {
94            name: "".to_string(),
95            event_types: vec![],
96            conditions: vec![],
97        }
98    }
99}
100
101#[derive(Deserialize, Debug, Clone)]
102pub struct ComponentDataManipulationRule {
103    pub name: String,
104    pub event_types: Vec<String>,
105    pub manipulations: Vec<ComponentDataManipulationRuleManipulation>,
106}
107
108#[derive(Deserialize, Debug, Clone)]
109pub struct ComponentDataManipulationRuleManipulation {
110    pub from_property: String,
111    pub to_property: String,
112    pub manipulation_type: String,
113}
114
115impl Default for ComponentDataManipulationRule {
116    fn default() -> Self {
117        ComponentDataManipulationRule {
118            name: "".to_string(),
119            event_types: vec![],
120            manipulations: vec![],
121        }
122    }
123}