@atelic-action/ui 8.0.0 → 8.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/README.md +187 -22
- package/bin/atelic-check-sentry.ts +5 -0
- package/dist/gate/middleware.js +15 -1
- package/dist/monitoring/server.d.ts +122 -0
- package/dist/monitoring/server.js +302 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/vite/marketing-config.d.ts +28 -1
- package/dist/vite/marketing-config.js +62 -0
- package/package.json +10 -2
- package/src/app/layout/DesktopRail.tsx +6 -4
- package/src/app/layout/MobileMenu.tsx +10 -5
- package/src/app/layout/MobileTabBar.tsx +3 -2
- package/src/app/layout/PageError.tsx +2 -2
- package/src/app/layout/SectionCards.tsx +7 -2
- package/src/app/layout/UserMenu.tsx +1 -1
- package/src/app/ui/alert.tsx +1 -1
- package/src/app/ui/form.tsx +2 -2
- package/src/artifact/AppErrorBoundary.tsx +12 -7
- package/src/chrome/BrandLockup.tsx +46 -7
- package/src/chrome/ContactDock.tsx +59 -13
- package/src/chrome/Footer.tsx +97 -28
- package/src/chrome/NavMegaPanel.tsx +11 -6
- package/src/chrome/SiteHeader.tsx +68 -18
- package/src/chrome/SiteMenu.tsx +207 -72
- package/src/chrome/SiteShell.tsx +25 -3
- package/src/chrome/StickyCTABar.tsx +24 -8
- package/src/chrome/index.ts +2 -0
- package/src/components/NotFound.tsx +3 -2
- package/src/gate/middleware.ts +15 -1
- package/src/lib/emailText.tsx +26 -0
- package/src/lib/phoneText.tsx +49 -0
- package/src/monitoring/ErrorCatcherScript.tsx +26 -0
- package/src/monitoring/catcher.ts +118 -0
- package/src/monitoring/index.ts +25 -0
- package/src/monitoring/sdk.ts +112 -0
- package/src/monitoring/server.ts +368 -0
- package/src/monitoring/start.ts +118 -0
- package/src/primitives/Button.tsx +3 -1
- package/src/primitives/Eyebrow.tsx +6 -2
- package/src/routing/index.ts +11 -32
- package/src/routing/miss.ts +32 -0
- package/src/routing/routerErrors.tsx +57 -0
- package/src/routing/staticNotFound.tsx +64 -0
- package/src/scripts/check-sentry.ts +98 -0
- package/src/sections/CalloutPanel.tsx +4 -1
- package/src/sections/ContactInfoCard.tsx +1 -1
- package/src/sections/FullBleedVideo.tsx +13 -4
- package/src/sections/Hero.tsx +10 -3
- package/src/sections/LinkColumns.tsx +30 -14
- package/src/sections/Locations.tsx +1 -1
- package/src/sections/LogoMarquee.tsx +1 -1
- package/src/sections/PricingBand.tsx +1 -1
- package/src/sections/ProcessSteps.tsx +1 -1
- package/src/sections/siteConfig.ts +67 -5
- package/src/styles/app.css +9 -0
- package/src/styles/base.css +34 -2
- package/src/styles/chrome.css +449 -41
- package/src/styles/defaults.css +61 -2
- package/src/styles/primitives.css +20 -7
- package/src/styles/sections.css +52 -9
- package/src/types.ts +40 -2
- package/src/vite/index.ts +4 -0
- package/src/vite/marketing-config.ts +81 -1
|
@@ -47,6 +47,8 @@ export function StickyCTABar({
|
|
|
47
47
|
const spaceRef = useRef(onSpaceChange);
|
|
48
48
|
spaceRef.current = onSpaceChange;
|
|
49
49
|
const listening = onSpaceChange !== undefined;
|
|
50
|
+
// The measuring effect's report, so a swap of listeners is told at once.
|
|
51
|
+
const reportRef = useRef<(() => void) | null>(null);
|
|
50
52
|
|
|
51
53
|
useEffect(() => {
|
|
52
54
|
if (fromTop) {
|
|
@@ -66,30 +68,44 @@ export function StickyCTABar({
|
|
|
66
68
|
const bar = barRef.current;
|
|
67
69
|
if (!bar || !listening) return;
|
|
68
70
|
let last = -1;
|
|
69
|
-
// The listener last told a height
|
|
70
|
-
//
|
|
71
|
-
//
|
|
71
|
+
// The listener last told a height: the one holding the space, which
|
|
72
|
+
// the cleanup hands back. Never the caller's latest, which after a
|
|
73
|
+
// swap is a listener that was never told anything.
|
|
72
74
|
let heard: ((pixels: number) => void) | undefined;
|
|
73
75
|
const report = () => {
|
|
74
76
|
const next = show ? bar.offsetHeight : 0;
|
|
75
|
-
|
|
77
|
+
const listener = spaceRef.current;
|
|
78
|
+
if (next === last && listener === heard) return;
|
|
79
|
+
// A caller swapped listeners since the last report: the old one
|
|
80
|
+
// gives its space back before the new one is told the height.
|
|
81
|
+
if (heard && heard !== listener) heard(0);
|
|
76
82
|
last = next;
|
|
77
|
-
heard =
|
|
83
|
+
heard = listener;
|
|
78
84
|
heard?.(next);
|
|
79
85
|
};
|
|
80
86
|
report();
|
|
87
|
+
reportRef.current = report;
|
|
81
88
|
const sizes = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(report);
|
|
82
89
|
sizes?.observe(bar);
|
|
83
90
|
window.addEventListener("resize", report);
|
|
84
91
|
return () => {
|
|
92
|
+
reportRef.current = null;
|
|
85
93
|
sizes?.disconnect();
|
|
86
94
|
window.removeEventListener("resize", report);
|
|
87
|
-
// A final 0 on unmount, on hiding, and when the listener goes,
|
|
88
|
-
// foot padding outlives the bar.
|
|
89
|
-
|
|
95
|
+
// A final 0 on unmount, on hiding, and when the listener goes, to the
|
|
96
|
+
// listener that holds the space, so no foot padding outlives the bar.
|
|
97
|
+
heard?.(0);
|
|
90
98
|
};
|
|
91
99
|
}, [show, listening]);
|
|
92
100
|
|
|
101
|
+
// A caller that swaps listeners is heard at once: the old one gives its
|
|
102
|
+
// space back and the new one is told the height, with no resize to wait
|
|
103
|
+
// for. A first render's report has already run, so this one says nothing.
|
|
104
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the listener is the trigger; the report reads it through spaceRef
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
reportRef.current?.();
|
|
107
|
+
}, [onSpaceChange]);
|
|
108
|
+
|
|
93
109
|
return (
|
|
94
110
|
// Inert while offscreen, so its links take no keyboard focus before it slides in.
|
|
95
111
|
// data-dock-lift and data-showing tell the contact dock to ride above it.
|
package/src/chrome/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type {
|
|
|
12
12
|
FooterIcon,
|
|
13
13
|
HeaderPhone,
|
|
14
14
|
HoursRow,
|
|
15
|
+
MenuBurgerStyle,
|
|
15
16
|
MenuContact,
|
|
16
17
|
NavCard,
|
|
17
18
|
NavCardsSection,
|
|
@@ -28,6 +29,7 @@ export type {
|
|
|
28
29
|
Phone,
|
|
29
30
|
PostalAddress,
|
|
30
31
|
SiteLink,
|
|
32
|
+
SiteMenuSurface,
|
|
31
33
|
SocialLink,
|
|
32
34
|
} from "../types";
|
|
33
35
|
export { BrandLockup, type BrandLockupProps } from "./BrandLockup";
|
|
@@ -54,8 +54,9 @@ export function NotFound({
|
|
|
54
54
|
<div className="wrap center">
|
|
55
55
|
<span className="eyebrow center">{linksLabel}</span>
|
|
56
56
|
<nav aria-label={linksLabel} className="cta-row center">
|
|
57
|
-
{links.map((link) => (
|
|
58
|
-
|
|
57
|
+
{links.map((link, at) => (
|
|
58
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: two links may share a page, so the place keeps the key unique; links never reorder
|
|
59
|
+
<a key={at} className="btn btn-ghost" href={link.href}>
|
|
59
60
|
{link.label}
|
|
60
61
|
</a>
|
|
61
62
|
))}
|
package/src/gate/middleware.ts
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* open file of its own passes `open`; one whose matcher already leaves its
|
|
30
30
|
* open paths out may still pass its own `needsSession`, which wins over both.
|
|
31
31
|
*/
|
|
32
|
+
import { reportServerError } from "../monitoring/server.js";
|
|
32
33
|
import { isAllowed } from "./config.js";
|
|
33
34
|
import { verifyToken } from "./tokens.js";
|
|
34
35
|
import { createNeedsSession, type WallOpenings } from "./wall.js";
|
|
@@ -53,7 +54,7 @@ function readCookie(header: string, name: string): string | undefined {
|
|
|
53
54
|
export function createMiddleware(options: MiddlewareOptions = {}) {
|
|
54
55
|
const needsSession = options.needsSession ?? createNeedsSession(options.open);
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
async function decide(request: Request): Promise<Response | undefined> {
|
|
57
58
|
const secret = process.env.GATE_SESSION_SECRET;
|
|
58
59
|
if (!secret) return; // gate off, let everything through
|
|
59
60
|
|
|
@@ -69,6 +70,19 @@ export function createMiddleware(options: MiddlewareOptions = {}) {
|
|
|
69
70
|
const login = new URL("/login", url.origin);
|
|
70
71
|
login.searchParams.set("next", url.pathname + url.search);
|
|
71
72
|
return Response.redirect(login.toString(), 302);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// A throw is reported to Sentry (when a DSN is set) and thrown again, so
|
|
76
|
+
// the request fails exactly as it did; a pass and a block are untouched.
|
|
77
|
+
// The expected misses (a malformed cookie, a token that fails to verify)
|
|
78
|
+
// are answers, not errors, and stay quiet.
|
|
79
|
+
return async function middleware(request: Request): Promise<Response | undefined> {
|
|
80
|
+
try {
|
|
81
|
+
return await decide(request);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
await reportServerError(error, { request, tags: { source: "middleware" } });
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
72
86
|
};
|
|
73
87
|
}
|
|
74
88
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Fragment, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An email address with its break opportunities marked: after the @ and
|
|
5
|
+
* before each dot of the domain, so a narrow column wraps it there and
|
|
6
|
+
* never inside a word ("hello@" / "kestrelhollow" / ".example.com"). The
|
|
7
|
+
* words read and copy exactly as the address.
|
|
8
|
+
*/
|
|
9
|
+
export function breakableEmail(email: string): ReactNode {
|
|
10
|
+
const at = email.indexOf("@");
|
|
11
|
+
if (at === -1) return email;
|
|
12
|
+
const [first, ...rest] = email.slice(at + 1).split(".");
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
{email.slice(0, at + 1)}
|
|
16
|
+
<wbr />
|
|
17
|
+
{first}
|
|
18
|
+
{rest.map((part, index) => (
|
|
19
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: the parts of one address never reorder
|
|
20
|
+
<Fragment key={index}>
|
|
21
|
+
<wbr />.{part}
|
|
22
|
+
</Fragment>
|
|
23
|
+
))}
|
|
24
|
+
</>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
/** A run that reads as a phone number: seven digits or more, with the usual separators. */
|
|
4
|
+
const PHONE = /(\+?\(?\d[\d\s().-]{5,}\d)/;
|
|
5
|
+
|
|
6
|
+
/** Whether a link calls: a `tel:` href. */
|
|
7
|
+
export function isTel(href: string | undefined): boolean {
|
|
8
|
+
return href?.startsWith("tel:") ?? false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps each phone number in a run of words in `.tel-number`, which never
|
|
13
|
+
* breaks, so a call link holding more than the number (a dock row's label
|
|
14
|
+
* and line, a menu row) wraps its words and holds its number whole.
|
|
15
|
+
* Anything that is not a string passes through as it is.
|
|
16
|
+
*
|
|
17
|
+
* The run comes back inside one plain inline span, so a flex parent (a
|
|
18
|
+
* button, a row) sees the words as the one item a bare string was: split
|
|
19
|
+
* into separate items, the space before the number was dropped at an
|
|
20
|
+
* item's edge and the parent's gap stood in its place, wider than a space.
|
|
21
|
+
*/
|
|
22
|
+
export function holdPhoneNumbers(content: ReactNode): ReactNode {
|
|
23
|
+
if (typeof content !== "string") return content;
|
|
24
|
+
const parts = content.split(PHONE);
|
|
25
|
+
if (parts.length === 1) return content;
|
|
26
|
+
return (
|
|
27
|
+
<span>
|
|
28
|
+
{parts.map((part, at) =>
|
|
29
|
+
at % 2 === 1 && (part.match(/\d/g)?.length ?? 0) >= 7 ? (
|
|
30
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: the runs of one string never reorder
|
|
31
|
+
<span key={at} className="tel-number">
|
|
32
|
+
{part}
|
|
33
|
+
</span>
|
|
34
|
+
) : (
|
|
35
|
+
part
|
|
36
|
+
),
|
|
37
|
+
)}
|
|
38
|
+
</span>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The words of a link, with any phone number in them held whole when the
|
|
44
|
+
* link calls (`holdPhoneNumbers` on a `tel:` href), and as given otherwise.
|
|
45
|
+
* The one way a component sets a link's words that may hold a number.
|
|
46
|
+
*/
|
|
47
|
+
export function telText(href: string | undefined, content: ReactNode): ReactNode {
|
|
48
|
+
return isTel(href) ? holdPhoneNumbers(content) : content;
|
|
49
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { errorCatcherScript } from "./catcher";
|
|
2
|
+
|
|
3
|
+
export interface ErrorCatcherScriptProps {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the catcher renders at all. Defaults to true. A root route
|
|
6
|
+
* passes whether the build has a DSN (`enabled={Boolean(env.VITE_SENTRY_DSN)}`),
|
|
7
|
+
* so a site built without one ships no catcher holding errors nobody reads.
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The inline early catcher as an element, for a root route's `<head>` ahead
|
|
14
|
+
* of `<HeadContent />` and every other script: it is the page's first script
|
|
15
|
+
* and runs before any other, so an error thrown before the app's own
|
|
16
|
+
* JavaScript is held until `startErrorReporting` hands it to Sentry. React 19
|
|
17
|
+
* hoists the title, the meta tags, the preloads, and the stylesheets ahead of
|
|
18
|
+
* it, which changes nothing it does. With `enabled` false it renders nothing.
|
|
19
|
+
*/
|
|
20
|
+
export function ErrorCatcherScript({ enabled = true }: ErrorCatcherScriptProps = {}) {
|
|
21
|
+
if (!enabled) return null;
|
|
22
|
+
return (
|
|
23
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: the package's own constant script, no outside input
|
|
24
|
+
<script dangerouslySetInnerHTML={{ __html: errorCatcherScript }} />
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The early catcher: the buffer every error lands in before the Sentry SDK
|
|
3
|
+
* has loaded, on one well known global, so an error thrown in the first
|
|
4
|
+
* moments of a page (before first paint, before the app's own script runs)
|
|
5
|
+
* is held rather than lost. Two things install it, to the same contract:
|
|
6
|
+
* the inline script a site's root route sets first in `<head>`
|
|
7
|
+
* (`errorCatcherScript`), and `installCatcher`, which `startErrorReporting`
|
|
8
|
+
* calls in case the page has no inline script. Whichever runs first wins;
|
|
9
|
+
* the other sees the global and leaves it alone.
|
|
10
|
+
*
|
|
11
|
+
* Nothing here imports the SDK or touches `window` at module scope, so the
|
|
12
|
+
* module is safe in a prerender and costs a page next to nothing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The global the catcher lives on. */
|
|
16
|
+
export const CATCHER_GLOBAL = "__atelicErrors";
|
|
17
|
+
|
|
18
|
+
/** How many errors the buffer holds before it counts the rest as dropped. */
|
|
19
|
+
export const CATCHER_CAP = 20;
|
|
20
|
+
|
|
21
|
+
/** What raised a held error: the window's error event, an unhandled rejection, or a render crash. */
|
|
22
|
+
export type CaughtKind = "error" | "unhandledrejection" | "boundary";
|
|
23
|
+
|
|
24
|
+
/** One held error: what was thrown (an Error, a reason, or a message), how, and when. */
|
|
25
|
+
export interface CaughtError {
|
|
26
|
+
error: unknown;
|
|
27
|
+
kind: CaughtKind;
|
|
28
|
+
at: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The catcher, as the inline script and `installCatcher` both shape it. */
|
|
32
|
+
export interface Catcher {
|
|
33
|
+
q: CaughtError[];
|
|
34
|
+
max: number;
|
|
35
|
+
/** Errors past the cap, counted and let go. */
|
|
36
|
+
dropped: number;
|
|
37
|
+
push: (error: unknown, kind: CaughtKind) => void;
|
|
38
|
+
onError: (event: ErrorEvent) => void;
|
|
39
|
+
onRejection: (event: PromiseRejectionEvent) => void;
|
|
40
|
+
/** Set once the SDK is up: every error from then on goes straight to it. */
|
|
41
|
+
report?: (error: unknown, kind: CaughtKind) => void;
|
|
42
|
+
/**
|
|
43
|
+
* The launch check, set once reporting starts: throws a clearly named
|
|
44
|
+
* error from the package's own code on the next turn, uncaught, so a
|
|
45
|
+
* site can confirm in Sentry that it arrives with a readable, source
|
|
46
|
+
* mapped stack. Run `window.__atelicErrors.test()` in the console.
|
|
47
|
+
*/
|
|
48
|
+
test?: () => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type CatcherWindow = Window & { [CATCHER_GLOBAL]?: Catcher };
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The inline catcher, as a script for the first place in `<head>`: ES5, no
|
|
55
|
+
* dependencies, and the same shape `installCatcher` builds. It holds up to
|
|
56
|
+
* twenty errors and rejections and counts the rest. `ErrorCatcherScript`
|
|
57
|
+
* renders it; a site that builds its head another way inlines the string.
|
|
58
|
+
*/
|
|
59
|
+
export const errorCatcherScript =
|
|
60
|
+
`(function(w){if(!w||w.${CATCHER_GLOBAL})return;` +
|
|
61
|
+
`var q=[],c={q:q,max:${CATCHER_CAP},dropped:0};` +
|
|
62
|
+
"c.push=function(e,k){if(q.length<c.max)q.push({error:e,kind:k,at:+new Date()});else c.dropped++};" +
|
|
63
|
+
'c.onError=function(v){c.push(v&&v.error!=null?v.error:v&&v.message,"error")};' +
|
|
64
|
+
'c.onRejection=function(v){c.push(v?v.reason:v,"unhandledrejection")};' +
|
|
65
|
+
'w.addEventListener("error",c.onError);' +
|
|
66
|
+
'w.addEventListener("unhandledrejection",c.onRejection);' +
|
|
67
|
+
`w.${CATCHER_GLOBAL}=c})(window);`;
|
|
68
|
+
|
|
69
|
+
/** The catcher on this window, when one is installed. */
|
|
70
|
+
export function readCatcher(win: Window): Catcher | undefined {
|
|
71
|
+
return (win as CatcherWindow)[CATCHER_GLOBAL];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Installs the catcher on a window that has none and returns it, or returns
|
|
76
|
+
* the one already there (the inline script's). Browser only: call it from an
|
|
77
|
+
* effect or a start function, never during a render.
|
|
78
|
+
*/
|
|
79
|
+
export function installCatcher(win: Window): Catcher {
|
|
80
|
+
const existing = readCatcher(win);
|
|
81
|
+
if (existing) return existing;
|
|
82
|
+
const q: CaughtError[] = [];
|
|
83
|
+
const catcher: Catcher = {
|
|
84
|
+
q,
|
|
85
|
+
max: CATCHER_CAP,
|
|
86
|
+
dropped: 0,
|
|
87
|
+
push(error, kind) {
|
|
88
|
+
if (q.length < catcher.max) q.push({ error, kind, at: Date.now() });
|
|
89
|
+
else catcher.dropped++;
|
|
90
|
+
},
|
|
91
|
+
onError(event) {
|
|
92
|
+
catcher.push(event?.error != null ? event.error : event?.message, "error");
|
|
93
|
+
},
|
|
94
|
+
onRejection(event) {
|
|
95
|
+
catcher.push(event ? event.reason : event, "unhandledrejection");
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
win.addEventListener("error", catcher.onError);
|
|
99
|
+
win.addEventListener("unhandledrejection", catcher.onRejection);
|
|
100
|
+
(win as CatcherWindow)[CATCHER_GLOBAL] = catcher;
|
|
101
|
+
return catcher;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Hands an error to whatever is listening: the SDK once it has loaded, the
|
|
106
|
+
* buffer before that. For an error the window never sees, such as a render
|
|
107
|
+
* crash an error boundary catches. A page where reporting was never started
|
|
108
|
+
* and no inline catcher runs has nothing listening, so the error is let go
|
|
109
|
+
* quietly rather than held by a catcher nobody will read. A no op where
|
|
110
|
+
* there is no window (a prerender).
|
|
111
|
+
*/
|
|
112
|
+
export function reportError(error: unknown, kind: CaughtKind = "boundary"): void {
|
|
113
|
+
if (typeof window === "undefined") return;
|
|
114
|
+
const catcher = readCatcher(window);
|
|
115
|
+
if (!catcher) return;
|
|
116
|
+
if (catcher.report) catcher.report(error, kind);
|
|
117
|
+
else catcher.push(error, kind);
|
|
118
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error reporting for a site, in the browser: the early catcher and the
|
|
3
|
+
* start function. The server side is its own built entry,
|
|
4
|
+
* `@atelic-action/ui/monitoring/server`, since a Vercel function imports it
|
|
5
|
+
* uncompiled. README.md, Error Reporting, has the wiring.
|
|
6
|
+
*/
|
|
7
|
+
export {
|
|
8
|
+
CATCHER_CAP,
|
|
9
|
+
CATCHER_GLOBAL,
|
|
10
|
+
type Catcher,
|
|
11
|
+
type CaughtError,
|
|
12
|
+
type CaughtKind,
|
|
13
|
+
errorCatcherScript,
|
|
14
|
+
installCatcher,
|
|
15
|
+
readCatcher,
|
|
16
|
+
reportError,
|
|
17
|
+
} from "./catcher";
|
|
18
|
+
export { ErrorCatcherScript, type ErrorCatcherScriptProps } from "./ErrorCatcherScript";
|
|
19
|
+
export {
|
|
20
|
+
afterFirstPaint,
|
|
21
|
+
type ErrorReportingOptions,
|
|
22
|
+
LAUNCH_CHECK_MESSAGE,
|
|
23
|
+
startErrorReporting,
|
|
24
|
+
throwLaunchCheck,
|
|
25
|
+
} from "./start";
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Sentry browser SDK, set up for errors alone, in the one module
|
|
3
|
+
* `startErrorReporting` imports dynamically, so a page downloads it only
|
|
4
|
+
* after first paint and only when a DSN is configured.
|
|
5
|
+
*
|
|
6
|
+
* Built from the SDK's parts rather than `init()`: `init()` pulls in every
|
|
7
|
+
* default integration (breadcrumbs, sessions, the browser API wrappers) even
|
|
8
|
+
* when told not to use them, where a client given its integrations by name
|
|
9
|
+
* bundles only those. No tracing, no replay, no breadcrumbs: breadcrumbs
|
|
10
|
+
* would carry the console, the requests a page makes, and what a reader
|
|
11
|
+
* clicked, none of which an error report needs.
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
BrowserClient,
|
|
15
|
+
captureException,
|
|
16
|
+
dedupeIntegration,
|
|
17
|
+
defaultStackParser,
|
|
18
|
+
eventFiltersIntegration,
|
|
19
|
+
functionToStringIntegration,
|
|
20
|
+
globalHandlersIntegration,
|
|
21
|
+
httpContextIntegration,
|
|
22
|
+
linkedErrorsIntegration,
|
|
23
|
+
makeFetchTransport,
|
|
24
|
+
setCurrentClient,
|
|
25
|
+
} from "@sentry/browser";
|
|
26
|
+
import type { CaughtKind } from "./catcher";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Noise the reports leave out, kept short on purpose. An error whose top
|
|
30
|
+
* frame is a browser extension's script is the extension's, not the site's.
|
|
31
|
+
* The two messages are the bridges in app webviews (an email app's or a
|
|
32
|
+
* social app's built in browser) failing between the page and the app.
|
|
33
|
+
*/
|
|
34
|
+
export const DENY_URLS = [
|
|
35
|
+
/^chrome-extension:\/\//,
|
|
36
|
+
/^moz-extension:\/\//,
|
|
37
|
+
/^safari-(web-)?extension:\/\//,
|
|
38
|
+
];
|
|
39
|
+
export const IGNORE_ERRORS = [/Java object is gone/, /Error invoking postMessage/];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What an event may carry of its request, matching the server reporter: the
|
|
43
|
+
* URL with no query string or fragment, and the user agent. The SDK's own
|
|
44
|
+
* request integration attaches the full URL and the referrer, and a link can
|
|
45
|
+
* carry a reader's personal parameters in either, so they are cut here, the
|
|
46
|
+
* last step before an event leaves the page.
|
|
47
|
+
*/
|
|
48
|
+
export function scrubRequest<
|
|
49
|
+
T extends {
|
|
50
|
+
request?: { url?: string; headers?: Record<string, string> };
|
|
51
|
+
exception?: { values?: { stacktrace?: { frames?: { filename?: string }[] } }[] };
|
|
52
|
+
},
|
|
53
|
+
>(event: T): T {
|
|
54
|
+
// A frame's file is the page itself for an inline script, query and all.
|
|
55
|
+
for (const value of event.exception?.values ?? []) {
|
|
56
|
+
for (const frame of value.stacktrace?.frames ?? []) {
|
|
57
|
+
if (frame.filename) frame.filename = frame.filename.replace(/[?#].*$/, "");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const request = event.request;
|
|
61
|
+
if (!request) return event;
|
|
62
|
+
if (request.url) {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = new URL(request.url);
|
|
65
|
+
request.url = `${parsed.origin}${parsed.pathname}`;
|
|
66
|
+
} catch {
|
|
67
|
+
delete request.url;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const agent = request.headers?.["User-Agent"];
|
|
71
|
+
if (agent) request.headers = { "User-Agent": agent };
|
|
72
|
+
else delete request.headers;
|
|
73
|
+
return event;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface SDKOptions {
|
|
77
|
+
dsn: string;
|
|
78
|
+
release?: string;
|
|
79
|
+
environment?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Starts the client and returns how an error reaches it, tagged with what raised it. */
|
|
83
|
+
export function initSentry({ dsn, release, environment }: SDKOptions) {
|
|
84
|
+
const client = new BrowserClient({
|
|
85
|
+
dsn,
|
|
86
|
+
release,
|
|
87
|
+
environment,
|
|
88
|
+
transport: makeFetchTransport,
|
|
89
|
+
stackParser: defaultStackParser,
|
|
90
|
+
denyUrls: DENY_URLS,
|
|
91
|
+
ignoreErrors: IGNORE_ERRORS,
|
|
92
|
+
beforeSend: scrubRequest,
|
|
93
|
+
integrations: [
|
|
94
|
+
eventFiltersIntegration(),
|
|
95
|
+
functionToStringIntegration(),
|
|
96
|
+
globalHandlersIntegration(),
|
|
97
|
+
linkedErrorsIntegration(),
|
|
98
|
+
dedupeIntegration(),
|
|
99
|
+
httpContextIntegration(),
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
setCurrentClient(client);
|
|
103
|
+
client.init();
|
|
104
|
+
return (error: unknown, kind: CaughtKind, early = false, dropped = 0) => {
|
|
105
|
+
captureException(error, {
|
|
106
|
+
tags: { source: kind, ...(early ? { early: "true" } : {}) },
|
|
107
|
+
// How many errors the early catcher let go past its cap, on each
|
|
108
|
+
// replayed one, so a burst before the SDK arrived is still visible.
|
|
109
|
+
...(dropped > 0 ? { extra: { earlyDropped: dropped } } : {}),
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
}
|