chore(agent): major version dependency bump (#4446)

This commit is contained in:
Shreyas
2024-10-23 21:22:19 +05:30
committed by GitHub
parent 79aefed322
commit aef11e329f
8 changed files with 901 additions and 991 deletions

View File

@@ -21,6 +21,8 @@
nodePackages_latest.vls nodePackages_latest.vls
nodePackages_latest.prisma nodePackages_latest.prisma
prisma-engines prisma-engines
# Cargo
cargo-edit
]; ];
# https://devenv.sh/basics/ # https://devenv.sh/basics/

View File

@@ -11,24 +11,24 @@
}, },
"dependencies": { "dependencies": {
"@hoppscotch/ui": "^0.2.1", "@hoppscotch/ui": "^0.2.1",
"@tauri-apps/api": ">=2.0.0-rc.0", "@tauri-apps/api": "^2.0.2",
"@tauri-apps/plugin-shell": ">=2.0.0-rc.0", "@tauri-apps/plugin-shell": "^2.0.0",
"@vueuse/core": "^11.1.0", "@vueuse/core": "^11.1.0",
"axios": "^1.7.7", "axios": "^1.7.7",
"fp-ts": "^2.16.9", "fp-ts": "^2.16.9",
"vue": "^3.3.4" "vue": "3.3.9"
}, },
"devDependencies": { "devDependencies": {
"@iconify-json/lucide": "^1.2.6", "@iconify-json/lucide": "^1.2.8",
"@tauri-apps/cli": ">=2.0.0-rc.0", "@tauri-apps/cli": "^2.0.3",
"@types/node": "^22.7.0", "@types/node": "^22.7.5",
"@vitejs/plugin-vue": "^5.1.4", "@vitejs/plugin-vue": "^5.1.4",
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.20",
"postcss": "^8.4.47", "postcss": "^8.4.47",
"tailwindcss": "^3.4.13", "tailwindcss": "^3.4.13",
"typescript": "^5.2.2", "typescript": "^5.6.3",
"unplugin-icons": "^0.19.3", "unplugin-icons": "^0.19.3",
"vite": "^5.4.7", "vite": "^5.4.8",
"vue-tsc": "^2.0.22" "vue-tsc": "^2.1.6"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -12,36 +12,36 @@ name = "hoppscotch_agent_lib"
crate-type = ["staticlib", "cdylib", "rlib"] crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies] [build-dependencies]
tauri-build = { version = "2.0.0-rc", features = [] } tauri-build = { version = "2.0.1", features = [] }
[dependencies] [dependencies]
tauri = { version = "2.0.0-rc.0", features = ["tray-icon", "image-png"] } tauri = { version = "2.0.4", features = ["tray-icon", "image-png"] }
tauri-plugin-shell = "2.0.0-rc" tauri-plugin-shell = "2.0.1"
tauri-plugin-autostart = "2.0.0-rc" tauri-plugin-autostart = "2.0.1"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
tokio = { version = "1.40.0", features = ["full"] } tokio = { version = "1.40.0", features = ["full"] }
dashmap = { version = "6.1.0", features = ["serde"] } dashmap = { version = "6.1.0", features = ["serde"] }
axum = { version = "0.7.6" } axum = { version = "0.7.7" }
axum-extra = { version = "0.9.4", features = ["typed-header"] } axum-extra = { version = "0.9.4", features = ["typed-header"] }
tower-http = { version = "0.6.1", features = ["cors"] } tower-http = { version = "0.6.1", features = ["cors"] }
tokio-util = "0.7.12" tokio-util = "0.7.12"
uuid = { version = "1.10.0", features = [ "v4", "fast-rng" ] } uuid = { version = "1.11.0", features = [ "v4", "fast-rng" ] }
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
rand = "0.8.5" rand = "0.8.5"
log = "0.4.22" log = "0.4.22"
env_logger = "0.11.5" env_logger = "0.11.5"
curl = { version = "0.4.46", features = ["ntlm", "static-curl", "static-ssl"] } curl = { version = "0.4.47", features = ["ntlm", "static-curl", "static-ssl"] }
openssl = { version = "0.10.66", features = ["vendored"] } openssl = { version = "0.10.68", features = ["vendored"] }
openssl-sys = { version = "0.9.103", features = ["vendored"] } openssl-sys = { version = "0.9.104", features = ["vendored"] }
url-escape = "0.1.1" url-escape = "0.1.1"
thiserror = "1.0.64" thiserror = "1.0.64"
tauri-plugin-store = "2.0.0-rc.3" tauri-plugin-store = "2.0.1"
x25519-dalek = { version = "2.0.1", features = ["getrandom"] } x25519-dalek = { version = "2.0.1", features = ["getrandom"] }
base16 = "0.2.1" base16 = "0.2.1"
aes-gcm = { version = "0.10.3", features = ["aes"] } aes-gcm = { version = "0.10.3", features = ["aes"] }
tauri-plugin-updater = "2.0.0-rc.3" tauri-plugin-updater = "2.0.2"
tauri-plugin-dialog = "2.0.0-rc.7" tauri-plugin-dialog = "2.0.1"
http = "1.1.0" http = "1.1.0"
lazy_static = "1.5.0" lazy_static = "1.5.0"

View File

@@ -40,6 +40,8 @@ pub enum AppError {
RegistrationInsertError, RegistrationInsertError,
#[error("Failed to save registrations to store")] #[error("Failed to save registrations to store")]
RegistrationSaveError, RegistrationSaveError,
#[error("Store error: {0}")]
TauriPluginStore(#[from] tauri_plugin_store::Error),
} }
impl IntoResponse for AppError { impl IntoResponse for AppError {

View File

@@ -4,20 +4,20 @@ use chrono::{DateTime, Utc};
use dashmap::DashMap; use dashmap::DashMap;
use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tauri_plugin_store::StoreBuilder; use tauri_plugin_store::StoreBuilder;
use tokio_util::sync::CancellationToken;
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tokio_util::sync::CancellationToken;
use crate::error::AppError; use crate::error::AppError;
/// Describes one registered app instance /// Describes one registered app instance
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Registration { pub struct Registration {
pub registered_at: DateTime<Utc>, pub registered_at: DateTime<Utc>,
/// base16 (lowercase) encoded shared secret that the client /// base16 (lowercase) encoded shared secret that the client
/// and agent established during registration that is used /// and agent established during registration that is used
/// to encrypt traffic between them /// to encrypt traffic between them
pub shared_secret_b16: String pub shared_secret_b16: String,
} }
#[derive(Default)] #[derive(Default)]
@@ -30,28 +30,26 @@ pub struct AppState {
/// Registrations against the agent, the key is the auth /// Registrations against the agent, the key is the auth
/// token associated to the registration /// token associated to the registration
registrations: DashMap<String, Registration> registrations: DashMap<String, Registration>,
} }
impl AppState { impl AppState {
pub fn new(app_handle: tauri::AppHandle) -> Self { pub fn new(app_handle: tauri::AppHandle) -> Self {
let mut store = StoreBuilder::new("app_data.bin") let store = StoreBuilder::new(&app_handle, "app_data.bin").build();
.build(app_handle);
let _ = store.load(); let _ = store.load();
// Try loading and parsing registrations from the store, if that failed, // Try loading and parsing registrations from the store, if that failed,
// load the default list // load the default list
let registrations = store.get("registrations") let registrations = store
.and_then(|val| serde_json::from_value(val.clone()).ok()) .get("registrations")
.unwrap_or_else(|| DashMap::new()); .and_then(|val| serde_json::from_value(val.clone()).ok())
.unwrap_or_else(|| DashMap::new());
Self { Self {
active_registration_code: RwLock::new(None), active_registration_code: RwLock::new(None),
cancellation_tokens: DashMap::new(), cancellation_tokens: DashMap::new(),
registrations registrations,
} }
} }
@@ -60,39 +58,41 @@ impl AppState {
/// reference, you shouldn't do it for registrations as `update_registrations` /// reference, you shouldn't do it for registrations as `update_registrations`
/// performs save operation that needs to be done and should be used instead /// performs save operation that needs to be done and should be used instead
pub fn get_registrations(&self) -> &DashMap<String, Registration> { pub fn get_registrations(&self) -> &DashMap<String, Registration> {
&self.registrations &self.registrations
} }
/// Provides you an opportunity to update the registrations list /// Provides you an opportunity to update the registrations list
/// and also persists the data to the disk /// and also persists the data to the disk
pub fn update_registrations( pub fn update_registrations(
&self, &self,
app_handle: tauri::AppHandle, app_handle: tauri::AppHandle,
update_func: impl FnOnce(&DashMap<String, Registration>) update_func: impl FnOnce(&DashMap<String, Registration>),
) -> Result<(), AppError> { ) -> Result<(), AppError> {
update_func(&self.registrations); update_func(&self.registrations);
let mut store = StoreBuilder::new("app_data.bin") let store = StoreBuilder::new(&app_handle, "app_data.bin").build();
.build(app_handle);
let _ = store.load(); let _ = store.load()?;
store.delete("registrations") let _ = store
.map_err(|_| AppError::RegistrationClearError)?; .delete("registrations")
.then_some(())
.ok_or(AppError::RegistrationClearError)?;
store.insert("registrations".into(), serde_json::to_value(self.registrations.clone()).unwrap()) let _ = store.set(
.map_err(|_| AppError::RegistrationInsertError)?; "registrations",
serde_json::to_value(self.registrations.clone()).unwrap(),
);
store.save() store.save().map_err(|_| AppError::RegistrationSaveError)?;
.map_err(|_| AppError::RegistrationSaveError)?;
Ok(()) Ok(())
} }
pub async fn validate_registration(&self, registration: &str) -> bool { pub async fn validate_registration(&self, registration: &str) -> bool {
match *self.active_registration_code.read().await { match *self.active_registration_code.read().await {
Some(ref code) => code == registration, Some(ref code) => code == registration,
None => false None => false,
} }
} }
@@ -105,50 +105,40 @@ impl AppState {
} }
pub fn validate_access(&self, auth_key: &str) -> bool { pub fn validate_access(&self, auth_key: &str) -> bool {
self.registrations.get(auth_key).is_some() self.registrations.get(auth_key).is_some()
} }
pub fn validate_access_and_get_data<T>( pub fn validate_access_and_get_data<T>(
&self, &self,
auth_key: &str, auth_key: &str,
nonce: &str, nonce: &str,
data: &Bytes data: &Bytes,
) -> Option<T> ) -> Option<T>
where where
T : DeserializeOwned T: DeserializeOwned,
{ {
if let Some(registration) = self.registrations.get(auth_key) { if let Some(registration) = self.registrations.get(auth_key) {
let key: [u8; 32] = base16::decode(&registration.shared_secret_b16) let key: [u8; 32] = base16::decode(&registration.shared_secret_b16).ok()?[0..32]
.ok()? .try_into()
[0..32] .ok()?;
.try_into()
.ok()?;
let nonce: [u8; 12] = base16::decode(nonce) let nonce: [u8; 12] = base16::decode(nonce).ok()?[0..12].try_into().ok()?;
.ok()?
[0..12]
.try_into()
.ok()?;
let cipher = Aes256Gcm::new(&key.into()); let cipher = Aes256Gcm::new(&key.into());
let data = data let data = data.iter().cloned().collect::<Vec<u8>>();
.iter()
.cloned()
.collect::<Vec<u8>>();
let plain_data = cipher.decrypt(&nonce.into(), data.as_slice()) let plain_data = cipher.decrypt(&nonce.into(), data.as_slice()).ok()?;
.ok()?;
serde_json::from_reader(plain_data.as_slice()) serde_json::from_reader(plain_data.as_slice()).ok()
.ok() } else {
} else { None
None }
}
} }
pub fn get_registration_info(&self, auth_key: &str) -> Option<Registration> { pub fn get_registration_info(&self, auth_key: &str) -> Option<Registration> {
self.registrations.get(auth_key) self.registrations
.map(|reference| reference.value().clone()) .get(auth_key)
.map(|reference| reference.value().clone())
} }
} }

View File

@@ -1,34 +1,39 @@
#[cfg(desktop)] #[cfg(desktop)]
pub async fn check_and_install_updates(app: tauri::AppHandle, updater: tauri_plugin_updater::Updater) { pub async fn check_and_install_updates(
use tauri::Manager; app: tauri::AppHandle,
use tauri_plugin_dialog::MessageDialogKind; updater: tauri_plugin_updater::Updater,
use tauri_plugin_dialog::DialogExt; ) {
use tauri::Manager;
use tauri_plugin_dialog::DialogExt;
use tauri_plugin_dialog::MessageDialogButtons;
use tauri_plugin_dialog::MessageDialogKind;
let update = updater.check().await;
let update = updater.check().await; if let Ok(Some(update)) = update {
let do_update = app
.dialog()
.message(format!(
"Update to {} is available!{}",
update.version,
update
.body
.clone()
.map(|body| format!("\n\nRelease Notes: {}", body))
.unwrap_or("".into())
))
.title("Update Available")
.kind(MessageDialogKind::Info)
.buttons(MessageDialogButtons::OkCancelCustom(
"Update".to_string(),
"Cancel".to_string(),
))
.blocking_show();
if let Ok(Some(update)) = update { if do_update {
let do_update = app.dialog() let _ = update.download_and_install(|_, _| {}, || {}).await;
.message(
format!(
"Update to {} is available!{}",
update.version,
update.body
.clone()
.map(|body| format!("\n\nRelease Notes: {}", body))
.unwrap_or("".into())
)
)
.title("Update Available")
.kind(MessageDialogKind::Info)
.ok_button_label("Update")
.cancel_button_label("Cancel")
.blocking_show();
if do_update { tauri::process::restart(&app.env());
let _ = update.download_and_install(|_, _| {}, || {}).await; }
}
tauri::process::restart(&app.env());
}
}
} }

838
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff