@patchstack/connect 0.3.22 → 0.3.23

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
@@ -73,7 +73,7 @@ This versioned reference ships inside `@patchstack/connect` and documents each s
73
73
  <script src="https://cdn.patchstack.com/patchstack-widget.js" data-site-uuid="<SITE_UUID>" defer></script>
74
74
  ```
75
75
 
76
- 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.
76
+ 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. The `apiKey` (also `PATCHSTACK_API_KEY`, WP format `{secret}-{oauth.id}`) is the opposite: server-only, used to authenticate block-log reporting through the existing connector `POST /api/logs/log` so "Threats blocked" fills in the dashboard. Never put `apiKey` in the widget tag, client bundles, or public env vars (`NEXT_PUBLIC_*`, etc.). Prefer `PATCHSTACK_API_KEY` in production; `.patchstackrc.json` is fine for local DX. Opt out of reporting with `PATCHSTACK_TELEMETRY=off`. If the project must not carry the widget, persist `"widget": false` in `.patchstackrc.json`; otherwise the next scan re-adds it.
77
77
 
78
78
  4. **Install and verify runtime protection:**
79
79
 
@@ -120,7 +120,7 @@ Remove only the pieces that are actually present — check for each first. If no
120
120
  3. **Remove runtime protection before uninstalling the package.** Delete the connector-managed guard/rules files and remove only their managed imports, middleware registrations, tunnel code, and `#region patchstack…` blocks from the framework/server files. Preserve unrelated middleware and application code. Run `rg "patchstack|x-ps-target"` (or the available equivalent) afterwards and inspect every remaining source hit.
121
121
  4. **Remove the hooks from `package.json` scripts.** If a hook was chained (e.g. `"postbuild": "existing-command && patchstack-connect mark-build"`), remove only the `patchstack-connect …` part and keep the rest; if removal leaves a script empty, delete the key.
122
122
  5. **Uninstall the package** with the manager matching the lockfile: `npm uninstall` / `pnpm remove` / `yarn remove` / `bun remove` `@patchstack/connect`. Don't hand-edit `node_modules` or the lockfile.
123
- 6. **Delete `.patchstackrc.json`** and remove `PATCHSTACK_SITE_UUID` (and public-prefixed variants like `NEXT_PUBLIC_PATCHSTACK_SITE_UUID`) from env files and CI variables.
123
+ 6. **Delete `.patchstackrc.json`** and remove `PATCHSTACK_SITE_UUID`, `PATCHSTACK_API_KEY` (and public-prefixed variants like `NEXT_PUBLIC_PATCHSTACK_SITE_UUID`) from env files and CI variables.
124
124
  7. **Commit** the changes. Reporting stops immediately. The `window.__PATCHSTACK_PROD__` flag that `mark-build` injected lives only in build output, never in source — the next build simply won't contain it (rebuild if build output is committed).
125
125
 
126
126
  Local removal does not delete the site record on Patchstack's side. An unclaimed site is an anonymous record that stops receiving reports; a claimed site is removed by the user in their dashboard at https://app.patchstack.com. There is no CLI command for account-side deletion — do not invent one, and never attempt to authenticate or remove the site on the user's behalf.
package/dist/cli.js CHANGED
@@ -1272,8 +1272,10 @@ async function resolveConfig(options) {
1272
1272
  "CONFIG_MISSING"
1273
1273
  );
1274
1274
  }
1275
+ const apiKeyRaw = fromEnv.apiKey ?? fromFile.apiKey ?? null;
1275
1276
  return {
1276
1277
  siteUuid: siteUuid === null || siteUuid.length === 0 ? null : siteUuid,
1278
+ apiKey: apiKeyRaw === null || apiKeyRaw.length === 0 ? null : apiKeyRaw,
1277
1279
  endpoint,
1278
1280
  timeoutMs,
1279
1281
  environment,
@@ -1290,6 +1292,10 @@ async function persistSiteUuid(cwd, siteUuid) {
1290
1292
  const existing = await readConfigFile(cwd);
1291
1293
  return writeConfigFile(cwd, { ...existing, siteUuid });
1292
1294
  }
1295
+ async function persistApiKey(cwd, apiKey) {
1296
+ const existing = await readConfigFile(cwd);
1297
+ return writeConfigFile(cwd, { ...existing, apiKey });
1298
+ }
1293
1299
  async function readConfigFile(cwd) {
1294
1300
  const target = path6.join(cwd, CONFIG_FILENAME);
1295
1301
  let raw;
@@ -1331,6 +1337,7 @@ function readEnv() {
1331
1337
  const environmentRaw = process.env.PATCHSTACK_ENVIRONMENT;
1332
1338
  return {
1333
1339
  siteUuid: process.env.PATCHSTACK_SITE_UUID ?? void 0,
1340
+ apiKey: process.env.PATCHSTACK_API_KEY ?? void 0,
1334
1341
  endpoint: process.env.PATCHSTACK_ENDPOINT ?? void 0,
1335
1342
  timeoutMs,
1336
1343
  environment: environmentRaw !== void 0 && environmentRaw.length > 0 ? environmentRaw : void 0
@@ -2926,6 +2933,9 @@ Options (for demo and demo-guide):
2926
2933
 
2927
2934
  Environment:
2928
2935
  PATCHSTACK_SITE_UUID Site UUID
2936
+ PATCHSTACK_API_KEY WP-format site API key for block-log reporting (never put in the widget)
2937
+ PATCHSTACK_TELEMETRY Set to off to disable block-log reporting
2938
+ PATCHSTACK_API_BASE API origin for /oauth/token and /api/logs/log (default: https://api.patchstack.com)
2929
2939
  PATCHSTACK_ENDPOINT API endpoint (default: https://api.patchstack.com/monitor/pulse/manifest)
2930
2940
  PATCHSTACK_TIMEOUT_MS Request timeout in ms (default: 30000)
2931
2941
  PATCHSTACK_ENVIRONMENT Manifest environment: production | sandbox (default: production)
@@ -3049,6 +3059,10 @@ async function runScan(args, options = {}) {
3049
3059
  const target = await persistSiteUuid(process.cwd(), response.uuid);
3050
3060
  console.log(`Provisioned site ${response.uuid}. Saved UUID to ${target}.`);
3051
3061
  }
3062
+ if (typeof response.api_key === "string" && response.api_key.length > 0) {
3063
+ const target = await persistApiKey(process.cwd(), response.api_key);
3064
+ console.log(`Saved API key to ${target} (for block-log reporting via /api/logs/log; keep out of the public widget).`);
3065
+ }
3052
3066
  if (response.stored) {
3053
3067
  console.log(`Stored manifest #${response.manifest_id} (checksum ${response.checksum}).`);
3054
3068
  } else if (response.reason === "duplicate") {