@atelic-action/ui 8.0.0 → 8.1.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 +135 -14
- package/bin/atelic-check-sentry.ts +5 -0
- package/dist/gate/middleware.js +15 -1
- package/dist/monitoring/server.d.ts +72 -0
- package/dist/monitoring/server.js +201 -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 +35 -5
- package/src/chrome/ContactDock.tsx +45 -13
- package/src/chrome/Footer.tsx +97 -25
- package/src/chrome/NavMegaPanel.tsx +17 -6
- package/src/chrome/SiteHeader.tsx +35 -7
- package/src/chrome/SiteMenu.tsx +6 -3
- package/src/chrome/SiteShell.tsx +22 -2
- package/src/chrome/StickyCTABar.tsx +12 -8
- 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 +40 -0
- package/src/monitoring/ErrorCatcherScript.tsx +15 -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 +244 -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 +1 -0
- package/src/routing/miss.ts +32 -0
- package/src/scripts/check-sentry.ts +77 -0
- package/src/sections/FullBleedVideo.tsx +13 -4
- package/src/sections/Hero.tsx +8 -1
- package/src/sections/LinkColumns.tsx +30 -14
- package/src/sections/Locations.tsx +1 -1
- package/src/sections/siteConfig.ts +35 -5
- package/src/styles/app.css +9 -0
- package/src/styles/base.css +26 -0
- package/src/styles/chrome.css +218 -28
- package/src/styles/defaults.css +5 -2
- package/src/styles/primitives.css +11 -4
- package/src/styles/sections.css +26 -3
- package/src/types.ts +8 -1
- package/src/vite/index.ts +4 -0
- package/src/vite/marketing-config.ts +81 -1
|
@@ -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 } 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
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error reporting on the server: a dependency free Sentry reporter for a
|
|
3
|
+
* Vercel function or middleware. Built to dist/ with the gate (CLAUDE.md,
|
|
4
|
+
* the built corner), since Vercel runs a function's package imports as
|
|
5
|
+
* shipped, so this file imports nothing and touches only what a function and
|
|
6
|
+
* the middleware runtime both have (fetch, `AbortController`, `crypto`).
|
|
7
|
+
*
|
|
8
|
+
* import { reportServerError, withErrorReporting } from "@atelic-action/ui/monitoring/server";
|
|
9
|
+
*
|
|
10
|
+
* Privacy: a report carries the request's method and path, and its user
|
|
11
|
+
* agent, never its body, its query string, or any other header. A contact
|
|
12
|
+
* form's request holds a person's name, address, and message.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The parts of a DSN a report is sent with. */
|
|
16
|
+
export interface ParsedDSN {
|
|
17
|
+
/** The public key, sent as `sentry_key`. */
|
|
18
|
+
key: string;
|
|
19
|
+
projectId: string;
|
|
20
|
+
/** Where the envelope is posted. */
|
|
21
|
+
envelopeURL: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ServerReportOptions {
|
|
25
|
+
/** Defaults to `SENTRY_DSN`, then `VITE_SENTRY_DSN`, from the environment. */
|
|
26
|
+
dsn?: string;
|
|
27
|
+
/** The request being handled; only its method, path, and user agent are read. */
|
|
28
|
+
request?: Request;
|
|
29
|
+
/** Tags beside the runtime's, e.g. `{ route: "contact" }`. */
|
|
30
|
+
tags?: Record<string, string>;
|
|
31
|
+
/** Defaults to `VERCEL_GIT_COMMIT_SHA`. */
|
|
32
|
+
release?: string;
|
|
33
|
+
/** Defaults to `VERCEL_ENV`. */
|
|
34
|
+
environment?: string;
|
|
35
|
+
/** How long the send may take, in milliseconds. Defaults to 2000. */
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** One stack frame in Sentry's exception format. */
|
|
40
|
+
export interface SentryFrame {
|
|
41
|
+
function?: string;
|
|
42
|
+
filename?: string;
|
|
43
|
+
lineno?: number;
|
|
44
|
+
colno?: number;
|
|
45
|
+
in_app: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const SDK = { name: "atelic.server", version: "1" };
|
|
49
|
+
|
|
50
|
+
function environmentValue(name: string): string | undefined {
|
|
51
|
+
const env = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process
|
|
52
|
+
?.env;
|
|
53
|
+
const value = env?.[name];
|
|
54
|
+
return value === "" ? undefined : value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Reads a DSN (`https://<key>@<host>[/<path>]/<project>`) into the URL its
|
|
59
|
+
* envelopes are posted to. Undefined for anything that is not one.
|
|
60
|
+
*/
|
|
61
|
+
export function parseDSN(dsn: string | undefined): ParsedDSN | undefined {
|
|
62
|
+
if (!dsn) return undefined;
|
|
63
|
+
let url: URL;
|
|
64
|
+
try {
|
|
65
|
+
url = new URL(dsn);
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const key = url.username;
|
|
70
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
71
|
+
const projectId = parts.pop();
|
|
72
|
+
if (!key || !projectId || !/^\d+$/.test(projectId)) return undefined;
|
|
73
|
+
const prefix = parts.length ? `/${parts.join("/")}` : "";
|
|
74
|
+
const envelopeURL = `${url.protocol}//${url.host}${prefix}/api/${projectId}/envelope/?sentry_key=${encodeURIComponent(key)}&sentry_version=7`;
|
|
75
|
+
return { key, projectId, envelopeURL };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The frames of a V8 stack (`at fn (file:line:col)`, `at file:line:col`),
|
|
80
|
+
* oldest call first, as Sentry lists them. A frame inside `node_modules` is
|
|
81
|
+
* not the site's own code.
|
|
82
|
+
*/
|
|
83
|
+
export function parseStack(stack: string | undefined): SentryFrame[] {
|
|
84
|
+
if (!stack) return [];
|
|
85
|
+
const frames: SentryFrame[] = [];
|
|
86
|
+
for (const line of stack.split("\n")) {
|
|
87
|
+
const match = line.match(/^\s*at (?:(.+?) \()?(.+?):(\d+):(\d+)\)?\s*$/);
|
|
88
|
+
if (!match) continue;
|
|
89
|
+
const [, fn, filename, lineno, colno] = match;
|
|
90
|
+
frames.push({
|
|
91
|
+
...(fn ? { function: fn } : {}),
|
|
92
|
+
filename,
|
|
93
|
+
lineno: Number(lineno),
|
|
94
|
+
colno: Number(colno),
|
|
95
|
+
in_app: !filename.includes("node_modules"),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return frames.reverse();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The runtime a report came from: Vercel's edge, Node, or neither. */
|
|
102
|
+
function runtime(): string {
|
|
103
|
+
if (typeof (globalThis as { EdgeRuntime?: unknown }).EdgeRuntime !== "undefined") return "edge";
|
|
104
|
+
const node = (globalThis as { process?: { versions?: { node?: string } } }).process?.versions
|
|
105
|
+
?.node;
|
|
106
|
+
return node ? "node" : "unknown";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function eventID(): string {
|
|
110
|
+
const random = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto?.randomUUID;
|
|
111
|
+
if (random) return random.call(globalThis.crypto).replaceAll("-", "");
|
|
112
|
+
let id = "";
|
|
113
|
+
for (let i = 0; i < 32; i++) id += Math.floor(Math.random() * 16).toString(16);
|
|
114
|
+
return id;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The thrown value as Sentry's exception: its type, message, and frames. */
|
|
118
|
+
function exceptionOf(error: unknown) {
|
|
119
|
+
if (error instanceof Error) {
|
|
120
|
+
const frames = parseStack(error.stack);
|
|
121
|
+
return {
|
|
122
|
+
type: error.name || "Error",
|
|
123
|
+
value: error.message,
|
|
124
|
+
...(frames.length ? { stacktrace: { frames } } : {}),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
let value: string;
|
|
128
|
+
try {
|
|
129
|
+
value = typeof error === "string" ? error : JSON.stringify(error);
|
|
130
|
+
} catch {
|
|
131
|
+
value = String(error);
|
|
132
|
+
}
|
|
133
|
+
return { type: "Error", value: value ?? String(error) };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The request as a report may carry it: the method, the URL with no query
|
|
138
|
+
* string or fragment, and the user agent. Never the body, never another
|
|
139
|
+
* header.
|
|
140
|
+
*/
|
|
141
|
+
function requestOf(request: Request | undefined) {
|
|
142
|
+
if (!request) return undefined;
|
|
143
|
+
let url: string | undefined;
|
|
144
|
+
try {
|
|
145
|
+
const parsed = new URL(request.url);
|
|
146
|
+
url = `${parsed.origin}${parsed.pathname}`;
|
|
147
|
+
} catch {
|
|
148
|
+
url = undefined;
|
|
149
|
+
}
|
|
150
|
+
const agent = request.headers?.get?.("user-agent");
|
|
151
|
+
return {
|
|
152
|
+
method: request.method,
|
|
153
|
+
...(url ? { url } : {}),
|
|
154
|
+
...(agent ? { headers: { "User-Agent": agent } } : {}),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The envelope a report is sent as: the envelope header, the item header,
|
|
160
|
+
* and the event, one JSON document to a line. Exported for the tests.
|
|
161
|
+
*/
|
|
162
|
+
export function buildEnvelope(
|
|
163
|
+
error: unknown,
|
|
164
|
+
dsn: string,
|
|
165
|
+
options: Omit<ServerReportOptions, "dsn" | "timeoutMs"> = {},
|
|
166
|
+
now: Date = new Date(),
|
|
167
|
+
): string {
|
|
168
|
+
const id = eventID();
|
|
169
|
+
const release = options.release ?? environmentValue("VERCEL_GIT_COMMIT_SHA");
|
|
170
|
+
const environment = options.environment ?? environmentValue("VERCEL_ENV");
|
|
171
|
+
const request = requestOf(options.request);
|
|
172
|
+
const event = {
|
|
173
|
+
event_id: id,
|
|
174
|
+
timestamp: now.getTime() / 1000,
|
|
175
|
+
platform: "javascript",
|
|
176
|
+
level: "error",
|
|
177
|
+
sdk: SDK,
|
|
178
|
+
...(release ? { release } : {}),
|
|
179
|
+
...(environment ? { environment } : {}),
|
|
180
|
+
tags: { runtime: runtime(), ...options.tags },
|
|
181
|
+
...(request ? { request } : {}),
|
|
182
|
+
exception: { values: [exceptionOf(error)] },
|
|
183
|
+
};
|
|
184
|
+
const header = { event_id: id, sent_at: now.toISOString(), dsn, sdk: SDK };
|
|
185
|
+
return [JSON.stringify(header), JSON.stringify({ type: "event" }), JSON.stringify(event)].join(
|
|
186
|
+
"\n",
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Reports an error to Sentry from a function or the middleware. Resolves
|
|
192
|
+
* true when Sentry took it and false otherwise (no DSN, a bad DSN, a failed
|
|
193
|
+
* or slow send), and never throws, so a report can never become a second
|
|
194
|
+
* failure. With no DSN it sends nothing.
|
|
195
|
+
*/
|
|
196
|
+
export async function reportServerError(
|
|
197
|
+
error: unknown,
|
|
198
|
+
options: ServerReportOptions = {},
|
|
199
|
+
): Promise<boolean> {
|
|
200
|
+
try {
|
|
201
|
+
const dsn =
|
|
202
|
+
options.dsn ?? environmentValue("SENTRY_DSN") ?? environmentValue("VITE_SENTRY_DSN");
|
|
203
|
+
const parsed = parseDSN(dsn);
|
|
204
|
+
if (!dsn || !parsed) return false;
|
|
205
|
+
const body = buildEnvelope(error, dsn, options);
|
|
206
|
+
const controller = new AbortController();
|
|
207
|
+
const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 2000);
|
|
208
|
+
try {
|
|
209
|
+
const response = await fetch(parsed.envelopeURL, {
|
|
210
|
+
method: "POST",
|
|
211
|
+
headers: { "Content-Type": "application/x-sentry-envelope" },
|
|
212
|
+
body,
|
|
213
|
+
signal: controller.signal,
|
|
214
|
+
});
|
|
215
|
+
// The answer's body is never read, so it is let go at once rather
|
|
216
|
+
// than held open until the runtime collects it.
|
|
217
|
+
await response.body?.cancel().catch(() => {});
|
|
218
|
+
return response.ok;
|
|
219
|
+
} finally {
|
|
220
|
+
clearTimeout(timer);
|
|
221
|
+
}
|
|
222
|
+
} catch {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Wraps a function's handler so a throw is reported, then thrown again: the
|
|
229
|
+
* platform still answers the request as it would have, and Sentry hears of
|
|
230
|
+
* it first. `export const POST = withErrorReporting(async (request) => ...)`.
|
|
231
|
+
*/
|
|
232
|
+
export function withErrorReporting<Args extends [Request, ...unknown[]], Result>(
|
|
233
|
+
handler: (...args: Args) => Result | Promise<Result>,
|
|
234
|
+
options: Omit<ServerReportOptions, "request"> = {},
|
|
235
|
+
): (...args: Args) => Promise<Result> {
|
|
236
|
+
return async (...args: Args) => {
|
|
237
|
+
try {
|
|
238
|
+
return await handler(...args);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
await reportServerError(error, { ...options, request: args[0] });
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
import { installCatcher } from "./catcher";
|
|
3
|
+
|
|
4
|
+
export interface ErrorReportingOptions {
|
|
5
|
+
/** The project's DSN, `VITE_SENTRY_DSN`. With none, nothing is installed or loaded. */
|
|
6
|
+
dsn?: string;
|
|
7
|
+
/** The release the errors are filed under: the build's commit (`import.meta.env.VITE_RELEASE`). */
|
|
8
|
+
release?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The environment the errors are filed under. Defaults to the build's
|
|
11
|
+
* `import.meta.env.VITE_ENVIRONMENT`, which `marketingConfig` sets from
|
|
12
|
+
* `VERCEL_ENV` (production, preview, development), falling back to the
|
|
13
|
+
* build's mode.
|
|
14
|
+
*/
|
|
15
|
+
environment?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The message the launch check's error carries, so it is plain in Sentry what it is. */
|
|
19
|
+
export const LAUNCH_CHECK_MESSAGE =
|
|
20
|
+
"Atelic error reporting launch check: thrown on purpose from @atelic-action/ui";
|
|
21
|
+
|
|
22
|
+
/** The environment the site's build names, when it names one. */
|
|
23
|
+
function buildEnvironment(): string | undefined {
|
|
24
|
+
try {
|
|
25
|
+
return import.meta.env?.VITE_ENVIRONMENT || undefined;
|
|
26
|
+
} catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Throws the launch check's error on the next turn, uncaught, from this module. */
|
|
32
|
+
export function throwLaunchCheck(): void {
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
throw new Error(LAUNCH_CHECK_MESSAGE);
|
|
35
|
+
}, 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The longest the SDK waits for first paint before it loads anyway. */
|
|
39
|
+
export const LOAD_CAP_MS = 10_000;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Runs `task` once, after the first contentful paint, falling back to the
|
|
43
|
+
* load event where the browser cannot report paints (no
|
|
44
|
+
* `PerformanceObserver`, or one without the `paint` entry type), and after
|
|
45
|
+
* ten seconds whatever happens, so a page that never paints still reports.
|
|
46
|
+
* The SDK waits for paint because loaded any earlier it competes with the
|
|
47
|
+
* page's own first paint, which is what a speed test measures.
|
|
48
|
+
*/
|
|
49
|
+
export function afterFirstPaint(task: () => void, win: Window = window): void {
|
|
50
|
+
let ran = false;
|
|
51
|
+
const once = () => {
|
|
52
|
+
if (ran) return;
|
|
53
|
+
ran = true;
|
|
54
|
+
task();
|
|
55
|
+
};
|
|
56
|
+
const Observer = (win as Window & { PerformanceObserver?: typeof PerformanceObserver })
|
|
57
|
+
.PerformanceObserver;
|
|
58
|
+
let watching = false;
|
|
59
|
+
if (Observer && (Observer.supportedEntryTypes ?? []).includes("paint")) {
|
|
60
|
+
try {
|
|
61
|
+
const observer = new Observer((entries) => {
|
|
62
|
+
if (entries.getEntriesByName("first-contentful-paint").length) {
|
|
63
|
+
observer.disconnect();
|
|
64
|
+
win.setTimeout(once, 0);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
observer.observe({ type: "paint", buffered: true });
|
|
68
|
+
watching = true;
|
|
69
|
+
} catch {
|
|
70
|
+
watching = false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!watching) {
|
|
74
|
+
if (win.document.readyState === "complete") win.setTimeout(once, 0);
|
|
75
|
+
else win.addEventListener("load", once, { once: true });
|
|
76
|
+
}
|
|
77
|
+
win.setTimeout(once, LOAD_CAP_MS);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Starts error reporting in the browser: errors only, never tracing.
|
|
82
|
+
*
|
|
83
|
+
* At once it makes sure the early catcher is listening (the inline script
|
|
84
|
+
* from the root route, or one installed here), so nothing thrown before the
|
|
85
|
+
* SDK arrives is lost. After first paint it loads the SDK, set up for errors
|
|
86
|
+
* alone, replays what the catcher held (each tagged `early`), hands the
|
|
87
|
+
* catcher's later errors to the SDK, and takes the catcher's own listeners
|
|
88
|
+
* off, since the SDK's global handlers listen from then on and an error
|
|
89
|
+
* must never be reported twice.
|
|
90
|
+
*
|
|
91
|
+
* With no `dsn` it does nothing and loads nothing. Call it once, in the
|
|
92
|
+
* browser (a site's router module, guarded by `typeof window`).
|
|
93
|
+
*/
|
|
94
|
+
export function startErrorReporting({
|
|
95
|
+
dsn,
|
|
96
|
+
release,
|
|
97
|
+
environment = buildEnvironment(),
|
|
98
|
+
}: ErrorReportingOptions): void {
|
|
99
|
+
if (!dsn || typeof window === "undefined") return;
|
|
100
|
+
const win = window;
|
|
101
|
+
const catcher = installCatcher(win);
|
|
102
|
+
catcher.test = throwLaunchCheck;
|
|
103
|
+
afterFirstPaint(() => {
|
|
104
|
+
import("./sdk")
|
|
105
|
+
.then(({ initSentry }) => {
|
|
106
|
+
const capture = initSentry({ dsn, release, environment });
|
|
107
|
+
win.removeEventListener("error", catcher.onError);
|
|
108
|
+
win.removeEventListener("unhandledrejection", catcher.onRejection);
|
|
109
|
+
catcher.report = (error, kind) => capture(error, kind);
|
|
110
|
+
const held = catcher.q.splice(0, catcher.q.length);
|
|
111
|
+
for (const item of held) capture(item.error, item.kind, true, catcher.dropped);
|
|
112
|
+
})
|
|
113
|
+
.catch(() => {
|
|
114
|
+
// The SDK failed to load (offline, blocked by a content blocker):
|
|
115
|
+
// the catcher keeps holding, and the page is none the worse.
|
|
116
|
+
});
|
|
117
|
+
}, win);
|
|
118
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CSSProperties, ReactNode } from "react";
|
|
2
2
|
import { newTabProps } from "../lib/newTabProps";
|
|
3
|
+
import { holdPhoneNumbers, isTel } from "../lib/phoneText";
|
|
3
4
|
import { useWithBase } from "../routing/BasePathProvider";
|
|
4
5
|
|
|
5
6
|
export interface ButtonProps {
|
|
@@ -52,9 +53,10 @@ export function Button({
|
|
|
52
53
|
.filter(Boolean)
|
|
53
54
|
.join(" ");
|
|
54
55
|
|
|
56
|
+
// A call button with words beside its number holds the number whole.
|
|
55
57
|
const content = (
|
|
56
58
|
<>
|
|
57
|
-
{children}
|
|
59
|
+
{isTel(href) ? holdPhoneNumbers(children) : children}
|
|
58
60
|
{arrow && (
|
|
59
61
|
<span className="arrow" aria-hidden="true">
|
|
60
62
|
→
|
|
@@ -11,6 +11,8 @@ export interface EyebrowProps {
|
|
|
11
11
|
* Accepted so existing call sites keep compiling.
|
|
12
12
|
*/
|
|
13
13
|
run?: boolean;
|
|
14
|
+
/** Draws the trailing rule. Defaults to true; false sets the kicker alone. */
|
|
15
|
+
rule?: boolean;
|
|
14
16
|
children: ReactNode;
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -19,7 +21,9 @@ export interface EyebrowProps {
|
|
|
19
21
|
* that fades out to the right (the practice wordmark's signature), rendered
|
|
20
22
|
* from the primary token so it carries each site's brand color.
|
|
21
23
|
*/
|
|
22
|
-
export function Eyebrow({ onDark = false, center = false, children }: EyebrowProps) {
|
|
23
|
-
const classes = ["eyebrow", onDark && "on-dark", center && "center"
|
|
24
|
+
export function Eyebrow({ onDark = false, center = false, rule = true, children }: EyebrowProps) {
|
|
25
|
+
const classes = ["eyebrow", onDark && "on-dark", center && "center", !rule && "no-rule"]
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.join(" ");
|
|
24
28
|
return <p className={classes}>{children}</p>;
|
|
25
29
|
}
|
package/src/routing/index.ts
CHANGED