@patchstack/connect 0.5.32 → 0.5.33

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/AGENT-INSTALL.md CHANGED
@@ -75,17 +75,17 @@ Every command at a glance — what it does, whether it reads your source, what i
75
75
 
76
76
  | Command | What it does | Reads your source? | Writes to your project | Sends over the network |
77
77
  |---|---|---|---|---|
78
- | `scan` | Provision (or reuse) the site and POST the dependency list for vulnerability matching. Also runs automatically via `setup` and the install/build hooks. | No source analysis — lockfile only; `node_modules/` is enumerated when no lockfile can be read (e.g. `bun.lockb`) or when the lockfiles present disagree. It also reads the `<title>` of the root `index.html` and the `name` in `package.json`, to report what the site is called. During `prebuild` only, it reads the scaffolded guard and its co-located rules JSON to remove a previous map stamp. | `.patchstackrc.json` (public: site UUID + settings); `.patchstackrc.local.json` (the API key, created owner-only) and a `.gitignore` entry for it — the CLI says so if it could not add one; during `prebuild`, removal of a previous `_patchstack.build_id` from the guard's own rules file so a later build cannot carry stale coordinates; the widget `<script>` tag in the root HTML shell — only after a successful post; the production marker in a code root shell — before the post, since it needs no site UUID | Package names + versions; this site's public address and name, where the project or build environment states them |
78
+ | `scan` | Provision (or reuse) the site and POST the dependency list for vulnerability matching. Also runs automatically via `setup` and the install/build hooks. | No source analysis — lockfile only; `node_modules/` is enumerated when no lockfile can be read (e.g. `bun.lockb`) or when the lockfiles present disagree. It also reads the `<title>` of the root `index.html` and the `name` in `package.json`, to report what the site is called. During `prebuild` only, it reads the scaffolded guard and its co-located rules JSON to remove a previous map stamp. | `.patchstackrc.json` (public: site UUID + settings, the link to connect the site, and whether it is connected yet); `.patchstackrc.local.json` (the API key, created owner-only) and a `.gitignore` entry for it — the CLI says so if it could not add one; during `prebuild`, removal of a previous `_patchstack.build_id` from the guard's own rules file so a later build cannot carry stale coordinates; the widget `<script>` tag in the root HTML shell — only after a successful post; the production marker in a code root shell — before the post, since it needs no site UUID | Package names + versions; this site's public address and name, where the project or build environment states them; the site UUID, to check whether the site is connected to an account yet (skipped once `.patchstackrc.json` records that it is) |
79
79
  | `setup` | One bounded command: scan, widget, install + verify guard, upload map, pull live rules, wire build hooks. Never starts the app or runs a build. | Local integration and structural source analysis | Config, widget, guard/framework files, scripts, map identity in the guard rules JSON, git-ignored `.patchstack/` cache | Package inventory and site identity; structural map (routes, input names, packages, file:line, identity); authenticated Pulse rules lookup. No source code or environment values |
80
80
  | `map` | Local attack-surface analysis; setup invokes it with upload, and wires prebuild uploads. | Server source parsed with TypeScript (app compiler or CLI dependency) | `--out` file if requested; an uploaded map is stamped into the guard rules JSON during setup or a pre-bundle build hook | Standalone command sends nothing unless `--upload`. Setup and its build hook upload structure only, never source text or environment values |
81
81
  | `protect` | Install the always-on runtime guard; auto-wire known stacks, or scaffold a generic guard + print a wiring plan. `--check` verifies the guard is wired (exit 1 if not); `--demo` seeds a broad sample rule set. Runs automatically **only** via `setup` — never by `scan`, `guide`, `status`, or `mark-build`. | Reads local wiring/route source for integration; does not produce an attack-surface map | Guard/framework files (e.g. `middleware.ts`, `src/patchstack/`, supported Next App Router handlers) | Nothing |
82
82
  | `demo node-serialize` | Production-backed walkthrough: confirm the vulnerable package is present, scan, wait for live rule `18843`, install + verify the guard, print test requests. Does not install the package or start/restart the app. | Local integration reads via `scan` and `protect` | Same files as `scan` + `protect` | `scan` payload; polls the public Pulse rules endpoint (never the printed test requests) |
83
83
  | `demo-guide node-serialize` | Read-only companion: explains the prepare/run/prove/cleanup sequence and prints the next command. | Reads local protection wiring for verification | Nothing | Nothing |
