Compare commits

...

66 Commits

Author SHA1 Message Date
Gregory Schier
a00b4ae232 Always open new window when clicking current workspace:
https://feedback.yaak.app/p/dont-trigger-workspace-change-when-clicking-same-workspace
2025-10-04 06:47:50 -07:00
Gregory Schier
998b5cf78a Add RenderOptions and RenderErrorBehavior to ensure auth UI still loads with missing variables 2025-10-04 06:29:29 -07:00
Gregory Schier
b4deae6e8d Batch insert environments last, to handle folder case 2025-10-04 05:48:08 -07:00
Gregory Schier
87fdf17010 Fix plugin refresh toasts having no timeout 2025-10-04 05:47:39 -07:00
Gregory Schier
c6975a9e8b Allow toast interaction when dialog is open 2025-10-04 05:47:16 -07:00
Gregory Schier
b44ac55bc2 Fix broken environment migration 2025-10-04 05:47:00 -07:00
Gregory Schier
9c65c95ba9 Fix batch import potentially creating a useless base environment 2025-10-04 05:46:42 -07:00
Gregory Schier
7beb9f4e69 Merge remote-tracking branch 'origin/main' 2025-10-04 05:46:13 -07:00
Gregory Schier
dbecd74f46 Allow selecting confirm text 2025-10-04 05:46:06 -07:00
Gregory Schier
6826ee1672 Revise README for clarity and updated features
Updated the README to enhance clarity and organization, including feature descriptions and removing outdated content.
2025-10-03 10:29:19 -07:00
Gregory Schier
a12ae7ef56 Update README 2025-10-03 09:53:40 -07:00
gschier
dbc100409d Deploying to main from @ mountain-loop/yaak@6b87cd9655 🚀 2025-10-03 16:52:47 +00:00
Gregory Schier
6b87cd9655 Merge remote-tracking branch 'origin/main' 2025-10-03 09:52:31 -07:00
Gregory Schier
7ce2cdc9cc Update tiers 2025-10-03 09:52:26 -07:00
gschier
1f4e38b7a7 Deploying to main from @ mountain-loop/yaak@0013a0797b 🚀 2025-10-03 16:50:09 +00:00
Gregory Schier
0013a0797b Merge remote-tracking branch 'origin/main' 2025-10-03 09:49:45 -07:00
Gregory Schier
5e9b14dc0b Update workflow 2025-10-03 09:49:39 -07:00
gschier
b7cfb0db13 Deploying to main from @ mountain-loop/yaak@8948bfbf45 🚀 2025-10-03 16:46:35 +00:00
Gregory Schier
8948bfbf45 Merge remote-tracking branch 'origin/main' 2025-10-03 09:46:19 -07:00
Gregory Schier
4218e90bf4 Set active-only to true in sponsors workflow 2025-10-03 09:44:56 -07:00
gschier
2172d7ac60 Deploying to main from @ mountain-loop/yaak@5e45cb4908 🚀 2025-10-03 16:42:45 +00:00
Gregory Schier
5e45cb4908 Update sponsors workflow to use SPONSORS_PAT secret 2025-10-03 09:42:21 -07:00
Gregory Schier
d662883fdd Update README 2025-10-03 09:41:17 -07:00
Gregory Schier
f83f3d4682 Refine Yaak description in README
Updated the description of Yaak in the README.
2025-10-03 09:36:22 -07:00
gschier
e03c745093 Deploying to main from @ mountain-loop/yaak@73b9d699ed 🚀 2025-10-03 16:35:10 +00:00
Gregory Schier
73b9d699ed Merge remote-tracking branch 'origin/main' 2025-10-03 09:34:35 -07:00
Gregory Schier
5a7b9aba2f Sponsors workflow 2025-10-03 09:34:22 -07:00
Gregory Schier
cf433b26a5 Revise sponsor section in README.md
Updated sponsor section in README.md to include new sponsor images and links.
2025-10-03 09:32:36 -07:00
gschier
573035b17d Deploying to main from @ mountain-loop/yaak@3844fec968 🚀 2025-10-03 16:31:42 +00:00
Gregory Schier
a267c0c53f Update README 2025-10-03 09:31:21 -07:00
gschier
328563f4e6 Deploying to main from @ mountain-loop/yaak@3844fec968 🚀 2025-10-03 16:30:09 +00:00
Gregory Schier
3844fec968 Merge remote-tracking branch 'origin/main' 2025-10-03 09:29:35 -07:00
Gregory Schier
8557a2477b Sponsors workflow 2025-10-03 09:29:31 -07:00
Gregory Schier
d02519ab74 Update README header 2025-10-03 09:19:17 -07:00
Gregory Schier
1a1751c23e Fix window path issue 2025-10-02 08:25:00 -07:00
Gregory Schier
17de0678b0 Remove unused import from window.rs 2025-10-02 08:05:07 -07:00
Gregory Schier
20bb89de33 Try fix oauth window creation 2025-10-02 07:45:50 -07:00
Gregory Schier
8a634b1056 Add back environment.base (#260) 2025-10-02 06:04:27 -07:00
Gregory Schier
57f231ca00 Add trial status to links 2025-10-01 21:14:26 -07:00
Gregory Schier
cb1c0e4d8c Fix ref 2025-10-01 21:07:44 -07:00
Gregory Schier
2152cf87d7 Tweak license badge and fix keyring dep 2025-10-01 21:01:27 -07:00
Gregory Schier
8662b230e7 Oops, actually fix 2025-10-01 16:54:05 -07:00
Gregory Schier
3a8a6484c7 Fix release windows signing 2025-10-01 16:42:38 -07:00
Gregory Schier
f92594a16d Fix release tauri config 2025-10-01 10:51:26 -07:00
Gregory Schier
7969fcb76c Alias keyring function 2025-10-01 10:22:06 -07:00
Gregory Schier
eafefb1894 Fix setting 2025-10-01 09:44:18 -07:00
Gregory Schier
9a94a15c82 Integrated update experience (#259) 2025-10-01 09:36:36 -07:00
Gregory Schier
757d28c235 License and updater Cargo features (#258) 2025-09-29 22:08:05 -07:00
Gregory Schier
6c79c1ef3f Rework licensing flows to be more friendly 2025-09-29 15:40:15 -07:00
Gregory Schier
7262eccac5 Fix keyring errors 2025-09-29 10:53:20 -07:00
Gregory Schier
4989a5f759 Add back cmd palette icon 2025-09-29 09:39:15 -07:00
Gregory Schier
0b0b05d29c Add keyring template function 2025-09-29 08:56:24 -07:00
Gregory Schier
b3d6d87bee Delete duplicate folder environments on upsert 2025-09-29 07:48:07 -07:00
Gregory Schier
6abbdc8726 Filter out current variable from autocomplete and show sub environment variables in base environment autocomplete 2025-09-29 06:57:04 -07:00
Gregory Schier
b9613591f8 Update resource links in README.md 2025-09-28 15:38:14 -07:00
Gregory Schier
eb555989ac Force grpcurl to posix paths 2025-09-25 08:40:57 -07:00
Gregory Schier
b77f1375fd Fix test with timezone 2025-09-25 08:03:07 -07:00
Gregory Schier
3c438b3da7 Add cmdctrl+Backspace for request delete 2025-09-25 07:28:01 -07:00
Gregory Schier
df15543c80 Explicitly set the request layout (#257) 2025-09-25 07:23:52 -07:00
Gregory Schier
73ad86c6b9 Fix workspace settings scroll with long description 2025-09-25 07:22:42 -07:00
Gregory Schier
615de8b3cc Update importers for folder environment and fix tests 2025-09-25 07:12:50 -07:00
Gregory Schier
2418bd0672 Update README.md 2025-09-24 11:03:23 -07:00
Gregory Schier
b3414ee60f Fix ephemeral response body reading 2025-09-22 14:07:25 -07:00
Gregory Schier
8fe50959b9 Add migrate for base environment to sync logic 2025-09-22 11:15:32 -07:00
Gregory Schier
523e7dcf16 Add bootstrap to release script (to fix lint) 2025-09-22 08:57:05 -07:00
Gregory Schier
7951f3a7bd Tweak light theme, high contrast themes, and fix env null reference 2025-09-22 08:36:40 -07:00
150 changed files with 2192 additions and 779 deletions

View File

@@ -72,9 +72,16 @@ jobs:
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Some things (eg. WASM package) requires building before lint will work
- name: Run bootstrap
run: npm run bootstrap
- name: Run lint
run: npm run lint
- name: Run tests
run: npm test
- name: Set version
run: npm run replace-version
env:
@@ -106,5 +113,5 @@ jobs:
releaseName: 'Release __VERSION__'
releaseBody: '[Changelog __VERSION__](https://yaak.app/blog/__VERSION__)'
releaseDraft: true
prerelease: false
args: ${{ matrix.args }}
prerelease: true
args: '${{ matrix.args }} --config ./src-tauri/tauri.commercial.conf.json'

43
.github/workflows/sponsors.yml vendored Normal file
View 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>&nbsp;&nbsp;'
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>&nbsp;&nbsp;'
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: '.'

View File

@@ -1,34 +1,71 @@
# 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:&#x2F;&#x2F;github.com&#x2F;MVST-Solutions.png" width="80px" alt="User avatar: MVST-Solutions" /></a>&nbsp;&nbsp;<a href="https://github.com/dharsanb"><img src="https:&#x2F;&#x2F;github.com&#x2F;dharsanb.png" width="80px" alt="User avatar: dharsanb" /></a>&nbsp;&nbsp;<a href="https://github.com/railwayapp"><img src="https:&#x2F;&#x2F;github.com&#x2F;railwayapp.png" width="80px" alt="User avatar: railwayapp" /></a>&nbsp;&nbsp;<a href="https://github.com/caseyamcl"><img src="https:&#x2F;&#x2F;github.com&#x2F;caseyamcl.png" width="80px" alt="User avatar: caseyamcl" /></a>&nbsp;&nbsp;<a href="https://github.com/andriyor"><img src="https:&#x2F;&#x2F;github.com&#x2F;andriyor.png" width="80px" alt="User avatar: andriyor" /></a>&nbsp;&nbsp;<a href="https://github.com/"><img src="https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;JamesIves&#x2F;github-sponsors-readme-action&#x2F;dev&#x2F;.github&#x2F;assets&#x2F;placeholder.png" width="80px" alt="User avatar: " /></a>&nbsp;&nbsp;<!-- sponsors-premium -->
</p>
<p align="center">
<!-- sponsors-base --><a href="https://github.com/seanwash"><img src="https:&#x2F;&#x2F;github.com&#x2F;seanwash.png" width="50px" alt="User avatar: seanwash" /></a>&nbsp;&nbsp;<a href="https://github.com/jerath"><img src="https:&#x2F;&#x2F;github.com&#x2F;jerath.png" width="50px" alt="User avatar: jerath" /></a>&nbsp;&nbsp;<a href="https://github.com/itsa-sh"><img src="https:&#x2F;&#x2F;github.com&#x2F;itsa-sh.png" width="50px" alt="User avatar: itsa-sh" /></a>&nbsp;&nbsp;<a href="https://github.com/dmmulroy"><img src="https:&#x2F;&#x2F;github.com&#x2F;dmmulroy.png" width="50px" alt="User avatar: dmmulroy" /></a>&nbsp;&nbsp;<a href="https://github.com/timcole"><img src="https:&#x2F;&#x2F;github.com&#x2F;timcole.png" width="50px" alt="User avatar: timcole" /></a>&nbsp;&nbsp;<a href="https://github.com/VLZH"><img src="https:&#x2F;&#x2F;github.com&#x2F;VLZH.png" width="50px" alt="User avatar: VLZH" /></a>&nbsp;&nbsp;<a href="https://github.com/terasaka2k"><img src="https:&#x2F;&#x2F;github.com&#x2F;terasaka2k.png" width="50px" alt="User avatar: terasaka2k" /></a>&nbsp;&nbsp;<!-- sponsors-base -->
</p>
![Yaak API Client](https://yaak.app/static/screenshot.png)
## 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, its 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.
![366149288-f18e963f-0b68-4ecb-b8b8-cb71aa9aec02](https://github.com/user-attachments/assets/ca83b7ad-5708-411b-8faf-e36b365841a4)
## 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)
- [Documentation](https://feedback.yaak.app/help)
- [Yaak vs Postman](https://yaak.app/blog/postman-alternative)
- [Yaak vs Postman](https://yaak.app/alternatives/postman)
- [Yaak vs Bruno](https://yaak.app/alternatives/bruno)
- [Yaak vs Insomnia](https://yaak.app/alternatives/insomnia)

16
package-lock.json generated
View File

@@ -38,6 +38,7 @@
"plugins/template-function-uuid",
"plugins/template-function-xml",
"plugins/themes-yaak",
"src-tauri",
"src-tauri/yaak-crypto",
"src-tauri/yaak-git",
"src-tauri/yaak-fonts",
@@ -812,6 +813,12 @@
"w3c-keyname": "^2.2.4"
}
},
"node_modules/@date-fns/tz": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/@date-fns/tz/-/tz-1.4.1.tgz",
"integrity": "sha512-P5LUNhtbj6YfI3iJjw5EL9eUAG6OitD0W3fWQcpQjDRc/QIsL0tRNuO1PcDvPccWL1fSTXXdE1ds+l95DV/OFA==",
"license": "MIT"
},
"node_modules/@esbuild/aix-ppc64": {
"version": "0.25.6",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.6.tgz",
@@ -4245,6 +4252,10 @@
"resolved": "src-tauri/yaak-sync",
"link": true
},
"node_modules/@yaakapp-internal/tauri": {
"resolved": "src-tauri",
"link": true
},
"node_modules/@yaakapp-internal/templates": {
"resolved": "src-tauri/yaak-templates",
"link": true
@@ -18949,6 +18960,7 @@
"name": "@yaak/template-function-timestamp",
"version": "0.1.0",
"dependencies": {
"@date-fns/tz": "^1.4.1",
"date-fns": "^4.1.0"
}
},
@@ -18984,6 +18996,10 @@
"name": "@yaak/themes-yaak",
"version": "0.1.0"
},
"src-tauri": {
"name": "@yaakapp-internal/tauri",
"version": "1.0.0"
},
"src-tauri/yaak-crypto": {
"name": "@yaakapp-internal/crypto",
"version": "1.0.0"

View File

@@ -37,6 +37,7 @@
"plugins/template-function-uuid",
"plugins/template-function-xml",
"plugins/themes-yaak",
"src-tauri",
"src-tauri/yaak-crypto",
"src-tauri/yaak-git",
"src-tauri/yaak-fonts",
@@ -53,10 +54,11 @@
"scripts": {
"start": "npm run app-dev",
"app-build": "tauri build",
"app-dev": "tauri dev --no-watch --config ./src-tauri/tauri-dev.conf.json",
"app-dev": "tauri dev --no-watch --config ./src-tauri/tauri.development.conf.json",
"migration": "node scripts/create-migration.cjs",
"build": "npm run --workspaces --if-present build",
"build-plugins": "npm run --workspaces --if-present build",
"test": "npm run --workspaces --if-present test",
"icons": "run-p icons:*",
"icons:dev": "tauri icon src-tauri/icons/icon.png --output src-tauri/icons/release",
"icons:release": "tauri icon src-tauri/icons/icon-dev.png --output src-tauri/icons/dev",

View File

@@ -12,6 +12,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint": "eslint . --ext .ts,.tsx"
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
}
}

View File

@@ -12,6 +12,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
}
}

View File

@@ -41,8 +41,8 @@ export async function convert(request: Partial<GrpcRequest>, allProtoFiles: stri
if (protoDir) {
inferredIncludes.add(protoDir);
} else {
inferredIncludes.add(path.join(f, '..'));
inferredIncludes.add(path.join(f, '..', '..'));
inferredIncludes.add(path.posix.join(f, '..'));
inferredIncludes.add(path.posix.join(f, '..', '..'));
}
}

View File

@@ -12,6 +12,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -12,6 +12,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -12,6 +12,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
}
}

View File

@@ -12,7 +12,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
},
"dependencies": {
"jsonwebtoken": "^9.0.2"

View File

@@ -12,6 +12,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -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'));

View File

@@ -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() {

View File

@@ -12,7 +12,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
},
"dependencies": {
"jsonpath-plus": "^10.3.0"

View File

@@ -7,7 +7,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
},
"dependencies": {
"@xmldom/xmldom": "^0.9.8",

View File

@@ -7,7 +7,8 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
},
"dependencies": {
"shell-quote": "^1.8.1"

View File

@@ -7,7 +7,8 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
},
"dependencies": {
"yaml": "^2.4.2"

View File

@@ -30,18 +30,25 @@ export function convertInsomniaV5(parsed: any) {
model: 'workspace',
name: parsed.name,
description: meta.description || undefined,
...importHeaders(parsed),
...importAuthentication(parsed),
});
// Import environments
resources.environments.push(
importEnvironment(parsed.environments, meta.id, true),
...(parsed.environments.subEnvironments ?? []).map((r: any) => importEnvironment(r, meta.id)),
);
// Import folders
const nextFolder = (children: any[], parentId: string) => {
for (const child of children ?? []) {
if (!isJSObject(child)) continue;
if (Array.isArray(child.children)) {
resources.folders.push(importFolder(child, meta.id, parentId));
const { folder, environment } = importFolder(child, meta.id, parentId);
resources.folders.push(folder);
if (environment) resources.environments.push(environment);
nextFolder(child.children, child.meta.id);
} else if (child.method) {
resources.httpRequests.push(importHttpRequest(child, meta.id, parentId));
@@ -191,8 +198,8 @@ function importWebsocketRequest(
};
}
function importHeaders(r: any) {
const headers = (r.headers ?? [])
function importHeaders(obj: any) {
const headers = (obj.headers ?? [])
.map((h: any) => ({
enabled: !h.disabled,
name: h.name ?? '',
@@ -202,19 +209,19 @@ function importHeaders(r: any) {
return { headers } as const;
}
function importAuthentication(r: any) {
function importAuthentication(obj: any) {
let authenticationType: string | null = null;
let authentication = {};
if (r.authentication?.type === 'bearer') {
if (obj.authentication?.type === 'bearer') {
authenticationType = 'bearer';
authentication = {
token: convertSyntax(r.authentication.token),
token: convertSyntax(obj.authentication.token),
};
} else if (r.authentication?.type === 'basic') {
} else if (obj.authentication?.type === 'basic') {
authenticationType = 'basic';
authentication = {
username: convertSyntax(r.authentication.username),
password: convertSyntax(r.authentication.password),
username: convertSyntax(obj.authentication.username),
password: convertSyntax(obj.authentication.password),
};
}
@@ -225,22 +232,50 @@ function importFolder(
f: any,
workspaceId: string,
parentId: string,
): PartialImportResources['folders'][0] {
): {
folder: PartialImportResources['folders'][0];
environment: PartialImportResources['environments'][0] | null;
} {
const id = f.meta?.id ?? f._id;
const created = f.meta?.created ?? f.created;
const updated = f.meta?.modified ?? f.updated;
const sortKey = f.meta?.sortKey ?? f.sortKey;
let environment: PartialImportResources['environments'][0] | null = null;
if (Object.keys(f.environment ?? {}).length > 0) {
environment = {
id: convertId(id + 'folder'),
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
workspaceId: convertId(workspaceId),
public: true,
parentModel: 'folder',
parentId: convertId(id),
model: 'environment',
name: 'Folder Environment',
variables: Object.entries(f.environment ?? {}).map(([name, value]) => ({
enabled: true,
name,
value: `${value}`,
})),
};
}
return {
model: 'folder',
id: convertId(id),
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
folderId: parentId === workspaceId ? null : convertId(parentId),
sortPriority: sortKey,
workspaceId: convertId(workspaceId),
description: f.description || undefined,
name: f.name,
folder: {
model: 'folder',
id: convertId(id),
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
folderId: parentId === workspaceId ? null : convertId(parentId),
sortPriority: sortKey,
workspaceId: convertId(workspaceId),
description: f.description || undefined,
name: f.name,
...importAuthentication(f),
...importHeaders(f),
},
environment,
};
}
@@ -263,7 +298,8 @@ function importEnvironment(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
sortPriority: sortKey, // Will be added to Yaak later
base: isParent ?? e.parentId === workspaceId,
parentModel: isParent ? 'workspace' : 'environment',
parentId: null,
model: 'environment',
name: e.name,
variables: Object.entries(e.data ?? {}).map(([name, value]) => ({

View File

@@ -38,6 +38,8 @@ collection:
name: foo
value: bar
disabled: false
environment:
folder_env_var: testing
- name: New Request
meta:
id: req_e3f8cdbd58784a539dd4c1e127d73451

View File

@@ -2,7 +2,6 @@
"resources": {
"environments": [
{
"base": true,
"createdAt": "2025-05-14T04:45:24.903",
"id": "GENERATE_ID::env_e46dc73e8ccda30ca132153e8f11183bd08119ce",
"model": "environment",
@@ -10,6 +9,26 @@
"public": true,
"updatedAt": "2025-05-14T04:45:24.903",
"variables": [],
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
"parentId": null,
"parentModel": "workspace"
},
{
"createdAt": "2025-05-16T16:48:12.298",
"id": "GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7folder",
"model": "environment",
"name": "Folder Environment",
"parentId": "GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7",
"parentModel": "folder",
"public": true,
"updatedAt": "2025-05-16T16:49:02.427",
"variables": [
{
"enabled": true,
"name": "folder_env_var",
"value": "testing"
}
],
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
}
],
@@ -22,7 +41,16 @@
"name": "My Folder",
"sortPriority": -1747414092298,
"updatedAt": "2025-05-16T16:49:02.427",
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
"authentication": {},
"authenticationType": null,
"headers": [
{
"enabled": true,
"name": "foo",
"value": "bar"
}
]
}
],
"grpcRequests": [],
@@ -80,7 +108,10 @@
"id": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
"model": "workspace",
"name": "Debugging",
"updatedAt": "2025-05-14T04:45:24.902"
"updatedAt": "2025-05-14T04:45:24.902",
"authentication": {},
"authenticationType": null,
"headers": []
}
]
}

View File

@@ -4,11 +4,12 @@
{
"createdAt": "2025-01-13T15:15:43.767",
"updatedAt": "2025-01-13T15:15:55.209",
"base": true,
"public": true,
"id": "GENERATE_ID::env_20945044d3c8497ca8b717bef750987e",
"model": "environment",
"name": "Base Environment",
"parentId": null,
"parentModel": "workspace",
"variables": [
{
"enabled": true,
@@ -21,11 +22,12 @@
{
"createdAt": "2025-01-13T15:15:58.515",
"updatedAt": "2025-01-13T15:16:34.705",
"base": false,
"public": true,
"id": "GENERATE_ID::env_6f7728bb7fc04d558d668e954d756ea2",
"model": "environment",
"name": "Production",
"parentId": null,
"parentModel": "environment",
"sortPriority": 1736781358515,
"variables": [
{
@@ -39,8 +41,9 @@
{
"createdAt": "2025-01-13T15:16:14.707",
"updatedAt": "2025-01-13T15:16:31.078",
"base": false,
"public": true,
"parentId": null,
"parentModel": "environment",
"id": "GENERATE_ID::env_976a8b6eb5d44fb6a20150f65c32d243",
"model": "environment",
"name": "Staging",
@@ -64,7 +67,10 @@
"model": "folder",
"name": "Top Level",
"sortPriority": -1736781404718,
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53"
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53",
"authentication": {},
"authenticationType": null,
"headers": []
}
],
"grpcRequests": [
@@ -165,7 +171,10 @@
"description": "This is the description",
"id": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53",
"model": "workspace",
"name": "Dummy"
"name": "Dummy",
"authentication": {},
"authenticationType": null,
"headers": []
}
]
}

View File

@@ -7,7 +7,8 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
},
"dependencies": {
"openapi-to-postmanv2": "^5.0.0",

View File

@@ -8,6 +8,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
}
}

View File

@@ -57,9 +57,11 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin
const rawDescription = info.description;
const description =
typeof rawDescription === 'object' && rawDescription !== null && 'content' in rawDescription
typeof rawDescription === 'object' && rawDescription != null && 'content' in rawDescription
? String(rawDescription.content)
: String(rawDescription);
: rawDescription == null
? undefined
: String(rawDescription);
const workspace: ExportResources['workspaces'][0] = {
model: 'workspace',
@@ -75,6 +77,8 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin
id: generateId('environment'),
name: 'Global Variables',
workspaceId: workspace.id,
parentModel: 'workspace',
parentId: null,
variables:
toArray<{ key: string; value: string }>(root.variable).map((v) => ({
name: v.key,

View File

@@ -13,7 +13,9 @@
"model": "environment",
"name": "Global Variables",
"variables": [],
"workspaceId": "GENERATE_ID::WORKSPACE_0"
"workspaceId": "GENERATE_ID::WORKSPACE_0",
"parentId": null,
"parentModel": "workspace"
}
],
"httpRequests": [
@@ -25,6 +27,7 @@
"name": "Request 1",
"method": "GET",
"url": "",
"sortPriority": 2,
"urlParameters": [],
"body": {},
"bodyType": null,
@@ -39,6 +42,7 @@
"folderId": "GENERATE_ID::FOLDER_0",
"name": "Request 2",
"method": "GET",
"sortPriority": 3,
"url": "",
"urlParameters": [],
"body": {},
@@ -52,6 +56,7 @@
"id": "GENERATE_ID::HTTP_REQUEST_2",
"workspaceId": "GENERATE_ID::WORKSPACE_0",
"folderId": null,
"sortPriority": 4,
"name": "Request 3",
"method": "GET",
"url": "",
@@ -69,6 +74,7 @@
"workspaceId": "GENERATE_ID::WORKSPACE_0",
"id": "GENERATE_ID::FOLDER_0",
"name": "Top Folder",
"sortPriority": 0,
"folderId": null
},
{
@@ -76,6 +82,7 @@
"workspaceId": "GENERATE_ID::WORKSPACE_0",
"id": "GENERATE_ID::FOLDER_1",
"name": "Nested Folder",
"sortPriority": 1,
"folderId": "GENERATE_ID::FOLDER_0"
}
]

View File

@@ -13,6 +13,8 @@
"workspaceId": "GENERATE_ID::WORKSPACE_1",
"model": "environment",
"name": "Global Variables",
"parentId": null,
"parentModel": "workspace",
"variables": [
{
"name": "COLLECTION VARIABLE",
@@ -28,6 +30,7 @@
"workspaceId": "GENERATE_ID::WORKSPACE_1",
"folderId": null,
"name": "Form URL",
"sortPriority": 0,
"method": "POST",
"url": "example.com/:foo/:bar",
"urlParameters": [

View File

@@ -7,6 +7,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
}
}

View File

@@ -66,7 +66,20 @@ export function migrateImport(contents: string) {
}
}
return { resources: parsed.resources }; // Should already be in the correct format
// Migrate v4 to v5
for (const environment of parsed.resources.environments ?? []) {
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 && environment.parentModel == null) {
environment.parentModel = 'environment';
environment.parentId = null;
delete environment.base;
}
}
return { resources: parsed.resources };
}
function isJSObject(obj: unknown) {

View File

@@ -31,16 +31,20 @@ describe('importer-yaak', () => {
JSON.stringify({
yaakSchema: 2,
resources: {
environments: [{
id: 'e_1',
workspaceId: 'w_1',
name: 'Production',
variables: [{ name: 'E1', value: 'E1!' }],
}],
workspaces: [{
id: 'w_1',
variables: [{ name: 'W1', value: 'W1!' }],
}],
environments: [
{
id: 'e_1',
workspaceId: 'w_1',
name: 'Production',
variables: [{ name: 'E1', value: 'E1!' }],
},
],
workspaces: [
{
id: 'w_1',
variables: [{ name: 'W1', value: 'W1!' }],
},
],
},
}),
);
@@ -48,21 +52,98 @@ describe('importer-yaak', () => {
expect(imported).toEqual(
expect.objectContaining({
resources: {
workspaces: [{
id: 'w_1',
}],
environments: [{
id: 'e_1',
base: false,
workspaceId: 'w_1',
name: 'Production',
variables: [{ name: 'E1', value: 'E1!' }],
}, {
id: 'GENERATE_ID::base_env_w_1',
workspaceId: 'w_1',
name: 'Global Variables',
variables: [{ name: 'W1', value: 'W1!' }],
}],
workspaces: [
{
id: 'w_1',
},
],
environments: [
{
id: 'e_1',
workspaceId: 'w_1',
name: 'Production',
variables: [{ name: 'E1', value: 'E1!' }],
parentModel: 'environment',
parentId: null,
},
{
id: 'GENERATE_ID::base_env_w_1',
workspaceId: 'w_1',
name: 'Global Variables',
variables: [{ name: 'W1', value: 'W1!' }],
},
],
},
}),
);
});
test('converts schema 4 to 5', () => {
const imported = migrateImport(
JSON.stringify({
yaakSchema: 2,
resources: {
environments: [
{
id: 'e_1',
workspaceId: 'w_1',
base: false,
name: 'Production',
variables: [{ name: 'E1', value: 'E1!' }],
},
{
id: 'e_1',
workspaceId: 'w_1',
base: true,
name: 'Global Variables',
variables: [{ name: 'G1', value: 'G1!' }],
},
],
folders: [
{
id: 'f_1',
},
],
workspaces: [
{
id: 'w_1',
},
],
},
}),
);
expect(imported).toEqual(
expect.objectContaining({
resources: {
workspaces: [
{
id: 'w_1',
},
],
folders: [
{
id: 'f_1',
},
],
environments: [
{
id: 'e_1',
workspaceId: 'w_1',
name: 'Production',
variables: [{ name: 'E1', value: 'E1!' }],
parentModel: 'environment',
parentId: null,
},
{
id: 'e_1',
workspaceId: 'w_1',
name: 'Global Variables',
parentModel: 'workspace',
parentId: null,
variables: [{ name: 'G1', value: 'G1!' }],
},
],
},
}),
);

View File

@@ -7,6 +7,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -7,6 +7,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -7,6 +7,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -7,6 +7,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -7,7 +7,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
},
"dependencies": {
"jsonpath-plus": "^10.3.0"

View File

@@ -7,6 +7,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -7,6 +7,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
}
}

View File

@@ -7,6 +7,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -7,7 +7,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
},
"dependencies": {
"jsonpath-plus": "^10.3.0",

View File

@@ -5,9 +5,11 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx",
"test": "vitest --run tests"
},
"dependencies": {
"@date-fns/tz": "^1.4.1",
"date-fns": "^4.1.0"
}
}

View File

@@ -1,6 +1,7 @@
import type { TemplateFunctionArg } from '@yaakapp-internal/plugins';
import type { PluginDefinition } from '@yaakapp/api';
import type { ContextFn } from 'date-fns';
import {
addDays,
addHours,
@@ -24,7 +25,8 @@ const dateArg: TemplateFunctionArg = {
name: 'date',
label: 'Timestamp',
optional: true,
description: 'Can be a timestamp in milliseconds, ISO string, or anything parseable by JS `new Date()`',
description:
'Can be a timestamp in milliseconds, ISO string, or anything parseable by JS `new Date()`',
placeholder: new Date().toISOString(),
};
@@ -148,8 +150,12 @@ export function calculateDatetime(args: { date?: string; expression?: string }):
return jsDate.toISOString();
}
export function formatDatetime(args: { date?: string; format?: string }): string {
export function formatDatetime(args: {
date?: string;
format?: string;
in?: ContextFn<Date>;
}): string {
const { date, format = 'yyyy-MM-dd HH:mm:ss' } = args;
const d = parseDateString(date ?? '');
return formatDate(d, String(format));
return formatDate(d, String(format), { in: args.in });
}

View File

@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import { calculateDatetime, formatDatetime } from '../src';
import { tz } from "@date-fns/tz";
describe('formatDatetime', () => {
it('returns formatted current date', () => {
@@ -13,12 +14,12 @@ describe('formatDatetime', () => {
});
it('returns formatted specific timestamp', () => {
const result = formatDatetime({ date: '1752435296000' });
const result = formatDatetime({ date: '1752435296000', in: tz('America/Vancouver') });
expect(result).toBe('2025-07-13 12:34:56');
});
it('returns formatted specific timestamp with decimals', () => {
const result = formatDatetime({ date: '1752435296000.19' });
const result = formatDatetime({ date: '1752435296000.19', in: tz('America/Vancouver') });
expect(result).toBe('2025-07-13 12:34:56');
});

View File

@@ -7,7 +7,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
},
"dependencies": {
"uuid": "^11.1.0"

View File

@@ -7,7 +7,7 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
},
"dependencies": {
"@xmldom/xmldom": "^0.9.8",

View File

@@ -7,6 +7,6 @@
"scripts": {
"build": "yaakcli build",
"dev": "yaakcli dev",
"lint":"eslint . --ext .ts,.tsx"
"lint":"tsc --noEmit && eslint . --ext .ts,.tsx"
}
}

View File

@@ -2,6 +2,49 @@ import type { PluginDefinition } from '@yaakapp/api';
export const plugin: PluginDefinition = {
themes: [
{
id: 'high-contrast',
label: 'High Contrast Light',
dark: false,
base: {
surface: 'white',
surfaceHighlight: 'hsl(218,24%,93%)',
text: 'black',
textSubtle: 'hsl(217,24%,40%)',
textSubtlest: 'hsl(217,24%,40%)',
border: 'hsl(217,22%,50%)',
borderSubtle: 'hsl(217,22%,60%)',
primary: 'hsl(267,67%,47%)',
secondary: 'hsl(218,18%,53%)',
info: 'hsl(206,100%,36%)',
success: 'hsl(155,100%,26%)',
notice: 'hsl(45,100%,31%)',
warning: 'hsl(30,99%,34%)',
danger: 'hsl(334,100%,35%)',
},
},
{
id: 'high-contrast-dark',
label: 'High Contrast Dark',
dark: true,
base: {
surface: 'hsl(0,0%,0%)',
surfaceHighlight: 'hsl(0,0%,20%)',
text: 'hsl(0,0%,100%)',
textSubtle: 'hsl(0,0%,90%)',
textSubtlest: 'hsl(0,0%,80%)',
selection: 'hsl(276,100%,30%)',
surfaceActive: 'hsl(276,100%,30%)',
border: 'hsl(0,0%,60%)',
primary: 'hsl(266,100%,85%)',
secondary: 'hsl(242,20%,72%)',
info: 'hsl(208,100%,83%)',
success: 'hsl(150,100%,63%)',
notice: 'hsl(49,100%,77%)',
warning: 'hsl(28,100%,73%)',
danger: 'hsl(343,100%,79%)',
},
},
{
id: 'catppuccin-frappe',
label: 'Catppuccin Frappé',

160
src-tauri/Cargo.lock generated
View File

@@ -503,15 +503,6 @@ dependencies = [
"generic-array",
]
[[package]]
name = "block-padding"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"
dependencies = [
"generic-array",
]
[[package]]
name = "block2"
version = "0.5.1"
@@ -739,15 +730,6 @@ dependencies = [
"toml 0.8.23",
]
[[package]]
name = "cbc"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6"
dependencies = [
"cipher",
]
[[package]]
name = "cc"
version = "1.2.26"
@@ -1220,31 +1202,23 @@ checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476"
[[package]]
name = "dbus"
version = "0.9.7"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b"
checksum = "190b6255e8ab55a7b568df5a883e9497edc3e4821c06396612048b430e5ad1e9"
dependencies = [
"libc",
"libdbus-sys",
"winapi",
"windows-sys 0.59.0",
]
[[package]]
name = "dbus-secret-service"
version = "4.0.3"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b42a16374481d92aed73ae45b1f120207d8e71d24fb89f357fadbd8f946fd84b"
checksum = "708b509edf7889e53d7efb0ffadd994cc6c2345ccb62f55cfd6b0682165e4fa6"
dependencies = [
"aes",
"block-padding",
"cbc",
"dbus",
"futures-util",
"hkdf",
"num",
"once_cell",
"rand 0.8.5",
"sha2",
"zeroize",
]
[[package]]
@@ -2273,15 +2247,6 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hkdf"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"
dependencies = [
"hmac",
]
[[package]]
name = "hmac"
version = "0.12.1"
@@ -2695,7 +2660,6 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
dependencies = [
"block-padding",
"generic-array",
]
@@ -2855,15 +2819,17 @@ dependencies = [
[[package]]
name = "keyring"
version = "4.0.0-rc.1"
version = "3.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb06f73ca0ea1cbd3858e54404585e33dccb860cb4fc8a66ad5e75a5736f3f19"
checksum = "eebcc3aff044e5944a8fbaf69eb277d11986064cba30c468730e8b9909fb551c"
dependencies = [
"byteorder",
"dbus-secret-service",
"log",
"security-framework 2.11.1",
"security-framework 3.2.0",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
"zeroize",
]
[[package]]
@@ -2936,9 +2902,9 @@ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "libdbus-sys"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72"
checksum = "5cbe856efeb50e4681f010e9aaa2bf0a644e10139e54cde10fc83a307c23bd9f"
dependencies = [
"pkg-config",
]
@@ -3359,76 +3325,12 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d"
[[package]]
name = "num"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
dependencies = [
"num-bigint",
"num-complex",
"num-integer",
"num-iter",
"num-rational",
"num-traits",
]
[[package]]
name = "num-bigint"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
dependencies = [
"num-integer",
"num-traits",
]
[[package]]
name = "num-complex"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
dependencies = [
"num-bigint",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.19"
@@ -5163,10 +5065,11 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.219"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
checksum = "0dca6411025b24b60bfa7ec1fe1f8e710ac09782dca409ee8237ba74b51295fd"
dependencies = [
"serde_core",
"serde_derive",
]
@@ -5203,10 +5106,19 @@ dependencies = [
]
[[package]]
name = "serde_derive"
version = "1.0.219"
name = "serde_core"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
checksum = "ba2ba63999edb9dac981fb34b3e5c0d111a69b0924e253ed29d83f7c99e966a4"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.226"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8db53ae22f34573731bafa1db20f04027b2d25e02d8205921b569171699cdb33"
dependencies = [
"proc-macro2",
"quote",
@@ -5236,6 +5148,17 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_path_to_error"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457"
dependencies = [
"itoa",
"serde",
"serde_core",
]
[[package]]
name = "serde_repr"
version = "0.1.20"
@@ -7918,7 +7841,6 @@ dependencies = [
"charset",
"chrono",
"cookie",
"encoding_rs",
"eventsource-client",
"http",
"log",
@@ -7946,6 +7868,7 @@ dependencies = [
"thiserror 2.0.12",
"tokio",
"tokio-stream",
"ts-rs",
"uuid",
"yaak-common",
"yaak-crypto",
@@ -8121,6 +8044,7 @@ dependencies = [
"dunce",
"futures-util",
"hex",
"keyring",
"log",
"md5 0.7.0",
"path-slash",
@@ -8162,6 +8086,7 @@ dependencies = [
"notify",
"serde",
"serde_json",
"serde_path_to_error",
"serde_yaml",
"sha1",
"tauri",
@@ -8177,6 +8102,7 @@ name = "yaak-templates"
version = "0.1.0"
dependencies = [
"base64 0.22.1",
"log",
"serde",
"serde-wasm-bindgen",
"serde_json",

View File

@@ -32,6 +32,9 @@ strip = true # Automatically strip symbols from the binary.
[features]
cargo-clippy = []
default = []
updater = []
license = ["yaak-license"]
[build-dependencies]
tauri-build = { version = "2.4.1", features = [] }
@@ -40,9 +43,9 @@ tauri-build = { version = "2.4.1", features = [] }
openssl-sys = { version = "0.9.105", features = ["vendored"] } # For Ubuntu installation to work
[dependencies]
charset = "0.1.5"
chrono = { workspace = true, features = ["serde"] }
cookie = "0.18.1"
encoding_rs = "0.8.35"
eventsource-client = { git = "https://github.com/yaakapp/rust-eventsource-client", version = "0.14.0" }
http = { version = "1.2.0", default-features = false }
log = "0.4.27"
@@ -55,19 +58,20 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["raw_value"] }
tauri = { workspace = true, features = ["devtools", "protocol-asset"] }
tauri-plugin-clipboard-manager = "2.3.0"
tauri-plugin-deep-link = "2.4.3"
tauri-plugin-dialog = { workspace = true }
tauri-plugin-fs = "2.4.2"
tauri-plugin-log = { version = "2.7.0", features = ["colored"] }
tauri-plugin-opener = "2.5.0"
tauri-plugin-os = "2.3.1"
tauri-plugin-shell = { workspace = true }
tauri-plugin-deep-link = "2.4.3"
tauri-plugin-single-instance = { version = "2.3.4", features = ["deep-link"] }
tauri-plugin-updater = "2.9.0"
tauri-plugin-window-state = "2.4.0"
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
tokio-stream = "0.1.17"
ts-rs = { workspace = true }
uuid = "1.12.1"
yaak-common = { workspace = true }
yaak-crypto = { workspace = true }
@@ -75,7 +79,7 @@ yaak-fonts = { workspace = true }
yaak-git = { path = "yaak-git" }
yaak-grpc = { path = "yaak-grpc" }
yaak-http = { workspace = true }
yaak-license = { path = "yaak-license" }
yaak-license = { path = "yaak-license", optional = true }
yaak-mac-window = { path = "yaak-mac-window" }
yaak-models = { workspace = true }
yaak-plugins = { workspace = true }
@@ -83,25 +87,25 @@ yaak-sse = { workspace = true }
yaak-sync = { workspace = true }
yaak-templates = { workspace = true }
yaak-ws = { path = "yaak-ws" }
charset = "0.1.5"
[workspace.dependencies]
chrono = "0.4.41"
hex = "0.4.3"
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" }

View File

@@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type UpdateInfo = { replyEventId: string, version: string, downloaded: boolean, };
export type UpdateResponse = { "type": "ack" } | { "type": "action", action: UpdateResponseAction, };
export type UpdateResponseAction = "install" | "skip";
export type YaakNotification = { timestamp: string, timeout: number | null, id: string, title: string | null, message: string, color: string | null, action: YaakNotificationAction | null, };
export type YaakNotificationAction = { label: string, url: string, };

View File

@@ -1,8 +1,6 @@
{
"$schema": "../gen/schemas/capabilities.json",
"identifier": "main",
"description": "Main permissions",
"local": true,
"identifier": "default",
"description": "Default capabilities for all build variants",
"windows": [
"*"
],
@@ -11,6 +9,7 @@
"core:event:allow-emit",
"core:event:allow-listen",
"core:event:allow-unlisten",
"core:path:allow-resolve-directory",
"os:allow-os-type",
"clipboard-manager:allow-clear",
"clipboard-manager:allow-write-text",
@@ -54,7 +53,6 @@
"yaak-crypto:default",
"yaak-fonts:default",
"yaak-git:default",
"yaak-license:default",
"yaak-mac-window:default",
"yaak-models:default",
"yaak-plugins:default",

6
src-tauri/package.json Normal file
View File

@@ -0,0 +1,6 @@
{
"name": "@yaakapp-internal/tauri",
"private": true,
"version": "1.0.0",
"main": "bindings/index.ts"
}

View File

@@ -19,9 +19,13 @@ pub enum Error {
#[error(transparent)]
GitError(#[from] yaak_git::error::Error),
#[error(transparent)]
TokioTimeoutElapsed(#[from] tokio::time::error::Elapsed),
#[error(transparent)]
WebsocketError(#[from] yaak_ws::error::Error),
#[cfg(feature = "license")]
#[error(transparent)]
LicenseError(#[from] yaak_license::error::Error),

View File

@@ -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(

View File

@@ -39,6 +39,19 @@ pub(crate) async fn import_data<R: Runtime>(
.map(|mut v| {
v.id = maybe_gen_id::<Environment>(v.id.as_str(), &mut id_map);
v.workspace_id = maybe_gen_id::<Workspace>(v.workspace_id.as_str(), &mut id_map);
match (v.parent_model.as_str(), v.parent_id.clone().as_deref()) {
("folder", Some(parent_id)) => {
v.parent_id = Some(maybe_gen_id::<Folder>(&parent_id, &mut id_map));
}
("", _) => {
// Fix any empty ones
v.parent_model = "workspace".to_string();
}
_ => {
// Parent ID only required for the folder case
v.parent_id = None;
}
};
v
})
.collect();

View File

@@ -26,6 +26,7 @@ use tauri_plugin_log::{Builder, Target, TargetKind};
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
use tokio::sync::Mutex;
use tokio::task::block_in_place;
use tokio::time;
use yaak_common::window::WorkspaceWindowTrait;
use yaak_grpc::manager::{DynamicMessage, GrpcHandle};
use yaak_grpc::{Code, ServiceDefinition, deserialize_message, serialize_message};
@@ -48,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;
@@ -73,6 +74,8 @@ struct AppMetaData {
name: String,
app_data_dir: String,
app_log_dir: String,
feature_updater: bool,
feature_license: bool,
}
#[tauri::command]
@@ -85,6 +88,8 @@ async fn cmd_metadata(app_handle: AppHandle) -> YaakResult<AppMetaData> {
name: app_handle.package_info().name.to_string(),
app_data_dir: app_data_dir.to_string_lossy().to_string(),
app_log_dir: app_log_dir.to_string_lossy().to_string(),
feature_license: cfg!(feature = "license"),
feature_updater: cfg!(feature = "updater"),
})
}
@@ -121,6 +126,9 @@ async fn cmd_render_template<R: Runtime>(
&PluginWindowContext::new(&window),
RenderPurpose::Preview,
),
&RenderOptions {
error_behavior: RenderErrorBehavior::Throw,
},
)
.await?;
Ok(result)
@@ -162,6 +170,9 @@ async fn cmd_grpc_reflect<R: Runtime>(
&PluginWindowContext::new(&window),
RenderPurpose::Send,
),
&RenderOptions {
error_behavior: RenderErrorBehavior::Throw,
},
)
.await?;
@@ -208,6 +219,9 @@ async fn cmd_grpc_go<R: Runtime>(
&PluginWindowContext::new(&window),
RenderPurpose::Send,
),
&RenderOptions {
error_behavior: RenderErrorBehavior::Throw,
},
)
.await?;
@@ -330,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")
@@ -399,6 +416,9 @@ async fn cmd_grpc_go<R: Runtime>(
&PluginWindowContext::new(&window),
RenderPurpose::Send,
),
&RenderOptions {
error_behavior: RenderErrorBehavior::Throw,
},
)
.await?;
@@ -683,6 +703,12 @@ async fn cmd_grpc_go<R: Runtime>(
Ok(conn.id)
}
#[tauri::command]
async fn cmd_restart<R: Runtime>(app_handle: AppHandle<R>) -> YaakResult<()> {
app_handle.request_restart();
Ok(())
}
#[tauri::command]
async fn cmd_send_ephemeral_request<R: Runtime>(
mut request: HttpRequest,
@@ -720,13 +746,10 @@ async fn cmd_format_json(text: &str) -> YaakResult<String> {
#[tauri::command]
async fn cmd_http_response_body<R: Runtime>(
window: WebviewWindow<R>,
app_handle: AppHandle<R>,
plugin_manager: State<'_, PluginManager>,
response_id: &str,
response: HttpResponse,
filter: Option<&str>,
) -> YaakResult<FilterResponse> {
let response = app_handle.db().get_http_response(response_id)?;
let body_path = match response.body_path {
None => {
return Err(GenericError("Response body path not set".to_string()));
@@ -836,7 +859,7 @@ async fn cmd_get_http_authentication_config<R: Runtime>(
AnyModel::Workspace(m) => (m.id, None),
m => {
return Err(GenericError(format!("Unsupported model to call auth config {m:?}")));
},
}
};
let environment_chain =
@@ -1190,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(())
}
@@ -1206,7 +1229,12 @@ async fn cmd_check_for_updates<R: Runtime>(
yaak_updater: State<'_, Mutex<YaakUpdater>>,
) -> YaakResult<bool> {
let update_mode = get_update_mode(&window).await?;
Ok(yaak_updater.lock().await.check_now(&window, update_mode, UpdateTrigger::User).await?)
let settings = window.db().get_settings();
Ok(yaak_updater
.lock()
.await
.check_now(&window, update_mode, settings.auto_download_updates, UpdateTrigger::User)
.await?)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
@@ -1257,7 +1285,6 @@ pub fn run() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_fs::init())
.plugin(yaak_license::init())
.plugin(yaak_mac_window::init())
.plugin(yaak_models::init())
.plugin(yaak_plugins::init())
@@ -1267,6 +1294,11 @@ pub fn run() {
.plugin(yaak_ws::init())
.plugin(yaak_sync::init());
#[cfg(feature = "license")]
{
builder = builder.plugin(yaak_license::init());
}
builder
.setup(|app| {
{
@@ -1287,6 +1319,7 @@ pub fn run() {
),
color: Some(Color::Danger),
icon: None,
timeout: None,
},
);
};
@@ -1344,6 +1377,7 @@ pub fn run() {
cmd_plugin_info,
cmd_reload_plugins,
cmd_render_template,
cmd_restart,
cmd_save_response,
cmd_send_ephemeral_request,
cmd_send_http_request,
@@ -1383,19 +1417,27 @@ pub fn run() {
label,
..
} => {
let w = app_handle.get_webview_window(&label).unwrap();
let h = app_handle.clone();
// Run update check whenever the window is focused
tauri::async_runtime::spawn(async move {
if w.db().get_settings().autoupdate {
let val: State<'_, Mutex<YaakUpdater>> = h.state();
let update_mode = get_update_mode(&w).await.unwrap();
if let Err(e) = val.lock().await.maybe_check(&w, update_mode).await {
warn!("Failed to check for updates {e:?}");
if cfg!(feature = "updater") {
// Run update check whenever the window is focused
let w = app_handle.get_webview_window(&label).unwrap();
let h = app_handle.clone();
tauri::async_runtime::spawn(async move {
let settings = w.db().get_settings();
if settings.autoupdate {
time::sleep(Duration::from_secs(3)).await; // Wait a bit so it's not so jarring
let val: State<'_, Mutex<YaakUpdater>> = h.state();
let update_mode = get_update_mode(&w).await.unwrap();
if let Err(e) = val
.lock()
.await
.maybe_check(&w, settings.auto_download_updates, update_mode)
.await
{
warn!("Failed to check for updates {e:?}");
}
};
};
});
});
}
let h = app_handle.clone();
tauri::async_runtime::spawn(async move {
@@ -1465,7 +1507,7 @@ fn monitor_plugin_events<R: Runtime>(app_handle: &AppHandle<R>) {
}
async fn call_frontend<R: Runtime>(
window: WebviewWindow<R>,
window: &WebviewWindow<R>,
event: &InternalEvent,
) -> Option<InternalEventPayload> {
window.emit_to(window.label(), "plugin_event", event.clone()).unwrap();

View File

@@ -7,9 +7,9 @@ use log::debug;
use reqwest::Method;
use serde::{Deserialize, Serialize};
use tauri::{AppHandle, Emitter, Manager, Runtime, WebviewWindow};
use ts_rs::TS;
use yaak_common::api_client::yaak_api_client;
use yaak_common::platform::get_os;
use yaak_license::{LicenseCheckStatus, check_license};
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::UpdateSource;
@@ -24,18 +24,22 @@ pub struct YaakNotifier {
last_check: SystemTime,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export, export_to = "index.ts")]
pub struct YaakNotification {
timestamp: DateTime<Utc>,
timeout: Option<f64>,
id: String,
title: Option<String>,
message: String,
color: Option<String>,
action: Option<YaakNotificationAction>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export, export_to = "index.ts")]
pub struct YaakNotificationAction {
label: String,
url: String,
@@ -73,12 +77,20 @@ impl YaakNotifier {
self.last_check = SystemTime::now();
let license_check = match check_license(window).await? {
LicenseCheckStatus::PersonalUse { .. } => "personal".to_string(),
LicenseCheckStatus::CommercialUse => "commercial".to_string(),
LicenseCheckStatus::InvalidLicense => "invalid_license".to_string(),
LicenseCheckStatus::Trialing { .. } => "trialing".to_string(),
#[cfg(feature = "license")]
let license_check = {
use yaak_license::{LicenseCheckStatus, check_license};
match check_license(window).await {
Ok(LicenseCheckStatus::PersonalUse { .. }) => "personal".to_string(),
Ok(LicenseCheckStatus::CommercialUse) => "commercial".to_string(),
Ok(LicenseCheckStatus::InvalidLicense) => "invalid_license".to_string(),
Ok(LicenseCheckStatus::Trialing { .. }) => "trialing".to_string(),
Err(_) => "unknown".to_string(),
}
};
#[cfg(not(feature = "license"))]
let license_check = "disabled".to_string();
let settings = window.db().get_settings();
let num_launches = get_num_launches(app_handle).await;
let info = app_handle.package_info().clone();

View File

@@ -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>,
@@ -51,7 +52,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
InternalEventPayload::PromptTextRequest(_) => {
let window = get_window_from_window_context(app_handle, &window_context)
.expect("Failed to find window for render");
call_frontend(window, event).await
call_frontend(&window, event).await
}
InternalEventPayload::FindHttpResponsesRequest(req) => {
let http_responses = app_handle
@@ -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();

View File

@@ -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
}

View File

@@ -1,15 +1,21 @@
use std::fmt::{Display, Formatter};
use std::time::SystemTime;
use std::path::PathBuf;
use std::time::{Duration, SystemTime};
use crate::error::Result;
use log::info;
use tauri::{Manager, Runtime, WebviewWindow};
use log::{debug, error, info, warn};
use serde::{Deserialize, Serialize};
use tauri::{Emitter, Listener, Manager, Runtime, WebviewWindow};
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons};
use tauri_plugin_updater::UpdaterExt;
use tauri_plugin_updater::{Update, UpdaterExt};
use tokio::task::block_in_place;
use tokio::time::sleep;
use ts_rs::TS;
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::generate_id;
use yaak_plugins::manager::PluginManager;
use crate::error::Error::GenericError;
use crate::is_dev;
const MAX_UPDATE_CHECK_HOURS_STABLE: u64 = 12;
@@ -48,6 +54,7 @@ impl UpdateMode {
}
}
#[derive(PartialEq)]
pub enum UpdateTrigger {
Background,
User,
@@ -64,6 +71,7 @@ impl YaakUpdater {
&mut self,
window: &WebviewWindow<R>,
mode: UpdateMode,
auto_download: bool,
update_trigger: UpdateTrigger,
) -> Result<bool> {
// Only AppImage supports updates on Linux, so skip if it's not
@@ -78,7 +86,7 @@ impl YaakUpdater {
let update_key = format!("{:x}", md5::compute(settings.id));
self.last_update_check = SystemTime::now();
info!("Checking for updates mode={}", mode);
info!("Checking for updates mode={} autodl={}", mode, auto_download);
let w = window.clone();
let update_check_result = w
@@ -113,42 +121,44 @@ impl YaakUpdater {
None => false,
Some(update) => {
let w = window.clone();
w.dialog()
.message(format!(
"{} is available. Would you like to download and install it now?",
update.version
))
.buttons(MessageDialogButtons::OkCancelCustom(
"Download".to_string(),
"Later".to_string(),
))
.title("Update Available")
.show(|confirmed| {
if !confirmed {
return;
tauri::async_runtime::spawn(async move {
// Force native updater if specified (useful if a release broke the UI)
let native_install_mode =
update.raw_json.get("install_mode").map(|v| v.as_str()).unwrap_or_default()
== Some("native");
if native_install_mode {
start_native_update(&w, &update).await;
return;
}
// If it's a background update, try downloading it first
if update_trigger == UpdateTrigger::Background && auto_download {
info!("Downloading update {} in background", update.version);
if let Err(e) = download_update_idempotent(&w, &update).await {
error!("Failed to download {}: {}", update.version, e);
}
tauri::async_runtime::spawn(async move {
match update.download_and_install(|_, _| {}, || {}).await {
Ok(_) => {
if w.dialog()
.message("Would you like to restart the app?")
.title("Update Installed")
.buttons(MessageDialogButtons::OkCancelCustom(
"Restart".to_string(),
"Later".to_string(),
))
.blocking_show()
{
w.app_handle().restart();
}
}
Err(e) => {
w.dialog()
.message(format!("The update failed to install: {}", e));
}
}
});
});
}
match start_integrated_update(&w, &update).await {
Ok(UpdateResponseAction::Skip) => {
info!("Confirmed {}: skipped", update.version);
}
Ok(UpdateResponseAction::Install) => {
info!("Confirmed {}: install", update.version);
if let Err(e) = install_update_maybe_download(&w, &update).await {
error!("Failed to install: {e}");
return;
};
info!("Installed {}", update.version);
finish_integrated_update(&w, &update).await;
}
Err(e) => {
warn!("Failed to notify frontend, falling back: {e}",);
start_native_update(&w, &update).await;
}
};
});
true
}
};
@@ -158,6 +168,7 @@ impl YaakUpdater {
pub async fn maybe_check<R: Runtime>(
&mut self,
window: &WebviewWindow<R>,
auto_download: bool,
mode: UpdateMode,
) -> Result<bool> {
let update_period_seconds = match mode {
@@ -171,11 +182,206 @@ impl YaakUpdater {
return Ok(false);
}
// Don't check if dev
// Don't check if development (can still with manual user trigger)
if is_dev() {
return Ok(false);
}
self.check_now(window, mode, UpdateTrigger::Background).await
self.check_now(window, mode, auto_download, UpdateTrigger::Background).await
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export, export_to = "index.ts")]
struct UpdateInfo {
reply_event_id: String,
version: String,
downloaded: bool,
}
#[derive(Debug, Clone, PartialEq, Deserialize, TS)]
#[serde(rename_all = "camelCase", tag = "type")]
#[ts(export, export_to = "index.ts")]
enum UpdateResponse {
Ack,
Action { action: UpdateResponseAction },
}
#[derive(Debug, Clone, PartialEq, Deserialize, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export, export_to = "index.ts")]
enum UpdateResponseAction {
Install,
Skip,
}
async fn finish_integrated_update<R: Runtime>(window: &WebviewWindow<R>, update: &Update) {
if let Err(e) = window.emit_to(window.label(), "update_installed", update.version.to_string()) {
warn!("Failed to notify frontend of update install: {}", e);
}
}
async fn start_integrated_update<R: Runtime>(
window: &WebviewWindow<R>,
update: &Update,
) -> Result<UpdateResponseAction> {
let download_path = ensure_download_path(window, update)?;
debug!("Download path: {}", download_path.display());
let downloaded = download_path.exists();
let ack_wait = Duration::from_secs(3);
let reply_id = generate_id();
// 1) Start listening BEFORE emitting to avoid missing a fast reply
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<UpdateResponse>();
let w_for_listener = window.clone();
let event_id = w_for_listener.listen(reply_id.clone(), move |ev| {
match serde_json::from_str::<UpdateResponse>(ev.payload()) {
Ok(UpdateResponse::Ack) => {
let _ = tx.send(UpdateResponse::Ack);
}
Ok(UpdateResponse::Action { action }) => {
let _ = tx.send(UpdateResponse::Action { action });
}
Err(e) => {
warn!("Failed to parse update reply from frontend: {e:?}");
}
}
});
// Make sure we always unlisten
struct Unlisten<'a, R: Runtime> {
win: &'a WebviewWindow<R>,
id: tauri::EventId,
}
impl<'a, R: Runtime> Drop for Unlisten<'a, R> {
fn drop(&mut self) {
self.win.unlisten(self.id);
}
}
let _guard = Unlisten {
win: window,
id: event_id,
};
// 2) Emit the event now that listener is in place
let info = UpdateInfo {
version: update.version.to_string(),
downloaded,
reply_event_id: reply_id,
};
window
.emit_to(window.label(), "update_available", &info)
.map_err(|e| GenericError(format!("Failed to emit update_available: {e}")))?;
// 3) Two-stage timeout: first wait for ack, then wait for final action
// --- Phase 1: wait for ACK with timeout ---
let ack_timer = sleep(ack_wait);
tokio::pin!(ack_timer);
loop {
tokio::select! {
msg = rx.recv() => match msg {
Some(UpdateResponse::Ack) => break, // proceed to Phase 2
Some(UpdateResponse::Action{action}) => return Ok(action), // user was fast
None => return Err(GenericError("frontend channel closed before ack".into())),
},
_ = &mut ack_timer => {
return Err(GenericError("timed out waiting for frontend ack".into()));
}
}
}
// --- Phase 2: wait forever for final action ---
loop {
match rx.recv().await {
Some(UpdateResponse::Action { action }) => return Ok(action),
Some(UpdateResponse::Ack) => { /* ignore extra acks */ }
None => return Err(GenericError("frontend channel closed before action".into())),
}
}
}
async fn start_native_update<R: Runtime>(window: &WebviewWindow<R>, update: &Update) {
// If the frontend doesn't respond, fallback to native dialogs
let confirmed = window
.dialog()
.message(format!(
"{} is available. Would you like to download and install it now?",
update.version
))
.buttons(MessageDialogButtons::OkCancelCustom("Download".to_string(), "Later".to_string()))
.title("Update Available")
.blocking_show();
if !confirmed {
return;
}
match update.download_and_install(|_, _| {}, || {}).await {
Ok(()) => {
if window
.dialog()
.message("Would you like to restart the app?")
.title("Update Installed")
.buttons(MessageDialogButtons::OkCancelCustom(
"Restart".to_string(),
"Later".to_string(),
))
.blocking_show()
{
window.app_handle().request_restart();
}
}
Err(e) => {
window.dialog().message(format!("The update failed to install: {}", e));
}
}
}
pub async fn download_update_idempotent<R: Runtime>(
window: &WebviewWindow<R>,
update: &Update,
) -> Result<PathBuf> {
let dl_path = ensure_download_path(window, update)?;
if dl_path.exists() {
info!("{} already downloaded to {}", update.version, dl_path.display());
return Ok(dl_path);
}
info!("{} downloading: {}", update.version, dl_path.display());
let dl_bytes = update.download(|_, _| {}, || {}).await?;
std::fs::write(&dl_path, dl_bytes)
.map_err(|e| GenericError(format!("Failed to write update: {e}")))?;
info!("{} downloaded", update.version);
Ok(dl_path)
}
pub async fn install_update_maybe_download<R: Runtime>(
window: &WebviewWindow<R>,
update: &Update,
) -> Result<()> {
let dl_path = download_update_idempotent(window, update).await?;
let update_bytes = std::fs::read(&dl_path)?;
update.install(update_bytes.as_slice())?;
Ok(())
}
pub fn ensure_download_path<R: Runtime>(
window: &WebviewWindow<R>,
update: &Update,
) -> Result<PathBuf> {
// Ensure dir exists
let base_dir = window.path().app_cache_dir()?.join("updates");
std::fs::create_dir_all(&base_dir)?;
// Generate name based on signature
let sig_digest = md5::compute(&update.signature);
let name = format!("yaak-{}-{:x}", update.version, sig_digest);
let dl_path = base_dir.join(name);
Ok(dl_path)
}

View File

@@ -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),
},
)?;
}

View File

@@ -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)
}

BIN
src-tauri/static/greg.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -0,0 +1,38 @@
{
"build": {
"features": [
"updater",
"license"
]
},
"app": {
"security": {
"capabilities": [
"default",
{
"identifier": "release",
"windows": [
"*"
],
"permissions": [
"yaak-license:default"
]
}
]
}
},
"plugins": {
"updater": {
"endpoints": [
"https://update.yaak.app/check/{{target}}/{{arch}}/{{current_version}}"
],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEMxRDJFREQ1MjExQjdGN0IKUldSN2Z4c2gxZTNTd1FHNCtmYnFXMHVVQzhuNkJOM1cwOFBodmdLall3ckhKenpKUytHSTR1MlkK"
}
},
"bundle": {
"createUpdaterArtifacts": "v1Compatible",
"windows": {
"signCommand": "trusted-signing-cli -e https://eus.codesigning.azure.net/ -a Yaak -c yaakapp %1"
}
}
}

View File

@@ -15,7 +15,8 @@
"enable": true,
"scope": {
"allow": [
"$APPDATA/responses/*"
"$APPDATA/responses/*",
"$RESOURCE/static/*"
]
}
}
@@ -28,12 +29,6 @@
"yaak"
]
}
},
"updater": {
"endpoints": [
"https://update.yaak.app/check/{{target}}/{{arch}}/{{current_version}}"
],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEMxRDJFREQ1MjExQjdGN0IKUldSN2Z4c2gxZTNTd1FHNCtmYnFXMHVVQzhuNkJOM1cwOFBodmdLall3ckhKenpKUytHSTR1MlkK"
}
},
"bundle": {
@@ -56,6 +51,7 @@
],
"longDescription": "A cross-platform desktop app for interacting with REST, GraphQL, and gRPC",
"resources": [
"static",
"vendored/protoc/include",
"vendored/plugins",
"vendored/plugin-runtime"
@@ -69,15 +65,11 @@
"nsis",
"rpm"
],
"createUpdaterArtifacts": "v1Compatible",
"macOS": {
"minimumSystemVersion": "13.0",
"exceptionDomain": "",
"entitlements": "macos/entitlements.plist",
"frameworks": []
},
"windows": {
"signCommand": "trusted-signing-cli -e https://eus.codesigning.azure.net/ -a Yaak -c yaakapp %1"
}
}
}

View File

@@ -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 = { version = "4.0.0-rc.1" }
keyring = { workspace = true, features = ["apple-native", "windows-native", "sync-secret-service"] }
log = "0.4.26"
serde = { workspace = true, features = ["derive"] }
tauri = { workspace = true }

View File

@@ -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, };

View File

@@ -1,11 +1,14 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { invoke } from '@tauri-apps/api/core';
import { listen } from '@tauri-apps/api/event';
import { appInfo } from '@yaakapp/app/lib/appInfo';
import { useEffect } from 'react';
import { LicenseCheckStatus } from './bindings/license';
export * from './bindings/license';
const CHECK_QUERY_KEY = ['license.check'];
export function useLicense() {
const queryClient = useQueryClient();
const activate = useMutation<void, string, { licenseKey: string }>({
@@ -30,12 +33,16 @@ export function useLicense() {
};
}, []);
const CHECK_QUERY_KEY = ['license.check'];
const check = useQuery<void, string, LicenseCheckStatus>({
const check = useQuery<LicenseCheckStatus | null, string>({
refetchInterval: 1000 * 60 * 60 * 12, // Refetch every 12 hours
refetchOnWindowFocus: false,
queryKey: CHECK_QUERY_KEY,
queryFn: () => invoke('plugin:yaak-license|check'),
queryFn: async () => {
if (!appInfo.featureLicense) {
return null;
}
return invoke<LicenseCheckStatus>('plugin:yaak-license|check');
},
});
return {

View File

@@ -155,6 +155,7 @@ pub async fn check_license<R: Runtime>(window: &WebviewWindow<R>) -> Result<Lice
app_version: window.package_info().version.to_string(),
};
let activation_id = get_activation_id(window.app_handle()).await;
let settings = window.db().get_settings();
let trial_end = settings.created_at.add(Duration::from_secs(TRIAL_SECONDS));

View File

@@ -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, };
@@ -62,7 +62,7 @@ export type ProxySetting = { "type": "enabled", http: string, https: string, aut
export type ProxySettingAuth = { user: string, password: string, };
export type Settings = { model: "settings", id: string, createdAt: string, updatedAt: string, appearance: string, coloredMethods: boolean, editorFont: string | null, editorFontSize: number, editorKeymap: EditorKeymap, editorSoftWrap: boolean, hideWindowControls: boolean, interfaceFont: string | null, interfaceFontSize: number, interfaceScale: number, openWorkspaceNewWindow: boolean | null, proxy: ProxySetting | null, themeDark: string, themeLight: string, updateChannel: string, autoupdate: boolean, };
export type Settings = { model: "settings", id: string, createdAt: string, updatedAt: string, appearance: string, coloredMethods: boolean, editorFont: string | null, editorFontSize: number, editorKeymap: EditorKeymap, editorSoftWrap: boolean, hideWindowControls: boolean, interfaceFont: string | null, interfaceFontSize: number, interfaceScale: number, openWorkspaceNewWindow: boolean | null, proxy: ProxySetting | null, themeDark: string, themeLight: string, updateChannel: string, hideLicenseBadge: boolean, autoupdate: boolean, autoDownloadUpdates: boolean, };
export type SyncState = { model: "sync_state", id: string, workspaceId: string, createdAt: string, updatedAt: string, flushedAt: string, modelId: string, checksum: string, relPath: string, syncDir: string, };

View File

@@ -0,0 +1,10 @@
ALTER TABLE settings
ADD COLUMN hide_license_badge BOOLEAN DEFAULT FALSE;
-- 2. Backfill based on old JSON
UPDATE settings
SET hide_license_badge = 1
WHERE EXISTS ( SELECT 1
FROM key_values kv
WHERE kv.key = 'license_confirmation'
AND JSON_EXTRACT(kv.value, '$.confirmedPersonalUse') = TRUE );

View File

@@ -0,0 +1,2 @@
ALTER TABLE settings
ADD COLUMN auto_download_updates BOOLEAN DEFAULT TRUE;

View File

@@ -29,9 +29,6 @@ pub enum Error {
#[error("Multiple base environments for {0}. Delete duplicates before continuing.")]
MultipleBaseEnvironments(String),
#[error("Multiple folder environments for {0}. Delete duplicates before continuing.")]
MultipleFolderEnvironments(String),
#[error("unknown error")]
Unknown,

View File

@@ -120,7 +120,9 @@ pub struct Settings {
pub theme_dark: String,
pub theme_light: String,
pub update_channel: String,
pub hide_license_badge: bool,
pub autoupdate: bool,
pub auto_download_updates: bool,
}
impl UpsertModelInfo for Settings {
@@ -169,7 +171,9 @@ impl UpsertModelInfo for Settings {
(ThemeDark, self.theme_dark.as_str().into()),
(ThemeLight, self.theme_light.as_str().into()),
(UpdateChannel, self.update_channel.into()),
(HideLicenseBadge, self.hide_license_badge.into()),
(Autoupdate, self.autoupdate.into()),
(AutoDownloadUpdates, self.auto_download_updates.into()),
(ColoredMethods, self.colored_methods.into()),
(Proxy, proxy.into()),
])
@@ -192,7 +196,9 @@ impl UpsertModelInfo for Settings {
SettingsIden::ThemeDark,
SettingsIden::ThemeLight,
SettingsIden::UpdateChannel,
SettingsIden::HideLicenseBadge,
SettingsIden::Autoupdate,
SettingsIden::AutoDownloadUpdates,
SettingsIden::ColoredMethods,
]
}
@@ -223,6 +229,8 @@ impl UpsertModelInfo for Settings {
hide_window_controls: row.get("hide_window_controls")?,
update_channel: row.get("update_channel")?,
autoupdate: row.get("autoupdate")?,
auto_download_updates: row.get("auto_download_updates")?,
hide_license_badge: row.get("hide_license_badge")?,
colored_methods: row.get("colored_methods")?,
})
}
@@ -533,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 {
@@ -595,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")?,
@@ -602,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,
})
}
}

View File

@@ -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)
}
}

View File

@@ -1,11 +1,9 @@
use crate::db_context::DbContext;
use crate::error::Error::{
MissingBaseEnvironment, MultipleBaseEnvironments, MultipleFolderEnvironments,
};
use crate::error::Error::{MissingBaseEnvironment, MultipleBaseEnvironments};
use crate::error::Result;
use crate::models::{Environment, EnvironmentIden, EnvironmentVariable};
use crate::util::UpdateSource;
use log::info;
use log::{info, warn};
impl<'a> DbContext<'a> {
pub fn get_environment(&self, id: &str) -> Result<Environment> {
@@ -13,12 +11,10 @@ impl<'a> DbContext<'a> {
}
pub fn get_environment_by_folder_id(&self, folder_id: &str) -> Result<Option<Environment>> {
let environments: Vec<Environment> =
let mut environments: Vec<Environment> =
self.find_many(EnvironmentIden::ParentId, folder_id, None)?;
if environments.len() > 1 {
return Err(MultipleFolderEnvironments(folder_id.to_string()));
}
// Sort so we return the most recently updated environment
environments.sort_by(|a, b| b.updated_at.cmp(&a.updated_at));
Ok(environments.get(0).cloned())
}
@@ -26,7 +22,7 @@ impl<'a> DbContext<'a> {
let environments = self.list_environments_ensure_base(workspace_id)?;
let base_environments = environments
.into_iter()
.filter(|e| e.parent_id.is_none())
.filter(|e| e.parent_model == "workspace")
.collect::<Vec<Environment>>();
if base_environments.len() > 1 {
@@ -41,16 +37,16 @@ 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_id.is_none());
let base_environment = environments.iter().find(|e| e.parent_model == "workspace");
if let None = base_environment {
let e = self.upsert_environment(
&Environment {
workspace_id: workspace_id.to_string(),
name: "Global Variables".to_string(),
parent_model: "workspace".to_string(),
..Default::default()
},
&UpdateSource::Background,
@@ -62,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,
@@ -90,6 +91,23 @@ impl<'a> DbContext<'a> {
self.upsert_environment(&environment, source)
}
/// Find other environments with the same parent folder
fn list_duplicate_folder_environments(&self, environment: &Environment) -> Vec<Environment> {
if environment.parent_model != "folder" {
return Vec::new();
}
self.list_environments_dangerous(&environment.workspace_id)
.unwrap_or_default()
.into_iter()
.filter(|e| {
e.id != environment.id
&& e.parent_model == "folder"
&& e.parent_id == environment.parent_id
})
.collect()
}
pub fn upsert_environment(
&self,
environment: &Environment,
@@ -101,8 +119,32 @@ impl<'a> DbContext<'a> {
.filter(|v| !v.name.is_empty() || !v.value.is_empty())
.cloned()
.collect::<Vec<EnvironmentVariable>>();
// Sometimes a new environment can be created via sync/import, so we'll just delete
// the others when that happens. Not the best, but it's good for now.
let duplicates = self.list_duplicate_folder_environments(environment);
for duplicate in duplicates {
warn!(
"Deleting duplicate environment {} for folder {:?}",
duplicate.id, environment.parent_id
);
_ = self.delete(&duplicate, source);
}
// Automatically update the environment name based on the folder name
let mut name = environment.name.clone();
match (environment.parent_model.as_str(), environment.parent_id.as_deref()) {
("folder", Some(folder_id)) => {
if let Ok(folder) = self.get_folder(folder_id) {
name = format!("{} Environment", folder.name);
}
}
_ => {}
}
self.upsert(
&Environment {
name,
variables: cleaned_variables,
..environment.clone()
},

View File

@@ -33,6 +33,8 @@ impl<'a> DbContext<'a> {
update_channel: "stable".to_string(),
autoupdate: true,
colored_methods: false,
hide_license_badge: false,
auto_download_updates: true,
};
self.upsert(&settings, &UpdateSource::Background).expect("Failed to upsert settings")
}

View File

@@ -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,20 +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 }
[build-dependencies]
tauri-plugin = { workspace = true, features = ["build"] }

View File

@@ -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,
/**

View File

@@ -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, };

View File

@@ -32,7 +32,7 @@ pub enum Error {
#[error("JSON error: {0}")]
JsonErr(#[from] serde_json::Error),
#[error("API Error: {0}")]
ApiErr(String),

View File

@@ -1,5 +1,4 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use tauri::{Runtime, WebviewWindow};
use ts_rs::TS;
@@ -163,7 +162,7 @@ pub enum InternalEventPayload {
impl InternalEventPayload {
pub fn type_name(&self) -> String {
if let Ok(Value::Object(map)) = serde_json::to_value(self) {
if let Ok(serde_json::Value::Object(map)) = serde_json::to_value(self) {
map.get("type").map(|s| s.as_str().unwrap_or("unknown").to_string())
} else {
None
@@ -495,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)]

View File

@@ -1,7 +1,7 @@
use std::sync::atomic::{AtomicBool, Ordering};
use crate::commands::{install, search, uninstall, updates};
use crate::manager::PluginManager;
use log::info;
use std::process::exit;
use tauri::plugin::{Builder, TauriPlugin};
use tauri::{generate_handler, Manager, RunEvent, Runtime, State};
@@ -20,6 +20,8 @@ pub mod api;
pub mod install;
pub mod plugin_meta;
static EXITING: AtomicBool = AtomicBool::new(false);
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("yaak-plugins")
.invoke_handler(generate_handler![search, install, uninstall, updates])
@@ -31,12 +33,15 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
.on_event(|app, e| match e {
// TODO: Also exit when app is force-quit (eg. cmd+r in IntelliJ runner)
RunEvent::ExitRequested { api, .. } => {
if EXITING.swap(true, Ordering::SeqCst) {
return; // Only exit once to prevent infinite recursion
}
api.prevent_exit();
tauri::async_runtime::block_on(async move {
info!("Exiting plugin runtime due to app exit");
let manager: State<PluginManager> = app.state();
manager.terminate().await;
exit(0);
app.exit(0);
});
}
_ => {}

View File

@@ -14,7 +14,7 @@ use crate::events::{
ImportResponse, InternalEvent, InternalEventPayload, JsonPrimitive, PluginWindowContext,
RenderPurpose,
};
use crate::native_template_functions::template_function_secure;
use crate::native_template_functions::{template_function_keyring, template_function_secure};
use crate::nodejs::start_nodejs_plugin_runtime;
use crate::plugin_handle::PluginHandle;
use crate::server_ws::PluginRuntimeServerWebsocket;
@@ -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 {
@@ -514,7 +514,7 @@ impl PluginManager {
// Add Rust-based functions
result.push(GetTemplateFunctionsResponse {
plugin_ref_id: "__NATIVE__".to_string(), // Meh
functions: vec![template_function_secure()],
functions: vec![template_function_secure(), template_function_keyring()],
});
Ok(result)
@@ -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?;

View File

@@ -5,6 +5,8 @@ use crate::events::{
use crate::template_callback::PluginTemplateCallback;
use base64::Engine;
use base64::prelude::BASE64_STANDARD;
use keyring::Error::NoEntry;
use log::{debug, info};
use std::collections::HashMap;
use tauri::{AppHandle, Runtime};
use yaak_crypto::manager::EncryptionManagerExt;
@@ -32,6 +34,34 @@ pub(crate) fn template_function_secure() -> TemplateFunction {
}
}
pub(crate) fn template_function_keyring() -> TemplateFunction {
TemplateFunction {
name: "keychain".to_string(),
description: Some("Get a password from the OS keychain or keyring".to_string()),
aliases: Some(vec!["keyring".to_string()]),
args: vec![
TemplateFunctionArg::FormInput(FormInput::Text(FormInputText {
base: FormInputBase {
name: "service".to_string(),
label: Some("Service".to_string()),
description: Some("App or URL for the password".to_string()),
..Default::default()
},
..Default::default()
})),
TemplateFunctionArg::FormInput(FormInput::Text(FormInputText {
base: FormInputBase {
name: "account".to_string(),
label: Some("Account".to_string()),
description: Some("Username or email address".to_string()),
..Default::default()
},
..Default::default()
})),
],
}
}
pub fn template_function_secure_run<R: Runtime>(
app_handle: &AppHandle<R>,
args: HashMap<String, serde_json::Value>,
@@ -163,3 +193,25 @@ pub fn encrypt_secure_template_function<R: Runtime>(
)?
.to_string())
}
pub fn template_function_keychain_run(args: HashMap<String, serde_json::Value>) -> Result<String> {
let service = args.get("service").and_then(|v| v.as_str()).unwrap_or_default().to_owned();
let user = args.get("account").and_then(|v| v.as_str()).unwrap_or_default().to_owned();
debug!("Getting password for service {} and user {}", service, user);
let entry = match keyring::Entry::new(&service, &user) {
Ok(e) => e,
Err(e) => {
debug!("Failed to initialize keyring entry for '{}' and '{}' {:?}", service, user, e);
return Ok("".to_string()); // Don't fail for invalid args
}
};
match entry.get_password() {
Ok(p) => Ok(p),
Err(NoEntry) => {
info!("No password found for '{}' and '{}'", service, user);
Ok("".to_string()) // Don't fail for missing passwords
}
Err(e) => Err(RenderError(e.to_string())),
}
}

View File

@@ -1,12 +1,13 @@
use crate::events::{PluginWindowContext, RenderPurpose};
use crate::manager::PluginManager;
use crate::native_template_functions::{
template_function_secure_run, template_function_secure_transform_arg,
template_function_keychain_run, template_function_secure_run,
template_function_secure_transform_arg,
};
use std::collections::HashMap;
use tauri::{AppHandle, Manager, Runtime};
use yaak_templates::error::Result;
use yaak_templates::TemplateCallback;
use yaak_templates::error::Result;
#[derive(Clone)]
pub struct PluginTemplateCallback<R: Runtime> {
@@ -37,6 +38,8 @@ impl<R: Runtime> TemplateCallback for PluginTemplateCallback<R> {
if fn_name == "secure" {
return template_function_secure_run(&self.app_handle, args, &self.window_context);
} else if fn_name == "keychain" || fn_name == "keyring" {
return template_function_keychain_run(args);
}
let plugin_manager = &*self.app_handle.state::<PluginManager>();
@@ -51,12 +54,7 @@ impl<R: Runtime> TemplateCallback for PluginTemplateCallback<R> {
Ok(resp)
}
fn transform_arg(
&self,
fn_name: &str,
arg_name: &str,
arg_value: &str,
) -> Result<String> {
fn transform_arg(&self, fn_name: &str, arg_name: &str, arg_value: &str) -> Result<String> {
if fn_name == "secure" {
return template_function_secure_transform_arg(
&self.app_handle,

View File

@@ -19,6 +19,7 @@ thiserror = { workspace = true }
tokio = { workspace = true, features = ["fs", "sync", "macros"] }
ts-rs = { workspace = true, features = ["chrono-impl", "serde-json-impl"] }
yaak-models = { workspace = true }
serde_path_to_error = "0.1.20"
[build-dependencies]
tauri-plugin = { workspace = true, features = ["build"] }

View File

@@ -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, };

View File

@@ -1,8 +1,9 @@
use crate::error::Error::UnknownModel;
use crate::error::Result;
use chrono::NaiveDateTime;
use log::warn;
use serde::{Deserialize, Serialize};
use log::{debug, warn};
use serde::{Deserialize, Deserializer, Serialize};
use serde_yaml::{Mapping, Value};
use sha1::{Digest, Sha1};
use std::fs;
use std::path::Path;
@@ -11,7 +12,7 @@ use yaak_models::models::{
AnyModel, Environment, Folder, GrpcRequest, HttpRequest, WebsocketRequest, Workspace,
};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[derive(Debug, Clone, PartialEq, Serialize, TS)]
#[serde(rename_all = "snake_case", tag = "type")]
#[ts(export, export_to = "gen_models.ts")]
pub enum SyncModel {
@@ -23,6 +24,79 @@ pub enum SyncModel {
WebsocketRequest(WebsocketRequest),
}
impl<'de> Deserialize<'de> for SyncModel {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: Deserializer<'de>,
{
use serde_path_to_error as spte;
let mut v = Value::deserialize(deserializer)?;
let model = match v.get("model") {
Some(Value::String(model)) => model.clone(),
_ => "".to_string(),
};
let model = model.as_str();
let obj = v
.as_mapping_mut()
.ok_or_else(|| serde::de::Error::custom("expected object for SyncModel"))?;
// Dispatch to CHILD types (no recursion)
match model {
"workspace" => {
let x: Workspace = spte::deserialize(v).map_err(serde::de::Error::custom)?;
Ok(SyncModel::Workspace(x))
}
"environment" => {
migrate_environment(obj);
let x: Environment = spte::deserialize(v).map_err(serde::de::Error::custom)?;
Ok(SyncModel::Environment(x))
}
"folder" => {
let x: Folder = spte::deserialize(v).map_err(serde::de::Error::custom)?;
Ok(SyncModel::Folder(x))
}
"http_request" => {
let x: HttpRequest = spte::deserialize(v).map_err(serde::de::Error::custom)?;
Ok(SyncModel::HttpRequest(x))
}
"grpc_request" => {
let x: GrpcRequest = spte::deserialize(v).map_err(serde::de::Error::custom)?;
Ok(SyncModel::GrpcRequest(x))
}
"websocket_request" => {
let x: WebsocketRequest = spte::deserialize(v).map_err(serde::de::Error::custom)?;
Ok(SyncModel::WebsocketRequest(x))
}
other => Err(serde::de::Error::unknown_variant(
other,
&[
"workspace",
"environment",
"folder",
"http_request",
"grpc_request",
"websocket_request",
],
)),
}
}
}
fn migrate_environment(obj: &mut Mapping) {
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 {
obj.insert("parentModel".into(), "environment".into());
}
}
_ => {}
}
}
impl SyncModel {
pub fn from_bytes(content: Vec<u8>, file_path: &Path) -> Result<Option<(SyncModel, String)>> {
let mut hasher = Sha1::new();
@@ -145,3 +219,83 @@ impl TryFrom<AnyModel> for SyncModel {
Ok(m)
}
}
#[cfg(test)]
mod migration_tests {
use crate::error::Result;
use crate::models::SyncModel;
#[test]
fn deserializes_environment_via_syncmodel_with_fixups() -> Result<()> {
let raw = r#"
type: environment
model: environment
id: ev_fAUS49FUN2
workspaceId: wk_kfSI3JDHd7
createdAt: 2025-01-11T17:02:58.012792
updatedAt: 2025-07-23T20:00:46.049649
name: Global Variables
public: true
base: true
variables: []
color: null
"#;
let m: SyncModel = serde_yaml::from_str(raw)?;
match m {
SyncModel::Environment(env) => {
assert_eq!(env.parent_model, "workspace".to_string());
assert_eq!(env.parent_id, None);
}
_ => panic!("expected base environment"),
}
let raw = r#"
type: environment
model: environment
id: ev_fAUS49FUN2
workspaceId: wk_kfSI3JDHd7
createdAt: 2025-01-11T17:02:58.012792
updatedAt: 2025-07-23T20:00:46.049649
name: Global Variables
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, "environment".to_string());
assert_eq!(env.parent_id, None);
}
_ => 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(())
}
}

View File

@@ -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"

View File

@@ -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(())
}
}

View File

@@ -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?;

View File

@@ -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,

View File

@@ -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 });
},
});

View File

@@ -0,0 +1,20 @@
import type { ReactNode } from 'react';
import { appInfo } from '../lib/appInfo';
interface Props {
children: ReactNode;
feature: 'updater' | 'license';
}
const featureMap: Record<Props['feature'], boolean> = {
updater: appInfo.featureUpdater,
license: appInfo.featureLicense,
};
export function CargoFeature({ children, feature }: Props) {
if (featureMap[feature]) {
return <>{children}</>;
} else {
return null;
}
}

View File

@@ -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',

View File

@@ -51,7 +51,7 @@ export function ConfirmLargeResponse({ children, response }: Props) {
color="secondary"
variant="border"
size="xs"
text={() => getResponseBodyText({ responseId: response.id, filter: null })}
text={() => getResponseBodyText({ response, filter: null })}
/>
)}
</HStack>

View File

@@ -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);
};

View File

@@ -17,14 +17,14 @@ import { DismissibleBanner } from './core/DismissibleBanner';
import type { GenericCompletionConfig } from './core/Editor/genericCompletion';
import { Heading } from './core/Heading';
import type { PairWithId } from './core/PairEditor';
import { ensurePairId } from './core/PairEditor';
import { ensurePairId } from './core/PairEditor.util';
import { PairOrBulkEditor } from './core/PairOrBulkEditor';
import { VStack } from './core/Stacks';
import { EnvironmentColorIndicator } from './EnvironmentColorIndicator';
import { EnvironmentSharableTooltip } from './EnvironmentSharableTooltip';
export function EnvironmentEditor({
environment: selectedEnvironment,
environment,
hideName,
className,
}: {
@@ -32,7 +32,7 @@ export function EnvironmentEditor({
hideName?: boolean;
className?: string;
}) {
const workspaceId = selectedEnvironment.workspaceId;
const workspaceId = environment.workspaceId;
const isEncryptionEnabled = useIsEncryptionEnabled();
const valueVisibility = useKeyValue<boolean>({
namespace: 'global',
@@ -41,15 +41,15 @@ export function EnvironmentEditor({
});
const { allEnvironments } = useEnvironmentsBreakdown();
const handleChange = useCallback(
(variables: PairWithId[]) => patchModel(selectedEnvironment, { variables }),
[selectedEnvironment],
(variables: PairWithId[]) => patchModel(environment, { variables }),
[environment],
);
const [forceUpdateKey, regenerateForceUpdateKey] = useRandomKey();
// Gather a list of env names from other environments to help the user get them aligned
const nameAutocomplete = useMemo<GenericCompletionConfig>(() => {
const options: GenericCompletionOption[] = [];
if (isBaseEnvironment(selectedEnvironment)) {
if (isBaseEnvironment(environment)) {
return { options };
}
@@ -59,8 +59,10 @@ export function EnvironmentEditor({
const containingEnvs = allEnvironments.filter((e) =>
e.variables.some((v) => v.name === name),
);
const isAlreadyInActive = containingEnvs.find((e) => e.id === selectedEnvironment.id);
if (isAlreadyInActive) continue;
const isAlreadyInActive = containingEnvs.find((e) => e.id === environment.id);
if (isAlreadyInActive) {
continue;
}
options.push({
label: name,
type: 'constant',
@@ -68,7 +70,7 @@ export function EnvironmentEditor({
});
}
return { options };
}, [selectedEnvironment, allEnvironments]);
}, [environment, allEnvironments]);
const validateName = useCallback((name: string) => {
// Empty just means the variable doesn't have a name yet and is unusable
@@ -79,10 +81,8 @@ export function EnvironmentEditor({
const valueType = !isEncryptionEnabled && valueVisibility.value ? 'text' : 'password';
const allVariableAreEncrypted = useMemo(
() =>
selectedEnvironment.variables.every(
(v) => v.value === '' || analyzeTemplate(v.value) !== 'insecure',
),
[selectedEnvironment.variables],
environment.variables.every((v) => v.value === '' || analyzeTemplate(v.value) !== 'insecure'),
[environment.variables],
);
const encryptEnvironment = (environment: Environment) => {
@@ -100,11 +100,11 @@ export function EnvironmentEditor({
return (
<VStack space={4} className={className}>
<Heading className="w-full flex items-center gap-0.5">
<EnvironmentColorIndicator clickToEdit environment={selectedEnvironment ?? null} />
{!hideName && <div className="mr-2">{selectedEnvironment?.name}</div>}
<EnvironmentColorIndicator clickToEdit environment={environment ?? null} />
{!hideName && <div className="mr-2">{environment?.name}</div>}
{isEncryptionEnabled ? (
!allVariableAreEncrypted ? (
<BadgeButton color="notice" onClick={() => encryptEnvironment(selectedEnvironment)}>
<BadgeButton color="notice" onClick={() => encryptEnvironment(environment)}>
Encrypt All Variables
</BadgeButton>
) : (
@@ -121,22 +121,22 @@ export function EnvironmentEditor({
color="secondary"
rightSlot={<EnvironmentSharableTooltip />}
onClick={async () => {
await patchModel(selectedEnvironment, { public: !selectedEnvironment.public });
await patchModel(environment, { public: !environment.public });
}}
>
{selectedEnvironment.public ? 'Sharable' : 'Private'}
{environment.public ? 'Sharable' : 'Private'}
</BadgeButton>
</Heading>
{selectedEnvironment.public && (!isEncryptionEnabled || !allVariableAreEncrypted) && (
{environment.public && (!isEncryptionEnabled || !allVariableAreEncrypted) && (
<DismissibleBanner
id={`warn-unencrypted-${selectedEnvironment.id}`}
id={`warn-unencrypted-${environment.id}`}
color="notice"
className="mr-3"
actions={[
{
label: 'Encrypt Variables',
onClick: () => encryptEnvironment(selectedEnvironment),
color: 'primary',
onClick: () => encryptEnvironment(environment),
color: 'success',
},
]}
>
@@ -151,17 +151,13 @@ export function EnvironmentEditor({
namePlaceholder="VAR_NAME"
nameValidate={validateName}
valueType={valueType}
valueAutocompleteVariables
valueAutocompleteVariables='environment'
valueAutocompleteFunctions
forceUpdateKey={`${selectedEnvironment.id}::${forceUpdateKey}`}
pairs={selectedEnvironment.variables}
forceUpdateKey={`${environment.id}::${forceUpdateKey}`}
pairs={environment.variables}
onChange={handleChange}
stateKey={`environment.${selectedEnvironment.id}`}
forcedEnvironmentId={
// Editing the base environment should resolve variables using the active environment.
// Editing a sub environment should resolve variables as if it's the active environment
isBaseEnvironment(selectedEnvironment) ? undefined : selectedEnvironment.id
}
stateKey={`environment.${environment.id}`}
forcedEnvironmentId={environment.id}
/>
</div>
</VStack>

Some files were not shown because too many files have changed in this diff Show More