@patchstack/connect 0.3.28 → 0.3.30

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.
Files changed (40) hide show
  1. package/AGENT-INSTALL.md +37 -21
  2. package/README.md +24 -10
  3. package/dist/{chunk-MJOTFUDE.js → chunk-LLKP5EJS.js} +1 -1
  4. package/dist/chunk-LLKP5EJS.js.map +1 -0
  5. package/dist/cli.js +1267 -224
  6. package/dist/cli.js.map +1 -1
  7. package/dist/index.cjs +419 -104
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +28 -9
  10. package/dist/index.d.ts +28 -9
  11. package/dist/index.js +412 -97
  12. package/dist/index.js.map +1 -1
  13. package/dist/protect/templates/astro-middleware.ts +33 -13
  14. package/dist/protect/templates/demo-rules.json +2 -3
  15. package/dist/protect/templates/express-guard.cjs +26 -15
  16. package/dist/protect/templates/express-guard.js +26 -15
  17. package/dist/protect/templates/express-guard.ts +33 -16
  18. package/dist/protect/templates/fastify-plugin.cjs +33 -11
  19. package/dist/protect/templates/fastify-plugin.js +33 -11
  20. package/dist/protect/templates/fastify-plugin.ts +40 -12
  21. package/dist/protect/templates/generic-guard.cjs +28 -12
  22. package/dist/protect/templates/generic-guard.js +28 -13
  23. package/dist/protect/templates/generic-guard.ts +41 -20
  24. package/dist/protect/templates/guard.ts +47 -27
  25. package/dist/protect/templates/next-middleware.ts +29 -12
  26. package/dist/protect/templates/nuxt-middleware.ts +29 -12
  27. package/dist/protect/templates/rules.json +2 -2
  28. package/dist/protect/templates/sveltekit-hooks.ts +33 -13
  29. package/dist/protect.cjs +1039 -235
  30. package/dist/protect.cjs.map +1 -1
  31. package/dist/protect.d.ts +39 -11
  32. package/dist/protect.edge.js +663 -132
  33. package/dist/protect.edge.js.map +4 -4
  34. package/dist/protect.js +665 -134
  35. package/dist/protect.js.map +1 -1
  36. package/dist/{refresh-manifest-VRBE6RH6.js → refresh-manifest-ZSP76JWQ.js} +351 -94
  37. package/dist/refresh-manifest-ZSP76JWQ.js.map +1 -0
  38. package/package.json +5 -2
  39. package/dist/chunk-MJOTFUDE.js.map +0 -1
  40. package/dist/refresh-manifest-VRBE6RH6.js.map +0 -1
