aissue 0.0.0-stage → 2.0.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.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +390 -2
  3. package/dist/cjs/browser.d.ts +16 -0
  4. package/dist/cjs/browser.js +80 -0
  5. package/dist/cjs/core/breadcrumbs.d.ts +48 -0
  6. package/dist/cjs/core/breadcrumbs.js +313 -0
  7. package/dist/cjs/core/client.d.ts +54 -0
  8. package/dist/cjs/core/client.js +293 -0
  9. package/dist/cjs/core/env.d.ts +19 -0
  10. package/dist/cjs/core/env.js +71 -0
  11. package/dist/cjs/core/event.d.ts +35 -0
  12. package/dist/cjs/core/event.js +187 -0
  13. package/dist/cjs/core/hub.d.ts +20 -0
  14. package/dist/cjs/core/hub.js +21 -0
  15. package/dist/cjs/core/instrument-browser.d.ts +16 -0
  16. package/dist/cjs/core/instrument-browser.js +208 -0
  17. package/dist/cjs/core/instrument-node.d.ts +5 -0
  18. package/dist/cjs/core/instrument-node.js +250 -0
  19. package/dist/cjs/core/instrument.d.ts +12 -0
  20. package/dist/cjs/core/instrument.js +137 -0
  21. package/dist/cjs/core/privacy.d.ts +25 -0
  22. package/dist/cjs/core/privacy.js +269 -0
  23. package/dist/cjs/core/stack.d.ts +13 -0
  24. package/dist/cjs/core/stack.js +147 -0
  25. package/dist/cjs/core/transport.d.ts +31 -0
  26. package/dist/cjs/core/transport.js +154 -0
  27. package/dist/cjs/core/types.d.ts +149 -0
  28. package/dist/cjs/core/types.js +2 -0
  29. package/dist/cjs/core/version.d.ts +2 -0
  30. package/dist/cjs/core/version.js +6 -0
  31. package/dist/cjs/index.d.ts +27 -0
  32. package/dist/cjs/index.js +83 -0
  33. package/dist/cjs/nextjs/client.d.ts +10 -0
  34. package/dist/cjs/nextjs/client.js +99 -0
  35. package/dist/cjs/nextjs/index.d.ts +31 -0
  36. package/dist/cjs/nextjs/index.js +99 -0
  37. package/dist/cjs/node.d.ts +48 -0
  38. package/dist/cjs/node.js +223 -0
  39. package/dist/cjs/package.json +3 -0
  40. package/dist/cjs/react.d.ts +40 -0
  41. package/dist/cjs/react.js +90 -0
  42. package/dist/esm/browser.d.ts +16 -0
  43. package/dist/esm/browser.js +71 -0
  44. package/dist/esm/cli.d.ts +2 -0
  45. package/dist/esm/cli.js +386 -0
  46. package/dist/esm/core/breadcrumbs.d.ts +48 -0
  47. package/dist/esm/core/breadcrumbs.js +296 -0
  48. package/dist/esm/core/client.d.ts +54 -0
  49. package/dist/esm/core/client.js +285 -0
  50. package/dist/esm/core/env.d.ts +19 -0
  51. package/dist/esm/core/env.js +62 -0
  52. package/dist/esm/core/event.d.ts +35 -0
  53. package/dist/esm/core/event.js +179 -0
  54. package/dist/esm/core/hub.d.ts +20 -0
  55. package/dist/esm/core/hub.js +17 -0
  56. package/dist/esm/core/instrument-browser.d.ts +16 -0
  57. package/dist/esm/core/instrument-browser.js +203 -0
  58. package/dist/esm/core/instrument-node.d.ts +5 -0
  59. package/dist/esm/core/instrument-node.js +214 -0
  60. package/dist/esm/core/instrument.d.ts +12 -0
  61. package/dist/esm/core/instrument.js +132 -0
  62. package/dist/esm/core/privacy.d.ts +25 -0
  63. package/dist/esm/core/privacy.js +257 -0
  64. package/dist/esm/core/stack.d.ts +13 -0
  65. package/dist/esm/core/stack.js +140 -0
  66. package/dist/esm/core/transport.d.ts +31 -0
  67. package/dist/esm/core/transport.js +149 -0
  68. package/dist/esm/core/types.d.ts +149 -0
  69. package/dist/esm/core/types.js +1 -0
  70. package/dist/esm/core/version.d.ts +2 -0
  71. package/dist/esm/core/version.js +3 -0
  72. package/dist/esm/index.d.ts +27 -0
  73. package/dist/esm/index.js +72 -0
  74. package/dist/esm/nextjs/client.d.ts +10 -0
  75. package/dist/esm/nextjs/client.js +90 -0
  76. package/dist/esm/nextjs/index.d.ts +31 -0
  77. package/dist/esm/nextjs/index.js +88 -0
  78. package/dist/esm/node.d.ts +48 -0
  79. package/dist/esm/node.js +210 -0
  80. package/dist/esm/react.d.ts +40 -0
  81. package/dist/esm/react.js +47 -0
  82. package/package.json +141 -4
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clearBreadcrumbs = exports.addBreadcrumb = exports.flush = exports.setUser = exports.captureException = void 0;
4
+ exports.installNodeHandlers = installNodeHandlers;
5
+ exports.installNodeBreadcrumbs = installNodeBreadcrumbs;
6
+ exports.runWithBreadcrumbs = runWithBreadcrumbs;
7
+ exports.init = init;
8
+ exports.expressErrorHandler = expressErrorHandler;
9
+ /**
10
+ * aissue/node: Node.js servers and scripts, including Express 4/5.
11
+ *
12
+ * import { init, expressErrorHandler } from 'aissue/node';
13
+ * init(); // reads AISSUE_API_KEY / AISSUE_BASE_URL
14
+ * ...
15
+ * app.use(expressErrorHandler()); // after your routes
16
+ *
17
+ * Captures uncaught exceptions (then exits like Node would) and unhandled rejections, and records
18
+ * breadcrumbs (console, fetch, http/https requests), kept per incoming request.
19
+ */
20
+ const breadcrumbs_js_1 = require("./core/breadcrumbs.js");
21
+ const client_js_1 = require("./core/client.js");
22
+ const instrument_node_js_1 = require("./core/instrument-node.js");
23
+ const hub_js_1 = require("./core/hub.js");
24
+ const event_js_1 = require("./core/event.js");
25
+ const index_js_1 = require("./index.js");
26
+ var index_js_2 = require("./index.js");
27
+ Object.defineProperty(exports, "captureException", { enumerable: true, get: function () { return index_js_2.captureException; } });
28
+ Object.defineProperty(exports, "setUser", { enumerable: true, get: function () { return index_js_2.setUser; } });
29
+ Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return index_js_2.flush; } });
30
+ Object.defineProperty(exports, "addBreadcrumb", { enumerable: true, get: function () { return index_js_2.addBreadcrumb; } });
31
+ Object.defineProperty(exports, "clearBreadcrumbs", { enumerable: true, get: function () { return index_js_2.clearBreadcrumbs; } });
32
+ /** The global process, looked up dynamically so edge bundlers do not flag Node APIs. */
33
+ function nodeProcess() {
34
+ const p = globalThis.process;
35
+ if (p && typeof p.on === 'function' && typeof p.listeners === 'function' && typeof p.removeListener === 'function') {
36
+ return p;
37
+ }
38
+ return undefined;
39
+ }
40
+ const FLUSH_BEFORE_EXIT_MS = 2000;
41
+ /** Node's --unhandled-rejections mode ("throw" is the default since Node 15). */
42
+ function unhandledRejectionMode(p) {
43
+ let mode = 'throw';
44
+ const args = [...(p.execArgv || []), ...String(p.env?.NODE_OPTIONS || '').split(/\s+/)];
45
+ for (const arg of args) {
46
+ const m = /^--unhandled-rejections=(\S+)$/.exec(arg);
47
+ if (m)
48
+ mode = m[1];
49
+ }
50
+ return mode;
51
+ }
52
+ let exiting = false;
53
+ function onUncaughtException(error) {
54
+ const p = nodeProcess();
55
+ try {
56
+ (0, index_js_1.captureException)(error);
57
+ }
58
+ catch {
59
+ // ignore
60
+ }
61
+ if (!p)
62
+ return;
63
+ // Someone else handles uncaught exceptions: their handler decides whether to exit.
64
+ const others = p.listeners('uncaughtException').filter((l) => l !== onUncaughtException);
65
+ if (others.length > 0 || exiting)
66
+ return;
67
+ exiting = true;
68
+ // Send the event, then crash exactly like Node would without AIssue (message on stderr, exit code 1).
69
+ (0, index_js_1.flush)(FLUSH_BEFORE_EXIT_MS).then(() => {
70
+ removeHandlers(p);
71
+ setTimeout(() => {
72
+ throw error;
73
+ }, 0);
74
+ });
75
+ }
76
+ function onUnhandledRejection(reason) {
77
+ const p = nodeProcess();
78
+ try {
79
+ (0, index_js_1.captureException)(reason);
80
+ }
81
+ catch {
82
+ // ignore
83
+ }
84
+ if (!p)
85
+ return;
86
+ const others = p.listeners('unhandledRejection').filter((l) => l !== onUnhandledRejection);
87
+ if (others.length > 0 || exiting)
88
+ return;
89
+ // Listening for 'unhandledRejection' disables Node's default crash, so restore it.
90
+ const mode = unhandledRejectionMode(p);
91
+ if (mode === 'warn-with-error-code') {
92
+ p.exitCode = 1;
93
+ return;
94
+ }
95
+ if (mode !== 'throw')
96
+ return; // "strict" crashes via uncaughtException; "warn"/"none" never crash
97
+ exiting = true;
98
+ const error = reason instanceof Error
99
+ ? reason
100
+ : Object.assign(new Error('This error originated either by throwing inside of an async function without a catch block, ' +
101
+ 'or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "' +
102
+ safeString(reason) +
103
+ '".'), { code: 'ERR_UNHANDLED_REJECTION' });
104
+ (0, index_js_1.flush)(FLUSH_BEFORE_EXIT_MS).then(() => {
105
+ removeHandlers(p);
106
+ setTimeout(() => {
107
+ throw error;
108
+ }, 0);
109
+ });
110
+ }
111
+ function safeString(value) {
112
+ try {
113
+ return String(value);
114
+ }
115
+ catch {
116
+ return '[unprintable]';
117
+ }
118
+ }
119
+ function removeHandlers(p) {
120
+ p.removeListener('uncaughtException', onUncaughtException);
121
+ p.removeListener('unhandledRejection', onUnhandledRejection);
122
+ const installed = (0, hub_js_1.getHub)().installed;
123
+ installed.uncaughtException = false;
124
+ installed.unhandledRejection = false;
125
+ }
126
+ /** Install process-level handlers (idempotent). Exported for aissue/nextjs. */
127
+ function installNodeHandlers(options = {}) {
128
+ try {
129
+ const p = nodeProcess();
130
+ if (!p)
131
+ return;
132
+ const installed = (0, hub_js_1.getHub)().installed;
133
+ if (options.captureUncaughtExceptions !== false && !installed.uncaughtException) {
134
+ installed.uncaughtException = true;
135
+ p.on('uncaughtException', onUncaughtException);
136
+ }
137
+ if (options.captureUnhandledRejections !== false && !installed.unhandledRejection) {
138
+ installed.unhandledRejection = true;
139
+ p.on('unhandledRejection', onUnhandledRejection);
140
+ }
141
+ }
142
+ catch {
143
+ // never throw into the host app
144
+ }
145
+ }
146
+ /**
147
+ * Automatic Node breadcrumbs (console, fetch, http/https requests) and a separate breadcrumb buffer
148
+ * per incoming http(s) request. Idempotent; does nothing when the SDK is disabled. Exported for aissue/nextjs.
149
+ */
150
+ function installNodeBreadcrumbs() {
151
+ try {
152
+ const client = (0, hub_js_1.getHub)().client;
153
+ if (!client?.enabled || client.config.maxBreadcrumbs <= 0 || client.config.autoBreadcrumbs === false)
154
+ return;
155
+ (0, instrument_node_js_1.instrumentNode)();
156
+ }
157
+ catch {
158
+ // never throw into the host app
159
+ }
160
+ }
161
+ /**
162
+ * Run `fn` with its own, empty breadcrumb buffer, for work that is not an http request
163
+ * (queue jobs, cron tasks, custom servers). Incoming http(s) server requests get one automatically.
164
+ * Returns what `fn` returns.
165
+ */
166
+ function runWithBreadcrumbs(fn) {
167
+ return (0, breadcrumbs_js_1.runWithBreadcrumbScope)(fn);
168
+ }
169
+ /**
170
+ * Configure the SDK for Node.js and capture uncaught exceptions / unhandled rejections.
171
+ * Omitted options are read from AISSUE_API_KEY, AISSUE_BASE_URL (or AISSUE_DSN), AISSUE_ENVIRONMENT
172
+ * and the release env vars. Disabled by default when NODE_ENV is development or test.
173
+ */
174
+ function init(options = {}) {
175
+ try {
176
+ const client = (0, client_js_1.setupClient)(options, { runtime: 'server', platform: 'node' });
177
+ if (client?.enabled) {
178
+ installNodeHandlers(options);
179
+ installNodeBreadcrumbs();
180
+ }
181
+ }
182
+ catch {
183
+ // never throw into the host app
184
+ }
185
+ }
186
+ /**
187
+ * Express 4/5 error middleware. Add it after your routes and before other error handlers:
188
+ * app.use(expressErrorHandler());
189
+ * Captures the error with path, method, filtered query and allowlisted headers, then calls next(err).
190
+ */
191
+ function expressErrorHandler(options = {}) {
192
+ // Four declared parameters: that is how Express recognises error middleware.
193
+ return function aissueErrorHandler(err, req, _res, next) {
194
+ try {
195
+ const status = (0, event_js_1.statusFromError)(err, 500);
196
+ const should = options.shouldHandleError
197
+ ? options.shouldHandleError(err, status)
198
+ : !(status >= 400 && status <= 499);
199
+ if (should) {
200
+ const r = (req || {});
201
+ const url = typeof r.originalUrl === 'string' ? r.originalUrl : typeof r.url === 'string' ? r.url : r.path;
202
+ let userId;
203
+ try {
204
+ userId = options.getUserId ? options.getUserId(req) : undefined;
205
+ }
206
+ catch {
207
+ userId = undefined;
208
+ }
209
+ (0, index_js_1.captureException)(err, {
210
+ errorCode: status,
211
+ path: url,
212
+ method: r.method,
213
+ headers: r.headers,
214
+ userId: userId ?? undefined,
215
+ });
216
+ }
217
+ }
218
+ catch {
219
+ // never throw into the host app
220
+ }
221
+ next(err);
222
+ };
223
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * aissue/react: error boundary for React 17-19 (and a re-export of the browser init).
3
+ *
4
+ * import { init, AIssueErrorBoundary } from 'aissue/react';
5
+ * init({ apiKey: '...', baseUrl: 'https://aissue.example.com' });
6
+ * <AIssueErrorBoundary fallback={<p>Something went wrong.</p>}><App /></AIssueErrorBoundary>
7
+ */
8
+ import * as React from 'react';
9
+ export { init } from './browser.js';
10
+ export type { BrowserOptions } from './browser.js';
11
+ export { captureException, setUser, flush, addBreadcrumb, clearBreadcrumbs } from './index.js';
12
+ export type { AIssueEvent, AIssueOptions, AutoBreadcrumbsOptions, Breadcrumb, BreadcrumbInput, CaptureContext, StackFrame, User, } from './index.js';
13
+ export interface FallbackProps {
14
+ error: unknown;
15
+ /** Clear the error and render the children again. */
16
+ reset: () => void;
17
+ }
18
+ export interface AIssueErrorBoundaryProps {
19
+ children?: React.ReactNode;
20
+ /** Rendered instead of the children after an error. A function receives { error, reset }. */
21
+ fallback?: React.ReactNode | ((props: FallbackProps) => React.ReactNode);
22
+ /** Called after the error was captured. */
23
+ onError?: (error: unknown, info: {
24
+ componentStack: string;
25
+ }) => void;
26
+ }
27
+ interface AIssueErrorBoundaryState {
28
+ hasError: boolean;
29
+ error: unknown;
30
+ }
31
+ /** Catches render errors in its subtree, sends them to AIssue and renders `fallback`. */
32
+ export declare class AIssueErrorBoundary extends React.Component<AIssueErrorBoundaryProps, AIssueErrorBoundaryState> {
33
+ state: AIssueErrorBoundaryState;
34
+ static getDerivedStateFromError(error: unknown): AIssueErrorBoundaryState;
35
+ componentDidCatch(error: unknown, info: {
36
+ componentStack?: string | null;
37
+ }): void;
38
+ reset: () => void;
39
+ render(): React.ReactNode;
40
+ }
@@ -0,0 +1,90 @@
1
+ "use client";
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.AIssueErrorBoundary = exports.clearBreadcrumbs = exports.addBreadcrumb = exports.flush = exports.setUser = exports.captureException = exports.init = void 0;
38
+ /**
39
+ * aissue/react: error boundary for React 17-19 (and a re-export of the browser init).
40
+ *
41
+ * import { init, AIssueErrorBoundary } from 'aissue/react';
42
+ * init({ apiKey: '...', baseUrl: 'https://aissue.example.com' });
43
+ * <AIssueErrorBoundary fallback={<p>Something went wrong.</p>}><App /></AIssueErrorBoundary>
44
+ */
45
+ const React = __importStar(require("react"));
46
+ const client_js_1 = require("./core/client.js");
47
+ var browser_js_1 = require("./browser.js");
48
+ Object.defineProperty(exports, "init", { enumerable: true, get: function () { return browser_js_1.init; } });
49
+ var index_js_1 = require("./index.js");
50
+ Object.defineProperty(exports, "captureException", { enumerable: true, get: function () { return index_js_1.captureException; } });
51
+ Object.defineProperty(exports, "setUser", { enumerable: true, get: function () { return index_js_1.setUser; } });
52
+ Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return index_js_1.flush; } });
53
+ Object.defineProperty(exports, "addBreadcrumb", { enumerable: true, get: function () { return index_js_1.addBreadcrumb; } });
54
+ Object.defineProperty(exports, "clearBreadcrumbs", { enumerable: true, get: function () { return index_js_1.clearBreadcrumbs; } });
55
+ const MAX_COMPONENT_STACK = 8000;
56
+ /** Catches render errors in its subtree, sends them to AIssue and renders `fallback`. */
57
+ class AIssueErrorBoundary extends React.Component {
58
+ constructor() {
59
+ super(...arguments);
60
+ this.state = { hasError: false, error: null };
61
+ this.reset = () => {
62
+ this.setState({ hasError: false, error: null });
63
+ };
64
+ }
65
+ static getDerivedStateFromError(error) {
66
+ return { hasError: true, error };
67
+ }
68
+ componentDidCatch(error, info) {
69
+ const componentStack = (info && typeof info.componentStack === 'string' ? info.componentStack : '').slice(0, MAX_COMPONENT_STACK);
70
+ // The component stack is context, not frames: it goes in request_data.context and the traceback text.
71
+ (0, client_js_1.captureWithExtras)(error, componentStack ? { extra: { componentStack } } : undefined, componentStack ? { tracebackSuffix: `\n\nReact component stack:${componentStack}` } : undefined);
72
+ try {
73
+ this.props.onError?.(error, { componentStack });
74
+ }
75
+ catch {
76
+ // a broken onError must not break the boundary
77
+ }
78
+ }
79
+ render() {
80
+ if (this.state.hasError) {
81
+ const { fallback } = this.props;
82
+ if (typeof fallback === 'function') {
83
+ return fallback({ error: this.state.error, reset: this.reset }) ?? null;
84
+ }
85
+ return fallback ?? null;
86
+ }
87
+ return this.props.children ?? null;
88
+ }
89
+ }
90
+ exports.AIssueErrorBoundary = AIssueErrorBoundary;
@@ -0,0 +1,16 @@
1
+ import type { AIssueOptions } from './core/types.js';
2
+ export { captureException, setUser, flush, addBreadcrumb, clearBreadcrumbs } from './index.js';
3
+ export type { AIssueEvent, AIssueOptions, AutoBreadcrumbsOptions, Breadcrumb, BreadcrumbInput, CaptureContext, StackFrame, User, } from './index.js';
4
+ /** Browser options: an API key and the AIssue host (or a DSN) are required. */
5
+ export type BrowserOptions = AIssueOptions & ({
6
+ apiKey: string;
7
+ baseUrl: string;
8
+ } | {
9
+ dsn: string;
10
+ });
11
+ /**
12
+ * Configure the SDK in the browser, capture uncaught errors and unhandled rejections and record
13
+ * automatic breadcrumbs (see `autoBreadcrumbs`).
14
+ * Does nothing when called outside a browser (e.g. during server-side rendering).
15
+ */
16
+ export declare function init(options: BrowserOptions): void;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * aissue/browser: plain browser apps (and the base for aissue/react).
3
+ *
4
+ * import { init } from 'aissue/browser';
5
+ * init({ apiKey: '...', baseUrl: 'https://aissue.example.com' });
6
+ *
7
+ * Captures uncaught errors (window "error") and unhandled promise rejections automatically, and
8
+ * records breadcrumbs (console, clicks, fetch / XHR, navigation) that are sent with each event.
9
+ */
10
+ import { captureWithExtras, setupClient } from './core/client.js';
11
+ import { instrumentBrowser } from './core/instrument-browser.js';
12
+ import { isBrowser } from './core/env.js';
13
+ import { getHub } from './core/hub.js';
14
+ export { captureException, setUser, flush, addBreadcrumb, clearBreadcrumbs } from './index.js';
15
+ function onWindowError(event) {
16
+ if (event.error !== undefined && event.error !== null) {
17
+ captureWithExtras(event.error);
18
+ return;
19
+ }
20
+ // No error object (e.g. cross-origin "Script error."): rebuild what we can from the event.
21
+ if (typeof event.message !== 'string' || !event.message)
22
+ return;
23
+ const filename = typeof event.filename === 'string' ? event.filename : '';
24
+ const location = filename ? `\n at ${filename}:${Number(event.lineno) || 0}:${Number(event.colno) || 0}` : '';
25
+ captureWithExtras({ name: 'Error', message: event.message, stack: `Error: ${event.message}${location}` });
26
+ }
27
+ function installGlobalHandlers() {
28
+ const hub = getHub();
29
+ if (hub.installed.browser)
30
+ return;
31
+ const w = globalThis
32
+ .window;
33
+ if (!w || typeof w.addEventListener !== 'function')
34
+ return;
35
+ hub.installed.browser = true;
36
+ w.addEventListener('error', (event) => {
37
+ try {
38
+ onWindowError(event);
39
+ }
40
+ catch {
41
+ // never throw into the host app
42
+ }
43
+ });
44
+ w.addEventListener('unhandledrejection', (event) => {
45
+ try {
46
+ captureWithExtras(event ? event.reason : undefined);
47
+ }
48
+ catch {
49
+ // never throw into the host app
50
+ }
51
+ });
52
+ }
53
+ /**
54
+ * Configure the SDK in the browser, capture uncaught errors and unhandled rejections and record
55
+ * automatic breadcrumbs (see `autoBreadcrumbs`).
56
+ * Does nothing when called outside a browser (e.g. during server-side rendering).
57
+ */
58
+ export function init(options) {
59
+ try {
60
+ if (!isBrowser())
61
+ return;
62
+ const client = setupClient(options, { runtime: 'browser', platform: 'browser' });
63
+ installGlobalHandlers();
64
+ if (client?.enabled && client.config.maxBreadcrumbs > 0 && client.config.autoBreadcrumbs !== false) {
65
+ instrumentBrowser();
66
+ }
67
+ }
68
+ catch {
69
+ // never throw into the host app
70
+ }
71
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};