diff --git a/library/src/config.rs b/library/src/config.rs index 3a1b1437..a3672d73 100644 --- a/library/src/config.rs +++ b/library/src/config.rs @@ -86,6 +86,7 @@ pub struct UpdateConfig { pub file_provider: Box, pub patch_public_key: Option, pub patch_verification: PatchVerificationMode, + pub module_version: Option, } /// Returns Ok if the config was set successfully, Err if it was already set. @@ -129,6 +130,7 @@ pub fn set_config( file_provider, patch_public_key: yaml.patch_public_key.to_owned(), patch_verification: yaml.patch_verification.unwrap_or_default(), + module_version: yaml.module_version.to_owned(), }; shorebird_debug!("Updater configured with: {:?}", new_config); *config = Some(new_config); @@ -198,6 +200,7 @@ mod tests { base_url: Some("fake_base_url".to_string()), patch_public_key: None, patch_verification: None, + module_version: None, } } @@ -223,6 +226,7 @@ mod tests { base_url: Some("fake_base_url".to_string()), patch_public_key: Some("patch_public_key".to_string()), patch_verification: None, + module_version: None, }, NetworkHooks::default(), )?; diff --git a/library/src/network.rs b/library/src/network.rs index 2248bd3d..66583f48 100644 --- a/library/src/network.rs +++ b/library/src/network.rs @@ -247,6 +247,11 @@ pub struct PatchCheckRequest { /// The unique ID of this device. This is a random UUID generated by Shorebird and _not_ the /// device's UUID or any other identifier that has meaning outside of Shorebird. pub client_id: String, + /// Module version for add-to-app releases (AAR/iOS framework). + /// When present, used instead of release_version for patch lookup. + /// The release_version still contains the host app's version for analytics. + #[serde(skip_serializing_if = "Option::is_none")] + pub module_version: Option, // We specifically do not send a patch number as part of this request because we always want to // know what the latest available patch is. } @@ -260,6 +265,7 @@ impl PatchCheckRequest { platform: current_platform().to_string(), arch: current_arch().to_string(), client_id: client_id.to_string(), + module_version: config.module_version.clone(), } } } @@ -404,6 +410,7 @@ mod tests { platform: "".to_string(), arch: "".to_string(), client_id: "".to_string(), + module_version: None, }, ); assert!(result.is_err()); diff --git a/library/src/yaml.rs b/library/src/yaml.rs index 85cc082c..581b726e 100644 --- a/library/src/yaml.rs +++ b/library/src/yaml.rs @@ -27,6 +27,9 @@ pub struct YamlConfig { pub patch_public_key: Option, /// When to verify patch signatures. Defaults to "strict" (verify at boot time). pub patch_verification: Option, + /// Module version for add-to-app releases (AAR/iOS framework). + /// When present, used instead of release_version for patch lookup. + pub module_version: Option, } impl YamlConfig { @@ -42,6 +45,7 @@ impl YamlConfig { let mut auto_update: Option = None; let mut patch_public_key: Option = None; let mut patch_verification: Option = None; + let mut module_version: Option = None; for line in yaml.lines() { let line = line.trim(); @@ -75,6 +79,7 @@ impl YamlConfig { } }); } + "module_version" => module_version = Some(value.to_string()), _ => {} // Ignore unknown keys for forward compatibility. } } @@ -88,6 +93,7 @@ impl YamlConfig { auto_update, patch_public_key, patch_verification, + module_version, }) } } @@ -161,6 +167,7 @@ base_url: https://example.com auto_update: false patch_public_key: abc123 patch_verification: install_only +module_version: 1.2.3 "#; let config = YamlConfig::from_yaml(yaml).unwrap(); assert_eq!(config.app_id, "my_app"); @@ -172,6 +179,14 @@ patch_verification: install_only config.patch_verification, Some(PatchVerificationMode::InstallOnly) ); + assert_eq!(config.module_version.as_deref(), Some("1.2.3")); + } + + #[test] + fn module_version_defaults_to_none() { + let yaml = "app_id: test_app\n"; + let config = YamlConfig::from_yaml(yaml).unwrap(); + assert_eq!(config.module_version, None); } #[test]