Skip to content

Commit 6df9533

Browse files
committed
feat(types): Move NewTransport types into types package
1 parent 961d3af commit 6df9533

File tree

4 files changed

+67
-49
lines changed

4 files changed

+67
-49
lines changed

packages/core/src/transports/base.ts

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Envelope, EventStatus } from '@sentry/types';
1+
import {
2+
Envelope,
3+
InternalBaseTransportOptions,
4+
NewTransport,
5+
TransportCategory,
6+
TransportRequest,
7+
TransportRequestExecutor,
8+
TransportResponse,
9+
} from '@sentry/types';
210
import {
311
disabledUntil,
412
eventStatusFromHttpCode,
@@ -21,50 +29,6 @@ export const ATTACHMENT_TRANSPORT_CATEGORY = 'attachment';
2129

2230
export const SESSION_TRANSPORT_CATEGORY = 'session';
2331

24-
type TransportCategory =
25-
| typeof ERROR_TRANSPORT_CATEGORY
26-
| typeof TRANSACTION_TRANSPORT_CATEGORY
27-
| typeof ATTACHMENT_TRANSPORT_CATEGORY
28-
| typeof SESSION_TRANSPORT_CATEGORY;
29-
30-
export type TransportRequest = {
31-
body: string;
32-
category: TransportCategory;
33-
};
34-
35-
export type TransportMakeRequestResponse = {
36-
body?: string;
37-
headers?: {
38-
[key: string]: string | null;
39-
'x-sentry-rate-limits': string | null;
40-
'retry-after': string | null;
41-
};
42-
reason?: string;
43-
statusCode: number;
44-
};
45-
46-
export type TransportResponse = {
47-
status: EventStatus;
48-
reason?: string;
49-
};
50-
51-
interface InternalBaseTransportOptions {
52-
bufferSize?: number;
53-
}
54-
export interface BaseTransportOptions extends InternalBaseTransportOptions {
55-
// url to send the event
56-
// transport does not care about dsn specific - client should take care of
57-
// parsing and figuring that out
58-
url: string;
59-
}
60-
61-
export interface NewTransport {
62-
send(request: Envelope): PromiseLike<TransportResponse>;
63-
flush(timeout?: number): PromiseLike<boolean>;
64-
}
65-
66-
export type TransportRequestExecutor = (request: TransportRequest) => PromiseLike<TransportMakeRequestResponse>;
67-
6832
export const DEFAULT_TRANSPORT_BUFFER_SIZE = 30;
6933

7034
/**

packages/types/src/client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Options } from './options';
55
import { Scope } from './scope';
66
import { Session } from './session';
77
import { Severity, SeverityLevel } from './severity';
8-
import { Transport } from './transport';
8+
import { NewTransport } from './transport';
99

1010
/**
1111
* User-Facing Sentry SDK Client.
@@ -68,11 +68,10 @@ export interface Client<O extends Options = Options> {
6868

6969
/**
7070
* Returns the transport that is used by the client.
71-
* Please note that the transport gets lazy initialized so it will only be there once the first event has been sent.
7271
*
7372
* @returns The transport.
7473
*/
75-
getTransport?(): Transport;
74+
getTransport(): NewTransport;
7675

7776
/**
7877
* Flush the event queue and set the client to `enabled = false`. See {@link Client.flush}.

packages/types/src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ export type {
6262
TransactionSamplingMethod,
6363
} from './transaction';
6464
export type { Thread } from './thread';
65-
export type { Outcome, Transport, TransportOptions, TransportClass } from './transport';
65+
export type {
66+
Outcome,
67+
Transport,
68+
TransportOptions,
69+
TransportClass,
70+
TransportCategory,
71+
TransportRequest,
72+
TransportMakeRequestResponse,
73+
TransportResponse,
74+
InternalBaseTransportOptions,
75+
BaseTransportOptions,
76+
NewTransport,
77+
TransportRequestExecutor,
78+
} from './transport';
6679
export type { User, UserFeedback } from './user';
6780
export type { WrappedFunction } from './wrappedfunction';

packages/types/src/transport.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { DsnLike } from './dsn';
2+
import { Envelope } from './envelope';
23
import { Event } from './event';
4+
import { EventStatus } from './eventstatus';
35
import { SentryRequestType } from './request';
46
import { Response } from './response';
57
import { SdkMetadata } from './sdkmetadata';
@@ -13,6 +15,46 @@ export type Outcome =
1315
| 'ratelimit_backoff'
1416
| 'sample_rate';
1517

18+
export type TransportCategory = 'error' | 'transaction' | 'attachment' | 'session';
19+
20+
export type TransportRequest = {
21+
body: string;
22+
category: TransportCategory;
23+
};
24+
25+
export type TransportMakeRequestResponse = {
26+
body?: string;
27+
headers?: {
28+
[key: string]: string | null;
29+
'x-sentry-rate-limits': string | null;
30+
'retry-after': string | null;
31+
};
32+
reason?: string;
33+
statusCode: number;
34+
};
35+
36+
export type TransportResponse = {
37+
status: EventStatus;
38+
reason?: string;
39+
};
40+
41+
export interface InternalBaseTransportOptions {
42+
bufferSize?: number;
43+
}
44+
export interface BaseTransportOptions extends InternalBaseTransportOptions {
45+
// url to send the event
46+
// transport does not care about dsn specific - client should take care of
47+
// parsing and figuring that out
48+
url: string;
49+
}
50+
51+
export interface NewTransport {
52+
send(request: Envelope): PromiseLike<TransportResponse>;
53+
flush(timeout?: number): PromiseLike<boolean>;
54+
}
55+
56+
export type TransportRequestExecutor = (request: TransportRequest) => PromiseLike<TransportMakeRequestResponse>;
57+
1658
/** Transport used sending data to Sentry */
1759
export interface Transport {
1860
/**

0 commit comments

Comments
 (0)