@patchstack/connect 0.5.12 → 0.5.15

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.
@@ -69,6 +69,19 @@ export interface Protection {
69
69
  stop: () => Promise<void>;
70
70
  /** Alias of `stop`, under the name callers already have. */
71
71
  stopRefresh: () => Promise<void>;
72
+ /**
73
+ * Where the rules in force came from, and whether the most recent resolution was clean — the same
74
+ * shape `refresh()` resolves with, kept current by boot, every refresh, and recovery.
75
+ *
76
+ * With a live source, `ok: false` means the guard is not running the rules the source would give it
77
+ * now: `origin` says what it is running instead. When no `refreshMs` loop is configured and the first
78
+ * resolution was not clean, the guard retries on a lengthening schedule until one is.
79
+ */
80
+ readonly ruleSource: {
81
+ ok: boolean;
82
+ origin: "api" | "cache" | "bundled" | "empty";
83
+ reason?: string;
84
+ };
72
85
  /** Whether this guard reports security events, and if not, why not.
73
86
  *
74
87
  * Reporting is on for a site enrolled in Patchstack-managed mitigation that is running managed rules
@@ -244,7 +257,13 @@ export interface CreateProtectionOptions {
244
257
  reportManifest?: boolean;
245
258
  /** Directory the manifest re-scan reads the lockfile from during a refresh. Default process.cwd(). */
246
259
  cwd?: string;
247
- /** Directory for the last-known-good rule cache (disk — the default cache backend). */
260
+ /**
261
+ * Directory for the last-known-good rule cache (disk — the default cache backend).
262
+ *
263
+ * A cache belongs to the source it was fetched for: the site UUID or token, and the rules endpoint.
264
+ * One written for any other source — or by a version that did not record its source — reads as
265
+ * empty, so it is never enforced, revalidated or used to attribute detections for this guard.
266
+ */
248
267
  cacheDir?: string;
249
268
  /**
250
269
  * Pluggable last-known-good cache, for runtimes without a filesystem (Workers/Deno). Overrides
@@ -329,6 +348,11 @@ export interface CreateProtectionOptions {
329
348
  screenDns?: boolean;
330
349
  /** Redaction mask (string or per-category function). Default "[REDACTED]". */
331
350
  maskWith?: string | ((category?: string) => string);
351
+ /**
352
+ * Operational problems the guard handled without failing a request. Without it, rules that are not
353
+ * current — a failed fetch, a rejected update, held build-scoped rules — are written to the console
354
+ * once per cause instead.
355
+ */
332
356
  onError?: (err: unknown) => void;
333
357
  onEgressBlock?: (info: { url: string; host: string | null; method: string }) => void;
334
358
  onDetect?: (detection: {
package/dist/protect.d.ts CHANGED
@@ -69,6 +69,19 @@ export interface Protection {
69
69
  stop: () => Promise<void>;
70
70
  /** Alias of `stop`, under the name callers already have. */
71
71
  stopRefresh: () => Promise<void>;
72
+ /**
73
+ * Where the rules in force came from, and whether the most recent resolution was clean — the same
74
+ * shape `refresh()` resolves with, kept current by boot, every refresh, and recovery.
75
+ *
76
+ * With a live source, `ok: false` means the guard is not running the rules the source would give it
77
+ * now: `origin` says what it is running instead. When no `refreshMs` loop is configured and the first
78
+ * resolution was not clean, the guard retries on a lengthening schedule until one is.
79
+ */
80
+ readonly ruleSource: {
81
+ ok: boolean;
82
+ origin: "api" | "cache" | "bundled" | "empty";
83
+ reason?: string;
84
+ };
72
85
  /** Whether this guard reports security events, and if not, why not.
73
86
  *
74
87
  * Reporting is on for a site enrolled in Patchstack-managed mitigation that is running managed rules
@@ -244,7 +257,13 @@ export interface CreateProtectionOptions {
244
257
  reportManifest?: boolean;
245
258
  /** Directory the manifest re-scan reads the lockfile from during a refresh. Default process.cwd(). */
246
259
  cwd?: string;
247
- /** Directory for the last-known-good rule cache (disk — the default cache backend). */
260
+ /**
261
+ * Directory for the last-known-good rule cache (disk — the default cache backend).
262
+ *
263
+ * A cache belongs to the source it was fetched for: the site UUID or token, and the rules endpoint.
264
+ * One written for any other source — or by a version that did not record its source — reads as
265
+ * empty, so it is never enforced, revalidated or used to attribute detections for this guard.
266
+ */
248
267
  cacheDir?: string;
249
268
  /**
250
269
  * Pluggable last-known-good cache, for runtimes without a filesystem (Workers/Deno). Overrides
@@ -329,6 +348,11 @@ export interface CreateProtectionOptions {
329
348
  screenDns?: boolean;
330
349
  /** Redaction mask (string or per-category function). Default "[REDACTED]". */
331
350
  maskWith?: string | ((category?: string) => string);
351
+ /**
352
+ * Operational problems the guard handled without failing a request. Without it, rules that are not
353
+ * current — a failed fetch, a rejected update, held build-scoped rules — are written to the console
354
+ * once per cause instead.
355
+ */
332
356
  onError?: (err: unknown) => void;
333
357
  onEgressBlock?: (info: { url: string; host: string | null; method: string }) => void;
334
358
  onDetect?: (detection: {