@patchstack/connect 0.3.29 → 0.3.31
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 +42 -23
- package/README.md +40 -11
- package/dist/{chunk-MJOTFUDE.js → chunk-LLKP5EJS.js} +1 -1
- package/dist/chunk-LLKP5EJS.js.map +1 -0
- package/dist/cli.js +1265 -287
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +456 -111
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -10
- package/dist/index.d.ts +76 -10
- package/dist/index.js +449 -104
- package/dist/index.js.map +1 -1
- package/dist/protect/templates/astro-middleware.ts +33 -13
- package/dist/protect/templates/demo-rules.json +2 -3
- package/dist/protect/templates/express-guard.cjs +26 -15
- package/dist/protect/templates/express-guard.js +26 -15
- package/dist/protect/templates/express-guard.ts +33 -16
- package/dist/protect/templates/fastify-plugin.cjs +33 -11
- package/dist/protect/templates/fastify-plugin.js +33 -11
- package/dist/protect/templates/fastify-plugin.ts +40 -12
- package/dist/protect/templates/generic-guard.cjs +28 -12
- package/dist/protect/templates/generic-guard.js +28 -13
- package/dist/protect/templates/generic-guard.ts +41 -20
- package/dist/protect/templates/guard.ts +47 -27
- package/dist/protect/templates/next-middleware.ts +29 -12
- package/dist/protect/templates/nuxt-middleware.ts +29 -12
- package/dist/protect/templates/rules.json +2 -2
- package/dist/protect/templates/sveltekit-hooks.ts +33 -13
- package/dist/protect.cjs +1204 -252
- package/dist/protect.cjs.map +1 -1
- package/dist/protect.d.ts +39 -11
- package/dist/protect.edge.js +792 -143
- package/dist/protect.edge.js.map +4 -4
- package/dist/protect.js +794 -145
- package/dist/protect.js.map +1 -1
- package/dist/{refresh-manifest-VRBE6RH6.js → refresh-manifest-KNZQBC4V.js} +387 -100
- package/dist/refresh-manifest-KNZQBC4V.js.map +1 -0
- package/package.json +5 -2
- package/dist/chunk-MJOTFUDE.js.map +0 -1
- 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
|
-
/**
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
34
|
-
|
|
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`
|
|
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
|
|
59
|
-
* `PATCHSTACK_PULSE_AUTH`, then `.patchstackrc.json`
|
|
60
|
-
*
|
|
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. */
|