@tiny-fish/cli 0.1.6 → 0.1.7-next.62
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/commands/auth.js +10 -7
- package/dist/lib/auth.d.ts +1 -1
- package/dist/lib/auth.js +1 -1
- package/dist/lib/constants.d.ts +1 -0
- package/dist/lib/constants.js +15 -1
- package/package.json +4 -3
package/dist/commands/auth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
2
|
import * as readline from "readline";
|
|
3
|
-
import {
|
|
3
|
+
import { Option } from "commander";
|
|
4
|
+
import { clearConfig, getDashboardUrl, loadConfig, maskKey, saveConfig, validateKeyFormat, } from "../lib/auth.js";
|
|
4
5
|
import { err, errLine, out, outLine } from "../lib/output.js";
|
|
5
6
|
/**
|
|
6
7
|
* Read a key from stdin without echoing it to the terminal.
|
|
@@ -70,24 +71,26 @@ export function registerAuth(program) {
|
|
|
70
71
|
auth
|
|
71
72
|
.command("login")
|
|
72
73
|
.description("Open the API keys page and save your key interactively")
|
|
73
|
-
.
|
|
74
|
-
|
|
74
|
+
.addOption(new Option("--source <source>", "API keys page source attribution").default("cli").hideHelp())
|
|
75
|
+
.action(async (options) => {
|
|
76
|
+
const dashboardUrl = getDashboardUrl(options.source);
|
|
77
|
+
errLine(`Opening ${dashboardUrl} in your browser...`);
|
|
75
78
|
try {
|
|
76
79
|
// Use spawn with an explicit args array — no shell, no interpolation
|
|
77
80
|
let cmd;
|
|
78
81
|
let args;
|
|
79
82
|
if (process.platform === "darwin") {
|
|
80
83
|
cmd = "open";
|
|
81
|
-
args = [
|
|
84
|
+
args = [dashboardUrl];
|
|
82
85
|
}
|
|
83
86
|
else if (process.platform === "win32") {
|
|
84
87
|
// "start" treats the first quoted arg as a window title — empty string avoids it
|
|
85
88
|
cmd = "cmd";
|
|
86
|
-
args = ["/c", "start", "",
|
|
89
|
+
args = ["/c", "start", "", dashboardUrl];
|
|
87
90
|
}
|
|
88
91
|
else {
|
|
89
92
|
cmd = "xdg-open";
|
|
90
|
-
args = [
|
|
93
|
+
args = [dashboardUrl];
|
|
91
94
|
}
|
|
92
95
|
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
93
96
|
child.unref();
|
|
@@ -96,7 +99,7 @@ export function registerAuth(program) {
|
|
|
96
99
|
catch {
|
|
97
100
|
// headless — ignore
|
|
98
101
|
}
|
|
99
|
-
process.stderr.write(`If the browser didn't open, visit: ${
|
|
102
|
+
process.stderr.write(`If the browser didn't open, visit: ${dashboardUrl}\n\n`);
|
|
100
103
|
const key = await readKeyHidden("Paste your API key: ");
|
|
101
104
|
if (!key) {
|
|
102
105
|
err("API key cannot be empty");
|
package/dist/lib/auth.d.ts
CHANGED
package/dist/lib/auth.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as path from "path";
|
|
|
4
4
|
import { err } from "./output.js";
|
|
5
5
|
const KEY_PREFIXES = ["sk-tinyfish-", "sk-mino-"];
|
|
6
6
|
const MIN_KEY_LENGTH = 20;
|
|
7
|
-
export { DASHBOARD_URL } from "./constants.js";
|
|
7
|
+
export { DASHBOARD_URL, getDashboardUrl } from "./constants.js";
|
|
8
8
|
export function configDir() {
|
|
9
9
|
// os.homedir() is cross-platform; process.env.HOME is undefined on Windows
|
|
10
10
|
return path.join(os.homedir(), ".tinyfish");
|
package/dist/lib/constants.d.ts
CHANGED
package/dist/lib/constants.js
CHANGED
|
@@ -15,5 +15,19 @@ if (apiUrlOverride) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
export const BASE_URL = apiUrlOverride || "https://agent.tinyfish.ai";
|
|
18
|
+
const DEFAULT_DASHBOARD_SOURCE = "cli";
|
|
19
|
+
const DASHBOARD_SOURCE_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
20
|
+
function normalizeDashboardSource(source) {
|
|
21
|
+
const normalized = source?.trim().toLowerCase();
|
|
22
|
+
if (!normalized || !DASHBOARD_SOURCE_PATTERN.test(normalized)) {
|
|
23
|
+
return DEFAULT_DASHBOARD_SOURCE;
|
|
24
|
+
}
|
|
25
|
+
return normalized;
|
|
26
|
+
}
|
|
18
27
|
/** URL where users can create and manage API keys */
|
|
19
|
-
export
|
|
28
|
+
export function getDashboardUrl(source = DEFAULT_DASHBOARD_SOURCE) {
|
|
29
|
+
const url = new URL(`${BASE_URL}/api-keys`);
|
|
30
|
+
url.searchParams.set("source", normalizeDashboardSource(source));
|
|
31
|
+
return url.toString();
|
|
32
|
+
}
|
|
33
|
+
export const DASHBOARD_URL = getDashboardUrl();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiny-fish/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7-next.62",
|
|
4
4
|
"description": "TinyFish CLI — run web automations from your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -45,11 +45,12 @@
|
|
|
45
45
|
"eslint": "^10.1.0",
|
|
46
46
|
"prettier": "^3.0.0",
|
|
47
47
|
"typescript": "^5.0.0",
|
|
48
|
-
"vitest": "^
|
|
48
|
+
"vitest": "^4.1.0"
|
|
49
49
|
},
|
|
50
50
|
"overrides": {
|
|
51
|
+
"esbuild": "0.28.1",
|
|
51
52
|
"vite": "7.3.2",
|
|
52
|
-
"brace-expansion": "5.0.
|
|
53
|
+
"brace-expansion": "^5.0.6",
|
|
53
54
|
"postcss": "8.5.10"
|
|
54
55
|
},
|
|
55
56
|
"engines": {
|