aissue 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/README.md +390 -2
- package/dist/cjs/browser.d.ts +16 -0
- package/dist/cjs/browser.js +80 -0
- package/dist/cjs/core/breadcrumbs.d.ts +48 -0
- package/dist/cjs/core/breadcrumbs.js +313 -0
- package/dist/cjs/core/client.d.ts +54 -0
- package/dist/cjs/core/client.js +293 -0
- package/dist/cjs/core/env.d.ts +19 -0
- package/dist/cjs/core/env.js +71 -0
- package/dist/cjs/core/event.d.ts +35 -0
- package/dist/cjs/core/event.js +187 -0
- package/dist/cjs/core/hub.d.ts +20 -0
- package/dist/cjs/core/hub.js +21 -0
- package/dist/cjs/core/instrument-browser.d.ts +16 -0
- package/dist/cjs/core/instrument-browser.js +208 -0
- package/dist/cjs/core/instrument-node.d.ts +5 -0
- package/dist/cjs/core/instrument-node.js +250 -0
- package/dist/cjs/core/instrument.d.ts +12 -0
- package/dist/cjs/core/instrument.js +137 -0
- package/dist/cjs/core/privacy.d.ts +25 -0
- package/dist/cjs/core/privacy.js +269 -0
- package/dist/cjs/core/stack.d.ts +13 -0
- package/dist/cjs/core/stack.js +147 -0
- package/dist/cjs/core/transport.d.ts +31 -0
- package/dist/cjs/core/transport.js +154 -0
- package/dist/cjs/core/types.d.ts +149 -0
- package/dist/cjs/core/types.js +2 -0
- package/dist/cjs/core/version.d.ts +2 -0
- package/dist/cjs/core/version.js +6 -0
- package/dist/cjs/index.d.ts +27 -0
- package/dist/cjs/index.js +83 -0
- package/dist/cjs/nextjs/client.d.ts +10 -0
- package/dist/cjs/nextjs/client.js +99 -0
- package/dist/cjs/nextjs/index.d.ts +31 -0
- package/dist/cjs/nextjs/index.js +99 -0
- package/dist/cjs/node.d.ts +48 -0
- package/dist/cjs/node.js +223 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/react.d.ts +40 -0
- package/dist/cjs/react.js +90 -0
- package/dist/esm/browser.d.ts +16 -0
- package/dist/esm/browser.js +71 -0
- package/dist/esm/cli.d.ts +2 -0
- package/dist/esm/cli.js +386 -0
- package/dist/esm/core/breadcrumbs.d.ts +48 -0
- package/dist/esm/core/breadcrumbs.js +296 -0
- package/dist/esm/core/client.d.ts +54 -0
- package/dist/esm/core/client.js +285 -0
- package/dist/esm/core/env.d.ts +19 -0
- package/dist/esm/core/env.js +62 -0
- package/dist/esm/core/event.d.ts +35 -0
- package/dist/esm/core/event.js +179 -0
- package/dist/esm/core/hub.d.ts +20 -0
- package/dist/esm/core/hub.js +17 -0
- package/dist/esm/core/instrument-browser.d.ts +16 -0
- package/dist/esm/core/instrument-browser.js +203 -0
- package/dist/esm/core/instrument-node.d.ts +5 -0
- package/dist/esm/core/instrument-node.js +214 -0
- package/dist/esm/core/instrument.d.ts +12 -0
- package/dist/esm/core/instrument.js +132 -0
- package/dist/esm/core/privacy.d.ts +25 -0
- package/dist/esm/core/privacy.js +257 -0
- package/dist/esm/core/stack.d.ts +13 -0
- package/dist/esm/core/stack.js +140 -0
- package/dist/esm/core/transport.d.ts +31 -0
- package/dist/esm/core/transport.js +149 -0
- package/dist/esm/core/types.d.ts +149 -0
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/core/version.d.ts +2 -0
- package/dist/esm/core/version.js +3 -0
- package/dist/esm/index.d.ts +27 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/nextjs/client.d.ts +10 -0
- package/dist/esm/nextjs/client.js +90 -0
- package/dist/esm/nextjs/index.d.ts +31 -0
- package/dist/esm/nextjs/index.js +88 -0
- package/dist/esm/node.d.ts +48 -0
- package/dist/esm/node.js +210 -0
- package/dist/esm/react.d.ts +40 -0
- package/dist/esm/react.js +47 -0
- package/package.json +141 -4
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export const MAX_FRAMES = 50;
|
|
2
|
+
const MAX_STACK_LINES = 1000;
|
|
3
|
+
const EXTENSION_RE = /^(?:chrome|moz|safari|safari-web|ms-browser)-extension:\/\//i;
|
|
4
|
+
/** Frames from browser extensions (and Safari's masked extension URLs). */
|
|
5
|
+
export function isExtensionUrl(filename) {
|
|
6
|
+
return EXTENSION_RE.test(filename) || filename.startsWith('webkit-masked-url:');
|
|
7
|
+
}
|
|
8
|
+
/** false for library code, runtime internals and browser extensions. */
|
|
9
|
+
export function isInApp(filename) {
|
|
10
|
+
if (!filename)
|
|
11
|
+
return false;
|
|
12
|
+
if (/[\\/]node_modules[\\/]/.test(filename))
|
|
13
|
+
return false;
|
|
14
|
+
if (filename.startsWith('node:') || filename.startsWith('internal/'))
|
|
15
|
+
return false;
|
|
16
|
+
if (filename === '<anonymous>' || filename === 'native' || filename === '[native code]')
|
|
17
|
+
return false;
|
|
18
|
+
if (/^index \d+$/.test(filename))
|
|
19
|
+
return false; // e.g. "at Promise.all (index 0)"
|
|
20
|
+
if (isExtensionUrl(filename))
|
|
21
|
+
return false;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function normalizeFilename(filename) {
|
|
25
|
+
let name = filename.trim();
|
|
26
|
+
if (name.startsWith('file://')) {
|
|
27
|
+
try {
|
|
28
|
+
name = decodeURIComponent(name.slice('file://'.length));
|
|
29
|
+
if (/^\/[A-Za-z]:[\\/]/.test(name))
|
|
30
|
+
name = name.slice(1); // file:///C:/app -> C:/app
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
name = name.slice('file://'.length);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (/^https?:\/\//i.test(name)) {
|
|
37
|
+
// Script URLs: drop query strings / fragments (cache busters, occasionally tokens).
|
|
38
|
+
name = name.replace(/[?#].*$/, '');
|
|
39
|
+
}
|
|
40
|
+
return name.length > 1024 ? name.slice(0, 1024) : name;
|
|
41
|
+
}
|
|
42
|
+
function splitLocation(location) {
|
|
43
|
+
const m = /^(.*?):(\d+)(?::(\d+))?$/.exec(location.trim());
|
|
44
|
+
if (!m)
|
|
45
|
+
return { filename: location.trim() };
|
|
46
|
+
return {
|
|
47
|
+
filename: m[1],
|
|
48
|
+
lineno: parseInt(m[2], 10),
|
|
49
|
+
colno: m[3] !== undefined ? parseInt(m[3], 10) : undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function makeFrame(fn, location) {
|
|
53
|
+
const filename = normalizeFilename(location.filename);
|
|
54
|
+
const frame = {
|
|
55
|
+
filename,
|
|
56
|
+
function: (fn || '<anonymous>').slice(0, 512),
|
|
57
|
+
in_app: isInApp(filename),
|
|
58
|
+
};
|
|
59
|
+
if (location.lineno !== undefined && !isNaN(location.lineno))
|
|
60
|
+
frame.lineno = location.lineno;
|
|
61
|
+
if (location.colno !== undefined && !isNaN(location.colno))
|
|
62
|
+
frame.colno = location.colno;
|
|
63
|
+
return frame;
|
|
64
|
+
}
|
|
65
|
+
const V8_FRAME = /^\s+at\s+(.+?)\s*$/;
|
|
66
|
+
/** " at fn (file:1:2)", " at file:1:2", " at async fn (file:1:2)", " at new X (...)" */
|
|
67
|
+
function parseV8Line(line) {
|
|
68
|
+
const match = V8_FRAME.exec(line);
|
|
69
|
+
if (!match)
|
|
70
|
+
return null;
|
|
71
|
+
const rest = match[1];
|
|
72
|
+
let fn = '';
|
|
73
|
+
let location = rest;
|
|
74
|
+
if (rest.endsWith(')')) {
|
|
75
|
+
// Find the "(" matching the final ")"; locations can contain parentheses (eval frames).
|
|
76
|
+
let depth = 0;
|
|
77
|
+
for (let i = rest.length - 1; i >= 0; i--) {
|
|
78
|
+
const c = rest[i];
|
|
79
|
+
if (c === ')')
|
|
80
|
+
depth++;
|
|
81
|
+
else if (c === '(') {
|
|
82
|
+
depth--;
|
|
83
|
+
if (depth === 0) {
|
|
84
|
+
fn = rest.slice(0, i).trim();
|
|
85
|
+
location = rest.slice(i + 1, -1);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (fn.startsWith('async '))
|
|
92
|
+
fn = fn.slice(6).trim();
|
|
93
|
+
if (!fn && location.startsWith('async '))
|
|
94
|
+
location = location.slice(6).trim();
|
|
95
|
+
if (location.startsWith('eval at ')) {
|
|
96
|
+
// "eval at fn (file.js:1:2), <anonymous>:1:1" -> use the file that called eval
|
|
97
|
+
const inner = /\(([^()]*:\d+:\d+)\)/.exec(location);
|
|
98
|
+
location = inner ? inner[1] : '<anonymous>';
|
|
99
|
+
}
|
|
100
|
+
return makeFrame(fn, splitLocation(location));
|
|
101
|
+
}
|
|
102
|
+
/** Firefox / Safari: "fn@file:1:2", "@file:1:2", "fn@[native code]" */
|
|
103
|
+
function parseGeckoLine(line) {
|
|
104
|
+
const trimmed = line.trim();
|
|
105
|
+
const at = trimmed.indexOf('@');
|
|
106
|
+
if (at === -1)
|
|
107
|
+
return null;
|
|
108
|
+
const fn = trimmed.slice(0, at);
|
|
109
|
+
let location = trimmed.slice(at + 1);
|
|
110
|
+
if (!location)
|
|
111
|
+
return null;
|
|
112
|
+
// Firefox eval / Function frames: "file.js line 2 > eval:1:5" -> file.js:2
|
|
113
|
+
const evalMatch = /^(.*?) line (\d+)(?: > [\w ]+)+:\d+:\d+$/.exec(location);
|
|
114
|
+
if (evalMatch)
|
|
115
|
+
location = `${evalMatch[1]}:${evalMatch[2]}`;
|
|
116
|
+
return makeFrame(fn, splitLocation(location));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parse error.stack (V8, Firefox or Safari format) into frames,
|
|
120
|
+
* oldest call first and innermost (where it failed) last. At most 50 frames (the innermost ones).
|
|
121
|
+
*/
|
|
122
|
+
export function parseStack(stack) {
|
|
123
|
+
if (typeof stack !== 'string' || !stack)
|
|
124
|
+
return [];
|
|
125
|
+
const lines = stack.split('\n', MAX_STACK_LINES);
|
|
126
|
+
const isV8 = lines.some((l) => V8_FRAME.test(l));
|
|
127
|
+
const frames = [];
|
|
128
|
+
for (const line of lines) {
|
|
129
|
+
const frame = isV8 ? parseV8Line(line) : parseGeckoLine(line);
|
|
130
|
+
if (frame)
|
|
131
|
+
frames.push(frame);
|
|
132
|
+
}
|
|
133
|
+
// Runtimes print the innermost frame first; the protocol wants it last.
|
|
134
|
+
frames.reverse();
|
|
135
|
+
return frames.length > MAX_FRAMES ? frames.slice(frames.length - MAX_FRAMES) : frames;
|
|
136
|
+
}
|
|
137
|
+
/** True when the stack looks like V8's, which already starts with "Type: message". */
|
|
138
|
+
export function isV8Stack(stack) {
|
|
139
|
+
return /^\s+at\s/m.test(stack);
|
|
140
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type TransportMode = 'browser' | 'server';
|
|
2
|
+
export interface TransportOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
mode: TransportMode;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
log: (message: string) => void;
|
|
8
|
+
warn: (message: string) => void;
|
|
9
|
+
}
|
|
10
|
+
/** Parse Retry-After (seconds or an HTTP date) into milliseconds. */
|
|
11
|
+
export declare function parseRetryAfter(value: string | null | undefined, now?: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Sends JSON bodies to POST {baseUrl}/api/errors/. Never throws, never retries, never queues:
|
|
14
|
+
* events are dropped on failure (ingestion protocol "Responses").
|
|
15
|
+
*/
|
|
16
|
+
export declare class Transport {
|
|
17
|
+
private readonly options;
|
|
18
|
+
private readonly inflight;
|
|
19
|
+
private pausedUntil;
|
|
20
|
+
private warnedUnauthorized;
|
|
21
|
+
readonly url: string;
|
|
22
|
+
constructor(options: TransportOptions);
|
|
23
|
+
/** True while the server asked us to back off (429 Retry-After). */
|
|
24
|
+
isPaused(now?: number): boolean;
|
|
25
|
+
get pending(): number;
|
|
26
|
+
send(body: string): void;
|
|
27
|
+
private request;
|
|
28
|
+
private handleResponse;
|
|
29
|
+
/** Resolves true when every in-flight send finished, false when the timeout passed first. */
|
|
30
|
+
flush(timeoutMs?: number): Promise<boolean>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { byteLength } from './event.js';
|
|
2
|
+
import { SDK_NAME, SDK_VERSION } from './version.js';
|
|
3
|
+
/** Browsers refuse keepalive requests with bodies over 64 KB. */
|
|
4
|
+
const KEEPALIVE_MAX_BYTES = 60000;
|
|
5
|
+
const DEFAULT_RETRY_AFTER_SECONDS = 60;
|
|
6
|
+
/** Parse Retry-After (seconds or an HTTP date) into milliseconds. */
|
|
7
|
+
export function parseRetryAfter(value, now = Date.now()) {
|
|
8
|
+
if (value) {
|
|
9
|
+
const seconds = Number(value.trim());
|
|
10
|
+
if (Number.isFinite(seconds) && seconds >= 0)
|
|
11
|
+
return seconds * 1000;
|
|
12
|
+
const date = Date.parse(value);
|
|
13
|
+
if (!isNaN(date))
|
|
14
|
+
return Math.max(0, date - now);
|
|
15
|
+
}
|
|
16
|
+
return DEFAULT_RETRY_AFTER_SECONDS * 1000;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sends JSON bodies to POST {baseUrl}/api/errors/. Never throws, never retries, never queues:
|
|
20
|
+
* events are dropped on failure (ingestion protocol "Responses").
|
|
21
|
+
*/
|
|
22
|
+
export class Transport {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.inflight = new Set();
|
|
26
|
+
this.pausedUntil = 0;
|
|
27
|
+
this.warnedUnauthorized = false;
|
|
28
|
+
const base = options.baseUrl.replace(/\/+$/, '');
|
|
29
|
+
this.url =
|
|
30
|
+
options.mode === 'browser'
|
|
31
|
+
? `${base}/api/errors/?api_key=${encodeURIComponent(options.apiKey)}`
|
|
32
|
+
: `${base}/api/errors/`;
|
|
33
|
+
}
|
|
34
|
+
/** True while the server asked us to back off (429 Retry-After). */
|
|
35
|
+
isPaused(now = Date.now()) {
|
|
36
|
+
return now < this.pausedUntil;
|
|
37
|
+
}
|
|
38
|
+
get pending() {
|
|
39
|
+
return this.inflight.size;
|
|
40
|
+
}
|
|
41
|
+
send(body) {
|
|
42
|
+
try {
|
|
43
|
+
if (this.isPaused()) {
|
|
44
|
+
this.options.log('rate limited by the server; dropping event');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const fetchFn = globalThis.fetch;
|
|
48
|
+
if (typeof fetchFn !== 'function') {
|
|
49
|
+
this.options.log('fetch is not available; dropping event');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const promise = this.request(fetchFn, body)
|
|
53
|
+
.catch((error) => {
|
|
54
|
+
this.options.log(`failed to send event: ${error instanceof Error ? error.name : 'error'}`);
|
|
55
|
+
})
|
|
56
|
+
.then(() => {
|
|
57
|
+
this.inflight.delete(promise);
|
|
58
|
+
});
|
|
59
|
+
this.inflight.add(promise);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// never throw into the host app
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async request(fetchFn, body) {
|
|
66
|
+
const { mode } = this.options;
|
|
67
|
+
const init = { method: 'POST', body };
|
|
68
|
+
if (mode === 'browser') {
|
|
69
|
+
// text/plain + key in the query string = a "simple" CORS request (no preflight).
|
|
70
|
+
init.headers = { 'Content-Type': 'text/plain;charset=UTF-8' };
|
|
71
|
+
init.keepalive = byteLength(body) <= KEEPALIVE_MAX_BYTES;
|
|
72
|
+
init.credentials = 'omit';
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
init.headers = {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
'X-API-Key': this.options.apiKey,
|
|
78
|
+
'User-Agent': `${SDK_NAME}/${SDK_VERSION}`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
let timer;
|
|
82
|
+
const Controller = globalThis.AbortController;
|
|
83
|
+
if (Controller) {
|
|
84
|
+
const controller = new Controller();
|
|
85
|
+
init.signal = controller.signal;
|
|
86
|
+
timer = setTimeout(() => controller.abort(), this.options.timeoutMs ?? 5000);
|
|
87
|
+
timer.unref?.();
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const response = await fetchFn(this.url, init);
|
|
91
|
+
this.handleResponse(response);
|
|
92
|
+
try {
|
|
93
|
+
response.body?.cancel?.();
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// ignore
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
if (timer !== undefined)
|
|
101
|
+
clearTimeout(timer);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
handleResponse(response) {
|
|
105
|
+
const { status } = response;
|
|
106
|
+
if (status >= 200 && status < 300) {
|
|
107
|
+
this.options.log(`event sent (${status})`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (status === 429) {
|
|
111
|
+
let retryAfter = null;
|
|
112
|
+
try {
|
|
113
|
+
retryAfter = response.headers?.get('Retry-After') ?? null;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
retryAfter = null;
|
|
117
|
+
}
|
|
118
|
+
const ms = parseRetryAfter(retryAfter);
|
|
119
|
+
this.pausedUntil = Date.now() + ms;
|
|
120
|
+
this.options.warn(`AIssue rate limit reached; pausing for ${Math.round(ms / 1000)}s`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (status === 401) {
|
|
124
|
+
if (!this.warnedUnauthorized) {
|
|
125
|
+
this.warnedUnauthorized = true;
|
|
126
|
+
this.options.warn('AIssue rejected the API key (401). Check apiKey / AISSUE_API_KEY.');
|
|
127
|
+
}
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.options.log(`event dropped by the server (${status})`);
|
|
131
|
+
}
|
|
132
|
+
/** Resolves true when every in-flight send finished, false when the timeout passed first. */
|
|
133
|
+
flush(timeoutMs = 2000) {
|
|
134
|
+
if (this.inflight.size === 0)
|
|
135
|
+
return Promise.resolve(true);
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
|
+
const timer = setTimeout(() => resolve(false), Math.max(0, timeoutMs));
|
|
138
|
+
const settleAll = () => {
|
|
139
|
+
if (this.inflight.size === 0) {
|
|
140
|
+
clearTimeout(timer);
|
|
141
|
+
resolve(true);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
Promise.all(Array.from(this.inflight)).then(settleAll, settleAll);
|
|
145
|
+
};
|
|
146
|
+
settleAll();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/** Runtime that produced the event (see the ingestion protocol). */
|
|
2
|
+
export type Platform = 'node' | 'browser' | 'javascript';
|
|
3
|
+
/** One stack frame. Frames are ordered oldest call first, innermost (where it failed) last. */
|
|
4
|
+
export interface StackFrame {
|
|
5
|
+
filename: string;
|
|
6
|
+
function: string;
|
|
7
|
+
lineno?: number;
|
|
8
|
+
colno?: number;
|
|
9
|
+
/** false for library code (node_modules), runtime internals and browser extensions. */
|
|
10
|
+
in_app: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** The JSON body sent to `POST {baseUrl}/api/errors/` (ingestion protocol v1). */
|
|
13
|
+
export interface AIssueEvent {
|
|
14
|
+
/** HTTP status the error produced. Browser-side errors send 0. */
|
|
15
|
+
error_code: number;
|
|
16
|
+
/** Request path without the query string. */
|
|
17
|
+
path?: string;
|
|
18
|
+
method?: string;
|
|
19
|
+
/** Raw stack text. */
|
|
20
|
+
traceback: string;
|
|
21
|
+
exception: {
|
|
22
|
+
type: string;
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
25
|
+
frames: StackFrame[];
|
|
26
|
+
release?: string;
|
|
27
|
+
environment?: string;
|
|
28
|
+
platform: Platform;
|
|
29
|
+
sdk: {
|
|
30
|
+
name: string;
|
|
31
|
+
version: string;
|
|
32
|
+
};
|
|
33
|
+
/** Opaque identifier only, never an email or a name. */
|
|
34
|
+
user_id?: string;
|
|
35
|
+
request_data?: {
|
|
36
|
+
/** Query parameters. Values under sensitive-looking keys are replaced with "[Filtered]". */
|
|
37
|
+
GET?: Record<string, string[]>;
|
|
38
|
+
/** Extra context (e.g. Next.js routePath, React componentStack). Sensitive keys are filtered. */
|
|
39
|
+
context?: Record<string, unknown>;
|
|
40
|
+
};
|
|
41
|
+
/** Allowlisted request headers only. Never Cookie or Authorization. */
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
/** What happened before the error, oldest first (at most 100). */
|
|
44
|
+
breadcrumbs?: Breadcrumb[];
|
|
45
|
+
}
|
|
46
|
+
export type BreadcrumbType = 'default' | 'http' | 'navigation' | 'ui' | 'log' | 'query';
|
|
47
|
+
export type BreadcrumbLevel = 'debug' | 'info' | 'warning' | 'error';
|
|
48
|
+
/** One breadcrumb as sent in an event (ingestion protocol `breadcrumbs`). */
|
|
49
|
+
export interface Breadcrumb {
|
|
50
|
+
/** ISO-8601 UTC, e.g. "2026-01-31T12:00:00.000Z". */
|
|
51
|
+
timestamp: string;
|
|
52
|
+
type: BreadcrumbType;
|
|
53
|
+
category: string;
|
|
54
|
+
level: BreadcrumbLevel;
|
|
55
|
+
/** At most 1000 characters. */
|
|
56
|
+
message: string;
|
|
57
|
+
/** Flat: string / number / boolean values only, at most 20 keys. */
|
|
58
|
+
data: Record<string, string | number | boolean>;
|
|
59
|
+
}
|
|
60
|
+
/** What addBreadcrumb accepts. Everything is optional, validated and filtered with the privacy rules. */
|
|
61
|
+
export interface BreadcrumbInput {
|
|
62
|
+
/** Date, ms (or s) since the epoch, or an ISO string. Default: now. */
|
|
63
|
+
timestamp?: string | number | Date;
|
|
64
|
+
/** 'default' | 'http' | 'navigation' | 'ui' | 'log' | 'query'. Default 'default'. */
|
|
65
|
+
type?: BreadcrumbType | string;
|
|
66
|
+
/** e.g. "auth", "cart". Default "manual" (or the type). */
|
|
67
|
+
category?: string;
|
|
68
|
+
/** 'debug' | 'info' | 'warning' | 'error' ('warn' is accepted). Default 'info'. */
|
|
69
|
+
level?: BreadcrumbLevel | string;
|
|
70
|
+
message?: string;
|
|
71
|
+
/** Flat object of strings / numbers / booleans (other values are stringified), at most 20 keys. */
|
|
72
|
+
data?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/** Turn individual automatic breadcrumb sources off (all are on by default). */
|
|
75
|
+
export interface AutoBreadcrumbsOptions {
|
|
76
|
+
/** console.log / info / warn / error. */
|
|
77
|
+
console?: boolean;
|
|
78
|
+
/** Browser: clicks (element selector and short text, never input values). */
|
|
79
|
+
clicks?: boolean;
|
|
80
|
+
/** Outgoing fetch requests (browser and Node). */
|
|
81
|
+
fetch?: boolean;
|
|
82
|
+
/** Browser: XMLHttpRequest. */
|
|
83
|
+
xhr?: boolean;
|
|
84
|
+
/** Browser: history.pushState / replaceState / popstate. */
|
|
85
|
+
navigation?: boolean;
|
|
86
|
+
/** Node: outgoing http / https requests. */
|
|
87
|
+
http?: boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface AIssueOptions {
|
|
90
|
+
/** Domain API key. Server-side falls back to the AISSUE_API_KEY env var. */
|
|
91
|
+
apiKey?: string;
|
|
92
|
+
/** Your AIssue host, e.g. "https://aissue.example.com". Server-side falls back to AISSUE_BASE_URL. */
|
|
93
|
+
baseUrl?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Alternative to apiKey + baseUrl: "https://<api key>@<aissue host>/<domain id>"
|
|
96
|
+
* (the DSN shown on the domain page). Server-side falls back to AISSUE_DSN.
|
|
97
|
+
*/
|
|
98
|
+
dsn?: string;
|
|
99
|
+
/** Deployed version, ideally a git commit SHA. Server-side it is detected from common platform env vars. */
|
|
100
|
+
release?: string;
|
|
101
|
+
/** e.g. "production" or "staging". Server-side falls back to AISSUE_ENVIRONMENT, then NODE_ENV. */
|
|
102
|
+
environment?: string;
|
|
103
|
+
/** Defaults to false when NODE_ENV is "development" or "test", true otherwise. */
|
|
104
|
+
enabled?: boolean;
|
|
105
|
+
/** Inspect, modify or drop (return null) every event before it is sent. */
|
|
106
|
+
beforeSend?: (event: AIssueEvent) => AIssueEvent | null | undefined;
|
|
107
|
+
/** Errors whose message (or "Type: message") contains a string, or matches a RegExp, are not sent. */
|
|
108
|
+
ignoreErrors?: Array<string | RegExp>;
|
|
109
|
+
/** Client-side cap on events sent per minute by this process / page. Default 10. */
|
|
110
|
+
maxEventsPerMinute?: number;
|
|
111
|
+
/** Log what the SDK does to the console. */
|
|
112
|
+
debug?: boolean;
|
|
113
|
+
/** Breadcrumbs kept (and sent with each event). Default 50, at most 100; 0 disables breadcrumbs. */
|
|
114
|
+
maxBreadcrumbs?: number;
|
|
115
|
+
/** Inspect, modify or drop (return null) every breadcrumb before it is stored. */
|
|
116
|
+
beforeBreadcrumb?: (breadcrumb: Breadcrumb) => Breadcrumb | BreadcrumbInput | null | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Automatic breadcrumbs installed by aissue/browser and aissue/node. `false` turns them all off
|
|
119
|
+
* (addBreadcrumb still works); an object turns off individual sources.
|
|
120
|
+
*/
|
|
121
|
+
autoBreadcrumbs?: boolean | AutoBreadcrumbsOptions;
|
|
122
|
+
}
|
|
123
|
+
/** Anything that looks like request headers: a plain object, a Headers instance, or [name, value] pairs. */
|
|
124
|
+
export type HeadersInput = Record<string, string | string[] | number | undefined | null> | {
|
|
125
|
+
forEach(callback: (value: string, name: string) => void): void;
|
|
126
|
+
} | Array<[string, string]>;
|
|
127
|
+
/** Query parameters as a raw query string, URLSearchParams, or an object. */
|
|
128
|
+
export type QueryInput = string | {
|
|
129
|
+
forEach(callback: (value: string, name: string) => void): void;
|
|
130
|
+
} | Record<string, unknown>;
|
|
131
|
+
/** Optional details for captureException. Everything is filtered with the same privacy rules. */
|
|
132
|
+
export interface CaptureContext {
|
|
133
|
+
/** HTTP status the error produced (default 500 on servers, 0 in browsers). */
|
|
134
|
+
errorCode?: number;
|
|
135
|
+
/** Request path. A query string or fragment is stripped (the query is used as `query` if none is given). */
|
|
136
|
+
path?: string;
|
|
137
|
+
method?: string;
|
|
138
|
+
query?: QueryInput;
|
|
139
|
+
/** Only allowlisted headers are kept (User-Agent, Content-Type, Accept, Host, Origin, Referer, ...). */
|
|
140
|
+
headers?: HeadersInput;
|
|
141
|
+
/** Opaque user id for this event (overrides setUser). Never pass an email. */
|
|
142
|
+
userId?: string | number;
|
|
143
|
+
/** Extra context, sent as request_data.context. Sensitive-looking keys are filtered. */
|
|
144
|
+
extra?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
export interface User {
|
|
147
|
+
/** Opaque identifier only, never an email or a name. */
|
|
148
|
+
id: string | number;
|
|
149
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AIssueOptions, BreadcrumbInput, CaptureContext, User } from './core/types.js';
|
|
2
|
+
export type { AIssueEvent, AIssueOptions, AutoBreadcrumbsOptions, Breadcrumb, BreadcrumbInput, BreadcrumbLevel, BreadcrumbType, CaptureContext, HeadersInput, Platform, QueryInput, StackFrame, User, } from './core/types.js';
|
|
3
|
+
export { SDK_NAME, SDK_VERSION } from './core/version.js';
|
|
4
|
+
/**
|
|
5
|
+
* Configure the SDK. Server-side, omitted options are read from AISSUE_API_KEY, AISSUE_BASE_URL
|
|
6
|
+
* (or AISSUE_DSN), AISSUE_ENVIRONMENT and the release env vars. Calling init again replaces the config.
|
|
7
|
+
* Installs no global handlers: use aissue/browser or aissue/node for that.
|
|
8
|
+
*/
|
|
9
|
+
export declare function init(options?: AIssueOptions): void;
|
|
10
|
+
/** Send an error (or any thrown value) to AIssue. Never throws; does nothing before init(). */
|
|
11
|
+
export declare function captureException(error: unknown, context?: CaptureContext): void;
|
|
12
|
+
/**
|
|
13
|
+
* Attach an opaque user id to subsequent events (null clears it). Only the id is used: never pass
|
|
14
|
+
* an email or a name. On servers this is process-wide; prefer captureException(err, { userId }).
|
|
15
|
+
*/
|
|
16
|
+
export declare function setUser(user: User | null | undefined): void;
|
|
17
|
+
/** Wait for in-flight events. Resolves true when all were sent, false if `timeoutMs` (default 2000) passed. */
|
|
18
|
+
export declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Record something that happened (oldest breadcrumbs are dropped beyond `maxBreadcrumbs`). The
|
|
21
|
+
* breadcrumbs are sent with the next events. Message and data go through the privacy filters.
|
|
22
|
+
* Does nothing before init() or while the SDK is disabled. In Node, breadcrumbs added while handling
|
|
23
|
+
* an http request belong to that request only.
|
|
24
|
+
*/
|
|
25
|
+
export declare function addBreadcrumb(breadcrumb: BreadcrumbInput): void;
|
|
26
|
+
/** Forget the current breadcrumbs (in Node, inside a request: that request's breadcrumbs). */
|
|
27
|
+
export declare function clearBreadcrumbs(): void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* aissue: isomorphic core. Works in Node, browsers and edge runtimes.
|
|
3
|
+
*
|
|
4
|
+
* import { init, captureException } from 'aissue';
|
|
5
|
+
* init({ apiKey: '...', baseUrl: 'https://aissue.example.com' });
|
|
6
|
+
* captureException(error);
|
|
7
|
+
*
|
|
8
|
+
* Framework entry points add automatic capture: aissue/browser, aissue/react,
|
|
9
|
+
* aissue/node (incl. Express), aissue/nextjs and aissue/nextjs/client.
|
|
10
|
+
*/
|
|
11
|
+
import { clearCurrentBreadcrumbs, recordBreadcrumb } from './core/breadcrumbs.js';
|
|
12
|
+
import { setupClient } from './core/client.js';
|
|
13
|
+
import { getHub } from './core/hub.js';
|
|
14
|
+
export { SDK_NAME, SDK_VERSION } from './core/version.js';
|
|
15
|
+
/**
|
|
16
|
+
* Configure the SDK. Server-side, omitted options are read from AISSUE_API_KEY, AISSUE_BASE_URL
|
|
17
|
+
* (or AISSUE_DSN), AISSUE_ENVIRONMENT and the release env vars. Calling init again replaces the config.
|
|
18
|
+
* Installs no global handlers: use aissue/browser or aissue/node for that.
|
|
19
|
+
*/
|
|
20
|
+
export function init(options) {
|
|
21
|
+
setupClient(options);
|
|
22
|
+
}
|
|
23
|
+
/** Send an error (or any thrown value) to AIssue. Never throws; does nothing before init(). */
|
|
24
|
+
export function captureException(error, context) {
|
|
25
|
+
try {
|
|
26
|
+
getHub().client?.capture(error, context);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// never throw into the host app
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Attach an opaque user id to subsequent events (null clears it). Only the id is used: never pass
|
|
34
|
+
* an email or a name. On servers this is process-wide; prefer captureException(err, { userId }).
|
|
35
|
+
*/
|
|
36
|
+
export function setUser(user) {
|
|
37
|
+
try {
|
|
38
|
+
const id = user && user.id !== undefined && user.id !== null ? String(user.id) : undefined;
|
|
39
|
+
getHub().userId = id || undefined;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// ignore
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Wait for in-flight events. Resolves true when all were sent, false if `timeoutMs` (default 2000) passed. */
|
|
46
|
+
export function flush(timeoutMs = 2000) {
|
|
47
|
+
try {
|
|
48
|
+
const client = getHub().client;
|
|
49
|
+
return client ? client.flush(timeoutMs) : Promise.resolve(true);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return Promise.resolve(false);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Record something that happened (oldest breadcrumbs are dropped beyond `maxBreadcrumbs`). The
|
|
57
|
+
* breadcrumbs are sent with the next events. Message and data go through the privacy filters.
|
|
58
|
+
* Does nothing before init() or while the SDK is disabled. In Node, breadcrumbs added while handling
|
|
59
|
+
* an http request belong to that request only.
|
|
60
|
+
*/
|
|
61
|
+
export function addBreadcrumb(breadcrumb) {
|
|
62
|
+
try {
|
|
63
|
+
recordBreadcrumb(breadcrumb);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// never throw into the host app
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Forget the current breadcrumbs (in Node, inside a request: that request's breadcrumbs). */
|
|
70
|
+
export function clearBreadcrumbs() {
|
|
71
|
+
clearCurrentBreadcrumbs();
|
|
72
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Configure the browser SDK for a Next.js app and capture uncaught errors / unhandled rejections.
|
|
6
|
+
* Omitted options come from NEXT_PUBLIC_AISSUE_API_KEY, NEXT_PUBLIC_AISSUE_BASE_URL (or
|
|
7
|
+
* NEXT_PUBLIC_AISSUE_DSN), NEXT_PUBLIC_AISSUE_RELEASE / NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA and
|
|
8
|
+
* NEXT_PUBLIC_AISSUE_ENVIRONMENT / NEXT_PUBLIC_VERCEL_ENV. Does nothing on the server.
|
|
9
|
+
*/
|
|
10
|
+
export declare function initClient(options?: AIssueOptions): void;
|