import { Event , EventHint , Options , Session , SeverityLevel , Transport } from '@sentry/types' ; import { isDebugBuild , logger , SentryError } from '@sentry/utils' ; import { NoopTransport } from './transports/noop' ; /**
 * Internal platform-dependent Sentry SDK Backend.
 *
 * While  Client contains business logic specific to an SDK, the
 * Backend offers platform specific implementations for low-level operations.
 * These are persisting and loading information, sending events, and hooking
 * into the environment.
 *
 * Backends receive a handle to the Client in their constructor. When a
 * Backend automatically generates events, it must pass them to
 * the Client for validation and processing first.
 *
 * Usually, the Client will be of corresponding type, e.g. NodeBackend
 * receives NodeClient. However, higher-level SDKs can choose to instantiate
 * multiple Backends and delegate tasks between them. In this case, an event
 * generated by one backend might very well be sent by another one.
 *
 * The client also provides access to options via  Client . getOptions .
 *  hidden export interface Backend { /** Creates an  Event from all inputs to `captureException` and non-primitive inputs to `captureMessage`.  eventFromException ( exception , hint ? ) : PromiseLike < Event > ; /** Creates an  Event from primitive inputs to `captureMessage`.  eventFromMessage ( message , level ? , hint ? ) : PromiseLike < Event > ; /** Submits the event to Sentry */ sendEvent ( event ) : void ; /** Submits the session to Sentry */ sendSession ( session ) : void ; returns getTransport ( ) : Transport ; } hidden export type BackendClass < B extends Backend , O extends Options > = new ( options ) => B ; hidden export abstract class BaseBackend < O extends Options > implements Backend { /** Options passed to the SDK. */ protected readonly _options : O ; /** Cached transport used internally. */ protected _transport : Transport ; /** Creates a new backend instance. */ public constructor ( options ) { this . _options = options ; if ( ! this . _options . dsn ) { logger . warn ( 'No DSN provided, backend will not do anything.' ) ; } this . _transport = this . _setupTransport ( ) ; } inheritDoc public eventFromException ( _exception , _hint ? ) { throw new SentryError ( 'Backend has to implement `eventFromException` method' ) ; } inheritDoc public eventFromMessage ( _message , _level ? , _hint ? ) { throw new SentryError ( 'Backend has to implement `eventFromMessage` method' ) ; } inheritDoc public sendEvent ( event ) { void this . _transport . sendEvent ( event ) . then ( null , reason => { if ( isDebugBuild ( ) ) { logger . error ( `Error while sending event: ${ reason }` ) ; } } ) ; } inheritDoc public sendSession ( session ) { if ( ! this . _transport . sendSession ) { if ( isDebugBuild ( ) ) { logger . warn ( "Dropping session because custom transport doesn't implement sendSession" ) ; } return ; } void this . _transport . sendSession ( session ) . then ( null , reason => { if ( isDebugBuild ( ) ) { logger . error ( `Error while sending session: ${ reason }` ) ; } } ) ; } inheritDoc public getTransport ( ) { return this . _transport ; } /**
     * Sets up the transport so it can be used later to send requests.
     */ protected _setupTransport ( ) { return new NoopTransport ( ) ; } }