@artifactshare/cli 0.4.1 → 0.5.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/README.md +4 -3
- package/dist/index.js +424 -144
- package/package.json +7 -7
- package/skills/artifactshare/SKILL.md +29 -14
- package/skills/artifactshare/artifactshare.mdc +21 -8
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`
|
|
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`
|
|
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
|
@@ -14,18 +14,18 @@ const CLI_INVOCATION = "npx --yes @artifactshare/cli";
|
|
|
14
14
|
const AGENT_DOWNLOAD_OUTPUT = "./artifact";
|
|
15
15
|
const TOKEN_ENV_VAR = "ARTIFACTSHARE_TOKEN";
|
|
16
16
|
const TOKEN_OPTION = "--token";
|
|
17
|
-
const IGNORED_FILENAMES = new Set([
|
|
17
|
+
const IGNORED_FILENAMES = /* @__PURE__ */ new Set([
|
|
18
18
|
".DS_Store",
|
|
19
19
|
"Thumbs.db",
|
|
20
20
|
"desktop.ini"
|
|
21
21
|
]);
|
|
22
|
-
const EXCLUDED_DIR_NAMES = new Set([
|
|
22
|
+
const EXCLUDED_DIR_NAMES = /* @__PURE__ */ new Set([
|
|
23
23
|
"node_modules",
|
|
24
24
|
".git",
|
|
25
25
|
".artifactshare",
|
|
26
26
|
".turbo"
|
|
27
27
|
]);
|
|
28
|
-
const BOOLEAN_FLAGS = new Set([
|
|
28
|
+
const BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
|
|
29
29
|
"allow-plaintext-token-store",
|
|
30
30
|
"archive",
|
|
31
31
|
"dry-run",
|
|
@@ -36,7 +36,7 @@ const BOOLEAN_FLAGS = new Set([
|
|
|
36
36
|
"insecure-localhost",
|
|
37
37
|
"unarchive"
|
|
38
38
|
]);
|
|
39
|
-
const VALUE_FLAGS = new Set([
|
|
39
|
+
const VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
40
40
|
"add-email",
|
|
41
41
|
"agent",
|
|
42
42
|
"base-url",
|
|
@@ -67,8 +67,9 @@ const VALUE_FLAGS = new Set([
|
|
|
67
67
|
"tool",
|
|
68
68
|
"visibility"
|
|
69
69
|
]);
|
|
70
|
-
const COMMAND_NAMES = new Set([
|
|
70
|
+
const COMMAND_NAMES = /* @__PURE__ */ 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",
|
|
@@ -115,7 +117,7 @@ const SUBCOMMANDS = {
|
|
|
115
117
|
"ensure"
|
|
116
118
|
]
|
|
117
119
|
};
|
|
118
|
-
const UPDATE_OPTION_KEYS = new Set([
|
|
120
|
+
const UPDATE_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
119
121
|
"allowPlaintextTokenStore",
|
|
120
122
|
"baseUrl",
|
|
121
123
|
"help",
|
|
@@ -320,6 +322,15 @@ function mapApiError(status, body, options = {}) {
|
|
|
320
322
|
requiresHuman: false,
|
|
321
323
|
recovery: { kind: "change_input" }
|
|
322
324
|
});
|
|
325
|
+
if (apiCode === "project-limit-reached") return cliError({
|
|
326
|
+
code: "project_limit_reached",
|
|
327
|
+
message: apiMessage ?? "You've reached your plan's project limit. Upgrade your plan or archive existing projects.",
|
|
328
|
+
why: "The workspace already has the maximum number of active projects allowed by its plan.",
|
|
329
|
+
hint: "Archive an existing project, upgrade the workspace plan, or choose a different project.",
|
|
330
|
+
agentRecoverable: false,
|
|
331
|
+
requiresHuman: true,
|
|
332
|
+
recovery: { kind: "change_input" }
|
|
333
|
+
});
|
|
323
334
|
if (apiCode === "forbidden" || status === 403) return cliError({
|
|
324
335
|
code: "forbidden",
|
|
325
336
|
message: apiMessage ?? "You do not have permission to do that.",
|
|
@@ -435,6 +446,16 @@ function mapApiError(status, body, options = {}) {
|
|
|
435
446
|
requiresHuman: false,
|
|
436
447
|
recovery: { kind: "retry_later" }
|
|
437
448
|
});
|
|
449
|
+
if (apiCode === "maintenance") return cliError({
|
|
450
|
+
code: "maintenance",
|
|
451
|
+
message: apiMessage ?? "Artifact Share is currently under maintenance.",
|
|
452
|
+
why: "Artifact Share is temporarily unavailable while maintenance is in progress.",
|
|
453
|
+
hint: "Retry the same command in a few minutes.",
|
|
454
|
+
agentRecoverable: true,
|
|
455
|
+
requiresHuman: false,
|
|
456
|
+
recovery: { kind: "retry_later" },
|
|
457
|
+
details: { status }
|
|
458
|
+
});
|
|
438
459
|
return cliError({
|
|
439
460
|
code: "service_error",
|
|
440
461
|
message: apiMessage ?? `Artifact Share returned HTTP ${status}.`,
|
|
@@ -1466,6 +1487,35 @@ async function saveProfileCredential(profile, credential, options) {
|
|
|
1466
1487
|
reason: "unavailable"
|
|
1467
1488
|
};
|
|
1468
1489
|
}
|
|
1490
|
+
async function deleteProfileCredential(profile, options) {
|
|
1491
|
+
const account = accountName(profile, baseUrlOf(options));
|
|
1492
|
+
let credentialRemoved = false;
|
|
1493
|
+
let tokenStore = null;
|
|
1494
|
+
const native = await nativeStore();
|
|
1495
|
+
if (native) {
|
|
1496
|
+
if (await native.read(account)) {
|
|
1497
|
+
if (!await native.delete(account)) return {
|
|
1498
|
+
ok: false,
|
|
1499
|
+
reason: "unavailable"
|
|
1500
|
+
};
|
|
1501
|
+
credentialRemoved = true;
|
|
1502
|
+
tokenStore = native.kind;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
if (await readPlaintextToken(account) !== null) {
|
|
1506
|
+
if (!await deletePlaintextTokenAccount(account)) return {
|
|
1507
|
+
ok: false,
|
|
1508
|
+
reason: "unavailable"
|
|
1509
|
+
};
|
|
1510
|
+
credentialRemoved = true;
|
|
1511
|
+
tokenStore ??= "plaintext_file";
|
|
1512
|
+
}
|
|
1513
|
+
return {
|
|
1514
|
+
ok: true,
|
|
1515
|
+
credential_removed: credentialRemoved,
|
|
1516
|
+
token_store: tokenStore
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1469
1519
|
function parseStoredProfileCredential(raw) {
|
|
1470
1520
|
if (!raw) return {
|
|
1471
1521
|
ok: false,
|
|
@@ -1566,6 +1616,15 @@ function macosKeychain() {
|
|
|
1566
1616
|
"-w",
|
|
1567
1617
|
securityQuote(token)
|
|
1568
1618
|
].join(" ")}\n`)).status === 0;
|
|
1619
|
+
},
|
|
1620
|
+
delete: async (account) => {
|
|
1621
|
+
return (await spawnFile("security", [
|
|
1622
|
+
"delete-generic-password",
|
|
1623
|
+
"-s",
|
|
1624
|
+
SERVICE,
|
|
1625
|
+
"-a",
|
|
1626
|
+
account
|
|
1627
|
+
])).status === 0;
|
|
1569
1628
|
}
|
|
1570
1629
|
};
|
|
1571
1630
|
}
|
|
@@ -1596,9 +1655,34 @@ async function linuxSecretService() {
|
|
|
1596
1655
|
"account",
|
|
1597
1656
|
account
|
|
1598
1657
|
], token)).status === 0;
|
|
1658
|
+
},
|
|
1659
|
+
delete: async (account) => {
|
|
1660
|
+
return (await spawnFile("secret-tool", [
|
|
1661
|
+
"clear",
|
|
1662
|
+
"service",
|
|
1663
|
+
SERVICE,
|
|
1664
|
+
"account",
|
|
1665
|
+
account
|
|
1666
|
+
])).status === 0;
|
|
1599
1667
|
}
|
|
1600
1668
|
};
|
|
1601
1669
|
}
|
|
1670
|
+
async function deletePlaintextTokenAccount(account) {
|
|
1671
|
+
const tokens = await readPlaintextTokens();
|
|
1672
|
+
if (!tokens || !Object.hasOwn(tokens, account)) return false;
|
|
1673
|
+
const home = configHome();
|
|
1674
|
+
if (!home) return false;
|
|
1675
|
+
const { [account]: _removed, ...rest } = tokens;
|
|
1676
|
+
await mkdir(home, {
|
|
1677
|
+
recursive: true,
|
|
1678
|
+
mode: 448
|
|
1679
|
+
});
|
|
1680
|
+
const path = plaintextTokensPath(home);
|
|
1681
|
+
if (Object.keys(rest).length === 0) await writeFile(path, "{}\n", { mode: 384 });
|
|
1682
|
+
else await writeFile(path, `${JSON.stringify(rest, null, 2)}\n`, { mode: 384 });
|
|
1683
|
+
await chmod(path, 384);
|
|
1684
|
+
return true;
|
|
1685
|
+
}
|
|
1602
1686
|
async function readPlaintextToken(account) {
|
|
1603
1687
|
const token = (await readPlaintextTokens())?.[account];
|
|
1604
1688
|
return typeof token === "string" && token ? token : null;
|
|
@@ -2178,7 +2262,7 @@ function whoamiProfile(body) {
|
|
|
2178
2262
|
}
|
|
2179
2263
|
//#endregion
|
|
2180
2264
|
//#region src/command-runners/auto-login.ts
|
|
2181
|
-
const JSON_PENDING_AUTH_COMMANDS = new Set([
|
|
2265
|
+
const JSON_PENDING_AUTH_COMMANDS = /* @__PURE__ */ new Set([
|
|
2182
2266
|
"share",
|
|
2183
2267
|
"update",
|
|
2184
2268
|
"download",
|
|
@@ -2218,12 +2302,9 @@ async function handleCredentialFailure(command, credential, options, mode, rerun
|
|
|
2218
2302
|
return rerun();
|
|
2219
2303
|
}
|
|
2220
2304
|
async function handleAuthenticatedCredentialFailure(command, error, credential, options, mode, rerun, isRetry = false) {
|
|
2221
|
-
|
|
2222
|
-
if (
|
|
2223
|
-
|
|
2224
|
-
if (refreshed.ok) return rerun();
|
|
2225
|
-
if (refreshed.error) return writeFailure(command, refreshed.error, mode, 1);
|
|
2226
|
-
}
|
|
2305
|
+
const refreshed = await refreshAuthenticatedCredential(error, credential, options, isRetry);
|
|
2306
|
+
if (refreshed.ok) return rerun();
|
|
2307
|
+
if (refreshed.error) return writeFailure(command, refreshed.error, mode, 1);
|
|
2227
2308
|
return await handleCredentialFailure(command, {
|
|
2228
2309
|
ok: false,
|
|
2229
2310
|
source: credential.source,
|
|
@@ -2231,6 +2312,33 @@ async function handleAuthenticatedCredentialFailure(command, error, credential,
|
|
|
2231
2312
|
error
|
|
2232
2313
|
}, options, mode, rerun, isRetry);
|
|
2233
2314
|
}
|
|
2315
|
+
async function refreshAuthenticatedCredential(error, credential, options, isRetry = false) {
|
|
2316
|
+
if (error.code !== "auth_required") return {
|
|
2317
|
+
ok: false,
|
|
2318
|
+
error
|
|
2319
|
+
};
|
|
2320
|
+
if (isRetry || !credential.profile || credential.profileCredentialKind !== "session" || !credential.refreshToken) return { ok: false };
|
|
2321
|
+
const refreshed = await refreshStoredProfileSession(credential.profile, credential.refreshToken, options);
|
|
2322
|
+
if (!refreshed.ok) return refreshed;
|
|
2323
|
+
return {
|
|
2324
|
+
ok: true,
|
|
2325
|
+
credential: {
|
|
2326
|
+
...credential,
|
|
2327
|
+
token: refreshed.token
|
|
2328
|
+
}
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
async function runAuthenticatedApi(credential, options, request) {
|
|
2332
|
+
const first = await request(credential);
|
|
2333
|
+
if (!first.error) return first;
|
|
2334
|
+
const refreshed = await refreshAuthenticatedCredential(first.error, credential, options);
|
|
2335
|
+
if (!refreshed.ok) return refreshed.error ? {
|
|
2336
|
+
error: first.error,
|
|
2337
|
+
originalError: first.error,
|
|
2338
|
+
refreshError: refreshed.error
|
|
2339
|
+
} : { error: first.error };
|
|
2340
|
+
return await request(refreshed.credential);
|
|
2341
|
+
}
|
|
2234
2342
|
async function refreshStoredProfileSession(profile, refreshToken, options) {
|
|
2235
2343
|
const request = await requestConfig(options);
|
|
2236
2344
|
if (request.error) return {
|
|
@@ -2263,7 +2371,10 @@ async function refreshStoredProfileSession(profile, refreshToken, options) {
|
|
|
2263
2371
|
ok: false,
|
|
2264
2372
|
error: tokenStoreUnavailableError(profile)
|
|
2265
2373
|
};
|
|
2266
|
-
return {
|
|
2374
|
+
return {
|
|
2375
|
+
ok: true,
|
|
2376
|
+
token: body.access_token
|
|
2377
|
+
};
|
|
2267
2378
|
}
|
|
2268
2379
|
async function handleJsonPendingAuth(command, credential, options, mode, rerun) {
|
|
2269
2380
|
const profile = profileForAutoLogin(credential);
|
|
@@ -2368,19 +2479,24 @@ async function runArtifactsList(parsed, mode) {
|
|
|
2368
2479
|
if (home) url.searchParams.set("project_id", "");
|
|
2369
2480
|
else if (projectId) url.searchParams.set("project_id", projectId);
|
|
2370
2481
|
if (query) url.searchParams.set("query", query);
|
|
2371
|
-
const
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2482
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
2483
|
+
const response = await fetch(url, {
|
|
2484
|
+
headers: { Authorization: `Bearer ${current.token}` },
|
|
2485
|
+
...request.init
|
|
2486
|
+
}).catch((error) => ({ networkError: error }));
|
|
2487
|
+
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
2488
|
+
const body = await readJson(response);
|
|
2489
|
+
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
2490
|
+
authenticated: true,
|
|
2491
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
2492
|
+
credentialSource: current.source,
|
|
2493
|
+
profile: current.profile,
|
|
2494
|
+
profileCredentialKind: current.profileCredentialKind
|
|
2495
|
+
}) };
|
|
2496
|
+
return { data: body };
|
|
2497
|
+
});
|
|
2498
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2499
|
+
const body = result.data;
|
|
2384
2500
|
if (!artifactsListSuccessFields(body)) return writeFailure(command, serviceError("Artifact list succeeded but the response did not include list metadata."), mode, 1);
|
|
2385
2501
|
return writeSuccess(command, body, mode);
|
|
2386
2502
|
}
|
|
@@ -2831,19 +2947,22 @@ async function runCommentsList(parsed, mode) {
|
|
|
2831
2947
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2832
2948
|
const request = await requestConfig(parsed.options);
|
|
2833
2949
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2834
|
-
const result = await
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2950
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
2951
|
+
const comments = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, parsed.options, request.init, {
|
|
2952
|
+
artifactTarget: true,
|
|
2953
|
+
credentialSource: current.source,
|
|
2954
|
+
profile: current.profile,
|
|
2955
|
+
profileCredentialKind: current.profileCredentialKind
|
|
2956
|
+
});
|
|
2957
|
+
return comments.error ? { error: comments.error } : { data: comments.body };
|
|
2839
2958
|
});
|
|
2840
2959
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2841
|
-
const comments = Array.isArray(result.
|
|
2960
|
+
const comments = Array.isArray(result.data?.comments) ? result.data.comments : [];
|
|
2842
2961
|
writeSuccess(command, {
|
|
2843
2962
|
artifact_id: artifactId,
|
|
2844
|
-
share_url: configString(result.
|
|
2963
|
+
share_url: configString(result.data?.share_url),
|
|
2845
2964
|
comments,
|
|
2846
|
-
has_more: result.
|
|
2965
|
+
has_more: result.data?.has_more === true
|
|
2847
2966
|
}, mode);
|
|
2848
2967
|
if (!mode.json && comments.length === 0) writeText("No comments yet.\n");
|
|
2849
2968
|
}
|
|
@@ -2863,28 +2982,31 @@ async function runCommentsPost(parsed, mode) {
|
|
|
2863
2982
|
const request = await requestConfig(parsed.options);
|
|
2864
2983
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2865
2984
|
const agent = parsed.options.agent;
|
|
2866
|
-
const result = await
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2985
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
2986
|
+
const posted = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, {
|
|
2987
|
+
body,
|
|
2988
|
+
reply_to: replyTo,
|
|
2989
|
+
quote,
|
|
2990
|
+
quote_before: parsed.options.quoteBefore,
|
|
2991
|
+
quote_after: parsed.options.quoteAfter,
|
|
2992
|
+
...agent ? { agent } : {}
|
|
2993
|
+
}, parsed.options, request.init, {
|
|
2994
|
+
artifactTarget: true,
|
|
2995
|
+
credentialSource: current.source,
|
|
2996
|
+
profile: current.profile,
|
|
2997
|
+
profileCredentialKind: current.profileCredentialKind
|
|
2998
|
+
});
|
|
2999
|
+
return posted.error ? { error: posted.error } : { data: posted.body };
|
|
2878
3000
|
});
|
|
2879
3001
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2880
|
-
const threadId = configString(result.
|
|
3002
|
+
const threadId = configString(result.data?.thread_id);
|
|
2881
3003
|
if (!threadId) return writeFailure(command, serviceError("Comment was saved but the response had no thread id."), mode, 1);
|
|
2882
3004
|
writeSuccess(command, {
|
|
2883
3005
|
artifact_id: artifactId,
|
|
2884
|
-
share_url: configString(result.
|
|
3006
|
+
share_url: configString(result.data?.share_url),
|
|
2885
3007
|
thread_id: threadId,
|
|
2886
|
-
reply: result.
|
|
2887
|
-
thread: result.
|
|
3008
|
+
reply: result.data?.reply === true,
|
|
3009
|
+
thread: result.data?.thread ?? null
|
|
2888
3010
|
}, mode);
|
|
2889
3011
|
}
|
|
2890
3012
|
async function runCommentsEdit(parsed, mode) {
|
|
@@ -2973,21 +3095,24 @@ async function postCommentAction(parsed, command, artifactId, payload, mode) {
|
|
|
2973
3095
|
writeFailure(command, request.error, mode, 1);
|
|
2974
3096
|
return null;
|
|
2975
3097
|
}
|
|
2976
|
-
const result = await
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
3098
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3099
|
+
const action = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, payload, parsed.options, request.init, {
|
|
3100
|
+
artifactTarget: true,
|
|
3101
|
+
credentialSource: current.source,
|
|
3102
|
+
profile: current.profile,
|
|
3103
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3104
|
+
});
|
|
3105
|
+
return action.error ? { error: action.error } : { data: action.body };
|
|
2981
3106
|
});
|
|
2982
3107
|
if (result.error) {
|
|
2983
3108
|
writeFailure(command, result.error, mode, 1);
|
|
2984
3109
|
return null;
|
|
2985
3110
|
}
|
|
2986
|
-
if (result.
|
|
3111
|
+
if (result.data === null) {
|
|
2987
3112
|
writeFailure(command, serviceError("Comment was changed but the response was empty."), mode, 1);
|
|
2988
3113
|
return null;
|
|
2989
3114
|
}
|
|
2990
|
-
return result.
|
|
3115
|
+
return result.data;
|
|
2991
3116
|
}
|
|
2992
3117
|
function requiredOption(value, message, hint) {
|
|
2993
3118
|
if (!value || !value.trim()) return { error: validationError(message, hint) };
|
|
@@ -3004,15 +3129,18 @@ async function runDelete(parsed, mode) {
|
|
|
3004
3129
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3005
3130
|
const request = await requestConfig(parsed.options);
|
|
3006
3131
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3007
|
-
const result = await
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3132
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3133
|
+
const deleted = await apiDelete(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, current.token, parsed.options, request.init, {
|
|
3134
|
+
authenticated: true,
|
|
3135
|
+
artifactTarget: true,
|
|
3136
|
+
credentialSource: current.source,
|
|
3137
|
+
profile: current.profile,
|
|
3138
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3139
|
+
});
|
|
3140
|
+
return deleted.error ? { error: deleted.error } : { data: deleted.body };
|
|
3013
3141
|
});
|
|
3014
3142
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3015
|
-
const body = result.
|
|
3143
|
+
const body = result.data;
|
|
3016
3144
|
if (!deleteSuccessFields(body)) return writeFailure(command, serviceError("Delete succeeded but the response did not include deletion metadata."), mode, 1);
|
|
3017
3145
|
return writeSuccess(command, body, mode);
|
|
3018
3146
|
}
|
|
@@ -3095,32 +3223,50 @@ async function runDoctor(parsed, mode) {
|
|
|
3095
3223
|
}
|
|
3096
3224
|
const request = await requestConfig(parsed.options);
|
|
3097
3225
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3098
|
-
const
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3226
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3227
|
+
const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
|
|
3228
|
+
headers: { Authorization: `Bearer ${current.token}` },
|
|
3229
|
+
...request.init
|
|
3230
|
+
}).catch((error) => ({ networkError: error }));
|
|
3231
|
+
if ("networkError" in response) return { data: {
|
|
3232
|
+
kind: "network_failed",
|
|
3233
|
+
hint: networkError(response.networkError).hint
|
|
3234
|
+
} };
|
|
3235
|
+
const body = await readJson(response);
|
|
3236
|
+
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
3237
|
+
authenticated: true,
|
|
3238
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
3239
|
+
credentialSource: current.source,
|
|
3240
|
+
profile: current.profile,
|
|
3241
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3242
|
+
}) };
|
|
3243
|
+
return { data: {
|
|
3244
|
+
kind: "body",
|
|
3245
|
+
body
|
|
3246
|
+
} };
|
|
3247
|
+
});
|
|
3248
|
+
if (result.error) {
|
|
3249
|
+
const authError = result.refreshError ? result.originalError ?? result.error : result.error;
|
|
3250
|
+
if (result.refreshError?.code === "network_failed") data.network = {
|
|
3104
3251
|
ok: false,
|
|
3105
3252
|
code: "network_failed",
|
|
3106
|
-
hint:
|
|
3253
|
+
hint: result.refreshError.hint
|
|
3107
3254
|
};
|
|
3255
|
+
else data.network.ok = true;
|
|
3256
|
+
data.auth.code = authError.code;
|
|
3257
|
+
data.auth.hint = authError.hint;
|
|
3108
3258
|
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
3109
3259
|
}
|
|
3110
|
-
data.
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
credentialSource: credential.source,
|
|
3117
|
-
profile: credential.profile,
|
|
3118
|
-
profileCredentialKind: credential.profileCredentialKind
|
|
3119
|
-
});
|
|
3120
|
-
data.auth.code = error.code;
|
|
3121
|
-
data.auth.hint = error.hint;
|
|
3260
|
+
if (result.data.kind === "network_failed") {
|
|
3261
|
+
data.network = {
|
|
3262
|
+
ok: false,
|
|
3263
|
+
code: "network_failed",
|
|
3264
|
+
hint: result.data.hint
|
|
3265
|
+
};
|
|
3122
3266
|
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
3123
3267
|
}
|
|
3268
|
+
data.network.ok = true;
|
|
3269
|
+
const body = result.data.body;
|
|
3124
3270
|
if (!body) throw new Error("Doctor response was not valid JSON.");
|
|
3125
3271
|
data.auth.ok = body.auth?.ok ?? true;
|
|
3126
3272
|
data.auth.email = body.user?.email ?? null;
|
|
@@ -3444,15 +3590,18 @@ async function runEdit(parsed, mode) {
|
|
|
3444
3590
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3445
3591
|
const request = await requestConfig(parsed.options);
|
|
3446
3592
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3447
|
-
const result = await
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3593
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3594
|
+
const edited = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/edit`, current.token, payload.body, parsed.options, request.init, {
|
|
3595
|
+
artifactTarget: true,
|
|
3596
|
+
editSettings: true,
|
|
3597
|
+
credentialSource: current.source,
|
|
3598
|
+
profile: current.profile,
|
|
3599
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3600
|
+
});
|
|
3601
|
+
return edited.error ? { error: edited.error } : { data: edited.body };
|
|
3453
3602
|
});
|
|
3454
3603
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3455
|
-
const data = parseEditData(result.
|
|
3604
|
+
const data = parseEditData(result.data);
|
|
3456
3605
|
if (!data) return writeFailure(command, serviceError("Edit succeeded but the response did not include edit data."), mode, 1);
|
|
3457
3606
|
writeSuccess(command, data, mode);
|
|
3458
3607
|
}
|
|
@@ -3679,6 +3828,45 @@ function configData(config, resolved) {
|
|
|
3679
3828
|
};
|
|
3680
3829
|
}
|
|
3681
3830
|
//#endregion
|
|
3831
|
+
//#region src/command-runners/profile-credentials.ts
|
|
3832
|
+
async function deleteCredentialForProfileEntry(profile, rawEntry, options) {
|
|
3833
|
+
const entry = isRecord(rawEntry) ? rawEntry : {};
|
|
3834
|
+
return await deleteProfileCredential(profile, {
|
|
3835
|
+
...options,
|
|
3836
|
+
baseUrl: nonEmpty(entry.base_url) ?? "https://artifactshare.com"
|
|
3837
|
+
});
|
|
3838
|
+
}
|
|
3839
|
+
//#endregion
|
|
3840
|
+
//#region src/command-runners/logout.ts
|
|
3841
|
+
async function runLogout(parsed, mode) {
|
|
3842
|
+
const command = "logout";
|
|
3843
|
+
const explicitProfile = nonEmpty(parsed.options.profile);
|
|
3844
|
+
if (!configHome()) return writeFailure(command, tokenStoreUnavailableError(), mode, 1);
|
|
3845
|
+
const config = await readGlobalConfig() ?? {};
|
|
3846
|
+
let profile;
|
|
3847
|
+
if (explicitProfile) {
|
|
3848
|
+
if (!Object.hasOwn(config.profiles ?? {}, explicitProfile)) return writeFailure(command, profileNotFoundError(explicitProfile), mode, 1);
|
|
3849
|
+
profile = explicitProfile;
|
|
3850
|
+
} else {
|
|
3851
|
+
const defaultProfile = nonEmpty(config.default_profile);
|
|
3852
|
+
if (!defaultProfile) {
|
|
3853
|
+
const optionToken = nonEmpty(parsed.options.token);
|
|
3854
|
+
const envToken = nonEmpty(process.env.ARTIFACTSHARE_TOKEN);
|
|
3855
|
+
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);
|
|
3856
|
+
}
|
|
3857
|
+
if (!Object.hasOwn(config.profiles ?? {}, defaultProfile)) return writeFailure(command, profileNotFoundError(defaultProfile), mode, 1);
|
|
3858
|
+
profile = defaultProfile;
|
|
3859
|
+
}
|
|
3860
|
+
const rawEntry = config.profiles?.[profile];
|
|
3861
|
+
const deleted = await deleteCredentialForProfileEntry(profile, rawEntry, parsed.options);
|
|
3862
|
+
if (!deleted.ok) return writeFailure(command, tokenStoreUnavailableError(profile), mode, 1);
|
|
3863
|
+
return writeSuccess(command, {
|
|
3864
|
+
profile,
|
|
3865
|
+
credential_removed: deleted.credential_removed,
|
|
3866
|
+
token_store: deleted.token_store
|
|
3867
|
+
}, mode);
|
|
3868
|
+
}
|
|
3869
|
+
//#endregion
|
|
3682
3870
|
//#region src/command-runners/move.ts
|
|
3683
3871
|
async function runMove(parsed, mode) {
|
|
3684
3872
|
const command = "move";
|
|
@@ -3693,14 +3881,17 @@ async function runMove(parsed, mode) {
|
|
|
3693
3881
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3694
3882
|
const request = await requestConfig(parsed.options);
|
|
3695
3883
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3696
|
-
const result = await
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3884
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3885
|
+
const moved = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/move`, current.token, { destination: home ? "home" : { project_id: projectId } }, parsed.options, request.init, {
|
|
3886
|
+
artifactTarget: true,
|
|
3887
|
+
credentialSource: current.source,
|
|
3888
|
+
profile: current.profile,
|
|
3889
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3890
|
+
});
|
|
3891
|
+
return moved.error ? { error: moved.error } : { data: moved.body };
|
|
3701
3892
|
});
|
|
3702
3893
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3703
|
-
const data = parseMoveData(result.
|
|
3894
|
+
const data = parseMoveData(result.data);
|
|
3704
3895
|
if (!data) return writeFailure(command, serviceError("Move succeeded but the response did not include move data."), mode, 1);
|
|
3705
3896
|
writeSuccess(command, data, mode);
|
|
3706
3897
|
}
|
|
@@ -3823,6 +4014,33 @@ async function runProfilesImportToken(parsed, mode) {
|
|
|
3823
4014
|
base_url: baseUrlOf(parsed.options)
|
|
3824
4015
|
}, mode);
|
|
3825
4016
|
}
|
|
4017
|
+
async function runProfilesDelete(parsed, mode) {
|
|
4018
|
+
const command = "profiles delete";
|
|
4019
|
+
const name = nonEmpty(parsed.positionals[0]);
|
|
4020
|
+
if (!name) return writeFailure(command, validationError("A profile name is required.", `Run ${CLI_INVOCATION} profiles delete <name>.`), mode, 1);
|
|
4021
|
+
if (!configHome()) return writeFailure(command, tokenStoreUnavailableError(), mode, 1);
|
|
4022
|
+
const config = await readGlobalConfig() ?? {};
|
|
4023
|
+
if (!Object.hasOwn(config.profiles ?? {}, name)) return writeFailure(command, profileNotFoundError(name), mode, 1);
|
|
4024
|
+
const rawEntry = config.profiles?.[name];
|
|
4025
|
+
const deleted = await deleteCredentialForProfileEntry(name, rawEntry, parsed.options);
|
|
4026
|
+
if (!deleted.ok) return writeFailure(command, tokenStoreUnavailableError(name), mode, 1);
|
|
4027
|
+
const previousDefault = nonEmpty(config.default_profile) ?? null;
|
|
4028
|
+
const { [name]: _removed, ...restProfiles } = config.profiles ?? {};
|
|
4029
|
+
const defaultProfile = config.default_profile === name ? null : config.default_profile ?? null;
|
|
4030
|
+
await writeGlobalConfig({
|
|
4031
|
+
...config,
|
|
4032
|
+
default_profile: defaultProfile,
|
|
4033
|
+
profiles: restProfiles
|
|
4034
|
+
});
|
|
4035
|
+
return writeSuccess(command, {
|
|
4036
|
+
profile: name,
|
|
4037
|
+
credential_removed: deleted.credential_removed,
|
|
4038
|
+
token_store: deleted.token_store,
|
|
4039
|
+
profile_deleted: true,
|
|
4040
|
+
previous_default: previousDefault,
|
|
4041
|
+
default_profile: defaultProfile
|
|
4042
|
+
}, mode);
|
|
4043
|
+
}
|
|
3826
4044
|
//#endregion
|
|
3827
4045
|
//#region src/command-runners/projects.ts
|
|
3828
4046
|
async function fetchProjects(token, options, init, errorOptions = {}) {
|
|
@@ -3848,14 +4066,17 @@ async function runProjectsList(parsed, mode) {
|
|
|
3848
4066
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3849
4067
|
const request = await requestConfig(parsed.options);
|
|
3850
4068
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3851
|
-
const result = await
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
4069
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4070
|
+
const fetched = await fetchProjects(current.token, parsed.options, request.init, {
|
|
4071
|
+
credentialSource: current.source,
|
|
4072
|
+
profile: current.profile,
|
|
4073
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4074
|
+
});
|
|
4075
|
+
return fetched.error ? { error: fetched.error } : { data: fetched.projects };
|
|
3855
4076
|
});
|
|
3856
4077
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3857
4078
|
const defaultProjectId = configString(projectConfig.config?.default_project_id);
|
|
3858
|
-
const projects = result.
|
|
4079
|
+
const projects = result.data.map((project) => ({
|
|
3859
4080
|
...project,
|
|
3860
4081
|
is_default: project.id === defaultProjectId
|
|
3861
4082
|
}));
|
|
@@ -3876,17 +4097,20 @@ async function runProjectsCreate(parsed, mode) {
|
|
|
3876
4097
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3877
4098
|
const request = await requestConfig(parsed.options);
|
|
3878
4099
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3879
|
-
const result = await
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
4100
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4101
|
+
const created = await apiPost("/api/cli/projects", current.token, {
|
|
4102
|
+
name,
|
|
4103
|
+
description: parsed.options.description ?? null,
|
|
4104
|
+
base_visibility: visibility ?? null
|
|
4105
|
+
}, parsed.options, request.init, {
|
|
4106
|
+
credentialSource: current.source,
|
|
4107
|
+
profile: current.profile,
|
|
4108
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4109
|
+
});
|
|
4110
|
+
return created.error ? { error: created.error } : { data: created.body };
|
|
3887
4111
|
});
|
|
3888
4112
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3889
|
-
const project = isRecord(result.
|
|
4113
|
+
const project = isRecord(result.data?.project) ? result.data.project : null;
|
|
3890
4114
|
const id = configString(project?.id);
|
|
3891
4115
|
if (!id) return writeFailure(command, serviceError("Project create succeeded but no project id was returned."), mode, 1);
|
|
3892
4116
|
writeSuccess(command, {
|
|
@@ -3910,14 +4134,17 @@ async function runProjectsEdit(parsed, mode) {
|
|
|
3910
4134
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3911
4135
|
const request = await requestConfig(parsed.options);
|
|
3912
4136
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3913
|
-
const result = await
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
4137
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4138
|
+
const edited = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, current.token, payload.body, parsed.options, request.init, {
|
|
4139
|
+
projectTarget: true,
|
|
4140
|
+
credentialSource: current.source,
|
|
4141
|
+
profile: current.profile,
|
|
4142
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4143
|
+
});
|
|
4144
|
+
return edited.error ? { error: edited.error } : { data: edited.body };
|
|
3918
4145
|
});
|
|
3919
4146
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3920
|
-
const data = parseProjectsEditData(result.
|
|
4147
|
+
const data = parseProjectsEditData(result.data);
|
|
3921
4148
|
if (!data) return writeFailure(command, serviceError("Project edit succeeded but the response did not include project data."), mode, 1);
|
|
3922
4149
|
writeSuccess(command, data, mode);
|
|
3923
4150
|
}
|
|
@@ -4109,13 +4336,16 @@ async function runRequestAccess(parsed, mode) {
|
|
|
4109
4336
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
4110
4337
|
const request = await requestConfig(parsed.options);
|
|
4111
4338
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4112
|
-
const result = await
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4339
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4340
|
+
const requested = await apiPost("/api/cli/request-access", current.token, { note }, parsed.options, request.init, {
|
|
4341
|
+
credentialSource: current.source,
|
|
4342
|
+
profile: current.profile,
|
|
4343
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4344
|
+
});
|
|
4345
|
+
return requested.error ? { error: requested.error } : { data: requested.body };
|
|
4116
4346
|
});
|
|
4117
4347
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
4118
|
-
const body = result.
|
|
4348
|
+
const body = result.data;
|
|
4119
4349
|
const data = {
|
|
4120
4350
|
requested: body?.requested === true,
|
|
4121
4351
|
already_enabled: body?.already_enabled === true,
|
|
@@ -4139,19 +4369,24 @@ async function runResolve(parsed, mode) {
|
|
|
4139
4369
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4140
4370
|
const url = apiUrl("/api/cli/resolve", baseUrlOf(parsed.options));
|
|
4141
4371
|
url.searchParams.set("q", value);
|
|
4142
|
-
const
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4372
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4373
|
+
const response = await fetch(url, {
|
|
4374
|
+
headers: { Authorization: `Bearer ${current.token}` },
|
|
4375
|
+
...request.init
|
|
4376
|
+
}).catch((error) => ({ networkError: error }));
|
|
4377
|
+
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
4378
|
+
const body = await readJson(response);
|
|
4379
|
+
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
4380
|
+
authenticated: true,
|
|
4381
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
4382
|
+
credentialSource: current.source,
|
|
4383
|
+
profile: current.profile,
|
|
4384
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4385
|
+
}) };
|
|
4386
|
+
return { data: body };
|
|
4387
|
+
});
|
|
4388
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
4389
|
+
const body = result.data;
|
|
4155
4390
|
if (!resolveSuccessFields(body)) return writeFailure(command, serviceError("Resolve succeeded but the response did not include query, candidates, and has_more."), mode, 1);
|
|
4156
4391
|
return writeSuccess(command, body, mode);
|
|
4157
4392
|
}
|
|
@@ -4215,14 +4450,17 @@ async function runWhoami(parsed, mode) {
|
|
|
4215
4450
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
4216
4451
|
const request = await requestConfig(parsed.options);
|
|
4217
4452
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4218
|
-
const whoami = await
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4453
|
+
const whoami = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4454
|
+
const result = await apiGet("/api/cli/whoami", current.token, parsed.options, request.init, {
|
|
4455
|
+
credentialSource: current.source,
|
|
4456
|
+
profile: current.profile,
|
|
4457
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4458
|
+
});
|
|
4459
|
+
return result.error ? { error: result.error } : { data: result.body };
|
|
4222
4460
|
});
|
|
4223
4461
|
if (whoami.error) return writeFailure(command, whoami.error, mode, 1);
|
|
4224
|
-
return writeSuccess(command, isRecord(whoami.
|
|
4225
|
-
...whoami.
|
|
4462
|
+
return writeSuccess(command, isRecord(whoami.data) ? {
|
|
4463
|
+
...whoami.data,
|
|
4226
4464
|
credential_source: credential.source
|
|
4227
4465
|
} : { credential_source: credential.source }, mode);
|
|
4228
4466
|
}
|
|
@@ -4236,6 +4474,10 @@ async function loginRunner(ctx) {
|
|
|
4236
4474
|
const parsed = parsedArgsFromContext("login", ctx);
|
|
4237
4475
|
return await runLogin(parsed, outputMode(parsed.options));
|
|
4238
4476
|
}
|
|
4477
|
+
async function logoutRunner(ctx) {
|
|
4478
|
+
const parsed = parsedArgsFromContext("logout", ctx);
|
|
4479
|
+
return await runLogout(parsed, outputMode(parsed.options));
|
|
4480
|
+
}
|
|
4239
4481
|
async function updateRunner(ctx) {
|
|
4240
4482
|
const parsed = parsedArgsFromContext("update", ctx);
|
|
4241
4483
|
return await runUpdate(parsed, outputMode(parsed.options));
|
|
@@ -4317,6 +4559,10 @@ async function profilesImportTokenRunner(ctx) {
|
|
|
4317
4559
|
if (hasOptionToken(ctx, "token")) parsed.options.token = "<redacted>";
|
|
4318
4560
|
return await runProfilesImportToken(parsed, outputMode(parsed.options));
|
|
4319
4561
|
}
|
|
4562
|
+
async function profilesDeleteRunner(ctx) {
|
|
4563
|
+
const parsed = parsedArgsFromContext("profiles delete", ctx);
|
|
4564
|
+
return await runProfilesDelete(parsed, outputMode(parsed.options));
|
|
4565
|
+
}
|
|
4320
4566
|
async function projectsListRunner(ctx) {
|
|
4321
4567
|
const parsed = parsedArgsFromContext("projects list", ctx);
|
|
4322
4568
|
return await runProjectsList(parsed, outputMode(parsed.options));
|
|
@@ -4404,6 +4650,7 @@ async function runGunshi(argv) {
|
|
|
4404
4650
|
version: await loadCliVersion(),
|
|
4405
4651
|
subCommands: {
|
|
4406
4652
|
login: lazyCommand(loginDefinition, loginRunner),
|
|
4653
|
+
logout: lazyCommand(logoutDefinition, logoutRunner),
|
|
4407
4654
|
share: lazyCommand(shareDefinition, shareRunner),
|
|
4408
4655
|
open: lazyCommand(openDefinition, openRunner),
|
|
4409
4656
|
update: lazyCommand(updateDefinition, updateRunner),
|
|
@@ -4483,6 +4730,7 @@ npx --yes @artifactshare/cli comments list <artifact-id-or-url> --json
|
|
|
4483
4730
|
npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json
|
|
4484
4731
|
${agentDownloadCommand("<artifact-id-or-url>")}
|
|
4485
4732
|
npx --yes @artifactshare/cli login --profile default
|
|
4733
|
+
npx --yes @artifactshare/cli logout --profile default --json
|
|
4486
4734
|
npx --yes @artifactshare/cli profiles list --json
|
|
4487
4735
|
npx --yes @artifactshare/cli profiles use <name> --json
|
|
4488
4736
|
npx --yes @artifactshare/cli projects list --json
|
|
@@ -4522,6 +4770,22 @@ Common failures:
|
|
|
4522
4770
|
auth_expired The device code expired before approval
|
|
4523
4771
|
token_store_unavailable Configure an OS credential store or use the explicit plaintext fallback`
|
|
4524
4772
|
});
|
|
4773
|
+
const logoutDefinition = define({
|
|
4774
|
+
name: "logout",
|
|
4775
|
+
description: "Remove the saved credential for a CLI profile.",
|
|
4776
|
+
toKebab: true,
|
|
4777
|
+
args: commonArgs,
|
|
4778
|
+
examples: `npx --yes @artifactshare/cli logout --profile client-a --json
|
|
4779
|
+
npx --yes @artifactshare/cli logout --json
|
|
4780
|
+
|
|
4781
|
+
logout removes the local credential only. Profile metadata stays in config.json for re-login hints.
|
|
4782
|
+
When no --profile is passed, the global default profile is used.
|
|
4783
|
+
|
|
4784
|
+
Common failures:
|
|
4785
|
+
validation_failed Pass --profile or set a default profile; bearer-token-only auth has nothing to remove
|
|
4786
|
+
profile_not_found Run profiles list to see saved profiles
|
|
4787
|
+
token_store_unavailable Configure an OS credential store or use the explicit plaintext fallback`
|
|
4788
|
+
});
|
|
4525
4789
|
const shareDefinition = define({
|
|
4526
4790
|
name: "share",
|
|
4527
4791
|
description: "Share a file or directory.",
|
|
@@ -5126,6 +5390,20 @@ Common failures:
|
|
|
5126
5390
|
auth_account_mismatch The token belongs to a different account than the saved profile email
|
|
5127
5391
|
token_store_unavailable Configure an OS credential store or use the explicit plaintext fallback`
|
|
5128
5392
|
});
|
|
5393
|
+
const profilesDeleteDefinition = define({
|
|
5394
|
+
name: "delete",
|
|
5395
|
+
description: "Delete a saved CLI profile and its credential.",
|
|
5396
|
+
toKebab: true,
|
|
5397
|
+
args: commonArgs,
|
|
5398
|
+
examples: `npx --yes @artifactshare/cli profiles delete client-a --json
|
|
5399
|
+
|
|
5400
|
+
Removes the profile from config.json and clears its saved credential.
|
|
5401
|
+
If the deleted profile was the default, default_profile becomes null.
|
|
5402
|
+
|
|
5403
|
+
Common failures:
|
|
5404
|
+
profile_not_found Run profiles list to see saved profiles
|
|
5405
|
+
token_store_unavailable Credential removal failed; the profile entry is kept`
|
|
5406
|
+
});
|
|
5129
5407
|
const profilesDefinition = define({
|
|
5130
5408
|
name: "profiles",
|
|
5131
5409
|
description: "Manage saved CLI profiles.",
|
|
@@ -5134,11 +5412,13 @@ const profilesDefinition = define({
|
|
|
5134
5412
|
subCommands: {
|
|
5135
5413
|
list: lazyCommand(profilesListDefinition, profilesListRunner),
|
|
5136
5414
|
use: lazyCommand(profilesUseDefinition, profilesUseRunner),
|
|
5137
|
-
"import-token": lazyCommand(profilesImportTokenDefinition, profilesImportTokenRunner)
|
|
5415
|
+
"import-token": lazyCommand(profilesImportTokenDefinition, profilesImportTokenRunner),
|
|
5416
|
+
delete: lazyCommand(profilesDeleteDefinition, profilesDeleteRunner)
|
|
5138
5417
|
},
|
|
5139
5418
|
examples: `npx --yes @artifactshare/cli profiles list --json
|
|
5140
5419
|
npx --yes @artifactshare/cli profiles use client-a --json
|
|
5141
|
-
printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile client-a --json
|
|
5420
|
+
printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile client-a --json
|
|
5421
|
+
npx --yes @artifactshare/cli profiles delete client-a --json`,
|
|
5142
5422
|
run: parentCommandRunner("profiles")
|
|
5143
5423
|
});
|
|
5144
5424
|
const projectsListDefinition = define({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artifactshare/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"artifactshare": "./dist/index.js"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=22"
|
|
22
|
+
"node": ">=22.19.0"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"gunshi": "^0.
|
|
35
|
-
"undici": "^
|
|
34
|
+
"gunshi": "^0.35.1",
|
|
35
|
+
"undici": "^8.5.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "
|
|
39
|
-
"tsdown": "^0.22.
|
|
38
|
+
"@types/node": "26.0.0",
|
|
39
|
+
"tsdown": "^0.22.3",
|
|
40
40
|
"typescript": "6.0.3",
|
|
41
|
-
"vitest": "4.1.
|
|
41
|
+
"vitest": "4.1.9"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsdown",
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: artifactshare
|
|
3
|
-
description:
|
|
3
|
+
description: Share, publish, upload, host, update, open, or read back existing files and Artifact Share URLs. Use when the user wants a browser link for an HTML/Markdown report, folder, static site, or generated file; wants to update the same URL; says Artifact Share, artifactshare, or contextual "as"; or asks to read comments from a shared URL.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- artifactshare-skill
|
|
7
|
-
version:
|
|
7
|
+
version: 22
|
|
8
8
|
managed: true
|
|
9
9
|
-->
|
|
10
10
|
|
|
11
11
|
# Artifact Share CLI
|
|
12
12
|
|
|
13
|
-
Artifact Share
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
Artifact Share is for the last step after a file already exists: share,
|
|
14
|
+
publish, upload, or host HTML pages, Markdown documents, folders, and static
|
|
15
|
+
sites; return a browser link; update the same URL; open or read back an
|
|
16
|
+
Artifact Share URL; and read or post comments. The CLI is designed for agents:
|
|
17
|
+
every command supports `--json` with a stable contract.
|
|
18
|
+
|
|
19
|
+
Use this skill for Artifact Share, artifactshare, and contextual "as" requests.
|
|
20
|
+
Japanese requests such as `as でアップして` or `as に上げて` are strong
|
|
21
|
+
Artifact Share intents. In English, treat "as" as a user shorthand only when
|
|
22
|
+
the surrounding request is about sharing, publishing, updating, opening, or
|
|
23
|
+
reading a shared URL; bare English "as" alone is not an Artifact Share trigger.
|
|
24
|
+
|
|
25
|
+
Do not use this skill just because the user says "artifact". Claude Artifact is
|
|
26
|
+
for creating or designing an artifact inside the chat. Artifact Share is for
|
|
27
|
+
sharing, updating, opening, or reading back existing files, folders, static
|
|
28
|
+
sites, and Artifact Share URLs.
|
|
17
29
|
|
|
18
30
|
Run commands with `npx --yes @artifactshare/cli`. When unsure about a
|
|
19
31
|
command or flag, run `npx --yes @artifactshare/cli <command> --help` first.
|
|
@@ -42,6 +54,7 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
42
54
|
| Create a project | `projects create 'Name' --json` |
|
|
43
55
|
| Find an ID from a title | `resolve <value> --json` |
|
|
44
56
|
| Open a share URL | `open <url> --json` |
|
|
57
|
+
| Log out locally | `logout --profile <name> --json` |
|
|
45
58
|
|
|
46
59
|
## Authentication
|
|
47
60
|
|
|
@@ -52,6 +65,9 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
52
65
|
browser for approval. Use it when a user is present; the pending event on
|
|
53
66
|
stderr includes `browser_open`. Do not pass API tokens to `login`.
|
|
54
67
|
Profiles created by `login` renew expired CLI sessions automatically.
|
|
68
|
+
- `logout --profile <name> --json` removes the saved local credential for a
|
|
69
|
+
profile and leaves profile metadata in `config.json`. Without `--profile`,
|
|
70
|
+
it uses the default profile. This does not revoke API tokens on the server.
|
|
55
71
|
- To keep using an issued token as a named profile without TTY or browser
|
|
56
72
|
login, pipe it on standard input:
|
|
57
73
|
`printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile <name> --json`.
|
|
@@ -70,7 +86,10 @@ npx --yes @artifactshare/cli share ./site-dir --project-id <id> --json
|
|
|
70
86
|
```
|
|
71
87
|
|
|
72
88
|
- `share` accepts a single `.html` / `.md` file or a static-site directory.
|
|
73
|
-
|
|
89
|
+
In JSON output, give the user `data.artifact.url`; the artifact ID is
|
|
90
|
+
`data.artifact.id`.
|
|
91
|
+
Do not rerun `share` just to inspect the JSON shape: without `--key`, each
|
|
92
|
+
successful run creates a new artifact.
|
|
74
93
|
- Pick the destination with `--project-id <id>`, `--project <name>` (by exact
|
|
75
94
|
name, no prior `resolve` needed), the saved default from `init`, or `--home`.
|
|
76
95
|
Without any of these it fails with `destination_required`.
|
|
@@ -195,10 +214,13 @@ npx --yes @artifactshare/cli projects edit <id> --archive --json
|
|
|
195
214
|
```bash
|
|
196
215
|
npx --yes @artifactshare/cli profiles list --json
|
|
197
216
|
npx --yes @artifactshare/cli profiles use <name> --json
|
|
217
|
+
npx --yes @artifactshare/cli profiles delete <name> --json
|
|
198
218
|
```
|
|
199
219
|
|
|
200
220
|
- `profiles list` shows saved profiles and the default.
|
|
201
221
|
- `profiles use` switches the default profile.
|
|
222
|
+
- `profiles delete` removes the profile entry and its saved credential. Use
|
|
223
|
+
`logout --profile <name>` when you only want to remove the credential.
|
|
202
224
|
- To create a profile, use `login --profile <name>` (interactive) or
|
|
203
225
|
`profiles import-token` (non-interactive, see Authentication).
|
|
204
226
|
|
|
@@ -228,13 +250,6 @@ npx --yes @artifactshare/cli skills list --json
|
|
|
228
250
|
`ask_human`, `report_issue`. When `error.requires_human` is true, report to
|
|
229
251
|
the user instead of retrying.
|
|
230
252
|
|
|
231
|
-
## Upload access
|
|
232
|
-
|
|
233
|
-
If `share` or `update` fails with `upload_not_allowed`, run
|
|
234
|
-
`request-access --note '<why>' --json` to join the waitlist, then tell the
|
|
235
|
-
user that sharing stays closed until an operator opens it. Do not retry
|
|
236
|
-
share in a loop.
|
|
237
|
-
|
|
238
253
|
## First-time setup
|
|
239
254
|
|
|
240
255
|
`npx --yes @artifactshare/cli init` detects the agent, installs or updates
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
2
|
+
description: Share, publish, upload, host, update, open, or read back existing files and Artifact Share URLs.
|
|
3
3
|
alwaysApply: false
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- artifactshare-skill
|
|
7
|
-
version:
|
|
7
|
+
version: 22
|
|
8
8
|
managed: true
|
|
9
9
|
-->
|
|
10
10
|
|
|
11
11
|
# Artifact Share CLI
|
|
12
12
|
|
|
13
|
-
Artifact Share
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
Artifact Share is for the last step after a file already exists: share,
|
|
14
|
+
publish, upload, or host HTML pages, Markdown documents, folders, and static
|
|
15
|
+
sites; return a browser link; update the same URL; open or read back an
|
|
16
|
+
Artifact Share URL; and read or post comments. Use
|
|
17
|
+
`npx --yes @artifactshare/cli` from the terminal.
|
|
16
18
|
Run `npx --yes @artifactshare/cli <command> --help` before choosing a command.
|
|
17
19
|
|
|
20
|
+
Use this rule for Artifact Share, artifactshare, and contextual "as" requests.
|
|
21
|
+
Japanese requests such as `as でアップして` or `as に上げて` are strong
|
|
22
|
+
Artifact Share intents. In English, treat "as" as a user shorthand only when
|
|
23
|
+
the surrounding request is about sharing, publishing, updating, opening, or
|
|
24
|
+
reading a shared URL; bare English "as" alone is not an Artifact Share trigger.
|
|
25
|
+
|
|
26
|
+
Do not use this rule just because the user says "artifact". Claude Artifact is
|
|
27
|
+
for creating or designing an artifact inside the chat. Artifact Share is for
|
|
28
|
+
sharing, updating, opening, or reading back existing files, folders, static
|
|
29
|
+
sites, and Artifact Share URLs.
|
|
30
|
+
|
|
18
31
|
Use the CLI for local files and folders. The remote MCP tools accept HTML or
|
|
19
32
|
Markdown source strings; they cannot read paths like `/Users/.../report.html`
|
|
20
33
|
from the user's filesystem.
|
|
@@ -27,9 +40,10 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
27
40
|
- 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
41
|
- 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
42
|
- 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
|
-
-
|
|
43
|
+
- Remove a saved local credential with `logout --profile <name> --json`; this keeps profile metadata and does not revoke API tokens on the server.
|
|
44
|
+
- 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
45
|
- 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
|
-
- 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`.
|
|
46
|
+
- 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. 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
47
|
- 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.
|
|
34
48
|
- To keep an existing share URL, do not use `share --artifact-id`; add a version with `update <artifact-id-or-url> <path> --json`. `update` does not change title, visibility, viewers, or placement.
|
|
35
49
|
- Read back with `artifacts get <target> --json`. Pass `--include versions` or `--include comments` to fetch history or comments in one call. If truncated, call again with `--offset` set to `next_offset`.
|
|
@@ -42,6 +56,5 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
42
56
|
- Manage projects: `projects list --json`, `projects create <name> --json` (defaults to `--visibility workspace`; pass `--visibility private` for confidential projects), `projects edit <id>` for name, description, visibility, audience (`--add-email`/`--remove-email`), and archive state (`--archive`/`--unarchive`).
|
|
43
57
|
- Save a default project with `init --project-id <id> --json`. Preview setup with `init --dry-run --json`.
|
|
44
58
|
- 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
|
-
- 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
59
|
- Check the current state with `whoami --json` or `doctor --json` for authentication, destination, network, upload access, and skill update status.
|
|
47
60
|
- 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).
|