diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index aa3876e5e8ea..2dabfb31466e 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -62,6 +62,7 @@ export type { Severity, SeverityLevel } from './severity'; export type { Span, SpanContext } from './span'; export type { StackFrame } from './stackframe'; export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace'; +export type { TextEncoderInternal } from './textencoder'; export type { CustomSamplingContext, Measurements, diff --git a/packages/types/src/textencoder.ts b/packages/types/src/textencoder.ts new file mode 100644 index 000000000000..9071c14c007c --- /dev/null +++ b/packages/types/src/textencoder.ts @@ -0,0 +1,16 @@ +/** + * Vendored type from TS 3.8 `typescript/lib/lib.dom.d.ts`. + * + * Type is vendored in so that users don't have to opt-in to DOM types. + */ +export interface TextEncoderCommon { + /** + * Returns "utf-8". + */ + readonly encoding: string; +} + +// Combination of global TextEncoder and Node require('util').TextEncoder +export interface TextEncoderInternal extends TextEncoderCommon { + encode(input?: string): Uint8Array; +} diff --git a/packages/types/src/transport.ts b/packages/types/src/transport.ts index 6d358dc7ddc9..dae3ddd5f920 100644 --- a/packages/types/src/transport.ts +++ b/packages/types/src/transport.ts @@ -1,6 +1,7 @@ import { EventDropReason } from './clientreport'; import { DataCategory } from './datacategory'; import { Envelope } from './envelope'; +import { TextEncoderInternal } from './textencoder'; export type TransportRequest = { body: string | Uint8Array; @@ -15,11 +16,6 @@ export type TransportMakeRequestResponse = { }; }; -// Combination of global TextEncoder and Node require('util').TextEncoder -interface TextEncoderInternal extends TextEncoderCommon { - encode(input?: string): Uint8Array; -} - export interface InternalBaseTransportOptions { bufferSize?: number; recordDroppedEvent: (reason: EventDropReason, dataCategory: DataCategory) => void; diff --git a/packages/utils/src/envelope.ts b/packages/utils/src/envelope.ts index 1bc69915345d..f203cef51284 100644 --- a/packages/utils/src/envelope.ts +++ b/packages/utils/src/envelope.ts @@ -1,4 +1,12 @@ -import { Attachment, AttachmentItem, DataCategory, Envelope, EnvelopeItem, EnvelopeItemType } from '@sentry/types'; +import { + Attachment, + AttachmentItem, + DataCategory, + Envelope, + EnvelopeItem, + EnvelopeItemType, + TextEncoderInternal, +} from '@sentry/types'; import { dropUndefinedKeys } from './object'; @@ -36,11 +44,6 @@ export function forEachEnvelopeItem( }); } -// Combination of global TextEncoder and Node require('util').TextEncoder -interface TextEncoderInternal extends TextEncoderCommon { - encode(input?: string): Uint8Array; -} - function encodeUTF8(input: string, textEncoder?: TextEncoderInternal): Uint8Array { const utf8 = textEncoder || new TextEncoder(); return utf8.encode(input);