84
84
  | `guide` | Print this project's live setup status (done/missing, with tailored commands), then the full guide. `--full` prints it even when setup is complete. | Reads local protection wiring for verification | Nothing | Nothing |
85
- | `status` | Re-print the site UUID + dashboard URL and check whether the site still exists (active / removed / could not verify). | No | Nothing | Site-existence check |
85
+ | `status` | Re-print the site UUID + dashboard URL and check whether the site still exists (active / removed / could not verify) and whether it is connected to an account. | No | The connected note in `.patchstackrc.json`, when it changed | Site-existence and connection checks |
86
86
  | `init <site-uuid>` | Optional: pre-seed `.patchstackrc.json` with an existing UUID. | No | `.patchstackrc.json` only | Nothing |
87
87
  | `mark-build` | Ensure the widget tag in built pages, and — **on a production build only** — stamp the live-site flag + build fingerprint. A local or preview build is stamped with neither, and has a stale marker removed; `--production` forces it for a build published by hand. Run as a `postbuild` step. | No | Build output only (`dist/ build/ out/ .output/public/ _site/`) — never source | The same manifest `scan` sent, plus one word for what it did with the marker — and only for a site already registered |
88
- | `claim` | Attach the site to a Patchstack account from the terminal: print a link the user opens to sign in (or sign up) and poll (10 min). Whoever approves becomes the owner. Does **not** rotate the credential. Same result as opening the dashboard link `scan` prints. Not usable in CI. | No | Nothing, unless the server issues a credential for a checkout that had none — then `.patchstackrc.local.json` | Device-code request + approval poll |
88
+ | `claim` | Attach the site to a Patchstack account from the terminal: print a link the user opens to sign in (or sign up) and poll (10 min). Whoever approves becomes the owner. Does **not** rotate the credential. Same result as opening the dashboard link `scan` prints. Not usable in CI. | No | The connected note in `.patchstackrc.json`; and, if the server issues a credential for a checkout that had none, `.patchstackrc.local.json` | Device-code request + approval poll |
89
89
  | `login` | Recover a lost credential for an existing site: print an owner-approval link and poll (10 min). Approving **rotates** the credential. Not usable in CI. | No | New credential into `.patchstackrc.local.json` on approval | Device-code request + approval poll |
90
90
  | `uninstall` | Signal Patchstack that the package is being removed: an unclaimed record is deleted, a claimed one is flagged. Does **not** touch local files. | No | Nothing local | Removal signal |
91
91
 
@@ -103,7 +103,7 @@ Every command at a glance — what it does, whether it reads your source, what i
103
103
  - **Mapping is automatic in `setup`, and in its prebuild hook.** It parses server source and sends structure, not source text. A standalone `map` command prints locally and uploads only with `--upload`. `protect`, `scan`, `guide`, `status` and `mark-build` do not invoke mapping.
104
104
  - **`scan` makes up to three source edits:** the Patchstack Connector's `<script>` tag, the production marker, and — during `prebuild` only — removal of a previous `_patchstack.build_id` from the existing guard rules file. None runs on `--dry-run`; all are idempotent. `"widget": false` disables the first two, while stale-stamp removal is independent because it prevents old coordinates being attributed to a new build.
105
105
  - The **widget tag** goes in the root HTML shell — the first of `index.html`, `public/index.html`, or `src/app.html` that exists — and only after a successful post, because it carries the site UUID.
