diffusr 0.0.0-stage → 0.2.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +169 -2
  3. package/dist/cli/account.d.ts +19 -0
  4. package/dist/cli/account.js +250 -0
  5. package/dist/cli/account.js.map +1 -0
  6. package/dist/cli/args.d.ts +28 -0
  7. package/dist/cli/args.js +204 -0
  8. package/dist/cli/args.js.map +1 -0
  9. package/dist/cli/format.d.ts +10 -0
  10. package/dist/cli/format.js +80 -0
  11. package/dist/cli/format.js.map +1 -0
  12. package/dist/cli/io.d.ts +32 -0
  13. package/dist/cli/io.js +56 -0
  14. package/dist/cli/io.js.map +1 -0
  15. package/dist/cli/main.d.ts +3 -0
  16. package/dist/cli/main.js +176 -0
  17. package/dist/cli/main.js.map +1 -0
  18. package/dist/cli/ops.d.ts +22 -0
  19. package/dist/cli/ops.js +367 -0
  20. package/dist/cli/ops.js.map +1 -0
  21. package/dist/cli/spec.d.ts +37 -0
  22. package/dist/cli/spec.js +117 -0
  23. package/dist/cli/spec.js.map +1 -0
  24. package/dist/cli/spec.json +4207 -0
  25. package/dist/cli/test-helpers.d.ts +32 -0
  26. package/dist/cli/test-helpers.js +70 -0
  27. package/dist/cli/test-helpers.js.map +1 -0
  28. package/dist/cli.d.ts +2 -0
  29. package/dist/cli.js +9 -0
  30. package/dist/cli.js.map +1 -0
  31. package/dist/client.d.ts +116 -0
  32. package/dist/client.js +281 -0
  33. package/dist/client.js.map +1 -0
  34. package/dist/config.d.ts +30 -0
  35. package/dist/config.js +71 -0
  36. package/dist/config.js.map +1 -0
  37. package/dist/errors.d.ts +21 -0
  38. package/dist/errors.js +23 -0
  39. package/dist/errors.js.map +1 -0
  40. package/dist/index.d.ts +8 -0
  41. package/dist/index.js +6 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/types.d.ts +208 -0
  44. package/dist/types.js +5 -0
  45. package/dist/types.js.map +1 -0
  46. package/dist/verify.d.ts +11 -0
  47. package/dist/verify.js +43 -0
  48. package/dist/verify.js.map +1 -0
  49. package/package.json +56 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 diffusr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,170 @@
