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/dist/http.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The thinnest possible API client: one request method, no business logic
|
|
3
|
+
* (issue #12 — "thin pure API client"). Everything it knows about the contract
|
|
4
|
+
* is the base path and the `{ error, message, hint }` error envelope.
|
|
5
|
+
*
|
|
6
|
+
* No HTTP library. Node ≥22 has `fetch`, and a CLI people reach through `npx`
|
|
7
|
+
* pays for every dependency in start-up latency against a 60-second budget
|
|
8
|
+
* (issue #9's acceptance criterion).
|
|
9
|
+
*/
|
|
10
|
+
import { CliError, EXIT_NETWORK } from "./errors.js";
|
|
11
|
+
/**
|
|
12
|
+
* The versioned prefix every endpoint sits under. Mirrors `API_BASE_PATH` from
|
|
13
|
+
* `@scrollport/shared`, which is the executable contract; duplicated as a
|
|
14
|
+
* literal only so this package carries no runtime dependency on a private
|
|
15
|
+
* workspace package. `http.test.ts` asserts the two agree, so the duplication
|
|
16
|
+
* cannot drift silently.
|
|
17
|
+
*/
|
|
18
|
+
export const API_BASE_PATH = "/v1";
|
|
19
|
+
/** Where the API lives when nothing says otherwise. */
|
|
20
|
+
export const DEFAULT_API_URL = "https://api.scrollport.com";
|
|
21
|
+
/** Per-request ceiling. Generous: a cold Railway container can be slow. */
|
|
22
|
+
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
23
|
+
/**
|
|
24
|
+
* Normalize whatever the user typed into an origin we can append paths to.
|
|
25
|
+
*
|
|
26
|
+
* Accepts `api.scrollport.com`, `https://api.scrollport.com/`, and
|
|
27
|
+
* `http://localhost:8787/v1` alike — the trailing `/v1` is stripped because we
|
|
28
|
+
* add it ourselves, and getting `/v1/v1/wallet` for being helpful is a bad
|
|
29
|
+
* first-run experience.
|
|
30
|
+
*/
|
|
31
|
+
export function normalizeApiUrl(raw) {
|
|
32
|
+
const trimmed = raw.trim();
|
|
33
|
+
if (!trimmed) {
|
|
34
|
+
throw new CliError("invalid_api_url", "The API URL is empty.", {
|
|
35
|
+
hint: `example: --api-url ${DEFAULT_API_URL}`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// Only a value with NO scheme at all gets https:// prepended. Testing for
|
|
39
|
+
// `https?://` instead would turn `file:///etc/passwd` into a valid URL for a
|
|
40
|
+
// host called "file" — silently accepting exactly what the check below exists
|
|
41
|
+
// to reject.
|
|
42
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:/i.test(trimmed);
|
|
43
|
+
const withScheme = hasScheme ? trimmed : `https://${trimmed}`;
|
|
44
|
+
let url;
|
|
45
|
+
try {
|
|
46
|
+
url = new URL(withScheme);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw new CliError("invalid_api_url", `Not a URL: ${raw}`, {
|
|
50
|
+
hint: `example: --api-url ${DEFAULT_API_URL}`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
54
|
+
throw new CliError("invalid_api_url", `Unsupported scheme: ${url.protocol}`, {
|
|
55
|
+
hint: `The API is spoken over http or https — example: --api-url ${DEFAULT_API_URL}`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const path = url.pathname.replace(/\/+$/, "").replace(new RegExp(`${API_BASE_PATH}$`), "");
|
|
59
|
+
return `${url.origin}${path}`;
|
|
60
|
+
}
|
|
61
|
+
export class ApiClient {
|
|
62
|
+
baseUrl;
|
|
63
|
+
fetchImpl;
|
|
64
|
+
timeoutMs;
|
|
65
|
+
constructor(baseUrl, opts = {}) {
|
|
66
|
+
this.baseUrl = baseUrl;
|
|
67
|
+
this.fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
68
|
+
this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Send one request. Returns non-2xx responses rather than throwing: the
|
|
72
|
+
* device-flow poll spends its whole life reading HTTP 400s that are not
|
|
73
|
+
* failures (RFC 8628 §3.5), so "not ok" cannot mean "throw" here.
|
|
74
|
+
*
|
|
75
|
+
* Only a *transport* failure throws, and it throws a CliError that names the
|
|
76
|
+
* URL — "connection refused" with no address is the least useful message in
|
|
77
|
+
* computing.
|
|
78
|
+
*/
|
|
79
|
+
async send(method, path, opts = {}) {
|
|
80
|
+
const url = `${this.baseUrl}${API_BASE_PATH}${path}`;
|
|
81
|
+
const headers = { accept: "application/json" };
|
|
82
|
+
if (opts.body !== undefined)
|
|
83
|
+
headers["content-type"] = "application/json";
|
|
84
|
+
if (opts.apiKey)
|
|
85
|
+
headers["authorization"] = `Bearer ${opts.apiKey}`;
|
|
86
|
+
let response;
|
|
87
|
+
try {
|
|
88
|
+
response = await this.fetchImpl(url, {
|
|
89
|
+
method,
|
|
90
|
+
headers,
|
|
91
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
92
|
+
...(opts.body === undefined ? {} : { body: JSON.stringify(opts.body) }),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (cause) {
|
|
96
|
+
throw new CliError("api_unreachable", `Could not reach the scrollport API at ${url}.`, {
|
|
97
|
+
hint: `Check your connection, then retry. Pointing at a local API: --api-url http://localhost:8787 (or SCROLLPORT_API_URL). Cause: ${describe(cause)}`,
|
|
98
|
+
exitCode: EXIT_NETWORK,
|
|
99
|
+
cause,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return { status: response.status, ok: response.ok, body: await readJson(response) };
|
|
103
|
+
}
|
|
104
|
+
/** `send`, but a non-2xx is a failure and the API's own teaching error is kept. */
|
|
105
|
+
async request(method, path, opts = {}) {
|
|
106
|
+
const res = await this.send(method, path, opts);
|
|
107
|
+
if (!res.ok)
|
|
108
|
+
throw toCliError(res);
|
|
109
|
+
return res.body;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Best-effort JSON decode. A body that is not JSON is information, not a crash. */
|
|
113
|
+
async function readJson(response) {
|
|
114
|
+
let text;
|
|
115
|
+
try {
|
|
116
|
+
text = await response.text();
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
if (!text.trim())
|
|
122
|
+
return undefined;
|
|
123
|
+
try {
|
|
124
|
+
return JSON.parse(text);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return { error: "unexpected_response", message: text.slice(0, 500) };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** True when a body carries the API's `{ error, message }` envelope. */
|
|
131
|
+
export function isTeachingError(body) {
|
|
132
|
+
if (typeof body !== "object" || body === null)
|
|
133
|
+
return false;
|
|
134
|
+
const candidate = body;
|
|
135
|
+
return typeof candidate["error"] === "string" && typeof candidate["message"] === "string";
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Turn a failed response into a CliError, preserving the API's message and hint
|
|
139
|
+
* verbatim. The server already wrote a teaching error (CLAUDE.md > Invariant 5);
|
|
140
|
+
* rewording it here would only lose information.
|
|
141
|
+
*/
|
|
142
|
+
export function toCliError(res) {
|
|
143
|
+
// A 5xx is the server having a bad day, not the caller having done something
|
|
144
|
+
// wrong — same class of thing as a dropped connection, so same exit code.
|
|
145
|
+
const serverSide = res.status >= 500 ? { exitCode: EXIT_NETWORK } : {};
|
|
146
|
+
if (isTeachingError(res.body)) {
|
|
147
|
+
const hint = typeof res.body.hint === "string" ? res.body.hint : undefined;
|
|
148
|
+
return new CliError(res.body.error, res.body.message, {
|
|
149
|
+
...(hint === undefined ? {} : { hint }),
|
|
150
|
+
...serverSide,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return new CliError("unexpected_response", `The API returned HTTP ${res.status} with no error body.`, {
|
|
154
|
+
hint: "This is a bug on our side. Retry, and if it persists report the status code.",
|
|
155
|
+
...serverSide,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function describe(cause) {
|
|
159
|
+
if (cause instanceof Error)
|
|
160
|
+
return cause.message;
|
|
161
|
+
return String(cause);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AAEnC,uDAAuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAE5D,2EAA2E;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAiBzC;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,QAAQ,CAAC,iBAAiB,EAAE,uBAAuB,EAAE;YAC7D,IAAI,EAAE,sBAAsB,eAAe,EAAE;SAC9C,CAAC,CAAC;IACL,CAAC;IAED,0EAA0E;IAC1E,6EAA6E;IAC7E,8EAA8E;IAC9E,aAAa;IACb,MAAM,SAAS,GAAG,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,OAAO,EAAE,CAAC;IAE9D,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,QAAQ,CAAC,iBAAiB,EAAE,cAAc,GAAG,EAAE,EAAE;YAC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,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE;YACpD,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;YACvC,GAAG,UAAU;SACd,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,QAAQ,CACjB,qBAAqB,EACrB,yBAAyB,GAAG,CAAC,MAAM,sBAAsB,EACzD;QACE,IAAI,EAAE,8EAA8E;QACpF,GAAG,UAAU;KACd,CACF,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output discipline: **progress goes to stderr, the result goes to stdout.**
|
|
3
|
+
*
|
|
4
|
+
* That split is what makes `--json` a stable machine contract (issue #12) — an
|
|
5
|
+
* agent can `JSON.parse(stdout)` unconditionally, because nothing else is ever
|
|
6
|
+
* written there. Human-readable mode uses the same two streams so a pipeline can
|
|
7
|
+
* mix them without either surprising the other.
|
|
8
|
+
*/
|
|
9
|
+
import type { CliError } from "./errors.js";
|
|
10
|
+
/** What a command hands back: one machine object, and the lines a human reads. */
|
|
11
|
+
export interface CommandResult {
|
|
12
|
+
/** Merged into the `--json` envelope. Must contain no secrets. */
|
|
13
|
+
json: Record<string, unknown>;
|
|
14
|
+
/** stdout lines for a human. Empty is legal. */
|
|
15
|
+
human: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface Reporter {
|
|
18
|
+
/** Progress, warnings, prompts — stderr, and suppressed by nothing. */
|
|
19
|
+
progress(line: string): void;
|
|
20
|
+
/** The final word. Exactly one JSON object in `--json` mode. */
|
|
21
|
+
finish(command: string, result: CommandResult): void;
|
|
22
|
+
/** The final word when it failed. */
|
|
23
|
+
fail(command: string, err: CliError): void;
|
|
24
|
+
}
|
|
25
|
+
export interface ReporterOptions {
|
|
26
|
+
json: boolean;
|
|
27
|
+
writeOut?: (text: string) => void;
|
|
28
|
+
writeErr?: (text: string) => void;
|
|
29
|
+
}
|
|
30
|
+
export declare function createReporter(opts: ReporterOptions): Reporter;
|
|
31
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,gDAAgD;IAChD,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,gEAAgE;IAChE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IACrD,qCAAqC;IACrC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,QAAQ,CA0B9D"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function createReporter(opts) {
|
|
2
|
+
const out = opts.writeOut ?? ((text) => process.stdout.write(text));
|
|
3
|
+
const err = opts.writeErr ?? ((text) => process.stderr.write(text));
|
|
4
|
+
return {
|
|
5
|
+
progress(line) {
|
|
6
|
+
err(`${line}\n`);
|
|
7
|
+
},
|
|
8
|
+
finish(command, result) {
|
|
9
|
+
if (opts.json) {
|
|
10
|
+
out(`${JSON.stringify({ ok: true, command, ...result.json })}\n`);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
for (const line of result.human)
|
|
14
|
+
out(`${line}\n`);
|
|
15
|
+
},
|
|
16
|
+
fail(command, cliError) {
|
|
17
|
+
if (opts.json) {
|
|
18
|
+
out(`${JSON.stringify({ ok: false, command, ...cliError.toJSON() })}\n`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
err(`\nerror: ${cliError.message}\n`);
|
|
22
|
+
if (cliError.hint)
|
|
23
|
+
err(`hint: ${cliError.hint}\n`);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAiCA,MAAM,UAAU,cAAc,CAAC,IAAqB;IAClD,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5E,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAE5E,OAAO;QACL,QAAQ,CAAC,IAAI;YACX,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QACnB,CAAC;QAED,MAAM,CAAC,OAAO,EAAE,MAAM;YACpB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC;gBAClE,OAAO;YACT,CAAC;YACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK;gBAAE,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,QAAQ;YACpB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;gBACzE,OAAO;YACT,CAAC;YACD,GAAG,CAAC,YAAY,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;YACtC,IAAI,QAAQ,CAAC,IAAI;gBAAE,GAAG,CAAC,UAAU,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;QACtD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/verify.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,UAAU,GAAG,aAAa,CAAC;AAE7D,wBAAsB,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAaxF"}
|
package/dist/verify.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Does this key actually work?"
|
|
3
|
+
*
|
|
4
|
+
* `GET /v1/wallet` is the cheapest authenticated call in the API — no capability
|
|
5
|
+
* lookup, no run, no money moved — which makes it the right probe. Setup that
|
|
6
|
+
* ends with "here is a key, good luck" is setup that fails silently on someone
|
|
7
|
+
* else's machine; issue #9's criterion is a *working* key, so the CLI checks.
|
|
8
|
+
*/
|
|
9
|
+
import { isCliError } from "./errors.js";
|
|
10
|
+
export async function verifyKey(client, apiKey) {
|
|
11
|
+
let res;
|
|
12
|
+
try {
|
|
13
|
+
res = await client.send("GET", "/wallet", { apiKey });
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
if (isCliError(err) && err.code === "api_unreachable")
|
|
17
|
+
return "unreachable";
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
if (res.ok)
|
|
21
|
+
return "ok";
|
|
22
|
+
if (res.status === 401 || res.status === 403)
|
|
23
|
+
return "rejected";
|
|
24
|
+
// Anything else (5xx, a proxy's 502 HTML) says nothing about the key.
|
|
25
|
+
return "unreachable";
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAiB,EAAE,MAAc;IAC/D,IAAI,GAAG,CAAC;IACR,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,iBAAiB;YAAE,OAAO,aAAa,CAAC;QAC5E,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,IAAI,GAAG,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACxB,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,UAAU,CAAC;IAChE,sEAAsE;IACtE,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "scrollport",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "scrollport CLI \u2014 provision an agent's key against one prepaid wallet.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"scrollport": "./dist/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -b",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"lint": "echo \"(no linter configured yet)\""
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@scrollport/shared": "workspace:*",
|
|
28
|
+
"@types/node": "^22.10.2",
|
|
29
|
+
"vitest": "^2.1.8"
|
|
30
|
+
}
|
|
31
|
+
}
|