diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml deleted file mode 100644 index 57599dc..0000000 --- a/.gitea/workflows/ci.yml +++ /dev/null @@ -1,130 +0,0 @@ -name: ci - -on: - push: - branches: [main] - tags: ['v*'] - pull_request: - workflow_dispatch: - -# The runner is arm64 with 2 CPUs. Job containers ask for at most that many, -# and JavaScript actions need node inside the container, so it comes first. - -jobs: - test: - runs-on: ubuntu-latest - container: - image: rust:1-bookworm - options: --cpus 2 - steps: - - name: Install node and build dependencies - run: | - apt-get update - DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs \ - libwebkit2gtk-4.1-dev libgtk-3-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev librsvg2-dev libdbus-1-dev pkg-config - - uses: actions/checkout@v4 - - run: cargo test -p knock-core --locked - - # amd64 packages, cross-compiled on the arm64 runner. Ubuntu 22.04 is the - # oldest supported target, so glibc and WebKitGTK fit 22.04 and newer. - # No AppImage: its tooling only runs on amd64. - packages: - needs: test - if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' - runs-on: ubuntu-latest - container: - image: ubuntu:22.04 - options: --cpus 2 - env: - DEBIAN_FRONTEND: noninteractive - TARGET: x86_64-unknown-linux-gnu - CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: x86_64-linux-gnu-gcc - CC_x86_64_unknown_linux_gnu: x86_64-linux-gnu-gcc - CXX_x86_64_unknown_linux_gnu: x86_64-linux-gnu-g++ - AR_x86_64_unknown_linux_gnu: x86_64-linux-gnu-ar - PKG_CONFIG_ALLOW_CROSS: '1' - PKG_CONFIG_SYSROOT_DIR: / - PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig - steps: - - name: Install node - run: | - apt-get update - apt-get install -y curl ca-certificates gnupg git - curl -fsSL https://deb.nodesource.com/setup_22.x | bash - - apt-get install -y nodejs - - - uses: actions/checkout@v4 - - - name: Add amd64 as a foreign architecture - run: | - # arm64 comes from ports.ubuntu.com, amd64 from the main archive. - sed -i -E 's/^deb (http)/deb [arch=arm64] \1/' /etc/apt/sources.list - cat > /etc/apt/sources.list.d/amd64.list <<'EOF' - deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse - deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse - deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse - EOF - dpkg --add-architecture amd64 - apt-get update - - - name: Install cross toolchain and amd64 libraries - run: | - apt-get install -y build-essential pkg-config file cmake \ - gcc-x86-64-linux-gnu g++-x86-64-linux-gnu libc6-dev-amd64-cross \ - libwebkit2gtk-4.1-dev:amd64 libgtk-3-dev:amd64 libsoup-3.0-dev:amd64 \ - libjavascriptcoregtk-4.1-dev:amd64 librsvg2-dev:amd64 libdbus-1-dev:amd64 - - - name: Install Rust - run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --target "$TARGET" - echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" - - - name: Build - run: | - npm ci - cargo build --release --locked -p knock-cli --target "$TARGET" - BIN="../target/$TARGET/release/knock" - npx tauri build --target "$TARGET" --bundles deb,rpm \ - --config "{\"bundle\":{\"linux\":{\"deb\":{\"files\":{\"/usr/bin/knock\":\"$BIN\"}},\"rpm\":{\"files\":{\"/usr/bin/knock\":\"$BIN\"}}}}}" - - - name: Check packages - run: | - OUT="target/$TARGET/release/bundle" - DEB=$(ls $OUT/deb/*.deb) - fail() { echo "check failed: $1"; exit 1; } - CONTENTS=$(dpkg-deb -c "$DEB") - [ "$(dpkg-deb --field "$DEB" Architecture)" = amd64 ] || fail "deb architecture is not amd64" - echo "$CONTENTS" | grep -qE 'usr/bin/knock-app$' || fail "knock-app missing from the deb" - echo "$CONTENTS" | grep -qE 'usr/bin/knock$' || fail "knock CLI missing from the deb" - echo "$CONTENTS" | grep -qE 'usr/share/applications/.+\.desktop$' || fail "desktop entry missing from the deb" - file "target/$TARGET/release/knock-app" | grep -q 'x86-64' || fail "knock-app is not an x86-64 binary" - file "target/$TARGET/release/knock" | grep -q 'x86-64' || fail "knock is not an x86-64 binary" - # Nothing newer than Ubuntu 22.04's glibc (2.35) may be required. - too_new=$(x86_64-linux-gnu-objdump -T "target/$TARGET/release/knock-app" | grep -oE 'GLIBC_2\.[0-9]+' | sort -u | awk -F. '$2 > 35') - if [ -n "$too_new" ]; then echo "needs newer glibc than Ubuntu 22.04: $too_new"; exit 1; fi - ls -la $OUT/deb $OUT/rpm - - - uses: actions/upload-artifact@v3 - with: - name: packages-amd64 - path: | - target/x86_64-unknown-linux-gnu/release/bundle/deb/*.deb - target/x86_64-unknown-linux-gnu/release/bundle/rpm/*.rpm - - - name: Attach to release - if: startsWith(github.ref, 'refs/tags/v') - env: - TOKEN: ${{ secrets.GITEA_TOKEN }} - API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} - TAG: ${{ github.ref_name }} - run: | - apt-get install -y jq - id=$(curl -fsS -H "Authorization: token $TOKEN" "$API/releases/tags/$TAG" | jq -r .id || true) - if [ -z "$id" ] || [ "$id" = "null" ]; then - pre=$(case "$TAG" in *-*) echo true;; *) echo false;; esac) - id=$(curl -fsS -X POST -H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \ - -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"prerelease\":$pre}" "$API/releases" | jq -r .id) - fi - for f in target/$TARGET/release/bundle/deb/*.deb target/$TARGET/release/bundle/rpm/*.rpm; do - curl -fsS -X POST -H "Authorization: token $TOKEN" -F "attachment=@$f" "$API/releases/$id/assets?name=$(basename "$f")" - done diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e8ac136 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: ci + +on: + push: + branches: [main] + pull_request: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 22 + cache: npm + - uses: Swatinem/rust-cache@v2 + - name: System libraries + run: | + sudo apt-get update + sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev libdbus-1-dev + - run: npm ci + - name: Frontend types + run: npx svelte-check --tsconfig ./tsconfig.json + - name: Frontend build + run: npm run build + - name: Core tests + run: cargo test -p knock-core --locked + - name: App and CLI compile + run: cargo check --locked -p knock-app -p knock-cli diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 30bc06f..6f643d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,8 @@ name: release -# Runs on the GitHub mirror only (Gitea uses .gitea/workflows). macOS and -# Windows minutes are expensive on private repositories, so this runs for -# tags and on demand, not on every push. +# Push a tag vX.Y.Z (scripts/release.sh does it) and this builds every +# platform and publishes a GitHub release. Manual runs build without +# releasing; pick platforms to save macOS and Windows minutes. on: push: tags: ['v*'] @@ -129,13 +129,21 @@ jobs: - uses: actions/download-artifact@v5 with: path: artifacts - - name: Attach to the GitHub release + merge-multiple: true + - name: Checksums + run: | + cd artifacts + sha256sum * > SHA256SUMS + cat SHA256SUMS + - name: Publish release env: GH_TOKEN: ${{ github.token }} TAG: ${{ github.ref_name }} run: | pre="" case "$TAG" in *-*) pre="--prerelease";; esac - gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1 \ - || gh release create "$TAG" -R "$GITHUB_REPOSITORY" --title "$TAG" --notes "" $pre - find artifacts -type f -exec gh release upload "$TAG" -R "$GITHUB_REPOSITORY" --clobber {} + + if gh release view "$TAG" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1; then + gh release upload "$TAG" -R "$GITHUB_REPOSITORY" --clobber artifacts/* + else + gh release create "$TAG" -R "$GITHUB_REPOSITORY" --title "knock ${TAG#v}" --generate-notes $pre artifacts/* + fi diff --git a/README.md b/README.md index e148479..bed2ae9 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ An offline desktop API client for REST, GraphQL and WebSocket. No account, no cloud, no telemetry. Collections are folders of YAML files that live in your git repository. +**Documentation:** https://docs.joshicodes.de/b/knock/introduction · **Downloads:** [Releases](https://github.com/JoshiCodes/knock/releases) + ## What makes it different - **JSON bodies without typing brackets.** Every JSON body has a form view (keys, types, values, drag to reorder) and a code view on the same text. Switching is lossless: key order, `{{variables}}` as raw values and numbers larger than 2^53 survive. Attach a JSON Schema and the form suggests fields, marks required ones and validates while you type. @@ -64,21 +66,39 @@ knock auth debug users --env prod --verbose `knock run` exits with 1 when an assertion fails. In CI, secrets come from `KNOCK_SECRET_` environment variables (set `KNOCK_NO_KEYRING=1` where no keyring exists). -## Building +## Install + +- **Arch Linux / CachyOS:** `packaging/arch/knock-bin` (release package), `packaging/arch/knock` (from source) or `packaging/arch/knock-git` (latest `main`); `makepkg -si` in the folder +- **Ubuntu 22.04+ / Debian:** the `.deb` from the [latest release](https://github.com/JoshiCodes/knock/releases/latest) +- **Fedora and others:** the `.rpm` or the AppImage +- **macOS:** the universal `.dmg` (not notarized: open it once with right click → Open) +- **Windows:** the `.msi` or setup `.exe` (best effort) + +If the window stays blank on Wayland, WebKitGTK's DMA-BUF renderer is the usual cause; knock turns it off by default. Set `KNOCK_DMABUF=1` to turn it back on. + +## Development Requirements: Rust (stable), Node.js 20+, and on Linux `webkit2gtk-4.1`, `gtk3`, `libsecret`. ```sh npm ci npm run tauri dev # run the app -npm run tauri build # deb, rpm, AppImage in target/release/bundle -cargo build --release -p knock-cli -cargo test -p knock-core +cargo test -p knock-core # tests +npx svelte-check # frontend types +npm run dev # frontend only; open http://localhost:1420/?mock for a fake backend ``` -Arch Linux: `packaging/arch/knock` builds from source, `packaging/arch/knock-bin` repackages the release `.deb`. +`.github/workflows/ci.yml` checks every push and pull request. -If the window stays blank on Wayland, WebKitGTK's DMA-BUF renderer is the usual cause; knock turns it off by default. Set `KNOCK_DMABUF=1` to turn it back on. +## Releasing + +```sh +scripts/release.sh 0.2.0 +``` + +The script sets the version in Cargo, npm, Tauri and the PKGBUILDs, commits, tags `v0.2.0` and pushes. The tag starts `.github/workflows/release.yml`, which builds Linux (deb, rpm, AppImage), macOS (universal dmg) and Windows (msi, exe) plus the CLI for each, and publishes a GitHub release with generated notes and `SHA256SUMS`. A version with a suffix (`0.2.0-rc1`) becomes a pre-release. + +To try the builds without releasing: `gh workflow run release.yml -f platforms=linux` (or `macos`, `windows`, `all`). ## License diff --git a/packaging/arch/knock-bin/PKGBUILD b/packaging/arch/knock-bin/PKGBUILD index 303fe5d..b9df389 100644 --- a/packaging/arch/knock-bin/PKGBUILD +++ b/packaging/arch/knock-bin/PKGBUILD @@ -4,7 +4,7 @@ pkgver=0.1.0 pkgrel=1 pkgdesc="Offline desktop API client for REST, GraphQL and WebSocket with plain-file collections (binary release)" arch=('x86_64') -url="https://git.joshicodes.de/JoshiCodes/knock" +url="https://github.com/JoshiCodes/knock" license=('MIT') depends=('webkit2gtk-4.1' 'gtk3' 'libsecret' 'hicolor-icon-theme') optdepends=('kwallet: store secrets in KWallet' 'gnome-keyring: store secrets in GNOME Keyring') diff --git a/packaging/arch/knock-git/PKGBUILD b/packaging/arch/knock-git/PKGBUILD index 9d709e7..146f3e4 100644 --- a/packaging/arch/knock-git/PKGBUILD +++ b/packaging/arch/knock-git/PKGBUILD @@ -4,7 +4,7 @@ pkgver=r0 pkgrel=1 pkgdesc="Offline desktop API client for REST, GraphQL and WebSocket with plain-file collections (latest main)" arch=('x86_64') -url="https://git.joshicodes.de/JoshiCodes/knock" +url="https://github.com/JoshiCodes/knock" license=('MIT') depends=('webkit2gtk-4.1' 'gtk3' 'libsecret' 'hicolor-icon-theme') makedepends=('rust' 'cargo' 'nodejs' 'npm' 'git') diff --git a/packaging/arch/knock/PKGBUILD b/packaging/arch/knock/PKGBUILD index 95b3e6d..fb7d949 100644 --- a/packaging/arch/knock/PKGBUILD +++ b/packaging/arch/knock/PKGBUILD @@ -4,7 +4,7 @@ pkgver=0.1.0 pkgrel=1 pkgdesc="Offline desktop API client for REST, GraphQL and WebSocket with plain-file collections" arch=('x86_64') -url="https://git.joshicodes.de/JoshiCodes/knock" +url="https://github.com/JoshiCodes/knock" license=('MIT') depends=('webkit2gtk-4.1' 'gtk3' 'libsecret' 'hicolor-icon-theme') makedepends=('rust' 'cargo' 'nodejs' 'npm' 'git') @@ -12,30 +12,30 @@ optdepends=('kwallet: store secrets in KWallet' 'gnome-keyring: store secrets in conflicts=('knock-bin') # aws-lc and sqlite are C; makepkg's LTO flags produce objects the Rust linker cannot read. options=('!lto') -source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz") +source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz") sha256sums=('SKIP') prepare() { - cd "$pkgname" + cd "$pkgname-$pkgver" export RUSTUP_TOOLCHAIN=stable cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')" npm ci } build() { - cd "$pkgname" + cd "$pkgname-$pkgver" export RUSTUP_TOOLCHAIN=stable npm run build cargo build --frozen --release -p knock-app -p knock-cli --features knock-app/custom-protocol } check() { - cd "$pkgname" + cd "$pkgname-$pkgver" cargo test --frozen --release -p knock-core } package() { - cd "$pkgname" + cd "$pkgname-$pkgver" install -Dm755 target/release/knock-app "$pkgdir/usr/bin/knock-app" install -Dm755 target/release/knock "$pkgdir/usr/bin/knock" install -Dm644 packaging/linux/knock-app.desktop "$pkgdir/usr/share/applications/knock-app.desktop" diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..387469d --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Usage: scripts/release.sh 0.2.0 +# Sets the version everywhere, commits, tags v0.2.0 and pushes. The tag +# starts .github/workflows/release.yml, which builds all platforms and +# publishes the GitHub release. +set -euo pipefail +cd "$(dirname "$0")/.." + +v="${1:-}" +if ! [[ "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then + echo "usage: $0 e.g. $0 0.2.0 or $0 0.2.0-rc1" >&2 + exit 2 +fi +if [ -n "$(git status --porcelain)" ]; then + echo "working tree is not clean; commit or stash first" >&2 + exit 1 +fi +if [ "$(git branch --show-current)" != main ]; then + echo "releases are cut from main" >&2 + exit 1 +fi +if git rev-parse -q --verify "refs/tags/v$v" >/dev/null; then + echo "tag v$v exists already" >&2 + exit 1 +fi + +# Cargo workspace, npm, Tauri, Arch packages. +sed -i -E "0,/^version = \"[^\"]+\"/s//version = \"$v\"/" Cargo.toml +npm version "$v" --no-git-tag-version --allow-same-version >/dev/null +sed -i -E "s/(\"version\": )\"[^\"]+\"/\1\"$v\"/" src-tauri/tauri.conf.json +base="${v%%-*}" +sed -i -E "s/^pkgver=.*/pkgver=$base/; s/^pkgrel=.*/pkgrel=1/" packaging/arch/knock/PKGBUILD packaging/arch/knock-bin/PKGBUILD +cargo update -w --offline >/dev/null 2>&1 || cargo update -w >/dev/null + +git add Cargo.toml Cargo.lock package.json package-lock.json src-tauri/tauri.conf.json packaging/arch +git commit -q -m "Release v$v" +git tag -a "v$v" -m "knock $v" +git push -q origin main "v$v" +echo "Pushed v$v. Follow the build: gh run watch \$(gh run list -w release -L1 --json databaseId -q '.[0].databaseId')" diff --git a/src/app.css b/src/app.css index 1021143..5798101 100644 --- a/src/app.css +++ b/src/app.css @@ -141,8 +141,42 @@ font-family: var(--ck-font-mono); font-weight: 500; } - button { - cursor: default; + /* Everything clickable shows the hand; disabled controls say so. */ + button, + a[href], + select, + summary, + [role='button'], + [role='tab'], + [role='treeitem'], + [role='radio'], + [role='switch'], + [role='menuitem'], + [role='option'], + input[type='checkbox'], + input[type='radio'], + label:has(> input[type='checkbox']), + label:has(> input[type='radio']) { + cursor: pointer; + } + button:disabled, + select:disabled, + input:disabled, + [aria-disabled='true'] { + cursor: not-allowed; + } + input:not([type='checkbox']):not([type='radio']), + textarea { + cursor: text; + } + button, + [role='tab'], + [role='treeitem'] { + transition: + background-color 90ms ease, + color 90ms ease, + border-color 90ms ease, + opacity 90ms ease; } } diff --git a/src/dev/mock.ts b/src/dev/mock.ts new file mode 100644 index 0000000..9ffa2bc --- /dev/null +++ b/src/dev/mock.ts @@ -0,0 +1,222 @@ +// Dev only: a stand-in for the Tauri bridge so the UI runs in a plain browser +// (`npm run dev`, then open http://localhost:1420/?mock). Used for screenshots +// and design work; never part of a build. + +const json = (v: unknown) => JSON.parse(JSON.stringify(v)); + +const tree = { + id: '', + name: 'Sigil', + children: [ + { + node: 'folder', + id: 'openid-discovery', + name: 'OpenID Discovery', + children: [ + { node: 'request', id: 'openid-discovery/openid-configuration.yaml', name: 'OpenID Configuration', type: 'http', method: 'GET' }, + { node: 'request', id: 'openid-discovery/openid-jwks.yaml', name: 'OpenID JWKs', type: 'http', method: 'GET' } + ] + }, + { + node: 'folder', + id: 'auth', + name: 'Auth', + children: [ + { node: 'request', id: 'auth/login.yaml', name: 'Login', type: 'http', method: 'POST' }, + { node: 'request', id: 'auth/user-info.yaml', name: 'User Info', type: 'http', method: 'GET' } + ] + }, + { node: 'folder', id: 'users', name: 'Users', children: [ + { node: 'request', id: 'users/create-user.yaml', name: 'Create user', type: 'http', method: 'POST' }, + { node: 'request', id: 'users/update-user.yaml', name: 'Update user', type: 'http', method: 'PATCH' }, + { node: 'request', id: 'users/delete-user.yaml', name: 'Delete user', type: 'http', method: 'DELETE' }, + { node: 'request', id: 'users/search.gql.yaml', name: 'Search', type: 'graphql', method: 'POST' } + ] }, + { node: 'request', id: 'events.ws.yaml', name: 'Events', type: 'ws', method: 'GET' } + ] +}; + +const collection = { + id: 'demo', + root: '/home/you/projects/sigil/knock', + name: 'Sigil', + tree, + environments: [ + { id: 'local', name: 'local', color: '#2EC4F1', protected: false }, + { id: 'prod', name: 'Production', color: '#FF5C5C', protected: true } + ], + problems: [] +}; + +const requests: Record = { + 'auth/login.yaml': { + name: 'Login', + type: 'http', + method: 'POST', + url: '{{BASE}}/api/login?remember=true', + params: { query: [{ name: 'remember', value: 'true' }], path: {} }, + headers: [ + { name: 'Origin', value: '{{BASE}}' }, + { name: 'Accept', value: 'application/json' } + ], + auth: 'inherit', + body: { + type: 'json', + content: + '{\n "username": "alice",\n "password": "{{secret.password}}",\n "remember": true,\n "device": {\n "id": "{{$uuid}}",\n "name": "knock on CachyOS",\n "trusted": false\n },\n "scopes": ["openid", "profile"],\n "maxAge": {{sessionMinutes}}\n}' + }, + extract: [{ var: 'token', from: 'json', path: '$.access_token' }], + assert: [ + { on: 'status', equals: 200 }, + { on: 'json', path: '$.user.id', exists: true }, + { on: 'time', lt: 500 } + ] + } +}; + +const response = { + output: { + request: { + method: 'POST', + url: 'http://localhost:5173/api/login?remember=true', + headers: [ + ['Origin', 'http://localhost:5173'], + ['Content-Type', 'application/json'] + ], + body: '{}' + }, + response: { + status: 200, + status_text: 'OK', + http_version: '1.1', + url: 'http://localhost:5173/api/login?remember=true', + headers: [ + ['content-type', 'application/json; charset=utf-8'], + ['set-cookie', 'sigil_session=7a2…; Path=/; HttpOnly; SameSite=Lax'], + ['x-request-id', '01JDX4Z8T9K3'] + ], + cookies: [{ name: 'sigil_session', value: '7a2LqAoHcJz2', domain: 'localhost', path: '/', expires: null, secure: false, http_only: true, same_site: 'Lax' }], + size: 734, + header_size: 212, + content_type: 'application/json', + timings: { ttfb_ms: 38.2, download_ms: 1.4, total_ms: 41.7, redirect_ms: 0 }, + redirects: [], + remote_addr: '127.0.0.1:5173', + body_file: null + }, + auth: { kind: 'none', origin: null, source: null, steps: [], sent: [], warnings: [], flow_id: null }, + asserts: [ + { index: 0, label: 'status equals', passed: true, expected: '200', actual: '200' }, + { index: 1, label: 'json $.user.id exists', passed: true, expected: 'true', actual: '"u_8f2"' }, + { index: 2, label: 'response time (ms) <', passed: true, expected: '500', actual: '42' } + ], + extracted: [{ var: 'token', value: 'eyJhbGciOi…', persist: false, error: null }], + error: null, + missing: [], + retried: false + }, + body_id: 'b1', + history_id: 1, + body_file: null +}; + +const responseBody = JSON.stringify( + { + access_token: 'eyJhbGciOiJSUzI1NiIsImtpZCI6ImsxIn0.eyJzdWIiOiJ1XzhmMiJ9.c2ln', + token_type: 'Bearer', + expires_in: 900, + user: { id: 'u_8f2', name: 'Alice Liddell', email: 'alice@example.com', roles: ['admin', 'editor'], createdAt: '2026-03-14T09:26:53Z', quota: 12345678901234567890 }, + session: { id: 's_19c', idleTimeout: 1800, mfa: false } + }, + null, + 2 +); + +const vars = [ + { name: 'BASE', value: 'http://localhost:5173', scope: 'environment', source: 'local', secret: false, problem: null }, + { name: 'sessionMinutes', value: '480', scope: 'collection', source: 'knock.yaml', secret: false, problem: null }, + { name: 'token', value: 'eyJhbGciOi…', scope: 'runtime', source: 'runtime', secret: false, problem: null } +]; + +const history = [ + { id: 3, at: new Date(Date.now() - 60_000).toISOString(), collection: 'demo', request_id: 'auth/login.yaml', name: 'Login', method: 'POST', url: 'http://localhost:5173/api/login', status: 200, duration_ms: 41.7, size: 734, error: null, has_body: true }, + { id: 2, at: new Date(Date.now() - 600_000).toISOString(), collection: 'demo', request_id: null, name: 'User Info', method: 'GET', url: 'http://localhost:8080/oauth2/userinfo', status: 401, duration_ms: 12, size: 64, error: null, has_body: true }, + { id: 1, at: new Date(Date.now() - 3_600_000).toISOString(), collection: 'demo', request_id: null, name: 'Delete user', method: 'DELETE', url: 'http://localhost:5173/api/users/7', status: 204, duration_ms: 18, size: 0, error: null, has_body: false } +]; + +function handle(cmd: string, args: Record): unknown { + switch (cmd) { + case 'collection_open': + case 'collection_get': + return json(collection); + case 'recent_collections': + return ['/home/you/projects/sigil/knock', '/home/you/work/billing-api/knock']; + case 'request_get': + return json( + requests[args.id as string] ?? { + name: String(args.id).split('/').pop()?.replace(/\.(gql|ws)?\.?yaml$/, ''), + type: 'http', + method: 'GET', + url: '{{BASE}}/api/' + String(args.id).replace(/\.yaml$/, ''), + auth: 'inherit' + } + ); + case 'vars_list': + return { vars, dynamic: [['$uuid', 'Random UUID v4'], ['$timestamp', 'Unix time in seconds']] }; + case 'request_send': + return new Promise((r) => setTimeout(() => r(json(response)), 350)); + case 'response_body': + return new TextEncoder().encode(responseBody).buffer; + case 'request_preview': + return { request: response.output.request, auth: response.output.auth, missing: [], error: null }; + case 'history_list': + return history; + case 'env_get': + return { name: args.id === 'prod' ? 'Production' : 'local', vars: { BASE: 'http://localhost:5173', clientId: 'knock', clientSecret: { secret: true } } }; + case 'env_secrets': + return [{ name: 'clientSecret', source: 'keyring', value: '••••' }]; + case 'manifest_get': + return { version: 1, name: 'Sigil', id: 'demo', auth: { type: 'oauth2', issuer: '{{BASE}}/realms/default', client_id: 'test', client_secret: '{{secret.clientSecret}}', scopes: 'openid profile email' }, headers: [], vars: { sessionMinutes: '480' } }; + case 'oauth_status': + return { key: 'oauth:demo', redirect_uri: 'http://127.0.0.1:53127/callback', token: null, flows: [], logout_url: null }; + case 'app_version': + return '0.1.0'; + case 'globals_get': + return {}; + case 'runtime_list': + return { token: 'eyJhbGciOi…' }; + case 'cookies_list': + return response.output.response.cookies; + case 'setting_get': + return null; + case 'path_params': + return []; + case 'plugin:window|is_maximized': + return false; + default: + if (cmd.startsWith('plugin:event|')) return 0; + if (cmd.startsWith('plugin:')) return null; + return null; + } +} + +let cb = 0; +const w = window as unknown as Record; +w.__TAURI_INTERNALS__ = { + metadata: { currentWindow: { label: 'main' }, currentWebview: { windowLabel: 'main', label: 'main' } }, + transformCallback: () => ++cb, + unregisterCallback: () => {}, + convertFileSrc: (p: string) => p, + invoke: async (cmd: string, args: Record = {}) => handle(cmd, args) +}; +w.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} }; + +try { + if (!localStorage.getItem('knock.open')) { + localStorage.setItem('knock.open', JSON.stringify([collection.root])); + localStorage.setItem('knock.tabs', JSON.stringify([{ kind: 'request', col: 'demo', id: 'auth/login.yaml' }])); + localStorage.setItem('knock.expanded', JSON.stringify(['demo:auth', 'demo:users'])); + } +} catch { + /* storage blocked */ +} diff --git a/src/lib/ui/VarInput.svelte b/src/lib/ui/VarInput.svelte index 5204b83..946b04c 100644 --- a/src/lib/ui/VarInput.svelte +++ b/src/lib/ui/VarInput.svelte @@ -204,7 +204,7 @@
{#each menu.items as item, i} +
{/if} {#each s.data.params as [k, v]} @@ -162,11 +162,11 @@ {@const x = s.exchange}
-
Request
+
Request
{m(exchangeText(x, 'req'))}
-
Response
+
Response
{m(exchangeText(x, 'res'))}
diff --git a/src/lib/views/auth/OAuthConfig.svelte b/src/lib/views/auth/OAuthConfig.svelte index aa90ee2..c4b46c0 100644 --- a/src/lib/views/auth/OAuthConfig.svelte +++ b/src/lib/views/auth/OAuthConfig.svelte @@ -375,7 +375,7 @@ {mode === 'manual' ? 'Paste the URL of the page you landed on, or just the code:' : 'Waiting for the knock:// link. If the browser does not hand it over, paste the URL here:'}
e.key === 'Enter' && sendPasted()} /> - +
diff --git a/src/lib/views/auth/TokenInspector.svelte b/src/lib/views/auth/TokenInspector.svelte index 7471370..4da07f7 100644 --- a/src/lib/views/auth/TokenInspector.svelte +++ b/src/lib/views/auth/TokenInspector.svelte @@ -100,7 +100,7 @@ {#if signature}signature {signature}{/if} diff --git a/src/lib/views/request/UrlBar.svelte b/src/lib/views/request/UrlBar.svelte index 87ef895..1379139 100644 --- a/src/lib/views/request/UrlBar.svelte +++ b/src/lib/views/request/UrlBar.svelte @@ -89,7 +89,7 @@ {#if req.type !== 'ws'} {#if tab.sending} - diff --git a/src/lib/views/response/ResponsePane.svelte b/src/lib/views/response/ResponsePane.svelte index ba91710..b269b15 100644 --- a/src/lib/views/response/ResponsePane.svelte +++ b/src/lib/views/response/ResponsePane.svelte @@ -75,7 +75,7 @@ {formatBytes(resp.size)} HTTP/{resp.http_version} {#if assertsTotal} - {/if} diff --git a/src/lib/views/settings/CollectionSettings.svelte b/src/lib/views/settings/CollectionSettings.svelte index ab4b9b1..ed22e80 100644 --- a/src/lib/views/settings/CollectionSettings.svelte +++ b/src/lib/views/settings/CollectionSettings.svelte @@ -88,7 +88,7 @@
{root}/knock.yaml
- +
@@ -163,11 +163,11 @@
Certificate - + Private key - + or PKCS#12 - + Passphrase c.passphrase ?? '', (v) => (c.passphrase = v || undefined)} />
diff --git a/src/lib/views/settings/EnvironmentView.svelte b/src/lib/views/settings/EnvironmentView.svelte index 74640c5..648bc92 100644 --- a/src/lib/views/settings/EnvironmentView.svelte +++ b/src/lib/views/settings/EnvironmentView.svelte @@ -159,7 +159,7 @@ data!.name ?? env!, (v) => (data!.name = v)} /> - +
environments/{env}.yaml
diff --git a/src/lib/views/settings/FolderView.svelte b/src/lib/views/settings/FolderView.svelte index 0c8d495..752c977 100644 --- a/src/lib/views/settings/FolderView.svelte +++ b/src/lib/views/settings/FolderView.svelte @@ -62,7 +62,7 @@
{id}/folder.yaml
- +

Auth

diff --git a/src/lib/views/ws/WsView.svelte b/src/lib/views/ws/WsView.svelte index 6431f98..6de6f44 100644 --- a/src/lib/views/ws/WsView.svelte +++ b/src/lib/views/ws/WsView.svelte @@ -126,13 +126,13 @@
{#if connected} - connected{wsLogs.handshake[tab.key]?.hs.protocol ? ` · ${wsLogs.handshake[tab.key].hs.protocol}` : ''} {:else if connecting} - + connecting… {:else} - +
{#if format === 'json'} @@ -184,7 +184,7 @@ {m.format} {m.content.replace(/\s+/g, ' ')} - +
{/each} @@ -251,7 +251,7 @@ {@const json = expanded.has(e.id) ? asJson(e) : null}