@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,8 @@
1
+ import {
2
+ expressErrorHandler,
3
+ requestHandler
4
+ } from "../chunk-PETWPVHU.mjs";
5
+ export {
6
+ expressErrorHandler,
7
+ requestHandler
8
+ };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Fastify Integration
3
+ *
4
+ * Provides plugin for error handling in Fastify applications.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import Fastify from 'fastify';
9
+ * import { Statly } from '@statly/observe-sdk';
10
+ * import { statlyFastifyPlugin } from '@statly/observe-sdk/fastify';
11
+ *
12
+ * const fastify = Fastify();
13
+ *
14
+ * // Initialize Statly
15
+ * Statly.init({ dsn: 'your-dsn' });
16
+ *
17
+ * // Register the plugin
18
+ * fastify.register(statlyFastifyPlugin);
19
+ *
20
+ * // Your routes here
21
+ * fastify.get('/', async (request, reply) => { ... });
22
+ * ```
23
+ */
24
+ interface FastifyRequest {
25
+ id: string;
26
+ method: string;
27
+ url: string;
28
+ routerPath?: string;
29
+ headers: Record<string, string | string[] | undefined>;
30
+ query?: Record<string, string>;
31
+ params?: Record<string, string>;
32
+ body?: unknown;
33
+ ip?: string;
34
+ ips?: string[];
35
+ }
36
+ interface FastifyReply {
37
+ statusCode: number;
38
+ sent: boolean;
39
+ }
40
+ interface FastifyError extends Error {
41
+ statusCode?: number;
42
+ code?: string;
43
+ validation?: unknown[];
44
+ }
45
+ interface FastifyInstance {
46
+ addHook(hook: string, handler: (request: FastifyRequest, reply: FastifyReply, done: () => void) => void): void;
47
+ setErrorHandler(handler: (error: FastifyError, request: FastifyRequest, reply: FastifyReply) => void): void;
48
+ decorate(name: string, value: unknown): void;
49
+ }
50
+ interface StatlyFastifyPluginOptions {
51
+ /**
52
+ * Whether to capture validation errors (default: true)
53
+ */
54
+ captureValidationErrors?: boolean;
55
+ /**
56
+ * Custom function to determine if an error should be captured
57
+ */
58
+ shouldCapture?: (error: FastifyError) => boolean;
59
+ /**
60
+ * Skip capturing errors with these status codes
61
+ */
62
+ skipStatusCodes?: number[];
63
+ }
64
+ /**
65
+ * Fastify plugin for Statly error tracking
66
+ */
67
+ declare function statlyFastifyPlugin(fastify: FastifyInstance, options: StatlyFastifyPluginOptions, done: () => void): void;
68
+ /**
69
+ * Alternative export as a standard Fastify plugin
70
+ */
71
+ declare const statlyPlugin: typeof statlyFastifyPlugin;
72
+ /**
73
+ * Create a request-scoped error capture function
74
+ */
75
+ declare function createRequestCapture(request: FastifyRequest): (error: Error, additionalContext?: Record<string, unknown>) => string;
76
+
77
+ export { createRequestCapture, statlyFastifyPlugin, statlyPlugin };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Fastify Integration
3
+ *
4
+ * Provides plugin for error handling in Fastify applications.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import Fastify from 'fastify';
9
+ * import { Statly } from '@statly/observe-sdk';
10
+ * import { statlyFastifyPlugin } from '@statly/observe-sdk/fastify';
11
+ *
12
+ * const fastify = Fastify();
13
+ *
14
+ * // Initialize Statly
15
+ * Statly.init({ dsn: 'your-dsn' });
16
+ *
17
+ * // Register the plugin
18
+ * fastify.register(statlyFastifyPlugin);
19
+ *
20
+ * // Your routes here
21
+ * fastify.get('/', async (request, reply) => { ... });
22
+ * ```
23
+ */
24
+ interface FastifyRequest {
25
+ id: string;
26
+ method: string;
27
+ url: string;
28
+ routerPath?: string;
29
+ headers: Record<string, string | string[] | undefined>;
30
+ query?: Record<string, string>;
31
+ params?: Record<string, string>;
32
+ body?: unknown;
33
+ ip?: string;
34
+ ips?: string[];
35
+ }
36
+ interface FastifyReply {
37
+ statusCode: number;
38
+ sent: boolean;
39
+ }
40
+ interface FastifyError extends Error {
41
+ statusCode?: number;
42
+ code?: string;
43
+ validation?: unknown[];
44
+ }
45
+ interface FastifyInstance {
46
+ addHook(hook: string, handler: (request: FastifyRequest, reply: FastifyReply, done: () => void) => void): void;
47
+ setErrorHandler(handler: (error: FastifyError, request: FastifyRequest, reply: FastifyReply) => void): void;
48
+ decorate(name: string, value: unknown): void;
49
+ }
50
+ interface StatlyFastifyPluginOptions {
51
+ /**
52
+ * Whether to capture validation errors (default: true)
53
+ */
54
+ captureValidationErrors?: boolean;
55
+ /**
56
+ * Custom function to determine if an error should be captured
57
+ */
58
+ shouldCapture?: (error: FastifyError) => boolean;
59
+ /**
60
+ * Skip capturing errors with these status codes
61
+ */
62
+ skipStatusCodes?: number[];
63
+ }
64
+ /**
65
+ * Fastify plugin for Statly error tracking
66
+ */
67
+ declare function statlyFastifyPlugin(fastify: FastifyInstance, options: StatlyFastifyPluginOptions, done: () => void): void;
68
+ /**
69
+ * Alternative export as a standard Fastify plugin
70
+ */
71
+ declare const statlyPlugin: typeof statlyFastifyPlugin;
72
+ /**
73
+ * Create a request-scoped error capture function
74
+ */
75
+ declare function createRequestCapture(request: FastifyRequest): (error: Error, additionalContext?: Record<string, unknown>) => string;
76
+
77
+ export { createRequestCapture, statlyFastifyPlugin, statlyPlugin };