@artifactshare/cli 0.10.2 → 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 CHANGED
@@ -5,6 +5,11 @@ For user-facing announcements, see https://artifactshare.com/updates?product=cli
5
5
 
6
6
  ## Unreleased
7
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
+
8
13
  ## 0.10.2 - 2026-08-09
9
14
 
10
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.
package/README.md CHANGED
@@ -43,7 +43,7 @@ runs add versions to the same file.
43
43
 
44
44
  ## Authentication
45
45
 
46
- - **Interactive**: run `npx --yes @artifactshare/cli login`, or run `share`, `update`, or `download` directly — those commands start sign-in for you 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.
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
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
 
package/dist/index.d.ts CHANGED
@@ -1 +1,4 @@
1
- export {}
1
+ //#region src/index.d.ts
2
+ declare function generateCliHelp(path: string[]): Promise<string>;
3
+ //#endregion
4
+ export { generateCliHelp };
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
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";
6
9
  import { createHash, randomUUID } from "node:crypto";
7
10
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
8
- import { homedir } from "node:os";
9
- import { createReadStream } from "node:fs";
11
+ import { arch, homedir, platform } from "node:os";
10
12
  import { Blob } from "node:buffer";
11
13
  //#region src/constants.ts
12
14
  const DEFAULT_BASE_URL = "https://artifactshare.com";
@@ -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",
@@ -1791,7 +1794,8 @@ function parseStoredProfileCredential(raw) {
1791
1794
  session_token: parsed.session_token,
1792
1795
  refresh_token: parsed.refresh_token,
1793
1796
  ...parsed.expires_at !== void 0 ? { expires_at: parsed.expires_at } : {},
1794
- ...typeof parsed.pending_rotation_id === "string" && parsed.pending_rotation_id ? { pending_rotation_id: parsed.pending_rotation_id } : {}
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 } : {}
1795
1799
  };
