@phnx-labs/artifacts-cli 0.9.13 → 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 +25 -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 +207 -27
- 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
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type ShareBackendKind } from './backend.js';
|
|
1
|
+
import { type ShareBackend } from './backend.js';
|
|
3
2
|
import { type CommentPolicy, type ShareVisibility } from './visibility.js';
|
|
4
3
|
/** The share upload result. `body`/`retryAfter` carry the server's error
|
|
5
4
|
* response so a failed publish can surface WHY (the Worker returns
|
|
@@ -26,13 +25,7 @@ export interface CollabRegistration {
|
|
|
26
25
|
/** Read the Worker's `x-collab-registered` / `x-collab-error` response headers. */
|
|
27
26
|
export declare function readCollabRegistration(headers: Headers): CollabRegistration | undefined;
|
|
28
27
|
export type PutFn = (url: string, body: Buffer, headers: Record<string, string>) => Promise<PutResult>;
|
|
29
|
-
export interface PublishEndpoint {
|
|
30
|
-
baseUrl: string;
|
|
31
|
-
token: string;
|
|
32
|
-
}
|
|
33
28
|
export interface PublishOptions {
|
|
34
|
-
/** Internal resolved backend; publishFile sets this after authentication. */
|
|
35
|
-
backendKind?: ShareBackendKind;
|
|
36
29
|
slug?: string;
|
|
37
30
|
/**
|
|
38
31
|
* Auto-expire window. Relative (`30d`, `12h`), absolute (`2026-08-01`), or
|
|
@@ -78,33 +71,22 @@ export interface PublishOptions {
|
|
|
78
71
|
* strings). Required when the page intentionally carries those patterns.
|
|
79
72
|
*/
|
|
80
73
|
force?: boolean;
|
|
81
|
-
/**
|
|
74
|
+
/** Point og:image at the Worker-rendered cover for HTML pages (default true). */
|
|
82
75
|
cover?: boolean;
|
|
83
|
-
/** Inject the Cloudflare Web Analytics beacon (default true for HTML). */
|
|
84
|
-
analytics?: boolean;
|
|
85
76
|
/**
|
|
86
77
|
* Embed a QR of the final share URL (including any `?k=` viewer token) in the
|
|
87
78
|
* page footer, so a desktop reader can hand the page to a phone (default true
|
|
88
79
|
* for HTML). Local renders never get one — they have no URL.
|
|
89
80
|
*/
|
|
90
81
|
qr?: boolean;
|
|
91
|
-
/** Override the analytics token from share config. */
|
|
92
|
-
analyticsToken?: string;
|
|
93
|
-
/** Override the GitHub username used for the URL namespace (BYO path). */
|
|
94
|
-
githubUser?: string;
|
|
95
82
|
/**
|
|
96
83
|
* Override the managed public handle (PHNX-3547). Managed publishes normally
|
|
97
84
|
* namespace under the email local-part; when that handle is taken — or a
|
|
98
85
|
* vanity namespace is wanted — pass an alternate. Sanitized to
|
|
99
86
|
* `[a-z0-9-]` (max 63 chars, matching the Worker); the Worker binds it with
|
|
100
|
-
* the same first-writer claim as a derived handle.
|
|
101
|
-
* `githubUser` there).
|
|
87
|
+
* the same first-writer claim as a derived handle.
|
|
102
88
|
*/
|
|
103
89
|
handle?: string;
|
|
104
|
-
/** DI seam for tests — override the persisted share endpoint config. */
|
|
105
|
-
config?: ShareConfig;
|
|
106
|
-
/** DI seam for tests — override the keychain-backed write token. Selects BYO. */
|
|
107
|
-
writeToken?: string;
|
|
108
90
|
/** DI seam for tests — override `readSession()`. `null` means signed out. */
|
|
109
91
|
session?: import('../identity/client.js').PhoenixSession | null;
|
|
110
92
|
/**
|
|
@@ -113,8 +95,6 @@ export interface PublishOptions {
|
|
|
113
95
|
* an empty string suppresses the stamp (initials-only bar).
|
|
114
96
|
*/
|
|
115
97
|
avatar?: string;
|
|
116
|
-
/** Force the BYO Cloudflare path even when signed in. */
|
|
117
|
-
byo?: boolean;
|
|
118
98
|
/** DI seam for tests — override the real HTTP PUT. */
|
|
119
99
|
uploader?: PutFn;
|
|
120
100
|
/** DI seam for tests — override multipart HTTP requests. */
|
|
@@ -123,8 +103,6 @@ export interface PublishOptions {
|
|
|
123
103
|
uploadStateDir?: string;
|
|
124
104
|
/** Called after multipart resume and each completed part. */
|
|
125
105
|
onUploadProgress?: (uploadedBytes: number, totalBytes: number) => void;
|
|
126
|
-
/** DI seam for tests — override cover capture (returns a PNG buffer or null). */
|
|
127
|
-
capturer?: (htmlPath: string) => Promise<Buffer | null>;
|
|
128
106
|
/**
|
|
129
107
|
* Human display title, shown instead of the slug in the gallery and
|
|
130
108
|
* `artifacts share list`. When omitted, one is derived (HTML `<title>`,
|
|
@@ -181,17 +159,6 @@ export interface PublishResult {
|
|
|
181
159
|
/** Review-thread registration outcome, when the endpoint reported one. */
|
|
182
160
|
collab?: CollabRegistration;
|
|
183
161
|
}
|
|
184
|
-
/**
|
|
185
|
-
* `--protected` / `{ protected: true }` map to `private` (token-gated — it wins
|
|
186
|
-
* over `--unlisted` when both are set, being the stronger control); `--unlisted`
|
|
187
|
-
* maps to `unlisted`; `--visibility private|unlisted|me|org` passes through;
|
|
188
|
-
* otherwise `visibility` (default public).
|
|
189
|
-
*/
|
|
190
|
-
export declare function resolveShareVisibility(opts?: {
|
|
191
|
-
visibility?: ShareVisibility;
|
|
192
|
-
unlisted?: boolean;
|
|
193
|
-
protected?: boolean;
|
|
194
|
-
}): ShareVisibility;
|
|
195
162
|
/** Mint a fresh random viewer token for a `private` (token-gated) publish. The
|
|
196
163
|
* raw token rides ONLY in the returned URL's `?k=`; the Worker stores just its
|
|
197
164
|
* SHA-256 hash, so the object metadata never carries the secret. */
|
|
@@ -254,10 +221,10 @@ export declare function resolveShareProvenance(opts?: {
|
|
|
254
221
|
* lowercased email (Gravatar resolves either MD5 or SHA-256), with `d=404` so
|
|
255
222
|
* Gravatar returns 404 for a user who has none — the bar's `<img>` onerror
|
|
256
223
|
* then falls back to the initials circle. Only the hash lands in public
|
|
257
|
-
* metadata, never the raw email. Returns '' when
|
|
258
|
-
*
|
|
224
|
+
* metadata, never the raw email. Returns '' when there is no session, leaving
|
|
225
|
+
* the bar on the initials circle.
|
|
259
226
|
*
|
|
260
|
-
* `opts.session === null` means "explicitly signed out" (a test seam
|
|
227
|
+
* `opts.session === null` means "explicitly signed out" (a test seam) and
|
|
261
228
|
* yields ''; `undefined` reads the real persisted session.
|
|
262
229
|
*/
|
|
263
230
|
export declare function resolveShareAvatar(opts?: {
|
|
@@ -380,33 +347,11 @@ export declare function detectProject(dir?: string): string;
|
|
|
380
347
|
* URL. `--slug` remains an exact override.
|
|
381
348
|
*/
|
|
382
349
|
export declare function defaultSlug(filePath: string, body?: Buffer): string;
|
|
383
|
-
/**
|
|
384
|
-
|
|
385
|
-
* the page body with og:image meta injected (+ the cover URL). All IO is injected
|
|
386
|
-
* (`put`, `capturer`), so this whole path is unit-testable without config/keychain.
|
|
387
|
-
* Any miss — no capturer output, a failed upload — returns the original body and no
|
|
388
|
-
* coverUrl, so publishing never fails because a cover couldn't be made.
|
|
389
|
-
*/
|
|
390
|
-
export declare function attachOgCover(filePath: string, body: Buffer, ctx: {
|
|
391
|
-
/** Absolute URL to PUT the cover to, `${pageUrl}.png`. Doubles as the cover URL. */
|
|
392
|
-
pngUrl: string;
|
|
393
|
-
pageUrl: string;
|
|
394
|
-
put: PutFn;
|
|
395
|
-
pngHeaders: Record<string, string>;
|
|
396
|
-
capturer: (p: string) => Promise<Buffer | null>;
|
|
397
|
-
}): Promise<{
|
|
398
|
-
body: Buffer;
|
|
399
|
-
coverUrl?: string;
|
|
400
|
-
}>;
|
|
401
|
-
/** Resolve the publisher's GitHub username, with an explicit override winning first. */
|
|
402
|
-
export declare function resolveShareUsername(opts?: {
|
|
403
|
-
githubUser?: string;
|
|
404
|
-
}): Promise<string>;
|
|
405
|
-
/** Build the R2 object key from a namespace username and a slug part. */
|
|
406
|
-
export declare function buildShareKey(username: string, slugPart: string): string;
|
|
350
|
+
/** Build the R2 object key from a namespace and a slug part. */
|
|
351
|
+
export declare function buildShareKey(namespace: string, slugPart: string): string;
|
|
407
352
|
export declare function publishFile(filePath: string, opts?: PublishOptions): Promise<PublishResult>;
|
|
408
353
|
/** Sanitize a caller-chosen managed handle to the Worker's namespace shape.
|
|
409
354
|
* Returns '' when the result is empty or over the Worker's 63-char cap (the
|
|
410
|
-
* caller then
|
|
355
|
+
* caller then errors). */
|
|
411
356
|
export declare function resolveManagedHandle(handle: string | undefined): string;
|
|
412
|
-
export declare function publishToEndpoint(filePath: string, endpoint:
|
|
357
|
+
export declare function publishToEndpoint(filePath: string, endpoint: ShareBackend, opts?: PublishOptions): Promise<PublishResult>;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
// The publish path for `artifacts share <file>` — an authed PUT to the
|
|
2
|
-
// Pure logic (slug, expiry) is exported for tests; the network call
|
|
1
|
+
// The publish path for `artifacts share <file>` — an authed PUT to the managed
|
|
2
|
+
// share Worker. Pure logic (slug, expiry) is exported for tests; the network call
|
|
3
|
+
// is behind a DI seam.
|
|
3
4
|
//
|
|
4
|
-
// For HTML publishes it
|
|
5
|
-
//
|
|
6
|
-
// Slack / iMessage / Twitter / Discord.
|
|
7
|
-
// browser is available it's skipped and the plain link still publishes.
|
|
5
|
+
// For HTML publishes it injects og:image / twitter:card meta pointing at the
|
|
6
|
+
// Worker's lazily rendered `<page>.png` cover, so the link unfurls into a preview
|
|
7
|
+
// card in Slack / iMessage / Twitter / Discord.
|
|
8
8
|
import { closeSync, createReadStream, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
9
9
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
10
10
|
import { execFileSync } from 'node:child_process';
|
|
11
11
|
import { hostname as osHostname } from 'node:os';
|
|
12
12
|
import { createHash, randomBytes } from 'node:crypto';
|
|
13
13
|
import { readSession } from '../identity/client.js';
|
|
14
|
-
import { readShareConfig } from './config.js';
|
|
15
|
-
import { resolveGitHubUsername } from '../github.js';
|
|
16
14
|
import { resolveShareBackend, sanitizeShareNamespace } from './backend.js';
|
|
17
|
-
import { captureCover, OG_WIDTH, OG_HEIGHT, OG_SCALE } from './capture.js';
|
|
18
15
|
import { deriveMeta, injectOgMeta } from './og.js';
|
|
19
16
|
import { extractShareHttpError, formatShareHttpErrorDetail } from './http-error.js';
|
|
20
17
|
import { PUBLISH_VISIBILITY_LEVELS as MODEL_PUBLISH_VISIBILITY_LEVELS, EDITABLE_VISIBILITY_LEVELS, resolveVisibility, } from './visibility.js';
|
|
21
|
-
import { injectAnalyticsBeacon } from './analytics.js';
|
|
22
18
|
import { prepareShareHtml } from './html.js';
|
|
23
19
|
import { injectShareQr, stripShareQr } from './qr.js';
|
|
24
20
|
import { stateDir } from '../config.js';
|
|
@@ -41,19 +37,6 @@ export const PUBLISH_VISIBILITY_LEVELS = MODEL_PUBLISH_VISIBILITY_LEVELS;
|
|
|
41
37
|
* accept. Excludes `private`: re-scoping to token-gated needs a fresh viewer
|
|
42
38
|
* token, which only the publish path mints. */
|
|
43
39
|
export const SHARE_VISIBILITY_LEVELS = EDITABLE_VISIBILITY_LEVELS;
|
|
44
|
-
/**
|
|
45
|
-
* `--protected` / `{ protected: true }` map to `private` (token-gated — it wins
|
|
46
|
-
* over `--unlisted` when both are set, being the stronger control); `--unlisted`
|
|
47
|
-
* maps to `unlisted`; `--visibility private|unlisted|me|org` passes through;
|
|
48
|
-
* otherwise `visibility` (default public).
|
|
49
|
-
*/
|
|
50
|
-
export function resolveShareVisibility(opts = {}) {
|
|
51
|
-
// Delegates to the shared visibility resolver, whose fallback is `public` —
|
|
52
|
-
// the same default `artifacts share` applies. The command surface calls
|
|
53
|
-
// `publishVisibility` with the resolved backend so the default is decided in
|
|
54
|
-
// one place; this lib-level entry point is what non-CLI callers use.
|
|
55
|
-
return resolveVisibility(opts);
|
|
56
|
-
}
|
|
57
40
|
/** The bytes of viewer-token entropy the `private` mode mints (128-bit; the
|
|
58
41
|
* base64url form is ~22 URL-safe chars). Well past the 64-bit floor a guessable
|
|
59
42
|
* capability URL would fall to. */
|
|
@@ -151,10 +134,10 @@ export function resolveShareProvenance(opts = {}) {
|
|
|
151
134
|
* lowercased email (Gravatar resolves either MD5 or SHA-256), with `d=404` so
|
|
152
135
|
* Gravatar returns 404 for a user who has none — the bar's `<img>` onerror
|
|
153
136
|
* then falls back to the initials circle. Only the hash lands in public
|
|
154
|
-
* metadata, never the raw email. Returns '' when
|
|
155
|
-
*
|
|
137
|
+
* metadata, never the raw email. Returns '' when there is no session, leaving
|
|
138
|
+
* the bar on the initials circle.
|
|
156
139
|
*
|
|
157
|
-
* `opts.session === null` means "explicitly signed out" (a test seam
|
|
140
|
+
* `opts.session === null` means "explicitly signed out" (a test seam) and
|
|
158
141
|
* yields ''; `undefined` reads the real persisted session.
|
|
159
142
|
*/
|
|
160
143
|
export function resolveShareAvatar(opts = {}) {
|
|
@@ -530,51 +513,12 @@ function guessContentType(filePath) {
|
|
|
530
513
|
return 'text/plain; charset=utf-8';
|
|
531
514
|
return 'application/octet-stream';
|
|
532
515
|
}
|
|
533
|
-
/**
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
* (`put`, `capturer`), so this whole path is unit-testable without config/keychain.
|
|
537
|
-
* Any miss — no capturer output, a failed upload — returns the original body and no
|
|
538
|
-
* coverUrl, so publishing never fails because a cover couldn't be made.
|
|
539
|
-
*/
|
|
540
|
-
export async function attachOgCover(filePath, body, ctx) {
|
|
541
|
-
const png = await ctx.capturer(filePath).catch(() => null);
|
|
542
|
-
if (!png)
|
|
543
|
-
return { body };
|
|
544
|
-
const cr = await ctx.put(ctx.pngUrl, png, ctx.pngHeaders);
|
|
545
|
-
if (!cr.ok)
|
|
546
|
-
return { body };
|
|
547
|
-
const { title, description } = deriveMeta(body.toString('utf8'));
|
|
548
|
-
const injected = injectOgMeta(body.toString('utf8'), {
|
|
549
|
-
title,
|
|
550
|
-
description,
|
|
551
|
-
imageUrl: ctx.pngUrl,
|
|
552
|
-
pageUrl: ctx.pageUrl,
|
|
553
|
-
imageWidth: OG_WIDTH * OG_SCALE,
|
|
554
|
-
imageHeight: OG_HEIGHT * OG_SCALE,
|
|
555
|
-
});
|
|
556
|
-
return { body: Buffer.from(injected, 'utf8'), coverUrl: ctx.pngUrl };
|
|
557
|
-
}
|
|
558
|
-
/** Resolve the publisher's GitHub username, with an explicit override winning first. */
|
|
559
|
-
export async function resolveShareUsername(opts = {}) {
|
|
560
|
-
if (opts.githubUser) {
|
|
561
|
-
const sanitized = sanitizeSlugPart(opts.githubUser);
|
|
562
|
-
if (sanitized)
|
|
563
|
-
return sanitized;
|
|
564
|
-
}
|
|
565
|
-
const resolved = await resolveGitHubUsername();
|
|
566
|
-
if (resolved)
|
|
567
|
-
return sanitizeSlugPart(resolved);
|
|
568
|
-
throw new Error("Could not determine your GitHub username for the share URL namespace. " +
|
|
569
|
-
"Authenticate with `gh auth login`, set `git config --global github.user <user>`, " +
|
|
570
|
-
"or pass `--github-user <user>`.");
|
|
571
|
-
}
|
|
572
|
-
/** Build the R2 object key from a namespace username and a slug part. */
|
|
573
|
-
export function buildShareKey(username, slugPart) {
|
|
574
|
-
const user = sanitizeSlugPart(username);
|
|
516
|
+
/** Build the R2 object key from a namespace and a slug part. */
|
|
517
|
+
export function buildShareKey(namespace, slugPart) {
|
|
518
|
+
const user = sanitizeSlugPart(namespace);
|
|
575
519
|
const part = sanitizeSlugPart(slugPart.replace(/\//g, '-'));
|
|
576
520
|
if (!user)
|
|
577
|
-
throw new Error('
|
|
521
|
+
throw new Error('A namespace is required for the share URL.');
|
|
578
522
|
if (!part)
|
|
579
523
|
throw new Error('Share slug is empty.');
|
|
580
524
|
return `${user}/${part}`;
|
|
@@ -697,22 +641,11 @@ async function responseJson(response, operation) {
|
|
|
697
641
|
}
|
|
698
642
|
}
|
|
699
643
|
export async function publishFile(filePath, opts = {}) {
|
|
700
|
-
|
|
701
|
-
const managedHandle = backend.kind === 'managed' ? requireManagedHandle(opts.handle) : '';
|
|
702
|
-
const username = backend.kind === 'managed'
|
|
703
|
-
? managedHandle || backend.namespace
|
|
704
|
-
: await resolveShareUsername({ githubUser: opts.githubUser || backend.namespace || undefined });
|
|
705
|
-
const analyticsToken = opts.analyticsToken ?? (backend.kind === 'byo' ? (opts.config ?? readShareConfig())?.analyticsToken : undefined);
|
|
706
|
-
return publishToEndpoint(filePath, { baseUrl: backend.baseUrl, token: backend.token }, {
|
|
707
|
-
...opts,
|
|
708
|
-
githubUser: username,
|
|
709
|
-
analyticsToken,
|
|
710
|
-
backendKind: backend.kind,
|
|
711
|
-
});
|
|
644
|
+
return publishToEndpoint(filePath, resolveShareBackend({ session: opts.session }), opts);
|
|
712
645
|
}
|
|
713
646
|
/** Sanitize a caller-chosen managed handle to the Worker's namespace shape.
|
|
714
647
|
* Returns '' when the result is empty or over the Worker's 63-char cap (the
|
|
715
|
-
* caller then
|
|
648
|
+
* caller then errors). */
|
|
716
649
|
export function resolveManagedHandle(handle) {
|
|
717
650
|
if (!handle)
|
|
718
651
|
return '';
|
|
@@ -727,18 +660,17 @@ function requireManagedHandle(handle) {
|
|
|
727
660
|
return resolved;
|
|
728
661
|
}
|
|
729
662
|
export async function publishToEndpoint(filePath, endpoint, opts = {}) {
|
|
730
|
-
//
|
|
731
|
-
//
|
|
732
|
-
//
|
|
733
|
-
const managedHandle =
|
|
734
|
-
const username = managedHandle ||
|
|
663
|
+
// An explicit --handle namespaces the URL and rides the x-share-handle header
|
|
664
|
+
// so the Worker binds the claim to it (a derived handle is proven by the
|
|
665
|
+
// email; an alternate one must be declared).
|
|
666
|
+
const managedHandle = requireManagedHandle(opts.handle);
|
|
667
|
+
const username = managedHandle || endpoint.namespace;
|
|
735
668
|
let expiresAt = resolveExpire(opts.expire);
|
|
736
|
-
const visibility =
|
|
669
|
+
const visibility = resolveVisibility(opts);
|
|
737
670
|
const unlisted = visibility === 'unlisted';
|
|
738
671
|
const contentType = opts.contentType ?? guessContentType(filePath);
|
|
739
672
|
const initialStat = statSync(filePath);
|
|
740
|
-
const multipart =
|
|
741
|
-
(visibility === 'me' || visibility === 'org') &&
|
|
673
|
+
const multipart = (visibility === 'me' || visibility === 'org') &&
|
|
742
674
|
contentType.toLowerCase().startsWith('video/') &&
|
|
743
675
|
initialStat.size > SHARE_SINGLE_PUT_MAX_BYTES;
|
|
744
676
|
// A multipart video is never loaded wholesale: its label/slug both fall back
|
|
@@ -782,19 +714,13 @@ export async function publishToEndpoint(filePath, endpoint, opts = {}) {
|
|
|
782
714
|
// caller's namespace belongs to another account) and 'publish conflict'
|
|
783
715
|
// (a concurrent write won the republish race — retry, per PHNX-3547).
|
|
784
716
|
const httpError = extractShareHttpError({ status, body: responseBody, retryAfter });
|
|
785
|
-
if (status === 409 && httpError.serverMessage === 'handle taken'
|
|
717
|
+
if (status === 409 && httpError.serverMessage === 'handle taken') {
|
|
786
718
|
throw new Error(`Handle '${username}' is already claimed by another account. ` +
|
|
787
719
|
'If you signed in again and got a new account id, republishing with the same email re-binds your handle automatically; ' +
|
|
788
720
|
'otherwise pick a different public namespace with --handle <name>.');
|
|
789
721
|
}
|
|
790
722
|
const detail = formatShareHttpErrorDetail(httpError);
|
|
791
|
-
|
|
792
|
-
if (status === 401 || status === 403) {
|
|
793
|
-
advice =
|
|
794
|
-
opts.backendKind === 'managed'
|
|
795
|
-
? ". Check that you're signed in — run 'artifacts auth login'."
|
|
796
|
-
: ". Check the write token, or that 'artifacts share setup' completed.";
|
|
797
|
-
}
|
|
723
|
+
const advice = status === 401 || status === 403 ? ". Check that you're signed in — run 'artifacts auth login'." : '';
|
|
798
724
|
throw new Error(`Publish failed (${status}) for ${pageUrl}${detail}${advice}`);
|
|
799
725
|
};
|
|
800
726
|
let coverUrl;
|
|
@@ -812,17 +738,11 @@ export async function publishToEndpoint(filePath, endpoint, opts = {}) {
|
|
|
812
738
|
const label = explicitLabel ? sanitizeLabel(explicitLabel) : deriveLabel(filePath, body);
|
|
813
739
|
const labelSource = explicitLabel ? 'explicit' : 'derived';
|
|
814
740
|
const ogMeta = isHtml ? deriveMeta(body.toString('utf8')) : undefined;
|
|
815
|
-
// The
|
|
816
|
-
//
|
|
817
|
-
if (isHtml && opts.cover !== false &&
|
|
741
|
+
// The Worker owns deterministic OG generation. Point crawlers at the lazy
|
|
742
|
+
// sibling route.
|
|
743
|
+
if (isHtml && opts.cover !== false && ogMeta) {
|
|
818
744
|
coverUrl = `${pageUrl}.png`;
|
|
819
|
-
body = Buffer.from(injectOgMeta(body.toString('utf8'), {
|
|
820
|
-
...ogMeta,
|
|
821
|
-
imageUrl: coverUrl,
|
|
822
|
-
pageUrl,
|
|
823
|
-
imageWidth: OG_WIDTH,
|
|
824
|
-
imageHeight: OG_HEIGHT,
|
|
825
|
-
}), 'utf8');
|
|
745
|
+
body = Buffer.from(injectOgMeta(body.toString('utf8'), { ...ogMeta, imageUrl: coverUrl, pageUrl }), 'utf8');
|
|
826
746
|
}
|
|
827
747
|
// Pre-publish scan (RUSH-2443/RUSH-2683): refuse emails / credential-shaped
|
|
828
748
|
// strings unless --force. Runs on the raw file body AND on every piece of
|
|
@@ -830,9 +750,8 @@ export async function publishToEndpoint(filePath, endpoint, opts = {}) {
|
|
|
830
750
|
// or derived) and every --meta value. Metadata is visible in the gallery,
|
|
831
751
|
// `share list --list-json`, and `share revisions` just like the page itself, so a
|
|
832
752
|
// credential smuggled in there is exactly as exposed as one in the body; it
|
|
833
|
-
// must not have a free pass around this gate.
|
|
834
|
-
//
|
|
835
|
-
// scan. Binary media bodies are a no-op for the body scan.
|
|
753
|
+
// must not have a free pass around this gate. Binary media bodies are a no-op
|
|
754
|
+
// for the body scan.
|
|
836
755
|
if (opts.force !== true) {
|
|
837
756
|
const hits = [
|
|
838
757
|
...scanShareContent(body),
|
|
@@ -846,7 +765,7 @@ export async function publishToEndpoint(filePath, endpoint, opts = {}) {
|
|
|
846
765
|
// Validate the FULL customMetadata payload before any network call — fail
|
|
847
766
|
// fast, not mid-upload.
|
|
848
767
|
const metadataPreview = { ...meta, label, 'label-source': labelSource };
|
|
849
|
-
if (ogMeta
|
|
768
|
+
if (ogMeta) {
|
|
850
769
|
metadataPreview['og-title'] = ogMeta.title;
|
|
851
770
|
metadataPreview['og-description'] = ogMeta.description;
|
|
852
771
|
}
|
|
@@ -907,7 +826,7 @@ export async function publishToEndpoint(filePath, endpoint, opts = {}) {
|
|
|
907
826
|
setText('x-share-avatar', avatarUrl);
|
|
908
827
|
setText('x-share-label', label);
|
|
909
828
|
h['x-share-label-source'] = labelSource;
|
|
910
|
-
if (ogMeta
|
|
829
|
+
if (ogMeta) {
|
|
911
830
|
setText('x-share-og-title', ogMeta.title);
|
|
912
831
|
setText('x-share-og-description', ogMeta.description);
|
|
913
832
|
}
|
|
@@ -931,24 +850,6 @@ export async function publishToEndpoint(filePath, endpoint, opts = {}) {
|
|
|
931
850
|
h['x-share-no-revision'] = '1';
|
|
932
851
|
return h;
|
|
933
852
|
};
|
|
934
|
-
// Analytics: cookieless CF Web Analytics beacon, injected for HTML by default.
|
|
935
|
-
if (isHtml && opts.analytics !== false && opts.analyticsToken) {
|
|
936
|
-
body = Buffer.from(injectAnalyticsBeacon(body.toString('utf8'), opts.analyticsToken), 'utf8');
|
|
937
|
-
}
|
|
938
|
-
// Cover: screenshot the page's hero → upload <slug>.png → inject og:image meta.
|
|
939
|
-
// Unlisted pages still get a cover (the direct URL is the capability), but the
|
|
940
|
-
// cover inherits visibility=unlisted so it is also omitted from the gallery.
|
|
941
|
-
if (isHtml && opts.cover !== false && opts.backendKind !== 'managed') {
|
|
942
|
-
const res = await attachOgCover(filePath, body, {
|
|
943
|
-
pngUrl: `${pageUrl}.png`,
|
|
944
|
-
pageUrl,
|
|
945
|
-
put,
|
|
946
|
-
pngHeaders: authHeaders('image/png'),
|
|
947
|
-
capturer: opts.capturer ?? captureCover,
|
|
948
|
-
});
|
|
949
|
-
body = res.body;
|
|
950
|
-
coverUrl = res.coverUrl;
|
|
951
|
-
}
|
|
952
853
|
// Footer QR: the exact URL a phone should open — for a token-gated publish
|
|
953
854
|
// that includes the freshly minted `?k=` viewer token, minted above. Runs
|
|
954
855
|
// after the sensitive-content scan so the base64 payload can never trip it,
|