106
- - The **production marker** goes in a root shell that is JSX rather than HTML (e.g. `src/routes/__root.tsx`, `app/layout.tsx`), inside a `{/* #region patchstack */}` block placed above the widget tag. It is written *before* the post: it carries no site UUID and needs no network, and build scripts commonly chain `patchstack-connect scan || true`, where waiting on the server would mean an offline build silently ships without the flag. The marker is guarded by the framework's own production expression (`import.meta.env.PROD`, or `process.env.NODE_ENV === 'production'`), so it is inert in dev and preview builds. Without it a server-rendered site has no built HTML for `mark-build` to stamp, and the widget treats the published site as build mode. `mark-build` writes to build output only (`dist/`, `build/`, `out/`, `.output/public/`, `_site/`), never to source. `guide`, `status`, and `init` write nothing except `init`'s own `.patchstackrc.json`.
106
+ - The **production marker** goes in a root shell that is JSX rather than HTML (e.g. `src/routes/__root.tsx`, `app/layout.tsx`), inside a `{/* #region patchstack */}` block placed above the widget tag. It is written *before* the post: it carries no site UUID and needs no network, and build scripts commonly chain `patchstack-connect scan || true`, where waiting on the server would mean an offline build silently ships without the flag. The marker is guarded by the framework's own production expression (`import.meta.env.PROD`, or `process.env.NODE_ENV === 'production'`), so it is inert in dev and preview builds. Without it a server-rendered site has no built HTML for `mark-build` to stamp, and the widget treats the published site as build mode. `mark-build` writes to build output only (`dist/`, `build/`, `out/`, `.output/public/`, `_site/`), never to source. `guide` writes nothing, `init` writes only its own `.patchstackrc.json`, and `status` writes only the connected note in `.patchstackrc.json`. `guide` sends nothing either: it reports a site as connected from that note, which `scan`, `status` and `claim` keep current.
107
107
  - **`setup` runs `scan` → `protect` → map upload → live-rule lookup**, then reports the outcome. Provisioning precedes guard installation. The map is stamped into the guard source for the NEXT startup/build; restart an already-running preview/server to load it. The rule lookup uses the runtime validator and source-scoped local cache without creating a running guard or installing global hooks. A successful empty policy is reported as zero assigned rules, not proof of protection. Failed uploads/pulls appear under Missing and can be retried by rerunning setup. It also wires install scans, prebuild scans + map uploads, and postbuild marking (explicit build chains for Yarn, pnpm and Bun), preserving existing commands. It never starts, builds or deploys the app. Ambiguous/custom integration code still requires review rather than being overwritten.
108
108
  - The package also exposes **`protect`** directly (runtime exploit guard; its templates live under `dist/protect/`). `setup` invokes it automatically; `scan`, `guide`, `status`, and `mark-build` do not. It writes only local files and auto-wires known stacks — **TanStack Start + Supabase** (patches the Supabase client + `src/start.ts`), **TanStack Start** (documented server Fetch entry without requiring Supabase), **Next.js** (scaffolds or composes middleware/proxy and adds request/response checks to supported App Router handlers), **SvelteKit** (`src/hooks.server.ts`), **Astro** (`src/middleware.ts`), **Nuxt** (`server/middleware/`), **NestJS** (`app.use(patchstackMiddleware)` in the bootstrap), **Fastify** (`app.register(patchstackFastify)`), and **Express** (`app.use(patchstackMiddleware)`). On **any other stack** it scaffolds a framework-agnostic guard under `src/patchstack/` and prints a wiring plan — then you finish the install by importing that guard into your server entry (`protectFetch(handler)` for a Web-Fetch server, or `app.use(patchstackMiddleware)` for Node/Express) and running `patchstack-connect protect --check` to confirm it is wired (exit 1 until it is). Passing `--demo` seeds a broad sample rule set (for demonstrations, not production).
109
109
  - **`demo node-serialize` is an explicit production-backed walkthrough.** It requires `node-serialize@0.0.4` to already be present in the lockfile; it does not install the vulnerable dependency. It runs the same production `scan`, polls the configured site's public Pulse rules endpoint until rule `18843` is served, runs `protect`, verifies the generated guard, and prints exploit/benign test requests. It writes the same manifest/widget and guard files as those underlying commands. It does not start/restart the app and does not send the printed requests.
@@ -290,6 +290,13 @@ neither a terminal nor a way to approve it. Then none of the options above exist
290
290
  running the command again, under any spelling, gets the same answer. Step 1 still applies: do not route
291
291
  around the block, and leave `package.json` and the source tree as they were.
292
292
 
293
+ That includes rebuilding by hand what `setup` would have done. Do not write a build plugin or script that
294
+ imitates a Patchstack step, do not set `window.__PATCHSTACK_PROD__` or `window.__PATCHSTACK_ENV__`
295
+ yourself, and do not call the Patchstack API in place of the CLI. A hosted builder can serve the same build
296
+ at its preview address and at the published one, so a marker decided at build time cannot be right for
297
+ both. A hand-set live-site flag tells the widget that the builder's preview is the live site, and the
298
+ person loses the "Connect this website" panel in the one place they would look for it.
299
+
293
300
  Tell the person in plain words that this platform will not run Patchstack's setup, then give them these
294
301
  choices and wait for theirs:
