@statly/observe 0.1.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.
@@ -0,0 +1,273 @@
1
+ export { expressErrorHandler, requestHandler } from './integrations/express.mjs';
2
+ export { captureNextJsError, withStatly, withStatlyGetServerSideProps, withStatlyGetStaticProps, withStatlyPagesApi, withStatlyServerAction } from './integrations/nextjs.mjs';
3
+ export { createRequestCapture, statlyFastifyPlugin, statlyPlugin } from './integrations/fastify.mjs';
4
+
5
+ /**
6
+ * Statly Observe SDK Types
7
+ */
8
+ interface StatlyOptions {
9
+ /** DSN for your organization: https://<api-key>@statly.live/<org-slug> */
10
+ dsn: string;
11
+ /** Release/version identifier */
12
+ release?: string;
13
+ /** Environment (e.g., 'production', 'staging', 'development') */
14
+ environment?: string;
15
+ /** Enable debug logging */
16
+ debug?: boolean;
17
+ /** Sample rate for error events (0.0 to 1.0) */
18
+ sampleRate?: number;
19
+ /** Maximum breadcrumbs to capture */
20
+ maxBreadcrumbs?: number;
21
+ /** Auto-attach global error handlers */
22
+ autoCapture?: boolean;
23
+ /** Capture console errors as breadcrumbs */
24
+ captureConsole?: boolean;
25
+ /** Capture XHR/fetch requests as breadcrumbs */
26
+ captureNetwork?: boolean;
27
+ /** Custom tags to attach to all events */
28
+ tags?: Record<string, string>;
29
+ /** Before send hook - return null to drop the event */
30
+ beforeSend?: (event: StatlyEvent) => StatlyEvent | null;
31
+ }
32
+ interface User {
33
+ id?: string;
34
+ email?: string;
35
+ name?: string;
36
+ username?: string;
37
+ [key: string]: unknown;
38
+ }
39
+ interface Breadcrumb {
40
+ timestamp?: number;
41
+ category?: string;
42
+ message?: string;
43
+ level?: 'debug' | 'info' | 'warning' | 'error';
44
+ data?: Record<string, unknown>;
45
+ }
46
+ interface StackFrame {
47
+ filename?: string;
48
+ function?: string;
49
+ lineno?: number;
50
+ colno?: number;
51
+ in_app?: boolean;
52
+ context_line?: string;
53
+ pre_context?: string[];
54
+ post_context?: string[];
55
+ }
56
+ interface Exception {
57
+ type?: string;
58
+ value?: string;
59
+ stacktrace?: {
60
+ frames?: StackFrame[];
61
+ };
62
+ }
63
+ interface BrowserInfo {
64
+ name?: string;
65
+ version?: string;
66
+ }
67
+ interface OSInfo {
68
+ name?: string;
69
+ version?: string;
70
+ }
71
+ interface DeviceInfo {
72
+ type?: string;
73
+ model?: string;
74
+ vendor?: string;
75
+ }
76
+ interface StatlyEvent {
77
+ message: string;
78
+ timestamp?: number;
79
+ level?: 'debug' | 'info' | 'warning' | 'error' | 'fatal';
80
+ stack?: string;
81
+ exception?: Exception;
82
+ environment?: string;
83
+ release?: string;
84
+ url?: string;
85
+ user?: User;
86
+ tags?: Record<string, string>;
87
+ extra?: Record<string, unknown>;
88
+ breadcrumbs?: Breadcrumb[];
89
+ browser?: BrowserInfo;
90
+ os?: OSInfo;
91
+ device?: DeviceInfo;
92
+ sdk?: {
93
+ name: string;
94
+ version: string;
95
+ };
96
+ fingerprint?: string[];
97
+ }
98
+ type EventLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';
99
+
100
+ /**
101
+ * Statly Observe Client
102
+ * Main SDK entry point for error tracking
103
+ */
104
+
105
+ declare class StatlyClient {
106
+ private options;
107
+ private transport;
108
+ private breadcrumbs;
109
+ private globalHandlers;
110
+ private consoleIntegration;
111
+ private user;
112
+ private initialized;
113
+ constructor(options: StatlyOptions);
114
+ private mergeOptions;
115
+ private detectEnvironment;
116
+ /**
117
+ * Initialize the SDK
118
+ */
119
+ init(): void;
120
+ /**
121
+ * Capture an exception/error
122
+ */
123
+ captureException(error: Error | unknown, context?: Record<string, unknown>): string;
124
+ /**
125
+ * Capture a message
126
+ */
127
+ captureMessage(message: string, level?: EventLevel): string;
128
+ /**
129
+ * Internal method to capture an error
130
+ */
131
+ private captureError;
132
+ /**
133
+ * Build a complete event from partial data
134
+ */
135
+ private buildEvent;
136
+ /**
137
+ * Parse a stack trace string into structured frames
138
+ */
139
+ private parseStackTrace;
140
+ /**
141
+ * Send an event to the server
142
+ */
143
+ private sendEvent;
144
+ private generateEventId;
145
+ /**
146
+ * Set user context
147
+ */
148
+ setUser(user: User | null): void;
149
+ /**
150
+ * Set a single tag
151
+ */
152
+ setTag(key: string, value: string): void;
153
+ /**
154
+ * Set multiple tags
155
+ */
156
+ setTags(tags: Record<string, string>): void;
157
+ /**
158
+ * Add a breadcrumb
159
+ */
160
+ addBreadcrumb(breadcrumb: Omit<Breadcrumb, 'timestamp'>): void;
161
+ /**
162
+ * Get browser info
163
+ */
164
+ private getBrowserInfo;
165
+ /**
166
+ * Get OS info
167
+ */
168
+ private getOSInfo;
169
+ /**
170
+ * Flush pending events and clean up
171
+ */
172
+ close(): Promise<void>;
173
+ /**
174
+ * Force flush pending events
175
+ */
176
+ flush(): Promise<void>;
177
+ }
178
+
179
+ /**
180
+ * Statly Observe SDK
181
+ *
182
+ * Error tracking and monitoring for JavaScript applications.
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * import { Statly } from '@statly/observe-sdk';
187
+ *
188
+ * Statly.init({
189
+ * dsn: 'https://sk_live_xxx@statly.live/your-org',
190
+ * release: '1.0.0',
191
+ * environment: 'production',
192
+ * });
193
+ *
194
+ * // Errors are captured automatically
195
+ *
196
+ * // Manual capture
197
+ * try {
198
+ * riskyOperation();
199
+ * } catch (error) {
200
+ * Statly.captureException(error);
201
+ * }
202
+ *
203
+ * // Capture a message
204
+ * Statly.captureMessage('Something happened', 'warning');
205
+ *
206
+ * // Set user context
207
+ * Statly.setUser({
208
+ * id: 'user-123',
209
+ * email: 'user@example.com',
210
+ * });
211
+ *
212
+ * // Add breadcrumb
213
+ * Statly.addBreadcrumb({
214
+ * category: 'auth',
215
+ * message: 'User logged in',
216
+ * });
217
+ * ```
218
+ */
219
+
220
+ /**
221
+ * Initialize the Statly SDK
222
+ */
223
+ declare function init(options: StatlyOptions): void;
224
+ /**
225
+ * Capture an exception
226
+ */
227
+ declare function captureException(error: Error | unknown, context?: Record<string, unknown>): string;
228
+ /**
229
+ * Capture a message
230
+ */
231
+ declare function captureMessage(message: string, level?: EventLevel): string;
232
+ /**
233
+ * Set user context
234
+ */
235
+ declare function setUser(user: User | null): void;
236
+ /**
237
+ * Set a tag
238
+ */
239
+ declare function setTag(key: string, value: string): void;
240
+ /**
241
+ * Set multiple tags
242
+ */
243
+ declare function setTags(tags: Record<string, string>): void;
244
+ /**
245
+ * Add a breadcrumb
246
+ */
247
+ declare function addBreadcrumb(breadcrumb: Omit<Breadcrumb, 'timestamp'>): void;
248
+ /**
249
+ * Flush pending events
250
+ */
251
+ declare function flush(): Promise<void>;
252
+ /**
253
+ * Close the SDK and flush pending events
254
+ */
255
+ declare function close(): Promise<void>;
256
+ /**
257
+ * Get the current client instance
258
+ */
259
+ declare function getClient(): StatlyClient | null;
260
+ declare const Statly: {
261
+ readonly init: typeof init;
262
+ readonly captureException: typeof captureException;
263
+ readonly captureMessage: typeof captureMessage;
264
+ readonly setUser: typeof setUser;
265
+ readonly setTag: typeof setTag;
266
+ readonly setTags: typeof setTags;
267
+ readonly addBreadcrumb: typeof addBreadcrumb;
268
+ readonly flush: typeof flush;
269
+ readonly close: typeof close;
270
+ readonly getClient: typeof getClient;
271
+ };
272
+
273
+ export { type Breadcrumb, type BrowserInfo, type DeviceInfo, type EventLevel, type Exception, type OSInfo, type StackFrame, Statly, StatlyClient, type StatlyEvent, type StatlyOptions, type User, addBreadcrumb, captureException, captureMessage, close, flush, getClient, init, setTag, setTags, setUser };
@@ -0,0 +1,273 @@
1
+ export { expressErrorHandler, requestHandler } from './integrations/express.js';
2
+ export { captureNextJsError, withStatly, withStatlyGetServerSideProps, withStatlyGetStaticProps, withStatlyPagesApi, withStatlyServerAction } from './integrations/nextjs.js';
3
+ export { createRequestCapture, statlyFastifyPlugin, statlyPlugin } from './integrations/fastify.js';
4
+
5
+ /**
6
+ * Statly Observe SDK Types
7
+ */
8
+ interface StatlyOptions {
9
+ /** DSN for your organization: https://<api-key>@statly.live/<org-slug> */
10
+ dsn: string;
11
+ /** Release/version identifier */
12
+ release?: string;
13
+ /** Environment (e.g., 'production', 'staging', 'development') */
14
+ environment?: string;
15
+ /** Enable debug logging */
16
+ debug?: boolean;
17
+ /** Sample rate for error events (0.0 to 1.0) */
18
+ sampleRate?: number;
19
+ /** Maximum breadcrumbs to capture */
20
+ maxBreadcrumbs?: number;
21
+ /** Auto-attach global error handlers */
22
+ autoCapture?: boolean;
23
+ /** Capture console errors as breadcrumbs */
24
+ captureConsole?: boolean;
25
+ /** Capture XHR/fetch requests as breadcrumbs */
26
+ captureNetwork?: boolean;
27
+ /** Custom tags to attach to all events */
28
+ tags?: Record<string, string>;
29
+ /** Before send hook - return null to drop the event */
30
+ beforeSend?: (event: StatlyEvent) => StatlyEvent | null;
31
+ }
32
+ interface User {
33
+ id?: string;
34
+ email?: string;
35
+ name?: string;
36
+ username?: string;
37
+ [key: string]: unknown;
38
+ }
39
+ interface Breadcrumb {
40
+ timestamp?: number;
41
+ category?: string;
42
+ message?: string;
43
+ level?: 'debug' | 'info' | 'warning' | 'error';
44
+ data?: Record<string, unknown>;
45
+ }
46
+ interface StackFrame {
47
+ filename?: string;
48
+ function?: string;
49
+ lineno?: number;
50
+ colno?: number;
51
+ in_app?: boolean;
52
+ context_line?: string;
53
+ pre_context?: string[];
54
+ post_context?: string[];
55
+ }
56
+ interface Exception {
57
+ type?: string;
58
+ value?: string;
59
+ stacktrace?: {
60
+ frames?: StackFrame[];
61
+ };
62
+ }
63
+ interface BrowserInfo {
64
+ name?: string;
65
+ version?: string;
66
+ }
67
+ interface OSInfo {
68
+ name?: string;
69
+ version?: string;
70
+ }
71
+ interface DeviceInfo {
72
+ type?: string;
73
+ model?: string;
74
+ vendor?: string;
75
+ }
76
+ interface StatlyEvent {
77
+ message: string;
78
+ timestamp?: number;
79
+ level?: 'debug' | 'info' | 'warning' | 'error' | 'fatal';
80
+ stack?: string;
81
+ exception?: Exception;
82
+ environment?: string;
83
+ release?: string;
84
+ url?: string;
85
+ user?: User;
86
+ tags?: Record<string, string>;
87
+ extra?: Record<string, unknown>;
88
+ breadcrumbs?: Breadcrumb[];
89
+ browser?: BrowserInfo;
90
+ os?: OSInfo;
91
+ device?: DeviceInfo;
92
+ sdk?: {
93
+ name: string;
94
+ version: string;
95
+ };
96
+ fingerprint?: string[];
97
+ }
98
+ type EventLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';
99
+
100
+ /**
101
+ * Statly Observe Client
102
+ * Main SDK entry point for error tracking
103
+ */
104
+
105
+ declare class StatlyClient {
106
+ private options;
107
+ private transport;
108
+ private breadcrumbs;
109
+ private globalHandlers;
110
+ private consoleIntegration;
111
+ private user;
112
+ private initialized;
113
+ constructor(options: StatlyOptions);
114
+ private mergeOptions;
115
+ private detectEnvironment;
116
+ /**
117
+ * Initialize the SDK
118
+ */
119
+ init(): void;
120
+ /**
121
+ * Capture an exception/error
122
+ */
123
+ captureException(error: Error | unknown, context?: Record<string, unknown>): string;
124
+ /**
125
+ * Capture a message
126
+ */
127
+ captureMessage(message: string, level?: EventLevel): string;
128
+ /**
129
+ * Internal method to capture an error
130
+ */
131
+ private captureError;
132
+ /**
133
+ * Build a complete event from partial data
134
+ */
135
+ private buildEvent;
136
+ /**
137
+ * Parse a stack trace string into structured frames
138
+ */
139
+ private parseStackTrace;
140
+ /**
141
+ * Send an event to the server
142
+ */
143
+ private sendEvent;
144
+ private generateEventId;
145
+ /**
146
+ * Set user context
147
+ */
148
+ setUser(user: User | null): void;
149
+ /**
150
+ * Set a single tag
151
+ */
152
+ setTag(key: string, value: string): void;
153
+ /**
154
+ * Set multiple tags
155
+ */
156
+ setTags(tags: Record<string, string>): void;
157
+ /**
158
+ * Add a breadcrumb
159
+ */
160
+ addBreadcrumb(breadcrumb: Omit<Breadcrumb, 'timestamp'>): void;
161
+ /**
162
+ * Get browser info
163
+ */
164
+ private getBrowserInfo;
165
+ /**
166
+ * Get OS info
167
+ */
168
+ private getOSInfo;
169
+ /**
170
+ * Flush pending events and clean up
171
+ */
172
+ close(): Promise<void>;
173
+ /**
174
+ * Force flush pending events
175
+ */
176
+ flush(): Promise<void>;
177
+ }
178
+
179
+ /**
180
+ * Statly Observe SDK
181
+ *
182
+ * Error tracking and monitoring for JavaScript applications.
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * import { Statly } from '@statly/observe-sdk';
187
+ *
188
+ * Statly.init({
189
+ * dsn: 'https://sk_live_xxx@statly.live/your-org',
190
+ * release: '1.0.0',
191
+ * environment: 'production',
192
+ * });
193
+ *
194
+ * // Errors are captured automatically
195
+ *
196
+ * // Manual capture
197
+ * try {
198
+ * riskyOperation();
199
+ * } catch (error) {
200
+ * Statly.captureException(error);
201
+ * }
202
+ *
203
+ * // Capture a message
204
+ * Statly.captureMessage('Something happened', 'warning');
205
+ *
206
+ * // Set user context
207
+ * Statly.setUser({
208
+ * id: 'user-123',
209
+ * email: 'user@example.com',
210
+ * });
211
+ *
212
+ * // Add breadcrumb
213
+ * Statly.addBreadcrumb({
214
+ * category: 'auth',
215
+ * message: 'User logged in',
216
+ * });
217
+ * ```
218
+ */
219
+
220
+ /**
221
+ * Initialize the Statly SDK
222
+ */
223
+ declare function init(options: StatlyOptions): void;
224
+ /**
225
+ * Capture an exception
226
+ */
227
+ declare function captureException(error: Error | unknown, context?: Record<string, unknown>): string;
228
+ /**
229
+ * Capture a message
230
+ */
231
+ declare function captureMessage(message: string, level?: EventLevel): string;
232
+ /**
233
+ * Set user context
234
+ */
235
+ declare function setUser(user: User | null): void;
236
+ /**
237
+ * Set a tag
238
+ */
239
+ declare function setTag(key: string, value: string): void;
240
+ /**
241
+ * Set multiple tags
242
+ */
243
+ declare function setTags(tags: Record<string, string>): void;
244
+ /**
245
+ * Add a breadcrumb
246
+ */
247
+ declare function addBreadcrumb(breadcrumb: Omit<Breadcrumb, 'timestamp'>): void;
248
+ /**
249
+ * Flush pending events
250
+ */
251
+ declare function flush(): Promise<void>;
252
+ /**
253
+ * Close the SDK and flush pending events
254
+ */
255
+ declare function close(): Promise<void>;
256
+ /**
257
+ * Get the current client instance
258
+ */
259
+ declare function getClient(): StatlyClient | null;
260
+ declare const Statly: {
261
+ readonly init: typeof init;
262
+ readonly captureException: typeof captureException;
263
+ readonly captureMessage: typeof captureMessage;
264
+ readonly setUser: typeof setUser;
265
+ readonly setTag: typeof setTag;
266
+ readonly setTags: typeof setTags;
267
+ readonly addBreadcrumb: typeof addBreadcrumb;
268
+ readonly flush: typeof flush;
269
+ readonly close: typeof close;
270
+ readonly getClient: typeof getClient;
271
+ };
272
+
273
+ export { type Breadcrumb, type BrowserInfo, type DeviceInfo, type EventLevel, type Exception, type OSInfo, type StackFrame, Statly, StatlyClient, type StatlyEvent, type StatlyOptions, type User, addBreadcrumb, captureException, captureMessage, close, flush, getClient, init, setTag, setTags, setUser };