diff --git a/package-lock.json b/package-lock.json index e391b123..f6a2f426 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "@tauri-apps/plugin-log": "^2.0.0-rc.1", "@tauri-apps/plugin-os": "^2.0.0-rc.1", "@tauri-apps/plugin-shell": "^2.0.0-rc.1", - "@yaakapp/api": "^0.1.17", + "@yaakapp/api": "^0.2.0", "buffer": "^6.0.3", "classnames": "^2.5.1", "cm6-graphql": "^0.0.9", @@ -3322,11 +3322,11 @@ "license": "MIT" }, "node_modules/@yaakapp/api": { - "version": "0.1.17", - "resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.1.17.tgz", - "integrity": "sha512-VE9A0FDZwczZkTAbMOYjQOKzbW1KmaItq/mPSuTgU87Lf570JUepcHVtL7QFLV1U/R5q+n7I6xQg9Q2mDj/OWQ==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.2.0.tgz", + "integrity": "sha512-DskPYRQ0Hk3KcOIi8O5drbpK0wUwvpUcMvsYfPPz90jfwb9tSpprfFKFUiCVartrA/VO6R0skKscWz74QTKaSA==", "dependencies": { - "@types/node": "^22.0.0" + "@types/node": "^22.5.4" } }, "node_modules/abbrev": { diff --git a/package.json b/package.json index d39aed63..3405cc1e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@tauri-apps/plugin-log": "^2.0.0-rc.1", "@tauri-apps/plugin-os": "^2.0.0-rc.1", "@tauri-apps/plugin-shell": "^2.0.0-rc.1", - "@yaakapp/api": "^0.1.17", + "@yaakapp/api": "^0.2.0", "buffer": "^6.0.3", "classnames": "^2.5.1", "cm6-graphql": "^0.0.9", diff --git a/plugin-runtime-types/package.json b/plugin-runtime-types/package.json index 00a2a373..fdf26b4b 100644 --- a/plugin-runtime-types/package.json +++ b/plugin-runtime-types/package.json @@ -1,6 +1,6 @@ { "name": "@yaakapp/api", - "version": "0.1.17", + "version": "0.2.0", "main": "lib/index.js", "typings": "./lib/index.d.ts", "files": [ diff --git a/plugin-runtime-types/src/gen/EmptyResponse.ts b/plugin-runtime-types/src/gen/BootRequest.ts similarity index 71% rename from plugin-runtime-types/src/gen/EmptyResponse.ts rename to plugin-runtime-types/src/gen/BootRequest.ts index 7fd56b5a..398ca72c 100644 --- a/plugin-runtime-types/src/gen/EmptyResponse.ts +++ b/plugin-runtime-types/src/gen/BootRequest.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type EmptyResponse = {}; +export type BootRequest = { dir: string, }; diff --git a/plugin-runtime-types/src/gen/PluginBootRequest.ts b/plugin-runtime-types/src/gen/BootResponse.ts similarity index 54% rename from plugin-runtime-types/src/gen/PluginBootRequest.ts rename to plugin-runtime-types/src/gen/BootResponse.ts index dcbc7b7c..1c1654de 100644 --- a/plugin-runtime-types/src/gen/PluginBootRequest.ts +++ b/plugin-runtime-types/src/gen/BootResponse.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type PluginBootRequest = { dir: string, }; +export type BootResponse = { name: string, version: string, capabilities: Array, }; diff --git a/plugin-runtime-types/src/gen/InternalEventPayload.ts b/plugin-runtime-types/src/gen/InternalEventPayload.ts index a4d2226c..10dca75c 100644 --- a/plugin-runtime-types/src/gen/InternalEventPayload.ts +++ b/plugin-runtime-types/src/gen/InternalEventPayload.ts @@ -1,30 +1,55 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { CallHttpRequestActionRequest } from "./CallHttpRequestActionRequest"; -import type { CallTemplateFunctionRequest } from "./CallTemplateFunctionRequest"; -import type { CallTemplateFunctionResponse } from "./CallTemplateFunctionResponse"; -import type { CopyTextRequest } from "./CopyTextRequest"; -import type { EmptyResponse } from "./EmptyResponse"; -import type { ExportHttpRequestRequest } from "./ExportHttpRequestRequest"; -import type { ExportHttpRequestResponse } from "./ExportHttpRequestResponse"; -import type { FilterRequest } from "./FilterRequest"; -import type { FilterResponse } from "./FilterResponse"; -import type { FindHttpResponsesRequest } from "./FindHttpResponsesRequest"; -import type { FindHttpResponsesResponse } from "./FindHttpResponsesResponse"; -import type { GetHttpRequestActionsRequest } from "./GetHttpRequestActionsRequest"; -import type { GetHttpRequestActionsResponse } from "./GetHttpRequestActionsResponse"; -import type { GetHttpRequestByIdRequest } from "./GetHttpRequestByIdRequest"; -import type { GetHttpRequestByIdResponse } from "./GetHttpRequestByIdResponse"; -import type { GetTemplateFunctionsResponse } from "./GetTemplateFunctionsResponse"; -import type { ImportRequest } from "./ImportRequest"; -import type { ImportResponse } from "./ImportResponse"; -import type { PluginBootRequest } from "./PluginBootRequest"; -import type { PluginBootResponse } from "./PluginBootResponse"; -import type { PluginReloadRequest } from "./PluginReloadRequest"; -import type { PluginReloadResponse } from "./PluginReloadResponse"; -import type { RenderHttpRequestRequest } from "./RenderHttpRequestRequest"; -import type { RenderHttpRequestResponse } from "./RenderHttpRequestResponse"; -import type { SendHttpRequestRequest } from "./SendHttpRequestRequest"; -import type { SendHttpRequestResponse } from "./SendHttpRequestResponse"; -import type { ShowToastRequest } from "./ShowToastRequest"; +import type { BootRequest } from './BootRequest'; +import type { BootResponse } from './BootResponse'; +import type { CallHttpRequestActionRequest } from './CallHttpRequestActionRequest'; +import type { CallTemplateFunctionRequest } from './CallTemplateFunctionRequest'; +import type { CallTemplateFunctionResponse } from './CallTemplateFunctionResponse'; +import type { CopyTextRequest } from './CopyTextRequest'; +import type { ExportHttpRequestRequest } from './ExportHttpRequestRequest'; +import type { ExportHttpRequestResponse } from './ExportHttpRequestResponse'; +import type { FilterRequest } from './FilterRequest'; +import type { FilterResponse } from './FilterResponse'; +import type { FindHttpResponsesRequest } from './FindHttpResponsesRequest'; +import type { FindHttpResponsesResponse } from './FindHttpResponsesResponse'; +import type { GetHttpRequestActionsRequest } from './GetHttpRequestActionsRequest'; +import type { GetHttpRequestActionsResponse } from './GetHttpRequestActionsResponse'; +import type { GetHttpRequestByIdRequest } from './GetHttpRequestByIdRequest'; +import type { GetHttpRequestByIdResponse } from './GetHttpRequestByIdResponse'; +import type { GetTemplateFunctionsResponse } from './GetTemplateFunctionsResponse'; +import type { ImportRequest } from './ImportRequest'; +import type { ImportResponse } from './ImportResponse'; +import type { RenderHttpRequestRequest } from './RenderHttpRequestRequest'; +import type { RenderHttpRequestResponse } from './RenderHttpRequestResponse'; +import type { SendHttpRequestRequest } from './SendHttpRequestRequest'; +import type { SendHttpRequestResponse } from './SendHttpRequestResponse'; +import type { ShowToastRequest } from './ShowToastRequest'; -export type InternalEventPayload = { "type": "boot_request" } & PluginBootRequest | { "type": "boot_response" } & PluginBootResponse | { "type": "reload_request" } & PluginReloadRequest | { "type": "reload_response" } & PluginReloadResponse | { "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": "get_http_request_actions_request" } & GetHttpRequestActionsRequest | { "type": "get_http_request_actions_response" } & GetHttpRequestActionsResponse | { "type": "call_http_request_action_request" } & CallHttpRequestActionRequest | { "type": "get_template_functions_request" } | { "type": "get_template_functions_response" } & GetTemplateFunctionsResponse | { "type": "call_template_function_request" } & CallTemplateFunctionRequest | { "type": "call_template_function_response" } & CallTemplateFunctionResponse | { "type": "copy_text_request" } & CopyTextRequest | { "type": "render_http_request_request" } & RenderHttpRequestRequest | { "type": "render_http_request_response" } & RenderHttpRequestResponse | { "type": "show_toast_request" } & ShowToastRequest | { "type": "get_http_request_by_id_request" } & GetHttpRequestByIdRequest | { "type": "get_http_request_by_id_response" } & GetHttpRequestByIdResponse | { "type": "find_http_responses_request" } & FindHttpResponsesRequest | { "type": "find_http_responses_response" } & FindHttpResponsesResponse | { "type": "empty_response" } & EmptyResponse; +export type InternalEventPayload = + | ({ type: 'boot_request' } & BootRequest) + | ({ type: 'boot_response' } & BootResponse) + | { type: 'reload_request' } + | { type: 'reload_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: 'get_http_request_actions_request' } & GetHttpRequestActionsRequest) + | ({ type: 'get_http_request_actions_response' } & GetHttpRequestActionsResponse) + | ({ type: 'call_http_request_action_request' } & CallHttpRequestActionRequest) + | { type: 'get_template_functions_request' } + | ({ type: 'get_template_functions_response' } & GetTemplateFunctionsResponse) + | ({ type: 'call_template_function_request' } & CallTemplateFunctionRequest) + | ({ type: 'call_template_function_response' } & CallTemplateFunctionResponse) + | ({ type: 'copy_text_request' } & CopyTextRequest) + | ({ type: 'render_http_request_request' } & RenderHttpRequestRequest) + | ({ type: 'render_http_request_response' } & RenderHttpRequestResponse) + | ({ type: 'show_toast_request' } & ShowToastRequest) + | ({ type: 'get_http_request_by_id_request' } & GetHttpRequestByIdRequest) + | ({ type: 'get_http_request_by_id_response' } & GetHttpRequestByIdResponse) + | ({ type: 'find_http_responses_request' } & FindHttpResponsesRequest) + | ({ type: 'find_http_responses_response' } & FindHttpResponsesResponse) + | { type: 'empty_response' }; diff --git a/plugin-runtime-types/src/gen/PluginBootResponse.ts b/plugin-runtime-types/src/gen/PluginBootResponse.ts deleted file mode 100644 index b9023922..00000000 --- a/plugin-runtime-types/src/gen/PluginBootResponse.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type PluginBootResponse = { name: string, version: string, capabilities: Array, }; diff --git a/plugin-runtime-types/src/gen/PluginReloadRequest.ts b/plugin-runtime-types/src/gen/PluginReloadRequest.ts deleted file mode 100644 index 2bf23758..00000000 --- a/plugin-runtime-types/src/gen/PluginReloadRequest.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type PluginReloadRequest = {}; diff --git a/plugin-runtime-types/src/gen/PluginReloadResponse.ts b/plugin-runtime-types/src/gen/PluginReloadResponse.ts deleted file mode 100644 index 44393138..00000000 --- a/plugin-runtime-types/src/gen/PluginReloadResponse.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type PluginReloadResponse = {}; diff --git a/plugin-runtime-types/src/index.ts b/plugin-runtime-types/src/index.ts index ddd79b18..fffb3bb0 100644 --- a/plugin-runtime-types/src/index.ts +++ b/plugin-runtime-types/src/index.ts @@ -12,7 +12,6 @@ export * from './gen/CookieDomain'; export * from './gen/CookieExpires'; export * from './gen/CookieJar'; export * from './gen/CopyTextRequest'; -export * from './gen/EmptyResponse'; export * from './gen/Environment'; export * from './gen/EnvironmentVariable'; export * from './gen/ExportHttpRequestRequest'; @@ -43,10 +42,8 @@ export * from './gen/InternalEvent'; export * from './gen/InternalEventPayload'; export * from './gen/KeyValue'; export * from './gen/Model'; -export * from './gen/PluginBootRequest'; -export * from './gen/PluginBootResponse'; -export * from './gen/PluginReloadRequest'; -export * from './gen/PluginReloadResponse'; +export * from './gen/BootRequest'; +export * from './gen/BootResponse'; export * from './gen/RenderHttpRequestRequest'; export * from './gen/RenderHttpRequestResponse'; export * from './gen/RenderPurpose'; diff --git a/plugin-runtime/src/index.worker.ts b/plugin-runtime/src/index.worker.ts index 6f069c17..863a74e8 100644 --- a/plugin-runtime/src/index.worker.ts +++ b/plugin-runtime/src/index.worker.ts @@ -313,8 +313,6 @@ function watchFile(filepath: string, cb: (filepath: string) => void) { const stat = statSync(filepath); if (stat.mtimeMs !== watchedFiles[filepath]?.mtimeMs) { cb(filepath); - } else { - console.log('SKIPPING SAME FILE STAT', filepath, stat); } watchedFiles[filepath] = stat; }); diff --git a/src-tauri/src/http_request.rs b/src-tauri/src/http_request.rs index dd1d53d3..dcdb1db8 100644 --- a/src-tauri/src/http_request.rs +++ b/src-tauri/src/http_request.rs @@ -10,6 +10,7 @@ use std::time::Duration; use crate::render::render_http_request; use crate::response_err; use crate::template_callback::PluginTemplateCallback; +use base64::prelude::BASE64_STANDARD; use base64::Engine; use http::header::{ACCEPT, USER_AGENT}; use http::{HeaderMap, HeaderName, HeaderValue}; @@ -204,7 +205,7 @@ pub async fn send_http_request( .unwrap_or_default(); let auth = format!("{username}:{password}"); - let encoded = base64::engine::general_purpose::STANDARD.encode(auth); + let encoded = BASE64_STANDARD.encode(auth); headers.insert( "Authorization", HeaderValue::from_str(&format!("Basic {}", encoded)).unwrap(), diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 2a6c23d4..c6356964 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -59,7 +59,7 @@ use yaak_models::queries::{ use yaak_plugin_runtime::events::{ CallHttpRequestActionRequest, FilterResponse, FindHttpResponsesResponse, GetHttpRequestActionsResponse, GetHttpRequestByIdResponse, GetTemplateFunctionsResponse, - InternalEvent, InternalEventPayload, PluginBootResponse, RenderHttpRequestResponse, + InternalEvent, InternalEventPayload, BootResponse, RenderHttpRequestResponse, SendHttpRequestResponse, ShowToastRequest, ToastVariant, }; use yaak_plugin_runtime::handle::PluginHandle; @@ -1473,7 +1473,7 @@ async fn cmd_plugin_info( id: &str, w: WebviewWindow, plugin_manager: State<'_, PluginManager>, -) -> Result { +) -> Result { let plugin = get_plugin(&w, id).await.map_err(|e| e.to_string())?; plugin_manager .get_plugin_info(plugin.directory.as_str()) @@ -2085,7 +2085,7 @@ async fn handle_plugin_event( }, )) } - InternalEventPayload::ReloadResponse(_) => { + InternalEventPayload::ReloadResponse => { let w = get_focused_window_no_lock(app_handle).expect("No focused window"); let plugins = list_plugins(&w).await.unwrap(); for plugin in plugins { diff --git a/src-tauri/yaak_plugin_runtime/src/events.rs b/src-tauri/yaak_plugin_runtime/src/events.rs index 51cec3f2..32d0b6dc 100644 --- a/src-tauri/yaak_plugin_runtime/src/events.rs +++ b/src-tauri/yaak_plugin_runtime/src/events.rs @@ -21,11 +21,11 @@ pub struct InternalEvent { #[serde(rename_all = "snake_case", tag = "type")] #[ts(export)] pub enum InternalEventPayload { - BootRequest(PluginBootRequest), - BootResponse(PluginBootResponse), + BootRequest(BootRequest), + BootResponse(BootResponse), - ReloadRequest(EmptyResponse), - ReloadResponse(EmptyResponse), + ReloadRequest, + ReloadResponse, ImportRequest(ImportRequest), ImportResponse(ImportResponse), @@ -63,25 +63,20 @@ pub enum InternalEventPayload { /// Returned when a plugin doesn't get run, just so the server /// has something to listen for - EmptyResponse(EmptyResponse), + EmptyResponse, } -#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] -#[serde(default)] -#[ts(export, type = "{}")] -pub struct EmptyResponse {} - #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export)] -pub struct PluginBootRequest { +pub struct BootRequest { pub dir: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export)] -pub struct PluginBootResponse { +pub struct BootResponse { pub name: String, pub version: String, pub capabilities: Vec, diff --git a/src-tauri/yaak_plugin_runtime/src/handle.rs b/src-tauri/yaak_plugin_runtime/src/handle.rs index 4931367a..915d5fd5 100644 --- a/src-tauri/yaak_plugin_runtime/src/handle.rs +++ b/src-tauri/yaak_plugin_runtime/src/handle.rs @@ -1,4 +1,4 @@ -use crate::events::{EmptyResponse, InternalEvent, InternalEventPayload, PluginBootResponse}; +use crate::events::{BootResponse, InternalEvent, InternalEventPayload}; use crate::server::plugin_runtime::EventStreamEvent; use crate::util::gen_id; use std::sync::Arc; @@ -9,7 +9,7 @@ pub struct PluginHandle { pub ref_id: String, pub dir: String, pub(crate) to_plugin_tx: Arc>>>, - pub(crate) boot_resp: Arc>>, + pub(crate) boot_resp: Arc>>, } impl PluginHandle { @@ -20,7 +20,7 @@ impl PluginHandle { } } - pub async fn info(&self) -> Option { + pub async fn info(&self) -> Option { let resp = &*self.boot_resp.lock().await; resp.clone() } @@ -39,7 +39,7 @@ impl PluginHandle { } pub async fn reload(&self) -> crate::error::Result<()> { - let event = self.build_event_to_send(&InternalEventPayload::ReloadRequest(EmptyResponse{}), None); + let event = self.build_event_to_send(&InternalEventPayload::ReloadRequest, None); self.send(&event).await } @@ -59,7 +59,7 @@ impl PluginHandle { Ok(()) } - pub async fn boot(&self, resp: &PluginBootResponse) { + pub async fn boot(&self, resp: &BootResponse) { let mut boot_resp = self.boot_resp.lock().await; *boot_resp = Some(resp.clone()); } diff --git a/src-tauri/yaak_plugin_runtime/src/manager.rs b/src-tauri/yaak_plugin_runtime/src/manager.rs index d1683610..1e885612 100644 --- a/src-tauri/yaak_plugin_runtime/src/manager.rs +++ b/src-tauri/yaak_plugin_runtime/src/manager.rs @@ -1,6 +1,6 @@ use crate::error::Result; use crate::events::{ - PluginBootResponse, CallHttpRequestActionRequest, CallTemplateFunctionArgs, + BootResponse, CallHttpRequestActionRequest, CallTemplateFunctionArgs, CallTemplateFunctionRequest, CallTemplateFunctionResponse, FilterRequest, FilterResponse, GetHttpRequestActionsRequest, GetHttpRequestActionsResponse, GetTemplateFunctionsResponse, ImportRequest, ImportResponse, InternalEvent, InternalEventPayload, RenderPurpose, @@ -69,7 +69,7 @@ impl PluginManager { .await } - pub async fn get_plugin_info(&self, dir: &str) -> Option { + pub async fn get_plugin_info(&self, dir: &str) -> Option { self.server.plugin_by_dir(dir).await.ok()?.info().await } @@ -204,7 +204,7 @@ impl PluginManager { match event.payload { InternalEventPayload::FilterResponse(resp) => Ok(resp), - InternalEventPayload::EmptyResponse(_) => { + InternalEventPayload::EmptyResponse => { Err(PluginErr("Filter returned empty".to_string())) } e => Err(PluginErr(format!("Export returned invalid event {:?}", e))), diff --git a/src-tauri/yaak_plugin_runtime/src/server.rs b/src-tauri/yaak_plugin_runtime/src/server.rs index 0b02f18d..b40f1515 100644 --- a/src-tauri/yaak_plugin_runtime/src/server.rs +++ b/src-tauri/yaak_plugin_runtime/src/server.rs @@ -10,7 +10,7 @@ use tonic::{Request, Response, Status, Streaming}; use crate::error::Error::PluginNotFoundErr; use crate::error::Result; -use crate::events::{InternalEvent, InternalEventPayload, PluginBootRequest, PluginBootResponse}; +use crate::events::{InternalEvent, InternalEventPayload, BootRequest, BootResponse}; use crate::handle::PluginHandle; use crate::server::plugin_runtime::plugin_runtime_server::PluginRuntime; use crate::util::gen_id; @@ -75,7 +75,7 @@ impl PluginRuntimeGrpcServer { }; } - pub async fn boot_plugin(&self, id: &str, resp: &PluginBootResponse) { + pub async fn boot_plugin(&self, id: &str, resp: &BootResponse) { match self.plugin_ref_to_plugin.lock().await.get(id) { None => println!("Tried booting non-existing plugin {}", id), Some(plugin) => plugin.clone().boot(resp).await, @@ -266,7 +266,7 @@ impl PluginRuntimeGrpcServer { plugin_ids.push(plugin.clone().ref_id); let event = plugin.build_event_to_send( - &InternalEventPayload::BootRequest(PluginBootRequest { + &InternalEventPayload::BootRequest(BootRequest { dir: dir.to_string(), }), None, diff --git a/src-web/hooks/useTemplateFunctions.ts b/src-web/hooks/useTemplateFunctions.ts index 519cfc53..d3e077cc 100644 --- a/src-web/hooks/useTemplateFunctions.ts +++ b/src-web/hooks/useTemplateFunctions.ts @@ -5,7 +5,6 @@ import { invokeCmd } from '../lib/tauri'; export function useTemplateFunctions() { const result = useQuery({ queryKey: ['template_functions'], - refetchOnWindowFocus: false, queryFn: async () => { const responses = (await invokeCmd( 'cmd_template_functions',