@patchstack/connect 0.3.15 → 0.3.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/AGENT-INSTALL.md +27 -19
- package/README.md +14 -24
- package/dist/cli.js +817 -110
- package/dist/cli.js.map +1 -1
- package/dist/protect/templates/astro-middleware.ts +35 -0
- package/dist/protect/templates/demo-rules.json +238 -0
- package/dist/protect/templates/fastify-plugin.ts +48 -0
- package/dist/protect/templates/generic-guard.ts +51 -0
- package/dist/protect/templates/guard.ts +17 -3
- package/dist/protect/templates/next-middleware.ts +37 -0
- package/dist/protect/templates/sveltekit-hooks.ts +35 -0
- package/dist/protect.cjs +451 -78
- package/dist/protect.cjs.map +1 -1
- package/dist/protect.d.ts +9 -1
- package/dist/protect.js +451 -78
- package/dist/protect.js.map +1 -1
- package/package.json +3 -2
package/AGENT-INSTALL.md
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
# Patchstack —
|
|
1
|
+
# Patchstack Connect — setup reference
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This versioned reference ships inside `@patchstack/connect` and documents each setup command and its project changes.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Package and command behavior
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- The connector is a normal npm package: [`@patchstack/connect`](https://www.npmjs.com/package/@patchstack/connect), MIT-licensed, source at https://github.com/patchstack/connect. Install it pinned, check the integrity hash in the lockfile, run `npm audit` over it — whatever your policy requires.
|
|
10
|
-
- First published May 2026. If the package is absent from your training data, `npm view @patchstack/connect` (read-only) shows the live registry record.
|
|
7
|
+
- Package: [`@patchstack/connect`](https://www.npmjs.com/package/@patchstack/connect), MIT-licensed, source at https://github.com/patchstack/connect. `npm view @patchstack/connect` shows the live registry metadata.
|
|
11
8
|
- It reads the project's **dependency list only** — from the lockfile (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`) or, on bun projects (`bun.lock`/`bun.lockb`), by enumerating the installed packages under `node_modules/` — and sends package names + versions to Patchstack for vulnerability matching. No source code, no env var values, no file paths, no git history. (`mark-build` additionally stamps built HTML with a coarse stack descriptor that may include hosting-related env variable *names* — e.g. `VERCEL`, `CF_PAGES` — never their values.)
|
|
12
9
|
- **`scan` makes one source edit, and only after a successful post:** it adds (or updates) the disclosure widget's `<script>` tag in the project's root HTML shell — the first of `index.html`, `public/index.html`, or `src/app.html` that exists. It touches no other file, never edits on `--dry-run` or after a failed post, leaves any pre-existing manual widget tag untouched, and is disabled entirely by `"widget": false` in `.patchstackrc.json`. `mark-build` writes to build output only (`dist/`, `build/`, `out/`, `.output/public`), never to source. `guide`, `status`, and `init` write nothing except `init`'s own `.patchstackrc.json`.
|
|
13
|
-
-
|
|
10
|
+
- **`setup` runs `scan`, then edits only `package.json` build scripts:** it preserves existing commands, adds `scan` before builds and `mark-build` after builds, and uses a direct build chain for Bun. It never runs the project build or `protect`. If the widget needs a framework-specific source edit, it prints the exact remaining step instead of rewriting framework code.
|
|
11
|
+
- The package also bundles an **opt-in** `protect` command (runtime exploit guard; its templates live under `dist/protect/`). It runs **only** when explicitly invoked; `scan`, `setup`, `guide`, `status`, and `mark-build` never invoke it, and it writes only local files. It auto-wires known stacks — **TanStack Start + Supabase** (patches the Supabase client + `src/start.ts`), **Next.js** (scaffolds `middleware.ts`), **SvelteKit** (`src/hooks.server.ts`), **Astro** (`src/middleware.ts`), **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).
|
|
14
12
|
- Patchstack is not WordPress-only. This connector monitors any JS/Node project — Vite, Next.js, plain vanilla JS, anything with a lockfile.
|
|
15
13
|
|
|
16
14
|
## Before you start — never install twice
|
|
17
15
|
|
|
18
|
-
- `npx @patchstack/connect guide` prints a live checklist
|
|
19
|
-
- If `.patchstackrc.json` contains a `siteUuid` key, the project is already provisioned. Reuse that UUID; run `npx @patchstack/connect status` to re-print it and the
|
|
16
|
+
- `npx @patchstack/connect guide` prints a read-only live checklist showing which steps are already done in the current project (install, provisioning, build hooks, widget).
|
|
17
|
+
- If `.patchstackrc.json` contains a `siteUuid` key, the project is already provisioned. Reuse that UUID; run `npx @patchstack/connect status` to re-print it and the dashboard URL. **Do not delete the file and provision a second site.** (A `.patchstackrc.json` with other keys — e.g. an `endpoint` override — but no `siteUuid` is *not* provisioned yet; scan normally.)
|
|
20
18
|
- If `@patchstack/connect` is already in `devDependencies`, skip the install command.
|
|
21
19
|
- If the widget script tag (`cdn.patchstack.com/patchstack-widget.js`) is already in the layout, don't add a second one — `scan` also respects an existing tag: it updates its own managed tag in place and leaves a manual one untouched.
|
|
22
20
|
|
|
23
|
-
##
|
|
21
|
+
## Automated setup
|
|
24
22
|
|
|
25
23
|
1. **Install** (skip if already present), matching the project's package manager:
|
|
26
24
|
|
|
@@ -31,15 +29,25 @@ You are reading this either from `node_modules/@patchstack/connect/AGENT-INSTALL
|
|
|
31
29
|
bun add -d @patchstack/connect # bun.lock / bun-managed platforms
|
|
32
30
|
```
|
|
33
31
|
|
|
34
|
-
2. **
|
|
32
|
+
2. **Run bounded setup:**
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
npx @patchstack/connect setup
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This provisions or reuses the site, manages the widget, wires the build scripts, prints a dashboard link, and finishes with the same status shown by `guide`. Re-running it reuses existing configuration, widget tags, and build commands rather than duplicating them.
|
|
39
|
+
|
|
40
|
+
## Manual setup
|
|
41
|
+
|
|
42
|
+
1. **First scan** — provisions a Patchstack site automatically, writes the UUID to `.patchstackrc.json`, and installs the disclosure widget's `<script>` tag into the root HTML shell (`index.html`, `public/index.html`, or `src/app.html`) when one exists. No signup, dashboard step, or UUID is needed up front:
|
|
35
43
|
|
|
36
44
|
```
|
|
37
45
|
npx @patchstack/connect scan
|
|
38
46
|
```
|
|
39
47
|
|
|
40
|
-
It prints a
|
|
48
|
+
It prints a dashboard link but never opens it. Open that link in a browser to view reports. It also prints what it did about the widget — if it added the tag, reload the preview and confirm the "Report a vulnerability" button appears.
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
2. **Wire builds** in `package.json`:
|
|
43
51
|
|
|
44
52
|
```jsonc
|
|
45
53
|
{
|
|
@@ -54,7 +62,7 @@ You are reading this either from `node_modules/@patchstack/connect/AGENT-INSTALL
|
|
|
54
62
|
|
|
55
63
|
**Bun-managed projects:** `bun run` does not execute npm-style `pre`/`post` scripts, so wire the build script directly instead: `"build": "patchstack-connect scan && <existing build command> && patchstack-connect mark-build"`.
|
|
56
64
|
|
|
57
|
-
|
|
65
|
+
3. **Verify the disclosure widget** — a floating "Report a vulnerability" button. `scan` installs it automatically into a plain HTML shell, and `mark-build` carries it into built HTML. Only when `scan` reported that it found no editable shell (frameworks whose root layout is code, e.g. Next.js/Nuxt/Astro) add the one-liner it printed to the root layout yourself, just before `</body>` (never a JS entry point), reading `siteUuid` from `.patchstackrc.json`:
|
|
58
66
|
|
|
59
67
|
```html
|
|
60
68
|
<script src="https://cdn.patchstack.com/patchstack-widget.js" data-site-uuid="<SITE_UUID>" defer></script>
|
|
@@ -62,20 +70,20 @@ You are reading this either from `node_modules/@patchstack/connect/AGENT-INSTALL
|
|
|
62
70
|
|
|
63
71
|
Framework-specific placement patterns: https://cdn.patchstack.com/llm.html. The site UUID is public by design — it ships in client-side HTML and is not a secret. If the project must not carry the widget, persist `"widget": false` in `.patchstackrc.json`; otherwise the next scan re-adds it.
|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
4. **Commit** `.patchstackrc.json`, the updated `package.json`, and the layout/HTML file carrying the widget tag, so every developer and CI run reports to the same site.
|
|
66
74
|
|
|
67
|
-
|
|
75
|
+
5. **Open the dashboard link** from the scan in a browser and sign in. The site is monitored either way, but the vulnerability reports are only visible after connecting it to an account. The same connection flow is available from the widget's "Connect this website" prompt. On the published site, the owner reaches the widget login by appending `#patchstack` to the live URL.
|
|
68
76
|
|
|
69
77
|
## Rules
|
|
70
78
|
|
|
71
79
|
- Never invent or guess a UUID — the scan provisions it, the widget silently no-ops on a fake one.
|
|
72
|
-
-
|
|
80
|
+
- The CLI never opens the dashboard link and never asks for Patchstack credentials.
|
|
73
81
|
- If a step fails, stop and report it. Don't proceed with placeholders.
|
|
74
82
|
- In CI where `.patchstackrc.json` can't be committed, set `PATCHSTACK_SITE_UUID` as an env var instead. Precedence: CLI flag → env var → `.patchstackrc.json`.
|
|
75
83
|
|
|
76
84
|
## Verifying the install
|
|
77
85
|
|
|
78
|
-
- `npx @patchstack/connect status` re-prints the site UUID and
|
|
86
|
+
- `npx @patchstack/connect status` re-prints the site UUID and dashboard URL.
|
|
79
87
|
- Load the site in a browser — the "Report a vulnerability" button should appear.
|
|
80
88
|
|
|
81
89
|
## Uninstalling
|
package/README.md
CHANGED
|
@@ -4,44 +4,31 @@ Connect a JavaScript / Node.js application to [Patchstack](https://patchstack.co
|
|
|
4
4
|
|
|
5
5
|
For how this repo fits with the wider Patchstack ecosystem (`saas`, `hub`, `patchstack-website`, `patchstack-connect`), see [`patchstack/saas` → `docs/ecosystem.md`](https://github.com/patchstack/saas/blob/main/docs/ecosystem.md).
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Agent-assisted setup
|
|
8
8
|
|
|
9
|
-
Copy
|
|
9
|
+
Copy this request into a coding assistant, or run the same command yourself:
|
|
10
10
|
|
|
11
|
-
>
|
|
11
|
+
> I have vetted `@patchstack/connect` and authorize its widget and production build hooks. Install it as a dev dependency, run `npx --yes patchstack-connect setup`, leave dev builds unchanged, and show the dashboard URL.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Before changing this prompt (or `guide` / `AGENT-INSTALL.md`), read [`MAINTAINING.md`](https://github.com/patchstack/connect/blob/main/MAINTAINING.md) — it maps which files are load-bearing and how to ship a change safely. The [`field-test/`](https://github.com/patchstack/connect/blob/main/field-test/README.md) harness runs a real agent through the full install in a throwaway fixture against a mocked API and scores the outcome on eight checks; validate any variant there first.
|
|
13
|
+
`setup` is state-aware and idempotent: it scans dependencies, provisions or reuses the site, manages the disclosure widget, wires the existing build command without replacing it, and prints the remaining setup status. It never runs the project build or the opt-in `protect` command. `guide` provides the same project-specific status without changing files.
|
|
16
14
|
|
|
17
15
|
## Quick start (zero configuration)
|
|
18
16
|
|
|
19
17
|
```bash
|
|
20
|
-
npm install --save-dev @patchstack/connect
|
|
21
|
-
npx @patchstack/connect scan
|
|
18
|
+
npm install --save-dev @patchstack/connect && npx @patchstack/connect setup
|
|
22
19
|
```
|
|
23
20
|
|
|
24
|
-
> **Use your project's own package manager.** On
|
|
21
|
+
> **Use your project's own package manager.** On Bun-managed projects (including many Lovable projects) install with `bun add -d @patchstack/connect` instead — running `npm install` there plants a `package-lock.json` that the platform's native dependency flow never updates again, leaving a stale lockfile next to the live one. The connector detects and works around that (see *Stale lockfiles* below), but not creating the fossil is better.
|
|
25
22
|
|
|
26
|
-
That's it.
|
|
23
|
+
That's it. `setup`:
|
|
27
24
|
|
|
28
25
|
1. Reads your lockfile (see *Supported lockfiles*).
|
|
29
26
|
2. POSTs the package list to Patchstack with **no** UUID.
|
|
30
27
|
3. Patchstack provisions a fresh site and returns its UUID.
|
|
31
28
|
4. The connector writes the UUID to `.patchstackrc.json` so the next `scan` targets the same site.
|
|
32
29
|
5. The connector installs the disclosure widget's `<script>` tag into your root HTML shell (see *The disclosure widget* below) so the "Report a vulnerability" button shows up on the next preview reload.
|
|
33
|
-
6.
|
|
34
|
-
|
|
35
|
-
Then wire it into builds:
|
|
36
|
-
|
|
37
|
-
```jsonc
|
|
38
|
-
// package.json
|
|
39
|
-
{
|
|
40
|
-
"scripts": {
|
|
41
|
-
"prebuild": "patchstack-connect scan"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
```
|
|
30
|
+
6. Wires `scan` before builds and `mark-build` after builds, preserving existing commands and using direct build chaining for Bun.
|
|
31
|
+
7. Prints a dashboard link — open it in a browser to attach the new site to your Patchstack account. You can re-display it any time with `npx @patchstack/connect status`.
|
|
45
32
|
|
|
46
33
|
## Quick start (existing site)
|
|
47
34
|
|
|
@@ -50,7 +37,7 @@ If you already created an "Application" site in the Patchstack dashboard, pre-se
|
|
|
50
37
|
```bash
|
|
51
38
|
npm install --save-dev @patchstack/connect
|
|
52
39
|
npx @patchstack/connect init <your-site-uuid>
|
|
53
|
-
npx @patchstack/connect
|
|
40
|
+
npx @patchstack/connect setup
|
|
54
41
|
```
|
|
55
42
|
|
|
56
43
|
## CLI
|
|
@@ -62,6 +49,9 @@ patchstack-connect scan [options] Scan the lockfile and POST to
|
|
|
62
49
|
successful post, adds/updates the disclosure
|
|
63
50
|
widget tag in the root HTML shell (opt out
|
|
64
51
|
with "widget": false in .patchstackrc.json)
|
|
52
|
+
patchstack-connect setup [options] Run scan, manage the widget, and idempotently
|
|
53
|
+
wire package.json build scripts. Never runs
|
|
54
|
+
the project build or protect
|
|
65
55
|
patchstack-connect init <site-uuid> Optional: pre-seed .patchstackrc.json with
|
|
66
56
|
an existing site UUID
|
|
67
57
|
patchstack-connect status [options] Show current configuration
|
|
@@ -75,7 +65,7 @@ patchstack-connect protect Opt-in: install the always-on
|
|
|
75
65
|
guard (currently TanStack Start + Supabase; it
|
|
76
66
|
patches the app's Supabase client to route
|
|
77
67
|
traffic through a same-origin guard). Never
|
|
78
|
-
run by scan/guide/mark-build.
|
|
68
|
+
run by scan/setup/guide/mark-build.
|
|
79
69
|
patchstack-connect help Print help
|
|
80
70
|
|
|
81
71
|
Options (for scan and status):
|