@domandigital/sentry 0.1.2 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @domandigital/sentry
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1c341f5: Adds critical-path reporting. `criticalReporter(captureException)` returns `criticalFailure(path, stage, error, extra?)`, which reports a failure at a checkout, booking or enquiry step at level `fatal` with the tags `critical_path` and `critical_stage`, grouped by path and stage, and never throws. `watchCriticalCsp(document, reporter)` reports a CSP block only while the visitor is on a step marked with `enter()`, once per directive and origin, with the blocked URL cut to its origin. `criticalContext()` builds the same event for a site with its own capture wrapper. Exported from the root, `/browser` and `/cloudflare`.
8
+
9
+ ## 0.1.3
10
+
11
+ ### Patch Changes
12
+
13
+ - e4db92a: The README examples, code comments and changelog entries no longer name clients. They describe the site instead, for example "a client electrician site". No runtime behaviour changes.
14
+ - Updated dependencies [e4db92a]
15
+ - @domandigital/synthetic@0.2.2
16
+
3
17
  ## 0.1.2
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -166,9 +166,44 @@ made only of third-party frames is dropped. Use the same project slug in both.
166
166
  `onRequestError` and `captureGlobalError` load the site's own `@sentry/nextjs`
167
167
  when they run.
168
168
 
169
+ ## Critical paths: checkout, booking, enquiries
170
+
171
+ A failure where a customer pays or leaves their details is reported at level
172
+ `fatal` with two tags, `critical_path` (`checkout`, `booking`, `enquiry`) and
173
+ `critical_stage` (`card-load`, `tokenize`, `confirm`, `csp`). Each Sentry
174
+ project has one alert that fires on every event carrying `critical_path`,
175
+ emails, and posts to the relay, which pages the founder. The alert is created
176
+ from the site's `critical:` row in the estate registry, so nothing here
177
+ creates it.
178
+
179
+ ```ts
180
+ import * as Sentry from "@sentry/browser";
181
+ import { criticalReporter, watchCriticalCsp } from "@domandigital/sentry/browser";
182
+
183
+ const critical = criticalReporter(Sentry.captureException);
184
+ watchCriticalCsp(document, critical); // CSP blocks count only while a step is marked
185
+
186
+ critical.enter("checkout", "card"); // the card form is open
187
+ try {
188
+ await card.tokenize();
189
+ } catch (error) {
190
+ critical.criticalFailure("checkout", "tokenize", error, { status });
191
+ }
192
+ critical.leave();
193
+ ```
194
+
195
+ The same import works on a Worker (`@domandigital/sentry/cloudflare`), handing
196
+ it `Sentry.captureException` from `@sentry/cloudflare`. A site that loads
197
+ Sentry lazily can build the event itself with `criticalContext(path, stage,
198
+ extra)`. Names are lower case letters, digits and hyphens. A report never
199
+ throws, so a broken SDK cannot break the checkout it is describing. Events are
200
+ grouped by path and stage, which is why the alert fires on every event rather
201
+ than only on a new issue: the second customer to hit the same failure matters
202
+ as much as the first.
203
+
169
204
  ## Release and source maps for Worker and Astro builds: `dd-sentry-release`
170
205
 
171
- The step from RMP-Electrical's `deploy-astro.yml`, as one command in two
206
+ The step from a client Astro site's `deploy-astro.yml`, as one command in two
172
207
  halves. The maps go up and are deleted **before** the deploy, and the deploy
173
208
  record is written **after** it:
174
209
 
package/dist/browser.cjs CHANGED
@@ -21,8 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var browser_exports = {};
22
22
  __export(browser_exports, {
23
23
  BROWSER_TRACES_SAMPLE_RATE: () => BROWSER_TRACES_SAMPLE_RATE,
24
+ CRITICAL_PATH_TAG: () => CRITICAL_PATH_TAG,
25
+ CRITICAL_STAGE_TAG: () => CRITICAL_STAGE_TAG,
26
+ blockedOrigin: () => blockedOrigin,
24
27
  browserOptions: () => browserOptions,
25
- thirdPartyFilterOptions: () => thirdPartyFilterOptions
28
+ criticalContext: () => criticalContext,
29
+ criticalReporter: () => criticalReporter,
30
+ thirdPartyFilterOptions: () => thirdPartyFilterOptions,
31
+ watchCriticalCsp: () => watchCriticalCsp
26
32
  });
27
33
  module.exports = __toCommonJS(browser_exports);
28
34
 
@@ -352,6 +358,75 @@ function thirdPartyFilterOptions(project) {
352
358
  };
353
359
  }
354
360
 
