diff --git a/packages/core/client.d.ts b/packages/core/client.d.ts index c95021c0c..8ba593843 100644 --- a/packages/core/client.d.ts +++ b/packages/core/client.d.ts @@ -24,7 +24,11 @@ interface SessionDeliveryPayload { notifier?: Notifier device?: Device app?: App - sessions?: Session[] + sessions?: Array<{ + id: string + startedAt: Date + user?: User + }> } interface Delivery { @@ -32,6 +36,12 @@ interface Delivery { sendSession(session: SessionDeliveryPayload, cb: (err?: Error | null) => void): void } +export interface SessionDelegate { + startSession: (client: ClientWithInternals, session: Session) => ClientWithInternals + pauseSession: (client: ClientWithInternals) => void + resumeSession: (client: ClientWithInternals) => ClientWithInternals +} + /** * Extend the public type definitions with internal declarations. * @@ -58,11 +68,7 @@ export default class ClientWithInternals extends Clie _session: Session | null _pausedSession: Session | null - _sessionDelegate: { - startSession: (client: ClientWithInternals, session: Session) => ClientWithInternals - pauseSession: (client: ClientWithInternals) => void - resumeSession: (client: ClientWithInternals) => ClientWithInternals - } + _sessionDelegate: SessionDelegate _addOnSessionPayload: (cb: (sessionPayload: Session) => void) => void diff --git a/packages/core/types/session.d.ts b/packages/core/types/session.d.ts index 760cd2b9e..73ec509c1 100644 --- a/packages/core/types/session.d.ts +++ b/packages/core/types/session.d.ts @@ -7,8 +7,6 @@ declare class Session { public device?: Device; public app?: App; - public _user?: User; - public getUser(): User; public setUser(id?: string, email?: string, name?: string): void; } diff --git a/packages/plugin-browser-session/src/session.ts b/packages/plugin-browser-session/src/session.ts index 8036e84d4..4d866f908 100644 --- a/packages/plugin-browser-session/src/session.ts +++ b/packages/plugin-browser-session/src/session.ts @@ -1,30 +1,14 @@ -import { Client, Logger, Plugin, Session } from '@bugsnag/core' +import { Plugin, Session } from '@bugsnag/core' +import ClientWithInternals, { Notifier } from '@bugsnag/core/client' import includes from '@bugsnag/core/lib/es-utils/includes' -interface SessionDelegate { - startSession: (client: InternalClient, session: Session) => InternalClient - resumeSession: (client: { _session: any, _pausedSession: null, startSession: () => any}) => any - pauseSession: (client: { _pausedSession: any, _session: null }) => void -} - -interface InternalClient extends Client { - _config: { - enabledReleaseStages: string[] | null - releaseStage: string - releaseStages: string[] - } - _delivery: any - _logger: Logger - _notifier: any - _session: Session - _sessionDelegate: SessionDelegate - _pausedSession: any +interface InternalClient extends ClientWithInternals { + _notifier?: Notifier } const plugin: Plugin = { load: client => { - const internalClient = client as InternalClient - internalClient._sessionDelegate = sessionDelegate + (client as InternalClient)._sessionDelegate = sessionDelegate } } @@ -35,7 +19,7 @@ const sessionDelegate = { sessionClient._pausedSession = null // exit early if the current releaseStage is not enabled - if (sessionClient._config.enabledReleaseStages !== null && !includes(sessionClient._config.enabledReleaseStages, sessionClient._config.releaseStage)) { + if (sessionClient._config.enabledReleaseStages && !includes(sessionClient._config.enabledReleaseStages, sessionClient._config.releaseStage)) { sessionClient._logger.warn('Session not sent due to releaseStage/enabledReleaseStages configuration') return sessionClient } @@ -48,13 +32,13 @@ const sessionDelegate = { { id: session.id, startedAt: session.startedAt, - user: session._user + user: session.getUser() } ] - }) + }, () => {}) return sessionClient }, - resumeSession: (client: { _session: any, _pausedSession: null, startSession: () => any }) => { + resumeSession: (client: InternalClient) => { // Do nothing if there's already an active session if (client._session) { return client @@ -71,7 +55,7 @@ const sessionDelegate = { // Otherwise start a new session return client.startSession() }, - pauseSession: (client: { _pausedSession: any, _session: null }) => { + pauseSession: (client: InternalClient) => { client._pausedSession = client._session client._session = null } diff --git a/packages/plugin-browser-session/tsconfig.json b/packages/plugin-browser-session/tsconfig.json index 9478c5130..a5cb75c56 100644 --- a/packages/plugin-browser-session/tsconfig.json +++ b/packages/plugin-browser-session/tsconfig.json @@ -1,7 +1,4 @@ { "extends": "../../tsconfig.json", - "include": ["src/**/*.ts"], - "compilerOptions": { - "target": "ES2020" - } + "include": ["src/**/*.ts"] }