@@ -9,25 +9,46 @@ import { sentryCaptureErrorHook } from '../hooks/captureErrorHook';
99import { updateRouteBeforeResponse } from '../hooks/updateRouteBeforeResponse' ;
1010import { addSentryTracingMetaTags } from '../utils' ;
1111
12- interface CfEventType {
12+ interface EventBase {
1313 protocol : string ;
1414 host : string ;
1515 method : string ;
1616 headers : Record < string , string > ;
17+ }
18+
19+ interface MinimalCfProps {
20+ httpProtocol ?: string ;
21+ country ?: string ;
22+ // ...other CF properties
23+ }
24+
25+ interface MinimalCloudflareProps {
26+ context : ExecutionContext ;
27+ request ?: Record < string , unknown > ;
28+ env ?: Record < string , unknown > ;
29+ }
30+
31+ // Direct shape: cf and cloudflare are directly on context
32+ interface CfEventDirect extends EventBase {
1733 context : {
18- cf : {
19- httpProtocol ?: string ;
20- country ?: string ;
21- // ...other CF properties
22- } ;
23- cloudflare : {
24- context : ExecutionContext ;
25- request ?: Record < string , unknown > ;
26- env ?: Record < string , unknown > ;
34+ cf : MinimalCfProps ;
35+ cloudflare : MinimalCloudflareProps ;
36+ } ;
37+ }
38+
39+ // Nested shape: cf and cloudflare are under _platform
40+ // Since Nitro v2.12.0 (PR: https://github.com/nitrojs/nitro/commit/911a63bc478183acb472d05e977584dcdce61abf)
41+ interface CfEventPlatform extends EventBase {
42+ context : {
43+ _platform : {
44+ cf : MinimalCfProps ;
45+ cloudflare : MinimalCloudflareProps ;
2746 } ;
2847 } ;
2948}
3049
50+ type CfEventType = CfEventDirect | CfEventPlatform ;
51+
3152function isEventType ( event : unknown ) : event is CfEventType {
3253 if ( event === null || typeof event !== 'object' ) return false ;
3354
0 commit comments