@artis-lab/cli 0.12.0 → 0.13.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 +23 -10
- package/package.json +1 -1
- package/src/bin.js +7 -6
- package/src/index.js +11 -8
- package/src/lib/{chunk-YXGHBN47.js → chunk-2M77TQDV.js} +558 -229
- package/src/lib/chunk-43WVFZLO.js +104 -0
- package/src/lib/chunk-46DMRA3V.js +141 -0
- package/src/lib/{chunk-OBEJTKCR.js → chunk-JYLA7E3H.js} +7 -3
- package/src/lib/{chunk-KY47KP5E.js → chunk-JYMG2Y6C.js} +1 -1
- package/src/lib/{chunk-YAZGW7Y4.js → chunk-QZFIUZXT.js} +256 -83
- package/src/lib/cli.d.ts +38 -21
- package/src/lib/cli.js +11 -8
- package/src/lib/config.d.ts +31 -1
- package/src/lib/config.js +11 -3
- package/src/lib/files.js +1 -1
- package/src/lib/oauth.d.ts +45 -0
- package/src/lib/oauth.js +18 -0
- package/src/lib/revision-bases.js +2 -2
- package/src/lib/skill-install.d.ts +1 -1
- package/src/lib/skill-install.js +1 -1
- package/src/lib/verify.d.ts +27 -10
- package/src/lib/verify.js +3 -3
- package/src/lib/chunk-QNS7GLAA.js +0 -63
- /package/src/lib/{chunk-QDQQASRY.js → chunk-MEPQKMK5.js} +0 -0
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRememberedBase,
|
|
3
|
+
rememberBase
|
|
4
|
+
} from "./chunk-JYMG2Y6C.js";
|
|
1
5
|
import {
|
|
2
6
|
installSkillFromCli
|
|
3
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-JYLA7E3H.js";
|
|
4
8
|
import {
|
|
5
9
|
VerifyUnavailableError,
|
|
6
|
-
composeSlidesFiles,
|
|
7
10
|
formatVerifyReport,
|
|
8
|
-
|
|
11
|
+
verifyFiles,
|
|
9
12
|
verifyTypes
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-QZFIUZXT.js";
|
|
11
14
|
import {
|
|
12
15
|
artisCliVersion
|
|
13
16
|
} from "./chunk-IZYFOV2K.js";
|
|
@@ -15,11 +18,22 @@ import {
|
|
|
15
18
|
hasFlag,
|
|
16
19
|
parseFlagValue
|
|
17
20
|
} from "./chunk-U3ZF6SRR.js";
|
|
21
|
+
import {
|
|
22
|
+
ARTIS_DEFAULT_HOST,
|
|
23
|
+
findProfileForHost,
|
|
24
|
+
getConfigPath,
|
|
25
|
+
normalizeHost,
|
|
26
|
+
readCliConfig,
|
|
27
|
+
resolveOrigin,
|
|
28
|
+
saveDefaultProfile,
|
|
29
|
+
updateProfileTokens,
|
|
30
|
+
withConfigLock
|
|
31
|
+
} from "./chunk-46DMRA3V.js";
|
|
18
32
|
import {
|
|
19
33
|
changedFiles,
|
|
20
34
|
readFilesDir,
|
|
21
35
|
writeFilesDir
|
|
22
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-MEPQKMK5.js";
|
|
23
37
|
import {
|
|
24
38
|
CliError,
|
|
25
39
|
exitCodeForResponse,
|
|
@@ -27,17 +41,12 @@ import {
|
|
|
27
41
|
usageError
|
|
28
42
|
} from "./chunk-H32QAUSA.js";
|
|
29
43
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
getConfigPath,
|
|
37
|
-
normalizeHost,
|
|
38
|
-
readCliConfig,
|
|
39
|
-
saveDefaultProfile
|
|
40
|
-
} from "./chunk-QNS7GLAA.js";
|
|
44
|
+
OAuthError,
|
|
45
|
+
pollDeviceToken,
|
|
46
|
+
refreshTokens,
|
|
47
|
+
revokeToken,
|
|
48
|
+
startDeviceAuthorization
|
|
49
|
+
} from "./chunk-43WVFZLO.js";
|
|
41
50
|
|
|
42
51
|
// packages/cli/src/lib/cli.ts
|
|
43
52
|
import { spawn } from "node:child_process";
|
|
@@ -87,7 +96,10 @@ function buildRequest(baseUrl, key, input = {}) {
|
|
|
87
96
|
const search = query.toString();
|
|
88
97
|
const headers = {};
|
|
89
98
|
let body;
|
|
90
|
-
if (typeof
|
|
99
|
+
if (typeof Blob !== "undefined" && input.body instanceof Blob) {
|
|
100
|
+
headers["content-type"] = "application/octet-stream";
|
|
101
|
+
body = input.body;
|
|
102
|
+
} else if (typeof input.body === "string" || input.body instanceof Uint8Array) {
|
|
91
103
|
const bytes = typeof input.body === "string" ? new TextEncoder().encode(input.body) : input.body;
|
|
92
104
|
headers["content-type"] = htmlUploadContentType;
|
|
93
105
|
headers["content-length"] = String(bytes.byteLength);
|
|
@@ -106,6 +118,11 @@ function buildRequest(baseUrl, key, input = {}) {
|
|
|
106
118
|
};
|
|
107
119
|
}
|
|
108
120
|
async function readBody(response) {
|
|
121
|
+
if (/^application\/octet-stream\b/i.test(
|
|
122
|
+
response.headers.get("content-type") ?? ""
|
|
123
|
+
)) {
|
|
124
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
125
|
+
}
|
|
109
126
|
const text = await response.text();
|
|
110
127
|
if (!text) {
|
|
111
128
|
return void 0;
|
|
@@ -135,6 +152,9 @@ function createApiClient(options) {
|
|
|
135
152
|
input
|
|
136
153
|
);
|
|
137
154
|
const headers = init.headers;
|
|
155
|
+
for (const [name, value] of Object.entries(options.headers ?? {})) {
|
|
156
|
+
headers[name.toLowerCase()] ??= value;
|
|
157
|
+
}
|
|
138
158
|
if (options.auth && options.auth !== "cookie") {
|
|
139
159
|
headers["authorization"] = `Bearer ${options.auth.bearer}`;
|
|
140
160
|
}
|
|
@@ -212,9 +232,8 @@ var storageLimits = {
|
|
|
212
232
|
var encoder = new TextEncoder();
|
|
213
233
|
var storageOnlyCodes = /* @__PURE__ */ new Set([
|
|
214
234
|
"version_conflict",
|
|
215
|
-
"
|
|
235
|
+
"capability_not_declared",
|
|
216
236
|
"rules_changed",
|
|
217
|
-
"revision_stale",
|
|
218
237
|
"quota_exceeded",
|
|
219
238
|
"too_large",
|
|
220
239
|
"invalid_path",
|
|
@@ -311,6 +330,8 @@ var commands = [
|
|
|
311
330
|
"annotate",
|
|
312
331
|
"annotation",
|
|
313
332
|
"artifact",
|
|
333
|
+
"asset",
|
|
334
|
+
"capabilities",
|
|
314
335
|
"data",
|
|
315
336
|
"guidelines",
|
|
316
337
|
"help",
|
|
@@ -329,7 +350,6 @@ var cliVisibilityOptions = ["public", "unlisted", "private"];
|
|
|
329
350
|
var cliAnnotationStatusOptions = ["open", "resolved"];
|
|
330
351
|
var valueFlags = /* @__PURE__ */ new Set([
|
|
331
352
|
"--after",
|
|
332
|
-
"--api-key",
|
|
333
353
|
"--as-role",
|
|
334
354
|
"--depth",
|
|
335
355
|
"--idempotency-key",
|
|
@@ -337,9 +357,11 @@ var valueFlags = /* @__PURE__ */ new Set([
|
|
|
337
357
|
"--ops",
|
|
338
358
|
"--order",
|
|
339
359
|
"--patch",
|
|
360
|
+
"--self",
|
|
340
361
|
"--value",
|
|
341
362
|
"--author",
|
|
342
363
|
"--comment",
|
|
364
|
+
"--content-type",
|
|
343
365
|
"--css",
|
|
344
366
|
"--cursor",
|
|
345
367
|
"--description",
|
|
@@ -351,6 +373,7 @@ var valueFlags = /* @__PURE__ */ new Set([
|
|
|
351
373
|
// positional before rejectRemovedKindFlag() refuses it.
|
|
352
374
|
"--kind",
|
|
353
375
|
"--limit",
|
|
376
|
+
"--name",
|
|
354
377
|
"--output",
|
|
355
378
|
"--pin-label",
|
|
356
379
|
"--quote",
|
|
@@ -369,6 +392,8 @@ var valueFlags = /* @__PURE__ */ new Set([
|
|
|
369
392
|
"--status",
|
|
370
393
|
"--base",
|
|
371
394
|
"--capabilities",
|
|
395
|
+
// Removed (ADR 0025); still a value flag so its value is not read as a
|
|
396
|
+
// positional before rejectRemovedContractFlag() refuses it.
|
|
372
397
|
"--contract",
|
|
373
398
|
"--summary",
|
|
374
399
|
"--tag",
|
|
@@ -408,7 +433,7 @@ function parseVisibility(value) {
|
|
|
408
433
|
`Invalid visibility "${value}". Expected one of: ${cliVisibilityOptions.join(", ")}`
|
|
409
434
|
);
|
|
410
435
|
}
|
|
411
|
-
async function parseCapabilitiesFlag(value) {
|
|
436
|
+
async function parseCapabilitiesFlag(value, flag = "--capabilities") {
|
|
412
437
|
if (value === void 0) {
|
|
413
438
|
return void 0;
|
|
414
439
|
}
|
|
@@ -418,7 +443,7 @@ async function parseCapabilitiesFlag(value) {
|
|
|
418
443
|
source = await readFile(value, "utf8");
|
|
419
444
|
} catch {
|
|
420
445
|
throw usageError(
|
|
421
|
-
|
|
446
|
+
`${flag} must be a JSON object or a path to a JSON file; could not read "${value}".`
|
|
422
447
|
);
|
|
423
448
|
}
|
|
424
449
|
}
|
|
@@ -426,28 +451,21 @@ async function parseCapabilitiesFlag(value) {
|
|
|
426
451
|
try {
|
|
427
452
|
parsed = JSON.parse(source);
|
|
428
453
|
} catch {
|
|
429
|
-
throw usageError(
|
|
454
|
+
throw usageError(`${flag} is not valid JSON.`);
|
|
430
455
|
}
|
|
431
456
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
432
457
|
throw usageError(
|
|
433
|
-
|
|
458
|
+
`${flag} must be a JSON object, e.g. '{"<name>":true}' ({} clears them).`
|
|
434
459
|
);
|
|
435
460
|
}
|
|
436
461
|
return parsed;
|
|
437
462
|
}
|
|
438
|
-
function
|
|
439
|
-
if (
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return value;
|
|
444
|
-
}
|
|
445
|
-
if (/^\d+$/.test(value)) {
|
|
446
|
-
return Number(value);
|
|
463
|
+
function rejectRemovedContractFlag(args) {
|
|
464
|
+
if (args.includes("--contract")) {
|
|
465
|
+
throw usageError(
|
|
466
|
+
"--contract was removed: there is one page contract, and every page gets the `artis` global."
|
|
467
|
+
);
|
|
447
468
|
}
|
|
448
|
-
throw usageError(
|
|
449
|
-
`Invalid --contract "${value}". Expected a version number or latest.`
|
|
450
|
-
);
|
|
451
469
|
}
|
|
452
470
|
function parseTypeFlag(value) {
|
|
453
471
|
if (value === void 0) {
|
|
@@ -459,7 +477,7 @@ function parseTypeFlag(value) {
|
|
|
459
477
|
return value.trim();
|
|
460
478
|
}
|
|
461
479
|
function describeType(declaration) {
|
|
462
|
-
return declaration.type
|
|
480
|
+
return declaration.type !== "html" ? `${declaration.type} (format ${declaration.typeFormat})` : void 0;
|
|
463
481
|
}
|
|
464
482
|
function parseAnnotationStatus(value) {
|
|
465
483
|
if (cliAnnotationStatusOptions.includes(value)) {
|
|
@@ -536,47 +554,64 @@ function resolveBaseUrl(args, config) {
|
|
|
536
554
|
const host = parseFlagValue(args, "--host") || parseFlagValue(args, "--url") || process.env["ARTIS_URL"] || config?.defaultHost || ARTIS_DEFAULT_HOST;
|
|
537
555
|
return normalizeHost(host);
|
|
538
556
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
557
|
+
var refreshMarginMs = 6e4;
|
|
558
|
+
function needsRefresh(profile) {
|
|
559
|
+
return profile.expiresAt !== void 0 && profile.expiresAt - refreshMarginMs <= Date.now() && Boolean(profile.refreshToken);
|
|
560
|
+
}
|
|
561
|
+
async function savedAccessToken(config, baseUrl) {
|
|
562
|
+
const saved = findProfileForHost(config, baseUrl);
|
|
563
|
+
if (!saved) return void 0;
|
|
564
|
+
if (!needsRefresh(saved)) return saved.accessToken;
|
|
565
|
+
return withConfigLock(async () => {
|
|
566
|
+
const profile = findProfileForHost(await readCliConfig(), baseUrl);
|
|
567
|
+
if (!profile) return void 0;
|
|
568
|
+
if (!needsRefresh(profile) || !profile.refreshToken) {
|
|
569
|
+
return profile.accessToken;
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
const tokens = await refreshTokens(baseUrl, profile.refreshToken);
|
|
573
|
+
await updateProfileTokens(baseUrl, {
|
|
574
|
+
accessToken: tokens.accessToken,
|
|
575
|
+
refreshToken: tokens.refreshToken ?? profile.refreshToken,
|
|
576
|
+
expiresAt: tokens.expiresAt
|
|
577
|
+
});
|
|
578
|
+
return tokens.accessToken;
|
|
579
|
+
} catch (error) {
|
|
580
|
+
if (error instanceof OAuthError && error.status < 500 && error.status !== 429) {
|
|
581
|
+
return void 0;
|
|
582
|
+
}
|
|
583
|
+
return profile.accessToken;
|
|
584
|
+
}
|
|
585
|
+
});
|
|
552
586
|
}
|
|
553
587
|
async function resolveCredentials(args) {
|
|
554
588
|
const config = await readCliConfig();
|
|
555
589
|
const baseUrl = resolveBaseUrl(args, config);
|
|
556
|
-
const
|
|
557
|
-
if (!
|
|
590
|
+
const accessToken = await savedAccessToken(config, baseUrl);
|
|
591
|
+
if (!accessToken) {
|
|
558
592
|
throw new CliError(
|
|
559
|
-
`
|
|
593
|
+
`Not signed in to ${baseUrl}. Run "artis login --host ${baseUrl}".`,
|
|
560
594
|
exitCodes.auth
|
|
561
595
|
);
|
|
562
596
|
}
|
|
563
|
-
return {
|
|
597
|
+
return { accessToken, baseUrl, origin: await resolveOrigin() };
|
|
564
598
|
}
|
|
565
599
|
async function resolveOptionalTarget(args) {
|
|
566
600
|
const config = await readCliConfig();
|
|
567
601
|
const baseUrl = resolveBaseUrl(args, config);
|
|
568
|
-
const
|
|
569
|
-
return {
|
|
602
|
+
const accessToken = await savedAccessToken(config, baseUrl);
|
|
603
|
+
return {
|
|
604
|
+
accessToken,
|
|
605
|
+
baseUrl,
|
|
606
|
+
origin: accessToken ? await resolveOrigin() : void 0
|
|
607
|
+
};
|
|
570
608
|
}
|
|
571
609
|
async function guidelinesFromCli(args) {
|
|
610
|
+
rejectRemovedContractFlag(args);
|
|
572
611
|
const [section] = getPositionals(args);
|
|
573
|
-
const contract = parseContractFlag(parseFlagValue(args, "--contract"));
|
|
574
612
|
const config = await readCliConfig();
|
|
575
613
|
const baseUrl = resolveBaseUrl(args, config);
|
|
576
614
|
const query = new URLSearchParams({ section: section ?? "index" });
|
|
577
|
-
if (contract !== void 0) {
|
|
578
|
-
query.set("contract", String(contract));
|
|
579
|
-
}
|
|
580
615
|
const response = await fetch(`${baseUrl}/skills.md?${query.toString()}`);
|
|
581
616
|
const text = await response.text();
|
|
582
617
|
if (!response.ok) {
|
|
@@ -604,11 +639,12 @@ function rejectRemovedResolveFlag(args) {
|
|
|
604
639
|
}
|
|
605
640
|
async function parsePublishOptions(args) {
|
|
606
641
|
rejectRemovedKindFlag(args);
|
|
642
|
+
rejectRemovedContractFlag(args);
|
|
607
643
|
const [filePath] = getPositionals(args);
|
|
608
644
|
const root = parseFlagValue(args, "--root");
|
|
609
645
|
if (!filePath && !root) {
|
|
610
646
|
throw usageError(
|
|
611
|
-
"Missing artifact HTML file path (or --root <dir> for
|
|
647
|
+
"Missing artifact HTML file path (or --root <dir> for an artifact as a directory of files, e.g. a slides deck)."
|
|
612
648
|
);
|
|
613
649
|
}
|
|
614
650
|
if (filePath && root) {
|
|
@@ -621,7 +657,7 @@ async function parsePublishOptions(args) {
|
|
|
621
657
|
return {
|
|
622
658
|
filePath,
|
|
623
659
|
root,
|
|
624
|
-
|
|
660
|
+
credentials,
|
|
625
661
|
baseUrl: credentials.baseUrl,
|
|
626
662
|
title: parseFlagValue(args, "--title"),
|
|
627
663
|
description: parseFlagValue(args, "--description") ?? "Published from Artis CLI.",
|
|
@@ -630,12 +666,54 @@ async function parsePublishOptions(args) {
|
|
|
630
666
|
capabilities: await parseCapabilitiesFlag(
|
|
631
667
|
parseFlagValue(args, "--capabilities")
|
|
632
668
|
),
|
|
633
|
-
|
|
669
|
+
reloadPages: hasFlag(args, "--reload-pages") || void 0,
|
|
634
670
|
type: parseTypeFlag(parseFlagValue(args, "--type")),
|
|
635
671
|
json: hasFlag(args, "--json")
|
|
636
672
|
};
|
|
637
673
|
}
|
|
638
|
-
function
|
|
674
|
+
async function apiCallRoot(root, credentials, key, ...input) {
|
|
675
|
+
try {
|
|
676
|
+
return await apiClient(credentials).call(key, ...input);
|
|
677
|
+
} catch (error) {
|
|
678
|
+
const cliError = cliErrorOf(error, {
|
|
679
|
+
artifact: root.artifact,
|
|
680
|
+
root: root.dir
|
|
681
|
+
});
|
|
682
|
+
const issue = error instanceof ApiError && layoutIssueOf(error);
|
|
683
|
+
if (!issue || !(cliError instanceof CliError)) throw cliError;
|
|
684
|
+
const stray = /does not take (\S+):/.exec(issue)?.[1];
|
|
685
|
+
let hint = stray ? ` Every file under --root is sent (dotfiles and node_modules are skipped): move ${stray} out of ${root.dir}.` : "";
|
|
686
|
+
if (root.untyped) {
|
|
687
|
+
hint += " Without --type the files are an html artifact; for another type, pass --type <type>, e.g. --type slides.";
|
|
688
|
+
}
|
|
689
|
+
throw new CliError(`${cliError.message}${hint}`, cliError.exitCode);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function layoutIssueOf(error) {
|
|
693
|
+
if (error.status !== 400 || error.code !== "invalid_request") {
|
|
694
|
+
return void 0;
|
|
695
|
+
}
|
|
696
|
+
const issues = error.body?.["issues"];
|
|
697
|
+
if (!Array.isArray(issues)) return void 0;
|
|
698
|
+
for (const issue of issues) {
|
|
699
|
+
if (!issue || typeof issue !== "object") continue;
|
|
700
|
+
const { path, message } = issue;
|
|
701
|
+
if ((path === "files" || path === "type") && typeof message === "string") {
|
|
702
|
+
return message;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return void 0;
|
|
706
|
+
}
|
|
707
|
+
function conflictingPathsHint(body, context = {}) {
|
|
708
|
+
const paths = body?.["conflictingPaths"];
|
|
709
|
+
if (body?.["code"] !== "revision_conflict" || !Array.isArray(paths) || paths.length === 0) {
|
|
710
|
+
return "";
|
|
711
|
+
}
|
|
712
|
+
const artifact = context.artifact ?? "<artifact>";
|
|
713
|
+
const recover = context.root ? `Pull the current revision into a new directory (artis artifact files ${artifact} --output <new-dir>), reapply your change there, and revise with --root <new-dir>.` : `Read the current version (artis artifact files ${artifact} ${paths.length === 1 ? paths[0] : "<path>"}), reapply your change, and revise again.`;
|
|
714
|
+
return `Conflicting files: ${paths.join(", ")}. ${recover}`;
|
|
715
|
+
}
|
|
716
|
+
function cliErrorOf(error, context = {}) {
|
|
639
717
|
if (!(error instanceof ApiError)) {
|
|
640
718
|
return error;
|
|
641
719
|
}
|
|
@@ -643,6 +721,10 @@ function cliErrorOf(error) {
|
|
|
643
721
|
formatRevisionConflictMessage(error.message, error.body),
|
|
644
722
|
error.body
|
|
645
723
|
);
|
|
724
|
+
const conflict = conflictingPathsHint(error.body, context);
|
|
725
|
+
if (conflict) {
|
|
726
|
+
message = `${message.replace(/[.\s]*$/, "")}. ${conflict}`;
|
|
727
|
+
}
|
|
646
728
|
if (error.status === 429 && error.retryAfter) {
|
|
647
729
|
message += ` Retry after ${error.retryAfter} s.`;
|
|
648
730
|
}
|
|
@@ -651,7 +733,8 @@ function cliErrorOf(error) {
|
|
|
651
733
|
function apiClient(target) {
|
|
652
734
|
return createApiClient({
|
|
653
735
|
baseUrl: target.baseUrl,
|
|
654
|
-
auth: target.
|
|
736
|
+
auth: target.accessToken ? { bearer: target.accessToken } : void 0,
|
|
737
|
+
headers: target.accessToken && target.origin ? { "artis-origin": target.origin } : void 0
|
|
655
738
|
});
|
|
656
739
|
}
|
|
657
740
|
async function apiCall(credentials, key, ...input) {
|
|
@@ -665,7 +748,7 @@ async function apiCallOptional(target, key, ...input) {
|
|
|
665
748
|
try {
|
|
666
749
|
return await apiClient(target).call(key, ...input);
|
|
667
750
|
} catch (error) {
|
|
668
|
-
if (!(error instanceof ApiError) || error.status !== 401 || !target.
|
|
751
|
+
if (!(error instanceof ApiError) || error.status !== 401 || !target.accessToken) {
|
|
669
752
|
throw cliErrorOf(error);
|
|
670
753
|
}
|
|
671
754
|
}
|
|
@@ -675,7 +758,7 @@ async function apiCallOptional(target, key, ...input) {
|
|
|
675
758
|
...input
|
|
676
759
|
);
|
|
677
760
|
console.warn(
|
|
678
|
-
`Saved
|
|
761
|
+
`Saved sign-in was rejected by ${target.baseUrl}; retried without credentials. Run "artis login --host ${target.baseUrl}" to sign in again.`
|
|
679
762
|
);
|
|
680
763
|
return result;
|
|
681
764
|
} catch (error) {
|
|
@@ -737,27 +820,28 @@ Usage:
|
|
|
737
820
|
artis --version
|
|
738
821
|
artis login [--host <url>]
|
|
739
822
|
artis whoami [--host <url>]
|
|
740
|
-
artis guidelines [section] [--
|
|
823
|
+
artis guidelines [section] [--host <url>]
|
|
741
824
|
artis types [name [reference]] [--json] [--host <url>]
|
|
742
825
|
artis install-skill [--harness <id>]... [--yes] [--dir <path>] [--force] [--list] [--json]
|
|
743
826
|
artis publish artifact.html [options]
|
|
744
|
-
artis publish --root <dir> --type <type> [options]
|
|
827
|
+
artis publish --root <dir> [--type <type>] [options]
|
|
745
828
|
artis artifact get <artifact> [--json]
|
|
746
|
-
artis artifact html <artifact> [--output <path>] [--revision <revision-id>] [--json]
|
|
747
829
|
artis artifact files <artifact> [path] [--output <dir>] [--revision <revision-id>] [--json]
|
|
748
830
|
artis artifact feedback <artifact> [--json] [--revision <revision-id>]
|
|
749
831
|
artis artifact list [--query <text>] [--tag <tag>] [--type <type>] [--limit <n>] [--cursor <cursor>] [--json]
|
|
750
832
|
artis artifact visibility <artifact> <public|unlisted|private> [--json]
|
|
751
833
|
artis artifact delete <artifact> --yes
|
|
752
|
-
artis verify <artifact.html | artifact> [--
|
|
753
|
-
artis verify --root <dir> --type slides [--json]
|
|
834
|
+
artis verify <artifact.html | artifact> [--revision <revision-id>] [--json]
|
|
835
|
+
artis verify --root <dir> [--type slides] [--json]
|
|
754
836
|
artis share <artifact> [--email <email> --role <viewer|commenter|contributor|editor>] [--remove]
|
|
755
|
-
artis revise <artifact> (artifact.html | --root <dir>) --summary <text> [--base <revision-id>] [--capabilities <json|file>] [--
|
|
837
|
+
artis revise <artifact> (artifact.html | --root <dir>) --summary <text> [--base <revision-id>] [--capabilities <json|file>] [--reload-pages] [--type <type>]
|
|
838
|
+
artis capabilities show <artifact> [--json]
|
|
839
|
+
artis capabilities set <artifact> <json|file> [--reload-pages] [--json]
|
|
756
840
|
artis annotate <artifact> --comment <text> [anchor options]
|
|
757
841
|
artis reply <annotation-id> --comment <text>
|
|
758
842
|
artis annotation edit <annotation-id> [--comment <text>] [--title <text>] [--requested-change <text>]
|
|
759
843
|
artis annotation retract <annotation-id>
|
|
760
|
-
artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--
|
|
844
|
+
artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--self origin|client|none] [--types <families>]
|
|
761
845
|
artis data get <artifact> <path> [--as-role <role>]
|
|
762
846
|
artis data list <artifact> [prefix] [--depth children|all] [--order path|created] [--limit <n>] [--after <next>] [--as-role <role>]
|
|
763
847
|
artis data set <artifact> <path> --value <json|file|-> [--if-match <id>@<version> | --if-absent] [--idempotency-key <key>]
|
|
@@ -766,9 +850,12 @@ Usage:
|
|
|
766
850
|
artis data batch <artifact> --ops <json|file|-> [--idempotency-key <key>]
|
|
767
851
|
artis data export <artifact> [--output <path>] [--as-role <role>]
|
|
768
852
|
artis data usage <artifact>
|
|
853
|
+
artis asset upload <artifact> <file> [--name <name>] [--content-type <type>]
|
|
854
|
+
artis asset list <artifact>
|
|
855
|
+
artis asset get <artifact> <asset-id> [--output <path>]
|
|
856
|
+
artis asset rm <artifact> <asset-id>
|
|
769
857
|
|
|
770
858
|
Options:
|
|
771
|
-
--api-key <key> API key. Defaults to ARTIS_API_KEY or ~/.artis/config.json. Run "artis login" to obtain one.
|
|
772
859
|
--host, --url <url> Artis server URL. Falls back to ARTIS_URL, then a saved login, then https://artis.xiispace.eu.org.
|
|
773
860
|
--title <title> Artifact title. Defaults to the file name.
|
|
774
861
|
--description <text> Artifact description.
|
|
@@ -776,9 +863,9 @@ Options:
|
|
|
776
863
|
--type <type> The type the artifact is created with, e.g. slides (publish, revise, verify; artifact list keeps your artifacts of that type). It is fixed at publish: revise keeps it, and may only repeat it. Verify of a published artifact reads it from the revision.
|
|
777
864
|
--author <name> Artifact author/agent name. Defaults to Artis CLI.
|
|
778
865
|
--summary <text> Revision summary. Write one change per line; they render as a list.
|
|
779
|
-
--base <revision-id> Revision the file was edited from. Defaults to the revision this machine last published, read (artifact html), or revised. Refuses the revise if someone revised since.
|
|
780
|
-
--capabilities <json|file> Page capabilities as a JSON object or JSON file (publish, revise).
|
|
781
|
-
--
|
|
866
|
+
--base <revision-id> Revision the file was edited from. Defaults to the revision this machine last published, read whole (artifact files --output, or an html artifact's index.html), or revised. Refuses the revise if someone revised since.
|
|
867
|
+
--capabilities <json|file> Page capabilities as a JSON object or JSON file (publish, revise). They belong to the artifact, not the revision: revise keeps them without it; '{}' clears them.
|
|
868
|
+
--reload-pages Make open pages reload (revise, capabilities set), e.g. when stored data changes shape. A revise that leaves the capabilities alone does not interrupt open pages without it.
|
|
782
869
|
--comment <text> Annotation or reply comment text (annotate, reply).
|
|
783
870
|
--requested-change <text> Structured change request for the artifact author (annotate).
|
|
784
871
|
--status <value> Annotation status: open or resolved. Defaults to open.
|
|
@@ -790,9 +877,9 @@ Options:
|
|
|
790
877
|
--text-end <n> Document offset where the quote ends (annotate, TextPositionSelector).
|
|
791
878
|
--rect <x,y,w,h> Canvas point/rect as percentages (annotate, FragmentSelector). w,h default to 0.
|
|
792
879
|
--pin-label <text> Short label shown on the artifact canvas pin (annotate).
|
|
793
|
-
--output <path> Write
|
|
794
|
-
--root <dir>
|
|
795
|
-
--revision <revision-id> Revision to read (artifact
|
|
880
|
+
--output <path> Write every file of the revision under this directory, downloaded in parallel (artifact files).
|
|
881
|
+
--root <dir> An artifact as a directory of files, any type (an html artifact is one file, index.html): publish every file under it, or revise with only the ones that differ from the base revision (files gone from it are removed). The type checks the files, so keep anything else (notes, a README) out of it. Dotfiles and node_modules are skipped. verify serves the files at the paths usercontent serves them at.
|
|
882
|
+
--revision <revision-id> Revision to read (artifact files, artifact feedback). Defaults to the current revision.
|
|
796
883
|
--query <text> Text to find in your artifacts' titles and descriptions (artifact list).
|
|
797
884
|
--tag <tag> Only your artifacts carrying this tag (artifact list).
|
|
798
885
|
--limit <n> Artifacts per page, 1-100 (artifact list). Defaults to 50.
|
|
@@ -808,8 +895,8 @@ Options:
|
|
|
808
895
|
--since <cursor> Feedback cursor to watch from (watch). Defaults to now; 0 replays every event.
|
|
809
896
|
--once Exit after the first batch of events, printed as {events, cursor} (watch).
|
|
810
897
|
--timeout <duration> Give up after this long, e.g. 30s, 10m (watch). Exits 6 if nothing happened.
|
|
811
|
-
--
|
|
812
|
-
--types <families> Only these event families, comma-separated: annotation, revision (watch). Defaults to all.
|
|
898
|
+
--self <scope> Which of your own events to leave out (watch): origin (default) leaves out this machine's, client those of every machine signed in with the CLI, none leaves out nothing. --include-self is --self none. The origin is ARTIS_ORIGIN, else one generated per machine.
|
|
899
|
+
--types <families> Only these event families, comma-separated: annotation, revision, page, policy (watch). Defaults to all.
|
|
813
900
|
--value <json|file|-> The whole document, a JSON object: inline, a file, or - for stdin (data set).
|
|
814
901
|
--patch <json|file|-> A JSON object deep-merged into the document (data update).
|
|
815
902
|
--ops <json|file|-> Writes for data batch: [{"op":"set","path":"...","value":{...}}, ...] or {"ops":[...]}.
|
|
@@ -831,9 +918,12 @@ Examples (--host is optional; without it commands target https://artis.xiispace.
|
|
|
831
918
|
artis publish report.html --host https://artis.example.com --visibility private
|
|
832
919
|
artis share 4kq9Zt2LmX8vRbP3nWc7Hy --host https://artis.example.com --email reviewer@example.com --role commenter
|
|
833
920
|
artis artifact get 4kq9Zt2LmX8vRbP3nWc7Hy --host https://artis.example.com --json
|
|
834
|
-
artis artifact
|
|
921
|
+
artis artifact files 4kq9Zt2LmX8vRbP3nWc7Hy index.html > report.html
|
|
922
|
+
artis publish --root deck --type slides
|
|
923
|
+
artis artifact files 4kq9Zt2LmX8vRbP3nWc7Hy --output deck
|
|
924
|
+
artis revise 4kq9Zt2LmX8vRbP3nWc7Hy --root deck --summary "Fix the cover slide"
|
|
835
925
|
artis verify report.html
|
|
836
|
-
artis verify deck
|
|
926
|
+
artis verify --root deck --type slides
|
|
837
927
|
artis artifact feedback 4kq9Zt2LmX8vRbP3nWc7Hy --host https://artis.example.com --json
|
|
838
928
|
artis annotate 4kq9Zt2LmX8vRbP3nWc7Hy --host https://artis.example.com --comment "Tighten this heading" --quote "Checkout latency" --requested-change "Add the affected checkout count"
|
|
839
929
|
artis reply annotation-123 --host https://artis.example.com --comment "Addressed in the latest revision"
|
|
@@ -847,7 +937,7 @@ Examples (--host is optional; without it commands target https://artis.xiispace.
|
|
|
847
937
|
}
|
|
848
938
|
async function publishArtifactFromCli(args) {
|
|
849
939
|
const options = await parsePublishOptions(args);
|
|
850
|
-
const credentials =
|
|
940
|
+
const credentials = options.credentials;
|
|
851
941
|
const source = options.root ?? options.filePath ?? "";
|
|
852
942
|
const title = options.title ?? inferTitleFromPath(source);
|
|
853
943
|
const query = {
|
|
@@ -857,21 +947,18 @@ async function publishArtifactFromCli(args) {
|
|
|
857
947
|
authorName: options.authorName,
|
|
858
948
|
source: "cli",
|
|
859
949
|
capabilities: options.capabilities,
|
|
860
|
-
|
|
950
|
+
reloadPages: options.reloadPages,
|
|
861
951
|
type: options.type
|
|
862
952
|
};
|
|
863
953
|
let result;
|
|
864
954
|
if (options.root) {
|
|
865
|
-
if (!options.type || options.type === "html") {
|
|
866
|
-
throw usageError(
|
|
867
|
-
"--root publishes an artifact made of files: pass the type it is written in, e.g. --type slides. An html artifact is one HTML file."
|
|
868
|
-
);
|
|
869
|
-
}
|
|
870
955
|
const files = await readFilesDir(options.root);
|
|
871
|
-
({ result } = await
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
956
|
+
({ result } = await apiCallRoot(
|
|
957
|
+
{ dir: options.root, untyped: !options.type },
|
|
958
|
+
credentials,
|
|
959
|
+
"POST /api/artifacts",
|
|
960
|
+
{ query, body: { files } }
|
|
961
|
+
));
|
|
875
962
|
} else {
|
|
876
963
|
const html = await readHtmlUpload(source, "Artifact file");
|
|
877
964
|
({ result } = await apiCall(credentials, "POST /api/artifacts", {
|
|
@@ -886,52 +973,82 @@ async function publishArtifactFromCli(args) {
|
|
|
886
973
|
title,
|
|
887
974
|
url: buildArtifactUrl(options.baseUrl, result.url),
|
|
888
975
|
visibility: options.visibility,
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
typeFormat: result.typeFormat ?? null
|
|
976
|
+
type: result.type,
|
|
977
|
+
typeFormat: result.typeFormat
|
|
892
978
|
};
|
|
893
979
|
}
|
|
894
980
|
async function loginFromCli(args) {
|
|
895
981
|
const config = await readCliConfig();
|
|
896
982
|
const baseUrl = resolveBaseUrl(args, config);
|
|
897
|
-
const api = apiClient({ baseUrl });
|
|
898
983
|
let login;
|
|
899
984
|
try {
|
|
900
|
-
login = await
|
|
985
|
+
login = await startDeviceAuthorization(baseUrl);
|
|
901
986
|
} catch (error) {
|
|
902
|
-
throw
|
|
987
|
+
throw loginErrorOf(error, baseUrl);
|
|
903
988
|
}
|
|
904
|
-
|
|
905
|
-
|
|
989
|
+
const verificationUrl = login.verificationUriComplete ?? login.verificationUri;
|
|
990
|
+
assertSafeLoginUrl(verificationUrl, baseUrl);
|
|
991
|
+
console.log(`Opening ${verificationUrl}`);
|
|
906
992
|
console.log(`Code: ${login.userCode}`);
|
|
907
993
|
try {
|
|
908
|
-
openBrowser(
|
|
994
|
+
openBrowser(verificationUrl);
|
|
909
995
|
} catch {
|
|
910
996
|
console.log("Could not open a browser automatically.");
|
|
911
997
|
}
|
|
912
|
-
|
|
913
|
-
|
|
998
|
+
let intervalMs = Math.max(login.interval, 1) * 1e3;
|
|
999
|
+
const expiresAt = Date.now() + login.expiresIn * 1e3;
|
|
1000
|
+
while (Date.now() < expiresAt) {
|
|
914
1001
|
await sleep(intervalMs);
|
|
915
1002
|
let poll;
|
|
916
1003
|
try {
|
|
917
|
-
poll = await
|
|
918
|
-
body: { deviceCode: login.deviceCode }
|
|
919
|
-
});
|
|
1004
|
+
poll = await pollDeviceToken(baseUrl, login.deviceCode);
|
|
920
1005
|
} catch (error) {
|
|
921
|
-
|
|
922
|
-
await sleep((error.retryAfter ?? 10) * 1e3);
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
throw cliErrorOf(error);
|
|
1006
|
+
throw loginErrorOf(error, baseUrl);
|
|
926
1007
|
}
|
|
927
1008
|
if (poll.status === "pending") {
|
|
928
1009
|
continue;
|
|
929
1010
|
}
|
|
930
|
-
|
|
1011
|
+
if (poll.status === "slow_down") {
|
|
1012
|
+
intervalMs += 5e3;
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
const previous = findProfileForHost(await readCliConfig(), baseUrl);
|
|
1016
|
+
await saveDefaultProfile({ host: baseUrl, ...poll.tokens });
|
|
1017
|
+
if (previous?.refreshToken) {
|
|
1018
|
+
await revokeToken(baseUrl, previous.refreshToken, "refresh_token");
|
|
1019
|
+
}
|
|
1020
|
+
if (previous?.accessToken) {
|
|
1021
|
+
await revokeToken(baseUrl, previous.accessToken, "access_token");
|
|
1022
|
+
}
|
|
1023
|
+
await resolveOrigin();
|
|
931
1024
|
console.log(`Saved artis credentials to ${getConfigPath()}`);
|
|
932
1025
|
return;
|
|
933
1026
|
}
|
|
934
|
-
throw new
|
|
1027
|
+
throw new CliError("Login expired. Run artis login again.", exitCodes.auth);
|
|
1028
|
+
}
|
|
1029
|
+
function loginErrorOf(error, baseUrl) {
|
|
1030
|
+
if (!(error instanceof OAuthError)) {
|
|
1031
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
1032
|
+
}
|
|
1033
|
+
if (error.code === "access_denied") {
|
|
1034
|
+
return new CliError("Login was denied in the browser.", exitCodes.auth);
|
|
1035
|
+
}
|
|
1036
|
+
if (error.code === "expired_token") {
|
|
1037
|
+
return new CliError(
|
|
1038
|
+
"Login expired. Run artis login again.",
|
|
1039
|
+
exitCodes.auth
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
if (error.status === 429) {
|
|
1043
|
+
return new CliError(
|
|
1044
|
+
`Too many logins from here; ${baseUrl} asked to slow down. Try again in a minute.`,
|
|
1045
|
+
exitCodes.rateLimited
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
return new CliError(
|
|
1049
|
+
`Login failed on ${baseUrl}: ${error.message}`,
|
|
1050
|
+
exitCodeForResponse(error.status, error.code)
|
|
1051
|
+
);
|
|
935
1052
|
}
|
|
936
1053
|
async function typesFromCli(args) {
|
|
937
1054
|
const [name, file] = getPositionals(args);
|
|
@@ -1038,6 +1155,44 @@ async function getArtifactFromCli(args) {
|
|
|
1038
1155
|
`Open annotations: ${result.annotations.filter((annotation) => isRootAnnotation(annotation) && !isReviewClosed(annotation["artis:status"])).length}`
|
|
1039
1156
|
);
|
|
1040
1157
|
}
|
|
1158
|
+
var parallelFileReads = 6;
|
|
1159
|
+
async function mapConcurrent(items, limit, run) {
|
|
1160
|
+
const results = new Array(items.length);
|
|
1161
|
+
let next = 0;
|
|
1162
|
+
async function worker() {
|
|
1163
|
+
while (next < items.length) {
|
|
1164
|
+
const index = next++;
|
|
1165
|
+
results[index] = await run(items[index]);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
await Promise.all(
|
|
1169
|
+
Array.from({ length: Math.min(limit, items.length) }, worker)
|
|
1170
|
+
);
|
|
1171
|
+
return results;
|
|
1172
|
+
}
|
|
1173
|
+
function listRevisionFiles(target, artifactId, revisionId) {
|
|
1174
|
+
return apiCallOptional(target, "GET /api/artifacts/{artifactId}/files", {
|
|
1175
|
+
params: { artifactId },
|
|
1176
|
+
query: { revisionId }
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
function readListedFiles(target, artifactId, listed) {
|
|
1180
|
+
return mapConcurrent(listed.files, parallelFileReads, async (file) => {
|
|
1181
|
+
const read = await apiCallOptional(
|
|
1182
|
+
target,
|
|
1183
|
+
"GET /api/artifacts/{artifactId}/files/{path}",
|
|
1184
|
+
{
|
|
1185
|
+
params: { artifactId, path: file.path },
|
|
1186
|
+
query: { revisionId: listed.revisionId }
|
|
1187
|
+
}
|
|
1188
|
+
);
|
|
1189
|
+
return { path: file.path, content: read.content };
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
async function readRevisionFiles(target, artifactId, revisionId) {
|
|
1193
|
+
const listed = await listRevisionFiles(target, artifactId, revisionId);
|
|
1194
|
+
return { listed, files: await readListedFiles(target, artifactId, listed) };
|
|
1195
|
+
}
|
|
1041
1196
|
async function getArtifactFilesFromCli(args) {
|
|
1042
1197
|
const [artifactRef, filePath] = getPositionals(args);
|
|
1043
1198
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
@@ -1049,41 +1204,45 @@ async function getArtifactFilesFromCli(args) {
|
|
|
1049
1204
|
const target = await resolveOptionalTarget(args);
|
|
1050
1205
|
const revisionId = parseFlagValue(args, "--revision");
|
|
1051
1206
|
const json = hasFlag(args, "--json");
|
|
1207
|
+
const output = parseFlagValue(args, "--output");
|
|
1208
|
+
if (filePath && output) {
|
|
1209
|
+
throw usageError(
|
|
1210
|
+
`--output writes every file of the revision under a directory. To save one file, redirect it: artis artifact files ${artifactRef} ${filePath} > <file>.`
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1052
1213
|
if (filePath) {
|
|
1053
1214
|
const file = await apiCallOptional(
|
|
1054
1215
|
target,
|
|
1055
1216
|
"GET /api/artifacts/{artifactId}/files/{path}",
|
|
1056
1217
|
{ params: { artifactId, path: filePath }, query: { revisionId } }
|
|
1057
1218
|
);
|
|
1219
|
+
const revision = await apiCallOptional(
|
|
1220
|
+
target,
|
|
1221
|
+
"GET /api/artifacts/{artifactId}/files",
|
|
1222
|
+
{ params: { artifactId }, query: { revisionId: file.revisionId } }
|
|
1223
|
+
);
|
|
1224
|
+
if (revision.files.length === 1) {
|
|
1225
|
+
await rememberBase(
|
|
1226
|
+
target.baseUrl,
|
|
1227
|
+
[artifactId, file.artifactId],
|
|
1228
|
+
file.revisionId
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
if (file.isLatest === false) {
|
|
1232
|
+
console.error(
|
|
1233
|
+
`Note: version ${file.version} is not the latest. The latest is version ${file.latestVersion} (revision ${file.latestRevisionId}); a revise based on this one will be refused if it changes a file changed since.`
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1058
1236
|
if (json) {
|
|
1059
1237
|
console.log(JSON.stringify(file, null, 2));
|
|
1060
1238
|
return;
|
|
1061
1239
|
}
|
|
1062
|
-
process.stdout.write(
|
|
1063
|
-
file.content.endsWith("\n") ? file.content : `${file.content}
|
|
1064
|
-
`
|
|
1065
|
-
);
|
|
1240
|
+
process.stdout.write(file.content);
|
|
1066
1241
|
return;
|
|
1067
1242
|
}
|
|
1068
|
-
const listed = await
|
|
1069
|
-
target,
|
|
1070
|
-
"GET /api/artifacts/{artifactId}/files",
|
|
1071
|
-
{ params: { artifactId }, query: { revisionId } }
|
|
1072
|
-
);
|
|
1073
|
-
const output = parseFlagValue(args, "--output");
|
|
1243
|
+
const listed = await listRevisionFiles(target, artifactId, revisionId);
|
|
1074
1244
|
if (output) {
|
|
1075
|
-
const files =
|
|
1076
|
-
for (const file of listed.files) {
|
|
1077
|
-
const read = await apiCallOptional(
|
|
1078
|
-
target,
|
|
1079
|
-
"GET /api/artifacts/{artifactId}/files/{path}",
|
|
1080
|
-
{
|
|
1081
|
-
params: { artifactId, path: file.path },
|
|
1082
|
-
query: { revisionId: listed.revisionId }
|
|
1083
|
-
}
|
|
1084
|
-
);
|
|
1085
|
-
files.push({ path: file.path, content: read.content });
|
|
1086
|
-
}
|
|
1245
|
+
const files = await readListedFiles(target, artifactId, listed);
|
|
1087
1246
|
await writeFilesDir(output, files);
|
|
1088
1247
|
await rememberBase(
|
|
1089
1248
|
target.baseUrl,
|
|
@@ -1102,50 +1261,6 @@ async function getArtifactFilesFromCli(args) {
|
|
|
1102
1261
|
output ? `Wrote ${listed.files.length} files of revision ${listed.revisionId} (v${listed.version}) to ${output}.` : `Revision ${listed.revisionId} (v${listed.version})${listed.isLatest ? "" : ", not the latest"}.`
|
|
1103
1262
|
);
|
|
1104
1263
|
}
|
|
1105
|
-
async function getArtifactHtmlFromCli(args) {
|
|
1106
|
-
const [artifactRef] = getPositionals(args);
|
|
1107
|
-
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1108
|
-
if (!artifactId) {
|
|
1109
|
-
throw usageError(
|
|
1110
|
-
"Usage: artis artifact html <artifact> [--output <path>] [--revision <revision-id>]"
|
|
1111
|
-
);
|
|
1112
|
-
}
|
|
1113
|
-
const target = await resolveOptionalTarget(args);
|
|
1114
|
-
const result = await apiCallOptional(
|
|
1115
|
-
target,
|
|
1116
|
-
"GET /api/artifacts/{artifactId}/html",
|
|
1117
|
-
{
|
|
1118
|
-
params: { artifactId },
|
|
1119
|
-
query: { revisionId: parseFlagValue(args, "--revision") }
|
|
1120
|
-
}
|
|
1121
|
-
);
|
|
1122
|
-
if (typeof result.html !== "string") {
|
|
1123
|
-
throw new Error("Artifact response did not include revision HTML.");
|
|
1124
|
-
}
|
|
1125
|
-
await rememberBase(
|
|
1126
|
-
target.baseUrl,
|
|
1127
|
-
[artifactId, result.artifactId],
|
|
1128
|
-
result.revisionId
|
|
1129
|
-
);
|
|
1130
|
-
if (result.isLatest === false) {
|
|
1131
|
-
console.error(
|
|
1132
|
-
`Note: version ${result.version} is not the latest. The latest is version ${result.latestVersion} (revision ${result.latestRevisionId}); a revise based on this one will be refused.`
|
|
1133
|
-
);
|
|
1134
|
-
}
|
|
1135
|
-
if (hasFlag(args, "--json")) {
|
|
1136
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
const outputPath = parseFlagValue(args, "--output");
|
|
1140
|
-
if (!outputPath) {
|
|
1141
|
-
process.stdout.write(result.html);
|
|
1142
|
-
return;
|
|
1143
|
-
}
|
|
1144
|
-
await writeFile(outputPath, result.html, "utf8");
|
|
1145
|
-
console.log(`Wrote ${outputPath}`);
|
|
1146
|
-
console.log(`Revision: ${result.revisionId}`);
|
|
1147
|
-
console.log(`Version: ${result.version}`);
|
|
1148
|
-
}
|
|
1149
1264
|
function parseVerifyType(value) {
|
|
1150
1265
|
const type = parseTypeFlag(value);
|
|
1151
1266
|
if (type === void 0 || type === "html") {
|
|
@@ -1163,15 +1278,16 @@ async function verifyFromCli(args) {
|
|
|
1163
1278
|
const root = parseFlagValue(args, "--root");
|
|
1164
1279
|
if (!target && !root) {
|
|
1165
1280
|
throw usageError(
|
|
1166
|
-
"Usage: artis verify <artifact.html | artifact> [--
|
|
1281
|
+
"Usage: artis verify <artifact.html | artifact> [--revision <revision-id>] [--json]\n artis verify --root <dir> [--type slides] [--json]"
|
|
1167
1282
|
);
|
|
1168
1283
|
}
|
|
1169
1284
|
if (root) {
|
|
1170
1285
|
return verifyFilesDirFromCli(args, root, target);
|
|
1171
1286
|
}
|
|
1172
1287
|
let type = parseVerifyType(parseFlagValue(args, "--type"));
|
|
1173
|
-
let
|
|
1288
|
+
let files;
|
|
1174
1289
|
let label;
|
|
1290
|
+
let loadAsset;
|
|
1175
1291
|
const referenced = artifactIdFromReference(target);
|
|
1176
1292
|
const looksLikePath = !referenced && (/[\\/]/.test(target) || /\.html?$/i.test(target));
|
|
1177
1293
|
const local = await readFile(target, "utf8").catch(
|
|
@@ -1186,30 +1302,43 @@ async function verifyFromCli(args) {
|
|
|
1186
1302
|
"--revision applies to a published artifact, not a local file."
|
|
1187
1303
|
);
|
|
1188
1304
|
}
|
|
1189
|
-
|
|
1305
|
+
if (type) {
|
|
1306
|
+
throw usageError(
|
|
1307
|
+
`A ${type} artifact is a directory of files: artis verify --root <dir> --type ${type}.`
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
files = { "index.html": local };
|
|
1190
1311
|
label = target;
|
|
1191
1312
|
} else {
|
|
1192
1313
|
const remote = await resolveOptionalTarget(args);
|
|
1193
|
-
const
|
|
1314
|
+
const artifactId = referenced ?? target;
|
|
1315
|
+
const read = await readRevisionFiles(
|
|
1194
1316
|
remote,
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
params: { artifactId: referenced ?? target },
|
|
1198
|
-
query: { revisionId: parseFlagValue(args, "--revision") }
|
|
1199
|
-
}
|
|
1317
|
+
artifactId,
|
|
1318
|
+
parseFlagValue(args, "--revision")
|
|
1200
1319
|
);
|
|
1201
|
-
|
|
1202
|
-
|
|
1320
|
+
files = Object.fromEntries(
|
|
1321
|
+
read.files.map((file) => [file.path, file.content])
|
|
1322
|
+
);
|
|
1323
|
+
label = `${target} v${read.listed.version}`;
|
|
1324
|
+
if (remote.accessToken) {
|
|
1325
|
+
loadAsset = (assetId) => fetchAssetContent(remote, artifactId, assetId).catch((error) => {
|
|
1326
|
+
if (error instanceof CliError && error.exitCode === exitCodes.notFound) {
|
|
1327
|
+
return void 0;
|
|
1328
|
+
}
|
|
1329
|
+
throw error;
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1203
1332
|
if (type === void 0) {
|
|
1204
1333
|
const { artifact } = await apiCallOptional(
|
|
1205
1334
|
remote,
|
|
1206
1335
|
"GET /api/artifacts/{artifactId}",
|
|
1207
|
-
{ params: { artifactId
|
|
1336
|
+
{ params: { artifactId } }
|
|
1208
1337
|
);
|
|
1209
1338
|
const declared = artifact.revisions.find(
|
|
1210
|
-
(revision) => revision.id ===
|
|
1339
|
+
(revision) => revision.id === read.listed.revisionId
|
|
1211
1340
|
)?.type;
|
|
1212
|
-
if (declared && declared !== "html") {
|
|
1341
|
+
if (declared !== void 0 && declared !== "html") {
|
|
1213
1342
|
if (!verifyTypes.includes(declared)) {
|
|
1214
1343
|
throw new CliError(
|
|
1215
1344
|
`${label} is of type ${declared}, which this CLI cannot verify. Update the CLI.`,
|
|
@@ -1220,7 +1349,7 @@ async function verifyFromCli(args) {
|
|
|
1220
1349
|
}
|
|
1221
1350
|
}
|
|
1222
1351
|
}
|
|
1223
|
-
await runVerify(args,
|
|
1352
|
+
await runVerify(args, files, label, type, loadAsset);
|
|
1224
1353
|
}
|
|
1225
1354
|
async function verifyFilesDirFromCli(args, root, target) {
|
|
1226
1355
|
if (target) {
|
|
@@ -1230,22 +1359,20 @@ async function verifyFilesDirFromCli(args, root, target) {
|
|
|
1230
1359
|
throw usageError("--revision applies to a published artifact.");
|
|
1231
1360
|
}
|
|
1232
1361
|
const type = parseVerifyType(parseFlagValue(args, "--type"));
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
console.error(composed.error);
|
|
1239
|
-
throw new CliError("", exitCodes.verifyFailed);
|
|
1362
|
+
const files = await readFilesDir(root);
|
|
1363
|
+
if (!type && files["index.html"] === void 0) {
|
|
1364
|
+
throw usageError(
|
|
1365
|
+
`${root} has no index.html: an html artifact is that one file. For a deck, add --type slides.`
|
|
1366
|
+
);
|
|
1240
1367
|
}
|
|
1241
|
-
await runVerify(args,
|
|
1368
|
+
await runVerify(args, files, root, type);
|
|
1242
1369
|
}
|
|
1243
|
-
async function runVerify(args,
|
|
1370
|
+
async function runVerify(args, files, label, type, loadAsset) {
|
|
1244
1371
|
const json = hasFlag(args, "--json");
|
|
1245
1372
|
const title = `Verified ${label}${type ? ` (type ${type})` : ""}`;
|
|
1246
1373
|
let report;
|
|
1247
1374
|
try {
|
|
1248
|
-
report = await
|
|
1375
|
+
report = await verifyFiles(files, { type, loadAsset });
|
|
1249
1376
|
} catch (error) {
|
|
1250
1377
|
if (error instanceof VerifyUnavailableError) {
|
|
1251
1378
|
if (error.partial && !json) {
|
|
@@ -1416,6 +1543,60 @@ async function setArtifactVisibilityFromCli(args) {
|
|
|
1416
1543
|
}
|
|
1417
1544
|
console.log(`Visibility: ${result.artifact.metadata.visibility}`);
|
|
1418
1545
|
}
|
|
1546
|
+
function printPolicy(artifact) {
|
|
1547
|
+
console.log(`Declared: ${JSON.stringify(artifact.declaredCapabilities)}`);
|
|
1548
|
+
console.log(`Served: ${JSON.stringify(artifact.capabilities)}`);
|
|
1549
|
+
console.log(`Page epoch: ${artifact.pageEpoch}`);
|
|
1550
|
+
}
|
|
1551
|
+
async function capabilitiesFromCli(args) {
|
|
1552
|
+
const [subcommand, ...rest] = args;
|
|
1553
|
+
const [artifactRef, value] = getPositionals(rest);
|
|
1554
|
+
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1555
|
+
const usage = "Usage: artis capabilities show <artifact> | artis capabilities set <artifact> <json|file> [--reload-pages]";
|
|
1556
|
+
if (subcommand === "show" && artifactId) {
|
|
1557
|
+
const credentials = await resolveCredentials(rest);
|
|
1558
|
+
const { artifact } = await apiCall(
|
|
1559
|
+
credentials,
|
|
1560
|
+
"GET /api/artifacts/{artifactId}",
|
|
1561
|
+
{ params: { artifactId } }
|
|
1562
|
+
);
|
|
1563
|
+
if (hasFlag(rest, "--json")) {
|
|
1564
|
+
const { capabilities, declaredCapabilities, pageEpoch } = artifact;
|
|
1565
|
+
console.log(
|
|
1566
|
+
JSON.stringify(
|
|
1567
|
+
{ capabilities, declaredCapabilities, pageEpoch },
|
|
1568
|
+
null,
|
|
1569
|
+
2
|
|
1570
|
+
)
|
|
1571
|
+
);
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
printPolicy(artifact);
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
if (subcommand === "set" && artifactId && value !== void 0) {
|
|
1578
|
+
const capabilities = await parseCapabilitiesFlag(value, "capabilities");
|
|
1579
|
+
const credentials = await resolveCredentials(rest);
|
|
1580
|
+
const { artifact } = await apiCall(
|
|
1581
|
+
credentials,
|
|
1582
|
+
"PUT /api/artifacts/{artifactId}/capabilities",
|
|
1583
|
+
{
|
|
1584
|
+
params: { artifactId },
|
|
1585
|
+
body: {
|
|
1586
|
+
capabilities: capabilities ?? {},
|
|
1587
|
+
reloadPages: hasFlag(rest, "--reload-pages") || void 0
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
);
|
|
1591
|
+
if (hasFlag(rest, "--json")) {
|
|
1592
|
+
console.log(JSON.stringify({ artifact }, null, 2));
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
printPolicy(artifact);
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
throw usageError(usage);
|
|
1599
|
+
}
|
|
1419
1600
|
async function deleteArtifactFromCli(args) {
|
|
1420
1601
|
const [artifactRef] = getPositionals(args);
|
|
1421
1602
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
@@ -1435,6 +1616,7 @@ async function deleteArtifactFromCli(args) {
|
|
|
1435
1616
|
}
|
|
1436
1617
|
async function reviseArtifactFromCli(args) {
|
|
1437
1618
|
rejectRemovedResolveFlag(args);
|
|
1619
|
+
rejectRemovedContractFlag(args);
|
|
1438
1620
|
const [artifactRef, filePath] = getPositionals(args);
|
|
1439
1621
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1440
1622
|
const summary = parseFlagValue(args, "--summary");
|
|
@@ -1450,7 +1632,6 @@ async function reviseArtifactFromCli(args) {
|
|
|
1450
1632
|
const capabilities = await parseCapabilitiesFlag(
|
|
1451
1633
|
parseFlagValue(args, "--capabilities")
|
|
1452
1634
|
);
|
|
1453
|
-
const contract = parseContractFlag(parseFlagValue(args, "--contract"));
|
|
1454
1635
|
const type = parseTypeFlag(parseFlagValue(args, "--type"));
|
|
1455
1636
|
const credentials = await resolveCredentials(args);
|
|
1456
1637
|
const explicitBase = parseFlagValue(args, "--base");
|
|
@@ -1461,7 +1642,7 @@ async function reviseArtifactFromCli(args) {
|
|
|
1461
1642
|
source: "cli",
|
|
1462
1643
|
summary,
|
|
1463
1644
|
capabilities,
|
|
1464
|
-
|
|
1645
|
+
reloadPages: hasFlag(args, "--reload-pages") || void 0,
|
|
1465
1646
|
type
|
|
1466
1647
|
};
|
|
1467
1648
|
let result;
|
|
@@ -1479,9 +1660,10 @@ async function reviseArtifactFromCli(args) {
|
|
|
1479
1660
|
);
|
|
1480
1661
|
return;
|
|
1481
1662
|
}
|
|
1482
|
-
result = await
|
|
1663
|
+
result = await apiCallRoot(
|
|
1664
|
+
{ dir: root, untyped: false, artifact: artifactRef },
|
|
1483
1665
|
credentials,
|
|
1484
|
-
"POST /api/artifacts/{artifactId}/revisions
|
|
1666
|
+
"POST /api/artifacts/{artifactId}/revisions",
|
|
1485
1667
|
{ params: { artifactId }, query, body: { files } }
|
|
1486
1668
|
);
|
|
1487
1669
|
if (!hasFlag(args, "--json")) {
|
|
@@ -1494,11 +1676,14 @@ async function reviseArtifactFromCli(args) {
|
|
|
1494
1676
|
}
|
|
1495
1677
|
} else {
|
|
1496
1678
|
const html = await readHtmlUpload(filePath ?? "", "Revision file");
|
|
1497
|
-
|
|
1498
|
-
credentials
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1679
|
+
try {
|
|
1680
|
+
result = await apiClient(credentials).call(
|
|
1681
|
+
"POST /api/artifacts/{artifactId}/revisions",
|
|
1682
|
+
{ params: { artifactId }, query, body: html }
|
|
1683
|
+
);
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
throw cliErrorOf(error, { artifact: artifactRef });
|
|
1686
|
+
}
|
|
1502
1687
|
}
|
|
1503
1688
|
await rememberBase(
|
|
1504
1689
|
credentials.baseUrl,
|
|
@@ -1520,7 +1705,7 @@ async function reviseArtifactFromCli(args) {
|
|
|
1520
1705
|
console.log(`Base ${baseRevisionId} (remembered from this machine)`);
|
|
1521
1706
|
} else if (!baseRevisionId) {
|
|
1522
1707
|
console.log(
|
|
1523
|
-
"No base revision: pass --base, or read the artifact with publish or artifact
|
|
1708
|
+
"No base revision: pass --base, or read the artifact with publish or artifact files first, so a concurrent revision is refused instead of overwritten."
|
|
1524
1709
|
);
|
|
1525
1710
|
}
|
|
1526
1711
|
}
|
|
@@ -1545,7 +1730,6 @@ async function createAnnotationFromCli(args) {
|
|
|
1545
1730
|
comment,
|
|
1546
1731
|
pinLabel: parseFlagValue(args, "--pin-label"),
|
|
1547
1732
|
requestedChange: parseFlagValue(args, "--requested-change"),
|
|
1548
|
-
role: "agent",
|
|
1549
1733
|
selectors: selectors.length ? selectors : void 0,
|
|
1550
1734
|
status: parseAnnotationStatus(
|
|
1551
1735
|
parseFlagValue(args, "--status") ?? "open"
|
|
@@ -1571,8 +1755,7 @@ async function replyFromCli(args) {
|
|
|
1571
1755
|
params: { annotationId },
|
|
1572
1756
|
body: {
|
|
1573
1757
|
authorName: parseFlagValue(args, "--author") ?? "Artis CLI",
|
|
1574
|
-
comment
|
|
1575
|
-
role: "agent"
|
|
1758
|
+
comment
|
|
1576
1759
|
}
|
|
1577
1760
|
}
|
|
1578
1761
|
);
|
|
@@ -1624,12 +1807,23 @@ function parseDuration(value) {
|
|
|
1624
1807
|
const unitMs = { ms: 1, s: 1e3, m: 6e4, h: 36e5 }[match[2] ?? "s"];
|
|
1625
1808
|
return Number(match[1]) * unitMs;
|
|
1626
1809
|
}
|
|
1810
|
+
var watchSelfScopes = ["origin", "client", "none"];
|
|
1811
|
+
function parseSelfFlag(args) {
|
|
1812
|
+
const value = parseFlagValue(args, "--self");
|
|
1813
|
+
if (value === void 0) {
|
|
1814
|
+
return hasFlag(args, "--include-self") ? "none" : void 0;
|
|
1815
|
+
}
|
|
1816
|
+
if (!watchSelfScopes.includes(value)) {
|
|
1817
|
+
throw usageError(`Invalid --self "${value}". Use origin, client or none.`);
|
|
1818
|
+
}
|
|
1819
|
+
return value;
|
|
1820
|
+
}
|
|
1627
1821
|
async function watchArtifactFromCli(args) {
|
|
1628
1822
|
const [artifactRef] = getPositionals(args);
|
|
1629
1823
|
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1630
1824
|
if (!artifactId) {
|
|
1631
1825
|
throw usageError(
|
|
1632
|
-
"Usage: artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--
|
|
1826
|
+
"Usage: artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--self origin|client|none] [--types <families>]"
|
|
1633
1827
|
);
|
|
1634
1828
|
}
|
|
1635
1829
|
const typesFlag = parseFlagValue(args, "--types");
|
|
@@ -1643,9 +1837,10 @@ async function watchArtifactFromCli(args) {
|
|
|
1643
1837
|
const timeoutFlag = parseFlagValue(args, "--timeout");
|
|
1644
1838
|
const deadline = timeoutFlag !== void 0 ? Date.now() + parseDuration(timeoutFlag) : void 0;
|
|
1645
1839
|
const once = hasFlag(args, "--once");
|
|
1646
|
-
const
|
|
1647
|
-
|
|
1648
|
-
|
|
1840
|
+
const self = parseSelfFlag(args);
|
|
1841
|
+
let credentials = await resolveCredentials(args);
|
|
1842
|
+
let api = apiClient(credentials);
|
|
1843
|
+
let reauthorized = false;
|
|
1649
1844
|
let backoffMs = watchInitialBackoffMs;
|
|
1650
1845
|
let delivered = false;
|
|
1651
1846
|
const timedOut = () => new CliError(
|
|
@@ -1679,7 +1874,7 @@ async function watchArtifactFromCli(args) {
|
|
|
1679
1874
|
query: {
|
|
1680
1875
|
wait: Math.min(watchMaxWaitSeconds, Math.floor(remainingMs / 1e3)),
|
|
1681
1876
|
since: cursor,
|
|
1682
|
-
|
|
1877
|
+
self,
|
|
1683
1878
|
types
|
|
1684
1879
|
}
|
|
1685
1880
|
});
|
|
@@ -1690,6 +1885,15 @@ async function watchArtifactFromCli(args) {
|
|
|
1690
1885
|
}
|
|
1691
1886
|
return;
|
|
1692
1887
|
}
|
|
1888
|
+
if (error.status === 401 && !reauthorized) {
|
|
1889
|
+
reauthorized = true;
|
|
1890
|
+
const next = await resolveCredentials(args).catch(() => void 0);
|
|
1891
|
+
if (next && next.accessToken !== credentials.accessToken) {
|
|
1892
|
+
credentials = next;
|
|
1893
|
+
api = apiClient(credentials);
|
|
1894
|
+
continue;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1693
1897
|
if ((error.status === 429 || error.status >= 500) && !once) {
|
|
1694
1898
|
if (await backOff()) {
|
|
1695
1899
|
continue;
|
|
@@ -1702,6 +1906,7 @@ async function watchArtifactFromCli(args) {
|
|
|
1702
1906
|
);
|
|
1703
1907
|
}
|
|
1704
1908
|
backoffMs = watchInitialBackoffMs;
|
|
1909
|
+
reauthorized = false;
|
|
1705
1910
|
const { events } = page;
|
|
1706
1911
|
cursor = page.cursor;
|
|
1707
1912
|
if (events.length === 0) {
|
|
@@ -1836,6 +2041,120 @@ async function readJsonObjectFlag(args, flag) {
|
|
|
1836
2041
|
function printJson(value) {
|
|
1837
2042
|
console.log(JSON.stringify(value, null, 2));
|
|
1838
2043
|
}
|
|
2044
|
+
var assetUsage = `Usage:
|
|
2045
|
+
artis asset upload <artifact> <file> [--name <name>] [--content-type <type>]
|
|
2046
|
+
artis asset list <artifact>
|
|
2047
|
+
artis asset get <artifact> <asset-id> [--output <path>]
|
|
2048
|
+
artis asset rm <artifact> <asset-id>`;
|
|
2049
|
+
var textAssetTypes = {
|
|
2050
|
+
".json": "application/json",
|
|
2051
|
+
".csv": "text/csv",
|
|
2052
|
+
".txt": "text/plain",
|
|
2053
|
+
".svg": "image/svg+xml"
|
|
2054
|
+
};
|
|
2055
|
+
async function fetchAssetContent(credentials, artifactId, assetId) {
|
|
2056
|
+
const response = await fetch(
|
|
2057
|
+
`${credentials.baseUrl.replace(/\/+$/, "")}/api/artifacts/${encodeURIComponent(artifactId)}/assets/${encodeURIComponent(assetId)}/content`,
|
|
2058
|
+
{
|
|
2059
|
+
headers: credentials.accessToken ? {
|
|
2060
|
+
authorization: `Bearer ${credentials.accessToken}`,
|
|
2061
|
+
...credentials.origin ? { "artis-origin": credentials.origin } : {}
|
|
2062
|
+
} : {}
|
|
2063
|
+
}
|
|
2064
|
+
);
|
|
2065
|
+
if (!response.ok) {
|
|
2066
|
+
let body = {};
|
|
2067
|
+
try {
|
|
2068
|
+
body = await response.json();
|
|
2069
|
+
} catch {
|
|
2070
|
+
}
|
|
2071
|
+
throw cliErrorOf(
|
|
2072
|
+
new ApiError(
|
|
2073
|
+
response.status,
|
|
2074
|
+
typeof body["code"] === "string" ? body["code"] : "http_error",
|
|
2075
|
+
typeof body["error"] === "string" ? body["error"] : `Request failed with ${response.status}.`,
|
|
2076
|
+
body,
|
|
2077
|
+
response.headers
|
|
2078
|
+
)
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
return {
|
|
2082
|
+
bytes: new Uint8Array(await response.arrayBuffer()),
|
|
2083
|
+
contentType: response.headers.get("artis-asset-content-type") ?? "application/octet-stream"
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
async function assetFromCli(args) {
|
|
2087
|
+
const [action, artifactRef, target, extra] = getPositionals(args);
|
|
2088
|
+
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
2089
|
+
if (!artifactId || extra !== void 0 || !["upload", "list", "get", "rm"].includes(action ?? "") || (action === "list" ? target !== void 0 : target === void 0)) {
|
|
2090
|
+
throw usageError(assetUsage);
|
|
2091
|
+
}
|
|
2092
|
+
const credentials = await resolveCredentials(args);
|
|
2093
|
+
switch (action) {
|
|
2094
|
+
case "upload": {
|
|
2095
|
+
const filePath = target;
|
|
2096
|
+
let bytes;
|
|
2097
|
+
try {
|
|
2098
|
+
bytes = await readFile(filePath);
|
|
2099
|
+
} catch {
|
|
2100
|
+
throw usageError(`Could not read "${filePath}".`);
|
|
2101
|
+
}
|
|
2102
|
+
const contentType = parseFlagValue(args, "--content-type") ?? textAssetTypes[extname(filePath).toLowerCase()] ?? "application/octet-stream";
|
|
2103
|
+
printJson(
|
|
2104
|
+
await apiCall(credentials, "POST /api/artifacts/{artifactId}/assets", {
|
|
2105
|
+
params: { artifactId },
|
|
2106
|
+
query: { name: parseFlagValue(args, "--name") ?? basename(filePath) },
|
|
2107
|
+
body: new Uint8Array(
|
|
2108
|
+
bytes.buffer,
|
|
2109
|
+
bytes.byteOffset,
|
|
2110
|
+
bytes.byteLength
|
|
2111
|
+
),
|
|
2112
|
+
headers: { "content-type": contentType }
|
|
2113
|
+
})
|
|
2114
|
+
);
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
case "list": {
|
|
2118
|
+
printJson(
|
|
2119
|
+
await apiCall(credentials, "GET /api/artifacts/{artifactId}/assets", {
|
|
2120
|
+
params: { artifactId }
|
|
2121
|
+
})
|
|
2122
|
+
);
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
case "get": {
|
|
2126
|
+
const assetId = target;
|
|
2127
|
+
const output = parseFlagValue(args, "--output");
|
|
2128
|
+
if (!output) {
|
|
2129
|
+
printJson(
|
|
2130
|
+
await apiCall(
|
|
2131
|
+
credentials,
|
|
2132
|
+
"GET /api/artifacts/{artifactId}/assets/{assetId}",
|
|
2133
|
+
{ params: { artifactId, assetId } }
|
|
2134
|
+
)
|
|
2135
|
+
);
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2138
|
+
const { bytes: data } = await fetchAssetContent(
|
|
2139
|
+
credentials,
|
|
2140
|
+
artifactId,
|
|
2141
|
+
assetId
|
|
2142
|
+
);
|
|
2143
|
+
await writeFile(output, data);
|
|
2144
|
+
console.error(`Wrote ${data.byteLength} bytes to ${output}.`);
|
|
2145
|
+
return;
|
|
2146
|
+
}
|
|
2147
|
+
case "rm": {
|
|
2148
|
+
await apiCall(
|
|
2149
|
+
credentials,
|
|
2150
|
+
"DELETE /api/artifacts/{artifactId}/assets/{assetId}",
|
|
2151
|
+
{ params: { artifactId, assetId: target } }
|
|
2152
|
+
);
|
|
2153
|
+
console.error(`Deleted asset ${target}.`);
|
|
2154
|
+
return;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
1839
2158
|
async function dataFromCli(args) {
|
|
1840
2159
|
const command = parseDataCommand(args);
|
|
1841
2160
|
const credentials = await resolveCredentials(args);
|
|
@@ -2034,8 +2353,9 @@ async function runArtisCli(args = process.argv.slice(2)) {
|
|
|
2034
2353
|
return;
|
|
2035
2354
|
}
|
|
2036
2355
|
if (command === "artifact" && rest[0] === "html") {
|
|
2037
|
-
|
|
2038
|
-
|
|
2356
|
+
throw usageError(
|
|
2357
|
+
"artifact html was removed: every artifact is a set of files, and an html artifact is one, index.html. Use artis artifact files <artifact> index.html (or --output <dir>)."
|
|
2358
|
+
);
|
|
2039
2359
|
}
|
|
2040
2360
|
if (command === "artifact" && rest[0] === "files") {
|
|
2041
2361
|
await getArtifactFilesFromCli(rest.slice(1));
|
|
@@ -2065,6 +2385,10 @@ async function runArtisCli(args = process.argv.slice(2)) {
|
|
|
2065
2385
|
await shareArtifactFromCli(rest);
|
|
2066
2386
|
return;
|
|
2067
2387
|
}
|
|
2388
|
+
if (command === "capabilities") {
|
|
2389
|
+
await capabilitiesFromCli(rest);
|
|
2390
|
+
return;
|
|
2391
|
+
}
|
|
2068
2392
|
if (command === "revise") {
|
|
2069
2393
|
await reviseArtifactFromCli(rest);
|
|
2070
2394
|
return;
|
|
@@ -2093,6 +2417,10 @@ async function runArtisCli(args = process.argv.slice(2)) {
|
|
|
2093
2417
|
await dataFromCli(rest);
|
|
2094
2418
|
return;
|
|
2095
2419
|
}
|
|
2420
|
+
if (command === "asset") {
|
|
2421
|
+
await assetFromCli(rest);
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2096
2424
|
throw usageError(`Unknown command "${args.join(" ")}". Run artis help.`);
|
|
2097
2425
|
}
|
|
2098
2426
|
|
|
@@ -2107,12 +2435,12 @@ export {
|
|
|
2107
2435
|
whoamiFromCli,
|
|
2108
2436
|
getArtifactFromCli,
|
|
2109
2437
|
getArtifactFilesFromCli,
|
|
2110
|
-
getArtifactHtmlFromCli,
|
|
2111
2438
|
verifyFromCli,
|
|
2112
2439
|
listArtifactsFromCli,
|
|
2113
2440
|
getArtifactFeedbackFromCli,
|
|
2114
2441
|
shareArtifactFromCli,
|
|
2115
2442
|
setArtifactVisibilityFromCli,
|
|
2443
|
+
capabilitiesFromCli,
|
|
2116
2444
|
deleteArtifactFromCli,
|
|
2117
2445
|
reviseArtifactFromCli,
|
|
2118
2446
|
createAnnotationFromCli,
|
|
@@ -2121,6 +2449,7 @@ export {
|
|
|
2121
2449
|
retractAnnotationFromCli,
|
|
2122
2450
|
watchArtifactFromCli,
|
|
2123
2451
|
parseDataCommand,
|
|
2452
|
+
assetFromCli,
|
|
2124
2453
|
dataFromCli,
|
|
2125
2454
|
runArtisCli
|
|
2126
2455
|
};
|