@artis-lab/cli 0.14.0 → 0.16.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 +28 -21
- package/package.json +3 -7
- package/src/bin.js +13 -4
- package/src/lib/app.js +13 -4
- package/src/lib/chunk-2GXGXTAO.js +1229 -0
- package/src/lib/{chunk-CT5TD6L2.js → chunk-2LRPXCLL.js} +24 -47
- package/src/lib/chunk-4O5BCFCD.js +60 -0
- package/src/lib/chunk-6PK46UOP.js +1804 -0
- package/src/lib/{chunk-MEPQKMK5.js → chunk-FSJVBXCW.js} +4 -32
- package/src/lib/{chunk-H32QAUSA.js → chunk-HUWOFEEU.js} +7 -0
- package/src/lib/chunk-I5P3FLKO.js +929 -0
- package/src/lib/chunk-IKQ5U3DH.js +146 -0
- package/src/lib/chunk-XZYT3B5O.js +113 -0
- package/src/lib/cli.js +87 -61
- package/src/lib/commands.js +25 -0
- package/src/lib/exit-codes.js +5 -3
- package/src/lib/files.js +3 -2
- package/src/lib/next-actions.js +12 -5
- package/src/lib/skill-install.js +9 -4
- package/src/lib/verify.js +2 -3
- package/src/bin.d.ts +0 -2
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -76
- package/src/lib/app.d.ts +0 -3
- package/src/lib/args.d.ts +0 -4
- package/src/lib/args.js +0 -12
- package/src/lib/chunk-CCCATRMP.js +0 -591
- package/src/lib/chunk-KJV7R7DE.js +0 -82
- package/src/lib/chunk-PG7WDW5F.js +0 -2420
- package/src/lib/chunk-Q5KBGVKT.js +0 -155
- package/src/lib/chunk-QZFIUZXT.js +0 -10954
- package/src/lib/cli.d.ts +0 -147
- package/src/lib/config.d.ts +0 -50
- package/src/lib/exit-codes.d.ts +0 -28
- package/src/lib/files.d.ts +0 -19
- package/src/lib/next-actions.d.ts +0 -13
- package/src/lib/oauth.d.ts +0 -45
- package/src/lib/revision-bases.d.ts +0 -9
- package/src/lib/skill-install.d.ts +0 -50
- package/src/lib/verify.d.ts +0 -152
- package/src/lib/version.d.ts +0 -9
|
@@ -0,0 +1,1804 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OAuthError,
|
|
3
|
+
pollDeviceToken,
|
|
4
|
+
refreshTokens,
|
|
5
|
+
revokeToken,
|
|
6
|
+
startDeviceAuthorization
|
|
7
|
+
} from "./chunk-43WVFZLO.js";
|
|
8
|
+
import {
|
|
9
|
+
getRememberedBase,
|
|
10
|
+
rememberBase
|
|
11
|
+
} from "./chunk-JYMG2Y6C.js";
|
|
12
|
+
import {
|
|
13
|
+
ARTIS_DEFAULT_HOST,
|
|
14
|
+
findProfileForHost,
|
|
15
|
+
getConfigPath,
|
|
16
|
+
normalizeHost,
|
|
17
|
+
readCliConfig,
|
|
18
|
+
resolveOrigin,
|
|
19
|
+
saveDefaultProfile,
|
|
20
|
+
updateProfileTokens,
|
|
21
|
+
withConfigLock
|
|
22
|
+
} from "./chunk-46DMRA3V.js";
|
|
23
|
+
import {
|
|
24
|
+
changedFiles,
|
|
25
|
+
readFilesDir,
|
|
26
|
+
writeFilesDir
|
|
27
|
+
} from "./chunk-FSJVBXCW.js";
|
|
28
|
+
import {
|
|
29
|
+
isTypePackageName
|
|
30
|
+
} from "./chunk-4O5BCFCD.js";
|
|
31
|
+
import {
|
|
32
|
+
CliError,
|
|
33
|
+
exitCodeForResponse,
|
|
34
|
+
exitCodes,
|
|
35
|
+
usageError
|
|
36
|
+
} from "./chunk-HUWOFEEU.js";
|
|
37
|
+
|
|
38
|
+
// packages/cli/src/lib/cli.ts
|
|
39
|
+
import { spawn } from "node:child_process";
|
|
40
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
41
|
+
import { basename, extname } from "node:path";
|
|
42
|
+
|
|
43
|
+
// packages/api-contract/src/client.ts
|
|
44
|
+
var htmlUploadContentType = "text/html; charset=utf-8";
|
|
45
|
+
var ApiError = class extends Error {
|
|
46
|
+
constructor(status, code, message, body, headers) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.status = status;
|
|
49
|
+
this.code = code;
|
|
50
|
+
this.body = body;
|
|
51
|
+
this.name = "ApiError";
|
|
52
|
+
const retryAfter = Number(headers?.get("retry-after"));
|
|
53
|
+
this.retryAfter = Number.isFinite(retryAfter) && retryAfter > 0 ? retryAfter : void 0;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
function appendQuery(query, name, value) {
|
|
57
|
+
if (value === void 0 || value === null) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(value)) {
|
|
61
|
+
for (const item of value) appendQuery(query, name, item);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
query.append(
|
|
65
|
+
name,
|
|
66
|
+
typeof value === "object" ? JSON.stringify(value) : String(value)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
function buildRequest(baseUrl, key, input = {}) {
|
|
70
|
+
const space = key.indexOf(" ");
|
|
71
|
+
const method = key.slice(0, space);
|
|
72
|
+
const path = key.slice(space + 1).replace(/\{([^}]+)\}/g, (_, name) => {
|
|
73
|
+
const value = input.params?.[name];
|
|
74
|
+
if (value === void 0) {
|
|
75
|
+
throw new Error(`${key}: missing path parameter ${name}`);
|
|
76
|
+
}
|
|
77
|
+
return encodeURIComponent(value);
|
|
78
|
+
});
|
|
79
|
+
const query = new URLSearchParams();
|
|
80
|
+
for (const [name, value] of Object.entries(input.query ?? {})) {
|
|
81
|
+
appendQuery(query, name, value);
|
|
82
|
+
}
|
|
83
|
+
const search = query.toString();
|
|
84
|
+
const headers = {};
|
|
85
|
+
let body;
|
|
86
|
+
if (typeof Blob !== "undefined" && input.body instanceof Blob) {
|
|
87
|
+
headers["content-type"] = "application/octet-stream";
|
|
88
|
+
body = input.body;
|
|
89
|
+
} else if (typeof input.body === "string" || input.body instanceof Uint8Array) {
|
|
90
|
+
const bytes = typeof input.body === "string" ? new TextEncoder().encode(input.body) : input.body;
|
|
91
|
+
headers["content-type"] = htmlUploadContentType;
|
|
92
|
+
headers["content-length"] = String(bytes.byteLength);
|
|
93
|
+
body = bytes;
|
|
94
|
+
} else if (input.body !== void 0) {
|
|
95
|
+
headers["content-type"] = "application/json";
|
|
96
|
+
body = JSON.stringify(input.body);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
url: `${baseUrl.replace(/\/+$/, "")}${path}${search ? `?${search}` : ""}`,
|
|
100
|
+
init: {
|
|
101
|
+
method,
|
|
102
|
+
headers: { ...headers, ...input.headers },
|
|
103
|
+
...body === void 0 ? {} : { body }
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async function readBody(response) {
|
|
108
|
+
if (/^application\/octet-stream\b/i.test(
|
|
109
|
+
response.headers.get("content-type") ?? ""
|
|
110
|
+
)) {
|
|
111
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
112
|
+
}
|
|
113
|
+
const text = await response.text();
|
|
114
|
+
if (!text) {
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
117
|
+
const type = response.headers.get("content-type") ?? "";
|
|
118
|
+
if (!/json/i.test(type)) {
|
|
119
|
+
return text;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse(text);
|
|
123
|
+
} catch {
|
|
124
|
+
return text;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function errorOf(response, body) {
|
|
128
|
+
const record = body && typeof body === "object" && !Array.isArray(body) ? body : void 0;
|
|
129
|
+
const message = typeof record?.["error"] === "string" ? record["error"] : `Request failed with ${response.status}.`;
|
|
130
|
+
const code = typeof record?.["code"] === "string" ? record["code"] : "http_error";
|
|
131
|
+
return new ApiError(response.status, code, message, record, response.headers);
|
|
132
|
+
}
|
|
133
|
+
function createApiClient(options) {
|
|
134
|
+
const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
135
|
+
async function send(key, input = {}) {
|
|
136
|
+
const { url, init } = buildRequest(
|
|
137
|
+
options.baseUrl,
|
|
138
|
+
key,
|
|
139
|
+
input
|
|
140
|
+
);
|
|
141
|
+
const headers = init.headers;
|
|
142
|
+
for (const [name, value] of Object.entries(options.headers ?? {})) {
|
|
143
|
+
headers[name.toLowerCase()] ??= value;
|
|
144
|
+
}
|
|
145
|
+
if (options.auth && options.auth !== "cookie") {
|
|
146
|
+
headers["authorization"] = `Bearer ${options.auth.bearer}`;
|
|
147
|
+
}
|
|
148
|
+
const response = await fetchImpl(url, {
|
|
149
|
+
...init,
|
|
150
|
+
...options.auth === "cookie" ? { credentials: "include" } : {},
|
|
151
|
+
...input["signal"] ? { signal: input["signal"] } : {}
|
|
152
|
+
});
|
|
153
|
+
const body = await readBody(response);
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
throw errorOf(response, body);
|
|
156
|
+
}
|
|
157
|
+
return { status: response.status, body, headers: response.headers };
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
send,
|
|
161
|
+
call: (async (key, input) => (await send(key, input)).body),
|
|
162
|
+
withAuth: (auth) => createApiClient({ ...options, auth })
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// packages/sdk/src/lib/annotation.ts
|
|
167
|
+
function annotationIdFromIri(iri) {
|
|
168
|
+
return iri.replace(/\/+$/, "").split("/").pop() ?? iri;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// packages/sdk/src/lib/agent-handoff.ts
|
|
172
|
+
function isReviewClosed(status) {
|
|
173
|
+
return status === "resolved";
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// packages/sdk/src/lib/sdk.ts
|
|
177
|
+
var artifactShareRoles = [
|
|
178
|
+
"viewer",
|
|
179
|
+
"commenter",
|
|
180
|
+
"contributor",
|
|
181
|
+
"editor"
|
|
182
|
+
];
|
|
183
|
+
var artifactListLimits = { default: 50, max: 100 };
|
|
184
|
+
function formatRevisionConflictMessage(message, details) {
|
|
185
|
+
if (!details?.currentRevisionId) {
|
|
186
|
+
return message;
|
|
187
|
+
}
|
|
188
|
+
let text = `${message} Current revision: ${details.currentRevisionId}.`;
|
|
189
|
+
if (typeof details.currentVersion === "number") {
|
|
190
|
+
const [firstLine] = revisionSummaryLines(details.currentSummary ?? "");
|
|
191
|
+
text += firstLine ? ` Version ${details.currentVersion}: ${firstLine}` : ` Version ${details.currentVersion}.`;
|
|
192
|
+
}
|
|
193
|
+
return text;
|
|
194
|
+
}
|
|
195
|
+
function revisionSummaryLines(summary) {
|
|
196
|
+
return summary.split(/\r?\n/).map((line) => line.replace(/^\s*(?:[-*•]\s+)?/, "").trim()).filter(Boolean);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// packages/sdk/src/lib/page-storage.ts
|
|
200
|
+
var storageLimits = {
|
|
201
|
+
/** One document, serialized as UTF-8 JSON. */
|
|
202
|
+
maxDocBytes: 256 * 1024,
|
|
203
|
+
/** A document on a `{viewer}` path, unless its rule raises `maxBytes`. */
|
|
204
|
+
maxViewerDocBytes: 16 * 1024,
|
|
205
|
+
maxDepth: 32,
|
|
206
|
+
maxPathBytes: 512,
|
|
207
|
+
maxSegments: 16,
|
|
208
|
+
maxSegmentBytes: 128,
|
|
209
|
+
maxArtifactDocuments: 25e3,
|
|
210
|
+
maxArtifactBytes: 16 * 1024 * 1024,
|
|
211
|
+
maxOwnerBytes: 256 * 1024 * 1024,
|
|
212
|
+
maxRules: 64,
|
|
213
|
+
maxBatchOps: 50,
|
|
214
|
+
/** Sum of the serialized values and patches in one batch. */
|
|
215
|
+
maxBatchBytes: 1024 * 1024,
|
|
216
|
+
maxListLimit: 1e3,
|
|
217
|
+
idempotencyTtlMs: 24 * 60 * 60 * 1e3
|
|
218
|
+
};
|
|
219
|
+
var encoder = new TextEncoder();
|
|
220
|
+
var storageOnlyCodes = /* @__PURE__ */ new Set([
|
|
221
|
+
"version_conflict",
|
|
222
|
+
"capability_not_declared",
|
|
223
|
+
"rules_changed",
|
|
224
|
+
"quota_exceeded",
|
|
225
|
+
"too_large",
|
|
226
|
+
"invalid_path",
|
|
227
|
+
"invalid_value",
|
|
228
|
+
"idempotency_in_progress",
|
|
229
|
+
"idempotency_key_used",
|
|
230
|
+
"idempotency_key_reused"
|
|
231
|
+
]);
|
|
232
|
+
function formatStorageErrorMessage(message, body) {
|
|
233
|
+
if (!body) return message;
|
|
234
|
+
const storageCode = typeof body["code"] === "string" && storageOnlyCodes.has(body["code"]);
|
|
235
|
+
const details = [];
|
|
236
|
+
if (typeof body["code"] === "string") details.push(`code ${body["code"]}`);
|
|
237
|
+
if (typeof body["index"] === "number")
|
|
238
|
+
details.push(`write #${body["index"]}`);
|
|
239
|
+
if (typeof body["path"] === "string") details.push(`path ${body["path"]}`);
|
|
240
|
+
if (body["current"]) {
|
|
241
|
+
details.push(`current ${JSON.stringify(body["current"])}`);
|
|
242
|
+
}
|
|
243
|
+
if (body["quota"]) details.push(`quota ${JSON.stringify(body["quota"])}`);
|
|
244
|
+
return storageCode || details.length > 1 ? `${message} (${details.join("; ")})` : message;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// packages/sdk/src/lib/ids.ts
|
|
248
|
+
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
249
|
+
function isUuid(value) {
|
|
250
|
+
return typeof value === "string" && UUID_PATTERN.test(value);
|
|
251
|
+
}
|
|
252
|
+
var BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
253
|
+
var SHORT_ID_LENGTH = 22;
|
|
254
|
+
function artifactShortId(id) {
|
|
255
|
+
if (!isUuid(id)) throw new Error(`Not a uuid: ${id}`);
|
|
256
|
+
const hex = id.replace(/-/g, "");
|
|
257
|
+
const bytes = [];
|
|
258
|
+
for (let i = 0; i < 32; i += 2) bytes.push(parseInt(hex.slice(i, i + 2), 16));
|
|
259
|
+
let out = "";
|
|
260
|
+
for (let digit = 0; digit < SHORT_ID_LENGTH; digit += 1) {
|
|
261
|
+
let remainder = 0;
|
|
262
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
263
|
+
const value = remainder * 256 + bytes[i];
|
|
264
|
+
bytes[i] = Math.floor(value / 62);
|
|
265
|
+
remainder = value % 62;
|
|
266
|
+
}
|
|
267
|
+
out = BASE62[remainder] + out;
|
|
268
|
+
}
|
|
269
|
+
return out;
|
|
270
|
+
}
|
|
271
|
+
function artifactIdFromShortId(value) {
|
|
272
|
+
if (value.length !== SHORT_ID_LENGTH) return void 0;
|
|
273
|
+
const bytes = new Array(16).fill(0);
|
|
274
|
+
for (const char of value) {
|
|
275
|
+
const digit = BASE62.indexOf(char);
|
|
276
|
+
if (digit < 0) return void 0;
|
|
277
|
+
let carry = digit;
|
|
278
|
+
for (let i = 15; i >= 0; i -= 1) {
|
|
279
|
+
const next = bytes[i] * 62 + carry;
|
|
280
|
+
bytes[i] = next % 256;
|
|
281
|
+
carry = Math.floor(next / 256);
|
|
282
|
+
}
|
|
283
|
+
if (carry !== 0) return void 0;
|
|
284
|
+
}
|
|
285
|
+
const hex = bytes.map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
286
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
287
|
+
}
|
|
288
|
+
function artifactIdFromReference(reference) {
|
|
289
|
+
const value = reference.trim();
|
|
290
|
+
if (isUuid(value)) return value;
|
|
291
|
+
const short = artifactIdFromShortId(value);
|
|
292
|
+
if (short) return short;
|
|
293
|
+
let url;
|
|
294
|
+
try {
|
|
295
|
+
url = new URL(value);
|
|
296
|
+
} catch {
|
|
297
|
+
return void 0;
|
|
298
|
+
}
|
|
299
|
+
const page = /^\/a\/([0-9A-Za-z]+)\/?$/.exec(url.pathname);
|
|
300
|
+
if (page) return artifactIdFromShortId(page[1]);
|
|
301
|
+
const label = url.hostname.split(".")[0];
|
|
302
|
+
return isUuid(label) ? label : void 0;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// packages/cli/src/lib/cli.ts
|
|
306
|
+
function isRootAnnotation(annotation) {
|
|
307
|
+
return annotation.motivation === "commenting";
|
|
308
|
+
}
|
|
309
|
+
async function readHtmlUpload(filePath, what) {
|
|
310
|
+
const bytes = await readFile(filePath);
|
|
311
|
+
if (!/<html/i.test(bytes.toString("latin1"))) {
|
|
312
|
+
throw new Error(`${what} must be self-contained HTML including <html>.`);
|
|
313
|
+
}
|
|
314
|
+
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
315
|
+
}
|
|
316
|
+
var cliVisibilityOptions = ["public", "unlisted", "private"];
|
|
317
|
+
var cliAnnotationStatusOptions = ["open", "resolved"];
|
|
318
|
+
function inferTitleFromPath(filePath) {
|
|
319
|
+
const fileName = basename(filePath);
|
|
320
|
+
const extension = extname(fileName);
|
|
321
|
+
return extension ? fileName.slice(0, -extension.length) : fileName;
|
|
322
|
+
}
|
|
323
|
+
function parseVisibility(value) {
|
|
324
|
+
if (cliVisibilityOptions.includes(value)) {
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
throw usageError(
|
|
328
|
+
`Invalid visibility "${value}". Expected one of: ${cliVisibilityOptions.join(", ")}`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
async function parseCapabilitiesFlag(value, flag = "--capabilities") {
|
|
332
|
+
if (value === void 0) {
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
let source = value;
|
|
336
|
+
if (!value.trim().startsWith("{")) {
|
|
337
|
+
try {
|
|
338
|
+
source = await readFile(value, "utf8");
|
|
339
|
+
} catch {
|
|
340
|
+
throw usageError(
|
|
341
|
+
`${flag} must be a JSON object or a path to a JSON file; could not read "${value}".`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
let parsed;
|
|
346
|
+
try {
|
|
347
|
+
parsed = JSON.parse(source);
|
|
348
|
+
} catch {
|
|
349
|
+
throw usageError(`${flag} is not valid JSON.`);
|
|
350
|
+
}
|
|
351
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
352
|
+
throw usageError(
|
|
353
|
+
`${flag} must be a JSON object, e.g. '{"<name>":true}' ({} clears them).`
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
return parsed;
|
|
357
|
+
}
|
|
358
|
+
function parseTypeFlag(value) {
|
|
359
|
+
if (value === void 0) {
|
|
360
|
+
return void 0;
|
|
361
|
+
}
|
|
362
|
+
if (!value.trim()) {
|
|
363
|
+
throw usageError("--type must name a type, e.g. slides.");
|
|
364
|
+
}
|
|
365
|
+
return value.trim();
|
|
366
|
+
}
|
|
367
|
+
function parseAnnotationStatus(value) {
|
|
368
|
+
if (cliAnnotationStatusOptions.includes(value)) {
|
|
369
|
+
return value;
|
|
370
|
+
}
|
|
371
|
+
throw usageError(
|
|
372
|
+
`Invalid status "${value}". Expected one of: ${cliAnnotationStatusOptions.join(", ")}`
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
function parseShareRole(value) {
|
|
376
|
+
if (artifactShareRoles.includes(value)) {
|
|
377
|
+
return value;
|
|
378
|
+
}
|
|
379
|
+
throw usageError(
|
|
380
|
+
`Invalid role "${value}". Expected one of: ${artifactShareRoles.join(", ")}`
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
function parseRectSelector(value) {
|
|
384
|
+
if (!value) {
|
|
385
|
+
return void 0;
|
|
386
|
+
}
|
|
387
|
+
const parts = value.split(",").map((part) => Number(part.trim()));
|
|
388
|
+
if (parts.length !== 2 && parts.length !== 4 || parts.some((part) => !Number.isFinite(part))) {
|
|
389
|
+
throw usageError(
|
|
390
|
+
`Invalid --rect "${value}". Expected "x,y" or "x,y,w,h" percentages.`
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
const [x, y, width = 0, height = 0] = parts;
|
|
394
|
+
return {
|
|
395
|
+
type: "FragmentSelector",
|
|
396
|
+
conformsTo: "http://www.w3.org/TR/media-frags/",
|
|
397
|
+
value: `xywh=percent:${x},${y},${width},${height}`
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
function buildAnnotationSelectors(input) {
|
|
401
|
+
const selectors = [];
|
|
402
|
+
const quote = input.quote;
|
|
403
|
+
if (quote) {
|
|
404
|
+
const textQuote = {
|
|
405
|
+
type: "TextQuoteSelector",
|
|
406
|
+
exact: quote
|
|
407
|
+
};
|
|
408
|
+
const prefix = input.quotePrefix;
|
|
409
|
+
const suffix = input.quoteSuffix;
|
|
410
|
+
if (prefix) {
|
|
411
|
+
textQuote.prefix = prefix;
|
|
412
|
+
}
|
|
413
|
+
if (suffix) {
|
|
414
|
+
textQuote.suffix = suffix;
|
|
415
|
+
}
|
|
416
|
+
selectors.push(textQuote);
|
|
417
|
+
}
|
|
418
|
+
const { textStart, textEnd } = input;
|
|
419
|
+
if (textStart !== void 0 && textEnd !== void 0) {
|
|
420
|
+
const start = Number(textStart);
|
|
421
|
+
const end = Number(textEnd);
|
|
422
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) {
|
|
423
|
+
throw usageError("--text-start and --text-end must be numbers.");
|
|
424
|
+
}
|
|
425
|
+
selectors.push({ type: "TextPositionSelector", start, end });
|
|
426
|
+
}
|
|
427
|
+
const css = input.css;
|
|
428
|
+
if (css) {
|
|
429
|
+
selectors.push({ type: "CssSelector", value: css });
|
|
430
|
+
}
|
|
431
|
+
const rect = parseRectSelector(input.rect);
|
|
432
|
+
if (rect) {
|
|
433
|
+
selectors.push(rect);
|
|
434
|
+
}
|
|
435
|
+
return selectors;
|
|
436
|
+
}
|
|
437
|
+
function resolveBaseUrl(input, config) {
|
|
438
|
+
const host = input.host || config?.defaultHost || ARTIS_DEFAULT_HOST;
|
|
439
|
+
return normalizeHost(host);
|
|
440
|
+
}
|
|
441
|
+
var refreshMarginMs = 6e4;
|
|
442
|
+
function needsRefresh(profile) {
|
|
443
|
+
return profile.expiresAt !== void 0 && profile.expiresAt - refreshMarginMs <= Date.now() && Boolean(profile.refreshToken);
|
|
444
|
+
}
|
|
445
|
+
async function savedAccessToken(config, baseUrl) {
|
|
446
|
+
const saved = findProfileForHost(config, baseUrl);
|
|
447
|
+
if (!saved) return void 0;
|
|
448
|
+
if (!needsRefresh(saved)) return saved.accessToken;
|
|
449
|
+
return withConfigLock(async () => {
|
|
450
|
+
const profile = findProfileForHost(await readCliConfig(), baseUrl);
|
|
451
|
+
if (!profile) return void 0;
|
|
452
|
+
if (!needsRefresh(profile) || !profile.refreshToken) {
|
|
453
|
+
return profile.accessToken;
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
456
|
+
const tokens = await refreshTokens(baseUrl, profile.refreshToken);
|
|
457
|
+
await updateProfileTokens(baseUrl, {
|
|
458
|
+
accessToken: tokens.accessToken,
|
|
459
|
+
refreshToken: tokens.refreshToken ?? profile.refreshToken,
|
|
460
|
+
expiresAt: tokens.expiresAt
|
|
461
|
+
});
|
|
462
|
+
return tokens.accessToken;
|
|
463
|
+
} catch (error) {
|
|
464
|
+
if (error instanceof OAuthError && error.status < 500 && error.status !== 429) {
|
|
465
|
+
return void 0;
|
|
466
|
+
}
|
|
467
|
+
return profile.accessToken;
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
async function resolveCredentials(input) {
|
|
472
|
+
const config = await readCliConfig();
|
|
473
|
+
const baseUrl = resolveBaseUrl(input, config);
|
|
474
|
+
const accessToken = await savedAccessToken(config, baseUrl);
|
|
475
|
+
if (!accessToken) {
|
|
476
|
+
throw new CliError(
|
|
477
|
+
`Not signed in to ${baseUrl}. Run "artis login --host ${baseUrl}".`,
|
|
478
|
+
exitCodes.auth
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
return { accessToken, baseUrl, origin: await resolveOrigin() };
|
|
482
|
+
}
|
|
483
|
+
async function resolveOptionalTarget(input) {
|
|
484
|
+
const config = await readCliConfig();
|
|
485
|
+
const baseUrl = resolveBaseUrl(input, config);
|
|
486
|
+
const accessToken = await savedAccessToken(config, baseUrl);
|
|
487
|
+
return {
|
|
488
|
+
accessToken,
|
|
489
|
+
baseUrl,
|
|
490
|
+
origin: accessToken ? await resolveOrigin() : void 0
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
async function readGuidelines(input) {
|
|
494
|
+
const config = await readCliConfig();
|
|
495
|
+
const baseUrl = resolveBaseUrl(input, config);
|
|
496
|
+
const query = new URLSearchParams({ section: input.section ?? "index" });
|
|
497
|
+
const response = await fetch(`${baseUrl}/skills.md?${query.toString()}`);
|
|
498
|
+
const text = await response.text();
|
|
499
|
+
if (!response.ok) {
|
|
500
|
+
throw new CliError(
|
|
501
|
+
text.trim() || `Guidelines request failed with ${response.status}.`,
|
|
502
|
+
exitCodeForResponse(response.status)
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
return text;
|
|
506
|
+
}
|
|
507
|
+
async function apiCallRoot(root, credentials, key, ...input) {
|
|
508
|
+
try {
|
|
509
|
+
return await apiClient(credentials).call(key, ...input);
|
|
510
|
+
} catch (error) {
|
|
511
|
+
const cliError = cliErrorOf(error, {
|
|
512
|
+
artifact: root.artifact,
|
|
513
|
+
root: root.dir
|
|
514
|
+
});
|
|
515
|
+
const issue = error instanceof ApiError && layoutIssueOf(error);
|
|
516
|
+
if (!issue || !(cliError instanceof CliError)) throw cliError;
|
|
517
|
+
const stray = /does not take (\S+):/.exec(issue)?.[1];
|
|
518
|
+
let hint = stray ? ` Every file under --root is sent (dotfiles and node_modules are skipped): move ${stray} out of ${root.dir}.` : "";
|
|
519
|
+
if (root.untyped) {
|
|
520
|
+
hint += " Without --type the files are an html artifact; for another type, pass --type <type>, e.g. --type slides.";
|
|
521
|
+
}
|
|
522
|
+
throw new CliError(`${cliError.message}${hint}`, cliError.exitCode);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function layoutIssueOf(error) {
|
|
526
|
+
if (error.status !== 400 || error.code !== "invalid_request") {
|
|
527
|
+
return void 0;
|
|
528
|
+
}
|
|
529
|
+
const issues = error.body?.["issues"];
|
|
530
|
+
if (!Array.isArray(issues)) return void 0;
|
|
531
|
+
for (const issue of issues) {
|
|
532
|
+
if (!issue || typeof issue !== "object") continue;
|
|
533
|
+
const { path, message } = issue;
|
|
534
|
+
if ((path === "files" || path === "type") && typeof message === "string") {
|
|
535
|
+
return message;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return void 0;
|
|
539
|
+
}
|
|
540
|
+
function conflictingPathsHint(body, context = {}) {
|
|
541
|
+
const paths = body?.["conflictingPaths"];
|
|
542
|
+
if (body?.["code"] !== "revision_conflict" || !Array.isArray(paths) || paths.length === 0) {
|
|
543
|
+
return "";
|
|
544
|
+
}
|
|
545
|
+
const artifact = context.artifact ?? "<artifact>";
|
|
546
|
+
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.`;
|
|
547
|
+
return `Conflicting files: ${paths.join(", ")}. ${recover}`;
|
|
548
|
+
}
|
|
549
|
+
function cliErrorOf(error, context = {}) {
|
|
550
|
+
if (!(error instanceof ApiError)) {
|
|
551
|
+
return error;
|
|
552
|
+
}
|
|
553
|
+
let message = formatStorageErrorMessage(
|
|
554
|
+
formatRevisionConflictMessage(error.message, error.body),
|
|
555
|
+
error.body
|
|
556
|
+
);
|
|
557
|
+
const conflict = conflictingPathsHint(error.body, context);
|
|
558
|
+
if (conflict) {
|
|
559
|
+
message = `${message.replace(/[.\s]*$/, "")}. ${conflict}`;
|
|
560
|
+
}
|
|
561
|
+
if (error.status === 429 && error.retryAfter) {
|
|
562
|
+
message += ` Retry after ${error.retryAfter} s.`;
|
|
563
|
+
}
|
|
564
|
+
return new CliError(message, exitCodeForResponse(error.status, error.code));
|
|
565
|
+
}
|
|
566
|
+
function apiClient(target) {
|
|
567
|
+
return createApiClient({
|
|
568
|
+
baseUrl: target.baseUrl,
|
|
569
|
+
auth: target.accessToken ? { bearer: target.accessToken } : void 0,
|
|
570
|
+
headers: target.accessToken && target.origin ? { "artis-origin": target.origin } : void 0
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
async function apiCall(credentials, key, ...input) {
|
|
574
|
+
try {
|
|
575
|
+
return await apiClient(credentials).call(key, ...input);
|
|
576
|
+
} catch (error) {
|
|
577
|
+
throw cliErrorOf(error);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async function apiCallOptional(target, key, ...input) {
|
|
581
|
+
try {
|
|
582
|
+
return await apiClient(target).call(key, ...input);
|
|
583
|
+
} catch (error) {
|
|
584
|
+
if (!(error instanceof ApiError) || error.status !== 401 || !target.accessToken) {
|
|
585
|
+
throw cliErrorOf(error);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
try {
|
|
589
|
+
const result = await apiClient({ baseUrl: target.baseUrl }).call(
|
|
590
|
+
key,
|
|
591
|
+
...input
|
|
592
|
+
);
|
|
593
|
+
console.warn(
|
|
594
|
+
`Saved sign-in was rejected by ${target.baseUrl}; retried without credentials. Run "artis login --host ${target.baseUrl}" to sign in again.`
|
|
595
|
+
);
|
|
596
|
+
return result;
|
|
597
|
+
} catch (error) {
|
|
598
|
+
throw cliErrorOf(error);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function assertSafeLoginUrl(url, baseUrl) {
|
|
602
|
+
let parsed;
|
|
603
|
+
try {
|
|
604
|
+
parsed = new URL(url);
|
|
605
|
+
} catch {
|
|
606
|
+
throw new Error("Login host returned an invalid verification URL.");
|
|
607
|
+
}
|
|
608
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
609
|
+
throw new Error("Login host returned an unsafe verification URL scheme.");
|
|
610
|
+
}
|
|
611
|
+
let expected;
|
|
612
|
+
try {
|
|
613
|
+
expected = new URL(baseUrl);
|
|
614
|
+
} catch {
|
|
615
|
+
throw new Error("Configured login host is not a valid URL.");
|
|
616
|
+
}
|
|
617
|
+
if (parsed.hostname !== expected.hostname || parsed.port !== expected.port) {
|
|
618
|
+
throw new Error(
|
|
619
|
+
"Login host returned a verification URL that does not match the configured host."
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function openBrowser(url) {
|
|
624
|
+
let protocol;
|
|
625
|
+
try {
|
|
626
|
+
protocol = new URL(url).protocol;
|
|
627
|
+
} catch {
|
|
628
|
+
throw new Error("Refusing to open an invalid URL in the browser.");
|
|
629
|
+
}
|
|
630
|
+
if (protocol !== "http:" && protocol !== "https:") {
|
|
631
|
+
throw new Error("Refusing to open a non-http(s) URL in the browser.");
|
|
632
|
+
}
|
|
633
|
+
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
634
|
+
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
635
|
+
const child = spawn(command, args, {
|
|
636
|
+
detached: true,
|
|
637
|
+
stdio: "ignore"
|
|
638
|
+
});
|
|
639
|
+
child.unref();
|
|
640
|
+
}
|
|
641
|
+
function sleep(ms) {
|
|
642
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
643
|
+
}
|
|
644
|
+
function buildArtifactUrl(baseUrl, pathOrUrl) {
|
|
645
|
+
return pathOrUrl.startsWith("http") ? pathOrUrl : `${baseUrl}${pathOrUrl}`;
|
|
646
|
+
}
|
|
647
|
+
async function publishArtifact(input) {
|
|
648
|
+
const { file, root } = input;
|
|
649
|
+
if (!file && !root) {
|
|
650
|
+
throw usageError(
|
|
651
|
+
"Missing artifact HTML file path (or --root <dir> for an artifact as a directory of files, e.g. a slides deck)."
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
if (file && root) {
|
|
655
|
+
throw usageError("Pass an HTML file or --root <dir>, not both.");
|
|
656
|
+
}
|
|
657
|
+
const credentials = await resolveCredentials(input);
|
|
658
|
+
const baseUrl = credentials.baseUrl;
|
|
659
|
+
const visibility = parseVisibility(input.visibility ?? "unlisted");
|
|
660
|
+
const type = parseTypeFlag(input.type);
|
|
661
|
+
const source = root ?? file ?? "";
|
|
662
|
+
const title = input.title ?? inferTitleFromPath(source);
|
|
663
|
+
const query = {
|
|
664
|
+
title,
|
|
665
|
+
description: input.description ?? "Published from Artis CLI.",
|
|
666
|
+
visibility,
|
|
667
|
+
authorName: input.author ?? "Artis CLI",
|
|
668
|
+
source: "cli",
|
|
669
|
+
capabilities: await parseCapabilitiesFlag(input.capabilities),
|
|
670
|
+
reloadPages: input.reloadPages || void 0,
|
|
671
|
+
type
|
|
672
|
+
};
|
|
673
|
+
let result;
|
|
674
|
+
if (root) {
|
|
675
|
+
const files = await readFilesDir(root);
|
|
676
|
+
({ result } = await apiCallRoot(
|
|
677
|
+
{ dir: root, untyped: !type },
|
|
678
|
+
credentials,
|
|
679
|
+
"POST /api/artifacts",
|
|
680
|
+
{ query, body: { files } }
|
|
681
|
+
));
|
|
682
|
+
} else {
|
|
683
|
+
const html = await readHtmlUpload(source, "Artifact file");
|
|
684
|
+
({ result } = await apiCall(credentials, "POST /api/artifacts", {
|
|
685
|
+
query,
|
|
686
|
+
body: html
|
|
687
|
+
}));
|
|
688
|
+
}
|
|
689
|
+
await rememberBase(baseUrl, [result.artifactId], result.revisionId);
|
|
690
|
+
return {
|
|
691
|
+
artifactId: result.artifactId,
|
|
692
|
+
revisionId: result.revisionId,
|
|
693
|
+
title,
|
|
694
|
+
url: buildArtifactUrl(baseUrl, result.url),
|
|
695
|
+
visibility,
|
|
696
|
+
type: result.type,
|
|
697
|
+
typeFormat: result.typeFormat
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
async function login(input, prompt) {
|
|
701
|
+
const config = await readCliConfig();
|
|
702
|
+
const baseUrl = resolveBaseUrl(input, config);
|
|
703
|
+
let login2;
|
|
704
|
+
try {
|
|
705
|
+
login2 = await startDeviceAuthorization(baseUrl);
|
|
706
|
+
} catch (error) {
|
|
707
|
+
throw loginErrorOf(error, baseUrl);
|
|
708
|
+
}
|
|
709
|
+
const verificationUrl = login2.verificationUriComplete ?? login2.verificationUri;
|
|
710
|
+
assertSafeLoginUrl(verificationUrl, baseUrl);
|
|
711
|
+
prompt.onCode(verificationUrl, login2.userCode);
|
|
712
|
+
try {
|
|
713
|
+
openBrowser(verificationUrl);
|
|
714
|
+
} catch {
|
|
715
|
+
prompt.onBrowserFailure();
|
|
716
|
+
}
|
|
717
|
+
let intervalMs = Math.max(login2.interval, 1) * 1e3;
|
|
718
|
+
const expiresAt = Date.now() + login2.expiresIn * 1e3;
|
|
719
|
+
while (Date.now() < expiresAt) {
|
|
720
|
+
await sleep(intervalMs);
|
|
721
|
+
let poll;
|
|
722
|
+
try {
|
|
723
|
+
poll = await pollDeviceToken(baseUrl, login2.deviceCode);
|
|
724
|
+
} catch (error) {
|
|
725
|
+
throw loginErrorOf(error, baseUrl);
|
|
726
|
+
}
|
|
727
|
+
if (poll.status === "pending") {
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
if (poll.status === "slow_down") {
|
|
731
|
+
intervalMs += 5e3;
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
const previous = findProfileForHost(await readCliConfig(), baseUrl);
|
|
735
|
+
await saveDefaultProfile({ host: baseUrl, ...poll.tokens });
|
|
736
|
+
if (previous?.refreshToken) {
|
|
737
|
+
await revokeToken(baseUrl, previous.refreshToken, "refresh_token");
|
|
738
|
+
}
|
|
739
|
+
if (previous?.accessToken) {
|
|
740
|
+
await revokeToken(baseUrl, previous.accessToken, "access_token");
|
|
741
|
+
}
|
|
742
|
+
await resolveOrigin();
|
|
743
|
+
return { configPath: getConfigPath() };
|
|
744
|
+
}
|
|
745
|
+
throw new CliError("Login expired. Run artis login again.", exitCodes.auth);
|
|
746
|
+
}
|
|
747
|
+
function loginErrorOf(error, baseUrl) {
|
|
748
|
+
if (!(error instanceof OAuthError)) {
|
|
749
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
750
|
+
}
|
|
751
|
+
if (error.code === "access_denied") {
|
|
752
|
+
return new CliError("Login was denied in the browser.", exitCodes.auth);
|
|
753
|
+
}
|
|
754
|
+
if (error.code === "expired_token") {
|
|
755
|
+
return new CliError(
|
|
756
|
+
"Login expired. Run artis login again.",
|
|
757
|
+
exitCodes.auth
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
if (error.status === 429) {
|
|
761
|
+
return new CliError(
|
|
762
|
+
`Too many logins from here; ${baseUrl} asked to slow down. Try again in a minute.`,
|
|
763
|
+
exitCodes.rateLimited
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
return new CliError(
|
|
767
|
+
`Login failed on ${baseUrl}: ${error.message}`,
|
|
768
|
+
exitCodeForResponse(error.status, error.code)
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
async function publicCall(input, key, ...args) {
|
|
772
|
+
const baseUrl = resolveBaseUrl(input, await readCliConfig());
|
|
773
|
+
try {
|
|
774
|
+
return await apiClient({ baseUrl }).call(key, ...args);
|
|
775
|
+
} catch (error) {
|
|
776
|
+
throw cliErrorOf(error);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
async function listTypes(input) {
|
|
780
|
+
return (await publicCall(input, "GET /api/types")).types;
|
|
781
|
+
}
|
|
782
|
+
async function readType(input) {
|
|
783
|
+
return (await publicCall(input, "GET /api/types/{name}", {
|
|
784
|
+
params: { name: input.name }
|
|
785
|
+
})).type;
|
|
786
|
+
}
|
|
787
|
+
async function readTypeReference(input) {
|
|
788
|
+
return publicCall(input, "GET /api/types/{name}/files/{path}", {
|
|
789
|
+
params: { name: input.name, path: input.path }
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
async function whoami(input) {
|
|
793
|
+
const credentials = await resolveCredentials(input);
|
|
794
|
+
const result = await apiCall(credentials, "GET /api/me");
|
|
795
|
+
return { baseUrl: credentials.baseUrl, principal: result.principal };
|
|
796
|
+
}
|
|
797
|
+
function artifactIdArg(value) {
|
|
798
|
+
return artifactIdFromReference(value) ?? value;
|
|
799
|
+
}
|
|
800
|
+
function requireArtifactId(artifact, usage) {
|
|
801
|
+
const artifactId = artifact && artifactIdArg(artifact);
|
|
802
|
+
if (!artifactId) {
|
|
803
|
+
throw usageError(usage);
|
|
804
|
+
}
|
|
805
|
+
return artifactId;
|
|
806
|
+
}
|
|
807
|
+
async function getArtifact(input) {
|
|
808
|
+
const artifactId = requireArtifactId(
|
|
809
|
+
input.artifact,
|
|
810
|
+
"Missing artifact id or link."
|
|
811
|
+
);
|
|
812
|
+
const target = await resolveOptionalTarget(input);
|
|
813
|
+
const result = await apiCallOptional(
|
|
814
|
+
target,
|
|
815
|
+
"GET /api/artifacts/{artifactId}",
|
|
816
|
+
{ params: { artifactId } }
|
|
817
|
+
);
|
|
818
|
+
return {
|
|
819
|
+
details: result,
|
|
820
|
+
openAnnotations: result.annotations.filter(
|
|
821
|
+
(annotation) => isRootAnnotation(annotation) && !isReviewClosed(annotation["artis:status"])
|
|
822
|
+
).length
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
function describeType(declaration) {
|
|
826
|
+
return declaration.type !== "html" ? `${declaration.type} (format ${declaration.typeFormat})` : void 0;
|
|
827
|
+
}
|
|
828
|
+
var parallelFileReads = 6;
|
|
829
|
+
async function mapConcurrent(items, limit, run) {
|
|
830
|
+
const results = new Array(items.length);
|
|
831
|
+
let next = 0;
|
|
832
|
+
async function worker() {
|
|
833
|
+
while (next < items.length) {
|
|
834
|
+
const index = next++;
|
|
835
|
+
results[index] = await run(items[index]);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
await Promise.all(
|
|
839
|
+
Array.from({ length: Math.min(limit, items.length) }, worker)
|
|
840
|
+
);
|
|
841
|
+
return results;
|
|
842
|
+
}
|
|
843
|
+
function listRevisionFiles(target, artifactId, revisionId) {
|
|
844
|
+
return apiCallOptional(target, "GET /api/artifacts/{artifactId}/files", {
|
|
845
|
+
params: { artifactId },
|
|
846
|
+
query: { revisionId }
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
function readListedFiles(target, artifactId, listed) {
|
|
850
|
+
return mapConcurrent(listed.files, parallelFileReads, async (file) => {
|
|
851
|
+
const read = await apiCallOptional(
|
|
852
|
+
target,
|
|
853
|
+
"GET /api/artifacts/{artifactId}/files/{path}",
|
|
854
|
+
{
|
|
855
|
+
params: { artifactId, path: file.path },
|
|
856
|
+
query: { revisionId: listed.revisionId }
|
|
857
|
+
}
|
|
858
|
+
);
|
|
859
|
+
return { path: file.path, content: read.content };
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
async function readRevisionFiles(target, artifactId, revisionId) {
|
|
863
|
+
const listed = await listRevisionFiles(target, artifactId, revisionId);
|
|
864
|
+
return { listed, files: await readListedFiles(target, artifactId, listed) };
|
|
865
|
+
}
|
|
866
|
+
var artifactFilesUsage = "Usage: artis artifact files <artifact> [path] [--output <dir>] [--revision <revision-id>] [--json]";
|
|
867
|
+
async function readArtifactFile(input) {
|
|
868
|
+
const artifactId = requireArtifactId(input.artifact, artifactFilesUsage);
|
|
869
|
+
const target = await resolveOptionalTarget(input);
|
|
870
|
+
const file = await apiCallOptional(
|
|
871
|
+
target,
|
|
872
|
+
"GET /api/artifacts/{artifactId}/files/{path}",
|
|
873
|
+
{
|
|
874
|
+
params: { artifactId, path: input.path },
|
|
875
|
+
query: { revisionId: input.revision }
|
|
876
|
+
}
|
|
877
|
+
);
|
|
878
|
+
const revision = await apiCallOptional(
|
|
879
|
+
target,
|
|
880
|
+
"GET /api/artifacts/{artifactId}/files",
|
|
881
|
+
{ params: { artifactId }, query: { revisionId: file.revisionId } }
|
|
882
|
+
);
|
|
883
|
+
if (revision.files.length === 1) {
|
|
884
|
+
await rememberBase(
|
|
885
|
+
target.baseUrl,
|
|
886
|
+
[artifactId, file.artifactId],
|
|
887
|
+
file.revisionId
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
return file;
|
|
891
|
+
}
|
|
892
|
+
async function listArtifactFiles(input) {
|
|
893
|
+
const artifactId = requireArtifactId(input.artifact, artifactFilesUsage);
|
|
894
|
+
const target = await resolveOptionalTarget(input);
|
|
895
|
+
const listed = await listRevisionFiles(target, artifactId, input.revision);
|
|
896
|
+
if (input.output) {
|
|
897
|
+
const files = await readListedFiles(target, artifactId, listed);
|
|
898
|
+
await writeFilesDir(input.output, files);
|
|
899
|
+
await rememberBase(
|
|
900
|
+
target.baseUrl,
|
|
901
|
+
[artifactId, listed.artifactId],
|
|
902
|
+
listed.revisionId
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
return listed;
|
|
906
|
+
}
|
|
907
|
+
function parseVerifyType(value) {
|
|
908
|
+
const type = parseTypeFlag(value);
|
|
909
|
+
if (type === void 0 || type === "html") {
|
|
910
|
+
return void 0;
|
|
911
|
+
}
|
|
912
|
+
if (!isTypePackageName(type)) {
|
|
913
|
+
throw usageError(
|
|
914
|
+
`"${type}" is not a type name: 1-40 lower-case letters, digits and -, starting with a letter.`
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
return type;
|
|
918
|
+
}
|
|
919
|
+
async function readVerifyTypePackage(input, name) {
|
|
920
|
+
let files;
|
|
921
|
+
try {
|
|
922
|
+
({
|
|
923
|
+
type: { package: files }
|
|
924
|
+
} = await publicCall(input, "GET /api/types/{name}", {
|
|
925
|
+
params: { name }
|
|
926
|
+
}));
|
|
927
|
+
} catch (error) {
|
|
928
|
+
if (error instanceof CliError && error.exitCode === exitCodes.notFound) {
|
|
929
|
+
throw new CliError(
|
|
930
|
+
`The type ${name} is not installed on ${resolveBaseUrl(input, await readCliConfig())}. List the installed types with: artis types`,
|
|
931
|
+
exitCodes.notFound
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
throw error;
|
|
935
|
+
}
|
|
936
|
+
const read = async (path) => (await readTypeReference({ ...input, name, path })).content;
|
|
937
|
+
if (!files || typeof files.entry !== "string") {
|
|
938
|
+
throw new CliError(
|
|
939
|
+
`${resolveBaseUrl(input, await readCliConfig())} does not serve the ${name} package to artis verify: the server needs updating.`,
|
|
940
|
+
exitCodes.error
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
const { entry, runtime, check, googleFonts, layout } = files;
|
|
944
|
+
const [entryText, runtimeText, checkText] = await Promise.all([
|
|
945
|
+
read(entry),
|
|
946
|
+
read(runtime),
|
|
947
|
+
check ? read(check) : void 0
|
|
948
|
+
]);
|
|
949
|
+
return {
|
|
950
|
+
name,
|
|
951
|
+
entry: entryText,
|
|
952
|
+
runtime: runtimeText,
|
|
953
|
+
...checkText === void 0 ? {} : { check: checkText },
|
|
954
|
+
googleFonts,
|
|
955
|
+
...layout ? { layout } : {}
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
async function prepareVerify(input) {
|
|
959
|
+
const { target, root } = input;
|
|
960
|
+
if (!target && !root) {
|
|
961
|
+
throw usageError(
|
|
962
|
+
"Usage: artis verify <artifact.html | artifact> [--revision <revision-id>] [--json]\n artis verify --root <dir> [--type slides] [--json]"
|
|
963
|
+
);
|
|
964
|
+
}
|
|
965
|
+
if (root) {
|
|
966
|
+
const job = await prepareFilesDirVerify(input, root);
|
|
967
|
+
return job.typeName ? {
|
|
968
|
+
files: job.files,
|
|
969
|
+
label: job.label,
|
|
970
|
+
type: await readVerifyTypePackage(input, job.typeName)
|
|
971
|
+
} : { files: job.files, label: job.label };
|
|
972
|
+
}
|
|
973
|
+
const reference = target;
|
|
974
|
+
let type = parseVerifyType(input.type);
|
|
975
|
+
let files;
|
|
976
|
+
let label;
|
|
977
|
+
let loadAsset;
|
|
978
|
+
const referenced = artifactIdFromReference(reference);
|
|
979
|
+
const looksLikePath = !referenced && (/[\\/]/.test(reference) || /\.html?$/i.test(reference));
|
|
980
|
+
const local = await readFile(reference, "utf8").catch(
|
|
981
|
+
(error) => error
|
|
982
|
+
);
|
|
983
|
+
if (typeof local === "string" || looksLikePath) {
|
|
984
|
+
if (typeof local !== "string") {
|
|
985
|
+
throw local.code === "ENOENT" ? new CliError(`File not found: ${reference}`, exitCodes.notFound) : usageError(`Cannot read ${reference}: ${local.message}`);
|
|
986
|
+
}
|
|
987
|
+
if (input.revision) {
|
|
988
|
+
throw usageError(
|
|
989
|
+
"--revision applies to a published artifact, not a local file."
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
if (type) {
|
|
993
|
+
throw usageError(
|
|
994
|
+
`A ${type} artifact is a directory of files: artis verify --root <dir> --type ${type}.`
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
files = { "index.html": local };
|
|
998
|
+
label = reference;
|
|
999
|
+
} else {
|
|
1000
|
+
const remote = await resolveOptionalTarget(input);
|
|
1001
|
+
const artifactId = referenced ?? reference;
|
|
1002
|
+
const read = await readRevisionFiles(remote, artifactId, input.revision);
|
|
1003
|
+
files = Object.fromEntries(
|
|
1004
|
+
read.files.map((file) => [file.path, file.content])
|
|
1005
|
+
);
|
|
1006
|
+
label = `${reference} v${read.listed.version}`;
|
|
1007
|
+
if (remote.accessToken) {
|
|
1008
|
+
loadAsset = (assetId) => fetchAssetContent(remote, artifactId, assetId).catch((error) => {
|
|
1009
|
+
if (error instanceof CliError && error.exitCode === exitCodes.notFound) {
|
|
1010
|
+
return void 0;
|
|
1011
|
+
}
|
|
1012
|
+
throw error;
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
if (type === void 0) {
|
|
1016
|
+
const { artifact } = await apiCallOptional(
|
|
1017
|
+
remote,
|
|
1018
|
+
"GET /api/artifacts/{artifactId}",
|
|
1019
|
+
{ params: { artifactId } }
|
|
1020
|
+
);
|
|
1021
|
+
const declared = artifact.revisions.find(
|
|
1022
|
+
(revision) => revision.id === read.listed.revisionId
|
|
1023
|
+
)?.type;
|
|
1024
|
+
if (declared !== void 0 && declared !== "html") {
|
|
1025
|
+
type = declared;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
return {
|
|
1030
|
+
files,
|
|
1031
|
+
label,
|
|
1032
|
+
...type ? { type: await readVerifyTypePackage(input, type) } : {},
|
|
1033
|
+
loadAsset
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
async function prepareFilesDirVerify(input, root) {
|
|
1037
|
+
if (input.target) {
|
|
1038
|
+
throw usageError("--root takes no file or artifact argument.");
|
|
1039
|
+
}
|
|
1040
|
+
if (input.revision) {
|
|
1041
|
+
throw usageError("--revision applies to a published artifact.");
|
|
1042
|
+
}
|
|
1043
|
+
const type = parseVerifyType(input.type);
|
|
1044
|
+
const files = await readFilesDir(root);
|
|
1045
|
+
if (!type && files["index.html"] === void 0) {
|
|
1046
|
+
throw usageError(
|
|
1047
|
+
`${root} has no index.html: an html artifact is that one file. For a deck, add --type slides.`
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
return { files, label: root, ...type ? { typeName: type } : {} };
|
|
1051
|
+
}
|
|
1052
|
+
async function listArtifacts(input) {
|
|
1053
|
+
const credentials = await resolveCredentials(input);
|
|
1054
|
+
const { query, tag, limit, cursor } = input;
|
|
1055
|
+
const type = parseTypeFlag(input.type);
|
|
1056
|
+
if (limit !== void 0 && (!/^\d+$/.test(limit) || Number(limit) < 1 || Number(limit) > artifactListLimits.max)) {
|
|
1057
|
+
throw usageError(
|
|
1058
|
+
`Invalid --limit "${limit}". Pass a whole number from 1 to ${artifactListLimits.max}.`
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
return apiCall(credentials, "GET /api/artifacts", {
|
|
1062
|
+
query: {
|
|
1063
|
+
owner: "me",
|
|
1064
|
+
q: query || void 0,
|
|
1065
|
+
tag: tag || void 0,
|
|
1066
|
+
type,
|
|
1067
|
+
limit: limit ? Number(limit) : void 0,
|
|
1068
|
+
cursor: cursor || void 0
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
async function readFeedback(input) {
|
|
1073
|
+
const artifactId = requireArtifactId(
|
|
1074
|
+
input.artifact,
|
|
1075
|
+
"Missing artifact id or link."
|
|
1076
|
+
);
|
|
1077
|
+
const target = await resolveOptionalTarget(input);
|
|
1078
|
+
const feedback = await apiCallOptional(
|
|
1079
|
+
target,
|
|
1080
|
+
"GET /api/artifacts/{artifactId}/feedback",
|
|
1081
|
+
{ params: { artifactId }, query: { revisionId: input.revision } }
|
|
1082
|
+
);
|
|
1083
|
+
return { artifactId, feedback };
|
|
1084
|
+
}
|
|
1085
|
+
async function shareArtifact(input) {
|
|
1086
|
+
const artifactId = requireArtifactId(
|
|
1087
|
+
input.artifact,
|
|
1088
|
+
"Usage: artis share <artifact> [--email <email> --role <viewer|commenter|contributor|editor>] [--remove]"
|
|
1089
|
+
);
|
|
1090
|
+
const email = input.email?.trim().toLowerCase();
|
|
1091
|
+
const credentials = await resolveCredentials(input);
|
|
1092
|
+
if (!email) {
|
|
1093
|
+
return {
|
|
1094
|
+
action: "list",
|
|
1095
|
+
result: await apiCall(
|
|
1096
|
+
credentials,
|
|
1097
|
+
"GET /api/artifacts/{artifactId}/shares",
|
|
1098
|
+
{ params: { artifactId } }
|
|
1099
|
+
)
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
if (input.remove) {
|
|
1103
|
+
await apiCall(
|
|
1104
|
+
credentials,
|
|
1105
|
+
"DELETE /api/artifacts/{artifactId}/shares/{email}",
|
|
1106
|
+
{ params: { artifactId, email } }
|
|
1107
|
+
);
|
|
1108
|
+
return { action: "remove", email };
|
|
1109
|
+
}
|
|
1110
|
+
const role = parseShareRole(input.role ?? "viewer");
|
|
1111
|
+
return {
|
|
1112
|
+
action: "add",
|
|
1113
|
+
result: await apiCall(
|
|
1114
|
+
credentials,
|
|
1115
|
+
"POST /api/artifacts/{artifactId}/shares",
|
|
1116
|
+
{ params: { artifactId }, body: { email, role } }
|
|
1117
|
+
)
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
async function setArtifactVisibility(input) {
|
|
1121
|
+
const artifactId = requireArtifactId(
|
|
1122
|
+
input.artifact,
|
|
1123
|
+
`Usage: artis artifact visibility <artifact> <${cliVisibilityOptions.join("|")}>`
|
|
1124
|
+
);
|
|
1125
|
+
const visibility = parseVisibility(input.visibility);
|
|
1126
|
+
const credentials = await resolveCredentials(input);
|
|
1127
|
+
return apiCall(credentials, "PATCH /api/artifacts/{artifactId}", {
|
|
1128
|
+
params: { artifactId },
|
|
1129
|
+
body: { visibility }
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
var capabilitiesUsage = "Usage: artis capabilities show <artifact> | artis capabilities set <artifact> <json|file> [--reload-pages]";
|
|
1133
|
+
async function readCapabilities(input) {
|
|
1134
|
+
const artifactId = requireArtifactId(input.artifact, capabilitiesUsage);
|
|
1135
|
+
const credentials = await resolveCredentials(input);
|
|
1136
|
+
const { artifact } = await apiCall(
|
|
1137
|
+
credentials,
|
|
1138
|
+
"GET /api/artifacts/{artifactId}",
|
|
1139
|
+
{ params: { artifactId } }
|
|
1140
|
+
);
|
|
1141
|
+
const { capabilities, declaredCapabilities, pageEpoch } = artifact;
|
|
1142
|
+
return { capabilities, declaredCapabilities, pageEpoch };
|
|
1143
|
+
}
|
|
1144
|
+
async function setCapabilities(input) {
|
|
1145
|
+
const artifactId = requireArtifactId(input.artifact, capabilitiesUsage);
|
|
1146
|
+
const capabilities = await parseCapabilitiesFlag(
|
|
1147
|
+
input.capabilities,
|
|
1148
|
+
"capabilities"
|
|
1149
|
+
);
|
|
1150
|
+
const credentials = await resolveCredentials(input);
|
|
1151
|
+
return apiCall(credentials, "PUT /api/artifacts/{artifactId}/capabilities", {
|
|
1152
|
+
params: { artifactId },
|
|
1153
|
+
body: {
|
|
1154
|
+
capabilities: capabilities ?? {},
|
|
1155
|
+
reloadPages: input.reloadPages || void 0
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
async function deleteArtifact(input) {
|
|
1160
|
+
const artifactId = requireArtifactId(
|
|
1161
|
+
input.artifact,
|
|
1162
|
+
"Usage: artis artifact delete <artifact> --yes"
|
|
1163
|
+
);
|
|
1164
|
+
if (!input.yes) {
|
|
1165
|
+
throw usageError(
|
|
1166
|
+
"Deleting an artifact removes every revision, annotation and share, and cannot be undone. Pass --yes to confirm."
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
const credentials = await resolveCredentials(input);
|
|
1170
|
+
await apiCall(credentials, "DELETE /api/artifacts/{artifactId}", {
|
|
1171
|
+
params: { artifactId }
|
|
1172
|
+
});
|
|
1173
|
+
return { artifactId };
|
|
1174
|
+
}
|
|
1175
|
+
async function reviseArtifact(input) {
|
|
1176
|
+
const { artifact: artifactRef, file: filePath, root, summary } = input;
|
|
1177
|
+
const artifactId = artifactRef && artifactIdArg(artifactRef);
|
|
1178
|
+
if (!artifactId || !filePath && !root || filePath && root) {
|
|
1179
|
+
throw usageError(
|
|
1180
|
+
"Usage: artis revise <artifact> (artifact.html | --root <dir>) --summary <text> [--base <revision-id>]"
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
if (!summary) {
|
|
1184
|
+
throw usageError("Missing --summary for revision.");
|
|
1185
|
+
}
|
|
1186
|
+
const capabilities = await parseCapabilitiesFlag(input.capabilities);
|
|
1187
|
+
const type = parseTypeFlag(input.type);
|
|
1188
|
+
const credentials = await resolveCredentials(input);
|
|
1189
|
+
const explicitBase = input.base;
|
|
1190
|
+
const baseRevisionId = explicitBase ?? await getRememberedBase(credentials.baseUrl, artifactId);
|
|
1191
|
+
const query = {
|
|
1192
|
+
authorName: input.author ?? "Artis CLI",
|
|
1193
|
+
baseRevisionId,
|
|
1194
|
+
source: "cli",
|
|
1195
|
+
summary,
|
|
1196
|
+
capabilities,
|
|
1197
|
+
reloadPages: input.reloadPages || void 0,
|
|
1198
|
+
type
|
|
1199
|
+
};
|
|
1200
|
+
let result;
|
|
1201
|
+
let sent;
|
|
1202
|
+
if (root) {
|
|
1203
|
+
const local = await readFilesDir(root);
|
|
1204
|
+
const remote = await apiCall(
|
|
1205
|
+
credentials,
|
|
1206
|
+
"GET /api/artifacts/{artifactId}/files",
|
|
1207
|
+
{ params: { artifactId }, query: { revisionId: baseRevisionId } }
|
|
1208
|
+
);
|
|
1209
|
+
const files = changedFiles(local, remote.files);
|
|
1210
|
+
if (Object.keys(files).length === 0) {
|
|
1211
|
+
return { unchanged: true, artifactId, revisionId: remote.revisionId };
|
|
1212
|
+
}
|
|
1213
|
+
result = await apiCallRoot(
|
|
1214
|
+
{ dir: root, untyped: false, artifact: artifactRef },
|
|
1215
|
+
credentials,
|
|
1216
|
+
"POST /api/artifacts/{artifactId}/revisions",
|
|
1217
|
+
{ params: { artifactId }, query, body: { files } }
|
|
1218
|
+
);
|
|
1219
|
+
const removed = Object.values(files).filter(
|
|
1220
|
+
(content) => content === null
|
|
1221
|
+
).length;
|
|
1222
|
+
sent = {
|
|
1223
|
+
changed: Object.keys(files).length - removed,
|
|
1224
|
+
removed,
|
|
1225
|
+
total: Object.keys(local).length
|
|
1226
|
+
};
|
|
1227
|
+
} else {
|
|
1228
|
+
const html = await readHtmlUpload(filePath ?? "", "Revision file");
|
|
1229
|
+
try {
|
|
1230
|
+
result = await apiClient(credentials).call(
|
|
1231
|
+
"POST /api/artifacts/{artifactId}/revisions",
|
|
1232
|
+
{ params: { artifactId }, query, body: html }
|
|
1233
|
+
);
|
|
1234
|
+
} catch (error) {
|
|
1235
|
+
throw cliErrorOf(error, { artifact: artifactRef });
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
await rememberBase(
|
|
1239
|
+
credentials.baseUrl,
|
|
1240
|
+
[artifactId],
|
|
1241
|
+
result.revision.id,
|
|
1242
|
+
baseRevisionId
|
|
1243
|
+
);
|
|
1244
|
+
return {
|
|
1245
|
+
unchanged: false,
|
|
1246
|
+
artifactId,
|
|
1247
|
+
revision: result.revision,
|
|
1248
|
+
sent,
|
|
1249
|
+
baseRevisionId,
|
|
1250
|
+
baseRemembered: Boolean(baseRevisionId) && !explicitBase
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
async function createAnnotation(input) {
|
|
1254
|
+
const artifactId = input.artifact && artifactIdArg(input.artifact);
|
|
1255
|
+
const comment = input.comment;
|
|
1256
|
+
if (!artifactId || !comment) {
|
|
1257
|
+
throw usageError(
|
|
1258
|
+
"Usage: artis annotate <artifact> --comment <text> [--title <text>] [--quote <text>] [--css <selector>] [--text-start <n> --text-end <n>] [--rect <x,y,w,h>] [--pin-label <text>] [--requested-change <text>] [--status <open|resolved>]"
|
|
1259
|
+
);
|
|
1260
|
+
}
|
|
1261
|
+
const selectors = buildAnnotationSelectors(input);
|
|
1262
|
+
const credentials = await resolveCredentials(input);
|
|
1263
|
+
const result = await apiCall(
|
|
1264
|
+
credentials,
|
|
1265
|
+
"POST /api/artifacts/{artifactId}/annotations",
|
|
1266
|
+
{
|
|
1267
|
+
params: { artifactId },
|
|
1268
|
+
body: {
|
|
1269
|
+
authorName: input.author ?? "Artis CLI",
|
|
1270
|
+
comment,
|
|
1271
|
+
pinLabel: input.pinLabel,
|
|
1272
|
+
requestedChange: input.requestedChange,
|
|
1273
|
+
selectors: selectors.length ? selectors : void 0,
|
|
1274
|
+
status: parseAnnotationStatus(input.status ?? "open"),
|
|
1275
|
+
title: input.title
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
);
|
|
1279
|
+
return {
|
|
1280
|
+
annotationId: annotationIdFromIri(result.annotation.id),
|
|
1281
|
+
status: result.annotation["artis:status"]
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
async function replyToAnnotation(input) {
|
|
1285
|
+
const { annotationId, comment } = input;
|
|
1286
|
+
if (!annotationId || !comment) {
|
|
1287
|
+
throw usageError("Usage: artis reply <annotation-id> --comment <text>");
|
|
1288
|
+
}
|
|
1289
|
+
const credentials = await resolveCredentials(input);
|
|
1290
|
+
const result = await apiCall(
|
|
1291
|
+
credentials,
|
|
1292
|
+
"POST /api/annotations/{annotationId}/replies",
|
|
1293
|
+
{
|
|
1294
|
+
params: { annotationId },
|
|
1295
|
+
body: { authorName: input.author ?? "Artis CLI", comment }
|
|
1296
|
+
}
|
|
1297
|
+
);
|
|
1298
|
+
return { annotationId: annotationIdFromIri(result.annotation.id) };
|
|
1299
|
+
}
|
|
1300
|
+
async function editAnnotation(input) {
|
|
1301
|
+
const { annotationId, comment, title, requestedChange } = input;
|
|
1302
|
+
if (!annotationId || comment === void 0 && title === void 0 && requestedChange === void 0) {
|
|
1303
|
+
throw usageError(
|
|
1304
|
+
"Usage: artis annotation edit <annotation-id> [--comment <text>] [--title <text>] [--requested-change <text>]"
|
|
1305
|
+
);
|
|
1306
|
+
}
|
|
1307
|
+
const credentials = await resolveCredentials(input);
|
|
1308
|
+
const result = await apiCall(
|
|
1309
|
+
credentials,
|
|
1310
|
+
"PATCH /api/annotations/{annotationId}",
|
|
1311
|
+
{ params: { annotationId }, body: { comment, title, requestedChange } }
|
|
1312
|
+
);
|
|
1313
|
+
return { annotationId: annotationIdFromIri(result.annotation.id) };
|
|
1314
|
+
}
|
|
1315
|
+
async function retractAnnotation(input) {
|
|
1316
|
+
const { annotationId } = input;
|
|
1317
|
+
if (!annotationId) {
|
|
1318
|
+
throw usageError("Usage: artis annotation retract <annotation-id>");
|
|
1319
|
+
}
|
|
1320
|
+
const credentials = await resolveCredentials(input);
|
|
1321
|
+
const result = await apiCall(
|
|
1322
|
+
credentials,
|
|
1323
|
+
"DELETE /api/annotations/{annotationId}",
|
|
1324
|
+
{ params: { annotationId } }
|
|
1325
|
+
);
|
|
1326
|
+
return { annotationId: annotationIdFromIri(result.annotation.id) };
|
|
1327
|
+
}
|
|
1328
|
+
var watchMaxWaitSeconds = 25;
|
|
1329
|
+
var watchInitialBackoffMs = 1e3;
|
|
1330
|
+
var watchMaxBackoffMs = 6e4;
|
|
1331
|
+
function parseDuration(value) {
|
|
1332
|
+
const match = /^(\d+(?:\.\d+)?)(ms|s|m|h)?$/.exec(value.trim());
|
|
1333
|
+
if (!match) {
|
|
1334
|
+
throw usageError(
|
|
1335
|
+
`Invalid duration "${value}". Use e.g. 30s, 5m, 1h, or 500ms.`
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
const unitMs = { ms: 1, s: 1e3, m: 6e4, h: 36e5 }[match[2] ?? "s"];
|
|
1339
|
+
return Number(match[1]) * unitMs;
|
|
1340
|
+
}
|
|
1341
|
+
var watchSelfScopes = ["origin", "client", "none"];
|
|
1342
|
+
function parseSelfFlag(value, includeSelf) {
|
|
1343
|
+
if (value === void 0) {
|
|
1344
|
+
return includeSelf ? "none" : void 0;
|
|
1345
|
+
}
|
|
1346
|
+
if (!watchSelfScopes.includes(value)) {
|
|
1347
|
+
throw usageError(`Invalid --self "${value}". Use origin, client or none.`);
|
|
1348
|
+
}
|
|
1349
|
+
return value;
|
|
1350
|
+
}
|
|
1351
|
+
async function watchArtifact(input, onEvents) {
|
|
1352
|
+
const artifactId = requireArtifactId(
|
|
1353
|
+
input.artifact,
|
|
1354
|
+
"Usage: artis watch <artifact> [--since <cursor>] [--once] [--timeout <duration>] [--self origin|client|none] [--types <families>]"
|
|
1355
|
+
);
|
|
1356
|
+
const typesFlag = input.types;
|
|
1357
|
+
const types = typesFlag?.split(",").map((type) => type.trim()).filter(Boolean);
|
|
1358
|
+
let cursor = input.since;
|
|
1359
|
+
if (cursor !== void 0 && !/^\d+$/.test(cursor)) {
|
|
1360
|
+
throw usageError(
|
|
1361
|
+
`Invalid --since "${cursor}". Pass a cursor from artifact feedback or a previous event.`
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
const timeoutFlag = input.timeout;
|
|
1365
|
+
const deadline = timeoutFlag !== void 0 ? Date.now() + parseDuration(timeoutFlag) : void 0;
|
|
1366
|
+
const once = input.once;
|
|
1367
|
+
const self = parseSelfFlag(input.self, input.includeSelf);
|
|
1368
|
+
let credentials = await resolveCredentials(input);
|
|
1369
|
+
let api = apiClient(credentials);
|
|
1370
|
+
let reauthorized = false;
|
|
1371
|
+
let backoffMs = watchInitialBackoffMs;
|
|
1372
|
+
let delivered = false;
|
|
1373
|
+
const timedOut = () => new CliError(
|
|
1374
|
+
`No feedback events within ${timeoutFlag}.${cursor ? ` Resume with --since ${cursor}.` : ""}`,
|
|
1375
|
+
exitCodes.watchTimeout
|
|
1376
|
+
);
|
|
1377
|
+
const backOff = async () => {
|
|
1378
|
+
const remaining = deadline === void 0 ? Infinity : deadline - Date.now();
|
|
1379
|
+
if (remaining <= backoffMs) {
|
|
1380
|
+
if (delivered) {
|
|
1381
|
+
return false;
|
|
1382
|
+
}
|
|
1383
|
+
throw timedOut();
|
|
1384
|
+
}
|
|
1385
|
+
await sleep(backoffMs);
|
|
1386
|
+
backoffMs = Math.min(backoffMs * 2, watchMaxBackoffMs);
|
|
1387
|
+
return true;
|
|
1388
|
+
};
|
|
1389
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
1390
|
+
const remainingMs = deadline === void 0 ? Infinity : deadline - Date.now();
|
|
1391
|
+
if (attempt > 0 && remainingMs < 1e3) {
|
|
1392
|
+
if (delivered) {
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
throw timedOut();
|
|
1396
|
+
}
|
|
1397
|
+
let page;
|
|
1398
|
+
try {
|
|
1399
|
+
page = await api.call("GET /api/artifacts/{artifactId}/events", {
|
|
1400
|
+
params: { artifactId },
|
|
1401
|
+
query: {
|
|
1402
|
+
wait: Math.min(watchMaxWaitSeconds, Math.floor(remainingMs / 1e3)),
|
|
1403
|
+
since: cursor,
|
|
1404
|
+
self,
|
|
1405
|
+
types
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
if (!(error instanceof ApiError)) {
|
|
1410
|
+
if (await backOff()) {
|
|
1411
|
+
continue;
|
|
1412
|
+
}
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
if (error.status === 401 && !reauthorized) {
|
|
1416
|
+
reauthorized = true;
|
|
1417
|
+
const next = await resolveCredentials(input).catch(() => void 0);
|
|
1418
|
+
if (next && next.accessToken !== credentials.accessToken) {
|
|
1419
|
+
credentials = next;
|
|
1420
|
+
api = apiClient(credentials);
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
if ((error.status === 429 || error.status >= 500) && !once) {
|
|
1425
|
+
if (await backOff()) {
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
throw new CliError(
|
|
1431
|
+
error.status === 410 ? `${error.message} Re-read feedback (artis artifact feedback ${artifactId} --json) and watch from its cursor.` : error.message,
|
|
1432
|
+
exitCodeForResponse(error.status, error.code)
|
|
1433
|
+
);
|
|
1434
|
+
}
|
|
1435
|
+
backoffMs = watchInitialBackoffMs;
|
|
1436
|
+
reauthorized = false;
|
|
1437
|
+
const { events } = page;
|
|
1438
|
+
cursor = page.cursor;
|
|
1439
|
+
if (events.length === 0) {
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
onEvents(events, cursor);
|
|
1443
|
+
if (once) {
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
delivered = true;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
var dataAsRoles = ["viewer", "commenter", "contributor"];
|
|
1450
|
+
function parseAsRole(value) {
|
|
1451
|
+
if (value === void 0) return void 0;
|
|
1452
|
+
if (!dataAsRoles.includes(value)) {
|
|
1453
|
+
throw usageError(
|
|
1454
|
+
`Invalid --as-role "${value}". Expected one of: ${dataAsRoles.join(", ")}.`
|
|
1455
|
+
);
|
|
1456
|
+
}
|
|
1457
|
+
return value;
|
|
1458
|
+
}
|
|
1459
|
+
function parseIfMatchFlag(value) {
|
|
1460
|
+
if (value === void 0) return void 0;
|
|
1461
|
+
const match = /^([^@\s]+)@([1-9]\d*)$/.exec(value);
|
|
1462
|
+
if (!match?.[1] || !match[2]) {
|
|
1463
|
+
throw usageError(
|
|
1464
|
+
`Invalid --if-match "${value}". Expected <id>@<version>, e.g. doc-abc@3.`
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
return { id: match[1], version: Number(match[2]) };
|
|
1468
|
+
}
|
|
1469
|
+
function requireDocumentPath(path, action) {
|
|
1470
|
+
if (!path) {
|
|
1471
|
+
throw usageError(`Usage: artis data ${action} <artifact> <path>`);
|
|
1472
|
+
}
|
|
1473
|
+
return path;
|
|
1474
|
+
}
|
|
1475
|
+
function dataWrite(input) {
|
|
1476
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1477
|
+
const ifMatch = parseIfMatchFlag(input.ifMatch);
|
|
1478
|
+
if (ifMatch && input.ifAbsent) {
|
|
1479
|
+
throw usageError("Pass --if-match or --if-absent, not both.");
|
|
1480
|
+
}
|
|
1481
|
+
const key = input.idempotencyKey;
|
|
1482
|
+
if (key !== void 0 && !/^[\x21-\x7e]{1,255}$/.test(key)) {
|
|
1483
|
+
throw usageError(
|
|
1484
|
+
"--idempotency-key must be 1-255 printable characters without spaces."
|
|
1485
|
+
);
|
|
1486
|
+
}
|
|
1487
|
+
return {
|
|
1488
|
+
artifactId,
|
|
1489
|
+
ifMatch,
|
|
1490
|
+
condition: {
|
|
1491
|
+
...ifMatch ? { ifMatch } : {},
|
|
1492
|
+
...input.ifAbsent ? { ifAbsent: true } : {}
|
|
1493
|
+
},
|
|
1494
|
+
headers: key ? { "idempotency-key": key } : void 0
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
async function readStdin() {
|
|
1498
|
+
const chunks = [];
|
|
1499
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
1500
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
1501
|
+
}
|
|
1502
|
+
async function readJsonInput(value, flag) {
|
|
1503
|
+
if (value === void 0) {
|
|
1504
|
+
throw usageError(`Missing ${flag} <json|file|->.`);
|
|
1505
|
+
}
|
|
1506
|
+
let source = value;
|
|
1507
|
+
if (value === "-") {
|
|
1508
|
+
source = await readStdin();
|
|
1509
|
+
} else if (!/^\s*[[{]/.test(value)) {
|
|
1510
|
+
try {
|
|
1511
|
+
source = await readFile(value, "utf8");
|
|
1512
|
+
} catch {
|
|
1513
|
+
throw usageError(
|
|
1514
|
+
`${flag} must be JSON, a path to a JSON file, or - for stdin; could not read "${value}".`
|
|
1515
|
+
);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
try {
|
|
1519
|
+
return JSON.parse(source);
|
|
1520
|
+
} catch {
|
|
1521
|
+
throw usageError(`${flag} is not valid JSON.`);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
async function readJsonObjectInput(value, flag) {
|
|
1525
|
+
const parsed = await readJsonInput(value, flag);
|
|
1526
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1527
|
+
throw usageError(`${flag} must be a JSON object.`);
|
|
1528
|
+
}
|
|
1529
|
+
return parsed;
|
|
1530
|
+
}
|
|
1531
|
+
async function getDocument(input) {
|
|
1532
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1533
|
+
requireDocumentPath(input.path, "get");
|
|
1534
|
+
const asRole = parseAsRole(input.asRole);
|
|
1535
|
+
const credentials = await resolveCredentials(input);
|
|
1536
|
+
return apiCall(
|
|
1537
|
+
credentials,
|
|
1538
|
+
"GET /api/artifacts/{artifactId}/data/docs/{path}",
|
|
1539
|
+
{ params: { artifactId, path: input.path }, query: { asRole } }
|
|
1540
|
+
);
|
|
1541
|
+
}
|
|
1542
|
+
async function listDocuments(input) {
|
|
1543
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1544
|
+
const asRole = parseAsRole(input.asRole);
|
|
1545
|
+
const { limit, depth, order } = input;
|
|
1546
|
+
if (limit !== void 0 && (!/^\d+$/.test(limit) || Number(limit) < 1 || Number(limit) > 1e3)) {
|
|
1547
|
+
throw usageError(
|
|
1548
|
+
`Invalid --limit "${limit}". Pass a whole number from 1 to 1000.`
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
if (depth !== void 0 && depth !== "children" && depth !== "all") {
|
|
1552
|
+
throw usageError("--depth must be children or all.");
|
|
1553
|
+
}
|
|
1554
|
+
if (order !== void 0 && order !== "path" && order !== "created") {
|
|
1555
|
+
throw usageError("--order must be path or created.");
|
|
1556
|
+
}
|
|
1557
|
+
const credentials = await resolveCredentials(input);
|
|
1558
|
+
return apiCall(credentials, "GET /api/artifacts/{artifactId}/data", {
|
|
1559
|
+
params: { artifactId },
|
|
1560
|
+
query: {
|
|
1561
|
+
prefix: input.prefix,
|
|
1562
|
+
depth,
|
|
1563
|
+
order,
|
|
1564
|
+
limit: limit ? Number(limit) : void 0,
|
|
1565
|
+
after: input.after,
|
|
1566
|
+
asRole
|
|
1567
|
+
}
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
async function setDocument(input) {
|
|
1571
|
+
const path = requireDocumentPath(input.path, "set");
|
|
1572
|
+
const write = dataWrite(input);
|
|
1573
|
+
const credentials = await resolveCredentials(input);
|
|
1574
|
+
const value = await readJsonObjectInput(input.value, "--value");
|
|
1575
|
+
const { document } = await apiCall(
|
|
1576
|
+
credentials,
|
|
1577
|
+
"PUT /api/artifacts/{artifactId}/data/docs/{path}",
|
|
1578
|
+
{
|
|
1579
|
+
params: { artifactId: write.artifactId, path },
|
|
1580
|
+
body: { value, ...write.condition },
|
|
1581
|
+
headers: write.headers
|
|
1582
|
+
}
|
|
1583
|
+
);
|
|
1584
|
+
return document;
|
|
1585
|
+
}
|
|
1586
|
+
async function updateDocument(input) {
|
|
1587
|
+
const path = requireDocumentPath(input.path, "update");
|
|
1588
|
+
const write = dataWrite(input);
|
|
1589
|
+
const credentials = await resolveCredentials(input);
|
|
1590
|
+
const patch = await readJsonObjectInput(input.patch, "--patch");
|
|
1591
|
+
const { document } = await apiCall(
|
|
1592
|
+
credentials,
|
|
1593
|
+
"PATCH /api/artifacts/{artifactId}/data/docs/{path}",
|
|
1594
|
+
{
|
|
1595
|
+
params: { artifactId: write.artifactId, path },
|
|
1596
|
+
body: { patch, ...write.condition },
|
|
1597
|
+
headers: write.headers
|
|
1598
|
+
}
|
|
1599
|
+
);
|
|
1600
|
+
return document;
|
|
1601
|
+
}
|
|
1602
|
+
async function deleteDocument(input) {
|
|
1603
|
+
const path = requireDocumentPath(input.path, "delete");
|
|
1604
|
+
const write = dataWrite(input);
|
|
1605
|
+
const credentials = await resolveCredentials(input);
|
|
1606
|
+
const ifMatch = write.ifMatch ? `${write.ifMatch.id}@${write.ifMatch.version}` : void 0;
|
|
1607
|
+
return apiCall(
|
|
1608
|
+
credentials,
|
|
1609
|
+
"DELETE /api/artifacts/{artifactId}/data/docs/{path}",
|
|
1610
|
+
{
|
|
1611
|
+
params: { artifactId: write.artifactId, path },
|
|
1612
|
+
query: { ifMatch },
|
|
1613
|
+
headers: write.headers
|
|
1614
|
+
}
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
async function batchDocuments(input) {
|
|
1618
|
+
const write = dataWrite(input);
|
|
1619
|
+
const credentials = await resolveCredentials(input);
|
|
1620
|
+
const raw = await readJsonInput(input.ops, "--ops");
|
|
1621
|
+
const ops = Array.isArray(raw) ? raw : raw?.ops;
|
|
1622
|
+
if (!Array.isArray(ops)) {
|
|
1623
|
+
throw usageError(
|
|
1624
|
+
'--ops must be a JSON array of writes, or {"ops": [...]}.'
|
|
1625
|
+
);
|
|
1626
|
+
}
|
|
1627
|
+
return apiCall(
|
|
1628
|
+
credentials,
|
|
1629
|
+
"POST /api/artifacts/{artifactId}/data/batch",
|
|
1630
|
+
// The server checks each write.
|
|
1631
|
+
{
|
|
1632
|
+
params: { artifactId: write.artifactId },
|
|
1633
|
+
body: { ops },
|
|
1634
|
+
headers: write.headers
|
|
1635
|
+
}
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1638
|
+
async function exportDocuments(input) {
|
|
1639
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1640
|
+
const asRole = parseAsRole(input.asRole);
|
|
1641
|
+
const credentials = await resolveCredentials(input);
|
|
1642
|
+
let exported;
|
|
1643
|
+
try {
|
|
1644
|
+
exported = await apiClient(credentials).send(
|
|
1645
|
+
"GET /api/artifacts/{artifactId}/data/export",
|
|
1646
|
+
{ params: { artifactId }, query: { asRole } }
|
|
1647
|
+
);
|
|
1648
|
+
} catch (error) {
|
|
1649
|
+
throw cliErrorOf(error);
|
|
1650
|
+
}
|
|
1651
|
+
const ndjson = typeof exported.body === "string" ? exported.body : "";
|
|
1652
|
+
return {
|
|
1653
|
+
ndjson,
|
|
1654
|
+
count: ndjson.split("\n").filter((line) => line.trim()).length,
|
|
1655
|
+
privateLeftOut: exported.headers.get("artis-private-documents")
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
async function getDataUsage(input) {
|
|
1659
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1660
|
+
const credentials = await resolveCredentials(input);
|
|
1661
|
+
return apiCall(credentials, "GET /api/artifacts/{artifactId}/data/usage", {
|
|
1662
|
+
params: { artifactId }
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
var textAssetTypes = {
|
|
1666
|
+
".json": "application/json",
|
|
1667
|
+
".csv": "text/csv",
|
|
1668
|
+
".txt": "text/plain",
|
|
1669
|
+
".svg": "image/svg+xml"
|
|
1670
|
+
};
|
|
1671
|
+
async function fetchAssetContent(credentials, artifactId, assetId) {
|
|
1672
|
+
const response = await fetch(
|
|
1673
|
+
`${credentials.baseUrl.replace(/\/+$/, "")}/api/artifacts/${encodeURIComponent(artifactId)}/assets/${encodeURIComponent(assetId)}/content`,
|
|
1674
|
+
{
|
|
1675
|
+
headers: credentials.accessToken ? {
|
|
1676
|
+
authorization: `Bearer ${credentials.accessToken}`,
|
|
1677
|
+
...credentials.origin ? { "artis-origin": credentials.origin } : {}
|
|
1678
|
+
} : {}
|
|
1679
|
+
}
|
|
1680
|
+
);
|
|
1681
|
+
if (!response.ok) {
|
|
1682
|
+
let body = {};
|
|
1683
|
+
try {
|
|
1684
|
+
body = await response.json();
|
|
1685
|
+
} catch {
|
|
1686
|
+
}
|
|
1687
|
+
throw cliErrorOf(
|
|
1688
|
+
new ApiError(
|
|
1689
|
+
response.status,
|
|
1690
|
+
typeof body["code"] === "string" ? body["code"] : "http_error",
|
|
1691
|
+
typeof body["error"] === "string" ? body["error"] : `Request failed with ${response.status}.`,
|
|
1692
|
+
body,
|
|
1693
|
+
response.headers
|
|
1694
|
+
)
|
|
1695
|
+
);
|
|
1696
|
+
}
|
|
1697
|
+
return {
|
|
1698
|
+
bytes: new Uint8Array(await response.arrayBuffer()),
|
|
1699
|
+
contentType: response.headers.get("artis-asset-content-type") ?? "application/octet-stream"
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
async function uploadAsset(input) {
|
|
1703
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1704
|
+
const credentials = await resolveCredentials(input);
|
|
1705
|
+
const filePath = input.file;
|
|
1706
|
+
let bytes;
|
|
1707
|
+
try {
|
|
1708
|
+
bytes = await readFile(filePath);
|
|
1709
|
+
} catch {
|
|
1710
|
+
throw usageError(`Could not read "${filePath}".`);
|
|
1711
|
+
}
|
|
1712
|
+
const contentType = input.contentType ?? textAssetTypes[extname(filePath).toLowerCase()] ?? "application/octet-stream";
|
|
1713
|
+
return apiCall(credentials, "POST /api/artifacts/{artifactId}/assets", {
|
|
1714
|
+
params: { artifactId },
|
|
1715
|
+
query: { name: input.name ?? basename(filePath) },
|
|
1716
|
+
body: new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength),
|
|
1717
|
+
headers: { "content-type": contentType }
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
async function listAssets(input) {
|
|
1721
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1722
|
+
const credentials = await resolveCredentials(input);
|
|
1723
|
+
return apiCall(credentials, "GET /api/artifacts/{artifactId}/assets", {
|
|
1724
|
+
params: { artifactId }
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
async function getAsset(input) {
|
|
1728
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1729
|
+
const credentials = await resolveCredentials(input);
|
|
1730
|
+
return apiCall(
|
|
1731
|
+
credentials,
|
|
1732
|
+
"GET /api/artifacts/{artifactId}/assets/{assetId}",
|
|
1733
|
+
{ params: { artifactId, assetId: input.assetId } }
|
|
1734
|
+
);
|
|
1735
|
+
}
|
|
1736
|
+
async function downloadAsset(input) {
|
|
1737
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1738
|
+
const credentials = await resolveCredentials(input);
|
|
1739
|
+
const { bytes } = await fetchAssetContent(
|
|
1740
|
+
credentials,
|
|
1741
|
+
artifactId,
|
|
1742
|
+
input.assetId
|
|
1743
|
+
);
|
|
1744
|
+
await writeFile(input.output, bytes);
|
|
1745
|
+
return { bytes: bytes.byteLength };
|
|
1746
|
+
}
|
|
1747
|
+
async function removeAsset(input) {
|
|
1748
|
+
const artifactId = requireArtifactId(input.artifact, "Missing artifact.");
|
|
1749
|
+
const credentials = await resolveCredentials(input);
|
|
1750
|
+
await apiCall(
|
|
1751
|
+
credentials,
|
|
1752
|
+
"DELETE /api/artifacts/{artifactId}/assets/{assetId}",
|
|
1753
|
+
{ params: { artifactId, assetId: input.assetId } }
|
|
1754
|
+
);
|
|
1755
|
+
}
|
|
1756
|
+
async function runArtisCli(args = process.argv.slice(2)) {
|
|
1757
|
+
const { runAgentCli } = await import("./app.js");
|
|
1758
|
+
await runAgentCli(args);
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
export {
|
|
1762
|
+
artifactShortId,
|
|
1763
|
+
readGuidelines,
|
|
1764
|
+
assertSafeLoginUrl,
|
|
1765
|
+
publishArtifact,
|
|
1766
|
+
login,
|
|
1767
|
+
listTypes,
|
|
1768
|
+
readType,
|
|
1769
|
+
readTypeReference,
|
|
1770
|
+
whoami,
|
|
1771
|
+
artifactIdArg,
|
|
1772
|
+
getArtifact,
|
|
1773
|
+
describeType,
|
|
1774
|
+
readArtifactFile,
|
|
1775
|
+
listArtifactFiles,
|
|
1776
|
+
prepareVerify,
|
|
1777
|
+
listArtifacts,
|
|
1778
|
+
readFeedback,
|
|
1779
|
+
shareArtifact,
|
|
1780
|
+
setArtifactVisibility,
|
|
1781
|
+
readCapabilities,
|
|
1782
|
+
setCapabilities,
|
|
1783
|
+
deleteArtifact,
|
|
1784
|
+
reviseArtifact,
|
|
1785
|
+
createAnnotation,
|
|
1786
|
+
replyToAnnotation,
|
|
1787
|
+
editAnnotation,
|
|
1788
|
+
retractAnnotation,
|
|
1789
|
+
watchArtifact,
|
|
1790
|
+
getDocument,
|
|
1791
|
+
listDocuments,
|
|
1792
|
+
setDocument,
|
|
1793
|
+
updateDocument,
|
|
1794
|
+
deleteDocument,
|
|
1795
|
+
batchDocuments,
|
|
1796
|
+
exportDocuments,
|
|
1797
|
+
getDataUsage,
|
|
1798
|
+
uploadAsset,
|
|
1799
|
+
listAssets,
|
|
1800
|
+
getAsset,
|
|
1801
|
+
downloadAsset,
|
|
1802
|
+
removeAsset,
|
|
1803
|
+
runArtisCli
|
|
1804
|
+
};
|