@artifactshare/cli 0.4.0 → 0.4.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/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { appendFile, chmod, lstat, mkdir, mkdtemp, readFile, readdir, realpath,
|
|
|
3
3
|
import { cli, define, lazy } from "gunshi";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
6
|
-
import { setTimeout } from "node:timers/promises";
|
|
6
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { createReadStream } from "node:fs";
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
@@ -1234,6 +1234,104 @@ function spawnFile(command, args, input) {
|
|
|
1234
1234
|
else child.stdin.end();
|
|
1235
1235
|
});
|
|
1236
1236
|
}
|
|
1237
|
+
function browserOpenSkipReason() {
|
|
1238
|
+
if (process.env.CI === "true") return "ci";
|
|
1239
|
+
if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) return "headless_linux";
|
|
1240
|
+
return null;
|
|
1241
|
+
}
|
|
1242
|
+
function resolveBrowserOpener(url) {
|
|
1243
|
+
if (process.platform === "darwin") return {
|
|
1244
|
+
command: "open",
|
|
1245
|
+
args: [url],
|
|
1246
|
+
label: "open"
|
|
1247
|
+
};
|
|
1248
|
+
if (process.platform === "win32") return {
|
|
1249
|
+
command: "rundll32",
|
|
1250
|
+
args: ["url.dll,FileProtocolHandler", url],
|
|
1251
|
+
label: "rundll32"
|
|
1252
|
+
};
|
|
1253
|
+
return {
|
|
1254
|
+
command: "xdg-open",
|
|
1255
|
+
args: [url],
|
|
1256
|
+
label: "xdg-open"
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
const BROWSER_OPENER_CLOSE_TIMEOUT_MS = 1500;
|
|
1260
|
+
function spawnDetached(command, args) {
|
|
1261
|
+
return new Promise((resolve) => {
|
|
1262
|
+
const child = spawn(command, args, {
|
|
1263
|
+
stdio: "ignore",
|
|
1264
|
+
detached: true
|
|
1265
|
+
});
|
|
1266
|
+
let settled = false;
|
|
1267
|
+
const finish = (result) => {
|
|
1268
|
+
if (settled) return;
|
|
1269
|
+
settled = true;
|
|
1270
|
+
clearTimeout(timeoutId);
|
|
1271
|
+
resolve(result);
|
|
1272
|
+
};
|
|
1273
|
+
const timeoutId = setTimeout(() => {
|
|
1274
|
+
child.unref();
|
|
1275
|
+
finish({ status: "started" });
|
|
1276
|
+
}, BROWSER_OPENER_CLOSE_TIMEOUT_MS);
|
|
1277
|
+
child.once("error", (error) => {
|
|
1278
|
+
finish({
|
|
1279
|
+
status: "failed",
|
|
1280
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
1281
|
+
});
|
|
1282
|
+
});
|
|
1283
|
+
child.once("close", (code, signal) => {
|
|
1284
|
+
if (signal) {
|
|
1285
|
+
finish({
|
|
1286
|
+
status: "failed",
|
|
1287
|
+
reason: `signal_${signal}`
|
|
1288
|
+
});
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1291
|
+
if (code === 0) {
|
|
1292
|
+
finish({ status: "started" });
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
finish({
|
|
1296
|
+
status: "failed",
|
|
1297
|
+
reason: `exit_${code ?? "null"}`
|
|
1298
|
+
});
|
|
1299
|
+
});
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
async function openDeviceAuthorizationUrl(url) {
|
|
1303
|
+
const testOpener = process.env.ARTIFACTSHARE_TEST_BROWSER_OPENER?.trim();
|
|
1304
|
+
if (testOpener === "success") return {
|
|
1305
|
+
attempted: true,
|
|
1306
|
+
status: "started",
|
|
1307
|
+
command: "test"
|
|
1308
|
+
};
|
|
1309
|
+
if (testOpener === "fail") return {
|
|
1310
|
+
attempted: true,
|
|
1311
|
+
status: "failed",
|
|
1312
|
+
command: "test",
|
|
1313
|
+
reason: "spawn_failed"
|
|
1314
|
+
};
|
|
1315
|
+
const skipReason = browserOpenSkipReason();
|
|
1316
|
+
if (skipReason) return {
|
|
1317
|
+
attempted: false,
|
|
1318
|
+
status: "skipped",
|
|
1319
|
+
reason: skipReason
|
|
1320
|
+
};
|
|
1321
|
+
const opener = resolveBrowserOpener(url);
|
|
1322
|
+
const spawnResult = await spawnDetached(opener.command, opener.args);
|
|
1323
|
+
if (spawnResult.status === "failed") return {
|
|
1324
|
+
attempted: true,
|
|
1325
|
+
status: "failed",
|
|
1326
|
+
command: opener.label,
|
|
1327
|
+
reason: spawnResult.reason
|
|
1328
|
+
};
|
|
1329
|
+
return {
|
|
1330
|
+
attempted: true,
|
|
1331
|
+
status: "started",
|
|
1332
|
+
command: opener.label
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1237
1335
|
//#endregion
|
|
1238
1336
|
//#region src/destination.ts
|
|
1239
1337
|
function destinationConflictError(options) {
|
|
@@ -1798,15 +1896,18 @@ async function performDeviceLogin(profile, options, mode) {
|
|
|
1798
1896
|
error: code.error
|
|
1799
1897
|
};
|
|
1800
1898
|
const deadline = Date.now() + code.expires_in * 1e3;
|
|
1801
|
-
if (mode.json)
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1899
|
+
if (mode.json) {
|
|
1900
|
+
const browserOpen = await openDeviceAuthorizationUrl(code.verification_uri_complete ?? code.verification_uri);
|
|
1901
|
+
writeEvent({
|
|
1902
|
+
status: "pending",
|
|
1903
|
+
verification_uri: code.verification_uri,
|
|
1904
|
+
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
1905
|
+
user_code: code.user_code,
|
|
1906
|
+
expires_at: new Date(deadline).toISOString(),
|
|
1907
|
+
interval_seconds: code.interval,
|
|
1908
|
+
browser_open: browserOpen
|
|
1909
|
+
});
|
|
1910
|
+
} else writeText([
|
|
1810
1911
|
"Open this URL in a browser to sign in:",
|
|
1811
1912
|
code.verification_uri_complete ?? code.verification_uri,
|
|
1812
1913
|
"",
|
|
@@ -1911,7 +2012,7 @@ async function pollForToken(options, code, init, profile, deadline) {
|
|
|
1911
2012
|
let intervalMs = Math.max(code.interval, 1) * 1e3;
|
|
1912
2013
|
let networkFailures = 0;
|
|
1913
2014
|
while (Date.now() < deadline) {
|
|
1914
|
-
await setTimeout(intervalMs);
|
|
2015
|
+
await setTimeout$1(intervalMs);
|
|
1915
2016
|
const response = await fetch(apiUrl("/api/auth/device/token", baseUrlOf(options)), {
|
|
1916
2017
|
method: "POST",
|
|
1917
2018
|
headers: { "content-type": "application/json" },
|
|
@@ -3529,7 +3630,11 @@ function onboardingNextSteps(signedIn) {
|
|
|
3529
3630
|
return [{
|
|
3530
3631
|
id: "login",
|
|
3531
3632
|
title: signedIn ? "Already signed in." : "Sign in so you can share files.",
|
|
3532
|
-
command: `${CLI_INVOCATION} login`,
|
|
3633
|
+
command: `${CLI_INVOCATION} login --json`,
|
|
3634
|
+
...!signedIn ? {
|
|
3635
|
+
requires_browser_approval: true,
|
|
3636
|
+
awaits_user_action: true
|
|
3637
|
+
} : {},
|
|
3533
3638
|
done: signedIn
|
|
3534
3639
|
}, {
|
|
3535
3640
|
id: "share",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artifactshare/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Upload and share HTML, Markdown, folders, and static sites from terminals, AI agents, automation, and CI.",
|
|
5
5
|
"homepage": "https://artifactshare.com/connect",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -4,7 +4,7 @@ description: Open, share, update, and read back shared files with the Artifact S
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- artifactshare-skill
|
|
7
|
-
version:
|
|
7
|
+
version: 19
|
|
8
8
|
managed: true
|
|
9
9
|
-->
|
|
10
10
|
|
|
@@ -48,8 +48,9 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
48
48
|
- In non-interactive environments (agents, CI, scripts), ask the user to issue
|
|
49
49
|
an API token at `https://artifactshare.com/settings/tokens`, then use
|
|
50
50
|
`ARTIFACTSHARE_TOKEN` or `--token` for normal commands.
|
|
51
|
-
- `login --profile <name
|
|
52
|
-
|
|
51
|
+
- `login --profile <name> --json` starts device login and may open the OS
|
|
52
|
+
browser for approval. Use it when a user is present; the pending event on
|
|
53
|
+
stderr includes `browser_open`. Do not pass API tokens to `login`.
|
|
53
54
|
Profiles created by `login` renew expired CLI sessions automatically.
|
|
54
55
|
- To keep using an issued token as a named profile without TTY or browser
|
|
55
56
|
login, pipe it on standard input:
|
|
@@ -4,7 +4,7 @@ alwaysApply: false
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- artifactshare-skill
|
|
7
|
-
version:
|
|
7
|
+
version: 19
|
|
8
8
|
managed: true
|
|
9
9
|
-->
|
|
10
10
|
|
|
@@ -26,7 +26,7 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
26
26
|
- Always pass `--json`; on failure read `error.code`, `error.hint`, and `error.recovery`.
|
|
27
27
|
- In agents, CI, or scripts, ask the user to issue an API token at `https://artifactshare.com/settings/tokens`, then run normal commands with `ARTIFACTSHARE_TOKEN` or `--token`; do not pass API tokens to `login`.
|
|
28
28
|
- To save that token as a named profile without TTY or browser login, pipe it on standard input: `printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile <name> --json`. Imported API-token profiles are not renewed by the CLI. Add `--allow-plaintext-token-store` only on a trusted machine without a native token store.
|
|
29
|
-
- Use `login --profile <name
|
|
29
|
+
- Use `login --profile <name> --json` when a user is present for browser approval. The pending event on stderr includes `browser_open`. Profiles created by `login` renew expired CLI sessions automatically.
|
|
30
30
|
- Switch profiles with `profiles use <name> --json`; list with `profiles list --json`.
|
|
31
31
|
- When the user gives an Artifact Share URL, start with `open <artifact-id-or-url> --json`. It ensures this rule is installed or updated, then reads single-file artifacts or returns a `download` next command for static sites and multi-file artifacts.
|
|
32
32
|
- Share with `share <path> --json`. Pick the destination with `--project-id <id>`, `--project <name>` (by exact name), the saved default, or `--home`. Set visibility with `--visibility private|workspace|project`; when `--grant-email` is passed the default becomes `private`.
|
|
@@ -44,4 +44,4 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
44
44
|
- Manage skills: `skills ensure --tool auto --json` detects the agent and installs or reports updates; `skills update --json` updates installed skills to the bundled version; `skills install --tool <name> --scope user --json` installs at the user level (`--force` overwrites unmanaged files).
|
|
45
45
|
- On `upload_not_allowed`, run `request-access --note '<why>' --json` and tell the user an operator opens sharing; do not retry in a loop.
|
|
46
46
|
- Check the current state with `whoami --json` or `doctor --json` for authentication, destination, network, upload access, and skill update status.
|
|
47
|
-
- First-time setup: `npx --yes @artifactshare/cli init` detects the agent, installs or updates this rule, and reports the next steps (sign in, then share).
|
|
47
|
+
- First-time setup: `npx --yes @artifactshare/cli init --json` detects the agent, installs or updates this rule, and reports the next steps (sign in, then share).
|