Skip to content

Print claim URL after provisioning, expose in status#13

Merged
ejntaylor merged 1 commit into
mainfrom
elliott/print-claim-link
May 13, 2026
Merged

Print claim URL after provisioning, expose in status#13
ejntaylor merged 1 commit into
mainfrom
elliott/print-claim-link

Conversation

@ejntaylor
Copy link
Copy Markdown
Contributor

Summary

Implements the connector-side half of the claim flow agreed in ADR-0004.

  • After a successful provisioning scan, the connector prints a claim URL so the user can attach the new site to their Patchstack account.
  • npx @patchstack/connect status re-displays the claim URL whenever a UUID is configured.
  • The URL is constructed from the API endpoint's origin plus /claim?site=<uuid> — works for production, staging, ngrok and local mock servers without code changes.

Why

ADR-0004 (revised in saas#508) decides:

The site UUID is the credential for claiming. There is no separate claim token in the MVP. The connector prints a claim URL after every successful provisioning scan; the URL is constructed from the API endpoint's origin plus /claim?site=<uuid>.

This PR is the connector half of that decision. The matching SaaS work — adding the GET /claim?site=<uuid> page and the authenticated POST /claim route — lands separately on the SaaS side. Until that ships, clicking the URL will 404; the connector printing it does no harm and makes the connector ready as soon as the SaaS endpoint goes live.

What's in it

  • src/client.ts — new buildClaimUrl(endpoint, siteUuid) helper alongside buildEndpointUrl. Uses new URL(endpoint).origin to extract the host part, so changing the API path doesn't break the claim URL.
  • src/cli.tsrunScan prints the URL after the manifest-stored message, only on the provisioning path (first scan of a fresh project). runStatus shows a Claim URL: line whenever a UUID is configured.
  • src/index.ts — exports buildClaimUrl for programmatic consumers.
  • tests/client.test.ts — 6 new tests cover origin extraction, ngrok-style hosts, trailing slashes, scheme preservation (http vs https), URL encoding of the UUID, and dropping deep paths from the endpoint. Suite is 51 green.
  • README.md — adds the claim step to the "Quick start (zero configuration)" walkthrough.

What's deliberately not in it

  • No state added to .patchstackrc.json. The claim URL is reconstructible from siteUuid + endpoint and is never persisted. ADR-0004 explicitly avoids storing claim state in source control.
  • No detection of already-claimed sites. The ADR's "Watch" note flags this as a v2 improvement (server returns claimed: true, connector suppresses the link). For MVP the URL is informational; the /claim page tells a user "already claimed" if they reach it after the site is taken.
  • No SaaS-side changes. Mario or whoever owns the SaaS claim route will add GET/POST /claim separately. The connector PR is independent and harmless until then.

Output sample

Found 5 unique package versions across 4 package names in npm lockfile.
1 package(s) appear at multiple versions:
  lodash
No site UUID configured — provisioning a new Patchstack site from this manifest…
Provisioned site 973e041c-b607-413d-b8e3-556f81d848db. Saved UUID to /path/.patchstackrc.json.
Stored manifest #14 (checksum c5cf5c1b2279).

Claim this site to view vulnerability reports in your Patchstack dashboard:
  https://app.patchstack.com/claim?site=973e041c-b607-413d-b8e3-556f81d848db

Test plan

  • npx vitest run — 51/51 passing
  • npx tsc --noEmit — clean
  • End-to-end smoke test against a local mock server returning the exact response shape from the SaaS — claim URL prints correctly in both scan and status
  • Once the SaaS /claim route lands, click the URL from a real provisioning scan and confirm the round-trip

🤖 Generated with Claude Code

After ADR-0004 (revised) the site UUID is the credential for claiming.
The connector now prints the claim URL once the server provisions a
new site, and the status command re-displays it on demand.

The URL is constructed from the API endpoint's origin plus
`/claim?site=<uuid>`. Using the endpoint origin (rather than a
hard-coded https://app.patchstack.com) means the connector produces
the right URL whether it is talking to production, a staging deploy,
an ngrok tunnel, or a local mock server.

- New buildClaimUrl(endpoint, siteUuid) helper in client.ts, also
  exported from the public API.
- runScan prints the URL right after the manifest-stored message,
  but only on the provisioning path (first scan of a fresh project).
- runStatus shows a Claim URL line whenever a UUID is configured.
- 6 new tests cover origin extraction, staging hosts, trailing
  slashes, scheme preservation, and URL encoding. Suite is 51 green.

No state added to .patchstackrc.json — the claim URL is reconstructible
from siteUuid + endpoint and is never persisted.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ejntaylor ejntaylor merged commit f7f78ba into main May 13, 2026
4 checks passed
@ejntaylor ejntaylor deleted the elliott/print-claim-link branch May 13, 2026 08:43
ejntaylor added a commit that referenced this pull request May 13, 2026
…PS (#14)

Two minor URL corrections that should have landed together in #13:

- Claim URL: the SaaS claim page is at /monitor/claim alongside the
  other Pulse portal routes, not at /claim on the root.
- Default endpoint: was http://api.patchstack.com (HTTP). Browsers
  will redirect to HTTPS at the server, but printing an http:// link
  in the build log is sloppy.

Tests updated; help text and README brought in line.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants