hushdrop-mcp 0.3.3 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -27
- package/SKILL.md +173 -5
- package/brand/badge.html +2 -2
- package/brand/download-page.html +1 -1
- package/brand/gate.html +1 -1
- package/comment-widget.mjs +23 -0
- package/drop.mjs +1062 -59
- package/mcp.mjs +724 -9
- package/package.json +6 -2
- package/protect.mjs +26 -0
- package/read-beacon.mjs +17 -0
- package/site.mjs +60 -0
package/drop.mjs
CHANGED
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
* Serving is a dumb Vercel rewrite/edge-proxy (<domain>/<slug> → blob). No deploy per file.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { readFile, writeFile, mkdir, mkdtemp, readdir, rm } from "node:fs/promises";
|
|
18
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
17
|
+
import { readFile, writeFile, mkdir, mkdtemp, readdir, rm, stat } from "node:fs/promises";
|
|
18
|
+
import { existsSync, readFileSync, statSync, mkdirSync, writeFileSync } from "node:fs";
|
|
19
19
|
import { homedir, tmpdir } from "node:os";
|
|
20
20
|
import { join, dirname, basename, extname } from "node:path";
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
22
22
|
import { parseArgs } from "node:util";
|
|
23
23
|
import { spawn, spawnSync } from "node:child_process";
|
|
24
|
+
import { collectSiteFiles, makeVerifier } from "./site.mjs";
|
|
24
25
|
|
|
25
26
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
26
27
|
const DROP_HOME = join(homedir(), ".hushdrop");
|
|
@@ -59,6 +60,38 @@ function loadConfig() {
|
|
|
59
60
|
const CONFIG = loadConfig();
|
|
60
61
|
const DOMAIN = CONFIG.domain;
|
|
61
62
|
const ORIGIN = CONFIG.origin;
|
|
63
|
+
|
|
64
|
+
// ---------- client context (anonymous product analytics) ----------
|
|
65
|
+
// Sent as headers on hushdrop API calls so the hosted service can tell which client,
|
|
66
|
+
// version, OS and AI agent published. A random install id (no personal data) lets
|
|
67
|
+
// anonymous publishes from the same machine be counted as one user, and joins them to
|
|
68
|
+
// the account after `hush login`. Never sent to self-hosted deployments' Blob uploads.
|
|
69
|
+
const CLI_VERSION = (() => { try { return JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8")).version || "dev"; } catch { return "dev"; } })();
|
|
70
|
+
function installId() {
|
|
71
|
+
const f = join(DROP_HOME, "install-id");
|
|
72
|
+
try { const v = readFileSync(f, "utf8").trim(); if (/^[a-f0-9-]{36}$/.test(v)) return v; } catch {}
|
|
73
|
+
const v = globalThis.crypto.randomUUID();
|
|
74
|
+
try { mkdirSync(DROP_HOME, { recursive: true }); writeFileSync(f, v); } catch {}
|
|
75
|
+
return v;
|
|
76
|
+
}
|
|
77
|
+
function detectAgent(env = process.env) {
|
|
78
|
+
if (env.CLAUDECODE || env.CLAUDE_CODE_ENTRYPOINT) return "claude-code";
|
|
79
|
+
if (env.CURSOR_TRACE_ID || env.CURSOR_AGENT) return "cursor";
|
|
80
|
+
if (env.CODEX_SANDBOX || env.CODEX_HOME || env.CODEX_MANAGED_BY_NPM) return "codex";
|
|
81
|
+
if (env.GEMINI_CLI) return "gemini-cli";
|
|
82
|
+
if (env.OPENCODE || env.OPENCODE_BIN) return "opencode";
|
|
83
|
+
if (env.WINDSURF_EXTENSION || env.CODEIUM_API_KEY) return "windsurf";
|
|
84
|
+
if (env.AIDER_MODEL || env.AIDER_CHAT_HISTORY_FILE) return "aider";
|
|
85
|
+
if (env.ZED_TERM) return "zed";
|
|
86
|
+
if (env.TERM_PROGRAM === "vscode") return "vscode";
|
|
87
|
+
return "terminal";
|
|
88
|
+
}
|
|
89
|
+
const CLIENT_HEADERS = (() => {
|
|
90
|
+
const h = { "x-drop-client": process.env.HUSH_CLIENT === "mcp" ? "mcp-local" : "cli", "x-drop-client-version": CLI_VERSION, "x-drop-os": `${process.platform}-${process.arch}`, "x-drop-agent": detectAgent(), "x-drop-node": process.versions.node };
|
|
91
|
+
if (process.env.CI) h["x-drop-ci"] = "1";
|
|
92
|
+
if (!process.env.HUSH_NO_TELEMETRY && !process.env.DO_NOT_TRACK) h["x-drop-install-id"] = installId();
|
|
93
|
+
return h;
|
|
94
|
+
})();
|
|
62
95
|
const BRAND = CONFIG.brandDir;
|
|
63
96
|
|
|
64
97
|
// ---------- helpers ----------
|
|
@@ -84,6 +117,10 @@ function mimeFor(ext) {
|
|
|
84
117
|
".mjs": "application/javascript; charset=utf-8", ".map": "application/json",
|
|
85
118
|
".ico": "image/x-icon", ".woff": "font/woff", ".woff2": "font/woff2", ".ttf": "font/ttf",
|
|
86
119
|
".wasm": "application/wasm", ".xml": "application/xml", ".webmanifest": "application/manifest+json",
|
|
120
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
121
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
122
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
123
|
+
".webm": "video/webm", ".mp3": "audio/mpeg", ".wav": "audio/wav",
|
|
87
124
|
};
|
|
88
125
|
return m[ext.toLowerCase()] || "application/octet-stream";
|
|
89
126
|
}
|
|
@@ -103,6 +140,12 @@ const rand = (n) => {
|
|
|
103
140
|
return s;
|
|
104
141
|
};
|
|
105
142
|
|
|
143
|
+
const randomHex = (n) => {
|
|
144
|
+
const buf = new Uint8Array(n);
|
|
145
|
+
(globalThis.crypto || require("node:crypto").webcrypto).getRandomValues(buf);
|
|
146
|
+
return [...buf].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
147
|
+
};
|
|
148
|
+
|
|
106
149
|
const ADJ = ["amber","brisk","clever","copper","dusky","ember","fleet","golden","hazel","ivory","jolly","keen","lunar","mellow","noble","opal","prime","quartz","rapid","silver","tidal","umber","vivid","witty","zesty","bold","crisp","swift","sunny","quiet"];
|
|
107
150
|
const NOUN = ["canyon","river","harbor","meadow","summit","orbit","cedar","falcon","lantern","compass","beacon","pebble","willow","cobalt","cypress","drift","ember","glacier","horizon","ridge","comet","delta","fjord","grove","atlas"];
|
|
108
151
|
function genPassword() {
|
|
@@ -259,13 +302,33 @@ function injectBody(html, snippet) {
|
|
|
259
302
|
return `${html}\n${snippet}`;
|
|
260
303
|
}
|
|
261
304
|
|
|
262
|
-
|
|
305
|
+
// Pro and Team drops on hushdrop.dev carry no "Shared with Hushdrop" badge. Best effort:
|
|
306
|
+
// if the plan can't be read, the server still strips it from unlocked pages.
|
|
307
|
+
async function paidSpace() {
|
|
308
|
+
const key = getApiKey(); if (!key) return false;
|
|
309
|
+
const t = String(opts.to || activeSpace() || "").replace(/^@/, "").split("/")[0];
|
|
310
|
+
try {
|
|
311
|
+
const r = await fetch(`${ORIGIN}/api/billing${t ? `?team=${encodeURIComponent(t)}` : ""}`, { headers: { ...CLIENT_HEADERS, authorization: `Bearer ${key}` }, signal: AbortSignal.timeout(4000) });
|
|
312
|
+
if (!r.ok) return false;
|
|
313
|
+
const d = await r.json();
|
|
314
|
+
return d.plan === "pro" || d.plan === "team";
|
|
315
|
+
} catch { return false; }
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function brandHtml(html, { title, url, logoUri, ogImage, expiresAt, noBadge }) {
|
|
263
319
|
const meta = await buildMeta({ title, url, ogImage });
|
|
264
320
|
let badge = await readFile(join(BRAND, "badge.html"), "utf8");
|
|
265
|
-
badge = applyBrandTokens(badge).replace(/__DROP_LOGO__/g, logoUri)
|
|
321
|
+
badge = applyBrandTokens(badge).replace(/__DROP_LOGO__/g, logoUri)
|
|
322
|
+
.replace(/__DROP_BADGE_TEXT__/g, DOMAIN === "hushdrop.dev" ? "Shared with Hushdrop" : DOMAIN).replace(/__DROP_DOMAIN__/g, DOMAIN);
|
|
266
323
|
html = injectHead(html, meta);
|
|
267
|
-
html = injectBody(html, badge);
|
|
324
|
+
if (!noBadge) html = injectBody(html, badge);
|
|
268
325
|
if (expiresAt) html = injectBody(html, expiryGuard(expiresAt));
|
|
326
|
+
// --comments: bake the pinned-comment widget in before encryption so it survives unlock.
|
|
327
|
+
if (opts.comments) html = injectBody(html, (await import("./comment-widget.mjs")).commentWidget());
|
|
328
|
+
// View-only: locked drops rewrite their document on unlock, so bake the deterrents in now.
|
|
329
|
+
if (opts.protect) html = injectBody(html, (await import("./protect.mjs")).protectSnippet());
|
|
330
|
+
// Hosted drops: reading-depth beacon (time on page, scroll reach) for the owner's stats.
|
|
331
|
+
if (getApiKey() && !opts.managed) html = injectBody(html, (await import("./read-beacon.mjs")).readBeacon());
|
|
269
332
|
return html;
|
|
270
333
|
}
|
|
271
334
|
|
|
@@ -322,8 +385,9 @@ async function upload(key, body, contentType, token) {
|
|
|
322
385
|
// managed endpoint. No token, no Vercel setup — the server assigns a `u/` slug.
|
|
323
386
|
async function managedPublish(body, contentType, { burn } = {}) {
|
|
324
387
|
const endpoint = `${ORIGIN}/api/publish`;
|
|
325
|
-
const headers = { "content-type": "application/octet-stream", "x-drop-content-type": contentType };
|
|
388
|
+
const headers = { ...CLIENT_HEADERS, "content-type": "application/octet-stream", "x-drop-content-type": contentType };
|
|
326
389
|
if (burn) headers["x-drop-burn"] = "1";
|
|
390
|
+
if (opts.notify) headers["x-drop-owner-email"] = opts.notify;
|
|
327
391
|
let r;
|
|
328
392
|
try {
|
|
329
393
|
r = await fetch(endpoint, { method: "POST", headers, body });
|
|
@@ -334,17 +398,62 @@ async function managedPublish(body, contentType, { burn } = {}) {
|
|
|
334
398
|
|
|
335
399
|
// Hosted (logged-in free tier) publish: same client-side branded/encrypted bytes, but
|
|
336
400
|
// authenticated with the API key so the drop lands persistently at <handle>/<slug>.
|
|
337
|
-
|
|
401
|
+
// Over the serverless body limit (~4.5 MB): upload straight to Blob with a short-lived
|
|
402
|
+
// client token from /api/upload, then finalize. Free up to 90 MB, Pro up to 2 GB.
|
|
403
|
+
const DIRECT_OVER = 4 * 1024 * 1024;
|
|
404
|
+
async function directHostedPublish(body, contentType, slug, locked, to = opts.to || activeSpace()) {
|
|
338
405
|
const key = getApiKey();
|
|
339
|
-
const
|
|
406
|
+
const [toHandle, toSlug] = String(to || "").replace(/^@/, "").split("/");
|
|
407
|
+
if (toSlug) slug = toSlug;
|
|
408
|
+
const call = async (payload) => {
|
|
409
|
+
const r = await fetch(`${ORIGIN}/api/upload`, { method: "POST", headers: { ...CLIENT_HEADERS, authorization: `Bearer ${key}`, "content-type": "application/json" }, body: JSON.stringify(payload) });
|
|
410
|
+
let d = {}; try { d = await r.json(); } catch {}
|
|
411
|
+
if (r.status === 402 && d.paywall) throw { paywall: d };
|
|
412
|
+
if (!r.ok) die(`upload failed: ${d.error || r.status}${d.upgrade ? ` (${d.upgrade})` : ""}`);
|
|
413
|
+
return d;
|
|
414
|
+
};
|
|
415
|
+
let start;
|
|
416
|
+
try { start = await call({ step: "start", slug, content_type: contentType, size: body.length, to: toHandle || undefined }); }
|
|
417
|
+
catch (e) {
|
|
418
|
+
if (!e?.paywall || directHostedPublish.retried) throw e;
|
|
419
|
+
directHostedPublish.retried = true;
|
|
420
|
+
return onPaywall(e.paywall, () => directHostedPublish(body, contentType, slug, locked, to));
|
|
421
|
+
}
|
|
422
|
+
await loadBlob();
|
|
423
|
+
const { put } = await import("@vercel/blob/client");
|
|
424
|
+
if (!JSON_OUT) process.stderr.write(` uploading ${Math.round(body.length / 1048576)} MB directly to storage…\n`);
|
|
425
|
+
await put(start.pathname, body, { access: "public", token: start.token, contentType, multipart: body.length > 50 * 1024 * 1024 });
|
|
426
|
+
return call({ step: "finish", slug: start.slug, pathname: start.pathname, content_type: contentType, locked: !!locked, to: toHandle || undefined });
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
async function hostedPublish(body, contentType, slug, locked, emailGate, to = opts.to || activeSpace()) {
|
|
430
|
+
if (body.length > DIRECT_OVER) {
|
|
431
|
+
const m = await directHostedPublish(body, contentType, slug, locked, to);
|
|
432
|
+
if (emailGate) await patchSite(m.slug, { email_gate: String(emailGate).replace(/^@/, "").toLowerCase() });
|
|
433
|
+
return m;
|
|
434
|
+
}
|
|
435
|
+
const key = getApiKey();
|
|
436
|
+
const headers = { ...CLIENT_HEADERS, "content-type": "application/octet-stream", "x-drop-content-type": contentType, authorization: `Bearer ${key}` };
|
|
437
|
+
// --to <owner>[/<slug>]: publish into a space you're on the team of, or update a drop
|
|
438
|
+
// someone made you an editor of.
|
|
439
|
+
const [toHandle, toSlug] = String(to || "").replace(/^@/, "").split("/");
|
|
440
|
+
if (toHandle) headers["x-drop-to"] = toHandle;
|
|
441
|
+
if (toSlug) slug = toSlug;
|
|
340
442
|
if (slug) headers["x-drop-slug"] = slug;
|
|
341
443
|
if (locked) headers["x-drop-locked"] = "1";
|
|
342
444
|
if (emailGate) headers["x-drop-email-gate"] = String(emailGate).replace(/^@/, "").toLowerCase();
|
|
343
445
|
let r;
|
|
344
446
|
try { r = await fetch(`${ORIGIN}/api/publish`, { method: "POST", headers, body }); }
|
|
345
447
|
catch (e) { die(`hosted publish failed: ${e.message}`); }
|
|
448
|
+
if (r.status === 402 && !hostedPublish.retried) {
|
|
449
|
+
let d = {}; try { d = await r.json(); } catch {}
|
|
450
|
+
if (d.paywall) { hostedPublish.retried = true; return onPaywall(d, () => hostedPublish(body, contentType, slug, locked, emailGate, to)); }
|
|
451
|
+
die(`hosted publish failed: ${d.error || r.status}`);
|
|
452
|
+
}
|
|
346
453
|
if (!r.ok) { let m; try { m = (await r.json()).error; } catch {} die(`hosted publish failed: ${m || r.status}`); }
|
|
347
|
-
|
|
454
|
+
const out = await r.json();
|
|
455
|
+
if (out.plan_notice && !JSON_OUT) console.error(` \x1b[33m●\x1b[0m ${out.plan_notice}`);
|
|
456
|
+
return out;
|
|
348
457
|
}
|
|
349
458
|
|
|
350
459
|
// Import an npm dep, auto-installing into the skill dir on first use (gitignored).
|
|
@@ -359,8 +468,29 @@ async function ensureDep(name) {
|
|
|
359
468
|
}
|
|
360
469
|
|
|
361
470
|
// ---------- commands ----------
|
|
471
|
+
// ---------- Claude artifacts ----------
|
|
472
|
+
// The Artifact tool's `read` saves a claude.ai artifact as a file whose authored page sits
|
|
473
|
+
// inside a viewer skeleton: `<!doctype html><html><head>…</head><body>\n<!doctype html>…</html>\n</body></html>`.
|
|
474
|
+
// Unwrap only when the outer body holds a complete inner document; a page authored as a
|
|
475
|
+
// fragment has a single doctype and is already the whole document, so it's left alone.
|
|
476
|
+
function unwrapClaudeArtifact(html) {
|
|
477
|
+
const m = html.match(/^\s*<!doctype html>\s*<html[^>]*>\s*<head>[\s\S]*?<\/head>\s*<body[^>]*>\s*(<!doctype html>[\s\S]*<\/html>)\s*<\/body>\s*<\/html>\s*$/i);
|
|
478
|
+
return m ? { html: m[1], unwrapped: true } : { html, unwrapped: false };
|
|
479
|
+
}
|
|
480
|
+
function htmlTitle(html) {
|
|
481
|
+
const m = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
|
|
482
|
+
if (!m) return null;
|
|
483
|
+
const t = m[1].replace(/<[^>]+>/g, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/\s+/g, " ").trim();
|
|
484
|
+
return t || null;
|
|
485
|
+
}
|
|
486
|
+
const isClaudeArtifactUrl = (s) => /^https?:\/\/(www\.)?claude\.ai\/(code\/)?artifact\//i.test(s || "");
|
|
487
|
+
const CLAUDE_ARTIFACT_HINT = "claude.ai artifacts are private pages and can't be fetched by URL.\n" +
|
|
488
|
+
" Agents: if you wrote it this session, hush the local .html you published. Otherwise read it with\n" +
|
|
489
|
+
" the Artifact tool (action: \"read\") and run: hush <the saved artifact-*.html path>";
|
|
490
|
+
|
|
362
491
|
async function cmdDrop(file, opts) {
|
|
363
492
|
if (!file) die("usage: hush <file> [-p password] [-s slug] [--page] [--no-lock]");
|
|
493
|
+
if (isClaudeArtifactUrl(file)) die(CLAUDE_ARTIFACT_HINT);
|
|
364
494
|
if (!existsSync(file)) die(`no such file: ${file}`);
|
|
365
495
|
|
|
366
496
|
const ext = extname(file).toLowerCase();
|
|
@@ -382,55 +512,44 @@ async function cmdDrop(file, opts) {
|
|
|
382
512
|
const logoUri = await dataUri(join(BRAND, "logo-white.png"));
|
|
383
513
|
const faviconUri = await dataUri(join(BRAND, "favicon.png"));
|
|
384
514
|
const ogImage = `${ORIGIN}/_brand/og.png`; // optional; harmless if absent
|
|
385
|
-
const stat = (await readFile(file)).length;
|
|
386
515
|
const expiresAt = parseExpiry(opts.expire);
|
|
387
516
|
if (opts.expire && !expiresAt) die(`bad --expire value: ${opts.expire} (use 7d, 24h, 30m, 2w, or a date)`);
|
|
388
517
|
|
|
518
|
+
// folder OR zip → whole static site under <slug>/ (handled before any readFile,
|
|
519
|
+
// since readFile on a directory throws). Self-host only.
|
|
520
|
+
const isSite = statSync(file).isDirectory() || ext === ".zip";
|
|
521
|
+
if (isSite) {
|
|
522
|
+
if (mode === "managed" || mode === "hosted")
|
|
523
|
+
die(`the ${mode} tier supports HTML/markdown only. Self-host ('hush deploy') for files, --page, and sites.`);
|
|
524
|
+
if (!token) die("sites need self-host: run 'hush deploy' (or 'hush setup --token …') first.");
|
|
525
|
+
return uploadSite(file, opts, { token, logoUri, ogImage, expiresAt });
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const stat = (await readFile(file)).length;
|
|
529
|
+
|
|
530
|
+
// Signed in, no self-host token: raw files (PDF, images, Office, media) go to your hosted
|
|
531
|
+
// space via a direct upload, at /<handle>/<slug>. Not encrypted: protection is the link.
|
|
532
|
+
const HOSTED_FILE = [".pdf", ".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".mp4", ".webm", ".mp3", ".wav", ".docx", ".pptx", ".xlsx", ".txt", ".zip"];
|
|
533
|
+
if (mode === "hosted" && !isHtml && !opts.page && HOSTED_FILE.includes(ext)) {
|
|
534
|
+
const fslug = (opts.slug || slugify(file)) + "-" + rand(4);
|
|
535
|
+
const m = await directHostedPublish(await readFile(file), mimeFor(ext).split(";")[0], fslug, false);
|
|
536
|
+
if (JSON_OUT) return console.log(JSON.stringify({ ...m, type: "file" }));
|
|
537
|
+
return report({ url: m.url, password: null, locked: false, extra: `hosted file · ${Math.round(m.size / 1024)} KB · not encrypted (the link is the key)` });
|
|
538
|
+
}
|
|
389
539
|
if ((mode === "managed" || mode === "hosted") && (opts.page || !isHtml)) die(`the ${mode} tier supports HTML/markdown only. Self-host ('hush deploy') for files, --page, and zip sites.`);
|
|
390
540
|
|
|
391
541
|
const manifest = await loadManifest();
|
|
392
542
|
const now = new Date().toISOString();
|
|
393
543
|
|
|
394
|
-
// multi-file static site from a zip → uploaded under <slug>/, served at <slug>/
|
|
395
|
-
if (ext === ".zip") {
|
|
396
|
-
const { default: AdmZip } = await ensureDep("adm-zip");
|
|
397
|
-
const slug = opts.slug || slugify(file) + "-" + rand(4);
|
|
398
|
-
const entries = new AdmZip(file).getEntries().filter((e) => !e.isDirectory);
|
|
399
|
-
if (!entries.length) die("empty zip");
|
|
400
|
-
const indexEntry = entries
|
|
401
|
-
.filter((e) => /(^|\/)index\.html?$/i.test(e.entryName))
|
|
402
|
-
.sort((a, b) => a.entryName.split("/").length - b.entryName.split("/").length)[0];
|
|
403
|
-
if (!indexEntry) die("no index.html found in the zip");
|
|
404
|
-
// strip a single wrapping top-level folder if present (e.g. dist/)
|
|
405
|
-
const top = indexEntry.entryName.includes("/") ? indexEntry.entryName.slice(0, indexEntry.entryName.indexOf("/") + 1) : "";
|
|
406
|
-
let total = 0, count = 0;
|
|
407
|
-
for (const e of entries) {
|
|
408
|
-
const rel = top && e.entryName.startsWith(top) ? e.entryName.slice(top.length) : e.entryName;
|
|
409
|
-
if (!rel || rel.startsWith("..")) continue;
|
|
410
|
-
let data = e.getData();
|
|
411
|
-
if (/^index\.html?$/i.test(rel)) {
|
|
412
|
-
let html = data.toString("utf8");
|
|
413
|
-
// <base> so relative asset links resolve under /<slug>/ regardless of trailing slash
|
|
414
|
-
if (/<head[^>]*>/i.test(html)) html = html.replace(/<head([^>]*)>/i, `<head$1><base href="/${slug}/">`);
|
|
415
|
-
else html = `<base href="/${slug}/">\n` + html;
|
|
416
|
-
html = await brandHtml(html, { title: opts.title || basename(file, ext), url: `${ORIGIN}/${slug}/`, logoUri, ogImage, expiresAt });
|
|
417
|
-
data = Buffer.from(html, "utf8");
|
|
418
|
-
}
|
|
419
|
-
await upload(`${slug}/${rel}`, data, mimeFor(extname(rel)), token);
|
|
420
|
-
total += data.length; count++;
|
|
421
|
-
}
|
|
422
|
-
const url = `${ORIGIN}/${slug}/`;
|
|
423
|
-
manifest.unshift({ slug, url, type: "site", locked: false, password: null, file: basename(file), size: total, createdAt: now, expiresAt: expiresAt || null });
|
|
424
|
-
await saveManifest(manifest);
|
|
425
|
-
report({ url, password: null, locked: false, extra: `${count} files (multi-file site, public)` });
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
544
|
if (isHtml && !opts.page) {
|
|
430
|
-
const slug = opts.slug || slugify(file) + "-" + rand(4);
|
|
431
|
-
const url = `${ORIGIN}/${slug}`;
|
|
432
|
-
const title = opts.title || basename(file, ext).replace(/[-_]+/g, " ");
|
|
433
545
|
let html = await readFile(file, "utf8");
|
|
546
|
+
// A saved Claude artifact: publish the authored page, named after its own <title>.
|
|
547
|
+
const art = isMd ? { html, unwrapped: false } : unwrapClaudeArtifact(html);
|
|
548
|
+
html = art.html;
|
|
549
|
+
const artTitle = art.unwrapped ? htmlTitle(html) : null;
|
|
550
|
+
const slug = opts.slug || (artTitle ? slugify(`${artTitle}.html`).slice(0, 48).replace(/-+$/, "") || "artifact" : slugify(file)) + "-" + rand(4);
|
|
551
|
+
const url = `${ORIGIN}/${slug}`;
|
|
552
|
+
const title = opts.title || artTitle || basename(file, ext).replace(/[-_]+/g, " ");
|
|
434
553
|
if (isMd) html = await mdToHtml(html, title);
|
|
435
554
|
|
|
436
555
|
// PII / secret scan on the RAW content (before brand + encrypt). Warn by default
|
|
@@ -444,7 +563,7 @@ async function cmdDrop(file, opts) {
|
|
|
444
563
|
if (!JSON_OUT) console.error(`\x1b[33m⚠ ${msg}\x1b[0m\n \x1b[2mpublishing anyway — use --block-pii to refuse, --no-pii-check to silence${opts.noLock ? ", and note this drop is PUBLIC (unlocked)" : ""}\x1b[0m`);
|
|
445
564
|
}
|
|
446
565
|
}
|
|
447
|
-
html = await brandHtml(html, { title, url, logoUri, ogImage, expiresAt });
|
|
566
|
+
html = await brandHtml(html, { title, url, logoUri, ogImage, expiresAt, noBadge: mode === "hosted" && await paidSpace() });
|
|
448
567
|
|
|
449
568
|
let password = null, body = html;
|
|
450
569
|
if (!opts.noLock) {
|
|
@@ -459,11 +578,13 @@ async function cmdDrop(file, opts) {
|
|
|
459
578
|
const m = await managedPublish(body, "text/html; charset=utf-8", { burn: opts.burn });
|
|
460
579
|
manifest.unshift({ slug: m.slug, url: m.url, type: "html", locked: !opts.noLock, password, file: basename(file), size: stat, managed: true, burn: !!opts.burn, createdAt: now });
|
|
461
580
|
await saveManifest(manifest);
|
|
462
|
-
report({ url: m.url, password, locked: !opts.noLock, extra: opts.burn ? "managed · burns on first view" : "managed · auto-expires in 24h" });
|
|
581
|
+
report({ url: m.url, password, locked: !opts.noLock, extra: opts.burn ? "managed · burns on first view" : "managed · auto-expires in 24h", keep: opts.burn ? null : m.keep, tip: loginTip(manifest) });
|
|
463
582
|
return;
|
|
464
583
|
}
|
|
465
584
|
if (mode === "hosted") {
|
|
466
585
|
const m = await hostedPublish(body, "text/html; charset=utf-8", slug, !opts.noLock, opts.emailGate);
|
|
586
|
+
if (opts.comments) await patchSite(m.slug, { feedback: true });
|
|
587
|
+
if (opts.protect) await patchSite(m.slug, { protect: true });
|
|
467
588
|
manifest.unshift({ slug: m.slug, url: m.url, type: "html", locked: !opts.noLock, password, file: basename(file), size: stat, hosted: true, handle: m.handle, createdAt: now });
|
|
468
589
|
await saveManifest(manifest);
|
|
469
590
|
report({ url: m.url, password, locked: !opts.noLock, extra: `hosted · ${m.handle}/${m.slug}${opts.emailGate ? ` · @${String(opts.emailGate).replace(/^@/, "")} only` : ""}` });
|
|
@@ -525,8 +646,57 @@ async function cmdDrop(file, opts) {
|
|
|
525
646
|
report({ url, password: null, locked: false, extra: expiresAt ? `expires: ${new Date(expiresAt).toISOString().slice(0, 16).replace("T", " ")}` : undefined });
|
|
526
647
|
}
|
|
527
648
|
|
|
528
|
-
|
|
529
|
-
|
|
649
|
+
// Publish a whole static site (folder or zip) under <slug>/. Brands only the root
|
|
650
|
+
// index.html (injects <base href> so relative links resolve); other files upload as-is.
|
|
651
|
+
// With opts.password, also writes a <slug>/.hush.json PBKDF2 verifier (edge gate).
|
|
652
|
+
async function uploadSite(input, opts, { token, logoUri, ogImage, expiresAt }) {
|
|
653
|
+
const { files, indexRel } = await collectSiteFiles(input, {
|
|
654
|
+
loadZip: async () => (await ensureDep("adm-zip")).default,
|
|
655
|
+
});
|
|
656
|
+
const slug = opts.slug || slugify(basename(input)) + "-" + rand(4);
|
|
657
|
+
const now = new Date().toISOString();
|
|
658
|
+
|
|
659
|
+
if (!opts.noPiiCheck) {
|
|
660
|
+
const hits = new Set();
|
|
661
|
+
for (const f of files) if (/\.html?$/i.test(f.rel)) scanPII(f.data.toString("utf8")).forEach((h) => hits.add(h));
|
|
662
|
+
if (hits.size) {
|
|
663
|
+
const msg = `possible sensitive data in site: ${[...hits].join(", ")}`;
|
|
664
|
+
if (opts.blockPii) die(`⚠ ${msg}\n refusing to publish (--block-pii). Remove it, or drop --no-pii-check.`);
|
|
665
|
+
if (!JSON_OUT) console.error(`\x1b[33m⚠ ${msg}\x1b[0m`);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
let total = 0;
|
|
670
|
+
for (const f of files) {
|
|
671
|
+
let data = f.data;
|
|
672
|
+
if (f.rel === indexRel) {
|
|
673
|
+
let html = data.toString("utf8");
|
|
674
|
+
if (/<head[^>]*>/i.test(html)) html = html.replace(/<head([^>]*)>/i, `<head$1><base href="/${slug}/">`);
|
|
675
|
+
else html = `<base href="/${slug}/">\n` + html;
|
|
676
|
+
html = await brandHtml(html, { title: opts.title || slug, url: `${ORIGIN}/${slug}/`, logoUri, ogImage, expiresAt });
|
|
677
|
+
data = Buffer.from(html, "utf8");
|
|
678
|
+
}
|
|
679
|
+
await upload(`${slug}/${f.rel}`, data, mimeFor(extname(f.rel)), token);
|
|
680
|
+
total += data.length;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
let password = null;
|
|
684
|
+
if (opts.password) {
|
|
685
|
+
password = opts.password;
|
|
686
|
+
const verifier = await makeVerifier(password, { name: CONFIG.brand?.name, logoUri, color: CONFIG.brand?.primaryColor });
|
|
687
|
+
await upload(`${slug}/.hush.json`, Buffer.from(JSON.stringify(verifier)), "application/json", token);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const url = `${ORIGIN}/${slug}/`;
|
|
691
|
+
const manifest = await loadManifest();
|
|
692
|
+
manifest.unshift({ slug, url, type: "site", locked: !!password, password,
|
|
693
|
+
file: basename(input), size: total, count: files.length, createdAt: now, expiresAt: expiresAt || null });
|
|
694
|
+
await saveManifest(manifest);
|
|
695
|
+
report({ url, password, locked: !!password, extra: `${files.length} files · site · ${password ? "locked" : "public"}` });
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function report({ url, password, locked, extra, tip, keep }) {
|
|
699
|
+
if (JSON_OUT) { console.log(JSON.stringify({ url, password: password || null, locked: !!locked, extra: extra || null, ...(keep ? { keep } : {}), ...(tip ? { tip } : {}) })); return; }
|
|
530
700
|
console.log("");
|
|
531
701
|
ok("live");
|
|
532
702
|
console.log(` \x1b[1m${url}\x1b[0m`);
|
|
@@ -534,15 +704,31 @@ function report({ url, password, locked, extra }) {
|
|
|
534
704
|
if (locked && password) console.log(` password: \x1b[1m\x1b[33m${password}\x1b[0m`);
|
|
535
705
|
const payload = locked && password ? `${url}\npassword: ${password}` : url;
|
|
536
706
|
if (clip(payload)) console.log(` \x1b[2m(copied to clipboard)\x1b[0m`);
|
|
707
|
+
if (keep) console.log(` keep it past 24h (free account): ${keep}`);
|
|
708
|
+
if (tip) console.log(`\n \x1b[33m●\x1b[0m ${tip.text}\n ${tip.command}`);
|
|
537
709
|
console.log("");
|
|
538
710
|
}
|
|
539
711
|
|
|
712
|
+
// After a few anonymous drops, suggest a free account: drops that don't expire, a handle, history.
|
|
713
|
+
// Shown on the 3rd anonymous drop and every 5th after, never when logged in. HUSH_NO_TIPS=1 hides it.
|
|
714
|
+
function loginTip(manifest) {
|
|
715
|
+
if (getApiKey() || process.env.HUSH_NO_TIPS) return null;
|
|
716
|
+
const n = manifest.filter((d) => d.managed).length;
|
|
717
|
+
if (n < 3 || (n - 3) % 5) return null;
|
|
718
|
+
return {
|
|
719
|
+
kind: "login", anonymous_drops: n,
|
|
720
|
+
text: `That's ${n} drops that expire in 24h. A free account keeps them on hushdrop.dev/<you>/..., with version history and rollback.`,
|
|
721
|
+
command: "hush login",
|
|
722
|
+
agent_hint: "Offer the user a free Hushdrop account. If they agree, call the login tool (or run `hush login --start --json`), give them verify_url, then call finish_login.",
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
|
|
540
726
|
// Logged-in hosted account → list/remove via the API (not the BYO Blob store).
|
|
541
727
|
const useHosted = () => getApiKey() && !getToken();
|
|
542
728
|
|
|
543
729
|
async function hostedList() {
|
|
544
730
|
const key = getApiKey();
|
|
545
|
-
let r; try { r = await fetch(`${ORIGIN}/api/sites`, { headers: { authorization: `Bearer ${key}` } }); } catch (e) { die(e.message); }
|
|
731
|
+
let r; try { r = await fetch(`${ORIGIN}/api/sites`, { headers: { ...CLIENT_HEADERS, authorization: `Bearer ${key}` } }); } catch (e) { die(e.message); }
|
|
546
732
|
if (!r.ok) die("could not list drops (key invalid? run `hush login`)");
|
|
547
733
|
const { sites } = await r.json();
|
|
548
734
|
const local = await loadManifest();
|
|
@@ -558,7 +744,7 @@ async function hostedList() {
|
|
|
558
744
|
|
|
559
745
|
async function hostedRm(slug) {
|
|
560
746
|
const key = getApiKey();
|
|
561
|
-
let r; try { r = await fetch(`${ORIGIN}/api/sites?slug=${encodeURIComponent(slug)}`, { method: "DELETE", headers: { authorization: `Bearer ${key}` } }); } catch (e) { die(e.message); }
|
|
747
|
+
let r; try { r = await fetch(`${ORIGIN}/api/sites?slug=${encodeURIComponent(slug)}`, { method: "DELETE", headers: { ...CLIENT_HEADERS, authorization: `Bearer ${key}` } }); } catch (e) { die(e.message); }
|
|
562
748
|
if (!r.ok) { let m; try { m = (await r.json()).error; } catch {} die(m || "remove failed"); }
|
|
563
749
|
const m = await loadManifest(); const kept = m.filter((d) => d.slug !== slug); if (kept.length !== m.length) await saveManifest(kept);
|
|
564
750
|
if (JSON_OUT) { console.log(JSON.stringify({ removed: slug })); return; }
|
|
@@ -704,6 +890,21 @@ async function cmdDeploy(opts) {
|
|
|
704
890
|
ok(`config + token saved to ${DROP_HOME}`);
|
|
705
891
|
}
|
|
706
892
|
|
|
893
|
+
// 4b. Gate cookie-signing secret (idempotent — never overwrite a live one, which would
|
|
894
|
+
// invalidate existing site sessions).
|
|
895
|
+
if (!dry) {
|
|
896
|
+
const sh = process.platform === "win32";
|
|
897
|
+
const ls = spawnSync("vercel", ["env", "ls", "production"], { cwd: repoRoot, encoding: "utf8", shell: sh });
|
|
898
|
+
if (!/HUSH_GATE_SECRET/.test(ls.stdout || "")) {
|
|
899
|
+
const add = spawnSync("vercel", ["env", "add", "HUSH_GATE_SECRET", "production"],
|
|
900
|
+
{ cwd: repoRoot, input: randomHex(32) + "\n", encoding: "utf8", shell: sh });
|
|
901
|
+
if (add.status === 0) ok("provisioned HUSH_GATE_SECRET (site password gate)");
|
|
902
|
+
else console.error("\x1b[33m⚠ could not set HUSH_GATE_SECRET — add it manually: vercel env add HUSH_GATE_SECRET production\x1b[0m");
|
|
903
|
+
}
|
|
904
|
+
} else {
|
|
905
|
+
console.log("Dry run — would ensure HUSH_GATE_SECRET is set (vercel env add HUSH_GATE_SECRET production)");
|
|
906
|
+
}
|
|
907
|
+
|
|
707
908
|
// 5. deploy + domain
|
|
708
909
|
if (dry || opts.noDeploy) {
|
|
709
910
|
console.log(`\n${dry ? "Dry run — would run" : "Skipped deploy. Run"}: vercel deploy --prod${opts.domain ? ` && vercel domains add ${opts.domain}` : ""}`);
|
|
@@ -820,10 +1021,42 @@ function openBrowser(url) {
|
|
|
820
1021
|
}
|
|
821
1022
|
async function cmdLogin(opts) {
|
|
822
1023
|
if (opts.token && opts.token.startsWith("drop_")) { await saveApiKey(opts.token); ok("API key saved"); return cmdWhoami(); }
|
|
1024
|
+
// Agent flow, two steps so nothing blocks: --start returns the approval link, --finish waits for it.
|
|
1025
|
+
if (opts.start) {
|
|
1026
|
+
let s; try { s = await (await fetch(`${ORIGIN}/api/auth/device/start`, { method: "POST", headers: CLIENT_HEADERS })).json(); } catch (e) { die(`could not reach ${ORIGIN}: ${e.message}`); }
|
|
1027
|
+
if (!s?.code) die("login unavailable");
|
|
1028
|
+
let cfg = {}; try { cfg = JSON.parse(readFileSync(CONFIG_FILE, "utf8")); } catch {}
|
|
1029
|
+
cfg.pendingLogin = { code: s.code, at: Date.now() };
|
|
1030
|
+
await mkdir(DROP_HOME, { recursive: true });
|
|
1031
|
+
await writeFile(CONFIG_FILE, JSON.stringify(cfg, null, 2) + "\n");
|
|
1032
|
+
if (opts.with) s.verify_url += `&with=${encodeURIComponent(String(opts.with).toLowerCase())}`;
|
|
1033
|
+
const out = { verify_url: s.verify_url, code: s.code, expires_in: 300, next: "hush login --finish" };
|
|
1034
|
+
if (JSON_OUT) return console.log(JSON.stringify(out));
|
|
1035
|
+
return ok(`open this to sign in (free): ${s.verify_url}\n then run: hush login --finish`);
|
|
1036
|
+
}
|
|
1037
|
+
if (opts.finish) {
|
|
1038
|
+
let cfg = {}; try { cfg = JSON.parse(readFileSync(CONFIG_FILE, "utf8")); } catch {}
|
|
1039
|
+
const code = cfg.pendingLogin?.code;
|
|
1040
|
+
if (!code) die("no login in progress — run: hush login --start");
|
|
1041
|
+
const deadline = Date.now() + Math.min(Number(opts.wait || 90), 280) * 1000;
|
|
1042
|
+
while (Date.now() < deadline) {
|
|
1043
|
+
let p; try { p = await (await fetch(`${ORIGIN}/api/auth/device/poll?code=${code}`, { headers: CLIENT_HEADERS })).json(); } catch { p = {}; }
|
|
1044
|
+
if (p.status === "approved" && p.api_key) {
|
|
1045
|
+
await saveApiKey(p.api_key);
|
|
1046
|
+
try { const c = JSON.parse(readFileSync(CONFIG_FILE, "utf8")); delete c.pendingLogin; await writeFile(CONFIG_FILE, JSON.stringify(c, null, 2) + "\n"); } catch {}
|
|
1047
|
+
return cmdWhoami();
|
|
1048
|
+
}
|
|
1049
|
+
if (p.status === "denied" || p.status === "expired") die(`login ${p.status} — run: hush login --start`);
|
|
1050
|
+
await sleep(2000);
|
|
1051
|
+
}
|
|
1052
|
+
if (JSON_OUT) return console.log(JSON.stringify({ status: "pending", next: "hush login --finish" }));
|
|
1053
|
+
die("still waiting for approval — run `hush login --finish` again once you've signed in");
|
|
1054
|
+
}
|
|
823
1055
|
let start;
|
|
824
|
-
try { start = await (await fetch(`${ORIGIN}/api/auth/device/start`, { method: "POST" })).json(); }
|
|
1056
|
+
try { start = await (await fetch(`${ORIGIN}/api/auth/device/start`, { method: "POST", headers: CLIENT_HEADERS })).json(); }
|
|
825
1057
|
catch (e) { die(`could not reach ${ORIGIN}: ${e.message}`); }
|
|
826
1058
|
if (!start?.code) die("login unavailable (hosted tier not configured yet)");
|
|
1059
|
+
if (opts.with) start.verify_url += `&with=${encodeURIComponent(String(opts.with).toLowerCase())}`;
|
|
827
1060
|
console.log(`\n opening ${start.verify_url}`);
|
|
828
1061
|
console.log(` \x1b[2mif it doesn't open, paste that URL into your browser\x1b[0m\n`);
|
|
829
1062
|
openBrowser(start.verify_url);
|
|
@@ -832,7 +1065,7 @@ async function cmdLogin(opts) {
|
|
|
832
1065
|
while (Date.now() < deadline) {
|
|
833
1066
|
await sleep((start.poll_interval || 2) * 1000);
|
|
834
1067
|
process.stdout.write(".");
|
|
835
|
-
let p; try { p = await (await fetch(`${ORIGIN}/api/auth/device/poll?code=${start.code}
|
|
1068
|
+
let p; try { p = await (await fetch(`${ORIGIN}/api/auth/device/poll?code=${start.code}`, { headers: CLIENT_HEADERS })).json(); } catch { continue; }
|
|
836
1069
|
if (p.status === "approved" && p.api_key) { console.log(""); await saveApiKey(p.api_key); ok(`logged in — key saved to ${CONFIG_FILE}`); return cmdWhoami(); }
|
|
837
1070
|
if (p.status === "denied") { console.log(""); die("authorization denied"); }
|
|
838
1071
|
if (p.status === "expired") { console.log(""); die("code expired — run `hush login` again"); }
|
|
@@ -859,12 +1092,50 @@ async function cmdLogout() {
|
|
|
859
1092
|
// Thin authenticated calls against the hosted API. Each needs `hush login` first.
|
|
860
1093
|
async function apiCall(path, init = {}) {
|
|
861
1094
|
const key = getApiKey(); if (!key) die("not logged in — run: hush login");
|
|
862
|
-
let r; try { r = await fetch(`${ORIGIN}${path}`, { ...init, headers: { authorization: `Bearer ${key}`, ...(init.headers || {}) } }); }
|
|
1095
|
+
let r; try { r = await fetch(`${ORIGIN}${path}`, { ...init, headers: { ...CLIENT_HEADERS, authorization: `Bearer ${key}`, ...(init.headers || {}) } }); }
|
|
863
1096
|
catch (e) { die(`request failed: ${e.message}`); }
|
|
864
1097
|
let d = {}; try { d = await r.json(); } catch {}
|
|
1098
|
+
if (r.status === 402 && d.paywall && init.retry !== false) return onPaywall(d, () => apiCall(path, { ...init, retry: false }));
|
|
865
1099
|
if (!r.ok) die(d.error || `request failed (${r.status})`);
|
|
866
1100
|
return d;
|
|
867
1101
|
}
|
|
1102
|
+
|
|
1103
|
+
// ---------- paywall + upgrade (same flow whether checkout is Stripe or the free trial) ----------
|
|
1104
|
+
async function confirm(q) {
|
|
1105
|
+
if (opts.yes) return true;
|
|
1106
|
+
if (!process.stdin.isTTY) return false;
|
|
1107
|
+
const rl = (await import("node:readline")).createInterface({ input: process.stdin, output: process.stdout });
|
|
1108
|
+
const a = await new Promise((res) => rl.question(q, res)); rl.close();
|
|
1109
|
+
return !/^n/i.test(String(a).trim());
|
|
1110
|
+
}
|
|
1111
|
+
// A Team action hit the plan: say what they were doing, offer the trial in place, then finish it.
|
|
1112
|
+
async function onPaywall(d, retry) {
|
|
1113
|
+
const p = d.paywall;
|
|
1114
|
+
if (JSON_OUT) { console.log(JSON.stringify(d)); process.exit(2); }
|
|
1115
|
+
console.error(`\n \x1b[33m●\x1b[0m ${d.error.split(" Run: ")[0]}`);
|
|
1116
|
+
if (!p.can_upgrade) { console.error(`\n ask an owner of @${p.team}, or run: hush team upgrade ${p.team} (we'll tell them you asked)\n`); process.exit(2); }
|
|
1117
|
+
const label = p.trial_available ? `Start the free ${p.trial_days}-day Team trial for @${p.team}? No card. [Y/n] ` : `Upgrade @${p.team} to Team ($29/mo flat)? [Y/n] `;
|
|
1118
|
+
if (!(await confirm(`\n ${label}`))) { console.error(`\n no changes. Later: hush team upgrade ${p.team}\n`); process.exit(2); }
|
|
1119
|
+
const u = await upgradeSpace({ plan: "team", team: p.team, then: p.then, from: p.gate });
|
|
1120
|
+
if (!u || u.requested || u.url) process.exit(u?.requested ? 2 : 0);
|
|
1121
|
+
if (u.completed?.added) process.exit(0);
|
|
1122
|
+
return retry();
|
|
1123
|
+
}
|
|
1124
|
+
// The checkout step. Stripe: open checkout in the browser. No Stripe yet: start the trial here.
|
|
1125
|
+
async function upgradeSpace(payload) {
|
|
1126
|
+
const d = await apiCall(`/api/billing`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ interval: opts.yearly ? "year" : "month", ...payload }) });
|
|
1127
|
+
if (JSON_OUT) { console.log(JSON.stringify(d)); return d; }
|
|
1128
|
+
if (d.url) { openBrowser(d.url); ok(d.portal ? `@${d.space} is on ${d.plan}: opened billing (card, invoices, cancel)\n ${d.url}` : `opened checkout for @${d.space}\n ${d.url}`); return d; }
|
|
1129
|
+
if (d.requested) { console.error(`\n ${d.message}\n`); return d; }
|
|
1130
|
+
if (d.portal === false) { ok(d.message); return d; }
|
|
1131
|
+
ok(d.message);
|
|
1132
|
+
const when = d.renews_at ? new Date(d.renews_at).toISOString().slice(0, 10) : null;
|
|
1133
|
+
if (when) console.log(` ${d.status === "trialing" ? "trial ends" : "paid through"} ${when} · hush billing${d.kind === "team" ? " " + d.space : ""}`);
|
|
1134
|
+
if (d.completed?.added) ok(`@${d.completed.added} is ${d.completed.role} on @${d.completed.team} — they publish with: hush <file> --to ${d.completed.team}`);
|
|
1135
|
+
else if (d.completed?.error) console.error(` ${d.completed.error}`);
|
|
1136
|
+
else if (d.kind === "team" && d.trial) console.log(` next: hush team add ${d.space} @handle`);
|
|
1137
|
+
return d;
|
|
1138
|
+
}
|
|
868
1139
|
const patchSite = (slug, patch) => apiCall(`/api/sites?slug=${encodeURIComponent(slug)}`, { method: "PATCH", headers: { "content-type": "application/json" }, body: JSON.stringify(patch) });
|
|
869
1140
|
|
|
870
1141
|
async function cmdSetExpiry(slug, when) {
|
|
@@ -881,6 +1152,328 @@ async function cmdSetEmailGate(slug, domain) {
|
|
|
881
1152
|
if (JSON_OUT) return console.log(JSON.stringify({ slug, email_gate: val }));
|
|
882
1153
|
ok(val ? `email-gate on ${slug} → only @${val} may open it` : `email-gate cleared on ${slug}`);
|
|
883
1154
|
}
|
|
1155
|
+
// ---------- versions + team (hosted) ----------
|
|
1156
|
+
const spaceOf = (o) => { const t = o.to || activeSpace(); return t ? String(t).replace(/^@/, "").split("/")[0] : undefined; };
|
|
1157
|
+
const spaceQ = (o) => (spaceOf(o) ? `&space=${encodeURIComponent(spaceOf(o))}` : "");
|
|
1158
|
+
async function cmdVersions(slug, o) {
|
|
1159
|
+
if (!slug) die("usage: hush versions <slug> [--unpin] [--to <handle>]");
|
|
1160
|
+
const d = o.unpin ? null : await apiCall(`/api/versions?slug=${encodeURIComponent(slug)}${spaceQ(o)}`);
|
|
1161
|
+
if (JSON_OUT && !o.unpin) return console.log(JSON.stringify(d));
|
|
1162
|
+
if (o.unpin) {
|
|
1163
|
+
const u = await apiCall(`/api/versions`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ slug, unpin: true, space: spaceOf(o) }) });
|
|
1164
|
+
if (JSON_OUT) return console.log(JSON.stringify(u));
|
|
1165
|
+
return ok(`${u.handle}/${u.slug} unpinned: the latest version (v${u.current}) is live`);
|
|
1166
|
+
}
|
|
1167
|
+
console.log(`\n ${d.handle}/${d.slug} \x1b[2m(${d.versions.length} versions)\x1b[0m${d.pinned ? ` \x1b[33mpinned to v${d.pinned}\x1b[0m` : ""}`);
|
|
1168
|
+
for (const v of d.versions) {
|
|
1169
|
+
const when = new Date(v.created_at).toISOString().slice(0, 16).replace("T", " ");
|
|
1170
|
+
console.log(` ${v.live ? "\x1b[33m●\x1b[0m" : " "} v${String(v.version).padEnd(4)} ${when} ${String(Math.round((v.size_bytes || 0) / 1024) + " KB").padStart(8)} ${v.published_by ? "@" + v.published_by : ""}${v.note ? ` \x1b[2m${v.note}\x1b[0m` : ""}`);
|
|
1171
|
+
}
|
|
1172
|
+
console.log("");
|
|
1173
|
+
}
|
|
1174
|
+
async function cmdRollback(slug, version, o) {
|
|
1175
|
+
if (!slug || !version) die("usage: hush rollback <slug> <version> [--pin] [--to <handle>]");
|
|
1176
|
+
const space = spaceOf(o);
|
|
1177
|
+
const d = await apiCall(`/api/versions`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ slug, version: parseInt(String(version).replace(/^v/i, ""), 10), space, pin: !!o.pin }) });
|
|
1178
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1179
|
+
ok(`${d.handle}/${d.slug} is now on v${d.current} (same URL)${d.pinned ? `, pinned: new publishes are saved as versions but won't go live until: hush versions ${d.slug} --unpin` : ""}`);
|
|
1180
|
+
}
|
|
1181
|
+
// Per-drop editors: let someone else update one of your drops.
|
|
1182
|
+
async function cmdEditors(action, a, b, o) {
|
|
1183
|
+
const space = spaceOf(o);
|
|
1184
|
+
if (action === "add" || action === "rm" || action === "remove") {
|
|
1185
|
+
const [slug, who] = [a, b];
|
|
1186
|
+
if (!slug || !who) die(`usage: hush editors ${action} <slug> @handle`);
|
|
1187
|
+
const d = await apiCall(`/api/editors`, { method: action === "add" ? "POST" : "DELETE", headers: { "content-type": "application/json" }, body: JSON.stringify({ slug, handle: who, space }) });
|
|
1188
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1189
|
+
if (action === "add") return ok(`@${d.editor} can now update ${d.handle}/${d.slug} — they run: hush <file> --to ${d.handle}/${d.slug}`);
|
|
1190
|
+
return ok(`removed @${d.removed} from ${d.handle}/${d.slug}`);
|
|
1191
|
+
}
|
|
1192
|
+
const slug = action === "ls" || action === "list" ? a : action;
|
|
1193
|
+
if (!slug) die("usage: hush editors <slug> | hush editors add <slug> @handle | hush editors rm <slug> @handle");
|
|
1194
|
+
const d = await apiCall(`/api/editors?slug=${encodeURIComponent(slug)}${space ? `&space=${encodeURIComponent(space)}` : ""}`);
|
|
1195
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1196
|
+
console.log(`\n ${d.handle}/${d.slug} \x1b[2m(you: ${d.role})\x1b[0m`);
|
|
1197
|
+
if (!d.editors.length) console.log(` no editors — add one: hush editors add ${d.slug} @handle`);
|
|
1198
|
+
for (const e of d.editors) console.log(` @${e.handle}`);
|
|
1199
|
+
console.log("");
|
|
1200
|
+
}
|
|
1201
|
+
// Hosted custom domains (Pro/Team): serve a whole space or one drop on your own domain.
|
|
1202
|
+
function printDomain(d) {
|
|
1203
|
+
const state = d.live ? "\x1b[32mlive\x1b[0m" : "\x1b[33mwaiting for DNS records\x1b[0m";
|
|
1204
|
+
console.log(`\n ${d.domain} → ${d.target} ${state}`);
|
|
1205
|
+
if (!d.live && d.dns?.length) {
|
|
1206
|
+
console.log(" add these records at your DNS provider:");
|
|
1207
|
+
for (const r of d.dns) console.log(` ${r.type.padEnd(5)} ${String(r.name).padEnd(24)} ${r.value} \x1b[2m(${r.why})\x1b[0m`);
|
|
1208
|
+
console.log(` then check: hush domains status ${d.domain} (DNS can take a few minutes; HTTPS is automatic)`);
|
|
1209
|
+
} else if (d.live) console.log(` ${d.slug ? `https://${d.domain}/` : `https://${d.domain}/<slug>`}`);
|
|
1210
|
+
console.log("");
|
|
1211
|
+
}
|
|
1212
|
+
async function cmdDomains(action, a, b, o) {
|
|
1213
|
+
const space = spaceOf(o);
|
|
1214
|
+
if (action === "add") {
|
|
1215
|
+
if (!a) die("usage: hush domains add <domain> [<slug>] [--to <team>]");
|
|
1216
|
+
const d = await apiCall(`/api/domains`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ domain: a, slug: b || undefined, space }) });
|
|
1217
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1218
|
+
ok(`connected ${d.domain} to ${d.target}`);
|
|
1219
|
+
return printDomain(d);
|
|
1220
|
+
}
|
|
1221
|
+
if (action === "status" || action === "check") {
|
|
1222
|
+
if (!a) die("usage: hush domains status <domain>");
|
|
1223
|
+
const d = await apiCall(`/api/domains?domain=${encodeURIComponent(a)}`);
|
|
1224
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1225
|
+
return printDomain(d);
|
|
1226
|
+
}
|
|
1227
|
+
if (action === "rm" || action === "remove") {
|
|
1228
|
+
if (!a) die("usage: hush domains rm <domain>");
|
|
1229
|
+
const d = await apiCall(`/api/domains`, { method: "DELETE", headers: { "content-type": "application/json" }, body: JSON.stringify({ domain: a }) });
|
|
1230
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1231
|
+
return ok(`disconnected ${d.removed}`);
|
|
1232
|
+
}
|
|
1233
|
+
if (action && action !== "ls" && action !== "list") die("usage: hush domains [ls] | add <domain> [<slug>] | status <domain> | rm <domain> [--to <team>]");
|
|
1234
|
+
const d = await apiCall(`/api/domains${space ? `?space=${encodeURIComponent(space)}` : ""}`);
|
|
1235
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1236
|
+
console.log(`\n domains for ${d.handle}`);
|
|
1237
|
+
if (!d.domains.length) console.log(` none yet — hush domains add share.yourco.com${d.allowed ? "" : " (Pro/Team)"}`);
|
|
1238
|
+
for (const x of d.domains) console.log(` ${x.domain.padEnd(28)} → ${x.target.padEnd(24)} ${x.verified ? "\x1b[32mlive\x1b[0m" : "\x1b[33mpending\x1b[0m (hush domains status " + x.domain + ")"}`);
|
|
1239
|
+
console.log("");
|
|
1240
|
+
}
|
|
1241
|
+
// Team spaces: shared accounts with their own handle. `hush use <team>` switches the default.
|
|
1242
|
+
function readCfg() { try { return JSON.parse(readFileSync(CONFIG_FILE, "utf8")); } catch { return {}; } }
|
|
1243
|
+
function activeSpace() { return readCfg().space || null; }
|
|
1244
|
+
async function cmdUse(target) {
|
|
1245
|
+
const cfg = readCfg();
|
|
1246
|
+
if (!target) {
|
|
1247
|
+
const cur = cfg.space || "personal";
|
|
1248
|
+
if (JSON_OUT) return console.log(JSON.stringify({ space: cur }));
|
|
1249
|
+
return console.log(`\n publishing to: ${cur === "personal" ? "your personal space" : "@" + cur}\n switch: hush use <team> | hush use personal\n`);
|
|
1250
|
+
}
|
|
1251
|
+
const t = String(target).replace(/^@/, "").toLowerCase();
|
|
1252
|
+
if (t === "personal" || t === "me") delete cfg.space;
|
|
1253
|
+
else {
|
|
1254
|
+
const d = await apiCall(`/api/team?team=${encodeURIComponent(t)}`);
|
|
1255
|
+
cfg.space = d.team;
|
|
1256
|
+
}
|
|
1257
|
+
mkdirSync(dirname(CONFIG_FILE), { recursive: true });
|
|
1258
|
+
writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2));
|
|
1259
|
+
if (JSON_OUT) return console.log(JSON.stringify({ space: cfg.space || "personal" }));
|
|
1260
|
+
ok(cfg.space ? `now publishing to @${cfg.space} (hush use personal to switch back)` : "now publishing to your personal space");
|
|
1261
|
+
}
|
|
1262
|
+
async function cmdTeam(action, a, b, o) {
|
|
1263
|
+
const j = (d) => (JSON_OUT ? (console.log(JSON.stringify(d)), true) : false);
|
|
1264
|
+
if (!action || action === "ls" || action === "list") {
|
|
1265
|
+
const d = await apiCall(`/api/team`);
|
|
1266
|
+
if (j(d)) return;
|
|
1267
|
+
const cur = activeSpace();
|
|
1268
|
+
console.log(`\n ${cur ? " " : "\x1b[33m●\x1b[0m"} @${d.personal} \x1b[2mpersonal\x1b[0m`);
|
|
1269
|
+
for (const t of d.teams) console.log(` ${cur === t.handle ? "\x1b[33m●\x1b[0m" : " "} @${String(t.handle).padEnd(20)} ${t.role.padEnd(7)} ${t.members} members ${t.plan === "team" ? "\x1b[32mTeam\x1b[0m" : "\x1b[2mfree\x1b[0m"}${t.name ? ` \x1b[2m${t.name}\x1b[0m` : ""}`);
|
|
1270
|
+
console.log(`\n hush team create <handle> · hush use <team> · hush team members <team>\n`);
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
if (action === "create") {
|
|
1274
|
+
if (!a) die("usage: hush team create <handle> [--title \"Team name\"]");
|
|
1275
|
+
const d = await apiCall(`/api/team`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ create: a, name: o.title }) });
|
|
1276
|
+
if (j(d)) return;
|
|
1277
|
+
ok(`created @${d.team} — add people: hush team add ${d.team} @handle · publish: hush <file> --to ${d.team}`);
|
|
1278
|
+
if (d.next) console.log(` next: ${d.next}`);
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
if (action === "members") {
|
|
1282
|
+
const team = a || activeSpace();
|
|
1283
|
+
if (!team) die("usage: hush team members <team>");
|
|
1284
|
+
const d = await apiCall(`/api/team?team=${encodeURIComponent(String(team).replace(/^@/, ""))}`);
|
|
1285
|
+
if (j(d)) return;
|
|
1286
|
+
console.log(`\n @${d.team}${d.name ? ` \x1b[2m${d.name}\x1b[0m` : ""} \x1b[2m(you: ${d.role})\x1b[0m`);
|
|
1287
|
+
if (d.subdomain_url) console.log(` \x1b[2mcompany link:\x1b[0m ${d.subdomain_url}/<slug>`);
|
|
1288
|
+
for (const m of d.members) console.log(` @${String(m.handle).padEnd(20)} ${m.role}`);
|
|
1289
|
+
console.log("");
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
if (action === "invite" || action === "invites") {
|
|
1293
|
+
// Email invites: people sign up from the email and land in the team (no handle needed first).
|
|
1294
|
+
// hush team invite acme ann@acme.com leo@studio.io [--role admin] [--note "…"]
|
|
1295
|
+
// hush team invites acme pending invites + the invite link
|
|
1296
|
+
// hush team invite acme --link on|off|reset
|
|
1297
|
+
// hush team invite acme --revoke-invite <id> · --resend <id>
|
|
1298
|
+
const team = String(a || activeSpace() || "").replace(/^@/, "");
|
|
1299
|
+
if (!team) die("usage: hush team invite <team> ann@acme.com [more…] [--role editor|admin] [--note \"…\"] (or --link on|off|reset)");
|
|
1300
|
+
const J = { "content-type": "application/json" };
|
|
1301
|
+
const who = (o._rest || []).filter(Boolean);
|
|
1302
|
+
if (action === "invites" || (!who.length && !o.link && !o.revokeInvite && !o.resend)) {
|
|
1303
|
+
const d = await apiCall(`/api/team?team=${encodeURIComponent(team)}`);
|
|
1304
|
+
if (j({ invites: d.invites || [], link: d.link || null })) return;
|
|
1305
|
+
console.log(`\n @${d.team} pending invites`);
|
|
1306
|
+
for (const i of d.invites || []) console.log(` ${String(i.email).padEnd(32)} ${i.role.padEnd(7)} ${i.state} \x1b[2mid ${i.id}\x1b[0m`);
|
|
1307
|
+
if (!(d.invites || []).length) console.log(" \x1b[2mnone\x1b[0m");
|
|
1308
|
+
console.log(d.link ? `\n invite link: ${d.link.url} \x1b[2m(joins as editor, used ${d.link.uses}x)\x1b[0m\n` : `\n \x1b[2mno invite link — turn one on: hush team invite ${team} --link on\x1b[0m\n`);
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
if (o.revokeInvite) { const d = await apiCall(`/api/team`, { method: "DELETE", headers: J, body: JSON.stringify({ team, invite_id: o.revokeInvite }) }); if (j(d)) return; return ok(`revoked the invite for ${d.revoked}`); }
|
|
1312
|
+
const body = o.link ? { team, link: o.link } : o.resend ? { team, resend: o.resend } : { team, invite: who, role: o.role, note: o.note };
|
|
1313
|
+
const d = await apiCall(`/api/team`, { method: "POST", headers: J, body: JSON.stringify(body) });
|
|
1314
|
+
if (j(d)) return;
|
|
1315
|
+
if (d.trial_started) ok(`@${team} is on the free Team trial (no card)`);
|
|
1316
|
+
if (o.link) return d.link ? ok(`invite link: ${d.link.url} (anyone with it joins as editor)`) : ok("invite link turned off");
|
|
1317
|
+
if (o.resend) return ok(d.status === "sent" ? `resent to ${d.email}` : `email didn't go out — send this link yourself: ${d.url}`);
|
|
1318
|
+
for (const r of d.results || []) {
|
|
1319
|
+
const t = r.email || "@" + r.handle;
|
|
1320
|
+
if (r.status === "sent") ok(`invited ${t} as ${r.role}`);
|
|
1321
|
+
else if (r.status === "added") ok(`${t} already had an account — added as ${r.role}`);
|
|
1322
|
+
else if (r.status === "already_member") console.log(` ${t} is already on @${team}`);
|
|
1323
|
+
else if (r.status === "no_account") console.log(` \x1b[33m!\x1b[0m no account for ${t} — invite them by email`);
|
|
1324
|
+
else console.log(` \x1b[33m!\x1b[0m email didn't go out for ${t} — send this link: ${r.url || "(retry)"}`);
|
|
1325
|
+
}
|
|
1326
|
+
if ((d.invalid || []).length) console.log(` \x1b[33m!\x1b[0m skipped: ${d.invalid.join(", ")}`);
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
if (action === "add" || action === "rm" || action === "remove" || action === "leave") {
|
|
1330
|
+
const team = action === "leave" ? a : a;
|
|
1331
|
+
const who = action === "leave" ? null : b;
|
|
1332
|
+
if (!team || (action !== "leave" && !who)) die(`usage: hush team ${action} <team> ${action === "leave" ? "" : "@handle"}${action === "add" ? " [--role editor|admin|owner]" : ""}`);
|
|
1333
|
+
let handle = who;
|
|
1334
|
+
if (action === "leave") handle = (await apiCall(`/api/team`)).personal;
|
|
1335
|
+
const d = await apiCall(`/api/team`, { method: action === "add" ? "POST" : "DELETE", headers: { "content-type": "application/json" }, body: JSON.stringify({ team: String(team).replace(/^@/, ""), handle, role: o.role }) });
|
|
1336
|
+
if (j(d)) return;
|
|
1337
|
+
return action === "add" ? ok(`@${d.handle} is ${d.role} on @${d.team} — they publish with: hush <file> --to ${d.team}`) : ok(`removed @${d.removed} from @${d.team}`);
|
|
1338
|
+
}
|
|
1339
|
+
if (action === "sso") {
|
|
1340
|
+
// SAML SSO (Team add-on): members sign in through the company's identity provider.
|
|
1341
|
+
const team = String(a || activeSpace() || "").replace(/^@/, "");
|
|
1342
|
+
if (!team) die("usage: hush team sso <team> [--metadata-url https://idp/metadata | --metadata-file idp.xml | off]");
|
|
1343
|
+
if (!b && !o.metadataUrl && !o.metadataFile) {
|
|
1344
|
+
const d = await apiCall(`/api/team?team=${encodeURIComponent(team)}`);
|
|
1345
|
+
if (j({ team: d.team, sso: d.sso })) return;
|
|
1346
|
+
const s = d.sso || {};
|
|
1347
|
+
if (s.configured) return console.log(`\n @${d.team}: SAML SSO is on for @${s.domain}\n sign-in link: ${s.login}\n members: hush login --with sso\n`);
|
|
1348
|
+
return console.log(`\n @${d.team}: no SAML SSO yet${s.available ? "" : " (not switched on for this server)"}.\n set up: hush team sso ${d.team} --metadata-url <your IdP's SAML metadata URL>\n`);
|
|
1349
|
+
}
|
|
1350
|
+
let sso;
|
|
1351
|
+
if (b === "off") sso = "off";
|
|
1352
|
+
else if (o.metadataUrl) sso = { metadata_url: o.metadataUrl };
|
|
1353
|
+
else if (o.metadataFile) sso = { metadata_xml: await readFile(o.metadataFile, "utf8") };
|
|
1354
|
+
else die("pass --metadata-url, --metadata-file, or off");
|
|
1355
|
+
const d = await apiCall(`/api/team`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ team, sso }) });
|
|
1356
|
+
if (j(d)) return;
|
|
1357
|
+
if (!d.sso?.configured) return ok(`SAML SSO removed from @${d.team}`);
|
|
1358
|
+
ok(`SAML SSO on for @${d.team}: anyone at @${d.sso.domain} signs in through your identity provider and joins @${d.team}`);
|
|
1359
|
+
if (d.idp_setup) console.log(`\n in your IdP's SAML app use:\n ACS URL ${d.idp_setup.acs_url}\n Entity ID ${d.idp_setup.entity_id}\n NameID ${d.idp_setup.name_id}\n sign-in link for members: ${d.sso.login}\n`);
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
if (action === "domain") {
|
|
1363
|
+
// Company login: anyone signing in with a verified @<domain> address joins the team.
|
|
1364
|
+
const team = String(a || activeSpace() || "").replace(/^@/, "");
|
|
1365
|
+
if (!team) die("usage: hush team domain <team> [acme.com|off] [--role editor|admin]");
|
|
1366
|
+
if (!b) {
|
|
1367
|
+
const d = await apiCall(`/api/team?team=${encodeURIComponent(team)}`);
|
|
1368
|
+
if (j({ team: d.team, email_domain: d.email_domain, domain_role: d.domain_role })) return;
|
|
1369
|
+
return console.log(d.email_domain ? `\n @${d.team}: anyone signing in as @${d.email_domain} joins as ${d.domain_role}\n stop: hush team domain ${d.team} off\n` : `\n @${d.team} has no company domain. set one: hush team domain ${d.team} yourco.com\n`);
|
|
1370
|
+
}
|
|
1371
|
+
const d = await apiCall(`/api/team`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ team, email_domain: b === "off" ? null : b, domain_role: o.role }) });
|
|
1372
|
+
if (j(d)) return;
|
|
1373
|
+
return d.email_domain ? ok(d.note) : ok(`@${d.team} no longer auto-joins by email domain`);
|
|
1374
|
+
}
|
|
1375
|
+
if (action === "style") {
|
|
1376
|
+
// House style: markdown that hush rules --team <team> (and MCP page_rules) append for agents.
|
|
1377
|
+
const team = String(a || activeSpace() || "").replace(/^@/, "");
|
|
1378
|
+
if (!team) die("usage: hush team style <team> [style.md|off]");
|
|
1379
|
+
if (!b) {
|
|
1380
|
+
const d = await apiCall(`/api/team-style?team=${encodeURIComponent(team)}`);
|
|
1381
|
+
if (j(d)) return;
|
|
1382
|
+
if (!d.house_style) return ok(`@${d.team} has no house style yet — set one: hush team style ${d.team} style.md`);
|
|
1383
|
+
return console.log(d.house_style);
|
|
1384
|
+
}
|
|
1385
|
+
let text = b;
|
|
1386
|
+
if (b !== "off") { if (!existsSync(b)) die(`${b} not found (pass a markdown file, or "off" to clear)`); text = readFileSync(b, "utf8"); }
|
|
1387
|
+
const d = await apiCall(`/api/team-style`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ team, house_style: text }) });
|
|
1388
|
+
if (j(d)) return;
|
|
1389
|
+
return d.house_style ? ok(`house style set for @${d.team} (${d.bytes} bytes)\n agents read it with: ${d.read_with}`) : ok(`house style cleared for @${d.team}`);
|
|
1390
|
+
}
|
|
1391
|
+
if (action === "delete") {
|
|
1392
|
+
const team = String(a || "").replace(/^@/, "");
|
|
1393
|
+
if (!team) die("usage: hush team delete <team> --yes (deletes the team and every drop in it)");
|
|
1394
|
+
if (!opts.yes) die(`this deletes @${team} and every drop in it, and can't be undone. Re-run with --yes to confirm.`);
|
|
1395
|
+
const d = await apiCall(`/api/team`, { method: "DELETE", headers: { "content-type": "application/json" }, body: JSON.stringify({ team, delete_team: team }) });
|
|
1396
|
+
if (activeSpace() === team) { let cfg = {}; try { cfg = JSON.parse(readFileSync(CONFIG_FILE, "utf8")); } catch {} delete cfg.space; await writeFile(CONFIG_FILE, JSON.stringify(cfg, null, 2) + "\n"); }
|
|
1397
|
+
if (j(d)) return;
|
|
1398
|
+
return ok(`deleted @${d.deleted} (${d.drops_removed} drops removed)`);
|
|
1399
|
+
}
|
|
1400
|
+
if (action === "upgrade" || action === "billing") {
|
|
1401
|
+
const team = a || activeSpace();
|
|
1402
|
+
if (!team) die(`usage: hush team ${action} <team>`);
|
|
1403
|
+
return action === "upgrade" ? cmdUpgrade("team", team) : cmdBilling(team);
|
|
1404
|
+
}
|
|
1405
|
+
die("usage: hush team [ls | create <handle> | members <team> | add <team> @handle [--role ...] | rm <team> @handle | leave <team> | domain <team> [acme.com|off] | sso <team> [--metadata-url URL|off] | style <team> [style.md|off] | upgrade <team> | billing <team>]");
|
|
1406
|
+
}
|
|
1407
|
+
// Billing: Pro ($9, personal) and Team ($29 flat per team, free trial). Stripe hosts checkout.
|
|
1408
|
+
async function cmdUpgrade(plan, team) {
|
|
1409
|
+
const t = team ? String(team).replace(/^@/, "") : undefined;
|
|
1410
|
+
const s = await apiCall(`/api/billing${t ? `?team=${encodeURIComponent(t)}` : ""}`);
|
|
1411
|
+
const add = opts.add ? String(opts.add).replace(/^@/, "") : undefined;
|
|
1412
|
+
if (!JSON_OUT && s.checkout === "trial") {
|
|
1413
|
+
const name = plan === "team" ? "Team" : "Pro", price = s.prices[plan][opts.yearly ? "year" : "month"];
|
|
1414
|
+
console.log(`\n ${name} for @${s.space}: $${price}/${opts.yearly ? "yr" : "mo"}${plan === "team" ? " flat, unlimited members" : ""}`);
|
|
1415
|
+
if (s.plan === plan) console.log(` already on ${name}${s.renews_at ? ` until ${s.renews_at.slice(0, 10)}` : ""}`);
|
|
1416
|
+
else if (s.trial_available) {
|
|
1417
|
+
console.log(` ${s.trial_days} days free. No card, nothing to cancel.`);
|
|
1418
|
+
if (!(await confirm(`\n Start the free trial? [Y/n] `))) { console.log("\n no changes\n"); return; }
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
return upgradeSpace({ plan, team: t, then: add ? { add, role: opts.role } : undefined, from: "cli_upgrade" });
|
|
1422
|
+
}
|
|
1423
|
+
async function cmdBilling(team) {
|
|
1424
|
+
const t = team ? String(team).replace(/^@/, "") : "";
|
|
1425
|
+
const d = await apiCall(`/api/billing${t ? `?team=${encodeURIComponent(t)}` : ""}`);
|
|
1426
|
+
if (JSON_OUT) {
|
|
1427
|
+
if (d.checkout === "stripe" && d.source === "stripe") { try { const p = await apiCall(`/api/billing`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ portal: true, team: t || undefined }) }); d.portal_url = p.url; } catch {} }
|
|
1428
|
+
return console.log(JSON.stringify(d));
|
|
1429
|
+
}
|
|
1430
|
+
const when = d.renews_at ? new Date(d.renews_at).toISOString().slice(0, 10) : null;
|
|
1431
|
+
console.log(`\n @${d.space} ${d.kind} plan: ${d.plan}${d.status ? ` (${d.status})` : ""}${when ? ` ${d.status === "trialing" ? "trial ends" : "renews"} ${when}` : ""}`);
|
|
1432
|
+
if (d.plan === "free") console.log(` upgrade: ${d.kind === "team" ? `hush team upgrade ${d.space} ($${d.prices.team.month}/mo flat, unlimited members)` : `hush upgrade (Pro $${d.prices.pro.month}/mo)`}${d.trial_available ? ` · ${d.trial_days} days free, no card` : ""}\n`);
|
|
1433
|
+
else if (d.checkout === "stripe" && d.source === "stripe") { console.log(""); await upgradeSpace({ portal: true, team: t || undefined }); }
|
|
1434
|
+
else console.log(` ${d.source === "trial" ? `free trial, ${d.days_left} days left, no card on file` : "set by Hushdrop"}\n`);
|
|
1435
|
+
}
|
|
1436
|
+
// Admin (handles in ADMIN_HANDLES): set or revoke plans by hand, and see upgrade requests.
|
|
1437
|
+
async function cmdAdmin(action, a, b) {
|
|
1438
|
+
if (action === "plan") {
|
|
1439
|
+
if (!a || !b) die("usage: hush admin plan <@handle|team> <free|pro|team> [--days 30 | --until 2027-01-31] [--role trialing|active|comp] [--note \"...\"]");
|
|
1440
|
+
const status = ["trialing", "active", "comp"].includes(opts.role) ? opts.role : undefined;
|
|
1441
|
+
const d = await apiCall(`/api/admin`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ action: "set_plan", handle: a, plan: b, status, days: opts.days, until: opts.until === "never" ? null : opts.until, note: opts.note }) });
|
|
1442
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1443
|
+
return ok(`@${d.handle} (${d.kind}): ${d.from} → ${d.plan}${d.status ? ` (${d.status})` : ""}${d.until ? ` until ${d.until.slice(0, 10)}` : d.plan !== "free" ? " with no end date" : ""}`);
|
|
1444
|
+
}
|
|
1445
|
+
if (action === "requests" || action === "plans" || !action) {
|
|
1446
|
+
const d = await apiCall(`/api/admin`);
|
|
1447
|
+
const p = d.plans || { requests: [], changes: [], trialing: [] };
|
|
1448
|
+
if (JSON_OUT) return console.log(JSON.stringify(p));
|
|
1449
|
+
const open = p.requests.filter((r) => !r.handled_at);
|
|
1450
|
+
console.log(`\n upgrade requests (${open.length} open)`);
|
|
1451
|
+
for (const r of open) console.log(` ${r.created_at.slice(0, 16).replace("T", " ")} @${String(r.handle).padEnd(18)} ${r.plan.padEnd(5)} by @${r.by || "?"} → hush admin plan ${r.handle} ${r.plan} --days 30`);
|
|
1452
|
+
console.log(`\n on trial (${p.trialing.length})`);
|
|
1453
|
+
for (const t of p.trialing) console.log(` @${String(t.handle).padEnd(18)} ${t.plan.padEnd(5)} ${t.days_left}d left`);
|
|
1454
|
+
console.log(`\n recent changes`);
|
|
1455
|
+
for (const c of p.changes.slice(0, 10)) console.log(` ${c.created_at.slice(0, 16).replace("T", " ")} @${String(c.handle).padEnd(18)} ${c.from_plan || "free"} → ${c.to_plan} ${c.status || ""} ${c.source}${c.by ? " by @" + c.by : ""}`);
|
|
1456
|
+
console.log("");
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
die("usage: hush admin [requests | plan <handle> <free|pro|team> [--days N | --until DATE] [--role trialing|active|comp] [--note ...]]");
|
|
1460
|
+
}
|
|
1461
|
+
async function cmdShared() {
|
|
1462
|
+
const d = await apiCall(`/api/editors?mine=1`);
|
|
1463
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1464
|
+
if (!d.shared.length) { console.log("\n nobody has shared a drop with you yet\n"); return; }
|
|
1465
|
+
console.log("\n drops you can update:");
|
|
1466
|
+
for (const x of d.shared) console.log(` ${x.handle}/${x.slug} \x1b[2mhush <file> --to ${x.handle}/${x.slug}\x1b[0m`);
|
|
1467
|
+
console.log("");
|
|
1468
|
+
}
|
|
1469
|
+
async function cmdProtect(slug, onoff) {
|
|
1470
|
+
// View-only mode (Pro): no copy/save/print, blurs in the background, viewer-email watermark.
|
|
1471
|
+
if (!slug) die("usage: hush protect <slug> [on|off] (locked drops: republish with --protect)");
|
|
1472
|
+
const on = onoff !== "off";
|
|
1473
|
+
await patchSite(slug, { protect: on });
|
|
1474
|
+
if (JSON_OUT) return console.log(JSON.stringify({ slug, protect: on }));
|
|
1475
|
+
ok(on ? `view-only on for ${slug}. Unlocked drops get it now; for a locked drop republish with --protect` : `view-only off for ${slug}`);
|
|
1476
|
+
}
|
|
884
1477
|
async function cmdSetFeedback(slug, state) {
|
|
885
1478
|
if (!slug) die("usage: hush set-feedback <slug> [on|off]");
|
|
886
1479
|
const on = state !== "off";
|
|
@@ -912,6 +1505,290 @@ async function cmdShare(slug) {
|
|
|
912
1505
|
if (opts.revoke) return ok(`share token revoked for ${slug}`);
|
|
913
1506
|
ok(`revocable share link → ${d.url}\n revoke anytime: hush share ${slug} --revoke`);
|
|
914
1507
|
}
|
|
1508
|
+
async function cmdStats(slug) {
|
|
1509
|
+
// "Opened yet?" — views, unique viewers, first/last opened (+ referrers/countries on Pro).
|
|
1510
|
+
const d = await apiCall(slug ? `/api/stats?slug=${encodeURIComponent(slug)}` : `/api/stats`);
|
|
1511
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1512
|
+
const ago = (t) => { if (!t) return "never"; const m = Math.round((Date.now() - new Date(t)) / 60000); return m < 60 ? `${m}m ago` : m < 2880 ? `${Math.round(m / 60)}h ago` : `${Math.round(m / 1440)}d ago`; };
|
|
1513
|
+
if (!slug) {
|
|
1514
|
+
if (!d.drops?.length) return ok("no hosted drops yet");
|
|
1515
|
+
for (const s of d.drops) console.log(` ${s.opened ? "●" : "○"} ${s.slug.padEnd(28)} ${String(s.views).padStart(5)} views ${String(s.unique_viewers).padStart(4)} people last ${ago(s.last_viewed_at)}`);
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
console.log(`${d.opened ? "● opened" : "○ not opened yet"} ${d.url}`);
|
|
1519
|
+
console.log(` views ${d.views} · people ${d.unique_viewers} · first ${ago(d.first_viewed_at)} · last ${ago(d.last_viewed_at)}`);
|
|
1520
|
+
if (d.viewing_now) console.log(` viewing now: ${d.viewing_now}`);
|
|
1521
|
+
if (d.referrers?.length) console.log(` referrers: ${d.referrers.map((r) => `${r.name} ${r.views}`).join(", ")}`);
|
|
1522
|
+
if (d.countries?.length) console.log(` countries: ${d.countries.map((r) => `${r.name} ${r.views}`).join(", ")}`);
|
|
1523
|
+
if (d.pro_only) console.log(` referrers, countries and live viewers are Pro → ${d.upgrade}`);
|
|
1524
|
+
}
|
|
1525
|
+
async function cmdWebhook(sub, arg) {
|
|
1526
|
+
// Pro: signed HTTPS callbacks on drop.viewed / drop.first_opened / lead.captured.
|
|
1527
|
+
const J = { "content-type": "application/json" };
|
|
1528
|
+
let d;
|
|
1529
|
+
if (sub === "add") {
|
|
1530
|
+
if (!arg) die("usage: hush webhook add <https-url> [--slug <slug>] [--events drop.first_opened,lead.captured,drop.viewed]");
|
|
1531
|
+
d = await apiCall(`/api/webhooks`, { method: "POST", headers: J, body: JSON.stringify({ url: arg, slug: opts.slug, events: opts.events ? opts.events.split(",").map((e) => e.trim()) : undefined }) });
|
|
1532
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1533
|
+
return ok(`webhook ${d.id} → ${d.url}\n events: ${d.events.join(", ")}${d.slug ? ` (only ${d.slug})` : ""}\n signing secret (shown once): ${d.secret}\n verify: HMAC-SHA256(secret, "<t>.<body>") == v1 in X-Hushdrop-Signature`);
|
|
1534
|
+
}
|
|
1535
|
+
if (sub === "rm") { if (!arg) die("usage: hush webhook rm <id>"); d = await apiCall(`/api/webhooks?id=${encodeURIComponent(arg)}`, { method: "DELETE" }); if (JSON_OUT) return console.log(JSON.stringify(d)); return ok(`webhook ${arg} removed`); }
|
|
1536
|
+
if (sub === "test") { if (!arg) die("usage: hush webhook test <id>"); d = await apiCall(`/api/webhooks`, { method: "POST", headers: J, body: JSON.stringify({ id: arg, test: true }) }); if (JSON_OUT) return console.log(JSON.stringify(d)); return d.delivered ? ok(`test delivered (${d.status})`) : die(`test failed: ${d.error || d.status}`); }
|
|
1537
|
+
d = await apiCall(`/api/webhooks`);
|
|
1538
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1539
|
+
if (!d.webhooks.length) return ok("no webhooks — add one: hush webhook add https://example.com/hook");
|
|
1540
|
+
for (const h of d.webhooks) console.log(` ${h.id} ${h.url} [${h.events.join(",")}]${h.slug ? ` ${h.slug}` : ""}${h.disabled ? " DISABLED" : ""}${h.last_status ? ` last ${h.last_status}` : ""}`);
|
|
1541
|
+
}
|
|
1542
|
+
async function cmdAlerts(mode) {
|
|
1543
|
+
// Email when a drop is opened: off | first (free) | every new viewer (Pro). --slug for one drop.
|
|
1544
|
+
const d = mode
|
|
1545
|
+
? await apiCall(`/api/alerts`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ mode, slug: opts.slug }) })
|
|
1546
|
+
: await apiCall(`/api/alerts`);
|
|
1547
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1548
|
+
ok(`open alerts${d.slug ? ` on ${d.slug}` : ""}: ${d.mode}${d.email_enabled === false ? " (email sending is not configured on this server yet)" : ""}`);
|
|
1549
|
+
}
|
|
1550
|
+
async function cmdLeads(slug, state) {
|
|
1551
|
+
// Lead capture: ask viewers for their email (free) + custom fields (Pro) before the drop opens.
|
|
1552
|
+
if (!slug) die("usage: hush leads <slug> [on|off] [--fields name,company] [--csv]");
|
|
1553
|
+
if (state === "on" || state === "off") {
|
|
1554
|
+
const d = await apiCall(`/api/leads`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ slug, enabled: state === "on", ...(opts.fields !== undefined ? { fields: opts.fields ? opts.fields.split(",") : [] } : {}) }) });
|
|
1555
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1556
|
+
return ok(`lead capture ${d.lead_capture ? "on" : "off"} for ${slug}${d.fields?.length ? ` (asks: email, ${d.fields.join(", ")})` : ""}`);
|
|
1557
|
+
}
|
|
1558
|
+
if (opts.csv) {
|
|
1559
|
+
const key = getApiKey(); if (!key) die("not logged in — run: hush login");
|
|
1560
|
+
const r = await fetch(`${ORIGIN}/api/leads?slug=${encodeURIComponent(slug)}&format=csv`, { headers: { ...CLIENT_HEADERS, authorization: `Bearer ${key}` } });
|
|
1561
|
+
if (!r.ok) die(`request failed (${r.status})`);
|
|
1562
|
+
return process.stdout.write(await r.text() + "\n");
|
|
1563
|
+
}
|
|
1564
|
+
const d = await apiCall(`/api/leads?slug=${encodeURIComponent(slug)}`);
|
|
1565
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1566
|
+
console.log(`lead capture: ${d.lead_capture ? "on" : "off"}${d.email_gate ? ` · email gate @${d.email_gate}` : ""} · ${d.leads.length} lead(s)`);
|
|
1567
|
+
for (const l of d.leads) console.log(` ${l.at.slice(0, 16).replace("T", " ")} ${l.email}${l.verified ? " ✓" : ""}${Object.keys(l.fields).length ? " " + Object.values(l.fields).join(" · ") : ""}`);
|
|
1568
|
+
}
|
|
1569
|
+
async function cmdRecipients(slug) {
|
|
1570
|
+
// Who can open a drop: allow/block lists (Pro), named links per recipient (Pro), revoke one link (free).
|
|
1571
|
+
const J = { "content-type": "application/json" };
|
|
1572
|
+
if (opts.revokeLink) {
|
|
1573
|
+
const d = await apiCall(`/api/recipients?token=${encodeURIComponent(opts.revokeLink)}`, { method: "DELETE" });
|
|
1574
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1575
|
+
return ok(`link revoked (${d.slug})`);
|
|
1576
|
+
}
|
|
1577
|
+
if (!slug) die("usage: hush recipients <slug> [--allow a@x.com,@acme.com] [--block ...] [--link \"Ann at Acme\"] | --revoke-link <token>");
|
|
1578
|
+
let d;
|
|
1579
|
+
if (opts.invite) {
|
|
1580
|
+
d = await apiCall(`/api/recipients`, { method: "POST", headers: J, body: JSON.stringify({ slug, invite: opts.invite.split(","), message: opts.note }) });
|
|
1581
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1582
|
+
return ok(`invited ${d.invited.map((x) => x.email).join(", ")} to ${d.url}${d.email_enabled ? "\n they confirm their email with a one-time code when they open it" : "\n email sending isn't configured on this server: send them the link yourself"}`);
|
|
1583
|
+
}
|
|
1584
|
+
if (opts.link) {
|
|
1585
|
+
d = await apiCall(`/api/recipients`, { method: "POST", headers: J, body: JSON.stringify({ slug, link: opts.link }) });
|
|
1586
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1587
|
+
return ok(`link for ${d.label} → ${d.url}\n opens are counted per link: hush recipients ${slug}`);
|
|
1588
|
+
}
|
|
1589
|
+
if (opts.allow !== undefined || opts.block !== undefined) {
|
|
1590
|
+
const body = { slug };
|
|
1591
|
+
if (opts.allow !== undefined) body.allow = opts.allow === "off" ? [] : opts.allow.split(",");
|
|
1592
|
+
if (opts.block !== undefined) body.block = opts.block === "off" ? [] : opts.block.split(",");
|
|
1593
|
+
d = await apiCall(`/api/recipients`, { method: "POST", headers: J, body: JSON.stringify(body) });
|
|
1594
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1595
|
+
return ok(`${slug}: allow ${d.allow.length ? d.allow.join(", ") : "anyone"} · block ${d.block.length ? d.block.join(", ") : "none"}`);
|
|
1596
|
+
}
|
|
1597
|
+
d = await apiCall(`/api/recipients?slug=${encodeURIComponent(slug)}`);
|
|
1598
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1599
|
+
console.log(`allow: ${d.allow.length ? d.allow.join(", ") : "anyone with the link"}\nblock: ${d.block.length ? d.block.join(", ") : "none"}`);
|
|
1600
|
+
for (const l of d.links) console.log(` ${l.revoked ? "✕" : l.views ? "●" : "○"} ${(l.label || "(unnamed)").padEnd(24)} ${String(l.views).padStart(4)} opens ${l.url}${l.revoked ? " revoked" : ""}`);
|
|
1601
|
+
}
|
|
1602
|
+
async function cmdNda(slug, src) {
|
|
1603
|
+
// Pro: viewers must accept your terms (text or a .txt/.md file) before the drop opens.
|
|
1604
|
+
if (!slug || !src) die("usage: hush nda <slug> <terms.txt|\"terms text\"|off>");
|
|
1605
|
+
const nda = src === "off" ? null : existsSync(src) ? readFileSync(src, "utf8") : src;
|
|
1606
|
+
const d = await apiCall(`/api/leads`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ slug, nda }) });
|
|
1607
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1608
|
+
ok(d.nda ? `NDA gate on for ${slug}: viewers accept your terms before it opens (see who agreed: hush leads ${slug})` : `NDA gate off for ${slug}`);
|
|
1609
|
+
}
|
|
1610
|
+
async function cmdData(slug, mode) {
|
|
1611
|
+
// Pro: let a drop's own JS save JSON records (forms, RSVPs, votes); read them here.
|
|
1612
|
+
if (!slug) die("usage: hush data <slug> [collect|public|off] [--csv]");
|
|
1613
|
+
if (mode) {
|
|
1614
|
+
const d = await apiCall(`/api/data`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ slug, mode }) });
|
|
1615
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1616
|
+
return ok(mode === "off" ? `data store off for ${slug}` : `data store ${mode} for ${slug}\n from the page: ${d.usage}`);
|
|
1617
|
+
}
|
|
1618
|
+
if (opts.csv) {
|
|
1619
|
+
const key = getApiKey(); if (!key) die("not logged in — run: hush login");
|
|
1620
|
+
const r = await fetch(`${ORIGIN}/api/data?slug=${encodeURIComponent(slug)}&format=csv`, { headers: { ...CLIENT_HEADERS, authorization: `Bearer ${key}` } });
|
|
1621
|
+
if (!r.ok) die(`request failed (${r.status})`);
|
|
1622
|
+
return process.stdout.write(await r.text() + "\n");
|
|
1623
|
+
}
|
|
1624
|
+
const d = await apiCall(`/api/data?slug=${encodeURIComponent(slug)}`);
|
|
1625
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1626
|
+
console.log(`data store: ${d.mode} · ${d.records.length} record(s) · endpoint ${d.endpoint}`);
|
|
1627
|
+
for (const r of d.records.slice(0, 50)) console.log(` ${r.created_at.slice(0, 16).replace("T", " ")} ${JSON.stringify(r.data).slice(0, 120)}`);
|
|
1628
|
+
}
|
|
1629
|
+
async function cmdSecret(sub, name) {
|
|
1630
|
+
// Pro: store an API key server-side; a drop calls /api/proxy and the key never hits the browser.
|
|
1631
|
+
const J = { "content-type": "application/json" };
|
|
1632
|
+
let d;
|
|
1633
|
+
if (sub === "set") {
|
|
1634
|
+
if (!name || !opts.base) die("usage: hush secret set <NAME> --base https://api.example.com [--value <key> | stdin] [--slug s] [--header x-api-key --template '{value}']");
|
|
1635
|
+
let value = opts.value;
|
|
1636
|
+
if (!value && !process.stdin.isTTY) { let raw = ""; for await (const c of process.stdin) raw += c; value = raw.trim(); }
|
|
1637
|
+
if (!value) die("pass the key with --value or pipe it on stdin");
|
|
1638
|
+
d = await apiCall(`/api/secrets`, { method: "POST", headers: J, body: JSON.stringify({ name, value, base_url: opts.base, slug: opts.slug, header: opts.header, template: opts.template }) });
|
|
1639
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1640
|
+
return ok(`secret ${d.name} saved (only for ${d.base_url})\n from the page: ${d.usage}`);
|
|
1641
|
+
}
|
|
1642
|
+
if (sub === "rm") { if (!name) die("usage: hush secret rm <NAME>"); d = await apiCall(`/api/secrets?name=${encodeURIComponent(name)}`, { method: "DELETE" }); if (JSON_OUT) return console.log(JSON.stringify(d)); return ok(`secret ${name} removed`); }
|
|
1643
|
+
d = await apiCall(`/api/secrets`);
|
|
1644
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1645
|
+
if (!d.secrets.length) return ok("no secrets — add one: hush secret set OPENAI_KEY --base https://api.openai.com < key.txt");
|
|
1646
|
+
for (const x of d.secrets) console.log(` ${x.name.padEnd(22)} ${x.base_url}${x.slug ? ` (only ${x.slug})` : ""} ${x.calls} calls`);
|
|
1647
|
+
}
|
|
1648
|
+
async function cmdPortal(sub, a, b) {
|
|
1649
|
+
// Pro: one permanent link per client that lists every drop you add to it.
|
|
1650
|
+
const J = { "content-type": "application/json" };
|
|
1651
|
+
const find = async (ref) => { const d = await apiCall(`/api/portals`); const p = d.portals.find((x) => x.id === ref || x.name.toLowerCase() === String(ref).toLowerCase()); if (!p) die(`no portal "${ref}" (hush portal list)`); return p; };
|
|
1652
|
+
let d;
|
|
1653
|
+
if (sub === "create") {
|
|
1654
|
+
if (!a) die('usage: hush portal create "Acme Corp" [--note "text"]');
|
|
1655
|
+
d = await apiCall(`/api/portals`, { method: "POST", headers: J, body: JSON.stringify({ name: a, note: opts.note }) });
|
|
1656
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1657
|
+
return ok(`portal "${d.name}" → ${d.url}\n add drops: hush portal add "${d.name}" <slug>`);
|
|
1658
|
+
}
|
|
1659
|
+
if (sub === "add" || sub === "remove") {
|
|
1660
|
+
if (!a || !b) die(`usage: hush portal ${sub} <portal> <slug>${sub === "add" ? " [--label \"Q3 proposal\"]" : ""}`);
|
|
1661
|
+
const p = await find(a);
|
|
1662
|
+
d = await apiCall(`/api/portals`, { method: "POST", headers: J, body: JSON.stringify({ id: p.id, [sub]: b, label: opts.label }) });
|
|
1663
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1664
|
+
return ok(`${sub === "add" ? "added" : "removed"} ${b} ${sub === "add" ? "to" : "from"} "${p.name}" (${p.url})`);
|
|
1665
|
+
}
|
|
1666
|
+
if (sub === "rm") { if (!a) die("usage: hush portal rm <portal>"); const p = await find(a); d = await apiCall(`/api/portals?id=${p.id}`, { method: "DELETE" }); if (JSON_OUT) return console.log(JSON.stringify(d)); return ok(`portal "${p.name}" deleted (its drops are untouched)`); }
|
|
1667
|
+
d = await apiCall(`/api/portals`);
|
|
1668
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1669
|
+
if (!d.portals.length) return ok('no portals yet: hush portal create "Acme Corp"');
|
|
1670
|
+
for (const p of d.portals) console.log(` ${p.name.padEnd(24)} ${p.url} ${p.drops.length} drop(s)${p.drops.length ? ": " + p.drops.map((x) => x.slug).join(", ") : ""}`);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
async function cmdComments(slug, sub, id) {
|
|
1674
|
+
// Pinned viewer comments on a hosted drop. Agents: read them, fix the page, republish
|
|
1675
|
+
// with the same slug, then resolve them.
|
|
1676
|
+
if (!slug) die("usage: hush comments <slug> [on|off|resolve <id|all>] [--json]");
|
|
1677
|
+
const J = { "content-type": "application/json" };
|
|
1678
|
+
let d;
|
|
1679
|
+
if (sub === "on" || sub === "off") {
|
|
1680
|
+
await patchSite(slug, { feedback: sub === "on" });
|
|
1681
|
+
if (JSON_OUT) return console.log(JSON.stringify({ slug, comments: sub === "on" }));
|
|
1682
|
+
return ok(sub === "on" ? `comments on for ${slug}. Unlocked drops get the widget now; for a locked drop republish with --comments` : `comments off for ${slug}`);
|
|
1683
|
+
}
|
|
1684
|
+
if (sub === "resolve") {
|
|
1685
|
+
d = await apiCall(`/api/comments`, { method: "POST", headers: J, body: JSON.stringify({ slug, resolve: id || "all" }) });
|
|
1686
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1687
|
+
return ok(`resolved ${d.resolved} comment(s) on ${slug}`);
|
|
1688
|
+
}
|
|
1689
|
+
d = await apiCall(`/api/comments?slug=${encodeURIComponent(slug)}`);
|
|
1690
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1691
|
+
const open = d.comments.filter((c) => !c.resolved_at);
|
|
1692
|
+
if (!open.length) return ok(`no open comments on ${slug}`);
|
|
1693
|
+
for (const c of open) console.log(` #${c.id} ${c.author || "anonymous"}: ${c.body}\n at ${c.selector || "?"}${c.snippet ? ` "${c.snippet.slice(0, 80)}"` : ""}`);
|
|
1694
|
+
console.log(`\n fix, republish (hush <file> -s ${slug}), then: hush comments ${slug} resolve all`);
|
|
1695
|
+
}
|
|
1696
|
+
async function cmdAnalyticsTag(slug, tag) {
|
|
1697
|
+
// Pro: your own GA4 or Plausible on a drop (or every drop with --all).
|
|
1698
|
+
if ((!slug && !opts.all) || !(tag || (opts.all && slug))) die("usage: hush analytics-tag <slug> <G-XXXX|plausible:domain|off> or hush analytics-tag --all <tag>");
|
|
1699
|
+
const t = opts.all && !tag ? slug : tag;
|
|
1700
|
+
const d = await apiCall(`/api/analytics-tag`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(opts.all ? { all: true, tag: t } : { slug, tag: t }) });
|
|
1701
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1702
|
+
ok(d.tag ? `analytics tag ${d.tag} on ${d.drops.length} drop(s)` : `analytics tag removed from ${d.drops.length} drop(s)`);
|
|
1703
|
+
}
|
|
1704
|
+
async function cmdTemplate(sub, arg) {
|
|
1705
|
+
// Starter HTML templates (proposal, SOW, deck, status report...). Fill the {{placeholders}}, then: hush <file>.
|
|
1706
|
+
// Reads ../templates from a checkout; an npm install fetches the same files from hushdrop.dev/templates.
|
|
1707
|
+
// --team <handle>: the team's own saved templates (hush template save <file> --team <h> --name <id>).
|
|
1708
|
+
if (opts.team || sub === "save") return cmdTeamTemplate(sub, arg);
|
|
1709
|
+
const local = join(__dirname, "..", "templates");
|
|
1710
|
+
const remote = (process.env.HUSHDROP_TEMPLATES_URL || "https://hushdrop.dev/templates").replace(/\/$/, "");
|
|
1711
|
+
const get = async (file) => {
|
|
1712
|
+
if (existsSync(join(local, file))) return readFileSync(join(local, file), "utf8");
|
|
1713
|
+
let r; try { r = await fetch(`${remote}/${file}`, { headers: CLIENT_HEADERS }); } catch (e) { die(`could not reach ${remote}: ${e.message}`); }
|
|
1714
|
+
if (!r.ok) die(`could not fetch ${remote}/${file} (${r.status})`);
|
|
1715
|
+
return r.text();
|
|
1716
|
+
};
|
|
1717
|
+
const index = JSON.parse(await get("index.json"));
|
|
1718
|
+
if (!sub || sub === "list" || sub === "ls") {
|
|
1719
|
+
const list = index.templates.map(({ id, title, job, industry, description, placeholders }) => ({ id, title, job, industry, description, placeholders }));
|
|
1720
|
+
if (JSON_OUT) return console.log(JSON.stringify({ templates: list }));
|
|
1721
|
+
for (const t of list) console.log(` ${t.id.padEnd(16)} ${t.title.padEnd(22)} ${t.job} · ${t.industry}`);
|
|
1722
|
+
return console.log(`\n get one: hush template <id> -o file.html then fill the {{placeholders}} and run: hush file.html\n preview: ${remote.replace(/\/templates$/, "")}/templates`);
|
|
1723
|
+
}
|
|
1724
|
+
const t = index.templates.find((x) => x.id === sub);
|
|
1725
|
+
if (!t) die(`no template "${sub}". Available: ${index.templates.map((x) => x.id).join(", ")}`);
|
|
1726
|
+
const html = await get(t.file);
|
|
1727
|
+
if (opts.out) {
|
|
1728
|
+
if (existsSync(opts.out) && !opts.force) die(`${opts.out} already exists (pass --force to overwrite)`);
|
|
1729
|
+
writeFileSync(opts.out, html);
|
|
1730
|
+
if (JSON_OUT) return console.log(JSON.stringify({ id: t.id, path: opts.out, placeholders: t.placeholders }));
|
|
1731
|
+
return ok(`${t.title} → ${opts.out}\n fill ${t.placeholders.length} {{placeholders}}, then publish: hush ${opts.out}`);
|
|
1732
|
+
}
|
|
1733
|
+
if (JSON_OUT) return console.log(JSON.stringify({ id: t.id, title: t.title, placeholders: t.placeholders, html }));
|
|
1734
|
+
process.stdout.write(html);
|
|
1735
|
+
}
|
|
1736
|
+
async function cmdTeamTemplate(sub, arg) {
|
|
1737
|
+
const team = String(opts.team || "").replace(/^@/, "");
|
|
1738
|
+
if (!team) die("usage: hush template save <file.html> --team <handle> --name <id> [--title \"...\"]");
|
|
1739
|
+
const q = `team=${encodeURIComponent(team)}`;
|
|
1740
|
+
if (sub === "save") {
|
|
1741
|
+
if (!arg || !existsSync(arg)) die("usage: hush template save <file.html> --team <handle> --name <id> [--title \"...\"]");
|
|
1742
|
+
const id = String(opts.name || basename(arg).replace(/\.[^.]+$/, "")).toLowerCase();
|
|
1743
|
+
const d = await apiCall(`/api/team-templates`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ team, id, title: opts.title, html: readFileSync(arg, "utf8") }) });
|
|
1744
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1745
|
+
return ok(`${d.replaced ? "updated" : "saved"} template ${d.id} on @${d.team}\n teammates use it with: ${d.use_with}`);
|
|
1746
|
+
}
|
|
1747
|
+
if (sub === "rm") {
|
|
1748
|
+
if (!arg) die("usage: hush template rm <id> --team <handle>");
|
|
1749
|
+
const d = await apiCall(`/api/team-templates?${q}&id=${encodeURIComponent(arg)}`, { method: "DELETE" });
|
|
1750
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1751
|
+
return ok(`removed template ${d.removed} from @${d.team}`);
|
|
1752
|
+
}
|
|
1753
|
+
if (!sub || sub === "list" || sub === "ls") {
|
|
1754
|
+
const d = await apiCall(`/api/team-templates?${q}`);
|
|
1755
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1756
|
+
if (!d.templates.length) return ok(`@${d.team} has no templates yet — save one: hush template save page.html --team ${d.team} --name <id>`);
|
|
1757
|
+
for (const t of d.templates) console.log(` ${t.id.padEnd(24)} ${(t.title || "").padEnd(28)} ${t.created_by ? "@" + t.created_by : ""} ${String(t.updated_at || "").slice(0, 10)}`);
|
|
1758
|
+
return console.log(`\n get one: hush template <id> --team ${d.team} -o file.html`);
|
|
1759
|
+
}
|
|
1760
|
+
const d = await apiCall(`/api/team-templates?${q}&id=${encodeURIComponent(sub)}`);
|
|
1761
|
+
if (opts.out) {
|
|
1762
|
+
if (existsSync(opts.out) && !opts.force) die(`${opts.out} already exists (pass --force to overwrite)`);
|
|
1763
|
+
writeFileSync(opts.out, d.html);
|
|
1764
|
+
if (JSON_OUT) return console.log(JSON.stringify({ team: d.team, id: d.id, title: d.title, path: opts.out }));
|
|
1765
|
+
return ok(`@${d.team}/${d.id} → ${opts.out}\n fill it in, then publish: hush ${opts.out} --to ${d.team}`);
|
|
1766
|
+
}
|
|
1767
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1768
|
+
process.stdout.write(d.html);
|
|
1769
|
+
}
|
|
1770
|
+
async function cmdRules() {
|
|
1771
|
+
// Rules for writing pages that work as drops (sandbox, CSP, phone, dark mode, print).
|
|
1772
|
+
// --team <h>: plus that team's house style (members only).
|
|
1773
|
+
const team = opts.team ? String(opts.team).replace(/^@/, "") : "";
|
|
1774
|
+
const qs = [JSON_OUT ? "format=json" : "", team ? `team=${encodeURIComponent(team)}` : ""].filter(Boolean).join("&");
|
|
1775
|
+
const headers = { ...CLIENT_HEADERS };
|
|
1776
|
+
if (team) { const key = getApiKey(); if (!key) die("not logged in — run: hush login"); headers.authorization = `Bearer ${key}`; }
|
|
1777
|
+
const r = await fetch(`${ORIGIN}/api/page-rules${qs ? "?" + qs : ""}`, { headers }).catch(() => null);
|
|
1778
|
+
if (!r) die("could not fetch the page rules");
|
|
1779
|
+
if (!r.ok) { let e = {}; try { e = await r.json(); } catch {} die(e.error || `could not fetch the page rules (${r.status})`); }
|
|
1780
|
+
if (JSON_OUT) return console.log(JSON.stringify(await r.json()));
|
|
1781
|
+
console.log(await r.text());
|
|
1782
|
+
}
|
|
1783
|
+
async function cmdSearch(words, o) {
|
|
1784
|
+
// Find drops across your personal space and teams (locked drops: title/slug only).
|
|
1785
|
+
const q = [words, ...rest.slice(1)].filter(Boolean).join(" ");
|
|
1786
|
+
if (!q) die("usage: hush search <words> [--to <team>]");
|
|
1787
|
+
const d = await apiCall(`/api/search?q=${encodeURIComponent(q)}${o.to ? `&space=${encodeURIComponent(o.to.replace(/^@/, ""))}` : ""}`);
|
|
1788
|
+
if (JSON_OUT) return console.log(JSON.stringify(d));
|
|
1789
|
+
if (!d.results.length) return ok(`nothing matches "${q}" in ${d.spaces.map((h) => "@" + h).join(", ")}`);
|
|
1790
|
+
for (const r of d.results) console.log(` ${r.locked ? "🔒" : " "} ${r.title || r.slug} \x1b[2m${r.url}\x1b[0m${r.snippet ? `\n ${r.snippet}` : ""}`);
|
|
1791
|
+
}
|
|
915
1792
|
async function cmdMigrate() {
|
|
916
1793
|
// Re-home your hosted drops onto your own Vercel Blob, then rewrite config to self-host.
|
|
917
1794
|
const sites = (await apiCall("/api/sites")).sites || [];
|
|
@@ -939,28 +1816,69 @@ const { values, positionals } = parseArgs({
|
|
|
939
1816
|
title: { type: "string", short: "t" },
|
|
940
1817
|
page: { type: "boolean" },
|
|
941
1818
|
"no-lock": { type: "boolean" },
|
|
1819
|
+
comments: { type: "boolean" },
|
|
1820
|
+
protect: { type: "boolean" },
|
|
1821
|
+
label: { type: "string" },
|
|
1822
|
+
all: { type: "boolean" },
|
|
942
1823
|
token: { type: "string" },
|
|
943
1824
|
domain: { type: "string" },
|
|
944
1825
|
"blob-host": { type: "string" },
|
|
945
1826
|
project: { type: "string" },
|
|
946
1827
|
org: { type: "string" },
|
|
947
1828
|
json: { type: "boolean" },
|
|
1829
|
+
pin: { type: "boolean" },
|
|
1830
|
+
unpin: { type: "boolean" },
|
|
948
1831
|
expire: { type: "string" },
|
|
949
1832
|
"dry-run": { type: "boolean" },
|
|
950
1833
|
"no-deploy": { type: "boolean" },
|
|
951
1834
|
managed: { type: "boolean" },
|
|
952
1835
|
burn: { type: "boolean" },
|
|
953
1836
|
"email-gate": { type: "string" },
|
|
1837
|
+
to: { type: "string" },
|
|
1838
|
+
role: { type: "string" },
|
|
1839
|
+
add: { type: "string" },
|
|
1840
|
+
days: { type: "string" },
|
|
1841
|
+
until: { type: "string" },
|
|
1842
|
+
note: { type: "string" },
|
|
1843
|
+
yearly: { type: "boolean" },
|
|
1844
|
+
yes: { type: "boolean", short: "y" },
|
|
1845
|
+
start: { type: "boolean" },
|
|
1846
|
+
finish: { type: "boolean" },
|
|
1847
|
+
with: { type: "string" },
|
|
1848
|
+
"metadata-url": { type: "string" },
|
|
1849
|
+
"metadata-file": { type: "string" },
|
|
1850
|
+
wait: { type: "string" },
|
|
954
1851
|
revoke: { type: "boolean" },
|
|
955
1852
|
"no-pii-check": { type: "boolean" },
|
|
956
1853
|
"block-pii": { type: "boolean" },
|
|
1854
|
+
events: { type: "string" },
|
|
1855
|
+
fields: { type: "string" },
|
|
1856
|
+
notify: { type: "string" },
|
|
1857
|
+
csv: { type: "boolean" },
|
|
1858
|
+
allow: { type: "string" },
|
|
1859
|
+
block: { type: "string" },
|
|
1860
|
+
link: { type: "string" },
|
|
1861
|
+
resend: { type: "string" },
|
|
1862
|
+
"revoke-invite": { type: "string" },
|
|
1863
|
+
"revoke-link": { type: "string" },
|
|
1864
|
+
invite: { type: "string" },
|
|
1865
|
+
note: { type: "string" },
|
|
1866
|
+
base: { type: "string" },
|
|
1867
|
+
value: { type: "string" },
|
|
1868
|
+
header: { type: "string" },
|
|
1869
|
+
template: { type: "string" },
|
|
1870
|
+
team: { type: "string" },
|
|
1871
|
+
out: { type: "string", short: "o" },
|
|
1872
|
+
team: { type: "string" },
|
|
1873
|
+
name: { type: "string" },
|
|
1874
|
+
force: { type: "boolean" },
|
|
957
1875
|
help: { type: "boolean", short: "h" },
|
|
958
1876
|
},
|
|
959
1877
|
});
|
|
960
1878
|
const JSON_OUT = !!values.json;
|
|
961
1879
|
|
|
962
1880
|
const [cmd, ...rest] = positionals;
|
|
963
|
-
const opts = { password: values.password, slug: values.slug, title: values.title, page: values.page, noLock: values["no-lock"], token: values.token, domain: values.domain, blobHost: values["blob-host"], project: values.project, org: values.org, expire: values.expire, dryRun: values["dry-run"], noDeploy: values["no-deploy"], managed: values.managed, burn: values.burn, emailGate: values["email-gate"], revoke: values.revoke, noPiiCheck: values["no-pii-check"], blockPii: values["block-pii"] };
|
|
1881
|
+
const opts = { with: values.with, to: values.to, role: values.role, password: values.password, slug: values.slug, title: values.title, page: values.page, noLock: values["no-lock"], token: values.token, domain: values.domain, blobHost: values["blob-host"], project: values.project, org: values.org, expire: values.expire, dryRun: values["dry-run"], noDeploy: values["no-deploy"], managed: values.managed, burn: values.burn, emailGate: values["email-gate"], revoke: values.revoke, add: values.add, days: values.days, until: values.until, note: values.note, yearly: values.yearly, yes: values.yes, start: values.start, finish: values.finish, wait: values.wait, noPiiCheck: values["no-pii-check"], blockPii: values["block-pii"], events: values.events, fields: values.fields, csv: values.csv, allow: values.allow, block: values.block, link: values.link, revokeLink: values["revoke-link"], base: values.base, value: values.value, header: values.header, template: values.template, invite: values.invite, out: values.out, force: values.force, team: values.team, name: values.name, pin: values.pin, unpin: values.unpin, notify: values.notify, comments: values.comments, protect: values.protect, label: values.label, all: values.all, metadataUrl: values["metadata-url"], metadataFile: values["metadata-file"], resend: values.resend, revokeInvite: values["revoke-invite"] };
|
|
964
1882
|
|
|
965
1883
|
try {
|
|
966
1884
|
if (cmd === "init") await cmdInit(opts);
|
|
@@ -975,15 +1893,41 @@ try {
|
|
|
975
1893
|
else if (cmd === "claim") await cmdClaim(rest[0]);
|
|
976
1894
|
else if (cmd === "share") await cmdShare(rest[0]);
|
|
977
1895
|
else if (cmd === "migrate") await cmdMigrate();
|
|
1896
|
+
else if (cmd === "portal" || cmd === "portals") await cmdPortal(rest[0], rest[1], rest[2]);
|
|
1897
|
+
else if (cmd === "analytics-tag") await cmdAnalyticsTag(rest[0], rest[1]);
|
|
1898
|
+
else if (cmd === "comments") await cmdComments(rest[0], rest[1], rest[2]);
|
|
1899
|
+
else if (cmd === "search") await cmdSearch(rest[0], opts);
|
|
1900
|
+
else if (cmd === "rules") await cmdRules();
|
|
1901
|
+
else if (cmd === "secret" || cmd === "secrets") await cmdSecret(rest[0], rest[1]);
|
|
1902
|
+
else if (cmd === "template" || cmd === "templates") await cmdTemplate(rest[0], rest[1]);
|
|
1903
|
+
else if (cmd === "data") await cmdData(rest[0], rest[1]);
|
|
1904
|
+
else if (cmd === "nda") await cmdNda(rest[0], rest[1]);
|
|
1905
|
+
else if (cmd === "recipients") await cmdRecipients(rest[0]);
|
|
1906
|
+
else if (cmd === "leads") await cmdLeads(rest[0], rest[1]);
|
|
1907
|
+
else if (cmd === "alerts") await cmdAlerts(rest[0]);
|
|
1908
|
+
else if (cmd === "webhook" || cmd === "webhooks") await cmdWebhook(rest[0], rest[1]);
|
|
1909
|
+
else if (cmd === "stats" || cmd === "opened") await cmdStats(rest[0]);
|
|
978
1910
|
else if (cmd === "set-expiry") await cmdSetExpiry(rest[0], rest[1]);
|
|
979
1911
|
else if (cmd === "set-email-gate") await cmdSetEmailGate(rest[0], rest[1]);
|
|
980
1912
|
else if (cmd === "set-feedback") await cmdSetFeedback(rest[0], rest[1]);
|
|
1913
|
+
else if (cmd === "protect" || cmd === "view-only") await cmdProtect(rest[0], rest[1]);
|
|
1914
|
+
else if (cmd === "versions") await cmdVersions(rest[0], opts);
|
|
1915
|
+
else if (cmd === "rollback") await cmdRollback(rest[0], rest[1], opts);
|
|
1916
|
+
else if (cmd === "editors") await cmdEditors(rest[0], rest[1], rest[2], opts);
|
|
1917
|
+
else if (cmd === "domains") await cmdDomains(rest[0], rest[1], rest[2], opts);
|
|
1918
|
+
else if (cmd === "shared") await cmdShared();
|
|
1919
|
+
else if (cmd === "billing") await cmdBilling(rest[0]);
|
|
1920
|
+
else if (cmd === "admin") await cmdAdmin(rest[0], rest[1], rest[2]);
|
|
1921
|
+
else if (cmd === "upgrade") await cmdUpgrade(rest[0] === "team" ? "team" : "pro", rest[0] === "team" ? rest[1] : undefined);
|
|
1922
|
+
else if (cmd === "team") await cmdTeam(rest[0], rest[1], rest[2], { ...opts, _rest: rest.slice(2) });
|
|
1923
|
+
else if (cmd === "use") await cmdUse(rest[0]);
|
|
981
1924
|
else if (cmd === "set-password") await cmdSetPassword(rest[0], rest[1]);
|
|
982
1925
|
else if (values.help || cmd === "help" || cmd === "--help" || !cmd) {
|
|
983
1926
|
console.log(`hush — branded password-protected sharing on ${DOMAIN}
|
|
984
1927
|
|
|
985
1928
|
hush <file.html|.md> brand + lock (auto password) + upload → clean URL
|
|
986
1929
|
hush <file> --managed zero-setup: publish to the managed tier (no Vercel needed)
|
|
1930
|
+
hush <file> --managed --notify you@x.com email me when it's opened + a link to keep it
|
|
987
1931
|
hush <file> -p secret use your own password
|
|
988
1932
|
hush <file> --no-lock brand only, no password (renders for anyone)
|
|
989
1933
|
hush <file> --expire 7d auto-expire (7d/24h/30m/2w/date); enforce with 'hush gc'
|
|
@@ -992,7 +1936,8 @@ try {
|
|
|
992
1936
|
hush <file> --block-pii refuse to publish if a secret/credential is detected
|
|
993
1937
|
hush <file> --page branded download page wrapping the file
|
|
994
1938
|
hush <file> --page -p secret password-protect the download page
|
|
995
|
-
hush site.zip
|
|
1939
|
+
hush <dir>|<site.zip> publish a whole static site → /slug/ (folder or zip)
|
|
1940
|
+
hush <dir> -p secret lock the whole site behind a password (self-host)
|
|
996
1941
|
hush <file> raw file, unguessable URL
|
|
997
1942
|
hush -s myslug <file> force the slug
|
|
998
1943
|
hush list list live drops (from the store, cross-machine)
|
|
@@ -1000,15 +1945,73 @@ try {
|
|
|
1000
1945
|
hush gc delete drops whose --expire has passed (cron-friendly)
|
|
1001
1946
|
hush init --domain ... point hush at your own domain + Vercel Blob (BYO)
|
|
1002
1947
|
hush login sign in (magic-link) to host on Hushdrop + persist your drops
|
|
1948
|
+
hush login --with google|microsoft|sso sign in with your work account (joins your company's team)
|
|
1003
1949
|
hush whoami show your hosted account (email + handle)
|
|
1004
1950
|
hush logout clear your hosted account (forget the API key)
|
|
1005
1951
|
hush claim <url|slug> move an anonymous /u/ drop into your account
|
|
1006
1952
|
hush share <slug> [--revoke] mint (or revoke) a revocable guest share link
|
|
1953
|
+
hush stats [slug] [--json] opened yet? views, people, last opened (all drops, or one)
|
|
1954
|
+
hush webhook add <url> [--slug s] [--events a,b] signed callbacks on opens/leads (Pro)
|
|
1955
|
+
hush webhook [list|rm <id>|test <id>] manage webhooks
|
|
1956
|
+
hush alerts [off|first|every] [--slug s] email me when a drop is opened (every viewer: Pro)
|
|
1957
|
+
hush leads <slug> on [--fields name,company] ask viewers for email (+ fields, Pro) first
|
|
1958
|
+
hush leads <slug> [--csv] list captured leads (or export CSV)
|
|
1959
|
+
hush recipients <slug> who can open it + per-recipient links and opens
|
|
1960
|
+
hush recipients <slug> --allow a@x.com,@acme.com only these may open it (Pro; --block too; "off" clears)
|
|
1961
|
+
hush recipients <slug> --link "Ann at Acme" named link for one recipient (Pro)
|
|
1962
|
+
hush recipients <slug> --invite a@x.com,b@y.com [--note "msg"] email them the link; they verify with a code
|
|
1963
|
+
hush recipients --revoke-link <token> kill one guest link, keep the others
|
|
1964
|
+
hush nda <slug> <terms.txt|off> viewers accept your terms before it opens (Pro)
|
|
1965
|
+
hush data <slug> collect|public|off let the page save JSON (forms, RSVPs) (Pro)
|
|
1966
|
+
hush data <slug> [--csv] read what the page collected
|
|
1967
|
+
hush secret set <NAME> --base <url> < key keep an API key server-side for drops to call (Pro)
|
|
1968
|
+
hush secret [list|rm <NAME>] manage proxy secrets
|
|
1969
|
+
hush portal create "Acme Corp" one permanent link per client listing their drops (Pro)
|
|
1970
|
+
hush portal add "Acme Corp" <slug> [--label "Q3 proposal"] (also: remove, rm, list)
|
|
1971
|
+
hush <file> --comments let viewers pin comments on the page (hosted drops)
|
|
1972
|
+
hush comments <slug> [on|off] read viewer comments (with where they were pinned) / toggle
|
|
1973
|
+
hush comments <slug> resolve <id|all> mark comments done after you republish
|
|
1974
|
+
hush analytics-tag <slug|--all> <G-XXXX|plausible:domain|off> your own GA4/Plausible (Pro)
|
|
1975
|
+
hush template list [--json] starter pages: proposal, sow, pitch-deck, status-report, ...
|
|
1976
|
+
hush template <id> [-o file.html] write a template (stdout without -o); fill {{placeholders}}, then hush file.html
|
|
1977
|
+
hush rules [--json] [--team h] how to write a page that works as a drop (read before generating); --team adds its house style
|
|
1978
|
+
hush team style <team> [style.md|off] set the house style agents follow when publishing into a team (admin+, paid team)
|
|
1979
|
+
hush template save <file> --team <h> --name <id> [--title ..] save a page as a team template (editor+, paid team)
|
|
1980
|
+
hush template [list|<id>|rm <id>] --team <h> the team's own templates
|
|
1981
|
+
hush rules [--json] how to write a page that works as a drop (read before generating)
|
|
1982
|
+
hush search <words> [--to team] find drops across your space and teams (locked: title only)
|
|
1007
1983
|
hush migrate [--dry-run] re-home your hosted drops to your own blob (self-host)
|
|
1008
1984
|
hush set-expiry <slug> <when> change a hosted drop's expiry (7d/24h/date/off)
|
|
1009
1985
|
hush set-email-gate <slug> <domain> restrict a hosted drop to one email domain
|
|
1010
1986
|
hush set-password <slug> <file> re-encrypt a hosted drop with a new password
|
|
1011
1987
|
hush set-feedback <slug> [on|off] toggle the feedback widget on a hosted drop
|
|
1988
|
+
hush <file> --protect view-only: no copy/save/print, viewer-email watermark (Pro)
|
|
1989
|
+
hush protect <slug> [on|off] turn view-only on or off for a hosted drop
|
|
1990
|
+
hush versions <slug> [--to <handle>] list a hosted drop's version history
|
|
1991
|
+
hush rollback <slug> <n> [--pin] [--to ...] make version n live again; --pin keeps it live through new publishes
|
|
1992
|
+
hush versions <slug> --unpin put the latest version back live
|
|
1993
|
+
hush editors add <slug> @handle let someone update this one drop
|
|
1994
|
+
hush editors <slug> who can update it
|
|
1995
|
+
hush editors rm <slug> @handle revoke (or leave, with --to <owner>)
|
|
1996
|
+
hush shared drops others let you update
|
|
1997
|
+
hush domains add share.acme.com serve your drops on your own domain (Pro/Team)
|
|
1998
|
+
hush domains add docs.acme.com <slug> …or just one drop at that domain's root
|
|
1999
|
+
hush domains [status <d> | rm <d>] list, check DNS/HTTPS, disconnect (--to <team>)
|
|
2000
|
+
hush team your personal space + teams (● = active)
|
|
2001
|
+
hush team create <handle> create a team space (hushdrop.dev/<handle>/...)
|
|
2002
|
+
hush use <team> | personal switch where publishes go by default
|
|
2003
|
+
hush team members <team> who's on a team
|
|
2004
|
+
hush team invite <team> ann@acme.com [more…] [--role editor|admin] [--note "…"] email invites; they sign up from the link
|
|
2005
|
+
hush team invites <team> pending invites + invite link · --link on|off|reset · --revoke-invite <id> · --resend <id>
|
|
2006
|
+
hush team add <team> @handle [--role editor|admin|owner]
|
|
2007
|
+
hush team rm <team> @handle remove a member · hush team leave <team>
|
|
2008
|
+
hush team domain <team> acme.com anyone signing in with a verified @acme.com address joins (Team)
|
|
2009
|
+
hush team sso <team> --metadata-url URL SAML SSO through your identity provider (Team add-on)
|
|
2010
|
+
hush team delete <team> --yes delete a team and every drop in it (owners)
|
|
2011
|
+
hush team upgrade <team> [--add @h] Team plan: $29/mo flat, unlimited members (14 days free, no card)
|
|
2012
|
+
hush upgrade Pro for your personal space ($9/mo)
|
|
2013
|
+
hush billing [team] plan + renewal; opens Stripe to change card or cancel
|
|
2014
|
+
hush <file> --to <owner>/<slug> update a drop someone shared with you
|
|
1012
2015
|
hush setup [--token <tok>] provision a machine (deps + blob token)
|
|
1013
2016
|
hush deploy [--domain ...] wire backend (blob host → middleware/vercel.json) + deploy`);
|
|
1014
2017
|
} else {
|