filecafe 0.3.0 → 0.3.1
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/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as updateCachePath, d as normalizeBaseUrl, f as readConfig, l as configPath, m as writeConfig, n as fetchLatestVersion, o as updateUpdateCache, p as resolveSettings, r as readUpdateCache, s as VERSION, t as CHECK_INTERVAL_MS, u as deleteConfig } from "./update-cache
|
|
2
|
+
import { a as updateCachePath, d as normalizeBaseUrl, f as readConfig, l as configPath, m as writeConfig, n as fetchLatestVersion, o as updateUpdateCache, p as resolveSettings, r as readUpdateCache, s as VERSION, t as CHECK_INTERVAL_MS, u as deleteConfig } from "./update-cache--jPxzzep.js";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { homedir, hostname, tmpdir } from "node:os";
|
|
5
5
|
import { realpath, stat } from "node:fs/promises";
|
|
@@ -290,6 +290,73 @@ async function requireSession(context, globals, onNotice) {
|
|
|
290
290
|
}
|
|
291
291
|
};
|
|
292
292
|
}
|
|
293
|
+
// src/terminal.ts
|
|
294
|
+
/**
|
|
295
|
+
* Whether `stream` is a terminal that understands OSC 8 hyperlinks (link text that opens a
|
|
296
|
+
* different URL when clicked). Terminals that don't would print the escape codes as garbage,
|
|
297
|
+
* so this only says yes for ones known to support them. FORCE_HYPERLINK=1 or 0 overrides it.
|
|
298
|
+
*/
|
|
299
|
+
function supportsHyperlinks(stream, env) {
|
|
300
|
+
if (env.FORCE_HYPERLINK !== void 0) return env.FORCE_HYPERLINK !== "0";
|
|
301
|
+
if (!stream.isTTY || env.CI || env.TERM === "dumb") return false;
|
|
302
|
+
if (env.WT_SESSION || env.KITTY_WINDOW_ID || env.WEZTERM_PANE || env.KONSOLE_VERSION || env.DOMTERM) return true;
|
|
303
|
+
if (Number(env.VTE_VERSION) >= 5e3) return true;
|
|
304
|
+
return [
|
|
305
|
+
"iTerm.app",
|
|
306
|
+
"WezTerm",
|
|
307
|
+
"vscode",
|
|
308
|
+
"ghostty",
|
|
309
|
+
"Hyper",
|
|
310
|
+
"Tabby",
|
|
311
|
+
"rio"
|
|
312
|
+
].includes(env.TERM_PROGRAM ?? "");
|
|
313
|
+
}
|
|
314
|
+
/** `text` that opens `url` when clicked, for terminals where supportsHyperlinks() is true. */
|
|
315
|
+
function hyperlink(text, url) {
|
|
316
|
+
return `\u001B]8;;${url}\u0007${text}\u001B]8;;\u0007`;
|
|
317
|
+
}
|
|
318
|
+
const FRAMES = [
|
|
319
|
+
"⠋",
|
|
320
|
+
"⠙",
|
|
321
|
+
"⠹",
|
|
322
|
+
"⠸",
|
|
323
|
+
"⠼",
|
|
324
|
+
"⠴",
|
|
325
|
+
"⠦",
|
|
326
|
+
"⠧",
|
|
327
|
+
"⠇",
|
|
328
|
+
"⠏"
|
|
329
|
+
];
|
|
330
|
+
const ASCII_FRAMES = [
|
|
331
|
+
"-",
|
|
332
|
+
"\\",
|
|
333
|
+
"|",
|
|
334
|
+
"/"
|
|
335
|
+
];
|
|
336
|
+
/**
|
|
337
|
+
* Show `text` with a spinner in front of it on a terminal, erased by stop(). Anywhere else
|
|
338
|
+
* (a log file, CI, an AI agent) the text is written once as a plain line instead.
|
|
339
|
+
*/
|
|
340
|
+
function startSpinner(stream, text, env, platform) {
|
|
341
|
+
if (!stream.isTTY || env.CI || env.TERM === "dumb") {
|
|
342
|
+
stream.write(`${text}\n`);
|
|
343
|
+
return { stop: () => {} };
|
|
344
|
+
}
|
|
345
|
+
const frames = platform === "win32" && !env.WT_SESSION ? ASCII_FRAMES : FRAMES;
|
|
346
|
+
let frame = 0;
|
|
347
|
+
const draw = () => stream.write(`\r${frames[frame++ % frames.length]} ${text}`);
|
|
348
|
+
draw();
|
|
349
|
+
const timer = setInterval(draw, 80);
|
|
350
|
+
timer.unref();
|
|
351
|
+
let stopped = false;
|
|
352
|
+
return { stop: () => {
|
|
353
|
+
if (!stopped) {
|
|
354
|
+
stopped = true;
|
|
355
|
+
clearInterval(timer);
|
|
356
|
+
stream.write("\r\x1B[2K");
|
|
357
|
+
}
|
|
358
|
+
} };
|
|
359
|
+
}
|
|
293
360
|
// src/commands/login.ts
|
|
294
361
|
async function readAll(input) {
|
|
295
362
|
let text = "";
|
|
@@ -323,21 +390,26 @@ async function tokenFromBrowser(context, baseUrl) {
|
|
|
323
390
|
const client = clientFor(context, baseUrl, void 0, (message) => context.stderr.write(`${message}\n`));
|
|
324
391
|
const login = await client.request("POST", "/api/v1/cli/logins", { name: hostname() });
|
|
325
392
|
if (!isStartedLogin(login)) throw new CliError(`Unexpected response from ${baseUrl} when starting the login. Check the --url option / FILECAFE_URL.`);
|
|
326
|
-
context.stderr.
|
|
327
|
-
`);
|
|
393
|
+
const link = supportsHyperlinks(context.stderr, context.env) ? hyperlink(login.verification_uri, login.verification_uri_complete) : login.verification_uri;
|
|
394
|
+
context.stderr.write(`Your one-time code: ${login.user_code}\n\nOpening your browser to approve this login. Check that the code there matches.\nIf it does not open, visit ${link} and enter the code.\n\n`);
|
|
328
395
|
context.openBrowser(login.verification_uri_complete);
|
|
396
|
+
const spinner = startSpinner(context.stderr, "Waiting for approval...", context.env, context.platform);
|
|
329
397
|
const intervalMs = Math.max(login.interval, 1) * 1e3;
|
|
330
398
|
const deadline = context.now() + login.expires_in * 1e3;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
399
|
+
try {
|
|
400
|
+
while (context.now() < deadline) {
|
|
401
|
+
await context.sleep(Math.min(intervalMs, deadline - context.now()));
|
|
402
|
+
const result = await pollLogin(client, login.device_code);
|
|
403
|
+
switch (result.status) {
|
|
404
|
+
case "approved": return result.token;
|
|
405
|
+
case "denied": throw new CliError("Login was cancelled in the browser.");
|
|
406
|
+
case "expired": throw new CliError(EXPIRED_MESSAGE);
|
|
407
|
+
}
|
|
338
408
|
}
|
|
409
|
+
throw new CliError(EXPIRED_MESSAGE);
|
|
410
|
+
} finally {
|
|
411
|
+
spinner.stop();
|
|
339
412
|
}
|
|
340
|
-
throw new CliError(EXPIRED_MESSAGE);
|
|
341
413
|
}
|
|
342
414
|
async function loginCommand(options, globals, context) {
|
|
343
415
|
if (options.token !== void 0 && options.withToken) throw new CliError("Use either --token <token> or --with-token, not both.");
|
|
@@ -368,6 +440,7 @@ async function loginCommand(options, globals, context) {
|
|
|
368
440
|
context.stdout.write(`Logged in as ${me.name} (${me.email})\n`);
|
|
369
441
|
context.stderr.write(`Saved credentials for ${baseUrl} to ${configPath(context)}\n`);
|
|
370
442
|
if (context.env.FILECAFE_TOKEN?.trim()) context.stderr.write("Note: FILECAFE_TOKEN is set in your environment and takes precedence over the saved login.\n");
|
|
443
|
+
context.stderr.write("\nRun \"filecafe upload <file>\" to share a file.\n");
|
|
371
444
|
return 0;
|
|
372
445
|
}
|
|
373
446
|
// src/commands/logout.ts
|
|
@@ -108,7 +108,7 @@ async function resolveSettings(environment, urlOption) {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
// src/version.ts
|
|
111
|
-
const VERSION = "0.3.
|
|
111
|
+
const VERSION = "0.3.1";
|
|
112
112
|
// src/update-cache.ts
|
|
113
113
|
const REGISTRY_URL = "https://registry.npmjs.org/filecafe/latest";
|
|
114
114
|
/** Ask npm at most once a day. */
|
package/dist/update-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as refreshUpdateCache, s as VERSION } from "./update-cache
|
|
1
|
+
import { i as refreshUpdateCache, s as VERSION } from "./update-cache--jPxzzep.js";
|
|
2
2
|
// src/update-worker.ts
|
|
3
3
|
/**
|
|
4
4
|
* Spawned detached by the CLI to refresh the update cache, so no command ever waits on npm.
|