1796
1800
  return {
1797
1801
  ok: true,
@@ -2043,7 +2047,7 @@ async function clearPendingDeviceAuth(baseUrl, profile) {
2043
2047
  }
2044
2048
  function isPendingDeviceAuth(value) {
2045
2049
  if (!isRecord(value)) return false;
2046
- 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";
2047
2051
  }
2048
2052
  function configHome() {
2049
2053
  const override = nonEmpty(process.env.ARTIFACTSHARE_CONFIG_HOME);
@@ -2229,12 +2233,20 @@ async function resolveEffectiveDefaultProfile(projectInput = null) {
2229
2233
  //#endregion
2230
2234
  //#region src/command-runners/login.ts
2231
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
+ };
2232
2241
  const request = await requestConfig(options);
2233
2242
  if (request.error) return {
2234
2243
  ok: false,
2235
2244
  error: request.error
2236
2245
  };
2237
- const code = await requestDeviceCode(options, request.init);
2246
+ const code = await requestDeviceCode(options, request.init, {
2247
+ preset: preset.value,
2248
+ deviceName: deviceNameForProfile(profile)
2249
+ });
2238
2250
  if ("error" in code) return {
2239
2251
  ok: false,
2240
2252
  error: code.error
@@ -2301,11 +2313,15 @@ async function runLogin(parsed, mode) {
2301
2313
  if (!result.ok) return writeFailure(command, result.error, mode, 1);
2302
2314
  return writeSuccess(command, result.data, mode);
2303
2315
  }
2304
- async function requestDeviceCode(options, init) {
2316
+ async function requestDeviceCode(options, init, authorization) {
2305
2317
  const response = await cliFetch(apiUrl("/api/auth/device/code", baseUrlOf(options)), {
2306
2318
  method: "POST",
2307
2319
  headers: { "content-type": "application/json" },
2308
- body: JSON.stringify({ client_id: DEVICE_CLIENT_ID }),
2320
+ body: JSON.stringify({
2321
+ client_id: DEVICE_CLIENT_ID,
2322
+ preset: authorization?.preset ?? "unrestricted",
2323
+ device_name: authorization?.deviceName
2324
+ }),
2309
2325
  ...init
2310
2326
  });
2311
2327
  if ("networkError" in response) return { error: networkError(response.networkError) };
@@ -2343,6 +2359,7 @@ function pendingDeviceAuthFromCode(profile, options, code) {
2343
2359
  return {
2344
2360
  base_url: baseUrlOf(options),
2345
2361
  profile,
2362
+ preset: options.preset === "agent" ? "agent" : "unrestricted",
2346
2363
  device_code: code.device_code,
2347
2364
  verification_uri: code.verification_uri,
2348
2365
  verification_uri_complete: code.verification_uri_complete ?? null,
@@ -2390,7 +2407,12 @@ async function pollForToken(options, code, init, profile, deadline) {
2390
2407
  async function verifyAndStoreProfileToken(profile, token, options, init, sessionExpiresAt = null) {
2391
2408
  const verified = await verifyProfileTokenAccount(profile, token, options, init);
2392
2409
  if (!verified.ok) return verified;
2393
- const refresh = await issueCliRefreshCredential(token, options, init);
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);
2394
2416
  if ("error" in refresh) return {
2395
2417
  ok: false,
2396
2418
  error: refresh.error
@@ -2399,7 +2421,8 @@ async function verifyAndStoreProfileToken(profile, token, options, init, session
2399
2421
  kind: "session",
2400
2422
  session_token: token,
2401
2423
  refresh_token: refresh.refresh_token,
2402
- expires_at: sessionExpiresAt
2424
+ expires_at: sessionExpiresAt,
2425
+ device_id: deviceId
2403
2426
  }, options);
2404
2427
  if (!saved.ok) return {
2405
2428
  ok: false,
@@ -2466,8 +2489,11 @@ async function verifyProfileTokenAccount(profile, token, options, init) {
2466
2489
  whoami
2467
2490
  };
2468
2491
  }
2469
- async function issueCliRefreshCredential(token, options, init) {
2470
- const result = await apiPost("/api/cli/auth/refresh-credentials", token, {}, options, init, {
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, {
2471
2497
  authenticated: true,
2472
2498
  baseUrl: baseUrlOf(options)
2473
2499
  });
@@ -2493,11 +2519,22 @@ async function writeProfileConfig(profile, options, tokenStore, whoami) {
2493
2519
  email: whoami.email ?? currentProfile?.email ?? null,
2494
2520
  workspace_id: whoami.workspace_id,
2495
2521
  token_store: tokenStore,
2522
+ preset: options.preset === "agent" || options.preset === "unrestricted" ? options.preset : currentProfile?.preset ?? "unrestricted",
2496
2523
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
2497
2524
  }
2498
2525
  }
2499
2526
  });
2500
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
+ }
2501
2538
  function isDeviceCodeResponse(body) {
2502
2539
  if (!isRecord(body)) return false;
2503
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";
@@ -2637,7 +2674,9 @@ async function refreshStoredProfileSession(profile, refreshToken, options) {
2637
2674
  ok: false,
2638
2675
  error: validationError("Refresh response was invalid.", "Run login again. If this repeats, report the response shape.", "service_error")
2639
2676
  };
2677
+ const { pending_rotation_id: _completedRotation, ...persistedCredential } = stored.credential;
2640
2678
  if (!(await saveProfileSessionCredential(profile, {
2679
+ ...persistedCredential,
2641
2680
  kind: "session",
2642
2681
  session_token: body.access_token,
2643
2682
  refresh_token: body.refresh_token,
@@ -2666,7 +2705,10 @@ async function handleJsonPendingAuth(command, credential, options, mode, rerun)
2666
2705
  return writeFailure(command, exchange.error, mode, 1);
2667
2706
  }
2668
2707
  if (exchange.status === "success") {
2669
- const stored = await verifyAndStoreProfileToken(profile, exchange.token.access_token, options, request.init, exchange.token.expires_in === void 0 ? null : new Date(Date.now() + exchange.token.expires_in * 1e3).toISOString());
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());
2670
2712
  if (!stored.ok) return writeFailure(command, stored.error, mode, 1);
2671
2713
  await clearPendingDeviceAuth(baseUrl, profile);
2672
2714
  return rerun();
@@ -2679,9 +2721,16 @@ async function handleJsonPendingAuth(command, credential, options, mode, rerun)
2679
2721
  else if (exchange.status === "retry_later") return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, existing, extraDetails), mode, 1);
2680
2722
  else return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, existing, extraDetails), mode, 1);
2681
2723
  } else if (existing) await clearPendingDeviceAuth(baseUrl, profile);
2682
- const code = await requestDeviceCode(options, request.init);
2724
+ const preset = (await readGlobalConfig())?.profiles?.[profile]?.preset ?? "unrestricted";
2725
+ const code = await requestDeviceCode(options, request.init, {
2726
+ preset,
2727
+ deviceName: deviceNameForProfile(profile)
2728
+ });
2683
2729
  if ("error" in code) return writeFailure(command, credential.error, mode, 1);
2684
- const pending = pendingDeviceAuthFromCode(profile, options, code);
2730
+ const pending = pendingDeviceAuthFromCode(profile, {
2731
+ ...options,
2732
+ preset
2733
+ }, code);
2685
2734
  if (!await writePendingDeviceAuth(pending)) return writeFailure(command, credential.error, mode, 1);
2686
2735
  return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, pending, extraDetails), mode, 1);
2687
2736
  }
@@ -5571,11 +5620,13 @@ async function main(rawArgv) {
5571
5620
  if (usage) writeText(usage);
5572
5621
  }
5573
5622
  async function runGunshi(argv) {
5574
- const version = await loadCliVersion();
5575
- return cli(argv, entryCommand, {
5623
+ return cli(argv, entryCommand, await cliOptions());
5624
+ }
5625
+ async function cliOptions(version = loadCliVersion()) {
5626
+ return {
5576
5627
  name: "artifactshare",
5577
5628
  description: "Artifact Share CLI",
5578
- version,
5629
+ version: await version,
5579
5630
  subCommands: {
5580
5631
  login: lazyCommand(loginDefinition, loginRunner),
5581
5632
  logout: lazyCommand(logoutDefinition, logoutRunner),
@@ -5600,7 +5651,10 @@ async function runGunshi(argv) {
5600
5651
  init: lazyCommand(initDefinition, initRunner)
5601
5652
  },
5602
5653
  usageSilent: true
5603
- });
5654
+ };
5655
+ }
5656
+ async function generateCliHelp(path) {
5657
+ return generate(path.length ? path : null, entryCommand, await cliOptions());
5604
5658
  }
5605
5659
  function lazyCommand(definition, runner) {
5606
5660
  return lazy(() => Promise.resolve(async (ctx) => {
@@ -5687,9 +5741,15 @@ const loginDefinition = define({
5687
5741
  name: "login",
5688
5742
  description: "Sign in with browser device authorization and save a CLI profile.",
5689
5743
  toKebab: true,
5690
- args: commonArgs,
5744
+ args: {
5745
+ ...commonArgs,
5746
+ preset: {
5747
+ type: "string",
5748
+ description: "Authorization preset: unrestricted or agent"
5749
+ }
5750
+ },
5691
5751
  examples: `npx --yes @artifactshare/cli login --profile default
5692
- npx --yes @artifactshare/cli login --profile client-a --json
5752
+ npx --yes @artifactshare/cli login --profile client-a --preset agent --json
5693
5753
 
5694
5754
  login requires browser approval in an interactive terminal.
5695
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.
@@ -6810,8 +6870,14 @@ const changelogDefinition = define({
6810
6870
  args: { json: commonArgs.json }
6811
6871
  });
6812
6872
  const cliArgv = process.argv.slice(2);
6813
- main(cliArgv).catch((error) => {
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) => {
6814
6880
  writeFailure("unknown", unexpectedError(error), outputModeFromArgv(cliArgv), 1);
6815
6881
  });
6816
6882
  //#endregion
6817
- export {};
6883
+ export { generateCliHelp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artifactshare/cli",
3
- "version": "0.10.2",
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
6
  "repository": {
@@ -68,9 +68,10 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
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 and may open the OS
72
- browser for approval. Use it when a user is present; the pending event on
73
- stderr includes `browser_open`. Do not pass API tokens to `login`.
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
76
  - `logout --profile <name> --json` revokes a device-login refresh credential
76
77
  before removing it locally and leaves profile metadata in `config.json`.
@@ -49,7 +49,7 @@ 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
- - 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`.
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.