use serde::{Deserialize, Serialize}; use std::collections::HashMap; use tauri::{Runtime, WebviewWindow}; use ts_rs::TS; use yaak_models::models::{Environment, Folder, GrpcRequest, HttpRequest, HttpResponse, Workspace}; #[derive(Debug, Clone, Serialize, Deserialize, TS)] #[serde(rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct InternalEvent { pub id: String, pub plugin_ref_id: String, pub reply_id: Option, pub payload: InternalEventPayload, pub window_context: WindowContext, } #[derive(Debug, Clone, Serialize, Deserialize, TS)] #[serde(rename_all = "snake_case", tag = "type")] #[ts(export, export_to = "events.ts")] pub enum WindowContext { None, Label { label: String }, } impl WindowContext { pub fn from_window(window: &WebviewWindow) -> Self { Self::Label { label: window.label().to_string(), } } } #[derive(Debug, Clone, Serialize, Deserialize, TS)] #[serde(rename_all = "snake_case", tag = "type")] #[ts(export, export_to = "events.ts")] pub enum InternalEventPayload { BootRequest(BootRequest), BootResponse(BootResponse), ReloadRequest(EmptyPayload), ReloadResponse(EmptyPayload), TerminateRequest, TerminateResponse, ImportRequest(ImportRequest), ImportResponse(ImportResponse), FilterRequest(FilterRequest), FilterResponse(FilterResponse), ExportHttpRequestRequest(ExportHttpRequestRequest), ExportHttpRequestResponse(ExportHttpRequestResponse), SendHttpRequestRequest(SendHttpRequestRequest), SendHttpRequestResponse(SendHttpRequestResponse), // Request Actions GetHttpRequestActionsRequest(EmptyPayload), GetHttpRequestActionsResponse(GetHttpRequestActionsResponse), CallHttpRequestActionRequest(CallHttpRequestActionRequest), // Template Functions GetTemplateFunctionsRequest, GetTemplateFunctionsResponse(GetTemplateFunctionsResponse), CallTemplateFunctionRequest(CallTemplateFunctionRequest), CallTemplateFunctionResponse(CallTemplateFunctionResponse), GetHttpAuthenticationRequest(EmptyPayload), GetHttpAuthenticationResponse(GetHttpAuthenticationResponse), CallHttpAuthenticationRequest(CallHttpAuthenticationRequest), CallHttpAuthenticationResponse(CallHttpAuthenticationResponse), CopyTextRequest(CopyTextRequest), RenderHttpRequestRequest(RenderHttpRequestRequest), RenderHttpRequestResponse(RenderHttpRequestResponse), TemplateRenderRequest(TemplateRenderRequest), TemplateRenderResponse(TemplateRenderResponse), ShowToastRequest(ShowToastRequest), PromptTextRequest(PromptTextRequest), PromptTextResponse(PromptTextResponse), GetHttpRequestByIdRequest(GetHttpRequestByIdRequest), GetHttpRequestByIdResponse(GetHttpRequestByIdResponse), FindHttpResponsesRequest(FindHttpResponsesRequest), FindHttpResponsesResponse(FindHttpResponsesResponse), /// Returned when a plugin doesn't get run, just so the server /// has something to listen for EmptyResponse(EmptyPayload), } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default)] #[ts(export, type = "{}", export_to = "events.ts")] pub struct EmptyPayload {} #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct BootRequest { pub dir: String, pub watch: bool, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct BootResponse { pub name: String, pub version: String, pub capabilities: Vec, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct ImportRequest { pub content: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct ImportResponse { pub resources: ImportResources, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FilterRequest { pub content: String, pub filter: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FilterResponse { pub content: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct ExportHttpRequestRequest { pub http_request: HttpRequest, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct ExportHttpRequestResponse { pub content: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct SendHttpRequestRequest { pub http_request: HttpRequest, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct SendHttpRequestResponse { pub http_response: HttpResponse, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct CopyTextRequest { pub text: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct RenderHttpRequestRequest { pub http_request: HttpRequest, pub purpose: RenderPurpose, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct RenderHttpRequestResponse { pub http_request: HttpRequest, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct TemplateRenderRequest { pub data: serde_json::Value, pub purpose: RenderPurpose, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct TemplateRenderResponse { pub data: serde_json::Value, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct ShowToastRequest { pub message: String, #[ts(optional)] pub color: Option, #[ts(optional)] pub icon: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct PromptTextRequest { // A unique ID to identify the prompt (eg. "enter-password") pub id: String, // Title to show on the prompt dialog pub title: String, // Text to show on the label above the input pub label: String, #[ts(optional)] pub description: Option, #[ts(optional)] pub default_value: Option, #[ts(optional)] pub placeholder: Option, /// Text to add to the confirmation button #[ts(optional)] pub confirm_text: Option, /// Text to add to the cancel button #[ts(optional)] pub cancel_text: Option, /// Require the user to enter a non-empty value #[ts(optional)] pub require: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct PromptTextResponse { pub value: Option, } #[derive(Debug, Clone, Serialize, Deserialize, TS)] #[serde(rename_all = "snake_case")] #[ts(export, export_to = "events.ts")] pub enum Color { Custom, Default, Primary, Secondary, Info, Success, Notice, Warning, Danger, } impl Default for Color { fn default() -> Self { Color::Default } } #[derive(Debug, Clone, Serialize, Deserialize, TS)] #[serde(rename_all = "snake_case")] #[ts(export, export_to = "events.ts")] pub enum Icon { Copy, Info, CheckCircle, AlertTriangle, #[serde(untagged)] #[ts(type = "\"_unknown\"")] _Unknown(String), } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct GetHttpAuthenticationResponse { pub name: String, pub plugin_name: String, pub config: Vec, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct CallHttpAuthenticationRequest { pub config: serde_json::Map, pub method: String, pub url: String, pub headers: Vec, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct HttpHeader { pub name: String, pub value: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct CallHttpAuthenticationResponse { pub url: String, pub headers: Vec, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct GetTemplateFunctionsResponse { pub functions: Vec, pub plugin_ref_id: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct TemplateFunction { pub name: String, #[ts(optional)] pub description: Option, /// Also support alternative names. This is useful for not breaking existing /// tags when changing the `name` property #[ts(optional)] pub aliases: Option>, pub args: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, TS)] #[serde(rename_all = "snake_case", tag = "type")] #[ts(export, export_to = "events.ts")] pub enum FormInput { Text(FormInputText), Select(FormInputSelect), Checkbox(FormInputCheckbox), File(FormInputFile), HttpRequest(FormInputHttpRequest), } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FormInputBase { pub name: String, /// Whether the user must fill in the argument #[ts(optional)] pub optional: Option, /// The label of the input #[ts(optional)] pub label: Option, /// The default value #[ts(optional)] pub default_value: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FormInputText { #[serde(flatten)] pub base: FormInputBase, /// Placeholder for the text input #[ts(optional = nullable)] pub placeholder: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FormInputHttpRequest { #[serde(flatten)] pub base: FormInputBase, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FormInputFile { #[serde(flatten)] pub base: FormInputBase, /// The title of the file selection window pub title: String, /// Allow selecting multiple files #[ts(optional)] pub multiple: Option, // Select a directory, not a file #[ts(optional)] pub directory: Option, // Default file path for selection dialog #[ts(optional)] pub default_path: Option, // Specify to only allow selection of certain file extensions #[ts(optional)] pub filters: Option>, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FileFilter { pub name: String, /// File extensions to require pub extensions: Vec, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FormInputSelect { #[serde(flatten)] pub base: FormInputBase, /// The options that will be available in the select input pub options: Vec, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FormInputCheckbox { #[serde(flatten)] pub base: FormInputBase, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FormInputSelectOption { pub name: String, pub value: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct CallTemplateFunctionRequest { pub name: String, pub args: CallTemplateFunctionArgs, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct CallTemplateFunctionResponse { pub value: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct CallTemplateFunctionArgs { pub purpose: RenderPurpose, pub values: HashMap, } #[derive(Debug, Clone, Serialize, Deserialize, TS)] #[serde(rename_all = "snake_case")] #[ts(export, export_to = "events.ts")] pub enum RenderPurpose { Send, Preview, } impl Default for RenderPurpose { fn default() -> Self { RenderPurpose::Preview } } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default)] #[ts(export, export_to = "events.ts")] pub struct GetHttpRequestActionsRequest {} #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct GetHttpRequestActionsResponse { pub actions: Vec, pub plugin_ref_id: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct HttpRequestAction { pub key: String, pub label: String, #[ts(optional)] pub icon: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct CallHttpRequestActionRequest { pub key: String, pub plugin_ref_id: String, pub args: CallHttpRequestActionArgs, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct CallHttpRequestActionArgs { pub http_request: HttpRequest, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct GetHttpRequestByIdRequest { pub id: String, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct GetHttpRequestByIdResponse { pub http_request: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FindHttpResponsesRequest { pub request_id: String, #[ts(optional)] pub limit: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct FindHttpResponsesResponse { pub http_responses: Vec, } #[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] #[serde(default, rename_all = "camelCase")] #[ts(export, export_to = "events.ts")] pub struct ImportResources { pub workspaces: Vec, pub environments: Vec, pub folders: Vec, pub http_requests: Vec, pub grpc_requests: Vec, }