295
302
 
@@ -304,8 +311,10 @@ choices and wait for theirs:
304
311
  one script before bringing the changes back.
305
312
  - **Add only the Patchstack Connector.** The person creates an "Application" site in the Patchstack
306
313
  dashboard and gives you its site ID or widget snippet, and you add the tag as in steps 2 and 3 of
307
- "Plain HTML sites", in the app's root HTML shell or layout. This adds the widget and nothing else: no
308
- check of the app's packages, no build steps, no runtime protection. Say that when you offer it.
314
+ "Plain HTML sites", in the app's root HTML shell or layout. Add the tag only, with no production marker
315
+ and no build step: the widget then works out from the page's address whether it is on a preview or the
316
+ live site. This adds the widget and nothing else: no check of the app's packages, no build steps, no
317
+ runtime protection. Say that when you offer it.
309
318
  - **Stop here.** Nothing else changes.
310
319
 
311
320
  If you installed `@patchstack/connect` for this attempt, it stays in `dependencies` with nothing wired to
@@ -542,7 +551,7 @@ AI model. A framework or hosting upgrade requires this review again.
542
551
  - The CLI never opens the dashboard link and never asks for Patchstack credentials.
543
552
  - Label hosted workspace scans with `PATCHSTACK_ENVIRONMENT=sandbox` in that process only. Leave production builds unset (a platform's own tier or production branch name, or the hosted builder the project belongs to, makes the build report `production`; a developer machine or a CI runner this does not know reports `local`) and never commit a sandbox label into files shared with production.
544
553
  - If a step fails, stop and report it. Don't proceed with placeholders.
545
- - If your tool refuses to execute the CLI, stop and hand the command to the person — see "When your tool will not run this CLI", and "When the platform blocks the CLI outright" when nobody can approve it there. Never work around a permission refusal.
554
+ - If your tool refuses to execute the CLI, stop and hand the command to the person — see "When your tool will not run this CLI", and "When the platform blocks the CLI outright" when nobody can approve it there. Never work around a permission refusal, and never stand in for the CLI with a build step, a production marker or API calls of your own.
546
555
  - CI never has the credential in a file: `.patchstackrc.local.json` is git-ignored by design, so set `PATCHSTACK_API_KEY` as an env var there (and `PATCHSTACK_SITE_UUID` too where `.patchstackrc.json` is also absent). Precedence for the site UUID and settings: CLI flag → env var → `.patchstackrc.json`. For the API key: env var → `.patchstackrc.local.json` → `.patchstackrc.json` (where installs made before the split still hold it). `login` is interactive and refuses to run in CI, so CI always takes its credential from the environment.
547
556
 
548
557
  ## Which build a rule belongs to
@@ -826,11 +835,15 @@ When more than one guard in a process has `egress: true`, an outbound call is ch
826
835
  refused if any one refuses it. A host listed in one guard's `allowHosts` is still refused when another guard
827
836
  refuses it.
828
837
 
829
- Two more endpoints the package can call, for completeness:
838
+ Three more endpoints the package can call, for completeness:
830
839
 
831
840
  - `GET monitor/widget/settings/<your site uuid>` — how `status` tells "this site was deleted on
832
841
  Patchstack" apart from "still active". It sends no credential and nothing about your project; the site
833
842
  UUID in the path is the whole request.
843
+ - `GET monitor/claim/preview?site=<your site uuid>` — how `scan` and `status` tell whether the site is
844
+ connected to an account yet, the same lookup the claim link's page makes. It sends no credential and
845
+ nothing about your project; the site UUID is the whole request. `scan` stops asking once
846
+ `.patchstackrc.json` records `"claimed": true`.
834
847
  - `GET api/get-rules/3` — the older rules path, used only when the guard is configured with a `token`
835
848
  instead of a site UUID. The zero-configuration flow provisions a site UUID and uses
836
849
  `monitor/pulse/rules/<uuid>` instead, so this is unreachable unless you pass `token` yourself.
package/README.md CHANGED
@@ -374,6 +374,8 @@ Two files, because one value is public and the other is not.
374
374
 
375
375
  `"widget"` is optional and defaults to `true`; set it to `false` to stop Connect from managing the Patchstack Connector tag (see *The Patchstack Connector*).
376
376
 
377
+ Connect also keeps two fields there itself. `"claimUrl"` is the link that connects the site to your Patchstack account, saved when the site is created so it is not lost with the terminal output. Once `scan`, `status` or `claim` sees the site connected, the link is removed and `"claimed": true` takes its place, which is how `guide` knows without asking Patchstack.
378
+
377
379
  **You do not write `apiKey` yourself.** The first `scan` provisions the site and Connect saves it, so setup needs no manual step.
378
380
 
379
381
  The site UUID identifies the site and is **not** a secret — the Patchstack Connector ships the same UUID in client-side HTML.
@@ -292,4 +292,4 @@ export {
292
292
  canonicalBuildId,
293
293
  readBuildStamp
294
294
  };
295
- //# sourceMappingURL=chunk-52IV7LN7.js.map
295
+ //# sourceMappingURL=chunk-RQTKVXBB.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/protect/safe-origin.js","../src/types.ts","../src/endpoint-policy.ts","../src/bounded-response.ts","../src/pulse-token.ts","../src/build-id.ts"],"mappings":";AAKO,SAAS,aAAa,OAAO;AAClC,MAAI;AACF,UAAM,IAAI,IAAI,IAAI,KAAK;AACvB,QAAI,EAAE,aAAa,SAAU,QAAO;AACpC,WAAO,EAAE,aAAa,YAAY,EAAE,aAAa,eAAe,EAAE,aAAa,eAAe,EAAE,aAAa,WAAW,EAAE,aAAa;AAAA,EACzI,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMO,SAAS,YAAY,WAAW,UAAU,OAAO;AACtD,MAAI,OAAO,cAAc,YAAY,cAAc,GAAI,QAAO;AAC9D,MAAI,aAAa,SAAS,EAAG,QAAO;AACpC,WAAS,OAAO,gCAAgC,KAAK,cAAc,SAAS,qDAAqD;AACjI,SAAO;AACT;AAEA,IAAM,SAAS,oBAAI,IAAI;AACvB,SAAS,SAAS,KAAK,SAAS;AAC9B,MAAI,OAAO,IAAI,GAAG,EAAG;AACrB,SAAO,IAAI,GAAG;AAEd,UAAQ,KAAK,OAAO;AACtB;;;AC8HO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAQzC,YACE,SACgB,MAYA,OAChB;AACA,UAAM,OAAO;AAdG;AAYA;AAGhB,SAAK,OAAO;AAAA,EACd;AAAA,EAhBkB;AAAA,EAYA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAhBX,SAA4B,CAAC;AAqBtC;;;ACrLO,SAAS,0BAA0B,QAAgB,SAAS,OAAO,UAAgB;AACxF,MAAI,OAAO,oBAAoB,OAAO;AACpC,UAAM,IAAI;AAAA,MACR;AAAA,MAC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AAM,UAAU,MAAM,KAAK;AAE3B,SAAO,SAAS,KAAK,OAAO,IAAI,QAAQ,YAAY,IAAI;AAC1D;AASO,IAAM,kBAAkB;AASxB,SAAS,eAAe,QAAgC;AAC7D,MAAI,WAAW,QAAQ,OAAO,WAAW,SAAU,QAAO;AAC1D,QAAM,YAAa,OAAmC,eAAe;AACrE,MAAI,cAAc,QAAQ,OAAO,cAAc,SAAU,QAAO;AAEhE,SAAO,iBAAkB,UAAsC,QAAQ;AACzE;","names":[]}
1
+ {"version":3,"sources":["../src/protect/safe-origin.js","../src/types.ts","../src/endpoint-policy.ts","../src/bounded-response.ts","../src/pulse-token.ts","../src/build-id.ts"],"mappings":";AAKO,SAAS,aAAa,OAAO;AAClC,MAAI;AACF,UAAM,IAAI,IAAI,IAAI,KAAK;AACvB,QAAI,EAAE,aAAa,SAAU,QAAO;AACpC,WAAO,EAAE,aAAa,YAAY,EAAE,aAAa,eAAe,EAAE,aAAa,eAAe,EAAE,aAAa,WAAW,EAAE,aAAa;AAAA,EACzI,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMO,SAAS,YAAY,WAAW,UAAU,OAAO;AACtD,MAAI,OAAO,cAAc,YAAY,cAAc,GAAI,QAAO;AAC9D,MAAI,aAAa,SAAS,EAAG,QAAO;AACpC,WAAS,OAAO,gCAAgC,KAAK,cAAc,SAAS,qDAAqD;AACjI,SAAO;AACT;AAEA,IAAM,SAAS,oBAAI,IAAI;AACvB,SAAS,SAAS,KAAK,SAAS;AAC9B,MAAI,OAAO,IAAI,GAAG,EAAG;AACrB,SAAO,IAAI,GAAG;AAEd,UAAQ,KAAK,OAAO;AACtB;;;ACoIO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAQzC,YACE,SACgB,MAYA,OAChB;AACA,UAAM,OAAO;AAdG;AAYA;AAGhB,SAAK,OAAO;AAAA,EACd;AAAA,EAhBkB;AAAA,EAYA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAhBX,SAA4B,CAAC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;AAAA,EACxB;AAEA,SAAO,MAAM;AACf;;;AC/KA,IAAM,WAAW;AAWV,SAAS,iBAAiB,OAA+B;AAC9D,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,UAAU,MAAM,KAAK;AAE3B,SAAO,SAAS,KAAK,OAAO,IAAI,QAAQ,YAAY,IAAI;AAC1D;AASO,IAAM,kBAAkB;AASxB,SAAS,eAAe,QAAgC;AAC7D,MAAI,WAAW,QAAQ,OAAO,WAAW,SAAU,QAAO;AAC1D,QAAM,YAAa,OAAmC,eAAe;AACrE,MAAI,cAAc,QAAQ,OAAO,cAAc,SAAU,QAAO;AAEhE,SAAO,iBAAkB,UAAsC,QAAQ;AACzE;","names":[]}
package/dist/cli.js CHANGED
@@ -1816,6 +1816,30 @@ async function fetchSiteStatus(config) {
1816
1816
  return "unknown";
1817
1817
  }
1818
1818
  }
