@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.
- package/LICENSE +21 -0
- package/README.md +341 -0
- package/dist/chunk-PETWPVHU.mjs +1090 -0
- package/dist/index.d.mts +273 -0
- package/dist/index.d.ts +273 -0
- package/dist/index.js +1138 -0
- package/dist/index.mjs +50 -0
- package/dist/integrations/express.d.mts +71 -0
- package/dist/integrations/express.d.ts +71 -0
- package/dist/integrations/express.js +861 -0
- package/dist/integrations/express.mjs +8 -0
- package/dist/integrations/fastify.d.mts +77 -0
- package/dist/integrations/fastify.d.ts +77 -0
- package/dist/integrations/fastify.js +870 -0
- package/dist/integrations/fastify.mjs +10 -0
- package/dist/integrations/nextjs.d.mts +179 -0
- package/dist/integrations/nextjs.d.ts +179 -0
- package/dist/integrations/nextjs.js +901 -0
- package/dist/integrations/nextjs.mjs +16 -0
- package/package.json +74 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Integration
|
|
3
|
+
*
|
|
4
|
+
* Provides error handling for Next.js applications including
|
|
5
|
+
* API routes and server components.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // In your error.tsx (App Router)
|
|
10
|
+
* 'use client';
|
|
11
|
+
*
|
|
12
|
+
* import { Statly } from '@statly/observe-sdk';
|
|
13
|
+
*
|
|
14
|
+
* export default function Error({
|
|
15
|
+
* error,
|
|
16
|
+
* reset,
|
|
17
|
+
* }: {
|
|
18
|
+
* error: Error & { digest?: string };
|
|
19
|
+
* reset: () => void;
|
|
20
|
+
* }) {
|
|
21
|
+
* useEffect(() => {
|
|
22
|
+
* Statly.captureException(error);
|
|
23
|
+
* }, [error]);
|
|
24
|
+
*
|
|
25
|
+
* return <ErrorUI error={error} reset={reset} />;
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // In your API route
|
|
32
|
+
* import { withStatly } from '@statly/observe-sdk/nextjs';
|
|
33
|
+
*
|
|
34
|
+
* export const GET = withStatly(async (request) => {
|
|
35
|
+
* // Your handler code
|
|
36
|
+
* return Response.json({ data: 'ok' });
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
type NextApiRequest = {
|
|
41
|
+
method?: string;
|
|
42
|
+
url?: string;
|
|
43
|
+
headers: Record<string, string | string[] | undefined>;
|
|
44
|
+
query?: Record<string, string | string[]>;
|
|
45
|
+
body?: unknown;
|
|
46
|
+
};
|
|
47
|
+
type NextApiResponse = {
|
|
48
|
+
status: (code: number) => NextApiResponse;
|
|
49
|
+
json: (data: unknown) => void;
|
|
50
|
+
end: () => void;
|
|
51
|
+
};
|
|
52
|
+
type NextApiHandler<T = unknown> = (req: NextApiRequest, res: NextApiResponse) => Promise<T> | T;
|
|
53
|
+
/**
|
|
54
|
+
* Wrap a Next.js Pages API route handler with error tracking
|
|
55
|
+
*/
|
|
56
|
+
declare function withStatlyPagesApi<T>(handler: NextApiHandler<T>): NextApiHandler<T>;
|
|
57
|
+
type NextRequest = {
|
|
58
|
+
method: string;
|
|
59
|
+
url: string;
|
|
60
|
+
headers: Headers;
|
|
61
|
+
nextUrl?: {
|
|
62
|
+
pathname: string;
|
|
63
|
+
searchParams: URLSearchParams;
|
|
64
|
+
};
|
|
65
|
+
json: () => Promise<unknown>;
|
|
66
|
+
};
|
|
67
|
+
type NextRouteHandler = (request: NextRequest, context?: {
|
|
68
|
+
params?: Promise<Record<string, string>>;
|
|
69
|
+
}) => Promise<Response> | Response;
|
|
70
|
+
/**
|
|
71
|
+
* Wrap a Next.js App Router handler with error tracking
|
|
72
|
+
*/
|
|
73
|
+
declare function withStatly<T extends NextRouteHandler>(handler: T): T;
|
|
74
|
+
/**
|
|
75
|
+
* Capture errors from Next.js error boundaries
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // app/error.tsx
|
|
80
|
+
* 'use client';
|
|
81
|
+
*
|
|
82
|
+
* import { captureNextJsError } from '@statly/observe-sdk/nextjs';
|
|
83
|
+
*
|
|
84
|
+
* export default function Error({
|
|
85
|
+
* error,
|
|
86
|
+
* reset,
|
|
87
|
+
* }: {
|
|
88
|
+
* error: Error & { digest?: string };
|
|
89
|
+
* reset: () => void;
|
|
90
|
+
* }) {
|
|
91
|
+
* useEffect(() => {
|
|
92
|
+
* captureNextJsError(error);
|
|
93
|
+
* }, [error]);
|
|
94
|
+
*
|
|
95
|
+
* return <ErrorUI />;
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function captureNextJsError(error: Error & {
|
|
100
|
+
digest?: string;
|
|
101
|
+
}, context?: Record<string, unknown>): string;
|
|
102
|
+
/**
|
|
103
|
+
* Capture errors in getServerSideProps
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* export const getServerSideProps = withStatlyGetServerSideProps(async (context) => {
|
|
108
|
+
* // Your code here
|
|
109
|
+
* return { props: {} };
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function withStatlyGetServerSideProps<Props extends {
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
}, Context extends {
|
|
116
|
+
req?: {
|
|
117
|
+
url?: string;
|
|
118
|
+
};
|
|
119
|
+
resolvedUrl?: string;
|
|
120
|
+
}>(handler: (context: Context) => Promise<{
|
|
121
|
+
props: Props;
|
|
122
|
+
} | {
|
|
123
|
+
redirect: unknown;
|
|
124
|
+
} | {
|
|
125
|
+
notFound: boolean;
|
|
126
|
+
}>): (context: Context) => Promise<{
|
|
127
|
+
props: Props;
|
|
128
|
+
} | {
|
|
129
|
+
redirect: unknown;
|
|
130
|
+
} | {
|
|
131
|
+
notFound: boolean;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Capture errors in getStaticProps
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* export const getStaticProps = withStatlyGetStaticProps(async (context) => {
|
|
139
|
+
* // Your code here
|
|
140
|
+
* return { props: {} };
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function withStatlyGetStaticProps<Props extends {
|
|
145
|
+
[key: string]: unknown;
|
|
146
|
+
}, Context extends {
|
|
147
|
+
params?: Record<string, string>;
|
|
148
|
+
}>(handler: (context: Context) => Promise<{
|
|
149
|
+
props: Props;
|
|
150
|
+
revalidate?: number;
|
|
151
|
+
} | {
|
|
152
|
+
redirect: unknown;
|
|
153
|
+
} | {
|
|
154
|
+
notFound: boolean;
|
|
155
|
+
}>): (context: Context) => Promise<{
|
|
156
|
+
props: Props;
|
|
157
|
+
revalidate?: number;
|
|
158
|
+
} | {
|
|
159
|
+
redirect: unknown;
|
|
160
|
+
} | {
|
|
161
|
+
notFound: boolean;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Server Action wrapper for error tracking
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* 'use server';
|
|
169
|
+
*
|
|
170
|
+
* import { withStatlyServerAction } from '@statly/observe-sdk/nextjs';
|
|
171
|
+
*
|
|
172
|
+
* export const submitForm = withStatlyServerAction(async (formData: FormData) => {
|
|
173
|
+
* // Your code here
|
|
174
|
+
* });
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
declare function withStatlyServerAction<Args extends unknown[], Result>(action: (...args: Args) => Promise<Result>, actionName?: string): (...args: Args) => Promise<Result>;
|
|
178
|
+
|
|
179
|
+
export { captureNextJsError, withStatly, withStatlyGetServerSideProps, withStatlyGetStaticProps, withStatlyPagesApi, withStatlyServerAction };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Integration
|
|
3
|
+
*
|
|
4
|
+
* Provides error handling for Next.js applications including
|
|
5
|
+
* API routes and server components.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // In your error.tsx (App Router)
|
|
10
|
+
* 'use client';
|
|
11
|
+
*
|
|
12
|
+
* import { Statly } from '@statly/observe-sdk';
|
|
13
|
+
*
|
|
14
|
+
* export default function Error({
|
|
15
|
+
* error,
|
|
16
|
+
* reset,
|
|
17
|
+
* }: {
|
|
18
|
+
* error: Error & { digest?: string };
|
|
19
|
+
* reset: () => void;
|
|
20
|
+
* }) {
|
|
21
|
+
* useEffect(() => {
|
|
22
|
+
* Statly.captureException(error);
|
|
23
|
+
* }, [error]);
|
|
24
|
+
*
|
|
25
|
+
* return <ErrorUI error={error} reset={reset} />;
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // In your API route
|
|
32
|
+
* import { withStatly } from '@statly/observe-sdk/nextjs';
|
|
33
|
+
*
|
|
34
|
+
* export const GET = withStatly(async (request) => {
|
|
35
|
+
* // Your handler code
|
|
36
|
+
* return Response.json({ data: 'ok' });
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
type NextApiRequest = {
|
|
41
|
+
method?: string;
|
|
42
|
+
url?: string;
|
|
43
|
+
headers: Record<string, string | string[] | undefined>;
|
|
44
|
+
query?: Record<string, string | string[]>;
|
|
45
|
+
body?: unknown;
|
|
46
|
+
};
|
|
47
|
+
type NextApiResponse = {
|
|
48
|
+
status: (code: number) => NextApiResponse;
|
|
49
|
+
json: (data: unknown) => void;
|
|
50
|
+
end: () => void;
|
|
51
|
+
};
|
|
52
|
+
type NextApiHandler<T = unknown> = (req: NextApiRequest, res: NextApiResponse) => Promise<T> | T;
|
|
53
|
+
/**
|
|
54
|
+
* Wrap a Next.js Pages API route handler with error tracking
|
|
55
|
+
*/
|
|
56
|
+
declare function withStatlyPagesApi<T>(handler: NextApiHandler<T>): NextApiHandler<T>;
|
|
57
|
+
type NextRequest = {
|
|
58
|
+
method: string;
|
|
59
|
+
url: string;
|
|
60
|
+
headers: Headers;
|
|
61
|
+
nextUrl?: {
|
|
62
|
+
pathname: string;
|
|
63
|
+
searchParams: URLSearchParams;
|
|
64
|
+
};
|
|
65
|
+
json: () => Promise<unknown>;
|
|
66
|
+
};
|
|
67
|
+
type NextRouteHandler = (request: NextRequest, context?: {
|
|
68
|
+
params?: Promise<Record<string, string>>;
|
|
69
|
+
}) => Promise<Response> | Response;
|
|
70
|
+
/**
|
|
71
|
+
* Wrap a Next.js App Router handler with error tracking
|
|
72
|
+
*/
|
|
73
|
+
declare function withStatly<T extends NextRouteHandler>(handler: T): T;
|
|
74
|
+
/**
|
|
75
|
+
* Capture errors from Next.js error boundaries
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // app/error.tsx
|
|
80
|
+
* 'use client';
|
|
81
|
+
*
|
|
82
|
+
* import { captureNextJsError } from '@statly/observe-sdk/nextjs';
|
|
83
|
+
*
|
|
84
|
+
* export default function Error({
|
|
85
|
+
* error,
|
|
86
|
+
* reset,
|
|
87
|
+
* }: {
|
|
88
|
+
* error: Error & { digest?: string };
|
|
89
|
+
* reset: () => void;
|
|
90
|
+
* }) {
|
|
91
|
+
* useEffect(() => {
|
|
92
|
+
* captureNextJsError(error);
|
|
93
|
+
* }, [error]);
|
|
94
|
+
*
|
|
95
|
+
* return <ErrorUI />;
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function captureNextJsError(error: Error & {
|
|
100
|
+
digest?: string;
|
|
101
|
+
}, context?: Record<string, unknown>): string;
|
|
102
|
+
/**
|
|
103
|
+
* Capture errors in getServerSideProps
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* export const getServerSideProps = withStatlyGetServerSideProps(async (context) => {
|
|
108
|
+
* // Your code here
|
|
109
|
+
* return { props: {} };
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function withStatlyGetServerSideProps<Props extends {
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
}, Context extends {
|
|
116
|
+
req?: {
|
|
117
|
+
url?: string;
|
|
118
|
+
};
|
|
119
|
+
resolvedUrl?: string;
|
|
120
|
+
}>(handler: (context: Context) => Promise<{
|
|
121
|
+
props: Props;
|
|
122
|
+
} | {
|
|
123
|
+
redirect: unknown;
|
|
124
|
+
} | {
|
|
125
|
+
notFound: boolean;
|
|
126
|
+
}>): (context: Context) => Promise<{
|
|
127
|
+
props: Props;
|
|
128
|
+
} | {
|
|
129
|
+
redirect: unknown;
|
|
130
|
+
} | {
|
|
131
|
+
notFound: boolean;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Capture errors in getStaticProps
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* export const getStaticProps = withStatlyGetStaticProps(async (context) => {
|
|
139
|
+
* // Your code here
|
|
140
|
+
* return { props: {} };
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function withStatlyGetStaticProps<Props extends {
|
|
145
|
+
[key: string]: unknown;
|
|
146
|
+
}, Context extends {
|
|
147
|
+
params?: Record<string, string>;
|
|
148
|
+
}>(handler: (context: Context) => Promise<{
|
|
149
|
+
props: Props;
|
|
150
|
+
revalidate?: number;
|
|
151
|
+
} | {
|
|
152
|
+
redirect: unknown;
|
|
153
|
+
} | {
|
|
154
|
+
notFound: boolean;
|
|
155
|
+
}>): (context: Context) => Promise<{
|
|
156
|
+
props: Props;
|
|
157
|
+
revalidate?: number;
|
|
158
|
+
} | {
|
|
159
|
+
redirect: unknown;
|
|
160
|
+
} | {
|
|
161
|
+
notFound: boolean;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Server Action wrapper for error tracking
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* 'use server';
|
|
169
|
+
*
|
|
170
|
+
* import { withStatlyServerAction } from '@statly/observe-sdk/nextjs';
|
|
171
|
+
*
|
|
172
|
+
* export const submitForm = withStatlyServerAction(async (formData: FormData) => {
|
|
173
|
+
* // Your code here
|
|
174
|
+
* });
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
declare function withStatlyServerAction<Args extends unknown[], Result>(action: (...args: Args) => Promise<Result>, actionName?: string): (...args: Args) => Promise<Result>;
|
|
178
|
+
|
|
179
|
+
export { captureNextJsError, withStatly, withStatlyGetServerSideProps, withStatlyGetStaticProps, withStatlyPagesApi, withStatlyServerAction };
|