@artifactshare/cli 0.4.1 → 0.5.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/README.md CHANGED
@@ -25,6 +25,7 @@ npx --yes @artifactshare/cli edit <artifact-id-or-url> --project-id <id> --json
25
25
  npx --yes @artifactshare/cli edit <artifact-id-or-url> --visibility private --grant-email viewer@example.com --json
26
26
  npx --yes @artifactshare/cli update <artifact-id-or-url> ./dist
27
27
  npx --yes @artifactshare/cli delete <artifact-id-or-url> --json
28
+ npx --yes @artifactshare/cli logout --profile default --json
28
29
  ```
29
30
 
30
31
  To keep an existing share URL, update it with
@@ -37,7 +38,7 @@ runs add versions to the same file.
37
38
 
38
39
  - **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.
39
40
  - **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.
40
- - 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.
41
+ - 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 remove a saved credential while keeping profile metadata, or `profiles delete <name>` to remove the profile entry too.
41
42
 
42
43
  ## Commands
43
44
 
@@ -55,9 +56,9 @@ runs add versions to the same file.
55
56
  | `projects list / create / edit` | List, create, and edit project destinations and audience |
56
57
  | `move <target>` | Move an existing file into a project or back home; `edit` is preferred for new automation |
57
58
  | `request-access` | Join the waitlist when sharing is not enabled yet |
58
- | `login` / `whoami` | Sign in and check who you are |
59
+ | `login` / `logout` / `whoami` | Sign in, remove a saved local credential, and check who you are |
59
60
  | `doctor` | Diagnose auth, destination, network, and upload readiness — tells you the next command to run |
60
- | `profiles list / use / import-token` | Switch between local account profiles and import an issued token from stdin |
61
+ | `profiles list / use / import-token / delete` | Switch between local account profiles, import an issued token from stdin, and delete profile entries |
61
62
  | `init` | Set up this directory: detect the agent and install the skill, then show next steps; or save defaults with `--profile` / `--project-id` |
62
63
  | `skills ensure / install / list / update / remove` | Install or update the bundled usage guide in your AI agent's skills |
63
64
 
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ const VALUE_FLAGS = new Set([
69
69
  ]);
70
70
  const COMMAND_NAMES = new Set([
71
71
  "login",
72
+ "logout",
72
73
  "share",
73
74
  "open",
74
75
  "update",
@@ -100,7 +101,8 @@ const SUBCOMMANDS = {
100
101
  profiles: [
101
102
  "list",
102
103
  "use",
103
- "import-token"
104
+ "import-token",
105
+ "delete"
104
106
  ],
105
107
  projects: [
106
108
  "list",
@@ -1466,6 +1468,35 @@ async function saveProfileCredential(profile, credential, options) {
1466
1468
  reason: "unavailable"
1467
1469
  };
1468
1470
  }
1471
+ async function deleteProfileCredential(profile, options) {
1472
+ const account = accountName(profile, baseUrlOf(options));
1473
+ let credentialRemoved = false;
1474
+ let tokenStore = null;
1475
+ const native = await nativeStore();
1476
+ if (native) {
1477
+ if (await native.read(account)) {
1478
+ if (!await native.delete(account)) return {
1479
+ ok: false,
1480
+ reason: "unavailable"
1481
+ };
1482
+ credentialRemoved = true;
1483
+ tokenStore = native.kind;
1484
+ }
1485
+ }
1486
+ if (await readPlaintextToken(account) !== null) {
1487
+ if (!await deletePlaintextTokenAccount(account)) return {
1488
+ ok: false,
1489
+ reason: "unavailable"
1490
+ };
1491
+ credentialRemoved = true;
1492
+ tokenStore ??= "plaintext_file";
1493
+ }
1494
+ return {
1495
+ ok: true,
1496
+ credential_removed: credentialRemoved,
1497
+ token_store: tokenStore
1498
+ };
1499
+ }
1469
1500
  function parseStoredProfileCredential(raw) {
1470
1501
  if (!raw) return {
1471
1502
  ok: false,
@@ -1566,6 +1597,15 @@ function macosKeychain() {
1566
1597
  "-w",
1567
1598
  securityQuote(token)
1568
1599
  ].join(" ")}\n`)).status === 0;
