mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-02-23 16:14:53 +01:00
Compare commits
41 Commits
v2025.6.0-
...
v2025.6.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a00b4ae232 | ||
|
|
998b5cf78a | ||
|
|
b4deae6e8d | ||
|
|
87fdf17010 | ||
|
|
c6975a9e8b | ||
|
|
b44ac55bc2 | ||
|
|
9c65c95ba9 | ||
|
|
7beb9f4e69 | ||
|
|
dbecd74f46 | ||
|
|
6826ee1672 | ||
|
|
a12ae7ef56 | ||
|
|
dbc100409d | ||
|
|
6b87cd9655 | ||
|
|
7ce2cdc9cc | ||
|
|
1f4e38b7a7 | ||
|
|
0013a0797b | ||
|
|
5e9b14dc0b | ||
|
|
b7cfb0db13 | ||
|
|
8948bfbf45 | ||
|
|
4218e90bf4 | ||
|
|
2172d7ac60 | ||
|
|
5e45cb4908 | ||
|
|
d662883fdd | ||
|
|
f83f3d4682 | ||
|
|
e03c745093 | ||
|
|
73b9d699ed | ||
|
|
5a7b9aba2f | ||
|
|
cf433b26a5 | ||
|
|
573035b17d | ||
|
|
a267c0c53f | ||
|
|
328563f4e6 | ||
|
|
3844fec968 | ||
|
|
8557a2477b | ||
|
|
d02519ab74 | ||
|
|
1a1751c23e | ||
|
|
17de0678b0 | ||
|
|
20bb89de33 | ||
|
|
8a634b1056 | ||
|
|
57f231ca00 | ||
|
|
cb1c0e4d8c | ||
|
|
2152cf87d7 |
43
.github/workflows/sponsors.yml
vendored
Normal file
43
.github/workflows/sponsors.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
name: Generate Sponsors README
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: 30 15 * * 0-6
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout 🛎️
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Generate Sponsors
|
||||
uses: JamesIves/github-sponsors-readme-action@v1
|
||||
with:
|
||||
token: ${{ secrets.SPONSORS_PAT }}
|
||||
file: 'README.md'
|
||||
maximum: 1999
|
||||
template: '<a href="https://github.com/{{{ login }}}"><img src="{{{ avatarUrl }}}" width="50px" alt="User avatar: {{{ login }}}" /></a> '
|
||||
active-only: false
|
||||
include-private: true
|
||||
marker: 'sponsors-base'
|
||||
|
||||
- name: Generate Sponsors
|
||||
uses: JamesIves/github-sponsors-readme-action@v1
|
||||
with:
|
||||
token: ${{ secrets.SPONSORS_PAT }}
|
||||
file: 'README.md'
|
||||
minimum: 2000
|
||||
template: '<a href="https://github.com/{{{ login }}}"><img src="{{{ avatarUrl }}}" width="80px" alt="User avatar: {{{ login }}}" /></a> '
|
||||
active-only: false
|
||||
include-private: true
|
||||
marker: 'sponsors-premium'
|
||||
|
||||
# ⚠️ Note: You can use any deployment step here to automatically push the README
|
||||
# changes back to your branch.
|
||||
- name: Commit Changes
|
||||
uses: JamesIves/github-pages-deploy-action@v4
|
||||
with:
|
||||
branch: main
|
||||
folder: '.'
|
||||
74
README.md
74
README.md
@@ -1,32 +1,66 @@
|
||||
# Yaak API Client
|
||||
<p align="center">
|
||||
<a href="https://github.com/JamesIves/github-sponsors-readme-action">
|
||||
<img width="200px" src="https://github.com/mountain-loop/yaak/raw/main/src-tauri/icons/icon.png">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
Yaak is a desktop API client for interacting with REST, GraphQL, Server Sent Events (SSE), WebSocket, and gRPC
|
||||
APIs. It's built using [Tauri](https://tauri.app), Rust, and ReactJS.
|
||||
<h1 align="center">
|
||||
💫 Yaak ➟ Desktop API Client 💫
|
||||
</h1>
|
||||
|
||||
<p align="center">
|
||||
A fast, privacy-first API client for REST, GraphQL, SSE, WebSocket, and gRPC – built with Tauri, Rust, and React.
|
||||
</p>
|
||||
<p align="center">
|
||||
Development is funded by community-purchased <a href="https://yaak.app/pricing">licenses</a>. You can also <a href="https://github.com/sponsors/gschier">become a sponsor</a> to have your logo appear below. 💖
|
||||
</p>
|
||||
<br>
|
||||
|
||||
|
||||
|
||||
<p align="center">
|
||||
<!-- sponsors-premium --><a href="https://github.com/MVST-Solutions"><img src="https://github.com/MVST-Solutions.png" width="80px" alt="User avatar: MVST-Solutions" /></a> <a href="https://github.com/dharsanb"><img src="https://github.com/dharsanb.png" width="80px" alt="User avatar: dharsanb" /></a> <a href="https://github.com/railwayapp"><img src="https://github.com/railwayapp.png" width="80px" alt="User avatar: railwayapp" /></a> <a href="https://github.com/caseyamcl"><img src="https://github.com/caseyamcl.png" width="80px" alt="User avatar: caseyamcl" /></a> <a href="https://github.com/andriyor"><img src="https://github.com/andriyor.png" width="80px" alt="User avatar: andriyor" /></a> <a href="https://github.com/"><img src="https://raw.githubusercontent.com/JamesIves/github-sponsors-readme-action/dev/.github/assets/placeholder.png" width="80px" alt="User avatar: " /></a> <!-- sponsors-premium -->
|
||||
</p>
|
||||
<p align="center">
|
||||
<!-- sponsors-base --><a href="https://github.com/seanwash"><img src="https://github.com/seanwash.png" width="50px" alt="User avatar: seanwash" /></a> <a href="https://github.com/jerath"><img src="https://github.com/jerath.png" width="50px" alt="User avatar: jerath" /></a> <a href="https://github.com/itsa-sh"><img src="https://github.com/itsa-sh.png" width="50px" alt="User avatar: itsa-sh" /></a> <a href="https://github.com/dmmulroy"><img src="https://github.com/dmmulroy.png" width="50px" alt="User avatar: dmmulroy" /></a> <a href="https://github.com/timcole"><img src="https://github.com/timcole.png" width="50px" alt="User avatar: timcole" /></a> <a href="https://github.com/VLZH"><img src="https://github.com/VLZH.png" width="50px" alt="User avatar: VLZH" /></a> <a href="https://github.com/terasaka2k"><img src="https://github.com/terasaka2k.png" width="50px" alt="User avatar: terasaka2k" /></a> <!-- sponsors-base -->
|
||||
</p>
|
||||
|
||||

