@phnx-labs/artifacts-cli 0.4.6 → 0.5.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 +130 -0
- package/README.md +127 -12
- package/dist/cli.d.ts +1 -6
- package/dist/cli.js +93 -85
- package/dist/cli.js.map +1 -1
- package/dist/commands/auth.d.ts +5 -0
- package/dist/commands/auth.js +112 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/favorite.d.ts +9 -0
- package/dist/commands/favorite.js +59 -0
- package/dist/commands/favorite.js.map +1 -0
- package/dist/commands/share.d.ts +297 -14
- package/dist/commands/share.js +1351 -71
- package/dist/commands/share.js.map +1 -1
- package/dist/lib/browser-detect.d.ts +28 -0
- package/dist/lib/browser-detect.js +126 -0
- package/dist/lib/browser-detect.js.map +1 -0
- package/dist/lib/config.d.ts +14 -0
- package/dist/lib/config.js +8 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/embedded-html.d.ts +1 -1
- package/dist/lib/embedded-html.js +12 -0
- package/dist/lib/embedded-html.js.map +1 -1
- package/dist/lib/excerpt.d.ts +48 -0
- package/dist/lib/excerpt.js +167 -0
- package/dist/lib/excerpt.js.map +1 -0
- package/dist/lib/favorites.d.ts +73 -0
- package/dist/lib/favorites.js +180 -0
- package/dist/lib/favorites.js.map +1 -0
- package/dist/lib/format.d.ts +2 -0
- package/dist/lib/format.js +14 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/freshness.d.ts +1 -1
- package/dist/lib/freshness.js +1 -1
- package/dist/lib/github.d.ts +14 -0
- package/dist/lib/github.js +36 -0
- package/dist/lib/github.js.map +1 -0
- package/dist/lib/header-actions.d.ts +44 -0
- package/dist/lib/header-actions.js +181 -0
- package/dist/lib/header-actions.js.map +1 -0
- package/dist/lib/identity/client.d.ts +49 -0
- package/dist/lib/identity/client.js +97 -0
- package/dist/lib/identity/client.js.map +1 -0
- package/dist/lib/identity/index.d.ts +60 -0
- package/dist/lib/identity/index.js +69 -0
- package/dist/lib/identity/index.js.map +1 -0
- package/dist/lib/link-previews.d.ts +67 -0
- package/dist/lib/link-previews.js +427 -0
- package/dist/lib/link-previews.js.map +1 -0
- package/dist/lib/links.d.ts +2 -0
- package/dist/lib/links.js +21 -2
- package/dist/lib/links.js.map +1 -1
- package/dist/lib/math.d.ts +31 -0
- package/dist/lib/math.js +122 -0
- package/dist/lib/math.js.map +1 -0
- package/dist/lib/metadata-menu.d.ts +16 -1
- package/dist/lib/metadata-menu.js +24 -0
- package/dist/lib/metadata-menu.js.map +1 -1
- package/dist/lib/open.d.ts +6 -0
- package/dist/lib/open.js +54 -0
- package/dist/lib/open.js.map +1 -0
- package/dist/lib/render.d.ts +3 -0
- package/dist/lib/render.js +164 -54
- package/dist/lib/render.js.map +1 -1
- package/dist/lib/revisions.d.ts +17 -0
- package/dist/lib/revisions.js +6 -1
- package/dist/lib/revisions.js.map +1 -1
- package/dist/lib/share/analytics.d.ts +13 -0
- package/dist/lib/share/analytics.js +46 -0
- package/dist/lib/share/analytics.js.map +1 -0
- package/dist/lib/share/backend.d.ts +105 -0
- package/dist/lib/share/backend.js +161 -0
- package/dist/lib/share/backend.js.map +1 -0
- package/dist/lib/share/capture.d.ts +31 -0
- package/dist/lib/share/capture.js +175 -0
- package/dist/lib/share/capture.js.map +1 -0
- package/dist/lib/share/config.d.ts +82 -0
- package/dist/lib/share/config.js +181 -0
- package/dist/lib/share/config.js.map +1 -0
- package/dist/lib/share/delete.d.ts +122 -0
- package/dist/lib/share/delete.js +174 -0
- package/dist/lib/share/delete.js.map +1 -0
- package/dist/lib/share/html.d.ts +22 -0
- package/dist/lib/share/html.js +89 -0
- package/dist/lib/share/html.js.map +1 -0
- package/dist/lib/share/http-error.d.ts +52 -0
- package/dist/lib/share/http-error.js +66 -0
- package/dist/lib/share/http-error.js.map +1 -0
- package/dist/lib/share/og.d.ts +25 -0
- package/dist/lib/share/og.js +85 -0
- package/dist/lib/share/og.js.map +1 -0
- package/dist/lib/share/provision.d.ts +99 -0
- package/dist/lib/share/provision.js +271 -0
- package/dist/lib/share/provision.js.map +1 -0
- package/dist/lib/share/publish.d.ts +393 -0
- package/dist/lib/share/publish.js +829 -0
- package/dist/lib/share/publish.js.map +1 -0
- package/dist/lib/share/qr.d.ts +36 -0
- package/dist/lib/share/qr.js +102 -0
- package/dist/lib/share/qr.js.map +1 -0
- package/dist/lib/share/storage-policy.d.ts +9 -0
- package/dist/lib/share/storage-policy.js +43 -0
- package/dist/lib/share/storage-policy.js.map +1 -0
- package/dist/lib/share/visibility.d.ts +92 -0
- package/dist/lib/share/visibility.js +108 -0
- package/dist/lib/share/visibility.js.map +1 -0
- package/dist/lib/share/worker-template.d.ts +29 -0
- package/dist/lib/share/worker-template.js +2154 -0
- package/dist/lib/share/worker-template.js.map +1 -0
- package/dist/lib/status-list.d.ts +49 -0
- package/dist/lib/status-list.js +153 -0
- package/dist/lib/status-list.js.map +1 -0
- package/dist/lib/validate.js +122 -8
- package/dist/lib/validate.js.map +1 -1
- package/package.json +12 -3
- package/dist/lib/share-provision.d.ts +0 -31
- package/dist/lib/share-provision.js +0 -83
- package/dist/lib/share-provision.js.map +0 -1
- package/dist/lib/share-worker.d.ts +0 -1
- package/dist/lib/share-worker.js +0 -66
- package/dist/lib/share-worker.js.map +0 -1
- package/dist/lib/share.d.ts +0 -39
- package/dist/lib/share.js +0 -159
- package/dist/lib/share.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/lib/share/config.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,EAAE;AACF,+EAA+E;AAC/E,iFAAiF;AACjF,uCAAuC;AACvC,yEAAyE;AACzE,oEAAoE;AACpE,gFAAgF;AAChF,wEAAwE;AACxE,iCAAiC;AACjC,EAAE;AACF,kFAAkF;AAClF,mEAAmE;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,O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E,cAAc,CAAC,CAAC;QACxF,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS,GAAG,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC,IAAI,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QAC7F,CAAC;IACH,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,+EAA+E;YAC7E,8FAA8F;YAC9F,uBAAuB,MAAM,4BAA4B,CAC5D,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AACjC,CAAC;AAKD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,GAAW;IACzD,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE;YAChF,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC;YACnC,OAAO,EAAE,MAAM;SAChB,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type ShareConfig } from './config.js';
|
|
2
|
+
/** DI seam for tests — override the real HTTP DELETE. `body`/`retryAfter` carry
|
|
3
|
+
* the Worker's error response (read only on `!ok`) so a failed delete surfaces
|
|
4
|
+
* WHY, via the bounded {@link extractShareHttpError}. */
|
|
5
|
+
export type DeleteFn = (url: string, headers: Record<string, string>) => Promise<{
|
|
6
|
+
ok: boolean;
|
|
7
|
+
status: number;
|
|
8
|
+
body?: string;
|
|
9
|
+
retryAfter?: string;
|
|
10
|
+
}>;
|
|
11
|
+
/** DI seam for tests — override the real HTTP existence check (HEAD). */
|
|
12
|
+
export type CheckFn = (url: string) => Promise<{
|
|
13
|
+
status: number;
|
|
14
|
+
}>;
|
|
15
|
+
/** DI seam for tests — override the real HTTP GET of the revisions listing route. */
|
|
16
|
+
export type RevisionsFetchFn = (url: string) => Promise<{
|
|
17
|
+
status: number;
|
|
18
|
+
contentType: string;
|
|
19
|
+
body: string;
|
|
20
|
+
}>;
|
|
21
|
+
export interface DeleteEndpoint {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
token: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ResolvedShareTarget {
|
|
26
|
+
/** R2 object key for the page, `<user>/<slug>`. */
|
|
27
|
+
key: string;
|
|
28
|
+
/** R2 object key for the sibling OG cover, `<user>/<slug>.png`. */
|
|
29
|
+
coverKey: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Normalize any of the three accepted target forms to the R2 key that publish
|
|
33
|
+
* would have written:
|
|
34
|
+
* - a full share URL: `https://share.getrush.ai/<user>/<slug>`
|
|
35
|
+
* - `<user>/<slug>`
|
|
36
|
+
* - a bare `<slug>` — resolved against the caller's own namespace exactly as
|
|
37
|
+
* `publishToEndpoint` resolves it at publish time (resolveShareUsername +
|
|
38
|
+
* buildShareKey), so a bare slug always targets *your* published page.
|
|
39
|
+
*
|
|
40
|
+
* The URL and `<user>/<slug>` forms are taken as already the exact key a prior
|
|
41
|
+
* publish produced (no re-sanitizing) — only the bare-slug form runs through
|
|
42
|
+
* `buildShareKey`, because that's the one case where the slug hasn't already
|
|
43
|
+
* been normalized by a publish.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveDeleteTarget(target: string, opts?: {
|
|
46
|
+
githubUser?: string;
|
|
47
|
+
}): Promise<ResolvedShareTarget>;
|
|
48
|
+
export interface DeleteObjectResult {
|
|
49
|
+
key: string;
|
|
50
|
+
url: string;
|
|
51
|
+
/** Whether the object resolved (non-404) before the DELETE was issued. */
|
|
52
|
+
existedBefore: boolean;
|
|
53
|
+
/** Whether the Worker's DELETE call itself reported ok. */
|
|
54
|
+
deleted: boolean;
|
|
55
|
+
/** The postcondition: a follow-up check resolved 404 after the DELETE. */
|
|
56
|
+
verified404: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Delete one R2 object behind the share Worker and assert the postcondition.
|
|
60
|
+
* `{"ok":true}` from the Worker is not evidence a page came down — R2 delete is
|
|
61
|
+
* idempotent, so a DELETE on a key that was never there also returns `ok:true`.
|
|
62
|
+
* This checks existence before (so callers can tell "deleted" from "was never
|
|
63
|
+
* there") and re-checks after (so callers can tell "deleted" from "still public").
|
|
64
|
+
*/
|
|
65
|
+
export declare function deleteObject(endpoint: DeleteEndpoint, key: string, opts?: {
|
|
66
|
+
deleter?: DeleteFn;
|
|
67
|
+
checker?: CheckFn;
|
|
68
|
+
}): Promise<DeleteObjectResult>;
|
|
69
|
+
export interface DeleteShareOptions {
|
|
70
|
+
/** Skip deleting the sibling `<slug>.png` OG cover (default: delete it too). */
|
|
71
|
+
keepCover?: boolean;
|
|
72
|
+
/** Skip deleting the target's retained revisions (`<key>/rev-*`, RUSH-2683
|
|
73
|
+
* revision retention) — default: delete them too. A republished-then-deleted
|
|
74
|
+
* share would otherwise leave its prior world-readable versions live for up
|
|
75
|
+
* to the bucket's lifecycle max-age. */
|
|
76
|
+
keepRevisions?: boolean;
|
|
77
|
+
/** Treat an already-missing target as a no-op success instead of an error
|
|
78
|
+
* (mirrors SQL's `DROP ... IF EXISTS`). Default: missing target is an error. */
|
|
79
|
+
ifExists?: boolean;
|
|
80
|
+
/** Override the GitHub username used to resolve a bare-slug target. */
|
|
81
|
+
githubUser?: string;
|
|
82
|
+
/** DI seam for tests — override the persisted share endpoint config. */
|
|
83
|
+
config?: ShareConfig;
|
|
84
|
+
/** DI seam for tests — override the keychain-backed write token. Selects BYO. */
|
|
85
|
+
writeToken?: string;
|
|
86
|
+
/** DI seam for tests — override `readSession()`. `null` means signed out. */
|
|
87
|
+
session?: import('../identity/client.js').PhoenixSession | null;
|
|
88
|
+
/** Force the BYO Cloudflare path even when signed in. */
|
|
89
|
+
byo?: boolean;
|
|
90
|
+
/** DI seam for tests — override the real HTTP DELETE. */
|
|
91
|
+
deleter?: DeleteFn;
|
|
92
|
+
/** DI seam for tests — override the real HTTP existence check. */
|
|
93
|
+
checker?: CheckFn;
|
|
94
|
+
/** DI seam for tests — override the real HTTP GET of the revisions listing route. */
|
|
95
|
+
fetchRevisions?: RevisionsFetchFn;
|
|
96
|
+
}
|
|
97
|
+
export interface DeleteShareResult {
|
|
98
|
+
key: string;
|
|
99
|
+
url: string;
|
|
100
|
+
existedBefore: boolean;
|
|
101
|
+
verified404: boolean;
|
|
102
|
+
/** True when `ifExists` was set and the target was already gone — nothing ran. */
|
|
103
|
+
skipped?: boolean;
|
|
104
|
+
cover?: {
|
|
105
|
+
key: string;
|
|
106
|
+
url: string;
|
|
107
|
+
existedBefore: boolean;
|
|
108
|
+
verified404: boolean;
|
|
109
|
+
};
|
|
110
|
+
/** Retained revisions of this target that were also deleted (omitted when
|
|
111
|
+
* there were none, or `keepRevisions` was passed). */
|
|
112
|
+
revisions?: Array<{
|
|
113
|
+
key: string;
|
|
114
|
+
url: string;
|
|
115
|
+
existedBefore: boolean;
|
|
116
|
+
verified404: boolean;
|
|
117
|
+
}>;
|
|
118
|
+
}
|
|
119
|
+
/** Delete one share target (page + by default its OG cover) and verify both
|
|
120
|
+
* are gone. Throws on an unverified takedown — never reports success for an
|
|
121
|
+
* object that still resolves. */
|
|
122
|
+
export declare function deleteShare(target: string, opts?: DeleteShareOptions): Promise<DeleteShareResult>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// The delete path for `artifacts share delete` / `artifacts unshare` — an authed DELETE
|
|
2
|
+
// to the Worker, which already implements it (worker-template.ts). Mirrors
|
|
3
|
+
// publish.ts: pure target-resolution logic is exported for tests, the network
|
|
4
|
+
// calls (a status check + a delete) sit behind an injectable DI seam.
|
|
5
|
+
//
|
|
6
|
+
// The Worker's R2 delete is idempotent — DELETE on a key that never existed still
|
|
7
|
+
// returns `{"ok":true}` — so `{"ok":true}` alone is never proof of a takedown.
|
|
8
|
+
// Every delete here is followed by a status check that must observe 404 before
|
|
9
|
+
// the operation is reported as successful.
|
|
10
|
+
import { resolveShareBackend } from './backend.js';
|
|
11
|
+
import { buildShareKey, resolveShareUsername } from './publish.js';
|
|
12
|
+
import { extractShareHttpError, formatShareHttpErrorDetail } from './http-error.js';
|
|
13
|
+
/**
|
|
14
|
+
* Normalize any of the three accepted target forms to the R2 key that publish
|
|
15
|
+
* would have written:
|
|
16
|
+
* - a full share URL: `https://share.getrush.ai/<user>/<slug>`
|
|
17
|
+
* - `<user>/<slug>`
|
|
18
|
+
* - a bare `<slug>` — resolved against the caller's own namespace exactly as
|
|
19
|
+
* `publishToEndpoint` resolves it at publish time (resolveShareUsername +
|
|
20
|
+
* buildShareKey), so a bare slug always targets *your* published page.
|
|
21
|
+
*
|
|
22
|
+
* The URL and `<user>/<slug>` forms are taken as already the exact key a prior
|
|
23
|
+
* publish produced (no re-sanitizing) — only the bare-slug form runs through
|
|
24
|
+
* `buildShareKey`, because that's the one case where the slug hasn't already
|
|
25
|
+
* been normalized by a publish.
|
|
26
|
+
*/
|
|
27
|
+
export async function resolveDeleteTarget(target, opts = {}) {
|
|
28
|
+
const trimmed = target.trim();
|
|
29
|
+
if (!trimmed)
|
|
30
|
+
throw new Error('Share target is empty.');
|
|
31
|
+
let key;
|
|
32
|
+
if (/^https?:\/\//i.test(trimmed)) {
|
|
33
|
+
const url = new URL(trimmed);
|
|
34
|
+
const segments = url.pathname
|
|
35
|
+
.replace(/^\/+|\/+$/g, '')
|
|
36
|
+
.split('/')
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.map(decodeURIComponent);
|
|
39
|
+
if (segments.length < 2) {
|
|
40
|
+
throw new Error(`Not a share page URL (expected .../<user>/<slug>): ${trimmed}`);
|
|
41
|
+
}
|
|
42
|
+
key = segments.slice(0, 2).join('/');
|
|
43
|
+
}
|
|
44
|
+
else if (trimmed.includes('/')) {
|
|
45
|
+
const segments = trimmed.replace(/^\/+|\/+$/g, '').split('/').filter(Boolean);
|
|
46
|
+
if (segments.length !== 2) {
|
|
47
|
+
throw new Error(`Expected <user>/<slug>, got: ${trimmed}`);
|
|
48
|
+
}
|
|
49
|
+
key = segments.join('/');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const username = await resolveShareUsername(opts);
|
|
53
|
+
key = buildShareKey(username, trimmed);
|
|
54
|
+
}
|
|
55
|
+
return { key, coverKey: `${key}.png` };
|
|
56
|
+
}
|
|
57
|
+
async function defaultCheck(url) {
|
|
58
|
+
const res = await fetch(url, { method: 'HEAD' });
|
|
59
|
+
return { status: res.status };
|
|
60
|
+
}
|
|
61
|
+
async function defaultDelete(url, headers) {
|
|
62
|
+
const res = await fetch(url, { method: 'DELETE', headers });
|
|
63
|
+
if (res.ok)
|
|
64
|
+
return { ok: true, status: res.status };
|
|
65
|
+
const body = await res.text().catch(() => undefined);
|
|
66
|
+
return { ok: false, status: res.status, body, retryAfter: res.headers.get('retry-after') ?? undefined };
|
|
67
|
+
}
|
|
68
|
+
async function defaultRevisionsFetch(url) {
|
|
69
|
+
const res = await fetch(url, { headers: { accept: 'application/json' } });
|
|
70
|
+
return { status: res.status, contentType: res.headers.get('content-type') ?? '', body: await res.text() };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* List the R2 keys of a slug's retained revisions via the Worker's
|
|
74
|
+
* `?revisions=json` route (worker-template.ts `renderRevisions`). Best-effort:
|
|
75
|
+
* any failure to reach or parse the route (an endpoint provisioned before
|
|
76
|
+
* revisions existed, a network blip) yields an empty list rather than
|
|
77
|
+
* throwing — purging revisions is a safety improvement on top of the primary
|
|
78
|
+
* delete contract (take the canonical page down), never a reason to fail it.
|
|
79
|
+
*/
|
|
80
|
+
async function listRevisionKeys(endpoint, key, fetchRevisions) {
|
|
81
|
+
try {
|
|
82
|
+
const url = `${endpoint.baseUrl.replace(/\/+$/, '')}/${key}?revisions=json`;
|
|
83
|
+
const res = await fetchRevisions(url);
|
|
84
|
+
if (res.status !== 200 || !/application\/json/i.test(res.contentType))
|
|
85
|
+
return [];
|
|
86
|
+
const data = JSON.parse(res.body);
|
|
87
|
+
if (!Array.isArray(data.revisions))
|
|
88
|
+
return [];
|
|
89
|
+
return data.revisions.map((r) => String(r.key ?? '')).filter(Boolean);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Delete one R2 object behind the share Worker and assert the postcondition.
|
|
97
|
+
* `{"ok":true}` from the Worker is not evidence a page came down — R2 delete is
|
|
98
|
+
* idempotent, so a DELETE on a key that was never there also returns `ok:true`.
|
|
99
|
+
* This checks existence before (so callers can tell "deleted" from "was never
|
|
100
|
+
* there") and re-checks after (so callers can tell "deleted" from "still public").
|
|
101
|
+
*/
|
|
102
|
+
export async function deleteObject(endpoint, key, opts = {}) {
|
|
103
|
+
const url = `${endpoint.baseUrl.replace(/\/+$/, '')}/${key}`;
|
|
104
|
+
const check = opts.checker ?? defaultCheck;
|
|
105
|
+
const del = opts.deleter ?? defaultDelete;
|
|
106
|
+
const before = await check(url);
|
|
107
|
+
const existedBefore = before.status !== 404;
|
|
108
|
+
const r = await del(url, { authorization: `Bearer ${endpoint.token}` });
|
|
109
|
+
if (!r.ok) {
|
|
110
|
+
const detail = formatShareHttpErrorDetail(extractShareHttpError({ status: r.status, body: r.body, retryAfter: r.retryAfter }));
|
|
111
|
+
throw new Error(`Delete failed (${r.status}) for ${url}${detail}. Check the bearer (Phoenix session or WRITE_TOKEN), or that 'artifacts share setup' completed.`);
|
|
112
|
+
}
|
|
113
|
+
const after = await check(url);
|
|
114
|
+
const verified404 = after.status === 404;
|
|
115
|
+
return { key, url, existedBefore, deleted: r.ok, verified404 };
|
|
116
|
+
}
|
|
117
|
+
/** Delete one share target (page + by default its OG cover) and verify both
|
|
118
|
+
* are gone. Throws on an unverified takedown — never reports success for an
|
|
119
|
+
* object that still resolves. */
|
|
120
|
+
export async function deleteShare(target, opts = {}) {
|
|
121
|
+
const backend = resolveShareBackend(opts);
|
|
122
|
+
const githubUser = backend.kind === 'managed'
|
|
123
|
+
? backend.namespace
|
|
124
|
+
: opts.githubUser || backend.namespace || undefined;
|
|
125
|
+
const resolved = await resolveDeleteTarget(target, { githubUser });
|
|
126
|
+
const endpoint = { baseUrl: backend.baseUrl, token: backend.token };
|
|
127
|
+
const page = await deleteObject(endpoint, resolved.key, { deleter: opts.deleter, checker: opts.checker });
|
|
128
|
+
if (!page.existedBefore) {
|
|
129
|
+
if (opts.ifExists) {
|
|
130
|
+
return { key: page.key, url: page.url, existedBefore: false, verified404: page.verified404, skipped: true };
|
|
131
|
+
}
|
|
132
|
+
throw new Error(`Nothing to delete — ${page.url} was already not found. Pass --if-exists to treat this as a no-op instead of an error.`);
|
|
133
|
+
}
|
|
134
|
+
if (!page.verified404) {
|
|
135
|
+
throw new Error(`Delete reported success but ${page.url} still resolves — takedown NOT verified. Retry, or investigate the Worker/R2 directly.`);
|
|
136
|
+
}
|
|
137
|
+
const result = {
|
|
138
|
+
key: page.key,
|
|
139
|
+
url: page.url,
|
|
140
|
+
existedBefore: page.existedBefore,
|
|
141
|
+
verified404: page.verified404,
|
|
142
|
+
};
|
|
143
|
+
if (!opts.keepCover) {
|
|
144
|
+
const cover = await deleteObject(endpoint, resolved.coverKey, { deleter: opts.deleter, checker: opts.checker });
|
|
145
|
+
result.cover = {
|
|
146
|
+
key: cover.key,
|
|
147
|
+
url: cover.url,
|
|
148
|
+
existedBefore: cover.existedBefore,
|
|
149
|
+
verified404: cover.verified404,
|
|
150
|
+
};
|
|
151
|
+
// A missing cover is normal (non-HTML publishes, or --no-cover at publish
|
|
152
|
+
// time never made one) — only a cover that existed and is still up is a bug.
|
|
153
|
+
if (cover.existedBefore && !cover.verified404) {
|
|
154
|
+
throw new Error(`Cover delete reported success but ${cover.url} still resolves — takedown NOT verified. Retry, or pass --keep-cover and delete it manually.`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!opts.keepRevisions) {
|
|
158
|
+
const revisionKeys = await listRevisionKeys(endpoint, resolved.key, opts.fetchRevisions ?? defaultRevisionsFetch);
|
|
159
|
+
if (revisionKeys.length > 0) {
|
|
160
|
+
const revisions = [];
|
|
161
|
+
for (const revisionKey of revisionKeys) {
|
|
162
|
+
const rev = await deleteObject(endpoint, revisionKey, { deleter: opts.deleter, checker: opts.checker });
|
|
163
|
+
revisions.push({ key: rev.key, url: rev.url, existedBefore: rev.existedBefore, verified404: rev.verified404 });
|
|
164
|
+
}
|
|
165
|
+
result.revisions = revisions;
|
|
166
|
+
const stillUp = revisions.filter((r) => r.existedBefore && !r.verified404);
|
|
167
|
+
if (stillUp.length > 0) {
|
|
168
|
+
throw new Error(`Delete reported success but ${stillUp.length} retained revision(s) still resolve — takedown NOT verified. Retry, or pass --keep-revisions and delete them manually.`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/lib/share/delete.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,2EAA2E;AAC3E,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,kFAAkF;AAClF,+EAA+E;AAC/E,+EAA+E;AAC/E,2CAA2C;AAG3C,OAAO,EAAE,mBAAmB,EAAgC,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AA4BpF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAc,EACd,OAA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AAK,CACb,+BAA+B,OAAO,CAAC,MAAM,wHAAwH,CACtK,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make an HTML page self-contained enough to view on share.getrush.ai.
|
|
3
|
+
*
|
|
4
|
+
* Chrome "Save as" (and some renderers) leave `file:///…html#section` TOC
|
|
5
|
+
* links and sibling image paths. Those work on disk and 404 on the share
|
|
6
|
+
* Worker, which only stores the one PUT body. Rewrite same-document file
|
|
7
|
+
* anchors to `#section`, and inline local image files as data URIs.
|
|
8
|
+
*
|
|
9
|
+
* https citations, data: URIs already in the page, and missing files are
|
|
10
|
+
* left alone. This is not a bundler — it only fixes what would otherwise
|
|
11
|
+
* render as a broken page after a single-file publish.
|
|
12
|
+
*/
|
|
13
|
+
/** Skip inlining a sibling that would bloat the page past a reasonable PUT. */
|
|
14
|
+
export declare const MAX_INLINE_BYTES: number;
|
|
15
|
+
/**
|
|
16
|
+
* `href="file:///tmp/page.html#purpose"` → `href="#purpose"`.
|
|
17
|
+
* Bare `file:///tmp/page.html` (no hash) becomes `href="#"`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function rewriteFileAnchors(html: string): string;
|
|
20
|
+
/** Replace local image src/href with a data URI when the file exists next to the page. */
|
|
21
|
+
export declare function inlineLocalAssets(html: string, htmlPath: string): string;
|
|
22
|
+
export declare function prepareShareHtml(html: string, htmlPath: string): string;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make an HTML page self-contained enough to view on share.getrush.ai.
|
|
3
|
+
*
|
|
4
|
+
* Chrome "Save as" (and some renderers) leave `file:///…html#section` TOC
|
|
5
|
+
* links and sibling image paths. Those work on disk and 404 on the share
|
|
6
|
+
* Worker, which only stores the one PUT body. Rewrite same-document file
|
|
7
|
+
* anchors to `#section`, and inline local image files as data URIs.
|
|
8
|
+
*
|
|
9
|
+
* https citations, data: URIs already in the page, and missing files are
|
|
10
|
+
* left alone. This is not a bundler — it only fixes what would otherwise
|
|
11
|
+
* render as a broken page after a single-file publish.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
|
+
import { dirname, extname, resolve } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
/** Skip inlining a sibling that would bloat the page past a reasonable PUT. */
|
|
17
|
+
export const MAX_INLINE_BYTES = 4 * 1024 * 1024;
|
|
18
|
+
const IMAGE_MIME = {
|
|
19
|
+
'.png': 'image/png',
|
|
20
|
+
'.jpg': 'image/jpeg',
|
|
21
|
+
'.jpeg': 'image/jpeg',
|
|
22
|
+
'.gif': 'image/gif',
|
|
23
|
+
'.webp': 'image/webp',
|
|
24
|
+
'.svg': 'image/svg+xml',
|
|
25
|
+
'.ico': 'image/x-icon',
|
|
26
|
+
'.avif': 'image/avif',
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* `href="file:///tmp/page.html#purpose"` → `href="#purpose"`.
|
|
30
|
+
* Bare `file:///tmp/page.html` (no hash) becomes `href="#"`.
|
|
31
|
+
*/
|
|
32
|
+
export function rewriteFileAnchors(html) {
|
|
33
|
+
return html.replace(/\b(href\s*=\s*["'])file:\/\/[^"'#]*(#[^"']*)?(["'])/gi, (_m, attr, hash, quote) => `${attr}${hash ?? '#'}${quote}`);
|
|
34
|
+
}
|
|
35
|
+
function isRemoteOrSpecial(url) {
|
|
36
|
+
return (url.startsWith('data:') ||
|
|
37
|
+
url.startsWith('http://') ||
|
|
38
|
+
url.startsWith('https://') ||
|
|
39
|
+
url.startsWith('//') ||
|
|
40
|
+
url.startsWith('#') ||
|
|
41
|
+
url.startsWith('mailto:') ||
|
|
42
|
+
url.startsWith('javascript:') ||
|
|
43
|
+
url.startsWith('agents:'));
|
|
44
|
+
}
|
|
45
|
+
function localImagePath(url, htmlDir) {
|
|
46
|
+
if (!url || isRemoteOrSpecial(url))
|
|
47
|
+
return null;
|
|
48
|
+
const withoutHash = url.split('#')[0] ?? url;
|
|
49
|
+
let fsPath;
|
|
50
|
+
if (withoutHash.startsWith('file:')) {
|
|
51
|
+
try {
|
|
52
|
+
fsPath = fileURLToPath(withoutHash);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
fsPath = resolve(htmlDir, withoutHash);
|
|
60
|
+
}
|
|
61
|
+
if (!existsSync(fsPath))
|
|
62
|
+
return null;
|
|
63
|
+
const mime = IMAGE_MIME[extname(fsPath).toLowerCase()];
|
|
64
|
+
if (!mime)
|
|
65
|
+
return null;
|
|
66
|
+
return { path: fsPath, mime };
|
|
67
|
+
}
|
|
68
|
+
/** Replace local image src/href with a data URI when the file exists next to the page. */
|
|
69
|
+
export function inlineLocalAssets(html, htmlPath) {
|
|
70
|
+
const dir = dirname(htmlPath);
|
|
71
|
+
return html.replace(/\b((?:src|href)\s*=\s*["'])([^"']+)(["'])/gi, (full, pre, url, post) => {
|
|
72
|
+
const local = localImagePath(url, dir);
|
|
73
|
+
if (!local)
|
|
74
|
+
return full;
|
|
75
|
+
try {
|
|
76
|
+
const buf = readFileSync(local.path);
|
|
77
|
+
if (buf.length > MAX_INLINE_BYTES)
|
|
78
|
+
return full;
|
|
79
|
+
return `${pre}data:${local.mime};base64,${buf.toString('base64')}${post}`;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return full;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export function prepareShareHtml(html, htmlPath) {
|
|
87
|
+
return inlineLocalAssets(rewriteFileAnchors(html), htmlPath);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../../src/lib/share/html.ts"],"names":[],"mappings":"AAA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,OAAO,IAAI,CAAC;YAC/C,OAAO,GAAG,GAAG,QAAQ,KAAK,CAAC,IAAI,WAAW,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC;QAC5E,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,QAAgB;IAC7D,OAAO,iBAAiB,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE bounded extractor for the share Worker's error responses.
|
|
3
|
+
*
|
|
4
|
+
* Every share HTTP call (publish PUT, list/revisions GET, delete DELETE)
|
|
5
|
+
* previously threw on `!ok` with only the status code, discarding the JSON error
|
|
6
|
+
* body the Worker actually returns (`{"error":"…"}` for a 400/413/429, plus a
|
|
7
|
+
* `Retry-After` on a 429). The result: a rate-limited or quota-exceeded publish
|
|
8
|
+
* surfaced as a bare "Publish failed (429)" with no reason. This pulls the
|
|
9
|
+
* server's own `error` string and preserves the status + `Retry-After`, so the
|
|
10
|
+
* user sees why.
|
|
11
|
+
*
|
|
12
|
+
* Bounded and safe by construction: it parses at most {@link MAX_ERROR_BODY_BYTES}
|
|
13
|
+
* of the body, only lifts a string `error` field, caps its length, and NEVER
|
|
14
|
+
* surfaces an arbitrary body — a non-JSON or oversized body yields no message,
|
|
15
|
+
* so an HTML error page or a huge payload can't leak into a CLI error string.
|
|
16
|
+
*/
|
|
17
|
+
/** The raw pieces a caller's fetch wrapper hands in — status plus the (optional)
|
|
18
|
+
* response body text and `Retry-After` header value. */
|
|
19
|
+
export interface ShareHttpResponse {
|
|
20
|
+
status: number;
|
|
21
|
+
/** The response body text, when the caller read it (only on `!ok` paths). */
|
|
22
|
+
body?: string;
|
|
23
|
+
/** The `Retry-After` header value, when present (a 429 carries it). */
|
|
24
|
+
retryAfter?: string;
|
|
25
|
+
}
|
|
26
|
+
/** The extracted, bounded error facts. `serverMessage` is present only when the
|
|
27
|
+
* body parsed as JSON carrying a non-empty string `error`. */
|
|
28
|
+
export interface ShareHttpError {
|
|
29
|
+
status: number;
|
|
30
|
+
serverMessage?: string;
|
|
31
|
+
retryAfter?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Never parse more than this many chars of a body — a legitimate `{"error":"…"}`
|
|
34
|
+
* is tiny; a larger body is an HTML page or noise we deliberately don't surface. */
|
|
35
|
+
export declare const MAX_ERROR_BODY_BYTES = 4096;
|
|
36
|
+
/** Cap the surfaced message so even a pathological (but valid-JSON) `error`
|
|
37
|
+
* string can't blow up the CLI output. */
|
|
38
|
+
export declare const MAX_ERROR_MESSAGE_CHARS = 300;
|
|
39
|
+
/**
|
|
40
|
+
* Extract the bounded error facts from a share Worker response. Pulls a string
|
|
41
|
+
* `error` field from a small JSON body, preserves status + `Retry-After`, and
|
|
42
|
+
* never surfaces an arbitrary body.
|
|
43
|
+
*/
|
|
44
|
+
export declare function extractShareHttpError(res: ShareHttpResponse): ShareHttpError;
|
|
45
|
+
/**
|
|
46
|
+
* A one-line suffix summarizing the server's structured error, or `''` when the
|
|
47
|
+
* response carried nothing extractable. Appended after the status-bearing prefix
|
|
48
|
+
* a caller already builds, e.g.:
|
|
49
|
+
* `Publish failed (429) for <url>` + `formatShareHttpErrorDetail(err)`
|
|
50
|
+
* → `Publish failed (429) for <url> — rate limit exceeded; retry after 37s`
|
|
51
|
+
*/
|
|
52
|
+
export declare function formatShareHttpErrorDetail(err: ShareHttpError): string;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE bounded extractor for the share Worker's error responses.
|
|
3
|
+
*
|
|
4
|
+
* Every share HTTP call (publish PUT, list/revisions GET, delete DELETE)
|
|
5
|
+
* previously threw on `!ok` with only the status code, discarding the JSON error
|
|
6
|
+
* body the Worker actually returns (`{"error":"…"}` for a 400/413/429, plus a
|
|
7
|
+
* `Retry-After` on a 429). The result: a rate-limited or quota-exceeded publish
|
|
8
|
+
* surfaced as a bare "Publish failed (429)" with no reason. This pulls the
|
|
9
|
+
* server's own `error` string and preserves the status + `Retry-After`, so the
|
|
10
|
+
* user sees why.
|
|
11
|
+
*
|
|
12
|
+
* Bounded and safe by construction: it parses at most {@link MAX_ERROR_BODY_BYTES}
|
|
13
|
+
* of the body, only lifts a string `error` field, caps its length, and NEVER
|
|
14
|
+
* surfaces an arbitrary body — a non-JSON or oversized body yields no message,
|
|
15
|
+
* so an HTML error page or a huge payload can't leak into a CLI error string.
|
|
16
|
+
*/
|
|
17
|
+
/** Never parse more than this many chars of a body — a legitimate `{"error":"…"}`
|
|
18
|
+
* is tiny; a larger body is an HTML page or noise we deliberately don't surface. */
|
|
19
|
+
export const MAX_ERROR_BODY_BYTES = 4096;
|
|
20
|
+
/** Cap the surfaced message so even a pathological (but valid-JSON) `error`
|
|
21
|
+
* string can't blow up the CLI output. */
|
|
22
|
+
export const MAX_ERROR_MESSAGE_CHARS = 300;
|
|
23
|
+
/**
|
|
24
|
+
* Extract the bounded error facts from a share Worker response. Pulls a string
|
|
25
|
+
* `error` field from a small JSON body, preserves status + `Retry-After`, and
|
|
26
|
+
* never surfaces an arbitrary body.
|
|
27
|
+
*/
|
|
28
|
+
export function extractShareHttpError(res) {
|
|
29
|
+
const out = { status: res.status };
|
|
30
|
+
const retryAfter = res.retryAfter?.trim();
|
|
31
|
+
if (retryAfter)
|
|
32
|
+
out.retryAfter = retryAfter;
|
|
33
|
+
const raw = res.body;
|
|
34
|
+
if (raw && raw.length <= MAX_ERROR_BODY_BYTES) {
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
38
|
+
const err = parsed.error;
|
|
39
|
+
if (typeof err === 'string' && err.trim()) {
|
|
40
|
+
out.serverMessage = err.trim().slice(0, MAX_ERROR_MESSAGE_CHARS);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Not JSON (an HTML error page, a proxy body, truncated bytes) — deliberately
|
|
46
|
+
// surface nothing rather than dump an arbitrary body into the CLI error.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A one-line suffix summarizing the server's structured error, or `''` when the
|
|
53
|
+
* response carried nothing extractable. Appended after the status-bearing prefix
|
|
54
|
+
* a caller already builds, e.g.:
|
|
55
|
+
* `Publish failed (429) for <url>` + `formatShareHttpErrorDetail(err)`
|
|
56
|
+
* → `Publish failed (429) for <url> — rate limit exceeded; retry after 37s`
|
|
57
|
+
*/
|
|
58
|
+
export function formatShareHttpErrorDetail(err) {
|
|
59
|
+
const parts = [];
|
|
60
|
+
if (err.serverMessage)
|
|
61
|
+
parts.push(err.serverMessage);
|
|
62
|
+
if (err.retryAfter)
|
|
63
|
+
parts.push(`retry after ${err.retryAfter}s`);
|
|
64
|
+
return parts.length ? ` — ${parts.join('; ')}` : '';
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=http-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-error.js","sourceRoot":"","sources":["../../../src/lib/share/http-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAoBH;oFACoF;AACpF,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAEzC;0CAC0C;AAC1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAsB;IAC1D,MAAM,GAAG,GAAmB,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;IACnD,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE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
2
|
+
* Open Graph / Twitter card meta for a shared HTML page.
|
|
3
|
+
*
|
|
4
|
+
* `deriveMeta` pulls a title + description out of the document (its `<title>`/`<h1>`
|
|
5
|
+
* and first real paragraph or existing `<meta name=description>`); `injectOgMeta`
|
|
6
|
+
* splices the social tags into `<head>` (idempotent — it strips any tags we
|
|
7
|
+
* previously added before re-inserting). Pure string work so it's unit-testable
|
|
8
|
+
* without a browser or network.
|
|
9
|
+
*/
|
|
10
|
+
export interface OgFields {
|
|
11
|
+
title: string;
|
|
12
|
+
description: string;
|
|
13
|
+
imageUrl: string;
|
|
14
|
+
pageUrl: string;
|
|
15
|
+
/** Actual pixel dimensions of the served image (defaults to the 1200×630 OG card). */
|
|
16
|
+
imageWidth?: number;
|
|
17
|
+
imageHeight?: number;
|
|
18
|
+
}
|
|
19
|
+
/** Pull a sensible title + description out of a plan/document's HTML. */
|
|
20
|
+
export declare function deriveMeta(html: string, fallbackTitle?: string): {
|
|
21
|
+
title: string;
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
/** Splice OG + Twitter tags into `<head>` (or prepend if there's no head). Idempotent. */
|
|
25
|
+
export declare function injectOgMeta(html: string, f: OgFields): string;
|