Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changes/feat-account-remove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Added

- **`pbx <profile> account remove` signs a profile out and forgets it on this computer.** It forgets the saved
database or SFTP password and the profile's settings. `--keep-data` leaves its calls in the store, where search still
finds them; `--delete-data` deletes them. It asks first, or takes `--yes`; `--dry-run` lists what it would remove.
Why: WireCat Desktop removes an account with this command, and pbx could only sign out with `session end`. The
password itself stays valid on the server: only the server's owner changes it.
13 changes: 13 additions & 0 deletions contracts/wirecat.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@
"local": "read"
}
},
{
"path": [
"account",
"remove"
],
"summary": "sign this profile out and forget it, keeping or deleting its data",
"effects": {
"remote": "none",
"local": "write"
},
"permission": "account.remove",
"entity": "account_removal"
},
{
"path": [
"meetings",
Expand Down
24 changes: 24 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ pbx session list

**Example:** `pbx session list`, `pbx session list --json`

## `pbx account`

this profile on this computer

### `pbx account remove`

sign the profile out, then forget it on this computer: its settings, its saved sign-in and its files; --keep-data leaves its messages in the store, where search still finds them, --delete-data deletes them; asks first, or --yes

**Changes something on this computer only.**

```sh
pbx account remove [options]
```

| Option | What it does |
|---|---|
| `--keep-data` | leave what the store holds of this account, still searchable. |
| `--delete-data` | delete what the store and the tool's own files hold of this account. |
| `--dry-run` | list what it would remove and keep, and change nothing. |

**Returns:** account removal — profile, data, dry_run, account, revoked, config_file, removed, kept; every field: pbx commands info account remove

**Example:** `pbx personal account remove --keep-data --dry-run`, `pbx personal account remove --delete-data --yes`

## `pbx meetings`

stored meetings and their records
Expand Down
6 changes: 5 additions & 1 deletion docs/dev/test-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ran it · ⛔ not tested offline, with the reason and where it is checked instea
Measured from the test run (`coverage/argv.jsonl`), not searched for — see
[TESTING.md](TESTING.md) for how, and for the states and failures that cut across commands.

**126 ✅ · 48 ⛔ · 0 ❌** — 55 commands, 119 options.
**130 ✅ · 48 ⛔ · 0 ❌** — 56 commands, 122 options.

| Command | Option | | Note |
|---|---|---|---|
Expand All @@ -19,6 +19,10 @@ Measured from the test run (`coverage/argv.jsonl`), not searched for — see
| `session status` | `--check` | ✅ | |
| `session end` | | ✅ | |
| `session list` | | ✅ | |
| `account remove` | | ✅ | |
| `account remove` | `--keep-data` | ✅ | |
| `account remove` | `--delete-data` | ✅ | |
| `account remove` | `--dry-run` | ✅ | |
| `meetings list` | | ✅ | |
| `meetings list` | `--backend` | ⛔ | cli-core 0.660.0 src/store/meetings-read-through.test.ts drives archive, server and both on a shared source |
| `meetings list` | `--limit` | ✅ | |
Expand Down
30 changes: 30 additions & 0 deletions src/calls.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { appendFileSync, readFileSync, utimesSync, writeFileSync } from "node:fs"
import { join } from "node:path"
import { memoryKeyring } from "@wirecat/cli-base"
import { wallClock } from "@wirecat/cli-core/cli"
import { afterEach, beforeEach, expect, it } from "vitest"
import { openAsteriskStore } from "./store.js"
Expand Down Expand Up @@ -232,3 +233,32 @@ it("a resync that misses the call naming an extension keeps the name the call wa
const names = JSON.parse(await details(transferred.id)).item.participants.map(({ name }: { name: string }) => name)
expect(names).toEqual(["Petr Testov", "Oleg Operatorov", null])
})

it("account remove forgets the saved password and keeps or deletes the profile's calls", async () => {
await office()
const keyring = memoryKeyring({ "asterisk-cli:token:office": "secret" })
const start = () => runCli(["office", "session", "start", "--json"], { keyring })
expect((await start()).code).toBe(0)
expect((await sync()).code).toBe(0)
const synced = (await listed()).length
expect(synced).toBeGreaterThan(0)

const dry = await runCli(["office", "account", "remove", "--delete-data", "--dry-run", "--json"], { keyring })
expect(dry.code, dry.err).toBe(0)
expect(dry.json().item).toMatchObject({
removed: expect.arrayContaining([{ kind: "keyring", target: "token:office" }]),
})
expect(keyring.get("asterisk-cli", "token:office")).toBe("secret")

const kept = await runCli(["office", "account", "remove", "--keep-data", "--yes", "--json"], { keyring })
expect(kept.code, kept.err).toBe(0)
expect(kept.json().item).toMatchObject({ data: "kept", revoked: null })
expect(keyring.get("asterisk-cli", "token:office")).toBeNull()
expect((await listed()).length).toBe(synced)

await office()
expect((await start()).code).toBe(0)
const deleted = await runCli(["office", "account", "remove", "--delete-data", "--yes", "--json"], { keyring })
expect(deleted.code, deleted.err).toBe(0)
expect((await runCli(["office", "meetings", "list", "--json"])).json().items).toEqual([])
})
40 changes: 40 additions & 0 deletions src/commands/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { resolvePaths } from "@wirecat/cli-base"
import { annotate } from "@wirecat/cli-base/commands"
import { type AccountRemoval, accountRemoveCommand, LOCAL_READ, LOCAL_WRITE } from "@wirecat/cli-core/cli"
import { Command } from "commander"
import { PROVIDER_NAME } from "../call-source.js"
import { configuration } from "../config.js"
import { IDENTITY } from "../identity.js"

const removal: AccountRemoval = {
// The password belongs to a database or SFTP user on the owner's server; only that server can change it.
signOut: async (profile) => ({
revoked: null,
removed: [`the saved password of ${profile} (the user on the server keeps it)`],
}),
secrets: (profile, { env, keyring }) => [
{
credentials: {
configDir: resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env }).config,
service: IDENTITY.appName,
envVar: `${IDENTITY.envPrefix}_TOKEN`,
env,
...(keyring ? { keyring } : {}),
},
accounts: [`token:${profile}`],
},
],
}

export const accountCommand = (): Command =>
annotate(new Command("account"), { effects: LOCAL_READ })
.description("this profile on this computer")
.addCommand(
annotate(
accountRemoveCommand(IDENTITY, removal, {
provider: PROVIDER_NAME,
resolveSettings: configuration.resolveSettings,
}),
{ effects: LOCAL_WRITE },
),
)
2 changes: 2 additions & 0 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "@wirecat/cli-core/cli"
import { appUpdate } from "@wirecat/cli-core/update"
import type { Command } from "commander"
import { accountCommand } from "./commands/account.js"
import { meetingsMount } from "./commands/meetings.js"
import { modelsCommand } from "./commands/models.js"
import { sessionCommand } from "./commands/session.js"
Expand Down Expand Up @@ -80,6 +81,7 @@ export const definition = (): ProgramDefinition => {
commands: () => [
commandsCommand(IDENTITY),
sessionCommand(),
accountCommand(),
...meetings.commands(),
modelsCommand(),
appDoctorCommand(IDENTITY, configuration, { packageName: PACKAGE }),
Expand Down
Loading