JS client for consuming the BugSplat API
npm install @bugsplat/js-api-client
Install @bugsplat/js-api-client via npm. This package currently requires Node.js 18 or later.
``sh`
npm i @bugsplat/js-api-client
If you need to use a version of Node.js that's older than 18, you can install @bugsplat/js-api-client@2.1.3.
Import BugSplatApiClient and Environment from @bugsplat\js-api-client
`ts`
import { BugSplatApiClient, Environment } from '@bugsplat/js-api-client';
Create an authenticated BugSplatApiClient following the steps below. Authentication is slightly different depending on if you are use @bugsplat/js-api-client in a Node.js or Web Browser environment. The method used to authenticate also depends on if you already have access to the user's email and password, or if you have to prompt for it at a later time.
The host value used to create a new instance of BugSplatApiClient is https://app.bugsplat.com for most scenarios. When using this library to upload a crash reports the host value will be https://{{database}}.bugsplat.com.
can be used to return an authenticated instance of BugSplatApiClient in Node.js environments.`ts
const bugsplat = await BugSplatApiClient.createAuthenticatedClientForNode(email, password, host);
`If you need to authenticate at a later time, you can create an instance of
BugSplatApiClient and call login manually.`ts
const bugsplat = new BugSplatApiClient(host, Environment.Node);
await bugsplat.login(email, password);
`$3
The static factory function
createAuthenticatedClientForWebBrowser can be used to return an authenticated instance of BugSplatApiClient.`ts
const bugsplat = await BugSplatApiClient.createAuthenticatedClientForBrowser(email, password, host);
`If you need to authenticate at a later time, you can create an instance of
BugSplatApiClient and call login manually.`ts
const bugsplat = new BugSplatApiClient(host, Environment.WebBrowser);
await bugsplat.login(email, password);
`⌨️ Usage
Create an instance of
CrashApiClient or any of the API clients and pass a reference to the BugSplatApiClient instance`ts
const client = new CrashApiClient(bugsplat);
`The API clients are built to automatically parse responses from BugSplat into objects that can be used by your application
`ts
const database = 'Fred';
const id = 100389;
const crash = await client.getCrashById(database, id);for (const stackFrame of crash.thread.stackFrames) {
console.log(stackFrame);
}
// StackFrame {
// fileName: 'C:\\BugSplat\\samples\\myConsoleCrasher\\myConsoleCrasher.cpp',
// functionName: 'myConsoleCrasher!MemoryException',
// lineNumber: 150,
// stackFrameLevel: 1,
// arguments: [],
// locals: []
// }
// StackFrame {
// fileName: 'C:\\BugSplat\\samples\\myConsoleCrasher\\myConsoleCrasher.cpp',
// functionName: 'myConsoleCrasher!wmain',
// lineNumber: 84,
// stackFrameLevel: 2,
// arguments: [
// { variable: 'int argc', value: '0n2' },
// { variable: 'wchar_t ** argv', value: '0x0125ef20' }
// ],
// locals: [
// { variable: 'int i', value: '0n1' },
// { variable: 'int argc', value: '0n2' },
// { variable: 'wchar_t ** argv', value: '0x0125ef20' }
// ]
// }
// ...
``BugSplat ❤️s open source! If you feel that this package can be improved, please open an Issue. If you have an awesome new feature you'd like to implement, we'd love to merge your Pull Request. You can also send us an email, join us on Discord, or message us via the in-app chat on bugsplat.com.