1
- # Temporary Holding Version
1
+ # diffusr
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The diffusr API client for Node 18+. Make videos, images and music from code.
4
+ No dependencies. Bodies and answers are the API's own snake_case JSON.
5
+
6
+ ```sh
7
+ npm install diffusr
8
+ ```
9
+
10
+ ## Quickstart
11
+
12
+ Use a **test key** (`dfsr_test_…`) while you build: prices are quoted exactly,
13
+ nothing is charged, no model runs, and the result is a placeholder file a few
14
+ seconds later. Swap in a live key (`dfsr_live_…`) when you are ready to spend.
15
+ Mint keys on the Developers page in the app.
16
+
17
+ ```ts
18
+ import { Diffusr } from "diffusr";
19
+
20
+ const diffusr = new Diffusr(); // reads DIFFUSR_KEY, else the key `npx diffusr login` saved
21
+
22
+ // 1. Ask the price. Free: nothing is made, nothing is spent.
23
+ const quote = await diffusr.makeVideo({
24
+ prompt: "A can of sparkling water on a wet street, slow push-in, rain",
25
+ duration_sec: 5,
26
+ dry_run: true,
27
+ });
28
+ console.log(quote.price); // { credits: 63, usd: "0.6300", ... }
29
+
30
+ // 2. Make it. An Idempotency-Key is added for you and reused on retries,
31
+ // so a dropped connection never pays twice.
32
+ const job = await diffusr.makeVideo({
33
+ prompt: "A can of sparkling water on a wet street, slow push-in, rain",
34
+ duration_sec: 5,
35
+ });
36
+
37
+ // 3. Wait for it (polls with backoff; throws WAIT_TIMEOUT if it takes too long).
38
+ const result = await diffusr.waitFor(job.id, { timeoutMs: 10 * 60_000 });
39
+ if (result.status === "SUCCEEDED") console.log(result.output?.url);
40
+ else console.error(result.status, result.error);
41
+ console.log(result.charge); // { quoted_credits, charged_credits, final }
42
+ ```
43
+
44
+ ### Callbacks instead of polling
45
+
46
+ Pass `callback_url` (https, public) and we POST one signed event when the job
47
+ ends. Verify it with your signing secret (`await diffusr.getCallbackSecret()`):
48
+
49
+ ```ts
50
+ import { Diffusr } from "diffusr";
51
+
52
+ // Express: use the RAW body, not the parsed one.
53
+ app.post("/diffusr", express.text({ type: "*/*" }), (req, res) => {
54
+ if (!Diffusr.verifyCallback(req.body, req.headers, process.env.DIFFUSR_WHSEC!)) {
55
+ return res.sendStatus(400);
56
+ }
57
+ const event = JSON.parse(req.body); // { id, type: "result.finished", data: <result> }
58
+ res.sendStatus(200); // any 2xx; drop repeats of event.id
59
+ });
60
+ ```
61
+
62
+ `verifyCallback` implements [Standard Webhooks](https://www.standardwebhooks.com):
63
+ constant-time compare, two signatures after a secret rotation, a 5-minute
64
+ timestamp window, `whsec_` prefix handled.
65
+
66
+ ## Command line
67
+
68
+ The package also installs a `diffusr` command. No install needed:
69
+
70
+ ```sh
71
+ npx diffusr login # shows a code, opens your browser, saves a key
72
+ npx diffusr make_image "a mug on a sunlit table"
73
+ npx diffusr whoami # who you are, and your balance
74
+ npx diffusr help # every command
75
+ npx diffusr make_video --help # every flag of one command
76
+ ```
77
+
78
+ Anything that costs credits shows the price first and asks `Make it? [y/N]`.
79
+ It never spends without a yes. A local file works wherever a link is
80
+ expected (`--image-urls ./mug.jpg`): it is uploaded first.
81
+
82
+ For scripts and agents:
83
+
84
+ ```sh
85
+ diffusr price make_video "a can of sparkling water" --json # free: just the price
86
+ diffusr make_video "a can of sparkling water" --yes --json # spend, wait, print the result
87
+ ```
88
+
89
+ - `--json` prints only the JSON answer on stdout. Errors go to stderr.
90
+ - `--yes` allows spending. Without it, and with no terminal, the command
91
+ exits with code `2` and makes nothing.
92
+ - `--no-wait` starts the job and prints its id. Check it with `diffusr get_result <id>`.
93
+ - `diffusr logout` revokes the saved key and deletes the file.
94
+
95
+ The commands come from the API's own description, so a new API tool shows up
96
+ by itself.
97
+
98
+ **Where the key is saved.** `~/.config/diffusr/config.json` (or
99
+ `$XDG_CONFIG_HOME/diffusr/config.json`; on Windows `%APPDATA%\diffusr\config.json`).
100
+ Only you can read it (mode 0600). The `Diffusr` class and the Python package
101
+ read the same file.
102
+
103
+ **Which key wins.** The `--key` flag or the constructor argument, then the
104
+ `DIFFUSR_KEY` variable, then the saved file. The API address: `--base-url` or
105
+ the `baseUrl` option, then `DIFFUSR_BASE_URL`, then the saved file.
106
+
107
+ ## Methods
108
+
109
+ | Method | REST |
110
+ |---|---|
111
+ | `makeVideo`, `makeImage`, `editImage`, `recast`, `makeMusic`, `creatorVideo`, `runTemplate` `(body, { idempotencyKey? })` | `POST /{tool}` |
112
+ | `getResult(id)`, `listResults({ limit? })`, `cancel(id)` (stops queued work; a step already generating may finish and be charged: check `result.charge`) | `GET /results/{id}`, `GET /results`, `POST /results/{id}/cancel` |
113
+ | `waitFor(id, { timeoutMs?, intervalMs?, onPoll? })` | polls `GET /results/{id}` |
114
+ | `uploadFile(pathOrBytesOrBlob, { contentType? })`, `uploadFromUrl(url)` | `POST /uploads` + signed `PUT` |
115
+ | `listModels({ kind? })`, `listTemplates()` | `GET /models`, `GET /templates` |
116
+ | `listCallbacks({ limit?, cursor? })`, `retryCallback(eventId)`, `getCallbackSecret()`, `rotateCallbackSecret()` | `/callbacks…` |
117
+ | `Diffusr.verifyCallback(rawBody, headers, secret)` | |
118
+
119
+ `dry_run: true` on any make call answers with the price only.
120
+
121
+ `runTemplate` takes one flat body: `{ template: "<id from listTemplates()>", mode?, prompt?,
122
+ pictures?, image_urls?, product_image_url?, script?, place?, people?, setup?, resolution?, dry_run? }`.
123
+ `listTemplates()` says which fields each template takes.
124
+
125
+ ```ts
126
+ await diffusr.runTemplate({ template: "tpl-ugc-talking-head", script: "Hi!", people: [{ name: "Mia", image_url: "https://…" }], dry_run: true });
127
+ ```
128
+
129
+ ## Retries and errors
130
+
131
+ - Every request times out after 60 s (`new Diffusr(key, { timeoutMs })`, or
132
+ `{ timeoutMs, signal }` per call) with a `TIMEOUT` error. Your own `signal`
133
+ aborts without a retry.
134
+ - `GET`s (and so `waitFor`) retry on 429, 500, 502, 503, 504, network errors
135
+ and timeouts with backoff, honouring `Retry-After` (waits over 30 s are not
136
+ slept: the error is thrown).
137
+ - Make calls retry on 429, 503, network errors and timeouts only, **with the
138
+ same Idempotency-Key**.
139
+ Pass your own with `{ idempotencyKey }` to make a retry safe across restarts.
140
+ - Every failure is a `DiffusrError`:
141
+
142
+ ```ts
143
+ try {
144
+ await diffusr.makeVideo({ prompt: "…" });
145
+ } catch (e) {
146
+ if (e instanceof DiffusrError) {
147
+ console.log(e.status, e.code, e.message, e.requestId, e.retryAfter);
148
+ // e.body has the extras: issues, field, budget…
149
+ }
150
+ }
151
+ ```
152
+
153
+ Codes are the API's (`RATE_LIMITED`, `BUDGET_EXCEEDED`, `INSUFFICIENT_CREDITS`…).
154
+ The SDK adds `NETWORK_ERROR`, `TIMEOUT`, `WAIT_TIMEOUT`, `UPLOAD_FAILED`,
155
+ `CONTENT_TYPE_REQUIRED` and `MISSING_API_KEY` (status 0 or the PUT's status).
156
+ Handle codes you don't know.
157
+
158
+ ## Publishing
159
+
160
+ ESM only (Node 18+). In the monorepo `package.json` points at `src` so the
161
+ workspace can use it untouched; `publishConfig` swaps in `dist` with types.
162
+ Publish with **`pnpm publish` from `packages/sdk`** (it applies `publishConfig`
163
+ and builds first); `npm publish` would ship the `src` entry points. Check a
164
+ pack first with `pnpm pack:check`.
165
+
166
+ ## Docs
167
+
168
+ Full API reference, prices and agent guides: https://diffusr.ai/docs
169
+
170
+ MIT licensed.
@@ -0,0 +1,19 @@
1
+ import { Diffusr } from "../client.js";
2
+ import type { SavedConfig } from "../config.js";
3
+ import type { FlagDef, ParsedArgs } from "./args.js";
4
+ import type { Io } from "./io.js";
5
+ export declare const LOGIN_FLAGS: Map<string, FlagDef>;
6
+ export declare const LOGOUT_FLAGS: Map<string, FlagDef>;
7
+ export declare const WHOAMI_FLAGS: Map<string, FlagDef>;
8
+ export interface Auth {
9
+ key: string | undefined;
10
+ source: "argument" | "env" | "file" | undefined;
11
+ config: SavedConfig | undefined;
12
+ baseUrl: string;
13
+ }
14
+ /** The key (argument, DIFFUSR_KEY, saved file) and the base URL that goes with it. */
15
+ export declare function resolveAuth(io: Io, args: ParsedArgs): Auth;
16
+ export declare function makeClient(io: Io, auth: Auth): Diffusr;
17
+ export declare function login(io: Io, args: ParsedArgs): Promise<number>;
18
+ export declare function whoami(io: Io, args: ParsedArgs): Promise<number>;
19
+ export declare function logout(io: Io, args: ParsedArgs): Promise<number>;
@@ -0,0 +1,250 @@
1
+ import { DEFAULT_BASE_URL, Diffusr } from "../client.js";
2
+ import { configPath, deleteConfig, readConfig, resolveKey, writeConfig } from "../config.js";
3
+ import { DiffusrError } from "../errors.js";
4
+ import { flagBool, flagStr } from "./args.js";
5
+ import { credits, formatMe } from "./format.js";
6
+ import { CliError, shouldOpenBrowser } from "./io.js";
7
+ export const LOGIN_FLAGS = new Map([
8
+ ["test", true],
9
+ ["name", false],
10
+ ["force", true],
11
+ ["json", true],
12
+ ["help", true],
13
+ ["version", true],
14
+ ["yes", true],
15
+ ["base_url", false],
16
+ ["key", false],
17
+ ].map(([name, boolean]) => [name, { name: name, boolean: boolean }]));
18
+ export const LOGOUT_FLAGS = new Map([
19
+ ["revoke_env_key", true],
20
+ ["json", true],
21
+ ["help", true],
22
+ ["version", true],
23
+ ["yes", true],
24
+ ["base_url", false],
25
+ ["key", false],
26
+ ].map(([name, boolean]) => [name, { name: name, boolean: boolean }]));
27
+ export const WHOAMI_FLAGS = LOGOUT_FLAGS;
28
+ const MISSING_KEY = "Pass an API key, set DIFFUSR_KEY, or run `npx diffusr login`.";
29
+ const trim = (u) => u.replace(/\/+$/, "");
30
+ /** The key (argument, DIFFUSR_KEY, saved file) and the base URL that goes with it. */
31
+ export function resolveAuth(io, args) {
32
+ const found = resolveKey(flagStr(args, "key"), io.env, io.platform);
33
+ const fileBase = found?.source === "file" ? found.config?.base_url : undefined;
34
+ const baseUrl = trim(flagStr(args, "base_url") || io.env.DIFFUSR_BASE_URL || fileBase || DEFAULT_BASE_URL);
35
+ return { key: found?.key, source: found?.source, config: found?.config, baseUrl };
36
+ }
37
+ export function makeClient(io, auth) {
38
+ if (!auth.key)
39
+ throw new DiffusrError({ status: 0, code: "MISSING_API_KEY", message: MISSING_KEY });
40
+ return new Diffusr(auth.key, { baseUrl: auth.baseUrl, fetch: io.fetch });
41
+ }
42
+ function describeSource(io, auth) {
43
+ if (auth.source === "argument")
44
+ return "the --key flag";
45
+ if (auth.source === "env")
46
+ return "DIFFUSR_KEY";
47
+ return `the saved file ${configPath(io.env, io.platform)}`;
48
+ }
49
+ // ——— plain JSON calls with no key (login) ———
50
+ async function postJson(io, url, body) {
51
+ let res;
52
+ try {
53
+ res = await io.fetch(url, {
54
+ method: "POST",
55
+ headers: { "Content-Type": "application/json", Accept: "application/json", "User-Agent": "diffusr-cli" },
56
+ body: JSON.stringify(body),
57
+ signal: AbortSignal.timeout(20_000),
58
+ });
59
+ }
60
+ catch (cause) {
61
+ throw new DiffusrError({ status: 0, code: "NETWORK_ERROR", message: `Could not reach diffusr: ${cause.message}` });
62
+ }
63
+ const text = await res.text().catch(() => "");
64
+ let parsed = {};
65
+ try {
66
+ const p = JSON.parse(text);
67
+ if (p && typeof p === "object")
68
+ parsed = p;
69
+ }
70
+ catch {
71
+ /* not JSON */
72
+ }
73
+ if (!text || Object.keys(parsed).length === 0)
74
+ parsed = { error: text.slice(0, 300) || `HTTP ${res.status}` };
75
+ return { status: res.status, body: parsed };
76
+ }
77
+ function toDiffusrError(status, body) {
78
+ return new DiffusrError({
79
+ status,
80
+ code: typeof body.code === "string" ? body.code : `HTTP_${status}`,
81
+ message: typeof body.error === "string" ? body.error : `HTTP ${status}`,
82
+ requestId: typeof body.request_id === "string" ? body.request_id : undefined,
83
+ retryAfter: typeof body.retry_after_seconds === "number" ? body.retry_after_seconds : undefined,
84
+ body,
85
+ });
86
+ }
87
+ // ——— login ———
88
+ function limitWords(a) {
89
+ if (typeof a.monthly_limit_credits === "number")
90
+ return `limit ${credits(a.monthly_limit_credits)} a month`;
91
+ if (typeof a.daily_limit_credits === "number")
92
+ return `limit ${credits(a.daily_limit_credits)} a day`;
93
+ return "no limit";
94
+ }
95
+ export async function login(io, args) {
96
+ const json = flagBool(args, "json");
97
+ const say = (l) => (json ? io.err(l) : io.out(l));
98
+ const existing = readConfig(io.env, io.platform);
99
+ if (existing && !flagBool(args, "force")) {
100
+ io.err(`Already signed in as ${existing.email ?? "this account"}${existing.key_name ? ` (${existing.mode ?? "live"} key "${existing.key_name}")` : ""}. Run diffusr logout first, or diffusr login --force.`);
101
+ return 1;
102
+ }
103
+ const base = trim(flagStr(args, "base_url") || io.env.DIFFUSR_BASE_URL || DEFAULT_BASE_URL);
104
+ const mode = flagBool(args, "test") ? "test" : "live";
105
+ const started = await postJson(io, `${base}/cli/logins`, { device_name: flagStr(args, "name") || io.hostname, mode });
106
+ if (started.status < 200 || started.status >= 300)
107
+ throw toDiffusrError(started.status, started.body);
108
+ const s = started.body;
109
+ const loginId = String(s.login_id ?? "");
110
+ const pollToken = String(s.poll_token ?? "");
111
+ const code = String(s.code ?? "");
112
+ const verifyUrl = String(s.verify_url ?? "");
113
+ if (!loginId || !pollToken)
114
+ throw new CliError("diffusr sent back an answer this version does not understand. Update with: npm i -g diffusr");
115
+ say(`Your code: ${code.replace(/^(\d{3})(\d+)$/, "$1 $2")}`);
116
+ say(`Open ${verifyUrl}`);
117
+ say("and press Yes, connect.");
118
+ say("");
119
+ say("Waiting…");
120
+ if (shouldOpenBrowser(io.env, io.platform) && verifyUrl)
121
+ io.openUrl(verifyUrl);
122
+ const expiresAt = io.now() + (typeof s.expires_in === "number" ? s.expires_in : 600) * 1000;
123
+ const intervalMs = Math.max(1, typeof s.interval === "number" ? s.interval : 3) * 1000;
124
+ while (io.now() < expiresAt) {
125
+ await io.sleep(intervalMs);
126
+ const r = await postJson(io, `${base}/cli/logins/${encodeURIComponent(loginId)}/token`, { poll_token: pollToken });
127
+ if (r.status === 429) {
128
+ const wait = typeof r.body.retry_after_seconds === "number" ? r.body.retry_after_seconds * 1000 : intervalMs;
129
+ await io.sleep(wait);
130
+ continue;
131
+ }
132
+ if (r.status === 404)
133
+ throw new CliError("This login was not found. Run diffusr login again.");
134
+ if (r.status >= 500)
135
+ continue;
136
+ if (r.status >= 400)
137
+ throw toDiffusrError(r.status, r.body);
138
+ const a = r.body;
139
+ switch (a.status) {
140
+ case "approved": {
141
+ const cfg = {
142
+ key: String(a.key),
143
+ key_id: String(a.key_id ?? ""),
144
+ key_name: String(a.key_name ?? ""),
145
+ mode: a.mode === "test" ? "test" : "live",
146
+ email: String(a.email ?? ""),
147
+ ...(base !== DEFAULT_BASE_URL ? { base_url: base } : {}),
148
+ saved_at: new Date(io.now()).toISOString(),
149
+ };
150
+ const file = writeConfig(cfg, io.env, io.platform);
151
+ // --force replaced a saved key: revoke it so no live key is left behind.
152
+ if (existing && existing.key !== cfg.key)
153
+ await revokeQuietly(io, existing);
154
+ if (json) {
155
+ io.out(JSON.stringify({ connected: true, email: cfg.email, key_id: cfg.key_id, key_name: cfg.key_name, mode: cfg.mode, config_path: file }, null, 2));
156
+ }
157
+ else {
158
+ io.out(`✓ Connected as ${cfg.email} (${cfg.mode} key "${cfg.key_name}", ${limitWords(a)})`);
159
+ io.out("");
160
+ io.out('Try: diffusr make_image "a mug on a sunlit table"');
161
+ }
162
+ if (io.env.DIFFUSR_KEY)
163
+ io.err("Note: DIFFUSR_KEY is set in this shell, and it wins over the saved key.");
164
+ return 0;
165
+ }
166
+ case "denied":
167
+ throw new CliError("Cancelled in the browser.");
168
+ case "expired":
169
+ throw new CliError("The code expired. Run diffusr login again.");
170
+ case "failed":
171
+ throw new CliError(typeof a.error === "string" ? a.error : "The login failed. Run diffusr login again.");
172
+ default:
173
+ break; // pending
174
+ }
175
+ }
176
+ throw new CliError("The code expired. Run diffusr login again.");
177
+ }
178
+ /** Best effort: revoke a key we no longer keep. A failure only warns. */
179
+ async function revokeQuietly(io, old) {
180
+ try {
181
+ await new Diffusr(old.key, { baseUrl: trim(old.base_url || DEFAULT_BASE_URL), fetch: io.fetch, maxRetries: 1 }).call("POST", "/cli/logout", { body: {} });
182
+ }
183
+ catch (e) {
184
+ if (e instanceof DiffusrError && e.status === 401)
185
+ return; // already gone
186
+ io.err(`Note: the old key "${old.key_name ?? "CLI"}" could not be revoked. Revoke it on the Developers page.`);
187
+ }
188
+ }
189
+ // ——— whoami ———
190
+ export async function whoami(io, args) {
191
+ const auth = resolveAuth(io, args);
192
+ const client = makeClient(io, auth);
193
+ const me = await client.call("GET", "/me");
194
+ if (flagBool(args, "json")) {
195
+ io.out(JSON.stringify(me, null, 2));
196
+ return 0;
197
+ }
198
+ for (const l of formatMe(me))
199
+ io.out(l);
200
+ io.out(`Key from ${describeSource(io, auth)}`);
201
+ return 0;
202
+ }
203
+ // ——— logout ———
204
+ export async function logout(io, args) {
205
+ const json = flagBool(args, "json");
206
+ const auth = resolveAuth(io, args);
207
+ const saved = readConfig(io.env, io.platform);
208
+ const revokeEnv = flagBool(args, "revoke_env_key");
209
+ const envSet = Boolean(io.env.DIFFUSR_KEY);
210
+ let key;
211
+ let name;
212
+ let base = auth.baseUrl;
213
+ if (saved) {
214
+ key = saved.key;
215
+ name = saved.key_name;
216
+ base = trim(flagStr(args, "base_url") || io.env.DIFFUSR_BASE_URL || saved.base_url || DEFAULT_BASE_URL);
217
+ }
218
+ else if (revokeEnv && auth.key) {
219
+ key = auth.key;
220
+ }
221
+ if (!key) {
222
+ const msg = auth.key ? `Nothing saved to sign out of. The key from ${describeSource(io, auth)} was left alone (add --revoke-env-key to revoke it).` : "You are not signed in. Nothing is saved.";
223
+ if (json)
224
+ io.out(JSON.stringify({ revoked: false, message: msg }));
225
+ else
226
+ io.out(msg);
227
+ return 0;
228
+ }
229
+ try {
230
+ await new Diffusr(key, { baseUrl: base, fetch: io.fetch }).call("POST", "/cli/logout", { body: {} });
231
+ }
232
+ catch (e) {
233
+ // A 401 means the key is already gone: that is what we wanted.
234
+ if (!(e instanceof DiffusrError && e.status === 401))
235
+ throw e;
236
+ }
237
+ if (saved)
238
+ deleteConfig(io.env, io.platform);
239
+ const label = name ? `The key "${name}"` : "The key";
240
+ if (json)
241
+ io.out(JSON.stringify({ revoked: true, key_name: name ?? null }));
242
+ else
243
+ io.out(`Signed out. ${label} is revoked.`);
244
+ if (envSet && io.env.DIFFUSR_KEY !== key)
245
+ io.err("Note: DIFFUSR_KEY is still set in this shell.");
246
+ else if (envSet)
247
+ io.err("Note: DIFFUSR_KEY is still set in this shell, but that key no longer works.");
248
+ return 0;
249
+ }
250
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/cli/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAg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,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IACvG,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,+DAA+D;QAC/D,IAAI,CAAC,CAAC,CAAC,YAAY,YAAY,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC;YAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,KAAK;QAAE,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IACrD,IAAI,IAAI;QAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;;QACvE,EAAE,CAAC,GAAG,CAAC,eAAe,KAAK,cAAc,CAAC,CAAC;IAChD,IAAI,MAAM,IAAI,EAAE,CAAC,GAAG,CAAC,WAAW,KAAK,GAAG;QAAE,EAAE,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;SAC7F,IAAI,MAAM;QAAE,EAAE,CAAC,GAAG,CAAC,6EAA6E,CAAC,CAAC;IACvG,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Json } from "./spec.js";
2
+ export declare function schemaType(s: Json): string | undefined;
3
+ export declare const flagName: (prop: string) => string;
4
+ /** "string", "integer", "a|b", "string[]", "json". */
5
+ export declare function describeType(s: Json): string;
6
+ export declare function readAt(path: string, flag: string): string;
7
+ /**
8
+ * Turn the raw values of one flag into the JSON value its schema wants.
9
+ * `raws` has one entry per time the flag was given.
10
+ */
11
+ export declare function coerceFlag(s: Json, raws: string[], flag: string): unknown;
12
+ export interface FlagDef {
13
+ /** Property name, snake_case. */
14
+ name: string;
15
+ boolean: boolean;
16
+ }
17
+ export interface ParsedArgs {
18
+ positionals: string[];
19
+ /** Flag (snake_case) -> every value given. Booleans hold "true"/"false". */
20
+ flags: Map<string, string[]>;
21
+ }
22
+ /**
23
+ * Split argv into positionals and flags. `known` says which flags exist and
24
+ * whether they take a value; anything else is an error.
25
+ */
26
+ export declare function parseArgs(argv: string[], known: Map<string, FlagDef>, helpHint: string): ParsedArgs;
27
+ export declare function flagBool(p: ParsedArgs, name: string): boolean;
28
+ export declare function flagStr(p: ParsedArgs, name: string): string | undefined;