@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.
@@ -0,0 +1,250 @@
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/overseer/index.ts
21
+ var overseer_exports = {};
22
+ __export(overseer_exports, {
23
+ OverseerClient: () => OverseerClient,
24
+ addBreadcrumb: () => addBreadcrumb,
25
+ captureException: () => captureException,
26
+ captureMessage: () => captureMessage,
27
+ close: () => close,
28
+ flush: () => flush,
29
+ getClient: () => getClient,
30
+ init: () => init,
31
+ setTag: () => setTag,
32
+ setTags: () => setTags,
33
+ setUser: () => setUser
34
+ });
35
+ module.exports = __toCommonJS(overseer_exports);
36
+ var import_nanoid = require("nanoid");
37
+ var OverseerClient = class {
38
+ config;
39
+ user = null;
40
+ tags = {};
41
+ breadcrumbs = [];
42
+ eventQueue = [];
43
+ flushTimer = null;
44
+ isInitialized = false;
45
+ constructor(config = {}) {
46
+ this.config = {
47
+ dsn: config.dsn || "",
48
+ environment: config.environment || "development",
49
+ release: config.release || "unknown",
50
+ enabled: config.enabled ?? true,
51
+ debug: config.debug ?? false,
52
+ sampleRate: config.sampleRate ?? 1,
53
+ tracesSampleRate: config.tracesSampleRate ?? 0,
54
+ replaysSessionSampleRate: config.replaysSessionSampleRate ?? 0,
55
+ replaysOnErrorSampleRate: config.replaysOnErrorSampleRate ?? 1,
56
+ beforeSend: config.beforeSend || ((e) => e),
57
+ initialUser: config.initialUser,
58
+ initialTags: config.initialTags || {}
59
+ };
60
+ if (this.config.initialUser) {
61
+ this.user = this.config.initialUser;
62
+ }
63
+ if (this.config.initialTags) {
64
+ this.tags = { ...this.config.initialTags };
65
+ }
66
+ }
67
+ init() {
68
+ if (this.isInitialized) return;
69
+ this.isInitialized = true;
70
+ if (this.config.debug) {
71
+ console.log("[Overseer] Initialized", {
72
+ dsn: this.config.dsn,
73
+ environment: this.config.environment
74
+ });
75
+ }
76
+ }
77
+ captureException(error, context) {
78
+ if (!this.config.enabled) return "";
79
+ if (!this.shouldSample(this.config.sampleRate)) return "";
80
+ const eventId = (0, import_nanoid.nanoid)();
81
+ const err = error instanceof Error ? error : new Error(String(error));
82
+ const event = {
83
+ id: eventId,
84
+ type: "error",
85
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
86
+ level: "error",
87
+ message: err.message,
88
+ exception: {
89
+ type: err.name,
90
+ value: err.message,
91
+ stacktrace: this.parseStackTrace(err.stack),
92
+ mechanism: { type: "generic", handled: true }
93
+ },
94
+ user: this.user || void 0,
95
+ tags: { ...this.tags },
96
+ extra: context,
97
+ breadcrumbs: [...this.breadcrumbs],
98
+ environment: this.config.environment,
99
+ release: this.config.release,
100
+ sdk: { name: "@codmir/sdk", version: "1.0.0" }
101
+ };
102
+ this.sendEvent(event);
103
+ return eventId;
104
+ }
105
+ captureMessage(message, level = "info") {
106
+ if (!this.config.enabled) return "";
107
+ if (!this.shouldSample(this.config.sampleRate)) return "";
108
+ const eventId = (0, import_nanoid.nanoid)();
109
+ const event = {
110
+ id: eventId,
111
+ type: "message",
112
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
113
+ level,
114
+ message,
115
+ user: this.user || void 0,
116
+ tags: { ...this.tags },
117
+ breadcrumbs: [...this.breadcrumbs],
118
+ environment: this.config.environment,
119
+ release: this.config.release,
120
+ sdk: { name: "@codmir/sdk", version: "1.0.0" }
121
+ };
122
+ this.sendEvent(event);
123
+ return eventId;
124
+ }
125
+ setUser(user) {
126
+ this.user = user;
127
+ }
128
+ setTag(key, value) {
129
+ this.tags[key] = value;
130
+ }
131
+ setTags(tags) {
132
+ this.tags = { ...this.tags, ...tags };
133
+ }
134
+ setExtra(key, value) {
135
+ }
136
+ addBreadcrumb(breadcrumb) {
137
+ this.breadcrumbs.push({
138
+ ...breadcrumb,
139
+ timestamp: breadcrumb.timestamp || (/* @__PURE__ */ new Date()).toISOString()
140
+ });
141
+ if (this.breadcrumbs.length > 100) {
142
+ this.breadcrumbs = this.breadcrumbs.slice(-100);
143
+ }
144
+ }
145
+ async flush(timeout) {
146
+ if (this.eventQueue.length === 0) return true;
147
+ const events = [...this.eventQueue];
148
+ this.eventQueue = [];
149
+ try {
150
+ await this.sendBatch(events);
151
+ return true;
152
+ } catch {
153
+ this.eventQueue.unshift(...events);
154
+ return false;
155
+ }
156
+ }
157
+ close() {
158
+ if (this.flushTimer) {
159
+ clearTimeout(this.flushTimer);
160
+ }
161
+ this.flush();
162
+ }
163
+ // Private methods
164
+ shouldSample(rate) {
165
+ return Math.random() < rate;
166
+ }
167
+ parseStackTrace(stack) {
168
+ if (!stack) return [];
169
+ return stack.split("\n").slice(1).map((line) => {
170
+ const match = line.match(/at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
171
+ if (match) {
172
+ return {
173
+ function: match[1],
174
+ filename: match[2],
175
+ lineno: parseInt(match[3], 10),
176
+ colno: parseInt(match[4], 10),
177
+ in_app: !match[2].includes("node_modules")
178
+ };
179
+ }
180
+ return { function: line.trim() };
181
+ }).filter((f) => f.function);
182
+ }
183
+ sendEvent(event) {
184
+ const processed = this.config.beforeSend(event);
185
+ if (!processed) return;
186
+ this.eventQueue.push(processed);
187
+ if (this.flushTimer) clearTimeout(this.flushTimer);
188
+ this.flushTimer = setTimeout(() => this.flush(), 1e3);
189
+ }
190
+ async sendBatch(events) {
191
+ if (!this.config.dsn) {
192
+ if (this.config.debug) {
193
+ console.log("[Overseer] No DSN configured, events:", events);
194
+ }
195
+ return;
196
+ }
197
+ const endpoint = this.config.dsn.endsWith("/ingest") ? this.config.dsn : `${this.config.dsn}/ingest`;
198
+ await fetch(endpoint, {
199
+ method: "POST",
200
+ headers: { "Content-Type": "application/json" },
201
+ body: JSON.stringify({ events })
202
+ });
203
+ }
204
+ };
205
+ var client = null;
206
+ function init(config = {}) {
207
+ client = new OverseerClient(config);
208
+ client.init();
209
+ }
210
+ function getClient() {
211
+ return client;
212
+ }
213
+ function captureException(error, context) {
214
+ return client?.captureException(error, context) || "";
215
+ }
216
+ function captureMessage(message, level) {
217
+ return client?.captureMessage(message, level) || "";
218
+ }
219
+ function setUser(user) {
220
+ client?.setUser(user);
221
+ }
222
+ function setTag(key, value) {
223
+ client?.setTag(key, value);
224
+ }
225
+ function setTags(tags) {
226
+ client?.setTags(tags);
227
+ }
228
+ function addBreadcrumb(breadcrumb) {
229
+ client?.addBreadcrumb(breadcrumb);
230
+ }
231
+ function flush(timeout) {
232
+ return client?.flush(timeout) || Promise.resolve(true);
233
+ }
234
+ function close() {
235
+ client?.close();
236
+ }
237
+ // Annotate the CommonJS export names for ESM import in node:
238
+ 0 && (module.exports = {
239
+ OverseerClient,
240
+ addBreadcrumb,
241
+ captureException,
242
+ captureMessage,
243
+ close,
244
+ flush,
245
+ getClient,
246
+ init,
247
+ setTag,
248
+ setTags,
249
+ setUser
250
+ });
@@ -0,0 +1 @@
1
+ export { B as Breadcrumb, E as ExceptionData, k as OverseerClient, O as OverseerConfig, j as OverseerEvent, R as RequestData, S as SeverityLevel, l as StackFrame, U as UserContext, d as addBreadcrumb, c as captureException, a as captureMessage, e as close, f as flush, g as getClient, m as init, h as setTag, b as setTags, s as setUser } from '../index-BlgYnCLd.cjs';
@@ -0,0 +1 @@
1
+ export { B as Breadcrumb, E as ExceptionData, k as OverseerClient, O as OverseerConfig, j as OverseerEvent, R as RequestData, S as SeverityLevel, l as StackFrame, U as UserContext, d as addBreadcrumb, c as captureException, a as captureMessage, e as close, f as flush, g as getClient, m as init, h as setTag, b as setTags, s as setUser } from '../index-BlgYnCLd.js';
@@ -0,0 +1,27 @@
1
+ import {
2
+ OverseerClient,
3
+ addBreadcrumb,
4
+ captureException,
5
+ captureMessage,
6
+ close,
7
+ flush,
8
+ getClient,
9
+ init,
10
+ setTag,
11
+ setTags,
12
+ setUser
13
+ } from "../chunk-T7OAAOG2.js";
14
+ import "../chunk-MLKGABMK.js";
15
+ export {
16
+ OverseerClient,
17
+ addBreadcrumb,
18
+ captureException,
19
+ captureMessage,
20
+ close,
21
+ flush,
22
+ getClient,
23
+ init,
24
+ setTag,
25
+ setTags,
26
+ setUser
27
+ };
@@ -0,0 +1,356 @@
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/react-native/index.ts
21
+ var react_native_exports = {};
22
+ __export(react_native_exports, {
23
+ addBreadcrumb: () => addBreadcrumb,
24
+ captureException: () => captureException,
25
+ captureMessage: () => captureMessage,
26
+ close: () => close,
27
+ createErrorBoundary: () => createErrorBoundary,
28
+ createNavigationListener: () => createNavigationListener,
29
+ flush: () => flush,
30
+ getClient: () => getClient,
31
+ init: () => init2,
32
+ isOverseerInitialized: () => isOverseerInitialized,
33
+ setDeviceInfo: () => setDeviceInfo,
34
+ setTags: () => setTags,
35
+ setUser: () => setUser,
36
+ trackAppStateChange: () => trackAppStateChange,
37
+ trackScreenView: () => trackScreenView
38
+ });
39
+ module.exports = __toCommonJS(react_native_exports);
40
+
41
+ // src/overseer/index.ts
42
+ var import_nanoid = require("nanoid");
43
+ var OverseerClient = class {
44
+ config;
45
+ user = null;
46
+ tags = {};
47
+ breadcrumbs = [];
48
+ eventQueue = [];
49
+ flushTimer = null;
50
+ isInitialized = false;
51
+ constructor(config = {}) {
52
+ this.config = {
53
+ dsn: config.dsn || "",
54
+ environment: config.environment || "development",
55
+ release: config.release || "unknown",
56
+ enabled: config.enabled ?? true,
57
+ debug: config.debug ?? false,
58
+ sampleRate: config.sampleRate ?? 1,
59
+ tracesSampleRate: config.tracesSampleRate ?? 0,
60
+ replaysSessionSampleRate: config.replaysSessionSampleRate ?? 0,
61
+ replaysOnErrorSampleRate: config.replaysOnErrorSampleRate ?? 1,
62
+ beforeSend: config.beforeSend || ((e) => e),
63
+ initialUser: config.initialUser,
64
+ initialTags: config.initialTags || {}
65
+ };
66
+ if (this.config.initialUser) {
67
+ this.user = this.config.initialUser;
68
+ }
69
+ if (this.config.initialTags) {
70
+ this.tags = { ...this.config.initialTags };
71
+ }
72
+ }
73
+ init() {
74
+ if (this.isInitialized) return;
75
+ this.isInitialized = true;
76
+ if (this.config.debug) {
77
+ console.log("[Overseer] Initialized", {
78
+ dsn: this.config.dsn,
79
+ environment: this.config.environment
80
+ });
81
+ }
82
+ }
83
+ captureException(error, context) {
84
+ if (!this.config.enabled) return "";
85
+ if (!this.shouldSample(this.config.sampleRate)) return "";
86
+ const eventId = (0, import_nanoid.nanoid)();
87
+ const err = error instanceof Error ? error : new Error(String(error));
88
+ const event = {
89
+ id: eventId,
90
+ type: "error",
91
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
92
+ level: "error",
93
+ message: err.message,
94
+ exception: {
95
+ type: err.name,
96
+ value: err.message,
97
+ stacktrace: this.parseStackTrace(err.stack),
98
+ mechanism: { type: "generic", handled: true }
99
+ },
100
+ user: this.user || void 0,
101
+ tags: { ...this.tags },
102
+ extra: context,
103
+ breadcrumbs: [...this.breadcrumbs],
104
+ environment: this.config.environment,
105
+ release: this.config.release,
106
+ sdk: { name: "@codmir/sdk", version: "1.0.0" }
107
+ };
108
+ this.sendEvent(event);
109
+ return eventId;
110
+ }
111
+ captureMessage(message, level = "info") {
112
+ if (!this.config.enabled) return "";
113
+ if (!this.shouldSample(this.config.sampleRate)) return "";
114
+ const eventId = (0, import_nanoid.nanoid)();
115
+ const event = {
116
+ id: eventId,
117
+ type: "message",
118
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
119
+ level,
120
+ message,
121
+ user: this.user || void 0,
122
+ tags: { ...this.tags },
123
+ breadcrumbs: [...this.breadcrumbs],
124
+ environment: this.config.environment,
125
+ release: this.config.release,
126
+ sdk: { name: "@codmir/sdk", version: "1.0.0" }
127
+ };
128
+ this.sendEvent(event);
129
+ return eventId;
130
+ }
131
+ setUser(user) {
132
+ this.user = user;
133
+ }
134
+ setTag(key, value) {
135
+ this.tags[key] = value;
136
+ }
137
+ setTags(tags) {
138
+ this.tags = { ...this.tags, ...tags };
139
+ }
140
+ setExtra(key, value) {
141
+ }
142
+ addBreadcrumb(breadcrumb) {
143
+ this.breadcrumbs.push({
144
+ ...breadcrumb,
145
+ timestamp: breadcrumb.timestamp || (/* @__PURE__ */ new Date()).toISOString()
146
+ });
147
+ if (this.breadcrumbs.length > 100) {
148
+ this.breadcrumbs = this.breadcrumbs.slice(-100);
149
+ }
150
+ }
151
+ async flush(timeout) {
152
+ if (this.eventQueue.length === 0) return true;
153
+ const events = [...this.eventQueue];
154
+ this.eventQueue = [];
155
+ try {
156
+ await this.sendBatch(events);
157
+ return true;
158
+ } catch {
159
+ this.eventQueue.unshift(...events);
160
+ return false;
161
+ }
162
+ }
163
+ close() {
164
+ if (this.flushTimer) {
165
+ clearTimeout(this.flushTimer);
166
+ }
167
+ this.flush();
168
+ }
169
+ // Private methods
170
+ shouldSample(rate) {
171
+ return Math.random() < rate;
172
+ }
173
+ parseStackTrace(stack) {
174
+ if (!stack) return [];
175
+ return stack.split("\n").slice(1).map((line) => {
176
+ const match = line.match(/at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
177
+ if (match) {
178
+ return {
179
+ function: match[1],
180
+ filename: match[2],
181
+ lineno: parseInt(match[3], 10),
182
+ colno: parseInt(match[4], 10),
183
+ in_app: !match[2].includes("node_modules")
184
+ };
185
+ }
186
+ return { function: line.trim() };
187
+ }).filter((f) => f.function);
188
+ }
189
+ sendEvent(event) {
190
+ const processed = this.config.beforeSend(event);
191
+ if (!processed) return;
192
+ this.eventQueue.push(processed);
193
+ if (this.flushTimer) clearTimeout(this.flushTimer);
194
+ this.flushTimer = setTimeout(() => this.flush(), 1e3);
195
+ }
196
+ async sendBatch(events) {
197
+ if (!this.config.dsn) {
198
+ if (this.config.debug) {
199
+ console.log("[Overseer] No DSN configured, events:", events);
200
+ }
201
+ return;
202
+ }
203
+ const endpoint = this.config.dsn.endsWith("/ingest") ? this.config.dsn : `${this.config.dsn}/ingest`;
204
+ await fetch(endpoint, {
205
+ method: "POST",
206
+ headers: { "Content-Type": "application/json" },
207
+ body: JSON.stringify({ events })
208
+ });
209
+ }
210
+ };
211
+ var client = null;
212
+ function init(config = {}) {
213
+ client = new OverseerClient(config);
214
+ client.init();
215
+ }
216
+ function getClient() {
217
+ return client;
218
+ }
219
+ function captureException(error, context) {
220
+ return client?.captureException(error, context) || "";
221
+ }
222
+ function captureMessage(message, level) {
223
+ return client?.captureMessage(message, level) || "";
224
+ }
225
+ function setUser(user) {
226
+ client?.setUser(user);
227
+ }
228
+ function setTags(tags) {
229
+ client?.setTags(tags);
230
+ }
231
+ function addBreadcrumb(breadcrumb) {
232
+ client?.addBreadcrumb(breadcrumb);
233
+ }
234
+ function flush(timeout) {
235
+ return client?.flush(timeout) || Promise.resolve(true);
236
+ }
237
+ function close() {
238
+ client?.close();
239
+ }
240
+
241
+ // src/react-native/index.ts
242
+ var isInitialized = false;
243
+ var deviceInfo = null;
244
+ function init2(config = {}) {
245
+ if (isInitialized) return;
246
+ const {
247
+ captureNativeCrashes = true,
248
+ trackScreenViews = true,
249
+ trackAppState = true,
250
+ includeDeviceInfo = true,
251
+ ...coreConfig
252
+ } = config;
253
+ init(coreConfig);
254
+ isInitialized = true;
255
+ const originalHandler = ErrorUtils.getGlobalHandler();
256
+ ErrorUtils.setGlobalHandler((error, isFatal) => {
257
+ captureException(error, {
258
+ handled: false,
259
+ mechanism: "global-error-handler",
260
+ fatal: isFatal,
261
+ device: deviceInfo
262
+ });
263
+ if (originalHandler) {
264
+ originalHandler(error, isFatal);
265
+ }
266
+ });
267
+ }
268
+ function setDeviceInfo(info) {
269
+ deviceInfo = info;
270
+ setTags({
271
+ "device.platform": info.platform,
272
+ "device.os_version": info.osVersion || "unknown",
273
+ "device.model": info.deviceModel || "unknown",
274
+ "app.version": info.appVersion || "unknown",
275
+ "app.build": info.buildNumber || "unknown"
276
+ });
277
+ }
278
+ function trackScreenView(screenName, params) {
279
+ addBreadcrumb({
280
+ category: "navigation",
281
+ message: `Screen: ${screenName}`,
282
+ data: params
283
+ });
284
+ }
285
+ function createNavigationListener() {
286
+ return (state) => {
287
+ const currentRoute = getCurrentRouteName(state);
288
+ if (currentRoute) {
289
+ trackScreenView(currentRoute);
290
+ }
291
+ };
292
+ }
293
+ function getCurrentRouteName(state) {
294
+ if (!state) return null;
295
+ const route = state.routes[state.index];
296
+ if (route.state) {
297
+ return getCurrentRouteName(route.state);
298
+ }
299
+ return route.name;
300
+ }
301
+ function trackAppStateChange(state) {
302
+ addBreadcrumb({
303
+ category: "app.lifecycle",
304
+ message: `App state: ${state}`,
305
+ data: { state }
306
+ });
307
+ }
308
+ function createErrorBoundary(React) {
309
+ return class ErrorBoundary extends React.Component {
310
+ constructor(props) {
311
+ super(props);
312
+ this.state = { hasError: false, error: null };
313
+ }
314
+ static getDerivedStateFromError(error) {
315
+ return { hasError: true, error };
316
+ }
317
+ componentDidCatch(error, errorInfo) {
318
+ captureException(error, {
319
+ mechanism: "react-error-boundary",
320
+ componentStack: errorInfo.componentStack
321
+ });
322
+ this.props.onError?.(error, errorInfo.componentStack);
323
+ }
324
+ render() {
325
+ if (this.state.hasError) {
326
+ const { fallback } = this.props;
327
+ if (typeof fallback === "function") {
328
+ return fallback(this.state.error);
329
+ }
330
+ return fallback;
331
+ }
332
+ return this.props.children;
333
+ }
334
+ };
335
+ }
336
+ function isOverseerInitialized() {
337
+ return isInitialized && getClient() !== null;
338
+ }
339
+ // Annotate the CommonJS export names for ESM import in node:
340
+ 0 && (module.exports = {
341
+ addBreadcrumb,
342
+ captureException,
343
+ captureMessage,
344
+ close,
345
+ createErrorBoundary,
346
+ createNavigationListener,
347
+ flush,
348
+ getClient,
349
+ init,
350
+ isOverseerInitialized,
351
+ setDeviceInfo,
352
+ setTags,
353
+ setUser,
354
+ trackAppStateChange,
355
+ trackScreenView
356
+ });