@phnx-labs/artifacts-cli 0.9.12 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +7 -9
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +34 -190
- package/dist/cli.js.map +1 -1
- package/dist/commands/auth.d.ts +3 -1
- package/dist/commands/auth.js +17 -18
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/comments.js +2 -2
- package/dist/commands/comments.js.map +1 -1
- package/dist/commands/new.js +3 -3
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/share.d.ts +44 -111
- package/dist/commands/share.js +225 -638
- package/dist/commands/share.js.map +1 -1
- package/dist/lib/collab.d.ts +3 -3
- package/dist/lib/collab.js +183 -13
- package/dist/lib/collab.js.map +1 -1
- package/dist/lib/components.js +0 -1
- package/dist/lib/components.js.map +1 -1
- package/dist/lib/config.d.ts +0 -17
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/embedded-html.d.ts +1 -1
- package/dist/lib/embedded-html.js +0 -15
- package/dist/lib/embedded-html.js.map +1 -1
- package/dist/lib/freshness.d.ts +2 -6
- package/dist/lib/freshness.js +4 -33
- package/dist/lib/freshness.js.map +1 -1
- package/dist/lib/header-actions.d.ts +10 -37
- package/dist/lib/header-actions.js +19 -94
- package/dist/lib/header-actions.js.map +1 -1
- package/dist/lib/metadata-menu.d.ts +10 -33
- package/dist/lib/metadata-menu.js +12 -51
- package/dist/lib/metadata-menu.js.map +1 -1
- package/dist/lib/reader-anchors.d.ts +3 -3
- package/dist/lib/reader-anchors.js +7 -4
- package/dist/lib/reader-anchors.js.map +1 -1
- package/dist/lib/render.d.ts +2 -19
- package/dist/lib/render.js +37 -321
- package/dist/lib/render.js.map +1 -1
- package/dist/lib/section-collapse.d.ts +1 -2
- package/dist/lib/section-collapse.js +1 -2
- package/dist/lib/section-collapse.js.map +1 -1
- package/dist/lib/selection-toolbar.d.ts +9 -0
- package/dist/lib/selection-toolbar.js +49 -0
- package/dist/lib/selection-toolbar.js.map +1 -0
- package/dist/lib/share/backend.d.ts +8 -75
- package/dist/lib/share/backend.js +11 -123
- package/dist/lib/share/backend.js.map +1 -1
- package/dist/lib/share/config.d.ts +0 -79
- package/dist/lib/share/config.js +3 -175
- package/dist/lib/share/config.js.map +1 -1
- package/dist/lib/share/delete.d.ts +3 -14
- package/dist/lib/share/delete.js +8 -12
- package/dist/lib/share/delete.js.map +1 -1
- package/dist/lib/share/http-error.d.ts +12 -0
- package/dist/lib/share/http-error.js +32 -0
- package/dist/lib/share/http-error.js.map +1 -1
- package/dist/lib/share/media.d.ts +1 -6
- package/dist/lib/share/media.js +9 -17
- package/dist/lib/share/media.js.map +1 -1
- package/dist/lib/share/og.d.ts +0 -3
- package/dist/lib/share/og.js +2 -4
- package/dist/lib/share/og.js.map +1 -1
- package/dist/lib/share/provision.d.ts +7 -120
- package/dist/lib/share/provision.js +30 -290
- package/dist/lib/share/provision.js.map +1 -1
- package/dist/lib/share/publish.d.ts +10 -65
- package/dist/lib/share/publish.js +32 -131
- package/dist/lib/share/publish.js.map +1 -1
- package/dist/lib/share/visibility.d.ts +11 -35
- package/dist/lib/share/visibility.js +8 -35
- package/dist/lib/share/visibility.js.map +1 -1
- package/dist/lib/share/worker-media-template.js +1 -1
- package/dist/lib/share/worker-publish-template.d.ts +1 -1
- package/dist/lib/share/worker-publish-template.js +3 -0
- package/dist/lib/share/worker-publish-template.js.map +1 -1
- package/dist/lib/share/worker-template.d.ts +2 -14
- package/dist/lib/share/worker-template.js +266 -28
- package/dist/lib/share/worker-template.js.map +1 -1
- package/dist/lib/templates.d.ts +1 -2
- package/dist/lib/templates.js +1 -19
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/validate.js +1 -29
- package/dist/lib/validate.js.map +1 -1
- package/package.json +1 -4
- package/dist/commands/answers.d.ts +0 -6
- package/dist/commands/answers.js +0 -91
- package/dist/commands/answers.js.map +0 -1
- package/dist/commands/favorite.d.ts +0 -9
- package/dist/commands/favorite.js +0 -59
- package/dist/commands/favorite.js.map +0 -1
- package/dist/commands/history.d.ts +0 -4
- package/dist/commands/history.js +0 -29
- package/dist/commands/history.js.map +0 -1
- package/dist/commands/notes.d.ts +0 -5
- package/dist/commands/notes.js +0 -28
- package/dist/commands/notes.js.map +0 -1
- package/dist/lib/browser-detect.d.ts +0 -28
- package/dist/lib/browser-detect.js +0 -126
- package/dist/lib/browser-detect.js.map +0 -1
- package/dist/lib/favorites.d.ts +0 -73
- package/dist/lib/favorites.js +0 -180
- package/dist/lib/favorites.js.map +0 -1
- package/dist/lib/github.d.ts +0 -14
- package/dist/lib/github.js +0 -36
- package/dist/lib/github.js.map +0 -1
- package/dist/lib/highlights.d.ts +0 -11
- package/dist/lib/highlights.js +0 -116
- package/dist/lib/highlights.js.map +0 -1
- package/dist/lib/link-previews.d.ts +0 -67
- package/dist/lib/link-previews.js +0 -427
- package/dist/lib/link-previews.js.map +0 -1
- package/dist/lib/notes.d.ts +0 -22
- package/dist/lib/notes.js +0 -22
- package/dist/lib/notes.js.map +0 -1
- package/dist/lib/pdf.d.ts +0 -13
- package/dist/lib/pdf.js +0 -66
- package/dist/lib/pdf.js.map +0 -1
- package/dist/lib/revisions.d.ts +0 -102
- package/dist/lib/revisions.js +0 -445
- package/dist/lib/revisions.js.map +0 -1
- package/dist/lib/share/analytics.d.ts +0 -13
- package/dist/lib/share/analytics.js +0 -46
- package/dist/lib/share/analytics.js.map +0 -1
- package/dist/lib/share/capture.d.ts +0 -31
- package/dist/lib/share/capture.js +0 -175
- package/dist/lib/share/capture.js.map +0 -1
- package/dist/lib/tokens.d.ts +0 -12
- package/dist/lib/tokens.js +0 -28
- package/dist/lib/tokens.js.map +0 -1
- package/dist/lib/worksheet.d.ts +0 -94
- package/dist/lib/worksheet.js +0 -394
- package/dist/lib/worksheet.js.map +0 -1
package/dist/commands/share.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
// `artifacts share` — publish a rendered artifact to a shareable link
|
|
2
|
-
//
|
|
3
|
-
// otherwise the BYO Cloudflare R2 + Worker path.
|
|
1
|
+
// `artifacts share` — publish a rendered artifact to a shareable link on
|
|
2
|
+
// share.getrush.ai with the signed-in Phoenix session.
|
|
4
3
|
import { existsSync } from 'node:fs';
|
|
5
4
|
import { join } from 'node:path';
|
|
6
5
|
import { Argument, Option } from 'commander';
|
|
7
6
|
import chalk from 'chalk';
|
|
8
|
-
import { parseUnlimitedStorage } from '../lib/share/storage-policy.js';
|
|
9
7
|
import { formatBytes } from '../lib/format.js';
|
|
10
8
|
import { openPath } from '../lib/open.js';
|
|
11
9
|
import { compileArtifact, slugify } from '../lib/render.js';
|
|
12
|
-
import { DEFAULT_BUCKET_NAME,
|
|
13
|
-
import {
|
|
14
|
-
import { publishFile,
|
|
10
|
+
import { DEFAULT_BUCKET_NAME, DEFAULT_SHARE_DOMAIN, DEFAULT_WORKER_NAME } from '../lib/share/config.js';
|
|
11
|
+
import { deployWorker } from '../lib/share/provision.js';
|
|
12
|
+
import { publishFile, parseMetaEntries, parseMetaFilterEntries, sanitizeLabel, scanShareContent, formatSensitiveContentError, unlistedNotPrivateWarning, PUBLISH_VISIBILITY_LEVELS, SHARE_VISIBILITY_LEVELS, } from '../lib/share/publish.js';
|
|
15
13
|
import { deleteShare, resolveDeleteTarget } from '../lib/share/delete.js';
|
|
16
14
|
import { formatShareMediaRetry, formatShareMediaStatus, runShareMediaRetry, runShareMediaStatus } from '../lib/share/media.js';
|
|
17
|
-
import { renderWorkerBundle } from '../lib/share/worker-template.js';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { refreshSessionAvatar } from '../lib/identity/index.js';
|
|
15
|
+
import { renderWorkerBundle, SHARE_WORKER_VERSION } from '../lib/share/worker-template.js';
|
|
16
|
+
import { extractShareHttpError, fetchWorkerVersion, formatShareHttpErrorDetail, workerBehindError } from '../lib/share/http-error.js';
|
|
17
|
+
import { managedShareBaseUrl, resolveShareBackend, SIGNED_OUT_MESSAGE } from '../lib/share/backend.js';
|
|
18
|
+
import { COMMENT_POLICY_FLAGS, commentPolicyFromFlag, resolveVisibility } from '../lib/share/visibility.js';
|
|
19
|
+
import { readSession, refreshSessionAvatar } from '../lib/identity/index.js';
|
|
20
|
+
import { authLogin } from './auth.js';
|
|
24
21
|
export function formatSharePublishResult(result, json = false) {
|
|
25
22
|
if (json)
|
|
26
23
|
return JSON.stringify(result, null, 2);
|
|
@@ -53,49 +50,33 @@ export function formatSharePublishResult(result, json = false) {
|
|
|
53
50
|
}
|
|
54
51
|
return lines.join('\n');
|
|
55
52
|
}
|
|
53
|
+
/** `share status`'s line for the release the endpoint's Worker was built from,
|
|
54
|
+
* read from its `/__version`. */
|
|
55
|
+
export async function workerStatusLine(baseUrl, get) {
|
|
56
|
+
const deployed = await fetchWorkerVersion(baseUrl, get);
|
|
57
|
+
const label = deployed === SHARE_WORKER_VERSION
|
|
58
|
+
? chalk.green(`${deployed} (same as this CLI)`)
|
|
59
|
+
: deployed
|
|
60
|
+
? chalk.yellow(`${deployed} (this CLI is ${SHARE_WORKER_VERSION})`)
|
|
61
|
+
: chalk.dim('unknown — no /__version');
|
|
62
|
+
return `${chalk.bold('worker')} ${label}`;
|
|
63
|
+
}
|
|
56
64
|
/** The stderr warning for a page that published but could not be registered
|
|
57
65
|
* for review threads. The page itself is live; republishing retries. */
|
|
58
66
|
export function collabRegistrationWarning(collab) {
|
|
59
67
|
return `Published, but review threads are unavailable on this page${collab.error ? ` (${collab.error})` : ''}. Republish to retry.`;
|
|
60
68
|
}
|
|
61
|
-
/** Compare the configured endpoint's last-deployed template hash against the
|
|
62
|
-
* hash of the CURRENT `worker-template.ts` render. A config with no recorded
|
|
63
|
-
* hash (every endpoint provisioned before this field existed) is "unknown" —
|
|
64
|
-
* never "current" or "outdated", since there is nothing to compare against. */
|
|
65
|
-
export function shareTemplateStatus(cfg) {
|
|
66
|
-
if (!cfg.templateHash)
|
|
67
|
-
return 'unknown';
|
|
68
|
-
return cfg.templateHash === hashWorkerScript(renderWorkerBundle().script) ? 'current' : 'outdated';
|
|
69
|
-
}
|
|
70
69
|
/**
|
|
71
70
|
* The file that actually gets uploaded for `artifacts share <file>`.
|
|
72
71
|
*
|
|
73
72
|
* A Markdown source is compiled to HTML first — sharing is the last step of
|
|
74
|
-
* rendering, so `artifacts share plan.md` must not upload raw Markdown.
|
|
75
|
-
* compile is publish-free: this command does its own upload, and letting
|
|
76
|
-
* `compileArtifact` auto-publish would mint a second, unwanted link.
|
|
77
|
-
*
|
|
78
|
-
* A 64-hex artifact id (what `artifacts history` prints, and what the header
|
|
79
|
-
* Share button copies — local absolute paths never enter reader-facing HTML)
|
|
80
|
-
* resolves through the local store: the latest saved, hash-verified snapshot
|
|
81
|
-
* is uploaded as-is; an id with no snapshots but a surviving source recompiles
|
|
82
|
-
* from that source.
|
|
73
|
+
* rendering, so `artifacts share plan.md` must not upload raw Markdown.
|
|
83
74
|
*/
|
|
84
75
|
export async function resolveUploadPath(file) {
|
|
85
|
-
if (/^[0-9a-f]{64}$/.test(file)) {
|
|
86
|
-
const { readHistory, revisionSnapshot } = await import('../lib/revisions.js');
|
|
87
|
-
const history = readHistory(file);
|
|
88
|
-
const latest = history.revisions.at(-1);
|
|
89
|
-
if (latest)
|
|
90
|
-
return revisionSnapshot(file, latest.number);
|
|
91
|
-
if (history.sourcePath && existsSync(history.sourcePath))
|
|
92
|
-
return resolveUploadPath(history.sourcePath);
|
|
93
|
-
throw new Error(`No local artifact with id ${file} — nothing rendered on this device matches it.`);
|
|
94
|
-
}
|
|
95
76
|
if (!/\.md$/i.test(file))
|
|
96
77
|
return file;
|
|
97
78
|
const out = join(process.cwd(), '.artifacts', `${slugify(file.replace(/.*\//, '').replace(/\.[^.]+$/, '')) || 'artifact'}.html`);
|
|
98
|
-
const result = await compileArtifact(file, out
|
|
79
|
+
const result = await compileArtifact(file, out);
|
|
99
80
|
const errors = result.diagnostics.filter((d) => d.level === 'error');
|
|
100
81
|
if (errors.length) {
|
|
101
82
|
throw new Error(`Artifact did not compile cleanly:\n${errors.map((e) => `- ${e.message}`).join('\n')}`);
|
|
@@ -121,14 +102,8 @@ export async function runShareEdit(target, opts) {
|
|
|
121
102
|
if (hits.length > 0)
|
|
122
103
|
throw new Error(formatSensitiveContentError(hits));
|
|
123
104
|
}
|
|
124
|
-
const backend = resolveShareBackend({
|
|
125
|
-
|
|
126
|
-
// Worker's generic 400 for a signed-out caller (BYO WRITE_TOKEN can only set
|
|
127
|
-
// public/unlisted).
|
|
128
|
-
if ((opts.visibility === 'me' || opts.visibility === 'org') && backend.kind !== 'managed') {
|
|
129
|
-
throw new Error(`Changing visibility to '${opts.visibility}' requires a Phoenix session. Run 'artifacts auth login'.`);
|
|
130
|
-
}
|
|
131
|
-
const { key } = await resolveDeleteTarget(target, { githubUser: backend.kind === 'managed' ? backend.namespace : opts.githubUser || backend.namespace });
|
|
105
|
+
const backend = resolveShareBackend({ session: opts.session });
|
|
106
|
+
const { key } = resolveDeleteTarget(target, backend.namespace);
|
|
132
107
|
const res = await (opts.fetchEdit ?? fetch)(`${backend.baseUrl.replace(/\/+$/, '')}/${key}`, {
|
|
133
108
|
method: 'PATCH',
|
|
134
109
|
headers: { authorization: `Bearer ${backend.token}`, 'content-type': 'application/json' },
|
|
@@ -148,22 +123,18 @@ export async function runShareEdit(target, opts) {
|
|
|
148
123
|
throw new Error(`Share metadata edit failed (${res.status}): ${detail || 'unknown error'}`);
|
|
149
124
|
}
|
|
150
125
|
const result = JSON.parse(body);
|
|
151
|
-
// A Worker
|
|
152
|
-
//
|
|
153
|
-
// silent success while the page's visibility never changed. Fail loud with the
|
|
154
|
-
// update path instead.
|
|
126
|
+
// A Worker that predates the visibility edit ignores the `visibility` field
|
|
127
|
+
// and 200s without echoing it back: a silent success that changed nothing.
|
|
155
128
|
if (opts.visibility !== undefined && result.visibility === undefined) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
129
|
+
const get = async (url) => {
|
|
130
|
+
const res = await (opts.fetchEdit ?? fetch)(url);
|
|
131
|
+
return { status: res.status, body: await res.text() };
|
|
132
|
+
};
|
|
133
|
+
throw await workerBehindError(backend.baseUrl, 'in-place visibility changes', get);
|
|
159
134
|
}
|
|
160
135
|
return result;
|
|
161
136
|
}
|
|
162
|
-
|
|
163
|
-
* endpoint provisioned before this feature. Points at the update path instead of
|
|
164
|
-
* letting the caller hit a 404 or an HTML body and get a confusing parse error. */
|
|
165
|
-
const OUTDATED_TEMPLATE_HINT = 'Your deployed share Worker has no machine-readable listing route — it predates `artifacts share list`. ' +
|
|
166
|
-
'Run `artifacts share update` to deploy the current Worker template, then retry (`artifacts share status` shows whether an update is due).';
|
|
137
|
+
const NOT_A_LISTING = 'The share Worker did not answer with a share listing.';
|
|
167
138
|
async function defaultListingFetch(url, headers) {
|
|
168
139
|
const res = await fetch(url, { headers: { accept: 'application/json', ...(headers || {}) } });
|
|
169
140
|
return { status: res.status, contentType: res.headers.get('content-type') ?? '', body: await res.text() };
|
|
@@ -180,21 +151,21 @@ function parseMetaField(raw) {
|
|
|
180
151
|
}
|
|
181
152
|
return out;
|
|
182
153
|
}
|
|
183
|
-
/** Parse the Worker's listing JSON into a validated result, failing loud
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
154
|
+
/** Parse the Worker's listing JSON into a validated result, failing loud on any
|
|
155
|
+
* body that isn't the expected shape — an old Worker serves the HTML gallery for
|
|
156
|
+
* a non-empty namespace, which must not be silently accepted as "you have
|
|
157
|
+
* published nothing". */
|
|
187
158
|
export function parseShareListing(user, body) {
|
|
188
159
|
let data;
|
|
189
160
|
try {
|
|
190
161
|
data = JSON.parse(body);
|
|
191
162
|
}
|
|
192
163
|
catch {
|
|
193
|
-
throw new Error(
|
|
164
|
+
throw new Error(NOT_A_LISTING);
|
|
194
165
|
}
|
|
195
166
|
const objectsRaw = data?.objects;
|
|
196
167
|
if (!data || typeof data !== 'object' || !Array.isArray(objectsRaw)) {
|
|
197
|
-
throw new Error(
|
|
168
|
+
throw new Error(NOT_A_LISTING);
|
|
198
169
|
}
|
|
199
170
|
const objects = objectsRaw.map((o) => {
|
|
200
171
|
const item = o;
|
|
@@ -222,82 +193,38 @@ export function parseShareListing(user, body) {
|
|
|
222
193
|
});
|
|
223
194
|
return { user, count: objects.length, objects };
|
|
224
195
|
}
|
|
225
|
-
/** Namespace for list/revisions: managed uses the Phoenix handle (email
|
|
226
|
-
* local-part); BYO resolves the GitHub username (gh / git config / --for-user). */
|
|
227
|
-
async function namespaceForBackend(backend, githubUser) {
|
|
228
|
-
if (backend.kind === 'managed')
|
|
229
|
-
return backend.namespace;
|
|
230
|
-
return resolveShareUsername({ githubUser: githubUser || backend.namespace || undefined });
|
|
231
|
-
}
|
|
232
196
|
/** Fetch and parse the machine-readable listing of the caller's namespace from the
|
|
233
|
-
* Worker's `?format=json` route.
|
|
234
|
-
*
|
|
235
|
-
* route is absent (404 or a non-JSON 200 = the old HTML gallery) — never a silent
|
|
236
|
-
* empty/wrong result. */
|
|
197
|
+
* Worker's `?format=json` route. A 404 is an empty namespace; a non-JSON 200 (the
|
|
198
|
+
* HTML gallery of a Worker without the route) fails loud with the Worker's version. */
|
|
237
199
|
export async function runShareList(opts = {}) {
|
|
238
|
-
const backend = opts.backend ?? resolveShareBackend({
|
|
239
|
-
|
|
240
|
-
config: opts.config,
|
|
241
|
-
writeToken: opts.writeToken,
|
|
242
|
-
byo: opts.byo,
|
|
243
|
-
session: opts.phoenixSession,
|
|
244
|
-
requireToken: false,
|
|
245
|
-
});
|
|
246
|
-
// Managed: the platform Worker is current; skip the BYO template-hash gate.
|
|
247
|
-
// A known-stale BYO template can't have the listing route — say so before any
|
|
248
|
-
// network call. 'unknown' (provisioned before templateHash tracking) is
|
|
249
|
-
// attempted, then caught by the response checks below if the route is absent.
|
|
250
|
-
let templateStatus = 'current';
|
|
251
|
-
if (backend.kind === 'byo') {
|
|
252
|
-
const cfg = opts.config ?? readShareConfig();
|
|
253
|
-
templateStatus = cfg ? shareTemplateStatus(cfg) : 'unknown';
|
|
254
|
-
if (templateStatus === 'outdated') {
|
|
255
|
-
throw new Error(OUTDATED_TEMPLATE_HINT);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
const user = await namespaceForBackend(backend, opts.githubUser);
|
|
200
|
+
const backend = opts.backend ?? resolveShareBackend({ session: opts.phoenixSession });
|
|
201
|
+
const user = backend.namespace;
|
|
259
202
|
const scope = opts.scope ?? 'public';
|
|
260
203
|
const includeHidden = scope !== 'public';
|
|
261
204
|
const query = new URLSearchParams({ format: 'json' });
|
|
262
205
|
if (includeHidden)
|
|
263
206
|
query.set('scope', 'mine');
|
|
264
207
|
const listUrl = `${backend.baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(user)}?${query.toString()}`;
|
|
265
|
-
const listingHeaders = {};
|
|
266
|
-
if (includeHidden) {
|
|
267
|
-
if (!backend.token) {
|
|
268
|
-
throw new Error(`Listing ${scope} shares requires owner authentication. Run 'artifacts auth login' for the managed endpoint, or configure a write token ('artifacts share join') for BYO.`);
|
|
269
|
-
}
|
|
270
|
-
listingHeaders.authorization = `Bearer ${backend.token}`;
|
|
271
|
-
}
|
|
208
|
+
const listingHeaders = includeHidden ? { authorization: `Bearer ${backend.token}` } : {};
|
|
272
209
|
const fetchListing = opts.fetchListing ?? defaultListingFetch;
|
|
273
210
|
const res = await fetchListing(listUrl, listingHeaders);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
// endpoint predates the listing route entirely. The recorded templateHash
|
|
279
|
-
// disambiguates: a 'current' template HAS the route, so its 404 means an empty
|
|
280
|
-
// namespace ("nothing published"); otherwise the route may be absent, so point
|
|
281
|
-
// at `artifacts share update`. Managed is always 'current'.
|
|
282
|
-
if (templateStatus === 'current') {
|
|
283
|
-
return { user, count: 0, objects: [] };
|
|
284
|
-
}
|
|
285
|
-
throw new Error(OUTDATED_TEMPLATE_HINT);
|
|
286
|
-
}
|
|
211
|
+
// The listing route answers only a namespace that holds objects, so a 404 is
|
|
212
|
+
// a namespace with nothing published.
|
|
213
|
+
if (res.status === 404)
|
|
214
|
+
return { user, count: 0, objects: [] };
|
|
287
215
|
if (res.status !== 200) {
|
|
288
216
|
const detail = formatShareHttpErrorDetail(extractShareHttpError({ status: res.status, body: res.body }));
|
|
289
|
-
throw new Error(`Listing failed (${res.status}) for ${listUrl}${detail}. Check the endpoint is reachable, or
|
|
217
|
+
throw new Error(`Listing failed (${res.status}) for ${listUrl}${detail}. Check the endpoint is reachable, or run 'artifacts auth login'.`);
|
|
290
218
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
throw
|
|
219
|
+
let parsed;
|
|
220
|
+
try {
|
|
221
|
+
if (!/application\/json/i.test(res.contentType))
|
|
222
|
+
throw new Error(NOT_A_LISTING);
|
|
223
|
+
parsed = parseShareListing(user, res.body);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
throw await workerBehindError(backend.baseUrl, 'the share listing (`?format=json`)', fetchListing);
|
|
299
227
|
}
|
|
300
|
-
const parsed = parseShareListing(user, res.body);
|
|
301
228
|
return applyShareListFilters(parsed, {
|
|
302
229
|
agent: opts.agent,
|
|
303
230
|
session: opts.session,
|
|
@@ -370,19 +297,18 @@ export function formatShareList(result, json = false) {
|
|
|
370
297
|
});
|
|
371
298
|
return [header, ...rows].join('\n');
|
|
372
299
|
}
|
|
373
|
-
/** Parse the Worker's `?revisions=json` payload, failing loud
|
|
374
|
-
* outdated-template hint as {@link parseShareListing}) on an unexpected shape. */
|
|
300
|
+
/** Parse the Worker's `?revisions=json` payload, failing loud on an unexpected shape. */
|
|
375
301
|
export function parseShareRevisions(key, body) {
|
|
376
302
|
let data;
|
|
377
303
|
try {
|
|
378
304
|
data = JSON.parse(body);
|
|
379
305
|
}
|
|
380
306
|
catch {
|
|
381
|
-
throw new Error(
|
|
307
|
+
throw new Error(NOT_A_LISTING);
|
|
382
308
|
}
|
|
383
309
|
const revisionsRaw = data?.revisions;
|
|
384
310
|
if (!data || typeof data !== 'object' || !Array.isArray(revisionsRaw)) {
|
|
385
|
-
throw new Error(
|
|
311
|
+
throw new Error(NOT_A_LISTING);
|
|
386
312
|
}
|
|
387
313
|
const revisions = revisionsRaw.map((o) => {
|
|
388
314
|
const item = o;
|
|
@@ -408,56 +334,31 @@ export function parseShareRevisions(key, body) {
|
|
|
408
334
|
* or a bare slug resolved against the caller's own namespace) — reuses
|
|
409
335
|
* {@link resolveDeleteTarget} rather than re-deriving the key. */
|
|
410
336
|
export async function runShareRevisions(target, opts = {}) {
|
|
411
|
-
const backend = resolveShareBackend({
|
|
412
|
-
|
|
413
|
-
config: opts.config,
|
|
414
|
-
writeToken: opts.writeToken,
|
|
415
|
-
byo: opts.byo,
|
|
416
|
-
session: opts.session,
|
|
417
|
-
requireToken: false,
|
|
418
|
-
});
|
|
419
|
-
if (backend.kind === 'byo') {
|
|
420
|
-
const cfg = opts.config ?? readShareConfig();
|
|
421
|
-
if (cfg && shareTemplateStatus(cfg) === 'outdated') {
|
|
422
|
-
throw new Error(OUTDATED_TEMPLATE_HINT);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
const githubUser = backend.kind === 'managed'
|
|
426
|
-
? backend.namespace
|
|
427
|
-
: opts.githubUser || backend.namespace || undefined;
|
|
428
|
-
const { key } = await resolveDeleteTarget(target, { githubUser });
|
|
337
|
+
const backend = resolveShareBackend({ session: opts.session });
|
|
338
|
+
const { key } = resolveDeleteTarget(target, backend.namespace);
|
|
429
339
|
const revUrl = `${backend.baseUrl.replace(/\/+$/, '')}/${key}?revisions=json`;
|
|
430
340
|
const fetchListing = opts.fetchListing ?? defaultListingFetch;
|
|
431
341
|
const res = await fetchListing(revUrl);
|
|
432
342
|
if (res.status !== 200) {
|
|
433
343
|
const detail = formatShareHttpErrorDetail(extractShareHttpError({ status: res.status, body: res.body }));
|
|
434
|
-
throw new Error(`Revisions lookup failed (${res.status}) for ${revUrl}${detail}. Check the endpoint is reachable, or
|
|
344
|
+
throw new Error(`Revisions lookup failed (${res.status}) for ${revUrl}${detail}. Check the endpoint is reachable, or run 'artifacts auth login'.`);
|
|
435
345
|
}
|
|
436
|
-
|
|
437
|
-
if (
|
|
438
|
-
throw new Error(
|
|
439
|
-
|
|
440
|
-
|
|
346
|
+
try {
|
|
347
|
+
if (!/application\/json/i.test(res.contentType))
|
|
348
|
+
throw new Error(NOT_A_LISTING);
|
|
349
|
+
return parseShareRevisions(key, res.body);
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
throw await workerBehindError(backend.baseUrl, 'revision history (`?revisions=json`)', fetchListing);
|
|
441
353
|
}
|
|
442
|
-
return parseShareRevisions(key, res.body);
|
|
443
354
|
}
|
|
444
355
|
/** Mint a one-time login ticket for the signed-in owner and build the URL that
|
|
445
356
|
* opens their own published page **as the owner**, so the inline visibility
|
|
446
|
-
* control is live in the browser.
|
|
447
|
-
* the Phoenix identity, and BYO (WRITE_TOKEN) endpoints have no per-viewer login. */
|
|
357
|
+
* control is live in the browser. */
|
|
448
358
|
export async function runShareOpen(target, opts = {}) {
|
|
449
|
-
const backend = resolveShareBackend({
|
|
450
|
-
githubUser: opts.githubUser,
|
|
451
|
-
config: opts.config,
|
|
452
|
-
session: opts.session,
|
|
453
|
-
requireToken: false,
|
|
454
|
-
});
|
|
455
|
-
if (backend.kind !== 'managed') {
|
|
456
|
-
throw new Error("'artifacts share open' needs a managed (Phoenix) endpoint — the page's inline " +
|
|
457
|
-
"visibility control is gated on your signed-in identity. Run 'artifacts auth login' first.");
|
|
458
|
-
}
|
|
359
|
+
const backend = resolveShareBackend({ session: opts.session });
|
|
459
360
|
const baseUrl = backend.baseUrl.replace(/\/+$/, '');
|
|
460
|
-
const { key } =
|
|
361
|
+
const { key } = resolveDeleteTarget(target, backend.namespace);
|
|
461
362
|
const url = `${baseUrl}/${key}`;
|
|
462
363
|
const doFetch = opts.fetchTicket ??
|
|
463
364
|
(async (u, bearer) => {
|
|
@@ -465,9 +366,11 @@ export async function runShareOpen(target, opts = {}) {
|
|
|
465
366
|
return { status: res.status, body: await res.text() };
|
|
466
367
|
});
|
|
467
368
|
const res = await doFetch(`${baseUrl}/__ticket`, backend.token);
|
|
369
|
+
if (res.status === 404)
|
|
370
|
+
throw await workerBehindError(baseUrl, 'owner login tickets (`/__ticket`)');
|
|
468
371
|
if (res.status !== 200) {
|
|
469
|
-
|
|
470
|
-
|
|
372
|
+
const detail = formatShareHttpErrorDetail(extractShareHttpError({ status: res.status, body: res.body }));
|
|
373
|
+
throw new Error(`Could not mint a login ticket (${res.status}) from ${baseUrl}/__ticket${detail}.`);
|
|
471
374
|
}
|
|
472
375
|
let ticket;
|
|
473
376
|
try {
|
|
@@ -530,6 +433,12 @@ function formatShareVisibilityResult(result, requested) {
|
|
|
530
433
|
chalk.dim(' body unchanged — no revision created'),
|
|
531
434
|
].join('\n');
|
|
532
435
|
}
|
|
436
|
+
/** `--for-user` once named a GitHub namespace for bare-slug targets. Every
|
|
437
|
+
* target now resolves against the signed-in handle; the flag is accepted and
|
|
438
|
+
* ignored so existing scripts keep parsing. */
|
|
439
|
+
function ignoredForUserOption() {
|
|
440
|
+
return new Option('--for-user <user>').hideHelp();
|
|
441
|
+
}
|
|
533
442
|
/** Shared handler for `artifacts share delete <targets...>` and the top-level
|
|
534
443
|
* `artifacts unshare <targets...>` alias. Deletes each target independently and
|
|
535
444
|
* continues past a failed one (rm-style), reporting all results and exiting
|
|
@@ -546,7 +455,6 @@ export async function runShareDelete(targets, opts, deleteFn = deleteShare) {
|
|
|
546
455
|
keepCover: opts.keepCover === true,
|
|
547
456
|
keepRevisions: opts.keepRevisions === true,
|
|
548
457
|
ifExists: opts.ifExists === true,
|
|
549
|
-
githubUser: opts.forUser,
|
|
550
458
|
});
|
|
551
459
|
results.push({ target, result });
|
|
552
460
|
if (!opts.deleteJson)
|
|
@@ -573,14 +481,11 @@ function registerShareDeleteOptions(cmd) {
|
|
|
573
481
|
.option('--keep-cover', 'leave the sibling <slug>.png OG cover in place (default: delete it too)')
|
|
574
482
|
.option('--keep-revisions', 'leave retained revisions (<slug>/rev-*) in place (default: delete them too)')
|
|
575
483
|
.option('--if-exists', 'treat an already-missing target as a no-op success instead of an error')
|
|
576
|
-
|
|
577
|
-
// <file>` (the parent of the nested
|
|
578
|
-
//
|
|
579
|
-
// the WHOLE ancestor chain — a same-named child option is
|
|
580
|
-
// dropped at parse time even when it parses alone.
|
|
581
|
-
// `revisions`/`list` precedents below, and applies equally to the top-level
|
|
582
|
-
// `unshare` alias so both spellings stay identical.
|
|
583
|
-
.option('--for-user <user>', 'GitHub username for resolving a bare-slug target (default: resolved from gh/git config)')
|
|
484
|
+
.addOption(ignoredForUserOption())
|
|
485
|
+
// Named --delete-json, not --json: `share <file>` (the parent of the nested
|
|
486
|
+
// `share delete`) already owns --json, and commander resolves an option's
|
|
487
|
+
// long name against the WHOLE ancestor chain — a same-named child option is
|
|
488
|
+
// silently dropped at parse time even when it parses alone.
|
|
584
489
|
.option('--delete-json', 'emit machine-readable results');
|
|
585
490
|
}
|
|
586
491
|
const SHARE_DELETE_HELP = `
|
|
@@ -609,6 +514,78 @@ Notes:
|
|
|
609
514
|
|
|
610
515
|
artifacts share delete === artifacts unshare (same command, different name).
|
|
611
516
|
`;
|
|
517
|
+
/**
|
|
518
|
+
* Signed out: an interactive terminal runs the `artifacts auth login` device
|
|
519
|
+
* flow inline (prompts on stderr, so `--json` stdout stays clean); anything
|
|
520
|
+
* else fails with the command to run.
|
|
521
|
+
*/
|
|
522
|
+
async function ensureSignedIn() {
|
|
523
|
+
if (readSession())
|
|
524
|
+
return;
|
|
525
|
+
if (!(process.stdin.isTTY && process.stdout.isTTY))
|
|
526
|
+
throw new Error(SIGNED_OUT_MESSAGE);
|
|
527
|
+
console.error(chalk.dim('Not signed in. Starting `artifacts auth login`…'));
|
|
528
|
+
await authLogin(console.error);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* The one publish path behind `artifacts share <file>` and
|
|
532
|
+
* `artifacts render --publish`. Throws on failure; callers print the result.
|
|
533
|
+
*/
|
|
534
|
+
export async function runSharePublish(file, opts = {}) {
|
|
535
|
+
if (!existsSync(file))
|
|
536
|
+
throw new Error(`No such file: ${file}`);
|
|
537
|
+
const meta = parseMetaEntries(opts.meta ?? []);
|
|
538
|
+
const visibility = resolveVisibility({
|
|
539
|
+
visibility: opts.visibility,
|
|
540
|
+
unlisted: opts.unlisted === true || opts.private === true,
|
|
541
|
+
protected: opts.protected === true,
|
|
542
|
+
});
|
|
543
|
+
await ensureSignedIn();
|
|
544
|
+
// unlisted (incl. its --private alias) is obscurity, not read-auth — warn
|
|
545
|
+
// loudly before the publish so a "private" link is never mistaken for a
|
|
546
|
+
// gated one. Skipped for --json so machine output stays clean.
|
|
547
|
+
if (visibility === 'unlisted' && !opts.json) {
|
|
548
|
+
console.error(chalk.yellow(`⚠ ${unlistedNotPrivateWarning()}`));
|
|
549
|
+
}
|
|
550
|
+
// Fill the session's hosted avatar (one /auth/me call, no-op when already
|
|
551
|
+
// known) so the attribution bar can show the OAuth profile image.
|
|
552
|
+
await refreshSessionAvatar();
|
|
553
|
+
const uploadPath = await resolveUploadPath(file);
|
|
554
|
+
let progressLineOpen = false;
|
|
555
|
+
const onUploadProgress = process.stderr.isTTY === true && !opts.json
|
|
556
|
+
? (uploadedBytes, totalBytes) => {
|
|
557
|
+
progressLineOpen = uploadedBytes < totalBytes;
|
|
558
|
+
const percent = totalBytes > 0 ? Math.floor((uploadedBytes / totalBytes) * 100) : 100;
|
|
559
|
+
process.stderr.write(`\r${chalk.dim(`Uploading ${formatBytes(uploadedBytes)} / ${formatBytes(totalBytes)} (${percent}%)`)}`);
|
|
560
|
+
if (!progressLineOpen)
|
|
561
|
+
process.stderr.write('\n');
|
|
562
|
+
}
|
|
563
|
+
: undefined;
|
|
564
|
+
try {
|
|
565
|
+
return await publishFile(uploadPath, {
|
|
566
|
+
slug: opts.slug,
|
|
567
|
+
handle: opts.handle,
|
|
568
|
+
expire: opts.expire,
|
|
569
|
+
visibility,
|
|
570
|
+
...(opts.comments ? { comments: commentPolicyFromFlag(opts.comments) } : {}),
|
|
571
|
+
force: opts.force,
|
|
572
|
+
// A capability URL is only as private as its obscurity, and a gallery
|
|
573
|
+
// OG cover is a second world-readable object under a derivable key.
|
|
574
|
+
// Public pages get a cover; anything hidden does not, unless the author
|
|
575
|
+
// has already opted out with --no-cover (in which case honour that).
|
|
576
|
+
cover: opts.cover === false ? false : visibility === 'public',
|
|
577
|
+
qr: opts.qr,
|
|
578
|
+
label: opts.label ?? opts.title,
|
|
579
|
+
meta,
|
|
580
|
+
noRevision: opts.revision === false,
|
|
581
|
+
onUploadProgress,
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
finally {
|
|
585
|
+
if (progressLineOpen)
|
|
586
|
+
process.stderr.write('\n');
|
|
587
|
+
}
|
|
588
|
+
}
|
|
612
589
|
/**
|
|
613
590
|
* Register the `share` subtree on the root program, plus the top-level
|
|
614
591
|
* `artifacts unshare` alias (see {@link registerUnshareCommand}).
|
|
@@ -620,22 +597,23 @@ export function registerShareCommands(program) {
|
|
|
620
597
|
// `list --meta`). Keep option ownership positional within this subtree so
|
|
621
598
|
// Commander does not silently resolve those flags to the parent publisher.
|
|
622
599
|
.enablePositionalOptions()
|
|
623
|
-
.description('Publish an artifact to a shareable link
|
|
624
|
-
.argument('[file]', 'file to publish (Markdown, HTML, any static asset
|
|
600
|
+
.description('Publish an artifact to a shareable link on share.getrush.ai (signs you in first when needed).')
|
|
601
|
+
.argument('[file]', 'file to publish (Markdown, HTML, or any static asset)')
|
|
625
602
|
.option('--slug <slug>', 'URL slug override (default: stable slug of the artifact title, then filename)')
|
|
626
|
-
|
|
627
|
-
.
|
|
603
|
+
// Accepted and ignored for one release so scripts that still pass it keep parsing.
|
|
604
|
+
.addOption(new Option('--github-user <user>').hideHelp())
|
|
605
|
+
.option('--handle <name>', 'publish under an alternate public handle instead of your email local-part. The escape hatch when your derived handle is taken, or for a vanity namespace — the Worker binds it with the same first-writer claim')
|
|
628
606
|
.option('--expire <spec>', "auto-expire (default 30d). e.g. 12h, 30d, 2026-08-01, or 'never'")
|
|
629
607
|
.addOption(new Option('--visibility <level>', 'public (default) | unlisted | private | me | org. public is listed in the gallery and gets an OG cover; me is owner-only and org is your whole email domain (both need a Phoenix session); unlisted is an UNAUTHENTICATED capability URL; private is token-gated (404 without the key)')
|
|
630
608
|
.choices([...PUBLISH_VISIBILITY_LEVELS]))
|
|
631
609
|
.addOption(new Option('--protected', 'token-gated link (= --visibility private): the URL carries a secret key and returns 404 without it — the authenticated alternative to --unlisted'))
|
|
632
610
|
.option('--unlisted', 'alias of --visibility unlisted: hidden from the gallery, noindex, no OG cover (obscurity, NOT authentication)')
|
|
633
|
-
.addOption(new Option('--comments <who>', 'who may comment on hosted review threads: off | audience | signed-in (default: audience for me/org, signed-in
|
|
611
|
+
.addOption(new Option('--comments <who>', 'who may comment on hosted review threads: off | audience | signed-in (default: audience for me/org, signed-in otherwise)')
|
|
634
612
|
.choices([...COMMENT_POLICY_FLAGS]))
|
|
635
613
|
.addOption(new Option('--private', 'alias of --unlisted (obscurity, NOT authentication — for real read-auth use --protected)').hideHelp())
|
|
636
614
|
.option('--force', 'publish even when the file contains emails or credential-shaped strings')
|
|
637
615
|
.option('--no-cover', 'skip the OG preview image (public HTML pages get one by default)')
|
|
638
|
-
.
|
|
616
|
+
.addOption(new Option('--no-analytics').hideHelp())
|
|
639
617
|
.option('--no-qr', 'skip the footer QR of the share URL (embedded in published HTML pages by default)')
|
|
640
618
|
.option('--label <text>', 'human display title, shown in the gallery and `share list` (default: derived from the HTML <title>, frontmatter title, or filename)')
|
|
641
619
|
.option('--title <text>', 'alias of --label')
|
|
@@ -647,86 +625,21 @@ export function registerShareCommands(program) {
|
|
|
647
625
|
shareCmd.help();
|
|
648
626
|
return;
|
|
649
627
|
}
|
|
650
|
-
// A 64-hex artifact id resolves through the local store inside
|
|
651
|
-
// resolveUploadPath (latest saved snapshot), so it skips the file check.
|
|
652
|
-
if (!/^[0-9a-f]{64}$/.test(file) && !existsSync(file)) {
|
|
653
|
-
console.error(chalk.red(`No such file: ${file}`));
|
|
654
|
-
process.exitCode = 1;
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
let progressLineOpen = false;
|
|
658
628
|
try {
|
|
659
|
-
const
|
|
660
|
-
// Public by default: an explicit flag wins; otherwise the backend-aware
|
|
661
|
-
// default. `shareBackendKind` reads the same session/BYO signals
|
|
662
|
-
// `publishFile` will resolve, so the default matches the backend the
|
|
663
|
-
// publish actually uses.
|
|
664
|
-
const visibility = publishVisibility({
|
|
665
|
-
visibility: opts.visibility,
|
|
666
|
-
unlisted: opts.unlisted === true || opts.private === true,
|
|
667
|
-
protected: opts.protected === true,
|
|
668
|
-
}, shareBackendKind({}));
|
|
669
|
-
// unlisted (incl. its --private alias) is obscurity, not read-auth — warn
|
|
670
|
-
// loudly before the publish so a "private" link is never mistaken for a
|
|
671
|
-
// gated one. Skipped for --json so machine output stays clean.
|
|
672
|
-
if (visibility === 'unlisted' && !opts.json) {
|
|
673
|
-
console.error(chalk.yellow(`⚠ ${unlistedNotPrivateWarning()}`));
|
|
674
|
-
}
|
|
675
|
-
const managed = shareBackendKind({}) === 'managed';
|
|
676
|
-
// Managed publish: fill the session's hosted avatar (one /auth/me call,
|
|
677
|
-
// no-op when already known) so the attribution bar can show the OAuth
|
|
678
|
-
// profile image.
|
|
679
|
-
if (managed)
|
|
680
|
-
await refreshSessionAvatar();
|
|
681
|
-
const uploadPath = await resolveUploadPath(file);
|
|
682
|
-
const onUploadProgress = process.stderr.isTTY === true && !opts.json
|
|
683
|
-
? (uploadedBytes, totalBytes) => {
|
|
684
|
-
progressLineOpen = uploadedBytes < totalBytes;
|
|
685
|
-
const percent = totalBytes > 0 ? Math.floor((uploadedBytes / totalBytes) * 100) : 100;
|
|
686
|
-
process.stderr.write(`\r${chalk.dim(`Uploading ${formatBytes(uploadedBytes)} / ${formatBytes(totalBytes)} (${percent}%)`)}`);
|
|
687
|
-
if (!progressLineOpen)
|
|
688
|
-
process.stderr.write('\n');
|
|
689
|
-
}
|
|
690
|
-
: undefined;
|
|
691
|
-
const result = await publishFile(uploadPath, {
|
|
692
|
-
slug: opts.slug,
|
|
693
|
-
githubUser: opts.githubUser,
|
|
694
|
-
handle: opts.handle,
|
|
695
|
-
expire: opts.expire,
|
|
696
|
-
visibility,
|
|
697
|
-
unlisted: visibility === 'unlisted',
|
|
698
|
-
protected: visibility === 'private',
|
|
699
|
-
...(opts.comments ? { comments: commentPolicyFromFlag(opts.comments) } : {}),
|
|
700
|
-
force: opts.force,
|
|
701
|
-
// A capability URL is only as private as its obscurity, and a gallery
|
|
702
|
-
// OG cover is a second world-readable object under a derivable key.
|
|
703
|
-
// Public pages get a cover; anything hidden does not, unless the author
|
|
704
|
-
// has already opted out with --no-cover (in which case honour that).
|
|
705
|
-
cover: opts.cover === false ? false : visibility === 'public',
|
|
706
|
-
analytics: opts.analytics,
|
|
707
|
-
qr: opts.qr,
|
|
708
|
-
label: opts.label ?? opts.title,
|
|
709
|
-
meta,
|
|
710
|
-
noRevision: opts.revision === false,
|
|
711
|
-
onUploadProgress,
|
|
712
|
-
});
|
|
629
|
+
const result = await runSharePublish(file, opts);
|
|
713
630
|
console.log(formatSharePublishResult(result, Boolean(opts.json)));
|
|
714
631
|
if (result.collab && !result.collab.registered && !opts.json) {
|
|
715
632
|
console.error(chalk.yellow(`⚠ ${collabRegistrationWarning(result.collab)}`));
|
|
716
633
|
}
|
|
717
634
|
}
|
|
718
635
|
catch (e) {
|
|
719
|
-
if (progressLineOpen)
|
|
720
|
-
process.stderr.write('\n');
|
|
721
636
|
console.error(chalk.red(e.message));
|
|
722
637
|
process.exitCode = 1;
|
|
723
638
|
}
|
|
724
639
|
})
|
|
725
640
|
.addHelpText('after', `
|
|
726
641
|
Examples:
|
|
727
|
-
# Signed in? Just publish — no Cloudflare setup (managed endpoint).
|
|
728
642
|
# The default is public: listed in your gallery with an OG preview card.
|
|
729
|
-
$ artifacts auth login
|
|
730
643
|
$ artifacts share ./out/plan.html
|
|
731
644
|
|
|
732
645
|
# Markdown is rendered first, then published
|
|
@@ -736,7 +649,7 @@ Examples:
|
|
|
736
649
|
$ artifacts share ./out/plan.html --visibility me
|
|
737
650
|
$ artifacts share ./out/plan.html --visibility org
|
|
738
651
|
|
|
739
|
-
# Large
|
|
652
|
+
# Large recordings stream in resumable 50 MiB parts
|
|
740
653
|
$ artifacts share recording.mp4 --visibility org --expire never
|
|
741
654
|
|
|
742
655
|
# Hide from the gallery (direct URL still works, noindex, no card), expire sooner
|
|
@@ -753,19 +666,13 @@ Examples:
|
|
|
753
666
|
$ artifacts share ./out/landing.html --expire never --slug q3-landing
|
|
754
667
|
$ artifacts share ./out/plan.html --label "Q3 fleet plan" --meta kind=plan
|
|
755
668
|
${SHARE_DELETE_HELP}
|
|
756
|
-
# One-time BYO setup (or join an existing endpoint)
|
|
757
|
-
$ artifacts share setup --token <cf-token> --account <cf-account>
|
|
758
|
-
$ artifacts share join https://share.getrush.ai --token <write-token>
|
|
759
|
-
|
|
760
|
-
# Push a worker-template.ts change out to an already-provisioned endpoint
|
|
761
|
-
$ artifacts share update
|
|
762
669
|
|
|
763
670
|
Notes:
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
671
|
+
Pages publish to share.getrush.ai/<handle>/… with your Phoenix session. Signed
|
|
672
|
+
out, an interactive terminal runs 'artifacts auth login' first; a script or
|
|
673
|
+
agent run exits non-zero and names that command. The handle is the local-part
|
|
674
|
+
of the signed-in email; --handle publishes under an alternate public namespace
|
|
675
|
+
instead (first-writer-claimed like the derived one).
|
|
769
676
|
|
|
770
677
|
The default slug is derived deterministically from the HTML <title> or Markdown
|
|
771
678
|
frontmatter title, then the filename, so republishing the same title updates the
|
|
@@ -781,7 +688,7 @@ Notes:
|
|
|
781
688
|
is the real read-auth — the URL carries a secret ?k= key and GET returns 404
|
|
782
689
|
without it.
|
|
783
690
|
|
|
784
|
-
Eligible
|
|
691
|
+
Eligible video/* publishes over 20 MiB use resumable multipart upload
|
|
785
692
|
for --visibility me or org. Re-run the same command after an interruption to
|
|
786
693
|
continue from the completed parts saved under ~/.artifacts/uploads/. Progress
|
|
787
694
|
is written only to an interactive terminal.
|
|
@@ -813,21 +720,21 @@ Notes:
|
|
|
813
720
|
// `artifacts share visibility <target> <level>` — change an already-published
|
|
814
721
|
// page's visibility in place. It reuses the delete target parser and the same
|
|
815
722
|
// PATCH metadata-edit route as `share edit` (visibility is metadata), so it
|
|
816
|
-
// re-stamps the stored object rather than re-publishing. --
|
|
817
|
-
//
|
|
818
|
-
//
|
|
819
|
-
//
|
|
723
|
+
// re-stamps the stored object rather than re-publishing. --visibility-json
|
|
724
|
+
// (not --json): the parent `share <file>` already owns that long name, and
|
|
725
|
+
// commander resolves a child option's long name against the whole ancestor
|
|
726
|
+
// chain, silently dropping a same-named child.
|
|
820
727
|
const shareVisibilityCmd = shareCmd
|
|
821
728
|
.command('visibility')
|
|
822
729
|
.description("Change an already-published page's visibility in place (public | unlisted | me | org). The slug/URL is preserved; the body is untouched, so no revision is created.")
|
|
823
730
|
.addArgument(new Argument('<target>', 'the published page: a full URL, <user>/<slug>, or a bare slug in your namespace'))
|
|
824
731
|
.addArgument(new Argument('<level>', 'new visibility').choices([...SHARE_VISIBILITY_LEVELS]))
|
|
825
|
-
.
|
|
732
|
+
.addOption(ignoredForUserOption())
|
|
826
733
|
.option('--visibility-json', 'emit a machine-readable result')
|
|
827
734
|
.action(async (target, level, opts) => {
|
|
828
735
|
try {
|
|
829
736
|
const visibility = level;
|
|
830
|
-
const result = await runShareEdit(target, { visibility
|
|
737
|
+
const result = await runShareEdit(target, { visibility });
|
|
831
738
|
if (opts.visibilityJson) {
|
|
832
739
|
console.log(JSON.stringify(result, null, 2));
|
|
833
740
|
return;
|
|
@@ -862,12 +769,12 @@ Notes:
|
|
|
862
769
|
.command('open')
|
|
863
770
|
.description("Open your own published page in the browser signed in as the owner, so the page's inline visibility control is live. Mints a one-time login ticket and appends it to the URL.")
|
|
864
771
|
.addArgument(new Argument('<target>', 'the published page: a full URL, <user>/<slug>, or a bare slug in your namespace'))
|
|
865
|
-
.
|
|
772
|
+
.addOption(ignoredForUserOption())
|
|
866
773
|
.option('--no-open', 'print the owner URL instead of opening a browser')
|
|
867
774
|
.option('--open-json', 'emit a machine-readable result (includes the ticketed owner URL)')
|
|
868
775
|
.action(async (target, opts) => {
|
|
869
776
|
try {
|
|
870
|
-
const result = await runShareOpen(target
|
|
777
|
+
const result = await runShareOpen(target);
|
|
871
778
|
if (opts.openJson) {
|
|
872
779
|
console.log(JSON.stringify(result, null, 2));
|
|
873
780
|
return;
|
|
@@ -898,91 +805,17 @@ Notes:
|
|
|
898
805
|
share Worker) and opens the page with it, so the chip becomes a dropdown you
|
|
899
806
|
can switch in place.
|
|
900
807
|
|
|
901
|
-
Managed (Phoenix) endpoints only — run 'artifacts auth login' first.
|
|
902
|
-
mint 501s/404s, the Worker predates the feature: run 'artifacts share update'.
|
|
808
|
+
Managed (Phoenix) endpoints only — run 'artifacts auth login' first.
|
|
903
809
|
Prefer no browser? Use 'artifacts share visibility <target> <level>'.
|
|
904
810
|
`);
|
|
905
811
|
void shareOpenCmd;
|
|
906
812
|
shareCmd
|
|
907
|
-
.command('setup')
|
|
908
|
-
.description('Provision your own Cloudflare R2 bucket + Worker and save the endpoint config.')
|
|
909
|
-
.option('--bundle <name>', 'secrets bundle holding the Cloudflare API token', DEFAULT_CF_BUNDLE)
|
|
910
|
-
.option('--token <token>', 'Cloudflare API token (else CLOUDFLARE_API_TOKEN, else --bundle)')
|
|
911
|
-
.option('--account <id>', 'Cloudflare account id (else CLOUDFLARE_ACCOUNT_ID, else --bundle)')
|
|
912
|
-
.option('--worker <name>', 'Worker name', DEFAULT_WORKER_NAME)
|
|
913
|
-
.option('--bucket <name>', 'R2 bucket name', DEFAULT_BUCKET_NAME)
|
|
914
|
-
.option('--domain <host>', 'custom hostname to map, when your token owns the zone')
|
|
915
|
-
.option('--analytics-token <token>', 'Cloudflare Web Analytics token to inject into published pages')
|
|
916
|
-
.option('--unlimited-storage <json>', 'operator allowlist: JSON with exact emails and domains arrays; persisted for future updates')
|
|
917
|
-
.option('--managed', 'bind PHOENIX_ID_BASE so this Worker also accepts Phoenix bearers')
|
|
918
|
-
.option('--collab-api <url>', `bind hosted review threads to Rush Cloud at <url>; the service token comes from ${COLLAB_SERVICE_TOKEN_ENV}`)
|
|
919
|
-
.option('--media-keys', 'bind video transcripts + summaries: DEEPGRAM_API_KEY, OPENROUTER_API_KEY and MEDIA_JOB_SECRET from the environment')
|
|
920
|
-
.action(async (opts) => {
|
|
921
|
-
try {
|
|
922
|
-
await runShareProvision(opts);
|
|
923
|
-
}
|
|
924
|
-
catch (e) {
|
|
925
|
-
console.error(chalk.red(e.message));
|
|
926
|
-
process.exitCode = 1;
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
shareCmd
|
|
930
|
-
.command('join')
|
|
931
|
-
.description('Use an existing share endpoint and write token (no provisioning).')
|
|
932
|
-
.argument('<baseUrl>', 'base URL of the endpoint, e.g. https://share.getrush.ai')
|
|
933
|
-
.option('--token <token>', 'write token (else ARTIFACTS_SHARE_TOKEN / SHARE_WRITE_TOKEN)')
|
|
934
|
-
.option('--worker <name>', 'Worker name behind the endpoint', DEFAULT_WORKER_NAME)
|
|
935
|
-
.option('--bucket <name>', 'R2 bucket behind the endpoint', DEFAULT_BUCKET_NAME)
|
|
936
|
-
.option('--account <id>', 'Cloudflare account id (needed later by `artifacts share update`)')
|
|
937
|
-
.action((baseUrl, opts) => {
|
|
938
|
-
try {
|
|
939
|
-
runShareJoin(baseUrl, opts);
|
|
940
|
-
}
|
|
941
|
-
catch (e) {
|
|
942
|
-
console.error(chalk.red(e.message));
|
|
943
|
-
process.exitCode = 1;
|
|
944
|
-
}
|
|
945
|
-
});
|
|
946
|
-
const shareUpdateCmd = shareCmd
|
|
947
813
|
.command('update')
|
|
948
|
-
.description('
|
|
949
|
-
.
|
|
950
|
-
.option('--account <id>', "Cloudflare account id override (default: the configured endpoint's account)")
|
|
951
|
-
.option('--token <t>', 'Cloudflare API token (else CLOUDFLARE_API_TOKEN, else --bundle)')
|
|
952
|
-
.option('--force', 're-deploy even if the deployed template already matches')
|
|
953
|
-
.option('--check', 'report whether a deploy is needed and exit without deploying (needs no Cloudflare credentials)')
|
|
954
|
-
.option('--unlimited-storage <json>', 'operator allowlist: JSON with exact emails and domains arrays; persisted for future updates')
|
|
955
|
-
.option('--managed', 'bind PHOENIX_ID_BASE even when the configured hostname is not the managed domain')
|
|
956
|
-
.option('--collab-api <url>', `bind hosted review threads to Rush Cloud at <url>; the service token comes from ${COLLAB_SERVICE_TOKEN_ENV}`)
|
|
957
|
-
.option('--media-keys', 'bind video transcripts + summaries: DEEPGRAM_API_KEY, OPENROUTER_API_KEY and MEDIA_JOB_SECRET from the environment')
|
|
958
|
-
// Named --update-json, not --json: `share <file>` (the parent) already owns
|
|
959
|
-
// --json for its own publish result, and commander resolves an option's long
|
|
960
|
-
// name against the WHOLE ancestor chain, so a same-named child option is
|
|
961
|
-
// silently dropped at parse time.
|
|
962
|
-
.option('--update-json', 'emit a machine-readable result')
|
|
963
|
-
.action(async (opts) => {
|
|
814
|
+
.description(`Deploy this CLI's share Worker to ${DEFAULT_SHARE_DOMAIN} only, keeping the Worker's secrets (the release workflow runs it).`)
|
|
815
|
+
.action(async () => {
|
|
964
816
|
try {
|
|
965
|
-
const result = await runShareUpdate(
|
|
966
|
-
|
|
967
|
-
console.log(JSON.stringify(result, null, 2));
|
|
968
|
-
return;
|
|
969
|
-
}
|
|
970
|
-
if (result.checked) {
|
|
971
|
-
console.log(result.deployNeeded
|
|
972
|
-
? chalk.yellow(`Worker '${result.workerName}' needs an update (current render ${result.templateHash.slice(0, 12)}…).`)
|
|
973
|
-
: chalk.dim(`Worker '${result.workerName}' already matches the current template — no deploy needed.`));
|
|
974
|
-
return;
|
|
975
|
-
}
|
|
976
|
-
if (result.updated) {
|
|
977
|
-
console.log(chalk.green(`Worker '${result.workerName}' updated → template ${result.templateHash.slice(0, 12)}…`));
|
|
978
|
-
}
|
|
979
|
-
else {
|
|
980
|
-
console.log(chalk.dim(`Worker '${result.workerName}' already matches the current template — no-op.`));
|
|
981
|
-
}
|
|
982
|
-
if (result.collabApi)
|
|
983
|
-
console.log(chalk.dim(`Review threads bound → ${result.collabApi}`));
|
|
984
|
-
if (result.mediaKeys)
|
|
985
|
-
console.log(chalk.dim('Media keys bound → video transcripts and summaries are on'));
|
|
817
|
+
const result = await runShareUpdate();
|
|
818
|
+
console.log(chalk.green(`Worker '${result.workerName}' deployed at ${result.url}: artifacts-cli ${result.version}`));
|
|
986
819
|
}
|
|
987
820
|
catch (e) {
|
|
988
821
|
console.error(chalk.red(e.message));
|
|
@@ -990,90 +823,37 @@ Notes:
|
|
|
990
823
|
}
|
|
991
824
|
})
|
|
992
825
|
.addHelpText('after', `
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
Notes:
|
|
1001
|
-
Reuses the existing account/worker/bucket and write token — it never
|
|
1002
|
-
re-provisions a bucket, touches routes, or regenerates the token. See
|
|
1003
|
-
'artifacts share status' for whether an update is due.
|
|
1004
|
-
|
|
1005
|
-
--check renders the current template and compares its hash to what the endpoint
|
|
1006
|
-
last deployed, then exits — deploying nothing and reading no Cloudflare
|
|
1007
|
-
credentials. The release script uses it to decide, after publish, whether the
|
|
1008
|
-
shipped template changed.
|
|
1009
|
-
|
|
1010
|
-
The Cloudflare API token comes from --token, then the environment, then the
|
|
1011
|
-
named --bundle. Under a secrets manager the usual form is:
|
|
1012
|
-
agents secrets exec cloudflare -- artifacts share update
|
|
1013
|
-
|
|
1014
|
-
--collab-api turns on hosted review threads: the Worker answers /__collab/*
|
|
1015
|
-
and forwards to Rush Cloud's /internal/artifact-collab at that origin, with
|
|
1016
|
-
the service token from ${COLLAB_SERVICE_TOKEN_ENV}. Both values are bound
|
|
1017
|
-
together or not at all. Later updates without the flag keep an existing
|
|
1018
|
-
pair; a Worker without one serves no comment rail.
|
|
1019
|
-
|
|
1020
|
-
--media-keys turns on video transcripts and summaries: DEEPGRAM_API_KEY,
|
|
1021
|
-
OPENROUTER_API_KEY and MEDIA_JOB_SECRET (any long random string; it signs
|
|
1022
|
-
Deepgram's source link and callback) are read from the environment and bound
|
|
1023
|
-
as Worker secrets, all three or none. Later updates without the flag keep an
|
|
1024
|
-
existing set.
|
|
826
|
+
Deploys the managed worker '${DEFAULT_WORKER_NAME}' (R2 bucket '${DEFAULT_BUCKET_NAME}') with
|
|
827
|
+
CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID from the environment, and
|
|
828
|
+
refuses unless that Worker already has ${MANAGED_WORKER_BINDINGS.join(', ')}.
|
|
829
|
+
Every binding it has is inherited, so the deploy needs none of their values.
|
|
830
|
+
Change a secret with:
|
|
831
|
+
wrangler secret put <NAME> --name ${DEFAULT_WORKER_NAME}
|
|
1025
832
|
`);
|
|
1026
|
-
void shareUpdateCmd;
|
|
1027
833
|
shareCmd
|
|
1028
834
|
.command('status')
|
|
1029
|
-
.description('Show the
|
|
835
|
+
.description('Show the share endpoint and your namespace on it.')
|
|
1030
836
|
.action(async () => {
|
|
1031
837
|
let backend;
|
|
1032
838
|
try {
|
|
1033
|
-
backend = resolveShareBackend(
|
|
839
|
+
backend = resolveShareBackend();
|
|
1034
840
|
}
|
|
1035
841
|
catch (e) {
|
|
1036
842
|
console.log(chalk.dim(e.message));
|
|
1037
843
|
return;
|
|
1038
844
|
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
console.log(`${chalk.bold('namespace')} ${chalk.cyan(`${backend.baseUrl}/${backend.namespace}`)}`);
|
|
1043
|
-
console.log(chalk.dim('Phoenix session — no Cloudflare setup. Force BYO with ARTIFACTS_SHARE_BACKEND=byo.'));
|
|
1044
|
-
return;
|
|
1045
|
-
}
|
|
1046
|
-
const cfg = readShareConfig();
|
|
1047
|
-
if (!cfg) {
|
|
1048
|
-
console.log(chalk.dim("Not configured. Run 'artifacts auth login', 'artifacts share setup', or 'artifacts share join'."));
|
|
1049
|
-
return;
|
|
1050
|
-
}
|
|
1051
|
-
console.log(`${chalk.bold('backend')} ${chalk.green('byo')}`);
|
|
1052
|
-
console.log(`${chalk.bold('endpoint')} ${chalk.green(cfg.baseUrl)}`);
|
|
1053
|
-
console.log(chalk.dim(`worker ${cfg.workerName} · bucket ${cfg.bucketName} · account ${cfg.accountId || 'missing'}`));
|
|
1054
|
-
if (!cfg.accountId) {
|
|
1055
|
-
console.log(chalk.dim('account id empty — publish still uses baseUrl + the write token; `artifacts share update` needs --account or a re-join'));
|
|
1056
|
-
}
|
|
1057
|
-
const user = await resolveGitHubUsername();
|
|
1058
|
-
console.log(`${chalk.bold('namespace')} ${user ? chalk.cyan(`${cfg.baseUrl}/${user}`) : chalk.yellow('unknown — set gh auth or github.user')}`);
|
|
1059
|
-
console.log(`${chalk.bold('analytics')} ${analyticsEnabled(cfg) ? chalk.green('enabled') : chalk.dim('not configured')}`);
|
|
1060
|
-
const templateStatus = shareTemplateStatus(cfg);
|
|
1061
|
-
const templateLabel = templateStatus === 'current'
|
|
1062
|
-
? chalk.green('current')
|
|
1063
|
-
: templateStatus === 'outdated'
|
|
1064
|
-
? chalk.yellow('outdated — run `artifacts share update`')
|
|
1065
|
-
: chalk.dim('unknown — provisioned before version tracking; run `artifacts share update` to adopt it');
|
|
1066
|
-
console.log(`${chalk.bold('template')} ${templateLabel}`);
|
|
845
|
+
console.log(`${chalk.bold('endpoint')} ${chalk.green(backend.baseUrl)}`);
|
|
846
|
+
console.log(`${chalk.bold('namespace')} ${chalk.cyan(`${backend.baseUrl}/${backend.namespace}`)}`);
|
|
847
|
+
console.log(await workerStatusLine(backend.baseUrl));
|
|
1067
848
|
});
|
|
1068
849
|
const shareListCmd = shareCmd
|
|
1069
850
|
.command('list')
|
|
1070
851
|
.description("List the pages you've published to your share namespace (human table; --list-json for scripts).")
|
|
1071
|
-
// Named --
|
|
1072
|
-
//
|
|
1073
|
-
// names, and commander resolves a child option's long name against the WHOLE
|
|
852
|
+
// Named --list-json / --scope, not --json / --visibility: `share <file>`
|
|
853
|
+
// (the parent) owns both of those long names, and commander resolves a child option's long name against the WHOLE
|
|
1074
854
|
// ancestor chain — a same-named child option is silently dropped at parse
|
|
1075
855
|
// time even when it parses alone.
|
|
1076
|
-
.
|
|
856
|
+
.addOption(ignoredForUserOption())
|
|
1077
857
|
.addOption(new Option('--scope <level>', 'visibility filter: public (default), unlisted, private, me, org, or all')
|
|
1078
858
|
.choices(['public', 'unlisted', 'private', 'me', 'org', 'all'])
|
|
1079
859
|
.default('public'))
|
|
@@ -1089,7 +869,6 @@ Notes:
|
|
|
1089
869
|
const scope = opts.all ? 'all' : (opts.scope ?? 'public');
|
|
1090
870
|
const parentMeta = shareCmd.opts().meta ?? [];
|
|
1091
871
|
const result = await runShareList({
|
|
1092
|
-
githubUser: opts.forUser,
|
|
1093
872
|
scope,
|
|
1094
873
|
agent: opts.agent,
|
|
1095
874
|
session: opts.session,
|
|
@@ -1109,7 +888,6 @@ Examples:
|
|
|
1109
888
|
$ artifacts share list --all # include hidden unlisted/private/me/org pages
|
|
1110
889
|
$ artifacts share list --scope me
|
|
1111
890
|
$ artifacts share list --list-json | jq -r '.objects[].url'
|
|
1112
|
-
$ artifacts share list --for-user octocat
|
|
1113
891
|
$ artifacts share list --agent claude --label-contains "fleet plan" --meta kind=plan
|
|
1114
892
|
|
|
1115
893
|
Notes:
|
|
@@ -1126,7 +904,7 @@ Notes:
|
|
|
1126
904
|
const shareEditCmd = shareCmd
|
|
1127
905
|
.command('edit <target>')
|
|
1128
906
|
.description("Edit a published share's label or arbitrary metadata without republishing its body.")
|
|
1129
|
-
.
|
|
907
|
+
.addOption(ignoredForUserOption())
|
|
1130
908
|
.option('--label <text>', 'set or replace the display label')
|
|
1131
909
|
.option('--remove-label', 'remove the display label')
|
|
1132
910
|
.option('--meta <key=value>', 'merge a metadata entry (repeatable)', (v, p) => [...p, v], [])
|
|
@@ -1149,7 +927,6 @@ Notes:
|
|
|
1149
927
|
}
|
|
1150
928
|
const removeMeta = opts.removeMeta.map((key) => Object.keys(parseMetaEntries([`${key}=x`]))[0]);
|
|
1151
929
|
const result = await runShareEdit(target, {
|
|
1152
|
-
githubUser: opts.forUser,
|
|
1153
930
|
label: opts.removeLabel ? null : label === undefined ? undefined : sanitizeLabel(label),
|
|
1154
931
|
meta: parseMetaEntries(opts.replaceMeta.length ? opts.replaceMeta : mergeMeta),
|
|
1155
932
|
metaMode: opts.replaceMeta.length ? 'replace' : 'merge',
|
|
@@ -1183,11 +960,11 @@ Notes:
|
|
|
1183
960
|
const shareRevisionsCmd = shareCmd
|
|
1184
961
|
.command('revisions <target>')
|
|
1185
962
|
.description('Show the retained prior versions of a published slug, newest first (human table; --revisions-json for scripts).')
|
|
1186
|
-
.
|
|
963
|
+
.addOption(ignoredForUserOption())
|
|
1187
964
|
.option('--revisions-json', 'emit the machine-readable revision list')
|
|
1188
965
|
.action(async (target, opts) => {
|
|
1189
966
|
try {
|
|
1190
|
-
const result = await runShareRevisions(target
|
|
967
|
+
const result = await runShareRevisions(target);
|
|
1191
968
|
console.log(formatShareRevisions(result, Boolean(opts.revisionsJson)));
|
|
1192
969
|
}
|
|
1193
970
|
catch (e) {
|
|
@@ -1200,7 +977,7 @@ Examples:
|
|
|
1200
977
|
$ artifacts share revisions q3-report
|
|
1201
978
|
$ artifacts share revisions octocat/q3-report
|
|
1202
979
|
$ artifacts share revisions https://share.getrush.ai/octocat/q3-report
|
|
1203
|
-
$ artifacts share revisions q3-report --revisions-json
|
|
980
|
+
$ artifacts share revisions q3-report --revisions-json
|
|
1204
981
|
|
|
1205
982
|
Notes:
|
|
1206
983
|
A revision is created automatically on every republish of an existing slug
|
|
@@ -1239,11 +1016,11 @@ Notes:
|
|
|
1239
1016
|
shareMediaCmd
|
|
1240
1017
|
.command('status <target>')
|
|
1241
1018
|
.description('Show whether the transcript and summary are pending, ready or failed (and why).')
|
|
1242
|
-
.
|
|
1019
|
+
.addOption(ignoredForUserOption())
|
|
1243
1020
|
.option('--media-json', 'emit a machine-readable result')
|
|
1244
1021
|
.action(async (target, opts) => {
|
|
1245
1022
|
try {
|
|
1246
|
-
const status = await runShareMediaStatus(target
|
|
1023
|
+
const status = await runShareMediaStatus(target);
|
|
1247
1024
|
console.log(formatShareMediaStatus(status, Boolean(opts.mediaJson)));
|
|
1248
1025
|
if (status.media === 'failed')
|
|
1249
1026
|
process.exitCode = 1;
|
|
@@ -1256,55 +1033,17 @@ Notes:
|
|
|
1256
1033
|
shareMediaCmd
|
|
1257
1034
|
.command('retry <target>')
|
|
1258
1035
|
.description('Restart a failed transcript/summary job on a video you own (a summary failure re-runs only the summary).')
|
|
1259
|
-
.
|
|
1036
|
+
.addOption(ignoredForUserOption())
|
|
1260
1037
|
.option('--media-json', 'emit a machine-readable result')
|
|
1261
1038
|
.action(async (target, opts) => {
|
|
1262
1039
|
try {
|
|
1263
|
-
console.log(formatShareMediaRetry(await runShareMediaRetry(target
|
|
1040
|
+
console.log(formatShareMediaRetry(await runShareMediaRetry(target), Boolean(opts.mediaJson)));
|
|
1264
1041
|
}
|
|
1265
1042
|
catch (e) {
|
|
1266
1043
|
console.error(chalk.red(e.message));
|
|
1267
1044
|
process.exitCode = 1;
|
|
1268
1045
|
}
|
|
1269
1046
|
});
|
|
1270
|
-
shareCmd
|
|
1271
|
-
.command('analytics')
|
|
1272
|
-
.description('Show the Cloudflare Web Analytics status for this share endpoint.')
|
|
1273
|
-
.action(async () => {
|
|
1274
|
-
let backend;
|
|
1275
|
-
try {
|
|
1276
|
-
backend = resolveShareBackend({ requireToken: false });
|
|
1277
|
-
}
|
|
1278
|
-
catch (e) {
|
|
1279
|
-
console.log(chalk.dim(e.message));
|
|
1280
|
-
return;
|
|
1281
|
-
}
|
|
1282
|
-
if (backend.kind === 'managed') {
|
|
1283
|
-
console.log(chalk.yellow('Cloudflare Web Analytics is a BYO feature.'));
|
|
1284
|
-
console.log(chalk.dim(`You're on the managed endpoint (${backend.baseUrl}). Provision your own Cloudflare with 'artifacts share setup --analytics-token <token>', or force BYO with ARTIFACTS_SHARE_BACKEND=byo.`));
|
|
1285
|
-
return;
|
|
1286
|
-
}
|
|
1287
|
-
const cfg = readShareConfig();
|
|
1288
|
-
if (!cfg) {
|
|
1289
|
-
console.log(chalk.dim("Not configured. Run 'artifacts share setup' or 'artifacts share join'."));
|
|
1290
|
-
return;
|
|
1291
|
-
}
|
|
1292
|
-
if (!analyticsEnabled(cfg)) {
|
|
1293
|
-
console.log(chalk.yellow('Cloudflare Web Analytics is not configured.'));
|
|
1294
|
-
console.log(chalk.dim("Re-run 'artifacts share setup --analytics-token <token>'."));
|
|
1295
|
-
return;
|
|
1296
|
-
}
|
|
1297
|
-
const dashboard = cfg.domain
|
|
1298
|
-
? `https://dash.cloudflare.com/${cfg.accountId}/web-analytics/${cfg.domain}`
|
|
1299
|
-
: `https://dash.cloudflare.com/${cfg.accountId}/web-analytics`;
|
|
1300
|
-
console.log(`${chalk.bold('analytics')} ${chalk.green('enabled')}`);
|
|
1301
|
-
console.log(`${chalk.bold('token')} ${chalk.dim(cfg.analyticsToken.slice(0, 8) + '…')}`);
|
|
1302
|
-
console.log(`${chalk.bold('dashboard')} ${chalk.cyan(dashboard)}`);
|
|
1303
|
-
const user = await resolveGitHubUsername();
|
|
1304
|
-
if (user) {
|
|
1305
|
-
console.log(chalk.dim(`Per-page breakdown is available under Paths in the dashboard (filter by /${user}/).`));
|
|
1306
|
-
}
|
|
1307
|
-
});
|
|
1308
1047
|
}
|
|
1309
1048
|
/**
|
|
1310
1049
|
* Register `artifacts unshare <targets...>` as the top-level alias of
|
|
@@ -1319,175 +1058,23 @@ export function registerUnshareCommand(program) {
|
|
|
1319
1058
|
await runShareDelete(targets, opts);
|
|
1320
1059
|
});
|
|
1321
1060
|
}
|
|
1322
|
-
/**
|
|
1323
|
-
*
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
});
|
|
1329
|
-
const accountId = opts.account || acctFromBundle;
|
|
1330
|
-
if (!accountId) {
|
|
1331
|
-
throw new Error('A Cloudflare account id is required. Pass --account <id>, or set CLOUDFLARE_ACCOUNT_ID in the environment.');
|
|
1332
|
-
}
|
|
1333
|
-
const workerName = opts.worker;
|
|
1334
|
-
const bucketName = opts.bucket;
|
|
1335
|
-
const token = generateWriteToken();
|
|
1336
|
-
// Default to the product hostname: when the caller's token owns the zone this
|
|
1337
|
-
// is the platform provisioning path; when it doesn't, findZoneId returns null
|
|
1338
|
-
// and the endpoint simply stays on workers.dev.
|
|
1339
|
-
const requestedDomain = cleanHostname(opts.domain) ?? DEFAULT_SHARE_DOMAIN;
|
|
1340
|
-
const worker = renderWorkerBundle();
|
|
1341
|
-
const existing = readShareConfig();
|
|
1342
|
-
const unlimitedStorage = opts.unlimitedStorage === undefined
|
|
1343
|
-
? (existing?.accountId === accountId && existing.workerName === workerName ? existing.unlimitedStorage : undefined)
|
|
1344
|
-
: parseUnlimitedStorage(opts.unlimitedStorage);
|
|
1345
|
-
const collab = collabBindingFromFlag(opts.collabApi);
|
|
1346
|
-
const media = mediaBindingFromFlag(opts.mediaKeys);
|
|
1347
|
-
const provisionOpts = { ...(opts.request ? { request: opts.request } : {}), unlimitedStorage };
|
|
1348
|
-
await createBucket(apiToken, accountId, bucketName, provisionOpts);
|
|
1349
|
-
console.log(chalk.dim(`R2 bucket '${bucketName}' ready`));
|
|
1350
|
-
await configureBucketLifecycle(apiToken, accountId, bucketName, provisionOpts);
|
|
1351
|
-
await deployWorker(apiToken, accountId, workerName, worker, bucketName, { ...provisionOpts, ...(collab ? { collab } : {}), ...(media ? { media } : {}) });
|
|
1352
|
-
console.log(chalk.dim(`Worker '${workerName}' deployed`));
|
|
1353
|
-
if (collab)
|
|
1354
|
-
console.log(chalk.dim(`Review threads bound → ${collab.apiBase}`));
|
|
1355
|
-
if (media)
|
|
1356
|
-
console.log(chalk.dim('Media keys bound → video transcripts and summaries are on'));
|
|
1357
|
-
await setWorkerSecret(apiToken, accountId, workerName, token, provisionOpts);
|
|
1358
|
-
const subdomain = await enableWorkersDev(apiToken, accountId, workerName, provisionOpts);
|
|
1359
|
-
let baseUrl = `https://${workerName}.${subdomain}.workers.dev`;
|
|
1360
|
-
let domain;
|
|
1361
|
-
if (requestedDomain) {
|
|
1362
|
-
const zoneId = await findZoneId(apiToken, requestedDomain, provisionOpts);
|
|
1363
|
-
if (zoneId) {
|
|
1364
|
-
await addCustomDomain(apiToken, accountId, workerName, zoneId, requestedDomain, provisionOpts);
|
|
1365
|
-
baseUrl = `https://${requestedDomain}`;
|
|
1366
|
-
domain = requestedDomain;
|
|
1367
|
-
}
|
|
1368
|
-
else {
|
|
1369
|
-
console.error(chalk.yellow(`Zone for ${requestedDomain} is not visible to this token — staying on workers.dev`));
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
const phoenixIdBase = phoenixIdBaseForDeploy({ managed: opts.managed }, { baseUrl, domain });
|
|
1373
|
-
if (phoenixIdBase) {
|
|
1374
|
-
await putWorkerSecret(apiToken, accountId, workerName, WORKER_PHOENIX_ID_BASE_SECRET, phoenixIdBase, provisionOpts);
|
|
1375
|
-
console.log(chalk.dim(`Worker '${workerName}' Phoenix ID base set`));
|
|
1376
|
-
}
|
|
1377
|
-
writeShareConfig({
|
|
1378
|
-
baseUrl,
|
|
1379
|
-
accountId,
|
|
1380
|
-
workerName,
|
|
1381
|
-
bucketName,
|
|
1382
|
-
domain,
|
|
1383
|
-
analyticsToken: opts.analyticsToken,
|
|
1384
|
-
unlimitedStorage,
|
|
1385
|
-
templateHash: hashWorkerScript(worker.script),
|
|
1386
|
-
});
|
|
1387
|
-
storeWriteToken(token);
|
|
1388
|
-
console.log(chalk.green(`\nShare endpoint ready → ${chalk.bold(baseUrl)}`));
|
|
1389
|
-
console.log(chalk.dim('Publish with: ') + chalk.cyan('artifacts share <file>'));
|
|
1390
|
-
}
|
|
1391
|
-
/** Re-deploy the Worker script on an ALREADY-provisioned endpoint to match the
|
|
1392
|
-
* current `worker-template.ts`. Reuses the existing account/worker/bucket and
|
|
1393
|
-
* write token — never creates a bucket, touches routes/domains, or regenerates
|
|
1394
|
-
* the token (see `updateWorker` in `lib/share/provision.ts` for how the token —
|
|
1395
|
-
* and, on a managed endpoint, `PHOENIX_ID_BASE` — survives the re-upload).
|
|
1396
|
-
* Idempotent: no-ops the script upload when the deployed hash already matches
|
|
1397
|
-
* unless `force`; a managed endpoint still re-applies `PHOENIX_ID_BASE`. */
|
|
1061
|
+
/** What the managed Worker cannot serve without: its bucket, Phoenix sign-in,
|
|
1062
|
+
* and review threads. `share update` refuses a Worker missing any of them. */
|
|
1063
|
+
const MANAGED_WORKER_BINDINGS = ['BUCKET', 'PHOENIX_ID_BASE', 'COLLAB_API_BASE', 'COLLAB_SERVICE_TOKEN'];
|
|
1064
|
+
/** Deploy the current Worker to the managed endpoint only (worker and R2 bucket
|
|
1065
|
+
* `agents-share`, served at share.getrush.ai), inheriting every binding the
|
|
1066
|
+
* Worker already has, so the deploy needs no secret values. */
|
|
1398
1067
|
export async function runShareUpdate(opts = {}) {
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
const policyChanged = JSON.stringify(unlimitedStorage) !== JSON.stringify(cfg.unlimitedStorage);
|
|
1405
|
-
// Change detection is a pure local computation (render + sha256), so it needs
|
|
1406
|
-
// no Cloudflare credentials. The release script calls this in `--check` mode
|
|
1407
|
-
// to decide whether the release changes the Worker at all.
|
|
1408
|
-
const worker = renderWorkerBundle();
|
|
1409
|
-
const templateHash = hashWorkerScript(worker.script);
|
|
1410
|
-
const deployNeeded = opts.force === true || policyChanged || opts.collabApi !== undefined || opts.mediaKeys === true || shareTemplateStatus(cfg) !== 'current';
|
|
1411
|
-
if (opts.check) {
|
|
1412
|
-
return {
|
|
1413
|
-
updated: false,
|
|
1414
|
-
checked: true,
|
|
1415
|
-
deployNeeded,
|
|
1416
|
-
templateHash,
|
|
1417
|
-
deployedHash: cfg.templateHash,
|
|
1418
|
-
baseUrl: cfg.baseUrl,
|
|
1419
|
-
workerName: cfg.workerName,
|
|
1420
|
-
};
|
|
1421
|
-
}
|
|
1422
|
-
const { apiToken, accountId: acctFromBundle } = readCloudflareCreds(opts.bundle ?? DEFAULT_CF_BUNDLE, {
|
|
1423
|
-
apiToken: opts.token,
|
|
1424
|
-
accountId: opts.account,
|
|
1425
|
-
});
|
|
1426
|
-
const accountId = opts.account || acctFromBundle || cfg.accountId;
|
|
1427
|
-
if (!accountId) {
|
|
1428
|
-
throw new Error("Share endpoint has no Cloudflare account id — `artifacts share update` cannot call the API. Pass --account <id>, or re-run 'artifacts share join --account <id>'.");
|
|
1068
|
+
const env = opts.env ?? process.env;
|
|
1069
|
+
const apiToken = env.CLOUDFLARE_API_TOKEN?.trim();
|
|
1070
|
+
const accountId = env.CLOUDFLARE_ACCOUNT_ID?.trim();
|
|
1071
|
+
if (!apiToken || !accountId) {
|
|
1072
|
+
throw new Error('artifacts share update needs CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID in the environment.');
|
|
1429
1073
|
}
|
|
1430
|
-
|
|
1431
|
-
const phoenixIdBase = phoenixIdBaseForDeploy({ managed: opts.managed }, cfg);
|
|
1432
|
-
const collab = collabBindingFromFlag(opts.collabApi);
|
|
1433
|
-
const media = mediaBindingFromFlag(opts.mediaKeys);
|
|
1434
|
-
const provisionOpts = {
|
|
1074
|
+
await deployWorker(apiToken, accountId, DEFAULT_WORKER_NAME, renderWorkerBundle(), DEFAULT_BUCKET_NAME, {
|
|
1435
1075
|
...(opts.request ? { request: opts.request } : {}),
|
|
1436
|
-
|
|
1437
|
-
unlimitedStorage,
|
|
1438
|
-
...(phoenixIdBase !== undefined ? { phoenixIdBase } : {}),
|
|
1439
|
-
...(collab ? { collab } : {}),
|
|
1440
|
-
...(media ? { media } : {}),
|
|
1441
|
-
};
|
|
1442
|
-
const result = await updateWorker(apiToken, accountId, cfg.workerName, cfg.bucketName, worker, writeToken, cfg.templateHash, provisionOpts);
|
|
1443
|
-
if (!result.skipped || policyChanged) {
|
|
1444
|
-
writeShareConfig({ ...cfg, accountId, unlimitedStorage, templateHash: result.templateHash });
|
|
1445
|
-
}
|
|
1446
|
-
return {
|
|
1447
|
-
updated: !result.skipped || policyChanged,
|
|
1448
|
-
templateHash: result.templateHash,
|
|
1449
|
-
deployNeeded,
|
|
1450
|
-
deployedHash: cfg.templateHash,
|
|
1451
|
-
baseUrl: cfg.baseUrl,
|
|
1452
|
-
workerName: cfg.workerName,
|
|
1453
|
-
...(collab ? { collabApi: collab.apiBase } : {}),
|
|
1454
|
-
...(media ? { mediaKeys: true } : {}),
|
|
1455
|
-
};
|
|
1456
|
-
}
|
|
1457
|
-
function cleanHostname(domain) {
|
|
1458
|
-
const raw = domain?.trim().replace(/\/+$/, '');
|
|
1459
|
-
if (!raw)
|
|
1460
|
-
return undefined;
|
|
1461
|
-
try {
|
|
1462
|
-
const url = new URL(raw.includes('://') ? raw : `https://${raw}`);
|
|
1463
|
-
return url.hostname || undefined;
|
|
1464
|
-
}
|
|
1465
|
-
catch {
|
|
1466
|
-
return raw;
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
/** Join an existing share endpoint (no provisioning): persist the endpoint
|
|
1470
|
-
* details + write token. */
|
|
1471
|
-
export function runShareJoin(baseUrl, opts = {}) {
|
|
1472
|
-
const clean = baseUrl.trim().replace(/\/+$/, '');
|
|
1473
|
-
if (!clean)
|
|
1474
|
-
throw new Error('Share endpoint URL is required.');
|
|
1475
|
-
const token = opts.token?.trim() || readWriteTokenEnv();
|
|
1476
|
-
if (!token) {
|
|
1477
|
-
throw new Error('A write token is required to join. Pass --token <t>, or set ARTIFACTS_SHARE_TOKEN in the environment.');
|
|
1478
|
-
}
|
|
1479
|
-
const host = cleanHostname(clean);
|
|
1480
|
-
const domain = host && !host.endsWith('.workers.dev') ? host : undefined;
|
|
1481
|
-
writeShareConfig({
|
|
1482
|
-
baseUrl: clean,
|
|
1483
|
-
accountId: opts.account ?? '',
|
|
1484
|
-
workerName: opts.worker ?? DEFAULT_WORKER_NAME,
|
|
1485
|
-
bucketName: opts.bucket ?? DEFAULT_BUCKET_NAME,
|
|
1486
|
-
domain,
|
|
1076
|
+
requireBindings: MANAGED_WORKER_BINDINGS,
|
|
1487
1077
|
});
|
|
1488
|
-
|
|
1489
|
-
console.log(chalk.green(`Joined ${chalk.bold(clean)} — publish with `) + chalk.cyan('artifacts share <file>'));
|
|
1078
|
+
return { workerName: DEFAULT_WORKER_NAME, url: managedShareBaseUrl(), version: SHARE_WORKER_VERSION };
|
|
1490
1079
|
}
|
|
1491
|
-
/** The managed endpoint's public base, e.g. for a `join` default. */
|
|
1492
|
-
export const MANAGED_SHARE_BASE_URL = `https://${DEFAULT_SHARE_DOMAIN}`;
|
|
1493
1080
|
//# sourceMappingURL=share.js.map
|