From 562caa63f086899c86300a44eb1a998c0094f5fc Mon Sep 17 00:00:00 2001 From: Sacha Morard <2254275+SachaMorard@users.noreply.github.com> Date: Thu, 23 Jan 2025 04:42:06 +0100 Subject: [PATCH 1/2] feat: new wit and fix tests --- src/lib.rs | 80 +++++++++---------- src/piano_payload.rs | 2 +- wit/deps.lock | 6 +- wit/deps.toml | 2 +- wit/deps/protocols/consent-mapping.wit | 13 +++ .../{protocols.wit => data-collection.wit} | 8 +- wit/world.wit | 6 +- 7 files changed, 65 insertions(+), 52 deletions(-) create mode 100644 wit/deps/protocols/consent-mapping.wit rename wit/deps/protocols/{protocols.wit => data-collection.wit} (97%) diff --git a/src/lib.rs b/src/lib.rs index 5d94f7b..766275c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +1,15 @@ mod piano_payload; use crate::piano_payload::parse_value; -use exports::edgee::protocols::provider::Data; -use exports::edgee::protocols::provider::Dict; -use exports::edgee::protocols::provider::EdgeeRequest; -use exports::edgee::protocols::provider::Event; -use exports::edgee::protocols::provider::Guest; +use exports::edgee::protocols::data_collection::Data; +use exports::edgee::protocols::data_collection::Dict; +use exports::edgee::protocols::data_collection::EdgeeRequest; +use exports::edgee::protocols::data_collection::Event; +use exports::edgee::protocols::data_collection::Guest; use piano_payload::PianoEvent; use piano_payload::PianoPayload; use std::vec; -wit_bindgen::generate!({world: "data-collection", path: "wit", with: { "edgee:protocols/provider": generate }}); +wit_bindgen::generate!({world: "edgee", path: "wit", with: { "edgee:protocols/data-collection": generate }}); export!(PianoComponent); @@ -103,7 +103,7 @@ fn build_edgee_request(piano_payload: PianoPayload) -> EdgeeRequest { headers.push((String::from("content-type"), String::from("text/plain"))); EdgeeRequest { - method: exports::edgee::protocols::provider::HttpMethod::Post, + method: exports::edgee::protocols::data_collection::HttpMethod::Post, url: format!( "https://{}/event?s={}&idclient={}", piano_payload.collection_domain, piano_payload.site_id, piano_payload.id_client @@ -116,24 +116,24 @@ fn build_edgee_request(piano_payload: PianoPayload) -> EdgeeRequest { #[cfg(test)] mod tests { use super::*; - use crate::exports::edgee::protocols::provider::{ + use crate::exports::edgee::protocols::data_collection::{ Campaign, Client, Context, EventType, HttpMethod, PageData, Session, TrackData, UserData, }; - use exports::edgee::protocols::provider::Consent; + use exports::edgee::protocols::data_collection::Consent; use pretty_assertions::assert_eq; use uuid::Uuid; fn sample_user_data(edgee_id: String) -> UserData { - return UserData { + UserData { user_id: "123".to_string(), anonymous_id: "456".to_string(), - edgee_id: edgee_id, + edgee_id, properties: vec![ ("prop1".to_string(), "value1".to_string()), ("prop2".to_string(), "10".to_string()), ("user_category".to_string(), "whatever".to_string()), ], - }; + } } fn sample_context( @@ -142,14 +142,14 @@ mod tests { timezone: String, session_start: bool, ) -> Context { - return Context { + Context { page: sample_page_data(), user: sample_user_data(edgee_id), client: Client { city: "Paris".to_string(), ip: "192.168.0.1".to_string(), - locale: locale, - timezone: timezone, + locale, + timezone, user_agent: "Chrome".to_string(), user_agent_architecture: "fuck knows".to_string(), user_agent_bitness: "64".to_string(), @@ -180,15 +180,15 @@ mod tests { session_id: "random".to_string(), previous_session_id: "random".to_string(), session_count: 2, - session_start: session_start, + session_start, first_seen: 123, last_seen: 123, }, - }; + } } fn sample_page_data() -> PageData { - return PageData { + PageData { name: "page name".to_string(), category: "category".to_string(), keywords: vec!["value1".to_string(), "value2".into()], @@ -203,7 +203,7 @@ mod tests { ("prop2".to_string(), "10".to_string()), ("has_access".to_string(), "true".to_string()), ], - }; + } } fn sample_page_event( @@ -213,7 +213,7 @@ mod tests { timezone: String, session_start: bool, ) -> Event { - return Event { + Event { uuid: Uuid::new_v4().to_string(), timestamp: 123, timestamp_millis: 123, @@ -221,19 +221,19 @@ mod tests { event_type: EventType::Page, data: Data::Page(sample_page_data()), context: sample_context(edgee_id, locale, timezone, session_start), - consent: consent, - }; + consent, + } } fn sample_track_data(event_name: String) -> TrackData { - return TrackData { + TrackData { name: event_name, products: vec![], // why is this mandatory? properties: vec![ ("prop1".to_string(), "value1".to_string()), ("prop2".to_string(), "10".to_string()), ], - }; + } } fn sample_track_event( @@ -244,7 +244,7 @@ mod tests { timezone: String, session_start: bool, ) -> Event { - return Event { + Event { uuid: Uuid::new_v4().to_string(), timestamp: 123, timestamp_millis: 123, @@ -252,8 +252,8 @@ mod tests { event_type: EventType::Track, data: Data::Track(sample_track_data(event_name)), context: sample_context(edgee_id, locale, timezone, session_start), - consent: consent, - }; + consent, + } } fn sample_user_event( @@ -263,7 +263,7 @@ mod tests { timezone: String, session_start: bool, ) -> Event { - return Event { + Event { uuid: Uuid::new_v4().to_string(), timestamp: 123, timestamp_millis: 123, @@ -271,22 +271,22 @@ mod tests { event_type: EventType::User, data: Data::User(sample_user_data(edgee_id.clone())), context: sample_context(edgee_id, locale, timezone, session_start), - consent: consent, - }; + consent, + } } fn sample_collection_domain() -> String { - return "ABCDEFG.pa-cd.com".to_string(); + "ABCDEFG.pa-cd.com".to_string() } fn sample_credentials() -> Vec<(String, String)> { - return vec![ + vec![ ("piano_site_id".to_string(), "abc".to_string()), ( "piano_collection_domain".to_string(), sample_collection_domain(), ), - ]; + ] } #[test] @@ -304,7 +304,7 @@ mod tests { assert_eq!(result.is_err(), false); let edgee_request = result.unwrap(); assert_eq!(edgee_request.method, HttpMethod::Post); - assert_eq!(edgee_request.body.len() > 0, true); + assert!(!edgee_request.body.is_empty()); assert_eq!( edgee_request .url @@ -329,7 +329,7 @@ mod tests { assert_eq!(result.is_err(), false); let edgee_request = result.unwrap(); assert_eq!(edgee_request.method, HttpMethod::Post); - assert_eq!(edgee_request.body.len() > 0, true); + assert!(!edgee_request.body.is_empty()); } #[test] @@ -347,7 +347,7 @@ mod tests { assert_eq!(result.is_err(), false); let edgee_request = result.unwrap(); assert_eq!(edgee_request.method, HttpMethod::Post); - assert_eq!(edgee_request.body.len() > 0, true); + assert!(!edgee_request.body.is_empty()); } #[test] @@ -366,7 +366,7 @@ mod tests { assert_eq!(result.is_err(), false); let edgee_request = result.unwrap(); assert_eq!(edgee_request.method, HttpMethod::Post); - assert_eq!(edgee_request.body.len() > 0, true); + assert!(!edgee_request.body.is_empty()); } #[test] @@ -385,7 +385,7 @@ mod tests { assert_eq!(result.is_err(), false); let edgee_request = result.unwrap(); assert_eq!(edgee_request.method, HttpMethod::Post); - assert_eq!(edgee_request.body.len() > 0, true); + assert!(!edgee_request.body.is_empty()); } #[test] @@ -403,7 +403,7 @@ mod tests { assert_eq!(result.is_err(), false); let edgee_request = result.unwrap(); assert_eq!(edgee_request.method, HttpMethod::Post); - assert_eq!(edgee_request.body.len() > 0, true); + assert!(!edgee_request.body.is_empty()); } #[test] @@ -451,7 +451,7 @@ mod tests { assert_eq!(result.clone().is_err(), false); let edgee_request = result.unwrap(); assert_eq!(edgee_request.method, HttpMethod::Post); - assert_eq!(edgee_request.body.len() > 0, true); + assert!(!edgee_request.body.is_empty()); } #[test] diff --git a/src/piano_payload.rs b/src/piano_payload.rs index a306ed3..d2065a3 100644 --- a/src/piano_payload.rs +++ b/src/piano_payload.rs @@ -4,7 +4,7 @@ use serde::Serialize; use std::collections::HashMap; use std::str::FromStr; -use crate::exports::edgee::protocols::provider::{Consent, Dict, Event}; +use crate::exports::edgee::protocols::data_collection::{Consent, Dict, Event}; #[derive(Serialize, Debug, Default)] pub(crate) struct PianoPayload { #[serde(skip)] diff --git a/wit/deps.lock b/wit/deps.lock index 16908de..00362de 100644 --- a/wit/deps.lock +++ b/wit/deps.lock @@ -1,4 +1,4 @@ [protocols] -url = "https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.4.tar.gz" -sha256 = "9085b0ef016f6c1135e7175fe44db4f9694ce94c8cb9dd0e4b45b330610e4abb" -sha512 = "f06230b4471cb4c09b7a31830e0b1f77e58eba56fe7e6d1c764cbba7193cfc1f7396b520afa1d3a8961f86da3643bca37adca6b81fb5cdf92212a41a54fd5275" +url = "https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.3.0.tar.gz" +sha256 = "4d412367fff6f826280acbe95f7067e362d9299d76e60994981e7e27c74d1576" +sha512 = "65021cace5ed07990fdfb563699accb975a31cb22311739ff6189849b969b06b564a0f8f72de154fd086ba474757d3cffaef0175778e4989c467280cf1c86284" diff --git a/wit/deps.toml b/wit/deps.toml index 3d22e76..58ac5e6 100644 --- a/wit/deps.toml +++ b/wit/deps.toml @@ -1 +1 @@ -protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.4.tar.gz" \ No newline at end of file +protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.3.0.tar.gz" \ No newline at end of file diff --git a/wit/deps/protocols/consent-mapping.wit b/wit/deps/protocols/consent-mapping.wit new file mode 100644 index 0000000..23fbc2e --- /dev/null +++ b/wit/deps/protocols/consent-mapping.wit @@ -0,0 +1,13 @@ +package edgee:protocols; + +interface consent-mapping { + type config = list>; + + enum consent { + pending, + granted, + denied, + } + + map: func(cookie: string, config: config) -> option; +} \ No newline at end of file diff --git a/wit/deps/protocols/protocols.wit b/wit/deps/protocols/data-collection.wit similarity index 97% rename from wit/deps/protocols/protocols.wit rename to wit/deps/protocols/data-collection.wit index aaac806..d689514 100644 --- a/wit/deps/protocols/protocols.wit +++ b/wit/deps/protocols/data-collection.wit @@ -1,6 +1,7 @@ package edgee:protocols; -interface provider { -type dict = list>; + +interface data-collection { + type dict = list>; enum event-type { page, track, user } enum consent { pending, granted, denied } @@ -109,5 +110,4 @@ type dict = list>; page: func(e: event, cred: dict) -> result; track: func(e: event, cred: dict) -> result; user: func(e: event, cred:dict) -> result; -} - +} \ No newline at end of file diff --git a/wit/world.wit b/wit/world.wit index 561744e..e41080b 100644 --- a/wit/world.wit +++ b/wit/world.wit @@ -1,5 +1,5 @@ -package edgee:pianocomponent; +package edgee:native; -world data-collection { - export edgee:protocols/provider; +world edgee { + export edgee:protocols/data-collection; } \ No newline at end of file From e776d4b68a77150395cd55c917404edecaa1f5a0 Mon Sep 17 00:00:00 2001 From: Sacha Morard <2254275+SachaMorard@users.noreply.github.com> Date: Thu, 23 Jan 2025 06:59:08 +0100 Subject: [PATCH 2/2] fix: data-collection world --- src/lib.rs | 2 +- wit/world.wit | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 766275c..615d90b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ use exports::edgee::protocols::data_collection::Guest; use piano_payload::PianoEvent; use piano_payload::PianoPayload; use std::vec; -wit_bindgen::generate!({world: "edgee", path: "wit", with: { "edgee:protocols/data-collection": generate }}); +wit_bindgen::generate!({world: "data-collection", path: "wit", generate_all}); export!(PianoComponent); diff --git a/wit/world.wit b/wit/world.wit index e41080b..4a03eeb 100644 --- a/wit/world.wit +++ b/wit/world.wit @@ -1,5 +1,5 @@ package edgee:native; -world edgee { +world data-collection { export edgee:protocols/data-collection; } \ No newline at end of file