@floomhq/floom 1.0.64 → 2.0.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/whoami.js DELETED
@@ -1,64 +0,0 @@
1
- import ora from "ora";
2
- import { readConfig, CONFIG_PATH, resolveApiUrl } from "./config.js";
3
- import { floomFetch } from "./lib/api.js";
4
- import { c, symbols } from "./ui.js";
5
- import { FloomError, friendlyHttp, friendlyNetwork } from "./errors.js";
6
- export async function whoami() {
7
- const cfg = await readConfig();
8
- if (!cfg) {
9
- throw new FloomError("Not signed in.", "Run `npx -y @floomhq/floom login` to sign in.");
10
- }
11
- const apiUrl = resolveApiUrl(cfg);
12
- const spinner = ora({ text: c.dim("Checking session..."), color: "yellow" }).start();
13
- let me;
14
- let count = 0;
15
- try {
16
- const res = await floomFetch(`${apiUrl}/api/me`, "check your account", {
17
- token: cfg.accessToken,
18
- checkOk: false,
19
- });
20
- if (!res.ok) {
21
- spinner.stop();
22
- throw friendlyHttp(res.status, "check your account");
23
- }
24
- me = (await res.json());
25
- }
26
- catch (err) {
27
- spinner.stop();
28
- if (err instanceof FloomError)
29
- throw err;
30
- throw friendlyNetwork(err);
31
- }
32
- // Best-effort: count published skills. Don't fail whoami if it errors.
33
- try {
34
- const res = await floomFetch(`${apiUrl}/api/skills/mine`, "count published skills", {
35
- token: cfg.accessToken,
36
- checkOk: false,
37
- });
38
- if (res.ok) {
39
- const data = (await res.json());
40
- if (typeof data.count === "number")
41
- count = data.count;
42
- else if (Array.isArray(data.items))
43
- count = data.items.length;
44
- }
45
- }
46
- catch {
47
- // ignore
48
- }
49
- spinner.stop();
50
- process.stdout.write(`\n${symbols.ok} ${c.bold(me.email ?? me.id)}\n`);
51
- process.stdout.write(` ${c.dim(`Token at ${tildify(CONFIG_PATH)}`)}\n`);
52
- if (count > 0) {
53
- process.stdout.write(` ${c.dim(`${count} skill${count === 1 ? "" : "s"} published`)}\n\n`);
54
- }
55
- else {
56
- process.stdout.write("\n");
57
- }
58
- }
59
- function tildify(p) {
60
- const home = process.env.HOME ?? "";
61
- if (home && p.startsWith(home))
62
- return "~" + p.slice(home.length);
63
- return p;
64
- }