Skip to content

Commit 3e0333a

Browse files
committed
move CrossPlatformRequest to types package
1 parent ff4f97f commit 3e0333a

File tree

8 files changed

+76
-80
lines changed

8 files changed

+76
-80
lines changed

packages/node/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type {
22
Breadcrumb,
33
BreadcrumbHint,
4+
CrossPlatformRequest,
45
Request,
56
SdkInfo,
67
Event,
@@ -15,7 +16,7 @@ export type {
1516
Thread,
1617
User,
1718
} from '@sentry/types';
18-
export type { AddRequestDataToEventOptions, CrossPlatformRequest } from '@sentry/utils';
19+
export type { AddRequestDataToEventOptions } from '@sentry/utils';
1920

2021
export type { NodeOptions } from './types';
2122

packages/node/src/requestDataDeprecated.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
/* eslint-disable deprecation/deprecation */
88
/* eslint-disable @typescript-eslint/no-explicit-any */
9-
import { Event, ExtractedNodeRequestData } from '@sentry/types';
9+
import { CrossPlatformRequest, Event, ExtractedNodeRequestData } from '@sentry/types';
1010
import {
1111
addRequestDataToEvent,
1212
AddRequestDataToEventOptions,
13-
CrossPlatformRequest,
1413
extractRequestData as _extractRequestData,
1514
} from '@sentry/utils';
1615
import * as cookie from 'cookie';

packages/node/src/sdk.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/* eslint-disable max-lines */
22
import { getCurrentHub, getIntegrationsToSetup, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
33
import { getMainCarrier, setHubOnCarrier } from '@sentry/hub';
4-
import { Event, ExtractedNodeRequestData, SessionStatus, StackParser } from '@sentry/types';
4+
import { CrossPlatformRequest, Event, ExtractedNodeRequestData, SessionStatus, StackParser } from '@sentry/types';
55
import {
66
addRequestDataToEvent as _addRequestDataToEvent,
77
AddRequestDataToEventOptions,
88
createStackParser,
9-
CrossPlatformRequest,
109
extractRequestData as _extractRequestData,
1110
getGlobalObject,
1211
logger,

packages/tracing/src/integrations/node/express.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
/* eslint-disable max-lines */
2-
import { Integration, Transaction } from '@sentry/types';
3-
import {
4-
CrossPlatformRequest,
5-
extractPathForTransaction,
6-
getNumberOfUrlSegments,
7-
isRegExp,
8-
logger,
9-
} from '@sentry/utils';
2+
import { CrossPlatformRequest, Integration, Transaction } from '@sentry/types';
3+
import { extractPathForTransaction, getNumberOfUrlSegments, isRegExp, logger } from '@sentry/utils';
104

115
type Method =
126
| 'all'

packages/types/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export type { Mechanism } from './mechanism';
3939
export type { ExtractedNodeRequestData, HttpHeaderValue, Primitive, WorkerLocation } from './misc';
4040
export type { ClientOptions, Options } from './options';
4141
export type { Package } from './package';
42-
export type { PolymorphicEvent } from './polymorphics';
42+
export type { PolymorphicEvent, CrossPlatformRequest } from './polymorphics';
4343
export type { QueryParams, Request } from './request';
4444
export type { Runtime } from './runtime';
4545
export type { CaptureContext, Scope, ScopeContext } from './scope';

packages/types/src/polymorphics.ts

+67
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Event-like interface that's usable in browser and node.
33
*
4+
* Note: Here we mean the kind of events handled by event listeners, not our `Event` type.
5+
*
46
* Property availability taken from https://developer.mozilla.org/en-US/docs/Web/API/Event#browser_compatibility
57
*/
68
export interface PolymorphicEvent {
@@ -9,3 +11,68 @@ export interface PolymorphicEvent {
911
readonly target?: unknown;
1012
readonly currentTarget?: unknown;
1113
}
14+
15+
/** A `Request` type compatible with Node, Express, browser, etc., because everything is optional */
16+
export type CrossPlatformRequest = BaseRequest &
17+
BrowserRequest &
18+
NodeRequest &
19+
ExpressRequest &
20+
KoaRequest &
21+
NextjsRequest;
22+
23+
type BaseRequest = {
24+
method?: string;
25+
url?: string;
26+
};
27+
28+
type BrowserRequest = BaseRequest;
29+
30+
type NodeRequest = BaseRequest & {
31+
headers?: {
32+
[key: string]: string | string[] | undefined;
33+
};
34+
protocol?: string;
35+
socket?: {
36+
encrypted?: boolean;
37+
remoteAddress?: string;
38+
};
39+
};
40+
41+
type KoaRequest = NodeRequest & {
42+
host?: string;
43+
hostname?: string;
44+
ip?: string;
45+
originalUrl?: string;
46+
};
47+
48+
type NextjsRequest = NodeRequest & {
49+
cookies?: {
50+
[key: string]: string;
51+
};
52+
query?: {
53+
[key: string]: any;
54+
};
55+
};
56+
57+
type ExpressRequest = NodeRequest & {
58+
baseUrl?: string;
59+
body?: string | { [key: string]: any };
60+
host?: string;
61+
hostname?: string;
62+
ip?: string;
63+
originalUrl?: string;
64+
route?: {
65+
path: string;
66+
stack: [
67+
{
68+
name: string;
69+
},
70+
];
71+
};
72+
query?: {
73+
[key: string]: any;
74+
};
75+
user?: {
76+
[key: string]: any;
77+
};
78+
};

packages/types/src/transaction.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Baggage } from './baggage';
22
import { MeasurementUnit } from './measurement';
33
import { ExtractedNodeRequestData, Primitive, WorkerLocation } from './misc';
4+
import { CrossPlatformRequest } from './polymorphics';
45
import { Span, SpanContext } from './span';
56
/**
67
* Interface holding Transaction-specific properties

packages/utils/src/requestdata.ts

+1-66
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/* eslint-disable max-lines */
1313
/* eslint-disable @typescript-eslint/no-explicit-any */
1414

15-
import { Event, ExtractedNodeRequestData, Transaction, TransactionSource } from '@sentry/types';
15+
import { CrossPlatformRequest, Event, ExtractedNodeRequestData, Transaction, TransactionSource } from '@sentry/types';
1616

1717
import { isPlainObject, isString } from './is';
1818
import { normalize } from './normalize';
@@ -27,71 +27,6 @@ const DEFAULT_INCLUDES = {
2727
const DEFAULT_REQUEST_INCLUDES = ['cookies', 'data', 'headers', 'method', 'query_string', 'url'];
2828
const DEFAULT_USER_INCLUDES = ['id', 'username', 'email'];
2929

30-
type BaseRequest = {
31-
method?: string;
32-
url?: string;
33-
};
34-
35-
type BrowserRequest = BaseRequest;
36-
37-
type NodeRequest = BaseRequest & {
38-
headers?: {
39-
[key: string]: string | string[] | undefined;
40-
};
41-
protocol?: string;
42-
socket?: {
43-
encrypted?: boolean;
44-
remoteAddress?: string;
45-
};
46-
};
47-
48-
type KoaRequest = NodeRequest & {
49-
host?: string;
50-
hostname?: string;
51-
ip?: string;
52-
originalUrl?: string;
53-
};
54-
55-
type NextjsRequest = NodeRequest & {
56-
cookies?: {
57-
[key: string]: string;
58-
};
59-
query?: {
60-
[key: string]: any;
61-
};
62-
};
63-
64-
type ExpressRequest = NodeRequest & {
65-
baseUrl?: string;
66-
body?: string | { [key: string]: any };
67-
host?: string;
68-
hostname?: string;
69-
ip?: string;
70-
originalUrl?: string;
71-
route?: {
72-
path: string;
73-
stack: [
74-
{
75-
name: string;
76-
},
77-
];
78-
};
79-
query?: {
80-
[key: string]: any;
81-
};
82-
user?: {
83-
[key: string]: any;
84-
};
85-
};
86-
87-
/** A `Request` type compatible with Node, Express, browser, etc., because everything is optional */
88-
export type CrossPlatformRequest = BaseRequest &
89-
BrowserRequest &
90-
NodeRequest &
91-
ExpressRequest &
92-
KoaRequest &
93-
NextjsRequest;
94-
9530
type InjectedNodeDeps = {
9631
cookie: {
9732
parse: (cookieStr: string) => Record<string, string>;

0 commit comments

Comments
 (0)