@phnx-labs/artifacts-cli 0.9.13 → 0.11.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 +35 -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 +58 -111
- package/dist/commands/share.js +314 -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/people.d.ts +56 -0
- package/dist/lib/share/people.js +139 -0
- package/dist/lib/share/people.js.map +1 -0
- 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 +21 -63
- package/dist/lib/share/publish.js +44 -131
- package/dist/lib/share/publish.js.map +1 -1
- package/dist/lib/share/visibility.d.ts +13 -36
- 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-people-template.d.ts +1 -0
- package/dist/lib/share/worker-people-template.js +491 -0
- package/dist/lib/share/worker-people-template.js.map +1 -0
- package/dist/lib/share/worker-publish-template.d.ts +1 -1
- package/dist/lib/share/worker-publish-template.js +5 -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 +303 -52
- 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,24 @@
|
|
|
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, predictShareKey, 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';
|
|
14
|
+
import { changeSharePeople, existingPageVisibility, formatSharePeopleList, formatSharePeopleUpdate, parseEmailList, readSharePeople } from '../lib/share/people.js';
|
|
16
15
|
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';
|
|
16
|
+
import { renderWorkerBundle, SHARE_WORKER_VERSION } from '../lib/share/worker-template.js';
|
|
17
|
+
import { extractShareHttpError, fetchWorkerVersion, formatShareHttpErrorDetail, workerBehindError } from '../lib/share/http-error.js';
|
|
18
|
+
import { managedShareBaseUrl, resolveShareBackend, SIGNED_OUT_MESSAGE } from '../lib/share/backend.js';
|
|
19
|
+
import { COMMENT_POLICY_FLAGS, commentPolicyFromFlag, explicitVisibility, resolveVisibility } from '../lib/share/visibility.js';
|
|
20
|
+
import { readSession, refreshSessionAvatar } from '../lib/identity/index.js';
|
|
21
|
+
import { authLogin } from './auth.js';
|
|
24
22
|
export function formatSharePublishResult(result, json = false) {
|
|
25
23
|
if (json)
|
|
26
24
|
return JSON.stringify(result, null, 2);
|
|
@@ -51,51 +49,42 @@ export function formatSharePublishResult(result, json = false) {
|
|
|
51
49
|
else {
|
|
52
50
|
lines.push(chalk.dim(` visibility: ${visibility}`));
|
|
53
51
|
}
|
|
52
|
+
if (result.people) {
|
|
53
|
+
lines.push(chalk.dim(` shared with ${result.people.people.join(', ') || 'nobody'}`));
|
|
54
|
+
if (result.people.notified.length)
|
|
55
|
+
lines.push(chalk.dim(` emailed a link to ${result.people.notified.join(', ')}`));
|
|
56
|
+
if (result.people.notify_error)
|
|
57
|
+
lines.push(chalk.yellow(' the invitation email could not be sent; send them the link yourself'));
|
|
58
|
+
}
|
|
54
59
|
return lines.join('\n');
|
|
55
60
|
}
|
|
61
|
+
/** `share status`'s line for the release the endpoint's Worker was built from,
|
|
62
|
+
* read from its `/__version`. */
|
|
63
|
+
export async function workerStatusLine(baseUrl, get) {
|
|
64
|
+
const deployed = await fetchWorkerVersion(baseUrl, get);
|
|
65
|
+
const label = deployed === SHARE_WORKER_VERSION
|
|
66
|
+
? chalk.green(`${deployed} (same as this CLI)`)
|
|
67
|
+
: deployed
|
|
68
|
+
? chalk.yellow(`${deployed} (this CLI is ${SHARE_WORKER_VERSION})`)
|
|
69
|
+
: chalk.dim('unknown — no /__version');
|
|
70
|
+
return `${chalk.bold('worker')} ${label}`;
|
|
71
|
+
}
|
|
56
72
|
/** The stderr warning for a page that published but could not be registered
|
|
57
73
|
* for review threads. The page itself is live; republishing retries. */
|
|
58
74
|
export function collabRegistrationWarning(collab) {
|
|
59
75
|
return `Published, but review threads are unavailable on this page${collab.error ? ` (${collab.error})` : ''}. Republish to retry.`;
|
|
60
76
|
}
|
|
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
77
|
/**
|
|
71
78
|
* The file that actually gets uploaded for `artifacts share <file>`.
|
|
72
79
|
*
|
|
73
80
|
* 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.
|
|
81
|
+
* rendering, so `artifacts share plan.md` must not upload raw Markdown.
|
|
83
82
|
*/
|
|
84
83
|
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
84
|
if (!/\.md$/i.test(file))
|
|
96
85
|
return file;
|
|
97
86
|
const out = join(process.cwd(), '.artifacts', `${slugify(file.replace(/.*\//, '').replace(/\.[^.]+$/, '')) || 'artifact'}.html`);
|
|
98
|
-
const result = await compileArtifact(file, out
|
|
87
|
+
const result = await compileArtifact(file, out);
|
|
99
88
|
const errors = result.diagnostics.filter((d) => d.level === 'error');
|
|
100
89
|
if (errors.length) {
|
|
101
90
|
throw new Error(`Artifact did not compile cleanly:\n${errors.map((e) => `- ${e.message}`).join('\n')}`);
|
|
@@ -121,14 +110,8 @@ export async function runShareEdit(target, opts) {
|
|
|
121
110
|
if (hits.length > 0)
|
|
122
111
|
throw new Error(formatSensitiveContentError(hits));
|
|
123
112
|
}
|
|
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 });
|
|
113
|
+
const backend = resolveShareBackend({ session: opts.session });
|
|
114
|
+
const { key } = resolveDeleteTarget(target, backend.namespace);
|
|
132
115
|
const res = await (opts.fetchEdit ?? fetch)(`${backend.baseUrl.replace(/\/+$/, '')}/${key}`, {
|
|
133
116
|
method: 'PATCH',
|
|
134
117
|
headers: { authorization: `Bearer ${backend.token}`, 'content-type': 'application/json' },
|
|
@@ -148,22 +131,18 @@ export async function runShareEdit(target, opts) {
|
|
|
148
131
|
throw new Error(`Share metadata edit failed (${res.status}): ${detail || 'unknown error'}`);
|
|
149
132
|
}
|
|
150
133
|
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.
|
|
134
|
+
// A Worker that predates the visibility edit ignores the `visibility` field
|
|
135
|
+
// and 200s without echoing it back: a silent success that changed nothing.
|
|
155
136
|
if (opts.visibility !== undefined && result.visibility === undefined) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
137
|
+
const get = async (url) => {
|
|
138
|
+
const res = await (opts.fetchEdit ?? fetch)(url);
|
|
139
|
+
return { status: res.status, body: await res.text() };
|
|
140
|
+
};
|
|
141
|
+
throw await workerBehindError(backend.baseUrl, 'in-place visibility changes', get);
|
|
159
142
|
}
|
|
160
143
|
return result;
|
|
161
144
|
}
|
|
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).';
|
|
145
|
+
const NOT_A_LISTING = 'The share Worker did not answer with a share listing.';
|
|
167
146
|
async function defaultListingFetch(url, headers) {
|
|
168
147
|
const res = await fetch(url, { headers: { accept: 'application/json', ...(headers || {}) } });
|
|
169
148
|
return { status: res.status, contentType: res.headers.get('content-type') ?? '', body: await res.text() };
|
|
@@ -180,21 +159,21 @@ function parseMetaField(raw) {
|
|
|
180
159
|
}
|
|
181
160
|
return out;
|
|
182
161
|
}
|
|
183
|
-
/** Parse the Worker's listing JSON into a validated result, failing loud
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
162
|
+
/** Parse the Worker's listing JSON into a validated result, failing loud on any
|
|
163
|
+
* body that isn't the expected shape — an old Worker serves the HTML gallery for
|
|
164
|
+
* a non-empty namespace, which must not be silently accepted as "you have
|
|
165
|
+
* published nothing". */
|
|
187
166
|
export function parseShareListing(user, body) {
|
|
188
167
|
let data;
|
|
189
168
|
try {
|
|
190
169
|
data = JSON.parse(body);
|
|
191
170
|
}
|
|
192
171
|
catch {
|
|
193
|
-
throw new Error(
|
|
172
|
+
throw new Error(NOT_A_LISTING);
|
|
194
173
|
}
|
|
195
174
|
const objectsRaw = data?.objects;
|
|
196
175
|
if (!data || typeof data !== 'object' || !Array.isArray(objectsRaw)) {
|
|
197
|
-
throw new Error(
|
|
176
|
+
throw new Error(NOT_A_LISTING);
|
|
198
177
|
}
|
|
199
178
|
const objects = objectsRaw.map((o) => {
|
|
200
179
|
const item = o;
|
|
@@ -222,82 +201,38 @@ export function parseShareListing(user, body) {
|
|
|
222
201
|
});
|
|
223
202
|
return { user, count: objects.length, objects };
|
|
224
203
|
}
|
|
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
204
|
/** 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. */
|
|
205
|
+
* Worker's `?format=json` route. A 404 is an empty namespace; a non-JSON 200 (the
|
|
206
|
+
* HTML gallery of a Worker without the route) fails loud with the Worker's version. */
|
|
237
207
|
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);
|
|
208
|
+
const backend = opts.backend ?? resolveShareBackend({ session: opts.phoenixSession });
|
|
209
|
+
const user = backend.namespace;
|
|
259
210
|
const scope = opts.scope ?? 'public';
|
|
260
211
|
const includeHidden = scope !== 'public';
|
|
261
212
|
const query = new URLSearchParams({ format: 'json' });
|
|
262
213
|
if (includeHidden)
|
|
263
214
|
query.set('scope', 'mine');
|
|
264
215
|
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
|
-
}
|
|
216
|
+
const listingHeaders = includeHidden ? { authorization: `Bearer ${backend.token}` } : {};
|
|
272
217
|
const fetchListing = opts.fetchListing ?? defaultListingFetch;
|
|
273
218
|
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
|
-
}
|
|
219
|
+
// The listing route answers only a namespace that holds objects, so a 404 is
|
|
220
|
+
// a namespace with nothing published.
|
|
221
|
+
if (res.status === 404)
|
|
222
|
+
return { user, count: 0, objects: [] };
|
|
287
223
|
if (res.status !== 200) {
|
|
288
224
|
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
|
|
225
|
+
throw new Error(`Listing failed (${res.status}) for ${listUrl}${detail}. Check the endpoint is reachable, or run 'artifacts auth login'.`);
|
|
290
226
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
throw
|
|
227
|
+
let parsed;
|
|
228
|
+
try {
|
|
229
|
+
if (!/application\/json/i.test(res.contentType))
|
|
230
|
+
throw new Error(NOT_A_LISTING);
|
|
231
|
+
parsed = parseShareListing(user, res.body);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
throw await workerBehindError(backend.baseUrl, 'the share listing (`?format=json`)', fetchListing);
|
|
299
235
|
}
|
|
300
|
-
const parsed = parseShareListing(user, res.body);
|
|
301
236
|
return applyShareListFilters(parsed, {
|
|
302
237
|
agent: opts.agent,
|
|
303
238
|
session: opts.session,
|
|
@@ -370,19 +305,18 @@ export function formatShareList(result, json = false) {
|
|
|
370
305
|
});
|
|
371
306
|
return [header, ...rows].join('\n');
|
|
372
307
|
}
|
|
373
|
-
/** Parse the Worker's `?revisions=json` payload, failing loud
|
|
374
|
-
* outdated-template hint as {@link parseShareListing}) on an unexpected shape. */
|
|
308
|
+
/** Parse the Worker's `?revisions=json` payload, failing loud on an unexpected shape. */
|
|
375
309
|
export function parseShareRevisions(key, body) {
|
|
376
310
|
let data;
|
|
377
311
|
try {
|
|
378
312
|
data = JSON.parse(body);
|
|
379
313
|
}
|
|
380
314
|
catch {
|
|
381
|
-
throw new Error(
|
|
315
|
+
throw new Error(NOT_A_LISTING);
|
|
382
316
|
}
|
|
383
317
|
const revisionsRaw = data?.revisions;
|
|
384
318
|
if (!data || typeof data !== 'object' || !Array.isArray(revisionsRaw)) {
|
|
385
|
-
throw new Error(
|
|
319
|
+
throw new Error(NOT_A_LISTING);
|
|
386
320
|
}
|
|
387
321
|
const revisions = revisionsRaw.map((o) => {
|
|
388
322
|
const item = o;
|
|
@@ -408,56 +342,31 @@ export function parseShareRevisions(key, body) {
|
|
|
408
342
|
* or a bare slug resolved against the caller's own namespace) — reuses
|
|
409
343
|
* {@link resolveDeleteTarget} rather than re-deriving the key. */
|
|
410
344
|
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 });
|
|
345
|
+
const backend = resolveShareBackend({ session: opts.session });
|
|
346
|
+
const { key } = resolveDeleteTarget(target, backend.namespace);
|
|
429
347
|
const revUrl = `${backend.baseUrl.replace(/\/+$/, '')}/${key}?revisions=json`;
|
|
430
348
|
const fetchListing = opts.fetchListing ?? defaultListingFetch;
|
|
431
349
|
const res = await fetchListing(revUrl);
|
|
432
350
|
if (res.status !== 200) {
|
|
433
351
|
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
|
|
352
|
+
throw new Error(`Revisions lookup failed (${res.status}) for ${revUrl}${detail}. Check the endpoint is reachable, or run 'artifacts auth login'.`);
|
|
435
353
|
}
|
|
436
|
-
|
|
437
|
-
if (
|
|
438
|
-
throw new Error(
|
|
439
|
-
|
|
440
|
-
|
|
354
|
+
try {
|
|
355
|
+
if (!/application\/json/i.test(res.contentType))
|
|
356
|
+
throw new Error(NOT_A_LISTING);
|
|
357
|
+
return parseShareRevisions(key, res.body);
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
throw await workerBehindError(backend.baseUrl, 'revision history (`?revisions=json`)', fetchListing);
|
|
441
361
|
}
|
|
442
|
-
return parseShareRevisions(key, res.body);
|
|
443
362
|
}
|
|
444
363
|
/** Mint a one-time login ticket for the signed-in owner and build the URL that
|
|
445
364
|
* 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. */
|
|
365
|
+
* control is live in the browser. */
|
|
448
366
|
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
|
-
}
|
|
367
|
+
const backend = resolveShareBackend({ session: opts.session });
|
|
459
368
|
const baseUrl = backend.baseUrl.replace(/\/+$/, '');
|
|
460
|
-
const { key } =
|
|
369
|
+
const { key } = resolveDeleteTarget(target, backend.namespace);
|
|
461
370
|
const url = `${baseUrl}/${key}`;
|
|
462
371
|
const doFetch = opts.fetchTicket ??
|
|
463
372
|
(async (u, bearer) => {
|
|
@@ -465,9 +374,11 @@ export async function runShareOpen(target, opts = {}) {
|
|
|
465
374
|
return { status: res.status, body: await res.text() };
|
|
466
375
|
});
|
|
467
376
|
const res = await doFetch(`${baseUrl}/__ticket`, backend.token);
|
|
377
|
+
if (res.status === 404)
|
|
378
|
+
throw await workerBehindError(baseUrl, 'owner login tickets (`/__ticket`)');
|
|
468
379
|
if (res.status !== 200) {
|
|
469
|
-
|
|
470
|
-
|
|
380
|
+
const detail = formatShareHttpErrorDetail(extractShareHttpError({ status: res.status, body: res.body }));
|
|
381
|
+
throw new Error(`Could not mint a login ticket (${res.status}) from ${baseUrl}/__ticket${detail}.`);
|
|
471
382
|
}
|
|
472
383
|
let ticket;
|
|
473
384
|
try {
|
|
@@ -530,6 +441,12 @@ function formatShareVisibilityResult(result, requested) {
|
|
|
530
441
|
chalk.dim(' body unchanged — no revision created'),
|
|
531
442
|
].join('\n');
|
|
532
443
|
}
|
|
444
|
+
/** `--for-user` once named a GitHub namespace for bare-slug targets. Every
|
|
445
|
+
* target now resolves against the signed-in handle; the flag is accepted and
|
|
446
|
+
* ignored so existing scripts keep parsing. */
|
|
447
|
+
function ignoredForUserOption() {
|
|
448
|
+
return new Option('--for-user <user>').hideHelp();
|
|
449
|
+
}
|
|
533
450
|
/** Shared handler for `artifacts share delete <targets...>` and the top-level
|
|
534
451
|
* `artifacts unshare <targets...>` alias. Deletes each target independently and
|
|
535
452
|
* continues past a failed one (rm-style), reporting all results and exiting
|
|
@@ -546,7 +463,6 @@ export async function runShareDelete(targets, opts, deleteFn = deleteShare) {
|
|
|
546
463
|
keepCover: opts.keepCover === true,
|
|
547
464
|
keepRevisions: opts.keepRevisions === true,
|
|
548
465
|
ifExists: opts.ifExists === true,
|
|
549
|
-
githubUser: opts.forUser,
|
|
550
466
|
});
|
|
551
467
|
results.push({ target, result });
|
|
552
468
|
if (!opts.deleteJson)
|
|
@@ -573,14 +489,11 @@ function registerShareDeleteOptions(cmd) {
|
|
|
573
489
|
.option('--keep-cover', 'leave the sibling <slug>.png OG cover in place (default: delete it too)')
|
|
574
490
|
.option('--keep-revisions', 'leave retained revisions (<slug>/rev-*) in place (default: delete them too)')
|
|
575
491
|
.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)')
|
|
492
|
+
.addOption(ignoredForUserOption())
|
|
493
|
+
// Named --delete-json, not --json: `share <file>` (the parent of the nested
|
|
494
|
+
// `share delete`) already owns --json, and commander resolves an option's
|
|
495
|
+
// long name against the WHOLE ancestor chain — a same-named child option is
|
|
496
|
+
// silently dropped at parse time even when it parses alone.
|
|
584
497
|
.option('--delete-json', 'emit machine-readable results');
|
|
585
498
|
}
|
|
586
499
|
const SHARE_DELETE_HELP = `
|
|
@@ -609,6 +522,114 @@ Notes:
|
|
|
609
522
|
|
|
610
523
|
artifacts share delete === artifacts unshare (same command, different name).
|
|
611
524
|
`;
|
|
525
|
+
/**
|
|
526
|
+
* Signed out: an interactive terminal runs the `artifacts auth login` device
|
|
527
|
+
* flow inline (prompts on stderr, so `--json` stdout stays clean); anything
|
|
528
|
+
* else fails with the command to run.
|
|
529
|
+
*/
|
|
530
|
+
async function ensureSignedIn() {
|
|
531
|
+
if (readSession())
|
|
532
|
+
return;
|
|
533
|
+
if (!(process.stdin.isTTY && process.stdout.isTTY))
|
|
534
|
+
throw new Error(SIGNED_OUT_MESSAGE);
|
|
535
|
+
console.error(chalk.dim('Not signed in. Starting `artifacts auth login`…'));
|
|
536
|
+
await authLogin(console.error);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* The one publish path behind `artifacts share <file>` and
|
|
540
|
+
* `artifacts render --publish`. Throws on failure; callers print the result.
|
|
541
|
+
*/
|
|
542
|
+
export async function runSharePublish(file, opts = {}) {
|
|
543
|
+
if (!existsSync(file))
|
|
544
|
+
throw new Error(`No such file: ${file}`);
|
|
545
|
+
const meta = parseMetaEntries(opts.meta ?? []);
|
|
546
|
+
const people = parseEmailList(opts.with ?? []);
|
|
547
|
+
const visibilityFlags = {
|
|
548
|
+
visibility: opts.visibility,
|
|
549
|
+
unlisted: opts.unlisted === true || opts.private === true,
|
|
550
|
+
protected: opts.protected === true,
|
|
551
|
+
};
|
|
552
|
+
if (people.length && explicitVisibility(visibilityFlags) === 'private')
|
|
553
|
+
throw new Error(WITH_NEEDS_SIGN_IN);
|
|
554
|
+
await ensureSignedIn();
|
|
555
|
+
const uploadPath = await resolveUploadPath(file);
|
|
556
|
+
// --with keeps an existing page's visibility; a new page is yours and theirs
|
|
557
|
+
// alone (me) unless you say otherwise.
|
|
558
|
+
let visibility = resolveVisibility(visibilityFlags);
|
|
559
|
+
if (people.length && !explicitVisibility(visibilityFlags)) {
|
|
560
|
+
const key = predictShareKey(uploadPath, resolveShareBackend().namespace, { slug: opts.slug, handle: opts.handle });
|
|
561
|
+
visibility = (await existingPageVisibility(key)) ?? 'me';
|
|
562
|
+
if (visibility === 'private')
|
|
563
|
+
throw new Error(WITH_NEEDS_SIGN_IN);
|
|
564
|
+
}
|
|
565
|
+
if (people.length && (visibility === 'public' || visibility === 'unlisted') && !opts.json) {
|
|
566
|
+
console.error(chalk.dim(`This page is ${visibility}: anyone with the link can open it, so the people list grants nothing extra.`));
|
|
567
|
+
}
|
|
568
|
+
// unlisted (incl. its --private alias) is obscurity, not read-auth — warn
|
|
569
|
+
// loudly before the publish so a "private" link is never mistaken for a
|
|
570
|
+
// gated one. Skipped for --json so machine output stays clean.
|
|
571
|
+
if (visibility === 'unlisted' && !opts.json) {
|
|
572
|
+
console.error(chalk.yellow(`⚠ ${unlistedNotPrivateWarning()}`));
|
|
573
|
+
}
|
|
574
|
+
// Fill the session's hosted avatar (one /auth/me call, no-op when already
|
|
575
|
+
// known) so the attribution bar can show the OAuth profile image.
|
|
576
|
+
await refreshSessionAvatar();
|
|
577
|
+
let progressLineOpen = false;
|
|
578
|
+
const onUploadProgress = process.stderr.isTTY === true && !opts.json
|
|
579
|
+
? (uploadedBytes, totalBytes) => {
|
|
580
|
+
progressLineOpen = uploadedBytes < totalBytes;
|
|
581
|
+
const percent = totalBytes > 0 ? Math.floor((uploadedBytes / totalBytes) * 100) : 100;
|
|
582
|
+
process.stderr.write(`\r${chalk.dim(`Uploading ${formatBytes(uploadedBytes)} / ${formatBytes(totalBytes)} (${percent}%)`)}`);
|
|
583
|
+
if (!progressLineOpen)
|
|
584
|
+
process.stderr.write('\n');
|
|
585
|
+
}
|
|
586
|
+
: undefined;
|
|
587
|
+
let published;
|
|
588
|
+
try {
|
|
589
|
+
published = await publishFile(uploadPath, {
|
|
590
|
+
slug: opts.slug,
|
|
591
|
+
handle: opts.handle,
|
|
592
|
+
expire: opts.expire,
|
|
593
|
+
visibility,
|
|
594
|
+
...(opts.comments ? { comments: commentPolicyFromFlag(opts.comments) } : {}),
|
|
595
|
+
force: opts.force,
|
|
596
|
+
// A capability URL is only as private as its obscurity, and a gallery
|
|
597
|
+
// OG cover is a second world-readable object under a derivable key.
|
|
598
|
+
// Public pages get a cover; anything hidden does not, unless the author
|
|
599
|
+
// has already opted out with --no-cover (in which case honour that).
|
|
600
|
+
cover: opts.cover === false ? false : visibility === 'public',
|
|
601
|
+
qr: opts.qr,
|
|
602
|
+
label: opts.label ?? opts.title,
|
|
603
|
+
meta,
|
|
604
|
+
noRevision: opts.revision === false,
|
|
605
|
+
onUploadProgress,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
finally {
|
|
609
|
+
if (progressLineOpen)
|
|
610
|
+
process.stderr.write('\n');
|
|
611
|
+
}
|
|
612
|
+
if (!people.length)
|
|
613
|
+
return published;
|
|
614
|
+
try {
|
|
615
|
+
return { ...published, people: await changeSharePeople(published.url, { add: people, notify: opts.notify !== false }) };
|
|
616
|
+
}
|
|
617
|
+
catch (e) {
|
|
618
|
+
throw new Error(`Published ${published.url}, but sharing it with people failed: ${e.message} Retry with 'artifacts share people ${published.url} --add ${people.join(',')}'.`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const WITH_NEEDS_SIGN_IN = '--with needs a page people sign in to (--visibility me or org); a --protected link is opened by its key.';
|
|
622
|
+
/** `artifacts share people`: the printed result of reading or changing a page's people. */
|
|
623
|
+
export async function runSharePeople(target, opts, peopleOpts = {}) {
|
|
624
|
+
const add = parseEmailList(opts.add ?? []);
|
|
625
|
+
const remove = parseEmailList(opts.remove ?? []);
|
|
626
|
+
if (!add.length && !remove.length) {
|
|
627
|
+
const list = await readSharePeople(target, peopleOpts);
|
|
628
|
+
return opts.peopleJson ? JSON.stringify(list, null, 2) : formatSharePeopleList(target, list);
|
|
629
|
+
}
|
|
630
|
+
const update = await changeSharePeople(target, { add, remove, notify: opts.notify !== false }, peopleOpts);
|
|
631
|
+
return opts.peopleJson ? JSON.stringify(update, null, 2) : formatSharePeopleUpdate(update);
|
|
632
|
+
}
|
|
612
633
|
/**
|
|
613
634
|
* Register the `share` subtree on the root program, plus the top-level
|
|
614
635
|
* `artifacts unshare` alias (see {@link registerUnshareCommand}).
|
|
@@ -620,113 +641,51 @@ export function registerShareCommands(program) {
|
|
|
620
641
|
// `list --meta`). Keep option ownership positional within this subtree so
|
|
621
642
|
// Commander does not silently resolve those flags to the parent publisher.
|
|
622
643
|
.enablePositionalOptions()
|
|
623
|
-
.description('Publish an artifact to a shareable link
|
|
624
|
-
.argument('[file]', 'file to publish (Markdown, HTML, any static asset
|
|
644
|
+
.description('Publish an artifact to a shareable link on share.getrush.ai (signs you in first when needed).')
|
|
645
|
+
.argument('[file]', 'file to publish (Markdown, HTML, or any static asset)')
|
|
625
646
|
.option('--slug <slug>', 'URL slug override (default: stable slug of the artifact title, then filename)')
|
|
626
|
-
|
|
627
|
-
.
|
|
647
|
+
// Accepted and ignored for one release so scripts that still pass it keep parsing.
|
|
648
|
+
.addOption(new Option('--github-user <user>').hideHelp())
|
|
649
|
+
.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
650
|
.option('--expire <spec>', "auto-expire (default 30d). e.g. 12h, 30d, 2026-08-01, or 'never'")
|
|
629
651
|
.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
652
|
.choices([...PUBLISH_VISIBILITY_LEVELS]))
|
|
631
653
|
.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
654
|
.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
|
|
655
|
+
.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
656
|
.choices([...COMMENT_POLICY_FLAGS]))
|
|
635
657
|
.addOption(new Option('--private', 'alias of --unlisted (obscurity, NOT authentication — for real read-auth use --protected)').hideHelp())
|
|
636
658
|
.option('--force', 'publish even when the file contains emails or credential-shaped strings')
|
|
637
659
|
.option('--no-cover', 'skip the OG preview image (public HTML pages get one by default)')
|
|
638
|
-
.
|
|
660
|
+
.addOption(new Option('--no-analytics').hideHelp())
|
|
639
661
|
.option('--no-qr', 'skip the footer QR of the share URL (embedded in published HTML pages by default)')
|
|
640
662
|
.option('--label <text>', 'human display title, shown in the gallery and `share list` (default: derived from the HTML <title>, frontmatter title, or filename)')
|
|
641
663
|
.option('--title <text>', 'alias of --label')
|
|
642
664
|
.option('--meta <key=value>', 'structured metadata (repeatable), e.g. --meta kind=plan --meta ticket=PHNX-3992. Reserved (set automatically, not settable): agent, session, host, repo, date, label', (val, prev) => [...prev, val], [])
|
|
643
665
|
.option('--no-revision', "overwrite an existing slug in place — skip keeping the prior version as a <slug>/rev-<ts> backup (default: keep it, see 'artifacts share revisions')")
|
|
666
|
+
.option('--with <emails>', 'share with these people by email, comma-separated or repeated; they sign in with Google to open it, no Rush account needed. Without --visibility an existing page keeps its visibility and a new one is me (you and them)', (val, prev) => [...prev, val], [])
|
|
667
|
+
.option('--no-notify', 'with --with, do not email the added people a link')
|
|
644
668
|
.option('--json', 'emit the machine-readable publish result')
|
|
645
669
|
.action(async (file, opts) => {
|
|
646
670
|
if (!file) {
|
|
647
671
|
shareCmd.help();
|
|
648
672
|
return;
|
|
649
673
|
}
|
|
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
674
|
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
|
-
});
|
|
675
|
+
const result = await runSharePublish(file, opts);
|
|
713
676
|
console.log(formatSharePublishResult(result, Boolean(opts.json)));
|
|
714
677
|
if (result.collab && !result.collab.registered && !opts.json) {
|
|
715
678
|
console.error(chalk.yellow(`⚠ ${collabRegistrationWarning(result.collab)}`));
|
|
716
679
|
}
|
|
717
680
|
}
|
|
718
681
|
catch (e) {
|
|
719
|
-
if (progressLineOpen)
|
|
720
|
-
process.stderr.write('\n');
|
|
721
682
|
console.error(chalk.red(e.message));
|
|
722
683
|
process.exitCode = 1;
|
|
723
684
|
}
|
|
724
685
|
})
|
|
725
686
|
.addHelpText('after', `
|
|
726
687
|
Examples:
|
|
727
|
-
# Signed in? Just publish — no Cloudflare setup (managed endpoint).
|
|
728
688
|
# The default is public: listed in your gallery with an OG preview card.
|
|
729
|
-
$ artifacts auth login
|
|
730
689
|
$ artifacts share ./out/plan.html
|
|
731
690
|
|
|
732
691
|
# Markdown is rendered first, then published
|
|
@@ -736,7 +695,7 @@ Examples:
|
|
|
736
695
|
$ artifacts share ./out/plan.html --visibility me
|
|
737
696
|
$ artifacts share ./out/plan.html --visibility org
|
|
738
697
|
|
|
739
|
-
# Large
|
|
698
|
+
# Large recordings stream in resumable 50 MiB parts
|
|
740
699
|
$ artifacts share recording.mp4 --visibility org --expire never
|
|
741
700
|
|
|
742
701
|
# Hide from the gallery (direct URL still works, noindex, no card), expire sooner
|
|
@@ -749,23 +708,21 @@ Examples:
|
|
|
749
708
|
$ artifacts share plan.md --visibility org --comments audience
|
|
750
709
|
$ artifacts share plan.md --comments signed-in
|
|
751
710
|
|
|
711
|
+
# Only you and two people (one outside your company) can open it; both get an email
|
|
712
|
+
$ artifacts share plan.md --with ben@acme.com,lee@partner.io
|
|
713
|
+
$ artifacts share demo.mp4 --visibility org --with lee@partner.io --no-notify
|
|
714
|
+
|
|
752
715
|
# Permanent link, explicit slug, human title + structured metadata
|
|
753
716
|
$ artifacts share ./out/landing.html --expire never --slug q3-landing
|
|
754
717
|
$ artifacts share ./out/plan.html --label "Q3 fleet plan" --meta kind=plan
|
|
755
718
|
${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
719
|
|
|
763
720
|
Notes:
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
721
|
+
Pages publish to share.getrush.ai/<handle>/… with your Phoenix session. Signed
|
|
722
|
+
out, an interactive terminal runs 'artifacts auth login' first; a script or
|
|
723
|
+
agent run exits non-zero and names that command. The handle is the local-part
|
|
724
|
+
of the signed-in email; --handle publishes under an alternate public namespace
|
|
725
|
+
instead (first-writer-claimed like the derived one).
|
|
769
726
|
|
|
770
727
|
The default slug is derived deterministically from the HTML <title> or Markdown
|
|
771
728
|
frontmatter title, then the filename, so republishing the same title updates the
|
|
@@ -781,7 +738,7 @@ Notes:
|
|
|
781
738
|
is the real read-auth — the URL carries a secret ?k= key and GET returns 404
|
|
782
739
|
without it.
|
|
783
740
|
|
|
784
|
-
Eligible
|
|
741
|
+
Eligible video/* publishes over 20 MiB use resumable multipart upload
|
|
785
742
|
for --visibility me or org. Re-run the same command after an interruption to
|
|
786
743
|
continue from the completed parts saved under ~/.artifacts/uploads/. Progress
|
|
787
744
|
is written only to an interactive terminal.
|
|
@@ -813,21 +770,21 @@ Notes:
|
|
|
813
770
|
// `artifacts share visibility <target> <level>` — change an already-published
|
|
814
771
|
// page's visibility in place. It reuses the delete target parser and the same
|
|
815
772
|
// 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
|
-
//
|
|
773
|
+
// re-stamps the stored object rather than re-publishing. --visibility-json
|
|
774
|
+
// (not --json): the parent `share <file>` already owns that long name, and
|
|
775
|
+
// commander resolves a child option's long name against the whole ancestor
|
|
776
|
+
// chain, silently dropping a same-named child.
|
|
820
777
|
const shareVisibilityCmd = shareCmd
|
|
821
778
|
.command('visibility')
|
|
822
779
|
.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
780
|
.addArgument(new Argument('<target>', 'the published page: a full URL, <user>/<slug>, or a bare slug in your namespace'))
|
|
824
781
|
.addArgument(new Argument('<level>', 'new visibility').choices([...SHARE_VISIBILITY_LEVELS]))
|
|
825
|
-
.
|
|
782
|
+
.addOption(ignoredForUserOption())
|
|
826
783
|
.option('--visibility-json', 'emit a machine-readable result')
|
|
827
784
|
.action(async (target, level, opts) => {
|
|
828
785
|
try {
|
|
829
786
|
const visibility = level;
|
|
830
|
-
const result = await runShareEdit(target, { visibility
|
|
787
|
+
const result = await runShareEdit(target, { visibility });
|
|
831
788
|
if (opts.visibilityJson) {
|
|
832
789
|
console.log(JSON.stringify(result, null, 2));
|
|
833
790
|
return;
|
|
@@ -857,17 +814,56 @@ Notes:
|
|
|
857
814
|
refused on a public-inbox email domain (gmail.com, outlook.com, …). Changing to
|
|
858
815
|
'private' is not possible in place — token-gating needs a fresh viewer key,
|
|
859
816
|
which only a re-publish with --protected mints.
|
|
817
|
+
`);
|
|
818
|
+
// `artifacts share people <target>` (PHNX-4394): the people a page you own is
|
|
819
|
+
// shared with by email. --people-json, not --json, for the reason
|
|
820
|
+
// --visibility-json gives above.
|
|
821
|
+
shareCmd
|
|
822
|
+
.command('people')
|
|
823
|
+
.description('Show or change who a page you own is shared with by email. Listed people open it by signing in with Google; they need no Rush account.')
|
|
824
|
+
.addArgument(new Argument('<target>', 'the published page: a full URL, <user>/<slug>, or a bare slug in your namespace'))
|
|
825
|
+
.option('--add <emails>', 'addresses to add, comma-separated or repeated', (val, prev) => [...prev, val], [])
|
|
826
|
+
.option('--remove <emails>', 'addresses to remove, comma-separated or repeated', (val, prev) => [...prev, val], [])
|
|
827
|
+
.option('--no-notify', 'do not email the added people a link')
|
|
828
|
+
.option('--people-json', 'emit a machine-readable result')
|
|
829
|
+
.action(async (target, opts, command) => {
|
|
830
|
+
try {
|
|
831
|
+
// Commander hands --no-notify to the parent `share <file>`, which owns
|
|
832
|
+
// the same flag; either one turns the email off.
|
|
833
|
+
const notify = opts.notify !== false && command.parent?.opts().notify !== false;
|
|
834
|
+
console.log(await runSharePeople(target, { ...opts, notify }));
|
|
835
|
+
}
|
|
836
|
+
catch (e) {
|
|
837
|
+
console.error(chalk.red(e.message));
|
|
838
|
+
process.exitCode = 1;
|
|
839
|
+
}
|
|
840
|
+
})
|
|
841
|
+
.addHelpText('after', `
|
|
842
|
+
Examples:
|
|
843
|
+
$ artifacts share people octocat/q3-plan
|
|
844
|
+
$ artifacts share people octocat/q3-plan --add ben@acme.com,lee@partner.io
|
|
845
|
+
$ artifacts share people https://share.getrush.ai/octocat/q3-plan --remove lee@partner.io
|
|
846
|
+
$ artifacts share people q3-plan --add ben@acme.com --no-notify --people-json
|
|
847
|
+
|
|
848
|
+
Notes:
|
|
849
|
+
The people add to the page's audience: a me page opens for you and them, an
|
|
850
|
+
org page for your email domain and them. On a public or unlisted page anyone
|
|
851
|
+
with the link can already open it. A protected (--protected) link takes no
|
|
852
|
+
people. Removing someone takes effect at once for the page, its media, its
|
|
853
|
+
transcript and its cover. Only the addresses a change adds are emailed, and a
|
|
854
|
+
failed email still saves the list. At most 50 people per page and 20 newly
|
|
855
|
+
added addresses an hour.
|
|
860
856
|
`);
|
|
861
857
|
const shareOpenCmd = shareCmd
|
|
862
858
|
.command('open')
|
|
863
859
|
.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
860
|
.addArgument(new Argument('<target>', 'the published page: a full URL, <user>/<slug>, or a bare slug in your namespace'))
|
|
865
|
-
.
|
|
861
|
+
.addOption(ignoredForUserOption())
|
|
866
862
|
.option('--no-open', 'print the owner URL instead of opening a browser')
|
|
867
863
|
.option('--open-json', 'emit a machine-readable result (includes the ticketed owner URL)')
|
|
868
864
|
.action(async (target, opts) => {
|
|
869
865
|
try {
|
|
870
|
-
const result = await runShareOpen(target
|
|
866
|
+
const result = await runShareOpen(target);
|
|
871
867
|
if (opts.openJson) {
|
|
872
868
|
console.log(JSON.stringify(result, null, 2));
|
|
873
869
|
return;
|
|
@@ -898,91 +894,17 @@ Notes:
|
|
|
898
894
|
share Worker) and opens the page with it, so the chip becomes a dropdown you
|
|
899
895
|
can switch in place.
|
|
900
896
|
|
|
901
|
-
Managed (Phoenix) endpoints only — run 'artifacts auth login' first.
|
|
902
|
-
mint 501s/404s, the Worker predates the feature: run 'artifacts share update'.
|
|
897
|
+
Managed (Phoenix) endpoints only — run 'artifacts auth login' first.
|
|
903
898
|
Prefer no browser? Use 'artifacts share visibility <target> <level>'.
|
|
904
899
|
`);
|
|
905
900
|
void shareOpenCmd;
|
|
906
901
|
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
902
|
.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) => {
|
|
903
|
+
.description(`Deploy this CLI's share Worker to ${DEFAULT_SHARE_DOMAIN} only, keeping the Worker's secrets (the release workflow runs it).`)
|
|
904
|
+
.action(async () => {
|
|
964
905
|
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'));
|
|
906
|
+
const result = await runShareUpdate();
|
|
907
|
+
console.log(chalk.green(`Worker '${result.workerName}' deployed at ${result.url}: artifacts-cli ${result.version}`));
|
|
986
908
|
}
|
|
987
909
|
catch (e) {
|
|
988
910
|
console.error(chalk.red(e.message));
|
|
@@ -990,90 +912,37 @@ Notes:
|
|
|
990
912
|
}
|
|
991
913
|
})
|
|
992
914
|
.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.
|
|
915
|
+
Deploys the managed worker '${DEFAULT_WORKER_NAME}' (R2 bucket '${DEFAULT_BUCKET_NAME}') with
|
|
916
|
+
CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID from the environment, and
|
|
917
|
+
refuses unless that Worker already has ${MANAGED_WORKER_BINDINGS.join(', ')}.
|
|
918
|
+
Every binding it has is inherited, so the deploy needs none of their values.
|
|
919
|
+
Change a secret with:
|
|
920
|
+
wrangler secret put <NAME> --name ${DEFAULT_WORKER_NAME}
|
|
1025
921
|
`);
|
|
1026
|
-
void shareUpdateCmd;
|
|
1027
922
|
shareCmd
|
|
1028
923
|
.command('status')
|
|
1029
|
-
.description('Show the
|
|
924
|
+
.description('Show the share endpoint and your namespace on it.')
|
|
1030
925
|
.action(async () => {
|
|
1031
926
|
let backend;
|
|
1032
927
|
try {
|
|
1033
|
-
backend = resolveShareBackend(
|
|
928
|
+
backend = resolveShareBackend();
|
|
1034
929
|
}
|
|
1035
930
|
catch (e) {
|
|
1036
931
|
console.log(chalk.dim(e.message));
|
|
1037
932
|
return;
|
|
1038
933
|
}
|
|
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}`);
|
|
934
|
+
console.log(`${chalk.bold('endpoint')} ${chalk.green(backend.baseUrl)}`);
|
|
935
|
+
console.log(`${chalk.bold('namespace')} ${chalk.cyan(`${backend.baseUrl}/${backend.namespace}`)}`);
|
|
936
|
+
console.log(await workerStatusLine(backend.baseUrl));
|
|
1067
937
|
});
|
|
1068
938
|
const shareListCmd = shareCmd
|
|
1069
939
|
.command('list')
|
|
1070
940
|
.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
|
|
941
|
+
// Named --list-json / --scope, not --json / --visibility: `share <file>`
|
|
942
|
+
// (the parent) owns both of those long names, and commander resolves a child option's long name against the WHOLE
|
|
1074
943
|
// ancestor chain — a same-named child option is silently dropped at parse
|
|
1075
944
|
// time even when it parses alone.
|
|
1076
|
-
.
|
|
945
|
+
.addOption(ignoredForUserOption())
|
|
1077
946
|
.addOption(new Option('--scope <level>', 'visibility filter: public (default), unlisted, private, me, org, or all')
|
|
1078
947
|
.choices(['public', 'unlisted', 'private', 'me', 'org', 'all'])
|
|
1079
948
|
.default('public'))
|
|
@@ -1089,7 +958,6 @@ Notes:
|
|
|
1089
958
|
const scope = opts.all ? 'all' : (opts.scope ?? 'public');
|
|
1090
959
|
const parentMeta = shareCmd.opts().meta ?? [];
|
|
1091
960
|
const result = await runShareList({
|
|
1092
|
-
githubUser: opts.forUser,
|
|
1093
961
|
scope,
|
|
1094
962
|
agent: opts.agent,
|
|
1095
963
|
session: opts.session,
|
|
@@ -1109,7 +977,6 @@ Examples:
|
|
|
1109
977
|
$ artifacts share list --all # include hidden unlisted/private/me/org pages
|
|
1110
978
|
$ artifacts share list --scope me
|
|
1111
979
|
$ artifacts share list --list-json | jq -r '.objects[].url'
|
|
1112
|
-
$ artifacts share list --for-user octocat
|
|
1113
980
|
$ artifacts share list --agent claude --label-contains "fleet plan" --meta kind=plan
|
|
1114
981
|
|
|
1115
982
|
Notes:
|
|
@@ -1126,7 +993,7 @@ Notes:
|
|
|
1126
993
|
const shareEditCmd = shareCmd
|
|
1127
994
|
.command('edit <target>')
|
|
1128
995
|
.description("Edit a published share's label or arbitrary metadata without republishing its body.")
|
|
1129
|
-
.
|
|
996
|
+
.addOption(ignoredForUserOption())
|
|
1130
997
|
.option('--label <text>', 'set or replace the display label')
|
|
1131
998
|
.option('--remove-label', 'remove the display label')
|
|
1132
999
|
.option('--meta <key=value>', 'merge a metadata entry (repeatable)', (v, p) => [...p, v], [])
|
|
@@ -1149,7 +1016,6 @@ Notes:
|
|
|
1149
1016
|
}
|
|
1150
1017
|
const removeMeta = opts.removeMeta.map((key) => Object.keys(parseMetaEntries([`${key}=x`]))[0]);
|
|
1151
1018
|
const result = await runShareEdit(target, {
|
|
1152
|
-
githubUser: opts.forUser,
|
|
1153
1019
|
label: opts.removeLabel ? null : label === undefined ? undefined : sanitizeLabel(label),
|
|
1154
1020
|
meta: parseMetaEntries(opts.replaceMeta.length ? opts.replaceMeta : mergeMeta),
|
|
1155
1021
|
metaMode: opts.replaceMeta.length ? 'replace' : 'merge',
|
|
@@ -1183,11 +1049,11 @@ Notes:
|
|
|
1183
1049
|
const shareRevisionsCmd = shareCmd
|
|
1184
1050
|
.command('revisions <target>')
|
|
1185
1051
|
.description('Show the retained prior versions of a published slug, newest first (human table; --revisions-json for scripts).')
|
|
1186
|
-
.
|
|
1052
|
+
.addOption(ignoredForUserOption())
|
|
1187
1053
|
.option('--revisions-json', 'emit the machine-readable revision list')
|
|
1188
1054
|
.action(async (target, opts) => {
|
|
1189
1055
|
try {
|
|
1190
|
-
const result = await runShareRevisions(target
|
|
1056
|
+
const result = await runShareRevisions(target);
|
|
1191
1057
|
console.log(formatShareRevisions(result, Boolean(opts.revisionsJson)));
|
|
1192
1058
|
}
|
|
1193
1059
|
catch (e) {
|
|
@@ -1200,7 +1066,7 @@ Examples:
|
|
|
1200
1066
|
$ artifacts share revisions q3-report
|
|
1201
1067
|
$ artifacts share revisions octocat/q3-report
|
|
1202
1068
|
$ artifacts share revisions https://share.getrush.ai/octocat/q3-report
|
|
1203
|
-
$ artifacts share revisions q3-report --revisions-json
|
|
1069
|
+
$ artifacts share revisions q3-report --revisions-json
|
|
1204
1070
|
|
|
1205
1071
|
Notes:
|
|
1206
1072
|
A revision is created automatically on every republish of an existing slug
|
|
@@ -1239,11 +1105,11 @@ Notes:
|
|
|
1239
1105
|
shareMediaCmd
|
|
1240
1106
|
.command('status <target>')
|
|
1241
1107
|
.description('Show whether the transcript and summary are pending, ready or failed (and why).')
|
|
1242
|
-
.
|
|
1108
|
+
.addOption(ignoredForUserOption())
|
|
1243
1109
|
.option('--media-json', 'emit a machine-readable result')
|
|
1244
1110
|
.action(async (target, opts) => {
|
|
1245
1111
|
try {
|
|
1246
|
-
const status = await runShareMediaStatus(target
|
|
1112
|
+
const status = await runShareMediaStatus(target);
|
|
1247
1113
|
console.log(formatShareMediaStatus(status, Boolean(opts.mediaJson)));
|
|
1248
1114
|
if (status.media === 'failed')
|
|
1249
1115
|
process.exitCode = 1;
|
|
@@ -1256,55 +1122,17 @@ Notes:
|
|
|
1256
1122
|
shareMediaCmd
|
|
1257
1123
|
.command('retry <target>')
|
|
1258
1124
|
.description('Restart a failed transcript/summary job on a video you own (a summary failure re-runs only the summary).')
|
|
1259
|
-
.
|
|
1125
|
+
.addOption(ignoredForUserOption())
|
|
1260
1126
|
.option('--media-json', 'emit a machine-readable result')
|
|
1261
1127
|
.action(async (target, opts) => {
|
|
1262
1128
|
try {
|
|
1263
|
-
console.log(formatShareMediaRetry(await runShareMediaRetry(target
|
|
1129
|
+
console.log(formatShareMediaRetry(await runShareMediaRetry(target), Boolean(opts.mediaJson)));
|
|
1264
1130
|
}
|
|
1265
1131
|
catch (e) {
|
|
1266
1132
|
console.error(chalk.red(e.message));
|
|
1267
1133
|
process.exitCode = 1;
|
|
1268
1134
|
}
|
|
1269
1135
|
});
|
|
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
1136
|
}
|
|
1309
1137
|
/**
|
|
1310
1138
|
* Register `artifacts unshare <targets...>` as the top-level alias of
|
|
@@ -1319,175 +1147,23 @@ export function registerUnshareCommand(program) {
|
|
|
1319
1147
|
await runShareDelete(targets, opts);
|
|
1320
1148
|
});
|
|
1321
1149
|
}
|
|
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`. */
|
|
1150
|
+
/** What the managed Worker cannot serve without: its bucket, Phoenix sign-in,
|
|
1151
|
+
* and review threads. `share update` refuses a Worker missing any of them. */
|
|
1152
|
+
const MANAGED_WORKER_BINDINGS = ['BUCKET', 'PHOENIX_ID_BASE', 'COLLAB_API_BASE', 'COLLAB_SERVICE_TOKEN'];
|
|
1153
|
+
/** Deploy the current Worker to the managed endpoint only (worker and R2 bucket
|
|
1154
|
+
* `agents-share`, served at share.getrush.ai), inheriting every binding the
|
|
1155
|
+
* Worker already has, so the deploy needs no secret values. */
|
|
1398
1156
|
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>'.");
|
|
1157
|
+
const env = opts.env ?? process.env;
|
|
1158
|
+
const apiToken = env.CLOUDFLARE_API_TOKEN?.trim();
|
|
1159
|
+
const accountId = env.CLOUDFLARE_ACCOUNT_ID?.trim();
|
|
1160
|
+
if (!apiToken || !accountId) {
|
|
1161
|
+
throw new Error('artifacts share update needs CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID in the environment.');
|
|
1429
1162
|
}
|
|
1430
|
-
|
|
1431
|
-
const phoenixIdBase = phoenixIdBaseForDeploy({ managed: opts.managed }, cfg);
|
|
1432
|
-
const collab = collabBindingFromFlag(opts.collabApi);
|
|
1433
|
-
const media = mediaBindingFromFlag(opts.mediaKeys);
|
|
1434
|
-
const provisionOpts = {
|
|
1163
|
+
await deployWorker(apiToken, accountId, DEFAULT_WORKER_NAME, renderWorkerBundle(), DEFAULT_BUCKET_NAME, {
|
|
1435
1164
|
...(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,
|
|
1165
|
+
requireBindings: MANAGED_WORKER_BINDINGS,
|
|
1487
1166
|
});
|
|
1488
|
-
|
|
1489
|
-
console.log(chalk.green(`Joined ${chalk.bold(clean)} — publish with `) + chalk.cyan('artifacts share <file>'));
|
|
1167
|
+
return { workerName: DEFAULT_WORKER_NAME, url: managedShareBaseUrl(), version: SHARE_WORKER_VERSION };
|
|
1490
1168
|
}
|
|
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
1169
|
//# sourceMappingURL=share.js.map
|