diff --git a/package.json b/package.json index 2b0771a..7c48bab 100644 --- a/package.json +++ b/package.json @@ -70,8 +70,5 @@ "typescript": "5.6.3", "vitest": "2.1.5", "vitest-github-actions-reporter": "0.11.1" - }, - "dependencies": { - "ua-parser-js": "^1.0.32" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 056cb53..19bb421 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,10 +7,6 @@ settings: importers: .: - dependencies: - ua-parser-js: - specifier: ^1.0.32 - version: 1.0.39 devDependencies: '@rollup/plugin-typescript': specifier: 12.1.1 @@ -1393,10 +1389,6 @@ packages: engines: {node: '>=14.17'} hasBin: true - ua-parser-js@1.0.39: - resolution: {integrity: sha512-k24RCVWlEcjkdOxYmVJgeD/0a1TiSpqLg+ZalVGV9lsnr4yqu0w7tX/x2xX6G4zpkgQnRf89lxuZ1wsbjXM8lw==} - hasBin: true - uglify-js@3.19.3: resolution: {integrity: sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==} engines: {node: '>=0.8.0'} @@ -2756,8 +2748,6 @@ snapshots: typescript@5.6.3: {} - ua-parser-js@1.0.39: {} - uglify-js@3.19.3: optional: true diff --git a/src/browser-context.ts b/src/browser-context.ts index 596299f..266aed6 100644 --- a/src/browser-context.ts +++ b/src/browser-context.ts @@ -1,18 +1,7 @@ import { ExtendedClientApi, Plugin } from './client'; import { BugsnagEvent } from './event'; import { parseUserAgent } from './simple-ua-parser'; - -export type UserAgentInfo = { - browserName?: string; - browserVersion?: string; - osName?: string; - osVersion?: string; - manufacturer?: string; - model?: string; - modelNumber?: string; -}; - -export type UserAgentParserFn = (userAgent: string) => UserAgentInfo; +import type { UserAgentParserFn } from './user-agent-types'; export const browserContextWithUaParser = ( uaParser: UserAgentParserFn diff --git a/src/index.ts b/src/index.ts index 5e3c603..2427c4e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -344,12 +344,7 @@ export { nodeNotifyUnhandledExceptions } from './node-unhandled-exceptions'; // Other plugins export { appDuration } from './app-duration'; -export { - browserContext, - browserContextWithUaParser, - UserAgentParserFn, - UserAgentInfo, -} from './browser-context'; +export { browserContext, browserContextWithUaParser } from './browser-context'; export { deviceOrientation } from './deviceorientation'; export { limitEvents } from './limit-events'; export { @@ -365,6 +360,7 @@ export { redactObject, } from './redact-keys'; export { stringifyValues } from './stringify-values'; +export type { UserAgentParserFn, UserAgentInfo } from './user-agent-types'; // Delivery plugins export { FetchDelivery } from './fetch-delivery'; diff --git a/src/lambda-context.ts b/src/lambda-context.ts index 2fb0660..081c1d4 100644 --- a/src/lambda-context.ts +++ b/src/lambda-context.ts @@ -4,11 +4,12 @@ import { Context, } from 'aws-lambda'; import { platform as osPlatform, release as osRelease } from 'os'; -import UAParser from 'ua-parser-js'; import { ExtendedClientApi, Plugin } from './client'; import { BugsnagEvent } from './event'; +import { parseUserAgent } from './simple-ua-parser'; import { toExceptions } from './to-exceptions'; +import { UserAgentParserFn } from './user-agent-types'; export interface LambdaContextPlugin { setContext( @@ -22,7 +23,8 @@ export interface LambdaContextPlugin { }; } -export const lambdaContext = ( +export const lambdaContextWithUaParser = ( + uaParser: UserAgentParserFn, initialEvent?: Record, initialContext?: Context ): Plugin => { @@ -157,9 +159,7 @@ export const lambdaContext = ( lambdaEvent.requestContext.identity.userAgent || undefined; } - const browser = userAgent - ? new UAParser(userAgent).getBrowser() - : undefined; + const browser = userAgent ? uaParser(userAgent) : undefined; const hostname = lambdaEvent?.requestContext?.domainName; let timeEpoch: number | undefined; @@ -171,12 +171,15 @@ export const lambdaContext = ( event.device = { hostname, - osName: osPlatform(), - osVersion: osRelease(), + osName: browser?.osName || osPlatform(), + osVersion: browser?.osVersion || osRelease(), freeMemory, totalMemory, - browserName: browser?.name, - browserVersion: browser?.version, + browserName: browser?.browserName, + browserVersion: browser?.browserVersion, + manufacturer: browser?.manufacturer, + model: browser?.model, + modelNumber: browser?.modelNumber, runtimeVersions: { node: process.version, }, @@ -284,6 +287,17 @@ export const lambdaContext = ( }; }; +export const lambdaContext = ( + initialEvent?: Record, + initialContext?: Context +): Plugin => { + return lambdaContextWithUaParser( + parseUserAgent, + initialEvent, + initialContext + ); +}; + function isGwV2Event( event: Record | undefined ): event is APIGatewayProxyEventV2 { diff --git a/src/simple-ua-parser.ts b/src/simple-ua-parser.ts index 72d9380..b805ad5 100644 --- a/src/simple-ua-parser.ts +++ b/src/simple-ua-parser.ts @@ -1,4 +1,4 @@ -import { UserAgentInfo } from './browser-context'; +import type { UserAgentInfo } from './user-agent-types'; // The Bugsnag v5 API requires doing your own UA string parsing, requiring a // `browserName`, `browserVersion`, `osName`, `osVersion`, etc. diff --git a/src/user-agent-types.ts b/src/user-agent-types.ts new file mode 100644 index 0000000..cfdb13b --- /dev/null +++ b/src/user-agent-types.ts @@ -0,0 +1,11 @@ +export type UserAgentInfo = { + browserName?: string; + browserVersion?: string; + osName?: string; + osVersion?: string; + manufacturer?: string; + model?: string; + modelNumber?: string; +}; + +export type UserAgentParserFn = (userAgent: string) => UserAgentInfo;