361
+ // src/critical.ts
362
+ var CRITICAL_PATH_TAG = "critical_path";
363
+ var CRITICAL_STAGE_TAG = "critical_stage";
364
+ var NAME = /^[a-z][a-z0-9-]{0,39}$/;
365
+ function checkName(kind, value) {
366
+ if (!NAME.test(value)) throw new TypeError(`${kind} must be lower case letters, digits and hyphens (got ${JSON.stringify(value)})`);
367
+ return value;
368
+ }
369
+ function criticalContext(path, stage, extra = {}) {
370
+ checkName("path", path);
371
+ checkName("stage", stage);
372
+ return {
373
+ level: "fatal",
374
+ tags: { [CRITICAL_PATH_TAG]: path, [CRITICAL_STAGE_TAG]: stage },
375
+ fingerprint: ["critical", path, stage],
376
+ extra: { ...extra, critical_path: path, critical_stage: stage }
377
+ };
378
+ }
379
+ function criticalReporter(capture) {
380
+ let at = null;
381
+ return {
382
+ criticalFailure(path, stage, error, extra = {}) {
383
+ try {
384
+ const err = error instanceof Error ? error : new Error(`${path} failed at ${stage}: ${String(error)}`);
385
+ capture(err, criticalContext(path, stage, extra));
386
+ } catch {
387
+ }
388
+ },
389
+ enter(path, stage) {
390
+ at = { path: checkName("path", path), stage: checkName("stage", stage) };
391
+ },
392
+ leave() {
393
+ at = null;
394
+ },
395
+ current: () => at
396
+ };
397
+ }
398
+ function blockedOrigin(uri) {
399
+ if (!uri) return "unknown";
400
+ try {
401
+ const u = new URL(uri);
402
+ return u.origin === "null" ? u.protocol.replace(/:$/, "") : u.origin;
403
+ } catch {
404
+ return uri.split(/[/?#]/)[0] || "unknown";
405
+ }
406
+ }
407
+ function watchCriticalCsp(target, reporter, options = {}) {
408
+ const ignore = new Set(options.ignoreDirectives ?? []);
409
+ const seen = /* @__PURE__ */ new Set();
410
+ const listener = (event) => {
411
+ const at = reporter.current();
412
+ if (!at || event.disposition === "report") return;
413
+ if (ignore.has(event.effectiveDirective)) return;
414
+ const blocked = blockedOrigin(event.blockedURI);
415
+ const key = `${event.effectiveDirective} ${blocked}`;
416
+ if (seen.has(key)) return;
417
+ seen.add(key);
418
+ reporter.criticalFailure(at.path, "csp", new Error(`CSP blocked ${key} during ${at.stage}`), {
419
+ directive: event.effectiveDirective,
420
+ blocked,
421
+ source: blockedOrigin(event.sourceFile),
422
+ during: at.stage
423
+ });
424
+ options.onBlocked?.(event, at);
425
+ };
426
+ target.addEventListener("securitypolicyviolation", listener);
427
+ return () => target.removeEventListener("securitypolicyviolation", listener);
428
+ }
429
+
355
430
  // src/browser.ts
356
431
  var BROWSER_TRACES_SAMPLE_RATE = 0.05;
357
432
  function browserOptions(input = {}) {
@@ -360,6 +435,12 @@ function browserOptions(input = {}) {
360
435
  // Annotate the CommonJS export names for ESM import in node:
361
436
  0 && (module.exports = {
362
437
  BROWSER_TRACES_SAMPLE_RATE,
438
+ CRITICAL_PATH_TAG,
439
+ CRITICAL_STAGE_TAG,
440
+ blockedOrigin,
363
441
  browserOptions,
364
- thirdPartyFilterOptions
442
+ criticalContext,
443
+ criticalReporter,
444
+ thirdPartyFilterOptions,
445
+ watchCriticalCsp
365
446
  });
@@ -1,6 +1,7 @@
1
1
  import { P as PresetInput, B as BrowserPreset } from './preset-D2peo0uv.cjs';
2
2
  export { a as BrowserPresetDefaults, S as ScrubbingHook, b as SpanScrubbingHook } from './preset-D2peo0uv.cjs';
3
3
  export { t as thirdPartyFilterOptions } from './third-party-LjX9unFo.cjs';
4
+ export { C as CRITICAL_PATH_TAG, a as CRITICAL_STAGE_TAG, b as CaptureException, c as CriticalCaptureContext, d as CriticalReporter, e as CspViolation, V as ViolationTarget, W as WatchCspOptions, f as blockedOrigin, g as criticalContext, h as criticalReporter, w as watchCriticalCsp } from './critical-jznjvmAW.cjs';
4
5
 
5
6
  /**
6
7
  * Browser init options: plain sites, Astro's client (`@sentry/astro` or
package/dist/browser.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { P as PresetInput, B as BrowserPreset } from './preset-D2peo0uv.js';
2
2
  export { a as BrowserPresetDefaults, S as ScrubbingHook, b as SpanScrubbingHook } from './preset-D2peo0uv.js';
3
3
  export { t as thirdPartyFilterOptions } from './third-party-LjX9unFo.js';
4
+ export { C as CRITICAL_PATH_TAG, a as CRITICAL_STAGE_TAG, b as CaptureException, c as CriticalCaptureContext, d as CriticalReporter, e as CspViolation, V as ViolationTarget, W as WatchCspOptions, f as blockedOrigin, g as criticalContext, h as criticalReporter, w as watchCriticalCsp } from './critical-jznjvmAW.js';
4
5
 
5
6
  /**
6
7
  * Browser init options: plain sites, Astro's client (`@sentry/astro` or
package/dist/browser.js CHANGED
@@ -1,13 +1,26 @@
1
1
  import {
2
2
  BROWSER_TRACES_SAMPLE_RATE,
3
3
  browserOptions
4
- } from "./chunk-6BR5I252.js";
4
+ } from "./chunk-2IWK7LEE.js";
5
5
  import {
6
6
  thirdPartyFilterOptions
7
7
  } from "./chunk-TD2AK75E.js";
8
- import "./chunk-BICH2PO4.js";
8
+ import {
9
+ CRITICAL_PATH_TAG,
10
+ CRITICAL_STAGE_TAG,
11
+ blockedOrigin,
12
+ criticalContext,
13
+ criticalReporter,
14
+ watchCriticalCsp
15
+ } from "./chunk-EHOMV2ZB.js";
9
16
  export {
10
17
  BROWSER_TRACES_SAMPLE_RATE,
18
+ CRITICAL_PATH_TAG,
19
+ CRITICAL_STAGE_TAG,
20
+ blockedOrigin,
11
21
  browserOptions,
12
- thirdPartyFilterOptions
22
+ criticalContext,
23
+ criticalReporter,
24
+ thirdPartyFilterOptions,
25
+ watchCriticalCsp
13
26
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildPreset
3
- } from "./chunk-BICH2PO4.js";
3
+ } from "./chunk-EHOMV2ZB.js";
4
4
 
5
5
  // src/browser.ts
6
6
  var BROWSER_TRACES_SAMPLE_RATE = 0.05;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildPreset
3
- } from "./chunk-BICH2PO4.js";
3
+ } from "./chunk-EHOMV2ZB.js";
4
4
 
5
5
  // src/cloudflare.ts
6
6
  var SERVER_TRACES_SAMPLE_RATE = 0.1;
@@ -315,6 +315,75 @@ function buildPreset(input, runtime) {
315
315
  return out;
316
316
  }
317
317
 
318
+ // src/critical.ts
319
+ var CRITICAL_PATH_TAG = "critical_path";
320
+ var CRITICAL_STAGE_TAG = "critical_stage";
321
+ var NAME = /^[a-z][a-z0-9-]{0,39}$/;
322
+ function checkName(kind, value) {
323
+ if (!NAME.test(value)) throw new TypeError(`${kind} must be lower case letters, digits and hyphens (got ${JSON.stringify(value)})`);
324
+ return value;
325
+ }
326
+ function criticalContext(path, stage, extra = {}) {
327
+ checkName("path", path);
328
+ checkName("stage", stage);
329
+ return {
330
+ level: "fatal",
331
+ tags: { [CRITICAL_PATH_TAG]: path, [CRITICAL_STAGE_TAG]: stage },
332
+ fingerprint: ["critical", path, stage],
333
+ extra: { ...extra, critical_path: path, critical_stage: stage }
334
+ };
335
+ }
336
+ function criticalReporter(capture) {
337
+ let at = null;
338
+ return {
339
+ criticalFailure(path, stage, error, extra = {}) {
340
+ try {
341
+ const err = error instanceof Error ? error : new Error(`${path} failed at ${stage}: ${String(error)}`);
342
+ capture(err, criticalContext(path, stage, extra));
343
+ } catch {
344
+ }
345
+ },
346
+ enter(path, stage) {
347
+ at = { path: checkName("path", path), stage: checkName("stage", stage) };
348
+ },
349
+ leave() {
350
+ at = null;
351
+ },
352
+ current: () => at
353
+ };
354
+ }
355
+ function blockedOrigin(uri) {
356
+ if (!uri) return "unknown";
357
+ try {
358
+ const u = new URL(uri);
359
+ return u.origin === "null" ? u.protocol.replace(/:$/, "") : u.origin;
360
+ } catch {
361
+ return uri.split(/[/?#]/)[0] || "unknown";
362
+ }
363
+ }
364
+ function watchCriticalCsp(target, reporter, options = {}) {
365
+ const ignore = new Set(options.ignoreDirectives ?? []);
366
+ const seen = /* @__PURE__ */ new Set();
367
+ const listener = (event) => {
368
+ const at = reporter.current();
369
+ if (!at || event.disposition === "report") return;
370
+ if (ignore.has(event.effectiveDirective)) return;
371
+ const blocked = blockedOrigin(event.blockedURI);
372
+ const key = `${event.effectiveDirective} ${blocked}`;
373
+ if (seen.has(key)) return;
374
+ seen.add(key);
375
+ reporter.criticalFailure(at.path, "csp", new Error(`CSP blocked ${key} during ${at.stage}`), {
376
+ directive: event.effectiveDirective,
377
+ blocked,
378
+ source: blockedOrigin(event.sourceFile),
379
+ during: at.stage
380
+ });
381
+ options.onBlocked?.(event, at);
382
+ };
383
+ target.addEventListener("securitypolicyviolation", listener);
384
+ return () => target.removeEventListener("securitypolicyviolation", listener);
385
+ }
386
+
318
387
  export {
319
388
  SENTRY_ORG,
320
389
  INGEST_HOST,
@@ -335,5 +404,11 @@ export {
335
404
  scrubSpan,
336
405
  scrubEvent,
337
406
  DATA_COLLECTION,
338
- buildPreset
407
+ buildPreset,
408
+ CRITICAL_PATH_TAG,
409
+ CRITICAL_STAGE_TAG,
410
+ criticalContext,
411
+ criticalReporter,
412
+ blockedOrigin,
413
+ watchCriticalCsp
339
414
  };
@@ -20,8 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/cloudflare.ts
21
21
  var cloudflare_exports = {};
22
22
  __export(cloudflare_exports, {
23
+ CRITICAL_PATH_TAG: () => CRITICAL_PATH_TAG,
24
+ CRITICAL_STAGE_TAG: () => CRITICAL_STAGE_TAG,
23
25
  SERVER_TRACES_SAMPLE_RATE: () => SERVER_TRACES_SAMPLE_RATE,
24
- cloudflareOptions: () => cloudflareOptions
26
+ blockedOrigin: () => blockedOrigin,
27
+ cloudflareOptions: () => cloudflareOptions,
28
+ criticalContext: () => criticalContext,
29
+ criticalReporter: () => criticalReporter,
30
+ watchCriticalCsp: () => watchCriticalCsp
25
31
  });
26
32
  module.exports = __toCommonJS(cloudflare_exports);
27
33
 
@@ -340,6 +346,75 @@ function buildPreset(input, runtime) {
340
346
  return out;
341
347
  }
342
348
 
349
+ // src/critical.ts
350
+ var CRITICAL_PATH_TAG = "critical_path";
351
+ var CRITICAL_STAGE_TAG = "critical_stage";
352
+ var NAME = /^[a-z][a-z0-9-]{0,39}$/;
353
+ function checkName(kind, value) {
354
+ if (!NAME.test(value)) throw new TypeError(`${kind} must be lower case letters, digits and hyphens (got ${JSON.stringify(value)})`);
355
+ return value;
356
+ }
357
+ function criticalContext(path, stage, extra = {}) {
358
+ checkName("path", path);
359
+ checkName("stage", stage);
360
+ return {
361
+ level: "fatal",
362
+ tags: { [CRITICAL_PATH_TAG]: path, [CRITICAL_STAGE_TAG]: stage },
363
+ fingerprint: ["critical", path, stage],
364
+ extra: { ...extra, critical_path: path, critical_stage: stage }
365
+ };
366
+ }
367
+ function criticalReporter(capture) {
368
+ let at = null;
369
+ return {
370
+ criticalFailure(path, stage, error, extra = {}) {
371
+ try {
372
+ const err = error instanceof Error ? error : new Error(`${path} failed at ${stage}: ${String(error)}`);
373
+ capture(err, criticalContext(path, stage, extra));
374
+ } catch {
375
+ }
376
+ },
377
+ enter(path, stage) {
378
+ at = { path: checkName("path", path), stage: checkName("stage", stage) };
379
+ },
380
+ leave() {
381
+ at = null;
382
+ },
383
+ current: () => at
384
+ };
385
+ }
386
+ function blockedOrigin(uri) {
387
+ if (!uri) return "unknown";
388
+ try {
389
+ const u = new URL(uri);
390
+ return u.origin === "null" ? u.protocol.replace(/:$/, "") : u.origin;
391
+ } catch {
392
+ return uri.split(/[/?#]/)[0] || "unknown";
393
+ }
394
+ }
395
+ function watchCriticalCsp(target, reporter, options = {}) {
396
+ const ignore = new Set(options.ignoreDirectives ?? []);
397
+ const seen = /* @__PURE__ */ new Set();
398
+ const listener = (event) => {
399
+ const at = reporter.current();
400
+ if (!at || event.disposition === "report") return;
401
+ if (ignore.has(event.effectiveDirective)) return;
402
+ const blocked = blockedOrigin(event.blockedURI);
403
+ const key = `${event.effectiveDirective} ${blocked}`;
404
+ if (seen.has(key)) return;
405
+ seen.add(key);
406
+ reporter.criticalFailure(at.path, "csp", new Error(`CSP blocked ${key} during ${at.stage}`), {
407
+ directive: event.effectiveDirective,
408
+ blocked,
409
+ source: blockedOrigin(event.sourceFile),
410
+ during: at.stage
411
+ });
412
+ options.onBlocked?.(event, at);
413
+ };
414
+ target.addEventListener("securitypolicyviolation", listener);
415
+ return () => target.removeEventListener("securitypolicyviolation", listener);
416
+ }
417
+
343
418
  // src/cloudflare.ts
344
419
  var SERVER_TRACES_SAMPLE_RATE = 0.1;
345
420
  function cloudflareOptions(input = {}) {
@@ -347,6 +422,12 @@ function cloudflareOptions(input = {}) {
347
422
  }
348
423
  // Annotate the CommonJS export names for ESM import in node:
349
424
  0 && (module.exports = {
425
+ CRITICAL_PATH_TAG,
426
+ CRITICAL_STAGE_TAG,
350
427
  SERVER_TRACES_SAMPLE_RATE,
351
- cloudflareOptions
428
+ blockedOrigin,
429
+ cloudflareOptions,
430
+ criticalContext,
431
+ criticalReporter,
432
+ watchCriticalCsp
352
433
  });
@@ -1,5 +1,6 @@
1
1
  import { P as PresetInput, c as Preset } from './preset-D2peo0uv.cjs';
2
2
  export { d as PresetDefaults, S as ScrubbingHook, b as SpanScrubbingHook } from './preset-D2peo0uv.cjs';
3
+ export { C as CRITICAL_PATH_TAG, a as CRITICAL_STAGE_TAG, b as CaptureException, c as CriticalCaptureContext, d as CriticalReporter, e as CspViolation, V as ViolationTarget, W as WatchCspOptions, f as blockedOrigin, g as criticalContext, h as criticalReporter, w as watchCriticalCsp } from './critical-jznjvmAW.cjs';
3
4
 
4
5
  /**
5
6
  * Cloudflare Worker init options, for `@sentry/cloudflare`'s `withSentry`
@@ -1,5 +1,6 @@
1
1
  import { P as PresetInput, c as Preset } from './preset-D2peo0uv.js';
2
2
  export { d as PresetDefaults, S as ScrubbingHook, b as SpanScrubbingHook } from './preset-D2peo0uv.js';
3
+ export { C as CRITICAL_PATH_TAG, a as CRITICAL_STAGE_TAG, b as CaptureException, c as CriticalCaptureContext, d as CriticalReporter, e as CspViolation, V as ViolationTarget, W as WatchCspOptions, f as blockedOrigin, g as criticalContext, h as criticalReporter, w as watchCriticalCsp } from './critical-jznjvmAW.js';
3
4
 
4
5
  /**
5
6
  * Cloudflare Worker init options, for `@sentry/cloudflare`'s `withSentry`
@@ -1,9 +1,22 @@
1
1
  import {
2
2
  SERVER_TRACES_SAMPLE_RATE,
3
3
  cloudflareOptions
4
- } from "./chunk-ZIWYCDHF.js";
5
- import "./chunk-BICH2PO4.js";
4
+ } from "./chunk-5IXAEGK7.js";
5
+ import {
6
+ CRITICAL_PATH_TAG,
7
+ CRITICAL_STAGE_TAG,
8
+ blockedOrigin,
9
+ criticalContext,
10
+ criticalReporter,
11
+ watchCriticalCsp
12
+ } from "./chunk-EHOMV2ZB.js";
6
13
  export {
14
+ CRITICAL_PATH_TAG,
15
+ CRITICAL_STAGE_TAG,
7
16
  SERVER_TRACES_SAMPLE_RATE,
8
- cloudflareOptions
17
+ blockedOrigin,
18
+ cloudflareOptions,
19
+ criticalContext,
20
+ criticalReporter,
21
+ watchCriticalCsp
9
22
  };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Critical paths: the steps where a failure costs a client money or a lead
3
+ * (checkout, booking, an enquiry form). A failure there is reported at level
4
+ * `fatal` with two tags, and one Sentry alert per project (created from the
5
+ * estate registry's `critical:` row) watches for the tag and pages the
6
+ * founder through the relay. Nothing else in a project carries the tag, so
7
+ * the alert stays quiet until a customer is actually stuck.
8
+ *
9
+ * critical_path which path: `checkout`, `booking`, `enquiry`, ...
10
+ * critical_stage where on it: `card-load`, `tokenize`, `confirm`, `csp`, ...
11
+ *
12
+ * Like the presets, this imports no Sentry SDK: the site hands over its own
13
+ * `captureException`, so v10 and v11 both work and the browser bundle does
14
+ * not gain a second copy of the SDK.
15
+ */
16
+ /** The tag every critical-path alert filters on. Never set it by hand: use {@link criticalReporter}. */
17
+ declare const CRITICAL_PATH_TAG = "critical_path";
18
+ /** The step on the path that failed. */
19
+ declare const CRITICAL_STAGE_TAG = "critical_stage";
20
+ /** What `captureException` receives: the same in `@sentry/browser`, `@sentry/astro`, `@sentry/cloudflare` and `@sentry/nextjs`. */
21
+ interface CriticalCaptureContext {
22
+ level: "fatal";
23
+ tags: Record<string, string>;
24
+ fingerprint: string[];
25
+ extra: Record<string, unknown>;
26
+ }
27
+ /** The site's own `Sentry.captureException`, or anything with that shape. */
28
+ type CaptureException = (error: unknown, context: CriticalCaptureContext) => unknown;
29
+ /**
30
+ * The capture context for one critical failure. Exported so a site with its
31
+ * own wrapper (a lazy-loaded Sentry chunk, a beacon) can send the same event.
32
+ * The fingerprint groups by path and stage, so a hundred card declines are
33
+ * one issue and the alert fires on every event in it, not only the first.
34
+ */
35
+ declare function criticalContext(path: string, stage: string, extra?: Record<string, unknown>): CriticalCaptureContext;
36
+ /** A browser CSP violation, as much of it as this needs. */
37
+ interface CspViolation {
38
+ effectiveDirective: string;
39
+ blockedURI: string;
40
+ sourceFile?: string;
41
+ disposition?: string;
42
+ }
43
+ interface CriticalReporter {
44
+ /** Reports one failure on a critical path. Never throws: a broken report must not break the checkout it describes. */
45
+ criticalFailure(path: string, stage: string, error: unknown, extra?: Record<string, unknown>): void;
46
+ /** Marks the visitor as being on a critical step (the card form is open). CSP blocks are reported only from here on. */
47
+ enter(path: string, stage: string): void;
48
+ /** The visitor has left the critical step (booked, or gone back). */
49
+ leave(): void;
50
+ /** The step the visitor is on, or null. */
51
+ current(): {
52
+ path: string;
53
+ stage: string;
54
+ } | null;
55
+ }
56
+ /** Binds the site's `captureException`. One reporter per page. */
57
+ declare function criticalReporter(capture: CaptureException): CriticalReporter;
58
+ /** Scheme and host of a blocked URI, never its path or query (a bank's 3-D Secure URL carries session ids). */
59
+ declare function blockedOrigin(uri: string | undefined): string;
60
+ /** Anything with `addEventListener`: `document`, or a test double. */
61
+ interface ViolationTarget {
62
+ addEventListener(type: "securitypolicyviolation", listener: (event: CspViolation) => void): void;
63
+ removeEventListener(type: "securitypolicyviolation", listener: (event: CspViolation) => void): void;
64
+ }
65
+ interface WatchCspOptions {
66
+ /** Directives that cannot break this path (an analytics `img-src`, say). Default: none, so every enforced block counts. */
67
+ ignoreDirectives?: readonly string[];
68
+ /** Called after a block is reported: the site's own fallback (send the visitor to the provider's hosted page). */
69
+ onBlocked?: (violation: CspViolation, at: {
70
+ path: string;
71
+ stage: string;
72
+ }) => void;
73
+ }
74
+ /**
75
+ * Reports a CSP block as a critical failure, but only while the reporter is
76
+ * on a critical step: a tag blocked on page load is noise, the same block
77
+ * while the card form is open is a customer who cannot pay. Report-only
78
+ * violations are ignored, and each directive and origin is reported once per
79
+ * page. Returns the function that stops watching.
80
+ */
81
+ declare function watchCriticalCsp(target: ViolationTarget, reporter: CriticalReporter, options?: WatchCspOptions): () => void;
82
+
83
+ export { CRITICAL_PATH_TAG as C, type ViolationTarget as V, type WatchCspOptions as W, CRITICAL_STAGE_TAG as a, type CaptureException as b, type CriticalCaptureContext as c, type CriticalReporter as d, type CspViolation as e, blockedOrigin as f, criticalContext as g, criticalReporter as h, watchCriticalCsp as w };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Critical paths: the steps where a failure costs a client money or a lead
3
+ * (checkout, booking, an enquiry form). A failure there is reported at level
4
+ * `fatal` with two tags, and one Sentry alert per project (created from the
5
+ * estate registry's `critical:` row) watches for the tag and pages the
6
+ * founder through the relay. Nothing else in a project carries the tag, so
7
+ * the alert stays quiet until a customer is actually stuck.
8
+ *
9
+ * critical_path which path: `checkout`, `booking`, `enquiry`, ...
10
+ * critical_stage where on it: `card-load`, `tokenize`, `confirm`, `csp`, ...
11
+ *
12
+ * Like the presets, this imports no Sentry SDK: the site hands over its own
13
+ * `captureException`, so v10 and v11 both work and the browser bundle does
14
+ * not gain a second copy of the SDK.
15
+ */
16
+ /** The tag every critical-path alert filters on. Never set it by hand: use {@link criticalReporter}. */
17
+ declare const CRITICAL_PATH_TAG = "critical_path";
18
+ /** The step on the path that failed. */
19
+ declare const CRITICAL_STAGE_TAG = "critical_stage";
20
+ /** What `captureException` receives: the same in `@sentry/browser`, `@sentry/astro`, `@sentry/cloudflare` and `@sentry/nextjs`. */
21
+ interface CriticalCaptureContext {
22
+ level: "fatal";
23
+ tags: Record<string, string>;
24
+ fingerprint: string[];
25
+ extra: Record<string, unknown>;
26
+ }
27
+ /** The site's own `Sentry.captureException`, or anything with that shape. */
28
+ type CaptureException = (error: unknown, context: CriticalCaptureContext) => unknown;
29
+ /**
30
+ * The capture context for one critical failure. Exported so a site with its
31
+ * own wrapper (a lazy-loaded Sentry chunk, a beacon) can send the same event.
32
+ * The fingerprint groups by path and stage, so a hundred card declines are
33
+ * one issue and the alert fires on every event in it, not only the first.
34
+ */
35
+ declare function criticalContext(path: string, stage: string, extra?: Record<string, unknown>): CriticalCaptureContext;
36
+ /** A browser CSP violation, as much of it as this needs. */
37
+ interface CspViolation {
38
+ effectiveDirective: string;
39
+ blockedURI: string;
40
+ sourceFile?: string;
41
+ disposition?: string;
42
+ }
43
+ interface CriticalReporter {
44
+ /** Reports one failure on a critical path. Never throws: a broken report must not break the checkout it describes. */
45
+ criticalFailure(path: string, stage: string, error: unknown, extra?: Record<string, unknown>): void;
46
+ /** Marks the visitor as being on a critical step (the card form is open). CSP blocks are reported only from here on. */
47
+ enter(path: string, stage: string): void;
48
+ /** The visitor has left the critical step (booked, or gone back). */
49
+ leave(): void;
50
+ /** The step the visitor is on, or null. */
51
+ current(): {
52
+ path: string;
53
+ stage: string;
54
+ } | null;
55
+ }
56
+ /** Binds the site's `captureException`. One reporter per page. */
57
+ declare function criticalReporter(capture: CaptureException): CriticalReporter;
58
+ /** Scheme and host of a blocked URI, never its path or query (a bank's 3-D Secure URL carries session ids). */
59
+ declare function blockedOrigin(uri: string | undefined): string;
60
+ /** Anything with `addEventListener`: `document`, or a test double. */
61
+ interface ViolationTarget {
62
+ addEventListener(type: "securitypolicyviolation", listener: (event: CspViolation) => void): void;
63
+ removeEventListener(type: "securitypolicyviolation", listener: (event: CspViolation) => void): void;
64
+ }
65
+ interface WatchCspOptions {
66
+ /** Directives that cannot break this path (an analytics `img-src`, say). Default: none, so every enforced block counts. */
67
+ ignoreDirectives?: readonly string[];
68
+ /** Called after a block is reported: the site's own fallback (send the visitor to the provider's hosted page). */
69
+ onBlocked?: (violation: CspViolation, at: {
70
+ path: string;
71
+ stage: string;
72
+ }) => void;
73
+ }
74
+ /**
75
+ * Reports a CSP block as a critical failure, but only while the reporter is
76
+ * on a critical step: a tag blocked on page load is noise, the same block
77
+ * while the card form is open is a customer who cannot pay. Report-only
78
+ * violations are ignored, and each directive and origin is reported once per
79
+ * page. Returns the function that stops watching.
80
+ */
81
+ declare function watchCriticalCsp(target: ViolationTarget, reporter: CriticalReporter, options?: WatchCspOptions): () => void;
82
+
83
+ export { CRITICAL_PATH_TAG as C, type ViolationTarget as V, type WatchCspOptions as W, CRITICAL_STAGE_TAG as a, type CaptureException as b, type CriticalCaptureContext as c, type CriticalReporter as d, type CspViolation as e, blockedOrigin as f, criticalContext as g, criticalReporter as h, watchCriticalCsp as w };
package/dist/index.cjs CHANGED
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ CRITICAL_PATH_TAG: () => CRITICAL_PATH_TAG,
24
+ CRITICAL_STAGE_TAG: () => CRITICAL_STAGE_TAG,
23
25
  DATA_COLLECTION: () => DATA_COLLECTION,
24
26
  DENY_URLS: () => DENY_URLS,
25
27
  DSN_VARS: () => DSN_VARS,
@@ -31,7 +33,10 @@ __export(index_exports, {
31
33
  RELEASE_VARS: () => RELEASE_VARS,
32
34
  SENTRY_ORG: () => SENTRY_ORG,
33
35
  applicationKey: () => applicationKey,
36
+ blockedOrigin: () => blockedOrigin,
34
37
  buildPreset: () => buildPreset,
38
+ criticalContext: () => criticalContext,
39
+ criticalReporter: () => criticalReporter,
35
40
  isThirdPartyNetworkError: () => isThirdPartyNetworkError,
36
41
  normaliseDsn: () => normaliseDsn,
37
42
  resolveDsn: () => resolveDsn,
@@ -41,7 +46,8 @@ __export(index_exports, {
41
46
  scrubSpan: () => scrubSpan,
42
47
  scrubString: () => scrubString,
43
48
  scrubValue: () => scrubValue,
44
- thirdPartyFilterOptions: () => thirdPartyFilterOptions
49
+ thirdPartyFilterOptions: () => thirdPartyFilterOptions,
50
+ watchCriticalCsp: () => watchCriticalCsp
45
51
  });
46
52
  module.exports = __toCommonJS(index_exports);
47
53
 
@@ -372,8 +378,79 @@ function thirdPartyFilterOptions(project) {
372
378
  behaviour: "drop-error-if-exclusively-contains-third-party-frames"
373
379
  };
374
380
  }
381
+
382
+ // src/critical.ts
383
+ var CRITICAL_PATH_TAG = "critical_path";
384
+ var CRITICAL_STAGE_TAG = "critical_stage";
385
+ var NAME = /^[a-z][a-z0-9-]{0,39}$/;
386
+ function checkName(kind, value) {
387
+ if (!NAME.test(value)) throw new TypeError(`${kind} must be lower case letters, digits and hyphens (got ${JSON.stringify(value)})`);
388
+ return value;
389
+ }
390
+ function criticalContext(path, stage, extra = {}) {
391
+ checkName("path", path);
392
+ checkName("stage", stage);
393
+ return {
394
+ level: "fatal",
395
+ tags: { [CRITICAL_PATH_TAG]: path, [CRITICAL_STAGE_TAG]: stage },
396
+ fingerprint: ["critical", path, stage],
397
+ extra: { ...extra, critical_path: path, critical_stage: stage }
398
+ };
399
+ }
400
+ function criticalReporter(capture) {
401
+ let at = null;
402
+ return {
403
+ criticalFailure(path, stage, error, extra = {}) {
404
+ try {
405
+ const err = error instanceof Error ? error : new Error(`${path} failed at ${stage}: ${String(error)}`);
406
+ capture(err, criticalContext(path, stage, extra));
407
+ } catch {
408
+ }
409
+ },
410
+ enter(path, stage) {
411
+ at = { path: checkName("path", path), stage: checkName("stage", stage) };
412
+ },
413
+ leave() {
414
+ at = null;
415
+ },
416
+ current: () => at
417
+ };
418
+ }
419
+ function blockedOrigin(uri) {
420
+ if (!uri) return "unknown";
421
+ try {
422
+ const u = new URL(uri);
423
+ return u.origin === "null" ? u.protocol.replace(/:$/, "") : u.origin;
424
+ } catch {
425
+ return uri.split(/[/?#]/)[0] || "unknown";
426
+ }
427
+ }
428
+ function watchCriticalCsp(target, reporter, options = {}) {
429
+ const ignore = new Set(options.ignoreDirectives ?? []);
430
+ const seen = /* @__PURE__ */ new Set();
431
+ const listener = (event) => {
432
+ const at = reporter.current();
433
+ if (!at || event.disposition === "report") return;
434
+ if (ignore.has(event.effectiveDirective)) return;
435
+ const blocked = blockedOrigin(event.blockedURI);
436
+ const key = `${event.effectiveDirective} ${blocked}`;
437
+ if (seen.has(key)) return;
438
+ seen.add(key);
439
+ reporter.criticalFailure(at.path, "csp", new Error(`CSP blocked ${key} during ${at.stage}`), {
440
+ directive: event.effectiveDirective,
441
+ blocked,
442
+ source: blockedOrigin(event.sourceFile),
443
+ during: at.stage
444
+ });
445
+ options.onBlocked?.(event, at);
446
+ };
447
+ target.addEventListener("securitypolicyviolation", listener);
448
+ return () => target.removeEventListener("securitypolicyviolation", listener);
449
+ }
375
450
  // Annotate the CommonJS export names for ESM import in node:
376
451
  0 && (module.exports = {
452
+ CRITICAL_PATH_TAG,
453
+ CRITICAL_STAGE_TAG,
377
454
  DATA_COLLECTION,
378
455
  DENY_URLS,
379
456
  DSN_VARS,
@@ -385,7 +462,10 @@ function thirdPartyFilterOptions(project) {
385
462
  RELEASE_VARS,
386
463
  SENTRY_ORG,
387
464
  applicationKey,
465
+ blockedOrigin,
388
466
  buildPreset,
467
+ criticalContext,
468
+ criticalReporter,
389
469
  isThirdPartyNetworkError,
390
470
  normaliseDsn,
391
471
  resolveDsn,
@@ -395,5 +475,6 @@ function thirdPartyFilterOptions(project) {
395
475
  scrubSpan,
396
476
  scrubString,
397
477
  scrubValue,
398
- thirdPartyFilterOptions
478
+ thirdPartyFilterOptions,
479
+ watchCriticalCsp
399
480
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { B as BrowserPreset, a as BrowserPresetDefaults, D as DATA_COLLECTION, e as DSN_VARS, f as DataCollection, E as ENVIRONMENTS, g as ENVIRONMENT_VARS, h as EnvSource, I as INGEST_HOST, c as Preset, d as PresetDefaults, P as PresetInput, R as RELEASE_VARS, i as ResolvedEnvironment, j as Runtime, k as SENTRY_ORG, S as ScrubbingHook, l as SentryEnvironment, b as SpanScrubbingHook, m as buildPreset, n as normaliseDsn, r as resolveDsn, o as resolveEnvironment, p as resolveRelease } from './preset-D2peo0uv.cjs';
2
2
  export { a as applicationKey, t as thirdPartyFilterOptions } from './third-party-LjX9unFo.cjs';
3
+ export { C as CRITICAL_PATH_TAG, a as CRITICAL_STAGE_TAG, b as CaptureException, c as CriticalCaptureContext, d as CriticalReporter, e as CspViolation, V as ViolationTarget, W as WatchCspOptions, f as blockedOrigin, g as criticalContext, h as criticalReporter, w as watchCriticalCsp } from './critical-jznjvmAW.cjs';
3
4
 
4
5
  /**
5
6
  * Noise every Doman Digital project drops. Each entry is here because the
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { B as BrowserPreset, a as BrowserPresetDefaults, D as DATA_COLLECTION, e as DSN_VARS, f as DataCollection, E as ENVIRONMENTS, g as ENVIRONMENT_VARS, h as EnvSource, I as INGEST_HOST, c as Preset, d as PresetDefaults, P as PresetInput, R as RELEASE_VARS, i as ResolvedEnvironment, j as Runtime, k as SENTRY_ORG, S as ScrubbingHook, l as SentryEnvironment, b as SpanScrubbingHook, m as buildPreset, n as normaliseDsn, r as resolveDsn, o as resolveEnvironment, p as resolveRelease } from './preset-D2peo0uv.js';
2
2
  export { a as applicationKey, t as thirdPartyFilterOptions } from './third-party-LjX9unFo.js';
3
+ export { C as CRITICAL_PATH_TAG, a as CRITICAL_STAGE_TAG, b as CaptureException, c as CriticalCaptureContext, d as CriticalReporter, e as CspViolation, V as ViolationTarget, W as WatchCspOptions, f as blockedOrigin, g as criticalContext, h as criticalReporter, w as watchCriticalCsp } from './critical-jznjvmAW.js';
3
4
 
4
5
  /**
5
6
  * Noise every Doman Digital project drops. Each entry is here because the
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ import {
3
3
  thirdPartyFilterOptions
4
4
  } from "./chunk-TD2AK75E.js";
5
5
  import {
6
+ CRITICAL_PATH_TAG,
7
+ CRITICAL_STAGE_TAG,
6
8
  DATA_COLLECTION,
7
9
  DENY_URLS,
8
10
  DSN_VARS,
@@ -13,7 +15,10 @@ import {
13
15
  REDACTED,
14
16
  RELEASE_VARS,
15
17
  SENTRY_ORG,
18
+ blockedOrigin,
16
19
  buildPreset,
20
+ criticalContext,
21
+ criticalReporter,
17
22
  isThirdPartyNetworkError,
18
23
  normaliseDsn,
19
24
  resolveDsn,
@@ -22,9 +27,12 @@ import {
22
27
  scrubEvent,
23
28
  scrubSpan,
24
29
  scrubString,
25
- scrubValue
26
- } from "./chunk-BICH2PO4.js";
30
+ scrubValue,
31
+ watchCriticalCsp
32
+ } from "./chunk-EHOMV2ZB.js";
27
33
  export {
34
+ CRITICAL_PATH_TAG,
35
+ CRITICAL_STAGE_TAG,
28
36
  DATA_COLLECTION,
29
37
  DENY_URLS,
30
38
  DSN_VARS,
@@ -36,7 +44,10 @@ export {
36
44
  RELEASE_VARS,
37
45
  SENTRY_ORG,
38
46
  applicationKey,
47
+ blockedOrigin,
39
48
  buildPreset,
49
+ criticalContext,
50
+ criticalReporter,
40
51
  isThirdPartyNetworkError,
41
52
  normaliseDsn,
42
53
  resolveDsn,
@@ -46,5 +57,6 @@ export {
46
57
  scrubSpan,
47
58
  scrubString,
48
59
  scrubValue,
49
- thirdPartyFilterOptions
60
+ thirdPartyFilterOptions,
61
+ watchCriticalCsp
50
62
  };
package/dist/next.d.cts CHANGED
@@ -8,7 +8,7 @@ export { t as thirdPartyFilterOptions } from './third-party-LjX9unFo.cjs';
8
8
  *
9
9
  * Next 16 with Turbopack loads only `instrumentation-client.ts` in the
10
10
  * browser. A `sentry.client.config.ts` is never read, and a site that keeps
11
- * its client init there reports nothing from the browser (HJ-Beauty and the
11
+ * its client init there reports nothing from the browser (a client e-commerce site and the
12
12
  * DD portal, 2026-10-08 audit).
13
13
  */
14
14
 
package/dist/next.d.ts CHANGED
@@ -8,7 +8,7 @@ export { t as thirdPartyFilterOptions } from './third-party-LjX9unFo.js';
8
8
  *
9
9
  * Next 16 with Turbopack loads only `instrumentation-client.ts` in the
10
10
  * browser. A `sentry.client.config.ts` is never read, and a site that keeps
11
- * its client init there reports nothing from the browser (HJ-Beauty and the
11
+ * its client init there reports nothing from the browser (a client e-commerce site and the
12
12
  * DD portal, 2026-10-08 audit).
13
13
  */
14
14
 
package/dist/next.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  BROWSER_TRACES_SAMPLE_RATE
3
- } from "./chunk-6BR5I252.js";
3
+ } from "./chunk-2IWK7LEE.js";
4
4
  import {
5
5
  SERVER_TRACES_SAMPLE_RATE
6
- } from "./chunk-ZIWYCDHF.js";
6
+ } from "./chunk-5IXAEGK7.js";
7
7
  import {
8
8
  applicationKey,
9
9
  thirdPartyFilterOptions
@@ -13,7 +13,7 @@ import {
13
13
  buildPreset,
14
14
  resolveEnvironment,
15
15
  resolveRelease
16
- } from "./chunk-BICH2PO4.js";
16
+ } from "./chunk-EHOMV2ZB.js";
17
17
 
18
18
  // src/next.ts
19
19
  function nextClientOptions(input = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domandigital/sentry",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "description": "One Sentry setup for every Doman Digital site: init options for the browser, Cloudflare Workers and Next.js (environment, release, PII scrubber, noise filters, sample rates), and a release and source-map CLI for Worker and Astro builds.",
6
6
  "license": "Apache-2.0",
@@ -62,7 +62,7 @@
62
62
  "dist"
63
63
  ],
64
64
  "dependencies": {
65
- "@domandigital/synthetic": "^0.2.0"
65
+ "@domandigital/synthetic": "^0.2.2"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "@sentry/nextjs": ">=10",