@codmir/sdk 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/README.md +206 -0
- package/dist/browser/index.cjs +409 -0
- package/dist/browser/index.d.cts +47 -0
- package/dist/browser/index.d.ts +47 -0
- package/dist/browser/index.js +186 -0
- package/dist/chunk-233XBWQD.js +43 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-T7OAAOG2.js +235 -0
- package/dist/chunk-X6Y5XEK5.js +255 -0
- package/dist/client.cjs +315 -0
- package/dist/client.d.cts +52 -0
- package/dist/client.d.ts +52 -0
- package/dist/client.js +10 -0
- package/dist/index-BlgYnCLd.d.cts +171 -0
- package/dist/index-BlgYnCLd.d.ts +171 -0
- package/dist/index.cjs +540 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +21 -0
- package/dist/nextjs/index.cjs +371 -0
- package/dist/nextjs/index.d.cts +77 -0
- package/dist/nextjs/index.d.ts +77 -0
- package/dist/nextjs/index.js +142 -0
- package/dist/overseer/index.cjs +250 -0
- package/dist/overseer/index.d.cts +1 -0
- package/dist/overseer/index.d.ts +1 -0
- package/dist/overseer/index.js +27 -0
- package/dist/react-native/index.cjs +356 -0
- package/dist/react-native/index.d.cts +95 -0
- package/dist/react-native/index.d.ts +95 -0
- package/dist/react-native/index.js +128 -0
- package/dist/replay/index.cjs +284 -0
- package/dist/replay/index.d.cts +206 -0
- package/dist/replay/index.d.ts +206 -0
- package/dist/replay/index.js +258 -0
- package/dist/types.cjs +69 -0
- package/dist/types.d.cts +281 -0
- package/dist/types.d.ts +281 -0
- package/dist/types.js +11 -0
- package/package.json +116 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/nextjs/index.ts
|
|
21
|
+
var nextjs_exports = {};
|
|
22
|
+
__export(nextjs_exports, {
|
|
23
|
+
addBreadcrumb: () => addBreadcrumb2,
|
|
24
|
+
captureException: () => captureException2,
|
|
25
|
+
captureMessage: () => captureMessage2,
|
|
26
|
+
captureRequestError: () => captureRequestError,
|
|
27
|
+
captureRouterError: () => captureRouterError,
|
|
28
|
+
captureRouterTransitionStart: () => captureRouterTransitionStart,
|
|
29
|
+
close: () => close2,
|
|
30
|
+
flush: () => flush2,
|
|
31
|
+
getClient: () => getClient,
|
|
32
|
+
init: () => init2,
|
|
33
|
+
isOverseerInitialized: () => isOverseerInitialized,
|
|
34
|
+
setTag: () => setTag2,
|
|
35
|
+
setTags: () => setTags2,
|
|
36
|
+
setUser: () => setUser2
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(nextjs_exports);
|
|
39
|
+
|
|
40
|
+
// src/overseer/index.ts
|
|
41
|
+
var import_nanoid = require("nanoid");
|
|
42
|
+
var OverseerClient = class {
|
|
43
|
+
config;
|
|
44
|
+
user = null;
|
|
45
|
+
tags = {};
|
|
46
|
+
breadcrumbs = [];
|
|
47
|
+
eventQueue = [];
|
|
48
|
+
flushTimer = null;
|
|
49
|
+
isInitialized = false;
|
|
50
|
+
constructor(config = {}) {
|
|
51
|
+
this.config = {
|
|
52
|
+
dsn: config.dsn || "",
|
|
53
|
+
environment: config.environment || "development",
|
|
54
|
+
release: config.release || "unknown",
|
|
55
|
+
enabled: config.enabled ?? true,
|
|
56
|
+
debug: config.debug ?? false,
|
|
57
|
+
sampleRate: config.sampleRate ?? 1,
|
|
58
|
+
tracesSampleRate: config.tracesSampleRate ?? 0,
|
|
59
|
+
replaysSessionSampleRate: config.replaysSessionSampleRate ?? 0,
|
|
60
|
+
replaysOnErrorSampleRate: config.replaysOnErrorSampleRate ?? 1,
|
|
61
|
+
beforeSend: config.beforeSend || ((e) => e),
|
|
62
|
+
initialUser: config.initialUser,
|
|
63
|
+
initialTags: config.initialTags || {}
|
|
64
|
+
};
|
|
65
|
+
if (this.config.initialUser) {
|
|
66
|
+
this.user = this.config.initialUser;
|
|
67
|
+
}
|
|
68
|
+
if (this.config.initialTags) {
|
|
69
|
+
this.tags = { ...this.config.initialTags };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
init() {
|
|
73
|
+
if (this.isInitialized) return;
|
|
74
|
+
this.isInitialized = true;
|
|
75
|
+
if (this.config.debug) {
|
|
76
|
+
console.log("[Overseer] Initialized", {
|
|
77
|
+
dsn: this.config.dsn,
|
|
78
|
+
environment: this.config.environment
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
captureException(error, context) {
|
|
83
|
+
if (!this.config.enabled) return "";
|
|
84
|
+
if (!this.shouldSample(this.config.sampleRate)) return "";
|
|
85
|
+
const eventId = (0, import_nanoid.nanoid)();
|
|
86
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
87
|
+
const event = {
|
|
88
|
+
id: eventId,
|
|
89
|
+
type: "error",
|
|
90
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
91
|
+
level: "error",
|
|
92
|
+
message: err.message,
|
|
93
|
+
exception: {
|
|
94
|
+
type: err.name,
|
|
95
|
+
value: err.message,
|
|
96
|
+
stacktrace: this.parseStackTrace(err.stack),
|
|
97
|
+
mechanism: { type: "generic", handled: true }
|
|
98
|
+
},
|
|
99
|
+
user: this.user || void 0,
|
|
100
|
+
tags: { ...this.tags },
|
|
101
|
+
extra: context,
|
|
102
|
+
breadcrumbs: [...this.breadcrumbs],
|
|
103
|
+
environment: this.config.environment,
|
|
104
|
+
release: this.config.release,
|
|
105
|
+
sdk: { name: "@codmir/sdk", version: "1.0.0" }
|
|
106
|
+
};
|
|
107
|
+
this.sendEvent(event);
|
|
108
|
+
return eventId;
|
|
109
|
+
}
|
|
110
|
+
captureMessage(message, level = "info") {
|
|
111
|
+
if (!this.config.enabled) return "";
|
|
112
|
+
if (!this.shouldSample(this.config.sampleRate)) return "";
|
|
113
|
+
const eventId = (0, import_nanoid.nanoid)();
|
|
114
|
+
const event = {
|
|
115
|
+
id: eventId,
|
|
116
|
+
type: "message",
|
|
117
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
118
|
+
level,
|
|
119
|
+
message,
|
|
120
|
+
user: this.user || void 0,
|
|
121
|
+
tags: { ...this.tags },
|
|
122
|
+
breadcrumbs: [...this.breadcrumbs],
|
|
123
|
+
environment: this.config.environment,
|
|
124
|
+
release: this.config.release,
|
|
125
|
+
sdk: { name: "@codmir/sdk", version: "1.0.0" }
|
|
126
|
+
};
|
|
127
|
+
this.sendEvent(event);
|
|
128
|
+
return eventId;
|
|
129
|
+
}
|
|
130
|
+
setUser(user) {
|
|
131
|
+
this.user = user;
|
|
132
|
+
}
|
|
133
|
+
setTag(key, value) {
|
|
134
|
+
this.tags[key] = value;
|
|
135
|
+
}
|
|
136
|
+
setTags(tags) {
|
|
137
|
+
this.tags = { ...this.tags, ...tags };
|
|
138
|
+
}
|
|
139
|
+
setExtra(key, value) {
|
|
140
|
+
}
|
|
141
|
+
addBreadcrumb(breadcrumb) {
|
|
142
|
+
this.breadcrumbs.push({
|
|
143
|
+
...breadcrumb,
|
|
144
|
+
timestamp: breadcrumb.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
145
|
+
});
|
|
146
|
+
if (this.breadcrumbs.length > 100) {
|
|
147
|
+
this.breadcrumbs = this.breadcrumbs.slice(-100);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async flush(timeout) {
|
|
151
|
+
if (this.eventQueue.length === 0) return true;
|
|
152
|
+
const events = [...this.eventQueue];
|
|
153
|
+
this.eventQueue = [];
|
|
154
|
+
try {
|
|
155
|
+
await this.sendBatch(events);
|
|
156
|
+
return true;
|
|
157
|
+
} catch {
|
|
158
|
+
this.eventQueue.unshift(...events);
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
close() {
|
|
163
|
+
if (this.flushTimer) {
|
|
164
|
+
clearTimeout(this.flushTimer);
|
|
165
|
+
}
|
|
166
|
+
this.flush();
|
|
167
|
+
}
|
|
168
|
+
// Private methods
|
|
169
|
+
shouldSample(rate) {
|
|
170
|
+
return Math.random() < rate;
|
|
171
|
+
}
|
|
172
|
+
parseStackTrace(stack) {
|
|
173
|
+
if (!stack) return [];
|
|
174
|
+
return stack.split("\n").slice(1).map((line) => {
|
|
175
|
+
const match = line.match(/at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
|
|
176
|
+
if (match) {
|
|
177
|
+
return {
|
|
178
|
+
function: match[1],
|
|
179
|
+
filename: match[2],
|
|
180
|
+
lineno: parseInt(match[3], 10),
|
|
181
|
+
colno: parseInt(match[4], 10),
|
|
182
|
+
in_app: !match[2].includes("node_modules")
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return { function: line.trim() };
|
|
186
|
+
}).filter((f) => f.function);
|
|
187
|
+
}
|
|
188
|
+
sendEvent(event) {
|
|
189
|
+
const processed = this.config.beforeSend(event);
|
|
190
|
+
if (!processed) return;
|
|
191
|
+
this.eventQueue.push(processed);
|
|
192
|
+
if (this.flushTimer) clearTimeout(this.flushTimer);
|
|
193
|
+
this.flushTimer = setTimeout(() => this.flush(), 1e3);
|
|
194
|
+
}
|
|
195
|
+
async sendBatch(events) {
|
|
196
|
+
if (!this.config.dsn) {
|
|
197
|
+
if (this.config.debug) {
|
|
198
|
+
console.log("[Overseer] No DSN configured, events:", events);
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const endpoint = this.config.dsn.endsWith("/ingest") ? this.config.dsn : `${this.config.dsn}/ingest`;
|
|
203
|
+
await fetch(endpoint, {
|
|
204
|
+
method: "POST",
|
|
205
|
+
headers: { "Content-Type": "application/json" },
|
|
206
|
+
body: JSON.stringify({ events })
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var client = null;
|
|
211
|
+
function init(config = {}) {
|
|
212
|
+
client = new OverseerClient(config);
|
|
213
|
+
client.init();
|
|
214
|
+
}
|
|
215
|
+
function getClient() {
|
|
216
|
+
return client;
|
|
217
|
+
}
|
|
218
|
+
function captureException(error, context) {
|
|
219
|
+
return client?.captureException(error, context) || "";
|
|
220
|
+
}
|
|
221
|
+
function captureMessage(message, level) {
|
|
222
|
+
return client?.captureMessage(message, level) || "";
|
|
223
|
+
}
|
|
224
|
+
function setUser(user) {
|
|
225
|
+
client?.setUser(user);
|
|
226
|
+
}
|
|
227
|
+
function setTag(key, value) {
|
|
228
|
+
client?.setTag(key, value);
|
|
229
|
+
}
|
|
230
|
+
function setTags(tags) {
|
|
231
|
+
client?.setTags(tags);
|
|
232
|
+
}
|
|
233
|
+
function addBreadcrumb(breadcrumb) {
|
|
234
|
+
client?.addBreadcrumb(breadcrumb);
|
|
235
|
+
}
|
|
236
|
+
function flush(timeout) {
|
|
237
|
+
return client?.flush(timeout) || Promise.resolve(true);
|
|
238
|
+
}
|
|
239
|
+
function close() {
|
|
240
|
+
client?.close();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/nextjs/index.ts
|
|
244
|
+
var isInitialized = false;
|
|
245
|
+
function init2(config = {}) {
|
|
246
|
+
if (isInitialized) return;
|
|
247
|
+
const {
|
|
248
|
+
captureUnhandledErrors = true,
|
|
249
|
+
captureUnhandledRejections = true,
|
|
250
|
+
trackRouteChanges = true,
|
|
251
|
+
enableReplay = false,
|
|
252
|
+
...coreConfig
|
|
253
|
+
} = config;
|
|
254
|
+
init(coreConfig);
|
|
255
|
+
isInitialized = true;
|
|
256
|
+
if (typeof window !== "undefined") {
|
|
257
|
+
if (captureUnhandledErrors) {
|
|
258
|
+
window.addEventListener("error", (event) => {
|
|
259
|
+
captureException(event.error || event.message, {
|
|
260
|
+
handled: false,
|
|
261
|
+
mechanism: "onerror"
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
if (captureUnhandledRejections) {
|
|
266
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
267
|
+
captureException(event.reason, {
|
|
268
|
+
handled: false,
|
|
269
|
+
mechanism: "onunhandledrejection"
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
if (trackRouteChanges) {
|
|
274
|
+
setupRouteTracking();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function setupRouteTracking() {
|
|
279
|
+
if (typeof window === "undefined") return;
|
|
280
|
+
addBreadcrumb({
|
|
281
|
+
category: "navigation",
|
|
282
|
+
message: window.location.pathname,
|
|
283
|
+
data: {
|
|
284
|
+
from: document.referrer || void 0,
|
|
285
|
+
to: window.location.href
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
const originalPushState = history.pushState;
|
|
289
|
+
const originalReplaceState = history.replaceState;
|
|
290
|
+
history.pushState = function(...args) {
|
|
291
|
+
const result = originalPushState.apply(this, args);
|
|
292
|
+
addBreadcrumb({
|
|
293
|
+
category: "navigation",
|
|
294
|
+
message: "pushState",
|
|
295
|
+
data: { to: args[2] }
|
|
296
|
+
});
|
|
297
|
+
return result;
|
|
298
|
+
};
|
|
299
|
+
history.replaceState = function(...args) {
|
|
300
|
+
const result = originalReplaceState.apply(this, args);
|
|
301
|
+
addBreadcrumb({
|
|
302
|
+
category: "navigation",
|
|
303
|
+
message: "replaceState",
|
|
304
|
+
data: { to: args[2] }
|
|
305
|
+
});
|
|
306
|
+
return result;
|
|
307
|
+
};
|
|
308
|
+
window.addEventListener("popstate", () => {
|
|
309
|
+
addBreadcrumb({
|
|
310
|
+
category: "navigation",
|
|
311
|
+
message: "popstate",
|
|
312
|
+
data: { to: window.location.href }
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
function captureRequestError(error, errorContext, request) {
|
|
317
|
+
const eventId = captureException(error, {
|
|
318
|
+
mechanism: "server",
|
|
319
|
+
...errorContext,
|
|
320
|
+
request: request ? {
|
|
321
|
+
url: request.url,
|
|
322
|
+
method: request.method,
|
|
323
|
+
headers: Object.fromEntries(request.headers)
|
|
324
|
+
} : void 0
|
|
325
|
+
});
|
|
326
|
+
return eventId;
|
|
327
|
+
}
|
|
328
|
+
async function captureRouterError(error, request, context) {
|
|
329
|
+
captureException(error, {
|
|
330
|
+
mechanism: "nextjs-router",
|
|
331
|
+
routerKind: context.routerKind,
|
|
332
|
+
routePath: context.routePath,
|
|
333
|
+
routeType: context.routeType,
|
|
334
|
+
request
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function captureRouterTransitionStart(route) {
|
|
338
|
+
addBreadcrumb({
|
|
339
|
+
category: "navigation",
|
|
340
|
+
message: `Navigating to ${route}`,
|
|
341
|
+
data: { route }
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
var captureException2 = captureException;
|
|
345
|
+
var captureMessage2 = captureMessage;
|
|
346
|
+
var setUser2 = setUser;
|
|
347
|
+
var setTag2 = setTag;
|
|
348
|
+
var setTags2 = setTags;
|
|
349
|
+
var addBreadcrumb2 = addBreadcrumb;
|
|
350
|
+
var flush2 = flush;
|
|
351
|
+
var close2 = close;
|
|
352
|
+
function isOverseerInitialized() {
|
|
353
|
+
return isInitialized && getClient() !== null;
|
|
354
|
+
}
|
|
355
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
356
|
+
0 && (module.exports = {
|
|
357
|
+
addBreadcrumb,
|
|
358
|
+
captureException,
|
|
359
|
+
captureMessage,
|
|
360
|
+
captureRequestError,
|
|
361
|
+
captureRouterError,
|
|
362
|
+
captureRouterTransitionStart,
|
|
363
|
+
close,
|
|
364
|
+
flush,
|
|
365
|
+
getClient,
|
|
366
|
+
init,
|
|
367
|
+
isOverseerInitialized,
|
|
368
|
+
setTag,
|
|
369
|
+
setTags,
|
|
370
|
+
setUser
|
|
371
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { O as OverseerConfig, c as captureException$1, a as captureMessage$1, s as setUser$1, h as setTag$1, b as setTags$1, d as addBreadcrumb$1, f as flush$1, e as close$1 } from '../index-BlgYnCLd.cjs';
|
|
2
|
+
export { B as Breadcrumb, j as OverseerEvent, S as SeverityLevel, U as UserContext, g as getClient } from '../index-BlgYnCLd.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @codmir/sdk/nextjs - Next.js Integration
|
|
6
|
+
*
|
|
7
|
+
* Automatic error tracking, session replay, and performance
|
|
8
|
+
* monitoring for Next.js applications.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // instrumentation.ts
|
|
13
|
+
* import * as Codmir from '@codmir/sdk/nextjs';
|
|
14
|
+
*
|
|
15
|
+
* Codmir.init({
|
|
16
|
+
* dsn: process.env.NEXT_PUBLIC_CODMIR_DSN,
|
|
17
|
+
* environment: process.env.NODE_ENV,
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface NextjsConfig extends OverseerConfig {
|
|
23
|
+
/** Automatically capture unhandled errors */
|
|
24
|
+
captureUnhandledErrors?: boolean;
|
|
25
|
+
/** Automatically capture unhandled promise rejections */
|
|
26
|
+
captureUnhandledRejections?: boolean;
|
|
27
|
+
/** Track route changes as breadcrumbs */
|
|
28
|
+
trackRouteChanges?: boolean;
|
|
29
|
+
/** Enable session replay */
|
|
30
|
+
enableReplay?: boolean;
|
|
31
|
+
}
|
|
32
|
+
interface RequestError {
|
|
33
|
+
digest?: string;
|
|
34
|
+
message?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
stack?: string;
|
|
37
|
+
}
|
|
38
|
+
interface ErrorContext {
|
|
39
|
+
routerKind: string;
|
|
40
|
+
routePath: string;
|
|
41
|
+
routeType: string;
|
|
42
|
+
renderSource?: string;
|
|
43
|
+
revalidateReason?: string;
|
|
44
|
+
}
|
|
45
|
+
declare function init(config?: NextjsConfig): void;
|
|
46
|
+
/**
|
|
47
|
+
* Capture a server-side request error (App Router)
|
|
48
|
+
*/
|
|
49
|
+
declare function captureRequestError(error: RequestError, errorContext: Partial<ErrorContext>, request?: Request): string;
|
|
50
|
+
/**
|
|
51
|
+
* Handler for Next.js App Router errors
|
|
52
|
+
* Use in instrumentation.ts: export const onRequestError = captureRouterError
|
|
53
|
+
*/
|
|
54
|
+
declare function captureRouterError(error: RequestError, request: {
|
|
55
|
+
path: string;
|
|
56
|
+
method: string;
|
|
57
|
+
headers: Record<string, string>;
|
|
58
|
+
}, context: ErrorContext): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Track router transition start (for performance)
|
|
61
|
+
*/
|
|
62
|
+
declare function captureRouterTransitionStart(route: string): void;
|
|
63
|
+
|
|
64
|
+
declare const captureException: typeof captureException$1;
|
|
65
|
+
declare const captureMessage: typeof captureMessage$1;
|
|
66
|
+
declare const setUser: typeof setUser$1;
|
|
67
|
+
declare const setTag: typeof setTag$1;
|
|
68
|
+
declare const setTags: typeof setTags$1;
|
|
69
|
+
declare const addBreadcrumb: typeof addBreadcrumb$1;
|
|
70
|
+
declare const flush: typeof flush$1;
|
|
71
|
+
declare const close: typeof close$1;
|
|
72
|
+
/**
|
|
73
|
+
* Check if Overseer is initialized
|
|
74
|
+
*/
|
|
75
|
+
declare function isOverseerInitialized(): boolean;
|
|
76
|
+
|
|
77
|
+
export { type ErrorContext, type NextjsConfig, OverseerConfig, type RequestError, addBreadcrumb, captureException, captureMessage, captureRequestError, captureRouterError, captureRouterTransitionStart, close, flush, init, isOverseerInitialized, setTag, setTags, setUser };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { O as OverseerConfig, c as captureException$1, a as captureMessage$1, s as setUser$1, h as setTag$1, b as setTags$1, d as addBreadcrumb$1, f as flush$1, e as close$1 } from '../index-BlgYnCLd.js';
|
|
2
|
+
export { B as Breadcrumb, j as OverseerEvent, S as SeverityLevel, U as UserContext, g as getClient } from '../index-BlgYnCLd.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @codmir/sdk/nextjs - Next.js Integration
|
|
6
|
+
*
|
|
7
|
+
* Automatic error tracking, session replay, and performance
|
|
8
|
+
* monitoring for Next.js applications.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // instrumentation.ts
|
|
13
|
+
* import * as Codmir from '@codmir/sdk/nextjs';
|
|
14
|
+
*
|
|
15
|
+
* Codmir.init({
|
|
16
|
+
* dsn: process.env.NEXT_PUBLIC_CODMIR_DSN,
|
|
17
|
+
* environment: process.env.NODE_ENV,
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface NextjsConfig extends OverseerConfig {
|
|
23
|
+
/** Automatically capture unhandled errors */
|
|
24
|
+
captureUnhandledErrors?: boolean;
|
|
25
|
+
/** Automatically capture unhandled promise rejections */
|
|
26
|
+
captureUnhandledRejections?: boolean;
|
|
27
|
+
/** Track route changes as breadcrumbs */
|
|
28
|
+
trackRouteChanges?: boolean;
|
|
29
|
+
/** Enable session replay */
|
|
30
|
+
enableReplay?: boolean;
|
|
31
|
+
}
|
|
32
|
+
interface RequestError {
|
|
33
|
+
digest?: string;
|
|
34
|
+
message?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
stack?: string;
|
|
37
|
+
}
|
|
38
|
+
interface ErrorContext {
|
|
39
|
+
routerKind: string;
|
|
40
|
+
routePath: string;
|
|
41
|
+
routeType: string;
|
|
42
|
+
renderSource?: string;
|
|
43
|
+
revalidateReason?: string;
|
|
44
|
+
}
|
|
45
|
+
declare function init(config?: NextjsConfig): void;
|
|
46
|
+
/**
|
|
47
|
+
* Capture a server-side request error (App Router)
|
|
48
|
+
*/
|
|
49
|
+
declare function captureRequestError(error: RequestError, errorContext: Partial<ErrorContext>, request?: Request): string;
|
|
50
|
+
/**
|
|
51
|
+
* Handler for Next.js App Router errors
|
|
52
|
+
* Use in instrumentation.ts: export const onRequestError = captureRouterError
|
|
53
|
+
*/
|
|
54
|
+
declare function captureRouterError(error: RequestError, request: {
|
|
55
|
+
path: string;
|
|
56
|
+
method: string;
|
|
57
|
+
headers: Record<string, string>;
|
|
58
|
+
}, context: ErrorContext): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Track router transition start (for performance)
|
|
61
|
+
*/
|
|
62
|
+
declare function captureRouterTransitionStart(route: string): void;
|
|
63
|
+
|
|
64
|
+
declare const captureException: typeof captureException$1;
|
|
65
|
+
declare const captureMessage: typeof captureMessage$1;
|
|
66
|
+
declare const setUser: typeof setUser$1;
|
|
67
|
+
declare const setTag: typeof setTag$1;
|
|
68
|
+
declare const setTags: typeof setTags$1;
|
|
69
|
+
declare const addBreadcrumb: typeof addBreadcrumb$1;
|
|
70
|
+
declare const flush: typeof flush$1;
|
|
71
|
+
declare const close: typeof close$1;
|
|
72
|
+
/**
|
|
73
|
+
* Check if Overseer is initialized
|
|
74
|
+
*/
|
|
75
|
+
declare function isOverseerInitialized(): boolean;
|
|
76
|
+
|
|
77
|
+
export { type ErrorContext, type NextjsConfig, OverseerConfig, type RequestError, addBreadcrumb, captureException, captureMessage, captureRequestError, captureRouterError, captureRouterTransitionStart, close, flush, init, isOverseerInitialized, setTag, setTags, setUser };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addBreadcrumb,
|
|
3
|
+
captureException,
|
|
4
|
+
captureMessage,
|
|
5
|
+
close,
|
|
6
|
+
flush,
|
|
7
|
+
getClient,
|
|
8
|
+
init,
|
|
9
|
+
setTag,
|
|
10
|
+
setTags,
|
|
11
|
+
setUser
|
|
12
|
+
} from "../chunk-T7OAAOG2.js";
|
|
13
|
+
import "../chunk-MLKGABMK.js";
|
|
14
|
+
|
|
15
|
+
// src/nextjs/index.ts
|
|
16
|
+
var isInitialized = false;
|
|
17
|
+
function init2(config = {}) {
|
|
18
|
+
if (isInitialized) return;
|
|
19
|
+
const {
|
|
20
|
+
captureUnhandledErrors = true,
|
|
21
|
+
captureUnhandledRejections = true,
|
|
22
|
+
trackRouteChanges = true,
|
|
23
|
+
enableReplay = false,
|
|
24
|
+
...coreConfig
|
|
25
|
+
} = config;
|
|
26
|
+
init(coreConfig);
|
|
27
|
+
isInitialized = true;
|
|
28
|
+
if (typeof window !== "undefined") {
|
|
29
|
+
if (captureUnhandledErrors) {
|
|
30
|
+
window.addEventListener("error", (event) => {
|
|
31
|
+
captureException(event.error || event.message, {
|
|
32
|
+
handled: false,
|
|
33
|
+
mechanism: "onerror"
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (captureUnhandledRejections) {
|
|
38
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
39
|
+
captureException(event.reason, {
|
|
40
|
+
handled: false,
|
|
41
|
+
mechanism: "onunhandledrejection"
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (trackRouteChanges) {
|
|
46
|
+
setupRouteTracking();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function setupRouteTracking() {
|
|
51
|
+
if (typeof window === "undefined") return;
|
|
52
|
+
addBreadcrumb({
|
|
53
|
+
category: "navigation",
|
|
54
|
+
message: window.location.pathname,
|
|
55
|
+
data: {
|
|
56
|
+
from: document.referrer || void 0,
|
|
57
|
+
to: window.location.href
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const originalPushState = history.pushState;
|
|
61
|
+
const originalReplaceState = history.replaceState;
|
|
62
|
+
history.pushState = function(...args) {
|
|
63
|
+
const result = originalPushState.apply(this, args);
|
|
64
|
+
addBreadcrumb({
|
|
65
|
+
category: "navigation",
|
|
66
|
+
message: "pushState",
|
|
67
|
+
data: { to: args[2] }
|
|
68
|
+
});
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
history.replaceState = function(...args) {
|
|
72
|
+
const result = originalReplaceState.apply(this, args);
|
|
73
|
+
addBreadcrumb({
|
|
74
|
+
category: "navigation",
|
|
75
|
+
message: "replaceState",
|
|
76
|
+
data: { to: args[2] }
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
window.addEventListener("popstate", () => {
|
|
81
|
+
addBreadcrumb({
|
|
82
|
+
category: "navigation",
|
|
83
|
+
message: "popstate",
|
|
84
|
+
data: { to: window.location.href }
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function captureRequestError(error, errorContext, request) {
|
|
89
|
+
const eventId = captureException(error, {
|
|
90
|
+
mechanism: "server",
|
|
91
|
+
...errorContext,
|
|
92
|
+
request: request ? {
|
|
93
|
+
url: request.url,
|
|
94
|
+
method: request.method,
|
|
95
|
+
headers: Object.fromEntries(request.headers)
|
|
96
|
+
} : void 0
|
|
97
|
+
});
|
|
98
|
+
return eventId;
|
|
99
|
+
}
|
|
100
|
+
async function captureRouterError(error, request, context) {
|
|
101
|
+
captureException(error, {
|
|
102
|
+
mechanism: "nextjs-router",
|
|
103
|
+
routerKind: context.routerKind,
|
|
104
|
+
routePath: context.routePath,
|
|
105
|
+
routeType: context.routeType,
|
|
106
|
+
request
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function captureRouterTransitionStart(route) {
|
|
110
|
+
addBreadcrumb({
|
|
111
|
+
category: "navigation",
|
|
112
|
+
message: `Navigating to ${route}`,
|
|
113
|
+
data: { route }
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
var captureException2 = captureException;
|
|
117
|
+
var captureMessage2 = captureMessage;
|
|
118
|
+
var setUser2 = setUser;
|
|
119
|
+
var setTag2 = setTag;
|
|
120
|
+
var setTags2 = setTags;
|
|
121
|
+
var addBreadcrumb2 = addBreadcrumb;
|
|
122
|
+
var flush2 = flush;
|
|
123
|
+
var close2 = close;
|
|
124
|
+
function isOverseerInitialized() {
|
|
125
|
+
return isInitialized && getClient() !== null;
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
addBreadcrumb2 as addBreadcrumb,
|
|
129
|
+
captureException2 as captureException,
|
|
130
|
+
captureMessage2 as captureMessage,
|
|
131
|
+
captureRequestError,
|
|
132
|
+
captureRouterError,
|
|
133
|
+
captureRouterTransitionStart,
|
|
134
|
+
close2 as close,
|
|
135
|
+
flush2 as flush,
|
|
136
|
+
getClient,
|
|
137
|
+
init2 as init,
|
|
138
|
+
isOverseerInitialized,
|
|
139
|
+
setTag2 as setTag,
|
|
140
|
+
setTags2 as setTags,
|
|
141
|
+
setUser2 as setUser
|
|
142
|
+
};
|