1600
+ },
1601
+ delete: async (account) => {
1602
+ return (await spawnFile("security", [
1603
+ "delete-generic-password",
1604
+ "-s",
1605
+ SERVICE,
1606
+ "-a",
1607
+ account
1608
+ ])).status === 0;
1569
1609
  }
1570
1610
  };
1571
1611
  }
@@ -1596,9 +1636,34 @@ async function linuxSecretService() {
1596
1636
  "account",
1597
1637
  account
1598
1638
  ], token)).status === 0;
1639
+ },
1640
+ delete: async (account) => {
1641
+ return (await spawnFile("secret-tool", [
1642
+ "clear",
1643
+ "service",
1644
+ SERVICE,
1645
+ "account",
1646
+ account
1647
+ ])).status === 0;
1599
1648
  }
1600
1649
  };
1601
1650
  }
1651
+ async function deletePlaintextTokenAccount(account) {
1652
+ const tokens = await readPlaintextTokens();
1653
+ if (!tokens || !Object.hasOwn(tokens, account)) return false;
1654
+ const home = configHome();
1655
+ if (!home) return false;
1656
+ const { [account]: _removed, ...rest } = tokens;
1657
+ await mkdir(home, {
1658
+ recursive: true,
1659
+ mode: 448
1660
+ });
1661
+ const path = plaintextTokensPath(home);
1662
+ if (Object.keys(rest).length === 0) await writeFile(path, "{}\n", { mode: 384 });
1663
+ else await writeFile(path, `${JSON.stringify(rest, null, 2)}\n`, { mode: 384 });
1664
+ await chmod(path, 384);
1665
+ return true;
1666
+ }
1602
1667
  async function readPlaintextToken(account) {
1603
1668
  const token = (await readPlaintextTokens())?.[account];
1604
1669
  return typeof token === "string" && token ? token : null;
@@ -3679,6 +3744,45 @@ function configData(config, resolved) {
3679
3744
  };
3680
3745
  }
3681
3746
  //#endregion
3747
+ //#region src/command-runners/profile-credentials.ts
3748
+ async function deleteCredentialForProfileEntry(profile, rawEntry, options) {
3749
+ const entry = isRecord(rawEntry) ? rawEntry : {};
3750
+ return await deleteProfileCredential(profile, {
3751
+ ...options,
3752
+ baseUrl: nonEmpty(entry.base_url) ?? "https://artifactshare.com"
3753
+ });
3754
+ }
3755
+ //#endregion
3756
+ //#region src/command-runners/logout.ts
3757
+ async function runLogout(parsed, mode) {
3758
+ const command = "logout";
3759
+ const explicitProfile = nonEmpty(parsed.options.profile);
3760
+ if (!configHome()) return writeFailure(command, tokenStoreUnavailableError(), mode, 1);
3761
+ const config = await readGlobalConfig() ?? {};
3762
+ let profile;
3763
+ if (explicitProfile) {
3764
+ if (!Object.hasOwn(config.profiles ?? {}, explicitProfile)) return writeFailure(command, profileNotFoundError(explicitProfile), mode, 1);
3765
+ profile = explicitProfile;
3766
+ } else {
3767
+ const defaultProfile = nonEmpty(config.default_profile);
3768
+ if (!defaultProfile) {
3769
+ const optionToken = nonEmpty(parsed.options.token);
3770
+ const envToken = nonEmpty(process.env.ARTIFACTSHARE_TOKEN);
3771
+ return writeFailure(command, validationError("No profile is selected for logout.", optionToken || envToken ? `Bearer-token-only auth has no local credential to remove. Pass --profile <name>, set a default profile with ${CLI_INVOCATION} profiles use <name>, or unset ${TOKEN_ENV_VAR} before retrying.` : `Pass --profile <name> or run ${CLI_INVOCATION} profiles use <name> first.`), mode, 1);
3772
+ }
3773
+ if (!Object.hasOwn(config.profiles ?? {}, defaultProfile)) return writeFailure(command, profileNotFoundError(defaultProfile), mode, 1);
3774
+ profile = defaultProfile;
3775
+ }
3776
+ const rawEntry = config.profiles?.[profile];
3777
+ const deleted = await deleteCredentialForProfileEntry(profile, rawEntry, parsed.options);
3778
+ if (!deleted.ok) return writeFailure(command, tokenStoreUnavailableError(profile), mode, 1);
3779
+ return writeSuccess(command, {
3780
+ profile,
3781
+ credential_removed: deleted.credential_removed,
3782
+ token_store: deleted.token_store
3783
+ }, mode);
3784
+ }
3785
+ //#endregion
3682
3786
  //#region src/command-runners/move.ts
