@@ -12,7 +12,7 @@ import {
12
12
import * as domain from 'domain' ;
13
13
import { NextApiRequest , NextApiResponse } from 'next' ;
14
14
15
- // These are the same as the official `NextApiHandler` type, except
15
+ // The `NextApiHandler` and `WrappedNextApiHandler` types are the same as the official `NextApiHandler` type, except:
16
16
//
17
17
// a) The wrapped version returns only promises, because wrapped handlers are always async.
18
18
//
@@ -26,13 +26,23 @@ import { NextApiRequest, NextApiResponse } from 'next';
26
26
// type here would break the test app's build, because it would set up a situation in which the linked SDK's
27
27
// `withSentry` would refer to one version of the type (from the local repo's `node_modules`) while any typed handler in
28
28
// the test app would refer to the other version of the type (from the test app's `node_modules`). By using a custom
29
- // version of the type compatible with both the old and new official versions, we can use any Next version we want in
30
- // a test app without worrying about type errors.
31
- export type NextApiHandler = (
32
- req : NextApiRequest ,
33
- res : NextApiResponse ,
34
- ) => void | Promise < void > | unknown | Promise < unknown > ;
35
- export type WrappedNextApiHandler = ( req : NextApiRequest , res : NextApiResponse ) => Promise < void > | Promise < unknown > ;
29
+ // version of the type compatible with both the old and new official versions, we can use any Next version we want in a
30
+ // test app without worrying about type errors.
31
+ //
32
+ // c) These have internal SDK flags which the official Next types obviously don't have, one to allow our auto-wrapping
33
+ // function, `withSentryAPI`, to pass the parameterized route into `withSentry`, and the other to prevent a manually
34
+ // wrapped route from being wrapped again by the auto-wrapper.
35
+
36
+ export type NextApiHandler = {
37
+ __sentry_route__ ?: string ;
38
+ ( req : NextApiRequest , res : NextApiResponse ) : void | Promise < void > | unknown | Promise < unknown > ;
39
+ } ;
40
+
41
+ export type WrappedNextApiHandler = {
42
+ __sentry_route__ ?: string ;
43
+ __sentry_wrapped__ ?: boolean ;
44
+ ( req : NextApiRequest , res : NextApiResponse ) : Promise < void > | Promise < unknown > ;
45
+ } ;
36
46
37
47
export type AugmentedNextApiResponse = NextApiResponse & {
38
48
__sentryTransaction ?: Transaction ;
0 commit comments