import assert from "assert"; import { RawEvent, NormalizedEvent } from "../../types"; export default (event: RawEvent): NormalizedEvent<"bugsnag"> => { assert(event, `bugsnag:Events null event: ${event}`); assert( event.id, `bugsnag:Events event is missing the required field id ${event}` ); assert( event.received_at, `bugsnag:Events event is missing the required field received_at ${event}` ); const exception = event.exceptions[0]; // https://bugsnagapiv2.docs.apiary.io/#reference/errors/events/view-an-event // The `html_url` property onis injected by the tap return { id: `bugsnag|${event.id}`, ts: Date.parse(event.received_at), user_info: { source_user_id: null, user_id: (event.user && event.user.id) || null, name: (event.user && event.user.name) || null, email: (event.user && event.user.email) || null, ip: null, avatar: (event.user && event.user.avatar) || null, nickname: (event.user && event.user.username) || null, phone: null, city: null, continent_code: null, country: null, postal_code: null, region: null, timezone: null, country_code: null, address_line1: null, address_line2: null, user_agent: null, is_employee: null, title: null, birthday: null, company: { name: null, id: null, industry: null, employee_count: null, plan: null }, created_at: null, age: null, gender: null, website: null, custom_attributes: null }, text: !!exception ? `${exception.error_class}: ${exception.message}` : "An error occurred", href: event.html_url || null, is_bad: true, direction: null, source: "bugsnag", stream: "events" }; };