3683
3787
  async function runMove(parsed, mode) {
3684
3788
  const command = "move";
@@ -3823,6 +3927,33 @@ async function runProfilesImportToken(parsed, mode) {
3823
3927
  base_url: baseUrlOf(parsed.options)
3824
3928
  }, mode);
3825
3929
  }
3930
+ async function runProfilesDelete(parsed, mode) {
3931
+ const command = "profiles delete";
3932
+ const name = nonEmpty(parsed.positionals[0]);
3933
+ if (!name) return writeFailure(command, validationError("A profile name is required.", `Run ${CLI_INVOCATION} profiles delete <name>.`), mode, 1);
3934
+ if (!configHome()) return writeFailure(command, tokenStoreUnavailableError(), mode, 1);
3935
+ const config = await readGlobalConfig() ?? {};
3936
+ if (!Object.hasOwn(config.profiles ?? {}, name)) return writeFailure(command, profileNotFoundError(name), mode, 1);
3937
+ const rawEntry = config.profiles?.[name];
3938
+ const deleted = await deleteCredentialForProfileEntry(name, rawEntry, parsed.options);
3939
+ if (!deleted.ok) return writeFailure(command, tokenStoreUnavailableError(name), mode, 1);
3940
+ const previousDefault = nonEmpty(config.default_profile) ?? null;
3941
+ const { [name]: _removed, ...restProfiles } = config.profiles ?? {};
3942
+ const defaultProfile = config.default_profile === name ? null : config.default_profile ?? null;
3943
+ await writeGlobalConfig({
3944
+ ...config,
3945
+ default_profile: defaultProfile,
3946
+ profiles: restProfiles
3947
+ });
3948
+ return writeSuccess(command, {
3949
+ profile: name,
3950
+ credential_removed: deleted.credential_removed,
3951
+ token_store: deleted.token_store,
3952
+ profile_deleted: true,
3953
+ previous_default: previousDefault,
3954
+ default_profile: defaultProfile
3955
+ }, mode);
3956
+ }
3826
3957
  //#endregion
3827
3958
  //#region src/command-runners/projects.ts
