@xovris/browser 0.1.0 → 0.1.1

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/dist/index.d.ts CHANGED
@@ -6,7 +6,13 @@ export interface BrowserOptions {
6
6
  environment?: string | undefined;
7
7
  tunnel?: string | undefined;
8
8
  }
9
+ /** G90.46: the RUM session this tab is in (rum.ts keeps it in the tab's own storage), so an issue reaches the session's replay and the
10
+ * visitor's own words; none when the site records no sessions. */
11
+ export declare function sessionTag(w: Window | undefined): Record<string, string>;
9
12
  export declare function init(o: BrowserOptions, w?: Window | undefined): Client;
10
- export declare function captureException(err: unknown): string | null;
13
+ /** An error the app handled itself, reported - `mechanism` names what caught it (a framework's boundary), else 'manual'. */
14
+ export declare function captureException(err: unknown, o?: {
15
+ mechanism?: string;
16
+ }): string | null;
11
17
  /** Tests only: forget the page-wide client. */
12
18
  export declare function resetForTests(): void;
package/dist/index.js CHANGED
@@ -7,6 +7,17 @@ const shared = () => {
7
7
  const g = globalThis;
8
8
  return (g[SHARED] ??= { client: null, windows: new WeakSet() });
9
9
  };
10
+ /** G90.46: the RUM session this tab is in (rum.ts keeps it in the tab's own storage), so an issue reaches the session's replay and the
11
+ * visitor's own words; none when the site records no sessions. */
12
+ export function sessionTag(w) {
13
+ try {
14
+ const s = w ? JSON.parse(w.sessionStorage.getItem('xovris.rum.session') ?? 'null') : null;
15
+ return s && typeof s.id === 'string' && /^[0-9a-f]{32}$/.test(s.id) ? { 'xovris.session': s.id } : {};
16
+ }
17
+ catch {
18
+ return {};
19
+ }
20
+ }
10
21
  export function init(o, w = typeof window === 'undefined' ? undefined : window) {
11
22
  const s = shared();
12
23
  if (s.client)
@@ -17,13 +28,14 @@ export function init(o, w = typeof window === 'undefined' ? undefined : window)
17
28
  if (c.enabled && w && !s.windows.has(w)) {
18
29
  s.windows.add(w);
19
30
  const where = () => ({ url: w.location.href });
20
- w.addEventListener('error', (e) => { shared().client?.captureException(e.error ?? e.message, { handled: false, mechanism: 'onerror', request: where() }); });
21
- w.addEventListener('unhandledrejection', (e) => { shared().client?.captureException(e.reason, { handled: false, mechanism: 'onunhandledrejection', request: where() }); });
31
+ w.addEventListener('error', (e) => { shared().client?.captureException(e.error ?? e.message, { handled: false, mechanism: 'onerror', request: where(), tags: sessionTag(w) }); });
32
+ w.addEventListener('unhandledrejection', (e) => { shared().client?.captureException(e.reason, { handled: false, mechanism: 'onunhandledrejection', request: where(), tags: sessionTag(w) }); });
22
33
  }
23
34
  return c;
24
35
  }