|
||||
|
||||
|
||||
## Features
|
||||
|
||||
Yaak is an offline-first API client designed to stay out of your way while giving you everything you need when you need it.
|
||||
Built with [Tauri](https://tauri.app), Rust, and React, it’s fast, lightweight, and private. No telemetry, no VC funding, and no cloud lock-in.
|
||||
|
||||
|
||||
### 🌐 Work with any API
|
||||
|
||||
- Import collections from Postman, Insomnia, OpenAPI, Swagger, or Curl.
|
||||
- Send requests via REST, GraphQL, gRPC, WebSocket, or Server-Sent Events.
|
||||
- Filter and inspect responses with JSONPath or XPath.
|
||||
|
||||
### 🔐 Stay secure
|
||||
- Use OAuth 2.0, JWT, Basic Auth, or custom plugins for authentication.
|
||||
- Secure sensitive values with end-to-end encryption.
|
||||
- Store secrets in your OS keychain.
|
||||
|
||||
### ☁️ Organize & collaborate
|
||||
- Group requests into workspaces and nested folders.
|
||||
- Use environment variables to switch between dev, staging, and prod.
|
||||
- Mirror workspaces to your filesystem for versioning in Git or syncing with Dropbox.
|
||||
|
||||
### 🧩 Extend & customize
|
||||
- Insert dynamic values like UUIDs or timestamps with template tags.
|
||||
- Pick from built-in themes or build your own.
|
||||
- Create plugins to extend authentication, template tags, or the UI.
|
||||
|
||||
|
||||
## Contribution Policy
|
||||
|
||||
Yaak is open source, but only accepting contributions for bug fixes. To get started,
|
||||
visit [`DEVELOPMENT.md`](DEVELOPMENT.md) for tips on setting up your environment.
|
||||
|
||||
## Feature Overview
|
||||
|
||||
- 🪂 Import data from Postman, Insomnia, OpenAPI, Swagger, or Curl.<br/>
|
||||
- 📤 Send requests via REST, GraphQL, Server Sent Events (SSE), WebSockets, or gRPC.<br/>
|
||||
- 🔐 Automatically authorize requests with OAuth 2.0, JWT tokens, Basic Auth, and more.<br/>
|
||||
- 🔎 Filter response bodies using JSONPath or XPath queries.<br/>
|
||||
- ⛓️ Chain together multiple requests to dynamically reference values.<br/>
|
||||
- 📂 Organize requests into workspaces and nested folders.<br/>
|
||||
- 🧮 Use environment variables to easily switch between Prod and Dev.<br/>
|
||||
- 🛡️ Secure arbitrary text values with end-to-end encryption<br/>
|
||||
- 🏷️ Send dynamic values like UUIDs or timestamps using template tags.<br/>
|
||||
- 🎨 Choose from many of the included themes, or make your own.<br/>
|
||||
- 💽 Mirror workspace data to a directory for integration with Git or Dropbox.<br/>
|
||||
- 📜 View response history for each request.<br/>
|
||||
- 🔌 Create your own plugins for authentication, template tags, and more!<br/>
|
||||
- 🛜 Configure a proxy to access firewall-blocked APIs
|
||||
|
||||
## Useful Resources
|
||||
|
||||
- [Feedback and Bug Reports](https://feedback.yaak.app)
|
||||
|
||||
@@ -88,9 +88,9 @@ export async function getAuthorizationCode(
|
||||
const code = await new Promise<string>(async (resolve, reject) => {
|
||||
let foundCode = false;
|
||||
const { close } = await ctx.window.openUrl({
|
||||
dataDirKey,
|
||||
url: authorizationUrlStr,
|
||||
label: 'oauth-authorization-url',
|
||||
dataDirKey,
|
||||
async onClose() {
|
||||
if (!foundCode) {
|
||||
reject(new Error('Authorization window closed'));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Context } from '@yaakapp/api';
|
||||
import type { AccessToken, AccessTokenRawResponse } from '../store';
|
||||
import { getToken, storeToken } from '../store';
|
||||
import type { AccessToken, AccessTokenRawResponse} from '../store';
|
||||
import { getDataDirKey , getToken, storeToken } from '../store';
|
||||
import { isTokenExpired } from '../util';
|
||||
|
||||
export async function getImplicit(
|
||||
@@ -60,7 +60,9 @@ export async function getImplicit(
|
||||
const newToken = await new Promise<AccessToken>(async (resolve, reject) => {
|
||||
let foundAccessToken = false;
|
||||
const authorizationUrlStr = authorizationUrl.toString();
|
||||
const dataDirKey = await getDataDirKey(ctx, contextId);
|
||||
const { close } = await ctx.window.openUrl({
|
||||
dataDirKey,
|
||||
url: authorizationUrlStr,
|
||||
label: 'oauth-authorization-url',
|
||||
async onClose() {
|
||||
|
||||
@@ -68,11 +68,11 @@ export function migrateImport(contents: string) {
|
||||
|
||||
// Migrate v4 to v5
|
||||
for (const environment of parsed.resources.environments ?? []) {
|
||||
if ('base' in environment && environment.base) {
|
||||
if ('base' in environment && environment.base && environment.parentModel == null) {
|
||||
environment.parentModel = 'workspace';
|
||||
environment.parentId = null;
|
||||
delete environment.base;
|
||||
} else if ('base' in environment && !environment.base) {
|
||||
} else if ('base' in environment && !environment.base && environment.parentModel == null) {
|
||||
environment.parentModel = 'environment';
|
||||
environment.parentId = null;
|
||||
delete environment.base;
|
||||
|
||||
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
@@ -8102,6 +8102,7 @@ name = "yaak-templates"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"log",
|
||||
"serde",
|
||||
"serde-wasm-bindgen",
|
||||
"serde_json",
|
||||
|
||||
@@ -91,21 +91,21 @@ yaak-ws = { path = "yaak-ws" }
|
||||
[workspace.dependencies]
|
||||
chrono = "0.4.41"
|
||||
hex = "0.4.3"
|
||||
keyring = { version = "3.6.3", features = ["apple-native", "windows-native", "sync-secret-service"] }
|
||||
keyring = "3.6.3"
|
||||
reqwest = "0.12.20"
|
||||
reqwest_cookie_store = "0.8.0"
|
||||
rustls = { version = "0.23.27", default-features = false }
|
||||
rustls-platform-verifier = "0.6.0"
|
||||
serde = "1.0.219"
|
||||
serde_json = "1.0.140"
|
||||
sha2 = "0.10.9"
|
||||
tauri = "2.8.5"
|
||||
tauri-plugin = "2.4.0"
|
||||
tauri-plugin-dialog = "2.4.0"
|
||||
tauri-plugin-shell = "2.3.1"
|
||||
tokio = "1.45.1"
|
||||
thiserror = "2.0.12"
|
||||
tokio = "1.45.1"
|
||||
ts-rs = "11.0.1"
|
||||
reqwest_cookie_store = "0.8.0"
|
||||
rustls = { version = "0.23.27", default-features = false }
|
||||
rustls-platform-verifier = "0.6.0"
|
||||
sha2 = "0.10.9"
|
||||
yaak-common = { path = "yaak-common" }
|
||||
yaak-crypto = { path = "yaak-crypto" }
|
||||
yaak-fonts = { path = "yaak-fonts" }
|
||||
|
||||
@@ -32,6 +32,7 @@ use yaak_plugins::events::{
|
||||
};
|
||||
use yaak_plugins::manager::PluginManager;
|
||||
use yaak_plugins::template_callback::PluginTemplateCallback;
|
||||
use yaak_templates::{RenderErrorBehavior, RenderOptions};
|
||||
|
||||
pub async fn send_http_request<R: Runtime>(
|
||||
window: &WebviewWindow<R>,
|
||||
@@ -76,7 +77,11 @@ pub async fn send_http_request<R: Runtime>(
|
||||
RenderPurpose::Send,
|
||||
);
|
||||
|
||||
let request = match render_http_request(&resolved_request, environment_chain, &cb).await {
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
let request = match render_http_request(&resolved_request, environment_chain, &cb, &opt).await {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return Ok(response_err(
|
||||
|
||||
@@ -49,7 +49,7 @@ use yaak_plugins::plugin_meta::PluginMetadata;
|
||||
use yaak_plugins::template_callback::PluginTemplateCallback;
|
||||
use yaak_sse::sse::ServerSentEvent;
|
||||
use yaak_templates::format::format_json;
|
||||
use yaak_templates::{Tokens, transform_args};
|
||||
use yaak_templates::{Tokens, transform_args, RenderOptions, RenderErrorBehavior};
|
||||
|
||||
mod commands;
|
||||
mod encoding;
|
||||
@@ -126,6 +126,9 @@ async fn cmd_render_template<R: Runtime>(
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Preview,
|
||||
),
|
||||
&RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(result)
|
||||
@@ -167,6 +170,9 @@ async fn cmd_grpc_reflect<R: Runtime>(
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Send,
|
||||
),
|
||||
&RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -213,6 +219,9 @@ async fn cmd_grpc_go<R: Runtime>(
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Send,
|
||||
),
|
||||
&RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -335,6 +344,9 @@ async fn cmd_grpc_go<R: Runtime>(
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Send,
|
||||
),
|
||||
&RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("Failed to render template")
|
||||
@@ -404,6 +416,9 @@ async fn cmd_grpc_go<R: Runtime>(
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Send,
|
||||
),
|
||||
&RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -1198,13 +1213,13 @@ async fn cmd_new_child_window(
|
||||
title: &str,
|
||||
inner_size: (f64, f64),
|
||||
) -> YaakResult<()> {
|
||||
window::create_child_window(&parent_window, url, label, title, inner_size);
|
||||
window::create_child_window(&parent_window, url, label, title, inner_size)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn cmd_new_main_window(app_handle: AppHandle, url: &str) -> YaakResult<()> {
|
||||
window::create_main_window(&app_handle, url);
|
||||
window::create_main_window(&app_handle, url)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1304,6 +1319,7 @@ pub fn run() {
|
||||
),
|
||||
color: Some(Color::Danger),
|
||||
icon: None,
|
||||
timeout: None,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -7,22 +7,23 @@ use crate::{
|
||||
};
|
||||
use chrono::Utc;
|
||||
use cookie::Cookie;
|
||||
use log::warn;
|
||||
use log::{error, warn};
|
||||
use tauri::{AppHandle, Emitter, Manager, Runtime, State};
|
||||
use tauri_plugin_clipboard_manager::ClipboardExt;
|
||||
use yaak_models::models::{HttpResponse, Plugin};
|
||||
use yaak_models::query_manager::QueryManagerExt;
|
||||
use yaak_models::util::UpdateSource;
|
||||
use yaak_plugins::events::{
|
||||
Color, DeleteKeyValueResponse, EmptyPayload, FindHttpResponsesResponse, GetCookieValueResponse,
|
||||
GetHttpRequestByIdResponse, GetKeyValueResponse, Icon, InternalEvent, InternalEventPayload,
|
||||
ListCookieNamesResponse, PluginWindowContext, RenderGrpcRequestResponse,
|
||||
Color, DeleteKeyValueResponse, EmptyPayload, ErrorResponse, FindHttpResponsesResponse,
|
||||
GetCookieValueResponse, GetHttpRequestByIdResponse, GetKeyValueResponse, Icon, InternalEvent,
|
||||
InternalEventPayload, ListCookieNamesResponse, PluginWindowContext, RenderGrpcRequestResponse,
|
||||
RenderHttpRequestResponse, SendHttpRequestResponse, SetKeyValueResponse, ShowToastRequest,
|
||||
TemplateRenderResponse, WindowNavigateEvent,
|
||||
};
|
||||
use yaak_plugins::manager::PluginManager;
|
||||
use yaak_plugins::plugin_handle::PluginHandle;
|
||||
use yaak_plugins::template_callback::PluginTemplateCallback;
|
||||
use yaak_templates::{RenderErrorBehavior, RenderOptions};
|
||||
|
||||
pub(crate) async fn handle_plugin_event<R: Runtime>(
|
||||
app_handle: &AppHandle<R>,
|
||||
@@ -80,7 +81,10 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
|
||||
.resolve_environments(&workspace.id, None, environment_id.as_deref())
|
||||
.expect("Failed to resolve environments");
|
||||
let cb = PluginTemplateCallback::new(app_handle, &window_context, req.purpose);
|
||||
let grpc_request = render_grpc_request(&req.grpc_request, environment_chain, &cb)
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
let grpc_request = render_grpc_request(&req.grpc_request, environment_chain, &cb, &opt)
|
||||
.await
|
||||
.expect("Failed to render grpc request");
|
||||
Some(InternalEventPayload::RenderGrpcRequestResponse(RenderGrpcRequestResponse {
|
||||
@@ -99,7 +103,10 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
|
||||
.resolve_environments(&workspace.id, None, environment_id.as_deref())
|
||||
.expect("Failed to resolve environments");
|
||||
let cb = PluginTemplateCallback::new(app_handle, &window_context, req.purpose);
|
||||
let http_request = render_http_request(&req.http_request, environment_chain, &cb)
|
||||
let opt = &RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
let http_request = render_http_request(&req.http_request, environment_chain, &cb, &opt)
|
||||
.await
|
||||
.expect("Failed to render http request");
|
||||
Some(InternalEventPayload::RenderHttpRequestResponse(RenderHttpRequestResponse {
|
||||
@@ -118,12 +125,16 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
|
||||
.resolve_environments(&workspace.id, None, environment_id.as_deref())
|
||||
.expect("Failed to resolve environments");
|
||||
let cb = PluginTemplateCallback::new(app_handle, &window_context, req.purpose);
|
||||
let data = render_json_value(req.data, environment_chain, &cb)
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
let data = render_json_value(req.data, environment_chain, &cb, &opt)
|
||||
.await
|
||||
.expect("Failed to render template");
|
||||
Some(InternalEventPayload::TemplateRenderResponse(TemplateRenderResponse { data }))
|
||||
}
|
||||
InternalEventPayload::ErrorResponse(resp) => {
|
||||
error!("Plugin error: {}: {:?}", resp.error, resp);
|
||||
let toast_event = plugin_handle.build_event_to_send(
|
||||
&window_context,
|
||||
&InternalEventPayload::ShowToastRequest(ShowToastRequest {
|
||||
@@ -133,6 +144,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
|
||||
resp.error
|
||||
),
|
||||
color: Some(Color::Danger),
|
||||
timeout: None,
|
||||
..Default::default()
|
||||
}),
|
||||
None,
|
||||
@@ -161,6 +173,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
|
||||
&InternalEventPayload::ShowToastRequest(ShowToastRequest {
|
||||
message: format!("Reloaded plugin {}@{}", info.name, info.version),
|
||||
icon: Some(Icon::Info),
|
||||
timeout: Some(3000),
|
||||
..Default::default()
|
||||
}),
|
||||
None,
|
||||
@@ -218,20 +231,29 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
|
||||
}))
|
||||
}
|
||||
InternalEventPayload::OpenWindowRequest(req) => {
|
||||
let label = req.label;
|
||||
let (navigation_tx, mut navigation_rx) = tokio::sync::mpsc::channel(128);
|
||||
let (close_tx, mut close_rx) = tokio::sync::mpsc::channel(128);
|
||||
let win_config = CreateWindowConfig {
|
||||
url: &req.url,
|
||||
label: &label.clone(),
|
||||
title: &req.title.unwrap_or_default(),
|
||||
label: &req.label,
|
||||
title: &req.title.clone().unwrap_or_default(),
|
||||
navigation_tx: Some(navigation_tx),
|
||||
close_tx: Some(close_tx),
|
||||
inner_size: req.size.map(|s| (s.width, s.height)),
|
||||
data_dir_key: req.data_dir_key,
|
||||
inner_size: req.size.clone().map(|s| (s.width, s.height)),
|
||||
data_dir_key: req.data_dir_key.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
create_window(app_handle, win_config);
|
||||
if let Err(e) = create_window(app_handle, win_config) {
|
||||
let error_event = plugin_handle.build_event_to_send(
|
||||
&window_context,
|
||||
&InternalEventPayload::ErrorResponse(ErrorResponse {
|
||||
error: format!("Failed to create window: {:?}", e),
|
||||
}),
|
||||
None,
|
||||
);
|
||||
Box::pin(handle_plugin_event(app_handle, &error_event, plugin_handle)).await;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
let event_id = event.id.clone();
|
||||
|
||||
@@ -1,34 +1,37 @@
|
||||
use serde_json::Value;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::collections::BTreeMap;
|
||||
use yaak_http::apply_path_placeholders;
|
||||
use yaak_models::models::{
|
||||
Environment, GrpcRequest, HttpRequest, HttpRequestHeader, HttpUrlParameter,
|
||||
};
|
||||
use yaak_models::render::make_vars_hashmap;
|
||||
use yaak_templates::{TemplateCallback, parse_and_render, render_json_value_raw};
|
||||
use yaak_templates::{RenderOptions, TemplateCallback, parse_and_render, render_json_value_raw};
|
||||
|
||||
pub async fn render_template<T: TemplateCallback>(
|
||||
template: &str,
|
||||
environment_chain: Vec<Environment>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
) -> yaak_templates::error::Result<String> {
|
||||
let vars = &make_vars_hashmap(environment_chain);
|
||||
render(template, vars, cb).await
|
||||
parse_and_render(template, vars, cb, &opt).await
|
||||
}
|
||||
|
||||
pub async fn render_json_value<T: TemplateCallback>(
|
||||
value: Value,
|
||||
environment_chain: Vec<Environment>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
) -> yaak_templates::error::Result<Value> {
|
||||
let vars = &make_vars_hashmap(environment_chain);
|
||||
render_json_value_raw(value, vars, cb).await
|
||||
render_json_value_raw(value, vars, cb, opt).await
|
||||
}
|
||||
|
||||
pub async fn render_grpc_request<T: TemplateCallback>(
|
||||
r: &GrpcRequest,
|
||||
environment_chain: Vec<Environment>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
) -> yaak_templates::error::Result<GrpcRequest> {
|
||||
let vars = &make_vars_hashmap(environment_chain);
|
||||
|
||||
@@ -36,18 +39,18 @@ pub async fn render_grpc_request<T: TemplateCallback>(
|
||||
for p in r.metadata.clone() {
|
||||
metadata.push(HttpRequestHeader {
|
||||
enabled: p.enabled,
|
||||
name: render(p.name.as_str(), vars, cb).await?,
|
||||
value: render(p.value.as_str(), vars, cb).await?,
|
||||
name: parse_and_render(p.name.as_str(), vars, cb, &opt).await?,
|
||||
value: parse_and_render(p.value.as_str(), vars, cb, &opt).await?,
|
||||
id: p.id,
|
||||
})
|
||||
}
|
||||
|
||||
let mut authentication = BTreeMap::new();
|
||||
for (k, v) in r.authentication.clone() {
|
||||
authentication.insert(k, render_json_value_raw(v, vars, cb).await?);
|
||||
authentication.insert(k, render_json_value_raw(v, vars, cb, &opt).await?);
|
||||
}
|
||||
|
||||
let url = render(r.url.as_str(), vars, cb).await?;
|
||||
let url = parse_and_render(r.url.as_str(), vars, cb, &opt).await?;
|
||||
|
||||
Ok(GrpcRequest {
|
||||
url,
|
||||
@@ -61,6 +64,7 @@ pub async fn render_http_request<T: TemplateCallback>(
|
||||
r: &HttpRequest,
|
||||
environment_chain: Vec<Environment>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
) -> yaak_templates::error::Result<HttpRequest> {
|
||||
let vars = &make_vars_hashmap(environment_chain);
|
||||
|
||||
@@ -68,8 +72,8 @@ pub async fn render_http_request<T: TemplateCallback>(
|
||||
for p in r.url_parameters.clone() {
|
||||
url_parameters.push(HttpUrlParameter {
|
||||
enabled: p.enabled,
|
||||
name: render(p.name.as_str(), vars, cb).await?,
|
||||
value: render(p.value.as_str(), vars, cb).await?,
|
||||
name: parse_and_render(p.name.as_str(), vars, cb, &opt).await?,
|
||||
value: parse_and_render(p.value.as_str(), vars, cb, &opt).await?,
|
||||
id: p.id,
|
||||
})
|
||||
}
|
||||
@@ -78,23 +82,23 @@ pub async fn render_http_request<T: TemplateCallback>(
|
||||
for p in r.headers.clone() {
|
||||
headers.push(HttpRequestHeader {
|
||||
enabled: p.enabled,
|
||||
name: render(p.name.as_str(), vars, cb).await?,
|
||||
value: render(p.value.as_str(), vars, cb).await?,
|
||||
name: parse_and_render(p.name.as_str(), vars, cb, &opt).await?,
|
||||
value: parse_and_render(p.value.as_str(), vars, cb, &opt).await?,
|
||||
id: p.id,
|
||||
})
|
||||
}
|
||||
|
||||
let mut body = BTreeMap::new();
|
||||
for (k, v) in r.body.clone() {
|
||||
body.insert(k, render_json_value_raw(v, vars, cb).await?);
|
||||
body.insert(k, render_json_value_raw(v, vars, cb, &opt).await?);
|
||||
}
|
||||
|
||||
let mut authentication = BTreeMap::new();
|
||||
for (k, v) in r.authentication.clone() {
|
||||
authentication.insert(k, render_json_value_raw(v, vars, cb).await?);
|
||||
authentication.insert(k, render_json_value_raw(v, vars, cb, &opt).await?);
|
||||
}
|
||||
|
||||
let url = render(r.url.clone().as_str(), vars, cb).await?;
|
||||
let url = parse_and_render(r.url.clone().as_str(), vars, cb, &opt).await?;
|
||||
|
||||
// This doesn't fit perfectly with the concept of "rendering" but it kind of does
|
||||
let (url, url_parameters) = apply_path_placeholders(&url, url_parameters);
|
||||
@@ -108,11 +112,3 @@ pub async fn render_http_request<T: TemplateCallback>(
|
||||
..r.to_owned()
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn render<T: TemplateCallback>(
|
||||
template: &str,
|
||||
vars: &HashMap<String, String>,
|
||||
cb: &T,
|
||||
) -> yaak_templates::error::Result<String> {
|
||||
parse_and_render(template, vars, cb).await
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
|
||||
message: format!("Installed {name}@{}", pv.version),
|
||||
color: Some(Color::Success),
|
||||
icon: None,
|
||||
timeout: Some(5000),
|
||||
},
|
||||
)?;
|
||||
}
|
||||
@@ -90,6 +91,7 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
|
||||
message: "Failed to import data".to_string(),
|
||||
color: Some(Color::Danger),
|
||||
icon: None,
|
||||
timeout: None,
|
||||
},
|
||||
)?;
|
||||
return Ok(());
|
||||
@@ -103,6 +105,7 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
|
||||
message: format!("Imported data for {} workspaces", results.workspaces.len()),
|
||||
color: Some(Color::Success),
|
||||
icon: None,
|
||||
timeout: Some(5000),
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use tauri::{
|
||||
};
|
||||
use tauri_plugin_opener::OpenerExt;
|
||||
use tokio::sync::mpsc;
|
||||
use crate::error::Result;
|
||||
|
||||
const DEFAULT_WINDOW_WIDTH: f64 = 1100.0;
|
||||
const DEFAULT_WINDOW_HEIGHT: f64 = 600.0;
|
||||
@@ -32,9 +33,9 @@ pub(crate) struct CreateWindowConfig<'s> {
|
||||
pub(crate) fn create_window<R: Runtime>(
|
||||
handle: &AppHandle<R>,
|
||||
config: CreateWindowConfig,
|
||||
) -> WebviewWindow<R> {
|
||||
) -> Result<WebviewWindow<R>> {
|
||||
#[allow(unused_variables)]
|
||||
let menu = app_menu(handle).unwrap();
|
||||
let menu = app_menu(handle)?;
|
||||
|
||||
// This causes the window to not be clickable (in AppImage), so disable on Linux
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
@@ -55,12 +56,13 @@ pub(crate) fn create_window<R: Runtime>(
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
use std::fs;
|
||||
let dir = handle.path().temp_dir().unwrap().join("yaak_sessions").join(key);
|
||||
fs::create_dir_all(dir.clone()).unwrap();
|
||||
let safe_key = format!("{:x}", md5::compute(key.as_bytes()));
|
||||
let dir = handle.path().app_data_dir()?.join("window-sessions").join(safe_key);
|
||||
fs::create_dir_all(&dir)?;
|
||||
win_builder = win_builder.data_directory(dir);
|
||||
}
|
||||
|
||||
// macOS doesn't support data dir so must use this fn instead
|
||||
// macOS doesn't support `data_directory()` so must use this fn instead
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let hash = md5::compute(key.as_bytes());
|
||||
@@ -108,11 +110,11 @@ pub(crate) fn create_window<R: Runtime>(
|
||||
|
||||
if let Some(w) = handle.webview_windows().get(config.label) {
|
||||
info!("Webview with label {} already exists. Focusing existing", config.label);
|
||||
w.set_focus().unwrap();
|
||||
return w.to_owned();
|
||||
w.set_focus()?;
|
||||
return Ok(w.to_owned());
|
||||
}
|
||||
|
||||
let win = win_builder.build().unwrap();
|
||||
let win = win_builder.build()?;
|
||||
|
||||
if let Some(tx) = config.close_tx {
|
||||
win.on_window_event(move |event| match event {
|
||||
@@ -174,10 +176,10 @@ pub(crate) fn create_window<R: Runtime>(
|
||||
}
|
||||
});
|
||||
|
||||
win
|
||||
Ok(win)
|
||||
}
|
||||
|
||||
pub(crate) fn create_main_window(handle: &AppHandle, url: &str) -> WebviewWindow {
|
||||
pub(crate) fn create_main_window(handle: &AppHandle, url: &str) -> Result<WebviewWindow> {
|
||||
let mut counter = 0;
|
||||
let label = loop {
|
||||
let label = format!("{MAIN_WINDOW_PREFIX}{counter}");
|
||||
@@ -211,7 +213,7 @@ pub(crate) fn create_child_window(
|
||||
label: &str,
|
||||
title: &str,
|
||||
inner_size: (f64, f64),
|
||||
) -> WebviewWindow {
|
||||
) -> Result<WebviewWindow> {
|
||||
let app_handle = parent_window.app_handle();
|
||||
let label = format!("{OTHER_WINDOW_PREFIX}_{label}");
|
||||
let scale_factor = parent_window.scale_factor().unwrap();
|
||||
@@ -235,7 +237,7 @@ pub(crate) fn create_child_window(
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let child_window = create_window(&app_handle, config);
|
||||
let child_window = create_window(&app_handle, config)?;
|
||||
|
||||
// NOTE: These listeners will remain active even when the windows close. Unfortunately,
|
||||
// there's no way to unlisten to events for now, so we just have to be defensive.
|
||||
@@ -272,5 +274,5 @@ pub(crate) fn create_child_window(
|
||||
});
|
||||
}
|
||||
|
||||
child_window
|
||||
Ok(child_window)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ publish = false
|
||||
base32 = "0.5.1" # For encoding human-readable key
|
||||
base64 = "0.22.1" # For encoding in the database
|
||||
chacha20poly1305 = "0.10.1"
|
||||
keyring = { workspace = true }
|
||||
keyring = { workspace = true, features = ["apple-native", "windows-native", "sync-secret-service"] }
|
||||
log = "0.4.26"
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
tauri = { workspace = true }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, variables: Array<EnvironmentVariable>, color: string | null, parentModel: string, parentId: string | null, };
|
||||
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, parentModel: string, parentId: string | null, variables: Array<EnvironmentVariable>, color: string | null, };
|
||||
|
||||
export type EnvironmentVariable = { enabled?: boolean, name: string, value: string, id?: string, };
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export type EditorKeymap = "default" | "vim" | "vscode" | "emacs";
|
||||
|
||||
export type EncryptedKey = { encryptedKey: string, };
|
||||
|
||||
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, variables: Array<EnvironmentVariable>, color: string | null, parentModel: string, parentId: string | null, };
|
||||
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, parentModel: string, parentId: string | null, variables: Array<EnvironmentVariable>, color: string | null, };
|
||||
|
||||
export type EnvironmentVariable = { enabled?: boolean, name: string, value: string, id?: string, };
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { Environment, Folder, GrpcRequest, HttpRequest, WebsocketRequest, Workspace } from "./gen_models";
|
||||
import type { Environment, Folder, GrpcRequest, HttpRequest, WebsocketRequest, Workspace } from "./gen_models.js";
|
||||
|
||||
export type BatchUpsertResult = { workspaces: Array<Workspace>, environments: Array<Environment>, folders: Array<Folder>, httpRequests: Array<HttpRequest>, grpcRequests: Array<GrpcRequest>, websocketRequests: Array<WebsocketRequest>, };
|
||||
|
||||
@@ -541,10 +541,15 @@ pub struct Environment {
|
||||
|
||||
pub name: String,
|
||||
pub public: bool,
|
||||
pub variables: Vec<EnvironmentVariable>,
|
||||
pub color: Option<String>,
|
||||
#[deprecated(
|
||||
note = "parent_model is used instead. This field will be removed when schema field is added for sync/export."
|
||||
)]
|
||||
#[ts(skip)]
|
||||
pub base: bool,
|
||||
pub parent_model: String,
|
||||
pub parent_id: Option<String>,
|
||||
pub variables: Vec<EnvironmentVariable>,
|
||||
pub color: Option<String>,
|
||||
}
|
||||
|
||||
impl UpsertModelInfo for Environment {
|
||||
@@ -603,6 +608,8 @@ impl UpsertModelInfo for Environment {
|
||||
Self: Sized,
|
||||
{
|
||||
let variables: String = row.get("variables")?;
|
||||
let parent_model = row.get("parent_model")?;
|
||||
let base = parent_model == "workspace";
|
||||
Ok(Self {
|
||||
id: row.get("id")?,
|
||||
model: row.get("model")?,
|
||||
@@ -610,11 +617,16 @@ impl UpsertModelInfo for Environment {
|
||||
created_at: row.get("created_at")?,
|
||||
updated_at: row.get("updated_at")?,
|
||||
parent_id: row.get("parent_id")?,
|
||||
parent_model: row.get("parent_model")?,
|
||||
parent_model,
|
||||
color: row.get("color")?,
|
||||
name: row.get("name")?,
|
||||
public: row.get("public")?,
|
||||
variables: serde_json::from_str(variables.as_str()).unwrap_or_default(),
|
||||
|
||||
// Deprecated field, but we need to keep it around for a couple of versions
|
||||
// for compatibility because sync/export don't have a schema field
|
||||
#[allow(deprecated)]
|
||||
base,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,15 +49,7 @@ impl<'a> DbContext<'a> {
|
||||
info!("Upserted {} websocket_requests", imported_resources.websocket_requests.len());
|
||||
}
|
||||
|
||||
if environments.len() > 0 {
|
||||
for x in environments {
|
||||
let x = self.upsert_environment(&x, source)?;
|
||||
imported_resources.environments.push(x.clone());
|
||||
}
|
||||
info!("Upserted {} environments", imported_resources.environments.len());
|
||||
}
|
||||
|
||||
// Do folders last so it doesn't cause the UI to render empty folders before populating
|
||||
// Do folders after their children so the UI doesn't render empty folders before populating
|
||||
// immediately after.
|
||||
if folders.len() > 0 {
|
||||
for v in folders {
|
||||
@@ -67,6 +59,15 @@ impl<'a> DbContext<'a> {
|
||||
info!("Upserted {} folders", imported_resources.folders.len());
|
||||
}
|
||||
|
||||
// Do environments last because they can depend on many models (requests, folders, etc)
|
||||
if environments.len() > 0 {
|
||||
for x in environments {
|
||||
let x = self.upsert_environment(&x, source)?;
|
||||
imported_resources.environments.push(x.clone());
|
||||
}
|
||||
info!("Upserted {} environments", imported_resources.environments.len());
|
||||
}
|
||||
|
||||
Ok(imported_resources)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ impl<'a> DbContext<'a> {
|
||||
|
||||
/// Lists environments and will create a base environment if one doesn't exist
|
||||
pub fn list_environments_ensure_base(&self, workspace_id: &str) -> Result<Vec<Environment>> {
|
||||
let mut environments =
|
||||
self.find_many::<Environment>(EnvironmentIden::WorkspaceId, workspace_id, None)?;
|
||||
let mut environments = self.list_environments_dangerous(workspace_id)?;
|
||||
|
||||
let base_environment = environments.iter().find(|e| e.parent_model == "workspace");
|
||||
|
||||
@@ -59,6 +58,11 @@ impl<'a> DbContext<'a> {
|
||||
Ok(environments)
|
||||
}
|
||||
|
||||
/// List environments for a workspace. Prefer list_environments_ensure_base()
|
||||
fn list_environments_dangerous(&self, workspace_id: &str) -> Result<Vec<Environment>> {
|
||||
Ok(self.find_many::<Environment>(EnvironmentIden::WorkspaceId, workspace_id, None)?)
|
||||
}
|
||||
|
||||
pub fn delete_environment(
|
||||
&self,
|
||||
environment: &Environment,
|
||||
@@ -93,7 +97,7 @@ impl<'a> DbContext<'a> {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
self.list_environments_ensure_base(&environment.workspace_id)
|
||||
self.list_environments_dangerous(&environment.workspace_id)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter(|e| {
|
||||
@@ -131,8 +135,9 @@ impl<'a> DbContext<'a> {
|
||||
let mut name = environment.name.clone();
|
||||
match (environment.parent_model.as_str(), environment.parent_id.as_deref()) {
|
||||
("folder", Some(folder_id)) => {
|
||||
let folder = self.get_folder(folder_id)?;
|
||||
name = format!("{} Environment", folder.name);
|
||||
if let Ok(folder) = self.get_folder(folder_id) {
|
||||
name = format!("{} Environment", folder.name);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,11 @@ publish = false
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.22.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 = "0.4.21"
|
||||
md5 = "0.7.0"
|
||||
path-slash = "0.2.1"
|
||||
@@ -17,21 +20,18 @@ regex = "1.10.6"
|
||||
reqwest = { workspace = true, features = ["json"] }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
sha2 = { workspace = true }
|
||||
tauri = { workspace = true }
|
||||
tauri-plugin-shell = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "process"] }
|
||||
tokio-tungstenite = "0.26.1"
|
||||
ts-rs = { workspace = true, features = ["import-esm"] }
|
||||
sha2 = { workspace = true }
|
||||
yaak-common = { workspace = true }
|
||||
yaak-crypto = { workspace = true }
|
||||
yaak-models = { workspace = true }
|
||||
yaak-templates = { workspace = true }
|
||||
zip-extract = "0.4.0"
|
||||
chrono = { workspace = true }
|
||||
hex = { workspace = true }
|
||||
keyring = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
tauri-plugin = { workspace = true, features = ["build"] }
|
||||
|
||||
@@ -437,7 +437,7 @@ export type SetKeyValueRequest = { key: string, value: string, };
|
||||
|
||||
export type SetKeyValueResponse = {};
|
||||
|
||||
export type ShowToastRequest = { message: string, color?: Color, icon?: Icon, };
|
||||
export type ShowToastRequest = { message: string, color?: Color, icon?: Icon, timeout?: number, };
|
||||
|
||||
export type TemplateFunction = { name: string, description?: string,
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, variables: Array<EnvironmentVariable>, color: string | null, parentModel: string, parentId: string | null, };
|
||||
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, parentModel: string, parentId: string | null, variables: Array<EnvironmentVariable>, color: string | null, };
|
||||
|
||||
export type EnvironmentVariable = { enabled?: boolean, name: string, value: string, id?: string, };
|
||||
|
||||
|
||||
@@ -494,6 +494,9 @@ pub struct ShowToastRequest {
|
||||
|
||||
#[ts(optional)]
|
||||
pub icon: Option<Icon>,
|
||||
|
||||
#[ts(optional)]
|
||||
pub timeout: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
|
||||
@@ -39,7 +39,7 @@ use yaak_models::render::make_vars_hashmap;
|
||||
use yaak_models::util::generate_id;
|
||||
use yaak_templates::error::Error::RenderError;
|
||||
use yaak_templates::error::Result as TemplateResult;
|
||||
use yaak_templates::render_json_value_raw;
|
||||
use yaak_templates::{RenderErrorBehavior, RenderOptions, render_json_value_raw};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PluginManager {
|
||||
@@ -601,7 +601,11 @@ impl PluginManager {
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Preview,
|
||||
);
|
||||
let rendered_values = render_json_value_raw(json!(values), vars, &cb).await?;
|
||||
// We don't want to fail for this op because the UI will not be able to list any auth types then
|
||||
let render_opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::ReturnEmpty,
|
||||
};
|
||||
let rendered_values = render_json_value_raw(json!(values), vars, &cb, &render_opt).await?;
|
||||
let context_id = format!("{:x}", md5::compute(request_id.to_string()));
|
||||
let event = self
|
||||
.send_to_plugin_and_wait(
|
||||
@@ -643,6 +647,9 @@ impl PluginManager {
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Preview,
|
||||
),
|
||||
&RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let results = self.get_http_authentication_summaries(window).await?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, variables: Array<EnvironmentVariable>, color: string | null, parentModel: string, parentId: string | null, };
|
||||
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, parentModel: string, parentId: string | null, variables: Array<EnvironmentVariable>, color: string | null, };
|
||||
|
||||
export type EnvironmentVariable = { enabled?: boolean, name: string, value: string, id?: string, };
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::error::Error::UnknownModel;
|
||||
use crate::error::Result;
|
||||
use chrono::NaiveDateTime;
|
||||
use log::warn;
|
||||
use log::{debug, warn};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_yaml::{Mapping, Value};
|
||||
use sha1::{Digest, Sha1};
|
||||
@@ -84,8 +84,9 @@ impl<'de> Deserialize<'de> for SyncModel {
|
||||
}
|
||||
|
||||
fn migrate_environment(obj: &mut Mapping) {
|
||||
match obj.get("base") {
|
||||
Some(Value::Bool(base)) => {
|
||||
match (obj.get("base"), obj.get("parentModel")) {
|
||||
(Some(Value::Bool(base)), None) => {
|
||||
debug!("Migrating legacy environment {}", serde_yaml::to_string(obj).unwrap());
|
||||
if *base {
|
||||
obj.insert("parentModel".into(), "workspace".into());
|
||||
} else {
|
||||
@@ -220,7 +221,7 @@ impl TryFrom<AnyModel> for SyncModel {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod placeholder_tests {
|
||||
mod migration_tests {
|
||||
use crate::error::Result;
|
||||
use crate::models::SyncModel;
|
||||
|
||||
@@ -271,6 +272,30 @@ color: null
|
||||
_ => panic!("expected sub environment"),
|
||||
}
|
||||
|
||||
let raw = r#"
|
||||
type: environment
|
||||
model: environment
|
||||
id: ev_fAUS49FUN2
|
||||
parentId: fld_123
|
||||
parentModel: folder
|
||||
workspaceId: wk_kfSI3JDHd7
|
||||
createdAt: 2025-01-11T17:02:58.012792
|
||||
updatedAt: 2025-07-23T20:00:46.049649
|
||||
name: Folder Environment
|
||||
public: true
|
||||
base: false
|
||||
variables: []
|
||||
color: null
|
||||
"#;
|
||||
let m: SyncModel = serde_yaml::from_str(raw)?;
|
||||
match m {
|
||||
SyncModel::Environment(env) => {
|
||||
assert_eq!(env.parent_model, "folder".to_string());
|
||||
assert_eq!(env.parent_id, Some("fld_123".to_string()));
|
||||
}
|
||||
_ => panic!("expected folder environment"),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,3 +19,4 @@ tokio = { workspace = true, features = ["macros", "rt"] }
|
||||
ts-rs = { workspace = true }
|
||||
wasm-bindgen = { version = "0.2.100", features = ["serde-serialize"] }
|
||||
serde-wasm-bindgen = "0.6.5"
|
||||
log = "0.4.27"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::error::Error::{RenderStackExceededError, VariableNotFound};
|
||||
use crate::error::Result;
|
||||
use crate::{Parser, Token, Tokens, Val};
|
||||
use log::warn;
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
@@ -21,21 +22,22 @@ pub async fn render_json_value_raw<T: TemplateCallback>(
|
||||
v: serde_json::Value,
|
||||
vars: &HashMap<String, String>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
) -> Result<serde_json::Value> {
|
||||
let v = match v {
|
||||
serde_json::Value::String(s) => json!(parse_and_render(&s, vars, cb).await?),
|
||||
serde_json::Value::String(s) => json!(parse_and_render(&s, vars, cb, opt).await?),
|
||||
serde_json::Value::Array(a) => {
|
||||
let mut new_a = Vec::new();
|
||||
for v in a {
|
||||
new_a.push(Box::pin(render_json_value_raw(v, vars, cb)).await?)
|
||||
new_a.push(Box::pin(render_json_value_raw(v, vars, cb, opt)).await?)
|
||||
}
|
||||
json!(new_a)
|
||||
}
|
||||
serde_json::Value::Object(o) => {
|
||||
let mut new_o = serde_json::Map::new();
|
||||
for (k, v) in o {
|
||||
let key = Box::pin(parse_and_render(&k, vars, cb)).await?;
|
||||
let value = Box::pin(render_json_value_raw(v, vars, cb)).await?;
|
||||
let key = Box::pin(parse_and_render(&k, vars, cb, opt)).await?;
|
||||
let value = Box::pin(render_json_value_raw(v, vars, cb, opt)).await?;
|
||||
new_o.insert(key, value);
|
||||
}
|
||||
json!(new_o)
|
||||
@@ -49,30 +51,55 @@ async fn parse_and_render_at_depth<T: TemplateCallback>(
|
||||
template: &str,
|
||||
vars: &HashMap<String, String>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
depth: usize,
|
||||
) -> Result<String> {
|
||||
let mut p = Parser::new(template);
|
||||
let tokens = p.parse()?;
|
||||
render(tokens, vars, cb, depth + 1).await
|
||||
render(tokens, vars, cb, opt, depth + 1).await
|
||||
}
|
||||
|
||||
pub async fn parse_and_render<T: TemplateCallback>(
|
||||
template: &str,
|
||||
vars: &HashMap<String, String>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
) -> Result<String> {
|
||||
parse_and_render_at_depth(template, vars, cb, 1).await
|
||||
parse_and_render_at_depth(template, vars, cb, opt, 1).await
|
||||
}
|
||||
|
||||
pub enum RenderErrorBehavior {
|
||||
Throw,
|
||||
ReturnEmpty,
|
||||
}
|
||||
|
||||
pub struct RenderOptions {
|
||||
pub error_behavior: RenderErrorBehavior,
|
||||
}
|
||||
|
||||
impl RenderErrorBehavior {
|
||||
pub fn handle(&self, r: Result<String>) -> Result<String> {
|
||||
match (self, r) {
|
||||
(_, Ok(v)) => Ok(v),
|
||||
(RenderErrorBehavior::Throw, Err(e)) => Err(e),
|
||||
(RenderErrorBehavior::ReturnEmpty, Err(e)) => {
|
||||
warn!("Error rendering string: {}", e);
|
||||
Ok("".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn render<T: TemplateCallback>(
|
||||
tokens: Tokens,
|
||||
vars: &HashMap<String, String>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
mut depth: usize,
|
||||
) -> Result<String> {
|
||||
depth += 1;
|
||||
if depth > MAX_DEPTH {
|
||||
return Err(RenderStackExceededError);
|
||||
return opt.error_behavior.handle(Err(RenderStackExceededError));
|
||||
}
|
||||
|
||||
let mut doc_str: Vec<String> = Vec::new();
|
||||
@@ -80,7 +107,10 @@ pub async fn render<T: TemplateCallback>(
|
||||
for t in tokens.tokens {
|
||||
match t {
|
||||
Token::Raw { text } => doc_str.push(text),
|
||||
Token::Tag { val } => doc_str.push(render_value(val, &vars, cb, depth).await?),
|
||||
Token::Tag { val } => {
|
||||
let val = render_value(val, &vars, cb, opt, depth).await;
|
||||
doc_str.push(opt.error_behavior.handle(val)?)
|
||||
}
|
||||
Token::Eof => {}
|
||||
}
|
||||
}
|
||||
@@ -92,16 +122,17 @@ async fn render_value<T: TemplateCallback>(
|
||||
val: Val,
|
||||
vars: &HashMap<String, String>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
depth: usize,
|
||||
) -> Result<String> {
|
||||
let v = match val {
|
||||
Val::Str { text } => {
|
||||
let r = Box::pin(parse_and_render_at_depth(&text, vars, cb, depth)).await?;
|
||||
let r = Box::pin(parse_and_render_at_depth(&text, vars, cb, opt, depth)).await?;
|
||||
r.to_string()
|
||||
}
|
||||
Val::Var { name } => match vars.get(name.as_str()) {
|
||||
Some(v) => {
|
||||
let r = Box::pin(parse_and_render_at_depth(v, vars, cb, depth)).await?;
|
||||
let r = Box::pin(parse_and_render_at_depth(v, vars, cb, opt, depth)).await?;
|
||||
r.to_string()
|
||||
}
|
||||
None => return Err(VariableNotFound(name)),
|
||||
@@ -113,13 +144,13 @@ async fn render_value<T: TemplateCallback>(
|
||||
Val::Bool { value } => serde_json::Value::Bool(value),
|
||||
Val::Null => serde_json::Value::Null,
|
||||
_ => serde_json::Value::String(
|
||||
Box::pin(render_value(a.value, vars, cb, depth)).await?,
|
||||
Box::pin(render_value(a.value, vars, cb, opt, depth)).await?,
|
||||
),
|
||||
};
|
||||
resolved_args.insert(a.name, v);
|
||||
}
|
||||
let result = cb.run(name.as_str(), resolved_args.clone()).await?;
|
||||
Box::pin(parse_and_render_at_depth(&result, vars, cb, depth)).await?
|
||||
Box::pin(parse_and_render_at_depth(&result, vars, cb, opt, depth)).await?
|
||||
}
|
||||
Val::Bool { value } => value.to_string(),
|
||||
Val::Null => "".into(),
|
||||
@@ -163,7 +194,10 @@ mod parse_and_render_tests {
|
||||
let template = "";
|
||||
let vars = HashMap::new();
|
||||
let result = "";
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await?, result.to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -173,7 +207,10 @@ mod parse_and_render_tests {
|
||||
let template = "Hello World!";
|
||||
let vars = HashMap::new();
|
||||
let result = "Hello World!";
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await?, result.to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -183,7 +220,10 @@ mod parse_and_render_tests {
|
||||
let template = "${[ foo ]}";
|
||||
let vars = HashMap::from([("foo".to_string(), "bar".to_string())]);
|
||||
let result = "bar";
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await?, result.to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -197,7 +237,10 @@ mod parse_and_render_tests {
|
||||
vars.insert("baz".to_string(), "baz".to_string());
|
||||
|
||||
let result = "foo: bar: baz";
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await?, result.to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -206,9 +249,11 @@ mod parse_and_render_tests {
|
||||
let empty_cb = EmptyCB {};
|
||||
let template = "${[ foo ]}";
|
||||
let vars = HashMap::new();
|
||||
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &empty_cb).await,
|
||||
parse_and_render(template, &vars, &empty_cb, &opt).await,
|
||||
Err(VariableNotFound("foo".to_string()))
|
||||
);
|
||||
Ok(())
|
||||
@@ -220,9 +265,11 @@ mod parse_and_render_tests {
|
||||
let template = "${[ foo ]}";
|
||||
let mut vars = HashMap::new();
|
||||
vars.insert("foo".to_string(), "${[ foo ]}".to_string());
|
||||
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &empty_cb).await,
|
||||
parse_and_render(template, &vars, &empty_cb, &opt).await,
|
||||
Err(RenderStackExceededError)
|
||||
);
|
||||
Ok(())
|
||||
@@ -234,7 +281,10 @@ mod parse_and_render_tests {
|
||||
let template = "hello ${[ word ]} world!";
|
||||
let vars = HashMap::from([("word".to_string(), "cruel".to_string())]);
|
||||
let result = "hello cruel world!";
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await?, result.to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -243,6 +293,9 @@ mod parse_and_render_tests {
|
||||
let vars = HashMap::new();
|
||||
let template = r#"${[ say_hello(a='John', b='Kate') ]}"#;
|
||||
let result = r#"say_hello: 2, Some(String("John")) Some(String("Kate"))"#;
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
struct CB {}
|
||||
impl TemplateCallback for CB {
|
||||
@@ -263,7 +316,7 @@ mod parse_and_render_tests {
|
||||
Ok(arg_value.to_string())
|
||||
}
|
||||
}
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await?, result);
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}, &opt).await?, result);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -272,6 +325,9 @@ mod parse_and_render_tests {
|
||||
let vars = HashMap::new();
|
||||
let template = r#"${[ upper(foo='bar') ]}"#;
|
||||
let result = r#""BAR""#;
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
struct CB {}
|
||||
impl TemplateCallback for CB {
|
||||
async fn run(
|
||||
@@ -296,7 +352,7 @@ mod parse_and_render_tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await?, result.to_string());
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -306,9 +362,16 @@ mod parse_and_render_tests {
|
||||
vars.insert("foo".to_string(), "bar".to_string());
|
||||
let template = r#"${[ upper(foo=b64'Zm9vICdiYXInIGJheg') ]}"#;
|
||||
let result = r#""FOO 'BAR' BAZ""#;
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
struct CB {}
|
||||
impl TemplateCallback for CB {
|
||||
async fn run(&self, fn_name: &str, args: HashMap<String, serde_json::Value>) -> Result<String> {
|
||||
async fn run(
|
||||
&self,
|
||||
fn_name: &str,
|
||||
args: HashMap<String, serde_json::Value>,
|
||||
) -> Result<String> {
|
||||
Ok(match fn_name {
|
||||
"upper" => args["foo"].to_string().to_uppercase(),
|
||||
_ => "".to_string(),
|
||||
@@ -325,7 +388,7 @@ mod parse_and_render_tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await?, result.to_string());
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -335,9 +398,17 @@ mod parse_and_render_tests {
|
||||
vars.insert("foo".to_string(), "bar".to_string());
|
||||
let template = r#"${[ upper(foo='${[ foo ]}') ]}"#;
|
||||
let result = r#""BAR""#;
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
struct CB {}
|
||||
impl TemplateCallback for CB {
|
||||
async fn run(&self, fn_name: &str, args: HashMap<String, serde_json::Value>) -> Result<String> {
|
||||
async fn run(
|
||||
&self,
|
||||
fn_name: &str,
|
||||
args: HashMap<String, serde_json::Value>,
|
||||
) -> Result<String> {
|
||||
Ok(match fn_name {
|
||||
"secret" => "abc".to_string(),
|
||||
"upper" => args["foo"].to_string().to_uppercase(),
|
||||
@@ -355,7 +426,7 @@ mod parse_and_render_tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await?, result.to_string());
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -365,9 +436,17 @@ mod parse_and_render_tests {
|
||||
vars.insert("foo".to_string(), "bar".to_string());
|
||||
let template = r#"${[ no_op(inner='${[ foo ]}') ]}"#;
|
||||
let result = r#""bar""#;
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
struct CB {}
|
||||
impl TemplateCallback for CB {
|
||||
async fn run(&self, fn_name: &str, args: HashMap<String, serde_json::Value>) -> Result<String> {
|
||||
async fn run(
|
||||
&self,
|
||||
fn_name: &str,
|
||||
args: HashMap<String, serde_json::Value>,
|
||||
) -> Result<String> {
|
||||
Ok(match fn_name {
|
||||
"no_op" => args["inner"].to_string(),
|
||||
_ => "".to_string(),
|
||||
@@ -384,7 +463,7 @@ mod parse_and_render_tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await?, result.to_string());
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -393,9 +472,17 @@ mod parse_and_render_tests {
|
||||
let vars = HashMap::new();
|
||||
let template = r#"${[ upper(foo=secret()) ]}"#;
|
||||
let result = r#""ABC""#;
|
||||
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
struct CB {}
|
||||
impl TemplateCallback for CB {
|
||||
async fn run(&self, fn_name: &str, args: HashMap<String, serde_json::Value>) -> Result<String> {
|
||||
async fn run(
|
||||
&self,
|
||||
fn_name: &str,
|
||||
args: HashMap<String, serde_json::Value>,
|
||||
) -> Result<String> {
|
||||
Ok(match fn_name {
|
||||
"secret" => "abc".to_string(),
|
||||
"upper" => args["foo"].to_string().to_uppercase(),
|
||||
@@ -412,8 +499,7 @@ mod parse_and_render_tests {
|
||||
Ok(arg_value.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await?, result.to_string());
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}, &opt).await?, result.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -421,10 +507,17 @@ mod parse_and_render_tests {
|
||||
async fn render_fn_err() -> Result<()> {
|
||||
let vars = HashMap::new();
|
||||
let template = r#"hello ${[ error() ]}"#;
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
struct CB {}
|
||||
impl TemplateCallback for CB {
|
||||
async fn run(&self, _fn_name: &str, _args: HashMap<String, serde_json::Value>) -> Result<String> {
|
||||
async fn run(
|
||||
&self,
|
||||
_fn_name: &str,
|
||||
_args: HashMap<String, serde_json::Value>,
|
||||
) -> Result<String> {
|
||||
Err(RenderError("Failed to do it!".to_string()))
|
||||
}
|
||||
|
||||
@@ -439,7 +532,7 @@ mod parse_and_render_tests {
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &CB {}).await,
|
||||
parse_and_render(template, &vars, &CB {}, &opt).await,
|
||||
Err(RenderError("Failed to do it!".to_string()))
|
||||
);
|
||||
Ok(())
|
||||
@@ -449,14 +542,21 @@ mod parse_and_render_tests {
|
||||
#[cfg(test)]
|
||||
mod render_json_value_raw_tests {
|
||||
use crate::error::Result;
|
||||
use crate::{TemplateCallback, render_json_value_raw};
|
||||
use crate::{
|
||||
RenderErrorBehavior, RenderOptions, TemplateCallback, parse_and_render,
|
||||
render_json_value_raw,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
|
||||
struct EmptyCB {}
|
||||
|
||||
impl TemplateCallback for EmptyCB {
|
||||
async fn run(&self, _fn_name: &str, _args: HashMap<String, serde_json::Value>) -> Result<String> {
|
||||
async fn run(
|
||||
&self,
|
||||
_fn_name: &str,
|
||||
_args: HashMap<String, serde_json::Value>,
|
||||
) -> Result<String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@@ -475,8 +575,11 @@ mod render_json_value_raw_tests {
|
||||
let v = json!("${[a]}");
|
||||
let mut vars = HashMap::new();
|
||||
vars.insert("a".to_string(), "aaa".to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
assert_eq!(render_json_value_raw(v, &vars, &EmptyCB {}).await?, json!("aaa"));
|
||||
assert_eq!(render_json_value_raw(v, &vars, &EmptyCB {}, &opt).await?, json!("aaa"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -485,8 +588,11 @@ mod render_json_value_raw_tests {
|
||||
let v = json!(["${[a]}", "${[a]}"]);
|
||||
let mut vars = HashMap::new();
|
||||
vars.insert("a".to_string(), "aaa".to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
let result = render_json_value_raw(v, &vars, &EmptyCB {}).await?;
|
||||
let result = render_json_value_raw(v, &vars, &EmptyCB {}, &opt).await?;
|
||||
assert_eq!(result, json!(["aaa", "aaa"]));
|
||||
|
||||
Ok(())
|
||||
@@ -497,8 +603,11 @@ mod render_json_value_raw_tests {
|
||||
let v = json!({"${[a]}": "${[a]}"});
|
||||
let mut vars = HashMap::new();
|
||||
vars.insert("a".to_string(), "aaa".to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
let result = render_json_value_raw(v, &vars, &EmptyCB {}).await?;
|
||||
let result = render_json_value_raw(v, &vars, &EmptyCB {}, &opt).await?;
|
||||
assert_eq!(result, json!({"aaa": "aaa"}));
|
||||
|
||||
Ok(())
|
||||
@@ -516,8 +625,11 @@ mod render_json_value_raw_tests {
|
||||
]);
|
||||
let mut vars = HashMap::new();
|
||||
vars.insert("a".to_string(), "aaa".to_string());
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
};
|
||||
|
||||
let result = render_json_value_raw(v, &vars, &EmptyCB {}).await?;
|
||||
let result = render_json_value_raw(v, &vars, &EmptyCB {}, &opt).await?;
|
||||
assert_eq!(
|
||||
result,
|
||||
json!([
|
||||
@@ -532,4 +644,17 @@ mod render_json_value_raw_tests {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn render_opt_return_empty() -> Result<()> {
|
||||
let vars = HashMap::new();
|
||||
let opt = RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::ReturnEmpty,
|
||||
};
|
||||
|
||||
let result = parse_and_render("DNE: ${[hello]}", &vars, &EmptyCB {}, &opt).await?;
|
||||
assert_eq!(result, "DNE: ".to_string());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ use yaak_plugins::events::{
|
||||
};
|
||||
use yaak_plugins::manager::PluginManager;
|
||||
use yaak_plugins::template_callback::PluginTemplateCallback;
|
||||
use yaak_templates::{RenderErrorBehavior, RenderOptions};
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) async fn upsert_request<R: Runtime>(
|
||||
@@ -126,6 +127,9 @@ pub(crate) async fn send<R: Runtime>(
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Send,
|
||||
),
|
||||
&RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -202,6 +206,9 @@ pub(crate) async fn connect<R: Runtime>(
|
||||
&PluginWindowContext::new(&window),
|
||||
RenderPurpose::Send,
|
||||
),
|
||||
&RenderOptions {
|
||||
error_behavior: RenderErrorBehavior::Throw,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@ use crate::error::Result;
|
||||
use std::collections::BTreeMap;
|
||||
use yaak_models::models::{Environment, HttpRequestHeader, WebsocketRequest};
|
||||
use yaak_models::render::make_vars_hashmap;
|
||||
use yaak_templates::{parse_and_render, render_json_value_raw, TemplateCallback};
|
||||
use yaak_templates::{parse_and_render, render_json_value_raw, RenderOptions, TemplateCallback};
|
||||
|
||||
pub async fn render_websocket_request<T: TemplateCallback>(
|
||||
r: &WebsocketRequest,
|
||||
environment_chain: Vec<Environment>,
|
||||
cb: &T,
|
||||
opt: &RenderOptions,
|
||||
) -> Result<WebsocketRequest> {
|
||||
let vars = &make_vars_hashmap(environment_chain);
|
||||
|
||||
@@ -15,20 +16,20 @@ pub async fn render_websocket_request<T: TemplateCallback>(
|
||||
for p in r.headers.clone() {
|
||||
headers.push(HttpRequestHeader {
|
||||
enabled: p.enabled,
|
||||
name: parse_and_render(&p.name, vars, cb).await?,
|
||||
value: parse_and_render(&p.value, vars, cb).await?,
|
||||
name: parse_and_render(&p.name, vars, cb, opt).await?,
|
||||
value: parse_and_render(&p.value, vars, cb, opt).await?,
|
||||
id: p.id,
|
||||
})
|
||||
}
|
||||
|
||||
let mut authentication = BTreeMap::new();
|
||||
for (k, v) in r.authentication.clone() {
|
||||
authentication.insert(k, render_json_value_raw(v, vars, cb).await?);
|
||||
authentication.insert(k, render_json_value_raw(v, vars, cb, opt).await?);
|
||||
}
|
||||
|
||||
let url = parse_and_render(r.url.as_str(), vars, cb).await?;
|
||||
let url = parse_and_render(r.url.as_str(), vars, cb, opt).await?;
|
||||
|
||||
let message = parse_and_render(&r.message.clone(), vars, cb).await?;
|
||||
let message = parse_and_render(&r.message.clone(), vars, cb, opt).await?;
|
||||
|
||||
Ok(WebsocketRequest {
|
||||
url,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { jotaiStore } from '../lib/jotai';
|
||||
import { showPrompt } from '../lib/prompt';
|
||||
import { setWorkspaceSearchParams } from '../lib/setWorkspaceSearchParams';
|
||||
|
||||
export const createEnvironmentAndActivate = createFastMutation<
|
||||
export const createSubEnvironmentAndActivate = createFastMutation<
|
||||
string | null,
|
||||
unknown,
|
||||
Environment | null
|
||||
@@ -46,7 +46,6 @@ export const createEnvironmentAndActivate = createFastMutation<
|
||||
return; // Was not created
|
||||
}
|
||||
|
||||
console.log('NAVIGATING', jotaiStore.get(activeWorkspaceIdAtom), environmentId);
|
||||
setWorkspaceSearchParams({ environment_id: environmentId });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useAtomValue } from 'jotai';
|
||||
import type { KeyboardEvent, ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { createFolder } from '../commands/commands';
|
||||
import { createEnvironmentAndActivate } from '../commands/createEnvironment';
|
||||
import { createSubEnvironmentAndActivate } from '../commands/createEnvironment';
|
||||
import { openSettings } from '../commands/openSettings';
|
||||
import { switchWorkspace } from '../commands/switchWorkspace';
|
||||
import { useActiveCookieJar } from '../hooks/useActiveCookieJar';
|
||||
@@ -130,7 +130,7 @@ export function CommandPaletteDialog({ onClose }: { onClose: () => void }) {
|
||||
{
|
||||
key: 'environment.create',
|
||||
label: 'Create Environment',
|
||||
onSelect: () => createEnvironmentAndActivate.mutate(baseEnvironment),
|
||||
onSelect: () => createSubEnvironmentAndActivate.mutate(baseEnvironment),
|
||||
},
|
||||
{
|
||||
key: 'sidebar.toggle',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { duplicateModel, patchModel } from '@yaakapp-internal/models';
|
||||
import classNames from 'classnames';
|
||||
import type { ReactNode } from 'react';
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { createEnvironmentAndActivate } from '../commands/createEnvironment';
|
||||
import { createSubEnvironmentAndActivate } from '../commands/createEnvironment';
|
||||
import { useEnvironmentsBreakdown } from '../hooks/useEnvironmentsBreakdown';
|
||||
import { deleteModelWithConfirm } from '../lib/deleteModelWithConfirm';
|
||||
import { isBaseEnvironment } from '../lib/model_util';
|
||||
@@ -42,7 +42,7 @@ export const EnvironmentEditDialog = function ({ initialEnvironment }: Props) {
|
||||
|
||||
const handleCreateEnvironment = async () => {
|
||||
if (baseEnvironment == null) return;
|
||||
const id = await createEnvironmentAndActivate.mutateAsync(baseEnvironment);
|
||||
const id = await createSubEnvironmentAndActivate.mutateAsync(baseEnvironment);
|
||||
if (id != null) setSelectedEnvironmentId(id);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ const details: Record<
|
||||
commercial_use: null,
|
||||
invalid_license: { label: 'License Error', color: 'danger' },
|
||||
personal_use: { label: 'Personal Use', color: 'notice' },
|
||||
trialing: { label: 'Personal Use', color: 'info' },
|
||||
trialing: { label: 'Trialing', color: 'info' },
|
||||
};
|
||||
|
||||
export function LicenseBadge() {
|
||||
@@ -46,11 +46,6 @@ function LicenseBadgeCmp() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// User is trialing but has already seen the message, so hide badge
|
||||
if (check.data.type === 'trialing') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const detail = details[check.data.type];
|
||||
if (detail == null) {
|
||||
return null;
|
||||
@@ -59,9 +54,7 @@ function LicenseBadgeCmp() {
|
||||
return (
|
||||
<BadgeButton
|
||||
color={detail.color}
|
||||
onClick={async () => {
|
||||
openSettings.mutate('license');
|
||||
}}
|
||||
onClick={() => openSettings.mutate('license')}
|
||||
>
|
||||
{detail.label}
|
||||
</BadgeButton>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import classNames from 'classnames';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { FocusTrap } from 'focus-trap-react';
|
||||
import * as m from 'motion/react-m';
|
||||
import type { ReactNode } from 'react';
|
||||
import React from 'react';
|
||||
@@ -47,7 +47,11 @@ export function Overlay({
|
||||
return (
|
||||
<Portal name={portalName}>
|
||||
{open && (
|
||||
<FocusTrap>
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
allowOutsideClick: true, // So we can still click toasts and things
|
||||
}}
|
||||
>
|
||||
<m.div
|
||||
className={classNames('fixed inset-0', zIndexes[zIndex])}
|
||||
initial={{ opacity: 0 }}
|
||||
|
||||
@@ -35,17 +35,17 @@ function SettingsLicenseCmp() {
|
||||
{check.data?.type === 'commercial_use' ? (
|
||||
<Banner color="success">Your license is active 🥳</Banner>
|
||||
) : check.data?.type == 'trialing' ? (
|
||||
<Banner color="success" className="flex flex-col gap-3 max-w-lg">
|
||||
<p className="select-text">
|
||||
<Banner color="info" className="flex flex-col gap-3 max-w-lg">
|
||||
<p>
|
||||
<strong>
|
||||
{pluralizeCount('day', differenceInDays(check.data.end, new Date()))} remaining
|
||||
</strong>{' '}
|
||||
on trial
|
||||
on your commercial-use trial
|
||||
</p>
|
||||
</Banner>
|
||||
) : check.data?.type == 'personal_use' ? (
|
||||
<Banner color="success" className="flex flex-col gap-3 max-w-lg">
|
||||
<p>Your free trial has ended</p>
|
||||
<Banner color="notice" className="flex flex-col gap-3 max-w-lg">
|
||||
<p>You are able to use Yaak for personal use only</p>
|
||||
</Banner>
|
||||
) : null}
|
||||
|
||||
@@ -62,7 +62,7 @@ function SettingsLicenseCmp() {
|
||||
<p>
|
||||
<Link
|
||||
noUnderline
|
||||
href="https://yaak.app/pricing?s=learn"
|
||||
href={`https://yaak.app/pricing?s=learn&t=${check.data?.type ?? ''}`}
|
||||
className="text-sm text-notice opacity-80 hover:opacity-100"
|
||||
>
|
||||
Learn More
|
||||
@@ -90,7 +90,7 @@ function SettingsLicenseCmp() {
|
||||
<Button
|
||||
color="secondary"
|
||||
size="sm"
|
||||
onClick={() => openUrl('https://yaak.app/dashboard?s=support')}
|
||||
onClick={() => openUrl('https://yaak.app/dashboard?s=support&ref=app.yaak.desktop')}
|
||||
rightSlot={<Icon icon="external_link" />}
|
||||
>
|
||||
Direct Support
|
||||
@@ -98,16 +98,20 @@ function SettingsLicenseCmp() {
|
||||
</HStack>
|
||||
) : (
|
||||
<HStack space={2}>
|
||||
<Button color="primary" size="sm" onClick={toggleActivateFormVisible}>
|
||||
Activate
|
||||
<Button variant="border" color="secondary" size="sm" onClick={toggleActivateFormVisible}>
|
||||
Activate License
|
||||
</Button>
|
||||
<Button
|
||||
color="secondary"
|
||||
size="sm"
|
||||
onClick={() => openUrl('https://yaak.app/pricing?s=purchase&ref=app.yaak.desktop')}
|
||||
color="primary"
|
||||
onClick={() =>
|
||||
openUrl(
|
||||
`https://yaak.app/pricing?s=purchase&ref=app.yaak.desktop&t=${check.data?.type ?? ''}`,
|
||||
)
|
||||
}
|
||||
rightSlot={<Icon icon="external_link" />}
|
||||
>
|
||||
Purchase
|
||||
Purchase License
|
||||
</Button>
|
||||
</HStack>
|
||||
)}
|
||||
|
||||
@@ -7,7 +7,11 @@ import { memo, useCallback, useMemo } from 'react';
|
||||
import { openWorkspaceFromSyncDir } from '../commands/openWorkspaceFromSyncDir';
|
||||
import { openWorkspaceSettings } from '../commands/openWorkspaceSettings';
|
||||
import { switchWorkspace } from '../commands/switchWorkspace';
|
||||
import { activeWorkspaceAtom, activeWorkspaceMetaAtom } from '../hooks/useActiveWorkspace';
|
||||
import {
|
||||
activeWorkspaceAtom,
|
||||
activeWorkspaceIdAtom,
|
||||
activeWorkspaceMetaAtom,
|
||||
} from '../hooks/useActiveWorkspace';
|
||||
import { useCreateWorkspace } from '../hooks/useCreateWorkspace';
|
||||
import { useDeleteSendHistory } from '../hooks/useDeleteSendHistory';
|
||||
import { showDialog } from '../lib/dialog';
|
||||
@@ -95,7 +99,12 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
|
||||
if (workspaceId == null) return;
|
||||
|
||||
const settings = jotaiStore.get(settingsAtom);
|
||||
if (typeof settings.openWorkspaceNewWindow === 'boolean') {
|
||||
const activeWorkspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||
if (workspaceId === activeWorkspaceId) {
|
||||
// Always open a new window if the selected one is already active
|
||||
switchWorkspace.mutate({ workspaceId, inNewWindow: true });
|
||||
return;
|
||||
} else if (typeof settings.openWorkspaceNewWindow === 'boolean') {
|
||||
switchWorkspace.mutate({ workspaceId, inNewWindow: settings.openWorkspaceNewWindow });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import classNames from 'classnames';
|
||||
import type { ButtonProps } from './Button';
|
||||
import { Button } from './Button';
|
||||
|
||||
export function BadgeButton(props: ButtonProps) {
|
||||
return <Button size="2xs" variant="border" className="!rounded-full mx-1" {...props} />;
|
||||
export function BadgeButton({ className, ...props }: ButtonProps) {
|
||||
return (
|
||||
<Button
|
||||
size="2xs"
|
||||
variant="border"
|
||||
className={classNames(className, '!rounded-full mx-1 !px-3')}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export function Confirm({
|
||||
onChange={setConfirm}
|
||||
label={
|
||||
<>
|
||||
Type <strong>{requireTyping}</strong> to confirm
|
||||
Type <strong className="select-auto cursor-text">{requireTyping}</strong> to confirm
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -48,10 +48,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.select-all * {
|
||||
/*@apply select-all;*/
|
||||
}
|
||||
|
||||
a,
|
||||
a[href] * {
|
||||
@apply cursor-pointer !important;
|
||||
|
||||
Reference in New Issue
Block a user