scrollport 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -0
- package/dist/args.d.ts +21 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +122 -0
- package/dist/args.js.map +1 -0
- package/dist/browser.d.ts +38 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +88 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +122 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/logout.d.ts +15 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +25 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/setup.d.ts +18 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +171 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/status.d.ts +21 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +85 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/credentials.d.ts +54 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +197 -0
- package/dist/credentials.js.map +1 -0
- package/dist/device-client.d.ts +24 -0
- package/dist/device-client.d.ts.map +1 -0
- package/dist/device-client.js +82 -0
- package/dist/device-client.js.map +1 -0
- package/dist/device-flow.d.ts +70 -0
- package/dist/device-flow.d.ts.map +1 -0
- package/dist/device-flow.js +128 -0
- package/dist/device-flow.js.map +1 -0
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +61 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +76 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +163 -0
- package/dist/http.js.map +1 -0
- package/dist/output.d.ts +31 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +27 -0
- package/dist/output.js.map +1 -0
- package/dist/verify.d.ts +4 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +27 -0
- package/dist/verify.js.map +1 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# scrollport CLI
|
|
2
|
+
|
|
3
|
+
Provision an agent's key against one prepaid wallet.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npx scrollport setup
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Two clicks, no typing, no per-provider signup. The command prints a link with the
|
|
10
|
+
approval code already in it, opens your browser, and waits. You sign in, you
|
|
11
|
+
approve, it stores the key. The key is never shown, never pasted, and never
|
|
12
|
+
touches your shell history.
|
|
13
|
+
|
|
14
|
+
> **Published as [`scrollport`](https://www.npmjs.com/package/scrollport)**, so
|
|
15
|
+
> `npx scrollport setup` resolves. The package name and the bin are now the same
|
|
16
|
+
> word, which is what the API's 401 hint has always promised.
|
|
17
|
+
>
|
|
18
|
+
> The root workspace package was renamed `scrollport-monorepo` in the same
|
|
19
|
+
> change: with both named `scrollport`, `pnpm --filter scrollport …` resolved to
|
|
20
|
+
> the root and silently ran `pnpm -r test` — the DB-backed API suites — instead
|
|
21
|
+
> of this package's hermetic ones.
|
|
22
|
+
|
|
23
|
+
## Commands
|
|
24
|
+
|
|
25
|
+
| command | what it does |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `scrollport setup` | device flow: get a key and store it |
|
|
28
|
+
| `scrollport status` | is there a key, and does the API still accept it? |
|
|
29
|
+
| `scrollport logout` | remove the key stored on this machine |
|
|
30
|
+
| `scrollport help` / `version` | |
|
|
31
|
+
|
|
32
|
+
The capability commands from issue #12 — `discover`, `inspect`, `run`, `wallet` —
|
|
33
|
+
are **not in this release**.
|
|
34
|
+
|
|
35
|
+
## Flags
|
|
36
|
+
|
|
37
|
+
| flag | |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `--json` | machine-readable output (see below) |
|
|
40
|
+
| `--api-url <url>` | API origin. Default `https://api.scrollport.com` |
|
|
41
|
+
| `--force` | `setup`: provision a new key even if one already works |
|
|
42
|
+
| `--no-browser` | `setup`: print the link, open nothing |
|
|
43
|
+
| `--offline` | `status`: report what is on disk, skip the API check |
|
|
44
|
+
|
|
45
|
+
## Environment
|
|
46
|
+
|
|
47
|
+
| variable | |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `SCROLLPORT_API_KEY` | a key to use instead of the stored one. **Read, never written** — this is the CI path, where the right store is your platform's secret manager |
|
|
50
|
+
| `SCROLLPORT_API_URL` | default for `--api-url` |
|
|
51
|
+
| `SCROLLPORT_HOME` | config directory (default `~/.scrollport`) |
|
|
52
|
+
| `SCROLLPORT_NO_BROWSER` | set to anything to never open a browser |
|
|
53
|
+
|
|
54
|
+
## `--json`
|
|
55
|
+
|
|
56
|
+
**stdout carries exactly one JSON object. Everything else goes to stderr.** That
|
|
57
|
+
holds for progress, warnings and errors alike, so `JSON.parse(stdout)` is always
|
|
58
|
+
safe.
|
|
59
|
+
|
|
60
|
+
Success:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{ "ok": true, "command": "setup", "account_id": "…", "api_key_masked": "sp_live_…9f2c",
|
|
64
|
+
"api_url": "https://api.scrollport.com", "credentials_path": "/home/you/.scrollport/credentials.json",
|
|
65
|
+
"verified": true, "already_configured": false }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Failure — the API's own `{ error, message, hint }` envelope, plus the exit code:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{ "ok": false, "command": "setup", "error": "access_denied",
|
|
72
|
+
"message": "The approval was declined on the consent screen.",
|
|
73
|
+
"hint": "Nothing was provisioned … run `scrollport setup` again for a fresh code.",
|
|
74
|
+
"exit_code": 3 }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Fields present per command:
|
|
78
|
+
|
|
79
|
+
- `setup` — `already_configured`, `account_id`, `api_key_masked`, `api_url`,
|
|
80
|
+
`credentials_path`, `verified` (`true` when the API accepted the key, `false`
|
|
81
|
+
when it could not be reached to check).
|
|
82
|
+
- `status` — `authenticated`, `source` (`"file"` or `"env"`), `account_id`,
|
|
83
|
+
`api_key_masked`, `api_url`, `credentials_path` (`null` for an env key),
|
|
84
|
+
`verified` (`null` when unchecked), and `permissions_warning` when the file is
|
|
85
|
+
readable beyond its owner.
|
|
86
|
+
- `logout` — `removed`, `credentials_path`, `env_key_still_set`.
|
|
87
|
+
|
|
88
|
+
**The API key itself is never emitted**, in either mode. Masked only. A key in
|
|
89
|
+
stdout is a key in a log, a CI artifact and a screen recording.
|
|
90
|
+
|
|
91
|
+
## Exit codes
|
|
92
|
+
|
|
93
|
+
Agents branch on these, so they are part of the contract.
|
|
94
|
+
|
|
95
|
+
| code | meaning |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| 0 | success |
|
|
98
|
+
| 1 | unexpected error (a bug in the CLI) |
|
|
99
|
+
| 2 | usage: unknown command, bad flag |
|
|
100
|
+
| 3 | a human declined the approval |
|
|
101
|
+
| 4 | the code expired, or was already spent |
|
|
102
|
+
| 5 | the API could not be reached |
|
|
103
|
+
| 6 | no usable key — run `scrollport setup` |
|
|
104
|
+
| 130 | interrupted (Ctrl-C) |
|
|
105
|
+
|
|
106
|
+
## Where the key is stored
|
|
107
|
+
|
|
108
|
+
`~/.scrollport/credentials.json`, file mode `0600`, in a `0700` directory,
|
|
109
|
+
written atomically (temp file created with the mode already set, then renamed —
|
|
110
|
+
so the key is never briefly visible at your umask).
|
|
111
|
+
|
|
112
|
+
**Why a file and not the OS keychain.** The keychain is the better answer for a
|
|
113
|
+
desktop app and the wrong answer here. macOS Keychain, libsecret and Windows
|
|
114
|
+
Credential Manager all need a logged-in, unlocked user session; in a container,
|
|
115
|
+
over SSH, or in CI, that is not a degraded experience but a hang with no visible
|
|
116
|
+
prompt — and containers, SSH and CI are exactly where agents run. Every keychain
|
|
117
|
+
binding also drags in a native module whose prebuilt binaries are a recurring
|
|
118
|
+
`npx` failure. A file is what issue #12 specifies and what `gh`, `aws` and `fly`
|
|
119
|
+
all do, for the same reasons.
|
|
120
|
+
|
|
121
|
+
What the file has to earn in exchange, and does:
|
|
122
|
+
|
|
123
|
+
- `0600` in a `0700` directory, verified on write and **warned about on read** if
|
|
124
|
+
something has loosened it.
|
|
125
|
+
- Atomic write, so an interrupted `setup` cannot leave half a credential.
|
|
126
|
+
- The key is never a command-line argument and is never echoed — the CLI writes
|
|
127
|
+
it itself, straight from the poll response. Nothing about the happy path puts
|
|
128
|
+
it in shell history or terminal scrollback.
|
|
129
|
+
- `SCROLLPORT_API_KEY` is read but never written, so CI keeps its key in a real
|
|
130
|
+
secret manager rather than in our file.
|
|
131
|
+
|
|
132
|
+
The residual risk, stated plainly: anything running as your user can read this
|
|
133
|
+
file. A keychain would narrow that to "anything running as your user that can
|
|
134
|
+
also satisfy an unlock prompt". If we ship a desktop-first surface later, a
|
|
135
|
+
keychain backend belongs behind `credentials.ts` — nothing above that module
|
|
136
|
+
assumes a file.
|
|
137
|
+
|
|
138
|
+
## Development
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
pnpm --filter scrollport build
|
|
142
|
+
pnpm --filter scrollport test # hermetic: no server, no database
|
|
143
|
+
node packages/cli/dist/cli.js setup --api-url http://localhost:8787
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The tests stub `fetch` and point `SCROLLPORT_HOME` at a temp directory. They
|
|
147
|
+
stand up nothing and touch no database.
|
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const COMMANDS: readonly ["setup", "status", "logout", "help", "version"];
|
|
2
|
+
export type Command = (typeof COMMANDS)[number];
|
|
3
|
+
export declare const USAGE = "scrollport \u2014 provision an agent's key against one prepaid wallet.\n\nUsage:\n scrollport setup connect this machine (device flow, two clicks)\n scrollport status is there a key, and does it still work?\n scrollport logout forget the key stored on this machine\n scrollport help | version\n\nOptions:\n --json machine-readable output: one JSON object on stdout,\n progress on stderr. Stable \u2014 see README.md.\n --api-url <url> API origin (default https://api.scrollport.com,\n or $SCROLLPORT_API_URL)\n --force setup: provision a new key even if one already works\n --no-browser setup: print the link, do not open a browser\n --offline status: report what is on disk, skip the API check\n -h, --help this text\n -v, --version print the version\n\nEnvironment:\n SCROLLPORT_API_KEY a key to use instead of the stored one (read, never\n written \u2014 this is the CI path)\n SCROLLPORT_API_URL default for --api-url\n SCROLLPORT_HOME config directory (default ~/.scrollport)\n SCROLLPORT_NO_BROWSER set to anything to never open a browser\n\nExit codes:\n 0 ok \u00B7 1 error \u00B7 2 usage \u00B7 3 approval denied \u00B7 4 code expired\n 5 API unreachable \u00B7 6 no usable key (run `scrollport setup`) \u00B7 130 interrupted\n\nCapability commands (discover, inspect, run, wallet) are not in this release.\n";
|
|
4
|
+
/** The published version, read from our own package.json at run time. */
|
|
5
|
+
export declare function version(): string;
|
|
6
|
+
export interface ParsedArgs {
|
|
7
|
+
command: Command;
|
|
8
|
+
json: boolean;
|
|
9
|
+
apiUrl: string | undefined;
|
|
10
|
+
force: boolean;
|
|
11
|
+
noBrowser: boolean;
|
|
12
|
+
offline: boolean;
|
|
13
|
+
}
|
|
14
|
+
export type Env = Record<string, string | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Parse argv. Unknown flags and unknown commands are usage errors (exit 2) with
|
|
17
|
+
* a hint naming what is actually available — a CLI that answers a typo with
|
|
18
|
+
* "unknown option" and nothing else has wasted the user's next minute.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseCommandLine(argv: string[], env?: Env): ParsedArgs;
|
|
21
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,QAAQ,2DAA4D,CAAC;AAClF,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhD,eAAO,MAAM,KAAK,khDA+BjB,CAAC;AAEF,yEAAyE;AACzE,wBAAgB,OAAO,IAAI,MAAM,CAQhC;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,GAAE,GAAiB,GAAG,UAAU,CA4DnF"}
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command line parsing, usage text, and version — everything `cli.ts` needs to
|
|
3
|
+
* know before it does anything.
|
|
4
|
+
*
|
|
5
|
+
* Split out from the entry point for one reason: `cli.ts` runs `main()` on
|
|
6
|
+
* import, so nothing in it can be unit tested. This can.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
10
|
+
import { CliError, EXIT_USAGE } from "./errors.js";
|
|
11
|
+
import { DEFAULT_API_URL } from "./http.js";
|
|
12
|
+
export const COMMANDS = ["setup", "status", "logout", "help", "version"];
|
|
13
|
+
export const USAGE = `scrollport — provision an agent's key against one prepaid wallet.
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
scrollport setup connect this machine (device flow, two clicks)
|
|
17
|
+
scrollport status is there a key, and does it still work?
|
|
18
|
+
scrollport logout forget the key stored on this machine
|
|
19
|
+
scrollport help | version
|
|
20
|
+
|
|
21
|
+
Options:
|
|
22
|
+
--json machine-readable output: one JSON object on stdout,
|
|
23
|
+
progress on stderr. Stable — see README.md.
|
|
24
|
+
--api-url <url> API origin (default ${DEFAULT_API_URL},
|
|
25
|
+
or $SCROLLPORT_API_URL)
|
|
26
|
+
--force setup: provision a new key even if one already works
|
|
27
|
+
--no-browser setup: print the link, do not open a browser
|
|
28
|
+
--offline status: report what is on disk, skip the API check
|
|
29
|
+
-h, --help this text
|
|
30
|
+
-v, --version print the version
|
|
31
|
+
|
|
32
|
+
Environment:
|
|
33
|
+
SCROLLPORT_API_KEY a key to use instead of the stored one (read, never
|
|
34
|
+
written — this is the CI path)
|
|
35
|
+
SCROLLPORT_API_URL default for --api-url
|
|
36
|
+
SCROLLPORT_HOME config directory (default ~/.scrollport)
|
|
37
|
+
SCROLLPORT_NO_BROWSER set to anything to never open a browser
|
|
38
|
+
|
|
39
|
+
Exit codes:
|
|
40
|
+
0 ok · 1 error · 2 usage · 3 approval denied · 4 code expired
|
|
41
|
+
5 API unreachable · 6 no usable key (run \`scrollport setup\`) · 130 interrupted
|
|
42
|
+
|
|
43
|
+
Capability commands (discover, inspect, run, wallet) are not in this release.
|
|
44
|
+
`;
|
|
45
|
+
/** The published version, read from our own package.json at run time. */
|
|
46
|
+
export function version() {
|
|
47
|
+
try {
|
|
48
|
+
const raw = readFileSync(new URL("../package.json", import.meta.url), "utf8");
|
|
49
|
+
const pkg = JSON.parse(raw);
|
|
50
|
+
return pkg.version ?? "0.0.0";
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return "0.0.0";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parse argv. Unknown flags and unknown commands are usage errors (exit 2) with
|
|
58
|
+
* a hint naming what is actually available — a CLI that answers a typo with
|
|
59
|
+
* "unknown option" and nothing else has wasted the user's next minute.
|
|
60
|
+
*/
|
|
61
|
+
export function parseCommandLine(argv, env = process.env) {
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = parseArgs({
|
|
65
|
+
args: argv,
|
|
66
|
+
allowPositionals: true,
|
|
67
|
+
strict: true,
|
|
68
|
+
options: {
|
|
69
|
+
json: { type: "boolean", default: false },
|
|
70
|
+
"api-url": { type: "string" },
|
|
71
|
+
force: { type: "boolean", default: false },
|
|
72
|
+
"no-browser": { type: "boolean", default: false },
|
|
73
|
+
offline: { type: "boolean", default: false },
|
|
74
|
+
help: { type: "boolean", short: "h", default: false },
|
|
75
|
+
version: { type: "boolean", short: "v", default: false },
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (cause) {
|
|
80
|
+
throw new CliError("usage", cause instanceof Error ? cause.message : String(cause), {
|
|
81
|
+
hint: "Run `scrollport help` for the full list of commands and flags.",
|
|
82
|
+
exitCode: EXIT_USAGE,
|
|
83
|
+
cause,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const { values, positionals } = parsed;
|
|
87
|
+
let command;
|
|
88
|
+
if (values.help === true)
|
|
89
|
+
command = "help";
|
|
90
|
+
else if (values.version === true)
|
|
91
|
+
command = "version";
|
|
92
|
+
else {
|
|
93
|
+
const first = positionals[0];
|
|
94
|
+
if (first === undefined)
|
|
95
|
+
command = "help";
|
|
96
|
+
else if (COMMANDS.includes(first))
|
|
97
|
+
command = first;
|
|
98
|
+
else {
|
|
99
|
+
throw new CliError("unknown_command", `Unknown command: ${first}`, {
|
|
100
|
+
hint: `Try one of: ${COMMANDS.join(", ")} — example: scrollport setup`,
|
|
101
|
+
exitCode: EXIT_USAGE,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const extra = positionals.slice(1);
|
|
106
|
+
if (extra.length > 0) {
|
|
107
|
+
throw new CliError("usage", `\`${command}\` takes no arguments (got: ${extra.join(" ")}).`, {
|
|
108
|
+
hint: `example: scrollport ${command}`,
|
|
109
|
+
exitCode: EXIT_USAGE,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const apiUrl = values["api-url"] ?? env["SCROLLPORT_API_URL"];
|
|
113
|
+
return {
|
|
114
|
+
command,
|
|
115
|
+
json: values.json === true,
|
|
116
|
+
...(apiUrl === undefined ? { apiUrl: undefined } : { apiUrl }),
|
|
117
|
+
force: values.force === true,
|
|
118
|
+
noBrowser: values["no-browser"] === true,
|
|
119
|
+
offline: values.offline === true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=args.js.map
|
package/dist/args.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAU,CAAC;AAGlF,MAAM,CAAC,MAAM,KAAK,GAAG;;;;;;;;;;;gDAW2B,eAAe;;;;;;;;;;;;;;;;;;;;CAoB9D,CAAC;AAEF,yEAAyE;AACzE,MAAM,UAAU,OAAO;IACrB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;QAC9E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;QACpD,OAAO,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAaD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAc,EAAE,MAAW,OAAO,CAAC,GAAG;IAC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1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opening the consent URL — the click that turns 60 seconds of setup into two
|
|
3
|
+
* clicks (issue #9).
|
|
4
|
+
*
|
|
5
|
+
* Two rules govern this file:
|
|
6
|
+
*
|
|
7
|
+
* 1. **The URL is validated before it is handed to a shell.** It comes from an
|
|
8
|
+
* HTTP response, which makes it untrusted input by definition. We check it
|
|
9
|
+
* parses and is http(s) before spawning anything, and we never interpolate it
|
|
10
|
+
* into a shell string on POSIX.
|
|
11
|
+
* 2. **Failing to open is never fatal.** The URL is always printed first. A
|
|
12
|
+
* headless box with no `xdg-open` should print the link and carry on
|
|
13
|
+
* polling — not abort a setup that a human could still complete on a phone.
|
|
14
|
+
*/
|
|
15
|
+
import { spawn } from "node:child_process";
|
|
16
|
+
import type { Env } from "./credentials.js";
|
|
17
|
+
/**
|
|
18
|
+
* Parse and vet a URL we were handed by the API. Rejects anything that is not
|
|
19
|
+
* http(s) — a `file://` or `javascript:` URL reaching `open` would be a remote
|
|
20
|
+
* code execution bug wearing a convenience feature's clothes.
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertSafeUrl(raw: string): URL;
|
|
23
|
+
/**
|
|
24
|
+
* Should we even try? A browser we cannot see is worse than no browser: it opens
|
|
25
|
+
* somewhere nobody is looking while the terminal claims success.
|
|
26
|
+
*/
|
|
27
|
+
export declare function shouldOpenBrowser(env?: Env, disabled?: boolean): boolean;
|
|
28
|
+
export interface OpenDeps {
|
|
29
|
+
/** Injected for tests; defaults to `child_process.spawn`. */
|
|
30
|
+
spawnFn?: typeof spawn;
|
|
31
|
+
platform?: NodeJS.Platform;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Best-effort open. Returns whether the launcher was started — not whether a
|
|
35
|
+
* human ever saw it, which we cannot know.
|
|
36
|
+
*/
|
|
37
|
+
export declare function openInBrowser(url: URL, deps?: OpenDeps): boolean;
|
|
38
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAiB9C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,GAAiB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAQnF;AAED,MAAM,WAAW,QAAQ;IACvB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,QAAa,GAAG,OAAO,CA8BpE"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opening the consent URL — the click that turns 60 seconds of setup into two
|
|
3
|
+
* clicks (issue #9).
|
|
4
|
+
*
|
|
5
|
+
* Two rules govern this file:
|
|
6
|
+
*
|
|
7
|
+
* 1. **The URL is validated before it is handed to a shell.** It comes from an
|
|
8
|
+
* HTTP response, which makes it untrusted input by definition. We check it
|
|
9
|
+
* parses and is http(s) before spawning anything, and we never interpolate it
|
|
10
|
+
* into a shell string on POSIX.
|
|
11
|
+
* 2. **Failing to open is never fatal.** The URL is always printed first. A
|
|
12
|
+
* headless box with no `xdg-open` should print the link and carry on
|
|
13
|
+
* polling — not abort a setup that a human could still complete on a phone.
|
|
14
|
+
*/
|
|
15
|
+
import { spawn } from "node:child_process";
|
|
16
|
+
import { CliError } from "./errors.js";
|
|
17
|
+
/**
|
|
18
|
+
* Parse and vet a URL we were handed by the API. Rejects anything that is not
|
|
19
|
+
* http(s) — a `file://` or `javascript:` URL reaching `open` would be a remote
|
|
20
|
+
* code execution bug wearing a convenience feature's clothes.
|
|
21
|
+
*/
|
|
22
|
+
export function assertSafeUrl(raw) {
|
|
23
|
+
let url;
|
|
24
|
+
try {
|
|
25
|
+
url = new URL(raw);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new CliError("invalid_verification_uri", `The API returned a URL we cannot parse: ${raw}`, {
|
|
29
|
+
hint: "This is a server-side bug. Check --api-url points at a scrollport API.",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
33
|
+
throw new CliError("invalid_verification_uri", `The API returned a non-web verification URL (${url.protocol}).`, { hint: "Refusing to open it. Check --api-url points at a scrollport API." });
|
|
34
|
+
}
|
|
35
|
+
return url;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Should we even try? A browser we cannot see is worse than no browser: it opens
|
|
39
|
+
* somewhere nobody is looking while the terminal claims success.
|
|
40
|
+
*/
|
|
41
|
+
export function shouldOpenBrowser(env = process.env, disabled = false) {
|
|
42
|
+
if (disabled)
|
|
43
|
+
return false;
|
|
44
|
+
if (env["SCROLLPORT_NO_BROWSER"])
|
|
45
|
+
return false;
|
|
46
|
+
if (env["CI"])
|
|
47
|
+
return false;
|
|
48
|
+
// An SSH session's browser would open on the far end of the wrong machine.
|
|
49
|
+
if (env["SSH_CONNECTION"] || env["SSH_TTY"])
|
|
50
|
+
return false;
|
|
51
|
+
if (process.platform === "linux" && !env["DISPLAY"] && !env["WAYLAND_DISPLAY"])
|
|
52
|
+
return false;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Best-effort open. Returns whether the launcher was started — not whether a
|
|
57
|
+
* human ever saw it, which we cannot know.
|
|
58
|
+
*/
|
|
59
|
+
export function openInBrowser(url, deps = {}) {
|
|
60
|
+
const platform = deps.platform ?? process.platform;
|
|
61
|
+
const spawnFn = deps.spawnFn ?? spawn;
|
|
62
|
+
const [command, args] = platform === "darwin"
|
|
63
|
+
? ["open", [url.href]]
|
|
64
|
+
: platform === "win32"
|
|
65
|
+
? // `start` is a cmd builtin, so it needs cmd. The empty "" is the window
|
|
66
|
+
// title argument — without it, cmd treats a quoted URL as the title and
|
|
67
|
+
// opens nothing. `shell: false` below keeps the URL a single argv slot.
|
|
68
|
+
["cmd", ["/c", "start", "", url.href]]
|
|
69
|
+
: ["xdg-open", [url.href]];
|
|
70
|
+
try {
|
|
71
|
+
const child = spawnFn(command, [...args], {
|
|
72
|
+
stdio: "ignore",
|
|
73
|
+
detached: true,
|
|
74
|
+
shell: false,
|
|
75
|
+
windowsHide: true,
|
|
76
|
+
});
|
|
77
|
+
// Do not let a browser process hold the CLI's event loop open.
|
|
78
|
+
child.unref();
|
|
79
|
+
// A launcher that fails after spawn (no xdg-open installed) must not crash
|
|
80
|
+
// us — the URL is already on screen.
|
|
81
|
+
child.on("error", () => { });
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,QAAQ,CAAC,0BAA0B,EAAE,2CAA2C,GAAG,EAAE,EAAE;YA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CAAC,CAAC,QAAQ,KAAK,OAAO;YACpB,CAAC,CAAC,wEAAwE;gBACxE,wEAAwE;gBACxE,wEAAwE;gBACvE,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,CAAW;YACnD,CAAC,CAAE,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAW,CAAC;IAE5C,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE;YACxC,KAAK,EAAE,QAAQ;YACf,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,KAAK;YACZ,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,+DAA+D;QAC/D,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,2EAA2E;QAC3E,qCAAqC;QACrC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `scrollport` — the entry point.
|
|
4
|
+
*
|
|
5
|
+
* Dispatch, and the mapping from a failure to an exit code. All the actual
|
|
6
|
+
* behaviour lives in `commands/`; this file's job is to be boring and to never
|
|
7
|
+
* let an exception reach the user as a raw stack trace unless it really is a bug
|
|
8
|
+
* of ours.
|
|
9
|
+
*
|
|
10
|
+
* Scope note: this release ships the auth surface (`setup`, `status`, `logout`).
|
|
11
|
+
* The capability commands from issue #12 (`discover`, `inspect`, `run`,
|
|
12
|
+
* `wallet`) are not here yet, and `--help` says so rather than implying a
|
|
13
|
+
* surface that does not exist.
|
|
14
|
+
*/
|
|
15
|
+
import { parseCommandLine, USAGE, version } from "./args.js";
|
|
16
|
+
import { runLogout } from "./commands/logout.js";
|
|
17
|
+
import { runSetup } from "./commands/setup.js";
|
|
18
|
+
import { runStatus } from "./commands/status.js";
|
|
19
|
+
import { CliError, EXIT_ERROR, EXIT_INTERRUPTED, EXIT_OK, isCliError } from "./errors.js";
|
|
20
|
+
import { ApiClient, DEFAULT_API_URL, normalizeApiUrl } from "./http.js";
|
|
21
|
+
import { createReporter } from "./output.js";
|
|
22
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
23
|
+
setTimeout(resolve, ms);
|
|
24
|
+
});
|
|
25
|
+
async function main(argv = process.argv.slice(2)) {
|
|
26
|
+
// A usage error happens before parsing has produced anything to trust, but an
|
|
27
|
+
// agent that asked for `--json` still needs JSON back — a machine-readable CLI
|
|
28
|
+
// that answers a typo in prose has just handed its caller an unparseable
|
|
29
|
+
// failure. Scanning raw argv is enough, and a mistyped `--json` falls back to
|
|
30
|
+
// human output, which is the right way round.
|
|
31
|
+
const wantsJson = argv.includes("--json");
|
|
32
|
+
let args;
|
|
33
|
+
try {
|
|
34
|
+
args = parseCommandLine(argv);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
return report(createReporter({ json: wantsJson }), "cli", err);
|
|
38
|
+
}
|
|
39
|
+
const reporter = createReporter({ json: args.json });
|
|
40
|
+
try {
|
|
41
|
+
switch (args.command) {
|
|
42
|
+
case "help":
|
|
43
|
+
reporter.finish("help", { json: { usage: USAGE }, human: [USAGE.trimEnd()] });
|
|
44
|
+
return EXIT_OK;
|
|
45
|
+
case "version":
|
|
46
|
+
reporter.finish("version", { json: { version: version() }, human: [version()] });
|
|
47
|
+
return EXIT_OK;
|
|
48
|
+
case "logout":
|
|
49
|
+
reporter.finish("logout", runLogout({ env: process.env }));
|
|
50
|
+
return EXIT_OK;
|
|
51
|
+
case "setup": {
|
|
52
|
+
const client = makeClient(args.apiUrl);
|
|
53
|
+
installInterruptHandler(reporter, "setup");
|
|
54
|
+
const result = await runSetup({ client, reporter, env: process.env, sleep, now: () => Date.now() }, { force: args.force, noBrowser: args.noBrowser });
|
|
55
|
+
reporter.finish("setup", result);
|
|
56
|
+
return EXIT_OK;
|
|
57
|
+
}
|
|
58
|
+
case "status": {
|
|
59
|
+
const client = makeClient(args.apiUrl);
|
|
60
|
+
const result = await runStatus({ client, reporter, env: process.env }, { offline: args.offline });
|
|
61
|
+
reporter.finish("status", result);
|
|
62
|
+
return EXIT_OK;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
return report(reporter, args.command, err);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function makeClient(apiUrl) {
|
|
71
|
+
return new ApiClient(normalizeApiUrl(apiUrl ?? DEFAULT_API_URL));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Render a failure and pick its exit code. Anything that is not a CliError is a
|
|
75
|
+
* bug in this CLI, and gets a stack trace — being noisier about our own faults
|
|
76
|
+
* than about a user's mistake is the point.
|
|
77
|
+
*/
|
|
78
|
+
function report(reporter, command, err) {
|
|
79
|
+
if (isCliError(err)) {
|
|
80
|
+
reporter.fail(command, err);
|
|
81
|
+
return err.exitCode;
|
|
82
|
+
}
|
|
83
|
+
if (err instanceof Error && err.stack)
|
|
84
|
+
process.stderr.write(`${err.stack}\n`);
|
|
85
|
+
reporter.fail(command, new CliError("internal_error", err instanceof Error ? err.message : String(err), {
|
|
86
|
+
hint: "This is a bug in the scrollport CLI, not something you did. The stack trace above is the useful part of a report.",
|
|
87
|
+
exitCode: EXIT_ERROR,
|
|
88
|
+
}));
|
|
89
|
+
return EXIT_ERROR;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Ctrl-C during a ten-minute wait is the expected way to abandon a setup, so it
|
|
93
|
+
* gets a real message rather than a `^C` and silence.
|
|
94
|
+
*/
|
|
95
|
+
function installInterruptHandler(reporter, command) {
|
|
96
|
+
process.on("SIGINT", () => {
|
|
97
|
+
reporter.fail(command, new CliError("interrupted", "Stopped waiting for approval.", {
|
|
98
|
+
hint: "If you approved in the browser just now, the key may already be stored — check with `scrollport status`. Otherwise run `scrollport setup` again.",
|
|
99
|
+
exitCode: EXIT_INTERRUPTED,
|
|
100
|
+
}));
|
|
101
|
+
finish(EXIT_INTERRUPTED);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Exit once stdout has drained.
|
|
106
|
+
*
|
|
107
|
+
* `process.exit` is deliberate rather than falling off the end of `main`: Node's
|
|
108
|
+
* global `fetch` holds keep-alive sockets open after the last response, which
|
|
109
|
+
* can add seconds to a command that has already printed its answer — against a
|
|
110
|
+
* 60-second end-to-end budget. Draining first is what keeps a piped `--json`
|
|
111
|
+
* from being truncated by that exit.
|
|
112
|
+
*/
|
|
113
|
+
function finish(code) {
|
|
114
|
+
process.exitCode = code;
|
|
115
|
+
if (process.stdout.writableLength + process.stderr.writableLength === 0) {
|
|
116
|
+
process.exit(code);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
process.stdout.write("", () => process.exit(code));
|
|
120
|
+
}
|
|
121
|
+
void main().then(finish);
|
|
122
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,OAAO,EAAmB,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE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I,EAAE,kJAAkJ;YACxJ,QAAQ,EAAE,gBAAgB;SAC3B,CAAC,CACH,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IACxB,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,OAAO;IACT,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `scrollport logout` — forget the key on this machine.
|
|
3
|
+
*
|
|
4
|
+
* Local only, and says so. It deletes the file; it does **not** revoke the key
|
|
5
|
+
* server-side, because a key that is still valid somewhere else is exactly what
|
|
6
|
+
* this command must not silently kill. Revocation lives in the dashboard
|
|
7
|
+
* (issue #16), and the message points there rather than pretending.
|
|
8
|
+
*/
|
|
9
|
+
import { type Env } from "../credentials.js";
|
|
10
|
+
import type { CommandResult } from "../output.js";
|
|
11
|
+
export interface LogoutDeps {
|
|
12
|
+
env: Env;
|
|
13
|
+
}
|
|
14
|
+
export declare function runLogout(deps: LogoutDeps): CommandResult;
|
|
15
|
+
//# sourceMappingURL=logout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/commands/logout.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAsC,KAAK,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,GAAG,CAAC;CACV;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,aAAa,CAiBzD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `scrollport logout` — forget the key on this machine.
|
|
3
|
+
*
|
|
4
|
+
* Local only, and says so. It deletes the file; it does **not** revoke the key
|
|
5
|
+
* server-side, because a key that is still valid somewhere else is exactly what
|
|
6
|
+
* this command must not silently kill. Revocation lives in the dashboard
|
|
7
|
+
* (issue #16), and the message points there rather than pretending.
|
|
8
|
+
*/
|
|
9
|
+
import { credentialsPath, deleteCredentials } from "../credentials.js";
|
|
10
|
+
export function runLogout(deps) {
|
|
11
|
+
const path = credentialsPath(deps.env);
|
|
12
|
+
const removed = deleteCredentials(deps.env);
|
|
13
|
+
const envKeySet = Boolean(deps.env["SCROLLPORT_API_KEY"]?.trim());
|
|
14
|
+
const human = removed
|
|
15
|
+
? [`Removed ${path}.`, "The key still exists server-side — revoke it from the dashboard to kill it."]
|
|
16
|
+
: [`Nothing to remove (${path} does not exist).`];
|
|
17
|
+
if (envKeySet) {
|
|
18
|
+
human.push("SCROLLPORT_API_KEY is still set in this environment; unset it to fully disconnect.");
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
json: { removed, credentials_path: path, env_key_still_set: envKeySet },
|
|
22
|
+
human,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=logout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/commands/logout.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAY,MAAM,mBAAmB,CAAC;AAOjF,MAAM,UAAU,SAAS,CAAC,IAAgB;IACxC,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAElE,MAAM,KAAK,GAAG,OAAO;QACnB,CAAC,CAAC,CAAC,WAAW,IAAI,GAAG,EAAE,6EAA6E,CAAC;QACrG,CAAC,CAAC,CAAC,sBAAsB,IAAI,mBAAmB,CAAC,CAAC;IAEpD,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,CAAC,IAAI,CAAC,oFAAoF,CAAC,CAAC;IACnG,CAAC;IAED,OAAO;QACL,IAAI,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE;QACvE,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Env } from "../credentials.js";
|
|
2
|
+
import type { ApiClient } from "../http.js";
|
|
3
|
+
import type { CommandResult, Reporter } from "../output.js";
|
|
4
|
+
export interface SetupDeps {
|
|
5
|
+
client: ApiClient;
|
|
6
|
+
reporter: Reporter;
|
|
7
|
+
env: Env;
|
|
8
|
+
sleep: (ms: number) => Promise<void>;
|
|
9
|
+
now: () => number;
|
|
10
|
+
}
|
|
11
|
+
export interface SetupOptions {
|
|
12
|
+
/** Re-run the flow even when a working key is already stored. */
|
|
13
|
+
force: boolean;
|
|
14
|
+
/** `--no-browser`: print the link, open nothing. */
|
|
15
|
+
noBrowser: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function runSetup(deps: SetupDeps, opts: SetupOptions): Promise<CommandResult>;
|
|
18
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAqBA,OAAO,EAKL,KAAK,GAAG,EACT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAM5D,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,GAAG,EAAE,MAAM,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,iEAAiE;IACjE,KAAK,EAAE,OAAO,CAAC;IACf,oDAAoD;IACpD,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA0K1F"}
|