1819
+ async function fetchClaimState(config) {
1820
+ if (config.siteUuid === null) return "unknown";
1821
+ const url = new URL("/monitor/claim/preview", new URL(config.endpoint).origin);
1822
+ url.searchParams.set("site", config.siteUuid);
1823
+ try {
1824
+ assertConnectableEndpoint(config, url.toString());
1825
+ const response = await fetch(url.toString(), {
1826
+ method: "GET",
1827
+ headers: {
1828
+ Accept: "application/json",
1829
+ "Cache-Control": "no-cache",
1830
+ "User-Agent": "@patchstack/connect"
1831
+ },
1832
+ signal: AbortSignal.timeout(config.timeoutMs)
1833
+ });
1834
+ if (!response.ok) return "unknown";
1835
+ const body = await readBoundedJson(response);
1836
+ if (body?.state === "claimable") return "unclaimed";
1837
+ if (body?.state === "owned-by-other" || body?.state === "owned-by-you") return "claimed";
1838
+ return "unknown";
1839
+ } catch {
1840
+ return "unknown";
1841
+ }
1842
+ }
1819
1843
  function buildManifestBody(config, payload, env = process.env, marker = null) {
1820
1844
  const hosting = config.environment === "local" ? null : detectHostingPlatform(env);
1821
1845
  return {
@@ -2676,6 +2700,7 @@ async function resolveConfig(options) {
2676
2700
  environmentSource,
2677
2701
  ignoredFileEnvironment,
2678
2702
  widget: fromFile.widget !== false,
2703
+ claimed: fromFile.claimed === true,
2679
2704
  claimToken
2680
2705
  };
2681
2706
  }
@@ -2785,9 +2810,28 @@ function ignoresEntry(contents, entry) {
2785
2810
  }
2786
2811
  return ignored;
2787
2812
  }
