Compare commits

..
Author SHA1 Message Date
Gregory Schier 11e71b4b96 Add feature hints for sync, variables, encryption, and chaining 2026-09-14 21:31:47 -07:00
Gregory Schier 7c660f4528 Correct the language table in the HTTP Snippet README (#656) 2026-09-14 13:41:33 -07:00
Gregory Schier 0337ef35c9 Describe the request template functions (#655) 2026-09-14 12:38:21 -07:00
Gregory SchierandClaude Fable 5 602bd1bb45 Move Install under the screenshot and License to the end of the README
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-13 11:03:59 -07:00
Gregory SchierandClaude Fable 5 57ab349901 Add install and license sections to the README
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-13 11:02:35 -07:00
Gregory SchierandClaude Opus 5 7a6d275fdb feat(auth-oauth2): custom parameters for authorization, token, and refresh requests (#629)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 09:15:25 -07:00
Gregory Schier 7d0926c961 fix(input): opt plain inputs out of macOS Writing Tools suggestions (#646) 2026-09-13 09:15:15 -07:00
Gregory SchierandClaude Opus 5 522b898620 feat(auth): add HTTP Digest authentication plugin (#628)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 09:15:06 -07:00
Gregory SchierandClaude Fable 5.1 cb7ed9264d feat(client): show an indicator on the Info tab when a request has a description (#645)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 09:12:42 -07:00
Gregory SchierandClaude Fable 5.1 90cb578e26 Route all database writes through one connection (#642)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 08:12:41 -07:00
Gregory SchierandClaude Fable 5.1 ff7eebf3cd fix(importer-curl): join line continuations that have trailing whitespace (#644)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-12 23:33:54 -07:00
Ngo Quoc Viet eff0c06cb0 fix(importer-postman): stop swapping the API key name and its value (#643) 2026-09-12 12:52:20 -07:00
dependabot[bot] c6e09a5af3 Bump vite-plus from 0.2.9 to 0.3.0 in the npm-development group (#632)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-09-11 08:17:56 -07:00
dependabot[bot] b05071ef4b Bump cpy-cli from 5.0.0 to 7.0.0 (#633)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-09-11 08:17:40 -07:00
dependabot[bot] a44f31eeb2 Bump cpx2 from 8.0.2 to 9.0.0 (#634)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-09-11 08:17:26 -07:00
dependabot[bot] 1103d05915 Bump zip from 4.0.0 to 7.0.0 (#637)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-09-11 08:17:15 -07:00
Gregory SchierandClaude Fable 5.1 2f5639a26f chore: cargo fmt
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-10 19:35:33 -07:00
Gregory SchierandClaude Opus 5 7f8b7bf567 feat(import): remember the user's import selection (#619)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 15:26:43 -07:00
Gregory Schier 096e83a7bd chore(deps): patch open security advisories across npm deps (#630) 2026-09-10 14:34:00 -07:00
gschier 89ce84cefe Deploying to main from @ mountain-loop/yaak@d5d2a64c32 🚀 2026-09-10 15:37:06 +00:00
Gregory Schier d5d2a64c32 fix(cli): focus the agent skill description on when to use it (#625) 2026-09-09 08:50:26 -07:00
Gregory Schier d2d4b80a09 feat(import): merge re-imports from a linked source instead of duplicating (#618) 2026-09-01 11:12:07 -07:00
Gregory Schier d461c982ec Don't block window creation on plugin runtime boot (#616) 2026-09-01 09:14:50 -07:00
Gregory SchierandClaude Fable 5 8eebee460e fix(pair-editor): remount the editor when its stateKey changes (#617)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-01 08:58:55 -07:00
Gregory SchierandClaude Opus 5 81a2a5d955 feat(import): add stable per-resource source keys to the importer contract (#614)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-01 08:11:54 -07:00
Gregory SchierandClaude Opus 5 e63a87718c fix(tooling): keep the formatter off generated files in every entry point (#615)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-01 07:40:42 -07:00
Gregory Schier 222ea9cb83 fix(editor): opt editors out of macOS Writing Tools suggestions
A "Write with Siri" pill appears over empty editors on the macOS 27 beta,
because Codemirror's contentDOM is a contenteditable like any other. The
`writingsuggestions` attribute opts an editable element out, and setting
it here covers every editor at once.

If the pill turns out to be separate from writing suggestions, the
remaining lever is WKWebView's writingToolsBehavior, which would disable
Writing Tools for the whole window.
2026-08-31 10:55:05 -07:00
Gregory Schier 360c098b09 fix(grpc): remove the dead Refresh item from the method picker
It has never had an onSelect. Introduced inert in #193 and carried
through the codebase split, so clicking it only ever closed the dropdown.
Reload Schema in the message editor's schema dropdown does the job it
looked like it was for.
2026-08-31 10:54:40 -07:00
Gregory Schier fce1039bac feat(grpc): generate an example message from the method schema (#613) 2026-08-31 10:44:31 -07:00
Gregory Schier f18f93d613 Stage imports before committing (#571) 2026-08-31 10:20:44 -07:00
Gregory SchierandClaude Opus 5 661a384bed Faster codemirror search match counting (#612)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 10:09:50 -07:00
Gregory SchierandClaude Fable 5 50cccf1d25 fix(auth-oauth1): sign with the token secret when no access token is set (#611)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-27 15:27:40 -07:00
Gregory SchierandClaude Fable 5 0aae516f3a feat(importer-openapi): fill the OAuth redirect URI from an environment variable (#610)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-27 15:27:36 -07:00
Gregory SchierandClaude Fable 5 b7b8ae5f94 feat(settings): add HTTP version as an inherited request setting (#609)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-27 15:01:02 -07:00
Gregory SchierandClaude Fable 5 6777003b70 fix(updater): check for updates on Linux deb/rpm installs and prompt manual download (#604)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-25 19:43:54 -07:00
Gregory SchierandClaude Fable 5 426c6d5eb6 fix(plugins): render template function config values before plugins see them (#608)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-25 19:19:15 -07:00
Ngo Quoc Viet 068afe325e fix(importer-curl): keep an = inside --url-query and form values (#606) 2026-08-24 21:14:37 -07:00
Ngo Quoc Viet cef1129d4b fix(template-function-json): escape control characters in json.escape (#607) 2026-08-24 21:14:14 -07:00
Ngo Quoc Viet 9a7bcf73bb fix(auth-oauth1): use the signing key as the PLAINTEXT signature (#605) 2026-08-24 21:13:57 -07:00
Gregory SchierandClaude Opus 5 aa76d501f0 fix(appearance): detect the macOS system appearance via NSApp.effectiveAppearance (#603)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 00:04:26 -07:00
226 changed files with 15170 additions and 3878 deletions

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
day: monday
open-pull-requests-limit: 5
groups:
npm-production:
dependency-type: production
update-types:
- minor
- patch
npm-development:
dependency-type: development
update-types:
- minor
- patch
- package-ecosystem: cargo
directory: /
schedule:
interval: weekly
day: monday
open-pull-requests-limit: 5
groups:
cargo:
patterns:
- "*"
update-types:
- minor
- patch
-3
View File
@@ -1,3 +0,0 @@
**/bindings/**
**/routeTree.gen.ts
crates/yaak-templates/pkg/**
Generated
+57 -28
View File
@@ -960,15 +960,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "bzip2"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
dependencies = [
"bzip2-sys",
]
[[package]] [[package]]
name = "bzip2" name = "bzip2"
version = "0.6.1" version = "0.6.1"
@@ -978,16 +969,6 @@ dependencies = [
"libbz2-rs-sys", "libbz2-rs-sys",
] ]
[[package]]
name = "bzip2-sys"
version = "0.1.13+1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
dependencies = [
"cc",
"pkg-config",
]
[[package]] [[package]]
name = "cairo-rs" name = "cairo-rs"
version = "0.18.5" version = "0.18.5"
@@ -2114,7 +2095,7 @@ version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c169adf067a787e1f1c58ed62906a557de85388bee4b54fb878b722ff606b113" checksum = "c169adf067a787e1f1c58ed62906a557de85388bee4b54fb878b722ff606b113"
dependencies = [ dependencies = [
"bzip2 0.6.1", "bzip2",
"clap", "clap",
"fs-err", "fs-err",
"indicatif", "indicatif",
@@ -2914,11 +2895,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys",
"libc", "libc",
"r-efi", "r-efi",
"wasi 0.14.2+wasi-0.2.4", "wasi 0.14.2+wasi-0.2.4",
"wasm-bindgen",
] ]
[[package]] [[package]]
@@ -4194,6 +4173,15 @@ dependencies = [
"value-bag", "value-bag",
] ]
[[package]]
name = "lzma-rust2"
version = "0.15.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e20f57f9918e5bd7bc58c22cdd70a6afc7375d4dd9683af5f2b34bd3d2bba619"
dependencies = [
"sha2",
]
[[package]] [[package]]
name = "mac" name = "mac"
version = "0.1.1" version = "0.1.1"
@@ -6174,6 +6162,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppmd-rust"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e9219bcb9d7aca6b2f63c83cf100cf78bcd619ac46e6ecbd0dd90869a39345d"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.21" version = "0.2.21"
@@ -8906,7 +8900,7 @@ dependencies = [
"tokio", "tokio",
"url", "url",
"windows-sys 0.60.2", "windows-sys 0.60.2",
"zip", "zip 4.6.1",
] ]
[[package]] [[package]]
@@ -11223,9 +11217,12 @@ version = "0.1.0"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"base64 0.22.1", "base64 0.22.1",
"chrono",
"log 0.4.29", "log 0.4.29",
"md5 0.8.0", "md5 0.8.0",
"rusqlite",
"serde_json", "serde_json",
"sha2",
"tempfile", "tempfile",
"thiserror 2.0.17", "thiserror 2.0.17",
"tokio", "tokio",
@@ -11373,7 +11370,7 @@ dependencies = [
"yaak-models", "yaak-models",
"yaak-plugins", "yaak-plugins",
"yaak-templates", "yaak-templates",
"zip", "zip 7.0.0",
] ]
[[package]] [[package]]
@@ -11723,7 +11720,10 @@ name = "yaak-system-appearance"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dark-light", "dark-light",
"dispatch2",
"log 0.4.29", "log 0.4.29",
"objc2-app-kit",
"objc2-foundation 0.3.1",
"tauri", "tauri",
] ]
@@ -12040,13 +12040,13 @@ dependencies = [
[[package]] [[package]]
name = "zip" name = "zip"
version = "4.0.0" version = "4.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "153a6fff49d264c4babdcfa6b4d534747f520e56e8f0f384f3b808c4b64cc1fd" checksum = "caa8cd6af31c3b31c6631b8f483848b91589021b28fffe50adada48d4f4d2ed1"
dependencies = [ dependencies = [
"aes", "aes",
"arbitrary", "arbitrary",
"bzip2 0.5.2", "bzip2",
"constant_time_eq 0.3.1", "constant_time_eq 0.3.1",
"crc32fast", "crc32fast",
"deflate64", "deflate64",
@@ -12057,6 +12057,35 @@ dependencies = [
"liblzma", "liblzma",
"memchr", "memchr",
"pbkdf2", "pbkdf2",
"ppmd-rust",
"sha1",
"time",
"zeroize",
"zopfli",
"zstd",
]
[[package]]
name = "zip"
version = "7.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdd8a47718a4ee5fe78e07667cd36f3de80e7c2bfe727c7074245ffc7303c037"
dependencies = [
"aes",
"arbitrary",
"bzip2",
"constant_time_eq 0.3.1",
"crc32fast",
"deflate64",
"flate2",
"generic-array",
"getrandom 0.3.3",
"hmac",
"indexmap 2.14.0",
"lzma-rust2",
"memchr",
"pbkdf2",
"ppmd-rust",
"sha1", "sha1",
"time", "time",
"zeroize", "zeroize",
@@ -12072,7 +12101,7 @@ checksum = "aed5f10c571472911e37d8f7601a8dfba52b4f7f73a344015291b82ab292faf6"
dependencies = [ dependencies = [
"log 0.4.29", "log 0.4.29",
"thiserror 2.0.17", "thiserror 2.0.17",
"zip", "zip 4.6.1",
] ]
[[package]] [[package]]
+11 -1
View File
@@ -17,7 +17,7 @@
<br> <br>
<p align="center"> <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/bytebase"><img src="https:&#x2F;&#x2F;github.com&#x2F;bytebase.png" width="80px" alt="User avatar: bytebase" /></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 --> <!-- 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/bytebase"><img src="https:&#x2F;&#x2F;github.com&#x2F;bytebase.png" width="80px" alt="User avatar: bytebase" /></a>&nbsp;&nbsp;<a href="https://github.com/rauchg"><img src="https:&#x2F;&#x2F;github.com&#x2F;rauchg.png" width="80px" alt="User avatar: rauchg" /></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>
<p align="center"> <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;<a href="https://github.com/andriyor"><img src="https:&#x2F;&#x2F;github.com&#x2F;andriyor.png" width="50px" alt="User avatar: andriyor" /></a>&nbsp;&nbsp;<a href="https://github.com/majudhu"><img src="https:&#x2F;&#x2F;github.com&#x2F;majudhu.png" width="50px" alt="User avatar: majudhu" /></a>&nbsp;&nbsp;<a href="https://github.com/axelrindle"><img src="https:&#x2F;&#x2F;github.com&#x2F;axelrindle.png" width="50px" alt="User avatar: axelrindle" /></a>&nbsp;&nbsp;<a href="https://github.com/jirizverina"><img src="https:&#x2F;&#x2F;github.com&#x2F;jirizverina.png" width="50px" alt="User avatar: jirizverina" /></a>&nbsp;&nbsp;<a href="https://github.com/chip-well"><img src="https:&#x2F;&#x2F;github.com&#x2F;chip-well.png" width="50px" alt="User avatar: chip-well" /></a>&nbsp;&nbsp;<a href="https://github.com/GRAYAH"><img src="https:&#x2F;&#x2F;github.com&#x2F;GRAYAH.png" width="50px" alt="User avatar: GRAYAH" /></a>&nbsp;&nbsp;<a href="https://github.com/flashblaze"><img src="https:&#x2F;&#x2F;github.com&#x2F;flashblaze.png" width="50px" alt="User avatar: flashblaze" /></a>&nbsp;&nbsp;<a href="https://github.com/Frostist"><img src="https:&#x2F;&#x2F;github.com&#x2F;Frostist.png" width="50px" alt="User avatar: Frostist" /></a>&nbsp;&nbsp;<a href="https://github.com/PurplProto"><img src="https:&#x2F;&#x2F;github.com&#x2F;PurplProto.png" width="50px" alt="User avatar: PurplProto" /></a>&nbsp;&nbsp;<!-- sponsors-base --> <!-- 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;<a href="https://github.com/andriyor"><img src="https:&#x2F;&#x2F;github.com&#x2F;andriyor.png" width="50px" alt="User avatar: andriyor" /></a>&nbsp;&nbsp;<a href="https://github.com/majudhu"><img src="https:&#x2F;&#x2F;github.com&#x2F;majudhu.png" width="50px" alt="User avatar: majudhu" /></a>&nbsp;&nbsp;<a href="https://github.com/axelrindle"><img src="https:&#x2F;&#x2F;github.com&#x2F;axelrindle.png" width="50px" alt="User avatar: axelrindle" /></a>&nbsp;&nbsp;<a href="https://github.com/jirizverina"><img src="https:&#x2F;&#x2F;github.com&#x2F;jirizverina.png" width="50px" alt="User avatar: jirizverina" /></a>&nbsp;&nbsp;<a href="https://github.com/chip-well"><img src="https:&#x2F;&#x2F;github.com&#x2F;chip-well.png" width="50px" alt="User avatar: chip-well" /></a>&nbsp;&nbsp;<a href="https://github.com/GRAYAH"><img src="https:&#x2F;&#x2F;github.com&#x2F;GRAYAH.png" width="50px" alt="User avatar: GRAYAH" /></a>&nbsp;&nbsp;<a href="https://github.com/flashblaze"><img src="https:&#x2F;&#x2F;github.com&#x2F;flashblaze.png" width="50px" alt="User avatar: flashblaze" /></a>&nbsp;&nbsp;<a href="https://github.com/Frostist"><img src="https:&#x2F;&#x2F;github.com&#x2F;Frostist.png" width="50px" alt="User avatar: Frostist" /></a>&nbsp;&nbsp;<a href="https://github.com/PurplProto"><img src="https:&#x2F;&#x2F;github.com&#x2F;PurplProto.png" width="50px" alt="User avatar: PurplProto" /></a>&nbsp;&nbsp;<!-- sponsors-base -->
@@ -25,6 +25,10 @@
![Yaak API Client](https://yaak.app/static/screenshot.png) ![Yaak API Client](https://yaak.app/static/screenshot.png)
## Install
Download Yaak for macOS, Windows, or Linux from [yaak.app/download](https://yaak.app/download). Package managers and other install methods are in the [installation docs](https://yaak.app/docs/getting-started/installation).
## Features ## 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. Yaak is an offline-first API client designed to stay out of your way while giving you everything you need when you need it.
@@ -68,3 +72,9 @@ Built with [Tauri](https://tauri.app), Rust, and React, it’s fast, lightweight
- [Yaak vs Postman](https://yaak.app/alternatives/postman) - [Yaak vs Postman](https://yaak.app/alternatives/postman)
- [Yaak vs Bruno](https://yaak.app/alternatives/bruno) - [Yaak vs Bruno](https://yaak.app/alternatives/bruno)
- [Yaak vs Insomnia](https://yaak.app/alternatives/insomnia) - [Yaak vs Insomnia](https://yaak.app/alternatives/insomnia)
## License
The source is [MIT licensed](LICENSE) and can be built and run for free, for both personal and commercial use.
The prebuilt binaries follow Yaak's [pricing terms](https://yaak.app/pricing): free for personal use, license required for commercial use.
@@ -1,10 +1,16 @@
import type { WorkspaceSettingsTab } from "../components/WorkspaceSettingsDialog"; import type {
WorkspaceSettingsHighlight,
WorkspaceSettingsTab,
} from "../components/WorkspaceSettingsDialog";
import { WorkspaceSettingsDialog } from "../components/WorkspaceSettingsDialog"; import { WorkspaceSettingsDialog } from "../components/WorkspaceSettingsDialog";
import { activeWorkspaceIdAtom } from "../hooks/useActiveWorkspace"; import { activeWorkspaceIdAtom } from "../hooks/useActiveWorkspace";
import { jotaiStore } from "../lib/jotai"; import { jotaiStore } from "../lib/jotai";
export function openWorkspaceSettings(tab?: WorkspaceSettingsTab) { export function openWorkspaceSettings(
tab?: WorkspaceSettingsTab,
highlight?: WorkspaceSettingsHighlight,
) {
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom); const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
if (workspaceId == null) return; if (workspaceId == null) return;
WorkspaceSettingsDialog.show(workspaceId, tab); WorkspaceSettingsDialog.show(workspaceId, tab, highlight);
} }
+23 -4
View File
@@ -31,6 +31,7 @@ import type { Pair } from "./core/PairEditor";
import { PairEditor } from "./core/PairEditor"; import { PairEditor } from "./core/PairEditor";
import { PlainInput } from "./core/PlainInput"; import { PlainInput } from "./core/PlainInput";
import { Select } from "./core/Select"; import { Select } from "./core/Select";
import { SecretVariableHint } from "./hints/SecretVariableHint";
import { Markdown } from "./Markdown"; import { Markdown } from "./Markdown";
import { SelectFile } from "./SelectFile"; import { SelectFile } from "./SelectFile";
@@ -46,6 +47,8 @@ interface Props<T> {
stateKey: string; stateKey: string;
className?: string; className?: string;
disabled?: boolean; disabled?: boolean;
/** Offer to move literal secrets typed into password fields into a variable */
suggestVariables?: boolean;
} }
export function DynamicForm<T extends Record<string, JsonPrimitive>>({ export function DynamicForm<T extends Record<string, JsonPrimitive>>({
@@ -57,6 +60,7 @@ export function DynamicForm<T extends Record<string, JsonPrimitive>>({
stateKey, stateKey,
className, className,
disabled, disabled,
suggestVariables,
}: Props<T>) { }: Props<T>) {
const setDataAttr = useCallback( const setDataAttr = useCallback(
(name: string, value: JsonPrimitive) => { (name: string, value: JsonPrimitive) => {
@@ -73,6 +77,7 @@ export function DynamicForm<T extends Record<string, JsonPrimitive>>({
stateKey={stateKey} stateKey={stateKey}
autocompleteFunctions={autocompleteFunctions} autocompleteFunctions={autocompleteFunctions}
autocompleteVariables={autocompleteVariables} autocompleteVariables={autocompleteVariables}
suggestVariables={suggestVariables}
data={data} data={data}
className={classNames(className, "pb-4")} // Pad the bottom to look nice className={classNames(className, "pb-4")} // Pad the bottom to look nice
/> />
@@ -103,6 +108,7 @@ type FormInputsProps<T> = Pick<
> & { > & {
setDataAttr: (name: string, value: JsonPrimitive) => void; setDataAttr: (name: string, value: JsonPrimitive) => void;
disabled?: boolean; disabled?: boolean;
suggestVariables?: boolean;
}; };
function FormInputs<T extends Record<string, JsonPrimitive>>({ function FormInputs<T extends Record<string, JsonPrimitive>>({
@@ -113,6 +119,7 @@ function FormInputs<T extends Record<string, JsonPrimitive>>({
setDataAttr, setDataAttr,
data, data,
disabled, disabled,
suggestVariables,
}: FormInputsProps<T>) { }: FormInputsProps<T>) {
return ( return (
<> <>
@@ -147,6 +154,7 @@ function FormInputs<T extends Record<string, JsonPrimitive>>({
arg={input} arg={input}
autocompleteFunctions={autocompleteFunctions || false} autocompleteFunctions={autocompleteFunctions || false}
autocompleteVariables={autocompleteVariables || false} autocompleteVariables={autocompleteVariables || false}
suggestVariables={suggestVariables || false}
onChange={(v) => setDataAttr(input.name, v)} onChange={(v) => setDataAttr(input.name, v)}
value={ value={
data[input.name] != null ? String(data[input.name]) : (input.defaultValue ?? "") data[input.name] != null ? String(data[input.name]) : (input.defaultValue ?? "")
@@ -287,6 +295,7 @@ function TextArg({
value, value,
autocompleteFunctions, autocompleteFunctions,
autocompleteVariables, autocompleteVariables,
suggestVariables,
stateKey, stateKey,
}: { }: {
arg: FormInputText; arg: FormInputText;
@@ -294,6 +303,7 @@ function TextArg({
onChange: (v: string) => void; onChange: (v: string) => void;
autocompleteFunctions: boolean; autocompleteFunctions: boolean;
autocompleteVariables: boolean; autocompleteVariables: boolean;
suggestVariables: boolean;
stateKey: string; stateKey: string;
}) { }) {
const props: InputProps = { const props: InputProps = {
@@ -316,10 +326,19 @@ function TextArg({
autocompleteFunctions, autocompleteFunctions,
autocompleteVariables, autocompleteVariables,
}; };
if (autocompleteVariables || autocompleteFunctions || arg.completionOptions) { const input =
return <Input {...props} />; autocompleteVariables || autocompleteFunctions || arg.completionOptions ? (
} <Input {...props} />
return <PlainInput {...props} />; ) : (
<PlainInput {...props} />
);
if (!suggestVariables || !arg.password) return input;
return (
<div className="flex flex-col gap-2">
{input}
<SecretVariableHint name={arg.name} value={value} onReplace={onChange} />
</div>
);
} }
function EditorArg({ function EditorArg({
@@ -15,6 +15,7 @@ import {
withEncryptionEnabled, withEncryptionEnabled,
} from "../lib/setupOrConfigureEncryption"; } from "../lib/setupOrConfigureEncryption";
import { DismissibleBanner } from "./core/DismissibleBanner"; import { DismissibleBanner } from "./core/DismissibleBanner";
import { FeatureHint } from "./core/FeatureHint";
import type { GenericCompletionConfig } from "./core/Editor/genericCompletion"; import type { GenericCompletionConfig } from "./core/Editor/genericCompletion";
import type { PairEditorHandle, PairWithId } from "./core/PairEditor"; import type { PairEditorHandle, PairWithId } from "./core/PairEditor";
import { ensurePairId } from "./core/PairEditor.util"; import { ensurePairId } from "./core/PairEditor.util";
@@ -152,6 +153,17 @@ export function EnvironmentEditor({ environment, hideName, className, setRef }:
This sharable environment contains plain-text secrets This sharable environment contains plain-text secrets
</DismissibleBanner> </DismissibleBanner>
)} )}
{!environment.public && !isEncryptionEnabled && hasSecretLookingVariable(environment) && (
<FeatureHint
id="encrypt-secrets"
className="mr-3"
docsUrl="https://yaak.app/docs/collaboration/secrets-encryption"
action={{ label: "Enable Encryption", onClick: setupOrConfigureEncryption }}
>
Some of these look like secrets. Encrypt them so the workspace is safe to sync to a
folder or share with a team.
</FeatureHint>
)}
</div> </div>
<PairOrBulkEditor <PairOrBulkEditor
setRef={setRef} setRef={setRef}
@@ -173,3 +185,9 @@ export function EnvironmentEditor({ environment, hideName, className, setRef }:
</div> </div>
); );
} }
const SECRET_NAME = /token|secret|password|passwd|api[_-]?key|private[_-]?key|credential/i;
function hasSecretLookingVariable(environment: Environment) {
return environment.variables.some((v) => v.value.trim() !== "" && SECRET_NAME.test(v.name));
}
+180 -63
View File
@@ -1,9 +1,8 @@
import { linter } from "@codemirror/lint"; import { linter } from "@codemirror/lint";
import type { EditorView } from "@codemirror/view"; import type { EditorView } from "@codemirror/view";
import { jsoncLanguage } from "@shopify/lang-jsonc"; import { jsoncLanguage } from "@shopify/lang-jsonc";
import type { GrpcRequest } from "@yaakapp-internal/models"; import { type GrpcRequest, patchModel } from "@yaakapp-internal/models";
import { FormattedError, InlineCode, VStack } from "@yaakapp-internal/ui"; import { Banner, FormattedError, Icon, InlineCode, VStack } from "@yaakapp-internal/ui";
import classNames from "classnames";
import { import {
handleRefresh, handleRefresh,
jsonCompletion, jsonCompletion,
@@ -11,12 +10,20 @@ import {
stateExtensions, stateExtensions,
updateSchema, updateSchema,
} from "codemirror-json-schema"; } from "codemirror-json-schema";
import type { JSONSchema7 } from "json-schema";
import type { ReactNode } from "react";
import { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import type { ReflectResponseService } from "../hooks/useGrpc"; import type { ReflectResponseService } from "../hooks/useGrpc";
import { wasUpdatedExternally } from "../hooks/useRequestUpdateKey";
import { showAlert } from "../lib/alert"; import { showAlert } from "../lib/alert";
import { showConfirm } from "../lib/confirm";
import { showDialog } from "../lib/dialog"; import { showDialog } from "../lib/dialog";
import type { JsonSchema } from "../lib/jsonSchemaExample";
import { buildExampleFromSchema } from "../lib/jsonSchemaExample";
import { pluralizeCount } from "../lib/pluralize"; import { pluralizeCount } from "../lib/pluralize";
import { queryClient } from "../lib/queryClient";
import { Button } from "./core/Button"; import { Button } from "./core/Button";
import { Dropdown } from "./core/Dropdown";
import type { EditorProps } from "./core/Editor/Editor"; import type { EditorProps } from "./core/Editor/Editor";
import { Editor } from "./core/Editor/LazyEditor"; import { Editor } from "./core/Editor/LazyEditor";
import { GrpcProtoSelectionDialog } from "./GrpcProtoSelectionDialog"; import { GrpcProtoSelectionDialog } from "./GrpcProtoSelectionDialog";
@@ -29,6 +36,11 @@ type Props = Pick<EditorProps, "heightMode" | "onChange" | "className" | "forceU
protoFiles: string[]; protoFiles: string[];
}; };
type MethodSchema =
| { type: "none" }
| { type: "schema"; schema: JsonSchema }
| { type: "error"; id: string; title: string; body: ReactNode; log: unknown[] };
export function GrpcEditor({ export function GrpcEditor({
services, services,
reflectionError, reflectionError,
@@ -42,21 +54,16 @@ export function GrpcEditor({
setEditorView(h); setEditorView(h);
}, []); }, []);
// Find the schema for the selected service and method and update the editor // Find the schema for the selected service and method
useEffect(() => { const methodSchema = useMemo<MethodSchema>(() => {
if ( if (services === null || request.service === null || request.method === null) {
editorView == null || return { type: "none" };
services === null ||
request.service === null ||
request.method === null
) {
return;
} }
const s = services.find((s) => s.name === request.service); const s = services.find((s) => s.name === request.service);
if (s == null) { if (s == null) {
console.log("Failed to find service", { service: request.service, services }); return {
showAlert({ type: "error",
id: "grpc-find-service-error", id: "grpc-find-service-error",
title: "Couldn't Find Service", title: "Couldn't Find Service",
body: ( body: (
@@ -64,14 +71,14 @@ export function GrpcEditor({
Failed to find service <InlineCode>{request.service}</InlineCode> in schema Failed to find service <InlineCode>{request.service}</InlineCode> in schema
</> </>
), ),
}); log: ["Failed to find service", { service: request.service, services }],
return; };
} }
const schema = s.methods.find((m) => m.name === request.method)?.schema; const schema = s.methods.find((m) => m.name === request.method)?.schema;
if (request.method != null && schema == null) { if (schema == null) {
console.log("Failed to find method", { method: request.method, methods: s?.methods }); return {
showAlert({ type: "error",
id: "grpc-find-schema-error", id: "grpc-find-schema-error",
title: "Couldn't Find Method", title: "Couldn't Find Method",
body: ( body: (
@@ -80,18 +87,15 @@ export function GrpcEditor({
<InlineCode>{request.service}</InlineCode> in schema <InlineCode>{request.service}</InlineCode> in schema
</> </>
), ),
}); log: ["Failed to find method", { method: request.method, methods: s.methods }],
return; };
}
if (schema == null) {
return;
} }
try { try {
updateSchema(editorView, JSON.parse(schema)); return { type: "schema", schema: JSON.parse(schema) as JsonSchema };
} catch (err) { } catch (err) {
showAlert({ return {
type: "error",
id: "grpc-parse-schema-error", id: "grpc-parse-schema-error",
title: "Failed to Parse Schema", title: "Failed to Parse Schema",
body: ( body: (
@@ -103,9 +107,22 @@ export function GrpcEditor({
<FormattedError>{String(err)}</FormattedError> <FormattedError>{String(err)}</FormattedError>
</VStack> </VStack>
), ),
}); log: ["Failed to parse schema", err],
};
} }
}, [editorView, services, request.method, request.service]); }, [services, request.method, request.service]);
useEffect(() => {
if (methodSchema.type !== "error") return;
console.log(...methodSchema.log);
showAlert({ id: methodSchema.id, title: methodSchema.title, body: methodSchema.body });
}, [methodSchema]);
// Update the editor whenever the schema changes
useEffect(() => {
if (editorView == null || methodSchema.type !== "schema") return;
updateSchema(editorView, methodSchema.schema as JSONSchema7);
}, [editorView, methodSchema]);
const extraExtensions = useMemo( const extraExtensions = useMemo(
() => [ () => [
@@ -124,45 +141,145 @@ export function GrpcEditor({
const reflectionUnavailable = reflectionError?.match(/unimplemented/i); const reflectionUnavailable = reflectionError?.match(/unimplemented/i);
reflectionError = reflectionUnavailable ? undefined : reflectionError; reflectionError = reflectionUnavailable ? undefined : reflectionError;
const handleGenerateExample = useCallback(async () => {
if (methodSchema.type !== "schema") return;
if (request.message.trim() !== "") {
const confirmed = await showConfirm({
id: "grpc-generate-example",
title: "Generate Example",
description: "The current message will be replaced with an example.",
confirmText: "Generate",
});
if (!confirmed) return;
}
const message = JSON.stringify(buildExampleFromSchema(methodSchema.schema), null, 2);
await patchModel(request, { message });
// Force the editor to pick up the new message
wasUpdatedExternally(request.id);
}, [methodSchema, request]);
// The reflect query is keyed by request, url and proto files, so a prefix invalidate
// reaches it without threading a refetch down from the connection layout.
const handleReloadSchema = useCallback(
() => queryClient.invalidateQueries({ queryKey: ["grpc_reflect", request.id] }),
[request.id],
);
const handleShowReflectionError = useCallback(() => {
showDialog({
id: "grpc-reflection-error",
title: "Reflection Failed",
size: "sm",
render: ({ hide }) => (
<>
<FormattedError>{reflectionError ?? "unknown"}</FormattedError>
<div className="w-full my-4">
<Button
className="ml-auto"
color="primary"
size="sm"
onClick={async () => {
hide();
await handleReloadSchema();
}}
>
Retry
</Button>
</div>
</>
),
});
}, [handleReloadSchema, reflectionError]);
const actions = useMemo( const actions = useMemo(
() => [ () => [
<div key="reflection" className={classNames(services == null && "opacity-100!")}> // Matches the GraphQL editor: one always-visible control labelled by schema state,
<Button // with everything schema-related behind it.
size="xs" <div key="schema" className="opacity-100!">
color={ <Dropdown
reflectionLoading items={[
? "secondary" {
: reflectionUnavailable // Hidden for servers without reflection, which isn't an error
? "info" hidden: !reflectionError,
: reflectionError type: "content",
? "danger" label: (
: "secondary" <Banner color="danger">
} <p className="mb-1">Reflection failed</p>
isLoading={reflectionLoading} <Button
onClick={() => { size="xs"
showDialog({ color="danger"
title: "Configure Schema", variant="border"
size: "md", onClick={handleShowReflectionError}
id: "reflection-failed", >
render: ({ hide }) => <GrpcProtoSelectionDialog onDone={hide} />, View Error
}); </Button>
}} </Banner>
),
},
{
label: "Generate Example Message",
leftSlot: <Icon icon="magic_wand" />,
disabled: methodSchema.type !== "schema",
onSelect: handleGenerateExample,
},
{ type: "separator" },
{
label: "Reload Schema",
leftSlot: <Icon icon="refresh" spin={reflectionLoading} />,
keepOpenOnSelect: true,
onSelect: handleReloadSchema,
},
{
label: protoFiles.length > 0 ? "Select Proto Files\u2026" : "Configure Schema\u2026",
leftSlot: <Icon icon="settings" />,
onSelect: () => {
showDialog({
title: "Configure Schema",
size: "md",
id: "grpc-configure-schema",
render: ({ hide }) => <GrpcProtoSelectionDialog onDone={hide} />,
});
},
},
]}
> >
{reflectionLoading <Button
? "Inspecting Schema" size="sm"
: reflectionUnavailable variant="border"
? "Select Proto Files" title="Schema"
: reflectionError forDropdown
? "Server Error" isLoading={reflectionLoading}
: protoFiles.length > 0 color={reflectionUnavailable ? "info" : reflectionError ? "danger" : "default"}
? pluralizeCount("File", protoFiles.length) >
: services != null && protoFiles.length === 0 {reflectionLoading
? "Schema Detected" ? "Inspecting Schema"
: "Select Schema"} : reflectionUnavailable
</Button> ? "Select Proto Files"
: reflectionError
? "Server Error"
: protoFiles.length > 0
? pluralizeCount("File", protoFiles.length)
: services != null
? "Schema Detected"
: "Select Schema"}
</Button>
</Dropdown>
</div>, </div>,
], ],
[protoFiles.length, reflectionError, reflectionLoading, reflectionUnavailable, services], [
handleGenerateExample,
handleReloadSchema,
handleShowReflectionError,
methodSchema.type,
protoFiles.length,
reflectionError,
reflectionLoading,
reflectionUnavailable,
services,
],
); );
return ( return (
@@ -133,6 +133,8 @@ export function GrpcRequestPane({
onSend({ message: activeRequest.message }); onSend({ message: activeRequest.message });
}, [activeRequest, onSend]); }, [activeRequest, onSend]);
const hasDescription = activeRequest.description.trim().length > 0;
const tabs: TabItem[] = useMemo( const tabs: TabItem[] = useMemo(
() => [ () => [
{ value: TAB_MESSAGE, label: "Message" }, { value: TAB_MESSAGE, label: "Message" },
@@ -146,10 +148,10 @@ export function GrpcRequestPane({
{ {
value: TAB_DESCRIPTION, value: TAB_DESCRIPTION,
label: "Info", label: "Info",
rightSlot: activeRequest.description && <CountBadge count={true} />, rightSlot: hasDescription && <CountBadge count={true} />,
}, },
], ],
[activeRequest.description, authTab, metadataTab, numSettingsOverrides], [authTab, hasDescription, metadataTab, numSettingsOverrides],
); );
const handleMetadataChange = useCallback( const handleMetadataChange = useCallback(
@@ -194,13 +196,6 @@ export function GrpcRequestPane({
type: "default", type: "default",
shortLabel: o.label, shortLabel: o.label,
}))} }))}
itemsAfter={[
{
label: "Refresh",
type: "default",
leftSlot: <Icon size="sm" icon="refresh" />,
},
]}
> >
<Button <Button
size="sm" size="sm"
@@ -178,6 +178,7 @@ export function HttpAuthenticationEditor({ model }: Props) {
disabled={model.authentication.disabled === true} disabled={model.authentication.disabled === true}
autocompleteVariables autocompleteVariables
autocompleteFunctions autocompleteFunctions
suggestVariables
stateKey={`auth.${model.id}.${model.authenticationType}`} stateKey={`auth.${model.id}.${model.authenticationType}`}
inputs={authConfig.data?.args ?? []} inputs={authConfig.data?.args ?? []}
data={model.authentication} data={model.authentication}
+26 -18
View File
@@ -52,6 +52,7 @@ import { JsonBodyEditor } from "./JsonBodyEditor";
import { MarkdownEditor } from "./MarkdownEditor"; import { MarkdownEditor } from "./MarkdownEditor";
import { RequestMethodDropdown } from "./RequestMethodDropdown"; import { RequestMethodDropdown } from "./RequestMethodDropdown";
import { countOverriddenSettings, ModelSettingsEditor } from "./ModelSettingsEditor"; import { countOverriddenSettings, ModelSettingsEditor } from "./ModelSettingsEditor";
import { SharedOriginHint } from "./hints/SharedOriginHint";
import { UrlBar } from "./UrlBar"; import { UrlBar } from "./UrlBar";
import { UrlParametersEditor } from "./UrlParameterEditor"; import { UrlParametersEditor } from "./UrlParameterEditor";
@@ -165,6 +166,8 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }:
: 0; : 0;
} }
const hasDescription = activeRequest.description.trim().length > 0;
const tabs = useMemo<TabItem[]>( const tabs = useMemo<TabItem[]>(
() => [ () => [
{ {
@@ -260,6 +263,7 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }:
{ {
value: TAB_DESCRIPTION, value: TAB_DESCRIPTION,
label: "Info", label: "Info",
rightSlot: hasDescription && <CountBadge count={true} />,
}, },
], ],
[ [
@@ -267,6 +271,7 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }:
authTab, authTab,
contentType, contentType,
handleContentTypeChange, handleContentTypeChange,
hasDescription,
headersTab, headersTab,
numParams, numParams,
numSettingsOverrides, numSettingsOverrides,
@@ -340,24 +345,27 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }:
> >
{activeRequest && ( {activeRequest && (
<> <>
<UrlBar <div>
stateKey={`url.${activeRequest.id}`} <UrlBar
key={forceUpdateKey + urlKey} stateKey={`url.${activeRequest.id}`}
url={activeRequest.url} key={forceUpdateKey + urlKey}
placeholder="https://example.com" url={activeRequest.url}
onPasteOverwrite={handlePaste} placeholder="https://example.com"
autocomplete={autocomplete} onPasteOverwrite={handlePaste}
onSend={handleSend} autocomplete={autocomplete}
onCancel={cancelResponse} onSend={handleSend}
onUrlChange={handleUrlChange} onCancel={cancelResponse}
leftSlot={ onUrlChange={handleUrlChange}
<div className="py-0.5"> leftSlot={
<RequestMethodDropdown request={activeRequest} className="ml-0.5 h-full!" /> <div className="py-0.5">
</div> <RequestMethodDropdown request={activeRequest} className="ml-0.5 h-full!" />
} </div>
forceUpdateKey={updateKey} }
isLoading={activeResponse != null && activeResponse.state !== "closed"} forceUpdateKey={updateKey}
/> isLoading={activeResponse != null && activeResponse.state !== "closed"}
/>
<SharedOriginHint />
</div>
<Tabs <Tabs
ref={tabsRef} ref={tabsRef}
label="Request" label="Request"
@@ -28,6 +28,7 @@ import { TabContent, Tabs } from "./core/Tabs/Tabs";
import { Tooltip } from "./core/Tooltip"; import { Tooltip } from "./core/Tooltip";
import { EmptyStateText } from "./EmptyStateText"; import { EmptyStateText } from "./EmptyStateText";
import { ErrorBoundary } from "./ErrorBoundary"; import { ErrorBoundary } from "./ErrorBoundary";
import { ChainingHint } from "./hints/ChainingHint";
import { HttpResponseTimeline } from "./HttpResponseTimeline"; import { HttpResponseTimeline } from "./HttpResponseTimeline";
import { RecentHttpResponsesDropdown } from "./RecentHttpResponsesDropdown"; import { RecentHttpResponsesDropdown } from "./RecentHttpResponsesDropdown";
import { RequestBodyViewer } from "./RequestBodyViewer"; import { RequestBodyViewer } from "./RequestBodyViewer";
@@ -280,6 +281,7 @@ export function HttpResponsePane({ style, className, activeRequestId }: Props) {
{activeResponse.error} {activeResponse.error}
</Banner> </Banner>
)} )}
{activeResponse && <ChainingHint response={activeResponse} mimeType={mimeType} />}
{/* Show tabs if we have any data (headers, body, etc.) even if there's an error */} {/* Show tabs if we have any data (headers, body, etc.) even if there's an error */}
<Tabs <Tabs
tabs={tabs} tabs={tabs}
+681 -25
View File
@@ -1,15 +1,38 @@
import {
type Folder,
type ImportDestination,
type ImportPlan,
type ImportPlanItem,
type ImportSource,
type Workspace,
} from "@yaakapp-internal/models";
import { Banner, HStack, Icon, type IconProps, InlineCode, VStack } from "@yaakapp-internal/ui";
import { platform } from "@yaakapp-internal/platform"; import { platform } from "@yaakapp-internal/platform";
import { Icon, VStack } from "@yaakapp-internal/ui";
import classNames from "classnames"; import classNames from "classnames";
import { useEffect, useRef, useState } from "react"; import { formatDistanceToNowStrict } from "date-fns";
import { useLocalStorage } from "react-use"; import { useEffect, useMemo, useRef, useState } from "react";
import { pluralize } from "../lib/pluralize";
import { CommercialUseBanner } from "./CommercialUseBanner"; import { CommercialUseBanner } from "./CommercialUseBanner";
import { Button } from "./core/Button"; import { Button } from "./core/Button";
import { Checkbox } from "./core/Checkbox";
import type { CheckboxTreeNode } from "./core/CheckboxTree";
import { CheckboxTree } from "./core/CheckboxTree";
import { IconTooltip } from "./core/IconTooltip";
import { PlainInput } from "./core/PlainInput"; import { PlainInput } from "./core/PlainInput";
import { Select } from "./core/Select";
import { SegmentedControl } from "./core/SegmentedControl";
interface Props { interface Props {
importFile: (filePath: string) => Promise<void>; currentWorkspace: Workspace | null;
importUrl: (url: string) => Promise<void>; workspaces: Workspace[];
selectedFolder: Folder | null;
planFile: (filePath: string, destination: ImportDestination) => Promise<ImportPlan>;
planUrl: (url: string, destination: ImportDestination) => Promise<ImportPlan>;
listSources: (workspaceId: string) => Promise<ImportSource[]>;
findSourcesForOrigin: (args: { filePath?: string; url?: string }) => Promise<ImportSource[]>;
commit: (plan: ImportPlan) => Promise<void>;
cancel: () => void;
onError: (err: unknown) => void;
} }
/** /**
@@ -31,10 +54,74 @@ function fileName(path: string): string {
return path.split(/[/\\]/).at(-1) || path; return path.split(/[/\\]/).at(-1) || path;
} }
export function ImportDataDialog({ importFile, importUrl }: Props) { /**
* Loads the current workspace's linked sources before rendering the dialog, so the inner
* component can construct its initial state (prefilled path, destination) in one pass instead of
* patching it in with effects after the first paint.
*/
export function ImportDataDialog(props: Props) {
const [initialSources, setInitialSources] = useState<ImportSource[] | null>(null);
const { currentWorkspace, listSources } = props;
useEffect(() => {
let cancelled = false;
const load = currentWorkspace == null ? Promise.resolve([]) : listSources(currentWorkspace.id);
load
.then((sources) => {
if (!cancelled) setInitialSources(sources);
})
.catch(() => {
if (!cancelled) setInitialSources([]);
});
return () => {
cancelled = true;
};
}, [currentWorkspace, listSources]);
if (initialSources == null) return null;
return <LoadedImportDataDialog {...props} initialSources={initialSources} />;
}
function latestSource(sources: ImportSource[]): ImportSource | null {
return sources.reduce<ImportSource | null>(
(latest, s) => (latest == null || s.lastImportedAt > latest.lastImportedAt ? s : latest),
null,
);
}
function LoadedImportDataDialog({
currentWorkspace,
workspaces,
selectedFolder,
planFile,
planUrl,
listSources,
findSourcesForOrigin,
commit,
cancel,
onError,
initialSources,
}: Props & { initialSources: ImportSource[] }) {
// A workspace with a linked source is probably being re-imported, so start from that source
const prefill = latestSource(initialSources);
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
const [plan, setPlan] = useState<ImportPlan | null>(null);
const [items, setItems] = useState<ImportPlanItem[]>([]);
// null means no explicit choice yet, so the default below applies
const [destinationChoice, setDestinationChoice] = useState<"new" | "current" | "other" | null>(
null,
);
const [otherWorkspaceId, setOtherWorkspaceId] = useState<string | null>(null);
const [targetSelectedFolder, setTargetSelectedFolder] = useState(selectedFolder != null);
const [linkedSources, setLinkedSources] = useState<ImportSource[]>(
prefill != null ? initialSources : [],
);
const [originSources, setOriginSources] = useState<ImportSource[]>(
prefill != null ? [prefill] : [],
);
// A file path or a URL. Both inputs write here, so there is only ever one thing to import // A file path or a URL. Both inputs write here, so there is only ever one thing to import
const [source, setSource] = useLocalStorage<string | null>("importPathOrUrl", null); const [source, setSource] = useState<string | null>(prefill?.origin ?? null);
const [forceUpdateKey, setForceUpdateKey] = useState<number>(0); const [forceUpdateKey, setForceUpdateKey] = useState<number>(0);
const [isHovering, setIsHovering] = useState<boolean>(false); const [isHovering, setIsHovering] = useState<boolean>(false);
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
@@ -65,25 +152,272 @@ export function ImportDataDialog({ importFile, importUrl }: Props) {
}); });
}, [isHovering, setSource]); }, [isHovering, setSource]);
useEffect(() => {
if (trimmedSource === "") {
setOriginSources([]);
return;
}
let cancelled = false;
const timeout = setTimeout(() => {
findSourcesForOrigin(filePath != null ? { filePath } : { url: trimmedSource })
.then((sources) => {
if (!cancelled) setOriginSources(sources);
})
.catch(() => setOriginSources([]));
}, 300);
return () => {
cancelled = true;
clearTimeout(timeout);
};
}, [trimmedSource, filePath, findSourcesForOrigin]);
// The one workspace this file is linked to, if there is exactly one.
const linkedWorkspace = useMemo(() => {
const ids = [...new Set(originSources.map((s) => s.workspaceId))];
if (ids.length !== 1) return null;
return workspaces.find((w) => w.id === ids[0]) ?? null;
}, [originSources, workspaces]);
// A file linked to the current workspace defaults back into it, so re-importing doesn't
// accidentally create a duplicate workspace. A file linked elsewhere only gets a suggestion —
// silently targeting a workspace that is neither new nor current is too surprising. An
// explicit choice always wins.
const destinationKind =
destinationChoice ??
(linkedWorkspace != null && linkedWorkspace.id === currentWorkspace?.id ? "current" : "new");
const destinationWorkspaceId =
destinationKind === "current"
? (currentWorkspace?.id ?? null)
: destinationKind === "other"
? otherWorkspaceId
: null;
useEffect(() => {
if (destinationWorkspaceId == null) {
setLinkedSources([]);
return;
}
let cancelled = false;
listSources(destinationWorkspaceId)
.then((sources) => {
if (!cancelled) setLinkedSources(sources);
})
.catch(() => setLinkedSources([]));
return () => {
cancelled = true;
};
}, [destinationWorkspaceId, listSources]);
const handleSelectFile = async () => { const handleSelectFile = async () => {
const selected = await platform.dialog.open({ title: "Select File", multiple: false }); const selected = await platform.dialog.open({ title: "Select File", multiple: false });
if (selected == null) return; if (selected == null) return;
selectSource(selected); selectSource(selected);
}; };
const handleImport = async () => { // The selected folder belongs to the workspace being viewed, so it is only offerable when that
// is also the destination.
const canTargetSelectedFolder = selectedFolder != null && destinationKind === "current";
const destination = (): ImportDestination => {
if (destinationWorkspaceId == null) {
return { type: "new_workspace" };
}
return {
type: "existing_workspace",
workspaceId: destinationWorkspaceId,
folderId: canTargetSelectedFolder && targetSelectedFolder ? selectedFolder.id : undefined,
};
};
const handlePreview = async () => {
setIsLoading(true); setIsLoading(true);
try { try {
if (filePath != null) { const nextPlan =
await importFile(filePath); filePath != null
} else { ? await planFile(filePath, destination())
await importUrl(trimmedSource); : await planUrl(trimmedSource, destination());
} setPlan(nextPlan);
setItems(nextPlan.items);
} catch (err) {
onError(err);
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }
}; };
const handleCommit = async () => {
if (plan == null) return;
setIsLoading(true);
try {
await commit({ ...plan, items });
} catch (err) {
onError(err);
} finally {
setIsLoading(false);
}
};
const itemTree = useMemo(() => buildItemTree(items), [items]);
// A folder row's checkbox carries everything beneath it, deletions included — the row labels
// say which of those are destructive. Checking anything also brings back the folders it needs
// to live in.
const toggleNode = (node: CheckboxTreeNode<TreeRow>, checked: boolean) => {
const targets = new Set(togglableItems(node).map((i) => i.modelId));
if (checked && node.data.kind === "item") {
const byId = new Map(items.map((i) => [i.modelId, i]));
for (const ancestor of ancestorsOf(node.data.item, byId)) {
if (isMissingFolder(ancestor)) targets.add(ancestor.modelId);
}
}
setItems((prev) => prev.map((i) => (targets.has(i.modelId) ? { ...i, selected: checked } : i)));
};
const resolveConflict = (modelId: string, resolution: "keep_mine" | "take_source") => {
setItems((prev) =>
prev.map((item) => (item.modelId === modelId ? { ...item, resolution } : item)),
);
};
// Deleting a folder takes its contents with it, so those rows have nothing left to decide.
const disabledIds = useMemo(() => {
const disabled = new Set<string>();
const byId = new Map(items.map((i) => [i.modelId, i]));
for (const item of items) {
if (item.action !== "delete") continue;
for (const parent of ancestorsOf(item, byId)) {
if (parent.action === "delete" && parent.selected) {
disabled.add(item.modelId);
}
}
}
return disabled;
}, [items]);
if (plan != null) {
const unchanged = items.filter((i) => i.action === "unchanged");
const footerNote =
unchanged.length > 0
? `${unchanged.length} ${pluralize("resource", unchanged.length)} unchanged`
: "";
const changeCount = items.filter((item) => {
if (disabledIds.has(item.modelId)) return false;
if (item.action === "conflict") return item.resolution === "take_source";
if (item.action === "unchanged") return false;
return item.selected;
}).length;
// The row's label carries what kind of destination it is, so the value can just be its name
const [destinationLabel, destinationValue] = ((): [string, string] => {
if (plan.destination.type === "new_workspace") {
const names = plan.resources.workspaces.map((w) => w.name).filter((n) => n !== "");
if (names.length === 0) return ["New workspace", "Untitled"];
return [pluralize("New workspace", names.length), names.join(", ")];
}
const { workspaceId, folderId } = plan.destination;
const name = workspaces.find((w) => w.id === workspaceId)?.name ?? "Unknown workspace";
return [
"Destination",
folderId != null && folderId === selectedFolder?.id
? `${name} / ${selectedFolder.name}`
: name,
];
})();
// The destination workspace roots the tree. It is not a plan item — commit always applies
// it — so its checkbox only aggregates the subtree.
const workspaceRoot: CheckboxTreeNode<TreeRow> = (() => {
const planned = plan.resources.workspaces[0];
const planDestination = plan.destination;
const existing =
planDestination.type === "existing_workspace"
? workspaces.find((w) => w.id === planDestination.workspaceId)
: null;
return {
key: existing?.id ?? planned?.id ?? "workspace",
data: {
kind: "destination",
label: existing?.name ?? planned?.name ?? "New workspace",
isNew: planDestination.type === "new_workspace",
},
children: itemTree,
};
})();
return (
<VStack space={4} className="pb-4">
<div className="rounded-lg border border-border-subtle divide-y divide-border-subtle">
<PreviewRow label="Detected format" value={plan.importer} />
<PreviewRow label={destinationLabel} value={destinationValue} />
</div>
{plan.warnings.map((warning) => (
<Banner
key={`${warning.title}:${warning.detail}`}
color={warning.level === "warning" ? "warning" : "info"}
className="flex items-start gap-2.5"
>
<Icon
icon={warning.level === "warning" ? "alert_triangle" : "info"}
size="sm"
className="mt-0.5"
/>
<div className="min-w-0">
<div className="text-sm font-medium">{warning.title}</div>
<div className="text-xs text-text-subtle mt-0.5">{warning.detail}</div>
</div>
</Banner>
))}
<div className="rounded-lg border border-border-subtle px-3 py-2 overflow-y-auto max-h-[40vh]">
<CheckboxTree
node={workspaceRoot}
checked={nodeCheckedStatus}
onCheck={toggleNode}
isCheckboxDisabled={(n) => disabledIds.has(n.key)}
isCollapsedByDefault={(n) => n.data.kind === "item" && n.data.item.action === "ignored"}
isRelevant={(n) =>
n.data.kind === "destination" ||
(n.data.kind === "item" && n.data.item.action !== "unchanged")
}
renderRow={(n) => <ImportTreeRow row={n.data} onResolveConflict={resolveConflict} />}
/>
</div>
<HStack space={2} alignItems="center" className="mt-3">
{footerNote !== "" && <div className="text-xs text-text-subtle">{footerNote}</div>}
<Button
className="ml-auto"
color="secondary"
variant="border"
disabled={isLoading}
onClick={() => {
setPlan(null);
setItems([]);
}}
>
Back
</Button>
<Button color="primary" isLoading={isLoading} onClick={handleCommit}>
{isLoading
? "Importing"
: changeCount > 0
? `Apply ${changeCount} ${changeCount === 1 ? "Change" : "Changes"}`
: "Done"}
</Button>
</HStack>
</VStack>
);
}
const lastImported =
originSources.find((s) => s.workspaceId === destinationWorkspaceId) ??
linkedSources.reduce<ImportSource | null>(
(latest, s) => (latest == null || s.lastImportedAt > latest.lastImportedAt ? s : latest),
null,
);
return ( return (
<VStack ref={ref} space={4} className="pb-4"> <VStack ref={ref} space={4} className="pb-4">
<CommercialUseBanner source="data-import" title="Importing work data?" /> <CommercialUseBanner source="data-import" title="Importing work data?" />
@@ -94,7 +428,9 @@ export function ImportDataDialog({ importFile, importUrl }: Props) {
className={classNames( className={classNames(
"w-full rounded-lg border border-dashed px-4 py-6", "w-full rounded-lg border border-dashed px-4 py-6",
"flex flex-col items-center gap-1 text-center", "flex flex-col items-center gap-1 text-center",
isHovering ? "border-notice bg-surface-highlight" : "border-border hover:border-text", isHovering
? "border-notice bg-surface-highlight"
: "border-border hover:border-text-subtle",
)} )}
> >
<Icon icon="folder_input" className="text-text-subtlest w-8! h-8! mb-2" /> <Icon icon="folder_input" className="text-text-subtlest w-8! h-8! mb-2" />
@@ -115,25 +451,345 @@ export function ImportDataDialog({ importFile, importUrl }: Props) {
</div> </div>
</button> </button>
<PlainInput
label="Or enter a file path or URL"
size="sm"
placeholder="https://example.com/openapi.json"
defaultValue={source ?? ""}
forceUpdateKey={String(forceUpdateKey)}
onChange={setSource}
/>
<VStack space={2}> <VStack space={2}>
<PlainInput <Select
label="Or enter a file path or URL" name="import-destination-kind"
label="Import location"
size="sm" size="sm"
placeholder="https://example.com/openapi.json" value={destinationKind}
defaultValue={source ?? ""} onChange={setDestinationChoice}
forceUpdateKey={String(forceUpdateKey)} options={[
onChange={setSource} { value: "new", label: "New Workspace" },
...(currentWorkspace != null
? [{ value: "current" as const, label: "Current Workspace" }]
: []),
{ value: "other", label: "Other Workspace" },
]}
/> />
{destinationKind === "other" && (
<Select
name="import-destination-workspace"
label="Workspace"
hideLabel
size="sm"
value={otherWorkspaceId ?? ""}
onChange={(id) => setOtherWorkspaceId(id === "" ? null : id)}
filterable
options={[
{ value: "", label: "Select a workspace" },
...workspaces
.filter((w) => w.id !== currentWorkspace?.id)
.map((w) => ({ value: w.id, label: w.name })),
]}
/>
)}
{lastImported != null && destinationWorkspaceId != null ? (
<div className="text-xs text-text-subtle">
Last imported from {lastImported.originLabel} ·{" "}
{formatDistanceToNowStrict(`${lastImported.lastImportedAt}Z`, { addSuffix: true })}
</div>
) : linkedWorkspace != null && linkedWorkspace.id !== destinationWorkspaceId ? (
<div className="text-xs text-text-subtle">
This file was last imported into{" "}
<button
type="button"
className="underline hocus:text-text"
onClick={() => {
if (linkedWorkspace.id === currentWorkspace?.id) {
setDestinationChoice("current");
} else {
setDestinationChoice("other");
setOtherWorkspaceId(linkedWorkspace.id);
}
}}
>
{linkedWorkspace.name}
</button>
</div>
) : null}
{canTargetSelectedFolder && (
<Checkbox
checked={targetSelectedFolder}
title={`Place root resources in selected folder “${selectedFolder.name}”`}
onChange={setTargetSelectedFolder}
/>
)}
</VStack>
<HStack space={2} justifyContent="end">
<Button color="secondary" variant="border" disabled={isLoading} onClick={cancel}>
Cancel
</Button>
<Button <Button
color="primary" color="primary"
disabled={trimmedSource === "" || isLoading} disabled={
trimmedSource === "" ||
isLoading ||
(destinationKind === "other" && otherWorkspaceId == null)
}
isLoading={isLoading} isLoading={isLoading}
size="sm" onClick={handlePreview}
onClick={handleImport}
> >
{isLoading ? "Importing" : "Import"} {isLoading ? "Analyzing" : "Preview Import"}
</Button> </Button>
</VStack> </HStack>
</VStack> </VStack>
); );
} }
function ImportTreeRow({
row,
onResolveConflict,
}: {
row: TreeRow;
onResolveConflict: (modelId: string, resolution: "keep_mine" | "take_source") => void;
}) {
if (row.kind !== "item") {
return (
<>
<Icon color="secondary" icon={row.kind === "destination" ? "house" : row.icon} />
<div className="truncate flex-1">{row.label}</div>
{row.kind === "destination" && row.isNew && (
<ActionChip label="new" help="Created by this import" className="text-success" />
)}
</>
);
}
const { item } = row;
const label = actionLabel(item);
return (
<>
{item.model === "folder" || item.model === "environment" ? (
<Icon color="secondary" icon={item.model === "folder" ? "folder" : "variable"} />
) : (
<span aria-hidden className="w-4" />
)}
<div className="truncate flex-1">{item.name}</div>
{item.action === "conflict" ? (
<div className="shrink-0">
<SegmentedControl
name={`conflict-${item.modelId}`}
label={`Resolve conflict for ${item.name}`}
hideLabel
size="2xs"
help={actionHelp(item)}
value={item.resolution ?? "keep_mine"}
onChange={(v) => onResolveConflict(item.modelId, v)}
options={[
{ value: "keep_mine", label: "Keep mine" },
{ value: "take_source", label: "Take source" },
]}
/>
</div>
) : (
label != null && (
<ActionChip
label={label}
help={actionHelp(item)}
className={classNames(
item.action === "create" && "text-success",
item.action === "update" && "text-info",
item.action === "delete" && "text-danger",
item.action === "keep_local" && item.selected && "text-warning",
item.action === "ignored" && "text-text-subtlest",
)}
/>
)
)}
</>
);
}
function ActionChip({
label,
help,
className,
}: {
label: string;
help: string | null;
className?: string;
}) {
return (
<InlineCode
className={classNames(
"py-0 bg-transparent w-32 shrink-0 whitespace-nowrap text-xs",
"inline-flex items-center justify-center gap-1.5",
className,
)}
>
{label}
{help != null && <IconTooltip content={help} iconSize="xs" />}
</InlineCode>
);
}
function actionLabel(item: ImportPlanItem): string | null {
switch (item.action) {
case "create":
return "new";
case "update":
return "updated";
case "delete":
return "removed";
case "keep_local":
return "edited";
case "ignored":
return "ignored";
default:
return null;
}
}
function actionHelp(item: ImportPlanItem): string | null {
const help = (text: string) =>
item.changedFields.length > 0
? `${text} · ${item.changedFields.map(fieldLabel).join(", ")}`
: text;
switch (item.action) {
case "create":
return "Not in this workspace yet";
case "update":
return item.reason === "moved_into_ignored_folder"
? "Moved into a folder that isn't imported. Importing that folder brings it along"
: help("Changed in the source since the last import");
case "delete":
return "Gone from the source since the last import. Checking it deletes it here";
case "keep_local":
return help("Changed here since the last import. Checking it reverts to the source");
case "conflict":
return help("Changed here and in the source since the last import");
case "ignored":
return "Not in this workspace. Imports leave it alone until you check it";
default:
return null;
}
}
function fieldLabel(field: string): string {
return field.replace(/([A-Z])/g, " $1").toLowerCase();
}
/** Every plan item above `item`, nearest first. */
function ancestorsOf(item: ImportPlanItem, byId: Map<string, ImportPlanItem>): ImportPlanItem[] {
const ancestors: ImportPlanItem[] = [];
const seen = new Set<string>();
let parentId = item.parentId;
while (parentId != null && !seen.has(parentId)) {
seen.add(parentId);
const parent = byId.get(parentId);
if (parent == null) break;
ancestors.push(parent);
parentId = parent.parentId;
}
return ancestors;
}
/**
* A row of the preview tree. Most are plan items, but the destination workspace and the group the
* workspace's environments sit in are headings: they aggregate their children and decide nothing
* themselves.
*/
type TreeRow =
| { kind: "destination"; label: string; isNew: boolean }
| { kind: "group"; label: string; icon: IconProps["icon"] }
| { kind: "item"; item: ImportPlanItem };
function buildItemTree(items: ImportPlanItem[]): CheckboxTreeNode<TreeRow>[] {
const byId = new Map(items.map((i) => [i.modelId, i]));
const childrenOf = new Map<string, ImportPlanItem[]>();
const roots: ImportPlanItem[] = [];
for (const item of items) {
if (item.parentId != null && byId.has(item.parentId)) {
const siblings = childrenOf.get(item.parentId) ?? [];
siblings.push(item);
childrenOf.set(item.parentId, siblings);
} else {
roots.push(item);
}
}
const byKind = (list: ImportPlanItem[]) => [
...list.filter((i) => i.model === "environment"),
...list.filter((i) => i.model === "folder"),
...list.filter((i) => i.model !== "environment" && i.model !== "folder"),
];
const toNode = (item: ImportPlanItem, seen: Set<string>): CheckboxTreeNode<TreeRow> => ({
key: item.modelId,
data: { kind: "item", item },
children: seen.has(item.modelId)
? []
: byKind(childrenOf.get(item.modelId) ?? []).map((c) =>
toNode(c, new Set([...seen, item.modelId])),
),
});
// The workspace's environments have nothing to sit under — a sub-environment is a sibling of
// the base one, not its child — so a heading groups them into one thing to turn on and off.
const environments = roots.filter((i) => i.model === "environment");
const others = byKind(roots.filter((i) => i.model !== "environment"));
const nodes = others.map((r) => toNode(r, new Set()));
if (environments.length === 0) return nodes;
return [
{
key: "group:environments",
data: { kind: "group", label: "Variables", icon: "variable" },
children: environments.map((e) => toNode(e, new Set())),
},
...nodes,
];
}
function collectRows(node: CheckboxTreeNode<TreeRow>): TreeRow[] {
return [node.data, ...node.children.flatMap(collectRows)];
}
/** A folder that isn't there yet, so anything inside it needs it brought in first. */
function isMissingFolder(item: ImportPlanItem): boolean {
return item.model === "folder" && (item.action === "create" || item.action === "ignored");
}
/**
* The plan item a row's checkbox decides, if it decides one. An unchanged resource has nothing to
* decide and a conflict is decided by its own control, so neither takes a checkbox — nor rides
* along with a parent's.
*/
function togglableItem(row: TreeRow): ImportPlanItem | null {
if (row.kind !== "item") return null;
const { item } = row;
return item.action === "unchanged" || item.action === "conflict" ? null : item;
}
function togglableItems(node: CheckboxTreeNode<TreeRow>): ImportPlanItem[] {
return collectRows(node)
.map(togglableItem)
.filter((i) => i != null);
}
function nodeCheckedStatus(node: CheckboxTreeNode<TreeRow>): boolean | "indeterminate" | "hidden" {
const covered = togglableItems(node);
if (covered.length === 0) return "hidden";
const selected = covered.filter((i) => i.selected).length;
if (selected === covered.length) return true;
if (selected === 0) return false;
return "indeterminate";
}
function PreviewRow({ label, value }: { label: string; value: string }) {
return (
<div className="flex items-start justify-between gap-4 px-3 py-2 text-sm">
<span className="text-text-subtle">{label}</span>
<span className="text-right font-medium">{value}</span>
</div>
);
}
@@ -2,7 +2,9 @@ import type {
Folder, Folder,
GrpcRequest, GrpcRequest,
HttpRequest, HttpRequest,
HttpVersion,
InheritedBoolSetting, InheritedBoolSetting,
InheritedHttpVersionSetting,
InheritedIntSetting, InheritedIntSetting,
WebsocketRequest, WebsocketRequest,
Workspace, Workspace,
@@ -13,6 +15,7 @@ import {
modelSupportsSetting, modelSupportsSetting,
type RequestSettingDefinition, type RequestSettingDefinition,
SETTING_FOLLOW_REDIRECTS, SETTING_FOLLOW_REDIRECTS,
SETTING_HTTP_VERSION,
SETTING_REQUEST_MESSAGE_SIZE, SETTING_REQUEST_MESSAGE_SIZE,
SETTING_REQUEST_TIMEOUT, SETTING_REQUEST_TIMEOUT,
SETTING_SEND_COOKIES, SETTING_SEND_COOKIES,
@@ -21,6 +24,7 @@ import {
} from "../lib/requestSettings"; } from "../lib/requestSettings";
import { Checkbox } from "./core/Checkbox"; import { Checkbox } from "./core/Checkbox";
import { PlainInput } from "./core/PlainInput"; import { PlainInput } from "./core/PlainInput";
import { Select } from "./core/Select";
import { import {
SettingOverrideRow, SettingOverrideRow,
SettingRow, SettingRow,
@@ -38,37 +42,21 @@ interface Props {
model: ModelWithSettings; model: ModelWithSettings;
} }
type ModelWithSettings = type ModelWithSettings = Workspace | Folder | HttpRequest | WebsocketRequest | GrpcRequest;
| Workspace
| Folder
| HttpRequest
| WebsocketRequest
| GrpcRequest;
type ModelWithHttpSettings = Workspace | Folder | HttpRequest; type ModelWithHttpSettings = Workspace | Folder | HttpRequest;
type ModelWithTlsSettings = type ModelWithTlsSettings = Workspace | Folder | HttpRequest | WebsocketRequest | GrpcRequest;
| Workspace type ModelWithCookieSettings = Workspace | Folder | HttpRequest | WebsocketRequest;
| Folder type ModelWithMessageSizeSettings = Workspace | Folder | WebsocketRequest | GrpcRequest;
| HttpRequest
| WebsocketRequest
| GrpcRequest;
type ModelWithCookieSettings =
| Workspace
| Folder
| HttpRequest
| WebsocketRequest;
type ModelWithMessageSizeSettings =
| Workspace
| Folder
| WebsocketRequest
| GrpcRequest;
type BooleanSetting = boolean | InheritedBoolSetting; type BooleanSetting = boolean | InheritedBoolSetting;
type IntegerSetting = number | InheritedIntSetting; type IntegerSetting = number | InheritedIntSetting;
type HttpVersionSetting = HttpVersion | InheritedHttpVersionSetting;
type CookieSettingsPatch = { type CookieSettingsPatch = {
settingSendCookies?: ModelWithCookieSettings["settingSendCookies"]; settingSendCookies?: ModelWithCookieSettings["settingSendCookies"];
settingStoreCookies?: ModelWithCookieSettings["settingStoreCookies"]; settingStoreCookies?: ModelWithCookieSettings["settingStoreCookies"];
}; };
type HttpSettingsPatch = { type HttpSettingsPatch = {
settingFollowRedirects?: ModelWithHttpSettings["settingFollowRedirects"]; settingFollowRedirects?: ModelWithHttpSettings["settingFollowRedirects"];
settingHttpVersion?: ModelWithHttpSettings["settingHttpVersion"];
settingRequestTimeout?: ModelWithHttpSettings["settingRequestTimeout"]; settingRequestTimeout?: ModelWithHttpSettings["settingRequestTimeout"];
}; };
type TlsSettingsPatch = { type TlsSettingsPatch = {
@@ -78,10 +66,7 @@ type MessageSizeSettingsPatch = {
settingRequestMessageSize?: ModelWithMessageSizeSettings["settingRequestMessageSize"]; settingRequestMessageSize?: ModelWithMessageSizeSettings["settingRequestMessageSize"];
}; };
export function ModelSettingsEditor({ export function ModelSettingsEditor({ model, showSectionTitles = false }: Props) {
model,
showSectionTitles = false,
}: Props) {
const ancestors = useModelAncestors(model); const ancestors = useModelAncestors(model);
const supportsHttpSettings = modelSupportsHttpSettings(model); const supportsHttpSettings = modelSupportsHttpSettings(model);
const supportsCookieSettings = modelSupportsCookieSettings(model); const supportsCookieSettings = modelSupportsCookieSettings(model);
@@ -154,12 +139,26 @@ export function ModelSettingsEditor({
} }
/> />
)} )}
{supportsHttpSettings && (
<HttpVersionSettingRow
settingDefinition={SETTING_HTTP_VERSION}
setting={model.settingHttpVersion}
inheritedValue={resolveInheritedValue(
ancestors,
SETTING_HTTP_VERSION.modelKey,
model.settingHttpVersion,
)}
onChange={(settingHttpVersion) =>
patchHttpSettings(model, {
settingHttpVersion,
})
}
/>
)}
</SettingsSection> </SettingsSection>
)} )}
{supportsCookieSettings && ( {supportsCookieSettings && (
<SettingsSection <SettingsSection title={supportsTlsSettings || showSectionTitles ? "Cookies" : null}>
title={supportsTlsSettings || showSectionTitles ? "Cookies" : null}
>
<BooleanSettingRow <BooleanSettingRow
settingDefinition={SETTING_SEND_COOKIES} settingDefinition={SETTING_SEND_COOKIES}
setting={model.settingSendCookies} setting={model.settingSendCookies}
@@ -195,7 +194,7 @@ export function ModelSettingsEditor({
} }
export function countOverriddenSettings(model: ModelWithSettings) { export function countOverriddenSettings(model: ModelWithSettings) {
const settings: (BooleanSetting | IntegerSetting)[] = []; const settings: (BooleanSetting | IntegerSetting | HttpVersionSetting)[] = [];
if (modelSupportsCookieSettings(model)) { if (modelSupportsCookieSettings(model)) {
settings.push(model.settingSendCookies, model.settingStoreCookies); settings.push(model.settingSendCookies, model.settingStoreCookies);
@@ -204,22 +203,22 @@ export function countOverriddenSettings(model: ModelWithSettings) {
settings.push(model.settingValidateCertificates); settings.push(model.settingValidateCertificates);
if (modelSupportsHttpSettings(model)) { if (modelSupportsHttpSettings(model)) {
settings.push(model.settingFollowRedirects, model.settingRequestTimeout); settings.push(
model.settingFollowRedirects,
model.settingRequestTimeout,
model.settingHttpVersion,
);
} }
if (modelSupportsMessageSizeSettings(model)) { if (modelSupportsMessageSizeSettings(model)) {
settings.push(model.settingRequestMessageSize); settings.push(model.settingRequestMessageSize);
} }
return settings.filter( return settings.filter((setting) => isInheritedSetting(setting) && setting.enabled === true)
(setting) => isInheritedSetting(setting) && setting.enabled === true, .length;
).length;
} }
function patchCookieSettings( function patchCookieSettings(model: ModelWithCookieSettings, patch: Partial<CookieSettingsPatch>) {
model: ModelWithCookieSettings,
patch: Partial<CookieSettingsPatch>,
) {
switch (model.model) { switch (model.model) {
case "workspace": case "workspace":
return patchModel(model, patch as Partial<Workspace>); return patchModel(model, patch as Partial<Workspace>);
@@ -232,10 +231,7 @@ function patchCookieSettings(
} }
} }
function patchHttpSettings( function patchHttpSettings(model: ModelWithHttpSettings, patch: Partial<HttpSettingsPatch>) {
model: ModelWithHttpSettings,
patch: Partial<HttpSettingsPatch>,
) {
switch (model.model) { switch (model.model) {
case "workspace": case "workspace":
return patchModel(model, patch as Partial<Workspace>); return patchModel(model, patch as Partial<Workspace>);
@@ -246,10 +242,7 @@ function patchHttpSettings(
} }
} }
function patchTlsSettings( function patchTlsSettings(model: ModelWithTlsSettings, patch: Partial<TlsSettingsPatch>) {
model: ModelWithTlsSettings,
patch: Partial<TlsSettingsPatch>,
) {
switch (model.model) { switch (model.model) {
case "workspace": case "workspace":
return patchModel(model, patch as Partial<Workspace>); return patchModel(model, patch as Partial<Workspace>);
@@ -280,21 +273,15 @@ function patchMessageSizeSettings(
} }
} }
function modelSupportsHttpSettings( function modelSupportsHttpSettings(model: ModelWithSettings): model is ModelWithHttpSettings {
model: ModelWithSettings,
): model is ModelWithHttpSettings {
return modelSupportsSetting(model, SETTING_REQUEST_TIMEOUT); return modelSupportsSetting(model, SETTING_REQUEST_TIMEOUT);
} }
function modelSupportsCookieSettings( function modelSupportsCookieSettings(model: ModelWithSettings): model is ModelWithCookieSettings {
model: ModelWithSettings,
): model is ModelWithCookieSettings {
return modelSupportsSetting(model, SETTING_SEND_COOKIES); return modelSupportsSetting(model, SETTING_SEND_COOKIES);
} }
function modelSupportsTlsSettings( function modelSupportsTlsSettings(model: ModelWithSettings): model is ModelWithTlsSettings {
model: ModelWithSettings,
): model is ModelWithTlsSettings {
return modelSupportsSetting(model, SETTING_VALIDATE_CERTIFICATES); return modelSupportsSetting(model, SETTING_VALIDATE_CERTIFICATES);
} }
@@ -317,11 +304,7 @@ function BooleanSettingRow({
}) { }) {
const inherited = isInheritedSetting(setting); const inherited = isInheritedSetting(setting);
const overridden = inherited ? setting.enabled === true : false; const overridden = inherited ? setting.enabled === true : false;
const value = inherited const value = inherited ? (overridden ? setting.value : inheritedValue) : setting;
? overridden
? setting.value
: inheritedValue
: setting;
if (!inherited) { if (!inherited) {
return ( return (
@@ -352,6 +335,63 @@ function BooleanSettingRow({
); );
} }
const HTTP_VERSION_OPTIONS: { label: string; value: HttpVersion }[] = [
{ label: "Automatic", value: "auto" },
{ label: "HTTP/1.1", value: "http1" },
{ label: "HTTP/2", value: "http2" },
];
function HttpVersionSettingRow({
inheritedValue,
setting,
settingDefinition,
onChange,
}: {
inheritedValue: HttpVersion;
setting: HttpVersionSetting;
settingDefinition: RequestSettingDefinition<"settingHttpVersion">;
onChange: (setting: HttpVersionSetting) => void;
}) {
const inherited = isInheritedSetting(setting);
const overridden = inherited ? setting.enabled === true : false;
const value = inherited ? (overridden ? setting.value : inheritedValue) : setting;
if (!inherited) {
return (
<SettingRow title={settingDefinition.title} description={settingDefinition.description}>
<Select
hideLabel
name={settingDefinition.modelKey}
label={settingDefinition.title}
size="sm"
value={value}
options={HTTP_VERSION_OPTIONS}
onChange={(value) => onChange(value)}
/>
</SettingRow>
);
}
return (
<SettingOverrideRow
title={settingDefinition.title}
description={settingDefinition.description}
overridden={overridden}
onResetOverride={() => onChange({ ...setting, enabled: false })}
>
<Select
hideLabel
name={settingDefinition.modelKey}
label={settingDefinition.title}
size="sm"
value={value}
options={HTTP_VERSION_OPTIONS}
onChange={(value) => onChange({ ...setting, enabled: true, value })}
/>
</SettingOverrideRow>
);
}
function IntegerSettingRow({ function IntegerSettingRow({
inheritedValue, inheritedValue,
setting, setting,
@@ -365,18 +405,11 @@ function IntegerSettingRow({
}) { }) {
const inherited = isInheritedSetting(setting); const inherited = isInheritedSetting(setting);
const overridden = inherited ? setting.enabled === true : false; const overridden = inherited ? setting.enabled === true : false;
const value = inherited const value = inherited ? (overridden ? setting.value : inheritedValue) : setting;
? overridden
? setting.value
: inheritedValue
: setting;
if (!inherited) { if (!inherited) {
return ( return (
<SettingRow <SettingRow title={settingDefinition.title} description={settingDefinition.description}>
title={settingDefinition.title}
description={settingDefinition.description}
>
<NumberUnitInput <NumberUnitInput
name={settingDefinition.modelKey} name={settingDefinition.modelKey}
label={settingDefinition.title} label={settingDefinition.title}
@@ -429,20 +462,13 @@ function MessageSizeSettingRow({
}) { }) {
const inherited = isInheritedSetting(setting); const inherited = isInheritedSetting(setting);
const overridden = inherited ? setting.enabled === true : false; const overridden = inherited ? setting.enabled === true : false;
const value = inherited const value = inherited ? (overridden ? setting.value : inheritedValue) : setting;
? overridden
? setting.value
: inheritedValue
: setting;
const displayValue = formatMegabytes(value); const displayValue = formatMegabytes(value);
const placeholder = "0"; const placeholder = "0";
if (!inherited) { if (!inherited) {
return ( return (
<SettingRow <SettingRow title={settingDefinition.title} description={settingDefinition.description}>
title={settingDefinition.title}
description={settingDefinition.description}
>
<MessageSizeInput <MessageSizeInput
name={settingDefinition.modelKey} name={settingDefinition.modelKey}
label={settingDefinition.title} label={settingDefinition.title}
@@ -567,13 +593,18 @@ function resolveInheritedValue(
key: BooleanWorkspaceSettingKey, key: BooleanWorkspaceSettingKey,
fallback: BooleanSetting, fallback: BooleanSetting,
): boolean; ): boolean;
function resolveInheritedValue(
ancestors: (Folder | Workspace)[],
key: "settingHttpVersion",
fallback: HttpVersionSetting,
): HttpVersion;
function resolveInheritedValue( function resolveInheritedValue(
ancestors: (Folder | Workspace)[], ancestors: (Folder | Workspace)[],
key: keyof WorkspaceSettings, key: keyof WorkspaceSettings,
fallback: BooleanSetting | IntegerSetting, fallback: BooleanSetting | IntegerSetting | HttpVersionSetting,
) { ) {
for (const ancestor of ancestors) { for (const ancestor of ancestors) {
const setting = ancestor[key] as BooleanSetting | IntegerSetting; const setting = ancestor[key] as BooleanSetting | IntegerSetting | HttpVersionSetting;
if (isInheritedSetting(setting)) { if (isInheritedSetting(setting)) {
if (setting.enabled === true) { if (setting.enabled === true) {
return setting.value; return setting.value;
@@ -589,6 +620,7 @@ function resolveInheritedValue(
type WorkspaceSettings = Pick< type WorkspaceSettings = Pick<
Workspace, Workspace,
| "settingFollowRedirects" | "settingFollowRedirects"
| "settingHttpVersion"
| "settingRequestMessageSize" | "settingRequestMessageSize"
| "settingRequestTimeout" | "settingRequestTimeout"
| "settingSendCookies" | "settingSendCookies"
@@ -598,14 +630,12 @@ type WorkspaceSettings = Pick<
type BooleanWorkspaceSettingKey = Exclude< type BooleanWorkspaceSettingKey = Exclude<
keyof WorkspaceSettings, keyof WorkspaceSettings,
"settingRequestTimeout" | "settingRequestMessageSize" "settingRequestTimeout" | "settingRequestMessageSize" | "settingHttpVersion"
>; >;
function formatMegabytes(bytes: number) { function formatMegabytes(bytes: number) {
const megabytes = bytes / BYTES_PER_MB; const megabytes = bytes / BYTES_PER_MB;
return Number.isInteger(megabytes) return Number.isInteger(megabytes) ? `${megabytes}` : megabytes.toFixed(3).replace(/\.?0+$/, "");
? `${megabytes}`
: megabytes.toFixed(3).replace(/\.?0+$/, "");
} }
function parseMegabytes(value: string) { function parseMegabytes(value: string) {
@@ -626,9 +656,5 @@ function isValidInteger(value: string) {
function isValidMegabytes(value: string) { function isValidMegabytes(value: string) {
if (value === "") return true; if (value === "") return true;
const megabytes = Number(value); const megabytes = Number(value);
return ( return Number.isFinite(megabytes) && megabytes >= 0 && megabytes <= MAX_MESSAGE_SIZE_MB;
Number.isFinite(megabytes) &&
megabytes >= 0 &&
megabytes <= MAX_MESSAGE_SIZE_MB
);
} }
@@ -59,6 +59,7 @@ export function SyncToFilesystemSetting({
)} )}
<SettingRowDirectory <SettingRowDirectory
highlightKey="sync_dir"
title="Local directory sync" title="Local directory sync"
description="Sync data to a folder for backup and Git integration." description="Sync data to a folder for backup and Git integration."
filePath={value.filePath} filePath={value.filePath}
@@ -110,6 +110,8 @@ export function WebsocketRequestPane({ style, fullHeight, className, activeReque
[activeRequest.url, activeRequest.urlParameters, handleRenamePathPlaceholder], [activeRequest.url, activeRequest.urlParameters, handleRenamePathPlaceholder],
); );
const hasDescription = activeRequest.description.trim().length > 0;
const tabs = useMemo<TabItem[]>(() => { const tabs = useMemo<TabItem[]>(() => {
return [ return [
{ {
@@ -131,9 +133,10 @@ export function WebsocketRequestPane({ style, fullHeight, className, activeReque
{ {
value: TAB_DESCRIPTION, value: TAB_DESCRIPTION,
label: "Info", label: "Info",
rightSlot: hasDescription && <CountBadge count={true} />,
}, },
]; ];
}, [authTab, headersTab, numSettingsOverrides, urlParameterPairs.length]); }, [authTab, hasDescription, headersTab, numSettingsOverrides, urlParameterPairs.length]);
const { activeResponse } = usePinnedHttpResponse(activeRequestId); const { activeResponse } = usePinnedHttpResponse(activeRequestId);
const { mutate: cancelResponse } = useCancelHttpResponse(activeResponse?.id ?? null); const { mutate: cancelResponse } = useCancelHttpResponse(activeResponse?.id ?? null);
@@ -25,8 +25,12 @@ interface Props {
workspaceId: string; workspaceId: string;
hide: () => void; hide: () => void;
tab?: WorkspaceSettingsTab; tab?: WorkspaceSettingsTab;
highlight?: WorkspaceSettingsHighlight;
} }
/** Settings rows that can be pointed out when the dialog opens */
export type WorkspaceSettingsHighlight = "sync_dir";
const TAB_AUTH = "auth"; const TAB_AUTH = "auth";
const TAB_DNS = "dns"; const TAB_DNS = "dns";
const TAB_HEADERS = "headers"; const TAB_HEADERS = "headers";
@@ -42,7 +46,7 @@ export type WorkspaceSettingsTab =
const DEFAULT_TAB: WorkspaceSettingsTab = TAB_GENERAL; const DEFAULT_TAB: WorkspaceSettingsTab = TAB_GENERAL;
export function WorkspaceSettingsDialog({ workspaceId, hide, tab }: Props) { export function WorkspaceSettingsDialog({ workspaceId, hide, tab, highlight }: Props) {
const workspace = useAtomValue(workspacesAtom).find((w) => w.id === workspaceId); const workspace = useAtomValue(workspacesAtom).find((w) => w.id === workspaceId);
const workspaceMeta = useAtomValue(workspaceMetasAtom).find((m) => m.workspaceId === workspaceId); const workspaceMeta = useAtomValue(workspaceMetasAtom).find((m) => m.workspaceId === workspaceId);
const authTab = useAuthTab(TAB_AUTH, workspace ?? null); const authTab = useAuthTab(TAB_AUTH, workspace ?? null);
@@ -104,7 +108,7 @@ export function WorkspaceSettingsDialog({ workspaceId, hide, tab }: Props) {
/> />
</TabContent> </TabContent>
<TabContent value={TAB_SETTINGS} className="overflow-y-auto h-full px-4"> <TabContent value={TAB_SETTINGS} className="overflow-y-auto h-full px-4">
<SettingsList className="space-y-8 pb-3"> <SettingsList className="space-y-8 pb-3" highlight={highlight}>
<SettingsSection title={null}> <SettingsSection title={null}>
<SyncToFilesystemSetting <SyncToFilesystemSetting
layout="settings" layout="settings"
@@ -178,14 +182,23 @@ export function WorkspaceSettingsDialog({ workspaceId, hide, tab }: Props) {
); );
} }
WorkspaceSettingsDialog.show = (workspaceId: string, tab?: WorkspaceSettingsTab) => { WorkspaceSettingsDialog.show = (
workspaceId: string,
tab?: WorkspaceSettingsTab,
highlight?: WorkspaceSettingsHighlight,
) => {
showDialog({ showDialog({
id: "workspace-settings", id: "workspace-settings",
size: "lg", size: "lg",
className: "h-[calc(100vh-5rem)] max-h-200!", className: "h-[calc(100vh-5rem)] max-h-200!",
noPadding: true, noPadding: true,
render: ({ hide }) => ( render: ({ hide }) => (
<WorkspaceSettingsDialog workspaceId={workspaceId} hide={hide} tab={tab} /> <WorkspaceSettingsDialog
workspaceId={workspaceId}
hide={hide}
tab={tab}
highlight={highlight}
/>
), ),
}); });
}; };
@@ -0,0 +1,114 @@
import { Icon } from "@yaakapp-internal/ui";
import classNames from "classnames";
import type { ReactNode } from "react";
import { useState } from "react";
import type { CheckboxProps } from "./Checkbox";
import { Checkbox } from "./Checkbox";
export interface CheckboxTreeNode<T> {
key: string;
data: T;
children: CheckboxTreeNode<T>[];
}
interface Props<T> {
node: CheckboxTreeNode<T>;
depth?: number;
/** Return "hidden" to render row alignment space instead of a checkbox */
checked: (node: CheckboxTreeNode<T>) => CheckboxProps["checked"] | "hidden";
onCheck: (node: CheckboxTreeNode<T>, checked: boolean) => void;
checkboxTitle?: (node: CheckboxTreeNode<T>) => string;
isCheckboxDisabled?: (node: CheckboxTreeNode<T>) => boolean;
/** An irrelevant row is hidden unless one of its descendants is relevant */
isRelevant: (node: CheckboxTreeNode<T>) => boolean;
/** A node that starts collapsed, so a large subtree doesn't crowd out the rest */
isCollapsedByDefault?: (node: CheckboxTreeNode<T>) => boolean;
renderRow: (node: CheckboxTreeNode<T>) => ReactNode;
onSelectRow?: (node: CheckboxTreeNode<T>) => void;
canSelectRow?: (node: CheckboxTreeNode<T>) => boolean;
isRowSelected?: (node: CheckboxTreeNode<T>) => boolean;
}
export function CheckboxTree<T>(props: Props<T>) {
const { node, depth = 0 } = props;
const [collapsed, setCollapsed] = useState<boolean>(
() => props.isCollapsedByDefault?.(node) ?? false,
);
if (!hasRelevantNode(node, props.isRelevant)) return null;
const checked = props.checked(node);
const selected = props.isRowSelected?.(node) ?? false;
const selectable = props.onSelectRow != null && (props.canSelectRow?.(node) ?? true);
const hasVisibleChildren = node.children.some((c) => hasRelevantNode(c, props.isRelevant));
const rowContent = (
<div className="flex-1 min-w-0 flex items-center gap-1 px-1 py-0.5 text-left">
{props.renderRow(node)}
</div>
);
return (
<div
className={classNames(
depth > 0 && "pl-4 ml-2 border-l border-dashed border-border-subtle relative",
)}
>
<div
className={classNames(
"relative flex gap-1 w-full h-xs items-center",
selected ? "text-text" : "text-text-subtle",
)}
>
{selected && (
<div className="absolute left-[-100vw] right-0 top-0 bottom-0 bg-surface-active opacity-30 -z-10" />
)}
{hasVisibleChildren ? (
<button
type="button"
aria-label={collapsed ? "Expand" : "Collapse"}
aria-expanded={!collapsed}
className="shrink-0 text-text-subtlest hocus:text-text"
onClick={() => setCollapsed((v) => !v)}
>
<Icon size="sm" icon={collapsed ? "chevron_right" : "chevron_down"} />
</button>
) : (
<span aria-hidden className="w-4 shrink-0" />
)}
{checked === "hidden" ? (
<span aria-hidden className="w-4 mr-0.5 shrink-0" />
) : (
<Checkbox
checked={checked}
title={props.checkboxTitle?.(node) ?? "Toggle"}
hideLabel
disabled={props.isCheckboxDisabled?.(node)}
onChange={(checked) => props.onCheck(node, checked)}
/>
)}
{selectable ? (
<button
type="button"
className="flex-1 min-w-0 flex text-left"
onClick={() => props.onSelectRow?.(node)}
>
{rowContent}
</button>
) : (
rowContent
)}
</div>
{!collapsed &&
node.children.map((child) => (
<CheckboxTree key={child.key} {...props} node={child} depth={depth + 1} />
))}
</div>
);
}
function hasRelevantNode<T>(
node: CheckboxTreeNode<T>,
isRelevant: (node: CheckboxTreeNode<T>) => boolean,
): boolean {
return isRelevant(node) || node.children.some((c) => hasRelevantNode(c, isRelevant));
}
+7 -5
View File
@@ -10,11 +10,13 @@ export interface DialogProps {
children: ReactNode; children: ReactNode;
open: boolean; open: boolean;
onClose?: () => void; onClose?: () => void;
disableBackdropClose?: boolean; /** Block dismissal from the backdrop, Escape key, and built-in close button. */
disableClose?: boolean;
title?: ReactNode; title?: ReactNode;
description?: ReactNode; description?: ReactNode;
className?: string; className?: string;
size?: DialogSize; size?: DialogSize;
/** Hide the built-in close button without changing backdrop or Escape behavior. */
hideX?: boolean; hideX?: boolean;
noPadding?: boolean; noPadding?: boolean;
noScroll?: boolean; noScroll?: boolean;
@@ -27,7 +29,7 @@ export function Dialog({
size = "full", size = "full",
open, open,
onClose, onClose,
disableBackdropClose, disableClose,
title, title,
description, description,
hideX, hideX,
@@ -42,7 +44,7 @@ export function Dialog({
); );
return ( return (
<Overlay open={open} onClose={disableBackdropClose ? undefined : onClose} portalName="dialog"> <Overlay open={open} onClose={disableClose ? undefined : onClose} portalName="dialog">
<div <div
role="dialog" role="dialog"
className={classNames( className={classNames(
@@ -58,7 +60,7 @@ export function Dialog({
// NOTE: We handle Escape on the element itself so that it doesn't close multiple // NOTE: We handle Escape on the element itself so that it doesn't close multiple
// dialogs and can be intercepted by children if needed. // dialogs and can be intercepted by children if needed.
if (e.key === "Escape") { if (e.key === "Escape") {
onClose?.(); if (!disableClose) onClose?.();
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
} }
@@ -110,7 +112,7 @@ export function Dialog({
</div> </div>
{/*Put close at the end so that it's the last thing to be tabbed to*/} {/*Put close at the end so that it's the last thing to be tabbed to*/}
{!hideX && ( {!disableClose && !hideX && (
<div className="ml-auto absolute right-1 top-1"> <div className="ml-auto absolute right-1 top-1">
<IconButton <IconButton
className="opacity-70 hover:opacity-100" className="opacity-70 hover:opacity-100"
@@ -2,11 +2,12 @@ import type { Color } from "@yaakapp-internal/plugins";
import type { BannerProps } from "@yaakapp-internal/ui"; import type { BannerProps } from "@yaakapp-internal/ui";
import { Banner } from "@yaakapp-internal/ui"; import { Banner } from "@yaakapp-internal/ui";
import classNames from "classnames"; import classNames from "classnames";
import type { MouseEvent } from "react"; import type { MouseEvent, ReactNode } from "react";
import { useEffect } from "react"; import { useEffect } from "react";
import { useKeyValue } from "../../hooks/useKeyValue"; import { useKeyValue } from "../../hooks/useKeyValue";
import type { ButtonProps } from "./Button"; import type { ButtonProps } from "./Button";
import { Button } from "./Button"; import { Button } from "./Button";
import { IconButton } from "./IconButton";
type DismissibleBannerSize = "sm" | "xs"; type DismissibleBannerSize = "sm" | "xs";
@@ -18,17 +19,21 @@ export function DismissibleBanner({
onDismiss, onDismiss,
onShow, onShow,
actions, actions,
variant = "banner",
...props ...props
}: BannerProps & { }: BannerProps & {
id: string; id: string;
size?: DismissibleBannerSize; size?: DismissibleBannerSize;
onDismiss?: () => void | Promise<void>; onDismiss?: () => void | Promise<void>;
onShow?: () => void | Promise<void>; onShow?: () => void | Promise<void>;
/** A tip dismisses with an X in the corner instead of a text button */
variant?: "banner" | "tip";
actions?: { actions?: {
label: string; label: string;
onClick: () => void; onClick: () => void;
color?: Color; color?: Color;
variant?: ButtonProps["variant"]; variant?: ButtonProps["variant"];
rightSlot?: ReactNode;
}[]; }[];
}) { }) {
const { const {
@@ -56,54 +61,69 @@ export function DismissibleBanner({
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
}; };
const dismiss = (event: MouseEvent) => {
stopParentClick(event);
setDismissed(true).catch(console.error);
Promise.resolve(onDismiss?.()).catch(console.error);
};
const isTip = variant === "tip";
const hasActionRow = !isTip || (actions?.length ?? 0) > 0;
return ( return (
<Banner <Banner
className={classNames( className={classNames(className, "relative", size === "xs" && "!px-2 !py-2 text-xs")}
className,
"relative",
size === "xs" && "!px-2 !py-2 text-xs",
)}
{...props} {...props}
> >
<div className="@container"> <div className={classNames("@container", isTip && "relative")}>
{isTip && (
<IconButton
icon="x"
size="2xs"
iconSize="sm"
title="Dismiss message"
className="absolute! -top-0.5 -right-1 @[34rem]:top-1/2 @[34rem]:-translate-y-1/2 opacity-50 hover:opacity-100"
onClick={dismiss}
/>
)}
<div <div
className={classNames( className={classNames(
"grid @[34rem]:grid-cols-[minmax(0,1fr)_auto] @[34rem]:items-center", "grid @[34rem]:grid-cols-[minmax(0,1fr)_auto] @[34rem]:items-center",
isTip && "@[34rem]:pr-5",
size === "xs" ? "gap-1.5 @[34rem]:gap-2" : "gap-2 @[34rem]:gap-3", size === "xs" ? "gap-1.5 @[34rem]:gap-2" : "gap-2 @[34rem]:gap-3",
)} )}
> >
{children} {isTip ? <div className="pr-5 @[34rem]:pr-0">{children}</div> : children}
<div className="flex flex-wrap gap-1.5 @[34rem]:justify-end"> {hasActionRow && (
<Button <div className="flex flex-col gap-1.5 @[16rem]:flex-row @[16rem]:flex-wrap @[16rem]:justify-end">
variant="border" {!isTip && (
color={props.color} <Button
size={actionSize} variant="border"
onClick={(event) => { color={props.color}
stopParentClick(event); size={actionSize}
setDismissed(true).catch(console.error); onClick={dismiss}
Promise.resolve(onDismiss?.()).catch(console.error); title="Dismiss message"
}} >
title="Dismiss message" Dismiss
> </Button>
Dismiss )}
</Button> {actions?.map((a) => (
{actions?.map((a) => ( <Button
<Button key={a.label}
key={a.label} rightSlot={a.rightSlot}
variant={a.variant ?? "border"} variant={a.variant ?? "border"}
color={a.color ?? props.color} color={a.color ?? props.color}
size={actionSize} size={actionSize}
onClick={(event) => { onClick={(event) => {
stopParentClick(event); stopParentClick(event);
a.onClick(); a.onClick();
}} }}
title={a.label} title={a.label}
> >
{a.label} {a.label}
</Button> </Button>
))} ))}
</div> </div>
)}
</div> </div>
</div> </div>
</Banner> </Banner>
@@ -601,6 +601,8 @@ function getExtensions({
EditorView.contentAttributes.of({ EditorView.contentAttributes.of({
autocapitalize: "off", autocapitalize: "off",
autocorrect: "off", autocorrect: "off",
// Keeps macOS Writing Tools from offering to write code for us
writingsuggestions: "false",
}), }),
EditorView.domEventHandlers({ EditorView.domEventHandlers({
focus: () => { focus: () => {
@@ -0,0 +1,202 @@
import { SearchQuery } from "@codemirror/search";
import { EditorState } from "@codemirror/state";
import { describe, expect, test } from "vite-plus/test";
import {
currentMatch,
literalSearch,
MAX_COUNT,
MatchCounter,
normalizeDoc,
normalizeSearch,
scanNormalized,
scanQuery,
} from "./searchMatchCount";
type QueryConfig = ConstructorParameters<typeof SearchQuery>[0];
const stateOf = (doc: string) => EditorState.create({ doc });
/**
* The matches the counter finds, having checked them against the search panel's own cursor.
*
* The cursor decides which ranges the editor highlights and which one `find next` lands on, so
* a count that doesn't agree with it is a wrong count, however fast it was to produce.
*/
function matchesOf(doc: string, config: QueryConfig) {
const state = stateOf(doc);
const query = new SearchQuery(config);
const matches = new MatchCounter().matches(state, query);
expect(matches).toEqual(scanQuery(state, query));
return matches;
}
const countOf = (doc: string, config: QueryConfig) => matchesOf(doc, config).length;
describe("counting", () => {
test("counts every match, whatever the case", () => {
expect(countOf("one Two three two", { search: "two" })).toBe(2);
expect(countOf("one Two three two", { search: "two", caseSensitive: true })).toBe(1);
});
test("skips matches overlapping an earlier one", () => {
expect(countOf("aaaaa", { search: "aa" })).toBe(2);
expect(countOf("ababa", { search: "aba" })).toBe(1);
});
test("treats a query as text, not as a pattern", () => {
expect(countOf("a.b axb", { search: "a.b" })).toBe(1);
});
test("unquotes escapes unless the query is literal", () => {
expect(countOf("one\ntwo\nthree", { search: "\\n" })).toBe(2);
expect(countOf("one\\ntwo", { search: "\\n", literal: true })).toBe(1);
});
test("counts regexp and whole word queries through the cursor", () => {
expect(literalSearch(new SearchQuery({ search: "a", regexp: true }))).toBe(null);
expect(literalSearch(new SearchQuery({ search: "a", wholeWord: true }))).toBe(null);
expect(countOf("a1 b2 c3", { search: "[a-z]\\d", regexp: true })).toBe(3);
expect(countOf("cat cats cat", { search: "cat", wholeWord: true })).toBe(2);
});
test("stops counting at the cap", () => {
expect(countOf("x".repeat(MAX_COUNT + 100), { search: "x" })).toBe(MAX_COUNT + 1);
});
test("reports where the matches are", () => {
expect(matchesOf("ab..ab", { search: "ab" })).toEqual([
{ from: 0, to: 2 },
{ from: 4, to: 6 },
]);
});
test("finds nothing to match with an empty needle", () => {
expect(scanNormalized(normalizeDoc("abc", false), "")).toEqual([]);
});
});
describe("normalization", () => {
test("finds what a character decomposes into", () => {
// The é is one character holding an `e`, and the match covers the whole of it
expect(matchesOf("café", { search: "e" })).toEqual([{ from: 3, to: 4 }]);
expect(matchesOf("file", { search: "fi" })).toEqual([{ from: 0, to: 1 }]);
expect(matchesOf("a…b", { search: "..." })).toEqual([{ from: 1, to: 2 }]);
expect(countOf("one two", { search: "one two" })).toBe(1);
expect(countOf("full width", { search: "full" })).toBe(1);
});
test("matches a decomposed query against composed text, and the reverse", () => {
expect(countOf("café", { search: "café" })).toBe(1);
expect(countOf("café", { search: "café" })).toBe(1);
expect(countOf("café", { search: "café" })).toBe(1);
});
test("keeps offsets straight after an expansion", () => {
expect(matchesOf("é.é.end", { search: "end" })).toEqual([{ from: 4, to: 7 }]);
expect(matchesOf("fififi stop", { search: "stop" })).toEqual([{ from: 4, to: 8 }]);
});
test("normalizes the query whole, the document by character", () => {
expect(normalizeSearch("CAFÉ", false)).toBe("café");
expect(normalizeSearch("CAFÉ", true)).toBe("CAFÉ");
// Whole-string NFKD would fold this to a final sigma, which the cursor never does
expect(normalizeDoc("ΟΔΟΣ", false).text).toBe("οδοσ");
});
test("leaves a document that normalizes to itself untouched", () => {
const { text, expansions } = normalizeDoc("plain 日本 🎉 text", false);
expect(text).toBe("plain 日本 🎉 text");
expect(expansions).toEqual([]);
});
});
describe("current match", () => {
const matches = [
{ from: 0, to: 2 },
{ from: 4, to: 6 },
{ from: 8, to: 10 },
];
test("counts from one, and reports 0 off a match", () => {
expect(currentMatch(matches, { from: 4, to: 6 })).toBe(2);
expect(currentMatch(matches, { from: 8, to: 10 })).toBe(3);
expect(currentMatch(matches, { from: 5, to: 5 })).toBe(2);
expect(currentMatch(matches, { from: 2, to: 3 })).toBe(0);
expect(currentMatch(matches, { from: 4, to: 7 })).toBe(0);
expect(currentMatch([], { from: 0, to: 0 })).toBe(0);
});
test("moving the selection doesn't scan again", () => {
const state = stateOf("a1 b2 c3");
const query = new SearchQuery({ search: "\\d", regexp: true });
const counter = new MatchCounter();
const found = counter.matches(state, query);
// The document a selection-only transaction leaves behind is the one already scanned
const moved = state.update({ selection: { anchor: 4, head: 5 } }).state;
expect(counter.matches(moved, query)).toBe(found);
expect(currentMatch(found, moved.selection.main)).toBe(2);
});
});
/**
* The mapping from normalized offsets back to document offsets is the part of this that can go
* quietly wrong, and only on input nobody thinks to write a case for. So generate the input.
*/
describe("against the cursor, on awkward text", () => {
const ALPHABET = [
..."abcABC .\\\n".split(""),
"é",
"é",
"fi",
"…",
" ",
"İ",
"Σ",
"ς",
"日",
"🎉",
"Ⅻ",
"f",
"①",
"́",
];
/** Seeded, so a failure is the same failure next run */
function random(seed: number) {
let state = seed;
return () => {
state = (state * 1664525 + 1013904223) >>> 0;
return state / 2 ** 32;
};
}
for (const caseSensitive of [false, true]) {
test(`agrees on every generated document (caseSensitive: ${caseSensitive})`, () => {
const next = random(caseSensitive ? 20260831 : 7);
for (let round = 0; round < 400; round++) {
const doc = Array.from(
{ length: 2 + Math.floor(next() * 60) },
() => ALPHABET[Math.floor(next() * ALPHABET.length)]!,
).join("");
// Half the queries are lifted out of the document, so matches are actually found
const start = Math.floor(next() * doc.length);
const search =
next() < 0.5
? doc.slice(start, start + 1 + Math.floor(next() * 3))
: Array.from(
{ length: 1 + Math.floor(next() * 2) },
() => ALPHABET[Math.floor(next() * ALPHABET.length)]!,
).join("");
if (search === "") continue;
const state = stateOf(doc);
const query = new SearchQuery({ search, caseSensitive });
const where = `doc=${JSON.stringify(doc)} search=${JSON.stringify(search)}`;
expect(new MatchCounter().matches(state, query), where).toEqual(scanQuery(state, query));
}
});
}
});
@@ -1,7 +1,232 @@
import { getSearchQuery, searchPanelOpen } from "@codemirror/search"; import { getSearchQuery, type SearchQuery, searchPanelOpen } from "@codemirror/search";
import type { Extension } from "@codemirror/state"; import type { EditorState, Extension, Text } from "@codemirror/state";
import { type EditorView, ViewPlugin, type ViewUpdate } from "@codemirror/view"; import { type EditorView, ViewPlugin, type ViewUpdate } from "@codemirror/view";
/** Matches are counted no further than this, since an exact total stops being useful long before */
export const MAX_COUNT = 9999;
/** What normalizing rewrites: anything outside ASCII, plus the case it folds */
const REWRITTEN = /\P{ASCII}|[A-Z]+/gu;
const REWRITTEN_CASE_SENSITIVE = /\P{ASCII}/gu;
export interface Match {
from: number;
to: number;
}
/** A character whose normalized form is a different length, shifting every offset past it */
interface Expansion {
normFrom: number;
normTo: number;
docFrom: number;
docTo: number;
}
/** A document as SearchCursor compares it, with what's needed to get back to real offsets */
export interface NormalizedDoc {
text: string;
expansions: Expansion[];
}
/**
* Rewrites a document the way SearchCursor does — NFKD, then a case fold unless the search is
* case-sensitive — in a single pass rather than one call per code point.
*
* The cursor spends 90% of its time asking ICU about one character at a time, which is what
* makes counting matches in a large response slow. Doing it a character at a time still matters
* for the result, since it keeps NFKD from reordering marks across characters, so the
* granularity stays and only the repeated work goes: each distinct character is normalized once
* and the answer reused, and ASCII runs never reach ICU at all.
*/
export function normalizeDoc(text: string, caseSensitive: boolean): NormalizedDoc {
const rewritten = new Map<string, string>();
const expansions: Expansion[] = [];
let shift = 0;
const normalized = text.replace(
caseSensitive ? REWRITTEN_CASE_SENSITIVE : REWRITTEN,
(chunk: string, at: number) => {
// An ASCII run only ever folds case, which can't change its length
if (chunk.charCodeAt(0) < 0x80) return chunk.toLowerCase();
let out = rewritten.get(chunk);
if (out === undefined) {
out = chunk.normalize("NFKD");
if (!caseSensitive) out = out.toLowerCase();
rewritten.set(chunk, out);
}
if (out.length !== chunk.length) {
expansions.push({
normFrom: at + shift,
normTo: at + shift + out.length,
docFrom: at,
docTo: at + chunk.length,
});
shift += out.length - chunk.length;
}
return out;
},
);
return { text: normalized, expansions };
}
/** The query as SearchCursor compares it, which it normalizes whole rather than by character */
export function normalizeSearch(search: string, caseSensitive: boolean): string {
const normalized = search.normalize("NFKD");
return caseSensitive ? normalized : normalized.toLowerCase();
}
/** Every occurrence of `needle`, skipping matches that overlap an earlier one */
export function scanNormalized(doc: NormalizedDoc, needle: string): Match[] {
const matches: Match[] = [];
if (needle === "") return matches;
const { text } = doc;
let pos = text.indexOf(needle);
while (pos >= 0) {
let end = pos + needle.length;
// However the query was cut, a match ends on a whole code point, as the cursor's do
if (isLowSurrogate(text.charCodeAt(end))) end++;
matches.push({ from: docStart(doc, pos), to: docEnd(doc, end) });
if (matches.length > MAX_COUNT) break;
pos = text.indexOf(needle, resumeAfter(doc, end));
}
return matches;
}
/** The same through the query's own cursor, which handles regexps and whole words */
export function scanQuery(state: EditorState, query: SearchQuery): Match[] {
const matches: Match[] = [];
const cursor = query.getCursor(state);
for (let result = cursor.next(); !result.done; result = cursor.next()) {
matches.push({ from: result.value.from, to: result.value.to });
if (matches.length > MAX_COUNT) break;
}
return matches;
}
const isLowSurrogate = (code: number) => code >= 0xdc00 && code <= 0xdfff;
/** The last character expansion beginning at or before `offset`, if there is one */
function expansionAt({ expansions }: NormalizedDoc, offset: number): Expansion | null {
let low = 0;
let high = expansions.length - 1;
let found: Expansion | null = null;
while (low <= high) {
const mid = (low + high) >> 1;
if (expansions[mid]!.normFrom <= offset) {
found = expansions[mid]!;
low = mid + 1;
} else {
high = mid - 1;
}
}
return found;
}
function docStart(doc: NormalizedDoc, offset: number): number {
const expansion = expansionAt(doc, offset);
if (expansion == null) return offset;
// A match starting inside a character's expansion starts at the character
return offset < expansion.normTo
? expansion.docFrom
: offset - (expansion.normTo - expansion.docTo);
}
/**
* Where scanning picks up after a match ending at `offset`.
*
* The cursor moves through the document a character at a time, so once a match ends inside a
* character's expansion the rest of that expansion is behind it — "…" holds three dots but only
* ever counts as one match of ".".
*/
function resumeAfter(doc: NormalizedDoc, offset: number): number {
const expansion = expansionAt(doc, offset);
return expansion != null && offset > expansion.normFrom && offset < expansion.normTo
? expansion.normTo
: offset;
}
function docEnd(doc: NormalizedDoc, offset: number): number {
const expansion = expansionAt(doc, offset);
if (expansion == null) return offset;
if (offset <= expansion.normFrom) return expansion.docFrom;
// A match ending inside a character's expansion covers the whole character
return offset < expansion.normTo
? expansion.docTo
: offset - (expansion.normTo - expansion.docTo);
}
/** Position of the match holding the selection, counting from one, or 0 when it isn't on one */
export function currentMatch(matches: Match[], selection: { from: number; to: number }): number {
let index = 0;
for (const match of matches) {
index++;
if (match.from <= selection.from && match.to >= selection.to) return index;
}
return 0;
}
/** The text a plain query looks for, or null when only the cursor can answer it */
export function literalSearch(query: SearchQuery): string | null {
if (query.regexp || query.wholeWord || query.test != null) return null;
// Mirrors SearchQuery's own unquoting, which the published type doesn't expose
return query.literal
? query.search
: query.search.replace(/\\([nrt\\])/g, (_, ch) =>
ch === "n" ? "\n" : ch === "r" ? "\r" : ch === "t" ? "\t" : "\\",
);
}
/**
* Finds the matches for the search panel, keeping the normalized document and the matches it
* last found, so neither moving the selection nor typing another character starts over.
*/
export class MatchCounter {
private doc: { doc: Text; caseSensitive: boolean; normalized: NormalizedDoc } | null = null;
private last: { doc: Text; query: SearchQuery; matches: Match[] } | null = null;
matches(state: EditorState, query: SearchQuery): Match[] {
const last = this.last;
if (last != null && last.doc === state.doc && last.query.eq(query)) {
return last.matches;
}
const matches = this.scan(state, query);
this.last = { doc: state.doc, query, matches };
return matches;
}
private scan(state: EditorState, query: SearchQuery): Match[] {
const search = literalSearch(query);
if (search == null) return scanQuery(state, query);
const doc = this.normalizedDoc(state.doc, query.caseSensitive);
return scanNormalized(doc, normalizeSearch(search, query.caseSensitive));
}
private normalizedDoc(doc: Text, caseSensitive: boolean): NormalizedDoc {
const cached = this.doc;
if (cached != null && cached.doc === doc && cached.caseSensitive === caseSensitive) {
return cached.normalized;
}
const normalized = normalizeDoc(doc.toString(), caseSensitive);
this.doc = { doc, caseSensitive, normalized };
return normalized;
}
}
/** /**
* A CodeMirror extension that displays the total number of search matches * A CodeMirror extension that displays the total number of search matches
* inside the built-in search panel. * inside the built-in search panel.
@@ -10,6 +235,7 @@ export function searchMatchCount(): Extension {
return ViewPlugin.fromClass( return ViewPlugin.fromClass(
class { class {
private countEl: HTMLElement | null = null; private countEl: HTMLElement | null = null;
private counter = new MatchCounter();
constructor(private view: EditorView) { constructor(private view: EditorView) {
this.updateCount(); this.updateCount();
@@ -38,38 +264,21 @@ export function searchMatchCount(): Extension {
} }
this.ensureCountEl(); this.ensureCountEl();
if (this.countEl == null) return;
if (!query.search) { if (!query.search) {
if (this.countEl) { this.countEl.textContent = "0/0";
this.countEl.textContent = "0/0";
}
return; return;
} }
const selection = state.selection.main; const matches = this.counter.matches(state, query);
let count = 0; if (matches.length > MAX_COUNT) {
let currentIndex = 0; this.countEl.textContent = `${MAX_COUNT}+`;
const MAX_COUNT = 9999; } else if (matches.length === 0) {
const cursor = query.getCursor(state); this.countEl.textContent = "0/0";
for (let result = cursor.next(); !result.done; result = cursor.next()) { } else {
count++; const current = currentMatch(matches, state.selection.main);
const match = result.value; this.countEl.textContent = `${current}/${matches.length}`;
if (match.from <= selection.from && match.to >= selection.to) {
currentIndex = count;
}
if (count > MAX_COUNT) break;
}
if (this.countEl) {
if (count > MAX_COUNT) {
this.countEl.textContent = `${MAX_COUNT}+`;
} else if (count === 0) {
this.countEl.textContent = "0/0";
} else if (currentIndex > 0) {
this.countEl.textContent = `${currentIndex}/${count}`;
} else {
this.countEl.textContent = `0/${count}`;
}
} }
} }
@@ -0,0 +1,78 @@
import { platform } from "@yaakapp-internal/platform";
import { Icon } from "@yaakapp-internal/ui";
import type { ReactNode } from "react";
import { setKeyValue } from "../../lib/keyValueStore";
import { DismissibleBanner } from "./DismissibleBanner";
interface Props {
/** Stable id; the dismissal is remembered under it. */
id: string;
children: ReactNode;
docsUrl?: string;
action?: { label: string; onClick: () => void | Promise<void> };
onDismiss?: () => void;
className?: string;
}
/**
* A one-time nudge toward a feature the user hasn't found yet. Dismissed once, gone for good.
*/
export function FeatureHint({ id, children, docsUrl, action, onDismiss, className }: Props) {
const actions = [
...(action ? [{ ...action, variant: "solid" as const, color: "info" as const }] : []),
...(action != null && docsUrl != null
? [
{
label: "Docs",
rightSlot: <Icon icon="external_link" size="xs" className="opacity-60" />,
onClick: () => platform.openUrl(docsUrl).catch(console.error),
},
]
: []),
];
return (
<DismissibleBanner
id={`feature-hint:${id}`}
variant="tip"
color="info"
size="xs"
onDismiss={onDismiss}
className={className}
actions={actions}
>
<div className="flex items-start gap-2 text-xs">
<Icon icon="sparkles" size="xs" className="hidden @[16rem]:block mt-0.5 shrink-0" />
<div className="min-w-0">
{children}
{action == null && docsUrl != null && (
<>
{" "}
(
<button
type="button"
className="group inline-flex items-center gap-0.5 underline hover:text-info cursor-pointer! [&_*]:cursor-pointer!"
onClick={() => platform.openUrl(docsUrl).catch(console.error)}
>
docs
<Icon
icon="external_link"
size="xs"
className="opacity-80 group-hover:opacity-100"
/>
</button>
)
</>
)}
</div>
</div>
</DismissibleBanner>
);
}
export function dismissFeatureHint(id: string) {
return setKeyValue({
namespace: "global",
key: ["dismiss-banner", `feature-hint:${id}`],
value: true,
});
}
@@ -113,7 +113,15 @@ function toPairData({ commitName: _commitName, ...pair }: EditablePairWithId): P
/** Max number of pairs to show before prompting the user to reveal the rest */ /** Max number of pairs to show before prompting the user to reveal the rest */
const MAX_INITIAL_PAIRS = 30; const MAX_INITIAL_PAIRS = 30;
export function PairEditor({ // Keyed on `stateKey` so no state survives a change of owner. Row ids alone can't tell owners
// apart — two pair sets can share ids (eg. one duplicated from the other), and the same-rows
// fast path below would swap in the new data without rebuilding the row editors, leaving any
// still-focused input showing the old owner's text.
export function PairEditor(props: PairEditorProps) {
return <PairEditorInner key={props.stateKey} {...props} />;
}
function PairEditorInner({
allowFileValues, allowFileValues,
allowMultilineValues, allowMultilineValues,
className, className,
@@ -205,6 +205,7 @@ export const PlainInput = forwardRef<{ focus: () => void }, PlainInputProps>(fun
autoComplete="off" autoComplete="off"
autoCapitalize="off" autoCapitalize="off"
autoCorrect="off" autoCorrect="off"
writingsuggestions="false"
inputMode={inputMode} inputMode={inputMode}
onChange={(e) => handleChange(e.target.value)} onChange={(e) => handleChange(e.target.value)}
onPaste={(e) => onPaste?.(e.clipboardData.getData("Text"))} onPaste={(e) => onPaste?.(e.clipboardData.getData("Text"))}
@@ -6,6 +6,7 @@ import { useStateWithDeps } from "../../hooks/useStateWithDeps";
import { generateId } from "../../lib/generateId"; import { generateId } from "../../lib/generateId";
import { Button } from "./Button"; import { Button } from "./Button";
import { IconButton, type IconButtonProps } from "./IconButton"; import { IconButton, type IconButtonProps } from "./IconButton";
import { IconTooltip } from "./IconTooltip";
import { Label } from "./Label"; import { Label } from "./Label";
interface Props<T extends string> { interface Props<T extends string> {
@@ -36,11 +37,15 @@ export function SegmentedControl<T extends string>({
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const id = useRef(`input-${generateId()}`); const id = useRef(`input-${generateId()}`);
// A visually hidden label has nowhere to show the help, so the last option carries it
const inlineHelp =
hideLabel && help ? <IconTooltip tabIndex={-1} content={help} iconSize="xs" /> : null;
return ( return (
<div className="w-full grid"> <div className="w-full grid">
<Label <Label
htmlFor={id.current} htmlFor={id.current}
help={help} help={hideLabel ? undefined : help}
visuallyHidden={hideLabel} visuallyHidden={hideLabel}
className={classNames(labelClassName)} className={classNames(labelClassName)}
> >
@@ -78,9 +83,10 @@ export function SegmentedControl<T extends string>({
} }
}} }}
> >
{options.map((o) => { {options.map((o, i) => {
const isSelected = selectedValue === o.value; const isSelected = selectedValue === o.value;
const isActive = value === o.value; const isActive = value === o.value;
const rightSlot = i === options.length - 1 ? inlineHelp : null;
if (o.icon == null) { if (o.icon == null) {
return ( return (
<Button <Button
@@ -95,6 +101,7 @@ export function SegmentedControl<T extends string>({
isActive && "text-text!", isActive && "text-text!",
"focus:ring-1 focus:ring-border-focus", "focus:ring-1 focus:ring-border-focus",
)} )}
rightSlot={rightSlot}
onClick={() => onChange(o.value)} onClick={() => onChange(o.value)}
> >
{o.label} {o.label}
@@ -117,6 +124,7 @@ export function SegmentedControl<T extends string>({
)} )}
title={o.label} title={o.label}
icon={o.icon} icon={o.icon}
rightSlot={rightSlot}
onClick={() => onChange(o.value)} onClick={() => onChange(o.value)}
/> />
); );
+6 -2
View File
@@ -119,9 +119,13 @@ export function Select<T extends string>({
)} )}
> >
<Button <Button
className="w-full text-sm font-mono" className={classNames(
"w-full text-sm font-mono",
disabled && "border-dotted",
isInvalidSelection && "border-danger",
)}
justify="start" justify="start"
variant="border" variant="input"
size={size} size={size}
leftSlot={leftSlot} leftSlot={leftSlot}
disabled={disabled} disabled={disabled}
@@ -2,6 +2,7 @@ import type { AnyModel } from "@yaakapp-internal/models";
import { patchModel } from "@yaakapp-internal/models"; import { patchModel } from "@yaakapp-internal/models";
import classNames from "classnames"; import classNames from "classnames";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import { createContext, useContext, useEffect, useRef, useState } from "react";
import { CopyIconButton } from "../CopyIconButton"; import { CopyIconButton } from "../CopyIconButton";
import { Checkbox } from "./Checkbox"; import { Checkbox } from "./Checkbox";
import { IconButton, type IconButtonProps } from "./IconButton"; import { IconButton, type IconButtonProps } from "./IconButton";
@@ -19,11 +20,31 @@ type SettingRowBaseProps = {
controlClassName?: string; controlClassName?: string;
description?: ReactNode; description?: ReactNode;
disabled?: boolean; disabled?: boolean;
/** Matched against the surrounding `SettingsList` highlight to point this row out when it opens */
highlightKey?: string;
title: ReactNode; title: ReactNode;
}; };
export function SettingsList({ children, className }: { children: ReactNode; className?: string }) { const SettingsHighlightContext = createContext<string | null>(null);
return <div className={classNames("w-full", className)}>{children}</div>;
const FOCUSABLE =
"button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])";
export function SettingsList({
children,
className,
highlight = null,
}: {
children: ReactNode;
className?: string;
/** The `highlightKey` of a row to scroll to, focus, and briefly highlight */
highlight?: string | null;
}) {
return (
<SettingsHighlightContext.Provider value={highlight}>
<div className={classNames("w-full", className)}>{children}</div>
</SettingsHighlightContext.Provider>
);
} }
export function SettingsSection({ export function SettingsSection({
@@ -58,17 +79,37 @@ export function SettingRow({
controlClassName, controlClassName,
description, description,
disabled, disabled,
highlightKey,
title, title,
}: { }: {
children: ReactNode; children: ReactNode;
} & SettingRowBaseProps) { } & SettingRowBaseProps) {
const highlight = useContext(SettingsHighlightContext);
const isHighlighted = highlightKey != null && highlightKey === highlight;
const [flashing, setFlashing] = useState(isHighlighted);
const rowRef = useRef<HTMLDivElement>(null);
const controlRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!isHighlighted) return;
rowRef.current?.scrollIntoView({ block: "nearest" });
controlRef.current?.querySelector<HTMLElement>(FOCUSABLE)?.focus();
}, [isHighlighted]);
return ( return (
<div <div
ref={rowRef}
aria-disabled={disabled || undefined} aria-disabled={disabled || undefined}
onAnimationEnd={(event) => {
if (event.target === event.currentTarget) setFlashing(false);
}}
className={classNames( className={classNames(
className, className,
"@container border-b border-border-subtle py-4", "@container border-b border-border-subtle py-4",
disabled && "opacity-disabled", disabled && "opacity-disabled",
// Drawn on a layer so the tint gets even padding and stops short of the row's border
flashing &&
"relative isolate before:absolute before:-inset-x-3 before:inset-y-1 before:-z-10 before:rounded-lg before:animate-settingHighlight",
)} )}
> >
<div <div
@@ -84,6 +125,7 @@ export function SettingRow({
)} )}
</div> </div>
<div <div
ref={controlRef}
className={classNames( className={classNames(
"flex min-w-0 items-center justify-start @[40rem]:justify-end", "flex min-w-0 items-center justify-start @[40rem]:justify-end",
controlClassName, controlClassName,
@@ -21,6 +21,8 @@ import { CommercialUseBanner } from "../CommercialUseBanner";
import { Button } from "../core/Button"; import { Button } from "../core/Button";
import type { CheckboxProps } from "../core/Checkbox"; import type { CheckboxProps } from "../core/Checkbox";
import { Checkbox } from "../core/Checkbox"; import { Checkbox } from "../core/Checkbox";
import type { CheckboxTreeNode } from "../core/CheckboxTree";
import { CheckboxTree } from "../core/CheckboxTree";
import { DiffViewer } from "../core/Editor/DiffViewer"; import { DiffViewer } from "../core/Editor/DiffViewer";
import { Input } from "../core/Input"; import { Input } from "../core/Input";
import { Separator } from "../core/Separator"; import { Separator } from "../core/Separator";
@@ -43,10 +45,7 @@ interface CommitTreeNode {
export function GitCommitDialog({ syncDir, onDone, workspace }: Props) { export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
const callbacks = useGitCallbacks(syncDir); const callbacks = useGitCallbacks(syncDir);
const [{ status }, { commit, commitAndPush, add, unstage, restore }] = useGit( const [{ status }, { commit, commitAndPush, add, unstage, restore }] = useGit(syncDir, callbacks);
syncDir,
callbacks,
);
const [isPushing, setIsPushing] = useState(false); const [isPushing, setIsPushing] = useState(false);
const [commitError, setCommitError] = useState<string | null>(null); const [commitError, setCommitError] = useState<string | null>(null);
const [message, setMessage] = useState<string>(""); const [message, setMessage] = useState<string>("");
@@ -143,6 +142,15 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
return next(workspace, []); return next(workspace, []);
}, [workspace, internalEntries]); }, [workspace, internalEntries]);
const treeNode: CheckboxTreeNode<CommitTreeNode> | null = useMemo(() => {
const toTreeNode = (n: CommitTreeNode): CheckboxTreeNode<CommitTreeNode> => ({
key: n.status.relaPath + n.status.status + n.status.staged,
data: n,
children: n.children.map(toTreeNode),
});
return tree == null ? null : toTreeNode(tree);
}, [tree]);
const checkNode = useCallback( const checkNode = useCallback(
(treeNode: CommitTreeNode) => { (treeNode: CommitTreeNode) => {
const checked = nodeCheckedStatus(treeNode); const checked = nodeCheckedStatus(treeNode);
@@ -190,7 +198,7 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
[restore], [restore],
); );
if (tree == null) { if (tree == null || treeNode == null) {
return null; return null;
} }
@@ -221,12 +229,18 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
style={innerStyle} style={innerStyle}
className="h-full overflow-y-auto pb-3 pr-0.5 transform-cpu" className="h-full overflow-y-auto pb-3 pr-0.5 transform-cpu"
> >
<TreeNodeChildren <CheckboxTree
node={tree} node={treeNode}
depth={0} checked={(n) => nodeCheckedStatus(n.data)}
onCheck={checkNode} onCheck={(n) => checkNode(n.data)}
onSelect={handleSelectChild} checkboxTitle={(n) =>
selectedPath={selectedEntry?.relaPath ?? null} nodeCheckedStatus(n.data) ? "Unstage change" : "Stage change"
}
isRelevant={(n) => n.data.status.status !== "current"}
canSelectRow={(n) => n.data.status.status !== "current"}
onSelectRow={(n) => handleSelectChild(n.data.status)}
isRowSelected={(n) => selectedEntry?.relaPath === n.data.status.relaPath}
renderRow={(n) => <CommitTreeRow node={n.data} />}
/> />
{externalEntries.find((e) => e.status !== "current") && ( {externalEntries.find((e) => e.status !== "current") && (
<> <>
@@ -244,10 +258,7 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
</div> </div>
)} )}
secondSlot={({ style: innerStyle }) => ( secondSlot={({ style: innerStyle }) => (
<div <div style={innerStyle} className="grid grid-rows-[minmax(0,1fr)_auto] gap-3 pb-2">
style={innerStyle}
className="grid grid-rows-[minmax(0,1fr)_auto] gap-3 pb-2"
>
<Input <Input
className="text-base! font-sans rounded-md" className="text-base! font-sans rounded-md"
placeholder="Commit message..." placeholder="Commit message..."
@@ -301,96 +312,39 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
); );
} }
function TreeNodeChildren({ function CommitTreeRow({ node }: { node: CommitTreeNode }) {
node,
depth,
onCheck,
onSelect,
selectedPath,
}: {
node: CommitTreeNode | null;
depth: number;
onCheck: (node: CommitTreeNode, checked: boolean) => void;
onSelect: (entry: GitStatusEntry) => void;
selectedPath: string | null;
}) {
if (node === null) return null;
if (!isNodeRelevant(node)) return null;
const checked = nodeCheckedStatus(node);
const isSelected = selectedPath === node.status.relaPath;
return ( return (
<div <>
className={classNames( {node.model.model !== "http_request" &&
depth > 0 && "pl-4 ml-2 border-l border-dashed border-border-subtle relative", node.model.model !== "grpc_request" &&
)} node.model.model !== "websocket_request" ? (
> <Icon
<div color="secondary"
className={classNames( icon={
"relative flex gap-1 w-full h-xs items-center", node.model.model === "folder"
isSelected ? "text-text" : "text-text-subtle", ? "folder"
)} : node.model.model === "environment"
> ? "variable"
{isSelected && ( : "house"
<div className="absolute left-[-100vw] right-0 top-0 bottom-0 bg-surface-active opacity-30 -z-10" /> }
)}
<Checkbox
checked={checked}
title={checked ? "Unstage change" : "Stage change"}
hideLabel
onChange={(checked) => onCheck(node, checked)}
/> />
<button ) : (
type="button" <span aria-hidden className="w-4" />
className={classNames("flex-1 min-w-0 flex items-center gap-1 px-1 py-0.5 text-left")} )}
onClick={() => node.status.status !== "current" && onSelect(node.status)} <div className="truncate flex-1">{resolvedModelName(node.model)}</div>
{node.status.status !== "current" && (
<InlineCode
className={classNames(
"py-0 bg-transparent w-24 text-center shrink-0",
node.status.status === "modified" && "text-info",
node.status.status === "untracked" && "text-success",
node.status.status === "removed" && "text-danger",
)}
> >
{node.model.model !== "http_request" && {node.status.status}
node.model.model !== "grpc_request" && </InlineCode>
node.model.model !== "websocket_request" ? ( )}
<Icon </>
color="secondary"
icon={
node.model.model === "folder"
? "folder"
: node.model.model === "environment"
? "variable"
: "house"
}
/>
) : (
<span aria-hidden className="w-4" />
)}
<div className="truncate flex-1">{resolvedModelName(node.model)}</div>
{node.status.status !== "current" && (
<InlineCode
className={classNames(
"py-0 bg-transparent w-24 text-center shrink-0",
node.status.status === "modified" && "text-info",
node.status.status === "untracked" && "text-success",
node.status.status === "removed" && "text-danger",
)}
>
{node.status.status}
</InlineCode>
)}
</button>
</div>
{node.children.map((childNode) => {
return (
<TreeNodeChildren
key={childNode.status.relaPath + childNode.status.status + childNode.status.staged}
node={childNode}
depth={depth + 1}
onCheck={onCheck}
onSelect={onSelect}
selectedPath={selectedPath}
/>
);
})}
</div>
); );
} }
@@ -495,15 +449,6 @@ function setCheckedAndChildren(
if (toUnstage.length > 0) unstage({ relaPaths: toUnstage }); if (toUnstage.length > 0) unstage({ relaPaths: toUnstage });
} }
function isNodeRelevant(node: CommitTreeNode): boolean {
if (node.status.status !== "current") {
return true;
}
// Recursively check children
return node.children.some((c) => isNodeRelevant(c));
}
function DiffPanel({ function DiffPanel({
entry, entry,
onDiscardChanges, onDiscardChanges,
@@ -526,13 +471,11 @@ function DiffPanel({
size="2xs" size="2xs"
variant="border" variant="border"
onClick={() => onDiscardChanges(entry)} onClick={() => onDiscardChanges(entry)}
>Discard Changes</Button> >
Discard Changes
</Button>
</div> </div>
<DiffViewer <DiffViewer original={prevYaml ?? ""} modified={nextYaml ?? ""} className="flex-1 min-h-0" />
original={prevYaml ?? ""}
modified={nextYaml ?? ""}
className="flex-1 min-h-0"
/>
</div> </div>
); );
} }
@@ -1,10 +1,8 @@
import { useGitBranchInfo, useGitMutations } from "@yaakapp-internal/git"; import { useGitBranchInfo, useGitMutations } from "@yaakapp-internal/git";
import type { WorkspaceMeta } from "@yaakapp-internal/models";
import classNames from "classnames"; import classNames from "classnames";
import { useAtomValue } from "jotai"; import { useAtomValue } from "jotai";
import type { HTMLAttributes } from "react"; import type { HTMLAttributes } from "react";
import { forwardRef, useCallback, useMemo } from "react"; import { forwardRef, useCallback, useMemo } from "react";
import { openWorkspaceSettings } from "../../commands/openWorkspaceSettings";
import { activeWorkspaceAtom, activeWorkspaceMetaAtom } from "../../hooks/useActiveWorkspace"; import { activeWorkspaceAtom, activeWorkspaceMetaAtom } from "../../hooks/useActiveWorkspace";
import { useKeyValue } from "../../hooks/useKeyValue"; import { useKeyValue } from "../../hooks/useKeyValue";
import { useRandomKey } from "../../hooks/useRandomKey"; import { useRandomKey } from "../../hooks/useRandomKey";
@@ -18,6 +16,7 @@ import { showErrorToast, showToast } from "../../lib/toast";
import type { DropdownItem } from "../core/Dropdown"; import type { DropdownItem } from "../core/Dropdown";
import { Dropdown } from "../core/Dropdown"; import { Dropdown } from "../core/Dropdown";
import { Banner, Icon, InlineCode } from "@yaakapp-internal/ui"; import { Banner, Icon, InlineCode } from "@yaakapp-internal/ui";
import { SyncWorkspaceHint } from "../hints/SyncWorkspaceHint";
import { useGitCallbacks } from "./callbacks"; import { useGitCallbacks } from "./callbacks";
import { GitCommitDialog } from "./GitCommitDialog"; import { GitCommitDialog } from "./GitCommitDialog";
import { GitRemotesDialog } from "./GitRemotesDialog"; import { GitRemotesDialog } from "./GitRemotesDialog";
@@ -31,7 +30,7 @@ export function GitDropdown() {
if (workspaceMeta == null) return null; if (workspaceMeta == null) return null;
if (workspaceMeta.settingSyncDir == null) { if (workspaceMeta.settingSyncDir == null) {
return <SetupSyncDropdown workspaceMeta={workspaceMeta} />; return <SyncWorkspaceHint workspaceId={workspaceMeta.workspaceId} />;
} }
return <SyncDropdownWithSyncDir syncDir={workspaceMeta.settingSyncDir} />; return <SyncDropdownWithSyncDir syncDir={workspaceMeta.settingSyncDir} />;
@@ -567,64 +566,6 @@ const GitMenuButton = forwardRef<HTMLButtonElement, HTMLAttributes<HTMLButtonEle
}, },
); );
function SetupSyncDropdown({ workspaceMeta }: { workspaceMeta: WorkspaceMeta }) {
const { value: hidden, set: setHidden } = useKeyValue<Record<string, boolean>>({
key: "setup_sync",
fallback: {},
});
if (hidden == null || hidden[workspaceMeta.workspaceId]) {
return null;
}
const banner = (
<Banner color="info">
When enabled, workspace data syncs to the chosen folder as text files, ideal for backup and
Git collaboration.
</Banner>
);
return (
<Dropdown
fullWidth
items={[
{
type: "content",
label: banner,
},
{
color: "success",
label: "Open Workspace Settings",
leftSlot: <Icon icon="settings" />,
onSelect: () => openWorkspaceSettings("settings"),
},
{ type: "separator" },
{
label: "Hide This Message",
leftSlot: <Icon icon="eye_closed" />,
async onSelect() {
const confirmed = await showConfirm({
id: "hide-sync-menu-prompt",
title: "Hide Setup Message",
description: "You can configure filesystem sync or Git it in the workspace settings",
});
if (confirmed) {
await setHidden((prev) => ({ ...prev, [workspaceMeta.workspaceId]: true }));
}
},
},
]}
>
<GitMenuButton>
<div className="text-sm text-text-subtle grid grid-cols-[auto_minmax(0,1fr)] items-center gap-2">
<Icon icon="wrench" />
<div className="truncate">Setup FS Sync or Git</div>
</div>
</GitMenuButton>
</Dropdown>
);
}
function SetupGitDropdown({ function SetupGitDropdown({
workspaceId, workspaceId,
initRepo, initRepo,
+1 -3
View File
@@ -86,10 +86,8 @@ export async function promptDivergedStrategy({
showDialog({ showDialog({
id: "git-diverged", id: "git-diverged",
title: "Branches Diverged", title: "Branches Diverged",
hideX: true,
size: "sm", size: "sm",
disableBackdropClose: true, disableClose: true,
onClose: () => resolve("cancel"),
render: ({ hide }) => render: ({ hide }) =>
DivergedDialog({ DivergedDialog({
remote, remote,
@@ -0,0 +1,29 @@
import type { HttpResponse } from "@yaakapp-internal/models";
import { httpRequestsAtom } from "@yaakapp-internal/models";
import { InlineCode } from "@yaakapp-internal/ui";
import { useAtomValue } from "jotai";
import { FeatureHint } from "../core/FeatureHint";
const MIN_REQUESTS = 2;
const DOCS_URL = "https://yaak.app/docs/templating/request-chaining-scripting";
interface Props {
response: HttpResponse;
mimeType: string | null;
}
/** A successful JSON response, in a workspace with somewhere to send its values. */
export function ChainingHint({ response, mimeType }: Props) {
const requestCount = useAtomValue(httpRequestsAtom).length;
const status = response.status ?? 0;
const isJson = mimeType != null && /json/i.test(mimeType);
if (response.state !== "closed" || status < 200 || status >= 300) return null;
if (!isJson || requestCount < MIN_REQUESTS) return null;
return (
<FeatureHint id="chaining" className="mx-3 mt-1 shrink-0" docsUrl={DOCS_URL}>
Need a value from here in another request? Press <InlineCode>Ctrl+Space</InlineCode> in any
field and pick <InlineCode>response()</InlineCode> to pull it out with a JSONPath
</FeatureHint>
);
}
@@ -0,0 +1,44 @@
import { useEnvironmentsBreakdown } from "../../hooks/useEnvironmentsBreakdown";
import {
addVariableToBaseEnvironment,
isTemplate,
variableTemplate,
} from "../../lib/addVariableToBaseEnvironment";
import { dismissFeatureHint, FeatureHint } from "../core/FeatureHint";
const HINT_ID = "secret-variable";
const DOCS_URL = "https://yaak.app/docs/templating/environments-and-variables";
interface Props {
/** Becomes the variable name, so it should describe the value (eg. "password", "token") */
name: string;
value: string;
onReplace: (template: string) => void;
}
/**
* A literal secret typed straight into an auth field. Offer to move it to a variable so the
* request references it instead of holding it.
*/
export function SecretVariableHint({ name, value, onReplace }: Props) {
const { baseEnvironment } = useEnvironmentsBreakdown();
if (value.trim() === "" || isTemplate(value) || baseEnvironment == null) return null;
return (
<FeatureHint
id={HINT_ID}
docsUrl={DOCS_URL}
action={{
label: "Move to Variable",
onClick: async () => {
const finalName = await addVariableToBaseEnvironment(baseEnvironment, name, value);
onReplace(variableTemplate(finalName));
await dismissFeatureHint(HINT_ID);
},
}}
>
Typing this in by hand? Store it in a variable to reuse it across requests and swap it per
environment.
</FeatureHint>
);
}
@@ -0,0 +1,73 @@
import { httpRequestsAtom, patchModel } from "@yaakapp-internal/models";
import { InlineCode } from "@yaakapp-internal/ui";
import { useAtomValue } from "jotai";
import { useMemo } from "react";
import { useEnvironmentsBreakdown } from "../../hooks/useEnvironmentsBreakdown";
import {
addVariableToBaseEnvironment,
isTemplate,
variableTemplate,
} from "../../lib/addVariableToBaseEnvironment";
import { FeatureHint } from "../core/FeatureHint";
const MIN_SHARED_REQUESTS = 3;
const DOCS_URL = "https://yaak.app/docs/templating/environments-and-variables";
/**
* Once a few requests spell out the same literal origin, offer to hoist it into a variable and
* rewrite them all at once.
*/
export function SharedOriginHint() {
const requests = useAtomValue(httpRequestsAtom);
const { baseEnvironment } = useEnvironmentsBreakdown();
const shared = useMemo(() => {
const byOrigin = new Map<string, typeof requests>();
for (const r of requests) {
if (isTemplate(r.url)) continue;
const origin = literalOrigin(r.url);
if (origin == null) continue;
byOrigin.set(origin, [...(byOrigin.get(origin) ?? []), r]);
}
let best: { origin: string; requests: typeof requests } | null = null;
for (const [origin, group] of byOrigin) {
if (group.length >= MIN_SHARED_REQUESTS && group.length > (best?.requests.length ?? 0)) {
best = { origin, requests: group };
}
}
return best;
}, [requests]);
if (shared == null || baseEnvironment == null) return null;
const { origin } = shared;
const count = shared.requests.length;
return (
<FeatureHint
id={`shared-origin:${origin}`}
className="mt-1"
docsUrl={DOCS_URL}
action={{
label: "Use a Variable",
onClick: async () => {
const name = await addVariableToBaseEnvironment(baseEnvironment, "base_url", origin);
const template = variableTemplate(name);
await Promise.all(
shared.requests.map((r) =>
patchModel(r, { url: template + r.url.slice(origin.length) }),
),
);
},
}}
>
{count} requests start with <InlineCode>{origin}</InlineCode>. Put it in a variable and switch
hosts by switching environments.
</FeatureHint>
);
}
function literalOrigin(url: string): string | null {
const m = /^(https?:\/\/[^/?#\s]+)/i.exec(url.trim());
return m?.[1] ?? null;
}
@@ -0,0 +1,44 @@
import { VStack } from "@yaakapp-internal/ui";
import { openWorkspaceSettings } from "../../commands/openWorkspaceSettings";
import { useKeyValue } from "../../hooks/useKeyValue";
import { showToast } from "../../lib/toast";
import { FeatureHint } from "../core/FeatureHint";
const DOCS_URL = "https://yaak.app/docs/collaboration/local-directory-git-sync";
/** What the sidebar's Git slot shows while the workspace only lives in the app's database. */
export function SyncWorkspaceHint({ workspaceId }: { workspaceId: string }) {
// Hidden from the menu this replaced, so honor it
const { value: legacyHidden } = useKeyValue<Record<string, boolean>>({
key: "setup_sync",
fallback: {},
});
if (legacyHidden == null || legacyHidden[workspaceId]) return null;
return (
<FeatureHint
id={`sync-workspace:${workspaceId}`}
className="mx-2 mb-2!"
docsUrl={DOCS_URL}
action={{ label: "Configure", onClick: () => openWorkspaceSettings("settings", "sync_dir") }}
onDismiss={showSyncLocationToast}
>
Sync this workspace to a folder of plain files to back it up or track it with Git.
</FeatureHint>
);
}
function showSyncLocationToast() {
showToast({
id: "sync-hint-dismissed",
color: "info",
timeout: 8000,
message: (
<VStack>
<h2 className="font-semibold">Sync whenever you're ready</h2>
<p className="text-text-subtle text-sm">Directory sync and Git are in Workspace Settings</p>
</VStack>
),
});
}
@@ -0,0 +1,31 @@
import type { Environment } from "@yaakapp-internal/models";
import { patchModel } from "@yaakapp-internal/models";
import { generateId } from "./generateId";
/** Adds a variable, suffixing the name if it's taken, and returns the name that was used. */
export async function addVariableToBaseEnvironment(
environment: Environment,
name: string,
value: string,
): Promise<string> {
const taken = new Set(environment.variables.map((v) => v.name));
let finalName = name;
for (let i = 2; taken.has(finalName); i++) {
finalName = `${name}_${i}`;
}
await patchModel(environment, {
variables: [
...environment.variables,
{ id: generateId(), name: finalName, value, enabled: true },
],
});
return finalName;
}
export function variableTemplate(name: string) {
return `\${[ ${name} ]}`;
}
export function isTemplate(value: string) {
return value.includes("${[");
}
+1 -2
View File
@@ -14,9 +14,8 @@ export function showAlert({ id, title, body, size = "sm" }: AlertArgs) {
showDialog({ showDialog({
id, id,
title, title,
hideX: true,
size, size,
disableBackdropClose: true, // Prevent accidental dismisses disableClose: true,
render: ({ hide }) => Alert({ onHide: hide, body }), render: ({ hide }) => Alert({ onHide: hide, body }),
}); });
} }
+1 -2
View File
@@ -18,9 +18,8 @@ export async function showConfirm({
return new Promise((onResult: ConfirmProps["onResult"]) => { return new Promise((onResult: ConfirmProps["onResult"]) => {
showDialog({ showDialog({
...extraProps, ...extraProps,
hideX: true,
size, size,
disableBackdropClose: true, // Prevent accidental dismisses disableClose: true,
render: ({ hide }) => Confirm({ onHide: hide, color, onResult, confirmText, requireTyping }), render: ({ hide }) => Confirm({ onHide: hide, color, onResult, confirmText, requireTyping }),
}); });
}); });
+49 -17
View File
@@ -1,14 +1,34 @@
import type { BatchUpsertResult } from "@yaakapp-internal/models"; import {
type BatchUpsertResult,
type ImportDestination,
type ImportPlan,
type ImportSource,
workspacesAtom,
} from "@yaakapp-internal/models";
import { FormattedError, VStack } from "@yaakapp-internal/ui"; import { FormattedError, VStack } from "@yaakapp-internal/ui";
import { Button } from "../components/core/Button"; import { Button } from "../components/core/Button";
import { ImportDataDialog } from "../components/ImportDataDialog"; import { ImportDataDialog } from "../components/ImportDataDialog";
import { activeFolderAtom } from "../hooks/useActiveFolder";
import { activeWorkspaceAtom } from "../hooks/useActiveWorkspace";
import { createFastMutation } from "../hooks/useFastMutation"; import { createFastMutation } from "../hooks/useFastMutation";
import { showAlert } from "./alert"; import { showAlert } from "./alert";
import { showDialog } from "./dialog"; import { showDialog } from "./dialog";
import { jotaiStore } from "./jotai";
import { pluralizeCount } from "./pluralize"; import { pluralizeCount } from "./pluralize";
import { router } from "./router"; import { router } from "./router";
import { rpc } from "./rpc"; import { rpc } from "./rpc";
// Stable identities so the dialog's effects don't re-run (and cancel in-flight
// fetches) every time the dialog container re-renders.
const planFile = (filePath: string, destination: ImportDestination) =>
rpc<ImportPlan>("cmd_import_data", { filePath, destination });
const planUrl = (url: string, destination: ImportDestination) =>
rpc<ImportPlan>("cmd_import_url", { url, destination });
const listSources = (workspaceId: string) =>
rpc<ImportSource[]>("cmd_list_import_sources", { workspaceId });
const findSourcesForOrigin = (args: { filePath?: string; url?: string }) =>
rpc<ImportSource[]>("cmd_import_sources_for_origin", args);
export const importData = createFastMutation({ export const importData = createFastMutation({
mutationKey: ["import_data"], mutationKey: ["import_data"],
onError: (err: string) => { onError: (err: string) => {
@@ -21,29 +41,41 @@ export const importData = createFastMutation({
}, },
mutationFn: async () => { mutationFn: async () => {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
const currentWorkspace = jotaiStore.get(activeWorkspaceAtom);
const workspaces = jotaiStore.get(workspacesAtom);
const selectedFolder = jotaiStore.get(activeFolderAtom);
showDialog({ showDialog({
id: "import", id: "import",
title: "Import Data", title: "Import Data",
size: "sm", size: "lg",
disableClose: true,
render: ({ hide }) => { render: ({ hide }) => {
const importAndHide = async (runImport: () => Promise<BatchUpsertResult>) => { const cancel = () => {
try { hide();
await finishImport(await runImport()); resolve();
resolve(); };
} catch (err) { const fail = (err: unknown) => {
reject(err); hide();
} finally { reject(err);
hide(); };
} const commit = async (plan: ImportPlan) => {
const imported = await rpc<BatchUpsertResult>("cmd_commit_import", { plan });
hide();
await finishImport(imported);
resolve();
}; };
return ( return (
<ImportDataDialog <ImportDataDialog
importFile={(filePath) => currentWorkspace={currentWorkspace}
importAndHide(() => rpc<BatchUpsertResult>("cmd_import_data", { filePath })) workspaces={workspaces}
} selectedFolder={selectedFolder}
importUrl={(url) => planFile={planFile}
importAndHide(() => rpc<BatchUpsertResult>("cmd_import_url", { url })) planUrl={planUrl}
} listSources={listSources}
findSourcesForOrigin={findSourcesForOrigin}
commit={commit}
cancel={cancel}
onError={fail}
/> />
); );
}, },
+60 -14
View File
@@ -12,7 +12,7 @@ import type {
UpdateResponse, UpdateResponse,
YaakNotification, YaakNotification,
} from "@yaakapp-internal/tauri-client"; } from "@yaakapp-internal/tauri-client";
import { HStack, Icon, VStack } from "@yaakapp-internal/ui"; import { HStack, Icon, InlineCode, VStack } from "@yaakapp-internal/ui";
import { openSettings } from "../commands/openSettings"; import { openSettings } from "../commands/openSettings";
import { Button } from "../components/core/Button"; import { Button } from "../components/core/Button";
import { ButtonInfiniteLoading } from "../components/core/ButtonInfiniteLoading"; import { ButtonInfiniteLoading } from "../components/core/ButtonInfiniteLoading";
@@ -180,9 +180,65 @@ function showUpdateInstalledToast(version: string) {
async function showUpdateAvailableToast(updateInfo: UpdateInfo) { async function showUpdateAvailableToast(updateInfo: UpdateInfo) {
const UPDATE_TOAST_ID = "update-info"; const UPDATE_TOAST_ID = "update-info";
const { version, replyEventId, downloaded } = updateInfo; const { version, replyEventId, downloaded, install } = updateInfo;
jotaiStore.set(updateAvailableAtom, { version, downloaded }); jotaiStore.set(updateAvailableAtom, { version, downloaded, install });
const whatsNewButton = (
<Button
size="xs"
color="info"
variant="border"
rightSlot={<Icon icon="external_link" />}
onClick={async () => {
await platform.openUrl(`https://yaak.app/changelog/${version}`);
}}
>
What&apos;s New
</Button>
);
if (install !== "integrated") {
// Nothing to reply to here; the backend only told us so we can say how to update
const flatpak = install === "flatpak";
showToast({
id: UPDATE_TOAST_ID,
color: "info",
timeout: null,
message: (
<VStack>
<h2 className="font-semibold">Yaak {version} is available</h2>
<p className="text-text-subtle text-sm">
{flatpak ? (
<>
Update with <InlineCode>flatpak update</InlineCode> or your software center.
</>
) : (
"Download the new version to upgrade."
)}
</p>
</VStack>
),
action: () => (
<HStack space={1.5}>
{!flatpak && (
<Button
size="xs"
color="info"
rightSlot={<Icon icon="external_link" />}
onClick={async () => {
await platform.openUrl("https://yaak.app/download");
}}
>
Download
</Button>
)}
{whatsNewButton}
</HStack>
),
});
return;
}
// Acknowledge the event, so we don't time out and try the fallback update logic // Acknowledge the event, so we don't time out and try the fallback update logic
await platform.emit(replyEventId, { type: "ack" } satisfies UpdateResponse); await platform.emit(replyEventId, { type: "ack" } satisfies UpdateResponse);
@@ -215,17 +271,7 @@ async function showUpdateAvailableToast(updateInfo: UpdateInfo) {
> >
{downloaded ? "Install Now" : "Download and Install"} {downloaded ? "Install Now" : "Download and Install"}
</ButtonInfiniteLoading> </ButtonInfiniteLoading>
<Button {whatsNewButton}
size="xs"
color="info"
variant="border"
rightSlot={<Icon icon="external_link" />}
onClick={async () => {
await platform.openUrl(`https://yaak.app/changelog/${version}`);
}}
>
What&apos;s New
</Button>
</HStack> </HStack>
), ),
}); });
@@ -0,0 +1,251 @@
import { describe, expect, test } from "vite-plus/test";
import type { JsonSchema } from "./jsonSchemaExample";
import { buildExampleFromSchema } from "./jsonSchemaExample";
describe("buildExampleFromSchema", () => {
test("fills scalar fields with placeholders", () => {
const schema: JsonSchema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number", format: "int32" },
active: { type: "boolean" },
data: { type: "string", format: "byte" },
},
};
expect(buildExampleFromSchema(schema)).toEqual({
name: "",
age: 0,
active: false,
data: "",
});
});
test("encodes 64-bit integers as strings", () => {
const schema: JsonSchema = {
type: "object",
properties: {
id: { type: "string", format: "int64" },
count: { type: "string", format: "uint64" },
offset: { type: "string", format: "sfixed64" },
},
};
expect(buildExampleFromSchema(schema)).toEqual({ id: "0", count: "0", offset: "0" });
});
test("fills date-time with a parseable timestamp", () => {
const schema: JsonSchema = {
type: "object",
properties: { createdAt: { type: "string", format: "date-time" } },
};
const example = buildExampleFromSchema(schema) as { createdAt: string };
expect(Number.isNaN(Date.parse(example.createdAt))).toBe(false);
});
test("fills a duration with a value that parses", () => {
const schema: JsonSchema = {
type: "object",
properties: { timeout: { type: "string", format: "duration" } },
};
// An empty string fails protobuf's Duration parsing, so the message wouldn't send
expect(buildExampleFromSchema(schema)).toEqual({ timeout: "0s" });
});
test("expands nested messages through $defs", () => {
const schema: JsonSchema = {
type: "object",
properties: { user: { $ref: "#/$defs/example.User" } },
$defs: {
"example.User": {
type: "object",
properties: {
name: { type: "string" },
address: { $ref: "#/$defs/example.Address" },
},
},
"example.Address": {
type: "object",
properties: { city: { type: "string" } },
},
},
};
expect(buildExampleFromSchema(schema)).toEqual({
user: { name: "", address: { city: "" } },
});
});
test("gives repeated fields a single placeholder item", () => {
const schema: JsonSchema = {
type: "object",
properties: {
tags: { type: "array", items: { type: "string" } },
users: { type: "array", items: { $ref: "#/$defs/example.User" } },
unknown: { type: "array" },
},
$defs: {
"example.User": { type: "object", properties: { name: { type: "string" } } },
},
};
expect(buildExampleFromSchema(schema)).toEqual({
tags: [""],
users: [{ name: "" }],
unknown: [],
});
});
test("uses the first value of an enum", () => {
const schema: JsonSchema = {
type: "object",
properties: {
status: { type: "string", enum: ["STATUS_UNSPECIFIED", "STATUS_ACTIVE"] },
empty: { type: "string", enum: [] },
},
};
expect(buildExampleFromSchema(schema)).toEqual({ status: "STATUS_UNSPECIFIED", empty: "" });
});
test("gives maps a single placeholder entry", () => {
const schema: JsonSchema = {
type: "object",
properties: {
labels: { type: "object", additionalProperties: { type: "string" } },
users: { type: "object", additionalProperties: { $ref: "#/$defs/example.User" } },
},
$defs: {
"example.User": { type: "object", properties: { name: { type: "string" } } },
},
};
expect(buildExampleFromSchema(schema)).toEqual({
labels: { key: "" },
users: { key: { name: "" } },
});
});
test("stops at the root self-reference", () => {
const schema: JsonSchema = {
type: "object",
properties: {
value: { type: "string" },
children: { type: "array", items: { $ref: "#" } },
},
};
expect(buildExampleFromSchema(schema)).toEqual({ value: "", children: [{}] });
});
test("stops at a cycle between messages", () => {
const schema: JsonSchema = {
type: "object",
properties: { node: { $ref: "#/$defs/example.Node" } },
$defs: {
"example.Node": {
type: "object",
properties: {
name: { type: "string" },
parent: { $ref: "#/$defs/example.Node" },
leaf: { $ref: "#/$defs/example.Leaf" },
},
},
"example.Leaf": {
type: "object",
properties: { node: { $ref: "#/$defs/example.Node" } },
},
},
};
expect(buildExampleFromSchema(schema)).toEqual({
node: { name: "", parent: {}, leaf: { node: {} } },
});
});
test("expands the same message twice when it is not on the same path", () => {
const schema: JsonSchema = {
type: "object",
properties: {
from: { $ref: "#/$defs/example.User" },
to: { $ref: "#/$defs/example.User" },
},
$defs: {
"example.User": { type: "object", properties: { name: { type: "string" } } },
},
};
expect(buildExampleFromSchema(schema)).toEqual({ from: { name: "" }, to: { name: "" } });
});
test("fills every branch of a flattened oneof", () => {
const schema: JsonSchema = {
type: "object",
properties: {
id: { type: "string" },
text: { type: "string" },
image: { $ref: "#/$defs/example.Image" },
},
$defs: {
"example.Image": { type: "object", properties: { url: { type: "string" } } },
},
};
expect(buildExampleFromSchema(schema)).toEqual({
id: "",
text: "",
image: { url: "" },
});
});
test("stops expanding once the node budget runs out", () => {
// Every level references the next one twice, so an unbounded walk would build 2^depth
// nodes without ever repeating a ref on the same path.
const depth = 16;
const $defs: Record<string, JsonSchema> = { [`d${depth}`]: { type: "string" } };
for (let i = 0; i < depth; i++) {
$defs[`d${i}`] = {
type: "object",
properties: {
a: { $ref: `#/$defs/d${i + 1}` },
b: { $ref: `#/$defs/d${i + 1}` },
},
};
}
const example = buildExampleFromSchema({
type: "object",
properties: { root: { $ref: "#/$defs/d0" } },
$defs,
});
// 2 ** 16 nodes unbounded; the budget holds it to a couple of thousand
expect(countNodes(example)).toBeLessThan(10_000);
});
test("handles messages without a known type", () => {
const schema: JsonSchema = {
type: "object",
properties: {
empty: {},
struct: { type: "object" },
missing: { $ref: "#/$defs/example.Nope" },
},
};
expect(buildExampleFromSchema(schema)).toEqual({ empty: null, struct: {}, missing: {} });
});
});
function countNodes(value: unknown): number {
if (Array.isArray(value)) {
return 1 + value.reduce((total: number, v) => total + countNodes(v), 0);
}
if (value !== null && typeof value === "object") {
return 1 + Object.values(value).reduce((total: number, v) => total + countNodes(v), 0);
}
return 1;
}
+121
View File
@@ -0,0 +1,121 @@
/**
* Subset of JSON Schema emitted by the gRPC reflection layer for a method's
* input message. See `message_to_json_schema` in the `yaak-grpc` crate.
*/
export type JsonSchema = {
type?: string;
format?: string;
properties?: Record<string, JsonSchema>;
items?: JsonSchema;
additionalProperties?: JsonSchema;
enum?: unknown[];
$defs?: Record<string, JsonSchema>;
$ref?: string;
};
const DEFS_PREFIX = "#/$defs/";
const ROOT_REF = "#";
// Protobuf 64-bit integers are encoded as strings in the JSON mapping
const STRING_NUMBER_FORMATS = ["int64", "uint64", "sint64", "fixed64", "sfixed64"];
// Refs on sibling branches each expand their own subtree, so a schema that references the
// same messages repeatedly can produce exponentially many nodes without ever cycling.
const MAX_NODES = 5000;
type Budget = { remaining: number };
/** Build a sample message with placeholder values for every field in the schema */
export function buildExampleFromSchema(schema: JsonSchema): unknown {
// The root is already being built, so a `#` ref anywhere below it is a cycle
return buildValue(schema, schema, new Set([ROOT_REF]), { remaining: MAX_NODES });
}
function buildValue(
schema: JsonSchema,
root: JsonSchema,
refPath: Set<string>,
budget: Budget,
): unknown {
if (schema == null || typeof schema !== "object" || budget.remaining <= 0) {
return null;
}
budget.remaining -= 1;
if (typeof schema.$ref === "string") {
if (refPath.has(schema.$ref)) {
return {};
}
const resolved = resolveRef(schema.$ref, root);
if (resolved == null) {
return {};
}
return buildValue(resolved, root, new Set(refPath).add(schema.$ref), budget);
}
if (Array.isArray(schema.enum)) {
return schema.enum[0] ?? "";
}
switch (schema.type) {
case "object":
return buildObject(schema, root, refPath, budget);
case "array":
return schema.items == null ? [] : [buildValue(schema.items, root, refPath, budget)];
case "string":
return buildString(schema.format);
case "number":
return 0;
case "boolean":
return false;
default:
return null;
}
}
function buildObject(
schema: JsonSchema,
root: JsonSchema,
refPath: Set<string>,
budget: Budget,
): unknown {
if (schema.properties != null && typeof schema.properties === "object") {
const example: Record<string, unknown> = {};
for (const [name, propertySchema] of Object.entries(schema.properties)) {
example[name] = buildValue(propertySchema, root, refPath, budget);
}
return example;
}
// Maps have no properties, only a value schema
if (schema.additionalProperties != null) {
return { key: buildValue(schema.additionalProperties, root, refPath, budget) };
}
return {};
}
function buildString(format: string | undefined): string {
if (format === "date-time") {
return new Date().toISOString();
}
// Duration JSON is a decimal string with an `s` suffix, and an empty one fails to parse
if (format === "duration") {
return "0s";
}
if (format != null && STRING_NUMBER_FORMATS.includes(format)) {
return "0";
}
return "";
}
function resolveRef(ref: string, root: JsonSchema): JsonSchema | null {
if (ref === ROOT_REF) {
return root;
}
if (!ref.startsWith(DEFS_PREFIX)) {
return null;
}
return root.$defs?.[ref.slice(DEFS_PREFIX.length)] ?? null;
}
+1 -6
View File
@@ -25,13 +25,8 @@ export async function showPromptForm({
id, id,
title, title,
description, description,
hideX: true,
size: size ?? "sm", size: size ?? "sm",
disableBackdropClose: true, // Prevent accidental dismisses disableClose: true,
onClose: () => {
// Click backdrop, close, or escape
resolve(null);
},
render: ({ hide }) => render: ({ hide }) =>
Prompt({ Prompt({
onCancel: () => { onCancel: () => {
+14 -16
View File
@@ -5,6 +5,7 @@ type ModelType = AnyModel["model"];
type WorkspaceRequestSettings = Pick< type WorkspaceRequestSettings = Pick<
Workspace, Workspace,
| "settingFollowRedirects" | "settingFollowRedirects"
| "settingHttpVersion"
| "settingRequestMessageSize" | "settingRequestMessageSize"
| "settingRequestTimeout" | "settingRequestTimeout"
| "settingSendCookies" | "settingSendCookies"
@@ -18,9 +19,7 @@ type ModelTypeWithSetting<K extends RequestSettingKey> = {
[M in ModelType]: K extends keyof ModelForType<M> ? M : never; [M in ModelType]: K extends keyof ModelForType<M> ? M : never;
}[ModelType]; }[ModelType];
export type RequestSettingDefinition< export type RequestSettingDefinition<K extends RequestSettingKey = RequestSettingKey> = {
K extends RequestSettingKey = RequestSettingKey,
> = {
defaultValue: WorkspaceRequestSettings[K]; defaultValue: WorkspaceRequestSettings[K];
description: string; description: string;
modelKey: K; modelKey: K;
@@ -46,8 +45,7 @@ export const SETTING_REQUEST_TIMEOUT = defineRequestSetting({
export const SETTING_REQUEST_MESSAGE_SIZE = defineRequestSetting({ export const SETTING_REQUEST_MESSAGE_SIZE = defineRequestSetting({
defaultValue: 64 * 1024 * 1024, defaultValue: 64 * 1024 * 1024,
description: description: "Maximum gRPC or WebSocket message size in MB. Set to 0 to disable.",
"Maximum gRPC or WebSocket message size in MB. Set to 0 to disable.",
modelKey: "settingRequestMessageSize", modelKey: "settingRequestMessageSize",
models: ["workspace", "folder", "websocket_request", "grpc_request"], models: ["workspace", "folder", "websocket_request", "grpc_request"],
title: "Message Size Limit", title: "Message Size Limit",
@@ -57,13 +55,7 @@ export const SETTING_VALIDATE_CERTIFICATES = defineRequestSetting({
defaultValue: true, defaultValue: true,
description: "When disabled, skip validation of server certificates.", description: "When disabled, skip validation of server certificates.",
modelKey: "settingValidateCertificates", modelKey: "settingValidateCertificates",
models: [ models: ["workspace", "folder", "http_request", "websocket_request", "grpc_request"],
"workspace",
"folder",
"http_request",
"websocket_request",
"grpc_request",
],
title: "Validate TLS certificates", title: "Validate TLS certificates",
}); });
@@ -75,10 +67,17 @@ export const SETTING_FOLLOW_REDIRECTS = defineRequestSetting({
title: "Follow redirects", title: "Follow redirects",
}); });
export const SETTING_HTTP_VERSION = defineRequestSetting({
defaultValue: "auto",
description: "Force HTTP/1.1 or HTTP/2 for servers that don't negotiate the version correctly.",
modelKey: "settingHttpVersion",
models: ["workspace", "folder", "http_request"],
title: "HTTP version",
});
export const SETTING_SEND_COOKIES = defineRequestSetting({ export const SETTING_SEND_COOKIES = defineRequestSetting({
defaultValue: true, defaultValue: true,
description: description: "Attach matching cookies from the active cookie jar to outgoing requests.",
"Attach matching cookies from the active cookie jar to outgoing requests.",
modelKey: "settingSendCookies", modelKey: "settingSendCookies",
models: ["workspace", "folder", "http_request", "websocket_request"], models: ["workspace", "folder", "http_request", "websocket_request"],
title: "Automatically send cookies", title: "Automatically send cookies",
@@ -86,8 +85,7 @@ export const SETTING_SEND_COOKIES = defineRequestSetting({
export const SETTING_STORE_COOKIES = defineRequestSetting({ export const SETTING_STORE_COOKIES = defineRequestSetting({
defaultValue: true, defaultValue: true,
description: description: "Save cookies from Set-Cookie response headers to the active cookie jar.",
"Save cookies from Set-Cookie response headers to the active cookie jar.",
modelKey: "settingStoreCookies", modelKey: "settingStoreCookies",
models: ["workspace", "folder", "http_request", "websocket_request"], models: ["workspace", "folder", "http_request", "websocket_request"],
title: "Automatically store cookies", title: "Automatically store cookies",
+1 -1
View File
@@ -99,6 +99,6 @@
"vite-plugin-static-copy": "^3.3.0", "vite-plugin-static-copy": "^3.3.0",
"vite-plugin-svgr": "^4.5.0", "vite-plugin-svgr": "^4.5.0",
"vite-plugin-wasm": "^3.5.0", "vite-plugin-wasm": "^3.5.0",
"vite-plus": "^0.2.9" "vite-plus": "^0.3.0"
} }
} }
+8
View File
@@ -0,0 +1,8 @@
import "react";
declare module "react" {
interface HTMLAttributes<T> {
// Not in @types/react yet; opts editable elements out of macOS Writing Tools
writingsuggestions?: "true" | "false";
}
}
+1 -1
View File
@@ -32,6 +32,6 @@
"babel-plugin-react-compiler": "^1.0.0", "babel-plugin-react-compiler": "^1.0.0",
"typescript": "^5.8.3", "typescript": "^5.8.3",
"vite": "npm:@voidzero-dev/vite-plus-core@^0.2.9", "vite": "npm:@voidzero-dev/vite-plus-core@^0.2.9",
"vite-plus": "^0.2.9" "vite-plus": "^0.3.0"
} }
} }
+1 -1
View File
@@ -39,7 +39,7 @@ tokio = { workspace = true, features = [
] } ] }
walkdir = "2" walkdir = "2"
webbrowser = "1" webbrowser = "1"
zip = "4" zip = "7"
yaak = { workspace = true } yaak = { workspace = true }
yaak-api = { workspace = true } yaak-api = { workspace = true }
yaak-core = { workspace = true } yaak-core = { workspace = true }
+7 -14
View File
@@ -1,19 +1,12 @@
--- ---
name: use-yaak name: use-yaak
description: > description: >
Build and run HTTP API requests with the Yaak CLI (`yaak`): create workspaces, Use when the user mentions Yaak, a Yaak workspace, or the `yaak` command, or
folders, environments and variables, author HTTP requests, configure asks to call, hit, or smoke test HTTP/REST endpoints, save or organize API
authentication (OAuth 2.0, bearer tokens, API keys, basic, JWT, AWS SigV4), requests for reuse or manual testing, configure auth on saved requests, import
send them individually or a whole folder/workspace at once, chain one an OpenAPI spec, a Postman or Insomnia collection, or a cURL command, or run
request's response into the next, and import existing APIs from OpenAPI, saved requests across environments. Prefer over one-off `curl` when requests
Postman, Insomnia, or cURL. Use this skill whenever the user mentions Yaak, a should be saved, reused, shared, or run as a set.
Yaak workspace, or the `yaak` command, and also when they ask to try, hit,
call, exercise, or smoke test an HTTP or REST endpoint, to save or organize
API requests for reuse, to set up API requests for manual testing, to add auth
to a saved request, to turn an OpenAPI or Postman collection into runnable
requests, or to run a saved request suite against staging versus production.
Prefer this over one-off `curl` commands whenever the requests should be
saved, reused, shared, or run as a set.
allowed-tools: Bash(yaak:*), Bash(which:*), Bash(command:*), Bash(npm:*), Bash(npx:*) allowed-tools: Bash(yaak:*), Bash(which:*), Bash(command:*), Bash(npm:*), Bash(npx:*)
--- ---
@@ -34,7 +27,7 @@ only for publishing plugins to the Yaak registry.
Two consequences worth holding onto. Requests you create are permanent user data Two consequences worth holding onto. Requests you create are permanent user data
in an app they use, not scratch files, so name them the way the user would and in an app they use, not scratch files, so name them the way the user would and
clean up anything created just to test. And because the app is right there, the clean up anything created just to test. And because the app is right there, the
CLI is usually the wrong place to *read* a response in detail; it is the right CLI is usually the wrong place to _read_ a response in detail; it is the right
place to build, organize, and run requests. place to build, organize, and run requests.
## The CLI describes itself ## The CLI describes itself
+13 -10
View File
@@ -49,8 +49,11 @@ fn schema(pretty: bool) -> CommandResult {
fn list(ctx: &CliContext, workspace_id: Option<&str>) -> CommandResult { fn list(ctx: &CliContext, workspace_id: Option<&str>) -> CommandResult {
let workspace_id = resolve_workspace_id(ctx, workspace_id, "environment list")?; let workspace_id = resolve_workspace_id(ctx, workspace_id, "environment list")?;
let environments = ctx let environments = ctx
.db() .query_manager()
.list_environments_ensure_base(&workspace_id) .with_tx(|tx| {
tx.ensure_base_environment(&workspace_id)?;
tx.list_environments(&workspace_id)
})
.map_err(|e| format!("Failed to list environments: {e}"))?; .map_err(|e| format!("Failed to list environments: {e}"))?;
if environments.is_empty() { if environments.is_empty() {
@@ -111,8 +114,8 @@ fn create(
} }
let created = ctx let created = ctx
.db() .query_manager()
.upsert_environment(&environment, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_environment(&environment, &UpdateSource::Sync))
.map_err(|e| format!("Failed to create environment: {e}"))?; .map_err(|e| format!("Failed to create environment: {e}"))?;
println!("Created environment: {}", created.id); println!("Created environment: {}", created.id);
@@ -133,8 +136,8 @@ fn create(
}; };
let created = ctx let created = ctx
.db() .query_manager()
.upsert_environment(&environment, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_environment(&environment, &UpdateSource::Sync))
.map_err(|e| format!("Failed to create environment: {e}"))?; .map_err(|e| format!("Failed to create environment: {e}"))?;
println!("Created environment: {}", created.id); println!("Created environment: {}", created.id);
@@ -152,8 +155,8 @@ fn update(ctx: &CliContext, json: Option<String>, json_input: Option<String>) ->
let updated = apply_merge_patch(&existing, &patch, &id, "environment update")?; let updated = apply_merge_patch(&existing, &patch, &id, "environment update")?;
let saved = ctx let saved = ctx
.db() .query_manager()
.upsert_environment(&updated, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_environment(&updated, &UpdateSource::Sync))
.map_err(|e| format!("Failed to update environment: {e}"))?; .map_err(|e| format!("Failed to update environment: {e}"))?;
println!("Updated environment: {}", saved.id); println!("Updated environment: {}", saved.id);
@@ -167,8 +170,8 @@ fn delete(ctx: &CliContext, environment_id: &str, yes: bool) -> CommandResult {
} }
let deleted = ctx let deleted = ctx
.db() .query_manager()
.delete_environment_by_id(environment_id, &UpdateSource::Sync) .with_tx(|tx| tx.delete_environment_by_id(environment_id, &UpdateSource::Sync))
.map_err(|e| format!("Failed to delete environment: {e}"))?; .map_err(|e| format!("Failed to delete environment: {e}"))?;
println!("Deleted environment: {}", deleted.id); println!("Deleted environment: {}", deleted.id);
+8 -8
View File
@@ -102,8 +102,8 @@ fn create(
)?; )?;
let created = ctx let created = ctx
.db() .query_manager()
.upsert_folder(&folder, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_folder(&folder, &UpdateSource::Sync))
.map_err(|e| format!("Failed to create folder: {e}"))?; .map_err(|e| format!("Failed to create folder: {e}"))?;
println!("Created folder: {}", created.id); println!("Created folder: {}", created.id);
@@ -118,8 +118,8 @@ fn create(
let folder = Folder { workspace_id, name, ..Default::default() }; let folder = Folder { workspace_id, name, ..Default::default() };
let created = ctx let created = ctx
.db() .query_manager()
.upsert_folder(&folder, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_folder(&folder, &UpdateSource::Sync))
.map_err(|e| format!("Failed to create folder: {e}"))?; .map_err(|e| format!("Failed to create folder: {e}"))?;
println!("Created folder: {}", created.id); println!("Created folder: {}", created.id);
@@ -135,8 +135,8 @@ fn update(ctx: &CliContext, json: Option<String>, json_input: Option<String>) ->
let updated = apply_merge_patch(&existing, &patch, &id, "folder update")?; let updated = apply_merge_patch(&existing, &patch, &id, "folder update")?;
let saved = ctx let saved = ctx
.db() .query_manager()
.upsert_folder(&updated, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_folder(&updated, &UpdateSource::Sync))
.map_err(|e| format!("Failed to update folder: {e}"))?; .map_err(|e| format!("Failed to update folder: {e}"))?;
println!("Updated folder: {}", saved.id); println!("Updated folder: {}", saved.id);
@@ -150,8 +150,8 @@ fn delete(ctx: &CliContext, folder_id: &str, yes: bool) -> CommandResult {
} }
let deleted = ctx let deleted = ctx
.db() .query_manager()
.delete_folder_by_id(folder_id, &UpdateSource::Sync) .with_tx(|tx| tx.delete_folder_by_id(folder_id, &UpdateSource::Sync))
.map_err(|e| format!("Failed to delete folder: {e}"))?; .map_err(|e| format!("Failed to delete folder: {e}"))?;
println!("Deleted folder: {}", deleted.id); println!("Deleted folder: {}", deleted.id);
@@ -5,16 +5,20 @@ use std::fs;
use std::io::ErrorKind; use std::io::ErrorKind;
use yaak::export::{self, ExportDataParams}; use yaak::export::{self, ExportDataParams};
use yaak::import; use yaak::import;
use yaak_core::WorkspaceContext; use yaak_models::util::{
use yaak_models::util::BatchUpsertResult; BatchUpsertResult, ImportDestination, ImportOrigin, ImportPlanAction, ImportPlanItem,
};
use yaak_plugins::events::{ImportResources, PluginContext}; use yaak_plugins::events::{ImportResources, PluginContext};
type CommandResult<T = ()> = std::result::Result<T, String>; type CommandResult<T = ()> = std::result::Result<T, String>;
pub async fn run_import(ctx: &CliContext, args: ImportArgs) -> i32 { pub async fn run_import(ctx: &CliContext, args: ImportArgs) -> i32 {
match import(ctx, args).await { match import(ctx, args).await {
Ok(result) => { Ok((result, items)) => {
println!("Imported {}", format_counts(&result)); println!("Imported {}", format_counts(&result));
if let Some(skipped) = format_skipped(&items) {
println!("Skipped {skipped}");
}
0 0
} }
Err(error) => { Err(error) => {
@@ -37,7 +41,10 @@ pub fn run_export(ctx: &CliContext, args: ExportArgs) -> i32 {
} }
} }
async fn import(ctx: &CliContext, args: ImportArgs) -> CommandResult<BatchUpsertResult> { async fn import(
ctx: &CliContext,
args: ImportArgs,
) -> CommandResult<(BatchUpsertResult, Vec<ImportPlanItem>)> {
if let Some(workspace_id) = args.workspace_id.as_deref() { if let Some(workspace_id) = args.workspace_id.as_deref() {
ctx.db() ctx.db()
.get_workspace(workspace_id) .get_workspace(workspace_id)
@@ -51,6 +58,7 @@ async fn import(ctx: &CliContext, args: ImportArgs) -> CommandResult<BatchUpsert
.import_data(&plugin_context, &file_contents) .import_data(&plugin_context, &file_contents)
.await .await
.map_err(|e| format!("Failed to import data: {e}"))?; .map_err(|e| format!("Failed to import data: {e}"))?;
let importer = import_result.importer;
let resources = import_result.resources; let resources = import_result.resources;
let workspace_id = args.workspace_id; let workspace_id = args.workspace_id;
if workspace_id.is_none() && resources_need_current_workspace(&resources) { if workspace_id.is_none() && resources_need_current_workspace(&resources) {
@@ -59,15 +67,64 @@ async fn import(ctx: &CliContext, args: ImportArgs) -> CommandResult<BatchUpsert
.to_string(), .to_string(),
); );
} }
let workspace_context = WorkspaceContext { let destination = match workspace_id {
workspace_id, Some(workspace_id) => {
environment_id: None, ImportDestination::ExistingWorkspace { workspace_id, folder_id: None }
cookie_jar_id: None, }
request_id: None, None => ImportDestination::NewWorkspace,
}; };
let imported = import::import_resources(ctx.query_manager(), workspace_context, resources) let plan = import::plan_import_resources(
ctx.query_manager(),
importer,
destination,
resources,
import_result.source_keys,
Some(file_origin(&args.file)),
)
.map_err(|e| format!("Failed to plan import: {e}"))?;
let items = plan.items.clone();
let imported = import::commit_import_plan(ctx.query_manager(), plan)
.map_err(|e| format!("Failed to import data: {e}"))?; .map_err(|e| format!("Failed to import data: {e}"))?;
Ok(imported) Ok((imported, items))
}
fn file_origin(path: &std::path::Path) -> ImportOrigin {
let canonical = fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf());
let label = canonical
.file_name()
.map(|name| name.to_string_lossy().to_string())
.unwrap_or_else(|| path.display().to_string());
ImportOrigin { origin: canonical.to_string_lossy().to_string(), label }
}
/// Summarize what the default selection left untouched during a merging re-import.
fn format_skipped(items: &[ImportPlanItem]) -> Option<String> {
let count = |action: ImportPlanAction| items.iter().filter(|i| i.action == action).count();
let plural = |n: usize| if n == 1 { "" } else { "s" };
let mut parts = Vec::new();
let deletions = count(ImportPlanAction::Delete);
if deletions > 0 {
parts.push(format!("{deletions} removed from source (not deleted locally)"));
}
let conflicts = count(ImportPlanAction::Conflict);
if conflicts > 0 {
parts.push(format!("{conflicts} conflict{} (kept local changes)", plural(conflicts)));
}
let keep_local = count(ImportPlanAction::KeepLocal);
if keep_local > 0 {
parts.push(format!("{keep_local} with local edits"));
}
let ignored = count(ImportPlanAction::Ignored);
if ignored > 0 {
parts.push(format!("{ignored} ignored"));
}
let unchanged = count(ImportPlanAction::Unchanged);
if unchanged > 0 {
parts.push(format!("{unchanged} unchanged"));
}
if parts.is_empty() { None } else { Some(parts.join(", ")) }
} }
fn export(ctx: &CliContext, args: ExportArgs) -> CommandResult<usize> { fn export(ctx: &CliContext, args: ExportArgs) -> CommandResult<usize> {
+15 -16
View File
@@ -348,17 +348,19 @@ async fn install_from_directory(context: &CliContext, source: &str) -> CommandRe
ui::info(&format!("Installing plugin from directory {}", plugin_dir.display())); ui::info(&format!("Installing plugin from directory {}", plugin_dir.display()));
let plugin = context let plugin = context
.db() .query_manager()
.upsert_plugin( .with_tx(|tx| {
&Plugin { tx.upsert_plugin(
directory: plugin_dir_str, &Plugin {
url: None, directory: plugin_dir_str,
enabled: true, url: None,
source: PluginSource::Filesystem, enabled: true,
..Default::default() source: PluginSource::Filesystem,
}, ..Default::default()
&UpdateSource::Background, },
) &UpdateSource::Background,
)
})
.map_err(|err| format!("Failed to save plugin in database: {err}"))?; .map_err(|err| format!("Failed to save plugin in database: {err}"))?;
let plugin_context = PluginContext::new(Some("cli".to_string()), None); let plugin_context = PluginContext::new(Some("cli".to_string()), None);
@@ -883,11 +885,8 @@ mod tests {
fs::create_dir_all(root.join("build")).expect("create build"); fs::create_dir_all(root.join("build")).expect("create build");
fs::create_dir_all(root.join("vendor")).expect("create vendor"); fs::create_dir_all(root.join("vendor")).expect("create vendor");
fs::write(root.join("vendor/core_bg.wasm"), "asset").expect("write asset"); fs::write(root.join("vendor/core_bg.wasm"), "asset").expect("write asset");
fs::write( fs::write(root.join("package.json"), r#"{"yaak":{"buildAssets":["vendor/core_bg.wasm"]}}"#)
root.join("package.json"), .expect("write package.json");
r#"{"yaak":{"buildAssets":["vendor/core_bg.wasm"]}}"#,
)
.expect("write package.json");
copy_build_assets(root).expect("copy assets"); copy_build_assets(root).expect("copy assets");
+8 -8
View File
@@ -424,8 +424,8 @@ fn create(
)?; )?;
let created = ctx let created = ctx
.db() .query_manager()
.upsert_http_request(&request, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_http_request(&request, &UpdateSource::Sync))
.map_err(|e| format!("Failed to create request: {e}"))?; .map_err(|e| format!("Failed to create request: {e}"))?;
println!("Created request: {}", created.id); println!("Created request: {}", created.id);
@@ -443,8 +443,8 @@ fn create(
} }
let created = ctx let created = ctx
.db() .query_manager()
.upsert_http_request(&request, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_http_request(&request, &UpdateSource::Sync))
.map_err(|e| format!("Failed to create request: {e}"))?; .map_err(|e| format!("Failed to create request: {e}"))?;
println!("Created request: {}", created.id); println!("Created request: {}", created.id);
@@ -463,8 +463,8 @@ fn update(ctx: &CliContext, json: Option<String>, json_input: Option<String>) ->
let updated = apply_merge_patch(&existing, &patch, &id, "request update")?; let updated = apply_merge_patch(&existing, &patch, &id, "request update")?;
let saved = ctx let saved = ctx
.db() .query_manager()
.upsert_http_request(&updated, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_http_request(&updated, &UpdateSource::Sync))
.map_err(|e| format!("Failed to update request: {e}"))?; .map_err(|e| format!("Failed to update request: {e}"))?;
println!("Updated request: {}", saved.id); println!("Updated request: {}", saved.id);
@@ -487,8 +487,8 @@ fn delete(ctx: &CliContext, request_id: &str, yes: bool) -> CommandResult {
} }
let deleted = ctx let deleted = ctx
.db() .query_manager()
.delete_http_request_by_id(request_id, &UpdateSource::Sync) .with_tx(|tx| tx.delete_http_request_by_id(request_id, &UpdateSource::Sync))
.map_err(|e| format!("Failed to delete request: {e}"))?; .map_err(|e| format!("Failed to delete request: {e}"))?;
println!("Deleted request: {}", deleted.id); println!("Deleted request: {}", deleted.id);
Ok(()) Ok(())
+6 -4
View File
@@ -118,8 +118,8 @@ fn delete(ctx: &CliContext, id: &str, yes: bool) -> CommandResult {
return Ok(()); return Ok(());
} }
let count = ctx let count = ctx
.db() .query_manager()
.delete_all_http_responses_for_request(id, &UpdateSource::Sync) .with_tx(|tx| tx.delete_all_http_responses_for_request(id, &UpdateSource::Sync))
.map_err(|e| format!("Failed to delete responses: {e}"))?; .map_err(|e| format!("Failed to delete responses: {e}"))?;
println!("Deleted {count} responses for request {id}"); println!("Deleted {count} responses for request {id}");
return Ok(()); return Ok(());
@@ -131,8 +131,10 @@ fn delete(ctx: &CliContext, id: &str, yes: bool) -> CommandResult {
return Ok(()); return Ok(());
} }
let count = ctx let count = ctx
.db() .query_manager()
.delete_all_http_responses_for_workspace(&workspace_id, &UpdateSource::Sync) .with_tx(|tx| {
tx.delete_all_http_responses_for_workspace(&workspace_id, &UpdateSource::Sync)
})
.map_err(|e| format!("Failed to delete responses: {e}"))?; .map_err(|e| format!("Failed to delete responses: {e}"))?;
println!("Deleted {count} responses for workspace {workspace_id}"); println!("Deleted {count} responses for workspace {workspace_id}");
Ok(()) Ok(())
+10 -8
View File
@@ -84,8 +84,8 @@ fn create(
.map_err(|e| format!("Failed to parse workspace create JSON: {e}"))?; .map_err(|e| format!("Failed to parse workspace create JSON: {e}"))?;
let created = ctx let created = ctx
.db() .query_manager()
.upsert_workspace(&workspace, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_workspace(&workspace, &UpdateSource::Sync))
.map_err(|e| format!("Failed to create workspace: {e}"))?; .map_err(|e| format!("Failed to create workspace: {e}"))?;
println!("Created workspace: {}", created.id); println!("Created workspace: {}", created.id);
return Ok(()); return Ok(());
@@ -97,8 +97,8 @@ fn create(
let workspace = Workspace { name, ..Default::default() }; let workspace = Workspace { name, ..Default::default() };
let created = ctx let created = ctx
.db() .query_manager()
.upsert_workspace(&workspace, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_workspace(&workspace, &UpdateSource::Sync))
.map_err(|e| format!("Failed to create workspace: {e}"))?; .map_err(|e| format!("Failed to create workspace: {e}"))?;
println!("Created workspace: {}", created.id); println!("Created workspace: {}", created.id);
Ok(()) Ok(())
@@ -115,8 +115,8 @@ fn update(ctx: &CliContext, json: Option<String>, json_input: Option<String>) ->
let updated = apply_merge_patch(&existing, &patch, &id, "workspace update")?; let updated = apply_merge_patch(&existing, &patch, &id, "workspace update")?;
let saved = ctx let saved = ctx
.db() .query_manager()
.upsert_workspace(&updated, &UpdateSource::Sync) .with_tx(|tx| tx.upsert_workspace(&updated, &UpdateSource::Sync))
.map_err(|e| format!("Failed to update workspace: {e}"))?; .map_err(|e| format!("Failed to update workspace: {e}"))?;
println!("Updated workspace: {}", saved.id); println!("Updated workspace: {}", saved.id);
@@ -130,8 +130,10 @@ fn delete(ctx: &CliContext, workspace_id: &str, yes: bool) -> CommandResult {
} }
let deleted = ctx let deleted = ctx
.db() .query_manager()
.delete_workspace_by_id(workspace_id, &UpdateSource::Sync, ctx.blob_manager()) .with_tx(|tx| {
tx.delete_workspace_by_id(workspace_id, &UpdateSource::Sync, ctx.blob_manager())
})
.map_err(|e| format!("Failed to delete workspace: {e}"))?; .map_err(|e| format!("Failed to delete workspace: {e}"))?;
println!("Deleted workspace: {}", deleted.id); println!("Deleted workspace: {}", deleted.id);
Ok(()) Ok(())
+3 -5
View File
@@ -51,11 +51,9 @@ impl CliContext {
}; };
// Guest: the desktop may have this DB open, so only what's safe beside a live session // Guest: the desktop may have this DB open, so only what's safe beside a live session
let _ = yaak_lifecycle::on_launch( let _ = query_manager.with_tx(|tx| {
&yaak_lifecycle::Host::guest(), yaak_lifecycle::on_launch(&yaak_lifecycle::Host::guest(), tx, &blob_manager)
&query_manager.connect(), });
&blob_manager,
);
let encryption_manager = Arc::new(EncryptionManager::new(query_manager.clone(), app_id)); let encryption_manager = Arc::new(EncryptionManager::new(query_manager.clone(), app_id));
+1 -1
View File
@@ -13,7 +13,6 @@ use tokio::task::JoinHandle;
use yaak::plugin_events::{ use yaak::plugin_events::{
GroupedPluginEvent, HostRequest, SharedPluginEventContext, handle_shared_plugin_event, GroupedPluginEvent, HostRequest, SharedPluginEventContext, handle_shared_plugin_event,
}; };
use yaak_models::render::{render_grpc_request, render_http_request};
use yaak::response_body::FileResponseBodyStore; use yaak::response_body::FileResponseBodyStore;
use yaak::send::{SendHttpRequestWithPluginsParams, send_http_request_with_plugins}; use yaak::send::{SendHttpRequestWithPluginsParams, send_http_request_with_plugins};
use yaak_crypto::manager::EncryptionManager; use yaak_crypto::manager::EncryptionManager;
@@ -24,6 +23,7 @@ use yaak_models::models::Environment;
use yaak_models::queries::any_request::AnyRequest; use yaak_models::queries::any_request::AnyRequest;
use yaak_models::query_manager::QueryManager; use yaak_models::query_manager::QueryManager;
use yaak_models::render::make_vars_hashmap; use yaak_models::render::make_vars_hashmap;
use yaak_models::render::{render_grpc_request, render_http_request};
use yaak_models::util::UpdateSource; use yaak_models::util::UpdateSource;
use yaak_plugins::events::{ use yaak_plugins::events::{
EmptyPayload, ErrorResponse, FormInput, GetCookieValueResponse, InternalEvent, EmptyPayload, ErrorResponse, FormInput, GetCookieValueResponse, InternalEvent,
+5 -10
View File
@@ -40,8 +40,7 @@ pub fn seed_workspace(data_dir: &Path, workspace_id: &str) {
}; };
query_manager(data_dir) query_manager(data_dir)
.connect() .with_tx(|tx| tx.upsert_workspace(&workspace, &UpdateSource::Sync))
.upsert_workspace(&workspace, &UpdateSource::Sync)
.expect("Failed to seed workspace"); .expect("Failed to seed workspace");
} }
@@ -56,8 +55,7 @@ pub fn seed_request(data_dir: &Path, workspace_id: &str, request_id: &str) {
}; };
query_manager(data_dir) query_manager(data_dir)
.connect() .with_tx(|tx| tx.upsert_http_request(&request, &UpdateSource::Sync))
.upsert_http_request(&request, &UpdateSource::Sync)
.expect("Failed to seed request"); .expect("Failed to seed request");
} }
@@ -70,8 +68,7 @@ pub fn seed_folder(data_dir: &Path, workspace_id: &str, folder_id: &str) {
}; };
query_manager(data_dir) query_manager(data_dir)
.connect() .with_tx(|tx| tx.upsert_folder(&folder, &UpdateSource::Sync))
.upsert_folder(&folder, &UpdateSource::Sync)
.expect("Failed to seed folder"); .expect("Failed to seed folder");
} }
@@ -85,8 +82,7 @@ pub fn seed_grpc_request(data_dir: &Path, workspace_id: &str, request_id: &str)
}; };
query_manager(data_dir) query_manager(data_dir)
.connect() .with_tx(|tx| tx.upsert_grpc_request(&request, &UpdateSource::Sync))
.upsert_grpc_request(&request, &UpdateSource::Sync)
.expect("Failed to seed gRPC request"); .expect("Failed to seed gRPC request");
} }
@@ -100,7 +96,6 @@ pub fn seed_websocket_request(data_dir: &Path, workspace_id: &str, request_id: &
}; };
query_manager(data_dir) query_manager(data_dir)
.connect() .with_tx(|tx| tx.upsert_websocket_request(&request, &UpdateSource::Sync))
.upsert_websocket_request(&request, &UpdateSource::Sync)
.expect("Failed to seed WebSocket request"); .expect("Failed to seed WebSocket request");
} }
@@ -4,6 +4,7 @@ use common::{cli_cmd, parse_created_id, query_manager, seed_request};
use predicates::str::contains; use predicates::str::contains;
use serde_json::Value; use serde_json::Value;
use tempfile::TempDir; use tempfile::TempDir;
use yaak_models::util::UpdateSource;
#[test] #[test]
fn export_writes_yaak_workspace_file() { fn export_writes_yaak_workspace_file() {
@@ -81,14 +82,21 @@ fn import_reads_yaak_workspace_file() {
let query_manager = query_manager(data_dir); let query_manager = query_manager(data_dir);
let db = query_manager.connect(); let db = query_manager.connect();
assert_eq!( let workspaces = db.list_workspaces().expect("list imported workspaces");
db.get_workspace("wrk_import").expect("workspace imported").name, let workspace = workspaces
"Imported Workspace" .iter()
); .find(|workspace| workspace.name == "Imported Workspace")
assert_eq!( .expect("workspace imported");
db.get_http_request("req_import").expect("request imported").url, assert_ne!(workspace.id, "wrk_import");
"https://example.com"
); let requests = db.list_http_requests(&workspace.id).expect("list imported requests");
let request = requests
.iter()
.find(|request| request.name == "Imported Request")
.expect("request imported");
assert_ne!(request.id, "req_import");
assert_eq!(request.workspace_id, workspace.id);
assert_eq!(request.url, "https://example.com");
} }
fn write_postman_environment_fixture(path: &std::path::Path) { fn write_postman_environment_fixture(path: &std::path::Path) {
@@ -153,10 +161,164 @@ fn import_postman_environment_uses_workspace_id() {
let query_manager = query_manager(data_dir); let query_manager = query_manager(data_dir);
let db = query_manager.connect(); let db = query_manager.connect();
let environments = let environments = db.list_environments(&workspace_id).expect("list imported environments");
db.list_environments_ensure_base(&workspace_id).expect("list imported environments");
let imported_environment = let imported_environment =
environments.iter().find(|e| e.name == "Local").expect("postman environment imported"); environments.iter().find(|e| e.name == "Local").expect("postman environment imported");
assert_eq!(imported_environment.workspace_id, workspace_id); assert_eq!(imported_environment.workspace_id, workspace_id);
} }
fn write_linked_fixture(path: &std::path::Path, requests: &[(&str, &str, &str)]) {
let requests = requests
.iter()
.map(|(id, name, url)| {
format!(
r#"{{ "model": "http_request", "id": "{id}", "workspaceId": "wrk_link",
"name": "{name}", "method": "GET", "url": "{url}" }}"#
)
})
.collect::<Vec<_>>()
.join(",");
std::fs::write(
path,
format!(
r#"{{
"yaakVersion": "test",
"yaakSchema": 4,
"resources": {{
"workspaces": [{{ "model": "workspace", "id": "wrk_link", "name": "Linked Workspace" }}],
"httpRequests": [{requests}]
}}
}}"#
),
)
.expect("write linked fixture");
}
#[test]
fn re_import_merges_into_linked_workspace() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let data_dir = temp_dir.path();
let import_path = temp_dir.path().join("linked.json");
write_linked_fixture(
&import_path,
&[
("req_a", "Request A", "https://example.com/a"),
("req_b", "Request B", "https://example.com/b"),
],
);
cli_cmd(data_dir)
.args([
"import",
import_path.to_str().expect("import path is utf-8"),
])
.assert()
.success()
.stdout(contains("Imported 1 workspace, 2 HTTP requests"));
let workspace_id = {
let query_manager = query_manager(data_dir);
let db = query_manager.connect();
db.list_workspaces()
.expect("list workspaces")
.into_iter()
.find(|w| w.name == "Linked Workspace")
.expect("workspace imported")
.id
};
// The source doc changes A, drops B, and adds C. The default selection applies the
// update and the create but leaves the removal as an offer.
write_linked_fixture(
&import_path,
&[
("req_a", "Request A", "https://example.com/a-v2"),
("req_c", "Request C", "https://example.com/c"),
],
);
cli_cmd(data_dir)
.args([
"import",
import_path.to_str().expect("import path is utf-8"),
"--workspace-id",
&workspace_id,
])
.assert()
.success()
.stdout(contains("Imported 2 HTTP requests"))
.stdout(contains("Skipped 1 removed from source"));
let query_manager = query_manager(data_dir);
let db = query_manager.connect();
let requests = db.list_http_requests(&workspace_id).expect("list requests");
assert_eq!(requests.len(), 3, "merge must not duplicate: {requests:?}");
assert_eq!(
requests.iter().find(|r| r.name == "Request A").expect("request A").url,
"https://example.com/a-v2"
);
assert!(requests.iter().any(|r| r.name == "Request B"), "removal must not auto-apply");
assert!(requests.iter().any(|r| r.name == "Request C"));
}
#[test]
fn re_import_leaves_deleted_resources_alone() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let data_dir = temp_dir.path();
let import_path = temp_dir.path().join("linked.json");
write_linked_fixture(
&import_path,
&[
("req_a", "Request A", "https://example.com/a"),
("req_b", "Request B", "https://example.com/b"),
],
);
cli_cmd(data_dir)
.args([
"import",
import_path.to_str().expect("import path is utf-8"),
])
.assert()
.success();
let workspace_id = {
let query_manager = query_manager(data_dir);
let db = query_manager.connect();
let workspace_id = db
.list_workspaces()
.expect("list workspaces")
.into_iter()
.find(|w| w.name == "Linked Workspace")
.expect("workspace imported")
.id;
let request_b = db
.list_http_requests(&workspace_id)
.expect("list requests")
.into_iter()
.find(|r| r.name == "Request B")
.expect("request B imported");
drop(db);
query_manager
.with_tx(|tx| tx.delete_http_request_by_id(&request_b.id, &UpdateSource::Sync))
.expect("delete request B");
workspace_id
};
cli_cmd(data_dir)
.args([
"import",
import_path.to_str().expect("import path is utf-8"),
"--workspace-id",
&workspace_id,
])
.assert()
.success()
.stdout(contains("Skipped 1 ignored"));
let query_manager = query_manager(data_dir);
let requests =
query_manager.connect().list_http_requests(&workspace_id).expect("list requests");
assert_eq!(requests.len(), 1, "a deleted request must not come back: {requests:?}");
assert_eq!(requests[0].name, "Request A");
}
+1 -2
View File
@@ -25,8 +25,7 @@ fn top_level_send_folder_sends_http_requests_and_prints_summary() {
..Default::default() ..Default::default()
}; };
query_manager(data_dir) query_manager(data_dir)
.connect() .with_tx(|tx| tx.upsert_http_request(&request, &UpdateSource::Sync))
.upsert_http_request(&request, &UpdateSource::Sync)
.expect("Failed to seed folder request"); .expect("Failed to seed folder request");
cli_cmd(data_dir) cli_cmd(data_dir)
+111 -24
View File
@@ -1,48 +1,135 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type Cookie = { name: string, value: string, domain: CookieDomain, expires: CookieExpires, path: string, secure: boolean, httpOnly: boolean, sameSite: CookieSameSite | null, }; export type Cookie = {
name: string;
value: string;
domain: CookieDomain;
expires: CookieExpires;
path: string;
secure: boolean;
httpOnly: boolean;
sameSite: CookieSameSite | null;
};
export type CookieDomain = { "HostOnly": string } | { "Suffix": string } | "NotPresent" | "Empty"; export type CookieDomain = { HostOnly: string } | { Suffix: string } | "NotPresent" | "Empty";
export type CookieExpires = { "AtUtc": string } | "SessionEnd"; export type CookieExpires = { AtUtc: string } | "SessionEnd";
export type CookieSameSite = "Strict" | "Lax" | "None"; export type CookieSameSite = "Strict" | "Lax" | "None";
export type HttpRequest = { model: "http_request", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authentication: Record<string, any>, authenticationType: string | null, body: Record<string, any>, bodyType: string | null, description: string, headers: Array<HttpRequestHeader>, method: string, name: string, sortPriority: number, url: string, export type HttpRequest = {
/** model: "http_request";
* URL parameters used for both path placeholders (`:id`) and query string entries. id: string;
*/ createdAt: string;
urlParameters: Array<HttpUrlParameter>, settingSendCookies: InheritedBoolSetting, settingStoreCookies: InheritedBoolSetting, settingValidateCertificates: InheritedBoolSetting, settingFollowRedirects: InheritedBoolSetting, settingRequestTimeout: InheritedIntSetting, }; updatedAt: string;
workspaceId: string;
folderId: string | null;
authentication: Record<string, any>;
authenticationType: string | null;
body: Record<string, any>;
bodyType: string | null;
description: string;
headers: Array<HttpRequestHeader>;
method: string;
name: string;
sortPriority: number;
url: string;
/**
* URL parameters used for both path placeholders (`:id`) and query string entries.
*/
urlParameters: Array<HttpUrlParameter>;
settingSendCookies: InheritedBoolSetting;
settingStoreCookies: InheritedBoolSetting;
settingValidateCertificates: InheritedBoolSetting;
settingFollowRedirects: InheritedBoolSetting;
settingRequestTimeout: InheritedIntSetting;
settingHttpVersion: InheritedHttpVersionSetting;
};
export type HttpRequestHeader = { enabled?: boolean, name: string, value: string, id?: string, }; export type HttpRequestHeader = { enabled?: boolean; name: string; value: string; id?: string };
/** /**
* Serializable representation of HTTP response events for DB storage. * Serializable representation of HTTP response events for DB storage.
* This mirrors `yaak_http::sender::HttpResponseEvent` but with serde support. * This mirrors `yaak_http::sender::HttpResponseEvent` but with serde support.
* The `From` impl is in yaak-http to avoid circular dependencies. * The `From` impl is in yaak-http to avoid circular dependencies.
*/ */
export type HttpResponseEventData = { "type": "setting", name: string, value: string, source_model?: string, source_id?: string, source_name?: string, } | { "type": "info", message: string, } | { "type": "redirect", url: string, status: number, behavior: string, dropped_body: boolean, dropped_headers: Array<string>, } | { "type": "send_url", method: string, scheme: string, username: string, password: string, host: string, port: number, path: string, query: string, fragment: string, } | { "type": "receive_url", version: string, status: string, } | { "type": "header_up", name: string, value: string, } | { "type": "header_down", name: string, value: string, } | { "type": "chunk_sent", bytes: number, } | { "type": "chunk_received", bytes: number, } | { "type": "dns_resolved", hostname: string, addresses: Array<string>, duration: bigint, overridden: boolean, }; export type HttpResponseEventData =
| {
type: "setting";
name: string;
value: string;
source_model?: string;
source_id?: string;
source_name?: string;
}
| { type: "info"; message: string }
| {
type: "redirect";
url: string;
status: number;
behavior: string;
dropped_body: boolean;
dropped_headers: Array<string>;
}
| {
type: "send_url";
method: string;
scheme: string;
username: string;
password: string;
host: string;
port: number;
path: string;
query: string;
fragment: string;
}
| { type: "receive_url"; version: string; status: string }
| { type: "header_up"; name: string; value: string }
| { type: "header_down"; name: string; value: string }
| { type: "chunk_sent"; bytes: number }
| { type: "chunk_received"; bytes: number }
| {
type: "dns_resolved";
hostname: string;
addresses: Array<string>;
duration: bigint;
overridden: boolean;
};
export type HttpResponseHeader = { name: string, value: string, }; export type HttpResponseHeader = { name: string; value: string };
/** /**
* The resolved send settings, values only: what an executor has to obey, with the sources * The resolved send settings, values only: what an executor has to obey, with the sources
* (which model each came from) left behind in [`ResolvedHttpRequestSettings`]. This is what * (which model each came from) left behind in [`ResolvedHttpRequestSettings`]. This is what
* crosses from a tab to the Yaak server, and what the server reads. * crosses from a tab to the Yaak server, and what the server reads.
*/ */
export type HttpSendSettings = { validateCertificates: boolean, followRedirects: boolean, export type HttpSendSettings = {
/** validateCertificates: boolean;
* Milliseconds. Zero or negative means no timeout. followRedirects: boolean;
*/ /**
timeoutMs: number, sendCookies: boolean, storeCookies: boolean, }; * Milliseconds. Zero or negative means no timeout.
*/
timeoutMs: number;
sendCookies: boolean;
storeCookies: boolean;
httpVersion: HttpVersion;
};
export type HttpUrlParameter = { enabled?: boolean, export type HttpUrlParameter = {
/** enabled?: boolean;
* Colon-prefixed parameters are treated as path parameters if they match, like `/users/:id` /**
* Other entries are appended as query parameters * Colon-prefixed parameters are treated as path parameters if they match, like `/users/:id`
*/ * Other entries are appended as query parameters
name: string, value: string, id?: string, }; */
name: string;
value: string;
id?: string;
};
export type InheritedBoolSetting = { enabled?: boolean, value: boolean, }; export type HttpVersion = "auto" | "http1" | "http2";
export type InheritedIntSetting = { enabled?: boolean, value: number, }; export type InheritedBoolSetting = { enabled?: boolean; value: boolean };
export type InheritedHttpVersionSetting = { enabled?: boolean; value: HttpVersion };
export type InheritedIntSetting = { enabled?: boolean; value: number };
+2 -5
View File
@@ -145,11 +145,8 @@ async fn cache_control(req: Request, next: Next) -> Response {
.get(header::CONTENT_TYPE) .get(header::CONTENT_TYPE)
.and_then(|v| v.to_str().ok()) .and_then(|v| v.to_str().ok())
.is_some_and(|v| v.starts_with("text/html")); .is_some_and(|v| v.starts_with("text/html"));
let value = if hashed_name && !is_html { let value =
"public, max-age=31536000, immutable" if hashed_name && !is_html { "public, max-age=31536000, immutable" } else { "no-cache" };
} else {
"no-cache"
};
res.headers_mut().insert(header::CACHE_CONTROL, HeaderValue::from_static(value)); res.headers_mut().insert(header::CACHE_CONTROL, HeaderValue::from_static(value));
res res
} }
+1
View File
@@ -157,6 +157,7 @@ impl PreparedSend {
let (client, resolver) = HttpConnectionOptions { let (client, resolver) = HttpConnectionOptions {
id: uuid::Uuid::new_v4().to_string(), id: uuid::Uuid::new_v4().to_string(),
validate_certificates: self.settings.validate_certificates, validate_certificates: self.settings.validate_certificates,
http_version: self.settings.http_version,
// The proxy connects directly. Going through a system proxy would move DNS, and // The proxy connects directly. Going through a system proxy would move DNS, and
// therefore the address check, somewhere this process can't see. // therefore the address check, somewhere this process can't see.
proxy: HttpConnectionProxySetting::Disabled, proxy: HttpConnectionProxySetting::Disabled,
+28 -6
View File
@@ -1,15 +1,37 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type PluginUpdateInfo = { name: string, currentVersion: string, latestVersion: string, }; export type PluginUpdateInfo = { name: string; currentVersion: string; latestVersion: string };
export type PluginUpdateNotification = { updateCount: number, plugins: Array<PluginUpdateInfo>, }; export type PluginUpdateNotification = { updateCount: number; plugins: Array<PluginUpdateInfo> };
export type UpdateInfo = { replyEventId: string, version: string, downloaded: boolean, }; export type UpdateInfo = {
replyEventId: string;
version: string;
downloaded: boolean;
/**
* How this update gets applied. Anything but `Integrated` means the app can't do it
* itself and the user is told how to update instead.
*/
install: UpdateInstall;
};
export type UpdateResponse = { "type": "ack" } | { "type": "action", action: UpdateResponseAction, }; /**
* How an update can be applied to this install.
*/
export type UpdateInstall = "integrated" | "flatpak" | "manual";
export type UpdateResponse = { type: "ack" } | { type: "action"; action: UpdateResponseAction };
export type UpdateResponseAction = "install" | "skip"; 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 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, }; export type YaakNotificationAction = { label: string; url: string };
+2 -4
View File
@@ -3,11 +3,10 @@ use std::collections::BTreeMap;
use crate::PluginContextExt; use crate::PluginContextExt;
use crate::error::Result; use crate::error::Result;
use KeyAndValueRef::{Ascii, Binary}; use KeyAndValueRef::{Ascii, Binary};
use tauri::{Manager, Runtime, WebviewWindow}; use tauri::{Runtime, WebviewWindow};
use yaak_grpc::{KeyAndValueRef, MetadataMap}; use yaak_grpc::{KeyAndValueRef, MetadataMap};
use yaak_models::models::GrpcRequest; use yaak_models::models::GrpcRequest;
use yaak_plugins::events::{CallHttpAuthenticationRequest, HttpHeader}; use yaak_plugins::events::{CallHttpAuthenticationRequest, HttpHeader};
use yaak_plugins::manager::PluginManager;
pub(crate) fn metadata_to_map(metadata: MetadataMap) -> BTreeMap<String, String> { pub(crate) fn metadata_to_map(metadata: MetadataMap) -> BTreeMap<String, String> {
let mut entries = BTreeMap::new(); let mut entries = BTreeMap::new();
@@ -20,13 +19,12 @@ pub(crate) fn metadata_to_map(metadata: MetadataMap) -> BTreeMap<String, String>
entries entries
} }
pub(crate) async fn build_metadata<R: Runtime>( pub(crate) async fn build_metadata<R: Runtime>(
window: &WebviewWindow<R>, window: &WebviewWindow<R>,
request: &GrpcRequest, request: &GrpcRequest,
authentication_context_id: &str, authentication_context_id: &str,
) -> Result<BTreeMap<String, String>> { ) -> Result<BTreeMap<String, String>> {
let plugin_manager = window.state::<PluginManager>(); let plugin_manager = crate::plugins_ext::plugin_manager(window).await?;
let mut metadata = BTreeMap::new(); let mut metadata = BTreeMap::new();
// Add the rest of metadata // Add the rest of metadata
@@ -14,7 +14,6 @@ use yaak_http::manager::HttpConnectionManager;
use yaak_models::models::{CookieJar, Environment, HttpRequest, HttpResponse, HttpResponseState}; use yaak_models::models::{CookieJar, Environment, HttpRequest, HttpResponse, HttpResponseState};
use yaak_models::util::UpdateSource; use yaak_models::util::UpdateSource;
use yaak_plugins::events::PluginContext; use yaak_plugins::events::PluginContext;
use yaak_plugins::manager::PluginManager;
/// Context for managing response state during HTTP transactions. /// Context for managing response state during HTTP transactions.
/// Handles both persisted responses (stored in DB) and ephemeral responses (in-memory only). /// Handles both persisted responses (stored in DB) and ephemeral responses (in-memory only).
@@ -149,7 +148,7 @@ async fn send_http_request_inner<R: Runtime>(
response_ctx: &mut ResponseContext<R>, response_ctx: &mut ResponseContext<R>,
) -> Result<SentHttpRequest> { ) -> Result<SentHttpRequest> {
let app_handle = window.app_handle().clone(); let app_handle = window.app_handle().clone();
let plugin_manager = Arc::new((*app_handle.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(&app_handle).await?);
let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone()); let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone());
let connection_manager = app_handle.state::<HttpConnectionManager>(); let connection_manager = app_handle.state::<HttpConnectionManager>();
let environment_id = environment.map(|e| e.id); let environment_id = environment.map(|e| e.id);
@@ -178,4 +177,3 @@ async fn send_http_request_inner<R: Runtime>(
Ok(SentHttpRequest { response: result.response, body: result.response_body }) Ok(SentHttpRequest { response: result.response, body: result.response_body })
} }
+53 -22
View File
@@ -4,53 +4,84 @@ use crate::models_ext::QueryManagerExt;
use std::fs::read_to_string; use std::fs::read_to_string;
use std::io::ErrorKind; use std::io::ErrorKind;
use tauri::{Manager, Runtime, WebviewWindow}; use tauri::{Manager, Runtime, WebviewWindow};
use yaak::import::{self, ImportDataParams}; use yaak::import::{self, PlanImportDataParams};
use yaak_api::{ApiClientKind, yaak_api_client}; use yaak_api::{ApiClientKind, yaak_api_client};
use yaak_core::WorkspaceContext; use yaak_models::util::{BatchUpsertResult, ImportDestination, ImportOrigin, ImportPlan};
use yaak_models::util::BatchUpsertResult;
use yaak_plugins::manager::PluginManager;
use yaak_tauri_utils::window::WorkspaceWindowTrait;
pub(crate) async fn import_data<R: Runtime>( pub(crate) async fn import_data<R: Runtime>(
window: &WebviewWindow<R>, window: &WebviewWindow<R>,
file_path: &str, file_path: &str,
origin: Option<ImportOrigin>,
) -> Result<BatchUpsertResult> { ) -> Result<BatchUpsertResult> {
let contents = read_import_file(file_path)?; let contents = read_import_file(file_path)?;
import_contents(window, &contents).await let plan =
plan_import_contents(window, &contents, ImportDestination::NewWorkspace, origin).await?;
commit_import(window, plan)
} }
pub(crate) async fn import_url<R: Runtime>( pub(crate) async fn plan_import_data<R: Runtime>(
window: &WebviewWindow<R>,
file_path: &str,
destination: ImportDestination,
) -> Result<ImportPlan> {
let contents = read_import_file(file_path)?;
plan_import_contents(window, &contents, destination, Some(file_origin(file_path))).await
}
pub(crate) async fn plan_import_url<R: Runtime>(
window: &WebviewWindow<R>, window: &WebviewWindow<R>,
url: &str, url: &str,
) -> Result<BatchUpsertResult> { destination: ImportDestination,
let contents = fetch_import_url(window, url).await?; ) -> Result<ImportPlan> {
import_contents(window, &contents).await let url = normalize_import_url(url)?;
let contents = fetch_import_url(window, &url).await?;
plan_import_contents(window, &contents, destination, Some(url_origin(&url))).await
} }
async fn import_contents<R: Runtime>( async fn plan_import_contents<R: Runtime>(
window: &WebviewWindow<R>, window: &WebviewWindow<R>,
contents: &str, contents: &str,
) -> Result<BatchUpsertResult> { destination: ImportDestination,
let plugin_manager = window.state::<PluginManager>(); origin: Option<ImportOrigin>,
) -> Result<ImportPlan> {
let plugin_manager = crate::plugins_ext::plugin_manager(window).await?;
let query_manager = window.db_manager(); let query_manager = window.db_manager();
let plugin_context = window.plugin_context(); let plugin_context = window.plugin_context();
let workspace_context = WorkspaceContext {
workspace_id: window.workspace_id(),
environment_id: window.environment_id(),
cookie_jar_id: window.cookie_jar_id(),
request_id: None,
};
Ok(import::import_data(ImportDataParams { Ok(import::plan_import_data(PlanImportDataParams {
query_manager: &query_manager, query_manager: &query_manager,
plugin_manager: &plugin_manager, plugin_manager: &plugin_manager,
plugin_context: &plugin_context, plugin_context: &plugin_context,
workspace_context, destination,
contents, contents,
origin,
}) })
.await?) .await?)
} }
/// Canonicalize so re-importing the same file through a different spelling of its path still
/// matches the linked source.
pub(crate) fn file_origin(file_path: &str) -> ImportOrigin {
let path = std::path::Path::new(file_path);
let canonical = std::fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf());
let label = canonical
.file_name()
.map(|name| name.to_string_lossy().to_string())
.unwrap_or_else(|| file_path.to_string());
ImportOrigin { origin: canonical.to_string_lossy().to_string(), label }
}
pub(crate) fn url_origin(url: &str) -> ImportOrigin {
ImportOrigin { origin: url.to_string(), label: url.to_string() }
}
pub(crate) fn commit_import<R: Runtime>(
window: &WebviewWindow<R>,
plan: ImportPlan,
) -> Result<BatchUpsertResult> {
Ok(import::commit_import_plan(&window.db_manager(), plan)?)
}
/// Download an importable document (OpenAPI, Postman, Insomnia, …) so it can be fed to the same /// Download an importable document (OpenAPI, Postman, Insomnia, …) so it can be fed to the same
/// pipeline as a file on disk. /// pipeline as a file on disk.
/// ///
@@ -79,7 +110,7 @@ async fn fetch_import_url<R: Runtime>(window: &WebviewWindow<R>, url: &str) -> R
.map_err(|err| Error::GenericError(format!("Failed to read response from {url}: {err}"))) .map_err(|err| Error::GenericError(format!("Failed to read response from {url}: {err}")))
} }
fn normalize_import_url(url: &str) -> Result<String> { pub(crate) fn normalize_import_url(url: &str) -> Result<String> {
let url = url.trim(); let url = url.trim();
if url.is_empty() { if url.is_empty() {
return Err(Error::GenericError("Import URL must not be empty".to_string())); return Err(Error::GenericError("Import URL must not be empty".to_string()));
+326 -285
View File
@@ -4,7 +4,7 @@ use crate::error::Error::GenericError;
use crate::error::Result; use crate::error::Result;
use crate::grpc::{build_metadata, metadata_to_map}; use crate::grpc::{build_metadata, metadata_to_map};
use crate::http_request::send_http_request; use crate::http_request::send_http_request;
use crate::import::{import_data, import_url}; use crate::import::{commit_import, plan_import_data, plan_import_url};
use crate::models_ext::{BlobManagerExt, QueryManagerExt}; use crate::models_ext::{BlobManagerExt, QueryManagerExt};
use crate::notifications::YaakNotifier; use crate::notifications::YaakNotifier;
use crate::render::{render_grpc_request, render_template}; use crate::render::{render_grpc_request, render_template};
@@ -29,23 +29,22 @@ use tokio::sync::Mutex;
use tokio::task::block_in_place; use tokio::task::block_in_place;
use tokio::time; use tokio::time;
use yaak::send::ResponseBody; use yaak::send::ResponseBody;
use yaak_commands::responses::locate_response_body;
use yaak_commands::resolve::resolve_grpc_request; use yaak_commands::resolve::resolve_grpc_request;
use yaak_commands::responses::locate_response_body;
use yaak_common::command::new_checked_command; use yaak_common::command::new_checked_command;
use yaak_crypto::manager::EncryptionManager; use yaak_crypto::manager::EncryptionManager;
use yaak_grpc::manager::{GrpcConfig, GrpcHandle}; use yaak_grpc::manager::{GrpcConfig, GrpcHandle};
use yaak_grpc::{Code, ServiceDefinition}; use yaak_grpc::{Code, ServiceDefinition};
use yaak_mac_window::AppHandleMacWindowExt; use yaak_mac_window::AppHandleMacWindowExt;
use yaak_models::models::{ use yaak_models::models::{
CookieJar, Environment, GrpcConnection, GrpcConnectionState, GrpcEvent, CookieJar, Environment, GrpcConnection, GrpcConnectionState, GrpcEvent, GrpcEventType,
GrpcEventType, HttpRequest, HttpResponse, HttpResponseState, Workspace, HttpRequest, HttpResponse, HttpResponseState, Workspace,
}; };
use yaak_models::util::{BatchUpsertResult, UpdateSource}; use yaak_models::util::{BatchUpsertResult, ImportDestination, ImportPlan, UpdateSource};
use yaak_plugins::events::{ use yaak_plugins::events::{
Color, ErrorResponse, FilterResponse, InternalEvent, InternalEventPayload, PluginContext, Color, ErrorResponse, FilterResponse, InternalEvent, InternalEventPayload, PluginContext,
RenderPurpose, ShowToastRequest, RenderPurpose, ShowToastRequest,
}; };
use yaak_plugins::manager::PluginManager;
use yaak_plugins::template_callback::PluginTemplateCallback; use yaak_plugins::template_callback::PluginTemplateCallback;
use yaak_rpc_schema::{AppMetaData, EphemeralHttpResponse}; use yaak_rpc_schema::{AppMetaData, EphemeralHttpResponse};
use yaak_sse::sse::ServerSentEvent; use yaak_sse::sse::ServerSentEvent;
@@ -250,7 +249,7 @@ async fn cmd_grpc_reflect<R: Runtime>(
let resolved_settings = let resolved_settings =
app_handle.db().resolve_settings_for_grpc_request(&unrendered_request)?; app_handle.db().resolve_settings_for_grpc_request(&unrendered_request)?;
let plugin_manager = Arc::new((*app_handle.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(&app_handle).await?);
let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone()); let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone());
let req = render_grpc_request( let req = render_grpc_request(
&resolved_request, &resolved_request,
@@ -310,7 +309,7 @@ async fn cmd_grpc_go<R: Runtime>(
let resolved_settings = let resolved_settings =
app_handle.db().resolve_settings_for_grpc_request(&unrendered_request)?; app_handle.db().resolve_settings_for_grpc_request(&unrendered_request)?;
let plugin_manager = Arc::new((*app_handle.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(&app_handle).await?);
let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone()); let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone());
let request = render_grpc_request( let request = render_grpc_request(
&resolved_request, &resolved_request,
@@ -331,18 +330,20 @@ async fn cmd_grpc_go<R: Runtime>(
let settings = app_handle.db().get_settings(); let settings = app_handle.db().get_settings();
let client_cert = find_client_certificate(&request.url, &settings.client_certificates); let client_cert = find_client_certificate(&request.url, &settings.client_certificates);
let conn = app_handle.db().upsert_grpc_connection( let conn = app_handle.with_tx(|tx| {
&GrpcConnection { tx.upsert_grpc_connection(
workspace_id: request.workspace_id.clone(), &GrpcConnection {
request_id: request.id.clone(), workspace_id: request.workspace_id.clone(),
status: -1, request_id: request.id.clone(),
elapsed: 0, status: -1,
state: GrpcConnectionState::Initialized, elapsed: 0,
url: request.url.clone(), state: GrpcConnectionState::Initialized,
..Default::default() url: request.url.clone(),
}, ..Default::default()
&UpdateSource::from_window_label(window.label()), },
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
let conn_id = conn.id.clone(); let conn_id = conn.id.clone();
@@ -387,15 +388,17 @@ async fn cmd_grpc_go<R: Runtime>(
let connection = match connection { let connection = match connection {
Ok(c) => c, Ok(c) => c,
Err(err) => { Err(err) => {
app_handle.db().upsert_grpc_connection( app_handle.with_tx(|tx| {
&GrpcConnection { tx.upsert_grpc_connection(
elapsed: start.elapsed().as_millis() as i32, &GrpcConnection {
error: Some(err.to_string()), elapsed: start.elapsed().as_millis() as i32,
state: GrpcConnectionState::Closed, error: Some(err.to_string()),
..conn.clone() state: GrpcConnectionState::Closed,
}, ..conn.clone()
&UpdateSource::from_window_label(window.label()), },
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
return Ok(conn_id); return Ok(conn_id);
} }
}; };
@@ -496,15 +499,17 @@ async fn cmd_grpc_go<R: Runtime>(
.await?; .await?;
let msg = strip_json_comments(&msg); let msg = strip_json_comments(&msg);
app_handle.db().upsert_grpc_event( app_handle.with_tx(|tx| {
&GrpcEvent { tx.upsert_grpc_event(
content: format!("Connecting to {}", req.url), &GrpcEvent {
event_type: GrpcEventType::ConnectionStart, content: format!("Connecting to {}", req.url),
metadata: metadata.clone(), event_type: GrpcEventType::ConnectionStart,
..base_event.clone() metadata: metadata.clone(),
}, ..base_event.clone()
&UpdateSource::from_window_label(window.label()), },
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
async move { async move {
// Create callback for streaming methods that handles both success and error // Create callback for streaming methods that handles both success and error
@@ -514,24 +519,28 @@ async fn cmd_grpc_go<R: Runtime>(
let window_label = window.label().to_string(); let window_label = window.label().to_string();
move |result: std::result::Result<String, String>| match result { move |result: std::result::Result<String, String>| match result {
Ok(msg) => { Ok(msg) => {
let _ = app_handle.db().upsert_grpc_event( let _ = app_handle.with_tx(|tx| {
&GrpcEvent { tx.upsert_grpc_event(
content: msg, &GrpcEvent {
event_type: GrpcEventType::ClientMessage, content: msg,
..base_event.clone() event_type: GrpcEventType::ClientMessage,
}, ..base_event.clone()
&UpdateSource::from_window_label(&window_label), },
); &UpdateSource::from_window_label(&window_label),
)
});
} }
Err(error) => { Err(error) => {
let _ = app_handle.db().upsert_grpc_event( let _ = app_handle.with_tx(|tx| {
&GrpcEvent { tx.upsert_grpc_event(
content: format!("Failed to send message: {}", error), &GrpcEvent {
event_type: GrpcEventType::Error, content: format!("Failed to send message: {}", error),
..base_event.clone() event_type: GrpcEventType::Error,
}, ..base_event.clone()
&UpdateSource::from_window_label(&window_label), },
); &UpdateSource::from_window_label(&window_label),
)
});
} }
} }
}; };
@@ -584,36 +593,38 @@ async fn cmd_grpc_go<R: Runtime>(
if !method_desc.is_client_streaming() { if !method_desc.is_client_streaming() {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
event_type: GrpcEventType::ClientMessage, event_type: GrpcEventType::ClientMessage,
content: msg, content: msg,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
} }
match maybe_msg { match maybe_msg {
Some(Ok(msg)) => { Some(Ok(msg)) => {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
metadata: metadata_to_map(msg.metadata().clone()), metadata: metadata_to_map(msg.metadata().clone()),
content: if msg.metadata().len() == 0 { content: if msg.metadata().len() == 0 {
"Received response" "Received response"
} else { } else {
"Received response with metadata" "Received response with metadata"
} }
.to_string(), .to_string(),
event_type: GrpcEventType::Info, event_type: GrpcEventType::Info,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
let response_message = msg.into_inner(); let response_message = msg.into_inner();
let content = match connection let content = match connection
@@ -623,83 +634,88 @@ async fn cmd_grpc_go<R: Runtime>(
Ok(content) => content, Ok(content) => content,
Err(err) => { Err(err) => {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
content: "Failed to read response".to_string(), content: "Failed to read response".to_string(),
error: Some(err.to_string()), error: Some(err.to_string()),
status: Some(Code::Internal as i32), status: Some(Code::Internal as i32),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
return; return;
} }
}; };
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
content, content,
event_type: GrpcEventType::ServerMessage, event_type: GrpcEventType::ServerMessage,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
content: "Connection complete".to_string(), content: "Connection complete".to_string(),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
status: Some(Code::Ok as i32), status: Some(Code::Ok as i32),
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
} }
Some(Err(yaak_grpc::error::Error::GrpcStreamError(e))) => { Some(Err(yaak_grpc::error::Error::GrpcStreamError(e))) => {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&(match e.status { &(match e.status {
Some(s) => GrpcEvent { Some(s) => GrpcEvent {
error: Some(s.message().to_string()), error: Some(s.message().to_string()),
status: Some(s.code() as i32), status: Some(s.code() as i32),
content: "Request failed".to_string(), content: "Request failed".to_string(),
metadata: metadata_to_map(s.metadata().clone()), metadata: metadata_to_map(s.metadata().clone()),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
None => GrpcEvent { None => GrpcEvent {
error: Some(e.message), error: Some(e.message),
status: Some(Code::Unknown as i32),
content: "Request failed".to_string(),
event_type: GrpcEventType::ConnectionEnd,
..base_event.clone()
},
}),
&UpdateSource::from_window_label(window.label()),
)
})
.unwrap();
}
Some(Err(e)) => {
app_handle
.with_tx(|tx| {
tx.upsert_grpc_event(
&GrpcEvent {
error: Some(e.to_string()),
status: Some(Code::Unknown as i32), status: Some(Code::Unknown as i32),
content: "Request failed".to_string(), content: "Request failed".to_string(),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
}), &UpdateSource::from_window_label(window.label()),
&UpdateSource::from_window_label(window.label()), )
) })
.unwrap();
}
Some(Err(e)) => {
app_handle
.db()
.upsert_grpc_event(
&GrpcEvent {
error: Some(e.to_string()),
status: Some(Code::Unknown as i32),
content: "Request failed".to_string(),
event_type: GrpcEventType::ConnectionEnd,
..base_event.clone()
},
&UpdateSource::from_window_label(window.label()),
)
.unwrap(); .unwrap();
} }
None => { None => {
@@ -710,64 +726,67 @@ async fn cmd_grpc_go<R: Runtime>(
let mut stream = match maybe_stream { let mut stream = match maybe_stream {
Some(Ok(stream)) => { Some(Ok(stream)) => {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
metadata: metadata_to_map(stream.metadata().clone()), metadata: metadata_to_map(stream.metadata().clone()),
content: if stream.metadata().len() == 0 { content: if stream.metadata().len() == 0 {
"Received response" "Received response"
} else { } else {
"Received response with metadata" "Received response with metadata"
} }
.to_string(), .to_string(),
event_type: GrpcEventType::Info, event_type: GrpcEventType::Info,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
stream.into_inner() stream.into_inner()
} }
Some(Err(yaak_grpc::error::Error::GrpcStreamError(e))) => { Some(Err(yaak_grpc::error::Error::GrpcStreamError(e))) => {
warn!("GRPC stream error {e:?}"); warn!("GRPC stream error {e:?}");
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&(match e.status { &(match e.status {
Some(s) => GrpcEvent { Some(s) => GrpcEvent {
error: Some(s.message().to_string()), error: Some(s.message().to_string()),
status: Some(s.code() as i32), status: Some(s.code() as i32),
content: "Stream failed".to_string(), content: "Stream failed".to_string(),
metadata: metadata_to_map(s.metadata().clone()), metadata: metadata_to_map(s.metadata().clone()),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
None => GrpcEvent { None => GrpcEvent {
error: Some(e.message), error: Some(e.message),
status: Some(Code::Unknown as i32), status: Some(Code::Unknown as i32),
content: "Stream failed".to_string(), content: "Stream failed".to_string(),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
}), }),
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
return; return;
} }
Some(Err(e)) => { Some(Err(e)) => {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
error: Some(e.to_string()), error: Some(e.to_string()),
status: Some(Code::Unknown as i32), status: Some(Code::Unknown as i32),
content: "Stream failed".to_string(), content: "Stream failed".to_string(),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
return; return;
} }
@@ -784,65 +803,69 @@ async fn cmd_grpc_go<R: Runtime>(
Ok(message) => message, Ok(message) => message,
Err(err) => { Err(err) => {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
content: "Failed to read response".to_string(), content: "Failed to read response".to_string(),
error: Some(err.to_string()), error: Some(err.to_string()),
status: Some(Code::Internal as i32), status: Some(Code::Internal as i32),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
break; break;
} }
}; };
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
content: message, content: message,
event_type: GrpcEventType::ServerMessage, event_type: GrpcEventType::ServerMessage,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
} }
Ok(None) => { Ok(None) => {
let trailers = let trailers =
stream.trailers().await.unwrap_or_default().unwrap_or_default(); stream.trailers().await.unwrap_or_default().unwrap_or_default();
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
content: "Connection complete".to_string(), content: "Connection complete".to_string(),
status: Some(Code::Ok as i32), status: Some(Code::Ok as i32),
metadata: metadata_to_map(trailers), metadata: metadata_to_map(trailers),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
break; break;
} }
Err(status) => { Err(status) => {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_grpc_event( tx.upsert_grpc_event(
&GrpcEvent { &GrpcEvent {
content: "Stream failed".to_string(), content: "Stream failed".to_string(),
error: Some(status.message().to_string()), error: Some(status.message().to_string()),
status: Some(status.code() as i32), status: Some(status.code() as i32),
metadata: metadata_to_map(status.metadata().clone()), metadata: metadata_to_map(status.metadata().clone()),
event_type: GrpcEventType::ConnectionEnd, event_type: GrpcEventType::ConnectionEnd,
..base_event.clone() ..base_event.clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
) )
})
.unwrap(); .unwrap();
break; break;
} }
@@ -875,21 +898,24 @@ async fn cmd_grpc_go<R: Runtime>(
}).unwrap(); }).unwrap();
}, },
_ = cancelled_rx.changed() => { _ = cancelled_rx.changed() => {
w.db().upsert_grpc_event( w.with_tx(|tx| {
&GrpcEvent { tx.upsert_grpc_event(
content: "Cancelled".to_string(), &GrpcEvent {
event_type: GrpcEventType::ConnectionEnd, content: "Cancelled".to_string(),
status: Some(Code::Cancelled as i32), event_type: GrpcEventType::ConnectionEnd,
..base_msg.clone() status: Some(Code::Cancelled as i32),
}, ..base_msg.clone()
&UpdateSource::from_window_label(window.label()), },
).unwrap(); &UpdateSource::from_window_label(window.label()),
)
})
.unwrap();
w.with_tx(|c| { w.with_tx(|c| {
c.upsert_grpc_connection( c.upsert_grpc_connection(
&GrpcConnection{ &GrpcConnection{
elapsed: start.elapsed().as_millis() as i32, elapsed: start.elapsed().as_millis() as i32,
status: Code::Cancelled as i32, status: Code::Cancelled as i32,
state: GrpcConnectionState::Closed, state: GrpcConnectionState::Closed,
..c.get_grpc_connection( &conn_id).unwrap().clone() ..c.get_grpc_connection( &conn_id).unwrap().clone()
}, },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
@@ -962,7 +988,6 @@ async fn cmd_format_graphql(text: &str) -> YaakResult<String> {
async fn cmd_http_response_body<R: Runtime>( async fn cmd_http_response_body<R: Runtime>(
window: WebviewWindow<R>, window: WebviewWindow<R>,
plugin_manager: State<'_, PluginManager>,
response_id: &str, response_id: &str,
filter: Option<&str>, filter: Option<&str>,
) -> YaakResult<FilterResponse> { ) -> YaakResult<FilterResponse> {
@@ -977,7 +1002,8 @@ async fn cmd_http_response_body<R: Runtime>(
.ok_or(GenericError("Failed to find response body".to_string()))?; .ok_or(GenericError("Failed to find response body".to_string()))?;
match filter { match filter {
Some(filter) if !filter.is_empty() => Ok(plugin_manager Some(filter) if !filter.is_empty() => Ok(plugins_ext::plugin_manager(&window)
.await?
.filter_data(&window.plugin_context(), filter, &body, content_type) .filter_data(&window.plugin_context(), filter, &body, content_type)
.await?), .await?),
_ => Ok(FilterResponse { content: body, error: None }), _ => Ok(FilterResponse { content: body, error: None }),
@@ -1014,30 +1040,25 @@ async fn cmd_get_sse_events<R: Runtime>(
async fn cmd_import_data<R: Runtime>( async fn cmd_import_data<R: Runtime>(
window: WebviewWindow<R>, window: WebviewWindow<R>,
file_path: &str, file_path: &str,
) -> YaakResult<BatchUpsertResult> { destination: ImportDestination,
import_data(&window, file_path).await ) -> YaakResult<ImportPlan> {
plan_import_data(&window, file_path, destination).await
} }
async fn cmd_import_url<R: Runtime>( async fn cmd_import_url<R: Runtime>(
window: WebviewWindow<R>, window: WebviewWindow<R>,
url: &str, url: &str,
) -> YaakResult<BatchUpsertResult> { destination: ImportDestination,
import_url(&window, url).await ) -> YaakResult<ImportPlan> {
plan_import_url(&window, url, destination).await
} }
async fn cmd_commit_import<R: Runtime>(
window: WebviewWindow<R>,
plan: ImportPlan,
) -> YaakResult<BatchUpsertResult> {
commit_import(&window, plan)
}
/// Decodes base64 and writes the bytes to a file the user picked. /// Decodes base64 and writes the bytes to a file the user picked.
/// ///
@@ -1072,15 +1093,17 @@ async fn cmd_send_http_request<R: Runtime>(
let request = app_handle.db().get_http_request(&request_id)?; let request = app_handle.db().get_http_request(&request_id)?;
let blobs = app_handle.blob_manager(); let blobs = app_handle.blob_manager();
let response = app_handle.db().upsert_http_response( let response = app_handle.with_tx(|tx| {
&HttpResponse { tx.upsert_http_response(
request_id: request.id.clone(), &HttpResponse {
workspace_id: request.workspace_id.clone(), request_id: request.id.clone(),
..Default::default() workspace_id: request.workspace_id.clone(),
}, ..Default::default()
&UpdateSource::from_window_label(window.label()), },
&blobs, &UpdateSource::from_window_label(window.label()),
)?; &blobs,
)
})?;
let (cancel_tx, mut cancel_rx) = tokio::sync::watch::channel(false); let (cancel_tx, mut cancel_rx) = tokio::sync::watch::channel(false);
app_handle.listen_any(format!("cancel_http_response_{}", response.id), move |_event| { app_handle.listen_any(format!("cancel_http_response_{}", response.id), move |_event| {
@@ -1118,22 +1141,23 @@ async fn cmd_send_http_request<R: Runtime>(
Ok(sent) => sent.response, Ok(sent) => sent.response,
Err(e) => { Err(e) => {
let resp = app_handle.db().get_http_response(&response.id)?; let resp = app_handle.db().get_http_response(&response.id)?;
app_handle.db().upsert_http_response( app_handle.with_tx(|tx| {
&HttpResponse { tx.upsert_http_response(
state: HttpResponseState::Closed, &HttpResponse {
error: Some(e.to_string()), state: HttpResponseState::Closed,
..resp error: Some(e.to_string()),
}, ..resp
&UpdateSource::from_window_label(window.label()), },
&blobs, &UpdateSource::from_window_label(window.label()),
)? &blobs,
)
})?
} }
}; };
Ok(r) Ok(r)
} }
async fn cmd_new_child_window<R: Runtime>( async fn cmd_new_child_window<R: Runtime>(
parent_window: WebviewWindow<R>, parent_window: WebviewWindow<R>,
url: &str, url: &str,
@@ -1261,8 +1285,8 @@ pub fn run() {
.setup(|app| { .setup(|app| {
let lifecycle_host = yaak_lifecycle::Host::owner() let lifecycle_host = yaak_lifecycle::Host::owner()
.with_responses_dir(app.path().app_data_dir()?.join("responses")); .with_responses_dir(app.path().app_data_dir()?.join("responses"));
if let Err(e) = if let Err(e) = app
yaak_lifecycle::on_launch(&lifecycle_host, &app.db(), &app.blob_manager()) .with_tx(|tx| yaak_lifecycle::on_launch(&lifecycle_host, tx, &app.blob_manager()))
{ {
error!("on_launch hook failed: {e:?}"); error!("on_launch hook failed: {e:?}");
} }
@@ -1367,6 +1391,16 @@ pub fn run() {
debug!("Launched Yaak {:?}", info); debug!("Launched Yaak {:?}", info);
}); });
} }
RunEvent::WindowEvent { event: WindowEvent::ThemeChanged(_), .. } => {
// On macOS this is how OS appearance changes arrive: tao observes
// AppleInterfaceThemeChangedNotification and emits it for every window
#[cfg(any(target_os = "linux", target_os = "macos"))]
if let Some(state) =
app_handle.try_state::<yaak_system_appearance::SystemAppearanceState>()
{
yaak_system_appearance::emit_change(app_handle, &state);
}
}
RunEvent::WindowEvent { event: WindowEvent::Focused(true), label, .. } => { RunEvent::WindowEvent { event: WindowEvent::Focused(true), label, .. } => {
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "linux", target_os = "macos"))]
if let Some(state) = if let Some(state) =
@@ -1431,7 +1465,10 @@ fn safe_uri(endpoint: &str) -> String {
fn monitor_plugin_events<R: Runtime>(app_handle: &AppHandle<R>) { fn monitor_plugin_events<R: Runtime>(app_handle: &AppHandle<R>) {
let app_handle = app_handle.clone(); let app_handle = app_handle.clone();
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {
let plugin_manager: State<'_, PluginManager> = app_handle.state(); let plugin_manager = match plugins_ext::plugin_manager(&app_handle).await {
Ok(pm) => pm,
Err(_) => return, // The runtime failed to boot; there are no events
};
let (rx_id, mut rx) = plugin_manager.subscribe("app").await; let (rx_id, mut rx) = plugin_manager.subscribe("app").await;
while let Some(event) = rx.recv().await { while let Some(event) = rx.recv().await {
@@ -1472,9 +1509,13 @@ fn monitor_plugin_events<R: Runtime>(app_handle: &AppHandle<R>) {
} }
}; };
let plugin_manager: State<'_, PluginManager> = app_handle.state(); match plugins_ext::plugin_manager(&app_handle).await {
if let Err(e) = plugin_manager.reply(&event, &ev).await { Ok(pm) => {
warn!("Failed to reply to plugin manager: {:?}", e) if let Err(e) = pm.reply(&event, &ev).await {
warn!("Failed to reply to plugin manager: {:?}", e)
}
}
Err(e) => warn!("Failed to get plugin manager for reply: {e:?}"),
} }
}); });
} }
@@ -10,7 +10,7 @@ use tauri::plugin::TauriPlugin;
use tauri::{Emitter, Manager, Runtime, State}; use tauri::{Emitter, Manager, Runtime, State};
use tauri_plugin_dialog::{DialogExt, MessageDialogKind}; use tauri_plugin_dialog::{DialogExt, MessageDialogKind};
use yaak_models::blob_manager::BlobManager; use yaak_models::blob_manager::BlobManager;
use yaak_models::client_db::ClientDb; use yaak_models::client_db::{ClientDb, WriteDb};
use yaak_models::error::Result; use yaak_models::error::Result;
use yaak_models::query_manager::QueryManager; use yaak_models::query_manager::QueryManager;
use yaak_models::util::{ModelPayload, UpdateSource}; use yaak_models::util::{ModelPayload, UpdateSource};
@@ -95,7 +95,7 @@ pub trait QueryManagerExt<'a, R> {
fn db(&'a self) -> ClientDb<'a>; fn db(&'a self) -> ClientDb<'a>;
fn with_tx<F, T>(&'a self, func: F) -> Result<T> fn with_tx<F, T>(&'a self, func: F) -> Result<T>
where where
F: FnOnce(&ClientDb) -> Result<T>; F: FnOnce(&WriteDb) -> Result<T>;
} }
impl<'a, R: Runtime, M: Manager<R>> QueryManagerExt<'a, R> for M { impl<'a, R: Runtime, M: Manager<R>> QueryManagerExt<'a, R> for M {
@@ -110,7 +110,7 @@ impl<'a, R: Runtime, M: Manager<R>> QueryManagerExt<'a, R> for M {
fn with_tx<F, T>(&'a self, func: F) -> Result<T> fn with_tx<F, T>(&'a self, func: F) -> Result<T>
where where
F: FnOnce(&ClientDb) -> Result<T>, F: FnOnce(&WriteDb) -> Result<T>,
{ {
let qm = self.state::<QueryManager>(); let qm = self.state::<QueryManager>();
qm.inner().with_tx(func) qm.inner().with_tx(func)
@@ -55,12 +55,15 @@ impl YaakNotifier {
seen.push(id.to_string()); seen.push(id.to_string());
debug!("Marked notification as seen {}", id); debug!("Marked notification as seen {}", id);
let seen_json = serde_json::to_string(&seen)?; let seen_json = serde_json::to_string(&seen)?;
window.db().set_key_value_raw( window.with_tx(|tx| {
KV_NAMESPACE, tx.set_key_value_raw(
KV_KEY, KV_NAMESPACE,
seen_json.as_str(), KV_KEY,
&UpdateSource::from_window_label(window.label()), seen_json.as_str(),
); &UpdateSource::from_window_label(window.label()),
);
Ok(())
})?;
Ok(()) Ok(())
} }
@@ -32,7 +32,6 @@ use yaak_plugins::events::{
ShowToastRequest, TemplateRenderResponse, WindowInfoResponse, WindowNavigateEvent, ShowToastRequest, TemplateRenderResponse, WindowInfoResponse, WindowNavigateEvent,
WorkspaceInfo, WorkspaceInfo,
}; };
use yaak_plugins::manager::PluginManager;
use yaak_plugins::plugin_handle::PluginHandle; use yaak_plugins::plugin_handle::PluginHandle;
use yaak_plugins::template_callback::PluginTemplateCallback; use yaak_plugins::template_callback::PluginTemplateCallback;
use yaak_tauri_utils::window::WorkspaceWindowTrait; use yaak_tauri_utils::window::WorkspaceWindowTrait;
@@ -112,7 +111,7 @@ async fn handle_host_plugin_request<R: Runtime>(
} }
let new_plugin = Plugin { updated_at: Utc::now().naive_utc(), ..plugin }; let new_plugin = Plugin { updated_at: Utc::now().naive_utc(), ..plugin };
app_handle.db().upsert_plugin(&new_plugin, &UpdateSource::Plugin)?; app_handle.with_tx(|tx| tx.upsert_plugin(&new_plugin, &UpdateSource::Plugin))?;
} }
if !req.silent { if !req.silent {
@@ -205,7 +204,7 @@ async fn handle_host_plugin_request<R: Runtime>(
req.grpc_request.folder_id.as_deref(), req.grpc_request.folder_id.as_deref(),
environment_id.as_deref(), environment_id.as_deref(),
)?; )?;
let plugin_manager = Arc::new((*app_handle.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(app_handle).await?);
let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone()); let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone());
let cb = PluginTemplateCallback::new( let cb = PluginTemplateCallback::new(
plugin_manager, plugin_manager,
@@ -231,7 +230,7 @@ async fn handle_host_plugin_request<R: Runtime>(
req.http_request.folder_id.as_deref(), req.http_request.folder_id.as_deref(),
environment_id.as_deref(), environment_id.as_deref(),
)?; )?;
let plugin_manager = Arc::new((*app_handle.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(app_handle).await?);
let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone()); let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone());
let cb = PluginTemplateCallback::new( let cb = PluginTemplateCallback::new(
plugin_manager, plugin_manager,
@@ -267,7 +266,7 @@ async fn handle_host_plugin_request<R: Runtime>(
folder_id.as_deref(), folder_id.as_deref(),
environment_id.as_deref(), environment_id.as_deref(),
)?; )?;
let plugin_manager = Arc::new((*app_handle.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(app_handle).await?);
let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone()); let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone());
let cb = PluginTemplateCallback::new( let cb = PluginTemplateCallback::new(
plugin_manager, plugin_manager,
@@ -295,15 +294,17 @@ async fn handle_host_plugin_request<R: Runtime>(
HttpResponse::default() HttpResponse::default()
} else { } else {
let blobs = window.blob_manager(); let blobs = window.blob_manager();
window.db().upsert_http_response( window.with_tx(|tx| {
&HttpResponse { tx.upsert_http_response(
request_id: http_request.id.clone(), &HttpResponse {
workspace_id: http_request.workspace_id.clone(), request_id: http_request.id.clone(),
..Default::default() workspace_id: http_request.workspace_id.clone(),
}, ..Default::default()
&UpdateSource::from_window_label(window.label()), },
&blobs, &UpdateSource::from_window_label(window.label()),
)? &blobs,
)
})?
}; };
let http_response = send_http_request_with_context( let http_response = send_http_request_with_context(
+92 -30
View File
@@ -16,8 +16,7 @@ use std::time::{Duration, Instant};
use tauri::path::BaseDirectory; use tauri::path::BaseDirectory;
use tauri::plugin::{Builder, TauriPlugin}; use tauri::plugin::{Builder, TauriPlugin};
use tauri::{ use tauri::{
AppHandle, Emitter, Manager, RunEvent, Runtime, State, WebviewWindow, WindowEvent, AppHandle, Emitter, Manager, RunEvent, Runtime, State, WebviewWindow, WindowEvent, is_dev,
is_dev,
}; };
use tokio::sync::Mutex; use tokio::sync::Mutex;
use ts_rs::TS; use ts_rs::TS;
@@ -28,6 +27,7 @@ use yaak_plugins::api::{
PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates, PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates,
search_plugins, search_plugins,
}; };
use yaak_plugins::error::Error::PluginErr;
use yaak_plugins::events::{Color, PluginContext, ShowToastRequest}; use yaak_plugins::events::{Color, PluginContext, ShowToastRequest};
use yaak_plugins::install::{delete_and_uninstall, download_and_install}; use yaak_plugins::install::{delete_and_uninstall, download_and_install};
use yaak_plugins::manager::PluginManager; use yaak_plugins::manager::PluginManager;
@@ -35,6 +35,38 @@ use yaak_plugins::plugin_meta::get_plugin_meta;
static EXITING: AtomicBool = AtomicBool::new(false); static EXITING: AtomicBool = AtomicBool::new(false);
// ============================================================================
// Plugin Manager Handle
// ============================================================================
/// The plugin runtime boots in the background so startup doesn't wait on it.
/// This handle is the only way to reach the manager: [`PluginManagerHandle::get`]
/// resolves once boot completes, so callers can never observe a
/// partially-initialized runtime.
#[derive(Clone)]
pub struct PluginManagerHandle {
rx: tokio::sync::watch::Receiver<Option<std::result::Result<PluginManager, String>>>,
}
impl PluginManagerHandle {
pub async fn get(&self) -> yaak_plugins::error::Result<PluginManager> {
let mut rx = self.rx.clone();
let result = rx
.wait_for(|v| v.is_some())
.await
.map_err(|_| PluginErr("Plugin runtime boot task died".to_string()))?;
result.clone().unwrap().map_err(PluginErr)
}
}
/// Wait for the plugin runtime to finish booting and return the manager.
pub async fn plugin_manager<R: Runtime>(
manager: &impl Manager<R>,
) -> yaak_plugins::error::Result<PluginManager> {
let handle = manager.state::<PluginManagerHandle>().inner().clone();
handle.get().await
}
// ============================================================================ // ============================================================================
// Plugin Updater // Plugin Updater
// ============================================================================ // ============================================================================
@@ -146,7 +178,7 @@ pub async fn cmd_plugins_install<R: Runtime>(
name: &str, name: &str,
version: Option<String>, version: Option<String>,
) -> Result<()> { ) -> Result<()> {
let plugin_manager = Arc::new((*window.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(plugin_manager(&window).await?);
let app_version = window.app_handle().package_info().version.to_string(); let app_version = window.app_handle().package_info().version.to_string();
let http_client = yaak_api_client(ApiClientKind::App, &app_version)?; let http_client = yaak_api_client(ApiClientKind::App, &app_version)?;
let query_manager = window.state::<yaak_models::query_manager::QueryManager>(); let query_manager = window.state::<yaak_models::query_manager::QueryManager>();
@@ -167,18 +199,22 @@ pub async fn cmd_plugins_install_from_directory<R: Runtime>(
window: WebviewWindow<R>, window: WebviewWindow<R>,
directory: &str, directory: &str,
) -> Result<Plugin> { ) -> Result<Plugin> {
let plugin = window.db().upsert_plugin( // Resolve the manager before writing the row so startup's plugin snapshot
&Plugin { // can't include it and boot it a second time
directory: directory.into(), let plugin_manager = Arc::new(plugin_manager(&window).await?);
url: None, let plugin = window.with_tx(|tx| {
enabled: true, tx.upsert_plugin(
source: PluginSource::Filesystem, &Plugin {
..Default::default() directory: directory.into(),
}, url: None,
&UpdateSource::from_window_label(window.label()), enabled: true,
)?; source: PluginSource::Filesystem,
..Default::default()
},
&UpdateSource::from_window_label(window.label()),
)
})?;
let plugin_manager = Arc::new((*window.state::<PluginManager>()).clone());
plugin_manager.add_plugin(&window.plugin_context(), &plugin).await?; plugin_manager.add_plugin(&window.plugin_context(), &plugin).await?;
Ok(plugin) Ok(plugin)
@@ -188,7 +224,7 @@ pub async fn cmd_plugins_uninstall<R: Runtime>(
plugin_id: &str, plugin_id: &str,
window: WebviewWindow<R>, window: WebviewWindow<R>,
) -> Result<Plugin> { ) -> Result<Plugin> {
let plugin_manager = Arc::new((*window.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(plugin_manager(&window).await?);
let query_manager = window.state::<yaak_models::query_manager::QueryManager>(); let query_manager = window.state::<yaak_models::query_manager::QueryManager>();
let plugin_context = window.plugin_context(); let plugin_context = window.plugin_context();
Ok(delete_and_uninstall(plugin_manager, &query_manager, &plugin_context, plugin_id).await?) Ok(delete_and_uninstall(plugin_manager, &query_manager, &plugin_context, plugin_id).await?)
@@ -217,7 +253,7 @@ pub async fn cmd_plugins_update_all<R: Runtime>(
return Ok(Vec::new()); return Ok(Vec::new());
} }
let plugin_manager = Arc::new((*window.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(plugin_manager(&window).await?);
let query_manager = window.state::<yaak_models::query_manager::QueryManager>(); let query_manager = window.state::<yaak_models::query_manager::QueryManager>();
let plugin_context = window.plugin_context(); let plugin_context = window.plugin_context();
@@ -300,20 +336,40 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
let query_manager = let query_manager =
app_handle.state::<yaak_models::query_manager::QueryManager>().inner().clone(); app_handle.state::<yaak_models::query_manager::QueryManager>().inner().clone();
// Create plugin manager asynchronously // Boot the plugin runtime in the background so the window shows
// immediately. Everything that needs plugins resolves the handle,
// which waits for this task to finish.
let (tx, rx) = tokio::sync::watch::channel(None);
app_handle.manage(PluginManagerHandle { rx });
let app_handle_clone = app_handle.clone(); let app_handle_clone = app_handle.clone();
tauri::async_runtime::block_on(async move { tauri::async_runtime::spawn(async move {
let manager = PluginManager::new( let result = tokio::time::timeout(
vendored_plugin_dir, Duration::from_secs(60),
installed_plugin_dir, PluginManager::new(
node_bin_path, vendored_plugin_dir,
plugin_runtime_main, installed_plugin_dir,
&query_manager, node_bin_path,
&PluginContext::new_empty(), plugin_runtime_main,
dev_mode, &query_manager,
&PluginContext::new_empty(),
dev_mode,
),
) )
.await .await
.expect("Failed to start plugin runtime"); .unwrap_or_else(|_| {
Err(yaak_plugins::error::Error::PluginErr(
"Timed out starting the plugin runtime".to_string(),
))
});
let manager = match result {
Ok(manager) => manager,
Err(e) => {
error!("Failed to start plugin runtime: {e:?}");
let _ = tx.send(Some(Err(e.to_string())));
return;
}
};
// Surface unexpected runtime crashes to the user // Surface unexpected runtime crashes to the user
let mut crash_rx = manager.runtime_crash_rx(); let mut crash_rx = manager.runtime_crash_rx();
@@ -339,7 +395,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
} }
}); });
app_handle_clone.manage(manager); let _ = tx.send(Some(Ok(manager)));
}); });
let plugin_updater = PluginUpdater::new(); let plugin_updater = PluginUpdater::new();
@@ -355,8 +411,14 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
api.prevent_exit(); api.prevent_exit();
tauri::async_runtime::block_on(async move { tauri::async_runtime::block_on(async move {
info!("Exiting plugin runtime due to app exit"); info!("Exiting plugin runtime due to app exit");
let manager: State<PluginManager> = app.state(); // Bound the wait in case the exit comes while boot is still
manager.terminate().await; // in flight
let get_manager = plugin_manager(app);
if let Ok(Ok(manager)) =
tokio::time::timeout(Duration::from_secs(5), get_manager).await
{
manager.terminate().await;
}
app.exit(0); app.exit(0);
}); });
} }
+1 -1
View File
@@ -4,5 +4,5 @@
//! `yaak-commands` when the template commands did. Callers in this crate do not //! `yaak-commands` when the template commands did. Callers in this crate do not
//! need to track which is which. //! need to track which is which.
pub use yaak_models::render::{render_grpc_request, render_http_request};
pub use yaak_commands::render::{render_json_value, render_template}; pub use yaak_commands::render::{render_json_value, render_template};
pub use yaak_models::render::{render_grpc_request, render_http_request};
File diff suppressed because it is too large. Load diff
+9 -6
View File
@@ -12,8 +12,8 @@ use tokio::sync::watch;
use yaak_rpc_schema::WatchResult; use yaak_rpc_schema::WatchResult;
use yaak_sync::error::Error::InvalidSyncDirectory; use yaak_sync::error::Error::InvalidSyncDirectory;
use yaak_sync::sync::{ use yaak_sync::sync::{
FsCandidate, SyncOp, apply_sync_ops, apply_sync_state_ops, compute_sync_ops, get_db_candidates, FsCandidate, SyncOp, apply_db_sync_ops, apply_fs_sync_ops, apply_sync_state_ops,
get_fs_candidates, compute_sync_ops, get_db_candidates, get_fs_candidates,
}; };
use yaak_sync::watch::{WatchEvent, watch_directory}; use yaak_sync::watch::{WatchEvent, watch_directory};
@@ -49,11 +49,14 @@ pub(crate) async fn cmd_sync_apply<R: Runtime>(
sync_dir: &Path, sync_dir: &Path,
workspace_id: &str, workspace_id: &str,
) -> Result<()> { ) -> Result<()> {
let db = app_handle.db(); // Files first, so the write transaction never waits on the filesystem
let pending = apply_fs_sync_ops(workspace_id, sync_dir, sync_ops)?;
let blobs = app_handle.blob_manager(); let blobs = app_handle.blob_manager();
let sync_state_ops = apply_sync_ops(&db, &blobs, workspace_id, sync_dir, sync_ops)?; app_handle.db_manager().with_tx(|tx| {
apply_sync_state_ops(&db, workspace_id, sync_dir, sync_state_ops)?; let sync_state_ops = apply_db_sync_ops(tx, &blobs, workspace_id, sync_dir, pending)?;
Ok(()) apply_sync_state_ops(tx, workspace_id, sync_dir, sync_state_ops)?;
Ok(())
})
} }
pub(crate) async fn sync_watch<R, F>( pub(crate) async fn sync_watch<R, F>(
+187 -14
View File
@@ -14,7 +14,6 @@ use tokio::task::block_in_place;
use tokio::time::sleep; use tokio::time::sleep;
use ts_rs::TS; use ts_rs::TS;
use yaak_models::util::generate_id; use yaak_models::util::generate_id;
use yaak_plugins::manager::PluginManager;
use url::Url; use url::Url;
use yaak_api::get_system_proxy_url; use yaak_api::get_system_proxy_url;
@@ -76,14 +75,6 @@ impl YaakUpdater {
auto_download: bool, auto_download: bool,
update_trigger: UpdateTrigger, update_trigger: UpdateTrigger,
) -> Result<bool> { ) -> Result<bool> {
// Only AppImage supports updates on Linux, so skip if it's not
#[cfg(target_os = "linux")]
{
if std::env::var("APPIMAGE").is_err() {
return Ok(false);
}
}
let settings = window.db().get_settings(); let settings = window.db().get_settings();
let update_key = format!("{:x}", md5::compute(settings.id)); let update_key = format!("{:x}", md5::compute(settings.id));
self.last_check = Some(Instant::now()); self.last_check = Some(Instant::now());
@@ -106,8 +97,9 @@ impl YaakUpdater {
block_in_place(|| { block_in_place(|| {
tauri::async_runtime::block_on(async move { tauri::async_runtime::block_on(async move {
info!("Shutting down plugin manager before update"); info!("Shutting down plugin manager before update");
let plugin_manager = w.state::<PluginManager>(); if let Ok(plugin_manager) = crate::plugins_ext::plugin_manager(&w).await {
plugin_manager.terminate().await; plugin_manager.terminate().await;
}
}); });
}); });
}) })
@@ -130,6 +122,18 @@ impl YaakUpdater {
Some(update) => { Some(update) => {
let w = window.clone(); let w = window.clone();
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {
// Only hand the artifact to the updater plugin when this install can
// apply it itself; otherwise tell the user how to update instead
let install = update_install_method(&update);
if install != UpdateInstall::Integrated {
info!(
"{} available, but this install updates via {install:?}",
update.version
);
notify_external_update(&w, &update, install);
return;
}
// Force native updater if specified (useful if a release broke the UI) // Force native updater if specified (useful if a release broke the UI)
let native_install_mode = let native_install_mode =
update.raw_json.get("install_mode").map(|v| v.as_str()).unwrap_or_default() update.raw_json.get("install_mode").map(|v| v.as_str()).unwrap_or_default()
@@ -207,6 +211,23 @@ struct UpdateInfo {
reply_event_id: String, reply_event_id: String,
version: String, version: String,
downloaded: bool, downloaded: bool,
/// How this update gets applied. Anything but `Integrated` means the app can't do it
/// itself and the user is told how to update instead.
install: UpdateInstall,
}
/// How an update can be applied to this install.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Default, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export, export_to = "index.ts")]
enum UpdateInstall {
/// The app downloads and installs it itself
#[default]
Integrated,
/// Flatpak install: updated by `flatpak update` from its remote (e.g. FlatPark)
Flatpak,
/// Nothing can install it in-app (distro package, Nix, unknown); download by hand
Manual,
} }
#[derive(Debug, Clone, PartialEq, Deserialize, TS)] #[derive(Debug, Clone, PartialEq, Deserialize, TS)]
@@ -272,8 +293,12 @@ async fn start_integrated_update<R: Runtime>(
let _guard = Unlisten { win: window, id: event_id }; let _guard = Unlisten { win: window, id: event_id };
// 2) Emit the event now that listener is in place // 2) Emit the event now that listener is in place
let info = let info = UpdateInfo {
UpdateInfo { version: update.version.to_string(), downloaded, reply_event_id: reply_id }; version: update.version.to_string(),
downloaded,
install: UpdateInstall::Integrated,
reply_event_id: reply_id,
};
window window
.emit_to(window.label(), "update_available", &info) .emit_to(window.label(), "update_available", &info)
.map_err(|e| GenericError(format!("Failed to emit update_available: {e}")))?; .map_err(|e| GenericError(format!("Failed to emit update_available: {e}")))?;
@@ -306,6 +331,24 @@ async fn start_integrated_update<R: Runtime>(
} }
} }
/// Tell the frontend about an update this install can't apply itself, so the user can be
/// told how to get it. Unlike the integrated flow, there is nothing to reply to.
fn notify_external_update<R: Runtime>(
window: &WebviewWindow<R>,
update: &Update,
install: UpdateInstall,
) {
let info = UpdateInfo {
version: update.version.to_string(),
downloaded: false,
install,
reply_event_id: generate_id(),
};
if let Err(e) = window.emit_to(window.label(), "update_available", &info) {
warn!("Failed to emit update_available: {e}");
}
}
async fn start_native_update<R: Runtime>(window: &WebviewWindow<R>, update: &Update) { async fn start_native_update<R: Runtime>(window: &WebviewWindow<R>, update: &Update) {
// If the frontend doesn't respond, fallback to native dialogs // If the frontend doesn't respond, fallback to native dialogs
let confirmed = window let confirmed = window
@@ -376,7 +419,137 @@ fn detect_install_mode() -> Option<&'static str> {
return Some("nsis"); return Some("nsis");
} }
#[allow(unreachable_code)] #[allow(unreachable_code)]
None if !cfg!(target_os = "linux") {
None
} else if is_flatpak() {
Some("flatpak")
} else {
linux_installer()
}
}
/// Flatpak installs (e.g. FlatPark) are updated by flatpak from their remote; the in-app
/// updater can't write inside the sandbox and must not try.
fn is_flatpak() -> bool {
std::env::var_os("FLATPAK_ID").is_some()
}
/// How Yaak was installed on Linux, as far as the updater plugin can install into it.
///
/// The bundle type is stamped into the binary by the bundler, but that only says how the
/// binary was *packaged*: third-party packages (AUR, Nix, ...) repackage the .deb, and
/// letting dpkg/rpm replace those would stomp on another package manager's files. So a
/// deb/rpm install also has to be one the package manager actually owns. The AppImage
/// updater needs `$APPIMAGE` since that's the file it replaces.
fn linux_installer() -> Option<&'static str> {
use tauri::utils::{config::BundleType, platform::bundle_type};
match bundle_type() {
Some(BundleType::Deb) if package_manager_owns_exe("dpkg", "-S") => Some("deb"),
Some(BundleType::Rpm) if package_manager_owns_exe("rpm", "-qf") => Some("rpm"),
Some(BundleType::Deb) | Some(BundleType::Rpm) => None,
_ if std::env::var_os("APPIMAGE").is_some() => Some("appimage"),
_ => None,
}
}
/// Whether `cmd query_arg <current exe>` succeeds, i.e. that package manager knows the
/// running executable as one of its files. False when the tool isn't installed at all.
fn package_manager_owns_exe(cmd: &str, query_arg: &str) -> bool {
let Ok(exe) = std::env::current_exe() else {
return false;
};
std::process::Command::new(cmd)
.arg(query_arg)
.arg(&exe)
.stdin(std::process::Stdio::null())
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.map(|status| status.success())
.unwrap_or(false)
}
/// How the artifact the server returned can be applied to this install. On Linux the
/// server may hand back a different package format than the one installed, Flatpak can't
/// be written from inside the sandbox, and unknown install methods (distro packages,
/// Nix, ...) can't be updated in-app at all.
fn update_install_method(update: &Update) -> UpdateInstall {
// Dev-only override to preview the non-integrated flows on any OS:
// YAAK_SIMULATE_INSTALL=flatpak|manual
if is_dev() {
match std::env::var("YAAK_SIMULATE_INSTALL").as_deref() {
Ok("flatpak") => return UpdateInstall::Flatpak,
Ok("manual") => return UpdateInstall::Manual,
_ => {}
}
}
if !cfg!(target_os = "linux") {
return UpdateInstall::Integrated;
}
if is_flatpak() {
return UpdateInstall::Flatpak;
}
if artifact_matches_installer(linux_installer(), update.download_url.path()) {
UpdateInstall::Integrated
} else {
UpdateInstall::Manual
}
}
/// Whether the artifact at `url_path` is in the package format `installer` can install.
fn artifact_matches_installer(installer: Option<&str>, url_path: &str) -> bool {
let path = url_path.to_ascii_lowercase();
match installer {
Some("deb") => path.ends_with(".deb"),
Some("rpm") => path.ends_with(".rpm"),
Some("appimage") => path.ends_with(".appimage") || path.ends_with(".appimage.tar.gz"),
_ => false,
}
}
#[cfg(test)]
mod tests {
use super::artifact_matches_installer;
const BASE: &str = "/mountain-loop/yaak/releases/download/v2026.6.0/";
#[test]
fn matching_package_format_is_installable() {
let cases = [
("deb", "yaak_2026.6.0_amd64.deb"),
("deb", "yaak_2026.6.0_arm64.deb"),
("rpm", "yaak-2026.6.0-1.x86_64.rpm"),
("rpm", "yaak-2026.6.0-1.aarch64.rpm"),
("appimage", "yaak_2026.6.0_amd64.AppImage"),
("appimage", "yaak_2026.6.0_amd64.AppImage.tar.gz"),
];
for (installer, asset) in cases {
assert!(
artifact_matches_installer(Some(installer), &format!("{BASE}{asset}")),
"{installer} should install {asset}"
);
}
}
#[test]
fn mismatched_package_format_is_not_installable() {
// What the server returns for every Linux install today
let appimage = format!("{BASE}yaak_2026.6.0_amd64.AppImage");
assert!(!artifact_matches_installer(Some("deb"), &appimage));
assert!(!artifact_matches_installer(Some("rpm"), &appimage));
let deb = format!("{BASE}yaak_2026.6.0_amd64.deb");
assert!(!artifact_matches_installer(Some("rpm"), &deb));
assert!(!artifact_matches_installer(Some("appimage"), &deb));
}
#[test]
fn unknown_installer_is_never_installable() {
for asset in ["yaak_2026.6.0_amd64.deb", "yaak_2026.6.0_amd64.AppImage"] {
assert!(!artifact_matches_installer(None, &format!("{BASE}{asset}")));
}
}
} }
pub async fn install_update_maybe_download<R: Runtime>( pub async fn install_update_maybe_download<R: Runtime>(
@@ -1,6 +1,6 @@
use crate::PluginContextExt; use crate::PluginContextExt;
use crate::error::Result; use crate::error::Result;
use crate::import::import_data; use crate::import::{file_origin, import_data, url_origin};
use crate::models_ext::QueryManagerExt; use crate::models_ext::QueryManagerExt;
use log::{info, warn}; use log::{info, warn};
use std::collections::HashMap; use std::collections::HashMap;
@@ -12,7 +12,6 @@ use yaak_api::{ApiClientKind, yaak_api_client};
use yaak_models::util::generate_id; use yaak_models::util::generate_id;
use yaak_plugins::events::{Color, ShowToastRequest}; use yaak_plugins::events::{Color, ShowToastRequest};
use yaak_plugins::install::download_and_install; use yaak_plugins::install::download_and_install;
use yaak_plugins::manager::PluginManager;
pub(crate) async fn handle_deep_link<R: Runtime>( pub(crate) async fn handle_deep_link<R: Runtime>(
app_handle: &AppHandle<R>, app_handle: &AppHandle<R>,
@@ -44,7 +43,7 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
return Ok(()); return Ok(());
} }
let plugin_manager = Arc::new((*window.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(window).await?);
let query_manager = app_handle.db_manager(); let query_manager = app_handle.db_manager();
let app_version = app_handle.package_info().version.to_string(); let app_version = app_handle.package_info().version.to_string();
let http_client = yaak_api_client(ApiClientKind::App, &app_version)?; let http_client = yaak_api_client(ApiClientKind::App, &app_version)?;
@@ -70,6 +69,7 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
} }
"import-data" => { "import-data" => {
let mut file_path = query_map.get("path").map(|s| s.to_owned()); let mut file_path = query_map.get("path").map(|s| s.to_owned());
let mut origin = None;
let name = query_map.get("name").map(|s| s.to_owned()).unwrap_or("data".to_string()); let name = query_map.get("name").map(|s| s.to_owned()).unwrap_or("data".to_string());
_ = window.set_focus(); _ = window.set_focus();
@@ -99,6 +99,7 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
.to_string(); .to_string();
fs::write(&p, json)?; fs::write(&p, json)?;
file_path = Some(p); file_path = Some(p);
origin = Some(url_origin(file_url));
} }
let file_path = match file_path { let file_path = match file_path {
@@ -117,7 +118,8 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
} }
}; };
let results = import_data(window, &file_path).await?; let origin = origin.unwrap_or_else(|| file_origin(&file_path));
let results = import_data(window, &file_path, Some(origin)).await?;
window.emit( window.emit(
"show_toast", "show_toast",
ShowToastRequest { ShowToastRequest {
+137 -124
View File
@@ -13,6 +13,7 @@ use tauri::{AppHandle, Manager, Runtime, State, WebviewWindow};
use tokio::sync::{Mutex, mpsc}; use tokio::sync::{Mutex, mpsc};
use tokio_tungstenite::tungstenite::Message; use tokio_tungstenite::tungstenite::Message;
use url::Url; use url::Url;
use yaak_commands::resolve::resolve_websocket_request;
use yaak_crypto::manager::EncryptionManager; use yaak_crypto::manager::EncryptionManager;
use yaak_http::cookies::CookieStore; use yaak_http::cookies::CookieStore;
use yaak_http::path_placeholders::apply_path_placeholders; use yaak_http::path_placeholders::apply_path_placeholders;
@@ -22,12 +23,10 @@ use yaak_models::models::{
}; };
use yaak_models::util::UpdateSource; use yaak_models::util::UpdateSource;
use yaak_plugins::events::{CallHttpAuthenticationRequest, HttpHeader, RenderPurpose}; use yaak_plugins::events::{CallHttpAuthenticationRequest, HttpHeader, RenderPurpose};
use yaak_plugins::manager::PluginManager;
use yaak_plugins::template_callback::PluginTemplateCallback; use yaak_plugins::template_callback::PluginTemplateCallback;
use yaak_templates::strip_json_comments::maybe_strip_json_comments; use yaak_templates::strip_json_comments::maybe_strip_json_comments;
use yaak_templates::{RenderErrorBehavior, RenderOptions}; use yaak_templates::{RenderErrorBehavior, RenderOptions};
use yaak_tls::find_client_certificate; use yaak_tls::find_client_certificate;
use yaak_commands::resolve::resolve_websocket_request;
use yaak_ws::{WebsocketManager, render_websocket_request}; use yaak_ws::{WebsocketManager, render_websocket_request};
pub async fn cmd_ws_send<R: Runtime>( pub async fn cmd_ws_send<R: Runtime>(
@@ -44,18 +43,20 @@ pub async fn cmd_ws_send<R: Runtime>(
{ {
Ok(connection) => Ok(connection), Ok(connection) => Ok(connection),
Err(e) => { Err(e) => {
app_handle.db().upsert_websocket_event( app_handle.with_tx(|tx| {
&WebsocketEvent { tx.upsert_websocket_event(
connection_id: connection.id.clone(), &WebsocketEvent {
request_id: connection.request_id.clone(), connection_id: connection.id.clone(),
workspace_id: connection.workspace_id.clone(), request_id: connection.request_id.clone(),
is_server: false, workspace_id: connection.workspace_id.clone(),
message_type: WebsocketEventType::Error, is_server: false,
message: e.to_string().into(), message_type: WebsocketEventType::Error,
..Default::default() message: e.to_string().into(),
}, ..Default::default()
&UpdateSource::from_window_label(window.label()), },
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
Ok(connection) Ok(connection)
} }
@@ -77,7 +78,7 @@ async fn send_websocket_message<R: Runtime>(
)?; )?;
let (resolved_request, _auth_context_id) = let (resolved_request, _auth_context_id) =
resolve_websocket_request(&window.db(), &unrendered_request)?; resolve_websocket_request(&window.db(), &unrendered_request)?;
let plugin_manager = Arc::new((*app_handle.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(app_handle).await?);
let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone()); let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone());
let request = render_websocket_request( let request = render_websocket_request(
&resolved_request, &resolved_request,
@@ -97,18 +98,20 @@ async fn send_websocket_message<R: Runtime>(
let mut ws_manager = ws_manager.lock().await; let mut ws_manager = ws_manager.lock().await;
ws_manager.send(&connection.id, Message::Text(message.clone().into())).await?; ws_manager.send(&connection.id, Message::Text(message.clone().into())).await?;
app_handle.db().upsert_websocket_event( app_handle.with_tx(|tx| {
&WebsocketEvent { tx.upsert_websocket_event(
connection_id: connection.id.clone(), &WebsocketEvent {
request_id: request.id.clone(), connection_id: connection.id.clone(),
workspace_id: connection.workspace_id.clone(), request_id: request.id.clone(),
is_server: false, workspace_id: connection.workspace_id.clone(),
message_type: WebsocketEventType::Text, is_server: false,
message: message.into(), message_type: WebsocketEventType::Text,
..Default::default() message: message.into(),
}, ..Default::default()
&UpdateSource::from_window_label(window.label()), },
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
Ok(connection.clone()) Ok(connection.clone())
} }
@@ -119,14 +122,13 @@ pub async fn cmd_ws_close<R: Runtime>(
window: WebviewWindow<R>, window: WebviewWindow<R>,
ws_manager: State<'_, Mutex<WebsocketManager>>, ws_manager: State<'_, Mutex<WebsocketManager>>,
) -> Result<WebsocketConnection> { ) -> Result<WebsocketConnection> {
let connection = { let connection = app_handle.with_tx(|tx| {
let db = app_handle.db(); let connection = tx.get_websocket_connection(connection_id)?;
let connection = db.get_websocket_connection(connection_id)?; tx.upsert_websocket_connection(
db.upsert_websocket_connection(
&WebsocketConnection { state: WebsocketConnectionState::Closing, ..connection }, &WebsocketConnection { state: WebsocketConnectionState::Closing, ..connection },
&UpdateSource::from_window_label(window.label()), &UpdateSource::from_window_label(window.label()),
)? )
}; })?;
let mut ws_manager = ws_manager.lock().await; let mut ws_manager = ws_manager.lock().await;
if let Err(e) = ws_manager.close(&connection.id).await { if let Err(e) = ws_manager.close(&connection.id).await {
@@ -142,7 +144,6 @@ pub async fn cmd_ws_connect<R: Runtime>(
cookie_jar_id: Option<&str>, cookie_jar_id: Option<&str>,
app_handle: AppHandle<R>, app_handle: AppHandle<R>,
window: WebviewWindow<R>, window: WebviewWindow<R>,
_plugin_manager: State<'_, PluginManager>,
ws_manager: State<'_, Mutex<WebsocketManager>>, ws_manager: State<'_, Mutex<WebsocketManager>>,
) -> Result<WebsocketConnection> { ) -> Result<WebsocketConnection> {
let unrendered_request = app_handle.db().get_websocket_request(request_id)?; let unrendered_request = app_handle.db().get_websocket_request(request_id)?;
@@ -156,7 +157,7 @@ pub async fn cmd_ws_connect<R: Runtime>(
let settings = app_handle.db().get_settings(); let settings = app_handle.db().get_settings();
let (resolved_request, auth_context_id) = let (resolved_request, auth_context_id) =
resolve_websocket_request(&window.db(), &unrendered_request)?; resolve_websocket_request(&window.db(), &unrendered_request)?;
let plugin_manager = Arc::new((*app_handle.state::<PluginManager>()).clone()); let plugin_manager = Arc::new(crate::plugins_ext::plugin_manager(&app_handle).await?);
let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone()); let encryption_manager = Arc::new((*app_handle.state::<EncryptionManager>()).clone());
let request = render_websocket_request( let request = render_websocket_request(
&resolved_request, &resolved_request,
@@ -171,14 +172,16 @@ pub async fn cmd_ws_connect<R: Runtime>(
) )
.await?; .await?;
let connection = app_handle.db().upsert_websocket_connection( let connection = app_handle.with_tx(|tx| {
&WebsocketConnection { tx.upsert_websocket_connection(
workspace_id: request.workspace_id.clone(), &WebsocketConnection {
request_id: request_id.to_string(), workspace_id: request.workspace_id.clone(),
..Default::default() request_id: request_id.to_string(),
}, ..Default::default()
&UpdateSource::from_window_label(window.label()), },
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
let (mut url, url_parameters) = apply_path_placeholders(&request.url, &request.url_parameters); let (mut url, url_parameters) = apply_path_placeholders(&request.url, &request.url_parameters);
if !url.starts_with("ws://") && !url.starts_with("wss://") { if !url.starts_with("ws://") && !url.starts_with("wss://") {
@@ -189,14 +192,16 @@ pub async fn cmd_ws_connect<R: Runtime>(
let mut url = match Url::parse(&url) { let mut url = match Url::parse(&url) {
Ok(url) => url, Ok(url) => url,
Err(e) => { Err(e) => {
return Ok(app_handle.db().upsert_websocket_connection( return Ok(app_handle.with_tx(|tx| {
&WebsocketConnection { tx.upsert_websocket_connection(
error: Some(format!("Failed to parse URL {}", e.to_string())), &WebsocketConnection {
state: WebsocketConnectionState::Closed, error: Some(format!("Failed to parse URL {}", e.to_string())),
..connection state: WebsocketConnectionState::Closed,
}, ..connection
&UpdateSource::from_window_label(window.label()), },
)?); &UpdateSource::from_window_label(window.label()),
)
})?);
} }
}; };
@@ -323,28 +328,32 @@ pub async fn cmd_ws_connect<R: Runtime>(
{ {
Ok(r) => r, Ok(r) => r,
Err(e) => { Err(e) => {
return Ok(app_handle.db().upsert_websocket_connection( return Ok(app_handle.with_tx(|tx| {
&WebsocketConnection { tx.upsert_websocket_connection(
error: Some(e.to_string()), &WebsocketConnection {
state: WebsocketConnectionState::Closed, error: Some(e.to_string()),
..connection state: WebsocketConnectionState::Closed,
}, ..connection
&UpdateSource::from_window_label(window.label()), },
)?); &UpdateSource::from_window_label(window.label()),
)
})?);
} }
}; };
app_handle.db().upsert_websocket_event( app_handle.with_tx(|tx| {
&WebsocketEvent { tx.upsert_websocket_event(
connection_id: connection.id.clone(), &WebsocketEvent {
request_id: request.id.clone(), connection_id: connection.id.clone(),
workspace_id: connection.workspace_id.clone(), request_id: request.id.clone(),
is_server: false, workspace_id: connection.workspace_id.clone(),
message_type: WebsocketEventType::Open, is_server: false,
..Default::default() message_type: WebsocketEventType::Open,
}, ..Default::default()
&UpdateSource::from_window_label(window.label()), },
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
let response_headers = response let response_headers = response
.headers() .headers()
@@ -368,20 +377,22 @@ pub async fn cmd_ws_connect<R: Runtime>(
if !set_cookie_headers.is_empty() { if !set_cookie_headers.is_empty() {
store.store_cookies_from_response(&convert_ws_url_to_http(&url), &set_cookie_headers); store.store_cookies_from_response(&convert_ws_url_to_http(&url), &set_cookie_headers);
cookie_jar.cookies = store.get_all_cookies(); cookie_jar.cookies = store.get_all_cookies();
app_handle.db().upsert_cookie_jar(cookie_jar, &UpdateSource::Background)?; app_handle.with_tx(|tx| tx.upsert_cookie_jar(cookie_jar, &UpdateSource::Background))?;
} }
} }
let connection = app_handle.db().upsert_websocket_connection( let connection = app_handle.with_tx(|tx| {
&WebsocketConnection { tx.upsert_websocket_connection(
state: WebsocketConnectionState::Connected, &WebsocketConnection {
headers: response_headers, state: WebsocketConnectionState::Connected,
status: response.status().as_u16() as i32, headers: response_headers,
url: request.url.clone(), status: response.status().as_u16() as i32,
..connection url: request.url.clone(),
}, ..connection
&UpdateSource::from_window_label(window.label()), },
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
{ {
let connection_id = connection.id.clone(); let connection_id = connection.id.clone();
@@ -397,57 +408,60 @@ pub async fn cmd_ws_connect<R: Runtime>(
} }
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_websocket_event( tx.upsert_websocket_event(
&WebsocketEvent { &WebsocketEvent {
connection_id: connection_id.clone(), connection_id: connection_id.clone(),
request_id: request_id.clone(), request_id: request_id.clone(),
workspace_id: workspace_id.clone(), workspace_id: workspace_id.clone(),
is_server: true, is_server: true,
message_type: match message { message_type: match message {
Message::Text(_) => WebsocketEventType::Text, Message::Text(_) => WebsocketEventType::Text,
Message::Binary(_) => WebsocketEventType::Binary, Message::Binary(_) => WebsocketEventType::Binary,
Message::Ping(_) => WebsocketEventType::Ping, Message::Ping(_) => WebsocketEventType::Ping,
Message::Pong(_) => WebsocketEventType::Pong, Message::Pong(_) => WebsocketEventType::Pong,
Message::Close(_) => WebsocketEventType::Close, Message::Close(_) => WebsocketEventType::Close,
// Raw frame will never happen during a read // Raw frame will never happen during a read
Message::Frame(_) => WebsocketEventType::Frame, Message::Frame(_) => WebsocketEventType::Frame,
},
message: message.into_data().into(),
..Default::default()
}, },
message: message.into_data().into(), &UpdateSource::from_window_label(&window_label),
..Default::default() )
}, })
&UpdateSource::from_window_label(&window_label),
)
.unwrap(); .unwrap();
} }
info!("Websocket connection closed"); info!("Websocket connection closed");
if !has_written_close { if !has_written_close {
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_websocket_event( tx.upsert_websocket_event(
&WebsocketEvent { &WebsocketEvent {
connection_id: connection_id.clone(), connection_id: connection_id.clone(),
request_id: request_id.clone(), request_id: request_id.clone(),
workspace_id: workspace_id.clone(), workspace_id: workspace_id.clone(),
is_server: true, is_server: true,
message_type: WebsocketEventType::Close, message_type: WebsocketEventType::Close,
..Default::default() ..Default::default()
}, },
&UpdateSource::from_window_label(&window_label), &UpdateSource::from_window_label(&window_label),
) )
})
.unwrap(); .unwrap();
} }
app_handle app_handle
.db() .with_tx(|tx| {
.upsert_websocket_connection( tx.upsert_websocket_connection(
&WebsocketConnection { &WebsocketConnection {
workspace_id: request.workspace_id.clone(), workspace_id: request.workspace_id.clone(),
request_id: request_id.to_string(), request_id: request_id.to_string(),
state: WebsocketConnectionState::Closed, state: WebsocketConnectionState::Closed,
..connection ..connection
}, },
&UpdateSource::from_window_label(&window_label), &UpdateSource::from_window_label(&window_label),
) )
})
.unwrap(); .unwrap();
}); });
} }
@@ -455,7 +469,6 @@ pub async fn cmd_ws_connect<R: Runtime>(
Ok(connection) Ok(connection)
} }
/// Convert WS URL to HTTP URL for cookie filtering /// Convert WS URL to HTTP URL for cookie filtering
/// WebSocket upgrade requests are HTTP requests initially, so HttpOnly cookies should apply /// WebSocket upgrade requests are HTTP requests initially, so HttpOnly cookies should apply
fn convert_ws_url_to_http(ws_url: &Url) -> Url { fn convert_ws_url_to_http(ws_url: &Url) -> Url {
+31 -12
View File
@@ -9,7 +9,7 @@ use tauri::{AppHandle, Emitter, Manager, Runtime, WebviewWindow, is_dev};
use ts_rs::TS; use ts_rs::TS;
use yaak_api::{ApiClientKind, yaak_api_client}; use yaak_api::{ApiClientKind, yaak_api_client};
use yaak_common::platform::get_os_str; use yaak_common::platform::get_os_str;
use yaak_models::client_db::ClientDb; use yaak_models::client_db::{ClientDb, WriteDb};
use yaak_models::query_manager::QueryManager; use yaak_models::query_manager::QueryManager;
use yaak_models::util::UpdateSource; use yaak_models::util::UpdateSource;
@@ -17,6 +17,10 @@ use yaak_models::util::UpdateSource;
/// This is needed temporarily until all crates are refactored to not use Tauri. /// This is needed temporarily until all crates are refactored to not use Tauri.
trait QueryManagerExt<'a, R> { trait QueryManagerExt<'a, R> {
fn db(&'a self) -> ClientDb<'a>; fn db(&'a self) -> ClientDb<'a>;
fn with_tx<T>(
&'a self,
func: impl FnOnce(&WriteDb) -> yaak_models::error::Result<T>,
) -> yaak_models::error::Result<T>;
} }
impl<'a, R: Runtime, M: Manager<R>> QueryManagerExt<'a, R> for M { impl<'a, R: Runtime, M: Manager<R>> QueryManagerExt<'a, R> for M {
@@ -24,6 +28,14 @@ impl<'a, R: Runtime, M: Manager<R>> QueryManagerExt<'a, R> for M {
let qm = self.state::<QueryManager>(); let qm = self.state::<QueryManager>();
qm.inner().connect() qm.inner().connect()
} }
fn with_tx<T>(
&'a self,
func: impl FnOnce(&WriteDb) -> yaak_models::error::Result<T>,
) -> yaak_models::error::Result<T> {
let qm = self.state::<QueryManager>();
qm.inner().with_tx(func)
}
} }
const KV_NAMESPACE: &str = "license"; const KV_NAMESPACE: &str = "license";
@@ -137,12 +149,17 @@ pub async fn activate_license<R: Runtime>(
} }
let body: ActivateLicenseResponsePayload = response.json().await?; let body: ActivateLicenseResponsePayload = response.json().await?;
window.app_handle().db().set_key_value_str( if let Err(e) = window.app_handle().with_tx(|tx| {
KV_ACTIVATION_ID_KEY, tx.set_key_value_str(
KV_NAMESPACE, KV_ACTIVATION_ID_KEY,
body.activation_id.as_str(), KV_NAMESPACE,
&UpdateSource::from_window_label(window.label()), body.activation_id.as_str(),
); &UpdateSource::from_window_label(window.label()),
);
Ok(())
}) {
warn!("Failed to store license activation: {e}");
}
if let Err(e) = window.emit("license-activated", true) { if let Err(e) = window.emit("license-activated", true) {
warn!("Failed to emit check-license event: {}", e); warn!("Failed to emit check-license event: {}", e);
@@ -172,11 +189,13 @@ pub async fn deactivate_license<R: Runtime>(window: &WebviewWindow<R>) -> Result
return Err(ServerError); return Err(ServerError);
} }
app_handle.db().delete_key_value( app_handle.with_tx(|tx| {
KV_ACTIVATION_ID_KEY, tx.delete_key_value(
KV_NAMESPACE, KV_ACTIVATION_ID_KEY,
&UpdateSource::from_window_label(window.label()), KV_NAMESPACE,
)?; &UpdateSource::from_window_label(window.label()),
)
})?;
if let Err(e) = app_handle.emit("license-deactivated", true) { if let Err(e) = app_handle.emit("license-deactivated", true) {
warn!("Failed to emit deactivate-license event: {}", e); warn!("Failed to emit deactivate-license event: {}", e);
@@ -4,9 +4,14 @@ version = "0.1.0"
edition = "2024" edition = "2024"
publish = false publish = false
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
dark-light = "2.0.0" dark-light = "2.0.0"
[target.'cfg(target_os = "macos")'.dependencies]
dispatch2 = "0.3.0"
objc2-app-kit = { version = "0.3.1", features = ["NSAppearance", "NSApplication", "NSResponder"] }
objc2-foundation = { version = "0.3.1", features = ["NSArray", "NSString", "NSUserDefaults"] }
[dependencies] [dependencies]
log = { workspace = true } log = { workspace = true }
tauri = { workspace = true } tauri = { workspace = true }
+74 -12
View File
@@ -1,5 +1,5 @@
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(target_os = "linux")]
use std::time::Duration; use std::time::Duration;
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "linux", target_os = "macos"))]
@@ -11,7 +11,7 @@ use tauri::{AppHandle, Runtime};
pub const INITIAL_APPEARANCE_GLOBAL: &str = "__YAAK_INITIAL_APPEARANCE__"; pub const INITIAL_APPEARANCE_GLOBAL: &str = "__YAAK_INITIAL_APPEARANCE__";
pub const SYSTEM_APPEARANCE_CHANGE_EVENT: &str = "system_appearance_change"; pub const SYSTEM_APPEARANCE_CHANGE_EVENT: &str = "system_appearance_change";
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(target_os = "linux")]
const SYSTEM_APPEARANCE_POLL_INTERVAL: Duration = Duration::from_secs(1); const SYSTEM_APPEARANCE_POLL_INTERVAL: Duration = Duration::from_secs(1);
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -47,14 +47,12 @@ pub fn initialization_script(appearance: Appearance) -> String {
/// Detect the appearance the OS prefers, independent of any appearance that has /// Detect the appearance the OS prefers, independent of any appearance that has
/// been forced onto app windows (which is what the webview itself reports). /// been forced onto app windows (which is what the webview itself reports).
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(target_os = "linux")]
pub fn system_appearance() -> Option<Appearance> { pub fn system_appearance() -> Option<Appearance> {
#[cfg(target_os = "linux")]
if let Some(appearance) = gsettings_system_appearance() { if let Some(appearance) = gsettings_system_appearance() {
return Some(appearance); return Some(appearance);
} }
// On macOS this reads AppleInterfaceStyle from the global user defaults
match dark_light::detect() { match dark_light::detect() {
Ok(dark_light::Mode::Dark) => Some(Appearance::Dark), Ok(dark_light::Mode::Dark) => Some(Appearance::Dark),
Ok(dark_light::Mode::Light) => Some(Appearance::Light), Ok(dark_light::Mode::Light) => Some(Appearance::Light),
@@ -66,11 +64,69 @@ pub fn system_appearance() -> Option<Appearance> {
} }
} }
/// Detect the appearance the OS prefers, independent of any appearance that has
/// been forced onto app windows (which is what the webview itself reports).
///
/// This asks AppKit for the application's effective appearance, the same source tauri
/// uses for `window.theme()`, instead of reading `AppleInterfaceStyle` from the user
/// defaults: macOS 27 no longer reliably writes that key when dark mode is on, so anything
/// reading it sees light mode. Appearances forced per window (yaak-mac-window) don't reach
/// `NSApp`, so this is the OS preference.
#[cfg(target_os = "macos")]
pub fn system_appearance() -> Option<Appearance> {
use objc2_app_kit::{NSAppearanceNameAqua, NSAppearanceNameDarkAqua, NSApplication};
use objc2_foundation::NSArray;
// AppKit is main-thread only. Every caller runs there today; this keeps it correct if
// one ever doesn't.
dispatch2::run_on_main(|mtm| {
let app = NSApplication::sharedApplication(mtm);
// An appearance forced on the whole app (tauri's `set_theme` does this) would make
// the effective appearance report the override instead of the OS preference. Nothing
// in Yaak does that, but fall back to the user defaults if something ever does.
//
// SAFETY: Called on the main thread with the shared application
if unsafe { app.appearance() }.is_some() {
return defaults_appearance();
}
// SAFETY: The appearance names are AppKit constants that live for the whole process
let (dark, light) = unsafe { (NSAppearanceNameDarkAqua, NSAppearanceNameAqua) };
let names = NSArray::from_slice(&[dark, light]);
let best = app.effectiveAppearance().bestMatchFromAppearancesWithNames(&names)?;
// SAFETY: Both are valid strings
let is_dark = unsafe { best.isEqualToString(dark) };
Some(if is_dark { Appearance::Dark } else { Appearance::Light })
})
}
/// The appearance macOS persists to the global user defaults. Absent means light, except
/// on macOS 27, which stopped reliably writing the key. Only used when the effective
/// appearance is forced and can't be trusted.
#[cfg(target_os = "macos")]
fn defaults_appearance() -> Option<Appearance> {
use objc2_foundation::{NSUserDefaults, ns_string};
// SAFETY: The standard defaults are a process-wide singleton and the key is a valid string
let style = unsafe {
NSUserDefaults::standardUserDefaults().stringForKey(ns_string!("AppleInterfaceStyle"))
};
// SAFETY: Both are valid strings
let is_dark = style.is_some_and(|style| unsafe { style.isEqualToString(ns_string!("Dark")) });
Some(if is_dark { Appearance::Dark } else { Appearance::Light })
}
#[cfg(not(any(target_os = "linux", target_os = "macos")))] #[cfg(not(any(target_os = "linux", target_os = "macos")))]
pub fn system_appearance() -> Option<Appearance> { pub fn system_appearance() -> Option<Appearance> {
None None
} }
/// Start tracking the OS appearance. Linux polls for changes. macOS gets them from tauri's
/// `WindowEvent::ThemeChanged` (tao observes `AppleInterfaceThemeChangedNotification`), which
/// the app forwards to [`emit_change`], so no thread is needed there.
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(any(target_os = "linux", target_os = "macos"))]
pub fn watch<R: Runtime>(app_handle: AppHandle<R>) -> Option<SystemAppearanceState> { pub fn watch<R: Runtime>(app_handle: AppHandle<R>) -> Option<SystemAppearanceState> {
let last_appearance = system_appearance(); let last_appearance = system_appearance();
@@ -80,13 +136,19 @@ pub fn watch<R: Runtime>(app_handle: AppHandle<R>) -> Option<SystemAppearanceSta
} }
let state = SystemAppearanceState { last_appearance: Arc::new(Mutex::new(last_appearance)) }; let state = SystemAppearanceState { last_appearance: Arc::new(Mutex::new(last_appearance)) };
let thread_state = state.clone();
let _ = std::thread::spawn(move || { #[cfg(target_os = "linux")]
loop { {
std::thread::sleep(SYSTEM_APPEARANCE_POLL_INTERVAL); let thread_state = state.clone();
emit_change(&app_handle, &thread_state); let _ = std::thread::spawn(move || {
} loop {
}); std::thread::sleep(SYSTEM_APPEARANCE_POLL_INTERVAL);
emit_change(&app_handle, &thread_state);
}
});
}
#[cfg(target_os = "macos")]
let _ = app_handle;
Some(state) Some(state)
} }
+2 -1
View File
@@ -21,7 +21,8 @@
//! the second ask. Sharing the handle instead makes nested *reads* work the way //! the second ask. Sharing the handle instead makes nested *reads* work the way
//! they do on the desktop; nested *write transactions* fail on both, only //! they do on the desktop; nested *write transactions* fail on both, only
//! differently (here SQLite refuses the inner `BEGIN`; natively the inner //! differently (here SQLite refuses the inner `BEGIN`; natively the inner
//! connection blocks on `busy_timeout` and then fails). //! call waits for the one writer connection, which the outer call holds, and
//! times out).
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
mod imp { mod imp {
@@ -20,7 +20,9 @@ impl UpdateSource {
#[derive(Debug, Clone, Serialize, Deserialize, TS)] #[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[serde(rename_all = "snake_case", tag = "type")] #[serde(rename_all = "snake_case", tag = "type")]
pub enum ModelChangeEvent { pub enum ModelChangeEvent {
Upsert { created: bool }, Upsert {
created: bool,
},
/// A delete for a workspace implies deletion of every model in that /// A delete for a workspace implies deletion of every model in that
/// workspace — children are bulk-deleted without their own change rows or /// workspace — children are bulk-deleted without their own change rows or
/// events, and consumers must prune the subtree themselves (the frontend /// events, and consumers must prune the subtree themselves (the frontend
+465 -70
View File
@@ -1,127 +1,522 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type AnyModel = CookieJar | Environment | Folder | GraphQlIntrospection | GrpcConnection | GrpcEvent | GrpcRequest | HttpRequest | HttpResponse | HttpResponseEvent | KeyValue | Plugin | Settings | SyncState | WebsocketConnection | WebsocketEvent | WebsocketRequest | Workspace | WorkspaceMeta; export type AnyModel =
| CookieJar
| Environment
| Folder
| GraphQlIntrospection
| GrpcConnection
| GrpcEvent
| GrpcRequest
| HttpRequest
| HttpResponse
| HttpResponseEvent
| ImportSource
| KeyValue
| Plugin
| Settings
| SyncState
| WebsocketConnection
| WebsocketEvent
| WebsocketRequest
| Workspace
| WorkspaceMeta;
export type ClientCertificate = { host: string, port: number | null, crtFile: string | null, keyFile: string | null, pfxFile: string | null, passphrase: string | null, enabled?: boolean, }; export type ClientCertificate = {
host: string;
port: number | null;
crtFile: string | null;
keyFile: string | null;
pfxFile: string | null;
passphrase: string | null;
enabled?: boolean;
};
export type Cookie = { name: string, value: string, domain: CookieDomain, expires: CookieExpires, path: string, secure: boolean, httpOnly: boolean, sameSite: CookieSameSite | null, }; export type Cookie = {
name: string;
value: string;
domain: CookieDomain;
expires: CookieExpires;
path: string;
secure: boolean;
httpOnly: boolean;
sameSite: CookieSameSite | null;
};
export type CookieDomain = { "HostOnly": string } | { "Suffix": string } | "NotPresent" | "Empty"; export type CookieDomain = { HostOnly: string } | { Suffix: string } | "NotPresent" | "Empty";
export type CookieExpires = { "AtUtc": string } | "SessionEnd"; export type CookieExpires = { AtUtc: string } | "SessionEnd";
export type CookieJar = { model: "cookie_jar", id: string, createdAt: string, updatedAt: string, workspaceId: string, cookies: Array<Cookie>, name: string, }; export type CookieJar = {
model: "cookie_jar";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
cookies: Array<Cookie>;
name: string;
};
export type CookieSameSite = "Strict" | "Lax" | "None"; export type CookieSameSite = "Strict" | "Lax" | "None";
export type DnsOverride = { hostname: string, ipv4: Array<string>, ipv6: Array<string>, enabled?: boolean, }; export type DnsOverride = {
hostname: string;
ipv4: Array<string>;
ipv6: Array<string>;
enabled?: boolean;
};
export type EditorKeymap = "default" | "vim" | "vscode" | "emacs"; export type EditorKeymap = "default" | "vim" | "vscode" | "emacs";
export type EncryptedKey = { encryptedKey: string, }; export type EncryptedKey = { encryptedKey: string };
export type Environment = { model: "environment", id: string, workspaceId: string, createdAt: string, updatedAt: string, name: string, public: boolean, parentModel: string, parentId: string | null, export type Environment = {
/** model: "environment";
* Variables defined in this environment scope. id: string;
* Child environments override parent variables by name. workspaceId: string;
*/ createdAt: string;
variables: Array<EnvironmentVariable>, color: string | null, sortPriority: number, }; updatedAt: string;
name: string;
public: boolean;
parentModel: string;
parentId: string | null;
/**
* Variables defined in this environment scope.
* Child environments override parent variables by name.
*/
variables: Array<EnvironmentVariable>;
color: string | null;
sortPriority: number;
};
export type EnvironmentVariable = { enabled?: boolean, name: string, value: string, id?: string, }; export type EnvironmentVariable = { enabled?: boolean; name: string; value: string; id?: string };
export type Folder = { model: "folder", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authentication: Record<string, any>, authenticationType: string | null, description: string, headers: Array<HttpRequestHeader>, name: string, sortPriority: number, settingSendCookies: InheritedBoolSetting, settingStoreCookies: InheritedBoolSetting, settingValidateCertificates: InheritedBoolSetting, settingFollowRedirects: InheritedBoolSetting, settingRequestTimeout: InheritedIntSetting, settingRequestMessageSize: InheritedIntSetting, }; export type Folder = {
model: "folder";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
folderId: string | null;
authentication: Record<string, any>;
authenticationType: string | null;
description: string;
headers: Array<HttpRequestHeader>;
name: string;
sortPriority: number;
settingSendCookies: InheritedBoolSetting;
settingStoreCookies: InheritedBoolSetting;
settingValidateCertificates: InheritedBoolSetting;
settingFollowRedirects: InheritedBoolSetting;
settingRequestTimeout: InheritedIntSetting;
settingRequestMessageSize: InheritedIntSetting;
settingHttpVersion: InheritedHttpVersionSetting;
};
export type GraphQlIntrospection = { model: "graphql_introspection", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, content: string | null, }; export type GraphQlIntrospection = {
model: "graphql_introspection";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
requestId: string;
content: string | null;
};
export type GrpcConnection = { model: "grpc_connection", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, elapsed: number, error: string | null, method: string, service: string, status: number, state: GrpcConnectionState, trailers: { [key in string]?: string }, url: string, }; export type GrpcConnection = {
model: "grpc_connection";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
requestId: string;
elapsed: number;
error: string | null;
method: string;
service: string;
status: number;
state: GrpcConnectionState;
trailers: { [key in string]?: string };
url: string;
};
export type GrpcConnectionState = "initialized" | "connected" | "closed"; export type GrpcConnectionState = "initialized" | "connected" | "closed";
export type GrpcEvent = { model: "grpc_event", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, connectionId: string, content: string, error: string | null, eventType: GrpcEventType, metadata: { [key in string]?: string }, status: number | null, }; export type GrpcEvent = {
model: "grpc_event";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
requestId: string;
connectionId: string;
content: string;
error: string | null;
eventType: GrpcEventType;
metadata: { [key in string]?: string };
status: number | null;
};
export type GrpcEventType = "info" | "error" | "client_message" | "server_message" | "connection_start" | "connection_end"; export type GrpcEventType =
| "info"
| "error"
| "client_message"
| "server_message"
| "connection_start"
| "connection_end";
export type GrpcRequest = { model: "grpc_request", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authenticationType: string | null, authentication: Record<string, any>, description: string, message: string, metadata: Array<HttpRequestHeader>, method: string | null, name: string, service: string | null, sortPriority: number, export type GrpcRequest = {
/** model: "grpc_request";
* Server URL (http for plaintext or https for secure) id: string;
*/ createdAt: string;
url: string, settingValidateCertificates: InheritedBoolSetting, settingRequestMessageSize: InheritedIntSetting, }; updatedAt: string;
workspaceId: string;
folderId: string | null;
authenticationType: string | null;
authentication: Record<string, any>;
description: string;
message: string;
metadata: Array<HttpRequestHeader>;
method: string | null;
name: string;
service: string | null;
sortPriority: number;
/**
* Server URL (http for plaintext or https for secure)
*/
url: string;
settingValidateCertificates: InheritedBoolSetting;
settingRequestMessageSize: InheritedIntSetting;
};
export type HttpRequest = { model: "http_request", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authentication: Record<string, any>, authenticationType: string | null, body: Record<string, any>, bodyType: string | null, description: string, headers: Array<HttpRequestHeader>, method: string, name: string, sortPriority: number, url: string, export type HttpRequest = {
/** model: "http_request";
* URL parameters used for both path placeholders (`:id`) and query string entries. id: string;
*/ createdAt: string;
urlParameters: Array<HttpUrlParameter>, settingSendCookies: InheritedBoolSetting, settingStoreCookies: InheritedBoolSetting, settingValidateCertificates: InheritedBoolSetting, settingFollowRedirects: InheritedBoolSetting, settingRequestTimeout: InheritedIntSetting, }; updatedAt: string;
workspaceId: string;
folderId: string | null;
authentication: Record<string, any>;
authenticationType: string | null;
body: Record<string, any>;
bodyType: string | null;
description: string;
headers: Array<HttpRequestHeader>;
method: string;
name: string;
sortPriority: number;
url: string;
/**
* URL parameters used for both path placeholders (`:id`) and query string entries.
*/
urlParameters: Array<HttpUrlParameter>;
settingSendCookies: InheritedBoolSetting;
settingStoreCookies: InheritedBoolSetting;
settingValidateCertificates: InheritedBoolSetting;
settingFollowRedirects: InheritedBoolSetting;
settingRequestTimeout: InheritedIntSetting;
settingHttpVersion: InheritedHttpVersionSetting;
};
export type HttpRequestHeader = { enabled?: boolean, name: string, value: string, id?: string, }; export type HttpRequestHeader = { enabled?: boolean; name: string; value: string; id?: string };
export type HttpResponse = { model: "http_response", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, contentLength: number | null, contentLengthCompressed: number | null, elapsed: number, elapsedHeaders: number, elapsedDns: number, error: string | null, headers: Array<HttpResponseHeader>, remoteAddr: string | null, requestContentLength: number | null, requestHeaders: Array<HttpResponseHeader>, status: number, statusReason: string | null, state: HttpResponseState, url: string, version: string | null, }; export type HttpResponse = {
model: "http_response";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
requestId: string;
contentLength: number | null;
contentLengthCompressed: number | null;
elapsed: number;
elapsedHeaders: number;
elapsedDns: number;
error: string | null;
headers: Array<HttpResponseHeader>;
remoteAddr: string | null;
requestContentLength: number | null;
requestHeaders: Array<HttpResponseHeader>;
status: number;
statusReason: string | null;
state: HttpResponseState;
url: string;
version: string | null;
};
export type HttpResponseEvent = { model: "http_response_event", id: string, createdAt: string, updatedAt: string, workspaceId: string, responseId: string, event: HttpResponseEventData, }; export type HttpResponseEvent = {
model: "http_response_event";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
responseId: string;
event: HttpResponseEventData;
};
/** /**
* Serializable representation of HTTP response events for DB storage. * Serializable representation of HTTP response events for DB storage.
* This mirrors `yaak_http::sender::HttpResponseEvent` but with serde support. * This mirrors `yaak_http::sender::HttpResponseEvent` but with serde support.
* The `From` impl is in yaak-http to avoid circular dependencies. * The `From` impl is in yaak-http to avoid circular dependencies.
*/ */
export type HttpResponseEventData = { "type": "setting", name: string, value: string, source_model?: string, source_id?: string, source_name?: string, } | { "type": "info", message: string, } | { "type": "redirect", url: string, status: number, behavior: string, dropped_body: boolean, dropped_headers: Array<string>, } | { "type": "send_url", method: string, scheme: string, username: string, password: string, host: string, port: number, path: string, query: string, fragment: string, } | { "type": "receive_url", version: string, status: string, } | { "type": "header_up", name: string, value: string, } | { "type": "header_down", name: string, value: string, } | { "type": "chunk_sent", bytes: number, } | { "type": "chunk_received", bytes: number, } | { "type": "dns_resolved", hostname: string, addresses: Array<string>, duration: bigint, overridden: boolean, }; export type HttpResponseEventData =
| {
type: "setting";
name: string;
value: string;
source_model?: string;
source_id?: string;
source_name?: string;
}
| { type: "info"; message: string }
| {
type: "redirect";
url: string;
status: number;
behavior: string;
dropped_body: boolean;
dropped_headers: Array<string>;
}
| {
type: "send_url";
method: string;
scheme: string;
username: string;
password: string;
host: string;
port: number;
path: string;
query: string;
fragment: string;
}
| { type: "receive_url"; version: string; status: string }
| { type: "header_up"; name: string; value: string }
| { type: "header_down"; name: string; value: string }
| { type: "chunk_sent"; bytes: number }
| { type: "chunk_received"; bytes: number }
| {
type: "dns_resolved";
hostname: string;
addresses: Array<string>;
duration: bigint;
overridden: boolean;
};
export type HttpResponseHeader = { name: string, value: string, }; export type HttpResponseHeader = { name: string; value: string };
export type HttpResponseState = "initialized" | "connected" | "closed"; export type HttpResponseState = "initialized" | "connected" | "closed";
/** export type HttpUrlParameter = {
* The resolved send settings, values only: what an executor has to obey, with the sources enabled?: boolean;
* (which model each came from) left behind in [`ResolvedHttpRequestSettings`]. This is what /**
* crosses from a tab to the Yaak server, and what the server reads. * Colon-prefixed parameters are treated as path parameters if they match, like `/users/:id`
*/ * Other entries are appended as query parameters
export type HttpSendSettings = { validateCertificates: boolean, followRedirects: boolean, */
/** name: string;
* Milliseconds. Zero or negative means no timeout. value: string;
*/ id?: string;
timeoutMs: number, sendCookies: boolean, storeCookies: boolean, }; };
export type HttpUrlParameter = { enabled?: boolean, export type HttpVersion = "auto" | "http1" | "http2";
/**
* Colon-prefixed parameters are treated as path parameters if they match, like `/users/:id`
* Other entries are appended as query parameters
*/
name: string, value: string, id?: string, };
export type InheritedBoolSetting = { enabled?: boolean, value: boolean, }; export type ImportSource = {
model: "import_source";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
importer: string;
origin: string;
originLabel: string;
lastImportedAt: string;
};
export type InheritedIntSetting = { enabled?: boolean, value: number, }; export type InheritedBoolSetting = { enabled?: boolean; value: boolean };
export type KeyValue = { model: "key_value", id: string, createdAt: string, updatedAt: string, key: string, namespace: string, value: string, }; export type InheritedHttpVersionSetting = { enabled?: boolean; value: HttpVersion };
export type Plugin = { model: "plugin", id: string, createdAt: string, updatedAt: string, checkedAt: string | null, directory: string, enabled: boolean, url: string | null, source: PluginSource, }; export type InheritedIntSetting = { enabled?: boolean; value: number };
export type KeyValue = {
model: "key_value";
id: string;
createdAt: string;
updatedAt: string;
key: string;
namespace: string;
value: string;
};
export type Plugin = {
model: "plugin";
id: string;
createdAt: string;
updatedAt: string;
checkedAt: string | null;
directory: string;
enabled: boolean;
url: string | null;
source: PluginSource;
};
export type PluginSource = "bundled" | "filesystem" | "registry"; export type PluginSource = "bundled" | "filesystem" | "registry";
export type ProxySetting = { "type": "enabled", http: string, https: string, auth: ProxySettingAuth | null, bypass: string, disabled: boolean, } | { "type": "disabled" }; export type ProxySetting =
| {
type: "enabled";
http: string;
https: string;
auth: ProxySettingAuth | null;
bypass: string;
disabled: boolean;
}
| { type: "disabled" };
export type ProxySettingAuth = { user: string, password: string, }; export type ProxySettingAuth = { user: string; password: string };
export type Settings = { model: "settings", id: string, createdAt: string, updatedAt: string, appearance: string, clientCertificates: Array<ClientCertificate>, coloredMethods: boolean, editorFont: string | null, editorFontSize: number, editorKeymap: EditorKeymap, editorSoftWrap: boolean, hideWindowControls: boolean, useNativeTitlebar: boolean, interfaceFont: string | null, interfaceFontSize: number, interfaceScale: number, openWorkspaceNewWindow: boolean | null, proxy: ProxySetting | null, themeDark: string, themeLight: string, updateChannel: string, hideLicenseBadge: boolean, promptFeedback: boolean, autoupdate: boolean, autoDownloadUpdates: boolean, checkNotifications: boolean, hotkeys: { [key in string]?: Array<string> }, }; export type Settings = {
model: "settings";
id: string;
createdAt: string;
updatedAt: string;
appearance: string;
clientCertificates: Array<ClientCertificate>;
coloredMethods: boolean;
editorFont: string | null;
editorFontSize: number;
editorKeymap: EditorKeymap;
editorSoftWrap: boolean;
hideWindowControls: boolean;
useNativeTitlebar: boolean;
interfaceFont: string | null;
interfaceFontSize: number;
interfaceScale: number;
openWorkspaceNewWindow: boolean | null;
proxy: ProxySetting | null;
themeDark: string;
themeLight: string;
updateChannel: string;
hideLicenseBadge: boolean;
promptFeedback: boolean;
autoupdate: boolean;
autoDownloadUpdates: boolean;
checkNotifications: boolean;
hotkeys: { [key in string]?: Array<string> };
};
export type SyncModel = { "type": "workspace" } & Workspace | { "type": "environment" } & Environment | { "type": "folder" } & Folder | { "type": "http_request" } & HttpRequest | { "type": "grpc_request" } & GrpcRequest | { "type": "websocket_request" } & WebsocketRequest; export type SyncModel =
| ({ type: "workspace" } & Workspace)
| ({ type: "environment" } & Environment)
| ({ type: "folder" } & Folder)
| ({ type: "http_request" } & HttpRequest)
| ({ type: "grpc_request" } & GrpcRequest)
| ({ type: "websocket_request" } & WebsocketRequest);
export type SyncState = { model: "sync_state", id: string, workspaceId: string, createdAt: string, updatedAt: string, flushedAt: string, modelId: string, checksum: string, relPath: string, syncDir: string, }; export type SyncState = {
model: "sync_state";
id: string;
workspaceId: string;
createdAt: string;
updatedAt: string;
flushedAt: string;
modelId: string;
checksum: string;
relPath: string;
syncDir: string;
};
export type WebsocketConnection = { model: "websocket_connection", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, elapsed: number, error: string | null, headers: Array<HttpResponseHeader>, state: WebsocketConnectionState, status: number, url: string, }; export type WebsocketConnection = {
model: "websocket_connection";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
requestId: string;
elapsed: number;
error: string | null;
headers: Array<HttpResponseHeader>;
state: WebsocketConnectionState;
status: number;
url: string;
};
export type WebsocketConnectionState = "initialized" | "connected" | "closing" | "closed"; export type WebsocketConnectionState = "initialized" | "connected" | "closing" | "closed";
export type WebsocketEvent = { model: "websocket_event", id: string, createdAt: string, updatedAt: string, workspaceId: string, requestId: string, connectionId: string, isServer: boolean, message: Array<number>, messageType: WebsocketEventType, }; export type WebsocketEvent = {
model: "websocket_event";
id: string;
createdAt: string;
updatedAt: string;
workspaceId: string;
requestId: string;
connectionId: string;
isServer: boolean;
message: Array<number>;
messageType: WebsocketEventType;
};
export type WebsocketEventType = "binary" | "close" | "error" | "frame" | "open" | "ping" | "pong" | "text"; export type WebsocketEventType =
| "binary"
| "close"
| "error"
| "frame"
| "open"
| "ping"
| "pong"
| "text";
export type WebsocketRequest = { model: "websocket_request", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authentication: Record<string, any>, authenticationType: string | null, description: string, headers: Array<HttpRequestHeader>, message: string, name: string, sortPriority: number, url: string, export type WebsocketRequest = {
/** model: "websocket_request";
* URL parameters used for both path placeholders (`:id`) and query string entries. id: string;
*/ createdAt: string;
urlParameters: Array<HttpUrlParameter>, settingSendCookies: InheritedBoolSetting, settingStoreCookies: InheritedBoolSetting, settingValidateCertificates: InheritedBoolSetting, settingRequestMessageSize: InheritedIntSetting, }; updatedAt: string;
workspaceId: string;
folderId: string | null;
authentication: Record<string, any>;
authenticationType: string | null;
description: string;
headers: Array<HttpRequestHeader>;
message: string;
name: string;
sortPriority: number;
url: string;
/**
* URL parameters used for both path placeholders (`:id`) and query string entries.
*/
urlParameters: Array<HttpUrlParameter>;
settingSendCookies: InheritedBoolSetting;
settingStoreCookies: InheritedBoolSetting;
settingValidateCertificates: InheritedBoolSetting;
settingRequestMessageSize: InheritedIntSetting;
};
export type Workspace = { model: "workspace", id: string, createdAt: string, updatedAt: string, authentication: Record<string, any>, authenticationType: string | null, description: string, headers: Array<HttpRequestHeader>, name: string, encryptionKeyChallenge: string | null, settingValidateCertificates: boolean, settingFollowRedirects: boolean, settingRequestTimeout: number, settingRequestMessageSize: number, settingDnsOverrides: Array<DnsOverride>, settingSendCookies: boolean, settingStoreCookies: boolean, }; export type Workspace = {
model: "workspace";
id: string;
createdAt: string;
updatedAt: string;
authentication: Record<string, any>;
authenticationType: string | null;
description: string;
headers: Array<HttpRequestHeader>;
name: string;
encryptionKeyChallenge: string | null;
settingValidateCertificates: boolean;
settingFollowRedirects: boolean;
settingRequestTimeout: number;
settingRequestMessageSize: number;
settingDnsOverrides: Array<DnsOverride>;
settingSendCookies: boolean;
settingStoreCookies: boolean;
settingHttpVersion: HttpVersion;
};
export type WorkspaceMeta = { model: "workspace_meta", id: string, workspaceId: string, createdAt: string, updatedAt: string, encryptionKey: EncryptedKey | null, settingSyncDir: string | null, }; export type WorkspaceMeta = {
model: "workspace_meta";
id: string;
workspaceId: string;
createdAt: string;
updatedAt: string;
encryptionKey: EncryptedKey | null;
settingSyncDir: string | null;
};
+11 -5
View File
@@ -3,10 +3,10 @@ import type { PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse } f
import type { CallFolderActionRequest, CallGrpcRequestActionRequest, CallHttpRequestActionRequest, CallWebsocketRequestActionRequest, CallWorkspaceActionRequest, FilterResponse, GetFolderActionsResponse, GetGrpcRequestActionsResponse, GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse, GetHttpRequestActionsResponse, GetTemplateFunctionConfigResponse, GetTemplateFunctionSummaryResponse, GetThemesResponse, GetWebsocketRequestActionsResponse, GetWorkspaceActionsResponse, JsonPrimitive, RenderPurpose } from "./gen_events"; import type { CallFolderActionRequest, CallGrpcRequestActionRequest, CallHttpRequestActionRequest, CallWebsocketRequestActionRequest, CallWorkspaceActionRequest, FilterResponse, GetFolderActionsResponse, GetGrpcRequestActionsResponse, GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse, GetHttpRequestActionsResponse, GetTemplateFunctionConfigResponse, GetTemplateFunctionSummaryResponse, GetThemesResponse, GetWebsocketRequestActionsResponse, GetWorkspaceActionsResponse, JsonPrimitive, RenderPurpose } from "./gen_events";
import type { BranchDeleteResult, CloneResult, GitBranchInfo, GitCommit, GitFileDiff, GitRemote, GitStatusSummary, GitWorktreeStatus, PullResult, PushResult } from "./gen_git"; import type { BranchDeleteResult, CloneResult, GitBranchInfo, GitCommit, GitFileDiff, GitRemote, GitStatusSummary, GitWorktreeStatus, PullResult, PushResult } from "./gen_git";
import type { ServiceDefinition } from "./gen_grpc"; import type { ServiceDefinition } from "./gen_grpc";
import type { AnyModel, GraphQlIntrospection, GrpcEvent, HttpRequest, HttpRequestHeader, HttpResponse, HttpResponseEvent, Plugin, Settings, WebsocketConnection, WebsocketEvent, WorkspaceMeta } from "./gen_models"; import type { AnyModel, GraphQlIntrospection, GrpcEvent, HttpRequest, HttpRequestHeader, HttpResponse, HttpResponseEvent, ImportSource, Plugin, Settings, WebsocketConnection, WebsocketEvent, WorkspaceMeta } from "./gen_models";
import type { PluginMetadata } from "./gen_search"; import type { PluginMetadata } from "./gen_search";
import type { SyncOp } from "./gen_sync"; import type { SyncOp } from "./gen_sync";
import type { BatchUpsertResult } from "./gen_util"; import type { BatchUpsertResult, ImportDestination, ImportPlan } from "./gen_util";
import type { Tokens } from "./parser"; import type { Tokens } from "./parser";
import type { ServerSentEvent } from "./sse"; import type { ServerSentEvent } from "./sse";
@@ -29,6 +29,8 @@ export type CmdCallWorkspaceActionReq = { req: CallWorkspaceActionRequest, };
export type CmdCheckForUpdatesReq = Record<string, never>; export type CmdCheckForUpdatesReq = Record<string, never>;
export type CmdCommitImportReq = { plan: ImportPlan, };
export type CmdCurlToRequestReq = { command: string, workspaceId: string, }; export type CmdCurlToRequestReq = { command: string, workspaceId: string, };
export type CmdDecryptTemplateReq = { template: string, }; export type CmdDecryptTemplateReq = { template: string, };
@@ -141,9 +143,13 @@ export type CmdHttpResponseBodyPathReq = { responseId: string, };
export type CmdHttpResponseBodyReq = { responseId: string, filter: string | null, }; export type CmdHttpResponseBodyReq = { responseId: string, filter: string | null, };
export type CmdImportDataReq = { filePath: string, }; export type CmdImportDataReq = { filePath: string, destination: ImportDestination, };
export type CmdImportUrlReq = { url: string, }; export type CmdImportSourcesForOriginReq = { filePath?: string, url?: string, };
export type CmdImportUrlReq = { url: string, destination: ImportDestination, };
export type CmdListImportSourcesReq = { workspaceId: string, };
export type CmdMetadataReq = Record<string, never>; export type CmdMetadataReq = Record<string, never>;
@@ -248,6 +254,6 @@ export type ModelsWebsocketEventsReq = { connectionId: string, };
export type ModelsWorkspaceModelsReq = { workspaceId: string | null, }; export type ModelsWorkspaceModelsReq = { workspaceId: string | null, };
export type RpcSchema = { cmd_metadata: [CmdMetadataReq, AppMetaData], cmd_template_tokens_to_string: [CmdTemplateTokensToStringReq, string], cmd_render_template: [CmdRenderTemplateReq, string], cmd_send_feedback: [CmdSendFeedbackReq, null], cmd_dismiss_notification: [CmdDismissNotificationReq, null], cmd_grpc_reflect: [CmdGrpcReflectReq, Array<ServiceDefinition>], cmd_grpc_go: [CmdGrpcGoReq, string], cmd_restart: [CmdRestartReq, null], cmd_send_ephemeral_request: [CmdSendEphemeralRequestReq, EphemeralHttpResponse], cmd_format_json: [CmdFormatJsonReq, string], cmd_format_graphql: [CmdFormatGraphqlReq, string], cmd_http_response_body: [CmdHttpResponseBodyReq, FilterResponse], cmd_http_response_body_path: [CmdHttpResponseBodyPathReq, string | null], cmd_http_request_body: [CmdHttpRequestBodyReq, Array<number> | null], cmd_get_sse_events: [CmdGetSseEventsReq, Array<ServerSentEvent>], cmd_get_http_response_events: [CmdGetHttpResponseEventsReq, Array<HttpResponseEvent>], cmd_import_data: [CmdImportDataReq, BatchUpsertResult], cmd_import_url: [CmdImportUrlReq, BatchUpsertResult], cmd_http_request_actions: [CmdHttpRequestActionsReq, Array<GetHttpRequestActionsResponse>], cmd_websocket_request_actions: [CmdWebsocketRequestActionsReq, Array<GetWebsocketRequestActionsResponse>], cmd_call_websocket_request_action: [CmdCallWebsocketRequestActionReq, null], cmd_workspace_actions: [CmdWorkspaceActionsReq, Array<GetWorkspaceActionsResponse>], cmd_call_workspace_action: [CmdCallWorkspaceActionReq, null], cmd_folder_actions: [CmdFolderActionsReq, Array<GetFolderActionsResponse>], cmd_call_folder_action: [CmdCallFolderActionReq, null], cmd_grpc_request_actions: [CmdGrpcRequestActionsReq, Array<GetGrpcRequestActionsResponse>], cmd_template_function_summaries: [CmdTemplateFunctionSummariesReq, Array<GetTemplateFunctionSummaryResponse>], cmd_template_function_config: [CmdTemplateFunctionConfigReq, GetTemplateFunctionConfigResponse], cmd_get_http_authentication_summaries: [CmdGetHttpAuthenticationSummariesReq, Array<GetHttpAuthenticationSummaryResponse>], cmd_get_http_authentication_config: [CmdGetHttpAuthenticationConfigReq, GetHttpAuthenticationConfigResponse], cmd_call_http_request_action: [CmdCallHttpRequestActionReq, null], cmd_call_grpc_request_action: [CmdCallGrpcRequestActionReq, null], cmd_call_http_authentication_action: [CmdCallHttpAuthenticationActionReq, null], cmd_curl_to_request: [CmdCurlToRequestReq, HttpRequest], cmd_export_data: [CmdExportDataReq, null], cmd_save_base64_to_binary: [CmdSaveBase64ToBinaryReq, null], cmd_save_response: [CmdSaveResponseReq, null], cmd_send_http_request: [CmdSendHttpRequestReq, HttpResponse], cmd_reload_plugins: [CmdReloadPluginsReq, Array<[string, string]>], cmd_plugin_info: [CmdPluginInfoReq, PluginMetadata], cmd_delete_all_grpc_connections: [CmdDeleteAllGrpcConnectionsReq, null], cmd_delete_send_history: [CmdDeleteSendHistoryReq, null], cmd_delete_all_http_responses: [CmdDeleteAllHttpResponsesReq, null], cmd_get_workspace_meta: [CmdGetWorkspaceMetaReq, WorkspaceMeta], cmd_new_child_window: [CmdNewChildWindowReq, null], cmd_new_main_window: [CmdNewMainWindowReq, null], cmd_check_for_updates: [CmdCheckForUpdatesReq, boolean], cmd_decrypt_template: [CmdDecryptTemplateReq, string], cmd_secure_template: [CmdSecureTemplateReq, string], cmd_get_themes: [CmdGetThemesReq, Array<GetThemesResponse>], cmd_enable_encryption: [CmdEnableEncryptionReq, null], cmd_reveal_workspace_key: [CmdRevealWorkspaceKeyReq, string], cmd_set_workspace_key: [CmdSetWorkspaceKeyReq, null], cmd_disable_encryption: [CmdDisableEncryptionReq, null], cmd_default_headers: [CmdDefaultHeadersReq, Array<HttpRequestHeader>], models_upsert: [ModelsUpsertReq, string], models_delete: [ModelsDeleteReq, string], models_duplicate: [ModelsDuplicateReq, string], models_websocket_events: [ModelsWebsocketEventsReq, Array<WebsocketEvent>], models_grpc_events: [ModelsGrpcEventsReq, Array<GrpcEvent>], models_get_settings: [ModelsGetSettingsReq, Settings], models_get_graphql_introspection: [ModelsGetGraphqlIntrospectionReq, GraphQlIntrospection | null], models_upsert_graphql_introspection: [ModelsUpsertGraphqlIntrospectionReq, GraphQlIntrospection], models_workspace_models: [ModelsWorkspaceModelsReq, string], cmd_git_checkout: [CmdGitCheckoutReq, string], cmd_git_branch: [CmdGitBranchReq, null], cmd_git_delete_branch: [CmdGitDeleteBranchReq, BranchDeleteResult], cmd_git_delete_remote_branch: [CmdGitDeleteRemoteBranchReq, null], cmd_git_merge_branch: [CmdGitMergeBranchReq, null], cmd_git_rename_branch: [CmdGitRenameBranchReq, null], cmd_git_status: [CmdGitStatusReq, GitStatusSummary], cmd_git_branch_info: [CmdGitBranchInfoReq, GitBranchInfo], cmd_git_worktree_status: [CmdGitWorktreeStatusReq, GitWorktreeStatus], cmd_git_log: [CmdGitLogReq, Array<GitCommit>], cmd_git_log_for_file: [CmdGitLogForFileReq, Array<GitCommit>], cmd_git_file_diff_for_commit: [CmdGitFileDiffForCommitReq, GitFileDiff], cmd_git_initialize: [CmdGitInitializeReq, nuLine truncated export type RpcSchema = { cmd_metadata: [CmdMetadataReq, AppMetaData], cmd_template_tokens_to_string: [CmdTemplateTokensToStringReq, string], cmd_render_template: [CmdRenderTemplateReq, string], cmd_send_feedback: [CmdSendFeedbackReq, null], cmd_dismiss_notification: [CmdDismissNotificationReq, null], cmd_grpc_reflect: [CmdGrpcReflectReq, Array<ServiceDefinition>], cmd_grpc_go: [CmdGrpcGoReq, string], cmd_restart: [CmdRestartReq, null], cmd_send_ephemeral_request: [CmdSendEphemeralRequestReq, EphemeralHttpResponse], cmd_format_json: [CmdFormatJsonReq, string], cmd_format_graphql: [CmdFormatGraphqlReq, string], cmd_http_response_body: [CmdHttpResponseBodyReq, FilterResponse], cmd_http_response_body_path: [CmdHttpResponseBodyPathReq, string | null], cmd_http_request_body: [CmdHttpRequestBodyReq, Array<number> | null], cmd_get_sse_events: [CmdGetSseEventsReq, Array<ServerSentEvent>], cmd_get_http_response_events: [CmdGetHttpResponseEventsReq, Array<HttpResponseEvent>], cmd_import_data: [CmdImportDataReq, ImportPlan], cmd_import_url: [CmdImportUrlReq, ImportPlan], cmd_commit_import: [CmdCommitImportReq, BatchUpsertResult], cmd_list_import_sources: [CmdListImportSourcesReq, Array<ImportSource>], cmd_import_sources_for_origin: [CmdImportSourcesForOriginReq, Array<ImportSource>], cmd_http_request_actions: [CmdHttpRequestActionsReq, Array<GetHttpRequestActionsResponse>], cmd_websocket_request_actions: [CmdWebsocketRequestActionsReq, Array<GetWebsocketRequestActionsResponse>], cmd_call_websocket_request_action: [CmdCallWebsocketRequestActionReq, null], cmd_workspace_actions: [CmdWorkspaceActionsReq, Array<GetWorkspaceActionsResponse>], cmd_call_workspace_action: [CmdCallWorkspaceActionReq, null], cmd_folder_actions: [CmdFolderActionsReq, Array<GetFolderActionsResponse>], cmd_call_folder_action: [CmdCallFolderActionReq, null], cmd_grpc_request_actions: [CmdGrpcRequestActionsReq, Array<GetGrpcRequestActionsResponse>], cmd_template_function_summaries: [CmdTemplateFunctionSummariesReq, Array<GetTemplateFunctionSummaryResponse>], cmd_template_function_config: [CmdTemplateFunctionConfigReq, GetTemplateFunctionConfigResponse], cmd_get_http_authentication_summaries: [CmdGetHttpAuthenticationSummariesReq, Array<GetHttpAuthenticationSummaryResponse>], cmd_get_http_authentication_config: [CmdGetHttpAuthenticationConfigReq, GetHttpAuthenticationConfigResponse], cmd_call_http_request_action: [CmdCallHttpRequestActionReq, null], cmd_call_grpc_request_action: [CmdCallGrpcRequestActionReq, null], cmd_call_http_authentication_action: [CmdCallHttpAuthenticationActionReq, null], cmd_curl_to_request: [CmdCurlToRequestReq, HttpRequest], cmd_export_data: [CmdExportDataReq, null], cmd_save_base64_to_binary: [CmdSaveBase64ToBinaryReq, null], cmd_save_response: [CmdSaveResponseReq, null], cmd_send_http_request: [CmdSendHttpRequestReq, HttpResponse], cmd_reload_plugins: [CmdReloadPluginsReq, Array<[string, string]>], cmd_plugin_info: [CmdPluginInfoReq, PluginMetadata], cmd_delete_all_grpc_connections: [CmdDeleteAllGrpcConnectionsReq, null], cmd_delete_send_history: [CmdDeleteSendHistoryReq, null], cmd_delete_all_http_responses: [CmdDeleteAllHttpResponsesReq, null], cmd_get_workspace_meta: [CmdGetWorkspaceMetaReq, WorkspaceMeta], cmd_new_child_window: [CmdNewChildWindowReq, null], cmd_new_main_window: [CmdNewMainWindowReq, null], cmd_check_for_updates: [CmdCheckForUpdatesReq, boolean], cmd_decrypt_template: [CmdDecryptTemplateReq, string], cmd_secure_template: [CmdSecureTemplateReq, string], cmd_get_themes: [CmdGetThemesReq, Array<GetThemesResponse>], cmd_enable_encryption: [CmdEnableEncryptionReq, null], cmd_reveal_workspace_key: [CmdRevealWorkspaceKeyReq, string], cmd_set_workspace_key: [CmdSetWorkspaceKeyReq, null], cmd_disable_encryption: [CmdDisableEncryptionReq, null], cmd_default_headers: [CmdDefaultHeadersReq, Array<HttpRequestHeader>], models_upsert: [ModelsUpsertReq, string], models_delete: [ModelsDeleteReq, string], models_duplicate: [ModelsDuplicateReq, string], models_websocket_events: [ModelsWebsocketEventsReq, Array<WebsocketEvent>], models_grpc_events: [ModelsGrpcEventsReq, Array<GrpcEvent>], models_get_settings: [ModelsGetSettingsReq, Settings], models_get_graphql_introspection: [ModelsGetGraphqlIntrospectionReq, GraphQlIntrospection | null], models_upsert_graphql_introspection: [ModelsUpsertGraphqlIntrospectionReq, GraphQlIntrospection], models_workspace_models: [ModelsWorkspaceModelsReq, string], cmd_git_checkout: [CmdGitCheckoutReq, string], cmd_git_branch: [CmdGitBranchReq, null], cmd_git_delete_branch: [CmdGitDeleteBranchReq, BranchDeleteResult], cmd_git_delete_remote_branch: [CmdGitDeleteRemoteBranchReq, null], cmd_git_merge_branch: [CmdGitMergeBranchReq, null], cmd_git_rename_branch: [CmdGitRenameBranchReq, null], cmd_git_status: [CmdGitStatusReq, GitStatusSummary], cmd_git_branch_info: [CmdGitBranchInfoReq, GitBranchInfo], cmd_git_worktree_status: [CmdGitWorktreeStatusReq, GitWorktreeStatus], cmd_git_log: [CmdGitLogRLine truncated
export type WatchResult = { unlistenEvent: string, }; export type WatchResult = { unlistenEvent: string, };
+105 -2
View File
@@ -1,4 +1,107 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Environment, Folder, GrpcRequest, HttpRequest, WebsocketRequest, Workspace } from "./gen_models"; import type {
Environment,
Folder,
GrpcRequest,
HttpRequest,
WebsocketRequest,
Workspace,
} from "./gen_models";
export type BatchUpsertResult = { workspaces: Array<Workspace>, environments: Array<Environment>, folders: Array<Folder>, httpRequests: Array<HttpRequest>, grpcRequests: Array<GrpcRequest>, websocketRequests: Array<WebsocketRequest>, }; export type BatchUpsertResult = {
workspaces: Array<Workspace>;
environments: Array<Environment>;
folders: Array<Folder>;
httpRequests: Array<HttpRequest>;
grpcRequests: Array<GrpcRequest>;
websocketRequests: Array<WebsocketRequest>;
};
export type ImportConflictResolution = "keep_mine" | "take_source";
/**
* Where a staged import will be committed.
*
* The destination workspace and optional folder IDs are captured in the plan so the preview describes
* the exact destination that confirmation will use.
*/
export type ImportDestination =
| { type: "new_workspace" }
| { type: "existing_workspace"; workspaceId: string; folderId?: string };
/**
* Where an import's contents came from, used to link the committed workspace back to it.
*/
export type ImportOrigin = {
/**
* The absolute file path or URL the contents were read from.
*/
origin: string;
label: string;
};
export type ImportPlan = {
importer: string;
destination: ImportDestination;
resources: BatchUpsertResult;
warnings: Array<ImportPlanWarning>;
/**
* Stable source key for every model in `resources`, keyed by its planned ID.
*/
sourceKeys: { [key in string]?: string };
/**
* One entry per plannable resource; commit applies only the selected ones.
*/
items: Array<ImportPlanItem>;
origin?: ImportOrigin;
};
export type ImportPlanAction =
| "create"
| "update"
| "delete"
| "unchanged"
| "keep_local"
| "conflict"
| "ignored";
export type ImportPlanItem = {
action: ImportPlanAction;
model: ImportResourceType;
modelId: string;
name: string;
/**
* Planned parent folder ID for incoming resources; current parent for deletions.
*/
parentId?: string;
selected: boolean;
resolution?: ImportConflictResolution;
reason?: ImportPlanReason;
/**
* Fields where the source and the local copy disagree, so the preview can say why
*/
changedFields: Array<string>;
};
/**
* Extra context for an action that would otherwise be indistinguishable from its plain form.
*/
export type ImportPlanReason = "moved_into_ignored_folder";
export type ImportPlanWarning = { title: string; detail: string; level: ImportPlanWarningLevel };
/**
* Whether a plan's note is something to know or something to think twice about.
*/
export type ImportPlanWarningLevel = "info" | "warning";
/**
* The model types an import plan can contain.
*/
export type ImportResourceType =
| "environment"
| "folder"
| "grpc_request"
| "http_request"
| "websocket_request"
| "workspace";
+38 -9
View File
@@ -21,18 +21,18 @@ use yaak_git::{
use yaak_grpc::ServiceDefinition; use yaak_grpc::ServiceDefinition;
use yaak_models::models::{ use yaak_models::models::{
AnyModel, GraphQlIntrospection, GrpcEvent, HttpRequest, HttpRequestHeader, HttpResponse, AnyModel, GraphQlIntrospection, GrpcEvent, HttpRequest, HttpRequestHeader, HttpResponse,
HttpResponseEvent, Plugin, Settings, WebsocketConnection, WebsocketEvent, WorkspaceMeta, HttpResponseEvent, ImportSource, Plugin, Settings, WebsocketConnection, WebsocketEvent,
WorkspaceMeta,
}; };
use yaak_models::util::BatchUpsertResult; use yaak_models::util::{BatchUpsertResult, ImportDestination, ImportPlan};
use yaak_plugins::api::{PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse}; use yaak_plugins::api::{PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse};
use yaak_plugins::events::{ use yaak_plugins::events::{
CallFolderActionRequest, CallGrpcRequestActionRequest, CallHttpRequestActionRequest, CallFolderActionRequest, CallGrpcRequestActionRequest, CallHttpRequestActionRequest,
CallWebsocketRequestActionRequest, CallWorkspaceActionRequest, FilterResponse, CallWebsocketRequestActionRequest, CallWorkspaceActionRequest, FilterResponse,
GetFolderActionsResponse, GetGrpcRequestActionsResponse, GetFolderActionsResponse, GetGrpcRequestActionsResponse, GetHttpAuthenticationConfigResponse,
GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse, GetHttpAuthenticationSummaryResponse, GetHttpRequestActionsResponse,
GetHttpRequestActionsResponse, GetTemplateFunctionConfigResponse, GetTemplateFunctionConfigResponse, GetTemplateFunctionSummaryResponse, GetThemesResponse,
GetTemplateFunctionSummaryResponse, GetThemesResponse, GetWebsocketRequestActionsResponse, GetWebsocketRequestActionsResponse, GetWorkspaceActionsResponse, JsonPrimitive, RenderPurpose,
GetWorkspaceActionsResponse, JsonPrimitive, RenderPurpose,
}; };
use yaak_plugins::plugin_meta::PluginMetadata; use yaak_plugins::plugin_meta::PluginMetadata;
use yaak_sse::sse::ServerSentEvent; use yaak_sse::sse::ServerSentEvent;
@@ -229,6 +229,7 @@ pub struct CmdGetHttpResponseEventsReq {
#[ts(export, export_to = "gen_rpc.ts")] #[ts(export, export_to = "gen_rpc.ts")]
pub struct CmdImportDataReq { pub struct CmdImportDataReq {
pub file_path: String, pub file_path: String,
pub destination: ImportDestination,
} }
#[derive(Debug, Deserialize, TS)] #[derive(Debug, Deserialize, TS)]
@@ -236,6 +237,31 @@ pub struct CmdImportDataReq {
#[ts(export, export_to = "gen_rpc.ts")] #[ts(export, export_to = "gen_rpc.ts")]
pub struct CmdImportUrlReq { pub struct CmdImportUrlReq {
pub url: String, pub url: String,
pub destination: ImportDestination,
}
#[derive(Debug, Deserialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "gen_rpc.ts")]
pub struct CmdCommitImportReq {
pub plan: ImportPlan,
}
#[derive(Debug, Deserialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "gen_rpc.ts")]
pub struct CmdListImportSourcesReq {
pub workspace_id: String,
}
#[derive(Debug, Deserialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export, export_to = "gen_rpc.ts")]
pub struct CmdImportSourcesForOriginReq {
#[ts(optional)]
pub file_path: Option<String>,
#[ts(optional)]
pub url: Option<String>,
} }
#[derive(Debug, Deserialize, TS)] #[derive(Debug, Deserialize, TS)]
@@ -909,8 +935,11 @@ macro_rules! with_commands {
cmd_http_request_body(CmdHttpRequestBodyReq) -> Option<Vec<u8>>, cmd_http_request_body(CmdHttpRequestBodyReq) -> Option<Vec<u8>>,
cmd_get_sse_events(CmdGetSseEventsReq) -> Vec<ServerSentEvent>, cmd_get_sse_events(CmdGetSseEventsReq) -> Vec<ServerSentEvent>,
cmd_get_http_response_events(CmdGetHttpResponseEventsReq) -> Vec<HttpResponseEvent>, cmd_get_http_response_events(CmdGetHttpResponseEventsReq) -> Vec<HttpResponseEvent>,
cmd_import_data(CmdImportDataReq) -> BatchUpsertResult, cmd_import_data(CmdImportDataReq) -> ImportPlan,
cmd_import_url(CmdImportUrlReq) -> BatchUpsertResult, cmd_import_url(CmdImportUrlReq) -> ImportPlan,
cmd_commit_import(CmdCommitImportReq) -> BatchUpsertResult,
cmd_list_import_sources(CmdListImportSourcesReq) -> Vec<ImportSource>,
cmd_import_sources_for_origin(CmdImportSourcesForOriginReq) -> Vec<ImportSource>,
cmd_http_request_actions(CmdHttpRequestActionsReq) -> Vec<GetHttpRequestActionsResponse>, cmd_http_request_actions(CmdHttpRequestActionsReq) -> Vec<GetHttpRequestActionsResponse>,
cmd_websocket_request_actions(CmdWebsocketRequestActionsReq) -> Vec<GetWebsocketRequestActionsResponse>, cmd_websocket_request_actions(CmdWebsocketRequestActionsReq) -> Vec<GetWebsocketRequestActionsResponse>,
cmd_call_websocket_request_action(CmdCallWebsocketRequestActionReq) -> (), cmd_call_websocket_request_action(CmdCallWebsocketRequestActionReq) -> (),
+5 -5
View File
@@ -13,8 +13,9 @@ pub type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send + 'static>>;
/// `dispatch` call frame, so it cannot borrow, and contexts are cheap clones /// `dispatch` call frame, so it cannot borrow, and contexts are cheap clones
/// (handles and `Arc`s). Synchronous handlers wrap into this via `rpc_handler!` /// (handles and `Arc`s). Synchronous handlers wrap into this via `rpc_handler!`
/// with no visible change. /// with no visible change.
type HandlerFn<Ctx> = type HandlerFn<Ctx> = Box<
Box<dyn Fn(Ctx, serde_json::Value) -> BoxFuture<Result<serde_json::Value, RpcError>> + Send + Sync>; dyn Fn(Ctx, serde_json::Value) -> BoxFuture<Result<serde_json::Value, RpcError>> + Send + Sync,
>;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RpcError { pub struct RpcError {
@@ -249,9 +250,8 @@ macro_rules! rpc_handler_async {
Box::new(|ctx, payload| { Box::new(|ctx, payload| {
Box::pin(async move { Box::pin(async move {
let req = serde_json::from_value(payload).map_err($crate::RpcError::from)?; let req = serde_json::from_value(payload).map_err($crate::RpcError::from)?;
let res = $f(ctx, req) let res =
.await $f(ctx, req).await.map_err(|e| $crate::RpcError { message: e.to_string() })?;
.map_err(|e| $crate::RpcError { message: e.to_string() })?;
serde_json::to_value(res).map_err($crate::RpcError::from) serde_json::to_value(res).map_err($crate::RpcError::from)
}) })
}) })
+5 -45
View File
@@ -6,14 +6,11 @@
//! own environment chain before a plugin sees them, or an auth plugin receives //! own environment chain before a plugin sees them, or an auth plugin receives
//! `${[ api_key ]}` where it expected a key. //! `${[ api_key ]}` where it expected a key.
use crate::error::{Error, Result}; use crate::error::Result;
use crate::host::PluginHost; use crate::host::PluginHost;
use crate::render::render_json_value; use crate::render::render_form_values;
use std::collections::HashMap;
use yaak_models::models::AnyModel;
use yaak_plugins::events::{ use yaak_plugins::events::{
GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse, JsonPrimitive, GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse, RenderPurpose,
RenderPurpose,
}; };
use yaak_rpc_schema::*; use yaak_rpc_schema::*;
use yaak_templates::RenderOptions; use yaak_templates::RenderOptions;
@@ -31,7 +28,7 @@ pub async fn cmd_get_http_authentication_config<H: PluginHost>(
) -> Result<GetHttpAuthenticationConfigResponse> { ) -> Result<GetHttpAuthenticationConfigResponse> {
// A config form is being displayed, so a template that cannot resolve // A config form is being displayed, so a template that cannot resolve
// should show as blank rather than refuse to open the form. // should show as blank rather than refuse to open the form.
let values = render_auth_values( let values = render_form_values(
&host, &host,
&req.model, &req.model,
req.environment_id.as_deref(), req.environment_id.as_deref(),
@@ -50,7 +47,7 @@ pub async fn cmd_call_http_authentication_action<H: PluginHost>(
) -> Result<()> { ) -> Result<()> {
// An action actually uses these values, so an unresolvable template is an // An action actually uses these values, so an unresolvable template is an
// error rather than an empty string that would silently authenticate wrong. // error rather than an empty string that would silently authenticate wrong.
let values = render_auth_values( let values = render_form_values(
&host, &host,
&req.model, &req.model,
req.environment_id.as_deref(), req.environment_id.as_deref(),
@@ -63,40 +60,3 @@ pub async fn cmd_call_http_authentication_action<H: PluginHost>(
host.call_http_authentication_action(&req.auth_name, req.action_index, values, req.model.id()) host.call_http_authentication_action(&req.auth_name, req.action_index, values, req.model.id())
.await .await
} }
/// Render the form's values against the environment chain the model sits in.
///
/// The chain depends on where the model lives — a request inherits through its
/// folder, a workspace has only its own — so the model is what decides which
/// variables are in scope.
async fn render_auth_values<H: PluginHost>(
host: &H,
model: &AnyModel,
environment_id: Option<&str>,
values: HashMap<String, JsonPrimitive>,
purpose: RenderPurpose,
options: &RenderOptions,
) -> Result<HashMap<String, JsonPrimitive>> {
let (workspace_id, folder_id) = match model {
AnyModel::HttpRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
AnyModel::GrpcRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
AnyModel::WebsocketRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
AnyModel::Folder(f) => (f.workspace_id.clone(), f.folder_id.clone()),
AnyModel::Workspace(w) => (w.id.clone(), None),
other => {
return Err(Error::Generic(format!(
"Cannot resolve authentication for a {}",
other.model()
)));
}
};
let environment_chain =
host.db().resolve_environments(&workspace_id, folder_id.as_deref(), environment_id)?;
let cb = host.template_callback(purpose);
let rendered =
render_json_value(serde_json::to_value(&values)?, environment_chain, &cb, options).await?;
Ok(serde_json::from_value(rendered)?)
}
+8 -2
View File
@@ -72,7 +72,7 @@ pub trait Host: Clone {
self.query_manager().connect() self.query_manager().connect()
} }
fn blobs(&self) -> BlobContext { fn blobs(&self) -> BlobContext<'_> {
self.blob_manager().connect() self.blob_manager().connect()
} }
} }
@@ -121,7 +121,12 @@ pub trait PluginHost: Host {
/// a render — the variables come from the environment chain, which is an /// a render — the variables come from the environment chain, which is an
/// ordinary database read — so handing back the callback keeps the rest of /// ordinary database read — so handing back the callback keeps the rest of
/// rendering shared instead of pushing whole commands behind this trait. /// rendering shared instead of pushing whole commands behind this trait.
fn template_callback(&self, purpose: RenderPurpose) -> impl TemplateCallback; /// Async so hosts that finish booting their plugin runtime in the
/// background can wait for it here.
fn template_callback(
&self,
purpose: RenderPurpose,
) -> impl Future<Output = crate::Result<impl TemplateCallback>>;
/// Every template function the installed plugins expose, for the /// Every template function the installed plugins expose, for the
/// autocomplete menu. /// autocomplete menu.
@@ -130,6 +135,7 @@ pub trait PluginHost: Host {
) -> impl Future<Output = crate::Result<Vec<GetTemplateFunctionSummaryResponse>>>; ) -> impl Future<Output = crate::Result<Vec<GetTemplateFunctionSummaryResponse>>>;
/// The form a template function wants to show for the given values. /// The form a template function wants to show for the given values.
/// `values` arrive already rendered.
fn template_function_config( fn template_function_config(
&self, &self,
function_name: &str, function_name: &str,
+25 -17
View File
@@ -11,10 +11,11 @@ use yaak_models::queries::workspaces::default_headers;
use yaak_rpc_schema::*; use yaak_rpc_schema::*;
pub async fn models_upsert<H: Host>(host: H, req: ModelsUpsertReq) -> Result<String> { pub async fn models_upsert<H: Host>(host: H, req: ModelsUpsertReq) -> Result<String> {
let db = host.db();
let blobs = host.blob_manager(); let blobs = host.blob_manager();
let source = host.update_source(); let source = host.update_source();
Ok(yaak_models::models_ops::upsert_model(&db, blobs, req.model, &source)?) Ok(host
.query_manager()
.with_tx(|tx| yaak_models::models_ops::upsert_model(tx, blobs, req.model, &source))?)
} }
/// Deletes cascade — a workspace can hold thousands of requests — and run in a /// Deletes cascade — a workspace can hold thousands of requests — and run in a
@@ -75,12 +76,9 @@ pub async fn models_upsert_graphql_introspection<H: Host>(
req: ModelsUpsertGraphqlIntrospectionReq, req: ModelsUpsertGraphqlIntrospectionReq,
) -> Result<GraphQlIntrospection> { ) -> Result<GraphQlIntrospection> {
let source = host.update_source(); let source = host.update_source();
Ok(host.db().upsert_graphql_introspection( Ok(host.query_manager().with_tx(|tx| {
&req.workspace_id, tx.upsert_graphql_introspection(&req.workspace_id, &req.request_id, req.content, &source)
&req.request_id, })?)
req.content,
&source,
)?)
} }
/// Everything the frontend's model store needs to boot, as one JSON string. /// Everything the frontend's model store needs to boot, as one JSON string.
@@ -112,9 +110,16 @@ pub async fn models_workspace_models<H: PluginHost>(
// Add the workspace children // Add the workspace children
if let Some(wid) = req.workspace_id.as_deref() { if let Some(wid) = req.workspace_id.as_deref() {
// Opening a workspace is where the rows it is assumed to have get created
host.query_manager().with_tx(|tx| {
tx.ensure_base_environment(wid)?;
tx.ensure_default_cookie_jar(wid)?;
tx.ensure_workspace_meta(wid)?;
Ok::<(), yaak_models::error::Error>(())
})?;
let db = host.db(); let db = host.db();
l.append(&mut db.list_cookie_jars(wid)?.into_iter().map(Into::into).collect()); l.append(&mut db.list_cookie_jars(wid)?.into_iter().map(Into::into).collect());
l.append(&mut db.list_environments_ensure_base(wid)?.into_iter().map(Into::into).collect()); l.append(&mut db.list_environments(wid)?.into_iter().map(Into::into).collect());
l.append(&mut db.list_folders(wid)?.into_iter().map(Into::into).collect()); l.append(&mut db.list_folders(wid)?.into_iter().map(Into::into).collect());
l.append(&mut db.list_grpc_connections(wid)?.into_iter().map(Into::into).collect()); l.append(&mut db.list_grpc_connections(wid)?.into_iter().map(Into::into).collect());
l.append(&mut db.list_grpc_requests(wid)?.into_iter().map(Into::into).collect()); l.append(&mut db.list_grpc_requests(wid)?.into_iter().map(Into::into).collect());
@@ -132,23 +137,26 @@ pub async fn cmd_get_workspace_meta<H: Host>(
host: H, host: H,
req: CmdGetWorkspaceMetaReq, req: CmdGetWorkspaceMetaReq,
) -> Result<WorkspaceMeta> { ) -> Result<WorkspaceMeta> {
let db = host.db(); let workspace = host.db().get_workspace(&req.workspace_id)?;
let workspace = db.get_workspace(&req.workspace_id)?; Ok(host.query_manager().with_tx(|tx| tx.ensure_workspace_meta(&workspace.id))?)
Ok(db.get_or_create_workspace_meta(&workspace.id)?)
} }
pub async fn cmd_delete_all_grpc_connections<H: Host>( pub async fn cmd_delete_all_grpc_connections<H: Host>(
host: H, host: H,
req: CmdDeleteAllGrpcConnectionsReq, req: CmdDeleteAllGrpcConnectionsReq,
) -> Result<()> { ) -> Result<()> {
Ok(host.db().delete_all_grpc_connections_for_request(&req.request_id, &host.update_source())?) Ok(host.query_manager().with_tx(|tx| {
tx.delete_all_grpc_connections_for_request(&req.request_id, &host.update_source())
})?)
} }
pub async fn cmd_delete_all_http_responses<H: Host>( pub async fn cmd_delete_all_http_responses<H: Host>(
host: H, host: H,
req: CmdDeleteAllHttpResponsesReq, req: CmdDeleteAllHttpResponsesReq,
) -> Result<()> { ) -> Result<()> {
host.db().delete_all_http_responses_for_request(&req.request_id, &host.update_source())?; host.query_manager().with_tx(|tx| {
tx.delete_all_http_responses_for_request(&req.request_id, &host.update_source())
})?;
Ok(()) Ok(())
} }
@@ -156,9 +164,9 @@ pub async fn cmd_ws_delete_connections<H: Host>(
host: H, host: H,
req: CmdWsDeleteConnectionsReq, req: CmdWsDeleteConnectionsReq,
) -> Result<()> { ) -> Result<()> {
Ok(host Ok(host.query_manager().with_tx(|tx| {
.db() tx.delete_all_websocket_connections_for_request(&req.request_id, &host.update_source())
.delete_all_websocket_connections_for_request(&req.request_id, &host.update_source())?) })?)
} }
pub async fn cmd_delete_send_history<H: Host>(host: H, req: CmdDeleteSendHistoryReq) -> Result<()> { pub async fn cmd_delete_send_history<H: Host>(host: H, req: CmdDeleteSendHistoryReq) -> Result<()> {
+47 -3
View File
@@ -1,12 +1,19 @@
//! Rendering a template against an environment chain. //! Rendering a template against an environment chain.
//! //!
//! The variables come from the chain, the functions come from the host's //! The variables come from the chain, the functions come from the host's
//! template callback. Neither of these knows which host it is running under — //! template callback. `render_template` and `render_json_value` know nothing
//! that is the whole point of taking the callback as a parameter. //! about which host they run under — that is the whole point of taking the
//! callback as a parameter. `render_form_values` sits one level up: resolving
//! the chain a model sits in is an ordinary database read, so it takes the
//! host and does that read before rendering.
use crate::error::{Error, Result};
use crate::host::PluginHost;
use serde_json::Value; use serde_json::Value;
use yaak_models::models::Environment; use std::collections::HashMap;
use yaak_models::models::{AnyModel, Environment};
use yaak_models::render::make_vars_hashmap; use yaak_models::render::make_vars_hashmap;
use yaak_plugins::events::{JsonPrimitive, RenderPurpose};
use yaak_templates::{RenderOptions, 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>( pub async fn render_template<T: TemplateCallback>(
@@ -28,3 +35,40 @@ pub async fn render_json_value<T: TemplateCallback>(
let vars = &make_vars_hashmap(environment_chain); let vars = &make_vars_hashmap(environment_chain);
render_json_value_raw(value, vars, cb, opt).await render_json_value_raw(value, vars, cb, opt).await
} }
/// Render a config form's values against the environment chain the model sits in.
///
/// The chain depends on where the model lives — a request inherits through its
/// folder, a workspace has only its own — so the model is what decides which
/// variables are in scope.
pub(crate) async fn render_form_values<H: PluginHost>(
host: &H,
model: &AnyModel,
environment_id: Option<&str>,
values: HashMap<String, JsonPrimitive>,
purpose: RenderPurpose,
options: &RenderOptions,
) -> Result<HashMap<String, JsonPrimitive>> {
let (workspace_id, folder_id) = match model {
AnyModel::HttpRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
AnyModel::GrpcRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
AnyModel::WebsocketRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
AnyModel::Folder(f) => (f.workspace_id.clone(), f.folder_id.clone()),
AnyModel::Workspace(w) => (w.id.clone(), None),
other => {
return Err(Error::Generic(format!(
"Cannot resolve environments for a {}",
other.model()
)));
}
};
let environment_chain =
host.db().resolve_environments(&workspace_id, folder_id.as_deref(), environment_id)?;
let cb = host.template_callback(purpose).await?;
let rendered =
render_json_value(serde_json::to_value(&values)?, environment_chain, &cb, options).await?;
Ok(serde_json::from_value(rendered)?)
}
+16 -4
View File
@@ -7,7 +7,7 @@
use crate::error::Result; use crate::error::Result;
use crate::host::PluginHost; use crate::host::PluginHost;
use crate::render::render_template; use crate::render::{render_form_values, render_template};
use yaak_plugins::events::{ use yaak_plugins::events::{
GetTemplateFunctionConfigResponse, GetTemplateFunctionSummaryResponse, GetThemesResponse, GetTemplateFunctionConfigResponse, GetTemplateFunctionSummaryResponse, GetThemesResponse,
RenderPurpose, RenderPurpose,
@@ -21,7 +21,7 @@ pub async fn cmd_render_template<H: PluginHost>(
) -> Result<String> { ) -> Result<String> {
let environment_chain = let environment_chain =
host.db().resolve_environments(&req.workspace_id, None, req.environment_id.as_deref())?; host.db().resolve_environments(&req.workspace_id, None, req.environment_id.as_deref())?;
let cb = host.template_callback(req.purpose.unwrap_or(RenderPurpose::Preview)); let cb = host.template_callback(req.purpose.unwrap_or(RenderPurpose::Preview)).await?;
let options = RenderOptions { let options = RenderOptions {
// A preview that throws would show the user an error where they expect // A preview that throws would show the user an error where they expect
// to see the value so far, so callers rendering *into the UI* ask for // to see the value so far, so callers rendering *into the UI* ask for
@@ -41,7 +41,7 @@ pub async fn cmd_template_tokens_to_string<H: PluginHost>(
host: H, host: H,
req: CmdTemplateTokensToStringReq, req: CmdTemplateTokensToStringReq,
) -> Result<String> { ) -> Result<String> {
let cb = host.template_callback(RenderPurpose::Preview); let cb = host.template_callback(RenderPurpose::Preview).await?;
Ok(transform_args(req.tokens, &cb)?.to_string()) Ok(transform_args(req.tokens, &cb)?.to_string())
} }
@@ -56,7 +56,19 @@ pub async fn cmd_template_function_config<H: PluginHost>(
host: H, host: H,
req: CmdTemplateFunctionConfigReq, req: CmdTemplateFunctionConfigReq,
) -> Result<GetTemplateFunctionConfigResponse> { ) -> Result<GetTemplateFunctionConfigResponse> {
host.template_function_config(&req.function_name, req.values, req.model.id()).await // A config form is being displayed, so a template that cannot resolve
// should show as blank rather than refuse to open the form.
let values = render_form_values(
&host,
&req.model,
req.environment_id.as_deref(),
req.values,
RenderPurpose::Preview,
&RenderOptions::return_empty(),
)
.await?;
host.template_function_config(&req.function_name, values, req.model.id()).await
} }
pub async fn cmd_get_themes<H: PluginHost>( pub async fn cmd_get_themes<H: PluginHost>(
+120 -41
View File
@@ -18,7 +18,7 @@ use yaak_commands::models::{
cmd_default_headers, cmd_get_workspace_meta, models_delete, models_upsert, cmd_default_headers, cmd_get_workspace_meta, models_delete, models_upsert,
models_workspace_models, models_workspace_models,
}; };
use yaak_commands::templates::cmd_render_template; use yaak_commands::templates::{cmd_render_template, cmd_template_function_config};
use yaak_commands::{Host, PluginHost}; use yaak_commands::{Host, PluginHost};
use yaak_core::WorkspaceContext; use yaak_core::WorkspaceContext;
use yaak_crypto::manager::EncryptionManager; use yaak_crypto::manager::EncryptionManager;
@@ -118,6 +118,7 @@ impl Host for TestHost {
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn writes_carry_the_client_id() { async fn writes_carry_the_client_id() {
let host = TestHost::new(); let host = TestHost::new();
host.drain_writes(); // the rows startup creates
let workspace = Workspace { name: "From a test".to_string(), ..Default::default() }; let workspace = Workspace { name: "From a test".to_string(), ..Default::default() };
let id = models_upsert(host.clone(), ModelsUpsertReq { model: AnyModel::Workspace(workspace) }) let id = models_upsert(host.clone(), ModelsUpsertReq { model: AnyModel::Workspace(workspace) })
@@ -172,6 +173,8 @@ struct SingleThreadedHost {
/// The values the last auth-config call arrived with, so a test can check /// The values the last auth-config call arrived with, so a test can check
/// they were rendered before the host ever saw them. /// they were rendered before the host ever saw them.
auth_values: Rc<RefCell<Option<HashMap<String, JsonPrimitive>>>>, auth_values: Rc<RefCell<Option<HashMap<String, JsonPrimitive>>>>,
/// Same, for the last template-function-config call.
fn_values: Rc<RefCell<Option<HashMap<String, JsonPrimitive>>>>,
} }
impl Host for SingleThreadedHost { impl Host for SingleThreadedHost {
@@ -248,8 +251,11 @@ impl PluginHost for SingleThreadedHost {
Err(yaak_commands::Error::Generic("no plugin runtime on this host".into())) Err(yaak_commands::Error::Generic("no plugin runtime on this host".into()))
} }
fn template_callback(&self, _purpose: RenderPurpose) -> impl TemplateCallback { async fn template_callback(
NoTemplateFunctions &self,
_purpose: RenderPurpose,
) -> yaak_commands::Result<impl TemplateCallback> {
Ok(NoTemplateFunctions)
} }
async fn template_function_summaries( async fn template_function_summaries(
@@ -261,9 +267,10 @@ impl PluginHost for SingleThreadedHost {
async fn template_function_config( async fn template_function_config(
&self, &self,
function_name: &str, function_name: &str,
_values: HashMap<String, JsonPrimitive>, values: HashMap<String, JsonPrimitive>,
_model_id: &str, _model_id: &str,
) -> yaak_commands::Result<GetTemplateFunctionConfigResponse> { ) -> yaak_commands::Result<GetTemplateFunctionConfigResponse> {
*self.fn_values.borrow_mut() = Some(values);
Err(yaak_commands::Error::Generic(format!("no plugin provides {function_name}()"))) Err(yaak_commands::Error::Generic(format!("no plugin provides {function_name}()")))
} }
@@ -376,6 +383,7 @@ async fn a_single_threaded_host_can_implement_the_trait() {
let host = SingleThreadedHost { let host = SingleThreadedHost {
inner: Rc::new(Arc::into_inner(inner).expect("sole owner")), inner: Rc::new(Arc::into_inner(inner).expect("sole owner")),
auth_values: Rc::new(RefCell::new(None)), auth_values: Rc::new(RefCell::new(None)),
fn_values: Rc::new(RefCell::new(None)),
}; };
let workspace = Workspace { name: "From one thread".to_string(), ..Default::default() }; let workspace = Workspace { name: "From one thread".to_string(), ..Default::default() };
@@ -399,21 +407,23 @@ async fn a_single_threaded_host_can_implement_the_trait() {
// shared code; only the callback came from the host. Rendering a real // shared code; only the callback came from the host. Rendering a real
// variable is what proves the chain was resolved rather than skipped. // variable is what proves the chain was resolved rather than skipped.
let environment = host let environment = host
.db() .query_manager()
.upsert_environment( .with_tx(|tx| {
&Environment { tx.upsert_environment(
workspace_id: id.clone(), &Environment {
name: "Test env".to_string(), workspace_id: id.clone(),
variables: vec![EnvironmentVariable { name: "Test env".to_string(),
enabled: true, variables: vec![EnvironmentVariable {
name: "greeting".to_string(), enabled: true,
value: "hello".to_string(), name: "greeting".to_string(),
id: None, value: "hello".to_string(),
}], id: None,
..Default::default() }],
}, ..Default::default()
&host.update_source(), },
) &host.update_source(),
)
})
.expect("seed environment"); .expect("seed environment");
let rendered = cmd_render_template( let rendered = cmd_render_template(
@@ -448,33 +458,37 @@ async fn auth_values_are_rendered_before_the_host_sees_them() {
let host = SingleThreadedHost { let host = SingleThreadedHost {
inner: Rc::new(Arc::into_inner(inner).expect("sole owner")), inner: Rc::new(Arc::into_inner(inner).expect("sole owner")),
auth_values: Rc::new(RefCell::new(None)), auth_values: Rc::new(RefCell::new(None)),
fn_values: Rc::new(RefCell::new(None)),
}; };
let workspace = host let workspace = host
.db() .query_manager()
.upsert_workspace( .with_tx(|tx| {
&Workspace { name: "Auth".to_string(), ..Default::default() }, tx.upsert_workspace(
&host.update_source(), &Workspace { name: "Auth".to_string(), ..Default::default() },
) &host.update_source(),
)
})
.expect("workspace"); .expect("workspace");
host.db() host.query_manager()
.upsert_environment( .with_tx(|tx| {
&Environment { tx.upsert_environment(
workspace_id: workspace.id.clone(), &Environment {
name: "Env".to_string(), workspace_id: workspace.id.clone(),
variables: vec![EnvironmentVariable { name: "Env".to_string(),
enabled: true, variables: vec![EnvironmentVariable {
name: "token".to_string(), enabled: true,
value: "s3cret".to_string(), name: "token".to_string(),
id: None, value: "s3cret".to_string(),
}], id: None,
..Default::default() }],
}, ..Default::default()
&host.update_source(), },
) &host.update_source(),
)
})
.expect("environment"); .expect("environment");
let environment = let environment = host.db().list_environments(&workspace.id).expect("list").remove(0);
host.db().list_environments_ensure_base(&workspace.id).expect("list").remove(0);
let mut values = HashMap::new(); let mut values = HashMap::new();
values.insert("password".to_string(), JsonPrimitive::String("${[ token ]}".to_string())); values.insert("password".to_string(), JsonPrimitive::String("${[ token ]}".to_string()));
@@ -499,3 +513,68 @@ async fn auth_values_are_rendered_before_the_host_sees_them() {
seen.get("password"), seen.get("password"),
); );
} }
/// Same contract as auth: template function argument values may contain
/// templates (the 1Password token argument defaults to `${[1PASSWORD_TOKEN]}`),
/// and the shared handler renders them before the host is called.
#[tokio::test]
async fn template_function_values_are_rendered_before_the_host_sees_them() {
let TestHost { inner } = TestHost::new();
let host = SingleThreadedHost {
inner: Rc::new(Arc::into_inner(inner).expect("sole owner")),
auth_values: Rc::new(RefCell::new(None)),
fn_values: Rc::new(RefCell::new(None)),
};
let workspace = host
.query_manager()
.with_tx(|tx| {
tx.upsert_workspace(
&Workspace { name: "Functions".to_string(), ..Default::default() },
&host.update_source(),
)
})
.expect("workspace");
host.query_manager()
.with_tx(|tx| {
tx.upsert_environment(
&Environment {
workspace_id: workspace.id.clone(),
name: "Env".to_string(),
variables: vec![EnvironmentVariable {
enabled: true,
name: "1PASSWORD_TOKEN".to_string(),
value: "ops_abc123".to_string(),
id: None,
}],
..Default::default()
},
&host.update_source(),
)
})
.expect("environment");
let environment = host.db().list_environments(&workspace.id).expect("list").remove(0);
let mut values = HashMap::new();
values.insert("token".to_string(), JsonPrimitive::String("${[1PASSWORD_TOKEN]}".to_string()));
// The host refuses the call itself — it has no plugins — but only after the
// handler has rendered and handed over the values, which is what matters.
let _ = cmd_template_function_config(
host.clone(),
yaak_rpc_schema::CmdTemplateFunctionConfigReq {
function_name: "1password.item".to_string(),
values,
model: AnyModel::Workspace(workspace),
environment_id: Some(environment.id),
},
)
.await;
let seen = host.fn_values.borrow().clone().expect("the host should have been called");
assert!(
matches!(seen.get("token"), Some(JsonPrimitive::String(v)) if v == "ops_abc123"),
"the template should have been rendered before reaching the host, got {:?}",
seen.get("token"),
);
}
+9 -7
View File
@@ -83,7 +83,7 @@ impl EncryptionManager {
let workspace_meta = self.query_manager.with_tx::<WorkspaceMeta, Error>(|tx| { let workspace_meta = self.query_manager.with_tx::<WorkspaceMeta, Error>(|tx| {
let workspace = tx.get_workspace(workspace_id)?; let workspace = tx.get_workspace(workspace_id)?;
let workspace_meta = tx.get_or_create_workspace_meta(workspace_id)?; let workspace_meta = tx.ensure_workspace_meta(workspace_id)?;
tx.upsert_workspace( tx.upsert_workspace(
&Workspace { encryption_key_challenge, ..workspace }, &Workspace { encryption_key_challenge, ..workspace },
&UpdateSource::Background, &UpdateSource::Background,
@@ -103,7 +103,7 @@ impl EncryptionManager {
pub fn ensure_workspace_key(&self, workspace_id: &str) -> Result<WorkspaceMeta> { pub fn ensure_workspace_key(&self, workspace_id: &str) -> Result<WorkspaceMeta> {
let workspace_meta = let workspace_meta =
self.query_manager.connect().get_or_create_workspace_meta(workspace_id)?; self.query_manager.with_tx(|tx| tx.ensure_workspace_meta(workspace_id))?;
// Already exists // Already exists
if let Some(_) = workspace_meta.encryption_key { if let Some(_) = workspace_meta.encryption_key {
@@ -120,7 +120,7 @@ impl EncryptionManager {
self.query_manager.with_tx::<(), Error>(|tx| { self.query_manager.with_tx::<(), Error>(|tx| {
let workspace = tx.get_workspace(workspace_id)?; let workspace = tx.get_workspace(workspace_id)?;
let workspace_meta = tx.get_or_create_workspace_meta(workspace_id)?; let workspace_meta = tx.ensure_workspace_meta(workspace_id)?;
// Clear encryption challenge on workspace // Clear encryption challenge on workspace
tx.upsert_workspace( tx.upsert_workspace(
@@ -152,10 +152,12 @@ impl EncryptionManager {
} }
}; };
let db = self.query_manager.connect(); let key = match self
let workspace_meta = db.get_or_create_workspace_meta(workspace_id)?; .query_manager
.connect()
let key = match workspace_meta.encryption_key { .get_workspace_meta(workspace_id)
.and_then(|m| m.encryption_key)
{
None => return Err(MissingWorkspaceKey), None => return Err(MissingWorkspaceKey),
Some(k) => k, Some(k) => k,
}; };
+7
View File
@@ -47,6 +47,7 @@ export type Folder = {
settingFollowRedirects: InheritedBoolSetting; settingFollowRedirects: InheritedBoolSetting;
settingRequestTimeout: InheritedIntSetting; settingRequestTimeout: InheritedIntSetting;
settingRequestMessageSize: InheritedIntSetting; settingRequestMessageSize: InheritedIntSetting;
settingHttpVersion: InheritedHttpVersionSetting;
}; };
export type GrpcRequest = { export type GrpcRequest = {
@@ -99,6 +100,7 @@ export type HttpRequest = {
settingValidateCertificates: InheritedBoolSetting; settingValidateCertificates: InheritedBoolSetting;
settingFollowRedirects: InheritedBoolSetting; settingFollowRedirects: InheritedBoolSetting;
settingRequestTimeout: InheritedIntSetting; settingRequestTimeout: InheritedIntSetting;
settingHttpVersion: InheritedHttpVersionSetting;
}; };
export type HttpRequestHeader = { enabled?: boolean; name: string; value: string; id?: string }; export type HttpRequestHeader = { enabled?: boolean; name: string; value: string; id?: string };
@@ -114,8 +116,12 @@ export type HttpUrlParameter = {
id?: string; id?: string;
}; };
export type HttpVersion = "auto" | "http1" | "http2";
export type InheritedBoolSetting = { enabled?: boolean; value: boolean }; export type InheritedBoolSetting = { enabled?: boolean; value: boolean };
export type InheritedHttpVersionSetting = { enabled?: boolean; value: HttpVersion };
export type InheritedIntSetting = { enabled?: boolean; value: number }; export type InheritedIntSetting = { enabled?: boolean; value: number };
export type SyncModel = export type SyncModel =
@@ -169,4 +175,5 @@ export type Workspace = {
settingDnsOverrides: Array<DnsOverride>; settingDnsOverrides: Array<DnsOverride>;
settingSendCookies: boolean; settingSendCookies: boolean;
settingStoreCookies: boolean; settingStoreCookies: boolean;
settingHttpVersion: HttpVersion;
}; };
+5
View File
@@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type MethodDefinition = { name: string, schema: string, clientStreaming: boolean, serverStreaming: boolean, };
export type ServiceDefinition = { name: string, methods: Array<MethodDefinition>, };
+1 -1
View File
@@ -210,7 +210,7 @@ fn field_to_type_or_ref(root_name: &str, field: FieldDescriptor) -> JsonSchemaEn
// [Protocol Buffers Well-Known Types]: https://protobuf.dev/reference/protobuf/google.protobuf/ // [Protocol Buffers Well-Known Types]: https://protobuf.dev/reference/protobuf/google.protobuf/
"google.protobuf.FieldMask" => JsonSchemaEntry::string(), "google.protobuf.FieldMask" => JsonSchemaEntry::string(),
"google.protobuf.Timestamp" => JsonSchemaEntry::string_with_format("date-time"), "google.protobuf.Timestamp" => JsonSchemaEntry::string_with_format("date-time"),
"google.protobuf.Duration" => JsonSchemaEntry::string(), "google.protobuf.Duration" => JsonSchemaEntry::string_with_format("duration"),
"google.protobuf.StringValue" => JsonSchemaEntry::string(), "google.protobuf.StringValue" => JsonSchemaEntry::string(),
"google.protobuf.BytesValue" => JsonSchemaEntry::string_with_format("byte"), "google.protobuf.BytesValue" => JsonSchemaEntry::string_with_format("byte"),
"google.protobuf.Int32Value" => JsonSchemaEntry::number("int32"), "google.protobuf.Int32Value" => JsonSchemaEntry::number("int32"),
Loaded 100 of 226 files, more files were not shown because too many files have changed in this diff. Show more