mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-29 03:32:43 +01:00
Merge main into feat/request-versioning
Conflicts were all at registration points; both sides are kept. Main now routes every write through one connection (#642): ClientDb only reads and writes go through `with_tx` on a WriteDb. Versioning follows: snapshot, restore, prune and the cascade delete move to WriteDb, while the lookups and the "has it changed" check stay on ClientDb. Callers take a write transaction the way their neighbours do: - The HTTP send snapshots in its own transaction from `resolve_send_inputs`, and a failure there (including not getting the writer) is still logged and swallowed, so the response just has no version. - gRPC and WebSocket connect snapshot inside the transaction that upserts the connection. - The snapshot and restore RPCs, on the desktop and in the browser host, each run in a transaction. - The request and workspace cascades live on main's WriteDb deletes. The Request Changed dropdown moves into the response pane's `statusLineRight` slot, since main moved the status line into the shared pane view. The plugin runtime's copy of the model bindings picks up `versionId`, and `gen_rpc.ts` is regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
1b0a196c50
794 files changed
+76953
-18061
No files matched your search
@@ -5,26 +5,26 @@ edition = "2024"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.22.1"
|
||||
base64 = "0.23.1"
|
||||
chrono = { workspace = true }
|
||||
dunce = "1.0.4"
|
||||
futures-util = "0.3.30"
|
||||
hex = { workspace = true }
|
||||
keyring = { workspace = true, features = ["apple-native", "windows-native", "sync-secret-service"] }
|
||||
log = { workspace = true }
|
||||
md5 = "0.7.0"
|
||||
md5 = "0.8.0"
|
||||
path-slash = "0.2.1"
|
||||
rand = "0.9.0"
|
||||
rand = "0.10.2"
|
||||
reqwest = { workspace = true, features = ["json"] }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
sha2 = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "process", "fs"] }
|
||||
tokio-tungstenite = "0.26.1"
|
||||
tokio-tungstenite = "0.30.0"
|
||||
ts-rs = { workspace = true }
|
||||
yaak-common = { workspace = true }
|
||||
yaak-crypto = { workspace = true }
|
||||
yaak-models = { workspace = true }
|
||||
yaak-templates = { workspace = true }
|
||||
zip-extract = "0.4.0"
|
||||
zip = "9.0.5"
|
||||
+24
-3
@@ -84,10 +84,17 @@ export type FileFilter = { name: string,
|
||||
*/
|
||||
extensions: Array<string>, };
|
||||
|
||||
export type FilterLanguage = "jsonpath" | "xpath";
|
||||
|
||||
export type FilterRequest = { content: string, filter: string, };
|
||||
|
||||
export type FilterResponse = { content: string, error?: string, };
|
||||
|
||||
/**
|
||||
* A plugin asking the host to run a JSONPath or XPath query over some text.
|
||||
*/
|
||||
export type FilterTextRequest = { language: FilterLanguage, text: string, query: string, };
|
||||
|
||||
export type FindHttpResponsesRequest = { requestId: string, limit?: number, };
|
||||
|
||||
export type FindHttpResponsesResponse = { httpResponses: Array<HttpResponse>, };
|
||||
@@ -470,7 +477,16 @@ export type HttpRequestAction = { label: string, icon?: Icon, };
|
||||
|
||||
export type Icon = "alert_triangle" | "check" | "check_circle" | "chevron_down" | "copy" | "info" | "pin" | "search" | "trash" | "_unknown";
|
||||
|
||||
export type ImportRequest = { content: string, };
|
||||
/**
|
||||
* Transport descriptor; plugins see a scoped ImportFiles API, not this representation.
|
||||
*/
|
||||
export type ImportFileSource = { "type": "file", name: string, base64: string, } | { "type": "directory", path: string, };
|
||||
|
||||
export type ImportRequest = {
|
||||
/**
|
||||
* Kept for text-only importers and older runtimes.
|
||||
*/
|
||||
content: string, source?: ImportFileSource, };
|
||||
|
||||
export type ImportResources = { workspaces: Array<Workspace>, environments: Array<Environment>, folders: Array<Folder>, httpRequests: Array<HttpRequest>, grpcRequests: Array<GrpcRequest>, websocketRequests: Array<WebsocketRequest>, };
|
||||
|
||||
@@ -489,7 +505,7 @@ sourceKeys?: { [key in string]?: string }, };
|
||||
|
||||
export type InternalEvent = { id: string, pluginRefId: string, pluginName: string, replyId: string | null, context: PluginContext, payload: InternalEventPayload, };
|
||||
|
||||
export type InternalEventPayload = { "type": "boot_request" } & BootRequest | { "type": "boot_response" } | { "type": "reload_response" } & ReloadResponse | { "type": "terminate_request" } | { "type": "terminate_response" } | { "type": "import_request" } & ImportRequest | { "type": "import_response" } & ImportResponse | { "type": "filter_request" } & FilterRequest | { "type": "filter_response" } & FilterResponse | { "type": "export_http_request_request" } & ExportHttpRequestRequest | { "type": "export_http_request_response" } & ExportHttpRequestResponse | { "type": "send_http_request_request" } & SendHttpRequestRequest | { "type": "send_http_request_response" } & SendHttpRequestResponse | { "type": "list_cookie_names_request" } & ListCookieNamesRequest | { "type": "list_cookie_names_response" } & ListCookieNamesResponse | { "type": "get_cookie_value_request" } & GetCookieValueRequest | { "type": "get_cookie_value_response" } & GetCookieValueResponse | { "type": "get_http_request_actions_request" } & EmptyPayload | { "type": "get_http_request_actions_response" } & GetHttpRequestActionsResponse | { "type": "call_http_request_action_request" } & CallHttpRequestActionRequest | { "type": "get_websocket_request_actions_request" } & EmptyPayload | { "type": "get_websocket_request_actions_response" } & GetWebsocketRequestActionsResponse | { "type": "call_websocket_request_action_request" } & CallWebsocketRequestActionRequest | { "type": "get_workspace_actions_request" } & EmptyPayload | { "type": "get_workspace_actions_response" } & GetWorkspaceActionsResponse | { "type": "call_workspace_action_request" } & CallWorkspaceActionRequest | { "type": "get_folder_actions_request" } & EmptyPayload | { "type": "get_folder_actions_response" } & GetFolderActionsResponse | { "type": "call_folder_action_request" } & CallFolderActionRequest | { "type": "get_grpc_request_actions_request" } & EmptyPayload | { "type": "get_grpc_request_actions_response" } & GetGrpcRequestActionsResponse | { "type": "call_grpc_request_action_request" } & CallGrpcRequestActionRequest | { "type": "get_template_function_summary_request" } & EmptyPayload | { "type": "get_template_function_summary_response" } & GetTemplateFunctionSummaryResponse | { "type": "get_template_function_config_request" } & GetTemplateFunctionConfigRequest | { "type": "get_template_function_config_response" } & GetTemplateFunctionConfigResponse | { "type": "call_template_function_request" } & CallTemplateFunctionRequest | { "type": "call_template_function_response" } & CallTemplateFunctionResponse | { "type": "get_http_authentication_summary_request" } & EmptyPayload | { "type": "get_http_authentication_summary_response" } & GetHttpAuthenticationSummaryResponse | { "type": "get_http_authentication_config_request" } & GetHttpAuthenticationConfigRequest | { "type": "get_http_authentication_config_response" } & GetHttpAuthenticationConfigResponse | { "type": "call_http_authentication_request" } & CallHttpAuthenticationRequest | { "type": "call_http_authentication_response" } & CallHttpAuthenticationResponse | { "type": "call_http_authentication_action_request" } & CallHttpAuthenticationActionRequest | { "type": "call_http_authentication_action_response" } & EmptyPayload | { "type": "copy_text_request" } & CopyTextRequest | { "type": "copy_text_response" } & EmptyPayload | { "type": "render_http_request_request" } & RenderHttpRequestRequest | { "type": "render_http_request_response" } & RenderHttpRequestResponse | { "type": "render_grpc_request_request" } & RenderGrpcRequestRequest | { "type": "render_grpc_request_response" } & RenderGrpcRequestResponse | { "type": "template_render_request" } & TemplateRenderRequest | { "type": "template_render_response" } & TemplateRenderResponse | { "type": "get_key_value_request" } & GetKeyValueRequest | { "type": "get_key_value_response" } & GetKeyValueResponse | { "type": "set_key_value_request" } & SetKeyValueRequest | { "type": "set_key_value_response" } & SetKeyValueResponse | { "type": "delete_key_value_request" } & DeleteKeyValueRequest | { "type": "delete_key_value_response" } & DeleteKeyValueResponse | { "type": "open_window_request" } & OpenWindowRequest | { "type": "window_navigate_event" } & WindowNavigateEvent | { "type": "window_close_event" } | { "type": "close_window_request" } & CloseWindowRequest | { "type": "open_external_url_request" } & OpenExternalUrlRequest | { "type": "open_external_url_response" } & EmptyPayload | { "type": "show_toast_request" } & ShowToastRequest | { "type": "show_toast_response" } & EmptyPayload | { "type": "prompt_text_request" } & PromptTextRequest | { "type": "prompt_text_response" } & PromptTextResponse | { "type": "prompt_form_request" } & PromptFormRequest | { "type": "prompt_form_response" } & PromptFormResponse | { "type": "window_info_request" } & WindowInfoRequest | { "type": "window_info_response" } & WindowInfoResponse | { "type": "list_open_workspaces_request" } & ListOpenWorkspacesRequeLine truncated
|
||||
export type InternalEventPayload = { "type": "boot_request" } & BootRequest | { "type": "boot_response" } | { "type": "reload_response" } & ReloadResponse | { "type": "terminate_request" } | { "type": "terminate_response" } | { "type": "import_request" } & ImportRequest | { "type": "import_response" } & ImportResponse | { "type": "filter_request" } & FilterRequest | { "type": "filter_response" } & FilterResponse | { "type": "filter_text_request" } & FilterTextRequest | { "type": "filter_text_response" } & FilterResponse | { "type": "export_http_request_request" } & ExportHttpRequestRequest | { "type": "export_http_request_response" } & ExportHttpRequestResponse | { "type": "send_http_request_request" } & SendHttpRequestRequest | { "type": "send_http_request_response" } & SendHttpRequestResponse | { "type": "list_cookie_names_request" } & ListCookieNamesRequest | { "type": "list_cookie_names_response" } & ListCookieNamesResponse | { "type": "get_cookie_value_request" } & GetCookieValueRequest | { "type": "get_cookie_value_response" } & GetCookieValueResponse | { "type": "get_http_request_actions_request" } & EmptyPayload | { "type": "get_http_request_actions_response" } & GetHttpRequestActionsResponse | { "type": "call_http_request_action_request" } & CallHttpRequestActionRequest | { "type": "get_websocket_request_actions_request" } & EmptyPayload | { "type": "get_websocket_request_actions_response" } & GetWebsocketRequestActionsResponse | { "type": "call_websocket_request_action_request" } & CallWebsocketRequestActionRequest | { "type": "get_workspace_actions_request" } & EmptyPayload | { "type": "get_workspace_actions_response" } & GetWorkspaceActionsResponse | { "type": "call_workspace_action_request" } & CallWorkspaceActionRequest | { "type": "get_folder_actions_request" } & EmptyPayload | { "type": "get_folder_actions_response" } & GetFolderActionsResponse | { "type": "call_folder_action_request" } & CallFolderActionRequest | { "type": "get_grpc_request_actions_request" } & EmptyPayload | { "type": "get_grpc_request_actions_response" } & GetGrpcRequestActionsResponse | { "type": "call_grpc_request_action_request" } & CallGrpcRequestActionRequest | { "type": "get_template_function_summary_request" } & EmptyPayload | { "type": "get_template_function_summary_response" } & GetTemplateFunctionSummaryResponse | { "type": "get_template_function_config_request" } & GetTemplateFunctionConfigRequest | { "type": "get_template_function_config_response" } & GetTemplateFunctionConfigResponse | { "type": "call_template_function_request" } & CallTemplateFunctionRequest | { "type": "call_template_function_response" } & CallTemplateFunctionResponse | { "type": "get_http_authentication_summary_request" } & EmptyPayload | { "type": "get_http_authentication_summary_response" } & GetHttpAuthenticationSummaryResponse | { "type": "get_http_authentication_config_request" } & GetHttpAuthenticationConfigRequest | { "type": "get_http_authentication_config_response" } & GetHttpAuthenticationConfigResponse | { "type": "call_http_authentication_request" } & CallHttpAuthenticationRequest | { "type": "call_http_authentication_response" } & CallHttpAuthenticationResponse | { "type": "call_http_authentication_action_request" } & CallHttpAuthenticationActionRequest | { "type": "call_http_authentication_action_response" } & EmptyPayload | { "type": "copy_text_request" } & CopyTextRequest | { "type": "copy_text_response" } & EmptyPayload | { "type": "render_http_request_request" } & RenderHttpRequestRequest | { "type": "render_http_request_response" } & RenderHttpRequestResponse | { "type": "render_grpc_request_request" } & RenderGrpcRequestRequest | { "type": "render_grpc_request_response" } & RenderGrpcRequestResponse | { "type": "template_render_request" } & TemplateRenderRequest | { "type": "template_render_response" } & TemplateRenderResponse | { "type": "get_key_value_request" } & GetKeyValueRequest | { "type": "get_key_value_response" } & GetKeyValueResponse | { "type": "set_key_value_request" } & SetKeyValueRequest | { "type": "set_key_value_response" } & SetKeyValueResponse | { "type": "delete_key_value_request" } & DeleteKeyValueRequest | { "type": "delete_key_value_response" } & DeleteKeyValueResponse | { "type": "open_window_request" } & OpenWindowRequest | { "type": "window_navigate_event" } & WindowNavigateEvent | { "type": "window_close_event" } | { "type": "close_window_request" } & CloseWindowRequest | { "type": "open_external_url_request" } & OpenExternalUrlRequest | { "type": "open_external_url_response" } & EmptyPayload | { "type": "show_toast_request" } & ShowToastRequest | { "type": "show_toast_response" } & EmptyPayload | { "type": "prompt_text_request" } & PromptTextRequest | { "type": "prompt_text_response" } & PromptTextResponse | { "type": "prompt_form_request" } & PromptFormRequest | { "type": "prompt_form_response" } & PromptFormResponse | { "type": "window_info_request" } & WindowInfoRequest | { "type": "windoLine truncated
|
||||
|
||||
export type JsonPrimitive = string | number | boolean | null;
|
||||
|
||||
@@ -572,7 +588,12 @@ export type RenderHttpRequestResponse = { httpRequest: HttpRequest, };
|
||||
|
||||
export type RenderPurpose = "send" | "preview";
|
||||
|
||||
export type SendHttpRequestRequest = { httpRequest: Partial<HttpRequest>, };
|
||||
export type SendHttpRequestRequest = { httpRequest: Partial<HttpRequest>,
|
||||
/**
|
||||
* Override the environment for this send without changing the active selection.
|
||||
* When omitted, use the host's active environment.
|
||||
*/
|
||||
environmentId?: string, };
|
||||
|
||||
export type SendHttpRequestResponse = { httpResponse: HttpResponse,
|
||||
/**
|
||||
|
||||
+1
@@ -406,6 +406,7 @@ export type Settings = {
|
||||
updateChannel: string;
|
||||
hideLicenseBadge: boolean;
|
||||
promptFeedback: boolean;
|
||||
mcpServerEnabled: boolean;
|
||||
autoupdate: boolean;
|
||||
autoDownloadUpdates: boolean;
|
||||
checkNotifications: boolean;
|
||||
|
||||
+6
-2
@@ -1,5 +1,9 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type PluginMetadata = { version: string, name: string, displayName: string, description: string | null, homepageUrl: string | null, repositoryUrl: string | null, };
|
||||
export type PluginMetadata = { version: string, name: string, displayName: string, description: string | null, homepageUrl: string | null, repositoryUrl: string | null,
|
||||
/**
|
||||
* Why the plugin should no longer be used, from `deprecated` in its package.json
|
||||
*/
|
||||
deprecated: string | null, };
|
||||
|
||||
export type PluginVersion = { id: string, version: string, url: string, description: string | null, name: string, displayName: string, homepageUrl: string | null, repositoryUrl: string | null, checksum: string, readme: string | null, yanked: boolean, };
|
||||
export type PluginVersion = { id: string, version: string, url: string, description: string | null, name: string, displayName: string, homepageUrl: string | null, repositoryUrl: string | null, checksum: string, readme: string | null, yanked: boolean, deprecated: string | null, };
|
||||
@@ -109,7 +109,10 @@ pub struct PluginVersion {
|
||||
pub repository_url: Option<String>,
|
||||
pub checksum: String,
|
||||
pub readme: Option<String>,
|
||||
#[serde(default)]
|
||||
pub yanked: bool,
|
||||
#[serde(default)]
|
||||
pub deprecated: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS, PartialEq)]
|
||||
|
||||
@@ -43,7 +43,7 @@ pub enum Error {
|
||||
PluginErr(String),
|
||||
|
||||
#[error("zip error: {0}")]
|
||||
ZipError(#[from] zip_extract::ZipExtractError),
|
||||
ZipError(#[from] zip::result::ZipError),
|
||||
|
||||
#[error("Client not initialized error")]
|
||||
ClientNotInitializedErr,
|
||||
|
||||
@@ -69,6 +69,8 @@ pub enum InternalEventPayload {
|
||||
|
||||
FilterRequest(FilterRequest),
|
||||
FilterResponse(FilterResponse),
|
||||
FilterTextRequest(FilterTextRequest),
|
||||
FilterTextResponse(FilterResponse),
|
||||
|
||||
ExportHttpRequestRequest(ExportHttpRequestRequest),
|
||||
ExportHttpRequestResponse(ExportHttpRequestResponse),
|
||||
@@ -240,7 +242,20 @@ pub struct ReloadResponse {
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
pub struct ImportRequest {
|
||||
/// Kept for text-only importers and older runtimes.
|
||||
pub content: String,
|
||||
#[ts(optional)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub source: Option<ImportFileSource>,
|
||||
}
|
||||
|
||||
/// Transport descriptor; plugins see a scoped ImportFiles API, not this representation.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
pub enum ImportFileSource {
|
||||
File { name: String, base64: String },
|
||||
Directory { path: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
@@ -273,9 +288,28 @@ pub struct FilterRequest {
|
||||
pub struct FilterResponse {
|
||||
pub content: String,
|
||||
#[ts(optional)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
/// A plugin asking the host to run a JSONPath or XPath query over some text.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
pub struct FilterTextRequest {
|
||||
pub language: FilterLanguage,
|
||||
pub text: String,
|
||||
pub query: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
pub enum FilterLanguage {
|
||||
JsonPath,
|
||||
XPath,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
@@ -296,6 +330,36 @@ pub struct ExportHttpRequestResponse {
|
||||
pub struct SendHttpRequestRequest {
|
||||
#[ts(type = "Partial<HttpRequest>")]
|
||||
pub http_request: HttpRequest,
|
||||
/// Override the environment for this send without changing the active selection.
|
||||
/// When omitted, use the host's active environment.
|
||||
#[ts(optional)]
|
||||
pub environment_id: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod send_http_request_tests {
|
||||
use super::SendHttpRequestRequest;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn environment_override_survives_the_plugin_wire_format() {
|
||||
let request: SendHttpRequestRequest = serde_json::from_value(json!({
|
||||
"httpRequest": { "id": "rq_test" }, "environmentId": "ev_staging"
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(request.environment_id.as_deref(), Some("ev_staging"));
|
||||
assert_eq!(serde_json::to_value(request).unwrap()["environmentId"], "ev_staging");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn older_plugins_can_omit_the_environment_override() {
|
||||
let request: SendHttpRequestRequest = serde_json::from_value(json!({
|
||||
"httpRequest": { "id": "rq_test" }
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(request.environment_id, None);
|
||||
assert_eq!(request.http_request.id, "rq_test");
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
use crate::events::{ImportFileSource, ImportRequest};
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::STANDARD;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, Read};
|
||||
use std::path::Path;
|
||||
|
||||
pub const MAX_IMPORT_BYTES: u64 = 64 * 1024 * 1024;
|
||||
|
||||
impl ImportRequest {
|
||||
pub fn from_text(content: &str) -> Self {
|
||||
Self { content: content.to_string(), source: None }
|
||||
}
|
||||
|
||||
pub fn from_bytes(name: &str, bytes: &[u8]) -> io::Result<Self> {
|
||||
if bytes.len() as u64 > MAX_IMPORT_BYTES {
|
||||
return Err(io::Error::other("Import file exceeds the 64 MiB limit"));
|
||||
}
|
||||
Ok(Self {
|
||||
content: std::str::from_utf8(bytes).unwrap_or_default().to_string(),
|
||||
source: Some(ImportFileSource::File {
|
||||
name: name.to_string(),
|
||||
base64: STANDARD.encode(bytes),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn from_path(path: &Path) -> io::Result<Self> {
|
||||
let path = fs::canonicalize(path)?;
|
||||
let metadata = fs::metadata(&path)?;
|
||||
if metadata.is_dir() {
|
||||
return Ok(Self {
|
||||
content: String::new(),
|
||||
source: Some(ImportFileSource::Directory {
|
||||
path: path
|
||||
.to_str()
|
||||
.ok_or_else(|| io::Error::other("Import path is not UTF-8"))?
|
||||
.to_string(),
|
||||
}),
|
||||
});
|
||||
}
|
||||
if !metadata.is_file() {
|
||||
return Err(io::Error::other("Import source must be a file or directory"));
|
||||
}
|
||||
let mut bytes = Vec::new();
|
||||
File::open(&path)?.take(MAX_IMPORT_BYTES + 1).read_to_end(&mut bytes)?;
|
||||
Self::from_bytes(path.file_name().and_then(|v| v.to_str()).unwrap_or("input"), &bytes)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn text_and_binary_inputs_preserve_bytes() {
|
||||
let input = ImportRequest::from_bytes("api.yml", "café".as_bytes()).unwrap();
|
||||
assert_eq!(input.content, "café");
|
||||
let input = ImportRequest::from_bytes("data.zip", &[0x50, 0x4b, 0xff]).unwrap();
|
||||
assert_eq!(input.content, "");
|
||||
let Some(ImportFileSource::File { name, base64 }) = input.source else {
|
||||
panic!("file input")
|
||||
};
|
||||
assert_eq!(name, "data.zip");
|
||||
assert_eq!(STANDARD.decode(base64).unwrap(), vec![0x50, 0x4b, 0xff]);
|
||||
assert!(ImportRequest::from_text("text").source.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn directory_input_is_lazy_and_canonical() {
|
||||
let input = ImportRequest::from_path(Path::new(".")).unwrap();
|
||||
let Some(ImportFileSource::Directory { path }) = input.source else {
|
||||
panic!("directory input")
|
||||
};
|
||||
assert_eq!(Path::new(&path), fs::canonicalize(".").unwrap());
|
||||
assert!(input.content.is_empty());
|
||||
assert!(ImportRequest::from_path(Path::new("does-not-exist-yaak-import")).is_err());
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,7 @@ pub async fn delete_and_uninstall(
|
||||
Some(label) => UpdateSource::from_window_label(label),
|
||||
None => UpdateSource::Background,
|
||||
};
|
||||
// Scope the db connection so it doesn't live across await
|
||||
let plugin = {
|
||||
let db = query_manager.connect();
|
||||
db.delete_plugin_by_id(plugin_id, &update_source)?
|
||||
};
|
||||
let plugin = query_manager.with_tx(|db| db.delete_plugin_by_id(plugin_id, &update_source))?;
|
||||
if let Err(err) = plugin_manager.uninstall(plugin_context, plugin.directory.as_str()).await {
|
||||
if !matches!(err, PluginNotFoundErr(_)) {
|
||||
return Err(err);
|
||||
@@ -69,12 +65,11 @@ pub async fn download_and_install(
|
||||
let _ = remove_dir_all(&plugin_dir);
|
||||
create_dir_all(&plugin_dir)?;
|
||||
|
||||
zip_extract::extract(Cursor::new(&bytes), &plugin_dir, true)?;
|
||||
zip::ZipArchive::new(Cursor::new(&bytes))?
|
||||
.extract_unwrapped_root_dir(&plugin_dir, zip::read::root_dir_common_filter)?;
|
||||
info!("Extracted plugin {} to {}", plugin_version.id, plugin_dir_str);
|
||||
|
||||
// Scope the db connection so it doesn't live across await
|
||||
let plugin = {
|
||||
let db = query_manager.connect();
|
||||
let plugin = query_manager.with_tx(|db| {
|
||||
db.upsert_plugin(
|
||||
&Plugin {
|
||||
id: plugin_version.id.clone(),
|
||||
@@ -86,8 +81,8 @@ pub async fn download_and_install(
|
||||
..Default::default()
|
||||
},
|
||||
&UpdateSource::Background,
|
||||
)?
|
||||
};
|
||||
)
|
||||
})?;
|
||||
|
||||
plugin_manager.add_plugin(plugin_context, &plugin).await?;
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ pub mod api;
|
||||
mod checksum;
|
||||
pub mod error;
|
||||
pub mod events;
|
||||
mod import_input;
|
||||
pub use import_input::MAX_IMPORT_BYTES;
|
||||
pub mod install;
|
||||
pub mod manager;
|
||||
pub mod native_template_functions;
|
||||
|
||||
@@ -9,14 +9,13 @@ use crate::events::{
|
||||
CallHttpAuthenticationRequest, CallHttpAuthenticationResponse, CallHttpRequestActionRequest,
|
||||
CallTemplateFunctionArgs, CallTemplateFunctionRequest, CallTemplateFunctionResponse,
|
||||
CallWebsocketRequestActionRequest, CallWorkspaceActionRequest, EmptyPayload, ErrorResponse,
|
||||
FilterRequest, FilterResponse, GetFolderActionsResponse, GetGrpcRequestActionsResponse,
|
||||
GetHttpAuthenticationConfigRequest, GetHttpAuthenticationConfigResponse,
|
||||
GetHttpAuthenticationSummaryResponse, GetHttpRequestActionsResponse,
|
||||
GetTemplateFunctionConfigRequest, GetTemplateFunctionConfigResponse,
|
||||
GetTemplateFunctionSummaryResponse, GetThemesRequest, GetThemesResponse,
|
||||
GetWebsocketRequestActionsResponse, GetWorkspaceActionsResponse, ImportRequest, ImportResponse,
|
||||
InternalEvent, InternalEventPayload, JsonPrimitive, PluginContext, RenderPurpose,
|
||||
ShowToastRequest,
|
||||
GetFolderActionsResponse, GetGrpcRequestActionsResponse, GetHttpAuthenticationConfigRequest,
|
||||
GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse,
|
||||
GetHttpRequestActionsResponse, GetTemplateFunctionConfigRequest,
|
||||
GetTemplateFunctionConfigResponse, GetTemplateFunctionSummaryResponse, GetThemesRequest,
|
||||
GetThemesResponse, GetWebsocketRequestActionsResponse, GetWorkspaceActionsResponse,
|
||||
ImportRequest, ImportResponse, InternalEvent, InternalEventPayload, JsonPrimitive,
|
||||
PluginContext, RenderPurpose, ShowToastRequest,
|
||||
};
|
||||
use crate::native_template_functions::{template_function_keyring, template_function_secure};
|
||||
use crate::nodejs::start_nodejs_plugin_runtime;
|
||||
@@ -187,9 +186,7 @@ impl PluginManager {
|
||||
}
|
||||
|
||||
let bundled_dirs = plugin_manager.list_bundled_plugin_dirs().await?;
|
||||
// Scope the db connection so the future stays Send across the await below
|
||||
let plugins = {
|
||||
let db = query_manager.connect();
|
||||
let plugins = query_manager.with_tx(|db| {
|
||||
for dir in &bundled_dirs {
|
||||
if db.get_plugin_by_directory(dir).is_none() {
|
||||
db.upsert_plugin(
|
||||
@@ -204,8 +201,8 @@ impl PluginManager {
|
||||
)?;
|
||||
}
|
||||
}
|
||||
db.list_plugins()?
|
||||
};
|
||||
db.list_plugins()
|
||||
})?;
|
||||
|
||||
let init_errors = plugin_manager.initialize_all_plugins(plugins, plugin_context).await;
|
||||
if !init_errors.is_empty() {
|
||||
@@ -1093,18 +1090,32 @@ impl PluginManager {
|
||||
&self,
|
||||
plugin_context: &PluginContext,
|
||||
content: &str,
|
||||
) -> Result<ImportResponse> {
|
||||
self.import_input(plugin_context, &ImportRequest::from_text(content)).await
|
||||
}
|
||||
|
||||
pub async fn import_input(
|
||||
&self,
|
||||
plugin_context: &PluginContext,
|
||||
input: &ImportRequest,
|
||||
) -> Result<ImportResponse> {
|
||||
let reply_events = self
|
||||
.send_and_wait(
|
||||
plugin_context,
|
||||
&InternalEventPayload::ImportRequest(ImportRequest {
|
||||
content: content.to_string(),
|
||||
}),
|
||||
&InternalEventPayload::ImportRequest(input.clone()),
|
||||
Duration::from_secs(60),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// TODO: Don't just return the first valid response
|
||||
let errors = reply_events
|
||||
.iter()
|
||||
.filter_map(|e| match &e.payload {
|
||||
InternalEventPayload::ErrorResponse(error) => Some(error.error.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("; ");
|
||||
let result = reply_events.into_iter().find_map(|e| match e {
|
||||
InternalEvent {
|
||||
plugin_name,
|
||||
@@ -1122,50 +1133,11 @@ impl PluginManager {
|
||||
});
|
||||
|
||||
match result {
|
||||
None => Err(PluginErr("No importers found for file contents".to_string())),
|
||||
None if !errors.is_empty() => Err(PluginErr(errors)),
|
||||
None => Err(PluginErr("No importers found for this input".to_string())),
|
||||
Some(resp) => Ok(resp),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn filter_data(
|
||||
&self,
|
||||
plugin_context: &PluginContext,
|
||||
filter: &str,
|
||||
content: &str,
|
||||
content_type: &str,
|
||||
) -> Result<FilterResponse> {
|
||||
let ct = content_type.to_lowercase();
|
||||
let plugin_name = if ct.contains("xml") || ct.contains("html") {
|
||||
"@yaak/filter-xpath"
|
||||
} else {
|
||||
"@yaak/filter-jsonpath"
|
||||
};
|
||||
|
||||
let plugin = self
|
||||
.get_plugin_by_name(plugin_name)
|
||||
.await
|
||||
.ok_or(PluginNotFoundErr(plugin_name.to_string()))?;
|
||||
|
||||
let event = self
|
||||
.send_to_plugin_and_wait(
|
||||
plugin_context,
|
||||
&plugin,
|
||||
&InternalEventPayload::FilterRequest(FilterRequest {
|
||||
filter: filter.to_string(),
|
||||
content: content.to_string(),
|
||||
}),
|
||||
Duration::from_secs(5),
|
||||
)
|
||||
.await?;
|
||||
|
||||
match event.payload {
|
||||
InternalEventPayload::FilterResponse(resp) => Ok(resp),
|
||||
InternalEventPayload::EmptyResponse(_) => {
|
||||
Err(PluginErr("Filter returned empty".to_string()))
|
||||
}
|
||||
e => Err(PluginErr(format!("Export returned invalid event {:?}", e))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn source_priority(source: &PluginSource) -> i32 {
|
||||
@@ -1194,8 +1166,9 @@ fn prefer_plugin(candidate: &Plugin, existing: &Plugin) -> bool {
|
||||
/// whose directory isn't in this list are filtered out by `resolve_plugins_for_runtime`.
|
||||
///
|
||||
/// `exporter-curl` was renamed to `action-copy-curl` in 19ffcd18, which is why affected
|
||||
/// installs show "Copy as cURL" twice.
|
||||
const REMOVED_BUNDLED_PLUGIN_DIRS: &[&str] = &["exporter-curl"];
|
||||
/// installs show "Copy as cURL" twice. `filter-jsonpath` and `filter-xpath` moved into
|
||||
/// the `yaak-filter` crate.
|
||||
const REMOVED_BUNDLED_PLUGIN_DIRS: &[&str] = &["exporter-curl", "filter-jsonpath", "filter-xpath"];
|
||||
|
||||
/// Whether a plugin directory path is one of the known-removed bundled plugins.
|
||||
fn is_removed_bundled_plugin_dir(dir: &str) -> bool {
|
||||
@@ -1243,6 +1216,8 @@ mod tests {
|
||||
r"C:\Users\me\AppData\Local\Yaak\vendored\plugins\exporter-curl"
|
||||
));
|
||||
assert!(is_removed_bundled_plugin_dir("vendored/plugins/exporter-curl/"));
|
||||
assert!(is_removed_bundled_plugin_dir("vendored/plugins/filter-jsonpath"));
|
||||
assert!(is_removed_bundled_plugin_dir("vendored/plugins/filter-xpath"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -14,6 +14,8 @@ pub struct PluginMetadata {
|
||||
pub description: Option<String>,
|
||||
pub homepage_url: Option<String>,
|
||||
pub repository_url: Option<String>,
|
||||
/// Why the plugin should no longer be used, from `deprecated` in its package.json
|
||||
pub deprecated: Option<String>,
|
||||
}
|
||||
|
||||
pub fn get_plugin_meta(plugin_dir: &Path) -> Result<PluginMetadata> {
|
||||
@@ -37,6 +39,7 @@ pub fn get_plugin_meta(plugin_dir: &Path) -> Result<PluginMetadata> {
|
||||
name: package_json.name,
|
||||
display_name,
|
||||
homepage_url: package_json.homepage,
|
||||
deprecated: package_json.deprecated,
|
||||
repository_url: match package_json.repository {
|
||||
None => None,
|
||||
Some(RepositoryField::Object { url }) => Some(url),
|
||||
@@ -54,6 +57,7 @@ struct PackageJson {
|
||||
pub repository: Option<RepositoryField>,
|
||||
pub homepage: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub deprecated: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use rand::Rng;
|
||||
use rand::RngExt;
|
||||
use rand::distr::Alphanumeric;
|
||||
|
||||
pub fn gen_id() -> String {
|
||||
|
||||
Reference in new issue
Block a user