@artifactshare/cli 0.10.1 → 0.11.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.
- package/CHANGELOG.md +11 -0
- package/README.md +4 -4
- package/dist/index.d.ts +4 -1
- package/dist/index.js +127 -30
- package/package.json +6 -1
- package/skills/artifactshare/SKILL.md +9 -7
- package/skills/artifactshare/artifactshare.mdc +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to `@artifactshare/cli` are documented here.
|
|
4
4
|
For user-facing announcements, see https://artifactshare.com/updates?product=cli.
|
|
5
5
|
|
|
6
|
+
## Unreleased
|
|
7
|
+
|
|
8
|
+
## 0.11.0 - 2026-08-12
|
|
9
|
+
|
|
10
|
+
- Add `login --preset agent` for browser-approved credentials restricted to one project, with scoped defaults and guidance across login, `whoami`, and `doctor`.
|
|
11
|
+
- Identify CLI device sessions across login and refresh rotation so users can manage and revoke them from Settings.
|
|
12
|
+
|
|
13
|
+
## 0.10.2 - 2026-08-09
|
|
14
|
+
|
|
15
|
+
- Rotate device-login refresh credentials after use and revoke their credential family during `logout`; a failed remote revoke now leaves the local credential intact.
|
|
16
|
+
|
|
6
17
|
## 0.10.1 - 2026-08-09
|
|
7
18
|
|
|
8
19
|
- Publish the first npm release covered by the Artifact Share source-available license.
|
package/README.md
CHANGED
|
@@ -43,9 +43,9 @@ runs add versions to the same file.
|
|
|
43
43
|
|
|
44
44
|
## Authentication
|
|
45
45
|
|
|
46
|
-
- **Interactive**: run `npx --yes @artifactshare/cli login`, or
|
|
46
|
+
- **Interactive**: run `npx --yes @artifactshare/cli login`, or use `login --preset agent` to authorize a profile for one selected project with restricted agent operations. Running `share`, `update`, or `download` directly also starts sign-in when unauthenticated (the CLI prints a link and code to open in your browser). Profiles created by `login` renew expired CLI sessions automatically during normal use.
|
|
47
47
|
- **CI / non-interactive**: issue a token at `https://artifactshare.com/settings/tokens`, then set `ARTIFACTSHARE_TOKEN` (or pass `--token`). Without a token, non-interactive runs fail with `error.code: "auth_required"` instead of hanging.
|
|
48
|
-
- Multiple accounts: keep one local profile per account (`profiles list` / `profiles use <name>`). In non-interactive agents, pipe an issued token into `profiles import-token --profile <name> --json` to create a saved API-token profile without browser login; API-token profiles are not renewed by the CLI. Use `logout --profile <name>` to
|
|
48
|
+
- Multiple accounts: keep one local profile per account (`profiles list` / `profiles use <name>`). In non-interactive agents, pipe an issued token into `profiles import-token --profile <name> --json` to create a saved API-token profile without browser login; API-token profiles are not renewed by the CLI. Use `logout --profile <name>` to revoke a device-login credential before removing it locally while keeping profile metadata, or `profiles delete <name>` to remove the profile entry too. API-token profiles are only removed locally.
|
|
49
49
|
|
|
50
50
|
## Commands
|
|
51
51
|
|
|
@@ -63,7 +63,7 @@ runs add versions to the same file.
|
|
|
63
63
|
| `comments list / post / edit / resolve / reopen / delete <target>` | Read, write, edit, resolve, reopen, and permanently delete comments |
|
|
64
64
|
| `projects list / create / edit` | List, create, and edit project destinations and audience |
|
|
65
65
|
| `move <target>` | Move an existing file into a project or back home; `edit` is preferred for new automation |
|
|
66
|
-
| `login` / `logout` / `whoami` | Sign in,
|
|
66
|
+
| `login` / `logout` / `whoami` | Sign in, revoke a device-login credential before removing it locally, and check who you are |
|
|
67
67
|
| `doctor` | Diagnose auth, destination, network, and upload readiness — tells you the next command to run |
|
|
68
68
|
| `changelog` | Show the installed version, this release's notes, and the public updates page |
|
|
69
69
|
| `profiles list / use / import-token / delete` | Switch between local account profiles, import an issued token from stdin, and delete profile entries |
|
|
@@ -129,4 +129,4 @@ Quote paths and free-form text before passing them through a shell. Artifact Sha
|
|
|
129
129
|
|
|
130
130
|
## License
|
|
131
131
|
|
|
132
|
-
The npm package through version 0.9.0 is licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). From
|
|
132
|
+
The npm package through version 0.9.0 is licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). From version 0.10.0 onward, `@artifactshare/cli` is covered by the [source-available license](LICENSE). Version 0.10.0 was intentionally not published; version 0.10.1 is the first npm release under the new license.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cli, define, lazy } from "gunshi";
|
|
3
|
+
import { generate } from "gunshi/generator";
|
|
4
|
+
import { createReadStream, realpathSync } from "node:fs";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
3
6
|
import { spawn } from "node:child_process";
|
|
4
7
|
import { appendFile, chmod, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
5
8
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
9
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
6
10
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
7
|
-
import { homedir } from "node:os";
|
|
8
|
-
import { createReadStream } from "node:fs";
|
|
11
|
+
import { arch, homedir, platform } from "node:os";
|
|
9
12
|
import { Blob } from "node:buffer";
|
|
10
|
-
import { createHash } from "node:crypto";
|
|
11
13
|
//#region src/constants.ts
|
|
12
14
|
const DEFAULT_BASE_URL = "https://artifactshare.com";
|
|
13
15
|
const DEVICE_CLIENT_ID = "artifactshare-cli";
|
|
@@ -55,6 +57,7 @@ const VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
|
55
57
|
"offset",
|
|
56
58
|
"output",
|
|
57
59
|
"profile",
|
|
60
|
+
"preset",
|
|
58
61
|
"project",
|
|
59
62
|
"project-id",
|
|
60
63
|
"query",
|
|
@@ -1790,7 +1793,9 @@ function parseStoredProfileCredential(raw) {
|
|
|
1790
1793
|
kind: "session",
|
|
1791
1794
|
session_token: parsed.session_token,
|
|
1792
1795
|
refresh_token: parsed.refresh_token,
|
|
1793
|
-
...parsed.expires_at !== void 0 ? { expires_at: parsed.expires_at } : {}
|
|
1796
|
+
...parsed.expires_at !== void 0 ? { expires_at: parsed.expires_at } : {},
|
|
1797
|
+
...typeof parsed.pending_rotation_id === "string" && parsed.pending_rotation_id ? { pending_rotation_id: parsed.pending_rotation_id } : {},
|
|
1798
|
+
...typeof parsed.device_id === "string" && parsed.device_id ? { device_id: parsed.device_id } : {}
|
|
1794
1799
|
};
|
|
1795
1800
|
return {
|
|
1796
1801
|
ok: true,
|
|
@@ -2042,7 +2047,7 @@ async function clearPendingDeviceAuth(baseUrl, profile) {
|
|
|
2042
2047
|
}
|
|
2043
2048
|
function isPendingDeviceAuth(value) {
|
|
2044
2049
|
if (!isRecord(value)) return false;
|
|
2045
|
-
return typeof value.base_url === "string" && typeof value.profile === "string" && typeof value.device_code === "string" && typeof value.verification_uri === "string" && (typeof value.verification_uri_complete === "string" || value.verification_uri_complete === null) && typeof value.user_code === "string" && typeof value.expires_at === "string" && typeof value.interval_seconds === "number" && typeof value.created_at === "string";
|
|
2050
|
+
return typeof value.base_url === "string" && typeof value.profile === "string" && (value.preset === void 0 || value.preset === "unrestricted" || value.preset === "agent") && typeof value.device_code === "string" && typeof value.verification_uri === "string" && (typeof value.verification_uri_complete === "string" || value.verification_uri_complete === null) && typeof value.user_code === "string" && typeof value.expires_at === "string" && typeof value.interval_seconds === "number" && typeof value.created_at === "string";
|
|
2046
2051
|
}
|
|
2047
2052
|
function configHome() {
|
|
2048
2053
|
const override = nonEmpty(process.env.ARTIFACTSHARE_CONFIG_HOME);
|
|
@@ -2228,12 +2233,20 @@ async function resolveEffectiveDefaultProfile(projectInput = null) {
|
|
|
2228
2233
|
//#endregion
|
|
2229
2234
|
//#region src/command-runners/login.ts
|
|
2230
2235
|
async function performDeviceLogin(profile, options, mode) {
|
|
2236
|
+
const preset = await resolveAuthorizationPreset(profile, options);
|
|
2237
|
+
if ("error" in preset) return {
|
|
2238
|
+
ok: false,
|
|
2239
|
+
error: preset.error
|
|
2240
|
+
};
|
|
2231
2241
|
const request = await requestConfig(options);
|
|
2232
2242
|
if (request.error) return {
|
|
2233
2243
|
ok: false,
|
|
2234
2244
|
error: request.error
|
|
2235
2245
|
};
|
|
2236
|
-
const code = await requestDeviceCode(options, request.init
|
|
2246
|
+
const code = await requestDeviceCode(options, request.init, {
|
|
2247
|
+
preset: preset.value,
|
|
2248
|
+
deviceName: deviceNameForProfile(profile)
|
|
2249
|
+
});
|
|
2237
2250
|
if ("error" in code) return {
|
|
2238
2251
|
ok: false,
|
|
2239
2252
|
error: code.error
|
|
@@ -2300,11 +2313,15 @@ async function runLogin(parsed, mode) {
|
|
|
2300
2313
|
if (!result.ok) return writeFailure(command, result.error, mode, 1);
|
|
2301
2314
|
return writeSuccess(command, result.data, mode);
|
|
2302
2315
|
}
|
|
2303
|
-
async function requestDeviceCode(options, init) {
|
|
2316
|
+
async function requestDeviceCode(options, init, authorization) {
|
|
2304
2317
|
const response = await cliFetch(apiUrl("/api/auth/device/code", baseUrlOf(options)), {
|
|
2305
2318
|
method: "POST",
|
|
2306
2319
|
headers: { "content-type": "application/json" },
|
|
2307
|
-
body: JSON.stringify({
|
|
2320
|
+
body: JSON.stringify({
|
|
2321
|
+
client_id: DEVICE_CLIENT_ID,
|
|
2322
|
+
preset: authorization?.preset ?? "unrestricted",
|
|
2323
|
+
device_name: authorization?.deviceName
|
|
2324
|
+
}),
|
|
2308
2325
|
...init
|
|
2309
2326
|
});
|
|
2310
2327
|
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
@@ -2342,6 +2359,7 @@ function pendingDeviceAuthFromCode(profile, options, code) {
|
|
|
2342
2359
|
return {
|
|
2343
2360
|
base_url: baseUrlOf(options),
|
|
2344
2361
|
profile,
|
|
2362
|
+
preset: options.preset === "agent" ? "agent" : "unrestricted",
|
|
2345
2363
|
device_code: code.device_code,
|
|
2346
2364
|
verification_uri: code.verification_uri,
|
|
2347
2365
|
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
@@ -2389,7 +2407,12 @@ async function pollForToken(options, code, init, profile, deadline) {
|
|
|
2389
2407
|
async function verifyAndStoreProfileToken(profile, token, options, init, sessionExpiresAt = null) {
|
|
2390
2408
|
const verified = await verifyProfileTokenAccount(profile, token, options, init);
|
|
2391
2409
|
if (!verified.ok) return verified;
|
|
2392
|
-
const
|
|
2410
|
+
const stored = await readProfileToken(profile, options);
|
|
2411
|
+
const deviceId = (stored.ok && stored.credential.kind === "session" ? nonEmpty(stored.credential.device_id) : null) ?? randomUUID();
|
|
2412
|
+
const deviceSuffix = `, ${deviceId.slice(0, 8)})`;
|
|
2413
|
+
const devicePrefix = `Artifact Share CLI on ${platform()} ${arch()} (`;
|
|
2414
|
+
const profileBudget = Math.max(0, 100 - devicePrefix.length - deviceSuffix.length);
|
|
2415
|
+
const refresh = await issueCliRefreshCredential(token, `${devicePrefix}${profile.slice(0, profileBudget)}${deviceSuffix}`, deviceId, options, init);
|
|
2393
2416
|
if ("error" in refresh) return {
|
|
2394
2417
|
ok: false,
|
|
2395
2418
|
error: refresh.error
|
|
@@ -2398,7 +2421,8 @@ async function verifyAndStoreProfileToken(profile, token, options, init, session
|
|
|
2398
2421
|
kind: "session",
|
|
2399
2422
|
session_token: token,
|
|
2400
2423
|
refresh_token: refresh.refresh_token,
|
|
2401
|
-
expires_at: sessionExpiresAt
|
|
2424
|
+
expires_at: sessionExpiresAt,
|
|
2425
|
+
device_id: deviceId
|
|
2402
2426
|
}, options);
|
|
2403
2427
|
if (!saved.ok) return {
|
|
2404
2428
|
ok: false,
|
|
@@ -2465,8 +2489,11 @@ async function verifyProfileTokenAccount(profile, token, options, init) {
|
|
|
2465
2489
|
whoami
|
|
2466
2490
|
};
|
|
2467
2491
|
}
|
|
2468
|
-
async function issueCliRefreshCredential(token, options, init) {
|
|
2469
|
-
const result = await apiPost("/api/cli/auth/refresh-credentials", token, {
|
|
2492
|
+
async function issueCliRefreshCredential(token, deviceName, deviceId, options, init) {
|
|
2493
|
+
const result = await apiPost("/api/cli/auth/refresh-credentials", token, {
|
|
2494
|
+
device_name: deviceName,
|
|
2495
|
+
device_id: deviceId
|
|
2496
|
+
}, options, init, {
|
|
2470
2497
|
authenticated: true,
|
|
2471
2498
|
baseUrl: baseUrlOf(options)
|
|
2472
2499
|
});
|
|
@@ -2492,11 +2519,22 @@ async function writeProfileConfig(profile, options, tokenStore, whoami) {
|
|
|
2492
2519
|
email: whoami.email ?? currentProfile?.email ?? null,
|
|
2493
2520
|
workspace_id: whoami.workspace_id,
|
|
2494
2521
|
token_store: tokenStore,
|
|
2522
|
+
preset: options.preset === "agent" || options.preset === "unrestricted" ? options.preset : currentProfile?.preset ?? "unrestricted",
|
|
2495
2523
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2496
2524
|
}
|
|
2497
2525
|
}
|
|
2498
2526
|
});
|
|
2499
2527
|
}
|
|
2528
|
+
async function resolveAuthorizationPreset(profile, options) {
|
|
2529
|
+
const requested = nonEmpty(options.preset);
|
|
2530
|
+
if (requested && requested !== "agent" && requested !== "unrestricted") return { error: validationError(`Unknown authorization preset: ${requested}`, "Use --preset agent or --preset unrestricted.") };
|
|
2531
|
+
if (requested === "agent" || requested === "unrestricted") return { value: requested };
|
|
2532
|
+
return { value: (await readGlobalConfig())?.profiles?.[profile]?.preset ?? "unrestricted" };
|
|
2533
|
+
}
|
|
2534
|
+
function deviceNameForProfile(profile) {
|
|
2535
|
+
const prefix = `Artifact Share CLI on ${platform()} ${arch()} (`;
|
|
2536
|
+
return `${prefix}${profile.slice(0, Math.max(0, 99 - prefix.length))})`;
|
|
2537
|
+
}
|
|
2500
2538
|
function isDeviceCodeResponse(body) {
|
|
2501
2539
|
if (!isRecord(body)) return false;
|
|
2502
2540
|
return typeof body.device_code === "string" && typeof body.user_code === "string" && typeof body.verification_uri === "string" && (typeof body.verification_uri_complete === "string" || body.verification_uri_complete === void 0) && typeof body.expires_in === "number" && typeof body.interval === "number";
|
|
@@ -2599,12 +2637,27 @@ async function runAuthenticatedApi(credential, options, request) {
|
|
|
2599
2637
|
return await request(refreshed.credential);
|
|
2600
2638
|
}
|
|
2601
2639
|
async function refreshStoredProfileSession(profile, refreshToken, options) {
|
|
2640
|
+
const stored = await readProfileToken(profile, options);
|
|
2641
|
+
if (!stored.ok || stored.credential.kind !== "session") return { ok: false };
|
|
2642
|
+
const rotationRequestId = stored.credential.pending_rotation_id ?? randomUUID();
|
|
2643
|
+
if (!stored.credential.pending_rotation_id) {
|
|
2644
|
+
if (!(await saveProfileSessionCredential(profile, {
|
|
2645
|
+
...stored.credential,
|
|
2646
|
+
pending_rotation_id: rotationRequestId
|
|
2647
|
+
}, options)).ok) return {
|
|
2648
|
+
ok: false,
|
|
2649
|
+
error: tokenStoreUnavailableError(profile)
|
|
2650
|
+
};
|
|
2651
|
+
}
|
|
2602
2652
|
const request = await requestConfig(options);
|
|
2603
2653
|
if (request.error) return {
|
|
2604
2654
|
ok: false,
|
|
2605
2655
|
error: request.error
|
|
2606
2656
|
};
|
|
2607
|
-
const result = await apiPostPublic("/api/cli/auth/refresh", {
|
|
2657
|
+
const result = await apiPostPublic("/api/cli/auth/refresh", {
|
|
2658
|
+
refresh_token: refreshToken,
|
|
2659
|
+
rotation_request_id: rotationRequestId
|
|
2660
|
+
}, options, request.init);
|
|
2608
2661
|
if (result.error) return {
|
|
2609
2662
|
ok: false,
|
|
2610
2663
|
error: result.error
|
|
@@ -2617,14 +2670,16 @@ async function refreshStoredProfileSession(profile, refreshToken, options) {
|
|
|
2617
2670
|
error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) })
|
|
2618
2671
|
};
|
|
2619
2672
|
}
|
|
2620
|
-
if (typeof body?.access_token !== "string" || body.access_token.length === 0 || body.token_type?.toLowerCase() !== "bearer" || typeof body.expires_at !== "string") return {
|
|
2673
|
+
if (typeof body?.access_token !== "string" || body.access_token.length === 0 || body.token_type?.toLowerCase() !== "bearer" || typeof body.expires_at !== "string" || typeof body.refresh_token !== "string" || !body.refresh_token || typeof body.refresh_token_expires_at !== "string") return {
|
|
2621
2674
|
ok: false,
|
|
2622
2675
|
error: validationError("Refresh response was invalid.", "Run login again. If this repeats, report the response shape.", "service_error")
|
|
2623
2676
|
};
|
|
2677
|
+
const { pending_rotation_id: _completedRotation, ...persistedCredential } = stored.credential;
|
|
2624
2678
|
if (!(await saveProfileSessionCredential(profile, {
|
|
2679
|
+
...persistedCredential,
|
|
2625
2680
|
kind: "session",
|
|
2626
2681
|
session_token: body.access_token,
|
|
2627
|
-
refresh_token:
|
|
2682
|
+
refresh_token: body.refresh_token,
|
|
2628
2683
|
expires_at: body.expires_at
|
|
2629
2684
|
}, options)).ok) return {
|
|
2630
2685
|
ok: false,
|
|
@@ -2650,7 +2705,10 @@ async function handleJsonPendingAuth(command, credential, options, mode, rerun)
|
|
|
2650
2705
|
return writeFailure(command, exchange.error, mode, 1);
|
|
2651
2706
|
}
|
|
2652
2707
|
if (exchange.status === "success") {
|
|
2653
|
-
const stored = await verifyAndStoreProfileToken(profile, exchange.token.access_token,
|
|
2708
|
+
const stored = await verifyAndStoreProfileToken(profile, exchange.token.access_token, {
|
|
2709
|
+
...options,
|
|
2710
|
+
preset: existing.preset ?? "unrestricted"
|
|
2711
|
+
}, request.init, exchange.token.expires_in === void 0 ? null : new Date(Date.now() + exchange.token.expires_in * 1e3).toISOString());
|
|
2654
2712
|
if (!stored.ok) return writeFailure(command, stored.error, mode, 1);
|
|
2655
2713
|
await clearPendingDeviceAuth(baseUrl, profile);
|
|
2656
2714
|
return rerun();
|
|
@@ -2663,9 +2721,16 @@ async function handleJsonPendingAuth(command, credential, options, mode, rerun)
|
|
|
2663
2721
|
else if (exchange.status === "retry_later") return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, existing, extraDetails), mode, 1);
|
|
2664
2722
|
else return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, existing, extraDetails), mode, 1);
|
|
2665
2723
|
} else if (existing) await clearPendingDeviceAuth(baseUrl, profile);
|
|
2666
|
-
const
|
|
2724
|
+
const preset = (await readGlobalConfig())?.profiles?.[profile]?.preset ?? "unrestricted";
|
|
2725
|
+
const code = await requestDeviceCode(options, request.init, {
|
|
2726
|
+
preset,
|
|
2727
|
+
deviceName: deviceNameForProfile(profile)
|
|
2728
|
+
});
|
|
2667
2729
|
if ("error" in code) return writeFailure(command, credential.error, mode, 1);
|
|
2668
|
-
const pending = pendingDeviceAuthFromCode(profile,
|
|
2730
|
+
const pending = pendingDeviceAuthFromCode(profile, {
|
|
2731
|
+
...options,
|
|
2732
|
+
preset
|
|
2733
|
+
}, code);
|
|
2669
2734
|
if (!await writePendingDeviceAuth(pending)) return writeFailure(command, credential.error, mode, 1);
|
|
2670
2735
|
return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, pending, extraDetails), mode, 1);
|
|
2671
2736
|
}
|
|
@@ -4435,11 +4500,17 @@ function configData(config, resolved) {
|
|
|
4435
4500
|
//#endregion
|
|
4436
4501
|
//#region src/command-runners/profile-credentials.ts
|
|
4437
4502
|
async function deleteCredentialForProfileEntry(profile, rawEntry, options) {
|
|
4503
|
+
return await deleteProfileCredential(profile, optionsForProfileEntry(rawEntry, options));
|
|
4504
|
+
}
|
|
4505
|
+
async function readCredentialForProfileEntry(profile, rawEntry, options) {
|
|
4506
|
+
return await readProfileToken(profile, optionsForProfileEntry(rawEntry, options));
|
|
4507
|
+
}
|
|
4508
|
+
function optionsForProfileEntry(rawEntry, options) {
|
|
4438
4509
|
const entry = isRecord(rawEntry) ? rawEntry : {};
|
|
4439
|
-
return
|
|
4510
|
+
return {
|
|
4440
4511
|
...options,
|
|
4441
4512
|
baseUrl: nonEmpty(entry.base_url) ?? "https://artifactshare.com"
|
|
4442
|
-
}
|
|
4513
|
+
};
|
|
4443
4514
|
}
|
|
4444
4515
|
//#endregion
|
|
4445
4516
|
//#region src/command-runners/logout.ts
|
|
@@ -4463,6 +4534,15 @@ async function runLogout(parsed, mode) {
|
|
|
4463
4534
|
profile = defaultProfile;
|
|
4464
4535
|
}
|
|
4465
4536
|
const rawEntry = config.profiles?.[profile];
|
|
4537
|
+
const profileOptions = optionsForProfileEntry(rawEntry, parsed.options);
|
|
4538
|
+
const stored = await readCredentialForProfileEntry(profile, rawEntry, parsed.options);
|
|
4539
|
+
if (stored.ok && stored.credential.kind === "session") {
|
|
4540
|
+
const request = await requestConfig(profileOptions);
|
|
4541
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4542
|
+
const revoked = await apiPostPublic("/api/cli/auth/revoke", { refresh_token: stored.credential.refresh_token }, profileOptions, request.init);
|
|
4543
|
+
if (revoked.error) return writeFailure(command, revoked.error, mode, 1);
|
|
4544
|
+
if (!revoked.response.ok && revoked.response.status !== 401) return writeFailure(command, mapApiError(revoked.response.status, revoked.body, { baseUrl: baseUrlOf(profileOptions) }), mode, 1);
|
|
4545
|
+
}
|
|
4466
4546
|
const deleted = await deleteCredentialForProfileEntry(profile, rawEntry, parsed.options);
|
|
4467
4547
|
if (!deleted.ok) return writeFailure(command, tokenStoreUnavailableError(profile), mode, 1);
|
|
4468
4548
|
return writeSuccess(command, {
|
|
@@ -5540,11 +5620,13 @@ async function main(rawArgv) {
|
|
|
5540
5620
|
if (usage) writeText(usage);
|
|
5541
5621
|
}
|
|
5542
5622
|
async function runGunshi(argv) {
|
|
5543
|
-
|
|
5544
|
-
|
|
5623
|
+
return cli(argv, entryCommand, await cliOptions());
|
|
5624
|
+
}
|
|
5625
|
+
async function cliOptions(version = loadCliVersion()) {
|
|
5626
|
+
return {
|
|
5545
5627
|
name: "artifactshare",
|
|
5546
5628
|
description: "Artifact Share CLI",
|
|
5547
|
-
version,
|
|
5629
|
+
version: await version,
|
|
5548
5630
|
subCommands: {
|
|
5549
5631
|
login: lazyCommand(loginDefinition, loginRunner),
|
|
5550
5632
|
logout: lazyCommand(logoutDefinition, logoutRunner),
|
|
@@ -5569,7 +5651,10 @@ async function runGunshi(argv) {
|
|
|
5569
5651
|
init: lazyCommand(initDefinition, initRunner)
|
|
5570
5652
|
},
|
|
5571
5653
|
usageSilent: true
|
|
5572
|
-
}
|
|
5654
|
+
};
|
|
5655
|
+
}
|
|
5656
|
+
async function generateCliHelp(path) {
|
|
5657
|
+
return generate(path.length ? path : null, entryCommand, await cliOptions());
|
|
5573
5658
|
}
|
|
5574
5659
|
function lazyCommand(definition, runner) {
|
|
5575
5660
|
return lazy(() => Promise.resolve(async (ctx) => {
|
|
@@ -5656,9 +5741,15 @@ const loginDefinition = define({
|
|
|
5656
5741
|
name: "login",
|
|
5657
5742
|
description: "Sign in with browser device authorization and save a CLI profile.",
|
|
5658
5743
|
toKebab: true,
|
|
5659
|
-
args:
|
|
5744
|
+
args: {
|
|
5745
|
+
...commonArgs,
|
|
5746
|
+
preset: {
|
|
5747
|
+
type: "string",
|
|
5748
|
+
description: "Authorization preset: unrestricted or agent"
|
|
5749
|
+
}
|
|
5750
|
+
},
|
|
5660
5751
|
examples: `npx --yes @artifactshare/cli login --profile default
|
|
5661
|
-
npx --yes @artifactshare/cli login --profile client-a --json
|
|
5752
|
+
npx --yes @artifactshare/cli login --profile client-a --preset agent --json
|
|
5662
5753
|
|
|
5663
5754
|
login requires browser approval in an interactive terminal.
|
|
5664
5755
|
For agents or CI, issue a token at ${DEFAULT_BASE_URL}/settings/tokens, then pass it to normal commands with ${TOKEN_ENV_VAR} or ${TOKEN_OPTION}; do not pass the token to login.
|
|
@@ -5670,13 +5761,13 @@ Common failures:
|
|
|
5670
5761
|
});
|
|
5671
5762
|
const logoutDefinition = define({
|
|
5672
5763
|
name: "logout",
|
|
5673
|
-
description: "
|
|
5764
|
+
description: "Revoke and remove the saved credential for a CLI profile.",
|
|
5674
5765
|
toKebab: true,
|
|
5675
5766
|
args: commonArgs,
|
|
5676
5767
|
examples: `npx --yes @artifactshare/cli logout --profile client-a --json
|
|
5677
5768
|
npx --yes @artifactshare/cli logout --json
|
|
5678
5769
|
|
|
5679
|
-
logout
|
|
5770
|
+
logout revokes a device-login refresh credential before removing it locally. API-token profiles are removed locally only. Profile metadata stays in config.json for re-login hints.
|
|
5680
5771
|
When no --profile is passed, the global default profile is used.
|
|
5681
5772
|
|
|
5682
5773
|
Common failures:
|
|
@@ -6779,8 +6870,14 @@ const changelogDefinition = define({
|
|
|
6779
6870
|
args: { json: commonArgs.json }
|
|
6780
6871
|
});
|
|
6781
6872
|
const cliArgv = process.argv.slice(2);
|
|
6782
|
-
|
|
6873
|
+
let isDirectExecution = false;
|
|
6874
|
+
if (process.argv[1]) try {
|
|
6875
|
+
isDirectExecution = realpathSync(new URL(import.meta.url)) === realpathSync(process.argv[1]);
|
|
6876
|
+
} catch {
|
|
6877
|
+
isDirectExecution = import.meta.url === pathToFileURL(process.argv[1]).href;
|
|
6878
|
+
}
|
|
6879
|
+
if (isDirectExecution) main(cliArgv).catch((error) => {
|
|
6783
6880
|
writeFailure("unknown", unexpectedError(error), outputModeFromArgv(cliArgv), 1);
|
|
6784
6881
|
});
|
|
6785
6882
|
//#endregion
|
|
6786
|
-
export {};
|
|
6883
|
+
export { generateCliHelp };
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artifactshare/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/artifactshare/artifactshare.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
6
11
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
12
|
"keywords": [
|
|
8
13
|
"artifact-share",
|
|
@@ -61,20 +61,22 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
61
61
|
| Create a project | `projects create 'Name' --json` |
|
|
62
62
|
| Find an ID from a title | `resolve <value> --json` |
|
|
63
63
|
| Open a share URL | `open <url> --json` |
|
|
64
|
-
| Log out
|
|
64
|
+
| Log out | `logout --profile <name> --json` |
|
|
65
65
|
|
|
66
66
|
## Authentication
|
|
67
67
|
|
|
68
68
|
- In non-interactive environments (agents, CI, scripts), ask the user to issue
|
|
69
69
|
an API token at `https://artifactshare.com/settings/tokens`, then use
|
|
70
70
|
`ARTIFACTSHARE_TOKEN` or `--token` for normal commands.
|
|
71
|
-
- `login --profile <name> --json` starts device login
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
- `login --profile <name> --preset agent --json` starts device login for a
|
|
72
|
+
project-scoped agent profile. Omit `--preset` for unrestricted login. It may
|
|
73
|
+
open the OS browser for approval. Use it when a user is present; the pending
|
|
74
|
+
event on stderr includes `browser_open`. Do not pass API tokens to `login`.
|
|
74
75
|
Profiles created by `login` renew expired CLI sessions automatically.
|
|
75
|
-
- `logout --profile <name> --json`
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
- `logout --profile <name> --json` revokes a device-login refresh credential
|
|
77
|
+
before removing it locally and leaves profile metadata in `config.json`.
|
|
78
|
+
If remote revoke fails, the local credential is kept and logout fails.
|
|
79
|
+
API-token profiles are removed locally only and are not revoked on the server.
|
|
78
80
|
- To keep using an issued token as a named profile without TTY or browser
|
|
79
81
|
login, pipe it on standard input:
|
|
80
82
|
`printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile <name> --json`.
|
|
@@ -49,10 +49,10 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
49
49
|
exactly one of `--link-expires-at <RFC3339 UTC>` or `--no-link-expiry`; omit
|
|
50
50
|
both to use the workspace default on share or preserve the current expiry on
|
|
51
51
|
edit. Results expose `link_expires_at` as a UTC timestamp or `null`.
|
|
52
|
-
-
|
|
52
|
+
- For an agent with a user present, prefer `login --preset agent --profile <name> --json` and let the user select one project during browser approval. In unattended 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`.
|
|
53
53
|
- 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.
|
|
54
54
|
- 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.
|
|
55
|
-
-
|
|
55
|
+
- Use `logout --profile <name> --json` to revoke a device-login credential before removing it locally; this keeps profile metadata. API-token profiles are removed locally only and their server token is not revoked.
|
|
56
56
|
- Switch profiles with `profiles use <name> --json`; list with `profiles list --json`; remove a profile entry and its credential with `profiles delete <name> --json`.
|
|
57
57
|
- 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.
|
|
58
58
|
- Share with `share <path> --json`. In JSON output, give the user `data.artifact.url`; the artifact ID is `data.artifact.id`. Do not rerun `share` just to inspect the JSON shape: without `--key`, each successful run creates a new artifact. Posting to a project delivers to the audience defined by that project. Pick it with `--project-id <id>` or `--project <name>` (by exact name), or use the saved default. With no destination, share posts to home. Choose `home_audience` by purpose: use `config set home_audience private --scope user --json` for a personal safe default in this CLI environment, use `--scope repository` only for a policy agreed by all participants, and use `--visibility private|workspace|link` for one home post. For link sharing, pass exactly one of `--link-expires-at <RFC3339 UTC>` or `--no-link-expiry`; omit both to use the workspace default. Confirm the resolved audience with `config get home_audience --scope effective --json`; `--grant-email` does not change the resolved default.
|