package/dist/protect.d.ts CHANGED
@@ -19,19 +19,43 @@ export interface Protection {
19
19
  fetchGuard(): (request: Request) => Promise<Response | null>;
20
20
  /** Screens the request, then the response (secret-leak redaction / withhold). */
21
21
  fetch(handler: (request: Request, ...rest: unknown[]) => unknown): (request: Request, ...rest: unknown[]) => Promise<unknown>;
22
- /** Screen a fetch Response through the response-phase rules (redact/withhold). */
23
- screenResponse(response: Response): Promise<Response>;
22
+ /**
23
+ * Screen a fetch Response through the response-phase rules (redact/withhold/encode).
24
+ *
25
+ * Pass the originating `request` wherever it is available. A response rule can be scoped to a route or a
26
+ * method (`when`), and that scope can only be applied if the engine is given the request the response
27
+ * belongs to — without it, a scoped response rule is delivered, counted as protection, and never matches.
28
+ */
29
+ screenResponse(response: Response, request?: Request): Promise<Response>;
24
30
  express(options?: { screenResponses?: boolean }): (req: unknown, res: unknown, next: () => void) => void;
25
31
  node(options?: { maxBodyBytes?: number; screenResponses?: boolean }): (req: unknown, res: unknown, next: () => void) => void;
26
32
  /** Present when `egress: true` — restores the original global fetch. */
27
33
  uninstallEgress?: () => void;
28
- /** Present with a live source — re-fetch + hot-swap the rules once (used by the loop + push). */
29
- refresh?: () => Promise<void>;
34
+ /** Present with a live source — re-fetch + hot-swap the rules once (used by the loop + push).
35
+ * Resolves with the outcome of the attempt: `ok: false` means the rules in force came from the
36
+ * cache or the bundled fallback, not from the source. It does not reject on a source failure. */
37
+ refresh?: () => Promise<{ ok: boolean; reason?: string }>;
30
38
  /** Present with a live source — a fetch handler that runs `refresh()` when the request carries
31
39
  * the configured refresh secret (a push/zero-day trigger). No secret set → the handler 404s. */
32
40
  refreshHandler?: () => (request: Request) => Promise<Response>;
33
- /** Present when `refreshMs > 0` — stops the live rule-refresh loop. */
34
- stopRefresh?: () => void;
41
+ /** Stops everything with a timer or a buffer behind it: the refresh loop, the block log, the
42
+ * detection reporter (flushing what it holds). Always present, and safe to call twice. */
43
+ stop: () => void;
44
+ /** Alias of `stop`, under the name callers already have. */
45
+ stopRefresh: () => void;
46
+ /** Whether detection reporting is running, requested but undeliverable, or not requested.
47
+ * `unavailable-no-credential` means `reportDetections` was set but no credential resolved, so
48
+ * nothing is being sent. */
49
+ detectionReporting: "on" | "off" | "unavailable-no-credential";
50
+ /** Present when detection reporting is on — delivery counts (in events) and the last acknowledgement.
51
+ * Carries no request data. */
52
+ detectionHealth?: () => {
53
+ sent: number;
54
+ delivered: number;
55
+ failed: number;
56
+ dropped: number;
57
+ lastDeliveredAt: string | null;
58
+ };
35
59
  }
36
60
 
37
61
  export interface CreateProtectionOptions {
@@ -51,14 +75,16 @@ export interface CreateProtectionOptions {
51
75
  /**
52
76
  * WP-format site API key (`{secret}-{oauth.id}`) for authenticated block logs
53
77
  * via connector `POST /api/logs/log`. Falls back to `PATCHSTACK_API_KEY`, then
54
- * `.patchstackrc.json` `apiKey`. Never put this in the public widget.
78
+ * `apiKey` in `.patchstackrc.local.json` (where setup writes it) and then in
79
+ * `.patchstackrc.json` (where installs that predate the split still hold it).
80
+ * Never put this in the public widget.
55
81
  */
56
82
  apiKey?: string;
57
83
  /**
58
- * Credential for the authenticated rules lookup. Falls back to `apiKey`, then
59
- * `PATCHSTACK_PULSE_AUTH`, then `.patchstackrc.json` `pulseAuth`. Exchanged
60
- * for a short-lived token; never sent directly. Never put this in the public
61
- * widget.
84
+ * Credential for the authenticated rules lookup. Falls back to
85
+ * `PATCHSTACK_PULSE_AUTH`, then `pulseAuth` in `.patchstackrc.local.json` and
86
+ * then in `.patchstackrc.json`, then to `apiKey`. Exchanged for a short-lived
87
+ * token; never sent directly. Never put this in the public widget.
62
88
  */
63
89
  pulseAuth?: string;
64
90
  /** Override the Pulse rules API base URL. */
@@ -81,6 +107,8 @@ export interface CreateProtectionOptions {
81
107
  * this is a counting channel, not a copy of your traffic.
82
108
  *
83
109
  * Off by default because switching it on adds an outbound request to every guard with a site UUID.
110
+ * Needs a resolvable API credential: the endpoint requires a verified, site-bound token, so with no
111
+ * credential no reporter is created and `detectionReporting` reads `unavailable-no-credential`.
84
112
  */
85
113
  reportDetections?: boolean;
86
114
  /** How long to buffer detections before posting a batch. Default 5000ms. */