2788
- async function persistSiteUuid(cwd, siteUuid) {
2813
+ async function persistSiteUuid(cwd, siteUuid, claimUrl) {
2814
+ const existing = await readConfigFile(cwd);
2815
+ return writeConfigFile(cwd, {
2816
+ ...existing,
2817
+ siteUuid,
2818
+ ...typeof claimUrl === "string" && claimUrl !== "" ? { claimUrl } : {}
2819
+ });
2820
+ }
2821
+ async function persistClaimState(cwd, claimed, claimUrl) {
2789
2822
  const existing = await readConfigFile(cwd);
2790
- return writeConfigFile(cwd, { ...existing, siteUuid });
2823
+ if (typeof existing.siteUuid !== "string" || existing.siteUuid === "") return false;
2824
+ const next = { ...existing };
2825
+ if (claimed) {
2826
+ next.claimed = true;
2827
+ delete next.claimUrl;
2828
+ } else {
2829
+ delete next.claimed;
2830
+ if (typeof claimUrl === "string" && claimUrl !== "") next.claimUrl = claimUrl;
2831
+ }
2832
+ if (JSON.stringify(next) === JSON.stringify(existing)) return false;
2833
+ await writeConfigFile(cwd, next);
2834
+ return true;
2791
2835
  }
2792
2836
  async function persistTimeout(cwd, timeoutMs) {
2793
2837
  const existing = await readConfigFile(cwd);
@@ -6877,6 +6921,7 @@ async function collectGuideState(cwd) {
6877
6921
  }
6878
6922
  let siteUuid = null;
6879
6923
  let claimUrl = null;
6924
+ let claimed = false;
6880
6925
  let endpointOverride = null;
6881
6926
  let widgetOptOut = false;
6882
6927
  let environment = null;
@@ -6886,6 +6931,7 @@ async function collectGuideState(cwd) {
6886
6931
  environment = config.environment;
6887
6932
  environmentSource = config.environmentSource ?? null;
6888
6933
  siteUuid = config.siteUuid;
6934
+ claimed = siteUuid !== null && config.claimed === true;
6889
6935
  if (siteUuid !== null && config.endpointTrusted !== false) {
6890
6936
  claimUrl = buildClaimUrl(config.endpoint, siteUuid);
6891
6937
  }
@@ -6910,6 +6956,7 @@ async function collectGuideState(cwd) {
6910
6956
  installed,
6911
6957
  siteUuid,
6912
6958
  claimUrl,
6959
+ claimed,
6913
6960
  endpointOverride,
6914
6961
  environment,
6915
6962
  environmentSource,
@@ -6959,9 +7006,9 @@ function countRemainingSteps(state) {
6959
7006
  function guideProgress(state, known = {}) {
6960
7007
  return {
6961
7008
  installed: state.installed !== null,
6962
- // Claim state lives on the server and nothing on disk records it, so only a caller that has just
6963
- // heard from the server (a scan's claim outcome) can mark it done.
6964
- connected: false,
7009
+ // Claim state lives on the server. The working tree has only the note a scan, status or claim left
7010
+ // in `.patchstackrc.json`; a caller that has just heard from the server overrides it.
7011
+ connected: state.claimed,
6965
7012
  // `.patchstackrc.json` only gains a site UUID from a manifest the server stored.
6966
7013
  synced: state.siteUuid !== null,
6967
7014
  // Only the dashboard can see the live site, so nothing the CLI runs marks this done.
@@ -7057,7 +7104,7 @@ function guideMissing(state, known = {}) {
7057
7104
  }
7058
7105
  );
7059
7106
  }
7060
- if (known.connected !== true) missing.push(notConnectedItem());
7107
+ if ((known.connected ?? state.claimed) !== true) missing.push(notConnectedItem());
7061
7108
  return missing;
7062
7109
  }
7063
7110
  function renderGuideChecklist(state, useColor2, known = {}, options = {}) {
@@ -12991,6 +13038,7 @@ async function runClaim(args) {
12991
13038
  return 1;
12992
13039
  }
12993
13040
  const settled = async (result2) => {
13041
+ await recordClaimState(config, siteUuid, true);
12994
13042
  console.log(
12995
13043
  `
12996
13044
  \u2713 Site claimed${result2.account !== void 0 ? ` by ${result2.account}` : ""}.`
@@ -13042,6 +13090,7 @@ async function runClaim(args) {
13042
13090
  const started = await startClaim(config);
13043
13091
  if (started.status !== "started" || started.pending === void 0) {
13044
13092
  if (started.status === "already-claimed") {
13093
+ await recordClaimState(config, siteUuid, true);
13045
13094
  console.log(`
13046
13095
  ${started.message ?? "This site is already claimed."}
13047
13096
  `);
@@ -13062,6 +13111,7 @@ async function runClaim(args) {
13062
13111
  });
13063
13112
  if (result.status === "claimed") return await settled(result);
13064
13113
  if (result.status === "already-claimed") {
13114
+ await recordClaimState(config, siteUuid, true);
13065
13115
  console.log(`
13066
13116
  ${result.message ?? "This site is already claimed."}
13067
13117
  `);
@@ -13283,9 +13333,10 @@ async function runScan(args, options = {}) {
13283
13333
  });
13284
13334
  }
13285
13335
  if (provisioning && response.uuid !== void 0 && response.uuid.length > 0) {
13286
- const target = await persistSiteUuid(process.cwd(), response.uuid);
13336
+ const claimUrl = config.endpointTrusted !== false ? buildClaimUrl(config.endpoint, response.uuid) : null;
13337
+ const target = await persistSiteUuid(process.cwd(), response.uuid, claimUrl);
13287
13338
  report.done.push("Added this project to Patchstack");
13288
- say(`Created site ${response.uuid}. Saved to ${target}.`);
13339
+ say(`Created site ${response.uuid}. Saved it${claimUrl !== null ? " and the link to connect it" : ""} to ${target}.`);
13289
13340
  }
13290
13341
  if (typeof response.api_key === "string" && response.api_key.length > 0) {
13291
13342
  const hadCredentialInConfig = await credentialInCommittedConfig(process.cwd());
@@ -13315,11 +13366,12 @@ async function runScan(args, options = {}) {
13315
13366
  } else if (claim3 !== null) {
13316
13367
  report.missing.push(notConnectedItem([`${claim3.summary}.`, ...claim3.hint]));
13317
13368
  }
13318
- const connected = response.claim?.state === "claimed" || response.claim?.state === "owned-by-you";
13369
+ const tokenConnected = response.claim?.state === "claimed" || response.claim?.state === "owned-by-you";
13319
13370
  const effectiveUuid = config.siteUuid ?? response.uuid ?? null;
13320
13371
  if (config.widget && effectiveUuid !== null && effectiveUuid.length > 0) {
13321
13372
  reportSourceWidget(effectiveUuid, shellFramework, report);
13322
13373
  }
13374
+ const connected = await resolveConnected(config, effectiveUuid, tokenConnected);
13323
13375
  const synced = effectiveUuid !== null && effectiveUuid.length > 0 && (response.stored || response.reason === "duplicate" || response.reason === "build-reported");
13324
13376
  const outcome = {
13325
13377
  connected,
@@ -13336,6 +13388,20 @@ async function runScan(args, options = {}) {
13336
13388
  }
13337
13389
  return 0;
13338
13390
  }
13391
+ async function resolveConnected(config, siteUuid, tokenConnected) {
13392
+ if (siteUuid === null || siteUuid.length === 0) return false;
13393
+ if (!tokenConnected && config.claimed === true) return true;
13394
+ const state = tokenConnected ? "claimed" : await fetchClaimState({ ...config, siteUuid });
13395
+ if (state !== "unknown") await recordClaimState(config, siteUuid, state === "claimed");
13396
+ return state === "claimed";
13397
+ }
13398
+ async function recordClaimState(config, siteUuid, claimed) {
13399
+ const claimUrl = config.endpointTrusted !== false ? buildClaimUrl(config.endpoint, siteUuid) : null;
13400
+ try {
13401
+ await persistClaimState(process.cwd(), claimed, claimUrl);
13402
+ } catch {
13403
+ }
13404
+ }
13339
13405
  function mergeMissing(...lists) {
13340
13406
  const merged = [];
13341
13407
  for (const item of lists.flat()) {
@@ -13707,7 +13773,15 @@ async function runStatus(args) {
13707
13773
  console.log(`Environment: ${config.environment}`);
13708
13774
  if (config.siteUuid !== null) {
13709
13775
  console.log(`Dashboard URL: ${buildClaimUrl(config.endpoint, config.siteUuid)}`);
13710
- console.log(" Not connected yet? Open the link above or run `npx @patchstack/connect claim`.");
13776
+ const claimState = await fetchClaimState(config);
13777
+ if (claimState !== "unknown") await recordClaimState(config, config.siteUuid, claimState === "claimed");
13778
+ if (claimState === "claimed") {
13779
+ console.log("Connected: yes, to a Patchstack account");
13780
+ } else if (claimState === "unclaimed") {
13781
+ console.log("Connected: not yet. Open the link above or run `npx @patchstack/connect claim`.");
13782
+ } else {
13783
+ console.log("Connected: could not be verified. Not connected yet? Open the link above.");
13784
+ }
13711
13785
  switch (await fetchSiteStatus(config)) {
13712
13786
  case "active":
13713
13787
  console.log("Site status: active on Patchstack");