diff --git a/jest.config.js b/jest.config.js index 6b81e5c918..1142aa5943 100644 --- a/jest.config.js +++ b/jest.config.js @@ -24,6 +24,7 @@ module.exports = { testsForPackage('plugin-browser-context'), testsForPackage('plugin-browser-device'), testsForPackage('plugin-browser-request'), + testsForPackage('plugin-client-ip'), testsForPackage('plugin-window-unhandled-rejection'), testsForPackage('plugin-window-onerror'), testsForPackage('plugin-strip-query-string'), diff --git a/packages/core/client.d.ts b/packages/core/client.d.ts index 872f6db865..5e873df4f2 100644 --- a/packages/core/client.d.ts +++ b/packages/core/client.d.ts @@ -1,4 +1,4 @@ -import { Client, OnErrorCallback, Config, Breadcrumb, Session, OnSessionCallback, OnBreadcrumbCallback, Plugin, Device, App } from './types' +import { Client, OnErrorCallback, Config, Breadcrumb, Session, OnSessionCallback, OnBreadcrumbCallback, Plugin, Device, App, User } from './types' import EventWithInternals from './event' interface LoggerConfig { @@ -46,6 +46,8 @@ export default class ClientWithInternals extends Clie _delivery: Delivery _setDelivery: (handler: (client: Client) => Delivery) => void + _user: User + _metadata: { [key: string]: any } startSession(): ClientWithInternals diff --git a/packages/core/event.d.ts b/packages/core/event.d.ts index 4327273e96..03682246c2 100644 --- a/packages/core/event.d.ts +++ b/packages/core/event.d.ts @@ -16,6 +16,7 @@ interface HandledState { export default class EventWithInternals extends Event { constructor (errorClass: string, errorMessage: string, stacktrace: any[], handledState?: HandledState, originalError?: Error) _metadata: { [key: string]: any } + _user: User _handledState: HandledState _session?: Session toJSON(): { diff --git a/packages/plugin-client-ip/package.json b/packages/plugin-client-ip/package.json index fc2e830650..db4f6d55c0 100644 --- a/packages/plugin-client-ip/package.json +++ b/packages/plugin-client-ip/package.json @@ -14,15 +14,10 @@ "files": [ "*.js" ], - "scripts": { - "test": "nyc --reporter=lcov -- jasmine '!(node_modules)/**/*.test.js'" - }, "author": "Bugsnag", "license": "MIT", "devDependencies": { - "@bugsnag/core": "^7.3.3", - "jasmine": "^3.1.0", - "nyc": "^12.0.2" + "@bugsnag/core": "^7.3.3" }, "peerDependencies": { "@bugsnag/core": "^7.0.0" diff --git a/packages/plugin-client-ip/test/client-ip.test.js b/packages/plugin-client-ip/test/client-ip.test.ts similarity index 79% rename from packages/plugin-client-ip/test/client-ip.test.js rename to packages/plugin-client-ip/test/client-ip.test.ts index e7eb4835a3..04a4f50b00 100644 --- a/packages/plugin-client-ip/test/client-ip.test.js +++ b/packages/plugin-client-ip/test/client-ip.test.ts @@ -1,15 +1,13 @@ -const { describe, it, expect } = global +import plugin from '../' -const plugin = require('../') - -const Client = require('@bugsnag/core/client') +import Client, { EventDeliveryPayload } from '@bugsnag/core/client' describe('plugin: ip', () => { it('does nothing when collectUserIp=true', () => { const client = new Client({ apiKey: 'API_KEY_YEAH' }, undefined, [plugin]) - const payloads = [] + const payloads: EventDeliveryPayload[] = [] - client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) })) + client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} })) client.notify(new Error('noooo'), event => { event.request = { some: 'detail' } }) expect(payloads.length).toEqual(1) @@ -18,11 +16,11 @@ describe('plugin: ip', () => { it('doesn’t overwrite an existing user id', () => { const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin]) - const payloads = [] + const payloads: EventDeliveryPayload[] = [] client._user = { id: 'foobar' } - client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) })) + client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} })) client.notify(new Error('noooo')) expect(payloads.length).toEqual(1) @@ -32,11 +30,11 @@ describe('plugin: ip', () => { it('overwrites a user id if it is explicitly `undefined`', () => { const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin]) - const payloads = [] + const payloads: EventDeliveryPayload[] = [] client._user = { id: undefined } - client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) })) + client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} })) client.notify(new Error('noooo')) expect(payloads.length).toEqual(1) @@ -46,9 +44,9 @@ describe('plugin: ip', () => { it('redacts user IP if none is provided', () => { const client = new Client({ apiKey: 'API_KEY_YEAH', collectUserIp: false }, undefined, [plugin]) - const payloads = [] + const payloads: EventDeliveryPayload[] = [] - client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload) })) + client._setDelivery(client => ({ sendEvent: (payload) => payloads.push(payload), sendSession: () => {} })) client.notify(new Error('noooo')) expect(payloads.length).toEqual(1) diff --git a/tsconfig.json b/tsconfig.json index a0c25e2e48..a0db56b906 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -75,7 +75,6 @@ "packages/plugin-react-native-client-sync", "packages/plugin-react-native-event-sync", "packages/plugin-server-session", - "packages/plugin-react", "packages/plugin-vue", "packages/plugin-express", @@ -83,6 +82,7 @@ "packages/plugin-restify", "packages/node", "packages/react-native", + "packages/plugin-client-ip", "packages/plugin-window-unhandled-rejection", "packages/plugin-window-onerror", "packages/plugin-strip-query-string",