3828
3959
  async function fetchProjects(token, options, init, errorOptions = {}) {
@@ -4236,6 +4367,10 @@ async function loginRunner(ctx) {
4236
4367
  const parsed = parsedArgsFromContext("login", ctx);
4237
4368
  return await runLogin(parsed, outputMode(parsed.options));
4238
4369
  }
4370
+ async function logoutRunner(ctx) {
4371
+ const parsed = parsedArgsFromContext("logout", ctx);
4372
+ return await runLogout(parsed, outputMode(parsed.options));
4373
+ }
4239
4374
  async function updateRunner(ctx) {
4240
4375
  const parsed = parsedArgsFromContext("update", ctx);
4241
4376
  return await runUpdate(parsed, outputMode(parsed.options));
@@ -4317,6 +4452,10 @@ async function profilesImportTokenRunner(ctx) {
4317
4452
  if (hasOptionToken(ctx, "token")) parsed.options.token = "<redacted>";
4318
4453
  return await runProfilesImportToken(parsed, outputMode(parsed.options));
4319
4454
  }
4455
+ async function profilesDeleteRunner(ctx) {
4456
+ const parsed = parsedArgsFromContext("profiles delete", ctx);
4457
+ return await runProfilesDelete(parsed, outputMode(parsed.options));
4458
+ }
4320
4459
  async function projectsListRunner(ctx) {
4321
4460
  const parsed = parsedArgsFromContext("projects list", ctx);
4322
4461
  return await runProjectsList(parsed, outputMode(parsed.options));
@@ -4404,6 +4543,7 @@ async function runGunshi(argv) {
4404
4543
  version: await loadCliVersion(),
4405
4544
  subCommands: {
4406
4545
  login: lazyCommand(loginDefinition, loginRunner),
4546
+ logout: lazyCommand(logoutDefinition, logoutRunner),
4407
4547
  share: lazyCommand(shareDefinition, shareRunner),
4408
4548
  open: lazyCommand(openDefinition, openRunner),
4409
4549
  update: lazyCommand(updateDefinition, updateRunner),
@@ -4483,6 +4623,7 @@ npx --yes @artifactshare/cli comments list <artifact-id-or-url> --json
4483
4623
  npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json
4484
4624
  ${agentDownloadCommand("<artifact-id-or-url>")}
4485
4625
  npx --yes @artifactshare/cli login --profile default
4626
+ npx --yes @artifactshare/cli logout --profile default --json
4486
4627
  npx --yes @artifactshare/cli profiles list --json
4487
4628
  npx --yes @artifactshare/cli profiles use <name> --json
4488
4629
  npx --yes @artifactshare/cli projects list --json
@@ -4522,6 +4663,22 @@ Common failures:
4522
4663
  auth_expired The device code expired before approval
4523
4664
  token_store_unavailable Configure an OS credential store or use the explicit plaintext fallback`
4524
4665
  });
4666
+ const logoutDefinition = define({
4667
+ name: "logout",
4668
+ description: "Remove the saved credential for a CLI profile.",
4669
+ toKebab: true,
4670
+ args: commonArgs,
4671
+ examples: `npx --yes @artifactshare/cli logout --profile client-a --json
4672
+ npx --yes @artifactshare/cli logout --json
4673
+
4674
+ logout removes the local credential only. Profile metadata stays in config.json for re-login hints.
4675
+ When no --profile is passed, the global default profile is used.
4676
+
4677
+ Common failures:
4678
+ validation_failed Pass --profile or set a default profile; bearer-token-only auth has nothing to remove
4679
+ profile_not_found Run profiles list to see saved profiles
4680
+ token_store_unavailable Configure an OS credential store or use the explicit plaintext fallback`
4681
+ });
4525
4682
  const shareDefinition = define({
4526
4683
  name: "share",
4527
4684
  description: "Share a file or directory.",
@@ -5126,6 +5283,20 @@ Common failures:
5126
5283
  auth_account_mismatch The token belongs to a different account than the saved profile email
5127
5284
  token_store_unavailable Configure an OS credential store or use the explicit plaintext fallback`
5128
5285
  });
5286
+ const profilesDeleteDefinition = define({
5287
+ name: "delete",
5288
+ description: "Delete a saved CLI profile and its credential.",
5289
+ toKebab: true,
5290
+ args: commonArgs,
5291
+ examples: `npx --yes @artifactshare/cli profiles delete client-a --json
5292
+
5293
+ Removes the profile from config.json and clears its saved credential.
5294
+ If the deleted profile was the default, default_profile becomes null.
5295
+
5296
+ Common failures:
5297
+ profile_not_found Run profiles list to see saved profiles
5298
+ token_store_unavailable Credential removal failed; the profile entry is kept`
5299
+ });
5129
5300
  const profilesDefinition = define({
5130
5301
  name: "profiles",
5131
5302
  description: "Manage saved CLI profiles.",
@@ -5134,11 +5305,13 @@ const profilesDefinition = define({
5134
5305
  subCommands: {
5135
5306
  list: lazyCommand(profilesListDefinition, profilesListRunner),
5136
5307
  use: lazyCommand(profilesUseDefinition, profilesUseRunner),
5137
- "import-token": lazyCommand(profilesImportTokenDefinition, profilesImportTokenRunner)
5308
+ "import-token": lazyCommand(profilesImportTokenDefinition, profilesImportTokenRunner),
5309
+ delete: lazyCommand(profilesDeleteDefinition, profilesDeleteRunner)
5138
5310
  },
5139
5311
  examples: `npx --yes @artifactshare/cli profiles list --json
5140
5312
  npx --yes @artifactshare/cli profiles use client-a --json
5141
- printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile client-a --json`,
5313
+ printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile client-a --json
5314
+ npx --yes @artifactshare/cli profiles delete client-a --json`,
5142
5315
  run: parentCommandRunner("profiles")
5143
5316
  });
5144
5317
  const projectsListDefinition = define({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artifactshare/cli",
3
- "version": "0.4.1",
3
+ "version": "0.5.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
  "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: 19
7
+ version: 20
8
8
  managed: true
9
9
  -->
10
10
 
@@ -42,6 +42,7 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
42
42
  | Create a project | `projects create 'Name' --json` |
43
43
  | Find an ID from a title | `resolve <value> --json` |
44
44
  | Open a share URL | `open <url> --json` |
45
+ | Log out locally | `logout --profile <name> --json` |
45
46
 
46
47
  ## Authentication
47
48
 
@@ -52,6 +53,9 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
52
53
  browser for approval. Use it when a user is present; the pending event on
53
54
  stderr includes `browser_open`. Do not pass API tokens to `login`.
54
55
  Profiles created by `login` renew expired CLI sessions automatically.
56
+ - `logout --profile <name> --json` removes the saved local credential for a
57
+ profile and leaves profile metadata in `config.json`. Without `--profile`,
58
+ it uses the default profile. This does not revoke API tokens on the server.
55
59
  - To keep using an issued token as a named profile without TTY or browser
56
60
  login, pipe it on standard input:
57
61
  `printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile <name> --json`.
@@ -195,10 +199,13 @@ npx --yes @artifactshare/cli projects edit <id> --archive --json
195
199
  ```bash
196
200
  npx --yes @artifactshare/cli profiles list --json
197
201
  npx --yes @artifactshare/cli profiles use <name> --json
202
+ npx --yes @artifactshare/cli profiles delete <name> --json
198
203
  ```
199
204
 
200
205
  - `profiles list` shows saved profiles and the default.
201
206
  - `profiles use` switches the default profile.
207
+ - `profiles delete` removes the profile entry and its saved credential. Use
208
+ `logout --profile <name>` when you only want to remove the credential.
202
209
  - To create a profile, use `login --profile <name>` (interactive) or
203
210
  `profiles import-token` (non-interactive, see Authentication).
204
211
 
@@ -4,7 +4,7 @@ alwaysApply: false
4
4
  ---
5
5
 
6
6
  <!-- artifactshare-skill
7
- version: 19
7
+ version: 20
8
8
  managed: true
9
9
  -->
10
10
 
@@ -27,7 +27,8 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
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
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
- - Switch profiles with `profiles use <name> --json`; list with `profiles list --json`.
30
+ - Remove a saved local credential with `logout --profile <name> --json`; this keeps profile metadata and does not revoke API tokens on the server.
31
+ - Switch profiles with `profiles use <name> --json`; list with `profiles list --json`; remove a profile entry and its credential with `profiles delete <name> --json`.
31
32
  - 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
33
  - 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`.
33
34
  - For repeat jobs with a stable caller-owned name, use `share <path> --key <key> --json`: the first run creates the artifact, later runs add versions to the same artifact.