25
- export function captureException(err) {
26
- return shared().client?.captureException(err, { handled: true, mechanism: 'manual' }) ?? null;
36
+ /** An error the app handled itself, reported - `mechanism` names what caught it (a framework's boundary), else 'manual'. */
37
+ export function captureException(err, o = {}) {
38
+ return shared().client?.captureException(err, { handled: true, mechanism: o.mechanism ?? 'manual', tags: sessionTag(typeof window === 'undefined' ? undefined : window) }) ?? null;
27
39
  }
28
40
  /** Tests only: forget the page-wide client. */
29
41
  export function resetForTests() { shared().client = null; }
package/dist/mask.js CHANGED
@@ -5,8 +5,8 @@
5
5
  // (Luhn-checked), phone numbers, national identifiers, IBANs, IP addresses, tokens and long digit runs replaced by their kind.
6
6
  const EMAIL = /\b[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
7
7
  const JWT = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
8
- const BEARER = /\b(bearer|basic|token)\s+[A-Za-z0-9._~+/=-]{12,}/gi;
9
- const KEYISH = /\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]{8,}\b|\bgh[pousr]_[A-Za-z0-9]{20,}\b|\bxox[abposr]-[A-Za-z0-9-]{10,}\b|\bAKIA[A-Z0-9]{16}\b|\bAIza[0-9A-Za-z_-]{35}\b/g;
8
+ const BEARER = /\b(bearer|basic|token)\s+[A-Za-z0-9._~+/=-]{12,}/gi; // KEEP: security - a credential's format, masked in the browser
9
+ const KEYISH = /\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]{8,}\b|\bgh[pousr]_[A-Za-z0-9]{20,}\b|\bxox[abposr]-[A-Za-z0-9-]{10,}\b|\bAKIA[A-Z0-9]{16}\b|\bAIza[0-9A-Za-z_-]{35}\b/g; // KEEP: security - a credential's format, masked in the browser
10
10
  const SECRET_KV = /\b(password|passwd|pwd|secret|api[_-]?key|access[_-]?token|refresh[_-]?token|token|session[_-]?id)(\s*[:=]\s*)["']?[^\s"'&,;]{3,}/gi;
11
11
  const IBAN = /\b[A-Z]{2}\d{2}(?:\s?[A-Z0-9]{4}){2,7}(?:\s?[A-Z0-9]{1,4})?\b/g;
12
12
  const CARD = /\b(?:\d[ -]?){12,18}\d\b/g;
@@ -1,4 +1,4 @@
1
- export type SiteErrorKind = 'error' | 'unhandledrejection' | 'react' | 'boundary' | 'resource' | 'console' | 'csp' | 'deprecation' | 'intervention' | 'other';
1
+ export type SiteErrorKind = 'error' | 'unhandledrejection' | 'react' | 'boundary' | 'resource' | 'console' | 'csp' | 'deprecation' | 'intervention' | 'not_found' | 'no_match' | 'other';
2
2
  export interface SiteReporterOptions {
3
3
  /** POST target, e.g. https://api.xovris.ai/v1/public/site-errors. */
4
4
  endpoint: string;
@@ -0,0 +1,10 @@
1
+ type FallbackOf<E> = E | ((error: unknown, reset: () => void) => E);
2
+ /** The props Solid's own ErrorBoundary takes: its fallback (an element, or one made from the error and a reset) and its children, read lazily. */
3
+ export interface ErrorBoundaryProps<E> {
4
+ fallback: FallbackOf<E>;
5
+ children?: E;
6
+ }
7
+ /** Solid's ErrorBoundary that also reports to Xovris every error it catches: `const ErrorBoundary = withXovrisErrorBoundary(SolidErrorBoundary)`.
8
+ * Every prop but the fallback reaches Solid's boundary as the app wrote it (its children stay lazy, so the boundary still catches them). */
9
+ export declare function withXovrisErrorBoundary<E, P extends ErrorBoundaryProps<E>>(ErrorBoundary: (props: P) => E): (props: P) => E;
10
+ export {};
package/dist/solid.js ADDED
@@ -0,0 +1,27 @@
1
+ // D01.01.06.01: Solid has no page-wide error hook - an error one of its ErrorBoundary components catches renders that boundary's fallback and
2
+ // never reaches the page's error event. Its ErrorBoundary wrapped, the way the leader's SDK wraps it (@sentry/solid withSentryErrorBoundary):
3
+ // each error it catches is reported once, then the app's own fallback renders exactly as Solid would have rendered it. Nothing here imports
4
+ // solid-js - the app's own copy is the one wrapped, so one Solid runs on the page.
5
+ import { captureException } from './index.js';
6
+ /** Solid's ErrorBoundary that also reports to Xovris every error it catches: `const ErrorBoundary = withXovrisErrorBoundary(SolidErrorBoundary)`.
7
+ * Every prop but the fallback reaches Solid's boundary as the app wrote it (its children stay lazy, so the boundary still catches them). */
8
+ export function withXovrisErrorBoundary(ErrorBoundary) {
9
+ return (props) => {
10
+ const told = new WeakSet();
11
+ const fallback = (error, reset) => {
12
+ const kept = typeof error === 'object' && error !== null;
13
+ if (!kept || !told.has(error)) {
14
+ if (kept)
15
+ told.add(error);
16
+ captureException(error, { mechanism: 'solid.ErrorBoundary' });
17
+ }
18
+ const theirs = props.fallback;
19
+ if (typeof theirs === 'function' && theirs.length)
20
+ return theirs(error, reset);
21
+ // Solid logs the error itself whenever the fallback takes no error - it still is, as before
22
+ console.error(error);
23
+ return theirs;
24
+ };
25
+ return ErrorBoundary(new Proxy(props, { get: (t, k, r) => (k === 'fallback' ? fallback : Reflect.get(t, k, r)) }));
26
+ };
27
+ }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@xovris/browser",
3
+ "gitHead": "8c4ea16632dacbd3d42aa498287016ff8445a668",
3
4
  "description": "Xovris in the browser: errors and unhandled rejections with the page address (ADR 0011).",
4
- "version": "0.1.0",
5
+ "version": "0.1.1",
5
6
  "license": "Apache-2.0",
6
7
  "type": "module",
7
8
  "files": [
@@ -10,23 +11,33 @@
10
11
  "exports": {
11
12
  ".": {
12
13
  "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js"
14
+ "import": "./dist/index.js",
15
+ "default": "./dist/index.js"
14
16
  },
15
17
  "./site": {
16
18
  "types": "./dist/site-reporter.d.ts",
17
- "import": "./dist/site-reporter.js"
19
+ "import": "./dist/site-reporter.js",
20
+ "default": "./dist/site-reporter.js"
18
21
  },
19
22
  "./rum": {
20
23
  "types": "./dist/rum.d.ts",
21
- "import": "./dist/rum.js"
24
+ "import": "./dist/rum.js",
25
+ "default": "./dist/rum.js"
22
26
  },
23
27
  "./mask": {
24
28
  "types": "./dist/mask.d.ts",
25
- "import": "./dist/mask.js"
29
+ "import": "./dist/mask.js",
30
+ "default": "./dist/mask.js"
26
31
  },
27
32
  "./replay": {
28
33
  "types": "./dist/replay.d.ts",
29
- "import": "./dist/replay.js"
34
+ "import": "./dist/replay.js",
35
+ "default": "./dist/replay.js"
36
+ },
37
+ "./solid": {
38
+ "types": "./dist/solid.d.ts",
39
+ "import": "./dist/solid.js",
40
+ "default": "./dist/solid.js"
30
41
  }
31
42
  },
32
43
  "publishConfig": {
@@ -35,7 +46,7 @@
35
46
  "dependencies": {
36
47
  "@rrweb/record": "2.1.7",
37
48
  "web-vitals": "6.2.3",
38
- "@xovris/core": "0.1.0"
49
+ "@xovris/core": "0.1.1"
39
50
  },
40
51
  "devDependencies": {
41
52
  "happy-dom": "^20.14.6"