mnfst-publish 0.1.15 → 0.1.17
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 +6 -0
- package/manifest.publish.mjs +166 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,5 +15,11 @@ project, zips it gitignore-aware, uploads it, and prints the live URL.
|
|
|
15
15
|
Flags: `--staging` / `--production` (default), `--no-render`, `--promote`,
|
|
16
16
|
`--source render|spa` (auto-detected), `--key <key>`, `--mcp <url>`.
|
|
17
17
|
|
|
18
|
+
Publishing from Claude with the Manifest connector needs no key: the command it
|
|
19
|
+
gives you carries a one-time upload link. While the site renders, mnfst-publish
|
|
20
|
+
keeps that link alive (up to 3 hours). If a link still expires, ask Claude to
|
|
21
|
+
publish again and add `--no-render` to the new command, so the site already
|
|
22
|
+
rendered on disk uploads without rendering again.
|
|
23
|
+
|
|
18
24
|
Zero dependencies, cross-platform (pure-Node zip). `.env`, `.env.*`, `.claude/`,
|
|
19
25
|
keys and credential files are never uploaded.
|
package/manifest.publish.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// the MCP publish handshake, renders if needed, zips gitignore-aware, uploads,
|
|
7
7
|
// and prints the live URL. Zero npm deps; cross-platform (pure-Node zip).
|
|
8
8
|
|
|
9
|
-
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
10
10
|
import { createHash } from 'node:crypto';
|
|
11
11
|
import { deflateRawSync } from 'node:zlib';
|
|
12
12
|
import { readFileSync, existsSync, statSync, readdirSync } from 'node:fs';
|
|
@@ -192,7 +192,7 @@ async function callTool(url, key, name, args) {
|
|
|
192
192
|
// Never ship local config or secrets — matched at ANY depth (by path segment /
|
|
193
193
|
// basename), not just the project root. A nested `api/.env` or `sub/.claude/…`
|
|
194
194
|
// must be excluded too. Mirrors the server's ingest drop list.
|
|
195
|
-
const EXCLUDED_DIRS = new Set(['.git', 'node_modules', '.claude']);
|
|
195
|
+
const EXCLUDED_DIRS = new Set(['.git', 'node_modules', '.claude', '.mnfst-cache']);
|
|
196
196
|
const SECRET_DIRS = new Set(['.ssh', '.aws', '.wrangler']);
|
|
197
197
|
const SECRET_FILES = new Set([
|
|
198
198
|
'.npmrc', '.yarnrc', '.yarnrc.yml', '.pypirc', '.netrc', '_netrc', '.git-credentials', '.htpasswd',
|
|
@@ -424,6 +424,118 @@ export async function pollPublishStatus(statusUrl, opts = {}) {
|
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
// --- Upload link renewal ------------------------------------------------------
|
|
428
|
+
|
|
429
|
+
// A connector link expires 15 minutes after mint unless renewed, and a website
|
|
430
|
+
// render can take an hour. While rendering, renew it on this interval (well
|
|
431
|
+
// inside the window, so a missed beat or two is harmless) and once more right
|
|
432
|
+
// before uploading. The server caps how long a link can be kept alive.
|
|
433
|
+
const RENEW_EVERY_MS = 5 * 60 * 1000;
|
|
434
|
+
// A hung renewal must not stall the publish; a timeout counts as a blip.
|
|
435
|
+
const RENEW_TIMEOUT_MS = 15_000;
|
|
436
|
+
|
|
437
|
+
export function renewUrlFor(uploadUrl) {
|
|
438
|
+
return uploadUrl.replace(/\/+$/, '') + '/renew';
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* One renewal. Resolves `{state, body}`:
|
|
443
|
+
* renewed the link is good for another window
|
|
444
|
+
* expired the link is used, expired or unknown (410)
|
|
445
|
+
* unsupported the server has no renew route, or will not extend this link
|
|
446
|
+
* retry a blip, 429 or 5xx: try again next time
|
|
447
|
+
*/
|
|
448
|
+
export async function renewUploadLink(uploadUrl, opts = {}) {
|
|
449
|
+
const { fetchImpl = fetch } = opts;
|
|
450
|
+
let status = 0;
|
|
451
|
+
let json = null;
|
|
452
|
+
try {
|
|
453
|
+
const res = await fetchImpl(renewUrlFor(uploadUrl), {
|
|
454
|
+
method: 'POST',
|
|
455
|
+
headers: { accept: 'application/json' },
|
|
456
|
+
signal: AbortSignal.timeout(RENEW_TIMEOUT_MS),
|
|
457
|
+
});
|
|
458
|
+
status = res.status;
|
|
459
|
+
const text = await res.text();
|
|
460
|
+
try {
|
|
461
|
+
json = text ? JSON.parse(text) : null;
|
|
462
|
+
} catch {
|
|
463
|
+
/* not JSON */
|
|
464
|
+
}
|
|
465
|
+
} catch {
|
|
466
|
+
return { state: 'retry' };
|
|
467
|
+
}
|
|
468
|
+
if (status === 200 && json && json.status === 'pending') return { state: 'renewed', body: json };
|
|
469
|
+
if (status === 410) return { state: 'expired', body: json };
|
|
470
|
+
if (status === 429 || status >= 500 || status === 0) return { state: 'retry', body: json };
|
|
471
|
+
return { state: 'unsupported', body: json };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Renew `uploadUrl` every `intervalMs` until finish(). finish() stops the
|
|
476
|
+
* timer, waits for any renewal in flight (so none races the upload), renews
|
|
477
|
+
* once more and resolves the link's state: active | expired | unsupported.
|
|
478
|
+
*/
|
|
479
|
+
export function keepUploadLinkAlive(uploadUrl, opts = {}) {
|
|
480
|
+
const {
|
|
481
|
+
fetchImpl = fetch,
|
|
482
|
+
intervalMs = RENEW_EVERY_MS,
|
|
483
|
+
setTimer = setTimeout,
|
|
484
|
+
clearTimer = clearTimeout,
|
|
485
|
+
log: logFn = log,
|
|
486
|
+
} = opts;
|
|
487
|
+
let state = 'active';
|
|
488
|
+
let timer = null;
|
|
489
|
+
let inFlight = null;
|
|
490
|
+
let stopped = false;
|
|
491
|
+
|
|
492
|
+
const renew = async () => {
|
|
493
|
+
const r = await renewUploadLink(uploadUrl, { fetchImpl });
|
|
494
|
+
if (r.state === 'expired' && state !== 'expired') {
|
|
495
|
+
state = 'expired';
|
|
496
|
+
logFn(' the publish link expired. The render carries on so its output is kept on disk.');
|
|
497
|
+
} else if (r.state === 'unsupported') {
|
|
498
|
+
state = 'unsupported';
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
const schedule = () => {
|
|
502
|
+
if (stopped || state !== 'active') return;
|
|
503
|
+
timer = setTimer(() => {
|
|
504
|
+
timer = null;
|
|
505
|
+
inFlight = renew().finally(() => {
|
|
506
|
+
inFlight = null;
|
|
507
|
+
schedule();
|
|
508
|
+
});
|
|
509
|
+
}, intervalMs);
|
|
510
|
+
if (timer && typeof timer.unref === 'function') timer.unref();
|
|
511
|
+
};
|
|
512
|
+
schedule();
|
|
513
|
+
|
|
514
|
+
return {
|
|
515
|
+
get state() {
|
|
516
|
+
return state;
|
|
517
|
+
},
|
|
518
|
+
async finish() {
|
|
519
|
+
stopped = true;
|
|
520
|
+
if (timer) clearTimer(timer);
|
|
521
|
+
timer = null;
|
|
522
|
+
if (inFlight) await inFlight;
|
|
523
|
+
if (state === 'active') await renew();
|
|
524
|
+
return state;
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** What to do when the link is gone: a new link, and no second render when the output is already on disk. */
|
|
530
|
+
export function expiredLinkAdvice({ rendered = false, outputDir = 'website' } = {}) {
|
|
531
|
+
const base = 'this publish link expired before the upload. Run manifest_publish again for a new link and run the command it returns.';
|
|
532
|
+
return rendered ? `${base} ${noRenderHint(outputDir)}` : base;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function noRenderHint(outputDir) {
|
|
536
|
+
return `The site is already rendered in "${outputDir}", so add --no-render to the new command to upload it without rendering again.`;
|
|
537
|
+
}
|
|
538
|
+
|
|
427
539
|
/** Turn a settled poll result into the success payload, or throw a plain-language error. */
|
|
428
540
|
function settledPayload(res) {
|
|
429
541
|
if (res.state === 'done') return res.body;
|
|
@@ -506,6 +618,13 @@ export async function uploadBundle(uploadUrl, zip, opts = {}) {
|
|
|
506
618
|
return settledPayload(await poll({}));
|
|
507
619
|
}
|
|
508
620
|
|
|
621
|
+
// The link is used, expired or unknown: nothing to retry with it.
|
|
622
|
+
if (res.status === 410) {
|
|
623
|
+
const err = new Error((json && json.message) || 'Publish link expired or already used.');
|
|
624
|
+
err.code = 'link_expired';
|
|
625
|
+
throw err;
|
|
626
|
+
}
|
|
627
|
+
|
|
509
628
|
if (res.status >= 500 && attempt < tries) {
|
|
510
629
|
logFn(` the upload server had a hiccup (HTTP ${res.status}) — retrying (${attempt}/${tries - 1})…`);
|
|
511
630
|
await sleepImpl(500 * attempt);
|
|
@@ -636,6 +755,35 @@ function buildZip(root, rels, overrides = new Map()) {
|
|
|
636
755
|
|
|
637
756
|
// --- Main ------------------------------------------------------------------
|
|
638
757
|
|
|
758
|
+
function runCommand(cmd, args, options) {
|
|
759
|
+
return new Promise((resolve) => {
|
|
760
|
+
const child = spawn(cmd, args, options);
|
|
761
|
+
child.on('error', () => resolve(1));
|
|
762
|
+
child.on('exit', (code) => resolve(code ?? 1));
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// The upload carries the whole project. Only POST it to an HTTPS endpoint on
|
|
767
|
+
// the SAME host as the MCP server — never to an arbitrary URL a tampered
|
|
768
|
+
// response or misconfigured .mcp.json could inject.
|
|
769
|
+
function checkUploadUrl(uploadUrl, mcpUrl) {
|
|
770
|
+
let u;
|
|
771
|
+
let mcpHost;
|
|
772
|
+
try {
|
|
773
|
+
u = new URL(uploadUrl);
|
|
774
|
+
mcpHost = new URL(mcpUrl).host;
|
|
775
|
+
} catch {
|
|
776
|
+
fail('the upload URL returned by the server was malformed.');
|
|
777
|
+
}
|
|
778
|
+
// Same host as the configured MCP, or the canonical first-party host — a
|
|
779
|
+
// project whose .mcp.json still points at the legacy workers.dev URL gets
|
|
780
|
+
// upload links minted on mcp.manifestx.dev during the domain migration.
|
|
781
|
+
const canonical = new URL(DEFAULT_MCP).host;
|
|
782
|
+
if (u.protocol !== 'https:' || (u.host !== mcpHost && u.host !== canonical)) {
|
|
783
|
+
fail(`refusing to upload to an unexpected endpoint (${u.protocol}//${u.host}); expected https://${mcpHost} or https://${canonical}.`);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
639
787
|
export async function main() {
|
|
640
788
|
const opts = parseArgs(process.argv.slice(2));
|
|
641
789
|
if (opts.help) {
|
|
@@ -672,10 +820,16 @@ export async function main() {
|
|
|
672
820
|
fail('no API key found. Publish from Claude with the Manifest connector (no key needed), or set MANIFEST_API_KEY in .env for headless/CI use.');
|
|
673
821
|
}
|
|
674
822
|
|
|
675
|
-
|
|
823
|
+
// Checked before rendering, since the link is renewed while the render runs.
|
|
824
|
+
if (injectedUpload) checkUploadUrl(injectedUpload, url);
|
|
825
|
+
const keepAlive = injectedUpload ? keepUploadLinkAlive(injectedUpload) : null;
|
|
826
|
+
|
|
827
|
+
const rendering = source === 'render' && opts.render !== false;
|
|
828
|
+
if (rendering) {
|
|
676
829
|
log('Rendering the site…');
|
|
677
|
-
|
|
678
|
-
|
|
830
|
+
// Async, so the renewal timer runs during the render.
|
|
831
|
+
const code = await runCommand('npx', ['mnfst-render'], { cwd: root, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
832
|
+
if (code !== 0) fail('render failed — fix the errors above and try again.');
|
|
679
833
|
}
|
|
680
834
|
|
|
681
835
|
// For a render project, sanity-check there's actually a built site to ship —
|
|
@@ -706,22 +860,7 @@ export async function main() {
|
|
|
706
860
|
const handshake = await callTool(url, key, 'manifest_publish', { env: opts.env, source, via_cli: true });
|
|
707
861
|
uploadUrl = handshake.upload_url;
|
|
708
862
|
if (!uploadUrl) fail(handshake._text || 'could not start the publish (no upload URL returned).');
|
|
709
|
-
|
|
710
|
-
// The upload carries the whole project. Only POST it to an HTTPS endpoint on
|
|
711
|
-
// the SAME host as the MCP server — never to an arbitrary URL a tampered
|
|
712
|
-
// response or misconfigured .mcp.json could inject.
|
|
713
|
-
try {
|
|
714
|
-
const u = new URL(uploadUrl);
|
|
715
|
-
const mcpHost = new URL(url).host;
|
|
716
|
-
// Same host as the configured MCP, or the canonical first-party host — a
|
|
717
|
-
// project whose .mcp.json still points at the legacy workers.dev URL gets
|
|
718
|
-
// upload links minted on mcp.manifestx.dev during the domain migration.
|
|
719
|
-
const canonical = new URL(DEFAULT_MCP).host;
|
|
720
|
-
if (u.protocol !== 'https:' || (u.host !== mcpHost && u.host !== canonical)) {
|
|
721
|
-
fail(`refusing to upload to an unexpected endpoint (${u.protocol}//${u.host}); expected https://${mcpHost} or https://${canonical}.`);
|
|
722
|
-
}
|
|
723
|
-
} catch {
|
|
724
|
-
fail('the upload URL returned by the server was malformed.');
|
|
863
|
+
checkUploadUrl(uploadUrl, url);
|
|
725
864
|
}
|
|
726
865
|
|
|
727
866
|
const rels = collectFiles(root, opts.outputDir);
|
|
@@ -730,12 +869,18 @@ export async function main() {
|
|
|
730
869
|
fail(`the output folder "${opts.outputDir}" doesn't exist — run the project's build first, then publish again.`);
|
|
731
870
|
}
|
|
732
871
|
const zip = buildZip(root, rels, stampManifests(root, rels));
|
|
872
|
+
const recovery = { rendered: source === 'render', outputDir: prerenderOutputDir(root) };
|
|
873
|
+
// Last renewal before the upload; an older server without renewal just uploads as before.
|
|
874
|
+
if (keepAlive && (await keepAlive.finish()) === 'expired') fail(expiredLinkAdvice(recovery));
|
|
733
875
|
log(`Uploading ${rels.length} files (${(zip.length / 1048576).toFixed(1)} MB)…`);
|
|
734
876
|
|
|
735
877
|
let upJson;
|
|
736
878
|
try {
|
|
737
879
|
upJson = await uploadBundle(uploadUrl, zip);
|
|
738
880
|
} catch (e) {
|
|
881
|
+
if (e.code === 'link_expired') {
|
|
882
|
+
fail(/--no-render/.test(e.message) || !recovery.rendered ? e.message : `${e.message} ${noRenderHint(recovery.outputDir)}`);
|
|
883
|
+
}
|
|
739
884
|
fail(e.message);
|
|
740
885
|
}
|
|
741
886
|
|