Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Publish to Netlify: sites are public by default (#6259)
Milind Soni200de1b803da
diff --git a/server/skill-publish-to-netlify.test.ts b/server/skill-publish-to-netlify.test.tsindex 26ec393d74..0589c08b21 100644--- a/server/skill-publish-to-netlify.test.ts+++ b/server/skill-publish-to-netlify.test.ts@@ -82,7 +82,7 @@ describe("publish-to-netlify skill guide", () => {expect(guide).toContain("deploy.mjs");expect(guide).toContain(helper.SITE_FILE);expect(guide).toMatch(/link is public/);- expect(guide).toMatch(/no sign-in for visitors/);+ expect(guide).toMatch(/anyone who has it can open it, with no sign-in/);expect(guide).toMatch(/token never goes to the cloud computer/);expect(guide).toContain('"access": "private"');expect(guide).toContain("contentType");@@ -92,7 +92,10 @@ describe("publish-to-netlify skill guide", () => {expect(guide).toMatch(/--delete --token-file/);expect(guide).toMatch(/only after they confirm/);expect(guide).toMatch(/link will stop working for everyone/);- expect(guide).toMatch(/--make-public[^.]*only after they say/);+ expect(guide).toMatch(/public by default/);+ expect(guide).toMatch(/--keep-private[^.]*only when the person asks for\s+a private site/);+ expect(guide).toMatch(/a draft never changes it/);+ expect(guide).toMatch(/`--make-public` alone undoes it when they ask/);expect(guide).toMatch(/Early Access/);expect(guide).toMatch(/Never promise that it is always on/);});@@ -258,6 +261,8 @@ describe("publish-to-netlify helper, end to end against a stand-in on loopback",const first = await run(["--dir", "dist", "--token-file", tokenFile]);expect(first.stderr).toBe("");expect(first.json).toMatchObject({ ok: true, created: true, state: "ready", live: true, access: "public", liveStatus: 200, files: 2, uploaded: 2 });+ expect(first.json).not.toHaveProperty("message");+ expect(fake.requests.filter((request) => request.startsWith("PATCH "))).toEqual([`PATCH /api/v1/sites/${String(first.json.siteId)}`]);expect([...fake.uploads].sort()).toEqual(["/assets/app.js", "/index.html"]);expect(first.json.skipped).toEqual([".env", "node_modules", "server.pem"]);@@ -277,6 +282,7 @@ describe("publish-to-netlify helper, end to end against a stand-in on loopback",expect(second.json).toMatchObject({ ok: true, created: false, siteId: before.siteId, url: before.url, live: true, files: 2, uploaded: 1 });expect(fake.uploads.slice(uploadsBefore)).toEqual(["/assets/app.js"]);expect(fake.requests.filter((request) => request === "POST /api/v1/sites")).toHaveLength(1);+ expect(fake.requests.filter((request) => request.startsWith("PATCH "))).toEqual([`PATCH /api/v1/sites/${before.siteId}`, `PATCH /api/v1/sites/${before.siteId}`]);expect([...fake.sites.keys()]).toEqual([before.siteId]);expect(await (await fetch(`${before.url}assets/app.js`)).text()).toBe("console.log('v2')");});@@ -369,7 +375,7 @@ describe("publish-to-netlify helper, end to end against a stand-in on loopback",const record = JSON.stringify({ version: 1, hosting: "included", appKey: "app-5d0c1b7e9a3f4c62b8e1d2a4f6c80913", siteId: "app-5d0c1b7e9a3f4c62b8e1d2a4f6c80913", url: "https://mb-3f9c2a17d04e8b65.netlify.app/" });writeFileSync(join(included, helper.SITE_FILE), record);const before = fake.requests.length;- for (const args of [["--dir", join(project, "dist")], ["--check"], ["--make-public"], ["--delete"]]) {+ for (const args of [["--dir", join(project, "dist")], ["--dir", join(project, "dist"), "--keep-private"], ["--check"], ["--make-public"], ["--delete"]]) {const answer = await run([...args, "--token-file", tokenFile, "--project", included]);expect(answer.json, args[0]).toEqual({ ok: false, error: "this project's app is on the Cloud plan's included hosting (https://mb-3f9c2a17d04e8b65.netlify.app/), not on Netlify; "+ "update or delete it with publish_app, or publish to Netlify from another project folder (--project)" });@@ -378,28 +384,145 @@ describe("publish-to-netlify helper, end to end against a stand-in on loopback",expect(readFileSync(join(included, helper.SITE_FILE), "utf8")).toBe(record);});- it("reports a new account's site as deployed but private, and opens it only when asked to", async () => {- const guarded = await startFakeNetlify(TOKEN, { teamLogin: true });- const elsewhere = join(home, "workspace", "guarded");- mkdirSync(elsewhere, { recursive: true });- const args = ["--token-file", tokenFile, "--project", elsewhere];- try {- const first = await run(["--dir", join(project, "dist"), ...args], { OMB_NETLIFY_API_URL: guarded.url });- expect(first).toMatchObject({ code: 0, json: { ok: true, created: true, state: "ready", live: false, access: "private", liveStatus: 401 } });- expect(guarded.requests.some((request) => request.startsWith("PATCH "))).toBe(false);- expect((await fetch(String(first.json.url))).status).toBe(401);-- const opened = await run(["--make-public", ...args], { OMB_NETLIFY_API_URL: guarded.url });- expect(opened.json).toMatchObject({ ok: true, live: true, access: "public", siteId: first.json.siteId, url: first.json.url });- expect(guarded.requests.filter((request) => request.startsWith("PATCH "))).toEqual([`PATCH /api/v1/sites/${String(first.json.siteId)}`]);- expect(guarded.requests.filter((request) => /^POST .*\/deploys$/.test(request))).toHaveLength(1);+ describe("a Netlify team that protects new sites", () => {+ let guarded: FakeNetlify;+ const patches = () => guarded.requests.filter((request) => request.startsWith("PATCH "));+ const patchOf = (siteId: unknown) => `PATCH /api/v1/sites/${String(siteId)}`;+ const recordIn = (folder: string) => JSON.parse(readFileSync(join(home, "workspace", folder, helper.SITE_FILE), "utf8")) as Record<string, unknown>;+ /** In process, with short waits: a private link is only called private after a few seconds of 401s. */+ const publishIn = (folder: string, extra: string[], waits: { waitMs?: number } = {}) => {+ mkdirSync(join(home, "workspace", folder), { recursive: true });+ return helper.publish([...extra, "--token-file", tokenFile, "--project", join(home, "workspace", folder)], { OMB_NETLIFY_API_URL: guarded.url },+ { pollMs: 5, waitMs: 2000, linkWaitMs: 2000, privateAfterMs: 50, ...waits });+ };+ let dist: string[];+ beforeAll(async () => {+ guarded = await startFakeNetlify(TOKEN, { teamLogin: true });+ dist = ["--dir", join(project, "dist")];+ });+ afterAll(async () => {+ await guarded.stop();+ });++ it("makes a new site public once its deploy is ready, and again on every publish", async () => {+ mkdirSync(join(home, "workspace", "guarded"), { recursive: true });+ const first = await run([...dist, "--token-file", tokenFile, "--project", join(home, "workspace", "guarded")], { OMB_NETLIFY_API_URL: guarded.url });+ expect(first).toMatchObject({ code: 0, json: { ok: true, created: true, state: "ready", live: true, access: "public", liveStatus: 200 } });+ expect(first.json).not.toHaveProperty("message");+ const site = patchOf(first.json.siteId);+ expect(patches()).toEqual([site]);+ const deployRead = guarded.requests.lastIndexOf(`GET /api/v1/sites/${String(first.json.siteId)}/deploys/${String(first.json.deployId)}`);+ const started = guarded.requests.indexOf(`POST /api/v1/sites/${String(first.json.siteId)}/deploys`);+ expect(guarded.requests.indexOf(site)).toBeGreaterThan(Math.max(deployRead, started));expect(await (await fetch(String(first.json.url))).text()).toBe("<h1>Bakery</h1>");+ guarded.sites.get(String(first.json.siteId))!.teamLogin = true;+ const again = await publishIn("guarded", dist);+ expect(again).toMatchObject({ ok: true, created: false, live: true, access: "public", siteId: first.json.siteId });+ expect(patches()).toEqual([site, site]);+ expect(recordIn("guarded")).toMatchObject({ access: "public" });+ expect(recordIn("guarded")).not.toHaveProperty("privateReason");+ });++ it("does not open a site whose deploy is not ready yet, and opens it when --check finds it ready", async () => {+ const before = patches().length;+ guarded.processingPolls = 1_000_000;+ let pending: Record<string, unknown>;+ try {+ pending = await publishIn("slow-guarded", dist, { waitMs: 100 });+ } finally {+ guarded.processingPolls = 0;+ }+ expect(pending).toMatchObject({ ok: true, pending: true, live: false });+ expect(patches()).toHaveLength(before);+ expect((await fetch(String(pending.url))).status).toBe(401);++ guarded.deploys.get(String(pending.deployId))!.pollsLeft = 1;+ const ready = await publishIn("slow-guarded", ["--check"]);+ expect(ready).toMatchObject({ ok: true, state: "ready", live: true, access: "public" });+ expect(patches()).toEqual([...patches().slice(0, before), patchOf(pending.siteId)]);+ const checkedAgain = await publishIn("slow-guarded", ["--check"]);+ expect(checkedAgain).toMatchObject({ access: "public" });+ expect(patches()).toHaveLength(before + 1);+ });++ it("keeps a site private with --keep-private, remembers that, and never opens it with a draft", async () => {+ const before = patches().length;+ const kept = await publishIn("kept-private", [...dist, "--keep-private"]);+ expect(kept).toMatchObject({ ok: true, created: true, state: "ready", live: false, access: "private", liveStatus: 401, privateReason: "person" });+ expect(kept).not.toHaveProperty("message");+ expect(recordIn("kept-private")).toMatchObject({ access: "private", privateReason: "person", keepPrivate: true });++ const draft = await publishIn("kept-private", [...dist, "--draft"]);+ expect(draft).toMatchObject({ ok: true, draft: true, access: "private", liveStatus: 401 });+ expect((await fetch(String(kept.url))).status).toBe(401);++ const later = await publishIn("kept-private", dist);+ expect(later).toMatchObject({ ok: true, created: false, access: "private", privateReason: "person" });+ expect(later).not.toHaveProperty("message");+ const checked = await publishIn("kept-private", ["--check"]);+ expect(checked).toMatchObject({ ok: true, access: "private", privateReason: "person" });+ expect(patches()).toHaveLength(before);++ const opened = await publishIn("kept-private", ["--make-public"]);+ expect(opened).toMatchObject({ ok: true, live: true, access: "public", siteId: kept.siteId, url: kept.url });+ expect(patches()).toEqual([...patches().slice(0, before), patchOf(kept.siteId)]);+ expect(recordIn("kept-private")).not.toHaveProperty("keepPrivate");+ expect(recordIn("kept-private")).not.toHaveProperty("privateReason");+ expect(guarded.requests.filter((request) => request === `POST /api/v1/sites/${String(kept.siteId)}/deploys`)).toHaveLength(3);++ await expect(publishIn("kept-private", ["--make-public", "--keep-private"])).rejects.toThrow(/--make-public and --keep-private ask for opposite things/);const nothing = await run(["--make-public", "--token-file", tokenFile, "--project", join(home, "workspace")], { OMB_NETLIFY_API_URL: guarded.url });expect(String(nothing.json.error)).toMatch(/\.netlify-site\.json is missing; publish the site first/);- } finally {- await guarded.stop();- }+ });++ it("leaves a new site as the team made it when only a draft is published", async () => {+ const before = patches().length;+ const draft = await publishIn("draft-only", [...dist, "--draft"]);+ expect(draft).toMatchObject({ ok: true, draft: true, access: "private", liveStatus: 401 });+ expect(String(draft.message)).toMatch(/a draft never changes who can open the site/);+ expect(patches()).toHaveLength(before);+ });++ it("still publishes when the team refuses to open the site, and says where the setting is", async () => {+ guarded.refusePublicWith = 403;+ try {+ const refused = await publishIn("enforced", dist);+ expect(refused).toMatchObject({ ok: true, created: true, state: "ready", live: false, access: "private", liveStatus: 401, privateReason: "team" });+ expect(patches()).toContain(patchOf(refused.siteId));+ const message = String(refused.message);+ expect(message).toMatch(/Netlify team's settings keep it private/);+ expect(message).toContain("Project configuration > General > Visitor access");+ expect(message).toContain("Team settings > General > Visitor access");+ expect(message).toContain("Team settings > Access & security > Visitor access");+ expect(recordIn("enforced")).toMatchObject({ access: "private", privateReason: "team", deployState: "ready" });+ expect(recordIn("enforced")).not.toHaveProperty("keepPrivate");++ const checked = await publishIn("enforced", ["--check"]);+ expect(checked).toMatchObject({ access: "private", privateReason: "team" });+ expect(String(checked.message)).toMatch(/team's settings keep it private/);++ guarded.refusePublicWith = 400;+ const failed = await publishIn("enforced", dist);+ expect(failed).toMatchObject({ ok: true, state: "ready", access: "private" });+ expect(String(failed.message)).toMatch(/^Making the site public: Netlify answered 400: .*The site is deployed; run again with --make-public in a minute\.$/);+ } finally {+ guarded.refusePublicWith = 0;+ }+ });++ it("says a site may have a password when it still asks for a login after being opened", async () => {+ guarded.passwordProtected = true;+ try {+ const still = await publishIn("password", dist);+ expect(still).toMatchObject({ ok: true, access: "private", privateReason: "protected" });+ expect(String(still.message)).toMatch(/Netlify accepted making the site public, but the link still asks for a login: the site may have password protection/);+ expect(String(still.message)).not.toMatch(/team's settings/);+ expect(recordIn("password")).toMatchObject({ access: "private", privateReason: "protected" });+ } finally {+ guarded.passwordProtected = false;+ }+ });});it("publishes a one-file site under its own name, and does not call a root served as plain text live", async () => {diff --git a/server/testing/fake-netlify.ts b/server/testing/fake-netlify.tsindex ab01584986..a6ecfe9ef5 100644--- a/server/testing/fake-netlify.ts+++ b/server/testing/fake-netlify.ts@@ -31,10 +31,14 @@ export interface FakeNetlify {rootContentType: string;/** How many status reads a new deploy answers "processing" before it is ready; a new site's first deploy is slow. */processingPolls: number;+ /** Non-zero: turning `sso_login` off is refused with this status (403 is a team that enforces its protection). */+ refusePublicWith: number;+ /** Sites also have a password: turning `sso_login` off is accepted, and they keep answering 401. */+ passwordProtected: boolean;stop(): Promise<void>;}-/** `teamLogin`: new sites answer 401 until `sso_login` is turned off, as on a new Netlify account (2026-11). */+/** `teamLogin`: new sites answer 401 until `sso_login` is turned off, as on a team that protects new sites (2026-11). */export async function startFakeNetlify(token: string, { teamLogin = false }: { teamLogin?: boolean } = {}): Promise<FakeNetlify> {const blobs = new Map<string, Buffer>();let failure: { status: number; body: unknown } | null = null;@@ -43,6 +47,8 @@ export async function startFakeNetlify(token: string, { teamLogin = false }: { tfailNext: (status, body) => { failure = { status, body }; },rootContentType: "text/html; charset=UTF-8",processingPolls: 0,+ refusePublicWith: 0,+ passwordProtected: false,};const origin = () => `http://127.0.0.1:${(server.address() as AddressInfo).port}`;const deployView = (deploy: FakeDeploy) => ({@@ -108,8 +114,10 @@ export async function startFakeNetlify(token: string, { teamLogin = false }: { treturn res.end();}if (req.method === "PATCH" && changed) {- if ((JSON.parse(body.toString()) as { sso_login?: boolean }).sso_login === false) changed.teamLogin = false;- return send(200, { id: change[1], name: changed.name, sso_login: changed.teamLogin });+ if (fake.refusePublicWith) return send(fake.refusePublicWith, { code: fake.refusePublicWith, message: "Your team's settings don't allow changing site protection" });+ const off = (JSON.parse(body.toString()) as { sso_login?: boolean }).sso_login === false;+ if (off && !fake.passwordProtected) changed.teamLogin = false;+ return send(200, { id: change[1], name: changed.name, sso_login: off ? false : changed.teamLogin });}const create = /^\/api\/v1\/sites\/([\w-]+)\/deploys$/.exec(path);if (req.method === "POST" && create) {diff --git a/skills/publish-to-netlify/SKILL.md b/skills/publish-to-netlify/SKILL.mdindex e5a3f3a6b2..f859c3288f 100644--- a/skills/publish-to-netlify/SKILL.md+++ b/skills/publish-to-netlify/SKILL.md@@ -21,8 +21,8 @@ Publish only when the person asks. If they only asked you to build something, sh## Before anything goes out-- A published link is public: anyone who has it can open it, and there is no sign-in for visitors. Say so the first- time you publish for a person.+- A published link is public: anyone who has it can open it, with no sign-in. Say so the first time you publish for a+ person. A site is private only when they ask for that, or when their Netlify team won't let it be opened.- Never publish secrets, keys, private files, memory or notes, anything from another person's chat, or a team'sprivate data. A page's code is readable by every visitor, so nothing secret goes in it either.- If the content looks personal or internal (names with contact details, customer lists, money, health, staff or@@ -128,6 +128,9 @@ Give the call an 8-minute `timeout`: a new site's first deploy can take NetlifyNetlify, so it may be taken. Without it Netlify picks a name.- `--project <folder>` when the project folder is not the current one. `--draft` publishes a preview at its ownaddress and leaves the live site as it is.+- Sites are public by default: once a deploy is ready, the site is opened to anyone with the link, even where their+ Netlify team keeps new sites private (a draft never changes it). Pass `--keep-private` only when the person asks for+ a private site: it is remembered for later runs, and `--make-public` alone undoes it when they ask.- It never uploads dotfiles and dot folders (`.env`, `.git`, `.openmausbot-secrets`, the site record),`node_modules`, env files, keys or certificates, or links to files elsewhere, and it stops if any file contains thetoken. The answer lists what it left out under `skipped`.@@ -138,11 +141,9 @@ It prints one line of JSON:- `"ok": true`, `"state": "ready"`, `"live": true`: Netlify processed the deploy and the link answered. Reply with thelink (`url`), what you published in one or two lines, and that the link is public.-- `"access": "private"`: the site is deployed, but the link asks for a Netlify login. New Netlify accounts keep every- site visible to the account's own team only. This is not a failure. Give the link, say that right now only people- signed in to their Netlify team can open it, and ask whether to open it to anyone with the link. Run- `node "<root>/deploy.mjs" --make-public --token-file <the secret file's path>` only after they say yes; it changes- that one site and checks the link again.+- `"access": "private"`: deployed, not a failure; only people signed in to their Netlify team can open it.+ `privateReason` `person`: as they asked. Otherwise pass on the `message` (`team`: their team's setting keeps it+ private; `protected`: it may have a password) and where it says the setting is. Change nothing else on their account.- `live` false with `"liveStatus": 200`: the link answers, but not as a web page (`contentType` is not `text/html`),so a browser would show the page's source. Say so; don't call it published.- `"pending": true` (`state` is `processing` or similar): Netlify is still working on it. It is not live yet and itdiff --git a/skills/publish-to-netlify/deploy.mjs b/skills/publish-to-netlify/deploy.mjsindex 5db1cc7261..7cef9298dd 100644--- a/skills/publish-to-netlify/deploy.mjs+++ b/skills/publish-to-netlify/deploy.mjs@@ -154,19 +154,21 @@ class NetlifyError extends Error {}function parseArgs(argv) {- const args = { draft: false, public: false, check: false, delete: false };+ const args = { draft: false, public: false, keepPrivate: false, check: false, delete: false };for (let at = 0; at < argv.length; at += 1) {const flag = argv[at];if (flag === "--draft") args.draft = true;else if (flag === "--make-public") args.public = true;+ else if (flag === "--keep-private") args.keepPrivate = true;else if (flag === "--check") args.check = true;else if (flag === "--delete") args.delete = true;else if (["--dir", "--token-file", "--project", "--name", "--title", "--bot-name"].includes(flag) && argv[at + 1]) args[flag.slice(2)] = argv[(at += 1)];else throw new Error(`unknown or incomplete option ${flag}`);}- if (args.delete && (args.dir || args.public || args.check || args.draft)) throw new Error("--delete takes only --token-file and --project");+ if (args.delete && (args.dir || args.public || args.keepPrivate || args.check || args.draft)) throw new Error("--delete takes only --token-file and --project");+ if (args.public && args.keepPrivate) throw new Error("--make-public and --keep-private ask for opposite things; pass one");if (!args["token-file"] || !(args.dir || args.public || args.check || args.delete)) {- throw new Error("usage: node deploy.mjs --dir <folder to publish> --token-file <secret file> [--project <folder>] [--name <site name>] [--title <title>] [--bot-name <your name>] [--draft] [--make-public] | --check --token-file <secret file> | --make-public --token-file <secret file> | --delete --token-file <secret file>");+ throw new Error("usage: node deploy.mjs --dir <folder to publish> --token-file <secret file> [--project <folder>] [--name <site name>] [--title <title>] [--bot-name <your name>] [--draft] [--keep-private] | --check --token-file <secret file> | --make-public --token-file <secret file> | --delete --token-file <secret file>");}return args;}@@ -187,7 +189,7 @@ function readSiteRecord(file) {return record;}-const RECORD_KEYS = ["version", "siteId", "name", "url", "adminUrl", "title", "botId", "botName", "createdAt", "publishedAt", "deployId", "deployState", "access"];+const RECORD_KEYS = ["version", "siteId", "name", "url", "adminUrl", "title", "botId", "botName", "createdAt", "publishedAt", "deployId", "deployState", "access", "privateReason", "keepPrivate"];const oneLine = (value, max) => String(value).replace(/[\p{Cc}\s]+/gu, " ").trim().slice(0, max);/** `.netlify-site.json`, a contract other code reads: known keys only, in a fixed order, and never the token. */@@ -197,11 +199,25 @@ export function siteRecord(fields) {return record;}+/** Answers to the PATCH that mean the team keeps its sites private (Netlify 2026-11: a team can enforce its default). */+const PUBLIC_REFUSED = new Set([403, 422]);+// Netlify's docs (2026-11): the site's own setting is under Project configuration > General > Visitor access; the+// team default is under Team settings > General > Visitor access, or Team settings > Access & security > Visitor+// access on Enterprise and older plans.+const TEAM_KEEPS_PRIVATE = "The site is deployed, but the Netlify team's settings keep it private: only people signed in to that team can open the link. "+ + "To open it to anyone with the link, open the site in Netlify and change Project configuration > General > Visitor access. "+ + "To make new sites public, a team owner changes the default in Team settings > General > Visitor access (Team settings > Access & security > Visitor access on some plans).";+const STILL_ASKS_LOGIN = "Netlify accepted making the site public, but the link still asks for a login: the site may have password protection or "+ + "another Visitor access setting. The person can check Project configuration > General > Visitor access for this site in Netlify.";+const PRIVATE_ON_CHECK = "The link asks for a Netlify login. Unless the person asked for a private site, run again with --make-public.";+const DRAFT_ASKS_LOGIN = "This draft asks for a Netlify login: a draft never changes who can open the site. A publish without --draft makes the site public, unless the person asked for a private one.";+const PRIVATE_MESSAGES = { team: TEAM_KEEPS_PRIVATE, protected: STILL_ASKS_LOGIN, unknown: PRIVATE_ON_CHECK };+const wait = (ms) => new Promise((done) => setTimeout(done, ms));-/** Netlify (2026-11): a new account's sites answer 401 with a redirect to its team login until `sso_login` is turned- * off on the site, so a 401 is a deployed site that only the account's team can open. Turning it off takes a few- * seconds to show, so `expectPublic` waits through 401s. */+/** Netlify (2026-11): where a team protects new sites, they answer 401 with a redirect to the team login until+ * `sso_login` is turned off on the site, so a 401 is a deployed site that only the account's team can open. Turning+ * it off takes a few seconds to show, so `expectPublic` waits through 401s. */async function checkLink(url, env, { pollMs, waitMs, privateAfterMs, expectPublic }) {const started = Date.now();for (;;) {@@ -242,11 +258,36 @@ export async function publish(argv, env = process.env, { pollMs = 2000, waitMs =site = siteRecord({ ...site, ...changes });writeFileSync(siteFile, `${JSON.stringify(site, null, 2)}\n`);};- const makePublic = () => api("Making the site public", "PATCH", `/sites/${site.siteId}`, { sso_login: false });-+ /** Opens the site to anyone with the link: "opened", "refused" when the team keeps its sites private (it refuses the+ * change or keeps `sso_login` on), or what went wrong. The deploy is live by then, so nothing here fails it. */+ const openToAll = async () => {+ try {+ const changed = await api("Making the site public", "PATCH", `/sites/${site.siteId}`, { sso_login: false });+ return changed?.sso_login === true ? "refused" : "opened";+ } catch (error) {+ return error instanceof NetlifyError && PUBLIC_REFUSED.has(error.status) ? "refused" : scrub(error.message);+ }+ };+ /** The person's choice, kept in the record so a later publish honours it until they ask for the site to be public. */+ const wantPrivate = args.keepPrivate || (site?.keepPrivate === true && !args.public);+ /** Opens the site unless the person wants it private (a draft never changes it), then checks the link. A private+ * answer says why: the `person` asked for it, the `team` refused the change, the site is still `protected` some+ * other way, or nothing was changed this time (`unknown`). */+ const lookAt = async (url, { draft, open }) => {+ const opened = draft || wantPrivate || !open ? null : await openToAll();+ const link = await checkLink(url, env, { pollMs, waitMs: linkWaitMs, privateAfterMs, expectPublic: opened === "opened" });+ if (link.access !== "private") return { link, record: { access: link.access, privateReason: undefined } };+ if (draft) return { link: wantPrivate ? link : { ...link, message: DRAFT_ASKS_LOGIN }, record: {} };+ if (opened !== null && opened !== "opened" && opened !== "refused") {+ return { link: { ...link, message: `${opened}. The site is deployed; run again with --make-public in a minute.` }, record: { access: "private", privateReason: "unknown" } };+ }+ const reason = wantPrivate ? "person" : opened === "refused" ? "team" : opened === "opened" ? "protected" : site.privateReason ?? "unknown";+ return { link: { ...link, privateReason: reason, ...(reason === "person" ? {} : { message: PRIVATE_MESSAGES[reason] }) }, record: { access: "private", privateReason: reason } };+ };/** Waits for Netlify to finish a deploy, then for its link. A deploy still being processed at the deadline is- * neither a success nor a failure: the answer says so and `--check` picks it up. */- const finish = async (deploy, { draft, expectPublic, firstLook }) => {+ * neither a success nor a failure: the answer says so and `--check` picks it up. Only a ready production deploy+ * opens the site, so a failed or draft one never changes who can see it. */+ const finish = async (deploy, { draft, firstLook }) => {const deadline = Date.now() + waitMs;while (deploy.state !== "ready" && deploy.state !== "error" && Date.now() < deadline) {await wait(pollMs);@@ -263,8 +304,8 @@ export async function publish(argv, env = process.env, { pollMs = 2000, waitMs =if (!draft) save({ deployState: state });return { ...common, pending: true, live: false, message: `Netlify is still processing this deploy (${state}). It is not live yet and has not failed. Run again with --check in a minute.` };}- const link = await checkLink(url, env, { pollMs, waitMs: linkWaitMs, privateAfterMs, expectPublic });- if (!draft) save({ url, deployState: state, ...(link.access ? { access: link.access } : {}), ...(firstLook ? { publishedAt: now().toISOString() } : {}) });+ const { link, record } = await lookAt(url, { draft, open: firstLook || args.public });+ if (!draft) save({ url, deployState: state, ...(link.access ? record : {}), ...(firstLook ? { publishedAt: now().toISOString() } : {}) });return { ...common, ...link };};@@ -282,10 +323,14 @@ export async function publish(argv, env = process.env, { pollMs = 2000, waitMs =if (!dir) {if (!site) throw new Error(`${siteFile} is missing; publish the site first`);- if (args.public) await makePublic();- if (!site.deployId) return { ok: true, draft: false, siteId: site.siteId, name: site.name, url: site.url, adminUrl: site.adminUrl, ...(await checkLink(site.url, env, { pollMs, waitMs: linkWaitMs, privateAfterMs, expectPublic: args.public })) };+ if (args.public) save({ keepPrivate: undefined });+ if (!site.deployId) {+ const { link, record } = await lookAt(site.url, { draft: false, open: args.public });+ if (link.access) save(record);+ return { ok: true, draft: false, siteId: site.siteId, name: site.name, url: site.url, adminUrl: site.adminUrl, ...link };+ }const deploy = await api("Checking the deploy", "GET", `/sites/${site.siteId}/deploys/${site.deployId}`);- return await finish(deploy, { draft: false, expectPublic: args.public, firstLook: site.deployState !== "ready" || !site.publishedAt });+ return await finish(deploy, { draft: false, firstLook: site.deployState !== "ready" || !site.publishedAt });}const { files, skipped } = collectFiles(dir);@@ -306,7 +351,7 @@ export async function publish(argv, env = process.env, { pollMs = 2000, waitMs =} else if (Object.keys(labels).length && !args.draft) {save(labels);}- if (args.public) await makePublic();+ if (!args.draft && (args.keepPrivate || args.public)) save({ keepPrivate: args.keepPrivate || undefined });let deploy = await api("Starting the deploy", "POST", `/sites/${site.siteId}/deploys`, {files: digest,@@ -340,7 +385,7 @@ export async function publish(argv, env = process.env, { pollMs = 2000, waitMs =}));return {- ...(await finish(deploy, { draft: args.draft, expectPublic: args.public, firstLook: true })), created,+ ...(await finish(deploy, { draft: args.draft, firstLook: !args.draft })), created,files: files.length, uploaded: required.length, alreadyOnNetlify: new Set(Object.values(digest)).size - required.length,bytes: files.reduce((sum, file) => sum + file.size, 0), skipped,};diff --git a/skills/publish-to-netlify/site-record.md b/skills/publish-to-netlify/site-record.mdindex cd9a015ee9..9abcf1151b 100644--- a/skills/publish-to-netlify/site-record.md+++ b/skills/publish-to-netlify/site-record.md@@ -49,7 +49,9 @@ dotfile: it is never uploaded with the site, and it never holds the token.| `deployId` | no | Netlify's id of the latest production deploy that was started. Absent until the first one starts. || `deployState` | no | That deploy's state when last seen: Netlify's own word (`uploading`, `uploaded`, `processing`, `ready`, `error`, …). Only `ready` means it is live. || `publishedAt` | no | When the latest production deploy was first seen ready, ISO 8601 in UTC. While a newer deploy is still being processed it is the time of the one before. Absent until a deploy has been ready. |-| `access` | no | `public`: the link answered without a login. `private`: it asked for a Netlify login (a new account's default). As last checked. |+| `access` | no | `public`: the link answered without a login. `private`: it asked for a login. As last checked. |+| `privateReason` | no | Only while `access` is `private`: `person` (they asked for a private site), `team` (their Netlify team refused to open it), `protected` (opened, but it still asks for a login, such as a password), `unknown`. |+| `keepPrivate` | no | `true` once the person asked for a private site (`--keep-private`): later runs leave it private until `--make-public`. |`deploy.mjs --delete` deletes the site from Netlify and then removes the record; the record stays when Netlifyrefuses. Draft deploys (`--draft`) change nothing in the record. A record written before version 1 has only `siteId`, `name`,